@reverbia/sdk 1.0.0-next.20251218225706 → 1.0.0-next.20251219092050

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.
@@ -348,6 +348,295 @@ type LlmapiSearchUsage = {
348
348
  cost_micro_usd?: number;
349
349
  };
350
350
 
351
+ type AuthToken = string | undefined;
352
+ interface Auth {
353
+ /**
354
+ * Which part of the request do we use to send the auth?
355
+ *
356
+ * @default 'header'
357
+ */
358
+ in?: 'header' | 'query' | 'cookie';
359
+ /**
360
+ * Header or query parameter name.
361
+ *
362
+ * @default 'Authorization'
363
+ */
364
+ name?: string;
365
+ scheme?: 'basic' | 'bearer';
366
+ type: 'apiKey' | 'http';
367
+ }
368
+
369
+ interface SerializerOptions<T> {
370
+ /**
371
+ * @default true
372
+ */
373
+ explode: boolean;
374
+ style: T;
375
+ }
376
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
377
+ type ObjectStyle = 'form' | 'deepObject';
378
+
379
+ type QuerySerializer = (query: Record<string, unknown>) => string;
380
+ type BodySerializer = (body: any) => any;
381
+ type QuerySerializerOptionsObject = {
382
+ allowReserved?: boolean;
383
+ array?: Partial<SerializerOptions<ArrayStyle>>;
384
+ object?: Partial<SerializerOptions<ObjectStyle>>;
385
+ };
386
+ type QuerySerializerOptions = QuerySerializerOptionsObject & {
387
+ /**
388
+ * Per-parameter serialization overrides. When provided, these settings
389
+ * override the global array/object settings for specific parameter names.
390
+ */
391
+ parameters?: Record<string, QuerySerializerOptionsObject>;
392
+ };
393
+
394
+ type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
395
+ type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
396
+ /**
397
+ * Returns the final request URL.
398
+ */
399
+ buildUrl: BuildUrlFn;
400
+ getConfig: () => Config;
401
+ request: RequestFn;
402
+ setConfig: (config: Config) => Config;
403
+ } & {
404
+ [K in HttpMethod]: MethodFn;
405
+ } & ([SseFn] extends [never] ? {
406
+ sse?: never;
407
+ } : {
408
+ sse: {
409
+ [K in HttpMethod]: SseFn;
410
+ };
411
+ });
412
+ interface Config$1 {
413
+ /**
414
+ * Auth token or a function returning auth token. The resolved value will be
415
+ * added to the request payload as defined by its `security` array.
416
+ */
417
+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
418
+ /**
419
+ * A function for serializing request body parameter. By default,
420
+ * {@link JSON.stringify()} will be used.
421
+ */
422
+ bodySerializer?: BodySerializer | null;
423
+ /**
424
+ * An object containing any HTTP headers that you want to pre-populate your
425
+ * `Headers` object with.
426
+ *
427
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
428
+ */
429
+ headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
430
+ /**
431
+ * The request method.
432
+ *
433
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
434
+ */
435
+ method?: Uppercase<HttpMethod>;
436
+ /**
437
+ * A function for serializing request query parameters. By default, arrays
438
+ * will be exploded in form style, objects will be exploded in deepObject
439
+ * style, and reserved characters are percent-encoded.
440
+ *
441
+ * This method will have no effect if the native `paramsSerializer()` Axios
442
+ * API function is used.
443
+ *
444
+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
445
+ */
446
+ querySerializer?: QuerySerializer | QuerySerializerOptions;
447
+ /**
448
+ * A function validating request data. This is useful if you want to ensure
449
+ * the request conforms to the desired shape, so it can be safely sent to
450
+ * the server.
451
+ */
452
+ requestValidator?: (data: unknown) => Promise<unknown>;
453
+ /**
454
+ * A function transforming response data before it's returned. This is useful
455
+ * for post-processing data, e.g. converting ISO strings into Date objects.
456
+ */
457
+ responseTransformer?: (data: unknown) => Promise<unknown>;
458
+ /**
459
+ * A function validating response data. This is useful if you want to ensure
460
+ * the response conforms to the desired shape, so it can be safely passed to
461
+ * the transformers and returned to the user.
462
+ */
463
+ responseValidator?: (data: unknown) => Promise<unknown>;
464
+ }
465
+
466
+ type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
467
+ /**
468
+ * Fetch API implementation. You can use this option to provide a custom
469
+ * fetch instance.
470
+ *
471
+ * @default globalThis.fetch
472
+ */
473
+ fetch?: typeof fetch;
474
+ /**
475
+ * Implementing clients can call request interceptors inside this hook.
476
+ */
477
+ onRequest?: (url: string, init: RequestInit) => Promise<Request>;
478
+ /**
479
+ * Callback invoked when a network or parsing error occurs during streaming.
480
+ *
481
+ * This option applies only if the endpoint returns a stream of events.
482
+ *
483
+ * @param error The error that occurred.
484
+ */
485
+ onSseError?: (error: unknown) => void;
486
+ /**
487
+ * Callback invoked when an event is streamed from the server.
488
+ *
489
+ * This option applies only if the endpoint returns a stream of events.
490
+ *
491
+ * @param event Event streamed from the server.
492
+ * @returns Nothing (void).
493
+ */
494
+ onSseEvent?: (event: StreamEvent<TData>) => void;
495
+ serializedBody?: RequestInit['body'];
496
+ /**
497
+ * Default retry delay in milliseconds.
498
+ *
499
+ * This option applies only if the endpoint returns a stream of events.
500
+ *
501
+ * @default 3000
502
+ */
503
+ sseDefaultRetryDelay?: number;
504
+ /**
505
+ * Maximum number of retry attempts before giving up.
506
+ */
507
+ sseMaxRetryAttempts?: number;
508
+ /**
509
+ * Maximum retry delay in milliseconds.
510
+ *
511
+ * Applies only when exponential backoff is used.
512
+ *
513
+ * This option applies only if the endpoint returns a stream of events.
514
+ *
515
+ * @default 30000
516
+ */
517
+ sseMaxRetryDelay?: number;
518
+ /**
519
+ * Optional sleep function for retry backoff.
520
+ *
521
+ * Defaults to using `setTimeout`.
522
+ */
523
+ sseSleepFn?: (ms: number) => Promise<void>;
524
+ url: string;
525
+ };
526
+ interface StreamEvent<TData = unknown> {
527
+ data: TData;
528
+ event?: string;
529
+ id?: string;
530
+ retry?: number;
531
+ }
532
+ type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
533
+ stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
534
+ };
535
+
536
+ type ErrInterceptor<Err, Res, Options> = (error: Err, response: Res, options: Options) => Err | Promise<Err>;
537
+ type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
538
+ type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
539
+ declare class Interceptors<Interceptor> {
540
+ fns: Array<Interceptor | null>;
541
+ clear(): void;
542
+ eject(id: number | Interceptor): void;
543
+ exists(id: number | Interceptor): boolean;
544
+ getInterceptorIndex(id: number | Interceptor): number;
545
+ update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
546
+ use(fn: Interceptor): number;
547
+ }
548
+ interface Middleware<Res, Err, Options> {
549
+ error: Interceptors<ErrInterceptor<Err, Res, Options>>;
550
+ request: Interceptors<ReqInterceptor<Options>>;
551
+ response: Interceptors<ResInterceptor<Res, Options>>;
552
+ }
553
+
554
+ interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
555
+ /**
556
+ * Base URL for all requests made by this client.
557
+ */
558
+ baseUrl?: T['baseUrl'];
559
+ /**
560
+ * Fetch API implementation. You can use this option to provide a custom
561
+ * fetch instance.
562
+ *
563
+ * @default globalThis.fetch
564
+ */
565
+ fetch?: typeof fetch;
566
+ /**
567
+ * Return the response data parsed in a specified format. By default, `auto`
568
+ * will infer the appropriate method from the `Content-Type` response header.
569
+ * You can override this behavior with any of the {@link Body} methods.
570
+ * Select `stream` if you don't want to parse response data at all.
571
+ *
572
+ * @default 'auto'
573
+ */
574
+ parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
575
+ /**
576
+ * Throw an error instead of returning it in the response?
577
+ *
578
+ * @default false
579
+ */
580
+ throwOnError?: T['throwOnError'];
581
+ }
582
+ interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
583
+ throwOnError: ThrowOnError;
584
+ }>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
585
+ /**
586
+ * Any body that you want to add to your request.
587
+ *
588
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
589
+ */
590
+ body?: unknown;
591
+ path?: Record<string, unknown>;
592
+ query?: Record<string, unknown>;
593
+ /**
594
+ * Security mechanism(s) to use for the request.
595
+ */
596
+ security?: ReadonlyArray<Auth>;
597
+ url: Url;
598
+ }
599
+ interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
600
+ serializedBody?: string;
601
+ }
602
+ type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
603
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
604
+ response: Response;
605
+ }> : Promise<({
606
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
607
+ error: undefined;
608
+ } | {
609
+ data: undefined;
610
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
611
+ }) & {
612
+ response: Response;
613
+ }>;
614
+ interface ClientOptions {
615
+ baseUrl?: string;
616
+ throwOnError?: boolean;
617
+ }
618
+ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
619
+ type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
620
+ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
621
+ type BuildUrlFn = <TData extends {
622
+ body?: unknown;
623
+ path?: Record<string, unknown>;
624
+ query?: Record<string, unknown>;
625
+ url: string;
626
+ }>(options: TData & Options<TData>) => string;
627
+ type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
628
+ interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
629
+ };
630
+ interface TDataShape {
631
+ body?: unknown;
632
+ headers?: unknown;
633
+ path?: unknown;
634
+ query?: unknown;
635
+ url: string;
636
+ }
637
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
638
+ type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
639
+
351
640
  /**
352
641
  * Parameter definition for a client-side tool
353
642
  */
@@ -1567,26 +1856,23 @@ interface UseDropboxBackupResult {
1567
1856
  declare function useDropboxBackup(options: UseDropboxBackupOptions): UseDropboxBackupResult;
1568
1857
 
1569
1858
  /**
1570
- * Dropbox OAuth 2.0 with PKCE
1859
+ * Dropbox OAuth 2.0 Authorization Code Flow
1571
1860
  *
1572
1861
  * Flow:
1573
- * 1. Generate code_verifier and code_challenge
1574
- * 2. Redirect user to Dropbox authorization URL
1575
- * 3. User authorizes and is redirected back with authorization code
1576
- * 4. Exchange code for access token using code_verifier
1577
- */
1578
- /**
1579
- * Get the stored access token from session storage
1862
+ * 1. Redirect user to Dropbox authorization URL
1863
+ * 2. User authorizes and is redirected back with authorization code
1864
+ * 3. Exchange code on backend for access + refresh tokens
1865
+ * 4. Use refresh token to get new access tokens silently
1580
1866
  */
1581
- declare function getStoredToken(): string | null;
1867
+
1582
1868
  /**
1583
- * Store access token in session storage
1869
+ * Clear Dropbox token data
1584
1870
  */
1585
- declare function storeToken(token: string): void;
1871
+ declare function clearToken(): void;
1586
1872
  /**
1587
- * Clear stored access token
1873
+ * Check if we have any stored credentials (including refresh token)
1588
1874
  */
1589
- declare function clearToken(): void;
1875
+ declare function hasDropboxCredentials(): boolean;
1590
1876
 
1591
1877
  /**
1592
1878
  * Props for DropboxAuthProvider
@@ -1594,8 +1880,13 @@ declare function clearToken(): void;
1594
1880
  interface DropboxAuthProviderProps {
1595
1881
  /** Dropbox App Key (from Dropbox Developer Console) */
1596
1882
  appKey: string | undefined;
1597
- /** OAuth callback path (e.g., "/auth/dropbox/callback") */
1883
+ /** OAuth callback path (default: "/auth/dropbox/callback") */
1598
1884
  callbackPath?: string;
1885
+ /**
1886
+ * API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
1887
+ * Only needed if you have a custom client configuration (e.g., different baseUrl).
1888
+ */
1889
+ apiClient?: Client;
1599
1890
  /** Children to render */
1600
1891
  children: ReactNode;
1601
1892
  }
@@ -1612,13 +1903,15 @@ interface DropboxAuthContextValue {
1612
1903
  /** Request Dropbox access - returns token or redirects to OAuth */
1613
1904
  requestAccess: () => Promise<string>;
1614
1905
  /** Clear stored token and log out */
1615
- logout: () => void;
1906
+ logout: () => Promise<void>;
1907
+ /** Refresh the access token using the refresh token */
1908
+ refreshToken: () => Promise<string | null>;
1616
1909
  }
1617
1910
  /**
1618
1911
  * Provider component for Dropbox OAuth authentication.
1619
1912
  *
1620
1913
  * Wrap your app with this provider to enable Dropbox authentication.
1621
- * It handles the OAuth 2.0 PKCE flow automatically.
1914
+ * It handles the OAuth 2.0 Authorization Code flow with refresh tokens.
1622
1915
  *
1623
1916
  * @example
1624
1917
  * ```tsx
@@ -1638,7 +1931,7 @@ interface DropboxAuthContextValue {
1638
1931
  *
1639
1932
  * @category Components
1640
1933
  */
1641
- declare function DropboxAuthProvider({ appKey, callbackPath, children, }: DropboxAuthProviderProps): JSX.Element;
1934
+ declare function DropboxAuthProvider({ appKey, callbackPath, apiClient, children, }: DropboxAuthProviderProps): JSX.Element;
1642
1935
  /**
1643
1936
  * Hook to access Dropbox authentication state and methods.
1644
1937
  *
@@ -1667,6 +1960,115 @@ declare function DropboxAuthProvider({ appKey, callbackPath, children, }: Dropbo
1667
1960
  */
1668
1961
  declare function useDropboxAuth(): DropboxAuthContextValue;
1669
1962
 
1963
+ /**
1964
+ * Google Drive OAuth 2.0 Authorization Code Flow
1965
+ *
1966
+ * Flow:
1967
+ * 1. Redirect user to Google authorization URL
1968
+ * 2. User authorizes and is redirected back with authorization code
1969
+ * 3. Exchange code on backend for access + refresh tokens
1970
+ * 4. Use refresh token to get new access tokens silently
1971
+ */
1972
+
1973
+ /**
1974
+ * Get stored token data for Google Drive
1975
+ */
1976
+ declare function getGoogleDriveStoredToken(): string | null;
1977
+ /**
1978
+ * Clear Google Drive token data
1979
+ */
1980
+ declare function clearGoogleDriveToken(): void;
1981
+ /**
1982
+ * Check if we have any stored credentials (including refresh token)
1983
+ */
1984
+ declare function hasGoogleDriveCredentials(): boolean;
1985
+
1986
+ /**
1987
+ * Props for GoogleDriveAuthProvider
1988
+ */
1989
+ interface GoogleDriveAuthProviderProps {
1990
+ /** Google OAuth Client ID (from Google Cloud Console) */
1991
+ clientId: string | undefined;
1992
+ /** OAuth callback path (default: "/auth/google/callback") */
1993
+ callbackPath?: string;
1994
+ /**
1995
+ * API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
1996
+ * Only needed if you have a custom client configuration (e.g., different baseUrl).
1997
+ */
1998
+ apiClient?: Client;
1999
+ /** Children to render */
2000
+ children: ReactNode;
2001
+ }
2002
+ /**
2003
+ * Context value for Google Drive authentication
2004
+ */
2005
+ interface GoogleDriveAuthContextValue {
2006
+ /** Current access token (null if not authenticated) */
2007
+ accessToken: string | null;
2008
+ /** Whether user has authenticated with Google Drive */
2009
+ isAuthenticated: boolean;
2010
+ /** Whether Google Drive is configured (client ID exists) */
2011
+ isConfigured: boolean;
2012
+ /** Request Google Drive access - returns token or redirects to OAuth */
2013
+ requestAccess: () => Promise<string>;
2014
+ /** Clear stored token and log out */
2015
+ logout: () => Promise<void>;
2016
+ /** Refresh the access token using the refresh token */
2017
+ refreshToken: () => Promise<string | null>;
2018
+ }
2019
+ /**
2020
+ * Provider component for Google Drive OAuth authentication.
2021
+ *
2022
+ * Wrap your app with this provider to enable Google Drive authentication.
2023
+ * It handles the OAuth 2.0 Authorization Code flow with refresh tokens.
2024
+ *
2025
+ * @example
2026
+ * ```tsx
2027
+ * import { GoogleDriveAuthProvider } from "@reverbia/sdk/react";
2028
+ *
2029
+ * function App() {
2030
+ * return (
2031
+ * <GoogleDriveAuthProvider
2032
+ * clientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
2033
+ * callbackPath="/auth/google/callback"
2034
+ * >
2035
+ * <MyApp />
2036
+ * </GoogleDriveAuthProvider>
2037
+ * );
2038
+ * }
2039
+ * ```
2040
+ *
2041
+ * @category Components
2042
+ */
2043
+ declare function GoogleDriveAuthProvider({ clientId, callbackPath, apiClient, children, }: GoogleDriveAuthProviderProps): JSX.Element;
2044
+ /**
2045
+ * Hook to access Google Drive authentication state and methods.
2046
+ *
2047
+ * Must be used within a GoogleDriveAuthProvider.
2048
+ *
2049
+ * @example
2050
+ * ```tsx
2051
+ * import { useGoogleDriveAuth } from "@reverbia/sdk/react";
2052
+ *
2053
+ * function GoogleDriveButton() {
2054
+ * const { isAuthenticated, isConfigured, requestAccess, logout } = useGoogleDriveAuth();
2055
+ *
2056
+ * if (!isConfigured) {
2057
+ * return <p>Google Drive not configured</p>;
2058
+ * }
2059
+ *
2060
+ * if (isAuthenticated) {
2061
+ * return <button onClick={logout}>Disconnect Google Drive</button>;
2062
+ * }
2063
+ *
2064
+ * return <button onClick={requestAccess}>Connect Google Drive</button>;
2065
+ * }
2066
+ * ```
2067
+ *
2068
+ * @category Hooks
2069
+ */
2070
+ declare function useGoogleDriveAuth(): GoogleDriveAuthContextValue;
2071
+
1670
2072
  /**
1671
2073
  * Google Drive API utilities
1672
2074
  *
@@ -1708,10 +2110,6 @@ interface UseGoogleDriveBackupOptions {
1708
2110
  database: Database;
1709
2111
  /** Current user address (null if not signed in) */
1710
2112
  userAddress: string | null;
1711
- /** Current Google Drive access token (null if not authenticated) */
1712
- accessToken: string | null;
1713
- /** Request Google Drive access - returns access token */
1714
- requestDriveAccess: () => Promise<string>;
1715
2113
  /** Request encryption key for the user address */
1716
2114
  requestEncryptionKey: (address: string) => Promise<void>;
1717
2115
  /** Export a conversation to an encrypted blob */
@@ -1744,6 +2142,8 @@ interface UseGoogleDriveBackupResult {
1744
2142
  }) => Promise<GoogleDriveImportResult | {
1745
2143
  error: string;
1746
2144
  }>;
2145
+ /** Whether Google Drive is configured */
2146
+ isConfigured: boolean;
1747
2147
  /** Whether user has a Google Drive token */
1748
2148
  isAuthenticated: boolean;
1749
2149
  }
@@ -1752,23 +2152,18 @@ interface UseGoogleDriveBackupResult {
1752
2152
  *
1753
2153
  * This hook provides methods to backup conversations to Google Drive and restore them.
1754
2154
  * It handles all the logic for checking timestamps, skipping unchanged files,
1755
- * and managing the backup/restore process.
2155
+ * authentication, and managing the backup/restore process.
1756
2156
  *
1757
- * Unlike Dropbox, Google Drive auth requires browser-specific setup (Google Identity Services),
1758
- * so the auth provider must be implemented in the app. This hook accepts the auth
1759
- * callbacks as options.
2157
+ * Must be used within a GoogleDriveAuthProvider.
1760
2158
  *
1761
2159
  * @example
1762
2160
  * ```tsx
1763
2161
  * import { useGoogleDriveBackup } from "@reverbia/sdk/react";
1764
2162
  *
1765
2163
  * function BackupButton() {
1766
- * const { accessToken, requestDriveAccess } = useGoogleAccessToken();
1767
- * const { backup, restore, isAuthenticated } = useGoogleDriveBackup({
2164
+ * const { backup, restore, isConfigured, isAuthenticated } = useGoogleDriveBackup({
1768
2165
  * database,
1769
2166
  * userAddress,
1770
- * accessToken,
1771
- * requestDriveAccess,
1772
2167
  * requestEncryptionKey,
1773
2168
  * exportConversation,
1774
2169
  * importConversation,
@@ -1788,7 +2183,7 @@ interface UseGoogleDriveBackupResult {
1788
2183
  * }
1789
2184
  * };
1790
2185
  *
1791
- * return <button onClick={handleBackup}>Backup</button>;
2186
+ * return <button onClick={handleBackup} disabled={!isConfigured}>Backup</button>;
1792
2187
  * }
1793
2188
  * ```
1794
2189
  *
@@ -1796,4 +2191,275 @@ interface UseGoogleDriveBackupResult {
1796
2191
  */
1797
2192
  declare function useGoogleDriveBackup(options: UseGoogleDriveBackupOptions): UseGoogleDriveBackupResult;
1798
2193
 
1799
- export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ClientTool, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_TOOL_SELECTOR_MODEL, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveExportResult, type GoogleDriveImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearToken as clearDropboxToken, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getStoredToken as getDropboxToken, hasEncryptionKey, memoryStorageSchema, requestEncryptionKey, sdkMigrations, sdkModelClasses, sdkSchema, selectTool, settingsStorageSchema, storeToken as storeDropboxToken, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
2194
+ /**
2195
+ * Props for BackupAuthProvider
2196
+ *
2197
+ * At least one of `dropboxAppKey` or `googleClientId` should be provided
2198
+ * for the provider to be useful. Both are optional to allow using just
2199
+ * one backup provider.
2200
+ */
2201
+ interface BackupAuthProviderProps {
2202
+ /** Dropbox App Key (from Dropbox Developer Console). Optional - omit to disable Dropbox. */
2203
+ dropboxAppKey?: string;
2204
+ /** Dropbox OAuth callback path (default: "/auth/dropbox/callback") */
2205
+ dropboxCallbackPath?: string;
2206
+ /** Google OAuth Client ID (from Google Cloud Console). Optional - omit to disable Google Drive. */
2207
+ googleClientId?: string;
2208
+ /** Google OAuth callback path (default: "/auth/google/callback") */
2209
+ googleCallbackPath?: string;
2210
+ /**
2211
+ * API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
2212
+ * Only needed if you have a custom client configuration (e.g., different baseUrl).
2213
+ */
2214
+ apiClient?: Client;
2215
+ /** Children to render */
2216
+ children: ReactNode;
2217
+ }
2218
+ /**
2219
+ * Auth state for a single provider
2220
+ */
2221
+ interface ProviderAuthState {
2222
+ /** Current access token (null if not authenticated) */
2223
+ accessToken: string | null;
2224
+ /** Whether user has authenticated with this provider */
2225
+ isAuthenticated: boolean;
2226
+ /** Whether this provider is configured */
2227
+ isConfigured: boolean;
2228
+ /** Request access - returns token or redirects to OAuth */
2229
+ requestAccess: () => Promise<string>;
2230
+ /** Clear stored token and log out */
2231
+ logout: () => Promise<void>;
2232
+ /** Refresh the access token using the refresh token */
2233
+ refreshToken: () => Promise<string | null>;
2234
+ }
2235
+ /**
2236
+ * Context value for unified backup authentication
2237
+ */
2238
+ interface BackupAuthContextValue {
2239
+ /** Dropbox authentication state and methods */
2240
+ dropbox: ProviderAuthState;
2241
+ /** Google Drive authentication state and methods */
2242
+ googleDrive: ProviderAuthState;
2243
+ /** Check if any provider is configured */
2244
+ hasAnyProvider: boolean;
2245
+ /** Check if any provider is authenticated */
2246
+ hasAnyAuthentication: boolean;
2247
+ /** Logout from all providers */
2248
+ logoutAll: () => Promise<void>;
2249
+ }
2250
+ /**
2251
+ * Unified provider component for backup OAuth authentication.
2252
+ *
2253
+ * Wrap your app with this provider to enable both Dropbox and Google Drive
2254
+ * authentication. It handles the OAuth 2.0 Authorization Code flow with
2255
+ * refresh tokens for both providers.
2256
+ *
2257
+ * @example
2258
+ * ```tsx
2259
+ * import { BackupAuthProvider } from "@reverbia/sdk/react";
2260
+ *
2261
+ * function App() {
2262
+ * return (
2263
+ * <BackupAuthProvider
2264
+ * dropboxAppKey={process.env.NEXT_PUBLIC_DROPBOX_APP_KEY}
2265
+ * dropboxCallbackPath="/auth/dropbox/callback"
2266
+ * googleClientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
2267
+ * googleCallbackPath="/auth/google/callback"
2268
+ * apiClient={apiClient}
2269
+ * >
2270
+ * <MyApp />
2271
+ * </BackupAuthProvider>
2272
+ * );
2273
+ * }
2274
+ * ```
2275
+ *
2276
+ * @category Components
2277
+ */
2278
+ declare function BackupAuthProvider({ dropboxAppKey, dropboxCallbackPath, googleClientId, googleCallbackPath, apiClient, children, }: BackupAuthProviderProps): JSX.Element;
2279
+ /**
2280
+ * Hook to access unified backup authentication state and methods.
2281
+ *
2282
+ * Must be used within a BackupAuthProvider.
2283
+ *
2284
+ * @example
2285
+ * ```tsx
2286
+ * import { useBackupAuth } from "@reverbia/sdk/react";
2287
+ *
2288
+ * function BackupSettings() {
2289
+ * const { dropbox, googleDrive, logoutAll } = useBackupAuth();
2290
+ *
2291
+ * return (
2292
+ * <div>
2293
+ * <h3>Backup Providers</h3>
2294
+ *
2295
+ * {dropbox.isConfigured && (
2296
+ * <div>
2297
+ * <span>Dropbox: {dropbox.isAuthenticated ? 'Connected' : 'Not connected'}</span>
2298
+ * {dropbox.isAuthenticated ? (
2299
+ * <button onClick={dropbox.logout}>Disconnect</button>
2300
+ * ) : (
2301
+ * <button onClick={dropbox.requestAccess}>Connect</button>
2302
+ * )}
2303
+ * </div>
2304
+ * )}
2305
+ *
2306
+ * {googleDrive.isConfigured && (
2307
+ * <div>
2308
+ * <span>Google Drive: {googleDrive.isAuthenticated ? 'Connected' : 'Not connected'}</span>
2309
+ * {googleDrive.isAuthenticated ? (
2310
+ * <button onClick={googleDrive.logout}>Disconnect</button>
2311
+ * ) : (
2312
+ * <button onClick={googleDrive.requestAccess}>Connect</button>
2313
+ * )}
2314
+ * </div>
2315
+ * )}
2316
+ *
2317
+ * <button onClick={logoutAll}>Disconnect All</button>
2318
+ * </div>
2319
+ * );
2320
+ * }
2321
+ * ```
2322
+ *
2323
+ * @category Hooks
2324
+ */
2325
+ declare function useBackupAuth(): BackupAuthContextValue;
2326
+
2327
+ /**
2328
+ * Options for useBackup hook
2329
+ */
2330
+ interface UseBackupOptions {
2331
+ /** WatermelonDB database instance */
2332
+ database: Database;
2333
+ /** Current user address (null if not signed in) */
2334
+ userAddress: string | null;
2335
+ /** Request encryption key for the user address */
2336
+ requestEncryptionKey: (address: string) => Promise<void>;
2337
+ /** Export a conversation to an encrypted blob */
2338
+ exportConversation: (conversationId: string, userAddress: string) => Promise<{
2339
+ success: boolean;
2340
+ blob?: Blob;
2341
+ }>;
2342
+ /** Import a conversation from an encrypted blob */
2343
+ importConversation: (blob: Blob, userAddress: string) => Promise<{
2344
+ success: boolean;
2345
+ }>;
2346
+ /** Dropbox folder path for backups (default: '/ai-chat-app/conversations') */
2347
+ dropboxFolder?: string;
2348
+ /** Google Drive root folder name (default: 'ai-chat-app') */
2349
+ googleRootFolder?: string;
2350
+ /** Google Drive conversations subfolder (default: 'conversations') */
2351
+ googleConversationsFolder?: string;
2352
+ }
2353
+ /**
2354
+ * Progress callback type
2355
+ */
2356
+ type ProgressCallback = (current: number, total: number) => void;
2357
+ /**
2358
+ * Backup options for individual operations
2359
+ */
2360
+ interface BackupOperationOptions {
2361
+ onProgress?: ProgressCallback;
2362
+ }
2363
+ /**
2364
+ * Provider-specific backup state
2365
+ */
2366
+ interface ProviderBackupState {
2367
+ /** Whether the provider is configured */
2368
+ isConfigured: boolean;
2369
+ /** Whether user has authenticated with this provider */
2370
+ isAuthenticated: boolean;
2371
+ /** Backup all conversations to this provider */
2372
+ backup: (options?: BackupOperationOptions) => Promise<DropboxExportResult | GoogleDriveExportResult | {
2373
+ error: string;
2374
+ }>;
2375
+ /** Restore conversations from this provider */
2376
+ restore: (options?: BackupOperationOptions) => Promise<DropboxImportResult | GoogleDriveImportResult | {
2377
+ error: string;
2378
+ }>;
2379
+ /** Request access to this provider (triggers OAuth if needed) */
2380
+ connect: () => Promise<string>;
2381
+ /** Disconnect from this provider */
2382
+ disconnect: () => Promise<void>;
2383
+ }
2384
+ /**
2385
+ * Result returned by useBackup hook
2386
+ */
2387
+ interface UseBackupResult {
2388
+ /** Dropbox backup state and methods */
2389
+ dropbox: ProviderBackupState;
2390
+ /** Google Drive backup state and methods */
2391
+ googleDrive: ProviderBackupState;
2392
+ /** Whether any backup provider is configured */
2393
+ hasAnyProvider: boolean;
2394
+ /** Whether any backup provider is authenticated */
2395
+ hasAnyAuthentication: boolean;
2396
+ /** Disconnect from all providers */
2397
+ disconnectAll: () => Promise<void>;
2398
+ }
2399
+ /**
2400
+ * Unified React hook for backup and restore functionality.
2401
+ *
2402
+ * This hook provides methods to backup conversations to both Dropbox and Google Drive,
2403
+ * and restore them. It handles all the logic for checking timestamps, skipping
2404
+ * unchanged files, authentication, and managing the backup/restore process.
2405
+ *
2406
+ * Must be used within a BackupAuthProvider.
2407
+ *
2408
+ * @example
2409
+ * ```tsx
2410
+ * import { useBackup } from "@reverbia/sdk/react";
2411
+ *
2412
+ * function BackupManager() {
2413
+ * const { dropbox, googleDrive, hasAnyProvider } = useBackup({
2414
+ * database,
2415
+ * userAddress,
2416
+ * requestEncryptionKey,
2417
+ * exportConversation,
2418
+ * importConversation,
2419
+ * });
2420
+ *
2421
+ * if (!hasAnyProvider) {
2422
+ * return <p>No backup providers configured</p>;
2423
+ * }
2424
+ *
2425
+ * return (
2426
+ * <div>
2427
+ * {dropbox.isConfigured && (
2428
+ * <div>
2429
+ * <h3>Dropbox</h3>
2430
+ * {dropbox.isAuthenticated ? (
2431
+ * <>
2432
+ * <button onClick={() => dropbox.backup()}>Backup</button>
2433
+ * <button onClick={() => dropbox.restore()}>Restore</button>
2434
+ * <button onClick={dropbox.disconnect}>Disconnect</button>
2435
+ * </>
2436
+ * ) : (
2437
+ * <button onClick={dropbox.connect}>Connect Dropbox</button>
2438
+ * )}
2439
+ * </div>
2440
+ * )}
2441
+ *
2442
+ * {googleDrive.isConfigured && (
2443
+ * <div>
2444
+ * <h3>Google Drive</h3>
2445
+ * {googleDrive.isAuthenticated ? (
2446
+ * <>
2447
+ * <button onClick={() => googleDrive.backup()}>Backup</button>
2448
+ * <button onClick={() => googleDrive.restore()}>Restore</button>
2449
+ * <button onClick={googleDrive.disconnect}>Disconnect</button>
2450
+ * </>
2451
+ * ) : (
2452
+ * <button onClick={googleDrive.connect}>Connect Google Drive</button>
2453
+ * )}
2454
+ * </div>
2455
+ * )}
2456
+ * </div>
2457
+ * );
2458
+ * }
2459
+ * ```
2460
+ *
2461
+ * @category Hooks
2462
+ */
2463
+ declare function useBackup(options: UseBackupOptions): UseBackupResult;
2464
+
2465
+ export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ClientTool, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_DROPBOX_FOLDER, DEFAULT_TOOL_SELECTOR_MODEL, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearToken as clearDropboxToken, clearGoogleDriveToken, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, memoryStorageSchema, requestEncryptionKey, sdkMigrations, sdkModelClasses, sdkSchema, selectTool, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };