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.
Files changed (146) hide show
  1. package/README.md +27 -17
  2. package/dist/bin/opencode-quota-gui.js +0 -0
  3. package/dist/contracts/build-identity.js +1 -1
  4. package/dist/contracts/dashboard.d.ts +8 -1
  5. package/dist/contracts/dto-guards.js +2 -0
  6. package/dist/contracts/openai-quota.d.ts +3 -0
  7. package/dist/contracts/openai-quota.js +3 -0
  8. package/dist/data/modelsdev-temporal.min.json +57 -0
  9. package/dist/gui/config.d.ts +3 -3
  10. package/dist/gui/config.js +31 -2
  11. package/dist/gui/lifecycle.d.ts +5 -3
  12. package/dist/gui/lifecycle.js +3 -3
  13. package/dist/gui/primary-quota-windows.js +16 -14
  14. package/dist/gui/provider-cards.d.ts +10 -2
  15. package/dist/gui/provider-cards.js +51 -23
  16. package/dist/gui/quota-notification-detector.d.ts +4 -4
  17. package/dist/gui/quota-notification-detector.js +76 -42
  18. package/dist/gui/quota-notification-observer.d.ts +2 -3
  19. package/dist/gui/quota-notification-observer.js +68 -19
  20. package/dist/gui/rpc.d.ts +2 -0
  21. package/dist/gui/rpc.js +11 -3
  22. package/dist/gui/server.js +11 -2
  23. package/dist/gui/snapshot-service.d.ts +3 -1
  24. package/dist/gui/snapshot-service.js +126 -18
  25. package/dist/gui/sources.js +98 -56
  26. package/dist/gui-experimental.cjs +230 -225
  27. package/dist/lib/accounting-format.js +8 -0
  28. package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
  29. package/dist/lib/alibaba-coding-plan-cli.js +539 -0
  30. package/dist/lib/anthropic-auth.d.ts +2 -3
  31. package/dist/lib/anthropic-auth.js +2 -3
  32. package/dist/lib/anthropic.d.ts +48 -12
  33. package/dist/lib/anthropic.js +610 -275
  34. package/dist/lib/api-key-retry-after.d.ts +7 -0
  35. package/dist/lib/api-key-retry-after.js +62 -0
  36. package/dist/lib/atomic-json.d.ts +2 -0
  37. package/dist/lib/atomic-json.js +1 -0
  38. package/dist/lib/cache-observer-ingestion.d.ts +90 -0
  39. package/dist/lib/cache-observer-ingestion.js +981 -0
  40. package/dist/lib/cache-observer.d.ts +138 -0
  41. package/dist/lib/cache-observer.js +317 -0
  42. package/dist/lib/canonical-config-lock.d.ts +9 -0
  43. package/dist/lib/canonical-config-lock.js +36 -0
  44. package/dist/lib/chutes.js +62 -51
  45. package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
  46. package/dist/lib/claude-agent-transcript-ttl.js +154 -0
  47. package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
  48. package/dist/lib/claude-agent-ttl-tracker.js +152 -0
  49. package/dist/lib/cli-show.js +5 -3
  50. package/dist/lib/config-write-target.d.ts +1 -1
  51. package/dist/lib/config-write-target.js +5 -2
  52. package/dist/lib/config.d.ts +2 -1
  53. package/dist/lib/config.js +193 -2
  54. package/dist/lib/copilot.js +171 -86
  55. package/dist/lib/dashboard-web-policy.d.ts +4 -4
  56. package/dist/lib/dashboard-web-policy.js +2 -2
  57. package/dist/lib/deepseek.js +25 -13
  58. package/dist/lib/display-sanitize.js +1 -0
  59. package/dist/lib/entries.d.ts +23 -0
  60. package/dist/lib/entries.js +2 -0
  61. package/dist/lib/glm-coding-plan.js +98 -74
  62. package/dist/lib/google-agy.js +90 -12
  63. package/dist/lib/google-gemini-cli.js +84 -11
  64. package/dist/lib/http.d.ts +4 -0
  65. package/dist/lib/http.js +16 -2
  66. package/dist/lib/init-installer.js +5 -3
  67. package/dist/lib/kilo.js +37 -18
  68. package/dist/lib/kimi.js +35 -18
  69. package/dist/lib/mimo.d.ts +2 -0
  70. package/dist/lib/mimo.js +36 -0
  71. package/dist/lib/nanogpt.d.ts +1 -0
  72. package/dist/lib/nanogpt.js +26 -3
  73. package/dist/lib/ollama-cloud.d.ts +1 -1
  74. package/dist/lib/ollama-cloud.js +48 -35
  75. package/dist/lib/openai.js +84 -38
  76. package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
  77. package/dist/lib/opencode-auth-sqlite.js +2 -2
  78. package/dist/lib/opencode-config-editor.d.ts +1 -0
  79. package/dist/lib/opencode-config-editor.js +6 -1
  80. package/dist/lib/opencode-go.js +29 -2
  81. package/dist/lib/opencode-version-core.d.ts +23 -0
  82. package/dist/lib/opencode-version-core.js +49 -0
  83. package/dist/lib/opencode-version.d.ts +2 -22
  84. package/dist/lib/opencode-version.js +4 -48
  85. package/dist/lib/opencode-zen.d.ts +3 -0
  86. package/dist/lib/opencode-zen.js +71 -5
  87. package/dist/lib/provider-add.js +5 -2
  88. package/dist/lib/provider-registration.d.ts +19 -9
  89. package/dist/lib/provider-registration.js +17 -6
  90. package/dist/lib/quota-command-format.js +1 -1
  91. package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
  92. package/dist/lib/quota-exhaustion-projection.js +25 -0
  93. package/dist/lib/quota-providers-remote.d.ts +2 -1
  94. package/dist/lib/quota-providers-remote.js +59 -3
  95. package/dist/lib/quota-providers.d.ts +1 -1
  96. package/dist/lib/quota-providers.js +12 -35
  97. package/dist/lib/quota-render-data.d.ts +6 -0
  98. package/dist/lib/quota-render-data.js +43 -17
  99. package/dist/lib/quota-state-codec.js +17 -1
  100. package/dist/lib/quota-state.d.ts +7 -1
  101. package/dist/lib/quota-state.js +208 -34
  102. package/dist/lib/quota-stats.js +21 -0
  103. package/dist/lib/quota-status.js +3 -51
  104. package/dist/lib/scoped-update.d.ts +1 -1
  105. package/dist/lib/synthetic.js +65 -54
  106. package/dist/lib/types.d.ts +31 -1
  107. package/dist/lib/types.js +13 -0
  108. package/dist/lib/xai.js +48 -22
  109. package/dist/plugin.js +261 -13
  110. package/dist/provider-logos/NOTICE.md +1 -1
  111. package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
  112. package/dist/providers/alibaba-coding-plan.js +107 -104
  113. package/dist/providers/anthropic.d.ts +12 -3
  114. package/dist/providers/anthropic.js +71 -228
  115. package/dist/providers/cache-policies.d.ts +11 -4
  116. package/dist/providers/cache-policies.js +19 -13
  117. package/dist/providers/claude-agent.d.ts +19 -0
  118. package/dist/providers/claude-agent.js +196 -0
  119. package/dist/providers/copilot.js +2 -0
  120. package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
  121. package/dist/providers/google-account-format.js +1 -0
  122. package/dist/providers/google-agy.d.ts +6 -5
  123. package/dist/providers/google-agy.js +43 -15
  124. package/dist/providers/google-gemini-cli.js +1 -0
  125. package/dist/providers/kilo.js +1 -0
  126. package/dist/providers/kimi-code.js +2 -0
  127. package/dist/providers/mimo.js +1 -0
  128. package/dist/providers/nanogpt.js +1 -0
  129. package/dist/providers/opencode-go.js +3 -0
  130. package/dist/providers/opencode-zen.js +2 -0
  131. package/dist/providers/openrouter.js +1 -0
  132. package/dist/providers/quota-providers.js +16 -5
  133. package/dist/providers/registry.js +2 -0
  134. package/dist/providers/result-helpers.d.ts +2 -0
  135. package/dist/providers/result-helpers.js +2 -0
  136. package/dist/rpc.d.ts +121 -8
  137. package/dist/rpc.js +204 -12
  138. package/dist/ui/assets/{index-cDd9jUVY.css → index-BcueIm3Z.css} +1 -1
  139. package/dist/ui/assets/index-C6qRSoh8.js +10 -0
  140. package/dist/ui/assets/{popover-BGkgv9s0.js → popover-4bFSvRZ7.js} +1 -1
  141. package/dist/ui/assets/providers/claude-agent.svg +3 -0
  142. package/dist/ui/index.html +2 -2
  143. package/package.json +44 -45
  144. package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
  145. package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
  146. package/dist/ui/assets/index-DLHeXYff.js +0 -9
@@ -48,6 +48,7 @@ export function formatGoogleAccountErrors(errors, style, labels) {
48
48
  label: (error.email && labels?.get(error.email)) ?? formatGoogleAccountLabel(error.email, style),
49
49
  message: error.error,
50
50
  ...(error.failureCategory !== undefined ? { failureCategory: error.failureCategory } : {}),
51
+ ...(error.retryAtMs !== undefined ? { retryAtMs: error.retryAtMs } : {}),
51
52
  }));
52
53
  }
53
54
  //# sourceMappingURL=google-account-format.js.map
@@ -1,15 +1,16 @@
1
1
  import type { QuotaProvider, QuotaProviderAccount } from "../lib/entries.js";
2
- import type { GoogleAgyQuotaBucket } from "../lib/types.js";
2
+ import type { GoogleAccountError, GoogleAgyQuotaBucket } from "../lib/types.js";
3
3
  /** Stable explicit row key for one AGY bucket row (family + window; never the label). */
4
4
  export declare function agyBucketRowKey(bucket: Pick<GoogleAgyQuotaBucket, "family" | "window">): string;
5
5
  /**
6
- * Accounts of the legacy companion path (no `CredentialRow`). `sourceId` keeps
7
- * the historical `account-N` ordinal byte-identical for reset/cache
8
- * compatibility; when the bucket carries an email the descriptor adds a
9
- * server-only email digest as `identityKey`. No key is derived from an ordinal.
6
+ * Legacy companion accounts have no `CredentialRow`. `sourceId` keeps the
7
+ * historical `account-N` value for reset/cache compatibility; email-backed
8
+ * descriptors use a server-only digest identity, while missing emails retain
9
+ * the existing source-id identity fallback.
10
10
  */
11
11
  export declare function buildAgyLegacyAccounts(params: {
12
12
  buckets: readonly GoogleAgyQuotaBucket[];
13
+ errors?: readonly GoogleAccountError[];
13
14
  accountLabels: ReadonlyMap<string, string>;
14
15
  }): QuotaProviderAccount[];
15
16
  export declare function formatAgyCredentialGroup(credentialName: string, familyLabel: string): string;
@@ -72,25 +72,43 @@ export function agyBucketRowKey(bucket) {
72
72
  return `named:${bucket.family} ${bucket.window}`;
73
73
  }
74
74
  /**
75
- * Accounts of the legacy companion path (no `CredentialRow`). `sourceId` keeps
76
- * the historical `account-N` ordinal byte-identical for reset/cache
77
- * compatibility; when the bucket carries an email the descriptor adds a
78
- * server-only email digest as `identityKey`. No key is derived from an ordinal.
75
+ * Legacy companion accounts have no `CredentialRow`. `sourceId` keeps the
76
+ * historical `account-N` value for reset/cache compatibility; email-backed
77
+ * descriptors use a server-only digest identity, while missing emails retain
78
+ * the existing source-id identity fallback.
79
79
  */
80
80
  export function buildAgyLegacyAccounts(params) {
81
81
  const accounts = new Map();
82
82
  for (const bucket of [...params.buckets].sort(compareBuckets)) {
83
- const sourceId = `account-${bucket.accountIndex + 1}`;
84
- if (accounts.has(sourceId))
83
+ if (!accounts.has(bucket.accountIndex))
84
+ accounts.set(bucket.accountIndex, bucket);
85
+ }
86
+ for (const error of params.errors ?? []) {
87
+ const accountIndex = error.accountIndex;
88
+ if (accountIndex === undefined ||
89
+ !Number.isInteger(accountIndex) ||
90
+ accountIndex < 0 ||
91
+ accounts.has(accountIndex)) {
85
92
  continue;
86
- const email = bucket.accountEmail;
87
- accounts.set(sourceId, {
88
- sourceId,
89
- ...(email ? { identityKey: deriveStableAccountIdentityKey(email) } : {}),
90
- label: formatAgyAccountLabel(bucket, params.accountLabels),
93
+ }
94
+ accounts.set(accountIndex, {
95
+ ...(AGY_AUTH_KEYS.some((sourceKey) => sourceKey === error.email)
96
+ ? {}
97
+ : { accountEmail: error.email }),
98
+ accountIndex,
91
99
  });
92
100
  }
93
- return [...accounts.values()];
101
+ return [...accounts.values()]
102
+ .sort((left, right) => left.accountIndex - right.accountIndex)
103
+ .map((account) => {
104
+ const sourceId = `account-${account.accountIndex + 1}`;
105
+ const email = account.accountEmail;
106
+ return {
107
+ sourceId,
108
+ ...(email ? { identityKey: deriveStableAccountIdentityKey(email) } : {}),
109
+ label: formatAgyAccountLabel(account, params.accountLabels),
110
+ };
111
+ });
94
112
  }
95
113
  export function formatAgyCredentialGroup(credentialName, familyLabel) {
96
114
  const trimmed = credentialName.trim();
@@ -205,6 +223,7 @@ export const googleAgyProvider = {
205
223
  ...(error.failureCategory !== undefined
206
224
  ? { failureCategory: error.failureCategory }
207
225
  : {}),
226
+ ...(error.retryAtMs !== undefined ? { retryAtMs: error.retryAtMs } : {}),
208
227
  })));
209
228
  }
210
229
  return withStatusDetails({ ...attemptedResult(entries, errors, { singleWindowShowRight: true }), accounts }, statusDetails);
@@ -227,7 +246,11 @@ export const googleAgyProvider = {
227
246
  ...sortedBuckets.map((bucket) => bucket.accountEmail),
228
247
  ...(result.errors ?? []).map((error) => error.email),
229
248
  ], "domainHint");
230
- const legacyAccounts = buildAgyLegacyAccounts({ buckets: sortedBuckets, accountLabels });
249
+ const legacyAccounts = buildAgyLegacyAccounts({
250
+ buckets: sortedBuckets,
251
+ errors: result.errors,
252
+ accountLabels,
253
+ });
231
254
  const sourceIdByEmail = new Map(sortedBuckets.flatMap((bucket) => bucket.accountEmail
232
255
  ? [[bucket.accountEmail, `account-${bucket.accountIndex + 1}`]]
233
256
  : []));
@@ -253,8 +276,13 @@ export const googleAgyProvider = {
253
276
  };
254
277
  });
255
278
  const errors = formatGoogleAccountErrors(result.errors, "domainHint", accountLabels).map((error, index) => {
256
- const email = result.errors?.[index]?.email;
257
- const sourceId = email ? sourceIdByEmail.get(email) : undefined;
279
+ const failed = result.errors?.[index];
280
+ // Same `account-N` ids the entries use, so a failed account keeps its previous rows.
281
+ const sourceId = failed?.accountIndex !== undefined
282
+ ? `account-${failed.accountIndex + 1}`
283
+ : failed?.email
284
+ ? sourceIdByEmail.get(failed.email)
285
+ : undefined;
258
286
  return sourceId ? { ...error, sourceId } : error;
259
287
  });
260
288
  return withStatusDetails({
@@ -158,6 +158,7 @@ export const googleGeminiCliProvider = {
158
158
  ...(error.failureCategory !== undefined
159
159
  ? { failureCategory: error.failureCategory }
160
160
  : {}),
161
+ ...(error.retryAtMs !== undefined ? { retryAtMs: error.retryAtMs } : {}),
161
162
  })));
162
163
  }
163
164
  return withStatusDetails({
@@ -134,6 +134,7 @@ export const kiloProvider = {
134
134
  {
135
135
  label: "Kilo Gateway",
136
136
  message: stateResult.error,
137
+ ...(stateResult.retryAtMs !== undefined ? { retryAtMs: stateResult.retryAtMs } : {}),
137
138
  ...(stateResult.failureCategory !== undefined
138
139
  ? { failureCategory: stateResult.failureCategory }
139
140
  : {}),
@@ -92,6 +92,7 @@ function createKimiProvider(spec) {
92
92
  message: result.error,
93
93
  sourceId: row.id,
94
94
  failureCategory: result.failureCategory,
95
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
95
96
  });
96
97
  continue;
97
98
  }
@@ -127,6 +128,7 @@ function createKimiProvider(spec) {
127
128
  if (!result.success) {
128
129
  return withStatusDetails(attemptedErrorResult(spec.label, result.error, {
129
130
  failureCategory: result.failureCategory,
131
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
130
132
  }), [...authDetails, { key: "live_fetch_error", value: result.error }]);
131
133
  }
132
134
  const entries = result.windows.map((window) => ({
@@ -74,6 +74,7 @@ function endpointErrors(result) {
74
74
  label: MIMO_LABEL,
75
75
  message: endpoint.error,
76
76
  failureCategory: endpoint.failureCategory,
77
+ ...(endpoint.retryAtMs !== undefined ? { retryAtMs: endpoint.retryAtMs } : {}),
77
78
  });
78
79
  }
79
80
  }
@@ -66,6 +66,7 @@ function mapNanoGptSuccess(result) {
66
66
  const errors = result.endpointErrors?.map((entry) => ({
67
67
  label: entry.endpoint === "usage" ? "NanoGPT Usage" : "NanoGPT Balance",
68
68
  message: entry.message,
69
+ ...(entry.retryAtMs !== undefined ? { retryAtMs: entry.retryAtMs } : {}),
69
70
  ...(entry.failureCategory !== undefined ? { failureCategory: entry.failureCategory } : {}),
70
71
  })) ?? [];
71
72
  const subscription = result.subscription;
@@ -192,6 +192,7 @@ async function fetchOpenCodeGoConsoleAccounts(ctx, windows, consoleAccounts) {
192
192
  retryable: result.retryable,
193
193
  sourceId: account.sourceId,
194
194
  failureCategory: result.failureCategory,
195
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
195
196
  });
196
197
  fetchErrorsBySourceId.set(account.sourceId, result.error);
197
198
  accounts.push(consoleAccountDescriptor(account));
@@ -352,6 +353,7 @@ async function fetchOpenCodeGoLegacy(ctx, diagnostics, statusDetails) {
352
353
  retryable: result.retryable,
353
354
  sourceId: row.id,
354
355
  failureCategory: result.failureCategory,
356
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
355
357
  });
356
358
  }
357
359
  const attemptedSourceIds = new Set([
@@ -401,6 +403,7 @@ async function fetchOpenCodeGoLegacy(ctx, diagnostics, statusDetails) {
401
403
  return withStatusDetails(attemptedErrorResult(OPENCODE_GO_PROVIDER_LABEL, result.error, {
402
404
  retryable: result.retryable,
403
405
  failureCategory: result.failureCategory,
406
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
404
407
  }), [...baseStatusDetails, { key: "live_fetch_error", value: result.error }]);
405
408
  }
406
409
  const liveDetails = OPENCODE_GO_WINDOW_ORDER.map((window) => {
@@ -208,6 +208,7 @@ async function fetchOpenCodeZenConsoleAccounts(ctx, consoleAccounts) {
208
208
  ...(result.failureCategory !== undefined
209
209
  ? { failureCategory: result.failureCategory }
210
210
  : {}),
211
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
211
212
  });
212
213
  statusDetails.push({
213
214
  key: `live_fetch_error:${account.sourceId}`,
@@ -230,6 +231,7 @@ async function fetchOpenCodeZenConsoleAccounts(ctx, consoleAccounts) {
230
231
  ...(optionalError.failureCategory !== undefined
231
232
  ? { failureCategory: optionalError.failureCategory }
232
233
  : {}),
234
+ ...(optionalError.retryAtMs !== undefined ? { retryAtMs: optionalError.retryAtMs } : {}),
233
235
  });
234
236
  }
235
237
  }
@@ -69,6 +69,7 @@ export const openRouterProvider = {
69
69
  errors.push({
70
70
  label: account.label,
71
71
  message: result.error,
72
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
72
73
  failureCategory: result.failureCategory,
73
74
  ...(account.sourceId ? { sourceId: account.sourceId } : {}),
74
75
  });
@@ -2,7 +2,7 @@ import { mapWithConcurrency } from "../lib/map-with-concurrency.js";
2
2
  import { customQuotaProviderDefinitions, QUOTA_PROVIDERS_AGGREGATE_ID, resolveQuotaProviderSessionModelIdentity, selectEligibleQuotaProviderDefinitions, } from "../lib/quota-providers.js";
3
3
  import { collectLocalQuotaProviderEstimate, inspectLocalQuotaProviderState, } from "../lib/quota-providers-local.js";
4
4
  import { fetchRemoteQuotaProvider, QUOTA_PROVIDER_CONCURRENCY, resolveQuotaProviderApiKey, } from "../lib/quota-providers-remote.js";
5
- import { fetchQuotaProviderResult } from "../lib/quota-state.js";
5
+ import { fetchQuotaProviderResult, QUOTA_FORCE_REFRESH } from "../lib/quota-state.js";
6
6
  import { resolveQuotaProviderDefinitionAuthIdentity } from "./cache-policies.js";
7
7
  export const QUOTA_PROVIDERS_PROVIDER_ID = QUOTA_PROVIDERS_AGGREGATE_ID;
8
8
  export const selectEligibleQuotaProviders = selectEligibleQuotaProviderDefinitions;
@@ -19,6 +19,12 @@ function matchesConfiguredCurrentSelection(model, context) {
19
19
  async function getAvailableProviderIds(ctx) {
20
20
  return ctx.resolveRuntimeProviderIds();
21
21
  }
22
+ function configuredDefinitions(ctx) {
23
+ return ctx.config.quotaProviders ?? [];
24
+ }
25
+ function selectedDefinitionsStillCurrent(selected, current) {
26
+ return selected.filter((definition) => current.some((candidate) => candidate.id === definition.id));
27
+ }
22
28
  function buildDiagnosticIdentity(definition) {
23
29
  return {
24
30
  sourceId: definition.id,
@@ -93,6 +99,7 @@ async function executeRemote(definition, requestTimeoutMs) {
93
99
  {
94
100
  label: definition.label,
95
101
  message: result.error,
102
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
96
103
  ...(result.failureCategory !== undefined
97
104
  ? { failureCategory: result.failureCategory }
98
105
  : {}),
@@ -135,7 +142,7 @@ async function executeRemoteWithCache(definition, ctx) {
135
142
  isAvailable: async () => true,
136
143
  cachePolicy: {
137
144
  kind: "resolved-auth",
138
- resolveIdentity: () => resolveQuotaProviderDefinitionAuthIdentity(definition),
145
+ resolveIdentity: (_cacheCtx) => resolveQuotaProviderDefinitionAuthIdentity(definition),
139
146
  },
140
147
  fetch: async () => {
141
148
  const result = await executeRemote(definition, ctx.config.requestTimeoutMs);
@@ -157,6 +164,7 @@ async function executeRemoteWithCache(definition, ctx) {
157
164
  },
158
165
  },
159
166
  ttlMs: ctx.config.providerCacheTtlMs ?? 0,
167
+ forceRefresh: ctx.operationCache?.get(QUOTA_FORCE_REFRESH) === true,
160
168
  });
161
169
  return {
162
170
  entries: result.entries,
@@ -227,7 +235,7 @@ async function executeDefinition(definition, ctx) {
227
235
  export const quotaProvidersProvider = {
228
236
  id: QUOTA_PROVIDERS_PROVIDER_ID,
229
237
  async isAvailable(ctx) {
230
- const definitions = ctx.config.quotaProviders ?? [];
238
+ const definitions = configuredDefinitions(ctx);
231
239
  if (customQuotaProviderDefinitions(definitions).length === 0)
232
240
  return false;
233
241
  const availableProviderIds = await getAvailableProviderIds(ctx);
@@ -243,12 +251,15 @@ export const quotaProvidersProvider = {
243
251
  return matchesConfiguredCurrentSelection(model, context);
244
252
  },
245
253
  async fetch(ctx, cacheContext) {
246
- const definitions = ctx.config.quotaProviders ?? [];
254
+ const definitions = configuredDefinitions(ctx);
247
255
  if (customQuotaProviderDefinitions(definitions).length === 0) {
248
256
  return { attempted: false, entries: [], errors: [] };
249
257
  }
250
258
  let selected = cacheContext?.runtimeEligibleQuotaProviders;
251
- if (!selected) {
259
+ if (selected) {
260
+ selected = selectedDefinitionsStillCurrent(selected, definitions);
261
+ }
262
+ else {
252
263
  let availableProviderIds;
253
264
  try {
254
265
  availableProviderIds = await getAvailableProviderIds(ctx);
@@ -10,6 +10,7 @@ import { alibabaTokenPlanProvider } from "./alibaba-token-plan.js";
10
10
  import { anthropicProvider } from "./anthropic.js";
11
11
  import { PROVIDER_CACHE_POLICIES } from "./cache-policies.js";
12
12
  import { chutesProvider } from "./chutes.js";
13
+ import { claudeAgentProvider } from "./claude-agent.js";
13
14
  import { copilotProvider } from "./copilot.js";
14
15
  import { cursorProvider } from "./cursor.js";
15
16
  import { deepseekProvider } from "./deepseek.js";
@@ -32,6 +33,7 @@ import { zaiProvider } from "./zai.js";
32
33
  import { zhipuProvider } from "./zhipu.js";
33
34
  const PROVIDERS_BY_ID = {
34
35
  anthropic: anthropicProvider,
36
+ "claude-agent": claudeAgentProvider,
35
37
  copilot: copilotProvider,
36
38
  openai: openaiProvider,
37
39
  openrouter: openRouterProvider,
@@ -5,6 +5,7 @@ export declare function attemptedResult(entries: QuotaToastEntry[], errors?: Quo
5
5
  export declare function attemptedErrorResult(label: string, message: string, options?: {
6
6
  retryable?: boolean;
7
7
  failureCategory?: ProviderFailureCategory;
8
+ retryAtMs?: number;
8
9
  }): QuotaProviderResult;
9
10
  export declare function statusDetailsFromRecord(values: Readonly<Record<string, string | undefined>>): QuotaProviderStatusDetail[];
10
11
  export declare function configStatusDetails(diagnostics: {
@@ -40,6 +41,7 @@ export declare function mapNullableProviderResult<TResult extends {
40
41
  success: false;
41
42
  error: string;
42
43
  retryable?: boolean;
44
+ retryAtMs?: number;
43
45
  failureCategory?: ProviderFailureCategory;
44
46
  } | null>(result: TResult, params: {
45
47
  errorLabel: string;
@@ -17,6 +17,7 @@ export function attemptedErrorResult(label, message, options = {}) {
17
17
  label,
18
18
  message,
19
19
  ...(options.retryable === true ? { retryable: true } : {}),
20
+ ...(options.retryAtMs !== undefined ? { retryAtMs: options.retryAtMs } : {}),
20
21
  ...(options.failureCategory !== undefined
21
22
  ? { failureCategory: options.failureCategory }
22
23
  : {}),
@@ -97,6 +98,7 @@ export function mapNullableProviderResult(result, params) {
97
98
  if (!result.success) {
98
99
  return attemptedErrorResult(params.errorLabel, result.error, {
99
100
  ...(result.retryable === true ? { retryable: true } : {}),
101
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
100
102
  ...((result.failureCategory ?? params.failureCategory) !== undefined
101
103
  ? { failureCategory: result.failureCategory ?? params.failureCategory }
102
104
  : {}),
package/dist/rpc.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The plugin RPC definitions. `QuotaRpc` is the inherited TUI contract (still
3
- * used by the retained TUI source, but no longer registered by the GUI-only
4
- * server plugin). `DashboardRpc` is the Stage 3 typed dashboard contract the
2
+ * The plugin RPC definitions. `QuotaRpc` is a legacy terminal-client contract
3
+ * retained for compatibility, but is not registered by the GUI-only server
4
+ * plugin. `DashboardRpc` is the typed dashboard contract the
5
5
  * server plugin registers for native clients. Imports from `@opencode/*` stay
6
6
  * type-only, so loading this file loads no OpenCode package.
7
7
  */
@@ -106,6 +106,8 @@ export type DashboardRpcImportApplyInput = {
106
106
  };
107
107
  export type DashboardRpcWatchInput = {
108
108
  scope: DashboardRpcViewScope;
109
+ /** Optional for older callers; Native uses it to correlate the source cutover snapshot. */
110
+ attemptNonce?: string;
109
111
  };
110
112
  export type DashboardRpcWatchOutput = {
111
113
  active: boolean;
@@ -113,10 +115,113 @@ export type DashboardRpcWatchOutput = {
113
115
  export type DashboardRpcOpenSettingsOutput = {
114
116
  opened: true;
115
117
  };
118
+ export type DashboardRpcCacheObserverEvent = {
119
+ type: "session.step.started";
120
+ created: number;
121
+ data: {
122
+ sessionID: string;
123
+ assistantMessageID: string;
124
+ /** OpenCode's selected model identity, not the resolved HTTP request route. */
125
+ model: {
126
+ providerID: string;
127
+ id: string;
128
+ variant?: string;
129
+ };
130
+ /** Captured before `llm.stream`; event.created is emitted at first output instead. */
131
+ started?: number;
132
+ connectionMethod?: "oauth" | "key" | "external";
133
+ };
134
+ } | {
135
+ type: "session.step.ended";
136
+ created: number;
137
+ data: {
138
+ sessionID: string;
139
+ assistantMessageID: string;
140
+ tokens: {
141
+ input?: number;
142
+ cache?: {
143
+ read?: number;
144
+ write?: number;
145
+ };
146
+ };
147
+ };
148
+ } | {
149
+ /**
150
+ * One completed Claude Agent invocation whose cache writes were observed as 1-hour-only.
151
+ * Carries no transcript content, path or native id.
152
+ */
153
+ type: "session.cache.ttl";
154
+ created: number;
155
+ data: {
156
+ sessionID: string;
157
+ assistantMessageID: string;
158
+ ttlMs: 3_600_000;
159
+ };
160
+ } | {
161
+ type: "session.created";
162
+ data: {
163
+ sessionID: string;
164
+ parentID: string;
165
+ };
166
+ } | {
167
+ type: "session.forked";
168
+ data: {
169
+ sessionID: string;
170
+ parentID?: string;
171
+ };
172
+ } | {
173
+ type: "session.compaction.ended" | "session.deleted";
174
+ data: {
175
+ sessionID: string;
176
+ };
177
+ } | {
178
+ /**
179
+ * Authoritative session execution state, projected from the host's own
180
+ * `session.status`, `session.idle` and `session.execution.*` events.
181
+ * Carries no message, error or credential content.
182
+ */
183
+ type: "session.status";
184
+ created: number;
185
+ data: {
186
+ sessionID: string;
187
+ state: "busy" | "idle";
188
+ };
189
+ } | {
190
+ /**
191
+ * Narrow session-identity update, projected from the host's own
192
+ * `session.renamed`, `session.agent.selected` and `session.model.selected`
193
+ * events. Only display-identity fields are carried, and only those the
194
+ * source event contains; `created` is the host timestamp that dates the
195
+ * change for recency ordering.
196
+ */
197
+ type: "session.metadata";
198
+ created: number;
199
+ data: {
200
+ sessionID: string;
201
+ title?: string;
202
+ agent?: string;
203
+ model?: {
204
+ providerID: string;
205
+ id: string;
206
+ variant?: string;
207
+ };
208
+ };
209
+ } | {
210
+ type: "source.status";
211
+ created: number;
212
+ data: {
213
+ state: "unverified" | "observed" | "unavailable" | "stopped";
214
+ /** Present only on a source snapshot requested by an active watch attempt. */
215
+ attemptNonce?: string;
216
+ /** Opaque identity of the setup-owned host-event source that emitted this state. */
217
+ sourceBinding?: string;
218
+ };
219
+ };
116
220
  export type DashboardRpcEventData = {
117
- topic: DashboardEventTopic;
221
+ topic: DashboardEventTopic | "cache.observer";
118
222
  at: number;
119
223
  scope?: "visibility";
224
+ cacheObserverEvent?: DashboardRpcCacheObserverEvent;
120
225
  };
121
226
  export type DashboardRpcQuotaNotificationKind = "low" | "exhausted" | "reset" | "provider-error";
122
227
  /**
@@ -153,9 +258,8 @@ declare const DASHBOARD_RPC_ERRORS: {
153
258
  export type DashboardRpcErrorCode = keyof typeof DASHBOARD_RPC_ERRORS;
154
259
  export type DashboardRpcMethod = (typeof DashboardRpc.methods)[keyof typeof DashboardRpc.methods];
155
260
  /**
156
- * The explicit typed dashboard RPC. Every method maps to one `DashboardDataSource`
157
- * operation (plus the transport-lifecycle `watch` method); there is deliberately
158
- * no generic dispatch/call method.
261
+ * The explicit typed dashboard RPC. Methods map to a dashboard data-source or
262
+ * user settings-store operation (plus `watch`); there is no generic dispatch.
159
263
  */
160
264
  export declare const DashboardRpc: {
161
265
  id: string;
@@ -185,7 +289,9 @@ export declare const DashboardRpc: {
185
289
  };
186
290
  };
187
291
  quota: {
188
- input: QuotaRpcSchema<DashboardRpcNoInput>;
292
+ input: QuotaRpcSchema<{
293
+ refresh?: boolean;
294
+ }>;
189
295
  output: QuotaRpcSchema<import("./contracts/dashboard.js").QuotaSnapshot>;
190
296
  errors: {
191
297
  readonly "bad-request": QuotaRpcSchema<DashboardRpcErrorDetails>;
@@ -391,5 +497,12 @@ export declare const DASHBOARD_HEALTH: DashboardHealth;
391
497
  * unsafe payload is dropped before it can reach a window's presenter.
392
498
  */
393
499
  export declare function isDashboardRpcQuotaNotificationData(value: unknown): value is DashboardRpcQuotaNotificationData;
500
+ /** Strict runtime validation for the narrow, content-free cache observer event DTO. */
501
+ export declare function isDashboardRpcCacheObserverEvent(value: unknown): value is DashboardRpcCacheObserverEvent;
502
+ /** Strict guard for cache observer DTOs wrapped in the existing invalidation event envelope. */
503
+ export declare function isDashboardRpcCacheObserverEventData(value: unknown): value is DashboardRpcEventData & {
504
+ topic: "cache.observer";
505
+ cacheObserverEvent: DashboardRpcCacheObserverEvent;
506
+ };
394
507
  export {};
395
508
  //# sourceMappingURL=rpc.d.ts.map