39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.toolHandler = exports.toolDefinition = void 0;
|
|
const uuid_1 = require("uuid");
|
|
exports.toolDefinition = {
|
|
name: 'switch_thread',
|
|
description: 'Switch the active context to a specific thread.',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
threadId: {
|
|
type: 'string',
|
|
description: 'ID of the thread to switch to (can be full UUID or a unique prefix)'
|
|
}
|
|
},
|
|
required: ['threadId']
|
|
}
|
|
};
|
|
const toolHandler = async (invocation, threadManager) => {
|
|
const input = invocation.input;
|
|
let { threadId } = input;
|
|
// If threadId is not a full UUID, try to resolve it from prefix
|
|
if (!(0, uuid_1.validate)(threadId)) {
|
|
const matchingThreads = threadManager.findThreadsByPrefix(threadId);
|
|
if (matchingThreads.length === 0) {
|
|
return { success: false, message: `No thread found matching prefix "${threadId}".` };
|
|
}
|
|
else if (matchingThreads.length > 1) {
|
|
const matches = matchingThreads.map(t => `${t.title} (${t.id.substring(0, 8)})`).join(', ');
|
|
return { success: false, message: `Multiple threads match "${threadId}": ${matches}. Please provide a more specific ID.` };
|
|
}
|
|
else {
|
|
threadId = matchingThreads[0].id; // Use the full ID
|
|
}
|
|
}
|
|
return await threadManager.switchThread(threadId);
|
|
};
|
|
exports.toolHandler = toolHandler;
|