@reverbia/sdk 1.0.0-next.20251215193957 → 1.0.0-next.20251217134403
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/index.cjs +66 -3
- package/dist/expo/index.d.mts +17 -1
- package/dist/expo/index.d.ts +17 -1
- package/dist/expo/index.mjs +65 -3
- package/dist/react/index.cjs +326 -54
- package/dist/react/index.d.mts +151 -2
- package/dist/react/index.d.ts +151 -2
- package/dist/react/index.mjs +314 -46
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -34,6 +34,8 @@ __export(index_exports, {
|
|
|
34
34
|
ChatMessage: () => Message,
|
|
35
35
|
DEFAULT_TOOL_SELECTOR_MODEL: () => DEFAULT_TOOL_SELECTOR_MODEL,
|
|
36
36
|
StoredMemoryModel: () => Memory,
|
|
37
|
+
StoredModelPreferenceModel: () => ModelPreference,
|
|
38
|
+
chatStorageMigrations: () => chatStorageMigrations,
|
|
37
39
|
chatStorageSchema: () => chatStorageSchema,
|
|
38
40
|
createMemoryContextSystemMessage: () => createMemoryContextSystemMessage,
|
|
39
41
|
decryptData: () => decryptData,
|
|
@@ -49,6 +51,7 @@ __export(index_exports, {
|
|
|
49
51
|
memoryStorageSchema: () => memoryStorageSchema,
|
|
50
52
|
requestEncryptionKey: () => requestEncryptionKey,
|
|
51
53
|
selectTool: () => selectTool,
|
|
54
|
+
settingsStorageSchema: () => settingsStorageSchema,
|
|
52
55
|
useChat: () => useChat,
|
|
53
56
|
useChatStorage: () => useChatStorage,
|
|
54
57
|
useEncryption: () => useEncryption,
|
|
@@ -57,7 +60,8 @@ __export(index_exports, {
|
|
|
57
60
|
useModels: () => useModels,
|
|
58
61
|
useOCR: () => useOCR,
|
|
59
62
|
usePdf: () => usePdf,
|
|
60
|
-
useSearch: () => useSearch
|
|
63
|
+
useSearch: () => useSearch,
|
|
64
|
+
useSettings: () => useSettings
|
|
61
65
|
});
|
|
62
66
|
module.exports = __toCommonJS(index_exports);
|
|
63
67
|
|
|
@@ -1482,6 +1486,7 @@ Please inform the user about this issue and try to help them alternatively.`
|
|
|
1482
1486
|
toolExecution: toolExecutionResult
|
|
1483
1487
|
};
|
|
1484
1488
|
}
|
|
1489
|
+
let sseError = null;
|
|
1485
1490
|
const sseResult = await client.sse.post({
|
|
1486
1491
|
baseUrl,
|
|
1487
1492
|
url: "/api/v1/chat/completions",
|
|
@@ -1495,23 +1500,52 @@ Please inform the user about this issue and try to help them alternatively.`
|
|
|
1495
1500
|
Authorization: `Bearer ${token}`,
|
|
1496
1501
|
...headers
|
|
1497
1502
|
},
|
|
1498
|
-
signal: abortController.signal
|
|
1503
|
+
signal: abortController.signal,
|
|
1504
|
+
sseMaxRetryAttempts: 1,
|
|
1505
|
+
onSseError: (error) => {
|
|
1506
|
+
sseError = error instanceof Error ? error : new Error(String(error));
|
|
1507
|
+
}
|
|
1499
1508
|
});
|
|
1500
1509
|
const accumulator = createStreamAccumulator();
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
if (
|
|
1512
|
-
|
|
1510
|
+
try {
|
|
1511
|
+
for await (const chunk of sseResult.stream) {
|
|
1512
|
+
if (isDoneMarker(chunk)) {
|
|
1513
|
+
continue;
|
|
1514
|
+
}
|
|
1515
|
+
if (chunk && typeof chunk === "object") {
|
|
1516
|
+
const contentDelta = processStreamingChunk(
|
|
1517
|
+
chunk,
|
|
1518
|
+
accumulator
|
|
1519
|
+
);
|
|
1520
|
+
if (contentDelta) {
|
|
1521
|
+
if (onData) onData(contentDelta);
|
|
1522
|
+
if (globalOnData) globalOnData(contentDelta);
|
|
1523
|
+
}
|
|
1513
1524
|
}
|
|
1514
1525
|
}
|
|
1526
|
+
} catch (streamErr) {
|
|
1527
|
+
if (isAbortError(streamErr) || abortController.signal.aborted) {
|
|
1528
|
+
setIsLoading(false);
|
|
1529
|
+
const partialCompletion = buildCompletionResponse(accumulator);
|
|
1530
|
+
return {
|
|
1531
|
+
data: partialCompletion,
|
|
1532
|
+
error: "Request aborted",
|
|
1533
|
+
toolExecution: toolExecutionResult
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
throw streamErr;
|
|
1537
|
+
}
|
|
1538
|
+
if (abortController.signal.aborted) {
|
|
1539
|
+
setIsLoading(false);
|
|
1540
|
+
const partialCompletion = buildCompletionResponse(accumulator);
|
|
1541
|
+
return {
|
|
1542
|
+
data: partialCompletion,
|
|
1543
|
+
error: "Request aborted",
|
|
1544
|
+
toolExecution: toolExecutionResult
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
if (sseError) {
|
|
1548
|
+
throw sseError;
|
|
1515
1549
|
}
|
|
1516
1550
|
const completion = buildCompletionResponse(accumulator);
|
|
1517
1551
|
setIsLoading(false);
|
|
@@ -1733,7 +1767,8 @@ function messageToStored(message) {
|
|
|
1733
1767
|
embeddingModel: message.embeddingModel,
|
|
1734
1768
|
usage: message.usage,
|
|
1735
1769
|
sources: message.sources,
|
|
1736
|
-
responseDuration: message.responseDuration
|
|
1770
|
+
responseDuration: message.responseDuration,
|
|
1771
|
+
wasStopped: message.wasStopped
|
|
1737
1772
|
};
|
|
1738
1773
|
}
|
|
1739
1774
|
function conversationToStored(conversation) {
|
|
@@ -1822,6 +1857,7 @@ async function createMessageOp(ctx, opts) {
|
|
|
1822
1857
|
msg._setRaw("response_duration", opts.responseDuration);
|
|
1823
1858
|
if (opts.vector) msg._setRaw("vector", JSON.stringify(opts.vector));
|
|
1824
1859
|
if (opts.embeddingModel) msg._setRaw("embedding_model", opts.embeddingModel);
|
|
1860
|
+
if (opts.wasStopped) msg._setRaw("was_stopped", opts.wasStopped);
|
|
1825
1861
|
});
|
|
1826
1862
|
});
|
|
1827
1863
|
return messageToStored(created);
|
|
@@ -2112,6 +2148,45 @@ function useChatStorage(options) {
|
|
|
2112
2148
|
});
|
|
2113
2149
|
const responseDuration = (Date.now() - startTime) / 1e3;
|
|
2114
2150
|
if (result.error || !result.data) {
|
|
2151
|
+
const abortedResult = result;
|
|
2152
|
+
if (abortedResult.error === "Request aborted") {
|
|
2153
|
+
const assistantContent2 = abortedResult.data?.choices?.[0]?.message?.content?.map((part) => part.text || "").join("") || "";
|
|
2154
|
+
const responseModel = abortedResult.data?.model || model || "";
|
|
2155
|
+
let storedAssistantMessage2;
|
|
2156
|
+
try {
|
|
2157
|
+
storedAssistantMessage2 = await createMessageOp(storageCtx, {
|
|
2158
|
+
conversationId: convId,
|
|
2159
|
+
role: "assistant",
|
|
2160
|
+
content: assistantContent2,
|
|
2161
|
+
model: responseModel,
|
|
2162
|
+
usage: convertUsageToStored(abortedResult.data?.usage),
|
|
2163
|
+
responseDuration,
|
|
2164
|
+
wasStopped: true
|
|
2165
|
+
});
|
|
2166
|
+
const completionData = abortedResult.data || {
|
|
2167
|
+
id: `aborted-${Date.now()}`,
|
|
2168
|
+
model: responseModel,
|
|
2169
|
+
choices: [{
|
|
2170
|
+
index: 0,
|
|
2171
|
+
message: {
|
|
2172
|
+
role: "assistant",
|
|
2173
|
+
content: [{ type: "text", text: assistantContent2 }]
|
|
2174
|
+
},
|
|
2175
|
+
finish_reason: "stop"
|
|
2176
|
+
}],
|
|
2177
|
+
usage: void 0
|
|
2178
|
+
};
|
|
2179
|
+
return {
|
|
2180
|
+
data: completionData,
|
|
2181
|
+
error: null,
|
|
2182
|
+
// Treat as success to the caller
|
|
2183
|
+
toolExecution: abortedResult.toolExecution,
|
|
2184
|
+
userMessage: storedUserMessage,
|
|
2185
|
+
assistantMessage: storedAssistantMessage2
|
|
2186
|
+
};
|
|
2187
|
+
} catch (err) {
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2115
2190
|
return {
|
|
2116
2191
|
data: null,
|
|
2117
2192
|
error: result.error || "No response data received",
|
|
@@ -2183,8 +2258,9 @@ function useChatStorage(options) {
|
|
|
2183
2258
|
|
|
2184
2259
|
// src/lib/chatStorage/schema.ts
|
|
2185
2260
|
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
2261
|
+
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
2186
2262
|
var chatStorageSchema = (0, import_watermelondb2.appSchema)({
|
|
2187
|
-
version:
|
|
2263
|
+
version: 2,
|
|
2188
2264
|
tables: [
|
|
2189
2265
|
(0, import_watermelondb2.tableSchema)({
|
|
2190
2266
|
name: "history",
|
|
@@ -2207,7 +2283,8 @@ var chatStorageSchema = (0, import_watermelondb2.appSchema)({
|
|
|
2207
2283
|
// JSON stringified ChatCompletionUsage
|
|
2208
2284
|
{ name: "sources", type: "string", isOptional: true },
|
|
2209
2285
|
// JSON stringified SearchSource[]
|
|
2210
|
-
{ name: "response_duration", type: "number", isOptional: true }
|
|
2286
|
+
{ name: "response_duration", type: "number", isOptional: true },
|
|
2287
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2211
2288
|
]
|
|
2212
2289
|
}),
|
|
2213
2290
|
(0, import_watermelondb2.tableSchema)({
|
|
@@ -2222,6 +2299,21 @@ var chatStorageSchema = (0, import_watermelondb2.appSchema)({
|
|
|
2222
2299
|
})
|
|
2223
2300
|
]
|
|
2224
2301
|
});
|
|
2302
|
+
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
2303
|
+
migrations: [
|
|
2304
|
+
{
|
|
2305
|
+
toVersion: 2,
|
|
2306
|
+
steps: [
|
|
2307
|
+
(0, import_migrations.addColumns)({
|
|
2308
|
+
table: "history",
|
|
2309
|
+
columns: [
|
|
2310
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2311
|
+
]
|
|
2312
|
+
})
|
|
2313
|
+
]
|
|
2314
|
+
}
|
|
2315
|
+
]
|
|
2316
|
+
});
|
|
2225
2317
|
|
|
2226
2318
|
// src/lib/chatStorage/models.ts
|
|
2227
2319
|
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
@@ -2305,6 +2397,10 @@ var Message = class extends import_watermelondb3.Model {
|
|
|
2305
2397
|
const value = this._getRaw("response_duration");
|
|
2306
2398
|
return value !== null && value !== void 0 ? value : void 0;
|
|
2307
2399
|
}
|
|
2400
|
+
/** Whether the message generation was stopped by the user */
|
|
2401
|
+
get wasStopped() {
|
|
2402
|
+
return this._getRaw("was_stopped");
|
|
2403
|
+
}
|
|
2308
2404
|
};
|
|
2309
2405
|
Message.table = "history";
|
|
2310
2406
|
Message.associations = {
|
|
@@ -3507,9 +3603,181 @@ var Memory = class extends import_watermelondb6.Model {
|
|
|
3507
3603
|
};
|
|
3508
3604
|
Memory.table = "memories";
|
|
3509
3605
|
|
|
3510
|
-
// src/react/
|
|
3606
|
+
// src/react/useSettings.ts
|
|
3511
3607
|
var import_react4 = require("react");
|
|
3512
3608
|
|
|
3609
|
+
// src/lib/settingsStorage/operations.ts
|
|
3610
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
3611
|
+
function modelPreferenceToStored(preference) {
|
|
3612
|
+
return {
|
|
3613
|
+
uniqueId: preference.id,
|
|
3614
|
+
walletAddress: preference.walletAddress,
|
|
3615
|
+
models: preference.models
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
3619
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb7.Q.where("wallet_address", walletAddress)).fetch();
|
|
3620
|
+
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
3621
|
+
}
|
|
3622
|
+
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
3623
|
+
const result = await ctx.database.write(async () => {
|
|
3624
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb7.Q.where("wallet_address", walletAddress)).fetch();
|
|
3625
|
+
if (results.length > 0) {
|
|
3626
|
+
const preference = results[0];
|
|
3627
|
+
await preference.update((pref) => {
|
|
3628
|
+
if (models !== void 0) {
|
|
3629
|
+
pref._setRaw("models", models || null);
|
|
3630
|
+
}
|
|
3631
|
+
});
|
|
3632
|
+
return preference;
|
|
3633
|
+
}
|
|
3634
|
+
return await ctx.modelPreferencesCollection.create((pref) => {
|
|
3635
|
+
pref._setRaw("wallet_address", walletAddress);
|
|
3636
|
+
if (models) pref._setRaw("models", models);
|
|
3637
|
+
});
|
|
3638
|
+
});
|
|
3639
|
+
return modelPreferenceToStored(result);
|
|
3640
|
+
}
|
|
3641
|
+
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
3642
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb7.Q.where("wallet_address", walletAddress)).fetch();
|
|
3643
|
+
if (results.length === 0) return false;
|
|
3644
|
+
await ctx.database.write(async () => {
|
|
3645
|
+
await results[0].destroyPermanently();
|
|
3646
|
+
});
|
|
3647
|
+
return true;
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3650
|
+
// src/react/useSettings.ts
|
|
3651
|
+
function useSettings(options) {
|
|
3652
|
+
const { database, walletAddress } = options;
|
|
3653
|
+
const [modelPreference, setModelPreferenceState] = (0, import_react4.useState)(null);
|
|
3654
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
3655
|
+
const modelPreferencesCollection = (0, import_react4.useMemo)(
|
|
3656
|
+
() => database.get("modelPreferences"),
|
|
3657
|
+
[database]
|
|
3658
|
+
);
|
|
3659
|
+
const storageCtx = (0, import_react4.useMemo)(
|
|
3660
|
+
() => ({
|
|
3661
|
+
database,
|
|
3662
|
+
modelPreferencesCollection
|
|
3663
|
+
}),
|
|
3664
|
+
[database, modelPreferencesCollection]
|
|
3665
|
+
);
|
|
3666
|
+
const getModelPreference = (0, import_react4.useCallback)(
|
|
3667
|
+
async (address) => {
|
|
3668
|
+
try {
|
|
3669
|
+
if (!address) throw new Error("Wallet address is required");
|
|
3670
|
+
const result = await getModelPreferenceOp(storageCtx, address);
|
|
3671
|
+
return result;
|
|
3672
|
+
} catch (error) {
|
|
3673
|
+
throw new Error(
|
|
3674
|
+
error instanceof Error ? error.message : "An unknown error occurred"
|
|
3675
|
+
);
|
|
3676
|
+
}
|
|
3677
|
+
},
|
|
3678
|
+
[storageCtx]
|
|
3679
|
+
);
|
|
3680
|
+
const setModelPreference = (0, import_react4.useCallback)(
|
|
3681
|
+
async (address, models) => {
|
|
3682
|
+
try {
|
|
3683
|
+
if (!address) throw new Error("Wallet address is required");
|
|
3684
|
+
const result = await setModelPreferenceOp(storageCtx, address, models);
|
|
3685
|
+
if (walletAddress && address === walletAddress) {
|
|
3686
|
+
setModelPreferenceState(result);
|
|
3687
|
+
}
|
|
3688
|
+
return result;
|
|
3689
|
+
} catch (error) {
|
|
3690
|
+
throw new Error(
|
|
3691
|
+
error instanceof Error ? error.message : "An unknown error occurred"
|
|
3692
|
+
);
|
|
3693
|
+
}
|
|
3694
|
+
},
|
|
3695
|
+
[storageCtx, walletAddress]
|
|
3696
|
+
);
|
|
3697
|
+
const deleteModelPreference = (0, import_react4.useCallback)(
|
|
3698
|
+
async (address) => {
|
|
3699
|
+
try {
|
|
3700
|
+
if (!address) throw new Error("Wallet address is required");
|
|
3701
|
+
const deleted = await deleteModelPreferenceOp(storageCtx, address);
|
|
3702
|
+
if (deleted && walletAddress && address === walletAddress) {
|
|
3703
|
+
setModelPreferenceState(null);
|
|
3704
|
+
}
|
|
3705
|
+
return deleted;
|
|
3706
|
+
} catch (error) {
|
|
3707
|
+
throw new Error(
|
|
3708
|
+
error instanceof Error ? error.message : "An unknown error occurred"
|
|
3709
|
+
);
|
|
3710
|
+
}
|
|
3711
|
+
},
|
|
3712
|
+
[storageCtx, walletAddress]
|
|
3713
|
+
);
|
|
3714
|
+
(0, import_react4.useEffect)(() => {
|
|
3715
|
+
if (!walletAddress) {
|
|
3716
|
+
setModelPreferenceState(null);
|
|
3717
|
+
return;
|
|
3718
|
+
}
|
|
3719
|
+
let cancelled = false;
|
|
3720
|
+
const loadPreference = async () => {
|
|
3721
|
+
setIsLoading(true);
|
|
3722
|
+
try {
|
|
3723
|
+
const preference = await getModelPreference(walletAddress);
|
|
3724
|
+
if (!cancelled) {
|
|
3725
|
+
setModelPreferenceState(preference);
|
|
3726
|
+
}
|
|
3727
|
+
} finally {
|
|
3728
|
+
if (!cancelled) {
|
|
3729
|
+
setIsLoading(false);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
};
|
|
3733
|
+
loadPreference();
|
|
3734
|
+
return () => {
|
|
3735
|
+
cancelled = true;
|
|
3736
|
+
};
|
|
3737
|
+
}, [walletAddress, getModelPreference]);
|
|
3738
|
+
return {
|
|
3739
|
+
modelPreference,
|
|
3740
|
+
isLoading,
|
|
3741
|
+
getModelPreference,
|
|
3742
|
+
setModelPreference,
|
|
3743
|
+
deleteModelPreference
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
// src/lib/settingsStorage/schema.ts
|
|
3748
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
3749
|
+
var settingsStorageSchema = (0, import_watermelondb8.appSchema)({
|
|
3750
|
+
version: 1,
|
|
3751
|
+
tables: [
|
|
3752
|
+
(0, import_watermelondb8.tableSchema)({
|
|
3753
|
+
name: "modelPreferences",
|
|
3754
|
+
columns: [
|
|
3755
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
3756
|
+
{ name: "models", type: "string", isOptional: true }
|
|
3757
|
+
// stored as JSON stringified ModelPreference[]
|
|
3758
|
+
]
|
|
3759
|
+
})
|
|
3760
|
+
]
|
|
3761
|
+
});
|
|
3762
|
+
|
|
3763
|
+
// src/lib/settingsStorage/models.ts
|
|
3764
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
3765
|
+
var ModelPreference = class extends import_watermelondb9.Model {
|
|
3766
|
+
/** User's wallet address */
|
|
3767
|
+
get walletAddress() {
|
|
3768
|
+
return this._getRaw("wallet_address");
|
|
3769
|
+
}
|
|
3770
|
+
/** Preferred model identifier */
|
|
3771
|
+
get models() {
|
|
3772
|
+
const value = this._getRaw("models");
|
|
3773
|
+
return value ? value : void 0;
|
|
3774
|
+
}
|
|
3775
|
+
};
|
|
3776
|
+
ModelPreference.table = "modelPreferences";
|
|
3777
|
+
|
|
3778
|
+
// src/react/usePdf.ts
|
|
3779
|
+
var import_react5 = require("react");
|
|
3780
|
+
|
|
3513
3781
|
// src/lib/pdf.ts
|
|
3514
3782
|
var pdfjs = __toESM(require("pdfjs-dist"));
|
|
3515
3783
|
pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
|
@@ -3561,9 +3829,9 @@ async function convertPdfToImages(pdfDataUrl) {
|
|
|
3561
3829
|
// src/react/usePdf.ts
|
|
3562
3830
|
var PDF_MIME_TYPE = "application/pdf";
|
|
3563
3831
|
function usePdf() {
|
|
3564
|
-
const [isProcessing, setIsProcessing] = (0,
|
|
3565
|
-
const [error, setError] = (0,
|
|
3566
|
-
const extractPdfContext = (0,
|
|
3832
|
+
const [isProcessing, setIsProcessing] = (0, import_react5.useState)(false);
|
|
3833
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
3834
|
+
const extractPdfContext = (0, import_react5.useCallback)(
|
|
3567
3835
|
async (files) => {
|
|
3568
3836
|
setIsProcessing(true);
|
|
3569
3837
|
setError(null);
|
|
@@ -3610,12 +3878,12 @@ ${text}`;
|
|
|
3610
3878
|
}
|
|
3611
3879
|
|
|
3612
3880
|
// src/react/useOCR.ts
|
|
3613
|
-
var
|
|
3881
|
+
var import_react6 = require("react");
|
|
3614
3882
|
var import_tesseract = __toESM(require("tesseract.js"));
|
|
3615
3883
|
function useOCR() {
|
|
3616
|
-
const [isProcessing, setIsProcessing] = (0,
|
|
3617
|
-
const [error, setError] = (0,
|
|
3618
|
-
const extractOCRContext = (0,
|
|
3884
|
+
const [isProcessing, setIsProcessing] = (0, import_react6.useState)(false);
|
|
3885
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
3886
|
+
const extractOCRContext = (0, import_react6.useCallback)(
|
|
3619
3887
|
async (files) => {
|
|
3620
3888
|
setIsProcessing(true);
|
|
3621
3889
|
setError(null);
|
|
@@ -3701,22 +3969,22 @@ ${text}`;
|
|
|
3701
3969
|
}
|
|
3702
3970
|
|
|
3703
3971
|
// src/react/useModels.ts
|
|
3704
|
-
var
|
|
3972
|
+
var import_react7 = require("react");
|
|
3705
3973
|
function useModels(options = {}) {
|
|
3706
3974
|
const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
|
|
3707
|
-
const [models, setModels] = (0,
|
|
3708
|
-
const [isLoading, setIsLoading] = (0,
|
|
3709
|
-
const [error, setError] = (0,
|
|
3710
|
-
const getTokenRef = (0,
|
|
3711
|
-
const baseUrlRef = (0,
|
|
3712
|
-
const providerRef = (0,
|
|
3713
|
-
const abortControllerRef = (0,
|
|
3714
|
-
(0,
|
|
3975
|
+
const [models, setModels] = (0, import_react7.useState)([]);
|
|
3976
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
3977
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
3978
|
+
const getTokenRef = (0, import_react7.useRef)(getToken);
|
|
3979
|
+
const baseUrlRef = (0, import_react7.useRef)(baseUrl);
|
|
3980
|
+
const providerRef = (0, import_react7.useRef)(provider);
|
|
3981
|
+
const abortControllerRef = (0, import_react7.useRef)(null);
|
|
3982
|
+
(0, import_react7.useEffect)(() => {
|
|
3715
3983
|
getTokenRef.current = getToken;
|
|
3716
3984
|
baseUrlRef.current = baseUrl;
|
|
3717
3985
|
providerRef.current = provider;
|
|
3718
3986
|
});
|
|
3719
|
-
(0,
|
|
3987
|
+
(0, import_react7.useEffect)(() => {
|
|
3720
3988
|
return () => {
|
|
3721
3989
|
if (abortControllerRef.current) {
|
|
3722
3990
|
abortControllerRef.current.abort();
|
|
@@ -3724,7 +3992,7 @@ function useModels(options = {}) {
|
|
|
3724
3992
|
}
|
|
3725
3993
|
};
|
|
3726
3994
|
}, []);
|
|
3727
|
-
const fetchModels = (0,
|
|
3995
|
+
const fetchModels = (0, import_react7.useCallback)(async () => {
|
|
3728
3996
|
if (abortControllerRef.current) {
|
|
3729
3997
|
abortControllerRef.current.abort();
|
|
3730
3998
|
}
|
|
@@ -3782,12 +4050,12 @@ function useModels(options = {}) {
|
|
|
3782
4050
|
}
|
|
3783
4051
|
}
|
|
3784
4052
|
}, []);
|
|
3785
|
-
const refetch = (0,
|
|
4053
|
+
const refetch = (0, import_react7.useCallback)(async () => {
|
|
3786
4054
|
setModels([]);
|
|
3787
4055
|
await fetchModels();
|
|
3788
4056
|
}, [fetchModels]);
|
|
3789
|
-
const hasFetchedRef = (0,
|
|
3790
|
-
(0,
|
|
4057
|
+
const hasFetchedRef = (0, import_react7.useRef)(false);
|
|
4058
|
+
(0, import_react7.useEffect)(() => {
|
|
3791
4059
|
if (autoFetch && !hasFetchedRef.current) {
|
|
3792
4060
|
hasFetchedRef.current = true;
|
|
3793
4061
|
fetchModels();
|
|
@@ -3805,15 +4073,15 @@ function useModels(options = {}) {
|
|
|
3805
4073
|
}
|
|
3806
4074
|
|
|
3807
4075
|
// src/react/useSearch.ts
|
|
3808
|
-
var
|
|
4076
|
+
var import_react8 = require("react");
|
|
3809
4077
|
function useSearch(options = {}) {
|
|
3810
4078
|
const { getToken, baseUrl = BASE_URL, onError } = options;
|
|
3811
|
-
const [isLoading, setIsLoading] = (0,
|
|
3812
|
-
const [results, setResults] = (0,
|
|
3813
|
-
const [response, setResponse] = (0,
|
|
3814
|
-
const [error, setError] = (0,
|
|
3815
|
-
const abortControllerRef = (0,
|
|
3816
|
-
(0,
|
|
4079
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
4080
|
+
const [results, setResults] = (0, import_react8.useState)(null);
|
|
4081
|
+
const [response, setResponse] = (0, import_react8.useState)(null);
|
|
4082
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
4083
|
+
const abortControllerRef = (0, import_react8.useRef)(null);
|
|
4084
|
+
(0, import_react8.useEffect)(() => {
|
|
3817
4085
|
return () => {
|
|
3818
4086
|
if (abortControllerRef.current) {
|
|
3819
4087
|
abortControllerRef.current.abort();
|
|
@@ -3821,7 +4089,7 @@ function useSearch(options = {}) {
|
|
|
3821
4089
|
}
|
|
3822
4090
|
};
|
|
3823
4091
|
}, []);
|
|
3824
|
-
const search = (0,
|
|
4092
|
+
const search = (0, import_react8.useCallback)(
|
|
3825
4093
|
async (query, searchOptions = {}) => {
|
|
3826
4094
|
if (abortControllerRef.current) {
|
|
3827
4095
|
abortControllerRef.current.abort();
|
|
@@ -3889,12 +4157,12 @@ function useSearch(options = {}) {
|
|
|
3889
4157
|
}
|
|
3890
4158
|
|
|
3891
4159
|
// src/react/useImageGeneration.ts
|
|
3892
|
-
var
|
|
4160
|
+
var import_react9 = require("react");
|
|
3893
4161
|
function useImageGeneration(options = {}) {
|
|
3894
4162
|
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
3895
|
-
const [isLoading, setIsLoading] = (0,
|
|
3896
|
-
const abortControllerRef = (0,
|
|
3897
|
-
(0,
|
|
4163
|
+
const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
|
|
4164
|
+
const abortControllerRef = (0, import_react9.useRef)(null);
|
|
4165
|
+
(0, import_react9.useEffect)(() => {
|
|
3898
4166
|
return () => {
|
|
3899
4167
|
if (abortControllerRef.current) {
|
|
3900
4168
|
abortControllerRef.current.abort();
|
|
@@ -3902,13 +4170,13 @@ function useImageGeneration(options = {}) {
|
|
|
3902
4170
|
}
|
|
3903
4171
|
};
|
|
3904
4172
|
}, []);
|
|
3905
|
-
const stop = (0,
|
|
4173
|
+
const stop = (0, import_react9.useCallback)(() => {
|
|
3906
4174
|
if (abortControllerRef.current) {
|
|
3907
4175
|
abortControllerRef.current.abort();
|
|
3908
4176
|
abortControllerRef.current = null;
|
|
3909
4177
|
}
|
|
3910
4178
|
}, []);
|
|
3911
|
-
const generateImage = (0,
|
|
4179
|
+
const generateImage = (0, import_react9.useCallback)(
|
|
3912
4180
|
async (args) => {
|
|
3913
4181
|
if (abortControllerRef.current) {
|
|
3914
4182
|
abortControllerRef.current.abort();
|
|
@@ -4030,6 +4298,8 @@ var extractConversationContext = (messages, maxMessages = 3) => {
|
|
|
4030
4298
|
ChatMessage,
|
|
4031
4299
|
DEFAULT_TOOL_SELECTOR_MODEL,
|
|
4032
4300
|
StoredMemoryModel,
|
|
4301
|
+
StoredModelPreferenceModel,
|
|
4302
|
+
chatStorageMigrations,
|
|
4033
4303
|
chatStorageSchema,
|
|
4034
4304
|
createMemoryContextSystemMessage,
|
|
4035
4305
|
decryptData,
|
|
@@ -4045,6 +4315,7 @@ var extractConversationContext = (messages, maxMessages = 3) => {
|
|
|
4045
4315
|
memoryStorageSchema,
|
|
4046
4316
|
requestEncryptionKey,
|
|
4047
4317
|
selectTool,
|
|
4318
|
+
settingsStorageSchema,
|
|
4048
4319
|
useChat,
|
|
4049
4320
|
useChatStorage,
|
|
4050
4321
|
useEncryption,
|
|
@@ -4053,5 +4324,6 @@ var extractConversationContext = (messages, maxMessages = 3) => {
|
|
|
4053
4324
|
useModels,
|
|
4054
4325
|
useOCR,
|
|
4055
4326
|
usePdf,
|
|
4056
|
-
useSearch
|
|
4327
|
+
useSearch,
|
|
4328
|
+
useSettings
|
|
4057
4329
|
});
|