@narumitw/pi-usage 0.63.1 → 0.64.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.
@@ -6,7 +6,7 @@ import {
6
6
  fingerprintResolvedAuth,
7
7
  openAIAuthAccessToken,
8
8
  resolveUsageAuth
9
- } from "./chunk-ENCC7IBP.ts";
9
+ } from "./chunk-ACPQJ2CM.ts";
10
10
 
11
11
  // src/openai-companion-auth.ts
12
12
  async function resolveOpenAICompanionAuth(ctx, native, salt, credentialReader, candidateReader) {
@@ -80,4 +80,4 @@ function object(value) {
80
80
  export {
81
81
  resolveOpenAICompanionAuth
82
82
  };
83
- //# sourceMappingURL=openai-companion-auth-6VLPFVHF.ts.map
83
+ //# sourceMappingURL=openai-companion-auth-FGFC6DBT.ts.map
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  CHATGPT_USAGE_SETTINGS_URL,
5
5
  fetchProviderJson
6
- } from "./chunk-ENCC7IBP.ts";
6
+ } from "./chunk-ACPQJ2CM.ts";
7
7
 
8
8
  // src/providers/openai-companion-usage.ts
9
9
  var USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
@@ -117,4 +117,4 @@ export {
117
117
  matchingOpenAIAppBuckets,
118
118
  queryOpenAICompanionUsage
119
119
  };
120
- //# sourceMappingURL=openai-companion-usage-4NOBHGP7.ts.map
120
+ //# sourceMappingURL=openai-companion-usage-TGHK2OQR.ts.map
package/dist/index.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  abortError,
10
10
  adapterForProvider,
11
11
  awaitWithDeadline,
12
+ commandCodeOrgId,
12
13
  createFireworksAdapter,
13
14
  createOAuthCredentialCandidateReader,
14
15
  createUsageTargetSelectOptions,
@@ -23,6 +24,7 @@ import {
23
24
  miniMaxUsageKind,
24
25
  normalizeBasetenBillingUsagePayload,
25
26
  normalizeCodexBackendPayload,
27
+ normalizeCommandCodeUsagePayload,
26
28
  normalizeDeepSeekBalancePayload,
27
29
  normalizeFireworksAccountsPayload,
28
30
  normalizeFireworksBillingSummaryPayload,
@@ -45,7 +47,7 @@ import {
45
47
  runWithConcurrency,
46
48
  sanitizeDisplayText,
47
49
  usageAdapters
48
- } from "./chunks/chunk-ENCC7IBP.ts";
50
+ } from "./chunks/chunk-ACPQJ2CM.ts";
49
51
 
50
52
  // src/codex-fast.ts
51
53
  import { calculateCost, hasApi } from "@earendil-works/pi-ai";
@@ -405,6 +407,7 @@ function formatUsageReport(report, displayState) {
405
407
  else if (report.providerId === "github-copilot") formatGitHubCopilotReport(lines, report);
406
408
  else if (report.providerId === "openrouter") formatOpenRouterReport(lines, report);
407
409
  else if (report.providerId === "opencode-go") formatOpenCodeZenReport(lines, report);
410
+ else if (report.providerId === "command-code") formatCommandCodeReport(lines, report);
408
411
  else if (report.providerId === "kimi-coding") formatKimiCodingReport(lines, report);
409
412
  else if (report.providerId === "moonshotai" || report.providerId === "moonshotai-cn") {
410
413
  formatMoonshotReport(lines, report);
@@ -444,6 +447,7 @@ function formatUsageStatusline(report, model, now = Date.now(), showCodexResetCo
444
447
  if (typeof total?.value === "number") return `openrouter ${formatUsd(total.value)} used`;
445
448
  }
446
449
  if (report.providerId === "opencode-go") return formatOpenCodeZenStatusline(report);
450
+ if (report.providerId === "command-code") return formatCommandCodeStatusline(report);
447
451
  if (report.providerId === "kimi-coding") return formatKimiCodingStatusline(report);
448
452
  if (report.providerId === "moonshotai" || report.providerId === "moonshotai-cn") {
449
453
  return formatMoonshotStatusline(report);
@@ -623,6 +627,34 @@ function formatOpenCodeZenStatusline(report) {
623
627
  }
624
628
  return parts.length > 1 ? parts.join(" ") : void 0;
625
629
  }
630
+ function formatCommandCodeReport(lines, report) {
631
+ for (const bucket of report.buckets) {
632
+ const reset = bucket.resetsAt ? ` (resets ${formatReset(bucket.resetsAt)})` : "";
633
+ if (bucket.used === void 0 || bucket.limit === void 0) {
634
+ lines.push(`${`${bucket.label}:`.padEnd(VALUE_COLUMN)}unavailable${reset}`);
635
+ continue;
636
+ }
637
+ lines.push(
638
+ `${`${bucket.label}:`.padEnd(VALUE_COLUMN)}${formatUsd(bucket.used)} of ${formatUsd(bucket.limit)} used \xB7 ${percentRemaining(bucket)}% left${reset}`
639
+ );
640
+ }
641
+ for (const metric of report.metrics) {
642
+ lines.push(`${`${metric.label}:`.padEnd(VALUE_COLUMN)}${formatMetricValue(metric.value, metric.unit)}`);
643
+ }
644
+ }
645
+ function formatCommandCodeStatusline(report) {
646
+ const parts = ["cmd"];
647
+ for (const [id, label] of [
648
+ ["five-hour", "5h"],
649
+ ["weekly", "wk"],
650
+ ["monthly", "mo"]
651
+ ]) {
652
+ const bucket = report.buckets.find((candidate) => candidate.id === id);
653
+ if (bucket?.unit !== "usd" || bucket.limit === void 0 || bucket.remaining === void 0) continue;
654
+ parts.push(`${percentRemaining(bucket)}% ${label}`);
655
+ }
656
+ return parts.length > 1 ? parts.join(" ") : void 0;
657
+ }
626
658
  function formatKimiCodingReport(lines, report) {
627
659
  for (const bucket of report.buckets) {
628
660
  const reset = bucket.resetsAt ? ` (resets ${formatReset(bucket.resetsAt)})` : "";
@@ -1567,6 +1599,7 @@ async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent,
1567
1599
  var CACHE_TTL_MS = 5 * 60 * 1e3;
1568
1600
  var STATUS_COUNTDOWN_REFRESH_MS = 60 * 1e3;
1569
1601
  var DEFAULT_TIMEOUT_MS = 15e3;
1602
+ var COMMAND_CODE_REVALIDATION_RESERVE_MS = 1e3;
1570
1603
  var ALL_PROVIDER_CONCURRENCY = 2;
1571
1604
  var FAILURE_BACKOFF_MS = 3e4;
1572
1605
  var MAX_ACCOUNT_STATES = 32;
@@ -1736,6 +1769,7 @@ function usageExtension(pi, dependencies = {}) {
1736
1769
  }
1737
1770
  const requiresRequestBoundaryGuard = adapter.targets !== void 0 || [
1738
1771
  "baseten",
1772
+ "command-code",
1739
1773
  "deepseek",
1740
1774
  "minimax",
1741
1775
  "minimax-cn",
@@ -1866,11 +1900,15 @@ function usageExtension(pi, dependencies = {}) {
1866
1900
  querySequence += 1;
1867
1901
  queryId = querySequence;
1868
1902
  setBoundedMap(latestQueries, failureKey, queryId, MAX_ACCOUNT_STATES);
1903
+ const queryTimeoutMs = Math.max(
1904
+ 1,
1905
+ deadlineAt - Date.now() - (adapter.id === "command-code" ? COMMAND_CODE_REVALIDATION_RESERVE_MS : 0)
1906
+ );
1869
1907
  const report = await queryProviderUsage(
1870
1908
  adapter,
1871
1909
  auth,
1872
1910
  signal,
1873
- Math.max(1, deadlineAt - Date.now()),
1911
+ queryTimeoutMs,
1874
1912
  requiresRequestBoundaryGuard ? guard : void 0,
1875
1913
  target.targetId
1876
1914
  );
@@ -2752,6 +2790,7 @@ export {
2752
2790
  codexFastIsEffective,
2753
2791
  codexFastRequestTier,
2754
2792
  codexFastStatusLabel,
2793
+ commandCodeOrgId,
2755
2794
  consumeCodexResetCredit,
2756
2795
  correctCodexFastMessageCost,
2757
2796
  createFireworksAdapter,
@@ -2772,6 +2811,7 @@ export {
2772
2811
  normalizeBasetenBillingUsagePayload,
2773
2812
  normalizeCodexBackendPayload,
2774
2813
  normalizeCodexResetCreditsPayload,
2814
+ normalizeCommandCodeUsagePayload,
2775
2815
  normalizeDeepSeekBalancePayload,
2776
2816
  normalizeFireworksAccountsPayload,
2777
2817
  normalizeFireworksBillingSummaryPayload,