@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.mjs
CHANGED
|
@@ -5683,7 +5683,7 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5683
5683
|
try {
|
|
5684
5684
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5685
5685
|
const { id, payload, from } = request;
|
|
5686
|
-
const { prompt, limit =
|
|
5686
|
+
const { prompt, limit = 10 } = payload;
|
|
5687
5687
|
const wsId = from.id;
|
|
5688
5688
|
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5689
5689
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -5693,48 +5693,37 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5693
5693
|
}, sendMessage, wsId);
|
|
5694
5694
|
return;
|
|
5695
5695
|
}
|
|
5696
|
-
const
|
|
5697
|
-
const
|
|
5696
|
+
const displayComponents = components.filter((c) => c.isDisplayComp === true);
|
|
5697
|
+
const bookmarkTextSearchHandler = collections?.["bookmarks"]?.["textSearch"];
|
|
5698
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Using token-based search for components (${displayComponents.length} display components) and PostgreSQL text search for bookmarks`);
|
|
5699
|
+
const searchPromises = [];
|
|
5698
5700
|
let componentSuggestions = [];
|
|
5699
5701
|
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
|
-
);
|
|
5702
|
+
if (displayComponents.length > 0) {
|
|
5703
|
+
const componentResults = searchComponents(prompt, displayComponents, limit);
|
|
5704
|
+
componentSuggestions = componentResults.map((c) => ({
|
|
5705
|
+
...c,
|
|
5706
|
+
suggestionType: "component",
|
|
5707
|
+
similarity: 1
|
|
5708
|
+
// Token-based search doesn't have similarity scores
|
|
5709
|
+
}));
|
|
5710
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${componentSuggestions.length} component suggestions via token search`);
|
|
5721
5711
|
}
|
|
5722
|
-
if (
|
|
5712
|
+
if (bookmarkTextSearchHandler && userId && userId !== "anonymous") {
|
|
5723
5713
|
searchPromises.push(
|
|
5724
5714
|
(async () => {
|
|
5725
5715
|
try {
|
|
5726
|
-
logger.info(`Using
|
|
5727
|
-
const result = await
|
|
5716
|
+
logger.info(`Using PostgreSQL text search for bookmarks (user: ${userId})`);
|
|
5717
|
+
const result = await bookmarkTextSearchHandler({ prompt, userId, limit });
|
|
5728
5718
|
if (result.success && result.suggestions) {
|
|
5729
5719
|
bookmarkSuggestions = result.suggestions.map((s) => ({
|
|
5730
5720
|
...s,
|
|
5731
5721
|
suggestionType: "bookmark"
|
|
5732
5722
|
}));
|
|
5733
|
-
|
|
5734
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions`);
|
|
5723
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Found ${bookmarkSuggestions.length} bookmark suggestions via PostgreSQL text search`);
|
|
5735
5724
|
}
|
|
5736
|
-
} catch (
|
|
5737
|
-
logger.warn("Bookmark
|
|
5725
|
+
} catch (searchError) {
|
|
5726
|
+
logger.warn("Bookmark PostgreSQL text search failed:", searchError);
|
|
5738
5727
|
}
|
|
5739
5728
|
})()
|
|
5740
5729
|
);
|
|
@@ -5742,44 +5731,33 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5742
5731
|
if (searchPromises.length > 0) {
|
|
5743
5732
|
await Promise.all(searchPromises);
|
|
5744
5733
|
}
|
|
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) {
|
|
5734
|
+
const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].slice(0, limit);
|
|
5735
|
+
const finalComponentCount = allSuggestions.filter((s) => s.suggestionType === "component").length;
|
|
5736
|
+
const finalBookmarkCount = allSuggestions.filter((s) => s.suggestionType === "bookmark").length;
|
|
5737
|
+
if (allSuggestions.length === 0) {
|
|
5764
5738
|
sendResponse(id, {
|
|
5765
5739
|
success: true,
|
|
5766
5740
|
data: {
|
|
5767
5741
|
prompt,
|
|
5768
5742
|
suggestions: [],
|
|
5769
5743
|
count: 0,
|
|
5770
|
-
|
|
5744
|
+
componentCount: 0,
|
|
5745
|
+
bookmarkCount: 0,
|
|
5746
|
+
message: "No matching suggestions found"
|
|
5771
5747
|
}
|
|
5772
5748
|
}, sendMessage, wsId);
|
|
5773
5749
|
return;
|
|
5774
5750
|
}
|
|
5775
|
-
|
|
5751
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning ${allSuggestions.length} suggestions: ${finalComponentCount} components, ${finalBookmarkCount} bookmarks`);
|
|
5776
5752
|
sendResponse(id, {
|
|
5777
5753
|
success: true,
|
|
5778
5754
|
data: {
|
|
5779
5755
|
prompt,
|
|
5780
|
-
suggestions,
|
|
5781
|
-
count:
|
|
5782
|
-
|
|
5756
|
+
suggestions: allSuggestions,
|
|
5757
|
+
count: allSuggestions.length,
|
|
5758
|
+
componentCount: finalComponentCount,
|
|
5759
|
+
bookmarkCount: finalBookmarkCount,
|
|
5760
|
+
message: `Found ${allSuggestions.length} suggestions (${finalComponentCount} components, ${finalBookmarkCount} bookmarks)`
|
|
5783
5761
|
}
|
|
5784
5762
|
}, sendMessage, wsId);
|
|
5785
5763
|
} catch (error) {
|