@anuma/sdk 3.0.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-IY7NNIYM.mjs → chunk-22CSPJLL.mjs} +16 -850
- package/dist/expo/index.cjs +1663 -1071
- package/dist/expo/index.d.mts +179 -10
- package/dist/expo/index.d.ts +179 -10
- package/dist/expo/index.mjs +1556 -68
- package/dist/expo/{recall-DJ5LD5WJ.mjs → recall-LICO3TJ7.mjs} +1 -1
- package/dist/index.cjs +415 -394
- package/dist/index.mjs +412 -391
- package/dist/react/{chunk-OSDVRDLI.mjs → chunk-FD5MB73N.mjs} +8 -987
- package/dist/react/index.cjs +1687 -1712
- package/dist/react/index.d.mts +103 -12
- package/dist/react/index.d.ts +103 -12
- package/dist/react/index.mjs +1209 -219
- package/dist/react/{recall-3BDCIEQF.mjs → recall-FPACUZGD.mjs} +1 -1
- package/dist/server/{chunk-QQOIC37O.mjs → chunk-RKUNGNBF.mjs} +7 -817
- package/dist/server/index.cjs +223 -941
- package/dist/server/index.d.mts +95 -12
- package/dist/server/index.d.ts +95 -12
- package/dist/server/index.mjs +182 -23
- package/dist/server/{recall-6QLUEYB7.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,13 +59,6 @@ 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,
|
|
@@ -95,17 +86,6 @@ import {
|
|
|
95
86
|
makeSyntheticStoredMessage,
|
|
96
87
|
onClearAllEncryptionState,
|
|
97
88
|
onKeyAvailable,
|
|
98
|
-
postApiV1CreditsPurchase,
|
|
99
|
-
postApiV1PhoneCalls,
|
|
100
|
-
postApiV1SubscriptionsCancel,
|
|
101
|
-
postApiV1SubscriptionsCreateCheckoutSession,
|
|
102
|
-
postApiV1SubscriptionsCustomerPortal,
|
|
103
|
-
postApiV1SubscriptionsRenew,
|
|
104
|
-
postApiV1WalletsBinding,
|
|
105
|
-
postApiV1WalletsBindingNonce,
|
|
106
|
-
postAuthOauthByProviderExchange,
|
|
107
|
-
postAuthOauthByProviderRefresh,
|
|
108
|
-
postAuthOauthByProviderRevoke,
|
|
109
89
|
preEmbedVaultMemories,
|
|
110
90
|
recall,
|
|
111
91
|
replaceMemoryEntitiesGuardedOp,
|
|
@@ -132,7 +112,7 @@ import {
|
|
|
132
112
|
updateVaultMemoryOp,
|
|
133
113
|
useEncryption,
|
|
134
114
|
vaultMemoryToStored
|
|
135
|
-
} from "./chunk-
|
|
115
|
+
} from "./chunk-FD5MB73N.mjs";
|
|
136
116
|
import {
|
|
137
117
|
PiiRedactor,
|
|
138
118
|
createStreamingDeAnonymizer,
|
|
@@ -152,9 +132,145 @@ import {
|
|
|
152
132
|
import {
|
|
153
133
|
BASE_URL,
|
|
154
134
|
MCP_R2_DOMAIN,
|
|
155
|
-
__decorateClass
|
|
135
|
+
__decorateClass,
|
|
136
|
+
createClientConfig
|
|
156
137
|
} from "./chunk-GYKJOWEO.mjs";
|
|
157
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
|
+
|
|
158
274
|
// src/lib/chat/runHooks.ts
|
|
159
275
|
function composeHooks(hooks) {
|
|
160
276
|
const handlers = hooks.filter((h) => h !== void 0 && h !== null);
|
|
@@ -7510,9 +7626,11 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
|
|
|
7510
7626
|
return new LRUCache(maxSize);
|
|
7511
7627
|
}
|
|
7512
7628
|
|
|
7513
|
-
// src/lib/memory/
|
|
7629
|
+
// src/lib/memory/recallConstants.ts
|
|
7514
7630
|
var RECALL_TOOL_NAME = "recall_memory";
|
|
7515
7631
|
var RECALL_MAX_LIMIT = 50;
|
|
7632
|
+
|
|
7633
|
+
// src/lib/memory/recallTool.ts
|
|
7516
7634
|
var DEFAULT_LIMIT = 8;
|
|
7517
7635
|
var DEFAULT_BUDGET = "low";
|
|
7518
7636
|
function formatEventTime(start, end, kind) {
|
|
@@ -9210,7 +9328,7 @@ function getCachedServerTools() {
|
|
|
9210
9328
|
if (!cached) return null;
|
|
9211
9329
|
const parsed = JSON.parse(cached);
|
|
9212
9330
|
if (parsed.version !== CACHE_VERSION) {
|
|
9213
|
-
|
|
9331
|
+
removeLocalStorageCache();
|
|
9214
9332
|
return null;
|
|
9215
9333
|
}
|
|
9216
9334
|
return parsed;
|
|
@@ -9222,37 +9340,45 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
|
|
|
9222
9340
|
if (!cache) return true;
|
|
9223
9341
|
return Date.now() - cache.timestamp > expirationMs;
|
|
9224
9342
|
}
|
|
9225
|
-
function
|
|
9226
|
-
|
|
9227
|
-
const cacheData = {
|
|
9343
|
+
function buildCacheEntry(tools, checksum) {
|
|
9344
|
+
return {
|
|
9228
9345
|
tools,
|
|
9229
9346
|
timestamp: Date.now(),
|
|
9230
9347
|
version: CACHE_VERSION,
|
|
9231
9348
|
...checksum && { checksum }
|
|
9232
9349
|
};
|
|
9350
|
+
}
|
|
9351
|
+
function writeLocalStorageCache(entry) {
|
|
9352
|
+
if (typeof localStorage === "undefined") return;
|
|
9233
9353
|
try {
|
|
9234
|
-
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(
|
|
9354
|
+
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(entry));
|
|
9235
9355
|
} catch (error) {
|
|
9236
9356
|
getLogger().warn("[serverTools] Failed to cache tools:", error);
|
|
9237
9357
|
}
|
|
9238
9358
|
}
|
|
9239
|
-
function
|
|
9359
|
+
function removeLocalStorageCache() {
|
|
9240
9360
|
if (typeof localStorage === "undefined") return;
|
|
9241
9361
|
localStorage.removeItem(SERVER_TOOLS_CACHE_KEY);
|
|
9242
9362
|
}
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
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;
|
|
9246
9374
|
}
|
|
9247
|
-
function shouldRefreshTools(responseChecksum) {
|
|
9375
|
+
function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
|
|
9248
9376
|
if (!responseChecksum) {
|
|
9249
9377
|
return false;
|
|
9250
9378
|
}
|
|
9251
|
-
const
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
}
|
|
9255
|
-
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);
|
|
9256
9382
|
}
|
|
9257
9383
|
async function fetchServerToolsFromApi(baseUrl, token) {
|
|
9258
9384
|
const response = await fetch(`${baseUrl}/api/v1/tools`, {
|
|
@@ -9274,9 +9400,23 @@ async function getServerTools(options) {
|
|
|
9274
9400
|
cacheExpirationMs = DEFAULT_CACHE_EXPIRATION_MS,
|
|
9275
9401
|
forceRefresh = false,
|
|
9276
9402
|
getToken,
|
|
9277
|
-
apiKey
|
|
9403
|
+
apiKey,
|
|
9404
|
+
cache = localStorageToolsCache
|
|
9278
9405
|
} = options;
|
|
9279
|
-
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;
|
|
9280
9420
|
const cacheValid = !isCacheExpired(cached, cacheExpirationMs);
|
|
9281
9421
|
if (cached && cacheValid && !forceRefresh) {
|
|
9282
9422
|
return cached.tools;
|
|
@@ -9297,7 +9437,7 @@ async function getServerTools(options) {
|
|
|
9297
9437
|
}
|
|
9298
9438
|
const data = await response.json();
|
|
9299
9439
|
const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
|
|
9300
|
-
|
|
9440
|
+
await persistCache(buildCacheEntry(tools2, checksum2));
|
|
9301
9441
|
return tools2;
|
|
9302
9442
|
}
|
|
9303
9443
|
if (!getToken) {
|
|
@@ -9310,7 +9450,7 @@ async function getServerTools(options) {
|
|
|
9310
9450
|
return cached?.tools ?? [];
|
|
9311
9451
|
}
|
|
9312
9452
|
const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
|
|
9313
|
-
|
|
9453
|
+
await persistCache(buildCacheEntry(tools, checksum));
|
|
9314
9454
|
return tools;
|
|
9315
9455
|
} catch (error) {
|
|
9316
9456
|
getLogger().error("[serverTools] Failed to fetch server tools:", error);
|
|
@@ -9815,13 +9955,14 @@ async function selectServerToolsForPrompt(options) {
|
|
|
9815
9955
|
baseUrl,
|
|
9816
9956
|
embeddingModel,
|
|
9817
9957
|
cacheExpirationMs,
|
|
9958
|
+
cache,
|
|
9818
9959
|
deferLoading
|
|
9819
9960
|
} = options;
|
|
9820
9961
|
if (serverToolsFilter === void 0) return [];
|
|
9821
9962
|
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
|
|
9822
9963
|
let allServerTools;
|
|
9823
9964
|
try {
|
|
9824
|
-
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken });
|
|
9965
|
+
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken, cache });
|
|
9825
9966
|
} catch {
|
|
9826
9967
|
return [];
|
|
9827
9968
|
}
|
|
@@ -9845,6 +9986,123 @@ async function selectServerToolsForPrompt(options) {
|
|
|
9845
9986
|
return filterServerTools(allServerTools, serverToolsFilter);
|
|
9846
9987
|
}
|
|
9847
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
|
+
|
|
9848
10106
|
// src/react/useChatMedia.ts
|
|
9849
10107
|
import { useCallback as useCallback3 } from "react";
|
|
9850
10108
|
function resolveMediaMeta(extractedKind, urlPath, reportedType) {
|
|
@@ -10094,165 +10352,51 @@ function useChatMedia(options) {
|
|
|
10094
10352
|
}
|
|
10095
10353
|
|
|
10096
10354
|
// src/react/useChatStorage.ts
|
|
10097
|
-
function
|
|
10098
|
-
const
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
const isMemoryTool = (t) => {
|
|
10116
|
-
const name = getToolName2(t);
|
|
10117
|
-
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME;
|
|
10118
|
-
};
|
|
10119
|
-
const alwaysInclude = clientTools.filter(isMemoryTool);
|
|
10120
|
-
const filterCandidates = clientTools.filter((t) => !isMemoryTool(t));
|
|
10121
|
-
if (filterCandidates.length === 0) {
|
|
10122
|
-
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
|
+
);
|
|
10123
10373
|
}
|
|
10124
|
-
if (!
|
|
10125
|
-
return {
|
|
10374
|
+
if (!prompt.trim()) {
|
|
10375
|
+
return { clientToolNames: [], serverToolNames: [] };
|
|
10126
10376
|
}
|
|
10127
|
-
if (
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
try {
|
|
10151
|
-
const descriptions = toolsNeedingEmbeddings.map((t) => t.description);
|
|
10152
|
-
const embeddings = await generateEmbeddings(descriptions, embeddingOptions);
|
|
10153
|
-
for (let i = 0; i < toolsNeedingEmbeddings.length; i++) {
|
|
10154
|
-
cache.set(toolsNeedingEmbeddings[i].name, embeddings[i]);
|
|
10155
|
-
}
|
|
10156
|
-
} catch {
|
|
10157
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
10158
|
-
}
|
|
10159
|
-
}
|
|
10160
|
-
const pseudoServerTools = [];
|
|
10161
|
-
for (const t of filterCandidates) {
|
|
10162
|
-
const name = getToolName2(t);
|
|
10163
|
-
const embedding = cache.get(name);
|
|
10164
|
-
if (!embedding) continue;
|
|
10165
|
-
const fn = t.function;
|
|
10166
|
-
const params = fn?.parameters || fn?.arguments || {
|
|
10167
|
-
type: "object",
|
|
10168
|
-
properties: {},
|
|
10169
|
-
required: []
|
|
10170
|
-
};
|
|
10171
|
-
pseudoServerTools.push({
|
|
10172
|
-
type: "function",
|
|
10173
|
-
name,
|
|
10174
|
-
description: getToolDescription(t),
|
|
10175
|
-
parameters: params,
|
|
10176
|
-
embedding
|
|
10177
|
-
});
|
|
10178
|
-
}
|
|
10179
|
-
const matches = findMatchingTools(promptEmbeddings, pseudoServerTools, {
|
|
10180
|
-
limit: MAX_CLIENT_TOOLS_AFTER_FILTER,
|
|
10181
|
-
minSimilarity: CLIENT_TOOLS_MIN_SIMILARITY,
|
|
10182
|
-
filterAmbiguous: true,
|
|
10183
|
-
// See CLIENT_TOOLS_RELEVANCE_RATIO: 0.75 admits the second intent of a
|
|
10184
|
-
// multi-intent prompt (which lands ~75-80% of the dominant match), while
|
|
10185
|
-
// still trimming the loose tail. The earlier 0.9 made a second intent
|
|
10186
|
-
// structurally unselectable; the anchorMinSimilarity gates (0.53-0.55)
|
|
10187
|
-
// remain the guard against borderline anchors activating a whole set.
|
|
10188
|
-
relevanceRatio: CLIENT_TOOLS_RELEVANCE_RATIO
|
|
10189
|
-
});
|
|
10190
|
-
const matchedNames = new Set(matches.map((m) => m.tool.name));
|
|
10191
|
-
const scores = scoreTools(promptEmbeddings, pseudoServerTools);
|
|
10192
|
-
const availableNames = new Set(filterCandidates.map(getToolName2));
|
|
10193
|
-
const toolSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
10194
|
-
const activeSetNames = activeToolSets.length > 0 ? new Set(activeToolSets) : void 0;
|
|
10195
|
-
const finalNames = expandToolSetsAdditive(
|
|
10196
|
-
matchedNames,
|
|
10197
|
-
availableNames,
|
|
10198
|
-
scores,
|
|
10199
|
-
toolSets,
|
|
10200
|
-
activeSetNames
|
|
10201
|
-
);
|
|
10202
|
-
const activatedSetNames = activatedToolSetNames(scores, toolSets, activeSetNames);
|
|
10203
|
-
if (finalNames.size === 0) {
|
|
10204
|
-
return { tools: alwaysInclude, activatedSetNames };
|
|
10205
|
-
}
|
|
10206
|
-
const filtered = filterCandidates.filter((t) => {
|
|
10207
|
-
const name = getToolName2(t);
|
|
10208
|
-
return name && finalNames.has(name);
|
|
10209
|
-
});
|
|
10210
|
-
return { tools: [...alwaysInclude, ...filtered], activatedSetNames };
|
|
10211
|
-
}
|
|
10212
|
-
async function previewToolSelection(options) {
|
|
10213
|
-
const {
|
|
10214
|
-
prompt,
|
|
10215
|
-
clientTools = [],
|
|
10216
|
-
serverToolsFilter,
|
|
10217
|
-
serverToolsConfig,
|
|
10218
|
-
getToken,
|
|
10219
|
-
apiKey,
|
|
10220
|
-
baseUrl,
|
|
10221
|
-
embeddingModel = DEFAULT_API_EMBEDDING_MODEL,
|
|
10222
|
-
extraToolSets,
|
|
10223
|
-
activeToolSets,
|
|
10224
|
-
clientToolEmbeddingsCache
|
|
10225
|
-
} = options;
|
|
10226
|
-
if (!getToken && !apiKey) {
|
|
10227
|
-
throw new Error(
|
|
10228
|
-
"previewToolSelection requires either `getToken` (Bearer auth) or `apiKey` (X-API-Key auth) \u2014 without one, embeddings and the server tool catalog cannot be fetched."
|
|
10229
|
-
);
|
|
10230
|
-
}
|
|
10231
|
-
if (!prompt.trim()) {
|
|
10232
|
-
return { clientToolNames: [], serverToolNames: [] };
|
|
10233
|
-
}
|
|
10234
|
-
if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
10235
|
-
const { tools: gatedTools } = await autoFilterClientTools(
|
|
10236
|
-
clientTools,
|
|
10237
|
-
null,
|
|
10238
|
-
clientToolEmbeddingsCache ?? /* @__PURE__ */ new Map(),
|
|
10239
|
-
{ getToken, apiKey, baseUrl, model: embeddingModel },
|
|
10240
|
-
extraToolSets ?? [],
|
|
10241
|
-
activeToolSets ?? []
|
|
10242
|
-
);
|
|
10243
|
-
let gatedServerNames = [];
|
|
10244
|
-
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length > 0) {
|
|
10245
|
-
try {
|
|
10246
|
-
const allServerTools = await getServerTools({
|
|
10247
|
-
baseUrl,
|
|
10248
|
-
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
10249
|
-
getToken,
|
|
10250
|
-
apiKey
|
|
10251
|
-
});
|
|
10252
|
-
const allow = new Set(serverToolsFilter);
|
|
10253
|
-
gatedServerNames = allServerTools.filter((t) => allow.has(t.name)).map((t) => t.name);
|
|
10254
|
-
} catch {
|
|
10255
|
-
}
|
|
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
|
+
}
|
|
10256
10400
|
}
|
|
10257
10401
|
return {
|
|
10258
10402
|
clientToolNames: gatedTools.map(getToolName2).filter(Boolean),
|
|
@@ -10295,7 +10439,8 @@ async function previewToolSelection(options) {
|
|
|
10295
10439
|
baseUrl,
|
|
10296
10440
|
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
10297
10441
|
getToken,
|
|
10298
|
-
apiKey
|
|
10442
|
+
apiKey,
|
|
10443
|
+
cache: serverToolsConfig?.cache
|
|
10299
10444
|
});
|
|
10300
10445
|
if (serverToolsConfig?.deferLoading?.enabled) {
|
|
10301
10446
|
serverToolNames = allServerTools.map((t) => t.name);
|
|
@@ -11288,7 +11433,8 @@ function useChatStorage(options) {
|
|
|
11288
11433
|
const allServerTools = await getServerTools({
|
|
11289
11434
|
baseUrl,
|
|
11290
11435
|
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
11291
|
-
getToken
|
|
11436
|
+
getToken,
|
|
11437
|
+
cache: serverToolsConfig?.cache
|
|
11292
11438
|
});
|
|
11293
11439
|
if (serverToolsConfig?.deferLoading?.enabled) {
|
|
11294
11440
|
filteredServerTools2 = allServerTools;
|
|
@@ -11306,12 +11452,14 @@ function useChatStorage(options) {
|
|
|
11306
11452
|
let filteredClientTools2 = clientTools;
|
|
11307
11453
|
let clientActivatedSetNames2;
|
|
11308
11454
|
if (clientToolsFilter && clientTools?.length) {
|
|
11309
|
-
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
|
|
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
|
+
}
|
|
11315
11463
|
} else if (clientTools?.length && getToken) {
|
|
11316
11464
|
const clientFilterResult = await autoFilterClientTools(
|
|
11317
11465
|
clientTools,
|
|
@@ -11378,8 +11526,20 @@ function useChatStorage(options) {
|
|
|
11378
11526
|
error: result2.error || "Unknown error"
|
|
11379
11527
|
};
|
|
11380
11528
|
}
|
|
11381
|
-
|
|
11382
|
-
|
|
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) => {
|
|
11383
11543
|
getLogger().warn("[useChatStorage] Failed to refresh server tools cache:", err);
|
|
11384
11544
|
});
|
|
11385
11545
|
}
|
|
@@ -11646,7 +11806,8 @@ function useChatStorage(options) {
|
|
|
11646
11806
|
const allServerTools = await getServerTools({
|
|
11647
11807
|
baseUrl,
|
|
11648
11808
|
cacheExpirationMs: serverToolsConfig?.cacheExpirationMs,
|
|
11649
|
-
getToken
|
|
11809
|
+
getToken,
|
|
11810
|
+
cache: serverToolsConfig?.cache
|
|
11650
11811
|
});
|
|
11651
11812
|
if (serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") {
|
|
11652
11813
|
filteredServerTools = allServerTools;
|
|
@@ -11664,12 +11825,14 @@ function useChatStorage(options) {
|
|
|
11664
11825
|
let filteredClientTools = clientTools;
|
|
11665
11826
|
let clientActivatedSetNames;
|
|
11666
11827
|
if (clientToolsFilter && clientTools?.length) {
|
|
11667
|
-
|
|
11668
|
-
|
|
11669
|
-
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
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
|
+
}
|
|
11673
11836
|
} else if (clientTools?.length && getToken) {
|
|
11674
11837
|
const clientFilterResult = await autoFilterClientTools(
|
|
11675
11838
|
clientTools,
|
|
@@ -11989,8 +12152,17 @@ Based on these results, continue with the task.`;
|
|
|
11989
12152
|
} catch {
|
|
11990
12153
|
}
|
|
11991
12154
|
}
|
|
11992
|
-
if (getToken
|
|
11993
|
-
|
|
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) => {
|
|
11994
12166
|
getLogger().warn("[useChatStorage] Failed to refresh server tools cache:", err);
|
|
11995
12167
|
});
|
|
11996
12168
|
}
|
|
@@ -15999,6 +16171,824 @@ function useVoice(options) {
|
|
|
15999
16171
|
|
|
16000
16172
|
// src/react/useCredits.ts
|
|
16001
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
|
|
16002
16992
|
function useCredits(options = {}) {
|
|
16003
16993
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
16004
16994
|
const [balance, setBalance] = useState11(null);
|