@superatomai/sdk-node 0.0.55 → 0.0.57
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/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +485 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +485 -112
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2359,10 +2359,30 @@ var BookmarksRequestMessageSchema = z3.object({
|
|
|
2359
2359
|
type: z3.literal("BOOKMARKS"),
|
|
2360
2360
|
payload: BookmarksRequestPayloadSchema
|
|
2361
2361
|
});
|
|
2362
|
+
var ArtifactsRequestPayloadSchema = z3.object({
|
|
2363
|
+
operation: z3.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
2364
|
+
data: z3.object({
|
|
2365
|
+
id: z3.number().optional(),
|
|
2366
|
+
name: z3.string().optional(),
|
|
2367
|
+
createdBy: z3.number().optional(),
|
|
2368
|
+
dsl: z3.record(z3.any()).optional(),
|
|
2369
|
+
status: z3.string().optional(),
|
|
2370
|
+
deleted: z3.boolean().optional(),
|
|
2371
|
+
limit: z3.number().optional()
|
|
2372
|
+
}).optional()
|
|
2373
|
+
});
|
|
2374
|
+
var ArtifactsRequestMessageSchema = z3.object({
|
|
2375
|
+
id: z3.string(),
|
|
2376
|
+
from: MessageParticipantSchema,
|
|
2377
|
+
type: z3.literal("ARTIFACTS"),
|
|
2378
|
+
payload: ArtifactsRequestPayloadSchema
|
|
2379
|
+
});
|
|
2380
|
+
var KbNodeTypeSchema = z3.enum(["global", "user", "query"]);
|
|
2362
2381
|
var KbNodesQueryFiltersSchema = z3.object({
|
|
2363
2382
|
query: z3.string().optional(),
|
|
2364
2383
|
category: z3.string().optional(),
|
|
2365
2384
|
tags: z3.array(z3.string()).optional(),
|
|
2385
|
+
type: KbNodeTypeSchema.optional(),
|
|
2366
2386
|
createdBy: z3.number().optional()
|
|
2367
2387
|
});
|
|
2368
2388
|
var KbNodesRequestPayloadSchema = z3.object({
|
|
@@ -2373,6 +2393,7 @@ var KbNodesRequestPayloadSchema = z3.object({
|
|
|
2373
2393
|
content: z3.string().optional(),
|
|
2374
2394
|
category: z3.string().optional(),
|
|
2375
2395
|
tags: z3.array(z3.string()).optional(),
|
|
2396
|
+
type: KbNodeTypeSchema.optional(),
|
|
2376
2397
|
createdBy: z3.number().optional(),
|
|
2377
2398
|
updatedBy: z3.number().optional(),
|
|
2378
2399
|
userId: z3.number().optional(),
|
|
@@ -5386,7 +5407,7 @@ var getKnowledgeBase = async ({
|
|
|
5386
5407
|
topK
|
|
5387
5408
|
});
|
|
5388
5409
|
if (!result || !result.content) {
|
|
5389
|
-
logger.
|
|
5410
|
+
logger.info("[KnowledgeBase] No knowledge base results returned");
|
|
5390
5411
|
return "";
|
|
5391
5412
|
}
|
|
5392
5413
|
logger.info(`[KnowledgeBase] Retrieved knowledge base context (${result.content.length} chars)`);
|
|
@@ -5400,8 +5421,101 @@ var getKnowledgeBase = async ({
|
|
|
5400
5421
|
return "";
|
|
5401
5422
|
}
|
|
5402
5423
|
};
|
|
5424
|
+
var getGlobalKnowledgeBase = async ({
|
|
5425
|
+
collections,
|
|
5426
|
+
limit = 100
|
|
5427
|
+
}) => {
|
|
5428
|
+
try {
|
|
5429
|
+
if (!collections || !collections["knowledge-base"] || !collections["knowledge-base"]["getGlobal"]) {
|
|
5430
|
+
logger.info("[KnowledgeBase] knowledge-base.getGlobal collection not registered, skipping");
|
|
5431
|
+
return "";
|
|
5432
|
+
}
|
|
5433
|
+
logger.info("[KnowledgeBase] Fetching global knowledge base nodes...");
|
|
5434
|
+
const result = await collections["knowledge-base"]["getGlobal"]({ limit });
|
|
5435
|
+
if (!result || !result.content) {
|
|
5436
|
+
logger.info("[KnowledgeBase] No global knowledge base nodes found");
|
|
5437
|
+
return "";
|
|
5438
|
+
}
|
|
5439
|
+
logger.info(`[KnowledgeBase] Retrieved ${result.count || 0} global knowledge base nodes`);
|
|
5440
|
+
return result.content;
|
|
5441
|
+
} catch (error) {
|
|
5442
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5443
|
+
logger.warn(`[KnowledgeBase] Error fetching global knowledge base: ${errorMsg}`);
|
|
5444
|
+
return "";
|
|
5445
|
+
}
|
|
5446
|
+
};
|
|
5447
|
+
var getUserKnowledgeBase = async ({
|
|
5448
|
+
collections,
|
|
5449
|
+
userId,
|
|
5450
|
+
limit = 100
|
|
5451
|
+
}) => {
|
|
5452
|
+
try {
|
|
5453
|
+
if (!userId) {
|
|
5454
|
+
logger.info("[KnowledgeBase] No userId provided, skipping user knowledge base");
|
|
5455
|
+
return "";
|
|
5456
|
+
}
|
|
5457
|
+
if (!collections || !collections["knowledge-base"] || !collections["knowledge-base"]["getByUser"]) {
|
|
5458
|
+
logger.info("[KnowledgeBase] knowledge-base.getByUser collection not registered, skipping");
|
|
5459
|
+
return "";
|
|
5460
|
+
}
|
|
5461
|
+
logger.info(`[KnowledgeBase] Fetching user knowledge base nodes for userId: ${userId}...`);
|
|
5462
|
+
const result = await collections["knowledge-base"]["getByUser"]({
|
|
5463
|
+
userId: Number(userId),
|
|
5464
|
+
limit
|
|
5465
|
+
});
|
|
5466
|
+
if (!result || !result.content) {
|
|
5467
|
+
logger.info(`[KnowledgeBase] No user knowledge base nodes found for userId: ${userId}`);
|
|
5468
|
+
return "";
|
|
5469
|
+
}
|
|
5470
|
+
logger.info(`[KnowledgeBase] Retrieved ${result.count || 0} user knowledge base nodes for userId: ${userId}`);
|
|
5471
|
+
return result.content;
|
|
5472
|
+
} catch (error) {
|
|
5473
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5474
|
+
logger.warn(`[KnowledgeBase] Error fetching user knowledge base: ${errorMsg}`);
|
|
5475
|
+
return "";
|
|
5476
|
+
}
|
|
5477
|
+
};
|
|
5478
|
+
var getAllKnowledgeBase = async ({
|
|
5479
|
+
prompt,
|
|
5480
|
+
collections,
|
|
5481
|
+
userId,
|
|
5482
|
+
topK = 3
|
|
5483
|
+
}) => {
|
|
5484
|
+
logger.info("[KnowledgeBase] Fetching all knowledge base contexts...");
|
|
5485
|
+
const [globalContext, userContext, queryContext] = await Promise.all([
|
|
5486
|
+
getGlobalKnowledgeBase({ collections }),
|
|
5487
|
+
getUserKnowledgeBase({ collections, userId }),
|
|
5488
|
+
getKnowledgeBase({ prompt, collections, topK })
|
|
5489
|
+
]);
|
|
5490
|
+
let combinedContext = "";
|
|
5491
|
+
if (globalContext) {
|
|
5492
|
+
combinedContext += "## Global Knowledge Base\n";
|
|
5493
|
+
combinedContext += "The following information applies to all queries:\n\n";
|
|
5494
|
+
combinedContext += globalContext + "\n\n";
|
|
5495
|
+
}
|
|
5496
|
+
if (userContext) {
|
|
5497
|
+
combinedContext += "## User-Specific Knowledge Base\n";
|
|
5498
|
+
combinedContext += "The following information is specific to this user:\n\n";
|
|
5499
|
+
combinedContext += userContext + "\n\n";
|
|
5500
|
+
}
|
|
5501
|
+
if (queryContext) {
|
|
5502
|
+
combinedContext += "## Relevant Knowledge Base (Query-Matched)\n";
|
|
5503
|
+
combinedContext += "The following information is semantically relevant to the current query:\n\n";
|
|
5504
|
+
combinedContext += queryContext + "\n\n";
|
|
5505
|
+
}
|
|
5506
|
+
logger.info(`[KnowledgeBase] Combined knowledge base context: global=${globalContext.length} chars, user=${userContext.length} chars, query=${queryContext.length} chars`);
|
|
5507
|
+
return {
|
|
5508
|
+
globalContext,
|
|
5509
|
+
userContext,
|
|
5510
|
+
queryContext,
|
|
5511
|
+
combinedContext: combinedContext.trim()
|
|
5512
|
+
};
|
|
5513
|
+
};
|
|
5403
5514
|
var KB = {
|
|
5404
|
-
getKnowledgeBase
|
|
5515
|
+
getKnowledgeBase,
|
|
5516
|
+
getGlobalKnowledgeBase,
|
|
5517
|
+
getUserKnowledgeBase,
|
|
5518
|
+
getAllKnowledgeBase
|
|
5405
5519
|
};
|
|
5406
5520
|
var knowledge_base_default = KB;
|
|
5407
5521
|
|
|
@@ -6264,8 +6378,9 @@ ${executedToolsText}`);
|
|
|
6264
6378
|
* @param components - Optional list of available components for matching suggestions
|
|
6265
6379
|
* @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called
|
|
6266
6380
|
* @param category - Question category ('data_analysis' | 'data_modification' | 'general'). For data_modification, answer component streaming is skipped. For general, component generation is skipped entirely.
|
|
6381
|
+
* @param userId - Optional user ID for fetching user-specific knowledge base nodes
|
|
6267
6382
|
*/
|
|
6268
|
-
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category) {
|
|
6383
|
+
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category, userId) {
|
|
6269
6384
|
const errors = [];
|
|
6270
6385
|
logger.debug(`[${this.getProviderName()}] Starting text response generation`);
|
|
6271
6386
|
logger.debug(`[${this.getProviderName()}] User prompt: "${userPrompt.substring(0, 50)}..."`);
|
|
@@ -6314,11 +6429,13 @@ ${executedToolsText}`);
|
|
|
6314
6429
|
}
|
|
6315
6430
|
const schemaDoc = schema.generateSchemaDocumentation();
|
|
6316
6431
|
const databaseRules = await promptLoader.loadDatabaseRules();
|
|
6317
|
-
const
|
|
6432
|
+
const kbResult = await knowledge_base_default.getAllKnowledgeBase({
|
|
6318
6433
|
prompt: userPrompt,
|
|
6319
6434
|
collections,
|
|
6320
|
-
|
|
6435
|
+
userId,
|
|
6436
|
+
topK: 3
|
|
6321
6437
|
});
|
|
6438
|
+
const knowledgeBaseContext = kbResult.combinedContext;
|
|
6322
6439
|
const prompts = await promptLoader.loadPrompts("text-response", {
|
|
6323
6440
|
USER_PROMPT: userPrompt,
|
|
6324
6441
|
CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
|
|
@@ -6444,10 +6561,58 @@ ${executedToolsText}`);
|
|
|
6444
6561
|
const executedToolsList = [];
|
|
6445
6562
|
let maxAttemptsReached = false;
|
|
6446
6563
|
let fullStreamedText = "";
|
|
6564
|
+
let streamBuffer = "";
|
|
6565
|
+
let flushTimer = null;
|
|
6566
|
+
const FLUSH_INTERVAL = 50;
|
|
6567
|
+
const flushStreamBuffer = () => {
|
|
6568
|
+
if (streamBuffer && streamCallback) {
|
|
6569
|
+
streamCallback(streamBuffer);
|
|
6570
|
+
streamBuffer = "";
|
|
6571
|
+
}
|
|
6572
|
+
flushTimer = null;
|
|
6573
|
+
};
|
|
6447
6574
|
const wrappedStreamCallback = streamCallback ? (chunk) => {
|
|
6448
6575
|
fullStreamedText += chunk;
|
|
6449
|
-
|
|
6576
|
+
streamBuffer += chunk;
|
|
6577
|
+
if (chunk.includes("\n") || chunk.length > 100) {
|
|
6578
|
+
if (flushTimer) {
|
|
6579
|
+
clearTimeout(flushTimer);
|
|
6580
|
+
flushTimer = null;
|
|
6581
|
+
}
|
|
6582
|
+
flushStreamBuffer();
|
|
6583
|
+
} else if (!flushTimer) {
|
|
6584
|
+
flushTimer = setTimeout(flushStreamBuffer, FLUSH_INTERVAL);
|
|
6585
|
+
}
|
|
6450
6586
|
} : void 0;
|
|
6587
|
+
const flushStream = () => {
|
|
6588
|
+
if (flushTimer) {
|
|
6589
|
+
clearTimeout(flushTimer);
|
|
6590
|
+
flushTimer = null;
|
|
6591
|
+
}
|
|
6592
|
+
flushStreamBuffer();
|
|
6593
|
+
};
|
|
6594
|
+
const streamDelay = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6595
|
+
const withProgressHeartbeat = async (operation, progressMessage, intervalMs = 1e3) => {
|
|
6596
|
+
if (!wrappedStreamCallback) {
|
|
6597
|
+
return operation();
|
|
6598
|
+
}
|
|
6599
|
+
const startTime = Date.now();
|
|
6600
|
+
await streamDelay(30);
|
|
6601
|
+
wrappedStreamCallback(`\u23F3 ${progressMessage}`);
|
|
6602
|
+
const heartbeatInterval = setInterval(() => {
|
|
6603
|
+
const elapsedSeconds = Math.floor((Date.now() - startTime) / 1e3);
|
|
6604
|
+
if (elapsedSeconds >= 1) {
|
|
6605
|
+
wrappedStreamCallback(` (${elapsedSeconds}s)`);
|
|
6606
|
+
}
|
|
6607
|
+
}, intervalMs);
|
|
6608
|
+
try {
|
|
6609
|
+
const result2 = await operation();
|
|
6610
|
+
return result2;
|
|
6611
|
+
} finally {
|
|
6612
|
+
clearInterval(heartbeatInterval);
|
|
6613
|
+
wrappedStreamCallback("\n\n");
|
|
6614
|
+
}
|
|
6615
|
+
};
|
|
6451
6616
|
const toolHandler = async (toolName, toolInput) => {
|
|
6452
6617
|
if (toolName === "execute_query") {
|
|
6453
6618
|
let sql = toolInput.sql;
|
|
@@ -6482,6 +6647,7 @@ Please try rephrasing your question or simplifying your request.
|
|
|
6482
6647
|
throw new Error(errorMsg);
|
|
6483
6648
|
}
|
|
6484
6649
|
try {
|
|
6650
|
+
flushStream();
|
|
6485
6651
|
if (wrappedStreamCallback) {
|
|
6486
6652
|
const paramsDisplay = Object.keys(params).length > 0 ? `
|
|
6487
6653
|
**Parameters:** ${JSON.stringify(params)}` : "";
|
|
@@ -6491,10 +6657,12 @@ Please try rephrasing your question or simplifying your request.
|
|
|
6491
6657
|
\u{1F50D} **Analyzing your question...**
|
|
6492
6658
|
|
|
6493
6659
|
`);
|
|
6660
|
+
await streamDelay(50);
|
|
6494
6661
|
if (reasoning) {
|
|
6495
6662
|
wrappedStreamCallback(`\u{1F4AD} ${reasoning}
|
|
6496
6663
|
|
|
6497
6664
|
`);
|
|
6665
|
+
await streamDelay(50);
|
|
6498
6666
|
}
|
|
6499
6667
|
wrappedStreamCallback(`\u{1F4DD} **Generated SQL Query:**
|
|
6500
6668
|
\`\`\`sql
|
|
@@ -6502,19 +6670,19 @@ ${sql}
|
|
|
6502
6670
|
\`\`\`${paramsDisplay}
|
|
6503
6671
|
|
|
6504
6672
|
`);
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
`);
|
|
6673
|
+
await streamDelay(50);
|
|
6508
6674
|
} else {
|
|
6509
6675
|
wrappedStreamCallback(`
|
|
6510
6676
|
|
|
6511
6677
|
\u{1F504} **Retrying with corrected query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS})...**
|
|
6512
6678
|
|
|
6513
6679
|
`);
|
|
6680
|
+
await streamDelay(50);
|
|
6514
6681
|
if (reasoning) {
|
|
6515
6682
|
wrappedStreamCallback(`\u{1F4AD} ${reasoning}
|
|
6516
6683
|
|
|
6517
6684
|
`);
|
|
6685
|
+
await streamDelay(50);
|
|
6518
6686
|
}
|
|
6519
6687
|
wrappedStreamCallback(`\u{1F4DD} **Corrected SQL Query:**
|
|
6520
6688
|
\`\`\`sql
|
|
@@ -6522,9 +6690,7 @@ ${sql}
|
|
|
6522
6690
|
\`\`\`${paramsDisplay}
|
|
6523
6691
|
|
|
6524
6692
|
`);
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
`);
|
|
6693
|
+
await streamDelay(50);
|
|
6528
6694
|
}
|
|
6529
6695
|
}
|
|
6530
6696
|
logCollector?.logQuery(
|
|
@@ -6536,15 +6702,22 @@ ${sql}
|
|
|
6536
6702
|
throw new Error("Database collection not registered. Please register database.execute collection to execute queries.");
|
|
6537
6703
|
}
|
|
6538
6704
|
const queryPayload = Object.keys(params).length > 0 ? { sql: JSON.stringify({ sql, values: params }) } : { sql };
|
|
6539
|
-
const result2 = await
|
|
6705
|
+
const result2 = await withProgressHeartbeat(
|
|
6706
|
+
() => collections["database"]["execute"](queryPayload),
|
|
6707
|
+
"Executing database query",
|
|
6708
|
+
800
|
|
6709
|
+
// Send heartbeat every 800ms for responsive feedback
|
|
6710
|
+
);
|
|
6540
6711
|
const data = result2?.data || result2;
|
|
6541
6712
|
const rowCount = result2?.count ?? (Array.isArray(data) ? data.length : "N/A");
|
|
6542
6713
|
logger.info(`[${this.getProviderName()}] Query executed successfully, rows returned: ${rowCount}`);
|
|
6543
6714
|
logCollector?.info(`Query successful, returned ${rowCount} rows`);
|
|
6544
6715
|
if (wrappedStreamCallback) {
|
|
6545
|
-
wrappedStreamCallback(
|
|
6716
|
+
wrappedStreamCallback(`
|
|
6717
|
+
\u2705 **Query executed successfully!**
|
|
6546
6718
|
|
|
6547
6719
|
`);
|
|
6720
|
+
await streamDelay(50);
|
|
6548
6721
|
if (Array.isArray(data) && data.length > 0) {
|
|
6549
6722
|
const firstRow = data[0];
|
|
6550
6723
|
const columns = Object.keys(firstRow);
|
|
@@ -6553,18 +6726,22 @@ ${sql}
|
|
|
6553
6726
|
wrappedStreamCallback(`**Result:** ${value}
|
|
6554
6727
|
|
|
6555
6728
|
`);
|
|
6729
|
+
await streamDelay(50);
|
|
6556
6730
|
} else if (data.length > 0) {
|
|
6557
6731
|
wrappedStreamCallback(`**Retrieved ${rowCount} rows**
|
|
6558
6732
|
|
|
6559
6733
|
`);
|
|
6734
|
+
await streamDelay(50);
|
|
6560
6735
|
wrappedStreamCallback(`<DataTable>${JSON.stringify(data)}</DataTable>
|
|
6561
6736
|
|
|
6562
6737
|
`);
|
|
6738
|
+
await streamDelay(50);
|
|
6563
6739
|
}
|
|
6564
6740
|
} else if (Array.isArray(data) && data.length === 0) {
|
|
6565
6741
|
wrappedStreamCallback(`**No rows returned.**
|
|
6566
6742
|
|
|
6567
6743
|
`);
|
|
6744
|
+
await streamDelay(50);
|
|
6568
6745
|
}
|
|
6569
6746
|
wrappedStreamCallback(`\u{1F4CA} **Analyzing results...**
|
|
6570
6747
|
|
|
@@ -6614,6 +6791,7 @@ Please try rephrasing your request or contact support.
|
|
|
6614
6791
|
throw new Error(errorMsg);
|
|
6615
6792
|
}
|
|
6616
6793
|
try {
|
|
6794
|
+
flushStream();
|
|
6617
6795
|
if (wrappedStreamCallback) {
|
|
6618
6796
|
if (attempts === 1) {
|
|
6619
6797
|
wrappedStreamCallback(`
|
|
@@ -6628,8 +6806,14 @@ Please try rephrasing your request or contact support.
|
|
|
6628
6806
|
|
|
6629
6807
|
`);
|
|
6630
6808
|
}
|
|
6809
|
+
await streamDelay(50);
|
|
6631
6810
|
}
|
|
6632
|
-
const result2 = await
|
|
6811
|
+
const result2 = await withProgressHeartbeat(
|
|
6812
|
+
() => externalTool.fn(toolInput),
|
|
6813
|
+
`Running ${externalTool.name}`,
|
|
6814
|
+
800
|
|
6815
|
+
// Send heartbeat every 800ms
|
|
6816
|
+
);
|
|
6633
6817
|
logger.info(`[${this.getProviderName()}] External tool ${externalTool.name} executed successfully`);
|
|
6634
6818
|
logCollector?.info(`\u2713 ${externalTool.name} executed successfully`);
|
|
6635
6819
|
if (!executedToolsList.find((t) => t.id === externalTool.id)) {
|
|
@@ -6662,6 +6846,7 @@ Please try rephrasing your request or contact support.
|
|
|
6662
6846
|
wrappedStreamCallback(`\u2705 **${externalTool.name} completed successfully**
|
|
6663
6847
|
|
|
6664
6848
|
`);
|
|
6849
|
+
await streamDelay(50);
|
|
6665
6850
|
}
|
|
6666
6851
|
return JSON.stringify(result2, null, 2);
|
|
6667
6852
|
} catch (error) {
|
|
@@ -6730,7 +6915,9 @@ ${errorMsg}
|
|
|
6730
6915
|
textLength: textResponse.length
|
|
6731
6916
|
}
|
|
6732
6917
|
);
|
|
6918
|
+
flushStream();
|
|
6733
6919
|
if (wrappedStreamCallback && components && components.length > 0 && category !== "general") {
|
|
6920
|
+
wrappedStreamCallback("\n\n\u{1F4CA} **Generating visualization components...**\n\n");
|
|
6734
6921
|
wrappedStreamCallback("__TEXT_COMPLETE__COMPONENT_GENERATION_START__");
|
|
6735
6922
|
}
|
|
6736
6923
|
let matchedComponents = [];
|
|
@@ -7040,7 +7227,8 @@ ${errorMsg}
|
|
|
7040
7227
|
collections,
|
|
7041
7228
|
components,
|
|
7042
7229
|
toolsToUse,
|
|
7043
|
-
categoryClassification.category
|
|
7230
|
+
categoryClassification.category,
|
|
7231
|
+
userId
|
|
7044
7232
|
);
|
|
7045
7233
|
const elapsedTime = Date.now() - startTime;
|
|
7046
7234
|
logger.info(`[${this.getProviderName()}] Total time taken: ${elapsedTime}ms (${(elapsedTime / 1e3).toFixed(2)}s)`);
|
|
@@ -10113,6 +10301,182 @@ function sendResponse7(id, res, sendMessage, clientId) {
|
|
|
10113
10301
|
sendMessage(response);
|
|
10114
10302
|
}
|
|
10115
10303
|
|
|
10304
|
+
// src/handlers/artifacts.ts
|
|
10305
|
+
init_logger();
|
|
10306
|
+
async function handleArtifactsRequest(data, collections, sendMessage) {
|
|
10307
|
+
const executeCollection = async (collection, op, params) => {
|
|
10308
|
+
const handler = collections[collection]?.[op];
|
|
10309
|
+
if (!handler) {
|
|
10310
|
+
throw new Error(`Collection operation ${collection}.${op} not found`);
|
|
10311
|
+
}
|
|
10312
|
+
return await handler(params);
|
|
10313
|
+
};
|
|
10314
|
+
try {
|
|
10315
|
+
const request = ArtifactsRequestMessageSchema.parse(data);
|
|
10316
|
+
const { id, payload, from } = request;
|
|
10317
|
+
const { operation, data: requestData } = payload;
|
|
10318
|
+
const artifactId = requestData?.id;
|
|
10319
|
+
const name = requestData?.name;
|
|
10320
|
+
const createdBy = requestData?.createdBy;
|
|
10321
|
+
const dsl = requestData?.dsl;
|
|
10322
|
+
const status = requestData?.status;
|
|
10323
|
+
const deleted = requestData?.deleted;
|
|
10324
|
+
const limit = requestData?.limit;
|
|
10325
|
+
switch (operation) {
|
|
10326
|
+
case "create":
|
|
10327
|
+
await handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, from.id);
|
|
10328
|
+
break;
|
|
10329
|
+
case "update":
|
|
10330
|
+
await handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, from.id);
|
|
10331
|
+
break;
|
|
10332
|
+
case "delete":
|
|
10333
|
+
await handleDelete6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10334
|
+
break;
|
|
10335
|
+
case "getAll":
|
|
10336
|
+
await handleGetAll6(id, limit, executeCollection, sendMessage, from.id);
|
|
10337
|
+
break;
|
|
10338
|
+
case "getOne":
|
|
10339
|
+
await handleGetOne6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10340
|
+
break;
|
|
10341
|
+
default:
|
|
10342
|
+
sendResponse8(id, {
|
|
10343
|
+
success: false,
|
|
10344
|
+
error: `Unknown operation: ${operation}`
|
|
10345
|
+
}, sendMessage, from.id);
|
|
10346
|
+
}
|
|
10347
|
+
} catch (error) {
|
|
10348
|
+
logger.error("Failed to handle artifacts request:", error);
|
|
10349
|
+
sendResponse8(null, {
|
|
10350
|
+
success: false,
|
|
10351
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10352
|
+
}, sendMessage);
|
|
10353
|
+
}
|
|
10354
|
+
}
|
|
10355
|
+
async function handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, clientId) {
|
|
10356
|
+
if (!name) {
|
|
10357
|
+
sendResponse8(id, {
|
|
10358
|
+
success: false,
|
|
10359
|
+
error: "name is required"
|
|
10360
|
+
}, sendMessage, clientId);
|
|
10361
|
+
return;
|
|
10362
|
+
}
|
|
10363
|
+
try {
|
|
10364
|
+
const result = await executeCollection("artifacts", "create", { name, createdBy, dsl, status });
|
|
10365
|
+
sendResponse8(id, {
|
|
10366
|
+
success: true,
|
|
10367
|
+
data: result.data,
|
|
10368
|
+
message: "Artifact created successfully"
|
|
10369
|
+
}, sendMessage, clientId);
|
|
10370
|
+
logger.info(`Artifact created: ID ${result.data.id}`);
|
|
10371
|
+
} catch (error) {
|
|
10372
|
+
sendResponse8(id, {
|
|
10373
|
+
success: false,
|
|
10374
|
+
error: error instanceof Error ? error.message : "Failed to create artifact"
|
|
10375
|
+
}, sendMessage, clientId);
|
|
10376
|
+
}
|
|
10377
|
+
}
|
|
10378
|
+
async function handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, clientId) {
|
|
10379
|
+
if (!artifactId) {
|
|
10380
|
+
sendResponse8(id, {
|
|
10381
|
+
success: false,
|
|
10382
|
+
error: "Artifact ID is required"
|
|
10383
|
+
}, sendMessage, clientId);
|
|
10384
|
+
return;
|
|
10385
|
+
}
|
|
10386
|
+
try {
|
|
10387
|
+
const result = await executeCollection("artifacts", "update", { id: artifactId, name, dsl, status, deleted });
|
|
10388
|
+
sendResponse8(id, {
|
|
10389
|
+
success: true,
|
|
10390
|
+
data: result.data,
|
|
10391
|
+
message: "Artifact updated successfully"
|
|
10392
|
+
}, sendMessage, clientId);
|
|
10393
|
+
logger.info(`Artifact updated: ID ${artifactId}`);
|
|
10394
|
+
} catch (error) {
|
|
10395
|
+
sendResponse8(id, {
|
|
10396
|
+
success: false,
|
|
10397
|
+
error: error instanceof Error ? error.message : "Failed to update artifact"
|
|
10398
|
+
}, sendMessage, clientId);
|
|
10399
|
+
}
|
|
10400
|
+
}
|
|
10401
|
+
async function handleDelete6(id, artifactId, executeCollection, sendMessage, clientId) {
|
|
10402
|
+
if (!artifactId) {
|
|
10403
|
+
sendResponse8(id, {
|
|
10404
|
+
success: false,
|
|
10405
|
+
error: "Artifact ID is required"
|
|
10406
|
+
}, sendMessage, clientId);
|
|
10407
|
+
return;
|
|
10408
|
+
}
|
|
10409
|
+
try {
|
|
10410
|
+
const result = await executeCollection("artifacts", "delete", { id: artifactId });
|
|
10411
|
+
sendResponse8(id, {
|
|
10412
|
+
success: true,
|
|
10413
|
+
data: result.data,
|
|
10414
|
+
message: "Artifact deleted successfully"
|
|
10415
|
+
}, sendMessage, clientId);
|
|
10416
|
+
logger.info(`Artifact deleted: ID ${artifactId}`);
|
|
10417
|
+
} catch (error) {
|
|
10418
|
+
sendResponse8(id, {
|
|
10419
|
+
success: false,
|
|
10420
|
+
error: error instanceof Error ? error.message : "Failed to delete artifact"
|
|
10421
|
+
}, sendMessage, clientId);
|
|
10422
|
+
}
|
|
10423
|
+
}
|
|
10424
|
+
async function handleGetAll6(id, limit, executeCollection, sendMessage, clientId) {
|
|
10425
|
+
try {
|
|
10426
|
+
const result = await executeCollection("artifacts", "getAll", { limit });
|
|
10427
|
+
sendResponse8(id, {
|
|
10428
|
+
success: true,
|
|
10429
|
+
data: result.data,
|
|
10430
|
+
count: result.count,
|
|
10431
|
+
message: `Retrieved ${result.count} artifacts`
|
|
10432
|
+
}, sendMessage, clientId);
|
|
10433
|
+
logger.info(`Retrieved all artifacts (count: ${result.count})`);
|
|
10434
|
+
} catch (error) {
|
|
10435
|
+
sendResponse8(id, {
|
|
10436
|
+
success: false,
|
|
10437
|
+
error: error instanceof Error ? error.message : "Failed to get artifacts"
|
|
10438
|
+
}, sendMessage, clientId);
|
|
10439
|
+
}
|
|
10440
|
+
}
|
|
10441
|
+
async function handleGetOne6(id, artifactId, executeCollection, sendMessage, clientId) {
|
|
10442
|
+
if (!artifactId) {
|
|
10443
|
+
sendResponse8(id, {
|
|
10444
|
+
success: false,
|
|
10445
|
+
error: "Artifact ID is required"
|
|
10446
|
+
}, sendMessage, clientId);
|
|
10447
|
+
return;
|
|
10448
|
+
}
|
|
10449
|
+
try {
|
|
10450
|
+
const result = await executeCollection("artifacts", "getOne", { id: artifactId });
|
|
10451
|
+
sendResponse8(id, {
|
|
10452
|
+
success: true,
|
|
10453
|
+
data: result.data,
|
|
10454
|
+
message: `Retrieved artifact ID ${artifactId}`
|
|
10455
|
+
}, sendMessage, clientId);
|
|
10456
|
+
logger.info(`Retrieved artifact: ID ${artifactId}`);
|
|
10457
|
+
} catch (error) {
|
|
10458
|
+
sendResponse8(id, {
|
|
10459
|
+
success: false,
|
|
10460
|
+
error: error instanceof Error ? error.message : "Failed to get artifact"
|
|
10461
|
+
}, sendMessage, clientId);
|
|
10462
|
+
}
|
|
10463
|
+
}
|
|
10464
|
+
function sendResponse8(id, res, sendMessage, clientId) {
|
|
10465
|
+
const response = {
|
|
10466
|
+
id: id || "unknown",
|
|
10467
|
+
type: "ARTIFACTS_RES",
|
|
10468
|
+
from: { type: "data-agent" },
|
|
10469
|
+
to: {
|
|
10470
|
+
type: "user",
|
|
10471
|
+
id: clientId
|
|
10472
|
+
},
|
|
10473
|
+
payload: {
|
|
10474
|
+
...res
|
|
10475
|
+
}
|
|
10476
|
+
};
|
|
10477
|
+
sendMessage(response);
|
|
10478
|
+
}
|
|
10479
|
+
|
|
10116
10480
|
// src/handlers/kb-nodes.ts
|
|
10117
10481
|
init_logger();
|
|
10118
10482
|
async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
@@ -10132,6 +10496,7 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10132
10496
|
const content = requestData?.content;
|
|
10133
10497
|
const category = requestData?.category;
|
|
10134
10498
|
const tags = requestData?.tags;
|
|
10499
|
+
const type = requestData?.type;
|
|
10135
10500
|
const createdBy = requestData?.createdBy;
|
|
10136
10501
|
const updatedBy = requestData?.updatedBy;
|
|
10137
10502
|
const userId = requestData?.userId;
|
|
@@ -10141,22 +10506,22 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10141
10506
|
const offset = requestData?.offset;
|
|
10142
10507
|
switch (operation) {
|
|
10143
10508
|
case "create":
|
|
10144
|
-
await
|
|
10509
|
+
await handleCreate7(id, { title, content, category, tags, type, createdBy }, executeCollection, sendMessage, from.id);
|
|
10145
10510
|
break;
|
|
10146
10511
|
case "update":
|
|
10147
|
-
await
|
|
10512
|
+
await handleUpdate7(id, nodeId, { title, content, category, tags, type, updatedBy }, executeCollection, sendMessage, from.id);
|
|
10148
10513
|
break;
|
|
10149
10514
|
case "delete":
|
|
10150
|
-
await
|
|
10515
|
+
await handleDelete7(id, nodeId, executeCollection, sendMessage, from.id);
|
|
10151
10516
|
break;
|
|
10152
10517
|
case "getAll":
|
|
10153
|
-
await
|
|
10518
|
+
await handleGetAll7(id, limit, offset, executeCollection, sendMessage, from.id);
|
|
10154
10519
|
break;
|
|
10155
10520
|
case "getOne":
|
|
10156
|
-
await
|
|
10521
|
+
await handleGetOne7(id, nodeId, executeCollection, sendMessage, from.id);
|
|
10157
10522
|
break;
|
|
10158
10523
|
case "search":
|
|
10159
|
-
await handleSearch(id, { query, category, tags, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
10524
|
+
await handleSearch(id, { query, category, tags, type, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
10160
10525
|
break;
|
|
10161
10526
|
case "getByCategory":
|
|
10162
10527
|
await handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, from.id);
|
|
@@ -10171,37 +10536,37 @@ async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
|
10171
10536
|
await handleGetTags(id, executeCollection, sendMessage, from.id);
|
|
10172
10537
|
break;
|
|
10173
10538
|
default:
|
|
10174
|
-
|
|
10539
|
+
sendResponse9(id, {
|
|
10175
10540
|
success: false,
|
|
10176
10541
|
error: `Unknown operation: ${operation}`
|
|
10177
10542
|
}, sendMessage, from.id);
|
|
10178
10543
|
}
|
|
10179
10544
|
} catch (error) {
|
|
10180
10545
|
logger.error("Failed to handle KB nodes request:", error);
|
|
10181
|
-
|
|
10546
|
+
sendResponse9(null, {
|
|
10182
10547
|
success: false,
|
|
10183
10548
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10184
10549
|
}, sendMessage);
|
|
10185
10550
|
}
|
|
10186
10551
|
}
|
|
10187
|
-
async function
|
|
10188
|
-
const { title, content, category, tags, createdBy } = nodeData;
|
|
10552
|
+
async function handleCreate7(id, nodeData, executeCollection, sendMessage, clientId) {
|
|
10553
|
+
const { title, content, category, tags, type, createdBy } = nodeData;
|
|
10189
10554
|
if (!title || title.trim().length === 0) {
|
|
10190
|
-
|
|
10555
|
+
sendResponse9(id, {
|
|
10191
10556
|
success: false,
|
|
10192
10557
|
error: "Title is required and cannot be empty"
|
|
10193
10558
|
}, sendMessage, clientId);
|
|
10194
10559
|
return;
|
|
10195
10560
|
}
|
|
10196
10561
|
if (!content || content.trim().length === 0) {
|
|
10197
|
-
|
|
10562
|
+
sendResponse9(id, {
|
|
10198
10563
|
success: false,
|
|
10199
10564
|
error: "Content is required and cannot be empty"
|
|
10200
10565
|
}, sendMessage, clientId);
|
|
10201
10566
|
return;
|
|
10202
10567
|
}
|
|
10203
10568
|
if (!createdBy) {
|
|
10204
|
-
|
|
10569
|
+
sendResponse9(id, {
|
|
10205
10570
|
success: false,
|
|
10206
10571
|
error: "createdBy (user ID) is required"
|
|
10207
10572
|
}, sendMessage, clientId);
|
|
@@ -10213,11 +10578,12 @@ async function handleCreate6(id, nodeData, executeCollection, sendMessage, clien
|
|
|
10213
10578
|
content,
|
|
10214
10579
|
category: category || void 0,
|
|
10215
10580
|
tags: tags || void 0,
|
|
10581
|
+
type: type || "query",
|
|
10216
10582
|
createdBy
|
|
10217
10583
|
});
|
|
10218
10584
|
if (result && result.success) {
|
|
10219
10585
|
logger.info(`[DB] KB node created successfully: ${title}`);
|
|
10220
|
-
|
|
10586
|
+
sendResponse9(id, {
|
|
10221
10587
|
success: true,
|
|
10222
10588
|
data: {
|
|
10223
10589
|
...result.data,
|
|
@@ -10226,29 +10592,29 @@ async function handleCreate6(id, nodeData, executeCollection, sendMessage, clien
|
|
|
10226
10592
|
}, sendMessage, clientId);
|
|
10227
10593
|
return;
|
|
10228
10594
|
}
|
|
10229
|
-
|
|
10595
|
+
sendResponse9(id, {
|
|
10230
10596
|
success: false,
|
|
10231
10597
|
error: "Failed to create knowledge node"
|
|
10232
10598
|
}, sendMessage, clientId);
|
|
10233
10599
|
} catch (error) {
|
|
10234
10600
|
logger.error("[DB] Failed to create KB node:", error);
|
|
10235
|
-
|
|
10601
|
+
sendResponse9(id, {
|
|
10236
10602
|
success: false,
|
|
10237
10603
|
error: error instanceof Error ? error.message : "Failed to create knowledge node"
|
|
10238
10604
|
}, sendMessage, clientId);
|
|
10239
10605
|
}
|
|
10240
10606
|
}
|
|
10241
|
-
async function
|
|
10242
|
-
const { title, content, category, tags, updatedBy } = nodeData;
|
|
10607
|
+
async function handleUpdate7(id, nodeId, nodeData, executeCollection, sendMessage, clientId) {
|
|
10608
|
+
const { title, content, category, tags, type, updatedBy } = nodeData;
|
|
10243
10609
|
if (!nodeId) {
|
|
10244
|
-
|
|
10610
|
+
sendResponse9(id, {
|
|
10245
10611
|
success: false,
|
|
10246
10612
|
error: "Knowledge node ID is required"
|
|
10247
10613
|
}, sendMessage, clientId);
|
|
10248
10614
|
return;
|
|
10249
10615
|
}
|
|
10250
10616
|
if (!updatedBy) {
|
|
10251
|
-
|
|
10617
|
+
sendResponse9(id, {
|
|
10252
10618
|
success: false,
|
|
10253
10619
|
error: "updatedBy (user ID) is required"
|
|
10254
10620
|
}, sendMessage, clientId);
|
|
@@ -10261,11 +10627,12 @@ async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessag
|
|
|
10261
10627
|
content,
|
|
10262
10628
|
category,
|
|
10263
10629
|
tags,
|
|
10630
|
+
type,
|
|
10264
10631
|
updatedBy
|
|
10265
10632
|
});
|
|
10266
10633
|
if (result && result.success) {
|
|
10267
10634
|
logger.info(`[DB] KB node updated successfully, ID: ${nodeId}`);
|
|
10268
|
-
|
|
10635
|
+
sendResponse9(id, {
|
|
10269
10636
|
success: true,
|
|
10270
10637
|
data: {
|
|
10271
10638
|
...result.data,
|
|
@@ -10274,21 +10641,21 @@ async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessag
|
|
|
10274
10641
|
}, sendMessage, clientId);
|
|
10275
10642
|
return;
|
|
10276
10643
|
}
|
|
10277
|
-
|
|
10644
|
+
sendResponse9(id, {
|
|
10278
10645
|
success: false,
|
|
10279
10646
|
error: "Failed to update knowledge node"
|
|
10280
10647
|
}, sendMessage, clientId);
|
|
10281
10648
|
} catch (error) {
|
|
10282
10649
|
logger.error("[DB] Failed to update KB node:", error);
|
|
10283
|
-
|
|
10650
|
+
sendResponse9(id, {
|
|
10284
10651
|
success: false,
|
|
10285
10652
|
error: error instanceof Error ? error.message : "Failed to update knowledge node"
|
|
10286
10653
|
}, sendMessage, clientId);
|
|
10287
10654
|
}
|
|
10288
10655
|
}
|
|
10289
|
-
async function
|
|
10656
|
+
async function handleDelete7(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
10290
10657
|
if (!nodeId) {
|
|
10291
|
-
|
|
10658
|
+
sendResponse9(id, {
|
|
10292
10659
|
success: false,
|
|
10293
10660
|
error: "Knowledge node ID is required"
|
|
10294
10661
|
}, sendMessage, clientId);
|
|
@@ -10298,7 +10665,7 @@ async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10298
10665
|
const result = await executeCollection("kbNodes", "delete", { id: nodeId });
|
|
10299
10666
|
if (result && result.success) {
|
|
10300
10667
|
logger.info(`[DB] KB node deleted successfully, ID: ${nodeId}`);
|
|
10301
|
-
|
|
10668
|
+
sendResponse9(id, {
|
|
10302
10669
|
success: true,
|
|
10303
10670
|
data: {
|
|
10304
10671
|
id: nodeId,
|
|
@@ -10308,19 +10675,19 @@ async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10308
10675
|
}, sendMessage, clientId);
|
|
10309
10676
|
return;
|
|
10310
10677
|
}
|
|
10311
|
-
|
|
10678
|
+
sendResponse9(id, {
|
|
10312
10679
|
success: false,
|
|
10313
10680
|
error: "Failed to delete knowledge node"
|
|
10314
10681
|
}, sendMessage, clientId);
|
|
10315
10682
|
} catch (error) {
|
|
10316
10683
|
logger.error("[DB] Failed to delete KB node:", error);
|
|
10317
|
-
|
|
10684
|
+
sendResponse9(id, {
|
|
10318
10685
|
success: false,
|
|
10319
10686
|
error: error instanceof Error ? error.message : "Failed to delete knowledge node"
|
|
10320
10687
|
}, sendMessage, clientId);
|
|
10321
10688
|
}
|
|
10322
10689
|
}
|
|
10323
|
-
async function
|
|
10690
|
+
async function handleGetAll7(id, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10324
10691
|
try {
|
|
10325
10692
|
const result = await executeCollection("kbNodes", "getAll", {
|
|
10326
10693
|
limit: limit || 100,
|
|
@@ -10328,7 +10695,7 @@ async function handleGetAll6(id, limit, offset, executeCollection, sendMessage,
|
|
|
10328
10695
|
});
|
|
10329
10696
|
if (result && result.success) {
|
|
10330
10697
|
logger.info(`[DB] Retrieved ${result.count} KB nodes`);
|
|
10331
|
-
|
|
10698
|
+
sendResponse9(id, {
|
|
10332
10699
|
success: true,
|
|
10333
10700
|
data: {
|
|
10334
10701
|
nodes: result.data,
|
|
@@ -10338,21 +10705,21 @@ async function handleGetAll6(id, limit, offset, executeCollection, sendMessage,
|
|
|
10338
10705
|
}, sendMessage, clientId);
|
|
10339
10706
|
return;
|
|
10340
10707
|
}
|
|
10341
|
-
|
|
10708
|
+
sendResponse9(id, {
|
|
10342
10709
|
success: false,
|
|
10343
10710
|
error: "Failed to retrieve knowledge nodes"
|
|
10344
10711
|
}, sendMessage, clientId);
|
|
10345
10712
|
} catch (error) {
|
|
10346
10713
|
logger.error("[DB] Failed to get all KB nodes:", error);
|
|
10347
|
-
|
|
10714
|
+
sendResponse9(id, {
|
|
10348
10715
|
success: false,
|
|
10349
10716
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes"
|
|
10350
10717
|
}, sendMessage, clientId);
|
|
10351
10718
|
}
|
|
10352
10719
|
}
|
|
10353
|
-
async function
|
|
10720
|
+
async function handleGetOne7(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
10354
10721
|
if (!nodeId) {
|
|
10355
|
-
|
|
10722
|
+
sendResponse9(id, {
|
|
10356
10723
|
success: false,
|
|
10357
10724
|
error: "Knowledge node ID is required"
|
|
10358
10725
|
}, sendMessage, clientId);
|
|
@@ -10362,7 +10729,7 @@ async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10362
10729
|
const result = await executeCollection("kbNodes", "getOne", { id: nodeId });
|
|
10363
10730
|
if (result && result.success) {
|
|
10364
10731
|
logger.info(`[DB] Retrieved KB node ID: ${nodeId}`);
|
|
10365
|
-
|
|
10732
|
+
sendResponse9(id, {
|
|
10366
10733
|
success: true,
|
|
10367
10734
|
data: {
|
|
10368
10735
|
node: result.data,
|
|
@@ -10371,32 +10738,33 @@ async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientI
|
|
|
10371
10738
|
}, sendMessage, clientId);
|
|
10372
10739
|
return;
|
|
10373
10740
|
}
|
|
10374
|
-
|
|
10741
|
+
sendResponse9(id, {
|
|
10375
10742
|
success: false,
|
|
10376
10743
|
error: "Failed to retrieve knowledge node"
|
|
10377
10744
|
}, sendMessage, clientId);
|
|
10378
10745
|
} catch (error) {
|
|
10379
10746
|
logger.error("[DB] Failed to get KB node:", error);
|
|
10380
|
-
|
|
10747
|
+
sendResponse9(id, {
|
|
10381
10748
|
success: false,
|
|
10382
10749
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge node"
|
|
10383
10750
|
}, sendMessage, clientId);
|
|
10384
10751
|
}
|
|
10385
10752
|
}
|
|
10386
10753
|
async function handleSearch(id, searchParams, executeCollection, sendMessage, clientId) {
|
|
10387
|
-
const { query, category, tags, createdBy, limit, offset } = searchParams;
|
|
10754
|
+
const { query, category, tags, type, createdBy, limit, offset } = searchParams;
|
|
10388
10755
|
try {
|
|
10389
10756
|
const result = await executeCollection("kbNodes", "search", {
|
|
10390
10757
|
query,
|
|
10391
10758
|
category,
|
|
10392
10759
|
tags,
|
|
10760
|
+
type,
|
|
10393
10761
|
createdBy,
|
|
10394
10762
|
limit: limit || 50,
|
|
10395
10763
|
offset: offset || 0
|
|
10396
10764
|
});
|
|
10397
10765
|
if (result && result.success) {
|
|
10398
10766
|
logger.info(`[DB] Search returned ${result.count} KB nodes`);
|
|
10399
|
-
|
|
10767
|
+
sendResponse9(id, {
|
|
10400
10768
|
success: true,
|
|
10401
10769
|
data: {
|
|
10402
10770
|
nodes: result.data,
|
|
@@ -10406,13 +10774,13 @@ async function handleSearch(id, searchParams, executeCollection, sendMessage, cl
|
|
|
10406
10774
|
}, sendMessage, clientId);
|
|
10407
10775
|
return;
|
|
10408
10776
|
}
|
|
10409
|
-
|
|
10777
|
+
sendResponse9(id, {
|
|
10410
10778
|
success: false,
|
|
10411
10779
|
error: "Failed to search knowledge nodes"
|
|
10412
10780
|
}, sendMessage, clientId);
|
|
10413
10781
|
} catch (error) {
|
|
10414
10782
|
logger.error("[DB] Failed to search KB nodes:", error);
|
|
10415
|
-
|
|
10783
|
+
sendResponse9(id, {
|
|
10416
10784
|
success: false,
|
|
10417
10785
|
error: error instanceof Error ? error.message : "Failed to search knowledge nodes"
|
|
10418
10786
|
}, sendMessage, clientId);
|
|
@@ -10420,7 +10788,7 @@ async function handleSearch(id, searchParams, executeCollection, sendMessage, cl
|
|
|
10420
10788
|
}
|
|
10421
10789
|
async function handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10422
10790
|
if (!category) {
|
|
10423
|
-
|
|
10791
|
+
sendResponse9(id, {
|
|
10424
10792
|
success: false,
|
|
10425
10793
|
error: "Category is required"
|
|
10426
10794
|
}, sendMessage, clientId);
|
|
@@ -10434,7 +10802,7 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10434
10802
|
});
|
|
10435
10803
|
if (result && result.success) {
|
|
10436
10804
|
logger.info(`[DB] Retrieved ${result.count} KB nodes for category: ${category}`);
|
|
10437
|
-
|
|
10805
|
+
sendResponse9(id, {
|
|
10438
10806
|
success: true,
|
|
10439
10807
|
data: {
|
|
10440
10808
|
nodes: result.data,
|
|
@@ -10445,13 +10813,13 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10445
10813
|
}, sendMessage, clientId);
|
|
10446
10814
|
return;
|
|
10447
10815
|
}
|
|
10448
|
-
|
|
10816
|
+
sendResponse9(id, {
|
|
10449
10817
|
success: false,
|
|
10450
10818
|
error: "Failed to retrieve knowledge nodes by category"
|
|
10451
10819
|
}, sendMessage, clientId);
|
|
10452
10820
|
} catch (error) {
|
|
10453
10821
|
logger.error("[DB] Failed to get KB nodes by category:", error);
|
|
10454
|
-
|
|
10822
|
+
sendResponse9(id, {
|
|
10455
10823
|
success: false,
|
|
10456
10824
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by category"
|
|
10457
10825
|
}, sendMessage, clientId);
|
|
@@ -10459,7 +10827,7 @@ async function handleGetByCategory(id, category, limit, offset, executeCollectio
|
|
|
10459
10827
|
}
|
|
10460
10828
|
async function handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, clientId) {
|
|
10461
10829
|
if (!userId) {
|
|
10462
|
-
|
|
10830
|
+
sendResponse9(id, {
|
|
10463
10831
|
success: false,
|
|
10464
10832
|
error: "User ID is required"
|
|
10465
10833
|
}, sendMessage, clientId);
|
|
@@ -10473,7 +10841,7 @@ async function handleGetByUser(id, userId, limit, offset, executeCollection, sen
|
|
|
10473
10841
|
});
|
|
10474
10842
|
if (result && result.success) {
|
|
10475
10843
|
logger.info(`[DB] Retrieved ${result.count} KB nodes for user: ${userId}`);
|
|
10476
|
-
|
|
10844
|
+
sendResponse9(id, {
|
|
10477
10845
|
success: true,
|
|
10478
10846
|
data: {
|
|
10479
10847
|
nodes: result.data,
|
|
@@ -10484,13 +10852,13 @@ async function handleGetByUser(id, userId, limit, offset, executeCollection, sen
|
|
|
10484
10852
|
}, sendMessage, clientId);
|
|
10485
10853
|
return;
|
|
10486
10854
|
}
|
|
10487
|
-
|
|
10855
|
+
sendResponse9(id, {
|
|
10488
10856
|
success: false,
|
|
10489
10857
|
error: "Failed to retrieve knowledge nodes by user"
|
|
10490
10858
|
}, sendMessage, clientId);
|
|
10491
10859
|
} catch (error) {
|
|
10492
10860
|
logger.error("[DB] Failed to get KB nodes by user:", error);
|
|
10493
|
-
|
|
10861
|
+
sendResponse9(id, {
|
|
10494
10862
|
success: false,
|
|
10495
10863
|
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by user"
|
|
10496
10864
|
}, sendMessage, clientId);
|
|
@@ -10501,7 +10869,7 @@ async function handleGetCategories(id, executeCollection, sendMessage, clientId)
|
|
|
10501
10869
|
const result = await executeCollection("kbNodes", "getCategories", {});
|
|
10502
10870
|
if (result && result.success) {
|
|
10503
10871
|
logger.info(`[DB] Retrieved ${result.count} categories`);
|
|
10504
|
-
|
|
10872
|
+
sendResponse9(id, {
|
|
10505
10873
|
success: true,
|
|
10506
10874
|
data: {
|
|
10507
10875
|
categories: result.data,
|
|
@@ -10511,13 +10879,13 @@ async function handleGetCategories(id, executeCollection, sendMessage, clientId)
|
|
|
10511
10879
|
}, sendMessage, clientId);
|
|
10512
10880
|
return;
|
|
10513
10881
|
}
|
|
10514
|
-
|
|
10882
|
+
sendResponse9(id, {
|
|
10515
10883
|
success: false,
|
|
10516
10884
|
error: "Failed to retrieve categories"
|
|
10517
10885
|
}, sendMessage, clientId);
|
|
10518
10886
|
} catch (error) {
|
|
10519
10887
|
logger.error("[DB] Failed to get categories:", error);
|
|
10520
|
-
|
|
10888
|
+
sendResponse9(id, {
|
|
10521
10889
|
success: false,
|
|
10522
10890
|
error: error instanceof Error ? error.message : "Failed to retrieve categories"
|
|
10523
10891
|
}, sendMessage, clientId);
|
|
@@ -10528,7 +10896,7 @@ async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
|
10528
10896
|
const result = await executeCollection("kbNodes", "getTags", {});
|
|
10529
10897
|
if (result && result.success) {
|
|
10530
10898
|
logger.info(`[DB] Retrieved ${result.count} tags`);
|
|
10531
|
-
|
|
10899
|
+
sendResponse9(id, {
|
|
10532
10900
|
success: true,
|
|
10533
10901
|
data: {
|
|
10534
10902
|
tags: result.data,
|
|
@@ -10538,19 +10906,19 @@ async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
|
10538
10906
|
}, sendMessage, clientId);
|
|
10539
10907
|
return;
|
|
10540
10908
|
}
|
|
10541
|
-
|
|
10909
|
+
sendResponse9(id, {
|
|
10542
10910
|
success: false,
|
|
10543
10911
|
error: "Failed to retrieve tags"
|
|
10544
10912
|
}, sendMessage, clientId);
|
|
10545
10913
|
} catch (error) {
|
|
10546
10914
|
logger.error("[DB] Failed to get tags:", error);
|
|
10547
|
-
|
|
10915
|
+
sendResponse9(id, {
|
|
10548
10916
|
success: false,
|
|
10549
10917
|
error: error instanceof Error ? error.message : "Failed to retrieve tags"
|
|
10550
10918
|
}, sendMessage, clientId);
|
|
10551
10919
|
}
|
|
10552
10920
|
}
|
|
10553
|
-
function
|
|
10921
|
+
function sendResponse9(id, res, sendMessage, clientId) {
|
|
10554
10922
|
const response = {
|
|
10555
10923
|
id: id || "unknown",
|
|
10556
10924
|
type: "KB_NODES_RES",
|
|
@@ -10595,19 +10963,19 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10595
10963
|
const items = requestData?.items;
|
|
10596
10964
|
switch (operation) {
|
|
10597
10965
|
case "create":
|
|
10598
|
-
await
|
|
10966
|
+
await handleCreate8(id, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, from.id);
|
|
10599
10967
|
break;
|
|
10600
10968
|
case "update":
|
|
10601
|
-
await
|
|
10969
|
+
await handleUpdate8(id, menuId, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, from.id);
|
|
10602
10970
|
break;
|
|
10603
10971
|
case "delete":
|
|
10604
|
-
await
|
|
10972
|
+
await handleDelete8(id, menuId, executeCollection, sendMessage, from.id);
|
|
10605
10973
|
break;
|
|
10606
10974
|
case "getAll":
|
|
10607
|
-
await
|
|
10975
|
+
await handleGetAll8(id, executeCollection, sendMessage, from.id);
|
|
10608
10976
|
break;
|
|
10609
10977
|
case "getOne":
|
|
10610
|
-
await
|
|
10978
|
+
await handleGetOne8(id, menuId, executeCollection, sendMessage, from.id);
|
|
10611
10979
|
break;
|
|
10612
10980
|
case "getRootMenus":
|
|
10613
10981
|
await handleGetRootMenus(id, executeCollection, sendMessage, from.id);
|
|
@@ -10625,29 +10993,29 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10625
10993
|
await handleReorder(id, items, executeCollection, sendMessage, from.id);
|
|
10626
10994
|
break;
|
|
10627
10995
|
default:
|
|
10628
|
-
|
|
10996
|
+
sendResponse10(id, {
|
|
10629
10997
|
success: false,
|
|
10630
10998
|
error: `Unknown operation: ${operation}`
|
|
10631
10999
|
}, sendMessage, from.id);
|
|
10632
11000
|
}
|
|
10633
11001
|
} catch (error) {
|
|
10634
11002
|
logger.error("Failed to handle menus request:", error);
|
|
10635
|
-
|
|
11003
|
+
sendResponse10(null, {
|
|
10636
11004
|
success: false,
|
|
10637
11005
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
10638
11006
|
}, sendMessage);
|
|
10639
11007
|
}
|
|
10640
11008
|
}
|
|
10641
|
-
async function
|
|
11009
|
+
async function handleCreate8(id, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, clientId) {
|
|
10642
11010
|
if (!name) {
|
|
10643
|
-
|
|
11011
|
+
sendResponse10(id, {
|
|
10644
11012
|
success: false,
|
|
10645
11013
|
error: "name is required"
|
|
10646
11014
|
}, sendMessage, clientId);
|
|
10647
11015
|
return;
|
|
10648
11016
|
}
|
|
10649
11017
|
if (!componentName) {
|
|
10650
|
-
|
|
11018
|
+
sendResponse10(id, {
|
|
10651
11019
|
success: false,
|
|
10652
11020
|
error: "componentName is required"
|
|
10653
11021
|
}, sendMessage, clientId);
|
|
@@ -10664,22 +11032,22 @@ async function handleCreate7(id, name, componentName, icon, userMessage, parentI
|
|
|
10664
11032
|
props,
|
|
10665
11033
|
isActive
|
|
10666
11034
|
});
|
|
10667
|
-
|
|
11035
|
+
sendResponse10(id, {
|
|
10668
11036
|
success: true,
|
|
10669
11037
|
data: result.data,
|
|
10670
11038
|
message: "Menu created successfully"
|
|
10671
11039
|
}, sendMessage, clientId);
|
|
10672
11040
|
logger.info(`Menu created: ID ${result.data?.id}`);
|
|
10673
11041
|
} catch (error) {
|
|
10674
|
-
|
|
11042
|
+
sendResponse10(id, {
|
|
10675
11043
|
success: false,
|
|
10676
11044
|
error: error instanceof Error ? error.message : "Failed to create menu"
|
|
10677
11045
|
}, sendMessage, clientId);
|
|
10678
11046
|
}
|
|
10679
11047
|
}
|
|
10680
|
-
async function
|
|
11048
|
+
async function handleUpdate8(id, menuId, name, componentName, icon, userMessage, parentId, sortOrder, props, isActive, executeCollection, sendMessage, clientId) {
|
|
10681
11049
|
if (!menuId) {
|
|
10682
|
-
|
|
11050
|
+
sendResponse10(id, {
|
|
10683
11051
|
success: false,
|
|
10684
11052
|
error: "Menu ID is required"
|
|
10685
11053
|
}, sendMessage, clientId);
|
|
@@ -10697,22 +11065,22 @@ async function handleUpdate7(id, menuId, name, componentName, icon, userMessage,
|
|
|
10697
11065
|
props,
|
|
10698
11066
|
isActive
|
|
10699
11067
|
});
|
|
10700
|
-
|
|
11068
|
+
sendResponse10(id, {
|
|
10701
11069
|
success: true,
|
|
10702
11070
|
data: result.data,
|
|
10703
11071
|
message: "Menu updated successfully"
|
|
10704
11072
|
}, sendMessage, clientId);
|
|
10705
11073
|
logger.info(`Menu updated: ID ${menuId}`);
|
|
10706
11074
|
} catch (error) {
|
|
10707
|
-
|
|
11075
|
+
sendResponse10(id, {
|
|
10708
11076
|
success: false,
|
|
10709
11077
|
error: error instanceof Error ? error.message : "Failed to update menu"
|
|
10710
11078
|
}, sendMessage, clientId);
|
|
10711
11079
|
}
|
|
10712
11080
|
}
|
|
10713
|
-
async function
|
|
11081
|
+
async function handleDelete8(id, menuId, executeCollection, sendMessage, clientId) {
|
|
10714
11082
|
if (!menuId) {
|
|
10715
|
-
|
|
11083
|
+
sendResponse10(id, {
|
|
10716
11084
|
success: false,
|
|
10717
11085
|
error: "Menu ID is required"
|
|
10718
11086
|
}, sendMessage, clientId);
|
|
@@ -10720,23 +11088,23 @@ async function handleDelete7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10720
11088
|
}
|
|
10721
11089
|
try {
|
|
10722
11090
|
const result = await executeCollection("menus", "delete", { id: menuId });
|
|
10723
|
-
|
|
11091
|
+
sendResponse10(id, {
|
|
10724
11092
|
success: true,
|
|
10725
11093
|
data: result.data,
|
|
10726
11094
|
message: "Menu deleted successfully"
|
|
10727
11095
|
}, sendMessage, clientId);
|
|
10728
11096
|
logger.info(`Menu deleted: ID ${menuId}`);
|
|
10729
11097
|
} catch (error) {
|
|
10730
|
-
|
|
11098
|
+
sendResponse10(id, {
|
|
10731
11099
|
success: false,
|
|
10732
11100
|
error: error instanceof Error ? error.message : "Failed to delete menu"
|
|
10733
11101
|
}, sendMessage, clientId);
|
|
10734
11102
|
}
|
|
10735
11103
|
}
|
|
10736
|
-
async function
|
|
11104
|
+
async function handleGetAll8(id, executeCollection, sendMessage, clientId) {
|
|
10737
11105
|
try {
|
|
10738
11106
|
const result = await executeCollection("menus", "getAll", {});
|
|
10739
|
-
|
|
11107
|
+
sendResponse10(id, {
|
|
10740
11108
|
success: true,
|
|
10741
11109
|
data: result.data,
|
|
10742
11110
|
count: result.count,
|
|
@@ -10744,15 +11112,15 @@ async function handleGetAll7(id, executeCollection, sendMessage, clientId) {
|
|
|
10744
11112
|
}, sendMessage, clientId);
|
|
10745
11113
|
logger.info(`Retrieved all menus (count: ${result.count})`);
|
|
10746
11114
|
} catch (error) {
|
|
10747
|
-
|
|
11115
|
+
sendResponse10(id, {
|
|
10748
11116
|
success: false,
|
|
10749
11117
|
error: error instanceof Error ? error.message : "Failed to get menus"
|
|
10750
11118
|
}, sendMessage, clientId);
|
|
10751
11119
|
}
|
|
10752
11120
|
}
|
|
10753
|
-
async function
|
|
11121
|
+
async function handleGetOne8(id, menuId, executeCollection, sendMessage, clientId) {
|
|
10754
11122
|
if (!menuId) {
|
|
10755
|
-
|
|
11123
|
+
sendResponse10(id, {
|
|
10756
11124
|
success: false,
|
|
10757
11125
|
error: "Menu ID is required"
|
|
10758
11126
|
}, sendMessage, clientId);
|
|
@@ -10760,14 +11128,14 @@ async function handleGetOne7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10760
11128
|
}
|
|
10761
11129
|
try {
|
|
10762
11130
|
const result = await executeCollection("menus", "getOne", { id: menuId });
|
|
10763
|
-
|
|
11131
|
+
sendResponse10(id, {
|
|
10764
11132
|
success: true,
|
|
10765
11133
|
data: result.data,
|
|
10766
11134
|
message: `Retrieved menu ID ${menuId}`
|
|
10767
11135
|
}, sendMessage, clientId);
|
|
10768
11136
|
logger.info(`Retrieved menu: ID ${menuId}`);
|
|
10769
11137
|
} catch (error) {
|
|
10770
|
-
|
|
11138
|
+
sendResponse10(id, {
|
|
10771
11139
|
success: false,
|
|
10772
11140
|
error: error instanceof Error ? error.message : "Failed to get menu"
|
|
10773
11141
|
}, sendMessage, clientId);
|
|
@@ -10776,7 +11144,7 @@ async function handleGetOne7(id, menuId, executeCollection, sendMessage, clientI
|
|
|
10776
11144
|
async function handleGetRootMenus(id, executeCollection, sendMessage, clientId) {
|
|
10777
11145
|
try {
|
|
10778
11146
|
const result = await executeCollection("menus", "getRootMenus", {});
|
|
10779
|
-
|
|
11147
|
+
sendResponse10(id, {
|
|
10780
11148
|
success: true,
|
|
10781
11149
|
data: result.data,
|
|
10782
11150
|
count: result.count,
|
|
@@ -10784,7 +11152,7 @@ async function handleGetRootMenus(id, executeCollection, sendMessage, clientId)
|
|
|
10784
11152
|
}, sendMessage, clientId);
|
|
10785
11153
|
logger.info(`Retrieved root menus (count: ${result.count})`);
|
|
10786
11154
|
} catch (error) {
|
|
10787
|
-
|
|
11155
|
+
sendResponse10(id, {
|
|
10788
11156
|
success: false,
|
|
10789
11157
|
error: error instanceof Error ? error.message : "Failed to get root menus"
|
|
10790
11158
|
}, sendMessage, clientId);
|
|
@@ -10792,7 +11160,7 @@ async function handleGetRootMenus(id, executeCollection, sendMessage, clientId)
|
|
|
10792
11160
|
}
|
|
10793
11161
|
async function handleGetChildMenus(id, parentId, executeCollection, sendMessage, clientId) {
|
|
10794
11162
|
if (parentId === void 0 || parentId === null) {
|
|
10795
|
-
|
|
11163
|
+
sendResponse10(id, {
|
|
10796
11164
|
success: false,
|
|
10797
11165
|
error: "parentId is required"
|
|
10798
11166
|
}, sendMessage, clientId);
|
|
@@ -10800,7 +11168,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10800
11168
|
}
|
|
10801
11169
|
try {
|
|
10802
11170
|
const result = await executeCollection("menus", "getChildMenus", { parentId });
|
|
10803
|
-
|
|
11171
|
+
sendResponse10(id, {
|
|
10804
11172
|
success: true,
|
|
10805
11173
|
data: result.data,
|
|
10806
11174
|
count: result.count,
|
|
@@ -10808,7 +11176,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10808
11176
|
}, sendMessage, clientId);
|
|
10809
11177
|
logger.info(`Retrieved child menus for parent ${parentId} (count: ${result.count})`);
|
|
10810
11178
|
} catch (error) {
|
|
10811
|
-
|
|
11179
|
+
sendResponse10(id, {
|
|
10812
11180
|
success: false,
|
|
10813
11181
|
error: error instanceof Error ? error.message : "Failed to get child menus"
|
|
10814
11182
|
}, sendMessage, clientId);
|
|
@@ -10817,7 +11185,7 @@ async function handleGetChildMenus(id, parentId, executeCollection, sendMessage,
|
|
|
10817
11185
|
async function handleGetHierarchy(id, executeCollection, sendMessage, clientId) {
|
|
10818
11186
|
try {
|
|
10819
11187
|
const result = await executeCollection("menus", "getHierarchy", {});
|
|
10820
|
-
|
|
11188
|
+
sendResponse10(id, {
|
|
10821
11189
|
success: true,
|
|
10822
11190
|
data: result.data,
|
|
10823
11191
|
count: result.count,
|
|
@@ -10825,7 +11193,7 @@ async function handleGetHierarchy(id, executeCollection, sendMessage, clientId)
|
|
|
10825
11193
|
}, sendMessage, clientId);
|
|
10826
11194
|
logger.info(`Retrieved menus hierarchy (root count: ${result.count})`);
|
|
10827
11195
|
} catch (error) {
|
|
10828
|
-
|
|
11196
|
+
sendResponse10(id, {
|
|
10829
11197
|
success: false,
|
|
10830
11198
|
error: error instanceof Error ? error.message : "Failed to get menus hierarchy"
|
|
10831
11199
|
}, sendMessage, clientId);
|
|
@@ -10838,7 +11206,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10838
11206
|
limit,
|
|
10839
11207
|
sort
|
|
10840
11208
|
});
|
|
10841
|
-
|
|
11209
|
+
sendResponse10(id, {
|
|
10842
11210
|
success: true,
|
|
10843
11211
|
data: result.data,
|
|
10844
11212
|
count: result.count,
|
|
@@ -10846,7 +11214,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10846
11214
|
}, sendMessage, clientId);
|
|
10847
11215
|
logger.info(`Query returned ${result.count} menus`);
|
|
10848
11216
|
} catch (error) {
|
|
10849
|
-
|
|
11217
|
+
sendResponse10(id, {
|
|
10850
11218
|
success: false,
|
|
10851
11219
|
error: error instanceof Error ? error.message : "Failed to query menus"
|
|
10852
11220
|
}, sendMessage, clientId);
|
|
@@ -10854,7 +11222,7 @@ async function handleQuery6(id, filters, limit, sort, executeCollection, sendMes
|
|
|
10854
11222
|
}
|
|
10855
11223
|
async function handleReorder(id, items, executeCollection, sendMessage, clientId) {
|
|
10856
11224
|
if (!items || !Array.isArray(items) || items.length === 0) {
|
|
10857
|
-
|
|
11225
|
+
sendResponse10(id, {
|
|
10858
11226
|
success: false,
|
|
10859
11227
|
error: "items array is required"
|
|
10860
11228
|
}, sendMessage, clientId);
|
|
@@ -10862,20 +11230,20 @@ async function handleReorder(id, items, executeCollection, sendMessage, clientId
|
|
|
10862
11230
|
}
|
|
10863
11231
|
try {
|
|
10864
11232
|
const result = await executeCollection("menus", "reorder", { items });
|
|
10865
|
-
|
|
11233
|
+
sendResponse10(id, {
|
|
10866
11234
|
success: true,
|
|
10867
11235
|
data: result.data,
|
|
10868
11236
|
message: `Reordered ${items.length} menus successfully`
|
|
10869
11237
|
}, sendMessage, clientId);
|
|
10870
11238
|
logger.info(`Reordered ${items.length} menus`);
|
|
10871
11239
|
} catch (error) {
|
|
10872
|
-
|
|
11240
|
+
sendResponse10(id, {
|
|
10873
11241
|
success: false,
|
|
10874
11242
|
error: error instanceof Error ? error.message : "Failed to reorder menus"
|
|
10875
11243
|
}, sendMessage, clientId);
|
|
10876
11244
|
}
|
|
10877
11245
|
}
|
|
10878
|
-
function
|
|
11246
|
+
function sendResponse10(id, res, sendMessage, clientId) {
|
|
10879
11247
|
const response = {
|
|
10880
11248
|
id: id || "unknown",
|
|
10881
11249
|
type: "MENUS_RES",
|
|
@@ -12407,6 +12775,11 @@ var SuperatomSDK = class {
|
|
|
12407
12775
|
logger.error("Failed to handle bookmarks request:", error);
|
|
12408
12776
|
});
|
|
12409
12777
|
break;
|
|
12778
|
+
case "ARTIFACTS":
|
|
12779
|
+
handleArtifactsRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
12780
|
+
logger.error("Failed to handle artifacts request:", error);
|
|
12781
|
+
});
|
|
12782
|
+
break;
|
|
12410
12783
|
case "KB_NODES":
|
|
12411
12784
|
handleKbNodesRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
12412
12785
|
logger.error("Failed to handle KB nodes request:", error);
|