@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.mjs
CHANGED
|
@@ -2359,10 +2359,39 @@ var BookmarksRequestMessageSchema = z3.object({
|
|
|
2359
2359
|
type: z3.literal("BOOKMARKS"),
|
|
2360
2360
|
payload: BookmarksRequestPayloadSchema
|
|
2361
2361
|
});
|
|
2362
|
+
var ArtifactsQueryFiltersSchema = z3.object({
|
|
2363
|
+
createdBy: z3.number().optional(),
|
|
2364
|
+
status: z3.string().optional(),
|
|
2365
|
+
name: z3.string().optional(),
|
|
2366
|
+
deleted: z3.boolean().optional()
|
|
2367
|
+
});
|
|
2368
|
+
var ArtifactsRequestPayloadSchema = z3.object({
|
|
2369
|
+
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
2370
|
+
data: z3.object({
|
|
2371
|
+
id: z3.number().optional(),
|
|
2372
|
+
name: z3.string().optional(),
|
|
2373
|
+
createdBy: z3.number().optional(),
|
|
2374
|
+
dsl: z3.record(z3.any()).optional(),
|
|
2375
|
+
status: z3.string().optional(),
|
|
2376
|
+
deleted: z3.boolean().optional(),
|
|
2377
|
+
limit: z3.number().optional(),
|
|
2378
|
+
// Query operation fields
|
|
2379
|
+
filters: ArtifactsQueryFiltersSchema.optional(),
|
|
2380
|
+
sort: z3.enum(["ASC", "DESC"]).optional()
|
|
2381
|
+
}).optional()
|
|
2382
|
+
});
|
|
2383
|
+
var ArtifactsRequestMessageSchema = z3.object({
|
|
2384
|
+
id: z3.string(),
|
|
2385
|
+
from: MessageParticipantSchema,
|
|
2386
|
+
type: z3.literal("ARTIFACTS"),
|
|
2387
|
+
payload: ArtifactsRequestPayloadSchema
|
|
2388
|
+
});
|
|
2389
|
+
var KbNodeTypeSchema = z3.enum(["global", "user", "query"]);
|
|
2362
2390
|
var KbNodesQueryFiltersSchema = z3.object({
|
|
2363
2391
|
query: z3.string().optional(),
|
|
2364
2392
|
category: z3.string().optional(),
|
|
2365
2393
|
tags: z3.array(z3.string()).optional(),
|
|
2394
|
+
type: KbNodeTypeSchema.optional(),
|
|
2366
2395
|
createdBy: z3.number().optional()
|
|
2367
2396
|
});
|
|
2368
2397
|
var KbNodesRequestPayloadSchema = z3.object({
|
|
@@ -2373,6 +2402,7 @@ var KbNodesRequestPayloadSchema = z3.object({
|
|
|
2373
2402
|
content: z3.string().optional(),
|
|
2374
2403
|
category: z3.string().optional(),
|
|
2375
2404
|
tags: z3.array(z3.string()).optional(),
|
|
2405
|
+
type: KbNodeTypeSchema.optional(),
|
|
2376
2406
|
createdBy: z3.number().optional(),
|
|
2377
2407
|
updatedBy: z3.number().optional(),
|
|
2378
2408
|
userId: z3.number().optional(),
|
|
@@ -5386,7 +5416,7 @@ var getKnowledgeBase = async ({
|
|
|
5386
5416
|
topK
|
|
5387
5417
|
});
|
|
5388
5418
|
if (!result || !result.content) {
|
|
5389
|
-
logger.
|
|
5419
|
+
logger.info("[KnowledgeBase] No knowledge base results returned");
|
|
5390
5420
|
return "";
|
|
5391
5421
|
}
|
|
5392
5422
|
logger.info(`[KnowledgeBase] Retrieved knowledge base context (${result.content.length} chars)`);
|
|
@@ -5400,8 +5430,101 @@ var getKnowledgeBase = async ({
|
|
|
5400
5430
|
return "";
|
|
5401
5431
|
}
|
|
5402
5432
|
};
|
|
5433
|
+
var getGlobalKnowledgeBase = async ({
|
|
5434
|
+
collections,
|
|
5435
|
+
limit = 100
|
|
5436
|
+
}) => {
|
|
5437
|
+
try {
|
|
5438
|
+
if (!collections || !collections["knowledge-base"] || !collections["knowledge-base"]["getGlobal"]) {
|
|
5439
|
+
logger.info("[KnowledgeBase] knowledge-base.getGlobal collection not registered, skipping");
|
|
5440
|
+
return "";
|
|
5441
|
+
}
|
|
5442
|
+
logger.info("[KnowledgeBase] Fetching global knowledge base nodes...");
|
|
5443
|
+
const result = await collections["knowledge-base"]["getGlobal"]({ limit });
|
|
5444
|
+
if (!result || !result.content) {
|
|
5445
|
+
logger.info("[KnowledgeBase] No global knowledge base nodes found");
|
|
5446
|
+
return "";
|
|
5447
|
+
}
|
|
5448
|
+
logger.info(`[KnowledgeBase] Retrieved ${result.count || 0} global knowledge base nodes`);
|
|
5449
|
+
return result.content;
|
|
5450
|
+
} catch (error) {
|
|
5451
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5452
|
+
logger.warn(`[KnowledgeBase] Error fetching global knowledge base: ${errorMsg}`);
|
|
5453
|
+
return "";
|
|
5454
|
+
}
|
|
5455
|
+
};
|
|
5456
|
+
var getUserKnowledgeBase = async ({
|
|
5457
|
+
collections,
|
|
5458
|
+
userId,
|
|
5459
|
+
limit = 100
|
|
5460
|
+
}) => {
|
|
5461
|
+
try {
|
|
5462
|
+
if (!userId) {
|
|
5463
|
+
logger.info("[KnowledgeBase] No userId provided, skipping user knowledge base");
|
|
5464
|
+
return "";
|
|
5465
|
+
}
|
|
5466
|
+
if (!collections || !collections["knowledge-base"] || !collections["knowledge-base"]["getByUser"]) {
|
|
5467
|
+
logger.info("[KnowledgeBase] knowledge-base.getByUser collection not registered, skipping");
|
|
5468
|
+
return "";
|
|
5469
|
+
}
|
|
5470
|
+
logger.info(`[KnowledgeBase] Fetching user knowledge base nodes for userId: ${userId}...`);
|
|
5471
|
+
const result = await collections["knowledge-base"]["getByUser"]({
|
|
5472
|
+
userId: Number(userId),
|
|
5473
|
+
limit
|
|
5474
|
+
});
|
|
5475
|
+
if (!result || !result.content) {
|
|
5476
|
+
logger.info(`[KnowledgeBase] No user knowledge base nodes found for userId: ${userId}`);
|
|
5477
|
+
return "";
|
|
5478
|
+
}
|
|
5479
|
+
logger.info(`[KnowledgeBase] Retrieved ${result.count || 0} user knowledge base nodes for userId: ${userId}`);
|
|
5480
|
+
return result.content;
|
|
5481
|
+
} catch (error) {
|
|
5482
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5483
|
+
logger.warn(`[KnowledgeBase] Error fetching user knowledge base: ${errorMsg}`);
|
|
5484
|
+
return "";
|
|
5485
|
+
}
|
|
5486
|
+
};
|
|
5487
|
+
var getAllKnowledgeBase = async ({
|
|
5488
|
+
prompt,
|
|
5489
|
+
collections,
|
|
5490
|
+
userId,
|
|
5491
|
+
topK = 3
|
|
5492
|
+
}) => {
|
|
5493
|
+
logger.info("[KnowledgeBase] Fetching all knowledge base contexts...");
|
|
5494
|
+
const [globalContext, userContext, queryContext] = await Promise.all([
|
|
5495
|
+
getGlobalKnowledgeBase({ collections }),
|
|
5496
|
+
getUserKnowledgeBase({ collections, userId }),
|
|
5497
|
+
getKnowledgeBase({ prompt, collections, topK })
|
|
5498
|
+
]);
|
|
5499
|
+
let combinedContext = "";
|
|
5500
|
+
if (globalContext) {
|
|
5501
|
+
combinedContext += "## Global Knowledge Base\n";
|
|
5502
|
+
combinedContext += "The following information applies to all queries:\n\n";
|
|
5503
|
+
combinedContext += globalContext + "\n\n";
|
|
5504
|
+
}
|
|
5505
|
+
if (userContext) {
|
|
5506
|
+
combinedContext += "## User-Specific Knowledge Base\n";
|
|
5507
|
+
combinedContext += "The following information is specific to this user:\n\n";
|
|
5508
|
+
combinedContext += userContext + "\n\n";
|
|
5509
|
+
}
|
|
5510
|
+
if (queryContext) {
|
|
5511
|
+
combinedContext += "## Relevant Knowledge Base (Query-Matched)\n";
|
|
5512
|
+
combinedContext += "The following information is semantically relevant to the current query:\n\n";
|
|
5513
|
+
combinedContext += queryContext + "\n\n";
|
|
5514
|
+
}
|
|
5515
|
+
logger.info(`[KnowledgeBase] Combined knowledge base context: global=${globalContext.length} chars, user=${userContext.length} chars, query=${queryContext.length} chars`);
|
|
5516
|
+
return {
|
|
5517
|
+
globalContext,
|
|
5518
|
+
userContext,
|
|
5519
|
+
queryContext,
|
|
5520
|
+
combinedContext: combinedContext.trim()
|
|
5521
|
+
};
|
|
5522
|
+
};
|
|
5403
5523
|
var KB = {
|
|
5404
|
-
getKnowledgeBase
|
|
5524
|
+
getKnowledgeBase,
|
|
5525
|
+
getGlobalKnowledgeBase,
|
|
5526
|
+
getUserKnowledgeBase,
|
|
5527
|
+
getAllKnowledgeBase
|
|
5405
5528
|
};
|
|
5406
5529
|
var knowledge_base_default = KB;
|
|
5407
5530
|
|
|
@@ -5783,6 +5906,9 @@ var BaseLLM = class {
|
|
|
5783
5906
|
* @returns Object containing matched components, layout title/description, and follow-up actions
|
|
5784
5907
|
*/
|
|
5785
5908
|
async matchComponentsFromAnalysis(analysisContent, components, apiKey, logCollector, componentStreamCallback, deferredTools, executedTools) {
|
|
5909
|
+
const methodStartTime = Date.now();
|
|
5910
|
+
const methodName = "matchComponentsFromAnalysis";
|
|
5911
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")}`);
|
|
5786
5912
|
try {
|
|
5787
5913
|
logger.debug(`[${this.getProviderName()}] Starting component matching from text response`);
|
|
5788
5914
|
let availableComponentsText = "No components available";
|
|
@@ -6089,6 +6215,8 @@ ${executedToolsText}`);
|
|
|
6089
6215
|
}
|
|
6090
6216
|
};
|
|
6091
6217
|
}).filter(Boolean);
|
|
6218
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6219
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | components: ${finalComponents.length} | actions: ${actions.length}`);
|
|
6092
6220
|
return {
|
|
6093
6221
|
components: finalComponents,
|
|
6094
6222
|
layoutTitle,
|
|
@@ -6096,8 +6224,9 @@ ${executedToolsText}`);
|
|
|
6096
6224
|
actions
|
|
6097
6225
|
};
|
|
6098
6226
|
} catch (error) {
|
|
6227
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6099
6228
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6100
|
-
logger.error(`[${this.getProviderName()}]
|
|
6229
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6101
6230
|
logCollector?.error(`Failed to match components: ${errorMsg}`);
|
|
6102
6231
|
return {
|
|
6103
6232
|
components: [],
|
|
@@ -6112,6 +6241,10 @@ ${executedToolsText}`);
|
|
|
6112
6241
|
* Determines if question is for data analysis, requires external tools, or needs text response
|
|
6113
6242
|
*/
|
|
6114
6243
|
async classifyQuestionCategory(userPrompt, apiKey, logCollector, conversationHistory, externalTools) {
|
|
6244
|
+
const methodStartTime = Date.now();
|
|
6245
|
+
const methodName = "classifyQuestionCategory";
|
|
6246
|
+
const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
|
|
6247
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
|
|
6115
6248
|
try {
|
|
6116
6249
|
const schemaDoc = schema.generateSchemaDocumentation();
|
|
6117
6250
|
const availableToolsDoc = externalTools && externalTools.length > 0 ? externalTools.map((tool) => {
|
|
@@ -6155,6 +6288,8 @@ ${executedToolsText}`);
|
|
|
6155
6288
|
confidence: result.confidence
|
|
6156
6289
|
}
|
|
6157
6290
|
);
|
|
6291
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6292
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | category: ${result.category} | confidence: ${result.confidence}% | tools: ${(result.externalTools || []).length}`);
|
|
6158
6293
|
return {
|
|
6159
6294
|
category: result.category || "data_analysis",
|
|
6160
6295
|
externalTools: result.externalTools || [],
|
|
@@ -6163,8 +6298,9 @@ ${executedToolsText}`);
|
|
|
6163
6298
|
confidence: result.confidence || 0
|
|
6164
6299
|
};
|
|
6165
6300
|
} catch (error) {
|
|
6301
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6166
6302
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6167
|
-
logger.error(`[${this.getProviderName()}]
|
|
6303
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6168
6304
|
logger.debug(`[${this.getProviderName()}] Category classification error details:`, error);
|
|
6169
6305
|
throw error;
|
|
6170
6306
|
}
|
|
@@ -6175,9 +6311,15 @@ ${executedToolsText}`);
|
|
|
6175
6311
|
* Also adapts the cached text response to match the new question
|
|
6176
6312
|
*/
|
|
6177
6313
|
async adaptUIBlockParameters(currentUserPrompt, originalUserPrompt, matchedUIBlock, apiKey, logCollector, cachedTextResponse) {
|
|
6314
|
+
const methodStartTime = Date.now();
|
|
6315
|
+
const methodName = "adaptUIBlockParameters";
|
|
6316
|
+
const promptPreview = currentUserPrompt.substring(0, 50) + (currentUserPrompt.length > 50 ? "..." : "");
|
|
6317
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | prompt: "${promptPreview}"`);
|
|
6178
6318
|
try {
|
|
6179
6319
|
const component = matchedUIBlock?.generatedComponentMetadata || matchedUIBlock?.component;
|
|
6180
6320
|
if (!matchedUIBlock || !component) {
|
|
6321
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6322
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: no component found`);
|
|
6181
6323
|
return {
|
|
6182
6324
|
success: false,
|
|
6183
6325
|
explanation: "No component found in matched UI block"
|
|
@@ -6210,9 +6352,8 @@ ${executedToolsText}`);
|
|
|
6210
6352
|
// Parse as JSON
|
|
6211
6353
|
);
|
|
6212
6354
|
if (!result.success) {
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
);
|
|
6355
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6356
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: adaptation failed - ${result.reason}`);
|
|
6216
6357
|
logCollector?.warn(
|
|
6217
6358
|
"Could not adapt matched UI block",
|
|
6218
6359
|
"explanation",
|
|
@@ -6237,6 +6378,8 @@ ${executedToolsText}`);
|
|
|
6237
6378
|
componentType: result.adaptedComponent?.type
|
|
6238
6379
|
}
|
|
6239
6380
|
);
|
|
6381
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6382
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | changes: ${(result.parametersChanged || []).length}`);
|
|
6240
6383
|
return {
|
|
6241
6384
|
success: true,
|
|
6242
6385
|
adaptedComponent: result.adaptedComponent,
|
|
@@ -6245,8 +6388,9 @@ ${executedToolsText}`);
|
|
|
6245
6388
|
explanation: result.explanation || "Parameters adapted successfully"
|
|
6246
6389
|
};
|
|
6247
6390
|
} catch (error) {
|
|
6391
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6248
6392
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6249
|
-
logger.error(`[${this.getProviderName()}]
|
|
6393
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6250
6394
|
logger.debug(`[${this.getProviderName()}] Adaptation error details:`, error);
|
|
6251
6395
|
return {
|
|
6252
6396
|
success: false,
|
|
@@ -6264,8 +6408,13 @@ ${executedToolsText}`);
|
|
|
6264
6408
|
* @param components - Optional list of available components for matching suggestions
|
|
6265
6409
|
* @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called
|
|
6266
6410
|
* @param category - Question category ('data_analysis' | 'data_modification' | 'general'). For data_modification, answer component streaming is skipped. For general, component generation is skipped entirely.
|
|
6411
|
+
* @param userId - Optional user ID for fetching user-specific knowledge base nodes
|
|
6267
6412
|
*/
|
|
6268
|
-
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category) {
|
|
6413
|
+
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category, userId) {
|
|
6414
|
+
const methodStartTime = Date.now();
|
|
6415
|
+
const methodName = "generateTextResponse";
|
|
6416
|
+
const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
|
|
6417
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | category: ${category} | prompt: "${promptPreview}"`);
|
|
6269
6418
|
const errors = [];
|
|
6270
6419
|
logger.debug(`[${this.getProviderName()}] Starting text response generation`);
|
|
6271
6420
|
logger.debug(`[${this.getProviderName()}] User prompt: "${userPrompt.substring(0, 50)}..."`);
|
|
@@ -6314,11 +6463,13 @@ ${executedToolsText}`);
|
|
|
6314
6463
|
}
|
|
6315
6464
|
const schemaDoc = schema.generateSchemaDocumentation();
|
|
6316
6465
|
const databaseRules = await promptLoader.loadDatabaseRules();
|
|
6317
|
-
const
|
|
6466
|
+
const kbResult = await knowledge_base_default.getAllKnowledgeBase({
|
|
6318
6467
|
prompt: userPrompt,
|
|
6319
6468
|
collections,
|
|
6320
|
-
|
|
6469
|
+
userId,
|
|
6470
|
+
topK: 3
|
|
6321
6471
|
});
|
|
6472
|
+
const knowledgeBaseContext = kbResult.combinedContext;
|
|
6322
6473
|
const prompts = await promptLoader.loadPrompts("text-response", {
|
|
6323
6474
|
USER_PROMPT: userPrompt,
|
|
6324
6475
|
CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
|
|
@@ -6444,26 +6595,48 @@ ${executedToolsText}`);
|
|
|
6444
6595
|
const executedToolsList = [];
|
|
6445
6596
|
let maxAttemptsReached = false;
|
|
6446
6597
|
let fullStreamedText = "";
|
|
6598
|
+
let streamBuffer = "";
|
|
6599
|
+
let flushTimer = null;
|
|
6600
|
+
const FLUSH_INTERVAL = 50;
|
|
6601
|
+
const flushStreamBuffer = () => {
|
|
6602
|
+
if (streamBuffer && streamCallback) {
|
|
6603
|
+
streamCallback(streamBuffer);
|
|
6604
|
+
streamBuffer = "";
|
|
6605
|
+
}
|
|
6606
|
+
flushTimer = null;
|
|
6607
|
+
};
|
|
6447
6608
|
const wrappedStreamCallback = streamCallback ? (chunk) => {
|
|
6448
6609
|
fullStreamedText += chunk;
|
|
6449
|
-
|
|
6610
|
+
streamBuffer += chunk;
|
|
6611
|
+
if (chunk.includes("\n") || chunk.length > 100) {
|
|
6612
|
+
if (flushTimer) {
|
|
6613
|
+
clearTimeout(flushTimer);
|
|
6614
|
+
flushTimer = null;
|
|
6615
|
+
}
|
|
6616
|
+
flushStreamBuffer();
|
|
6617
|
+
} else if (!flushTimer) {
|
|
6618
|
+
flushTimer = setTimeout(flushStreamBuffer, FLUSH_INTERVAL);
|
|
6619
|
+
}
|
|
6450
6620
|
} : void 0;
|
|
6621
|
+
const flushStream = () => {
|
|
6622
|
+
if (flushTimer) {
|
|
6623
|
+
clearTimeout(flushTimer);
|
|
6624
|
+
flushTimer = null;
|
|
6625
|
+
}
|
|
6626
|
+
flushStreamBuffer();
|
|
6627
|
+
};
|
|
6628
|
+
const streamDelay = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6451
6629
|
const withProgressHeartbeat = async (operation, progressMessage, intervalMs = 1e3) => {
|
|
6452
6630
|
if (!wrappedStreamCallback) {
|
|
6453
6631
|
return operation();
|
|
6454
6632
|
}
|
|
6455
6633
|
const startTime = Date.now();
|
|
6456
|
-
|
|
6457
|
-
const maxDots = 3;
|
|
6634
|
+
await streamDelay(30);
|
|
6458
6635
|
wrappedStreamCallback(`\u23F3 ${progressMessage}`);
|
|
6459
6636
|
const heartbeatInterval = setInterval(() => {
|
|
6460
6637
|
const elapsedSeconds = Math.floor((Date.now() - startTime) / 1e3);
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
if (elapsedSeconds >= 2) {
|
|
6464
|
-
wrappedStreamCallback(`${dots} (${elapsedSeconds}s)`);
|
|
6465
|
-
} else {
|
|
6466
|
-
wrappedStreamCallback(dots);
|
|
6638
|
+
if (elapsedSeconds >= 1) {
|
|
6639
|
+
wrappedStreamCallback(` (${elapsedSeconds}s)`);
|
|
6467
6640
|
}
|
|
6468
6641
|
}, intervalMs);
|
|
6469
6642
|
try {
|
|
@@ -6508,6 +6681,7 @@ Please try rephrasing your question or simplifying your request.
|
|
|
6508
6681
|
throw new Error(errorMsg);
|
|
6509
6682
|
}
|
|
6510
6683
|
try {
|
|
6684
|
+
flushStream();
|
|
6511
6685
|
if (wrappedStreamCallback) {
|
|
6512
6686
|
const paramsDisplay = Object.keys(params).length > 0 ? `
|
|
6513
6687
|
**Parameters:** ${JSON.stringify(params)}` : "";
|
|
@@ -6517,10 +6691,12 @@ Please try rephrasing your question or simplifying your request.
|
|
|
6517
6691
|
\u{1F50D} **Analyzing your question...**
|
|
6518
6692
|
|
|
6519
6693
|
`);
|
|
6694
|
+
await streamDelay(50);
|
|
6520
6695
|
if (reasoning) {
|
|
6521
6696
|
wrappedStreamCallback(`\u{1F4AD} ${reasoning}
|
|
6522
6697
|
|
|
6523
6698
|
`);
|
|
6699
|
+
await streamDelay(50);
|
|
6524
6700
|
}
|
|
6525
6701
|
wrappedStreamCallback(`\u{1F4DD} **Generated SQL Query:**
|
|
6526
6702
|
\`\`\`sql
|
|
@@ -6528,16 +6704,19 @@ ${sql}
|
|
|
6528
6704
|
\`\`\`${paramsDisplay}
|
|
6529
6705
|
|
|
6530
6706
|
`);
|
|
6707
|
+
await streamDelay(50);
|
|
6531
6708
|
} else {
|
|
6532
6709
|
wrappedStreamCallback(`
|
|
6533
6710
|
|
|
6534
6711
|
\u{1F504} **Retrying with corrected query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS})...**
|
|
6535
6712
|
|
|
6536
6713
|
`);
|
|
6714
|
+
await streamDelay(50);
|
|
6537
6715
|
if (reasoning) {
|
|
6538
6716
|
wrappedStreamCallback(`\u{1F4AD} ${reasoning}
|
|
6539
6717
|
|
|
6540
6718
|
`);
|
|
6719
|
+
await streamDelay(50);
|
|
6541
6720
|
}
|
|
6542
6721
|
wrappedStreamCallback(`\u{1F4DD} **Corrected SQL Query:**
|
|
6543
6722
|
\`\`\`sql
|
|
@@ -6545,6 +6724,7 @@ ${sql}
|
|
|
6545
6724
|
\`\`\`${paramsDisplay}
|
|
6546
6725
|
|
|
6547
6726
|
`);
|
|
6727
|
+
await streamDelay(50);
|
|
6548
6728
|
}
|
|
6549
6729
|
}
|
|
6550
6730
|
logCollector?.logQuery(
|
|
@@ -6571,6 +6751,7 @@ ${sql}
|
|
|
6571
6751
|
\u2705 **Query executed successfully!**
|
|
6572
6752
|
|
|
6573
6753
|
`);
|
|
6754
|
+
await streamDelay(50);
|
|
6574
6755
|
if (Array.isArray(data) && data.length > 0) {
|
|
6575
6756
|
const firstRow = data[0];
|
|
6576
6757
|
const columns = Object.keys(firstRow);
|
|
@@ -6579,18 +6760,22 @@ ${sql}
|
|
|
6579
6760
|
wrappedStreamCallback(`**Result:** ${value}
|
|
6580
6761
|
|
|
6581
6762
|
`);
|
|
6763
|
+
await streamDelay(50);
|
|
6582
6764
|
} else if (data.length > 0) {
|
|
6583
6765
|
wrappedStreamCallback(`**Retrieved ${rowCount} rows**
|
|
6584
6766
|
|
|
6585
6767
|
`);
|
|
6768
|
+
await streamDelay(50);
|
|
6586
6769
|
wrappedStreamCallback(`<DataTable>${JSON.stringify(data)}</DataTable>
|
|
6587
6770
|
|
|
6588
6771
|
`);
|
|
6772
|
+
await streamDelay(50);
|
|
6589
6773
|
}
|
|
6590
6774
|
} else if (Array.isArray(data) && data.length === 0) {
|
|
6591
6775
|
wrappedStreamCallback(`**No rows returned.**
|
|
6592
6776
|
|
|
6593
6777
|
`);
|
|
6778
|
+
await streamDelay(50);
|
|
6594
6779
|
}
|
|
6595
6780
|
wrappedStreamCallback(`\u{1F4CA} **Analyzing results...**
|
|
6596
6781
|
|
|
@@ -6640,6 +6825,7 @@ Please try rephrasing your request or contact support.
|
|
|
6640
6825
|
throw new Error(errorMsg);
|
|
6641
6826
|
}
|
|
6642
6827
|
try {
|
|
6828
|
+
flushStream();
|
|
6643
6829
|
if (wrappedStreamCallback) {
|
|
6644
6830
|
if (attempts === 1) {
|
|
6645
6831
|
wrappedStreamCallback(`
|
|
@@ -6654,6 +6840,7 @@ Please try rephrasing your request or contact support.
|
|
|
6654
6840
|
|
|
6655
6841
|
`);
|
|
6656
6842
|
}
|
|
6843
|
+
await streamDelay(50);
|
|
6657
6844
|
}
|
|
6658
6845
|
const result2 = await withProgressHeartbeat(
|
|
6659
6846
|
() => externalTool.fn(toolInput),
|
|
@@ -6693,6 +6880,7 @@ Please try rephrasing your request or contact support.
|
|
|
6693
6880
|
wrappedStreamCallback(`\u2705 **${externalTool.name} completed successfully**
|
|
6694
6881
|
|
|
6695
6882
|
`);
|
|
6883
|
+
await streamDelay(50);
|
|
6696
6884
|
}
|
|
6697
6885
|
return JSON.stringify(result2, null, 2);
|
|
6698
6886
|
} catch (error) {
|
|
@@ -6740,7 +6928,8 @@ ${errorMsg}
|
|
|
6740
6928
|
logger.info(`[${this.getProviderName()}] Text response stream completed`);
|
|
6741
6929
|
const textResponse = fullStreamedText || result || "I apologize, but I was unable to generate a response.";
|
|
6742
6930
|
if (maxAttemptsReached) {
|
|
6743
|
-
|
|
6931
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6932
|
+
logger.warn(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: max attempts reached`);
|
|
6744
6933
|
logCollector?.error("Failed to generate valid query after maximum attempts");
|
|
6745
6934
|
return {
|
|
6746
6935
|
success: false,
|
|
@@ -6761,6 +6950,7 @@ ${errorMsg}
|
|
|
6761
6950
|
textLength: textResponse.length
|
|
6762
6951
|
}
|
|
6763
6952
|
);
|
|
6953
|
+
flushStream();
|
|
6764
6954
|
if (wrappedStreamCallback && components && components.length > 0 && category !== "general") {
|
|
6765
6955
|
wrappedStreamCallback("\n\n\u{1F4CA} **Generating visualization components...**\n\n");
|
|
6766
6956
|
wrappedStreamCallback("__TEXT_COMPLETE__COMPONENT_GENERATION_START__");
|
|
@@ -6842,6 +7032,8 @@ ${errorMsg}
|
|
|
6842
7032
|
}
|
|
6843
7033
|
};
|
|
6844
7034
|
}
|
|
7035
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7036
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | components: ${matchedComponents.length} | actions: ${actions.length}`);
|
|
6845
7037
|
return {
|
|
6846
7038
|
success: true,
|
|
6847
7039
|
data: {
|
|
@@ -6853,8 +7045,9 @@ ${errorMsg}
|
|
|
6853
7045
|
errors: []
|
|
6854
7046
|
};
|
|
6855
7047
|
} catch (error) {
|
|
7048
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6856
7049
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6857
|
-
logger.error(`[${this.getProviderName()}]
|
|
7050
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6858
7051
|
logCollector?.error(`Error generating text response: ${errorMsg}`);
|
|
6859
7052
|
userPromptErrorLogger.logLlmError(
|
|
6860
7053
|
this.getProviderName(),
|
|
@@ -7072,7 +7265,8 @@ ${errorMsg}
|
|
|
7072
7265
|
collections,
|
|
7073
7266
|
components,
|
|
7074
7267
|
toolsToUse,
|
|
7075
|
-
categoryClassification.category
|
|
7268
|
+
categoryClassification.category,
|
|
7269
|
+
userId
|
|
7076
7270
|
);
|
|
7077
7271
|
const elapsedTime = Date.now() - startTime;
|
|
7078
7272
|
logger.info(`[${this.getProviderName()}] Total time taken: ${elapsedTime}ms (${(elapsedTime / 1e3).toFixed(2)}s)`);
|
|
@@ -7107,6 +7301,10 @@ ${errorMsg}
|
|
|
7107
7301
|
* For general/conversational questions without components, pass textResponse instead
|
|
7108
7302
|
*/
|
|
7109
7303
|
async generateNextQuestions(originalUserPrompt, component, componentData, apiKey, logCollector, conversationHistory, textResponse) {
|
|
7304
|
+
const methodStartTime = Date.now();
|
|
7305
|
+
const methodName = "generateNextQuestions";
|
|
7306
|
+
const promptPreview = originalUserPrompt.substring(0, 50) + (originalUserPrompt.length > 50 ? "..." : "");
|
|
7307
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
|
|
7110
7308
|
try {
|
|
7111
7309
|
let component_info;
|
|
7112
7310
|
if (component) {
|
|
@@ -7155,10 +7353,13 @@ ${errorMsg}
|
|
|
7155
7353
|
questions: nextQuestions
|
|
7156
7354
|
}
|
|
7157
7355
|
);
|
|
7356
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7357
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | questions: ${nextQuestions.length}`);
|
|
7158
7358
|
return nextQuestions;
|
|
7159
7359
|
} catch (error) {
|
|
7360
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7160
7361
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
7161
|
-
logger.error(`[${this.getProviderName()}]
|
|
7362
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
7162
7363
|
logger.debug(`[${this.getProviderName()}] Next questions generation error details:`, error);
|
|
7163
7364
|
logCollector?.error(`Error generating next questions: ${errorMsg}`);
|
|
7164
7365
|
return [];
|
|
@@ -10145,6 +10346,208 @@ function sendResponse7(id, res, sendMessage, clientId) {
|
|
|
10145
10346
|
sendMessage(response);
|
|
10146
10347
|
}
|
|
10147
10348
|
|
|
10349
|
+
// src/handlers/artifacts.ts
|
|
10350
|
+
init_logger();
|
|
10351
|
+
async function handleArtifactsRequest(data, collections, sendMessage) {
|
|
10352
|
+
const executeCollection = async (collection, op, params) => {
|
|
10353
|
+
const handler = collections[collection]?.[op];
|
|
10354
|
+
if (!handler) {
|
|
10355
|
+
throw new Error(`Collection operation ${collection}.${op} not found`);
|
|
10356
|
+
}
|
|
10357
|
+
return await handler(params);
|
|
10358
|
+
};
|
|
10359
|
+
try {
|
|
10360
|
+
const request = ArtifactsRequestMessageSchema.parse(data);
|
|
10361
|
+
const { id, payload, from } = request;
|
|
10362
|
+
const { operation, data: requestData } = payload;
|
|
10363
|
+
const artifactId = requestData?.id;
|
|
10364
|
+
const name = requestData?.name;
|
|
10365
|
+
const createdBy = requestData?.createdBy;
|
|
10366
|
+
const dsl = requestData?.dsl;
|
|
10367
|
+
const status = requestData?.status;
|
|
10368
|
+
const deleted = requestData?.deleted;
|
|
10369
|
+
const limit = requestData?.limit;
|
|
10370
|
+
const filters = requestData?.filters;
|
|
10371
|
+
const sort = requestData?.sort;
|
|
10372
|
+
switch (operation) {
|
|
10373
|
+
case "create":
|
|
10374
|
+
await handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, from.id);
|
|
10375
|
+
break;
|
|
10376
|
+
case "update":
|
|
10377
|
+
await handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, from.id);
|
|
10378
|
+
break;
|
|
10379
|
+
case "delete":
|
|
10380
|
+
await handleDelete6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10381
|
+
break;
|
|
10382
|
+
case "getAll":
|
|
10383
|
+
await handleGetAll6(id, limit, executeCollection, sendMessage, from.id);
|
|
10384
|
+
break;
|
|
10385
|
+
case "getOne":
|
|
10386
|
+
await handleGetOne6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10387
|
+
break;
|
|
10388
|
+
case "query":
|
|
10389
|
+
await handleQuery6(id, { filters, limit, sort }, executeCollection, sendMessage, from.id);
|
|
10390
|
+
break;
|
|
10391
|
+
default:
|
|
10392
|
+
sendResponse8(id, {
|
|
10393
|
+
success: false,
|
|
10394
|
+
error: `Unknown operation: ${operation}`
|
|
10395
|
+
}, sendMessage, from.id);
|
|
10396
|
+
}
|
|
10397
|
+
} catch (error) {
|
|
10398
|
+
logger.error("Failed to handle artifacts request:", error);
|
|
10399
|
+
sendResponse8(null, {
|
|
10400
|
+
success: false,
|
|
10401
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10402
|
+
}, sendMessage);
|
|
10403
|
+
}
|
|
10404
|
+
}
|
|
10405
|
+
async function handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, clientId) {
|
|
10406
|
+
if (!name) {
|
|
10407
|
+
sendResponse8(id, {
|
|
10408
|
+
success: false,
|
|
10409
|
+
error: "name is required"
|
|
10410
|
+
}, sendMessage, clientId);
|
|
10411
|
+
return;
|
|
10412
|
+
}
|
|
10413
|
+
try {
|
|
10414
|
+
const result = await executeCollection("artifacts", "create", { name, createdBy, dsl, status });
|
|
10415
|
+
sendResponse8(id, {
|
|
10416
|
+
success: true,
|
|
10417
|
+
data: result.data,
|
|
10418
|
+
message: "Artifact created successfully"
|
|
10419
|
+
}, sendMessage, clientId);
|
|
10420
|
+
logger.info(`Artifact created: ID ${result.data.id}`);
|
|
10421
|
+
} catch (error) {
|
|
10422
|
+
sendResponse8(id, {
|
|
10423
|
+
success: false,
|
|
10424
|
+
error: error instanceof Error ? error.message : "Failed to create artifact"
|
|
10425
|
+
}, sendMessage, clientId);
|
|
10426
|
+
}
|
|
10427
|
+
}
|
|
10428
|
+
async function handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, clientId) {
|
|
10429
|
+
if (!artifactId) {
|
|
10430
|
+
sendResponse8(id, {
|
|
10431
|
+
success: false,
|
|
10432
|
+
error: "Artifact ID is required"
|
|
10433
|
+
}, sendMessage, clientId);
|
|
10434
|
+
return;
|
|
10435
|
+
}
|
|
10436
|
+
try {
|
|
10437
|
+
const result = await executeCollection("artifacts", "update", { id: artifactId, name, dsl, status, deleted });
|
|
10438
|
+
sendResponse8(id, {
|
|
10439
|
+
success: true,
|
|
10440
|
+
data: result.data,
|
|
10441
|
+
message: "Artifact updated successfully"
|
|
10442
|
+
}, sendMessage, clientId);
|
|
10443
|
+
logger.info(`Artifact updated: ID ${artifactId}`);
|
|
10444
|
+
} catch (error) {
|
|
10445
|
+
sendResponse8(id, {
|
|
10446
|
+
success: false,
|
|
10447
|
+
error: error instanceof Error ? error.message : "Failed to update artifact"
|
|
10448
|
+
}, sendMessage, clientId);
|
|
10449
|
+
}
|
|
10450
|
+
}
|
|
10451
|
+
async function handleDelete6(id, artifactId, executeCollection, sendMessage, clientId) {
|
|
10452
|
+
if (!artifactId) {
|
|
10453
|
+
sendResponse8(id, {
|
|
10454
|
+
success: false,
|
|
10455
|
+
error: "Artifact ID is required"
|
|
10456
|
+
}, sendMessage, clientId);
|
|
10457
|
+
return;
|
|
10458
|
+
}
|
|
10459
|
+
try {
|
|
10460
|
+
const result = await executeCollection("artifacts", "delete", { id: artifactId });
|
|
10461
|
+
sendResponse8(id, {
|
|
10462
|
+
success: true,
|
|
10463
|
+
data: result.data,
|
|
10464
|
+
message: "Artifact deleted successfully"
|
|
10465
|
+
}, sendMessage, clientId);
|
|
10466
|
+
logger.info(`Artifact deleted: ID ${artifactId}`);
|
|
10467
|
+
} catch (error) {
|
|
10468
|
+
sendResponse8(id, {
|
|
10469
|
+
success: false,
|
|
10470
|
+
error: error instanceof Error ? error.message : "Failed to delete artifact"
|
|
10471
|
+
}, sendMessage, clientId);
|
|
10472
|
+
}
|
|
10473
|
+
}
|
|
10474
|
+
async function handleGetAll6(id, limit, executeCollection, sendMessage, clientId) {
|
|
10475
|
+
try {
|
|
10476
|
+
const result = await executeCollection("artifacts", "getAll", { limit });
|
|
10477
|
+
sendResponse8(id, {
|
|
10478
|
+
success: true,
|
|
10479
|
+
data: result.data,
|
|
10480
|
+
count: result.count,
|
|
10481
|
+
message: `Retrieved ${result.count} artifacts`
|
|
10482
|
+
}, sendMessage, clientId);
|
|
10483
|
+
logger.info(`Retrieved all artifacts (count: ${result.count})`);
|
|
10484
|
+
} catch (error) {
|
|
10485
|
+
sendResponse8(id, {
|
|
10486
|
+
success: false,
|
|
10487
|
+
error: error instanceof Error ? error.message : "Failed to get artifacts"
|
|
10488
|
+
}, sendMessage, clientId);
|
|
10489
|
+
}
|
|
10490
|
+
}
|
|
10491
|
+
async function handleGetOne6(id, artifactId, executeCollection, sendMessage, clientId) {
|
|
10492
|
+
if (!artifactId) {
|
|
10493
|
+
sendResponse8(id, {
|
|
10494
|
+
success: false,
|
|
10495
|
+
error: "Artifact ID is required"
|
|
10496
|
+
}, sendMessage, clientId);
|
|
10497
|
+
return;
|
|
10498
|
+
}
|
|
10499
|
+
try {
|
|
10500
|
+
const result = await executeCollection("artifacts", "getOne", { id: artifactId });
|
|
10501
|
+
sendResponse8(id, {
|
|
10502
|
+
success: true,
|
|
10503
|
+
data: result.data,
|
|
10504
|
+
message: `Retrieved artifact ID ${artifactId}`
|
|
10505
|
+
}, sendMessage, clientId);
|
|
10506
|
+
logger.info(`Retrieved artifact: ID ${artifactId}`);
|
|
10507
|
+
} catch (error) {
|
|
10508
|
+
sendResponse8(id, {
|
|
10509
|
+
success: false,
|
|
10510
|
+
error: error instanceof Error ? error.message : "Failed to get artifact"
|
|
10511
|
+
}, sendMessage, clientId);
|
|
10512
|
+
}
|
|
10513
|
+
}
|
|
10514
|
+
async function handleQuery6(id, queryParams, executeCollection, sendMessage, clientId) {
|
|
10515
|
+
try {
|
|
10516
|
+
const result = await executeCollection("artifacts", "query", {
|
|
10517
|
+
filters: queryParams.filters,
|
|
10518
|
+
limit: queryParams.limit || 50,
|
|
10519
|
+
sort: queryParams.sort || "DESC"
|
|
10520
|
+
});
|
|
10521
|
+
sendResponse8(id, {
|
|
10522
|
+
success: true,
|
|
10523
|
+
data: result.data,
|
|
10524
|
+
count: result.count,
|
|
10525
|
+
message: `Query returned ${result.count} artifacts`
|
|
10526
|
+
}, sendMessage, clientId);
|
|
10527
|
+
logger.info(`Query artifacts (count: ${result.count})`);
|
|
10528
|
+
} catch (error) {
|
|
10529
|
+
sendResponse8(id, {
|
|
10530
|
+
success: false,
|
|
10531
|
+
error: error instanceof Error ? error.message : "Failed to query artifacts"
|
|
10532
|
+
}, sendMessage, clientId);
|
|
10533
|
+
}
|
|
10534
|
+
}
|
|
10535
|
+
function sendResponse8(id, res, sendMessage, clientId) {
|
|
10536
|
+
const response = {
|
|
10537
|
+
id: id || "unknown",
|
|
10538
|
+
type: "ARTIFACTS_RES",
|
|
10539
|
+
from: { type: "data-agent" },
|
|
10540
|
+
to: {
|
|
10541
|
+
type: "user",
|
|
10542
|
+
id: clientId
|
|
10543
|
+
},
|
|
10544
|
+
payload: {
|
|
10545
|
+
...res
|
|
10546
|
+
}
|
|
10547
|
+
};
|
|
10548
|
+
sendMessage(response);
|
|
10549
|
+
}
|
|
10550
|
+
|
|
10148
10551
|
// src/handlers/kb-nodes.ts
|
|
10149
10552
|
init_logger();
|
|
10150
10553
|
async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
@@ -10164,6 +10567,7 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10164
10567
|
const content = requestData?.content;
|
|
10165
10568
|
const category = requestData?.category;
|
|
10166
10569
|
const tags = requestData?.tags;
|
|
10570
|
+
const type = requestData?.type;
|
|
10167
10571
|
const createdBy = requestData?.createdBy;
|
|
10168
10572
|
const updatedBy = requestData?.updatedBy;
|
|
10169
10573
|
const userId = requestData?.userId;
|
|
@@ -10173,22 +10577,22 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10173
10577
|
const offset = requestData?.offset;
|
|
10174
10578
|
switch (operation) {
|
|
10175
10579
|
case "create":
|
|
10176
|
-
await
|
|
10580
|
+
await handleCreate7(id, { title, content, category, tags, type, createdBy }, executeCollection, sendMessage, from.id);
|
|
10177
10581
|
break;
|
|
10178
10582
|
case "update":
|
|
10179
|
-
await
|
|
10583
|
+
await handleUpdate7(id, nodeId, { title, content, category, tags, type, updatedBy }, executeCollection, sendMessage, from.id);
|
|
10180
10584
|
break;
|
|
10181
10585
|
case "delete":
|
|
10182
|
-
await
|
|
10586
|
+
await handleDelete7(id, nodeId, executeCollection, sendMessage, from.id);
|
|
10183
10587
|
break;
|
|
10184
10588
|
case "getAll":
|
|
10185
|
-
await
|
|
10589
|
+
await handleGetAll7(id, limit, offset, executeCollection, sendMessage, from.id);
|
|
10186
10590
|
break;
|
|
10187
10591
|
case "getOne":
|
|
10188
|
-
await
|
|
10592
|
+
await handleGetOne7(id, nodeId, executeCollection, sendMessage, from.id);
|
|
10189
10593
|
break;
|
|
10190
10594
|
case "search":
|
|
10191
|
-
await handleSearch(id, { query, category, tags, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
10595
|
+
await handleSearch(id, { query, category, tags, type, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
10192
10596
|
break;
|
|
10193
10597
|
case "getByCategory":
|
|
10194
10598
|
await handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, from.id);
|
|
@@ -10203,37 +10607,37 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10203
10607
|
await handleGetTags(id, executeCollection, sendMessage, from.id);
|
|
10204
10608
|
break;
|
|
10205
10609
|
default:
|
|
10206
|
-
|
|
10610
|
+
sendResponse9(id, {
|
|
10207
10611
|
success: false,
|
|
10208
10612
|
error: `Unknown operation: ${operation}`
|
|
10209
10613
|
}, sendMessage, from.id);
|
|
10210
10614
|
}
|
|
10211
10615
|
} catch (error) {
|
|
10212
10616
|
logger.error("Failed to handle KB nodes request:", error);
|
|
10213
|
-
|
|
10617
|
+
sendResponse9(null, {
|
|
10214
10618
|
success: false,
|
|
10215
10619
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10216
10620
|
}, sendMessage);
|
|
10217
10621
|
}
|
|
10218
10622
|
}
|
|
10219
|
-
async function
|
|
10220
|
-
const { title, content, category, tags, createdBy } = nodeData;
|
|
10623
|
+
async function handleCreate7(id, nodeData, executeCollection, sendMessage, clientId) {
|
|
10624
|
+
const { title, content, category, tags, type, createdBy } = nodeData;
|
|
10221
10625
|
if (!title || title.trim().length === 0) {
|
|
10222
|
-
|
|
10626
|
+
sendResponse9(id, {
|
|
10223
10627
|
success: false,
|
|
10224
10628
|
error: "Title is required and cannot be empty"
|
|
10225
10629
|
}, sendMessage, clientId);
|
|
10226
10630
|
return;
|
|
10227
10631
|
}
|
|
10228
10632
|
if (!content || content.trim().length === 0) {
|
|
10229
|
-
|
|
10633
|
+
sendResponse9(id, {
|
|
10230
10634
|
success: false,
|
|
10231
10635
|
error: "Content is required and cannot be empty"
|
|
10232
10636
|
}, sendMessage, clientId);
|
|
10233
10637
|
return;
|
|
10234
10638
|
}
|
|
10235
10639
|
if (!createdBy) {
|
|
10236
|
-
|
|
10640
|
+
sendResponse9(id, {
|
|
10237
10641
|
success: false,
|
|
10238
10642
|
error: "createdBy (user ID) is required"
|
|
10239
10643
|
}, sendMessage, clientId);
|
|
@@ -10245,11 +10649,12 @@ async function handleCreate6(id, nodeData, executeCollection, sendMessage, clien
|
|
|
10245
10649
|
content,
|
|
10246
10650
|
category: category || void 0,
|
|
10247
10651
|
tags: tags || void 0,
|
|
10652
|
+
type: type || "query",
|
|
10248
10653
|
createdBy
|
|
10249
10654
|
});
|
|
10250
10655
|
if (result && result.success) {
|
|
10251
10656
|
logger.info(`[DB] KB node created successfully: ${title}`);
|
|
10252
|
-
|
|
10657
|
+
sendResponse9(id, {
|
|
10253
10658
|
success: true,
|
|
10254
10659
|
data: {
|
|
10255
10660
|
...result.data,
|
|
@@ -10258,29 +10663,29 @@ async function handleCreate6(id, nodeData, executeCollection, sendMessage, clien
|
|
|
10258
10663
|
}, sendMessage, clientId);
|
|
10259
10664
|
return;
|
|
10260
10665
|
}
|
|
10261
|
-
|
|
10666
|
+
sendResponse9(id, {
|
|
10262
10667
|
success: false,
|
|
10263
10668
|
error: "Failed to create knowledge node"
|
|
10264
10669
|
}, sendMessage, clientId);
|
|
10265
10670
|
} catch (error) {
|
|
10266
10671
|
logger.error("[DB] Failed to create KB node:", error);
|
|
10267
|
-
|
|
10672
|
+
sendResponse9(id, {
|
|
10268
10673
|
success: false,
|
|
10269
10674
|
error: error instanceof Error ? error.message : "Failed to create knowledge node"
|
|
10270
10675
|
}, sendMessage, clientId);
|
|
10271
10676
|
}
|
|
10272
10677
|
}
|
|
10273
|
-
async function
|
|
10274
|
-
const { title, content, category, tags, updatedBy } = nodeData;
|
|
10678
|
+
async function handleUpdate7(id, nodeId, nodeData, executeCollection, sendMessage, clientId) {
|
|
10679
|
+
const { title, content, category, tags, type, updatedBy } = nodeData;
|
|
10275
10680
|
if (!nodeId) {
|
|
10276
|
-
|
|
10681
|
+
sendResponse9(id, {
|
|
10277
10682
|
success: false,
|
|
10278
10683
|
error: "Knowledge node ID is required"
|
|
10279
10684
|
}, sendMessage, clientId);
|
|
10280
10685
|
return;
|
|
10281
10686
|
}
|
|
10282
10687
|
if (!updatedBy) {
|
|
10283
|
-
|
|
10688
|
+
sendResponse9(id, {
|
|
10284
10689
|
success: false,
|
|
10285
10690
|
error: "updatedBy (user ID) is required"
|
|
10286
10691
|
}, sendMessage, clientId);
|
|
@@ -10293,11 +10698,12 @@ async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessag
|
|
|
10293
10698
|
content,
|
|
10294
10699
|
category,
|
|
10295
10700
|
tags,
|
|
10701
|
+
type,
|
|
10296
10702
|
updatedBy
|
|
10297
10703
|
});
|
|
10298
10704
|
if (result && result.success) {
|
|
10299
10705
|
logger.info(`[DB] KB node updated successfully, ID: ${nodeId}`);
|
|
10300
|
-
|
|
10706
|
+
sendResponse9(id, {
|
|
10301
10707
|
success: true,
|
|
10302
10708
|
data: {
|
|
10303
10709
|
...result.data,
|
|
@@ -10306,21 +10712,21 @@ async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessag
|
|
|
10306
10712
|
}, sendMessage, clientId);
|
|
10307
10713
|
return;
|
|
10308
10714
|
}
|
|
10309
|
-
|
|
10715
|
+
sendResponse9(id, {
|
|
10310
10716
|
success: false,
|
|
10311
10717
|
error: "Failed to update knowledge node"
|
|
10312
10718
|
}, sendMessage, clientId);
|
|
10313
10719
|
} catch (error) {
|
|
10314
10720
|
logger.error("[DB] Failed to update KB node:", error);
|
|
10315
|
-
|
|
10721
|
+
sendResponse9(id, {
|
|
10316
10722
|
success: false,
|
|
10317
10723
|
error: error instanceof Error ? error.message : "Failed to update knowledge node"
|
|
10318
10724
|
}, sendMessage, clientId);
|
|
10319
10725
|
}
|
|
10320
10726
|
}
|
|
10321
|
-
async function
|
|
10727
|
+
async function handleDelete7(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
10322
10728
|
if (!nodeId) {
|
|
10323
|
-
|
|
10729
|
+
sendResponse9(id, {
|
|
10324
10730
|
success: false,
|
|
10325
10731
|
error: "Knowledge node ID is required"
|
|
10326
10732
|
}, sendMessage, clientId);
|
|
@@ -10330,7 +10736,7 @@ async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10330
10736
|
const result = await executeCollection("kbNodes", "delete", { id: nodeId });
|
|
10331
10737
|
if (result && result.success) {
|
|
10332
10738
|
logger.info(`[DB] KB node deleted successfully, ID: ${nodeId}`);
|
|
10333
|
-
|
|
10739
|
+
sendResponse9(id, {
|
|
10334
10740
|
success: true,
|
|
10335
10741
|
data: {
|
|
10336
10742
|
id: nodeId,
|
|
@@ -10340,19 +10746,19 @@ async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10340
10746
|
}, sendMessage, clientId);
|
|
10341
10747
|
return;
|
|
10342
10748
|
}
|
|
10343
|
-
|
|
10749
|
+
sendResponse9(id, {
|
|
10344
10750
|
success: false,
|
|
10345
10751
|
error: "Failed to delete knowledge node"
|
|
10346
10752
|
}, sendMessage, clientId);
|
|
10347
10753
|
} catch (error) {
|
|
10348
10754
|
logger.error("[DB] Failed to delete KB node:", error);
|
|
10349
|
-
|
|
10755
|
+
sendResponse9(id, {
|
|
10350
10756
|
success: false,
|
|
10351
10757
|
error: error instanceof Error ? error.message : "Failed to delete knowledge node"
|
|
10352
10758
|
}, sendMessage, clientId);
|
|
10353
10759
|
}
|
|
10354
10760
|
}
|
|
10355
|
-
async function
|
|
10761
|
+
async function handleGetAll7(id, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10356
10762
|
try {
|
|
10357
10763
|
const result = await executeCollection("kbNodes", "getAll", {
|
|
10358
10764
|
limit: limit || 100,
|
|
@@ -10360,7 +10766,7 @@ async function handleGetAll6(id, limit, offset, executeCollection, sendMessage,
|
|
|
10360
10766
|
});
|
|
10361
10767
|
if (result && result.success) {
|
|
10362
10768
|
logger.info(`[DB] Retrieved ${result.count} KB nodes`);
|
|
10363
|
-
|
|
10769
|
+
sendResponse9(id, {
|
|
10364
10770
|
success: true,
|
|
10365
10771
|
data: {
|
|
10366
10772
|
nodes: result.data,
|
|
@@ -10370,21 +10776,21 @@ async function handleGetAll6(id, limit, offset, executeCollection, sendMessage,
|
|
|
10370
10776
|
}, sendMessage, clientId);
|
|
10371
10777
|
return;
|
|
10372
10778
|
}
|
|
10373
|
-
|
|
10779
|
+
sendResponse9(id, {
|
|
10374
10780
|
success: false,
|
|
10375
10781
|
error: "Failed to retrieve knowledge nodes"
|
|
10376
10782
|
}, sendMessage, clientId);
|
|
10377
10783
|
} catch (error) {
|
|
10378
10784
|
logger.error("[DB] Failed to get all KB nodes:", error);
|
|
10379
|
-
|
|
10785
|
+
sendResponse9(id, {
|
|
10380
10786
|
success: false,
|
|
10381
10787
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes"
|
|
10382
10788
|
}, sendMessage, clientId);
|
|
10383
10789
|
}
|
|
10384
10790
|
}
|
|
10385
|
-
async function
|
|
10791
|
+
async function handleGetOne7(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
10386
10792
|
if (!nodeId) {
|
|
10387
|
-
|
|
10793
|
+
sendResponse9(id, {
|
|
10388
10794
|
success: false,
|
|
10389
10795
|
error: "Knowledge node ID is required"
|
|
10390
10796
|
}, sendMessage, clientId);
|
|
@@ -10394,7 +10800,7 @@ async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10394
10800
|
const result = await executeCollection("kbNodes", "getOne", { id: nodeId });
|
|
10395
10801
|
if (result && result.success) {
|
|
10396
10802
|
logger.info(`[DB] Retrieved KB node ID: ${nodeId}`);
|
|
10397
|
-
|
|
10803
|
+
sendResponse9(id, {
|
|
10398
10804
|
success: true,
|
|
10399
10805
|
data: {
|
|
10400
10806
|
node: result.data,
|
|
@@ -10403,32 +10809,33 @@ async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10403
10809
|
}, sendMessage, clientId);
|
|
10404
10810
|
return;
|
|
10405
10811
|
}
|
|
10406
|
-
|
|
10812
|
+
sendResponse9(id, {
|
|
10407
10813
|
success: false,
|
|
10408
10814
|
error: "Failed to retrieve knowledge node"
|
|
10409
10815
|
}, sendMessage, clientId);
|
|
10410
10816
|
} catch (error) {
|
|
10411
10817
|
logger.error("[DB] Failed to get KB node:", error);
|
|
10412
|
-
|
|
10818
|
+
sendResponse9(id, {
|
|
10413
10819
|
success: false,
|
|
10414
10820
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge node"
|
|
10415
10821
|
}, sendMessage, clientId);
|
|
10416
10822
|
}
|
|
10417
10823
|
}
|
|
10418
10824
|
async function handleSearch(id, searchParams, executeCollection, sendMessage, clientId) {
|
|
10419
|
-
const { query, category, tags, createdBy, limit, offset } = searchParams;
|
|
10825
|
+
const { query, category, tags, type, createdBy, limit, offset } = searchParams;
|
|
10420
10826
|
try {
|
|
10421
10827
|
const result = await executeCollection("kbNodes", "search", {
|
|
10422
10828
|
query,
|
|
10423
10829
|
category,
|
|
10424
10830
|
tags,
|
|
10831
|
+
type,
|
|
10425
10832
|
createdBy,
|
|
10426
10833
|
limit: limit || 50,
|
|
10427
10834
|
offset: offset || 0
|
|
10428
10835
|
});
|
|
10429
10836
|
if (result && result.success) {
|
|
10430
10837
|
logger.info(`[DB] Search returned ${result.count} KB nodes`);
|
|
10431
|
-
|
|
10838
|
+
sendResponse9(id, {
|
|
10432
10839
|
success: true,
|
|
10433
10840
|
data: {
|
|
10434
10841
|
nodes: result.data,
|
|
@@ -10438,13 +10845,13 @@ async function handleSearch(id, searchParams, executeCollection, sendMessage, cl
|
|
|
10438
10845
|
}, sendMessage, clientId);
|
|
10439
10846
|
return;
|
|
10440
10847
|
}
|
|
10441
|
-
|
|
10848
|
+
sendResponse9(id, {
|
|
10442
10849
|
success: false,
|
|
10443
10850
|
error: "Failed to search knowledge nodes"
|
|
10444
10851
|
}, sendMessage, clientId);
|
|
10445
10852
|
} catch (error) {
|
|
10446
10853
|
logger.error("[DB] Failed to search KB nodes:", error);
|
|
10447
|
-
|
|
10854
|
+
sendResponse9(id, {
|
|
10448
10855
|
success: false,
|
|
10449
10856
|
error: error instanceof Error ? error.message : "Failed to search knowledge nodes"
|
|
10450
10857
|
}, sendMessage, clientId);
|
|
@@ -10452,7 +10859,7 @@ async function handleSearch(id, searchParams, executeCollection, sendMessage, cl
|
|
|
10452
10859
|
}
|
|
10453
10860
|
async function handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10454
10861
|
if (!category) {
|
|
10455
|
-
|
|
10862
|
+
sendResponse9(id, {
|
|
10456
10863
|
success: false,
|
|
10457
10864
|
error: "Category is required"
|
|
10458
10865
|
}, sendMessage, clientId);
|
|
@@ -10466,7 +10873,7 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10466
10873
|
});
|
|
10467
10874
|
if (result && result.success) {
|
|
10468
10875
|
logger.info(`[DB] Retrieved ${result.count} KB nodes for category: ${category}`);
|
|
10469
|
-
|
|
10876
|
+
sendResponse9(id, {
|
|
10470
10877
|
success: true,
|
|
10471
10878
|
data: {
|
|
10472
10879
|
nodes: result.data,
|
|
@@ -10477,13 +10884,13 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10477
10884
|
}, sendMessage, clientId);
|
|
10478
10885
|
return;
|
|
10479
10886
|
}
|
|
10480
|
-
|
|
10887
|
+
sendResponse9(id, {
|
|
10481
10888
|
success: false,
|
|
10482
10889
|
error: "Failed to retrieve knowledge nodes by category"
|
|
10483
10890
|
}, sendMessage, clientId);
|
|
10484
10891
|
} catch (error) {
|
|
10485
10892
|
logger.error("[DB] Failed to get KB nodes by category:", error);
|
|
10486
|
-
|
|
10893
|
+
sendResponse9(id, {
|
|
10487
10894
|
success: false,
|
|
10488
10895
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by category"
|
|
10489
10896
|
}, sendMessage, clientId);
|
|
@@ -10491,7 +10898,7 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10491
10898
|
}
|
|
10492
10899
|
async function handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10493
10900
|
if (!userId) {
|
|
10494
|
-
|
|
10901
|
+
sendResponse9(id, {
|
|
10495
10902
|
success: false,
|
|
10496
10903
|
error: "User ID is required"
|
|
10497
10904
|
}, sendMessage, clientId);
|
|
@@ -10505,7 +10912,7 @@ async function handleGetByUser(id, userId, limit, offset, executeCollection, sen
|
|
|
10505
10912
|
});
|
|
10506
10913
|
if (result && result.success) {
|
|
10507
10914
|
logger.info(`[DB] Retrieved ${result.count} KB nodes for user: ${userId}`);
|
|
10508
|
-
|
|
10915
|
+
sendResponse9(id, {
|
|
10509
10916
|
success: true,
|
|
10510
10917
|
data: {
|
|
10511
10918
|
nodes: result.data,
|
|
@@ -10516,13 +10923,13 @@ async function handleGetByUser(id, userId, limit, offset, executeCollection, sen
|
|
|
10516
10923
|
}, sendMessage, clientId);
|
|
10517
10924
|
return;
|
|
10518
10925
|
}
|
|
10519
|
-
|
|
10926
|
+
sendResponse9(id, {
|
|
10520
10927
|
success: false,
|
|
10521
10928
|
error: "Failed to retrieve knowledge nodes by user"
|
|
10522
10929
|
}, sendMessage, clientId);
|
|
10523
10930
|
} catch (error) {
|
|
10524
10931
|
logger.error("[DB] Failed to get KB nodes by user:", error);
|
|
10525
|
-
|
|
10932
|
+
sendResponse9(id, {
|
|
10526
10933
|
success: false,
|
|
10527
10934
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by user"
|
|
10528
10935
|
}, sendMessage, clientId);
|
|
@@ -10533,7 +10940,7 @@ async function handleGetCategories(id, executeCollection, sendMessage, clientId)
|
|
|
10533
10940
|
const result = await executeCollection("kbNodes", "getCategories", {});
|
|
10534
10941
|
if (result && result.success) {
|
|
10535
10942
|
logger.info(`[DB] Retrieved ${result.count} categories`);
|
|
10536
|
-
|
|
10943
|
+
sendResponse9(id, {
|
|
10537
10944
|
success: true,
|
|
10538
10945
|
data: {
|
|
10539
10946
|
categories: result.data,
|
|
@@ -10543,13 +10950,13 @@ async function handleGetCategories(id, executeCollection, sendMessage, clientId)
|
|
|
10543
10950
|
}, sendMessage, clientId);
|
|
10544
10951
|
return;
|
|
10545
10952
|
}
|
|
10546
|
-
|
|
10953
|
+
sendResponse9(id, {
|
|
10547
10954
|
success: false,
|
|
10548
10955
|
error: "Failed to retrieve categories"
|
|
10549
10956
|
}, sendMessage, clientId);
|
|
10550
10957
|
} catch (error) {
|
|
10551
10958
|
logger.error("[DB] Failed to get categories:", error);
|
|
10552
|
-
|
|
10959
|
+
sendResponse9(id, {
|
|
10553
10960
|
success: false,
|
|
10554
10961
|
error: error instanceof Error ? error.message : "Failed to retrieve categories"
|
|
10555
10962
|
}, sendMessage, clientId);
|
|
@@ -10560,7 +10967,7 @@ async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
|
10560
10967
|
const result = await executeCollection("kbNodes", "getTags", {});
|
|
10561
10968
|
if (result && result.success) {
|
|
10562
10969
|
logger.info(`[DB] Retrieved ${result.count} tags`);
|
|
10563
|
-
|
|
10970
|
+
sendResponse9(id, {
|
|
10564
10971
|
success: true,
|
|
10565
10972
|
data: {
|
|
10566
10973
|
tags: result.data,
|
|
@@ -10570,19 +10977,19 @@ async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
|
10570
10977
|
}, sendMessage, clientId);
|
|
10571
10978
|
return;
|
|
10572
10979
|
}
|
|
10573
|
-
|
|
10980
|
+
sendResponse9(id, {
|
|
10574
10981
|
success: false,
|
|
10575
10982
|
error: "Failed to retrieve tags"
|
|
10576
10983
|
}, sendMessage, clientId);
|
|
10577
10984
|
} catch (error) {
|
|
10578
10985
|
logger.error("[DB] Failed to get tags:", error);
|
|
10579
|
-
|
|
10986
|
+
sendResponse9(id, {
|
|
10580
10987
|
success: false,
|
|
10581
10988
|
error: error instanceof Error ? error.message : "Failed to retrieve tags"
|
|
10582
10989
|
}, sendMessage, clientId);
|
|
10583
10990
|
}
|
|
10584
10991
|
}
|
|
10585
|
-
function
|
|
10992
|
+
function sendResponse9(id, res, sendMessage, clientId) {
|
|
10586
10993
|
const response = {
|
|
10587
10994
|
id: id || "unknown",
|
|
10588
10995
|
type: "KB_NODES_RES",
|
|
@@ -10627,19 +11034,19 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10627
11034
|
const items = requestData?.items;
|
|
10628
11035
|
switch (operation) {
|
|
10629
11036
|
case "create":
|
|
10630
|
-
await
|
|
11037
|
+
await handleCreate8(id, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, from.id);
|
|
10631
11038
|
break;
|
|
10632
11039
|
case "update":
|
|
10633
|
-
await
|
|
11040
|
+
await handleUpdate8(id, menuId, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, from.id);
|
|
10634
11041
|
break;
|
|
10635
11042
|
case "delete":
|
|
10636
|
-
await
|
|
11043
|
+
await handleDelete8(id, menuId, executeCollection, sendMessage, from.id);
|
|
10637
11044
|
break;
|
|
10638
11045
|
case "getAll":
|
|
10639
|
-
await
|
|
11046
|
+
await handleGetAll8(id, executeCollection, sendMessage, from.id);
|
|
10640
11047
|
break;
|
|
10641
11048
|
case "getOne":
|
|
10642
|
-
await
|
|
11049
|
+
await handleGetOne8(id, menuId, executeCollection, sendMessage, from.id);
|
|
10643
11050
|
break;
|
|
10644
11051
|
case "getRootMenus":
|
|
10645
11052
|
await handleGetRootMenus(id, executeCollection, sendMessage, from.id);
|
|
@@ -10651,35 +11058,35 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10651
11058
|
await handleGetHierarchy(id, executeCollection, sendMessage, from.id);
|
|
10652
11059
|
break;
|
|
10653
11060
|
case "query":
|
|
10654
|
-
await
|
|
11061
|
+
await handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
10655
11062
|
break;
|
|
10656
11063
|
case "reorder":
|
|
10657
11064
|
await handleReorder(id, items, executeCollection, sendMessage, from.id);
|
|
10658
11065
|
break;
|
|
10659
11066
|
default:
|
|
10660
|
-
|
|
11067
|
+
sendResponse10(id, {
|
|
10661
11068
|
success: false,
|
|
10662
11069
|
error: `Unknown operation: ${operation}`
|
|
10663
11070
|
}, sendMessage, from.id);
|
|
10664
11071
|
}
|
|
10665
11072
|
} catch (error) {
|
|
10666
11073
|
logger.error("Failed to handle menus request:", error);
|
|
10667
|
-
|
|
11074
|
+
sendResponse10(null, {
|
|
10668
11075
|
success: false,
|
|
10669
11076
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10670
11077
|
}, sendMessage);
|
|
10671
11078
|
}
|
|
10672
11079
|
}
|
|
10673
|
-
async function
|
|
11080
|
+
async function handleCreate8(id, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, clientId) {
|
|
10674
11081
|
if (!name) {
|
|
10675
|
-
|
|
11082
|
+
sendResponse10(id, {
|
|
10676
11083
|
success: false,
|
|
10677
11084
|
error: "name is required"
|
|
10678
11085
|
}, sendMessage, clientId);
|
|
10679
11086
|
return;
|
|
10680
11087
|
}
|
|
10681
11088
|
if (!componentName) {
|
|
10682
|
-
|
|
11089
|
+
sendResponse10(id, {
|
|
10683
11090
|
success: false,
|
|
10684
11091
|
error: "componentName is required"
|
|
10685
11092
|
}, sendMessage, clientId);
|
|
@@ -10696,22 +11103,22 @@ async function handleCreate7(id, name, componentName, icon, userMessage, parentI
|
|
|
10696
11103
|
props,
|
|
10697
11104
|
isActive
|
|
10698
11105
|
});
|
|
10699
|
-
|
|
11106
|
+
sendResponse10(id, {
|
|
10700
11107
|
success: true,
|
|
10701
11108
|
data: result.data,
|
|
10702
11109
|
message: "Menu created successfully"
|
|
10703
11110
|
}, sendMessage, clientId);
|
|
10704
11111
|
logger.info(`Menu created: ID ${result.data?.id}`);
|
|
10705
11112
|
} catch (error) {
|
|
10706
|
-
|
|
11113
|
+
sendResponse10(id, {
|
|
10707
11114
|
success: false,
|
|
10708
11115
|
error: error instanceof Error ? error.message : "Failed to create menu"
|
|
10709
11116
|
}, sendMessage, clientId);
|
|
10710
11117
|
}
|
|
10711
11118
|
}
|
|
10712
|
-
async function
|
|
11119
|
+
async function handleUpdate8(id, menuId, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, clientId) {
|
|
10713
11120
|
if (!menuId) {
|
|
10714
|
-
|
|
11121
|
+
sendResponse10(id, {
|
|
10715
11122
|
success: false,
|
|
10716
11123
|
error: "Menu ID is required"
|
|
10717
11124
|
}, sendMessage, clientId);
|
|
@@ -10729,22 +11136,22 @@ async function handleUpdate7(id, menuId, name, componentName, icon, userMessage,
|
|
|
10729
11136
|
props,
|
|
10730
11137
|
isActive
|
|
10731
11138
|
});
|
|
10732
|
-
|
|
11139
|
+
sendResponse10(id, {
|
|
10733
11140
|
success: true,
|
|
10734
11141
|
data: result.data,
|
|
10735
11142
|
message: "Menu updated successfully"
|
|
10736
11143
|
}, sendMessage, clientId);
|
|
10737
11144
|
logger.info(`Menu updated: ID ${menuId}`);
|
|
10738
11145
|
} catch (error) {
|
|
10739
|
-
|
|
11146
|
+
sendResponse10(id, {
|
|
10740
11147
|
success: false,
|
|
10741
11148
|
error: error instanceof Error ? error.message : "Failed to update menu"
|
|
10742
11149
|
}, sendMessage, clientId);
|
|
10743
11150
|
}
|
|
10744
11151
|
}
|
|
10745
|
-
async function
|
|
11152
|
+
async function handleDelete8(id, menuId, executeCollection, sendMessage, clientId) {
|
|
10746
11153
|
if (!menuId) {
|
|
10747
|
-
|
|
11154
|
+
sendResponse10(id, {
|
|
10748
11155
|
success: false,
|
|
10749
11156
|
error: "Menu ID is required"
|
|
10750
11157
|
}, sendMessage, clientId);
|
|
@@ -10752,23 +11159,23 @@ async function handleDelete7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10752
11159
|
}
|
|
10753
11160
|
try {
|
|
10754
11161
|
const result = await executeCollection("menus", "delete", { id: menuId });
|
|
10755
|
-
|
|
11162
|
+
sendResponse10(id, {
|
|
10756
11163
|
success: true,
|
|
10757
11164
|
data: result.data,
|
|
10758
11165
|
message: "Menu deleted successfully"
|
|
10759
11166
|
}, sendMessage, clientId);
|
|
10760
11167
|
logger.info(`Menu deleted: ID ${menuId}`);
|
|
10761
11168
|
} catch (error) {
|
|
10762
|
-
|
|
11169
|
+
sendResponse10(id, {
|
|
10763
11170
|
success: false,
|
|
10764
11171
|
error: error instanceof Error ? error.message : "Failed to delete menu"
|
|
10765
11172
|
}, sendMessage, clientId);
|
|
10766
11173
|
}
|
|
10767
11174
|
}
|
|
10768
|
-
async function
|
|
11175
|
+
async function handleGetAll8(id, executeCollection, sendMessage, clientId) {
|
|
10769
11176
|
try {
|
|
10770
11177
|
const result = await executeCollection("menus", "getAll", {});
|
|
10771
|
-
|
|
11178
|
+
sendResponse10(id, {
|
|
10772
11179
|
success: true,
|
|
10773
11180
|
data: result.data,
|
|
10774
11181
|
count: result.count,
|
|
@@ -10776,15 +11183,15 @@ async function handleGetAll7(id, executeCollection, sendMessage, clientId) {
|
|
|
10776
11183
|
}, sendMessage, clientId);
|
|
10777
11184
|
logger.info(`Retrieved all menus (count: ${result.count})`);
|
|
10778
11185
|
} catch (error) {
|
|
10779
|
-
|
|
11186
|
+
sendResponse10(id, {
|
|
10780
11187
|
success: false,
|
|
10781
11188
|
error: error instanceof Error ? error.message : "Failed to get menus"
|
|
10782
11189
|
}, sendMessage, clientId);
|
|
10783
11190
|
}
|
|
10784
11191
|
}
|
|
10785
|
-
async function
|
|
11192
|
+
async function handleGetOne8(id, menuId, executeCollection, sendMessage, clientId) {
|
|
10786
11193
|
if (!menuId) {
|
|
10787
|
-
|
|
11194
|
+
sendResponse10(id, {
|
|
10788
11195
|
success: false,
|
|
10789
11196
|
error: "Menu ID is required"
|
|
10790
11197
|
}, sendMessage, clientId);
|
|
@@ -10792,14 +11199,14 @@ async function handleGetOne7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10792
11199
|
}
|
|
10793
11200
|
try {
|
|
10794
11201
|
const result = await executeCollection("menus", "getOne", { id: menuId });
|
|
10795
|
-
|
|
11202
|
+
sendResponse10(id, {
|
|
10796
11203
|
success: true,
|
|
10797
11204
|
data: result.data,
|
|
10798
11205
|
message: `Retrieved menu ID ${menuId}`
|
|
10799
11206
|
}, sendMessage, clientId);
|
|
10800
11207
|
logger.info(`Retrieved menu: ID ${menuId}`);
|
|
10801
11208
|
} catch (error) {
|
|
10802
|
-
|
|
11209
|
+
sendResponse10(id, {
|
|
10803
11210
|
success: false,
|
|
10804
11211
|
error: error instanceof Error ? error.message : "Failed to get menu"
|
|
10805
11212
|
}, sendMessage, clientId);
|
|
@@ -10808,7 +11215,7 @@ async function handleGetOne7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10808
11215
|
async function handleGetRootMenus(id, executeCollection, sendMessage, clientId) {
|
|
10809
11216
|
try {
|
|
10810
11217
|
const result = await executeCollection("menus", "getRootMenus", {});
|
|
10811
|
-
|
|
11218
|
+
sendResponse10(id, {
|
|
10812
11219
|
success: true,
|
|
10813
11220
|
data: result.data,
|
|
10814
11221
|
count: result.count,
|
|
@@ -10816,7 +11223,7 @@ async function handleGetRootMenus(id, executeCollection, sendMessage, clientId)
|
|
|
10816
11223
|
}, sendMessage, clientId);
|
|
10817
11224
|
logger.info(`Retrieved root menus (count: ${result.count})`);
|
|
10818
11225
|
} catch (error) {
|
|
10819
|
-
|
|
11226
|
+
sendResponse10(id, {
|
|
10820
11227
|
success: false,
|
|
10821
11228
|
error: error instanceof Error ? error.message : "Failed to get root menus"
|
|
10822
11229
|
}, sendMessage, clientId);
|
|
@@ -10824,7 +11231,7 @@ async function handleGetRootMenus(id, executeCollection, sendMessage, clientId)
|
|
|
10824
11231
|
}
|
|
10825
11232
|
async function handleGetChildMenus(id, parentId, executeCollection, sendMessage, clientId) {
|
|
10826
11233
|
if (parentId === void 0 || parentId === null) {
|
|
10827
|
-
|
|
11234
|
+
sendResponse10(id, {
|
|
10828
11235
|
success: false,
|
|
10829
11236
|
error: "parentId is required"
|
|
10830
11237
|
}, sendMessage, clientId);
|
|
@@ -10832,7 +11239,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10832
11239
|
}
|
|
10833
11240
|
try {
|
|
10834
11241
|
const result = await executeCollection("menus", "getChildMenus", { parentId });
|
|
10835
|
-
|
|
11242
|
+
sendResponse10(id, {
|
|
10836
11243
|
success: true,
|
|
10837
11244
|
data: result.data,
|
|
10838
11245
|
count: result.count,
|
|
@@ -10840,7 +11247,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10840
11247
|
}, sendMessage, clientId);
|
|
10841
11248
|
logger.info(`Retrieved child menus for parent ${parentId} (count: ${result.count})`);
|
|
10842
11249
|
} catch (error) {
|
|
10843
|
-
|
|
11250
|
+
sendResponse10(id, {
|
|
10844
11251
|
success: false,
|
|
10845
11252
|
error: error instanceof Error ? error.message : "Failed to get child menus"
|
|
10846
11253
|
}, sendMessage, clientId);
|
|
@@ -10849,7 +11256,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10849
11256
|
async function handleGetHierarchy(id, executeCollection, sendMessage, clientId) {
|
|
10850
11257
|
try {
|
|
10851
11258
|
const result = await executeCollection("menus", "getHierarchy", {});
|
|
10852
|
-
|
|
11259
|
+
sendResponse10(id, {
|
|
10853
11260
|
success: true,
|
|
10854
11261
|
data: result.data,
|
|
10855
11262
|
count: result.count,
|
|
@@ -10857,20 +11264,20 @@ async function handleGetHierarchy(id, executeCollection, sendMessage, clientId)
|
|
|
10857
11264
|
}, sendMessage, clientId);
|
|
10858
11265
|
logger.info(`Retrieved menus hierarchy (root count: ${result.count})`);
|
|
10859
11266
|
} catch (error) {
|
|
10860
|
-
|
|
11267
|
+
sendResponse10(id, {
|
|
10861
11268
|
success: false,
|
|
10862
11269
|
error: error instanceof Error ? error.message : "Failed to get menus hierarchy"
|
|
10863
11270
|
}, sendMessage, clientId);
|
|
10864
11271
|
}
|
|
10865
11272
|
}
|
|
10866
|
-
async function
|
|
11273
|
+
async function handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
10867
11274
|
try {
|
|
10868
11275
|
const result = await executeCollection("menus", "query", {
|
|
10869
11276
|
filters: filters || {},
|
|
10870
11277
|
limit,
|
|
10871
11278
|
sort
|
|
10872
11279
|
});
|
|
10873
|
-
|
|
11280
|
+
sendResponse10(id, {
|
|
10874
11281
|
success: true,
|
|
10875
11282
|
data: result.data,
|
|
10876
11283
|
count: result.count,
|
|
@@ -10878,7 +11285,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10878
11285
|
}, sendMessage, clientId);
|
|
10879
11286
|
logger.info(`Query returned ${result.count} menus`);
|
|
10880
11287
|
} catch (error) {
|
|
10881
|
-
|
|
11288
|
+
sendResponse10(id, {
|
|
10882
11289
|
success: false,
|
|
10883
11290
|
error: error instanceof Error ? error.message : "Failed to query menus"
|
|
10884
11291
|
}, sendMessage, clientId);
|
|
@@ -10886,7 +11293,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10886
11293
|
}
|
|
10887
11294
|
async function handleReorder(id, items, executeCollection, sendMessage, clientId) {
|
|
10888
11295
|
if (!items || !Array.isArray(items) || items.length === 0) {
|
|
10889
|
-
|
|
11296
|
+
sendResponse10(id, {
|
|
10890
11297
|
success: false,
|
|
10891
11298
|
error: "items array is required"
|
|
10892
11299
|
}, sendMessage, clientId);
|
|
@@ -10894,20 +11301,20 @@ async function handleReorder(id, items, executeCollection, sendMessage, clientId
|
|
|
10894
11301
|
}
|
|
10895
11302
|
try {
|
|
10896
11303
|
const result = await executeCollection("menus", "reorder", { items });
|
|
10897
|
-
|
|
11304
|
+
sendResponse10(id, {
|
|
10898
11305
|
success: true,
|
|
10899
11306
|
data: result.data,
|
|
10900
11307
|
message: `Reordered ${items.length} menus successfully`
|
|
10901
11308
|
}, sendMessage, clientId);
|
|
10902
11309
|
logger.info(`Reordered ${items.length} menus`);
|
|
10903
11310
|
} catch (error) {
|
|
10904
|
-
|
|
11311
|
+
sendResponse10(id, {
|
|
10905
11312
|
success: false,
|
|
10906
11313
|
error: error instanceof Error ? error.message : "Failed to reorder menus"
|
|
10907
11314
|
}, sendMessage, clientId);
|
|
10908
11315
|
}
|
|
10909
11316
|
}
|
|
10910
|
-
function
|
|
11317
|
+
function sendResponse10(id, res, sendMessage, clientId) {
|
|
10911
11318
|
const response = {
|
|
10912
11319
|
id: id || "unknown",
|
|
10913
11320
|
type: "MENUS_RES",
|
|
@@ -12439,6 +12846,11 @@ var SuperatomSDK = class {
|
|
|
12439
12846
|
logger.error("Failed to handle bookmarks request:", error);
|
|
12440
12847
|
});
|
|
12441
12848
|
break;
|
|
12849
|
+
case "ARTIFACTS":
|
|
12850
|
+
handleArtifactsRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
12851
|
+
logger.error("Failed to handle artifacts request:", error);
|
|
12852
|
+
});
|
|
12853
|
+
break;
|
|
12442
12854
|
case "KB_NODES":
|
|
12443
12855
|
handleKbNodesRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
12444
12856
|
logger.error("Failed to handle KB nodes request:", error);
|