@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
@@ -37,6 +37,7 @@ import {
37
37
  createLlmNeighborRefiner,
38
38
  createMemoryVaultSearchTool,
39
39
  createMessageOp,
40
+ createSseClient,
40
41
  createSupersedingMemoryOp,
41
42
  createVaultEmbeddingCache,
42
43
  createVaultMemoriesBatchOp,
@@ -49,6 +50,7 @@ import {
49
50
  decryptField,
50
51
  decryptJsonField,
51
52
  deleteAllVaultMemoriesForUserOp,
53
+ deleteApiV1WalletsBindingByAddress,
52
54
  deleteConversationOp,
53
55
  deleteVaultMemoryOp,
54
56
  eagerEmbedContent,
@@ -70,6 +72,13 @@ import {
70
72
  getAllFilesOp,
71
73
  getAllVaultMemoriesOp,
72
74
  getAllVaultMemoryContentsOp,
75
+ getApiV1Config,
76
+ getApiV1CreditsBalance,
77
+ getApiV1CreditsPacks,
78
+ getApiV1Models,
79
+ getApiV1PhoneCallsByCallId,
80
+ getApiV1SubscriptionsStatus,
81
+ getApiV1WalletsBinding,
73
82
  getConversationOp,
74
83
  getConversationsByProjectLazyOp,
75
84
  getConversationsByProjectOp,
@@ -100,6 +109,17 @@ import {
100
109
  makeSyntheticStoredMessage,
101
110
  onClearAllEncryptionState,
102
111
  onKeyAvailable,
112
+ postApiV1CreditsPurchase,
113
+ postApiV1PhoneCalls,
114
+ postApiV1SubscriptionsCancel,
115
+ postApiV1SubscriptionsCreateCheckoutSession,
116
+ postApiV1SubscriptionsCustomerPortal,
117
+ postApiV1SubscriptionsRenew,
118
+ postApiV1WalletsBinding,
119
+ postApiV1WalletsBindingNonce,
120
+ postAuthOauthByProviderExchange,
121
+ postAuthOauthByProviderRefresh,
122
+ postAuthOauthByProviderRevoke,
103
123
  preEmbedVaultMemories,
104
124
  recall,
105
125
  replaceMemoryEntitiesGuardedOp,
@@ -129,7 +149,7 @@ import {
129
149
  updateVaultMemoryOp,
130
150
  useEncryption,
131
151
  vaultMemoryToStored
132
- } from "./chunk-DDHTJGZN.mjs";
152
+ } from "./chunk-3VPEZDYL.mjs";
133
153
  import {
134
154
  PiiRedactor,
135
155
  createStreamingDeAnonymizer,
@@ -144,142 +164,15 @@ import {
144
164
  noopLogger,
145
165
  resolvePortalAuthHeaders,
146
166
  setLogger,
147
- supportsResponseFormat
148
- } from "./chunk-DFVCS3QQ.mjs";
167
+ supportsResponseFormat,
168
+ validateEndpointOverride
169
+ } from "./chunk-BOY27A2C.mjs";
149
170
  import {
150
171
  BASE_URL,
151
172
  MCP_R2_DOMAIN,
152
- __decorateClass,
153
- createClientConfig
173
+ __decorateClass
154
174
  } from "./chunk-GYKJOWEO.mjs";
155
175
 
156
- // src/client/core/serverSentEvents.gen.ts
157
- function createSseClient({
158
- onRequest,
159
- onSseError,
160
- onSseEvent,
161
- responseTransformer,
162
- responseValidator,
163
- sseDefaultRetryDelay,
164
- sseMaxRetryAttempts,
165
- sseMaxRetryDelay,
166
- sseSleepFn,
167
- url,
168
- ...options
169
- }) {
170
- let lastEventId;
171
- const sleep3 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
172
- const createStream = async function* () {
173
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
174
- let attempt = 0;
175
- const signal = options.signal ?? new AbortController().signal;
176
- while (true) {
177
- if (signal.aborted) break;
178
- attempt++;
179
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
180
- if (lastEventId !== void 0) {
181
- headers.set("Last-Event-ID", lastEventId);
182
- }
183
- try {
184
- const requestInit = {
185
- redirect: "follow",
186
- ...options,
187
- body: options.serializedBody,
188
- headers,
189
- signal
190
- };
191
- let request = new Request(url, requestInit);
192
- if (onRequest) {
193
- request = await onRequest(url, requestInit);
194
- }
195
- const _fetch = options.fetch ?? globalThis.fetch;
196
- const response = await _fetch(request);
197
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
198
- if (!response.body) throw new Error("No body in SSE response");
199
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
200
- let buffer = "";
201
- const abortHandler = () => {
202
- try {
203
- reader.cancel();
204
- } catch {
205
- }
206
- };
207
- signal.addEventListener("abort", abortHandler);
208
- try {
209
- while (true) {
210
- const { done, value } = await reader.read();
211
- if (done) break;
212
- buffer += value;
213
- buffer = buffer.replace(/\r\n?/g, "\n");
214
- const chunks = buffer.split("\n\n");
215
- buffer = chunks.pop() ?? "";
216
- for (const chunk of chunks) {
217
- const lines = chunk.split("\n");
218
- const dataLines = [];
219
- let eventName;
220
- for (const line of lines) {
221
- if (line.startsWith("data:")) {
222
- dataLines.push(line.replace(/^data:\s*/, ""));
223
- } else if (line.startsWith("event:")) {
224
- eventName = line.replace(/^event:\s*/, "");
225
- } else if (line.startsWith("id:")) {
226
- lastEventId = line.replace(/^id:\s*/, "");
227
- } else if (line.startsWith("retry:")) {
228
- const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
229
- if (!Number.isNaN(parsed)) {
230
- retryDelay = parsed;
231
- }
232
- }
233
- }
234
- let data;
235
- let parsedJson = false;
236
- if (dataLines.length) {
237
- const rawData = dataLines.join("\n");
238
- try {
239
- data = JSON.parse(rawData);
240
- parsedJson = true;
241
- } catch {
242
- data = rawData;
243
- }
244
- }
245
- if (parsedJson) {
246
- if (responseValidator) {
247
- await responseValidator(data);
248
- }
249
- if (responseTransformer) {
250
- data = await responseTransformer(data);
251
- }
252
- }
253
- onSseEvent?.({
254
- data,
255
- event: eventName,
256
- id: lastEventId,
257
- retry: retryDelay
258
- });
259
- if (dataLines.length) {
260
- yield data;
261
- }
262
- }
263
- }
264
- } finally {
265
- signal.removeEventListener("abort", abortHandler);
266
- reader.releaseLock();
267
- }
268
- break;
269
- } catch (error) {
270
- onSseError?.(error);
271
- if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
272
- break;
273
- }
274
- const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
275
- await sleep3(backoff);
276
- }
277
- }
278
- };
279
- const stream = createStream();
280
- return { stream };
281
- }
282
-
283
176
  // src/lib/chat/runHooks.ts
284
177
  function composeHooks(hooks) {
285
178
  const handlers = hooks.filter((h) => h !== void 0 && h !== null);
@@ -2454,22 +2347,6 @@ function linkAbortSignals(a, b) {
2454
2347
  }
2455
2348
  };
2456
2349
  }
2457
- function validateEndpointOverride(override) {
2458
- const trimmed = override.trim();
2459
- if (trimmed === "") {
2460
- return {
2461
- valid: false,
2462
- message: 'endpointOverride must be a non-empty, root-relative path (e.g. "/api/v1/utility/responses"); received an empty or whitespace-only string'
2463
- };
2464
- }
2465
- if (trimmed.startsWith("//") || trimmed.includes("://")) {
2466
- return {
2467
- valid: false,
2468
- message: `endpointOverride must be a root-relative path (e.g. "/api/v1/utility/responses"), not a protocol-relative or absolute URL; received "${trimmed}"`
2469
- };
2470
- }
2471
- return { valid: true, endpoint: trimmed.startsWith("/") ? trimmed : `/${trimmed}` };
2472
- }
2473
2350
  async function runToolLoop(options) {
2474
2351
  const {
2475
2352
  model,
@@ -7351,7 +7228,7 @@ async function tryConsolidate(trimmed, ctx, options) {
7351
7228
  content: m.content,
7352
7229
  similarity: m.similarity
7353
7230
  }));
7354
- const { consolidateMemory: doConsolidate } = await import("./consolidate-3MXZV3G7.mjs");
7231
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-PWJCAPZA.mjs");
7355
7232
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
7356
7233
  if (decision.action === "create") return null;
7357
7234
  if (decision.action === "supersede" && decision.targetId && decision.content) {
@@ -9094,6 +8971,9 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
9094
8971
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
9095
8972
  ...options.getToken !== void 0 && { getToken: options.getToken },
9096
8973
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
8974
+ ...options.endpointOverride !== void 0 && {
8975
+ endpointOverride: options.endpointOverride
8976
+ },
9097
8977
  model: options.model ?? DEFAULT_EXTRACTION_MODEL,
9098
8978
  systemPrompt: SYSTEM_PROMPT4,
9099
8979
  userMessage: `${vocabularyNote}Memories:
@@ -17434,745 +17314,6 @@ function useVoice(options) {
17434
17314
 
17435
17315
  // src/react/useCredits.ts
17436
17316
  import { useCallback as useCallback12, useEffect as useEffect6, useRef as useRef6, useState as useState11 } from "react";
17437
-
17438
- // src/client/core/bodySerializer.gen.ts
17439
- var jsonBodySerializer = {
17440
- bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
17441
- };
17442
-
17443
- // src/client/core/pathSerializer.gen.ts
17444
- var separatorArrayExplode = (style) => {
17445
- switch (style) {
17446
- case "label":
17447
- return ".";
17448
- case "matrix":
17449
- return ";";
17450
- case "simple":
17451
- return ",";
17452
- default:
17453
- return "&";
17454
- }
17455
- };
17456
- var separatorArrayNoExplode = (style) => {
17457
- switch (style) {
17458
- case "form":
17459
- return ",";
17460
- case "pipeDelimited":
17461
- return "|";
17462
- case "spaceDelimited":
17463
- return "%20";
17464
- default:
17465
- return ",";
17466
- }
17467
- };
17468
- var separatorObjectExplode = (style) => {
17469
- switch (style) {
17470
- case "label":
17471
- return ".";
17472
- case "matrix":
17473
- return ";";
17474
- case "simple":
17475
- return ",";
17476
- default:
17477
- return "&";
17478
- }
17479
- };
17480
- var serializeArrayParam = ({
17481
- allowReserved,
17482
- explode,
17483
- name,
17484
- style,
17485
- value
17486
- }) => {
17487
- if (!explode) {
17488
- const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
17489
- switch (style) {
17490
- case "label":
17491
- return `.${joinedValues2}`;
17492
- case "matrix":
17493
- return `;${name}=${joinedValues2}`;
17494
- case "simple":
17495
- return joinedValues2;
17496
- default:
17497
- return `${name}=${joinedValues2}`;
17498
- }
17499
- }
17500
- const separator = separatorArrayExplode(style);
17501
- const joinedValues = value.map((v) => {
17502
- if (style === "label" || style === "simple") {
17503
- return allowReserved ? v : encodeURIComponent(v);
17504
- }
17505
- return serializePrimitiveParam({
17506
- allowReserved,
17507
- name,
17508
- value: v
17509
- });
17510
- }).join(separator);
17511
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
17512
- };
17513
- var serializePrimitiveParam = ({
17514
- allowReserved,
17515
- name,
17516
- value
17517
- }) => {
17518
- if (value === void 0 || value === null) {
17519
- return "";
17520
- }
17521
- if (typeof value === "object") {
17522
- throw new Error(
17523
- "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
17524
- );
17525
- }
17526
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
17527
- };
17528
- var serializeObjectParam = ({
17529
- allowReserved,
17530
- explode,
17531
- name,
17532
- style,
17533
- value,
17534
- valueOnly
17535
- }) => {
17536
- if (value instanceof Date) {
17537
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
17538
- }
17539
- if (style !== "deepObject" && !explode) {
17540
- let values = [];
17541
- Object.entries(value).forEach(([key, v]) => {
17542
- values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
17543
- });
17544
- const joinedValues2 = values.join(",");
17545
- switch (style) {
17546
- case "form":
17547
- return `${name}=${joinedValues2}`;
17548
- case "label":
17549
- return `.${joinedValues2}`;
17550
- case "matrix":
17551
- return `;${name}=${joinedValues2}`;
17552
- default:
17553
- return joinedValues2;
17554
- }
17555
- }
17556
- const separator = separatorObjectExplode(style);
17557
- const joinedValues = Object.entries(value).map(
17558
- ([key, v]) => serializePrimitiveParam({
17559
- allowReserved,
17560
- name: style === "deepObject" ? `${name}[${key}]` : key,
17561
- value: v
17562
- })
17563
- ).join(separator);
17564
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
17565
- };
17566
-
17567
- // src/client/core/utils.gen.ts
17568
- function getValidRequestBody(options) {
17569
- const hasBody = options.body !== void 0;
17570
- const isSerializedBody = hasBody && options.bodySerializer;
17571
- if (isSerializedBody) {
17572
- if ("serializedBody" in options) {
17573
- const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
17574
- return hasSerializedBody ? options.serializedBody : null;
17575
- }
17576
- return options.body !== "" ? options.body : null;
17577
- }
17578
- if (hasBody) {
17579
- return options.body;
17580
- }
17581
- return void 0;
17582
- }
17583
-
17584
- // src/client/core/auth.gen.ts
17585
- var getAuthToken = async (auth, callback) => {
17586
- const token = typeof callback === "function" ? await callback(auth) : callback;
17587
- if (!token) {
17588
- return;
17589
- }
17590
- if (auth.scheme === "bearer") {
17591
- return `Bearer ${token}`;
17592
- }
17593
- if (auth.scheme === "basic") {
17594
- return `Basic ${btoa(token)}`;
17595
- }
17596
- return token;
17597
- };
17598
-
17599
- // src/client/client/utils.gen.ts
17600
- var PATH_PARAM_RE = /\{[^{}]+\}/g;
17601
- var defaultPathSerializer = ({ path, url: _url }) => {
17602
- let url = _url;
17603
- const matches = _url.match(PATH_PARAM_RE);
17604
- if (matches) {
17605
- for (const match of matches) {
17606
- let explode = false;
17607
- let name = match.substring(1, match.length - 1);
17608
- let style = "simple";
17609
- if (name.endsWith("*")) {
17610
- explode = true;
17611
- name = name.substring(0, name.length - 1);
17612
- }
17613
- if (name.startsWith(".")) {
17614
- name = name.substring(1);
17615
- style = "label";
17616
- } else if (name.startsWith(";")) {
17617
- name = name.substring(1);
17618
- style = "matrix";
17619
- }
17620
- const value = path[name];
17621
- if (value === void 0 || value === null) {
17622
- continue;
17623
- }
17624
- if (Array.isArray(value)) {
17625
- url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
17626
- continue;
17627
- }
17628
- if (typeof value === "object") {
17629
- url = url.replace(
17630
- match,
17631
- serializeObjectParam({
17632
- explode,
17633
- name,
17634
- style,
17635
- value,
17636
- valueOnly: true
17637
- })
17638
- );
17639
- continue;
17640
- }
17641
- if (style === "matrix") {
17642
- url = url.replace(
17643
- match,
17644
- `;${serializePrimitiveParam({
17645
- name,
17646
- value
17647
- })}`
17648
- );
17649
- continue;
17650
- }
17651
- const replaceValue = encodeURIComponent(
17652
- style === "label" ? `.${value}` : value
17653
- );
17654
- url = url.replace(match, replaceValue);
17655
- }
17656
- }
17657
- return url;
17658
- };
17659
- var createQuerySerializer = ({
17660
- parameters = {},
17661
- ...args
17662
- } = {}) => {
17663
- const querySerializer = (queryParams) => {
17664
- const search = [];
17665
- if (queryParams && typeof queryParams === "object") {
17666
- for (const name in queryParams) {
17667
- const value = queryParams[name];
17668
- if (value === void 0 || value === null) {
17669
- continue;
17670
- }
17671
- const options = parameters[name] || args;
17672
- if (Array.isArray(value)) {
17673
- const serializedArray = serializeArrayParam({
17674
- allowReserved: options.allowReserved,
17675
- explode: true,
17676
- name,
17677
- style: "form",
17678
- value,
17679
- ...options.array
17680
- });
17681
- if (serializedArray) search.push(serializedArray);
17682
- } else if (typeof value === "object") {
17683
- const serializedObject = serializeObjectParam({
17684
- allowReserved: options.allowReserved,
17685
- explode: true,
17686
- name,
17687
- style: "deepObject",
17688
- value,
17689
- ...options.object
17690
- });
17691
- if (serializedObject) search.push(serializedObject);
17692
- } else {
17693
- const serializedPrimitive = serializePrimitiveParam({
17694
- allowReserved: options.allowReserved,
17695
- name,
17696
- value
17697
- });
17698
- if (serializedPrimitive) search.push(serializedPrimitive);
17699
- }
17700
- }
17701
- }
17702
- return search.join("&");
17703
- };
17704
- return querySerializer;
17705
- };
17706
- var getParseAs = (contentType) => {
17707
- if (!contentType) {
17708
- return "stream";
17709
- }
17710
- const cleanContent = contentType.split(";")[0]?.trim();
17711
- if (!cleanContent) {
17712
- return;
17713
- }
17714
- if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
17715
- return "json";
17716
- }
17717
- if (cleanContent === "multipart/form-data") {
17718
- return "formData";
17719
- }
17720
- if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
17721
- return "blob";
17722
- }
17723
- if (cleanContent.startsWith("text/")) {
17724
- return "text";
17725
- }
17726
- return;
17727
- };
17728
- var checkForExistence = (options, name) => {
17729
- if (!name) {
17730
- return false;
17731
- }
17732
- if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
17733
- return true;
17734
- }
17735
- return false;
17736
- };
17737
- async function setAuthParams(options) {
17738
- for (const auth of options.security ?? []) {
17739
- if (checkForExistence(options, auth.name)) {
17740
- continue;
17741
- }
17742
- const token = await getAuthToken(auth, options.auth);
17743
- if (!token) {
17744
- continue;
17745
- }
17746
- const name = auth.name ?? "Authorization";
17747
- switch (auth.in) {
17748
- case "query":
17749
- if (!options.query) {
17750
- options.query = {};
17751
- }
17752
- options.query[name] = token;
17753
- break;
17754
- case "cookie":
17755
- options.headers.append("Cookie", `${name}=${token}`);
17756
- break;
17757
- case "header":
17758
- default:
17759
- options.headers.set(name, token);
17760
- break;
17761
- }
17762
- }
17763
- }
17764
- var buildUrl = (options) => {
17765
- const url = getUrl({
17766
- baseUrl: options.baseUrl,
17767
- path: options.path,
17768
- query: options.query,
17769
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
17770
- url: options.url
17771
- });
17772
- return url;
17773
- };
17774
- var getUrl = ({
17775
- baseUrl,
17776
- path,
17777
- query,
17778
- querySerializer,
17779
- url: _url
17780
- }) => {
17781
- const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
17782
- let url = (baseUrl ?? "") + pathUrl;
17783
- if (path) {
17784
- url = defaultPathSerializer({ path, url });
17785
- }
17786
- let search = query ? querySerializer(query) : "";
17787
- if (search.startsWith("?")) {
17788
- search = search.substring(1);
17789
- }
17790
- if (search) {
17791
- url += `?${search}`;
17792
- }
17793
- return url;
17794
- };
17795
- var mergeConfigs = (a, b) => {
17796
- const config = { ...a, ...b };
17797
- if (config.baseUrl?.endsWith("/")) {
17798
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
17799
- }
17800
- config.headers = mergeHeaders(a.headers, b.headers);
17801
- return config;
17802
- };
17803
- var headersEntries = (headers) => {
17804
- const entries = [];
17805
- headers.forEach((value, key) => {
17806
- entries.push([key, value]);
17807
- });
17808
- return entries;
17809
- };
17810
- var mergeHeaders = (...headers) => {
17811
- const mergedHeaders = new Headers();
17812
- for (const header of headers) {
17813
- if (!header || typeof header !== "object") {
17814
- continue;
17815
- }
17816
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
17817
- for (const [key, value] of iterator) {
17818
- if (value === null) {
17819
- mergedHeaders.delete(key);
17820
- } else if (Array.isArray(value)) {
17821
- for (const v of value) {
17822
- mergedHeaders.append(key, v);
17823
- }
17824
- } else if (value !== void 0) {
17825
- mergedHeaders.set(
17826
- key,
17827
- typeof value === "object" ? JSON.stringify(value) : value
17828
- );
17829
- }
17830
- }
17831
- }
17832
- return mergedHeaders;
17833
- };
17834
- var Interceptors = class {
17835
- constructor() {
17836
- this.fns = [];
17837
- }
17838
- clear() {
17839
- this.fns = [];
17840
- }
17841
- eject(id) {
17842
- const index = this.getInterceptorIndex(id);
17843
- if (this.fns[index]) {
17844
- this.fns[index] = null;
17845
- }
17846
- }
17847
- exists(id) {
17848
- const index = this.getInterceptorIndex(id);
17849
- return Boolean(this.fns[index]);
17850
- }
17851
- getInterceptorIndex(id) {
17852
- if (typeof id === "number") {
17853
- return this.fns[id] ? id : -1;
17854
- }
17855
- return this.fns.indexOf(id);
17856
- }
17857
- update(id, fn) {
17858
- const index = this.getInterceptorIndex(id);
17859
- if (this.fns[index]) {
17860
- this.fns[index] = fn;
17861
- return id;
17862
- }
17863
- return false;
17864
- }
17865
- use(fn) {
17866
- this.fns.push(fn);
17867
- return this.fns.length - 1;
17868
- }
17869
- };
17870
- var createInterceptors = () => ({
17871
- error: new Interceptors(),
17872
- request: new Interceptors(),
17873
- response: new Interceptors()
17874
- });
17875
- var defaultQuerySerializer = createQuerySerializer({
17876
- allowReserved: false,
17877
- array: {
17878
- explode: true,
17879
- style: "form"
17880
- },
17881
- object: {
17882
- explode: true,
17883
- style: "deepObject"
17884
- }
17885
- });
17886
- var defaultHeaders = {
17887
- "Content-Type": "application/json"
17888
- };
17889
- var createConfig = (override = {}) => ({
17890
- ...jsonBodySerializer,
17891
- headers: defaultHeaders,
17892
- parseAs: "auto",
17893
- querySerializer: defaultQuerySerializer,
17894
- ...override
17895
- });
17896
-
17897
- // src/client/client/client.gen.ts
17898
- var createClient = (config = {}) => {
17899
- let _config = mergeConfigs(createConfig(), config);
17900
- const getConfig = () => ({ ..._config });
17901
- const setConfig = (config2) => {
17902
- _config = mergeConfigs(_config, config2);
17903
- return getConfig();
17904
- };
17905
- const interceptors = createInterceptors();
17906
- const beforeRequest = async (options) => {
17907
- const opts = {
17908
- ..._config,
17909
- ...options,
17910
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
17911
- headers: mergeHeaders(_config.headers, options.headers),
17912
- serializedBody: void 0
17913
- };
17914
- if (opts.security) {
17915
- await setAuthParams(opts);
17916
- }
17917
- if (opts.requestValidator) {
17918
- await opts.requestValidator(opts);
17919
- }
17920
- if (opts.body !== void 0 && opts.bodySerializer) {
17921
- opts.serializedBody = opts.bodySerializer(opts.body);
17922
- }
17923
- if (opts.body === void 0 || opts.serializedBody === "") {
17924
- opts.headers.delete("Content-Type");
17925
- }
17926
- const resolvedOpts = opts;
17927
- const url = buildUrl(resolvedOpts);
17928
- return { opts: resolvedOpts, url };
17929
- };
17930
- const request = async (options) => {
17931
- const throwOnError = options.throwOnError ?? _config.throwOnError;
17932
- let response;
17933
- try {
17934
- const { opts, url } = await beforeRequest(options);
17935
- for (const fn of interceptors.request.fns) {
17936
- if (fn) {
17937
- await fn(opts);
17938
- }
17939
- }
17940
- const _fetch = opts.fetch;
17941
- const requestInit = {
17942
- ...opts,
17943
- body: getValidRequestBody(opts)
17944
- };
17945
- response = await _fetch(url, requestInit);
17946
- for (const fn of interceptors.response.fns) {
17947
- if (fn) {
17948
- response = await fn(response, opts);
17949
- }
17950
- }
17951
- const result = {
17952
- response
17953
- };
17954
- if (response.ok) {
17955
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
17956
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
17957
- let emptyData;
17958
- switch (parseAs) {
17959
- case "arrayBuffer":
17960
- case "blob":
17961
- case "text":
17962
- emptyData = await response[parseAs]();
17963
- break;
17964
- case "formData":
17965
- emptyData = new FormData();
17966
- break;
17967
- case "stream":
17968
- emptyData = response.body;
17969
- break;
17970
- case "json":
17971
- default:
17972
- emptyData = {};
17973
- break;
17974
- }
17975
- return {
17976
- data: emptyData,
17977
- ...result
17978
- };
17979
- }
17980
- let data;
17981
- switch (parseAs) {
17982
- case "arrayBuffer":
17983
- case "blob":
17984
- case "formData":
17985
- case "text":
17986
- data = await response[parseAs]();
17987
- break;
17988
- case "json": {
17989
- const text12 = await response.text();
17990
- data = text12 ? JSON.parse(text12) : {};
17991
- break;
17992
- }
17993
- case "stream":
17994
- return {
17995
- data: response.body,
17996
- ...result
17997
- };
17998
- }
17999
- if (parseAs === "json") {
18000
- if (opts.responseValidator) {
18001
- await opts.responseValidator(data);
18002
- }
18003
- if (opts.responseTransformer) {
18004
- data = await opts.responseTransformer(data);
18005
- }
18006
- }
18007
- return {
18008
- data,
18009
- ...result
18010
- };
18011
- }
18012
- const textError = await response.text();
18013
- let jsonError;
18014
- try {
18015
- jsonError = JSON.parse(textError);
18016
- } catch {
18017
- }
18018
- throw jsonError ?? textError;
18019
- } catch (error) {
18020
- let finalError = error;
18021
- for (const fn of interceptors.error.fns) {
18022
- if (fn) {
18023
- finalError = await fn(finalError, response, options);
18024
- }
18025
- }
18026
- finalError = finalError || {};
18027
- if (throwOnError) {
18028
- throw finalError;
18029
- }
18030
- return {
18031
- error: finalError,
18032
- response
18033
- };
18034
- }
18035
- };
18036
- const makeMethodFn = (method) => (options) => request({ ...options, method });
18037
- const makeSseFn = (method) => async (options) => {
18038
- const { opts, url } = await beforeRequest(options);
18039
- return createSseClient({
18040
- ...opts,
18041
- body: opts.body,
18042
- method,
18043
- onRequest: async (url2, init) => {
18044
- let request2 = new Request(url2, init);
18045
- const requestInit = { ...init, url: url2 };
18046
- for (const fn of interceptors.request.fns) {
18047
- if (fn) {
18048
- await fn(requestInit);
18049
- request2 = new Request(requestInit.url, requestInit);
18050
- }
18051
- }
18052
- return request2;
18053
- },
18054
- serializedBody: getValidRequestBody(opts),
18055
- url
18056
- });
18057
- };
18058
- const _buildUrl = (options) => buildUrl({ ..._config, ...options });
18059
- return {
18060
- buildUrl: _buildUrl,
18061
- connect: makeMethodFn("CONNECT"),
18062
- delete: makeMethodFn("DELETE"),
18063
- get: makeMethodFn("GET"),
18064
- getConfig,
18065
- head: makeMethodFn("HEAD"),
18066
- interceptors,
18067
- options: makeMethodFn("OPTIONS"),
18068
- patch: makeMethodFn("PATCH"),
18069
- post: makeMethodFn("POST"),
18070
- put: makeMethodFn("PUT"),
18071
- request,
18072
- setConfig,
18073
- sse: {
18074
- connect: makeSseFn("CONNECT"),
18075
- delete: makeSseFn("DELETE"),
18076
- get: makeSseFn("GET"),
18077
- head: makeSseFn("HEAD"),
18078
- options: makeSseFn("OPTIONS"),
18079
- patch: makeSseFn("PATCH"),
18080
- post: makeSseFn("POST"),
18081
- put: makeSseFn("PUT"),
18082
- trace: makeSseFn("TRACE")
18083
- },
18084
- trace: makeMethodFn("TRACE")
18085
- };
18086
- };
18087
-
18088
- // src/client/client.gen.ts
18089
- var client = createClient(createClientConfig(createConfig()));
18090
-
18091
- // src/client/sdk.gen.ts
18092
- var getApiV1Config = (options) => (options?.client ?? client).get({ url: "/api/v1/config", ...options });
18093
- var getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
18094
- var getApiV1CreditsPacks = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/packs", ...options });
18095
- var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
18096
- url: "/api/v1/credits/purchase",
18097
- ...options,
18098
- headers: {
18099
- "Content-Type": "application/json",
18100
- ...options.headers
18101
- }
18102
- });
18103
- var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
18104
- var postApiV1PhoneCalls = (options) => (options.client ?? client).post({
18105
- url: "/api/v1/phone-calls",
18106
- ...options,
18107
- headers: {
18108
- "Content-Type": "application/json",
18109
- ...options.headers
18110
- }
18111
- });
18112
- var getApiV1PhoneCallsByCallId = (options) => (options.client ?? client).get({ url: "/api/v1/phone-calls/{call_id}", ...options });
18113
- var postApiV1SubscriptionsCancel = (options) => (options?.client ?? client).post({
18114
- url: "/api/v1/subscriptions/cancel",
18115
- ...options,
18116
- headers: {
18117
- "Content-Type": "application/json",
18118
- ...options?.headers
18119
- }
18120
- });
18121
- var postApiV1SubscriptionsCreateCheckoutSession = (options) => (options.client ?? client).post({
18122
- url: "/api/v1/subscriptions/create-checkout-session",
18123
- ...options,
18124
- headers: {
18125
- "Content-Type": "application/json",
18126
- ...options.headers
18127
- }
18128
- });
18129
- var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? client).post({
18130
- url: "/api/v1/subscriptions/customer-portal",
18131
- ...options,
18132
- headers: {
18133
- "Content-Type": "application/json",
18134
- ...options.headers
18135
- }
18136
- });
18137
- var postApiV1SubscriptionsRenew = (options) => (options?.client ?? client).post({ url: "/api/v1/subscriptions/renew", ...options });
18138
- var getApiV1SubscriptionsStatus = (options) => (options?.client ?? client).get({ url: "/api/v1/subscriptions/status", ...options });
18139
- var getApiV1WalletsBinding = (options) => (options?.client ?? client).get({ url: "/api/v1/wallets/binding", ...options });
18140
- var postApiV1WalletsBinding = (options) => (options.client ?? client).post({
18141
- url: "/api/v1/wallets/binding",
18142
- ...options,
18143
- headers: {
18144
- "Content-Type": "application/json",
18145
- ...options.headers
18146
- }
18147
- });
18148
- var postApiV1WalletsBindingNonce = (options) => (options?.client ?? client).post({ url: "/api/v1/wallets/binding/nonce", ...options });
18149
- var deleteApiV1WalletsBindingByAddress = (options) => (options.client ?? client).delete({ url: "/api/v1/wallets/binding/{address}", ...options });
18150
- var postAuthOauthByProviderExchange = (options) => (options.client ?? client).post({
18151
- url: "/auth/oauth/{provider}/exchange",
18152
- ...options,
18153
- headers: {
18154
- "Content-Type": "application/json",
18155
- ...options.headers
18156
- }
18157
- });
18158
- var postAuthOauthByProviderRefresh = (options) => (options.client ?? client).post({
18159
- url: "/auth/oauth/{provider}/refresh",
18160
- ...options,
18161
- headers: {
18162
- "Content-Type": "application/json",
18163
- ...options.headers
18164
- }
18165
- });
18166
- var postAuthOauthByProviderRevoke = (options) => (options.client ?? client).post({
18167
- url: "/auth/oauth/{provider}/revoke",
18168
- ...options,
18169
- headers: {
18170
- "Content-Type": "application/json",
18171
- ...options.headers
18172
- }
18173
- });
18174
-
18175
- // src/react/useCredits.ts
18176
17317
  function useCredits(options = {}) {
18177
17318
  const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
18178
17319
  const [balance, setBalance] = useState11(null);