| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | import { HumanMessage, AIMessage, SystemMessage, ToolMessage } from '../../../../src/index.js';
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | function formatMessage(message, options = {}) {
|
| | const maxLength = options.maxLength || 100;
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | function formatConversation(messages) {
|
| |
|
| |
|
| |
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | function formatMessageWithColor(message, options = {}) {
|
| |
|
| |
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | async function runTests() {
|
| | console.log('π§ͺ Testing Message Formatter...\n');
|
| |
|
| | try {
|
| |
|
| | console.log('Test 1: Basic message formatting');
|
| | const msg1 = new HumanMessage("Hello, how are you?");
|
| | const formatted1 = formatMessage(msg1);
|
| | console.log(` Output: ${formatted1}`);
|
| | console.assert(formatted1.includes('HUMAN'), 'Should include message type');
|
| | console.assert(formatted1.includes('Hello'), 'Should include content');
|
| | console.log('β
Basic formatting works\n');
|
| |
|
| |
|
| | console.log('Test 2: Long message truncation');
|
| | const longContent = 'A'.repeat(150);
|
| | const msg2 = new AIMessage(longContent);
|
| | const formatted2 = formatMessage(msg2, { maxLength: 50 });
|
| | console.log(` Output length: ${formatted2.length}`);
|
| | console.assert(formatted2.length < 100, 'Should truncate long messages');
|
| | console.log('β
Truncation works\n');
|
| |
|
| |
|
| | console.log('Test 3: Different message types');
|
| | const messages = [
|
| | new SystemMessage("You are helpful"),
|
| | new HumanMessage("Hi"),
|
| | new AIMessage("Hello!"),
|
| | new ToolMessage("result", "tool_123")
|
| | ];
|
| |
|
| | messages.forEach(msg => {
|
| | const formatted = formatMessage(msg);
|
| | console.log(` ${formatted}`);
|
| | });
|
| | console.log('β
All message types format correctly\n');
|
| |
|
| |
|
| | console.log('Test 4: Full conversation formatting');
|
| | const conversation = [
|
| | new SystemMessage("You are a helpful assistant"),
|
| | new HumanMessage("What's 2+2?"),
|
| | new AIMessage("2+2 equals 4")
|
| | ];
|
| |
|
| | const formattedConv = formatConversation(conversation);
|
| | console.log(formattedConv);
|
| | console.assert(formattedConv.split('\n').length >= 3, 'Should have multiple lines');
|
| | console.log('β
Conversation formatting works\n');
|
| |
|
| |
|
| | console.log('Test 5: Timestamp format');
|
| | const msg5 = new HumanMessage("Test");
|
| | const formatted5 = formatMessage(msg5);
|
| | const timestampRegex = /\[\d{2}:\d{2}:\d{2}\]/;
|
| | console.assert(timestampRegex.test(formatted5), 'Should have [HH:MM:SS] timestamp');
|
| | console.log('β
Timestamp format is correct\n');
|
| |
|
| | console.log('π All tests passed!');
|
| | } catch (error) {
|
| | console.error('β Test failed:', error.message);
|
| | console.error(error.stack);
|
| | }
|
| | }
|
| |
|
| |
|
| | if (import.meta.url === `file://${process.argv[1]}`) {
|
| | runTests();
|
| | }
|
| |
|
| | export { formatMessage, formatConversation, formatMessageWithColor }; |