aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-11-19 10:36:59 -0500
committerbobzel <zzzman@gmail.com>2024-11-19 10:36:59 -0500
commit7b38bbc4d845fa524e8310a0ec05b0e776b47c82 (patch)
tree958609fc079523803345a74e33b16c164c226fd8 /src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
parent196b92cb84095780d2b36244831cac03e9b66d8e (diff)
parent9e447814b551c352709296ae562f1f50480320f5 (diff)
Merge remote-tracking branch 'origin/ajs-finalagent'
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts61
1 files changed, 61 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..fae78aa49
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
@@ -0,0 +1,61 @@
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType } from '../types/tool_types';
+import { DocumentOptions } from '../../../../documents/Documents';
+import { RTFCast, StrCast } from '../../../../../fields/Types';
+
+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 _addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void;
+
+ constructor(addLinkedDoc: (text_content: string, data: 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._addLinkedDoc = addLinkedDoc;
+ }
+
+ async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> {
+ try {
+ console.log(RTFCast(args.text_content));
+ this._addLinkedDoc('text', 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 }];
+ }
+ }
+}