@superatomai/sdk-node 0.0.22 → 0.0.23
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.js +33 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5723,7 +5723,7 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5723
5723
|
try {
|
|
5724
5724
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5725
5725
|
const { id, payload, from } = request;
|
|
5726
|
-
const { prompt, limit =
|
|
5726
|
+
const { prompt, limit = 10 } = payload;
|
|
5727
5727
|
const wsId = from.id;
|
|
5728
5728
|
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5729
5729
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -5733,48 +5733,37 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5733
5733
|
}, sendMessage, wsId);
|
|
5734
5734
|
return;
|
|
5735
5735
|
}
|
|
5736
|
-
const
|
|
5737
|
-
const
|
|
5736
|
+
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5737
|
+
const bookmarkTextSearchHandler = collections?.["bookmarks"]?.["textSearch"];
|
|
5738
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based search for components (${displayComponents.length} display components) and PostgreSQL text search for bookmarks`);
|
|
5739
|
+
const searchPromises = [];
|
|
5738
5740
|
let componentSuggestions = [];
|
|
5739
5741
|
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
|
-
);
|
|
5742
|
+
if (displayComponents.length > 0) {
|
|
5743
|
+
const componentResults = searchComponents(prompt, displayComponents, limit);
|
|
5744
|
+
componentSuggestions = componentResults.map((c) => ({
|
|
5745
|
+
...c,
|
|
5746
|
+
suggestionType: "component",
|
|
5747
|
+
similarity: 1
|
|
5748
|
+
// Token-based search doesn't have similarity scores
|
|
5749
|
+
}));
|
|
5750
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions via token search`);
|
|
5761
5751
|
}
|
|
5762
|
-
if (
|
|
5752
|
+
if (bookmarkTextSearchHandler && userId && userId !== "anonymous") {
|
|
5763
5753
|
searchPromises.push(
|
|
5764
5754
|
(async () => {
|
|
5765
5755
|
try {
|
|
5766
|
-
logger.info(`Using
|
|
5767
|
-
const result = await
|
|
5756
|
+
logger.info(`Using PostgreSQL text search for bookmarks (user: ${userId})`);
|
|
5757
|
+
const result = await bookmarkTextSearchHandler({ prompt, userId, limit });
|
|
5768
5758
|
if (result.success && result.suggestions) {
|
|
5769
5759
|
bookmarkSuggestions = result.suggestions.map((s) => ({
|
|
5770
5760
|
...s,
|
|
5771
5761
|
suggestionType: "bookmark"
|
|
5772
5762
|
}));
|
|
5773
|
-
|
|
5774
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions`);
|
|
5763
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions via PostgreSQL text search`);
|
|
5775
5764
|
}
|
|
5776
|
-
} catch (
|
|
5777
|
-
logger.warn("Bookmark
|
|
5765
|
+
} catch (searchError) {
|
|
5766
|
+
logger.warn("Bookmark PostgreSQL text search failed:", searchError);
|
|
5778
5767
|
}
|
|
5779
5768
|
})()
|
|
5780
5769
|
);
|
|
@@ -5782,44 +5771,33 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5782
5771
|
if (searchPromises.length > 0) {
|
|
5783
5772
|
await Promise.all(searchPromises);
|
|
5784
5773
|
}
|
|
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) {
|
|
5774
|
+
const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].slice(0, limit);
|
|
5775
|
+
const finalComponentCount = allSuggestions.filter((s) => s.suggestionType === "component").length;
|
|
5776
|
+
const finalBookmarkCount = allSuggestions.filter((s) => s.suggestionType === "bookmark").length;
|
|
5777
|
+
if (allSuggestions.length === 0) {
|
|
5804
5778
|
sendResponse(id, {
|
|
5805
5779
|
success: true,
|
|
5806
5780
|
data: {
|
|
5807
5781
|
prompt,
|
|
5808
5782
|
suggestions: [],
|
|
5809
5783
|
count: 0,
|
|
5810
|
-
|
|
5784
|
+
componentCount: 0,
|
|
5785
|
+
bookmarkCount: 0,
|
|
5786
|
+
message: "No matching suggestions found"
|
|
5811
5787
|
}
|
|
5812
5788
|
}, sendMessage, wsId);
|
|
5813
5789
|
return;
|
|
5814
5790
|
}
|
|
5815
|
-
|
|
5791
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning ${allSuggestions.length} suggestions: ${finalComponentCount} components, ${finalBookmarkCount} bookmarks`);
|
|
5816
5792
|
sendResponse(id, {
|
|
5817
5793
|
success: true,
|
|
5818
5794
|
data: {
|
|
5819
5795
|
prompt,
|
|
5820
|
-
suggestions,
|
|
5821
|
-
count:
|
|
5822
|
-
|
|
5796
|
+
suggestions: allSuggestions,
|
|
5797
|
+
count: allSuggestions.length,
|
|
5798
|
+
componentCount: finalComponentCount,
|
|
5799
|
+
bookmarkCount: finalBookmarkCount,
|
|
5800
|
+
message: `Found ${allSuggestions.length} suggestions (${finalComponentCount} components, ${finalBookmarkCount} bookmarks)`
|
|
5823
5801
|
}
|
|
5824
5802
|
}, sendMessage, wsId);
|
|
5825
5803
|
} catch (error) {
|