@bitkyc08/opencodex 2.100.0 → 2.100.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.
Files changed (178) hide show
  1. package/gui/dist/assets/App-BpJOzw4F.js +59 -0
  2. package/gui/dist/assets/Tray-BcaI-VCr.js +1 -0
  3. package/gui/dist/assets/brand-mark-DU-0Vdkr.js +1 -0
  4. package/gui/dist/assets/index-Bbor_y80.js +94 -0
  5. package/gui/dist/assets/index-DJEkIDAi.css +2 -0
  6. package/gui/dist/assets/{segment-thumb-features-CcxZBnxv.js → segment-thumb-features-e9A_FogJ.js} +1 -1
  7. package/gui/dist/classic/assets/{App-aYgIQMxI.js → App-BrIlUiLc.js} +18 -18
  8. package/gui/dist/classic/assets/{Tray-D8jfUXpQ.js → Tray-DT146AhS.js} +1 -1
  9. package/gui/dist/classic/assets/index-DyJHagvT.js +94 -0
  10. package/gui/dist/classic/assets/quota-summary-CakPe9Ni.js +1 -0
  11. package/gui/dist/classic/index.html +1 -1
  12. package/gui/dist/index.html +2 -2
  13. package/package.json +2 -2
  14. package/src/adapters/anthropic-image-normalize.ts +1 -1
  15. package/src/adapters/client-fingerprint.ts +6 -4
  16. package/src/adapters/cursor/native-exec.ts +3 -2
  17. package/src/adapters/cursor/tool-guidance.ts +3 -3
  18. package/src/adapters/cursor/tool-wording.ts +10 -1
  19. package/src/adapters/devin/cloud-direct/tool-schema.ts +20 -2
  20. package/src/adapters/google-antigravity-wire.ts +13 -6
  21. package/src/adapters/google-truncation.ts +4 -2
  22. package/src/adapters/google.ts +8 -2
  23. package/src/adapters/openai-chat/mistral-image-limit.ts +28 -15
  24. package/src/adapters/openai-chat/tool-schema.ts +9 -0
  25. package/src/adapters/openai-chat-images.ts +100 -0
  26. package/src/adapters/openai-chat.ts +6 -9
  27. package/src/adapters/openai-responses/tool-schema.ts +18 -4
  28. package/src/adapters/run-turn-queue.ts +139 -5
  29. package/src/adapters/upstream-http-error.ts +4 -2
  30. package/src/bridge/sse.ts +8 -1
  31. package/src/claude/chat-tool-dispatch.ts +233 -0
  32. package/src/claude/inbound-tool-loading.ts +42 -17
  33. package/src/cli/account-api.ts +6 -0
  34. package/src/cli/account-extended.ts +60 -6
  35. package/src/cli/account-key-quota.ts +22 -2
  36. package/src/cli/account.ts +1 -1
  37. package/src/cli/capabilities-access-remote.ts +10 -0
  38. package/src/cli/capabilities-agents-routing.ts +2 -2
  39. package/src/cli/capabilities-base.ts +2 -2
  40. package/src/cli/claude.ts +19 -14
  41. package/src/cli/config-command.ts +24 -1
  42. package/src/cli/connect.ts +36 -3
  43. package/src/cli/gui-pair-client.ts +23 -2
  44. package/src/cli/help.ts +1 -1
  45. package/src/cli/hub.ts +18 -1
  46. package/src/cli/link-child-ops.ts +136 -0
  47. package/src/cli/link-status-child.ts +94 -0
  48. package/src/cli/link.ts +22 -9
  49. package/src/cli/registry.ts +3 -2
  50. package/src/cli/sync-command.ts +3 -1
  51. package/src/cli/sync-fanout.ts +8 -81
  52. package/src/client/link-readiness.ts +16 -6
  53. package/src/client/link-tunnel-status.ts +76 -0
  54. package/src/clients/config-export.ts +14 -1
  55. package/src/codex/account-resume-health.ts +41 -0
  56. package/src/codex/auth-api/login-flow.ts +6 -0
  57. package/src/codex/auth-api/routes.ts +35 -2
  58. package/src/codex/catalog/gather-capture.ts +2 -0
  59. package/src/codex/catalog/provider-models.ts +13 -8
  60. package/src/codex/convergence-types.ts +2 -0
  61. package/src/codex/quota.ts +111 -6
  62. package/src/combos/cooldown-store.ts +208 -0
  63. package/src/combos/failover.ts +432 -35
  64. package/src/config/salvage.ts +1 -0
  65. package/src/config/schema/config-schema.ts +6 -3
  66. package/src/config/schema/leaf-validators.ts +34 -12
  67. package/src/generated/compatibility-version.json +227 -135
  68. package/src/lib/catalog-etag.ts +10 -0
  69. package/src/lib/client-error-body.ts +15 -0
  70. package/src/lib/config-ownership.ts +9 -2
  71. package/src/lib/context-overflow-verdict.ts +266 -9
  72. package/src/lib/failure-detail.ts +72 -3
  73. package/src/lib/hard-refusal.ts +259 -0
  74. package/src/link/child-activity.ts +57 -0
  75. package/src/link/child-catalog-freshness.ts +149 -0
  76. package/src/link/child-gated-ocx.ts +117 -0
  77. package/src/link/child-observations.ts +205 -0
  78. package/src/link/child-observe.ts +121 -0
  79. package/src/link/child-ops-engine.ts +162 -0
  80. package/src/link/child-update-contract.ts +165 -0
  81. package/src/link/paths.ts +5 -0
  82. package/src/link/remote-windows.ts +42 -6
  83. package/src/link/ssh-argv.ts +126 -32
  84. package/src/link/status-projection.ts +73 -0
  85. package/src/link/sync-fanout-classify.ts +98 -0
  86. package/src/link/tunnel-state.ts +10 -4
  87. package/src/messaging/mcp-queue-rpc.ts +2 -1
  88. package/src/messaging/mcp-queue-server.ts +5 -0
  89. package/src/messaging/mcp-reply-tools.ts +24 -9
  90. package/src/messaging/mcp-reply-wait.ts +70 -0
  91. package/src/oauth/account-resume-health.ts +60 -0
  92. package/src/oauth/anthropic-model-quota.ts +12 -0
  93. package/src/oauth/anthropic-routing.ts +11 -4
  94. package/src/oauth/index.ts +1 -0
  95. package/src/oauth/kiro-iam-identity-center.ts +4 -1
  96. package/src/oauth/store.ts +44 -1
  97. package/src/providers/api-key-pause-state.ts +23 -0
  98. package/src/providers/api-key-pause.ts +68 -10
  99. package/src/providers/api-key-selection-capture.ts +3 -1
  100. package/src/providers/api-key-selection.ts +3 -2
  101. package/src/providers/api-keys.ts +18 -5
  102. package/src/providers/claude-cli-identity.ts +9 -3
  103. package/src/providers/claude-cli-usage-state.ts +11 -6
  104. package/src/providers/claude-cli-usage.ts +27 -8
  105. package/src/providers/codex-capacity.ts +11 -2
  106. package/src/providers/key-failover.ts +13 -6
  107. package/src/providers/model-discovery-config.ts +31 -0
  108. package/src/providers/model-discovery-diagnostic.ts +34 -3
  109. package/src/providers/model-discovery.ts +43 -7
  110. package/src/providers/model-rename-fields.ts +2 -0
  111. package/src/providers/openai-sidecar.ts +15 -2
  112. package/src/providers/provider-id-rewrite.ts +3 -0
  113. package/src/providers/quota/account-cache.ts +52 -34
  114. package/src/providers/quota/anthropic-family-headers.ts +8 -1
  115. package/src/providers/quota/anthropic-usage-windows.ts +66 -9
  116. package/src/providers/quota/report-cache.ts +53 -5
  117. package/src/providers/quota/vendor-probes-key.ts +73 -0
  118. package/src/providers/quota/vendor-probes-oauth.ts +57 -3
  119. package/src/providers/quota-key-accounts.ts +12 -5
  120. package/src/providers/quota-mistral-budget.ts +18 -0
  121. package/src/providers/quota-types.ts +32 -0
  122. package/src/providers/quota.ts +22 -22
  123. package/src/providers/reasoning-metadata.ts +1051 -12
  124. package/src/providers/registry/entries-extended.ts +3 -1
  125. package/src/providers/registry/model-ids.ts +1 -0
  126. package/src/providers/registry/types.ts +6 -0
  127. package/src/quota/reset-observer.ts +4 -2
  128. package/src/quota/reset-seen-store.ts +9 -0
  129. package/src/quota/window-mapping.ts +1 -0
  130. package/src/quota-pool/assemble.ts +4 -1
  131. package/src/responses/hosted-tool-policy.ts +56 -12
  132. package/src/responses/retained-compaction.ts +31 -5
  133. package/src/router.ts +2 -0
  134. package/src/server/auth-cors.ts +11 -8
  135. package/src/server/catalog-download.ts +3 -5
  136. package/src/server/chat-native.ts +11 -2
  137. package/src/server/claude-messages.ts +2 -1
  138. package/src/server/images.ts +41 -13
  139. package/src/server/index/link-listener.ts +16 -2
  140. package/src/server/index/link-relay-sessions.ts +43 -2
  141. package/src/server/index/optional-listeners.ts +18 -0
  142. package/src/server/management/config-routes.ts +7 -1
  143. package/src/server/management/context.ts +1 -1
  144. package/src/server/management/link-child-ops-routes.ts +116 -0
  145. package/src/server/management/link-route-state.ts +10 -0
  146. package/src/server/management/link-routes.ts +10 -0
  147. package/src/server/management/oauth-account-routes.ts +33 -4
  148. package/src/server/management/provider-overwrite-carry.ts +28 -3
  149. package/src/server/management/provider-routes.ts +16 -11
  150. package/src/server/management/route-registry.ts +3 -0
  151. package/src/server/messages-native.ts +5 -0
  152. package/src/server/request-log-failure-detail.ts +59 -1
  153. package/src/server/responses/adapter-dispatch.ts +35 -44
  154. package/src/server/responses/combo-stream-preflight.ts +146 -29
  155. package/src/server/responses/compact.ts +27 -4
  156. package/src/server/responses/context-overflow.ts +58 -2
  157. package/src/server/responses/core-combo-failure.ts +29 -4
  158. package/src/server/responses/core-combo-native.ts +3 -1
  159. package/src/server/responses/core-combo.ts +30 -3
  160. package/src/server/responses/core-errors.ts +3 -1
  161. package/src/server/responses/core-opaque-recovery.ts +45 -2
  162. package/src/server/responses/core-options.ts +12 -0
  163. package/src/server/responses/passthrough-dispatch.ts +30 -38
  164. package/src/server/responses/request-transport.ts +43 -14
  165. package/src/server/responses/reset-replay.ts +58 -2
  166. package/src/server/responses/run-turn-execution.ts +56 -30
  167. package/src/types/claude-tool-loading.ts +48 -0
  168. package/src/types/config.ts +5 -35
  169. package/src/types/provider.ts +21 -0
  170. package/src/types.ts +1 -0
  171. package/src/web-search/parse.ts +44 -4
  172. package/gui/dist/assets/App-CitvEefy.js +0 -59
  173. package/gui/dist/assets/Tray-CeKVWQyB.js +0 -1
  174. package/gui/dist/assets/brand-mark-M92UnxX2.js +0 -1
  175. package/gui/dist/assets/index-BP47do6-.js +0 -94
  176. package/gui/dist/assets/index-DmDooSAG.css +0 -2
  177. package/gui/dist/classic/assets/index-CfGqHooN.js +0 -94
  178. package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +0 -1
@@ -1,32 +1,90 @@
1
1
  import { accountAutoPauseFenceMatchesDisk, type AccountAutoPauseFence } from "../config/account-auto-pause-revisions";
2
2
  import { randomUUID } from "node:crypto";
3
+ import { clearModelCache } from "../codex/model-cache";
3
4
  import type { OcxConfig } from "../types";
4
5
  import type { ProviderApiKeySelection } from "../types/provider";
5
6
  import type { AccountPauseDetails } from "../types/account-auto-pause";
7
+ import { ProviderApiKeyPausedError, isProviderApiKeyPaused } from "./api-key-pause-state";
6
8
  import { apiKeyPoolEntryId } from "./api-keys";
9
+ import { clearKeyCooldowns } from "./api-key-cooldowns";
7
10
  import { resolveProviderApiKey } from "./api-key-resolve";
8
- import { commitProviderApiKeySelection } from "./api-key-selection";
11
+ import { captureProviderApiKeySelection, commitProviderApiKeySelection } from "./api-key-selection";
12
+ import { forgetApiKeyRotationCursor } from "./key-failover";
13
+ import { clearProviderQuotaCacheFor } from "./quota/report-cache";
9
14
 
10
- export function setProviderApiKeyPaused(config: OcxConfig, name: string, id: string, paused: boolean,
11
- automatic?: { fence: AccountAutoPauseFence; selection: ProviderApiKeySelection; pauseRevision?: string; resolvedKey?: string; details: AccountPauseDetails }): boolean {
15
+ export { ProviderApiKeyPausedError, isProviderApiKeyPaused } from "./api-key-pause-state";
16
+
17
+ export interface ProviderApiKeyPauseResult {
18
+ ok: boolean;
19
+ activeAccountId: string | null;
20
+ activeAccountChanged: boolean;
21
+ }
22
+
23
+ export function setProviderApiKeyPausedWithResult(config: OcxConfig, name: string, id: string, paused: boolean,
24
+ automatic?: { fence: AccountAutoPauseFence; selection: ProviderApiKeySelection; pauseRevision?: string; resolvedKey?: string; details: AccountPauseDetails }): ProviderApiKeyPauseResult {
25
+ let activeKeyChanged = false;
12
26
  const result = commitProviderApiKeySelection(config, name, provider => {
13
- if (automatic && !accountAutoPauseFenceMatchesDisk(name, automatic.fence)) return { changed: false, value: false };
27
+ if (automatic && !accountAutoPauseFenceMatchesDisk(name, automatic.fence)) {
28
+ return { changed: false, value: { ok: false, activeAccountId: null, activeAccountChanged: false } };
29
+ }
14
30
  const pool = provider.apiKeyPool?.length ? provider.apiKeyPool
15
31
  : provider.apiKey ? [{ id: apiKeyPoolEntryId(provider.apiKey), key: provider.apiKey }] : [];
32
+ const currentActiveAccountId = () => captureProviderApiKeySelection({ ...provider, apiKeyPool: pool }).entryId ?? null;
33
+ const beforeActiveAccountId = currentActiveAccountId();
34
+ const resultForCurrentSelection = (ok: boolean): ProviderApiKeyPauseResult => {
35
+ const activeAccountId = currentActiveAccountId();
36
+ return { ok, activeAccountId, activeAccountChanged: beforeActiveAccountId !== activeAccountId };
37
+ };
16
38
  const entry = pool.find(e => e.id === id);
17
39
  if (!entry || automatic && (entry.disabled || entry.key !== automatic.selection.reference || entry.pauseRevision !== automatic.pauseRevision
18
- || provider.accountAutoPause?.enabled !== true || resolveProviderApiKey(entry.key) !== automatic.resolvedKey)) return { changed: false, value: false };
40
+ || provider.accountAutoPause?.enabled !== true || resolveProviderApiKey(entry.key) !== automatic.resolvedKey)) {
41
+ return { changed: false, value: resultForCurrentSelection(false) };
42
+ }
43
+ const beforeApiKey = provider.apiKey;
19
44
  provider.apiKeyPool = pool;
45
+ const idx = pool.indexOf(entry);
46
+ const ordered = idx >= 0 ? [...pool.slice(idx + 1), ...pool.slice(0, idx)] : pool;
47
+ const hasEnabledActiveReference = () => pool.some(e => !e.disabled && e.key === provider.apiKey);
48
+ const activeDisabled = () => !provider.apiKey
49
+ || (pool.some(e => e.disabled && e.key === provider.apiKey) && !pool.some(e => !e.disabled && e.key === provider.apiKey));
50
+ if (!automatic && paused && entry.disabled) {
51
+ if (provider.apiKey === entry.key && !hasEnabledActiveReference()) {
52
+ const next = ordered.find(e => !e.disabled);
53
+ if (next) provider.apiKey = next.key;
54
+ else delete provider.apiKey;
55
+ activeKeyChanged = beforeApiKey !== provider.apiKey;
56
+ return { changed: true, selectionChanged: true, value: resultForCurrentSelection(true) };
57
+ }
58
+ return { changed: false, value: resultForCurrentSelection(true) };
59
+ }
20
60
  entry.disabled = paused;
21
61
  entry.pauseRevision = randomUUID();
22
62
  if (automatic) entry.pauseDetails = automatic.details;
23
63
  else delete entry.pauseDetails;
24
- if (paused && provider.apiKey === entry.key) {
25
- const next = provider.apiKeyPool?.find(e => !e.disabled);
64
+ if (paused && provider.apiKey === entry.key && !hasEnabledActiveReference()) {
65
+ const next = ordered.find(e => !e.disabled);
26
66
  if (next) provider.apiKey = next.key;
27
67
  else delete provider.apiKey;
28
- } else if (!paused && !provider.apiKey) provider.apiKey = entry.key;
29
- return { changed: true, selectionChanged: true, value: true };
68
+ } else if (!paused && activeDisabled()) provider.apiKey = entry.key;
69
+ activeKeyChanged = beforeApiKey !== provider.apiKey;
70
+ return { changed: true, selectionChanged: true, value: resultForCurrentSelection(true) };
30
71
  }, automatic?.selection);
31
- return result.status === "committed" && result.value;
72
+ const response = result.status === "committed"
73
+ ? result.value
74
+ : { ok: false, activeAccountId: null, activeAccountChanged: false };
75
+ const ok = response.ok;
76
+ if (ok && !automatic) {
77
+ clearKeyCooldowns(name);
78
+ forgetApiKeyRotationCursor(name);
79
+ if (activeKeyChanged) {
80
+ clearModelCache(name);
81
+ clearProviderQuotaCacheFor(name);
82
+ }
83
+ }
84
+ return response;
85
+ }
86
+
87
+ export function setProviderApiKeyPaused(config: OcxConfig, name: string, id: string, paused: boolean,
88
+ automatic?: { fence: AccountAutoPauseFence; selection: ProviderApiKeySelection; pauseRevision?: string; resolvedKey?: string; details: AccountPauseDetails }): boolean {
89
+ return setProviderApiKeyPausedWithResult(config, name, id, paused, automatic).ok;
32
90
  }
@@ -2,8 +2,10 @@ import type { OcxProviderConfig } from "../types";
2
2
  import type { ProviderApiKeySelection } from "../types/provider";
3
3
 
4
4
  export function captureProviderApiKeySelection(provider: OcxProviderConfig): ProviderApiKeySelection {
5
+ const activeReference = provider.apiKeyPool?.find(entry => entry.key === provider.apiKey && !entry.disabled)
6
+ ?? provider.apiKeyPool?.find(entry => entry.key === provider.apiKey);
5
7
  return {
6
- entryId: provider.apiKeyPool?.find(entry => entry.key === provider.apiKey)?.id,
8
+ entryId: activeReference?.id,
7
9
  reference: provider.apiKey,
8
10
  revision: provider.apiKeySelectionRevision,
9
11
  };
@@ -32,8 +32,9 @@ function currentKeyProvider(config: OcxConfig, name: string, selection?: Provide
32
32
  || !configured.requestPacing?.enabled || configured.requestPacing.keySelection !== "round-robin") return null;
33
33
  row = { ...configured, apiKey: entry.key, _apiKeyAttempt: selection };
34
34
  }
35
- if (row.apiKeyPool?.some(entry => entry.disabled && entry.key === row.apiKey)
36
- || row.apiKeyPool?.length && row.apiKeyPool.every(entry => entry.disabled)) return null;
35
+ const hasPausedActiveReference = row.apiKeyPool?.some(entry => entry.disabled && entry.key === row.apiKey)
36
+ && !row.apiKeyPool?.some(entry => !entry.disabled && entry.key === row.apiKey);
37
+ if (hasPausedActiveReference || row.apiKeyPool?.length && row.apiKeyPool.every(entry => entry.disabled)) return null;
37
38
  const current = routedProviderConfig(name, { ...row, _apiKeyAttempt: selection?.distributed ? selection : undefined });
38
39
  if (current.authMode === "oauth" || current.authMode === "forward") return null;
39
40
  if (current.authMode === "key" && !current.keyOptional && !current.apiKey?.trim()
@@ -13,6 +13,7 @@ import { GCP_CREDENTIAL_MARKER_PREFIX, isGcpCredentialMaterial, parseGcpCredenti
13
13
  import { invalidateResolvedProviderKeyCache, probeProviderKeychain, providerKeychainEntry } from "./api-key-resolve";
14
14
  import type { AccountQuotaFields } from "./quota-types";
15
15
  import { commitProviderApiKeySelection } from "./api-key-selection";
16
+ import { captureProviderApiKeySelection } from "./api-key-selection-capture";
16
17
  import { cleanupRemovedGcpCredentials } from "./gcp-credential-cleanup";
17
18
 
18
19
  export interface ProviderApiKeyInfo extends AccountQuotaFields {
@@ -204,6 +205,10 @@ export function sanitizeApiKeyValue(value: unknown): string | undefined {
204
205
  }
205
206
 
206
207
  /** Seed the pool from a legacy bare `apiKey`, and keep `apiKey` mirrored to the active entry. */
208
+ export function providerHasStoredApiKey(provider: OcxProviderConfig): boolean {
209
+ return !!provider.apiKey || (isKeyAuthProvider(provider) && (provider.apiKeyPool?.length ?? 0) > 0);
210
+ }
211
+
207
212
  function ensurePool(provider: OcxProviderConfig): NonNullable<OcxProviderConfig["apiKeyPool"]> {
208
213
  if (!provider.apiKeyPool) provider.apiKeyPool = [];
209
214
  if (provider.apiKeyPool.length === 0 && provider.apiKey) {
@@ -219,7 +224,7 @@ export function listProviderApiKeys(config: OcxConfig, name: string): { activeId
219
224
  const pool = provider.apiKeyPool?.length
220
225
  ? provider.apiKeyPool
221
226
  : provider.apiKey ? [{ id: apiKeyPoolEntryId(provider.apiKey), key: provider.apiKey }] : [];
222
- const activeId = pool.find(entry => entry.key === provider.apiKey)?.id ?? null;
227
+ const activeId = captureProviderApiKeySelection({ ...provider, apiKeyPool: pool }).entryId ?? null;
223
228
  return {
224
229
  activeId,
225
230
  keys: pool.map(entry => ({
@@ -276,7 +281,8 @@ export function addProviderApiKey(config: OcxConfig, name: string, key: string,
276
281
  pool.push({ id, key: marker, ...(label?.trim() ? { label: label.trim() } : {}), addedAt: Date.now() });
277
282
  }
278
283
  }
279
- fresh.apiKey = stored[0]!.marker;
284
+ const activeCandidate = stored.find(({ id }) => !pool.find(e => e.id === id)?.disabled);
285
+ if (activeCandidate) fresh.apiKey = activeCandidate.marker;
280
286
  return { changed: true, selectionChanged: true, value: stored[0]!.id };
281
287
  });
282
288
  if (committed.status === "committed") {
@@ -343,17 +349,24 @@ export function removeProviderApiKey(config: OcxConfig, name: string, id: string
343
349
  const committed = commitProviderApiKeySelection(config, name, provider => {
344
350
  const pool = provider.apiKeyPool?.length ? provider.apiKeyPool
345
351
  : provider.apiKey ? [{ id: apiKeyPoolEntryId(provider.apiKey), key: provider.apiKey }] : [];
352
+ const activeEntryIdBefore = captureProviderApiKeySelection({ ...provider, apiKeyPool: pool }).entryId;
346
353
  const entry = pool.find(e => e.id === id);
347
354
  if (!entry) return { changed: false, value: false };
355
+ const idx = pool.indexOf(entry);
348
356
  removed = entry.key;
349
357
  provider.apiKeyPool = pool.filter(e => e.id !== id);
350
- if (provider.apiKey === entry.key) {
351
- const next = provider.apiKeyPool.find(candidate => !candidate.disabled);
358
+ const hasEnabledSurvivor = provider.apiKeyPool.some(e => !e.disabled && e.key === entry.key);
359
+ if (provider.apiKey === entry.key && !hasEnabledSurvivor) {
360
+ const ordered = idx >= 0
361
+ ? [...provider.apiKeyPool.slice(idx), ...provider.apiKeyPool.slice(0, idx)]
362
+ : provider.apiKeyPool;
363
+ const next = ordered.find(candidate => !candidate.disabled);
352
364
  if (next) provider.apiKey = next.key;
353
365
  else delete provider.apiKey;
354
366
  }
355
367
  if (provider.apiKeyPool.length === 0) delete provider.apiKeyPool;
356
- return { changed: true, value: true };
368
+ const activeEntryIdAfter = captureProviderApiKeySelection(provider).entryId;
369
+ return { changed: true, selectionChanged: activeEntryIdBefore !== activeEntryIdAfter, value: true };
357
370
  });
358
371
  if (committed.status !== "committed" || !committed.value) return false;
359
372
  if (removed?.startsWith(GCP_CREDENTIAL_MARKER_PREFIX)) cleanupRemovedGcpCredentials([removed]);
@@ -7,8 +7,14 @@
7
7
  * "cli_version"`; `claude-code/<ver>` is answered with `"surface"`. Only the
8
8
  * `claude-cli/<ver> (external, cli)` form of a current release is treated as the
9
9
  * Claude Code CLI surface. Bump the version together with a live GET check.
10
+ *
11
+ * Model access is gated on it too: Anthropic answers claude-fable-5-2 with
12
+ * "Claude Code 2.1.280 does not support this model; version 2.1.290 or newer is required".
13
+ * The three values below are one coherent client: Claude Code 2.1.321 sends @anthropic-ai/sdk 0.128.0 on
14
+ * runtime v26.12.1 (mitmproxy capture in router-for-me/CLIProxyAPI#7392; the locally installed 2.1.319
15
+ * binary carries the same SDK and runtime strings).
10
16
  */
11
- export const CLAUDE_CLI_VERSION = "2.1.280";
17
+ export const CLAUDE_CLI_VERSION = "2.1.321";
12
18
  export const CLAUDE_CLI_USER_AGENT = `claude-cli/${CLAUDE_CLI_VERSION} (external, cli)`;
13
- export const CLAUDE_CLI_SDK_PACKAGE_VERSION = "0.112.1";
14
- export const CLAUDE_CLI_RUNTIME_VERSION = "v26.3.0";
19
+ export const CLAUDE_CLI_SDK_PACKAGE_VERSION = "0.128.0";
20
+ export const CLAUDE_CLI_RUNTIME_VERSION = "v26.12.1";
@@ -10,7 +10,7 @@
10
10
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
11
11
  import { dirname, join } from "node:path";
12
12
  import { getConfigDir } from "../config/paths";
13
- import type { ProviderQuota } from "./quota-types";
13
+ import { isWeeklyAllowancePercent, type ProviderQuota } from "./quota-types";
14
14
 
15
15
  export type ClaudeUsageSnapshot = {
16
16
  identity: string;
@@ -50,11 +50,16 @@ export function loadClaudeUsageSnapshot(path: string): ClaudeUsageSnapshot | und
50
50
  if (!q || typeof q !== "object" || !finite(q.updatedAt)) return;
51
51
  for (const field of ["fiveHourPercent", "fiveHourResetAt", "weeklyPercent", "weeklyResetAt"])
52
52
  if (q[field] !== undefined && !finite(q[field])) return;
53
- if (q.customWindows !== undefined && (!Array.isArray(q.customWindows) || !q.customWindows.every((w: unknown) => {
54
- if (!w || typeof w !== "object") return false;
55
- const row = w as Record<string, unknown>;
56
- return typeof row.label === "string" && finite(row.percent) && (row.resetAt === undefined || finite(row.resetAt));
57
- }))) return;
53
+ // Display-only rows (an inactive model limit) reach the dashboard too, so they pass the same check.
54
+ for (const field of ["customWindows", "displayWindows"]) {
55
+ const windows: unknown = q[field];
56
+ if (windows !== undefined && (!Array.isArray(windows) || !windows.every((w: unknown) => {
57
+ if (!w || typeof w !== "object") return false;
58
+ const row = w as Record<string, unknown>;
59
+ return typeof row.label === "string" && finite(row.percent) && (row.resetAt === undefined || finite(row.resetAt))
60
+ && (row.weeklyAllowancePercent === undefined || isWeeklyAllowancePercent(row.weeklyAllowancePercent));
61
+ }))) return;
62
+ }
58
63
  }
59
64
  return saved;
60
65
  } catch { /* Missing or malformed cache is unknown, never proof of capacity. */ }
@@ -1,6 +1,6 @@
1
1
  import { markAnthropicFamilyEnumeration } from "./quota/anthropic-family-headers";
2
2
  import { rawAnthropicUsageWindows } from "./quota/anthropic-decision-windows";
3
- import { anthropicUsageBuckets } from "./quota/anthropic-usage-windows";
3
+ import { anthropicUsageBuckets, type AnthropicUsageBucket } from "./quota/anthropic-usage-windows";
4
4
  import { bindRawDecisionWindows } from "./quota-decision-publication";
5
5
  import { decisionQuotaSinkActive } from "../lib/decision-quota-sink";
6
6
  import { CLAUDE_CLI_USER_AGENT } from "./claude-cli-identity";
@@ -9,6 +9,20 @@ import type { ProviderQuota, ProviderQuotaWindow, QuotaFailureCode } from "./quo
9
9
  import { httpQuotaFailure } from "./quota/failure-codes";
10
10
  const hasQuotaRows = (q: ProviderQuota) => q.fiveHourPercent !== undefined || q.weeklyPercent !== undefined || Boolean(q.customWindows?.length);
11
11
 
12
+ const FAMILY_LABELS: Partial<Record<AnthropicUsageBucket["window"], string>> = { fable: "Fable", opus: "Opus", sonnet: "Sonnet" };
13
+
14
+ /** Project a model-family bucket into a quota window; shared buckets and unusable percents yield none. */
15
+ function familyWindow({ window, row, percentField, weeklyAllowancePercent }: AnthropicUsageBucket): ProviderQuotaWindow | undefined {
16
+ const label = FAMILY_LABELS[window];
17
+ const percent = normalizePercent(row[percentField]);
18
+ if (!label || percent === undefined) {
19
+ return undefined;
20
+ }
21
+ const resetAt = normalizeResetAt(row.resets_at);
22
+ return { label, scope: "model", percent, ...(resetAt !== undefined ? { resetAt } : {}),
23
+ ...(weeklyAllowancePercent !== undefined ? { weeklyAllowancePercent } : {}) };
24
+ }
25
+
12
26
  /** Read the Anthropic OAuth usage endpoint for an access token and return the parsed quota, or null on a non-OK or malformed response. */
13
27
  export async function readAnthropicUsageQuota(accessToken: string): Promise<ProviderQuota | null> {
14
28
  return (await probeAnthropicUsageQuota(accessToken)).quota;
@@ -37,23 +51,28 @@ export async function probeAnthropicUsageQuota(accessToken: string): Promise<Ant
37
51
  }
38
52
  const body = asRecord(await readQuotaJson(response));
39
53
  if (!body) return { quota: null, failure: "response_unusable" };
40
- const { buckets, familyEnumeration } = anthropicUsageBuckets(body);
54
+ const { buckets, displayBuckets, familyEnumeration } = anthropicUsageBuckets(body);
41
55
  const shared: Partial<ProviderQuota> = {};
42
56
  const customWindows: ProviderQuotaWindow[] = [];
43
- for (const { window, row, percentField } of buckets) {
44
- const percent = normalizePercent(row[percentField]);
45
- const resetAt = normalizeResetAt(row.resets_at);
57
+ for (const bucket of buckets) {
58
+ const { window, row, percentField } = bucket;
46
59
  if (window === "5h" || window === "weekly") {
60
+ const percent = normalizePercent(row[percentField]);
61
+ const resetAt = normalizeResetAt(row.resets_at);
47
62
  if (percent !== undefined) shared[window === "5h" ? "fiveHourPercent" : "weeklyPercent"] = percent;
48
63
  if (resetAt !== undefined) shared[window === "5h" ? "fiveHourResetAt" : "weeklyResetAt"] = resetAt;
49
- } else if (percent !== undefined) {
50
- const label = { fable: "Fable", opus: "Opus", sonnet: "Sonnet" }[window];
51
- customWindows.push({ label, scope: "model", percent, ...(resetAt !== undefined ? { resetAt } : {}) });
64
+ } else {
65
+ const custom = familyWindow(bucket);
66
+ if (custom) {
67
+ customWindows.push(custom);
68
+ }
52
69
  }
53
70
  }
71
+ const displayWindows = displayBuckets.flatMap(bucket => familyWindow(bucket) ?? []);
54
72
  const quota: ProviderQuota = {
55
73
  ...shared,
56
74
  ...(customWindows.length > 0 ? { customWindows } : {}),
75
+ ...(displayWindows.length > 0 ? { displayWindows } : {}),
57
76
  updatedAt: Date.now(),
58
77
  };
59
78
  if (decisionQuotaSinkActive()) bindRawDecisionWindows(quota, rawAnthropicUsageWindows(body, quota.updatedAt));
@@ -59,6 +59,12 @@ export interface CodexCapacityAccount {
59
59
  isMain: boolean;
60
60
  active?: boolean;
61
61
  plan?: unknown;
62
+ /**
63
+ * Explicit capacity weight for providers without a calibrated plan table (Anthropic seats
64
+ * report no tier). When set it replaces the Codex plan lookup and the account is not counted
65
+ * as an uncalibrated plan.
66
+ */
67
+ weight?: number;
62
68
  paused: boolean;
63
69
  needsReauth?: boolean;
64
70
  quota: CodexCapacityQuota | null;
@@ -227,10 +233,13 @@ export function aggregateCodexPoolCapacity(
227
233
  let staleQuotaAccounts = 0;
228
234
 
229
235
  for (const account of accounts) {
230
- const weight = codexCapacityWeight(account.plan);
236
+ const explicitWeight = typeof account.weight === "number" && Number.isFinite(account.weight) && account.weight > 0
237
+ ? account.weight
238
+ : undefined;
239
+ const weight = explicitWeight ?? codexCapacityWeight(account.plan);
231
240
  // Still reported, so the operator can see the estimate is conservative for this seat —
232
241
  // but no longer a reason to drop the account from the aggregate (#3155).
233
- if (!isCalibratedPlan(account.plan)) unknownPlanAccounts += 1;
242
+ if (explicitWeight === undefined && !isCalibratedPlan(account.plan)) unknownPlanAccounts += 1;
234
243
  if (account.paused) pausedAccounts += 1;
235
244
  if (account.needsReauth) reauthAccounts += 1;
236
245
  const quota = account.quota;
@@ -21,10 +21,12 @@ import type { OcxConfig, OcxProviderConfig, RateLimitRetryPolicy, ResetReplayPol
21
21
  import { OPENCODE_GO_SESSION_HEADER } from "./opencode-go-transport";
22
22
  import { resolveProviderTransport, type OcxProviderTransport } from "./xai-transport";
23
23
  import { sweepExpiredOnWrite } from "../lib/state-store-sweeper";
24
+ import { ProviderApiKeyPausedError } from "./api-key-pause-state";
24
25
  // quota-key-accounts imports only node:crypto, the key store and the quota types -- NOT
25
26
  // providers/quota.ts -- so the cached reader reaches the dispatch path without dragging the
26
27
  // probe machinery onto it.
27
28
  import { cachedApiKeyQuota } from "./quota-key-accounts";
29
+ import { isDisplayOnlyQuota } from "./quota-types";
28
30
 
29
31
  // ---- cooldown state (in-memory, same as codex/routing.ts) ----
30
32
 
@@ -422,7 +424,7 @@ type ApiKeyPoolEntry = NonNullable<OcxProviderConfig["apiKeyPool"]>[number];
422
424
  */
423
425
  function keyHeadroom(providerName: string, provider: OcxProviderConfig, entry: ApiKeyPoolEntry): number | null {
424
426
  const quota = cachedApiKeyQuota(providerName, provider, entry.id, entry.key);
425
- if (!quota) return null;
427
+ if (!quota || isDisplayOnlyQuota(quota)) return null;
426
428
  const percents = [
427
429
  quota.fiveHourPercent,
428
430
  quota.weeklyPercent,
@@ -487,12 +489,14 @@ export function selectProactiveApiKey(
487
489
  ): OcxProviderConfig | null {
488
490
  const provider = config.providers?.[providerName];
489
491
  if (!provider) return null;
490
- const strategy = provider.apiKeyPoolStrategy;
491
- if (!strategy) return null;
492
492
  if (!hasKeyPoolFailover(provider)) return null;
493
493
  const pool = provider.apiKeyPool ?? [];
494
494
 
495
- const activeEntry = pool.find(entry => entry.key === provider.apiKey);
495
+ const activeEntry = pool.find(entry => entry.key === provider.apiKey && !entry.disabled)
496
+ ?? pool.find(entry => entry.key === provider.apiKey);
497
+ const activeDisabled = Boolean(activeEntry?.disabled || (!provider.apiKey && pool.some(entry => entry.disabled)));
498
+ const strategy = provider.apiKeyPoolStrategy ?? (activeDisabled ? "fill-first" : undefined);
499
+ if (!strategy) return null;
496
500
  // A healthy committed key wins, whether the operator chose it or a previous rotation did.
497
501
  if (activeEntry && !activeEntry.disabled && !isKeyInCooldown(providerName, activeEntry.id, now)) return null;
498
502
 
@@ -521,7 +525,8 @@ export function selectProactiveApiKey(
521
525
  const target = freshPool.find(entry => entry.id === chosen.id);
522
526
  if (!target || target.disabled) return { changed: false, value: null };
523
527
  if (freshProvider.apiKey === target.key) return { changed: false, value: null };
524
- const freshActive = freshPool.find(entry => entry.key === freshProvider.apiKey);
528
+ const freshActive = freshPool.find(entry => entry.key === freshProvider.apiKey && !entry.disabled)
529
+ ?? freshPool.find(entry => entry.key === freshProvider.apiKey);
525
530
  // Re-check under the lock: a concurrent manual selection may have landed a healthy key.
526
531
  if (freshActive && !freshActive.disabled && !isKeyInCooldown(providerName, freshActive.id, now)) {
527
532
  return { changed: false, value: null };
@@ -566,6 +571,7 @@ export function selectProactiveApiKeyTransport(
566
571
  const dispatchKeyCursor = new Map<string, string>();
567
572
  function allocateDistributedKey(providerName: string, provider: OcxProviderConfig, now: number): OcxProviderConfig {
568
573
  const pool = (provider.apiKeyPool ?? []).filter(entry => !entry.disabled).filter((entry, index, all) => all.findIndex(other => other.key === entry.key) === index);
574
+ if (pool.length === 0) throw new ProviderApiKeyPausedError();
569
575
  const previous = dispatchKeyCursor.get(providerName);
570
576
  const start = pool.findIndex(entry => entry.id === previous);
571
577
  for (let offset = 1; offset <= pool.length; offset++) {
@@ -771,7 +777,8 @@ function rotateKeyAfterFailure(
771
777
  : pool.find(entry => entry.key === failedKey);
772
778
 
773
779
  if (freshProvider.apiKey !== failedKey) {
774
- const activeEntry = pool.find(entry => entry.key === freshProvider.apiKey);
780
+ const activeEntry = pool.find(entry => entry.key === freshProvider.apiKey && !entry.disabled)
781
+ ?? pool.find(entry => entry.key === freshProvider.apiKey);
775
782
  if (activeEntry && !activeEntry.disabled && !isKeyInCooldown(providerName, activeEntry.id, now)) {
776
783
  return {
777
784
  changed: false,
@@ -0,0 +1,31 @@
1
+ import type { OcxProviderConfig } from "../types";
2
+
3
+ /** Keys a `providers.<name>.modelDiscovery` block may carry (#7910). */
4
+ const PROVIDER_MODEL_DISCOVERY_KEYS = new Set(["skipInvalidRows"]);
5
+
6
+ /**
7
+ * Validate a provider's `modelDiscovery` block at the management write boundary. The loader
8
+ * degrades a malformed block to absent (strict discovery), so this is where a bad value is
9
+ * refused loudly instead of being stored and then ignored.
10
+ */
11
+ export function providerModelDiscoveryConfigError(value: unknown): string | null {
12
+ if (value === undefined) return null;
13
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
14
+ return "modelDiscovery must be an object such as { \"skipInvalidRows\": true }";
15
+ }
16
+ const record = value as Record<string, unknown>;
17
+ if (Object.keys(record).some(key => !PROVIDER_MODEL_DISCOVERY_KEYS.has(key))) {
18
+ return "modelDiscovery accepts only skipInvalidRows";
19
+ }
20
+ if (record.skipInvalidRows !== undefined && typeof record.skipInvalidRows !== "boolean") {
21
+ return "modelDiscovery.skipInvalidRows must be a boolean";
22
+ }
23
+ return null;
24
+ }
25
+
26
+ /** Whether the provider opted into skipping invalid `/models` rows. Anything but `true` is strict. */
27
+ export function providerSkipsInvalidModelRows(
28
+ provider: Partial<Pick<OcxProviderConfig, "modelDiscovery">>,
29
+ ): boolean {
30
+ return provider.modelDiscovery?.skipInvalidRows === true;
31
+ }
@@ -1,4 +1,35 @@
1
- /** Safe operator guidance for malformed upstream model lists. */
2
- export function invalidModelDiscoveryHint(diagnostic?: string): string {
3
- return `${diagnostic ? ` (${diagnostic})` : ""}. A newly added API-key provider can keep its model selection pending while discovery fails; a static models list with liveModels: false avoids discovery for gateways publishing invalid rows.`;
1
+ /**
2
+ * Safe operator guidance for malformed upstream model lists.
3
+ *
4
+ * A diagnostic is present only for a row-level failure of a generic `/models` envelope, and it
5
+ * already names the first invalid row and how many rows are invalid (never row contents). For those,
6
+ * the guidance names the per-provider `modelDiscovery.skipInvalidRows` opt-in (#7910) next to the
7
+ * static-roster recovery; once the opt-in is on, reaching here means no row survived.
8
+ */
9
+ export function invalidModelDiscoveryHint(diagnostic?: string, skipInvalidRows = false): string {
10
+ const pending = "A newly added API-key provider can keep its model selection pending while discovery fails";
11
+ const staticRoster = "a static models list with liveModels: false avoids discovery for gateways publishing invalid rows.";
12
+ if (!diagnostic) return `. ${pending}; ${staticRoster}`;
13
+ if (skipInvalidRows) {
14
+ return ` (${diagnostic}). modelDiscovery.skipInvalidRows left no usable row, so the listing stays rejected. ${pending}; ${staticRoster}`;
15
+ }
16
+ return ` (${diagnostic}). ${pending}; set modelDiscovery.skipInvalidRows: true on this provider to skip invalid rows and keep the valid ones, or use a static models list with liveModels: false to avoid discovery for gateways publishing invalid rows.`;
17
+ }
18
+
19
+ const skippedRowWarnings = new Map<string, string>();
20
+
21
+ /**
22
+ * Whether a successful listing that skipped invalid rows should be logged. The warning is one-time
23
+ * per provider for an unchanged skipped/received count; a clean listing resets it so a recurrence
24
+ * is reported again. Keyed by provider name, so it is bounded by the configured providers.
25
+ */
26
+ export function shouldWarnSkippedModelRows(provider: string, skipped: number, rawCount: number): boolean {
27
+ if (skipped <= 0) {
28
+ skippedRowWarnings.delete(provider);
29
+ return false;
30
+ }
31
+ const signature = `${skipped}/${rawCount}`;
32
+ if (skippedRowWarnings.get(provider) === signature) return false;
33
+ skippedRowWarnings.set(provider, signature);
34
+ return true;
4
35
  }
@@ -1,5 +1,6 @@
1
1
  import { extractWorkBuddyModels } from "./workbuddy-models";
2
2
  import type { OcxProviderConfig } from "../types";
3
+ import { providerSkipsInvalidModelRows } from "./model-discovery-config";
3
4
  import {
4
5
  isValidModelDiscoveryModelId,
5
6
  MODEL_DISCOVERY_MAX_MODEL_ID_LENGTH,
@@ -31,6 +32,8 @@ export interface ResolvedProviderModelDiscovery {
31
32
  spec?: ProviderModelDiscoverySpec;
32
33
  maxResponseBytes: number;
33
34
  maxModels: number;
35
+ /** Operator opt-in `providers.<name>.modelDiscovery.skipInvalidRows` (#7910); absent means strict. */
36
+ skipInvalidRows?: true;
34
37
  }
35
38
 
36
39
  export type ProviderModelsApiItem = Record<string, unknown> & { id: string };
@@ -46,7 +49,7 @@ export type BoundedDiscoveryJsonResult =
46
49
  | { ok: false; reason: "response_too_large" | "invalid_json" };
47
50
 
48
51
  export type ProviderModelItemsResult =
49
- | { ok: true; items: ProviderModelsApiItem[]; rawCount: number }
52
+ | { ok: true; items: ProviderModelsApiItem[]; rawCount: number; skippedInvalidRows?: number }
50
53
  | { ok: false; reason: "invalid_shape" | "too_many_models"; diagnostic?: string };
51
54
 
52
55
  export type ModelEnvelopeRowsResult =
@@ -162,7 +165,7 @@ export function providerModelDiscoverySpecError(spec: ProviderModelDiscoverySpec
162
165
 
163
166
  export function resolveProviderModelDiscovery(
164
167
  providerName: string,
165
- provider: Pick<OcxProviderConfig, "baseUrl" | "adapter"> & Partial<Pick<OcxProviderConfig, "authMode">>,
168
+ provider: Pick<OcxProviderConfig, "baseUrl" | "adapter"> & Partial<Pick<OcxProviderConfig, "authMode" | "modelDiscovery">>,
166
169
  ): ResolvedProviderModelDiscovery {
167
170
  // The dashboard permits a canonical preset to be saved under a different name. Recover its
168
171
  // registry-owned discovery policy by transport in that case. The destination helper is limited
@@ -177,6 +180,8 @@ export function resolveProviderModelDiscovery(
177
180
  ...(spec ? { spec } : {}),
178
181
  maxResponseBytes: positiveIntegerAtMost(spec?.maxResponseBytes, MODEL_DISCOVERY_MAX_RESPONSE_BYTES),
179
182
  maxModels: positiveIntegerAtMost(spec?.maxModels, MODEL_DISCOVERY_MAX_MODELS),
183
+ // Operator configuration, never registry policy: the registry cannot relax row validation.
184
+ ...(providerSkipsInvalidModelRows(provider) ? { skipInvalidRows: true as const } : {}),
180
185
  };
181
186
  }
182
187
 
@@ -509,6 +514,22 @@ function plainObject(value: unknown): Record<string, unknown> | null {
509
514
  ? value as Record<string, unknown>
510
515
  : null;
511
516
  }
517
+
518
+ /** Why one envelope row cannot become a model, phrased without any row content. */
519
+ function invalidRowReason(raw: unknown, idField: string): string | undefined {
520
+ const row = plainObject(raw);
521
+ if (!row) return "is not an object";
522
+ const id = row[idField];
523
+ if (isValidModelDiscoveryModelId(id)) return undefined;
524
+ return typeof id !== "string" ? "has a non-string id" : !id.trim() ? "has an empty id" : "has an invalid id";
525
+ }
526
+
527
+ /**
528
+ * Strict discovery rejects a listing with any invalid row; `skipInvalidRows` (#7910) drops those rows
529
+ * instead. Every row is still counted against the raw-row ceiling before this runs, and a listing
530
+ * where invalid rows were skipped but nothing was admitted stays malformed: skipping must never turn
531
+ * a broken listing into an authoritative empty roster.
532
+ */
512
533
  export function extractProviderModelItems(
513
534
  value: unknown,
514
535
  discovery: ResolvedProviderModelDiscovery,
@@ -534,12 +555,19 @@ export function extractProviderModelItems(
534
555
  const preferred: ProviderModelsApiItem[] = [];
535
556
  const seen = new Set<string>();
536
557
  const idField = discovery.spec?.idField ?? "id";
558
+ const skipInvalidRows = discovery.skipInvalidRows === true;
559
+ let invalidRows = 0;
560
+ let firstInvalid = "";
537
561
  for (const [index, raw] of data.entries()) {
538
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
539
- return { ok: false, reason: "invalid_shape", diagnostic: `row ${index} is not an object` };
562
+ const invalid = invalidRowReason(raw, idField);
563
+ if (invalid !== undefined) {
564
+ if (invalidRows === 0) firstInvalid = `row ${index} ${invalid}`;
565
+ invalidRows += 1;
566
+ continue;
540
567
  }
541
- const id = (raw as Record<string, unknown>)[idField];
542
- if (!isValidModelDiscoveryModelId(id)) return { ok: false, reason: "invalid_shape", diagnostic: `row ${index} has ${typeof id !== "string" ? "a non-string id" : !id.trim() ? "an empty id" : "an invalid id"}` };
568
+ // A strict listing is already rejected; keep scanning only to count the invalid rows.
569
+ if (invalidRows > 0 && !skipInvalidRows) continue;
570
+ const id = (raw as Record<string, unknown>)[idField] as string;
543
571
  const prefix = discovery.spec?.stripIdPrefix;
544
572
  let finalId = id;
545
573
  if (prefix && finalId.startsWith(prefix)) {
@@ -562,5 +590,13 @@ export function extractProviderModelItems(
562
590
  ? preferred : items;
563
591
  target.push(siblings ? enrichAdmittedModel(item, siblings) : item);
564
592
  }
565
- return { ok: true, items: [...preferred, ...items], rawCount: data.length };
593
+ if (invalidRows > 0 && (!skipInvalidRows || items.length + preferred.length === 0)) {
594
+ return { ok: false, reason: "invalid_shape", diagnostic: `${firstInvalid}; ${invalidRows} of ${data.length} rows invalid` };
595
+ }
596
+ return {
597
+ ok: true,
598
+ items: [...preferred, ...items],
599
+ rawCount: data.length,
600
+ ...(invalidRows > 0 ? { skippedInvalidRows: invalidRows } : {}),
601
+ };
566
602
  }
@@ -58,6 +58,7 @@ export const PROVIDER_MODEL_RENAME_ROLES = {
58
58
  defaultModel: "scalar",
59
59
  models: "list",
60
60
  liveModels: "none",
61
+ modelDiscovery: "none",
61
62
  selectedModels: "list",
62
63
  initialModelSelection: "none",
63
64
  retainModels: "list",
@@ -112,6 +113,7 @@ export const PROVIDER_MODEL_RENAME_ROLES = {
112
113
  zaiResponsesDefaultVersion: "none",
113
114
  supportsResponsesCustomTools: "none",
114
115
  unsupportedHostedTools: "none",
116
+ unsupportedHostedToolsWithClientTools: "none",
115
117
  responsesSnapshotRepair: "none",
116
118
  webSearchBridge: "none",
117
119
  reasoningEffortMap: "none",