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

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.
@@ -688,6 +688,17 @@ type UseMemoryResult = {
688
688
  */
689
689
  declare function useMemory(options?: UseMemoryOptions): UseMemoryResult;
690
690
 
691
+ interface PdfFile {
692
+ url: string;
693
+ mediaType?: string;
694
+ filename?: string;
695
+ }
696
+ declare function usePdf(): {
697
+ extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
698
+ isProcessing: boolean;
699
+ error: Error | null;
700
+ };
701
+
691
702
  type UseModelsOptions = {
692
703
  /**
693
704
  * Custom function to get auth token for API calls
@@ -846,4 +857,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
846
857
  error?: string;
847
858
  }>;
848
859
 
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 };
860
+ export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
@@ -688,6 +688,17 @@ type UseMemoryResult = {
688
688
  */
689
689
  declare function useMemory(options?: UseMemoryOptions): UseMemoryResult;
690
690
 
691
+ interface PdfFile {
692
+ url: string;
693
+ mediaType?: string;
694
+ filename?: string;
695
+ }
696
+ declare function usePdf(): {
697
+ extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
698
+ isProcessing: boolean;
699
+ error: Error | null;
700
+ };
701
+
691
702
  type UseModelsOptions = {
692
703
  /**
693
704
  * Custom function to get auth token for API calls
@@ -846,4 +857,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
846
857
  error?: string;
847
858
  }>;
848
859
 
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 };
860
+ export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
@@ -830,7 +830,7 @@ async function getTextGenerationPipeline(options) {
830
830
  if (sharedPipeline && currentModel === model && currentDevice === device) {
831
831
  return sharedPipeline;
832
832
  }
833
- const { pipeline, env } = await import("./transformers.node-BSHUG7OY.mjs");
833
+ const { pipeline, env } = await import("./transformers.node-LUTOZWVQ.mjs");
834
834
  env.allowLocalModels = false;
835
835
  if (env.backends?.onnx) {
836
836
  env.backends.onnx.logLevel = "fatal";
@@ -856,7 +856,7 @@ async function generateLocalChatCompletion(messages, options = {}) {
856
856
  onToken,
857
857
  signal
858
858
  } = options;
859
- const { TextStreamer } = await import("./transformers.node-BSHUG7OY.mjs");
859
+ const { TextStreamer } = await import("./transformers.node-LUTOZWVQ.mjs");
860
860
  const chatPipeline = await getTextGenerationPipeline({
861
861
  model,
862
862
  device: "wasm",
@@ -1816,7 +1816,7 @@ var generateEmbeddingForText = async (text, options = {}) => {
1816
1816
  }
1817
1817
  try {
1818
1818
  if (!embeddingPipeline) {
1819
- const { pipeline } = await import("./transformers.node-BSHUG7OY.mjs");
1819
+ const { pipeline } = await import("./transformers.node-LUTOZWVQ.mjs");
1820
1820
  embeddingPipeline = await pipeline("feature-extraction", model);
1821
1821
  }
1822
1822
  const output = await embeddingPipeline(text, {
@@ -2144,13 +2144,90 @@ function useMemory(options = {}) {
2144
2144
  };
2145
2145
  }
2146
2146
 
2147
+ // src/react/usePdf.ts
2148
+ import { useCallback as useCallback3, useState as useState2 } from "react";
2149
+
2150
+ // src/lib/pdf.ts
2151
+ import * as pdfjs from "pdfjs-dist";
2152
+ pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
2153
+ async function extractTextFromPdf(pdfDataUrl) {
2154
+ try {
2155
+ const loadingTask = pdfjs.getDocument(pdfDataUrl);
2156
+ const pdf = await loadingTask.promise;
2157
+ const textParts = [];
2158
+ for (let i = 1; i <= pdf.numPages; i++) {
2159
+ const page = await pdf.getPage(i);
2160
+ const textContent = await page.getTextContent();
2161
+ const pageText = textContent.items.map((item) => item.str).join(" ");
2162
+ if (pageText.trim()) {
2163
+ textParts.push(pageText);
2164
+ }
2165
+ }
2166
+ return textParts.join("\n\n");
2167
+ } catch (error) {
2168
+ console.error("Error extracting text from PDF:", error);
2169
+ throw error;
2170
+ }
2171
+ }
2172
+
2173
+ // src/react/usePdf.ts
2174
+ var PDF_MIME_TYPE = "application/pdf";
2175
+ function usePdf() {
2176
+ const [isProcessing, setIsProcessing] = useState2(false);
2177
+ const [error, setError] = useState2(null);
2178
+ const extractPdfContext = useCallback3(
2179
+ async (files) => {
2180
+ setIsProcessing(true);
2181
+ setError(null);
2182
+ try {
2183
+ const pdfFiles = files.filter(
2184
+ (file) => file.mediaType === PDF_MIME_TYPE || file.filename?.toLowerCase().endsWith(".pdf")
2185
+ );
2186
+ if (pdfFiles.length === 0) {
2187
+ return null;
2188
+ }
2189
+ const contexts = await Promise.all(
2190
+ pdfFiles.map(async (file) => {
2191
+ try {
2192
+ const text = await extractTextFromPdf(file.url);
2193
+ if (!text.trim()) {
2194
+ console.warn(`No text found in PDF ${file.filename}`);
2195
+ return null;
2196
+ }
2197
+ return `[Context from PDF attachment ${file.filename}]:
2198
+ ${text}`;
2199
+ } catch (err) {
2200
+ console.error(`Failed to process PDF ${file.filename}:`, err);
2201
+ return null;
2202
+ }
2203
+ })
2204
+ );
2205
+ const mergedContext = contexts.filter(Boolean).join("\n\n");
2206
+ return mergedContext || null;
2207
+ } catch (err) {
2208
+ const processedError = err instanceof Error ? err : new Error(String(err));
2209
+ setError(processedError);
2210
+ throw processedError;
2211
+ } finally {
2212
+ setIsProcessing(false);
2213
+ }
2214
+ },
2215
+ []
2216
+ );
2217
+ return {
2218
+ extractPdfContext,
2219
+ isProcessing,
2220
+ error
2221
+ };
2222
+ }
2223
+
2147
2224
  // src/react/useModels.ts
2148
- import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef4, useState as useState2 } from "react";
2225
+ import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
2149
2226
  function useModels(options = {}) {
2150
2227
  const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
2151
- const [models, setModels] = useState2([]);
2152
- const [isLoading, setIsLoading] = useState2(false);
2153
- const [error, setError] = useState2(null);
2228
+ const [models, setModels] = useState3([]);
2229
+ const [isLoading, setIsLoading] = useState3(false);
2230
+ const [error, setError] = useState3(null);
2154
2231
  const getTokenRef = useRef4(getToken);
2155
2232
  const baseUrlRef = useRef4(baseUrl);
2156
2233
  const providerRef = useRef4(provider);
@@ -2168,7 +2245,7 @@ function useModels(options = {}) {
2168
2245
  }
2169
2246
  };
2170
2247
  }, []);
2171
- const fetchModels = useCallback3(async () => {
2248
+ const fetchModels = useCallback4(async () => {
2172
2249
  if (abortControllerRef.current) {
2173
2250
  abortControllerRef.current.abort();
2174
2251
  }
@@ -2226,7 +2303,7 @@ function useModels(options = {}) {
2226
2303
  }
2227
2304
  }
2228
2305
  }, []);
2229
- const refetch = useCallback3(async () => {
2306
+ const refetch = useCallback4(async () => {
2230
2307
  setModels([]);
2231
2308
  await fetchModels();
2232
2309
  }, [fetchModels]);
@@ -2249,13 +2326,13 @@ function useModels(options = {}) {
2249
2326
  }
2250
2327
 
2251
2328
  // src/react/useSearch.ts
2252
- import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef5, useState as useState3 } from "react";
2329
+ import { useCallback as useCallback5, useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
2253
2330
  function useSearch(options = {}) {
2254
2331
  const { getToken, baseUrl = BASE_URL, onError } = options;
2255
- const [isLoading, setIsLoading] = useState3(false);
2256
- const [results, setResults] = useState3(null);
2257
- const [response, setResponse] = useState3(null);
2258
- const [error, setError] = useState3(null);
2332
+ const [isLoading, setIsLoading] = useState4(false);
2333
+ const [results, setResults] = useState4(null);
2334
+ const [response, setResponse] = useState4(null);
2335
+ const [error, setError] = useState4(null);
2259
2336
  const abortControllerRef = useRef5(null);
2260
2337
  useEffect4(() => {
2261
2338
  return () => {
@@ -2265,7 +2342,7 @@ function useSearch(options = {}) {
2265
2342
  }
2266
2343
  };
2267
2344
  }, []);
2268
- const search = useCallback4(
2345
+ const search = useCallback5(
2269
2346
  async (query, searchOptions = {}) => {
2270
2347
  if (abortControllerRef.current) {
2271
2348
  abortControllerRef.current.abort();
@@ -2333,10 +2410,10 @@ function useSearch(options = {}) {
2333
2410
  }
2334
2411
 
2335
2412
  // src/react/useImageGeneration.ts
2336
- import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef6, useState as useState4 } from "react";
2413
+ import { useCallback as useCallback6, useEffect as useEffect5, useRef as useRef6, useState as useState5 } from "react";
2337
2414
  function useImageGeneration(options = {}) {
2338
2415
  const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
2339
- const [isLoading, setIsLoading] = useState4(false);
2416
+ const [isLoading, setIsLoading] = useState5(false);
2340
2417
  const abortControllerRef = useRef6(null);
2341
2418
  useEffect5(() => {
2342
2419
  return () => {
@@ -2346,13 +2423,13 @@ function useImageGeneration(options = {}) {
2346
2423
  }
2347
2424
  };
2348
2425
  }, []);
2349
- const stop = useCallback5(() => {
2426
+ const stop = useCallback6(() => {
2350
2427
  if (abortControllerRef.current) {
2351
2428
  abortControllerRef.current.abort();
2352
2429
  abortControllerRef.current = null;
2353
2430
  }
2354
2431
  }, []);
2355
- const generateImage = useCallback5(
2432
+ const generateImage = useCallback6(
2356
2433
  async (args) => {
2357
2434
  if (abortControllerRef.current) {
2358
2435
  abortControllerRef.current.abort();
@@ -2483,5 +2560,6 @@ export {
2483
2560
  useImageGeneration,
2484
2561
  useMemory,
2485
2562
  useModels,
2563
+ usePdf,
2486
2564
  useSearch
2487
2565
  };