@narumitw/pi-usage 0.63.0 → 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.
- package/README.md +5 -3
- package/dist/chunks/{chunk-ENCC7IBP.ts → chunk-ACPQJ2CM.ts} +379 -104
- package/dist/chunks/chunk-ACPQJ2CM.ts.map +7 -0
- package/dist/chunks/{openai-companion-auth-6VLPFVHF.ts → openai-companion-auth-FGFC6DBT.ts} +2 -2
- package/dist/chunks/{openai-companion-usage-4NOBHGP7.ts → openai-companion-usage-TGHK2OQR.ts} +2 -2
- package/dist/index.ts +48 -11
- package/dist/index.ts.map +2 -2
- package/docs/providers.md +22 -2
- package/package.json +2 -1
- package/src/format.ts +40 -13
- package/src/index.ts +6 -0
- package/src/providers/command-code.ts +228 -0
- package/src/query.ts +107 -1
- package/src/types.ts +29 -0
- package/src/usage.ts +9 -1
- package/dist/chunks/chunk-ENCC7IBP.ts.map +0 -7
- /package/dist/chunks/{openai-companion-auth-6VLPFVHF.ts.map → openai-companion-auth-FGFC6DBT.ts.map} +0 -0
- /package/dist/chunks/{openai-companion-usage-4NOBHGP7.ts.map → openai-companion-usage-TGHK2OQR.ts.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
fingerprintResolvedAuth,
|
|
7
7
|
openAIAuthAccessToken,
|
|
8
8
|
resolveUsageAuth
|
|
9
|
-
} from "./chunk-
|
|
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-
|
|
83
|
+
//# sourceMappingURL=openai-companion-auth-FGFC6DBT.ts.map
|
package/dist/chunks/{openai-companion-usage-4NOBHGP7.ts → openai-companion-usage-TGHK2OQR.ts}
RENAMED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
CHATGPT_USAGE_SETTINGS_URL,
|
|
5
5
|
fetchProviderJson
|
|
6
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
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);
|
|
@@ -422,15 +425,12 @@ function formatUsageReport(report, displayState) {
|
|
|
422
425
|
function formatUsageStatusline(report, model, now = Date.now(), showCodexResetCountdown = true, codexStatusPercentage = "remaining") {
|
|
423
426
|
if (report.providerId === "openai" && report.source === "openai-chatgpt-auth") return "chatgpt usage: web only";
|
|
424
427
|
if (report.source === "openai-chatgpt-companion") {
|
|
425
|
-
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
});
|
|
432
|
-
return `${group === "chatgpt-plan" ? "plan" : "app"} ${windows.join(" ")}`;
|
|
433
|
-
}).join(" \xB7 ")}`;
|
|
428
|
+
const windows = report.buckets.filter((bucket) => bucket.groupId === "chatgpt-plan").map((bucket) => {
|
|
429
|
+
const reset = formatResetCountdown(bucket.resetsAt, now);
|
|
430
|
+
const window = reset ? `\u21BB ${reset}` : formatWindowLabel(bucket.windowMinutes, "weekly", true);
|
|
431
|
+
return `${bucket.remaining === void 0 ? "unavailable" : `${bucket.remaining.toFixed(0)}%`} ${window}`;
|
|
432
|
+
});
|
|
433
|
+
return `chatgpt plan ${windows.join(" ")}`;
|
|
434
434
|
}
|
|
435
435
|
if (report.providerId === "baseten") return formatBasetenStatusline(report);
|
|
436
436
|
if (report.providerId === "openai-codex") {
|
|
@@ -447,6 +447,7 @@ function formatUsageStatusline(report, model, now = Date.now(), showCodexResetCo
|
|
|
447
447
|
if (typeof total?.value === "number") return `openrouter ${formatUsd(total.value)} used`;
|
|
448
448
|
}
|
|
449
449
|
if (report.providerId === "opencode-go") return formatOpenCodeZenStatusline(report);
|
|
450
|
+
if (report.providerId === "command-code") return formatCommandCodeStatusline(report);
|
|
450
451
|
if (report.providerId === "kimi-coding") return formatKimiCodingStatusline(report);
|
|
451
452
|
if (report.providerId === "moonshotai" || report.providerId === "moonshotai-cn") {
|
|
452
453
|
return formatMoonshotStatusline(report);
|
|
@@ -626,6 +627,34 @@ function formatOpenCodeZenStatusline(report) {
|
|
|
626
627
|
}
|
|
627
628
|
return parts.length > 1 ? parts.join(" ") : void 0;
|
|
628
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
|
+
}
|
|
629
658
|
function formatKimiCodingReport(lines, report) {
|
|
630
659
|
for (const bucket of report.buckets) {
|
|
631
660
|
const reset = bucket.resetsAt ? ` (resets ${formatReset(bucket.resetsAt)})` : "";
|
|
@@ -1570,6 +1599,7 @@ async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent,
|
|
|
1570
1599
|
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
1571
1600
|
var STATUS_COUNTDOWN_REFRESH_MS = 60 * 1e3;
|
|
1572
1601
|
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
1602
|
+
var COMMAND_CODE_REVALIDATION_RESERVE_MS = 1e3;
|
|
1573
1603
|
var ALL_PROVIDER_CONCURRENCY = 2;
|
|
1574
1604
|
var FAILURE_BACKOFF_MS = 3e4;
|
|
1575
1605
|
var MAX_ACCOUNT_STATES = 32;
|
|
@@ -1739,6 +1769,7 @@ function usageExtension(pi, dependencies = {}) {
|
|
|
1739
1769
|
}
|
|
1740
1770
|
const requiresRequestBoundaryGuard = adapter.targets !== void 0 || [
|
|
1741
1771
|
"baseten",
|
|
1772
|
+
"command-code",
|
|
1742
1773
|
"deepseek",
|
|
1743
1774
|
"minimax",
|
|
1744
1775
|
"minimax-cn",
|
|
@@ -1869,11 +1900,15 @@ function usageExtension(pi, dependencies = {}) {
|
|
|
1869
1900
|
querySequence += 1;
|
|
1870
1901
|
queryId = querySequence;
|
|
1871
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
|
+
);
|
|
1872
1907
|
const report = await queryProviderUsage(
|
|
1873
1908
|
adapter,
|
|
1874
1909
|
auth,
|
|
1875
1910
|
signal,
|
|
1876
|
-
|
|
1911
|
+
queryTimeoutMs,
|
|
1877
1912
|
requiresRequestBoundaryGuard ? guard : void 0,
|
|
1878
1913
|
target.targetId
|
|
1879
1914
|
);
|
|
@@ -2755,6 +2790,7 @@ export {
|
|
|
2755
2790
|
codexFastIsEffective,
|
|
2756
2791
|
codexFastRequestTier,
|
|
2757
2792
|
codexFastStatusLabel,
|
|
2793
|
+
commandCodeOrgId,
|
|
2758
2794
|
consumeCodexResetCredit,
|
|
2759
2795
|
correctCodexFastMessageCost,
|
|
2760
2796
|
createFireworksAdapter,
|
|
@@ -2775,6 +2811,7 @@ export {
|
|
|
2775
2811
|
normalizeBasetenBillingUsagePayload,
|
|
2776
2812
|
normalizeCodexBackendPayload,
|
|
2777
2813
|
normalizeCodexResetCreditsPayload,
|
|
2814
|
+
normalizeCommandCodeUsagePayload,
|
|
2778
2815
|
normalizeDeepSeekBalancePayload,
|
|
2779
2816
|
normalizeFireworksAccountsPayload,
|
|
2780
2817
|
normalizeFireworksBillingSummaryPayload,
|