@bitkyc08/opencodex 2.100.3 → 2.100.5-preview.20261118.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 (249) hide show
  1. package/AGENTS_INSTALL.md +23 -1
  2. package/bin/ocx.mjs +8 -1
  3. package/gui/dist/assets/{App-Dnb6VMsP.js → App-BiOGtxDS.js} +21 -20
  4. package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-BwsMejUO.js} +1 -1
  5. package/gui/dist/assets/brand-mark-BY1dgACL.js +1 -0
  6. package/gui/dist/assets/{index-DCdXsMyZ.js → index-CwHSKMdG.js} +46 -13
  7. package/gui/dist/assets/index-DJxM-imn.css +2 -0
  8. package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bds9Hb_7.js} +1 -1
  9. package/gui/dist/classic/assets/{App-DA-scMPq.js → App-CGLOiqQL.js} +20 -19
  10. package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-Da4r2O70.js} +1 -1
  11. package/gui/dist/classic/assets/{index-BqOaGLf5.js → index-CvoKXKL9.js} +46 -13
  12. package/gui/dist/classic/assets/quota-summary-DvqzfCmr.js +1 -0
  13. package/gui/dist/classic/index.html +1 -1
  14. package/gui/dist/index.html +2 -2
  15. package/native/ocx-child/src/cli.rs +5 -3
  16. package/native/ocx-child/src/codex_home.rs +1 -0
  17. package/native/ocx-child/src/link_ws.rs +24 -19
  18. package/native/ocx-child/src/link_ws_frame.rs +136 -50
  19. package/package.json +3 -3
  20. package/src/adapters/anthropic/per-message-effort.ts +296 -0
  21. package/src/adapters/anthropic-input-schema.ts +270 -0
  22. package/src/adapters/anthropic.ts +4 -63
  23. package/src/adapters/claude-cli/adapter.ts +1 -0
  24. package/src/adapters/command-code-tool-text.ts +9 -1
  25. package/src/adapters/command-code.ts +18 -2
  26. package/src/adapters/devin/cloud-direct/chat.ts +95 -14
  27. package/src/adapters/devin/live-models.ts +11 -1
  28. package/src/adapters/google-errors.ts +14 -2
  29. package/src/adapters/kiro/reasoning.ts +3 -0
  30. package/src/adapters/kiro-tools.ts +14 -9
  31. package/src/adapters/openai-responses/passthrough.ts +3 -1
  32. package/src/adapters/openai-responses/request-strips.ts +1 -0
  33. package/src/adapters/qoder/adapter.ts +9 -1
  34. package/src/adapters/tool-catalog-nudge.ts +1 -1
  35. package/src/adapters/zed.ts +4 -2
  36. package/src/claude/chat-tool-dispatch.ts +4 -1
  37. package/src/claude/desktop-remote-store.ts +60 -10
  38. package/src/cli/account-api.ts +4 -0
  39. package/src/cli/account-auth.ts +30 -2
  40. package/src/cli/account-extended.ts +33 -2
  41. package/src/cli/capabilities-access-remote.ts +3 -3
  42. package/src/cli/capabilities-accounts.ts +3 -3
  43. package/src/cli/capabilities-base.ts +11 -6
  44. package/src/cli/capabilities-observe-system.ts +2 -2
  45. package/src/cli/claude.ts +3 -3
  46. package/src/cli/disconnect-runtime.ts +16 -6
  47. package/src/cli/dispatch.ts +7 -1
  48. package/src/cli/index.ts +2 -2
  49. package/src/cli/link-apply-restart.ts +4 -2
  50. package/src/cli/link-routes.ts +4 -1
  51. package/src/cli/link.ts +5 -4
  52. package/src/cli/logout-command.ts +23 -4
  53. package/src/cli/preflight-exemptions.ts +3 -0
  54. package/src/cli/provider.ts +3 -2
  55. package/src/cli/registry.ts +5 -2
  56. package/src/cli/resolve.ts +23 -8
  57. package/src/cli/restart-failure.ts +11 -1
  58. package/src/cli/runtime-api.ts +4 -0
  59. package/src/cli/status.ts +4 -1
  60. package/src/cli/system-command.ts +1 -1
  61. package/src/cli/system-restart-client.ts +9 -3
  62. package/src/cli/system-settings-parity.ts +2 -1
  63. package/src/client/connect.ts +73 -11
  64. package/src/client/desktop-refusal.ts +38 -0
  65. package/src/client/lifecycle-lock.ts +29 -4
  66. package/src/client/runtime-restart.ts +27 -15
  67. package/src/client/runtime.ts +4 -2
  68. package/src/client/state.ts +14 -0
  69. package/src/clients/config-export.ts +12 -7
  70. package/src/codex/account-lifecycle.ts +3 -1
  71. package/src/codex/account-pause.ts +4 -0
  72. package/src/codex/account-runtime-state.ts +4 -0
  73. package/src/codex/auth-api/main-account-probe.ts +3 -1
  74. package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
  75. package/src/codex/auth-context.ts +40 -2
  76. package/src/codex/catalog/build-entries.ts +10 -0
  77. package/src/codex/catalog/derive-entry.ts +7 -0
  78. package/src/codex/catalog/metadata.ts +8 -0
  79. package/src/codex/catalog/native-models.ts +16 -6
  80. package/src/codex/catalog/pinned-models.ts +1 -0
  81. package/src/codex/catalog/provider-models.ts +5 -5
  82. package/src/codex/catalog/reserve-warn.ts +7 -5
  83. package/src/codex/catalog/reserve.ts +4 -3
  84. package/src/codex/catalog/retained-sync.ts +2 -0
  85. package/src/codex/catalog/routed-defaults.ts +35 -0
  86. package/src/codex/catalog-auto-refresh.ts +13 -2
  87. package/src/codex/config-drift-heal.ts +40 -12
  88. package/src/codex/config-write-lock.ts +39 -1
  89. package/src/codex/convergence.ts +2 -0
  90. package/src/codex/data/roster-pinned-models.json +346 -1
  91. package/src/codex/inject/config-write-section.ts +39 -1
  92. package/src/codex/inject/plan.ts +10 -8
  93. package/src/codex/inject/remove.ts +21 -19
  94. package/src/codex/inject/restore.ts +5 -1
  95. package/src/codex/inject-coordination.ts +58 -7
  96. package/src/codex/inject.ts +10 -12
  97. package/src/codex/journal-config-restore.ts +42 -0
  98. package/src/codex/journal.ts +62 -8
  99. package/src/codex/loopback-target.ts +22 -8
  100. package/src/codex/main-account.ts +94 -30
  101. package/src/codex/native-main-auth-file.ts +14 -0
  102. package/src/codex/native-main-credentials.ts +276 -0
  103. package/src/codex/native-main-owner.ts +3 -0
  104. package/src/codex/native-main-refresh-mode.ts +14 -1
  105. package/src/codex/quota.ts +63 -14
  106. package/src/combos/failover.ts +195 -1
  107. package/src/combos/index.ts +5 -0
  108. package/src/combos/resolve.ts +115 -19
  109. package/src/config/diagnostics.ts +3 -0
  110. package/src/config/live-reconcile.ts +6 -3
  111. package/src/config/load-degrade.ts +2 -0
  112. package/src/config/persisted-mutation.ts +2 -2
  113. package/src/config/persisted-projections.ts +18 -0
  114. package/src/config/process-state.ts +4 -3
  115. package/src/config/reserve-capability.ts +96 -0
  116. package/src/config/schema/config-schema.ts +6 -0
  117. package/src/config/schema/leaf-validators.ts +2 -0
  118. package/src/config/schema/routed-catalog-defaults.ts +49 -0
  119. package/src/config/subagent-models.ts +20 -12
  120. package/src/config.ts +7 -7
  121. package/src/desktop-update/acquire.ts +202 -0
  122. package/src/desktop-update/cli.ts +168 -0
  123. package/src/desktop-update/drain.ts +40 -0
  124. package/src/desktop-update/headless.ts +285 -0
  125. package/src/desktop-update/image.ts +85 -0
  126. package/src/desktop-update/install.ts +53 -0
  127. package/src/desktop-update/msi.ts +72 -0
  128. package/src/desktop-update/release.ts +128 -0
  129. package/src/desktop-update/runtime.ts +155 -0
  130. package/src/desktop-update/staging.ts +118 -0
  131. package/src/desktop-update/trust.ts +45 -0
  132. package/src/generated/compatibility-version.json +327 -195
  133. package/src/generated/model-metadata.ts +3 -3
  134. package/src/images/fulfill-video.ts +3 -3
  135. package/src/images/loop.ts +6 -2
  136. package/src/images/plan.ts +147 -11
  137. package/src/images/types.ts +13 -4
  138. package/src/images/xai-video-client.ts +72 -10
  139. package/src/lib/client-error-body.ts +6 -0
  140. package/src/lib/developer-role-rejection.ts +15 -0
  141. package/src/lib/gcp-adc.ts +48 -4
  142. package/src/lib/offline-resend.ts +150 -0
  143. package/src/lib/paced-stream.ts +3 -3
  144. package/src/lib/provider-outbound.ts +17 -6
  145. package/src/lib/request-failure-model.ts +2 -0
  146. package/src/lib/response-body-inactivity.ts +23 -1
  147. package/src/lib/upstream-retry.ts +39 -6
  148. package/src/link/explicit-route.ts +4 -4
  149. package/src/link/remote-windows.ts +79 -31
  150. package/src/link/residual-recovery.ts +20 -8
  151. package/src/messaging/budget.ts +23 -5
  152. package/src/messaging/remote-ports.ts +22 -10
  153. package/src/messaging/rpc.ts +4 -4
  154. package/src/oauth/antigravity-risk.ts +126 -0
  155. package/src/oauth/credential-siblings.ts +32 -0
  156. package/src/oauth/generic-account-failover.ts +113 -30
  157. package/src/oauth/generic-session-affinity.ts +10 -3
  158. package/src/oauth/index.ts +22 -14
  159. package/src/oauth/login-cli.ts +35 -1
  160. package/src/oauth/pool-kernel.ts +3 -3
  161. package/src/oauth/store.ts +38 -7
  162. package/src/providers/anthropic-billing-refusal.ts +27 -3
  163. package/src/providers/anthropic-reset-grants.ts +4 -0
  164. package/src/providers/claude-cli-usage.ts +2 -0
  165. package/src/providers/codebuddy-models.ts +11 -0
  166. package/src/providers/google-vertex-model-discovery.ts +49 -15
  167. package/src/providers/kiro-models.ts +5 -0
  168. package/src/providers/model-rename-fields.ts +2 -0
  169. package/src/providers/quota/workbuddy.ts +6 -2
  170. package/src/providers/registry/entries-core.ts +9 -3
  171. package/src/providers/registry/entries-extended.ts +20 -9
  172. package/src/providers/registry/model-seeds.ts +4 -1
  173. package/src/providers/stale-context-window-migration.ts +2 -0
  174. package/src/providers/workbuddy-credit-balance.ts +125 -16
  175. package/src/responses/citation-markers.ts +26 -23
  176. package/src/responses/effort-history.ts +732 -0
  177. package/src/routing/history/integrity.ts +41 -4
  178. package/src/server/auth-cors.ts +13 -3
  179. package/src/server/codex-model-list.ts +2 -1
  180. package/src/server/direct-local-http.ts +26 -3
  181. package/src/server/index/link-listener.ts +20 -14
  182. package/src/server/index/serve-options.ts +1 -0
  183. package/src/server/index.ts +3 -2
  184. package/src/server/link-turn.ts +17 -5
  185. package/src/server/management/config-routes.ts +39 -3
  186. package/src/server/management/link-child-preflight.ts +1 -1
  187. package/src/server/management/link-enrollment.ts +3 -3
  188. package/src/server/management/link-route-edit.ts +20 -1
  189. package/src/server/management/link-route-request.ts +11 -5
  190. package/src/server/management/oauth-account-routes.ts +43 -13
  191. package/src/server/management/provider-credential-release.ts +44 -0
  192. package/src/server/management/provider-overwrite-carry.ts +3 -0
  193. package/src/server/management/provider-routes.ts +12 -12
  194. package/src/server/management/static-catalog-probe.ts +33 -0
  195. package/src/server/management/usage-aggregate-cache.ts +6 -3
  196. package/src/server/messages-native.ts +16 -2
  197. package/src/server/proxy-liveness.ts +54 -9
  198. package/src/server/relay.ts +6 -1
  199. package/src/server/request-log-conversation.ts +8 -4
  200. package/src/server/request-log-failure-detail.ts +26 -9
  201. package/src/server/request-log.ts +5 -1
  202. package/src/server/reserve-capability-startup.ts +32 -0
  203. package/src/server/responses/adapter-continuation.ts +59 -25
  204. package/src/server/responses/adapter-delivery.ts +2 -0
  205. package/src/server/responses/adapter-dispatch.ts +39 -18
  206. package/src/server/responses/antigravity-fault-rotation.ts +24 -0
  207. package/src/server/responses/antigravity-validation-refusal.ts +43 -6
  208. package/src/server/responses/codex-tool-catalog.ts +47 -10
  209. package/src/server/responses/combo-selection-keepalive.ts +254 -0
  210. package/src/server/responses/combo-session-recall.ts +26 -1
  211. package/src/server/responses/combo-stream-preflight.ts +35 -26
  212. package/src/server/responses/core-combo-failure.ts +6 -0
  213. package/src/server/responses/core-combo-native.ts +2 -1
  214. package/src/server/responses/core-combo.ts +67 -28
  215. package/src/server/responses/core-errors.ts +9 -6
  216. package/src/server/responses/core-options.ts +10 -0
  217. package/src/server/responses/core.ts +21 -0
  218. package/src/server/responses/estimated-usage.ts +115 -0
  219. package/src/server/responses/input-admission.ts +41 -3
  220. package/src/server/responses/jev-model-invoke.ts +7 -2
  221. package/src/server/responses/passthrough-completion.ts +6 -3
  222. package/src/server/responses/passthrough-delivery.ts +47 -8
  223. package/src/server/responses/passthrough-dispatch.ts +3 -0
  224. package/src/server/responses/request-prepare.ts +9 -5
  225. package/src/server/responses/request-send-budget.ts +1 -1
  226. package/src/server/responses/request-transport.ts +10 -2
  227. package/src/server/responses/sidecar-execution.ts +11 -4
  228. package/src/service/desktop-supervision.d.mts +2 -0
  229. package/src/service/desktop-supervision.mjs +5 -0
  230. package/src/service/windows-checked-stop-live.ts +28 -5
  231. package/src/stall-timeout.ts +11 -0
  232. package/src/types/config.ts +15 -92
  233. package/src/types/provider.ts +13 -0
  234. package/src/types/request.ts +23 -3
  235. package/src/types/routed-catalog-defaults.ts +17 -0
  236. package/src/types/routing-profile.ts +90 -0
  237. package/src/types.ts +1 -0
  238. package/src/update/index.ts +1 -1
  239. package/src/usage/expected-prices.ts +35 -0
  240. package/src/usage/ledger-scanner.ts +44 -10
  241. package/src/usage/log.ts +14 -4
  242. package/src/usage/telemetry-contract.ts +1 -0
  243. package/src/web-search/loop.ts +20 -2
  244. package/src/web-search/parse.ts +2 -12
  245. package/src/web-search/passthrough-bridge.ts +7 -0
  246. package/src/web-search/sources.ts +13 -0
  247. package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
  248. package/gui/dist/assets/index-DQtCRNAw.css +0 -2
  249. package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Production seam for the Anthropic adapter's experimental `perMessageEffort` option (#6895).
3
+ *
4
+ * Off by default. With `providers.<name>.perMessageEffort: true` on an `anthropic`-adapter provider
5
+ * that sends to `api.anthropic.com` with an API key, a Codex conversation that changes reasoning
6
+ * effort keeps its top-level `output_config.effort` at the conversation's first value and carries
7
+ * each change as an effort-only system message, `{role: "system", content: [], output_config: {effort}}`,
8
+ * right before the user message of the turn that changed it, with the
9
+ * `mid-conversation-output-config-2026-07-01` beta. Earlier change points are re-sent at the same
10
+ * message index on every later turn, so the cached prefix stays byte-identical.
11
+ *
12
+ * The decision itself lives in `src/responses/effort-history.ts`. This file maps one request onto
13
+ * it (scope, lineage, receipt, emitted fields), applies a "send" decision to the wire body, and
14
+ * settles the pending slot when the turn completes or fails. Every request the module answers
15
+ * "off" is sent byte-for-byte as it would be without the option.
16
+ *
17
+ * Owner: structure/providers/anthropic-per-message-effort.md.
18
+ */
19
+ import { codexLineageScopeKey } from "../../codex/lineage";
20
+ import { readBoundedResponseBody } from "../../lib/bounded-body";
21
+ import { mergeAnthropicBetaHeader } from "../../providers/anthropic-fast";
22
+ import { SUMMARY_PREFIX } from "../../responses/compaction";
23
+ import {
24
+ abandon,
25
+ commit,
26
+ createStore,
27
+ decide,
28
+ hash,
29
+ kindOf,
30
+ lineageFromMetadata,
31
+ rejectUpstream,
32
+ type EffortHistoryDecision,
33
+ type EffortHistoryRequest,
34
+ type EffortHistoryStore,
35
+ } from "../../responses/effort-history";
36
+ import type { OcxParsedRequest, OcxProviderConfig, PerMessageEffortTurn } from "../../types";
37
+ import type { IncomingMeta } from "../base";
38
+
39
+ export const PER_MESSAGE_EFFORT_BETA = "mid-conversation-output-config-2026-07-01";
40
+ const TURN_METADATA = "x-codex-turn-metadata";
41
+ // The only credential generation an API key has: a rotated key is a different credential hash.
42
+ const KEY_GENERATION = "key";
43
+ const NEW_INPUT_KINDS = new Set(["user", "tool_result", "developer", "configuration_update"]);
44
+
45
+ type Rec = Record<string, unknown>;
46
+ const isRec = (value: unknown): value is Rec => value !== null && typeof value === "object" && !Array.isArray(value);
47
+
48
+ let store: EffortHistoryStore = createStore();
49
+
50
+ /** The process store. Tests only. */
51
+ export function perMessageEffortStoreForTests(): EffortHistoryStore {
52
+ return store;
53
+ }
54
+ /** Start from an empty store. Tests only. */
55
+ export function resetPerMessageEffortStoreForTests(): void {
56
+ store = createStore();
57
+ }
58
+
59
+ /**
60
+ * Whether Codex's own turn metadata for THIS request says the conversation is new
61
+ * (`history_initialization: "New"`). Over HTTP that is the request's `x-codex-turn-metadata` header.
62
+ * Over WebSocket only the frame's own `client_metadata` copy counts: the upgrade header describes
63
+ * the turn that opened the socket, not this one.
64
+ */
65
+ export function codexTurnStartsNewHistory(body: unknown, headers: Headers, transport?: "websocket"): boolean {
66
+ if (transport === "websocket") {
67
+ const client = isRec(body) && isRec(body.client_metadata) ? body.client_metadata : undefined;
68
+ return client !== undefined && Object.hasOwn(client, TURN_METADATA) && lineageFromMetadata(client[TURN_METADATA]);
69
+ }
70
+ return lineageFromMetadata(headers.get(TURN_METADATA));
71
+ }
72
+
73
+ /** The raw input split into the history the client echoes and this turn's new input. */
74
+ export function splitTurnInput(input: readonly unknown[]): { parent: unknown[]; suffix: unknown[] } {
75
+ let start = input.length;
76
+ while (start > 0 && NEW_INPUT_KINDS.has(kindOf(input[start - 1]))) start--;
77
+ return { parent: input.slice(0, start), suffix: input.slice(start) };
78
+ }
79
+
80
+ function firstInputText(item: unknown): string | undefined {
81
+ if (!isRec(item)) return undefined;
82
+ if (typeof item.content === "string") return item.content;
83
+ if (!Array.isArray(item.content)) return undefined;
84
+ const first = item.content[0];
85
+ return isRec(first) && (first.type === "input_text" || first.type === "text") && typeof first.text === "string" ? first.text : undefined;
86
+ }
87
+
88
+ function firstWireText(message: Rec): string | undefined {
89
+ if (typeof message.content === "string") return message.content;
90
+ if (!Array.isArray(message.content)) return undefined;
91
+ const first = message.content[0];
92
+ return isRec(first) && first.type === "text" && typeof first.text === "string" ? first.text : undefined;
93
+ }
94
+
95
+ /**
96
+ * The Anthropic `messages` index where this turn's effort message goes: the wire message that
97
+ * starts with this turn's user text. Only the trailing user-role run is searched, since this turn's
98
+ * input is user, tool-result and developer items. A user message merged behind other content, or
99
+ * one that starts with an image, has no such index and the change point is not placed.
100
+ */
101
+ export function userMessageWireIndex(messages: readonly unknown[], suffix: readonly unknown[]): number | undefined {
102
+ const text = firstInputText(suffix.find(item => kindOf(item) === "user"));
103
+ if (text === undefined) return undefined;
104
+ for (let index = messages.length - 1; index >= 0; index--) {
105
+ const message = messages[index];
106
+ if (!isRec(message) || message.role !== "user") return undefined;
107
+ if (firstWireText(message) === text) return index;
108
+ }
109
+ return undefined;
110
+ }
111
+
112
+ // Everything on the wire that does not move with effort. max_tokens and the emitted thinking
113
+ // field are compared on their own (rules 3b and 6).
114
+ function frameOf(body: Rec): string {
115
+ const { messages: _messages, max_tokens: _maxTokens, stream: _stream, thinking: _thinking, output_config: outputConfig, ...rest } = body;
116
+ const pinned = isRec(outputConfig) ? Object.fromEntries(Object.entries(outputConfig).filter(([key]) => key !== "effort")) : outputConfig;
117
+ return hash({ ...rest, output_config: pinned });
118
+ }
119
+
120
+ function destinationOf(url: string): string | undefined {
121
+ try {
122
+ return new URL(url).hostname;
123
+ } catch {
124
+ return undefined;
125
+ }
126
+ }
127
+
128
+ /** A turn the option never serves, decided before the store is consulted. */
129
+ function outsideOption(parsed: OcxParsedRequest): boolean {
130
+ return parsed.stream !== true || parsed._advisorGuard !== undefined
131
+ || parsed._compactionRequest === true || parsed._summaryProhibitsToolCalls === true
132
+ || parsed._memoryModelPhase !== undefined;
133
+ }
134
+
135
+ /**
136
+ * Share one turn record across a hosted sidecar loop (web search, images, video) before its first
137
+ * build. Each iteration builds from a spread copy of the parsed request, so the copies hold this
138
+ * same record: the first build decides, a later iteration abandons the decision and is sent as
139
+ * today, and the loop's completion settles it.
140
+ */
141
+ export function shareAnthropicPerMessageEffortTurn(parsed: OcxParsedRequest): void {
142
+ parsed._perMessageEffort ??= { builds: 0, generation: KEY_GENERATION };
143
+ }
144
+
145
+ export interface PerMessageEffortBuild {
146
+ provider: OcxProviderConfig;
147
+ parsed: OcxParsedRequest;
148
+ incoming?: IncomingMeta;
149
+ /** The finished wire body, mutated in place on a "send" decision. */
150
+ body: Rec;
151
+ headers: Record<string, string>;
152
+ url: string;
153
+ isOAuth: boolean;
154
+ chatLineage?: string;
155
+ }
156
+
157
+ function requestFor(build: PerMessageEffortBuild, input: unknown[]): EffortHistoryRequest {
158
+ const { provider, parsed, incoming, body, url, isOAuth } = build;
159
+ const raw = parsed._rawBody as Rec;
160
+ const { parent, suffix } = splitTurnInput(input);
161
+ const outputConfig = isRec(body.output_config) ? body.output_config : undefined;
162
+ const messages = Array.isArray(body.messages) ? body.messages : [];
163
+ return {
164
+ chatLineage: build.chatLineage,
165
+ scope: {
166
+ cohort: incoming ? codexLineageScopeKey(incoming.headers) : undefined,
167
+ provider: incoming?.providerName,
168
+ destination: destinationOf(url),
169
+ adapter: "anthropic",
170
+ model: typeof body.model === "string" ? body.model : undefined,
171
+ credential: typeof provider.apiKey === "string" && provider.apiKey ? hash(["credential", provider.apiKey]) : undefined,
172
+ authMode: isOAuth ? "oauth" : "apiKey",
173
+ },
174
+ parent,
175
+ suffix,
176
+ effort: typeof outputConfig?.effort === "string" ? outputConfig.effort : undefined,
177
+ thinking: body.thinking,
178
+ emittedMaxTokens: typeof body.max_tokens === "number" ? body.max_tokens : undefined,
179
+ frame: frameOf(body),
180
+ generation: KEY_GENERATION,
181
+ cacheControl: JSON.stringify(body).includes("\"cache_control\""),
182
+ stripped: parsed._stripReasoningEncryptedContent === true,
183
+ transport: "http",
184
+ apiKind: parsed._anthropicInbound === true || parsed._chatCompletionsInput === true ? "messages" : "responses",
185
+ previousResponseId: raw.previous_response_id ?? (parsed._previousResponseInputExpanded === true ? true : undefined),
186
+ compactionSummary: suffix.some(item => kindOf(item) === "user" && firstInputText(item)?.startsWith(SUMMARY_PREFIX) === true),
187
+ newTranscriptReceipt: parsed._codexNewHistory === true,
188
+ changeWireIndex: userMessageWireIndex(messages, suffix),
189
+ };
190
+ }
191
+
192
+ function applySend(build: PerMessageEffortBuild, decision: Extract<EffortHistoryDecision, { action: "send" }>, userIndex: number | undefined): boolean {
193
+ const messages = build.body.messages;
194
+ if (!Array.isArray(messages)) return false;
195
+ const points = decision.changePoints ?? [];
196
+ // Every index must still name a user message, the indices must rise strictly in prefix order, and
197
+ // only this turn's own change point may sit at this turn's user message; otherwise nothing changes.
198
+ if (points.some((point, i) => !isRec(messages[point.wireIndex]) || (messages[point.wireIndex] as Rec).role !== "user"
199
+ || (i > 0 && point.wireIndex <= points[i - 1].wireIndex))) return false;
200
+ if (userIndex !== undefined && points.some(point => point === decision.insert ? point.wireIndex !== userIndex : point.wireIndex >= userIndex)) return false;
201
+ for (const point of [...points].reverse()) {
202
+ messages.splice(point.wireIndex, 0, { role: "system", content: [], output_config: { effort: point.effort } });
203
+ }
204
+ build.body.output_config = { ...(isRec(build.body.output_config) ? build.body.output_config : {}), effort: decision.anchorEffort };
205
+ mergeAnthropicBetaHeader(build.headers, [PER_MESSAGE_EFFORT_BETA]);
206
+ return true;
207
+ }
208
+
209
+ /**
210
+ * Decide this build and apply a "send" decision to `body` and `headers`. A second build of the same
211
+ * turn (a retry, rebuild or failover) abandons the first decision and is sent as today.
212
+ */
213
+ export function applyAnthropicPerMessageEffort(build: PerMessageEffortBuild): void {
214
+ const { provider, parsed } = build;
215
+ const existing = parsed._perMessageEffort;
216
+ // Counted before the switch: a failover to a provider without the option is still a second build.
217
+ if (existing && existing.builds > 0) {
218
+ existing.builds += 1;
219
+ const token = existing.token;
220
+ existing.token = undefined;
221
+ if (token) abandon(store, token, { sent: true });
222
+ return;
223
+ }
224
+ if (existing) existing.builds = 1;
225
+ if (provider.perMessageEffort !== true) return;
226
+ const turn: PerMessageEffortTurn = existing ?? { builds: 1, generation: KEY_GENERATION };
227
+ parsed._perMessageEffort = turn;
228
+ if (outsideOption(parsed) || !isRec(parsed._rawBody) || !Array.isArray(parsed._rawBody.input)) return;
229
+ let request: EffortHistoryRequest;
230
+ try {
231
+ request = requestFor(build, parsed._rawBody.input);
232
+ } catch {
233
+ // Mapping the build failed (for example a pathologically deep body): off, sent as today.
234
+ return;
235
+ }
236
+ const decision = decide(store, request, {
237
+ enabled: true,
238
+ activated: true,
239
+ websocketHeaderRead: true,
240
+ compactionMarkerIdentified: true,
241
+ });
242
+ if (decision.action !== "send") return;
243
+ if (!applySend(build, decision, request.changeWireIndex)) {
244
+ abandon(store, decision.pendingToken, { sent: false });
245
+ return;
246
+ }
247
+ turn.token = decision.pendingToken;
248
+ }
249
+
250
+ /**
251
+ * Settle the turn at its terminal response: a completed Anthropic turn commits with its output
252
+ * items and the cache counters on the response's own usage; anything else deletes the pending slot.
253
+ */
254
+ export function settleAnthropicPerMessageEffort(parsed: OcxParsedRequest, response: Rec, adapterName: string): void {
255
+ const turn = parsed._perMessageEffort;
256
+ const token = turn?.token;
257
+ if (!turn || !token) return;
258
+ turn.token = undefined;
259
+ if (response.status !== "completed" || turn.builds !== 1 || adapterName !== "anthropic") {
260
+ abandon(store, token, { sent: true });
261
+ return;
262
+ }
263
+ // The completed response's usage: cached_tokens is the cache read, cache_write_tokens the creation.
264
+ const usage = isRec(response.usage) && isRec(response.usage.input_tokens_details) ? response.usage.input_tokens_details : {};
265
+ const read = typeof usage.cached_tokens === "number" ? usage.cached_tokens : 0;
266
+ const write = typeof usage.cache_write_tokens === "number" ? usage.cache_write_tokens : 0;
267
+ commit(store, token, {
268
+ messageStop: true,
269
+ cacheRead: read,
270
+ P: read + write,
271
+ outputItems: Array.isArray(response.output) ? response.output : undefined,
272
+ generation: turn.generation,
273
+ });
274
+ }
275
+
276
+ /**
277
+ * An upstream error for a turn that holds a pending slot: the slot is deleted, and the documented
278
+ * model-unsupported 400 marks the model and destination unsupported. Nothing is resent here.
279
+ */
280
+ export async function rejectAnthropicPerMessageEffort(parsed: OcxParsedRequest, response: Response, signal?: AbortSignal): Promise<void> {
281
+ const turn = parsed._perMessageEffort;
282
+ const token = turn?.token;
283
+ if (!turn || !token || response.ok) return;
284
+ turn.token = undefined;
285
+ let errorText = "";
286
+ if (response.status === 400) {
287
+ try {
288
+ const body = await readBoundedResponseBody(response.clone(), { signal });
289
+ if (body.displaySafe && !body.truncated) errorText = body.text;
290
+ } catch {
291
+ // An unreadable body is an unclassified 400: the slot is still deleted, no capability record.
292
+ }
293
+ }
294
+ rejectUpstream(store, token, { status: response.status, errorText });
295
+ }
296
+
@@ -0,0 +1,270 @@
1
+ import { stripResponsesOnlyEncryptedMarker } from "./responses-tool-schema";
2
+
3
+ /**
4
+ * Anthropic rejects a root-level missing `type` and root-level `oneOf`/`anyOf`/`allOf` in
5
+ * `input_schema`. Normalize the root only: ensure `type:"object"` + `properties`, flatten root
6
+ * composition while preserving nested schemas, and inline local `#/...` refs (RFC 6901: the
7
+ * fragment is percent-decoded, numeric tokens index arrays) before flattening so a referenced
8
+ * branch keeps its parameters and required members. A `$ref` with siblings merges both property
9
+ * maps, unions `required`, and keeps a property declared on both sides conjunctive under
10
+ * `allOf`; composition on both sides is kept, not replaced. A property met twice on an all-`allOf`
11
+ * path is conjoined the same way. Composition branches and direct alias hops share one 4096-step
12
+ * budget. Shared by the anthropic and command-code adapters; Command Code's text-call recovery
13
+ * matches markup against the normalized schema and validates it against the declared one too.
14
+ *
15
+ * Flattening root alternatives is lossy: later branches win for a same-named property, and
16
+ * `oneOf`/`anyOf` branch `required` members are not promoted because no branch is guaranteed.
17
+ * A root `oneOf` whose branches declare `action.enum: ["read"]` and `action.enum: ["write"]`
18
+ * yields a schema that permits only `"write"`. Covered by
19
+ * tests/providers/command-code-tool-schema.test.ts and
20
+ * tests/adapters/anthropic/anthropic-tool-schema.test.ts.
21
+ */
22
+
23
+ const LOCAL_REF_PREFIX = "#/";
24
+ const COMPOSITION_KEYS = ["oneOf", "anyOf", "allOf"] as const;
25
+ /** Branch visits allowed while expanding root composition; shared ref graphs multiply. */
26
+ const ROOT_COMPOSITION_EXPANSION_LIMIT = 4096;
27
+ const ROOT_COMPOSITION_LIMIT_MESSAGE =
28
+ "tool input schema reference expansion exceeded the supported limit";
29
+ /** Shared work budget: composition branches and direct `$ref` alias hops both count against it. */
30
+ interface ExpansionBudget { count: number }
31
+
32
+ function spend(budget: ExpansionBudget): void {
33
+ budget.count += 1;
34
+ if (budget.count > ROOT_COMPOSITION_EXPANSION_LIMIT) throw new Error(ROOT_COMPOSITION_LIMIT_MESSAGE);
35
+ }
36
+
37
+ function decodePointerSegment(segment: string): string {
38
+ return segment.replace(/~1/g, "/").replace(/~0/g, "~");
39
+ }
40
+
41
+ /**
42
+ * RFC 6901: a URI fragment is percent-decoded before it is split into tokens, each token then
43
+ * undoes `~1`/`~0`, and a canonical decimal token selects an array element. A malformed escape
44
+ * or a path that does not resolve leaves the reference unresolved.
45
+ */
46
+ function resolveLocalPointer(root: Record<string, unknown>, pointer: string): Record<string, unknown> | undefined {
47
+ if (!pointer.startsWith(LOCAL_REF_PREFIX)) return undefined;
48
+ let decoded: string;
49
+ try {
50
+ decoded = decodeURIComponent(pointer.slice(2));
51
+ } catch {
52
+ return undefined;
53
+ }
54
+ let node: unknown = root;
55
+ for (const segment of decoded.split("/")) {
56
+ const token = decodePointerSegment(segment);
57
+ if (Array.isArray(node)) {
58
+ if (!/^(?:0|[1-9]\d*)$/.test(token)) return undefined;
59
+ node = node[Number(token)];
60
+ continue;
61
+ }
62
+ if (!node || typeof node !== "object" || !Object.hasOwn(node, token)) return undefined;
63
+ node = (node as Record<string, unknown>)[token];
64
+ }
65
+ return node && typeof node === "object" && !Array.isArray(node)
66
+ ? node as Record<string, unknown>
67
+ : undefined;
68
+ }
69
+
70
+ function asSchemaMap(value: unknown): Record<string, unknown> | undefined {
71
+ return value && typeof value === "object" && !Array.isArray(value)
72
+ ? value as Record<string, unknown>
73
+ : undefined;
74
+ }
75
+
76
+ /** Conjunctions this module built, so a later collision extends them instead of nesting. */
77
+ const builtConjunctions = new WeakSet<object>();
78
+
79
+ /**
80
+ * Both schemas apply. A conjunction built here gains one more member; a caller's own `allOf`
81
+ * schema stays a single member so its meaning is not spliced into ours.
82
+ */
83
+ function conjoin(existing: unknown, schema: unknown): Record<string, unknown> {
84
+ const members = existing && typeof existing === "object" && builtConjunctions.has(existing)
85
+ ? [...((existing as { allOf: unknown[] }).allOf)]
86
+ : [existing];
87
+ if (!members.includes(schema)) members.push(schema);
88
+ const conjunction = { allOf: members };
89
+ builtConjunctions.add(conjunction);
90
+ return conjunction;
91
+ }
92
+
93
+ /**
94
+ * JSON Schema applies a `$ref` sibling's keywords alongside the referenced schema rather than
95
+ * replacing them. Spread would let a sibling that adds one parameter drop the referenced ones, so
96
+ * merge both `properties` maps, union `required`, and keep both constraints under `allOf` when a
97
+ * property appears on both sides.
98
+ */
99
+ function mergeRefSiblings(
100
+ resolved: Record<string, unknown>,
101
+ siblings: Record<string, unknown>,
102
+ ): Record<string, unknown> {
103
+ const merged: Record<string, unknown> = { ...resolved, ...siblings };
104
+
105
+ const resolvedProperties = asSchemaMap(resolved.properties);
106
+ const siblingProperties = asSchemaMap(siblings.properties);
107
+ if (resolvedProperties || siblingProperties) {
108
+ // Null prototype keeps a parameter named "__proto__" as data instead of replacing the prototype.
109
+ const properties: Record<string, unknown> = Object.create(null) as Record<string, unknown>;
110
+ for (const [name, schema] of Object.entries(resolvedProperties ?? {})) properties[name] = schema;
111
+ for (const [name, schema] of Object.entries(siblingProperties ?? {})) {
112
+ const existing = properties[name];
113
+ properties[name] = existing === undefined ? schema : conjoin(existing, schema);
114
+ }
115
+ merged.properties = properties;
116
+ }
117
+
118
+ const required = new Set<string>();
119
+ for (const source of [resolved.required, siblings.required]) {
120
+ if (!Array.isArray(source)) continue;
121
+ for (const item of source) if (typeof item === "string") required.add(item);
122
+ }
123
+ if (required.size > 0) merged.required = [...required];
124
+ else delete merged.required;
125
+
126
+ // The spread above lets a sibling's composition replace the referenced schema's. Both sides
127
+ // apply, so concatenate `allOf` and keep each side's `oneOf`/`anyOf` as its own `allOf` entry.
128
+ const allOf: unknown[] = [];
129
+ for (const source of [resolved, siblings]) if (Array.isArray(source.allOf)) allOf.push(...source.allOf);
130
+ for (const key of ["oneOf", "anyOf"] as const) {
131
+ if (Array.isArray(resolved[key]) && Array.isArray(siblings[key])) {
132
+ allOf.push({ [key]: resolved[key] }, { [key]: siblings[key] });
133
+ delete merged[key];
134
+ }
135
+ }
136
+ if (allOf.length > 0) merged.allOf = allOf;
137
+
138
+ return merged;
139
+ }
140
+
141
+ /**
142
+ * Inline a local `#/...` reference so root-composition branches keep their definitions. Each
143
+ * alias hop spends the shared budget, so a long direct chain fails explicitly instead of
144
+ * recursing until the stack or allocation gives out.
145
+ */
146
+ function dereferenceLocal(
147
+ node: unknown,
148
+ root: Record<string, unknown>,
149
+ seen: ReadonlySet<string>,
150
+ budget: ExpansionBudget,
151
+ ): Record<string, unknown> | undefined {
152
+ if (!node || typeof node !== "object" || Array.isArray(node)) return undefined;
153
+ const record = node as Record<string, unknown>;
154
+ const ref = record.$ref;
155
+ if (typeof ref !== "string" || !ref.startsWith(LOCAL_REF_PREFIX) || seen.has(ref)) return record;
156
+ spend(budget);
157
+ const target = resolveLocalPointer(root, ref);
158
+ if (!target) return record;
159
+ const nextSeen = new Set(seen);
160
+ nextSeen.add(ref);
161
+ const resolved = dereferenceLocal(target, root, nextSeen, budget) ?? target;
162
+ const { $ref: _ignored, ...siblings } = record;
163
+ return mergeRefSiblings(resolved, siblings);
164
+ }
165
+
166
+ /**
167
+ * `allOf` applies every branch, so a property met twice on an all-`allOf` path keeps both
168
+ * schemas under `allOf`. On a path through `oneOf`/`anyOf` the documented last-branch-wins
169
+ * flattening still applies. The same schema object reached twice (a shared `$ref`) is kept once.
170
+ */
171
+ function collectProperty(
172
+ properties: Record<string, unknown>,
173
+ name: string,
174
+ schema: unknown,
175
+ conjunctive: boolean,
176
+ ): void {
177
+ const existing = properties[name];
178
+ if (existing === schema) return;
179
+ properties[name] = conjunctive && existing !== undefined ? conjoin(existing, schema) : schema;
180
+ }
181
+
182
+ /**
183
+ * Flatten root-equivalent composition, including composition that a resolved `$ref` branch
184
+ * carries. Only a node standing where the root composition stands contributes; `properties`
185
+ * and nested property schemas are never traversed. `chain` holds the refs already inlined on
186
+ * this path, so a self- or mutually-recursive definition stops instead of recursing forever.
187
+ * `visits` bounds the total expansion so a shared acyclic graph cannot multiply work; exceeding
188
+ * it throws, and the adapter build then fails as an explicit invalid request.
189
+ */
190
+ function collectRootComposition(
191
+ node: Record<string, unknown>,
192
+ root: Record<string, unknown>,
193
+ chain: ReadonlySet<string>,
194
+ mergeRequired: boolean,
195
+ properties: Record<string, unknown>,
196
+ required: Set<string>,
197
+ budget: ExpansionBudget,
198
+ ): void {
199
+ for (const key of COMPOSITION_KEYS) {
200
+ const variants = node[key];
201
+ if (!Array.isArray(variants)) continue;
202
+ const branchMergesRequired = mergeRequired && key === "allOf";
203
+ for (const variant of variants) {
204
+ const record = asSchemaMap(variant);
205
+ if (!record) continue;
206
+ const ref = typeof record.$ref === "string" ? record.$ref : undefined;
207
+ if (ref && chain.has(ref)) continue;
208
+ spend(budget);
209
+ const resolved = dereferenceLocal(variant, root, chain, budget);
210
+ if (!resolved) continue;
211
+ const nextChain = ref ? new Set(chain).add(ref) : chain;
212
+ const branchProperties = asSchemaMap(resolved.properties);
213
+ if (branchProperties) {
214
+ for (const [name, schema] of Object.entries(branchProperties)) {
215
+ collectProperty(properties, name, schema, branchMergesRequired);
216
+ }
217
+ }
218
+ if (branchMergesRequired && Array.isArray(resolved.required)) {
219
+ for (const item of resolved.required) if (typeof item === "string") required.add(item);
220
+ }
221
+ collectRootComposition(resolved, root, nextChain, branchMergesRequired, properties, required, budget);
222
+ }
223
+ }
224
+ }
225
+
226
+ export function normalizeAnthropicInputSchema(schema: unknown): Record<string, unknown> {
227
+ const stripped = stripResponsesOnlyEncryptedMarker(schema);
228
+ const obj = stripped && typeof stripped === "object" && !Array.isArray(stripped)
229
+ ? stripped as Record<string, unknown>
230
+ : {};
231
+ const budget: ExpansionBudget = { count: 0 };
232
+ const root = dereferenceLocal(obj, obj, new Set(), budget) ?? obj;
233
+ const hasRootComposition = COMPOSITION_KEYS.some(key => Array.isArray(root[key]));
234
+ const type = root.type;
235
+ const rootObjectType = type === "object" || (Array.isArray(type) && type.includes("object"));
236
+
237
+ if (!hasRootComposition) {
238
+ const normalized: Record<string, unknown> = rootObjectType && type === "object"
239
+ ? { ...root }
240
+ : { ...root, type: "object" };
241
+ if (normalized.properties === undefined || normalized.properties === null) {
242
+ normalized.properties = {};
243
+ }
244
+ return normalized;
245
+ }
246
+
247
+ // Null prototype keeps a parameter literally named "__proto__" as data instead of letting
248
+ // Object.assign replace this object's prototype and drop the parameter from JSON output.
249
+ const properties: Record<string, unknown> = Object.create(null) as Record<string, unknown>;
250
+ const required = new Set<string>();
251
+ if (root.properties && typeof root.properties === "object" && !Array.isArray(root.properties)) {
252
+ Object.assign(properties, root.properties as Record<string, unknown>);
253
+ }
254
+ if (Array.isArray(root.required)) {
255
+ for (const item of root.required) if (typeof item === "string") required.add(item);
256
+ }
257
+
258
+ collectRootComposition(root, root, new Set(), true, properties, required, budget);
259
+
260
+ const normalized: Record<string, unknown> = {};
261
+ for (const [key, value] of Object.entries(root)) {
262
+ if (key === "oneOf" || key === "anyOf" || key === "allOf") continue;
263
+ if (key === "type" || key === "properties" || key === "required") continue;
264
+ normalized[key] = value;
265
+ }
266
+ normalized.type = "object";
267
+ normalized.properties = properties;
268
+ if (required.size > 0) normalized.required = [...required];
269
+ return normalized;
270
+ }
@@ -26,7 +26,7 @@ import { parseDataUrl } from "./image";
26
26
  import { enforceAnthropicImageLimits } from "./anthropic-image-guard";
27
27
  import { normalizeAnthropicImages } from "./anthropic-image-normalize";
28
28
  import { normalizeAnthropicOutputSchema } from "./anthropic-output-schema";
29
- import { stripResponsesOnlyEncryptedMarker } from "./responses-tool-schema";
29
+ import { normalizeAnthropicInputSchema } from "./anthropic-input-schema";
30
30
  import { identifyRoutedModel } from "./identity";
31
31
  import { redactSecretString } from "../lib/redact";
32
32
  import { CLAUDE_CODE_HEADERS, claudeCodeSessionId } from "./client-fingerprint";
@@ -42,6 +42,7 @@ import { declaresThinkingToggleWire, reasoningControlsAreUnsupported } from "./r
42
42
  import { applyAgentRouterLanguageFraming, isAgentRouterEndpoint } from "./agentrouter";
43
43
  import { anthropicCacheWrite1hTokens, resolveAnthropicCacheRetention, type AnthropicCacheRetention } from "./anthropic/cache-retention";
44
44
  import { advisorServerExchange, advisorServerToolDestination, planAnthropicServerTools } from "./anthropic/advisor-tool";
45
+ import { applyAnthropicPerMessageEffort } from "./anthropic/per-message-effort";
45
46
  import { claudeFamilyVersion, rejectsCombinedSampling, rejectsForcedToolChoice, rejectsSamplingParameters, supportsExplicitThinkingDisable, usesAdaptiveThinking, usesBetweenToolsFloor } from "./anthropic-model-contract";
46
47
 
47
48
  /** Map a user content part to an Anthropic content block (text or image source). */
@@ -971,68 +972,6 @@ function withAnthropicServerTools(tools: unknown[] | undefined, parsed: OcxParse
971
972
  return [...(tools ?? []), ...serverTools.map(t => ({ ...t, cache_control: undefined }))];
972
973
  }
973
974
 
974
- function normalizeAnthropicInputSchema(schema: unknown): Record<string, unknown> {
975
- const stripped = stripResponsesOnlyEncryptedMarker(schema);
976
- const obj = stripped && typeof stripped === "object" && !Array.isArray(stripped)
977
- ? stripped as Record<string, unknown>
978
- : {};
979
- // Anthropic rejects root-level missing type and oneOf/anyOf/allOf in input_schema.
980
- // Normalize the root only: ensure type:"object" + properties, flatten root composition
981
- // while preserving nested schemas. Mirrors kiro-tools.ts ensureRootObjectType.
982
- // Known limitation: Object.assign on branch properties means later branches overwrite
983
- // earlier ones when the same property name appears with different schemas.
984
- const compositionKeys = ["oneOf", "anyOf", "allOf"] as const;
985
- const hasRootComposition = compositionKeys.some(key => Array.isArray(obj[key]));
986
- const type = obj.type;
987
- const rootObjectType = type === "object" || (Array.isArray(type) && type.includes("object"));
988
-
989
- if (!hasRootComposition) {
990
- const normalized: Record<string, unknown> = rootObjectType && type === "object"
991
- ? { ...obj }
992
- : { ...obj, type: "object" };
993
- if (normalized.properties === undefined || normalized.properties === null) {
994
- normalized.properties = {};
995
- }
996
- return normalized;
997
- }
998
-
999
- const properties: Record<string, unknown> = {};
1000
- const required = new Set<string>();
1001
- if (obj.properties && typeof obj.properties === "object" && !Array.isArray(obj.properties)) {
1002
- Object.assign(properties, obj.properties as Record<string, unknown>);
1003
- }
1004
- if (Array.isArray(obj.required)) {
1005
- for (const item of obj.required) if (typeof item === "string") required.add(item);
1006
- }
1007
-
1008
- for (const key of compositionKeys) {
1009
- const variants = obj[key];
1010
- if (!Array.isArray(variants)) continue;
1011
- const mergeRequired = key === "allOf";
1012
- for (const variant of variants) {
1013
- if (!variant || typeof variant !== "object" || Array.isArray(variant)) continue;
1014
- const v = variant as Record<string, unknown>;
1015
- if (v.properties && typeof v.properties === "object" && !Array.isArray(v.properties)) {
1016
- Object.assign(properties, v.properties as Record<string, unknown>);
1017
- }
1018
- if (mergeRequired && Array.isArray(v.required)) {
1019
- for (const item of v.required) if (typeof item === "string") required.add(item);
1020
- }
1021
- }
1022
- }
1023
-
1024
- const normalized: Record<string, unknown> = {};
1025
- for (const [key, value] of Object.entries(obj)) {
1026
- if (key === "oneOf" || key === "anyOf" || key === "allOf") continue;
1027
- if (key === "type" || key === "properties" || key === "required") continue;
1028
- normalized[key] = value;
1029
- }
1030
- normalized.type = "object";
1031
- normalized.properties = properties;
1032
- if (required.size > 0) normalized.required = [...required];
1033
- return normalized;
1034
- }
1035
-
1036
975
  export function createAnthropicAdapter(provider: OcxProviderConfig, cacheRetention?: "none" | "short" | "long"): ProviderAdapter {
1037
976
  const isOAuth = provider.authMode === "oauth";
1038
977
  const toolNames = buildToolNameTransforms(provider);
@@ -1320,6 +1259,8 @@ export function createAnthropicAdapter(provider: OcxProviderConfig, cacheRetenti
1320
1259
  });
1321
1260
  enforceCacheControlLimit(body, explicitLimit);
1322
1261
  normalizeTtlOrdering(body);
1262
+ // Experimental, default off (#6895): pin the top-level effort and carry changes as effort messages.
1263
+ applyAnthropicPerMessageEffort({ provider, parsed, incoming, body, headers, url, isOAuth, chatLineage: resolveTranslatedAnthropicSessionKey(parsed, incoming) });
1323
1264
 
1324
1265
  const request = {
1325
1266
  url,
@@ -90,6 +90,7 @@ export function buildChildEnv(_profile: ClaudeCliProfile, _apiKey: string): Reco
90
90
  const env: Record<string, string> = {
91
91
  ...baseScopedEnv(),
92
92
  ...CLAUDE_CLI_QUIET_ENV,
93
+ CLAUDE_CODE_ENTRYPOINT: "opencodex",
93
94
  };
94
95
  const user = process.env.USER;
95
96
  if (user) env.USER = user;