opencode-quota-gui 1.3.0 → 1.3.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 +27 -17
- package/dist/bin/opencode-quota-gui.js +0 -0
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/dashboard.d.ts +8 -1
- package/dist/contracts/dto-guards.js +2 -0
- package/dist/contracts/openai-quota.d.ts +3 -0
- package/dist/contracts/openai-quota.js +3 -0
- package/dist/data/modelsdev-temporal.min.json +57 -0
- package/dist/gui/config.d.ts +3 -3
- package/dist/gui/config.js +31 -2
- package/dist/gui/lifecycle.d.ts +5 -3
- package/dist/gui/lifecycle.js +3 -3
- package/dist/gui/primary-quota-windows.js +16 -14
- package/dist/gui/provider-cards.d.ts +10 -2
- package/dist/gui/provider-cards.js +51 -23
- package/dist/gui/quota-notification-detector.d.ts +4 -4
- package/dist/gui/quota-notification-detector.js +76 -42
- package/dist/gui/quota-notification-observer.d.ts +2 -3
- package/dist/gui/quota-notification-observer.js +68 -19
- package/dist/gui/rpc.d.ts +2 -0
- package/dist/gui/rpc.js +11 -3
- package/dist/gui/server.js +11 -2
- package/dist/gui/snapshot-service.d.ts +3 -1
- package/dist/gui/snapshot-service.js +126 -18
- package/dist/gui/sources.js +98 -56
- package/dist/gui-experimental.cjs +230 -225
- package/dist/lib/accounting-format.js +8 -0
- 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-auth.d.ts +2 -3
- package/dist/lib/anthropic-auth.js +2 -3
- package/dist/lib/anthropic.d.ts +48 -12
- package/dist/lib/anthropic.js +610 -275
- 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 +981 -0
- package/dist/lib/cache-observer.d.ts +138 -0
- package/dist/lib/cache-observer.js +317 -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.js +5 -3
- 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 +193 -2
- package/dist/lib/copilot.js +171 -86
- 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 +1 -0
- package/dist/lib/entries.d.ts +23 -0
- package/dist/lib/entries.js +2 -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/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/mimo.d.ts +2 -0
- package/dist/lib/mimo.js +36 -0
- 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-go.js +29 -2
- package/dist/lib/opencode-version-core.d.ts +23 -0
- package/dist/lib/opencode-version-core.js +49 -0
- package/dist/lib/opencode-version.d.ts +2 -22
- package/dist/lib/opencode-version.js +4 -48
- 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-registration.d.ts +19 -9
- package/dist/lib/provider-registration.js +17 -6
- package/dist/lib/quota-command-format.js +1 -1
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.js +25 -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 +12 -35
- package/dist/lib/quota-render-data.d.ts +6 -0
- package/dist/lib/quota-render-data.js +43 -17
- package/dist/lib/quota-state-codec.js +17 -1
- package/dist/lib/quota-state.d.ts +7 -1
- package/dist/lib/quota-state.js +208 -34
- package/dist/lib/quota-stats.js +21 -0
- package/dist/lib/quota-status.js +3 -51
- package/dist/lib/scoped-update.d.ts +1 -1
- package/dist/lib/synthetic.js +65 -54
- package/dist/lib/types.d.ts +31 -1
- package/dist/lib/types.js +13 -0
- package/dist/lib/xai.js +48 -22
- package/dist/plugin.js +261 -13
- package/dist/provider-logos/NOTICE.md +1 -1
- package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
- package/dist/providers/alibaba-coding-plan.js +107 -104
- package/dist/providers/anthropic.d.ts +12 -3
- package/dist/providers/anthropic.js +71 -228
- package/dist/providers/cache-policies.d.ts +11 -4
- package/dist/providers/cache-policies.js +19 -13
- package/dist/providers/claude-agent.d.ts +19 -0
- package/dist/providers/claude-agent.js +196 -0
- package/dist/providers/copilot.js +2 -0
- package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
- 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/opencode-go.js +3 -0
- package/dist/providers/opencode-zen.js +2 -0
- 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 +2 -0
- package/dist/providers/result-helpers.js +2 -0
- package/dist/rpc.d.ts +121 -8
- package/dist/rpc.js +204 -12
- package/dist/ui/assets/{index-cDd9jUVY.css → index-BcueIm3Z.css} +1 -1
- package/dist/ui/assets/index-C6qRSoh8.js +10 -0
- package/dist/ui/assets/{popover-BGkgv9s0.js → popover-4bFSvRZ7.js} +1 -1
- package/dist/ui/assets/providers/claude-agent.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +44 -45
- 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({
|
|
@@ -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";
|
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
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -17,9 +17,32 @@ export type QuotaResetWindow = "fiveHour" | "hourly" | "daily" | "weekly" | "mon
|
|
|
17
17
|
export interface QuotaResetNotificationsConfig {
|
|
18
18
|
/** Whether successful quota-window resets emit a one-shot toast. */
|
|
19
19
|
enabled: boolean;
|
|
20
|
-
/**
|
|
20
|
+
/** Windows whose verified reset transitions may produce a one-shot notification. */
|
|
21
21
|
windows: QuotaResetWindow[];
|
|
22
22
|
}
|
|
23
|
+
/** Canonical Native desktop notification policy; legacy `resetNotifications` is separate. */
|
|
24
|
+
export interface NativeQuotaNotificationPolicy {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
/** Focused-window model mismatch toasts; independent of the quota alert master. */
|
|
27
|
+
modelChangeToastEnabled: boolean;
|
|
28
|
+
low: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
thresholdRemainingPercent: number;
|
|
31
|
+
};
|
|
32
|
+
exhausted: {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
};
|
|
35
|
+
reset: {
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
windows: QuotaResetWindow[];
|
|
38
|
+
};
|
|
39
|
+
providerError: {
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
};
|
|
42
|
+
/** Shared cooldown for every Native quota notification fingerprint. */
|
|
43
|
+
duplicateCooldownMinutes: number;
|
|
44
|
+
}
|
|
45
|
+
export declare const DEFAULT_NATIVE_QUOTA_NOTIFICATION_POLICY: NativeQuotaNotificationPolicy;
|
|
23
46
|
export interface PricingSnapshotConfig {
|
|
24
47
|
source: PricingSnapshotSource;
|
|
25
48
|
autoRefresh: number;
|
|
@@ -128,6 +151,8 @@ export interface QuotaToastConfig {
|
|
|
128
151
|
enableToast: boolean;
|
|
129
152
|
/** Opt-in, persisted notifications when selected quota windows reset. */
|
|
130
153
|
resetNotifications: QuotaResetNotificationsConfig;
|
|
154
|
+
/** Master/category policy for Native quota notifications. */
|
|
155
|
+
nativeQuotaNotifications: NativeQuotaNotificationPolicy;
|
|
131
156
|
/**
|
|
132
157
|
* Percent of a quota window remaining at or below which quota is considered
|
|
133
158
|
* low. Stored as remaining even when the UI displays used percentages.
|
|
@@ -600,6 +625,10 @@ export interface GoogleAccountError {
|
|
|
600
625
|
email: string;
|
|
601
626
|
error: string;
|
|
602
627
|
failureCategory?: ProviderFailureCategory;
|
|
628
|
+
/** Deadline observed in an upstream Retry-After response. */
|
|
629
|
+
retryAtMs?: number;
|
|
630
|
+
/** Position of the failed account, matching its buckets' `accountIndex`. */
|
|
631
|
+
accountIndex?: number;
|
|
603
632
|
}
|
|
604
633
|
export interface GeminiCliQuotaBucket {
|
|
605
634
|
modelId: string;
|
|
@@ -661,6 +690,7 @@ export type GoogleAgyResult = GoogleAgyQuotaResult | QuotaError | null;
|
|
|
661
690
|
export interface QuotaError {
|
|
662
691
|
success: false;
|
|
663
692
|
error: string;
|
|
693
|
+
retryAtMs?: number;
|
|
664
694
|
/** Whether retrying later may succeed without changing credentials or configuration. */
|
|
665
695
|
retryable?: boolean;
|
|
666
696
|
/** Source-assigned safe category; absence means unknown and consumers fail closed. */
|
package/dist/lib/types.js
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
* Type definitions for the opencode-quota-gui product.
|
|
3
3
|
*/
|
|
4
4
|
import { DEFAULT_QUOTA_FORMAT_STYLE } from "./quota-format-style.js";
|
|
5
|
+
export const DEFAULT_NATIVE_QUOTA_NOTIFICATION_POLICY = {
|
|
6
|
+
enabled: true,
|
|
7
|
+
modelChangeToastEnabled: true,
|
|
8
|
+
low: { enabled: true, thresholdRemainingPercent: 10 },
|
|
9
|
+
exhausted: { enabled: true },
|
|
10
|
+
reset: {
|
|
11
|
+
enabled: true,
|
|
12
|
+
windows: ["fiveHour", "hourly", "daily", "weekly", "monthly", "yearly"],
|
|
13
|
+
},
|
|
14
|
+
providerError: { enabled: true },
|
|
15
|
+
duplicateCooldownMinutes: 30,
|
|
16
|
+
};
|
|
5
17
|
/** Default dashboard port (spec §5.4); never falls back to another port. */
|
|
6
18
|
export const DEFAULT_DASHBOARD_PORT = 4144;
|
|
7
19
|
/** Cap for opaque dashboard id-list settings (`hiddenCards`, `hiddenRows`, order lists). */
|
|
@@ -16,6 +28,7 @@ export const DEFAULT_CONFIG = {
|
|
|
16
28
|
enabled: false,
|
|
17
29
|
windows: ["weekly"],
|
|
18
30
|
},
|
|
31
|
+
nativeQuotaNotifications: DEFAULT_NATIVE_QUOTA_NOTIFICATION_POLICY,
|
|
19
32
|
lowQuotaThresholdRemainingPercent: 10,
|
|
20
33
|
duplicateCooldownMinutes: 30,
|
|
21
34
|
tuiCommandDisplay: "dialog",
|
package/dist/lib/xai.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* OpenCode remains the sole owner of OAuth refresh and opencode.db persistence.
|
|
12
12
|
*/
|
|
13
13
|
import { providerFailureCategoryForHttpStatus, } from "../contracts/provider-failure.js";
|
|
14
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
14
15
|
import { sanitizeSingleLineDisplaySnippet } from "./display-sanitize.js";
|
|
15
16
|
import { clampPercent } from "./format-utils.js";
|
|
16
17
|
import { fetchWithTimeout } from "./http.js";
|
|
@@ -22,6 +23,16 @@ const SUBSCRIPTIONS_URL = "https://grok.com/rest/subscriptions";
|
|
|
22
23
|
const SUBSCRIPTIONS_TIMEOUT_MS = 2_000;
|
|
23
24
|
const HEAVY_OFFER_ID_RE = /^heavy-p\d+m-\d{1,2}-[a-z]{3}\d{4}$/i;
|
|
24
25
|
const USER_AGENT = "opencode-quota-gui/1.0";
|
|
26
|
+
const guard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
27
|
+
success: false,
|
|
28
|
+
error: "xAI API error 429",
|
|
29
|
+
failureCategory: providerFailureCategoryForHttpStatus(429),
|
|
30
|
+
retryAtMs,
|
|
31
|
+
}));
|
|
32
|
+
const subscriptionGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
33
|
+
success: false,
|
|
34
|
+
retryAtMs,
|
|
35
|
+
}));
|
|
25
36
|
function isRecord(value) {
|
|
26
37
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
27
38
|
}
|
|
@@ -176,23 +187,30 @@ function xaiLabelForTier(tier) {
|
|
|
176
187
|
}
|
|
177
188
|
}
|
|
178
189
|
async function queryXaiSubscriptionTier(accessToken, requestTimeoutMs) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
190
|
+
const result = await subscriptionGuard(accessToken, async () => {
|
|
191
|
+
try {
|
|
192
|
+
return await fetchWithTimeout(SUBSCRIPTIONS_URL, {
|
|
193
|
+
request: {
|
|
194
|
+
method: "GET",
|
|
195
|
+
headers: xaiHeaders(accessToken),
|
|
196
|
+
},
|
|
197
|
+
timeoutMs: Math.min(requestTimeoutMs ?? SUBSCRIPTIONS_TIMEOUT_MS, SUBSCRIPTIONS_TIMEOUT_MS),
|
|
198
|
+
consume: async (response) => {
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
const retryAtMs = retryAfterDeadline(response);
|
|
201
|
+
return retryAtMs === undefined
|
|
202
|
+
? { success: true, tier: null }
|
|
203
|
+
: { success: false, retryAtMs };
|
|
204
|
+
}
|
|
205
|
+
return { success: true, tier: parseXaiSubscriptionTier(await response.json()) };
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return { success: true, tier: null };
|
|
211
|
+
}
|
|
212
|
+
}, Math.min(requestTimeoutMs ?? SUBSCRIPTIONS_TIMEOUT_MS, SUBSCRIPTIONS_TIMEOUT_MS));
|
|
213
|
+
return result.success ? result.tier : null;
|
|
196
214
|
}
|
|
197
215
|
function safeErrorText(message, accessToken) {
|
|
198
216
|
const redacted = accessToken ? message.split(accessToken).join("[redacted]") : message;
|
|
@@ -219,22 +237,29 @@ export async function queryXaiQuota(options = {}) {
|
|
|
219
237
|
failureCategory: "credentials",
|
|
220
238
|
};
|
|
221
239
|
}
|
|
240
|
+
const accessToken = resolvedAuth.accessToken;
|
|
241
|
+
return guard(accessToken, () => fetchXaiQuota(accessToken, options.requestTimeoutMs), options.requestTimeoutMs);
|
|
242
|
+
}
|
|
243
|
+
async function fetchXaiQuota(accessToken, requestTimeoutMs) {
|
|
222
244
|
let responseStatus;
|
|
245
|
+
let retryAtMs;
|
|
223
246
|
try {
|
|
224
247
|
const creditsResult = await fetchWithTimeout(CREDITS_URL, {
|
|
225
248
|
request: {
|
|
226
249
|
method: "GET",
|
|
227
|
-
headers: xaiHeaders(
|
|
250
|
+
headers: xaiHeaders(accessToken),
|
|
228
251
|
},
|
|
229
|
-
timeoutMs:
|
|
252
|
+
timeoutMs: requestTimeoutMs,
|
|
230
253
|
consume: async (response) => {
|
|
231
254
|
responseStatus = response.status;
|
|
232
255
|
if (!response.ok) {
|
|
256
|
+
retryAtMs = retryAfterDeadline(response);
|
|
233
257
|
const body = await response.text();
|
|
234
258
|
return {
|
|
235
259
|
success: false,
|
|
236
|
-
error: `xAI API error ${response.status}: ${safeErrorText(body,
|
|
260
|
+
error: `xAI API error ${response.status}: ${safeErrorText(body, accessToken)}`,
|
|
237
261
|
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
262
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
238
263
|
};
|
|
239
264
|
}
|
|
240
265
|
const payload = await response.json();
|
|
@@ -251,16 +276,17 @@ export async function queryXaiQuota(options = {}) {
|
|
|
251
276
|
});
|
|
252
277
|
if (!creditsResult.success)
|
|
253
278
|
return creditsResult;
|
|
254
|
-
const tier = await queryXaiSubscriptionTier(
|
|
279
|
+
const tier = await queryXaiSubscriptionTier(accessToken, requestTimeoutMs);
|
|
255
280
|
return { success: true, label: xaiLabelForTier(tier), window: creditsResult.window };
|
|
256
281
|
}
|
|
257
282
|
catch (error) {
|
|
258
283
|
return {
|
|
259
284
|
success: false,
|
|
260
|
-
error: safeErrorText(error instanceof Error ? error.message : String(error),
|
|
285
|
+
error: safeErrorText(error instanceof Error ? error.message : String(error), accessToken),
|
|
261
286
|
failureCategory: responseStatus === undefined
|
|
262
287
|
? "provider_api"
|
|
263
288
|
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
289
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
264
290
|
};
|
|
265
291
|
}
|
|
266
292
|
}
|