aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx69
-rw-r--r--src/client/views/nodes/chatbot/types/types.ts3
-rw-r--r--src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts3
3 files changed, 12 insertions, 63 deletions
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 35dbee3e9..b11bf7405 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -593,7 +593,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
});
// Try to find the document
- const linkedDocs = this.linkedDocs;
let doc: Doc | undefined;
// First try to find the document using the document manager's chunk ID lookup
@@ -603,25 +602,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
console.log(`Found document by chunk ID lookup: ${parentDocId}`);
}
- // If not found, fall back to searching through linked docs (maintains compatibility)
- if (!doc) {
- for (const linkedDoc of linkedDocs) {
- if (linkedDoc.chunk_simpl) {
- try {
- const docChunkSimpl = JSON.parse(StrCast(linkedDoc.chunk_simpl)) as { chunks: SimplifiedChunk[] };
- const foundChunk = docChunkSimpl.chunks.find(chunk => chunk.chunkId === chunkId);
- if (foundChunk) {
- doc = linkedDoc;
- console.log(`Found document by iterating through linked docs`);
- break;
- }
- } catch (e) {
- console.error(`Error parsing chunk_simpl for doc ${linkedDoc.id}:`, e);
- }
- }
- }
- }
-
if (!doc) {
console.warn(`Document not found for citation with chunk_id: ${chunkId}`);
return;
@@ -641,29 +621,16 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// Handle different chunk types
if (foundChunk) {
console.log(`Found chunk in document:`, foundChunk);
-
- // Handle video chunks
- if (foundChunk.chunkType === CHUNK_TYPE.VIDEO) {
- if (foundChunk.start_time !== undefined) {
- await this.goToMediaTimestamp(doc, foundChunk.start_time, 'video');
+ if (foundChunk.chunkType === CHUNK_TYPE.AUDIO || foundChunk.chunkType === CHUNK_TYPE.VIDEO) {
+ const directMatchSegmentStart = this.getDirectMatchingSegmentStart(doc, citation.direct_text || '', foundChunk.indexes || []);
+ if (directMatchSegmentStart) {
+ await this.goToMediaTimestamp(doc, directMatchSegmentStart, foundChunk.chunkType);
} else {
- console.warn('Video chunk missing start_time:', foundChunk);
+ console.error('No direct matching segment found for the citation.');
}
- }
- // Handle audio chunks - note that we're using string comparison since 'audio' isn't in CHUNK_TYPE enum
- else if (String(foundChunk.chunkType).toLowerCase() === 'audio') {
- if (foundChunk.start_time !== undefined) {
- await this.goToMediaTimestamp(doc, foundChunk.start_time, 'audio');
- } else {
- console.warn('Audio chunk missing start_time:', foundChunk);
- }
- }
- // Handle table or image chunks
- else if (foundChunk.chunkType === CHUNK_TYPE.TABLE || foundChunk.chunkType === CHUNK_TYPE.IMAGE) {
+ } else if (foundChunk.chunkType === CHUNK_TYPE.TABLE || foundChunk.chunkType === CHUNK_TYPE.IMAGE) {
this.handleOtherChunkTypes(foundChunk, citation, doc);
- }
- // Handle text chunks
- else if (foundChunk.chunkType === CHUNK_TYPE.TEXT) {
+ } else if (foundChunk.chunkType === CHUNK_TYPE.TEXT) {
// Find text from the document's chunks metadata
let chunkText = '';
@@ -691,33 +658,15 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// Handle URL chunks
else if (foundChunk.chunkType === CHUNK_TYPE.URL) {
if (foundChunk.url) {
- // Instead of opening the URL in a new window, show the document in the viewer
DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
console.log(`Navigated to web document with URL: ${foundChunk.url}`);
} else {
console.warn('URL chunk missing URL:', foundChunk);
}
}
- } else if (doc?.original_segments) {
- // Handle original segments for media files
- let original_segments: any[] = [];
- try {
- original_segments = JSON.parse(StrCast(doc.original_segments));
- } catch (e) {
- console.error(`Error parsing original_segments:`, e);
- return;
- }
-
- // Check if there's direct text to find in the segments
- if (citation.direct_text) {
- // Find the segment that contains the direct text
- const start = this.getDirectMatchingSegmentStart(doc, citation.direct_text, []);
- if (start !== -1) {
- await this.goToMediaTimestamp(doc, start, doc.ai_type === 'audio' ? 'audio' : 'video');
- }
- }
} else {
- console.warn('Unable to find chunk or segments for citation', citation);
+ console.warn('Navigating to doc. Unable to find chunk or segments for citation', citation);
+ DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
}
} catch (error) {
console.error('Error handling citation click:', error);
diff --git a/src/client/views/nodes/chatbot/types/types.ts b/src/client/views/nodes/chatbot/types/types.ts
index dcb132ec7..90b5e7e11 100644
--- a/src/client/views/nodes/chatbot/types/types.ts
+++ b/src/client/views/nodes/chatbot/types/types.ts
@@ -15,8 +15,9 @@ export enum CHUNK_TYPE {
TABLE = 'table',
URL = 'url',
CSV = 'CSV',
- MEDIA = 'media',
+ //MEDIA = 'media',
VIDEO = 'video',
+ AUDIO = 'audio',
}
export enum PROCESSING_TYPE {
diff --git a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
index 4bb61d8b2..4512ae3e6 100644
--- a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
+++ b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
@@ -137,7 +137,6 @@ export class Vectorstore {
});
doc.original_segments = JSON.stringify(typedResponse.full);
- doc.ai_type = local_file_path.endsWith('.mp3') ? 'audio' : 'video';
const doc_id = uuidv4();
// Register the document with the AgentDocumentManager
@@ -167,7 +166,7 @@ export class Vectorstore {
start_time: chunk.start,
end_time: chunk.end,
text: chunk.text,
- type: CHUNK_TYPE.VIDEO,
+ type: local_file_path.endsWith('.mp3') ? CHUNK_TYPE.AUDIO : CHUNK_TYPE.VIDEO,
},
})),
type: 'media',