@mupt-ai/dari-gateway 0.2.0 → 0.3.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 (385) hide show
  1. package/README.md +8 -4
  2. package/dist/bun.d.ts +2 -0
  3. package/dist/bun.js +4 -0
  4. package/dist/context/eval_catalog.d.ts +3 -0
  5. package/dist/context/eval_catalog.js +7 -0
  6. package/dist/context/interaction_fingerprint.d.ts +27 -0
  7. package/dist/context/interaction_fingerprint.js +519 -0
  8. package/dist/context/interaction_fingerprint_format.d.ts +42 -0
  9. package/dist/context/interaction_fingerprint_format.js +113 -0
  10. package/dist/context/interaction_lease_depth.d.ts +2 -0
  11. package/dist/context/interaction_lease_depth.js +110 -0
  12. package/dist/context/lease_history.d.ts +7 -0
  13. package/dist/context/lease_history.js +158 -0
  14. package/dist/context/pricing.d.ts +4 -0
  15. package/dist/context/pricing.js +27 -0
  16. package/dist/context/provider_prompt_accounting.d.ts +14 -0
  17. package/dist/context/provider_prompt_accounting.js +187 -0
  18. package/dist/context/routing_context.d.ts +40 -0
  19. package/dist/context/routing_context.js +211 -0
  20. package/dist/http/auth.d.ts +2 -0
  21. package/dist/http/auth.js +35 -0
  22. package/dist/http/errors.d.ts +19 -0
  23. package/dist/http/errors.js +89 -0
  24. package/dist/http/handler.d.ts +12 -0
  25. package/dist/http/handler.js +88 -0
  26. package/dist/http/http2_server.d.ts +6 -0
  27. package/dist/http/http2_server.js +103 -0
  28. package/dist/http/serve.d.ts +20 -0
  29. package/dist/http/serve.js +78 -0
  30. package/dist/index.d.ts +7 -0
  31. package/dist/index.js +9 -0
  32. package/dist/ingress/anthropic_messages.d.ts +3 -0
  33. package/dist/ingress/anthropic_messages.js +122 -0
  34. package/dist/ingress/anthropic_models.d.ts +1 -0
  35. package/dist/ingress/anthropic_models.js +23 -0
  36. package/dist/ingress/chat_completions.d.ts +2 -0
  37. package/dist/ingress/chat_completions.js +44 -0
  38. package/dist/ingress/claude_code/request_context.d.ts +2 -0
  39. package/dist/ingress/claude_code/request_context.js +31 -0
  40. package/dist/ingress/codex.d.ts +3 -0
  41. package/dist/ingress/codex.js +69 -0
  42. package/dist/ingress/codex_models.d.ts +2 -0
  43. package/dist/ingress/codex_models.js +89 -0
  44. package/dist/ingress/json.d.ts +1 -0
  45. package/dist/ingress/json.js +95 -0
  46. package/dist/ingress/models.d.ts +1 -0
  47. package/dist/ingress/models.js +65 -0
  48. package/dist/ingress/muse_code.d.ts +2 -0
  49. package/dist/ingress/muse_code.js +8 -0
  50. package/dist/ingress/muse_models.d.ts +9 -0
  51. package/dist/ingress/muse_models.js +32 -0
  52. package/dist/interaction/capabilities.d.ts +3 -0
  53. package/dist/interaction/capabilities.js +24 -0
  54. package/dist/interaction/image.d.ts +4 -0
  55. package/dist/interaction/image.js +13 -0
  56. package/dist/interaction/portable_reasoning_state.d.ts +4 -0
  57. package/dist/interaction/portable_reasoning_state.js +18 -0
  58. package/dist/interaction/provider_continuation_state.d.ts +6 -0
  59. package/dist/interaction/provider_continuation_state.js +27 -0
  60. package/dist/interaction/tool_identity.d.ts +10 -0
  61. package/dist/interaction/tool_identity.js +41 -0
  62. package/dist/interaction/types.d.ts +204 -0
  63. package/dist/interaction/types.js +5 -0
  64. package/dist/models/catalog.d.ts +35 -0
  65. package/dist/models/catalog.js +232 -0
  66. package/dist/models/context_limits.d.ts +2 -0
  67. package/dist/models/context_limits.js +7 -0
  68. package/dist/models/execution_provider.d.ts +9 -0
  69. package/dist/models/execution_provider.js +17 -0
  70. package/dist/models/gateways.d.ts +11 -0
  71. package/dist/models/gateways.js +45 -0
  72. package/dist/models/ids.d.ts +1 -0
  73. package/dist/models/ids.js +15 -0
  74. package/dist/models/provider_defaults.d.ts +4 -0
  75. package/dist/models/provider_defaults.js +44 -0
  76. package/dist/models/runtime_overrides.d.ts +7 -0
  77. package/dist/models/runtime_overrides.js +226 -0
  78. package/dist/models/subscriptions.d.ts +8 -0
  79. package/dist/models/subscriptions.js +37 -0
  80. package/dist/observability/errors.d.ts +8 -0
  81. package/dist/observability/errors.js +11 -0
  82. package/dist/platform/platform.d.ts +156 -0
  83. package/dist/platform/platform.js +11 -0
  84. package/dist/platform/routing_contract.d.ts +2 -0
  85. package/dist/platform/routing_contract.js +5 -0
  86. package/dist/protocol/input/anthropic_messages.d.ts +2 -0
  87. package/dist/protocol/input/anthropic_messages.js +494 -0
  88. package/dist/protocol/input/chat_completions.d.ts +4 -0
  89. package/dist/protocol/input/chat_completions.js +214 -0
  90. package/dist/protocol/input/chat_completions_validation.d.ts +2 -0
  91. package/dist/protocol/input/chat_completions_validation.js +258 -0
  92. package/dist/protocol/input/openai_responses.d.ts +2 -0
  93. package/dist/protocol/input/openai_responses.js +666 -0
  94. package/dist/protocol/input/router_model.d.ts +7 -0
  95. package/dist/protocol/input/router_model.js +43 -0
  96. package/dist/protocol/output/anthropic_messages.d.ts +10 -0
  97. package/dist/protocol/output/anthropic_messages.js +15 -0
  98. package/dist/protocol/output/anthropic_messages_output.d.ts +10 -0
  99. package/dist/protocol/output/anthropic_messages_output.js +124 -0
  100. package/dist/protocol/output/anthropic_messages_stream.d.ts +16 -0
  101. package/dist/protocol/output/anthropic_messages_stream.js +267 -0
  102. package/dist/protocol/output/chat_completions.d.ts +29 -0
  103. package/dist/protocol/output/chat_completions.js +406 -0
  104. package/dist/protocol/output/chat_reasoning_detail.d.ts +2 -0
  105. package/dist/protocol/output/chat_reasoning_detail.js +13 -0
  106. package/dist/protocol/output/delivered_stream_snapshot.d.ts +10 -0
  107. package/dist/protocol/output/delivered_stream_snapshot.js +31 -0
  108. package/dist/protocol/output/openai_responses.d.ts +10 -0
  109. package/dist/protocol/output/openai_responses.js +14 -0
  110. package/dist/protocol/output/openai_responses_output.d.ts +14 -0
  111. package/dist/protocol/output/openai_responses_output.js +125 -0
  112. package/dist/protocol/output/openai_responses_stream.d.ts +18 -0
  113. package/dist/protocol/output/openai_responses_stream.js +546 -0
  114. package/dist/protocol/output/sse_stream.d.ts +31 -0
  115. package/dist/protocol/output/sse_stream.js +67 -0
  116. package/dist/providers/anthropic_safeguards.d.ts +11 -0
  117. package/dist/providers/anthropic_safeguards.js +81 -0
  118. package/dist/providers/aws_assume_role.d.ts +17 -0
  119. package/dist/providers/aws_assume_role.js +107 -0
  120. package/dist/providers/cancel_estimate.d.ts +43 -0
  121. package/dist/providers/cancel_estimate.js +89 -0
  122. package/dist/providers/execution.d.ts +72 -0
  123. package/dist/providers/execution.js +491 -0
  124. package/dist/providers/model_capabilities.d.ts +11 -0
  125. package/dist/providers/model_capabilities.js +29 -0
  126. package/dist/providers/pi.d.ts +65 -0
  127. package/dist/providers/pi.js +325 -0
  128. package/dist/providers/pi_context.d.ts +7 -0
  129. package/dist/providers/pi_context.js +405 -0
  130. package/dist/providers/pi_options.d.ts +11 -0
  131. package/dist/providers/pi_options.js +410 -0
  132. package/dist/providers/pi_output.d.ts +2 -0
  133. package/dist/providers/pi_output.js +453 -0
  134. package/dist/providers/provider_attempt_runner.d.ts +55 -0
  135. package/dist/providers/provider_attempt_runner.js +90 -0
  136. package/dist/providers/provider_call.d.ts +77 -0
  137. package/dist/providers/provider_call.js +296 -0
  138. package/dist/providers/provider_reported_cost.d.ts +10 -0
  139. package/dist/providers/provider_reported_cost.js +123 -0
  140. package/dist/providers/reasoning.d.ts +12 -0
  141. package/dist/providers/reasoning.js +30 -0
  142. package/dist/providers/response_capture.d.ts +23 -0
  143. package/dist/providers/response_capture.js +47 -0
  144. package/dist/providers/stream_finalization.d.ts +46 -0
  145. package/dist/providers/stream_finalization.js +165 -0
  146. package/dist/providers/subscription_limits.d.ts +33 -0
  147. package/dist/providers/subscription_limits.js +179 -0
  148. package/dist/providers/subscription_usage.d.ts +10 -0
  149. package/dist/providers/subscription_usage.js +79 -0
  150. package/dist/runtime/claude_code/auxiliary_routing.d.ts +3 -0
  151. package/dist/runtime/claude_code/auxiliary_routing.js +60 -0
  152. package/dist/runtime/customer_disconnect.d.ts +20 -0
  153. package/dist/runtime/customer_disconnect.js +49 -0
  154. package/dist/runtime/explicit_model.d.ts +7 -0
  155. package/dist/runtime/explicit_model.js +57 -0
  156. package/dist/runtime/harness_identity/conversation.d.ts +33 -0
  157. package/dist/runtime/harness_identity/conversation.js +39 -0
  158. package/dist/runtime/harness_identity/extract.d.ts +8 -0
  159. package/dist/runtime/harness_identity/extract.js +214 -0
  160. package/dist/runtime/harness_identity/index.d.ts +2 -0
  161. package/dist/runtime/harness_identity/index.js +2 -0
  162. package/dist/runtime/prepare_routed_completion.d.ts +33 -0
  163. package/dist/runtime/prepare_routed_completion.js +186 -0
  164. package/dist/runtime/provider_stream_lifecycle.d.ts +31 -0
  165. package/dist/runtime/provider_stream_lifecycle.js +88 -0
  166. package/dist/runtime/provider_stream_outcome.d.ts +23 -0
  167. package/dist/runtime/provider_stream_outcome.js +55 -0
  168. package/dist/runtime/request_tags.d.ts +7 -0
  169. package/dist/runtime/request_tags.js +33 -0
  170. package/dist/runtime/routed_completion.d.ts +17 -0
  171. package/dist/runtime/routed_completion.js +80 -0
  172. package/dist/runtime/routed_protocol.d.ts +30 -0
  173. package/dist/runtime/routed_protocol.js +1 -0
  174. package/dist/runtime/routed_runtime.d.ts +40 -0
  175. package/dist/runtime/routed_runtime.js +535 -0
  176. package/dist/runtime/routing_lease.d.ts +26 -0
  177. package/dist/runtime/routing_lease.js +210 -0
  178. package/dist/runtime/runtime_reporter.d.ts +71 -0
  179. package/dist/runtime/runtime_reporter.js +35 -0
  180. package/dist/runtime/strict_provider_access.d.ts +6 -0
  181. package/dist/runtime/strict_provider_access.js +40 -0
  182. package/dist/self_host/config.d.ts +46 -0
  183. package/dist/self_host/config.js +105 -0
  184. package/dist/self_host/main.d.ts +16 -0
  185. package/dist/self_host/main.js +95 -0
  186. package/dist/self_host/platform.d.ts +13 -0
  187. package/dist/self_host/platform.js +50 -0
  188. package/dist/self_host/prefix_store.d.ts +46 -0
  189. package/dist/self_host/prefix_store.js +261 -0
  190. package/dist/self_host/resolve.d.ts +28 -0
  191. package/dist/self_host/resolve.js +167 -0
  192. package/dist/self_host/subscriptions/access.d.ts +10 -0
  193. package/dist/self_host/subscriptions/access.js +37 -0
  194. package/dist/self_host/subscriptions/http.d.ts +15 -0
  195. package/dist/self_host/subscriptions/http.js +187 -0
  196. package/dist/self_host/subscriptions/index.d.ts +24 -0
  197. package/dist/self_host/subscriptions/index.js +24 -0
  198. package/dist/self_host/subscriptions/oauth.d.ts +59 -0
  199. package/dist/self_host/subscriptions/oauth.js +376 -0
  200. package/dist/self_host/subscriptions/store.d.ts +78 -0
  201. package/dist/self_host/subscriptions/store.js +236 -0
  202. package/dist/strategies/auto_routing_selector.d.ts +12 -0
  203. package/dist/strategies/auto_routing_selector.js +61 -0
  204. package/dist/strategies/eval_relevance.d.ts +17 -0
  205. package/dist/strategies/eval_relevance.js +32 -0
  206. package/dist/strategies/fallback_decision.d.ts +8 -0
  207. package/dist/strategies/fallback_decision.js +17 -0
  208. package/dist/strategies/priority_selector.d.ts +7 -0
  209. package/dist/strategies/priority_selector.js +37 -0
  210. package/dist/strategies/route_decision.d.ts +22 -0
  211. package/dist/strategies/route_decision.js +65 -0
  212. package/dist/strategies/routing.d.ts +74 -0
  213. package/dist/strategies/routing.js +280 -0
  214. package/dist/strategies/selector_projection.d.ts +15 -0
  215. package/dist/strategies/selector_projection.js +161 -0
  216. package/dist/telemetry/background.d.ts +7 -0
  217. package/dist/telemetry/background.js +33 -0
  218. package/dist/telemetry/benchmark_replay.d.ts +37 -0
  219. package/dist/telemetry/benchmark_replay.js +108 -0
  220. package/dist/telemetry/billing_finalization.d.ts +64 -0
  221. package/dist/telemetry/billing_finalization.js +96 -0
  222. package/dist/telemetry/ingest_values.d.ts +4 -0
  223. package/dist/telemetry/ingest_values.js +12 -0
  224. package/dist/telemetry/model_cost.d.ts +3 -0
  225. package/dist/telemetry/model_cost.js +15 -0
  226. package/dist/telemetry/prefix_state.d.ts +47 -0
  227. package/dist/telemetry/prefix_state.js +116 -0
  228. package/dist/telemetry/report.d.ts +88 -0
  229. package/dist/telemetry/report.js +621 -0
  230. package/dist/telemetry/requests/interaction_observability.d.ts +45 -0
  231. package/dist/telemetry/requests/interaction_observability.js +180 -0
  232. package/dist/telemetry/requests/retained_interaction_request.d.ts +8 -0
  233. package/dist/telemetry/requests/retained_interaction_request.js +10 -0
  234. package/dist/telemetry/scrub.d.ts +2 -0
  235. package/dist/telemetry/scrub.js +31 -0
  236. package/dist/telemetry/skills/claude/catalog.d.ts +6 -0
  237. package/dist/telemetry/skills/claude/catalog.js +99 -0
  238. package/dist/telemetry/skills/claude/file_reads.d.ts +4 -0
  239. package/dist/telemetry/skills/claude/file_reads.js +110 -0
  240. package/dist/telemetry/skills/claude/observations.d.ts +3 -0
  241. package/dist/telemetry/skills/claude/observations.js +366 -0
  242. package/dist/telemetry/skills/codex/catalog.d.ts +11 -0
  243. package/dist/telemetry/skills/codex/catalog.js +138 -0
  244. package/dist/telemetry/skills/codex/exec_file_reads.d.ts +9 -0
  245. package/dist/telemetry/skills/codex/exec_file_reads.js +36 -0
  246. package/dist/telemetry/skills/codex/explicit.d.ts +3 -0
  247. package/dist/telemetry/skills/codex/explicit.js +90 -0
  248. package/dist/telemetry/skills/codex/file_reads.d.ts +4 -0
  249. package/dist/telemetry/skills/codex/file_reads.js +37 -0
  250. package/dist/telemetry/skills/codex/identity.d.ts +2 -0
  251. package/dist/telemetry/skills/codex/identity.js +20 -0
  252. package/dist/telemetry/skills/observations.d.ts +21 -0
  253. package/dist/telemetry/skills/observations.js +41 -0
  254. package/dist/telemetry/skills/paths.d.ts +11 -0
  255. package/dist/telemetry/skills/paths.js +61 -0
  256. package/dist/telemetry/skills/pi.d.ts +6 -0
  257. package/dist/telemetry/skills/pi.js +223 -0
  258. package/dist/telemetry/skills/shell_file_reads.d.ts +7 -0
  259. package/dist/telemetry/skills/shell_file_reads.js +226 -0
  260. package/dist/telemetry/skills/shell_words.d.ts +13 -0
  261. package/dist/telemetry/skills/shell_words.js +189 -0
  262. package/dist/telemetry/tools/input.d.ts +2 -0
  263. package/dist/telemetry/tools/input.js +14 -0
  264. package/dist/telemetry/tools/observations.d.ts +29 -0
  265. package/dist/telemetry/tools/observations.js +247 -0
  266. package/dist/telemetry/usage.d.ts +57 -0
  267. package/dist/telemetry/usage.js +136 -0
  268. package/dist/types.d.ts +97 -0
  269. package/dist/types.js +1 -0
  270. package/package.json +22 -7
  271. package/src/bun.ts +2 -2
  272. package/src/context/eval_catalog.ts +1 -1
  273. package/src/context/interaction_fingerprint.ts +9 -9
  274. package/src/context/interaction_fingerprint_format.ts +1 -1
  275. package/src/context/interaction_lease_depth.ts +1 -1
  276. package/src/context/pricing.ts +6 -3
  277. package/src/context/provider_prompt_accounting.ts +5 -5
  278. package/src/context/routing_context.ts +16 -16
  279. package/src/http/auth.ts +1 -1
  280. package/src/http/handler.ts +15 -8
  281. package/src/http/serve.ts +3 -3
  282. package/src/index.ts +14 -6
  283. package/src/ingress/anthropic_messages.ts +12 -12
  284. package/src/ingress/anthropic_models.ts +1 -1
  285. package/src/ingress/chat_completions.ts +17 -10
  286. package/src/ingress/claude_code/request_context.ts +2 -2
  287. package/src/ingress/codex.ts +14 -10
  288. package/src/ingress/codex_models.ts +4 -4
  289. package/src/ingress/json.ts +1 -1
  290. package/src/ingress/models.ts +22 -10
  291. package/src/ingress/muse_code.ts +9 -0
  292. package/src/ingress/muse_models.ts +36 -0
  293. package/src/interaction/capabilities.ts +1 -1
  294. package/src/interaction/portable_reasoning_state.ts +1 -1
  295. package/src/interaction/provider_continuation_state.ts +1 -1
  296. package/src/interaction/tool_identity.ts +2 -2
  297. package/src/interaction/types.ts +2 -0
  298. package/src/models/catalog.ts +310 -0
  299. package/src/models/context_limits.ts +1 -1
  300. package/src/models/execution_provider.ts +5 -2
  301. package/src/models/ids.ts +1 -1
  302. package/src/models/provider_defaults.ts +4 -1
  303. package/src/models/runtime_overrides.ts +23 -1
  304. package/src/models/subscriptions.ts +54 -0
  305. package/src/observability/errors.ts +2 -2
  306. package/src/platform/platform.ts +9 -5
  307. package/src/protocol/input/anthropic_messages.ts +7 -7
  308. package/src/protocol/input/chat_completions.ts +8 -6
  309. package/src/protocol/input/chat_completions_validation.ts +6 -5
  310. package/src/protocol/input/openai_responses.ts +6 -6
  311. package/src/protocol/output/anthropic_messages.ts +3 -3
  312. package/src/protocol/output/anthropic_messages_output.ts +6 -4
  313. package/src/protocol/output/anthropic_messages_stream.ts +7 -7
  314. package/src/protocol/output/chat_completions.ts +13 -13
  315. package/src/protocol/output/chat_reasoning_detail.ts +1 -1
  316. package/src/protocol/output/openai_responses.ts +3 -3
  317. package/src/protocol/output/openai_responses_output.ts +4 -2
  318. package/src/protocol/output/openai_responses_stream.ts +6 -6
  319. package/src/protocol/output/sse_stream.ts +3 -3
  320. package/src/providers/anthropic_safeguards.ts +2 -2
  321. package/src/providers/aws_assume_role.ts +2 -2
  322. package/src/providers/cancel_estimate.ts +1 -1
  323. package/src/providers/execution.ts +17 -17
  324. package/src/providers/pi.ts +34 -19
  325. package/src/providers/pi_context.ts +6 -6
  326. package/src/providers/pi_options.ts +27 -11
  327. package/src/providers/pi_output.ts +5 -5
  328. package/src/providers/provider_attempt_runner.ts +1 -1
  329. package/src/providers/provider_call.ts +21 -17
  330. package/src/providers/provider_reported_cost.ts +3 -3
  331. package/src/providers/reasoning.ts +2 -2
  332. package/src/providers/stream_finalization.ts +9 -9
  333. package/src/providers/subscription_limits.ts +24 -7
  334. package/src/runtime/claude_code/auxiliary_routing.ts +5 -5
  335. package/src/runtime/customer_disconnect.ts +1 -1
  336. package/src/runtime/explicit_model.ts +19 -20
  337. package/src/runtime/harness_identity/conversation.ts +1 -1
  338. package/src/runtime/harness_identity/extract.ts +3 -3
  339. package/src/runtime/harness_identity/index.ts +2 -2
  340. package/src/runtime/prepare_routed_completion.ts +35 -16
  341. package/src/runtime/provider_stream_lifecycle.ts +1 -1
  342. package/src/runtime/provider_stream_outcome.ts +2 -2
  343. package/src/runtime/request_tags.ts +2 -2
  344. package/src/runtime/routed_completion.ts +11 -11
  345. package/src/runtime/routed_protocol.ts +2 -2
  346. package/src/runtime/routed_runtime.ts +20 -19
  347. package/src/runtime/routing_lease.ts +7 -7
  348. package/src/runtime/runtime_reporter.ts +3 -3
  349. package/src/runtime/strict_provider_access.ts +42 -0
  350. package/src/self_host/main.ts +12 -12
  351. package/src/self_host/platform.ts +5 -5
  352. package/src/self_host/prefix_store.ts +2 -2
  353. package/src/self_host/resolve.ts +17 -31
  354. package/src/self_host/subscriptions/access.ts +2 -2
  355. package/src/self_host/subscriptions/http.ts +2 -2
  356. package/src/self_host/subscriptions/index.ts +4 -4
  357. package/src/self_host/subscriptions/oauth.ts +139 -8
  358. package/src/self_host/subscriptions/store.ts +2 -1
  359. package/src/strategies/auto_routing_selector.ts +2 -2
  360. package/src/strategies/eval_relevance.ts +3 -3
  361. package/src/strategies/priority_selector.ts +1 -1
  362. package/src/strategies/route_decision.ts +7 -7
  363. package/src/strategies/routing.ts +10 -10
  364. package/src/strategies/selector_projection.ts +2 -2
  365. package/src/telemetry/billing_finalization.ts +3 -3
  366. package/src/telemetry/model_cost.ts +1 -1
  367. package/src/telemetry/prefix_state.ts +4 -4
  368. package/src/telemetry/report.ts +21 -21
  369. package/src/telemetry/requests/interaction_observability.ts +1 -1
  370. package/src/telemetry/requests/retained_interaction_request.ts +1 -1
  371. package/src/telemetry/skills/claude/catalog.ts +1 -1
  372. package/src/telemetry/skills/claude/file_reads.ts +6 -6
  373. package/src/telemetry/skills/claude/observations.ts +3 -3
  374. package/src/telemetry/skills/codex/catalog.ts +3 -3
  375. package/src/telemetry/skills/codex/exec_file_reads.ts +4 -4
  376. package/src/telemetry/skills/codex/explicit.ts +3 -3
  377. package/src/telemetry/skills/codex/file_reads.ts +5 -5
  378. package/src/telemetry/skills/observations.ts +7 -7
  379. package/src/telemetry/skills/pi.ts +3 -3
  380. package/src/telemetry/skills/shell_file_reads.ts +2 -2
  381. package/src/telemetry/skills/shell_words.ts +1 -1
  382. package/src/telemetry/tools/input.ts +1 -1
  383. package/src/telemetry/tools/observations.ts +9 -9
  384. package/src/telemetry/usage.ts +5 -5
  385. package/src/types.ts +20 -3
@@ -1,15 +1,15 @@
1
1
  import type { BedrockOptions } from "@mupt-ai/pi-ai/api/bedrock-converse-stream";
2
2
  import { isReasoningEffort, isRecord, type ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
3
- import type { InteractionRequest, InteractionResponseFormat, InteractionToolChoice } from "../interaction/types";
4
- import { requiredCapabilitiesFor } from "../interaction/capabilities";
5
- import { toolWireName, toolsByWireName } from "../interaction/tool_identity";
6
- import { gatewayFor, payloadWithGatewayFields } from "../models/gateways";
7
- import { offRequiresWireNone } from "../models/runtime_overrides";
8
- import { effectiveReasoningForModel, validateReasoningEffortForModel } from "./reasoning";
9
- import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities";
10
- import type { ResolvedProviderAuth } from "../types";
11
- import type { ProviderFetch } from "./response_capture";
12
- import { forwardsAnthropicSafeguards, payloadWithSafeguards } from "./anthropic_safeguards";
3
+ import type { InteractionRequest, InteractionResponseFormat, InteractionToolChoice } from "../interaction/types.js";
4
+ import { requiredCapabilitiesFor } from "../interaction/capabilities.js";
5
+ import { toolWireName, toolsByWireName } from "../interaction/tool_identity.js";
6
+ import { gatewayFor, payloadWithGatewayFields } from "../models/gateways.js";
7
+ import { offRequiresWireNone } from "../models/runtime_overrides.js";
8
+ import { effectiveReasoningForModel, validateReasoningEffortForModel } from "./reasoning.js";
9
+ import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities.js";
10
+ import type { ResolvedProviderAuth } from "../types.js";
11
+ import type { ProviderFetch } from "./response_capture.js";
12
+ import { forwardsAnthropicSafeguards, payloadWithSafeguards } from "./anthropic_safeguards.js";
13
13
 
14
14
  type PiOptionsSupport = {
15
15
  getSupportedThinkingLevels?: (model: Record<string, unknown>) => string[];
@@ -51,8 +51,10 @@ export function buildOptions(
51
51
  const providerAuth: ResolvedProviderAuth = typeof auth === "string" ? { type: "bearer", apiKey: auth } : auth;
52
52
  const { generation, toolChoice, parallelToolCalls, responseFormat } = request;
53
53
  const headers: Record<string, string> = {};
54
+ const bearerHeader = sendsBearerToMessages(providerAuth, model);
55
+ if (bearerHeader) headers.authorization = `Bearer ${providerAuth.apiKey}`;
54
56
  const options: Record<string, unknown> = {
55
- ...authenticationOptions(providerAuth, api),
57
+ ...(bearerHeader ? {} : authenticationOptions(providerAuth, api)),
56
58
  maxRetries: 0,
57
59
  timeoutMs,
58
60
  signal,
@@ -67,6 +69,9 @@ export function buildOptions(
67
69
  if (isClaudeCodeOAuth(providerAuth, api)) {
68
70
  headers["user-agent"] = request.claudeCodeUserAgent ?? CLAUDE_CODE_USER_AGENT;
69
71
  }
72
+ if (model.provider === "meta" && request.museCodeClientId !== undefined) {
73
+ headers["x-client-id"] = request.museCodeClientId;
74
+ }
70
75
  // Pi's Anthropic transport honors compat.supportsTemperature; the OpenAI
71
76
  // transports forward temperature regardless, so drop it here for models
72
77
  // that reject it instead of failing the whole request.
@@ -207,6 +212,17 @@ function authenticationOptions(auth: ResolvedProviderAuth, api: unknown): Bedroc
207
212
  };
208
213
  }
209
214
 
215
+ // Anthropic Messages endpoints outside Anthropic that take the key as a bearer
216
+ // token (Claude Code's ANTHROPIC_AUTH_TOKEN) and reject x-api-key.
217
+ const BEARER_MESSAGES_PROVIDERS: ReadonlySet<unknown> = new Set(["meta"]);
218
+
219
+ function sendsBearerToMessages(
220
+ auth: ResolvedProviderAuth,
221
+ model: Model,
222
+ ): auth is Extract<ResolvedProviderAuth, { type: "bearer" }> {
223
+ return auth.type === "bearer" && isAnthropic(model.api) && BEARER_MESSAGES_PROVIDERS.has(model.provider);
224
+ }
225
+
210
226
  function isClaudeCodeOAuth(auth: ResolvedProviderAuth, api: unknown): boolean {
211
227
  return auth.type === "bearer" && isAnthropic(api) && auth.apiKey.includes("sk-ant-oat");
212
228
  }
@@ -1,9 +1,9 @@
1
1
  import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
- import { HttpError } from "../http/errors";
4
- import { providerToolCallIdentity, toolsByWireName } from "../interaction/tool_identity";
5
- import { isAnthropicEffort } from "../interaction/provider_continuation_state";
6
- import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities";
3
+ import { HttpError } from "../http/errors.js";
4
+ import { providerToolCallIdentity, toolsByWireName } from "../interaction/tool_identity.js";
5
+ import { isAnthropicEffort } from "../interaction/provider_continuation_state.js";
6
+ import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities.js";
7
7
  import type {
8
8
  InteractionItem,
9
9
  InteractionOutput,
@@ -13,7 +13,7 @@ import type {
13
13
  ProviderContinuationState,
14
14
  ProviderIdentity,
15
15
  ToolKind,
16
- } from "../interaction/types";
16
+ } from "../interaction/types.js";
17
17
 
18
18
  export function piMessageToInteractionOutput(
19
19
  message: Record<string, unknown>,
@@ -1,4 +1,4 @@
1
- import { subscriptionUsageLimitFromFailure } from "./subscription_limits";
1
+ import { subscriptionUsageLimitFromFailure } from "./subscription_limits.js";
2
2
 
3
3
  export type ProviderAttemptFailure =
4
4
  | {
@@ -8,46 +8,46 @@ import {
8
8
  type RoutingDecision,
9
9
  } from "@mupt-ai/dari-router/policy-engine";
10
10
 
11
- import { executionProviderForModel, keySourceForModel } from "../models/execution_provider";
12
- import { HttpError } from "../http/errors";
13
- import type { RequestTags } from "../platform/platform";
14
- import type { InteractionRequest, ProviderIdentity } from "../interaction/types";
11
+ import { executionProviderForModel, keySourceForModel } from "../models/execution_provider.js";
12
+ import { HttpError } from "../http/errors.js";
13
+ import type { RequestTags } from "../platform/platform.js";
14
+ import type { InteractionRequest, ProviderIdentity } from "../interaction/types.js";
15
15
  import {
16
16
  CustomerDisconnectedError,
17
17
  createProviderAttemptAbort,
18
18
  type ProviderAttemptAbort,
19
- } from "../runtime/customer_disconnect";
19
+ } from "../runtime/customer_disconnect.js";
20
20
  import {
21
21
  isProviderFailureMessage,
22
22
  providerFailureFromCaught,
23
23
  providerFailureFromEvent,
24
- } from "../runtime/provider_stream_outcome";
25
- import { providerAuthForSelectedModel } from "../strategies/routing";
26
- import { scrubSecretValues } from "../telemetry/scrub";
24
+ } from "../runtime/provider_stream_outcome.js";
25
+ import { providerAuthForSelectedModel } from "../strategies/routing.js";
26
+ import { scrubSecretValues } from "../telemetry/scrub.js";
27
27
  import {
28
28
  usageContextFor,
29
29
  type RoutingUsageContext,
30
- } from "../telemetry/usage";
30
+ } from "../telemetry/usage.js";
31
31
  import type {
32
32
  ProviderAuth,
33
33
  ProviderKeySource,
34
34
  ResolvedRouter,
35
35
  ResolvedRouterModelConfig,
36
- } from "../types";
37
- import { awsRoleCredentials } from "./aws_assume_role";
36
+ } from "../types.js";
37
+ import { awsRoleCredentials } from "./aws_assume_role.js";
38
38
  import {
39
39
  attachProviderResponseCapture,
40
40
  createProviderResponseCapture,
41
41
  type ProviderFetch,
42
42
  type ProviderResponseCapture,
43
- } from "./response_capture";
43
+ } from "./response_capture.js";
44
44
  import {
45
45
  completeInteractionModel,
46
46
  streamInteractionModel,
47
47
  type ProviderEndpoint,
48
48
  type ProviderEventStream,
49
- } from "./pi";
50
- import { promptTokenEstimateFor, type PromptTokenEstimate } from "./cancel_estimate";
49
+ } from "./pi.js";
50
+ import { promptTokenEstimateFor, type PromptTokenEstimate } from "./cancel_estimate.js";
51
51
 
52
52
  type ProviderCallConfig = {
53
53
  model: string;
@@ -115,8 +115,10 @@ export function prepareProviderExecution(args: {
115
115
  }
116
116
  const provider = executionProviderForModel(args.credentials, model);
117
117
  const supplied = args.credentials.provider_credentials?.[model];
118
- const providerKeySource = supplied ? "user" : keySourceForModel(args.credentials, model);
119
- if (args.credentials.strict === true && providerKeySource === "subscription") {
118
+ const providerKeySource = keySourceForModel(args.credentials, model);
119
+ // A strict router serves a plan only when the platform supplied it for this
120
+ // request, never a pooled or personal one it resolved.
121
+ if (args.credentials.strict === true && providerKeySource === "subscription" && !supplied) {
120
122
  throw new HttpError(
121
123
  400,
122
124
  `Strict routers do not serve '${model}' from a personal subscription.`,
@@ -148,7 +150,9 @@ export function prepareProviderExecution(args: {
148
150
  : {}),
149
151
  provider,
150
152
  providerKeySource,
151
- ...(providerKeySource === "subscription" && args.credentials.attributed_user_id
153
+ // Only resolved personal subscriptions are held at their usage limit;
154
+ // the platform manages the plans it supplies.
155
+ ...(providerKeySource === "subscription" && !supplied && args.credentials.attributed_user_id
152
156
  ? {
153
157
  subscriptionUserId: args.credentials.attributed_user_id,
154
158
  subscriptionCredentialId: args.credentials.subscription_credential_ids?.[provider],
@@ -1,8 +1,8 @@
1
1
  import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
- import { gatewayFor } from "../models/gateways";
4
- import { providerFailureFromCaught } from "../runtime/provider_stream_outcome";
5
- import type { ProviderFetch } from "./response_capture";
3
+ import { gatewayFor } from "../models/gateways.js";
4
+ import { providerFailureFromCaught } from "../runtime/provider_stream_outcome.js";
5
+ import type { ProviderFetch } from "./response_capture.js";
6
6
 
7
7
  // Gateways bill per call and say what they billed: OpenRouter as `usage.cost`
8
8
  // on the final chunk, Vercel AI Gateway as `providerMetadata.gateway.cost`.
@@ -1,6 +1,6 @@
1
1
  import type { ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
2
- import { HttpError } from "../http/errors";
3
- import type { InteractionRequest } from "../interaction/types";
2
+ import { HttpError } from "../http/errors.js";
3
+ import type { InteractionRequest } from "../interaction/types.js";
4
4
 
5
5
  type ReasoningRequest = Pick<InteractionRequest, "reasoning">;
6
6
 
@@ -3,32 +3,32 @@ import type {
3
3
  RoutingDecision,
4
4
  } from "@mupt-ai/dari-router/policy-engine";
5
5
 
6
- import type { InteractionRequest, ProviderIdentity } from "../interaction/types";
6
+ import type { InteractionRequest, ProviderIdentity } from "../interaction/types.js";
7
7
  import {
8
8
  captureOperationalError,
9
9
  type OperationalErrorCode,
10
- } from "../observability/errors";
11
- import type { ProviderStreamOutcome } from "../runtime/provider_stream_outcome";
12
- import type { RoutedProtocol } from "../runtime/routed_protocol";
10
+ } from "../observability/errors.js";
11
+ import type { ProviderStreamOutcome } from "../runtime/provider_stream_outcome.js";
12
+ import type { RoutedProtocol } from "../runtime/routed_protocol.js";
13
13
  import {
14
14
  reportedExecution,
15
15
  type FrozenProviderTerminal,
16
16
  type ProviderAttemptRecord,
17
17
  type ReportableProviderOutcome,
18
18
  type RoutedRuntimeReporter,
19
- } from "../runtime/runtime_reporter";
20
- import type { ProviderKeySource } from "../types";
19
+ } from "../runtime/runtime_reporter.js";
20
+ import type { ProviderKeySource } from "../types.js";
21
21
  import {
22
22
  reportRoutingUsage,
23
23
  type RoutingUsageContext,
24
- } from "../telemetry/usage";
25
- import { customerCanceledProviderMessage } from "../runtime/customer_disconnect";
24
+ } from "../telemetry/usage.js";
25
+ import { customerCanceledProviderMessage } from "../runtime/customer_disconnect.js";
26
26
  import {
27
27
  estimatedCancelUsage,
28
28
  partialInteractionOutput,
29
29
  type DeliveredOutput,
30
30
  type PromptTokenEstimate,
31
- } from "./cancel_estimate";
31
+ } from "./cancel_estimate.js";
32
32
 
33
33
  // Structurally a subset of ProviderExecution. The narrowing is deliberate: it
34
34
  // keeps apiKey and auth out of the finalizer.
@@ -1,10 +1,10 @@
1
1
  import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
- import { providerFailureMessage } from "../runtime/provider_stream_outcome";
4
- import type { ProviderKeySource } from "../types";
5
- import type { CapturedProviderResponse } from "./response_capture";
3
+ import { providerFailureMessage } from "../runtime/provider_stream_outcome.js";
4
+ import type { ProviderKeySource } from "../types.js";
5
+ import type { CapturedProviderResponse } from "./response_capture.js";
6
6
 
7
- export type SubscriptionOAuthProvider = "anthropic_claude_code" | "openai_codex";
7
+ export type SubscriptionOAuthProvider = "anthropic_claude_code" | "openai_codex" | "meta_muse";
8
8
 
9
9
  export type SubscriptionUsageLimit = {
10
10
  oauthProvider: SubscriptionOAuthProvider;
@@ -25,6 +25,7 @@ const FAILURE_MARKER = "subscription_usage_limit";
25
25
  const SUBSCRIPTION_LABEL: Record<SubscriptionOAuthProvider, string> = {
26
26
  anthropic_claude_code: "Claude Code",
27
27
  openai_codex: "ChatGPT",
28
+ meta_muse: "Muse Code",
28
29
  };
29
30
 
30
31
  export function subscriptionOAuthProviderFor(
@@ -34,13 +35,16 @@ export function subscriptionOAuthProviderFor(
34
35
  if (keySource !== "subscription") return null;
35
36
  if (provider === "anthropic") return "anthropic_claude_code";
36
37
  if (provider === "openai" || provider === "openai-codex") return "openai_codex";
38
+ if (provider === "meta") return "meta_muse";
37
39
  return null;
38
40
  }
39
41
 
40
42
  /**
41
43
  * Recognize a personal subscription that has run out of quota. Claude Code
42
44
  * answers 429 with the unified rate-limit headers; the ChatGPT backend answers
43
- * 429 with a structured `error.code` and `resets_at`. The Codex WebSocket
45
+ * 429 with a structured `error.code` and `resets_at`. Meta documents no
46
+ * usage-limit signature for Muse Code plans, so any 429 on one holds it until
47
+ * the reset Meta gives, if any. The Codex WebSocket
44
48
  * transport bypasses fetch, so its usage-limit error only survives as message
45
49
  * text and is matched there without a reset time.
46
50
  */
@@ -57,6 +61,7 @@ export function detectSubscriptionUsageLimit(args: {
57
61
  if (oauthProvider === "anthropic_claude_code") {
58
62
  return anthropicUsageLimit(args.captured, now);
59
63
  }
64
+ if (oauthProvider === "meta_muse") return museUsageLimit(args.captured, now);
60
65
  return codexUsageLimit(args.captured, providerFailureMessage(args.failure), now);
61
66
  }
62
67
 
@@ -109,6 +114,18 @@ function codexUsageLimit(
109
114
  };
110
115
  }
111
116
 
117
+ function museUsageLimit(
118
+ captured: CapturedProviderResponse | undefined,
119
+ now: Date,
120
+ ): SubscriptionUsageLimit | null {
121
+ if (captured === undefined || captured.status !== 429) return null;
122
+ return {
123
+ oauthProvider: "meta_muse",
124
+ resetsAt: laterReset(codexErrorBody(captured.bodyText)?.resets_at, captured.headers, now),
125
+ reason: "Muse Code usage limit reached.",
126
+ };
127
+ }
128
+
112
129
  function codexErrorBody(bodyText: string): Record<string, unknown> | null {
113
130
  try {
114
131
  const parsed: unknown = JSON.parse(bodyText);
@@ -178,13 +195,13 @@ export function subscriptionUsageLimitFromFailure(
178
195
  const oauthProvider = marker.oauth_provider;
179
196
  const resetsAt = typeof marker.resets_at === "string" ? new Date(marker.resets_at) : null;
180
197
  if (
181
- (oauthProvider !== "anthropic_claude_code" && oauthProvider !== "openai_codex")
198
+ typeof oauthProvider !== "string" || !(oauthProvider in SUBSCRIPTION_LABEL)
182
199
  || resetsAt === null || Number.isNaN(resetsAt.getTime())
183
200
  ) {
184
201
  return null;
185
202
  }
186
203
  return {
187
- oauthProvider,
204
+ oauthProvider: oauthProvider as SubscriptionOAuthProvider,
188
205
  resetsAt,
189
206
  reason: typeof marker.reason === "string" ? marker.reason : "Subscription usage limit reached.",
190
207
  ...(marker.switched === true ? { switched: true } : {}),
@@ -4,11 +4,11 @@ import {
4
4
  type RoutingDecision,
5
5
  } from "@mupt-ai/dari-router/policy-engine";
6
6
 
7
- import type { RoutedDecision } from "../../strategies/route_decision";
8
- import { isBackgroundRequest } from "../../interaction/types";
9
- import { HttpError } from "../../http/errors";
10
- import { assertCreditAvailableBeforeRouting } from "../../telemetry/usage";
11
- import type { PreparedRoutedCompletion } from "../prepare_routed_completion";
7
+ import type { RoutedDecision } from "../../strategies/route_decision.js";
8
+ import { isBackgroundRequest } from "../../interaction/types.js";
9
+ import { HttpError } from "../../http/errors.js";
10
+ import { assertCreditAvailableBeforeRouting } from "../../telemetry/usage.js";
11
+ import type { PreparedRoutedCompletion } from "../prepare_routed_completion.js";
12
12
  import { leaseFallbackDecision } from "../routing_lease.js";
13
13
 
14
14
  // Explicit background classes bypass the selector and every lease path.
@@ -1,4 +1,4 @@
1
- import { HttpError } from "../http/errors";
1
+ import { HttpError } from "../http/errors.js";
2
2
 
3
3
  const CUSTOMER_DISCONNECTED_MESSAGE = "Client disconnected.";
4
4
 
@@ -1,9 +1,9 @@
1
1
  import type { RoutingCandidate, RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
- import { HttpError } from "../http/errors";
4
- import { explicitModelId } from "../protocol/input/router_model";
5
- import type { RoutedDecision } from "../strategies/route_decision";
6
- import type { PreparedRoutedCompletion } from "./prepare_routed_completion";
3
+ import { HttpError } from "../http/errors.js";
4
+ import { explicitModelId } from "../protocol/input/router_model.js";
5
+ import type { RoutedDecision } from "../strategies/route_decision.js";
6
+ import type { PreparedRoutedCompletion } from "./prepare_routed_completion.js";
7
7
 
8
8
  /* A request for `dari/model/<id>` is served by exactly that enabled model,
9
9
  with no selector, lease, or fallback: the user chose it, like picking a
@@ -14,14 +14,7 @@ export function explicitModelDecision(
14
14
  ): RoutedDecision | null {
15
15
  const modelId = explicitModelId(prepared.interaction.model);
16
16
  if (modelId === null) return null;
17
- if (!prepared.credentials.enabled_models.includes(modelId)) {
18
- throw new HttpError(
19
- 400,
20
- `Model '${modelId}' is not enabled on this router.`,
21
- "model_not_enabled",
22
- "model",
23
- );
24
- }
17
+ if (!prepared.credentials.enabled_models.includes(modelId)) throw modelNotEnabled(modelId);
25
18
  const candidates = prepared.routing.candidateResolution.candidates.filter(
26
19
  (candidate) => candidate.model === modelId,
27
20
  );
@@ -63,14 +56,7 @@ function pickCandidate(
63
56
  refuses everything else instead of substituting. */
64
57
  export function strictModelDecision(prepared: PreparedRoutedCompletion): RoutedDecision {
65
58
  const modelId = explicitModelId(prepared.interaction.model);
66
- if (modelId === null) {
67
- throw new HttpError(
68
- 400,
69
- "This router is strict: request a pinned model as 'dari/model/<id>'.",
70
- "strict_model_required",
71
- "model",
72
- );
73
- }
59
+ if (modelId === null) throw strictModelRequired();
74
60
  const { decision } = explicitModelDecision(prepared)!;
75
61
  const requested = prepared.interaction.reasoning?.effort
76
62
  ?? prepared.credentials.model_configs?.[modelId]?.default_thinking_level;
@@ -84,3 +70,16 @@ export function strictModelDecision(prepared: PreparedRoutedCompletion): RoutedD
84
70
  }
85
71
  return { decision };
86
72
  }
73
+
74
+ export function modelNotEnabled(modelId: string): HttpError {
75
+ return new HttpError(400, `Model '${modelId}' is not enabled on this router.`, "model_not_enabled", "model");
76
+ }
77
+
78
+ export function strictModelRequired(): HttpError {
79
+ return new HttpError(
80
+ 400,
81
+ "This router is strict: request a pinned model as 'dari/model/<id>'.",
82
+ "strict_model_required",
83
+ "model",
84
+ );
85
+ }
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
 
3
- import type { SourceProtocol } from "../../interaction/types";
3
+ import type { SourceProtocol } from "../../interaction/types.js";
4
4
 
5
5
  export type HarnessConversationIdentity =
6
6
  | {
@@ -1,12 +1,12 @@
1
1
  import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
- import { HttpError } from "../../http/errors";
3
+ import { HttpError } from "../../http/errors.js";
4
4
  import type {
5
5
  AgentRequestClass,
6
6
  AgentRequestContext,
7
7
  InteractionRequestPurpose,
8
- } from "../../interaction/types";
9
- import type { HarnessConversationIdentity } from "./conversation";
8
+ } from "../../interaction/types.js";
9
+ import type { HarnessConversationIdentity } from "./conversation.js";
10
10
 
11
11
  const MAX_ID_CHARS = 200;
12
12
 
@@ -3,7 +3,7 @@ export {
3
3
  scopedHarnessSessionId,
4
4
  type HarnessConversationIdentity,
5
5
  type HarnessConversationScope,
6
- } from "./conversation";
6
+ } from "./conversation.js";
7
7
  export {
8
8
  chatCompletionsConversationIdentity,
9
9
  claudeCodeConversationIdentity,
@@ -11,4 +11,4 @@ export {
11
11
  codexRequestPurpose,
12
12
  codexRequestContext,
13
13
  openCodeRequestContext,
14
- } from "./extract";
14
+ } from "./extract.js";
@@ -1,27 +1,29 @@
1
1
  import type { CandidatePruningAudit } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
- import { interactionConversationPrefix } from "../context/interaction_fingerprint";
3
+ import { interactionConversationPrefix } from "../context/interaction_fingerprint.js";
4
4
  import {
5
5
  buildRoutingContext,
6
6
  derivePrefixLookupHashes,
7
7
  type ImageCapabilityPrunedModel,
8
8
  type RoutingContext,
9
- } from "../context/routing_context";
10
- import { isBackgroundRequest, type InteractionRequest } from "../interaction/types";
11
- import { executionProviderForModel } from "../models/execution_provider";
12
- import { gatewayPlatform, type RequestTags } from "../platform/platform";
13
- import { resolveRouter } from "../strategies/routing";
14
- import { RequestReporter, type ReportedCandidatePruning } from "../telemetry/report";
15
- import { RoutingBillingFinalization } from "../telemetry/billing_finalization";
16
- import type { ClientHarness, ProviderCredential, ResolvedRouter } from "../types";
17
- import { requestTags } from "./request_tags";
18
- import type { RoutedRuntimeReporter } from "./runtime_reporter";
19
- import type { RoutedProtocol } from "./routed_protocol";
9
+ } from "../context/routing_context.js";
10
+ import { isBackgroundRequest, type InteractionRequest } from "../interaction/types.js";
11
+ import { executionProviderForModel } from "../models/execution_provider.js";
12
+ import { codexModelConfig, subscriptionServes } from "../models/subscriptions.js";
13
+ import { gatewayPlatform, type RequestTags } from "../platform/platform.js";
14
+ import { resolveRouter } from "../strategies/routing.js";
15
+ import { RequestReporter, type ReportedCandidatePruning } from "../telemetry/report.js";
16
+ import { RoutingBillingFinalization } from "../telemetry/billing_finalization.js";
17
+ import type { ClientHarness, ProviderCredential, ResolvedRouter } from "../types.js";
18
+ import { requestTags } from "./request_tags.js";
19
+ import { strictProviderAccess } from "./strict_provider_access.js";
20
+ import type { RoutedRuntimeReporter } from "./runtime_reporter.js";
21
+ import type { RoutedProtocol } from "./routed_protocol.js";
20
22
  import {
21
23
  scopedHarnessConversationId,
22
24
  scopedHarnessSessionId,
23
25
  type HarnessConversationIdentity,
24
- } from "./harness_identity";
26
+ } from "./harness_identity/index.js";
25
27
 
26
28
  export type PreparedRoutedCompletion = {
27
29
  requestId: string;
@@ -125,7 +127,10 @@ export async function prepareRoutedCompletion(args: {
125
127
  }
126
128
  credentials = conversationCredentials;
127
129
  }
128
- credentials = await withProviderCredentials(credentials, args.apiKey);
130
+ const access = strictProviderAccess(credentials, args.interaction);
131
+ credentials = access.credentials;
132
+ args = { ...args, interaction: access.interaction };
133
+ credentials = await withProviderCredentials(credentials, args.apiKey, args.clientHarness);
129
134
  const billable = true;
130
135
  const routing = await buildRoutingContext({
131
136
  routerId: prefixFingerprintRouterId,
@@ -188,6 +193,7 @@ export async function prepareRoutedCompletion(args: {
188
193
  async function withProviderCredentials(
189
194
  credentials: ResolvedRouter,
190
195
  apiKey: string,
196
+ clientHarness: ClientHarness | undefined,
191
197
  ): Promise<ResolvedRouter> {
192
198
  const platform = gatewayPlatform();
193
199
  if (platform.resolveProviderCredential === undefined) return credentials;
@@ -200,14 +206,27 @@ async function withProviderCredentials(
200
206
  routerId: credentials.router_id,
201
207
  organizationId: credentials.organization_id,
202
208
  apiKey,
209
+ ...(clientHarness ? { clientHarness } : {}),
203
210
  }),
204
211
  ] as const),
205
212
  );
206
213
  const provider_credentials: Record<string, ProviderCredential> = {};
214
+ const model_configs = { ...credentials.model_configs };
207
215
  for (const [model, credential] of resolved) {
208
- if (credential?.apiKey.trim()) provider_credentials[model] = credential;
216
+ if (!credential?.apiKey.trim()) continue;
217
+ const plan = credential.subscription;
218
+ if (plan !== undefined && !subscriptionServes(plan, model, clientHarness)) continue;
219
+ provider_credentials[model] = credential;
220
+ if (plan === "openai_codex") {
221
+ // Keep the catalog's limits and thinking levels; only the serving
222
+ // endpoint changes.
223
+ model_configs[model] = {
224
+ ...model_configs[model],
225
+ ...codexModelConfig(model, credentials.model_prices?.[model] ?? null),
226
+ };
227
+ }
209
228
  }
210
- return { ...credentials, provider_credentials };
229
+ return { ...credentials, provider_credentials, model_configs };
211
230
  }
212
231
 
213
232
  // Core's cache-aware pruning audit, extended with the context layer's image
@@ -1,4 +1,4 @@
1
- import type { ProviderStreamOutcome } from "./provider_stream_outcome";
1
+ import type { ProviderStreamOutcome } from "./provider_stream_outcome.js";
2
2
 
3
3
  type LifecycleArgs = {
4
4
  partialResponse: () => Record<string, unknown>;
@@ -1,6 +1,6 @@
1
1
  import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
- import type { InteractionOutput } from "../interaction/types";
3
- import { scrubSecrets } from "../telemetry/scrub";
2
+ import type { InteractionOutput } from "../interaction/types.js";
3
+ import { scrubSecrets } from "../telemetry/scrub.js";
4
4
 
5
5
  export type ProviderStreamOutcome =
6
6
  | {
@@ -1,5 +1,5 @@
1
- import { HttpError } from "../http/errors";
2
- import type { RequestTags } from "../platform/platform";
1
+ import { HttpError } from "../http/errors.js";
2
+ import type { RequestTags } from "../platform/platform.js";
3
3
 
4
4
  const TAGS_MAX_CHARS = 2048;
5
5
  const TAGS_MAX_COUNT = 32;
@@ -1,16 +1,16 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
 
3
- import { isBackgroundRequest, type InteractionRequest } from "../interaction/types";
4
- import { explicitModelId } from "../protocol/input/router_model";
5
- import { captureRequestError } from "../observability/errors";
6
- import type { SelectorBackend } from "../strategies/routing";
7
- import type { ClientHarness } from "../types";
8
- import { assertAutoroutingAllowed, assertCreditAvailableBeforeRouting, routerSelectsModels } from "../telemetry/usage";
9
- import type { HarnessConversationIdentity } from "./harness_identity";
10
- import { CustomerDisconnectedError } from "./customer_disconnect";
11
- import { prepareRoutedCompletion } from "./prepare_routed_completion";
12
- import type { RoutedProtocol } from "./routed_protocol";
13
- import { runPreparedRoutedCompletion } from "./routed_runtime";
3
+ import { isBackgroundRequest, type InteractionRequest } from "../interaction/types.js";
4
+ import { explicitModelId } from "../protocol/input/router_model.js";
5
+ import { captureRequestError } from "../observability/errors.js";
6
+ import type { SelectorBackend } from "../strategies/routing.js";
7
+ import type { ClientHarness } from "../types.js";
8
+ import { assertAutoroutingAllowed, assertCreditAvailableBeforeRouting, routerSelectsModels } from "../telemetry/usage.js";
9
+ import type { HarnessConversationIdentity } from "./harness_identity/index.js";
10
+ import { CustomerDisconnectedError } from "./customer_disconnect.js";
11
+ import { prepareRoutedCompletion } from "./prepare_routed_completion.js";
12
+ import type { RoutedProtocol } from "./routed_protocol.js";
13
+ import { runPreparedRoutedCompletion } from "./routed_runtime.js";
14
14
 
15
15
  export async function handleRoutedCompletion(args: {
16
16
  request: Request;
@@ -1,6 +1,6 @@
1
1
  import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
2
- import type { InteractionOutput, InteractionRequest, ProviderIdentity } from "../interaction/types";
3
- import type { ProviderStreamOutcome } from "./provider_stream_outcome";
2
+ import type { InteractionOutput, InteractionRequest, ProviderIdentity } from "../interaction/types.js";
3
+ import type { ProviderStreamOutcome } from "./provider_stream_outcome.js";
4
4
 
5
5
  export type RoutedCompletionResponseArgs = {
6
6
  id: string;