import { Observation } from '../types/types'; import { ParametersType, ToolInfo } from '../types/tool_types'; import { BaseTool } from './BaseTool'; import { AgentDocumentManager } from '../utils/AgentDocumentManager'; const createLinksToolParams = [ { name: 'document_ids', type: 'string[]', description: 'List of document IDs to create links between. All documents will be linked to each other.', required: true, }, ] as const; type CreateLinksToolParamsType = typeof createLinksToolParams; const createLinksToolInfo: ToolInfo = { name: 'createLinks', description: 'Creates visual links between multiple documents in the dashboard. This allows related documents to be connected visually with lines that users can see.', citationRules: 'No citation needed.', parameterRules: createLinksToolParams, }; export class CreateLinksTool extends BaseTool { private _documentManager: AgentDocumentManager; constructor(documentManager: AgentDocumentManager) { super(createLinksToolInfo); this._documentManager = documentManager; } async execute(args: ParametersType): Promise { try { // Validate that we have at least 2 documents to link if (args.document_ids.length < 2) { return [{ type: 'text', text: 'Error: At least 2 document IDs are required to create links.' }]; } // Validate that all documents exist const missingDocIds = args.document_ids.filter(id => !this._documentManager.has(id)); if (missingDocIds.length > 0) { return [ { type: 'text', text: `Error: The following document IDs were not found: ${missingDocIds.join(', ')}`, }, ]; } // Create links between all documents with the specified relationship const createdLinks = this._documentManager.addLinks(args.document_ids); return [ { type: 'text', text: `Successfully created ${createdLinks.length} visual links between ${args.document_ids.length}.`, }, ]; } catch (error) { return [ { type: 'text', text: `Error creating links: ${error instanceof Error ? error.message : String(error)}`, }, ]; } } }