@anuma/sdk 2.7.0 → 3.1.0
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/{chunk-TCRDSUC6.mjs → chunk-22CSPJLL.mjs} +164 -891
- package/dist/expo/index.cjs +1812 -1112
- package/dist/expo/index.d.mts +226 -12
- package/dist/expo/index.d.ts +226 -12
- package/dist/expo/index.mjs +1558 -68
- package/dist/expo/{recall-FQU3NUTL.mjs → recall-LICO3TJ7.mjs} +1 -1
- package/dist/index.cjs +418 -395
- package/dist/index.mjs +415 -392
- package/dist/react/{chunk-ZXS3KOY4.mjs → chunk-FD5MB73N.mjs} +158 -1030
- package/dist/react/index.cjs +1839 -1742
- package/dist/react/index.d.mts +150 -14
- package/dist/react/index.d.ts +150 -14
- package/dist/react/index.mjs +1235 -229
- package/dist/react/{recall-PV7L3SN3.mjs → recall-FPACUZGD.mjs} +1 -1
- package/dist/server/{chunk-Z6II54I7.mjs → chunk-RKUNGNBF.mjs} +163 -842
- package/dist/server/index.cjs +392 -970
- package/dist/server/index.d.mts +170 -14
- package/dist/server/index.d.ts +170 -14
- package/dist/server/index.mjs +198 -27
- package/dist/server/{recall-CQT24XLH.mjs → recall-WT5HY2IA.mjs} +1 -1
- package/dist/tools/selection/chunk-4ETHWSXJ.mjs +25 -0
- package/dist/tools/selection/clientConfig-WITO4T6L.mjs +12 -0
- package/dist/tools/selection/index.cjs +1977 -0
- package/dist/tools/selection/index.d.mts +1380 -0
- package/dist/tools/selection/index.d.ts +1380 -0
- package/dist/tools/selection/index.mjs +1859 -0
- package/package.json +8 -1
package/dist/react/index.mjs
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
createConversationOp,
|
|
27
27
|
createMemoryVaultSearchTool,
|
|
28
28
|
createMessageOp,
|
|
29
|
-
createSseClient,
|
|
30
29
|
createSupersedingMemoryOp,
|
|
31
30
|
createVaultEmbeddingCache,
|
|
32
31
|
createVaultMemoriesBatchOp,
|
|
@@ -39,7 +38,6 @@ import {
|
|
|
39
38
|
decryptField,
|
|
40
39
|
decryptJsonField,
|
|
41
40
|
deleteAllVaultMemoriesForUserOp,
|
|
42
|
-
deleteApiV1WalletsBindingByAddress,
|
|
43
41
|
deleteConversationOp,
|
|
44
42
|
deleteVaultMemoryOp,
|
|
45
43
|
eagerEmbedContent,
|
|
@@ -61,18 +59,12 @@ import {
|
|
|
61
59
|
getAllFilesOp,
|
|
62
60
|
getAllVaultMemoriesOp,
|
|
63
61
|
getAllVaultMemoryContentsOp,
|
|
64
|
-
getApiV1Config,
|
|
65
|
-
getApiV1CreditsBalance,
|
|
66
|
-
getApiV1CreditsPacks,
|
|
67
|
-
getApiV1Models,
|
|
68
|
-
getApiV1PhoneCallsByCallId,
|
|
69
|
-
getApiV1SubscriptionsStatus,
|
|
70
|
-
getApiV1WalletsBinding,
|
|
71
62
|
getConversationOp,
|
|
72
63
|
getConversationsByProjectLazyOp,
|
|
73
64
|
getConversationsByProjectOp,
|
|
74
65
|
getConversationsLazyOp,
|
|
75
66
|
getConversationsOp,
|
|
67
|
+
getConversationsPageOp,
|
|
76
68
|
getEncryptionKey,
|
|
77
69
|
getImageModel,
|
|
78
70
|
getMemoriesByEntityNamesOp,
|
|
@@ -94,17 +86,6 @@ import {
|
|
|
94
86
|
makeSyntheticStoredMessage,
|
|
95
87
|
onClearAllEncryptionState,
|
|
96
88
|
onKeyAvailable,
|
|
97
|
-
postApiV1CreditsPurchase,
|
|
98
|
-
postApiV1PhoneCalls,
|
|
99
|
-
postApiV1SubscriptionsCancel,
|
|
100
|
-
postApiV1SubscriptionsCreateCheckoutSession,
|
|
101
|
-
postApiV1SubscriptionsCustomerPortal,
|
|
102
|
-
postApiV1SubscriptionsRenew,
|
|
103
|
-
postApiV1WalletsBinding,
|
|
104
|
-
postApiV1WalletsBindingNonce,
|
|
105
|
-
postAuthOauthByProviderExchange,
|
|
106
|
-
postAuthOauthByProviderRefresh,
|
|
107
|
-
postAuthOauthByProviderRevoke,
|
|
108
89
|
preEmbedVaultMemories,
|
|
109
90
|
recall,
|
|
110
91
|
replaceMemoryEntitiesGuardedOp,
|
|
@@ -131,7 +112,7 @@ import {
|
|
|
131
112
|
updateVaultMemoryOp,
|
|
132
113
|
useEncryption,
|
|
133
114
|
vaultMemoryToStored
|
|
134
|
-
} from "./chunk-
|
|
115
|
+
} from "./chunk-FD5MB73N.mjs";
|
|
135
116
|
import {
|
|
136
117
|
PiiRedactor,
|
|
137
118
|
createStreamingDeAnonymizer,
|
|
@@ -151,9 +132,145 @@ import {
|
|
|
151
132
|
import {
|
|
152
133
|
BASE_URL,
|
|
153
134
|
MCP_R2_DOMAIN,
|
|
154
|
-
__decorateClass
|
|
135
|
+
__decorateClass,
|
|
136
|
+
createClientConfig
|
|
155
137
|
} from "./chunk-GYKJOWEO.mjs";
|
|
156
138
|
|
|
139
|
+
// src/client/core/serverSentEvents.gen.ts
|
|
140
|
+
var createSseClient = ({
|
|
141
|
+
onRequest,
|
|
142
|
+
onSseError,
|
|
143
|
+
onSseEvent,
|
|
144
|
+
responseTransformer,
|
|
145
|
+
responseValidator,
|
|
146
|
+
sseDefaultRetryDelay,
|
|
147
|
+
sseMaxRetryAttempts,
|
|
148
|
+
sseMaxRetryDelay,
|
|
149
|
+
sseSleepFn,
|
|
150
|
+
url,
|
|
151
|
+
...options
|
|
152
|
+
}) => {
|
|
153
|
+
let lastEventId;
|
|
154
|
+
const sleep3 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
155
|
+
const createStream = async function* () {
|
|
156
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
157
|
+
let attempt = 0;
|
|
158
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
159
|
+
while (true) {
|
|
160
|
+
if (signal.aborted) break;
|
|
161
|
+
attempt++;
|
|
162
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
163
|
+
if (lastEventId !== void 0) {
|
|
164
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const requestInit = {
|
|
168
|
+
redirect: "follow",
|
|
169
|
+
...options,
|
|
170
|
+
body: options.serializedBody,
|
|
171
|
+
headers,
|
|
172
|
+
signal
|
|
173
|
+
};
|
|
174
|
+
let request = new Request(url, requestInit);
|
|
175
|
+
if (onRequest) {
|
|
176
|
+
request = await onRequest(url, requestInit);
|
|
177
|
+
}
|
|
178
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
179
|
+
const response = await _fetch(request);
|
|
180
|
+
if (!response.ok)
|
|
181
|
+
throw new Error(
|
|
182
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
183
|
+
);
|
|
184
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
185
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
186
|
+
let buffer = "";
|
|
187
|
+
const abortHandler = () => {
|
|
188
|
+
try {
|
|
189
|
+
reader.cancel();
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
signal.addEventListener("abort", abortHandler);
|
|
194
|
+
try {
|
|
195
|
+
while (true) {
|
|
196
|
+
const { done, value } = await reader.read();
|
|
197
|
+
if (done) break;
|
|
198
|
+
buffer += value;
|
|
199
|
+
const chunks = buffer.split("\n\n");
|
|
200
|
+
buffer = chunks.pop() ?? "";
|
|
201
|
+
for (const chunk of chunks) {
|
|
202
|
+
const lines = chunk.split("\n");
|
|
203
|
+
const dataLines = [];
|
|
204
|
+
let eventName;
|
|
205
|
+
for (const line of lines) {
|
|
206
|
+
if (line.startsWith("data:")) {
|
|
207
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
208
|
+
} else if (line.startsWith("event:")) {
|
|
209
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
210
|
+
} else if (line.startsWith("id:")) {
|
|
211
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
212
|
+
} else if (line.startsWith("retry:")) {
|
|
213
|
+
const parsed = Number.parseInt(
|
|
214
|
+
line.replace(/^retry:\s*/, ""),
|
|
215
|
+
10
|
|
216
|
+
);
|
|
217
|
+
if (!Number.isNaN(parsed)) {
|
|
218
|
+
retryDelay = parsed;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let data;
|
|
223
|
+
let parsedJson = false;
|
|
224
|
+
if (dataLines.length) {
|
|
225
|
+
const rawData = dataLines.join("\n");
|
|
226
|
+
try {
|
|
227
|
+
data = JSON.parse(rawData);
|
|
228
|
+
parsedJson = true;
|
|
229
|
+
} catch {
|
|
230
|
+
data = rawData;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (parsedJson) {
|
|
234
|
+
if (responseValidator) {
|
|
235
|
+
await responseValidator(data);
|
|
236
|
+
}
|
|
237
|
+
if (responseTransformer) {
|
|
238
|
+
data = await responseTransformer(data);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
onSseEvent?.({
|
|
242
|
+
data,
|
|
243
|
+
event: eventName,
|
|
244
|
+
id: lastEventId,
|
|
245
|
+
retry: retryDelay
|
|
246
|
+
});
|
|
247
|
+
if (dataLines.length) {
|
|
248
|
+
yield data;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
} finally {
|
|
253
|
+
signal.removeEventListener("abort", abortHandler);
|
|
254
|
+
reader.releaseLock();
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
} catch (error) {
|
|
258
|
+
onSseError?.(error);
|
|
259
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
const backoff = Math.min(
|
|
263
|
+
retryDelay * 2 ** (attempt - 1),
|
|
264
|
+
sseMaxRetryDelay ?? 3e4
|
|
265
|
+
);
|
|
266
|
+
await sleep3(backoff);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const stream = createStream();
|
|
271
|
+
return { stream };
|
|
272
|
+
};
|
|
273
|
+
|
|
157
274
|
// src/lib/chat/runHooks.ts
|
|
158
275
|
function composeHooks(hooks) {
|
|
159
276
|
const handlers = hooks.filter((h) => h !== void 0 && h !== null);
|
|
@@ -7509,9 +7626,11 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
|
|
|
7509
7626
|
return new LRUCache(maxSize);
|
|
7510
7627
|
}
|
|
7511
7628
|
|
|
7512
|
-
// src/lib/memory/
|
|
7629
|
+
// src/lib/memory/recallConstants.ts
|
|
7513
7630
|
var RECALL_TOOL_NAME = "recall_memory";
|
|
7514
7631
|
var RECALL_MAX_LIMIT = 50;
|
|
7632
|
+
|
|
7633
|
+
// src/lib/memory/recallTool.ts
|
|
7515
7634
|
var DEFAULT_LIMIT = 8;
|
|
7516
7635
|
var DEFAULT_BUDGET = "low";
|
|
7517
7636
|
function formatEventTime(start, end, kind) {
|
|
@@ -8274,6 +8393,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
8274
8393
|
}
|
|
8275
8394
|
|
|
8276
8395
|
// src/lib/processors/encoding.ts
|
|
8396
|
+
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
8277
8397
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
8278
8398
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
8279
8399
|
const response = await fetch(dataUrl);
|
|
@@ -8296,11 +8416,28 @@ function uint8ArrayToBase64(data) {
|
|
|
8296
8416
|
if (typeof Buffer !== "undefined") {
|
|
8297
8417
|
return Buffer.from(data).toString("base64");
|
|
8298
8418
|
}
|
|
8299
|
-
let
|
|
8300
|
-
for (let i = 0; i < data.length; i
|
|
8301
|
-
|
|
8419
|
+
let base64 = "";
|
|
8420
|
+
for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
|
|
8421
|
+
const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
|
|
8422
|
+
let binary = "";
|
|
8423
|
+
for (let j = 0; j < slice.length; j++) {
|
|
8424
|
+
binary += String.fromCharCode(slice[j]);
|
|
8425
|
+
}
|
|
8426
|
+
base64 += btoa(binary);
|
|
8427
|
+
}
|
|
8428
|
+
return base64;
|
|
8429
|
+
}
|
|
8430
|
+
function base64ToUint8Array(base64) {
|
|
8431
|
+
if (typeof Buffer !== "undefined") {
|
|
8432
|
+
const buf = Buffer.from(base64, "base64");
|
|
8433
|
+
return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
|
|
8434
|
+
}
|
|
8435
|
+
const binary = atob(base64);
|
|
8436
|
+
const bytes = new Uint8Array(binary.length);
|
|
8437
|
+
for (let i = 0; i < binary.length; i++) {
|
|
8438
|
+
bytes[i] = binary.charCodeAt(i);
|
|
8302
8439
|
}
|
|
8303
|
-
return
|
|
8440
|
+
return bytes;
|
|
8304
8441
|
}
|
|
8305
8442
|
|
|
8306
8443
|
// src/lib/processors/ExcelProcessor.ts
|
|
@@ -9191,7 +9328,7 @@ function getCachedServerTools() {
|
|
|
9191
9328
|
if (!cached) return null;
|
|
9192
9329
|
const parsed = JSON.parse(cached);
|
|
9193
9330
|
if (parsed.version !== CACHE_VERSION) {
|
|
9194
|
-
|
|
9331
|
+
removeLocalStorageCache();
|
|
9195
9332
|
return null;
|
|
9196
9333
|
}
|
|
9197
9334
|
return parsed;
|
|
@@ -9203,37 +9340,45 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
|
|
|
9203
9340
|
if (!cache) return true;
|
|
9204
9341
|
return Date.now() - cache.timestamp > expirationMs;
|
|
9205
9342
|
}
|
|
9206
|
-
function
|
|
9207
|
-
|
|
9208
|
-
const cacheData = {
|
|
9343
|
+
function buildCacheEntry(tools, checksum) {
|
|
9344
|
+
return {
|
|
9209
9345
|
tools,
|
|
9210
9346
|
timestamp: Date.now(),
|
|
9211
9347
|
version: CACHE_VERSION,
|
|
9212
9348
|
...checksum && { checksum }
|
|
9213
9349
|
};
|
|
9350
|
+
}
|
|
9351
|
+
function writeLocalStorageCache(entry) {
|
|
9352
|
+
if (typeof localStorage === "undefined") return;
|
|
9214
9353
|
try {
|
|
9215
|
-
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(
|
|
9354
|
+
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(entry));
|
|
9216
9355
|
} catch (error) {
|
|
9217
9356
|
getLogger().warn("[serverTools] Failed to cache tools:", error);
|
|
9218
9357
|
}
|
|
9219
9358
|
}
|
|
9220
|
-
function
|
|
9359
|
+
function removeLocalStorageCache() {
|
|
9221
9360
|
if (typeof localStorage === "undefined") return;
|
|
9222
9361
|
localStorage.removeItem(SERVER_TOOLS_CACHE_KEY);
|
|
9223
9362
|
}
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9363
|
+
var localStorageToolsCache = {
|
|
9364
|
+
get: getCachedServerTools,
|
|
9365
|
+
set: writeLocalStorageCache,
|
|
9366
|
+
clear: removeLocalStorageCache
|
|
9367
|
+
};
|
|
9368
|
+
function clearServerToolsCache(cache = localStorageToolsCache) {
|
|
9369
|
+
return cache.clear?.();
|
|
9370
|
+
}
|
|
9371
|
+
function getToolsChecksum2(cache = localStorageToolsCache) {
|
|
9372
|
+
const cached = cache.get();
|
|
9373
|
+
return cached instanceof Promise ? cached.then((c) => c?.checksum) : cached?.checksum;
|
|
9227
9374
|
}
|
|
9228
|
-
function shouldRefreshTools(responseChecksum) {
|
|
9375
|
+
function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
|
|
9229
9376
|
if (!responseChecksum) {
|
|
9230
9377
|
return false;
|
|
9231
9378
|
}
|
|
9232
|
-
const
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
}
|
|
9236
|
-
return cachedChecksum !== responseChecksum;
|
|
9379
|
+
const decide = (cachedChecksum2) => !cachedChecksum2 || cachedChecksum2 !== responseChecksum;
|
|
9380
|
+
const cachedChecksum = getToolsChecksum2(cache);
|
|
9381
|
+
return cachedChecksum instanceof Promise ? cachedChecksum.then(decide) : decide(cachedChecksum);
|
|
9237
9382
|
}
|
|
9238
9383
|
async function fetchServerToolsFromApi(baseUrl, token) {
|
|
9239
9384
|
const response = await fetch(`${baseUrl}/api/v1/tools`, {
|
|
@@ -9255,9 +9400,23 @@ async function getServerTools(options) {
|
|
|
9255
9400
|
cacheExpirationMs = DEFAULT_CACHE_EXPIRATION_MS,
|
|
9256
9401
|
forceRefresh = false,
|
|
9257
9402
|
getToken,
|
|
9258
|
-
apiKey
|
|
9403
|
+
apiKey,
|
|
9404
|
+
cache = localStorageToolsCache
|
|
9259
9405
|
} = options;
|
|
9260
|
-
const
|
|
9406
|
+
const persistCache = async (entry) => {
|
|
9407
|
+
try {
|
|
9408
|
+
await cache.set(entry);
|
|
9409
|
+
} catch (error) {
|
|
9410
|
+
getLogger().warn("[serverTools] Cache write failed (non-fatal):", error);
|
|
9411
|
+
}
|
|
9412
|
+
};
|
|
9413
|
+
let rawCached = null;
|
|
9414
|
+
try {
|
|
9415
|
+
rawCached = await cache.get();
|
|
9416
|
+
} catch (error) {
|
|
9417
|
+
getLogger().warn("[serverTools] Cache read failed; falling through to server fetch:", error);
|
|
9418
|
+
}
|
|
9419
|
+
const cached = rawCached && rawCached.version === CACHE_VERSION ? rawCached : null;
|
|
9261
9420
|
const cacheValid = !isCacheExpired(cached, cacheExpirationMs);
|
|
9262
9421
|
if (cached && cacheValid && !forceRefresh) {
|
|
9263
9422
|
return cached.tools;
|
|
@@ -9278,7 +9437,7 @@ async function getServerTools(options) {
|
|
|
9278
9437
|
}
|
|
9279
9438
|
const data = await response.json();
|
|
9280
9439
|
const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
|
|
9281
|
-
|
|
9440
|
+
await persistCache(buildCacheEntry(tools2, checksum2));
|
|
9282
9441
|
return tools2;
|
|
9283
9442
|
}
|
|
9284
9443
|
if (!getToken) {
|
|
@@ -9291,7 +9450,7 @@ async function getServerTools(options) {
|
|
|
9291
9450
|
return cached?.tools ?? [];
|
|
9292
9451
|
}
|
|
9293
9452
|
const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
|
|
9294
|
-
|
|
9453
|
+
await persistCache(buildCacheEntry(tools, checksum));
|
|
9295
9454
|
return tools;
|
|
9296
9455
|
} catch (error) {
|
|
9297
9456
|
getLogger().error("[serverTools] Failed to fetch server tools:", error);
|
|
@@ -9796,13 +9955,14 @@ async function selectServerToolsForPrompt(options) {
|
|
|
9796
9955
|
baseUrl,
|
|
9797
9956
|
embeddingModel,
|
|
9798
9957
|
cacheExpirationMs,
|
|
9958
|
+
cache,
|
|
9799
9959
|
deferLoading
|
|
9800
9960
|
} = options;
|
|
9801
9961
|
if (serverToolsFilter === void 0) return [];
|
|
9802
9962
|
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
|
|
9803
9963
|
let allServerTools;
|
|
9804
9964
|
try {
|
|
9805
|
-
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken });
|
|
9965
|
+
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken, cache });
|
|
9806
9966
|
} catch {
|
|
9807
9967
|
return [];
|
|
9808
9968
|
}
|
|
@@ -9826,6 +9986,123 @@ async function selectServerToolsForPrompt(options) {
|
|
|
9826
9986
|
return filterServerTools(allServerTools, serverToolsFilter);
|
|
9827
9987
|
}
|
|
9828
9988
|
|
|
9989
|
+
// src/lib/tools/clientToolSelection.ts
|
|
9990
|
+
function getToolName2(t) {
|
|
9991
|
+
const fn = t.function;
|
|
9992
|
+
return fn?.name || t.name || "";
|
|
9993
|
+
}
|
|
9994
|
+
function getToolDescription(t) {
|
|
9995
|
+
const fn = t.function;
|
|
9996
|
+
return fn?.description || t.description || getToolName2(t);
|
|
9997
|
+
}
|
|
9998
|
+
function computeToolGuidance(selectedServerTools, selectedClientTools, extraToolSets, activatedSetNames) {
|
|
9999
|
+
const names = [
|
|
10000
|
+
...selectedServerTools.map((t) => t.name),
|
|
10001
|
+
...(selectedClientTools ?? []).map(getToolName2)
|
|
10002
|
+
].filter(Boolean);
|
|
10003
|
+
const toolSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
10004
|
+
const prompts = toolSetSystemPrompts(names, toolSets, activatedSetNames);
|
|
10005
|
+
return prompts.length > 0 ? prompts.join("\n\n") : void 0;
|
|
10006
|
+
}
|
|
10007
|
+
async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embeddingOptions, extraToolSets = [], activeToolSets = [], noEmbeddingsReason = "short-prompt") {
|
|
10008
|
+
const isMemoryTool = (t) => {
|
|
10009
|
+
const name = getToolName2(t);
|
|
10010
|
+
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME;
|
|
10011
|
+
};
|
|
10012
|
+
const alwaysInclude = clientTools.filter(isMemoryTool);
|
|
10013
|
+
const filterCandidates = clientTools.filter((t) => !isMemoryTool(t));
|
|
10014
|
+
if (filterCandidates.length === 0) {
|
|
10015
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10016
|
+
}
|
|
10017
|
+
if (!promptEmbeddings && noEmbeddingsReason === "error") {
|
|
10018
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10019
|
+
}
|
|
10020
|
+
if (!promptEmbeddings) {
|
|
10021
|
+
if (activeToolSets.length === 0) {
|
|
10022
|
+
return { tools: [], activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10023
|
+
}
|
|
10024
|
+
const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
10025
|
+
const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
|
|
10026
|
+
const stickyMembers = new Set(activeSets.flatMap((s) => s.members));
|
|
10027
|
+
return {
|
|
10028
|
+
tools: [
|
|
10029
|
+
...alwaysInclude,
|
|
10030
|
+
...filterCandidates.filter((t) => stickyMembers.has(getToolName2(t)))
|
|
10031
|
+
],
|
|
10032
|
+
activatedSetNames: new Set(activeSets.map((s) => s.name))
|
|
10033
|
+
};
|
|
10034
|
+
}
|
|
10035
|
+
const toolsNeedingEmbeddings = [];
|
|
10036
|
+
for (const t of filterCandidates) {
|
|
10037
|
+
const name = getToolName2(t);
|
|
10038
|
+
if (name && !cache.has(name)) {
|
|
10039
|
+
toolsNeedingEmbeddings.push({ name, description: getToolDescription(t) });
|
|
10040
|
+
}
|
|
10041
|
+
}
|
|
10042
|
+
if (toolsNeedingEmbeddings.length > 0) {
|
|
10043
|
+
try {
|
|
10044
|
+
const descriptions = toolsNeedingEmbeddings.map((t) => t.description);
|
|
10045
|
+
const embeddings = await generateEmbeddings(descriptions, embeddingOptions);
|
|
10046
|
+
for (let i = 0; i < toolsNeedingEmbeddings.length; i++) {
|
|
10047
|
+
cache.set(toolsNeedingEmbeddings[i].name, embeddings[i]);
|
|
10048
|
+
}
|
|
10049
|
+
} catch {
|
|
10050
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10051
|
+
}
|
|
10052
|
+
}
|
|
10053
|
+
const pseudoServerTools = [];
|
|
10054
|
+
for (const t of filterCandidates) {
|
|
10055
|
+
const name = getToolName2(t);
|
|
10056
|
+
const embedding = cache.get(name);
|
|
10057
|
+
if (!embedding) continue;
|
|
10058
|
+
const fn = t.function;
|
|
10059
|
+
const params = fn?.parameters || fn?.arguments || {
|
|
10060
|
+
type: "object",
|
|
10061
|
+
properties: {},
|
|
10062
|
+
required: []
|
|
10063
|
+
};
|
|
10064
|
+
pseudoServerTools.push({
|
|
10065
|
+
type: "function",
|
|
10066
|
+
name,
|
|
10067
|
+
description: getToolDescription(t),
|
|
10068
|
+
parameters: params,
|
|
10069
|
+
embedding
|
|
10070
|
+
});
|
|
10071
|
+
}
|
|
10072
|
+
const matches = findMatchingTools(promptEmbeddings, pseudoServerTools, {
|
|
10073
|
+
limit: MAX_CLIENT_TOOLS_AFTER_FILTER,
|
|
10074
|
+
minSimilarity: CLIENT_TOOLS_MIN_SIMILARITY,
|
|
10075
|
+
filterAmbiguous: true,
|
|
10076
|
+
// See CLIENT_TOOLS_RELEVANCE_RATIO: 0.75 admits the second intent of a
|
|
10077
|
+
// multi-intent prompt (which lands ~75-80% of the dominant match), while
|
|
10078
|
+
// still trimming the loose tail. The earlier 0.9 made a second intent
|
|
10079
|
+
// structurally unselectable; the anchorMinSimilarity gates (0.53-0.55)
|
|
10080
|
+
// remain the guard against borderline anchors activating a whole set.
|
|
10081
|
+
relevanceRatio: CLIENT_TOOLS_RELEVANCE_RATIO
|
|
10082
|
+
});
|
|
10083
|
+
const matchedNames = new Set(matches.map((m) => m.tool.name));
|
|
10084
|
+
const scores = scoreTools(promptEmbeddings, pseudoServerTools);
|
|
10085
|
+
const availableNames = new Set(filterCandidates.map(getToolName2));
|
|
10086
|
+
const toolSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
10087
|
+
const activeSetNames = activeToolSets.length > 0 ? new Set(activeToolSets) : void 0;
|
|
10088
|
+
const finalNames = expandToolSetsAdditive(
|
|
10089
|
+
matchedNames,
|
|
10090
|
+
availableNames,
|
|
10091
|
+
scores,
|
|
10092
|
+
toolSets,
|
|
10093
|
+
activeSetNames
|
|
10094
|
+
);
|
|
10095
|
+
const activatedSetNames = activatedToolSetNames(scores, toolSets, activeSetNames);
|
|
10096
|
+
if (finalNames.size === 0) {
|
|
10097
|
+
return { tools: alwaysInclude, activatedSetNames };
|
|
10098
|
+
}
|
|
10099
|
+
const filtered = filterCandidates.filter((t) => {
|
|
10100
|
+
const name = getToolName2(t);
|
|
10101
|
+
return name && finalNames.has(name);
|
|
10102
|
+
});
|
|
10103
|
+
return { tools: [...alwaysInclude, ...filtered], activatedSetNames };
|
|
10104
|
+
}
|
|
10105
|
+
|
|
9829
10106
|
// src/react/useChatMedia.ts
|
|
9830
10107
|
import { useCallback as useCallback3 } from "react";
|
|
9831
10108
|
function resolveMediaMeta(extractedKind, urlPath, reportedType) {
|
|
@@ -10075,165 +10352,51 @@ function useChatMedia(options) {
|
|
|
10075
10352
|
}
|
|
10076
10353
|
|
|
10077
10354
|
// src/react/useChatStorage.ts
|
|
10078
|
-
function
|
|
10079
|
-
const
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
const isMemoryTool = (t) => {
|
|
10097
|
-
const name = getToolName2(t);
|
|
10098
|
-
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME;
|
|
10099
|
-
};
|
|
10100
|
-
const alwaysInclude = clientTools.filter(isMemoryTool);
|
|
10101
|
-
const filterCandidates = clientTools.filter((t) => !isMemoryTool(t));
|
|
10102
|
-
if (filterCandidates.length === 0) {
|
|
10103
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10355
|
+
async function previewToolSelection(options) {
|
|
10356
|
+
const {
|
|
10357
|
+
prompt,
|
|
10358
|
+
clientTools = [],
|
|
10359
|
+
serverToolsFilter,
|
|
10360
|
+
serverToolsConfig,
|
|
10361
|
+
getToken,
|
|
10362
|
+
apiKey,
|
|
10363
|
+
baseUrl,
|
|
10364
|
+
embeddingModel = DEFAULT_API_EMBEDDING_MODEL,
|
|
10365
|
+
extraToolSets,
|
|
10366
|
+
activeToolSets,
|
|
10367
|
+
clientToolEmbeddingsCache
|
|
10368
|
+
} = options;
|
|
10369
|
+
if (!getToken && !apiKey) {
|
|
10370
|
+
throw new Error(
|
|
10371
|
+
"previewToolSelection requires either `getToken` (Bearer auth) or `apiKey` (X-API-Key auth) \u2014 without one, embeddings and the server tool catalog cannot be fetched."
|
|
10372
|
+
);
|
|
10104
10373
|
}
|
|
10105
|
-
if (!
|
|
10106
|
-
return {
|
|
10374
|
+
if (!prompt.trim()) {
|
|
10375
|
+
return { clientToolNames: [], serverToolNames: [] };
|
|
10107
10376
|
}
|
|
10108
|
-
if (
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
try {
|
|
10132
|
-
const descriptions = toolsNeedingEmbeddings.map((t) => t.description);
|
|
10133
|
-
const embeddings = await generateEmbeddings(descriptions, embeddingOptions);
|
|
10134
|
-
for (let i = 0; i < toolsNeedingEmbeddings.length; i++) {
|
|
10135
|
-
cache.set(toolsNeedingEmbeddings[i].name, embeddings[i]);
|
|
10136
|
-
}
|
|
10137
|
-
} catch {
|
|
10138
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10139
|
-
}
|
|
10140
|
-
}
|
|
10141
|
-
const pseudoServerTools = [];
|
|
10142
|
-
for (const t of filterCandidates) {
|
|
10143
|
-
const name = getToolName2(t);
|
|
10144
|
-
const embedding = cache.get(name);
|
|
10145
|
-
if (!embedding) continue;
|
|
10146
|
-
const fn = t.function;
|
|
10147
|
-
const params = fn?.parameters || fn?.arguments || {
|
|
10148
|
-
type: "object",
|
|
10149
|
-
properties: {},
|
|
10150
|
-
required: []
|
|
10151
|
-
};
|
|
10152
|
-
pseudoServerTools.push({
|
|
10153
|
-
type: "function",
|
|
10154
|
-
name,
|
|
10155
|
-
description: getToolDescription(t),
|
|
10156
|
-
parameters: params,
|
|
10157
|
-
embedding
|
|
10158
|
-
});
|
|
10159
|
-
}
|
|
10160
|
-
const matches = findMatchingTools(promptEmbeddings, pseudoServerTools, {
|
|
10161
|
-
limit: MAX_CLIENT_TOOLS_AFTER_FILTER,
|
|
10162
|
-
minSimilarity: CLIENT_TOOLS_MIN_SIMILARITY,
|
|
10163
|
-
filterAmbiguous: true,
|
|
10164
|
-
// See CLIENT_TOOLS_RELEVANCE_RATIO: 0.75 admits the second intent of a
|
|
10165
|
-
// multi-intent prompt (which lands ~75-80% of the dominant match), while
|
|
10166
|
-
// still trimming the loose tail. The earlier 0.9 made a second intent
|
|
10167
|
-
// structurally unselectable; the anchorMinSimilarity gates (0.53-0.55)
|
|
10168
|
-
// remain the guard against borderline anchors activating a whole set.
|
|
10169
|
-
relevanceRatio: CLIENT_TOOLS_RELEVANCE_RATIO
|
|
10170
|
-
});
|
|
10171
|
-
const matchedNames = new Set(matches.map((m) => m.tool.name));
|
|
10172
|
-
const scores = scoreTools(promptEmbeddings, pseudoServerTools);
|
|
10173
|
-
const availableNames = new Set(filterCandidates.map(getToolName2));
|
|
10174
|
-
const toolSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
10175
|
-
const activeSetNames = activeToolSets.length > 0 ? new Set(activeToolSets) : void 0;
|
|
10176
|
-
const finalNames = expandToolSetsAdditive(
|
|
10177
|
-
matchedNames,
|
|
10178
|
-
availableNames,
|
|
10179
|
-
scores,
|
|
10180
|
-
toolSets,
|
|
10181
|
-
activeSetNames
|
|
10182
|
-
);
|
|
10183
|
-
const activatedSetNames = activatedToolSetNames(scores, toolSets, activeSetNames);
|
|
10184
|
-
if (finalNames.size === 0) {
|
|
10185
|
-
return { tools: alwaysInclude, activatedSetNames };
|
|
10186
|
-
}
|
|
10187
|
-
const filtered = filterCandidates.filter((t) => {
|
|
10188
|
-
const name = getToolName2(t);
|
|
10189
|
-
return name && finalNames.has(name);
|
|
10190
|
-
});
|
|
10191
|
-
return { tools: [...alwaysInclude, ...filtered], activatedSetNames };
|
|
10192
|
-
}
|
|
10193
|
-
async function previewToolSelection(options) {
|
|
10194
|
-
const {
|
|
10195
|
-
prompt,
|
|
10196
|
-
clientTools = [],
|
|
10197
|
-
serverToolsFilter,
|
|
10198
|
-
serverToolsConfig,
|
|
10199
|
-
getToken,
|
|
10200
|
-
apiKey,
|
|
10201
|
-
baseUrl,
|
|
10202
|
-
embeddingModel = DEFAULT_API_EMBEDDING_MODEL,
|
|
10203
|
-
extraToolSets,
|
|
10204
|
-
activeToolSets,
|
|
10205
|
-
clientToolEmbeddingsCache
|
|
10206
|
-
} = options;
|
|
10207
|
-
if (!getToken && !apiKey) {
|
|
10208
|
-
throw new Error(
|
|
10209
|
-
"previewToolSelection requires either `getToken` (Bearer auth) or `apiKey` (X-API-Key auth) \u2014 without one, embeddings and the server tool catalog cannot be fetched."
|
|
10210
|
-
);
|
|
10211
|
-
}
|
|
10212
|
-
if (!prompt.trim()) {
|
|
10213
|
-
return { clientToolNames: [], serverToolNames: [] };
|
|
10214
|
-
}
|
|
10215
|
-
if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
10216
|
-
const { tools: gatedTools } = await autoFilterClientTools(
|
|
10217
|
-
clientTools,
|
|
10218
|
-
null,
|
|
10219
|
-
clientToolEmbeddingsCache ?? /* @__PURE__ */ new Map(),
|
|
10220
|
-
{ getToken, apiKey, baseUrl, model: embeddingModel },
|
|
10221
|
-
extraToolSets ?? [],
|
|
10222
|
-
activeToolSets ?? []
|
|
10223
|
-
);
|
|
10224
|
-
let gatedServerNames = [];
|
|
10225
|
-
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length > 0) {
|
|
10226
|
-
try {
|
|
10227
|
-
const allServerTools = await getServerTools({
|
|
10228
|
-
baseUrl,
|
|
10229
|
-
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
10230
|
-
getToken,
|
|
10231
|
-
apiKey
|
|
10232
|
-
});
|
|
10233
|
-
const allow = new Set(serverToolsFilter);
|
|
10234
|
-
gatedServerNames = allServerTools.filter((t) => allow.has(t.name)).map((t) => t.name);
|
|
10235
|
-
} catch {
|
|
10236
|
-
}
|
|
10377
|
+
if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
10378
|
+
const { tools: gatedTools } = await autoFilterClientTools(
|
|
10379
|
+
clientTools,
|
|
10380
|
+
null,
|
|
10381
|
+
clientToolEmbeddingsCache ?? /* @__PURE__ */ new Map(),
|
|
10382
|
+
{ getToken, apiKey, baseUrl, model: embeddingModel },
|
|
10383
|
+
extraToolSets ?? [],
|
|
10384
|
+
activeToolSets ?? []
|
|
10385
|
+
);
|
|
10386
|
+
let gatedServerNames = [];
|
|
10387
|
+
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length > 0) {
|
|
10388
|
+
try {
|
|
10389
|
+
const allServerTools = await getServerTools({
|
|
10390
|
+
baseUrl,
|
|
10391
|
+
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
10392
|
+
getToken,
|
|
10393
|
+
apiKey,
|
|
10394
|
+
cache: serverToolsConfig?.cache
|
|
10395
|
+
});
|
|
10396
|
+
const allow = new Set(serverToolsFilter);
|
|
10397
|
+
gatedServerNames = allServerTools.filter((t) => allow.has(t.name)).map((t) => t.name);
|
|
10398
|
+
} catch {
|
|
10399
|
+
}
|
|
10237
10400
|
}
|
|
10238
10401
|
return {
|
|
10239
10402
|
clientToolNames: gatedTools.map(getToolName2).filter(Boolean),
|
|
@@ -10276,7 +10439,8 @@ async function previewToolSelection(options) {
|
|
|
10276
10439
|
baseUrl,
|
|
10277
10440
|
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
10278
10441
|
getToken,
|
|
10279
|
-
apiKey
|
|
10442
|
+
apiKey,
|
|
10443
|
+
cache: serverToolsConfig?.cache
|
|
10280
10444
|
});
|
|
10281
10445
|
if (serverToolsConfig?.deferLoading?.enabled) {
|
|
10282
10446
|
serverToolNames = allServerTools.map((t) => t.name);
|
|
@@ -11269,7 +11433,8 @@ function useChatStorage(options) {
|
|
|
11269
11433
|
const allServerTools = await getServerTools({
|
|
11270
11434
|
baseUrl,
|
|
11271
11435
|
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
11272
|
-
getToken
|
|
11436
|
+
getToken,
|
|
11437
|
+
cache: serverToolsConfig?.cache
|
|
11273
11438
|
});
|
|
11274
11439
|
if (serverToolsConfig?.deferLoading?.enabled) {
|
|
11275
11440
|
filteredServerTools2 = allServerTools;
|
|
@@ -11287,12 +11452,14 @@ function useChatStorage(options) {
|
|
|
11287
11452
|
let filteredClientTools2 = clientTools;
|
|
11288
11453
|
let clientActivatedSetNames2;
|
|
11289
11454
|
if (clientToolsFilter && clientTools?.length) {
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11455
|
+
if (!skipStorageEmbeddingsFailed) {
|
|
11456
|
+
const clientToolNames = clientToolsFilter(skipStorageEmbeddings, clientTools);
|
|
11457
|
+
filteredClientTools2 = clientTools.filter((t) => {
|
|
11458
|
+
const fn = t.function;
|
|
11459
|
+
const name = fn?.name || t.name;
|
|
11460
|
+
return clientToolNames.includes(name);
|
|
11461
|
+
});
|
|
11462
|
+
}
|
|
11296
11463
|
} else if (clientTools?.length && getToken) {
|
|
11297
11464
|
const clientFilterResult = await autoFilterClientTools(
|
|
11298
11465
|
clientTools,
|
|
@@ -11359,8 +11526,20 @@ function useChatStorage(options) {
|
|
|
11359
11526
|
error: result2.error || "Unknown error"
|
|
11360
11527
|
};
|
|
11361
11528
|
}
|
|
11362
|
-
|
|
11363
|
-
|
|
11529
|
+
const refreshResponse = result2.data;
|
|
11530
|
+
if (getToken) {
|
|
11531
|
+
Promise.resolve().then(
|
|
11532
|
+
() => shouldRefreshTools(getToolsChecksum(refreshResponse), serverToolsConfig?.cache)
|
|
11533
|
+
).then((refresh) => {
|
|
11534
|
+
if (refresh) {
|
|
11535
|
+
return getServerTools({
|
|
11536
|
+
baseUrl,
|
|
11537
|
+
getToken,
|
|
11538
|
+
forceRefresh: true,
|
|
11539
|
+
cache: serverToolsConfig?.cache
|
|
11540
|
+
});
|
|
11541
|
+
}
|
|
11542
|
+
}).catch((err) => {
|
|
11364
11543
|
getLogger().warn("[useChatStorage] Failed to refresh server tools cache:", err);
|
|
11365
11544
|
});
|
|
11366
11545
|
}
|
|
@@ -11627,7 +11806,8 @@ function useChatStorage(options) {
|
|
|
11627
11806
|
const allServerTools = await getServerTools({
|
|
11628
11807
|
baseUrl,
|
|
11629
11808
|
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
11630
|
-
getToken
|
|
11809
|
+
getToken,
|
|
11810
|
+
cache: serverToolsConfig?.cache
|
|
11631
11811
|
});
|
|
11632
11812
|
if (serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") {
|
|
11633
11813
|
filteredServerTools = allServerTools;
|
|
@@ -11645,12 +11825,14 @@ function useChatStorage(options) {
|
|
|
11645
11825
|
let filteredClientTools = clientTools;
|
|
11646
11826
|
let clientActivatedSetNames;
|
|
11647
11827
|
if (clientToolsFilter && clientTools?.length) {
|
|
11648
|
-
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
|
|
11653
|
-
|
|
11828
|
+
if (!userMessageEmbeddingsFailed) {
|
|
11829
|
+
const clientToolNames = clientToolsFilter(userMessageEmbeddings ?? null, clientTools);
|
|
11830
|
+
filteredClientTools = clientTools.filter((t) => {
|
|
11831
|
+
const fn = t.function;
|
|
11832
|
+
const name = fn?.name || t.name;
|
|
11833
|
+
return clientToolNames.includes(name);
|
|
11834
|
+
});
|
|
11835
|
+
}
|
|
11654
11836
|
} else if (clientTools?.length && getToken) {
|
|
11655
11837
|
const clientFilterResult = await autoFilterClientTools(
|
|
11656
11838
|
clientTools,
|
|
@@ -11970,8 +12152,17 @@ Based on these results, continue with the task.`;
|
|
|
11970
12152
|
} catch {
|
|
11971
12153
|
}
|
|
11972
12154
|
}
|
|
11973
|
-
if (getToken
|
|
11974
|
-
|
|
12155
|
+
if (getToken) {
|
|
12156
|
+
Promise.resolve().then(() => shouldRefreshTools(getToolsChecksum(responseData), serverToolsConfig?.cache)).then((refresh) => {
|
|
12157
|
+
if (refresh) {
|
|
12158
|
+
return getServerTools({
|
|
12159
|
+
baseUrl,
|
|
12160
|
+
getToken,
|
|
12161
|
+
forceRefresh: true,
|
|
12162
|
+
cache: serverToolsConfig?.cache
|
|
12163
|
+
});
|
|
12164
|
+
}
|
|
12165
|
+
}).catch((err) => {
|
|
11975
12166
|
getLogger().warn("[useChatStorage] Failed to refresh server tools cache:", err);
|
|
11976
12167
|
});
|
|
11977
12168
|
}
|
|
@@ -15980,6 +16171,824 @@ function useVoice(options) {
|
|
|
15980
16171
|
|
|
15981
16172
|
// src/react/useCredits.ts
|
|
15982
16173
|
import { useCallback as useCallback12, useEffect as useEffect6, useRef as useRef6, useState as useState11 } from "react";
|
|
16174
|
+
|
|
16175
|
+
// src/client/core/bodySerializer.gen.ts
|
|
16176
|
+
var jsonBodySerializer = {
|
|
16177
|
+
bodySerializer: (body) => JSON.stringify(
|
|
16178
|
+
body,
|
|
16179
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
16180
|
+
)
|
|
16181
|
+
};
|
|
16182
|
+
|
|
16183
|
+
// src/client/core/pathSerializer.gen.ts
|
|
16184
|
+
var separatorArrayExplode = (style) => {
|
|
16185
|
+
switch (style) {
|
|
16186
|
+
case "label":
|
|
16187
|
+
return ".";
|
|
16188
|
+
case "matrix":
|
|
16189
|
+
return ";";
|
|
16190
|
+
case "simple":
|
|
16191
|
+
return ",";
|
|
16192
|
+
default:
|
|
16193
|
+
return "&";
|
|
16194
|
+
}
|
|
16195
|
+
};
|
|
16196
|
+
var separatorArrayNoExplode = (style) => {
|
|
16197
|
+
switch (style) {
|
|
16198
|
+
case "form":
|
|
16199
|
+
return ",";
|
|
16200
|
+
case "pipeDelimited":
|
|
16201
|
+
return "|";
|
|
16202
|
+
case "spaceDelimited":
|
|
16203
|
+
return "%20";
|
|
16204
|
+
default:
|
|
16205
|
+
return ",";
|
|
16206
|
+
}
|
|
16207
|
+
};
|
|
16208
|
+
var separatorObjectExplode = (style) => {
|
|
16209
|
+
switch (style) {
|
|
16210
|
+
case "label":
|
|
16211
|
+
return ".";
|
|
16212
|
+
case "matrix":
|
|
16213
|
+
return ";";
|
|
16214
|
+
case "simple":
|
|
16215
|
+
return ",";
|
|
16216
|
+
default:
|
|
16217
|
+
return "&";
|
|
16218
|
+
}
|
|
16219
|
+
};
|
|
16220
|
+
var serializeArrayParam = ({
|
|
16221
|
+
allowReserved,
|
|
16222
|
+
explode,
|
|
16223
|
+
name,
|
|
16224
|
+
style,
|
|
16225
|
+
value
|
|
16226
|
+
}) => {
|
|
16227
|
+
if (!explode) {
|
|
16228
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
16229
|
+
switch (style) {
|
|
16230
|
+
case "label":
|
|
16231
|
+
return `.${joinedValues2}`;
|
|
16232
|
+
case "matrix":
|
|
16233
|
+
return `;${name}=${joinedValues2}`;
|
|
16234
|
+
case "simple":
|
|
16235
|
+
return joinedValues2;
|
|
16236
|
+
default:
|
|
16237
|
+
return `${name}=${joinedValues2}`;
|
|
16238
|
+
}
|
|
16239
|
+
}
|
|
16240
|
+
const separator = separatorArrayExplode(style);
|
|
16241
|
+
const joinedValues = value.map((v) => {
|
|
16242
|
+
if (style === "label" || style === "simple") {
|
|
16243
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
16244
|
+
}
|
|
16245
|
+
return serializePrimitiveParam({
|
|
16246
|
+
allowReserved,
|
|
16247
|
+
name,
|
|
16248
|
+
value: v
|
|
16249
|
+
});
|
|
16250
|
+
}).join(separator);
|
|
16251
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
16252
|
+
};
|
|
16253
|
+
var serializePrimitiveParam = ({
|
|
16254
|
+
allowReserved,
|
|
16255
|
+
name,
|
|
16256
|
+
value
|
|
16257
|
+
}) => {
|
|
16258
|
+
if (value === void 0 || value === null) {
|
|
16259
|
+
return "";
|
|
16260
|
+
}
|
|
16261
|
+
if (typeof value === "object") {
|
|
16262
|
+
throw new Error(
|
|
16263
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
16264
|
+
);
|
|
16265
|
+
}
|
|
16266
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
16267
|
+
};
|
|
16268
|
+
var serializeObjectParam = ({
|
|
16269
|
+
allowReserved,
|
|
16270
|
+
explode,
|
|
16271
|
+
name,
|
|
16272
|
+
style,
|
|
16273
|
+
value,
|
|
16274
|
+
valueOnly
|
|
16275
|
+
}) => {
|
|
16276
|
+
if (value instanceof Date) {
|
|
16277
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
16278
|
+
}
|
|
16279
|
+
if (style !== "deepObject" && !explode) {
|
|
16280
|
+
let values = [];
|
|
16281
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
16282
|
+
values = [
|
|
16283
|
+
...values,
|
|
16284
|
+
key,
|
|
16285
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
16286
|
+
];
|
|
16287
|
+
});
|
|
16288
|
+
const joinedValues2 = values.join(",");
|
|
16289
|
+
switch (style) {
|
|
16290
|
+
case "form":
|
|
16291
|
+
return `${name}=${joinedValues2}`;
|
|
16292
|
+
case "label":
|
|
16293
|
+
return `.${joinedValues2}`;
|
|
16294
|
+
case "matrix":
|
|
16295
|
+
return `;${name}=${joinedValues2}`;
|
|
16296
|
+
default:
|
|
16297
|
+
return joinedValues2;
|
|
16298
|
+
}
|
|
16299
|
+
}
|
|
16300
|
+
const separator = separatorObjectExplode(style);
|
|
16301
|
+
const joinedValues = Object.entries(value).map(
|
|
16302
|
+
([key, v]) => serializePrimitiveParam({
|
|
16303
|
+
allowReserved,
|
|
16304
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
16305
|
+
value: v
|
|
16306
|
+
})
|
|
16307
|
+
).join(separator);
|
|
16308
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
16309
|
+
};
|
|
16310
|
+
|
|
16311
|
+
// src/client/core/utils.gen.ts
|
|
16312
|
+
function getValidRequestBody(options) {
|
|
16313
|
+
const hasBody = options.body !== void 0;
|
|
16314
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
16315
|
+
if (isSerializedBody) {
|
|
16316
|
+
if ("serializedBody" in options) {
|
|
16317
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
16318
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
16319
|
+
}
|
|
16320
|
+
return options.body !== "" ? options.body : null;
|
|
16321
|
+
}
|
|
16322
|
+
if (hasBody) {
|
|
16323
|
+
return options.body;
|
|
16324
|
+
}
|
|
16325
|
+
return void 0;
|
|
16326
|
+
}
|
|
16327
|
+
|
|
16328
|
+
// src/client/core/auth.gen.ts
|
|
16329
|
+
var getAuthToken = async (auth, callback) => {
|
|
16330
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
16331
|
+
if (!token) {
|
|
16332
|
+
return;
|
|
16333
|
+
}
|
|
16334
|
+
if (auth.scheme === "bearer") {
|
|
16335
|
+
return `Bearer ${token}`;
|
|
16336
|
+
}
|
|
16337
|
+
if (auth.scheme === "basic") {
|
|
16338
|
+
return `Basic ${btoa(token)}`;
|
|
16339
|
+
}
|
|
16340
|
+
return token;
|
|
16341
|
+
};
|
|
16342
|
+
|
|
16343
|
+
// src/client/client/utils.gen.ts
|
|
16344
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
16345
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
16346
|
+
let url = _url;
|
|
16347
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
16348
|
+
if (matches) {
|
|
16349
|
+
for (const match of matches) {
|
|
16350
|
+
let explode = false;
|
|
16351
|
+
let name = match.substring(1, match.length - 1);
|
|
16352
|
+
let style = "simple";
|
|
16353
|
+
if (name.endsWith("*")) {
|
|
16354
|
+
explode = true;
|
|
16355
|
+
name = name.substring(0, name.length - 1);
|
|
16356
|
+
}
|
|
16357
|
+
if (name.startsWith(".")) {
|
|
16358
|
+
name = name.substring(1);
|
|
16359
|
+
style = "label";
|
|
16360
|
+
} else if (name.startsWith(";")) {
|
|
16361
|
+
name = name.substring(1);
|
|
16362
|
+
style = "matrix";
|
|
16363
|
+
}
|
|
16364
|
+
const value = path[name];
|
|
16365
|
+
if (value === void 0 || value === null) {
|
|
16366
|
+
continue;
|
|
16367
|
+
}
|
|
16368
|
+
if (Array.isArray(value)) {
|
|
16369
|
+
url = url.replace(
|
|
16370
|
+
match,
|
|
16371
|
+
serializeArrayParam({ explode, name, style, value })
|
|
16372
|
+
);
|
|
16373
|
+
continue;
|
|
16374
|
+
}
|
|
16375
|
+
if (typeof value === "object") {
|
|
16376
|
+
url = url.replace(
|
|
16377
|
+
match,
|
|
16378
|
+
serializeObjectParam({
|
|
16379
|
+
explode,
|
|
16380
|
+
name,
|
|
16381
|
+
style,
|
|
16382
|
+
value,
|
|
16383
|
+
valueOnly: true
|
|
16384
|
+
})
|
|
16385
|
+
);
|
|
16386
|
+
continue;
|
|
16387
|
+
}
|
|
16388
|
+
if (style === "matrix") {
|
|
16389
|
+
url = url.replace(
|
|
16390
|
+
match,
|
|
16391
|
+
`;${serializePrimitiveParam({
|
|
16392
|
+
name,
|
|
16393
|
+
value
|
|
16394
|
+
})}`
|
|
16395
|
+
);
|
|
16396
|
+
continue;
|
|
16397
|
+
}
|
|
16398
|
+
const replaceValue = encodeURIComponent(
|
|
16399
|
+
style === "label" ? `.${value}` : value
|
|
16400
|
+
);
|
|
16401
|
+
url = url.replace(match, replaceValue);
|
|
16402
|
+
}
|
|
16403
|
+
}
|
|
16404
|
+
return url;
|
|
16405
|
+
};
|
|
16406
|
+
var createQuerySerializer = ({
|
|
16407
|
+
parameters = {},
|
|
16408
|
+
...args
|
|
16409
|
+
} = {}) => {
|
|
16410
|
+
const querySerializer = (queryParams) => {
|
|
16411
|
+
const search = [];
|
|
16412
|
+
if (queryParams && typeof queryParams === "object") {
|
|
16413
|
+
for (const name in queryParams) {
|
|
16414
|
+
const value = queryParams[name];
|
|
16415
|
+
if (value === void 0 || value === null) {
|
|
16416
|
+
continue;
|
|
16417
|
+
}
|
|
16418
|
+
const options = parameters[name] || args;
|
|
16419
|
+
if (Array.isArray(value)) {
|
|
16420
|
+
const serializedArray = serializeArrayParam({
|
|
16421
|
+
allowReserved: options.allowReserved,
|
|
16422
|
+
explode: true,
|
|
16423
|
+
name,
|
|
16424
|
+
style: "form",
|
|
16425
|
+
value,
|
|
16426
|
+
...options.array
|
|
16427
|
+
});
|
|
16428
|
+
if (serializedArray) search.push(serializedArray);
|
|
16429
|
+
} else if (typeof value === "object") {
|
|
16430
|
+
const serializedObject = serializeObjectParam({
|
|
16431
|
+
allowReserved: options.allowReserved,
|
|
16432
|
+
explode: true,
|
|
16433
|
+
name,
|
|
16434
|
+
style: "deepObject",
|
|
16435
|
+
value,
|
|
16436
|
+
...options.object
|
|
16437
|
+
});
|
|
16438
|
+
if (serializedObject) search.push(serializedObject);
|
|
16439
|
+
} else {
|
|
16440
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
16441
|
+
allowReserved: options.allowReserved,
|
|
16442
|
+
name,
|
|
16443
|
+
value
|
|
16444
|
+
});
|
|
16445
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
16446
|
+
}
|
|
16447
|
+
}
|
|
16448
|
+
}
|
|
16449
|
+
return search.join("&");
|
|
16450
|
+
};
|
|
16451
|
+
return querySerializer;
|
|
16452
|
+
};
|
|
16453
|
+
var getParseAs = (contentType) => {
|
|
16454
|
+
if (!contentType) {
|
|
16455
|
+
return "stream";
|
|
16456
|
+
}
|
|
16457
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
16458
|
+
if (!cleanContent) {
|
|
16459
|
+
return;
|
|
16460
|
+
}
|
|
16461
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
16462
|
+
return "json";
|
|
16463
|
+
}
|
|
16464
|
+
if (cleanContent === "multipart/form-data") {
|
|
16465
|
+
return "formData";
|
|
16466
|
+
}
|
|
16467
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
16468
|
+
(type) => cleanContent.startsWith(type)
|
|
16469
|
+
)) {
|
|
16470
|
+
return "blob";
|
|
16471
|
+
}
|
|
16472
|
+
if (cleanContent.startsWith("text/")) {
|
|
16473
|
+
return "text";
|
|
16474
|
+
}
|
|
16475
|
+
return;
|
|
16476
|
+
};
|
|
16477
|
+
var checkForExistence = (options, name) => {
|
|
16478
|
+
if (!name) {
|
|
16479
|
+
return false;
|
|
16480
|
+
}
|
|
16481
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
16482
|
+
return true;
|
|
16483
|
+
}
|
|
16484
|
+
return false;
|
|
16485
|
+
};
|
|
16486
|
+
var setAuthParams = async ({
|
|
16487
|
+
security,
|
|
16488
|
+
...options
|
|
16489
|
+
}) => {
|
|
16490
|
+
for (const auth of security) {
|
|
16491
|
+
if (checkForExistence(options, auth.name)) {
|
|
16492
|
+
continue;
|
|
16493
|
+
}
|
|
16494
|
+
const token = await getAuthToken(auth, options.auth);
|
|
16495
|
+
if (!token) {
|
|
16496
|
+
continue;
|
|
16497
|
+
}
|
|
16498
|
+
const name = auth.name ?? "Authorization";
|
|
16499
|
+
switch (auth.in) {
|
|
16500
|
+
case "query":
|
|
16501
|
+
if (!options.query) {
|
|
16502
|
+
options.query = {};
|
|
16503
|
+
}
|
|
16504
|
+
options.query[name] = token;
|
|
16505
|
+
break;
|
|
16506
|
+
case "cookie":
|
|
16507
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
16508
|
+
break;
|
|
16509
|
+
case "header":
|
|
16510
|
+
default:
|
|
16511
|
+
options.headers.set(name, token);
|
|
16512
|
+
break;
|
|
16513
|
+
}
|
|
16514
|
+
}
|
|
16515
|
+
};
|
|
16516
|
+
var buildUrl = (options) => {
|
|
16517
|
+
const url = getUrl({
|
|
16518
|
+
baseUrl: options.baseUrl,
|
|
16519
|
+
path: options.path,
|
|
16520
|
+
query: options.query,
|
|
16521
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
16522
|
+
url: options.url
|
|
16523
|
+
});
|
|
16524
|
+
return url;
|
|
16525
|
+
};
|
|
16526
|
+
var getUrl = ({
|
|
16527
|
+
baseUrl,
|
|
16528
|
+
path,
|
|
16529
|
+
query,
|
|
16530
|
+
querySerializer,
|
|
16531
|
+
url: _url
|
|
16532
|
+
}) => {
|
|
16533
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
16534
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
16535
|
+
if (path) {
|
|
16536
|
+
url = defaultPathSerializer({ path, url });
|
|
16537
|
+
}
|
|
16538
|
+
let search = query ? querySerializer(query) : "";
|
|
16539
|
+
if (search.startsWith("?")) {
|
|
16540
|
+
search = search.substring(1);
|
|
16541
|
+
}
|
|
16542
|
+
if (search) {
|
|
16543
|
+
url += `?${search}`;
|
|
16544
|
+
}
|
|
16545
|
+
return url;
|
|
16546
|
+
};
|
|
16547
|
+
var mergeConfigs = (a, b) => {
|
|
16548
|
+
const config = { ...a, ...b };
|
|
16549
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
16550
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
16551
|
+
}
|
|
16552
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
16553
|
+
return config;
|
|
16554
|
+
};
|
|
16555
|
+
var headersEntries = (headers) => {
|
|
16556
|
+
const entries = [];
|
|
16557
|
+
headers.forEach((value, key) => {
|
|
16558
|
+
entries.push([key, value]);
|
|
16559
|
+
});
|
|
16560
|
+
return entries;
|
|
16561
|
+
};
|
|
16562
|
+
var mergeHeaders = (...headers) => {
|
|
16563
|
+
const mergedHeaders = new Headers();
|
|
16564
|
+
for (const header of headers) {
|
|
16565
|
+
if (!header || typeof header !== "object") {
|
|
16566
|
+
continue;
|
|
16567
|
+
}
|
|
16568
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
16569
|
+
for (const [key, value] of iterator) {
|
|
16570
|
+
if (value === null) {
|
|
16571
|
+
mergedHeaders.delete(key);
|
|
16572
|
+
} else if (Array.isArray(value)) {
|
|
16573
|
+
for (const v of value) {
|
|
16574
|
+
mergedHeaders.append(key, v);
|
|
16575
|
+
}
|
|
16576
|
+
} else if (value !== void 0) {
|
|
16577
|
+
mergedHeaders.set(
|
|
16578
|
+
key,
|
|
16579
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
16580
|
+
);
|
|
16581
|
+
}
|
|
16582
|
+
}
|
|
16583
|
+
}
|
|
16584
|
+
return mergedHeaders;
|
|
16585
|
+
};
|
|
16586
|
+
var Interceptors = class {
|
|
16587
|
+
constructor() {
|
|
16588
|
+
this.fns = [];
|
|
16589
|
+
}
|
|
16590
|
+
clear() {
|
|
16591
|
+
this.fns = [];
|
|
16592
|
+
}
|
|
16593
|
+
eject(id) {
|
|
16594
|
+
const index = this.getInterceptorIndex(id);
|
|
16595
|
+
if (this.fns[index]) {
|
|
16596
|
+
this.fns[index] = null;
|
|
16597
|
+
}
|
|
16598
|
+
}
|
|
16599
|
+
exists(id) {
|
|
16600
|
+
const index = this.getInterceptorIndex(id);
|
|
16601
|
+
return Boolean(this.fns[index]);
|
|
16602
|
+
}
|
|
16603
|
+
getInterceptorIndex(id) {
|
|
16604
|
+
if (typeof id === "number") {
|
|
16605
|
+
return this.fns[id] ? id : -1;
|
|
16606
|
+
}
|
|
16607
|
+
return this.fns.indexOf(id);
|
|
16608
|
+
}
|
|
16609
|
+
update(id, fn) {
|
|
16610
|
+
const index = this.getInterceptorIndex(id);
|
|
16611
|
+
if (this.fns[index]) {
|
|
16612
|
+
this.fns[index] = fn;
|
|
16613
|
+
return id;
|
|
16614
|
+
}
|
|
16615
|
+
return false;
|
|
16616
|
+
}
|
|
16617
|
+
use(fn) {
|
|
16618
|
+
this.fns.push(fn);
|
|
16619
|
+
return this.fns.length - 1;
|
|
16620
|
+
}
|
|
16621
|
+
};
|
|
16622
|
+
var createInterceptors = () => ({
|
|
16623
|
+
error: new Interceptors(),
|
|
16624
|
+
request: new Interceptors(),
|
|
16625
|
+
response: new Interceptors()
|
|
16626
|
+
});
|
|
16627
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
16628
|
+
allowReserved: false,
|
|
16629
|
+
array: {
|
|
16630
|
+
explode: true,
|
|
16631
|
+
style: "form"
|
|
16632
|
+
},
|
|
16633
|
+
object: {
|
|
16634
|
+
explode: true,
|
|
16635
|
+
style: "deepObject"
|
|
16636
|
+
}
|
|
16637
|
+
});
|
|
16638
|
+
var defaultHeaders = {
|
|
16639
|
+
"Content-Type": "application/json"
|
|
16640
|
+
};
|
|
16641
|
+
var createConfig = (override = {}) => ({
|
|
16642
|
+
...jsonBodySerializer,
|
|
16643
|
+
headers: defaultHeaders,
|
|
16644
|
+
parseAs: "auto",
|
|
16645
|
+
querySerializer: defaultQuerySerializer,
|
|
16646
|
+
...override
|
|
16647
|
+
});
|
|
16648
|
+
|
|
16649
|
+
// src/client/client/client.gen.ts
|
|
16650
|
+
var createClient = (config = {}) => {
|
|
16651
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
16652
|
+
const getConfig = () => ({ ..._config });
|
|
16653
|
+
const setConfig = (config2) => {
|
|
16654
|
+
_config = mergeConfigs(_config, config2);
|
|
16655
|
+
return getConfig();
|
|
16656
|
+
};
|
|
16657
|
+
const interceptors = createInterceptors();
|
|
16658
|
+
const beforeRequest = async (options) => {
|
|
16659
|
+
const opts = {
|
|
16660
|
+
..._config,
|
|
16661
|
+
...options,
|
|
16662
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
16663
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
16664
|
+
serializedBody: void 0
|
|
16665
|
+
};
|
|
16666
|
+
if (opts.security) {
|
|
16667
|
+
await setAuthParams({
|
|
16668
|
+
...opts,
|
|
16669
|
+
security: opts.security
|
|
16670
|
+
});
|
|
16671
|
+
}
|
|
16672
|
+
if (opts.requestValidator) {
|
|
16673
|
+
await opts.requestValidator(opts);
|
|
16674
|
+
}
|
|
16675
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
16676
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
16677
|
+
}
|
|
16678
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
16679
|
+
opts.headers.delete("Content-Type");
|
|
16680
|
+
}
|
|
16681
|
+
const url = buildUrl(opts);
|
|
16682
|
+
return { opts, url };
|
|
16683
|
+
};
|
|
16684
|
+
const request = async (options) => {
|
|
16685
|
+
const { opts, url } = await beforeRequest(options);
|
|
16686
|
+
for (const fn of interceptors.request.fns) {
|
|
16687
|
+
if (fn) {
|
|
16688
|
+
await fn(opts);
|
|
16689
|
+
}
|
|
16690
|
+
}
|
|
16691
|
+
const _fetch = opts.fetch;
|
|
16692
|
+
const requestInit = {
|
|
16693
|
+
...opts,
|
|
16694
|
+
body: getValidRequestBody(opts)
|
|
16695
|
+
};
|
|
16696
|
+
let response = await _fetch(url, requestInit);
|
|
16697
|
+
for (const fn of interceptors.response.fns) {
|
|
16698
|
+
if (fn) {
|
|
16699
|
+
response = await fn(response, opts);
|
|
16700
|
+
}
|
|
16701
|
+
}
|
|
16702
|
+
const result = {
|
|
16703
|
+
response
|
|
16704
|
+
};
|
|
16705
|
+
if (response.ok) {
|
|
16706
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
16707
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
16708
|
+
let emptyData;
|
|
16709
|
+
switch (parseAs) {
|
|
16710
|
+
case "arrayBuffer":
|
|
16711
|
+
case "blob":
|
|
16712
|
+
case "text":
|
|
16713
|
+
emptyData = await response[parseAs]();
|
|
16714
|
+
break;
|
|
16715
|
+
case "formData":
|
|
16716
|
+
emptyData = new FormData();
|
|
16717
|
+
break;
|
|
16718
|
+
case "stream":
|
|
16719
|
+
emptyData = response.body;
|
|
16720
|
+
break;
|
|
16721
|
+
case "json":
|
|
16722
|
+
default:
|
|
16723
|
+
emptyData = {};
|
|
16724
|
+
break;
|
|
16725
|
+
}
|
|
16726
|
+
return {
|
|
16727
|
+
data: emptyData,
|
|
16728
|
+
...result
|
|
16729
|
+
};
|
|
16730
|
+
}
|
|
16731
|
+
let data;
|
|
16732
|
+
switch (parseAs) {
|
|
16733
|
+
case "arrayBuffer":
|
|
16734
|
+
case "blob":
|
|
16735
|
+
case "formData":
|
|
16736
|
+
case "json":
|
|
16737
|
+
case "text":
|
|
16738
|
+
data = await response[parseAs]();
|
|
16739
|
+
break;
|
|
16740
|
+
case "stream":
|
|
16741
|
+
return {
|
|
16742
|
+
data: response.body,
|
|
16743
|
+
...result
|
|
16744
|
+
};
|
|
16745
|
+
}
|
|
16746
|
+
if (parseAs === "json") {
|
|
16747
|
+
if (opts.responseValidator) {
|
|
16748
|
+
await opts.responseValidator(data);
|
|
16749
|
+
}
|
|
16750
|
+
if (opts.responseTransformer) {
|
|
16751
|
+
data = await opts.responseTransformer(data);
|
|
16752
|
+
}
|
|
16753
|
+
}
|
|
16754
|
+
return {
|
|
16755
|
+
data,
|
|
16756
|
+
...result
|
|
16757
|
+
};
|
|
16758
|
+
}
|
|
16759
|
+
const textError = await response.text();
|
|
16760
|
+
let jsonError;
|
|
16761
|
+
try {
|
|
16762
|
+
jsonError = JSON.parse(textError);
|
|
16763
|
+
} catch {
|
|
16764
|
+
}
|
|
16765
|
+
const error = jsonError ?? textError;
|
|
16766
|
+
let finalError = error;
|
|
16767
|
+
for (const fn of interceptors.error.fns) {
|
|
16768
|
+
if (fn) {
|
|
16769
|
+
finalError = await fn(error, response, opts);
|
|
16770
|
+
}
|
|
16771
|
+
}
|
|
16772
|
+
finalError = finalError || {};
|
|
16773
|
+
if (opts.throwOnError) {
|
|
16774
|
+
throw finalError;
|
|
16775
|
+
}
|
|
16776
|
+
return {
|
|
16777
|
+
error: finalError,
|
|
16778
|
+
...result
|
|
16779
|
+
};
|
|
16780
|
+
};
|
|
16781
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
16782
|
+
const makeSseFn = (method) => async (options) => {
|
|
16783
|
+
const { opts, url } = await beforeRequest(options);
|
|
16784
|
+
return createSseClient({
|
|
16785
|
+
...opts,
|
|
16786
|
+
body: opts.body,
|
|
16787
|
+
headers: opts.headers,
|
|
16788
|
+
method,
|
|
16789
|
+
onRequest: async (url2, init) => {
|
|
16790
|
+
let request2 = new Request(url2, init);
|
|
16791
|
+
const requestInit = {
|
|
16792
|
+
...init,
|
|
16793
|
+
method: init.method,
|
|
16794
|
+
url: url2
|
|
16795
|
+
};
|
|
16796
|
+
for (const fn of interceptors.request.fns) {
|
|
16797
|
+
if (fn) {
|
|
16798
|
+
await fn(requestInit);
|
|
16799
|
+
request2 = new Request(requestInit.url, requestInit);
|
|
16800
|
+
}
|
|
16801
|
+
}
|
|
16802
|
+
return request2;
|
|
16803
|
+
},
|
|
16804
|
+
url
|
|
16805
|
+
});
|
|
16806
|
+
};
|
|
16807
|
+
return {
|
|
16808
|
+
buildUrl,
|
|
16809
|
+
connect: makeMethodFn("CONNECT"),
|
|
16810
|
+
delete: makeMethodFn("DELETE"),
|
|
16811
|
+
get: makeMethodFn("GET"),
|
|
16812
|
+
getConfig,
|
|
16813
|
+
head: makeMethodFn("HEAD"),
|
|
16814
|
+
interceptors,
|
|
16815
|
+
options: makeMethodFn("OPTIONS"),
|
|
16816
|
+
patch: makeMethodFn("PATCH"),
|
|
16817
|
+
post: makeMethodFn("POST"),
|
|
16818
|
+
put: makeMethodFn("PUT"),
|
|
16819
|
+
request,
|
|
16820
|
+
setConfig,
|
|
16821
|
+
sse: {
|
|
16822
|
+
connect: makeSseFn("CONNECT"),
|
|
16823
|
+
delete: makeSseFn("DELETE"),
|
|
16824
|
+
get: makeSseFn("GET"),
|
|
16825
|
+
head: makeSseFn("HEAD"),
|
|
16826
|
+
options: makeSseFn("OPTIONS"),
|
|
16827
|
+
patch: makeSseFn("PATCH"),
|
|
16828
|
+
post: makeSseFn("POST"),
|
|
16829
|
+
put: makeSseFn("PUT"),
|
|
16830
|
+
trace: makeSseFn("TRACE")
|
|
16831
|
+
},
|
|
16832
|
+
trace: makeMethodFn("TRACE")
|
|
16833
|
+
};
|
|
16834
|
+
};
|
|
16835
|
+
|
|
16836
|
+
// src/client/client.gen.ts
|
|
16837
|
+
var client = createClient(createClientConfig(createConfig()));
|
|
16838
|
+
|
|
16839
|
+
// src/client/sdk.gen.ts
|
|
16840
|
+
var getApiV1Config = (options) => {
|
|
16841
|
+
return (options?.client ?? client).get({
|
|
16842
|
+
url: "/api/v1/config",
|
|
16843
|
+
...options
|
|
16844
|
+
});
|
|
16845
|
+
};
|
|
16846
|
+
var getApiV1CreditsBalance = (options) => {
|
|
16847
|
+
return (options?.client ?? client).get({
|
|
16848
|
+
url: "/api/v1/credits/balance",
|
|
16849
|
+
...options
|
|
16850
|
+
});
|
|
16851
|
+
};
|
|
16852
|
+
var getApiV1CreditsPacks = (options) => {
|
|
16853
|
+
return (options?.client ?? client).get({
|
|
16854
|
+
url: "/api/v1/credits/packs",
|
|
16855
|
+
...options
|
|
16856
|
+
});
|
|
16857
|
+
};
|
|
16858
|
+
var postApiV1CreditsPurchase = (options) => {
|
|
16859
|
+
return (options.client ?? client).post({
|
|
16860
|
+
url: "/api/v1/credits/purchase",
|
|
16861
|
+
...options,
|
|
16862
|
+
headers: {
|
|
16863
|
+
"Content-Type": "application/json",
|
|
16864
|
+
...options.headers
|
|
16865
|
+
}
|
|
16866
|
+
});
|
|
16867
|
+
};
|
|
16868
|
+
var getApiV1Models = (options) => {
|
|
16869
|
+
return (options?.client ?? client).get({
|
|
16870
|
+
url: "/api/v1/models",
|
|
16871
|
+
...options
|
|
16872
|
+
});
|
|
16873
|
+
};
|
|
16874
|
+
var postApiV1PhoneCalls = (options) => {
|
|
16875
|
+
return (options.client ?? client).post({
|
|
16876
|
+
url: "/api/v1/phone-calls",
|
|
16877
|
+
...options,
|
|
16878
|
+
headers: {
|
|
16879
|
+
"Content-Type": "application/json",
|
|
16880
|
+
...options.headers
|
|
16881
|
+
}
|
|
16882
|
+
});
|
|
16883
|
+
};
|
|
16884
|
+
var getApiV1PhoneCallsByCallId = (options) => {
|
|
16885
|
+
return (options.client ?? client).get({
|
|
16886
|
+
url: "/api/v1/phone-calls/{call_id}",
|
|
16887
|
+
...options
|
|
16888
|
+
});
|
|
16889
|
+
};
|
|
16890
|
+
var postApiV1SubscriptionsCancel = (options) => {
|
|
16891
|
+
return (options?.client ?? client).post({
|
|
16892
|
+
url: "/api/v1/subscriptions/cancel",
|
|
16893
|
+
...options,
|
|
16894
|
+
headers: {
|
|
16895
|
+
"Content-Type": "application/json",
|
|
16896
|
+
...options?.headers
|
|
16897
|
+
}
|
|
16898
|
+
});
|
|
16899
|
+
};
|
|
16900
|
+
var postApiV1SubscriptionsCreateCheckoutSession = (options) => {
|
|
16901
|
+
return (options.client ?? client).post({
|
|
16902
|
+
url: "/api/v1/subscriptions/create-checkout-session",
|
|
16903
|
+
...options,
|
|
16904
|
+
headers: {
|
|
16905
|
+
"Content-Type": "application/json",
|
|
16906
|
+
...options.headers
|
|
16907
|
+
}
|
|
16908
|
+
});
|
|
16909
|
+
};
|
|
16910
|
+
var postApiV1SubscriptionsCustomerPortal = (options) => {
|
|
16911
|
+
return (options.client ?? client).post({
|
|
16912
|
+
url: "/api/v1/subscriptions/customer-portal",
|
|
16913
|
+
...options,
|
|
16914
|
+
headers: {
|
|
16915
|
+
"Content-Type": "application/json",
|
|
16916
|
+
...options.headers
|
|
16917
|
+
}
|
|
16918
|
+
});
|
|
16919
|
+
};
|
|
16920
|
+
var postApiV1SubscriptionsRenew = (options) => {
|
|
16921
|
+
return (options?.client ?? client).post({
|
|
16922
|
+
url: "/api/v1/subscriptions/renew",
|
|
16923
|
+
...options
|
|
16924
|
+
});
|
|
16925
|
+
};
|
|
16926
|
+
var getApiV1SubscriptionsStatus = (options) => {
|
|
16927
|
+
return (options?.client ?? client).get({
|
|
16928
|
+
url: "/api/v1/subscriptions/status",
|
|
16929
|
+
...options
|
|
16930
|
+
});
|
|
16931
|
+
};
|
|
16932
|
+
var getApiV1WalletsBinding = (options) => {
|
|
16933
|
+
return (options?.client ?? client).get({
|
|
16934
|
+
url: "/api/v1/wallets/binding",
|
|
16935
|
+
...options
|
|
16936
|
+
});
|
|
16937
|
+
};
|
|
16938
|
+
var postApiV1WalletsBinding = (options) => {
|
|
16939
|
+
return (options.client ?? client).post({
|
|
16940
|
+
url: "/api/v1/wallets/binding",
|
|
16941
|
+
...options,
|
|
16942
|
+
headers: {
|
|
16943
|
+
"Content-Type": "application/json",
|
|
16944
|
+
...options.headers
|
|
16945
|
+
}
|
|
16946
|
+
});
|
|
16947
|
+
};
|
|
16948
|
+
var postApiV1WalletsBindingNonce = (options) => {
|
|
16949
|
+
return (options?.client ?? client).post({
|
|
16950
|
+
url: "/api/v1/wallets/binding/nonce",
|
|
16951
|
+
...options
|
|
16952
|
+
});
|
|
16953
|
+
};
|
|
16954
|
+
var deleteApiV1WalletsBindingByAddress = (options) => {
|
|
16955
|
+
return (options.client ?? client).delete({
|
|
16956
|
+
url: "/api/v1/wallets/binding/{address}",
|
|
16957
|
+
...options
|
|
16958
|
+
});
|
|
16959
|
+
};
|
|
16960
|
+
var postAuthOauthByProviderExchange = (options) => {
|
|
16961
|
+
return (options.client ?? client).post({
|
|
16962
|
+
url: "/auth/oauth/{provider}/exchange",
|
|
16963
|
+
...options,
|
|
16964
|
+
headers: {
|
|
16965
|
+
"Content-Type": "application/json",
|
|
16966
|
+
...options.headers
|
|
16967
|
+
}
|
|
16968
|
+
});
|
|
16969
|
+
};
|
|
16970
|
+
var postAuthOauthByProviderRefresh = (options) => {
|
|
16971
|
+
return (options.client ?? client).post({
|
|
16972
|
+
url: "/auth/oauth/{provider}/refresh",
|
|
16973
|
+
...options,
|
|
16974
|
+
headers: {
|
|
16975
|
+
"Content-Type": "application/json",
|
|
16976
|
+
...options.headers
|
|
16977
|
+
}
|
|
16978
|
+
});
|
|
16979
|
+
};
|
|
16980
|
+
var postAuthOauthByProviderRevoke = (options) => {
|
|
16981
|
+
return (options.client ?? client).post({
|
|
16982
|
+
url: "/auth/oauth/{provider}/revoke",
|
|
16983
|
+
...options,
|
|
16984
|
+
headers: {
|
|
16985
|
+
"Content-Type": "application/json",
|
|
16986
|
+
...options.headers
|
|
16987
|
+
}
|
|
16988
|
+
});
|
|
16989
|
+
};
|
|
16990
|
+
|
|
16991
|
+
// src/react/useCredits.ts
|
|
15983
16992
|
function useCredits(options = {}) {
|
|
15984
16993
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
15985
16994
|
const [balance, setBalance] = useState11(null);
|
|
@@ -18590,7 +19599,7 @@ async function uploadFileToICloud(filename, content) {
|
|
|
18590
19599
|
const database = container.privateCloudDatabase;
|
|
18591
19600
|
const recordName = `backup_${filename.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
18592
19601
|
const arrayBuffer = await content.arrayBuffer();
|
|
18593
|
-
const base64Data =
|
|
19602
|
+
const base64Data = uint8ArrayToBase64(new Uint8Array(arrayBuffer));
|
|
18594
19603
|
const record = {
|
|
18595
19604
|
recordType: RECORD_TYPE,
|
|
18596
19605
|
recordName,
|
|
@@ -18652,11 +19661,7 @@ async function downloadICloudFile(recordName) {
|
|
|
18652
19661
|
throw new Error("No data in record");
|
|
18653
19662
|
}
|
|
18654
19663
|
if (typeof dataField === "string") {
|
|
18655
|
-
const
|
|
18656
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
18657
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
18658
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
18659
|
-
}
|
|
19664
|
+
const bytes = base64ToUint8Array(dataField);
|
|
18660
19665
|
return new Blob([bytes], { type: "application/json" });
|
|
18661
19666
|
}
|
|
18662
19667
|
if (typeof dataField === "object" && "downloadURL" in dataField) {
|
|
@@ -22831,6 +23836,7 @@ export {
|
|
|
22831
23836
|
getConversationsByProjectLazyOp,
|
|
22832
23837
|
getConversationsByProjectOp,
|
|
22833
23838
|
getConversationsLazyOp,
|
|
23839
|
+
getConversationsPageOp,
|
|
22834
23840
|
getDocumentsOp,
|
|
22835
23841
|
getDriveAccessToken,
|
|
22836
23842
|
getEncryptionKey,
|