opencode-quota-gui 1.3.0 → 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 +34 -20
- package/dist/bin/opencode-quota-gui.js +0 -0
- 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 +95 -6
- package/dist/contracts/dashboard.js +10 -0
- package/dist/contracts/dto-guards.d.ts +4 -0
- package/dist/contracts/dto-guards.js +31 -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/openai-quota.d.ts +3 -0
- package/dist/contracts/openai-quota.js +3 -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 +60 -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 +3 -3
- package/dist/gui/config.js +77 -7
- package/dist/gui/identity.d.ts +6 -20
- package/dist/gui/identity.js +6 -54
- package/dist/gui/lifecycle.d.ts +5 -3
- package/dist/gui/lifecycle.js +3 -3
- package/dist/gui/primary-quota-windows.js +67 -44
- package/dist/gui/provider-cards.d.ts +20 -8
- package/dist/gui/provider-cards.js +42 -55
- package/dist/gui/quota-notification-detector.d.ts +29 -6
- package/dist/gui/quota-notification-detector.js +136 -47
- package/dist/gui/quota-notification-observer.d.ts +3 -4
- package/dist/gui/quota-notification-observer.js +73 -20
- package/dist/gui/quota-observation.d.ts +4 -0
- package/dist/gui/quota-observation.js +18 -0
- package/dist/gui/rpc.d.ts +2 -0
- package/dist/gui/rpc.js +14 -3
- package/dist/gui/server.js +17 -3
- package/dist/gui/snapshot-service.d.ts +3 -15
- package/dist/gui/snapshot-service.js +281 -23
- package/dist/gui/sources.js +179 -64
- package/dist/gui/temporal-status.d.ts +3 -2
- package/dist/gui/temporal-status.js +10 -6
- package/dist/gui-experimental.cjs +230 -225
- package/dist/lib/accounting-format.d.ts +8 -0
- package/dist/lib/accounting-format.js +20 -2
- package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
- package/dist/lib/alibaba-coding-plan-cli.js +539 -0
- 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-auth.d.ts +2 -3
- package/dist/lib/anthropic-auth.js +2 -3
- 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 +68 -14
- package/dist/lib/anthropic.js +1016 -363
- package/dist/lib/api-key-retry-after.d.ts +7 -0
- package/dist/lib/api-key-retry-after.js +62 -0
- package/dist/lib/atomic-json.d.ts +2 -0
- package/dist/lib/atomic-json.js +1 -0
- package/dist/lib/cache-observer-ingestion.d.ts +90 -0
- package/dist/lib/cache-observer-ingestion.js +1008 -0
- package/dist/lib/cache-observer.d.ts +141 -0
- package/dist/lib/cache-observer.js +323 -0
- package/dist/lib/canonical-config-lock.d.ts +9 -0
- package/dist/lib/canonical-config-lock.js +36 -0
- package/dist/lib/chutes.js +62 -51
- package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
- package/dist/lib/claude-agent-transcript-ttl.js +154 -0
- package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
- package/dist/lib/claude-agent-ttl-tracker.js +152 -0
- package/dist/lib/cli-show.d.ts +5 -0
- package/dist/lib/cli-show.js +21 -8
- package/dist/lib/cli-status.js +3 -6
- package/dist/lib/config-write-target.d.ts +1 -1
- package/dist/lib/config-write-target.js +5 -2
- package/dist/lib/config.d.ts +2 -1
- package/dist/lib/config.js +257 -4
- package/dist/lib/copilot.js +171 -86
- package/dist/lib/dashboard-visibility.d.ts +5 -0
- package/dist/lib/dashboard-visibility.js +11 -10
- package/dist/lib/dashboard-web-policy.d.ts +4 -4
- package/dist/lib/dashboard-web-policy.js +2 -2
- package/dist/lib/deepseek.js +25 -13
- package/dist/lib/display-sanitize.js +2 -0
- package/dist/lib/entries.d.ts +33 -1
- package/dist/lib/entries.js +6 -0
- package/dist/lib/glm-coding-plan.js +98 -74
- package/dist/lib/google-agy.js +90 -12
- package/dist/lib/google-gemini-cli.js +84 -11
- package/dist/lib/grouped-entry-normalization.js +1 -1
- package/dist/lib/http.d.ts +4 -0
- package/dist/lib/http.js +16 -2
- package/dist/lib/init-installer.js +5 -3
- package/dist/lib/kilo.js +37 -18
- package/dist/lib/kimi.js +35 -18
- package/dist/lib/maintainer-announcements.js +2 -2
- package/dist/lib/mimo.d.ts +2 -0
- package/dist/lib/mimo.js +36 -0
- 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/nanogpt.d.ts +1 -0
- package/dist/lib/nanogpt.js +26 -3
- package/dist/lib/ollama-cloud.d.ts +1 -1
- package/dist/lib/ollama-cloud.js +48 -35
- package/dist/lib/openai.js +84 -38
- package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
- package/dist/lib/opencode-auth-sqlite.js +2 -2
- package/dist/lib/opencode-config-editor.d.ts +1 -0
- package/dist/lib/opencode-config-editor.js +6 -1
- package/dist/lib/opencode-config-providers.js +2 -2
- package/dist/lib/opencode-go.js +29 -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 +30 -0
- package/dist/lib/opencode-version-core.js +59 -0
- package/dist/lib/opencode-version.d.ts +2 -22
- package/dist/lib/opencode-version.js +4 -48
- package/dist/lib/opencode-warming-refresh.d.ts +19 -0
- package/dist/lib/opencode-warming-refresh.js +95 -0
- package/dist/lib/opencode-zen.d.ts +3 -0
- package/dist/lib/opencode-zen.js +71 -5
- package/dist/lib/provider-add.js +5 -2
- package/dist/lib/provider-metadata.d.ts +11 -3
- package/dist/lib/provider-metadata.js +20 -2
- package/dist/lib/provider-registration.d.ts +358 -9
- package/dist/lib/provider-registration.js +423 -30
- 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 +23 -10
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.js +25 -0
- package/dist/lib/quota-identity.d.ts +64 -0
- package/dist/lib/quota-identity.js +111 -0
- package/dist/lib/quota-providers-remote.d.ts +2 -1
- package/dist/lib/quota-providers-remote.js +59 -3
- package/dist/lib/quota-providers.d.ts +1 -1
- package/dist/lib/quota-providers.js +14 -37
- package/dist/lib/quota-render-data.d.ts +6 -0
- package/dist/lib/quota-render-data.js +45 -19
- 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 +31 -2
- package/dist/lib/quota-state.d.ts +8 -2
- package/dist/lib/quota-state.js +253 -47
- package/dist/lib/quota-stats.d.ts +26 -0
- package/dist/lib/quota-stats.js +40 -1
- package/dist/lib/quota-status.js +3 -51
- 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/scoped-update.d.ts +1 -1
- package/dist/lib/state-file-lock.d.ts +26 -0
- package/dist/lib/state-file-lock.js +205 -0
- package/dist/lib/synthetic.js +65 -54
- package/dist/lib/toast-format-grouped.js +7 -4
- package/dist/lib/tui-compact-format.js +29 -16
- package/dist/lib/types.d.ts +51 -1
- package/dist/lib/types.js +17 -1
- package/dist/lib/xai.js +48 -22
- package/dist/plugin.js +328 -14
- package/dist/provider-logos/NOTICE.md +1 -1
- package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
- package/dist/providers/alibaba-coding-plan.js +125 -104
- package/dist/providers/alibaba-token-plan.js +9 -5
- package/dist/providers/anthropic.d.ts +16 -3
- package/dist/providers/anthropic.js +172 -220
- package/dist/providers/cache-policies.d.ts +11 -4
- package/dist/providers/cache-policies.js +19 -13
- package/dist/providers/chutes.js +2 -0
- package/dist/providers/claude-agent.d.ts +19 -0
- package/dist/providers/claude-agent.js +215 -0
- package/dist/providers/copilot.js +7 -4
- package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
- package/dist/providers/glm-coding-plan-provider.js +30 -23
- package/dist/providers/google-account-format.js +1 -0
- package/dist/providers/google-agy.d.ts +6 -5
- package/dist/providers/google-agy.js +43 -15
- package/dist/providers/google-gemini-cli.js +1 -0
- package/dist/providers/kilo.js +1 -0
- package/dist/providers/kimi-code.js +2 -0
- package/dist/providers/mimo.js +1 -0
- package/dist/providers/nanogpt.js +1 -0
- package/dist/providers/ollama-cloud.js +10 -0
- package/dist/providers/openai.js +24 -23
- package/dist/providers/opencode-go.js +10 -6
- package/dist/providers/opencode-zen.js +3 -1
- package/dist/providers/openrouter.js +1 -0
- package/dist/providers/quota-providers.js +16 -5
- package/dist/providers/registry.js +2 -0
- package/dist/providers/result-helpers.d.ts +6 -2
- package/dist/providers/result-helpers.js +7 -1
- package/dist/providers/synthetic.js +4 -0
- package/dist/providers/xai.js +9 -8
- package/dist/rpc.d.ts +129 -8
- package/dist/rpc.js +219 -14
- package/dist/ui/assets/{index-cDd9jUVY.css → index-6_g1FHs-.css} +1 -1
- package/dist/ui/assets/index-sZnGUuML.js +10 -0
- package/dist/ui/assets/{popover-BGkgv9s0.js → popover-C4ZLYe9E.js} +1 -1
- package/dist/ui/assets/providers/claude-agent.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +45 -46
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
- package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
- package/dist/ui/assets/index-DLHeXYff.js +0 -9
package/dist/lib/quota-status.js
CHANGED
|
@@ -11,7 +11,6 @@ import { getOpenCodeDbPath } from "./opencode-db-path.js";
|
|
|
11
11
|
import { getOpencodeRuntimeDirs } from "./opencode-runtime-paths.js";
|
|
12
12
|
import { getOpenCodeDbStats } from "./opencode-storage.js";
|
|
13
13
|
import { getQuotaProviderDisplayLabel } from "./provider-metadata.js";
|
|
14
|
-
import { isMaintainedQuotaProviderTuning } from "./quota-providers.js";
|
|
15
14
|
import { aggregateUsage } from "./quota-stats.js";
|
|
16
15
|
import { commandHeading, renderPlainTextReport, } from "./report-document.js";
|
|
17
16
|
import { totalTokenBuckets } from "./token-buckets.js";
|
|
@@ -110,20 +109,6 @@ function appendProviderStatusDetailRows(rows, providerId, probes, keys) {
|
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
|
-
function findProviderStatusDetail(providerId, key, probes) {
|
|
114
|
-
return getProviderStatusDetails(providerId, probes)?.find((detail) => detail.key === key)?.value;
|
|
115
|
-
}
|
|
116
|
-
function getLiveProbeState(probe) {
|
|
117
|
-
if (!probe)
|
|
118
|
-
return "unavailable";
|
|
119
|
-
if (probe.result.entries.length > 0 && probe.result.errors.length > 0)
|
|
120
|
-
return "partial";
|
|
121
|
-
if (probe.result.entries.length > 0)
|
|
122
|
-
return "success";
|
|
123
|
-
if (probe.result.errors.length > 0)
|
|
124
|
-
return "error";
|
|
125
|
-
return "no_data";
|
|
126
|
-
}
|
|
127
112
|
function appendProviderCompactLiveProbeRows(rows, providerId, probes, availability, homeDir) {
|
|
128
113
|
const provider = availability.find((item) => item.id === providerId);
|
|
129
114
|
if (!provider?.enabled || !provider.available)
|
|
@@ -229,32 +214,6 @@ function createQuotaProvidersSection(params) {
|
|
|
229
214
|
for (const definition of params.definitions) {
|
|
230
215
|
const diagnostic = diagnosticsBySource.get(definition.id);
|
|
231
216
|
const coverage = definition.modelIds ? definition.modelIds.join(",") : "all_models";
|
|
232
|
-
if (definition.mode === "local-estimate" && isMaintainedQuotaProviderTuning(definition)) {
|
|
233
|
-
const probe = findProviderLiveProbe(definition.id, params.probes);
|
|
234
|
-
const statePath = findProviderStatusDetail(definition.id, "local_state_path", params.probes);
|
|
235
|
-
const stateExists = findProviderStatusDetail(definition.id, "local_state_exists", params.probes);
|
|
236
|
-
const stateHealth = findProviderStatusDetail(definition.id, "local_state_health", params.probes);
|
|
237
|
-
const stateVersion = findProviderStatusDetail(definition.id, "local_state_version", params.probes);
|
|
238
|
-
const stateLastUpdate = findProviderStatusDetail(definition.id, "local_state_last_update", params.probes);
|
|
239
|
-
rows.push({
|
|
240
|
-
key: `provider_${definition.id}`,
|
|
241
|
-
value: [
|
|
242
|
-
`provider_id=${definition.providerId}`,
|
|
243
|
-
"mode=local-estimate",
|
|
244
|
-
`coverage=${coverage}`,
|
|
245
|
-
`outcome=${getLiveProbeState(probe)}`,
|
|
246
|
-
`limits=${definition.windows.map((window) => `${window.id}:${window.requestLimit}`).join(",")}`,
|
|
247
|
-
`state_path=${statePath ?? "(none)"}`,
|
|
248
|
-
`state_exists=${stateExists ?? "false"}`,
|
|
249
|
-
`state_health=${stateHealth ?? "missing"}`,
|
|
250
|
-
`state_version=${stateVersion ?? "(none)"}`,
|
|
251
|
-
`state_last_update=${stateLastUpdate ?? "(none)"}`,
|
|
252
|
-
]
|
|
253
|
-
.map((part) => sanitizeSingleLineDisplayText(part))
|
|
254
|
-
.join(" "),
|
|
255
|
-
});
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
217
|
if (definition.mode === "local-estimate") {
|
|
259
218
|
const stateHealth = diagnostic?.stateHealth ?? "missing";
|
|
260
219
|
rows.push({
|
|
@@ -389,7 +348,7 @@ function supportedProviderPricingRow(params) {
|
|
|
389
348
|
return {
|
|
390
349
|
id,
|
|
391
350
|
pricing: "no",
|
|
392
|
-
notes: "
|
|
351
|
+
notes: "official Bailian CLI Coding Plan quota (not token-priced)",
|
|
393
352
|
};
|
|
394
353
|
}
|
|
395
354
|
if (id === "alibaba-token-plan") {
|
|
@@ -565,14 +524,7 @@ export async function buildQuotaStatusReportDocument(params) {
|
|
|
565
524
|
key: "opencode.db",
|
|
566
525
|
value: `path=${dbPath} present=${(await pathExists(dbPath)) ? "true" : "false"} (session and token history)`,
|
|
567
526
|
});
|
|
568
|
-
appendProviderStatusDetailRows(pathsRows, "alibaba-coding-plan", params.providerLiveProbes, new Set([
|
|
569
|
-
"alibaba auth configured",
|
|
570
|
-
"alibaba_api_key_source",
|
|
571
|
-
"alibaba_api_key_checked_paths",
|
|
572
|
-
"alibaba_api_key_credential_database_paths",
|
|
573
|
-
"alibaba_coding_plan",
|
|
574
|
-
"alibaba_auth_error",
|
|
575
|
-
]));
|
|
527
|
+
appendProviderStatusDetailRows(pathsRows, "alibaba-coding-plan", params.providerLiveProbes, new Set(["alibaba_coding_plan_source", "alibaba_coding_plan_cli_status"]));
|
|
576
528
|
sections.push(createKvSection("paths", "paths:", pathsRows));
|
|
577
529
|
// === credential_source ===
|
|
578
530
|
const credentialSource = getCredentialSourceDiagnostics();
|
|
@@ -592,6 +544,7 @@ export async function buildQuotaStatusReportDocument(params) {
|
|
|
592
544
|
for (const [id, providerId] of [
|
|
593
545
|
["openai", "openai"],
|
|
594
546
|
["anthropic", "anthropic"],
|
|
547
|
+
["claude-agent", "claude-agent"],
|
|
595
548
|
]) {
|
|
596
549
|
sections.push(createProviderStatusSection({
|
|
597
550
|
id,
|
|
@@ -605,7 +558,6 @@ export async function buildQuotaStatusReportDocument(params) {
|
|
|
605
558
|
// === cursor ===
|
|
606
559
|
const cursorRows = [];
|
|
607
560
|
appendProviderStatusDetailRows(cursorRows, "cursor", params.providerLiveProbes);
|
|
608
|
-
appendProviderStatusDetailRows(cursorRows, "alibaba-coding-plan", params.providerLiveProbes, new Set(["alibaba coding plan local quota", "alibaba coding plan error"]));
|
|
609
561
|
appendProviderCompactLiveProbeRows(cursorRows, "cursor", params.providerLiveProbes, params.providerAvailability, homeDir);
|
|
610
562
|
sections.push(createKvSection("cursor", "cursor:", cursorRows));
|
|
611
563
|
const alibabaCodingPlanLiveProbeSection = createCompactLiveProbeOnlySection({
|
|
@@ -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));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ConfigWriteTargetSnapshot } from "./config-write-target.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { OpenCodeMajor } from "./opencode-version-core.js";
|
|
3
3
|
import { type ScopedUpdateManualFinding, type ScopedUpdateSafeAction } from "./scoped-update-migration.js";
|
|
4
4
|
export declare const QUOTA_PACKAGE_NAME = "opencode-quota-gui";
|
|
5
5
|
export declare const LEGACY_QUOTA_PACKAGE_NAME = "@slkiser/opencode-quota";
|
|
@@ -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
|
package/dist/lib/synthetic.js
CHANGED
|
@@ -5,11 +5,18 @@
|
|
|
5
5
|
* https://api.synthetic.new/v2/quotas
|
|
6
6
|
*/
|
|
7
7
|
import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
|
|
8
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
8
9
|
import { sanitizeDisplaySnippet, sanitizeDisplayText } from "./display-sanitize.js";
|
|
9
10
|
import { clampPercent } from "./format-utils.js";
|
|
10
11
|
import { fetchWithTimeout } from "./http.js";
|
|
11
|
-
import { resolveSyntheticApiKey
|
|
12
|
+
import { resolveSyntheticApiKey } from "./synthetic-config.js";
|
|
12
13
|
const SYNTHETIC_QUOTA_URL = "https://api.synthetic.new/v2/quotas";
|
|
14
|
+
const guard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
15
|
+
success: false,
|
|
16
|
+
error: "Synthetic API error 429",
|
|
17
|
+
failureCategory: "provider_api",
|
|
18
|
+
retryAtMs,
|
|
19
|
+
}));
|
|
13
20
|
const SYNTHETIC_CREDIT_AMOUNT_PATTERN = /^\$(\d+)(?:\.(\d{1,2}))?$/;
|
|
14
21
|
export { getSyntheticKeyDiagnostics, hasSyntheticApiKey as hasSyntheticApiKeyConfigured, } from "./synthetic-config.js";
|
|
15
22
|
function asRecord(value) {
|
|
@@ -121,61 +128,65 @@ export async function querySyntheticQuota(options = {}) {
|
|
|
121
128
|
const resolved = await resolveSyntheticApiKey();
|
|
122
129
|
if (!resolved)
|
|
123
130
|
return null;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
return guard(resolved.key, async () => {
|
|
132
|
+
let responseStatus;
|
|
133
|
+
try {
|
|
134
|
+
return await fetchWithTimeout(SYNTHETIC_QUOTA_URL, {
|
|
135
|
+
request: {
|
|
136
|
+
method: "GET",
|
|
137
|
+
headers: {
|
|
138
|
+
Authorization: `Bearer ${resolved.key}`,
|
|
139
|
+
"User-Agent": "opencode-quota-gui/1.0",
|
|
140
|
+
},
|
|
132
141
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
timeoutMs: options.requestTimeoutMs,
|
|
143
|
+
consume: async (resp) => {
|
|
144
|
+
responseStatus = resp.status;
|
|
145
|
+
if (!resp.ok) {
|
|
146
|
+
const retryAtMs = retryAfterDeadline(resp);
|
|
147
|
+
const text = await resp.text().catch(() => "");
|
|
148
|
+
return {
|
|
149
|
+
success: false,
|
|
150
|
+
error: `Synthetic API error ${resp.status}: ${sanitizeDisplaySnippet(text, 120)}`,
|
|
151
|
+
failureCategory: providerFailureCategoryForHttpStatus(resp.status),
|
|
152
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const data = (await resp.json());
|
|
156
|
+
if (isEmptyPlainObject(data)) {
|
|
157
|
+
return invalidSyntheticResponse("Synthetic returned no quota data for this account.");
|
|
158
|
+
}
|
|
159
|
+
const record = asRecord(data);
|
|
160
|
+
if (!record) {
|
|
161
|
+
return invalidSyntheticResponse("Synthetic API response missing rollingFiveHourLimit quota window");
|
|
162
|
+
}
|
|
163
|
+
const rollingFiveHour = buildRollingFiveHourWindow(record);
|
|
164
|
+
if (!("limit" in rollingFiveHour)) {
|
|
165
|
+
return rollingFiveHour;
|
|
166
|
+
}
|
|
167
|
+
const weekly = buildWeeklyTokenWindow(record);
|
|
168
|
+
if (!("limit" in weekly)) {
|
|
169
|
+
return weekly;
|
|
170
|
+
}
|
|
139
171
|
return {
|
|
140
|
-
success:
|
|
141
|
-
|
|
142
|
-
|
|
172
|
+
success: true,
|
|
173
|
+
windows: {
|
|
174
|
+
fiveHour: rollingFiveHour,
|
|
175
|
+
weekly,
|
|
176
|
+
},
|
|
143
177
|
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const weekly = buildWeeklyTokenWindow(record);
|
|
158
|
-
if (!("limit" in weekly)) {
|
|
159
|
-
return weekly;
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
success: true,
|
|
163
|
-
windows: {
|
|
164
|
-
fiveHour: rollingFiveHour,
|
|
165
|
-
weekly,
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
return {
|
|
173
|
-
success: false,
|
|
174
|
-
error: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
|
|
175
|
-
failureCategory: responseStatus === undefined
|
|
176
|
-
? "provider_api"
|
|
177
|
-
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
178
|
-
};
|
|
179
|
-
}
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
|
|
185
|
+
failureCategory: responseStatus === undefined
|
|
186
|
+
? "provider_api"
|
|
187
|
+
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}, options.requestTimeoutMs);
|
|
180
191
|
}
|
|
181
192
|
//# sourceMappingURL=synthetic.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 &&
|