opencode-quota-gui 1.3.1 → 1.3.2
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 +16 -12
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/card-order.d.ts +2 -0
- package/dist/contracts/card-order.js +2 -2
- package/dist/contracts/card-visibility.d.ts +2 -1
- package/dist/contracts/card-visibility.js +2 -1
- package/dist/contracts/dashboard.d.ts +87 -5
- package/dist/contracts/dashboard.js +10 -0
- package/dist/contracts/dto-guards.d.ts +4 -0
- package/dist/contracts/dto-guards.js +29 -7
- package/dist/contracts/guards.js +3 -1
- package/dist/contracts/identity.d.ts +37 -5
- package/dist/contracts/identity.js +43 -0
- package/dist/contracts/provider-auto-resume.d.ts +9 -0
- package/dist/contracts/provider-auto-resume.js +24 -0
- package/dist/contracts/provider-failure.d.ts +22 -0
- package/dist/contracts/provider-failure.js +25 -1
- package/dist/contracts/row-order.d.ts +13 -0
- package/dist/contracts/row-order.js +34 -0
- package/dist/contracts/row-visibility.d.ts +53 -0
- package/dist/contracts/row-visibility.js +130 -0
- package/dist/data/modelsdev-pricing.min.json +1 -1
- package/dist/data/modelsdev-temporal.min.json +3 -634
- package/dist/gui/aggregation.d.ts +29 -1
- package/dist/gui/aggregation.js +157 -4
- package/dist/gui/analytics-bridge.d.ts +8 -9
- package/dist/gui/analytics-bridge.js +197 -54
- package/dist/gui/analytics-engine.d.ts +7 -15
- package/dist/gui/analytics-engine.js +246 -106
- package/dist/gui/analytics-model.d.ts +7 -0
- package/dist/gui/analytics-model.js +75 -9
- package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
- package/dist/gui/analytics-pricing-upkeep.js +23 -0
- package/dist/gui/analytics-protocol.d.ts +17 -7
- package/dist/gui/analytics-protocol.js +1 -0
- package/dist/gui/analytics-service.d.ts +10 -0
- package/dist/gui/analytics-service.js +30 -9
- package/dist/gui/analytics-state.d.ts +30 -5
- package/dist/gui/analytics-state.js +46 -7
- package/dist/gui/analytics-worker-runtime.d.ts +5 -0
- package/dist/gui/analytics-worker-runtime.js +9 -1
- package/dist/gui/analytics-worker.js +11 -0
- package/dist/gui/config.d.ts +2 -2
- package/dist/gui/config.js +46 -5
- package/dist/gui/identity.d.ts +6 -20
- package/dist/gui/identity.js +6 -54
- package/dist/gui/primary-quota-windows.js +55 -34
- package/dist/gui/provider-cards.d.ts +12 -8
- package/dist/gui/provider-cards.js +12 -53
- package/dist/gui/quota-notification-detector.d.ts +25 -2
- package/dist/gui/quota-notification-detector.js +60 -5
- package/dist/gui/quota-notification-observer.d.ts +1 -1
- package/dist/gui/quota-notification-observer.js +5 -1
- package/dist/gui/quota-observation.d.ts +4 -0
- package/dist/gui/quota-observation.js +18 -0
- package/dist/gui/rpc.js +3 -0
- package/dist/gui/server.js +6 -1
- package/dist/gui/snapshot-service.d.ts +3 -17
- package/dist/gui/snapshot-service.js +159 -9
- package/dist/gui/sources.js +84 -11
- package/dist/gui/temporal-status.d.ts +3 -2
- package/dist/gui/temporal-status.js +10 -6
- package/dist/gui-experimental.cjs +228 -228
- package/dist/lib/accounting-format.d.ts +8 -0
- package/dist/lib/accounting-format.js +12 -2
- package/dist/lib/anthropic-api-auth.d.ts +7 -0
- package/dist/lib/anthropic-api-auth.js +27 -0
- package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
- package/dist/lib/anthropic-api-rate-limits.js +92 -0
- package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
- package/dist/lib/anthropic-oauth-throttle.js +379 -0
- package/dist/lib/anthropic.d.ts +22 -4
- package/dist/lib/anthropic.js +498 -180
- package/dist/lib/cache-observer-ingestion.js +27 -0
- package/dist/lib/cache-observer.d.ts +3 -0
- package/dist/lib/cache-observer.js +9 -3
- package/dist/lib/cli-show.d.ts +5 -0
- package/dist/lib/cli-show.js +16 -5
- package/dist/lib/cli-status.js +3 -6
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.js +64 -2
- package/dist/lib/dashboard-visibility.d.ts +5 -0
- package/dist/lib/dashboard-visibility.js +11 -10
- package/dist/lib/display-sanitize.js +1 -0
- package/dist/lib/entries.d.ts +10 -1
- package/dist/lib/entries.js +4 -0
- package/dist/lib/grouped-entry-normalization.js +1 -1
- package/dist/lib/maintainer-announcements.js +2 -2
- package/dist/lib/modelsdev-pricing.d.ts +74 -2
- package/dist/lib/modelsdev-pricing.js +457 -63
- package/dist/lib/modelsdev-temporal.d.ts +6 -0
- package/dist/lib/modelsdev-temporal.js +16 -2
- package/dist/lib/opencode-config-providers.js +2 -2
- package/dist/lib/opencode-storage.d.ts +20 -0
- package/dist/lib/opencode-storage.js +89 -2
- package/dist/lib/opencode-version-core.d.ts +7 -0
- package/dist/lib/opencode-version-core.js +10 -0
- package/dist/lib/opencode-warming-refresh.d.ts +19 -0
- package/dist/lib/opencode-warming-refresh.js +95 -0
- package/dist/lib/provider-metadata.d.ts +11 -3
- package/dist/lib/provider-metadata.js +20 -2
- package/dist/lib/provider-registration.d.ts +342 -3
- package/dist/lib/provider-registration.js +409 -27
- package/dist/lib/quota-auto-resume.d.ts +74 -0
- package/dist/lib/quota-auto-resume.js +539 -0
- package/dist/lib/quota-command-format.js +22 -9
- package/dist/lib/quota-identity.d.ts +64 -0
- package/dist/lib/quota-identity.js +111 -0
- package/dist/lib/quota-providers.js +2 -2
- package/dist/lib/quota-render-data.js +2 -2
- package/dist/lib/quota-reset-notifications.js +11 -155
- package/dist/lib/quota-retry-wait.d.ts +106 -5
- package/dist/lib/quota-retry-wait.js +301 -34
- package/dist/lib/quota-runtime-context.js +1 -0
- package/dist/lib/quota-state-codec.d.ts +2 -0
- package/dist/lib/quota-state-codec.js +14 -1
- package/dist/lib/quota-state.d.ts +1 -1
- package/dist/lib/quota-state.js +60 -28
- package/dist/lib/quota-stats.d.ts +26 -0
- package/dist/lib/quota-stats.js +19 -1
- package/dist/lib/quota-surface-data.js +18 -3
- package/dist/lib/quota-telemetry.js +2 -2
- package/dist/lib/resolved-auth-identity.d.ts +19 -0
- package/dist/lib/resolved-auth-identity.js +44 -0
- package/dist/lib/state-file-lock.d.ts +26 -0
- package/dist/lib/state-file-lock.js +205 -0
- package/dist/lib/toast-format-grouped.js +7 -4
- package/dist/lib/tui-compact-format.js +29 -16
- package/dist/lib/types.d.ts +20 -0
- package/dist/lib/types.js +4 -1
- package/dist/plugin.js +67 -1
- package/dist/providers/alibaba-coding-plan.js +21 -3
- package/dist/providers/alibaba-token-plan.js +9 -5
- package/dist/providers/anthropic.d.ts +6 -2
- package/dist/providers/anthropic.js +123 -14
- package/dist/providers/chutes.js +2 -0
- package/dist/providers/claude-agent.js +24 -5
- package/dist/providers/copilot.js +5 -4
- package/dist/providers/glm-coding-plan-provider.js +30 -23
- package/dist/providers/ollama-cloud.js +10 -0
- package/dist/providers/openai.js +24 -23
- package/dist/providers/opencode-go.js +7 -6
- package/dist/providers/opencode-zen.js +1 -1
- package/dist/providers/result-helpers.d.ts +4 -2
- package/dist/providers/result-helpers.js +5 -1
- package/dist/providers/synthetic.js +4 -0
- package/dist/providers/xai.js +9 -8
- package/dist/rpc.d.ts +8 -0
- package/dist/rpc.js +15 -2
- package/dist/ui/assets/{index-BcueIm3Z.css → index-6_g1FHs-.css} +1 -1
- package/dist/ui/assets/index-sZnGUuML.js +10 -0
- package/dist/ui/assets/{popover-4bFSvRZ7.js → popover-C4ZLYe9E.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/package.json +3 -3
- package/dist/ui/assets/index-C6qRSoh8.js +0 -10
package/dist/lib/quota-stats.js
CHANGED
|
@@ -4,7 +4,7 @@ import { hasCatalogModel, hasCost, hasModel, hasProvider, isModelsDevProviderId,
|
|
|
4
4
|
import { getTemporalPolicy, resolveTemporalRates } from "./modelsdev-temporal.js";
|
|
5
5
|
import { getOpenCodeDbPath } from "./opencode-db-path.js";
|
|
6
6
|
import { iterAssistantMessages, iterAssistantMessagesForSession, iterAssistantMessagesForSessions, readAllSessionsIndex, SessionNotFoundError, } from "./opencode-storage.js";
|
|
7
|
-
import { addTokenBuckets, emptyTokenBuckets, tokenBucketsFromMessage } from "./token-buckets.js";
|
|
7
|
+
import { addTokenBuckets, emptyTokenBuckets, tokenBucketsFromMessage, totalTokenBuckets, } from "./token-buckets.js";
|
|
8
8
|
import { calculateUsdFromTokenBuckets, splitTokenBucketsByRate, tokenRateCoverage, } from "./token-cost.js";
|
|
9
9
|
// Re-export for consumers
|
|
10
10
|
export { SessionNotFoundError } from "./opencode-storage.js";
|
|
@@ -758,6 +758,24 @@ export function priceTokenBuckets(params) {
|
|
|
758
758
|
},
|
|
759
759
|
};
|
|
760
760
|
}
|
|
761
|
+
/**
|
|
762
|
+
* models.dev remains primary. Only a row whose resolved route has no usable
|
|
763
|
+
* models.dev rates (unknown or unpriced) may use the host-recorded message cost,
|
|
764
|
+
* and only a finite positive value: zero/missing/negative/NaN stays unpriced
|
|
765
|
+
* and is never Free evidence. Partially priced rows keep their models.dev cost.
|
|
766
|
+
*/
|
|
767
|
+
export function priceTokenBucketsWithRecordedCost(params) {
|
|
768
|
+
const outcome = priceTokenBuckets(params);
|
|
769
|
+
if (outcome.status === "priced" || outcome.status === "partial")
|
|
770
|
+
return outcome;
|
|
771
|
+
const recorded = params.recordedCostUsd;
|
|
772
|
+
if (typeof recorded !== "number" || !Number.isFinite(recorded) || recorded <= 0)
|
|
773
|
+
return outcome;
|
|
774
|
+
const recordedTokens = totalTokenBuckets(params.tokens);
|
|
775
|
+
if (!(recordedTokens > 0))
|
|
776
|
+
return outcome;
|
|
777
|
+
return { status: "recorded_cost", costUsd: recorded, recordedTokens };
|
|
778
|
+
}
|
|
761
779
|
function compareSessionCreatedAt(a, b) {
|
|
762
780
|
const aCreated = typeof a.time?.created === "number" && Number.isFinite(a.time.created)
|
|
763
781
|
? a.time.created
|
|
@@ -9,9 +9,10 @@ import { sanitizeDisplayText } from "./display-sanitize.js";
|
|
|
9
9
|
import { formatQuotaRows } from "./format.js";
|
|
10
10
|
import { BUNDLED_MAINTAINER_ANNOUNCEMENTS, formatMaintainerAnnouncementHomeCountLine, getMaintainerAnnouncementsSummary, getMaintainerAnnouncementTargetProviderIds, } from "./maintainer-announcements.js";
|
|
11
11
|
import { getMaintainerAnnouncementsHomeStatePath } from "./private-state-paths.js";
|
|
12
|
-
import {
|
|
12
|
+
import { getQuotaProviderRegistration, normalizeQuotaProviderId } from "./provider-metadata.js";
|
|
13
13
|
import { buildQuotaExport, createExportProviderContext, resolveExportPath, writeQuotaExport, } from "./quota-export.js";
|
|
14
14
|
import { resolveQuotaFormatStyle } from "./quota-format-style.js";
|
|
15
|
+
import { quotaEntryIsHidden } from "./quota-identity.js";
|
|
15
16
|
import { collectConcreteEnabledProviderIds, collectQuotaRenderData, } from "./quota-render-data.js";
|
|
16
17
|
import { formatQuotaResetNotification, observeQuotaResetNotifications, } from "./quota-reset-notifications.js";
|
|
17
18
|
import { createQuotaProviderRuntimeContext, createQuotaRuntimeRequestContext, resolveQuotaRuntimeContext, } from "./quota-runtime-context.js";
|
|
@@ -76,8 +77,22 @@ export async function getQuotaMessage(host, sessionID, surface) {
|
|
|
76
77
|
config.resetNotifications.enabled &&
|
|
77
78
|
result.providerResults.length > 0) {
|
|
78
79
|
try {
|
|
80
|
+
const hiddenCards = config.dashboard.hiddenCards;
|
|
81
|
+
const hiddenRows = config.dashboard.hiddenRows;
|
|
79
82
|
const notices = await observeQuotaResetNotifications({
|
|
80
|
-
providers: result.providerResults
|
|
83
|
+
providers: result.providerResults.map((provider) => ({
|
|
84
|
+
...provider,
|
|
85
|
+
result: {
|
|
86
|
+
...provider.result,
|
|
87
|
+
entries: provider.result.entries.filter((entry) => !quotaEntryIsHidden({
|
|
88
|
+
providerId: provider.providerId,
|
|
89
|
+
result: provider.result,
|
|
90
|
+
entry,
|
|
91
|
+
hiddenCards,
|
|
92
|
+
hiddenRows,
|
|
93
|
+
})),
|
|
94
|
+
},
|
|
95
|
+
})),
|
|
81
96
|
windows: config.resetNotifications.windows,
|
|
82
97
|
});
|
|
83
98
|
resetNotification = formatQuotaResetNotification(notices) ?? undefined;
|
|
@@ -222,7 +237,7 @@ async function getHomeAnnouncementText(runtime) {
|
|
|
222
237
|
const announcements = BUNDLED_MAINTAINER_ANNOUNCEMENTS;
|
|
223
238
|
const targetProviderIds = new Set(getMaintainerAnnouncementTargetProviderIds({ announcements }));
|
|
224
239
|
const announcementProviders = runtime.providers.filter((provider) => {
|
|
225
|
-
const shape =
|
|
240
|
+
const shape = getQuotaProviderRegistration(normalizeQuotaProviderId(provider.id));
|
|
226
241
|
return shape ? targetProviderIds.has(shape.id) : false;
|
|
227
242
|
});
|
|
228
243
|
const providerIds = await collectConcreteEnabledProviderIds({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isPercentEntry } from "./entries.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getQuotaProviderRegistration } from "./provider-metadata.js";
|
|
3
3
|
import { classifyQuotaWindowText } from "./quota-entry-display.js";
|
|
4
4
|
import { QUOTA_PROVIDERS_AGGREGATE_ID } from "./quota-providers.js";
|
|
5
5
|
const METER_NAME = "opencode-quota-gui";
|
|
@@ -32,7 +32,7 @@ function safeProviderAttribute(providerId) {
|
|
|
32
32
|
providerId.startsWith(`${QUOTA_PROVIDERS_AGGREGATE_ID}:`)) {
|
|
33
33
|
return "custom";
|
|
34
34
|
}
|
|
35
|
-
return
|
|
35
|
+
return getQuotaProviderRegistration(providerId)?.id ?? "other";
|
|
36
36
|
}
|
|
37
37
|
function activeProviderId(providerId) {
|
|
38
38
|
return providerId.startsWith(`${QUOTA_PROVIDERS_AGGREGATE_ID}:`)
|
|
@@ -30,6 +30,25 @@ export declare function composeResolvedAuthIdentities(params: {
|
|
|
30
30
|
identities: readonly ResolvedAuthIdentity[];
|
|
31
31
|
qualifiers?: readonly string[];
|
|
32
32
|
}): Promise<ResolvedAuthIdentity | null>;
|
|
33
|
+
/**
|
|
34
|
+
* A process-local identity for platforms without protected identity storage (Windows). The random
|
|
35
|
+
* key never leaves this process, so the value cannot be reproduced after a restart and may only
|
|
36
|
+
* key in-memory retention, never a persisted cache. The principal must be non-secret account
|
|
37
|
+
* evidence; a credential or token is never suitable here.
|
|
38
|
+
*/
|
|
39
|
+
export declare function deriveProcessLocalAuthIdentity(params: {
|
|
40
|
+
providerId: string;
|
|
41
|
+
principal: ResolvedAuthPrincipal;
|
|
42
|
+
qualifiers?: readonly string[];
|
|
43
|
+
}): ResolvedAuthIdentity | null;
|
|
44
|
+
/** Process-local equivalent of `composeResolvedAuthIdentities`; Windows-only, like its inputs. */
|
|
45
|
+
export declare function composeProcessLocalAuthIdentities(params: {
|
|
46
|
+
providerId: string;
|
|
47
|
+
identities: readonly ResolvedAuthIdentity[];
|
|
48
|
+
qualifiers?: readonly string[];
|
|
49
|
+
}): ResolvedAuthIdentity | null;
|
|
50
|
+
/** True for the in-memory-only identity; such a scope must never be persisted. */
|
|
51
|
+
export declare function isProcessLocalResolvedAuthIdentity(value: string): boolean;
|
|
33
52
|
export declare function isResolvedAuthIdentity(value: unknown): value is ResolvedAuthIdentity;
|
|
34
53
|
export declare function __resetResolvedAuthIdentityForTests(): void;
|
|
35
54
|
export {};
|
|
@@ -7,6 +7,9 @@ const RESOLVED_AUTH_KEY_FILENAME = "resolved-auth-key-v1";
|
|
|
7
7
|
const RESOLVED_AUTH_KEY_PREFIX = "v1:";
|
|
8
8
|
const RESOLVED_AUTH_KEY_BYTES = 32;
|
|
9
9
|
const RESOLVED_AUTH_IDENTITY_PREFIX = "rai1_";
|
|
10
|
+
const PROCESS_LOCAL_AUTH_IDENTITY_PREFIX = "rai1p_";
|
|
11
|
+
/** Per-process key for platforms with no protected identity storage. It never leaves memory. */
|
|
12
|
+
const PROCESS_LOCAL_IDENTITY_KEY = randomBytes(RESOLVED_AUTH_KEY_BYTES);
|
|
10
13
|
const WINNER_READ_ATTEMPTS = 20;
|
|
11
14
|
const WINNER_READ_DELAY_MS = 5;
|
|
12
15
|
const resolvedAuthIdentityBrand = Symbol("ResolvedAuthIdentity");
|
|
@@ -182,6 +185,47 @@ export async function composeResolvedAuthIdentities(params) {
|
|
|
182
185
|
params.qualifiers ?? [],
|
|
183
186
|
]);
|
|
184
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* A process-local identity for platforms without protected identity storage (Windows). The random
|
|
190
|
+
* key never leaves this process, so the value cannot be reproduced after a restart and may only
|
|
191
|
+
* key in-memory retention, never a persisted cache. The principal must be non-secret account
|
|
192
|
+
* evidence; a credential or token is never suitable here.
|
|
193
|
+
*/
|
|
194
|
+
export function deriveProcessLocalAuthIdentity(params) {
|
|
195
|
+
if (process.platform !== "win32")
|
|
196
|
+
return null;
|
|
197
|
+
const value = params.principal.value.trim();
|
|
198
|
+
if (!params.providerId || !value)
|
|
199
|
+
return null;
|
|
200
|
+
return `${PROCESS_LOCAL_AUTH_IDENTITY_PREFIX}${createHmac("sha256", PROCESS_LOCAL_IDENTITY_KEY)
|
|
201
|
+
.update(identityPayload([
|
|
202
|
+
"process-local",
|
|
203
|
+
params.providerId,
|
|
204
|
+
params.principal.kind,
|
|
205
|
+
value,
|
|
206
|
+
params.qualifiers ?? [],
|
|
207
|
+
]))
|
|
208
|
+
.digest("base64url")}`;
|
|
209
|
+
}
|
|
210
|
+
/** Process-local equivalent of `composeResolvedAuthIdentities`; Windows-only, like its inputs. */
|
|
211
|
+
export function composeProcessLocalAuthIdentities(params) {
|
|
212
|
+
if (process.platform !== "win32")
|
|
213
|
+
return null;
|
|
214
|
+
if (!params.providerId || params.identities.length === 0)
|
|
215
|
+
return null;
|
|
216
|
+
return `${PROCESS_LOCAL_AUTH_IDENTITY_PREFIX}${createHmac("sha256", PROCESS_LOCAL_IDENTITY_KEY)
|
|
217
|
+
.update(identityPayload([
|
|
218
|
+
"process-local-composition",
|
|
219
|
+
params.providerId,
|
|
220
|
+
[...params.identities],
|
|
221
|
+
params.qualifiers ?? [],
|
|
222
|
+
]))
|
|
223
|
+
.digest("base64url")}`;
|
|
224
|
+
}
|
|
225
|
+
/** True for the in-memory-only identity; such a scope must never be persisted. */
|
|
226
|
+
export function isProcessLocalResolvedAuthIdentity(value) {
|
|
227
|
+
return value.startsWith(PROCESS_LOCAL_AUTH_IDENTITY_PREFIX);
|
|
228
|
+
}
|
|
185
229
|
export function isResolvedAuthIdentity(value) {
|
|
186
230
|
return (typeof value === "string" &&
|
|
187
231
|
new RegExp(`^${RESOLVED_AUTH_IDENTITY_PREFIX}[A-Za-z0-9_-]{43}$`, "u").test(value));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface StateFileLockOptions {
|
|
2
|
+
/** Give up after this long and throw; callers that must not block skip. */
|
|
3
|
+
timeoutMs?: number;
|
|
4
|
+
retryDelayMs?: number;
|
|
5
|
+
/** A lock directory/owner this old without a live process is reclaimable. */
|
|
6
|
+
staleMs?: number;
|
|
7
|
+
/**
|
|
8
|
+
* A still-live owner older than this bound is reclaimable because the PID may
|
|
9
|
+
* have been reused by another process. A fresh live owner is never reclaimed.
|
|
10
|
+
*/
|
|
11
|
+
liveOwnerMaxAgeMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Release retries a transient removal failure; a permanent failure is surfaced. */
|
|
14
|
+
export declare function removeStateLockWithRetry(lockPath: string, options?: {
|
|
15
|
+
attempts?: number;
|
|
16
|
+
retryDelayMs?: number;
|
|
17
|
+
remove?: (path: string) => Promise<void>;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Cross-process state-file lock: a lock directory next to the state file with a
|
|
21
|
+
* PID/token owner. A dead owner or an ownerless lock older than `staleMs` is
|
|
22
|
+
* reclaimed through a second exclusive file. Throws when the timeout expires so
|
|
23
|
+
* callers that must stay responsive can catch it and skip the work.
|
|
24
|
+
*/
|
|
25
|
+
export declare function acquireStateFileLock(statePath: string, options?: StateFileLockOptions): Promise<() => Promise<void>>;
|
|
26
|
+
//# sourceMappingURL=state-file-lock.d.ts.map
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { mkdir, open, readFile, rm, rmdir, stat, unlink } from "node:fs/promises";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
const DEFAULT_LOCK_RETRY_DELAY_MS = 20;
|
|
6
|
+
const DEFAULT_LOCK_TIMEOUT_MS = 2_000;
|
|
7
|
+
const DEFAULT_STALE_LOCK_AGE_MS = 30_000;
|
|
8
|
+
const DEFAULT_RELEASE_ATTEMPTS = 3;
|
|
9
|
+
const DEFAULT_RELEASE_RETRY_DELAY_MS = 10;
|
|
10
|
+
const LOCK_OWNER_FILE = "owner.json";
|
|
11
|
+
const LOCK_RECLAIM_FILE = "reclaim";
|
|
12
|
+
function isFileSystemError(error, code) {
|
|
13
|
+
return error?.code === code;
|
|
14
|
+
}
|
|
15
|
+
function delay(ms) {
|
|
16
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
function parseLockOwner(value) {
|
|
19
|
+
try {
|
|
20
|
+
const owner = JSON.parse(value);
|
|
21
|
+
if (typeof owner.token !== "string" ||
|
|
22
|
+
!Number.isSafeInteger(owner.pid) ||
|
|
23
|
+
(owner.pid ?? 0) <= 0 ||
|
|
24
|
+
!Number.isFinite(owner.createdAtMs)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return owner;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function readLockOwner(lockPath) {
|
|
34
|
+
try {
|
|
35
|
+
return parseLockOwner(await readFile(join(lockPath, LOCK_OWNER_FILE), "utf8"));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (isFileSystemError(error, "ENOENT"))
|
|
39
|
+
return null;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isProcessAlive(pid) {
|
|
44
|
+
try {
|
|
45
|
+
process.kill(pid, 0);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return !isFileSystemError(error, "ESRCH");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function ownerReclaimable(owner, nowMs, liveOwnerMaxAgeMs) {
|
|
53
|
+
if (!isProcessAlive(owner.pid))
|
|
54
|
+
return true;
|
|
55
|
+
// PID reuse can leave a dead claim looking alive. A bound older than the
|
|
56
|
+
// longest possible attempt is reclaimable; a fresh live claim never is.
|
|
57
|
+
return liveOwnerMaxAgeMs !== undefined && nowMs - owner.createdAtMs > liveOwnerMaxAgeMs;
|
|
58
|
+
}
|
|
59
|
+
async function getReclaimStatus(lockPath, staleMs, liveOwnerMaxAgeMs) {
|
|
60
|
+
const owner = await readLockOwner(lockPath);
|
|
61
|
+
if (owner) {
|
|
62
|
+
return {
|
|
63
|
+
reclaimable: ownerReclaimable(owner, Date.now(), liveOwnerMaxAgeMs),
|
|
64
|
+
allowMissingOwner: false,
|
|
65
|
+
ownerToken: owner.token,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const lock = await stat(lockPath);
|
|
70
|
+
const stale = Date.now() - lock.mtimeMs > staleMs;
|
|
71
|
+
return { reclaimable: stale, allowMissingOwner: stale };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (isFileSystemError(error, "ENOENT")) {
|
|
75
|
+
return { reclaimable: true, allowMissingOwner: true };
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function clearReclaimMarker(reclaimPath) {
|
|
81
|
+
await unlink(reclaimPath).catch((error) => {
|
|
82
|
+
if (!isFileSystemError(error, "ENOENT"))
|
|
83
|
+
throw error;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async function tryReclaimStateLock(lockPath, status, staleMs, liveOwnerMaxAgeMs) {
|
|
87
|
+
const reclaimPath = join(lockPath, LOCK_RECLAIM_FILE);
|
|
88
|
+
/**
|
|
89
|
+
* Ownership fence: the owner observed before the reclaim attempt must still
|
|
90
|
+
* be the same owner and still reclaimable. A new owner (different token) is
|
|
91
|
+
* never removed.
|
|
92
|
+
*/
|
|
93
|
+
const ownerStillMatches = (owner) => status.ownerToken !== undefined
|
|
94
|
+
? owner?.token === status.ownerToken && ownerReclaimable(owner, Date.now(), liveOwnerMaxAgeMs)
|
|
95
|
+
: owner === null && status.allowMissingOwner;
|
|
96
|
+
try {
|
|
97
|
+
const handle = await open(reclaimPath, "wx", 0o600);
|
|
98
|
+
await handle.close();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (isFileSystemError(error, "ENOENT"))
|
|
102
|
+
return true;
|
|
103
|
+
if (!isFileSystemError(error, "EEXIST"))
|
|
104
|
+
throw error;
|
|
105
|
+
try {
|
|
106
|
+
const reclaim = await stat(reclaimPath);
|
|
107
|
+
if (Date.now() - reclaim.mtimeMs <= staleMs)
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
catch (statError) {
|
|
111
|
+
if (isFileSystemError(statError, "ENOENT"))
|
|
112
|
+
return false;
|
|
113
|
+
throw statError;
|
|
114
|
+
}
|
|
115
|
+
const owner = await readLockOwner(lockPath);
|
|
116
|
+
if (!ownerStillMatches(owner)) {
|
|
117
|
+
await clearReclaimMarker(reclaimPath);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
await rm(lockPath, { recursive: true, force: true });
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
const owner = await readLockOwner(lockPath);
|
|
124
|
+
if (ownerStillMatches(owner)) {
|
|
125
|
+
await rm(lockPath, { recursive: true, force: true });
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
await clearReclaimMarker(reclaimPath);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
/** Release retries a transient removal failure; a permanent failure is surfaced. */
|
|
132
|
+
export async function removeStateLockWithRetry(lockPath, options = {}) {
|
|
133
|
+
const attempts = Math.max(1, options.attempts ?? DEFAULT_RELEASE_ATTEMPTS);
|
|
134
|
+
const retryDelayMs = options.retryDelayMs ?? DEFAULT_RELEASE_RETRY_DELAY_MS;
|
|
135
|
+
const remove = options.remove ?? ((path) => rm(path, { recursive: true, force: true }));
|
|
136
|
+
for (let attempt = 1;; attempt += 1) {
|
|
137
|
+
try {
|
|
138
|
+
await remove(lockPath);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (attempt >= attempts)
|
|
143
|
+
throw error;
|
|
144
|
+
await delay(retryDelayMs);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Cross-process state-file lock: a lock directory next to the state file with a
|
|
150
|
+
* PID/token owner. A dead owner or an ownerless lock older than `staleMs` is
|
|
151
|
+
* reclaimed through a second exclusive file. Throws when the timeout expires so
|
|
152
|
+
* callers that must stay responsive can catch it and skip the work.
|
|
153
|
+
*/
|
|
154
|
+
export async function acquireStateFileLock(statePath, options = {}) {
|
|
155
|
+
const retryDelayMs = options.retryDelayMs ?? DEFAULT_LOCK_RETRY_DELAY_MS;
|
|
156
|
+
const staleMs = options.staleMs ?? DEFAULT_STALE_LOCK_AGE_MS;
|
|
157
|
+
const liveOwnerMaxAgeMs = options.liveOwnerMaxAgeMs;
|
|
158
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_LOCK_TIMEOUT_MS;
|
|
159
|
+
await mkdir(dirname(statePath), { recursive: true, mode: 0o700 });
|
|
160
|
+
const lockPath = `${statePath}.lock`;
|
|
161
|
+
const token = randomUUID();
|
|
162
|
+
const deadline = Date.now() + timeoutMs;
|
|
163
|
+
while (true) {
|
|
164
|
+
try {
|
|
165
|
+
await mkdir(lockPath, { mode: 0o700 });
|
|
166
|
+
const owner = { token, pid: process.pid, createdAtMs: Date.now() };
|
|
167
|
+
try {
|
|
168
|
+
writeFileSync(join(lockPath, LOCK_OWNER_FILE), JSON.stringify(owner), {
|
|
169
|
+
flag: "wx",
|
|
170
|
+
mode: 0o600,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
await rmdir(lockPath).catch(() => undefined);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
return async () => {
|
|
178
|
+
let currentOwner;
|
|
179
|
+
try {
|
|
180
|
+
currentOwner = await readLockOwner(lockPath);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
currentOwner = null;
|
|
184
|
+
}
|
|
185
|
+
if (currentOwner?.token !== token)
|
|
186
|
+
return;
|
|
187
|
+
await removeStateLockWithRetry(lockPath);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (!isFileSystemError(error, "EEXIST"))
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
const status = await getReclaimStatus(lockPath, staleMs, liveOwnerMaxAgeMs);
|
|
195
|
+
if (status.reclaimable &&
|
|
196
|
+
(await tryReclaimStateLock(lockPath, status, staleMs, liveOwnerMaxAgeMs))) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (Date.now() >= deadline) {
|
|
200
|
+
throw new Error(`Timed out acquiring state file lock: ${lockPath}`);
|
|
201
|
+
}
|
|
202
|
+
await delay(retryDelayMs);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=state-file-lock.js.map
|
|
@@ -31,8 +31,6 @@ function extractWindowLabel(text) {
|
|
|
31
31
|
return kind ? GROUPED_WINDOW_LABELS[kind] : null;
|
|
32
32
|
}
|
|
33
33
|
function resolveGroupedRowLabel(entry, semanticLabel) {
|
|
34
|
-
if (entry.semantic)
|
|
35
|
-
return semanticLabel;
|
|
36
34
|
const rawLabel = normalizeLabelText(entry.label);
|
|
37
35
|
const fromLabel = extractWindowLabel(rawLabel);
|
|
38
36
|
if (fromLabel)
|
|
@@ -45,9 +43,12 @@ function resolveGroupedRowLabel(entry, semanticLabel) {
|
|
|
45
43
|
return fromMetricLabel;
|
|
46
44
|
if (metricLabel)
|
|
47
45
|
return metricLabel;
|
|
48
|
-
const fromName = extractWindowLabel(entry.name);
|
|
46
|
+
const fromName = entry.semantic ? null : extractWindowLabel(entry.name);
|
|
49
47
|
if (fromName)
|
|
50
48
|
return fromName;
|
|
49
|
+
const fromSemantic = normalizeLabelText(semanticLabel);
|
|
50
|
+
if (fromSemantic)
|
|
51
|
+
return fromSemantic;
|
|
51
52
|
return normalizeLabelText(entry.group) || "Quota window";
|
|
52
53
|
}
|
|
53
54
|
export function formatQuotaRowsGrouped(params) {
|
|
@@ -101,7 +102,9 @@ export function formatQuotaRowsGrouped(params) {
|
|
|
101
102
|
const right = entry.right ? entry.right.trim() : "";
|
|
102
103
|
if (interpretation.display.kind === "value") {
|
|
103
104
|
const isAtomicValue = interpretation.display.entryKind !== "value";
|
|
104
|
-
const label = entry.semantic
|
|
105
|
+
const label = entry.semantic
|
|
106
|
+
? normalizeLabelText(interpretation.label) || entry.name
|
|
107
|
+
: entry.label?.trim() || entry.name;
|
|
105
108
|
const isRedundantLabel = !entry.semantic &&
|
|
106
109
|
!entry.label &&
|
|
107
110
|
Boolean(label &&
|
|
@@ -93,7 +93,7 @@ function formatCompactPercentGroupSegment(group, windows = group.windows) {
|
|
|
93
93
|
const separator = windows.every((window) => window.label && !window.isWindow) ? ": " : " ";
|
|
94
94
|
return compactText(`${group.provider}${separator}${summary}`);
|
|
95
95
|
}
|
|
96
|
-
function buildSemanticCandidate(entry, percentDisplayMode, accountingDetail, resetTimeSpaced) {
|
|
96
|
+
function buildSemanticCandidate(entry, order, percentDisplayMode, accountingDetail, resetTimeSpaced) {
|
|
97
97
|
if (!entry.semantic)
|
|
98
98
|
return null;
|
|
99
99
|
const shouldRequestBasis = accountingDetail === "detailed" &&
|
|
@@ -113,8 +113,10 @@ function buildSemanticCandidate(entry, percentDisplayMode, accountingDetail, res
|
|
|
113
113
|
if (!value)
|
|
114
114
|
return null;
|
|
115
115
|
const provider = getProviderName(entry);
|
|
116
|
-
const
|
|
117
|
-
const
|
|
116
|
+
const hasExplicitLabel = Boolean(entry.label?.trim() || entry.metricLabel?.trim());
|
|
117
|
+
const explicitLabel = hasExplicitLabel ? getWindowLabel(entry) : null;
|
|
118
|
+
const label = explicitLabel ? explicitLabel.text : compactText(interpretation.label);
|
|
119
|
+
const prefix = compactText([provider, label].filter(Boolean).join(explicitLabel?.isWindow ? " " : ": "));
|
|
118
120
|
const runway = isPercentEntry(entry) ? formatQuotaRunway(entry.runway) : "";
|
|
119
121
|
const displayValue = compactText([
|
|
120
122
|
value,
|
|
@@ -133,6 +135,7 @@ function buildSemanticCandidate(entry, percentDisplayMode, accountingDetail, res
|
|
|
133
135
|
return {
|
|
134
136
|
segment,
|
|
135
137
|
prominence: entry.semantic.prominence === "supplementary" ? 1 : 0,
|
|
138
|
+
order,
|
|
136
139
|
providerKey: provider.toLowerCase(),
|
|
137
140
|
...(isPercentEntry(entry) && entry.runway ? { runway: entry.runway } : {}),
|
|
138
141
|
...(detail ? { detail } : {}),
|
|
@@ -145,9 +148,9 @@ function formatCompactEntryCandidates(params) {
|
|
|
145
148
|
const semantic = [];
|
|
146
149
|
const groups = new Map();
|
|
147
150
|
const pendingLegacy = [];
|
|
148
|
-
for (const entry of params.entries) {
|
|
151
|
+
for (const [index, entry] of params.entries.entries()) {
|
|
149
152
|
if (entry.semantic) {
|
|
150
|
-
const candidate = buildSemanticCandidate(entry, params.percentDisplayMode, params.accountingDetail, params.resetTimeSpaced);
|
|
153
|
+
const candidate = buildSemanticCandidate(entry, index, params.percentDisplayMode, params.accountingDetail, params.resetTimeSpaced);
|
|
151
154
|
if (candidate)
|
|
152
155
|
semantic.push(candidate);
|
|
153
156
|
continue;
|
|
@@ -155,7 +158,12 @@ function formatCompactEntryCandidates(params) {
|
|
|
155
158
|
if (isValueEntry(entry)) {
|
|
156
159
|
const segment = formatCompactValueEntrySegment(entry, params.resetTimeSpaced);
|
|
157
160
|
if (segment) {
|
|
158
|
-
pendingLegacy.push({
|
|
161
|
+
pendingLegacy.push({
|
|
162
|
+
kind: "value",
|
|
163
|
+
segment,
|
|
164
|
+
provider: getProviderName(entry),
|
|
165
|
+
order: index,
|
|
166
|
+
});
|
|
159
167
|
}
|
|
160
168
|
continue;
|
|
161
169
|
}
|
|
@@ -174,7 +182,7 @@ function formatCompactEntryCandidates(params) {
|
|
|
174
182
|
const key = provider.toLowerCase();
|
|
175
183
|
let group = groups.get(key);
|
|
176
184
|
if (!group) {
|
|
177
|
-
group = { provider, windows: [] };
|
|
185
|
+
group = { provider, order: index, windows: [] };
|
|
178
186
|
groups.set(key, group);
|
|
179
187
|
pendingLegacy.push({ kind: "percent", key });
|
|
180
188
|
}
|
|
@@ -191,6 +199,7 @@ function formatCompactEntryCandidates(params) {
|
|
|
191
199
|
return {
|
|
192
200
|
segment: pending.segment,
|
|
193
201
|
prominence: 0,
|
|
202
|
+
order: pending.order,
|
|
194
203
|
providerKey: pending.provider.toLowerCase(),
|
|
195
204
|
};
|
|
196
205
|
}
|
|
@@ -213,6 +222,7 @@ function formatCompactEntryCandidates(params) {
|
|
|
213
222
|
return {
|
|
214
223
|
segment,
|
|
215
224
|
prominence: 0,
|
|
225
|
+
order: group.order,
|
|
216
226
|
providerKey: group.provider.toLowerCase(),
|
|
217
227
|
...(fallbackSegment && fallbackSegment !== segment && fallbackValue
|
|
218
228
|
? {
|
|
@@ -224,10 +234,7 @@ function formatCompactEntryCandidates(params) {
|
|
|
224
234
|
};
|
|
225
235
|
})
|
|
226
236
|
.filter((candidate) => Boolean(candidate));
|
|
227
|
-
return [...legacy, ...semantic]
|
|
228
|
-
.map((candidate, index) => ({ candidate, index }))
|
|
229
|
-
.sort((left, right) => left.candidate.prominence - right.candidate.prominence || left.index - right.index)
|
|
230
|
-
.map(({ candidate }) => candidate);
|
|
237
|
+
return [...legacy, ...semantic].sort((left, right) => left.prominence - right.prominence || left.order - right.order);
|
|
231
238
|
}
|
|
232
239
|
function fitAtomicCandidate(atomic, maxWidth) {
|
|
233
240
|
if (atomic.value.length > maxWidth)
|
|
@@ -373,7 +380,7 @@ function applyProviderOverflow(admitted, candidates, maxWidth) {
|
|
|
373
380
|
return current;
|
|
374
381
|
const withOverflow = (items, count) => [
|
|
375
382
|
...items,
|
|
376
|
-
{ segment: formatProviderOverflow(count), prominence: 0 },
|
|
383
|
+
{ segment: formatProviderOverflow(count), prominence: 0, order: Number.MAX_SAFE_INTEGER },
|
|
377
384
|
];
|
|
378
385
|
if (joinCompactSegments(withOverflow(current, omitted)).length <= maxWidth) {
|
|
379
386
|
return withOverflow(current, omitted);
|
|
@@ -400,12 +407,14 @@ function applyProviderOverflow(admitted, candidates, maxWidth) {
|
|
|
400
407
|
if (truncated) {
|
|
401
408
|
return [
|
|
402
409
|
{ ...first, segment: truncated },
|
|
403
|
-
{ segment: overflowText, prominence: 0 },
|
|
410
|
+
{ segment: overflowText, prominence: 0, order: Number.MAX_SAFE_INTEGER },
|
|
404
411
|
];
|
|
405
412
|
}
|
|
406
413
|
}
|
|
407
414
|
}
|
|
408
|
-
return overflowText.length <= maxWidth
|
|
415
|
+
return overflowText.length <= maxWidth
|
|
416
|
+
? [{ segment: overflowText, prominence: 0, order: Number.MAX_SAFE_INTEGER }]
|
|
417
|
+
: admitted;
|
|
409
418
|
}
|
|
410
419
|
function formatIssueCount(count) {
|
|
411
420
|
return `+${count} issue${count === 1 ? "" : "s"}`;
|
|
@@ -434,7 +443,11 @@ export function buildCompactQuotaStatusLine(params) {
|
|
|
434
443
|
});
|
|
435
444
|
const sessionTokensSegment = formatCompactSessionTokensSegment(data);
|
|
436
445
|
if (sessionTokensSegment) {
|
|
437
|
-
candidates.push({
|
|
446
|
+
candidates.push({
|
|
447
|
+
segment: sessionTokensSegment,
|
|
448
|
+
prominence: 0,
|
|
449
|
+
order: Number.MAX_SAFE_INTEGER,
|
|
450
|
+
});
|
|
438
451
|
}
|
|
439
452
|
const admitted = applyProviderOverflow(admitCompactCandidates(candidates, maxWidth), candidates, maxWidth);
|
|
440
453
|
const issues = data.errors.filter((error) => error.kind !== "intentional-filter");
|
|
@@ -449,7 +462,7 @@ export function buildCompactQuotaStatusLine(params) {
|
|
|
449
462
|
const issueSegment = formatIssueCount(issues.length);
|
|
450
463
|
const candidate = [...admitted.map((item) => item.segment), issueSegment].join(COMPACT_SEGMENT_SEPARATOR);
|
|
451
464
|
if (candidate.length <= maxWidth) {
|
|
452
|
-
admitted.push({ segment: issueSegment, prominence: 0 });
|
|
465
|
+
admitted.push({ segment: issueSegment, prominence: 0, order: Number.MAX_SAFE_INTEGER });
|
|
453
466
|
}
|
|
454
467
|
}
|
|
455
468
|
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -119,6 +119,13 @@ export interface QuotaDashboardConfig {
|
|
|
119
119
|
* only; providerOrder remains the legacy fallback when this is empty.
|
|
120
120
|
*/
|
|
121
121
|
cardOrder: string[];
|
|
122
|
+
/**
|
|
123
|
+
* Sparse per-card row display order: opaque card id -> ordered opaque row
|
|
124
|
+
* ids. A card absent from this map keeps provider emission order. Listed
|
|
125
|
+
* rows come first in saved order, and every unlisted/new row keeps emission
|
|
126
|
+
* order after them. Display order only; hiding stays in `hiddenRows`.
|
|
127
|
+
*/
|
|
128
|
+
rowOrder: Record<string, string[]>;
|
|
122
129
|
/**
|
|
123
130
|
* Explicit temporal chip visibility per provider. Sparse by design: an
|
|
124
131
|
* absent provider follows account discovery, while a present boolean keeps
|
|
@@ -192,6 +199,12 @@ export interface QuotaToastConfig {
|
|
|
192
199
|
/** Whether exact multi-unit reset countdowns include spaces between units. Defaults to true. */
|
|
193
200
|
resetTimeSpaced?: boolean;
|
|
194
201
|
minIntervalMs: number;
|
|
202
|
+
/**
|
|
203
|
+
* Minimum spacing between Anthropic OAuth usage requests for Claude Agent,
|
|
204
|
+
* shared by every OpenCode process. Defaults to three minutes; never below
|
|
205
|
+
* one minute.
|
|
206
|
+
*/
|
|
207
|
+
claudeAgentPollIntervalMs: number;
|
|
195
208
|
/** Request timeout in milliseconds for remote provider API calls. */
|
|
196
209
|
requestTimeoutMs: number;
|
|
197
210
|
/**
|
|
@@ -243,6 +256,13 @@ export interface QuotaToastConfig {
|
|
|
243
256
|
* model's provider resets, instead of OpenCode's normal retry timing.
|
|
244
257
|
*/
|
|
245
258
|
waitForQuotaReset: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* If true, a session that terminally failed on a provider quota limit gets one `continue`
|
|
261
|
+
* prompt after the failed account's exhausted quota window is observed as reset and the
|
|
262
|
+
* session has stayed inactive for two minutes. Off by default; pending resumes are lost when
|
|
263
|
+
* the plugin process restarts.
|
|
264
|
+
*/
|
|
265
|
+
autoResumeOnQuotaRecovery: boolean;
|
|
246
266
|
/**
|
|
247
267
|
* If true, show the Session input/output tokens section in quota displays when session token data is available.
|
|
248
268
|
* "allWindows" keeps per-model rows on toast + sidebar; "singleWindow"
|
package/dist/lib/types.js
CHANGED
|
@@ -37,6 +37,7 @@ export const DEFAULT_CONFIG = {
|
|
|
37
37
|
accountingDetail: "summary",
|
|
38
38
|
resetTimeSpaced: true,
|
|
39
39
|
minIntervalMs: 60000, // 1 minute
|
|
40
|
+
claudeAgentPollIntervalMs: 180000, // 3 minutes; shared by every OpenCode process
|
|
40
41
|
requestTimeoutMs: REQUEST_TIMEOUT_MS,
|
|
41
42
|
debug: false,
|
|
42
43
|
// Providers are auto-detected by default; set to explicit list to opt-in manually.
|
|
@@ -48,7 +49,7 @@ export const DEFAULT_CONFIG = {
|
|
|
48
49
|
opencodeMonthlyLimit: undefined,
|
|
49
50
|
pricingSnapshot: {
|
|
50
51
|
source: "auto",
|
|
51
|
-
autoRefresh:
|
|
52
|
+
autoRefresh: 1,
|
|
52
53
|
},
|
|
53
54
|
showOnIdle: true,
|
|
54
55
|
showOnQuestion: true,
|
|
@@ -57,6 +58,7 @@ export const DEFAULT_CONFIG = {
|
|
|
57
58
|
toastDurationMs: 9000,
|
|
58
59
|
onlyCurrentModel: false,
|
|
59
60
|
waitForQuotaReset: true,
|
|
61
|
+
autoResumeOnQuotaRecovery: false,
|
|
60
62
|
showSessionTokens: true,
|
|
61
63
|
sessionTokenScope: "current",
|
|
62
64
|
tuiSidebarPanel: {
|
|
@@ -91,6 +93,7 @@ export const DEFAULT_CONFIG = {
|
|
|
91
93
|
hiddenRows: [],
|
|
92
94
|
providerOrder: [],
|
|
93
95
|
cardOrder: [],
|
|
96
|
+
rowOrder: {},
|
|
94
97
|
temporalProviderOverrides: {},
|
|
95
98
|
},
|
|
96
99
|
layout: {
|