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.ts22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts b/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
index dcb708450..088891022 100644
--- a/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
+++ b/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
@@ -27,6 +27,7 @@ interface AgentDocument {
export class AgentDocumentManager {
@observable private documentsById: ObservableMap<string, AgentDocument>;
private chatBox: ChatBox;
+ private parentView: DocumentView;
private chatBoxDocument: Doc | null = null;
private fieldMetadata: Record<string, any> = {}; // bcz: CHANGE any to a proper type!
@observable private simplifiedChunks: ObservableMap<string, SimplifiedChunk>;
@@ -35,8 +36,9 @@ export class AgentDocumentManager {
* Creates a new DocumentManager
* @param templateDocument The document that serves as a template for new documents
*/
- constructor(chatBox: ChatBox) {
+ constructor(chatBox: ChatBox, parentView: DocumentView) {
makeObservable(this);
+ this.parentView = parentView;
const agentDoc = DocCast(chatBox.Document.agentDocument) ?? new Doc();
const chunk_simpl = DocCast(agentDoc.chunk_simpl) ?? new Doc();
@@ -164,6 +166,10 @@ export class AgentDocumentManager {
}
}
+ public get parentViewDocument(): DocumentView {
+ return this.parentView;
+ }
+
/**
* Process a document by ensuring it has an ID and adding it to the appropriate collections
* @param doc The document to process
@@ -851,6 +857,7 @@ export class AgentDocumentManager {
try {
// Create simple document with just title and data
const simpleDoc: parsedDoc = {
+ ...(options as parsedDoc), // bcz: hack .. why do we need parsedDoc and not DocumentOptions here?
doc_type: docType,
title: options?.title ?? `Untitled Document ${this.documentsById.size + 1}`,
data: data,
@@ -1011,6 +1018,19 @@ export class AgentDocumentManager {
const docInfo = this.documentsById.get(docId);
return docInfo?.dataDoc;
}
+
+ // In AgentDocumentManager
+ private descriptionCache = new Map<string, string>();
+
+ public async getDocDescription(id: string): Promise<string> {
+ if (!this.descriptionCache.has(id)) {
+ const doc = this.getDocument(id)!;
+ const desc = await Doc.getDescription(doc);
+ this.descriptionCache.set(id, desc.replace(/\n/g, ' ').trim());
+ }
+ return this.descriptionCache.get(id)!;
+ }
+
/**
* Adds simplified chunks to a document for citation handling
* @param doc The document to add simplified chunks to