@reverbia/sdk 1.0.0-next.20251202225102 → 1.0.0-next.20251203130707

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.
@@ -46682,7 +46682,8 @@ __export(index_exports, {
46682
46682
  useEncryption: () => useEncryption,
46683
46683
  useImageGeneration: () => useImageGeneration,
46684
46684
  useMemory: () => useMemory,
46685
- useModels: () => useModels
46685
+ useModels: () => useModels,
46686
+ useSearch: () => useSearch
46686
46687
  });
46687
46688
  module.exports = __toCommonJS(index_exports);
46688
46689
 
@@ -48447,6 +48448,16 @@ var getApiV1Models = (options) => {
48447
48448
  ...options
48448
48449
  });
48449
48450
  };
48451
+ var postApiV1Search = (options) => {
48452
+ return (options.client ?? client).post({
48453
+ url: "/api/v1/search",
48454
+ ...options,
48455
+ headers: {
48456
+ "Content-Type": "application/json",
48457
+ ...options.headers
48458
+ }
48459
+ });
48460
+ };
48450
48461
 
48451
48462
  // src/lib/memory/constants.ts
48452
48463
  var DEFAULT_LOCAL_EMBEDDING_MODEL = "Snowflake/snowflake-arctic-embed-xs";
@@ -48924,11 +48935,14 @@ function useModels(options = {}) {
48924
48935
  };
48925
48936
  }
48926
48937
 
48927
- // src/react/useImageGeneration.ts
48938
+ // src/react/useSearch.ts
48928
48939
  var import_react5 = require("react");
48929
- function useImageGeneration(options = {}) {
48930
- const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
48940
+ function useSearch(options = {}) {
48941
+ const { getToken, baseUrl = BASE_URL, onError } = options;
48931
48942
  const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
48943
+ const [results, setResults] = (0, import_react5.useState)(null);
48944
+ const [response, setResponse] = (0, import_react5.useState)(null);
48945
+ const [error, setError] = (0, import_react5.useState)(null);
48932
48946
  const abortControllerRef = (0, import_react5.useRef)(null);
48933
48947
  (0, import_react5.useEffect)(() => {
48934
48948
  return () => {
@@ -48938,13 +48952,94 @@ function useImageGeneration(options = {}) {
48938
48952
  }
48939
48953
  };
48940
48954
  }, []);
48941
- const stop = (0, import_react5.useCallback)(() => {
48955
+ const search = (0, import_react5.useCallback)(
48956
+ async (query, searchOptions = {}) => {
48957
+ if (abortControllerRef.current) {
48958
+ abortControllerRef.current.abort();
48959
+ }
48960
+ const abortController = new AbortController();
48961
+ abortControllerRef.current = abortController;
48962
+ setIsLoading(true);
48963
+ setError(null);
48964
+ setResults(null);
48965
+ setResponse(null);
48966
+ try {
48967
+ let token;
48968
+ if (getToken) {
48969
+ token = await getToken() ?? void 0;
48970
+ }
48971
+ if (abortController.signal.aborted) return null;
48972
+ const queryArray = Array.isArray(query) ? query : [query];
48973
+ const res = await postApiV1Search({
48974
+ baseUrl,
48975
+ body: {
48976
+ query: queryArray,
48977
+ ...searchOptions
48978
+ },
48979
+ headers: token ? {
48980
+ Authorization: `Bearer ${token}`
48981
+ } : void 0,
48982
+ signal: abortController.signal
48983
+ });
48984
+ if (res.error) {
48985
+ const errorMsg = res.error.error || res.error.message || "Failed to perform search";
48986
+ throw new Error(errorMsg);
48987
+ }
48988
+ if (res.data) {
48989
+ setResponse(res.data);
48990
+ setResults(res.data.results || []);
48991
+ return res.data;
48992
+ }
48993
+ return null;
48994
+ } catch (err) {
48995
+ if (err instanceof Error && err.name === "AbortError") {
48996
+ return null;
48997
+ }
48998
+ const errorObj = err instanceof Error ? err : new Error(String(err));
48999
+ setError(errorObj);
49000
+ if (onError) {
49001
+ onError(errorObj);
49002
+ }
49003
+ return null;
49004
+ } finally {
49005
+ if (abortControllerRef.current === abortController) {
49006
+ setIsLoading(false);
49007
+ abortControllerRef.current = null;
49008
+ }
49009
+ }
49010
+ },
49011
+ [baseUrl, getToken, onError]
49012
+ );
49013
+ return {
49014
+ isLoading,
49015
+ search,
49016
+ results,
49017
+ response,
49018
+ error
49019
+ };
49020
+ }
49021
+
49022
+ // src/react/useImageGeneration.ts
49023
+ var import_react6 = require("react");
49024
+ function useImageGeneration(options = {}) {
49025
+ const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
49026
+ const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
49027
+ const abortControllerRef = (0, import_react6.useRef)(null);
49028
+ (0, import_react6.useEffect)(() => {
49029
+ return () => {
49030
+ if (abortControllerRef.current) {
49031
+ abortControllerRef.current.abort();
49032
+ abortControllerRef.current = null;
49033
+ }
49034
+ };
49035
+ }, []);
49036
+ const stop = (0, import_react6.useCallback)(() => {
48942
49037
  if (abortControllerRef.current) {
48943
49038
  abortControllerRef.current.abort();
48944
49039
  abortControllerRef.current = null;
48945
49040
  }
48946
49041
  }, []);
48947
- const generateImage = (0, import_react5.useCallback)(
49042
+ const generateImage = (0, import_react6.useCallback)(
48948
49043
  async (args) => {
48949
49044
  if (abortControllerRef.current) {
48950
49045
  abortControllerRef.current.abort();
@@ -49075,7 +49170,8 @@ var extractConversationContext = (messages, maxMessages = 3) => {
49075
49170
  useEncryption,
49076
49171
  useImageGeneration,
49077
49172
  useMemory,
49078
- useModels
49173
+ useModels,
49174
+ useSearch
49079
49175
  });
49080
49176
  /*! Bundled license information:
49081
49177
 
@@ -288,6 +288,80 @@ type LlmapiModelTopProvider = {
288
288
  * Role is the message role (system, user, assistant)
289
289
  */
290
290
  type LlmapiRole = string;
291
+ /**
292
+ * ExtraFields contains additional metadata.
293
+ */
294
+ type LlmapiSearchExtraFields = {
295
+ /**
296
+ * RequestType is always "search".
297
+ */
298
+ request_type?: string;
299
+ /**
300
+ * SearchProvider is the search provider used (e.g., "perplexity", "google-pse").
301
+ */
302
+ search_provider?: string;
303
+ };
304
+ type LlmapiSearchRequest = {
305
+ /**
306
+ * Country code filter (e.g., "US", "GB", "DE").
307
+ */
308
+ country?: string;
309
+ /**
310
+ * Maximum number of results to return (1-20). Default: 10.
311
+ */
312
+ max_results?: number;
313
+ /**
314
+ * Maximum tokens per page to process. Default: 1024.
315
+ */
316
+ max_tokens_per_page?: number;
317
+ /**
318
+ * Search query. Can be a single string or array of strings.
319
+ */
320
+ query?: Array<string>;
321
+ /**
322
+ * List of domains to filter results (max 20 domains).
323
+ */
324
+ search_domain_filter?: Array<string>;
325
+ /**
326
+ * The search provider to use.
327
+ */
328
+ search_tool_name?: string;
329
+ };
330
+ type LlmapiSearchResponse = {
331
+ extra_fields?: LlmapiSearchExtraFields;
332
+ /**
333
+ * List of search results.
334
+ */
335
+ results?: Array<LlmapiSearchResult>;
336
+ usage?: LlmapiSearchUsage;
337
+ };
338
+ type LlmapiSearchResult = {
339
+ /**
340
+ * Optional publication or last updated date.
341
+ */
342
+ date?: string;
343
+ /**
344
+ * Text snippet from the result.
345
+ */
346
+ snippet?: string;
347
+ /**
348
+ * Title of the search result.
349
+ */
350
+ title?: string;
351
+ /**
352
+ * URL of the search result.
353
+ */
354
+ url?: string;
355
+ };
356
+ /**
357
+ * Usage contains usage information.
358
+ */
359
+ type LlmapiSearchUsage = {
360
+ /**
361
+ * CostMicroUSD is the cost of this search in micro-dollars (USD × 1,000,000).
362
+ */
363
+ cost_micro_usd?: number;
364
+ };
291
365
 
292
366
  /**
293
367
  * Parameter definition for a client-side tool
@@ -644,6 +718,47 @@ type UseModelsResult = {
644
718
  */
645
719
  declare function useModels(options?: UseModelsOptions): UseModelsResult;
646
720
 
721
+ type UseSearchOptions = {
722
+ /**
723
+ * Custom function to get auth token for API calls
724
+ */
725
+ getToken?: () => Promise<string | null>;
726
+ /**
727
+ * Optional base URL for the API requests.
728
+ */
729
+ baseUrl?: string;
730
+ /**
731
+ * Callback function to be called when an error is encountered.
732
+ */
733
+ onError?: (error: Error) => void;
734
+ };
735
+ type SearchOptions = Omit<LlmapiSearchRequest, "query">;
736
+ type UseSearchResult = {
737
+ isLoading: boolean;
738
+ search: (query: string | string[], options?: SearchOptions) => Promise<LlmapiSearchResponse | null>;
739
+ results: LlmapiSearchResult[] | null;
740
+ response: LlmapiSearchResponse | null;
741
+ error: Error | null;
742
+ };
743
+ /**
744
+ * React hook for performing search operations using the AI SDK.
745
+ *
746
+ * @param options - Configuration options for the search hook
747
+ * @returns Object containing search function, results, loading state, and error
748
+ *
749
+ * @example
750
+ * ```tsx
751
+ * const { search, results, isLoading } = useSearch({
752
+ * getToken: async () => "my-token"
753
+ * });
754
+ *
755
+ * const handleSearch = async () => {
756
+ * await search("What is ZetaChain?");
757
+ * };
758
+ * ```
759
+ */
760
+ declare function useSearch(options?: UseSearchOptions): UseSearchResult;
761
+
647
762
  type UseImageGenerationOptions = {
648
763
  /**
649
764
  * Custom function to get auth token for API calls
@@ -731,4 +846,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
731
846
  error?: string;
732
847
  }>;
733
848
 
734
- export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels };
849
+ export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, useSearch };
@@ -288,6 +288,80 @@ type LlmapiModelTopProvider = {
288
288
  * Role is the message role (system, user, assistant)
289
289
  */
290
290
  type LlmapiRole = string;
291
+ /**
292
+ * ExtraFields contains additional metadata.
293
+ */
294
+ type LlmapiSearchExtraFields = {
295
+ /**
296
+ * RequestType is always "search".
297
+ */
298
+ request_type?: string;
299
+ /**
300
+ * SearchProvider is the search provider used (e.g., "perplexity", "google-pse").
301
+ */
302
+ search_provider?: string;
303
+ };
304
+ type LlmapiSearchRequest = {
305
+ /**
306
+ * Country code filter (e.g., "US", "GB", "DE").
307
+ */
308
+ country?: string;
309
+ /**
310
+ * Maximum number of results to return (1-20). Default: 10.
311
+ */
312
+ max_results?: number;
313
+ /**
314
+ * Maximum tokens per page to process. Default: 1024.
315
+ */
316
+ max_tokens_per_page?: number;
317
+ /**
318
+ * Search query. Can be a single string or array of strings.
319
+ */
320
+ query?: Array<string>;
321
+ /**
322
+ * List of domains to filter results (max 20 domains).
323
+ */
324
+ search_domain_filter?: Array<string>;
325
+ /**
326
+ * The search provider to use.
327
+ */
328
+ search_tool_name?: string;
329
+ };
330
+ type LlmapiSearchResponse = {
331
+ extra_fields?: LlmapiSearchExtraFields;
332
+ /**
333
+ * List of search results.
334
+ */
335
+ results?: Array<LlmapiSearchResult>;
336
+ usage?: LlmapiSearchUsage;
337
+ };
338
+ type LlmapiSearchResult = {
339
+ /**
340
+ * Optional publication or last updated date.
341
+ */
342
+ date?: string;
343
+ /**
344
+ * Text snippet from the result.
345
+ */
346
+ snippet?: string;
347
+ /**
348
+ * Title of the search result.
349
+ */
350
+ title?: string;
351
+ /**
352
+ * URL of the search result.
353
+ */
354
+ url?: string;
355
+ };
356
+ /**
357
+ * Usage contains usage information.
358
+ */
359
+ type LlmapiSearchUsage = {
360
+ /**
361
+ * CostMicroUSD is the cost of this search in micro-dollars (USD × 1,000,000).
362
+ */
363
+ cost_micro_usd?: number;
364
+ };
291
365
 
292
366
  /**
293
367
  * Parameter definition for a client-side tool
@@ -644,6 +718,47 @@ type UseModelsResult = {
644
718
  */
645
719
  declare function useModels(options?: UseModelsOptions): UseModelsResult;
646
720
 
721
+ type UseSearchOptions = {
722
+ /**
723
+ * Custom function to get auth token for API calls
724
+ */
725
+ getToken?: () => Promise<string | null>;
726
+ /**
727
+ * Optional base URL for the API requests.
728
+ */
729
+ baseUrl?: string;
730
+ /**
731
+ * Callback function to be called when an error is encountered.
732
+ */
733
+ onError?: (error: Error) => void;
734
+ };
735
+ type SearchOptions = Omit<LlmapiSearchRequest, "query">;
736
+ type UseSearchResult = {
737
+ isLoading: boolean;
738
+ search: (query: string | string[], options?: SearchOptions) => Promise<LlmapiSearchResponse | null>;
739
+ results: LlmapiSearchResult[] | null;
740
+ response: LlmapiSearchResponse | null;
741
+ error: Error | null;
742
+ };
743
+ /**
744
+ * React hook for performing search operations using the AI SDK.
745
+ *
746
+ * @param options - Configuration options for the search hook
747
+ * @returns Object containing search function, results, loading state, and error
748
+ *
749
+ * @example
750
+ * ```tsx
751
+ * const { search, results, isLoading } = useSearch({
752
+ * getToken: async () => "my-token"
753
+ * });
754
+ *
755
+ * const handleSearch = async () => {
756
+ * await search("What is ZetaChain?");
757
+ * };
758
+ * ```
759
+ */
760
+ declare function useSearch(options?: UseSearchOptions): UseSearchResult;
761
+
647
762
  type UseImageGenerationOptions = {
648
763
  /**
649
764
  * Custom function to get auth token for API calls
@@ -731,4 +846,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
731
846
  error?: string;
732
847
  }>;
733
848
 
734
- export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels };
849
+ export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, useSearch };
@@ -1761,6 +1761,16 @@ var getApiV1Models = (options) => {
1761
1761
  ...options
1762
1762
  });
1763
1763
  };
1764
+ var postApiV1Search = (options) => {
1765
+ return (options.client ?? client).post({
1766
+ url: "/api/v1/search",
1767
+ ...options,
1768
+ headers: {
1769
+ "Content-Type": "application/json",
1770
+ ...options.headers
1771
+ }
1772
+ });
1773
+ };
1764
1774
 
1765
1775
  // src/lib/memory/constants.ts
1766
1776
  var DEFAULT_LOCAL_EMBEDDING_MODEL = "Snowflake/snowflake-arctic-embed-xs";
@@ -2238,11 +2248,14 @@ function useModels(options = {}) {
2238
2248
  };
2239
2249
  }
2240
2250
 
2241
- // src/react/useImageGeneration.ts
2251
+ // src/react/useSearch.ts
2242
2252
  import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef5, useState as useState3 } from "react";
2243
- function useImageGeneration(options = {}) {
2244
- const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
2253
+ function useSearch(options = {}) {
2254
+ const { getToken, baseUrl = BASE_URL, onError } = options;
2245
2255
  const [isLoading, setIsLoading] = useState3(false);
2256
+ const [results, setResults] = useState3(null);
2257
+ const [response, setResponse] = useState3(null);
2258
+ const [error, setError] = useState3(null);
2246
2259
  const abortControllerRef = useRef5(null);
2247
2260
  useEffect4(() => {
2248
2261
  return () => {
@@ -2252,13 +2265,94 @@ function useImageGeneration(options = {}) {
2252
2265
  }
2253
2266
  };
2254
2267
  }, []);
2255
- const stop = useCallback4(() => {
2268
+ const search = useCallback4(
2269
+ async (query, searchOptions = {}) => {
2270
+ if (abortControllerRef.current) {
2271
+ abortControllerRef.current.abort();
2272
+ }
2273
+ const abortController = new AbortController();
2274
+ abortControllerRef.current = abortController;
2275
+ setIsLoading(true);
2276
+ setError(null);
2277
+ setResults(null);
2278
+ setResponse(null);
2279
+ try {
2280
+ let token;
2281
+ if (getToken) {
2282
+ token = await getToken() ?? void 0;
2283
+ }
2284
+ if (abortController.signal.aborted) return null;
2285
+ const queryArray = Array.isArray(query) ? query : [query];
2286
+ const res = await postApiV1Search({
2287
+ baseUrl,
2288
+ body: {
2289
+ query: queryArray,
2290
+ ...searchOptions
2291
+ },
2292
+ headers: token ? {
2293
+ Authorization: `Bearer ${token}`
2294
+ } : void 0,
2295
+ signal: abortController.signal
2296
+ });
2297
+ if (res.error) {
2298
+ const errorMsg = res.error.error || res.error.message || "Failed to perform search";
2299
+ throw new Error(errorMsg);
2300
+ }
2301
+ if (res.data) {
2302
+ setResponse(res.data);
2303
+ setResults(res.data.results || []);
2304
+ return res.data;
2305
+ }
2306
+ return null;
2307
+ } catch (err) {
2308
+ if (err instanceof Error && err.name === "AbortError") {
2309
+ return null;
2310
+ }
2311
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2312
+ setError(errorObj);
2313
+ if (onError) {
2314
+ onError(errorObj);
2315
+ }
2316
+ return null;
2317
+ } finally {
2318
+ if (abortControllerRef.current === abortController) {
2319
+ setIsLoading(false);
2320
+ abortControllerRef.current = null;
2321
+ }
2322
+ }
2323
+ },
2324
+ [baseUrl, getToken, onError]
2325
+ );
2326
+ return {
2327
+ isLoading,
2328
+ search,
2329
+ results,
2330
+ response,
2331
+ error
2332
+ };
2333
+ }
2334
+
2335
+ // src/react/useImageGeneration.ts
2336
+ import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef6, useState as useState4 } from "react";
2337
+ function useImageGeneration(options = {}) {
2338
+ const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
2339
+ const [isLoading, setIsLoading] = useState4(false);
2340
+ const abortControllerRef = useRef6(null);
2341
+ useEffect5(() => {
2342
+ return () => {
2343
+ if (abortControllerRef.current) {
2344
+ abortControllerRef.current.abort();
2345
+ abortControllerRef.current = null;
2346
+ }
2347
+ };
2348
+ }, []);
2349
+ const stop = useCallback5(() => {
2256
2350
  if (abortControllerRef.current) {
2257
2351
  abortControllerRef.current.abort();
2258
2352
  abortControllerRef.current = null;
2259
2353
  }
2260
2354
  }, []);
2261
- const generateImage = useCallback4(
2355
+ const generateImage = useCallback5(
2262
2356
  async (args) => {
2263
2357
  if (abortControllerRef.current) {
2264
2358
  abortControllerRef.current.abort();
@@ -2388,5 +2482,6 @@ export {
2388
2482
  useEncryption,
2389
2483
  useImageGeneration,
2390
2484
  useMemory,
2391
- useModels
2485
+ useModels,
2486
+ useSearch
2392
2487
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reverbia/sdk",
3
- "version": "1.0.0-next.20251202225102",
3
+ "version": "1.0.0-next.20251203130707",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -57,7 +57,7 @@
57
57
  "homepage": "https://github.com/zeta-chain/ai-sdk#readme",
58
58
  "dependencies": {
59
59
  "@huggingface/transformers": "^3.8.0",
60
- "@reverbia/portal": "1.0.0-next.20251201184846",
60
+ "@reverbia/portal": "1.0.0-next.20251202220311",
61
61
  "ai": "5.0.93"
62
62
  },
63
63
  "devDependencies": {