From a0fb2f69b7024d0dbb1de3cc70bd8defea69afff Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Fri, 4 Apr 2025 11:38:42 -0400 Subject: feat: create and edit are unified --- .../views/nodes/chatbot/agentsystem/Agent.ts | 2 +- .../nodes/chatbot/tools/CreateDocumentTool.ts | 2 +- .../nodes/chatbot/tools/DocumentMetadataTool.ts | 165 +++++++++++++++++++-- 3 files changed, 158 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts index 3c76cf348..bab2081b3 100644 --- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts +++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts @@ -87,7 +87,7 @@ export class Agent { noTool: new NoTool(), imageCreationTool: new ImageCreationTool(createImage), // createTextDoc: new CreateTextDocTool(addLinkedDoc), - createDoc: new CreateDocTool(addLinkedDoc), + // createDoc: new CreateDocTool(addLinkedDoc), // createAnyDocument: new CreateAnyDocumentTool(addLinkedDoc), // dictionary: new DictionaryTool(), documentMetadata: new DocumentMetadataTool(this), diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts index 284879a4a..b3bf6dfb2 100644 --- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts +++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts @@ -9,7 +9,7 @@ import { CollectionViewType } from '../../../../documents/DocumentTypes'; */ export enum supportedDocTypes { flashcard = 'flashcard', - text = 'text', + note = 'note', html = 'html', equation = 'equation', functionplot = 'functionplot', diff --git a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts index 093ab248d..c74e502e7 100644 --- a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts +++ b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts @@ -8,6 +8,8 @@ import { CollectionFreeFormDocumentView } from '../../../nodes/CollectionFreeFor import { v4 as uuidv4 } from 'uuid'; import { LinkManager } from '../../../../util/LinkManager'; import { DocCast, StrCast } from '../../../../../fields/Types'; +import { supportedDocTypes } from './CreateDocumentTool'; +import { parsedDoc } from '../chatboxcomponents/ChatBox'; // Define the parameters for the DocumentMetadataTool const parameterDefinitions: ReadonlyArray = [ @@ -15,13 +17,13 @@ const parameterDefinitions: ReadonlyArray = [ name: 'action', type: 'string', required: true, - description: 'The action to perform: "get" to retrieve metadata, "edit" to modify metadata, "list" to enumerate documents, or "getFieldOptions" to retrieve all available field options', + description: 'The action to perform: "get" to retrieve metadata, "edit" to modify metadata, "list" to enumerate documents, "getFieldOptions" to retrieve all available field options, or "create" to create a new document', }, { name: 'documentId', type: 'string', required: false, - description: 'The ID of the document to get or edit metadata for. Required for "edit", optional for "get", ignored for "list" and "getFieldOptions"', + description: 'The ID of the document to get or edit metadata for. Required for "edit", optional for "get", ignored for "list", "getFieldOptions", and "create"', }, { name: 'fieldName', @@ -40,14 +42,32 @@ const parameterDefinitions: ReadonlyArray = [ type: 'string', required: false, description: 'JSON array of field edits for editing multiple fields at once. Each item should have fieldName and fieldValue. Example: [{"fieldName":"layout_autoHeight","fieldValue":false},{"fieldName":"height","fieldValue":300}]', + }, + { + name: 'title', + type: 'string', + required: false, + description: 'The title of the document to create. Required for "create" action', + }, + { + name: 'data', + type: 'string', + required: false, + description: 'The data content for the document to create. Required for "create" action', + }, + { + name: 'doc_type', + type: 'string', + required: false, + description: `The type of document to create. Required for "create" action. Options: ${Object.keys(supportedDocTypes).join(',')}`, } ] as const; type DocumentMetadataToolParamsType = typeof parameterDefinitions; // Detailed description with usage guidelines for the DocumentMetadataTool -const toolDescription = `Extracts and modifies metadata from documents in the same Freeform view as the ChatBox. -This tool helps you work with document properties, understand available fields, and edit document metadata. +const toolDescription = `Extracts and modifies metadata from documents in the same Freeform view as the ChatBox, and can create new documents. +This tool helps you work with document properties, understand available fields, edit document metadata, and create new documents. The Dash document system organizes fields in two locations: 1. Layout documents: contain visual properties like position, dimensions, and appearance @@ -63,6 +83,13 @@ This tool provides the following capabilities: - Understand which fields are stored where (layout vs data document) - Get detailed information about all available document fields - Support for all value types: strings, numbers, and booleans +- Create new documents with basic properties + +DOCUMENT CREATION: +- Use action="create" to create new documents with a simplified approach +- Required parameters: title, data, and doc_type +- The tool will create the document with sensible defaults and link it to the current view +- After creation, you can use the edit action to update its properties IMPORTANT: Before editing any document metadata, first call 'getFieldOptions' to understand: - Which fields are available @@ -99,6 +126,14 @@ To GET ALL FIELD OPTIONS (call this first): - ALWAYS call this before attempting to edit document metadata - Use this information to understand which fields need special handling +To CREATE a new document: +- Use action="create" with the following required parameters: + - title: The title of the document to create + - data: The content data for the document (text content, URL, etc.) + - doc_type: The type of document to create (text, web, image, etc.) +- Example: { action: "create", title: "My Notes", data: "This is the content", doc_type: "text" } +- After creation, you can edit the document with more specific properties + To EDIT document metadata: - Use action="edit" with required documentId, and either: 1. fieldName + fieldValue for single field edits, OR @@ -120,6 +155,10 @@ RECOMMENDED WORKFLOW: 2. Then call action="getFieldOptions" to understand available fields 3. Get document metadata with action="get" to see current values 4. Edit fields with action="edit" using proper dependencies +OR +1. Create a new document with action="create" +2. Get its ID from the response +3. Edit the document's properties with action="edit" HANDLING DEPENDENT FIELDS: - When editing some fields, you may need to update related dependent fields @@ -154,6 +193,8 @@ Examples: - 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 create a text document: { action: "create", title: "My Notes", data: "This is my note content", doc_type: "text" } +- To create a web document: { action: "create", title: "Google", data: "https://www.google.com", doc_type: "web" } - To edit height with its dependent field together (recommended): { action: "edit", documentId: "doc123", fieldEdits: [ { fieldName: "layout_autoHeight", fieldValue: false }, @@ -936,10 +977,10 @@ export class DocumentMetadataTool extends BaseTool