@reverbia/sdk 1.0.0-next.20251217123222 → 1.0.0-next.20251217144159
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/expo/index.cjs +66 -3
- package/dist/expo/index.d.mts +17 -1
- package/dist/expo/index.d.ts +17 -1
- package/dist/expo/index.mjs +65 -3
- package/dist/react/index.cjs +1186 -53
- package/dist/react/index.d.mts +500 -2
- package/dist/react/index.d.ts +500 -2
- package/dist/react/index.mjs +1171 -45
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Database, Model } from '@nozbe/watermelondb';
|
|
2
|
+
import * as _nozbe_watermelondb_Schema_migrations from '@nozbe/watermelondb/Schema/migrations';
|
|
2
3
|
import * as _nozbe_watermelondb_Schema from '@nozbe/watermelondb/Schema';
|
|
3
4
|
import { Associations } from '@nozbe/watermelondb/Model';
|
|
5
|
+
import { ReactNode, JSX } from 'react';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* ExtraFields contains additional metadata
|
|
@@ -475,7 +477,7 @@ type SendMessageResult = {
|
|
|
475
477
|
error: null;
|
|
476
478
|
toolExecution?: ToolExecutionResult;
|
|
477
479
|
} | {
|
|
478
|
-
data: null;
|
|
480
|
+
data: LlmapiChatCompletionResponse | null;
|
|
479
481
|
error: string;
|
|
480
482
|
toolExecution?: ToolExecutionResult;
|
|
481
483
|
};
|
|
@@ -706,6 +708,8 @@ interface StoredMessage {
|
|
|
706
708
|
sources?: SearchSource[];
|
|
707
709
|
/** Response time in seconds */
|
|
708
710
|
responseDuration?: number;
|
|
711
|
+
/** Whether the message generation was stopped by the user */
|
|
712
|
+
wasStopped?: boolean;
|
|
709
713
|
}
|
|
710
714
|
/**
|
|
711
715
|
* Stored conversation record
|
|
@@ -755,6 +759,8 @@ interface CreateMessageOptions {
|
|
|
755
759
|
vector?: number[];
|
|
756
760
|
/** Model used to generate the embedding */
|
|
757
761
|
embeddingModel?: string;
|
|
762
|
+
/** Whether the message generation was stopped by the user */
|
|
763
|
+
wasStopped?: boolean;
|
|
758
764
|
}
|
|
759
765
|
/**
|
|
760
766
|
* Options for creating a new conversation
|
|
@@ -982,6 +988,15 @@ declare const chatStorageSchema: Readonly<{
|
|
|
982
988
|
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
983
989
|
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
984
990
|
}>;
|
|
991
|
+
/**
|
|
992
|
+
* Schema migrations
|
|
993
|
+
*/
|
|
994
|
+
declare const chatStorageMigrations: Readonly<{
|
|
995
|
+
validated: true;
|
|
996
|
+
minVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
997
|
+
maxVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
998
|
+
sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
|
|
999
|
+
}>;
|
|
985
1000
|
|
|
986
1001
|
/**
|
|
987
1002
|
* Message model representing a single chat message
|
|
@@ -1018,6 +1033,8 @@ declare class Message extends Model {
|
|
|
1018
1033
|
get sources(): SearchSource[] | undefined;
|
|
1019
1034
|
/** Response time in seconds */
|
|
1020
1035
|
get responseDuration(): number | undefined;
|
|
1036
|
+
/** Whether the message generation was stopped by the user */
|
|
1037
|
+
get wasStopped(): boolean;
|
|
1021
1038
|
}
|
|
1022
1039
|
/**
|
|
1023
1040
|
* Conversation model representing conversation metadata
|
|
@@ -1396,6 +1413,139 @@ declare class Memory extends Model {
|
|
|
1396
1413
|
get isDeleted(): boolean;
|
|
1397
1414
|
}
|
|
1398
1415
|
|
|
1416
|
+
/**
|
|
1417
|
+
* Stored model preference record (what gets persisted to the database)
|
|
1418
|
+
*/
|
|
1419
|
+
interface StoredModelPreference {
|
|
1420
|
+
/** Primary key (WatermelonDB auto-generated) */
|
|
1421
|
+
uniqueId: string;
|
|
1422
|
+
/** User's wallet address */
|
|
1423
|
+
walletAddress: string;
|
|
1424
|
+
/** Preferred model identifiers */
|
|
1425
|
+
models?: string;
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Options for creating a new model preference
|
|
1429
|
+
*/
|
|
1430
|
+
interface CreateModelPreferenceOptions {
|
|
1431
|
+
/** User's wallet address */
|
|
1432
|
+
walletAddress: string;
|
|
1433
|
+
/** Preferred model identifiers */
|
|
1434
|
+
models?: string;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Options for updating a model preference
|
|
1438
|
+
*/
|
|
1439
|
+
interface UpdateModelPreferenceOptions {
|
|
1440
|
+
/** New preferred model identifiers */
|
|
1441
|
+
models?: string;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Base options for useSettings hook
|
|
1445
|
+
*/
|
|
1446
|
+
interface BaseUseSettingsOptions {
|
|
1447
|
+
/** WatermelonDB database instance */
|
|
1448
|
+
database: Database;
|
|
1449
|
+
/** User's wallet address */
|
|
1450
|
+
walletAddress?: string;
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Base result returned by useSettings hook
|
|
1454
|
+
*/
|
|
1455
|
+
interface BaseUseSettingsResult {
|
|
1456
|
+
/** Current model preference */
|
|
1457
|
+
modelPreference: StoredModelPreference | null;
|
|
1458
|
+
/** Whether the settings are loading */
|
|
1459
|
+
isLoading: boolean;
|
|
1460
|
+
/** Get model preference by wallet address. Throws on error. */
|
|
1461
|
+
getModelPreference: (walletAddress: string) => Promise<StoredModelPreference | null>;
|
|
1462
|
+
/** Create or update model preference. Throws on error. */
|
|
1463
|
+
setModelPreference: (walletAddress: string, models?: string) => Promise<StoredModelPreference | null>;
|
|
1464
|
+
/** Delete model preference. Throws on error. */
|
|
1465
|
+
deleteModelPreference: (walletAddress: string) => Promise<boolean>;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* Options for useSettings hook (React version)
|
|
1470
|
+
*/
|
|
1471
|
+
interface UseSettingsOptions extends BaseUseSettingsOptions {
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Result returned by useSettings hook (React version)
|
|
1475
|
+
*/
|
|
1476
|
+
interface UseSettingsResult extends BaseUseSettingsResult {
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* A React hook for managing user settings with automatic persistence using WatermelonDB.
|
|
1480
|
+
*
|
|
1481
|
+
* This hook provides methods to get, set, and delete user model preferences,
|
|
1482
|
+
* with automatic loading of preferences when a wallet address is provided.
|
|
1483
|
+
*
|
|
1484
|
+
* @param options - Configuration options
|
|
1485
|
+
* @returns An object containing settings state and methods
|
|
1486
|
+
*
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```tsx
|
|
1489
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
1490
|
+
* import { useSettings } from '@reverbia/sdk/react';
|
|
1491
|
+
*
|
|
1492
|
+
* function SettingsComponent({ database }: { database: Database }) {
|
|
1493
|
+
* const {
|
|
1494
|
+
* modelPreference,
|
|
1495
|
+
* isLoading,
|
|
1496
|
+
* setModelPreference,
|
|
1497
|
+
* getModelPreference,
|
|
1498
|
+
* deleteModelPreference,
|
|
1499
|
+
* } = useSettings({
|
|
1500
|
+
* database,
|
|
1501
|
+
* walletAddress: '0x123...', // Optional: auto-loads preference for this wallet
|
|
1502
|
+
* });
|
|
1503
|
+
*
|
|
1504
|
+
* const handleModelChange = async (model: string) => {
|
|
1505
|
+
* await setModelPreference('0x123...', model);
|
|
1506
|
+
* };
|
|
1507
|
+
*
|
|
1508
|
+
* return (
|
|
1509
|
+
* <div>
|
|
1510
|
+
* <p>Current model: {modelPreference?.model ?? 'Not set'}</p>
|
|
1511
|
+
* <button onClick={() => handleModelChange('gpt-4o')}>
|
|
1512
|
+
* Use GPT-4o
|
|
1513
|
+
* </button>
|
|
1514
|
+
* </div>
|
|
1515
|
+
* );
|
|
1516
|
+
* }
|
|
1517
|
+
* ```
|
|
1518
|
+
*
|
|
1519
|
+
* @category Hooks
|
|
1520
|
+
*/
|
|
1521
|
+
declare function useSettings(options: UseSettingsOptions): UseSettingsResult;
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* WatermelonDB schema for settings storage
|
|
1525
|
+
*
|
|
1526
|
+
* * Defines one table::
|
|
1527
|
+
* - modelPreferences: Model preferences metadata
|
|
1528
|
+
*/
|
|
1529
|
+
declare const settingsStorageSchema: Readonly<{
|
|
1530
|
+
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1531
|
+
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
1532
|
+
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
1533
|
+
}>;
|
|
1534
|
+
|
|
1535
|
+
/**
|
|
1536
|
+
* ModelPreference model representing user model preferences
|
|
1537
|
+
*
|
|
1538
|
+
* Note: This model uses raw column accessors instead of decorators
|
|
1539
|
+
* for better TypeScript compatibility without requiring legacy decorators.
|
|
1540
|
+
*/
|
|
1541
|
+
declare class ModelPreference extends Model {
|
|
1542
|
+
static table: string;
|
|
1543
|
+
/** User's wallet address */
|
|
1544
|
+
get walletAddress(): string;
|
|
1545
|
+
/** Preferred model identifier */
|
|
1546
|
+
get models(): string | undefined;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1399
1549
|
interface PdfFile {
|
|
1400
1550
|
url: string;
|
|
1401
1551
|
mediaType?: string;
|
|
@@ -1608,4 +1758,352 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
1608
1758
|
error?: string;
|
|
1609
1759
|
}>;
|
|
1610
1760
|
|
|
1611
|
-
|
|
1761
|
+
/**
|
|
1762
|
+
* Dropbox API utilities
|
|
1763
|
+
*
|
|
1764
|
+
* Uses Dropbox HTTP API for file operations.
|
|
1765
|
+
* Dropbox uses OAuth 2.0 with PKCE for browser apps.
|
|
1766
|
+
*/
|
|
1767
|
+
/** Default folder path for Dropbox backups */
|
|
1768
|
+
declare const DEFAULT_BACKUP_FOLDER = "/ai-chat-app/conversations";
|
|
1769
|
+
|
|
1770
|
+
/**
|
|
1771
|
+
* Dropbox Backup Implementation
|
|
1772
|
+
*
|
|
1773
|
+
* Generic backup/restore functionality for Dropbox storage.
|
|
1774
|
+
* Works directly with WatermelonDB database.
|
|
1775
|
+
*/
|
|
1776
|
+
|
|
1777
|
+
interface DropboxExportResult {
|
|
1778
|
+
success: boolean;
|
|
1779
|
+
uploaded: number;
|
|
1780
|
+
skipped: number;
|
|
1781
|
+
total: number;
|
|
1782
|
+
}
|
|
1783
|
+
interface DropboxImportResult {
|
|
1784
|
+
success: boolean;
|
|
1785
|
+
restored: number;
|
|
1786
|
+
failed: number;
|
|
1787
|
+
total: number;
|
|
1788
|
+
/** True if no backups were found in Dropbox */
|
|
1789
|
+
noBackupsFound?: boolean;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Options for useDropboxBackup hook
|
|
1794
|
+
*/
|
|
1795
|
+
interface UseDropboxBackupOptions {
|
|
1796
|
+
/** WatermelonDB database instance */
|
|
1797
|
+
database: Database;
|
|
1798
|
+
/** Current user address (null if not signed in) */
|
|
1799
|
+
userAddress: string | null;
|
|
1800
|
+
/** Request encryption key for the user address */
|
|
1801
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
1802
|
+
/** Export a conversation to an encrypted blob */
|
|
1803
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
1804
|
+
success: boolean;
|
|
1805
|
+
blob?: Blob;
|
|
1806
|
+
}>;
|
|
1807
|
+
/** Import a conversation from an encrypted blob */
|
|
1808
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
1809
|
+
success: boolean;
|
|
1810
|
+
}>;
|
|
1811
|
+
/** Dropbox folder path for backups (default: '/ai-chat-app/conversations') */
|
|
1812
|
+
backupFolder?: string;
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Result returned by useDropboxBackup hook
|
|
1816
|
+
*/
|
|
1817
|
+
interface UseDropboxBackupResult {
|
|
1818
|
+
/** Backup all conversations to Dropbox */
|
|
1819
|
+
backup: (options?: {
|
|
1820
|
+
onProgress?: (current: number, total: number) => void;
|
|
1821
|
+
}) => Promise<DropboxExportResult | {
|
|
1822
|
+
error: string;
|
|
1823
|
+
}>;
|
|
1824
|
+
/** Restore conversations from Dropbox */
|
|
1825
|
+
restore: (options?: {
|
|
1826
|
+
onProgress?: (current: number, total: number) => void;
|
|
1827
|
+
}) => Promise<DropboxImportResult | {
|
|
1828
|
+
error: string;
|
|
1829
|
+
}>;
|
|
1830
|
+
/** Whether Dropbox is configured */
|
|
1831
|
+
isConfigured: boolean;
|
|
1832
|
+
/** Whether user has a Dropbox token */
|
|
1833
|
+
isAuthenticated: boolean;
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* React hook for Dropbox backup and restore functionality.
|
|
1837
|
+
*
|
|
1838
|
+
* This hook provides methods to backup conversations to Dropbox and restore them.
|
|
1839
|
+
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
1840
|
+
* authentication, and managing the backup/restore process.
|
|
1841
|
+
*
|
|
1842
|
+
* Must be used within a DropboxAuthProvider.
|
|
1843
|
+
*
|
|
1844
|
+
* @example
|
|
1845
|
+
* ```tsx
|
|
1846
|
+
* import { useDropboxBackup } from "@reverbia/sdk/react";
|
|
1847
|
+
*
|
|
1848
|
+
* function BackupButton() {
|
|
1849
|
+
* const { backup, restore, isConfigured } = useDropboxBackup({
|
|
1850
|
+
* database,
|
|
1851
|
+
* userAddress,
|
|
1852
|
+
* requestEncryptionKey,
|
|
1853
|
+
* exportConversation,
|
|
1854
|
+
* importConversation,
|
|
1855
|
+
* });
|
|
1856
|
+
*
|
|
1857
|
+
* const handleBackup = async () => {
|
|
1858
|
+
* const result = await backup({
|
|
1859
|
+
* onProgress: (current, total) => {
|
|
1860
|
+
* console.log(`Progress: ${current}/${total}`);
|
|
1861
|
+
* },
|
|
1862
|
+
* });
|
|
1863
|
+
*
|
|
1864
|
+
* if ("error" in result) {
|
|
1865
|
+
* console.error(result.error);
|
|
1866
|
+
* } else {
|
|
1867
|
+
* console.log(`Uploaded: ${result.uploaded}, Skipped: ${result.skipped}`);
|
|
1868
|
+
* }
|
|
1869
|
+
* };
|
|
1870
|
+
*
|
|
1871
|
+
* return <button onClick={handleBackup} disabled={!isConfigured}>Backup</button>;
|
|
1872
|
+
* }
|
|
1873
|
+
* ```
|
|
1874
|
+
*
|
|
1875
|
+
* @category Hooks
|
|
1876
|
+
*/
|
|
1877
|
+
declare function useDropboxBackup(options: UseDropboxBackupOptions): UseDropboxBackupResult;
|
|
1878
|
+
|
|
1879
|
+
/**
|
|
1880
|
+
* Dropbox OAuth 2.0 with PKCE
|
|
1881
|
+
*
|
|
1882
|
+
* Flow:
|
|
1883
|
+
* 1. Generate code_verifier and code_challenge
|
|
1884
|
+
* 2. Redirect user to Dropbox authorization URL
|
|
1885
|
+
* 3. User authorizes and is redirected back with authorization code
|
|
1886
|
+
* 4. Exchange code for access token using code_verifier
|
|
1887
|
+
*/
|
|
1888
|
+
/**
|
|
1889
|
+
* Get the stored access token from session storage
|
|
1890
|
+
*/
|
|
1891
|
+
declare function getStoredToken(): string | null;
|
|
1892
|
+
/**
|
|
1893
|
+
* Store access token in session storage
|
|
1894
|
+
*/
|
|
1895
|
+
declare function storeToken(token: string): void;
|
|
1896
|
+
/**
|
|
1897
|
+
* Clear stored access token
|
|
1898
|
+
*/
|
|
1899
|
+
declare function clearToken(): void;
|
|
1900
|
+
|
|
1901
|
+
/**
|
|
1902
|
+
* Props for DropboxAuthProvider
|
|
1903
|
+
*/
|
|
1904
|
+
interface DropboxAuthProviderProps {
|
|
1905
|
+
/** Dropbox App Key (from Dropbox Developer Console) */
|
|
1906
|
+
appKey: string | undefined;
|
|
1907
|
+
/** OAuth callback path (e.g., "/auth/dropbox/callback") */
|
|
1908
|
+
callbackPath?: string;
|
|
1909
|
+
/** Children to render */
|
|
1910
|
+
children: ReactNode;
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Context value for Dropbox authentication
|
|
1914
|
+
*/
|
|
1915
|
+
interface DropboxAuthContextValue {
|
|
1916
|
+
/** Current access token (null if not authenticated) */
|
|
1917
|
+
accessToken: string | null;
|
|
1918
|
+
/** Whether user has authenticated with Dropbox */
|
|
1919
|
+
isAuthenticated: boolean;
|
|
1920
|
+
/** Whether Dropbox is configured (app key exists) */
|
|
1921
|
+
isConfigured: boolean;
|
|
1922
|
+
/** Request Dropbox access - returns token or redirects to OAuth */
|
|
1923
|
+
requestAccess: () => Promise<string>;
|
|
1924
|
+
/** Clear stored token and log out */
|
|
1925
|
+
logout: () => void;
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Provider component for Dropbox OAuth authentication.
|
|
1929
|
+
*
|
|
1930
|
+
* Wrap your app with this provider to enable Dropbox authentication.
|
|
1931
|
+
* It handles the OAuth 2.0 PKCE flow automatically.
|
|
1932
|
+
*
|
|
1933
|
+
* @example
|
|
1934
|
+
* ```tsx
|
|
1935
|
+
* import { DropboxAuthProvider } from "@reverbia/sdk/react";
|
|
1936
|
+
*
|
|
1937
|
+
* function App() {
|
|
1938
|
+
* return (
|
|
1939
|
+
* <DropboxAuthProvider
|
|
1940
|
+
* appKey={process.env.NEXT_PUBLIC_DROPBOX_APP_KEY}
|
|
1941
|
+
* callbackPath="/auth/dropbox/callback"
|
|
1942
|
+
* >
|
|
1943
|
+
* <MyApp />
|
|
1944
|
+
* </DropboxAuthProvider>
|
|
1945
|
+
* );
|
|
1946
|
+
* }
|
|
1947
|
+
* ```
|
|
1948
|
+
*
|
|
1949
|
+
* @category Components
|
|
1950
|
+
*/
|
|
1951
|
+
declare function DropboxAuthProvider({ appKey, callbackPath, children, }: DropboxAuthProviderProps): JSX.Element;
|
|
1952
|
+
/**
|
|
1953
|
+
* Hook to access Dropbox authentication state and methods.
|
|
1954
|
+
*
|
|
1955
|
+
* Must be used within a DropboxAuthProvider.
|
|
1956
|
+
*
|
|
1957
|
+
* @example
|
|
1958
|
+
* ```tsx
|
|
1959
|
+
* import { useDropboxAuth } from "@reverbia/sdk/react";
|
|
1960
|
+
*
|
|
1961
|
+
* function DropboxButton() {
|
|
1962
|
+
* const { isAuthenticated, isConfigured, requestAccess, logout } = useDropboxAuth();
|
|
1963
|
+
*
|
|
1964
|
+
* if (!isConfigured) {
|
|
1965
|
+
* return <p>Dropbox not configured</p>;
|
|
1966
|
+
* }
|
|
1967
|
+
*
|
|
1968
|
+
* if (isAuthenticated) {
|
|
1969
|
+
* return <button onClick={logout}>Disconnect Dropbox</button>;
|
|
1970
|
+
* }
|
|
1971
|
+
*
|
|
1972
|
+
* return <button onClick={requestAccess}>Connect Dropbox</button>;
|
|
1973
|
+
* }
|
|
1974
|
+
* ```
|
|
1975
|
+
*
|
|
1976
|
+
* @category Hooks
|
|
1977
|
+
*/
|
|
1978
|
+
declare function useDropboxAuth(): DropboxAuthContextValue;
|
|
1979
|
+
|
|
1980
|
+
/**
|
|
1981
|
+
* Google Drive API utilities
|
|
1982
|
+
*
|
|
1983
|
+
* Uses Google Drive API v3 for file operations.
|
|
1984
|
+
* Requires an OAuth 2.0 access token with drive.file scope.
|
|
1985
|
+
*/
|
|
1986
|
+
/** Default root folder name for backups */
|
|
1987
|
+
declare const DEFAULT_ROOT_FOLDER = "ai-chat-app";
|
|
1988
|
+
/** Default subfolder for conversation backups */
|
|
1989
|
+
declare const DEFAULT_CONVERSATIONS_FOLDER = "conversations";
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* Google Drive Backup Implementation
|
|
1993
|
+
*
|
|
1994
|
+
* Generic backup/restore functionality for Google Drive storage.
|
|
1995
|
+
* Works directly with WatermelonDB database.
|
|
1996
|
+
*/
|
|
1997
|
+
|
|
1998
|
+
interface GoogleDriveExportResult {
|
|
1999
|
+
success: boolean;
|
|
2000
|
+
uploaded: number;
|
|
2001
|
+
skipped: number;
|
|
2002
|
+
total: number;
|
|
2003
|
+
}
|
|
2004
|
+
interface GoogleDriveImportResult {
|
|
2005
|
+
success: boolean;
|
|
2006
|
+
restored: number;
|
|
2007
|
+
failed: number;
|
|
2008
|
+
total: number;
|
|
2009
|
+
/** True if no backups were found in Google Drive */
|
|
2010
|
+
noBackupsFound?: boolean;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
/**
|
|
2014
|
+
* Options for useGoogleDriveBackup hook
|
|
2015
|
+
*/
|
|
2016
|
+
interface UseGoogleDriveBackupOptions {
|
|
2017
|
+
/** WatermelonDB database instance */
|
|
2018
|
+
database: Database;
|
|
2019
|
+
/** Current user address (null if not signed in) */
|
|
2020
|
+
userAddress: string | null;
|
|
2021
|
+
/** Current Google Drive access token (null if not authenticated) */
|
|
2022
|
+
accessToken: string | null;
|
|
2023
|
+
/** Request Google Drive access - returns access token */
|
|
2024
|
+
requestDriveAccess: () => Promise<string>;
|
|
2025
|
+
/** Request encryption key for the user address */
|
|
2026
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
2027
|
+
/** Export a conversation to an encrypted blob */
|
|
2028
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
2029
|
+
success: boolean;
|
|
2030
|
+
blob?: Blob;
|
|
2031
|
+
}>;
|
|
2032
|
+
/** Import a conversation from an encrypted blob */
|
|
2033
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
2034
|
+
success: boolean;
|
|
2035
|
+
}>;
|
|
2036
|
+
/** Root folder name in Google Drive (default: 'ai-chat-app') */
|
|
2037
|
+
rootFolder?: string;
|
|
2038
|
+
/** Subfolder for conversations (default: 'conversations') */
|
|
2039
|
+
conversationsFolder?: string;
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Result returned by useGoogleDriveBackup hook
|
|
2043
|
+
*/
|
|
2044
|
+
interface UseGoogleDriveBackupResult {
|
|
2045
|
+
/** Backup all conversations to Google Drive */
|
|
2046
|
+
backup: (options?: {
|
|
2047
|
+
onProgress?: (current: number, total: number) => void;
|
|
2048
|
+
}) => Promise<GoogleDriveExportResult | {
|
|
2049
|
+
error: string;
|
|
2050
|
+
}>;
|
|
2051
|
+
/** Restore conversations from Google Drive */
|
|
2052
|
+
restore: (options?: {
|
|
2053
|
+
onProgress?: (current: number, total: number) => void;
|
|
2054
|
+
}) => Promise<GoogleDriveImportResult | {
|
|
2055
|
+
error: string;
|
|
2056
|
+
}>;
|
|
2057
|
+
/** Whether user has a Google Drive token */
|
|
2058
|
+
isAuthenticated: boolean;
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* React hook for Google Drive backup and restore functionality.
|
|
2062
|
+
*
|
|
2063
|
+
* This hook provides methods to backup conversations to Google Drive and restore them.
|
|
2064
|
+
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
2065
|
+
* and managing the backup/restore process.
|
|
2066
|
+
*
|
|
2067
|
+
* Unlike Dropbox, Google Drive auth requires browser-specific setup (Google Identity Services),
|
|
2068
|
+
* so the auth provider must be implemented in the app. This hook accepts the auth
|
|
2069
|
+
* callbacks as options.
|
|
2070
|
+
*
|
|
2071
|
+
* @example
|
|
2072
|
+
* ```tsx
|
|
2073
|
+
* import { useGoogleDriveBackup } from "@reverbia/sdk/react";
|
|
2074
|
+
*
|
|
2075
|
+
* function BackupButton() {
|
|
2076
|
+
* const { accessToken, requestDriveAccess } = useGoogleAccessToken();
|
|
2077
|
+
* const { backup, restore, isAuthenticated } = useGoogleDriveBackup({
|
|
2078
|
+
* database,
|
|
2079
|
+
* userAddress,
|
|
2080
|
+
* accessToken,
|
|
2081
|
+
* requestDriveAccess,
|
|
2082
|
+
* requestEncryptionKey,
|
|
2083
|
+
* exportConversation,
|
|
2084
|
+
* importConversation,
|
|
2085
|
+
* });
|
|
2086
|
+
*
|
|
2087
|
+
* const handleBackup = async () => {
|
|
2088
|
+
* const result = await backup({
|
|
2089
|
+
* onProgress: (current, total) => {
|
|
2090
|
+
* console.log(`Progress: ${current}/${total}`);
|
|
2091
|
+
* },
|
|
2092
|
+
* });
|
|
2093
|
+
*
|
|
2094
|
+
* if ("error" in result) {
|
|
2095
|
+
* console.error(result.error);
|
|
2096
|
+
* } else {
|
|
2097
|
+
* console.log(`Uploaded: ${result.uploaded}, Skipped: ${result.skipped}`);
|
|
2098
|
+
* }
|
|
2099
|
+
* };
|
|
2100
|
+
*
|
|
2101
|
+
* return <button onClick={handleBackup}>Backup</button>;
|
|
2102
|
+
* }
|
|
2103
|
+
* ```
|
|
2104
|
+
*
|
|
2105
|
+
* @category Hooks
|
|
2106
|
+
*/
|
|
2107
|
+
declare function useGoogleDriveBackup(options: UseGoogleDriveBackupOptions): UseGoogleDriveBackupResult;
|
|
2108
|
+
|
|
2109
|
+
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, selectTool, settingsStorageSchema, storeToken as storeDropboxToken, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
|