@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.
- package/README.md +3 -2
- 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 +45 -4
- package/dist/index.ts.map +2 -2
- package/docs/providers.md +19 -0
- package/package.json +2 -1
- package/src/format.ts +32 -0
- 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 +16 -3
- 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);
|
|
@@ -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;
|
|
@@ -1659,6 +1692,7 @@ function usageExtension(pi, dependencies = {}) {
|
|
|
1659
1692
|
}
|
|
1660
1693
|
const settings = settingsRuntime.get().settings;
|
|
1661
1694
|
const showCodexResetCountdown = outcome.state.report.providerId === "openai-codex" && settings.codexStatusResetCountdown;
|
|
1695
|
+
const isCompanionReport = outcome.state.report.source === "openai-chatgpt-companion";
|
|
1662
1696
|
const now = Date.now();
|
|
1663
1697
|
const rawValue = formatUsageStatusline(
|
|
1664
1698
|
outcome.state.report,
|
|
@@ -1670,8 +1704,8 @@ function usageExtension(pi, dependencies = {}) {
|
|
|
1670
1704
|
const value = rawValue ? fastRuntime.decorateStatus(model, rawValue) : void 0;
|
|
1671
1705
|
if (!safeSetStatus(ctx, value)) return;
|
|
1672
1706
|
if (shouldSchedule && sessionActive) scheduleStatusRefresh(ctx, model);
|
|
1673
|
-
if (sessionActive && (showCodexResetCountdown ||
|
|
1674
|
-
(bucket) => bucket.resetsAt !== void 0 && Number.isFinite(bucket.resetsAt) && bucket.resetsAt * 1e3 > now
|
|
1707
|
+
if (sessionActive && (showCodexResetCountdown || isCompanionReport) && outcome.state.report.buckets.some(
|
|
1708
|
+
(bucket) => (!isCompanionReport || bucket.groupId === "chatgpt-plan") && bucket.resetsAt !== void 0 && Number.isFinite(bucket.resetsAt) && bucket.resetsAt * 1e3 > now
|
|
1675
1709
|
)) {
|
|
1676
1710
|
const generation = statusGeneration;
|
|
1677
1711
|
statusCountdownTimer = setTimeout(() => {
|
|
@@ -1736,6 +1770,7 @@ function usageExtension(pi, dependencies = {}) {
|
|
|
1736
1770
|
}
|
|
1737
1771
|
const requiresRequestBoundaryGuard = adapter.targets !== void 0 || [
|
|
1738
1772
|
"baseten",
|
|
1773
|
+
"command-code",
|
|
1739
1774
|
"deepseek",
|
|
1740
1775
|
"minimax",
|
|
1741
1776
|
"minimax-cn",
|
|
@@ -1866,11 +1901,15 @@ function usageExtension(pi, dependencies = {}) {
|
|
|
1866
1901
|
querySequence += 1;
|
|
1867
1902
|
queryId = querySequence;
|
|
1868
1903
|
setBoundedMap(latestQueries, failureKey, queryId, MAX_ACCOUNT_STATES);
|
|
1904
|
+
const queryTimeoutMs = Math.max(
|
|
1905
|
+
1,
|
|
1906
|
+
deadlineAt - Date.now() - (adapter.id === "command-code" ? COMMAND_CODE_REVALIDATION_RESERVE_MS : 0)
|
|
1907
|
+
);
|
|
1869
1908
|
const report = await queryProviderUsage(
|
|
1870
1909
|
adapter,
|
|
1871
1910
|
auth,
|
|
1872
1911
|
signal,
|
|
1873
|
-
|
|
1912
|
+
queryTimeoutMs,
|
|
1874
1913
|
requiresRequestBoundaryGuard ? guard : void 0,
|
|
1875
1914
|
target.targetId
|
|
1876
1915
|
);
|
|
@@ -2752,6 +2791,7 @@ export {
|
|
|
2752
2791
|
codexFastIsEffective,
|
|
2753
2792
|
codexFastRequestTier,
|
|
2754
2793
|
codexFastStatusLabel,
|
|
2794
|
+
commandCodeOrgId,
|
|
2755
2795
|
consumeCodexResetCredit,
|
|
2756
2796
|
correctCodexFastMessageCost,
|
|
2757
2797
|
createFireworksAdapter,
|
|
@@ -2772,6 +2812,7 @@ export {
|
|
|
2772
2812
|
normalizeBasetenBillingUsagePayload,
|
|
2773
2813
|
normalizeCodexBackendPayload,
|
|
2774
2814
|
normalizeCodexResetCreditsPayload,
|
|
2815
|
+
normalizeCommandCodeUsagePayload,
|
|
2775
2816
|
normalizeDeepSeekBalancePayload,
|
|
2776
2817
|
normalizeFireworksAccountsPayload,
|
|
2777
2818
|
normalizeFireworksBillingSummaryPayload,
|