aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts')
-rw-r--r--src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts b/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
index 088891022..a96d93a25 100644
--- a/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
+++ b/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
@@ -10,6 +10,7 @@ import { DocumentManager } from '../../../../util/DocumentManager';
import { LinkManager, UPDATE_SERVER_CACHE } from '../../../../util/LinkManager';
import { DocumentView } from '../../DocumentView';
import { ChatBox, parsedDoc } from '../chatboxcomponents/ChatBox';
+import { CanvasDocsTool } from '../tools/CanvasDocsTool';
import { supportedDocTypes } from '../types/tool_types';
import { CHUNK_TYPE, RAGChunk, SimplifiedChunk } from '../types/types';
@@ -29,6 +30,7 @@ export class AgentDocumentManager {
private chatBox: ChatBox;
private parentView: DocumentView;
private chatBoxDocument: Doc | null = null;
+ @observable private _useCanvasMode: boolean = false;
private fieldMetadata: Record<string, any> = {}; // bcz: CHANGE any to a proper type!
@observable private simplifiedChunks: ObservableMap<string, SimplifiedChunk>;
@@ -133,6 +135,74 @@ export class AgentDocumentManager {
}
/**
+ * Toggle between linked documents mode and canvas mode
+ */
+ @action
+ public setCanvasMode(useCanvas: boolean) {
+ this._useCanvasMode = useCanvas;
+ console.log(`[AgentDocumentManager] Canvas mode ${useCanvas ? 'enabled' : 'disabled'}`);
+
+ // Reinitialize documents based on new mode
+ if (useCanvas) {
+ this.initializeCanvasDocuments();
+ } else {
+ this.initializeFindDocsFreeform();
+ }
+ }
+
+ /**
+ * Get current canvas mode status
+ */
+ public get useCanvasMode(): boolean {
+ return this._useCanvasMode;
+ }
+
+ /**
+ * Get current canvas mode status (for external access)
+ */
+ public getCanvasMode(): boolean {
+ return this._useCanvasMode;
+ }
+
+ /**
+ * Initialize documents from the entire canvas
+ */
+ @action
+ public initializeCanvasDocuments() {
+ try {
+ console.log('[AgentDocumentManager] Finding all documents on canvas...');
+ console.log('[AgentDocumentManager] Canvas mode enabled, looking for all documents...');
+
+ // Get all canvas documents using CanvasDocsTool
+ const canvasDocs = CanvasDocsTool.getAllCanvasDocuments(false);
+ console.log(`[AgentDocumentManager] Found ${canvasDocs.length} documents on canvas`);
+
+ if (canvasDocs.length === 0) {
+ console.warn('[AgentDocumentManager] No documents found on canvas. This might indicate:');
+ console.warn(' 1. No documents are currently rendered/visible');
+ console.warn(' 2. All documents are considered "system" documents');
+ console.warn(' 3. DocumentView.allViews() is not returning expected results');
+
+ // Let's also try including system docs to see if that's the issue
+ const canvasDocsWithSystem = CanvasDocsTool.getAllCanvasDocuments(true);
+ console.log(`[AgentDocumentManager] With system docs included: ${canvasDocsWithSystem.length} documents`);
+ }
+
+ // Process each canvas document
+ canvasDocs.forEach(async (doc: Doc) => {
+ if (doc && doc !== this.chatBoxDocument) { // Don't process the chatbox itself
+ console.log('[AgentDocumentManager] Processing canvas document:', doc.id, doc.title, doc.type);
+ await this.processDocument(doc);
+ console.log('[AgentDocumentManager] Completed processing document:', doc.id);
+ }
+ });
+
+ } catch (error) {
+ console.error('[AgentDocumentManager] Error finding documents on canvas:', error);
+ }
+ }
+
+ /**
* Gets all documents in the same Freeform view as the ChatBox
* Uses the LinkManager to get all linked documents, similar to how ChatBox does it
*/