@anuma/sdk 9.1.5 → 9.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -511,7 +511,7 @@ var mergeHeaders = (...headers) => {
511
511
  if (!header || typeof header !== "object") {
512
512
  continue;
513
513
  }
514
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
514
+ const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
515
515
  for (const [key, value] of iterator) {
516
516
  if (value === null) {
517
517
  mergedHeaders.delete(key);
@@ -786,6 +786,18 @@ var createClient = (config = {}) => {
786
786
  // src/client/client.gen.ts
787
787
  var client = createClient(createClientConfig(createConfig()));
788
788
 
789
+ // src/clientHeaders.ts
790
+ function normalizeHeaders(headers) {
791
+ if (headers instanceof Headers || Array.isArray(headers)) {
792
+ const normalized = /* @__PURE__ */ Object.create(null);
793
+ new Headers(headers).forEach((value, name) => {
794
+ normalized[name] = value;
795
+ });
796
+ return normalized;
797
+ }
798
+ return headers;
799
+ }
800
+
789
801
  // src/client/sdk.gen.ts
790
802
  var deleteApiV1Account = (options) => (options?.client ?? client).delete({ url: "/api/v1/account", ...options });
791
803
  var postApiV1AdminAddCredits = (options) => (options.client ?? client).post({
@@ -793,7 +805,7 @@ var postApiV1AdminAddCredits = (options) => (options.client ?? client).post({
793
805
  ...options,
794
806
  headers: {
795
807
  "Content-Type": "application/json",
796
- ...options.headers
808
+ ...normalizeHeaders(options.headers)
797
809
  }
798
810
  });
799
811
  var postApiV1AdminAgents = (options) => (options.client ?? client).post({
@@ -801,7 +813,7 @@ var postApiV1AdminAgents = (options) => (options.client ?? client).post({
801
813
  ...options,
802
814
  headers: {
803
815
  "Content-Type": "application/json",
804
- ...options.headers
816
+ ...normalizeHeaders(options.headers)
805
817
  }
806
818
  });
807
819
  var deleteApiV1AdminAgentsById = (options) => (options.client ?? client).delete({ url: "/api/v1/admin/agents/{id}", ...options });
@@ -810,7 +822,7 @@ var putApiV1AdminAgentsById = (options) => (options.client ?? client).put({
810
822
  ...options,
811
823
  headers: {
812
824
  "Content-Type": "application/json",
813
- ...options.headers
825
+ ...normalizeHeaders(options.headers)
814
826
  }
815
827
  });
816
828
  var getApiV1AdminApps = (options) => (options.client ?? client).get({ url: "/api/v1/admin/apps", ...options });
@@ -819,7 +831,7 @@ var postApiV1AdminApps = (options) => (options.client ?? client).post({
819
831
  ...options,
820
832
  headers: {
821
833
  "Content-Type": "application/json",
822
- ...options.headers
834
+ ...normalizeHeaders(options.headers)
823
835
  }
824
836
  });
825
837
  var getApiV1AdminAppsByAppIdApiKeys = (options) => (options.client ?? client).get({ url: "/api/v1/admin/apps/{app_id}/api-keys", ...options });
@@ -828,7 +840,7 @@ var postApiV1AdminAppsByAppIdApiKeys = (options) => (options.client ?? client).p
828
840
  ...options,
829
841
  headers: {
830
842
  "Content-Type": "application/json",
831
- ...options.headers
843
+ ...normalizeHeaders(options.headers)
832
844
  }
833
845
  });
834
846
  var deleteApiV1AdminAppsByAppIdApiKeysById = (options) => (options.client ?? client).delete({ url: "/api/v1/admin/apps/{app_id}/api-keys/{id}", ...options });
@@ -838,7 +850,7 @@ var putApiV1AdminAppsByAppIdApiKeysById = (options) => (options.client ?? client
838
850
  ...options,
839
851
  headers: {
840
852
  "Content-Type": "application/json",
841
- ...options.headers
853
+ ...normalizeHeaders(options.headers)
842
854
  }
843
855
  });
844
856
  var deleteApiV1AdminAppsById = (options) => (options.client ?? client).delete({ url: "/api/v1/admin/apps/{id}", ...options });
@@ -848,7 +860,7 @@ var putApiV1AdminAppsById = (options) => (options.client ?? client).put({
848
860
  ...options,
849
861
  headers: {
850
862
  "Content-Type": "application/json",
851
- ...options.headers
863
+ ...normalizeHeaders(options.headers)
852
864
  }
853
865
  });
854
866
  var postApiV1AdminPersonas = (options) => (options.client ?? client).post({
@@ -856,7 +868,7 @@ var postApiV1AdminPersonas = (options) => (options.client ?? client).post({
856
868
  ...options,
857
869
  headers: {
858
870
  "Content-Type": "application/json",
859
- ...options.headers
871
+ ...normalizeHeaders(options.headers)
860
872
  }
861
873
  });
862
874
  var deleteApiV1AdminPersonasById = (options) => (options.client ?? client).delete({ url: "/api/v1/admin/personas/{id}", ...options });
@@ -865,7 +877,7 @@ var putApiV1AdminPersonasById = (options) => (options.client ?? client).put({
865
877
  ...options,
866
878
  headers: {
867
879
  "Content-Type": "application/json",
868
- ...options.headers
880
+ ...normalizeHeaders(options.headers)
869
881
  }
870
882
  });
871
883
  var postApiV1AdminSeedApps = (options) => (options.client ?? client).post({
@@ -873,7 +885,7 @@ var postApiV1AdminSeedApps = (options) => (options.client ?? client).post({
873
885
  ...options,
874
886
  headers: {
875
887
  "Content-Type": "application/json",
876
- ...options.headers
888
+ ...normalizeHeaders(options.headers)
877
889
  }
878
890
  });
879
891
  var postApiV1AdminSubscriptionTier = (options) => (options.client ?? client).post({
@@ -881,7 +893,7 @@ var postApiV1AdminSubscriptionTier = (options) => (options.client ?? client).pos
881
893
  ...options,
882
894
  headers: {
883
895
  "Content-Type": "application/json",
884
- ...options.headers
896
+ ...normalizeHeaders(options.headers)
885
897
  }
886
898
  });
887
899
  var deleteApiV1AdminTextReset = (options) => (options.client ?? client).delete({ url: "/api/v1/admin/text/reset", ...options });
@@ -894,7 +906,7 @@ var putApiV1AgentsByIdPreference = (options) => (options.client ?? client).put({
894
906
  ...options,
895
907
  headers: {
896
908
  "Content-Type": "application/json",
897
- ...options.headers
909
+ ...normalizeHeaders(options.headers)
898
910
  }
899
911
  });
900
912
  var postApiV1ChatCompletions = (options) => (options.client ?? client).post({
@@ -902,7 +914,7 @@ var postApiV1ChatCompletions = (options) => (options.client ?? client).post({
902
914
  ...options,
903
915
  headers: {
904
916
  "Content-Type": "application/json",
905
- ...options.headers
917
+ ...normalizeHeaders(options.headers)
906
918
  }
907
919
  });
908
920
  var getApiV1Config = (options) => (options?.client ?? client).get({ url: "/api/v1/config", ...options });
@@ -913,7 +925,7 @@ var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
913
925
  ...options,
914
926
  headers: {
915
927
  "Content-Type": "application/json",
916
- ...options.headers
928
+ ...normalizeHeaders(options.headers)
917
929
  }
918
930
  });
919
931
  var postApiV1CreditsRedeemTokens = (options) => (options.client ?? client).post({
@@ -921,7 +933,7 @@ var postApiV1CreditsRedeemTokens = (options) => (options.client ?? client).post(
921
933
  ...options,
922
934
  headers: {
923
935
  "Content-Type": "application/json",
924
- ...options.headers
936
+ ...normalizeHeaders(options.headers)
925
937
  }
926
938
  });
927
939
  var getApiV1DeveloperApps = (options) => (options?.client ?? client).get({ url: "/api/v1/developer/apps", ...options });
@@ -930,7 +942,7 @@ var postApiV1DeveloperApps = (options) => (options.client ?? client).post({
930
942
  ...options,
931
943
  headers: {
932
944
  "Content-Type": "application/json",
933
- ...options.headers
945
+ ...normalizeHeaders(options.headers)
934
946
  }
935
947
  });
936
948
  var deleteApiV1DeveloperAppsByAppUuid = (options) => (options.client ?? client).delete({ url: "/api/v1/developer/apps/{app_uuid}", ...options });
@@ -940,7 +952,7 @@ var patchApiV1DeveloperAppsByAppUuid = (options) => (options.client ?? client).p
940
952
  ...options,
941
953
  headers: {
942
954
  "Content-Type": "application/json",
943
- ...options.headers
955
+ ...normalizeHeaders(options.headers)
944
956
  }
945
957
  });
946
958
  var getApiV1DeveloperAppsByAppUuidApiKeys = (options) => (options.client ?? client).get({ url: "/api/v1/developer/apps/{app_uuid}/api-keys", ...options });
@@ -949,7 +961,7 @@ var postApiV1DeveloperAppsByAppUuidApiKeys = (options) => (options.client ?? cli
949
961
  ...options,
950
962
  headers: {
951
963
  "Content-Type": "application/json",
952
- ...options.headers
964
+ ...normalizeHeaders(options.headers)
953
965
  }
954
966
  });
955
967
  var deleteApiV1DeveloperAppsByAppUuidApiKeysByKeyId = (options) => (options.client ?? client).delete({ url: "/api/v1/developer/apps/{app_uuid}/api-keys/{key_id}", ...options });
@@ -958,7 +970,7 @@ var postApiV1DeveloperAppsByAppUuidFund = (options) => (options.client ?? client
958
970
  ...options,
959
971
  headers: {
960
972
  "Content-Type": "application/json",
961
- ...options.headers
973
+ ...normalizeHeaders(options.headers)
962
974
  }
963
975
  });
964
976
  var deleteApiV1DeveloperAppsByAppUuidPrivy = (options) => (options.client ?? client).delete({ url: "/api/v1/developer/apps/{app_uuid}/privy", ...options });
@@ -967,7 +979,7 @@ var postApiV1DeveloperAppsByAppUuidPrivy = (options) => (options.client ?? clien
967
979
  ...options,
968
980
  headers: {
969
981
  "Content-Type": "application/json",
970
- ...options.headers
982
+ ...normalizeHeaders(options.headers)
971
983
  }
972
984
  });
973
985
  var getApiV1DeveloperAppsByAppUuidUsage = (options) => (options.client ?? client).get({ url: "/api/v1/developer/apps/{app_uuid}/usage", ...options });
@@ -979,7 +991,7 @@ var patchApiV1DeveloperAppsByAppUuidUsersByAddress = (options) => (options.clien
979
991
  ...options,
980
992
  headers: {
981
993
  "Content-Type": "application/json",
982
- ...options.headers
994
+ ...normalizeHeaders(options.headers)
983
995
  }
984
996
  });
985
997
  var postApiV1DeveloperAppsByAppUuidUsersByAddressTopUp = (options) => (options.client ?? client).post({
@@ -987,7 +999,7 @@ var postApiV1DeveloperAppsByAppUuidUsersByAddressTopUp = (options) => (options.c
987
999
  ...options,
988
1000
  headers: {
989
1001
  "Content-Type": "application/json",
990
- ...options.headers
1002
+ ...normalizeHeaders(options.headers)
991
1003
  }
992
1004
  });
993
1005
  var getApiV1DeveloperBilling = (options) => (options?.client ?? client).get({ url: "/api/v1/developer/billing", ...options });
@@ -997,7 +1009,7 @@ var postApiV1Embeddings = (options) => (options.client ?? client).post({
997
1009
  ...options,
998
1010
  headers: {
999
1011
  "Content-Type": "application/json",
1000
- ...options.headers
1012
+ ...normalizeHeaders(options.headers)
1001
1013
  }
1002
1014
  });
1003
1015
  var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
@@ -1008,7 +1020,7 @@ var postApiV1PhoneCalls = (options) => (options.client ?? client).post({
1008
1020
  ...options,
1009
1021
  headers: {
1010
1022
  "Content-Type": "application/json",
1011
- ...options.headers
1023
+ ...normalizeHeaders(options.headers)
1012
1024
  }
1013
1025
  });
1014
1026
  var getApiV1PhoneCallsByCallId = (options) => (options.client ?? client).get({ url: "/api/v1/phone-calls/{call_id}", ...options });
@@ -1017,7 +1029,7 @@ var postApiV1Responses = (options) => (options.client ?? client).post({
1017
1029
  ...options,
1018
1030
  headers: {
1019
1031
  "Content-Type": "application/json",
1020
- ...options.headers
1032
+ ...normalizeHeaders(options.headers)
1021
1033
  }
1022
1034
  });
1023
1035
  var postApiV1SubscriptionsCancel = (options) => (options?.client ?? client).post({
@@ -1025,7 +1037,7 @@ var postApiV1SubscriptionsCancel = (options) => (options?.client ?? client).post
1025
1037
  ...options,
1026
1038
  headers: {
1027
1039
  "Content-Type": "application/json",
1028
- ...options?.headers
1040
+ ...normalizeHeaders(options?.headers)
1029
1041
  }
1030
1042
  });
1031
1043
  var postApiV1SubscriptionsCancelScheduledDowngrade = (options) => (options?.client ?? client).post({ url: "/api/v1/subscriptions/cancel-scheduled-downgrade", ...options });
@@ -1034,7 +1046,7 @@ var postApiV1SubscriptionsCreateCheckoutSession = (options) => (options.client ?
1034
1046
  ...options,
1035
1047
  headers: {
1036
1048
  "Content-Type": "application/json",
1037
- ...options.headers
1049
+ ...normalizeHeaders(options.headers)
1038
1050
  }
1039
1051
  });
1040
1052
  var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? client).post({
@@ -1042,7 +1054,7 @@ var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? clien
1042
1054
  ...options,
1043
1055
  headers: {
1044
1056
  "Content-Type": "application/json",
1045
- ...options.headers
1057
+ ...normalizeHeaders(options.headers)
1046
1058
  }
1047
1059
  });
1048
1060
  var getApiV1SubscriptionsPlans = (options) => (options?.client ?? client).get({ url: "/api/v1/subscriptions/plans", ...options });
@@ -1052,7 +1064,7 @@ var postApiV1SubscriptionsScheduleDowngrade = (options) => (options.client ?? cl
1052
1064
  ...options,
1053
1065
  headers: {
1054
1066
  "Content-Type": "application/json",
1055
- ...options.headers
1067
+ ...normalizeHeaders(options.headers)
1056
1068
  }
1057
1069
  });
1058
1070
  var getApiV1SubscriptionsStatus = (options) => (options?.client ?? client).get({ url: "/api/v1/subscriptions/status", ...options });
@@ -1061,7 +1073,7 @@ var postApiV1SubscriptionsUpgrade = (options) => (options.client ?? client).post
1061
1073
  ...options,
1062
1074
  headers: {
1063
1075
  "Content-Type": "application/json",
1064
- ...options.headers
1076
+ ...normalizeHeaders(options.headers)
1065
1077
  }
1066
1078
  });
1067
1079
  var postApiV1SubscriptionsWebhook = (options) => (options.client ?? client).post({
@@ -1069,7 +1081,7 @@ var postApiV1SubscriptionsWebhook = (options) => (options.client ?? client).post
1069
1081
  ...options,
1070
1082
  headers: {
1071
1083
  "Content-Type": "application/json",
1072
- ...options.headers
1084
+ ...normalizeHeaders(options.headers)
1073
1085
  }
1074
1086
  });
1075
1087
  var getApiV1Tools = (options) => (options?.client ?? client).get({ url: "/api/v1/tools", ...options });
@@ -1081,7 +1093,7 @@ var postApiV1UserApiKeys = (options) => (options.client ?? client).post({
1081
1093
  ...options,
1082
1094
  headers: {
1083
1095
  "Content-Type": "application/json",
1084
- ...options.headers
1096
+ ...normalizeHeaders(options.headers)
1085
1097
  }
1086
1098
  });
1087
1099
  var deleteApiV1UserApiKeysByKeyId = (options) => (options.client ?? client).delete({ url: "/api/v1/user/api-keys/{key_id}", ...options });
@@ -1091,7 +1103,7 @@ var postApiV1WalletsBinding = (options) => (options.client ?? client).post({
1091
1103
  ...options,
1092
1104
  headers: {
1093
1105
  "Content-Type": "application/json",
1094
- ...options.headers
1106
+ ...normalizeHeaders(options.headers)
1095
1107
  }
1096
1108
  });
1097
1109
  var postApiV1WalletsBindingNonce = (options) => (options?.client ?? client).post({ url: "/api/v1/wallets/binding/nonce", ...options });
@@ -1101,7 +1113,7 @@ var postApiV1WebhooksRevenuecat = (options) => (options?.client ?? client).post(
1101
1113
  ...options,
1102
1114
  headers: {
1103
1115
  "Content-Type": "application/json",
1104
- ...options?.headers
1116
+ ...normalizeHeaders(options?.headers)
1105
1117
  }
1106
1118
  });
1107
1119
  var getApiV1ZetaCreditRate = (options) => (options?.client ?? client).get({ url: "/api/v1/zeta/credit-rate", ...options });
@@ -723,6 +723,12 @@ function assertTransportMatchesEndpoint(transport, endpoint) {
723
723
  `endpointOverride "${endpoint}" is the other transport's endpoint, but transport is "${transport}". The request body is built for the transport, so this sends the wrong shape and 400s without retry.`
724
724
  );
725
725
  }
726
+ var TIME_BUDGET_EXHAUSTED = {
727
+ kind: "terminal",
728
+ code: "time-budget-exhausted",
729
+ reason: "time budget exhausted"
730
+ };
731
+ var MAX_TIMER_DELAY_MS = 2147483647;
726
732
  var RETRYABLE_HTTP = /* @__PURE__ */ new Set([408, 409, 425, 429]);
727
733
  function isRetryableStatus(status) {
728
734
  return status >= 500 || RETRYABLE_HTTP.has(status);
@@ -778,7 +784,8 @@ async function callPortalJsonCompletion(req) {
778
784
  }
779
785
  const maxAttempts = Math.max(1, req.maxAttempts ?? 3);
780
786
  const startedAt = Date.now();
781
- const overBudget = () => req.totalTimeoutMs !== void 0 && Date.now() - startedAt >= req.totalTimeoutMs;
787
+ const deadlineAt = req.totalTimeoutMs === void 0 ? void 0 : startedAt + req.totalTimeoutMs;
788
+ const overBudget = () => deadlineAt !== void 0 && Date.now() >= deadlineAt;
782
789
  let lastFailure;
783
790
  let reinforce = false;
784
791
  const giveUp = () => {
@@ -791,17 +798,11 @@ async function callPortalJsonCompletion(req) {
791
798
  lastFailure = { reason: "time-budget-exhausted", attempts: attempt - 1 };
792
799
  break;
793
800
  }
794
- const attemptReq = req.totalTimeoutMs !== void 0 ? {
795
- ...req,
796
- timeoutMs: Math.max(
797
- 1,
798
- Math.min(req.timeoutMs ?? 6e4, req.totalTimeoutMs - (Date.now() - startedAt))
799
- ),
800
- ...reinforce && { reinforceJsonContract: true }
801
- } : reinforce ? { ...req, reinforceJsonContract: true } : req;
801
+ const attemptReq = reinforce ? { ...req, reinforceJsonContract: true } : req;
802
802
  const outcome = await attemptPortalJson(
803
803
  { ...attemptReq, transport },
804
- endpoint
804
+ endpoint,
805
+ deadlineAt
805
806
  );
806
807
  if (outcome.kind === "ok") {
807
808
  req.onAttempt?.({ attempt, ok: true });
@@ -841,13 +842,38 @@ async function callPortalJsonCompletion(req) {
841
842
  }
842
843
  return giveUp();
843
844
  }
844
- async function attemptPortalJson(req, endpoint) {
845
+ async function attemptPortalJson(req, endpoint, deadlineAt) {
846
+ const controller = new AbortController();
847
+ if (deadlineAt === void 0 || deadlineAt - Date.now() > MAX_TIMER_DELAY_MS) {
848
+ return requestPortalJson(req, endpoint, controller);
849
+ }
850
+ const remainingMs = deadlineAt - Date.now();
851
+ if (remainingMs <= 0) return TIME_BUDGET_EXHAUSTED;
852
+ let timer;
853
+ try {
854
+ const outcome = await Promise.race([
855
+ new Promise((resolve) => {
856
+ timer = setTimeout(() => {
857
+ resolve(TIME_BUDGET_EXHAUSTED);
858
+ controller.abort();
859
+ }, remainingMs);
860
+ }),
861
+ requestPortalJson(req, endpoint, controller, deadlineAt)
862
+ ]);
863
+ return Date.now() >= deadlineAt ? TIME_BUDGET_EXHAUSTED : outcome;
864
+ } finally {
865
+ clearTimeout(timer);
866
+ }
867
+ }
868
+ async function requestPortalJson(req, endpoint, controller, deadlineAt) {
845
869
  const baseUrl = req.baseUrl ?? defaultBaseUrl();
846
870
  const fetchImpl = req.fetchFn ?? fetch;
847
- const timeoutMs = req.timeoutMs ?? 6e4;
848
871
  const authHeaders = await resolvePortalAuthHeaders(req, req.tag);
872
+ const remainingMs = deadlineAt === void 0 ? Infinity : deadlineAt - Date.now();
873
+ if (controller.signal.aborted || remainingMs <= 0) return TIME_BUDGET_EXHAUSTED;
849
874
  if (authHeaders === null)
850
875
  return { kind: "terminal", code: "auth-unavailable", reason: "auth unavailable (no token)" };
876
+ const timeoutMs = Math.min(req.timeoutMs ?? 6e4, remainingMs);
851
877
  const usesPrefill = req.transport !== "responses" && req.model.startsWith("anthropic/");
852
878
  const prefill = usesPrefill ? "{" : "";
853
879
  const messages = [
@@ -857,7 +883,6 @@ async function attemptPortalJson(req, endpoint) {
857
883
  ];
858
884
  if (prefill) messages.push({ role: "assistant", content: prefill });
859
885
  const supportsJsonObjectFormat = supportsResponseFormat(req.model);
860
- const controller = new AbortController();
861
886
  const timer = setTimeout(() => controller.abort(), timeoutMs);
862
887
  const requestBody = req.transport === "responses" ? {
863
888
  model: req.model,
@@ -4,7 +4,7 @@ import {
4
4
  notifyConsolidationFallback,
5
5
  requiresResponsesTransport,
6
6
  resolvePiiRedactor
7
- } from "./chunk-7QX4J7KV.mjs";
7
+ } from "./chunk-RSA3S6OA.mjs";
8
8
  import "./chunk-GYKJOWEO.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts