@ny4n/ai 0.0.0-stage → 1.0.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 (821) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1940 -2
  3. package/dist/api/anthropic-messages.d.ts +71 -0
  4. package/dist/api/anthropic-messages.d.ts.map +1 -0
  5. package/dist/api/anthropic-messages.js +1310 -0
  6. package/dist/api/anthropic-messages.js.map +1 -0
  7. package/dist/api/anthropic-messages.lazy.d.ts +3 -0
  8. package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
  9. package/dist/api/anthropic-messages.lazy.js +3 -0
  10. package/dist/api/anthropic-messages.lazy.js.map +1 -0
  11. package/dist/api/azure-openai-config.d.ts +15 -0
  12. package/dist/api/azure-openai-config.d.ts.map +1 -0
  13. package/dist/api/azure-openai-config.js +76 -0
  14. package/dist/api/azure-openai-config.js.map +1 -0
  15. package/dist/api/azure-openai-responses.d.ts +14 -0
  16. package/dist/api/azure-openai-responses.d.ts.map +1 -0
  17. package/dist/api/azure-openai-responses.js +194 -0
  18. package/dist/api/azure-openai-responses.js.map +1 -0
  19. package/dist/api/azure-openai-responses.lazy.d.ts +3 -0
  20. package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -0
  21. package/dist/api/azure-openai-responses.lazy.js +3 -0
  22. package/dist/api/azure-openai-responses.lazy.js.map +1 -0
  23. package/dist/api/bedrock-converse-stream.d.ts +38 -0
  24. package/dist/api/bedrock-converse-stream.d.ts.map +1 -0
  25. package/dist/api/bedrock-converse-stream.js +1147 -0
  26. package/dist/api/bedrock-converse-stream.js.map +1 -0
  27. package/dist/api/bedrock-converse-stream.lazy.d.ts +9 -0
  28. package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
  29. package/dist/api/bedrock-converse-stream.lazy.js +30 -0
  30. package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
  31. package/dist/api/classifier-shared.d.ts +21 -0
  32. package/dist/api/classifier-shared.d.ts.map +1 -0
  33. package/dist/api/classifier-shared.js +98 -0
  34. package/dist/api/classifier-shared.js.map +1 -0
  35. package/dist/api/cloudflare-ai-binding.d.ts +77 -0
  36. package/dist/api/cloudflare-ai-binding.d.ts.map +1 -0
  37. package/dist/api/cloudflare-ai-binding.js +72 -0
  38. package/dist/api/cloudflare-ai-binding.js.map +1 -0
  39. package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
  40. package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -0
  41. package/dist/api/cloudflare-workers-ai-system-one.js +49 -0
  42. package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -0
  43. package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts +3 -0
  44. package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts.map +1 -0
  45. package/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
  46. package/dist/api/cloudflare-workers-ai-system-one.lazy.js.map +1 -0
  47. package/dist/api/cloudflare.d.ts +11 -0
  48. package/dist/api/cloudflare.d.ts.map +1 -0
  49. package/dist/api/cloudflare.js +11 -0
  50. package/dist/api/cloudflare.js.map +1 -0
  51. package/dist/api/constrained-sampling.d.ts +26 -0
  52. package/dist/api/constrained-sampling.d.ts.map +1 -0
  53. package/dist/api/constrained-sampling.js +233 -0
  54. package/dist/api/constrained-sampling.js.map +1 -0
  55. package/dist/api/github-copilot-headers.d.ts +8 -0
  56. package/dist/api/github-copilot-headers.d.ts.map +1 -0
  57. package/dist/api/github-copilot-headers.js +29 -0
  58. package/dist/api/github-copilot-headers.js.map +1 -0
  59. package/dist/api/google-generative-ai.d.ts +13 -0
  60. package/dist/api/google-generative-ai.d.ts.map +1 -0
  61. package/dist/api/google-generative-ai.js +370 -0
  62. package/dist/api/google-generative-ai.js.map +1 -0
  63. package/dist/api/google-generative-ai.lazy.d.ts +3 -0
  64. package/dist/api/google-generative-ai.lazy.d.ts.map +1 -0
  65. package/dist/api/google-generative-ai.lazy.js +3 -0
  66. package/dist/api/google-generative-ai.lazy.js.map +1 -0
  67. package/dist/api/google-shared.d.ts +93 -0
  68. package/dist/api/google-shared.d.ts.map +1 -0
  69. package/dist/api/google-shared.js +451 -0
  70. package/dist/api/google-shared.js.map +1 -0
  71. package/dist/api/google-vertex.d.ts +15 -0
  72. package/dist/api/google-vertex.d.ts.map +1 -0
  73. package/dist/api/google-vertex.js +431 -0
  74. package/dist/api/google-vertex.js.map +1 -0
  75. package/dist/api/google-vertex.lazy.d.ts +3 -0
  76. package/dist/api/google-vertex.lazy.d.ts.map +1 -0
  77. package/dist/api/google-vertex.lazy.js +3 -0
  78. package/dist/api/google-vertex.lazy.js.map +1 -0
  79. package/dist/api/lazy.d.ts +19 -0
  80. package/dist/api/lazy.d.ts.map +1 -0
  81. package/dist/api/lazy.js +71 -0
  82. package/dist/api/lazy.js.map +1 -0
  83. package/dist/api/llama-cpp-classify.d.ts +33 -0
  84. package/dist/api/llama-cpp-classify.d.ts.map +1 -0
  85. package/dist/api/llama-cpp-classify.js +367 -0
  86. package/dist/api/llama-cpp-classify.js.map +1 -0
  87. package/dist/api/llama-cpp-classify.lazy.d.ts +3 -0
  88. package/dist/api/llama-cpp-classify.lazy.d.ts.map +1 -0
  89. package/dist/api/llama-cpp-classify.lazy.js +4 -0
  90. package/dist/api/llama-cpp-classify.lazy.js.map +1 -0
  91. package/dist/api/mistral-conversations.d.ts +25 -0
  92. package/dist/api/mistral-conversations.d.ts.map +1 -0
  93. package/dist/api/mistral-conversations.js +766 -0
  94. package/dist/api/mistral-conversations.js.map +1 -0
  95. package/dist/api/mistral-conversations.lazy.d.ts +3 -0
  96. package/dist/api/mistral-conversations.lazy.d.ts.map +1 -0
  97. package/dist/api/mistral-conversations.lazy.js +3 -0
  98. package/dist/api/mistral-conversations.lazy.js.map +1 -0
  99. package/dist/api/openai-codex-responses.d.ts +31 -0
  100. package/dist/api/openai-codex-responses.d.ts.map +1 -0
  101. package/dist/api/openai-codex-responses.js +1321 -0
  102. package/dist/api/openai-codex-responses.js.map +1 -0
  103. package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
  104. package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
  105. package/dist/api/openai-codex-responses.lazy.js +3 -0
  106. package/dist/api/openai-codex-responses.lazy.js.map +1 -0
  107. package/dist/api/openai-completions.d.ts +26 -0
  108. package/dist/api/openai-completions.d.ts.map +1 -0
  109. package/dist/api/openai-completions.js +1345 -0
  110. package/dist/api/openai-completions.js.map +1 -0
  111. package/dist/api/openai-completions.lazy.d.ts +3 -0
  112. package/dist/api/openai-completions.lazy.d.ts.map +1 -0
  113. package/dist/api/openai-completions.lazy.js +3 -0
  114. package/dist/api/openai-completions.lazy.js.map +1 -0
  115. package/dist/api/openai-decisions.d.ts +4 -0
  116. package/dist/api/openai-decisions.d.ts.map +1 -0
  117. package/dist/api/openai-decisions.js +162 -0
  118. package/dist/api/openai-decisions.js.map +1 -0
  119. package/dist/api/openai-decisions.lazy.d.ts +3 -0
  120. package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
  121. package/dist/api/openai-decisions.lazy.js +4 -0
  122. package/dist/api/openai-decisions.lazy.js.map +1 -0
  123. package/dist/api/openai-prompt-cache.d.ts +3 -0
  124. package/dist/api/openai-prompt-cache.d.ts.map +1 -0
  125. package/dist/api/openai-prompt-cache.js +10 -0
  126. package/dist/api/openai-prompt-cache.js.map +1 -0
  127. package/dist/api/openai-responses-shared.d.ts +29 -0
  128. package/dist/api/openai-responses-shared.d.ts.map +1 -0
  129. package/dist/api/openai-responses-shared.js +704 -0
  130. package/dist/api/openai-responses-shared.js.map +1 -0
  131. package/dist/api/openai-responses.d.ts +14 -0
  132. package/dist/api/openai-responses.d.ts.map +1 -0
  133. package/dist/api/openai-responses.js +314 -0
  134. package/dist/api/openai-responses.js.map +1 -0
  135. package/dist/api/openai-responses.lazy.d.ts +3 -0
  136. package/dist/api/openai-responses.lazy.d.ts.map +1 -0
  137. package/dist/api/openai-responses.lazy.js +3 -0
  138. package/dist/api/openai-responses.lazy.js.map +1 -0
  139. package/dist/api/openrouter-images.d.ts +4 -0
  140. package/dist/api/openrouter-images.d.ts.map +1 -0
  141. package/dist/api/openrouter-images.js +133 -0
  142. package/dist/api/openrouter-images.js.map +1 -0
  143. package/dist/api/openrouter-images.lazy.d.ts +3 -0
  144. package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
  145. package/dist/api/openrouter-images.lazy.js +4 -0
  146. package/dist/api/openrouter-images.lazy.js.map +1 -0
  147. package/dist/api/simple-options.d.ts +16 -0
  148. package/dist/api/simple-options.d.ts.map +1 -0
  149. package/dist/api/simple-options.js +73 -0
  150. package/dist/api/simple-options.js.map +1 -0
  151. package/dist/api/system-one-shared.d.ts +22 -0
  152. package/dist/api/system-one-shared.d.ts.map +1 -0
  153. package/dist/api/system-one-shared.js +99 -0
  154. package/dist/api/system-one-shared.js.map +1 -0
  155. package/dist/api/transform-messages.d.ts +8 -0
  156. package/dist/api/transform-messages.d.ts.map +1 -0
  157. package/dist/api/transform-messages.js +201 -0
  158. package/dist/api/transform-messages.js.map +1 -0
  159. package/dist/api/typesafe-system-one.d.ts +4 -0
  160. package/dist/api/typesafe-system-one.d.ts.map +1 -0
  161. package/dist/api/typesafe-system-one.js +20 -0
  162. package/dist/api/typesafe-system-one.js.map +1 -0
  163. package/dist/api/typesafe-system-one.lazy.d.ts +3 -0
  164. package/dist/api/typesafe-system-one.lazy.d.ts.map +1 -0
  165. package/dist/api/typesafe-system-one.lazy.js +4 -0
  166. package/dist/api/typesafe-system-one.lazy.js.map +1 -0
  167. package/dist/api-options.d.ts +39 -0
  168. package/dist/api-options.d.ts.map +1 -0
  169. package/dist/api-options.js +9 -0
  170. package/dist/api-options.js.map +1 -0
  171. package/dist/auth/context.d.ts +7 -0
  172. package/dist/auth/context.d.ts.map +1 -0
  173. package/dist/auth/context.js +42 -0
  174. package/dist/auth/context.js.map +1 -0
  175. package/dist/auth/credential-store.d.ts +17 -0
  176. package/dist/auth/credential-store.d.ts.map +1 -0
  177. package/dist/auth/credential-store.js +51 -0
  178. package/dist/auth/credential-store.js.map +1 -0
  179. package/dist/auth/helpers.d.ts +22 -0
  180. package/dist/auth/helpers.d.ts.map +1 -0
  181. package/dist/auth/helpers.js +53 -0
  182. package/dist/auth/helpers.js.map +1 -0
  183. package/dist/auth/oauth/anthropic.d.ts +9 -0
  184. package/dist/auth/oauth/anthropic.d.ts.map +1 -0
  185. package/dist/auth/oauth/anthropic.js +257 -0
  186. package/dist/auth/oauth/anthropic.js.map +1 -0
  187. package/dist/auth/oauth/callback-server.d.ts +55 -0
  188. package/dist/auth/oauth/callback-server.d.ts.map +1 -0
  189. package/dist/auth/oauth/callback-server.js +146 -0
  190. package/dist/auth/oauth/callback-server.js.map +1 -0
  191. package/dist/auth/oauth/device-code.d.ts +24 -0
  192. package/dist/auth/oauth/device-code.d.ts.map +1 -0
  193. package/dist/auth/oauth/device-code.js +69 -0
  194. package/dist/auth/oauth/device-code.js.map +1 -0
  195. package/dist/auth/oauth/github-copilot.d.ts +6 -0
  196. package/dist/auth/oauth/github-copilot.d.ts.map +1 -0
  197. package/dist/auth/oauth/github-copilot.js +392 -0
  198. package/dist/auth/oauth/github-copilot.js.map +1 -0
  199. package/dist/auth/oauth/kimi-coding.d.ts +10 -0
  200. package/dist/auth/oauth/kimi-coding.d.ts.map +1 -0
  201. package/dist/auth/oauth/kimi-coding.js +248 -0
  202. package/dist/auth/oauth/kimi-coding.js.map +1 -0
  203. package/dist/auth/oauth/load.d.ts +23 -0
  204. package/dist/auth/oauth/load.d.ts.map +1 -0
  205. package/dist/auth/oauth/load.js +64 -0
  206. package/dist/auth/oauth/load.js.map +1 -0
  207. package/dist/auth/oauth/meta.d.ts +17 -0
  208. package/dist/auth/oauth/meta.d.ts.map +1 -0
  209. package/dist/auth/oauth/meta.js +190 -0
  210. package/dist/auth/oauth/meta.js.map +1 -0
  211. package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
  212. package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
  213. package/dist/auth/oauth/openai-chatgpt.js +263 -0
  214. package/dist/auth/oauth/openai-chatgpt.js.map +1 -0
  215. package/dist/auth/oauth/openai-codex.d.ts +9 -0
  216. package/dist/auth/oauth/openai-codex.d.ts.map +1 -0
  217. package/dist/auth/oauth/openai-codex.js +346 -0
  218. package/dist/auth/oauth/openai-codex.js.map +1 -0
  219. package/dist/auth/oauth/openrouter.d.ts +15 -0
  220. package/dist/auth/oauth/openrouter.d.ts.map +1 -0
  221. package/dist/auth/oauth/openrouter.js +158 -0
  222. package/dist/auth/oauth/openrouter.js.map +1 -0
  223. package/dist/auth/oauth/pkce.d.ts +13 -0
  224. package/dist/auth/oauth/pkce.d.ts.map +1 -0
  225. package/dist/auth/oauth/pkce.js +31 -0
  226. package/dist/auth/oauth/pkce.js.map +1 -0
  227. package/dist/auth/oauth/xai.d.ts +6 -0
  228. package/dist/auth/oauth/xai.d.ts.map +1 -0
  229. package/dist/auth/oauth/xai.js +190 -0
  230. package/dist/auth/oauth/xai.js.map +1 -0
  231. package/dist/auth/resolve.d.ts +36 -0
  232. package/dist/auth/resolve.d.ts.map +1 -0
  233. package/dist/auth/resolve.js +140 -0
  234. package/dist/auth/resolve.js.map +1 -0
  235. package/dist/auth/types.d.ts +245 -0
  236. package/dist/auth/types.d.ts.map +1 -0
  237. package/dist/auth/types.js +2 -0
  238. package/dist/auth/types.js.map +1 -0
  239. package/dist/bedrock-provider.d.ts +5 -0
  240. package/dist/bedrock-provider.d.ts.map +1 -0
  241. package/dist/bedrock-provider.js +6 -0
  242. package/dist/bedrock-provider.js.map +1 -0
  243. package/dist/bun-oauth.d.ts +6 -0
  244. package/dist/bun-oauth.d.ts.map +1 -0
  245. package/dist/bun-oauth.js +26 -0
  246. package/dist/bun-oauth.js.map +1 -0
  247. package/dist/cli.d.ts +3 -0
  248. package/dist/cli.d.ts.map +1 -0
  249. package/dist/cli.js +115 -0
  250. package/dist/cli.js.map +1 -0
  251. package/dist/compat/extension-oauth-types.d.ts +39 -0
  252. package/dist/compat/extension-oauth-types.d.ts.map +1 -0
  253. package/dist/compat/extension-oauth-types.js +2 -0
  254. package/dist/compat/extension-oauth-types.js.map +1 -0
  255. package/dist/compat.d.ts +66 -0
  256. package/dist/compat.d.ts.map +1 -0
  257. package/dist/compat.js +199 -0
  258. package/dist/compat.js.map +1 -0
  259. package/dist/contracts/index.d.ts +30 -0
  260. package/dist/contracts/index.d.ts.map +1 -0
  261. package/dist/contracts/index.js +12 -0
  262. package/dist/contracts/index.js.map +1 -0
  263. package/dist/env-api-keys.d.ts +26 -0
  264. package/dist/env-api-keys.d.ts.map +1 -0
  265. package/dist/env-api-keys.js +162 -0
  266. package/dist/env-api-keys.js.map +1 -0
  267. package/dist/image-models.d.ts +21 -0
  268. package/dist/image-models.d.ts.map +1 -0
  269. package/dist/image-models.js +24 -0
  270. package/dist/image-models.js.map +1 -0
  271. package/dist/images-api-registry.d.ts +14 -0
  272. package/dist/images-api-registry.d.ts.map +1 -0
  273. package/dist/images-api-registry.js +22 -0
  274. package/dist/images-api-registry.js.map +1 -0
  275. package/dist/images.d.ts +9 -0
  276. package/dist/images.d.ts.map +1 -0
  277. package/dist/images.js +19 -0
  278. package/dist/images.js.map +1 -0
  279. package/dist/index.d.ts +36 -0
  280. package/dist/index.d.ts.map +1 -0
  281. package/dist/index.js +24 -0
  282. package/dist/index.js.map +1 -0
  283. package/dist/legacy-api-aliases.d.ts +42 -0
  284. package/dist/legacy-api-aliases.d.ts.map +1 -0
  285. package/dist/legacy-api-aliases.js +49 -0
  286. package/dist/legacy-api-aliases.js.map +1 -0
  287. package/dist/model-catalog.d.ts +33 -0
  288. package/dist/model-catalog.d.ts.map +1 -0
  289. package/dist/model-catalog.js +16 -0
  290. package/dist/model-catalog.js.map +1 -0
  291. package/dist/models-store.d.ts +30 -0
  292. package/dist/models-store.d.ts.map +1 -0
  293. package/dist/models-store.js +17 -0
  294. package/dist/models-store.js.map +1 -0
  295. package/dist/models.d.ts +250 -0
  296. package/dist/models.d.ts.map +1 -0
  297. package/dist/models.generated.d.ts +171 -0
  298. package/dist/models.generated.d.ts.map +1 -0
  299. package/dist/models.generated.js +173 -0
  300. package/dist/models.generated.js.map +1 -0
  301. package/dist/models.js +644 -0
  302. package/dist/models.js.map +1 -0
  303. package/dist/oauth.d.ts +3 -0
  304. package/dist/oauth.d.ts.map +1 -0
  305. package/dist/oauth.js +2 -0
  306. package/dist/oauth.js.map +1 -0
  307. package/dist/providers/all.d.ts +31 -0
  308. package/dist/providers/all.d.ts.map +1 -0
  309. package/dist/providers/all.js +134 -0
  310. package/dist/providers/all.js.map +1 -0
  311. package/dist/providers/amazon-bedrock.d.ts +3 -0
  312. package/dist/providers/amazon-bedrock.d.ts.map +1 -0
  313. package/dist/providers/amazon-bedrock.js +93 -0
  314. package/dist/providers/amazon-bedrock.js.map +1 -0
  315. package/dist/providers/amazon-bedrock.models.d.ts +6 -0
  316. package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
  317. package/dist/providers/amazon-bedrock.models.js +8 -0
  318. package/dist/providers/amazon-bedrock.models.js.map +1 -0
  319. package/dist/providers/ant-ling.d.ts +3 -0
  320. package/dist/providers/ant-ling.d.ts.map +1 -0
  321. package/dist/providers/ant-ling.js +15 -0
  322. package/dist/providers/ant-ling.js.map +1 -0
  323. package/dist/providers/ant-ling.models.d.ts +6 -0
  324. package/dist/providers/ant-ling.models.d.ts.map +1 -0
  325. package/dist/providers/ant-ling.models.js +8 -0
  326. package/dist/providers/ant-ling.models.js.map +1 -0
  327. package/dist/providers/anthropic.d.ts +3 -0
  328. package/dist/providers/anthropic.d.ts.map +1 -0
  329. package/dist/providers/anthropic.js +78 -0
  330. package/dist/providers/anthropic.js.map +1 -0
  331. package/dist/providers/anthropic.models.d.ts +6 -0
  332. package/dist/providers/anthropic.models.d.ts.map +1 -0
  333. package/dist/providers/anthropic.models.js +8 -0
  334. package/dist/providers/anthropic.models.js.map +1 -0
  335. package/dist/providers/azure.d.ts +3 -0
  336. package/dist/providers/azure.d.ts.map +1 -0
  337. package/dist/providers/azure.js +46 -0
  338. package/dist/providers/azure.js.map +1 -0
  339. package/dist/providers/azure.models.d.ts +6 -0
  340. package/dist/providers/azure.models.d.ts.map +1 -0
  341. package/dist/providers/azure.models.js +8 -0
  342. package/dist/providers/azure.models.js.map +1 -0
  343. package/dist/providers/baseten.d.ts +3 -0
  344. package/dist/providers/baseten.d.ts.map +1 -0
  345. package/dist/providers/baseten.js +15 -0
  346. package/dist/providers/baseten.js.map +1 -0
  347. package/dist/providers/baseten.models.d.ts +6 -0
  348. package/dist/providers/baseten.models.d.ts.map +1 -0
  349. package/dist/providers/baseten.models.js +8 -0
  350. package/dist/providers/baseten.models.js.map +1 -0
  351. package/dist/providers/cerebras.d.ts +3 -0
  352. package/dist/providers/cerebras.d.ts.map +1 -0
  353. package/dist/providers/cerebras.js +15 -0
  354. package/dist/providers/cerebras.js.map +1 -0
  355. package/dist/providers/cerebras.models.d.ts +6 -0
  356. package/dist/providers/cerebras.models.d.ts.map +1 -0
  357. package/dist/providers/cerebras.models.js +8 -0
  358. package/dist/providers/cerebras.models.js.map +1 -0
  359. package/dist/providers/cloudflare-ai-gateway.d.ts +5 -0
  360. package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
  361. package/dist/providers/cloudflare-ai-gateway.js +25 -0
  362. package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
  363. package/dist/providers/cloudflare-ai-gateway.models.d.ts +6 -0
  364. package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
  365. package/dist/providers/cloudflare-ai-gateway.models.js +8 -0
  366. package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
  367. package/dist/providers/cloudflare-auth.d.ts +4 -0
  368. package/dist/providers/cloudflare-auth.d.ts.map +1 -0
  369. package/dist/providers/cloudflare-auth.js +86 -0
  370. package/dist/providers/cloudflare-auth.js.map +1 -0
  371. package/dist/providers/cloudflare-stream.d.ts +12 -0
  372. package/dist/providers/cloudflare-stream.d.ts.map +1 -0
  373. package/dist/providers/cloudflare-stream.js +27 -0
  374. package/dist/providers/cloudflare-stream.js.map +1 -0
  375. package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
  376. package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
  377. package/dist/providers/cloudflare-workers-ai.js +22 -0
  378. package/dist/providers/cloudflare-workers-ai.js.map +1 -0
  379. package/dist/providers/cloudflare-workers-ai.models.d.ts +6 -0
  380. package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
  381. package/dist/providers/cloudflare-workers-ai.models.js +8 -0
  382. package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
  383. package/dist/providers/data/.manifest.json +1 -0
  384. package/dist/providers/data/amazon-bedrock.json +1 -0
  385. package/dist/providers/data/ant-ling.json +1 -0
  386. package/dist/providers/data/anthropic.json +1 -0
  387. package/dist/providers/data/azure.json +1 -0
  388. package/dist/providers/data/baseten.json +1 -0
  389. package/dist/providers/data/cerebras.json +1 -0
  390. package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
  391. package/dist/providers/data/cloudflare-workers-ai.json +1 -0
  392. package/dist/providers/data/deepseek.json +1 -0
  393. package/dist/providers/data/fireworks.json +1 -0
  394. package/dist/providers/data/github-copilot.json +1 -0
  395. package/dist/providers/data/google-vertex.json +1 -0
  396. package/dist/providers/data/google.json +1 -0
  397. package/dist/providers/data/groq.json +1 -0
  398. package/dist/providers/data/huggingface.json +1 -0
  399. package/dist/providers/data/kimi-coding.json +1 -0
  400. package/dist/providers/data/meta.json +1 -0
  401. package/dist/providers/data/minimax-cn.json +1 -0
  402. package/dist/providers/data/minimax.json +1 -0
  403. package/dist/providers/data/mistral.json +1 -0
  404. package/dist/providers/data/moonshotai-cn.json +1 -0
  405. package/dist/providers/data/moonshotai.json +1 -0
  406. package/dist/providers/data/nvidia.json +1 -0
  407. package/dist/providers/data/openai-codex.json +1 -0
  408. package/dist/providers/data/openai.json +1 -0
  409. package/dist/providers/data/opencode-go.json +1 -0
  410. package/dist/providers/data/opencode.json +1 -0
  411. package/dist/providers/data/openrouter.json +1 -0
  412. package/dist/providers/data/qwen-token-plan-cn.json +1 -0
  413. package/dist/providers/data/qwen-token-plan-individual.json +1 -0
  414. package/dist/providers/data/qwen-token-plan.json +1 -0
  415. package/dist/providers/data/together.json +1 -0
  416. package/dist/providers/data/typesafe.json +1 -0
  417. package/dist/providers/data/vercel-ai-gateway.json +1 -0
  418. package/dist/providers/data/xai.json +1 -0
  419. package/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
  420. package/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
  421. package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
  422. package/dist/providers/data/xiaomi.json +1 -0
  423. package/dist/providers/data/zai-coding-cn.json +1 -0
  424. package/dist/providers/data/zai.json +1 -0
  425. package/dist/providers/deepseek.d.ts +3 -0
  426. package/dist/providers/deepseek.d.ts.map +1 -0
  427. package/dist/providers/deepseek.js +15 -0
  428. package/dist/providers/deepseek.js.map +1 -0
  429. package/dist/providers/deepseek.models.d.ts +6 -0
  430. package/dist/providers/deepseek.models.d.ts.map +1 -0
  431. package/dist/providers/deepseek.models.js +8 -0
  432. package/dist/providers/deepseek.models.js.map +1 -0
  433. package/dist/providers/faux.d.ts +103 -0
  434. package/dist/providers/faux.d.ts.map +1 -0
  435. package/dist/providers/faux.js +506 -0
  436. package/dist/providers/faux.js.map +1 -0
  437. package/dist/providers/fireworks.d.ts +3 -0
  438. package/dist/providers/fireworks.d.ts.map +1 -0
  439. package/dist/providers/fireworks.js +19 -0
  440. package/dist/providers/fireworks.js.map +1 -0
  441. package/dist/providers/fireworks.models.d.ts +6 -0
  442. package/dist/providers/fireworks.models.d.ts.map +1 -0
  443. package/dist/providers/fireworks.models.js +8 -0
  444. package/dist/providers/fireworks.models.js.map +1 -0
  445. package/dist/providers/github-copilot.d.ts +3 -0
  446. package/dist/providers/github-copilot.d.ts.map +1 -0
  447. package/dist/providers/github-copilot.js +35 -0
  448. package/dist/providers/github-copilot.js.map +1 -0
  449. package/dist/providers/github-copilot.models.d.ts +6 -0
  450. package/dist/providers/github-copilot.models.d.ts.map +1 -0
  451. package/dist/providers/github-copilot.models.js +8 -0
  452. package/dist/providers/github-copilot.models.js.map +1 -0
  453. package/dist/providers/google-vertex.d.ts +3 -0
  454. package/dist/providers/google-vertex.d.ts.map +1 -0
  455. package/dist/providers/google-vertex.js +94 -0
  456. package/dist/providers/google-vertex.js.map +1 -0
  457. package/dist/providers/google-vertex.models.d.ts +6 -0
  458. package/dist/providers/google-vertex.models.d.ts.map +1 -0
  459. package/dist/providers/google-vertex.models.js +8 -0
  460. package/dist/providers/google-vertex.models.js.map +1 -0
  461. package/dist/providers/google.d.ts +3 -0
  462. package/dist/providers/google.d.ts.map +1 -0
  463. package/dist/providers/google.js +15 -0
  464. package/dist/providers/google.js.map +1 -0
  465. package/dist/providers/google.models.d.ts +6 -0
  466. package/dist/providers/google.models.d.ts.map +1 -0
  467. package/dist/providers/google.models.js +8 -0
  468. package/dist/providers/google.models.js.map +1 -0
  469. package/dist/providers/groq.d.ts +3 -0
  470. package/dist/providers/groq.d.ts.map +1 -0
  471. package/dist/providers/groq.js +15 -0
  472. package/dist/providers/groq.js.map +1 -0
  473. package/dist/providers/groq.models.d.ts +6 -0
  474. package/dist/providers/groq.models.d.ts.map +1 -0
  475. package/dist/providers/groq.models.js +8 -0
  476. package/dist/providers/groq.models.js.map +1 -0
  477. package/dist/providers/huggingface.d.ts +3 -0
  478. package/dist/providers/huggingface.d.ts.map +1 -0
  479. package/dist/providers/huggingface.js +15 -0
  480. package/dist/providers/huggingface.js.map +1 -0
  481. package/dist/providers/huggingface.models.d.ts +6 -0
  482. package/dist/providers/huggingface.models.d.ts.map +1 -0
  483. package/dist/providers/huggingface.models.js +8 -0
  484. package/dist/providers/huggingface.models.js.map +1 -0
  485. package/dist/providers/images/register-builtins.d.ts +4 -0
  486. package/dist/providers/images/register-builtins.d.ts.map +1 -0
  487. package/dist/providers/images/register-builtins.js +34 -0
  488. package/dist/providers/images/register-builtins.js.map +1 -0
  489. package/dist/providers/kimi-coding.d.ts +3 -0
  490. package/dist/providers/kimi-coding.d.ts.map +1 -0
  491. package/dist/providers/kimi-coding.js +24 -0
  492. package/dist/providers/kimi-coding.js.map +1 -0
  493. package/dist/providers/kimi-coding.models.d.ts +6 -0
  494. package/dist/providers/kimi-coding.models.d.ts.map +1 -0
  495. package/dist/providers/kimi-coding.models.js +8 -0
  496. package/dist/providers/kimi-coding.models.js.map +1 -0
  497. package/dist/providers/meta.d.ts +3 -0
  498. package/dist/providers/meta.d.ts.map +1 -0
  499. package/dist/providers/meta.js +24 -0
  500. package/dist/providers/meta.js.map +1 -0
  501. package/dist/providers/meta.models.d.ts +6 -0
  502. package/dist/providers/meta.models.d.ts.map +1 -0
  503. package/dist/providers/meta.models.js +8 -0
  504. package/dist/providers/meta.models.js.map +1 -0
  505. package/dist/providers/minimax-cn.d.ts +3 -0
  506. package/dist/providers/minimax-cn.d.ts.map +1 -0
  507. package/dist/providers/minimax-cn.js +15 -0
  508. package/dist/providers/minimax-cn.js.map +1 -0
  509. package/dist/providers/minimax-cn.models.d.ts +6 -0
  510. package/dist/providers/minimax-cn.models.d.ts.map +1 -0
  511. package/dist/providers/minimax-cn.models.js +8 -0
  512. package/dist/providers/minimax-cn.models.js.map +1 -0
  513. package/dist/providers/minimax.d.ts +3 -0
  514. package/dist/providers/minimax.d.ts.map +1 -0
  515. package/dist/providers/minimax.js +15 -0
  516. package/dist/providers/minimax.js.map +1 -0
  517. package/dist/providers/minimax.models.d.ts +6 -0
  518. package/dist/providers/minimax.models.d.ts.map +1 -0
  519. package/dist/providers/minimax.models.js +8 -0
  520. package/dist/providers/minimax.models.js.map +1 -0
  521. package/dist/providers/mistral.d.ts +3 -0
  522. package/dist/providers/mistral.d.ts.map +1 -0
  523. package/dist/providers/mistral.js +15 -0
  524. package/dist/providers/mistral.js.map +1 -0
  525. package/dist/providers/mistral.models.d.ts +6 -0
  526. package/dist/providers/mistral.models.d.ts.map +1 -0
  527. package/dist/providers/mistral.models.js +8 -0
  528. package/dist/providers/mistral.models.js.map +1 -0
  529. package/dist/providers/moonshotai-cn.d.ts +3 -0
  530. package/dist/providers/moonshotai-cn.d.ts.map +1 -0
  531. package/dist/providers/moonshotai-cn.js +15 -0
  532. package/dist/providers/moonshotai-cn.js.map +1 -0
  533. package/dist/providers/moonshotai-cn.models.d.ts +6 -0
  534. package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
  535. package/dist/providers/moonshotai-cn.models.js +8 -0
  536. package/dist/providers/moonshotai-cn.models.js.map +1 -0
  537. package/dist/providers/moonshotai.d.ts +3 -0
  538. package/dist/providers/moonshotai.d.ts.map +1 -0
  539. package/dist/providers/moonshotai.js +15 -0
  540. package/dist/providers/moonshotai.js.map +1 -0
  541. package/dist/providers/moonshotai.models.d.ts +6 -0
  542. package/dist/providers/moonshotai.models.d.ts.map +1 -0
  543. package/dist/providers/moonshotai.models.js +8 -0
  544. package/dist/providers/moonshotai.models.js.map +1 -0
  545. package/dist/providers/nvidia.d.ts +3 -0
  546. package/dist/providers/nvidia.d.ts.map +1 -0
  547. package/dist/providers/nvidia.js +15 -0
  548. package/dist/providers/nvidia.js.map +1 -0
  549. package/dist/providers/nvidia.models.d.ts +6 -0
  550. package/dist/providers/nvidia.models.d.ts.map +1 -0
  551. package/dist/providers/nvidia.models.js +8 -0
  552. package/dist/providers/nvidia.models.js.map +1 -0
  553. package/dist/providers/openai-codex.d.ts +3 -0
  554. package/dist/providers/openai-codex.d.ts.map +1 -0
  555. package/dist/providers/openai-codex.js +22 -0
  556. package/dist/providers/openai-codex.js.map +1 -0
  557. package/dist/providers/openai-codex.models.d.ts +6 -0
  558. package/dist/providers/openai-codex.models.d.ts.map +1 -0
  559. package/dist/providers/openai-codex.models.js +8 -0
  560. package/dist/providers/openai-codex.models.js.map +1 -0
  561. package/dist/providers/openai.d.ts +3 -0
  562. package/dist/providers/openai.d.ts.map +1 -0
  563. package/dist/providers/openai.js +33 -0
  564. package/dist/providers/openai.js.map +1 -0
  565. package/dist/providers/openai.models.d.ts +6 -0
  566. package/dist/providers/openai.models.d.ts.map +1 -0
  567. package/dist/providers/openai.models.js +8 -0
  568. package/dist/providers/openai.models.js.map +1 -0
  569. package/dist/providers/opencode-go.d.ts +3 -0
  570. package/dist/providers/opencode-go.d.ts.map +1 -0
  571. package/dist/providers/opencode-go.js +21 -0
  572. package/dist/providers/opencode-go.js.map +1 -0
  573. package/dist/providers/opencode-go.models.d.ts +6 -0
  574. package/dist/providers/opencode-go.models.d.ts.map +1 -0
  575. package/dist/providers/opencode-go.models.js +8 -0
  576. package/dist/providers/opencode-go.models.js.map +1 -0
  577. package/dist/providers/opencode-headers.d.ts +4 -0
  578. package/dist/providers/opencode-headers.d.ts.map +1 -0
  579. package/dist/providers/opencode-headers.js +22 -0
  580. package/dist/providers/opencode-headers.js.map +1 -0
  581. package/dist/providers/opencode.d.ts +5 -0
  582. package/dist/providers/opencode.d.ts.map +1 -0
  583. package/dist/providers/opencode.js +26 -0
  584. package/dist/providers/opencode.js.map +1 -0
  585. package/dist/providers/opencode.models.d.ts +6 -0
  586. package/dist/providers/opencode.models.d.ts.map +1 -0
  587. package/dist/providers/opencode.models.js +8 -0
  588. package/dist/providers/opencode.models.js.map +1 -0
  589. package/dist/providers/openrouter.d.ts +3 -0
  590. package/dist/providers/openrouter.d.ts.map +1 -0
  591. package/dist/providers/openrouter.js +36 -0
  592. package/dist/providers/openrouter.js.map +1 -0
  593. package/dist/providers/openrouter.models.d.ts +6 -0
  594. package/dist/providers/openrouter.models.d.ts.map +1 -0
  595. package/dist/providers/openrouter.models.js +8 -0
  596. package/dist/providers/openrouter.models.js.map +1 -0
  597. package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
  598. package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
  599. package/dist/providers/qwen-token-plan-cn.js +15 -0
  600. package/dist/providers/qwen-token-plan-cn.js.map +1 -0
  601. package/dist/providers/qwen-token-plan-cn.models.d.ts +6 -0
  602. package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
  603. package/dist/providers/qwen-token-plan-cn.models.js +8 -0
  604. package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
  605. package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
  606. package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
  607. package/dist/providers/qwen-token-plan-individual.js +15 -0
  608. package/dist/providers/qwen-token-plan-individual.js.map +1 -0
  609. package/dist/providers/qwen-token-plan-individual.models.d.ts +6 -0
  610. package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
  611. package/dist/providers/qwen-token-plan-individual.models.js +8 -0
  612. package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
  613. package/dist/providers/qwen-token-plan.d.ts +3 -0
  614. package/dist/providers/qwen-token-plan.d.ts.map +1 -0
  615. package/dist/providers/qwen-token-plan.js +15 -0
  616. package/dist/providers/qwen-token-plan.js.map +1 -0
  617. package/dist/providers/qwen-token-plan.models.d.ts +6 -0
  618. package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
  619. package/dist/providers/qwen-token-plan.models.js +8 -0
  620. package/dist/providers/qwen-token-plan.models.js.map +1 -0
  621. package/dist/providers/together.d.ts +3 -0
  622. package/dist/providers/together.d.ts.map +1 -0
  623. package/dist/providers/together.js +15 -0
  624. package/dist/providers/together.js.map +1 -0
  625. package/dist/providers/together.models.d.ts +6 -0
  626. package/dist/providers/together.models.d.ts.map +1 -0
  627. package/dist/providers/together.models.js +8 -0
  628. package/dist/providers/together.models.js.map +1 -0
  629. package/dist/providers/typesafe.d.ts +3 -0
  630. package/dist/providers/typesafe.d.ts.map +1 -0
  631. package/dist/providers/typesafe.js +18 -0
  632. package/dist/providers/typesafe.js.map +1 -0
  633. package/dist/providers/typesafe.models.d.ts +6 -0
  634. package/dist/providers/typesafe.models.d.ts.map +1 -0
  635. package/dist/providers/typesafe.models.js +8 -0
  636. package/dist/providers/typesafe.models.js.map +1 -0
  637. package/dist/providers/vercel-ai-gateway.d.ts +3 -0
  638. package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
  639. package/dist/providers/vercel-ai-gateway.js +18 -0
  640. package/dist/providers/vercel-ai-gateway.js.map +1 -0
  641. package/dist/providers/vercel-ai-gateway.models.d.ts +6 -0
  642. package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
  643. package/dist/providers/vercel-ai-gateway.models.js +8 -0
  644. package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
  645. package/dist/providers/xai.d.ts +3 -0
  646. package/dist/providers/xai.d.ts.map +1 -0
  647. package/dist/providers/xai.js +24 -0
  648. package/dist/providers/xai.js.map +1 -0
  649. package/dist/providers/xai.models.d.ts +6 -0
  650. package/dist/providers/xai.models.d.ts.map +1 -0
  651. package/dist/providers/xai.models.js +8 -0
  652. package/dist/providers/xai.models.js.map +1 -0
  653. package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
  654. package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
  655. package/dist/providers/xiaomi-token-plan-ams.js +15 -0
  656. package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
  657. package/dist/providers/xiaomi-token-plan-ams.models.d.ts +6 -0
  658. package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
  659. package/dist/providers/xiaomi-token-plan-ams.models.js +8 -0
  660. package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
  661. package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
  662. package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
  663. package/dist/providers/xiaomi-token-plan-cn.js +15 -0
  664. package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
  665. package/dist/providers/xiaomi-token-plan-cn.models.d.ts +6 -0
  666. package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
  667. package/dist/providers/xiaomi-token-plan-cn.models.js +8 -0
  668. package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
  669. package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
  670. package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
  671. package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
  672. package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
  673. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +6 -0
  674. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
  675. package/dist/providers/xiaomi-token-plan-sgp.models.js +8 -0
  676. package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
  677. package/dist/providers/xiaomi.d.ts +3 -0
  678. package/dist/providers/xiaomi.d.ts.map +1 -0
  679. package/dist/providers/xiaomi.js +15 -0
  680. package/dist/providers/xiaomi.js.map +1 -0
  681. package/dist/providers/xiaomi.models.d.ts +6 -0
  682. package/dist/providers/xiaomi.models.d.ts.map +1 -0
  683. package/dist/providers/xiaomi.models.js +8 -0
  684. package/dist/providers/xiaomi.models.js.map +1 -0
  685. package/dist/providers/zai-coding-cn.d.ts +3 -0
  686. package/dist/providers/zai-coding-cn.d.ts.map +1 -0
  687. package/dist/providers/zai-coding-cn.js +15 -0
  688. package/dist/providers/zai-coding-cn.js.map +1 -0
  689. package/dist/providers/zai-coding-cn.models.d.ts +6 -0
  690. package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
  691. package/dist/providers/zai-coding-cn.models.js +8 -0
  692. package/dist/providers/zai-coding-cn.models.js.map +1 -0
  693. package/dist/providers/zai.d.ts +3 -0
  694. package/dist/providers/zai.d.ts.map +1 -0
  695. package/dist/providers/zai.js +15 -0
  696. package/dist/providers/zai.js.map +1 -0
  697. package/dist/providers/zai.models.d.ts +6 -0
  698. package/dist/providers/zai.models.d.ts.map +1 -0
  699. package/dist/providers/zai.models.js +8 -0
  700. package/dist/providers/zai.models.js.map +1 -0
  701. package/dist/schemas/compat-schema.d.ts +338 -0
  702. package/dist/schemas/compat-schema.d.ts.map +1 -0
  703. package/dist/schemas/compat-schema.js +375 -0
  704. package/dist/schemas/compat-schema.js.map +1 -0
  705. package/dist/schemas/model-schema.d.ts +91 -0
  706. package/dist/schemas/model-schema.d.ts.map +1 -0
  707. package/dist/schemas/model-schema.js +55 -0
  708. package/dist/schemas/model-schema.js.map +1 -0
  709. package/dist/session-resources.d.ts +4 -0
  710. package/dist/session-resources.d.ts.map +1 -0
  711. package/dist/session-resources.js +22 -0
  712. package/dist/session-resources.js.map +1 -0
  713. package/dist/types.d.ts +645 -0
  714. package/dist/types.d.ts.map +1 -0
  715. package/dist/types.js +2 -0
  716. package/dist/types.js.map +1 -0
  717. package/dist/utils/abort-signals.d.ts +6 -0
  718. package/dist/utils/abort-signals.d.ts.map +1 -0
  719. package/dist/utils/abort-signals.js +34 -0
  720. package/dist/utils/abort-signals.js.map +1 -0
  721. package/dist/utils/abort.d.ts +8 -0
  722. package/dist/utils/abort.d.ts.map +1 -0
  723. package/dist/utils/abort.js +49 -0
  724. package/dist/utils/abort.js.map +1 -0
  725. package/dist/utils/assistant-message-frame.d.ts +77 -0
  726. package/dist/utils/assistant-message-frame.d.ts.map +1 -0
  727. package/dist/utils/assistant-message-frame.js +425 -0
  728. package/dist/utils/assistant-message-frame.js.map +1 -0
  729. package/dist/utils/diagnostics.d.ts +20 -0
  730. package/dist/utils/diagnostics.d.ts.map +1 -0
  731. package/dist/utils/diagnostics.js +25 -0
  732. package/dist/utils/diagnostics.js.map +1 -0
  733. package/dist/utils/error-body.d.ts +25 -0
  734. package/dist/utils/error-body.d.ts.map +1 -0
  735. package/dist/utils/error-body.js +133 -0
  736. package/dist/utils/error-body.js.map +1 -0
  737. package/dist/utils/estimate.d.ts +17 -0
  738. package/dist/utils/estimate.d.ts.map +1 -0
  739. package/dist/utils/estimate.js +95 -0
  740. package/dist/utils/estimate.js.map +1 -0
  741. package/dist/utils/event-stream.d.ts +30 -0
  742. package/dist/utils/event-stream.d.ts.map +1 -0
  743. package/dist/utils/event-stream.js +124 -0
  744. package/dist/utils/event-stream.js.map +1 -0
  745. package/dist/utils/hash.d.ts +3 -0
  746. package/dist/utils/hash.d.ts.map +1 -0
  747. package/dist/utils/hash.js +14 -0
  748. package/dist/utils/hash.js.map +1 -0
  749. package/dist/utils/headers.d.ts +4 -0
  750. package/dist/utils/headers.d.ts.map +1 -0
  751. package/dist/utils/headers.js +20 -0
  752. package/dist/utils/headers.js.map +1 -0
  753. package/dist/utils/json-parse.d.ts +16 -0
  754. package/dist/utils/json-parse.d.ts.map +1 -0
  755. package/dist/utils/json-parse.js +113 -0
  756. package/dist/utils/json-parse.js.map +1 -0
  757. package/dist/utils/model-operations.d.ts +34 -0
  758. package/dist/utils/model-operations.d.ts.map +1 -0
  759. package/dist/utils/model-operations.js +129 -0
  760. package/dist/utils/model-operations.js.map +1 -0
  761. package/dist/utils/models-error.d.ts +8 -0
  762. package/dist/utils/models-error.d.ts.map +1 -0
  763. package/dist/utils/models-error.js +19 -0
  764. package/dist/utils/models-error.js.map +1 -0
  765. package/dist/utils/node-http-proxy.d.ts +4 -0
  766. package/dist/utils/node-http-proxy.d.ts.map +1 -0
  767. package/dist/utils/node-http-proxy.js +133 -0
  768. package/dist/utils/node-http-proxy.js.map +1 -0
  769. package/dist/utils/nyan-user-agent.d.ts +2 -0
  770. package/dist/utils/nyan-user-agent.d.ts.map +1 -0
  771. package/dist/utils/nyan-user-agent.js +12 -0
  772. package/dist/utils/nyan-user-agent.js.map +1 -0
  773. package/dist/utils/oauth-page.d.ts +3 -0
  774. package/dist/utils/oauth-page.d.ts.map +1 -0
  775. package/dist/utils/oauth-page.js +105 -0
  776. package/dist/utils/oauth-page.js.map +1 -0
  777. package/dist/utils/overflow.d.ts +69 -0
  778. package/dist/utils/overflow.d.ts.map +1 -0
  779. package/dist/utils/overflow.js +179 -0
  780. package/dist/utils/overflow.js.map +1 -0
  781. package/dist/utils/provider-env.d.ts +7 -0
  782. package/dist/utils/provider-env.d.ts.map +1 -0
  783. package/dist/utils/provider-env.js +42 -0
  784. package/dist/utils/provider-env.js.map +1 -0
  785. package/dist/utils/provider-retry.d.ts +18 -0
  786. package/dist/utils/provider-retry.d.ts.map +1 -0
  787. package/dist/utils/provider-retry.js +97 -0
  788. package/dist/utils/provider-retry.js.map +1 -0
  789. package/dist/utils/retry.d.ts +58 -0
  790. package/dist/utils/retry.d.ts.map +1 -0
  791. package/dist/utils/retry.js +196 -0
  792. package/dist/utils/retry.js.map +1 -0
  793. package/dist/utils/sanitize-unicode.d.ts +22 -0
  794. package/dist/utils/sanitize-unicode.d.ts.map +1 -0
  795. package/dist/utils/sanitize-unicode.js +26 -0
  796. package/dist/utils/sanitize-unicode.js.map +1 -0
  797. package/dist/utils/sleep.d.ts +2 -0
  798. package/dist/utils/sleep.d.ts.map +1 -0
  799. package/dist/utils/sleep.js +15 -0
  800. package/dist/utils/sleep.js.map +1 -0
  801. package/dist/utils/text.d.ts +14 -0
  802. package/dist/utils/text.d.ts.map +1 -0
  803. package/dist/utils/text.js +36 -0
  804. package/dist/utils/text.js.map +1 -0
  805. package/dist/utils/transcript.d.ts +87 -0
  806. package/dist/utils/transcript.d.ts.map +1 -0
  807. package/dist/utils/transcript.js +207 -0
  808. package/dist/utils/transcript.js.map +1 -0
  809. package/dist/utils/typebox-helpers.d.ts +17 -0
  810. package/dist/utils/typebox-helpers.d.ts.map +1 -0
  811. package/dist/utils/typebox-helpers.js +21 -0
  812. package/dist/utils/typebox-helpers.js.map +1 -0
  813. package/dist/utils/uuid.d.ts +3 -0
  814. package/dist/utils/uuid.d.ts.map +1 -0
  815. package/dist/utils/uuid.js +42 -0
  816. package/dist/utils/uuid.js.map +1 -0
  817. package/dist/utils/validation.d.ts +18 -0
  818. package/dist/utils/validation.d.ts.map +1 -0
  819. package/dist/utils/validation.js +309 -0
  820. package/dist/utils/validation.js.map +1 -0
  821. package/package.json +113 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-complet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AC,MAAM,CAAC,6BAA6B,IAAI,QAAQ,CAAC,6BAA6B;QACrF,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,kBAAkB,IAAI,QAAQ,CAAC,kBAAkB;QAClF,0BAA0B,EAAE,KAAK,CAAC,MAAM,CAAC,0BAA0B,IAAI,QAAQ,CAAC,0BAA0B;QAC1G,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,qBAAqB,IAAI,QAAQ,CAAC,qBAAqB;QAC3F,0BAA0B,EAAE,KAAK,CAAC,MAAM,CAAC,0BAA0B,IAAI,QAAQ,CAAC,0BAA0B;QAC1G,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC;AACH,CAAC","sourcesContent":["import OpenAI from \"openai\";\nimport type {\n\tChatCompletionAssistantMessageParam,\n\tChatCompletionChunk,\n\tChatCompletionContentPart,\n\tChatCompletionContentPartImage,\n\tChatCompletionContentPartText,\n\tChatCompletionDeveloperMessageParam,\n\tChatCompletionMessageParam,\n\tChatCompletionMessageToolCall,\n\tChatCompletionSystemMessageParam,\n\tChatCompletionToolMessageParam,\n} from \"openai/resources/chat/completions.js\";\nimport type {\n\tAssistantMessage,\n\tCacheRetention,\n\tChatTemplateKwargValue,\n\tImageContent,\n\tJsonValue,\n\tMessage,\n\tModel,\n\tOpenAICompletionsCompat,\n\tProviderEnv,\n\tProviderHeaders,\n\tSimpleStreamOptions,\n\tStopReason,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tThinkingTokenBudgetField,\n\tTool,\n\tToolCall,\n\tToolResultMessage,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { shortHash } from \"../utils/hash.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport { calculateCost, clampThinkingLevel } from \"../utils/model-operations.ts\";\nimport { getNyanUserAgent } from \"../utils/nyan-user-agent.ts\";\nimport { getProviderEnvValue } from \"../utils/provider-env.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport { getSystemMessageText, renderSystemMessageUpdate } from \"../utils/text.ts\";\nimport {\n\tgetDeclaredTools,\n\tresolveTranscript,\n\tresolveTranscriptTools,\n\ttype TranscriptContext,\n} from \"../utils/transcript.ts\";\nimport {\n\tappendGrammarToolInputJsonDelta,\n\tcreateGrammarToolInputProperties,\n\ttype GrammarToolInputJsonBuffer,\n\tgetGrammarToolInput,\n\tgetJsonSchemaToolParameters,\n\tresolveGrammarConstrainedSampling,\n\tresolveJsonSchemaStrictSampling,\n} from \"./constrained-sampling.ts\";\nimport { buildCopilotDynamicHeaders, hasCopilotVisionInput } from \"./github-copilot-headers.ts\";\nimport { clampOpenAIPromptCacheKey } from \"./openai-prompt-cache.ts\";\nimport {\n\tbuildBaseOptions,\n\tclampThinkingBudgetToAnswerRoom,\n\tresolveSamplingParams,\n\tthinkingBudgetForLevel,\n} from \"./simple-options.ts\";\nimport { transformMessages } from \"./transform-messages.ts\";\n\n/**\n * Check if conversation messages contain tool calls or tool results.\n * This is needed because Anthropic (via proxy) requires the tools param\n * to be present when messages include tool_calls or tool role messages.\n */\nfunction hasHeader(headers: ProviderHeaders | undefined, name: string): boolean {\n\tif (!headers) return false;\n\tconst expected = name.toLowerCase();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (key.toLowerCase() === expected && value !== null && value.trim().length > 0) return true;\n\t}\n\treturn false;\n}\n\nfunction getClientApiKey(provider: string, apiKey: string | undefined, headers: ProviderHeaders | undefined): string {\n\tif (apiKey) return apiKey;\n\tif (hasHeader(headers, \"authorization\") || hasHeader(headers, \"cf-aig-authorization\")) return \"unused\";\n\tthrow new Error(`No API key for provider: ${provider}`);\n}\n\nfunction hasToolHistory(messages: Message[]): boolean {\n\tfor (const msg of messages) {\n\t\tif (msg.role === \"toolResult\") {\n\t\t\treturn true;\n\t\t}\n\t\tif (msg.role === \"assistant\") {\n\t\t\tif (msg.content.some((block) => block.type === \"toolCall\")) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isTextContentBlock(block: { type: string }): block is TextContent {\n\treturn block.type === \"text\";\n}\n\nfunction isThinkingContentBlock(block: { type: string }): block is ThinkingContent {\n\treturn block.type === \"thinking\";\n}\n\nfunction isToolCallBlock(block: { type: string }): block is ToolCall {\n\treturn block.type === \"toolCall\";\n}\n\nfunction isImageContentBlock(block: { type: string }): block is ImageContent {\n\treturn block.type === \"image\";\n}\n\nfunction isReasoningDetailObject(detail: unknown): detail is Record<string, unknown> {\n\treturn typeof detail === \"object\" && detail !== null && !Array.isArray(detail);\n}\n\nfunction hasValidCommonReasoningDetailFields(candidate: Record<string, unknown>): boolean {\n\treturn (\n\t\t(candidate.id === undefined || candidate.id === null || typeof candidate.id === \"string\") &&\n\t\t(candidate.format === undefined || typeof candidate.format === \"string\") &&\n\t\t(candidate.index === undefined || typeof candidate.index === \"number\")\n\t);\n}\n\nfunction isOpenAIReasoningDetail(detail: unknown): detail is OpenAIReasoningDetail {\n\tif (!isReasoningDetailObject(detail) || !hasValidCommonReasoningDetailFields(detail)) {\n\t\treturn false;\n\t}\n\tswitch (detail.type) {\n\t\tcase \"reasoning.summary\":\n\t\t\treturn typeof detail.summary === \"string\";\n\t\tcase \"reasoning.encrypted\":\n\t\t\treturn typeof detail.data === \"string\";\n\t\tcase \"reasoning.text\":\n\t\t\treturn (\n\t\t\t\ttypeof detail.text === \"string\" &&\n\t\t\t\t(detail.signature === undefined || detail.signature === null || typeof detail.signature === \"string\")\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport interface OpenAICompletionsOptions extends StreamOptions {\n\ttoolChoice?: OpenAI.Chat.Completions.ChatCompletionToolChoiceOption;\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\t/** Token budgets per thinking level. Used when `compat.thinkingTokenBudgetField` or `compat.supportsThinkingTokenBudget` is set, or by `{ \"$var\": \"thinking.budget\" }`. */\n\tthinkingBudgets?: ThinkingBudgets;\n}\n\nexport interface ConvertCompletionsMessagesOptions {\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n}\n\ninterface OpenAICompatCacheControl {\n\ttype: \"ephemeral\";\n\tttl?: string;\n}\n\ntype ResolvedOpenAICompletionsCompat = Omit<\n\tRequired<OpenAICompletionsCompat>,\n\t| \"cacheControlFormat\"\n\t| \"supportsThinkingTokenBudget\"\n\t| \"thinkingTokenBudgetField\"\n\t| \"supportsMidConvoSystemMessages\"\n\t| \"supportsMidConvoToolAdditions\"\n\t| \"vllmPriority\"\n> & {\n\tcacheControlFormat?: OpenAICompletionsCompat[\"cacheControlFormat\"];\n\tsupportsThinkingTokenBudget?: OpenAICompletionsCompat[\"supportsThinkingTokenBudget\"];\n\tthinkingTokenBudgetField?: OpenAICompletionsCompat[\"thinkingTokenBudgetField\"];\n\tsupportsMidConvoSystemMessages?: OpenAICompletionsCompat[\"supportsMidConvoSystemMessages\"];\n\tsupportsMidConvoToolAdditions?: OpenAICompletionsCompat[\"supportsMidConvoToolAdditions\"];\n\tvllmPriority?: OpenAICompletionsCompat[\"vllmPriority\"];\n};\n\ntype ResolvedChatTemplateKwargValue = string | number | boolean | null;\n\ntype ChatCompletionInstructionMessageParam = ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam;\n\ntype KimiToolSystemMessageParam = {\n\trole: \"system\";\n\ttools: OpenAI.Chat.Completions.ChatCompletionTool[];\n};\n\ntype OpenAIReasoningDetailBase = Record<string, JsonValue> & {\n\tid?: string | null;\n\tformat?: string;\n\tindex?: number;\n};\n\ntype OpenAIReasoningSummaryDetail = OpenAIReasoningDetailBase & {\n\ttype: \"reasoning.summary\";\n\tsummary: string;\n};\n\ntype OpenAIEncryptedReasoningDetail = OpenAIReasoningDetailBase & {\n\ttype: \"reasoning.encrypted\";\n\tdata: string;\n};\n\ntype OpenAIReasoningTextDetail = OpenAIReasoningDetailBase & {\n\ttype: \"reasoning.text\";\n\ttext: string;\n\tsignature?: string | null;\n};\n\ntype OpenAIReasoningDetail = OpenAIReasoningSummaryDetail | OpenAIEncryptedReasoningDetail | OpenAIReasoningTextDetail;\n\nfunction parseOpenAIReasoningDetails(signature: string | undefined): OpenAIReasoningDetail[] | undefined {\n\tif (!signature) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as unknown;\n\t\treturn Array.isArray(parsed) && parsed.length > 0 && parsed.every(isOpenAIReasoningDetail) ? parsed : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction parseLegacyEncryptedReasoningDetail(\n\tsignature: string | undefined,\n): OpenAIEncryptedReasoningDetail | undefined {\n\tif (!signature) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as unknown;\n\t\treturn isOpenAIReasoningDetail(parsed) &&\n\t\t\tparsed.type === \"reasoning.encrypted\" &&\n\t\t\ttypeof parsed.id === \"string\" &&\n\t\t\tparsed.id.length > 0 &&\n\t\t\tparsed.data.length > 0\n\t\t\t? parsed\n\t\t\t: undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction fillMissingCommonReasoningDetailFields(\n\ttarget: OpenAIReasoningDetailBase,\n\tsource: OpenAIReasoningDetail,\n): void {\n\ttarget.id ??= source.id;\n\ttarget.format ||= source.format;\n\ttarget.index ??= source.index;\n}\n\nfunction appendOpenAIReasoningDetail(details: OpenAIReasoningDetail[], detail: OpenAIReasoningDetail): void {\n\tconst lastDetail = details[details.length - 1];\n\tif (detail.type === \"reasoning.text\" && lastDetail?.type === \"reasoning.text\") {\n\t\tlastDetail.text += detail.text;\n\t\tlastDetail.signature ||= detail.signature;\n\t\tfillMissingCommonReasoningDetailFields(lastDetail, detail);\n\t\treturn;\n\t}\n\tif (detail.type === \"reasoning.summary\" && lastDetail?.type === \"reasoning.summary\") {\n\t\tlastDetail.summary += detail.summary;\n\t\tfillMissingCommonReasoningDetailFields(lastDetail, detail);\n\t\treturn;\n\t}\n\tdetails.push({ ...detail });\n}\n\nconst OPENAI_COMPLETIONS_REASONING_FIELDS = [\"reasoning\", \"reasoning_content\", \"reasoning_text\"] as const;\n\ntype OpenAICompletionsReasoningField = (typeof OPENAI_COMPLETIONS_REASONING_FIELDS)[number];\n\nfunction isOpenAICompletionsReasoningField(field: string): field is OpenAICompletionsReasoningField {\n\treturn OPENAI_COMPLETIONS_REASONING_FIELDS.includes(field as OpenAICompletionsReasoningField);\n}\n\ntype ChatCompletionAssistantMessageParamWithReasoning = ChatCompletionAssistantMessageParam &\n\tPartial<Record<OpenAICompletionsReasoningField, string>> & {\n\t\treasoning_details?: JsonValue[];\n\t};\n\ntype ChatCompletionTextPartWithCacheControl = ChatCompletionContentPartText & {\n\tcache_control?: OpenAICompatCacheControl;\n};\n\ntype ChatCompletionToolWithCacheControl = OpenAI.Chat.Completions.ChatCompletionTool & {\n\tcache_control?: OpenAICompatCacheControl;\n};\n\nfunction resolveCacheRetention(cacheRetention?: CacheRetention, env?: ProviderEnv): CacheRetention {\n\tif (cacheRetention) {\n\t\treturn cacheRetention;\n\t}\n\tif (getProviderEnvValue(\"NYAN_CACHE_RETENTION\", env) === \"long\") {\n\t\treturn \"long\";\n\t}\n\treturn \"short\";\n}\n\nexport const stream: StreamFunction<\"openai-completions\", OpenAICompletionsOptions> = (\n\tmodel: Model<\"openai-completions\">,\n\tcontext: TranscriptContext,\n\toptions?: OpenAICompletionsOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\tconst normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"pending\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\t// `reasoning_details` are replay metadata, not user-visible stream deltas.\n\t\t// Keep them in memory during streaming and serialize once when the block is finalized.\n\t\tlet streamedReasoningDetails: OpenAIReasoningDetail[] | undefined;\n\t\tconst applyStreamedReasoningDetails = (block: ThinkingContent): void => {\n\t\t\tif (streamedReasoningDetails !== undefined) {\n\t\t\t\tblock.thinkingSignature = JSON.stringify(streamedReasoningDetails);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);\n\t\t\tconst compat = getCompat(model);\n\t\t\tconst grammarToolInputProperties = createGrammarToolInputProperties(\n\t\t\t\tgetDeclaredTools(normalizedContext.messages),\n\t\t\t\tcompat.supportsOpenAIGrammarTools,\n\t\t\t);\n\t\t\tconst cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);\n\t\t\tconst cacheSessionId = cacheRetention === \"none\" ? undefined : options?.sessionId;\n\t\t\tconst client = createClient(\n\t\t\t\tmodel,\n\t\t\t\tnormalizedContext,\n\t\t\t\tapiKey,\n\t\t\t\toptions?.headers,\n\t\t\t\toptions?.fetch,\n\t\t\t\tcacheSessionId,\n\t\t\t\tcompat,\n\t\t\t);\n\t\t\tlet params = buildParams(\n\t\t\t\tmodel,\n\t\t\t\tnormalizedContext,\n\t\t\t\toptions,\n\t\t\t\tcompat,\n\t\t\t\tcacheRetention,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;\n\t\t\t}\n\t\t\tconst requestOptions = {\n\t\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\t\tmaxRetries: 0,\n\t\t\t};\n\t\t\tconst { data: openaiStream, response } = await retryProviderRequest(\n\t\t\t\t() => client.chat.completions.create(params, requestOptions).withResponse(),\n\t\t\t\t{\n\t\t\t\t\tmaxRetries: options?.maxRetries,\n\t\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t},\n\t\t\t);\n\t\t\tawait options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tinterface StreamingToolCallBlock extends ToolCall {\n\t\t\t\tpartialArgs?: string;\n\t\t\t\tcustomInput?: {\n\t\t\t\t\tproperty: string;\n\t\t\t\t\tjsonBuffer: GrammarToolInputJsonBuffer;\n\t\t\t\t};\n\t\t\t\tstreamIndex?: number;\n\t\t\t}\n\t\t\ttype StreamingBlock = TextContent | ThinkingContent | StreamingToolCallBlock;\n\t\t\ttype StreamingToolCallDelta = {\n\t\t\t\tindex?: number;\n\t\t\t\tid?: string;\n\t\t\t\ttype?: string;\n\t\t\t\tfunction?: { name?: string; arguments?: string };\n\t\t\t\tcustom?: { name?: string; input?: string };\n\t\t\t};\n\n\t\t\tlet textBlock: TextContent | null = null;\n\t\t\tlet thinkingBlock: ThinkingContent | null = null;\n\t\t\tlet hasFinishReason = false;\n\t\t\tconst toolCallBlocksByIndex = new Map<number, StreamingToolCallBlock>();\n\t\t\tconst toolCallBlocksById = new Map<string, StreamingToolCallBlock>();\n\t\t\tconst blocks = output.content as StreamingBlock[];\n\t\t\tconst getContentIndex = (block: StreamingBlock) => blocks.indexOf(block);\n\t\t\tconst getCustomToolCallInput = (block: StreamingToolCallBlock): string => {\n\t\t\t\tconst property = block.customInput?.property;\n\t\t\t\tif (property === undefined) return \"\";\n\t\t\t\tconst value = block.arguments[property];\n\t\t\t\treturn typeof value === \"string\" ? value : \"\";\n\t\t\t};\n\t\t\tconst appendCustomToolCallInput = (\n\t\t\t\tblock: StreamingToolCallBlock,\n\t\t\t\tnextInput: string,\n\t\t\t\tclose: boolean,\n\t\t\t): string | undefined => {\n\t\t\t\tconst customInput = block.customInput;\n\t\t\t\tif (!customInput) return undefined;\n\t\t\t\tconst delta = appendGrammarToolInputJsonDelta(\n\t\t\t\t\tcustomInput.jsonBuffer,\n\t\t\t\t\tcustomInput.property,\n\t\t\t\t\tnextInput,\n\t\t\t\t\tclose,\n\t\t\t\t);\n\t\t\t\tblock.arguments = { [customInput.property]: nextInput };\n\t\t\t\treturn delta;\n\t\t\t};\n\t\t\tconst finishBlock = (block: StreamingBlock) => {\n\t\t\t\tconst contentIndex = getContentIndex(block);\n\t\t\t\tif (contentIndex === -1) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\tcontent: block.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else if (block.type === \"thinking\") {\n\t\t\t\t\tapplyStreamedReasoningDetails(block);\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\tcontent: block.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else if (block.type === \"toolCall\") {\n\t\t\t\t\tif (block.customInput) {\n\t\t\t\t\t\tconst delta = appendCustomToolCallInput(block, getCustomToolCallInput(block), true);\n\t\t\t\t\t\tif (delta !== undefined) {\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tblock.arguments = parseStreamingJson(block.partialArgs);\n\t\t\t\t\t}\n\t\t\t\t\t// Finalize in-place and strip the scratch buffers so replay only\n\t\t\t\t\t// carries parsed arguments.\n\t\t\t\t\tdelete block.partialArgs;\n\t\t\t\t\tdelete block.customInput;\n\t\t\t\t\tdelete block.streamIndex;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst ensureTextBlock = () => {\n\t\t\t\tif (!textBlock) {\n\t\t\t\t\ttextBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\tblocks.push(textBlock);\n\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: getContentIndex(textBlock), partial: output });\n\t\t\t\t}\n\t\t\t\treturn textBlock;\n\t\t\t};\n\t\t\tconst ensureThinkingBlock = (thinkingSignature: string) => {\n\t\t\t\tif (!thinkingBlock) {\n\t\t\t\t\tthinkingBlock = {\n\t\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\t\tthinking: \"\",\n\t\t\t\t\t\tthinkingSignature,\n\t\t\t\t\t};\n\t\t\t\t\tblocks.push(thinkingBlock);\n\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: getContentIndex(thinkingBlock), partial: output });\n\t\t\t\t}\n\t\t\t\treturn thinkingBlock;\n\t\t\t};\n\t\t\tconst ensureToolCallBlock = (toolCall: StreamingToolCallDelta) => {\n\t\t\t\tconst streamIndex = typeof toolCall.index === \"number\" ? toolCall.index : undefined;\n\t\t\t\tconst name = toolCall.function?.name ?? toolCall.custom?.name ?? \"\";\n\t\t\t\tlet block = streamIndex !== undefined ? toolCallBlocksByIndex.get(streamIndex) : undefined;\n\t\t\t\tif (!block && toolCall.id) {\n\t\t\t\t\tblock = toolCallBlocksById.get(toolCall.id);\n\t\t\t\t}\n\t\t\t\tif (!block) {\n\t\t\t\t\t// Note: the \"input\" fallback here should/must not be taken. in case the LLM makes up\n\t\t\t\t\t// a tool we don't knwo about, we at least have a place to stash our stuff.\n\t\t\t\t\tconst customInputProperty =\n\t\t\t\t\t\ttoolCall.custom && !toolCall.function ? (grammarToolInputProperties.get(name) ?? \"input\") : undefined;\n\t\t\t\t\tconst hasCustomInput = customInputProperty !== undefined;\n\t\t\t\t\tblock = {\n\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\tid: toolCall.id || \"\",\n\t\t\t\t\t\tname,\n\t\t\t\t\t\targuments: hasCustomInput ? { [customInputProperty]: \"\" } : {},\n\t\t\t\t\t\tpartialArgs: hasCustomInput ? undefined : \"\",\n\t\t\t\t\t\tcustomInput: hasCustomInput\n\t\t\t\t\t\t\t? { property: customInputProperty, jsonBuffer: { input: \"\", started: false, closed: false } }\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tstreamIndex,\n\t\t\t\t\t};\n\t\t\t\t\tif (streamIndex !== undefined) {\n\t\t\t\t\t\ttoolCallBlocksByIndex.set(streamIndex, block);\n\t\t\t\t\t}\n\t\t\t\t\tif (toolCall.id) {\n\t\t\t\t\t\ttoolCallBlocksById.set(toolCall.id, block);\n\t\t\t\t\t}\n\t\t\t\t\tblocks.push(block);\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_start\",\n\t\t\t\t\t\tcontentIndex: getContentIndex(block),\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (streamIndex !== undefined && block.streamIndex === undefined) {\n\t\t\t\t\tblock.streamIndex = streamIndex;\n\t\t\t\t\ttoolCallBlocksByIndex.set(streamIndex, block);\n\t\t\t\t}\n\t\t\t\tif (toolCall.id) {\n\t\t\t\t\ttoolCallBlocksById.set(toolCall.id, block);\n\t\t\t\t}\n\t\t\t\tif (!block.name && name) {\n\t\t\t\t\tblock.name = name;\n\t\t\t\t}\n\t\t\t\tif (toolCall.custom && !toolCall.function && !block.customInput) {\n\t\t\t\t\tconst customInputProperty = grammarToolInputProperties.get(block.name) ?? \"input\";\n\t\t\t\t\tblock.arguments = { [customInputProperty]: \"\" };\n\t\t\t\t\tblock.customInput = {\n\t\t\t\t\t\tproperty: customInputProperty,\n\t\t\t\t\t\tjsonBuffer: { input: \"\", started: false, closed: false },\n\t\t\t\t\t};\n\t\t\t\t\tdelete block.partialArgs;\n\t\t\t\t}\n\t\t\t\treturn block;\n\t\t\t};\n\n\t\t\tfor await (const chunk of openaiStream) {\n\t\t\t\tawait options?.onProviderStreamEvent?.(chunk, model);\n\t\t\t\tif (!chunk || typeof chunk !== \"object\") continue;\n\n\t\t\t\t// OpenAI documents ChatCompletionChunk.id as the unique chat completion identifier,\n\t\t\t\t// and each chunk in a streamed completion carries the same id.\n\t\t\t\toutput.responseId ||= chunk.id;\n\t\t\t\tif (typeof chunk.model === \"string\" && chunk.model.length > 0 && chunk.model !== model.id) {\n\t\t\t\t\toutput.responseModel ||= chunk.model;\n\t\t\t\t}\n\t\t\t\tif (chunk.usage) {\n\t\t\t\t\toutput.usage = parseChunkUsage(chunk.usage, model);\n\t\t\t\t}\n\n\t\t\t\tconst choice = Array.isArray(chunk.choices) ? chunk.choices[0] : undefined;\n\t\t\t\tif (!choice) continue;\n\n\t\t\t\t// Fallback: some providers (e.g., Moonshot) return usage\n\t\t\t\t// in choice.usage instead of the standard chunk.usage\n\t\t\t\tif (!chunk.usage && (choice as any).usage) {\n\t\t\t\t\toutput.usage = parseChunkUsage((choice as any).usage, model);\n\t\t\t\t}\n\n\t\t\t\tif (choice.finish_reason) {\n\t\t\t\t\toutput.rawStopReason = choice.finish_reason;\n\t\t\t\t\tconst finishReasonResult = mapStopReason(choice.finish_reason);\n\t\t\t\t\toutput.stopReason = finishReasonResult.stopReason;\n\t\t\t\t\tif (finishReasonResult.errorMessage) {\n\t\t\t\t\t\toutput.errorMessage = finishReasonResult.errorMessage;\n\t\t\t\t\t}\n\t\t\t\t\thasFinishReason = true;\n\t\t\t\t}\n\n\t\t\t\tif (choice.delta) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tchoice.delta.content !== null &&\n\t\t\t\t\t\tchoice.delta.content !== undefined &&\n\t\t\t\t\t\tchoice.delta.content.length > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst block = ensureTextBlock();\n\t\t\t\t\t\tblock.text += choice.delta.content;\n\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\tcontentIndex: getContentIndex(block),\n\t\t\t\t\t\t\tdelta: choice.delta.content,\n\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// Some endpoints return reasoning in reasoning_content (llama.cpp),\n\t\t\t\t\t// or reasoning (other openai compatible endpoints)\n\t\t\t\t\t// Use the first non-empty reasoning field to avoid duplication\n\t\t\t\t\t// (e.g., chutes.ai returns both reasoning_content and reasoning with same content)\n\t\t\t\t\tconst reasoningFields = [\"reasoning_content\", \"reasoning\", \"reasoning_text\"];\n\t\t\t\t\tconst deltaFields = choice.delta as Record<string, unknown>;\n\t\t\t\t\tlet foundReasoningField: string | null = null;\n\t\t\t\t\tfor (const field of reasoningFields) {\n\t\t\t\t\t\tconst value = deltaFields[field];\n\t\t\t\t\t\tif (typeof value === \"string\" && value.length > 0) {\n\t\t\t\t\t\t\tfoundReasoningField = field;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (foundReasoningField) {\n\t\t\t\t\t\tconst delta = deltaFields[foundReasoningField];\n\t\t\t\t\t\tif (typeof delta === \"string\" && delta.length > 0) {\n\t\t\t\t\t\t\tconst thinkingSignature =\n\t\t\t\t\t\t\t\tmodel.provider === \"opencode-go\" && foundReasoningField === \"reasoning\"\n\t\t\t\t\t\t\t\t\t? \"reasoning_content\"\n\t\t\t\t\t\t\t\t\t: foundReasoningField;\n\t\t\t\t\t\t\tconst block = ensureThinkingBlock(thinkingSignature);\n\t\t\t\t\t\t\tblock.thinking += delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: getContentIndex(block),\n\t\t\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (choice?.delta?.tool_calls) {\n\t\t\t\t\t\tfor (const toolCall of choice.delta.tool_calls as StreamingToolCallDelta[]) {\n\t\t\t\t\t\t\tconst block = ensureToolCallBlock(toolCall);\n\t\t\t\t\t\t\tif (!block.id && toolCall.id) {\n\t\t\t\t\t\t\t\tblock.id = toolCall.id;\n\t\t\t\t\t\t\t\ttoolCallBlocksById.set(toolCall.id, block);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst name = toolCall.function?.name ?? toolCall.custom?.name;\n\t\t\t\t\t\t\tif (!block.name && name) {\n\t\t\t\t\t\t\t\tblock.name = name;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet delta = \"\";\n\t\t\t\t\t\t\tif (toolCall.function?.arguments) {\n\t\t\t\t\t\t\t\tdelta = toolCall.function.arguments;\n\t\t\t\t\t\t\t\tblock.partialArgs = (block.partialArgs ?? \"\") + toolCall.function.arguments;\n\t\t\t\t\t\t\t\tblock.arguments = parseStreamingJson(block.partialArgs);\n\t\t\t\t\t\t\t} else if (toolCall.custom?.input) {\n\t\t\t\t\t\t\t\tconst nextInput = getCustomToolCallInput(block) + toolCall.custom.input;\n\t\t\t\t\t\t\t\tdelta = appendCustomToolCallInput(block, nextInput, false) ?? \"\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: getContentIndex(block),\n\t\t\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst reasoningDetails = (choice.delta as { reasoning_details?: unknown }).reasoning_details;\n\t\t\t\t\tif (Array.isArray(reasoningDetails)) {\n\t\t\t\t\t\tfor (const detail of reasoningDetails) {\n\t\t\t\t\t\t\tif (!isOpenAIReasoningDetail(detail)) continue;\n\t\t\t\t\t\t\tensureThinkingBlock(\"\");\n\t\t\t\t\t\t\tstreamedReasoningDetails ??= [];\n\t\t\t\t\t\t\t// Keep provider replay data in the existing signature slot. OpenRouter streams\n\t\t\t\t\t\t\t// reasoning_details as deltas: consecutive text/summary deltas are merged into\n\t\t\t\t\t\t\t// logical entries, while encrypted entries remain opaque and discrete.\n\t\t\t\t\t\t\tappendOpenAIReasoningDetail(streamedReasoningDetails, detail);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const block of blocks) {\n\t\t\t\tfinishBlock(block);\n\t\t\t}\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\") {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\t\t\tif (!hasFinishReason && !compat.supportsFinishReason) {\n\t\t\t\toutput.stopReason = output.content.some((block) => block.type === \"toolCall\") ? \"toolUse\" : \"stop\";\n\t\t\t}\n\t\t\tif (output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"Provider returned an error stop reason\");\n\t\t\t}\n\t\t\tif ((compat.supportsFinishReason && !hasFinishReason) || output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Stream ended without finish_reason\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tapplyStreamedReasoningDetails(block);\n\t\t\t\t}\n\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t// Streaming scratch buffers are only used during parsing; never persist them.\n\t\t\t\tdelete (block as { partialArgs?: string }).partialArgs;\n\t\t\t\tdelete (block as { customInput?: unknown }).customInput;\n\t\t\t\tdelete (block as { streamIndex?: number }).streamIndex;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error));\n\t\t\t// Some providers via OpenRouter give additional information in this field.\n\t\t\t// normalizeProviderError already stringifies the parsed body (error.error)\n\t\t\t// into errorMessage, so only append the raw metadata when it is not already\n\t\t\t// present to avoid double-printing it.\n\t\t\tconst rawMetadata = (error as any)?.error?.metadata?.raw;\n\t\t\tif (rawMetadata && !output.errorMessage.includes(String(rawMetadata))) {\n\t\t\t\toutput.errorMessage += `\\n${rawMetadata}`;\n\t\t\t}\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimple: StreamFunction<\"openai-completions\", SimpleStreamOptions> = (\n\tmodel: Model<\"openai-completions\">,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tgetClientApiKey(model.provider, options?.apiKey, options?.headers);\n\n\tconst base = {\n\t\t...buildBaseOptions(model, context, options, options?.apiKey),\n\t\ttoolChoice: options?.toolChoice,\n\t} satisfies OpenAICompletionsOptions;\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoningEffort = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t\tthinkingBudgets: options?.thinkingBudgets,\n\t} satisfies OpenAICompletionsOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"openai-completions\">,\n\tcontext: TranscriptContext,\n\tapiKey: string,\n\toptionsHeaders?: ProviderHeaders,\n\tfetch?: typeof globalThis.fetch,\n\tsessionId?: string,\n\tcompat: ResolvedOpenAICompletionsCompat = getCompat(model),\n) {\n\tconst headers: ProviderHeaders = { \"User-Agent\": getNyanUserAgent(), ...model.headers };\n\tif (model.provider === \"github-copilot\") {\n\t\tconst hasImages = hasCopilotVisionInput(context.messages);\n\t\tconst copilotHeaders = buildCopilotDynamicHeaders({\n\t\t\tmessages: context.messages,\n\t\t\thasImages,\n\t\t});\n\t\tObject.assign(headers, copilotHeaders);\n\t}\n\n\tif (sessionId && compat.sendSessionAffinityHeaders) {\n\t\tif (compat.sessionAffinityFormat === \"openrouter\") {\n\t\t\theaders[\"x-session-id\"] = sessionId;\n\t\t} else {\n\t\t\tif (compat.sessionAffinityFormat === \"openai\") {\n\t\t\t\theaders.session_id = sessionId;\n\t\t\t}\n\t\t\theaders[\"x-client-request-id\"] = sessionId;\n\t\t\theaders[\"x-session-affinity\"] = sessionId;\n\t\t}\n\t}\n\n\t// Merge options headers last so they can override defaults\n\tif (optionsHeaders) {\n\t\tObject.assign(headers, optionsHeaders);\n\t}\n\n\treturn new OpenAI({\n\t\tapiKey,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tfetch,\n\t\tdefaultHeaders: headers,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"openai-completions\">,\n\tcontext: TranscriptContext,\n\toptions?: OpenAICompletionsOptions,\n\tcompat: ResolvedOpenAICompletionsCompat = getCompat(model),\n\tcacheRetention: CacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env),\n\tgrammarToolInputProperties: ReadonlyMap<string, string> = createGrammarToolInputProperties(\n\t\tgetDeclaredTools(context.messages),\n\t\tcompat.supportsOpenAIGrammarTools,\n\t),\n) {\n\tconst transcriptTools = resolveTranscriptTools(\n\t\tcontext.messages,\n\t\tcompat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true,\n\t);\n\tconst messages = convertMessages(model, context, compat, {\n\t\tgrammarToolInputProperties,\n\t});\n\tconst cacheControl = getCompatCacheControl(compat, cacheRetention);\n\n\tconst params: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {\n\t\tmodel: model.id,\n\t\tmessages,\n\t\tstream: true,\n\t\tprompt_cache_key:\n\t\t\t(model.baseUrl.includes(\"api.openai.com\") && cacheRetention !== \"none\") ||\n\t\t\t(cacheRetention === \"long\" && compat.supportsLongCacheRetention)\n\t\t\t\t? clampOpenAIPromptCacheKey(options?.sessionId)\n\t\t\t\t: undefined,\n\t\tprompt_cache_retention: cacheRetention === \"long\" && compat.supportsLongCacheRetention ? \"24h\" : undefined,\n\t};\n\n\tif (compat.supportsUsageInStreaming !== false) {\n\t\tparams.stream_options = { include_usage: true };\n\t}\n\n\tif (compat.supportsStore) {\n\t\tparams.store = false;\n\t}\n\n\tif (options?.maxTokens) {\n\t\tif (compat.maxTokensField === \"max_tokens\") {\n\t\t\t// Deprecated by OpenAI, but some OpenAI-compatible providers only accept max_tokens.\n\t\t\t(params as { max_tokens?: number }).max_tokens = options.maxTokens;\n\t\t} else {\n\t\t\tparams.max_completion_tokens = options.maxTokens;\n\t\t}\n\t}\n\n\tif (options?.temperature !== undefined) {\n\t\tparams.temperature = options.temperature;\n\t}\n\n\tif (transcriptTools.requestTools.length > 0) {\n\t\tparams.tools = convertTools(transcriptTools.requestTools, compat);\n\t\tif (compat.zaiToolStream) {\n\t\t\t(params as any).tool_stream = true;\n\t\t}\n\t} else if (hasToolHistory(context.messages)) {\n\t\t// Anthropic (via LiteLLM/proxy) requires tools param when conversation has tool_calls/tool_results\n\t\tparams.tools = [];\n\t}\n\n\tif (cacheControl) {\n\t\tapplyAnthropicCacheControl(messages, params.tools, cacheControl);\n\t}\n\n\tif (options?.toolChoice) {\n\t\tparams.tool_choice = options.toolChoice;\n\t}\n\n\tif (compat.vllmPriority !== undefined) {\n\t\t(params as any).priority = compat.vllmPriority;\n\t}\n\n\tconst thinkingTokenBudgetField = resolveThinkingTokenBudgetField(compat);\n\tconst thinkingBudget = resolveClampedThinkingBudget(model, options, params);\n\n\tif (compat.thinkingFormat === \"zai\" && model.reasoning) {\n\t\tconst zaiParams = params as Omit<typeof params, \"reasoning_effort\"> & {\n\t\t\tthinking?: { type: \"enabled\" | \"disabled\"; clear_thinking?: boolean };\n\t\t\treasoning_effort?: string;\n\t\t};\n\t\tzaiParams.thinking = options?.reasoningEffort ? { type: \"enabled\", clear_thinking: false } : { type: \"disabled\" };\n\t\tif (options?.reasoningEffort && compat.supportsReasoningEffort) {\n\t\t\tconst mappedEffort = model.thinkingLevelMap?.[options.reasoningEffort];\n\t\t\tconst effort = mappedEffort === undefined ? options.reasoningEffort : mappedEffort;\n\t\t\tif (typeof effort === \"string\") {\n\t\t\t\tzaiParams.reasoning_effort = effort;\n\t\t\t}\n\t\t}\n\t} else if (compat.thinkingFormat === \"qwen\" && model.reasoning) {\n\t\t(params as any).enable_thinking = !!options?.reasoningEffort;\n\t\tif (options?.reasoningEffort && compat.supportsReasoningEffort) {\n\t\t\tconst effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n\t\t\tif (typeof effort === \"string\") {\n\t\t\t\t(params as any).reasoning_effort = effort;\n\t\t\t}\n\t\t}\n\t} else if (compat.thinkingFormat === \"qwen-chat-template\" && model.reasoning) {\n\t\t(params as any).chat_template_kwargs = {\n\t\t\tenable_thinking: !!options?.reasoningEffort,\n\t\t\tpreserve_thinking: true,\n\t\t};\n\t} else if (compat.thinkingFormat === \"chat-template\" && model.reasoning) {\n\t\tconst chatTemplateKwargs = buildChatTemplateValues(model, options, compat.chatTemplateKwargs, thinkingBudget);\n\t\tif (chatTemplateKwargs) {\n\t\t\t(params as any).chat_template_kwargs = chatTemplateKwargs;\n\t\t}\n\t} else if (compat.thinkingFormat === \"baseten\" && model.reasoning) {\n\t\tconst basetenParams = params as Omit<typeof params, \"reasoning_effort\"> & {\n\t\t\tchat_template_args?: Record<string, ResolvedChatTemplateKwargValue>;\n\t\t\treasoning_effort?: string;\n\t\t};\n\t\tconst chatTemplateArgs = buildChatTemplateValues(model, options, compat.chatTemplateArgs, thinkingBudget);\n\t\tif (chatTemplateArgs) {\n\t\t\tbasetenParams.chat_template_args = chatTemplateArgs;\n\t\t}\n\t\tif (compat.supportsReasoningEffort) {\n\t\t\tconst requestedEffort = options?.reasoningEffort;\n\t\t\tconst mappedEffort = requestedEffort ? model.thinkingLevelMap?.[requestedEffort] : model.thinkingLevelMap?.off;\n\t\t\tconst effort = mappedEffort === undefined ? requestedEffort : mappedEffort;\n\t\t\tif (typeof effort === \"string\") {\n\t\t\t\tbasetenParams.reasoning_effort = effort;\n\t\t\t}\n\t\t}\n\t} else if (compat.thinkingFormat === \"deepseek\" && model.reasoning) {\n\t\tif (options?.reasoningEffort) {\n\t\t\t(params as any).thinking = { type: \"enabled\" };\n\t\t} else if (model.thinkingLevelMap?.off !== null) {\n\t\t\t(params as any).thinking = { type: \"disabled\" };\n\t\t}\n\t\tif (options?.reasoningEffort && compat.supportsReasoningEffort) {\n\t\t\t(params as any).reasoning_effort =\n\t\t\t\tmodel.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n\t\t}\n\t} else if (compat.thinkingFormat === \"openrouter\" && model.reasoning) {\n\t\t// OpenRouter normalizes reasoning across providers via a nested reasoning object.\n\t\tconst openRouterParams = params as typeof params & { reasoning?: { effort?: string } };\n\t\tif (options?.reasoningEffort) {\n\t\t\topenRouterParams.reasoning = {\n\t\t\t\teffort: model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort,\n\t\t\t};\n\t\t} else if (model.thinkingLevelMap?.off !== null) {\n\t\t\topenRouterParams.reasoning = { effort: model.thinkingLevelMap?.off ?? \"none\" };\n\t\t}\n\t} else if (compat.thinkingFormat === \"ant-ling\" && model.reasoning && options?.reasoningEffort) {\n\t\tconst effort = model.thinkingLevelMap?.[options.reasoningEffort];\n\t\tif (typeof effort === \"string\") {\n\t\t\t(params as typeof params & { reasoning?: { effort: string } }).reasoning = { effort };\n\t\t}\n\t} else if (compat.thinkingFormat === \"together\" && model.reasoning) {\n\t\tconst togetherParams = params as Omit<typeof params, \"reasoning_effort\"> & {\n\t\t\treasoning?: { enabled: boolean };\n\t\t\treasoning_effort?: string;\n\t\t};\n\t\ttogetherParams.reasoning = { enabled: !!options?.reasoningEffort };\n\t\tif (options?.reasoningEffort && compat.supportsReasoningEffort) {\n\t\t\ttogetherParams.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n\t\t}\n\t} else if (compat.thinkingFormat === \"string-thinking\" && model.reasoning) {\n\t\tconst stringThinkingParams = params as typeof params & { thinking?: string };\n\t\tif (options?.reasoningEffort) {\n\t\t\tstringThinkingParams.thinking = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n\t\t} else if (model.thinkingLevelMap?.off !== null) {\n\t\t\tstringThinkingParams.thinking = model.thinkingLevelMap?.off ?? \"none\";\n\t\t}\n\t} else if (options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {\n\t\t// OpenAI-style reasoning_effort\n\t\t(params as any).reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n\t} else if (!options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {\n\t\tconst offValue = model.thinkingLevelMap?.off;\n\t\tif (typeof offValue === \"string\") {\n\t\t\t(params as any).reasoning_effort = offValue;\n\t\t}\n\t}\n\n\t// Cap reasoning with a top-level budget field. Independent of thinkingFormat: the\n\t// same server can serve zai, qwen or chat-template models. Reasoning and the answer\n\t// share max_tokens here, so an uncapped reasoning phase can consume the whole\n\t// response and leave no answer and no tool call.\n\tif (thinkingTokenBudgetField && thinkingBudget !== undefined) {\n\t\tObject.assign(params, { [thinkingTokenBudgetField]: thinkingBudget });\n\t}\n\n\t// OpenRouter provider routing preferences\n\tif (model.compat?.openRouterRouting) {\n\t\t(params as any).provider = model.compat.openRouterRouting;\n\t}\n\n\t// Vercel AI Gateway provider routing preferences\n\tif (model.compat?.vercelGatewayRouting) {\n\t\tconst routing = model.compat.vercelGatewayRouting;\n\t\tif (routing.only || routing.order) {\n\t\t\tconst gatewayOptions: Record<string, string[]> = {};\n\t\t\tif (routing.only) gatewayOptions.only = routing.only;\n\t\t\tif (routing.order) gatewayOptions.order = routing.order;\n\t\t\t(params as any).providerOptions = { gateway: gatewayOptions };\n\t\t}\n\t}\n\n\t// Last so model and request sampling parameters override named request fields.\n\tconst samplingParams = resolveSamplingParams(model, options?.reasoningEffort ?? \"off\", options?.samplingParams);\n\tif (samplingParams) {\n\t\tObject.assign(params, samplingParams);\n\t}\n\n\treturn params;\n}\n\nfunction resolveThinkingTokenBudgetField(\n\tcompat: Pick<OpenAICompletionsCompat, \"thinkingTokenBudgetField\" | \"supportsThinkingTokenBudget\">,\n): ThinkingTokenBudgetField | undefined {\n\tif (compat.thinkingTokenBudgetField) return compat.thinkingTokenBudgetField;\n\tif (compat.supportsThinkingTokenBudget) return \"thinking_token_budget\";\n\treturn undefined;\n}\n\nfunction resolveClampedThinkingBudget(\n\tmodel: Model<\"openai-completions\">,\n\toptions: OpenAICompletionsOptions | undefined,\n\tparams: { max_tokens?: number | null; max_completion_tokens?: number | null },\n): number | undefined {\n\tif (!options?.reasoningEffort || !model.reasoning) return undefined;\n\tconst ceiling = params.max_tokens ?? params.max_completion_tokens ?? model.maxTokens;\n\tconst budget = clampThinkingBudgetToAnswerRoom(\n\t\tthinkingBudgetForLevel(options.reasoningEffort, options.thinkingBudgets),\n\t\tceiling,\n\t);\n\treturn budget > 0 ? budget : undefined;\n}\n\nfunction buildChatTemplateValues(\n\tmodel: Model<\"openai-completions\">,\n\toptions: OpenAICompletionsOptions | undefined,\n\tvalues: Record<string, ChatTemplateKwargValue>,\n\tthinkingBudget?: number,\n): Record<string, ResolvedChatTemplateKwargValue> | undefined {\n\tconst resolvedValues: Record<string, ResolvedChatTemplateKwargValue> = {};\n\n\tfor (const [key, value] of Object.entries(values)) {\n\t\tconst resolved = resolveChatTemplateKwargValue(model, options, value, thinkingBudget);\n\t\tif (resolved !== undefined) {\n\t\t\tresolvedValues[key] = resolved;\n\t\t}\n\t}\n\n\treturn Object.keys(resolvedValues).length > 0 ? resolvedValues : undefined;\n}\n\nfunction resolveChatTemplateKwargValue(\n\tmodel: Model<\"openai-completions\">,\n\toptions: OpenAICompletionsOptions | undefined,\n\tvalue: ChatTemplateKwargValue,\n\tthinkingBudget?: number,\n): ResolvedChatTemplateKwargValue | undefined {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn value;\n\t}\n\n\tconst reasoningEffort = options?.reasoningEffort;\n\tif (!reasoningEffort && value.omitWhenOff) {\n\t\treturn undefined;\n\t}\n\tif (value.$var === \"thinking.enabled\") {\n\t\treturn !!reasoningEffort;\n\t}\n\tif (value.$var === \"thinking.budget\") {\n\t\treturn thinkingBudget;\n\t}\n\n\tconst mappedValue = reasoningEffort ? model.thinkingLevelMap?.[reasoningEffort] : model.thinkingLevelMap?.off;\n\treturn mappedValue === undefined ? reasoningEffort : typeof mappedValue === \"string\" ? mappedValue : undefined;\n}\n\nfunction getCompatCacheControl(\n\tcompat: ResolvedOpenAICompletionsCompat,\n\tcacheRetention: CacheRetention,\n): OpenAICompatCacheControl | undefined {\n\tif (compat.cacheControlFormat !== \"anthropic\" || cacheRetention === \"none\") {\n\t\treturn undefined;\n\t}\n\n\tconst ttl = cacheRetention === \"long\" && compat.supportsLongCacheRetention ? \"1h\" : undefined;\n\treturn { type: \"ephemeral\", ...(ttl ? { ttl } : {}) };\n}\n\nfunction applyAnthropicCacheControl(\n\tmessages: ChatCompletionMessageParam[],\n\ttools: OpenAI.Chat.Completions.ChatCompletionTool[] | undefined,\n\tcacheControl: OpenAICompatCacheControl,\n): void {\n\taddCacheControlToSystemPrompt(messages, cacheControl);\n\taddCacheControlToLastTool(tools, cacheControl);\n\taddCacheControlToLastConversationMessage(messages, cacheControl);\n}\n\nfunction addCacheControlToSystemPrompt(\n\tmessages: ChatCompletionMessageParam[],\n\tcacheControl: OpenAICompatCacheControl,\n): void {\n\tfor (const message of messages) {\n\t\tif (message.role === \"system\" || message.role === \"developer\") {\n\t\t\taddCacheControlToInstructionMessage(message, cacheControl);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nfunction addCacheControlToLastConversationMessage(\n\tmessages: ChatCompletionMessageParam[],\n\tcacheControl: OpenAICompatCacheControl,\n): void {\n\tfor (let i = messages.length - 1; i >= 0; i--) {\n\t\tconst message = messages[i];\n\t\tif (message.role === \"user\" || message.role === \"assistant\" || message.role === \"tool\") {\n\t\t\tif (addCacheControlToMessage(message, cacheControl)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction addCacheControlToLastTool(\n\ttools: OpenAI.Chat.Completions.ChatCompletionTool[] | undefined,\n\tcacheControl: OpenAICompatCacheControl,\n): void {\n\tif (!tools || tools.length === 0) {\n\t\treturn;\n\t}\n\n\tconst lastTool = tools[tools.length - 1] as ChatCompletionToolWithCacheControl;\n\tlastTool.cache_control = cacheControl;\n}\n\nfunction addCacheControlToInstructionMessage(\n\tmessage: ChatCompletionInstructionMessageParam,\n\tcacheControl: OpenAICompatCacheControl,\n): boolean {\n\treturn addCacheControlToTextContent(message, cacheControl);\n}\n\nfunction addCacheControlToMessage(\n\tmessage: ChatCompletionMessageParam,\n\tcacheControl: OpenAICompatCacheControl,\n): boolean {\n\tif (message.role === \"user\" || message.role === \"assistant\" || message.role === \"tool\") {\n\t\treturn addCacheControlToTextContent(message, cacheControl);\n\t}\n\treturn false;\n}\n\nfunction addCacheControlToTextContent(\n\tmessage:\n\t\t| ChatCompletionInstructionMessageParam\n\t\t| ChatCompletionAssistantMessageParam\n\t\t| ChatCompletionToolMessageParam\n\t\t| Extract<ChatCompletionMessageParam, { role: \"user\" }>,\n\tcacheControl: OpenAICompatCacheControl,\n): boolean {\n\tconst content = message.content;\n\tif (typeof content === \"string\") {\n\t\tif (content.length === 0) {\n\t\t\treturn false;\n\t\t}\n\t\tmessage.content = [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: content,\n\t\t\t\tcache_control: cacheControl,\n\t\t\t},\n\t\t] as ChatCompletionTextPartWithCacheControl[];\n\t\treturn true;\n\t}\n\n\tif (!Array.isArray(content)) {\n\t\treturn false;\n\t}\n\n\tfor (let i = content.length - 1; i >= 0; i--) {\n\t\tconst part = content[i];\n\t\tif (part?.type === \"text\") {\n\t\t\tconst textPart = part as ChatCompletionTextPartWithCacheControl;\n\t\t\ttextPart.cache_control = cacheControl;\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\nexport function convertMessages(\n\tmodel: Model<\"openai-completions\">,\n\tcontext: TranscriptContext,\n\tcompat: ResolvedOpenAICompletionsCompat,\n\toptions?: ConvertCompletionsMessagesOptions,\n): ChatCompletionMessageParam[] {\n\tconst normalizedContext = resolveTranscript(context, compat.supportsMidConvoSystemMessages);\n\tconst params: ChatCompletionMessageParam[] = [];\n\n\tconst normalizeToolCallId = (id: string): string => {\n\t\t// Handle pipe-separated IDs from OpenAI Responses API\n\t\t// Format: {call_id}|{id} where {id} can be 400+ chars with special chars (+, /, =)\n\t\t// These come from providers like github-copilot, openai-codex, opencode\n\t\t// Extract just the call_id part and normalize it\n\t\t// Multiple tool calls in the same turn can share call_id but differ by item_id.\n\t\t// Preserve item-level uniqueness when replaying into Chat Completions, which\n\t\t// requires distinct tool call ids.\n\t\tif (id.includes(\"|\")) {\n\t\t\t// Sanitize to allowed chars and truncate to 40 chars (OpenAI limit)\n\t\t\tconst separatorIndex = id.indexOf(\"|\");\n\t\t\tconst callId = id.slice(0, separatorIndex).replace(/[^a-zA-Z0-9_-]/g, \"_\");\n\t\t\tconst itemId = id.slice(separatorIndex + 1).replace(/[^a-zA-Z0-9_-]/g, \"_\");\n\t\t\tconst combinedId = itemId.length > 0 ? `${callId}_${itemId}` : callId;\n\t\t\tif (combinedId.length <= 40) {\n\t\t\t\treturn combinedId;\n\t\t\t}\n\t\t\tconst hash = shortHash(id).slice(0, 8);\n\t\t\tconst prefix = callId.slice(0, Math.max(1, 40 - hash.length - 1));\n\t\t\treturn `${prefix}_${hash}`;\n\t\t}\n\n\t\tif (model.provider === \"openai\") return id.length > 40 ? id.slice(0, 40) : id;\n\t\treturn id;\n\t};\n\n\tconst transformedMessages = transformMessages(normalizedContext.messages, model, (id) => normalizeToolCallId(id));\n\tconst transcriptTools = resolveTranscriptTools(\n\t\tnormalizedContext.messages,\n\t\tcompat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true,\n\t);\n\tconst instructionRole = model.reasoning && compat.supportsDeveloperRole ? \"developer\" : \"system\";\n\n\tlet lastRole: string | null = null;\n\n\tfor (let i = 0; i < transformedMessages.length; i++) {\n\t\tconst msg = transformedMessages[i];\n\t\t// Some providers don't allow user messages directly after tool results\n\t\t// Insert a synthetic assistant message to bridge the gap\n\t\tif (compat.requiresAssistantAfterToolResult && lastRole === \"toolResult\" && msg.role === \"user\") {\n\t\t\tparams.push({\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: \"I have processed the tool results.\",\n\t\t\t});\n\t\t}\n\n\t\tif (msg.role === \"system\") {\n\t\t\tconst addedTools = i > 0 && transcriptTools.anchorsAdditions ? (msg.toolsAdded ?? []) : [];\n\t\t\tif (addedTools.length > 0) {\n\t\t\t\tconst kimiToolMessage: KimiToolSystemMessageParam = {\n\t\t\t\t\trole: \"system\",\n\t\t\t\t\ttools: convertTools(addedTools, compat),\n\t\t\t\t};\n\t\t\t\tparams.push(kimiToolMessage as unknown as ChatCompletionMessageParam);\n\t\t\t}\n\t\t\tconst text = i === 0 ? getSystemMessageText(msg) : renderSystemMessageUpdate(msg);\n\t\t\tif (text.length > 0) {\n\t\t\t\tparams.push({ role: instructionRole, content: sanitizeSurrogates(text) });\n\t\t\t}\n\t\t} else if (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tparams.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: sanitizeSurrogates(msg.content),\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst content: ChatCompletionContentPart[] = msg.content\n\t\t\t\t\t.filter((item) => item.type !== \"text\" || item.text.length > 0)\n\t\t\t\t\t.map((item): ChatCompletionContentPart => {\n\t\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: sanitizeSurrogates(item.text),\n\t\t\t\t\t\t\t} satisfies ChatCompletionContentPartText;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\t\t\turl: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} satisfies ChatCompletionContentPartImage;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\tif (content.length === 0) continue;\n\t\t\t\tparams.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\t// Some providers don't accept null content, use empty string instead\n\t\t\tconst assistantMsg: ChatCompletionAssistantMessageParamWithReasoning = {\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: compat.requiresAssistantAfterToolResult ? \"\" : null,\n\t\t\t};\n\n\t\t\tconst assistantTextParts = msg.content\n\t\t\t\t.filter(isTextContentBlock)\n\t\t\t\t.filter((block) => block.text.trim().length > 0)\n\t\t\t\t.map(\n\t\t\t\t\t(block) =>\n\t\t\t\t\t\t({\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: sanitizeSurrogates(block.text),\n\t\t\t\t\t\t}) satisfies ChatCompletionContentPartText,\n\t\t\t\t);\n\t\t\tconst assistantText = assistantTextParts.map((part) => part.text).join(\"\");\n\n\t\t\tconst thinkingBlocks = msg.content.filter(isThinkingContentBlock);\n\t\t\tconst toolCalls = msg.content.filter(isToolCallBlock);\n\t\t\tconst signedReasoningDetails = thinkingBlocks\n\t\t\t\t.map((block) => parseOpenAIReasoningDetails(block.thinkingSignature))\n\t\t\t\t.find((details) => details !== undefined);\n\t\t\tconst legacyReasoningDetails = toolCalls\n\t\t\t\t.map((toolCall) => parseLegacyEncryptedReasoningDetail(toolCall.thoughtSignature))\n\t\t\t\t.filter((detail): detail is OpenAIEncryptedReasoningDetail => detail !== undefined);\n\t\t\tconst preservedReasoningDetails =\n\t\t\t\tsignedReasoningDetails ?? (legacyReasoningDetails.length > 0 ? legacyReasoningDetails : undefined);\n\n\t\t\tconst nonEmptyThinkingBlocks = thinkingBlocks.filter((block) => block.thinking.trim().length > 0);\n\t\t\tif (nonEmptyThinkingBlocks.length > 0) {\n\t\t\t\tif (compat.requiresThinkingAsText) {\n\t\t\t\t\t// Convert thinking blocks to plain text (no tags to avoid model mimicking them)\n\t\t\t\t\tconst thinkingText = nonEmptyThinkingBlocks\n\t\t\t\t\t\t.map((block) => sanitizeSurrogates(block.thinking))\n\t\t\t\t\t\t.join(\"\\n\\n\");\n\t\t\t\t\tassistantMsg.content = [{ type: \"text\", text: thinkingText }, ...assistantTextParts];\n\t\t\t\t} else {\n\t\t\t\t\t// Always send assistant content as a plain string (OpenAI Chat Completions\n\t\t\t\t\t// API standard format). Sending as an array of {type:\"text\", text:\"...\"}\n\t\t\t\t\t// objects is non-standard and causes some models (e.g. DeepSeek V3.2 via\n\t\t\t\t\t// NVIDIA NIM) to mirror the content-block structure literally in their\n\t\t\t\t\t// output, producing recursive nesting like [{'type':'text','text':'[{...}]'}].\n\t\t\t\t\tif (assistantText.length > 0) {\n\t\t\t\t\t\tassistantMsg.content = assistantText;\n\t\t\t\t\t}\n\n\t\t\t\t\t// reasoning_details is the structured alternative to a raw reasoning field.\n\t\t\t\t\tif (!preservedReasoningDetails) {\n\t\t\t\t\t\t// Use the signature from the first thinking block if available (for llama.cpp server + gpt-oss)\n\t\t\t\t\t\tlet signature = nonEmptyThinkingBlocks[0].thinkingSignature;\n\t\t\t\t\t\tif (model.provider === \"opencode-go\" && signature === \"reasoning\") {\n\t\t\t\t\t\t\tsignature = \"reasoning_content\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (signature && isOpenAICompletionsReasoningField(signature)) {\n\t\t\t\t\t\t\tassistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join(\"\\n\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (assistantText.length > 0) {\n\t\t\t\t// Always send assistant content as a plain string (OpenAI Chat Completions\n\t\t\t\t// API standard format). Sending as an array of {type:\"text\", text:\"...\"}\n\t\t\t\t// objects is non-standard and causes some models (e.g. DeepSeek V3.2 via\n\t\t\t\t// NVIDIA NIM) to mirror the content-block structure literally in their\n\t\t\t\t// output, producing recursive nesting like [{'type':'text','text':'[{...}]'}].\n\t\t\t\tassistantMsg.content = assistantText;\n\t\t\t}\n\n\t\t\tif (toolCalls.length > 0) {\n\t\t\t\tassistantMsg.tool_calls = toolCalls.map((tc): ChatCompletionMessageToolCall => {\n\t\t\t\t\tconst customInputProperty = options?.grammarToolInputProperties?.get(tc.name);\n\t\t\t\t\tif (customInputProperty !== undefined) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: tc.id,\n\t\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\t\tname: tc.name,\n\t\t\t\t\t\t\t\tinput: sanitizeSurrogates(getGrammarToolInput(tc.name, tc.arguments, customInputProperty)),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tid: tc.id,\n\t\t\t\t\t\ttype: \"function\",\n\t\t\t\t\t\tfunction: {\n\t\t\t\t\t\t\tname: tc.name,\n\t\t\t\t\t\t\targuments: JSON.stringify(tc.arguments),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (preservedReasoningDetails) {\n\t\t\t\tassistantMsg.reasoning_details = preservedReasoningDetails;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tcompat.requiresReasoningContentOnAssistantMessages &&\n\t\t\t\tmodel.reasoning &&\n\t\t\t\tassistantMsg.reasoning_content === undefined\n\t\t\t) {\n\t\t\t\tassistantMsg.reasoning_content = \"\";\n\t\t\t}\n\t\t\t// Skip assistant messages that have no content and no tool calls.\n\t\t\t// Some providers require \"either content or tool_calls, but not none\".\n\t\t\t// Other providers also don't accept empty assistant messages.\n\t\t\t// This handles aborted assistant responses that got no content.\n\t\t\tconst content = assistantMsg.content;\n\t\t\tconst hasContent =\n\t\t\t\tcontent !== null &&\n\t\t\t\tcontent !== undefined &&\n\t\t\t\t(typeof content === \"string\" ? content.length > 0 : content.length > 0);\n\t\t\tif (!hasContent && !assistantMsg.tool_calls) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tparams.push(assistantMsg);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst imageBlocks: Array<{ type: \"image_url\"; image_url: { url: string } }> = [];\n\t\t\tlet j = i;\n\n\t\t\tfor (; j < transformedMessages.length && transformedMessages[j].role === \"toolResult\"; j++) {\n\t\t\t\tconst toolMsg = transformedMessages[j] as ToolResultMessage;\n\n\t\t\t\t// Extract text and image content\n\t\t\t\tconst textResult = toolMsg.content\n\t\t\t\t\t.filter(isTextContentBlock)\n\t\t\t\t\t.map((block) => block.text)\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tconst hasImages = toolMsg.content.some((c) => c.type === \"image\");\n\n\t\t\t\t// Always send tool result with text (or placeholder if only images)\n\t\t\t\tconst hasText = textResult.length > 0;\n\t\t\t\tconst toolResultText = hasText ? textResult : hasImages ? \"(see attached image)\" : \"(no tool output)\";\n\t\t\t\t// Some providers require the 'name' field in tool results\n\t\t\t\tconst toolResultMsg: ChatCompletionToolMessageParam = {\n\t\t\t\t\trole: \"tool\",\n\t\t\t\t\tcontent: sanitizeSurrogates(toolResultText),\n\t\t\t\t\ttool_call_id: toolMsg.toolCallId,\n\t\t\t\t};\n\t\t\t\tif (compat.requiresToolResultName && toolMsg.toolName) {\n\t\t\t\t\t(toolResultMsg as any).name = toolMsg.toolName;\n\t\t\t\t}\n\t\t\t\tparams.push(toolResultMsg);\n\n\t\t\t\tif (hasImages && model.input.includes(\"image\")) {\n\t\t\t\t\tfor (const block of toolMsg.content) {\n\t\t\t\t\t\tif (isImageContentBlock(block)) {\n\t\t\t\t\t\t\timageBlocks.push({\n\t\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\t\t\turl: `data:${block.mimeType};base64,${block.data}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ti = j - 1;\n\n\t\t\tif (imageBlocks.length > 0) {\n\t\t\t\tif (compat.requiresAssistantAfterToolResult) {\n\t\t\t\t\tparams.push({\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\tcontent: \"I have processed the tool results.\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tparams.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: \"Attached image(s) from tool result:\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...imageBlocks,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tlastRole = \"user\";\n\t\t\t} else {\n\t\t\t\tlastRole = \"toolResult\";\n\t\t\t}\n\n\t\t\tcontinue;\n\t\t}\n\n\t\tlastRole = msg.role;\n\t}\n\n\treturn params;\n}\n\nfunction convertTools(\n\ttools: Tool[],\n\tcompat: ResolvedOpenAICompletionsCompat,\n): OpenAI.Chat.Completions.ChatCompletionTool[] {\n\treturn tools.map((tool) => {\n\t\tconst grammar = resolveGrammarConstrainedSampling(tool, compat.supportsOpenAIGrammarTools);\n\t\tif (grammar) {\n\t\t\treturn {\n\t\t\t\ttype: \"custom\",\n\t\t\t\tcustom: {\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\tformat: {\n\t\t\t\t\t\ttype: \"grammar\",\n\t\t\t\t\t\tgrammar: {\n\t\t\t\t\t\t\tsyntax: grammar.format,\n\t\t\t\t\t\t\tdefinition: grammar.definition,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst strict = resolveJsonSchemaStrictSampling(tool, compat.supportsStrictMode !== false);\n\t\treturn {\n\t\t\ttype: \"function\",\n\t\t\tfunction: {\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparameters: getJsonSchemaToolParameters(tool, strict) as Record<string, unknown>,\n\t\t\t\t// Only include strict if provider supports it. Some reject unknown fields.\n\t\t\t\t...(compat.supportsStrictMode !== false && { strict: strict ?? false }),\n\t\t\t},\n\t\t};\n\t});\n}\n\nfunction parseChunkUsage(\n\trawUsage: {\n\t\tprompt_tokens?: number;\n\t\tcompletion_tokens?: number;\n\t\tcached_tokens?: number;\n\t\tprompt_cache_hit_tokens?: number;\n\t\tprompt_tokens_details?: { cached_tokens?: number; cache_write_tokens?: number };\n\t\tcompletion_tokens_details?: { reasoning_tokens?: number };\n\t},\n\tmodel: Model<\"openai-completions\">,\n): AssistantMessage[\"usage\"] {\n\tconst promptTokens = rawUsage.prompt_tokens || 0;\n\tconst cacheReadTokens =\n\t\trawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? 0;\n\tconst cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;\n\n\t// Follow documented OpenAI/OpenRouter semantics: cached_tokens is cache-read\n\t// tokens (hits). Providers disagree on placement: OpenAI/OpenRouter use\n\t// prompt_tokens_details.cached_tokens, DeepSeek uses prompt_cache_hit_tokens,\n\t// and Kimi documents top-level usage.cached_tokens on the final usage chunk.\n\t// OpenAI does not document or emit cache_write_tokens, but\n\t// OpenRouter-compatible providers can include it as a separate write count.\n\t// OpenRouter's own provider/tests affirm the separate mapping:\n\t// https://github.com/OpenRouterTeam/ai-sdk-provider/pull/409\n\t// Do not subtract writes from cached_tokens, otherwise spec-compliant\n\t// providers are under-reported. DS4 mirrors this contract too:\n\t// https://github.com/antirez/ds4/pull/29\n\tconst input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);\n\t// OpenAI completion_tokens already includes reasoning_tokens.\n\tconst outputTokens = rawUsage.completion_tokens || 0;\n\tconst usage: AssistantMessage[\"usage\"] = {\n\t\tinput,\n\t\toutput: outputTokens,\n\t\tcacheRead: cacheReadTokens,\n\t\tcacheWrite: cacheWriteTokens,\n\t\treasoning: rawUsage.completion_tokens_details?.reasoning_tokens || 0,\n\t\ttotalTokens: input + outputTokens + cacheReadTokens + cacheWriteTokens,\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t};\n\tcalculateCost(model, usage);\n\treturn usage;\n}\n\nfunction mapStopReason(reason: ChatCompletionChunk.Choice[\"finish_reason\"] | string): {\n\tstopReason: StopReason;\n\terrorMessage?: string;\n} {\n\tif (reason === null) return { stopReason: \"stop\" };\n\tswitch (reason) {\n\t\tcase \"stop\":\n\t\tcase \"end\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tcase \"length\":\n\t\t\treturn { stopReason: \"length\" };\n\t\tcase \"function_call\":\n\t\tcase \"tool_calls\":\n\t\t\treturn { stopReason: \"toolUse\" };\n\t\tcase \"content_filter\":\n\t\t\treturn { stopReason: \"error\", errorMessage: \"Provider finish_reason: content_filter\" };\n\t\tcase \"network_error\":\n\t\t\treturn { stopReason: \"error\", errorMessage: \"Provider finish_reason: network_error\" };\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tstopReason: \"error\",\n\t\t\t\terrorMessage: `Provider finish_reason: ${reason}`,\n\t\t\t};\n\t}\n}\n\n/**\n * Auto-detect compatibility settings from provider name and baseUrl.\n * Used as the base when model.compat is not set; explicit model.compat\n * entries override these detected values.\n */\nfunction detectCompat(model: Model<\"openai-completions\">): ResolvedOpenAICompletionsCompat {\n\tconst provider = model.provider;\n\tconst baseUrl = model.baseUrl;\n\n\tconst isZai =\n\t\tprovider === \"zai\" ||\n\t\tprovider === \"zai-coding-cn\" ||\n\t\tbaseUrl.includes(\"api.z.ai\") ||\n\t\tbaseUrl.includes(\"open.bigmodel.cn\");\n\tconst isTogether =\n\t\tprovider === \"together\" || baseUrl.includes(\"api.together.ai\") || baseUrl.includes(\"api.together.xyz\");\n\tconst isMoonshot = provider === \"moonshotai\" || provider === \"moonshotai-cn\" || baseUrl.includes(\"api.moonshot.\");\n\tconst isOpenRouter = provider === \"openrouter\" || baseUrl.includes(\"openrouter.ai\");\n\tconst isCloudflareWorkersAI = provider === \"cloudflare-workers-ai\" || baseUrl.includes(\"api.cloudflare.com\");\n\tconst isCloudflareAiGateway = provider === \"cloudflare-ai-gateway\" || baseUrl.includes(\"gateway.ai.cloudflare.com\");\n\tconst isNvidia = provider === \"nvidia\" || baseUrl.includes(\"integrate.api.nvidia.com\");\n\tconst isAntLing = provider === \"ant-ling\" || baseUrl.includes(\"api.ant-ling.com\");\n\tconst isCerebras = provider === \"cerebras\" || baseUrl.includes(\"cerebras.ai\");\n\tconst isDeepSeek = provider === \"deepseek\" || baseUrl.toLowerCase().includes(\"deepseek.com\");\n\n\tconst isNonStandard =\n\t\tisNvidia ||\n\t\tisCerebras ||\n\t\tprovider === \"xai\" ||\n\t\tbaseUrl.includes(\"api.x.ai\") ||\n\t\tisTogether ||\n\t\tbaseUrl.includes(\"chutes.ai\") ||\n\t\tisDeepSeek ||\n\t\tisZai ||\n\t\tisMoonshot ||\n\t\tprovider === \"opencode\" ||\n\t\tbaseUrl.includes(\"opencode.ai\") ||\n\t\tisCloudflareWorkersAI ||\n\t\tisCloudflareAiGateway ||\n\t\tisAntLing;\n\n\tconst useMaxTokens =\n\t\tbaseUrl.includes(\"chutes.ai\") ||\n\t\tisDeepSeek ||\n\t\tisMoonshot ||\n\t\tisCloudflareAiGateway ||\n\t\tisTogether ||\n\t\tisNvidia ||\n\t\tisAntLing ||\n\t\tisZai;\n\n\tconst isGrok = provider === \"xai\" || baseUrl.includes(\"api.x.ai\");\n\tconst isOpenRouterDeveloperRoleModel =\n\t\tisOpenRouter && (model.id.startsWith(\"anthropic/\") || model.id.startsWith(\"openai/\"));\n\tconst cacheControlFormat = provider === \"openrouter\" && model.id.startsWith(\"anthropic/\") ? \"anthropic\" : undefined;\n\n\treturn {\n\t\tsupportsStore: !isNonStandard,\n\t\tsupportsDeveloperRole: isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter),\n\t\tsupportsReasoningEffort:\n\t\t\t!isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,\n\t\tsupportsUsageInStreaming: true,\n\t\tsupportsFinishReason: true,\n\t\tmaxTokensField: useMaxTokens ? \"max_tokens\" : \"max_completion_tokens\",\n\t\trequiresToolResultName: false,\n\t\trequiresAssistantAfterToolResult: false,\n\t\trequiresThinkingAsText: false,\n\t\trequiresReasoningContentOnAssistantMessages: isDeepSeek,\n\t\tthinkingFormat: isDeepSeek\n\t\t\t? \"deepseek\"\n\t\t\t: isZai\n\t\t\t\t? \"zai\"\n\t\t\t\t: isTogether\n\t\t\t\t\t? \"together\"\n\t\t\t\t\t: isAntLing\n\t\t\t\t\t\t? \"ant-ling\"\n\t\t\t\t\t\t: isOpenRouter\n\t\t\t\t\t\t\t? \"openrouter\"\n\t\t\t\t\t\t\t: \"openai\",\n\t\topenRouterRouting: {},\n\t\tvercelGatewayRouting: {},\n\t\tchatTemplateKwargs: {},\n\t\tchatTemplateArgs: {},\n\t\tzaiToolStream: false,\n\t\tsupportsThinkingTokenBudget: false,\n\t\tthinkingTokenBudgetField: undefined,\n\t\t// OpenAI compatibility alone does not imply strict JSON-schema tool support.\n\t\tsupportsStrictMode: false,\n\t\tsupportsOpenAIGrammarTools: false,\n\t\tsupportsMidConvoSystemMessages: false,\n\t\tsupportsMidConvoToolAdditions: false,\n\t\tcacheControlFormat,\n\t\tsendSessionAffinityHeaders: isOpenRouter,\n\t\tsessionAffinityFormat: isOpenRouter ? \"openrouter\" : \"openai\",\n\t\tsupportsLongCacheRetention: !(\n\t\t\tisTogether ||\n\t\t\tisCloudflareWorkersAI ||\n\t\t\tisCloudflareAiGateway ||\n\t\t\tisNvidia ||\n\t\t\tisAntLing\n\t\t),\n\t};\n}\n\n/**\n * Get resolved compatibility settings for a model.\n * Auto-detects from provider/URL then overrides with explicit model.compat.\n */\nfunction getCompat(model: Model<\"openai-completions\">): ResolvedOpenAICompletionsCompat {\n\tconst detected = detectCompat(model);\n\tif (!model.compat) return detected;\n\n\treturn {\n\t\tsupportsStore: model.compat.supportsStore ?? detected.supportsStore,\n\t\tsupportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,\n\t\tsupportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,\n\t\tsupportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,\n\t\tsupportsFinishReason: model.compat.supportsFinishReason ?? detected.supportsFinishReason,\n\t\tmaxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,\n\t\trequiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,\n\t\trequiresAssistantAfterToolResult:\n\t\t\tmodel.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,\n\t\trequiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,\n\t\trequiresReasoningContentOnAssistantMessages:\n\t\t\tmodel.compat.requiresReasoningContentOnAssistantMessages ??\n\t\t\tdetected.requiresReasoningContentOnAssistantMessages,\n\t\tthinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,\n\t\topenRouterRouting: model.compat.openRouterRouting ?? {},\n\t\tvercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,\n\t\tchatTemplateKwargs: model.compat.chatTemplateKwargs ?? detected.chatTemplateKwargs,\n\t\tchatTemplateArgs: model.compat.chatTemplateArgs ?? detected.chatTemplateArgs,\n\t\tzaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,\n\t\tsupportsThinkingTokenBudget: model.compat.supportsThinkingTokenBudget ?? detected.supportsThinkingTokenBudget,\n\t\tthinkingTokenBudgetField: model.compat.thinkingTokenBudgetField ?? detected.thinkingTokenBudgetField,\n\t\tsupportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,\n\t\tsupportsOpenAIGrammarTools: model.compat.supportsOpenAIGrammarTools ?? detected.supportsOpenAIGrammarTools,\n\t\tsupportsMidConvoSystemMessages:\n\t\t\tmodel.compat.supportsMidConvoSystemMessages ?? detected.supportsMidConvoSystemMessages,\n\t\tsupportsMidConvoToolAdditions:\n\t\t\tmodel.compat.supportsMidConvoToolAdditions ?? detected.supportsMidConvoToolAdditions,\n\t\tcacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,\n\t\tsendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,\n\t\tsessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,\n\t\tsupportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,\n\t\tvllmPriority: model.compat.vllmPriority,\n\t};\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { ProviderStreams } from "../types.ts";
2
+ export declare const openAICompletionsApi: () => ProviderStreams;
3
+ //# sourceMappingURL=openai-completions.lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-completions.lazy.d.ts","sourceRoot":"","sources":["../../src/api/openai-completions.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,eAAO,MAAM,oBAAoB,QAAO,eAAmE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { lazyApi } from "./lazy.js";
2
+ export const openAICompletionsApi = () => lazyApi(() => import("./openai-completions.js"));
3
+ //# sourceMappingURL=openai-completions.lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-completions.lazy.js","sourceRoot":"","sources":["../../src/api/openai-completions.lazy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAoB,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC","sourcesContent":["import type { ProviderStreams } from \"../types.ts\";\nimport { lazyApi } from \"./lazy.ts\";\n\nexport const openAICompletionsApi = (): ProviderStreams => lazyApi(() => import(\"./openai-completions.ts\"));\n"]}
@@ -0,0 +1,4 @@
1
+ import type { ClassifierFunction, ClassifierOptions } from "../types.ts";
2
+ /** Classification through OpenAI's Decisions API. */
3
+ export declare const classify: ClassifierFunction<ClassifierOptions>;
4
+ //# sourceMappingURL=openai-decisions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-decisions.d.ts","sourceRoot":"","sources":["../../src/api/openai-decisions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,kBAAkB,EAClB,iBAAiB,EAGjB,MAAM,aAAa,CAAC;AAwJrB,qDAAqD;AACrD,eAAO,MAAM,QAAQ,EAAE,kBAAkB,CAAC,iBAAiB,CAoC1D,CAAC"}
@@ -0,0 +1,162 @@
1
+ import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
2
+ import { isRecord, parseClassifierUsage, postClassifierRequest, requiredNumber, } from "./classifier-shared.js";
3
+ /**
4
+ * OpenAI's Decisions API: `POST /v1/decisions` with `{ model, input, questions }`.
5
+ * https://developers.openai.com/api/docs/guides/decisions
6
+ *
7
+ * The state is sent as JSON text. With images, the input becomes one user message with the state
8
+ * as `input_text` followed by `input_image` data URLs. Questions map to Decisions types:
9
+ * `choice` to `choice`, `score` to `score`, and `bool` to `predicate`. Predicates have no
10
+ * criteria field, so the meanings of true and false are appended to the instructions.
11
+ *
12
+ * Only OpenAI API keys work: Sign in with ChatGPT tokens are rejected on this route.
13
+ */
14
+ const LABEL = "OpenAI Decisions";
15
+ /** The endpoint accepts at most this many image parts per request. */
16
+ const MAX_IMAGES = 128;
17
+ function predicateInstructions(question) {
18
+ const meanings = [
19
+ question.criteria.true ? `True means: ${question.criteria.true}` : "",
20
+ question.criteria.false ? `False means: ${question.criteria.false}` : "",
21
+ ].filter(Boolean);
22
+ return meanings.length > 0 ? `${question.instructions}\n\n${meanings.join("\n")}` : question.instructions;
23
+ }
24
+ function wireQuestion(name, question) {
25
+ if (question.type === "choice") {
26
+ return {
27
+ type: "choice",
28
+ name,
29
+ instructions: question.instructions,
30
+ choices: Object.entries(question.criteria).map(([value, description]) => description ? { value, description } : { value }),
31
+ };
32
+ }
33
+ if (question.type === "score") {
34
+ return {
35
+ type: "score",
36
+ name,
37
+ instructions: question.instructions,
38
+ levels: question.criteria.map((label) => ({ label })),
39
+ };
40
+ }
41
+ return { type: "predicate", name, instructions: predicateInstructions(question) };
42
+ }
43
+ function wireInput(context) {
44
+ const state = JSON.stringify(context.state);
45
+ const images = context.images ?? [];
46
+ if (images.length === 0)
47
+ return state;
48
+ if (images.length > MAX_IMAGES) {
49
+ throw new Error(`${LABEL} accepts at most ${MAX_IMAGES} images, got ${images.length}`);
50
+ }
51
+ return [
52
+ {
53
+ role: "user",
54
+ content: [
55
+ { type: "input_text", text: state },
56
+ ...images.map((image) => ({
57
+ type: "input_image",
58
+ image_url: `data:${image.mimeType};base64,${image.data}`,
59
+ })),
60
+ ],
61
+ },
62
+ ];
63
+ }
64
+ function choiceProbabilities(value, id) {
65
+ if (!Array.isArray(value))
66
+ throw new Error(`${LABEL} returned invalid probabilities for ${id}`);
67
+ return Object.fromEntries(value.map((entry) => {
68
+ if (!isRecord(entry) || typeof entry.value !== "string") {
69
+ throw new Error(`${LABEL} returned invalid probabilities for ${id}`);
70
+ }
71
+ return [entry.value, requiredNumber(LABEL, entry.probability, `probability for ${id}.${entry.value}`)];
72
+ }));
73
+ }
74
+ function parseAnswer(id, question, answer) {
75
+ if (answer.type === "refusal")
76
+ throw new Error(`${LABEL} refused to answer ${id}`);
77
+ if (question.type === "choice") {
78
+ if (answer.type !== "choice" || typeof answer.choice !== "string") {
79
+ throw new Error(`${LABEL} did not return a choice answer for ${id}`);
80
+ }
81
+ return {
82
+ type: "choice",
83
+ choice: answer.choice,
84
+ probabilities: choiceProbabilities(answer.probabilities, id),
85
+ confidence: requiredNumber(LABEL, answer.confidence, `confidence for ${id}`),
86
+ };
87
+ }
88
+ if (question.type === "score") {
89
+ if (answer.type !== "score")
90
+ throw new Error(`${LABEL} did not return a score answer for ${id}`);
91
+ return {
92
+ type: "score",
93
+ score: requiredNumber(LABEL, answer.score, `score for ${id}`),
94
+ confidence: requiredNumber(LABEL, answer.confidence, `confidence for ${id}`),
95
+ };
96
+ }
97
+ if (answer.type !== "predicate")
98
+ throw new Error(`${LABEL} did not return a predicate answer for ${id}`);
99
+ return { type: "bool", probability: requiredNumber(LABEL, answer.probability, `probability for ${id}`) };
100
+ }
101
+ function parseAnswers(value, context) {
102
+ if (!Array.isArray(value))
103
+ throw new Error(`${LABEL} returned an unexpected response`);
104
+ const byName = new Map();
105
+ for (const answer of value) {
106
+ if (isRecord(answer) && typeof answer.name === "string")
107
+ byName.set(answer.name, answer);
108
+ }
109
+ return Object.fromEntries(Object.entries(context.questions).map(([id, question]) => {
110
+ const answer = byName.get(id);
111
+ if (!answer)
112
+ throw new Error(`${LABEL} did not return an answer for ${id}`);
113
+ return [id, parseAnswer(id, question, answer)];
114
+ }));
115
+ }
116
+ /**
117
+ * Cloudflare in front of api.openai.com answers 504 with an HTML page when a request runs longer
118
+ * than about five seconds. Large inputs, currently above roughly 600K tokens, hit this limit, and
119
+ * retrying the same input runs into it again, so 504 is not retried.
120
+ */
121
+ const NO_RETRY_STATUSES = [504];
122
+ function errorMessage(error) {
123
+ if (error.status === 504) {
124
+ return `${LABEL} error (504): the request timed out at the gateway. Very large inputs (above roughly 600K tokens) currently exceed its time limit.`;
125
+ }
126
+ return formatProviderError(normalizeProviderError(error), `${LABEL} error`);
127
+ }
128
+ /** Classification through OpenAI's Decisions API. */
129
+ export const classify = async (model, context, options) => {
130
+ const output = {
131
+ api: model.api,
132
+ provider: model.provider,
133
+ model: model.id,
134
+ answers: {},
135
+ stopReason: "stop",
136
+ timestamp: Date.now(),
137
+ };
138
+ try {
139
+ if (model.api !== "openai-decisions")
140
+ throw new Error(`Unsupported classifier API: ${model.api}`);
141
+ const body = await postClassifierRequest(LABEL, new URL("decisions", `${model.baseUrl.replace(/\/+$/u, "")}/`), model, {
142
+ model: model.id,
143
+ input: wireInput(context),
144
+ questions: Object.entries(context.questions).map(([id, question]) => wireQuestion(id, question)),
145
+ }, options, NO_RETRY_STATUSES);
146
+ if (!isRecord(body))
147
+ throw new Error(`${LABEL} returned an unexpected response`);
148
+ // Set before parsing answers: a request with malformed or refused answers was still billed.
149
+ const usage = parseClassifierUsage(body.usage, model);
150
+ if (usage)
151
+ output.usage = usage;
152
+ output.answers = parseAnswers(body.answers, context);
153
+ return output;
154
+ }
155
+ catch (error) {
156
+ output.answers = {};
157
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
158
+ output.errorMessage = errorMessage(error);
159
+ return output;
160
+ }
161
+ };
162
+ //# sourceMappingURL=openai-decisions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-decisions.js","sourceRoot":"","sources":["../../src/api/openai-decisions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAEN,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACd,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;GAUG;AAEH,MAAM,KAAK,GAAG,kBAAkB,CAAC;AAEjC,sEAAsE;AACtE,MAAM,UAAU,GAAG,GAAG,CAAC;AAUvB,SAAS,qBAAqB,CAAC,QAAuD;IACrF,MAAM,QAAQ,GAAG;QAChB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;QACrE,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;KACxE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClB,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC;AAC3G,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,QAA4B;IAC/D,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAA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S,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC,CAAC","sourcesContent":["import type {\n\tClassifierAnswer,\n\tClassifierContext,\n\tClassifierFunction,\n\tClassifierOptions,\n\tClassifierQuestion,\n\tClassifierResult,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport {\n\ttype ClassifierHttpError,\n\tisRecord,\n\tparseClassifierUsage,\n\tpostClassifierRequest,\n\trequiredNumber,\n} from \"./classifier-shared.ts\";\n\n/**\n * OpenAI's Decisions API: `POST /v1/decisions` with `{ model, input, questions }`.\n * https://developers.openai.com/api/docs/guides/decisions\n *\n * The state is sent as JSON text. With images, the input becomes one user message with the state\n * as `input_text` followed by `input_image` data URLs. Questions map to Decisions types:\n * `choice` to `choice`, `score` to `score`, and `bool` to `predicate`. Predicates have no\n * criteria field, so the meanings of true and false are appended to the instructions.\n *\n * Only OpenAI API keys work: Sign in with ChatGPT tokens are rejected on this route.\n */\n\nconst LABEL = \"OpenAI Decisions\";\n\n/** The endpoint accepts at most this many image parts per request. */\nconst MAX_IMAGES = 128;\n\ninterface DecisionQuestion {\n\ttype: \"predicate\" | \"choice\" | \"score\";\n\tname: string;\n\tinstructions: string;\n\tchoices?: Array<{ value: string; description?: string }>;\n\tlevels?: Array<{ label: string }>;\n}\n\nfunction predicateInstructions(question: Extract<ClassifierQuestion, { type: \"bool\" }>): string {\n\tconst meanings = [\n\t\tquestion.criteria.true ? `True means: ${question.criteria.true}` : \"\",\n\t\tquestion.criteria.false ? `False means: ${question.criteria.false}` : \"\",\n\t].filter(Boolean);\n\treturn meanings.length > 0 ? `${question.instructions}\\n\\n${meanings.join(\"\\n\")}` : question.instructions;\n}\n\nfunction wireQuestion(name: string, question: ClassifierQuestion): DecisionQuestion {\n\tif (question.type === \"choice\") {\n\t\treturn {\n\t\t\ttype: \"choice\",\n\t\t\tname,\n\t\t\tinstructions: question.instructions,\n\t\t\tchoices: Object.entries(question.criteria).map(([value, description]) =>\n\t\t\t\tdescription ? { value, description } : { value },\n\t\t\t),\n\t\t};\n\t}\n\tif (question.type === \"score\") {\n\t\treturn {\n\t\t\ttype: \"score\",\n\t\t\tname,\n\t\t\tinstructions: question.instructions,\n\t\t\tlevels: question.criteria.map((label) => ({ label })),\n\t\t};\n\t}\n\treturn { type: \"predicate\", name, instructions: predicateInstructions(question) };\n}\n\nfunction wireInput(context: ClassifierContext): unknown {\n\tconst state = JSON.stringify(context.state);\n\tconst images = context.images ?? [];\n\tif (images.length === 0) return state;\n\tif (images.length > MAX_IMAGES) {\n\t\tthrow new Error(`${LABEL} accepts at most ${MAX_IMAGES} images, got ${images.length}`);\n\t}\n\treturn [\n\t\t{\n\t\t\trole: \"user\",\n\t\t\tcontent: [\n\t\t\t\t{ type: \"input_text\", text: state },\n\t\t\t\t...images.map((image) => ({\n\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\timage_url: `data:${image.mimeType};base64,${image.data}`,\n\t\t\t\t})),\n\t\t\t],\n\t\t},\n\t];\n}\n\nfunction choiceProbabilities(value: unknown, id: string): Record<string, number> {\n\tif (!Array.isArray(value)) throw new Error(`${LABEL} returned invalid probabilities for ${id}`);\n\treturn Object.fromEntries(\n\t\tvalue.map((entry) => {\n\t\t\tif (!isRecord(entry) || typeof entry.value !== \"string\") {\n\t\t\t\tthrow new Error(`${LABEL} returned invalid probabilities for ${id}`);\n\t\t\t}\n\t\t\treturn [entry.value, requiredNumber(LABEL, entry.probability, `probability for ${id}.${entry.value}`)];\n\t\t}),\n\t);\n}\n\nfunction parseAnswer(id: string, question: ClassifierQuestion, answer: Record<string, unknown>): ClassifierAnswer {\n\tif (answer.type === \"refusal\") throw new Error(`${LABEL} refused to answer ${id}`);\n\tif (question.type === \"choice\") {\n\t\tif (answer.type !== \"choice\" || typeof answer.choice !== \"string\") {\n\t\t\tthrow new Error(`${LABEL} did not return a choice answer for ${id}`);\n\t\t}\n\t\treturn {\n\t\t\ttype: \"choice\",\n\t\t\tchoice: answer.choice,\n\t\t\tprobabilities: choiceProbabilities(answer.probabilities, id),\n\t\t\tconfidence: requiredNumber(LABEL, answer.confidence, `confidence for ${id}`),\n\t\t};\n\t}\n\tif (question.type === \"score\") {\n\t\tif (answer.type !== \"score\") throw new Error(`${LABEL} did not return a score answer for ${id}`);\n\t\treturn {\n\t\t\ttype: \"score\",\n\t\t\tscore: requiredNumber(LABEL, answer.score, `score for ${id}`),\n\t\t\tconfidence: requiredNumber(LABEL, answer.confidence, `confidence for ${id}`),\n\t\t};\n\t}\n\tif (answer.type !== \"predicate\") throw new Error(`${LABEL} did not return a predicate answer for ${id}`);\n\treturn { type: \"bool\", probability: requiredNumber(LABEL, answer.probability, `probability for ${id}`) };\n}\n\nfunction parseAnswers(value: unknown, context: ClassifierContext): Record<string, ClassifierAnswer> {\n\tif (!Array.isArray(value)) throw new Error(`${LABEL} returned an unexpected response`);\n\tconst byName = new Map<string, Record<string, unknown>>();\n\tfor (const answer of value) {\n\t\tif (isRecord(answer) && typeof answer.name === \"string\") byName.set(answer.name, answer);\n\t}\n\treturn Object.fromEntries(\n\t\tObject.entries(context.questions).map(([id, question]) => {\n\t\t\tconst answer = byName.get(id);\n\t\t\tif (!answer) throw new Error(`${LABEL} did not return an answer for ${id}`);\n\t\t\treturn [id, parseAnswer(id, question, answer)];\n\t\t}),\n\t);\n}\n\n/**\n * Cloudflare in front of api.openai.com answers 504 with an HTML page when a request runs longer\n * than about five seconds. Large inputs, currently above roughly 600K tokens, hit this limit, and\n * retrying the same input runs into it again, so 504 is not retried.\n */\nconst NO_RETRY_STATUSES = [504];\n\nfunction errorMessage(error: unknown): string {\n\tif ((error as Partial<ClassifierHttpError>).status === 504) {\n\t\treturn `${LABEL} error (504): the request timed out at the gateway. Very large inputs (above roughly 600K tokens) currently exceed its time limit.`;\n\t}\n\treturn formatProviderError(normalizeProviderError(error), `${LABEL} error`);\n}\n\n/** Classification through OpenAI's Decisions API. */\nexport const classify: ClassifierFunction<ClassifierOptions> = async (model, context, options) => {\n\tconst output: ClassifierResult = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tanswers: {},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tif (model.api !== \"openai-decisions\") throw new Error(`Unsupported classifier API: ${model.api}`);\n\t\tconst body = await postClassifierRequest(\n\t\t\tLABEL,\n\t\t\tnew URL(\"decisions\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`),\n\t\t\tmodel,\n\t\t\t{\n\t\t\t\tmodel: model.id,\n\t\t\t\tinput: wireInput(context),\n\t\t\t\tquestions: Object.entries(context.questions).map(([id, question]) => wireQuestion(id, question)),\n\t\t\t},\n\t\t\toptions,\n\t\t\tNO_RETRY_STATUSES,\n\t\t);\n\t\tif (!isRecord(body)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\t// Set before parsing answers: a request with malformed or refused answers was still billed.\n\t\tconst usage = parseClassifierUsage(body.usage, model);\n\t\tif (usage) output.usage = usage;\n\t\toutput.answers = parseAnswers(body.answers, context);\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.answers = {};\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = errorMessage(error);\n\t\treturn output;\n\t}\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import type { ProviderClassifier } from "../types.ts";
2
+ export declare const openAIDecisionsApi: () => ProviderClassifier;
3
+ //# sourceMappingURL=openai-decisions.lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-decisions.lazy.d.ts","sourceRoot":"","sources":["../../src/api/openai-decisions.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,kBAAkB,QAAO,kBAGpC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const openAIDecisionsApi = () => ({
2
+ classify: async (model, context, options) => (await import("./openai-decisions.js")).classify(model, context, options),
3
+ });
4
+ //# sourceMappingURL=openai-decisions.lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-decisions.lazy.js","sourceRoot":"","sources":["../../src/api/openai-decisions.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAuB,EAAE,CAAC,CAAC;IAC5D,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC3C,CAAC,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;CAC1E,CAAC,CAAC","sourcesContent":["import type { ProviderClassifier } from \"../types.ts\";\n\nexport const openAIDecisionsApi = (): ProviderClassifier => ({\n\tclassify: async (model, context, options) =>\n\t\t(await import(\"./openai-decisions.ts\")).classify(model, context, options),\n});\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
2
+ export declare function clampOpenAIPromptCacheKey(key: string | undefined): string | undefined;
3
+ //# sourceMappingURL=openai-prompt-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-prompt-cache.d.ts","sourceRoot":"","sources":["../../src/api/openai-prompt-cache.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kCAAkC,KAAK,CAAC;AAErD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKrF"}
@@ -0,0 +1,10 @@
1
+ export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
2
+ export function clampOpenAIPromptCacheKey(key) {
3
+ if (key === undefined)
4
+ return undefined;
5
+ const chars = Array.from(key);
6
+ if (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH)
7
+ return key;
8
+ return chars.slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join("");
9
+ }
10
+ //# sourceMappingURL=openai-prompt-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-prompt-cache.js","sourceRoot":"","sources":["../../src/api/openai-prompt-cache.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAErD,MAAM,UAAU,yBAAyB,CAAC,GAAuB;IAChE,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,MAAM,IAAI,kCAAkC;QAAE,OAAO,GAAG,CAAC;IACnE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC","sourcesContent":["export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;\n\nexport function clampOpenAIPromptCacheKey(key: string | undefined): string | undefined {\n\tif (key === undefined) return undefined;\n\tconst chars = Array.from(key);\n\tif (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH) return key;\n\treturn chars.slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join(\"\");\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import type { Tool as OpenAITool, ResponseCreateParamsStreaming, ResponseInput, ResponseStreamEvent } from "openai/resources/responses/responses.js";
2
+ import type { Api, AssistantMessage, Model, StreamOptions, Tool, TranscriptContext, Usage } from "../types.ts";
3
+ import type { AssistantMessageEventStream } from "../utils/event-stream.ts";
4
+ export interface OpenAIResponsesStreamOptions {
5
+ onProviderStreamEvent?: StreamOptions["onProviderStreamEvent"];
6
+ serviceTier?: ResponseCreateParamsStreaming["service_tier"];
7
+ grammarToolInputProperties?: ReadonlyMap<string, string>;
8
+ resolveServiceTier?: (responseServiceTier: ResponseCreateParamsStreaming["service_tier"] | undefined, requestServiceTier: ResponseCreateParamsStreaming["service_tier"] | undefined) => ResponseCreateParamsStreaming["service_tier"] | undefined;
9
+ applyServiceTierPricing?: (usage: Usage, serviceTier: ResponseCreateParamsStreaming["service_tier"] | undefined) => void;
10
+ }
11
+ export interface ConvertResponsesMessagesOptions {
12
+ includeSystemPrompt?: boolean;
13
+ grammarToolInputProperties?: ReadonlyMap<string, string>;
14
+ /** Whether later system messages are sent in place; otherwise they are folded into the leading prompt. */
15
+ supportsMidConvoSystemMessages?: boolean;
16
+ supportsAdditionalTools?: boolean;
17
+ supportsToolSearch?: boolean;
18
+ toolOptions?: ConvertResponsesToolsOptions;
19
+ }
20
+ export interface ConvertResponsesToolsOptions {
21
+ strict?: boolean | null;
22
+ supportsStrictMode?: boolean;
23
+ supportsOpenAIGrammarTools?: boolean;
24
+ toolSearchResult?: boolean;
25
+ }
26
+ export declare function convertResponsesMessages<TApi extends Api>(model: Model<TApi>, context: TranscriptContext, allowedToolCallProviders: ReadonlySet<string>, options?: ConvertResponsesMessagesOptions): ResponseInput;
27
+ export declare function convertResponsesTools(tools: readonly Tool[], options?: ConvertResponsesToolsOptions): OpenAITool[];
28
+ export declare function processResponsesStream<TApi extends Api>(openaiStream: AsyncIterable<ResponseStreamEvent>, output: AssistantMessage, stream: AssistantMessageEventStream, model: Model<TApi>, options?: OpenAIResponsesStreamOptions): Promise<void>;
29
+ //# sourceMappingURL=openai-responses-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-responses-shared.d.ts","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,IAAI,IAAI,UAAU,EAClB,6BAA6B,EAC7B,aAAa,EAQb,mBAAmB,EAEnB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAEhB,KAAK,E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