@superatomai/sdk-node 0.0.21 → 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.mjs CHANGED
@@ -642,7 +642,7 @@ var BookmarkQueryFiltersSchema = z3.object({
642
642
  name: z3.string().optional()
643
643
  });
644
644
  var BookmarksRequestPayloadSchema = z3.object({
645
- operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "getByUser", "getByThread", "query"]),
645
+ operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
646
646
  data: z3.object({
647
647
  id: z3.number().optional(),
648
648
  userId: z3.number().optional(),
@@ -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 = 5 } = payload;
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 componentSearchHandler = collections?.["components"]?.["search"];
5697
- const bookmarkSearchHandler = collections?.["bookmarks"]?.["search"];
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
- let useEmbeddingSearch = false;
5701
- const searchPromises = [];
5702
- if (componentSearchHandler) {
5703
- searchPromises.push(
5704
- (async () => {
5705
- try {
5706
- logger.info("Using embedding-based search for components");
5707
- const result = await componentSearchHandler({ prompt, limit });
5708
- if (result.success && result.suggestions) {
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 (bookmarkSearchHandler && userId && userId !== "anonymous") {
5712
+ if (bookmarkTextSearchHandler && userId && userId !== "anonymous") {
5723
5713
  searchPromises.push(
5724
5714
  (async () => {
5725
5715
  try {
5726
- logger.info(`Using embedding-based search for bookmarks (user: ${userId})`);
5727
- const result = await bookmarkSearchHandler({ prompt, userId, limit });
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
- useEmbeddingSearch = true;
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 (embeddingError) {
5737
- logger.warn("Bookmark embedding search failed:", embeddingError);
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
- if (useEmbeddingSearch && (componentSuggestions.length > 0 || bookmarkSuggestions.length > 0)) {
5746
- const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
5747
- logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning all suggestions: ${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks`);
5748
- sendResponse(id, {
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
- message: "No display components available"
5744
+ componentCount: 0,
5745
+ bookmarkCount: 0,
5746
+ message: "No matching suggestions found"
5771
5747
  }
5772
5748
  }, sendMessage, wsId);
5773
5749
  return;
5774
5750
  }
5775
- const suggestions = searchComponents(prompt, displayComponents, limit);
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: suggestions.length,
5782
- message: `Found ${suggestions.length} matching components`
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) {
@@ -7697,12 +7675,6 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
7697
7675
  case "getOne":
7698
7676
  await handleGetOne5(id, bookmarkId, executeCollection, sendMessage, from.id);
7699
7677
  break;
7700
- case "getByUser":
7701
- await handleGetByUser(id, userId, threadId, executeCollection, sendMessage, from.id);
7702
- break;
7703
- case "getByThread":
7704
- await handleGetByThread(id, threadId, executeCollection, sendMessage, from.id);
7705
- break;
7706
7678
  case "query":
7707
7679
  await handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, from.id);
7708
7680
  break;
@@ -7836,54 +7808,6 @@ async function handleGetOne5(id, bookmarkId, executeCollection, sendMessage, cli
7836
7808
  }, sendMessage, clientId);
7837
7809
  }
7838
7810
  }
7839
- async function handleGetByUser(id, userId, threadId, executeCollection, sendMessage, clientId) {
7840
- if (!userId) {
7841
- sendResponse7(id, {
7842
- success: false,
7843
- error: "userId is required"
7844
- }, sendMessage, clientId);
7845
- return;
7846
- }
7847
- try {
7848
- const result = await executeCollection("bookmarks", "getByUser", { userId, threadId });
7849
- sendResponse7(id, {
7850
- success: true,
7851
- data: result.data,
7852
- count: result.count,
7853
- message: `Retrieved ${result.count} bookmarks for user ${userId}`
7854
- }, sendMessage, clientId);
7855
- logger.info(`Retrieved bookmarks for user ${userId} (count: ${result.count})`);
7856
- } catch (error) {
7857
- sendResponse7(id, {
7858
- success: false,
7859
- error: error instanceof Error ? error.message : "Failed to get bookmarks by user"
7860
- }, sendMessage, clientId);
7861
- }
7862
- }
7863
- async function handleGetByThread(id, threadId, executeCollection, sendMessage, clientId) {
7864
- if (!threadId) {
7865
- sendResponse7(id, {
7866
- success: false,
7867
- error: "threadId is required"
7868
- }, sendMessage, clientId);
7869
- return;
7870
- }
7871
- try {
7872
- const result = await executeCollection("bookmarks", "getByThread", { threadId });
7873
- sendResponse7(id, {
7874
- success: true,
7875
- data: result.data,
7876
- count: result.count,
7877
- message: `Retrieved ${result.count} bookmarks for thread ${threadId}`
7878
- }, sendMessage, clientId);
7879
- logger.info(`Retrieved bookmarks for thread ${threadId} (count: ${result.count})`);
7880
- } catch (error) {
7881
- sendResponse7(id, {
7882
- success: false,
7883
- error: error instanceof Error ? error.message : "Failed to get bookmarks by thread"
7884
- }, sendMessage, clientId);
7885
- }
7886
- }
7887
7811
  async function handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
7888
7812
  try {
7889
7813
  const result = await executeCollection("bookmarks", "query", {