@anuma/sdk 3.3.0 → 3.3.1

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.
@@ -99,7 +99,7 @@ import {
99
99
  upsertMessageOp,
100
100
  useEncryption,
101
101
  vaultMemoryToStored
102
- } from "./chunk-NMZMXIUM.mjs";
102
+ } from "./chunk-EIHIZ5L4.mjs";
103
103
  import {
104
104
  PII_PATTERNS,
105
105
  PiiRedactor,
@@ -292,7 +292,7 @@ function createWebSearchPreProcessor(options = {}) {
292
292
  }
293
293
 
294
294
  // src/client/core/serverSentEvents.gen.ts
295
- var createSseClient = ({
295
+ function createSseClient({
296
296
  onRequest,
297
297
  onSseError,
298
298
  onSseEvent,
@@ -304,7 +304,7 @@ var createSseClient = ({
304
304
  sseSleepFn,
305
305
  url,
306
306
  ...options
307
- }) => {
307
+ }) {
308
308
  let lastEventId;
309
309
  const sleep3 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
310
310
  const createStream = async function* () {
@@ -332,10 +332,7 @@ var createSseClient = ({
332
332
  }
333
333
  const _fetch = options.fetch ?? globalThis.fetch;
334
334
  const response = await _fetch(request);
335
- if (!response.ok)
336
- throw new Error(
337
- `SSE failed: ${response.status} ${response.statusText}`
338
- );
335
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
339
336
  if (!response.body) throw new Error("No body in SSE response");
340
337
  const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
341
338
  let buffer = "";
@@ -351,6 +348,7 @@ var createSseClient = ({
351
348
  const { done, value } = await reader.read();
352
349
  if (done) break;
353
350
  buffer += value;
351
+ buffer = buffer.replace(/\r\n?/g, "\n");
354
352
  const chunks = buffer.split("\n\n");
355
353
  buffer = chunks.pop() ?? "";
356
354
  for (const chunk of chunks) {
@@ -365,10 +363,7 @@ var createSseClient = ({
365
363
  } else if (line.startsWith("id:")) {
366
364
  lastEventId = line.replace(/^id:\s*/, "");
367
365
  } else if (line.startsWith("retry:")) {
368
- const parsed = Number.parseInt(
369
- line.replace(/^retry:\s*/, ""),
370
- 10
371
- );
366
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
372
367
  if (!Number.isNaN(parsed)) {
373
368
  retryDelay = parsed;
374
369
  }
@@ -414,17 +409,14 @@ var createSseClient = ({
414
409
  if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
415
410
  break;
416
411
  }
417
- const backoff = Math.min(
418
- retryDelay * 2 ** (attempt - 1),
419
- sseMaxRetryDelay ?? 3e4
420
- );
412
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
421
413
  await sleep3(backoff);
422
414
  }
423
415
  }
424
416
  };
425
417
  const stream = createStream();
426
418
  return { stream };
427
- };
419
+ }
428
420
 
429
421
  // src/lib/chat/runHooks.ts
430
422
  function composeHooks(hooks) {
@@ -3873,10 +3865,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
3873
3865
 
3874
3866
  // src/client/core/bodySerializer.gen.ts
3875
3867
  var jsonBodySerializer = {
3876
- bodySerializer: (body) => JSON.stringify(
3877
- body,
3878
- (_key, value) => typeof value === "bigint" ? value.toString() : value
3879
- )
3868
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
3880
3869
  };
3881
3870
 
3882
3871
  // src/client/core/pathSerializer.gen.ts
@@ -3978,11 +3967,7 @@ var serializeObjectParam = ({
3978
3967
  if (style !== "deepObject" && !explode) {
3979
3968
  let values = [];
3980
3969
  Object.entries(value).forEach(([key, v]) => {
3981
- values = [
3982
- ...values,
3983
- key,
3984
- allowReserved ? v : encodeURIComponent(v)
3985
- ];
3970
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
3986
3971
  });
3987
3972
  const joinedValues2 = values.join(",");
3988
3973
  switch (style) {
@@ -4065,10 +4050,7 @@ var defaultPathSerializer = ({ path, url: _url }) => {
4065
4050
  continue;
4066
4051
  }
4067
4052
  if (Array.isArray(value)) {
4068
- url = url.replace(
4069
- match,
4070
- serializeArrayParam({ explode, name, style, value })
4071
- );
4053
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
4072
4054
  continue;
4073
4055
  }
4074
4056
  if (typeof value === "object") {
@@ -4163,9 +4145,7 @@ var getParseAs = (contentType) => {
4163
4145
  if (cleanContent === "multipart/form-data") {
4164
4146
  return "formData";
4165
4147
  }
4166
- if (["application/", "audio/", "image/", "video/"].some(
4167
- (type) => cleanContent.startsWith(type)
4168
- )) {
4148
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
4169
4149
  return "blob";
4170
4150
  }
4171
4151
  if (cleanContent.startsWith("text/")) {
@@ -4182,11 +4162,8 @@ var checkForExistence = (options, name) => {
4182
4162
  }
4183
4163
  return false;
4184
4164
  };
4185
- var setAuthParams = async ({
4186
- security,
4187
- ...options
4188
- }) => {
4189
- for (const auth of security) {
4165
+ async function setAuthParams(options) {
4166
+ for (const auth of options.security ?? []) {
4190
4167
  if (checkForExistence(options, auth.name)) {
4191
4168
  continue;
4192
4169
  }
@@ -4211,7 +4188,7 @@ var setAuthParams = async ({
4211
4188
  break;
4212
4189
  }
4213
4190
  }
4214
- };
4191
+ }
4215
4192
  var buildUrl = (options) => {
4216
4193
  const url = getUrl({
4217
4194
  baseUrl: options.baseUrl,
@@ -4363,10 +4340,7 @@ var createClient = (config = {}) => {
4363
4340
  serializedBody: void 0
4364
4341
  };
4365
4342
  if (opts.security) {
4366
- await setAuthParams({
4367
- ...opts,
4368
- security: opts.security
4369
- });
4343
+ await setAuthParams(opts);
4370
4344
  }
4371
4345
  if (opts.requestValidator) {
4372
4346
  await opts.requestValidator(opts);
@@ -4377,105 +4351,115 @@ var createClient = (config = {}) => {
4377
4351
  if (opts.body === void 0 || opts.serializedBody === "") {
4378
4352
  opts.headers.delete("Content-Type");
4379
4353
  }
4380
- const url = buildUrl(opts);
4381
- return { opts, url };
4354
+ const resolvedOpts = opts;
4355
+ const url = buildUrl(resolvedOpts);
4356
+ return { opts: resolvedOpts, url };
4382
4357
  };
4383
4358
  const request = async (options) => {
4384
- const { opts, url } = await beforeRequest(options);
4385
- for (const fn of interceptors.request.fns) {
4386
- if (fn) {
4387
- await fn(opts);
4359
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
4360
+ let response;
4361
+ try {
4362
+ const { opts, url } = await beforeRequest(options);
4363
+ for (const fn of interceptors.request.fns) {
4364
+ if (fn) {
4365
+ await fn(opts);
4366
+ }
4388
4367
  }
4389
- }
4390
- const _fetch = opts.fetch;
4391
- const requestInit = {
4392
- ...opts,
4393
- body: getValidRequestBody(opts)
4394
- };
4395
- let response = await _fetch(url, requestInit);
4396
- for (const fn of interceptors.response.fns) {
4397
- if (fn) {
4398
- response = await fn(response, opts);
4368
+ const _fetch = opts.fetch;
4369
+ const requestInit = {
4370
+ ...opts,
4371
+ body: getValidRequestBody(opts)
4372
+ };
4373
+ response = await _fetch(url, requestInit);
4374
+ for (const fn of interceptors.response.fns) {
4375
+ if (fn) {
4376
+ response = await fn(response, opts);
4377
+ }
4399
4378
  }
4400
- }
4401
- const result = {
4402
- response
4403
- };
4404
- if (response.ok) {
4405
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
4406
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
4407
- let emptyData;
4379
+ const result = {
4380
+ response
4381
+ };
4382
+ if (response.ok) {
4383
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
4384
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
4385
+ let emptyData;
4386
+ switch (parseAs) {
4387
+ case "arrayBuffer":
4388
+ case "blob":
4389
+ case "text":
4390
+ emptyData = await response[parseAs]();
4391
+ break;
4392
+ case "formData":
4393
+ emptyData = new FormData();
4394
+ break;
4395
+ case "stream":
4396
+ emptyData = response.body;
4397
+ break;
4398
+ case "json":
4399
+ default:
4400
+ emptyData = {};
4401
+ break;
4402
+ }
4403
+ return {
4404
+ data: emptyData,
4405
+ ...result
4406
+ };
4407
+ }
4408
+ let data;
4408
4409
  switch (parseAs) {
4409
4410
  case "arrayBuffer":
4410
4411
  case "blob":
4412
+ case "formData":
4411
4413
  case "text":
4412
- emptyData = await response[parseAs]();
4414
+ data = await response[parseAs]();
4413
4415
  break;
4414
- case "formData":
4415
- emptyData = new FormData();
4416
+ case "json": {
4417
+ const text12 = await response.text();
4418
+ data = text12 ? JSON.parse(text12) : {};
4416
4419
  break;
4420
+ }
4417
4421
  case "stream":
4418
- emptyData = response.body;
4419
- break;
4420
- case "json":
4421
- default:
4422
- emptyData = {};
4423
- break;
4422
+ return {
4423
+ data: response.body,
4424
+ ...result
4425
+ };
4426
+ }
4427
+ if (parseAs === "json") {
4428
+ if (opts.responseValidator) {
4429
+ await opts.responseValidator(data);
4430
+ }
4431
+ if (opts.responseTransformer) {
4432
+ data = await opts.responseTransformer(data);
4433
+ }
4424
4434
  }
4425
4435
  return {
4426
- data: emptyData,
4436
+ data,
4427
4437
  ...result
4428
4438
  };
4429
4439
  }
4430
- let data;
4431
- switch (parseAs) {
4432
- case "arrayBuffer":
4433
- case "blob":
4434
- case "formData":
4435
- case "json":
4436
- case "text":
4437
- data = await response[parseAs]();
4438
- break;
4439
- case "stream":
4440
- return {
4441
- data: response.body,
4442
- ...result
4443
- };
4440
+ const textError = await response.text();
4441
+ let jsonError;
4442
+ try {
4443
+ jsonError = JSON.parse(textError);
4444
+ } catch {
4444
4445
  }
4445
- if (parseAs === "json") {
4446
- if (opts.responseValidator) {
4447
- await opts.responseValidator(data);
4448
- }
4449
- if (opts.responseTransformer) {
4450
- data = await opts.responseTransformer(data);
4446
+ throw jsonError ?? textError;
4447
+ } catch (error) {
4448
+ let finalError = error;
4449
+ for (const fn of interceptors.error.fns) {
4450
+ if (fn) {
4451
+ finalError = await fn(finalError, response, options);
4451
4452
  }
4452
4453
  }
4454
+ finalError = finalError || {};
4455
+ if (throwOnError) {
4456
+ throw finalError;
4457
+ }
4453
4458
  return {
4454
- data,
4455
- ...result
4459
+ error: finalError,
4460
+ response
4456
4461
  };
4457
4462
  }
4458
- const textError = await response.text();
4459
- let jsonError;
4460
- try {
4461
- jsonError = JSON.parse(textError);
4462
- } catch {
4463
- }
4464
- const error = jsonError ?? textError;
4465
- let finalError = error;
4466
- for (const fn of interceptors.error.fns) {
4467
- if (fn) {
4468
- finalError = await fn(error, response, opts);
4469
- }
4470
- }
4471
- finalError = finalError || {};
4472
- if (opts.throwOnError) {
4473
- throw finalError;
4474
- }
4475
- return {
4476
- error: finalError,
4477
- ...result
4478
- };
4479
4463
  };
4480
4464
  const makeMethodFn = (method) => (options) => request({ ...options, method });
4481
4465
  const makeSseFn = (method) => async (options) => {
@@ -4483,15 +4467,10 @@ var createClient = (config = {}) => {
4483
4467
  return createSseClient({
4484
4468
  ...opts,
4485
4469
  body: opts.body,
4486
- headers: opts.headers,
4487
4470
  method,
4488
4471
  onRequest: async (url2, init) => {
4489
4472
  let request2 = new Request(url2, init);
4490
- const requestInit = {
4491
- ...init,
4492
- method: init.method,
4493
- url: url2
4494
- };
4473
+ const requestInit = { ...init, url: url2 };
4495
4474
  for (const fn of interceptors.request.fns) {
4496
4475
  if (fn) {
4497
4476
  await fn(requestInit);
@@ -4500,11 +4479,13 @@ var createClient = (config = {}) => {
4500
4479
  }
4501
4480
  return request2;
4502
4481
  },
4482
+ serializedBody: getValidRequestBody(opts),
4503
4483
  url
4504
4484
  });
4505
4485
  };
4486
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
4506
4487
  return {
4507
- buildUrl,
4488
+ buildUrl: _buildUrl,
4508
4489
  connect: makeMethodFn("CONNECT"),
4509
4490
  delete: makeMethodFn("DELETE"),
4510
4491
  get: makeMethodFn("GET"),
@@ -4536,34 +4517,17 @@ var createClient = (config = {}) => {
4536
4517
  var client = createClient(createClientConfig(createConfig()));
4537
4518
 
4538
4519
  // src/client/sdk.gen.ts
4539
- var getApiV1CreditsBalance = (options) => {
4540
- return (options?.client ?? client).get({
4541
- url: "/api/v1/credits/balance",
4542
- ...options
4543
- });
4544
- };
4545
- var getApiV1CreditsPacks = (options) => {
4546
- return (options?.client ?? client).get({
4547
- url: "/api/v1/credits/packs",
4548
- ...options
4549
- });
4550
- };
4551
- var postApiV1CreditsPurchase = (options) => {
4552
- return (options.client ?? client).post({
4553
- url: "/api/v1/credits/purchase",
4554
- ...options,
4555
- headers: {
4556
- "Content-Type": "application/json",
4557
- ...options.headers
4558
- }
4559
- });
4560
- };
4561
- var getApiV1Models = (options) => {
4562
- return (options?.client ?? client).get({
4563
- url: "/api/v1/models",
4564
- ...options
4565
- });
4566
- };
4520
+ var getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
4521
+ var getApiV1CreditsPacks = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/packs", ...options });
4522
+ var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
4523
+ url: "/api/v1/credits/purchase",
4524
+ ...options,
4525
+ headers: {
4526
+ "Content-Type": "application/json",
4527
+ ...options.headers
4528
+ }
4529
+ });
4530
+ var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
4567
4531
 
4568
4532
  // src/react/useCredits.ts
4569
4533
  function useCredits(options = {}) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-NMZMXIUM.mjs";
3
+ } from "./chunk-EIHIZ5L4.mjs";
4
4
  import "./chunk-DFVCS3QQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {