From 8bc8bd13293e64a99b68408ec3d24a50a5dfe4bc Mon Sep 17 00:00:00 2001
From: "A.J. Shulman" <Shulman.aj@gmail.com>
Date: Mon, 21 Apr 2025 14:23:38 -0400
Subject: feat & fix: citations now scroll to correct page and using OpenAI 4o
 with structured outputs

---
 .../nodes/chatbot/chatboxcomponents/ChatBox.tsx    | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 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 3152fe923..33419e559 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -107,21 +107,12 @@ 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
@@ -743,6 +734,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                         DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
                         return;
                     }
+
                     const x1 = parseFloat(values[0]) * Doc.NativeWidth(doc);
                     const y1 = parseFloat(values[1]) * Doc.NativeHeight(doc) + foundChunk.startPage * Doc.NativeHeight(doc);
                     const x2 = parseFloat(values[2]) * Doc.NativeWidth(doc);
@@ -751,9 +743,18 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                     const annotationKey = Doc.LayoutFieldKey(doc) + '_annotations';
 
                     const existingDoc = DocListCast(doc[DocData][annotationKey]).find(d => d.citation_id === citation.citation_id);
+                    if (existingDoc) {
+                        existingDoc.x = x1;
+                        existingDoc.y = y1;
+                        existingDoc._width = x2 - x1;
+                        existingDoc._height = y2 - y1;
+                    }
                     const highlightDoc = existingDoc ?? this.createImageCitationHighlight(x1, y1, x2, y2, citation, annotationKey, doc);
 
-                    DocumentManager.Instance.showDocument(highlightDoc, { willZoomCentered: true }, () => {});
+                    //doc.layout_scroll = y1;
+                    doc._layout_curPage = foundChunk.startPage + 1;
+                    DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
+                    //DocumentManager.Instance.showDocument(highlightDoc, { willZoomCentered: true }, () => {});
                 }
                 break;
             case CHUNK_TYPE.TEXT:
@@ -795,6 +796,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             backgroundColor: 'rgba(255, 255, 0, 0.5)',
         });
         highlight_doc[DocData].citation_id = citation.citation_id;
+        highlight_doc.freeform_scale = 1;
         Doc.AddDocToList(pdfDoc[DocData], annotationKey, highlight_doc);
         highlight_doc.annotationOn = pdfDoc;
         Doc.SetContainer(highlight_doc, pdfDoc);
-- 
cgit v1.2.3-70-g09d2

