@mupt-ai/dari-gateway 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/README.md +8 -1
  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 +23 -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 +81 -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 +6 -0
  31. package/dist/index.js +8 -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 +37 -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 +65 -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 +53 -0
  48. package/dist/interaction/capabilities.d.ts +3 -0
  49. package/dist/interaction/capabilities.js +24 -0
  50. package/dist/interaction/image.d.ts +4 -0
  51. package/dist/interaction/image.js +13 -0
  52. package/dist/interaction/portable_reasoning_state.d.ts +4 -0
  53. package/dist/interaction/portable_reasoning_state.js +18 -0
  54. package/dist/interaction/provider_continuation_state.d.ts +6 -0
  55. package/dist/interaction/provider_continuation_state.js +27 -0
  56. package/dist/interaction/tool_identity.d.ts +10 -0
  57. package/dist/interaction/tool_identity.js +41 -0
  58. package/dist/interaction/types.d.ts +203 -0
  59. package/dist/interaction/types.js +5 -0
  60. package/dist/models/context_limits.d.ts +2 -0
  61. package/dist/models/context_limits.js +7 -0
  62. package/dist/models/execution_provider.d.ts +8 -0
  63. package/dist/models/execution_provider.js +13 -0
  64. package/dist/models/gateways.d.ts +11 -0
  65. package/dist/models/gateways.js +45 -0
  66. package/dist/models/ids.d.ts +1 -0
  67. package/dist/models/ids.js +15 -0
  68. package/dist/models/provider_defaults.d.ts +4 -0
  69. package/dist/models/provider_defaults.js +41 -0
  70. package/dist/models/runtime_overrides.d.ts +4 -0
  71. package/dist/models/runtime_overrides.js +209 -0
  72. package/dist/observability/errors.d.ts +8 -0
  73. package/dist/observability/errors.js +11 -0
  74. package/dist/platform/platform.d.ts +152 -0
  75. package/dist/platform/platform.js +11 -0
  76. package/dist/platform/routing_contract.d.ts +2 -0
  77. package/dist/platform/routing_contract.js +5 -0
  78. package/dist/protocol/input/anthropic_messages.d.ts +2 -0
  79. package/dist/protocol/input/anthropic_messages.js +494 -0
  80. package/dist/protocol/input/chat_completions.d.ts +4 -0
  81. package/dist/protocol/input/chat_completions.js +212 -0
  82. package/dist/protocol/input/chat_completions_validation.d.ts +2 -0
  83. package/dist/protocol/input/chat_completions_validation.js +257 -0
  84. package/dist/protocol/input/openai_responses.d.ts +2 -0
  85. package/dist/protocol/input/openai_responses.js +666 -0
  86. package/dist/protocol/input/router_model.d.ts +7 -0
  87. package/dist/protocol/input/router_model.js +43 -0
  88. package/dist/protocol/output/anthropic_messages.d.ts +10 -0
  89. package/dist/protocol/output/anthropic_messages.js +15 -0
  90. package/dist/protocol/output/anthropic_messages_output.d.ts +10 -0
  91. package/dist/protocol/output/anthropic_messages_output.js +124 -0
  92. package/dist/protocol/output/anthropic_messages_stream.d.ts +16 -0
  93. package/dist/protocol/output/anthropic_messages_stream.js +267 -0
  94. package/dist/protocol/output/chat_completions.d.ts +29 -0
  95. package/dist/protocol/output/chat_completions.js +406 -0
  96. package/dist/protocol/output/chat_reasoning_detail.d.ts +2 -0
  97. package/dist/protocol/output/chat_reasoning_detail.js +13 -0
  98. package/dist/protocol/output/delivered_stream_snapshot.d.ts +10 -0
  99. package/dist/protocol/output/delivered_stream_snapshot.js +31 -0
  100. package/dist/protocol/output/openai_responses.d.ts +10 -0
  101. package/dist/protocol/output/openai_responses.js +14 -0
  102. package/dist/protocol/output/openai_responses_output.d.ts +14 -0
  103. package/dist/protocol/output/openai_responses_output.js +125 -0
  104. package/dist/protocol/output/openai_responses_stream.d.ts +18 -0
  105. package/dist/protocol/output/openai_responses_stream.js +546 -0
  106. package/dist/protocol/output/sse_stream.d.ts +31 -0
  107. package/dist/protocol/output/sse_stream.js +67 -0
  108. package/dist/providers/anthropic_safeguards.d.ts +11 -0
  109. package/dist/providers/anthropic_safeguards.js +81 -0
  110. package/dist/providers/aws_assume_role.d.ts +17 -0
  111. package/dist/providers/aws_assume_role.js +107 -0
  112. package/dist/providers/cancel_estimate.d.ts +43 -0
  113. package/dist/providers/cancel_estimate.js +89 -0
  114. package/dist/providers/execution.d.ts +72 -0
  115. package/dist/providers/execution.js +491 -0
  116. package/dist/providers/model_capabilities.d.ts +11 -0
  117. package/dist/providers/model_capabilities.js +29 -0
  118. package/dist/providers/pi.d.ts +65 -0
  119. package/dist/providers/pi.js +319 -0
  120. package/dist/providers/pi_context.d.ts +7 -0
  121. package/dist/providers/pi_context.js +405 -0
  122. package/dist/providers/pi_options.d.ts +11 -0
  123. package/dist/providers/pi_options.js +398 -0
  124. package/dist/providers/pi_output.d.ts +2 -0
  125. package/dist/providers/pi_output.js +453 -0
  126. package/dist/providers/provider_attempt_runner.d.ts +55 -0
  127. package/dist/providers/provider_attempt_runner.js +90 -0
  128. package/dist/providers/provider_call.d.ts +77 -0
  129. package/dist/providers/provider_call.js +292 -0
  130. package/dist/providers/provider_reported_cost.d.ts +10 -0
  131. package/dist/providers/provider_reported_cost.js +123 -0
  132. package/dist/providers/reasoning.d.ts +12 -0
  133. package/dist/providers/reasoning.js +30 -0
  134. package/dist/providers/response_capture.d.ts +23 -0
  135. package/dist/providers/response_capture.js +47 -0
  136. package/dist/providers/stream_finalization.d.ts +46 -0
  137. package/dist/providers/stream_finalization.js +165 -0
  138. package/dist/providers/subscription_limits.d.ts +31 -0
  139. package/dist/providers/subscription_limits.js +163 -0
  140. package/dist/providers/subscription_usage.d.ts +10 -0
  141. package/dist/providers/subscription_usage.js +79 -0
  142. package/dist/runtime/claude_code/auxiliary_routing.d.ts +3 -0
  143. package/dist/runtime/claude_code/auxiliary_routing.js +60 -0
  144. package/dist/runtime/customer_disconnect.d.ts +20 -0
  145. package/dist/runtime/customer_disconnect.js +49 -0
  146. package/dist/runtime/explicit_model.d.ts +4 -0
  147. package/dist/runtime/explicit_model.js +53 -0
  148. package/dist/runtime/harness_identity/conversation.d.ts +33 -0
  149. package/dist/runtime/harness_identity/conversation.js +39 -0
  150. package/dist/runtime/harness_identity/extract.d.ts +8 -0
  151. package/dist/runtime/harness_identity/extract.js +214 -0
  152. package/dist/runtime/harness_identity/index.d.ts +2 -0
  153. package/dist/runtime/harness_identity/index.js +2 -0
  154. package/dist/runtime/prepare_routed_completion.d.ts +33 -0
  155. package/dist/runtime/prepare_routed_completion.js +167 -0
  156. package/dist/runtime/provider_stream_lifecycle.d.ts +31 -0
  157. package/dist/runtime/provider_stream_lifecycle.js +88 -0
  158. package/dist/runtime/provider_stream_outcome.d.ts +23 -0
  159. package/dist/runtime/provider_stream_outcome.js +55 -0
  160. package/dist/runtime/request_tags.d.ts +7 -0
  161. package/dist/runtime/request_tags.js +33 -0
  162. package/dist/runtime/routed_completion.d.ts +17 -0
  163. package/dist/runtime/routed_completion.js +80 -0
  164. package/dist/runtime/routed_protocol.d.ts +30 -0
  165. package/dist/runtime/routed_protocol.js +1 -0
  166. package/dist/runtime/routed_runtime.d.ts +40 -0
  167. package/dist/runtime/routed_runtime.js +535 -0
  168. package/dist/runtime/routing_lease.d.ts +26 -0
  169. package/dist/runtime/routing_lease.js +210 -0
  170. package/dist/runtime/runtime_reporter.d.ts +71 -0
  171. package/dist/runtime/runtime_reporter.js +35 -0
  172. package/dist/self_host/config.d.ts +46 -0
  173. package/dist/self_host/config.js +105 -0
  174. package/dist/self_host/main.d.ts +16 -0
  175. package/dist/self_host/main.js +95 -0
  176. package/dist/self_host/platform.d.ts +13 -0
  177. package/dist/self_host/platform.js +50 -0
  178. package/dist/self_host/prefix_store.d.ts +46 -0
  179. package/dist/self_host/prefix_store.js +261 -0
  180. package/dist/self_host/resolve.d.ts +28 -0
  181. package/dist/self_host/resolve.js +171 -0
  182. package/dist/self_host/subscriptions/access.d.ts +10 -0
  183. package/dist/self_host/subscriptions/access.js +37 -0
  184. package/dist/self_host/subscriptions/http.d.ts +15 -0
  185. package/dist/self_host/subscriptions/http.js +187 -0
  186. package/dist/self_host/subscriptions/index.d.ts +24 -0
  187. package/dist/self_host/subscriptions/index.js +24 -0
  188. package/dist/self_host/subscriptions/oauth.d.ts +55 -0
  189. package/dist/self_host/subscriptions/oauth.js +281 -0
  190. package/dist/self_host/subscriptions/store.d.ts +78 -0
  191. package/dist/self_host/subscriptions/store.js +235 -0
  192. package/dist/strategies/auto_routing_selector.d.ts +12 -0
  193. package/dist/strategies/auto_routing_selector.js +61 -0
  194. package/dist/strategies/eval_relevance.d.ts +17 -0
  195. package/dist/strategies/eval_relevance.js +32 -0
  196. package/dist/strategies/fallback_decision.d.ts +8 -0
  197. package/dist/strategies/fallback_decision.js +17 -0
  198. package/dist/strategies/priority_selector.d.ts +7 -0
  199. package/dist/strategies/priority_selector.js +37 -0
  200. package/dist/strategies/route_decision.d.ts +22 -0
  201. package/dist/strategies/route_decision.js +65 -0
  202. package/dist/strategies/routing.d.ts +74 -0
  203. package/dist/strategies/routing.js +280 -0
  204. package/dist/strategies/selector_projection.d.ts +15 -0
  205. package/dist/strategies/selector_projection.js +161 -0
  206. package/dist/telemetry/background.d.ts +7 -0
  207. package/dist/telemetry/background.js +33 -0
  208. package/dist/telemetry/benchmark_replay.d.ts +37 -0
  209. package/dist/telemetry/benchmark_replay.js +108 -0
  210. package/dist/telemetry/billing_finalization.d.ts +64 -0
  211. package/dist/telemetry/billing_finalization.js +96 -0
  212. package/dist/telemetry/ingest_values.d.ts +4 -0
  213. package/dist/telemetry/ingest_values.js +12 -0
  214. package/dist/telemetry/model_cost.d.ts +3 -0
  215. package/dist/telemetry/model_cost.js +15 -0
  216. package/dist/telemetry/prefix_state.d.ts +47 -0
  217. package/dist/telemetry/prefix_state.js +116 -0
  218. package/dist/telemetry/report.d.ts +88 -0
  219. package/dist/telemetry/report.js +621 -0
  220. package/dist/telemetry/requests/interaction_observability.d.ts +45 -0
  221. package/dist/telemetry/requests/interaction_observability.js +180 -0
  222. package/dist/telemetry/requests/retained_interaction_request.d.ts +8 -0
  223. package/dist/telemetry/requests/retained_interaction_request.js +10 -0
  224. package/dist/telemetry/scrub.d.ts +2 -0
  225. package/dist/telemetry/scrub.js +31 -0
  226. package/dist/telemetry/skills/claude/catalog.d.ts +6 -0
  227. package/dist/telemetry/skills/claude/catalog.js +99 -0
  228. package/dist/telemetry/skills/claude/file_reads.d.ts +4 -0
  229. package/dist/telemetry/skills/claude/file_reads.js +110 -0
  230. package/dist/telemetry/skills/claude/observations.d.ts +3 -0
  231. package/dist/telemetry/skills/claude/observations.js +366 -0
  232. package/dist/telemetry/skills/codex/catalog.d.ts +11 -0
  233. package/dist/telemetry/skills/codex/catalog.js +138 -0
  234. package/dist/telemetry/skills/codex/exec_file_reads.d.ts +9 -0
  235. package/dist/telemetry/skills/codex/exec_file_reads.js +36 -0
  236. package/dist/telemetry/skills/codex/explicit.d.ts +3 -0
  237. package/dist/telemetry/skills/codex/explicit.js +90 -0
  238. package/dist/telemetry/skills/codex/file_reads.d.ts +4 -0
  239. package/dist/telemetry/skills/codex/file_reads.js +37 -0
  240. package/dist/telemetry/skills/codex/identity.d.ts +2 -0
  241. package/dist/telemetry/skills/codex/identity.js +20 -0
  242. package/dist/telemetry/skills/observations.d.ts +21 -0
  243. package/dist/telemetry/skills/observations.js +41 -0
  244. package/dist/telemetry/skills/paths.d.ts +11 -0
  245. package/dist/telemetry/skills/paths.js +61 -0
  246. package/dist/telemetry/skills/pi.d.ts +6 -0
  247. package/dist/telemetry/skills/pi.js +223 -0
  248. package/dist/telemetry/skills/shell_file_reads.d.ts +7 -0
  249. package/dist/telemetry/skills/shell_file_reads.js +226 -0
  250. package/dist/telemetry/skills/shell_words.d.ts +13 -0
  251. package/dist/telemetry/skills/shell_words.js +189 -0
  252. package/dist/telemetry/tools/input.d.ts +2 -0
  253. package/dist/telemetry/tools/input.js +14 -0
  254. package/dist/telemetry/tools/observations.d.ts +29 -0
  255. package/dist/telemetry/tools/observations.js +247 -0
  256. package/dist/telemetry/usage.d.ts +57 -0
  257. package/dist/telemetry/usage.js +136 -0
  258. package/dist/types.d.ts +94 -0
  259. package/dist/types.js +1 -0
  260. package/package.json +22 -5
  261. package/src/bun.ts +4 -0
  262. package/src/context/eval_catalog.ts +1 -1
  263. package/src/context/interaction_fingerprint.ts +9 -9
  264. package/src/context/interaction_fingerprint_format.ts +1 -1
  265. package/src/context/interaction_lease_depth.ts +1 -1
  266. package/src/context/pricing.ts +1 -1
  267. package/src/context/provider_prompt_accounting.ts +5 -5
  268. package/src/context/routing_context.ts +17 -17
  269. package/src/http/auth.ts +1 -1
  270. package/src/http/handler.ts +8 -8
  271. package/src/http/serve.ts +3 -3
  272. package/src/index.ts +10 -9
  273. package/src/ingress/anthropic_messages.ts +12 -12
  274. package/src/ingress/anthropic_models.ts +1 -1
  275. package/src/ingress/chat_completions.ts +9 -9
  276. package/src/ingress/claude_code/request_context.ts +2 -2
  277. package/src/ingress/codex.ts +10 -10
  278. package/src/ingress/codex_models.ts +4 -4
  279. package/src/ingress/json.ts +1 -1
  280. package/src/ingress/models.ts +10 -10
  281. package/src/interaction/capabilities.ts +1 -1
  282. package/src/interaction/portable_reasoning_state.ts +1 -1
  283. package/src/interaction/provider_continuation_state.ts +1 -1
  284. package/src/interaction/tool_identity.ts +2 -2
  285. package/src/interaction/types.ts +3 -0
  286. package/src/models/context_limits.ts +1 -1
  287. package/src/models/execution_provider.ts +1 -1
  288. package/src/models/ids.ts +1 -1
  289. package/src/models/provider_defaults.ts +1 -1
  290. package/src/models/runtime_overrides.ts +1 -1
  291. package/src/observability/errors.ts +2 -2
  292. package/src/platform/platform.ts +36 -4
  293. package/src/protocol/input/anthropic_messages.ts +7 -7
  294. package/src/protocol/input/chat_completions.ts +5 -5
  295. package/src/protocol/input/chat_completions_validation.ts +4 -4
  296. package/src/protocol/input/openai_responses.ts +6 -6
  297. package/src/protocol/output/anthropic_messages.ts +3 -3
  298. package/src/protocol/output/anthropic_messages_output.ts +6 -4
  299. package/src/protocol/output/anthropic_messages_stream.ts +7 -7
  300. package/src/protocol/output/chat_completions.ts +13 -13
  301. package/src/protocol/output/chat_reasoning_detail.ts +1 -1
  302. package/src/protocol/output/openai_responses.ts +3 -3
  303. package/src/protocol/output/openai_responses_output.ts +4 -2
  304. package/src/protocol/output/openai_responses_stream.ts +6 -6
  305. package/src/protocol/output/sse_stream.ts +3 -3
  306. package/src/providers/anthropic_safeguards.ts +2 -2
  307. package/src/providers/aws_assume_role.ts +2 -2
  308. package/src/providers/cancel_estimate.ts +1 -1
  309. package/src/providers/execution.ts +17 -17
  310. package/src/providers/pi.ts +115 -41
  311. package/src/providers/pi_context.ts +6 -6
  312. package/src/providers/pi_options.ts +283 -453
  313. package/src/providers/pi_output.ts +6 -5
  314. package/src/providers/provider_attempt_runner.ts +1 -1
  315. package/src/providers/provider_call.ts +37 -18
  316. package/src/providers/provider_reported_cost.ts +138 -0
  317. package/src/providers/reasoning.ts +2 -2
  318. package/src/providers/stream_finalization.ts +10 -10
  319. package/src/providers/subscription_limits.ts +3 -3
  320. package/src/runtime/claude_code/auxiliary_routing.ts +5 -5
  321. package/src/runtime/customer_disconnect.ts +1 -1
  322. package/src/runtime/explicit_model.ts +31 -4
  323. package/src/runtime/harness_identity/conversation.ts +1 -1
  324. package/src/runtime/harness_identity/extract.ts +3 -3
  325. package/src/runtime/harness_identity/index.ts +2 -2
  326. package/src/runtime/prepare_routed_completion.ts +46 -10
  327. package/src/runtime/provider_stream_lifecycle.ts +1 -1
  328. package/src/runtime/provider_stream_outcome.ts +2 -2
  329. package/src/runtime/request_tags.ts +34 -0
  330. package/src/runtime/routed_completion.ts +13 -11
  331. package/src/runtime/routed_protocol.ts +2 -2
  332. package/src/runtime/routed_runtime.ts +38 -20
  333. package/src/runtime/routing_lease.ts +7 -7
  334. package/src/runtime/runtime_reporter.ts +3 -3
  335. package/src/self_host/main.ts +19 -14
  336. package/src/self_host/platform.ts +5 -5
  337. package/src/self_host/prefix_store.ts +2 -2
  338. package/src/self_host/resolve.ts +11 -11
  339. package/src/self_host/subscriptions/access.ts +2 -2
  340. package/src/self_host/subscriptions/http.ts +2 -2
  341. package/src/self_host/subscriptions/index.ts +4 -4
  342. package/src/self_host/subscriptions/store.ts +1 -1
  343. package/src/strategies/auto_routing_selector.ts +2 -2
  344. package/src/strategies/eval_relevance.ts +3 -3
  345. package/src/strategies/priority_selector.ts +1 -1
  346. package/src/strategies/route_decision.ts +7 -7
  347. package/src/strategies/routing.ts +11 -11
  348. package/src/strategies/selector_projection.ts +2 -2
  349. package/src/telemetry/billing_finalization.ts +3 -3
  350. package/src/telemetry/model_cost.ts +1 -1
  351. package/src/telemetry/prefix_state.ts +4 -4
  352. package/src/telemetry/report.ts +30 -25
  353. package/src/telemetry/requests/interaction_observability.ts +1 -1
  354. package/src/telemetry/requests/retained_interaction_request.ts +1 -1
  355. package/src/telemetry/skills/claude/catalog.ts +1 -1
  356. package/src/telemetry/skills/claude/file_reads.ts +6 -6
  357. package/src/telemetry/skills/claude/observations.ts +3 -3
  358. package/src/telemetry/skills/codex/catalog.ts +3 -3
  359. package/src/telemetry/skills/codex/exec_file_reads.ts +4 -4
  360. package/src/telemetry/skills/codex/explicit.ts +3 -3
  361. package/src/telemetry/skills/codex/file_reads.ts +5 -5
  362. package/src/telemetry/skills/observations.ts +7 -7
  363. package/src/telemetry/skills/pi.ts +3 -3
  364. package/src/telemetry/skills/shell_file_reads.ts +2 -2
  365. package/src/telemetry/skills/shell_words.ts +1 -1
  366. package/src/telemetry/tools/input.ts +1 -1
  367. package/src/telemetry/tools/observations.ts +9 -9
  368. package/src/telemetry/usage.ts +9 -5
  369. package/src/types.ts +15 -0
@@ -0,0 +1,27 @@
1
+ import { decodeUntrustedProviderContinuationState as coreDecode, encodeProviderContinuationState as coreEncode, providerIdentityFromModel as coreProviderIdentityFromModel, } from "@mupt-ai/dari-router/protocols";
2
+ import { rethrowFrameworkErrorAsHttp } from "../http/errors.js";
3
+ export { compatibleProviderContinuation, isAnthropicEffort, sameProviderIdentity } from "@mupt-ai/dari-router/protocols";
4
+ export function encodeProviderContinuationState(value) {
5
+ try {
6
+ return coreEncode(value);
7
+ }
8
+ catch (error) {
9
+ rethrowFrameworkErrorAsHttp(error, 500);
10
+ }
11
+ }
12
+ export function decodeUntrustedProviderContinuationState(value) {
13
+ try {
14
+ return coreDecode(value);
15
+ }
16
+ catch (error) {
17
+ rethrowFrameworkErrorAsHttp(error, 400);
18
+ }
19
+ }
20
+ export function providerIdentityFromModel(model) {
21
+ try {
22
+ return coreProviderIdentityFromModel(model);
23
+ }
24
+ catch (error) {
25
+ rethrowFrameworkErrorAsHttp(error, 502);
26
+ }
27
+ }
@@ -0,0 +1,10 @@
1
+ import type { InteractionTool, ProviderIdentity } from "./types.js";
2
+ export declare const TOOL_CALL_ID_MAX_LENGTH = 512;
3
+ export declare function isProtocolToolCallId(value: unknown): value is string;
4
+ export declare function toolWireName(namespace: string | undefined, name: string): string;
5
+ export declare function toolsByWireName(tools: InteractionTool[]): Map<string, InteractionTool>;
6
+ export declare function providerToolCallId(callId: string, itemId: string | undefined, providerApi: string | null): string;
7
+ export declare function providerToolCallIdentity(id: string, source: ProviderIdentity): {
8
+ callId: string;
9
+ itemId?: string;
10
+ };
@@ -0,0 +1,41 @@
1
+ import { HttpError } from "../http/errors.js";
2
+ export const TOOL_CALL_ID_MAX_LENGTH = 512;
3
+ export function isProtocolToolCallId(value) {
4
+ return (typeof value === "string" &&
5
+ value.trim().length > 0 &&
6
+ value.length <= TOOL_CALL_ID_MAX_LENGTH);
7
+ }
8
+ export function toolWireName(namespace, name) {
9
+ return namespace ? `${namespace}__${name}` : name;
10
+ }
11
+ export function toolsByWireName(tools) {
12
+ const indexed = new Map();
13
+ for (const tool of tools) {
14
+ if (tool.kind === "hosted" || tool.kind === "server_tool")
15
+ continue;
16
+ const wireName = tool.kind === "client_tool" ? tool.name : toolWireName(tool.namespace, tool.name);
17
+ if (indexed.has(wireName)) {
18
+ throw new HttpError(400, `Tool names must remain unique after namespace encoding; '${wireName}' is ambiguous.`, "invalid_request_error", "tools");
19
+ }
20
+ indexed.set(wireName, tool);
21
+ }
22
+ return indexed;
23
+ }
24
+ export function providerToolCallId(callId, itemId, providerApi) {
25
+ if (!itemId || !usesResponsesToolCallIds(providerApi))
26
+ return callId;
27
+ return `${callId}|${itemId}`;
28
+ }
29
+ export function providerToolCallIdentity(id, source) {
30
+ const separator = usesResponsesToolCallIds(source.api) ? id.indexOf("|") : -1;
31
+ const identity = separator > 0 && separator < id.length - 1
32
+ ? { callId: id.slice(0, separator), itemId: id.slice(separator + 1) }
33
+ : { callId: id };
34
+ if (!isProtocolToolCallId(identity.callId)) {
35
+ throw new HttpError(502, `Provider output tool call ID must be a non-empty string no longer than ${TOOL_CALL_ID_MAX_LENGTH} characters.`, "provider_output_invalid");
36
+ }
37
+ return identity;
38
+ }
39
+ function usesResponsesToolCallIds(api) {
40
+ return api === "openai-responses" || api === "azure-openai-responses";
41
+ }
@@ -0,0 +1,203 @@
1
+ import type { ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
2
+ export type { ProviderIdentity, ProviderContinuationState, } from "@mupt-ai/dari-router/protocols";
3
+ import type { ProviderContinuationState, ProviderIdentity } from "@mupt-ai/dari-router/protocols";
4
+ export type SourceProtocol = "anthropic_messages" | "openai_chat" | "openai_responses";
5
+ export type AgentRequestClass = "main" | "subagent" | "workflow" | "auxiliary" | "compaction" | "side_reply" | "unknown";
6
+ export type AgentRequestContext = {
7
+ requestClass: AgentRequestClass;
8
+ agentId?: string;
9
+ parentAgentId?: string;
10
+ agentType?: string;
11
+ };
12
+ export declare function isBackgroundRequest(request: InteractionRequest): boolean;
13
+ export type InteractionRequestPurpose = "memory_extraction" | "tool_continuation";
14
+ export type InteractionResponseFormat = {
15
+ type: "text";
16
+ } | {
17
+ type: "json_object";
18
+ } | {
19
+ type: "json_schema";
20
+ name: string;
21
+ schema: Record<string, unknown>;
22
+ strict?: boolean;
23
+ description?: string;
24
+ };
25
+ export type InteractionText = {
26
+ type: "text";
27
+ text: string;
28
+ annotations?: Array<Record<string, unknown>>;
29
+ };
30
+ export type InteractionImage = {
31
+ type: "image";
32
+ url: string;
33
+ detail?: "auto" | "low" | "high" | "original";
34
+ };
35
+ export type InteractionToolReference = {
36
+ type: "tool_reference";
37
+ toolName: string;
38
+ };
39
+ export type InteractionContent = InteractionText | InteractionImage | InteractionToolReference;
40
+ export type InteractionMessage = {
41
+ type: "message";
42
+ id?: string;
43
+ clientTurnId?: string;
44
+ role: "system" | "developer" | "user" | "assistant";
45
+ content: InteractionContent[];
46
+ contentShape: "string" | "parts" | "null" | "absent";
47
+ phase?: "commentary" | "final_answer";
48
+ source?: ProviderIdentity;
49
+ };
50
+ export type InteractionReasoning = {
51
+ type: "reasoning";
52
+ id?: string;
53
+ summary: string[];
54
+ content: string[];
55
+ source?: ProviderIdentity;
56
+ continuation?: ProviderContinuationState;
57
+ };
58
+ export type ToolKind = "function" | "custom";
59
+ export type InteractionToolCall = {
60
+ type: "tool_call";
61
+ id?: string;
62
+ callId: string;
63
+ kind: ToolKind;
64
+ name: string;
65
+ namespace?: string;
66
+ input?: string | Record<string, unknown>;
67
+ status?: "in_progress" | "completed" | "incomplete";
68
+ };
69
+ export type InteractionToolResult = {
70
+ type: "tool_result";
71
+ id?: string;
72
+ callId: string;
73
+ kind: ToolKind;
74
+ name?: string;
75
+ output: string | InteractionContent[] | null;
76
+ outputShape: "string" | "parts" | "null" | "absent";
77
+ isError?: boolean;
78
+ loadedTools?: string[];
79
+ };
80
+ export type InteractionReasoningConfiguration = {
81
+ type: "reasoning_configuration";
82
+ effort: ReasoningEffort;
83
+ };
84
+ export type InteractionHostedToolCall = {
85
+ type: "hosted_tool_call";
86
+ id: string;
87
+ tool: "web_search" | "server_tool_use" | "tool_search";
88
+ providerType: "web_search_call" | "server_tool_use" | "tool_search_result";
89
+ status?: "in_progress" | "searching" | "completed" | "incomplete" | "failed";
90
+ payload: Record<string, unknown>;
91
+ source?: ProviderIdentity;
92
+ serverToolUseId?: string;
93
+ serverToolName?: string;
94
+ serverToolInput?: Record<string, unknown>;
95
+ serverToolResult?: InteractionToolReference[];
96
+ };
97
+ export type InteractionItem = InteractionMessage | InteractionReasoning | InteractionToolCall | InteractionToolResult | InteractionReasoningConfiguration | InteractionHostedToolCall;
98
+ export type InteractionOutputItem = InteractionMessage | InteractionReasoning | InteractionToolCall | InteractionHostedToolCall;
99
+ export type ServerToolKind = "bash_20250124" | "text_editor_20250124" | "tool_search_tool_20250919" | "tool_search_tool_regex_20250919" | "tool_search_tool_regex" | "tool_search_tool_regex_20251119" | "tool_search_tool_bm25" | "tool_search_tool_bm25_20251119";
100
+ export type ClientTool = {
101
+ kind: "client_tool";
102
+ name: string;
103
+ type: "bash_20250124" | "text_editor_20250124";
104
+ description?: string;
105
+ };
106
+ export type FunctionTool = {
107
+ kind: "function";
108
+ name: string;
109
+ namespace?: string;
110
+ description?: string;
111
+ parameters?: Record<string, unknown>;
112
+ strict?: boolean;
113
+ deferLoading?: boolean;
114
+ };
115
+ export type CustomTool = {
116
+ kind: "custom";
117
+ name: string;
118
+ namespace?: string;
119
+ description?: string;
120
+ format?: Record<string, unknown>;
121
+ };
122
+ export type HostedTool = {
123
+ kind: "hosted";
124
+ type: "web_search" | "web_search_preview";
125
+ config: Record<string, unknown>;
126
+ };
127
+ export type ServerTool = {
128
+ kind: "server_tool";
129
+ name: string;
130
+ type: ServerToolKind;
131
+ description?: string;
132
+ };
133
+ export type InteractionTool = FunctionTool | CustomTool | HostedTool | ServerTool | ClientTool;
134
+ export type InteractionToolChoice = "none" | "auto" | "required" | "any" | {
135
+ kind: ToolKind;
136
+ name: string;
137
+ namespace?: string;
138
+ } | {
139
+ kind: "hosted";
140
+ type: HostedTool["type"];
141
+ };
142
+ export type GenerationControls = {
143
+ temperature?: number;
144
+ topP?: number;
145
+ maxOutputTokens?: number;
146
+ stop?: string | string[];
147
+ };
148
+ export type ReasoningControls = {
149
+ effort?: ReasoningEffort;
150
+ baseEffort?: ReasoningEffort;
151
+ hasConfigurationUpdate?: boolean;
152
+ enabled?: boolean;
153
+ budgetTokens?: number;
154
+ };
155
+ export type AnthropicSafeguards = {
156
+ safeguards: unknown[];
157
+ betas: string[];
158
+ };
159
+ export type InteractionRequest = {
160
+ sourceProtocol: SourceProtocol;
161
+ requestPurpose?: InteractionRequestPurpose;
162
+ agentContext?: AgentRequestContext;
163
+ claudeCodeUserAgent?: string;
164
+ anthropicSafeguards?: AnthropicSafeguards;
165
+ model?: string;
166
+ instructions?: string;
167
+ items: InteractionItem[];
168
+ tools: InteractionTool[];
169
+ toolChoice?: InteractionToolChoice;
170
+ parallelToolCalls?: boolean;
171
+ generation: GenerationControls;
172
+ reasoning?: ReasoningControls;
173
+ responseFormat?: InteractionResponseFormat;
174
+ promptCacheKey?: string;
175
+ stream: boolean;
176
+ metadata?: Record<string, unknown>;
177
+ user?: string;
178
+ };
179
+ export type InteractionUsage = {
180
+ input: number;
181
+ output: number;
182
+ cacheRead: number;
183
+ cacheWrite: number;
184
+ totalTokens: number;
185
+ cost: {
186
+ input: number;
187
+ output: number;
188
+ cacheRead: number;
189
+ cacheWrite: number;
190
+ total: number;
191
+ };
192
+ costSource?: "provider";
193
+ };
194
+ export type InteractionOutput = {
195
+ responseId?: string;
196
+ createdAtMs: number;
197
+ source: ProviderIdentity;
198
+ items: InteractionOutputItem[];
199
+ usage: InteractionUsage;
200
+ stopReason: "stop" | "length" | "tool_use" | "error" | "aborted";
201
+ errorMessage?: string;
202
+ safeguardResults?: unknown[];
203
+ };
@@ -0,0 +1,5 @@
1
+ export function isBackgroundRequest(request) {
2
+ return request.agentContext?.requestClass === "auxiliary"
3
+ || request.agentContext?.requestClass === "compaction"
4
+ || request.agentContext?.requestClass === "side_reply";
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { ResolvedRouterModelConfig } from "../types.js";
2
+ export declare function effectiveContextWindow(config: ResolvedRouterModelConfig | undefined, allowLongContext?: boolean): number | null;
@@ -0,0 +1,7 @@
1
+ export function effectiveContextWindow(config, allowLongContext = false) {
2
+ const window = config?.context_window;
3
+ const limit = config?.standard_context_limit;
4
+ if (allowLongContext || limit == null)
5
+ return window ?? null;
6
+ return Math.min(window ?? limit, limit);
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { ProviderKeySource, ResolvedRouter } from "../types.js";
2
+ /** Actual serving provider for a canonical model on a resolved managed router. */
3
+ export declare function executionProviderForModel(credentials: ResolvedRouter, model: string): string;
4
+ /**
5
+ * The key that serves a model on a resolved router. Missing declarations are
6
+ * user-owned so unknown platform data cannot trigger managed-key billing.
7
+ */
8
+ export declare function keySourceForModel(credentials: ResolvedRouter, model: string): ProviderKeySource;
@@ -0,0 +1,13 @@
1
+ import { providerForModel } from "@mupt-ai/dari-router/policy-engine";
2
+ /** Actual serving provider for a canonical model on a resolved managed router. */
3
+ export function executionProviderForModel(credentials, model) {
4
+ const configured = credentials.model_configs?.[model]?.provider?.trim();
5
+ return configured || providerForModel(model);
6
+ }
7
+ /**
8
+ * The key that serves a model on a resolved router. Missing declarations are
9
+ * user-owned so unknown platform data cannot trigger managed-key billing.
10
+ */
11
+ export function keySourceForModel(credentials, model) {
12
+ return credentials.provider_key_sources?.[executionProviderForModel(credentials, model)] ?? "user";
13
+ }
@@ -0,0 +1,11 @@
1
+ export type Gateway = {
2
+ label: string;
3
+ baseUrl: string;
4
+ compat: Record<string, unknown>;
5
+ requestFields(options: {
6
+ zdr: boolean;
7
+ }): Record<string, unknown>;
8
+ };
9
+ export declare function gatewayFor(provider: unknown): Gateway | undefined;
10
+ /** Deep-merges gateway routing fields into a provider request body. */
11
+ export declare function payloadWithGatewayFields(payload: Record<string, unknown>, fields: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,45 @@
1
+ import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
+ function gateway(spec) {
3
+ return { ...spec, compat: { thinkingFormat: "openrouter", ...spec.compat } };
4
+ }
5
+ const GATEWAYS = {
6
+ openrouter: gateway({
7
+ label: "OpenRouter",
8
+ baseUrl: "https://openrouter.ai/api/v1",
9
+ requestFields: ({ zdr }) => zdr ? { provider: { data_collection: "deny", zdr: true } } : {},
10
+ }),
11
+ // https://vercel.com/docs/ai-gateway/models-and-providers/provider-options
12
+ "vercel-ai-gateway": gateway({
13
+ label: "Vercel AI Gateway",
14
+ baseUrl: "https://ai-gateway.vercel.sh/v1",
15
+ // Pi detects OpenRouter's role, caching, and session conventions from its
16
+ // URL but not Vercel's: the system role reaches every upstream, and
17
+ // x-session-affinity keeps prompt-cache locality.
18
+ compat: {
19
+ supportsDeveloperRole: false,
20
+ sendSessionAffinityHeaders: true,
21
+ sessionAffinityFormat: "openai",
22
+ },
23
+ // Vercel passes requests through untouched unless asked to place the
24
+ // cache breakpoints Anthropic models need.
25
+ requestFields: ({ zdr }) => ({
26
+ providerOptions: {
27
+ gateway: { caching: "auto", ...(zdr ? { zeroDataRetention: true } : {}) },
28
+ },
29
+ }),
30
+ }),
31
+ };
32
+ export function gatewayFor(provider) {
33
+ return typeof provider === "string" ? GATEWAYS[provider.toLowerCase()] : undefined;
34
+ }
35
+ /** Deep-merges gateway routing fields into a provider request body. */
36
+ export function payloadWithGatewayFields(payload, fields) {
37
+ const merged = { ...payload };
38
+ for (const [key, value] of Object.entries(fields)) {
39
+ const current = merged[key];
40
+ merged[key] = isRecord(current) && isRecord(value)
41
+ ? payloadWithGatewayFields(current, value)
42
+ : value;
43
+ }
44
+ return merged;
45
+ }
@@ -0,0 +1 @@
1
+ export declare function requireCandidateModels(value: unknown): string[];
@@ -0,0 +1,15 @@
1
+ import { providerForModel } from "@mupt-ai/dari-router/policy-engine";
2
+ import { HttpError } from "../http/errors.js";
3
+ export function requireCandidateModels(value) {
4
+ if (!Array.isArray(value) || value.length === 0) {
5
+ throw new HttpError(400, "routing.candidate_models must include at least one model.", "invalid_routing_request", "routing.candidate_models");
6
+ }
7
+ const candidates = value.map((item, index) => {
8
+ if (typeof item !== "string" || item.trim() === "") {
9
+ throw new HttpError(400, "routing.candidate_models must contain non-empty strings.", "invalid_routing_request", `routing.candidate_models[${index}]`);
10
+ }
11
+ providerForModel(item);
12
+ return item;
13
+ });
14
+ return [...new Set(candidates)];
15
+ }
@@ -0,0 +1,4 @@
1
+ /** Display label for a provider slug; custom slugs title-case per segment. */
2
+ export declare function providerLabel(provider: string): string;
3
+ /** Endpoint fallback when neither the resolved config nor the registry has one. */
4
+ export declare function defaultBaseUrl(provider: string): string | null;
@@ -0,0 +1,41 @@
1
+ import { gatewayFor } from "./gateways.js";
2
+ // Built-in model provider presentation and endpoint defaults; gateways carry
3
+ // their own. Mirrors the hosted Dari model catalog's provider defaults; keep
4
+ // the two in sync when adding a provider.
5
+ const PROVIDER_LABELS = {
6
+ openai: "OpenAI",
7
+ anthropic: "Anthropic",
8
+ fireworks: "Fireworks",
9
+ meta: "Meta",
10
+ xai: "xAI",
11
+ dari: "Dari",
12
+ "amazon-bedrock": "Amazon Bedrock",
13
+ azure: "Microsoft Azure",
14
+ };
15
+ /** Display label for a provider slug; custom slugs title-case per segment. */
16
+ export function providerLabel(provider) {
17
+ const known = PROVIDER_LABELS[provider.toLowerCase()] ?? gatewayFor(provider)?.label;
18
+ if (known)
19
+ return known;
20
+ return (provider
21
+ .split(/[._-]+/)
22
+ .filter(Boolean)
23
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
24
+ .join(" ") || provider);
25
+ }
26
+ const PROVIDER_BASE_URLS = {
27
+ openai: "https://api.openai.com/v1",
28
+ anthropic: "https://api.anthropic.com",
29
+ fireworks: "https://api.fireworks.ai/inference/v1",
30
+ xai: "https://api.x.ai/v1",
31
+ // Pi-ai derives the effective AWS region from the endpoint unless the
32
+ // model config overrides base_url or the native id is an inference profile
33
+ // ARN, so this default only pins us-east-1 when nothing else is configured.
34
+ "amazon-bedrock": "https://bedrock-runtime.us-east-1.amazonaws.com",
35
+ // Microsoft Azure has no default: the platform derives each model's base
36
+ // URL from the credential's resource endpoint at resolve time.
37
+ };
38
+ /** Endpoint fallback when neither the resolved config nor the registry has one. */
39
+ export function defaultBaseUrl(provider) {
40
+ return PROVIDER_BASE_URLS[provider.toLowerCase()] ?? gatewayFor(provider)?.baseUrl ?? null;
41
+ }
@@ -0,0 +1,4 @@
1
+ export declare function offRequiresWireNone(modelId: string): boolean;
2
+ export declare function contextWindowOverride(modelId: string): number | undefined;
3
+ export declare function inputModalitiesOverride(modelId: string): string[] | undefined;
4
+ export declare function runtimeCompat(provider: string, registered: Record<string, unknown> | undefined, modelId?: string): unknown;
@@ -0,0 +1,209 @@
1
+ import { canonicalModelId, isRecord } from "@mupt-ai/dari-router/policy-engine";
2
+ import { gatewayFor } from "./gateways.js";
3
+ const MODEL_CONTEXT_OVERRIDES = {
4
+ // Selector and title models are not router candidate configs, so their
5
+ // context windows cannot depend on the Pi registry carrying them.
6
+ "openai/gpt-5.6-luna": 1_050_000,
7
+ "openai/gpt-6-luna": 1_050_000,
8
+ };
9
+ // Models whose true non-reasoning mode is the provider-literal effort "none"
10
+ // rather than omitting the field. Live-validated: Fireworks DeepSeek thinks
11
+ // by default when the request carries no reasoning_effort (and pi-ai's
12
+ // completions path drops Dari's "off" before serializing), so a client's
13
+ // explicit off must be injected into the provider payload as
14
+ // reasoning_effort "none" (verified quiet: ~2 output tokens vs ~40 thinking).
15
+ // OpenAI gpt-5.x models need no entry: the pi-ai registry already maps their
16
+ // "off" to wire "none".
17
+ // Models whose catalog metadata is not yet bundled in the installed Pi registry
18
+ // but need explicit compat overrides to produce correct provider payloads.
19
+ const MODEL_COMPAT_OVERRIDES = {
20
+ // The Pi registry does not carry Fable 5.1, Opus 5.5, Sonnet 5.5, and Opus 5's
21
+ // adaptive-thinking compatibility for every serving provider (OpenRouter,
22
+ // Bedrock), so it is declared here. Sonnet 5 is in the Pi
23
+ // registry (with forceAdaptiveThinking), but it's missing supportsTemperature
24
+ // (the Anthropic docs confirm non-default temperature returns 400).
25
+ "anthropic/claude-fable-5-1": {
26
+ forceAdaptiveThinking: true,
27
+ supportsTemperature: false,
28
+ },
29
+ "anthropic/claude-opus-5-5": {
30
+ forceAdaptiveThinking: true,
31
+ supportsTemperature: false,
32
+ supportsMidConvoEffort: true,
33
+ },
34
+ "anthropic/claude-opus-5": {
35
+ forceAdaptiveThinking: true,
36
+ supportsTemperature: false,
37
+ },
38
+ "anthropic/claude-sonnet-5-5": {
39
+ forceAdaptiveThinking: true,
40
+ supportsTemperature: false,
41
+ supportsMidConvoEffort: true,
42
+ },
43
+ "anthropic/claude-sonnet-5": {
44
+ supportsTemperature: false,
45
+ },
46
+ "anthropic/claude-haiku-5-5": {
47
+ forceAdaptiveThinking: true,
48
+ supportsTemperature: false,
49
+ },
50
+ // GPT-6 Astra always reasons and OpenAI rejects temperature on it (400
51
+ // "Unsupported parameter: 'temperature'"), on api.openai.com and on Azure
52
+ // alike. The OpenAI transports do not read this flag themselves, so
53
+ // buildOptions drops the parameter. Live-validated 2026-09-15.
54
+ "openai/gpt-6-astra": {
55
+ supportsTemperature: false,
56
+ },
57
+ // GPT-6 Sol and Luna are newer than the installed Pi registry. They retain
58
+ // the GPT-5.6 Responses feature set, including explicit prompt caching and
59
+ // deferred tool loading. Keep this local until Pi ships their metadata.
60
+ "openai/gpt-6.1-sol": {
61
+ supportsStrictMode: true,
62
+ supportsOpenAIGrammarTools: true,
63
+ supportsAdditionalTools: true,
64
+ supportsToolSearch: true,
65
+ supportsExplicitPromptCacheMode: true,
66
+ supportsReasoningConfigurationUpdate: true,
67
+ },
68
+ "openai/gpt-6-sol": {
69
+ supportsStrictMode: true,
70
+ supportsOpenAIGrammarTools: true,
71
+ supportsAdditionalTools: true,
72
+ supportsToolSearch: true,
73
+ supportsExplicitPromptCacheMode: true,
74
+ supportsReasoningConfigurationUpdate: true,
75
+ },
76
+ "openai/gpt-6-luna": {
77
+ supportsStrictMode: true,
78
+ supportsOpenAIGrammarTools: true,
79
+ supportsAdditionalTools: true,
80
+ supportsToolSearch: true,
81
+ supportsExplicitPromptCacheMode: true,
82
+ supportsReasoningConfigurationUpdate: true,
83
+ },
84
+ // Kimi K3 is not in the installed Pi registry under the Fireworks provider.
85
+ // Fireworks returns preserved thinking in reasoning_content and accepts the
86
+ // model's documented low/high/max reasoning_effort values.
87
+ "moonshotai/Kimi-K3": {
88
+ thinkingFormat: "deepseek",
89
+ supportsReasoningEffort: true,
90
+ requiresReasoningContentOnAssistantMessages: true,
91
+ },
92
+ // DeepSeek V4 Flash 0731 is not in the installed Pi registry (new model),
93
+ // so it needs the same compat overrides as Kimi K3 for correct deepseek-
94
+ // format response parsing and multi-turn reasoning continuity.
95
+ "deepseek-ai/DeepSeek-V4-Flash-0731": {
96
+ thinkingFormat: "deepseek",
97
+ supportsReasoningEffort: true,
98
+ requiresReasoningContentOnAssistantMessages: true,
99
+ },
100
+ "deepseek-ai/DeepSeek-V4.1-Flash-1017": {
101
+ thinkingFormat: "deepseek",
102
+ supportsReasoningEffort: true,
103
+ requiresReasoningContentOnAssistantMessages: true,
104
+ },
105
+ };
106
+ // Serving-provider specific compat that replaces the model-level override
107
+ // above. Microsoft Foundry serves DeepSeek through its own OpenAI-compatible
108
+ // endpoint: the `thinking` parameter the deepseek thinking format sends is
109
+ // rejected (400 unrecognized_request_argument), plain reasoning_effort
110
+ // (none/low/high/max) is accepted, and reasoning comes back in
111
+ // reasoning_content. Grok on Foundry takes reasoning_effort the same way.
112
+ // Live-validated against a Foundry resource on 2026-09-15.
113
+ const PROVIDER_MODEL_COMPAT_OVERRIDES = {
114
+ azure: {
115
+ "deepseek-ai/DeepSeek-V4-Flash-0731": {
116
+ supportsReasoningEffort: true,
117
+ requiresReasoningContentOnAssistantMessages: true,
118
+ },
119
+ "xai/grok-4.6": {
120
+ supportsReasoningEffort: true,
121
+ },
122
+ "xai/grok-4.7": {
123
+ supportsReasoningEffort: true,
124
+ },
125
+ },
126
+ };
127
+ // Compat keys that describe a model's native reasoning wire format, which a
128
+ // gateway replaces with its own.
129
+ const NATIVE_REASONING_COMPAT_KEYS = new Set([
130
+ "thinkingFormat",
131
+ "supportsReasoningEffort",
132
+ "requiresReasoningContentOnAssistantMessages",
133
+ ]);
134
+ // Models whose input modalities are not detectable from the Pi registry.
135
+ // GPT-5.6 is registered for Bedrock only under the unprefixed
136
+ // "openai.gpt-5.6-*" ids; Dari executes the "us." inference profiles, which
137
+ // miss the registry and would otherwise be pruned as text-only.
138
+ const MODEL_INPUT_OVERRIDES = {
139
+ "anthropic/claude-haiku-5-5": ["text", "image"],
140
+ "anthropic/claude-sonnet-5-5": ["text", "image"],
141
+ "openai/gpt-6.1-sol": ["text", "image"],
142
+ "openai/gpt-6-sol": ["text", "image"],
143
+ "openai/gpt-6-luna": ["text", "image"],
144
+ "openai/gpt-5.6-luna": ["text", "image"],
145
+ "openai/gpt-5.6-sol": ["text", "image"],
146
+ "openai/gpt-5.6-terra": ["text", "image"],
147
+ "openai/gpt-6-astra": ["text", "image"],
148
+ "moonshotai/Kimi-K3": ["text", "image"],
149
+ "deepseek-ai/DeepSeek-V4.1-Flash-1017": ["text", "image"],
150
+ "zai-org/GLM-5.3-Flash": ["text", "image"],
151
+ // Grok 4.6 and 4.7 are registered for xAI's Responses API only; Foundry
152
+ // serves them through chat completions with the same text and image input.
153
+ "xai/grok-4.6": ["text", "image"],
154
+ "xai/grok-4.7": ["text", "image"],
155
+ };
156
+ const MODEL_OFF_WIRE_NONE = new Set([
157
+ // No longer bundled under Fireworks in Pi 1.1; preserve explicit off.
158
+ "zai-org/GLM-5.2",
159
+ "deepseek-ai/DeepSeek-V4-Pro-0813",
160
+ "fireworks/deepseek-ai/DeepSeek-V4-Flash",
161
+ "deepseek-ai/DeepSeek-V4-Flash-0731",
162
+ "deepseek-ai/DeepSeek-V4.1-Flash-1017",
163
+ ]);
164
+ export function offRequiresWireNone(modelId) {
165
+ return MODEL_OFF_WIRE_NONE.has(canonicalModelId(modelId));
166
+ }
167
+ export function contextWindowOverride(modelId) {
168
+ return MODEL_CONTEXT_OVERRIDES[canonicalModelId(modelId)];
169
+ }
170
+ export function inputModalitiesOverride(modelId) {
171
+ return MODEL_INPUT_OVERRIDES[canonicalModelId(modelId)];
172
+ }
173
+ export function runtimeCompat(provider, registered, modelId) {
174
+ const canonical = modelId ? canonicalModelId(modelId) : undefined;
175
+ const compatOverride = canonical
176
+ ? PROVIDER_MODEL_COMPAT_OVERRIDES[provider]?.[canonical] ?? MODEL_COMPAT_OVERRIDES[canonical]
177
+ : undefined;
178
+ const gateway = gatewayFor(provider);
179
+ if (gateway) {
180
+ // A gateway's own dialect decides how reasoning goes over the wire, so
181
+ // the model overrides' native reasoning settings do not apply.
182
+ const modelOverride = Object.fromEntries(Object.entries(compatOverride ?? {}).filter(([key]) => !NATIVE_REASONING_COMPAT_KEYS.has(key)));
183
+ return {
184
+ ...(isRecord(registered?.compat) ? registered.compat : {}),
185
+ ...modelOverride,
186
+ ...gateway.compat,
187
+ };
188
+ }
189
+ if (provider !== "fireworks") {
190
+ if (compatOverride === undefined)
191
+ return registered?.compat;
192
+ return {
193
+ ...(isRecord(registered?.compat) ? registered.compat : {}),
194
+ ...compatOverride,
195
+ };
196
+ }
197
+ // Fireworks needs two compat defaults pi-ai does not detect for it:
198
+ // serverless cache hits ride on session-affinity headers pi-ai only sends
199
+ // when compat asks for them, and several Fireworks chat templates (e.g.
200
+ // DeepSeek) silently drop developer-role messages, so system prompts must
201
+ // go out under the system role. Registry-declared compat keys still win,
202
+ // and per-model overrides win over both for models the registry omits.
203
+ return {
204
+ sendSessionAffinityHeaders: true,
205
+ supportsDeveloperRole: false,
206
+ ...(isRecord(registered?.compat) ? registered.compat : {}),
207
+ ...compatOverride,
208
+ };
209
+ }