llm-relay 0.61.0 → 0.63.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 (235) hide show
  1. package/dist/accounting-store-io.js +0 -33
  2. package/dist/accounting-store-io.js.map +1 -1
  3. package/dist/accounting-store-schema.js +0 -65
  4. package/dist/accounting-store-schema.js.map +1 -1
  5. package/dist/accounting-store.js +0 -195
  6. package/dist/accounting-store.js.map +1 -1
  7. package/dist/accounting.js +0 -72
  8. package/dist/accounting.js.map +1 -1
  9. package/dist/anthropic.js +0 -18
  10. package/dist/anthropic.js.map +1 -1
  11. package/dist/authEnv.js +0 -78
  12. package/dist/authEnv.js.map +1 -1
  13. package/dist/availability-snapshot.js +0 -58
  14. package/dist/availability-snapshot.js.map +1 -1
  15. package/dist/availability.js +0 -162
  16. package/dist/availability.js.map +1 -1
  17. package/dist/backend.js +1 -416
  18. package/dist/backend.js.map +1 -1
  19. package/dist/benchmarks.js +1 -63
  20. package/dist/benchmarks.js.map +1 -1
  21. package/dist/breaker-persistence.js +0 -59
  22. package/dist/breaker-persistence.js.map +1 -1
  23. package/dist/candidates.js +0 -64
  24. package/dist/candidates.js.map +1 -1
  25. package/dist/catalog.js +1 -140
  26. package/dist/catalog.js.map +1 -1
  27. package/dist/circuit-breaker.js +1 -90
  28. package/dist/circuit-breaker.js.map +1 -1
  29. package/dist/claude-hook.js +0 -81
  30. package/dist/claude-hook.js.map +1 -1
  31. package/dist/cli.d.ts +89 -1
  32. package/dist/cli.js +115 -702
  33. package/dist/cli.js.map +1 -1
  34. package/dist/config-edit.js +0 -11
  35. package/dist/config-edit.js.map +1 -1
  36. package/dist/config.d.ts +21 -0
  37. package/dist/config.js +22 -372
  38. package/dist/config.js.map +1 -1
  39. package/dist/configured-limits.js +0 -58
  40. package/dist/configured-limits.js.map +1 -1
  41. package/dist/context-limits.js +0 -97
  42. package/dist/context-limits.js.map +1 -1
  43. package/dist/control-authorization.js +0 -36
  44. package/dist/control-authorization.js.map +1 -1
  45. package/dist/cooldown-clear.js +0 -6
  46. package/dist/cooldown-clear.js.map +1 -1
  47. package/dist/credential-fleet.js +0 -5
  48. package/dist/credential-fleet.js.map +1 -1
  49. package/dist/credential-select.js +4 -30
  50. package/dist/credential-select.js.map +1 -1
  51. package/dist/dashboard-auth.js +0 -29
  52. package/dist/dashboard-auth.js.map +1 -1
  53. package/dist/dashboard-contract.js +0 -46
  54. package/dist/dashboard-contract.js.map +1 -1
  55. package/dist/dashboard-routes.js +0 -32
  56. package/dist/dashboard-routes.js.map +1 -1
  57. package/dist/dashboard-snapshot.js +0 -154
  58. package/dist/dashboard-snapshot.js.map +1 -1
  59. package/dist/dashboard-static.js +0 -22
  60. package/dist/dashboard-static.js.map +1 -1
  61. package/dist/delegate-gate/cast-necessity.js +1 -22
  62. package/dist/delegate-gate/cast-necessity.js.map +1 -1
  63. package/dist/delegate-gate/cli.js +0 -6
  64. package/dist/delegate-gate/cli.js.map +1 -1
  65. package/dist/delegate-gate/diff-parser.js +0 -32
  66. package/dist/delegate-gate/diff-parser.js.map +1 -1
  67. package/dist/delegate-gate/fix.js +0 -10
  68. package/dist/delegate-gate/fix.js.map +1 -1
  69. package/dist/delegate-gate/gate.js +0 -12
  70. package/dist/delegate-gate/gate.js.map +1 -1
  71. package/dist/delegate-gate/minimality.js +0 -38
  72. package/dist/delegate-gate/minimality.js.map +1 -1
  73. package/dist/delegate-gate/post-image.js +1 -13
  74. package/dist/delegate-gate/post-image.js.map +1 -1
  75. package/dist/delegate-gate/shared-state.js +0 -23
  76. package/dist/delegate-gate/shared-state.js.map +1 -1
  77. package/dist/delegate-gate/test-assertions.js +1 -54
  78. package/dist/delegate-gate/test-assertions.js.map +1 -1
  79. package/dist/delegate-gate/types.js +0 -11
  80. package/dist/delegate-gate/types.js.map +1 -1
  81. package/dist/dialect-stream.js +9 -37
  82. package/dist/dialect-stream.js.map +1 -1
  83. package/dist/dispatch-exhaustion-persistence.js +0 -35
  84. package/dist/dispatch-exhaustion-persistence.js.map +1 -1
  85. package/dist/dispatch.js +0 -269
  86. package/dist/dispatch.js.map +1 -1
  87. package/dist/documents.js +0 -92
  88. package/dist/documents.js.map +1 -1
  89. package/dist/dotenv.js +0 -22
  90. package/dist/dotenv.js.map +1 -1
  91. package/dist/dynamic-pools.js +0 -93
  92. package/dist/dynamic-pools.js.map +1 -1
  93. package/dist/emitSse.js +0 -64
  94. package/dist/emitSse.js.map +1 -1
  95. package/dist/executable-lookup.d.ts +28 -0
  96. package/dist/executable-lookup.js +42 -0
  97. package/dist/executable-lookup.js.map +1 -0
  98. package/dist/hard-cap.js +1 -32
  99. package/dist/hard-cap.js.map +1 -1
  100. package/dist/host-routing.js +0 -40
  101. package/dist/host-routing.js.map +1 -1
  102. package/dist/installed-hosts.d.ts +64 -0
  103. package/dist/installed-hosts.js +75 -0
  104. package/dist/installed-hosts.js.map +1 -0
  105. package/dist/json-shape.js +0 -19
  106. package/dist/json-shape.js.map +1 -1
  107. package/dist/kernel/contracts.js +0 -26
  108. package/dist/kernel/contracts.js.map +1 -1
  109. package/dist/kernel/request-lifecycle.js +0 -4
  110. package/dist/kernel/request-lifecycle.js.map +1 -1
  111. package/dist/key-checker.js +0 -115
  112. package/dist/key-checker.js.map +1 -1
  113. package/dist/key-import.js +0 -20
  114. package/dist/key-import.js.map +1 -1
  115. package/dist/keys-cli.js +0 -15
  116. package/dist/keys-cli.js.map +1 -1
  117. package/dist/keystore.js +2 -51
  118. package/dist/keystore.js.map +1 -1
  119. package/dist/lane-cadence.js +1 -51
  120. package/dist/lane-cadence.js.map +1 -1
  121. package/dist/lane-manifest.js +0 -54
  122. package/dist/lane-manifest.js.map +1 -1
  123. package/dist/lane-probe.js +0 -36
  124. package/dist/lane-probe.js.map +1 -1
  125. package/dist/lane-quota-probe.js +0 -61
  126. package/dist/lane-quota-probe.js.map +1 -1
  127. package/dist/log.js +0 -17
  128. package/dist/log.js.map +1 -1
  129. package/dist/mcp/lane-runner.d.ts +114 -0
  130. package/dist/mcp/lane-runner.js +186 -0
  131. package/dist/mcp/lane-runner.js.map +1 -0
  132. package/dist/mcp/protocol.d.ts +98 -0
  133. package/dist/mcp/protocol.js +67 -0
  134. package/dist/mcp/protocol.js.map +1 -0
  135. package/dist/mcp/server.d.ts +78 -0
  136. package/dist/mcp/server.js +360 -0
  137. package/dist/mcp/server.js.map +1 -0
  138. package/dist/metadata.js +0 -73
  139. package/dist/metadata.js.map +1 -1
  140. package/dist/network-block.js +0 -45
  141. package/dist/network-block.js.map +1 -1
  142. package/dist/offload.js +0 -21
  143. package/dist/offload.js.map +1 -1
  144. package/dist/onboarding.js +0 -36
  145. package/dist/onboarding.js.map +1 -1
  146. package/dist/openai-dialect.js +0 -32
  147. package/dist/openai-dialect.js.map +1 -1
  148. package/dist/openai-request.js +0 -236
  149. package/dist/openai-request.js.map +1 -1
  150. package/dist/os-keyring.d.ts +11 -2
  151. package/dist/os-keyring.js +3 -39
  152. package/dist/os-keyring.js.map +1 -1
  153. package/dist/ping/cadence.js +3 -90
  154. package/dist/ping/cadence.js.map +1 -1
  155. package/dist/ping/metrics.js +0 -91
  156. package/dist/ping/metrics.js.map +1 -1
  157. package/dist/ping/ping.js +0 -17
  158. package/dist/ping/ping.js.map +1 -1
  159. package/dist/ping/probe-cache.js +2 -53
  160. package/dist/ping/probe-cache.js.map +1 -1
  161. package/dist/ping/quota.js +0 -17
  162. package/dist/ping/quota.js.map +1 -1
  163. package/dist/ping/runtime-telemetry.js +1 -18
  164. package/dist/ping/runtime-telemetry.js.map +1 -1
  165. package/dist/pool-health.js +0 -49
  166. package/dist/pool-health.js.map +1 -1
  167. package/dist/presets.js +0 -4
  168. package/dist/presets.js.map +1 -1
  169. package/dist/process-safety-net.js +0 -36
  170. package/dist/process-safety-net.js.map +1 -1
  171. package/dist/quota-demotion.js +1 -35
  172. package/dist/quota-demotion.js.map +1 -1
  173. package/dist/quota-observation.js +0 -21
  174. package/dist/quota-observation.js.map +1 -1
  175. package/dist/rate-limits.js +1 -94
  176. package/dist/rate-limits.js.map +1 -1
  177. package/dist/refusal-interpretation.js +2 -327
  178. package/dist/refusal-interpretation.js.map +1 -1
  179. package/dist/registry.js +0 -11
  180. package/dist/registry.js.map +1 -1
  181. package/dist/repair.js +1 -119
  182. package/dist/repair.js.map +1 -1
  183. package/dist/request-log.js +0 -2
  184. package/dist/request-log.js.map +1 -1
  185. package/dist/reshaper.js +0 -85
  186. package/dist/reshaper.js.map +1 -1
  187. package/dist/resolved-attempt.js +0 -3
  188. package/dist/resolved-attempt.js.map +1 -1
  189. package/dist/responses-request.js +0 -187
  190. package/dist/responses-request.js.map +1 -1
  191. package/dist/routes/admin.js +0 -38
  192. package/dist/routes/admin.js.map +1 -1
  193. package/dist/secret-file-acl.js +0 -26
  194. package/dist/secret-file-acl.js.map +1 -1
  195. package/dist/self-update.js +0 -118
  196. package/dist/self-update.js.map +1 -1
  197. package/dist/server.js +15 -952
  198. package/dist/server.js.map +1 -1
  199. package/dist/session-pin.js +0 -9
  200. package/dist/session-pin.js.map +1 -1
  201. package/dist/setup-claude.js +0 -9
  202. package/dist/setup-claude.js.map +1 -1
  203. package/dist/spend-headroom.js +0 -20
  204. package/dist/spend-headroom.js.map +1 -1
  205. package/dist/sse-frames.js +0 -31
  206. package/dist/sse-frames.js.map +1 -1
  207. package/dist/sse.js +1 -19
  208. package/dist/sse.js.map +1 -1
  209. package/dist/state-paths.js +0 -16
  210. package/dist/state-paths.js.map +1 -1
  211. package/dist/stream-commit.js +1 -27
  212. package/dist/stream-commit.js.map +1 -1
  213. package/dist/target-facts.js +2 -130
  214. package/dist/target-facts.js.map +1 -1
  215. package/dist/telemetry.js +0 -8
  216. package/dist/telemetry.js.map +1 -1
  217. package/dist/think-tags.js +1 -38
  218. package/dist/think-tags.js.map +1 -1
  219. package/dist/tier-data.js +0 -29
  220. package/dist/tier-data.js.map +1 -1
  221. package/dist/tool-dialects.js +1 -103
  222. package/dist/tool-dialects.js.map +1 -1
  223. package/dist/tool-use-ids.js +0 -51
  224. package/dist/tool-use-ids.js.map +1 -1
  225. package/dist/usage-observer.js +0 -52
  226. package/dist/usage-observer.js.map +1 -1
  227. package/dist/validator.js +1 -25
  228. package/dist/validator.js.map +1 -1
  229. package/dist/winenv.js +0 -63
  230. package/dist/winenv.js.map +1 -1
  231. package/dist/write-behind.js +0 -12
  232. package/dist/write-behind.js.map +1 -1
  233. package/package.json +2 -2
  234. package/scripts/install-skill.mjs +62 -9
  235. package/skills/llm-relay/SKILL.md +26 -1
@@ -1,95 +1,15 @@
1
1
  import { isRecord } from "./json-shape.js";
2
- /**
3
- * Anthropic Messages REQUEST → OpenAI Chat Completions REQUEST.
4
- *
5
- * Why this is relay-owned. Until 2026-08-23 `fetchBackend()` handed the whole conversation to
6
- * llm-bridge's `translateBetweenProviders("anthropic", "openai", …)`. Its `universalToOpenAI` has
7
- * no case for a `tool_call` or `tool_result` universal block, so every one of them fell through to
8
- * `JSON.stringify(<universal block>)` and became a `{type:"text"}` part of the OUTBOUND prompt —
9
- * the relay's own IR envelope (`{"_original":{"provider":"anthropic","raw":…},"tool_call":…}`)
10
- * written into the caller's conversation, 4–24 copies of it on a realistic agentic turn. Models
11
- * read the notation and echoed it back as their final answer, tool results were triplicated, the
12
- * prompt inflated ~3.1×, and `tool_calls` were emitted with no matching `role:"tool"` messages at
13
- * all. Diagnosis: docs/tool-call-dialect-leak.md §"Second mechanism".
14
- *
15
- * The rule this module exists to keep: **the body the relay sends is the caller's conversation,
16
- * never the relay's internals.** It is a deterministic wire-shape translation on the same side of
17
- * the repair boundary as `anthropicMessageToOpenAi` (its response-direction mirror in
18
- * `backend.ts`) — no model, no inference, no invented content. Anything it cannot represent is
19
- * REFUSED, following `documents.ts`: a mangled prompt reads as a working one, and stringifying a
20
- * block we do not understand is precisely the defect above.
21
- *
22
- * Scope is deliberate: exactly what Claude Code and Codex put on this front. `thinking` /
23
- * `redacted_thinking` are dropped (no OpenAI representation, and vendor-private reasoning is not
24
- * something to forward to a different vendor); `metadata` is dropped (llm-bridge dropped it too,
25
- * and `metadata.user_id` is a caller identifier that has never reached these providers); the
26
- * request-level `thinking` budget is dropped (mapping it to `reasoning_effort` would be a guess).
27
- */
28
2
  import { createHash } from "node:crypto";
29
- /**
30
- * A request shape this mapper will not put on the wire. The caller turns it into a clean 400,
31
- * exactly as `DocumentError` does — local origin, provider never asked.
32
- */
33
3
  export class RequestMappingError extends Error {
34
4
  constructor(message) {
35
5
  super(message);
36
6
  this.name = "RequestMappingError";
37
7
  }
38
8
  }
39
- /**
40
- * Google's documented opt-out token for a replayed tool call that carries no real thought
41
- * signature.
42
- *
43
- * FIRST-PARTY EVIDENCE (2026-08-23, `models/gemini-3.6-flash` via the OpenAI-compatible endpoint
44
- * at `generativelanguage.googleapis.com`): replaying an assistant `tool_calls` turn answers HTTP
45
- * 400 — "Function call is missing a thought_signature in functionCall parts…". Stamping this
46
- * string at `tool_calls[N].extra_content.google.thought_signature` was verified accepted on the
47
- * live endpoint the same day, for a single call and for BOTH entries of a parallel pair; the
48
- * model then answered correctly from the tool results. It is a RAW string and is never
49
- * base64-encoded — encoding it makes it an unparseable signature rather than the opt-out.
50
- *
51
- * WHY THE SENTINEL AND NOT THE REAL SIGNATURE. Echoing gemini's own signature back would need one
52
- * of two things this relay refuses to build:
53
- *
54
- * - a conversation store keyed by tool-call id, holding vendor-private reasoning between turns —
55
- * the reverse map `tool-use-ids.ts` deliberately does not have ("no reverse map, by
56
- * construction": the client echoes what it was given and the relay remembers nothing); or
57
- * - a fabricated `thinking` block smuggled back through the caller's conversation, which would
58
- * poison every anthropic-kind failover candidate with content the caller never wrote.
59
- *
60
- * Meanwhile this mapper DROPS `thinking` / `redacted_thinking` cross-vendor by rule (see
61
- * `assistantMessage` and `userMessages` below, and the module header's "mapping it to
62
- * `reasoning_effort` would be a guess" precedent), so no real signature is in hand to echo in the
63
- * first place. The sentinel is the vendor's OWN token for exactly this state — a labelled
64
- * parameter quirk, not an invented measurement — and it is config-overridable
65
- * (`compat.thoughtSignature`), which is the condition the "Provider knowledge is data" invariant
66
- * attaches to any provider fact living in `src/`.
67
- */
68
9
  const THOUGHT_SIGNATURE_SENTINEL = "skip_thought_signature_validator";
69
- /**
70
- * Mistral's stated tool-call-id shape.
71
- *
72
- * First-party evidence (2026-08-23, `mistral-medium-2505`): forwarding a caller-side id verbatim
73
- * answers HTTP 400
74
- * `{"object":"error","message":"Tool call id was toolu_01AAAAAAAAAAAAAAAAAAAAAA but must be a-z, A-Z, 0-9, with a length of 9.","type":"invalid_function_call","code":"3280"}`.
75
- * `mistral-common` enforces it on BOTH the assistant `tool_calls[].id` and the answering tool
76
- * message's `tool_call_id`, and from v13 also enforces linkage (a tool message must answer an id
77
- * a prior assistant turn actually called) and uniqueness. Every id shape that reaches this mapper
78
- * violates it: `toolu_01…` (Anthropic), `Read:0` (nim kimi-k3), `Read:0_relay1` (relay-minted),
79
- * `call_…` (Codex via the Responses front), `tu_recovered_0` (dialect rescue).
80
- */
81
10
  const STRICT9 = /^[a-zA-Z0-9]{9}$/;
82
11
  const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
83
12
  const sha256Digest = (input) => createHash("sha256").update(input, "utf8").digest();
84
- /**
85
- * A deterministic 9-char base62 id for one source id.
86
- *
87
- * SHA-256 of the UTF-8 id (plus `#<k>` on a collision retry), one base62 character per digest
88
- * byte. **No randomness** — the same precedent as `tool-use-ids.ts`: a conversation only ever
89
- * appends, so the same source id must map to the same outbound id on the next turn, on a retry,
90
- * and on every candidate of a pool walk. A random id would detach a `tool_result` from the call
91
- * it answers the moment the conversation was replayed.
92
- */
93
13
  function strict9(source, salt, digest) {
94
14
  const bytes = digest(salt === 0 ? source : `${source}#${salt}`);
95
15
  let out = "";
@@ -97,19 +17,6 @@ function strict9(source, salt, digest) {
97
17
  out += BASE62[bytes[i] % 62];
98
18
  return out;
99
19
  }
100
- /**
101
- * The one per-run source-id → outbound-id map, shared by `toolCall` and `toolResultMessage` so
102
- * both halves of a pair always land on the same value (mistral v13 checks that linkage).
103
- *
104
- * An id that already conforms is kept as-is, so a mistral-native id coming back through a later
105
- * turn round-trips unchanged. Collisions resolve deterministically by FIRST-APPEARANCE order:
106
- * the run is a single in-order walk of the conversation, so the same conversation always produces
107
- * the same assignment.
108
- *
109
- * ⚠ Exported ONLY so a test can hand it a colliding digest — see `ToolCallIdDigest`. Nothing
110
- * outside this module constructs one on the request path; `anthropicRequestToOpenAi` owns the
111
- * per-run instance and hands it to both halves of the pair itself.
112
- */
113
20
  export class ToolCallIds {
114
21
  digest;
115
22
  bySource = new Map();
@@ -123,9 +30,6 @@ export class ToolCallIds {
123
30
  if (existing !== undefined)
124
31
  return existing;
125
32
  let out;
126
- // A conforming id is kept — unless some earlier source already holds it, in which case
127
- // keeping it would map two different calls onto one id and break the uniqueness rule this
128
- // exists to satisfy. (62^-9; the branch is correctness, not a case anyone will meet.)
129
33
  if (STRICT9.test(id) && !this.taken.has(id))
130
34
  out = id;
131
35
  else {
@@ -143,22 +47,9 @@ export class ToolCallIds {
143
47
  return this.rewritten;
144
48
  }
145
49
  }
146
- /**
147
- * The per-run thought-signature stamper — `null` under `"none"`, which is every provider but
148
- * Google's Generative Language API.
149
- *
150
- * EVERY replayed tool call is stamped, not just the first of a turn. That is the placement the
151
- * 2026-08-23 live check verified: the sentinel on the single call of a one-call turn was accepted,
152
- * and the sentinel on BOTH entries of a parallel pair was accepted too (which contradicts a public
153
- * report that a parallel pair rejects it — against this endpoint and model, on that date, it did
154
- * not). Stamping every entry is also the only placement whose correctness does not depend on which
155
- * entry the validator happens to inspect.
156
- */
157
50
  class ThoughtSignatures {
158
51
  stamped = 0;
159
52
  stamp(call) {
160
- // A RAW string — never base64. Encoding it would make it a malformed signature instead of the
161
- // vendor's documented "there is no signature" token.
162
53
  call.extra_content = { google: { thought_signature: THOUGHT_SIGNATURE_SENTINEL } };
163
54
  this.stamped += 1;
164
55
  return call;
@@ -167,21 +58,12 @@ class ThoughtSignatures {
167
58
  return this.stamped;
168
59
  }
169
60
  }
170
- /** Name an unexpected block type in an error without echoing an arbitrary payload back. */
171
61
  function describeType(t) {
172
62
  return typeof t === "string" && t.length > 0 ? `"${t.slice(0, 40)}"` : "(missing type)";
173
63
  }
174
64
  function textOf(block) {
175
65
  return typeof block.text === "string" ? block.text : "";
176
66
  }
177
- /**
178
- * `system` (string or text blocks) → the leading `{role:"system"}` message.
179
- *
180
- * Blocks are joined with a blank line, not a space: they are independent documents (harness
181
- * preamble, project instructions, …) and llm-bridge's single space ran the last word of one into
182
- * the first word of the next. `cache_control` is dropped — OpenAI Chat has no equivalent, and a
183
- * prompt-cache hint is not content.
184
- */
185
67
  function systemText(system) {
186
68
  if (typeof system === "string")
187
69
  return system;
@@ -194,10 +76,7 @@ function systemText(system) {
194
76
  }
195
77
  return parts.join("\n\n");
196
78
  }
197
- /** One Anthropic `tool_use` block → one OpenAI `tool_calls[]` entry. */
198
79
  function toolCall(block, ids, sigs) {
199
- // A synthesized id would be unmatchable: the linkage to the `role:"tool"` message that answers
200
- // it is the id itself, so inventing one silently detaches the result from the call.
201
80
  if (typeof block.id !== "string" || block.id.length === 0) {
202
81
  throw new RequestMappingError("tool_use block without an id");
203
82
  }
@@ -206,28 +85,15 @@ function toolCall(block, ids, sigs) {
206
85
  }
207
86
  const input = block.input ?? {};
208
87
  const call = {
209
- // Under `"preserve"` (`ids === null`) this is the caller's own id, byte for byte.
210
88
  id: ids === null ? block.id : ids.map(block.id),
211
89
  type: "function",
212
90
  function: {
213
91
  name: block.name,
214
- // OpenAI carries arguments as a JSON STRING; a host-supplied string is already one.
215
92
  arguments: typeof input === "string" ? input : JSON.stringify(input),
216
93
  },
217
94
  };
218
- // Under `"none"` (`sigs === null`) NOTHING is added and this object is byte-identical to the one
219
- // this mapper emitted before the mode existed. See `THOUGHT_SIGNATURE_SENTINEL` for the 400 that
220
- // makes the other branch necessary and for why the vendor's opt-out token is the only honest
221
- // value the relay can put here.
222
95
  return sigs === null ? call : sigs.stamp(call);
223
96
  }
224
- /**
225
- * An assistant turn → exactly one OpenAI assistant message.
226
- *
227
- * Text blocks concatenate (the same rule as the response-direction `anthropicMessageToOpenAi`),
228
- * `tool_use` blocks become `tool_calls`, and `content` is `null` when nothing but tool calls
229
- * remains — the shape OpenAI defines for a tool-calling turn.
230
- */
231
97
  function assistantMessage(turn, ids, sigs) {
232
98
  const content = turn.content;
233
99
  if (typeof content === "string")
@@ -260,7 +126,6 @@ function assistantMessage(turn, ids, sigs) {
260
126
  message.tool_calls = toolCalls;
261
127
  return message;
262
128
  }
263
- /** An Anthropic `image` block → an OpenAI `image_url` part (base64 sources become data URLs). */
264
129
  function imagePart(block) {
265
130
  const source = isRecord(block.source) ? block.source : {};
266
131
  if (source.type === "url" && typeof source.url === "string") {
@@ -271,28 +136,6 @@ function imagePart(block) {
271
136
  }
272
137
  throw new RequestMappingError("image block needs a base64 or url source");
273
138
  }
274
- /**
275
- * Split one Anthropic `tool_result` into its tool-message text and its image parts.
276
- *
277
- * ⚠ An OpenAI `role:"tool"` message is TEXT ONLY — the Chat Completions schema gives it a
278
- * required string `content` and defines no image part — so a result carrying a screenshot or an
279
- * image file read (exactly what Claude Code's `Read` produces for an image) has no
280
- * representation there. Refusing it was worse than the gap: a `RequestMappingError` is a LOCAL
281
- * 400, which `server.ts` does not fail over, so one image killed the whole request on every
282
- * `openai`-kind lane.
283
- *
284
- * It is carried LOSSLESSLY instead. The text stays on the tool message; the image is emitted as
285
- * an `image_url` part on the `{role:"user"}` message that follows this turn's tool messages —
286
- * the closest faithful representation OpenAI Chat has: the content is the caller's own, it is
287
- * attached to the same turn, it invents nothing, and a host with no vision answers with its own
288
- * UPSTREAM 400, which DOES fail over to a candidate that can read it.
289
- *
290
- * A block with no representation ANYWHERE is still refused — stringifying a block we do not
291
- * understand is the defect this module exists to undo.
292
- *
293
- * Text blocks are joined with a newline — separate result blocks are separate records, not one
294
- * continuous sentence.
295
- */
296
139
  function toolResultParts(content) {
297
140
  if (content === undefined || content === null)
298
141
  return { text: "", images: [] };
@@ -319,57 +162,18 @@ function toolResultParts(content) {
319
162
  }
320
163
  return { text: texts.join("\n"), images };
321
164
  }
322
- /**
323
- * One Anthropic `tool_result` block → one OpenAI `{role:"tool"}` message, plus the image parts
324
- * that message cannot carry (see `toolResultParts`).
325
- *
326
- * `is_error` is passed through as plain text with NO relay-authored prefix. OpenAI has no error
327
- * flag on a tool message, and the two honest options are to drop the flag or to write words into
328
- * the prompt; a failing tool's own output already says it failed, so the conversation stays the
329
- * caller's. Recorded as a decision, not an oversight.
330
- *
331
- * An empty result yields `content: ""`. That is what the schema asks for — a tool message's
332
- * `content` is a required string, and the empty one is valid — and a relay-authored placeholder
333
- * ("(no output)") would again be words the caller never wrote. The mirror mapper's
334
- * `content: text || null` is the ASSISTANT shape, where OpenAI defines null; a tool message has
335
- * no such spelling.
336
- */
337
165
  function toolResultMessage(block, toolNames, ids) {
338
166
  if (typeof block.tool_use_id !== "string" || block.tool_use_id.length === 0) {
339
167
  throw new RequestMappingError("tool_result block without a tool_use_id");
340
168
  }
341
169
  const { text, images } = toolResultParts(block.content);
342
- // The SAME map the assistant turn used, so the pair still points at itself — mistral's v13
343
- // validator rejects a tool message whose id no prior `tool_calls` entry carries.
344
170
  const toolCallId = ids === null ? block.tool_use_id : ids.map(block.tool_use_id);
345
171
  const message = { role: "tool", tool_call_id: toolCallId, content: text };
346
- // Gemini's OpenAI-compatible layer folds a tool message into a `functionResponse` part whose
347
- // `name` is REQUIRED and is never resolved from the preceding `tool_calls`, so a nameless tool
348
- // message is a 400 there ("function_response.name: name cannot be empty"). The name here is the
349
- // caller's OWN tool name, looked up from the assistant `tool_use` whose id this result answers
350
- // (the conversation is walked in order, so the call has always been seen) — re-stated where
351
- // another vendor needs it, not invented: an orphan result (no matching tool_use, e.g. its call
352
- // sat in a dropped block) carries NO `name`.
353
- // ⚠ Keyed by the ORIGINAL id: the name table is built from the caller's conversation, which the
354
- // id rewrite deliberately does not touch.
355
172
  const name = toolNames?.get(block.tool_use_id);
356
173
  if (name !== undefined)
357
174
  message.name = name;
358
175
  return { message, images };
359
176
  }
360
- /**
361
- * A user turn → its `role:"tool"` messages (one per `tool_result`, in order) followed by at most
362
- * one `role:"user"` message carrying everything else.
363
- *
364
- * The tool messages lead regardless of where the blocks sat in the array: OpenAI requires every
365
- * `tool_call_id` from the preceding assistant turn to be answered directly, and a user message
366
- * wedged between them is rejected by strict providers. Relative order within each group is
367
- * preserved, and the turn is never merged into a neighbour.
368
- *
369
- * That trailing user message is also where a `tool_result`'s IMAGES land — an OpenAI tool
370
- * message cannot carry one, so the image rides on the user turn that follows it, keeping its
371
- * position relative to the turn's other leftover blocks (`toolResultParts`).
372
- */
373
177
  function userMessages(turn, toolNames, ids) {
374
178
  const content = turn.content;
375
179
  if (typeof content === "string")
@@ -389,8 +193,6 @@ function userMessages(turn, toolNames, ids) {
389
193
  case "tool_result": {
390
194
  const { message, images } = toolResultMessage(raw, toolNames, ids);
391
195
  toolMessages.push(message);
392
- // Appended HERE, not collected separately, so a result's images keep their place among
393
- // the turn's other leftover blocks.
394
196
  parts.push(...images);
395
197
  break;
396
198
  }
@@ -402,18 +204,14 @@ function userMessages(turn, toolNames, ids) {
402
204
  }
403
205
  }
404
206
  const out = [...toolMessages];
405
- // A text-only turn keeps the plain-string form llm-bridge produced: it is what every
406
- // OpenAI-compatible host accepts, and multimodal parts are the exception, not the rule.
407
207
  if (parts.length === 1 && parts[0].type === "text")
408
208
  out.push({ role: "user", content: parts[0].text });
409
209
  else if (parts.length > 0)
410
210
  out.push({ role: "user", content: parts });
411
- // A turn that produced nothing at all still occupies a position in the conversation.
412
211
  else if (toolMessages.length === 0)
413
212
  out.push({ role: "user", content: "" });
414
213
  return out;
415
214
  }
416
- /** `tools[]` → OpenAI function declarations. */
417
215
  function mapTools(tools) {
418
216
  if (!Array.isArray(tools) || tools.length === 0)
419
217
  return null;
@@ -422,26 +220,16 @@ function mapTools(tools) {
422
220
  if (!isRecord(raw))
423
221
  throw new RequestMappingError("tool declaration is not an object");
424
222
  if (typeof raw.name !== "string" || raw.name.length === 0) {
425
- // Dropping it would leave the model unable to call a tool the harness granted, and the
426
- // failure would surface as an unexplained refusal several turns later.
427
223
  throw new RequestMappingError("tool declaration without a name");
428
224
  }
429
225
  const fn = { name: raw.name };
430
226
  if (typeof raw.description === "string" && raw.description.length > 0)
431
227
  fn.description = raw.description;
432
- // Anthropic's built-in typed tools (`bash`, `text_editor`, …) declare no schema. An empty
433
- // object is not valid JSON Schema for every host, so the empty OBJECT schema is used —
434
- // "this tool takes no declared parameters", which is what the declaration means.
435
228
  fn.parameters = isRecord(raw.input_schema) ? raw.input_schema : { type: "object", properties: {} };
436
229
  out.push({ type: "function", function: fn });
437
230
  }
438
231
  return out;
439
232
  }
440
- /**
441
- * `tool_choice` → the OpenAI spelling. Anthropic's `any` ("call SOME tool") is OpenAI's
442
- * `required`; a named tool becomes the function form. An unrecognised shape is dropped rather
443
- * than guessed at — the host's default is `auto`, which is what llm-bridge left it at anyway.
444
- */
445
233
  function mapToolChoice(choice) {
446
234
  if (choice === "auto" || choice === "none" || choice === "required")
447
235
  return choice;
@@ -462,33 +250,17 @@ function mapToolChoice(choice) {
462
250
  return undefined;
463
251
  }
464
252
  }
465
- /** `stop_sequences` → `stop`, unchanged and uncapped: silently dropping one changes what the model may emit. */
466
253
  function stopSequences(raw) {
467
254
  if (!Array.isArray(raw))
468
255
  return null;
469
256
  const out = raw.filter((s) => typeof s === "string");
470
257
  return out.length > 0 ? out : null;
471
258
  }
472
- /**
473
- * Translate one Anthropic Messages request body into an OpenAI Chat Completions request body.
474
- *
475
- * Turn order is preserved exactly; no turn is merged or dropped. Unknown top-level fields are not
476
- * forwarded — this is a translation between two contracts, not a passthrough.
477
- *
478
- * @throws {RequestMappingError} for a block or declaration that cannot be represented.
479
- */
480
259
  export function anthropicRequestToOpenAi(reqJson, opts = {}) {
481
260
  const body = isRecord(reqJson) ? reqJson : {};
482
261
  const messages = [];
483
- // `null` is the "preserve" mode, and it is the mode for every provider but mistral: no map is
484
- // built and every id reaches the wire exactly as the caller wrote it.
485
262
  const ids = opts.toolCallIds === "strict9" ? new ToolCallIds() : null;
486
- // Same shape, and independent of it — a provider may set both keys, and the two passes touch
487
- // different parts of the same `tool_calls[]` entry (its `id`, and a sibling `extra_content`).
488
263
  const sigs = opts.thoughtSignature === "sentinel" ? new ThoughtSignatures() : null;
489
- // Assistant `tool_use` id → name across the whole conversation, so each `role:"tool"` message
490
- // can restate the name of the call it answers (see `toolResultMessage` — a gemini compat-layer
491
- // requirement). Filled lazily on first `tool_use`; a no-tool request keeps `undefined`.
492
264
  let toolNames;
493
265
  const rememberToolNames = (turn) => {
494
266
  if (!Array.isArray(turn.content))
@@ -508,8 +280,6 @@ export function anthropicRequestToOpenAi(reqJson, opts = {}) {
508
280
  for (const raw of Array.isArray(body.messages) ? body.messages : []) {
509
281
  if (!isRecord(raw))
510
282
  throw new RequestMappingError("message is not an object");
511
- // Walked in order, so a `tool_result` is always emitted after its `tool_use` was recorded —
512
- // and id minting (`tool-use-ids.ts`) is RESPONSE-side, so the echoed pair shares one id here.
513
283
  if (raw.role === "assistant") {
514
284
  rememberToolNames(raw);
515
285
  messages.push(assistantMessage(raw, ids, sigs));
@@ -517,16 +287,11 @@ export function anthropicRequestToOpenAi(reqJson, opts = {}) {
517
287
  else
518
288
  messages.push(...userMessages(raw, toolNames, ids));
519
289
  }
520
- // Announced for the same reason every other automatic fix on this path is: a count, never an id.
521
290
  if (ids !== null)
522
291
  opts.onToolCallIdsRewritten?.(ids.count());
523
- // Counted, not headered: the sentinel is vendor-protocol padding on the relay's own outbound
524
- // shape and alters nothing about the caller's data, so the operator gets a log counter rather
525
- // than a response header. A count, same rule.
526
292
  if (sigs !== null)
527
293
  opts.onThoughtSignatureSentinels?.(sigs.count());
528
294
  const out = { messages };
529
- // The relay's resolved deployment id, never the caller's — see `AnthropicToOpenAiOptions`.
530
295
  if (opts.model !== undefined)
531
296
  out.model = opts.model;
532
297
  const stream = opts.stream ?? (typeof body.stream === "boolean" ? body.stream : undefined);
@@ -544,7 +309,6 @@ export function anthropicRequestToOpenAi(reqJson, opts = {}) {
544
309
  const tools = mapTools(body.tools);
545
310
  if (tools) {
546
311
  out.tools = tools;
547
- // `tool_choice` without `tools` is rejected by strict hosts and means nothing anyway.
548
312
  const toolChoice = mapToolChoice(body.tool_choice);
549
313
  if (toolChoice !== undefined)
550
314
  out.tool_choice = toolChoice;
@@ -1 +1 @@
1
- {"version":3,"file":"openai-request.js","sourceRoot":"","sources":["../src/openai-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAgDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,0BAA0B,GAAG,kCAAkC,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,GAAG,kBAAkB,CAAC;AAEnC,MAAM,MAAM,GAAG,gEAAgE,CAAC;AAgBhF,MAAM,YAAY,GAAqB,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;AAEtG;;;;;;;;GAQG;AACH,SAAS,OAAO,CAAC,MAAc,EAAE,IAAY,EAAE,MAAwB;IACrE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI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AE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,KAAK,EAAE,CAAC;QACV,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;QAElB,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,UAAU,KAAK,SAAS;YAAE,GAAG,CAAC,WAAW,GAAG,UAAU,CAAC;IAC7D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { commandExistsOnPath } from "./executable-lookup.js";
1
2
  export type KekWrapMode = "dpapi" | "keychain" | "libsecret" | "passphrase";
2
3
  export type OsKekWrapMode = Exclude<KekWrapMode, "passphrase">;
3
4
  export interface ScryptKdfDescriptor {
@@ -60,8 +61,16 @@ export declare function keychainStoreArgv(): string[];
60
61
  export declare function keychainLoadArgv(keyId?: string): string[];
61
62
  export declare function libsecretStoreArgv(keyId?: string): string[];
62
63
  export declare function libsecretLoadArgv(keyId?: string): string[];
63
- /** PATH lookup used only to select Linux libsecret versus passphrase mode; it never spawns. */
64
- export declare function commandExistsOnPath(command: string, env?: NodeJS.ProcessEnv): boolean;
64
+ /**
65
+ * PATH lookup used only to select Linux libsecret versus passphrase mode; it never spawns.
66
+ *
67
+ * ⚠ The implementation moved to `executable-lookup.ts` when `installed-hosts.ts` needed the same
68
+ * question answered — two PATH walks would be the second implementation this project forbids, and
69
+ * the copy here had no PATHEXT handling. Behaviour on Linux, the only platform this caller runs
70
+ * on, is unchanged. Re-exported rather than relocated at the call sites so this module's public
71
+ * surface stays what it was.
72
+ */
73
+ export { commandExistsOnPath };
65
74
  /**
66
75
  * Wrap/store an existing random KEK in an OS facility.
67
76
  *
@@ -1,8 +1,8 @@
1
1
  import { randomBytes as nodeRandomBytes, scryptSync, timingSafeEqual } from "node:crypto";
2
2
  import { spawnSync as nodeSpawnSync } from "node:child_process";
3
- import { accessSync, constants as fsConstants } from "node:fs";
4
- import { delimiter, join, win32 } from "node:path";
3
+ import { win32 } from "node:path";
5
4
  import { windowsSystem32Executable } from "./secret-file-acl.js";
5
+ import { commandExistsOnPath } from "./executable-lookup.js";
6
6
  const KEK_BYTES = 32;
7
7
  const SCRYPT_SALT_BYTES = 32;
8
8
  const SCRYPT_MAXMEM = 64 * 1024 * 1024;
@@ -49,7 +49,6 @@ export class KeyringPassphraseRequiredError extends Error {
49
49
  this.name = "KeyringPassphraseRequiredError";
50
50
  }
51
51
  }
52
- /** Resolve Windows PowerShell 5.1 without consulting PATH. */
53
52
  export function windowsPowerShellPath(env = process.env) {
54
53
  const systemRoot = env.SystemRoot?.trim() || env.SYSTEMROOT?.trim() || "";
55
54
  return windowsSystem32Executable(win32.join("WindowsPowerShell", "v1.0", "powershell.exe"), systemRoot);
@@ -63,7 +62,6 @@ function keyringId(keyId) {
63
62
  function keyringPurpose(keyId) {
64
63
  return keyId === undefined ? "keystore-kek" : `keystore-kek:${keyringId(keyId)}`;
65
64
  }
66
- /** Pure argv builders. Secret material is deliberately not accepted as an argument. */
67
65
  export function dpapiWrapArgv() {
68
66
  return ["-NoProfile", "-NonInteractive", "-Command", DPAPI_WRAP_SCRIPT];
69
67
  }
@@ -96,27 +94,8 @@ export function libsecretStoreArgv(keyId) {
96
94
  export function libsecretLoadArgv(keyId) {
97
95
  return ["lookup", "application", "llm-relay", "purpose", keyringPurpose(keyId)];
98
96
  }
99
- /** PATH lookup used only to select Linux libsecret versus passphrase mode; it never spawns. */
100
- export function commandExistsOnPath(command, env = process.env) {
101
- const path = env.PATH;
102
- if (!path)
103
- return false;
104
- for (const directory of path.split(delimiter)) {
105
- if (!directory)
106
- continue;
107
- try {
108
- accessSync(join(directory, command), fsConstants.X_OK);
109
- return true;
110
- }
111
- catch {
112
- // Keep searching. Absence is the branch signal, not an exceptional condition.
113
- }
114
- }
115
- return false;
116
- }
97
+ export { commandExistsOnPath };
117
98
  const spawnCaptured = (command, args, options) => {
118
- // Unit tests must inject a captured-stdio seam. Never let an omitted double reach a real
119
- // OS credential store (most critically, a macOS Keychain write).
120
99
  if (process.env.VITEST !== undefined)
121
100
  throw new KeyringUnavailableError();
122
101
  return nodeSpawnSync(command, args, options);
@@ -125,7 +104,6 @@ function keyringFailure(operation, classification) {
125
104
  return new Error(`keyring ${operation} failed: ${classification}`);
126
105
  }
127
106
  function capturedOutput(value) {
128
- // A real spawnSync Buffer becomes caller-owned so its KEK bytes can be zeroized directly.
129
107
  if (Buffer.isBuffer(value))
130
108
  return value;
131
109
  if (value instanceof Uint8Array)
@@ -154,7 +132,6 @@ function runCaptured(operation, command, args, input, spawn) {
154
132
  catch (error) {
155
133
  if (error instanceof KeyringUnavailableError)
156
134
  throw new KeyringUnavailableError();
157
- // Never retain a child error as cause: child messages commonly contain argv and stdio.
158
135
  throw keyringFailure(operation, "launch");
159
136
  }
160
137
  let childError;
@@ -210,7 +187,6 @@ function encodeBase64Bytes(value) {
210
187
  return output;
211
188
  }
212
189
  function encodeSecretForLineInput(kek) {
213
- // secret-tool reads until EOF; no newline is included in the stored secret.
214
190
  return encodeBase64Bytes(kek);
215
191
  }
216
192
  function encodeKeychainStoreInput(kek, keyId) {
@@ -295,12 +271,6 @@ function selectMode(options) {
295
271
  }
296
272
  throw new KeyringUnavailableError();
297
273
  }
298
- /**
299
- * Wrap/store an existing random KEK in an OS facility.
300
- *
301
- * Passphrase mode is intentionally absent: its exact v1 format has only KDF parameters and no
302
- * encrypted blob, so `createPassphraseKek` derives the KEK instead of pretending to wrap one.
303
- */
304
274
  export function wrapKek(kek, options = {}) {
305
275
  validateKek(kek);
306
276
  const mode = options.mode ?? selectMode(options);
@@ -314,8 +284,6 @@ export function wrapKek(kek, options = {}) {
314
284
  return { wrap: "dpapi", blob: output.toString("base64") };
315
285
  }
316
286
  if (mode === "keychain") {
317
- // SecurityTool's direct add form requires `-w <password>` in the child argv. Interactive mode
318
- // parses the same bounded command from stdin, keeping the base64 KEK out of the process table.
319
287
  const input = encodeKeychainStoreInput(kek, options.keyId);
320
288
  try {
321
289
  const output = runCaptured("wrap", "security", keychainStoreArgv(), input, spawn);
@@ -342,7 +310,6 @@ function validKdf(kdf) {
342
310
  && kdf.p === 1
343
311
  && decodeCanonicalBase64(kdf.salt)?.length === SCRYPT_SALT_BYTES;
344
312
  }
345
- /** Derive one 256-bit KEK without changing caller-owned passphrase bytes. */
346
313
  export function derivePassphraseKek(passphrase, kdf) {
347
314
  if (!isNonEmptyPassphrase(passphrase) || !validKdf(kdf)) {
348
315
  throw keyringFailure("unwrap", "kdf");
@@ -382,7 +349,6 @@ export function createPassphraseKek(passphrase, options = {}) {
382
349
  salt.fill(0);
383
350
  }
384
351
  }
385
- /** Create a KEK using the selected platform custody mechanism. */
386
352
  export function createKek(options = {}) {
387
353
  const mode = selectMode(options);
388
354
  if (mode === "passphrase") {
@@ -418,7 +384,6 @@ export function createKek(options = {}) {
418
384
  throw error;
419
385
  }
420
386
  }
421
- /** Lazily recover a KEK. The returned Buffer is owned by the caller. */
422
387
  export function unwrapKek(descriptor, options = {}) {
423
388
  const spawn = options.spawnSync ?? spawnCaptured;
424
389
  if (descriptor.wrap === "dpapi") {
@@ -469,7 +434,6 @@ export function unwrapKek(descriptor, options = {}) {
469
434
  }
470
435
  throw keyringFailure("unwrap", "descriptor");
471
436
  }
472
- /** Constant-time helper for tests and callers that verify a passphrase-derived round trip. */
473
437
  export function sameKek(left, right) {
474
438
  return left.length === right.length && timingSafeEqual(left, right);
475
439
  }