@bitkyc08/opencodex 2.55.0 → 2.56.0

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 (167) hide show
  1. package/gui/dist/assets/{index-VuoiWj9J.js → index-D4zuyIxQ.js} +1 -1
  2. package/gui/dist/index.html +1 -1
  3. package/package.json +2 -1
  4. package/src/adapters/base.ts +21 -0
  5. package/src/adapters/cursor/transport-retry.ts +46 -1
  6. package/src/adapters/cursor.ts +4 -0
  7. package/src/adapters/kiro/adapter.ts +42 -1
  8. package/src/adapters/kiro-retry.ts +23 -4
  9. package/src/adapters/openai-chat/errors.ts +116 -0
  10. package/src/adapters/openai-chat/messages.ts +346 -0
  11. package/src/adapters/openai-chat/passthrough.ts +146 -0
  12. package/src/adapters/openai-chat/response-events.ts +117 -0
  13. package/src/adapters/openai-chat/tool-call-validation.ts +200 -0
  14. package/src/adapters/openai-chat/tool-schema.ts +477 -0
  15. package/src/adapters/openai-chat/wire.ts +50 -0
  16. package/src/adapters/openai-chat.ts +33 -1445
  17. package/src/adapters/openai-responses/canonical-forward.ts +202 -0
  18. package/src/adapters/openai-responses/image-gen.ts +406 -0
  19. package/src/adapters/openai-responses/internal.ts +3 -0
  20. package/src/adapters/openai-responses/passthrough.ts +611 -0
  21. package/src/adapters/openai-responses/prompt-cache.ts +83 -0
  22. package/src/adapters/openai-responses/reasoning.ts +220 -0
  23. package/src/adapters/openai-responses/request-strips.ts +185 -0
  24. package/src/adapters/openai-responses/tool-output-recovery.ts +509 -0
  25. package/src/adapters/openai-responses/tool-schema.ts +293 -0
  26. package/src/adapters/openai-responses/web-search.ts +156 -0
  27. package/src/adapters/openai-responses.ts +4 -2625
  28. package/src/bridge/errors.ts +34 -0
  29. package/src/bridge/internal.ts +174 -0
  30. package/src/bridge/response-json.ts +624 -0
  31. package/src/bridge/sse.ts +1444 -0
  32. package/src/bridge.ts +5 -2204
  33. package/src/chat/inbound.ts +12 -1
  34. package/src/codex/account-lifecycle.ts +3 -0
  35. package/src/codex/account-store.ts +71 -9
  36. package/src/codex/auth-api/account-list.ts +507 -0
  37. package/src/codex/auth-api/http.ts +32 -0
  38. package/src/codex/auth-api/login-flow.ts +554 -0
  39. package/src/codex/auth-api/login-state.ts +64 -0
  40. package/src/codex/auth-api/main-account-probe.ts +331 -0
  41. package/src/codex/auth-api/pool-mode-gate.ts +274 -0
  42. package/src/codex/auth-api/pool-quota-probe.ts +512 -0
  43. package/src/codex/auth-api/reset-credit-service.ts +422 -0
  44. package/src/codex/auth-api/routes.ts +425 -0
  45. package/src/codex/auth-api/runtime-config.ts +48 -0
  46. package/src/codex/auth-api.ts +27 -3118
  47. package/src/codex/auth-context.ts +95 -28
  48. package/src/codex/catalog/auto-review.ts +507 -0
  49. package/src/codex/catalog/build-entries.ts +981 -0
  50. package/src/codex/catalog/combo-member.ts +375 -0
  51. package/src/codex/catalog/derive-entry.ts +229 -0
  52. package/src/codex/catalog/effort.ts +0 -1
  53. package/src/codex/catalog/gated-native-warn.ts +63 -0
  54. package/src/codex/catalog/gather-capture.ts +533 -0
  55. package/src/codex/catalog/model-hints.ts +691 -0
  56. package/src/codex/catalog/model-visibility.ts +304 -0
  57. package/src/codex/catalog/provider-fetch.ts +52 -2942
  58. package/src/codex/catalog/provider-models.ts +685 -0
  59. package/src/codex/catalog/restore.ts +132 -0
  60. package/src/codex/catalog/retained-sync.ts +706 -0
  61. package/src/codex/catalog/routed-gather.ts +858 -0
  62. package/src/codex/catalog/subagent-roster.ts +176 -0
  63. package/src/codex/catalog/sync.ts +52 -2698
  64. package/src/codex/inject/config-toml.ts +563 -0
  65. package/src/codex/inject/remove.ts +192 -0
  66. package/src/codex/inject/restore.ts +540 -0
  67. package/src/codex/inject/routing-classify.ts +109 -0
  68. package/src/codex/inject/routing-target.ts +125 -0
  69. package/src/codex/inject.ts +81 -1436
  70. package/src/codex/lineage.ts +458 -0
  71. package/src/codex/pool-refresh-backoff.ts +152 -0
  72. package/src/codex/routing/active-account.ts +194 -0
  73. package/src/codex/routing/cooldown-math.ts +275 -0
  74. package/src/codex/routing/health-store.ts +402 -0
  75. package/src/codex/routing/probe-lease.ts +358 -0
  76. package/src/codex/routing/selection.ts +703 -0
  77. package/src/codex/routing/thread-affinity.ts +538 -0
  78. package/src/codex/routing.ts +353 -2234
  79. package/src/codex/shim-fingerprint.ts +223 -0
  80. package/src/codex/shim-inspect.ts +175 -0
  81. package/src/codex/shim-probe.ts +367 -0
  82. package/src/codex/shim-restore-lock.ts +169 -0
  83. package/src/codex/shim-state-file.ts +151 -0
  84. package/src/codex/shim-templates.ts +265 -0
  85. package/src/codex/shim.ts +48 -1268
  86. package/src/config/diagnostics.ts +705 -0
  87. package/src/config/feature-flags.ts +55 -0
  88. package/src/config/live-reconcile.ts +403 -0
  89. package/src/config/load-degrade.ts +880 -0
  90. package/src/config/mutation-lock.ts +244 -0
  91. package/src/config/openai-tier-backup.ts +268 -0
  92. package/src/config/persist-unlocked.ts +92 -0
  93. package/src/config/proxy-env.ts +188 -0
  94. package/src/config/salvage.ts +244 -0
  95. package/src/config/schema/config-schema.ts +640 -0
  96. package/src/config/schema/leaf-validators.ts +855 -0
  97. package/src/config/warn-memo.ts +28 -0
  98. package/src/config.ts +234 -4481
  99. package/src/generated/compatibility-version.json +539 -39
  100. package/src/lib/request-execution-budget.ts +69 -20
  101. package/src/lib/spend-reservation-ledger.ts +940 -0
  102. package/src/lib/upstream-retry.ts +55 -11
  103. package/src/lib/workflow-budget.ts +553 -30
  104. package/src/providers/quota/account-cache.ts +441 -0
  105. package/src/providers/quota/antigravity.ts +295 -0
  106. package/src/providers/quota/report-cache.ts +320 -0
  107. package/src/providers/quota/vendor-probes-key.ts +1243 -0
  108. package/src/providers/quota/vendor-probes-oauth.ts +590 -0
  109. package/src/providers/quota.ts +324 -3079
  110. package/src/providers/registry/entries-core.ts +1221 -0
  111. package/src/providers/registry/entries-extended.ts +1204 -0
  112. package/src/providers/registry/model-seeds.ts +908 -0
  113. package/src/providers/registry/types.ts +352 -0
  114. package/src/providers/registry.ts +24 -3536
  115. package/src/responses/continuation-ownership.ts +29 -0
  116. package/src/responses/state/replay-fingerprint.ts +80 -0
  117. package/src/responses/state/snapshot-codec.ts +104 -0
  118. package/src/responses/state/spill-failure.ts +118 -0
  119. package/src/responses/state/spill-queue.ts +665 -0
  120. package/src/responses/state/temp-recovery.ts +257 -0
  121. package/src/responses/state.ts +82 -1143
  122. package/src/routing/identity-domains.ts +449 -0
  123. package/src/routing/probe-lease.ts +511 -0
  124. package/src/server/index/bounded-request.ts +88 -0
  125. package/src/server/index/live-sideband.ts +565 -0
  126. package/src/server/index/serve-options.ts +1766 -0
  127. package/src/server/index/startup-warnings.ts +213 -0
  128. package/src/server/index/websocket-handler.ts +335 -0
  129. package/src/server/index.ts +40 -2547
  130. package/src/server/management/route-registry.ts +26 -23
  131. package/src/server/management/shared.ts +8 -5
  132. package/src/server/management/workflow-budget-routes.ts +133 -0
  133. package/src/server/management-api.ts +12 -0
  134. package/src/server/request-log-conversation.ts +9 -7
  135. package/src/server/request-log.ts +245 -1
  136. package/src/server/responses/account-change-state.ts +233 -0
  137. package/src/server/responses/adapter-continuation.ts +514 -0
  138. package/src/server/responses/adapter-delivery.ts +214 -0
  139. package/src/server/responses/adapter-dispatch.ts +971 -0
  140. package/src/server/responses/compact.ts +59 -4
  141. package/src/server/responses/completion-policy.ts +33 -0
  142. package/src/server/responses/core-auth.ts +527 -0
  143. package/src/server/responses/core-codex-account.ts +859 -0
  144. package/src/server/responses/core-combo-failure.ts +210 -0
  145. package/src/server/responses/core-combo.ts +707 -0
  146. package/src/server/responses/core-errors.ts +152 -0
  147. package/src/server/responses/core-lifetime.ts +95 -0
  148. package/src/server/responses/core-normalize.ts +350 -0
  149. package/src/server/responses/core-opaque-recovery.ts +380 -0
  150. package/src/server/responses/core-options.ts +159 -0
  151. package/src/server/responses/core-replay.ts +225 -0
  152. package/src/server/responses/core.ts +192 -8893
  153. package/src/server/responses/passthrough-delivery.ts +856 -0
  154. package/src/server/responses/passthrough-dispatch.ts +1476 -0
  155. package/src/server/responses/passthrough-execution.ts +54 -0
  156. package/src/server/responses/request-prepare.ts +970 -0
  157. package/src/server/responses/request-send-budget.ts +164 -0
  158. package/src/server/responses/request-sidecar-auth.ts +149 -0
  159. package/src/server/responses/request-transport.ts +744 -0
  160. package/src/server/responses/response-effects.ts +157 -0
  161. package/src/server/responses/run-turn-execution.ts +448 -0
  162. package/src/server/responses/sidecar-execution.ts +469 -0
  163. package/src/server/responses-image-gen-repair.ts +1 -1
  164. package/src/server/workflow-refusal.ts +84 -0
  165. package/src/types/config.ts +30 -0
  166. package/src/usage/log.ts +146 -0
  167. package/src/usage/summary.ts +171 -21
@@ -139,7 +139,11 @@ export interface RetryBackoffOptions {
139
139
  * first instead of silently lengthening every adapter's backoff.
140
140
  */
141
141
  retryAfterIsLowerBound?: boolean;
142
- /** Hard ceiling for an honoured `Retry-After`, so an hour-long wait cannot park a request. */
142
+ /**
143
+ * The wait deadline a caller applies to an honoured `Retry-After`. The delay itself is
144
+ * never shortened: an instruction longer than the deadline is a reason to END with the
145
+ * upstream answer, not to send early. Kept for callers that still pass it.
146
+ */
143
147
  retryAfterCeilingMs?: number;
144
148
  }
145
149
 
@@ -305,10 +309,10 @@ export function retryBackoffDelayMs(attempt: number, opts: RetryBackoffOptions):
305
309
  // A provider that names a wait is stating when it will serve again; sending earlier is a
306
310
  // request we already know will be refused, and refusing it twice is the retry storm the
307
311
  // header exists to prevent. The local maximum bounds our OWN exponential backoff and has no
308
- // business shortening someone else's instruction. The ceiling is separate: it stops an
309
- // hour-long Retry-After from parking a request forever.
310
- const ceiling = opts.retryAfterCeilingMs ?? RETRY_AFTER_CEILING_MS;
311
- return Math.min(Math.max(retryAfter, jittered), ceiling);
312
+ // business shortening someone else's instruction, so the instruction is returned in full.
313
+ // Whether the request can afford to wait that long is the caller's deadline decision --
314
+ // fetchWithTransientRetry ends with the upstream answer rather than retrying early.
315
+ return Math.max(retryAfter, jittered);
312
316
  }
313
317
 
314
318
  export function cancelResponseBodyBestEffort(res: Response): void {
@@ -353,17 +357,31 @@ export interface ResetRetryOptions {
353
357
  label?: string;
354
358
  /** Total upstream sends allowed, including the first one. Not a per-layer retry count. */
355
359
  attempts?: number;
360
+ /**
361
+ * Reports how many upstream sends this call actually consumed, so a caller that spans
362
+ * several legs of one request (initial send, then a 429/account-recovery refetch) can
363
+ * keep them on ONE budget instead of handing each leg a fresh one.
364
+ *
365
+ * It lives on the RESET options, not on the transient ones, because every leg that falls
366
+ * back to reset-only retry -- the non-policy adapter initial send, and every
367
+ * `rebuildAndRefetch` recovery kind whose provider has no transient policy -- was not merely
368
+ * uncounted but UNCOUNTABLE: the callback existed on a type those call sites never reach.
369
+ */
370
+ onSendsConsumed?: (sends: number) => void;
356
371
  }
357
372
 
358
373
  export interface TransientRetryOptions extends ResetRetryOptions {
359
374
  /** Test seam: per-attempt slow budget override (defaults to TRANSIENT_RETRY_SLOW_ATTEMPT_MS). */
360
375
  slowAttemptMs?: number;
361
376
  /**
362
- * Reports how many upstream sends this call actually consumed, so a caller that spans
363
- * several legs of one request (initial send, then a 429/account-recovery refetch) can
364
- * keep them on ONE budget instead of handing each leg a fresh one.
377
+ * How long this caller can wait on an honoured `Retry-After`, defaulting to
378
+ * {@link RETRY_AFTER_CEILING_MS}. It is a deadline, never a clamp: an instruction inside it
379
+ * is slept in full, and an instruction past it ends the call with the upstream answer and
380
+ * its `Retry-After` intact rather than sending early at a provider that already said it
381
+ * would refuse. A caller with a shorter budget than a minute says so and is not parked past
382
+ * it; a caller that can genuinely wait longer says so and is not cut short.
365
383
  */
366
- onSendsConsumed?: (sends: number) => void;
384
+ retryAfterCeilingMs?: number;
367
385
  }
368
386
 
369
387
  export type UpstreamSendRecovery = "connection-reset" | "transient-5xx";
@@ -442,6 +460,10 @@ export async function fetchWithResetRetry(
442
460
  let sawReset = false;
443
461
  for (let attempt = 0; attempt < attempts; attempt++) {
444
462
  if (opts.abortSignal?.aborted) throw abortError(opts.abortSignal);
463
+ // Reported before the await, one physical send at a time: a send that rejects has still
464
+ // been made, and this helper leaves through four exits (return, reset give-up, non-reset
465
+ // rethrow, abort), so a per-send report is the only shape that is correct on all of them.
466
+ opts.onSendsConsumed?.(1);
445
467
  try {
446
468
  return await doFetch(attempt === 0 ? firstRecovery : "connection-reset");
447
469
  } catch (err) {
@@ -504,13 +526,22 @@ export async function fetchWithTransientRetry(
504
526
  // more send -- the loop condition alone was never enough, because every later recovery leg
505
527
  // called this helper again and the floor funded each of them.
506
528
  const remaining = () => Math.max(0, budget - sent);
529
+ // The inner reset layer now has its own `onSendsConsumed`, and these are the same physical
530
+ // sends `countedFetch` already counts. Forwarding the reporter down the `remaining()` path
531
+ // would report each of them twice, which is how a four-send cap becomes a two-send cap. One
532
+ // send is counted once, by the outermost layer that owns the budget.
533
+ const innerResetOptions = (): ResetRetryOptions => ({
534
+ ...opts,
535
+ attempts: remaining(),
536
+ onSendsConsumed: undefined,
537
+ });
507
538
  // Reported in `finally` rather than at each exit: this function returns from five places
508
539
  // and throws from one, and a caller sharing the budget across request legs must be told the
509
540
  // real count on every one of them.
510
541
  try {
511
542
  if (budget === 0) throw new SendBudgetExhaustedError(opts.label);
512
543
  let attemptStart = Date.now();
513
- let res = await fetchWithResetRetry(countedFetch, { ...opts, attempts: remaining() });
544
+ let res = await fetchWithResetRetry(countedFetch, innerResetOptions());
514
545
  for (let attempt = 0; sent < budget; attempt++) {
515
546
  // A non-replayable gateway status was settled after the request body had already left
516
547
  // for the origin; retrying it here is the automatic resend the marker exists to forbid.
@@ -519,6 +550,19 @@ export async function fetchWithTransientRetry(
519
550
  // a response whose body we just cancelled.
520
551
  if (opts.abortSignal?.aborted) return res;
521
552
  if (Date.now() - attemptStart > slowAttemptMs) return res;
553
+ const instructedDelay = retryAfterDelayMs(res.headers);
554
+ // The deadline is the CALLER'S, not this module's default. Reading the constant directly
555
+ // broke it in both directions: a caller with a 30s budget slept the full 45s an upstream
556
+ // asked for, and a caller that could genuinely wait 120s was handed the error back for a
557
+ // 90s instruction it was willing to honour.
558
+ const waitDeadlineMs = opts.retryAfterCeilingMs ?? RETRY_AFTER_CEILING_MS;
559
+ if (instructedDelay !== undefined && instructedDelay > waitDeadlineMs) {
560
+ // Honouring the stated wait would park this request past the deadline it can commit
561
+ // to, and sleeping only up to the deadline is a send the provider already said it will
562
+ // refuse. End here instead: the caller receives the upstream answer with its
563
+ // Retry-After intact and applies its own policy, exactly as on the direct path.
564
+ return res;
565
+ }
522
566
  console.warn(
523
567
  `[upstream-retry] transient ${res.status}${opts.label ? ` (${opts.label})` : ""} — retrying (${sent + 1}/${budget})`,
524
568
  );
@@ -535,7 +579,7 @@ export async function fetchWithTransientRetry(
535
579
  attemptStart = Date.now();
536
580
  transientStatuses.push(res.status);
537
581
  try {
538
- res = await fetchWithResetRetry(countedFetch, { ...opts, attempts: remaining() }, "transient-5xx");
582
+ res = await fetchWithResetRetry(countedFetch, innerResetOptions(), "transient-5xx");
539
583
  } catch (err) {
540
584
  // Keep the prior 5xx evidence attached: the origin already responded, so
541
585
  // this rejection is not pre-connection and must not classify as neutral.