@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.mjs
CHANGED
|
@@ -662,6 +662,36 @@ var BookmarksRequestMessageSchema = z3.object({
|
|
|
662
662
|
type: z3.literal("BOOKMARKS"),
|
|
663
663
|
payload: BookmarksRequestPayloadSchema
|
|
664
664
|
});
|
|
665
|
+
var KbNodesQueryFiltersSchema = z3.object({
|
|
666
|
+
query: z3.string().optional(),
|
|
667
|
+
category: z3.string().optional(),
|
|
668
|
+
tags: z3.array(z3.string()).optional(),
|
|
669
|
+
createdBy: z3.number().optional()
|
|
670
|
+
});
|
|
671
|
+
var KbNodesRequestPayloadSchema = z3.object({
|
|
672
|
+
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "search", "getByCategory", "getByUser", "getCategories", "getTags"]),
|
|
673
|
+
data: z3.object({
|
|
674
|
+
id: z3.number().optional(),
|
|
675
|
+
title: z3.string().optional(),
|
|
676
|
+
content: z3.string().optional(),
|
|
677
|
+
category: z3.string().optional(),
|
|
678
|
+
tags: z3.array(z3.string()).optional(),
|
|
679
|
+
createdBy: z3.number().optional(),
|
|
680
|
+
updatedBy: z3.number().optional(),
|
|
681
|
+
userId: z3.number().optional(),
|
|
682
|
+
// Query/search operation fields
|
|
683
|
+
query: z3.string().optional(),
|
|
684
|
+
filters: KbNodesQueryFiltersSchema.optional(),
|
|
685
|
+
limit: z3.number().optional(),
|
|
686
|
+
offset: z3.number().optional()
|
|
687
|
+
}).optional()
|
|
688
|
+
});
|
|
689
|
+
var KbNodesRequestMessageSchema = z3.object({
|
|
690
|
+
id: z3.string(),
|
|
691
|
+
from: MessageParticipantSchema,
|
|
692
|
+
type: z3.literal("KB_NODES"),
|
|
693
|
+
payload: KbNodesRequestPayloadSchema
|
|
694
|
+
});
|
|
665
695
|
|
|
666
696
|
// src/utils/logger.ts
|
|
667
697
|
import fs from "fs";
|
|
@@ -5683,7 +5713,7 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5683
5713
|
try {
|
|
5684
5714
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5685
5715
|
const { id, payload, from } = request;
|
|
5686
|
-
const { prompt, limit =
|
|
5716
|
+
const { prompt, limit = 10 } = payload;
|
|
5687
5717
|
const wsId = from.id;
|
|
5688
5718
|
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5689
5719
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -5693,48 +5723,37 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5693
5723
|
}, sendMessage, wsId);
|
|
5694
5724
|
return;
|
|
5695
5725
|
}
|
|
5696
|
-
const
|
|
5697
|
-
const
|
|
5726
|
+
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5727
|
+
const bookmarkTextSearchHandler = collections?.["bookmarks"]?.["textSearch"];
|
|
5728
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based search for components (${displayComponents.length} display components) and PostgreSQL text search for bookmarks`);
|
|
5729
|
+
const searchPromises = [];
|
|
5698
5730
|
let componentSuggestions = [];
|
|
5699
5731
|
let bookmarkSuggestions = [];
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
componentSuggestions = result.suggestions.map((s) => ({
|
|
5710
|
-
...s,
|
|
5711
|
-
suggestionType: "component"
|
|
5712
|
-
}));
|
|
5713
|
-
useEmbeddingSearch = true;
|
|
5714
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions`);
|
|
5715
|
-
}
|
|
5716
|
-
} catch (embeddingError) {
|
|
5717
|
-
logger.warn("Component embedding search failed:", embeddingError);
|
|
5718
|
-
}
|
|
5719
|
-
})()
|
|
5720
|
-
);
|
|
5732
|
+
if (displayComponents.length > 0) {
|
|
5733
|
+
const componentResults = searchComponents(prompt, displayComponents, limit);
|
|
5734
|
+
componentSuggestions = componentResults.map((c) => ({
|
|
5735
|
+
...c,
|
|
5736
|
+
suggestionType: "component",
|
|
5737
|
+
similarity: 1
|
|
5738
|
+
// Token-based search doesn't have similarity scores
|
|
5739
|
+
}));
|
|
5740
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions via token search`);
|
|
5721
5741
|
}
|
|
5722
|
-
if (
|
|
5742
|
+
if (bookmarkTextSearchHandler && userId && userId !== "anonymous") {
|
|
5723
5743
|
searchPromises.push(
|
|
5724
5744
|
(async () => {
|
|
5725
5745
|
try {
|
|
5726
|
-
logger.info(`Using
|
|
5727
|
-
const result = await
|
|
5746
|
+
logger.info(`Using PostgreSQL text search for bookmarks (user: ${userId})`);
|
|
5747
|
+
const result = await bookmarkTextSearchHandler({ prompt, userId, limit });
|
|
5728
5748
|
if (result.success && result.suggestions) {
|
|
5729
5749
|
bookmarkSuggestions = result.suggestions.map((s) => ({
|
|
5730
5750
|
...s,
|
|
5731
5751
|
suggestionType: "bookmark"
|
|
5732
5752
|
}));
|
|
5733
|
-
|
|
5734
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions`);
|
|
5753
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions via PostgreSQL text search`);
|
|
5735
5754
|
}
|
|
5736
|
-
} catch (
|
|
5737
|
-
logger.warn("Bookmark
|
|
5755
|
+
} catch (searchError) {
|
|
5756
|
+
logger.warn("Bookmark PostgreSQL text search failed:", searchError);
|
|
5738
5757
|
}
|
|
5739
5758
|
})()
|
|
5740
5759
|
);
|
|
@@ -5742,44 +5761,33 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5742
5761
|
if (searchPromises.length > 0) {
|
|
5743
5762
|
await Promise.all(searchPromises);
|
|
5744
5763
|
}
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
success: true,
|
|
5750
|
-
data: {
|
|
5751
|
-
prompt,
|
|
5752
|
-
suggestions: allSuggestions,
|
|
5753
|
-
count: allSuggestions.length,
|
|
5754
|
-
componentCount: componentSuggestions.length,
|
|
5755
|
-
bookmarkCount: bookmarkSuggestions.length,
|
|
5756
|
-
message: `Found ${allSuggestions.length} suggestions (${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks)`
|
|
5757
|
-
}
|
|
5758
|
-
}, sendMessage, wsId);
|
|
5759
|
-
return;
|
|
5760
|
-
}
|
|
5761
|
-
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5762
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based approach. Display components: ${displayComponents.length}`);
|
|
5763
|
-
if (!displayComponents || displayComponents.length === 0) {
|
|
5764
|
+
const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].slice(0, limit);
|
|
5765
|
+
const finalComponentCount = allSuggestions.filter((s) => s.suggestionType === "component").length;
|
|
5766
|
+
const finalBookmarkCount = allSuggestions.filter((s) => s.suggestionType === "bookmark").length;
|
|
5767
|
+
if (allSuggestions.length === 0) {
|
|
5764
5768
|
sendResponse(id, {
|
|
5765
5769
|
success: true,
|
|
5766
5770
|
data: {
|
|
5767
5771
|
prompt,
|
|
5768
5772
|
suggestions: [],
|
|
5769
5773
|
count: 0,
|
|
5770
|
-
|
|
5774
|
+
componentCount: 0,
|
|
5775
|
+
bookmarkCount: 0,
|
|
5776
|
+
message: "No matching suggestions found"
|
|
5771
5777
|
}
|
|
5772
5778
|
}, sendMessage, wsId);
|
|
5773
5779
|
return;
|
|
5774
5780
|
}
|
|
5775
|
-
|
|
5781
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning ${allSuggestions.length} suggestions: ${finalComponentCount} components, ${finalBookmarkCount} bookmarks`);
|
|
5776
5782
|
sendResponse(id, {
|
|
5777
5783
|
success: true,
|
|
5778
5784
|
data: {
|
|
5779
5785
|
prompt,
|
|
5780
|
-
suggestions,
|
|
5781
|
-
count:
|
|
5782
|
-
|
|
5786
|
+
suggestions: allSuggestions,
|
|
5787
|
+
count: allSuggestions.length,
|
|
5788
|
+
componentCount: finalComponentCount,
|
|
5789
|
+
bookmarkCount: finalBookmarkCount,
|
|
5790
|
+
message: `Found ${allSuggestions.length} suggestions (${finalComponentCount} components, ${finalBookmarkCount} bookmarks)`
|
|
5783
5791
|
}
|
|
5784
5792
|
}, sendMessage, wsId);
|
|
5785
5793
|
} catch (error) {
|
|
@@ -7867,6 +7875,458 @@ function sendResponse7(id, res, sendMessage, clientId) {
|
|
|
7867
7875
|
sendMessage(response);
|
|
7868
7876
|
}
|
|
7869
7877
|
|
|
7878
|
+
// src/handlers/kb-nodes.ts
|
|
7879
|
+
async function handleKbNodesRequest(data, collections, sendMessage) {
|
|
7880
|
+
const executeCollection = async (collection, op, params) => {
|
|
7881
|
+
const handler = collections[collection]?.[op];
|
|
7882
|
+
if (!handler) {
|
|
7883
|
+
throw new Error(`Collection '${collection}' or operation '${op}' not found`);
|
|
7884
|
+
}
|
|
7885
|
+
return await handler(params);
|
|
7886
|
+
};
|
|
7887
|
+
try {
|
|
7888
|
+
const request = KbNodesRequestMessageSchema.parse(data);
|
|
7889
|
+
const { id, payload, from } = request;
|
|
7890
|
+
const { operation, data: requestData } = payload;
|
|
7891
|
+
const nodeId = requestData?.id;
|
|
7892
|
+
const title = requestData?.title;
|
|
7893
|
+
const content = requestData?.content;
|
|
7894
|
+
const category = requestData?.category;
|
|
7895
|
+
const tags = requestData?.tags;
|
|
7896
|
+
const createdBy = requestData?.createdBy;
|
|
7897
|
+
const updatedBy = requestData?.updatedBy;
|
|
7898
|
+
const userId = requestData?.userId;
|
|
7899
|
+
const query = requestData?.query;
|
|
7900
|
+
const filters = requestData?.filters;
|
|
7901
|
+
const limit = requestData?.limit;
|
|
7902
|
+
const offset = requestData?.offset;
|
|
7903
|
+
switch (operation) {
|
|
7904
|
+
case "create":
|
|
7905
|
+
await handleCreate6(id, { title, content, category, tags, createdBy }, executeCollection, sendMessage, from.id);
|
|
7906
|
+
break;
|
|
7907
|
+
case "update":
|
|
7908
|
+
await handleUpdate6(id, nodeId, { title, content, category, tags, updatedBy }, executeCollection, sendMessage, from.id);
|
|
7909
|
+
break;
|
|
7910
|
+
case "delete":
|
|
7911
|
+
await handleDelete6(id, nodeId, executeCollection, sendMessage, from.id);
|
|
7912
|
+
break;
|
|
7913
|
+
case "getAll":
|
|
7914
|
+
await handleGetAll6(id, limit, offset, executeCollection, sendMessage, from.id);
|
|
7915
|
+
break;
|
|
7916
|
+
case "getOne":
|
|
7917
|
+
await handleGetOne6(id, nodeId, executeCollection, sendMessage, from.id);
|
|
7918
|
+
break;
|
|
7919
|
+
case "search":
|
|
7920
|
+
await handleSearch(id, { query, category, tags, createdBy, limit, offset }, executeCollection, sendMessage, from.id);
|
|
7921
|
+
break;
|
|
7922
|
+
case "getByCategory":
|
|
7923
|
+
await handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, from.id);
|
|
7924
|
+
break;
|
|
7925
|
+
case "getByUser":
|
|
7926
|
+
await handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, from.id);
|
|
7927
|
+
break;
|
|
7928
|
+
case "getCategories":
|
|
7929
|
+
await handleGetCategories(id, executeCollection, sendMessage, from.id);
|
|
7930
|
+
break;
|
|
7931
|
+
case "getTags":
|
|
7932
|
+
await handleGetTags(id, executeCollection, sendMessage, from.id);
|
|
7933
|
+
break;
|
|
7934
|
+
default:
|
|
7935
|
+
sendResponse8(id, {
|
|
7936
|
+
success: false,
|
|
7937
|
+
error: `Unknown operation: ${operation}`
|
|
7938
|
+
}, sendMessage, from.id);
|
|
7939
|
+
}
|
|
7940
|
+
} catch (error) {
|
|
7941
|
+
logger.error("Failed to handle KB nodes request:", error);
|
|
7942
|
+
sendResponse8(null, {
|
|
7943
|
+
success: false,
|
|
7944
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
7945
|
+
}, sendMessage);
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7948
|
+
async function handleCreate6(id, nodeData, executeCollection, sendMessage, clientId) {
|
|
7949
|
+
const { title, content, category, tags, createdBy } = nodeData;
|
|
7950
|
+
if (!title || title.trim().length === 0) {
|
|
7951
|
+
sendResponse8(id, {
|
|
7952
|
+
success: false,
|
|
7953
|
+
error: "Title is required and cannot be empty"
|
|
7954
|
+
}, sendMessage, clientId);
|
|
7955
|
+
return;
|
|
7956
|
+
}
|
|
7957
|
+
if (!content || content.trim().length === 0) {
|
|
7958
|
+
sendResponse8(id, {
|
|
7959
|
+
success: false,
|
|
7960
|
+
error: "Content is required and cannot be empty"
|
|
7961
|
+
}, sendMessage, clientId);
|
|
7962
|
+
return;
|
|
7963
|
+
}
|
|
7964
|
+
if (!createdBy) {
|
|
7965
|
+
sendResponse8(id, {
|
|
7966
|
+
success: false,
|
|
7967
|
+
error: "createdBy (user ID) is required"
|
|
7968
|
+
}, sendMessage, clientId);
|
|
7969
|
+
return;
|
|
7970
|
+
}
|
|
7971
|
+
try {
|
|
7972
|
+
const result = await executeCollection("kbNodes", "create", {
|
|
7973
|
+
title,
|
|
7974
|
+
content,
|
|
7975
|
+
category: category || void 0,
|
|
7976
|
+
tags: tags || void 0,
|
|
7977
|
+
createdBy
|
|
7978
|
+
});
|
|
7979
|
+
if (result && result.success) {
|
|
7980
|
+
logger.info(`[DB] KB node created successfully: ${title}`);
|
|
7981
|
+
sendResponse8(id, {
|
|
7982
|
+
success: true,
|
|
7983
|
+
data: {
|
|
7984
|
+
...result.data,
|
|
7985
|
+
message: `Knowledge node '${title}' created successfully`
|
|
7986
|
+
}
|
|
7987
|
+
}, sendMessage, clientId);
|
|
7988
|
+
return;
|
|
7989
|
+
}
|
|
7990
|
+
sendResponse8(id, {
|
|
7991
|
+
success: false,
|
|
7992
|
+
error: "Failed to create knowledge node"
|
|
7993
|
+
}, sendMessage, clientId);
|
|
7994
|
+
} catch (error) {
|
|
7995
|
+
logger.error("[DB] Failed to create KB node:", error);
|
|
7996
|
+
sendResponse8(id, {
|
|
7997
|
+
success: false,
|
|
7998
|
+
error: error instanceof Error ? error.message : "Failed to create knowledge node"
|
|
7999
|
+
}, sendMessage, clientId);
|
|
8000
|
+
}
|
|
8001
|
+
}
|
|
8002
|
+
async function handleUpdate6(id, nodeId, nodeData, executeCollection, sendMessage, clientId) {
|
|
8003
|
+
const { title, content, category, tags, updatedBy } = nodeData;
|
|
8004
|
+
if (!nodeId) {
|
|
8005
|
+
sendResponse8(id, {
|
|
8006
|
+
success: false,
|
|
8007
|
+
error: "Knowledge node ID is required"
|
|
8008
|
+
}, sendMessage, clientId);
|
|
8009
|
+
return;
|
|
8010
|
+
}
|
|
8011
|
+
if (!updatedBy) {
|
|
8012
|
+
sendResponse8(id, {
|
|
8013
|
+
success: false,
|
|
8014
|
+
error: "updatedBy (user ID) is required"
|
|
8015
|
+
}, sendMessage, clientId);
|
|
8016
|
+
return;
|
|
8017
|
+
}
|
|
8018
|
+
try {
|
|
8019
|
+
const result = await executeCollection("kbNodes", "update", {
|
|
8020
|
+
id: nodeId,
|
|
8021
|
+
title,
|
|
8022
|
+
content,
|
|
8023
|
+
category,
|
|
8024
|
+
tags,
|
|
8025
|
+
updatedBy
|
|
8026
|
+
});
|
|
8027
|
+
if (result && result.success) {
|
|
8028
|
+
logger.info(`[DB] KB node updated successfully, ID: ${nodeId}`);
|
|
8029
|
+
sendResponse8(id, {
|
|
8030
|
+
success: true,
|
|
8031
|
+
data: {
|
|
8032
|
+
...result.data,
|
|
8033
|
+
message: `Knowledge node updated successfully`
|
|
8034
|
+
}
|
|
8035
|
+
}, sendMessage, clientId);
|
|
8036
|
+
return;
|
|
8037
|
+
}
|
|
8038
|
+
sendResponse8(id, {
|
|
8039
|
+
success: false,
|
|
8040
|
+
error: "Failed to update knowledge node"
|
|
8041
|
+
}, sendMessage, clientId);
|
|
8042
|
+
} catch (error) {
|
|
8043
|
+
logger.error("[DB] Failed to update KB node:", error);
|
|
8044
|
+
sendResponse8(id, {
|
|
8045
|
+
success: false,
|
|
8046
|
+
error: error instanceof Error ? error.message : "Failed to update knowledge node"
|
|
8047
|
+
}, sendMessage, clientId);
|
|
8048
|
+
}
|
|
8049
|
+
}
|
|
8050
|
+
async function handleDelete6(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
8051
|
+
if (!nodeId) {
|
|
8052
|
+
sendResponse8(id, {
|
|
8053
|
+
success: false,
|
|
8054
|
+
error: "Knowledge node ID is required"
|
|
8055
|
+
}, sendMessage, clientId);
|
|
8056
|
+
return;
|
|
8057
|
+
}
|
|
8058
|
+
try {
|
|
8059
|
+
const result = await executeCollection("kbNodes", "delete", { id: nodeId });
|
|
8060
|
+
if (result && result.success) {
|
|
8061
|
+
logger.info(`[DB] KB node deleted successfully, ID: ${nodeId}`);
|
|
8062
|
+
sendResponse8(id, {
|
|
8063
|
+
success: true,
|
|
8064
|
+
data: {
|
|
8065
|
+
id: nodeId,
|
|
8066
|
+
...result.data,
|
|
8067
|
+
message: `Knowledge node deleted successfully`
|
|
8068
|
+
}
|
|
8069
|
+
}, sendMessage, clientId);
|
|
8070
|
+
return;
|
|
8071
|
+
}
|
|
8072
|
+
sendResponse8(id, {
|
|
8073
|
+
success: false,
|
|
8074
|
+
error: "Failed to delete knowledge node"
|
|
8075
|
+
}, sendMessage, clientId);
|
|
8076
|
+
} catch (error) {
|
|
8077
|
+
logger.error("[DB] Failed to delete KB node:", error);
|
|
8078
|
+
sendResponse8(id, {
|
|
8079
|
+
success: false,
|
|
8080
|
+
error: error instanceof Error ? error.message : "Failed to delete knowledge node"
|
|
8081
|
+
}, sendMessage, clientId);
|
|
8082
|
+
}
|
|
8083
|
+
}
|
|
8084
|
+
async function handleGetAll6(id, limit, offset, executeCollection, sendMessage, clientId) {
|
|
8085
|
+
try {
|
|
8086
|
+
const result = await executeCollection("kbNodes", "getAll", {
|
|
8087
|
+
limit: limit || 100,
|
|
8088
|
+
offset: offset || 0
|
|
8089
|
+
});
|
|
8090
|
+
if (result && result.success) {
|
|
8091
|
+
logger.info(`[DB] Retrieved ${result.count} KB nodes`);
|
|
8092
|
+
sendResponse8(id, {
|
|
8093
|
+
success: true,
|
|
8094
|
+
data: {
|
|
8095
|
+
nodes: result.data,
|
|
8096
|
+
count: result.count,
|
|
8097
|
+
message: `Retrieved ${result.count} knowledge nodes`
|
|
8098
|
+
}
|
|
8099
|
+
}, sendMessage, clientId);
|
|
8100
|
+
return;
|
|
8101
|
+
}
|
|
8102
|
+
sendResponse8(id, {
|
|
8103
|
+
success: false,
|
|
8104
|
+
error: "Failed to retrieve knowledge nodes"
|
|
8105
|
+
}, sendMessage, clientId);
|
|
8106
|
+
} catch (error) {
|
|
8107
|
+
logger.error("[DB] Failed to get all KB nodes:", error);
|
|
8108
|
+
sendResponse8(id, {
|
|
8109
|
+
success: false,
|
|
8110
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes"
|
|
8111
|
+
}, sendMessage, clientId);
|
|
8112
|
+
}
|
|
8113
|
+
}
|
|
8114
|
+
async function handleGetOne6(id, nodeId, executeCollection, sendMessage, clientId) {
|
|
8115
|
+
if (!nodeId) {
|
|
8116
|
+
sendResponse8(id, {
|
|
8117
|
+
success: false,
|
|
8118
|
+
error: "Knowledge node ID is required"
|
|
8119
|
+
}, sendMessage, clientId);
|
|
8120
|
+
return;
|
|
8121
|
+
}
|
|
8122
|
+
try {
|
|
8123
|
+
const result = await executeCollection("kbNodes", "getOne", { id: nodeId });
|
|
8124
|
+
if (result && result.success) {
|
|
8125
|
+
logger.info(`[DB] Retrieved KB node ID: ${nodeId}`);
|
|
8126
|
+
sendResponse8(id, {
|
|
8127
|
+
success: true,
|
|
8128
|
+
data: {
|
|
8129
|
+
node: result.data,
|
|
8130
|
+
message: `Retrieved knowledge node`
|
|
8131
|
+
}
|
|
8132
|
+
}, sendMessage, clientId);
|
|
8133
|
+
return;
|
|
8134
|
+
}
|
|
8135
|
+
sendResponse8(id, {
|
|
8136
|
+
success: false,
|
|
8137
|
+
error: "Failed to retrieve knowledge node"
|
|
8138
|
+
}, sendMessage, clientId);
|
|
8139
|
+
} catch (error) {
|
|
8140
|
+
logger.error("[DB] Failed to get KB node:", error);
|
|
8141
|
+
sendResponse8(id, {
|
|
8142
|
+
success: false,
|
|
8143
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge node"
|
|
8144
|
+
}, sendMessage, clientId);
|
|
8145
|
+
}
|
|
8146
|
+
}
|
|
8147
|
+
async function handleSearch(id, searchParams, executeCollection, sendMessage, clientId) {
|
|
8148
|
+
const { query, category, tags, createdBy, limit, offset } = searchParams;
|
|
8149
|
+
try {
|
|
8150
|
+
const result = await executeCollection("kbNodes", "search", {
|
|
8151
|
+
query,
|
|
8152
|
+
category,
|
|
8153
|
+
tags,
|
|
8154
|
+
createdBy,
|
|
8155
|
+
limit: limit || 50,
|
|
8156
|
+
offset: offset || 0
|
|
8157
|
+
});
|
|
8158
|
+
if (result && result.success) {
|
|
8159
|
+
logger.info(`[DB] Search returned ${result.count} KB nodes`);
|
|
8160
|
+
sendResponse8(id, {
|
|
8161
|
+
success: true,
|
|
8162
|
+
data: {
|
|
8163
|
+
nodes: result.data,
|
|
8164
|
+
count: result.count,
|
|
8165
|
+
message: `Search returned ${result.count} knowledge nodes`
|
|
8166
|
+
}
|
|
8167
|
+
}, sendMessage, clientId);
|
|
8168
|
+
return;
|
|
8169
|
+
}
|
|
8170
|
+
sendResponse8(id, {
|
|
8171
|
+
success: false,
|
|
8172
|
+
error: "Failed to search knowledge nodes"
|
|
8173
|
+
}, sendMessage, clientId);
|
|
8174
|
+
} catch (error) {
|
|
8175
|
+
logger.error("[DB] Failed to search KB nodes:", error);
|
|
8176
|
+
sendResponse8(id, {
|
|
8177
|
+
success: false,
|
|
8178
|
+
error: error instanceof Error ? error.message : "Failed to search knowledge nodes"
|
|
8179
|
+
}, sendMessage, clientId);
|
|
8180
|
+
}
|
|
8181
|
+
}
|
|
8182
|
+
async function handleGetByCategory(id, category, limit, offset, executeCollection, sendMessage, clientId) {
|
|
8183
|
+
if (!category) {
|
|
8184
|
+
sendResponse8(id, {
|
|
8185
|
+
success: false,
|
|
8186
|
+
error: "Category is required"
|
|
8187
|
+
}, sendMessage, clientId);
|
|
8188
|
+
return;
|
|
8189
|
+
}
|
|
8190
|
+
try {
|
|
8191
|
+
const result = await executeCollection("kbNodes", "getByCategory", {
|
|
8192
|
+
category,
|
|
8193
|
+
limit: limit || 50,
|
|
8194
|
+
offset: offset || 0
|
|
8195
|
+
});
|
|
8196
|
+
if (result && result.success) {
|
|
8197
|
+
logger.info(`[DB] Retrieved ${result.count} KB nodes for category: ${category}`);
|
|
8198
|
+
sendResponse8(id, {
|
|
8199
|
+
success: true,
|
|
8200
|
+
data: {
|
|
8201
|
+
nodes: result.data,
|
|
8202
|
+
count: result.count,
|
|
8203
|
+
category,
|
|
8204
|
+
message: `Retrieved ${result.count} knowledge nodes for category '${category}'`
|
|
8205
|
+
}
|
|
8206
|
+
}, sendMessage, clientId);
|
|
8207
|
+
return;
|
|
8208
|
+
}
|
|
8209
|
+
sendResponse8(id, {
|
|
8210
|
+
success: false,
|
|
8211
|
+
error: "Failed to retrieve knowledge nodes by category"
|
|
8212
|
+
}, sendMessage, clientId);
|
|
8213
|
+
} catch (error) {
|
|
8214
|
+
logger.error("[DB] Failed to get KB nodes by category:", error);
|
|
8215
|
+
sendResponse8(id, {
|
|
8216
|
+
success: false,
|
|
8217
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by category"
|
|
8218
|
+
}, sendMessage, clientId);
|
|
8219
|
+
}
|
|
8220
|
+
}
|
|
8221
|
+
async function handleGetByUser(id, userId, limit, offset, executeCollection, sendMessage, clientId) {
|
|
8222
|
+
if (!userId) {
|
|
8223
|
+
sendResponse8(id, {
|
|
8224
|
+
success: false,
|
|
8225
|
+
error: "User ID is required"
|
|
8226
|
+
}, sendMessage, clientId);
|
|
8227
|
+
return;
|
|
8228
|
+
}
|
|
8229
|
+
try {
|
|
8230
|
+
const result = await executeCollection("kbNodes", "getByUser", {
|
|
8231
|
+
userId,
|
|
8232
|
+
limit: limit || 50,
|
|
8233
|
+
offset: offset || 0
|
|
8234
|
+
});
|
|
8235
|
+
if (result && result.success) {
|
|
8236
|
+
logger.info(`[DB] Retrieved ${result.count} KB nodes for user: ${userId}`);
|
|
8237
|
+
sendResponse8(id, {
|
|
8238
|
+
success: true,
|
|
8239
|
+
data: {
|
|
8240
|
+
nodes: result.data,
|
|
8241
|
+
count: result.count,
|
|
8242
|
+
userId,
|
|
8243
|
+
message: `Retrieved ${result.count} knowledge nodes for user ${userId}`
|
|
8244
|
+
}
|
|
8245
|
+
}, sendMessage, clientId);
|
|
8246
|
+
return;
|
|
8247
|
+
}
|
|
8248
|
+
sendResponse8(id, {
|
|
8249
|
+
success: false,
|
|
8250
|
+
error: "Failed to retrieve knowledge nodes by user"
|
|
8251
|
+
}, sendMessage, clientId);
|
|
8252
|
+
} catch (error) {
|
|
8253
|
+
logger.error("[DB] Failed to get KB nodes by user:", error);
|
|
8254
|
+
sendResponse8(id, {
|
|
8255
|
+
success: false,
|
|
8256
|
+
error: error instanceof Error ? error.message : "Failed to retrieve knowledge nodes by user"
|
|
8257
|
+
}, sendMessage, clientId);
|
|
8258
|
+
}
|
|
8259
|
+
}
|
|
8260
|
+
async function handleGetCategories(id, executeCollection, sendMessage, clientId) {
|
|
8261
|
+
try {
|
|
8262
|
+
const result = await executeCollection("kbNodes", "getCategories", {});
|
|
8263
|
+
if (result && result.success) {
|
|
8264
|
+
logger.info(`[DB] Retrieved ${result.count} categories`);
|
|
8265
|
+
sendResponse8(id, {
|
|
8266
|
+
success: true,
|
|
8267
|
+
data: {
|
|
8268
|
+
categories: result.data,
|
|
8269
|
+
count: result.count,
|
|
8270
|
+
message: `Retrieved ${result.count} categories`
|
|
8271
|
+
}
|
|
8272
|
+
}, sendMessage, clientId);
|
|
8273
|
+
return;
|
|
8274
|
+
}
|
|
8275
|
+
sendResponse8(id, {
|
|
8276
|
+
success: false,
|
|
8277
|
+
error: "Failed to retrieve categories"
|
|
8278
|
+
}, sendMessage, clientId);
|
|
8279
|
+
} catch (error) {
|
|
8280
|
+
logger.error("[DB] Failed to get categories:", error);
|
|
8281
|
+
sendResponse8(id, {
|
|
8282
|
+
success: false,
|
|
8283
|
+
error: error instanceof Error ? error.message : "Failed to retrieve categories"
|
|
8284
|
+
}, sendMessage, clientId);
|
|
8285
|
+
}
|
|
8286
|
+
}
|
|
8287
|
+
async function handleGetTags(id, executeCollection, sendMessage, clientId) {
|
|
8288
|
+
try {
|
|
8289
|
+
const result = await executeCollection("kbNodes", "getTags", {});
|
|
8290
|
+
if (result && result.success) {
|
|
8291
|
+
logger.info(`[DB] Retrieved ${result.count} tags`);
|
|
8292
|
+
sendResponse8(id, {
|
|
8293
|
+
success: true,
|
|
8294
|
+
data: {
|
|
8295
|
+
tags: result.data,
|
|
8296
|
+
count: result.count,
|
|
8297
|
+
message: `Retrieved ${result.count} tags`
|
|
8298
|
+
}
|
|
8299
|
+
}, sendMessage, clientId);
|
|
8300
|
+
return;
|
|
8301
|
+
}
|
|
8302
|
+
sendResponse8(id, {
|
|
8303
|
+
success: false,
|
|
8304
|
+
error: "Failed to retrieve tags"
|
|
8305
|
+
}, sendMessage, clientId);
|
|
8306
|
+
} catch (error) {
|
|
8307
|
+
logger.error("[DB] Failed to get tags:", error);
|
|
8308
|
+
sendResponse8(id, {
|
|
8309
|
+
success: false,
|
|
8310
|
+
error: error instanceof Error ? error.message : "Failed to retrieve tags"
|
|
8311
|
+
}, sendMessage, clientId);
|
|
8312
|
+
}
|
|
8313
|
+
}
|
|
8314
|
+
function sendResponse8(id, res, sendMessage, clientId) {
|
|
8315
|
+
const response = {
|
|
8316
|
+
id: id || "unknown",
|
|
8317
|
+
type: "KB_NODES_RES",
|
|
8318
|
+
from: { type: "data-agent" },
|
|
8319
|
+
to: {
|
|
8320
|
+
type: "admin",
|
|
8321
|
+
id: clientId
|
|
8322
|
+
},
|
|
8323
|
+
payload: {
|
|
8324
|
+
...res
|
|
8325
|
+
}
|
|
8326
|
+
};
|
|
8327
|
+
sendMessage(response);
|
|
8328
|
+
}
|
|
8329
|
+
|
|
7870
8330
|
// src/auth/user-manager.ts
|
|
7871
8331
|
import fs5 from "fs";
|
|
7872
8332
|
import path4 from "path";
|
|
@@ -8896,6 +9356,11 @@ var SuperatomSDK = class {
|
|
|
8896
9356
|
logger.error("Failed to handle bookmarks request:", error);
|
|
8897
9357
|
});
|
|
8898
9358
|
break;
|
|
9359
|
+
case "KB_NODES":
|
|
9360
|
+
handleKbNodesRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
9361
|
+
logger.error("Failed to handle KB nodes request:", error);
|
|
9362
|
+
});
|
|
9363
|
+
break;
|
|
8899
9364
|
default:
|
|
8900
9365
|
const handler = this.messageTypeHandlers.get(message.type);
|
|
8901
9366
|
if (handler) {
|