aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx32
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts190
2 files changed, 172 insertions, 50 deletions
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 7b7431bbe..0939247b7 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -434,23 +434,37 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// Create an array of promises for each document
const childDocPromises = data.map(async doc => {
const parsedDoc = JSON.parse(doc);
-
+ console.log('Parse #3: ' + parsedDoc);
if (parsedDoc.doc_type !== 'collection') {
// Handle non-collection documents
return await this.whichDoc(parsedDoc.doc_type, parsedDoc.data, parsedDoc.options, parsedDoc.id);
} else {
// Recursively process collections
- const nestedDocs = await this.createCollectionWithChildren(parsedDoc.data);
- return nestedDocs; // This will return an array of Docs
+ const nestedDocs = await this.createCollectionWithChildren(JSON.parse(parsedDoc.data) as string[]);
+ const collectionOptions: DocumentOptions = {
+ title: parsedDoc.title,
+ backgroundColor: parsedDoc.background_color,
+ _width: parsedDoc.width,
+ _height: parsedDoc.height,
+ _layout_fitWidth: true,
+ _freeform_backgroundGrid: true,
+ };
+ const collectionDoc = DocCast(Docs.Create.FreeformDocument(nestedDocs, collectionOptions));
+ return collectionDoc; // Return th
}
});
// Await all child document creations concurrently
const nestedResults = await Promise.all(childDocPromises);
-
+ console.log('n' + nestedResults);
// Flatten any nested arrays from recursive collection calls
- const childDocs = nestedResults.flat();
-
+ const childDocs = nestedResults.flat() as Doc[];
+ console.log('c' + childDocs);
+ childDocs.forEach(doc => {
+ console.log(DocCast(doc));
+ console.log(DocCast(doc)[DocData].data);
+ console.log(DocCast(doc)[DocData].data);
+ });
return childDocs;
};
@@ -478,8 +492,12 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
break;
case 'collection': {
const par = JSON.parse(data);
+ console.log('Parse #2: ' + par);
const arr = await this.createCollectionWithChildren(par);
- doc = DocCast(Docs.Create.FreeformDocument(arr, options));
+ options._layout_fitWidth = true;
+ options._freeform_backgroundGrid = true;
+ const opts = { _width: 500, _height: 800, _layout_fitWidth: true, _freeform_backgroundGrid: true };
+ doc = DocCast(Docs.Create.FreeformDocument(arr, opts));
break;
}
case 'web':
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
index 4c5d4dc7d..a1924ed82 100644
--- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -3,55 +3,153 @@ import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
import { ParametersType } from '../types/tool_types';
import { DocumentOptions } from '../../../../documents/Documents';
-const docInstructions = {
- collection: {
- description: 'A recursive collection of documents. Each document can be a "text", "flashcard", "image", "web", or another "collection".',
- example: [
+const jsonData = [
+ {
+ doc_type: 'collection',
+ title: 'Science Collection',
+ data: JSON.stringify([
+ {
+ doc_type: 'flashcard',
+ title: 'Photosynthesis',
+ data: JSON.stringify({ 'What is photosynthesis?': 'The process by which plants make food.' }),
+ width: 300,
+ height: 300,
+ backgroundColor: '#0000FF',
+ },
+ {
+ 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: 'Science Collection',
- data: [
+ title: 'Advanced Biology',
+ data: JSON.stringify([
{
doc_type: 'flashcard',
- title: 'Photosynthesis',
- data: { 'What is photosynthesis?': 'The process by which plants make food.' },
+ title: 'Respiration',
+ data: JSON.stringify({ 'What is respiration?': 'Conversion of oxygen and glucose to energy.' }),
width: 300,
height: 300,
},
{
doc_type: 'text',
- title: 'Water Cycle',
- data: 'The continuous movement of water on, above, and below the Earth’s surface.',
+ title: 'Cell Structure',
+ data: 'Cells are the basic building blocks of all living organisms.',
+ width: 300,
+ height: 300,
+ },
+ ]),
+ width: 600,
+ height: 600,
+ },
+ ]),
+ width: 600,
+ height: 600,
+ },
+ {
+ doc_type: 'collection',
+ title: 'Math Collection',
+ data: JSON.stringify([
+ {
+ doc_type: 'flashcard',
+ title: 'Pythagorean Theorem',
+ data: JSON.stringify({ 'What is the Pythagorean theorem?': 'In a right triangle, a² + b² = c².' }),
+ width: 300,
+ height: 300,
+ backgroundColor: '#FFA500',
+ },
+ {
+ doc_type: 'text',
+ title: 'Calculus Introduction',
+ data: 'Calculus is the mathematical study of continuous change.',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'collection',
+ title: 'Algebra Concepts',
+ data: JSON.stringify([
+ {
+ doc_type: 'flashcard',
+ title: 'Quadratic Formula',
+ data: JSON.stringify({ 'What is the quadratic formula?': 'x = (-b ± √(b² - 4ac)) / 2a' }),
width: 300,
height: 300,
},
{
- doc_type: 'collection',
- title: 'Advanced Biology',
- data: [
- {
- doc_type: 'flashcard',
- title: 'Respiration',
- data: { 'What is respiration?': 'Conversion of oxygen and glucose to energy.' },
- width: 300,
- height: 300,
- },
- {
- doc_type: 'text',
- title: 'Cell Structure',
- data: 'Cells are the basic building blocks of all living organisms.',
- width: 300,
- height: 300,
- },
- ],
- width: 600,
- height: 600,
+ doc_type: 'text',
+ title: 'Linear Equations',
+ data: 'A linear equation is an equation between two variables that gives a straight line when plotted.',
+ width: 300,
+ height: 300,
},
- ],
+ ]),
width: 600,
height: 600,
},
- ],
+ ]),
+ width: 600,
+ height: 600,
+ },
+];
+
+// Stringify the entire object if needed for your API
+const finalJsonString = JSON.stringify(jsonData);
+
+const docInstructions = {
+ collection: {
+ description: 'A recursive collection of documents. Each document can be a "text", "flashcard", "image", "web", or another "collection".',
+ example: finalJsonString,
+ // example: [
+ // {
+ // doc_type: 'collection',
+ // title: 'Science Collection',
+ // data: [
+ // {
+ // doc_type: 'flashcard',
+ // title: 'Photosynthesis',
+ // data: { 'What is photosynthesis?': 'The process by which plants make food.' },
+ // width: 300,
+ // height: 300,
+ // backgroundColor: '#0000FF',
+ // },
+ // {
+ // 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: 'flashcard',
+ // title: 'Respiration',
+ // data: { 'What is respiration?': 'Conversion of oxygen and glucose to energy.' },
+ // width: 300,
+ // height: 300,
+ // },
+ // {
+ // doc_type: 'text',
+ // title: 'Cell Structure',
+ // data: 'Cells are the basic building blocks of all living organisms.',
+ // width: 300,
+ // height: 300,
+ // },
+ // ],
+ // width: 600,
+ // height: 600,
+ // },
+ // ],
+ // width: 600,
+ // height: 600,
+ // },
+ // ],
},
text: 'Provide text content as a plain string. Example: "This is a standalone text document."',
flashcard: 'A dictionary mapping the front to the back of the flashcard. Example: {"Question":"Answer"}',
@@ -63,7 +161,7 @@ const docInstructions = {
const createDocToolParams = [
{
name: 'data',
- type: 'any', // Accepts either string or array, supporting individual and nested data
+ type: 'string', // Accepts either string or array, supporting individual and nested data
description: docInstructions,
required: true,
},
@@ -113,7 +211,10 @@ const createListDocToolParams = [
'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: ["{"doc_type":"collection","title":"Science Topics","data":["{\\"doc_type\\":\\"text\\",\\"title\\":\\"Photosynthesis\\",\\"data\\":\\"Photosynthesis is the process by which plants make food.\\",\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"collection\\",\\"title\\":\\"Advanced Biology\\",\\"data\\":["{\\"doc_type\\":\\"flashcard\\",\\"title\\":\\"Respiration\\",\\"data\\":{\\"What is respiration?\\":\\"Conversion of oxygen and glucose to energy.\\"},\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"text\\",\\"title\\":\\"Cell Structure\\",\\"data\\":\\"Cells are the basic building blocks of all living organisms.\\",\\"width\\":300,\\"height\\":300}"],\\"width\\":600,\\"height\\":600}"],"width":600,"height":600}"]',
+ '. Example: ' + finalJsonString,
+ //Example: ["{"doc_type":"collection","title":"Science Topics","data":"[\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Photosynthesis\\\\",\\\\"background_color\\\\":\\\\"#0000FF\\\\",\\\\"data\\\\":\\\\"Photosynthesis is the process by which plants make food.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\"{\\\\"doc_type\\\\":\\\\"collection\\\\",\\\\"title\\\\":\\\\"Advanced Biology\\\\",\\\\"data\\\\":\\\\"[\\\\"{\\\\"doc_type\\\\":\\\\"flashcard\\\\",\\\\"title\\\\":\\\\"Respiration\\\\",\\\\"data\\\\":{\\\\"What is respiration?\\\\":\\\\"Conversion of oxygen and glucose to energy.\\\\"},\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Cell Structure\\\\",\\\\"data\\\\":\\\\"Cells are the basic building blocks of all living organisms.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\"]\\\\",\\\\"width\\\\":600,\\\\"height\\\\":600}\\"]","width":600,"height":600}"]',
+
+ //["{"doc_type":"collection","title":"Science Topics","data":["{\\"doc_type\\":\\"text\\",\\"title\\":\\"Photosynthesis\\",\\"data\\":\\"Photosynthesis is the process by which plants make food.\\",\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"collection\\",\\"title\\":\\"Advanced Biology\\",\\"data\\":["{\\"doc_type\\":\\"flashcard\\",\\"title\\":\\"Respiration\\",\\"data\\":{\\"What is respiration?\\":\\"Conversion of oxygen and glucose to energy.\\"},\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"text\\",\\"title\\":\\"Cell Structure\\",\\"data\\":\\"Cells are the basic building blocks of all living organisms.\\",\\"width\\":300,\\"height\\":300}"],\\"width\\":600,\\"height\\":600}"],"width":600,"height":600}"]',
required: true,
},
] as const;
@@ -138,26 +239,29 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
}
async execute(args: ParametersType<CreateListDocToolParamsType>): Promise<Observation[]> {
-
/**
- * loop through each collection calling the
+ * loop through each collection calling the
*/
-
try {
- console.log('EXE' + args.docs);
+ // console.log('EXE' + args.docs);
const parsedDoc = JSON.parse(args.docs);
console.log('parsed' + parsedDoc);
parsedDoc.forEach((firstDoc: string) => {
- console.log('THIS DOC' + firstDoc);
+ // console.log('THIS DOC' + firstDoc);
console.log(typeof firstDoc);
const doc = JSON.parse(firstDoc);
console.log('NEW DOC' + doc);
- console.log('TYPE' + doc['doc_type']);
- console.log('WIDTH' + doc['width']);
- console.log('HEIGHT' + doc['height']);
+ // console.log('TYPE' + doc['doc_type']);
+ // console.log('WIDTH' + doc['width']);
+ // console.log('HEIGHT' + doc['height']);
- this._addLinkedDoc(doc['doc_type'], doc['data'], { title: doc['title'], backgroundColor: doc['background_color'], text_fontColor: doc['font_color'], _layout_fitWidth: false, _layout_autoHeight: true }, uuidv4());
+ this._addLinkedDoc(
+ doc['doc_type'],
+ doc['data'],
+ { title: doc['title'], backgroundColor: doc['background_color'], text_fontColor: doc['font_color'], _width: doc['width'], _height: doc['height'], _layout_fitWidth: false, _layout_autoHeight: true },
+ uuidv4()
+ );
});
// this._addLinkedDoc(args.doc_type, args.data, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4());
return [{ type: 'text', text: 'Created document.' }];