From a99d8df26d331d87bae4f27cd52ce5ec4d97fa7a Mon Sep 17 00:00:00 2001
From: "A.J. Shulman" <Shulman.aj@gmail.com>
Date: Thu, 3 Apr 2025 11:45:02 -0400
Subject: attempt

---
 .../views/nodes/chatbot/chatboxcomponents/ChatBox.tsx | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

(limited to 'src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx')

diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 6e9307d37..065c2780c 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -43,6 +43,7 @@ import MessageComponentBox from './MessageComponent';
 import { ProgressBar } from './ProgressBar';
 import { OpenWhere } from '../../OpenWhere';
 import { Upload } from '../../../../../server/SharedMediaTypes';
+import { DocumentMetadataTool } from '../tools/DocumentMetadataTool';
 
 dotenv.config();
 
@@ -106,7 +107,21 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             this.vectorstore_id = StrCast(this.dataDoc.vectorstore_id);
         }
         this.vectorstore = new Vectorstore(this.vectorstore_id, this.retrieveDocIds);
-        this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createImageInDash, this.createDocInDash, this.createCSVInDash);
+        this.agent = new Agent(
+            this.vectorstore, 
+            this.retrieveSummaries, 
+            this.retrieveFormattedHistory, 
+            this.retrieveCSVData, 
+            this.addLinkedUrlDoc, 
+            this.createImageInDash, 
+            this.createDocInDash, 
+            this.createCSVInDash
+        );
+        
+        // Reinitialize the DocumentMetadataTool with a direct reference to this ChatBox instance
+        // This ensures the tool can properly access documents in the same Freeform view
+        this.agent.reinitializeDocumentMetadataTool(this);
+        
         this.messagesRef = React.createRef<HTMLDivElement>();
 
         // Reaction to update dataDoc when chat history changes
@@ -408,7 +423,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             if (doc) {
                 LinkManager.Instance.addLink(Docs.Create.LinkDocument(this.Document, doc));
                 this._props.addDocument?.(doc);
-                DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {}).then(() => this.addCSVForAnalysis(doc, id));
+                DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => this.addCSVForAnalysis(doc, id));
             }
         });
 
-- 
cgit v1.2.3-70-g09d2

