From 17ec2a19b2d2dc5ba3f99c43d86c27946de2ac71 Mon Sep 17 00:00:00 2001 From: Joanne Date: Sun, 22 Jun 2025 23:12:46 -0400 Subject: successfully merged documentationtext functionality with new version of agent, however still minor issues with the agent not selecting the proper tool for documentation generation without the additional context from the topbar --- .../views/nodes/chatbot/tools/TutorialTool.ts | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'src/client/views/nodes/chatbot/tools/TutorialTool.ts') diff --git a/src/client/views/nodes/chatbot/tools/TutorialTool.ts b/src/client/views/nodes/chatbot/tools/TutorialTool.ts index 08e4e1409..1624f0439 100644 --- a/src/client/views/nodes/chatbot/tools/TutorialTool.ts +++ b/src/client/views/nodes/chatbot/tools/TutorialTool.ts @@ -11,7 +11,9 @@ import { RichTextField } from '../../../../../fields/RichTextField'; import { DocumentViewInternal } from '../../DocumentView'; import { Docs } from '../../../../documents/Documents'; import { OpenWhere } from '../../OpenWhere'; -import { CollectionFreeFormView } from '../../../collections/collectionFreeForm'; +import { CollectionFreeFormView } from '../../../collections/collectionFreeForm/CollectionFreeFormView'; +import { AgentDocumentManager } from '../utils/AgentDocumentManager'; +import { Node as ProseMirrorNode } from 'prosemirror-model'; const generateTutorialNodeToolParams = [ { @@ -28,20 +30,26 @@ const generateTutorialNodeToolInfo: ToolInfo { + +interface FormattedDocument { + doc: ProseMirrorNode; + plainText: string; +} + +const applyFormatting = (markdownText: string): FormattedDocument => { const lines = markdownText.split('\n'); - const nodes: any[] = []; + const nodes: ProseMirrorNode[] = []; let plainText = ''; let i = 0; - let currentListItems: any[] = []; - let currentParagraph: any[] = []; - let currentOrderedListItems: any[] = []; + let currentListItems: ProseMirrorNode[] = []; + let currentParagraph: ProseMirrorNode[] = []; + let currentOrderedListItems: ProseMirrorNode[] = []; let inOrderedList = false; let inBulletList = false; - const processBoldText = (text: string) => { + const processBoldText = (text: string): ProseMirrorNode[] => { const boldRegex = /\*\*(.*?)\*\*/g; - const parts = []; + const parts: ProseMirrorNode[] = []; let lastIndex = 0; let match; @@ -58,7 +66,7 @@ const applyFormatting = (markdownText: string): { doc: any; plainText: string } return parts.length > 0 ? parts : [schema.text(text)]; }; - const flushListItems = () => { + const flushListItems = (): void => { if (currentListItems.length > 0) { nodes.push(schema.nodes.ordered_list.create({ mapStyle: 'bullet' }, currentListItems)); nodes.push(schema.nodes.paragraph.create()); @@ -73,14 +81,14 @@ const applyFormatting = (markdownText: string): { doc: any; plainText: string } } }; - const flushParagraph = () => { + const flushParagraph = (): void => { if (currentParagraph.length > 0) { nodes.push(schema.nodes.paragraph.create({}, currentParagraph)); currentParagraph = []; } }; - const processHeader = (line: string) => { + const processHeader = (line: string): boolean => { const headerMatch = line.match(/^(#{1,6})\s+(.+)$/); if (headerMatch) { const level = Math.min(headerMatch[1].length, 6); // Cap at h6 @@ -138,12 +146,11 @@ const applyFormatting = (markdownText: string): { doc: any; plainText: string } }; export class GPTTutorialTool extends BaseTool { - private _createDocInDash: (doc: parsedDoc) => Doc | undefined; + private _docManager: AgentDocumentManager; - constructor(createDocInDash: (doc: parsedDoc) => Doc | undefined) { + constructor(docManager: AgentDocumentManager) { super(generateTutorialNodeToolInfo); - - this._createDocInDash = createDocInDash; + this._docManager = docManager; } async execute(args: ParametersType): Promise { @@ -158,7 +165,7 @@ export class GPTTutorialTool extends BaseTool