From 7c797ff1d3c81a2fa2ec7b646444b1b5585bb357 Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Thu, 3 Apr 2025 12:46:22 -0400 Subject: better text editing? --- .../nodes/chatbot/tools/DocumentMetadataTool.ts | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src') diff --git a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts index 6354e8df3..093ab248d 100644 --- a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts +++ b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts @@ -109,6 +109,12 @@ To EDIT document metadata: - All value types are supported: strings, numbers, and booleans - The tool will apply the edit to the correct document (layout or data) based on existing fields +SPECIAL FIELD HANDLING: +- Text fields: When editing the 'text' field, provide simple plain text + Example: { action: "edit", documentId: "doc123", fieldName: "text", fieldValue: "Hello world" } + The tool will automatically convert your text to the proper RichTextField format +- Width/Height: Set layout_autoHeight/layout_autoWidth to false before editing + RECOMMENDED WORKFLOW: 1. First call action="list" to identify available documents 2. Then call action="getFieldOptions" to understand available fields @@ -146,6 +152,7 @@ Examples: - To get metadata for a specific document: { action: "get", documentId: "doc123" } - To edit a single field: { action: "edit", documentId: "doc123", fieldName: "backgroundColor", fieldValue: "#ff0000" } - To edit a width property: { action: "edit", documentId: "doc123", fieldName: "width", fieldValue: 300 } +- To edit text content: { action: "edit", documentId: "doc123", fieldName: "text", fieldValue: "Simple plain text goes here" } - To disable auto-height: { action: "edit", documentId: "doc123", fieldName: "layout_autoHeight", fieldValue: false } - To edit height with its dependent field together (recommended): { action: "edit", documentId: "doc123", fieldEdits: [ @@ -634,6 +641,34 @@ export class DocumentMetadataTool extends BaseTool { + if (node.text) { + plainText += node.text; + } + if (node.content && Array.isArray(node.content)) { + node.content.forEach((child: any) => extractText(child)); + } + }; + + extractText(rtfObj.doc); + + // If we successfully extracted text, show it, but also preserve the original value + if (plainText) { + return { + type: 'RichText', + text: plainText, + length: plainText.length, + // Don't include the full value as it can be very large + }; + } + } + } catch (e) { + // If parsing fails, just treat as a regular string + } + } + // Handle arrays and complex objects if (typeof value === 'object') { // If the object has a toString method, use it @@ -831,6 +900,17 @@ export class DocumentMetadataTool extends BaseTool