@anuma/sdk 3.6.2 → 3.7.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.
Files changed (27) hide show
  1. package/dist/expo/{chunk-7TATXBC5.mjs → chunk-AAB7OG7Q.mjs} +810 -4
  2. package/dist/{react/chunk-DFVCS3QQ.mjs → expo/chunk-BOY27A2C.mjs} +30 -3
  3. package/dist/expo/{consolidate-3QQPUWD6.mjs → consolidate-J5PHQKKY.mjs} +1 -1
  4. package/dist/expo/index.cjs +931 -825
  5. package/dist/expo/index.d.mts +9 -0
  6. package/dist/expo/index.d.ts +9 -0
  7. package/dist/expo/index.mjs +14 -817
  8. package/dist/{react/recall-OPKHWKZX.mjs → expo/recall-YVU7OSSJ.mjs} +2 -2
  9. package/dist/react/{chunk-DDHTJGZN.mjs → chunk-3VPEZDYL.mjs} +896 -4
  10. package/dist/{expo/chunk-DFVCS3QQ.mjs → react/chunk-BOY27A2C.mjs} +30 -3
  11. package/dist/react/{consolidate-3MXZV3G7.mjs → consolidate-PWJCAPZA.mjs} +1 -1
  12. package/dist/react/index.cjs +2021 -1907
  13. package/dist/react/index.d.mts +9 -0
  14. package/dist/react/index.d.ts +9 -0
  15. package/dist/react/index.mjs +29 -888
  16. package/dist/{expo/recall-IO4KJ5W7.mjs → react/recall-Z7BWJ67X.mjs} +2 -2
  17. package/dist/server/{chunk-V7SVKIXQ.mjs → chunk-LSKFJNLF.mjs} +795 -4
  18. package/dist/server/{chunk-AHJT66EO.mjs → chunk-MIXEASUP.mjs} +30 -3
  19. package/dist/server/{consolidate-CN2GQV4D.mjs → consolidate-PCHO3D3G.mjs} +1 -1
  20. package/dist/server/index.cjs +925 -163
  21. package/dist/server/index.d.mts +36 -0
  22. package/dist/server/index.d.ts +36 -0
  23. package/dist/server/index.mjs +9 -147
  24. package/dist/server/{recall-IWY2MYHR.mjs → recall-XEOLXA6P.mjs} +2 -2
  25. package/dist/tools/selection/index.cjs +793 -3
  26. package/dist/tools/selection/index.mjs +791 -3
  27. package/package.json +2 -2
@@ -2048,6 +2048,838 @@ var init_constants = __esm({
2048
2048
  }
2049
2049
  });
2050
2050
 
2051
+ // src/client/core/bodySerializer.gen.ts
2052
+ var jsonBodySerializer;
2053
+ var init_bodySerializer_gen = __esm({
2054
+ "src/client/core/bodySerializer.gen.ts"() {
2055
+ "use strict";
2056
+ jsonBodySerializer = {
2057
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
2058
+ };
2059
+ }
2060
+ });
2061
+
2062
+ // src/client/core/serverSentEvents.gen.ts
2063
+ function createSseClient({
2064
+ onRequest,
2065
+ onSseError,
2066
+ onSseEvent,
2067
+ responseTransformer,
2068
+ responseValidator,
2069
+ sseDefaultRetryDelay,
2070
+ sseMaxRetryAttempts,
2071
+ sseMaxRetryDelay,
2072
+ sseSleepFn,
2073
+ url,
2074
+ ...options
2075
+ }) {
2076
+ let lastEventId;
2077
+ const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
2078
+ const createStream = async function* () {
2079
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
2080
+ let attempt = 0;
2081
+ const signal = options.signal ?? new AbortController().signal;
2082
+ while (true) {
2083
+ if (signal.aborted) break;
2084
+ attempt++;
2085
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
2086
+ if (lastEventId !== void 0) {
2087
+ headers.set("Last-Event-ID", lastEventId);
2088
+ }
2089
+ try {
2090
+ const requestInit = {
2091
+ redirect: "follow",
2092
+ ...options,
2093
+ body: options.serializedBody,
2094
+ headers,
2095
+ signal
2096
+ };
2097
+ let request = new Request(url, requestInit);
2098
+ if (onRequest) {
2099
+ request = await onRequest(url, requestInit);
2100
+ }
2101
+ const _fetch = options.fetch ?? globalThis.fetch;
2102
+ const response = await _fetch(request);
2103
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
2104
+ if (!response.body) throw new Error("No body in SSE response");
2105
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
2106
+ let buffer = "";
2107
+ const abortHandler = () => {
2108
+ try {
2109
+ reader.cancel();
2110
+ } catch {
2111
+ }
2112
+ };
2113
+ signal.addEventListener("abort", abortHandler);
2114
+ try {
2115
+ while (true) {
2116
+ const { done, value } = await reader.read();
2117
+ if (done) break;
2118
+ buffer += value;
2119
+ buffer = buffer.replace(/\r\n?/g, "\n");
2120
+ const chunks = buffer.split("\n\n");
2121
+ buffer = chunks.pop() ?? "";
2122
+ for (const chunk of chunks) {
2123
+ const lines = chunk.split("\n");
2124
+ const dataLines = [];
2125
+ let eventName;
2126
+ for (const line of lines) {
2127
+ if (line.startsWith("data:")) {
2128
+ dataLines.push(line.replace(/^data:\s*/, ""));
2129
+ } else if (line.startsWith("event:")) {
2130
+ eventName = line.replace(/^event:\s*/, "");
2131
+ } else if (line.startsWith("id:")) {
2132
+ lastEventId = line.replace(/^id:\s*/, "");
2133
+ } else if (line.startsWith("retry:")) {
2134
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
2135
+ if (!Number.isNaN(parsed)) {
2136
+ retryDelay = parsed;
2137
+ }
2138
+ }
2139
+ }
2140
+ let data;
2141
+ let parsedJson = false;
2142
+ if (dataLines.length) {
2143
+ const rawData = dataLines.join("\n");
2144
+ try {
2145
+ data = JSON.parse(rawData);
2146
+ parsedJson = true;
2147
+ } catch {
2148
+ data = rawData;
2149
+ }
2150
+ }
2151
+ if (parsedJson) {
2152
+ if (responseValidator) {
2153
+ await responseValidator(data);
2154
+ }
2155
+ if (responseTransformer) {
2156
+ data = await responseTransformer(data);
2157
+ }
2158
+ }
2159
+ onSseEvent?.({
2160
+ data,
2161
+ event: eventName,
2162
+ id: lastEventId,
2163
+ retry: retryDelay
2164
+ });
2165
+ if (dataLines.length) {
2166
+ yield data;
2167
+ }
2168
+ }
2169
+ }
2170
+ } finally {
2171
+ signal.removeEventListener("abort", abortHandler);
2172
+ reader.releaseLock();
2173
+ }
2174
+ break;
2175
+ } catch (error) {
2176
+ onSseError?.(error);
2177
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
2178
+ break;
2179
+ }
2180
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
2181
+ await sleep4(backoff);
2182
+ }
2183
+ }
2184
+ };
2185
+ const stream = createStream();
2186
+ return { stream };
2187
+ }
2188
+ var init_serverSentEvents_gen = __esm({
2189
+ "src/client/core/serverSentEvents.gen.ts"() {
2190
+ "use strict";
2191
+ }
2192
+ });
2193
+
2194
+ // src/client/core/pathSerializer.gen.ts
2195
+ var separatorArrayExplode, separatorArrayNoExplode, separatorObjectExplode, serializeArrayParam, serializePrimitiveParam, serializeObjectParam;
2196
+ var init_pathSerializer_gen = __esm({
2197
+ "src/client/core/pathSerializer.gen.ts"() {
2198
+ "use strict";
2199
+ separatorArrayExplode = (style) => {
2200
+ switch (style) {
2201
+ case "label":
2202
+ return ".";
2203
+ case "matrix":
2204
+ return ";";
2205
+ case "simple":
2206
+ return ",";
2207
+ default:
2208
+ return "&";
2209
+ }
2210
+ };
2211
+ separatorArrayNoExplode = (style) => {
2212
+ switch (style) {
2213
+ case "form":
2214
+ return ",";
2215
+ case "pipeDelimited":
2216
+ return "|";
2217
+ case "spaceDelimited":
2218
+ return "%20";
2219
+ default:
2220
+ return ",";
2221
+ }
2222
+ };
2223
+ separatorObjectExplode = (style) => {
2224
+ switch (style) {
2225
+ case "label":
2226
+ return ".";
2227
+ case "matrix":
2228
+ return ";";
2229
+ case "simple":
2230
+ return ",";
2231
+ default:
2232
+ return "&";
2233
+ }
2234
+ };
2235
+ serializeArrayParam = ({
2236
+ allowReserved,
2237
+ explode,
2238
+ name,
2239
+ style,
2240
+ value
2241
+ }) => {
2242
+ if (!explode) {
2243
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
2244
+ switch (style) {
2245
+ case "label":
2246
+ return `.${joinedValues2}`;
2247
+ case "matrix":
2248
+ return `;${name}=${joinedValues2}`;
2249
+ case "simple":
2250
+ return joinedValues2;
2251
+ default:
2252
+ return `${name}=${joinedValues2}`;
2253
+ }
2254
+ }
2255
+ const separator = separatorArrayExplode(style);
2256
+ const joinedValues = value.map((v) => {
2257
+ if (style === "label" || style === "simple") {
2258
+ return allowReserved ? v : encodeURIComponent(v);
2259
+ }
2260
+ return serializePrimitiveParam({
2261
+ allowReserved,
2262
+ name,
2263
+ value: v
2264
+ });
2265
+ }).join(separator);
2266
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
2267
+ };
2268
+ serializePrimitiveParam = ({
2269
+ allowReserved,
2270
+ name,
2271
+ value
2272
+ }) => {
2273
+ if (value === void 0 || value === null) {
2274
+ return "";
2275
+ }
2276
+ if (typeof value === "object") {
2277
+ throw new Error(
2278
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
2279
+ );
2280
+ }
2281
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
2282
+ };
2283
+ serializeObjectParam = ({
2284
+ allowReserved,
2285
+ explode,
2286
+ name,
2287
+ style,
2288
+ value,
2289
+ valueOnly
2290
+ }) => {
2291
+ if (value instanceof Date) {
2292
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
2293
+ }
2294
+ if (style !== "deepObject" && !explode) {
2295
+ let values = [];
2296
+ Object.entries(value).forEach(([key, v]) => {
2297
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
2298
+ });
2299
+ const joinedValues2 = values.join(",");
2300
+ switch (style) {
2301
+ case "form":
2302
+ return `${name}=${joinedValues2}`;
2303
+ case "label":
2304
+ return `.${joinedValues2}`;
2305
+ case "matrix":
2306
+ return `;${name}=${joinedValues2}`;
2307
+ default:
2308
+ return joinedValues2;
2309
+ }
2310
+ }
2311
+ const separator = separatorObjectExplode(style);
2312
+ const joinedValues = Object.entries(value).map(
2313
+ ([key, v]) => serializePrimitiveParam({
2314
+ allowReserved,
2315
+ name: style === "deepObject" ? `${name}[${key}]` : key,
2316
+ value: v
2317
+ })
2318
+ ).join(separator);
2319
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
2320
+ };
2321
+ }
2322
+ });
2323
+
2324
+ // src/client/core/utils.gen.ts
2325
+ function getValidRequestBody(options) {
2326
+ const hasBody = options.body !== void 0;
2327
+ const isSerializedBody = hasBody && options.bodySerializer;
2328
+ if (isSerializedBody) {
2329
+ if ("serializedBody" in options) {
2330
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
2331
+ return hasSerializedBody ? options.serializedBody : null;
2332
+ }
2333
+ return options.body !== "" ? options.body : null;
2334
+ }
2335
+ if (hasBody) {
2336
+ return options.body;
2337
+ }
2338
+ return void 0;
2339
+ }
2340
+ var init_utils_gen = __esm({
2341
+ "src/client/core/utils.gen.ts"() {
2342
+ "use strict";
2343
+ }
2344
+ });
2345
+
2346
+ // src/client/core/auth.gen.ts
2347
+ var getAuthToken;
2348
+ var init_auth_gen = __esm({
2349
+ "src/client/core/auth.gen.ts"() {
2350
+ "use strict";
2351
+ getAuthToken = async (auth, callback) => {
2352
+ const token = typeof callback === "function" ? await callback(auth) : callback;
2353
+ if (!token) {
2354
+ return;
2355
+ }
2356
+ if (auth.scheme === "bearer") {
2357
+ return `Bearer ${token}`;
2358
+ }
2359
+ if (auth.scheme === "basic") {
2360
+ return `Basic ${btoa(token)}`;
2361
+ }
2362
+ return token;
2363
+ };
2364
+ }
2365
+ });
2366
+
2367
+ // src/client/client/utils.gen.ts
2368
+ async function setAuthParams(options) {
2369
+ for (const auth of options.security ?? []) {
2370
+ if (checkForExistence(options, auth.name)) {
2371
+ continue;
2372
+ }
2373
+ const token = await getAuthToken(auth, options.auth);
2374
+ if (!token) {
2375
+ continue;
2376
+ }
2377
+ const name = auth.name ?? "Authorization";
2378
+ switch (auth.in) {
2379
+ case "query":
2380
+ if (!options.query) {
2381
+ options.query = {};
2382
+ }
2383
+ options.query[name] = token;
2384
+ break;
2385
+ case "cookie":
2386
+ options.headers.append("Cookie", `${name}=${token}`);
2387
+ break;
2388
+ case "header":
2389
+ default:
2390
+ options.headers.set(name, token);
2391
+ break;
2392
+ }
2393
+ }
2394
+ }
2395
+ var PATH_PARAM_RE, defaultPathSerializer, createQuerySerializer, getParseAs, checkForExistence, buildUrl, getUrl, mergeConfigs, headersEntries, mergeHeaders, Interceptors, createInterceptors, defaultQuerySerializer, defaultHeaders, createConfig;
2396
+ var init_utils_gen2 = __esm({
2397
+ "src/client/client/utils.gen.ts"() {
2398
+ "use strict";
2399
+ init_auth_gen();
2400
+ init_bodySerializer_gen();
2401
+ init_pathSerializer_gen();
2402
+ PATH_PARAM_RE = /\{[^{}]+\}/g;
2403
+ defaultPathSerializer = ({ path, url: _url }) => {
2404
+ let url = _url;
2405
+ const matches = _url.match(PATH_PARAM_RE);
2406
+ if (matches) {
2407
+ for (const match of matches) {
2408
+ let explode = false;
2409
+ let name = match.substring(1, match.length - 1);
2410
+ let style = "simple";
2411
+ if (name.endsWith("*")) {
2412
+ explode = true;
2413
+ name = name.substring(0, name.length - 1);
2414
+ }
2415
+ if (name.startsWith(".")) {
2416
+ name = name.substring(1);
2417
+ style = "label";
2418
+ } else if (name.startsWith(";")) {
2419
+ name = name.substring(1);
2420
+ style = "matrix";
2421
+ }
2422
+ const value = path[name];
2423
+ if (value === void 0 || value === null) {
2424
+ continue;
2425
+ }
2426
+ if (Array.isArray(value)) {
2427
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
2428
+ continue;
2429
+ }
2430
+ if (typeof value === "object") {
2431
+ url = url.replace(
2432
+ match,
2433
+ serializeObjectParam({
2434
+ explode,
2435
+ name,
2436
+ style,
2437
+ value,
2438
+ valueOnly: true
2439
+ })
2440
+ );
2441
+ continue;
2442
+ }
2443
+ if (style === "matrix") {
2444
+ url = url.replace(
2445
+ match,
2446
+ `;${serializePrimitiveParam({
2447
+ name,
2448
+ value
2449
+ })}`
2450
+ );
2451
+ continue;
2452
+ }
2453
+ const replaceValue = encodeURIComponent(
2454
+ style === "label" ? `.${value}` : value
2455
+ );
2456
+ url = url.replace(match, replaceValue);
2457
+ }
2458
+ }
2459
+ return url;
2460
+ };
2461
+ createQuerySerializer = ({
2462
+ parameters = {},
2463
+ ...args
2464
+ } = {}) => {
2465
+ const querySerializer = (queryParams) => {
2466
+ const search = [];
2467
+ if (queryParams && typeof queryParams === "object") {
2468
+ for (const name in queryParams) {
2469
+ const value = queryParams[name];
2470
+ if (value === void 0 || value === null) {
2471
+ continue;
2472
+ }
2473
+ const options = parameters[name] || args;
2474
+ if (Array.isArray(value)) {
2475
+ const serializedArray = serializeArrayParam({
2476
+ allowReserved: options.allowReserved,
2477
+ explode: true,
2478
+ name,
2479
+ style: "form",
2480
+ value,
2481
+ ...options.array
2482
+ });
2483
+ if (serializedArray) search.push(serializedArray);
2484
+ } else if (typeof value === "object") {
2485
+ const serializedObject = serializeObjectParam({
2486
+ allowReserved: options.allowReserved,
2487
+ explode: true,
2488
+ name,
2489
+ style: "deepObject",
2490
+ value,
2491
+ ...options.object
2492
+ });
2493
+ if (serializedObject) search.push(serializedObject);
2494
+ } else {
2495
+ const serializedPrimitive = serializePrimitiveParam({
2496
+ allowReserved: options.allowReserved,
2497
+ name,
2498
+ value
2499
+ });
2500
+ if (serializedPrimitive) search.push(serializedPrimitive);
2501
+ }
2502
+ }
2503
+ }
2504
+ return search.join("&");
2505
+ };
2506
+ return querySerializer;
2507
+ };
2508
+ getParseAs = (contentType) => {
2509
+ if (!contentType) {
2510
+ return "stream";
2511
+ }
2512
+ const cleanContent = contentType.split(";")[0]?.trim();
2513
+ if (!cleanContent) {
2514
+ return;
2515
+ }
2516
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
2517
+ return "json";
2518
+ }
2519
+ if (cleanContent === "multipart/form-data") {
2520
+ return "formData";
2521
+ }
2522
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
2523
+ return "blob";
2524
+ }
2525
+ if (cleanContent.startsWith("text/")) {
2526
+ return "text";
2527
+ }
2528
+ return;
2529
+ };
2530
+ checkForExistence = (options, name) => {
2531
+ if (!name) {
2532
+ return false;
2533
+ }
2534
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
2535
+ return true;
2536
+ }
2537
+ return false;
2538
+ };
2539
+ buildUrl = (options) => {
2540
+ const url = getUrl({
2541
+ baseUrl: options.baseUrl,
2542
+ path: options.path,
2543
+ query: options.query,
2544
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
2545
+ url: options.url
2546
+ });
2547
+ return url;
2548
+ };
2549
+ getUrl = ({
2550
+ baseUrl,
2551
+ path,
2552
+ query,
2553
+ querySerializer,
2554
+ url: _url
2555
+ }) => {
2556
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
2557
+ let url = (baseUrl ?? "") + pathUrl;
2558
+ if (path) {
2559
+ url = defaultPathSerializer({ path, url });
2560
+ }
2561
+ let search = query ? querySerializer(query) : "";
2562
+ if (search.startsWith("?")) {
2563
+ search = search.substring(1);
2564
+ }
2565
+ if (search) {
2566
+ url += `?${search}`;
2567
+ }
2568
+ return url;
2569
+ };
2570
+ mergeConfigs = (a, b) => {
2571
+ const config = { ...a, ...b };
2572
+ if (config.baseUrl?.endsWith("/")) {
2573
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
2574
+ }
2575
+ config.headers = mergeHeaders(a.headers, b.headers);
2576
+ return config;
2577
+ };
2578
+ headersEntries = (headers) => {
2579
+ const entries = [];
2580
+ headers.forEach((value, key) => {
2581
+ entries.push([key, value]);
2582
+ });
2583
+ return entries;
2584
+ };
2585
+ mergeHeaders = (...headers) => {
2586
+ const mergedHeaders = new Headers();
2587
+ for (const header of headers) {
2588
+ if (!header || typeof header !== "object") {
2589
+ continue;
2590
+ }
2591
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
2592
+ for (const [key, value] of iterator) {
2593
+ if (value === null) {
2594
+ mergedHeaders.delete(key);
2595
+ } else if (Array.isArray(value)) {
2596
+ for (const v of value) {
2597
+ mergedHeaders.append(key, v);
2598
+ }
2599
+ } else if (value !== void 0) {
2600
+ mergedHeaders.set(
2601
+ key,
2602
+ typeof value === "object" ? JSON.stringify(value) : value
2603
+ );
2604
+ }
2605
+ }
2606
+ }
2607
+ return mergedHeaders;
2608
+ };
2609
+ Interceptors = class {
2610
+ constructor() {
2611
+ this.fns = [];
2612
+ }
2613
+ clear() {
2614
+ this.fns = [];
2615
+ }
2616
+ eject(id) {
2617
+ const index = this.getInterceptorIndex(id);
2618
+ if (this.fns[index]) {
2619
+ this.fns[index] = null;
2620
+ }
2621
+ }
2622
+ exists(id) {
2623
+ const index = this.getInterceptorIndex(id);
2624
+ return Boolean(this.fns[index]);
2625
+ }
2626
+ getInterceptorIndex(id) {
2627
+ if (typeof id === "number") {
2628
+ return this.fns[id] ? id : -1;
2629
+ }
2630
+ return this.fns.indexOf(id);
2631
+ }
2632
+ update(id, fn) {
2633
+ const index = this.getInterceptorIndex(id);
2634
+ if (this.fns[index]) {
2635
+ this.fns[index] = fn;
2636
+ return id;
2637
+ }
2638
+ return false;
2639
+ }
2640
+ use(fn) {
2641
+ this.fns.push(fn);
2642
+ return this.fns.length - 1;
2643
+ }
2644
+ };
2645
+ createInterceptors = () => ({
2646
+ error: new Interceptors(),
2647
+ request: new Interceptors(),
2648
+ response: new Interceptors()
2649
+ });
2650
+ defaultQuerySerializer = createQuerySerializer({
2651
+ allowReserved: false,
2652
+ array: {
2653
+ explode: true,
2654
+ style: "form"
2655
+ },
2656
+ object: {
2657
+ explode: true,
2658
+ style: "deepObject"
2659
+ }
2660
+ });
2661
+ defaultHeaders = {
2662
+ "Content-Type": "application/json"
2663
+ };
2664
+ createConfig = (override = {}) => ({
2665
+ ...jsonBodySerializer,
2666
+ headers: defaultHeaders,
2667
+ parseAs: "auto",
2668
+ querySerializer: defaultQuerySerializer,
2669
+ ...override
2670
+ });
2671
+ }
2672
+ });
2673
+
2674
+ // src/client/client/client.gen.ts
2675
+ var createClient;
2676
+ var init_client_gen = __esm({
2677
+ "src/client/client/client.gen.ts"() {
2678
+ "use strict";
2679
+ init_serverSentEvents_gen();
2680
+ init_utils_gen();
2681
+ init_utils_gen2();
2682
+ createClient = (config = {}) => {
2683
+ let _config = mergeConfigs(createConfig(), config);
2684
+ const getConfig = () => ({ ..._config });
2685
+ const setConfig = (config2) => {
2686
+ _config = mergeConfigs(_config, config2);
2687
+ return getConfig();
2688
+ };
2689
+ const interceptors = createInterceptors();
2690
+ const beforeRequest = async (options) => {
2691
+ const opts = {
2692
+ ..._config,
2693
+ ...options,
2694
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
2695
+ headers: mergeHeaders(_config.headers, options.headers),
2696
+ serializedBody: void 0
2697
+ };
2698
+ if (opts.security) {
2699
+ await setAuthParams(opts);
2700
+ }
2701
+ if (opts.requestValidator) {
2702
+ await opts.requestValidator(opts);
2703
+ }
2704
+ if (opts.body !== void 0 && opts.bodySerializer) {
2705
+ opts.serializedBody = opts.bodySerializer(opts.body);
2706
+ }
2707
+ if (opts.body === void 0 || opts.serializedBody === "") {
2708
+ opts.headers.delete("Content-Type");
2709
+ }
2710
+ const resolvedOpts = opts;
2711
+ const url = buildUrl(resolvedOpts);
2712
+ return { opts: resolvedOpts, url };
2713
+ };
2714
+ const request = async (options) => {
2715
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
2716
+ let response;
2717
+ try {
2718
+ const { opts, url } = await beforeRequest(options);
2719
+ for (const fn of interceptors.request.fns) {
2720
+ if (fn) {
2721
+ await fn(opts);
2722
+ }
2723
+ }
2724
+ const _fetch = opts.fetch;
2725
+ const requestInit = {
2726
+ ...opts,
2727
+ body: getValidRequestBody(opts)
2728
+ };
2729
+ response = await _fetch(url, requestInit);
2730
+ for (const fn of interceptors.response.fns) {
2731
+ if (fn) {
2732
+ response = await fn(response, opts);
2733
+ }
2734
+ }
2735
+ const result = {
2736
+ response
2737
+ };
2738
+ if (response.ok) {
2739
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
2740
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
2741
+ let emptyData;
2742
+ switch (parseAs) {
2743
+ case "arrayBuffer":
2744
+ case "blob":
2745
+ case "text":
2746
+ emptyData = await response[parseAs]();
2747
+ break;
2748
+ case "formData":
2749
+ emptyData = new FormData();
2750
+ break;
2751
+ case "stream":
2752
+ emptyData = response.body;
2753
+ break;
2754
+ case "json":
2755
+ default:
2756
+ emptyData = {};
2757
+ break;
2758
+ }
2759
+ return {
2760
+ data: emptyData,
2761
+ ...result
2762
+ };
2763
+ }
2764
+ let data;
2765
+ switch (parseAs) {
2766
+ case "arrayBuffer":
2767
+ case "blob":
2768
+ case "formData":
2769
+ case "text":
2770
+ data = await response[parseAs]();
2771
+ break;
2772
+ case "json": {
2773
+ const text12 = await response.text();
2774
+ data = text12 ? JSON.parse(text12) : {};
2775
+ break;
2776
+ }
2777
+ case "stream":
2778
+ return {
2779
+ data: response.body,
2780
+ ...result
2781
+ };
2782
+ }
2783
+ if (parseAs === "json") {
2784
+ if (opts.responseValidator) {
2785
+ await opts.responseValidator(data);
2786
+ }
2787
+ if (opts.responseTransformer) {
2788
+ data = await opts.responseTransformer(data);
2789
+ }
2790
+ }
2791
+ return {
2792
+ data,
2793
+ ...result
2794
+ };
2795
+ }
2796
+ const textError = await response.text();
2797
+ let jsonError;
2798
+ try {
2799
+ jsonError = JSON.parse(textError);
2800
+ } catch {
2801
+ }
2802
+ throw jsonError ?? textError;
2803
+ } catch (error) {
2804
+ let finalError = error;
2805
+ for (const fn of interceptors.error.fns) {
2806
+ if (fn) {
2807
+ finalError = await fn(finalError, response, options);
2808
+ }
2809
+ }
2810
+ finalError = finalError || {};
2811
+ if (throwOnError) {
2812
+ throw finalError;
2813
+ }
2814
+ return {
2815
+ error: finalError,
2816
+ response
2817
+ };
2818
+ }
2819
+ };
2820
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
2821
+ const makeSseFn = (method) => async (options) => {
2822
+ const { opts, url } = await beforeRequest(options);
2823
+ return createSseClient({
2824
+ ...opts,
2825
+ body: opts.body,
2826
+ method,
2827
+ onRequest: async (url2, init) => {
2828
+ let request2 = new Request(url2, init);
2829
+ const requestInit = { ...init, url: url2 };
2830
+ for (const fn of interceptors.request.fns) {
2831
+ if (fn) {
2832
+ await fn(requestInit);
2833
+ request2 = new Request(requestInit.url, requestInit);
2834
+ }
2835
+ }
2836
+ return request2;
2837
+ },
2838
+ serializedBody: getValidRequestBody(opts),
2839
+ url
2840
+ });
2841
+ };
2842
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
2843
+ return {
2844
+ buildUrl: _buildUrl,
2845
+ connect: makeMethodFn("CONNECT"),
2846
+ delete: makeMethodFn("DELETE"),
2847
+ get: makeMethodFn("GET"),
2848
+ getConfig,
2849
+ head: makeMethodFn("HEAD"),
2850
+ interceptors,
2851
+ options: makeMethodFn("OPTIONS"),
2852
+ patch: makeMethodFn("PATCH"),
2853
+ post: makeMethodFn("POST"),
2854
+ put: makeMethodFn("PUT"),
2855
+ request,
2856
+ setConfig,
2857
+ sse: {
2858
+ connect: makeSseFn("CONNECT"),
2859
+ delete: makeSseFn("DELETE"),
2860
+ get: makeSseFn("GET"),
2861
+ head: makeSseFn("HEAD"),
2862
+ options: makeSseFn("OPTIONS"),
2863
+ patch: makeSseFn("PATCH"),
2864
+ post: makeSseFn("POST"),
2865
+ put: makeSseFn("PUT"),
2866
+ trace: makeSseFn("TRACE")
2867
+ },
2868
+ trace: makeMethodFn("TRACE")
2869
+ };
2870
+ };
2871
+ }
2872
+ });
2873
+
2874
+ // src/client/client/index.ts
2875
+ var init_client = __esm({
2876
+ "src/client/client/index.ts"() {
2877
+ "use strict";
2878
+ init_client_gen();
2879
+ init_utils_gen2();
2880
+ }
2881
+ });
2882
+
2051
2883
  // src/clientConfig.ts
2052
2884
  var clientConfig_exports = {};
2053
2885
  __export(clientConfig_exports, {
@@ -2080,6 +2912,53 @@ var init_clientConfig = __esm({
2080
2912
  }
2081
2913
  });
2082
2914
 
2915
+ // src/client/client.gen.ts
2916
+ var client;
2917
+ var init_client_gen2 = __esm({
2918
+ "src/client/client.gen.ts"() {
2919
+ "use strict";
2920
+ init_clientConfig();
2921
+ init_client();
2922
+ client = createClient(createClientConfig(createConfig()));
2923
+ }
2924
+ });
2925
+
2926
+ // src/client/sdk.gen.ts
2927
+ var getApiV1CreditsBalance, getApiV1CreditsPacks, postApiV1CreditsPurchase, postApiV1Embeddings, getApiV1Models;
2928
+ var init_sdk_gen = __esm({
2929
+ "src/client/sdk.gen.ts"() {
2930
+ "use strict";
2931
+ init_client_gen2();
2932
+ getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
2933
+ getApiV1CreditsPacks = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/packs", ...options });
2934
+ postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
2935
+ url: "/api/v1/credits/purchase",
2936
+ ...options,
2937
+ headers: {
2938
+ "Content-Type": "application/json",
2939
+ ...options.headers
2940
+ }
2941
+ });
2942
+ postApiV1Embeddings = (options) => (options.client ?? client).post({
2943
+ url: "/api/v1/embeddings",
2944
+ ...options,
2945
+ headers: {
2946
+ "Content-Type": "application/json",
2947
+ ...options.headers
2948
+ }
2949
+ });
2950
+ getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
2951
+ }
2952
+ });
2953
+
2954
+ // src/client/index.ts
2955
+ var init_client2 = __esm({
2956
+ "src/client/index.ts"() {
2957
+ "use strict";
2958
+ init_sdk_gen();
2959
+ }
2960
+ });
2961
+
2083
2962
  // src/lib/memoryEngine/generate.ts
2084
2963
  async function withEmbeddingRetry(call) {
2085
2964
  let last;
@@ -2134,7 +3013,7 @@ async function generateEmbedding(text12, options) {
2134
3013
  throw new Error("Either apiKey or getToken must be provided");
2135
3014
  }
2136
3015
  const response = await withEmbeddingRetry(
2137
- () => (0, import_client.postApiV1Embeddings)({
3016
+ () => postApiV1Embeddings({
2138
3017
  baseUrl,
2139
3018
  body: {
2140
3019
  // Mask PII from the request body only — the cache above still keys on
@@ -2166,7 +3045,7 @@ async function generateEmbedding(text12, options) {
2166
3045
  }
2167
3046
  async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput) {
2168
3047
  const response = await withEmbeddingRetry(
2169
- () => (0, import_client.postApiV1Embeddings)({
3048
+ () => postApiV1Embeddings({
2170
3049
  baseUrl,
2171
3050
  // Mask PII from the request body only; cache/order still key on originals.
2172
3051
  body: { input: maskInput ? texts.map(maskInput) : texts, model },
@@ -2267,11 +3146,11 @@ async function generateEmbeddings(texts, options) {
2267
3146
  }
2268
3147
  return results;
2269
3148
  }
2270
- var import_client, EMBED_MAX_ATTEMPTS, EmbeddingHttpError, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
3149
+ var EMBED_MAX_ATTEMPTS, EmbeddingHttpError, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
2271
3150
  var init_generate = __esm({
2272
3151
  "src/lib/memoryEngine/generate.ts"() {
2273
3152
  "use strict";
2274
- import_client = require("@anuma/sdk");
3153
+ init_client2();
2275
3154
  init_clientConfig();
2276
3155
  init_constants();
2277
3156
  EMBED_MAX_ATTEMPTS = 4;
@@ -3097,6 +3976,29 @@ var init_redactor = __esm({
3097
3976
  }
3098
3977
  });
3099
3978
 
3979
+ // src/lib/chat/endpointOverride.ts
3980
+ function validateEndpointOverride(override) {
3981
+ const trimmed = override.trim();
3982
+ if (trimmed === "") {
3983
+ return {
3984
+ valid: false,
3985
+ message: 'endpointOverride must be a non-empty, root-relative path (e.g. "/api/v1/utility/responses"); received an empty or whitespace-only string'
3986
+ };
3987
+ }
3988
+ if (trimmed.startsWith("//") || trimmed.includes("://")) {
3989
+ return {
3990
+ valid: false,
3991
+ message: `endpointOverride must be a root-relative path (e.g. "/api/v1/utility/responses"), not a protocol-relative or absolute URL; received "${trimmed}"`
3992
+ };
3993
+ }
3994
+ return { valid: true, endpoint: trimmed.startsWith("/") ? trimmed : `/${trimmed}` };
3995
+ }
3996
+ var init_endpointOverride = __esm({
3997
+ "src/lib/chat/endpointOverride.ts"() {
3998
+ "use strict";
3999
+ }
4000
+ });
4001
+
3100
4002
  // src/lib/db/entities/types.ts
3101
4003
  function normalizeEntityName(name) {
3102
4004
  return name.trim().toLowerCase();
@@ -4147,6 +5049,14 @@ async function resolvePortalAuthHeaders(auth, tag) {
4147
5049
  }
4148
5050
  async function callPortalJsonCompletion(req) {
4149
5051
  const log = getLogger();
5052
+ let endpoint = "/api/v1/chat/completions";
5053
+ if (req.endpointOverride !== void 0) {
5054
+ const overrideValidation = validateEndpointOverride(req.endpointOverride);
5055
+ if (!overrideValidation.valid) {
5056
+ throw new Error(overrideValidation.message);
5057
+ }
5058
+ endpoint = overrideValidation.endpoint;
5059
+ }
4150
5060
  const maxAttempts = Math.max(1, req.maxAttempts ?? 3);
4151
5061
  const startedAt = Date.now();
4152
5062
  const overBudget = () => req.totalTimeoutMs !== void 0 && Date.now() - startedAt >= req.totalTimeoutMs;
@@ -4162,7 +5072,7 @@ async function callPortalJsonCompletion(req) {
4162
5072
  Math.min(req.timeoutMs ?? 6e4, req.totalTimeoutMs - (Date.now() - startedAt))
4163
5073
  )
4164
5074
  } : req;
4165
- const outcome = await attemptPortalJson(attemptReq);
5075
+ const outcome = await attemptPortalJson(attemptReq, endpoint);
4166
5076
  if (outcome.kind === "ok") return outcome.value;
4167
5077
  if (outcome.kind === "terminal") {
4168
5078
  log.warn(`[${req.tag}] ${outcome.reason}`);
@@ -4185,7 +5095,7 @@ async function callPortalJsonCompletion(req) {
4185
5095
  }
4186
5096
  return null;
4187
5097
  }
4188
- async function attemptPortalJson(req) {
5098
+ async function attemptPortalJson(req, endpoint) {
4189
5099
  const baseUrl = req.baseUrl ?? defaultBaseUrl();
4190
5100
  const fetchImpl = req.fetchFn ?? fetch;
4191
5101
  const timeoutMs = req.timeoutMs ?? 6e4;
@@ -4210,7 +5120,7 @@ async function attemptPortalJson(req) {
4210
5120
  if (!supportsJsonObjectFormat) delete requestBody.response_format;
4211
5121
  let response;
4212
5122
  try {
4213
- response = await fetchImpl(`${baseUrl}/api/v1/chat/completions`, {
5123
+ response = await fetchImpl(`${baseUrl}${endpoint}`, {
4214
5124
  method: "POST",
4215
5125
  headers: { ...authHeaders, "Content-Type": "application/json" },
4216
5126
  body: JSON.stringify(requestBody),
@@ -4307,6 +5217,7 @@ var init_portalLlm = __esm({
4307
5217
  "src/lib/memory/portalLlm.ts"() {
4308
5218
  "use strict";
4309
5219
  init_clientConfig();
5220
+ init_endpointOverride();
4310
5221
  init_logger();
4311
5222
  RESPONSE_FORMAT_OK = /* @__PURE__ */ new Set(["openai", "inclusionai", "deepseek"]);
4312
5223
  RESPONSE_SCHEMA_OK = /* @__PURE__ */ new Set(["openai"]);
@@ -7133,147 +8044,22 @@ function createWebSearchPreProcessor(options = {}) {
7133
8044
  const results = await options.fetchSearchResults(prompt, { signal });
7134
8045
  if (typeof results === "string") {
7135
8046
  const wrapped = wrapAsUserText("Web search context:", results);
7136
- return wrapped.length === 0 ? void 0 : wrapped;
7137
- }
7138
- if (results.length === 0) return;
7139
- return results;
7140
- };
7141
- }
7142
-
7143
- // src/lib/chat/resumeStream.ts
7144
- init_clientConfig();
7145
-
7146
- // src/client/core/serverSentEvents.gen.ts
7147
- function createSseClient({
7148
- onRequest,
7149
- onSseError,
7150
- onSseEvent,
7151
- responseTransformer,
7152
- responseValidator,
7153
- sseDefaultRetryDelay,
7154
- sseMaxRetryAttempts,
7155
- sseMaxRetryDelay,
7156
- sseSleepFn,
7157
- url,
7158
- ...options
7159
- }) {
7160
- let lastEventId;
7161
- const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
7162
- const createStream = async function* () {
7163
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
7164
- let attempt = 0;
7165
- const signal = options.signal ?? new AbortController().signal;
7166
- while (true) {
7167
- if (signal.aborted) break;
7168
- attempt++;
7169
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
7170
- if (lastEventId !== void 0) {
7171
- headers.set("Last-Event-ID", lastEventId);
7172
- }
7173
- try {
7174
- const requestInit = {
7175
- redirect: "follow",
7176
- ...options,
7177
- body: options.serializedBody,
7178
- headers,
7179
- signal
7180
- };
7181
- let request = new Request(url, requestInit);
7182
- if (onRequest) {
7183
- request = await onRequest(url, requestInit);
7184
- }
7185
- const _fetch = options.fetch ?? globalThis.fetch;
7186
- const response = await _fetch(request);
7187
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
7188
- if (!response.body) throw new Error("No body in SSE response");
7189
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
7190
- let buffer = "";
7191
- const abortHandler = () => {
7192
- try {
7193
- reader.cancel();
7194
- } catch {
7195
- }
7196
- };
7197
- signal.addEventListener("abort", abortHandler);
7198
- try {
7199
- while (true) {
7200
- const { done, value } = await reader.read();
7201
- if (done) break;
7202
- buffer += value;
7203
- buffer = buffer.replace(/\r\n?/g, "\n");
7204
- const chunks = buffer.split("\n\n");
7205
- buffer = chunks.pop() ?? "";
7206
- for (const chunk of chunks) {
7207
- const lines = chunk.split("\n");
7208
- const dataLines = [];
7209
- let eventName;
7210
- for (const line of lines) {
7211
- if (line.startsWith("data:")) {
7212
- dataLines.push(line.replace(/^data:\s*/, ""));
7213
- } else if (line.startsWith("event:")) {
7214
- eventName = line.replace(/^event:\s*/, "");
7215
- } else if (line.startsWith("id:")) {
7216
- lastEventId = line.replace(/^id:\s*/, "");
7217
- } else if (line.startsWith("retry:")) {
7218
- const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
7219
- if (!Number.isNaN(parsed)) {
7220
- retryDelay = parsed;
7221
- }
7222
- }
7223
- }
7224
- let data;
7225
- let parsedJson = false;
7226
- if (dataLines.length) {
7227
- const rawData = dataLines.join("\n");
7228
- try {
7229
- data = JSON.parse(rawData);
7230
- parsedJson = true;
7231
- } catch {
7232
- data = rawData;
7233
- }
7234
- }
7235
- if (parsedJson) {
7236
- if (responseValidator) {
7237
- await responseValidator(data);
7238
- }
7239
- if (responseTransformer) {
7240
- data = await responseTransformer(data);
7241
- }
7242
- }
7243
- onSseEvent?.({
7244
- data,
7245
- event: eventName,
7246
- id: lastEventId,
7247
- retry: retryDelay
7248
- });
7249
- if (dataLines.length) {
7250
- yield data;
7251
- }
7252
- }
7253
- }
7254
- } finally {
7255
- signal.removeEventListener("abort", abortHandler);
7256
- reader.releaseLock();
7257
- }
7258
- break;
7259
- } catch (error) {
7260
- onSseError?.(error);
7261
- if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
7262
- break;
7263
- }
7264
- const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
7265
- await sleep4(backoff);
7266
- }
8047
+ return wrapped.length === 0 ? void 0 : wrapped;
7267
8048
  }
8049
+ if (results.length === 0) return;
8050
+ return results;
7268
8051
  };
7269
- const stream = createStream();
7270
- return { stream };
7271
8052
  }
7272
8053
 
8054
+ // src/lib/chat/resumeStream.ts
8055
+ init_clientConfig();
8056
+
7273
8057
  // src/lib/chat/toolLoop.ts
8058
+ init_serverSentEvents_gen();
7274
8059
  init_clientConfig();
7275
8060
  init_embeddings();
7276
8061
  init_redactor();
8062
+ init_endpointOverride();
7277
8063
 
7278
8064
  // src/lib/chat/runHooks.ts
7279
8065
  function composeHooks(hooks) {
@@ -9453,22 +10239,6 @@ function linkAbortSignals(a, b) {
9453
10239
  }
9454
10240
  };
9455
10241
  }
9456
- function validateEndpointOverride(override) {
9457
- const trimmed = override.trim();
9458
- if (trimmed === "") {
9459
- return {
9460
- valid: false,
9461
- message: 'endpointOverride must be a non-empty, root-relative path (e.g. "/api/v1/utility/responses"); received an empty or whitespace-only string'
9462
- };
9463
- }
9464
- if (trimmed.startsWith("//") || trimmed.includes("://")) {
9465
- return {
9466
- valid: false,
9467
- message: `endpointOverride must be a root-relative path (e.g. "/api/v1/utility/responses"), not a protocol-relative or absolute URL; received "${trimmed}"`
9468
- };
9469
- }
9470
- return { valid: true, endpoint: trimmed.startsWith("/") ? trimmed : `/${trimmed}` };
9471
- }
9472
10242
  async function runToolLoop(options) {
9473
10243
  const {
9474
10244
  model,
@@ -10724,675 +11494,7 @@ var xhrTransport = (options) => {
10724
11494
 
10725
11495
  // src/react/useCredits.ts
10726
11496
  var import_react = require("react");
10727
-
10728
- // src/client/core/bodySerializer.gen.ts
10729
- var jsonBodySerializer = {
10730
- bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
10731
- };
10732
-
10733
- // src/client/core/pathSerializer.gen.ts
10734
- var separatorArrayExplode = (style) => {
10735
- switch (style) {
10736
- case "label":
10737
- return ".";
10738
- case "matrix":
10739
- return ";";
10740
- case "simple":
10741
- return ",";
10742
- default:
10743
- return "&";
10744
- }
10745
- };
10746
- var separatorArrayNoExplode = (style) => {
10747
- switch (style) {
10748
- case "form":
10749
- return ",";
10750
- case "pipeDelimited":
10751
- return "|";
10752
- case "spaceDelimited":
10753
- return "%20";
10754
- default:
10755
- return ",";
10756
- }
10757
- };
10758
- var separatorObjectExplode = (style) => {
10759
- switch (style) {
10760
- case "label":
10761
- return ".";
10762
- case "matrix":
10763
- return ";";
10764
- case "simple":
10765
- return ",";
10766
- default:
10767
- return "&";
10768
- }
10769
- };
10770
- var serializeArrayParam = ({
10771
- allowReserved,
10772
- explode,
10773
- name,
10774
- style,
10775
- value
10776
- }) => {
10777
- if (!explode) {
10778
- const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
10779
- switch (style) {
10780
- case "label":
10781
- return `.${joinedValues2}`;
10782
- case "matrix":
10783
- return `;${name}=${joinedValues2}`;
10784
- case "simple":
10785
- return joinedValues2;
10786
- default:
10787
- return `${name}=${joinedValues2}`;
10788
- }
10789
- }
10790
- const separator = separatorArrayExplode(style);
10791
- const joinedValues = value.map((v) => {
10792
- if (style === "label" || style === "simple") {
10793
- return allowReserved ? v : encodeURIComponent(v);
10794
- }
10795
- return serializePrimitiveParam({
10796
- allowReserved,
10797
- name,
10798
- value: v
10799
- });
10800
- }).join(separator);
10801
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
10802
- };
10803
- var serializePrimitiveParam = ({
10804
- allowReserved,
10805
- name,
10806
- value
10807
- }) => {
10808
- if (value === void 0 || value === null) {
10809
- return "";
10810
- }
10811
- if (typeof value === "object") {
10812
- throw new Error(
10813
- "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
10814
- );
10815
- }
10816
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
10817
- };
10818
- var serializeObjectParam = ({
10819
- allowReserved,
10820
- explode,
10821
- name,
10822
- style,
10823
- value,
10824
- valueOnly
10825
- }) => {
10826
- if (value instanceof Date) {
10827
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
10828
- }
10829
- if (style !== "deepObject" && !explode) {
10830
- let values = [];
10831
- Object.entries(value).forEach(([key, v]) => {
10832
- values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
10833
- });
10834
- const joinedValues2 = values.join(",");
10835
- switch (style) {
10836
- case "form":
10837
- return `${name}=${joinedValues2}`;
10838
- case "label":
10839
- return `.${joinedValues2}`;
10840
- case "matrix":
10841
- return `;${name}=${joinedValues2}`;
10842
- default:
10843
- return joinedValues2;
10844
- }
10845
- }
10846
- const separator = separatorObjectExplode(style);
10847
- const joinedValues = Object.entries(value).map(
10848
- ([key, v]) => serializePrimitiveParam({
10849
- allowReserved,
10850
- name: style === "deepObject" ? `${name}[${key}]` : key,
10851
- value: v
10852
- })
10853
- ).join(separator);
10854
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
10855
- };
10856
-
10857
- // src/client/core/utils.gen.ts
10858
- function getValidRequestBody(options) {
10859
- const hasBody = options.body !== void 0;
10860
- const isSerializedBody = hasBody && options.bodySerializer;
10861
- if (isSerializedBody) {
10862
- if ("serializedBody" in options) {
10863
- const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
10864
- return hasSerializedBody ? options.serializedBody : null;
10865
- }
10866
- return options.body !== "" ? options.body : null;
10867
- }
10868
- if (hasBody) {
10869
- return options.body;
10870
- }
10871
- return void 0;
10872
- }
10873
-
10874
- // src/client/core/auth.gen.ts
10875
- var getAuthToken = async (auth, callback) => {
10876
- const token = typeof callback === "function" ? await callback(auth) : callback;
10877
- if (!token) {
10878
- return;
10879
- }
10880
- if (auth.scheme === "bearer") {
10881
- return `Bearer ${token}`;
10882
- }
10883
- if (auth.scheme === "basic") {
10884
- return `Basic ${btoa(token)}`;
10885
- }
10886
- return token;
10887
- };
10888
-
10889
- // src/client/client/utils.gen.ts
10890
- var PATH_PARAM_RE = /\{[^{}]+\}/g;
10891
- var defaultPathSerializer = ({ path, url: _url }) => {
10892
- let url = _url;
10893
- const matches = _url.match(PATH_PARAM_RE);
10894
- if (matches) {
10895
- for (const match of matches) {
10896
- let explode = false;
10897
- let name = match.substring(1, match.length - 1);
10898
- let style = "simple";
10899
- if (name.endsWith("*")) {
10900
- explode = true;
10901
- name = name.substring(0, name.length - 1);
10902
- }
10903
- if (name.startsWith(".")) {
10904
- name = name.substring(1);
10905
- style = "label";
10906
- } else if (name.startsWith(";")) {
10907
- name = name.substring(1);
10908
- style = "matrix";
10909
- }
10910
- const value = path[name];
10911
- if (value === void 0 || value === null) {
10912
- continue;
10913
- }
10914
- if (Array.isArray(value)) {
10915
- url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
10916
- continue;
10917
- }
10918
- if (typeof value === "object") {
10919
- url = url.replace(
10920
- match,
10921
- serializeObjectParam({
10922
- explode,
10923
- name,
10924
- style,
10925
- value,
10926
- valueOnly: true
10927
- })
10928
- );
10929
- continue;
10930
- }
10931
- if (style === "matrix") {
10932
- url = url.replace(
10933
- match,
10934
- `;${serializePrimitiveParam({
10935
- name,
10936
- value
10937
- })}`
10938
- );
10939
- continue;
10940
- }
10941
- const replaceValue = encodeURIComponent(
10942
- style === "label" ? `.${value}` : value
10943
- );
10944
- url = url.replace(match, replaceValue);
10945
- }
10946
- }
10947
- return url;
10948
- };
10949
- var createQuerySerializer = ({
10950
- parameters = {},
10951
- ...args
10952
- } = {}) => {
10953
- const querySerializer = (queryParams) => {
10954
- const search = [];
10955
- if (queryParams && typeof queryParams === "object") {
10956
- for (const name in queryParams) {
10957
- const value = queryParams[name];
10958
- if (value === void 0 || value === null) {
10959
- continue;
10960
- }
10961
- const options = parameters[name] || args;
10962
- if (Array.isArray(value)) {
10963
- const serializedArray = serializeArrayParam({
10964
- allowReserved: options.allowReserved,
10965
- explode: true,
10966
- name,
10967
- style: "form",
10968
- value,
10969
- ...options.array
10970
- });
10971
- if (serializedArray) search.push(serializedArray);
10972
- } else if (typeof value === "object") {
10973
- const serializedObject = serializeObjectParam({
10974
- allowReserved: options.allowReserved,
10975
- explode: true,
10976
- name,
10977
- style: "deepObject",
10978
- value,
10979
- ...options.object
10980
- });
10981
- if (serializedObject) search.push(serializedObject);
10982
- } else {
10983
- const serializedPrimitive = serializePrimitiveParam({
10984
- allowReserved: options.allowReserved,
10985
- name,
10986
- value
10987
- });
10988
- if (serializedPrimitive) search.push(serializedPrimitive);
10989
- }
10990
- }
10991
- }
10992
- return search.join("&");
10993
- };
10994
- return querySerializer;
10995
- };
10996
- var getParseAs = (contentType) => {
10997
- if (!contentType) {
10998
- return "stream";
10999
- }
11000
- const cleanContent = contentType.split(";")[0]?.trim();
11001
- if (!cleanContent) {
11002
- return;
11003
- }
11004
- if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
11005
- return "json";
11006
- }
11007
- if (cleanContent === "multipart/form-data") {
11008
- return "formData";
11009
- }
11010
- if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
11011
- return "blob";
11012
- }
11013
- if (cleanContent.startsWith("text/")) {
11014
- return "text";
11015
- }
11016
- return;
11017
- };
11018
- var checkForExistence = (options, name) => {
11019
- if (!name) {
11020
- return false;
11021
- }
11022
- if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
11023
- return true;
11024
- }
11025
- return false;
11026
- };
11027
- async function setAuthParams(options) {
11028
- for (const auth of options.security ?? []) {
11029
- if (checkForExistence(options, auth.name)) {
11030
- continue;
11031
- }
11032
- const token = await getAuthToken(auth, options.auth);
11033
- if (!token) {
11034
- continue;
11035
- }
11036
- const name = auth.name ?? "Authorization";
11037
- switch (auth.in) {
11038
- case "query":
11039
- if (!options.query) {
11040
- options.query = {};
11041
- }
11042
- options.query[name] = token;
11043
- break;
11044
- case "cookie":
11045
- options.headers.append("Cookie", `${name}=${token}`);
11046
- break;
11047
- case "header":
11048
- default:
11049
- options.headers.set(name, token);
11050
- break;
11051
- }
11052
- }
11053
- }
11054
- var buildUrl = (options) => {
11055
- const url = getUrl({
11056
- baseUrl: options.baseUrl,
11057
- path: options.path,
11058
- query: options.query,
11059
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
11060
- url: options.url
11061
- });
11062
- return url;
11063
- };
11064
- var getUrl = ({
11065
- baseUrl,
11066
- path,
11067
- query,
11068
- querySerializer,
11069
- url: _url
11070
- }) => {
11071
- const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
11072
- let url = (baseUrl ?? "") + pathUrl;
11073
- if (path) {
11074
- url = defaultPathSerializer({ path, url });
11075
- }
11076
- let search = query ? querySerializer(query) : "";
11077
- if (search.startsWith("?")) {
11078
- search = search.substring(1);
11079
- }
11080
- if (search) {
11081
- url += `?${search}`;
11082
- }
11083
- return url;
11084
- };
11085
- var mergeConfigs = (a, b) => {
11086
- const config = { ...a, ...b };
11087
- if (config.baseUrl?.endsWith("/")) {
11088
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
11089
- }
11090
- config.headers = mergeHeaders(a.headers, b.headers);
11091
- return config;
11092
- };
11093
- var headersEntries = (headers) => {
11094
- const entries = [];
11095
- headers.forEach((value, key) => {
11096
- entries.push([key, value]);
11097
- });
11098
- return entries;
11099
- };
11100
- var mergeHeaders = (...headers) => {
11101
- const mergedHeaders = new Headers();
11102
- for (const header of headers) {
11103
- if (!header || typeof header !== "object") {
11104
- continue;
11105
- }
11106
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
11107
- for (const [key, value] of iterator) {
11108
- if (value === null) {
11109
- mergedHeaders.delete(key);
11110
- } else if (Array.isArray(value)) {
11111
- for (const v of value) {
11112
- mergedHeaders.append(key, v);
11113
- }
11114
- } else if (value !== void 0) {
11115
- mergedHeaders.set(
11116
- key,
11117
- typeof value === "object" ? JSON.stringify(value) : value
11118
- );
11119
- }
11120
- }
11121
- }
11122
- return mergedHeaders;
11123
- };
11124
- var Interceptors = class {
11125
- constructor() {
11126
- this.fns = [];
11127
- }
11128
- clear() {
11129
- this.fns = [];
11130
- }
11131
- eject(id) {
11132
- const index = this.getInterceptorIndex(id);
11133
- if (this.fns[index]) {
11134
- this.fns[index] = null;
11135
- }
11136
- }
11137
- exists(id) {
11138
- const index = this.getInterceptorIndex(id);
11139
- return Boolean(this.fns[index]);
11140
- }
11141
- getInterceptorIndex(id) {
11142
- if (typeof id === "number") {
11143
- return this.fns[id] ? id : -1;
11144
- }
11145
- return this.fns.indexOf(id);
11146
- }
11147
- update(id, fn) {
11148
- const index = this.getInterceptorIndex(id);
11149
- if (this.fns[index]) {
11150
- this.fns[index] = fn;
11151
- return id;
11152
- }
11153
- return false;
11154
- }
11155
- use(fn) {
11156
- this.fns.push(fn);
11157
- return this.fns.length - 1;
11158
- }
11159
- };
11160
- var createInterceptors = () => ({
11161
- error: new Interceptors(),
11162
- request: new Interceptors(),
11163
- response: new Interceptors()
11164
- });
11165
- var defaultQuerySerializer = createQuerySerializer({
11166
- allowReserved: false,
11167
- array: {
11168
- explode: true,
11169
- style: "form"
11170
- },
11171
- object: {
11172
- explode: true,
11173
- style: "deepObject"
11174
- }
11175
- });
11176
- var defaultHeaders = {
11177
- "Content-Type": "application/json"
11178
- };
11179
- var createConfig = (override = {}) => ({
11180
- ...jsonBodySerializer,
11181
- headers: defaultHeaders,
11182
- parseAs: "auto",
11183
- querySerializer: defaultQuerySerializer,
11184
- ...override
11185
- });
11186
-
11187
- // src/client/client/client.gen.ts
11188
- var createClient = (config = {}) => {
11189
- let _config = mergeConfigs(createConfig(), config);
11190
- const getConfig = () => ({ ..._config });
11191
- const setConfig = (config2) => {
11192
- _config = mergeConfigs(_config, config2);
11193
- return getConfig();
11194
- };
11195
- const interceptors = createInterceptors();
11196
- const beforeRequest = async (options) => {
11197
- const opts = {
11198
- ..._config,
11199
- ...options,
11200
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
11201
- headers: mergeHeaders(_config.headers, options.headers),
11202
- serializedBody: void 0
11203
- };
11204
- if (opts.security) {
11205
- await setAuthParams(opts);
11206
- }
11207
- if (opts.requestValidator) {
11208
- await opts.requestValidator(opts);
11209
- }
11210
- if (opts.body !== void 0 && opts.bodySerializer) {
11211
- opts.serializedBody = opts.bodySerializer(opts.body);
11212
- }
11213
- if (opts.body === void 0 || opts.serializedBody === "") {
11214
- opts.headers.delete("Content-Type");
11215
- }
11216
- const resolvedOpts = opts;
11217
- const url = buildUrl(resolvedOpts);
11218
- return { opts: resolvedOpts, url };
11219
- };
11220
- const request = async (options) => {
11221
- const throwOnError = options.throwOnError ?? _config.throwOnError;
11222
- let response;
11223
- try {
11224
- const { opts, url } = await beforeRequest(options);
11225
- for (const fn of interceptors.request.fns) {
11226
- if (fn) {
11227
- await fn(opts);
11228
- }
11229
- }
11230
- const _fetch = opts.fetch;
11231
- const requestInit = {
11232
- ...opts,
11233
- body: getValidRequestBody(opts)
11234
- };
11235
- response = await _fetch(url, requestInit);
11236
- for (const fn of interceptors.response.fns) {
11237
- if (fn) {
11238
- response = await fn(response, opts);
11239
- }
11240
- }
11241
- const result = {
11242
- response
11243
- };
11244
- if (response.ok) {
11245
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
11246
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
11247
- let emptyData;
11248
- switch (parseAs) {
11249
- case "arrayBuffer":
11250
- case "blob":
11251
- case "text":
11252
- emptyData = await response[parseAs]();
11253
- break;
11254
- case "formData":
11255
- emptyData = new FormData();
11256
- break;
11257
- case "stream":
11258
- emptyData = response.body;
11259
- break;
11260
- case "json":
11261
- default:
11262
- emptyData = {};
11263
- break;
11264
- }
11265
- return {
11266
- data: emptyData,
11267
- ...result
11268
- };
11269
- }
11270
- let data;
11271
- switch (parseAs) {
11272
- case "arrayBuffer":
11273
- case "blob":
11274
- case "formData":
11275
- case "text":
11276
- data = await response[parseAs]();
11277
- break;
11278
- case "json": {
11279
- const text12 = await response.text();
11280
- data = text12 ? JSON.parse(text12) : {};
11281
- break;
11282
- }
11283
- case "stream":
11284
- return {
11285
- data: response.body,
11286
- ...result
11287
- };
11288
- }
11289
- if (parseAs === "json") {
11290
- if (opts.responseValidator) {
11291
- await opts.responseValidator(data);
11292
- }
11293
- if (opts.responseTransformer) {
11294
- data = await opts.responseTransformer(data);
11295
- }
11296
- }
11297
- return {
11298
- data,
11299
- ...result
11300
- };
11301
- }
11302
- const textError = await response.text();
11303
- let jsonError;
11304
- try {
11305
- jsonError = JSON.parse(textError);
11306
- } catch {
11307
- }
11308
- throw jsonError ?? textError;
11309
- } catch (error) {
11310
- let finalError = error;
11311
- for (const fn of interceptors.error.fns) {
11312
- if (fn) {
11313
- finalError = await fn(finalError, response, options);
11314
- }
11315
- }
11316
- finalError = finalError || {};
11317
- if (throwOnError) {
11318
- throw finalError;
11319
- }
11320
- return {
11321
- error: finalError,
11322
- response
11323
- };
11324
- }
11325
- };
11326
- const makeMethodFn = (method) => (options) => request({ ...options, method });
11327
- const makeSseFn = (method) => async (options) => {
11328
- const { opts, url } = await beforeRequest(options);
11329
- return createSseClient({
11330
- ...opts,
11331
- body: opts.body,
11332
- method,
11333
- onRequest: async (url2, init) => {
11334
- let request2 = new Request(url2, init);
11335
- const requestInit = { ...init, url: url2 };
11336
- for (const fn of interceptors.request.fns) {
11337
- if (fn) {
11338
- await fn(requestInit);
11339
- request2 = new Request(requestInit.url, requestInit);
11340
- }
11341
- }
11342
- return request2;
11343
- },
11344
- serializedBody: getValidRequestBody(opts),
11345
- url
11346
- });
11347
- };
11348
- const _buildUrl = (options) => buildUrl({ ..._config, ...options });
11349
- return {
11350
- buildUrl: _buildUrl,
11351
- connect: makeMethodFn("CONNECT"),
11352
- delete: makeMethodFn("DELETE"),
11353
- get: makeMethodFn("GET"),
11354
- getConfig,
11355
- head: makeMethodFn("HEAD"),
11356
- interceptors,
11357
- options: makeMethodFn("OPTIONS"),
11358
- patch: makeMethodFn("PATCH"),
11359
- post: makeMethodFn("POST"),
11360
- put: makeMethodFn("PUT"),
11361
- request,
11362
- setConfig,
11363
- sse: {
11364
- connect: makeSseFn("CONNECT"),
11365
- delete: makeSseFn("DELETE"),
11366
- get: makeSseFn("GET"),
11367
- head: makeSseFn("HEAD"),
11368
- options: makeSseFn("OPTIONS"),
11369
- patch: makeSseFn("PATCH"),
11370
- post: makeSseFn("POST"),
11371
- put: makeSseFn("PUT"),
11372
- trace: makeSseFn("TRACE")
11373
- },
11374
- trace: makeMethodFn("TRACE")
11375
- };
11376
- };
11377
-
11378
- // src/client/client.gen.ts
11379
- init_clientConfig();
11380
- var client = createClient(createClientConfig(createConfig()));
11381
-
11382
- // src/client/sdk.gen.ts
11383
- var getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
11384
- var getApiV1CreditsPacks = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/packs", ...options });
11385
- var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
11386
- url: "/api/v1/credits/purchase",
11387
- ...options,
11388
- headers: {
11389
- "Content-Type": "application/json",
11390
- ...options.headers
11391
- }
11392
- });
11393
- var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
11394
-
11395
- // src/react/useCredits.ts
11497
+ init_sdk_gen();
11396
11498
  init_clientConfig();
11397
11499
  function useCredits(options = {}) {
11398
11500
  const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
@@ -11551,6 +11653,7 @@ function useCredits(options = {}) {
11551
11653
 
11552
11654
  // src/react/useModels.ts
11553
11655
  var import_react2 = require("react");
11656
+ init_sdk_gen();
11554
11657
  init_clientConfig();
11555
11658
  function useModels(options = {}) {
11556
11659
  const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
@@ -15905,6 +16008,9 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
15905
16008
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
15906
16009
  ...options.getToken !== void 0 && { getToken: options.getToken },
15907
16010
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
16011
+ ...options.endpointOverride !== void 0 && {
16012
+ endpointOverride: options.endpointOverride
16013
+ },
15908
16014
  model: options.model ?? DEFAULT_EXTRACTION_MODEL,
15909
16015
  systemPrompt: SYSTEM_PROMPT6,
15910
16016
  userMessage: `${vocabularyNote}Memories: