46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.toolHandler = exports.toolDefinition = void 0;
|
|
exports.toolDefinition = {
|
|
name: 'add_message',
|
|
description: 'Add a message to the current active thread. Use this to record conversation messages.',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
role: {
|
|
type: 'string',
|
|
enum: ['user', 'assistant', 'system'],
|
|
description: 'The role of the message sender'
|
|
},
|
|
content: {
|
|
type: 'string',
|
|
description: 'The content of the message'
|
|
},
|
|
metadata: {
|
|
type: 'object',
|
|
description: 'Optional metadata for the message (e.g., timestamp, tags, etc.)'
|
|
}
|
|
},
|
|
required: ['role', 'content']
|
|
}
|
|
};
|
|
const toolHandler = async (invocation, threadManager) => {
|
|
const { role, content, metadata } = invocation.input;
|
|
const current = await threadManager.getCurrentThread();
|
|
if (!current.thread) {
|
|
return { success: false, message: "No active thread to add message to." };
|
|
}
|
|
try {
|
|
const message = await threadManager.addMessageToThread(current.thread.id, role, content, metadata);
|
|
return {
|
|
success: true,
|
|
message: message,
|
|
info: `Message added to thread "${current.thread.title}".`
|
|
};
|
|
}
|
|
catch (e) {
|
|
return { success: false, message: e.message };
|
|
}
|
|
};
|
|
exports.toolHandler = toolHandler;
|