From 98d0bba3e59ab7ec9dfbf5e6c9c58e6ac1d22ae3 Mon Sep 17 00:00:00 2001
From: "A.J. Shulman" <Shulman.aj@gmail.com>
Date: Thu, 17 Oct 2024 17:41:47 -0400
Subject: added create text doc tool with font color and background color and
 fixed no tool

---
 .../nodes/chatbot/chatboxcomponents/ChatBox.tsx    | 32 ++++++++++++++--------
 1 file changed, 21 insertions(+), 11 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 44c231c87..118d20153 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -20,7 +20,7 @@ import { CsvCast, DocCast, PDFCast, RTFCast, StrCast } from '../../../../../fiel
 import { Networking } from '../../../../Network';
 import { DocUtils } from '../../../../documents/DocUtils';
 import { DocumentType } from '../../../../documents/DocumentTypes';
-import { Docs } from '../../../../documents/Documents';
+import { Docs, DocumentOptions } from '../../../../documents/Documents';
 import { DocumentManager } from '../../../../util/DocumentManager';
 import { LinkManager } from '../../../../util/LinkManager';
 import { ViewBoxAnnotatableComponent } from '../../../DocComponent';
@@ -89,7 +89,7 @@ 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.createCSVInDash);
+        this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createTextDocInDash, this.createCSVInDash);
         this.messagesRef = React.createRef<HTMLDivElement>();
 
         // Reaction to update dataDoc when chat history changes
@@ -410,6 +410,23 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
         this.addCSVForAnalysis(doc, id);
     };
 
+    /**
+     * Creates a text document in the dashboard and adds it for analysis.
+     * @param title The title of the doc.
+     * @param text_content The text of the document.
+     * @param options Other optional document options (e.g. color)
+     * @param id The unique ID for the document.
+     */
+    @action
+    createTextDocInDash = async (text_content: string, options: DocumentOptions, id: string) => {
+        const doc = DocCast(Docs.Create.TextDocument(text_content, options));
+        const linkDoc = Docs.Create.LinkDocument(this.Document, doc);
+        LinkManager.Instance.addLink(linkDoc);
+
+        doc && this._props.addDocument?.(doc);
+        await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
+    };
+
     /**
      * Event handler to manage citations click in the message components.
      * @param citation The citation object clicked by the user.
@@ -709,17 +726,10 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                 </div>
                 <div className="chat-messages" ref={this.messagesRef}>
                     {this.history.map((message, index) => (
-                        <MessageComponentBox key={index} message={message} index={index} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
+                        <MessageComponentBox key={index} message={message} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
                     ))}
                     {this.current_message && (
-                        <MessageComponentBox
-                            key={this.history.length}
-                            message={this.current_message}
-                            index={this.history.length}
-                            onFollowUpClick={this.handleFollowUpClick}
-                            onCitationClick={this.handleCitationClick}
-                            updateMessageCitations={this.updateMessageCitations}
-                        />
+                        <MessageComponentBox key={this.history.length} message={this.current_message} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
                     )}
                 </div>
                 <form onSubmit={this.askGPT} className="chat-input">
-- 
cgit v1.2.3-70-g09d2

