diff options
author | Joanne <zehan_ding@brown.edu> | 2025-06-22 23:12:46 -0400 |
---|---|---|
committer | Joanne <zehan_ding@brown.edu> | 2025-06-22 23:12:46 -0400 |
commit | 17ec2a19b2d2dc5ba3f99c43d86c27946de2ac71 (patch) | |
tree | efb55f2b186f0636caefc8dd8680f918d1ddbb25 /src/client/views/nodes/chatbot/tools/TutorialTool.ts | |
parent | 61787b3c1cf53c0230f6142bee0df30c65971012 (diff) |
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
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/TutorialTool.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/TutorialTool.ts | 39 |
1 files changed, 23 insertions, 16 deletions
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<typeof generateTutorialNodeToolPara parameterRules: generateTutorialNodeToolParams, citationRules: "No citation needed for this tool's output.", }; -const applyFormatting = (markdownText: string): { doc: any; plainText: string } => { + +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<typeof generateTutorialNodeToolParams> { - 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<typeof generateTutorialNodeToolParams>): Promise<Observation[]> { @@ -158,7 +165,7 @@ export class GPTTutorialTool extends BaseTool<typeof generateTutorialNodeToolPar // Build the ProseMirror‐in‐JSON + plain-text for RichTextField const rtfData = { - doc: (doc as any).toJSON ? (doc as any).toJSON() : doc, + doc: doc.toJSON ? doc.toJSON() : doc, selection: { type: 'text', anchor: 0, head: 0 }, storedMarks: [], }; |