import { v4 as uuidv4 } from 'uuid'; import { BaseTool } from './BaseTool'; import { Observation } from '../types/types'; import { ParametersType } from '../types/tool_types'; import { DocumentOptions } from '../../../../documents/Documents'; const example = [ { doc_type: 'deck', title: 'Chemistry', data: [ { doc_type: 'flashcard', title: 'Photosynthesis', data: [ { doc_type: 'text', title: 'front_Photosynthesis', data: 'What is photosynthesis?', width: 300, height: 300, }, { doc_type: 'text', title: 'back_photosynthesis', data: 'The process by which plants make food.', width: 300, height: 300, }, ], backgroundColor: '#00ff00', width: 300, height: 300, }, { doc_type: 'flashcard', title: 'Photosynthesis', data: [ { doc_type: 'text', title: 'front_Photosynthesis', data: 'What is photosynthesis?', width: 300, height: 300, }, { doc_type: 'text', title: 'back_photosynthesis', data: 'The process by which plants make food.', width: 300, height: 300, }, ], backgroundColor: '#00ff00', width: 300, height: 300, }, ], backgroundColor: '#00ff00', width: 600, height: 600, }, { doc_type: 'web', title: 'Brown University Wikipedia', data: 'https://en.wikipedia.org/wiki/Brown_University', width: 300, height: 300, }, { doc_type: 'collection', title: 'Science Collection', data: [ { doc_type: 'web', title: 'Brown University Wikipedia', data: 'https://en.wikipedia.org/wiki/Brown_University', width: 300, height: 300, }, { doc_type: 'flashcard', title: 'Photosynthesis', data: [ { doc_type: 'text', title: 'front_Photosynthesis', data: 'What is photosynthesis?', width: 300, height: 300, }, { doc_type: 'text', title: 'back_photosynthesis', data: 'The process by which plants make food.', width: 300, height: 300, }, ], backgroundColor: '#00ff00', width: 300, height: 300, }, { doc_type: 'text', title: 'Water Cycle', data: 'The continuous movement of water on, above, and below the Earth’s surface.', width: 300, height: 300, }, { doc_type: 'collection', title: 'Advanced Biology', data: [ { doc_type: 'text', title: 'Cell Structure', data: 'Cells are the basic building blocks of all living organisms.', width: 300, height: 300, }, ], backgroundColor: '#00ff00', width: 600, height: 600, }, ], width: 600, height: 600, }, ]; // Stringify the entire structure for transmission if needed const finalJsonString = JSON.stringify(example); const docInstructions = { collection: { description: 'A recursive collection of documents as a stringified array. Each document can be a "text", "flashcard", "image", "web", "image", "comparison", "equation", "noteboard", "simulation", "diagram", "map", "screengrab", "webcam", "button", or another "collection".', example: finalJsonString, }, text: 'Provide text content as a plain string. Example: "This is a standalone text document."', flashcard: 'Two text documents with content for the front and back.', deck: 'A decks data is an array of flashcards.', image: 'A URL to an image for data. Example: "https://example.com/image.jpg"', web: 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University', equation: 'Create a equation document.', noteboard: 'Create a noteboard document', comparison: 'Create a comparison document', simulation: 'Create a simulation document', } as const; const createDocToolParams = [ { name: 'data', type: 'string', // Accepts either string or array, supporting individual and nested data description: docInstructions, required: true, }, { name: 'doc_type', type: 'string', description: 'The type of the document. Options: "collection", "text", "flashcard", "image", "web".', 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, }, { name: 'width', type: 'number', description: 'The width of the document in pixels.', required: true, }, { name: 'height', type: 'number', description: 'The height of the document in pixels.', required: true, }, ] as const; const createListDocToolParams = [ { name: 'docs', type: 'string', // Array of stringified JSON objects description: 'Array of documents in stringified JSON format. Each item in the array should be an individual stringified JSON object. Each document can be of type "text", "flashcard", "image", "web", or "collection" (for nested documents). ' + 'Use this structure for nesting collections within collections. Each document should follow the structure in ' + createDocToolParams + '. Example: ' + finalJsonString, required: true, }, ] as const; type CreateListDocToolParamsType = typeof createListDocToolParams; export class CreateDocTool extends BaseTool { private _addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void; constructor(addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void) { super( 'createDoc', 'Creates one or more documents that best fit users request with input following the example below. Or creates a dashboard of many documents/collections.', createListDocToolParams, 'Modify the data parameter and include title (and optionally color) for the document. Web doc data type must be url from search tool.', 'Creates one or more documents represented by an array of strings with the provided content based on the instructions ' + docInstructions + 'Use if the user wants to create something that aligns with a document type in dash like a flashcard, flashcard deck/stack, or textbox or text document of some sort. Can use after the search tool to save information.' + 'When user asks for dashboard, create many documents/collections with different colors and texts while listening to their preferences, after using search tool to create a dashboard.' ); this._addLinkedDoc = addLinkedDoc; } async execute(args: ParametersType): Promise { try { console.log('EXE' + args.docs); const parsedDoc = JSON.parse(args.docs); console.log('parsed' + parsedDoc); parsedDoc.forEach(doc => { this._addLinkedDoc( doc['doc_type'], doc['data'], { title: doc['title'], backgroundColor: doc['backgroundColor'], text_fontColor: doc['font_color'], _width: doc['width'], _height: doc['height'], _layout_fitWidth: false, _layout_autoHeight: true }, uuidv4() ); }); return [{ type: 'text', text: 'Created document.' }]; } catch (error) { return [{ type: 'text', text: 'Error creating text document, ' + error }]; } } }