aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/TutorialTool.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/TutorialTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/TutorialTool.ts39
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: [],
};