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.ts86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts b/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
index 3c8b49f33..dcb708450 100644
--- a/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
+++ b/src/client/views/nodes/chatbot/utils/AgentDocumentManager.ts
@@ -1,7 +1,5 @@
import { action, computed, makeObservable, observable, ObservableMap, reaction, runInAction } from 'mobx';
-import { observer } from 'mobx-react';
-import { v4 as uuidv4 } from 'uuid';
-import { Doc, StrListCast } from '../../../../../fields/Doc';
+import { Doc, FieldResult, StrListCast } from '../../../../../fields/Doc';
import { DocData } from '../../../../../fields/DocSymbols';
import { Id } from '../../../../../fields/FieldSymbols';
import { List } from '../../../../../fields/List';
@@ -30,7 +28,7 @@ export class AgentDocumentManager {
@observable private documentsById: ObservableMap<string, AgentDocument>;
private chatBox: ChatBox;
private chatBoxDocument: Doc | null = null;
- private fieldMetadata: Record<string, any> = {};
+ private fieldMetadata: Record<string, any> = {}; // bcz: CHANGE any to a proper type!
@observable private simplifiedChunks: ObservableMap<string, SimplifiedChunk>;
/**
@@ -103,6 +101,7 @@ export class AgentDocumentManager {
for (const [fieldName, fieldInfo] of documentOptionsEntries) {
// Extract field information
const fieldData: Record<string, any> = {
+ // bcz: CHANGE any to a proper type!
name: fieldName,
withoutUnderscore: fieldName.startsWith('_') ? fieldName.substring(1) : fieldName,
description: '',
@@ -223,6 +222,7 @@ export class AgentDocumentManager {
const dataDoc = agentDoc.dataDoc;
const metadata: Record<string, any> = {
+ // bcz: CHANGE any to a proper type!
id: layoutDoc[Id] || dataDoc[Id] || '',
title: layoutDoc.title || '',
type: layoutDoc.type || '',
@@ -235,7 +235,7 @@ export class AgentDocumentManager {
// Process all known field definitions
Object.keys(this.fieldMetadata).forEach(fieldName => {
- const fieldDef = this.fieldMetadata[fieldName];
+ // const fieldDef = this.fieldMetadata[fieldName];
const strippedName = fieldName.startsWith('_') ? fieldName.substring(1) : fieldName;
// Check if field exists on layout document
@@ -307,7 +307,7 @@ export class AgentDocumentManager {
* @param value The field value to format
* @returns A JSON-friendly representation of the field value
*/
- private formatFieldValue(value: any): any {
+ private formatFieldValue(value: FieldResult | undefined) {
if (value === undefined || value === null) {
return null;
}
@@ -330,12 +330,12 @@ export class AgentDocumentManager {
if (rtfObj.doc && rtfObj.doc.content) {
// Recursively extract text from the content
let plainText = '';
- const extractText = (node: any) => {
+ const extractText = (node: { text: string; content?: unknown[] }) => {
if (node.text) {
plainText += node.text;
}
if (node.content && Array.isArray(node.content)) {
- node.content.forEach((child: any) => extractText(child));
+ node.content.forEach(child => extractText(child as { text: string; content?: unknown[] }));
}
};
@@ -351,7 +351,7 @@ export class AgentDocumentManager {
};
}
}
- } catch (e) {
+ } catch {
// If parsing fails, just treat as a regular string
}
}
@@ -366,7 +366,7 @@ export class AgentDocumentManager {
try {
// Try to convert to JSON string
return JSON.stringify(value);
- } catch (e) {
+ } catch {
return '[Complex Object]';
}
}
@@ -381,26 +381,24 @@ export class AgentDocumentManager {
* @param fieldValue The string value to convert
* @returns The converted value with the appropriate type
*/
- private convertFieldValue(fieldName: string, fieldValue: any): any {
+ private convertFieldValue(fieldName: string, fieldValueIn: string | number | boolean): FieldResult | undefined {
// If fieldValue is already a number or boolean, we don't need to convert it from string
- if (typeof fieldValue === 'number' || typeof fieldValue === 'boolean') {
- return fieldValue;
+ if (typeof fieldValueIn === 'number' || typeof fieldValueIn === 'boolean') {
+ return fieldValueIn;
}
// If fieldValue is a string "true" or "false", convert to boolean
- if (typeof fieldValue === 'string') {
- if (fieldValue.toLowerCase() === 'true') {
+ if (typeof fieldValueIn === 'string') {
+ if (fieldValueIn.toLowerCase() === 'true') {
return true;
}
- if (fieldValue.toLowerCase() === 'false') {
+ if (fieldValueIn.toLowerCase() === 'false') {
return false;
}
}
- // If fieldValue is not a string (and not a number or boolean), convert it to string
- if (typeof fieldValue !== 'string') {
- fieldValue = String(fieldValue);
- }
+ // coerce fieldvValue to a string
+ const fieldValue = typeof fieldValueIn !== 'string' ? String(fieldValueIn) : fieldValueIn;
// Special handling for text field - convert to proper RichTextField format
if (fieldName === 'text') {
@@ -408,7 +406,7 @@ export class AgentDocumentManager {
// Check if it's already a valid JSON RichTextField
JSON.parse(fieldValue);
return fieldValue;
- } catch (e) {
+ } catch {
// It's a plain text string, so convert it to RichTextField format
const rtf = {
doc: {
@@ -462,21 +460,21 @@ export class AgentDocumentManager {
// Try to convert to date (stored as number timestamp)
try {
return new Date(fieldValue).getTime();
- } catch (e) {
+ } catch {
return fieldValue;
}
} else if (fieldType.includes('list') || fieldType.includes('array')) {
// Try to parse as JSON array
try {
- return JSON.parse(fieldValue);
- } catch (e) {
+ return JSON.parse(fieldValue) as FieldResult; // bcz: this needs to be typed properly. Dash fields can't accept a generic 'objext'
+ } catch {
return fieldValue;
}
} else if (fieldType === 'json' || fieldType === 'object') {
// Try to parse as JSON object
try {
- return JSON.parse(fieldValue);
- } catch (e) {
+ return JSON.parse(fieldValue) as FieldResult; // bcz: this needs to be typed properly. Dash fields can't accept a generic 'objext'
+ } catch {
return fieldValue;
}
}
@@ -492,6 +490,7 @@ export class AgentDocumentManager {
public getAllFieldMetadata() {
// Start with our already populated fieldMetadata from the DocumentOptions class
const result: Record<string, any> = {
+ // bcz: CHANGE any to a proper type!
fieldCount: Object.keys(this.fieldMetadata).length,
fields: {},
fieldsByType: {
@@ -526,6 +525,7 @@ export class AgentDocumentManager {
// Create structured field metadata
const fieldData: Record<string, any> = {
+ // bcz: CHANGE any to a proper type!
name: fieldName,
displayName: strippedName,
description: fieldInfo.description || '',
@@ -618,12 +618,12 @@ export class AgentDocumentManager {
message: string;
fieldName?: string;
originalFieldName?: string;
- newValue?: any;
+ newValue?: string | number | boolean | object;
warning?: string;
} {
// Normalize field name (handle with/without underscore)
let normalizedFieldName = fieldName.startsWith('_') ? fieldName : fieldName;
- const strippedFieldName = fieldName.startsWith('_') ? fieldName.substring(1) : fieldName;
+ // const strippedFieldName = fieldName.startsWith('_') ? fieldName.substring(1) : fieldName;
// Handle common field name aliases (width → _width, height → _height)
// Many document fields use '_' prefix for layout properties
@@ -690,7 +690,7 @@ export class AgentDocumentManager {
}
// Set the field value on the target document
- targetDoc[normalizedFieldName] = convertedValue;
+ targetDoc[normalizedFieldName] = convertedValue; // bcz: converteValue needs to be typed properly. Dash fields can't accept a generic 'objext'
return {
success: true,
@@ -712,19 +712,19 @@ export class AgentDocumentManager {
* @param documentId Optional ID of a specific document to get metadata for
* @returns Document metadata or metadata for all documents
*/
- public getDocumentMetadata(documentId?: string): any {
+ public getDocumentMetadata(documentId?: string) {
if (documentId) {
console.log(`Returning document metadata for docID, ${documentId}:`, this.extractDocumentMetadata(documentId));
return this.extractDocumentMetadata(documentId);
} else {
// Get metadata for all documents
- const documentsMetadata: Record<string, Record<string, any>> = {};
- for (const documentId of this.documentsById.keys()) {
- const metadata = this.extractDocumentMetadata(documentId);
+ const documentsMetadata: Record<string, Record<string, any>> = {}; // bcz: CHANGE any to a proper type!
+ for (const docid of this.documentsById.keys()) {
+ const metadata = this.extractDocumentMetadata(docid);
if (metadata) {
- documentsMetadata[documentId] = metadata;
+ documentsMetadata[docid] = metadata;
} else {
- console.warn(`No metadata found for document with ID: ${documentId}`);
+ console.warn(`No metadata found for document with ID: ${docid}`);
}
}
return {
@@ -842,7 +842,7 @@ export class AgentDocumentManager {
* @returns The ID of the created document
*/
- public async createDocInDash(docType: string, data: string, options?: any): Promise<string> {
+ public async createDocInDash(docType: string, data: string, options?: DocumentOptions): Promise<string> {
// Validate doc_type
if (!this.isValidDocType(docType)) {
throw new Error(`Invalid document type: ${docType}`);
@@ -1054,13 +1054,13 @@ export class AgentDocumentManager {
endPage: chunk.metadata.end_page,
location: chunk.metadata.location,
} as SimplifiedChunk);
- } else if (docType === 'csv') {
+ } else if (docType === 'csv' && 'row_start' in chunk.metadata && 'row_end' in chunk.metadata && 'col_start' in chunk.metadata && 'col_end' in chunk.metadata) {
simplifiedChunks.push({
...baseChunk,
- rowStart: (chunk.metadata as any).row_start,
- rowEnd: (chunk.metadata as any).row_end,
- colStart: (chunk.metadata as any).col_start,
- colEnd: (chunk.metadata as any).col_end,
+ rowStart: chunk.metadata.row_start,
+ rowEnd: chunk.metadata.row_end,
+ colStart: chunk.metadata.col_start,
+ colEnd: chunk.metadata.col_end,
} as SimplifiedChunk);
} else {
// Default for other document types
@@ -1077,7 +1077,7 @@ export class AgentDocumentManager {
* @returns The simplified chunk if found, undefined otherwise
*/
@action
- public getSimplifiedChunkById(chunkId: string): any | undefined {
+ public getSimplifiedChunkById(chunkId: string) {
return { foundChunk: this.simplifiedChunks.get(chunkId), doc: this.getDocument(this.simplifiedChunks.get(chunkId)?.doc_id || chunkId), dataDoc: this.getDataDocument(this.simplifiedChunks.get(chunkId)?.doc_id || chunkId) };
}
@@ -1098,7 +1098,7 @@ export class AgentDocumentManager {
* @param doc The document containing original media segments
* @returns Array of media segments or empty array if none exist
*/
- public getOriginalSegments(doc: Doc): any[] {
+ public getOriginalSegments(doc: Doc): { text: string; index: string; start: number }[] {
if (!doc || !doc.original_segments) {
return [];
}