@superatomai/sdk-node 0.0.56 → 0.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +942 -942
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +534 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +534 -122
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2409,10 +2409,39 @@ var BookmarksRequestMessageSchema = import_zod3.z.object({
|
|
|
2409
2409
|
type: import_zod3.z.literal("BOOKMARKS"),
|
|
2410
2410
|
payload: BookmarksRequestPayloadSchema
|
|
2411
2411
|
});
|
|
2412
|
+
var ArtifactsQueryFiltersSchema = import_zod3.z.object({
|
|
2413
|
+
createdBy: import_zod3.z.number().optional(),
|
|
2414
|
+
status: import_zod3.z.string().optional(),
|
|
2415
|
+
name: import_zod3.z.string().optional(),
|
|
2416
|
+
deleted: import_zod3.z.boolean().optional()
|
|
2417
|
+
});
|
|
2418
|
+
var ArtifactsRequestPayloadSchema = import_zod3.z.object({
|
|
2419
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
2420
|
+
data: import_zod3.z.object({
|
|
2421
|
+
id: import_zod3.z.number().optional(),
|
|
2422
|
+
name: import_zod3.z.string().optional(),
|
|
2423
|
+
createdBy: import_zod3.z.number().optional(),
|
|
2424
|
+
dsl: import_zod3.z.record(import_zod3.z.any()).optional(),
|
|
2425
|
+
status: import_zod3.z.string().optional(),
|
|
2426
|
+
deleted: import_zod3.z.boolean().optional(),
|
|
2427
|
+
limit: import_zod3.z.number().optional(),
|
|
2428
|
+
// Query operation fields
|
|
2429
|
+
filters: ArtifactsQueryFiltersSchema.optional(),
|
|
2430
|
+
sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
|
|
2431
|
+
}).optional()
|
|
2432
|
+
});
|
|
2433
|
+
var ArtifactsRequestMessageSchema = import_zod3.z.object({
|
|
2434
|
+
id: import_zod3.z.string(),
|
|
2435
|
+
from: MessageParticipantSchema,
|
|
2436
|
+
type: import_zod3.z.literal("ARTIFACTS"),
|
|
2437
|
+
payload: ArtifactsRequestPayloadSchema
|
|
2438
|
+
});
|
|
2439
|
+
var KbNodeTypeSchema = import_zod3.z.enum(["global", "user", "query"]);
|
|
2412
2440
|
var KbNodesQueryFiltersSchema = import_zod3.z.object({
|
|
2413
2441
|
query: import_zod3.z.string().optional(),
|
|
2414
2442
|
category: import_zod3.z.string().optional(),
|
|
2415
2443
|
tags: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
2444
|
+
type: KbNodeTypeSchema.optional(),
|
|
2416
2445
|
createdBy: import_zod3.z.number().optional()
|
|
2417
2446
|
});
|
|
2418
2447
|
var KbNodesRequestPayloadSchema = import_zod3.z.object({
|
|
@@ -2423,6 +2452,7 @@ var KbNodesRequestPayloadSchema = import_zod3.z.object({
|
|
|
2423
2452
|
content: import_zod3.z.string().optional(),
|
|
2424
2453
|
category: import_zod3.z.string().optional(),
|
|
2425
2454
|
tags: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
2455
|
+
type: KbNodeTypeSchema.optional(),
|
|
2426
2456
|
createdBy: import_zod3.z.number().optional(),
|
|
2427
2457
|
updatedBy: import_zod3.z.number().optional(),
|
|
2428
2458
|
userId: import_zod3.z.number().optional(),
|
|
@@ -5436,7 +5466,7 @@ var getKnowledgeBase = async ({
|
|
|
5436
5466
|
topK
|
|
5437
5467
|
});
|
|
5438
5468
|
if (!result || !result.content) {
|
|
5439
|
-
logger.
|
|
5469
|
+
logger.info("[KnowledgeBase] No knowledge base results returned");
|
|
5440
5470
|
return "";
|
|
5441
5471
|
}
|
|
5442
5472
|
logger.info(`[KnowledgeBase] Retrieved knowledge base context (${result.content.length} chars)`);
|
|
@@ -5450,8 +5480,101 @@ var getKnowledgeBase = async ({
|
|
|
5450
5480
|
return "";
|
|
5451
5481
|
}
|
|
5452
5482
|
};
|
|
5483
|
+
var getGlobalKnowledgeBase = async ({
|
|
5484
|
+
collections,
|
|
5485
|
+
limit = 100
|
|
5486
|
+
}) => {
|
|
5487
|
+
try {
|
|
5488
|
+
if (!collections || !collections["knowledge-base"] || !collections["knowledge-base"]["getGlobal"]) {
|
|
5489
|
+
logger.info("[KnowledgeBase] knowledge-base.getGlobal collection not registered, skipping");
|
|
5490
|
+
return "";
|
|
5491
|
+
}
|
|
5492
|
+
logger.info("[KnowledgeBase] Fetching global knowledge base nodes...");
|
|
5493
|
+
const result = await collections["knowledge-base"]["getGlobal"]({ limit });
|
|
5494
|
+
if (!result || !result.content) {
|
|
5495
|
+
logger.info("[KnowledgeBase] No global knowledge base nodes found");
|
|
5496
|
+
return "";
|
|
5497
|
+
}
|
|
5498
|
+
logger.info(`[KnowledgeBase] Retrieved ${result.count || 0} global knowledge base nodes`);
|
|
5499
|
+
return result.content;
|
|
5500
|
+
} catch (error) {
|
|
5501
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5502
|
+
logger.warn(`[KnowledgeBase] Error fetching global knowledge base: ${errorMsg}`);
|
|
5503
|
+
return "";
|
|
5504
|
+
}
|
|
5505
|
+
};
|
|
5506
|
+
var getUserKnowledgeBase = async ({
|
|
5507
|
+
collections,
|
|
5508
|
+
userId,
|
|
5509
|
+
limit = 100
|
|
5510
|
+
}) => {
|
|
5511
|
+
try {
|
|
5512
|
+
if (!userId) {
|
|
5513
|
+
logger.info("[KnowledgeBase] No userId provided, skipping user knowledge base");
|
|
5514
|
+
return "";
|
|
5515
|
+
}
|
|
5516
|
+
if (!collections || !collections["knowledge-base"] || !collections["knowledge-base"]["getByUser"]) {
|
|
5517
|
+
logger.info("[KnowledgeBase] knowledge-base.getByUser collection not registered, skipping");
|
|
5518
|
+
return "";
|
|
5519
|
+
}
|
|
5520
|
+
logger.info(`[KnowledgeBase] Fetching user knowledge base nodes for userId: ${userId}...`);
|
|
5521
|
+
const result = await collections["knowledge-base"]["getByUser"]({
|
|
5522
|
+
userId: Number(userId),
|
|
5523
|
+
limit
|
|
5524
|
+
});
|
|
5525
|
+
if (!result || !result.content) {
|
|
5526
|
+
logger.info(`[KnowledgeBase] No user knowledge base nodes found for userId: ${userId}`);
|
|
5527
|
+
return "";
|
|
5528
|
+
}
|
|
5529
|
+
logger.info(`[KnowledgeBase] Retrieved ${result.count || 0} user knowledge base nodes for userId: ${userId}`);
|
|
5530
|
+
return result.content;
|
|
5531
|
+
} catch (error) {
|
|
5532
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5533
|
+
logger.warn(`[KnowledgeBase] Error fetching user knowledge base: ${errorMsg}`);
|
|
5534
|
+
return "";
|
|
5535
|
+
}
|
|
5536
|
+
};
|
|
5537
|
+
var getAllKnowledgeBase = async ({
|
|
5538
|
+
prompt,
|
|
5539
|
+
collections,
|
|
5540
|
+
userId,
|
|
5541
|
+
topK = 3
|
|
5542
|
+
}) => {
|
|
5543
|
+
logger.info("[KnowledgeBase] Fetching all knowledge base contexts...");
|
|
5544
|
+
const [globalContext, userContext, queryContext] = await Promise.all([
|
|
5545
|
+
getGlobalKnowledgeBase({ collections }),
|
|
5546
|
+
getUserKnowledgeBase({ collections, userId }),
|
|
5547
|
+
getKnowledgeBase({ prompt, collections, topK })
|
|
5548
|
+
]);
|
|
5549
|
+
let combinedContext = "";
|
|
5550
|
+
if (globalContext) {
|
|
5551
|
+
combinedContext += "## Global Knowledge Base\n";
|
|
5552
|
+
combinedContext += "The following information applies to all queries:\n\n";
|
|
5553
|
+
combinedContext += globalContext + "\n\n";
|
|
5554
|
+
}
|
|
5555
|
+
if (userContext) {
|
|
5556
|
+
combinedContext += "## User-Specific Knowledge Base\n";
|
|
5557
|
+
combinedContext += "The following information is specific to this user:\n\n";
|
|
5558
|
+
combinedContext += userContext + "\n\n";
|
|
5559
|
+
}
|
|
5560
|
+
if (queryContext) {
|
|
5561
|
+
combinedContext += "## Relevant Knowledge Base (Query-Matched)\n";
|
|
5562
|
+
combinedContext += "The following information is semantically relevant to the current query:\n\n";
|
|
5563
|
+
combinedContext += queryContext + "\n\n";
|
|
5564
|
+
}
|
|
5565
|
+
logger.info(`[KnowledgeBase] Combined knowledge base context: global=${globalContext.length} chars, user=${userContext.length} chars, query=${queryContext.length} chars`);
|
|
5566
|
+
return {
|
|
5567
|
+
globalContext,
|
|
5568
|
+
userContext,
|
|
5569
|
+
queryContext,
|
|
5570
|
+
combinedContext: combinedContext.trim()
|
|
5571
|
+
};
|
|
5572
|
+
};
|
|
5453
5573
|
var KB = {
|
|
5454
|
-
getKnowledgeBase
|
|
5574
|
+
getKnowledgeBase,
|
|
5575
|
+
getGlobalKnowledgeBase,
|
|
5576
|
+
getUserKnowledgeBase,
|
|
5577
|
+
getAllKnowledgeBase
|
|
5455
5578
|
};
|
|
5456
5579
|
var knowledge_base_default = KB;
|
|
5457
5580
|
|
|
@@ -5833,6 +5956,9 @@ var BaseLLM = class {
|
|
|
5833
5956
|
* @returns Object containing matched components, layout title/description, and follow-up actions
|
|
5834
5957
|
*/
|
|
5835
5958
|
async matchComponentsFromAnalysis(analysisContent, components, apiKey, logCollector, componentStreamCallback, deferredTools, executedTools) {
|
|
5959
|
+
const methodStartTime = Date.now();
|
|
5960
|
+
const methodName = "matchComponentsFromAnalysis";
|
|
5961
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")}`);
|
|
5836
5962
|
try {
|
|
5837
5963
|
logger.debug(`[${this.getProviderName()}] Starting component matching from text response`);
|
|
5838
5964
|
let availableComponentsText = "No components available";
|
|
@@ -6139,6 +6265,8 @@ ${executedToolsText}`);
|
|
|
6139
6265
|
}
|
|
6140
6266
|
};
|
|
6141
6267
|
}).filter(Boolean);
|
|
6268
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6269
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | components: ${finalComponents.length} | actions: ${actions.length}`);
|
|
6142
6270
|
return {
|
|
6143
6271
|
components: finalComponents,
|
|
6144
6272
|
layoutTitle,
|
|
@@ -6146,8 +6274,9 @@ ${executedToolsText}`);
|
|
|
6146
6274
|
actions
|
|
6147
6275
|
};
|
|
6148
6276
|
} catch (error) {
|
|
6277
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6149
6278
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6150
|
-
logger.error(`[${this.getProviderName()}]
|
|
6279
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6151
6280
|
logCollector?.error(`Failed to match components: ${errorMsg}`);
|
|
6152
6281
|
return {
|
|
6153
6282
|
components: [],
|
|
@@ -6162,6 +6291,10 @@ ${executedToolsText}`);
|
|
|
6162
6291
|
* Determines if question is for data analysis, requires external tools, or needs text response
|
|
6163
6292
|
*/
|
|
6164
6293
|
async classifyQuestionCategory(userPrompt, apiKey, logCollector, conversationHistory, externalTools) {
|
|
6294
|
+
const methodStartTime = Date.now();
|
|
6295
|
+
const methodName = "classifyQuestionCategory";
|
|
6296
|
+
const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
|
|
6297
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
|
|
6165
6298
|
try {
|
|
6166
6299
|
const schemaDoc = schema.generateSchemaDocumentation();
|
|
6167
6300
|
const availableToolsDoc = externalTools && externalTools.length > 0 ? externalTools.map((tool) => {
|
|
@@ -6205,6 +6338,8 @@ ${executedToolsText}`);
|
|
|
6205
6338
|
confidence: result.confidence
|
|
6206
6339
|
}
|
|
6207
6340
|
);
|
|
6341
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6342
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | category: ${result.category} | confidence: ${result.confidence}% | tools: ${(result.externalTools || []).length}`);
|
|
6208
6343
|
return {
|
|
6209
6344
|
category: result.category || "data_analysis",
|
|
6210
6345
|
externalTools: result.externalTools || [],
|
|
@@ -6213,8 +6348,9 @@ ${executedToolsText}`);
|
|
|
6213
6348
|
confidence: result.confidence || 0
|
|
6214
6349
|
};
|
|
6215
6350
|
} catch (error) {
|
|
6351
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6216
6352
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6217
|
-
logger.error(`[${this.getProviderName()}]
|
|
6353
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6218
6354
|
logger.debug(`[${this.getProviderName()}] Category classification error details:`, error);
|
|
6219
6355
|
throw error;
|
|
6220
6356
|
}
|
|
@@ -6225,9 +6361,15 @@ ${executedToolsText}`);
|
|
|
6225
6361
|
* Also adapts the cached text response to match the new question
|
|
6226
6362
|
*/
|
|
6227
6363
|
async adaptUIBlockParameters(currentUserPrompt, originalUserPrompt, matchedUIBlock, apiKey, logCollector, cachedTextResponse) {
|
|
6364
|
+
const methodStartTime = Date.now();
|
|
6365
|
+
const methodName = "adaptUIBlockParameters";
|
|
6366
|
+
const promptPreview = currentUserPrompt.substring(0, 50) + (currentUserPrompt.length > 50 ? "..." : "");
|
|
6367
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | prompt: "${promptPreview}"`);
|
|
6228
6368
|
try {
|
|
6229
6369
|
const component = matchedUIBlock?.generatedComponentMetadata || matchedUIBlock?.component;
|
|
6230
6370
|
if (!matchedUIBlock || !component) {
|
|
6371
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6372
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: no component found`);
|
|
6231
6373
|
return {
|
|
6232
6374
|
success: false,
|
|
6233
6375
|
explanation: "No component found in matched UI block"
|
|
@@ -6260,9 +6402,8 @@ ${executedToolsText}`);
|
|
|
6260
6402
|
// Parse as JSON
|
|
6261
6403
|
);
|
|
6262
6404
|
if (!result.success) {
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
);
|
|
6405
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6406
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: adaptation failed - ${result.reason}`);
|
|
6266
6407
|
logCollector?.warn(
|
|
6267
6408
|
"Could not adapt matched UI block",
|
|
6268
6409
|
"explanation",
|
|
@@ -6287,6 +6428,8 @@ ${executedToolsText}`);
|
|
|
6287
6428
|
componentType: result.adaptedComponent?.type
|
|
6288
6429
|
}
|
|
6289
6430
|
);
|
|
6431
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6432
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | changes: ${(result.parametersChanged || []).length}`);
|
|
6290
6433
|
return {
|
|
6291
6434
|
success: true,
|
|
6292
6435
|
adaptedComponent: result.adaptedComponent,
|
|
@@ -6295,8 +6438,9 @@ ${executedToolsText}`);
|
|
|
6295
6438
|
explanation: result.explanation || "Parameters adapted successfully"
|
|
6296
6439
|
};
|
|
6297
6440
|
} catch (error) {
|
|
6441
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6298
6442
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6299
|
-
logger.error(`[${this.getProviderName()}]
|
|
6443
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6300
6444
|
logger.debug(`[${this.getProviderName()}] Adaptation error details:`, error);
|
|
6301
6445
|
return {
|
|
6302
6446
|
success: false,
|
|
@@ -6314,8 +6458,13 @@ ${executedToolsText}`);
|
|
|
6314
6458
|
* @param components - Optional list of available components for matching suggestions
|
|
6315
6459
|
* @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called
|
|
6316
6460
|
* @param category - Question category ('data_analysis' | 'data_modification' | 'general'). For data_modification, answer component streaming is skipped. For general, component generation is skipped entirely.
|
|
6461
|
+
* @param userId - Optional user ID for fetching user-specific knowledge base nodes
|
|
6317
6462
|
*/
|
|
6318
|
-
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category) {
|
|
6463
|
+
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category, userId) {
|
|
6464
|
+
const methodStartTime = Date.now();
|
|
6465
|
+
const methodName = "generateTextResponse";
|
|
6466
|
+
const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
|
|
6467
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | category: ${category} | prompt: "${promptPreview}"`);
|
|
6319
6468
|
const errors = [];
|
|
6320
6469
|
logger.debug(`[${this.getProviderName()}] Starting text response generation`);
|
|
6321
6470
|
logger.debug(`[${this.getProviderName()}] User prompt: "${userPrompt.substring(0, 50)}..."`);
|
|
@@ -6364,11 +6513,13 @@ ${executedToolsText}`);
|
|
|
6364
6513
|
}
|
|
6365
6514
|
const schemaDoc = schema.generateSchemaDocumentation();
|
|
6366
6515
|
const databaseRules = await promptLoader.loadDatabaseRules();
|
|
6367
|
-
const
|
|
6516
|
+
const kbResult = await knowledge_base_default.getAllKnowledgeBase({
|
|
6368
6517
|
prompt: userPrompt,
|
|
6369
6518
|
collections,
|
|
6370
|
-
|
|
6519
|
+
userId,
|
|
6520
|
+
topK: 3
|
|
6371
6521
|
});
|
|
6522
|
+
const knowledgeBaseContext = kbResult.combinedContext;
|
|
6372
6523
|
const prompts = await promptLoader.loadPrompts("text-response", {
|
|
6373
6524
|
USER_PROMPT: userPrompt,
|
|
6374
6525
|
CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
|
|
@@ -6494,26 +6645,48 @@ ${executedToolsText}`);
|
|
|
6494
6645
|
const executedToolsList = [];
|
|
6495
6646
|
let maxAttemptsReached = false;
|
|
6496
6647
|
let fullStreamedText = "";
|
|
6648
|
+
let streamBuffer = "";
|
|
6649
|
+
let flushTimer = null;
|
|
6650
|
+
const FLUSH_INTERVAL = 50;
|
|
6651
|
+
const flushStreamBuffer = () => {
|
|
6652
|
+
if (streamBuffer && streamCallback) {
|
|
6653
|
+
streamCallback(streamBuffer);
|
|
6654
|
+
streamBuffer = "";
|
|
6655
|
+
}
|
|
6656
|
+
flushTimer = null;
|
|
6657
|
+
};
|
|
6497
6658
|
const wrappedStreamCallback = streamCallback ? (chunk) => {
|
|
6498
6659
|
fullStreamedText += chunk;
|
|
6499
|
-
|
|
6660
|
+
streamBuffer += chunk;
|
|
6661
|
+
if (chunk.includes("\n") || chunk.length > 100) {
|
|
6662
|
+
if (flushTimer) {
|
|
6663
|
+
clearTimeout(flushTimer);
|
|
6664
|
+
flushTimer = null;
|
|
6665
|
+
}
|
|
6666
|
+
flushStreamBuffer();
|
|
6667
|
+
} else if (!flushTimer) {
|
|
6668
|
+
flushTimer = setTimeout(flushStreamBuffer, FLUSH_INTERVAL);
|
|
6669
|
+
}
|
|
6500
6670
|
} : void 0;
|
|
6671
|
+
const flushStream = () => {
|
|
6672
|
+
if (flushTimer) {
|
|
6673
|
+
clearTimeout(flushTimer);
|
|
6674
|
+
flushTimer = null;
|
|
6675
|
+
}
|
|
6676
|
+
flushStreamBuffer();
|
|
6677
|
+
};
|
|
6678
|
+
const streamDelay = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6501
6679
|
const withProgressHeartbeat = async (operation, progressMessage, intervalMs = 1e3) => {
|
|
6502
6680
|
if (!wrappedStreamCallback) {
|
|
6503
6681
|
return operation();
|
|
6504
6682
|
}
|
|
6505
6683
|
const startTime = Date.now();
|
|
6506
|
-
|
|
6507
|
-
const maxDots = 3;
|
|
6684
|
+
await streamDelay(30);
|
|
6508
6685
|
wrappedStreamCallback(`\u23F3 ${progressMessage}`);
|
|
6509
6686
|
const heartbeatInterval = setInterval(() => {
|
|
6510
6687
|
const elapsedSeconds = Math.floor((Date.now() - startTime) / 1e3);
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
if (elapsedSeconds >= 2) {
|
|
6514
|
-
wrappedStreamCallback(`${dots} (${elapsedSeconds}s)`);
|
|
6515
|
-
} else {
|
|
6516
|
-
wrappedStreamCallback(dots);
|
|
6688
|
+
if (elapsedSeconds >= 1) {
|
|
6689
|
+
wrappedStreamCallback(` (${elapsedSeconds}s)`);
|
|
6517
6690
|
}
|
|
6518
6691
|
}, intervalMs);
|
|
6519
6692
|
try {
|
|
@@ -6558,6 +6731,7 @@ Please try rephrasing your question or simplifying your request.
|
|
|
6558
6731
|
throw new Error(errorMsg);
|
|
6559
6732
|
}
|
|
6560
6733
|
try {
|
|
6734
|
+
flushStream();
|
|
6561
6735
|
if (wrappedStreamCallback) {
|
|
6562
6736
|
const paramsDisplay = Object.keys(params).length > 0 ? `
|
|
6563
6737
|
**Parameters:** ${JSON.stringify(params)}` : "";
|
|
@@ -6567,10 +6741,12 @@ Please try rephrasing your question or simplifying your request.
|
|
|
6567
6741
|
\u{1F50D} **Analyzing your question...**
|
|
6568
6742
|
|
|
6569
6743
|
`);
|
|
6744
|
+
await streamDelay(50);
|
|
6570
6745
|
if (reasoning) {
|
|
6571
6746
|
wrappedStreamCallback(`\u{1F4AD} ${reasoning}
|
|
6572
6747
|
|
|
6573
6748
|
`);
|
|
6749
|
+
await streamDelay(50);
|
|
6574
6750
|
}
|
|
6575
6751
|
wrappedStreamCallback(`\u{1F4DD} **Generated SQL Query:**
|
|
6576
6752
|
\`\`\`sql
|
|
@@ -6578,16 +6754,19 @@ ${sql}
|
|
|
6578
6754
|
\`\`\`${paramsDisplay}
|
|
6579
6755
|
|
|
6580
6756
|
`);
|
|
6757
|
+
await streamDelay(50);
|
|
6581
6758
|
} else {
|
|
6582
6759
|
wrappedStreamCallback(`
|
|
6583
6760
|
|
|
6584
6761
|
\u{1F504} **Retrying with corrected query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS})...**
|
|
6585
6762
|
|
|
6586
6763
|
`);
|
|
6764
|
+
await streamDelay(50);
|
|
6587
6765
|
if (reasoning) {
|
|
6588
6766
|
wrappedStreamCallback(`\u{1F4AD} ${reasoning}
|
|
6589
6767
|
|
|
6590
6768
|
`);
|
|
6769
|
+
await streamDelay(50);
|
|
6591
6770
|
}
|
|
6592
6771
|
wrappedStreamCallback(`\u{1F4DD} **Corrected SQL Query:**
|
|
6593
6772
|
\`\`\`sql
|
|
@@ -6595,6 +6774,7 @@ ${sql}
|
|
|
6595
6774
|
\`\`\`${paramsDisplay}
|
|
6596
6775
|
|
|
6597
6776
|
`);
|
|
6777
|
+
await streamDelay(50);
|
|
6598
6778
|
}
|
|
6599
6779
|
}
|
|
6600
6780
|
logCollector?.logQuery(
|
|
@@ -6621,6 +6801,7 @@ ${sql}
|
|
|
6621
6801
|
\u2705 **Query executed successfully!**
|
|
6622
6802
|
|
|
6623
6803
|
`);
|
|
6804
|
+
await streamDelay(50);
|
|
6624
6805
|
if (Array.isArray(data) && data.length > 0) {
|
|
6625
6806
|
const firstRow = data[0];
|
|
6626
6807
|
const columns = Object.keys(firstRow);
|
|
@@ -6629,18 +6810,22 @@ ${sql}
|
|
|
6629
6810
|
wrappedStreamCallback(`**Result:** ${value}
|
|
6630
6811
|
|
|
6631
6812
|
`);
|
|
6813
|
+
await streamDelay(50);
|
|
6632
6814
|
} else if (data.length > 0) {
|
|
6633
6815
|
wrappedStreamCallback(`**Retrieved ${rowCount} rows**
|
|
6634
6816
|
|
|
6635
6817
|
`);
|
|
6818
|
+
await streamDelay(50);
|
|
6636
6819
|
wrappedStreamCallback(`<DataTable>${JSON.stringify(data)}</DataTable>
|
|
6637
6820
|
|
|
6638
6821
|
`);
|
|
6822
|
+
await streamDelay(50);
|
|
6639
6823
|
}
|
|
6640
6824
|
} else if (Array.isArray(data) && data.length === 0) {
|
|
6641
6825
|
wrappedStreamCallback(`**No rows returned.**
|
|
6642
6826
|
|
|
6643
6827
|
`);
|
|
6828
|
+
await streamDelay(50);
|
|
6644
6829
|
}
|
|
6645
6830
|
wrappedStreamCallback(`\u{1F4CA} **Analyzing results...**
|
|
6646
6831
|
|
|
@@ -6690,6 +6875,7 @@ Please try rephrasing your request or contact support.
|
|
|
6690
6875
|
throw new Error(errorMsg);
|
|
6691
6876
|
}
|
|
6692
6877
|
try {
|
|
6878
|
+
flushStream();
|
|
6693
6879
|
if (wrappedStreamCallback) {
|
|
6694
6880
|
if (attempts === 1) {
|
|
6695
6881
|
wrappedStreamCallback(`
|
|
@@ -6704,6 +6890,7 @@ Please try rephrasing your request or contact support.
|
|
|
6704
6890
|
|
|
6705
6891
|
`);
|
|
6706
6892
|
}
|
|
6893
|
+
await streamDelay(50);
|
|
6707
6894
|
}
|
|
6708
6895
|
const result2 = await withProgressHeartbeat(
|
|
6709
6896
|
() => externalTool.fn(toolInput),
|
|
@@ -6743,6 +6930,7 @@ Please try rephrasing your request or contact support.
|
|
|
6743
6930
|
wrappedStreamCallback(`\u2705 **${externalTool.name} completed successfully**
|
|
6744
6931
|
|
|
6745
6932
|
`);
|
|
6933
|
+
await streamDelay(50);
|
|
6746
6934
|
}
|
|
6747
6935
|
return JSON.stringify(result2, null, 2);
|
|
6748
6936
|
} catch (error) {
|
|
@@ -6790,7 +6978,8 @@ ${errorMsg}
|
|
|
6790
6978
|
logger.info(`[${this.getProviderName()}] Text response stream completed`);
|
|
6791
6979
|
const textResponse = fullStreamedText || result || "I apologize, but I was unable to generate a response.";
|
|
6792
6980
|
if (maxAttemptsReached) {
|
|
6793
|
-
|
|
6981
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6982
|
+
logger.warn(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: max attempts reached`);
|
|
6794
6983
|
logCollector?.error("Failed to generate valid query after maximum attempts");
|
|
6795
6984
|
return {
|
|
6796
6985
|
success: false,
|
|
@@ -6811,6 +7000,7 @@ ${errorMsg}
|
|
|
6811
7000
|
textLength: textResponse.length
|
|
6812
7001
|
}
|
|
6813
7002
|
);
|
|
7003
|
+
flushStream();
|
|
6814
7004
|
if (wrappedStreamCallback && components && components.length > 0 && category !== "general") {
|
|
6815
7005
|
wrappedStreamCallback("\n\n\u{1F4CA} **Generating visualization components...**\n\n");
|
|
6816
7006
|
wrappedStreamCallback("__TEXT_COMPLETE__COMPONENT_GENERATION_START__");
|
|
@@ -6892,6 +7082,8 @@ ${errorMsg}
|
|
|
6892
7082
|
}
|
|
6893
7083
|
};
|
|
6894
7084
|
}
|
|
7085
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7086
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | components: ${matchedComponents.length} | actions: ${actions.length}`);
|
|
6895
7087
|
return {
|
|
6896
7088
|
success: true,
|
|
6897
7089
|
data: {
|
|
@@ -6903,8 +7095,9 @@ ${errorMsg}
|
|
|
6903
7095
|
errors: []
|
|
6904
7096
|
};
|
|
6905
7097
|
} catch (error) {
|
|
7098
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6906
7099
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6907
|
-
logger.error(`[${this.getProviderName()}]
|
|
7100
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6908
7101
|
logCollector?.error(`Error generating text response: ${errorMsg}`);
|
|
6909
7102
|
userPromptErrorLogger.logLlmError(
|
|
6910
7103
|
this.getProviderName(),
|
|
@@ -7122,7 +7315,8 @@ ${errorMsg}
|
|
|
7122
7315
|
collections,
|
|
7123
7316
|
components,
|
|
7124
7317
|
toolsToUse,
|
|
7125
|
-
categoryClassification.category
|
|
7318
|
+
categoryClassification.category,
|
|
7319
|
+
userId
|
|
7126
7320
|
);
|
|
7127
7321
|
const elapsedTime = Date.now() - startTime;
|
|
7128
7322
|
logger.info(`[${this.getProviderName()}] Total time taken: ${elapsedTime}ms (${(elapsedTime / 1e3).toFixed(2)}s)`);
|
|
@@ -7157,6 +7351,10 @@ ${errorMsg}
|
|
|
7157
7351
|
* For general/conversational questions without components, pass textResponse instead
|
|
7158
7352
|
*/
|
|
7159
7353
|
async generateNextQuestions(originalUserPrompt, component, componentData, apiKey, logCollector, conversationHistory, textResponse) {
|
|
7354
|
+
const methodStartTime = Date.now();
|
|
7355
|
+
const methodName = "generateNextQuestions";
|
|
7356
|
+
const promptPreview = originalUserPrompt.substring(0, 50) + (originalUserPrompt.length > 50 ? "..." : "");
|
|
7357
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
|
|
7160
7358
|
try {
|
|
7161
7359
|
let component_info;
|
|
7162
7360
|
if (component) {
|
|
@@ -7205,10 +7403,13 @@ ${errorMsg}
|
|
|
7205
7403
|
questions: nextQuestions
|
|
7206
7404
|
}
|
|
7207
7405
|
);
|
|
7406
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7407
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | questions: ${nextQuestions.length}`);
|
|
7208
7408
|
return nextQuestions;
|
|
7209
7409
|
} catch (error) {
|
|
7410
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7210
7411
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
7211
|
-
logger.error(`[${this.getProviderName()}]
|
|
7412
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
7212
7413
|
logger.debug(`[${this.getProviderName()}] Next questions generation error details:`, error);
|
|
7213
7414
|
logCollector?.error(`Error generating next questions: ${errorMsg}`);
|
|
7214
7415
|
return [];
|
|
@@ -10195,6 +10396,208 @@ function sendResponse7(id, res, sendMessage, clientId) {
|
|
|
10195
10396
|
sendMessage(response);
|
|
10196
10397
|
}
|
|
10197
10398
|
|
|
10399
|
+
// src/handlers/artifacts.ts
|
|
10400
|
+
init_logger();
|
|
10401
|
+
async function handleArtifactsRequest(data, collections, sendMessage) {
|
|
10402
|
+
const executeCollection = async (collection, op, params) => {
|
|
10403
|
+
const handler = collections[collection]?.[op];
|
|
10404
|
+
if (!handler) {
|
|
10405
|
+
throw new Error(`Collection operation ${collection}.${op} not found`);
|
|
10406
|
+
}
|
|
10407
|
+
return await handler(params);
|
|
10408
|
+
};
|
|
10409
|
+
try {
|
|
10410
|
+
const request = ArtifactsRequestMessageSchema.parse(data);
|
|
10411
|
+
const { id, payload, from } = request;
|
|
10412
|
+
const { operation, data: requestData } = payload;
|
|
10413
|
+
const artifactId = requestData?.id;
|
|
10414
|
+
const name = requestData?.name;
|
|
10415
|
+
const createdBy = requestData?.createdBy;
|
|
10416
|
+
const dsl = requestData?.dsl;
|
|
10417
|
+
const status = requestData?.status;
|
|
10418
|
+
const deleted = requestData?.deleted;
|
|
10419
|
+
const limit = requestData?.limit;
|
|
10420
|
+
const filters = requestData?.filters;
|
|
10421
|
+
const sort = requestData?.sort;
|
|
10422
|
+
switch (operation) {
|
|
10423
|
+
case "create":
|
|
10424
|
+
await handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, from.id);
|
|
10425
|
+
break;
|
|
10426
|
+
case "update":
|
|
10427
|
+
await handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, from.id);
|
|
10428
|
+
break;
|
|
10429
|
+
case "delete":
|
|
10430
|
+
await handleDelete6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10431
|
+
break;
|
|
10432
|
+
case "getAll":
|
|
10433
|
+
await handleGetAll6(id, limit, executeCollection, sendMessage, from.id);
|
|
10434
|
+
break;
|
|
10435
|
+
case "getOne":
|
|
10436
|
+
await handleGetOne6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10437
|
+
break;
|
|
10438
|
+
case "query":
|
|
10439
|
+
await handleQuery6(id, { filters, limit, sort }, executeCollection, sendMessage, from.id);
|
|
10440
|
+
break;
|
|
10441
|
+
default:
|
|
10442
|
+
sendResponse8(id, {
|
|
10443
|
+
success: false,
|
|
10444
|
+
error: `Unknown operation: ${operation}`
|
|
10445
|
+
}, sendMessage, from.id);
|
|
10446
|
+
}
|
|
10447
|
+
} catch (error) {
|
|
10448
|
+
logger.error("Failed to handle artifacts request:", error);
|
|
10449
|
+
sendResponse8(null, {
|
|
10450
|
+
success: false,
|
|
10451
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10452
|
+
}, sendMessage);
|
|
10453
|
+
}
|
|
10454
|
+
}
|
|
10455
|
+
async function handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, clientId) {
|
|
10456
|
+
if (!name) {
|
|
10457
|
+
sendResponse8(id, {
|
|
10458
|
+
success: false,
|
|
10459
|
+
error: "name is required"
|
|
10460
|
+
}, sendMessage, clientId);
|
|
10461
|
+
return;
|
|
10462
|
+
}
|
|
10463
|
+
try {
|
|
10464
|
+
const result = await executeCollection("artifacts", "create", { name, createdBy, dsl, status });
|
|
10465
|
+
sendResponse8(id, {
|
|
10466
|
+
success: true,
|
|
10467
|
+
data: result.data,
|
|
10468
|
+
message: "Artifact created successfully"
|
|
10469
|
+
}, sendMessage, clientId);
|
|
10470
|
+
logger.info(`Artifact created: ID ${result.data.id}`);
|
|
10471
|
+
} catch (error) {
|
|
10472
|
+
sendResponse8(id, {
|
|
10473
|
+
success: false,
|
|
10474
|
+
error: error instanceof Error ? error.message : "Failed to create artifact"
|
|
10475
|
+
}, sendMessage, clientId);
|
|
10476
|
+
}
|
|
10477
|
+
}
|
|
10478
|
+
async function handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, clientId) {
|
|
10479
|
+
if (!artifactId) {
|
|
10480
|
+
sendResponse8(id, {
|
|
10481
|
+
success: false,
|
|
10482
|
+
error: "Artifact ID is required"
|
|
10483
|
+
}, sendMessage, clientId);
|
|
10484
|
+
return;
|
|
10485
|
+
}
|
|
10486
|
+
try {
|
|
10487
|
+
const result = await executeCollection("artifacts", "update", { id: artifactId, name, dsl, status, deleted });
|
|
10488
|
+
sendResponse8(id, {
|
|
10489
|
+
success: true,
|
|
10490
|
+
data: result.data,
|
|
10491
|
+
message: "Artifact updated successfully"
|
|
10492
|
+
}, sendMessage, clientId);
|
|
10493
|
+
logger.info(`Artifact updated: ID ${artifactId}`);
|
|
10494
|
+
} catch (error) {
|
|
10495
|
+
sendResponse8(id, {
|
|
10496
|
+
success: false,
|
|
10497
|
+
error: error instanceof Error ? error.message : "Failed to update artifact"
|
|
10498
|
+
}, sendMessage, clientId);
|
|
10499
|
+
}
|
|
10500
|
+
}
|
|
10501
|
+
async function handleDelete6(id, artifactId, executeCollection, sendMessage, clientId) {
|
|
10502
|
+
if (!artifactId) {
|
|
10503
|
+
sendResponse8(id, {
|
|
10504
|
+
success: false,
|
|
10505
|
+
error: "Artifact ID is required"
|
|
10506
|
+
}, sendMessage, clientId);
|
|
10507
|
+
return;
|
|
10508
|
+
}
|
|
10509
|
+
try {
|
|
10510
|
+
const result = await executeCollection("artifacts", "delete", { id: artifactId });
|
|
10511
|
+
sendResponse8(id, {
|
|
10512
|
+
success: true,
|
|
10513
|
+
data: result.data,
|
|
10514
|
+
message: "Artifact deleted successfully"
|
|
10515
|
+
}, sendMessage, clientId);
|
|
10516
|
+
logger.info(`Artifact deleted: ID ${artifactId}`);
|
|
10517
|
+
} catch (error) {
|
|
10518
|
+
sendResponse8(id, {
|
|
10519
|
+
success: false,
|
|
10520
|
+
error: error instanceof Error ? error.message : "Failed to delete artifact"
|
|
10521
|
+
}, sendMessage, clientId);
|
|
10522
|
+
}
|
|
10523
|
+
}
|
|
10524
|
+
async function handleGetAll6(id, limit, executeCollection, sendMessage, clientId) {
|
|
10525
|
+
try {
|
|
10526
|
+
const result = await executeCollection("artifacts", "getAll", { limit });
|
|
10527
|
+
sendResponse8(id, {
|
|
10528
|
+
success: true,
|
|
10529
|
+
data: result.data,
|
|
10530
|
+
count: result.count,
|
|
10531
|
+
message: `Retrieved ${result.count} artifacts`
|
|
10532
|
+
}, sendMessage, clientId);
|
|
10533
|
+
logger.info(`Retrieved all artifacts (count: ${result.count})`);
|
|
10534
|
+
} catch (error) {
|
|
10535
|
+
sendResponse8(id, {
|
|
10536
|
+
success: false,
|
|
10537
|
+
error: error instanceof Error ? error.message : "Failed to get artifacts"
|
|
10538
|
+
}, sendMessage, clientId);
|
|
10539
|
+
}
|
|
10540
|
+
}
|
|
10541
|
+
async function handleGetOne6(id, artifactId, executeCollection, sendMessage, clientId) {
|
|
10542
|
+
if (!artifactId) {
|
|
10543
|
+
sendResponse8(id, {
|
|
10544
|
+
success: false,
|
|
10545
|
+
error: "Artifact ID is required"
|
|
10546
|
+
}, sendMessage, clientId);
|
|
10547
|
+
return;
|
|
10548
|
+
}
|
|
10549
|
+
try {
|
|
10550
|
+
const result = await executeCollection("artifacts", "getOne", { id: artifactId });
|
|
10551
|
+
sendResponse8(id, {
|
|
10552
|
+
success: true,
|
|
10553
|
+
data: result.data,
|
|
10554
|
+
message: `Retrieved artifact ID ${artifactId}`
|
|
10555
|
+
}, sendMessage, clientId);
|
|
10556
|
+
logger.info(`Retrieved artifact: ID ${artifactId}`);
|
|
10557
|
+
} catch (error) {
|
|
10558
|
+
sendResponse8(id, {
|
|
10559
|
+
success: false,
|
|
10560
|
+
error: error instanceof Error ? error.message : "Failed to get artifact"
|
|
10561
|
+
}, sendMessage, clientId);
|
|
10562
|
+
}
|
|
10563
|
+
}
|
|
10564
|
+
async function handleQuery6(id, queryParams, executeCollection, sendMessage, clientId) {
|
|
10565
|
+
try {
|
|
10566
|
+
const result = await executeCollection("artifacts", "query", {
|
|
10567
|
+
filters: queryParams.filters,
|
|
10568
|
+
limit: queryParams.limit || 50,
|
|
10569
|
+
sort: queryParams.sort || "DESC"
|
|
10570
|
+
});
|
|
10571
|
+
sendResponse8(id, {
|
|
10572
|
+
success: true,
|
|
10573
|
+
data: result.data,
|
|
10574
|
+
count: result.count,
|
|
10575
|
+
message: `Query returned ${result.count} artifacts`
|
|
10576
|
+
}, sendMessage, clientId);
|
|
10577
|
+
logger.info(`Query artifacts (count: ${result.count})`);
|
|
10578
|
+
} catch (error) {
|
|
10579
|
+
sendResponse8(id, {
|
|
10580
|
+
success: false,
|
|
10581
|
+
error: error instanceof Error ? error.message : "Failed to query artifacts"
|
|
10582
|
+
}, sendMessage, clientId);
|
|
10583
|
+
}
|
|
10584
|
+
}
|
|
10585
|
+
function sendResponse8(id, res, sendMessage, clientId) {
|
|
10586
|
+
const response = {
|
|
10587
|
+
id: id || "unknown",
|
|
10588
|
+
type: "ARTIFACTS_RES",
|
|
10589
|
+
from: { type: "data-agent" },
|
|
10590
|
+
to: {
|
|
10591
|
+
type: "user",
|
|
10592
|
+
id: clientId
|
|
10593
|
+
},
|
|
10594
|
+
payload: {
|
|
10595
|
+
...res
|
|
10596
|
+
}
|
|
10597
|
+
};
|
|
10598
|
+
sendMessage(response);
|
|
10599
|
+
}
|
|
10600
|
+
|
|
10198
10601
|
// src/handlers/kb-nodes.ts
|
|
10199
10602
|
init_logger();
|
|
10200
10603
|
async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
@@ -10214,6 +10617,7 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10214
10617
|
const content = requestData?.content;
|
|
10215
10618
|
const category = requestData?.category;
|
|
10216
10619
|
const tags = requestData?.tags;
|
|
10620
|
+
const type = requestData?.type;
|
|
10217
10621
|
const createdBy = requestData?.createdBy;
|
|
10218
10622
|
const updatedBy = requestData?.updatedBy;
|
|
10219
10623
|
const userId = requestData?.userId;
|
|
@@ -10223,22 +10627,22 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10223
10627
|
const offset = requestData?.offset;
|
|
10224
10628
|
switch (operation) {
|
|
10225
10629
|
case "create":
|
|
10226
|
-
await
|
|
10630
|
+
await handleCreate7(id, { title, content, category, tags, type, createdBy }, executeCollection, sendMessage, from.id);
|
|
10227
10631
|
break;
|
|
10228
10632
|
case "update":
|
|
10229
|
-
await
|
|
10633
|
+
await handleUpdate7(id, nodeId, { title, content, category, tags, type, updatedBy }, executeCollection, sendMessage, from.id);
|
|
10230
10634
|
break;
|
|
10231
10635
|
case "delete":
|
|
10232
|
-
await
|
|
10636
|
+
await handleDelete7(id, nodeId, executeCollection, sendMessage, from.id);
|
|
10233
10637
|
break;
|
|
10234
10638
|
case "getAll":
|
|
10235
|
-
await
|
|
10639
|
+
await handleGetAll7(id, limit, offset, executeCollection, sendMessage, from.id);
|
|
10236
10640
|
break;
|
|
10237
10641
|
case "getOne":
|
|
10238
|
-
await
|
|
10642
|
+
await handleGetOne7(id, nodeId, executeCollection, sendMessage, from.id);
|
|
10239
10643
|
break;
|
|
10240
10644
|
case "search":
|
|
10241
|
-
await handleSearch(id, { query, category, tags, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
10645
|
+
await handleSearch(id, { query, category, tags, type, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
10242
10646
|
break;
|
|
10243
10647
|
case "getByCategory":
|
|
10244
10648
|
await handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, from.id);
|
|
@@ -10253,37 +10657,37 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10253
10657
|
await handleGetTags(id, executeCollection, sendMessage, from.id);
|
|
10254
10658
|
break;
|
|
10255
10659
|
default:
|
|
10256
|
-
|
|
10660
|
+
sendResponse9(id, {
|
|
10257
10661
|
success: false,
|
|
10258
10662
|
error: `Unknown operation: ${operation}`
|
|
10259
10663
|
}, sendMessage, from.id);
|
|
10260
10664
|
}
|
|
10261
10665
|
} catch (error) {
|
|
10262
10666
|
logger.error("Failed to handle KB nodes request:", error);
|
|
10263
|
-
|
|
10667
|
+
sendResponse9(null, {
|
|
10264
10668
|
success: false,
|
|
10265
10669
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10266
10670
|
}, sendMessage);
|
|
10267
10671
|
}
|
|
10268
10672
|
}
|
|
10269
|
-
async function
|
|
10270
|
-
const { title, content, category, tags, createdBy } = nodeData;
|
|
10673
|
+
async function handleCreate7(id, nodeData, executeCollection, sendMessage, clientId) {
|
|
10674
|
+
const { title, content, category, tags, type, createdBy } = nodeData;
|
|
10271
10675
|
if (!title || title.trim().length === 0) {
|
|
10272
|
-
|
|
10676
|
+
sendResponse9(id, {
|
|
10273
10677
|
success: false,
|
|
10274
10678
|
error: "Title is required and cannot be empty"
|
|
10275
10679
|
}, sendMessage, clientId);
|
|
10276
10680
|
return;
|
|
10277
10681
|
}
|
|
10278
10682
|
if (!content || content.trim().length === 0) {
|
|
10279
|
-
|
|
10683
|
+
sendResponse9(id, {
|
|
10280
10684
|
success: false,
|
|
10281
10685
|
error: "Content is required and cannot be empty"
|
|
10282
10686
|
}, sendMessage, clientId);
|
|
10283
10687
|
return;
|
|
10284
10688
|
}
|
|
10285
10689
|
if (!createdBy) {
|
|
10286
|
-
|
|
10690
|
+
sendResponse9(id, {
|
|
10287
10691
|
success: false,
|
|
10288
10692
|
error: "createdBy (user ID) is required"
|
|
10289
10693
|
}, sendMessage, clientId);
|
|
@@ -10295,11 +10699,12 @@ async function handleCreate6(id, nodeData, executeCollection, sendMessage, clien
|
|
|
10295
10699
|
content,
|
|
10296
10700
|
category: category || void 0,
|
|
10297
10701
|
tags: tags || void 0,
|
|
10702
|
+
type: type || "query",
|
|
10298
10703
|
createdBy
|
|
10299
10704
|
});
|
|
10300
10705
|
if (result && result.success) {
|
|
10301
10706
|
logger.info(`[DB] KB node created successfully: ${title}`);
|
|
10302
|
-
|
|
10707
|
+
sendResponse9(id, {
|
|
10303
10708
|
success: true,
|
|
10304
10709
|
data: {
|
|
10305
10710
|
...result.data,
|
|
@@ -10308,29 +10713,29 @@ async function handleCreate6(id, nodeData, executeCollection, sendMessage, clien
|
|
|
10308
10713
|
}, sendMessage, clientId);
|
|
10309
10714
|
return;
|
|
10310
10715
|
}
|
|
10311
|
-
|
|
10716
|
+
sendResponse9(id, {
|
|
10312
10717
|
success: false,
|
|
10313
10718
|
error: "Failed to create knowledge node"
|
|
10314
10719
|
}, sendMessage, clientId);
|
|
10315
10720
|
} catch (error) {
|
|
10316
10721
|
logger.error("[DB] Failed to create KB node:", error);
|
|
10317
|
-
|
|
10722
|
+
sendResponse9(id, {
|
|
10318
10723
|
success: false,
|
|
10319
10724
|
error: error instanceof Error ? error.message : "Failed to create knowledge node"
|
|
10320
10725
|
}, sendMessage, clientId);
|
|
10321
10726
|
}
|
|
10322
10727
|
}
|
|
10323
|
-
async function
|
|
10324
|
-
const { title, content, category, tags, updatedBy } = nodeData;
|
|
10728
|
+
async function handleUpdate7(id, nodeId, nodeData, executeCollection, sendMessage, clientId) {
|
|
10729
|
+
const { title, content, category, tags, type, updatedBy } = nodeData;
|
|
10325
10730
|
if (!nodeId) {
|
|
10326
|
-
|
|
10731
|
+
sendResponse9(id, {
|
|
10327
10732
|
success: false,
|
|
10328
10733
|
error: "Knowledge node ID is required"
|
|
10329
10734
|
}, sendMessage, clientId);
|
|
10330
10735
|
return;
|
|
10331
10736
|
}
|
|
10332
10737
|
if (!updatedBy) {
|
|
10333
|
-
|
|
10738
|
+
sendResponse9(id, {
|
|
10334
10739
|
success: false,
|
|
10335
10740
|
error: "updatedBy (user ID) is required"
|
|
10336
10741
|
}, sendMessage, clientId);
|
|
@@ -10343,11 +10748,12 @@ async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessag
|
|
|
10343
10748
|
content,
|
|
10344
10749
|
category,
|
|
10345
10750
|
tags,
|
|
10751
|
+
type,
|
|
10346
10752
|
updatedBy
|
|
10347
10753
|
});
|
|
10348
10754
|
if (result && result.success) {
|
|
10349
10755
|
logger.info(`[DB] KB node updated successfully, ID: ${nodeId}`);
|
|
10350
|
-
|
|
10756
|
+
sendResponse9(id, {
|
|
10351
10757
|
success: true,
|
|
10352
10758
|
data: {
|
|
10353
10759
|
...result.data,
|
|
@@ -10356,21 +10762,21 @@ async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessag
|
|
|
10356
10762
|
}, sendMessage, clientId);
|
|
10357
10763
|
return;
|
|
10358
10764
|
}
|
|
10359
|
-
|
|
10765
|
+
sendResponse9(id, {
|
|
10360
10766
|
success: false,
|
|
10361
10767
|
error: "Failed to update knowledge node"
|
|
10362
10768
|
}, sendMessage, clientId);
|
|
10363
10769
|
} catch (error) {
|
|
10364
10770
|
logger.error("[DB] Failed to update KB node:", error);
|
|
10365
|
-
|
|
10771
|
+
sendResponse9(id, {
|
|
10366
10772
|
success: false,
|
|
10367
10773
|
error: error instanceof Error ? error.message : "Failed to update knowledge node"
|
|
10368
10774
|
}, sendMessage, clientId);
|
|
10369
10775
|
}
|
|
10370
10776
|
}
|
|
10371
|
-
async function
|
|
10777
|
+
async function handleDelete7(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
10372
10778
|
if (!nodeId) {
|
|
10373
|
-
|
|
10779
|
+
sendResponse9(id, {
|
|
10374
10780
|
success: false,
|
|
10375
10781
|
error: "Knowledge node ID is required"
|
|
10376
10782
|
}, sendMessage, clientId);
|
|
@@ -10380,7 +10786,7 @@ async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10380
10786
|
const result = await executeCollection("kbNodes", "delete", { id: nodeId });
|
|
10381
10787
|
if (result && result.success) {
|
|
10382
10788
|
logger.info(`[DB] KB node deleted successfully, ID: ${nodeId}`);
|
|
10383
|
-
|
|
10789
|
+
sendResponse9(id, {
|
|
10384
10790
|
success: true,
|
|
10385
10791
|
data: {
|
|
10386
10792
|
id: nodeId,
|
|
@@ -10390,19 +10796,19 @@ async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10390
10796
|
}, sendMessage, clientId);
|
|
10391
10797
|
return;
|
|
10392
10798
|
}
|
|
10393
|
-
|
|
10799
|
+
sendResponse9(id, {
|
|
10394
10800
|
success: false,
|
|
10395
10801
|
error: "Failed to delete knowledge node"
|
|
10396
10802
|
}, sendMessage, clientId);
|
|
10397
10803
|
} catch (error) {
|
|
10398
10804
|
logger.error("[DB] Failed to delete KB node:", error);
|
|
10399
|
-
|
|
10805
|
+
sendResponse9(id, {
|
|
10400
10806
|
success: false,
|
|
10401
10807
|
error: error instanceof Error ? error.message : "Failed to delete knowledge node"
|
|
10402
10808
|
}, sendMessage, clientId);
|
|
10403
10809
|
}
|
|
10404
10810
|
}
|
|
10405
|
-
async function
|
|
10811
|
+
async function handleGetAll7(id, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10406
10812
|
try {
|
|
10407
10813
|
const result = await executeCollection("kbNodes", "getAll", {
|
|
10408
10814
|
limit: limit || 100,
|
|
@@ -10410,7 +10816,7 @@ async function handleGetAll6(id, limit, offset, executeCollection, sendMessage,
|
|
|
10410
10816
|
});
|
|
10411
10817
|
if (result && result.success) {
|
|
10412
10818
|
logger.info(`[DB] Retrieved ${result.count} KB nodes`);
|
|
10413
|
-
|
|
10819
|
+
sendResponse9(id, {
|
|
10414
10820
|
success: true,
|
|
10415
10821
|
data: {
|
|
10416
10822
|
nodes: result.data,
|
|
@@ -10420,21 +10826,21 @@ async function handleGetAll6(id, limit, offset, executeCollection, sendMessage,
|
|
|
10420
10826
|
}, sendMessage, clientId);
|
|
10421
10827
|
return;
|
|
10422
10828
|
}
|
|
10423
|
-
|
|
10829
|
+
sendResponse9(id, {
|
|
10424
10830
|
success: false,
|
|
10425
10831
|
error: "Failed to retrieve knowledge nodes"
|
|
10426
10832
|
}, sendMessage, clientId);
|
|
10427
10833
|
} catch (error) {
|
|
10428
10834
|
logger.error("[DB] Failed to get all KB nodes:", error);
|
|
10429
|
-
|
|
10835
|
+
sendResponse9(id, {
|
|
10430
10836
|
success: false,
|
|
10431
10837
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes"
|
|
10432
10838
|
}, sendMessage, clientId);
|
|
10433
10839
|
}
|
|
10434
10840
|
}
|
|
10435
|
-
async function
|
|
10841
|
+
async function handleGetOne7(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
10436
10842
|
if (!nodeId) {
|
|
10437
|
-
|
|
10843
|
+
sendResponse9(id, {
|
|
10438
10844
|
success: false,
|
|
10439
10845
|
error: "Knowledge node ID is required"
|
|
10440
10846
|
}, sendMessage, clientId);
|
|
@@ -10444,7 +10850,7 @@ async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10444
10850
|
const result = await executeCollection("kbNodes", "getOne", { id: nodeId });
|
|
10445
10851
|
if (result && result.success) {
|
|
10446
10852
|
logger.info(`[DB] Retrieved KB node ID: ${nodeId}`);
|
|
10447
|
-
|
|
10853
|
+
sendResponse9(id, {
|
|
10448
10854
|
success: true,
|
|
10449
10855
|
data: {
|
|
10450
10856
|
node: result.data,
|
|
@@ -10453,32 +10859,33 @@ async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10453
10859
|
}, sendMessage, clientId);
|
|
10454
10860
|
return;
|
|
10455
10861
|
}
|
|
10456
|
-
|
|
10862
|
+
sendResponse9(id, {
|
|
10457
10863
|
success: false,
|
|
10458
10864
|
error: "Failed to retrieve knowledge node"
|
|
10459
10865
|
}, sendMessage, clientId);
|
|
10460
10866
|
} catch (error) {
|
|
10461
10867
|
logger.error("[DB] Failed to get KB node:", error);
|
|
10462
|
-
|
|
10868
|
+
sendResponse9(id, {
|
|
10463
10869
|
success: false,
|
|
10464
10870
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge node"
|
|
10465
10871
|
}, sendMessage, clientId);
|
|
10466
10872
|
}
|
|
10467
10873
|
}
|
|
10468
10874
|
async function handleSearch(id, searchParams, executeCollection, sendMessage, clientId) {
|
|
10469
|
-
const { query, category, tags, createdBy, limit, offset } = searchParams;
|
|
10875
|
+
const { query, category, tags, type, createdBy, limit, offset } = searchParams;
|
|
10470
10876
|
try {
|
|
10471
10877
|
const result = await executeCollection("kbNodes", "search", {
|
|
10472
10878
|
query,
|
|
10473
10879
|
category,
|
|
10474
10880
|
tags,
|
|
10881
|
+
type,
|
|
10475
10882
|
createdBy,
|
|
10476
10883
|
limit: limit || 50,
|
|
10477
10884
|
offset: offset || 0
|
|
10478
10885
|
});
|
|
10479
10886
|
if (result && result.success) {
|
|
10480
10887
|
logger.info(`[DB] Search returned ${result.count} KB nodes`);
|
|
10481
|
-
|
|
10888
|
+
sendResponse9(id, {
|
|
10482
10889
|
success: true,
|
|
10483
10890
|
data: {
|
|
10484
10891
|
nodes: result.data,
|
|
@@ -10488,13 +10895,13 @@ async function handleSearch(id, searchParams, executeCollection, sendMessage, cl
|
|
|
10488
10895
|
}, sendMessage, clientId);
|
|
10489
10896
|
return;
|
|
10490
10897
|
}
|
|
10491
|
-
|
|
10898
|
+
sendResponse9(id, {
|
|
10492
10899
|
success: false,
|
|
10493
10900
|
error: "Failed to search knowledge nodes"
|
|
10494
10901
|
}, sendMessage, clientId);
|
|
10495
10902
|
} catch (error) {
|
|
10496
10903
|
logger.error("[DB] Failed to search KB nodes:", error);
|
|
10497
|
-
|
|
10904
|
+
sendResponse9(id, {
|
|
10498
10905
|
success: false,
|
|
10499
10906
|
error: error instanceof Error ? error.message : "Failed to search knowledge nodes"
|
|
10500
10907
|
}, sendMessage, clientId);
|
|
@@ -10502,7 +10909,7 @@ async function handleSearch(id, searchParams, executeCollection, sendMessage, cl
|
|
|
10502
10909
|
}
|
|
10503
10910
|
async function handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10504
10911
|
if (!category) {
|
|
10505
|
-
|
|
10912
|
+
sendResponse9(id, {
|
|
10506
10913
|
success: false,
|
|
10507
10914
|
error: "Category is required"
|
|
10508
10915
|
}, sendMessage, clientId);
|
|
@@ -10516,7 +10923,7 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10516
10923
|
});
|
|
10517
10924
|
if (result && result.success) {
|
|
10518
10925
|
logger.info(`[DB] Retrieved ${result.count} KB nodes for category: ${category}`);
|
|
10519
|
-
|
|
10926
|
+
sendResponse9(id, {
|
|
10520
10927
|
success: true,
|
|
10521
10928
|
data: {
|
|
10522
10929
|
nodes: result.data,
|
|
@@ -10527,13 +10934,13 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10527
10934
|
}, sendMessage, clientId);
|
|
10528
10935
|
return;
|
|
10529
10936
|
}
|
|
10530
|
-
|
|
10937
|
+
sendResponse9(id, {
|
|
10531
10938
|
success: false,
|
|
10532
10939
|
error: "Failed to retrieve knowledge nodes by category"
|
|
10533
10940
|
}, sendMessage, clientId);
|
|
10534
10941
|
} catch (error) {
|
|
10535
10942
|
logger.error("[DB] Failed to get KB nodes by category:", error);
|
|
10536
|
-
|
|
10943
|
+
sendResponse9(id, {
|
|
10537
10944
|
success: false,
|
|
10538
10945
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by category"
|
|
10539
10946
|
}, sendMessage, clientId);
|
|
@@ -10541,7 +10948,7 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10541
10948
|
}
|
|
10542
10949
|
async function handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10543
10950
|
if (!userId) {
|
|
10544
|
-
|
|
10951
|
+
sendResponse9(id, {
|
|
10545
10952
|
success: false,
|
|
10546
10953
|
error: "User ID is required"
|
|
10547
10954
|
}, sendMessage, clientId);
|
|
@@ -10555,7 +10962,7 @@ async function handleGetByUser(id, userId, limit, offset, executeCollection, sen
|
|
|
10555
10962
|
});
|
|
10556
10963
|
if (result && result.success) {
|
|
10557
10964
|
logger.info(`[DB] Retrieved ${result.count} KB nodes for user: ${userId}`);
|
|
10558
|
-
|
|
10965
|
+
sendResponse9(id, {
|
|
10559
10966
|
success: true,
|
|
10560
10967
|
data: {
|
|
10561
10968
|
nodes: result.data,
|
|
@@ -10566,13 +10973,13 @@ async function handleGetByUser(id, userId, limit, offset, executeCollection, sen
|
|
|
10566
10973
|
}, sendMessage, clientId);
|
|
10567
10974
|
return;
|
|
10568
10975
|
}
|
|
10569
|
-
|
|
10976
|
+
sendResponse9(id, {
|
|
10570
10977
|
success: false,
|
|
10571
10978
|
error: "Failed to retrieve knowledge nodes by user"
|
|
10572
10979
|
}, sendMessage, clientId);
|
|
10573
10980
|
} catch (error) {
|
|
10574
10981
|
logger.error("[DB] Failed to get KB nodes by user:", error);
|
|
10575
|
-
|
|
10982
|
+
sendResponse9(id, {
|
|
10576
10983
|
success: false,
|
|
10577
10984
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by user"
|
|
10578
10985
|
}, sendMessage, clientId);
|
|
@@ -10583,7 +10990,7 @@ async function handleGetCategories(id, executeCollection, sendMessage, clientId)
|
|
|
10583
10990
|
const result = await executeCollection("kbNodes", "getCategories", {});
|
|
10584
10991
|
if (result && result.success) {
|
|
10585
10992
|
logger.info(`[DB] Retrieved ${result.count} categories`);
|
|
10586
|
-
|
|
10993
|
+
sendResponse9(id, {
|
|
10587
10994
|
success: true,
|
|
10588
10995
|
data: {
|
|
10589
10996
|
categories: result.data,
|
|
@@ -10593,13 +11000,13 @@ async function handleGetCategories(id, executeCollection, sendMessage, clientId)
|
|
|
10593
11000
|
}, sendMessage, clientId);
|
|
10594
11001
|
return;
|
|
10595
11002
|
}
|
|
10596
|
-
|
|
11003
|
+
sendResponse9(id, {
|
|
10597
11004
|
success: false,
|
|
10598
11005
|
error: "Failed to retrieve categories"
|
|
10599
11006
|
}, sendMessage, clientId);
|
|
10600
11007
|
} catch (error) {
|
|
10601
11008
|
logger.error("[DB] Failed to get categories:", error);
|
|
10602
|
-
|
|
11009
|
+
sendResponse9(id, {
|
|
10603
11010
|
success: false,
|
|
10604
11011
|
error: error instanceof Error ? error.message : "Failed to retrieve categories"
|
|
10605
11012
|
}, sendMessage, clientId);
|
|
@@ -10610,7 +11017,7 @@ async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
|
10610
11017
|
const result = await executeCollection("kbNodes", "getTags", {});
|
|
10611
11018
|
if (result && result.success) {
|
|
10612
11019
|
logger.info(`[DB] Retrieved ${result.count} tags`);
|
|
10613
|
-
|
|
11020
|
+
sendResponse9(id, {
|
|
10614
11021
|
success: true,
|
|
10615
11022
|
data: {
|
|
10616
11023
|
tags: result.data,
|
|
@@ -10620,19 +11027,19 @@ async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
|
10620
11027
|
}, sendMessage, clientId);
|
|
10621
11028
|
return;
|
|
10622
11029
|
}
|
|
10623
|
-
|
|
11030
|
+
sendResponse9(id, {
|
|
10624
11031
|
success: false,
|
|
10625
11032
|
error: "Failed to retrieve tags"
|
|
10626
11033
|
}, sendMessage, clientId);
|
|
10627
11034
|
} catch (error) {
|
|
10628
11035
|
logger.error("[DB] Failed to get tags:", error);
|
|
10629
|
-
|
|
11036
|
+
sendResponse9(id, {
|
|
10630
11037
|
success: false,
|
|
10631
11038
|
error: error instanceof Error ? error.message : "Failed to retrieve tags"
|
|
10632
11039
|
}, sendMessage, clientId);
|
|
10633
11040
|
}
|
|
10634
11041
|
}
|
|
10635
|
-
function
|
|
11042
|
+
function sendResponse9(id, res, sendMessage, clientId) {
|
|
10636
11043
|
const response = {
|
|
10637
11044
|
id: id || "unknown",
|
|
10638
11045
|
type: "KB_NODES_RES",
|
|
@@ -10677,19 +11084,19 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10677
11084
|
const items = requestData?.items;
|
|
10678
11085
|
switch (operation) {
|
|
10679
11086
|
case "create":
|
|
10680
|
-
await
|
|
11087
|
+
await handleCreate8(id, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, from.id);
|
|
10681
11088
|
break;
|
|
10682
11089
|
case "update":
|
|
10683
|
-
await
|
|
11090
|
+
await handleUpdate8(id, menuId, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, from.id);
|
|
10684
11091
|
break;
|
|
10685
11092
|
case "delete":
|
|
10686
|
-
await
|
|
11093
|
+
await handleDelete8(id, menuId, executeCollection, sendMessage, from.id);
|
|
10687
11094
|
break;
|
|
10688
11095
|
case "getAll":
|
|
10689
|
-
await
|
|
11096
|
+
await handleGetAll8(id, executeCollection, sendMessage, from.id);
|
|
10690
11097
|
break;
|
|
10691
11098
|
case "getOne":
|
|
10692
|
-
await
|
|
11099
|
+
await handleGetOne8(id, menuId, executeCollection, sendMessage, from.id);
|
|
10693
11100
|
break;
|
|
10694
11101
|
case "getRootMenus":
|
|
10695
11102
|
await handleGetRootMenus(id, executeCollection, sendMessage, from.id);
|
|
@@ -10701,35 +11108,35 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10701
11108
|
await handleGetHierarchy(id, executeCollection, sendMessage, from.id);
|
|
10702
11109
|
break;
|
|
10703
11110
|
case "query":
|
|
10704
|
-
await
|
|
11111
|
+
await handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
10705
11112
|
break;
|
|
10706
11113
|
case "reorder":
|
|
10707
11114
|
await handleReorder(id, items, executeCollection, sendMessage, from.id);
|
|
10708
11115
|
break;
|
|
10709
11116
|
default:
|
|
10710
|
-
|
|
11117
|
+
sendResponse10(id, {
|
|
10711
11118
|
success: false,
|
|
10712
11119
|
error: `Unknown operation: ${operation}`
|
|
10713
11120
|
}, sendMessage, from.id);
|
|
10714
11121
|
}
|
|
10715
11122
|
} catch (error) {
|
|
10716
11123
|
logger.error("Failed to handle menus request:", error);
|
|
10717
|
-
|
|
11124
|
+
sendResponse10(null, {
|
|
10718
11125
|
success: false,
|
|
10719
11126
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10720
11127
|
}, sendMessage);
|
|
10721
11128
|
}
|
|
10722
11129
|
}
|
|
10723
|
-
async function
|
|
11130
|
+
async function handleCreate8(id, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, clientId) {
|
|
10724
11131
|
if (!name) {
|
|
10725
|
-
|
|
11132
|
+
sendResponse10(id, {
|
|
10726
11133
|
success: false,
|
|
10727
11134
|
error: "name is required"
|
|
10728
11135
|
}, sendMessage, clientId);
|
|
10729
11136
|
return;
|
|
10730
11137
|
}
|
|
10731
11138
|
if (!componentName) {
|
|
10732
|
-
|
|
11139
|
+
sendResponse10(id, {
|
|
10733
11140
|
success: false,
|
|
10734
11141
|
error: "componentName is required"
|
|
10735
11142
|
}, sendMessage, clientId);
|
|
@@ -10746,22 +11153,22 @@ async function handleCreate7(id, name, componentName, icon, userMessage, parentI
|
|
|
10746
11153
|
props,
|
|
10747
11154
|
isActive
|
|
10748
11155
|
});
|
|
10749
|
-
|
|
11156
|
+
sendResponse10(id, {
|
|
10750
11157
|
success: true,
|
|
10751
11158
|
data: result.data,
|
|
10752
11159
|
message: "Menu created successfully"
|
|
10753
11160
|
}, sendMessage, clientId);
|
|
10754
11161
|
logger.info(`Menu created: ID ${result.data?.id}`);
|
|
10755
11162
|
} catch (error) {
|
|
10756
|
-
|
|
11163
|
+
sendResponse10(id, {
|
|
10757
11164
|
success: false,
|
|
10758
11165
|
error: error instanceof Error ? error.message : "Failed to create menu"
|
|
10759
11166
|
}, sendMessage, clientId);
|
|
10760
11167
|
}
|
|
10761
11168
|
}
|
|
10762
|
-
async function
|
|
11169
|
+
async function handleUpdate8(id, menuId, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, clientId) {
|
|
10763
11170
|
if (!menuId) {
|
|
10764
|
-
|
|
11171
|
+
sendResponse10(id, {
|
|
10765
11172
|
success: false,
|
|
10766
11173
|
error: "Menu ID is required"
|
|
10767
11174
|
}, sendMessage, clientId);
|
|
@@ -10779,22 +11186,22 @@ async function handleUpdate7(id, menuId, name, componentName, icon, userMessage,
|
|
|
10779
11186
|
props,
|
|
10780
11187
|
isActive
|
|
10781
11188
|
});
|
|
10782
|
-
|
|
11189
|
+
sendResponse10(id, {
|
|
10783
11190
|
success: true,
|
|
10784
11191
|
data: result.data,
|
|
10785
11192
|
message: "Menu updated successfully"
|
|
10786
11193
|
}, sendMessage, clientId);
|
|
10787
11194
|
logger.info(`Menu updated: ID ${menuId}`);
|
|
10788
11195
|
} catch (error) {
|
|
10789
|
-
|
|
11196
|
+
sendResponse10(id, {
|
|
10790
11197
|
success: false,
|
|
10791
11198
|
error: error instanceof Error ? error.message : "Failed to update menu"
|
|
10792
11199
|
}, sendMessage, clientId);
|
|
10793
11200
|
}
|
|
10794
11201
|
}
|
|
10795
|
-
async function
|
|
11202
|
+
async function handleDelete8(id, menuId, executeCollection, sendMessage, clientId) {
|
|
10796
11203
|
if (!menuId) {
|
|
10797
|
-
|
|
11204
|
+
sendResponse10(id, {
|
|
10798
11205
|
success: false,
|
|
10799
11206
|
error: "Menu ID is required"
|
|
10800
11207
|
}, sendMessage, clientId);
|
|
@@ -10802,23 +11209,23 @@ async function handleDelete7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10802
11209
|
}
|
|
10803
11210
|
try {
|
|
10804
11211
|
const result = await executeCollection("menus", "delete", { id: menuId });
|
|
10805
|
-
|
|
11212
|
+
sendResponse10(id, {
|
|
10806
11213
|
success: true,
|
|
10807
11214
|
data: result.data,
|
|
10808
11215
|
message: "Menu deleted successfully"
|
|
10809
11216
|
}, sendMessage, clientId);
|
|
10810
11217
|
logger.info(`Menu deleted: ID ${menuId}`);
|
|
10811
11218
|
} catch (error) {
|
|
10812
|
-
|
|
11219
|
+
sendResponse10(id, {
|
|
10813
11220
|
success: false,
|
|
10814
11221
|
error: error instanceof Error ? error.message : "Failed to delete menu"
|
|
10815
11222
|
}, sendMessage, clientId);
|
|
10816
11223
|
}
|
|
10817
11224
|
}
|
|
10818
|
-
async function
|
|
11225
|
+
async function handleGetAll8(id, executeCollection, sendMessage, clientId) {
|
|
10819
11226
|
try {
|
|
10820
11227
|
const result = await executeCollection("menus", "getAll", {});
|
|
10821
|
-
|
|
11228
|
+
sendResponse10(id, {
|
|
10822
11229
|
success: true,
|
|
10823
11230
|
data: result.data,
|
|
10824
11231
|
count: result.count,
|
|
@@ -10826,15 +11233,15 @@ async function handleGetAll7(id, executeCollection, sendMessage, clientId) {
|
|
|
10826
11233
|
}, sendMessage, clientId);
|
|
10827
11234
|
logger.info(`Retrieved all menus (count: ${result.count})`);
|
|
10828
11235
|
} catch (error) {
|
|
10829
|
-
|
|
11236
|
+
sendResponse10(id, {
|
|
10830
11237
|
success: false,
|
|
10831
11238
|
error: error instanceof Error ? error.message : "Failed to get menus"
|
|
10832
11239
|
}, sendMessage, clientId);
|
|
10833
11240
|
}
|
|
10834
11241
|
}
|
|
10835
|
-
async function
|
|
11242
|
+
async function handleGetOne8(id, menuId, executeCollection, sendMessage, clientId) {
|
|
10836
11243
|
if (!menuId) {
|
|
10837
|
-
|
|
11244
|
+
sendResponse10(id, {
|
|
10838
11245
|
success: false,
|
|
10839
11246
|
error: "Menu ID is required"
|
|
10840
11247
|
}, sendMessage, clientId);
|
|
@@ -10842,14 +11249,14 @@ async function handleGetOne7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10842
11249
|
}
|
|
10843
11250
|
try {
|
|
10844
11251
|
const result = await executeCollection("menus", "getOne", { id: menuId });
|
|
10845
|
-
|
|
11252
|
+
sendResponse10(id, {
|
|
10846
11253
|
success: true,
|
|
10847
11254
|
data: result.data,
|
|
10848
11255
|
message: `Retrieved menu ID ${menuId}`
|
|
10849
11256
|
}, sendMessage, clientId);
|
|
10850
11257
|
logger.info(`Retrieved menu: ID ${menuId}`);
|
|
10851
11258
|
} catch (error) {
|
|
10852
|
-
|
|
11259
|
+
sendResponse10(id, {
|
|
10853
11260
|
success: false,
|
|
10854
11261
|
error: error instanceof Error ? error.message : "Failed to get menu"
|
|
10855
11262
|
}, sendMessage, clientId);
|
|
@@ -10858,7 +11265,7 @@ async function handleGetOne7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10858
11265
|
async function handleGetRootMenus(id, executeCollection, sendMessage, clientId) {
|
|
10859
11266
|
try {
|
|
10860
11267
|
const result = await executeCollection("menus", "getRootMenus", {});
|
|
10861
|
-
|
|
11268
|
+
sendResponse10(id, {
|
|
10862
11269
|
success: true,
|
|
10863
11270
|
data: result.data,
|
|
10864
11271
|
count: result.count,
|
|
@@ -10866,7 +11273,7 @@ async function handleGetRootMenus(id, executeCollection, sendMessage, clientId)
|
|
|
10866
11273
|
}, sendMessage, clientId);
|
|
10867
11274
|
logger.info(`Retrieved root menus (count: ${result.count})`);
|
|
10868
11275
|
} catch (error) {
|
|
10869
|
-
|
|
11276
|
+
sendResponse10(id, {
|
|
10870
11277
|
success: false,
|
|
10871
11278
|
error: error instanceof Error ? error.message : "Failed to get root menus"
|
|
10872
11279
|
}, sendMessage, clientId);
|
|
@@ -10874,7 +11281,7 @@ async function handleGetRootMenus(id, executeCollection, sendMessage, clientId)
|
|
|
10874
11281
|
}
|
|
10875
11282
|
async function handleGetChildMenus(id, parentId, executeCollection, sendMessage, clientId) {
|
|
10876
11283
|
if (parentId === void 0 || parentId === null) {
|
|
10877
|
-
|
|
11284
|
+
sendResponse10(id, {
|
|
10878
11285
|
success: false,
|
|
10879
11286
|
error: "parentId is required"
|
|
10880
11287
|
}, sendMessage, clientId);
|
|
@@ -10882,7 +11289,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10882
11289
|
}
|
|
10883
11290
|
try {
|
|
10884
11291
|
const result = await executeCollection("menus", "getChildMenus", { parentId });
|
|
10885
|
-
|
|
11292
|
+
sendResponse10(id, {
|
|
10886
11293
|
success: true,
|
|
10887
11294
|
data: result.data,
|
|
10888
11295
|
count: result.count,
|
|
@@ -10890,7 +11297,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10890
11297
|
}, sendMessage, clientId);
|
|
10891
11298
|
logger.info(`Retrieved child menus for parent ${parentId} (count: ${result.count})`);
|
|
10892
11299
|
} catch (error) {
|
|
10893
|
-
|
|
11300
|
+
sendResponse10(id, {
|
|
10894
11301
|
success: false,
|
|
10895
11302
|
error: error instanceof Error ? error.message : "Failed to get child menus"
|
|
10896
11303
|
}, sendMessage, clientId);
|
|
@@ -10899,7 +11306,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10899
11306
|
async function handleGetHierarchy(id, executeCollection, sendMessage, clientId) {
|
|
10900
11307
|
try {
|
|
10901
11308
|
const result = await executeCollection("menus", "getHierarchy", {});
|
|
10902
|
-
|
|
11309
|
+
sendResponse10(id, {
|
|
10903
11310
|
success: true,
|
|
10904
11311
|
data: result.data,
|
|
10905
11312
|
count: result.count,
|
|
@@ -10907,20 +11314,20 @@ async function handleGetHierarchy(id, executeCollection, sendMessage, clientId)
|
|
|
10907
11314
|
}, sendMessage, clientId);
|
|
10908
11315
|
logger.info(`Retrieved menus hierarchy (root count: ${result.count})`);
|
|
10909
11316
|
} catch (error) {
|
|
10910
|
-
|
|
11317
|
+
sendResponse10(id, {
|
|
10911
11318
|
success: false,
|
|
10912
11319
|
error: error instanceof Error ? error.message : "Failed to get menus hierarchy"
|
|
10913
11320
|
}, sendMessage, clientId);
|
|
10914
11321
|
}
|
|
10915
11322
|
}
|
|
10916
|
-
async function
|
|
11323
|
+
async function handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
10917
11324
|
try {
|
|
10918
11325
|
const result = await executeCollection("menus", "query", {
|
|
10919
11326
|
filters: filters || {},
|
|
10920
11327
|
limit,
|
|
10921
11328
|
sort
|
|
10922
11329
|
});
|
|
10923
|
-
|
|
11330
|
+
sendResponse10(id, {
|
|
10924
11331
|
success: true,
|
|
10925
11332
|
data: result.data,
|
|
10926
11333
|
count: result.count,
|
|
@@ -10928,7 +11335,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10928
11335
|
}, sendMessage, clientId);
|
|
10929
11336
|
logger.info(`Query returned ${result.count} menus`);
|
|
10930
11337
|
} catch (error) {
|
|
10931
|
-
|
|
11338
|
+
sendResponse10(id, {
|
|
10932
11339
|
success: false,
|
|
10933
11340
|
error: error instanceof Error ? error.message : "Failed to query menus"
|
|
10934
11341
|
}, sendMessage, clientId);
|
|
@@ -10936,7 +11343,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10936
11343
|
}
|
|
10937
11344
|
async function handleReorder(id, items, executeCollection, sendMessage, clientId) {
|
|
10938
11345
|
if (!items || !Array.isArray(items) || items.length === 0) {
|
|
10939
|
-
|
|
11346
|
+
sendResponse10(id, {
|
|
10940
11347
|
success: false,
|
|
10941
11348
|
error: "items array is required"
|
|
10942
11349
|
}, sendMessage, clientId);
|
|
@@ -10944,20 +11351,20 @@ async function handleReorder(id, items, executeCollection, sendMessage, clientId
|
|
|
10944
11351
|
}
|
|
10945
11352
|
try {
|
|
10946
11353
|
const result = await executeCollection("menus", "reorder", { items });
|
|
10947
|
-
|
|
11354
|
+
sendResponse10(id, {
|
|
10948
11355
|
success: true,
|
|
10949
11356
|
data: result.data,
|
|
10950
11357
|
message: `Reordered ${items.length} menus successfully`
|
|
10951
11358
|
}, sendMessage, clientId);
|
|
10952
11359
|
logger.info(`Reordered ${items.length} menus`);
|
|
10953
11360
|
} catch (error) {
|
|
10954
|
-
|
|
11361
|
+
sendResponse10(id, {
|
|
10955
11362
|
success: false,
|
|
10956
11363
|
error: error instanceof Error ? error.message : "Failed to reorder menus"
|
|
10957
11364
|
}, sendMessage, clientId);
|
|
10958
11365
|
}
|
|
10959
11366
|
}
|
|
10960
|
-
function
|
|
11367
|
+
function sendResponse10(id, res, sendMessage, clientId) {
|
|
10961
11368
|
const response = {
|
|
10962
11369
|
id: id || "unknown",
|
|
10963
11370
|
type: "MENUS_RES",
|
|
@@ -12489,6 +12896,11 @@ var SuperatomSDK = class {
|
|
|
12489
12896
|
logger.error("Failed to handle bookmarks request:", error);
|
|
12490
12897
|
});
|
|
12491
12898
|
break;
|
|
12899
|
+
case "ARTIFACTS":
|
|
12900
|
+
handleArtifactsRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
12901
|
+
logger.error("Failed to handle artifacts request:", error);
|
|
12902
|
+
});
|
|
12903
|
+
break;
|
|
12492
12904
|
case "KB_NODES":
|
|
12493
12905
|
handleKbNodesRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
12494
12906
|
logger.error("Failed to handle KB nodes request:", error);
|