@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.js CHANGED
@@ -682,7 +682,7 @@ var BookmarkQueryFiltersSchema = import_zod3.z.object({
682
682
  name: import_zod3.z.string().optional()
683
683
  });
684
684
  var BookmarksRequestPayloadSchema = import_zod3.z.object({
685
- operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "getByUser", "getByThread", "query"]),
685
+ operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
686
686
  data: import_zod3.z.object({
687
687
  id: import_zod3.z.number().optional(),
688
688
  userId: import_zod3.z.number().optional(),
@@ -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 = 5 } = payload;
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 componentSearchHandler = collections?.["components"]?.["search"];
5737
- const bookmarkSearchHandler = collections?.["bookmarks"]?.["search"];
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
- let useEmbeddingSearch = false;
5741
- const searchPromises = [];
5742
- if (componentSearchHandler) {
5743
- searchPromises.push(
5744
- (async () => {
5745
- try {
5746
- logger.info("Using embedding-based search for components");
5747
- const result = await componentSearchHandler({ prompt, limit });
5748
- if (result.success && result.suggestions) {
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 (bookmarkSearchHandler && userId && userId !== "anonymous") {
5752
+ if (bookmarkTextSearchHandler && userId && userId !== "anonymous") {
5763
5753
  searchPromises.push(
5764
5754
  (async () => {
5765
5755
  try {
5766
- logger.info(`Using embedding-based search for bookmarks (user: ${userId})`);
5767
- const result = await bookmarkSearchHandler({ prompt, userId, limit });
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
- useEmbeddingSearch = true;
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 (embeddingError) {
5777
- logger.warn("Bookmark embedding search failed:", embeddingError);
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
- if (useEmbeddingSearch && (componentSuggestions.length > 0 || bookmarkSuggestions.length > 0)) {
5786
- const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
5787
- logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning all suggestions: ${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks`);
5788
- sendResponse(id, {
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
- message: "No display components available"
5784
+ componentCount: 0,
5785
+ bookmarkCount: 0,
5786
+ message: "No matching suggestions found"
5811
5787
  }
5812
5788
  }, sendMessage, wsId);
5813
5789
  return;
5814
5790
  }
5815
- const suggestions = searchComponents(prompt, displayComponents, limit);
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: suggestions.length,
5822
- message: `Found ${suggestions.length} matching components`
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) {
@@ -7737,12 +7715,6 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
7737
7715
  case "getOne":
7738
7716
  await handleGetOne5(id, bookmarkId, executeCollection, sendMessage, from.id);
7739
7717
  break;
7740
- case "getByUser":
7741
- await handleGetByUser(id, userId, threadId, executeCollection, sendMessage, from.id);
7742
- break;
7743
- case "getByThread":
7744
- await handleGetByThread(id, threadId, executeCollection, sendMessage, from.id);
7745
- break;
7746
7718
  case "query":
7747
7719
  await handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, from.id);
7748
7720
  break;
@@ -7876,54 +7848,6 @@ async function handleGetOne5(id, bookmarkId, executeCollection, sendMessage, cli
7876
7848
  }, sendMessage, clientId);
7877
7849
  }
7878
7850
  }
7879
- async function handleGetByUser(id, userId, threadId, executeCollection, sendMessage, clientId) {
7880
- if (!userId) {
7881
- sendResponse7(id, {
7882
- success: false,
7883
- error: "userId is required"
7884
- }, sendMessage, clientId);
7885
- return;
7886
- }
7887
- try {
7888
- const result = await executeCollection("bookmarks", "getByUser", { userId, threadId });
7889
- sendResponse7(id, {
7890
- success: true,
7891
- data: result.data,
7892
- count: result.count,
7893
- message: `Retrieved ${result.count} bookmarks for user ${userId}`
7894
- }, sendMessage, clientId);
7895
- logger.info(`Retrieved bookmarks for user ${userId} (count: ${result.count})`);
7896
- } catch (error) {
7897
- sendResponse7(id, {
7898
- success: false,
7899
- error: error instanceof Error ? error.message : "Failed to get bookmarks by user"
7900
- }, sendMessage, clientId);
7901
- }
7902
- }
7903
- async function handleGetByThread(id, threadId, executeCollection, sendMessage, clientId) {
7904
- if (!threadId) {
7905
- sendResponse7(id, {
7906
- success: false,
7907
- error: "threadId is required"
7908
- }, sendMessage, clientId);
7909
- return;
7910
- }
7911
- try {
7912
- const result = await executeCollection("bookmarks", "getByThread", { threadId });
7913
- sendResponse7(id, {
7914
- success: true,
7915
- data: result.data,
7916
- count: result.count,
7917
- message: `Retrieved ${result.count} bookmarks for thread ${threadId}`
7918
- }, sendMessage, clientId);
7919
- logger.info(`Retrieved bookmarks for thread ${threadId} (count: ${result.count})`);
7920
- } catch (error) {
7921
- sendResponse7(id, {
7922
- success: false,
7923
- error: error instanceof Error ? error.message : "Failed to get bookmarks by thread"
7924
- }, sendMessage, clientId);
7925
- }
7926
- }
7927
7851
  async function handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
7928
7852
  try {
7929
7853
  const result = await executeCollection("bookmarks", "query", {