@superatomai/sdk-node 0.0.22 → 0.0.24
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 +130 -1
- package/dist/index.d.ts +130 -1
- package/dist/index.js +520 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +520 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -702,6 +702,36 @@ var BookmarksRequestMessageSchema = import_zod3.z.object({
|
|
|
702
702
|
type: import_zod3.z.literal("BOOKMARKS"),
|
|
703
703
|
payload: BookmarksRequestPayloadSchema
|
|
704
704
|
});
|
|
705
|
+
var KbNodesQueryFiltersSchema = import_zod3.z.object({
|
|
706
|
+
query: import_zod3.z.string().optional(),
|
|
707
|
+
category: import_zod3.z.string().optional(),
|
|
708
|
+
tags: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
709
|
+
createdBy: import_zod3.z.number().optional()
|
|
710
|
+
});
|
|
711
|
+
var KbNodesRequestPayloadSchema = import_zod3.z.object({
|
|
712
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "search", "getByCategory", "getByUser", "getCategories", "getTags"]),
|
|
713
|
+
data: import_zod3.z.object({
|
|
714
|
+
id: import_zod3.z.number().optional(),
|
|
715
|
+
title: import_zod3.z.string().optional(),
|
|
716
|
+
content: import_zod3.z.string().optional(),
|
|
717
|
+
category: import_zod3.z.string().optional(),
|
|
718
|
+
tags: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
719
|
+
createdBy: import_zod3.z.number().optional(),
|
|
720
|
+
updatedBy: import_zod3.z.number().optional(),
|
|
721
|
+
userId: import_zod3.z.number().optional(),
|
|
722
|
+
// Query/search operation fields
|
|
723
|
+
query: import_zod3.z.string().optional(),
|
|
724
|
+
filters: KbNodesQueryFiltersSchema.optional(),
|
|
725
|
+
limit: import_zod3.z.number().optional(),
|
|
726
|
+
offset: import_zod3.z.number().optional()
|
|
727
|
+
}).optional()
|
|
728
|
+
});
|
|
729
|
+
var KbNodesRequestMessageSchema = import_zod3.z.object({
|
|
730
|
+
id: import_zod3.z.string(),
|
|
731
|
+
from: MessageParticipantSchema,
|
|
732
|
+
type: import_zod3.z.literal("KB_NODES"),
|
|
733
|
+
payload: KbNodesRequestPayloadSchema
|
|
734
|
+
});
|
|
705
735
|
|
|
706
736
|
// src/utils/logger.ts
|
|
707
737
|
var import_fs = __toESM(require("fs"));
|
|
@@ -5723,7 +5753,7 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5723
5753
|
try {
|
|
5724
5754
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5725
5755
|
const { id, payload, from } = request;
|
|
5726
|
-
const { prompt, limit =
|
|
5756
|
+
const { prompt, limit = 10 } = payload;
|
|
5727
5757
|
const wsId = from.id;
|
|
5728
5758
|
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5729
5759
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -5733,48 +5763,37 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5733
5763
|
}, sendMessage, wsId);
|
|
5734
5764
|
return;
|
|
5735
5765
|
}
|
|
5736
|
-
const
|
|
5737
|
-
const
|
|
5766
|
+
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5767
|
+
const bookmarkTextSearchHandler = collections?.["bookmarks"]?.["textSearch"];
|
|
5768
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based search for components (${displayComponents.length} display components) and PostgreSQL text search for bookmarks`);
|
|
5769
|
+
const searchPromises = [];
|
|
5738
5770
|
let componentSuggestions = [];
|
|
5739
5771
|
let bookmarkSuggestions = [];
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
componentSuggestions = result.suggestions.map((s) => ({
|
|
5750
|
-
...s,
|
|
5751
|
-
suggestionType: "component"
|
|
5752
|
-
}));
|
|
5753
|
-
useEmbeddingSearch = true;
|
|
5754
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions`);
|
|
5755
|
-
}
|
|
5756
|
-
} catch (embeddingError) {
|
|
5757
|
-
logger.warn("Component embedding search failed:", embeddingError);
|
|
5758
|
-
}
|
|
5759
|
-
})()
|
|
5760
|
-
);
|
|
5772
|
+
if (displayComponents.length > 0) {
|
|
5773
|
+
const componentResults = searchComponents(prompt, displayComponents, limit);
|
|
5774
|
+
componentSuggestions = componentResults.map((c) => ({
|
|
5775
|
+
...c,
|
|
5776
|
+
suggestionType: "component",
|
|
5777
|
+
similarity: 1
|
|
5778
|
+
// Token-based search doesn't have similarity scores
|
|
5779
|
+
}));
|
|
5780
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions via token search`);
|
|
5761
5781
|
}
|
|
5762
|
-
if (
|
|
5782
|
+
if (bookmarkTextSearchHandler && userId && userId !== "anonymous") {
|
|
5763
5783
|
searchPromises.push(
|
|
5764
5784
|
(async () => {
|
|
5765
5785
|
try {
|
|
5766
|
-
logger.info(`Using
|
|
5767
|
-
const result = await
|
|
5786
|
+
logger.info(`Using PostgreSQL text search for bookmarks (user: ${userId})`);
|
|
5787
|
+
const result = await bookmarkTextSearchHandler({ prompt, userId, limit });
|
|
5768
5788
|
if (result.success && result.suggestions) {
|
|
5769
5789
|
bookmarkSuggestions = result.suggestions.map((s) => ({
|
|
5770
5790
|
...s,
|
|
5771
5791
|
suggestionType: "bookmark"
|
|
5772
5792
|
}));
|
|
5773
|
-
|
|
5774
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions`);
|
|
5793
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions via PostgreSQL text search`);
|
|
5775
5794
|
}
|
|
5776
|
-
} catch (
|
|
5777
|
-
logger.warn("Bookmark
|
|
5795
|
+
} catch (searchError) {
|
|
5796
|
+
logger.warn("Bookmark PostgreSQL text search failed:", searchError);
|
|
5778
5797
|
}
|
|
5779
5798
|
})()
|
|
5780
5799
|
);
|
|
@@ -5782,44 +5801,33 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5782
5801
|
if (searchPromises.length > 0) {
|
|
5783
5802
|
await Promise.all(searchPromises);
|
|
5784
5803
|
}
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
success: true,
|
|
5790
|
-
data: {
|
|
5791
|
-
prompt,
|
|
5792
|
-
suggestions: allSuggestions,
|
|
5793
|
-
count: allSuggestions.length,
|
|
5794
|
-
componentCount: componentSuggestions.length,
|
|
5795
|
-
bookmarkCount: bookmarkSuggestions.length,
|
|
5796
|
-
message: `Found ${allSuggestions.length} suggestions (${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks)`
|
|
5797
|
-
}
|
|
5798
|
-
}, sendMessage, wsId);
|
|
5799
|
-
return;
|
|
5800
|
-
}
|
|
5801
|
-
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5802
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based approach. Display components: ${displayComponents.length}`);
|
|
5803
|
-
if (!displayComponents || displayComponents.length === 0) {
|
|
5804
|
+
const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].slice(0, limit);
|
|
5805
|
+
const finalComponentCount = allSuggestions.filter((s) => s.suggestionType === "component").length;
|
|
5806
|
+
const finalBookmarkCount = allSuggestions.filter((s) => s.suggestionType === "bookmark").length;
|
|
5807
|
+
if (allSuggestions.length === 0) {
|
|
5804
5808
|
sendResponse(id, {
|
|
5805
5809
|
success: true,
|
|
5806
5810
|
data: {
|
|
5807
5811
|
prompt,
|
|
5808
5812
|
suggestions: [],
|
|
5809
5813
|
count: 0,
|
|
5810
|
-
|
|
5814
|
+
componentCount: 0,
|
|
5815
|
+
bookmarkCount: 0,
|
|
5816
|
+
message: "No matching suggestions found"
|
|
5811
5817
|
}
|
|
5812
5818
|
}, sendMessage, wsId);
|
|
5813
5819
|
return;
|
|
5814
5820
|
}
|
|
5815
|
-
|
|
5821
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning ${allSuggestions.length} suggestions: ${finalComponentCount} components, ${finalBookmarkCount} bookmarks`);
|
|
5816
5822
|
sendResponse(id, {
|
|
5817
5823
|
success: true,
|
|
5818
5824
|
data: {
|
|
5819
5825
|
prompt,
|
|
5820
|
-
suggestions,
|
|
5821
|
-
count:
|
|
5822
|
-
|
|
5826
|
+
suggestions: allSuggestions,
|
|
5827
|
+
count: allSuggestions.length,
|
|
5828
|
+
componentCount: finalComponentCount,
|
|
5829
|
+
bookmarkCount: finalBookmarkCount,
|
|
5830
|
+
message: `Found ${allSuggestions.length} suggestions (${finalComponentCount} components, ${finalBookmarkCount} bookmarks)`
|
|
5823
5831
|
}
|
|
5824
5832
|
}, sendMessage, wsId);
|
|
5825
5833
|
} catch (error) {
|
|
@@ -7907,6 +7915,458 @@ function sendResponse7(id, res, sendMessage, clientId) {
|
|
|
7907
7915
|
sendMessage(response);
|
|
7908
7916
|
}
|
|
7909
7917
|
|
|
7918
|
+
// src/handlers/kb-nodes.ts
|
|
7919
|
+
async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
7920
|
+
const executeCollection = async (collection, op, params) => {
|
|
7921
|
+
const handler = collections[collection]?.[op];
|
|
7922
|
+
if (!handler) {
|
|
7923
|
+
throw new Error(`Collection '${collection}' or operation '${op}' not found`);
|
|
7924
|
+
}
|
|
7925
|
+
return await handler(params);
|
|
7926
|
+
};
|
|
7927
|
+
try {
|
|
7928
|
+
const request = KbNodesRequestMessageSchema.parse(data);
|
|
7929
|
+
const { id, payload, from } = request;
|
|
7930
|
+
const { operation, data: requestData } = payload;
|
|
7931
|
+
const nodeId = requestData?.id;
|
|
7932
|
+
const title = requestData?.title;
|
|
7933
|
+
const content = requestData?.content;
|
|
7934
|
+
const category = requestData?.category;
|
|
7935
|
+
const tags = requestData?.tags;
|
|
7936
|
+
const createdBy = requestData?.createdBy;
|
|
7937
|
+
const updatedBy = requestData?.updatedBy;
|
|
7938
|
+
const userId = requestData?.userId;
|
|
7939
|
+
const query = requestData?.query;
|
|
7940
|
+
const filters = requestData?.filters;
|
|
7941
|
+
const limit = requestData?.limit;
|
|
7942
|
+
const offset = requestData?.offset;
|
|
7943
|
+
switch (operation) {
|
|
7944
|
+
case "create":
|
|
7945
|
+
await handleCreate6(id, { title, content, category, tags, createdBy }, executeCollection, sendMessage, from.id);
|
|
7946
|
+
break;
|
|
7947
|
+
case "update":
|
|
7948
|
+
await handleUpdate6(id, nodeId, { title, content, category, tags, updatedBy }, executeCollection, sendMessage, from.id);
|
|
7949
|
+
break;
|
|
7950
|
+
case "delete":
|
|
7951
|
+
await handleDelete6(id, nodeId, executeCollection, sendMessage, from.id);
|
|
7952
|
+
break;
|
|
7953
|
+
case "getAll":
|
|
7954
|
+
await handleGetAll6(id, limit, offset, executeCollection, sendMessage, from.id);
|
|
7955
|
+
break;
|
|
7956
|
+
case "getOne":
|
|
7957
|
+
await handleGetOne6(id, nodeId, executeCollection, sendMessage, from.id);
|
|
7958
|
+
break;
|
|
7959
|
+
case "search":
|
|
7960
|
+
await handleSearch(id, { query, category, tags, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
7961
|
+
break;
|
|
7962
|
+
case "getByCategory":
|
|
7963
|
+
await handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, from.id);
|
|
7964
|
+
break;
|
|
7965
|
+
case "getByUser":
|
|
7966
|
+
await handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, from.id);
|
|
7967
|
+
break;
|
|
7968
|
+
case "getCategories":
|
|
7969
|
+
await handleGetCategories(id, executeCollection, sendMessage, from.id);
|
|
7970
|
+
break;
|
|
7971
|
+
case "getTags":
|
|
7972
|
+
await handleGetTags(id, executeCollection, sendMessage, from.id);
|
|
7973
|
+
break;
|
|
7974
|
+
default:
|
|
7975
|
+
sendResponse8(id, {
|
|
7976
|
+
success: false,
|
|
7977
|
+
error: `Unknown operation: ${operation}`
|
|
7978
|
+
}, sendMessage, from.id);
|
|
7979
|
+
}
|
|
7980
|
+
} catch (error) {
|
|
7981
|
+
logger.error("Failed to handle KB nodes request:", error);
|
|
7982
|
+
sendResponse8(null, {
|
|
7983
|
+
success: false,
|
|
7984
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
7985
|
+
}, sendMessage);
|
|
7986
|
+
}
|
|
7987
|
+
}
|
|
7988
|
+
async function handleCreate6(id, nodeData, executeCollection, sendMessage, clientId) {
|
|
7989
|
+
const { title, content, category, tags, createdBy } = nodeData;
|
|
7990
|
+
if (!title || title.trim().length === 0) {
|
|
7991
|
+
sendResponse8(id, {
|
|
7992
|
+
success: false,
|
|
7993
|
+
error: "Title is required and cannot be empty"
|
|
7994
|
+
}, sendMessage, clientId);
|
|
7995
|
+
return;
|
|
7996
|
+
}
|
|
7997
|
+
if (!content || content.trim().length === 0) {
|
|
7998
|
+
sendResponse8(id, {
|
|
7999
|
+
success: false,
|
|
8000
|
+
error: "Content is required and cannot be empty"
|
|
8001
|
+
}, sendMessage, clientId);
|
|
8002
|
+
return;
|
|
8003
|
+
}
|
|
8004
|
+
if (!createdBy) {
|
|
8005
|
+
sendResponse8(id, {
|
|
8006
|
+
success: false,
|
|
8007
|
+
error: "createdBy (user ID) is required"
|
|
8008
|
+
}, sendMessage, clientId);
|
|
8009
|
+
return;
|
|
8010
|
+
}
|
|
8011
|
+
try {
|
|
8012
|
+
const result = await executeCollection("kbNodes", "create", {
|
|
8013
|
+
title,
|
|
8014
|
+
content,
|
|
8015
|
+
category: category || void 0,
|
|
8016
|
+
tags: tags || void 0,
|
|
8017
|
+
createdBy
|
|
8018
|
+
});
|
|
8019
|
+
if (result && result.success) {
|
|
8020
|
+
logger.info(`[DB] KB node created successfully: ${title}`);
|
|
8021
|
+
sendResponse8(id, {
|
|
8022
|
+
success: true,
|
|
8023
|
+
data: {
|
|
8024
|
+
...result.data,
|
|
8025
|
+
message: `Knowledge node '${title}' created successfully`
|
|
8026
|
+
}
|
|
8027
|
+
}, sendMessage, clientId);
|
|
8028
|
+
return;
|
|
8029
|
+
}
|
|
8030
|
+
sendResponse8(id, {
|
|
8031
|
+
success: false,
|
|
8032
|
+
error: "Failed to create knowledge node"
|
|
8033
|
+
}, sendMessage, clientId);
|
|
8034
|
+
} catch (error) {
|
|
8035
|
+
logger.error("[DB] Failed to create KB node:", error);
|
|
8036
|
+
sendResponse8(id, {
|
|
8037
|
+
success: false,
|
|
8038
|
+
error: error instanceof Error ? error.message : "Failed to create knowledge node"
|
|
8039
|
+
}, sendMessage, clientId);
|
|
8040
|
+
}
|
|
8041
|
+
}
|
|
8042
|
+
async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessage, clientId) {
|
|
8043
|
+
const { title, content, category, tags, updatedBy } = nodeData;
|
|
8044
|
+
if (!nodeId) {
|
|
8045
|
+
sendResponse8(id, {
|
|
8046
|
+
success: false,
|
|
8047
|
+
error: "Knowledge node ID is required"
|
|
8048
|
+
}, sendMessage, clientId);
|
|
8049
|
+
return;
|
|
8050
|
+
}
|
|
8051
|
+
if (!updatedBy) {
|
|
8052
|
+
sendResponse8(id, {
|
|
8053
|
+
success: false,
|
|
8054
|
+
error: "updatedBy (user ID) is required"
|
|
8055
|
+
}, sendMessage, clientId);
|
|
8056
|
+
return;
|
|
8057
|
+
}
|
|
8058
|
+
try {
|
|
8059
|
+
const result = await executeCollection("kbNodes", "update", {
|
|
8060
|
+
id: nodeId,
|
|
8061
|
+
title,
|
|
8062
|
+
content,
|
|
8063
|
+
category,
|
|
8064
|
+
tags,
|
|
8065
|
+
updatedBy
|
|
8066
|
+
});
|
|
8067
|
+
if (result && result.success) {
|
|
8068
|
+
logger.info(`[DB] KB node updated successfully, ID: ${nodeId}`);
|
|
8069
|
+
sendResponse8(id, {
|
|
8070
|
+
success: true,
|
|
8071
|
+
data: {
|
|
8072
|
+
...result.data,
|
|
8073
|
+
message: `Knowledge node updated successfully`
|
|
8074
|
+
}
|
|
8075
|
+
}, sendMessage, clientId);
|
|
8076
|
+
return;
|
|
8077
|
+
}
|
|
8078
|
+
sendResponse8(id, {
|
|
8079
|
+
success: false,
|
|
8080
|
+
error: "Failed to update knowledge node"
|
|
8081
|
+
}, sendMessage, clientId);
|
|
8082
|
+
} catch (error) {
|
|
8083
|
+
logger.error("[DB] Failed to update KB node:", error);
|
|
8084
|
+
sendResponse8(id, {
|
|
8085
|
+
success: false,
|
|
8086
|
+
error: error instanceof Error ? error.message : "Failed to update knowledge node"
|
|
8087
|
+
}, sendMessage, clientId);
|
|
8088
|
+
}
|
|
8089
|
+
}
|
|
8090
|
+
async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
8091
|
+
if (!nodeId) {
|
|
8092
|
+
sendResponse8(id, {
|
|
8093
|
+
success: false,
|
|
8094
|
+
error: "Knowledge node ID is required"
|
|
8095
|
+
}, sendMessage, clientId);
|
|
8096
|
+
return;
|
|
8097
|
+
}
|
|
8098
|
+
try {
|
|
8099
|
+
const result = await executeCollection("kbNodes", "delete", { id: nodeId });
|
|
8100
|
+
if (result && result.success) {
|
|
8101
|
+
logger.info(`[DB] KB node deleted successfully, ID: ${nodeId}`);
|
|
8102
|
+
sendResponse8(id, {
|
|
8103
|
+
success: true,
|
|
8104
|
+
data: {
|
|
8105
|
+
id: nodeId,
|
|
8106
|
+
...result.data,
|
|
8107
|
+
message: `Knowledge node deleted successfully`
|
|
8108
|
+
}
|
|
8109
|
+
}, sendMessage, clientId);
|
|
8110
|
+
return;
|
|
8111
|
+
}
|
|
8112
|
+
sendResponse8(id, {
|
|
8113
|
+
success: false,
|
|
8114
|
+
error: "Failed to delete knowledge node"
|
|
8115
|
+
}, sendMessage, clientId);
|
|
8116
|
+
} catch (error) {
|
|
8117
|
+
logger.error("[DB] Failed to delete KB node:", error);
|
|
8118
|
+
sendResponse8(id, {
|
|
8119
|
+
success: false,
|
|
8120
|
+
error: error instanceof Error ? error.message : "Failed to delete knowledge node"
|
|
8121
|
+
}, sendMessage, clientId);
|
|
8122
|
+
}
|
|
8123
|
+
}
|
|
8124
|
+
async function handleGetAll6(id, limit, offset, executeCollection, sendMessage, clientId) {
|
|
8125
|
+
try {
|
|
8126
|
+
const result = await executeCollection("kbNodes", "getAll", {
|
|
8127
|
+
limit: limit || 100,
|
|
8128
|
+
offset: offset || 0
|
|
8129
|
+
});
|
|
8130
|
+
if (result && result.success) {
|
|
8131
|
+
logger.info(`[DB] Retrieved ${result.count} KB nodes`);
|
|
8132
|
+
sendResponse8(id, {
|
|
8133
|
+
success: true,
|
|
8134
|
+
data: {
|
|
8135
|
+
nodes: result.data,
|
|
8136
|
+
count: result.count,
|
|
8137
|
+
message: `Retrieved ${result.count} knowledge nodes`
|
|
8138
|
+
}
|
|
8139
|
+
}, sendMessage, clientId);
|
|
8140
|
+
return;
|
|
8141
|
+
}
|
|
8142
|
+
sendResponse8(id, {
|
|
8143
|
+
success: false,
|
|
8144
|
+
error: "Failed to retrieve knowledge nodes"
|
|
8145
|
+
}, sendMessage, clientId);
|
|
8146
|
+
} catch (error) {
|
|
8147
|
+
logger.error("[DB] Failed to get all KB nodes:", error);
|
|
8148
|
+
sendResponse8(id, {
|
|
8149
|
+
success: false,
|
|
8150
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes"
|
|
8151
|
+
}, sendMessage, clientId);
|
|
8152
|
+
}
|
|
8153
|
+
}
|
|
8154
|
+
async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
8155
|
+
if (!nodeId) {
|
|
8156
|
+
sendResponse8(id, {
|
|
8157
|
+
success: false,
|
|
8158
|
+
error: "Knowledge node ID is required"
|
|
8159
|
+
}, sendMessage, clientId);
|
|
8160
|
+
return;
|
|
8161
|
+
}
|
|
8162
|
+
try {
|
|
8163
|
+
const result = await executeCollection("kbNodes", "getOne", { id: nodeId });
|
|
8164
|
+
if (result && result.success) {
|
|
8165
|
+
logger.info(`[DB] Retrieved KB node ID: ${nodeId}`);
|
|
8166
|
+
sendResponse8(id, {
|
|
8167
|
+
success: true,
|
|
8168
|
+
data: {
|
|
8169
|
+
node: result.data,
|
|
8170
|
+
message: `Retrieved knowledge node`
|
|
8171
|
+
}
|
|
8172
|
+
}, sendMessage, clientId);
|
|
8173
|
+
return;
|
|
8174
|
+
}
|
|
8175
|
+
sendResponse8(id, {
|
|
8176
|
+
success: false,
|
|
8177
|
+
error: "Failed to retrieve knowledge node"
|
|
8178
|
+
}, sendMessage, clientId);
|
|
8179
|
+
} catch (error) {
|
|
8180
|
+
logger.error("[DB] Failed to get KB node:", error);
|
|
8181
|
+
sendResponse8(id, {
|
|
8182
|
+
success: false,
|
|
8183
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge node"
|
|
8184
|
+
}, sendMessage, clientId);
|
|
8185
|
+
}
|
|
8186
|
+
}
|
|
8187
|
+
async function handleSearch(id, searchParams, executeCollection, sendMessage, clientId) {
|
|
8188
|
+
const { query, category, tags, createdBy, limit, offset } = searchParams;
|
|
8189
|
+
try {
|
|
8190
|
+
const result = await executeCollection("kbNodes", "search", {
|
|
8191
|
+
query,
|
|
8192
|
+
category,
|
|
8193
|
+
tags,
|
|
8194
|
+
createdBy,
|
|
8195
|
+
limit: limit || 50,
|
|
8196
|
+
offset: offset || 0
|
|
8197
|
+
});
|
|
8198
|
+
if (result && result.success) {
|
|
8199
|
+
logger.info(`[DB] Search returned ${result.count} KB nodes`);
|
|
8200
|
+
sendResponse8(id, {
|
|
8201
|
+
success: true,
|
|
8202
|
+
data: {
|
|
8203
|
+
nodes: result.data,
|
|
8204
|
+
count: result.count,
|
|
8205
|
+
message: `Search returned ${result.count} knowledge nodes`
|
|
8206
|
+
}
|
|
8207
|
+
}, sendMessage, clientId);
|
|
8208
|
+
return;
|
|
8209
|
+
}
|
|
8210
|
+
sendResponse8(id, {
|
|
8211
|
+
success: false,
|
|
8212
|
+
error: "Failed to search knowledge nodes"
|
|
8213
|
+
}, sendMessage, clientId);
|
|
8214
|
+
} catch (error) {
|
|
8215
|
+
logger.error("[DB] Failed to search KB nodes:", error);
|
|
8216
|
+
sendResponse8(id, {
|
|
8217
|
+
success: false,
|
|
8218
|
+
error: error instanceof Error ? error.message : "Failed to search knowledge nodes"
|
|
8219
|
+
}, sendMessage, clientId);
|
|
8220
|
+
}
|
|
8221
|
+
}
|
|
8222
|
+
async function handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, clientId) {
|
|
8223
|
+
if (!category) {
|
|
8224
|
+
sendResponse8(id, {
|
|
8225
|
+
success: false,
|
|
8226
|
+
error: "Category is required"
|
|
8227
|
+
}, sendMessage, clientId);
|
|
8228
|
+
return;
|
|
8229
|
+
}
|
|
8230
|
+
try {
|
|
8231
|
+
const result = await executeCollection("kbNodes", "getByCategory", {
|
|
8232
|
+
category,
|
|
8233
|
+
limit: limit || 50,
|
|
8234
|
+
offset: offset || 0
|
|
8235
|
+
});
|
|
8236
|
+
if (result && result.success) {
|
|
8237
|
+
logger.info(`[DB] Retrieved ${result.count} KB nodes for category: ${category}`);
|
|
8238
|
+
sendResponse8(id, {
|
|
8239
|
+
success: true,
|
|
8240
|
+
data: {
|
|
8241
|
+
nodes: result.data,
|
|
8242
|
+
count: result.count,
|
|
8243
|
+
category,
|
|
8244
|
+
message: `Retrieved ${result.count} knowledge nodes for category '${category}'`
|
|
8245
|
+
}
|
|
8246
|
+
}, sendMessage, clientId);
|
|
8247
|
+
return;
|
|
8248
|
+
}
|
|
8249
|
+
sendResponse8(id, {
|
|
8250
|
+
success: false,
|
|
8251
|
+
error: "Failed to retrieve knowledge nodes by category"
|
|
8252
|
+
}, sendMessage, clientId);
|
|
8253
|
+
} catch (error) {
|
|
8254
|
+
logger.error("[DB] Failed to get KB nodes by category:", error);
|
|
8255
|
+
sendResponse8(id, {
|
|
8256
|
+
success: false,
|
|
8257
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by category"
|
|
8258
|
+
}, sendMessage, clientId);
|
|
8259
|
+
}
|
|
8260
|
+
}
|
|
8261
|
+
async function handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, clientId) {
|
|
8262
|
+
if (!userId) {
|
|
8263
|
+
sendResponse8(id, {
|
|
8264
|
+
success: false,
|
|
8265
|
+
error: "User ID is required"
|
|
8266
|
+
}, sendMessage, clientId);
|
|
8267
|
+
return;
|
|
8268
|
+
}
|
|
8269
|
+
try {
|
|
8270
|
+
const result = await executeCollection("kbNodes", "getByUser", {
|
|
8271
|
+
userId,
|
|
8272
|
+
limit: limit || 50,
|
|
8273
|
+
offset: offset || 0
|
|
8274
|
+
});
|
|
8275
|
+
if (result && result.success) {
|
|
8276
|
+
logger.info(`[DB] Retrieved ${result.count} KB nodes for user: ${userId}`);
|
|
8277
|
+
sendResponse8(id, {
|
|
8278
|
+
success: true,
|
|
8279
|
+
data: {
|
|
8280
|
+
nodes: result.data,
|
|
8281
|
+
count: result.count,
|
|
8282
|
+
userId,
|
|
8283
|
+
message: `Retrieved ${result.count} knowledge nodes for user ${userId}`
|
|
8284
|
+
}
|
|
8285
|
+
}, sendMessage, clientId);
|
|
8286
|
+
return;
|
|
8287
|
+
}
|
|
8288
|
+
sendResponse8(id, {
|
|
8289
|
+
success: false,
|
|
8290
|
+
error: "Failed to retrieve knowledge nodes by user"
|
|
8291
|
+
}, sendMessage, clientId);
|
|
8292
|
+
} catch (error) {
|
|
8293
|
+
logger.error("[DB] Failed to get KB nodes by user:", error);
|
|
8294
|
+
sendResponse8(id, {
|
|
8295
|
+
success: false,
|
|
8296
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by user"
|
|
8297
|
+
}, sendMessage, clientId);
|
|
8298
|
+
}
|
|
8299
|
+
}
|
|
8300
|
+
async function handleGetCategories(id, executeCollection, sendMessage, clientId) {
|
|
8301
|
+
try {
|
|
8302
|
+
const result = await executeCollection("kbNodes", "getCategories", {});
|
|
8303
|
+
if (result && result.success) {
|
|
8304
|
+
logger.info(`[DB] Retrieved ${result.count} categories`);
|
|
8305
|
+
sendResponse8(id, {
|
|
8306
|
+
success: true,
|
|
8307
|
+
data: {
|
|
8308
|
+
categories: result.data,
|
|
8309
|
+
count: result.count,
|
|
8310
|
+
message: `Retrieved ${result.count} categories`
|
|
8311
|
+
}
|
|
8312
|
+
}, sendMessage, clientId);
|
|
8313
|
+
return;
|
|
8314
|
+
}
|
|
8315
|
+
sendResponse8(id, {
|
|
8316
|
+
success: false,
|
|
8317
|
+
error: "Failed to retrieve categories"
|
|
8318
|
+
}, sendMessage, clientId);
|
|
8319
|
+
} catch (error) {
|
|
8320
|
+
logger.error("[DB] Failed to get categories:", error);
|
|
8321
|
+
sendResponse8(id, {
|
|
8322
|
+
success: false,
|
|
8323
|
+
error: error instanceof Error ? error.message : "Failed to retrieve categories"
|
|
8324
|
+
}, sendMessage, clientId);
|
|
8325
|
+
}
|
|
8326
|
+
}
|
|
8327
|
+
async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
8328
|
+
try {
|
|
8329
|
+
const result = await executeCollection("kbNodes", "getTags", {});
|
|
8330
|
+
if (result && result.success) {
|
|
8331
|
+
logger.info(`[DB] Retrieved ${result.count} tags`);
|
|
8332
|
+
sendResponse8(id, {
|
|
8333
|
+
success: true,
|
|
8334
|
+
data: {
|
|
8335
|
+
tags: result.data,
|
|
8336
|
+
count: result.count,
|
|
8337
|
+
message: `Retrieved ${result.count} tags`
|
|
8338
|
+
}
|
|
8339
|
+
}, sendMessage, clientId);
|
|
8340
|
+
return;
|
|
8341
|
+
}
|
|
8342
|
+
sendResponse8(id, {
|
|
8343
|
+
success: false,
|
|
8344
|
+
error: "Failed to retrieve tags"
|
|
8345
|
+
}, sendMessage, clientId);
|
|
8346
|
+
} catch (error) {
|
|
8347
|
+
logger.error("[DB] Failed to get tags:", error);
|
|
8348
|
+
sendResponse8(id, {
|
|
8349
|
+
success: false,
|
|
8350
|
+
error: error instanceof Error ? error.message : "Failed to retrieve tags"
|
|
8351
|
+
}, sendMessage, clientId);
|
|
8352
|
+
}
|
|
8353
|
+
}
|
|
8354
|
+
function sendResponse8(id, res, sendMessage, clientId) {
|
|
8355
|
+
const response = {
|
|
8356
|
+
id: id || "unknown",
|
|
8357
|
+
type: "KB_NODES_RES",
|
|
8358
|
+
from: { type: "data-agent" },
|
|
8359
|
+
to: {
|
|
8360
|
+
type: "admin",
|
|
8361
|
+
id: clientId
|
|
8362
|
+
},
|
|
8363
|
+
payload: {
|
|
8364
|
+
...res
|
|
8365
|
+
}
|
|
8366
|
+
};
|
|
8367
|
+
sendMessage(response);
|
|
8368
|
+
}
|
|
8369
|
+
|
|
7910
8370
|
// src/auth/user-manager.ts
|
|
7911
8371
|
var import_fs4 = __toESM(require("fs"));
|
|
7912
8372
|
var import_path3 = __toESM(require("path"));
|
|
@@ -8936,6 +9396,11 @@ var SuperatomSDK = class {
|
|
|
8936
9396
|
logger.error("Failed to handle bookmarks request:", error);
|
|
8937
9397
|
});
|
|
8938
9398
|
break;
|
|
9399
|
+
case "KB_NODES":
|
|
9400
|
+
handleKbNodesRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
9401
|
+
logger.error("Failed to handle KB nodes request:", error);
|
|
9402
|
+
});
|
|
9403
|
+
break;
|
|
8939
9404
|
default:
|
|
8940
9405
|
const handler = this.messageTypeHandlers.get(message.type);
|
|
8941
9406
|
if (handler) {
|