@reverbia/sdk 1.0.0 → 1.1.0-next.20251230221037
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/README.md +290 -45
- package/dist/expo/index.cjs +3428 -0
- package/dist/expo/index.d.mts +1217 -0
- package/dist/expo/index.d.ts +1217 -0
- package/dist/expo/index.mjs +3395 -0
- package/dist/index.cjs +972 -0
- package/dist/index.d.mts +1514 -0
- package/dist/index.d.ts +1514 -0
- package/dist/index.mjs +934 -0
- package/dist/next/index.cjs +64 -0
- package/dist/next/index.d.mts +23 -0
- package/dist/next/index.d.ts +23 -0
- package/dist/next/index.mjs +39 -0
- package/dist/polyfills/index.cjs +61 -0
- package/dist/polyfills/index.d.mts +9 -0
- package/dist/polyfills/index.d.ts +9 -0
- package/dist/polyfills/index.mjs +34 -0
- package/dist/react/chunk-KUFGQF6E.mjs +290 -0
- package/dist/react/chunk-T56Y62G7.mjs +410 -0
- package/dist/react/index.cjs +7982 -0
- package/dist/react/index.d.mts +3139 -0
- package/dist/react/index.d.ts +3139 -0
- package/dist/react/index.mjs +7209 -0
- package/dist/react/storage-Z2NBANCK.mjs +29 -0
- package/dist/react/useEncryption-5RTXKDNZ.mjs +31 -0
- package/dist/vercel/index.cjs +86 -0
- package/dist/vercel/index.d.mts +119 -0
- package/dist/vercel/index.d.ts +119 -0
- package/dist/vercel/index.mjs +57 -0
- package/package.json +91 -16
- package/dist/cjs/client/client/client.gen.d.ts +0 -2
- package/dist/cjs/client/client/client.gen.js +0 -203
- package/dist/cjs/client/client/index.d.ts +0 -8
- package/dist/cjs/client/client/index.js +0 -16
- package/dist/cjs/client/client/types.gen.d.ts +0 -99
- package/dist/cjs/client/client/types.gen.js +0 -3
- package/dist/cjs/client/client/utils.gen.d.ts +0 -40
- package/dist/cjs/client/client/utils.gen.js +0 -314
- package/dist/cjs/client/client.gen.d.ts +0 -12
- package/dist/cjs/client/client.gen.js +0 -6
- package/dist/cjs/client/core/auth.gen.d.ts +0 -18
- package/dist/cjs/client/core/auth.gen.js +0 -18
- package/dist/cjs/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/cjs/client/core/bodySerializer.gen.js +0 -60
- package/dist/cjs/client/core/params.gen.d.ts +0 -43
- package/dist/cjs/client/core/params.gen.js +0 -104
- package/dist/cjs/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/cjs/client/core/pathSerializer.gen.js +0 -123
- package/dist/cjs/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/cjs/client/core/queryKeySerializer.gen.js +0 -105
- package/dist/cjs/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/cjs/client/core/serverSentEvents.gen.js +0 -139
- package/dist/cjs/client/core/types.gen.d.ts +0 -78
- package/dist/cjs/client/core/types.gen.js +0 -3
- package/dist/cjs/client/core/utils.gen.d.ts +0 -19
- package/dist/cjs/client/core/utils.gen.js +0 -93
- package/dist/cjs/client/index.d.ts +0 -2
- package/dist/cjs/client/index.js +0 -18
- package/dist/cjs/client/sdk.gen.d.ts +0 -27
- package/dist/cjs/client/sdk.gen.js +0 -33
- package/dist/cjs/client/types.gen.d.ts +0 -120
- package/dist/cjs/client/types.gen.js +0 -3
- package/dist/esm/client/client/client.gen.d.ts +0 -2
- package/dist/esm/client/client/client.gen.js +0 -199
- package/dist/esm/client/client/index.d.ts +0 -8
- package/dist/esm/client/client/index.js +0 -6
- package/dist/esm/client/client/types.gen.d.ts +0 -99
- package/dist/esm/client/client/types.gen.js +0 -2
- package/dist/esm/client/client/utils.gen.d.ts +0 -40
- package/dist/esm/client/client/utils.gen.js +0 -302
- package/dist/esm/client/client.gen.d.ts +0 -12
- package/dist/esm/client/client.gen.js +0 -3
- package/dist/esm/client/core/auth.gen.d.ts +0 -18
- package/dist/esm/client/core/auth.gen.js +0 -14
- package/dist/esm/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/esm/client/core/bodySerializer.gen.js +0 -57
- package/dist/esm/client/core/params.gen.d.ts +0 -43
- package/dist/esm/client/core/params.gen.js +0 -100
- package/dist/esm/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/esm/client/core/pathSerializer.gen.js +0 -114
- package/dist/esm/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/esm/client/core/queryKeySerializer.gen.js +0 -99
- package/dist/esm/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/esm/client/core/serverSentEvents.gen.js +0 -135
- package/dist/esm/client/core/types.gen.d.ts +0 -78
- package/dist/esm/client/core/types.gen.js +0 -2
- package/dist/esm/client/core/utils.gen.d.ts +0 -19
- package/dist/esm/client/core/utils.gen.js +0 -87
- package/dist/esm/client/index.d.ts +0 -2
- package/dist/esm/client/index.js +0 -2
- package/dist/esm/client/sdk.gen.d.ts +0 -27
- package/dist/esm/client/sdk.gen.js +0 -28
- package/dist/esm/client/types.gen.d.ts +0 -120
- package/dist/esm/client/types.gen.js +0 -2
- package/dist/types/client/client/client.gen.d.ts +0 -2
- package/dist/types/client/client/index.d.ts +0 -8
- package/dist/types/client/client/types.gen.d.ts +0 -99
- package/dist/types/client/client/utils.gen.d.ts +0 -40
- package/dist/types/client/client.gen.d.ts +0 -12
- package/dist/types/client/core/auth.gen.d.ts +0 -18
- package/dist/types/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/types/client/core/params.gen.d.ts +0 -43
- package/dist/types/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/types/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/types/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/types/client/core/types.gen.d.ts +0 -78
- package/dist/types/client/core/utils.gen.d.ts +0 -19
- package/dist/types/client/index.d.ts +0 -2
- package/dist/types/client/sdk.gen.d.ts +0 -27
- package/dist/types/client/types.gen.d.ts +0 -120
|
@@ -0,0 +1,3139 @@
|
|
|
1
|
+
import { Database, Model } from '@nozbe/watermelondb';
|
|
2
|
+
import * as _nozbe_watermelondb_Schema_migrations from '@nozbe/watermelondb/Schema/migrations';
|
|
3
|
+
import * as _nozbe_watermelondb_Schema from '@nozbe/watermelondb/Schema';
|
|
4
|
+
import Model$1, { Associations } from '@nozbe/watermelondb/Model';
|
|
5
|
+
import { Class } from '@nozbe/watermelondb/types';
|
|
6
|
+
import { ReactNode, JSX } from 'react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ExtraFields contains additional metadata such as provider/model information.
|
|
10
|
+
*/
|
|
11
|
+
type LlmapiImageGenerationExtraFields = {
|
|
12
|
+
/**
|
|
13
|
+
* ModelRequested is the model identifier that the client asked for.
|
|
14
|
+
*/
|
|
15
|
+
model_requested?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Provider is the gateway that serviced this request.
|
|
18
|
+
*/
|
|
19
|
+
provider?: string;
|
|
20
|
+
/**
|
|
21
|
+
* RequestType is always "image_generation".
|
|
22
|
+
*/
|
|
23
|
+
request_type?: string;
|
|
24
|
+
};
|
|
25
|
+
type LlmapiImageGenerationImage = {
|
|
26
|
+
/**
|
|
27
|
+
* B64JSON is the base64 payload for models that can only return binary.
|
|
28
|
+
*/
|
|
29
|
+
b64_json?: string;
|
|
30
|
+
/**
|
|
31
|
+
* URL is the signed URL to download the image.
|
|
32
|
+
*/
|
|
33
|
+
url?: string;
|
|
34
|
+
};
|
|
35
|
+
type LlmapiImageGenerationRequest = {
|
|
36
|
+
/**
|
|
37
|
+
* Model is the model identifier to use for generation (e.g., "gpt-image-1").
|
|
38
|
+
*/
|
|
39
|
+
model: string;
|
|
40
|
+
/**
|
|
41
|
+
* Prompt is the text description of the desired image.
|
|
42
|
+
*/
|
|
43
|
+
prompt: string;
|
|
44
|
+
/**
|
|
45
|
+
* Quality targets a quality preset (e.g., "auto", "high").
|
|
46
|
+
*/
|
|
47
|
+
quality?: string;
|
|
48
|
+
/**
|
|
49
|
+
* ResponseFormat controls how the generated image is returned (e.g., "url" or "b64_json").
|
|
50
|
+
*/
|
|
51
|
+
response_format?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Size controls the dimensions of the generated image (e.g., "1024x1024").
|
|
54
|
+
*/
|
|
55
|
+
size?: string;
|
|
56
|
+
};
|
|
57
|
+
type LlmapiImageGenerationResponse = {
|
|
58
|
+
/**
|
|
59
|
+
* Created is the Unix timestamp when the image was generated.
|
|
60
|
+
*/
|
|
61
|
+
created?: number;
|
|
62
|
+
extra_fields?: LlmapiImageGenerationExtraFields;
|
|
63
|
+
/**
|
|
64
|
+
* Images contains the generated images.
|
|
65
|
+
*/
|
|
66
|
+
images?: Array<LlmapiImageGenerationImage>;
|
|
67
|
+
/**
|
|
68
|
+
* Model is the model identifier that generated the image.
|
|
69
|
+
*/
|
|
70
|
+
model?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Provider is the gateway that produced the image.
|
|
73
|
+
*/
|
|
74
|
+
provider?: string;
|
|
75
|
+
usage?: LlmapiImageGenerationUsage;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Usage documents token usage (when available).
|
|
79
|
+
*/
|
|
80
|
+
type LlmapiImageGenerationUsage = {
|
|
81
|
+
/**
|
|
82
|
+
* CostMicroUSD is the inference cost for this image generation request
|
|
83
|
+
*/
|
|
84
|
+
cost_micro_usd?: number;
|
|
85
|
+
/**
|
|
86
|
+
* InputTokens is the number of tokens sent in the prompt.
|
|
87
|
+
*/
|
|
88
|
+
input_tokens?: number;
|
|
89
|
+
/**
|
|
90
|
+
* OutputTokens is the number of tokens returned by the model.
|
|
91
|
+
*/
|
|
92
|
+
output_tokens?: number;
|
|
93
|
+
/**
|
|
94
|
+
* TotalTokens is the total number of tokens consumed.
|
|
95
|
+
*/
|
|
96
|
+
total_tokens?: number;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Message is the generated message
|
|
100
|
+
*/
|
|
101
|
+
type LlmapiMessage = {
|
|
102
|
+
/**
|
|
103
|
+
* Content is the message content
|
|
104
|
+
*/
|
|
105
|
+
content?: Array<LlmapiMessageContentPart>;
|
|
106
|
+
role?: LlmapiRole;
|
|
107
|
+
/**
|
|
108
|
+
* ToolCalls contains tool/function calls made by the assistant (only for assistant role)
|
|
109
|
+
*/
|
|
110
|
+
tool_calls?: Array<LlmapiToolCall>;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* ImageURL is used when Type=image_url
|
|
114
|
+
*/
|
|
115
|
+
type LlmapiMessageContentImage = {
|
|
116
|
+
/**
|
|
117
|
+
* Detail is the OpenAI detail hint (auto|low|high)
|
|
118
|
+
*/
|
|
119
|
+
detail?: string;
|
|
120
|
+
/**
|
|
121
|
+
* URL is the image URL or data URI
|
|
122
|
+
*/
|
|
123
|
+
url?: string;
|
|
124
|
+
};
|
|
125
|
+
type LlmapiMessageContentPart = {
|
|
126
|
+
image_url?: LlmapiMessageContentImage;
|
|
127
|
+
/**
|
|
128
|
+
* Text holds the text content when Type=text
|
|
129
|
+
*/
|
|
130
|
+
text?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Type is the block type (`text` or `image_url`)
|
|
133
|
+
*/
|
|
134
|
+
type?: string;
|
|
135
|
+
};
|
|
136
|
+
type LlmapiModel = {
|
|
137
|
+
architecture?: LlmapiModelArchitecture;
|
|
138
|
+
/**
|
|
139
|
+
* CanonicalSlug is the canonical slug for the model
|
|
140
|
+
*/
|
|
141
|
+
canonical_slug?: string;
|
|
142
|
+
/**
|
|
143
|
+
* ContextLength is the maximum context length in tokens
|
|
144
|
+
*/
|
|
145
|
+
context_length?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Created is the Unix timestamp of when the model was created
|
|
148
|
+
*/
|
|
149
|
+
created?: number;
|
|
150
|
+
/**
|
|
151
|
+
* DefaultParameters contains default parameter values
|
|
152
|
+
*/
|
|
153
|
+
default_parameters?: {
|
|
154
|
+
[key: string]: unknown;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Description describes the model and its capabilities
|
|
158
|
+
*/
|
|
159
|
+
description?: string;
|
|
160
|
+
/**
|
|
161
|
+
* HuggingFaceID is the Hugging Face model identifier
|
|
162
|
+
*/
|
|
163
|
+
hugging_face_id?: string;
|
|
164
|
+
/**
|
|
165
|
+
* ID is the model identifier (e.g., "openai/gpt-4")
|
|
166
|
+
*/
|
|
167
|
+
id?: string;
|
|
168
|
+
/**
|
|
169
|
+
* MaxInputTokens is the maximum input tokens
|
|
170
|
+
*/
|
|
171
|
+
max_input_tokens?: number;
|
|
172
|
+
/**
|
|
173
|
+
* MaxOutputTokens is the maximum output tokens
|
|
174
|
+
*/
|
|
175
|
+
max_output_tokens?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Modalities is a list of supported modalities (e.g., ["llm", "vision"])
|
|
178
|
+
*/
|
|
179
|
+
modalities?: Array<string>;
|
|
180
|
+
/**
|
|
181
|
+
* Name is the human-readable model name (optional)
|
|
182
|
+
*/
|
|
183
|
+
name?: string;
|
|
184
|
+
/**
|
|
185
|
+
* OwnedBy is the organization that owns the model
|
|
186
|
+
*/
|
|
187
|
+
owned_by?: string;
|
|
188
|
+
per_request_limits?: LlmapiModelPerRequestLimits;
|
|
189
|
+
pricing?: LlmapiModelPricing;
|
|
190
|
+
/**
|
|
191
|
+
* SupportedMethods is a list of supported API methods
|
|
192
|
+
*/
|
|
193
|
+
supported_methods?: Array<string>;
|
|
194
|
+
/**
|
|
195
|
+
* SupportedParameters is a list of supported parameter names
|
|
196
|
+
*/
|
|
197
|
+
supported_parameters?: Array<string>;
|
|
198
|
+
top_provider?: LlmapiModelTopProvider;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Architecture describes the model's technical capabilities
|
|
202
|
+
*/
|
|
203
|
+
type LlmapiModelArchitecture = {
|
|
204
|
+
instruct_type?: string;
|
|
205
|
+
modality?: string;
|
|
206
|
+
prompt_formatting?: string;
|
|
207
|
+
tokenizer?: string;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* PerRequestLimits contains rate limiting information
|
|
211
|
+
*/
|
|
212
|
+
type LlmapiModelPerRequestLimits = {
|
|
213
|
+
completion_tokens?: number;
|
|
214
|
+
prompt_tokens?: number;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Pricing contains the pricing structure for using this model
|
|
218
|
+
*/
|
|
219
|
+
type LlmapiModelPricing = {
|
|
220
|
+
completion?: string;
|
|
221
|
+
image?: string;
|
|
222
|
+
prompt?: string;
|
|
223
|
+
request?: string;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* TopProvider contains configuration details for the primary provider
|
|
227
|
+
*/
|
|
228
|
+
type LlmapiModelTopProvider = {
|
|
229
|
+
context_length?: number;
|
|
230
|
+
is_moderated?: boolean;
|
|
231
|
+
max_completion_tokens?: number;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* ExtraFields contains additional metadata
|
|
235
|
+
*/
|
|
236
|
+
type LlmapiResponseExtraFields = {
|
|
237
|
+
/**
|
|
238
|
+
* Latency is the request latency in milliseconds
|
|
239
|
+
*/
|
|
240
|
+
latency?: number;
|
|
241
|
+
/**
|
|
242
|
+
* ModelRequested is the model that was requested
|
|
243
|
+
*/
|
|
244
|
+
model_requested?: string;
|
|
245
|
+
/**
|
|
246
|
+
* Provider is the LLM provider used (e.g., "openai", "anthropic")
|
|
247
|
+
*/
|
|
248
|
+
provider?: string;
|
|
249
|
+
/**
|
|
250
|
+
* RequestType is always "responses"
|
|
251
|
+
*/
|
|
252
|
+
request_type?: string;
|
|
253
|
+
};
|
|
254
|
+
type LlmapiResponseOutputContent = {
|
|
255
|
+
/**
|
|
256
|
+
* Text is the text content
|
|
257
|
+
*/
|
|
258
|
+
text?: string;
|
|
259
|
+
/**
|
|
260
|
+
* Type is the content type (e.g., "output_text")
|
|
261
|
+
*/
|
|
262
|
+
type?: string;
|
|
263
|
+
};
|
|
264
|
+
type LlmapiResponseOutputItem = {
|
|
265
|
+
/**
|
|
266
|
+
* Arguments is the function arguments for function_call types
|
|
267
|
+
*/
|
|
268
|
+
arguments?: string;
|
|
269
|
+
/**
|
|
270
|
+
* CallID is the call ID for function_call types
|
|
271
|
+
*/
|
|
272
|
+
call_id?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Content is the content array for message and reasoning types
|
|
275
|
+
*/
|
|
276
|
+
content?: Array<LlmapiResponseOutputContent>;
|
|
277
|
+
/**
|
|
278
|
+
* ID is the unique identifier for this output item
|
|
279
|
+
*/
|
|
280
|
+
id?: string;
|
|
281
|
+
/**
|
|
282
|
+
* Name is the function name for function_call types
|
|
283
|
+
*/
|
|
284
|
+
name?: string;
|
|
285
|
+
/**
|
|
286
|
+
* Role is the role for message types (e.g., "assistant")
|
|
287
|
+
*/
|
|
288
|
+
role?: string;
|
|
289
|
+
/**
|
|
290
|
+
* Status is the status of this output item (e.g., "completed")
|
|
291
|
+
*/
|
|
292
|
+
status?: string;
|
|
293
|
+
/**
|
|
294
|
+
* Summary is the reasoning summary for reasoning types
|
|
295
|
+
*/
|
|
296
|
+
summary?: Array<LlmapiResponseOutputContent>;
|
|
297
|
+
/**
|
|
298
|
+
* Type is the output item type (e.g., "message", "function_call", "reasoning")
|
|
299
|
+
*/
|
|
300
|
+
type?: string;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Reasoning configures reasoning for o-series and other reasoning models
|
|
304
|
+
*/
|
|
305
|
+
type LlmapiResponseReasoning = {
|
|
306
|
+
/**
|
|
307
|
+
* Effort controls reasoning effort: "low", "medium", or "high"
|
|
308
|
+
*/
|
|
309
|
+
effort?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Summary controls reasoning summary: "auto", "concise", or "detailed"
|
|
312
|
+
*/
|
|
313
|
+
summary?: string;
|
|
314
|
+
};
|
|
315
|
+
type LlmapiResponseResponse = {
|
|
316
|
+
/**
|
|
317
|
+
* Created is the Unix timestamp of creation (created_at in OpenAI format)
|
|
318
|
+
*/
|
|
319
|
+
created_at?: number;
|
|
320
|
+
extra_fields?: LlmapiResponseExtraFields;
|
|
321
|
+
/**
|
|
322
|
+
* ID is the unique response identifier
|
|
323
|
+
*/
|
|
324
|
+
id?: string;
|
|
325
|
+
/**
|
|
326
|
+
* Model is the model used for generation
|
|
327
|
+
*/
|
|
328
|
+
model?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Object is the response type (e.g., "response")
|
|
331
|
+
*/
|
|
332
|
+
object?: string;
|
|
333
|
+
/**
|
|
334
|
+
* Output is the array of output items (OpenAI Responses API format)
|
|
335
|
+
*/
|
|
336
|
+
output?: Array<LlmapiResponseOutputItem>;
|
|
337
|
+
usage?: LlmapiResponseUsage;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Usage contains token usage information
|
|
341
|
+
*/
|
|
342
|
+
type LlmapiResponseUsage = {
|
|
343
|
+
/**
|
|
344
|
+
* CompletionTokens is the number of tokens in the completion
|
|
345
|
+
*/
|
|
346
|
+
completion_tokens?: number;
|
|
347
|
+
/**
|
|
348
|
+
* CostMicroUSD is the cost of this response in micro-dollars (USD × 1,000,000)
|
|
349
|
+
*/
|
|
350
|
+
cost_micro_usd?: number;
|
|
351
|
+
/**
|
|
352
|
+
* PromptTokens is the number of tokens in the prompt
|
|
353
|
+
*/
|
|
354
|
+
prompt_tokens?: number;
|
|
355
|
+
/**
|
|
356
|
+
* TotalTokens is the total number of tokens used
|
|
357
|
+
*/
|
|
358
|
+
total_tokens?: number;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Role is the message role (system, user, assistant)
|
|
362
|
+
*/
|
|
363
|
+
type LlmapiRole = string;
|
|
364
|
+
/**
|
|
365
|
+
* ExtraFields contains additional metadata.
|
|
366
|
+
*/
|
|
367
|
+
type LlmapiSearchExtraFields = {
|
|
368
|
+
/**
|
|
369
|
+
* RequestType is always "search".
|
|
370
|
+
*/
|
|
371
|
+
request_type?: string;
|
|
372
|
+
/**
|
|
373
|
+
* SearchProvider is the search provider used (e.g., "perplexity", "google-pse").
|
|
374
|
+
*/
|
|
375
|
+
search_provider?: string;
|
|
376
|
+
};
|
|
377
|
+
type LlmapiSearchResponse = {
|
|
378
|
+
extra_fields?: LlmapiSearchExtraFields;
|
|
379
|
+
/**
|
|
380
|
+
* List of search results.
|
|
381
|
+
*/
|
|
382
|
+
results?: Array<LlmapiSearchResult>;
|
|
383
|
+
usage?: LlmapiSearchUsage;
|
|
384
|
+
};
|
|
385
|
+
type LlmapiSearchResult = {
|
|
386
|
+
/**
|
|
387
|
+
* Optional publication or last updated date.
|
|
388
|
+
*/
|
|
389
|
+
date?: string;
|
|
390
|
+
/**
|
|
391
|
+
* Text snippet from the result.
|
|
392
|
+
*/
|
|
393
|
+
snippet?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Title of the search result.
|
|
396
|
+
*/
|
|
397
|
+
title?: string;
|
|
398
|
+
/**
|
|
399
|
+
* URL of the search result.
|
|
400
|
+
*/
|
|
401
|
+
url?: string;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Usage contains usage information.
|
|
405
|
+
*/
|
|
406
|
+
type LlmapiSearchUsage = {
|
|
407
|
+
/**
|
|
408
|
+
* CostMicroUSD is the cost of this search in micro-dollars (USD × 1,000,000).
|
|
409
|
+
*/
|
|
410
|
+
cost_micro_usd?: number;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Thinking configures extended thinking for Anthropic models
|
|
414
|
+
*/
|
|
415
|
+
type LlmapiThinkingOptions = {
|
|
416
|
+
/**
|
|
417
|
+
* BudgetTokens is the token budget for thinking
|
|
418
|
+
*/
|
|
419
|
+
budget_tokens?: number;
|
|
420
|
+
/**
|
|
421
|
+
* Type indicates if thinking is enabled: "enabled" or "disabled"
|
|
422
|
+
*/
|
|
423
|
+
type?: string;
|
|
424
|
+
};
|
|
425
|
+
type LlmapiTool = {
|
|
426
|
+
function?: LlmapiToolFunction;
|
|
427
|
+
/**
|
|
428
|
+
* Type is the tool type (function, code_interpreter, file_search, web_search)
|
|
429
|
+
*/
|
|
430
|
+
type?: string;
|
|
431
|
+
};
|
|
432
|
+
type LlmapiToolCall = {
|
|
433
|
+
function?: LlmapiToolCallFunction;
|
|
434
|
+
/**
|
|
435
|
+
* ID is the unique identifier for this tool call
|
|
436
|
+
*/
|
|
437
|
+
id?: string;
|
|
438
|
+
/**
|
|
439
|
+
* Type is the type of tool call (always "function" for now)
|
|
440
|
+
*/
|
|
441
|
+
type?: string;
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Function contains the function call details
|
|
445
|
+
*/
|
|
446
|
+
type LlmapiToolCallFunction = {
|
|
447
|
+
/**
|
|
448
|
+
* Arguments is the JSON string of arguments to pass to the function
|
|
449
|
+
*/
|
|
450
|
+
arguments?: string;
|
|
451
|
+
/**
|
|
452
|
+
* Name is the name of the function to call
|
|
453
|
+
*/
|
|
454
|
+
name?: string;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Function is the function definition (when Type is "function")
|
|
458
|
+
*/
|
|
459
|
+
type LlmapiToolFunction = {
|
|
460
|
+
/**
|
|
461
|
+
* Arguments is the function arguments schema (JSON object)
|
|
462
|
+
*/
|
|
463
|
+
arguments?: {
|
|
464
|
+
[key: string]: unknown;
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Name is the function name
|
|
468
|
+
*/
|
|
469
|
+
name?: string;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
type AuthToken = string | undefined;
|
|
473
|
+
interface Auth {
|
|
474
|
+
/**
|
|
475
|
+
* Which part of the request do we use to send the auth?
|
|
476
|
+
*
|
|
477
|
+
* @default 'header'
|
|
478
|
+
*/
|
|
479
|
+
in?: 'header' | 'query' | 'cookie';
|
|
480
|
+
/**
|
|
481
|
+
* Header or query parameter name.
|
|
482
|
+
*
|
|
483
|
+
* @default 'Authorization'
|
|
484
|
+
*/
|
|
485
|
+
name?: string;
|
|
486
|
+
scheme?: 'basic' | 'bearer';
|
|
487
|
+
type: 'apiKey' | 'http';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
interface SerializerOptions<T> {
|
|
491
|
+
/**
|
|
492
|
+
* @default true
|
|
493
|
+
*/
|
|
494
|
+
explode: boolean;
|
|
495
|
+
style: T;
|
|
496
|
+
}
|
|
497
|
+
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
498
|
+
type ObjectStyle = 'form' | 'deepObject';
|
|
499
|
+
|
|
500
|
+
type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
501
|
+
type BodySerializer = (body: any) => any;
|
|
502
|
+
type QuerySerializerOptionsObject = {
|
|
503
|
+
allowReserved?: boolean;
|
|
504
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
505
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
506
|
+
};
|
|
507
|
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
508
|
+
/**
|
|
509
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
510
|
+
* override the global array/object settings for specific parameter names.
|
|
511
|
+
*/
|
|
512
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
516
|
+
type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
517
|
+
/**
|
|
518
|
+
* Returns the final request URL.
|
|
519
|
+
*/
|
|
520
|
+
buildUrl: BuildUrlFn;
|
|
521
|
+
getConfig: () => Config;
|
|
522
|
+
request: RequestFn;
|
|
523
|
+
setConfig: (config: Config) => Config;
|
|
524
|
+
} & {
|
|
525
|
+
[K in HttpMethod]: MethodFn;
|
|
526
|
+
} & ([SseFn] extends [never] ? {
|
|
527
|
+
sse?: never;
|
|
528
|
+
} : {
|
|
529
|
+
sse: {
|
|
530
|
+
[K in HttpMethod]: SseFn;
|
|
531
|
+
};
|
|
532
|
+
});
|
|
533
|
+
interface Config$1 {
|
|
534
|
+
/**
|
|
535
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
536
|
+
* added to the request payload as defined by its `security` array.
|
|
537
|
+
*/
|
|
538
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
539
|
+
/**
|
|
540
|
+
* A function for serializing request body parameter. By default,
|
|
541
|
+
* {@link JSON.stringify()} will be used.
|
|
542
|
+
*/
|
|
543
|
+
bodySerializer?: BodySerializer | null;
|
|
544
|
+
/**
|
|
545
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
546
|
+
* `Headers` object with.
|
|
547
|
+
*
|
|
548
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
549
|
+
*/
|
|
550
|
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
551
|
+
/**
|
|
552
|
+
* The request method.
|
|
553
|
+
*
|
|
554
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
555
|
+
*/
|
|
556
|
+
method?: Uppercase<HttpMethod>;
|
|
557
|
+
/**
|
|
558
|
+
* A function for serializing request query parameters. By default, arrays
|
|
559
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
560
|
+
* style, and reserved characters are percent-encoded.
|
|
561
|
+
*
|
|
562
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
563
|
+
* API function is used.
|
|
564
|
+
*
|
|
565
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
566
|
+
*/
|
|
567
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
568
|
+
/**
|
|
569
|
+
* A function validating request data. This is useful if you want to ensure
|
|
570
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
571
|
+
* the server.
|
|
572
|
+
*/
|
|
573
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
574
|
+
/**
|
|
575
|
+
* A function transforming response data before it's returned. This is useful
|
|
576
|
+
* for post-processing data, e.g. converting ISO strings into Date objects.
|
|
577
|
+
*/
|
|
578
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
579
|
+
/**
|
|
580
|
+
* A function validating response data. This is useful if you want to ensure
|
|
581
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
582
|
+
* the transformers and returned to the user.
|
|
583
|
+
*/
|
|
584
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
588
|
+
/**
|
|
589
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
590
|
+
* fetch instance.
|
|
591
|
+
*
|
|
592
|
+
* @default globalThis.fetch
|
|
593
|
+
*/
|
|
594
|
+
fetch?: typeof fetch;
|
|
595
|
+
/**
|
|
596
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
597
|
+
*/
|
|
598
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
599
|
+
/**
|
|
600
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
601
|
+
*
|
|
602
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
603
|
+
*
|
|
604
|
+
* @param error The error that occurred.
|
|
605
|
+
*/
|
|
606
|
+
onSseError?: (error: unknown) => void;
|
|
607
|
+
/**
|
|
608
|
+
* Callback invoked when an event is streamed from the server.
|
|
609
|
+
*
|
|
610
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
611
|
+
*
|
|
612
|
+
* @param event Event streamed from the server.
|
|
613
|
+
* @returns Nothing (void).
|
|
614
|
+
*/
|
|
615
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
616
|
+
serializedBody?: RequestInit['body'];
|
|
617
|
+
/**
|
|
618
|
+
* Default retry delay in milliseconds.
|
|
619
|
+
*
|
|
620
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
621
|
+
*
|
|
622
|
+
* @default 3000
|
|
623
|
+
*/
|
|
624
|
+
sseDefaultRetryDelay?: number;
|
|
625
|
+
/**
|
|
626
|
+
* Maximum number of retry attempts before giving up.
|
|
627
|
+
*/
|
|
628
|
+
sseMaxRetryAttempts?: number;
|
|
629
|
+
/**
|
|
630
|
+
* Maximum retry delay in milliseconds.
|
|
631
|
+
*
|
|
632
|
+
* Applies only when exponential backoff is used.
|
|
633
|
+
*
|
|
634
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
635
|
+
*
|
|
636
|
+
* @default 30000
|
|
637
|
+
*/
|
|
638
|
+
sseMaxRetryDelay?: number;
|
|
639
|
+
/**
|
|
640
|
+
* Optional sleep function for retry backoff.
|
|
641
|
+
*
|
|
642
|
+
* Defaults to using `setTimeout`.
|
|
643
|
+
*/
|
|
644
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
645
|
+
url: string;
|
|
646
|
+
};
|
|
647
|
+
interface StreamEvent<TData = unknown> {
|
|
648
|
+
data: TData;
|
|
649
|
+
event?: string;
|
|
650
|
+
id?: string;
|
|
651
|
+
retry?: number;
|
|
652
|
+
}
|
|
653
|
+
type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
654
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
type ErrInterceptor<Err, Res, Options> = (error: Err, response: Res, options: Options) => Err | Promise<Err>;
|
|
658
|
+
type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
|
|
659
|
+
type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
|
|
660
|
+
declare class Interceptors<Interceptor> {
|
|
661
|
+
fns: Array<Interceptor | null>;
|
|
662
|
+
clear(): void;
|
|
663
|
+
eject(id: number | Interceptor): void;
|
|
664
|
+
exists(id: number | Interceptor): boolean;
|
|
665
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
666
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
667
|
+
use(fn: Interceptor): number;
|
|
668
|
+
}
|
|
669
|
+
interface Middleware<Res, Err, Options> {
|
|
670
|
+
error: Interceptors<ErrInterceptor<Err, Res, Options>>;
|
|
671
|
+
request: Interceptors<ReqInterceptor<Options>>;
|
|
672
|
+
response: Interceptors<ResInterceptor<Res, Options>>;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
|
|
676
|
+
/**
|
|
677
|
+
* Base URL for all requests made by this client.
|
|
678
|
+
*/
|
|
679
|
+
baseUrl?: T['baseUrl'];
|
|
680
|
+
/**
|
|
681
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
682
|
+
* fetch instance.
|
|
683
|
+
*
|
|
684
|
+
* @default globalThis.fetch
|
|
685
|
+
*/
|
|
686
|
+
fetch?: typeof fetch;
|
|
687
|
+
/**
|
|
688
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
689
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
690
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
691
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
692
|
+
*
|
|
693
|
+
* @default 'auto'
|
|
694
|
+
*/
|
|
695
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
696
|
+
/**
|
|
697
|
+
* Throw an error instead of returning it in the response?
|
|
698
|
+
*
|
|
699
|
+
* @default false
|
|
700
|
+
*/
|
|
701
|
+
throwOnError?: T['throwOnError'];
|
|
702
|
+
}
|
|
703
|
+
interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
704
|
+
throwOnError: ThrowOnError;
|
|
705
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
706
|
+
/**
|
|
707
|
+
* Any body that you want to add to your request.
|
|
708
|
+
*
|
|
709
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
710
|
+
*/
|
|
711
|
+
body?: unknown;
|
|
712
|
+
path?: Record<string, unknown>;
|
|
713
|
+
query?: Record<string, unknown>;
|
|
714
|
+
/**
|
|
715
|
+
* Security mechanism(s) to use for the request.
|
|
716
|
+
*/
|
|
717
|
+
security?: ReadonlyArray<Auth>;
|
|
718
|
+
url: Url;
|
|
719
|
+
}
|
|
720
|
+
interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
|
|
721
|
+
serializedBody?: string;
|
|
722
|
+
}
|
|
723
|
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
|
|
724
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
725
|
+
response: Response;
|
|
726
|
+
}> : Promise<({
|
|
727
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
728
|
+
error: undefined;
|
|
729
|
+
} | {
|
|
730
|
+
data: undefined;
|
|
731
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
732
|
+
}) & {
|
|
733
|
+
response: Response;
|
|
734
|
+
}>;
|
|
735
|
+
interface ClientOptions {
|
|
736
|
+
baseUrl?: string;
|
|
737
|
+
throwOnError?: boolean;
|
|
738
|
+
}
|
|
739
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
740
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
741
|
+
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>;
|
|
742
|
+
type BuildUrlFn = <TData extends {
|
|
743
|
+
body?: unknown;
|
|
744
|
+
path?: Record<string, unknown>;
|
|
745
|
+
query?: Record<string, unknown>;
|
|
746
|
+
url: string;
|
|
747
|
+
}>(options: TData & Options<TData>) => string;
|
|
748
|
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
749
|
+
interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
|
|
750
|
+
};
|
|
751
|
+
interface TDataShape {
|
|
752
|
+
body?: unknown;
|
|
753
|
+
headers?: unknown;
|
|
754
|
+
path?: unknown;
|
|
755
|
+
query?: unknown;
|
|
756
|
+
url: string;
|
|
757
|
+
}
|
|
758
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
759
|
+
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'>);
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Responses API options that can be passed to sendMessage
|
|
763
|
+
*/
|
|
764
|
+
type ResponsesApiOptions = {
|
|
765
|
+
/**
|
|
766
|
+
* Whether to store the response server-side.
|
|
767
|
+
* When true, the response can be retrieved later using the response ID.
|
|
768
|
+
*/
|
|
769
|
+
store?: boolean;
|
|
770
|
+
/**
|
|
771
|
+
* ID of a previous response to continue from.
|
|
772
|
+
* Enables multi-turn conversations without resending full history.
|
|
773
|
+
*/
|
|
774
|
+
previousResponseId?: string;
|
|
775
|
+
/**
|
|
776
|
+
* Conversation ID for grouping related responses.
|
|
777
|
+
*/
|
|
778
|
+
conversation?: string;
|
|
779
|
+
/**
|
|
780
|
+
* Controls randomness in the response (0.0 to 2.0).
|
|
781
|
+
* Lower values make output more deterministic.
|
|
782
|
+
*/
|
|
783
|
+
temperature?: number;
|
|
784
|
+
/**
|
|
785
|
+
* Maximum number of tokens to generate in the response.
|
|
786
|
+
*/
|
|
787
|
+
maxOutputTokens?: number;
|
|
788
|
+
/**
|
|
789
|
+
* Array of tool definitions available to the model.
|
|
790
|
+
*/
|
|
791
|
+
tools?: LlmapiTool[];
|
|
792
|
+
/**
|
|
793
|
+
* Controls which tool to use: "auto", "any", "none", "required", or a specific tool name.
|
|
794
|
+
*/
|
|
795
|
+
toolChoice?: string;
|
|
796
|
+
/**
|
|
797
|
+
* Reasoning configuration for o-series and other reasoning models.
|
|
798
|
+
* Controls reasoning effort and summary output.
|
|
799
|
+
*/
|
|
800
|
+
reasoning?: LlmapiResponseReasoning;
|
|
801
|
+
/**
|
|
802
|
+
* Extended thinking configuration for Anthropic models (Claude).
|
|
803
|
+
* Enables the model to think through complex problems step by step.
|
|
804
|
+
*/
|
|
805
|
+
thinking?: LlmapiThinkingOptions;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Base arguments for sending a message
|
|
809
|
+
*/
|
|
810
|
+
type BaseSendMessageArgs = ResponsesApiOptions & {
|
|
811
|
+
messages: LlmapiMessage[];
|
|
812
|
+
model?: string;
|
|
813
|
+
/**
|
|
814
|
+
* Per-request callback for data chunks. Called in addition to the global
|
|
815
|
+
* `onData` callback if provided in `useChat` options.
|
|
816
|
+
*
|
|
817
|
+
* @param chunk - The content delta from the current chunk
|
|
818
|
+
*/
|
|
819
|
+
onData?: (chunk: string) => void;
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* Base options for useChat hook
|
|
823
|
+
*/
|
|
824
|
+
type BaseUseChatOptions = {
|
|
825
|
+
getToken?: () => Promise<string | null>;
|
|
826
|
+
baseUrl?: string;
|
|
827
|
+
/**
|
|
828
|
+
* Callback function to be called when a new data chunk is received.
|
|
829
|
+
*/
|
|
830
|
+
onData?: (chunk: string) => void;
|
|
831
|
+
/**
|
|
832
|
+
* Callback function to be called when thinking/reasoning content is received.
|
|
833
|
+
* This is called with delta chunks as the model "thinks" through a problem.
|
|
834
|
+
*/
|
|
835
|
+
onThinking?: (chunk: string) => void;
|
|
836
|
+
/**
|
|
837
|
+
* Callback function to be called when the chat completion finishes successfully.
|
|
838
|
+
*/
|
|
839
|
+
onFinish?: (response: LlmapiResponseResponse) => void;
|
|
840
|
+
/**
|
|
841
|
+
* Callback function to be called when an unexpected error is encountered.
|
|
842
|
+
*
|
|
843
|
+
* **Note:** This callback is NOT called for aborted requests (via `stop()` or
|
|
844
|
+
* component unmount). Aborts are intentional actions and are not considered
|
|
845
|
+
* errors. To detect aborts, check the `error` field in the `sendMessage` result:
|
|
846
|
+
* `result.error === "Request aborted"`.
|
|
847
|
+
*
|
|
848
|
+
* @param error - The error that occurred (never an AbortError)
|
|
849
|
+
*/
|
|
850
|
+
onError?: (error: Error) => void;
|
|
851
|
+
};
|
|
852
|
+
/**
|
|
853
|
+
* Base result type for useChat hook
|
|
854
|
+
*/
|
|
855
|
+
type BaseUseChatResult = {
|
|
856
|
+
isLoading: boolean;
|
|
857
|
+
/**
|
|
858
|
+
* Aborts the current streaming request if one is in progress.
|
|
859
|
+
*
|
|
860
|
+
* When a request is aborted, `sendMessage` will return with
|
|
861
|
+
* `{ data: null, error: "Request aborted" }`. The `onError` callback
|
|
862
|
+
* will NOT be called, as aborts are intentional actions, not errors.
|
|
863
|
+
*/
|
|
864
|
+
stop: () => void;
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
type SendMessageArgs = BaseSendMessageArgs & {
|
|
868
|
+
/**
|
|
869
|
+
* Optional custom headers to include with the request.
|
|
870
|
+
*/
|
|
871
|
+
headers?: Record<string, string>;
|
|
872
|
+
/**
|
|
873
|
+
* Memory context to inject as a system message.
|
|
874
|
+
* This is typically formatted memories from useMemoryStorage.
|
|
875
|
+
*/
|
|
876
|
+
memoryContext?: string;
|
|
877
|
+
/**
|
|
878
|
+
* Search context to inject as a system message.
|
|
879
|
+
* This is typically formatted search results from useSearch.
|
|
880
|
+
*/
|
|
881
|
+
searchContext?: string;
|
|
882
|
+
/**
|
|
883
|
+
* Per-request callback for thinking/reasoning chunks. Called in addition to the global
|
|
884
|
+
* `onThinking` callback if provided in `useChat` options.
|
|
885
|
+
*
|
|
886
|
+
* @param chunk - The thinking delta from the current chunk
|
|
887
|
+
*/
|
|
888
|
+
onThinking?: (chunk: string) => void;
|
|
889
|
+
};
|
|
890
|
+
type SendMessageResult = {
|
|
891
|
+
data: LlmapiResponseResponse;
|
|
892
|
+
error: null;
|
|
893
|
+
} | {
|
|
894
|
+
data: LlmapiResponseResponse | null;
|
|
895
|
+
error: string;
|
|
896
|
+
};
|
|
897
|
+
type UseChatOptions = BaseUseChatOptions;
|
|
898
|
+
type UseChatResult = BaseUseChatResult & {
|
|
899
|
+
sendMessage: (args: SendMessageArgs) => Promise<SendMessageResult>;
|
|
900
|
+
};
|
|
901
|
+
/**
|
|
902
|
+
* A React hook for managing chat completions with authentication.
|
|
903
|
+
*
|
|
904
|
+
* This hook provides a convenient way to send chat messages to the LLM API
|
|
905
|
+
* with automatic token management and loading state handling.
|
|
906
|
+
* Streaming is enabled by default for better user experience.
|
|
907
|
+
*
|
|
908
|
+
* @param options - Optional configuration object
|
|
909
|
+
* @param options.getToken - An async function that returns an authentication token.
|
|
910
|
+
* This token will be used as a Bearer token in the Authorization header.
|
|
911
|
+
* If not provided, `sendMessage` will return an error.
|
|
912
|
+
* @param options.baseUrl - Optional base URL for the API requests.
|
|
913
|
+
* @param options.onData - Callback function to be called when a new data chunk is received.
|
|
914
|
+
* @param options.onThinking - Callback function to be called when thinking/reasoning content is received.
|
|
915
|
+
* @param options.onFinish - Callback function to be called when the chat completion finishes successfully.
|
|
916
|
+
* @param options.onError - Callback function to be called when an unexpected error
|
|
917
|
+
* is encountered. Note: This is NOT called for aborted requests (see `stop()`).
|
|
918
|
+
*
|
|
919
|
+
* @category Hooks
|
|
920
|
+
*
|
|
921
|
+
* @returns An object containing:
|
|
922
|
+
* - `isLoading`: A boolean indicating whether a request is currently in progress
|
|
923
|
+
* - `sendMessage`: An async function to send chat messages
|
|
924
|
+
* - `stop`: A function to abort the current request
|
|
925
|
+
*
|
|
926
|
+
* @example
|
|
927
|
+
* ```tsx
|
|
928
|
+
* // Basic usage with API
|
|
929
|
+
* const { isLoading, sendMessage, stop } = useChat({
|
|
930
|
+
* getToken: async () => await getAuthToken(),
|
|
931
|
+
* onFinish: (response) => console.log("Chat finished:", response),
|
|
932
|
+
* onError: (error) => console.error("Chat error:", error)
|
|
933
|
+
* });
|
|
934
|
+
*
|
|
935
|
+
* const handleSend = async () => {
|
|
936
|
+
* const result = await sendMessage({
|
|
937
|
+
* messages: [{ role: 'user', content: [{ type: 'text', text: 'Hello!' }] }],
|
|
938
|
+
* model: 'gpt-4o-mini'
|
|
939
|
+
* });
|
|
940
|
+
* };
|
|
941
|
+
*
|
|
942
|
+
* // Using extended thinking (Anthropic Claude)
|
|
943
|
+
* const result = await sendMessage({
|
|
944
|
+
* messages: [{ role: 'user', content: [{ type: 'text', text: 'Solve this complex problem...' }] }],
|
|
945
|
+
* model: 'anthropic/claude-3-7-sonnet-20250219',
|
|
946
|
+
* thinking: { type: 'enabled', budget_tokens: 10000 },
|
|
947
|
+
* onThinking: (chunk) => console.log('Thinking:', chunk)
|
|
948
|
+
* });
|
|
949
|
+
*
|
|
950
|
+
* // Using reasoning (OpenAI o-series)
|
|
951
|
+
* const result = await sendMessage({
|
|
952
|
+
* messages: [{ role: 'user', content: [{ type: 'text', text: 'Reason through this...' }] }],
|
|
953
|
+
* model: 'openai/o1',
|
|
954
|
+
* reasoning: { effort: 'high', summary: 'detailed' }
|
|
955
|
+
* });
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
declare function useChat(options?: UseChatOptions): UseChatResult;
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Clears the encryption key for a wallet address from memory
|
|
962
|
+
* @param address - The wallet address
|
|
963
|
+
*/
|
|
964
|
+
declare function clearEncryptionKey(address: string): void;
|
|
965
|
+
/**
|
|
966
|
+
* Clears all encryption keys from memory
|
|
967
|
+
*/
|
|
968
|
+
declare function clearAllEncryptionKeys(): void;
|
|
969
|
+
/**
|
|
970
|
+
* Encrypts data using AES-GCM with the stored encryption key
|
|
971
|
+
* @param plaintext - The data to encrypt (string or Uint8Array)
|
|
972
|
+
* @param address - The wallet address for encryption
|
|
973
|
+
* @returns Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
974
|
+
*/
|
|
975
|
+
declare function encryptData(plaintext: string | Uint8Array, address: string): Promise<string>;
|
|
976
|
+
/**
|
|
977
|
+
* Decrypts data using AES-GCM with the stored encryption key
|
|
978
|
+
* @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
979
|
+
* @param address - The wallet address for decryption
|
|
980
|
+
* @returns Decrypted data as string
|
|
981
|
+
*/
|
|
982
|
+
declare function decryptData(encryptedHex: string, address: string): Promise<string>;
|
|
983
|
+
/**
|
|
984
|
+
* Decrypts data and returns as Uint8Array (for binary data)
|
|
985
|
+
* @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
986
|
+
* @returns Decrypted data as Uint8Array
|
|
987
|
+
*/
|
|
988
|
+
declare function decryptDataBytes(encryptedHex: string, address: string): Promise<Uint8Array>;
|
|
989
|
+
/**
|
|
990
|
+
* Checks if an encryption key exists in memory for the given wallet address
|
|
991
|
+
*/
|
|
992
|
+
declare function hasEncryptionKey(address: string): boolean;
|
|
993
|
+
/**
|
|
994
|
+
* Type for the signMessage function that client must provide
|
|
995
|
+
*/
|
|
996
|
+
type SignMessageFn = (message: string) => Promise<string>;
|
|
997
|
+
/**
|
|
998
|
+
* Requests the user to sign a message to generate an encryption key.
|
|
999
|
+
* If a key already exists in memory for the given wallet, resolves immediately.
|
|
1000
|
+
*
|
|
1001
|
+
* Note: Keys are stored in memory only and do not persist across page reloads.
|
|
1002
|
+
* This is a security feature - users must sign once per session to derive their key.
|
|
1003
|
+
*
|
|
1004
|
+
* Handles Privy rate limits (429 errors) with automatic retry and exponential backoff.
|
|
1005
|
+
*
|
|
1006
|
+
* @param walletAddress - The wallet address to generate the key for
|
|
1007
|
+
* @param signMessage - Function to sign a message (returns signature hex string)
|
|
1008
|
+
* @returns Promise that resolves when the key is available
|
|
1009
|
+
*/
|
|
1010
|
+
declare function requestEncryptionKey(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Requests the user to sign a message to generate an ECDH key pair.
|
|
1013
|
+
* If a key pair already exists in memory for the given wallet, resolves immediately.
|
|
1014
|
+
*
|
|
1015
|
+
* Note: Key pairs are stored in memory only and do not persist across page reloads.
|
|
1016
|
+
* This is a security feature - users must sign once per session to derive their key pair.
|
|
1017
|
+
*
|
|
1018
|
+
* Handles Privy rate limits (429 errors) with automatic retry and exponential backoff.
|
|
1019
|
+
*
|
|
1020
|
+
* @param walletAddress - The wallet address to generate the key pair for
|
|
1021
|
+
* @param signMessage - Function to sign a message (returns signature hex string)
|
|
1022
|
+
* @returns Promise that resolves when the key pair is available
|
|
1023
|
+
*/
|
|
1024
|
+
declare function requestKeyPair(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Exports the public key for a wallet address as SPKI format (base64)
|
|
1027
|
+
* @param address - The wallet address
|
|
1028
|
+
* @param signMessage - Function to sign a message (returns signature hex string)
|
|
1029
|
+
* @returns The public key as base64-encoded SPKI string
|
|
1030
|
+
*/
|
|
1031
|
+
declare function exportPublicKey(address: string, signMessage: SignMessageFn): Promise<string>;
|
|
1032
|
+
/**
|
|
1033
|
+
* Checks if a key pair exists in memory for the given wallet address
|
|
1034
|
+
* @param address - The wallet address
|
|
1035
|
+
* @returns True if key pair exists, false otherwise
|
|
1036
|
+
*/
|
|
1037
|
+
declare function hasKeyPair(address: string): boolean;
|
|
1038
|
+
/**
|
|
1039
|
+
* Clears the key pair for a wallet address from memory
|
|
1040
|
+
* @param address - The wallet address
|
|
1041
|
+
*/
|
|
1042
|
+
declare function clearKeyPair(address: string): void;
|
|
1043
|
+
/**
|
|
1044
|
+
* Clears all key pairs from memory
|
|
1045
|
+
*/
|
|
1046
|
+
declare function clearAllKeyPairs(): void;
|
|
1047
|
+
/**
|
|
1048
|
+
* Hook that provides on-demand encryption key management.
|
|
1049
|
+
* @param signMessage - Function to sign a message (from Privy's useSignMessage)
|
|
1050
|
+
* @returns Functions to request encryption keys and manage key pairs
|
|
1051
|
+
* @category Hooks
|
|
1052
|
+
*/
|
|
1053
|
+
declare function useEncryption(signMessage: SignMessageFn): {
|
|
1054
|
+
requestEncryptionKey: (walletAddress: string) => Promise<void>;
|
|
1055
|
+
requestKeyPair: (walletAddress: string) => Promise<void>;
|
|
1056
|
+
exportPublicKey: (walletAddress: string) => Promise<string>;
|
|
1057
|
+
hasKeyPair: (walletAddress: string) => boolean;
|
|
1058
|
+
clearKeyPair: (walletAddress: string) => void;
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
declare const chatStorageSchema: Readonly<{
|
|
1062
|
+
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1063
|
+
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
1064
|
+
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
1065
|
+
}>;
|
|
1066
|
+
declare const chatStorageMigrations: Readonly<{
|
|
1067
|
+
validated: true;
|
|
1068
|
+
minVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1069
|
+
maxVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1070
|
+
sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
|
|
1071
|
+
}>;
|
|
1072
|
+
|
|
1073
|
+
interface MemoryItem$1 {
|
|
1074
|
+
type: "identity" | "preference" | "project" | "skill" | "constraint";
|
|
1075
|
+
namespace: string;
|
|
1076
|
+
key: string;
|
|
1077
|
+
value: string;
|
|
1078
|
+
rawEvidence: string;
|
|
1079
|
+
confidence: number;
|
|
1080
|
+
pii: boolean;
|
|
1081
|
+
}
|
|
1082
|
+
interface MemoryExtractionResult {
|
|
1083
|
+
items: MemoryItem$1[];
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
type MemoryType = "identity" | "preference" | "project" | "skill" | "constraint";
|
|
1087
|
+
interface MemoryItem {
|
|
1088
|
+
type: MemoryType;
|
|
1089
|
+
namespace: string;
|
|
1090
|
+
key: string;
|
|
1091
|
+
value: string;
|
|
1092
|
+
rawEvidence: string;
|
|
1093
|
+
confidence: number;
|
|
1094
|
+
pii: boolean;
|
|
1095
|
+
}
|
|
1096
|
+
interface CreateMemoryOptions extends MemoryItem {
|
|
1097
|
+
embedding?: number[];
|
|
1098
|
+
embeddingModel?: string;
|
|
1099
|
+
}
|
|
1100
|
+
type UpdateMemoryOptions = Partial<CreateMemoryOptions>;
|
|
1101
|
+
interface StoredMemory extends MemoryItem {
|
|
1102
|
+
uniqueId: string;
|
|
1103
|
+
compositeKey: string;
|
|
1104
|
+
uniqueKey: string;
|
|
1105
|
+
createdAt: Date;
|
|
1106
|
+
updatedAt: Date;
|
|
1107
|
+
embedding?: number[];
|
|
1108
|
+
embeddingModel?: string;
|
|
1109
|
+
isDeleted: boolean;
|
|
1110
|
+
}
|
|
1111
|
+
interface StoredMemoryWithSimilarity extends StoredMemory {
|
|
1112
|
+
similarity: number;
|
|
1113
|
+
}
|
|
1114
|
+
interface BaseUseMemoryStorageOptions {
|
|
1115
|
+
database: Database;
|
|
1116
|
+
completionsModel?: string;
|
|
1117
|
+
embeddingModel?: string | null;
|
|
1118
|
+
generateEmbeddings?: boolean;
|
|
1119
|
+
onFactsExtracted?: (facts: MemoryExtractionResult) => void;
|
|
1120
|
+
getToken?: () => Promise<string | null>;
|
|
1121
|
+
baseUrl?: string;
|
|
1122
|
+
/** Wallet address for encryption (optional - encryption disabled if not provided) */
|
|
1123
|
+
walletAddress?: string | null;
|
|
1124
|
+
/** Function to request encryption key (optional - encryption disabled if not provided) */
|
|
1125
|
+
requestEncryptionKey?: (address: string) => Promise<void>;
|
|
1126
|
+
/** Function to sign message for migration (optional - migration disabled if not provided) */
|
|
1127
|
+
signMessage?: (message: string) => Promise<string>;
|
|
1128
|
+
}
|
|
1129
|
+
interface BaseUseMemoryStorageResult {
|
|
1130
|
+
memories: StoredMemory[];
|
|
1131
|
+
refreshMemories: () => Promise<void>;
|
|
1132
|
+
extractMemoriesFromMessage: (options: {
|
|
1133
|
+
messages: Array<{
|
|
1134
|
+
role: string;
|
|
1135
|
+
content: string;
|
|
1136
|
+
}>;
|
|
1137
|
+
model?: string;
|
|
1138
|
+
}) => Promise<MemoryExtractionResult | null>;
|
|
1139
|
+
searchMemories: (query: string, limit?: number, minSimilarity?: number) => Promise<StoredMemoryWithSimilarity[]>;
|
|
1140
|
+
fetchAllMemories: () => Promise<StoredMemory[]>;
|
|
1141
|
+
fetchMemoriesByNamespace: (namespace: string) => Promise<StoredMemory[]>;
|
|
1142
|
+
fetchMemoriesByKey: (namespace: string, key: string) => Promise<StoredMemory[]>;
|
|
1143
|
+
getMemoryById: (id: string) => Promise<StoredMemory | null>;
|
|
1144
|
+
saveMemory: (memory: CreateMemoryOptions) => Promise<StoredMemory>;
|
|
1145
|
+
saveMemories: (memories: CreateMemoryOptions[]) => Promise<StoredMemory[]>;
|
|
1146
|
+
updateMemory: (id: string, updates: UpdateMemoryOptions) => Promise<StoredMemory | null>;
|
|
1147
|
+
removeMemory: (namespace: string, key: string, value: string) => Promise<void>;
|
|
1148
|
+
removeMemoryById: (id: string) => Promise<void>;
|
|
1149
|
+
removeMemories: (namespace: string, key: string) => Promise<void>;
|
|
1150
|
+
clearMemories: () => Promise<void>;
|
|
1151
|
+
}
|
|
1152
|
+
declare function generateCompositeKey(namespace: string, key: string): string;
|
|
1153
|
+
declare function generateUniqueKey(namespace: string, key: string, value: string): string;
|
|
1154
|
+
|
|
1155
|
+
type ChatRole = "user" | "assistant" | "system";
|
|
1156
|
+
interface FileMetadata {
|
|
1157
|
+
id: string;
|
|
1158
|
+
name: string;
|
|
1159
|
+
type: string;
|
|
1160
|
+
size: number;
|
|
1161
|
+
url?: string;
|
|
1162
|
+
}
|
|
1163
|
+
interface ChatCompletionUsage {
|
|
1164
|
+
promptTokens?: number;
|
|
1165
|
+
completionTokens?: number;
|
|
1166
|
+
totalTokens?: number;
|
|
1167
|
+
costMicroUsd?: number;
|
|
1168
|
+
}
|
|
1169
|
+
interface SearchSource {
|
|
1170
|
+
title?: string;
|
|
1171
|
+
url?: string;
|
|
1172
|
+
snippet?: string;
|
|
1173
|
+
date?: string;
|
|
1174
|
+
}
|
|
1175
|
+
interface StoredMessage {
|
|
1176
|
+
uniqueId: string;
|
|
1177
|
+
messageId: number;
|
|
1178
|
+
conversationId: string;
|
|
1179
|
+
role: ChatRole;
|
|
1180
|
+
content: string;
|
|
1181
|
+
model?: string;
|
|
1182
|
+
files?: FileMetadata[];
|
|
1183
|
+
createdAt: Date;
|
|
1184
|
+
updatedAt: Date;
|
|
1185
|
+
vector?: number[];
|
|
1186
|
+
embeddingModel?: string;
|
|
1187
|
+
usage?: ChatCompletionUsage;
|
|
1188
|
+
sources?: SearchSource[];
|
|
1189
|
+
responseDuration?: number;
|
|
1190
|
+
wasStopped?: boolean;
|
|
1191
|
+
/** If set, indicates the message failed with this error */
|
|
1192
|
+
error?: string;
|
|
1193
|
+
thoughtProcess?: ActivityPhase[];
|
|
1194
|
+
/** Reasoning/thinking content from models that support extended thinking */
|
|
1195
|
+
thinking?: string;
|
|
1196
|
+
}
|
|
1197
|
+
interface ActivityPhase {
|
|
1198
|
+
id: string;
|
|
1199
|
+
label: string;
|
|
1200
|
+
timestamp: number;
|
|
1201
|
+
status: "pending" | "active" | "completed";
|
|
1202
|
+
data?: StoredMemory[];
|
|
1203
|
+
}
|
|
1204
|
+
interface StoredConversation {
|
|
1205
|
+
uniqueId: string;
|
|
1206
|
+
conversationId: string;
|
|
1207
|
+
title: string;
|
|
1208
|
+
createdAt: Date;
|
|
1209
|
+
updatedAt: Date;
|
|
1210
|
+
isDeleted: boolean;
|
|
1211
|
+
}
|
|
1212
|
+
interface StoredMessageWithSimilarity extends StoredMessage {
|
|
1213
|
+
similarity: number;
|
|
1214
|
+
}
|
|
1215
|
+
interface CreateMessageOptions {
|
|
1216
|
+
conversationId: string;
|
|
1217
|
+
role: ChatRole;
|
|
1218
|
+
content: string;
|
|
1219
|
+
model?: string;
|
|
1220
|
+
files?: FileMetadata[];
|
|
1221
|
+
usage?: ChatCompletionUsage;
|
|
1222
|
+
sources?: SearchSource[];
|
|
1223
|
+
responseDuration?: number;
|
|
1224
|
+
vector?: number[];
|
|
1225
|
+
embeddingModel?: string;
|
|
1226
|
+
wasStopped?: boolean;
|
|
1227
|
+
/** If set, indicates the message failed with this error */
|
|
1228
|
+
error?: string;
|
|
1229
|
+
thoughtProcess?: ActivityPhase[];
|
|
1230
|
+
/** Reasoning/thinking content from models that support extended thinking */
|
|
1231
|
+
thinking?: string;
|
|
1232
|
+
}
|
|
1233
|
+
interface CreateConversationOptions {
|
|
1234
|
+
conversationId?: string;
|
|
1235
|
+
title?: string;
|
|
1236
|
+
}
|
|
1237
|
+
interface UpdateMessageOptions {
|
|
1238
|
+
content?: string;
|
|
1239
|
+
model?: string;
|
|
1240
|
+
files?: FileMetadata[];
|
|
1241
|
+
usage?: ChatCompletionUsage;
|
|
1242
|
+
sources?: SearchSource[];
|
|
1243
|
+
responseDuration?: number;
|
|
1244
|
+
vector?: number[];
|
|
1245
|
+
embeddingModel?: string;
|
|
1246
|
+
wasStopped?: boolean;
|
|
1247
|
+
error?: string | null;
|
|
1248
|
+
thoughtProcess?: ActivityPhase[];
|
|
1249
|
+
/** Reasoning/thinking content from models that support extended thinking */
|
|
1250
|
+
thinking?: string | null;
|
|
1251
|
+
}
|
|
1252
|
+
interface BaseUseChatStorageOptions {
|
|
1253
|
+
database: Database;
|
|
1254
|
+
conversationId?: string;
|
|
1255
|
+
autoCreateConversation?: boolean;
|
|
1256
|
+
defaultConversationTitle?: string;
|
|
1257
|
+
getToken?: () => Promise<string | null>;
|
|
1258
|
+
baseUrl?: string;
|
|
1259
|
+
onData?: (chunk: string) => void;
|
|
1260
|
+
onFinish?: (response: LlmapiResponseResponse) => void;
|
|
1261
|
+
onError?: (error: Error) => void;
|
|
1262
|
+
/** Wallet address for encryption (optional - encryption disabled if not provided) */
|
|
1263
|
+
walletAddress?: string | null;
|
|
1264
|
+
/** Function to request encryption key (optional - encryption disabled if not provided) */
|
|
1265
|
+
requestEncryptionKey?: (address: string) => Promise<void>;
|
|
1266
|
+
/** Function to sign message for migration (optional - required for migrating old encrypted data) */
|
|
1267
|
+
signMessage?: (message: string) => Promise<string>;
|
|
1268
|
+
}
|
|
1269
|
+
interface BaseSendMessageWithStorageArgs {
|
|
1270
|
+
content: string;
|
|
1271
|
+
model?: string;
|
|
1272
|
+
messages?: LlmapiMessage[];
|
|
1273
|
+
includeHistory?: boolean;
|
|
1274
|
+
maxHistoryMessages?: number;
|
|
1275
|
+
files?: FileMetadata[];
|
|
1276
|
+
onData?: (chunk: string) => void;
|
|
1277
|
+
memoryContext?: string;
|
|
1278
|
+
searchContext?: string;
|
|
1279
|
+
sources?: SearchSource[];
|
|
1280
|
+
thoughtProcess?: ActivityPhase[];
|
|
1281
|
+
/**
|
|
1282
|
+
* Whether to store the response server-side.
|
|
1283
|
+
* When true, the response can be retrieved later using the response ID.
|
|
1284
|
+
*/
|
|
1285
|
+
store?: boolean;
|
|
1286
|
+
/**
|
|
1287
|
+
* ID of a previous response to continue from.
|
|
1288
|
+
* Enables multi-turn conversations without resending full history.
|
|
1289
|
+
*/
|
|
1290
|
+
previousResponseId?: string;
|
|
1291
|
+
/**
|
|
1292
|
+
* Conversation ID for grouping related responses on the server.
|
|
1293
|
+
*/
|
|
1294
|
+
serverConversation?: string;
|
|
1295
|
+
/**
|
|
1296
|
+
* Controls randomness in the response (0.0 to 2.0).
|
|
1297
|
+
*/
|
|
1298
|
+
temperature?: number;
|
|
1299
|
+
/**
|
|
1300
|
+
* Maximum number of tokens to generate in the response.
|
|
1301
|
+
*/
|
|
1302
|
+
maxOutputTokens?: number;
|
|
1303
|
+
/**
|
|
1304
|
+
* Array of tool definitions available to the model.
|
|
1305
|
+
*/
|
|
1306
|
+
tools?: LlmapiTool[];
|
|
1307
|
+
/**
|
|
1308
|
+
* Controls which tool to use: "auto", "any", "none", "required", or a specific tool name.
|
|
1309
|
+
*/
|
|
1310
|
+
toolChoice?: string;
|
|
1311
|
+
/**
|
|
1312
|
+
* Reasoning configuration for o-series and other reasoning models.
|
|
1313
|
+
* Controls reasoning effort and summary output.
|
|
1314
|
+
*/
|
|
1315
|
+
reasoning?: LlmapiResponseReasoning;
|
|
1316
|
+
/**
|
|
1317
|
+
* Extended thinking configuration for Anthropic models (Claude).
|
|
1318
|
+
* Enables the model to think through complex problems step by step.
|
|
1319
|
+
*/
|
|
1320
|
+
thinking?: LlmapiThinkingOptions;
|
|
1321
|
+
/**
|
|
1322
|
+
* Per-request callback for thinking/reasoning chunks.
|
|
1323
|
+
* Called with delta chunks as the model "thinks" through a problem.
|
|
1324
|
+
*/
|
|
1325
|
+
onThinking?: (chunk: string) => void;
|
|
1326
|
+
}
|
|
1327
|
+
interface BaseUseChatStorageResult {
|
|
1328
|
+
isLoading: boolean;
|
|
1329
|
+
stop: () => void;
|
|
1330
|
+
conversationId: string | null;
|
|
1331
|
+
setConversationId: (id: string | null) => void;
|
|
1332
|
+
createConversation: (options?: CreateConversationOptions) => Promise<StoredConversation>;
|
|
1333
|
+
getConversation: (id: string) => Promise<StoredConversation | null>;
|
|
1334
|
+
getConversations: () => Promise<StoredConversation[]>;
|
|
1335
|
+
updateConversationTitle: (id: string, title: string) => Promise<boolean>;
|
|
1336
|
+
deleteConversation: (id: string) => Promise<boolean>;
|
|
1337
|
+
getMessages: (conversationId: string) => Promise<StoredMessage[]>;
|
|
1338
|
+
getMessageCount: (conversationId: string) => Promise<number>;
|
|
1339
|
+
clearMessages: (conversationId: string) => Promise<void>;
|
|
1340
|
+
}
|
|
1341
|
+
declare function generateConversationId(): string;
|
|
1342
|
+
|
|
1343
|
+
declare class Message extends Model {
|
|
1344
|
+
static table: string;
|
|
1345
|
+
static associations: Associations;
|
|
1346
|
+
messageId: number;
|
|
1347
|
+
conversationId: string;
|
|
1348
|
+
role: ChatRole;
|
|
1349
|
+
content: string;
|
|
1350
|
+
model?: string;
|
|
1351
|
+
files?: FileMetadata[];
|
|
1352
|
+
createdAt: Date;
|
|
1353
|
+
updatedAt: Date;
|
|
1354
|
+
vector?: number[];
|
|
1355
|
+
embeddingModel?: string;
|
|
1356
|
+
usage?: ChatCompletionUsage;
|
|
1357
|
+
sources?: SearchSource[];
|
|
1358
|
+
responseDuration?: number;
|
|
1359
|
+
wasStopped?: boolean;
|
|
1360
|
+
error?: string;
|
|
1361
|
+
thoughtProcess?: ActivityPhase[];
|
|
1362
|
+
thinking?: string;
|
|
1363
|
+
}
|
|
1364
|
+
declare class Conversation extends Model {
|
|
1365
|
+
static table: string;
|
|
1366
|
+
static associations: Associations;
|
|
1367
|
+
conversationId: string;
|
|
1368
|
+
title: string;
|
|
1369
|
+
createdAt: Date;
|
|
1370
|
+
updatedAt: Date;
|
|
1371
|
+
isDeleted: boolean;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* Options for useChatStorage hook (React version)
|
|
1376
|
+
*
|
|
1377
|
+
* Uses base options.
|
|
1378
|
+
*/
|
|
1379
|
+
type UseChatStorageOptions = BaseUseChatStorageOptions;
|
|
1380
|
+
/**
|
|
1381
|
+
* Arguments for sendMessage with storage (React version)
|
|
1382
|
+
*
|
|
1383
|
+
* Extends base arguments with headers support.
|
|
1384
|
+
*/
|
|
1385
|
+
interface SendMessageWithStorageArgs extends BaseSendMessageWithStorageArgs {
|
|
1386
|
+
/** Custom headers */
|
|
1387
|
+
headers?: Record<string, string>;
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Result from sendMessage with storage (React version)
|
|
1391
|
+
*/
|
|
1392
|
+
type SendMessageWithStorageResult = {
|
|
1393
|
+
data: LlmapiResponseResponse;
|
|
1394
|
+
error: null;
|
|
1395
|
+
userMessage: StoredMessage;
|
|
1396
|
+
assistantMessage: StoredMessage;
|
|
1397
|
+
} | {
|
|
1398
|
+
data: null;
|
|
1399
|
+
error: string;
|
|
1400
|
+
userMessage?: StoredMessage;
|
|
1401
|
+
assistantMessage?: undefined;
|
|
1402
|
+
};
|
|
1403
|
+
/**
|
|
1404
|
+
* Options for searching messages
|
|
1405
|
+
*/
|
|
1406
|
+
interface SearchMessagesOptions {
|
|
1407
|
+
/** Limit the number of results (default: 10) */
|
|
1408
|
+
limit?: number;
|
|
1409
|
+
/** Minimum similarity threshold (default: 0.5) */
|
|
1410
|
+
minSimilarity?: number;
|
|
1411
|
+
/** Filter by conversation ID */
|
|
1412
|
+
conversationId?: string;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Result returned by useChatStorage hook (React version)
|
|
1416
|
+
*
|
|
1417
|
+
* Extends base result with React-specific sendMessage signature.
|
|
1418
|
+
*/
|
|
1419
|
+
interface UseChatStorageResult extends BaseUseChatStorageResult {
|
|
1420
|
+
/** Send a message and automatically store it */
|
|
1421
|
+
sendMessage: (args: SendMessageWithStorageArgs) => Promise<SendMessageWithStorageResult>;
|
|
1422
|
+
/** Search messages by vector similarity */
|
|
1423
|
+
searchMessages: (queryVector: number[], options?: SearchMessagesOptions) => Promise<StoredMessageWithSimilarity[]>;
|
|
1424
|
+
/** Update a message's embedding vector. Returns updated message or null if not found. */
|
|
1425
|
+
updateMessageEmbedding: (uniqueId: string, vector: number[], embeddingModel: string) => Promise<StoredMessage | null>;
|
|
1426
|
+
/** Extract all links from assistant message content as SearchSource objects */
|
|
1427
|
+
extractSourcesFromAssistantMessage: (assistantMessage: {
|
|
1428
|
+
content: string;
|
|
1429
|
+
sources?: SearchSource[];
|
|
1430
|
+
}) => SearchSource[];
|
|
1431
|
+
/** Update a message's fields (content, embedding, files, etc). Returns updated message or null if not found. */
|
|
1432
|
+
updateMessage: (uniqueId: string, options: UpdateMessageOptions) => Promise<StoredMessage | null>;
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* A React hook that wraps useChat with automatic message persistence using WatermelonDB.
|
|
1436
|
+
*
|
|
1437
|
+
* This hook provides all the functionality of useChat plus automatic storage of
|
|
1438
|
+
* messages and conversations to a WatermelonDB database. Messages are automatically
|
|
1439
|
+
* saved when sent and when responses are received.
|
|
1440
|
+
*
|
|
1441
|
+
* @param options - Configuration options
|
|
1442
|
+
* @returns An object containing chat state, methods, and storage operations
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```tsx
|
|
1446
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
1447
|
+
* import { useChatStorage } from '@reverbia/sdk/react';
|
|
1448
|
+
*
|
|
1449
|
+
* function ChatComponent({ database }: { database: Database }) {
|
|
1450
|
+
* const {
|
|
1451
|
+
* isLoading,
|
|
1452
|
+
* sendMessage,
|
|
1453
|
+
* conversationId,
|
|
1454
|
+
* getMessages,
|
|
1455
|
+
* createConversation,
|
|
1456
|
+
* } = useChatStorage({
|
|
1457
|
+
* database,
|
|
1458
|
+
* getToken: async () => getAuthToken(),
|
|
1459
|
+
* onData: (chunk) => setResponse((prev) => prev + chunk),
|
|
1460
|
+
* });
|
|
1461
|
+
*
|
|
1462
|
+
* const handleSend = async () => {
|
|
1463
|
+
* const result = await sendMessage({
|
|
1464
|
+
* content: 'Hello, how are you?',
|
|
1465
|
+
* model: 'gpt-4o-mini',
|
|
1466
|
+
* includeHistory: true, // Include previous messages from this conversation
|
|
1467
|
+
* });
|
|
1468
|
+
*
|
|
1469
|
+
* if (result.error) {
|
|
1470
|
+
* console.error('Error:', result.error);
|
|
1471
|
+
* } else {
|
|
1472
|
+
* console.log('User message stored:', result.userMessage);
|
|
1473
|
+
* console.log('Assistant message stored:', result.assistantMessage);
|
|
1474
|
+
* }
|
|
1475
|
+
* };
|
|
1476
|
+
*
|
|
1477
|
+
* return (
|
|
1478
|
+
* <div>
|
|
1479
|
+
* <button onClick={handleSend} disabled={isLoading}>Send</button>
|
|
1480
|
+
* </div>
|
|
1481
|
+
* );
|
|
1482
|
+
* }
|
|
1483
|
+
* ```
|
|
1484
|
+
*
|
|
1485
|
+
* @category Hooks
|
|
1486
|
+
*/
|
|
1487
|
+
declare function useChatStorage(options: UseChatStorageOptions): UseChatStorageResult;
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* Combined WatermelonDB schema for all SDK storage modules.
|
|
1491
|
+
*
|
|
1492
|
+
* This unified schema includes all tables needed by the SDK:
|
|
1493
|
+
* - `history`: Chat message storage with embeddings and metadata
|
|
1494
|
+
* - `conversations`: Conversation metadata and organization
|
|
1495
|
+
* - `memories`: Persistent memory storage with semantic search
|
|
1496
|
+
* - `modelPreferences`: User model preferences and settings
|
|
1497
|
+
*
|
|
1498
|
+
* @example
|
|
1499
|
+
* ```typescript
|
|
1500
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
1501
|
+
* import LokiJSAdapter from '@nozbe/watermelondb/adapters/lokijs';
|
|
1502
|
+
* import { sdkSchema, sdkMigrations, sdkModelClasses } from '@reverbia/sdk/react';
|
|
1503
|
+
*
|
|
1504
|
+
* const adapter = new LokiJSAdapter({
|
|
1505
|
+
* schema: sdkSchema,
|
|
1506
|
+
* migrations: sdkMigrations,
|
|
1507
|
+
* dbName: 'my-app-db',
|
|
1508
|
+
* useWebWorker: false,
|
|
1509
|
+
* useIncrementalIndexedDB: true,
|
|
1510
|
+
* });
|
|
1511
|
+
*
|
|
1512
|
+
* const database = new Database({
|
|
1513
|
+
* adapter,
|
|
1514
|
+
* modelClasses: sdkModelClasses,
|
|
1515
|
+
* });
|
|
1516
|
+
* ```
|
|
1517
|
+
*/
|
|
1518
|
+
declare const sdkSchema: Readonly<{
|
|
1519
|
+
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1520
|
+
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
1521
|
+
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
1522
|
+
}>;
|
|
1523
|
+
/**
|
|
1524
|
+
* Combined migrations for all SDK storage modules.
|
|
1525
|
+
*
|
|
1526
|
+
* These migrations handle database schema upgrades from any previous version
|
|
1527
|
+
* to the current version. The SDK manages all migration logic internally,
|
|
1528
|
+
* so consumer apps don't need to handle version arithmetic or migration merging.
|
|
1529
|
+
*
|
|
1530
|
+
* **Minimum supported version: v2**
|
|
1531
|
+
* Migrations from v1 are not supported. Databases at v1 require a fresh install.
|
|
1532
|
+
*
|
|
1533
|
+
* Migration history:
|
|
1534
|
+
* - v2 → v3: Added `was_stopped` column to history table
|
|
1535
|
+
* - v3 → v4: Added `modelPreferences` table for settings storage
|
|
1536
|
+
* - v4 → v5: Added `error` column to history table for error persistence
|
|
1537
|
+
* - v5 → v6: Added `thought_process` column to history table for activity tracking
|
|
1538
|
+
*/
|
|
1539
|
+
declare const sdkMigrations: Readonly<{
|
|
1540
|
+
validated: true;
|
|
1541
|
+
minVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1542
|
+
maxVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1543
|
+
sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
|
|
1544
|
+
}>;
|
|
1545
|
+
/**
|
|
1546
|
+
* Model classes to register with the WatermelonDB database.
|
|
1547
|
+
*
|
|
1548
|
+
* Pass this array directly to the `modelClasses` option when creating
|
|
1549
|
+
* your Database instance.
|
|
1550
|
+
*
|
|
1551
|
+
* @example
|
|
1552
|
+
* ```typescript
|
|
1553
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
1554
|
+
* import { sdkSchema, sdkMigrations, sdkModelClasses } from '@reverbia/sdk/react';
|
|
1555
|
+
*
|
|
1556
|
+
* const database = new Database({
|
|
1557
|
+
* adapter,
|
|
1558
|
+
* modelClasses: sdkModelClasses,
|
|
1559
|
+
* });
|
|
1560
|
+
* ```
|
|
1561
|
+
*/
|
|
1562
|
+
declare const sdkModelClasses: Class<Model$1>[];
|
|
1563
|
+
|
|
1564
|
+
declare const memoryStorageSchema: Readonly<{
|
|
1565
|
+
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1566
|
+
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
1567
|
+
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
1568
|
+
}>;
|
|
1569
|
+
|
|
1570
|
+
declare class Memory extends Model {
|
|
1571
|
+
static table: string;
|
|
1572
|
+
type: MemoryType;
|
|
1573
|
+
namespace: string;
|
|
1574
|
+
key: string;
|
|
1575
|
+
value: string;
|
|
1576
|
+
rawEvidence: string;
|
|
1577
|
+
confidence: number;
|
|
1578
|
+
pii: boolean;
|
|
1579
|
+
compositeKey: string;
|
|
1580
|
+
uniqueKey: string;
|
|
1581
|
+
createdAt: Date;
|
|
1582
|
+
updatedAt: Date;
|
|
1583
|
+
embedding?: number[];
|
|
1584
|
+
embeddingModel?: string;
|
|
1585
|
+
isDeleted: boolean;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Options for useMemoryStorage hook (React version)
|
|
1590
|
+
*
|
|
1591
|
+
* Uses the base options. React-specific features can be added here if needed.
|
|
1592
|
+
*/
|
|
1593
|
+
type UseMemoryStorageOptions = BaseUseMemoryStorageOptions;
|
|
1594
|
+
/**
|
|
1595
|
+
* Result returned by useMemoryStorage hook (React version)
|
|
1596
|
+
*
|
|
1597
|
+
* Uses the base result. React-specific features can be added here if needed.
|
|
1598
|
+
*/
|
|
1599
|
+
type UseMemoryStorageResult = BaseUseMemoryStorageResult;
|
|
1600
|
+
/**
|
|
1601
|
+
* A React hook that wraps useMemory with automatic memory persistence using WatermelonDB.
|
|
1602
|
+
*
|
|
1603
|
+
* This hook provides all the functionality of useMemory plus automatic storage of
|
|
1604
|
+
* memories to a WatermelonDB database. Memories are automatically saved when extracted
|
|
1605
|
+
* and can be searched using semantic similarity.
|
|
1606
|
+
*
|
|
1607
|
+
* @param options - Configuration options
|
|
1608
|
+
* @returns An object containing memory state, methods, and storage operations
|
|
1609
|
+
*
|
|
1610
|
+
* @example
|
|
1611
|
+
* ```tsx
|
|
1612
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
1613
|
+
* import { useMemoryStorage } from '@reverbia/sdk/react';
|
|
1614
|
+
*
|
|
1615
|
+
* function MemoryComponent({ database }: { database: Database }) {
|
|
1616
|
+
* const {
|
|
1617
|
+
* memories,
|
|
1618
|
+
* extractMemoriesFromMessage,
|
|
1619
|
+
* searchMemories,
|
|
1620
|
+
* fetchAllMemories,
|
|
1621
|
+
* } = useMemoryStorage({
|
|
1622
|
+
* database,
|
|
1623
|
+
* getToken: async () => getAuthToken(),
|
|
1624
|
+
* onFactsExtracted: (facts) => console.log('Extracted:', facts),
|
|
1625
|
+
* });
|
|
1626
|
+
*
|
|
1627
|
+
* const handleExtract = async () => {
|
|
1628
|
+
* const result = await extractMemoriesFromMessage({
|
|
1629
|
+
* messages: [{ role: 'user', content: 'My name is John and I live in NYC' }],
|
|
1630
|
+
* model: 'gpt-4o-mini',
|
|
1631
|
+
* });
|
|
1632
|
+
* };
|
|
1633
|
+
*
|
|
1634
|
+
* return (
|
|
1635
|
+
* <div>
|
|
1636
|
+
* <button onClick={handleExtract}>Extract Memories</button>
|
|
1637
|
+
* <p>Total memories: {memories.length}</p>
|
|
1638
|
+
* </div>
|
|
1639
|
+
* );
|
|
1640
|
+
* }
|
|
1641
|
+
* ```
|
|
1642
|
+
*
|
|
1643
|
+
* @category Hooks
|
|
1644
|
+
*/
|
|
1645
|
+
declare function useMemoryStorage(options: UseMemoryStorageOptions): UseMemoryStorageResult;
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* Memory Encryption Utilities
|
|
1649
|
+
*
|
|
1650
|
+
* Encrypts sensitive memory fields at rest while keeping search/index fields unencrypted.
|
|
1651
|
+
* Based on the implementation from ai-memoryless-client.
|
|
1652
|
+
*/
|
|
1653
|
+
|
|
1654
|
+
/**
|
|
1655
|
+
* Get the encryption version from an encrypted value
|
|
1656
|
+
*/
|
|
1657
|
+
declare function getEncryptionVersion(value: string): "v1" | "v2" | null;
|
|
1658
|
+
/**
|
|
1659
|
+
* Encrypt a single string value using the SDK's encryption.
|
|
1660
|
+
* Returns the encrypted value with a prefix for identification.
|
|
1661
|
+
*
|
|
1662
|
+
* @param value - The plain text value to encrypt
|
|
1663
|
+
* @param address - The user's wallet address (encryption key identifier)
|
|
1664
|
+
* @returns The encrypted value with prefix
|
|
1665
|
+
* @throws {Error} If encryption fails - prevents sensitive data from being stored unencrypted
|
|
1666
|
+
*/
|
|
1667
|
+
declare function encryptField(value: string, address: string): Promise<string>;
|
|
1668
|
+
/**
|
|
1669
|
+
* Placeholder returned when decryption fails.
|
|
1670
|
+
* Allows UI to render a friendly message instead of gibberish.
|
|
1671
|
+
*/
|
|
1672
|
+
declare const DECRYPTION_FAILED_PLACEHOLDER = "[Decryption Failed]";
|
|
1673
|
+
/**
|
|
1674
|
+
* Decrypt a single string value using the SDK's decryption.
|
|
1675
|
+
* Supports both v1 (legacy) and v2 encryption formats.
|
|
1676
|
+
* Automatically migrates old encrypted values to new format.
|
|
1677
|
+
*
|
|
1678
|
+
* @param value - The encrypted value (with prefix)
|
|
1679
|
+
* @param address - The user's wallet address (encryption key identifier)
|
|
1680
|
+
* @param signMessage - Optional function to sign message for migration (required if old encryption detected)
|
|
1681
|
+
* @param onMigrated - Optional callback when a value is migrated
|
|
1682
|
+
* @returns The decrypted plain text, original value if not encrypted, or placeholder on error
|
|
1683
|
+
*/
|
|
1684
|
+
declare function decryptField(value: string, address: string, signMessage?: SignMessageFn, onMigrated?: (migratedValue: string) => Promise<void>): Promise<string>;
|
|
1685
|
+
/**
|
|
1686
|
+
* Memory data structure with fields that may be encrypted
|
|
1687
|
+
*/
|
|
1688
|
+
interface MemoryData {
|
|
1689
|
+
value?: string;
|
|
1690
|
+
rawEvidence?: string;
|
|
1691
|
+
key?: string;
|
|
1692
|
+
namespace?: string;
|
|
1693
|
+
[key: string]: unknown;
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Encrypt sensitive fields in a memory object.
|
|
1697
|
+
* Only encrypts the fields defined in ENCRYPTED_FIELDS.
|
|
1698
|
+
* Embeddings and other indexed fields are left unencrypted.
|
|
1699
|
+
*
|
|
1700
|
+
* @param memory - The memory object with plain text fields
|
|
1701
|
+
* @param address - The user's wallet address
|
|
1702
|
+
* @returns A new memory object with sensitive fields encrypted
|
|
1703
|
+
*/
|
|
1704
|
+
declare function encryptMemoryFields<T extends MemoryData>(memory: T, address: string): Promise<T>;
|
|
1705
|
+
/**
|
|
1706
|
+
* Decrypt sensitive fields in a memory object.
|
|
1707
|
+
* Only decrypts the fields defined in ENCRYPTED_FIELDS.
|
|
1708
|
+
* Automatically migrates old encrypted values to new format.
|
|
1709
|
+
* Also encrypts unencrypted fields when found (for users migrating to encryption).
|
|
1710
|
+
*
|
|
1711
|
+
* @param memory - The memory object with encrypted fields
|
|
1712
|
+
* @param address - The user's wallet address
|
|
1713
|
+
* @param signMessage - Optional function to sign message for migration (required if old encryption detected)
|
|
1714
|
+
* @param updateMemory - Optional function to update memory in storage after migration/encryption
|
|
1715
|
+
* @returns A new memory object with sensitive fields decrypted
|
|
1716
|
+
*/
|
|
1717
|
+
declare function decryptMemoryFields<T extends MemoryData>(memory: T, address: string, signMessage?: SignMessageFn, updateMemory?: (id: string, data: Partial<T>) => Promise<void>): Promise<T>;
|
|
1718
|
+
/**
|
|
1719
|
+
* Batch encrypt multiple memory objects.
|
|
1720
|
+
* Uses parallel processing for performance.
|
|
1721
|
+
*
|
|
1722
|
+
* @param memories - Array of memory objects
|
|
1723
|
+
* @param address - The user's wallet address
|
|
1724
|
+
* @returns Array of memory objects with encrypted fields
|
|
1725
|
+
*/
|
|
1726
|
+
declare function encryptMemoriesBatch<T extends MemoryData>(memories: T[], address: string): Promise<T[]>;
|
|
1727
|
+
/**
|
|
1728
|
+
* Batch decrypt multiple memory objects.
|
|
1729
|
+
* Uses parallel processing for performance.
|
|
1730
|
+
* Automatically migrates old encrypted values to new format.
|
|
1731
|
+
*
|
|
1732
|
+
* @param memories - Array of memory objects
|
|
1733
|
+
* @param address - The user's wallet address
|
|
1734
|
+
* @param signMessage - Optional function to sign message for migration (required if old encryption detected)
|
|
1735
|
+
* @param updateMemory - Optional function to update memory in storage after migration
|
|
1736
|
+
* @returns Array of memory objects with decrypted fields
|
|
1737
|
+
*/
|
|
1738
|
+
declare function decryptMemoriesBatch<T extends MemoryData>(memories: T[], address: string, signMessage?: SignMessageFn, updateMemory?: (id: string, data: Partial<T>) => Promise<void>): Promise<T[]>;
|
|
1739
|
+
/**
|
|
1740
|
+
* Check if a memory has any encrypted fields.
|
|
1741
|
+
* Useful for determining if migration is needed.
|
|
1742
|
+
*/
|
|
1743
|
+
declare function hasEncryptedFields(memory: MemoryData): boolean;
|
|
1744
|
+
/**
|
|
1745
|
+
* Check if a memory needs encryption (has unencrypted sensitive fields).
|
|
1746
|
+
*/
|
|
1747
|
+
declare function needsEncryption(memory: MemoryData): boolean;
|
|
1748
|
+
/**
|
|
1749
|
+
* Memory fields needed for encryption update
|
|
1750
|
+
*/
|
|
1751
|
+
interface MemoryEncryptionFields extends MemoryData {
|
|
1752
|
+
type: string;
|
|
1753
|
+
namespace: string;
|
|
1754
|
+
key: string;
|
|
1755
|
+
value: string;
|
|
1756
|
+
rawEvidence: string;
|
|
1757
|
+
confidence: number;
|
|
1758
|
+
pii: boolean;
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Memory object with the required fields for batch encryption
|
|
1762
|
+
*/
|
|
1763
|
+
interface MemoryForBatchEncryption {
|
|
1764
|
+
uniqueId: string;
|
|
1765
|
+
type: string;
|
|
1766
|
+
namespace: string;
|
|
1767
|
+
key: string;
|
|
1768
|
+
value: string;
|
|
1769
|
+
rawEvidence: string;
|
|
1770
|
+
confidence: number;
|
|
1771
|
+
pii: boolean;
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Encrypt a batch of memories in parallel with rate limiting and retry logic.
|
|
1775
|
+
* Tracks failed memories for error reporting.
|
|
1776
|
+
*
|
|
1777
|
+
* @param memories - Array of memories to encrypt
|
|
1778
|
+
* @param address - User's wallet address
|
|
1779
|
+
* @param updateFn - Function to update a memory in storage
|
|
1780
|
+
* @param batchSize - Number of memories to process in parallel (default: 5)
|
|
1781
|
+
* @returns Object with success count and failed memory IDs
|
|
1782
|
+
*/
|
|
1783
|
+
declare function encryptMemoriesBatchInPlace(memories: MemoryForBatchEncryption[], address: string, updateFn: (id: string, data: MemoryData) => Promise<unknown>, batchSize?: number): Promise<{
|
|
1784
|
+
success: number;
|
|
1785
|
+
failed: string[];
|
|
1786
|
+
errors: Array<{
|
|
1787
|
+
id: string;
|
|
1788
|
+
error: string;
|
|
1789
|
+
}>;
|
|
1790
|
+
}>;
|
|
1791
|
+
|
|
1792
|
+
declare const settingsStorageSchema: Readonly<{
|
|
1793
|
+
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
1794
|
+
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
1795
|
+
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
1796
|
+
}>;
|
|
1797
|
+
|
|
1798
|
+
declare class ModelPreference extends Model {
|
|
1799
|
+
static table: string;
|
|
1800
|
+
walletAddress: string;
|
|
1801
|
+
models?: string;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
interface StoredModelPreference {
|
|
1805
|
+
uniqueId: string;
|
|
1806
|
+
walletAddress: string;
|
|
1807
|
+
models?: string;
|
|
1808
|
+
}
|
|
1809
|
+
interface CreateModelPreferenceOptions {
|
|
1810
|
+
walletAddress: string;
|
|
1811
|
+
models?: string;
|
|
1812
|
+
}
|
|
1813
|
+
interface UpdateModelPreferenceOptions {
|
|
1814
|
+
models?: string;
|
|
1815
|
+
}
|
|
1816
|
+
interface BaseUseSettingsOptions {
|
|
1817
|
+
database: Database;
|
|
1818
|
+
walletAddress?: string;
|
|
1819
|
+
}
|
|
1820
|
+
interface BaseUseSettingsResult {
|
|
1821
|
+
modelPreference: StoredModelPreference | null;
|
|
1822
|
+
isLoading: boolean;
|
|
1823
|
+
getModelPreference: (walletAddress: string) => Promise<StoredModelPreference | null>;
|
|
1824
|
+
setModelPreference: (walletAddress: string, models?: string) => Promise<StoredModelPreference | null>;
|
|
1825
|
+
deleteModelPreference: (walletAddress: string) => Promise<boolean>;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
/**
|
|
1829
|
+
* Options for useSettings hook (React version)
|
|
1830
|
+
*/
|
|
1831
|
+
interface UseSettingsOptions extends BaseUseSettingsOptions {
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Result returned by useSettings hook (React version)
|
|
1835
|
+
*/
|
|
1836
|
+
interface UseSettingsResult extends BaseUseSettingsResult {
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* A React hook for managing user settings with automatic persistence using WatermelonDB.
|
|
1840
|
+
*
|
|
1841
|
+
* This hook provides methods to get, set, and delete user model preferences,
|
|
1842
|
+
* with automatic loading of preferences when a wallet address is provided.
|
|
1843
|
+
*
|
|
1844
|
+
* @param options - Configuration options
|
|
1845
|
+
* @returns An object containing settings state and methods
|
|
1846
|
+
*
|
|
1847
|
+
* @example
|
|
1848
|
+
* ```tsx
|
|
1849
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
1850
|
+
* import { useSettings } from '@reverbia/sdk/react';
|
|
1851
|
+
*
|
|
1852
|
+
* function SettingsComponent({ database }: { database: Database }) {
|
|
1853
|
+
* const {
|
|
1854
|
+
* modelPreference,
|
|
1855
|
+
* isLoading,
|
|
1856
|
+
* setModelPreference,
|
|
1857
|
+
* getModelPreference,
|
|
1858
|
+
* deleteModelPreference,
|
|
1859
|
+
* } = useSettings({
|
|
1860
|
+
* database,
|
|
1861
|
+
* walletAddress: '0x123...', // Optional: auto-loads preference for this wallet
|
|
1862
|
+
* });
|
|
1863
|
+
*
|
|
1864
|
+
* const handleModelChange = async (model: string) => {
|
|
1865
|
+
* await setModelPreference('0x123...', model);
|
|
1866
|
+
* };
|
|
1867
|
+
*
|
|
1868
|
+
* return (
|
|
1869
|
+
* <div>
|
|
1870
|
+
* <p>Current model: {modelPreference?.model ?? 'Not set'}</p>
|
|
1871
|
+
* <button onClick={() => handleModelChange('gpt-4o')}>
|
|
1872
|
+
* Use GPT-4o
|
|
1873
|
+
* </button>
|
|
1874
|
+
* </div>
|
|
1875
|
+
* );
|
|
1876
|
+
* }
|
|
1877
|
+
* ```
|
|
1878
|
+
*
|
|
1879
|
+
* @category Hooks
|
|
1880
|
+
*/
|
|
1881
|
+
declare function useSettings(options: UseSettingsOptions): UseSettingsResult;
|
|
1882
|
+
|
|
1883
|
+
interface PdfFile {
|
|
1884
|
+
url: string;
|
|
1885
|
+
mediaType?: string;
|
|
1886
|
+
filename?: string;
|
|
1887
|
+
}
|
|
1888
|
+
/**
|
|
1889
|
+
* React hook for extracting text from PDF files.
|
|
1890
|
+
* @category Hooks
|
|
1891
|
+
*/
|
|
1892
|
+
declare function usePdf(): {
|
|
1893
|
+
extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
|
|
1894
|
+
isProcessing: boolean;
|
|
1895
|
+
error: Error | null;
|
|
1896
|
+
};
|
|
1897
|
+
|
|
1898
|
+
interface OCRFile {
|
|
1899
|
+
url: string | File | Blob;
|
|
1900
|
+
filename?: string;
|
|
1901
|
+
language?: string;
|
|
1902
|
+
}
|
|
1903
|
+
/**
|
|
1904
|
+
* React hook for extracting text from images using OCR.
|
|
1905
|
+
* @category Hooks
|
|
1906
|
+
*/
|
|
1907
|
+
declare function useOCR(): {
|
|
1908
|
+
extractOCRContext: (files: OCRFile[]) => Promise<string | null>;
|
|
1909
|
+
isProcessing: boolean;
|
|
1910
|
+
error: Error | null;
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1913
|
+
type UseModelsOptions = {
|
|
1914
|
+
/**
|
|
1915
|
+
* Custom function to get auth token for API calls
|
|
1916
|
+
*/
|
|
1917
|
+
getToken?: () => Promise<string | null>;
|
|
1918
|
+
/**
|
|
1919
|
+
* Optional base URL for the API requests.
|
|
1920
|
+
*/
|
|
1921
|
+
baseUrl?: string;
|
|
1922
|
+
/**
|
|
1923
|
+
* Optional filter for specific provider (e.g. "openai")
|
|
1924
|
+
*/
|
|
1925
|
+
provider?: string;
|
|
1926
|
+
/**
|
|
1927
|
+
* Whether to fetch models automatically on mount (default: true)
|
|
1928
|
+
*/
|
|
1929
|
+
autoFetch?: boolean;
|
|
1930
|
+
};
|
|
1931
|
+
type UseModelsResult = {
|
|
1932
|
+
models: LlmapiModel[];
|
|
1933
|
+
isLoading: boolean;
|
|
1934
|
+
error: Error | null;
|
|
1935
|
+
refetch: () => Promise<void>;
|
|
1936
|
+
};
|
|
1937
|
+
/**
|
|
1938
|
+
* React hook for fetching available LLM models.
|
|
1939
|
+
* Automatically fetches all available models.
|
|
1940
|
+
* @category Hooks
|
|
1941
|
+
*/
|
|
1942
|
+
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
1943
|
+
|
|
1944
|
+
type UseSearchOptions = {
|
|
1945
|
+
/**
|
|
1946
|
+
* Custom function to get auth token for API calls
|
|
1947
|
+
*/
|
|
1948
|
+
getToken?: () => Promise<string | null>;
|
|
1949
|
+
/**
|
|
1950
|
+
* Optional base URL for the API requests.
|
|
1951
|
+
*/
|
|
1952
|
+
baseUrl?: string;
|
|
1953
|
+
/**
|
|
1954
|
+
* Callback function to be called when an error is encountered.
|
|
1955
|
+
*/
|
|
1956
|
+
onError?: (error: Error) => void;
|
|
1957
|
+
};
|
|
1958
|
+
type SearchOptions = {
|
|
1959
|
+
/**
|
|
1960
|
+
* Country code for search results (e.g., "us", "gb")
|
|
1961
|
+
*/
|
|
1962
|
+
country?: string;
|
|
1963
|
+
/**
|
|
1964
|
+
* Maximum number of results to return
|
|
1965
|
+
*/
|
|
1966
|
+
max_results?: number;
|
|
1967
|
+
/**
|
|
1968
|
+
* Maximum tokens per page
|
|
1969
|
+
*/
|
|
1970
|
+
max_tokens_per_page?: number;
|
|
1971
|
+
/**
|
|
1972
|
+
* List of domains to filter results (max 20 domains)
|
|
1973
|
+
*/
|
|
1974
|
+
search_domain_filter?: string[];
|
|
1975
|
+
/**
|
|
1976
|
+
* The search provider to use
|
|
1977
|
+
*/
|
|
1978
|
+
search_tool_name?: string;
|
|
1979
|
+
};
|
|
1980
|
+
type UseSearchResult = {
|
|
1981
|
+
isLoading: boolean;
|
|
1982
|
+
search: (query: string | string[], options?: SearchOptions) => Promise<LlmapiSearchResponse | null>;
|
|
1983
|
+
results: LlmapiSearchResult[] | null;
|
|
1984
|
+
response: LlmapiSearchResponse | null;
|
|
1985
|
+
error: Error | null;
|
|
1986
|
+
};
|
|
1987
|
+
/**
|
|
1988
|
+
* React hook for performing search operations using the AI SDK.
|
|
1989
|
+
*
|
|
1990
|
+
* @param options - Configuration options for the search hook
|
|
1991
|
+
* @returns Object containing search function, results, loading state, and error
|
|
1992
|
+
* @category Hooks
|
|
1993
|
+
*
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```tsx
|
|
1996
|
+
* const { search, results, isLoading } = useSearch({
|
|
1997
|
+
* getToken: async () => "my-token"
|
|
1998
|
+
* });
|
|
1999
|
+
*
|
|
2000
|
+
* const handleSearch = async () => {
|
|
2001
|
+
* await search("What is ZetaChain?");
|
|
2002
|
+
* };
|
|
2003
|
+
* ```
|
|
2004
|
+
*/
|
|
2005
|
+
declare function useSearch(options?: UseSearchOptions): UseSearchResult;
|
|
2006
|
+
|
|
2007
|
+
type UseImageGenerationOptions = {
|
|
2008
|
+
/**
|
|
2009
|
+
* Custom function to get auth token for API calls
|
|
2010
|
+
*/
|
|
2011
|
+
getToken?: () => Promise<string | null>;
|
|
2012
|
+
/**
|
|
2013
|
+
* Optional base URL for the API requests.
|
|
2014
|
+
*/
|
|
2015
|
+
baseUrl?: string;
|
|
2016
|
+
/**
|
|
2017
|
+
* Callback function to be called when the generation finishes successfully.
|
|
2018
|
+
*/
|
|
2019
|
+
onFinish?: (response: LlmapiImageGenerationResponse) => void;
|
|
2020
|
+
/**
|
|
2021
|
+
* Callback function to be called when an unexpected error is encountered.
|
|
2022
|
+
*/
|
|
2023
|
+
onError?: (error: Error) => void;
|
|
2024
|
+
};
|
|
2025
|
+
type GenerateImageArgs = LlmapiImageGenerationRequest;
|
|
2026
|
+
type GenerateImageResult = {
|
|
2027
|
+
data: LlmapiImageGenerationResponse;
|
|
2028
|
+
error: null;
|
|
2029
|
+
} | {
|
|
2030
|
+
data: null;
|
|
2031
|
+
error: string;
|
|
2032
|
+
};
|
|
2033
|
+
type UseImageGenerationResult = {
|
|
2034
|
+
isLoading: boolean;
|
|
2035
|
+
generateImage: (args: GenerateImageArgs) => Promise<GenerateImageResult>;
|
|
2036
|
+
stop: () => void;
|
|
2037
|
+
};
|
|
2038
|
+
/**
|
|
2039
|
+
* React hook for generating images using the LLM API.
|
|
2040
|
+
* @category Hooks
|
|
2041
|
+
*/
|
|
2042
|
+
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
2043
|
+
|
|
2044
|
+
/**
|
|
2045
|
+
* Format memories into a context string that can be included in chat messages
|
|
2046
|
+
* @param memories Array of memories with similarity scores
|
|
2047
|
+
* @param format Format style: "compact" (key-value pairs) or "detailed" (includes evidence)
|
|
2048
|
+
* @returns Formatted string ready to include in system/user message
|
|
2049
|
+
*/
|
|
2050
|
+
declare const formatMemoriesForChat: (memories: Array<StoredMemory & {
|
|
2051
|
+
similarity?: number;
|
|
2052
|
+
}>, format?: "compact" | "detailed") => string;
|
|
2053
|
+
/**
|
|
2054
|
+
* Create a system message that includes relevant memories
|
|
2055
|
+
* @param memories Array of memories to include
|
|
2056
|
+
* @param baseSystemPrompt Optional base system prompt (memories will be prepended)
|
|
2057
|
+
* @returns System message content with memories
|
|
2058
|
+
*/
|
|
2059
|
+
declare const createMemoryContextSystemMessage: (memories: Array<StoredMemory & {
|
|
2060
|
+
similarity?: number;
|
|
2061
|
+
}>, baseSystemPrompt?: string) => string;
|
|
2062
|
+
/**
|
|
2063
|
+
* Extract conversation context from messages for memory search
|
|
2064
|
+
* @param messages Array of chat messages
|
|
2065
|
+
* @param maxMessages Maximum number of recent messages to include (default: 3)
|
|
2066
|
+
* @returns Combined text query for memory search
|
|
2067
|
+
*/
|
|
2068
|
+
declare const extractConversationContext: (messages: Array<{
|
|
2069
|
+
role: string;
|
|
2070
|
+
content: string;
|
|
2071
|
+
}>, maxMessages?: number) => string;
|
|
2072
|
+
|
|
2073
|
+
/**
|
|
2074
|
+
* Dropbox API utilities
|
|
2075
|
+
*
|
|
2076
|
+
* Uses Dropbox HTTP API for file operations.
|
|
2077
|
+
* Dropbox uses OAuth 2.0 with PKCE for browser apps.
|
|
2078
|
+
*/
|
|
2079
|
+
/** Default folder path for Dropbox backups */
|
|
2080
|
+
declare const DEFAULT_BACKUP_FOLDER$1 = "/ai-chat-app/conversations";
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* Dropbox Backup Implementation
|
|
2084
|
+
*
|
|
2085
|
+
* Generic backup/restore functionality for Dropbox storage.
|
|
2086
|
+
* Works directly with WatermelonDB database.
|
|
2087
|
+
*/
|
|
2088
|
+
|
|
2089
|
+
interface DropboxExportResult {
|
|
2090
|
+
success: boolean;
|
|
2091
|
+
uploaded: number;
|
|
2092
|
+
skipped: number;
|
|
2093
|
+
total: number;
|
|
2094
|
+
}
|
|
2095
|
+
interface DropboxImportResult {
|
|
2096
|
+
success: boolean;
|
|
2097
|
+
restored: number;
|
|
2098
|
+
failed: number;
|
|
2099
|
+
total: number;
|
|
2100
|
+
/** True if no backups were found in Dropbox */
|
|
2101
|
+
noBackupsFound?: boolean;
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
/**
|
|
2105
|
+
* Options for useDropboxBackup hook
|
|
2106
|
+
*/
|
|
2107
|
+
interface UseDropboxBackupOptions {
|
|
2108
|
+
/** WatermelonDB database instance */
|
|
2109
|
+
database: Database;
|
|
2110
|
+
/** Current user address (null if not signed in) */
|
|
2111
|
+
userAddress: string | null;
|
|
2112
|
+
/** Request encryption key for the user address */
|
|
2113
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
2114
|
+
/** Export a conversation to an encrypted blob */
|
|
2115
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
2116
|
+
success: boolean;
|
|
2117
|
+
blob?: Blob;
|
|
2118
|
+
}>;
|
|
2119
|
+
/** Import a conversation from an encrypted blob */
|
|
2120
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
2121
|
+
success: boolean;
|
|
2122
|
+
}>;
|
|
2123
|
+
/** Dropbox folder path for backups (default: '/ai-chat-app/conversations') */
|
|
2124
|
+
backupFolder?: string;
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Result returned by useDropboxBackup hook
|
|
2128
|
+
*/
|
|
2129
|
+
interface UseDropboxBackupResult {
|
|
2130
|
+
/** Backup all conversations to Dropbox */
|
|
2131
|
+
backup: (options?: {
|
|
2132
|
+
onProgress?: (current: number, total: number) => void;
|
|
2133
|
+
}) => Promise<DropboxExportResult | {
|
|
2134
|
+
error: string;
|
|
2135
|
+
}>;
|
|
2136
|
+
/** Restore conversations from Dropbox */
|
|
2137
|
+
restore: (options?: {
|
|
2138
|
+
onProgress?: (current: number, total: number) => void;
|
|
2139
|
+
}) => Promise<DropboxImportResult | {
|
|
2140
|
+
error: string;
|
|
2141
|
+
}>;
|
|
2142
|
+
/** Whether Dropbox is configured */
|
|
2143
|
+
isConfigured: boolean;
|
|
2144
|
+
/** Whether user has a Dropbox token */
|
|
2145
|
+
isAuthenticated: boolean;
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* React hook for Dropbox backup and restore functionality.
|
|
2149
|
+
*
|
|
2150
|
+
* This hook provides methods to backup conversations to Dropbox and restore them.
|
|
2151
|
+
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
2152
|
+
* authentication, and managing the backup/restore process.
|
|
2153
|
+
*
|
|
2154
|
+
* Must be used within a DropboxAuthProvider.
|
|
2155
|
+
*
|
|
2156
|
+
* @example
|
|
2157
|
+
* ```tsx
|
|
2158
|
+
* import { useDropboxBackup } from "@reverbia/sdk/react";
|
|
2159
|
+
*
|
|
2160
|
+
* function BackupButton() {
|
|
2161
|
+
* const { backup, restore, isConfigured } = useDropboxBackup({
|
|
2162
|
+
* database,
|
|
2163
|
+
* userAddress,
|
|
2164
|
+
* requestEncryptionKey,
|
|
2165
|
+
* exportConversation,
|
|
2166
|
+
* importConversation,
|
|
2167
|
+
* });
|
|
2168
|
+
*
|
|
2169
|
+
* const handleBackup = async () => {
|
|
2170
|
+
* const result = await backup({
|
|
2171
|
+
* onProgress: (current, total) => {
|
|
2172
|
+
* console.log(`Progress: ${current}/${total}`);
|
|
2173
|
+
* },
|
|
2174
|
+
* });
|
|
2175
|
+
*
|
|
2176
|
+
* if ("error" in result) {
|
|
2177
|
+
* console.error(result.error);
|
|
2178
|
+
* } else {
|
|
2179
|
+
* console.log(`Uploaded: ${result.uploaded}, Skipped: ${result.skipped}`);
|
|
2180
|
+
* }
|
|
2181
|
+
* };
|
|
2182
|
+
*
|
|
2183
|
+
* return <button onClick={handleBackup} disabled={!isConfigured}>Backup</button>;
|
|
2184
|
+
* }
|
|
2185
|
+
* ```
|
|
2186
|
+
*
|
|
2187
|
+
* @category Hooks
|
|
2188
|
+
*/
|
|
2189
|
+
declare function useDropboxBackup(options: UseDropboxBackupOptions): UseDropboxBackupResult;
|
|
2190
|
+
|
|
2191
|
+
/**
|
|
2192
|
+
* Dropbox OAuth 2.0 Authorization Code Flow
|
|
2193
|
+
*
|
|
2194
|
+
* Flow:
|
|
2195
|
+
* 1. Redirect user to Dropbox authorization URL
|
|
2196
|
+
* 2. User authorizes and is redirected back with authorization code
|
|
2197
|
+
* 3. Exchange code on backend for access + refresh tokens
|
|
2198
|
+
* 4. Use refresh token to get new access tokens silently
|
|
2199
|
+
*/
|
|
2200
|
+
|
|
2201
|
+
/**
|
|
2202
|
+
* Clear Dropbox token data
|
|
2203
|
+
*/
|
|
2204
|
+
declare function clearToken(): void;
|
|
2205
|
+
/**
|
|
2206
|
+
* Check if we have any stored credentials (including refresh token)
|
|
2207
|
+
* Works with both encrypted and unencrypted credentials
|
|
2208
|
+
*/
|
|
2209
|
+
declare function hasDropboxCredentials(): boolean;
|
|
2210
|
+
|
|
2211
|
+
/**
|
|
2212
|
+
* Props for DropboxAuthProvider
|
|
2213
|
+
*/
|
|
2214
|
+
interface DropboxAuthProviderProps {
|
|
2215
|
+
/** Dropbox App Key (from Dropbox Developer Console) */
|
|
2216
|
+
appKey: string | undefined;
|
|
2217
|
+
/** OAuth callback path (default: "/auth/dropbox/callback") */
|
|
2218
|
+
callbackPath?: string;
|
|
2219
|
+
/**
|
|
2220
|
+
* API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
|
|
2221
|
+
* Only needed if you have a custom client configuration (e.g., different baseUrl).
|
|
2222
|
+
*/
|
|
2223
|
+
apiClient?: Client;
|
|
2224
|
+
/** Children to render */
|
|
2225
|
+
children: ReactNode;
|
|
2226
|
+
}
|
|
2227
|
+
/**
|
|
2228
|
+
* Context value for Dropbox authentication
|
|
2229
|
+
*/
|
|
2230
|
+
interface DropboxAuthContextValue {
|
|
2231
|
+
/** Current access token (null if not authenticated) */
|
|
2232
|
+
accessToken: string | null;
|
|
2233
|
+
/** Whether user has authenticated with Dropbox */
|
|
2234
|
+
isAuthenticated: boolean;
|
|
2235
|
+
/** Whether Dropbox is configured (app key exists) */
|
|
2236
|
+
isConfigured: boolean;
|
|
2237
|
+
/** Request Dropbox access - returns token or redirects to OAuth */
|
|
2238
|
+
requestAccess: () => Promise<string>;
|
|
2239
|
+
/** Clear stored token and log out */
|
|
2240
|
+
logout: () => Promise<void>;
|
|
2241
|
+
/** Refresh the access token using the refresh token */
|
|
2242
|
+
refreshToken: () => Promise<string | null>;
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Provider component for Dropbox OAuth authentication.
|
|
2246
|
+
*
|
|
2247
|
+
* Wrap your app with this provider to enable Dropbox authentication.
|
|
2248
|
+
* It handles the OAuth 2.0 Authorization Code flow with refresh tokens.
|
|
2249
|
+
*
|
|
2250
|
+
* @example
|
|
2251
|
+
* ```tsx
|
|
2252
|
+
* import { DropboxAuthProvider } from "@reverbia/sdk/react";
|
|
2253
|
+
*
|
|
2254
|
+
* function App() {
|
|
2255
|
+
* return (
|
|
2256
|
+
* <DropboxAuthProvider
|
|
2257
|
+
* appKey={process.env.NEXT_PUBLIC_DROPBOX_APP_KEY}
|
|
2258
|
+
* callbackPath="/auth/dropbox/callback"
|
|
2259
|
+
* >
|
|
2260
|
+
* <MyApp />
|
|
2261
|
+
* </DropboxAuthProvider>
|
|
2262
|
+
* );
|
|
2263
|
+
* }
|
|
2264
|
+
* ```
|
|
2265
|
+
*
|
|
2266
|
+
* @category Components
|
|
2267
|
+
*/
|
|
2268
|
+
declare function DropboxAuthProvider({ appKey, callbackPath, apiClient, children, }: DropboxAuthProviderProps): JSX.Element;
|
|
2269
|
+
/**
|
|
2270
|
+
* Hook to access Dropbox authentication state and methods.
|
|
2271
|
+
*
|
|
2272
|
+
* Must be used within a DropboxAuthProvider.
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* ```tsx
|
|
2276
|
+
* import { useDropboxAuth } from "@reverbia/sdk/react";
|
|
2277
|
+
*
|
|
2278
|
+
* function DropboxButton() {
|
|
2279
|
+
* const { isAuthenticated, isConfigured, requestAccess, logout } = useDropboxAuth();
|
|
2280
|
+
*
|
|
2281
|
+
* if (!isConfigured) {
|
|
2282
|
+
* return <p>Dropbox not configured</p>;
|
|
2283
|
+
* }
|
|
2284
|
+
*
|
|
2285
|
+
* if (isAuthenticated) {
|
|
2286
|
+
* return <button onClick={logout}>Disconnect Dropbox</button>;
|
|
2287
|
+
* }
|
|
2288
|
+
*
|
|
2289
|
+
* return <button onClick={requestAccess}>Connect Dropbox</button>;
|
|
2290
|
+
* }
|
|
2291
|
+
* ```
|
|
2292
|
+
*
|
|
2293
|
+
* @category Hooks
|
|
2294
|
+
*/
|
|
2295
|
+
declare function useDropboxAuth(): DropboxAuthContextValue;
|
|
2296
|
+
|
|
2297
|
+
/**
|
|
2298
|
+
* Google Drive OAuth 2.0 Authorization Code Flow
|
|
2299
|
+
*
|
|
2300
|
+
* Flow:
|
|
2301
|
+
* 1. Redirect user to Google authorization URL
|
|
2302
|
+
* 2. User authorizes and is redirected back with authorization code
|
|
2303
|
+
* 3. Exchange code on backend for access + refresh tokens
|
|
2304
|
+
* 4. Use refresh token to get new access tokens silently
|
|
2305
|
+
*/
|
|
2306
|
+
|
|
2307
|
+
/**
|
|
2308
|
+
* Get stored token data for Google Drive
|
|
2309
|
+
*/
|
|
2310
|
+
declare function getGoogleDriveStoredToken(): string | null;
|
|
2311
|
+
/**
|
|
2312
|
+
* Clear Google Drive token data
|
|
2313
|
+
*/
|
|
2314
|
+
declare function clearGoogleDriveToken(): void;
|
|
2315
|
+
/**
|
|
2316
|
+
* Check if we have any stored credentials (including refresh token)
|
|
2317
|
+
* Works with both encrypted and unencrypted credentials
|
|
2318
|
+
*/
|
|
2319
|
+
declare function hasGoogleDriveCredentials(): boolean;
|
|
2320
|
+
|
|
2321
|
+
/**
|
|
2322
|
+
* Props for GoogleDriveAuthProvider
|
|
2323
|
+
*/
|
|
2324
|
+
interface GoogleDriveAuthProviderProps {
|
|
2325
|
+
/** Google OAuth Client ID (from Google Cloud Console) */
|
|
2326
|
+
clientId: string | undefined;
|
|
2327
|
+
/** OAuth callback path (default: "/auth/google/callback") */
|
|
2328
|
+
callbackPath?: string;
|
|
2329
|
+
/**
|
|
2330
|
+
* API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
|
|
2331
|
+
* Only needed if you have a custom client configuration (e.g., different baseUrl).
|
|
2332
|
+
*/
|
|
2333
|
+
apiClient?: Client;
|
|
2334
|
+
/** Children to render */
|
|
2335
|
+
children: ReactNode;
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* Context value for Google Drive authentication
|
|
2339
|
+
*/
|
|
2340
|
+
interface GoogleDriveAuthContextValue {
|
|
2341
|
+
/** Current access token (null if not authenticated) */
|
|
2342
|
+
accessToken: string | null;
|
|
2343
|
+
/** Whether user has authenticated with Google Drive */
|
|
2344
|
+
isAuthenticated: boolean;
|
|
2345
|
+
/** Whether Google Drive is configured (client ID exists) */
|
|
2346
|
+
isConfigured: boolean;
|
|
2347
|
+
/** Request Google Drive access - returns token or redirects to OAuth */
|
|
2348
|
+
requestAccess: () => Promise<string>;
|
|
2349
|
+
/** Clear stored token and log out */
|
|
2350
|
+
logout: () => Promise<void>;
|
|
2351
|
+
/** Refresh the access token using the refresh token */
|
|
2352
|
+
refreshToken: () => Promise<string | null>;
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* Provider component for Google Drive OAuth authentication.
|
|
2356
|
+
*
|
|
2357
|
+
* Wrap your app with this provider to enable Google Drive authentication.
|
|
2358
|
+
* It handles the OAuth 2.0 Authorization Code flow with refresh tokens.
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
2361
|
+
* ```tsx
|
|
2362
|
+
* import { GoogleDriveAuthProvider } from "@reverbia/sdk/react";
|
|
2363
|
+
*
|
|
2364
|
+
* function App() {
|
|
2365
|
+
* return (
|
|
2366
|
+
* <GoogleDriveAuthProvider
|
|
2367
|
+
* clientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
|
|
2368
|
+
* callbackPath="/auth/google/callback"
|
|
2369
|
+
* >
|
|
2370
|
+
* <MyApp />
|
|
2371
|
+
* </GoogleDriveAuthProvider>
|
|
2372
|
+
* );
|
|
2373
|
+
* }
|
|
2374
|
+
* ```
|
|
2375
|
+
*
|
|
2376
|
+
* @category Components
|
|
2377
|
+
*/
|
|
2378
|
+
declare function GoogleDriveAuthProvider({ clientId, callbackPath, apiClient, children, }: GoogleDriveAuthProviderProps): JSX.Element;
|
|
2379
|
+
/**
|
|
2380
|
+
* Hook to access Google Drive authentication state and methods.
|
|
2381
|
+
*
|
|
2382
|
+
* Must be used within a GoogleDriveAuthProvider.
|
|
2383
|
+
*
|
|
2384
|
+
* @example
|
|
2385
|
+
* ```tsx
|
|
2386
|
+
* import { useGoogleDriveAuth } from "@reverbia/sdk/react";
|
|
2387
|
+
*
|
|
2388
|
+
* function GoogleDriveButton() {
|
|
2389
|
+
* const { isAuthenticated, isConfigured, requestAccess, logout } = useGoogleDriveAuth();
|
|
2390
|
+
*
|
|
2391
|
+
* if (!isConfigured) {
|
|
2392
|
+
* return <p>Google Drive not configured</p>;
|
|
2393
|
+
* }
|
|
2394
|
+
*
|
|
2395
|
+
* if (isAuthenticated) {
|
|
2396
|
+
* return <button onClick={logout}>Disconnect Google Drive</button>;
|
|
2397
|
+
* }
|
|
2398
|
+
*
|
|
2399
|
+
* return <button onClick={requestAccess}>Connect Google Drive</button>;
|
|
2400
|
+
* }
|
|
2401
|
+
* ```
|
|
2402
|
+
*
|
|
2403
|
+
* @category Hooks
|
|
2404
|
+
*/
|
|
2405
|
+
declare function useGoogleDriveAuth(): GoogleDriveAuthContextValue;
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* Google Drive API utilities
|
|
2409
|
+
*
|
|
2410
|
+
* Uses Google Drive API v3 for file operations.
|
|
2411
|
+
* Requires an OAuth 2.0 access token with drive.file scope.
|
|
2412
|
+
*/
|
|
2413
|
+
/** Default root folder name for backups */
|
|
2414
|
+
declare const DEFAULT_ROOT_FOLDER = "ai-chat-app";
|
|
2415
|
+
/** Default subfolder for conversation backups */
|
|
2416
|
+
declare const DEFAULT_CONVERSATIONS_FOLDER = "conversations";
|
|
2417
|
+
|
|
2418
|
+
/**
|
|
2419
|
+
* Google Drive Backup Implementation
|
|
2420
|
+
*
|
|
2421
|
+
* Generic backup/restore functionality for Google Drive storage.
|
|
2422
|
+
* Works directly with WatermelonDB database.
|
|
2423
|
+
*/
|
|
2424
|
+
|
|
2425
|
+
interface GoogleDriveExportResult {
|
|
2426
|
+
success: boolean;
|
|
2427
|
+
uploaded: number;
|
|
2428
|
+
skipped: number;
|
|
2429
|
+
total: number;
|
|
2430
|
+
}
|
|
2431
|
+
interface GoogleDriveImportResult {
|
|
2432
|
+
success: boolean;
|
|
2433
|
+
restored: number;
|
|
2434
|
+
failed: number;
|
|
2435
|
+
total: number;
|
|
2436
|
+
/** True if no backups were found in Google Drive */
|
|
2437
|
+
noBackupsFound?: boolean;
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
/**
|
|
2441
|
+
* Options for useGoogleDriveBackup hook
|
|
2442
|
+
*/
|
|
2443
|
+
interface UseGoogleDriveBackupOptions {
|
|
2444
|
+
/** WatermelonDB database instance */
|
|
2445
|
+
database: Database;
|
|
2446
|
+
/** Current user address (null if not signed in) */
|
|
2447
|
+
userAddress: string | null;
|
|
2448
|
+
/** Request encryption key for the user address */
|
|
2449
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
2450
|
+
/** Export a conversation to an encrypted blob */
|
|
2451
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
2452
|
+
success: boolean;
|
|
2453
|
+
blob?: Blob;
|
|
2454
|
+
}>;
|
|
2455
|
+
/** Import a conversation from an encrypted blob */
|
|
2456
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
2457
|
+
success: boolean;
|
|
2458
|
+
}>;
|
|
2459
|
+
/** Root folder name in Google Drive (default: 'ai-chat-app') */
|
|
2460
|
+
rootFolder?: string;
|
|
2461
|
+
/** Subfolder for conversations (default: 'conversations') */
|
|
2462
|
+
conversationsFolder?: string;
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Result returned by useGoogleDriveBackup hook
|
|
2466
|
+
*/
|
|
2467
|
+
interface UseGoogleDriveBackupResult {
|
|
2468
|
+
/** Backup all conversations to Google Drive */
|
|
2469
|
+
backup: (options?: {
|
|
2470
|
+
onProgress?: (current: number, total: number) => void;
|
|
2471
|
+
}) => Promise<GoogleDriveExportResult | {
|
|
2472
|
+
error: string;
|
|
2473
|
+
}>;
|
|
2474
|
+
/** Restore conversations from Google Drive */
|
|
2475
|
+
restore: (options?: {
|
|
2476
|
+
onProgress?: (current: number, total: number) => void;
|
|
2477
|
+
}) => Promise<GoogleDriveImportResult | {
|
|
2478
|
+
error: string;
|
|
2479
|
+
}>;
|
|
2480
|
+
/** Whether Google Drive is configured */
|
|
2481
|
+
isConfigured: boolean;
|
|
2482
|
+
/** Whether user has a Google Drive token */
|
|
2483
|
+
isAuthenticated: boolean;
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* React hook for Google Drive backup and restore functionality.
|
|
2487
|
+
*
|
|
2488
|
+
* This hook provides methods to backup conversations to Google Drive and restore them.
|
|
2489
|
+
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
2490
|
+
* authentication, and managing the backup/restore process.
|
|
2491
|
+
*
|
|
2492
|
+
* Must be used within a GoogleDriveAuthProvider.
|
|
2493
|
+
*
|
|
2494
|
+
* @example
|
|
2495
|
+
* ```tsx
|
|
2496
|
+
* import { useGoogleDriveBackup } from "@reverbia/sdk/react";
|
|
2497
|
+
*
|
|
2498
|
+
* function BackupButton() {
|
|
2499
|
+
* const { backup, restore, isConfigured, isAuthenticated } = useGoogleDriveBackup({
|
|
2500
|
+
* database,
|
|
2501
|
+
* userAddress,
|
|
2502
|
+
* requestEncryptionKey,
|
|
2503
|
+
* exportConversation,
|
|
2504
|
+
* importConversation,
|
|
2505
|
+
* });
|
|
2506
|
+
*
|
|
2507
|
+
* const handleBackup = async () => {
|
|
2508
|
+
* const result = await backup({
|
|
2509
|
+
* onProgress: (current, total) => {
|
|
2510
|
+
* console.log(`Progress: ${current}/${total}`);
|
|
2511
|
+
* },
|
|
2512
|
+
* });
|
|
2513
|
+
*
|
|
2514
|
+
* if ("error" in result) {
|
|
2515
|
+
* console.error(result.error);
|
|
2516
|
+
* } else {
|
|
2517
|
+
* console.log(`Uploaded: ${result.uploaded}, Skipped: ${result.skipped}`);
|
|
2518
|
+
* }
|
|
2519
|
+
* };
|
|
2520
|
+
*
|
|
2521
|
+
* return <button onClick={handleBackup} disabled={!isConfigured}>Backup</button>;
|
|
2522
|
+
* }
|
|
2523
|
+
* ```
|
|
2524
|
+
*
|
|
2525
|
+
* @category Hooks
|
|
2526
|
+
*/
|
|
2527
|
+
declare function useGoogleDriveBackup(options: UseGoogleDriveBackupOptions): UseGoogleDriveBackupResult;
|
|
2528
|
+
|
|
2529
|
+
/**
|
|
2530
|
+
* Props for ICloudAuthProvider
|
|
2531
|
+
*/
|
|
2532
|
+
interface ICloudAuthProviderProps {
|
|
2533
|
+
/** CloudKit API token (from Apple Developer Console) */
|
|
2534
|
+
apiToken: string;
|
|
2535
|
+
/** CloudKit container identifier (default: "iCloud.Memoryless") */
|
|
2536
|
+
containerIdentifier?: string;
|
|
2537
|
+
/** CloudKit environment (default: "production") */
|
|
2538
|
+
environment?: "development" | "production";
|
|
2539
|
+
/** Children to render */
|
|
2540
|
+
children: ReactNode;
|
|
2541
|
+
}
|
|
2542
|
+
/**
|
|
2543
|
+
* Context value for iCloud authentication
|
|
2544
|
+
*/
|
|
2545
|
+
interface ICloudAuthContextValue {
|
|
2546
|
+
/** Whether user is authenticated with iCloud */
|
|
2547
|
+
isAuthenticated: boolean;
|
|
2548
|
+
/** Whether iCloud is configured and available */
|
|
2549
|
+
isConfigured: boolean;
|
|
2550
|
+
/** Whether CloudKit JS is loaded */
|
|
2551
|
+
isAvailable: boolean;
|
|
2552
|
+
/** User record name (unique identifier) */
|
|
2553
|
+
userRecordName: string | null;
|
|
2554
|
+
/** Request access - triggers iCloud sign-in if needed */
|
|
2555
|
+
requestAccess: () => Promise<void>;
|
|
2556
|
+
/** Sign out from iCloud */
|
|
2557
|
+
logout: () => void;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Provider component for iCloud authentication.
|
|
2561
|
+
*
|
|
2562
|
+
* Wrap your app with this provider to enable iCloud authentication.
|
|
2563
|
+
* CloudKit JS is loaded automatically when needed.
|
|
2564
|
+
*
|
|
2565
|
+
* @example
|
|
2566
|
+
* ```tsx
|
|
2567
|
+
* import { ICloudAuthProvider } from "@reverbia/sdk/react";
|
|
2568
|
+
*
|
|
2569
|
+
* function App() {
|
|
2570
|
+
* return (
|
|
2571
|
+
* <ICloudAuthProvider
|
|
2572
|
+
* apiToken={process.env.NEXT_PUBLIC_CLOUDKIT_API_TOKEN!}
|
|
2573
|
+
* containerIdentifier="iCloud.Memoryless"
|
|
2574
|
+
* environment="production"
|
|
2575
|
+
* >
|
|
2576
|
+
* <MyApp />
|
|
2577
|
+
* </ICloudAuthProvider>
|
|
2578
|
+
* );
|
|
2579
|
+
* }
|
|
2580
|
+
* ```
|
|
2581
|
+
*
|
|
2582
|
+
* @category Components
|
|
2583
|
+
*/
|
|
2584
|
+
declare function ICloudAuthProvider({ apiToken, containerIdentifier, environment, children, }: ICloudAuthProviderProps): JSX.Element;
|
|
2585
|
+
/**
|
|
2586
|
+
* Hook to access iCloud authentication state and methods.
|
|
2587
|
+
*
|
|
2588
|
+
* Must be used within an ICloudAuthProvider.
|
|
2589
|
+
*
|
|
2590
|
+
* @example
|
|
2591
|
+
* ```tsx
|
|
2592
|
+
* import { useICloudAuth } from "@reverbia/sdk/react";
|
|
2593
|
+
*
|
|
2594
|
+
* function ICloudStatus() {
|
|
2595
|
+
* const { isAuthenticated, isAvailable, requestAccess, logout } = useICloudAuth();
|
|
2596
|
+
*
|
|
2597
|
+
* if (!isAvailable) {
|
|
2598
|
+
* return <p>iCloud is not available. Please load CloudKit JS.</p>;
|
|
2599
|
+
* }
|
|
2600
|
+
*
|
|
2601
|
+
* return (
|
|
2602
|
+
* <div>
|
|
2603
|
+
* {isAuthenticated ? (
|
|
2604
|
+
* <>
|
|
2605
|
+
* <span>Connected to iCloud</span>
|
|
2606
|
+
* <button onClick={logout}>Disconnect</button>
|
|
2607
|
+
* </>
|
|
2608
|
+
* ) : (
|
|
2609
|
+
* <button onClick={requestAccess}>Connect to iCloud</button>
|
|
2610
|
+
* )}
|
|
2611
|
+
* </div>
|
|
2612
|
+
* );
|
|
2613
|
+
* }
|
|
2614
|
+
* ```
|
|
2615
|
+
*
|
|
2616
|
+
* @category Hooks
|
|
2617
|
+
*/
|
|
2618
|
+
declare function useICloudAuth(): ICloudAuthContextValue;
|
|
2619
|
+
/**
|
|
2620
|
+
* Check if iCloud is configured (has API token)
|
|
2621
|
+
*/
|
|
2622
|
+
declare function hasICloudCredentials(): boolean;
|
|
2623
|
+
/**
|
|
2624
|
+
* Clear iCloud authentication state
|
|
2625
|
+
* Note: This only clears local state; user remains signed in to iCloud
|
|
2626
|
+
*/
|
|
2627
|
+
declare function clearICloudAuth(): void;
|
|
2628
|
+
|
|
2629
|
+
/**
|
|
2630
|
+
* iCloud CloudKit API utilities
|
|
2631
|
+
*
|
|
2632
|
+
* Uses Apple CloudKit JS for file operations in iCloud Drive.
|
|
2633
|
+
* Requires CloudKit container configuration and user authentication.
|
|
2634
|
+
*
|
|
2635
|
+
* CloudKit JS is loaded dynamically when needed.
|
|
2636
|
+
*/
|
|
2637
|
+
/** Default folder path for iCloud backups */
|
|
2638
|
+
declare const DEFAULT_BACKUP_FOLDER = "conversations";
|
|
2639
|
+
/** CloudKit record structure */
|
|
2640
|
+
interface CloudKitRecord {
|
|
2641
|
+
recordName: string;
|
|
2642
|
+
recordType: string;
|
|
2643
|
+
fields: {
|
|
2644
|
+
filename?: {
|
|
2645
|
+
value: string;
|
|
2646
|
+
};
|
|
2647
|
+
data?: {
|
|
2648
|
+
value: {
|
|
2649
|
+
downloadURL: string;
|
|
2650
|
+
size: number;
|
|
2651
|
+
};
|
|
2652
|
+
};
|
|
2653
|
+
};
|
|
2654
|
+
modified?: {
|
|
2655
|
+
timestamp: number;
|
|
2656
|
+
};
|
|
2657
|
+
created?: {
|
|
2658
|
+
timestamp: number;
|
|
2659
|
+
};
|
|
2660
|
+
}
|
|
2661
|
+
/** CloudKit response structure */
|
|
2662
|
+
interface CloudKitResponse {
|
|
2663
|
+
records?: CloudKitRecord[];
|
|
2664
|
+
continuationMarker?: string;
|
|
2665
|
+
}
|
|
2666
|
+
declare global {
|
|
2667
|
+
interface Window {
|
|
2668
|
+
CloudKit?: {
|
|
2669
|
+
configure: (config: {
|
|
2670
|
+
containers: Array<{
|
|
2671
|
+
containerIdentifier: string;
|
|
2672
|
+
apiTokenAuth: {
|
|
2673
|
+
apiToken: string;
|
|
2674
|
+
persist: boolean;
|
|
2675
|
+
signInButton?: {
|
|
2676
|
+
id: string;
|
|
2677
|
+
theme?: string;
|
|
2678
|
+
};
|
|
2679
|
+
signOutButton?: {
|
|
2680
|
+
id: string;
|
|
2681
|
+
theme?: string;
|
|
2682
|
+
};
|
|
2683
|
+
};
|
|
2684
|
+
environment: string;
|
|
2685
|
+
}>;
|
|
2686
|
+
}) => void;
|
|
2687
|
+
getDefaultContainer: () => CloudKitContainer;
|
|
2688
|
+
};
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
interface CloudKitContainer {
|
|
2692
|
+
containerIdentifier: string;
|
|
2693
|
+
setUpAuth: (options?: {
|
|
2694
|
+
buttonContainer?: HTMLElement;
|
|
2695
|
+
signInButtonId?: string;
|
|
2696
|
+
signOutButtonId?: string;
|
|
2697
|
+
}) => Promise<CloudKitUserIdentity | null>;
|
|
2698
|
+
whenUserSignsIn: () => Promise<CloudKitUserIdentity>;
|
|
2699
|
+
whenUserSignsOut: () => Promise<void>;
|
|
2700
|
+
privateCloudDatabase: CloudKitDatabase;
|
|
2701
|
+
}
|
|
2702
|
+
interface CloudKitUserIdentity {
|
|
2703
|
+
userRecordName: string;
|
|
2704
|
+
isDiscoverable?: boolean;
|
|
2705
|
+
}
|
|
2706
|
+
interface CloudKitDatabase {
|
|
2707
|
+
saveRecords: (records: CloudKitRecordToSave | CloudKitRecordToSave[], options?: {
|
|
2708
|
+
zoneName?: string;
|
|
2709
|
+
}) => Promise<CloudKitResponse>;
|
|
2710
|
+
deleteRecords: (recordNames: {
|
|
2711
|
+
recordName: string;
|
|
2712
|
+
}[], options?: {
|
|
2713
|
+
zoneName?: string;
|
|
2714
|
+
}) => Promise<CloudKitResponse>;
|
|
2715
|
+
performQuery: (query: CloudKitQuery) => Promise<CloudKitResponse>;
|
|
2716
|
+
fetchRecords: (recordNames: Array<{
|
|
2717
|
+
recordName: string;
|
|
2718
|
+
}>, options?: {
|
|
2719
|
+
desiredKeys?: string[];
|
|
2720
|
+
}) => Promise<CloudKitResponse>;
|
|
2721
|
+
}
|
|
2722
|
+
interface CloudKitRecordToSave {
|
|
2723
|
+
recordType: string;
|
|
2724
|
+
recordName?: string;
|
|
2725
|
+
fields: Record<string, {
|
|
2726
|
+
value: unknown;
|
|
2727
|
+
}>;
|
|
2728
|
+
}
|
|
2729
|
+
interface CloudKitQuery {
|
|
2730
|
+
recordType: string;
|
|
2731
|
+
filterBy?: Array<{
|
|
2732
|
+
fieldName: string;
|
|
2733
|
+
comparator: string;
|
|
2734
|
+
fieldValue: {
|
|
2735
|
+
value: unknown;
|
|
2736
|
+
};
|
|
2737
|
+
}>;
|
|
2738
|
+
sortBy?: Array<{
|
|
2739
|
+
fieldName: string;
|
|
2740
|
+
ascending: boolean;
|
|
2741
|
+
}>;
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
/**
|
|
2745
|
+
* iCloud Backup Implementation
|
|
2746
|
+
*
|
|
2747
|
+
* Generic backup/restore functionality for iCloud storage.
|
|
2748
|
+
* Works directly with WatermelonDB database.
|
|
2749
|
+
*/
|
|
2750
|
+
|
|
2751
|
+
interface ICloudExportResult {
|
|
2752
|
+
success: boolean;
|
|
2753
|
+
uploaded: number;
|
|
2754
|
+
skipped: number;
|
|
2755
|
+
total: number;
|
|
2756
|
+
}
|
|
2757
|
+
interface ICloudImportResult {
|
|
2758
|
+
success: boolean;
|
|
2759
|
+
restored: number;
|
|
2760
|
+
failed: number;
|
|
2761
|
+
total: number;
|
|
2762
|
+
/** True if no backups were found in iCloud */
|
|
2763
|
+
noBackupsFound?: boolean;
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
/**
|
|
2767
|
+
* Options for useICloudBackup hook
|
|
2768
|
+
*/
|
|
2769
|
+
interface UseICloudBackupOptions {
|
|
2770
|
+
/** WatermelonDB database instance */
|
|
2771
|
+
database: Database;
|
|
2772
|
+
/** Current user address (null if not signed in) */
|
|
2773
|
+
userAddress: string | null;
|
|
2774
|
+
/** Request encryption key for the user address */
|
|
2775
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
2776
|
+
/** Export a conversation to an encrypted blob */
|
|
2777
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
2778
|
+
success: boolean;
|
|
2779
|
+
blob?: Blob;
|
|
2780
|
+
}>;
|
|
2781
|
+
/** Import a conversation from an encrypted blob */
|
|
2782
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
2783
|
+
success: boolean;
|
|
2784
|
+
}>;
|
|
2785
|
+
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Result returned by useICloudBackup hook
|
|
2788
|
+
*/
|
|
2789
|
+
interface UseICloudBackupResult {
|
|
2790
|
+
/** Backup all conversations to iCloud */
|
|
2791
|
+
backup: (options?: {
|
|
2792
|
+
onProgress?: (current: number, total: number) => void;
|
|
2793
|
+
}) => Promise<ICloudExportResult | {
|
|
2794
|
+
error: string;
|
|
2795
|
+
}>;
|
|
2796
|
+
/** Restore conversations from iCloud */
|
|
2797
|
+
restore: (options?: {
|
|
2798
|
+
onProgress?: (current: number, total: number) => void;
|
|
2799
|
+
}) => Promise<ICloudImportResult | {
|
|
2800
|
+
error: string;
|
|
2801
|
+
}>;
|
|
2802
|
+
/** Whether iCloud is configured */
|
|
2803
|
+
isConfigured: boolean;
|
|
2804
|
+
/** Whether user has signed in to iCloud */
|
|
2805
|
+
isAuthenticated: boolean;
|
|
2806
|
+
/** Whether CloudKit JS is available */
|
|
2807
|
+
isAvailable: boolean;
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* React hook for iCloud backup and restore functionality.
|
|
2811
|
+
*
|
|
2812
|
+
* This hook provides methods to backup conversations to iCloud and restore them.
|
|
2813
|
+
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
2814
|
+
* authentication, and managing the backup/restore process.
|
|
2815
|
+
*
|
|
2816
|
+
* Must be used within an ICloudAuthProvider.
|
|
2817
|
+
*
|
|
2818
|
+
* @example
|
|
2819
|
+
* ```tsx
|
|
2820
|
+
* import { useICloudBackup } from "@reverbia/sdk/react";
|
|
2821
|
+
*
|
|
2822
|
+
* function BackupButton() {
|
|
2823
|
+
* const { backup, restore, isConfigured, isAuthenticated, isAvailable } = useICloudBackup({
|
|
2824
|
+
* database,
|
|
2825
|
+
* userAddress,
|
|
2826
|
+
* requestEncryptionKey,
|
|
2827
|
+
* exportConversation,
|
|
2828
|
+
* importConversation,
|
|
2829
|
+
* });
|
|
2830
|
+
*
|
|
2831
|
+
* if (!isAvailable) {
|
|
2832
|
+
* return <p>CloudKit JS not loaded</p>;
|
|
2833
|
+
* }
|
|
2834
|
+
*
|
|
2835
|
+
* const handleBackup = async () => {
|
|
2836
|
+
* const result = await backup({
|
|
2837
|
+
* onProgress: (current, total) => {
|
|
2838
|
+
* console.log(`Progress: ${current}/${total}`);
|
|
2839
|
+
* },
|
|
2840
|
+
* });
|
|
2841
|
+
*
|
|
2842
|
+
* if ("error" in result) {
|
|
2843
|
+
* console.error(result.error);
|
|
2844
|
+
* } else {
|
|
2845
|
+
* console.log(`Uploaded: ${result.uploaded}, Skipped: ${result.skipped}`);
|
|
2846
|
+
* }
|
|
2847
|
+
* };
|
|
2848
|
+
*
|
|
2849
|
+
* return <button onClick={handleBackup} disabled={!isConfigured}>Backup to iCloud</button>;
|
|
2850
|
+
* }
|
|
2851
|
+
* ```
|
|
2852
|
+
*
|
|
2853
|
+
* @category Hooks
|
|
2854
|
+
*/
|
|
2855
|
+
declare function useICloudBackup(options: UseICloudBackupOptions): UseICloudBackupResult;
|
|
2856
|
+
|
|
2857
|
+
/**
|
|
2858
|
+
* Props for BackupAuthProvider
|
|
2859
|
+
*
|
|
2860
|
+
* At least one of `dropboxAppKey`, `googleClientId`, or `icloudApiToken` should be provided
|
|
2861
|
+
* for the provider to be useful. All are optional to allow using just one backup provider.
|
|
2862
|
+
*/
|
|
2863
|
+
interface BackupAuthProviderProps {
|
|
2864
|
+
/** Dropbox App Key (from Dropbox Developer Console). Optional - omit to disable Dropbox. */
|
|
2865
|
+
dropboxAppKey?: string;
|
|
2866
|
+
/** Dropbox OAuth callback path (default: "/auth/dropbox/callback") */
|
|
2867
|
+
dropboxCallbackPath?: string;
|
|
2868
|
+
/** Google OAuth Client ID (from Google Cloud Console). Optional - omit to disable Google Drive. */
|
|
2869
|
+
googleClientId?: string;
|
|
2870
|
+
/** Google OAuth callback path (default: "/auth/google/callback") */
|
|
2871
|
+
googleCallbackPath?: string;
|
|
2872
|
+
/** CloudKit API token (from Apple Developer Console). Optional - omit to disable iCloud. */
|
|
2873
|
+
icloudApiToken?: string;
|
|
2874
|
+
/** CloudKit container identifier (default: "iCloud.Memoryless") */
|
|
2875
|
+
icloudContainerIdentifier?: string;
|
|
2876
|
+
/** CloudKit environment (default: "production") */
|
|
2877
|
+
icloudEnvironment?: "development" | "production";
|
|
2878
|
+
/**
|
|
2879
|
+
* API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
|
|
2880
|
+
* Only needed if you have a custom client configuration (e.g., different baseUrl).
|
|
2881
|
+
*/
|
|
2882
|
+
apiClient?: Client;
|
|
2883
|
+
/** Children to render */
|
|
2884
|
+
children: ReactNode;
|
|
2885
|
+
}
|
|
2886
|
+
/**
|
|
2887
|
+
* Auth state for a single provider
|
|
2888
|
+
*/
|
|
2889
|
+
interface ProviderAuthState {
|
|
2890
|
+
/** Current access token (null if not authenticated) */
|
|
2891
|
+
accessToken: string | null;
|
|
2892
|
+
/** Whether user has authenticated with this provider */
|
|
2893
|
+
isAuthenticated: boolean;
|
|
2894
|
+
/** Whether this provider is configured */
|
|
2895
|
+
isConfigured: boolean;
|
|
2896
|
+
/** Request access - returns token or redirects to OAuth */
|
|
2897
|
+
requestAccess: () => Promise<string>;
|
|
2898
|
+
/** Clear stored token and log out */
|
|
2899
|
+
logout: () => Promise<void>;
|
|
2900
|
+
/** Refresh the access token using the refresh token */
|
|
2901
|
+
refreshToken: () => Promise<string | null>;
|
|
2902
|
+
}
|
|
2903
|
+
/**
|
|
2904
|
+
* Context value for unified backup authentication
|
|
2905
|
+
*/
|
|
2906
|
+
interface BackupAuthContextValue {
|
|
2907
|
+
/** Dropbox authentication state and methods */
|
|
2908
|
+
dropbox: ProviderAuthState;
|
|
2909
|
+
/** Google Drive authentication state and methods */
|
|
2910
|
+
googleDrive: ProviderAuthState;
|
|
2911
|
+
/** iCloud authentication state and methods */
|
|
2912
|
+
icloud: ProviderAuthState;
|
|
2913
|
+
/** Check if any provider is configured */
|
|
2914
|
+
hasAnyProvider: boolean;
|
|
2915
|
+
/** Check if any provider is authenticated */
|
|
2916
|
+
hasAnyAuthentication: boolean;
|
|
2917
|
+
/** Logout from all providers */
|
|
2918
|
+
logoutAll: () => Promise<void>;
|
|
2919
|
+
}
|
|
2920
|
+
/**
|
|
2921
|
+
* Unified provider component for backup OAuth authentication.
|
|
2922
|
+
*
|
|
2923
|
+
* Wrap your app with this provider to enable both Dropbox and Google Drive
|
|
2924
|
+
* authentication. It handles the OAuth 2.0 Authorization Code flow with
|
|
2925
|
+
* refresh tokens for both providers.
|
|
2926
|
+
*
|
|
2927
|
+
* @example
|
|
2928
|
+
* ```tsx
|
|
2929
|
+
* import { BackupAuthProvider } from "@reverbia/sdk/react";
|
|
2930
|
+
*
|
|
2931
|
+
* function App() {
|
|
2932
|
+
* return (
|
|
2933
|
+
* <BackupAuthProvider
|
|
2934
|
+
* dropboxAppKey={process.env.NEXT_PUBLIC_DROPBOX_APP_KEY}
|
|
2935
|
+
* dropboxCallbackPath="/auth/dropbox/callback"
|
|
2936
|
+
* googleClientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
|
|
2937
|
+
* googleCallbackPath="/auth/google/callback"
|
|
2938
|
+
* icloudApiToken={process.env.NEXT_PUBLIC_CLOUDKIT_API_TOKEN}
|
|
2939
|
+
* icloudContainerIdentifier="iCloud.Memoryless"
|
|
2940
|
+
* apiClient={apiClient}
|
|
2941
|
+
* >
|
|
2942
|
+
* <MyApp />
|
|
2943
|
+
* </BackupAuthProvider>
|
|
2944
|
+
* );
|
|
2945
|
+
* }
|
|
2946
|
+
* ```
|
|
2947
|
+
*
|
|
2948
|
+
* @category Components
|
|
2949
|
+
*/
|
|
2950
|
+
declare function BackupAuthProvider({ dropboxAppKey, dropboxCallbackPath, googleClientId, googleCallbackPath, icloudApiToken, icloudContainerIdentifier, icloudEnvironment, apiClient, children, }: BackupAuthProviderProps): JSX.Element;
|
|
2951
|
+
/**
|
|
2952
|
+
* Hook to access unified backup authentication state and methods.
|
|
2953
|
+
*
|
|
2954
|
+
* Must be used within a BackupAuthProvider.
|
|
2955
|
+
*
|
|
2956
|
+
* @example
|
|
2957
|
+
* ```tsx
|
|
2958
|
+
* import { useBackupAuth } from "@reverbia/sdk/react";
|
|
2959
|
+
*
|
|
2960
|
+
* function BackupSettings() {
|
|
2961
|
+
* const { dropbox, googleDrive, logoutAll } = useBackupAuth();
|
|
2962
|
+
*
|
|
2963
|
+
* return (
|
|
2964
|
+
* <div>
|
|
2965
|
+
* <h3>Backup Providers</h3>
|
|
2966
|
+
*
|
|
2967
|
+
* {dropbox.isConfigured && (
|
|
2968
|
+
* <div>
|
|
2969
|
+
* <span>Dropbox: {dropbox.isAuthenticated ? 'Connected' : 'Not connected'}</span>
|
|
2970
|
+
* {dropbox.isAuthenticated ? (
|
|
2971
|
+
* <button onClick={dropbox.logout}>Disconnect</button>
|
|
2972
|
+
* ) : (
|
|
2973
|
+
* <button onClick={dropbox.requestAccess}>Connect</button>
|
|
2974
|
+
* )}
|
|
2975
|
+
* </div>
|
|
2976
|
+
* )}
|
|
2977
|
+
*
|
|
2978
|
+
* {googleDrive.isConfigured && (
|
|
2979
|
+
* <div>
|
|
2980
|
+
* <span>Google Drive: {googleDrive.isAuthenticated ? 'Connected' : 'Not connected'}</span>
|
|
2981
|
+
* {googleDrive.isAuthenticated ? (
|
|
2982
|
+
* <button onClick={googleDrive.logout}>Disconnect</button>
|
|
2983
|
+
* ) : (
|
|
2984
|
+
* <button onClick={googleDrive.requestAccess}>Connect</button>
|
|
2985
|
+
* )}
|
|
2986
|
+
* </div>
|
|
2987
|
+
* )}
|
|
2988
|
+
*
|
|
2989
|
+
* <button onClick={logoutAll}>Disconnect All</button>
|
|
2990
|
+
* </div>
|
|
2991
|
+
* );
|
|
2992
|
+
* }
|
|
2993
|
+
* ```
|
|
2994
|
+
*
|
|
2995
|
+
* @category Hooks
|
|
2996
|
+
*/
|
|
2997
|
+
declare function useBackupAuth(): BackupAuthContextValue;
|
|
2998
|
+
|
|
2999
|
+
/**
|
|
3000
|
+
* Options for useBackup hook
|
|
3001
|
+
*/
|
|
3002
|
+
interface UseBackupOptions {
|
|
3003
|
+
/** WatermelonDB database instance */
|
|
3004
|
+
database: Database;
|
|
3005
|
+
/** Current user address (null if not signed in) */
|
|
3006
|
+
userAddress: string | null;
|
|
3007
|
+
/** Request encryption key for the user address */
|
|
3008
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
3009
|
+
/** Export a conversation to an encrypted blob */
|
|
3010
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
3011
|
+
success: boolean;
|
|
3012
|
+
blob?: Blob;
|
|
3013
|
+
}>;
|
|
3014
|
+
/** Import a conversation from an encrypted blob */
|
|
3015
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
3016
|
+
success: boolean;
|
|
3017
|
+
}>;
|
|
3018
|
+
/** Dropbox folder path for backups (default: '/ai-chat-app/conversations') */
|
|
3019
|
+
dropboxFolder?: string;
|
|
3020
|
+
/** Google Drive root folder name (default: 'ai-chat-app') */
|
|
3021
|
+
googleRootFolder?: string;
|
|
3022
|
+
/** Google Drive conversations subfolder (default: 'conversations') */
|
|
3023
|
+
googleConversationsFolder?: string;
|
|
3024
|
+
}
|
|
3025
|
+
/**
|
|
3026
|
+
* Progress callback type
|
|
3027
|
+
*/
|
|
3028
|
+
type ProgressCallback = (current: number, total: number) => void;
|
|
3029
|
+
/**
|
|
3030
|
+
* Backup options for individual operations
|
|
3031
|
+
*/
|
|
3032
|
+
interface BackupOperationOptions {
|
|
3033
|
+
onProgress?: ProgressCallback;
|
|
3034
|
+
}
|
|
3035
|
+
/**
|
|
3036
|
+
* Provider-specific backup state
|
|
3037
|
+
*/
|
|
3038
|
+
interface ProviderBackupState {
|
|
3039
|
+
/** Whether the provider is configured */
|
|
3040
|
+
isConfigured: boolean;
|
|
3041
|
+
/** Whether user has authenticated with this provider */
|
|
3042
|
+
isAuthenticated: boolean;
|
|
3043
|
+
/** Backup all conversations to this provider */
|
|
3044
|
+
backup: (options?: BackupOperationOptions) => Promise<DropboxExportResult | GoogleDriveExportResult | ICloudExportResult | {
|
|
3045
|
+
error: string;
|
|
3046
|
+
}>;
|
|
3047
|
+
/** Restore conversations from this provider */
|
|
3048
|
+
restore: (options?: BackupOperationOptions) => Promise<DropboxImportResult | GoogleDriveImportResult | ICloudImportResult | {
|
|
3049
|
+
error: string;
|
|
3050
|
+
}>;
|
|
3051
|
+
/** Request access to this provider (triggers OAuth if needed) */
|
|
3052
|
+
connect: () => Promise<string>;
|
|
3053
|
+
/** Disconnect from this provider */
|
|
3054
|
+
disconnect: () => Promise<void>;
|
|
3055
|
+
}
|
|
3056
|
+
/**
|
|
3057
|
+
* Result returned by useBackup hook
|
|
3058
|
+
*/
|
|
3059
|
+
interface UseBackupResult {
|
|
3060
|
+
/** Dropbox backup state and methods */
|
|
3061
|
+
dropbox: ProviderBackupState;
|
|
3062
|
+
/** Google Drive backup state and methods */
|
|
3063
|
+
googleDrive: ProviderBackupState;
|
|
3064
|
+
/** iCloud backup state and methods */
|
|
3065
|
+
icloud: ProviderBackupState;
|
|
3066
|
+
/** Whether any backup provider is configured */
|
|
3067
|
+
hasAnyProvider: boolean;
|
|
3068
|
+
/** Whether any backup provider is authenticated */
|
|
3069
|
+
hasAnyAuthentication: boolean;
|
|
3070
|
+
/** Disconnect from all providers */
|
|
3071
|
+
disconnectAll: () => Promise<void>;
|
|
3072
|
+
}
|
|
3073
|
+
/**
|
|
3074
|
+
* Unified React hook for backup and restore functionality.
|
|
3075
|
+
*
|
|
3076
|
+
* This hook provides methods to backup conversations to both Dropbox and Google Drive,
|
|
3077
|
+
* and restore them. It handles all the logic for checking timestamps, skipping
|
|
3078
|
+
* unchanged files, authentication, and managing the backup/restore process.
|
|
3079
|
+
*
|
|
3080
|
+
* Must be used within a BackupAuthProvider.
|
|
3081
|
+
*
|
|
3082
|
+
* @example
|
|
3083
|
+
* ```tsx
|
|
3084
|
+
* import { useBackup } from "@reverbia/sdk/react";
|
|
3085
|
+
*
|
|
3086
|
+
* function BackupManager() {
|
|
3087
|
+
* const { dropbox, googleDrive, hasAnyProvider } = useBackup({
|
|
3088
|
+
* database,
|
|
3089
|
+
* userAddress,
|
|
3090
|
+
* requestEncryptionKey,
|
|
3091
|
+
* exportConversation,
|
|
3092
|
+
* importConversation,
|
|
3093
|
+
* });
|
|
3094
|
+
*
|
|
3095
|
+
* if (!hasAnyProvider) {
|
|
3096
|
+
* return <p>No backup providers configured</p>;
|
|
3097
|
+
* }
|
|
3098
|
+
*
|
|
3099
|
+
* return (
|
|
3100
|
+
* <div>
|
|
3101
|
+
* {dropbox.isConfigured && (
|
|
3102
|
+
* <div>
|
|
3103
|
+
* <h3>Dropbox</h3>
|
|
3104
|
+
* {dropbox.isAuthenticated ? (
|
|
3105
|
+
* <>
|
|
3106
|
+
* <button onClick={() => dropbox.backup()}>Backup</button>
|
|
3107
|
+
* <button onClick={() => dropbox.restore()}>Restore</button>
|
|
3108
|
+
* <button onClick={dropbox.disconnect}>Disconnect</button>
|
|
3109
|
+
* </>
|
|
3110
|
+
* ) : (
|
|
3111
|
+
* <button onClick={dropbox.connect}>Connect Dropbox</button>
|
|
3112
|
+
* )}
|
|
3113
|
+
* </div>
|
|
3114
|
+
* )}
|
|
3115
|
+
*
|
|
3116
|
+
* {googleDrive.isConfigured && (
|
|
3117
|
+
* <div>
|
|
3118
|
+
* <h3>Google Drive</h3>
|
|
3119
|
+
* {googleDrive.isAuthenticated ? (
|
|
3120
|
+
* <>
|
|
3121
|
+
* <button onClick={() => googleDrive.backup()}>Backup</button>
|
|
3122
|
+
* <button onClick={() => googleDrive.restore()}>Restore</button>
|
|
3123
|
+
* <button onClick={googleDrive.disconnect}>Disconnect</button>
|
|
3124
|
+
* </>
|
|
3125
|
+
* ) : (
|
|
3126
|
+
* <button onClick={googleDrive.connect}>Connect Google Drive</button>
|
|
3127
|
+
* )}
|
|
3128
|
+
* </div>
|
|
3129
|
+
* )}
|
|
3130
|
+
* </div>
|
|
3131
|
+
* );
|
|
3132
|
+
* }
|
|
3133
|
+
* ```
|
|
3134
|
+
*
|
|
3135
|
+
* @category Hooks
|
|
3136
|
+
*/
|
|
3137
|
+
declare function useBackup(options: UseBackupOptions): UseBackupResult;
|
|
3138
|
+
|
|
3139
|
+
export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DECRYPTION_FAILED_PLACEHOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryData, type MemoryEncryptionFields, 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 UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, decryptField, decryptMemoriesBatch, decryptMemoryFields, encryptData, encryptField, encryptMemoriesBatch, encryptMemoriesBatchInPlace, encryptMemoryFields, exportPublicKey, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getEncryptionVersion, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptedFields, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, memoryStorageSchema, needsEncryption, requestEncryptionKey, requestKeyPair, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
|