aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2025-04-10 12:42:25 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2025-04-10 12:42:25 -0400
commitfcee0e51396e85f3deac939ea5d836ac35e2caf7 (patch)
treecb78edefc2ee0ed7b2592abfcc1118195bce9f55
parent9de0e9844d5cbfbb385da34545006e617873b07a (diff)
Revert "adding edit and create at the same time"
This reverts commit 9de0e9844d5cbfbb385da34545006e617873b07a.
-rw-r--r--src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts171
1 files changed, 17 insertions, 154 deletions
diff --git a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts
index 9781d7a51..eeb9091f8 100644
--- a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts
+++ b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts
@@ -30,7 +30,7 @@ const parameterDefinitions: ReadonlyArray<Parameter> = [
type: 'string',
required: false,
description:
- 'JSON array of field edits for editing fields. Each item should have fieldName and fieldValue. For single field edits, use an array with one item. Can be used with both "edit" and "create" actions. Example: [{"fieldName":"layout_autoHeight","fieldValue":false},{"fieldName":"height","fieldValue":300}]',
+ 'JSON array of field edits for editing fields. Each item should have fieldName and fieldValue. For single field edits, use an array with one item. Example: [{"fieldName":"layout_autoHeight","fieldValue":false},{"fieldName":"height","fieldValue":300}]',
},
{
name: 'title',
@@ -73,12 +73,10 @@ This tool provides the following capabilities:
- Get detailed information about all available document fields
- Support for all value types: strings, numbers, and booleans
- Create new documents with basic properties
-- Create new documents and immediately configure additional properties in a single operation
DOCUMENT CREATION:
- Use action="create" to create new documents with a simplified approach
- Required parameters: title, data, and doc_type
-- Optional parameter: fieldEdits to set additional properties during creation
- 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
@@ -98,19 +96,7 @@ Example: To change document height, disable auto-height and set height in a sing
{... inputs: { action: "edit", documentId: "doc123", fieldEdits: [
{ fieldName: "layout_autoHeight", fieldValue: false },
{ fieldName: "height", fieldValue: 300 }
-]}}
-
-Example: To create a document and set additional properties in a single operation:
-{... inputs: {
- action: "create",
- title: "My Styled Note",
- data: "This is my note content",
- doc_type: "text",
- fieldEdits: [
- { fieldName: "backgroundColor", fieldValue: "#f0f0f0" },
- { fieldName: "borderWidth", fieldValue: 1 }
- ]
-}}`;
+]}}`;
// Extensive usage guidelines for the tool
const citationRules = `USAGE GUIDELINES:
@@ -130,10 +116,8 @@ To CREATE a new document:
- 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.)
-- Optionally include fieldEdits to set additional properties during creation
-- Example with just basic properties: {...inputs: { action: "create", title: "My Notes", data: "This is the content", doc_type: "text" }}
-- Example with additional properties: {...inputs: { action: "create", title: "My Notes", data: "This is the content", doc_type: "text", fieldEdits: [{ fieldName: "backgroundColor", fieldValue: "#f0f0f0" }] }}
-- The fieldEdits parameter allows you to create and configure a document in a single operation
+- Example: {...inputs: { 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 parameters:
@@ -157,8 +141,9 @@ RECOMMENDED WORKFLOW:
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 fieldEdits to configure it in one step:
- { action: "create", title: "My Document", data: "Content", doc_type: "text", fieldEdits: [{ fieldName: "backgroundColor", fieldValue: "#f0f0f0" }] }
+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
@@ -195,7 +180,6 @@ Examples:
- To disable auto-height: { action: "edit", documentId: "doc123", fieldEdits: [{ 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 create a document with custom styling: { action: "create", title: "Styled Note", data: "Content here", doc_type: "text", fieldEdits: [{ fieldName: "backgroundColor", fieldValue: "#f0f0f0" }] }
- To edit height with its dependent field together:
{ action: "edit", documentId: "doc123", fieldEdits: [
{ fieldName: "layout_autoHeight", fieldValue: false },
@@ -1238,115 +1222,28 @@ export class DocumentMetadataTool extends BaseTool<DocumentMetadataToolParamsTyp
// Update our local document maps with the new document
this.processDocument(createdDoc);
- // Apply any fieldEdits if provided
- let fieldEditsResults = null;
- if (args.fieldEdits) {
- try {
- // Parse fieldEdits array
- const edits = JSON.parse(String(args.fieldEdits));
- if (Array.isArray(edits) && edits.length > 0) {
- console.log(`DocumentMetadataTool: Applying ${edits.length} field edits to newly created document`);
-
- // Track results for all edits
- const results: {
- success: boolean;
- message: string;
- fieldName?: string;
- originalFieldName?: string;
- newValue?: any;
- warning?: string;
- }[] = [];
-
- let allSuccessful = true;
-
- // Process each edit
- for (const edit of edits) {
- // Get fieldValue in its original form
- let fieldValue = edit.fieldValue;
-
- // Only convert to string if it's neither boolean nor number
- if (typeof fieldValue !== 'boolean' && typeof fieldValue !== 'number') {
- fieldValue = String(fieldValue);
- }
-
- const fieldName = String(edit.fieldName);
-
- // Edit the field
- const result = this.editDocumentField(createdDoc.id, fieldName, fieldValue);
-
- console.log(`DocumentMetadataTool: Edit field result for ${fieldName}:`, result);
-
- // Add to results
- results.push(result);
-
- // Update success status
- if (!result.success) {
- allSuccessful = false;
- }
- }
-
- // Format edit results
- fieldEditsResults = {
- count: edits.length,
- success: allSuccessful,
- results,
- };
- }
- } catch (error) {
- console.error('Error applying fieldEdits during document creation:', error);
- fieldEditsResults = {
- error: `Error applying fieldEdits: ${error instanceof Error ? error.message : String(error)}`,
- };
- }
- }
-
// Get the created document's metadata
const createdMetadata = this.getDocumentMetadata(createdDoc.id);
- // Build the response text with fieldEdits results if available
- let responseText = `Document created successfully.
+ return [
+ {
+ type: 'text',
+ text: `Document created successfully.
Document ID: ${createdDoc.id}
Type: ${docType}
Title: "${title}"
-The document has been created with default dimensions and positioning.`;
-
- // Add field edits results if available
- if (fieldEditsResults) {
- if ('error' in fieldEditsResults) {
- responseText += `\n\nAttempted to apply additional field edits but encountered an error: ${fieldEditsResults.error}`;
- } else {
- responseText += `\n\nAdditional properties applied: ${fieldEditsResults.count} field(s) ${fieldEditsResults.success ? 'successfully updated' : 'with some errors'}`;
-
- if (fieldEditsResults.results && fieldEditsResults.results.length > 0) {
- responseText += '\nField edit results:';
- fieldEditsResults.results.forEach(result => {
- if (result.success) {
- responseText += `\n- Field '${result.originalFieldName}': updated to ${JSON.stringify(result.newValue)}`;
- if (result.warning) {
- responseText += ` (Warning: ${result.warning})`;
- }
- } else {
- responseText += `\n- Error editing '${result.originalFieldName}': ${result.message}`;
- }
- });
- }
- }
- }
+The document has been created with default dimensions and positioning.
+You can now use the "edit" action to modify additional properties of this document.
- responseText += `\n\nNext steps:
+Next steps:
1. Use the "getFieldOptions" action to understand available editable/addable fields/properties and their dependencies.
2. To modify this document, use: { action: "edit", documentId: "${createdDoc.id}", fieldEdits: [{"fieldName":"property","fieldValue":"value"}] }
3. To add styling, consider setting backgroundColor, fontColor, or other properties
4. For text documents, you can edit the content with: { action: "edit", documentId: "${createdDoc.id}", fieldEdits: [{"fieldName":"text","fieldValue":"New content"}] }
Full metadata for the created document:
-${JSON.stringify(createdMetadata, null, 2)}`;
-
- return [
- {
- type: 'text',
- text: responseText,
+${JSON.stringify(createdMetadata, null, 2)}`,
},
];
} catch (error) {
@@ -1394,41 +1291,7 @@ ${JSON.stringify(createdMetadata, null, 2)}`;
// For create action, validate required parameters
if (params.action === 'create') {
- // Validate required base parameters
- if (!(params.title && params.data && params.doc_type)) {
- return false;
- }
-
- // If fieldEdits is provided, validate its structure
- if (params.fieldEdits) {
- try {
- // Parse fieldEdits and validate its structure
- const edits = JSON.parse(String(params.fieldEdits));
-
- // Ensure it's an array
- if (!Array.isArray(edits)) {
- console.log('fieldEdits is not an array');
- return false;
- }
-
- // Ensure each item has fieldName and fieldValue
- for (const edit of edits) {
- if (!edit.fieldName) {
- console.log('An edit is missing fieldName');
- return false;
- }
- if (edit.fieldValue === undefined) {
- console.log('An edit is missing fieldValue');
- return false;
- }
- }
- } catch (error) {
- console.log('Error parsing fieldEdits:', error);
- return false;
- }
- }
-
- return true;
+ return !!(params.title && params.data && params.doc_type);
}
// For edit action, validate fieldEdits is provided
@@ -1505,7 +1368,7 @@ ${JSON.stringify(createdMetadata, null, 2)}`;
case 'getFieldOptions':
return 'The "getFieldOptions" action does not require any additional parameters. It returns metadata about all available document fields.';
case 'create':
- return 'The "create" action requires title, data, and doc_type parameters. You can optionally include fieldEdits to set additional properties during creation.';
+ return 'The "create" action requires title, data, and doc_type parameters.';
default:
return `Unknown action "${action}". Valid actions are "get", "edit", "list", "getFieldOptions", or "create".`;
}