diff options
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts new file mode 100644 index 000000000..fa978bdc3 --- /dev/null +++ b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts @@ -0,0 +1,59 @@ +import { v4 as uuidv4 } from 'uuid'; +import { Networking } from '../../../../Network'; +import { BaseTool } from './BaseTool'; +import { Observation } from '../types/types'; +import { ParametersType } from './ToolTypes'; +import { DocumentOptions } from '../../../../documents/Documents'; + +const createTextDocToolParams = [ + { + name: 'text_content', + type: 'string', + description: 'The text content that the document will display', + required: true, + }, + { + name: 'title', + type: 'string', + description: 'The title of the document', + required: true, + }, + { + name: 'background_color', + type: 'string', + description: 'The background color of the document as a hex string', + required: false, + }, + { + name: 'font_color', + type: 'string', + description: 'The font color of the document as a hex string', + required: false, + }, +] as const; + +type CreateTextDocToolParamsType = typeof createTextDocToolParams; + +export class CreateTextDocTool extends BaseTool<CreateTextDocToolParamsType> { + private _addLinkedTextDoc: (text_content: string, options: DocumentOptions, id: string) => void; + + constructor(addLinkedTextDoc: (text_content: string, options: DocumentOptions, id: string) => void) { + super( + 'createTextDoc', + 'Creates a text document with the provided content and title (and of specified other options if wanted)', + createTextDocToolParams, + 'Provide the text content and title (and optionally color) for the document.', + 'Creates a text document with the provided content and title (and of specified other options if wanted). Use if the user wants to create a textbox or text document of some sort. Can use after a search or other tool to save information.' + ); + this._addLinkedTextDoc = addLinkedTextDoc; + } + + async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> { + try { + this._addLinkedTextDoc(args.text_content, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4()); + return [{ type: 'text', text: 'Created text document.' }]; + } catch (error) { + return [{ type: 'text', text: 'Error creating text document, ' + error }]; + } + } +} |