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
|
@@ -653,9 +653,11 @@ function buildPlanSummary(plan) {
|
|
|
653
653
|
}
|
|
654
654
|
export function getInstallerProviderPromptOptions() {
|
|
655
655
|
return QUOTA_PROVIDER_SHAPES.map((shape) => ({
|
|
656
|
-
label: shape.autoSetup === "
|
|
657
|
-
? `${getQuotaProviderDisplayLabel(shape.id)} (
|
|
658
|
-
:
|
|
656
|
+
label: shape.autoSetup === "unavailable"
|
|
657
|
+
? `${getQuotaProviderDisplayLabel(shape.id)} (quota unavailable)`
|
|
658
|
+
: shape.autoSetup === "needs_quick_setup"
|
|
659
|
+
? `${getQuotaProviderDisplayLabel(shape.id)} (quick setup)`
|
|
660
|
+
: getQuotaProviderDisplayLabel(shape.id),
|
|
659
661
|
value: shape.id,
|
|
660
662
|
}));
|
|
661
663
|
}
|
package/dist/lib/kilo.js
CHANGED
|
@@ -6,12 +6,20 @@
|
|
|
6
6
|
* without an active Kilo Pass.
|
|
7
7
|
*/
|
|
8
8
|
import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
|
|
9
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
9
10
|
import { sanitizeSingleLineDisplayText } from "./display-sanitize.js";
|
|
10
11
|
import { fetchWithTimeout } from "./http.js";
|
|
11
12
|
import { resolveKiloApiKey } from "./kilo-config.js";
|
|
12
13
|
const KILO_PASS_STATE_ENDPOINT = "https://app.kilo.ai/api/trpc/kiloPass.getState";
|
|
13
14
|
const KILO_BALANCE_ENDPOINT = "https://api.kilo.ai/api/profile/balance";
|
|
14
15
|
const MAX_RESPONSE_BYTES = 64 * 1024;
|
|
16
|
+
const kiloBlocked = (retryAtMs) => ({
|
|
17
|
+
success: false,
|
|
18
|
+
error: "Kilo Gateway API error 429",
|
|
19
|
+
failureCategory: "provider_api",
|
|
20
|
+
retryAtMs,
|
|
21
|
+
});
|
|
22
|
+
const quotaGuard = createApiKeyRetryGuard(kiloBlocked);
|
|
15
23
|
function invalidKiloResponse(error) {
|
|
16
24
|
return { success: false, error, failureCategory: "provider_api" };
|
|
17
25
|
}
|
|
@@ -144,6 +152,7 @@ async function requestKiloPassState(key, options) {
|
|
|
144
152
|
input: JSON.stringify({ "0": null }),
|
|
145
153
|
});
|
|
146
154
|
let responseStatus;
|
|
155
|
+
let retryAtMs;
|
|
147
156
|
try {
|
|
148
157
|
return await fetchWithTimeout(`${KILO_PASS_STATE_ENDPOINT}?${query.toString()}`, {
|
|
149
158
|
request: {
|
|
@@ -158,12 +167,14 @@ async function requestKiloPassState(key, options) {
|
|
|
158
167
|
timeoutMs: options.requestTimeoutMs,
|
|
159
168
|
consume: async (response) => {
|
|
160
169
|
responseStatus = response.status;
|
|
170
|
+
retryAtMs = retryAfterDeadline(response);
|
|
161
171
|
const text = await readResponseText(response, "state");
|
|
162
172
|
if (!response.ok) {
|
|
163
173
|
return {
|
|
164
174
|
success: false,
|
|
165
175
|
error: `Kilo Gateway state API error ${response.status}: ${sanitizeMessage(text, key)}`,
|
|
166
176
|
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
177
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
167
178
|
};
|
|
168
179
|
}
|
|
169
180
|
return parseKiloPassState(JSON.parse(text));
|
|
@@ -177,11 +188,13 @@ async function requestKiloPassState(key, options) {
|
|
|
177
188
|
failureCategory: responseStatus === undefined
|
|
178
189
|
? "provider_api"
|
|
179
190
|
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
191
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
180
192
|
};
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
async function requestKiloBalance(key, options) {
|
|
184
196
|
let responseStatus;
|
|
197
|
+
let retryAtMs;
|
|
185
198
|
try {
|
|
186
199
|
return await fetchWithTimeout(KILO_BALANCE_ENDPOINT, {
|
|
187
200
|
request: {
|
|
@@ -196,12 +209,14 @@ async function requestKiloBalance(key, options) {
|
|
|
196
209
|
timeoutMs: options.requestTimeoutMs,
|
|
197
210
|
consume: async (response) => {
|
|
198
211
|
responseStatus = response.status;
|
|
212
|
+
retryAtMs = retryAfterDeadline(response);
|
|
199
213
|
const text = await readResponseText(response, "balance");
|
|
200
214
|
if (!response.ok) {
|
|
201
215
|
return {
|
|
202
216
|
success: false,
|
|
203
217
|
error: `Kilo Gateway balance API error ${response.status}: ${sanitizeMessage(text, key)}`,
|
|
204
218
|
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
219
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
205
220
|
};
|
|
206
221
|
}
|
|
207
222
|
return parseKiloBalance(JSON.parse(text));
|
|
@@ -215,6 +230,7 @@ async function requestKiloBalance(key, options) {
|
|
|
215
230
|
failureCategory: responseStatus === undefined
|
|
216
231
|
? "provider_api"
|
|
217
232
|
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
233
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
218
234
|
};
|
|
219
235
|
}
|
|
220
236
|
}
|
|
@@ -232,23 +248,26 @@ export async function queryKiloQuota(options = {}) {
|
|
|
232
248
|
const resolved = await resolveKiloApiKey();
|
|
233
249
|
if (!resolved)
|
|
234
250
|
return null;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
return quotaGuard(resolved.key, async () => {
|
|
252
|
+
const passResult = await requestKiloPassState(resolved.key, options);
|
|
253
|
+
if (passResult.success) {
|
|
254
|
+
return { ...passResult, mode: "kilo_pass" };
|
|
255
|
+
}
|
|
256
|
+
if (!isNoActiveKiloPassResult(passResult)) {
|
|
257
|
+
return passResult;
|
|
258
|
+
}
|
|
259
|
+
const balanceResult = await requestKiloBalance(resolved.key, options);
|
|
260
|
+
if (balanceResult.success) {
|
|
261
|
+
return { ...balanceResult, mode: "gateway_balance" };
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
error: `Kilo Gateway has no active Kilo Pass subscription; balance fallback failed: ${balanceResult.error}`,
|
|
266
|
+
...(balanceResult.failureCategory !== undefined
|
|
267
|
+
? { failureCategory: balanceResult.failureCategory }
|
|
268
|
+
: {}),
|
|
269
|
+
...(balanceResult.retryAtMs !== undefined ? { retryAtMs: balanceResult.retryAtMs } : {}),
|
|
270
|
+
};
|
|
271
|
+
}, options.requestTimeoutMs);
|
|
253
272
|
}
|
|
254
273
|
//# sourceMappingURL=kilo.js.map
|
package/dist/lib/kimi.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { providerFailureCategoryForHttpStatus, } from "../contracts/provider-failure.js";
|
|
2
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
2
3
|
import { sanitizeDisplaySnippet, sanitizeDisplayText } from "./display-sanitize.js";
|
|
3
4
|
import { clampPercent } from "./format-utils.js";
|
|
4
5
|
import { fetchWithTimeout } from "./http.js";
|
|
@@ -178,8 +179,15 @@ function parseKimiUsagePayload(payload) {
|
|
|
178
179
|
}
|
|
179
180
|
return { windows, topLevelKeys };
|
|
180
181
|
}
|
|
182
|
+
const guard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
183
|
+
success: false,
|
|
184
|
+
error: "Kimi API error 429",
|
|
185
|
+
failureCategory: "provider_api",
|
|
186
|
+
retryAtMs,
|
|
187
|
+
}));
|
|
181
188
|
async function fetchKimiQuotaFromUrl(url, apiKey, requestTimeoutMs) {
|
|
182
189
|
let responseStatus;
|
|
190
|
+
let retryAtMs;
|
|
183
191
|
try {
|
|
184
192
|
return await fetchWithTimeout(url, {
|
|
185
193
|
request: {
|
|
@@ -192,11 +200,13 @@ async function fetchKimiQuotaFromUrl(url, apiKey, requestTimeoutMs) {
|
|
|
192
200
|
consume: async (resp) => {
|
|
193
201
|
responseStatus = resp.status;
|
|
194
202
|
if (!resp.ok) {
|
|
203
|
+
retryAtMs = retryAfterDeadline(resp);
|
|
195
204
|
const text = await resp.text();
|
|
196
205
|
return {
|
|
197
206
|
ok: false,
|
|
198
207
|
error: `Kimi API error ${resp.status}: ${sanitizeDisplaySnippet(text, 120)}`,
|
|
199
208
|
failureCategory: providerFailureCategoryForHttpStatus(resp.status),
|
|
209
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
200
210
|
};
|
|
201
211
|
}
|
|
202
212
|
const payload = (await resp.json());
|
|
@@ -212,31 +222,38 @@ async function fetchKimiQuotaFromUrl(url, apiKey, requestTimeoutMs) {
|
|
|
212
222
|
failureCategory: responseStatus === undefined
|
|
213
223
|
? "provider_api"
|
|
214
224
|
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
225
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
215
226
|
};
|
|
216
227
|
}
|
|
217
228
|
}
|
|
218
229
|
export async function queryKimiQuota(options) {
|
|
219
230
|
const endpoint = getKimiQuotaEndpoint(options.endpoint);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
231
|
+
// Endpoint is part of the guarded identity so one key on global/cn stays isolated.
|
|
232
|
+
return guard(`${options.endpoint}\0${options.apiKey}`, async () => {
|
|
233
|
+
const result = await fetchKimiQuotaFromUrl(endpoint.quotaUrl, options.apiKey, options.requestTimeoutMs);
|
|
234
|
+
if (result.ok && result.windows.length > 0) {
|
|
235
|
+
return {
|
|
236
|
+
success: true,
|
|
237
|
+
label: options.label ?? endpoint.label,
|
|
238
|
+
windows: result.windows,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (!result.ok) {
|
|
242
|
+
return {
|
|
243
|
+
success: false,
|
|
244
|
+
error: result.error,
|
|
245
|
+
...(result.failureCategory !== undefined
|
|
246
|
+
? { failureCategory: result.failureCategory }
|
|
247
|
+
: {}),
|
|
248
|
+
...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// Succeeded structurally but had no usable windows.
|
|
229
252
|
return {
|
|
230
253
|
success: false,
|
|
231
|
-
error: result.
|
|
232
|
-
|
|
254
|
+
error: describeUnexpectedPayload(result.topLevelKeys),
|
|
255
|
+
failureCategory: "provider_api",
|
|
233
256
|
};
|
|
234
|
-
}
|
|
235
|
-
// Succeeded structurally but had no usable windows.
|
|
236
|
-
return {
|
|
237
|
-
success: false,
|
|
238
|
-
error: describeUnexpectedPayload(result.topLevelKeys),
|
|
239
|
-
failureCategory: "provider_api",
|
|
240
|
-
};
|
|
257
|
+
}, options.requestTimeoutMs);
|
|
241
258
|
}
|
|
242
259
|
//# sourceMappingURL=kimi.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getQuotaProviderRegistration, normalizeQuotaProviderId, } from "./provider-metadata.js";
|
|
2
2
|
export const BUNDLED_MAINTAINER_ANNOUNCEMENTS = [
|
|
3
3
|
{
|
|
4
4
|
id: "opencode-ecosystem-listing-support",
|
|
@@ -38,7 +38,7 @@ function normalizedProviderIds(providerIds) {
|
|
|
38
38
|
const out = [];
|
|
39
39
|
const seen = new Set();
|
|
40
40
|
for (const providerId of providerIds) {
|
|
41
|
-
const shape =
|
|
41
|
+
const shape = getQuotaProviderRegistration(normalizeQuotaProviderId(providerId));
|
|
42
42
|
if (!shape || seen.has(shape.id)) {
|
|
43
43
|
continue;
|
|
44
44
|
}
|
package/dist/lib/mimo.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type MimoEndpointResult<T> = {
|
|
|
21
21
|
state: "error";
|
|
22
22
|
error: string;
|
|
23
23
|
failureCategory: ProviderFailureCategory;
|
|
24
|
+
/** Deadline observed in an upstream Retry-After response. */
|
|
25
|
+
retryAtMs?: number;
|
|
24
26
|
};
|
|
25
27
|
export interface MimoDashboardResult {
|
|
26
28
|
usage: MimoEndpointResult<MimoMonthlyQuota>;
|
package/dist/lib/mimo.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
1
2
|
import { sanitizeSingleLineDisplaySnippet } from "./display-sanitize.js";
|
|
2
3
|
import { fetchWithTimeout } from "./http.js";
|
|
3
4
|
const MIMO_USAGE_URL = "https://platform.xiaomimimo.com/api/v1/tokenPlan/usage";
|
|
@@ -6,6 +7,16 @@ const MIMO_BALANCE_URL = "https://platform.xiaomimimo.com/api/v1/balance";
|
|
|
6
7
|
const MIMO_REQUEST_TIMEOUT_MS = 10_000;
|
|
7
8
|
const MIMO_RESPONSE_MAX_BYTES = 256 * 1024;
|
|
8
9
|
const MIMO_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36";
|
|
10
|
+
const endpointGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
11
|
+
success: false,
|
|
12
|
+
retryAtMs,
|
|
13
|
+
endpoint: {
|
|
14
|
+
state: "error",
|
|
15
|
+
error: "Xiaomi MiMo request failed (HTTP 429)",
|
|
16
|
+
failureCategory: "provider_api",
|
|
17
|
+
retryAtMs,
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
9
20
|
function isRecord(value) {
|
|
10
21
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11
22
|
}
|
|
@@ -144,7 +155,30 @@ function sanitizeRequestError(error, cookie) {
|
|
|
144
155
|
}
|
|
145
156
|
return sanitizeSingleLineDisplaySnippet(message, 120) || "request failed";
|
|
146
157
|
}
|
|
158
|
+
/** One cooldown per session cookie and endpoint; other cookies are unaffected. */
|
|
147
159
|
async function fetchMimoEndpoint(params) {
|
|
160
|
+
const guarded = await endpointGuard(JSON.stringify([params.cookie, params.name]), async () => {
|
|
161
|
+
const endpoint = await requestMimoEndpoint(params);
|
|
162
|
+
return {
|
|
163
|
+
success: endpoint.state === "success",
|
|
164
|
+
...(endpoint.state === "error" && endpoint.retryAtMs !== undefined
|
|
165
|
+
? { retryAtMs: endpoint.retryAtMs }
|
|
166
|
+
: {}),
|
|
167
|
+
endpoint,
|
|
168
|
+
};
|
|
169
|
+
}, params.requestTimeoutMs, (retryAtMs) => ({
|
|
170
|
+
success: false,
|
|
171
|
+
retryAtMs,
|
|
172
|
+
endpoint: {
|
|
173
|
+
state: "error",
|
|
174
|
+
error: `Xiaomi MiMo ${params.name} request failed (HTTP 429)`,
|
|
175
|
+
failureCategory: "provider_api",
|
|
176
|
+
retryAtMs,
|
|
177
|
+
},
|
|
178
|
+
}));
|
|
179
|
+
return guarded.endpoint;
|
|
180
|
+
}
|
|
181
|
+
async function requestMimoEndpoint(params) {
|
|
148
182
|
try {
|
|
149
183
|
return await fetchWithTimeout(params.url, {
|
|
150
184
|
request: {
|
|
@@ -170,10 +204,12 @@ async function fetchMimoEndpoint(params) {
|
|
|
170
204
|
};
|
|
171
205
|
}
|
|
172
206
|
if (!response.ok) {
|
|
207
|
+
const retryAtMs = retryAfterDeadline(response);
|
|
173
208
|
return {
|
|
174
209
|
state: "error",
|
|
175
210
|
error: `Xiaomi MiMo ${params.name} request failed (HTTP ${response.status})`,
|
|
176
211
|
failureCategory: response.status === 401 || response.status === 403 ? "credentials" : "provider_api",
|
|
212
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
177
213
|
};
|
|
178
214
|
}
|
|
179
215
|
let json;
|
|
@@ -52,16 +52,44 @@ export type PricingSnapshotHealth = {
|
|
|
52
52
|
maxAgeMs: number;
|
|
53
53
|
stale: boolean;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* One recorded models.dev request. Automatic entries consume the rolling 24h
|
|
57
|
+
* budget; manual `force` refreshes are recorded but stay outside it.
|
|
58
|
+
*/
|
|
59
|
+
export interface PricingRefreshAttempt {
|
|
60
|
+
at: number;
|
|
61
|
+
automatic: boolean;
|
|
62
|
+
/** Distinguishes reservations made in the same millisecond. */
|
|
63
|
+
id?: string;
|
|
64
|
+
}
|
|
55
65
|
export interface PricingRefreshStateV1 {
|
|
56
66
|
version: 1;
|
|
57
67
|
updatedAt: number;
|
|
58
68
|
lastAttemptAt?: number;
|
|
59
69
|
lastSuccessAt?: number;
|
|
60
70
|
lastFailureAt?: number;
|
|
61
|
-
lastResult?: "success" | "not_modified" | "skipped_fresh" | "skipped_throttled" | "failed";
|
|
71
|
+
lastResult?: "success" | "not_modified" | "skipped_fresh" | "skipped_throttled" | "skipped_budget" | "failed";
|
|
62
72
|
lastError?: string;
|
|
63
73
|
etag?: string;
|
|
64
74
|
lastModified?: string;
|
|
75
|
+
/** Every automatic and manual network request inside the rolling 24h. */
|
|
76
|
+
attempts24h?: PricingRefreshAttempt[];
|
|
77
|
+
/**
|
|
78
|
+
* Unpriced routes already checked against the catalog identity in `key`.
|
|
79
|
+
* A route missing here for the current identity may bypass the minimum
|
|
80
|
+
* automatic attempt interval once; the rolling 24h budget still applies.
|
|
81
|
+
*/
|
|
82
|
+
unpricedChecked?: PricingRouteChecks;
|
|
83
|
+
/**
|
|
84
|
+
* Unpriced routes that already spent their one throttle bypass for the
|
|
85
|
+
* catalog identity in `key`. A failed attempt still counts, so retries obey
|
|
86
|
+
* the ordinary minimum interval instead of burning the daily budget.
|
|
87
|
+
*/
|
|
88
|
+
unpricedBypassUsed?: PricingRouteChecks;
|
|
89
|
+
}
|
|
90
|
+
export interface PricingRouteChecks {
|
|
91
|
+
key: string;
|
|
92
|
+
routes: string[];
|
|
65
93
|
}
|
|
66
94
|
export interface PricingRefreshPolicy {
|
|
67
95
|
enabled: boolean;
|
|
@@ -70,7 +98,7 @@ export interface PricingRefreshPolicy {
|
|
|
70
98
|
timeoutMs: number;
|
|
71
99
|
}
|
|
72
100
|
export interface PricingRefreshOptions {
|
|
73
|
-
reason?: "init" | "tokens" | "status" | "manual";
|
|
101
|
+
reason?: "init" | "tokens" | "status" | "manual" | "unpriced";
|
|
74
102
|
force?: boolean;
|
|
75
103
|
nowMs?: number;
|
|
76
104
|
maxAgeMs?: number;
|
|
@@ -83,6 +111,20 @@ export interface PricingRefreshOptions {
|
|
|
83
111
|
providerAllowlist?: string[];
|
|
84
112
|
snapshotSelection?: PricingSnapshotSource;
|
|
85
113
|
allowRefreshWhenSelectionBundled?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Skip the max-age check for an unpriced-triggered attempt. The rolling
|
|
116
|
+
* budget always applies; the 6h throttle applies unless `unpricedRouteKeys`
|
|
117
|
+
* contains a route not yet checked against the current catalog identity.
|
|
118
|
+
*/
|
|
119
|
+
refreshEvenIfFresh?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Unpriced routes (see `pricingRouteKey`) the caller observed. A route with
|
|
122
|
+
* no recorded check and no spent throttle bypass for the current catalog
|
|
123
|
+
* identity may skip the 6h throttle once; later observations stay throttled.
|
|
124
|
+
*/
|
|
125
|
+
unpricedRouteKeys?: readonly string[];
|
|
126
|
+
/** Cross-process budget-lock wait; expired means skip the attempt. */
|
|
127
|
+
lockTimeoutMs?: number;
|
|
86
128
|
}
|
|
87
129
|
export interface PricingRefreshResult {
|
|
88
130
|
attempted: boolean;
|
|
@@ -95,8 +137,38 @@ export declare function getPricingRefreshPolicy(): PricingRefreshPolicy;
|
|
|
95
137
|
export declare function setPricingSnapshotAutoRefresh(days: number): void;
|
|
96
138
|
export declare function getRuntimePricingSnapshotPath(runtimeDirs?: OpencodeRuntimeDirs): string;
|
|
97
139
|
export declare function getRuntimePricingRefreshStatePath(runtimeDirs?: OpencodeRuntimeDirs): string;
|
|
140
|
+
/**
|
|
141
|
+
* Adopt a runtime snapshot rewritten by another process (the plugin host, or
|
|
142
|
+
* this worker's own refresh). A fresh `_meta` object is what invalidates the
|
|
143
|
+
* analytics pricing fingerprint and its derived presentation caches.
|
|
144
|
+
*/
|
|
145
|
+
export declare function reloadPricingSnapshotFromDisk(params?: {
|
|
146
|
+
runtimeDirs?: OpencodeRuntimeDirs;
|
|
147
|
+
bootstrapSnapshotOverride?: PricingSnapshot;
|
|
148
|
+
}): void;
|
|
98
149
|
export declare function readPricingRefreshState(runtimeDirs?: OpencodeRuntimeDirs): Promise<PricingRefreshStateV1 | null>;
|
|
150
|
+
export type PricingRoute = {
|
|
151
|
+
providerID?: string;
|
|
152
|
+
modelID?: string;
|
|
153
|
+
};
|
|
99
154
|
export declare function maybeRefreshPricingSnapshot(opts?: PricingRefreshOptions): Promise<PricingRefreshResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Event-driven analytics pricing upkeep: adopt an externally refreshed runtime
|
|
157
|
+
* snapshot, run the normal freshness refresh, and give one extra attempt when a
|
|
158
|
+
* route used by Analytics is still unpriced or unknown. A route not yet checked
|
|
159
|
+
* against the current catalog identity gets one throttle bypass per identity;
|
|
160
|
+
* every attempt still obeys the rolling 24h automatic request budget, and a
|
|
161
|
+
* bundled selection never refreshes. Cheap re-entry: unchanged unpriced routes
|
|
162
|
+
* inside the check interval do no I/O.
|
|
163
|
+
*/
|
|
164
|
+
export declare function refreshAnalyticsPricing(opts?: {
|
|
165
|
+
routes?: readonly PricingRoute[];
|
|
166
|
+
nowMs?: number;
|
|
167
|
+
runtimeDirs?: OpencodeRuntimeDirs;
|
|
168
|
+
fetchFn?: typeof fetch;
|
|
169
|
+
bootstrapSnapshotOverride?: PricingSnapshot;
|
|
170
|
+
snapshotSelection?: PricingSnapshotSource;
|
|
171
|
+
}): Promise<PricingRefreshResult | undefined>;
|
|
100
172
|
export declare function setPricingSnapshotSelection(selection: PricingSnapshotSource): void;
|
|
101
173
|
export declare function getPricingSnapshotSelection(): PricingSnapshotSource;
|
|
102
174
|
export declare function getPricingSnapshotMeta(): PricingSnapshot["_meta"];
|