@narumitw/pi-usage 0.63.1 → 0.64.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.
@@ -435,6 +435,190 @@ function clampPercent(value) {
435
435
  return Math.min(100, Math.max(0, value));
436
436
  }
437
437
 
438
+ // src/providers/command-code.ts
439
+ var FIVE_HOUR_WINDOW_MINUTES = 300;
440
+ var WEEKLY_WINDOW_MINUTES = 10080;
441
+ var IDENTIFIER_PATTERN = /^[A-Za-z0-9._~-]{1,128}$/u;
442
+ var MILLISECOND_EPOCH_FLOOR = 1e12;
443
+ var WINDOWS = [
444
+ { key: "fiveHour", id: "five-hour", label: "Five-hour window", windowMinutes: FIVE_HOUR_WINDOW_MINUTES },
445
+ { key: "weekly", id: "weekly", label: "Weekly window", windowMinutes: WEEKLY_WINDOW_MINUTES }
446
+ ];
447
+ var PLAN_LABELS = {
448
+ "individual-go": "Go",
449
+ "individual-goat": "GOAT",
450
+ "individual-pro": "Pro",
451
+ "individual-provider": "Provider",
452
+ "individual-max": "Max",
453
+ "individual-ultra": "Ultra"
454
+ };
455
+ function commandCodeOrgId(account) {
456
+ const id = asObject3(account.org)?.id;
457
+ return typeof id === "string" && IDENTIFIER_PATTERN.test(id) ? id : void 0;
458
+ }
459
+ function normalizeCommandCodeUsagePayload(bundle, capturedAt) {
460
+ const account = asObject3(bundle.account);
461
+ const user = asObject3(account?.user);
462
+ const accountLabel = asString2(user?.userName) ?? asString2(user?.name);
463
+ if (!accountLabel) {
464
+ throw new Error("Command Code account response omitted a safe account name.");
465
+ }
466
+ const creditsPayload = asObject3(bundle.credits);
467
+ const credits = asObject3(creditsPayload?.credits);
468
+ const windowLimits = asObject3(creditsPayload?.windowLimits);
469
+ const subscription = asObject3(asObject3(bundle.subscription)?.data);
470
+ const usage = asObject3(bundle.usage);
471
+ const buckets = [];
472
+ for (const window of WINDOWS) {
473
+ const bucket = parseWindow(windowLimits?.[window.key], window);
474
+ if (bucket) buckets.push(bucket);
475
+ }
476
+ const totalCost = asNonnegativeNumber(usage?.totalCost);
477
+ const remainingCredits = commandCodeRemainingCredits(credits);
478
+ const monthlyReset = asIsoEpochSeconds(subscription?.currentPeriodEnd);
479
+ if (totalCost !== void 0 && remainingCredits !== void 0) {
480
+ const pool = totalCost + remainingCredits;
481
+ if (pool > 0) {
482
+ buckets.push({
483
+ id: "monthly",
484
+ label: "Monthly credits",
485
+ used: totalCost,
486
+ remaining: remainingCredits,
487
+ limit: pool,
488
+ unit: "usd",
489
+ period: "billing-period",
490
+ ...monthlyReset !== void 0 ? { resetsAt: monthlyReset } : {}
491
+ });
492
+ }
493
+ }
494
+ const metrics = [];
495
+ const plan = planLabel(subscription?.planId);
496
+ const planStatus = asString2(subscription?.status, 40);
497
+ if (plan || planStatus) {
498
+ metrics.push({
499
+ id: "plan",
500
+ label: "Plan",
501
+ value: [plan, planStatus ? `(${planStatus})` : void 0].filter(Boolean).join(" ")
502
+ });
503
+ }
504
+ if (buckets.every((bucket) => bucket.id !== "monthly")) {
505
+ if (remainingCredits !== void 0) {
506
+ metrics.push({
507
+ id: "monthly-credits",
508
+ label: "Monthly credits remaining",
509
+ value: remainingCredits,
510
+ unit: "usd"
511
+ });
512
+ } else if (totalCost !== void 0) {
513
+ metrics.push({ id: "period-cost", label: "Cost this billing period", value: totalCost, unit: "usd" });
514
+ }
515
+ }
516
+ const purchased = asNonnegativeNumber(credits?.purchasedCredits);
517
+ if (purchased) {
518
+ metrics.push({ id: "purchased-credits", label: "Purchased credits remaining", value: purchased, unit: "usd" });
519
+ }
520
+ const free = asNonnegativeNumber(credits?.freeCredits);
521
+ if (free) {
522
+ metrics.push({ id: "free-credits", label: "Free credits remaining", value: free, unit: "usd" });
523
+ }
524
+ const totalCount = asNonnegativeNumber(usage?.totalCount);
525
+ if (totalCount !== void 0) {
526
+ metrics.push({ id: "requests", label: "Requests this period", value: totalCount, unit: "count" });
527
+ }
528
+ const totalTokens = asNonnegativeNumber(usage?.totalTokens);
529
+ if (totalTokens !== void 0) {
530
+ metrics.push({ id: "tokens", label: "Tokens this period", value: totalTokens, unit: "count" });
531
+ } else {
532
+ const tokensIn = asNonnegativeNumber(usage?.totalTokensIn);
533
+ const tokensOut = asNonnegativeNumber(usage?.totalTokensOut);
534
+ if (tokensIn !== void 0) {
535
+ metrics.push({ id: "tokens-in", label: "Input tokens", value: tokensIn, unit: "count" });
536
+ }
537
+ if (tokensOut !== void 0) {
538
+ metrics.push({ id: "tokens-out", label: "Output tokens", value: tokensOut, unit: "count" });
539
+ }
540
+ }
541
+ const notes = [];
542
+ if (!creditsPayload) notes.push("Command Code credits were unavailable.");
543
+ else if (windowLimits?.limited === false) {
544
+ notes.push("Rolling 5-hour and weekly limits are not enabled for this plan.");
545
+ }
546
+ if (!subscription) notes.push("Command Code plan details were unavailable.");
547
+ if (!usage) notes.push("Command Code billing-period usage was unavailable.");
548
+ if (buckets.length === 0 && metrics.length === 0) {
549
+ throw new Error("Command Code usage response returned no displayable usage data.");
550
+ }
551
+ return {
552
+ providerId: "command-code",
553
+ providerName: "Command Code",
554
+ capturedAt,
555
+ source: "command-code-alpha-usage",
556
+ semantics: { kind: "consumer-subscription", label: "Command Code plan credits and rolling limits" },
557
+ accountLabel,
558
+ buckets,
559
+ metrics,
560
+ ...notes.length > 0 ? { notes } : {}
561
+ };
562
+ }
563
+ function parseWindow(value, window) {
564
+ const row = asObject3(value);
565
+ if (!row) return void 0;
566
+ const used = asNonnegativeNumber(row.used);
567
+ const cap = asNonnegativeNumber(row.cap);
568
+ if (used === void 0 || cap === void 0 || cap <= 0) return void 0;
569
+ const resetsAt = asMillisecondEpochSeconds(row.resetAt);
570
+ return {
571
+ id: window.id,
572
+ label: window.label,
573
+ used,
574
+ remaining: Math.max(0, cap - used),
575
+ limit: cap,
576
+ unit: "usd",
577
+ windowMinutes: window.windowMinutes,
578
+ ...resetsAt !== void 0 ? { resetsAt } : {}
579
+ };
580
+ }
581
+ function commandCodeRemainingCredits(credits) {
582
+ if (!credits) return void 0;
583
+ const parts = ["monthlyCredits", "purchasedCredits", "freeCredits"].map((key) => asNonnegativeNumber(credits[key])).filter((value) => value !== void 0);
584
+ if (parts.length === 0) return void 0;
585
+ return parts.reduce((total, value) => total + value, 0);
586
+ }
587
+ function planLabel(value) {
588
+ const raw = asString2(value, 40);
589
+ if (!raw) return void 0;
590
+ const known = PLAN_LABELS[raw];
591
+ if (known) return known;
592
+ const words = raw.replace(/^individual[-_]/u, "").replace(/[-_]+/gu, " ").trim();
593
+ return words ? capitalize(words) : raw;
594
+ }
595
+ function asObject3(value) {
596
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
597
+ return value;
598
+ }
599
+ function asString2(value, maxLength = 80) {
600
+ if (typeof value !== "string") return void 0;
601
+ return sanitizeDisplayText(value, maxLength) || void 0;
602
+ }
603
+ function asNonnegativeNumber(value) {
604
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return void 0;
605
+ return value;
606
+ }
607
+ function asIsoEpochSeconds(value) {
608
+ if (typeof value !== "string" || !value.trim()) return void 0;
609
+ const parsed = Date.parse(value);
610
+ if (Number.isNaN(parsed)) return void 0;
611
+ return Math.floor(parsed / 1e3);
612
+ }
613
+ function asMillisecondEpochSeconds(value) {
614
+ const raw = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && /^\d+$/u.test(value.trim()) ? Number(value.trim()) : void 0;
615
+ if (raw === void 0 || raw < 0) return void 0;
616
+ return Math.floor(raw >= MILLISECOND_EPOCH_FLOOR ? raw / 1e3 : raw);
617
+ }
618
+ function capitalize(value) {
619
+ return `${value[0]?.toUpperCase() ?? ""}${value.slice(1)}`;
620
+ }
621
+
438
622
  // src/providers/deepseek.ts
439
623
  var CURRENCIES = ["CNY", "USD"];
440
624
  var BALANCE_FIELDS = [
@@ -451,7 +635,7 @@ function normalizeDeepSeekBalancePayload(payload, capturedAt) {
451
635
  }
452
636
  const balances = /* @__PURE__ */ new Map();
453
637
  for (const raw of payload.balance_infos) {
454
- const balance = asObject3(raw);
638
+ const balance = asObject4(raw);
455
639
  if (!balance) throw new Error("DeepSeek API balance row was not an object.");
456
640
  const currency = deepSeekCurrency(balance.currency);
457
641
  if (!currency) throw new Error("DeepSeek API balance row returned an unsupported currency.");
@@ -495,7 +679,7 @@ function normalizeDeepSeekBalancePayload(payload, capturedAt) {
495
679
  metrics
496
680
  };
497
681
  }
498
- function asObject3(value) {
682
+ function asObject4(value) {
499
683
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
500
684
  return value;
501
685
  }
@@ -534,7 +718,7 @@ function normalizeFireworksAccountsPayload(payload) {
534
718
  }
535
719
  const accounts = [];
536
720
  for (const raw of payload.accounts) {
537
- const account = asObject4(raw);
721
+ const account = asObject5(raw);
538
722
  if (!account) throw new Error("Fireworks accounts response row was not an object.");
539
723
  if (typeof account.name !== "string") {
540
724
  throw new Error("Fireworks accounts response omitted the account resource name.");
@@ -619,7 +803,7 @@ function normalizeFireworksBillingSummaryPayload(payload, accountId, capturedAt)
619
803
  }
620
804
  const totals = /* @__PURE__ */ new Map();
621
805
  for (const raw of payload.lineItems ?? []) {
622
- const lineItem = asObject4(raw);
806
+ const lineItem = asObject5(raw);
623
807
  if (!lineItem) throw new Error("Fireworks billing line item was not an object.");
624
808
  const cost = moneyAmount(lineItem.totalCost, "line item total cost");
625
809
  const series = seriesKey(lineItem.series);
@@ -668,7 +852,7 @@ function normalizeFireworksBillingSummaryPayload(payload, accountId, capturedAt)
668
852
  };
669
853
  }
670
854
  function moneyAmount(value, description) {
671
- const money = asObject4(value);
855
+ const money = asObject5(value);
672
856
  if (!money) throw new Error(`Fireworks billing ${description} was not a money object.`);
673
857
  const currency = typeof money.currencyCode === "string" ? money.currencyCode : void 0;
674
858
  if (!currency || !CURRENCY_PATTERN.test(currency)) {
@@ -740,15 +924,15 @@ function remainingTimeout(timeoutMs, startedAt, description) {
740
924
  if (remaining <= 0) throw new Error(`Timed out while ${description}.`);
741
925
  return remaining;
742
926
  }
743
- function asObject4(value) {
927
+ function asObject5(value) {
744
928
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
745
929
  return value;
746
930
  }
747
931
 
748
932
  // src/providers/github-copilot.ts
749
933
  function normalizeGitHubCopilotUsagePayload(payload, capturedAt) {
750
- const snapshots = asObject5(payload.quota_snapshots);
751
- const premium = asObject5(snapshots?.premium_interactions);
934
+ const snapshots = asObject6(payload.quota_snapshots);
935
+ const premium = asObject6(snapshots?.premium_interactions);
752
936
  const metrics = [];
753
937
  let semanticsLabel;
754
938
  let bucket;
@@ -760,12 +944,12 @@ function normalizeGitHubCopilotUsagePayload(payload, capturedAt) {
760
944
  if (premium.unlimited === true) {
761
945
  bucket = { id, label, unit: "count" };
762
946
  } else {
763
- const entitlement = asNonnegativeNumber(premium.entitlement);
947
+ const entitlement = asNonnegativeNumber2(premium.entitlement);
764
948
  const rawRemaining = asFiniteNumber(premium.remaining) ?? asFiniteNumber(premium.quota_remaining);
765
949
  if (entitlement === void 0 || rawRemaining === void 0) {
766
950
  throw new Error(`GitHub Copilot ${label.toLowerCase()} quota was incomplete.`);
767
951
  }
768
- const overageUsed = Math.max(asNonnegativeNumber(premium.overage_count) ?? 0, Math.max(0, -rawRemaining));
952
+ const overageUsed = Math.max(asNonnegativeNumber2(premium.overage_count) ?? 0, Math.max(0, -rawRemaining));
769
953
  if (overageUsed > 0) {
770
954
  metrics.push({
771
955
  id: "overage-used",
@@ -777,7 +961,7 @@ function normalizeGitHubCopilotUsagePayload(payload, capturedAt) {
777
961
  bucket = {
778
962
  id,
779
963
  label,
780
- used: asNonnegativeNumber(premium.credits_used) ?? Math.max(0, entitlement - rawRemaining),
964
+ used: asNonnegativeNumber2(premium.credits_used) ?? Math.max(0, entitlement - rawRemaining),
781
965
  remaining: Math.max(0, rawRemaining),
782
966
  limit: entitlement,
783
967
  unit: "count",
@@ -786,10 +970,10 @@ function normalizeGitHubCopilotUsagePayload(payload, capturedAt) {
786
970
  };
787
971
  }
788
972
  } else {
789
- const limited = asObject5(payload.limited_user_quotas);
790
- const monthly = asObject5(payload.monthly_quotas);
791
- const remaining = asNonnegativeNumber(limited?.chat);
792
- const entitlement = asNonnegativeNumber(monthly?.chat);
973
+ const limited = asObject6(payload.limited_user_quotas);
974
+ const monthly = asObject6(payload.monthly_quotas);
975
+ const remaining = asNonnegativeNumber2(limited?.chat);
976
+ const entitlement = asNonnegativeNumber2(monthly?.chat);
793
977
  if (remaining === void 0 || entitlement === void 0) {
794
978
  throw new Error("GitHub Copilot usage response contained no supported quota.");
795
979
  }
@@ -806,7 +990,7 @@ function normalizeGitHubCopilotUsagePayload(payload, capturedAt) {
806
990
  };
807
991
  }
808
992
  const notes = [];
809
- const plan = asString2(payload.copilot_plan) ?? asString2(payload.access_type_sku);
993
+ const plan = asString3(payload.copilot_plan) ?? asString3(payload.access_type_sku);
810
994
  if (plan) notes.push(`Plan: ${plan}`);
811
995
  return {
812
996
  providerId: "github-copilot",
@@ -814,23 +998,23 @@ function normalizeGitHubCopilotUsagePayload(payload, capturedAt) {
814
998
  capturedAt,
815
999
  source: "github-copilot-user",
816
1000
  semantics: { kind: "consumer-subscription", label: semanticsLabel },
817
- accountLabel: asString2(payload.login),
1001
+ accountLabel: asString3(payload.login),
818
1002
  buckets: [bucket],
819
1003
  metrics,
820
1004
  ...notes.length > 0 ? { notes } : {}
821
1005
  };
822
1006
  }
823
1007
  function resetTimestamp(payload) {
824
- const raw = asString2(payload.quota_reset_date_utc) ?? asString2(payload.quota_reset_date) ?? asString2(payload.limited_user_reset_date);
1008
+ const raw = asString3(payload.quota_reset_date_utc) ?? asString3(payload.quota_reset_date) ?? asString3(payload.limited_user_reset_date);
825
1009
  if (!raw) return {};
826
1010
  const milliseconds = Date.parse(raw);
827
1011
  return Number.isNaN(milliseconds) ? {} : { resetsAt: Math.floor(milliseconds / 1e3) };
828
1012
  }
829
- function asObject5(value) {
1013
+ function asObject6(value) {
830
1014
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
831
1015
  return value;
832
1016
  }
833
- function asString2(value) {
1017
+ function asString3(value) {
834
1018
  if (typeof value !== "string") return void 0;
835
1019
  return sanitizeDisplayText(value, 80) || void 0;
836
1020
  }
@@ -838,34 +1022,34 @@ function asFiniteNumber(value) {
838
1022
  if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
839
1023
  return value;
840
1024
  }
841
- function asNonnegativeNumber(value) {
1025
+ function asNonnegativeNumber2(value) {
842
1026
  const number = asFiniteNumber(value);
843
1027
  return number === void 0 || number < 0 ? void 0 : number;
844
1028
  }
845
1029
 
846
1030
  // src/providers/kimi-coding.ts
847
- var FIVE_HOUR_WINDOW_MINUTES = 300;
1031
+ var FIVE_HOUR_WINDOW_MINUTES2 = 300;
848
1032
  var DAILY_WINDOW_MINUTES = 1440;
849
- var WEEKLY_WINDOW_MINUTES = 10080;
1033
+ var WEEKLY_WINDOW_MINUTES2 = 10080;
850
1034
  var FIXED_POINT_UNITS_PER_CENT = 1e6;
851
1035
  var RATIO_WINDOWS = [
852
- { key: "limit_5h", id: "five-hour", label: "Five-hour window", windowMinutes: FIVE_HOUR_WINDOW_MINUTES },
853
- { key: "limit_week", id: "weekly", label: "Weekly window", windowMinutes: WEEKLY_WINDOW_MINUTES },
1036
+ { key: "limit_5h", id: "five-hour", label: "Five-hour window", windowMinutes: FIVE_HOUR_WINDOW_MINUTES2 },
1037
+ { key: "limit_week", id: "weekly", label: "Weekly window", windowMinutes: WEEKLY_WINDOW_MINUTES2 },
854
1038
  { key: "limit_month_total", id: "monthly", label: "Monthly window" }
855
1039
  ];
856
1040
  function normalizeKimiCodingUsagePayload(payload, capturedAt) {
857
- const root = asObject6(payload);
1041
+ const root = asObject7(payload);
858
1042
  if (!root) throw new Error("Kimi Coding usage response was not an object.");
859
1043
  const candidates = [];
860
1044
  const explicitWindows = /* @__PURE__ */ new Set();
861
1045
  let omittedWindow = false;
862
- if (root.usage !== void 0) explicitWindows.add(WEEKLY_WINDOW_MINUTES);
863
- const summary = parseUsageRow(root.usage, WEEKLY_WINDOW_MINUTES, "Weekly window");
1046
+ if (root.usage !== void 0) explicitWindows.add(WEEKLY_WINDOW_MINUTES2);
1047
+ const summary = parseUsageRow(root.usage, WEEKLY_WINDOW_MINUTES2, "Weekly window");
864
1048
  if (summary) candidates.push(summary);
865
1049
  else if (root.usage !== void 0) omittedWindow = true;
866
1050
  if (Array.isArray(root.limits)) {
867
1051
  for (const raw of root.limits) {
868
- const item = asObject6(raw);
1052
+ const item = asObject7(raw);
869
1053
  const windowMinutes = parseWindowMinutes(item?.window);
870
1054
  if (windowMinutes !== void 0) explicitWindows.add(windowMinutes);
871
1055
  const label = sanitizedLabel(item?.name);
@@ -886,7 +1070,7 @@ function normalizeKimiCodingUsagePayload(payload, capturedAt) {
886
1070
  if (rows.length === 1) buckets.push(rows[0]);
887
1071
  else omittedWindow = true;
888
1072
  }
889
- const usages = asObject6(root.usages);
1073
+ const usages = asObject7(root.usages);
890
1074
  if (root.usages !== void 0 && !usages) omittedWindow = true;
891
1075
  if (usages) {
892
1076
  for (const window of RATIO_WINDOWS) {
@@ -918,7 +1102,7 @@ function normalizeKimiCodingUsagePayload(payload, capturedAt) {
918
1102
  };
919
1103
  }
920
1104
  function parseUsageRow(value, windowMinutes, label) {
921
- const row = asObject6(value);
1105
+ const row = asObject7(value);
922
1106
  if (!row) return void 0;
923
1107
  const limit = asNonnegativeInteger2(row.limit);
924
1108
  if (limit === void 0 || limit === 0) return void 0;
@@ -929,7 +1113,7 @@ function parseUsageRow(value, windowMinutes, label) {
929
1113
  }
930
1114
  const used = usedRaw ?? (remainingRaw === void 0 ? 0 : Math.max(0, limit - remainingRaw));
931
1115
  const remaining = remainingRaw ?? Math.max(0, limit - used);
932
- const resetsAt = asIsoEpochSeconds(row.resetTime);
1116
+ const resetsAt = asIsoEpochSeconds2(row.resetTime);
933
1117
  return {
934
1118
  id: windowId(windowMinutes),
935
1119
  label,
@@ -942,10 +1126,10 @@ function parseUsageRow(value, windowMinutes, label) {
942
1126
  };
943
1127
  }
944
1128
  function parseRatioWindow(value, id, label) {
945
- const row = asObject6(value);
1129
+ const row = asObject7(value);
946
1130
  const ratio = row?.used_ratio;
947
1131
  if (typeof ratio !== "number" || !Number.isFinite(ratio) || ratio < 0 || ratio > 1) return void 0;
948
- const resetsAt = asIsoEpochSeconds(row?.reset_time);
1132
+ const resetsAt = asIsoEpochSeconds2(row?.reset_time);
949
1133
  const used = ratio * 100;
950
1134
  return {
951
1135
  id,
@@ -957,7 +1141,7 @@ function parseRatioWindow(value, id, label) {
957
1141
  };
958
1142
  }
959
1143
  function parseWindowMinutes(value) {
960
- const window = asObject6(value);
1144
+ const window = asObject7(value);
961
1145
  if (!window) return void 0;
962
1146
  const duration = asPositiveInteger(window.duration);
963
1147
  if (duration === void 0) return void 0;
@@ -967,8 +1151,8 @@ function parseWindowMinutes(value) {
967
1151
  return Number.isSafeInteger(minutes) ? minutes : void 0;
968
1152
  }
969
1153
  function parseBoosterWallet(value) {
970
- const wallet = asObject6(value);
971
- const balance = asObject6(wallet?.balance);
1154
+ const wallet = asObject7(value);
1155
+ const balance = asObject7(wallet?.balance);
972
1156
  if (!wallet || !balance || balance.type !== "BOOSTER") return [];
973
1157
  const totalRaw = asPositiveInteger(balance.amount);
974
1158
  if (totalRaw === void 0) return [];
@@ -1017,7 +1201,7 @@ function parseBoosterWallet(value) {
1017
1201
  return metrics;
1018
1202
  }
1019
1203
  function parseMoney(value) {
1020
- const money = asObject6(value);
1204
+ const money = asObject7(value);
1021
1205
  if (!money) return void 0;
1022
1206
  const cents = asNonnegativeInteger2(money.priceInCents);
1023
1207
  if (cents === void 0) return void 0;
@@ -1031,7 +1215,7 @@ function fixedPointToMajor(value) {
1031
1215
  const major = roundedCents / 100;
1032
1216
  return Number.isSafeInteger(roundedCents) && Number.isFinite(major) ? major : void 0;
1033
1217
  }
1034
- function asObject6(value) {
1218
+ function asObject7(value) {
1035
1219
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1036
1220
  return value;
1037
1221
  }
@@ -1045,7 +1229,7 @@ function asPositiveInteger(value) {
1045
1229
  const number = asNonnegativeInteger2(value);
1046
1230
  return number !== void 0 && number > 0 ? number : void 0;
1047
1231
  }
1048
- function asIsoEpochSeconds(value) {
1232
+ function asIsoEpochSeconds2(value) {
1049
1233
  if (typeof value !== "string") return void 0;
1050
1234
  const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-])(\d{2}):(\d{2}))$/u.exec(value);
1051
1235
  if (!match) return void 0;
@@ -1072,13 +1256,13 @@ function asCurrency(value) {
1072
1256
  return /^[A-Z]{3}$/u.test(currency) ? currency : void 0;
1073
1257
  }
1074
1258
  function windowId(minutes) {
1075
- if (minutes === FIVE_HOUR_WINDOW_MINUTES) return "five-hour";
1259
+ if (minutes === FIVE_HOUR_WINDOW_MINUTES2) return "five-hour";
1076
1260
  if (minutes === DAILY_WINDOW_MINUTES) return "daily";
1077
- if (minutes === WEEKLY_WINDOW_MINUTES) return "weekly";
1261
+ if (minutes === WEEKLY_WINDOW_MINUTES2) return "weekly";
1078
1262
  return `window-${minutes}-minutes`;
1079
1263
  }
1080
1264
  function defaultWindowLabel(minutes) {
1081
- if (minutes === WEEKLY_WINDOW_MINUTES) return "Weekly window";
1265
+ if (minutes === WEEKLY_WINDOW_MINUTES2) return "Weekly window";
1082
1266
  if (minutes % 10080 === 0) return `${minutes / 10080}w window`;
1083
1267
  if (minutes % 1440 === 0) return `${minutes / 1440}d window`;
1084
1268
  if (minutes % 60 === 0) return `${minutes / 60}h window`;
@@ -1127,7 +1311,7 @@ function normalizeTokenPlan(providerId, payload, capturedAt) {
1127
1311
  const buckets = [];
1128
1312
  const groups = /* @__PURE__ */ new Set();
1129
1313
  for (const [index, raw] of payload.model_remains.entries()) {
1130
- const row = asObject7(raw);
1314
+ const row = asObject8(raw);
1131
1315
  if (!row) throw new Error("MiniMax Token Plan quota row was not an object.");
1132
1316
  const groupLabel = safeLabel(row.model_name, `Quota ${index + 1}`);
1133
1317
  const groupId = uniqueGroupId(groupLabel, index, groups);
@@ -1242,7 +1426,7 @@ function resolveQuotaCounts(reportedCount, total, remainingPercent) {
1242
1426
  return { used: total - remaining, remaining, limit: total };
1243
1427
  }
1244
1428
  function assertSuccess(payload) {
1245
- const base = asObject7(payload.base_resp);
1429
+ const base = asObject8(payload.base_resp);
1246
1430
  if (base?.status_code !== 0) {
1247
1431
  throw new Error("MiniMax usage response did not report success.");
1248
1432
  }
@@ -1253,7 +1437,7 @@ function balanceMetric(id, label, value, currency, allowNegative = false) {
1253
1437
  }
1254
1438
  return { id, label, value, unit: "currency", currency };
1255
1439
  }
1256
- function asObject7(value) {
1440
+ function asObject8(value) {
1257
1441
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1258
1442
  return value;
1259
1443
  }
@@ -1305,7 +1489,7 @@ function normalizeMoonshotBalancePayload(providerId, payload, capturedAt) {
1305
1489
  if (payload.code !== 0 || payload.status !== true) {
1306
1490
  throw new Error("Moonshot AI balance response did not report success.");
1307
1491
  }
1308
- const data = asObject8(payload.data);
1492
+ const data = asObject9(payload.data);
1309
1493
  if (!data) throw new Error("Moonshot AI balance response data was not an object.");
1310
1494
  const provider = PROVIDERS2[providerId];
1311
1495
  const available = amount(data.available_balance, "available balance", false);
@@ -1329,7 +1513,7 @@ function normalizeMoonshotBalancePayload(providerId, payload, capturedAt) {
1329
1513
  function currencyMetric(id, label, value, currency) {
1330
1514
  return { id, label, value, unit: "currency", currency };
1331
1515
  }
1332
- function asObject8(value) {
1516
+ function asObject9(value) {
1333
1517
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1334
1518
  return value;
1335
1519
  }
@@ -1356,7 +1540,7 @@ var OPENAI_CHATGPT_ADAPTER = {
1356
1540
  invalidateCacheOnFailure: true,
1357
1541
  async query(auth, signal, timeoutMs, guard) {
1358
1542
  if (auth.openaiCompanion) {
1359
- const { queryOpenAICompanionUsage } = await import("./openai-companion-usage-4NOBHGP7.ts");
1543
+ const { queryOpenAICompanionUsage } = await import("./openai-companion-usage-TGHK2OQR.ts");
1360
1544
  signal.throwIfAborted();
1361
1545
  return queryOpenAICompanionUsage(auth, signal, timeoutMs, guard);
1362
1546
  }
@@ -1432,19 +1616,19 @@ var ZEN_WINDOWS = [
1432
1616
  { key: "monthly", label: "Monthly" }
1433
1617
  ];
1434
1618
  function normalizeOpenCodeZenPayload(payload, capturedAt) {
1435
- const usage = asObject9(payload.usage);
1619
+ const usage = asObject10(payload.usage);
1436
1620
  if (!usage) throw new Error("OpenCode Zen usage response was not an object.");
1437
1621
  const buckets = [];
1438
1622
  const notes = [];
1439
1623
  for (const window of ZEN_WINDOWS) {
1440
- const raw = asObject9(usage[window.key]);
1624
+ const raw = asObject10(usage[window.key]);
1441
1625
  if (!raw) continue;
1442
- const status = asString3(raw.status);
1626
+ const status = asString4(raw.status);
1443
1627
  if (status !== "ok" && status !== "rate-limited") {
1444
1628
  notes.push(`${window.label} window unavailable (${status ?? "unknown status"}).`);
1445
1629
  continue;
1446
1630
  }
1447
- const used = asNonnegativeNumber2(raw.percent);
1631
+ const used = asNonnegativeNumber3(raw.percent);
1448
1632
  if (used === void 0) continue;
1449
1633
  const resetsAt = asEpochSeconds(raw.resetsAt);
1450
1634
  buckets.push({
@@ -1474,15 +1658,15 @@ function normalizeOpenCodeZenPayload(payload, capturedAt) {
1474
1658
  ...notes.length > 0 ? { notes } : {}
1475
1659
  };
1476
1660
  }
1477
- function asObject9(value) {
1661
+ function asObject10(value) {
1478
1662
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1479
1663
  return value;
1480
1664
  }
1481
- function asString3(value) {
1665
+ function asString4(value) {
1482
1666
  if (typeof value !== "string") return void 0;
1483
1667
  return sanitizeDisplayText(value, 80) || void 0;
1484
1668
  }
1485
- function asNonnegativeNumber2(value) {
1669
+ function asNonnegativeNumber3(value) {
1486
1670
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return void 0;
1487
1671
  return value;
1488
1672
  }
@@ -1498,12 +1682,12 @@ function clampPercent2(value) {
1498
1682
 
1499
1683
  // src/providers/openrouter.ts
1500
1684
  function normalizeOpenRouterKeyPayload(payload, capturedAt) {
1501
- const data = asObject10(payload.data);
1685
+ const data = asObject11(payload.data);
1502
1686
  if (!data) throw new Error("OpenRouter key response data was not an object.");
1503
- const limit = asNonnegativeNumber3(data.limit);
1504
- const remaining = asNonnegativeNumber3(data.limit_remaining);
1505
- const period = asString4(data.limit_reset);
1506
- const totalUsage = asNonnegativeNumber3(data.usage);
1687
+ const limit = asNonnegativeNumber4(data.limit);
1688
+ const remaining = asNonnegativeNumber4(data.limit_remaining);
1689
+ const period = asString5(data.limit_reset);
1690
+ const totalUsage = asNonnegativeNumber4(data.usage);
1507
1691
  const buckets = [];
1508
1692
  if (limit !== void 0) {
1509
1693
  buckets.push({
@@ -1533,26 +1717,26 @@ function normalizeOpenRouterKeyPayload(payload, capturedAt) {
1533
1717
  capturedAt,
1534
1718
  source: "openrouter-key",
1535
1719
  semantics: { kind: "api-key", label: "API-key spend limits" },
1536
- accountLabel: asString4(data.label),
1720
+ accountLabel: asString5(data.label),
1537
1721
  buckets,
1538
1722
  metrics,
1539
1723
  ...notes.length > 0 ? { notes } : {}
1540
1724
  };
1541
1725
  }
1542
1726
  function addUsageMetric(metrics, id, label, value) {
1543
- const amount2 = typeof value === "number" ? asNonnegativeNumber3(value) : void 0;
1727
+ const amount2 = typeof value === "number" ? asNonnegativeNumber4(value) : void 0;
1544
1728
  if (amount2 === void 0) return;
1545
1729
  metrics.push({ id, label, value: amount2, unit: "usd" });
1546
1730
  }
1547
- function asObject10(value) {
1731
+ function asObject11(value) {
1548
1732
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1549
1733
  return value;
1550
1734
  }
1551
- function asString4(value) {
1735
+ function asString5(value) {
1552
1736
  if (typeof value !== "string") return void 0;
1553
1737
  return sanitizeDisplayText(value, 80) || void 0;
1554
1738
  }
1555
- function asNonnegativeNumber3(value) {
1739
+ function asNonnegativeNumber4(value) {
1556
1740
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return void 0;
1557
1741
  return value;
1558
1742
  }
@@ -1796,9 +1980,9 @@ var HTTP_MESSAGES = {
1796
1980
  500: "Internal error. Try again later."
1797
1981
  };
1798
1982
  function zaiPayloadError(payload) {
1799
- const object = asObject11(payload);
1983
+ const object = asObject12(payload);
1800
1984
  if (!object) return void 0;
1801
- const nested = asObject11(object.error);
1985
+ const nested = asObject12(object.error);
1802
1986
  const rawCode = nested?.code === void 0 ? object.code : nested.code;
1803
1987
  const code = errorCode(rawCode);
1804
1988
  if (object.error === void 0 && object.success !== false && (rawCode === void 0 || code === "0" || code === "200")) {
@@ -1826,26 +2010,26 @@ function errorCode(value) {
1826
2010
  }
1827
2011
  return typeof value === "string" && /^(?:0|[1-9]\d{0,3})$/u.test(value) ? value : void 0;
1828
2012
  }
1829
- function asObject11(value) {
2013
+ function asObject12(value) {
1830
2014
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
1831
2015
  }
1832
2016
 
1833
2017
  // src/providers/zai.ts
1834
- var FIVE_HOUR_WINDOW_MINUTES2 = 300;
1835
- var WEEKLY_WINDOW_MINUTES2 = 10080;
2018
+ var FIVE_HOUR_WINDOW_MINUTES3 = 300;
2019
+ var WEEKLY_WINDOW_MINUTES3 = 10080;
1836
2020
  function normalizeZaiQuotaPayload(providerId, providerName, payload, capturedAt, plan) {
1837
2021
  const error = zaiPayloadError(payload);
1838
2022
  if (error) throw new Error(error);
1839
- const data = asObject12(payload.data);
2023
+ const data = asObject13(payload.data);
1840
2024
  if (!data) throw new Error("Z.AI quota response data was not an object.");
1841
2025
  const limits = Array.isArray(data.limits) ? data.limits : [];
1842
2026
  const buckets = [];
1843
2027
  const metrics = [];
1844
2028
  for (const raw of limits) {
1845
- const limit = asObject12(raw);
2029
+ const limit = asObject13(raw);
1846
2030
  if (!limit) continue;
1847
- const type = asString5(limit.type);
1848
- const unit = asNonnegativeNumber4(limit.unit);
2031
+ const type = asString6(limit.type);
2032
+ const unit = asNonnegativeNumber5(limit.unit);
1849
2033
  const isPlanUsage = type === "TOKENS_LIMIT" || type === "CREDIT_LIMIT";
1850
2034
  if (type === "TIME_LIMIT") {
1851
2035
  addCountBucket(buckets, limit, "mcp-monthly", "MCP monthly allowance");
@@ -1853,8 +2037,8 @@ function normalizeZaiQuotaPayload(providerId, providerName, payload, capturedAt,
1853
2037
  } else if (isPlanUsage && unit === 3) {
1854
2038
  addPercentBucket(buckets, limit, "five-hour", sessionWindowLabel(limit), sessionWindowMinutes(limit));
1855
2039
  } else if (isPlanUsage && unit === 6) {
1856
- const used = asNonnegativeNumber4(limit.currentValue);
1857
- const quota = asNonnegativeNumber4(limit.usage);
2040
+ const used = asNonnegativeNumber5(limit.currentValue);
2041
+ const quota = asNonnegativeNumber5(limit.usage);
1858
2042
  if (used !== void 0 && quota !== void 0) {
1859
2043
  addCountBucket(buckets, limit, "weekly", "Weekly window", weeklyWindowMinutes(limit));
1860
2044
  } else {
@@ -1866,10 +2050,10 @@ function normalizeZaiQuotaPayload(providerId, providerName, payload, capturedAt,
1866
2050
  throw new Error("Z.AI quota endpoint returned no displayable usage data.");
1867
2051
  }
1868
2052
  const notes = [];
1869
- const level = asString5(data.level);
1870
- const planLabel = plan?.name ?? level;
1871
- if (planLabel) {
1872
- notes.push(plan?.renewsAt ? `Plan: ${planLabel} \xB7 renews ${plan.renewsAt}` : `Plan: ${planLabel}`);
2053
+ const level = asString6(data.level);
2054
+ const planLabel2 = plan?.name ?? level;
2055
+ if (planLabel2) {
2056
+ notes.push(plan?.renewsAt ? `Plan: ${planLabel2} \xB7 renews ${plan.renewsAt}` : `Plan: ${planLabel2}`);
1873
2057
  }
1874
2058
  return {
1875
2059
  providerId,
@@ -1887,12 +2071,12 @@ function normalizeZaiSubscriptionPayload(payload) {
1887
2071
  if (!Array.isArray(payload.data)) return void 0;
1888
2072
  const candidates = [];
1889
2073
  for (const raw of payload.data) {
1890
- const entry = asObject12(raw);
2074
+ const entry = asObject13(raw);
1891
2075
  if (!entry) continue;
1892
- const name = asString5(entry.productName);
2076
+ const name = asString6(entry.productName);
1893
2077
  if (!name) continue;
1894
2078
  const renewsAt = planRenewalDate(entry.nextRenewTime);
1895
- const status = asString5(entry.status)?.toUpperCase();
2079
+ const status = asString6(entry.status)?.toUpperCase();
1896
2080
  const inCurrentPeriod = asBoolean(entry.inCurrentPeriod);
1897
2081
  candidates.push({
1898
2082
  plan: { name, ...renewsAt !== void 0 ? { renewsAt } : {} },
@@ -1908,24 +2092,24 @@ function normalizeZaiSubscriptionPayload(payload) {
1908
2092
  }
1909
2093
  function planRenewalDate(value) {
1910
2094
  if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}/u.test(value)) return value.slice(0, 10);
1911
- const millis = asNonnegativeNumber4(value);
2095
+ const millis = asNonnegativeNumber5(value);
1912
2096
  if (millis === void 0 || millis === 0) return void 0;
1913
2097
  return new Date(millis).toISOString().slice(0, 10);
1914
2098
  }
1915
2099
  function sessionWindowMinutes(limit) {
1916
2100
  const hours = asPositiveNumber(limit.number);
1917
- return hours === void 0 ? FIVE_HOUR_WINDOW_MINUTES2 : Math.round(hours * 60);
2101
+ return hours === void 0 ? FIVE_HOUR_WINDOW_MINUTES3 : Math.round(hours * 60);
1918
2102
  }
1919
2103
  function sessionWindowLabel(limit) {
1920
2104
  const minutes = sessionWindowMinutes(limit);
1921
- return minutes === FIVE_HOUR_WINDOW_MINUTES2 ? "5h window" : `${Math.round(minutes / 60)}h window`;
2105
+ return minutes === FIVE_HOUR_WINDOW_MINUTES3 ? "5h window" : `${Math.round(minutes / 60)}h window`;
1922
2106
  }
1923
2107
  function weeklyWindowMinutes(limit) {
1924
2108
  const weeks = asPositiveNumber(limit.number);
1925
- return weeks === void 0 ? WEEKLY_WINDOW_MINUTES2 : Math.round(weeks * WEEKLY_WINDOW_MINUTES2);
2109
+ return weeks === void 0 ? WEEKLY_WINDOW_MINUTES3 : Math.round(weeks * WEEKLY_WINDOW_MINUTES3);
1926
2110
  }
1927
2111
  function addPercentBucket(buckets, limit, id, label, windowMinutes) {
1928
- const used = asNonnegativeNumber4(limit.percentage);
2112
+ const used = asNonnegativeNumber5(limit.percentage);
1929
2113
  if (used === void 0) return;
1930
2114
  const percent = clampPercent3(used);
1931
2115
  const resetsAt = asEpochSeconds2(limit.nextResetTime);
@@ -1941,8 +2125,8 @@ function addPercentBucket(buckets, limit, id, label, windowMinutes) {
1941
2125
  });
1942
2126
  }
1943
2127
  function addCountBucket(buckets, limit, id, label, windowMinutes) {
1944
- const used = asNonnegativeNumber4(limit.currentValue);
1945
- const quota = asNonnegativeNumber4(limit.usage);
2128
+ const used = asNonnegativeNumber5(limit.currentValue);
2129
+ const quota = asNonnegativeNumber5(limit.usage);
1946
2130
  if (used === void 0 || quota === void 0) return;
1947
2131
  const resetsAt = asEpochSeconds2(limit.nextResetTime);
1948
2132
  buckets.push({
@@ -1959,28 +2143,28 @@ function addCountBucket(buckets, limit, id, label, windowMinutes) {
1959
2143
  function addUsageDetailMetrics(metrics, value) {
1960
2144
  if (!Array.isArray(value)) return;
1961
2145
  for (const raw of value) {
1962
- const detail = asObject12(raw);
2146
+ const detail = asObject13(raw);
1963
2147
  if (!detail) continue;
1964
- const label = asString5(detail.modelCode);
1965
- const usage = asNonnegativeNumber4(detail.usage);
2148
+ const label = asString6(detail.modelCode);
2149
+ const usage = asNonnegativeNumber5(detail.usage);
1966
2150
  if (!label || usage === void 0) continue;
1967
2151
  metrics.push({ id: `mcp-${kebabCase(label)}`, label, value: usage, unit: "count" });
1968
2152
  }
1969
2153
  }
1970
- function asObject12(value) {
2154
+ function asObject13(value) {
1971
2155
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1972
2156
  return value;
1973
2157
  }
1974
- function asString5(value) {
2158
+ function asString6(value) {
1975
2159
  if (typeof value !== "string") return void 0;
1976
2160
  return sanitizeDisplayText(value, 80) || void 0;
1977
2161
  }
1978
- function asNonnegativeNumber4(value) {
2162
+ function asNonnegativeNumber5(value) {
1979
2163
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return void 0;
1980
2164
  return value;
1981
2165
  }
1982
2166
  function asPositiveNumber(value) {
1983
- const number = asNonnegativeNumber4(value);
2167
+ const number = asNonnegativeNumber5(value);
1984
2168
  return number !== void 0 && number > 0 ? number : void 0;
1985
2169
  }
1986
2170
  function asBoolean(value) {
@@ -1990,7 +2174,7 @@ function asBoolean(value) {
1990
2174
  return void 0;
1991
2175
  }
1992
2176
  function asEpochSeconds2(value) {
1993
- const millis = asNonnegativeNumber4(value);
2177
+ const millis = asNonnegativeNumber5(value);
1994
2178
  if (millis === void 0) return void 0;
1995
2179
  return Math.floor(millis / 1e3);
1996
2180
  }
@@ -2095,6 +2279,11 @@ import { readStoredCredential as readStoredCredential2 } from "@earendil-works/p
2095
2279
  var BASETEN_BILLING_USAGE_URL = "https://api.baseten.co/v1/billing/usage_summary";
2096
2280
  var BASETEN_USAGE_WINDOW_DAYS = 30;
2097
2281
  var CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
2282
+ var COMMAND_CODE_API_ORIGIN = "https://api.commandcode.ai";
2283
+ var COMMAND_CODE_ACCOUNT_URL = `${COMMAND_CODE_API_ORIGIN}/alpha/whoami`;
2284
+ var COMMAND_CODE_CREDITS_URL = `${COMMAND_CODE_API_ORIGIN}/alpha/billing/credits`;
2285
+ var COMMAND_CODE_SUBSCRIPTIONS_URL = `${COMMAND_CODE_API_ORIGIN}/alpha/billing/subscriptions`;
2286
+ var COMMAND_CODE_USAGE_SUMMARY_URL = `${COMMAND_CODE_API_ORIGIN}/alpha/usage/summary`;
2098
2287
  var DEEPSEEK_BALANCE_URL = "https://api.deepseek.com/user/balance";
2099
2288
  var GITHUB_COPILOT_USAGE_URL = "https://api.github.com/copilot_internal/user";
2100
2289
  var OPENROUTER_KEY_URL = "https://openrouter.ai/api/v1/key";
@@ -2223,6 +2412,62 @@ var SUPPORTED_ADAPTERS = [
2223
2412
  return normalizeVercelAIGatewayCreditsPayload(payload, Date.now());
2224
2413
  }
2225
2414
  },
2415
+ {
2416
+ id: "command-code",
2417
+ displayName: "Command Code",
2418
+ semantics: { kind: "consumer-subscription", label: "Command Code plan credits and rolling limits" },
2419
+ async query(auth, signal, timeoutMs, guard) {
2420
+ if (!guard) throw new Error("Command Code usage requires request-boundary revalidation.");
2421
+ const startedAt = Date.now();
2422
+ await guard();
2423
+ const account = await fetchProviderJson(
2424
+ COMMAND_CODE_ACCOUNT_URL,
2425
+ auth,
2426
+ signal,
2427
+ remainingTimeout2(timeoutMs, startedAt, "fetching the Command Code account"),
2428
+ "Command Code account endpoint",
2429
+ { redirect: "error" }
2430
+ );
2431
+ await guard();
2432
+ const orgId = commandCodeOrgId(account);
2433
+ const [credits, subscription] = await Promise.all([
2434
+ fetchCommandCodeOptional(
2435
+ commandCodeUrl(COMMAND_CODE_CREDITS_URL, { orgId }),
2436
+ auth,
2437
+ signal,
2438
+ timeoutMs - (Date.now() - startedAt),
2439
+ "Command Code credits endpoint"
2440
+ ),
2441
+ fetchCommandCodeOptional(
2442
+ commandCodeUrl(COMMAND_CODE_SUBSCRIPTIONS_URL, { orgId }),
2443
+ auth,
2444
+ signal,
2445
+ timeoutMs - (Date.now() - startedAt),
2446
+ "Command Code plan endpoint"
2447
+ )
2448
+ ]);
2449
+ await guard();
2450
+ const usage = await fetchCommandCodeOptional(
2451
+ commandCodeUrl(COMMAND_CODE_USAGE_SUMMARY_URL, {
2452
+ orgId,
2453
+ since: commandCodeSubscriptionStart(subscription)
2454
+ }),
2455
+ auth,
2456
+ signal,
2457
+ timeoutMs - (Date.now() - startedAt),
2458
+ "Command Code usage summary endpoint"
2459
+ );
2460
+ await guard();
2461
+ if (signal.aborted) throw abortError();
2462
+ const bundle = {
2463
+ account,
2464
+ ...credits ? { credits } : {},
2465
+ ...subscription ? { subscription } : {},
2466
+ ...usage ? { usage } : {}
2467
+ };
2468
+ return normalizeCommandCodeUsagePayload(bundle, Date.now());
2469
+ }
2470
+ },
2226
2471
  createFireworksAdapter(fetchProviderJson),
2227
2472
  {
2228
2473
  id: "opencode-go",
@@ -2446,7 +2691,7 @@ async function resolveUsageAuth(ctx, adapter, salt = AUTH_FINGERPRINT_SALT, cred
2446
2691
  const native = finalize(
2447
2692
  resolveOpenAIChatGPTAuth(auth, providerResult.auth, providerResult.source, model, offered.candidates)
2448
2693
  );
2449
- const { resolveOpenAICompanionAuth } = await import("./openai-companion-auth-6VLPFVHF.ts");
2694
+ const { resolveOpenAICompanionAuth } = await import("./openai-companion-auth-FGFC6DBT.ts");
2450
2695
  return resolveOpenAICompanionAuth(ctx, native, salt, credentialReader, candidateReader);
2451
2696
  }
2452
2697
  if (adapter.id === "github-copilot") {
@@ -2680,7 +2925,7 @@ function resolveXaiUsageAuth(auth, model, salt, candidates) {
2680
2925
  const matches = [];
2681
2926
  for (const candidate of candidates) {
2682
2927
  try {
2683
- const credential = asObject13(candidate);
2928
+ const credential = asObject14(candidate);
2684
2929
  if (credential?.type !== "oauth") continue;
2685
2930
  sawOAuth = true;
2686
2931
  if (credential.access !== resolvedAccess) continue;
@@ -2734,7 +2979,7 @@ function resolveGitHubCopilotUsageAuth(auth, model, salt, candidates, standalone
2734
2979
  const matches = /* @__PURE__ */ new Map();
2735
2980
  for (const candidate of candidates) {
2736
2981
  try {
2737
- const credential = asObject13(candidate);
2982
+ const credential = asObject14(candidate);
2738
2983
  if (credential?.type !== "oauth") continue;
2739
2984
  sawOAuth = true;
2740
2985
  const storedAccess2 = typeof credential.access === "string" && credential.access ? credential.access : void 0;
@@ -2794,7 +3039,7 @@ function bearerToken(authorization) {
2794
3039
  const match = /^Bearer\s+(.+)$/iu.exec(authorization ?? "");
2795
3040
  return match?.[1];
2796
3041
  }
2797
- function asObject13(value) {
3042
+ function asObject14(value) {
2798
3043
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
2799
3044
  return value;
2800
3045
  }
@@ -2817,6 +3062,7 @@ function hasOfficialUrlOrigin(value, providerId) {
2817
3062
  }
2818
3063
  if (providerId === "openai") return url.origin === "https://api.openai.com";
2819
3064
  if (providerId === "openai-codex") return url.origin === "https://chatgpt.com";
3065
+ if (providerId === "command-code") return url.origin === COMMAND_CODE_API_ORIGIN;
2820
3066
  if (providerId === "deepseek") return url.origin === "https://api.deepseek.com";
2821
3067
  if (providerId === "fireworks") return url.origin === "https://api.fireworks.ai";
2822
3068
  if (providerId === "openrouter") return url.origin === "https://openrouter.ai";
@@ -2950,6 +3196,33 @@ async function fetchZaiPlan(providerName, auth, signal, timeoutMs) {
2950
3196
  function isAbortError(error) {
2951
3197
  return error instanceof Error && error.name === "AbortError";
2952
3198
  }
3199
+ async function fetchCommandCodeOptional(url, auth, signal, timeoutMs, description) {
3200
+ if (signal.aborted) throw abortError();
3201
+ if (timeoutMs <= 0) return void 0;
3202
+ try {
3203
+ const payload = await fetchProviderJson(url, auth, signal, timeoutMs, description, { redirect: "error" });
3204
+ if (signal.aborted) throw abortError();
3205
+ return payload;
3206
+ } catch (error) {
3207
+ if (signal.aborted) throw abortError();
3208
+ if (isAbortError(error) || isStaleExtensionContextError(error)) throw error;
3209
+ return void 0;
3210
+ }
3211
+ }
3212
+ function commandCodeUrl(base, params) {
3213
+ const query = new URLSearchParams();
3214
+ for (const [key, value] of Object.entries(params)) {
3215
+ if (value) query.set(key, value);
3216
+ }
3217
+ const search = query.toString();
3218
+ return search ? `${base}?${search}` : base;
3219
+ }
3220
+ function commandCodeSubscriptionStart(subscription) {
3221
+ const data = subscription?.data;
3222
+ if (!data || typeof data !== "object" || Array.isArray(data)) return void 0;
3223
+ const value = data.currentPeriodStart;
3224
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
3225
+ }
2953
3226
 
2954
3227
  export {
2955
3228
  UsageCache,
@@ -2964,6 +3237,8 @@ export {
2964
3237
  fallbackOAuthCredentialCandidates,
2965
3238
  normalizeBasetenBillingUsagePayload,
2966
3239
  normalizeCodexBackendPayload,
3240
+ commandCodeOrgId,
3241
+ normalizeCommandCodeUsagePayload,
2967
3242
  normalizeDeepSeekBalancePayload,
2968
3243
  isFireworksAccountId,
2969
3244
  normalizeFireworksAccountsPayload,
@@ -2999,4 +3274,4 @@ export {
2999
3274
  providerIsConfigured,
3000
3275
  fetchProviderJson
3001
3276
  };
3002
- //# sourceMappingURL=chunk-ENCC7IBP.ts.map
3277
+ //# sourceMappingURL=chunk-ACPQJ2CM.ts.map