@superatomai/sdk-node 0.0.19 → 0.0.20
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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +907 -142
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +907 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -451,7 +451,8 @@ var UserPromptRequestMessageSchema = import_zod3.z.object({
|
|
|
451
451
|
});
|
|
452
452
|
var UserPromptSuggestionsPayloadSchema = import_zod3.z.object({
|
|
453
453
|
prompt: import_zod3.z.string(),
|
|
454
|
-
limit: import_zod3.z.number().int().positive().default(5)
|
|
454
|
+
limit: import_zod3.z.number().int().positive().default(5),
|
|
455
|
+
similarityThreshold: import_zod3.z.number().min(0).max(1).default(0.4)
|
|
455
456
|
});
|
|
456
457
|
var UserPromptSuggestionsMessageSchema = import_zod3.z.object({
|
|
457
458
|
id: import_zod3.z.string(),
|
|
@@ -538,11 +539,28 @@ var ActionsRequestMessageSchema = import_zod3.z.object({
|
|
|
538
539
|
type: import_zod3.z.literal("ACTIONS"),
|
|
539
540
|
payload: ActionsRequestPayloadSchema
|
|
540
541
|
});
|
|
542
|
+
var DashboardQueryFiltersSchema = import_zod3.z.object({
|
|
543
|
+
dashboardId: import_zod3.z.string().optional(),
|
|
544
|
+
projectId: import_zod3.z.string().optional(),
|
|
545
|
+
createdBy: import_zod3.z.number().optional(),
|
|
546
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
547
|
+
name: import_zod3.z.string().optional()
|
|
548
|
+
});
|
|
541
549
|
var DashboardsRequestPayloadSchema = import_zod3.z.object({
|
|
542
|
-
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
550
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
543
551
|
data: import_zod3.z.object({
|
|
552
|
+
id: import_zod3.z.number().optional(),
|
|
544
553
|
dashboardId: import_zod3.z.string().optional(),
|
|
545
|
-
|
|
554
|
+
projectId: import_zod3.z.string().optional(),
|
|
555
|
+
name: import_zod3.z.string().optional(),
|
|
556
|
+
description: import_zod3.z.string().optional(),
|
|
557
|
+
createdBy: import_zod3.z.number().optional(),
|
|
558
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
559
|
+
dashboard: DSLRendererPropsSchema.optional(),
|
|
560
|
+
// Query operation fields
|
|
561
|
+
filters: DashboardQueryFiltersSchema.optional(),
|
|
562
|
+
limit: import_zod3.z.number().optional(),
|
|
563
|
+
sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
|
|
546
564
|
}).optional()
|
|
547
565
|
});
|
|
548
566
|
var DashboardsRequestMessageSchema = import_zod3.z.object({
|
|
@@ -551,11 +569,28 @@ var DashboardsRequestMessageSchema = import_zod3.z.object({
|
|
|
551
569
|
type: import_zod3.z.literal("DASHBOARDS"),
|
|
552
570
|
payload: DashboardsRequestPayloadSchema
|
|
553
571
|
});
|
|
572
|
+
var ReportQueryFiltersSchema = import_zod3.z.object({
|
|
573
|
+
reportId: import_zod3.z.string().optional(),
|
|
574
|
+
projectId: import_zod3.z.string().optional(),
|
|
575
|
+
createdBy: import_zod3.z.number().optional(),
|
|
576
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
577
|
+
name: import_zod3.z.string().optional()
|
|
578
|
+
});
|
|
554
579
|
var ReportsRequestPayloadSchema = import_zod3.z.object({
|
|
555
|
-
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
580
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
556
581
|
data: import_zod3.z.object({
|
|
582
|
+
id: import_zod3.z.number().optional(),
|
|
557
583
|
reportId: import_zod3.z.string().optional(),
|
|
558
|
-
|
|
584
|
+
projectId: import_zod3.z.string().optional(),
|
|
585
|
+
name: import_zod3.z.string().optional(),
|
|
586
|
+
description: import_zod3.z.string().optional(),
|
|
587
|
+
createdBy: import_zod3.z.number().optional(),
|
|
588
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
589
|
+
report: DSLRendererPropsSchema2.optional(),
|
|
590
|
+
// Query operation fields
|
|
591
|
+
filters: ReportQueryFiltersSchema.optional(),
|
|
592
|
+
limit: import_zod3.z.number().optional(),
|
|
593
|
+
sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
|
|
559
594
|
}).optional()
|
|
560
595
|
});
|
|
561
596
|
var ReportsRequestMessageSchema = import_zod3.z.object({
|
|
@@ -564,6 +599,36 @@ var ReportsRequestMessageSchema = import_zod3.z.object({
|
|
|
564
599
|
type: import_zod3.z.literal("REPORTS"),
|
|
565
600
|
payload: ReportsRequestPayloadSchema
|
|
566
601
|
});
|
|
602
|
+
var UIQueryFiltersSchema = import_zod3.z.object({
|
|
603
|
+
uiId: import_zod3.z.string().optional(),
|
|
604
|
+
projectId: import_zod3.z.string().optional(),
|
|
605
|
+
createdBy: import_zod3.z.number().optional(),
|
|
606
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
607
|
+
name: import_zod3.z.string().optional()
|
|
608
|
+
});
|
|
609
|
+
var UIsRequestPayloadSchema = import_zod3.z.object({
|
|
610
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
611
|
+
data: import_zod3.z.object({
|
|
612
|
+
id: import_zod3.z.number().optional(),
|
|
613
|
+
uiId: import_zod3.z.string().optional(),
|
|
614
|
+
projectId: import_zod3.z.string().optional(),
|
|
615
|
+
name: import_zod3.z.string().optional(),
|
|
616
|
+
description: import_zod3.z.string().optional(),
|
|
617
|
+
createdBy: import_zod3.z.number().optional(),
|
|
618
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
619
|
+
ui: DSLRendererPropsSchema.optional(),
|
|
620
|
+
// Query operation fields
|
|
621
|
+
filters: UIQueryFiltersSchema.optional(),
|
|
622
|
+
limit: import_zod3.z.number().optional(),
|
|
623
|
+
sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
|
|
624
|
+
}).optional()
|
|
625
|
+
});
|
|
626
|
+
var UIsRequestMessageSchema = import_zod3.z.object({
|
|
627
|
+
id: import_zod3.z.string(),
|
|
628
|
+
from: MessageParticipantSchema,
|
|
629
|
+
type: import_zod3.z.literal("UIS"),
|
|
630
|
+
payload: UIsRequestPayloadSchema
|
|
631
|
+
});
|
|
567
632
|
var UIBlockSchema = import_zod3.z.object({
|
|
568
633
|
id: import_zod3.z.string().optional(),
|
|
569
634
|
userQuestion: import_zod3.z.string().optional(),
|
|
@@ -587,10 +652,16 @@ var UIBlockSchema = import_zod3.z.object({
|
|
|
587
652
|
similarity: import_zod3.z.number().optional()
|
|
588
653
|
}).optional()
|
|
589
654
|
});
|
|
655
|
+
var DBUIBlockSchema = import_zod3.z.object({
|
|
656
|
+
id: import_zod3.z.string(),
|
|
657
|
+
component: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.any()).nullable(),
|
|
658
|
+
analysis: import_zod3.z.string().nullable(),
|
|
659
|
+
user_prompt: import_zod3.z.string()
|
|
660
|
+
});
|
|
590
661
|
var BookmarkDataSchema = import_zod3.z.object({
|
|
591
662
|
id: import_zod3.z.number().optional(),
|
|
592
|
-
uiblock:
|
|
593
|
-
// JSON object
|
|
663
|
+
uiblock: DBUIBlockSchema,
|
|
664
|
+
// Typed JSON object
|
|
594
665
|
created_at: import_zod3.z.string().optional(),
|
|
595
666
|
updated_at: import_zod3.z.string().optional()
|
|
596
667
|
});
|
|
@@ -600,7 +671,9 @@ var BookmarksRequestPayloadSchema = import_zod3.z.object({
|
|
|
600
671
|
id: import_zod3.z.number().optional(),
|
|
601
672
|
userId: import_zod3.z.number().optional(),
|
|
602
673
|
threadId: import_zod3.z.string().optional(),
|
|
603
|
-
|
|
674
|
+
name: import_zod3.z.string().optional(),
|
|
675
|
+
description: import_zod3.z.string().optional(),
|
|
676
|
+
uiblock: DBUIBlockSchema.optional()
|
|
604
677
|
}).optional()
|
|
605
678
|
});
|
|
606
679
|
var BookmarksRequestMessageSchema = import_zod3.z.object({
|
|
@@ -5626,12 +5699,13 @@ function sendDataResponse4(id, res, sendMessage, clientId) {
|
|
|
5626
5699
|
}
|
|
5627
5700
|
|
|
5628
5701
|
// src/handlers/user-prompt-suggestions.ts
|
|
5629
|
-
async function handleUserPromptSuggestions(data, components, sendMessage) {
|
|
5702
|
+
async function handleUserPromptSuggestions(data, components, sendMessage, collections, userId) {
|
|
5630
5703
|
try {
|
|
5631
5704
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5632
5705
|
const { id, payload, from } = request;
|
|
5633
|
-
const { prompt, limit = 5 } = payload;
|
|
5706
|
+
const { prompt, limit = 5, similarityThreshold = 0.1 } = payload;
|
|
5634
5707
|
const wsId = from.id;
|
|
5708
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5635
5709
|
if (!prompt || prompt.trim().length === 0) {
|
|
5636
5710
|
sendResponse(id, {
|
|
5637
5711
|
success: false,
|
|
@@ -5639,7 +5713,79 @@ async function handleUserPromptSuggestions(data, components, sendMessage) {
|
|
|
5639
5713
|
}, sendMessage, wsId);
|
|
5640
5714
|
return;
|
|
5641
5715
|
}
|
|
5716
|
+
const componentSearchHandler = collections?.["components"]?.["search"];
|
|
5717
|
+
const bookmarkSearchHandler = collections?.["bookmarks"]?.["search"];
|
|
5718
|
+
let componentSuggestions = [];
|
|
5719
|
+
let bookmarkSuggestions = [];
|
|
5720
|
+
let useEmbeddingSearch = false;
|
|
5721
|
+
const searchPromises = [];
|
|
5722
|
+
if (componentSearchHandler) {
|
|
5723
|
+
searchPromises.push(
|
|
5724
|
+
(async () => {
|
|
5725
|
+
try {
|
|
5726
|
+
logger.info("Using embedding-based search for components");
|
|
5727
|
+
const result = await componentSearchHandler({ prompt, limit });
|
|
5728
|
+
if (result.success && result.suggestions) {
|
|
5729
|
+
componentSuggestions = result.suggestions.map((s) => ({
|
|
5730
|
+
...s,
|
|
5731
|
+
suggestionType: "component"
|
|
5732
|
+
}));
|
|
5733
|
+
useEmbeddingSearch = true;
|
|
5734
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions`);
|
|
5735
|
+
}
|
|
5736
|
+
} catch (embeddingError) {
|
|
5737
|
+
logger.warn("Component embedding search failed:", embeddingError);
|
|
5738
|
+
}
|
|
5739
|
+
})()
|
|
5740
|
+
);
|
|
5741
|
+
}
|
|
5742
|
+
if (bookmarkSearchHandler && userId && userId !== "anonymous") {
|
|
5743
|
+
searchPromises.push(
|
|
5744
|
+
(async () => {
|
|
5745
|
+
try {
|
|
5746
|
+
logger.info(`Using embedding-based search for bookmarks (user: ${userId})`);
|
|
5747
|
+
const result = await bookmarkSearchHandler({ prompt, userId, limit });
|
|
5748
|
+
if (result.success && result.suggestions) {
|
|
5749
|
+
bookmarkSuggestions = result.suggestions.map((s) => ({
|
|
5750
|
+
...s,
|
|
5751
|
+
suggestionType: "bookmark"
|
|
5752
|
+
}));
|
|
5753
|
+
useEmbeddingSearch = true;
|
|
5754
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions`);
|
|
5755
|
+
}
|
|
5756
|
+
} catch (embeddingError) {
|
|
5757
|
+
logger.warn("Bookmark embedding search failed:", embeddingError);
|
|
5758
|
+
}
|
|
5759
|
+
})()
|
|
5760
|
+
);
|
|
5761
|
+
}
|
|
5762
|
+
if (searchPromises.length > 0) {
|
|
5763
|
+
await Promise.all(searchPromises);
|
|
5764
|
+
}
|
|
5765
|
+
if (useEmbeddingSearch && (componentSuggestions.length > 0 || bookmarkSuggestions.length > 0)) {
|
|
5766
|
+
const filteredComponentSuggestions = componentSuggestions.filter(
|
|
5767
|
+
(s) => (s.similarity || 0) >= similarityThreshold
|
|
5768
|
+
);
|
|
5769
|
+
const filteredBookmarkSuggestions = bookmarkSuggestions.filter(
|
|
5770
|
+
(s) => (s.similarity || 0) >= similarityThreshold
|
|
5771
|
+
);
|
|
5772
|
+
const allSuggestions = [...filteredComponentSuggestions, ...filteredBookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
|
|
5773
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Filtered by threshold ${similarityThreshold}: ${componentSuggestions.length} -> ${filteredComponentSuggestions.length} components, ${bookmarkSuggestions.length} -> ${filteredBookmarkSuggestions.length} bookmarks`);
|
|
5774
|
+
sendResponse(id, {
|
|
5775
|
+
success: true,
|
|
5776
|
+
data: {
|
|
5777
|
+
prompt,
|
|
5778
|
+
suggestions: allSuggestions,
|
|
5779
|
+
count: allSuggestions.length,
|
|
5780
|
+
componentCount: filteredComponentSuggestions.length,
|
|
5781
|
+
bookmarkCount: filteredBookmarkSuggestions.length,
|
|
5782
|
+
message: `Found ${allSuggestions.length} suggestions (${filteredComponentSuggestions.length} components, ${filteredBookmarkSuggestions.length} bookmarks)`
|
|
5783
|
+
}
|
|
5784
|
+
}, sendMessage, wsId);
|
|
5785
|
+
return;
|
|
5786
|
+
}
|
|
5642
5787
|
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5788
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based approach. Display components: ${displayComponents.length}`);
|
|
5643
5789
|
if (!displayComponents || displayComponents.length === 0) {
|
|
5644
5790
|
sendResponse(id, {
|
|
5645
5791
|
success: true,
|
|
@@ -5977,10 +6123,10 @@ function sendResponse2(id, res, sendMessage, clientId) {
|
|
|
5977
6123
|
}
|
|
5978
6124
|
|
|
5979
6125
|
// src/handlers/components-list-response.ts
|
|
5980
|
-
async function handleComponentListResponse(data, storeComponents) {
|
|
6126
|
+
async function handleComponentListResponse(data, storeComponents, collections) {
|
|
5981
6127
|
try {
|
|
5982
6128
|
const componentListResponse = ComponentListResponseMessageSchema.parse(data);
|
|
5983
|
-
const {
|
|
6129
|
+
const { payload } = componentListResponse;
|
|
5984
6130
|
const componentsList = payload.components;
|
|
5985
6131
|
if (!componentsList) {
|
|
5986
6132
|
logger.error("Components list not found in the response");
|
|
@@ -5988,6 +6134,20 @@ async function handleComponentListResponse(data, storeComponents) {
|
|
|
5988
6134
|
}
|
|
5989
6135
|
const components = ComponentsSchema.parse(componentsList);
|
|
5990
6136
|
storeComponents(components);
|
|
6137
|
+
const embedHandler = collections?.["components"]?.["embed"];
|
|
6138
|
+
if (embedHandler) {
|
|
6139
|
+
try {
|
|
6140
|
+
logger.info("Embedding display components for semantic search...");
|
|
6141
|
+
const result = await embedHandler({ components });
|
|
6142
|
+
if (result.success) {
|
|
6143
|
+
logger.info(`Successfully embedded ${result.count} display components`);
|
|
6144
|
+
} else {
|
|
6145
|
+
logger.warn("Failed to embed components:", result.error);
|
|
6146
|
+
}
|
|
6147
|
+
} catch (embedError) {
|
|
6148
|
+
logger.warn("Failed to embed components:", embedError);
|
|
6149
|
+
}
|
|
6150
|
+
}
|
|
5991
6151
|
return;
|
|
5992
6152
|
} catch (error) {
|
|
5993
6153
|
logger.error("Failed to handle user prompt request:", error);
|
|
@@ -6005,7 +6165,7 @@ async function handleUsersRequest(data, sendMessage) {
|
|
|
6005
6165
|
const password = requestData?.password;
|
|
6006
6166
|
const fullname = requestData?.fullname;
|
|
6007
6167
|
const role = requestData?.role;
|
|
6008
|
-
if (from.type !== "admin") {
|
|
6168
|
+
if (from.type !== "admin" && operation !== "getOne" && operation !== "getAll") {
|
|
6009
6169
|
sendResponse3(id, {
|
|
6010
6170
|
success: false,
|
|
6011
6171
|
error: "Unauthorized: Only admin can manage users"
|
|
@@ -6292,13 +6452,29 @@ function getDashboardManager() {
|
|
|
6292
6452
|
}
|
|
6293
6453
|
|
|
6294
6454
|
// src/handlers/dashboards.ts
|
|
6295
|
-
async function handleDashboardsRequest(data, sendMessage) {
|
|
6455
|
+
async function handleDashboardsRequest(data, collections, sendMessage) {
|
|
6456
|
+
const executeCollection = async (collection, op, params) => {
|
|
6457
|
+
const handler = collections[collection]?.[op];
|
|
6458
|
+
if (!handler) {
|
|
6459
|
+
return null;
|
|
6460
|
+
}
|
|
6461
|
+
return await handler(params);
|
|
6462
|
+
};
|
|
6296
6463
|
try {
|
|
6297
6464
|
const request = DashboardsRequestMessageSchema.parse(data);
|
|
6298
6465
|
const { id, payload, from } = request;
|
|
6299
6466
|
const { operation, data: requestData } = payload;
|
|
6300
6467
|
const dashboardId = requestData?.dashboardId;
|
|
6301
6468
|
const dashboard = requestData?.dashboard;
|
|
6469
|
+
const projectId = requestData?.projectId;
|
|
6470
|
+
const name = requestData?.name;
|
|
6471
|
+
const description = requestData?.description;
|
|
6472
|
+
const createdBy = requestData?.createdBy;
|
|
6473
|
+
const updatedBy = requestData?.updatedBy;
|
|
6474
|
+
const numericId = requestData?.id;
|
|
6475
|
+
const filters = requestData?.filters;
|
|
6476
|
+
const limit = requestData?.limit;
|
|
6477
|
+
const sort = requestData?.sort;
|
|
6302
6478
|
if (from.type !== "admin") {
|
|
6303
6479
|
sendResponse4(id, {
|
|
6304
6480
|
success: false,
|
|
@@ -6310,19 +6486,22 @@ async function handleDashboardsRequest(data, sendMessage) {
|
|
|
6310
6486
|
const dashboardManager2 = getDashboardManager();
|
|
6311
6487
|
switch (operation) {
|
|
6312
6488
|
case "create":
|
|
6313
|
-
await handleCreate2(id, dashboardId, dashboard, dashboardManager2, sendMessage, from.id);
|
|
6489
|
+
await handleCreate2(id, dashboardId, dashboard, projectId, name, description, createdBy, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6314
6490
|
break;
|
|
6315
6491
|
case "update":
|
|
6316
|
-
await handleUpdate2(id, dashboardId, dashboard, dashboardManager2, sendMessage, from.id);
|
|
6492
|
+
await handleUpdate2(id, numericId, dashboardId, dashboard, name, description, updatedBy, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6317
6493
|
break;
|
|
6318
6494
|
case "delete":
|
|
6319
|
-
await handleDelete2(id, dashboardId, dashboardManager2, sendMessage, from.id);
|
|
6495
|
+
await handleDelete2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6320
6496
|
break;
|
|
6321
6497
|
case "getAll":
|
|
6322
|
-
await handleGetAll2(id, dashboardManager2, sendMessage, from.id);
|
|
6498
|
+
await handleGetAll2(id, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6323
6499
|
break;
|
|
6324
6500
|
case "getOne":
|
|
6325
|
-
await handleGetOne2(id, dashboardId, dashboardManager2, sendMessage, from.id);
|
|
6501
|
+
await handleGetOne2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6502
|
+
break;
|
|
6503
|
+
case "query":
|
|
6504
|
+
await handleQuery(id, filters, limit, sort, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6326
6505
|
break;
|
|
6327
6506
|
default:
|
|
6328
6507
|
sendResponse4(id, {
|
|
@@ -6338,7 +6517,7 @@ async function handleDashboardsRequest(data, sendMessage) {
|
|
|
6338
6517
|
}, sendMessage);
|
|
6339
6518
|
}
|
|
6340
6519
|
}
|
|
6341
|
-
async function handleCreate2(id, dashboardId, dashboard, dashboardManager2, sendMessage, clientId) {
|
|
6520
|
+
async function handleCreate2(id, dashboardId, dashboard, projectId, name, description, createdBy, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6342
6521
|
if (!dashboardId || dashboardId.trim().length === 0) {
|
|
6343
6522
|
sendResponse4(id, {
|
|
6344
6523
|
success: false,
|
|
@@ -6346,21 +6525,50 @@ async function handleCreate2(id, dashboardId, dashboard, dashboardManager2, send
|
|
|
6346
6525
|
}, sendMessage, clientId);
|
|
6347
6526
|
return;
|
|
6348
6527
|
}
|
|
6349
|
-
if (!
|
|
6528
|
+
if (!projectId) {
|
|
6350
6529
|
sendResponse4(id, {
|
|
6351
6530
|
success: false,
|
|
6352
|
-
error: "
|
|
6531
|
+
error: "Project ID is required"
|
|
6353
6532
|
}, sendMessage, clientId);
|
|
6354
6533
|
return;
|
|
6355
6534
|
}
|
|
6356
6535
|
try {
|
|
6536
|
+
const result = await executeCollection("dashboards", "create", {
|
|
6537
|
+
dashboardId,
|
|
6538
|
+
projectId,
|
|
6539
|
+
name: name || "",
|
|
6540
|
+
description,
|
|
6541
|
+
dashboard,
|
|
6542
|
+
createdBy
|
|
6543
|
+
});
|
|
6544
|
+
if (result && result.success) {
|
|
6545
|
+
logger.info(`[DB] Dashboard created successfully, ID: ${result.data?.id}`);
|
|
6546
|
+
sendResponse4(id, {
|
|
6547
|
+
success: true,
|
|
6548
|
+
data: {
|
|
6549
|
+
id: result.data?.id,
|
|
6550
|
+
dashboardId: result.data?.dashboardId,
|
|
6551
|
+
dashboard: result.data?.dashboard || dashboard,
|
|
6552
|
+
message: `Dashboard created successfully (DB)`
|
|
6553
|
+
}
|
|
6554
|
+
}, sendMessage, clientId);
|
|
6555
|
+
return;
|
|
6556
|
+
}
|
|
6557
|
+
} catch (dbError) {
|
|
6558
|
+
logger.warn(`[DB] Failed to create dashboard, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6559
|
+
}
|
|
6560
|
+
try {
|
|
6561
|
+
if (!dashboard) {
|
|
6562
|
+
dashboard = {};
|
|
6563
|
+
}
|
|
6357
6564
|
const createdDashboard = dashboardManager2.createDashboard(dashboardId, dashboard);
|
|
6565
|
+
logger.info(`[FILE] Dashboard '${dashboardId}' created successfully`);
|
|
6358
6566
|
sendResponse4(id, {
|
|
6359
6567
|
success: true,
|
|
6360
6568
|
data: {
|
|
6361
6569
|
dashboardId,
|
|
6362
6570
|
dashboard: createdDashboard,
|
|
6363
|
-
message: `Dashboard '${dashboardId}' created successfully`
|
|
6571
|
+
message: `Dashboard '${dashboardId}' created successfully (File)`
|
|
6364
6572
|
}
|
|
6365
6573
|
}, sendMessage, clientId);
|
|
6366
6574
|
} catch (error) {
|
|
@@ -6370,36 +6578,56 @@ async function handleCreate2(id, dashboardId, dashboard, dashboardManager2, send
|
|
|
6370
6578
|
}, sendMessage, clientId);
|
|
6371
6579
|
}
|
|
6372
6580
|
}
|
|
6373
|
-
async function handleUpdate2(id, dashboardId, dashboard, dashboardManager2, sendMessage, clientId) {
|
|
6374
|
-
if (!
|
|
6581
|
+
async function handleUpdate2(id, numericId, dashboardId, dashboard, name, description, updatedBy, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6582
|
+
if (!numericId) {
|
|
6375
6583
|
sendResponse4(id, {
|
|
6376
6584
|
success: false,
|
|
6377
|
-
error: "Dashboard ID is required
|
|
6585
|
+
error: "Dashboard ID is required"
|
|
6378
6586
|
}, sendMessage, clientId);
|
|
6379
6587
|
return;
|
|
6380
6588
|
}
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6589
|
+
try {
|
|
6590
|
+
const result = await executeCollection("dashboards", "update", {
|
|
6591
|
+
id: numericId,
|
|
6592
|
+
name,
|
|
6593
|
+
description,
|
|
6594
|
+
dashboard,
|
|
6595
|
+
updatedBy
|
|
6596
|
+
});
|
|
6597
|
+
if (result && result.success) {
|
|
6598
|
+
logger.info(`[DB] Dashboard updated successfully, ID: ${numericId}`);
|
|
6599
|
+
sendResponse4(id, {
|
|
6600
|
+
success: true,
|
|
6601
|
+
data: {
|
|
6602
|
+
id: numericId,
|
|
6603
|
+
dashboardId: result.data?.dashboardId,
|
|
6604
|
+
dashboard: result.data?.dashboard || dashboard,
|
|
6605
|
+
message: `Dashboard updated successfully (DB)`
|
|
6606
|
+
}
|
|
6607
|
+
}, sendMessage, clientId);
|
|
6608
|
+
return;
|
|
6609
|
+
}
|
|
6610
|
+
} catch (dbError) {
|
|
6611
|
+
logger.warn(`[DB] Failed to update dashboard, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6387
6612
|
}
|
|
6613
|
+
const fileStorageId = dashboardId || String(numericId);
|
|
6388
6614
|
try {
|
|
6389
|
-
const updatedDashboard = dashboardManager2.updateDashboard(
|
|
6615
|
+
const updatedDashboard = dashboardManager2.updateDashboard(fileStorageId, dashboard);
|
|
6390
6616
|
if (!updatedDashboard) {
|
|
6391
6617
|
sendResponse4(id, {
|
|
6392
6618
|
success: false,
|
|
6393
|
-
error: `Dashboard '${
|
|
6619
|
+
error: `Dashboard '${fileStorageId}' not found`
|
|
6394
6620
|
}, sendMessage, clientId);
|
|
6395
6621
|
return;
|
|
6396
6622
|
}
|
|
6623
|
+
logger.info(`[FILE] Dashboard '${fileStorageId}' updated successfully`);
|
|
6397
6624
|
sendResponse4(id, {
|
|
6398
6625
|
success: true,
|
|
6399
6626
|
data: {
|
|
6400
|
-
|
|
6627
|
+
id: numericId,
|
|
6628
|
+
dashboardId: fileStorageId,
|
|
6401
6629
|
dashboard: updatedDashboard,
|
|
6402
|
-
message: `Dashboard '${
|
|
6630
|
+
message: `Dashboard '${fileStorageId}' updated successfully (File)`
|
|
6403
6631
|
}
|
|
6404
6632
|
}, sendMessage, clientId);
|
|
6405
6633
|
} catch (error) {
|
|
@@ -6409,65 +6637,154 @@ async function handleUpdate2(id, dashboardId, dashboard, dashboardManager2, send
|
|
|
6409
6637
|
}, sendMessage, clientId);
|
|
6410
6638
|
}
|
|
6411
6639
|
}
|
|
6412
|
-
async function handleDelete2(id, dashboardId, dashboardManager2, sendMessage, clientId) {
|
|
6413
|
-
if (!
|
|
6640
|
+
async function handleDelete2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6641
|
+
if (!numericId) {
|
|
6414
6642
|
sendResponse4(id, {
|
|
6415
6643
|
success: false,
|
|
6416
|
-
error: "Dashboard ID is required
|
|
6644
|
+
error: "Dashboard ID is required"
|
|
6417
6645
|
}, sendMessage, clientId);
|
|
6418
6646
|
return;
|
|
6419
6647
|
}
|
|
6420
|
-
|
|
6648
|
+
try {
|
|
6649
|
+
const result = await executeCollection("dashboards", "delete", { id: numericId });
|
|
6650
|
+
if (result && result.success) {
|
|
6651
|
+
logger.info(`[DB] Dashboard deleted successfully, ID: ${numericId}`);
|
|
6652
|
+
sendResponse4(id, {
|
|
6653
|
+
success: true,
|
|
6654
|
+
data: {
|
|
6655
|
+
id: numericId,
|
|
6656
|
+
message: `Dashboard deleted successfully (DB)`
|
|
6657
|
+
}
|
|
6658
|
+
}, sendMessage, clientId);
|
|
6659
|
+
return;
|
|
6660
|
+
}
|
|
6661
|
+
} catch (dbError) {
|
|
6662
|
+
logger.warn(`[DB] Failed to delete dashboard, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6663
|
+
}
|
|
6664
|
+
const fileStorageId = dashboardId || String(numericId);
|
|
6665
|
+
const deleted = dashboardManager2.deleteDashboard(fileStorageId);
|
|
6421
6666
|
if (!deleted) {
|
|
6422
6667
|
sendResponse4(id, {
|
|
6423
6668
|
success: false,
|
|
6424
|
-
error: `Dashboard '${
|
|
6669
|
+
error: `Dashboard '${fileStorageId}' not found`
|
|
6425
6670
|
}, sendMessage, clientId);
|
|
6426
6671
|
return;
|
|
6427
6672
|
}
|
|
6673
|
+
logger.info(`[FILE] Dashboard '${fileStorageId}' deleted successfully`);
|
|
6428
6674
|
sendResponse4(id, {
|
|
6429
6675
|
success: true,
|
|
6430
6676
|
data: {
|
|
6431
|
-
|
|
6432
|
-
|
|
6677
|
+
id: numericId,
|
|
6678
|
+
dashboardId: fileStorageId,
|
|
6679
|
+
message: `Dashboard '${fileStorageId}' deleted successfully (File)`
|
|
6433
6680
|
}
|
|
6434
6681
|
}, sendMessage, clientId);
|
|
6435
6682
|
}
|
|
6436
|
-
async function handleGetAll2(id, dashboardManager2, sendMessage, clientId) {
|
|
6683
|
+
async function handleGetAll2(id, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6684
|
+
try {
|
|
6685
|
+
const result = await executeCollection("dashboards", "getAll", {});
|
|
6686
|
+
if (result && result.success) {
|
|
6687
|
+
logger.info(`[DB] Retrieved ${result.count} dashboards`);
|
|
6688
|
+
sendResponse4(id, {
|
|
6689
|
+
success: true,
|
|
6690
|
+
data: {
|
|
6691
|
+
dashboards: result.data,
|
|
6692
|
+
count: result.count,
|
|
6693
|
+
message: `Retrieved ${result.count} dashboards (DB)`
|
|
6694
|
+
}
|
|
6695
|
+
}, sendMessage, clientId);
|
|
6696
|
+
return;
|
|
6697
|
+
}
|
|
6698
|
+
} catch (dbError) {
|
|
6699
|
+
logger.warn(`[DB] Failed to get all dashboards, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6700
|
+
}
|
|
6437
6701
|
const dashboards = dashboardManager2.getAllDashboards();
|
|
6438
|
-
logger.info(`
|
|
6702
|
+
logger.info(`[FILE] Retrieved ${dashboards.length} dashboards`);
|
|
6439
6703
|
sendResponse4(id, {
|
|
6440
6704
|
success: true,
|
|
6441
6705
|
data: {
|
|
6442
6706
|
dashboards,
|
|
6443
6707
|
count: dashboards.length,
|
|
6444
|
-
message: `Retrieved ${dashboards.length} dashboards`
|
|
6708
|
+
message: `Retrieved ${dashboards.length} dashboards (File)`
|
|
6445
6709
|
}
|
|
6446
6710
|
}, sendMessage, clientId);
|
|
6447
6711
|
}
|
|
6448
|
-
async function handleGetOne2(id, dashboardId, dashboardManager2, sendMessage, clientId) {
|
|
6449
|
-
if (!
|
|
6712
|
+
async function handleGetOne2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6713
|
+
if (!numericId) {
|
|
6450
6714
|
sendResponse4(id, {
|
|
6451
6715
|
success: false,
|
|
6452
|
-
error: "Dashboard ID is required
|
|
6716
|
+
error: "Dashboard ID is required"
|
|
6453
6717
|
}, sendMessage, clientId);
|
|
6454
6718
|
return;
|
|
6455
6719
|
}
|
|
6456
|
-
|
|
6720
|
+
try {
|
|
6721
|
+
const result = await executeCollection("dashboards", "getOne", { id: numericId });
|
|
6722
|
+
if (result && result.success) {
|
|
6723
|
+
logger.info(`[DB] Retrieved dashboard ID: ${numericId}`);
|
|
6724
|
+
sendResponse4(id, {
|
|
6725
|
+
success: true,
|
|
6726
|
+
data: {
|
|
6727
|
+
id: numericId,
|
|
6728
|
+
dashboardId: result.data?.dashboardId,
|
|
6729
|
+
dashboard: result.data?.dashboard || result.data,
|
|
6730
|
+
message: `Retrieved dashboard (DB)`
|
|
6731
|
+
}
|
|
6732
|
+
}, sendMessage, clientId);
|
|
6733
|
+
return;
|
|
6734
|
+
}
|
|
6735
|
+
} catch (dbError) {
|
|
6736
|
+
logger.warn(`[DB] Failed to get dashboard, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6737
|
+
}
|
|
6738
|
+
const fileStorageId = dashboardId || String(numericId);
|
|
6739
|
+
const dashboard = dashboardManager2.getDashboard(fileStorageId);
|
|
6457
6740
|
if (!dashboard) {
|
|
6458
6741
|
sendResponse4(id, {
|
|
6459
6742
|
success: false,
|
|
6460
|
-
error: `Dashboard '${
|
|
6743
|
+
error: `Dashboard '${fileStorageId}' not found`
|
|
6461
6744
|
}, sendMessage, clientId);
|
|
6462
6745
|
return;
|
|
6463
6746
|
}
|
|
6464
|
-
logger.info(`
|
|
6747
|
+
logger.info(`[FILE] Retrieved dashboard: ${fileStorageId}`);
|
|
6465
6748
|
sendResponse4(id, {
|
|
6466
6749
|
success: true,
|
|
6467
6750
|
data: {
|
|
6468
|
-
|
|
6751
|
+
id: numericId,
|
|
6752
|
+
dashboardId: fileStorageId,
|
|
6469
6753
|
dashboard,
|
|
6470
|
-
message: `Retrieved dashboard '${
|
|
6754
|
+
message: `Retrieved dashboard '${fileStorageId}' (File)`
|
|
6755
|
+
}
|
|
6756
|
+
}, sendMessage, clientId);
|
|
6757
|
+
}
|
|
6758
|
+
async function handleQuery(id, filters, limit, sort, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6759
|
+
try {
|
|
6760
|
+
const result = await executeCollection("dashboards", "query", {
|
|
6761
|
+
filters: filters || {},
|
|
6762
|
+
limit,
|
|
6763
|
+
sort
|
|
6764
|
+
});
|
|
6765
|
+
if (result && result.success) {
|
|
6766
|
+
logger.info(`[DB] Query returned ${result.count} dashboards`);
|
|
6767
|
+
sendResponse4(id, {
|
|
6768
|
+
success: true,
|
|
6769
|
+
data: {
|
|
6770
|
+
dashboards: result.data,
|
|
6771
|
+
count: result.count,
|
|
6772
|
+
message: `Query returned ${result.count} dashboards (DB)`
|
|
6773
|
+
}
|
|
6774
|
+
}, sendMessage, clientId);
|
|
6775
|
+
return;
|
|
6776
|
+
}
|
|
6777
|
+
} catch (dbError) {
|
|
6778
|
+
logger.warn(`[DB] Failed to query dashboards: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6779
|
+
}
|
|
6780
|
+
const dashboards = dashboardManager2.getAllDashboards();
|
|
6781
|
+
logger.info(`[FILE] Retrieved ${dashboards.length} dashboards (all - no query filter)`);
|
|
6782
|
+
sendResponse4(id, {
|
|
6783
|
+
success: true,
|
|
6784
|
+
data: {
|
|
6785
|
+
dashboards,
|
|
6786
|
+
count: dashboards.length,
|
|
6787
|
+
message: `Retrieved ${dashboards.length} dashboards (File - no query filter)`
|
|
6471
6788
|
}
|
|
6472
6789
|
}, sendMessage, clientId);
|
|
6473
6790
|
}
|
|
@@ -6500,13 +6817,29 @@ function setReportManager(manager) {
|
|
|
6500
6817
|
}
|
|
6501
6818
|
|
|
6502
6819
|
// src/handlers/reports.ts
|
|
6503
|
-
async function handleReportsRequest(data, sendMessage) {
|
|
6820
|
+
async function handleReportsRequest(data, collections, sendMessage) {
|
|
6821
|
+
const executeCollection = async (collection, op, params) => {
|
|
6822
|
+
const handler = collections[collection]?.[op];
|
|
6823
|
+
if (!handler) {
|
|
6824
|
+
return null;
|
|
6825
|
+
}
|
|
6826
|
+
return await handler(params);
|
|
6827
|
+
};
|
|
6504
6828
|
try {
|
|
6505
6829
|
const request = ReportsRequestMessageSchema.parse(data);
|
|
6506
6830
|
const { id, payload, from } = request;
|
|
6507
6831
|
const { operation, data: requestData } = payload;
|
|
6508
6832
|
const reportId = requestData?.reportId;
|
|
6509
6833
|
const report = requestData?.report;
|
|
6834
|
+
const projectId = requestData?.projectId;
|
|
6835
|
+
const name = requestData?.name;
|
|
6836
|
+
const description = requestData?.description;
|
|
6837
|
+
const createdBy = requestData?.createdBy;
|
|
6838
|
+
const updatedBy = requestData?.updatedBy;
|
|
6839
|
+
const numericId = requestData?.id;
|
|
6840
|
+
const filters = requestData?.filters;
|
|
6841
|
+
const limit = requestData?.limit;
|
|
6842
|
+
const sort = requestData?.sort;
|
|
6510
6843
|
if (from.type !== "admin") {
|
|
6511
6844
|
sendResponse5(id, {
|
|
6512
6845
|
success: false,
|
|
@@ -6518,19 +6851,22 @@ async function handleReportsRequest(data, sendMessage) {
|
|
|
6518
6851
|
const reportManager2 = getReportManager();
|
|
6519
6852
|
switch (operation) {
|
|
6520
6853
|
case "create":
|
|
6521
|
-
await handleCreate3(id, reportId, report, reportManager2, sendMessage, from.id);
|
|
6854
|
+
await handleCreate3(id, reportId, report, projectId, name, description, createdBy, executeCollection, reportManager2, sendMessage, from.id);
|
|
6522
6855
|
break;
|
|
6523
6856
|
case "update":
|
|
6524
|
-
await handleUpdate3(id, reportId, report, reportManager2, sendMessage, from.id);
|
|
6857
|
+
await handleUpdate3(id, numericId, reportId, report, name, description, updatedBy, executeCollection, reportManager2, sendMessage, from.id);
|
|
6525
6858
|
break;
|
|
6526
6859
|
case "delete":
|
|
6527
|
-
await handleDelete3(id, reportId, reportManager2, sendMessage, from.id);
|
|
6860
|
+
await handleDelete3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, from.id);
|
|
6528
6861
|
break;
|
|
6529
6862
|
case "getAll":
|
|
6530
|
-
await handleGetAll3(id, reportManager2, sendMessage, from.id);
|
|
6863
|
+
await handleGetAll3(id, executeCollection, reportManager2, sendMessage, from.id);
|
|
6531
6864
|
break;
|
|
6532
6865
|
case "getOne":
|
|
6533
|
-
await handleGetOne3(id, reportId, reportManager2, sendMessage, from.id);
|
|
6866
|
+
await handleGetOne3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, from.id);
|
|
6867
|
+
break;
|
|
6868
|
+
case "query":
|
|
6869
|
+
await handleQuery2(id, filters, limit, sort, executeCollection, reportManager2, sendMessage, from.id);
|
|
6534
6870
|
break;
|
|
6535
6871
|
default:
|
|
6536
6872
|
sendResponse5(id, {
|
|
@@ -6546,7 +6882,7 @@ async function handleReportsRequest(data, sendMessage) {
|
|
|
6546
6882
|
}, sendMessage);
|
|
6547
6883
|
}
|
|
6548
6884
|
}
|
|
6549
|
-
async function handleCreate3(id, reportId, report, reportManager2, sendMessage, clientId) {
|
|
6885
|
+
async function handleCreate3(id, reportId, report, projectId, name, description, createdBy, executeCollection, reportManager2, sendMessage, clientId) {
|
|
6550
6886
|
if (!reportId || reportId.trim().length === 0) {
|
|
6551
6887
|
sendResponse5(id, {
|
|
6552
6888
|
success: false,
|
|
@@ -6554,21 +6890,50 @@ async function handleCreate3(id, reportId, report, reportManager2, sendMessage,
|
|
|
6554
6890
|
}, sendMessage, clientId);
|
|
6555
6891
|
return;
|
|
6556
6892
|
}
|
|
6557
|
-
if (!
|
|
6893
|
+
if (!projectId) {
|
|
6558
6894
|
sendResponse5(id, {
|
|
6559
6895
|
success: false,
|
|
6560
|
-
error: "
|
|
6896
|
+
error: "Project ID is required"
|
|
6561
6897
|
}, sendMessage, clientId);
|
|
6562
6898
|
return;
|
|
6563
6899
|
}
|
|
6564
6900
|
try {
|
|
6901
|
+
const result = await executeCollection("reports", "create", {
|
|
6902
|
+
reportId,
|
|
6903
|
+
projectId,
|
|
6904
|
+
name: name || "",
|
|
6905
|
+
description,
|
|
6906
|
+
report,
|
|
6907
|
+
createdBy
|
|
6908
|
+
});
|
|
6909
|
+
if (result && result.success) {
|
|
6910
|
+
logger.info(`[DB] Report created successfully, ID: ${result.data?.id}`);
|
|
6911
|
+
sendResponse5(id, {
|
|
6912
|
+
success: true,
|
|
6913
|
+
data: {
|
|
6914
|
+
id: result.data?.id,
|
|
6915
|
+
reportId: result.data?.reportId,
|
|
6916
|
+
report: result.data?.report || report,
|
|
6917
|
+
message: `Report created successfully (DB)`
|
|
6918
|
+
}
|
|
6919
|
+
}, sendMessage, clientId);
|
|
6920
|
+
return;
|
|
6921
|
+
}
|
|
6922
|
+
} catch (dbError) {
|
|
6923
|
+
logger.warn(`[DB] Failed to create report, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6924
|
+
}
|
|
6925
|
+
try {
|
|
6926
|
+
if (!report) {
|
|
6927
|
+
report = {};
|
|
6928
|
+
}
|
|
6565
6929
|
const createdReport = reportManager2.createReport(reportId, report);
|
|
6930
|
+
logger.info(`[FILE] Report '${reportId}' created successfully`);
|
|
6566
6931
|
sendResponse5(id, {
|
|
6567
6932
|
success: true,
|
|
6568
6933
|
data: {
|
|
6569
6934
|
reportId,
|
|
6570
6935
|
report: createdReport,
|
|
6571
|
-
message: `Report '${reportId}' created successfully`
|
|
6936
|
+
message: `Report '${reportId}' created successfully (File)`
|
|
6572
6937
|
}
|
|
6573
6938
|
}, sendMessage, clientId);
|
|
6574
6939
|
} catch (error) {
|
|
@@ -6578,36 +6943,56 @@ async function handleCreate3(id, reportId, report, reportManager2, sendMessage,
|
|
|
6578
6943
|
}, sendMessage, clientId);
|
|
6579
6944
|
}
|
|
6580
6945
|
}
|
|
6581
|
-
async function handleUpdate3(id, reportId, report, reportManager2, sendMessage, clientId) {
|
|
6582
|
-
if (!
|
|
6946
|
+
async function handleUpdate3(id, numericId, reportId, report, name, description, updatedBy, executeCollection, reportManager2, sendMessage, clientId) {
|
|
6947
|
+
if (!numericId) {
|
|
6583
6948
|
sendResponse5(id, {
|
|
6584
6949
|
success: false,
|
|
6585
|
-
error: "Report ID is required
|
|
6950
|
+
error: "Report ID is required"
|
|
6586
6951
|
}, sendMessage, clientId);
|
|
6587
6952
|
return;
|
|
6588
6953
|
}
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6954
|
+
try {
|
|
6955
|
+
const result = await executeCollection("reports", "update", {
|
|
6956
|
+
id: numericId,
|
|
6957
|
+
name,
|
|
6958
|
+
description,
|
|
6959
|
+
report,
|
|
6960
|
+
updatedBy
|
|
6961
|
+
});
|
|
6962
|
+
if (result && result.success) {
|
|
6963
|
+
logger.info(`[DB] Report updated successfully, ID: ${numericId}`);
|
|
6964
|
+
sendResponse5(id, {
|
|
6965
|
+
success: true,
|
|
6966
|
+
data: {
|
|
6967
|
+
id: numericId,
|
|
6968
|
+
reportId: result.data?.reportId,
|
|
6969
|
+
report: result.data?.report || report,
|
|
6970
|
+
message: `Report updated successfully (DB)`
|
|
6971
|
+
}
|
|
6972
|
+
}, sendMessage, clientId);
|
|
6973
|
+
return;
|
|
6974
|
+
}
|
|
6975
|
+
} catch (dbError) {
|
|
6976
|
+
logger.warn(`[DB] Failed to update report, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6595
6977
|
}
|
|
6978
|
+
const fileStorageId = reportId || String(numericId);
|
|
6596
6979
|
try {
|
|
6597
|
-
const updatedReport = reportManager2.updateReport(
|
|
6980
|
+
const updatedReport = reportManager2.updateReport(fileStorageId, report);
|
|
6598
6981
|
if (!updatedReport) {
|
|
6599
6982
|
sendResponse5(id, {
|
|
6600
6983
|
success: false,
|
|
6601
|
-
error: `Report '${
|
|
6984
|
+
error: `Report '${fileStorageId}' not found`
|
|
6602
6985
|
}, sendMessage, clientId);
|
|
6603
6986
|
return;
|
|
6604
6987
|
}
|
|
6988
|
+
logger.info(`[FILE] Report '${fileStorageId}' updated successfully`);
|
|
6605
6989
|
sendResponse5(id, {
|
|
6606
6990
|
success: true,
|
|
6607
6991
|
data: {
|
|
6608
|
-
|
|
6992
|
+
id: numericId,
|
|
6993
|
+
reportId: fileStorageId,
|
|
6609
6994
|
report: updatedReport,
|
|
6610
|
-
message: `Report '${
|
|
6995
|
+
message: `Report '${fileStorageId}' updated successfully (File)`
|
|
6611
6996
|
}
|
|
6612
6997
|
}, sendMessage, clientId);
|
|
6613
6998
|
} catch (error) {
|
|
@@ -6617,65 +7002,154 @@ async function handleUpdate3(id, reportId, report, reportManager2, sendMessage,
|
|
|
6617
7002
|
}, sendMessage, clientId);
|
|
6618
7003
|
}
|
|
6619
7004
|
}
|
|
6620
|
-
async function handleDelete3(id, reportId, reportManager2, sendMessage, clientId) {
|
|
6621
|
-
if (!
|
|
7005
|
+
async function handleDelete3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, clientId) {
|
|
7006
|
+
if (!numericId) {
|
|
6622
7007
|
sendResponse5(id, {
|
|
6623
7008
|
success: false,
|
|
6624
|
-
error: "Report ID is required
|
|
7009
|
+
error: "Report ID is required"
|
|
6625
7010
|
}, sendMessage, clientId);
|
|
6626
7011
|
return;
|
|
6627
7012
|
}
|
|
6628
|
-
|
|
7013
|
+
try {
|
|
7014
|
+
const result = await executeCollection("reports", "delete", { id: numericId });
|
|
7015
|
+
if (result && result.success) {
|
|
7016
|
+
logger.info(`[DB] Report deleted successfully, ID: ${numericId}`);
|
|
7017
|
+
sendResponse5(id, {
|
|
7018
|
+
success: true,
|
|
7019
|
+
data: {
|
|
7020
|
+
id: numericId,
|
|
7021
|
+
message: `Report deleted successfully (DB)`
|
|
7022
|
+
}
|
|
7023
|
+
}, sendMessage, clientId);
|
|
7024
|
+
return;
|
|
7025
|
+
}
|
|
7026
|
+
} catch (dbError) {
|
|
7027
|
+
logger.warn(`[DB] Failed to delete report, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
7028
|
+
}
|
|
7029
|
+
const fileStorageId = reportId || String(numericId);
|
|
7030
|
+
const deleted = reportManager2.deleteReport(fileStorageId);
|
|
6629
7031
|
if (!deleted) {
|
|
6630
7032
|
sendResponse5(id, {
|
|
6631
7033
|
success: false,
|
|
6632
|
-
error: `Report '${
|
|
7034
|
+
error: `Report '${fileStorageId}' not found`
|
|
6633
7035
|
}, sendMessage, clientId);
|
|
6634
7036
|
return;
|
|
6635
7037
|
}
|
|
7038
|
+
logger.info(`[FILE] Report '${fileStorageId}' deleted successfully`);
|
|
6636
7039
|
sendResponse5(id, {
|
|
6637
7040
|
success: true,
|
|
6638
7041
|
data: {
|
|
6639
|
-
|
|
6640
|
-
|
|
7042
|
+
id: numericId,
|
|
7043
|
+
reportId: fileStorageId,
|
|
7044
|
+
message: `Report '${fileStorageId}' deleted successfully (File)`
|
|
6641
7045
|
}
|
|
6642
7046
|
}, sendMessage, clientId);
|
|
6643
7047
|
}
|
|
6644
|
-
async function handleGetAll3(id, reportManager2, sendMessage, clientId) {
|
|
7048
|
+
async function handleGetAll3(id, executeCollection, reportManager2, sendMessage, clientId) {
|
|
7049
|
+
try {
|
|
7050
|
+
const result = await executeCollection("reports", "getAll", {});
|
|
7051
|
+
if (result && result.success) {
|
|
7052
|
+
logger.info(`[DB] Retrieved ${result.count} reports`);
|
|
7053
|
+
sendResponse5(id, {
|
|
7054
|
+
success: true,
|
|
7055
|
+
data: {
|
|
7056
|
+
reports: result.data,
|
|
7057
|
+
count: result.count,
|
|
7058
|
+
message: `Retrieved ${result.count} reports (DB)`
|
|
7059
|
+
}
|
|
7060
|
+
}, sendMessage, clientId);
|
|
7061
|
+
return;
|
|
7062
|
+
}
|
|
7063
|
+
} catch (dbError) {
|
|
7064
|
+
logger.warn(`[DB] Failed to get all reports, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
7065
|
+
}
|
|
6645
7066
|
const reports = reportManager2.getAllReports();
|
|
6646
|
-
logger.info(`
|
|
7067
|
+
logger.info(`[FILE] Retrieved ${reports.length} reports`);
|
|
6647
7068
|
sendResponse5(id, {
|
|
6648
7069
|
success: true,
|
|
6649
7070
|
data: {
|
|
6650
7071
|
reports,
|
|
6651
7072
|
count: reports.length,
|
|
6652
|
-
message: `Retrieved ${reports.length} reports`
|
|
7073
|
+
message: `Retrieved ${reports.length} reports (File)`
|
|
6653
7074
|
}
|
|
6654
7075
|
}, sendMessage, clientId);
|
|
6655
7076
|
}
|
|
6656
|
-
async function handleGetOne3(id, reportId, reportManager2, sendMessage, clientId) {
|
|
6657
|
-
if (!
|
|
7077
|
+
async function handleGetOne3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, clientId) {
|
|
7078
|
+
if (!numericId) {
|
|
6658
7079
|
sendResponse5(id, {
|
|
6659
7080
|
success: false,
|
|
6660
|
-
error: "Report ID is required
|
|
7081
|
+
error: "Report ID is required"
|
|
6661
7082
|
}, sendMessage, clientId);
|
|
6662
7083
|
return;
|
|
6663
7084
|
}
|
|
6664
|
-
|
|
7085
|
+
try {
|
|
7086
|
+
const result = await executeCollection("reports", "getOne", { id: numericId });
|
|
7087
|
+
if (result && result.success) {
|
|
7088
|
+
logger.info(`[DB] Retrieved report ID: ${numericId}`);
|
|
7089
|
+
sendResponse5(id, {
|
|
7090
|
+
success: true,
|
|
7091
|
+
data: {
|
|
7092
|
+
id: numericId,
|
|
7093
|
+
reportId: result.data?.reportId,
|
|
7094
|
+
report: result.data?.report || result.data,
|
|
7095
|
+
message: `Retrieved report (DB)`
|
|
7096
|
+
}
|
|
7097
|
+
}, sendMessage, clientId);
|
|
7098
|
+
return;
|
|
7099
|
+
}
|
|
7100
|
+
} catch (dbError) {
|
|
7101
|
+
logger.warn(`[DB] Failed to get report, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
7102
|
+
}
|
|
7103
|
+
const fileStorageId = reportId || String(numericId);
|
|
7104
|
+
const report = reportManager2.getReport(fileStorageId);
|
|
6665
7105
|
if (!report) {
|
|
6666
7106
|
sendResponse5(id, {
|
|
6667
7107
|
success: false,
|
|
6668
|
-
error: `Report '${
|
|
7108
|
+
error: `Report '${fileStorageId}' not found`
|
|
6669
7109
|
}, sendMessage, clientId);
|
|
6670
7110
|
return;
|
|
6671
7111
|
}
|
|
6672
|
-
logger.info(`
|
|
7112
|
+
logger.info(`[FILE] Retrieved report: ${fileStorageId}`);
|
|
6673
7113
|
sendResponse5(id, {
|
|
6674
7114
|
success: true,
|
|
6675
7115
|
data: {
|
|
6676
|
-
|
|
7116
|
+
id: numericId,
|
|
7117
|
+
reportId: fileStorageId,
|
|
6677
7118
|
report,
|
|
6678
|
-
message: `Retrieved report '${
|
|
7119
|
+
message: `Retrieved report '${fileStorageId}' (File)`
|
|
7120
|
+
}
|
|
7121
|
+
}, sendMessage, clientId);
|
|
7122
|
+
}
|
|
7123
|
+
async function handleQuery2(id, filters, limit, sort, executeCollection, reportManager2, sendMessage, clientId) {
|
|
7124
|
+
try {
|
|
7125
|
+
const result = await executeCollection("reports", "query", {
|
|
7126
|
+
filters: filters || {},
|
|
7127
|
+
limit,
|
|
7128
|
+
sort
|
|
7129
|
+
});
|
|
7130
|
+
if (result && result.success) {
|
|
7131
|
+
logger.info(`[DB] Query returned ${result.count} reports`);
|
|
7132
|
+
sendResponse5(id, {
|
|
7133
|
+
success: true,
|
|
7134
|
+
data: {
|
|
7135
|
+
reports: result.data,
|
|
7136
|
+
count: result.count,
|
|
7137
|
+
message: `Query returned ${result.count} reports (DB)`
|
|
7138
|
+
}
|
|
7139
|
+
}, sendMessage, clientId);
|
|
7140
|
+
return;
|
|
7141
|
+
}
|
|
7142
|
+
} catch (dbError) {
|
|
7143
|
+
logger.warn(`[DB] Failed to query reports: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
7144
|
+
}
|
|
7145
|
+
const reports = reportManager2.getAllReports();
|
|
7146
|
+
logger.info(`[FILE] Retrieved ${reports.length} reports (all - no query filter)`);
|
|
7147
|
+
sendResponse5(id, {
|
|
7148
|
+
success: true,
|
|
7149
|
+
data: {
|
|
7150
|
+
reports,
|
|
7151
|
+
count: reports.length,
|
|
7152
|
+
message: `Retrieved ${reports.length} reports (File - no query filter)`
|
|
6679
7153
|
}
|
|
6680
7154
|
}, sendMessage, clientId);
|
|
6681
7155
|
}
|
|
@@ -6695,6 +7169,297 @@ function sendResponse5(id, res, sendMessage, clientId) {
|
|
|
6695
7169
|
sendMessage(response);
|
|
6696
7170
|
}
|
|
6697
7171
|
|
|
7172
|
+
// src/handlers/uis.ts
|
|
7173
|
+
async function handleUIsRequest(data, collections, sendMessage) {
|
|
7174
|
+
const executeCollection = async (collection, op, params) => {
|
|
7175
|
+
const handler = collections[collection]?.[op];
|
|
7176
|
+
if (!handler) {
|
|
7177
|
+
throw new Error(`Collection handler not found: ${collection}.${op}`);
|
|
7178
|
+
}
|
|
7179
|
+
return await handler(params);
|
|
7180
|
+
};
|
|
7181
|
+
try {
|
|
7182
|
+
const request = UIsRequestMessageSchema.parse(data);
|
|
7183
|
+
const { id, payload, from } = request;
|
|
7184
|
+
const { operation, data: requestData } = payload;
|
|
7185
|
+
const uiId = requestData?.uiId;
|
|
7186
|
+
const ui = requestData?.ui;
|
|
7187
|
+
const projectId = requestData?.projectId;
|
|
7188
|
+
const name = requestData?.name;
|
|
7189
|
+
const description = requestData?.description;
|
|
7190
|
+
const createdBy = requestData?.createdBy;
|
|
7191
|
+
const updatedBy = requestData?.updatedBy;
|
|
7192
|
+
const numericId = requestData?.id;
|
|
7193
|
+
const filters = requestData?.filters;
|
|
7194
|
+
const limit = requestData?.limit;
|
|
7195
|
+
const sort = requestData?.sort;
|
|
7196
|
+
if (from.type !== "admin") {
|
|
7197
|
+
sendResponse6(id, {
|
|
7198
|
+
success: false,
|
|
7199
|
+
error: "Unauthorized: Only admin can manage UIs"
|
|
7200
|
+
}, sendMessage, from.id);
|
|
7201
|
+
logger.warn(`Unauthorized UI management attempt from: ${from.type}`);
|
|
7202
|
+
return;
|
|
7203
|
+
}
|
|
7204
|
+
switch (operation) {
|
|
7205
|
+
case "create":
|
|
7206
|
+
await handleCreate4(id, uiId, ui, projectId, name, description, createdBy, executeCollection, sendMessage, from.id);
|
|
7207
|
+
break;
|
|
7208
|
+
case "update":
|
|
7209
|
+
await handleUpdate4(id, numericId, ui, name, description, updatedBy, executeCollection, sendMessage, from.id);
|
|
7210
|
+
break;
|
|
7211
|
+
case "delete":
|
|
7212
|
+
await handleDelete4(id, numericId, executeCollection, sendMessage, from.id);
|
|
7213
|
+
break;
|
|
7214
|
+
case "getAll":
|
|
7215
|
+
await handleGetAll4(id, executeCollection, sendMessage, from.id);
|
|
7216
|
+
break;
|
|
7217
|
+
case "getOne":
|
|
7218
|
+
await handleGetOne4(id, numericId, executeCollection, sendMessage, from.id);
|
|
7219
|
+
break;
|
|
7220
|
+
case "query":
|
|
7221
|
+
await handleQuery3(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
7222
|
+
break;
|
|
7223
|
+
default:
|
|
7224
|
+
sendResponse6(id, {
|
|
7225
|
+
success: false,
|
|
7226
|
+
error: `Unknown operation: ${operation}`
|
|
7227
|
+
}, sendMessage, from.id);
|
|
7228
|
+
}
|
|
7229
|
+
} catch (error) {
|
|
7230
|
+
logger.error("Failed to handle UIs request:", error);
|
|
7231
|
+
sendResponse6(null, {
|
|
7232
|
+
success: false,
|
|
7233
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
7234
|
+
}, sendMessage);
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
async function handleCreate4(id, uiId, ui, projectId, name, description, createdBy, executeCollection, sendMessage, clientId) {
|
|
7238
|
+
if (!uiId || uiId.trim().length === 0) {
|
|
7239
|
+
sendResponse6(id, {
|
|
7240
|
+
success: false,
|
|
7241
|
+
error: "UI ID is required and cannot be empty"
|
|
7242
|
+
}, sendMessage, clientId);
|
|
7243
|
+
return;
|
|
7244
|
+
}
|
|
7245
|
+
if (!projectId || projectId.trim().length === 0) {
|
|
7246
|
+
sendResponse6(id, {
|
|
7247
|
+
success: false,
|
|
7248
|
+
error: "Project ID is required and cannot be empty"
|
|
7249
|
+
}, sendMessage, clientId);
|
|
7250
|
+
return;
|
|
7251
|
+
}
|
|
7252
|
+
try {
|
|
7253
|
+
const result = await executeCollection("uis", "create", {
|
|
7254
|
+
uiId,
|
|
7255
|
+
projectId,
|
|
7256
|
+
name: name || uiId,
|
|
7257
|
+
description,
|
|
7258
|
+
ui,
|
|
7259
|
+
createdBy
|
|
7260
|
+
});
|
|
7261
|
+
if (result && result.success) {
|
|
7262
|
+
logger.info(`UI created successfully, ID: ${result.data?.id}`);
|
|
7263
|
+
sendResponse6(id, {
|
|
7264
|
+
success: true,
|
|
7265
|
+
data: {
|
|
7266
|
+
id: result.data?.id,
|
|
7267
|
+
uiId: result.data?.uiId || uiId,
|
|
7268
|
+
ui: result.data?.ui || ui,
|
|
7269
|
+
message: `UI created successfully`
|
|
7270
|
+
}
|
|
7271
|
+
}, sendMessage, clientId);
|
|
7272
|
+
} else {
|
|
7273
|
+
sendResponse6(id, {
|
|
7274
|
+
success: false,
|
|
7275
|
+
error: "Failed to create UI"
|
|
7276
|
+
}, sendMessage, clientId);
|
|
7277
|
+
}
|
|
7278
|
+
} catch (error) {
|
|
7279
|
+
sendResponse6(id, {
|
|
7280
|
+
success: false,
|
|
7281
|
+
error: error instanceof Error ? error.message : "Failed to create UI"
|
|
7282
|
+
}, sendMessage, clientId);
|
|
7283
|
+
}
|
|
7284
|
+
}
|
|
7285
|
+
async function handleUpdate4(id, numericId, ui, name, description, updatedBy, executeCollection, sendMessage, clientId) {
|
|
7286
|
+
if (!numericId) {
|
|
7287
|
+
sendResponse6(id, {
|
|
7288
|
+
success: false,
|
|
7289
|
+
error: "UI ID is required"
|
|
7290
|
+
}, sendMessage, clientId);
|
|
7291
|
+
return;
|
|
7292
|
+
}
|
|
7293
|
+
try {
|
|
7294
|
+
const result = await executeCollection("uis", "update", {
|
|
7295
|
+
id: numericId,
|
|
7296
|
+
name,
|
|
7297
|
+
description,
|
|
7298
|
+
ui,
|
|
7299
|
+
updatedBy
|
|
7300
|
+
});
|
|
7301
|
+
if (result && result.success) {
|
|
7302
|
+
logger.info(`UI updated successfully, ID: ${numericId}`);
|
|
7303
|
+
sendResponse6(id, {
|
|
7304
|
+
success: true,
|
|
7305
|
+
data: {
|
|
7306
|
+
id: numericId,
|
|
7307
|
+
uiId: result.data?.uiId,
|
|
7308
|
+
ui: result.data?.ui || ui,
|
|
7309
|
+
message: `UI updated successfully`
|
|
7310
|
+
}
|
|
7311
|
+
}, sendMessage, clientId);
|
|
7312
|
+
} else {
|
|
7313
|
+
sendResponse6(id, {
|
|
7314
|
+
success: false,
|
|
7315
|
+
error: "Failed to update UI"
|
|
7316
|
+
}, sendMessage, clientId);
|
|
7317
|
+
}
|
|
7318
|
+
} catch (error) {
|
|
7319
|
+
sendResponse6(id, {
|
|
7320
|
+
success: false,
|
|
7321
|
+
error: error instanceof Error ? error.message : "Failed to update UI"
|
|
7322
|
+
}, sendMessage, clientId);
|
|
7323
|
+
}
|
|
7324
|
+
}
|
|
7325
|
+
async function handleDelete4(id, numericId, executeCollection, sendMessage, clientId) {
|
|
7326
|
+
if (!numericId) {
|
|
7327
|
+
sendResponse6(id, {
|
|
7328
|
+
success: false,
|
|
7329
|
+
error: "UI ID is required"
|
|
7330
|
+
}, sendMessage, clientId);
|
|
7331
|
+
return;
|
|
7332
|
+
}
|
|
7333
|
+
try {
|
|
7334
|
+
const result = await executeCollection("uis", "delete", { id: numericId });
|
|
7335
|
+
if (result && result.success) {
|
|
7336
|
+
logger.info(`UI deleted successfully, ID: ${numericId}`);
|
|
7337
|
+
sendResponse6(id, {
|
|
7338
|
+
success: true,
|
|
7339
|
+
data: {
|
|
7340
|
+
id: numericId,
|
|
7341
|
+
message: `UI deleted successfully`
|
|
7342
|
+
}
|
|
7343
|
+
}, sendMessage, clientId);
|
|
7344
|
+
} else {
|
|
7345
|
+
sendResponse6(id, {
|
|
7346
|
+
success: false,
|
|
7347
|
+
error: "Failed to delete UI"
|
|
7348
|
+
}, sendMessage, clientId);
|
|
7349
|
+
}
|
|
7350
|
+
} catch (error) {
|
|
7351
|
+
sendResponse6(id, {
|
|
7352
|
+
success: false,
|
|
7353
|
+
error: error instanceof Error ? error.message : "Failed to delete UI"
|
|
7354
|
+
}, sendMessage, clientId);
|
|
7355
|
+
}
|
|
7356
|
+
}
|
|
7357
|
+
async function handleGetAll4(id, executeCollection, sendMessage, clientId) {
|
|
7358
|
+
try {
|
|
7359
|
+
const result = await executeCollection("uis", "getAll", {});
|
|
7360
|
+
if (result && result.success) {
|
|
7361
|
+
logger.info(`Retrieved ${result.count} UIs`);
|
|
7362
|
+
sendResponse6(id, {
|
|
7363
|
+
success: true,
|
|
7364
|
+
data: {
|
|
7365
|
+
uis: result.data,
|
|
7366
|
+
count: result.count,
|
|
7367
|
+
message: `Retrieved ${result.count} UIs`
|
|
7368
|
+
}
|
|
7369
|
+
}, sendMessage, clientId);
|
|
7370
|
+
} else {
|
|
7371
|
+
sendResponse6(id, {
|
|
7372
|
+
success: false,
|
|
7373
|
+
error: "Failed to get UIs"
|
|
7374
|
+
}, sendMessage, clientId);
|
|
7375
|
+
}
|
|
7376
|
+
} catch (error) {
|
|
7377
|
+
sendResponse6(id, {
|
|
7378
|
+
success: false,
|
|
7379
|
+
error: error instanceof Error ? error.message : "Failed to get UIs"
|
|
7380
|
+
}, sendMessage, clientId);
|
|
7381
|
+
}
|
|
7382
|
+
}
|
|
7383
|
+
async function handleGetOne4(id, numericId, executeCollection, sendMessage, clientId) {
|
|
7384
|
+
if (!numericId) {
|
|
7385
|
+
sendResponse6(id, {
|
|
7386
|
+
success: false,
|
|
7387
|
+
error: "UI ID is required"
|
|
7388
|
+
}, sendMessage, clientId);
|
|
7389
|
+
return;
|
|
7390
|
+
}
|
|
7391
|
+
try {
|
|
7392
|
+
const result = await executeCollection("uis", "getOne", { id: numericId });
|
|
7393
|
+
if (result && result.success) {
|
|
7394
|
+
logger.info(`Retrieved UI ID: ${numericId}`);
|
|
7395
|
+
sendResponse6(id, {
|
|
7396
|
+
success: true,
|
|
7397
|
+
data: {
|
|
7398
|
+
id: numericId,
|
|
7399
|
+
uiId: result.data?.uiId,
|
|
7400
|
+
ui: result.data?.ui || result.data,
|
|
7401
|
+
message: `Retrieved UI`
|
|
7402
|
+
}
|
|
7403
|
+
}, sendMessage, clientId);
|
|
7404
|
+
} else {
|
|
7405
|
+
sendResponse6(id, {
|
|
7406
|
+
success: false,
|
|
7407
|
+
error: `UI not found`
|
|
7408
|
+
}, sendMessage, clientId);
|
|
7409
|
+
}
|
|
7410
|
+
} catch (error) {
|
|
7411
|
+
sendResponse6(id, {
|
|
7412
|
+
success: false,
|
|
7413
|
+
error: error instanceof Error ? error.message : "Failed to get UI"
|
|
7414
|
+
}, sendMessage, clientId);
|
|
7415
|
+
}
|
|
7416
|
+
}
|
|
7417
|
+
async function handleQuery3(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
7418
|
+
try {
|
|
7419
|
+
const result = await executeCollection("uis", "query", {
|
|
7420
|
+
filters: filters || {},
|
|
7421
|
+
limit,
|
|
7422
|
+
sort
|
|
7423
|
+
});
|
|
7424
|
+
if (result && result.success) {
|
|
7425
|
+
logger.info(`Query returned ${result.count} UIs`);
|
|
7426
|
+
sendResponse6(id, {
|
|
7427
|
+
success: true,
|
|
7428
|
+
data: {
|
|
7429
|
+
uis: result.data,
|
|
7430
|
+
count: result.count,
|
|
7431
|
+
message: `Query returned ${result.count} UIs`
|
|
7432
|
+
}
|
|
7433
|
+
}, sendMessage, clientId);
|
|
7434
|
+
} else {
|
|
7435
|
+
sendResponse6(id, {
|
|
7436
|
+
success: false,
|
|
7437
|
+
error: "Failed to query UIs"
|
|
7438
|
+
}, sendMessage, clientId);
|
|
7439
|
+
}
|
|
7440
|
+
} catch (error) {
|
|
7441
|
+
sendResponse6(id, {
|
|
7442
|
+
success: false,
|
|
7443
|
+
error: error instanceof Error ? error.message : "Failed to query UIs"
|
|
7444
|
+
}, sendMessage, clientId);
|
|
7445
|
+
}
|
|
7446
|
+
}
|
|
7447
|
+
function sendResponse6(id, res, sendMessage, clientId) {
|
|
7448
|
+
const response = {
|
|
7449
|
+
id: id || "unknown",
|
|
7450
|
+
type: "UIS_RES",
|
|
7451
|
+
from: { type: "data-agent" },
|
|
7452
|
+
to: {
|
|
7453
|
+
type: "admin",
|
|
7454
|
+
id: clientId
|
|
7455
|
+
},
|
|
7456
|
+
payload: {
|
|
7457
|
+
...res
|
|
7458
|
+
}
|
|
7459
|
+
};
|
|
7460
|
+
sendMessage(response);
|
|
7461
|
+
}
|
|
7462
|
+
|
|
6698
7463
|
// src/handlers/bookmarks.ts
|
|
6699
7464
|
async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
6700
7465
|
const executeCollection = async (collection, op, params) => {
|
|
@@ -6711,22 +7476,24 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
|
6711
7476
|
const bookmarkId = requestData?.id;
|
|
6712
7477
|
const userId = requestData?.userId;
|
|
6713
7478
|
const threadId = requestData?.threadId;
|
|
7479
|
+
const name = requestData?.name;
|
|
7480
|
+
const description = requestData?.description;
|
|
6714
7481
|
const uiblock = requestData?.uiblock;
|
|
6715
7482
|
switch (operation) {
|
|
6716
7483
|
case "create":
|
|
6717
|
-
await
|
|
7484
|
+
await handleCreate5(id, userId, threadId, name, description, uiblock, executeCollection, sendMessage, from.id);
|
|
6718
7485
|
break;
|
|
6719
7486
|
case "update":
|
|
6720
|
-
await
|
|
7487
|
+
await handleUpdate5(id, bookmarkId, threadId, name, description, uiblock, executeCollection, sendMessage, from.id);
|
|
6721
7488
|
break;
|
|
6722
7489
|
case "delete":
|
|
6723
|
-
await
|
|
7490
|
+
await handleDelete5(id, bookmarkId, executeCollection, sendMessage, from.id);
|
|
6724
7491
|
break;
|
|
6725
7492
|
case "getAll":
|
|
6726
|
-
await
|
|
7493
|
+
await handleGetAll5(id, executeCollection, sendMessage, from.id);
|
|
6727
7494
|
break;
|
|
6728
7495
|
case "getOne":
|
|
6729
|
-
await
|
|
7496
|
+
await handleGetOne5(id, bookmarkId, executeCollection, sendMessage, from.id);
|
|
6730
7497
|
break;
|
|
6731
7498
|
case "getByUser":
|
|
6732
7499
|
await handleGetByUser(id, userId, threadId, executeCollection, sendMessage, from.id);
|
|
@@ -6735,82 +7502,75 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
|
6735
7502
|
await handleGetByThread(id, threadId, executeCollection, sendMessage, from.id);
|
|
6736
7503
|
break;
|
|
6737
7504
|
default:
|
|
6738
|
-
|
|
7505
|
+
sendResponse7(id, {
|
|
6739
7506
|
success: false,
|
|
6740
7507
|
error: `Unknown operation: ${operation}`
|
|
6741
7508
|
}, sendMessage, from.id);
|
|
6742
7509
|
}
|
|
6743
7510
|
} catch (error) {
|
|
6744
7511
|
logger.error("Failed to handle bookmarks request:", error);
|
|
6745
|
-
|
|
7512
|
+
sendResponse7(null, {
|
|
6746
7513
|
success: false,
|
|
6747
7514
|
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
6748
7515
|
}, sendMessage);
|
|
6749
7516
|
}
|
|
6750
7517
|
}
|
|
6751
|
-
async function
|
|
7518
|
+
async function handleCreate5(id, userId, threadId, name, description, uiblock, executeCollection, sendMessage, clientId) {
|
|
6752
7519
|
if (!userId) {
|
|
6753
|
-
|
|
7520
|
+
sendResponse7(id, {
|
|
6754
7521
|
success: false,
|
|
6755
7522
|
error: "userId is required"
|
|
6756
7523
|
}, sendMessage, clientId);
|
|
6757
7524
|
return;
|
|
6758
7525
|
}
|
|
6759
7526
|
if (!uiblock) {
|
|
6760
|
-
|
|
7527
|
+
sendResponse7(id, {
|
|
6761
7528
|
success: false,
|
|
6762
7529
|
error: "UIBlock data is required"
|
|
6763
7530
|
}, sendMessage, clientId);
|
|
6764
7531
|
return;
|
|
6765
7532
|
}
|
|
6766
7533
|
try {
|
|
6767
|
-
const result = await executeCollection("bookmarks", "create", { userId, threadId, uiblock });
|
|
6768
|
-
|
|
7534
|
+
const result = await executeCollection("bookmarks", "create", { userId, threadId, name, description, uiblock });
|
|
7535
|
+
sendResponse7(id, {
|
|
6769
7536
|
success: true,
|
|
6770
7537
|
data: result.data,
|
|
6771
7538
|
message: "Bookmark created successfully"
|
|
6772
7539
|
}, sendMessage, clientId);
|
|
6773
7540
|
logger.info(`Bookmark created: ID ${result.data.id}`);
|
|
6774
7541
|
} catch (error) {
|
|
6775
|
-
|
|
7542
|
+
sendResponse7(id, {
|
|
6776
7543
|
success: false,
|
|
6777
7544
|
error: error instanceof Error ? error.message : "Failed to create bookmark"
|
|
6778
7545
|
}, sendMessage, clientId);
|
|
6779
7546
|
}
|
|
6780
7547
|
}
|
|
6781
|
-
async function
|
|
7548
|
+
async function handleUpdate5(id, bookmarkId, threadId, name, description, uiblock, executeCollection, sendMessage, clientId) {
|
|
6782
7549
|
if (!bookmarkId) {
|
|
6783
|
-
|
|
7550
|
+
sendResponse7(id, {
|
|
6784
7551
|
success: false,
|
|
6785
7552
|
error: "Bookmark ID is required"
|
|
6786
7553
|
}, sendMessage, clientId);
|
|
6787
7554
|
return;
|
|
6788
7555
|
}
|
|
6789
|
-
if (!uiblock) {
|
|
6790
|
-
sendResponse6(id, {
|
|
6791
|
-
success: false,
|
|
6792
|
-
error: "UIBlock data is required"
|
|
6793
|
-
}, sendMessage, clientId);
|
|
6794
|
-
return;
|
|
6795
|
-
}
|
|
6796
7556
|
try {
|
|
6797
|
-
const result = await executeCollection("bookmarks", "update", { id: bookmarkId, threadId, uiblock });
|
|
6798
|
-
|
|
7557
|
+
const result = await executeCollection("bookmarks", "update", { id: bookmarkId, threadId, name, description, uiblock });
|
|
7558
|
+
sendResponse7(id, {
|
|
6799
7559
|
success: true,
|
|
6800
7560
|
data: result.data,
|
|
6801
7561
|
message: "Bookmark updated successfully"
|
|
6802
7562
|
}, sendMessage, clientId);
|
|
6803
7563
|
logger.info(`Bookmark updated: ID ${bookmarkId}`);
|
|
6804
7564
|
} catch (error) {
|
|
6805
|
-
|
|
7565
|
+
sendResponse7(id, {
|
|
6806
7566
|
success: false,
|
|
6807
7567
|
error: error instanceof Error ? error.message : "Failed to update bookmark"
|
|
6808
7568
|
}, sendMessage, clientId);
|
|
6809
7569
|
}
|
|
6810
7570
|
}
|
|
6811
|
-
async function
|
|
7571
|
+
async function handleDelete5(id, bookmarkId, executeCollection, sendMessage, clientId) {
|
|
6812
7572
|
if (!bookmarkId) {
|
|
6813
|
-
|
|
7573
|
+
sendResponse7(id, {
|
|
6814
7574
|
success: false,
|
|
6815
7575
|
error: "Bookmark ID is required"
|
|
6816
7576
|
}, sendMessage, clientId);
|
|
@@ -6818,23 +7578,23 @@ async function handleDelete4(id, bookmarkId, executeCollection, sendMessage, cli
|
|
|
6818
7578
|
}
|
|
6819
7579
|
try {
|
|
6820
7580
|
const result = await executeCollection("bookmarks", "delete", { id: bookmarkId });
|
|
6821
|
-
|
|
7581
|
+
sendResponse7(id, {
|
|
6822
7582
|
success: true,
|
|
6823
7583
|
data: result.data,
|
|
6824
7584
|
message: "Bookmark deleted successfully"
|
|
6825
7585
|
}, sendMessage, clientId);
|
|
6826
7586
|
logger.info(`Bookmark deleted: ID ${bookmarkId}`);
|
|
6827
7587
|
} catch (error) {
|
|
6828
|
-
|
|
7588
|
+
sendResponse7(id, {
|
|
6829
7589
|
success: false,
|
|
6830
7590
|
error: error instanceof Error ? error.message : "Failed to delete bookmark"
|
|
6831
7591
|
}, sendMessage, clientId);
|
|
6832
7592
|
}
|
|
6833
7593
|
}
|
|
6834
|
-
async function
|
|
7594
|
+
async function handleGetAll5(id, executeCollection, sendMessage, clientId) {
|
|
6835
7595
|
try {
|
|
6836
7596
|
const result = await executeCollection("bookmarks", "getAll", {});
|
|
6837
|
-
|
|
7597
|
+
sendResponse7(id, {
|
|
6838
7598
|
success: true,
|
|
6839
7599
|
data: result.data,
|
|
6840
7600
|
count: result.count,
|
|
@@ -6842,15 +7602,15 @@ async function handleGetAll4(id, executeCollection, sendMessage, clientId) {
|
|
|
6842
7602
|
}, sendMessage, clientId);
|
|
6843
7603
|
logger.info(`Retrieved all bookmarks (count: ${result.count})`);
|
|
6844
7604
|
} catch (error) {
|
|
6845
|
-
|
|
7605
|
+
sendResponse7(id, {
|
|
6846
7606
|
success: false,
|
|
6847
7607
|
error: error instanceof Error ? error.message : "Failed to get bookmarks"
|
|
6848
7608
|
}, sendMessage, clientId);
|
|
6849
7609
|
}
|
|
6850
7610
|
}
|
|
6851
|
-
async function
|
|
7611
|
+
async function handleGetOne5(id, bookmarkId, executeCollection, sendMessage, clientId) {
|
|
6852
7612
|
if (!bookmarkId) {
|
|
6853
|
-
|
|
7613
|
+
sendResponse7(id, {
|
|
6854
7614
|
success: false,
|
|
6855
7615
|
error: "Bookmark ID is required"
|
|
6856
7616
|
}, sendMessage, clientId);
|
|
@@ -6858,14 +7618,14 @@ async function handleGetOne4(id, bookmarkId, executeCollection, sendMessage, cli
|
|
|
6858
7618
|
}
|
|
6859
7619
|
try {
|
|
6860
7620
|
const result = await executeCollection("bookmarks", "getOne", { id: bookmarkId });
|
|
6861
|
-
|
|
7621
|
+
sendResponse7(id, {
|
|
6862
7622
|
success: true,
|
|
6863
7623
|
data: result.data,
|
|
6864
7624
|
message: `Retrieved bookmark ID ${bookmarkId}`
|
|
6865
7625
|
}, sendMessage, clientId);
|
|
6866
7626
|
logger.info(`Retrieved bookmark: ID ${bookmarkId}`);
|
|
6867
7627
|
} catch (error) {
|
|
6868
|
-
|
|
7628
|
+
sendResponse7(id, {
|
|
6869
7629
|
success: false,
|
|
6870
7630
|
error: error instanceof Error ? error.message : "Failed to get bookmark"
|
|
6871
7631
|
}, sendMessage, clientId);
|
|
@@ -6873,7 +7633,7 @@ async function handleGetOne4(id, bookmarkId, executeCollection, sendMessage, cli
|
|
|
6873
7633
|
}
|
|
6874
7634
|
async function handleGetByUser(id, userId, threadId, executeCollection, sendMessage, clientId) {
|
|
6875
7635
|
if (!userId) {
|
|
6876
|
-
|
|
7636
|
+
sendResponse7(id, {
|
|
6877
7637
|
success: false,
|
|
6878
7638
|
error: "userId is required"
|
|
6879
7639
|
}, sendMessage, clientId);
|
|
@@ -6881,7 +7641,7 @@ async function handleGetByUser(id, userId, threadId, executeCollection, sendMess
|
|
|
6881
7641
|
}
|
|
6882
7642
|
try {
|
|
6883
7643
|
const result = await executeCollection("bookmarks", "getByUser", { userId, threadId });
|
|
6884
|
-
|
|
7644
|
+
sendResponse7(id, {
|
|
6885
7645
|
success: true,
|
|
6886
7646
|
data: result.data,
|
|
6887
7647
|
count: result.count,
|
|
@@ -6889,7 +7649,7 @@ async function handleGetByUser(id, userId, threadId, executeCollection, sendMess
|
|
|
6889
7649
|
}, sendMessage, clientId);
|
|
6890
7650
|
logger.info(`Retrieved bookmarks for user ${userId} (count: ${result.count})`);
|
|
6891
7651
|
} catch (error) {
|
|
6892
|
-
|
|
7652
|
+
sendResponse7(id, {
|
|
6893
7653
|
success: false,
|
|
6894
7654
|
error: error instanceof Error ? error.message : "Failed to get bookmarks by user"
|
|
6895
7655
|
}, sendMessage, clientId);
|
|
@@ -6897,7 +7657,7 @@ async function handleGetByUser(id, userId, threadId, executeCollection, sendMess
|
|
|
6897
7657
|
}
|
|
6898
7658
|
async function handleGetByThread(id, threadId, executeCollection, sendMessage, clientId) {
|
|
6899
7659
|
if (!threadId) {
|
|
6900
|
-
|
|
7660
|
+
sendResponse7(id, {
|
|
6901
7661
|
success: false,
|
|
6902
7662
|
error: "threadId is required"
|
|
6903
7663
|
}, sendMessage, clientId);
|
|
@@ -6905,7 +7665,7 @@ async function handleGetByThread(id, threadId, executeCollection, sendMessage, c
|
|
|
6905
7665
|
}
|
|
6906
7666
|
try {
|
|
6907
7667
|
const result = await executeCollection("bookmarks", "getByThread", { threadId });
|
|
6908
|
-
|
|
7668
|
+
sendResponse7(id, {
|
|
6909
7669
|
success: true,
|
|
6910
7670
|
data: result.data,
|
|
6911
7671
|
count: result.count,
|
|
@@ -6913,13 +7673,13 @@ async function handleGetByThread(id, threadId, executeCollection, sendMessage, c
|
|
|
6913
7673
|
}, sendMessage, clientId);
|
|
6914
7674
|
logger.info(`Retrieved bookmarks for thread ${threadId} (count: ${result.count})`);
|
|
6915
7675
|
} catch (error) {
|
|
6916
|
-
|
|
7676
|
+
sendResponse7(id, {
|
|
6917
7677
|
success: false,
|
|
6918
7678
|
error: error instanceof Error ? error.message : "Failed to get bookmarks by thread"
|
|
6919
7679
|
}, sendMessage, clientId);
|
|
6920
7680
|
}
|
|
6921
7681
|
}
|
|
6922
|
-
function
|
|
7682
|
+
function sendResponse7(id, res, sendMessage, clientId) {
|
|
6923
7683
|
const response = {
|
|
6924
7684
|
id: id || "unknown",
|
|
6925
7685
|
type: "BOOKMARKS_RES",
|
|
@@ -7930,12 +8690,12 @@ var SuperatomSDK = class {
|
|
|
7930
8690
|
});
|
|
7931
8691
|
break;
|
|
7932
8692
|
case "USER_PROMPT_SUGGESTIONS_REQ":
|
|
7933
|
-
handleUserPromptSuggestions(parsed, this.components, (msg) => this.send(msg)).catch((error) => {
|
|
8693
|
+
handleUserPromptSuggestions(parsed, this.components, (msg) => this.send(msg), this.collections, this.userId).catch((error) => {
|
|
7934
8694
|
logger.error("Failed to handle user prompt suggestions request:", error);
|
|
7935
8695
|
});
|
|
7936
8696
|
break;
|
|
7937
8697
|
case "COMPONENT_LIST_RES":
|
|
7938
|
-
handleComponentListResponse(parsed, (com) => this.storeComponents(com)).catch((error) => {
|
|
8698
|
+
handleComponentListResponse(parsed, (com) => this.storeComponents(com), this.collections).catch((error) => {
|
|
7939
8699
|
logger.error("Failed to handle component list request:", error);
|
|
7940
8700
|
});
|
|
7941
8701
|
break;
|
|
@@ -7945,15 +8705,20 @@ var SuperatomSDK = class {
|
|
|
7945
8705
|
});
|
|
7946
8706
|
break;
|
|
7947
8707
|
case "DASHBOARDS":
|
|
7948
|
-
handleDashboardsRequest(parsed, (msg) => this.send(msg)).catch((error) => {
|
|
8708
|
+
handleDashboardsRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
7949
8709
|
logger.error("Failed to handle dashboards request:", error);
|
|
7950
8710
|
});
|
|
7951
8711
|
break;
|
|
7952
8712
|
case "REPORTS":
|
|
7953
|
-
handleReportsRequest(parsed, (msg) => this.send(msg)).catch((error) => {
|
|
8713
|
+
handleReportsRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
7954
8714
|
logger.error("Failed to handle reports request:", error);
|
|
7955
8715
|
});
|
|
7956
8716
|
break;
|
|
8717
|
+
case "UIS":
|
|
8718
|
+
handleUIsRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
8719
|
+
logger.error("Failed to handle UIs request:", error);
|
|
8720
|
+
});
|
|
8721
|
+
break;
|
|
7957
8722
|
case "BOOKMARKS":
|
|
7958
8723
|
handleBookmarksRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
7959
8724
|
logger.error("Failed to handle bookmarks request:", error);
|