@diffra-ai/ai 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (887) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +2010 -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 +1549 -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 +192 -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 +1189 -0
  26. package/dist/api/bedrock-converse-stream.js.map +1 -0
  27. package/dist/api/bedrock-converse-stream.lazy.d.ts +16 -0
  28. package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
  29. package/dist/api/bedrock-converse-stream.lazy.js +43 -0
  30. package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
  31. package/dist/api/classifier-shared.d.ts +23 -0
  32. package/dist/api/classifier-shared.d.ts.map +1 -0
  33. package/dist/api/classifier-shared.js +104 -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 +57 -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 +38 -0
  52. package/dist/api/constrained-sampling.d.ts.map +1 -0
  53. package/dist/api/constrained-sampling.js +257 -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 +363 -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 +501 -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 +427 -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 +24 -0
  80. package/dist/api/lazy.d.ts.map +1 -0
  81. package/dist/api/lazy.js +91 -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 +368 -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 +740 -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 +1346 -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 +27 -0
  108. package/dist/api/openai-completions.d.ts.map +1 -0
  109. package/dist/api/openai-completions.js +1351 -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 +54 -0
  128. package/dist/api/openai-responses-shared.d.ts.map +1 -0
  129. package/dist/api/openai-responses-shared.js +796 -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 +335 -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 +135 -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/pi-messages.d.ts +101 -0
  148. package/dist/api/pi-messages.d.ts.map +1 -0
  149. package/dist/api/pi-messages.js +329 -0
  150. package/dist/api/pi-messages.js.map +1 -0
  151. package/dist/api/pi-messages.lazy.d.ts +3 -0
  152. package/dist/api/pi-messages.lazy.d.ts.map +1 -0
  153. package/dist/api/pi-messages.lazy.js +3 -0
  154. package/dist/api/pi-messages.lazy.js.map +1 -0
  155. package/dist/api/simple-options.d.ts +17 -0
  156. package/dist/api/simple-options.d.ts.map +1 -0
  157. package/dist/api/simple-options.js +88 -0
  158. package/dist/api/simple-options.js.map +1 -0
  159. package/dist/api/strict-tool-limits.d.ts +13 -0
  160. package/dist/api/strict-tool-limits.d.ts.map +1 -0
  161. package/dist/api/strict-tool-limits.js +50 -0
  162. package/dist/api/strict-tool-limits.js.map +1 -0
  163. package/dist/api/system-one-shared.d.ts +49 -0
  164. package/dist/api/system-one-shared.d.ts.map +1 -0
  165. package/dist/api/system-one-shared.js +151 -0
  166. package/dist/api/system-one-shared.js.map +1 -0
  167. package/dist/api/transform-messages.d.ts +23 -0
  168. package/dist/api/transform-messages.d.ts.map +1 -0
  169. package/dist/api/transform-messages.js +214 -0
  170. package/dist/api/transform-messages.js.map +1 -0
  171. package/dist/api/typesafe-system-one.d.ts +4 -0
  172. package/dist/api/typesafe-system-one.d.ts.map +1 -0
  173. package/dist/api/typesafe-system-one.js +30 -0
  174. package/dist/api/typesafe-system-one.js.map +1 -0
  175. package/dist/api/typesafe-system-one.lazy.d.ts +3 -0
  176. package/dist/api/typesafe-system-one.lazy.d.ts.map +1 -0
  177. package/dist/api/typesafe-system-one.lazy.js +4 -0
  178. package/dist/api/typesafe-system-one.lazy.js.map +1 -0
  179. package/dist/auth/context.d.ts +7 -0
  180. package/dist/auth/context.d.ts.map +1 -0
  181. package/dist/auth/context.js +42 -0
  182. package/dist/auth/context.js.map +1 -0
  183. package/dist/auth/credential-store.d.ts +17 -0
  184. package/dist/auth/credential-store.d.ts.map +1 -0
  185. package/dist/auth/credential-store.js +51 -0
  186. package/dist/auth/credential-store.js.map +1 -0
  187. package/dist/auth/helpers.d.ts +22 -0
  188. package/dist/auth/helpers.d.ts.map +1 -0
  189. package/dist/auth/helpers.js +53 -0
  190. package/dist/auth/helpers.js.map +1 -0
  191. package/dist/auth/oauth/anthropic.d.ts +9 -0
  192. package/dist/auth/oauth/anthropic.d.ts.map +1 -0
  193. package/dist/auth/oauth/anthropic.js +257 -0
  194. package/dist/auth/oauth/anthropic.js.map +1 -0
  195. package/dist/auth/oauth/callback-server.d.ts +55 -0
  196. package/dist/auth/oauth/callback-server.d.ts.map +1 -0
  197. package/dist/auth/oauth/callback-server.js +146 -0
  198. package/dist/auth/oauth/callback-server.js.map +1 -0
  199. package/dist/auth/oauth/device-code.d.ts +24 -0
  200. package/dist/auth/oauth/device-code.d.ts.map +1 -0
  201. package/dist/auth/oauth/device-code.js +69 -0
  202. package/dist/auth/oauth/device-code.js.map +1 -0
  203. package/dist/auth/oauth/github-copilot.d.ts +6 -0
  204. package/dist/auth/oauth/github-copilot.d.ts.map +1 -0
  205. package/dist/auth/oauth/github-copilot.js +385 -0
  206. package/dist/auth/oauth/github-copilot.js.map +1 -0
  207. package/dist/auth/oauth/kimi-coding.d.ts +10 -0
  208. package/dist/auth/oauth/kimi-coding.d.ts.map +1 -0
  209. package/dist/auth/oauth/kimi-coding.js +230 -0
  210. package/dist/auth/oauth/kimi-coding.js.map +1 -0
  211. package/dist/auth/oauth/load.d.ts +31 -0
  212. package/dist/auth/oauth/load.d.ts.map +1 -0
  213. package/dist/auth/oauth/load.js +72 -0
  214. package/dist/auth/oauth/load.js.map +1 -0
  215. package/dist/auth/oauth/meta.d.ts +17 -0
  216. package/dist/auth/oauth/meta.d.ts.map +1 -0
  217. package/dist/auth/oauth/meta.js +177 -0
  218. package/dist/auth/oauth/meta.js.map +1 -0
  219. package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
  220. package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
  221. package/dist/auth/oauth/openai-chatgpt.js +263 -0
  222. package/dist/auth/oauth/openai-chatgpt.js.map +1 -0
  223. package/dist/auth/oauth/openai-codex.d.ts +9 -0
  224. package/dist/auth/oauth/openai-codex.d.ts.map +1 -0
  225. package/dist/auth/oauth/openai-codex.js +346 -0
  226. package/dist/auth/oauth/openai-codex.js.map +1 -0
  227. package/dist/auth/oauth/openrouter.d.ts +15 -0
  228. package/dist/auth/oauth/openrouter.d.ts.map +1 -0
  229. package/dist/auth/oauth/openrouter.js +158 -0
  230. package/dist/auth/oauth/openrouter.js.map +1 -0
  231. package/dist/auth/oauth/pkce.d.ts +13 -0
  232. package/dist/auth/oauth/pkce.d.ts.map +1 -0
  233. package/dist/auth/oauth/pkce.js +31 -0
  234. package/dist/auth/oauth/pkce.js.map +1 -0
  235. package/dist/auth/oauth/radius.d.ts +17 -0
  236. package/dist/auth/oauth/radius.d.ts.map +1 -0
  237. package/dist/auth/oauth/radius.js +259 -0
  238. package/dist/auth/oauth/radius.js.map +1 -0
  239. package/dist/auth/oauth/trusted-url.d.ts +7 -0
  240. package/dist/auth/oauth/trusted-url.d.ts.map +1 -0
  241. package/dist/auth/oauth/trusted-url.js +12 -0
  242. package/dist/auth/oauth/trusted-url.js.map +1 -0
  243. package/dist/auth/oauth/xai.d.ts +6 -0
  244. package/dist/auth/oauth/xai.d.ts.map +1 -0
  245. package/dist/auth/oauth/xai.js +190 -0
  246. package/dist/auth/oauth/xai.js.map +1 -0
  247. package/dist/auth/resolve.d.ts +36 -0
  248. package/dist/auth/resolve.d.ts.map +1 -0
  249. package/dist/auth/resolve.js +140 -0
  250. package/dist/auth/resolve.js.map +1 -0
  251. package/dist/auth/types.d.ts +249 -0
  252. package/dist/auth/types.d.ts.map +1 -0
  253. package/dist/auth/types.js +2 -0
  254. package/dist/auth/types.js.map +1 -0
  255. package/dist/bedrock-provider.d.ts +5 -0
  256. package/dist/bedrock-provider.d.ts.map +1 -0
  257. package/dist/bedrock-provider.js +6 -0
  258. package/dist/bedrock-provider.js.map +1 -0
  259. package/dist/bun-oauth.d.ts +3 -0
  260. package/dist/bun-oauth.d.ts.map +1 -0
  261. package/dist/bun-oauth.js +25 -0
  262. package/dist/bun-oauth.js.map +1 -0
  263. package/dist/cache-warming.d.ts +53 -0
  264. package/dist/cache-warming.d.ts.map +1 -0
  265. package/dist/cache-warming.js +82 -0
  266. package/dist/cache-warming.js.map +1 -0
  267. package/dist/cli.d.ts +3 -0
  268. package/dist/cli.d.ts.map +1 -0
  269. package/dist/cli.js +119 -0
  270. package/dist/cli.js.map +1 -0
  271. package/dist/compat/extension-oauth-types.d.ts +43 -0
  272. package/dist/compat/extension-oauth-types.d.ts.map +1 -0
  273. package/dist/compat/extension-oauth-types.js +2 -0
  274. package/dist/compat/extension-oauth-types.js.map +1 -0
  275. package/dist/compat.d.ts +67 -0
  276. package/dist/compat.d.ts.map +1 -0
  277. package/dist/compat.js +202 -0
  278. package/dist/compat.js.map +1 -0
  279. package/dist/env-api-keys.d.ts +26 -0
  280. package/dist/env-api-keys.d.ts.map +1 -0
  281. package/dist/env-api-keys.js +165 -0
  282. package/dist/env-api-keys.js.map +1 -0
  283. package/dist/image-models.d.ts +21 -0
  284. package/dist/image-models.d.ts.map +1 -0
  285. package/dist/image-models.js +24 -0
  286. package/dist/image-models.js.map +1 -0
  287. package/dist/images-api-registry.d.ts +14 -0
  288. package/dist/images-api-registry.d.ts.map +1 -0
  289. package/dist/images-api-registry.js +22 -0
  290. package/dist/images-api-registry.js.map +1 -0
  291. package/dist/images.d.ts +9 -0
  292. package/dist/images.d.ts.map +1 -0
  293. package/dist/images.js +19 -0
  294. package/dist/images.js.map +1 -0
  295. package/dist/index.d.ts +37 -0
  296. package/dist/index.d.ts.map +1 -0
  297. package/dist/index.js +25 -0
  298. package/dist/index.js.map +1 -0
  299. package/dist/lazy-bedrock-provider.d.ts +10 -0
  300. package/dist/lazy-bedrock-provider.d.ts.map +1 -0
  301. package/dist/lazy-bedrock-provider.js +13 -0
  302. package/dist/lazy-bedrock-provider.js.map +1 -0
  303. package/dist/lazy-oauth.d.ts +10 -0
  304. package/dist/lazy-oauth.d.ts.map +1 -0
  305. package/dist/lazy-oauth.js +23 -0
  306. package/dist/lazy-oauth.js.map +1 -0
  307. package/dist/legacy-api-aliases.d.ts +42 -0
  308. package/dist/legacy-api-aliases.d.ts.map +1 -0
  309. package/dist/legacy-api-aliases.js +49 -0
  310. package/dist/legacy-api-aliases.js.map +1 -0
  311. package/dist/model-catalog.d.ts +33 -0
  312. package/dist/model-catalog.d.ts.map +1 -0
  313. package/dist/model-catalog.js +16 -0
  314. package/dist/model-catalog.js.map +1 -0
  315. package/dist/models-store.d.ts +30 -0
  316. package/dist/models-store.d.ts.map +1 -0
  317. package/dist/models-store.js +17 -0
  318. package/dist/models-store.js.map +1 -0
  319. package/dist/models.d.ts +285 -0
  320. package/dist/models.d.ts.map +1 -0
  321. package/dist/models.generated.d.ts +179 -0
  322. package/dist/models.generated.d.ts.map +1 -0
  323. package/dist/models.generated.js +181 -0
  324. package/dist/models.generated.js.map +1 -0
  325. package/dist/models.js +753 -0
  326. package/dist/models.js.map +1 -0
  327. package/dist/oauth.d.ts +3 -0
  328. package/dist/oauth.d.ts.map +1 -0
  329. package/dist/oauth.js +2 -0
  330. package/dist/oauth.js.map +1 -0
  331. package/dist/providers/all.d.ts +34 -0
  332. package/dist/providers/all.d.ts.map +1 -0
  333. package/dist/providers/all.js +139 -0
  334. package/dist/providers/all.js.map +1 -0
  335. package/dist/providers/amazon-bedrock.d.ts +3 -0
  336. package/dist/providers/amazon-bedrock.d.ts.map +1 -0
  337. package/dist/providers/amazon-bedrock.js +93 -0
  338. package/dist/providers/amazon-bedrock.js.map +1 -0
  339. package/dist/providers/amazon-bedrock.models.d.ts +6 -0
  340. package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
  341. package/dist/providers/amazon-bedrock.models.js +8 -0
  342. package/dist/providers/amazon-bedrock.models.js.map +1 -0
  343. package/dist/providers/ant-ling.d.ts +3 -0
  344. package/dist/providers/ant-ling.d.ts.map +1 -0
  345. package/dist/providers/ant-ling.js +15 -0
  346. package/dist/providers/ant-ling.js.map +1 -0
  347. package/dist/providers/ant-ling.models.d.ts +6 -0
  348. package/dist/providers/ant-ling.models.d.ts.map +1 -0
  349. package/dist/providers/ant-ling.models.js +8 -0
  350. package/dist/providers/ant-ling.models.js.map +1 -0
  351. package/dist/providers/anthropic.d.ts +3 -0
  352. package/dist/providers/anthropic.d.ts.map +1 -0
  353. package/dist/providers/anthropic.js +78 -0
  354. package/dist/providers/anthropic.js.map +1 -0
  355. package/dist/providers/anthropic.models.d.ts +6 -0
  356. package/dist/providers/anthropic.models.d.ts.map +1 -0
  357. package/dist/providers/anthropic.models.js +8 -0
  358. package/dist/providers/anthropic.models.js.map +1 -0
  359. package/dist/providers/azure.d.ts +3 -0
  360. package/dist/providers/azure.d.ts.map +1 -0
  361. package/dist/providers/azure.js +46 -0
  362. package/dist/providers/azure.js.map +1 -0
  363. package/dist/providers/azure.models.d.ts +6 -0
  364. package/dist/providers/azure.models.d.ts.map +1 -0
  365. package/dist/providers/azure.models.js +8 -0
  366. package/dist/providers/azure.models.js.map +1 -0
  367. package/dist/providers/baseten.d.ts +3 -0
  368. package/dist/providers/baseten.d.ts.map +1 -0
  369. package/dist/providers/baseten.js +15 -0
  370. package/dist/providers/baseten.js.map +1 -0
  371. package/dist/providers/baseten.models.d.ts +6 -0
  372. package/dist/providers/baseten.models.d.ts.map +1 -0
  373. package/dist/providers/baseten.models.js +8 -0
  374. package/dist/providers/baseten.models.js.map +1 -0
  375. package/dist/providers/cerebras.d.ts +3 -0
  376. package/dist/providers/cerebras.d.ts.map +1 -0
  377. package/dist/providers/cerebras.js +15 -0
  378. package/dist/providers/cerebras.js.map +1 -0
  379. package/dist/providers/cerebras.models.d.ts +6 -0
  380. package/dist/providers/cerebras.models.d.ts.map +1 -0
  381. package/dist/providers/cerebras.models.js +8 -0
  382. package/dist/providers/cerebras.models.js.map +1 -0
  383. package/dist/providers/cloudflare-ai-gateway.d.ts +5 -0
  384. package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
  385. package/dist/providers/cloudflare-ai-gateway.js +25 -0
  386. package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
  387. package/dist/providers/cloudflare-ai-gateway.models.d.ts +6 -0
  388. package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
  389. package/dist/providers/cloudflare-ai-gateway.models.js +8 -0
  390. package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
  391. package/dist/providers/cloudflare-auth.d.ts +4 -0
  392. package/dist/providers/cloudflare-auth.d.ts.map +1 -0
  393. package/dist/providers/cloudflare-auth.js +86 -0
  394. package/dist/providers/cloudflare-auth.js.map +1 -0
  395. package/dist/providers/cloudflare-stream.d.ts +12 -0
  396. package/dist/providers/cloudflare-stream.d.ts.map +1 -0
  397. package/dist/providers/cloudflare-stream.js +27 -0
  398. package/dist/providers/cloudflare-stream.js.map +1 -0
  399. package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
  400. package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
  401. package/dist/providers/cloudflare-workers-ai.js +22 -0
  402. package/dist/providers/cloudflare-workers-ai.js.map +1 -0
  403. package/dist/providers/cloudflare-workers-ai.models.d.ts +6 -0
  404. package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
  405. package/dist/providers/cloudflare-workers-ai.models.js +8 -0
  406. package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
  407. package/dist/providers/compat-schema.d.ts +511 -0
  408. package/dist/providers/compat-schema.d.ts.map +1 -0
  409. package/dist/providers/compat-schema.js +466 -0
  410. package/dist/providers/compat-schema.js.map +1 -0
  411. package/dist/providers/data/.manifest.json +1 -0
  412. package/dist/providers/data/amazon-bedrock.json +1 -0
  413. package/dist/providers/data/ant-ling.json +1 -0
  414. package/dist/providers/data/anthropic.json +1 -0
  415. package/dist/providers/data/azure.json +1 -0
  416. package/dist/providers/data/baseten.json +1 -0
  417. package/dist/providers/data/cerebras.json +1 -0
  418. package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
  419. package/dist/providers/data/cloudflare-workers-ai.json +1 -0
  420. package/dist/providers/data/deepseek.json +1 -0
  421. package/dist/providers/data/fireworks.json +1 -0
  422. package/dist/providers/data/github-copilot.json +1 -0
  423. package/dist/providers/data/google-vertex.json +1 -0
  424. package/dist/providers/data/google.json +1 -0
  425. package/dist/providers/data/groq.json +1 -0
  426. package/dist/providers/data/huggingface.json +1 -0
  427. package/dist/providers/data/kimi-coding.json +1 -0
  428. package/dist/providers/data/meta.json +1 -0
  429. package/dist/providers/data/minimax-cn.json +1 -0
  430. package/dist/providers/data/minimax.json +1 -0
  431. package/dist/providers/data/mistral.json +1 -0
  432. package/dist/providers/data/moonshotai-cn.json +1 -0
  433. package/dist/providers/data/moonshotai.json +1 -0
  434. package/dist/providers/data/nvidia.json +1 -0
  435. package/dist/providers/data/openai-codex.json +1 -0
  436. package/dist/providers/data/openai.json +1 -0
  437. package/dist/providers/data/opencode-go.json +1 -0
  438. package/dist/providers/data/opencode.json +1 -0
  439. package/dist/providers/data/openrouter.json +1 -0
  440. package/dist/providers/data/qwen-token-plan-cn.json +1 -0
  441. package/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
  442. package/dist/providers/data/qwen-token-plan-individual.json +1 -0
  443. package/dist/providers/data/qwen-token-plan.json +1 -0
  444. package/dist/providers/data/radius.json +1 -0
  445. package/dist/providers/data/together.json +1 -0
  446. package/dist/providers/data/typesafe.json +1 -0
  447. package/dist/providers/data/vercel-ai-gateway.json +1 -0
  448. package/dist/providers/data/xai.json +1 -0
  449. package/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
  450. package/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
  451. package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
  452. package/dist/providers/data/xiaomi.json +1 -0
  453. package/dist/providers/data/zai-coding-cn.json +1 -0
  454. package/dist/providers/data/zai.json +1 -0
  455. package/dist/providers/deepseek.d.ts +3 -0
  456. package/dist/providers/deepseek.d.ts.map +1 -0
  457. package/dist/providers/deepseek.js +15 -0
  458. package/dist/providers/deepseek.js.map +1 -0
  459. package/dist/providers/deepseek.models.d.ts +6 -0
  460. package/dist/providers/deepseek.models.d.ts.map +1 -0
  461. package/dist/providers/deepseek.models.js +8 -0
  462. package/dist/providers/deepseek.models.js.map +1 -0
  463. package/dist/providers/faux.d.ts +103 -0
  464. package/dist/providers/faux.d.ts.map +1 -0
  465. package/dist/providers/faux.js +511 -0
  466. package/dist/providers/faux.js.map +1 -0
  467. package/dist/providers/fireworks.d.ts +3 -0
  468. package/dist/providers/fireworks.d.ts.map +1 -0
  469. package/dist/providers/fireworks.js +19 -0
  470. package/dist/providers/fireworks.js.map +1 -0
  471. package/dist/providers/fireworks.models.d.ts +6 -0
  472. package/dist/providers/fireworks.models.d.ts.map +1 -0
  473. package/dist/providers/fireworks.models.js +8 -0
  474. package/dist/providers/fireworks.models.js.map +1 -0
  475. package/dist/providers/github-copilot.d.ts +5 -0
  476. package/dist/providers/github-copilot.d.ts.map +1 -0
  477. package/dist/providers/github-copilot.js +46 -0
  478. package/dist/providers/github-copilot.js.map +1 -0
  479. package/dist/providers/github-copilot.models.d.ts +6 -0
  480. package/dist/providers/github-copilot.models.d.ts.map +1 -0
  481. package/dist/providers/github-copilot.models.js +8 -0
  482. package/dist/providers/github-copilot.models.js.map +1 -0
  483. package/dist/providers/google-vertex.d.ts +3 -0
  484. package/dist/providers/google-vertex.d.ts.map +1 -0
  485. package/dist/providers/google-vertex.js +94 -0
  486. package/dist/providers/google-vertex.js.map +1 -0
  487. package/dist/providers/google-vertex.models.d.ts +6 -0
  488. package/dist/providers/google-vertex.models.d.ts.map +1 -0
  489. package/dist/providers/google-vertex.models.js +8 -0
  490. package/dist/providers/google-vertex.models.js.map +1 -0
  491. package/dist/providers/google.d.ts +3 -0
  492. package/dist/providers/google.d.ts.map +1 -0
  493. package/dist/providers/google.js +15 -0
  494. package/dist/providers/google.js.map +1 -0
  495. package/dist/providers/google.models.d.ts +6 -0
  496. package/dist/providers/google.models.d.ts.map +1 -0
  497. package/dist/providers/google.models.js +8 -0
  498. package/dist/providers/google.models.js.map +1 -0
  499. package/dist/providers/groq.d.ts +3 -0
  500. package/dist/providers/groq.d.ts.map +1 -0
  501. package/dist/providers/groq.js +15 -0
  502. package/dist/providers/groq.js.map +1 -0
  503. package/dist/providers/groq.models.d.ts +6 -0
  504. package/dist/providers/groq.models.d.ts.map +1 -0
  505. package/dist/providers/groq.models.js +8 -0
  506. package/dist/providers/groq.models.js.map +1 -0
  507. package/dist/providers/huggingface.d.ts +3 -0
  508. package/dist/providers/huggingface.d.ts.map +1 -0
  509. package/dist/providers/huggingface.js +15 -0
  510. package/dist/providers/huggingface.js.map +1 -0
  511. package/dist/providers/huggingface.models.d.ts +6 -0
  512. package/dist/providers/huggingface.models.d.ts.map +1 -0
  513. package/dist/providers/huggingface.models.js +8 -0
  514. package/dist/providers/huggingface.models.js.map +1 -0
  515. package/dist/providers/images/register-builtins.d.ts +4 -0
  516. package/dist/providers/images/register-builtins.d.ts.map +1 -0
  517. package/dist/providers/images/register-builtins.js +34 -0
  518. package/dist/providers/images/register-builtins.js.map +1 -0
  519. package/dist/providers/kimi-coding.d.ts +3 -0
  520. package/dist/providers/kimi-coding.d.ts.map +1 -0
  521. package/dist/providers/kimi-coding.js +24 -0
  522. package/dist/providers/kimi-coding.js.map +1 -0
  523. package/dist/providers/kimi-coding.models.d.ts +6 -0
  524. package/dist/providers/kimi-coding.models.d.ts.map +1 -0
  525. package/dist/providers/kimi-coding.models.js +8 -0
  526. package/dist/providers/kimi-coding.models.js.map +1 -0
  527. package/dist/providers/meta.d.ts +3 -0
  528. package/dist/providers/meta.d.ts.map +1 -0
  529. package/dist/providers/meta.js +24 -0
  530. package/dist/providers/meta.js.map +1 -0
  531. package/dist/providers/meta.models.d.ts +6 -0
  532. package/dist/providers/meta.models.d.ts.map +1 -0
  533. package/dist/providers/meta.models.js +8 -0
  534. package/dist/providers/meta.models.js.map +1 -0
  535. package/dist/providers/minimax-cn.d.ts +3 -0
  536. package/dist/providers/minimax-cn.d.ts.map +1 -0
  537. package/dist/providers/minimax-cn.js +15 -0
  538. package/dist/providers/minimax-cn.js.map +1 -0
  539. package/dist/providers/minimax-cn.models.d.ts +6 -0
  540. package/dist/providers/minimax-cn.models.d.ts.map +1 -0
  541. package/dist/providers/minimax-cn.models.js +8 -0
  542. package/dist/providers/minimax-cn.models.js.map +1 -0
  543. package/dist/providers/minimax.d.ts +3 -0
  544. package/dist/providers/minimax.d.ts.map +1 -0
  545. package/dist/providers/minimax.js +15 -0
  546. package/dist/providers/minimax.js.map +1 -0
  547. package/dist/providers/minimax.models.d.ts +6 -0
  548. package/dist/providers/minimax.models.d.ts.map +1 -0
  549. package/dist/providers/minimax.models.js +8 -0
  550. package/dist/providers/minimax.models.js.map +1 -0
  551. package/dist/providers/mistral.d.ts +3 -0
  552. package/dist/providers/mistral.d.ts.map +1 -0
  553. package/dist/providers/mistral.js +15 -0
  554. package/dist/providers/mistral.js.map +1 -0
  555. package/dist/providers/mistral.models.d.ts +6 -0
  556. package/dist/providers/mistral.models.d.ts.map +1 -0
  557. package/dist/providers/mistral.models.js +8 -0
  558. package/dist/providers/mistral.models.js.map +1 -0
  559. package/dist/providers/model-schema.d.ts +91 -0
  560. package/dist/providers/model-schema.d.ts.map +1 -0
  561. package/dist/providers/model-schema.js +68 -0
  562. package/dist/providers/model-schema.js.map +1 -0
  563. package/dist/providers/moonshotai-cn.d.ts +3 -0
  564. package/dist/providers/moonshotai-cn.d.ts.map +1 -0
  565. package/dist/providers/moonshotai-cn.js +15 -0
  566. package/dist/providers/moonshotai-cn.js.map +1 -0
  567. package/dist/providers/moonshotai-cn.models.d.ts +6 -0
  568. package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
  569. package/dist/providers/moonshotai-cn.models.js +8 -0
  570. package/dist/providers/moonshotai-cn.models.js.map +1 -0
  571. package/dist/providers/moonshotai.d.ts +3 -0
  572. package/dist/providers/moonshotai.d.ts.map +1 -0
  573. package/dist/providers/moonshotai.js +15 -0
  574. package/dist/providers/moonshotai.js.map +1 -0
  575. package/dist/providers/moonshotai.models.d.ts +6 -0
  576. package/dist/providers/moonshotai.models.d.ts.map +1 -0
  577. package/dist/providers/moonshotai.models.js +8 -0
  578. package/dist/providers/moonshotai.models.js.map +1 -0
  579. package/dist/providers/nvidia.d.ts +3 -0
  580. package/dist/providers/nvidia.d.ts.map +1 -0
  581. package/dist/providers/nvidia.js +15 -0
  582. package/dist/providers/nvidia.js.map +1 -0
  583. package/dist/providers/nvidia.models.d.ts +6 -0
  584. package/dist/providers/nvidia.models.d.ts.map +1 -0
  585. package/dist/providers/nvidia.models.js +8 -0
  586. package/dist/providers/nvidia.models.js.map +1 -0
  587. package/dist/providers/openai-codex.d.ts +3 -0
  588. package/dist/providers/openai-codex.d.ts.map +1 -0
  589. package/dist/providers/openai-codex.js +22 -0
  590. package/dist/providers/openai-codex.js.map +1 -0
  591. package/dist/providers/openai-codex.models.d.ts +6 -0
  592. package/dist/providers/openai-codex.models.d.ts.map +1 -0
  593. package/dist/providers/openai-codex.models.js +8 -0
  594. package/dist/providers/openai-codex.models.js.map +1 -0
  595. package/dist/providers/openai.d.ts +3 -0
  596. package/dist/providers/openai.d.ts.map +1 -0
  597. package/dist/providers/openai.js +33 -0
  598. package/dist/providers/openai.js.map +1 -0
  599. package/dist/providers/openai.models.d.ts +6 -0
  600. package/dist/providers/openai.models.d.ts.map +1 -0
  601. package/dist/providers/openai.models.js +8 -0
  602. package/dist/providers/openai.models.js.map +1 -0
  603. package/dist/providers/opencode-go.d.ts +5 -0
  604. package/dist/providers/opencode-go.d.ts.map +1 -0
  605. package/dist/providers/opencode-go.js +23 -0
  606. package/dist/providers/opencode-go.js.map +1 -0
  607. package/dist/providers/opencode-go.models.d.ts +6 -0
  608. package/dist/providers/opencode-go.models.d.ts.map +1 -0
  609. package/dist/providers/opencode-go.models.js +8 -0
  610. package/dist/providers/opencode-go.models.js.map +1 -0
  611. package/dist/providers/opencode-headers.d.ts +4 -0
  612. package/dist/providers/opencode-headers.d.ts.map +1 -0
  613. package/dist/providers/opencode-headers.js +22 -0
  614. package/dist/providers/opencode-headers.js.map +1 -0
  615. package/dist/providers/opencode.d.ts +5 -0
  616. package/dist/providers/opencode.d.ts.map +1 -0
  617. package/dist/providers/opencode.js +26 -0
  618. package/dist/providers/opencode.js.map +1 -0
  619. package/dist/providers/opencode.models.d.ts +6 -0
  620. package/dist/providers/opencode.models.d.ts.map +1 -0
  621. package/dist/providers/opencode.models.js +8 -0
  622. package/dist/providers/opencode.models.js.map +1 -0
  623. package/dist/providers/openrouter-api.d.ts +40 -0
  624. package/dist/providers/openrouter-api.d.ts.map +1 -0
  625. package/dist/providers/openrouter-api.js +41 -0
  626. package/dist/providers/openrouter-api.js.map +1 -0
  627. package/dist/providers/openrouter.d.ts +13 -0
  628. package/dist/providers/openrouter.d.ts.map +1 -0
  629. package/dist/providers/openrouter.js +87 -0
  630. package/dist/providers/openrouter.js.map +1 -0
  631. package/dist/providers/openrouter.models.d.ts +6 -0
  632. package/dist/providers/openrouter.models.d.ts.map +1 -0
  633. package/dist/providers/openrouter.models.js +8 -0
  634. package/dist/providers/openrouter.models.js.map +1 -0
  635. package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
  636. package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
  637. package/dist/providers/qwen-token-plan-cn.js +20 -0
  638. package/dist/providers/qwen-token-plan-cn.js.map +1 -0
  639. package/dist/providers/qwen-token-plan-cn.models.d.ts +6 -0
  640. package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
  641. package/dist/providers/qwen-token-plan-cn.models.js +8 -0
  642. package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
  643. package/dist/providers/qwen-token-plan-individual-cn.d.ts +3 -0
  644. package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -0
  645. package/dist/providers/qwen-token-plan-individual-cn.js +20 -0
  646. package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -0
  647. package/dist/providers/qwen-token-plan-individual-cn.models.d.ts +6 -0
  648. package/dist/providers/qwen-token-plan-individual-cn.models.d.ts.map +1 -0
  649. package/dist/providers/qwen-token-plan-individual-cn.models.js +8 -0
  650. package/dist/providers/qwen-token-plan-individual-cn.models.js.map +1 -0
  651. package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
  652. package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
  653. package/dist/providers/qwen-token-plan-individual.js +20 -0
  654. package/dist/providers/qwen-token-plan-individual.js.map +1 -0
  655. package/dist/providers/qwen-token-plan-individual.models.d.ts +6 -0
  656. package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
  657. package/dist/providers/qwen-token-plan-individual.models.js +8 -0
  658. package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
  659. package/dist/providers/qwen-token-plan.d.ts +3 -0
  660. package/dist/providers/qwen-token-plan.d.ts.map +1 -0
  661. package/dist/providers/qwen-token-plan.js +20 -0
  662. package/dist/providers/qwen-token-plan.js.map +1 -0
  663. package/dist/providers/qwen-token-plan.models.d.ts +6 -0
  664. package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
  665. package/dist/providers/qwen-token-plan.models.js +8 -0
  666. package/dist/providers/qwen-token-plan.models.js.map +1 -0
  667. package/dist/providers/radius-config.d.ts +26 -0
  668. package/dist/providers/radius-config.d.ts.map +1 -0
  669. package/dist/providers/radius-config.js +64 -0
  670. package/dist/providers/radius-config.js.map +1 -0
  671. package/dist/providers/radius.d.ts +9 -0
  672. package/dist/providers/radius.d.ts.map +1 -0
  673. package/dist/providers/radius.js +70 -0
  674. package/dist/providers/radius.js.map +1 -0
  675. package/dist/providers/radius.models.d.ts +6 -0
  676. package/dist/providers/radius.models.d.ts.map +1 -0
  677. package/dist/providers/radius.models.js +8 -0
  678. package/dist/providers/radius.models.js.map +1 -0
  679. package/dist/providers/schema-builders.d.ts +10 -0
  680. package/dist/providers/schema-builders.d.ts.map +1 -0
  681. package/dist/providers/schema-builders.js +18 -0
  682. package/dist/providers/schema-builders.js.map +1 -0
  683. package/dist/providers/together.d.ts +3 -0
  684. package/dist/providers/together.d.ts.map +1 -0
  685. package/dist/providers/together.js +15 -0
  686. package/dist/providers/together.js.map +1 -0
  687. package/dist/providers/together.models.d.ts +6 -0
  688. package/dist/providers/together.models.d.ts.map +1 -0
  689. package/dist/providers/together.models.js +8 -0
  690. package/dist/providers/together.models.js.map +1 -0
  691. package/dist/providers/typesafe.d.ts +3 -0
  692. package/dist/providers/typesafe.d.ts.map +1 -0
  693. package/dist/providers/typesafe.js +18 -0
  694. package/dist/providers/typesafe.js.map +1 -0
  695. package/dist/providers/typesafe.models.d.ts +6 -0
  696. package/dist/providers/typesafe.models.d.ts.map +1 -0
  697. package/dist/providers/typesafe.models.js +8 -0
  698. package/dist/providers/typesafe.models.js.map +1 -0
  699. package/dist/providers/vercel-ai-gateway.d.ts +3 -0
  700. package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
  701. package/dist/providers/vercel-ai-gateway.js +18 -0
  702. package/dist/providers/vercel-ai-gateway.js.map +1 -0
  703. package/dist/providers/vercel-ai-gateway.models.d.ts +6 -0
  704. package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
  705. package/dist/providers/vercel-ai-gateway.models.js +8 -0
  706. package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
  707. package/dist/providers/xai.d.ts +3 -0
  708. package/dist/providers/xai.d.ts.map +1 -0
  709. package/dist/providers/xai.js +24 -0
  710. package/dist/providers/xai.js.map +1 -0
  711. package/dist/providers/xai.models.d.ts +6 -0
  712. package/dist/providers/xai.models.d.ts.map +1 -0
  713. package/dist/providers/xai.models.js +8 -0
  714. package/dist/providers/xai.models.js.map +1 -0
  715. package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
  716. package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
  717. package/dist/providers/xiaomi-token-plan-ams.js +15 -0
  718. package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
  719. package/dist/providers/xiaomi-token-plan-ams.models.d.ts +6 -0
  720. package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
  721. package/dist/providers/xiaomi-token-plan-ams.models.js +8 -0
  722. package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
  723. package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
  724. package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
  725. package/dist/providers/xiaomi-token-plan-cn.js +15 -0
  726. package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
  727. package/dist/providers/xiaomi-token-plan-cn.models.d.ts +6 -0
  728. package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
  729. package/dist/providers/xiaomi-token-plan-cn.models.js +8 -0
  730. package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
  731. package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
  732. package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
  733. package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
  734. package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
  735. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +6 -0
  736. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
  737. package/dist/providers/xiaomi-token-plan-sgp.models.js +8 -0
  738. package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
  739. package/dist/providers/xiaomi.d.ts +3 -0
  740. package/dist/providers/xiaomi.d.ts.map +1 -0
  741. package/dist/providers/xiaomi.js +15 -0
  742. package/dist/providers/xiaomi.js.map +1 -0
  743. package/dist/providers/xiaomi.models.d.ts +6 -0
  744. package/dist/providers/xiaomi.models.d.ts.map +1 -0
  745. package/dist/providers/xiaomi.models.js +8 -0
  746. package/dist/providers/xiaomi.models.js.map +1 -0
  747. package/dist/providers/zai-coding-cn.d.ts +3 -0
  748. package/dist/providers/zai-coding-cn.d.ts.map +1 -0
  749. package/dist/providers/zai-coding-cn.js +15 -0
  750. package/dist/providers/zai-coding-cn.js.map +1 -0
  751. package/dist/providers/zai-coding-cn.models.d.ts +6 -0
  752. package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
  753. package/dist/providers/zai-coding-cn.models.js +8 -0
  754. package/dist/providers/zai-coding-cn.models.js.map +1 -0
  755. package/dist/providers/zai.d.ts +3 -0
  756. package/dist/providers/zai.d.ts.map +1 -0
  757. package/dist/providers/zai.js +15 -0
  758. package/dist/providers/zai.js.map +1 -0
  759. package/dist/providers/zai.models.d.ts +6 -0
  760. package/dist/providers/zai.models.d.ts.map +1 -0
  761. package/dist/providers/zai.models.js +8 -0
  762. package/dist/providers/zai.models.js.map +1 -0
  763. package/dist/session-resources.d.ts +4 -0
  764. package/dist/session-resources.d.ts.map +1 -0
  765. package/dist/session-resources.js +22 -0
  766. package/dist/session-resources.js.map +1 -0
  767. package/dist/telemetry.d.ts +288 -0
  768. package/dist/telemetry.d.ts.map +1 -0
  769. package/dist/telemetry.js +192 -0
  770. package/dist/telemetry.js.map +1 -0
  771. package/dist/types.d.ts +707 -0
  772. package/dist/types.d.ts.map +1 -0
  773. package/dist/types.js +2 -0
  774. package/dist/types.js.map +1 -0
  775. package/dist/utils/abort-signals.d.ts +6 -0
  776. package/dist/utils/abort-signals.d.ts.map +1 -0
  777. package/dist/utils/abort-signals.js +34 -0
  778. package/dist/utils/abort-signals.js.map +1 -0
  779. package/dist/utils/abort.d.ts +8 -0
  780. package/dist/utils/abort.d.ts.map +1 -0
  781. package/dist/utils/abort.js +49 -0
  782. package/dist/utils/abort.js.map +1 -0
  783. package/dist/utils/diagnostics.d.ts +20 -0
  784. package/dist/utils/diagnostics.d.ts.map +1 -0
  785. package/dist/utils/diagnostics.js +25 -0
  786. package/dist/utils/diagnostics.js.map +1 -0
  787. package/dist/utils/error-body.d.ts +33 -0
  788. package/dist/utils/error-body.d.ts.map +1 -0
  789. package/dist/utils/error-body.js +161 -0
  790. package/dist/utils/error-body.js.map +1 -0
  791. package/dist/utils/estimate.d.ts +17 -0
  792. package/dist/utils/estimate.d.ts.map +1 -0
  793. package/dist/utils/estimate.js +95 -0
  794. package/dist/utils/estimate.js.map +1 -0
  795. package/dist/utils/event-stream.d.ts +30 -0
  796. package/dist/utils/event-stream.d.ts.map +1 -0
  797. package/dist/utils/event-stream.js +124 -0
  798. package/dist/utils/event-stream.js.map +1 -0
  799. package/dist/utils/hash.d.ts +3 -0
  800. package/dist/utils/hash.d.ts.map +1 -0
  801. package/dist/utils/hash.js +14 -0
  802. package/dist/utils/hash.js.map +1 -0
  803. package/dist/utils/headers.d.ts +4 -0
  804. package/dist/utils/headers.d.ts.map +1 -0
  805. package/dist/utils/headers.js +20 -0
  806. package/dist/utils/headers.js.map +1 -0
  807. package/dist/utils/identity.d.ts +65 -0
  808. package/dist/utils/identity.d.ts.map +1 -0
  809. package/dist/utils/identity.js +141 -0
  810. package/dist/utils/identity.js.map +1 -0
  811. package/dist/utils/json-parse.d.ts +26 -0
  812. package/dist/utils/json-parse.d.ts.map +1 -0
  813. package/dist/utils/json-parse.js +138 -0
  814. package/dist/utils/json-parse.js.map +1 -0
  815. package/dist/utils/model-operations.d.ts +13 -0
  816. package/dist/utils/model-operations.d.ts.map +1 -0
  817. package/dist/utils/model-operations.js +53 -0
  818. package/dist/utils/model-operations.js.map +1 -0
  819. package/dist/utils/models-error.d.ts +8 -0
  820. package/dist/utils/models-error.d.ts.map +1 -0
  821. package/dist/utils/models-error.js +19 -0
  822. package/dist/utils/models-error.js.map +1 -0
  823. package/dist/utils/node-http-proxy.d.ts +4 -0
  824. package/dist/utils/node-http-proxy.d.ts.map +1 -0
  825. package/dist/utils/node-http-proxy.js +133 -0
  826. package/dist/utils/node-http-proxy.js.map +1 -0
  827. package/dist/utils/oauth-page.d.ts +3 -0
  828. package/dist/utils/oauth-page.d.ts.map +1 -0
  829. package/dist/utils/oauth-page.js +105 -0
  830. package/dist/utils/oauth-page.js.map +1 -0
  831. package/dist/utils/openrouter-cost.d.ts +24 -0
  832. package/dist/utils/openrouter-cost.d.ts.map +1 -0
  833. package/dist/utils/openrouter-cost.js +34 -0
  834. package/dist/utils/openrouter-cost.js.map +1 -0
  835. package/dist/utils/overflow.d.ts +70 -0
  836. package/dist/utils/overflow.d.ts.map +1 -0
  837. package/dist/utils/overflow.js +186 -0
  838. package/dist/utils/overflow.js.map +1 -0
  839. package/dist/utils/provider-env.d.ts +7 -0
  840. package/dist/utils/provider-env.d.ts.map +1 -0
  841. package/dist/utils/provider-env.js +44 -0
  842. package/dist/utils/provider-env.js.map +1 -0
  843. package/dist/utils/provider-retry.d.ts +18 -0
  844. package/dist/utils/provider-retry.d.ts.map +1 -0
  845. package/dist/utils/provider-retry.js +97 -0
  846. package/dist/utils/provider-retry.js.map +1 -0
  847. package/dist/utils/retry.d.ts +58 -0
  848. package/dist/utils/retry.d.ts.map +1 -0
  849. package/dist/utils/retry.js +257 -0
  850. package/dist/utils/retry.js.map +1 -0
  851. package/dist/utils/sanitize-unicode.d.ts +22 -0
  852. package/dist/utils/sanitize-unicode.d.ts.map +1 -0
  853. package/dist/utils/sanitize-unicode.js +26 -0
  854. package/dist/utils/sanitize-unicode.js.map +1 -0
  855. package/dist/utils/sleep.d.ts +2 -0
  856. package/dist/utils/sleep.d.ts.map +1 -0
  857. package/dist/utils/sleep.js +15 -0
  858. package/dist/utils/sleep.js.map +1 -0
  859. package/dist/utils/streaming-json.d.ts +84 -0
  860. package/dist/utils/streaming-json.d.ts.map +1 -0
  861. package/dist/utils/streaming-json.js +513 -0
  862. package/dist/utils/streaming-json.js.map +1 -0
  863. package/dist/utils/string-enum.d.ts +17 -0
  864. package/dist/utils/string-enum.d.ts.map +1 -0
  865. package/dist/utils/string-enum.js +20 -0
  866. package/dist/utils/string-enum.js.map +1 -0
  867. package/dist/utils/text.d.ts +21 -0
  868. package/dist/utils/text.d.ts.map +1 -0
  869. package/dist/utils/text.js +45 -0
  870. package/dist/utils/text.js.map +1 -0
  871. package/dist/utils/transcript.d.ts +101 -0
  872. package/dist/utils/transcript.d.ts.map +1 -0
  873. package/dist/utils/transcript.js +218 -0
  874. package/dist/utils/transcript.js.map +1 -0
  875. package/dist/utils/uuid.d.ts +3 -0
  876. package/dist/utils/uuid.d.ts.map +1 -0
  877. package/dist/utils/uuid.js +42 -0
  878. package/dist/utils/uuid.js.map +1 -0
  879. package/dist/utils/validation.d.ts +20 -0
  880. package/dist/utils/validation.d.ts.map +1 -0
  881. package/dist/utils/validation.js +62 -0
  882. package/dist/utils/validation.js.map +1 -0
  883. package/dist/utils/version.d.ts +2 -0
  884. package/dist/utils/version.d.ts.map +1 -0
  885. package/dist/utils/version.js +3 -0
  886. package/dist/utils/version.js.map +1 -0
  887. package/package.json +119 -5
@@ -0,0 +1,72 @@
1
+ /**
2
+ * AI Gateway transport over the Workers AI binding.
3
+ *
4
+ * diffra's Cloudflare AI Gateway support speaks HTTPS
5
+ * (`gateway.ai.cloudflare.com/v1/{account}/{gateway}/{provider}/...`, see `api/cloudflare.ts`),
6
+ * which needs a Cloudflare API token even when the caller is a Worker in the gateway's own
7
+ * account.
8
+ *
9
+ * A Worker avoids that token by talking to the gateway through the AI binding's `fetch`
10
+ * passthrough (`env.AI.fetch()`), which serves the gateway's provider passthrough at
11
+ * `https://workers-binding.ai/ai-gateway/gateways/{gateway}/{provider}/{endpoint...}` — the same
12
+ * shape as the HTTPS URL, minus the account id (the binding channel carries identity). Binding
13
+ * calls are pre-authenticated in-account and return the provider's native wire format as a
14
+ * regular (streaming) `Response`, so API implementations behave identically over either
15
+ * transport.
16
+ *
17
+ * A model whose `baseUrl` names that route therefore needs no translation: point it there and
18
+ * pass {@link createAiBindingFetch} as the request `fetch`. Nothing is rewritten, buffered or
19
+ * re-encoded — method, headers, query string and the body stream go to the binding as they
20
+ * arrive, so every method, non-JSON body and streaming request body works.
21
+ *
22
+ * The only thing this module adds over calling `env.AI.fetch()` yourself is a type: `Ai#fetch`
23
+ * exists at runtime (`workerd/src/cloudflare/internal/ai-api.ts:158`) but
24
+ * `@cloudflare/workers-types`' `Ai` class does not declare it yet, so calling it directly means
25
+ * casting the binding at every call site. {@link AiBinding} takes the cast instead — declare
26
+ * `fetch` optional, check it once at construction — so `env.AI` can be passed as-is. Once
27
+ * workers-types declares `fetch`, the optional marker and the runtime check both go away.
28
+ */
29
+ /**
30
+ * Placeholder value for auth headers on binding-routed requests. API implementations
31
+ * require an API key or a recognized auth header (`authorization`, `x-api-key`,
32
+ * `cf-aig-authorization`) before dispatch; binding calls are pre-authenticated, so pass
33
+ * `cf-aig-authorization: Bearer ${CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL}` to satisfy
34
+ * the check. The gateway ignores (and strips) `cf-aig-authorization` on binding-routed
35
+ * requests. Pair it with `Authorization: null` / `x-api-key: null` so the SDKs' placeholder
36
+ * auth headers never reach the gateway, which would treat a request-supplied auth header as a
37
+ * BYOK provider key that overrides its stored keys — the same as it would over HTTPS.
38
+ */
39
+ export const CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL = "cloudflare-gateway-binding";
40
+ /**
41
+ * Create a `fetch` backed by the AI binding, for models whose `baseUrl` already names a route
42
+ * the binding serves — including the gateway's provider passthrough,
43
+ * `https://workers-binding.ai/ai-gateway/gateways/{gateway}/{provider}/...`. Requests pass
44
+ * through untouched.
45
+ *
46
+ * ```ts
47
+ * const model = {
48
+ * // ...
49
+ * baseUrl: `https://workers-binding.ai/ai-gateway/gateways/${gateway}/anthropic`,
50
+ * };
51
+ * await models.complete(model, context, {
52
+ * headers: {
53
+ * "cf-aig-authorization": `Bearer ${CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL}`,
54
+ * Authorization: null,
55
+ * "x-api-key": null,
56
+ * },
57
+ * fetch: createAiBindingFetch(env.AI),
58
+ * });
59
+ * ```
60
+ */
61
+ export function createAiBindingFetch(binding) {
62
+ // `fetch` is optional on the type, so its presence is checked here — early, rather than as a
63
+ // confusing failure on the first inference request.
64
+ if (typeof binding.fetch !== "function") {
65
+ throw new TypeError("createAiBindingFetch: the AI binding does not expose fetch()");
66
+ }
67
+ // Bound eagerly: `fetch` is a mutable property, so the narrowing above would not survive into
68
+ // the returned closure.
69
+ const bindingFetch = binding.fetch.bind(binding);
70
+ return (input, init) => bindingFetch(input, init);
71
+ }
72
+ //# sourceMappingURL=cloudflare-ai-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-ai-binding.js","sourceRoot":"","sources":["../../src/api/cloudflare-ai-binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAmBH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,4BAA4B,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAkB;IACtD,6FAA6F;IAC7F,oDAAoD;IACpD,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACzC,MAAM,IAAI,SAAS,CAAC,8DAA8D,CAAC,CAAC;IACrF,CAAC;IACD,8FAA8F;IAC9F,wBAAwB;IACxB,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/**\n * AI Gateway transport over the Workers AI binding.\n *\n * diffra's Cloudflare AI Gateway support speaks HTTPS\n * (`gateway.ai.cloudflare.com/v1/{account}/{gateway}/{provider}/...`, see `api/cloudflare.ts`),\n * which needs a Cloudflare API token even when the caller is a Worker in the gateway's own\n * account.\n *\n * A Worker avoids that token by talking to the gateway through the AI binding's `fetch`\n * passthrough (`env.AI.fetch()`), which serves the gateway's provider passthrough at\n * `https://workers-binding.ai/ai-gateway/gateways/{gateway}/{provider}/{endpoint...}` — the same\n * shape as the HTTPS URL, minus the account id (the binding channel carries identity). Binding\n * calls are pre-authenticated in-account and return the provider's native wire format as a\n * regular (streaming) `Response`, so API implementations behave identically over either\n * transport.\n *\n * A model whose `baseUrl` names that route therefore needs no translation: point it there and\n * pass {@link createAiBindingFetch} as the request `fetch`. Nothing is rewritten, buffered or\n * re-encoded — method, headers, query string and the body stream go to the binding as they\n * arrive, so every method, non-JSON body and streaming request body works.\n *\n * The only thing this module adds over calling `env.AI.fetch()` yourself is a type: `Ai#fetch`\n * exists at runtime (`workerd/src/cloudflare/internal/ai-api.ts:158`) but\n * `@cloudflare/workers-types`' `Ai` class does not declare it yet, so calling it directly means\n * casting the binding at every call site. {@link AiBinding} takes the cast instead — declare\n * `fetch` optional, check it once at construction — so `env.AI` can be passed as-is. Once\n * workers-types declares `fetch`, the optional marker and the runtime check both go away.\n */\n\nimport type { FetchFunction } from \"../types.ts\";\n\n/**\n * The Workers AI binding (`env.AI`), described structurally so this module does not depend on\n * `@cloudflare/workers-types`.\n *\n * `fetch` is optional only because the published `Ai` type doesn't declare it yet — every real\n * binding has it at runtime. `aiGatewayLogId` is here to pin the type to the AI binding: it is\n * the one member unique to `Ai`, so without it this interface would also accept an `AiGateway`\n * or any hand-rolled `{ fetch }` object, which is exactly the mistake the runtime check reports\n * late.\n */\nexport interface AiBinding {\n\taiGatewayLogId: string | null;\n\tfetch?(input: Request | string | URL, init?: RequestInit): Promise<Response>;\n}\n\n/**\n * Placeholder value for auth headers on binding-routed requests. API implementations\n * require an API key or a recognized auth header (`authorization`, `x-api-key`,\n * `cf-aig-authorization`) before dispatch; binding calls are pre-authenticated, so pass\n * `cf-aig-authorization: Bearer ${CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL}` to satisfy\n * the check. The gateway ignores (and strips) `cf-aig-authorization` on binding-routed\n * requests. Pair it with `Authorization: null` / `x-api-key: null` so the SDKs' placeholder\n * auth headers never reach the gateway, which would treat a request-supplied auth header as a\n * BYOK provider key that overrides its stored keys — the same as it would over HTTPS.\n */\nexport const CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL = \"cloudflare-gateway-binding\";\n\n/**\n * Create a `fetch` backed by the AI binding, for models whose `baseUrl` already names a route\n * the binding serves — including the gateway's provider passthrough,\n * `https://workers-binding.ai/ai-gateway/gateways/{gateway}/{provider}/...`. Requests pass\n * through untouched.\n *\n * ```ts\n * const model = {\n * // ...\n * baseUrl: `https://workers-binding.ai/ai-gateway/gateways/${gateway}/anthropic`,\n * };\n * await models.complete(model, context, {\n * headers: {\n * \"cf-aig-authorization\": `Bearer ${CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL}`,\n * Authorization: null,\n * \"x-api-key\": null,\n * },\n * fetch: createAiBindingFetch(env.AI),\n * });\n * ```\n */\nexport function createAiBindingFetch(binding: AiBinding): FetchFunction {\n\t// `fetch` is optional on the type, so its presence is checked here — early, rather than as a\n\t// confusing failure on the first inference request.\n\tif (typeof binding.fetch !== \"function\") {\n\t\tthrow new TypeError(\"createAiBindingFetch: the AI binding does not expose fetch()\");\n\t}\n\t// Bound eagerly: `fetch` is a mutable property, so the narrowing above would not survive into\n\t// the returned closure.\n\tconst bindingFetch = binding.fetch.bind(binding);\n\treturn (input, init) => bindingFetch(input, init);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { ClassifierFunction, ClassifierOptions } from "../types.ts";
2
+ /** Cloudflare Workers AI System One classification with public `bool` values mapped to wire-level `noul`. */
3
+ export declare const classify: ClassifierFunction<ClassifierOptions>;
4
+ //# sourceMappingURL=cloudflare-workers-ai-system-one.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-workers-ai-system-one.d.ts","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAqDzE,6GAA6G;AAC7G,eAAO,MAAM,QAAQ,EAAE,kBAAkB,CAAC,iBAAiB,CACL,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { isRecord } from "./classifier-shared.js";
2
+ import { classifySystemOne } from "./system-one-shared.js";
3
+ const LABEL = "Cloudflare Workers AI";
4
+ function cloudflareErrorMessage(errors) {
5
+ if (Array.isArray(errors)) {
6
+ const messages = errors
7
+ .map((error) => (isRecord(error) && typeof error.message === "string" ? error.message : undefined))
8
+ .filter((message) => message !== undefined);
9
+ if (messages.length > 0)
10
+ return `${LABEL} error: ${messages.join("; ")}`;
11
+ }
12
+ return `${LABEL} request failed`;
13
+ }
14
+ /**
15
+ * System One models on the Workers AI REST endpoint:
16
+ * `POST /accounts/{account}/ai/run` with `{ model, input }`. The REST API wraps the model
17
+ * output in Cloudflare's API envelope. Third-party models such as `typesafe/jev` add a run record:
18
+ * `{ success, result: { state: "Completed", result: { answers, usage } } }`.
19
+ * https://developers.cloudflare.com/ai/models/typesafe/jev/
20
+ * Cloudflare-hosted models such as `@cf/cloudflare/clef` return the output directly:
21
+ * `{ success, result: { model, answers, usage } }`.
22
+ * https://developers.cloudflare.com/workers-ai/models/clef/
23
+ *
24
+ * Clef models take images as an `images` list of data URLs. TypeSafe's models take them as
25
+ * System One `assets`, without TypeSafe's opt-in header. The catalog sets `compat.imageInput`;
26
+ * the model ID check only covers models without it.
27
+ */
28
+ const transport = {
29
+ api: "cloudflare-workers-ai-system-one",
30
+ label: LABEL,
31
+ detectCompat: (model) => ({
32
+ imageInput: model.id.startsWith("@cf/cloudflare/clef") ? "images" : "assets",
33
+ sendImageOptInHeader: false,
34
+ }),
35
+ url: (model) => new URL("run", `${model.baseUrl.replace(/\/+$/u, "")}/`),
36
+ payload: (model, request) => ({ model: model.id, input: request }),
37
+ output: (body) => {
38
+ if (!isRecord(body))
39
+ throw new Error(`${LABEL} returned an unexpected response`);
40
+ if (body.success === false)
41
+ throw new Error(cloudflareErrorMessage(body.errors));
42
+ const result = body.result;
43
+ if (!isRecord(result))
44
+ throw new Error(`${LABEL} returned an unexpected response`);
45
+ if ("answers" in result)
46
+ return result;
47
+ if (result.state !== "Completed") {
48
+ throw new Error(`${LABEL} run did not complete (state: ${String(result.state)})`);
49
+ }
50
+ if (!isRecord(result.result))
51
+ throw new Error(`${LABEL} returned an unexpected response`);
52
+ return result.result;
53
+ },
54
+ };
55
+ /** Cloudflare Workers AI System One classification with public `bool` values mapped to wire-level `noul`. */
56
+ export const classify = (model, context, options) => classifySystemOne(transport, model, context, options);
57
+ //# sourceMappingURL=cloudflare-workers-ai-system-one.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-workers-ai-system-one.js","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AAEpF,MAAM,KAAK,GAAG,uBAAuB,CAAC;AAEtC,SAAS,sBAAsB,CAAC,MAAe;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,MAAM;aACrB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,K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,CAAC,CAAC;QACjF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;QACnF,IAAI,SAAS,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QACvC,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,iCAAiC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;QAC1F,OAAO,MAAM,CAAC,MAAM,CAAC;IACtB,CAAC;CACD,CAAC;AAEF,6GAA6G;AAC7G,MAAM,CAAC,MAAM,QAAQ,GAA0C,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC1F,iBAAiB,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import type { ClassifierFunction, ClassifierOptions } from \"../types.ts\";\nimport { isRecord } from \"./classifier-shared.ts\";\nimport { classifySystemOne, type SystemOneTransport } from \"./system-one-shared.ts\";\n\nconst LABEL = \"Cloudflare Workers AI\";\n\nfunction cloudflareErrorMessage(errors: unknown): string {\n\tif (Array.isArray(errors)) {\n\t\tconst messages = errors\n\t\t\t.map((error) => (isRecord(error) && typeof error.message === \"string\" ? error.message : undefined))\n\t\t\t.filter((message): message is string => message !== undefined);\n\t\tif (messages.length > 0) return `${LABEL} error: ${messages.join(\"; \")}`;\n\t}\n\treturn `${LABEL} request failed`;\n}\n\n/**\n * System One models on the Workers AI REST endpoint:\n * `POST /accounts/{account}/ai/run` with `{ model, input }`. The REST API wraps the model\n * output in Cloudflare's API envelope. Third-party models such as `typesafe/jev` add a run record:\n * `{ success, result: { state: \"Completed\", result: { answers, usage } } }`.\n * https://developers.cloudflare.com/ai/models/typesafe/jev/\n * Cloudflare-hosted models such as `@cf/cloudflare/clef` return the output directly:\n * `{ success, result: { model, answers, usage } }`.\n * https://developers.cloudflare.com/workers-ai/models/clef/\n *\n * Clef models take images as an `images` list of data URLs. TypeSafe's models take them as\n * System One `assets`, without TypeSafe's opt-in header. The catalog sets `compat.imageInput`;\n * the model ID check only covers models without it.\n */\nconst transport: SystemOneTransport = {\n\tapi: \"cloudflare-workers-ai-system-one\",\n\tlabel: LABEL,\n\tdetectCompat: (model) => ({\n\t\timageInput: model.id.startsWith(\"@cf/cloudflare/clef\") ? \"images\" : \"assets\",\n\t\tsendImageOptInHeader: false,\n\t}),\n\turl: (model) => new URL(\"run\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`),\n\tpayload: (model, request) => ({ model: model.id, input: request }),\n\toutput: (body) => {\n\t\tif (!isRecord(body)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\tif (body.success === false) throw new Error(cloudflareErrorMessage(body.errors));\n\t\tconst result = body.result;\n\t\tif (!isRecord(result)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\tif (\"answers\" in result) return result;\n\t\tif (result.state !== \"Completed\") {\n\t\t\tthrow new Error(`${LABEL} run did not complete (state: ${String(result.state)})`);\n\t\t}\n\t\tif (!isRecord(result.result)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\treturn result.result;\n\t},\n};\n\n/** Cloudflare Workers AI System One classification with public `bool` values mapped to wire-level `noul`. */\nexport const classify: ClassifierFunction<ClassifierOptions> = (model, context, options) =>\n\tclassifySystemOne(transport, model, context, options);\n"]}
@@ -0,0 +1,3 @@
1
+ import type { ProviderClassifier } from "../types.ts";
2
+ export declare const cloudflareWorkersAISystemOneApi: () => ProviderClassifier;
3
+ //# sourceMappingURL=cloudflare-workers-ai-system-one.lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-workers-ai-system-one.lazy.d.ts","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,+BAA+B,QAAO,kBAGjD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const cloudflareWorkersAISystemOneApi = () => ({
2
+ classify: async (model, context, options) => (await import("./cloudflare-workers-ai-system-one.js")).classify(model, context, options),
3
+ });
4
+ //# sourceMappingURL=cloudflare-workers-ai-system-one.lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-workers-ai-system-one.lazy.js","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAuB,EAAE,CAAC,CAAC;IACzE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC3C,CAAC,MAAM,MAAM,CAAC,uCAAuC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;CAC1F,CAAC,CAAC","sourcesContent":["import type { ProviderClassifier } from \"../types.ts\";\n\nexport const cloudflareWorkersAISystemOneApi = (): ProviderClassifier => ({\n\tclassify: async (model, context, options) =>\n\t\t(await import(\"./cloudflare-workers-ai-system-one.ts\")).classify(model, context, options),\n});\n"]}
@@ -0,0 +1,11 @@
1
+ /** Workers AI direct endpoint. */
2
+ export declare const CLOUDFLARE_WORKERS_AI_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1";
3
+ /** Workers AI REST endpoint root; model runs are posted to `run`. */
4
+ export declare const CLOUDFLARE_WORKERS_AI_REST_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai";
5
+ /** AI Gateway Unified API. https://developers.cloudflare.com/ai-gateway/usage/unified-api/ */
6
+ export declare const CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat";
7
+ /** AI Gateway → OpenAI passthrough. Used until /compat supports /v1/responses. */
8
+ export declare const CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai";
9
+ /** AI Gateway → Anthropic passthrough. */
10
+ export declare const CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic";
11
+ //# sourceMappingURL=cloudflare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/api/cloudflare.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,eAAO,MAAM,8BAA8B,gFACmC,CAAC;AAE/E,qEAAqE;AACrE,eAAO,MAAM,mCAAmC,6EAC2B,CAAC;AAE5E,8FAA8F;AAC9F,eAAO,MAAM,qCAAqC,gGAC4C,CAAC;AAE/F,kFAAkF;AAClF,eAAO,MAAM,qCAAqC,gGAC4C,CAAC;AAE/F,0CAA0C;AAC1C,eAAO,MAAM,wCAAwC,mGAC4C,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Workers AI direct endpoint. */
2
+ export const CLOUDFLARE_WORKERS_AI_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1";
3
+ /** Workers AI REST endpoint root; model runs are posted to `run`. */
4
+ export const CLOUDFLARE_WORKERS_AI_REST_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai";
5
+ /** AI Gateway Unified API. https://developers.cloudflare.com/ai-gateway/usage/unified-api/ */
6
+ export const CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat";
7
+ /** AI Gateway → OpenAI passthrough. Used until /compat supports /v1/responses. */
8
+ export const CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai";
9
+ /** AI Gateway → Anthropic passthrough. */
10
+ export const CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic";
11
+ //# sourceMappingURL=cloudflare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../src/api/cloudflare.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,MAAM,CAAC,MAAM,8BAA8B,GAC1C,6EAA6E,CAAC;AAE/E,qEAAqE;AACrE,MAAM,CAAC,MAAM,mCAAmC,GAC/C,0EAA0E,CAAC;AAE5E,8FAA8F;AAC9F,MAAM,CAAC,MAAM,qCAAqC,GACjD,6FAA6F,CAAC;AAE/F,kFAAkF;AAClF,MAAM,CAAC,MAAM,qCAAqC,GACjD,6FAA6F,CAAC;AAE/F,0CAA0C;AAC1C,MAAM,CAAC,MAAM,wCAAwC,GACpD,gGAAgG,CAAC","sourcesContent":["/** Workers AI direct endpoint. */\nexport const CLOUDFLARE_WORKERS_AI_BASE_URL =\n\t\"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1\";\n\n/** Workers AI REST endpoint root; model runs are posted to `run`. */\nexport const CLOUDFLARE_WORKERS_AI_REST_BASE_URL =\n\t\"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai\";\n\n/** AI Gateway Unified API. https://developers.cloudflare.com/ai-gateway/usage/unified-api/ */\nexport const CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL =\n\t\"https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat\";\n\n/** AI Gateway → OpenAI passthrough. Used until /compat supports /v1/responses. */\nexport const CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL =\n\t\"https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai\";\n\n/** AI Gateway → Anthropic passthrough. */\nexport const CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL =\n\t\"https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic\";\n"]}
@@ -0,0 +1,38 @@
1
+ import type { Tool } from "../types.ts";
2
+ /** Returns true when a provider's strict mode rejects this schema keyword with this value. */
3
+ export type UnsupportedStrictSchemaKeywordCheck = (key: string, value: unknown) => boolean;
4
+ /** Convert a tool schema to the strict subset expected by provider constrained sampling. */
5
+ export declare function makeStrictJsonSchema(schema: Tool["parameters"], isUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck): Record<string, unknown>;
6
+ /** Returns true for a tool that asks for strict JSON-schema sampling only when possible (`strict: "prefer"`). */
7
+ export declare function prefersJsonSchemaStrictSampling(tool: Tool): boolean;
8
+ export declare function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined): Tool["parameters"];
9
+ export interface GrammarConstrainedSampling {
10
+ format: "lark" | "regex";
11
+ definition: string;
12
+ inputProperty: string;
13
+ }
14
+ export interface GrammarToolInputJsonBuffer {
15
+ input: string;
16
+ started: boolean;
17
+ closed: boolean;
18
+ }
19
+ export declare function getGrammarToolInput(toolName: string, arguments_: Record<string, unknown>, inputProperty: string): string;
20
+ /**
21
+ * Append `inputDelta` to a streaming grammar tool input and return the matching piece of its JSON arguments text, or
22
+ * `undefined` for an empty delta. Costs time linear in the delta, never in the input so far.
23
+ */
24
+ export declare function appendGrammarToolInputJsonDelta(buffer: GrammarToolInputJsonBuffer, inputProperty: string, inputDelta: string): string | undefined;
25
+ /**
26
+ * Close a streaming grammar tool input and return the rest of its JSON arguments text. `finalInput` is the complete
27
+ * input when the provider sends one; it must continue the input streamed so far. Closing again with the same input
28
+ * returns `undefined`.
29
+ */
30
+ export declare function closeGrammarToolInputJson(buffer: GrammarToolInputJsonBuffer, inputProperty: string, finalInput: string | undefined): string | undefined;
31
+ /**
32
+ * Decide whether a JSON-schema tool is sent in strict mode. `isUnsupportedKeyword` lets a provider
33
+ * reject extra keywords its strict mode does not accept, so "prefer" tools fall back to non-strict.
34
+ */
35
+ export declare function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean, isUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck): boolean | undefined;
36
+ export declare function resolveGrammarConstrainedSampling(tool: Tool, supportsOpenAIGrammarTools: boolean): GrammarConstrainedSampling | undefined;
37
+ export declare function createGrammarToolInputProperties(tools: Tool[] | undefined, supportsOpenAIGrammarTools: boolean): ReadonlyMap<string, string>;
38
+ //# sourceMappingURL=constrained-sampling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constrained-sampling.d.ts","sourceRoot":"","sources":["../../src/api/constrained-sampling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAWxC,8FAA8F;AAC9F,MAAM,MAAM,mCAAmC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAsH3F,4FAA4F;AAC5F,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,EAC1B,oBAAoB,CAAC,EAAE,mC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C,CAC/C,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,EACzB,0BAA0B,EAAE,OAAO,GACjC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAS7B"}
@@ -0,0 +1,257 @@
1
+ class UnsupportedStrictJsonSchemaError extends Error {
2
+ }
3
+ const UNSUPPORTED_STRICT_SCHEMA_KEYS = [
4
+ "$ref",
5
+ "$defs",
6
+ "definitions",
7
+ "allOf",
8
+ "oneOf",
9
+ "patternProperties",
10
+ "dependentSchemas",
11
+ "dependencies",
12
+ "unevaluatedProperties",
13
+ "propertyNames",
14
+ "contains",
15
+ "prefixItems",
16
+ "not",
17
+ "if",
18
+ "then",
19
+ "else",
20
+ ];
21
+ function isJsonSchemaObject(value) {
22
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23
+ }
24
+ function isStructuredSchema(schema) {
25
+ if (!isJsonSchemaObject(schema))
26
+ return false;
27
+ const types = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
28
+ return (types.includes("object") ||
29
+ types.includes("array") ||
30
+ schema.properties !== undefined ||
31
+ schema.items !== undefined);
32
+ }
33
+ function schemaAllowsNull(schema) {
34
+ if (!isJsonSchemaObject(schema))
35
+ return false;
36
+ if (schema.type === "null" || (Array.isArray(schema.type) && schema.type.includes("null")))
37
+ return true;
38
+ if (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null)))
39
+ return true;
40
+ return Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));
41
+ }
42
+ function makeJsonSchemaNodeStrict(schema, isUnsupportedKeyword) {
43
+ if (!isJsonSchemaObject(schema)) {
44
+ throw new UnsupportedStrictJsonSchemaError("boolean schemas are unsupported");
45
+ }
46
+ for (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {
47
+ if (schema[key] !== undefined) {
48
+ throw new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);
49
+ }
50
+ }
51
+ if (isUnsupportedKeyword) {
52
+ for (const [key, value] of Object.entries(schema)) {
53
+ if (isUnsupportedKeyword(key, value)) {
54
+ throw new UnsupportedStrictJsonSchemaError(`${key}: ${JSON.stringify(value)} is unsupported`);
55
+ }
56
+ }
57
+ }
58
+ // OpenAI strict mode rejects nodes without a type; a bare enum counts as typed, a bare const does not.
59
+ if (schema.type === undefined && schema.anyOf === undefined && schema.enum === undefined) {
60
+ throw new UnsupportedStrictJsonSchemaError("schemas without a type are unsupported");
61
+ }
62
+ if (schema.anyOf !== undefined) {
63
+ if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
64
+ throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
65
+ }
66
+ for (const variant of schema.anyOf) {
67
+ if (isStructuredSchema(variant)) {
68
+ throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
69
+ }
70
+ makeJsonSchemaNodeStrict(variant, isUnsupportedKeyword);
71
+ }
72
+ }
73
+ if (schema.items !== undefined) {
74
+ if (Array.isArray(schema.items)) {
75
+ throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
76
+ }
77
+ makeJsonSchemaNodeStrict(schema.items, isUnsupportedKeyword);
78
+ }
79
+ const isObjectSchema = schema.type === "object";
80
+ if (schema.properties !== undefined && !isObjectSchema) {
81
+ throw new UnsupportedStrictJsonSchemaError("properties require type object");
82
+ }
83
+ if (!isObjectSchema)
84
+ return;
85
+ if (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {
86
+ throw new UnsupportedStrictJsonSchemaError("schema-valued or true additionalProperties is unsupported");
87
+ }
88
+ if (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {
89
+ throw new UnsupportedStrictJsonSchemaError("object properties must be a schema map");
90
+ }
91
+ if (schema.required !== undefined &&
92
+ (!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
93
+ throw new UnsupportedStrictJsonSchemaError("object required must be a string array");
94
+ }
95
+ const properties = schema.properties ?? {};
96
+ const propertyNames = Object.keys(properties);
97
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
98
+ if ([...required].some((key) => !propertyNames.includes(key))) {
99
+ throw new UnsupportedStrictJsonSchemaError("required contains an unknown property");
100
+ }
101
+ for (const [key, property] of Object.entries(properties)) {
102
+ makeJsonSchemaNodeStrict(property, isUnsupportedKeyword);
103
+ if (!required.has(key) && !schemaAllowsNull(property)) {
104
+ properties[key] = { anyOf: [property, { type: "null" }] };
105
+ }
106
+ }
107
+ schema.required = propertyNames;
108
+ schema.additionalProperties = false;
109
+ }
110
+ /** Convert a tool schema to the strict subset expected by provider constrained sampling. */
111
+ export function makeStrictJsonSchema(schema, isUnsupportedKeyword) {
112
+ const cloned = structuredClone(schema);
113
+ if (!isJsonSchemaObject(cloned)) {
114
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
115
+ }
116
+ makeJsonSchemaNodeStrict(cloned, isUnsupportedKeyword);
117
+ if (cloned.type !== "object") {
118
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
119
+ }
120
+ return cloned;
121
+ }
122
+ /** Returns true for a tool that asks for strict JSON-schema sampling only when possible (`strict: "prefer"`). */
123
+ export function prefersJsonSchemaStrictSampling(tool) {
124
+ const config = tool.constrainedSampling;
125
+ return !!config && config.type === "json_schema" && config.strict === "prefer";
126
+ }
127
+ export function getJsonSchemaToolParameters(tool, strict) {
128
+ return (strict === true ? makeStrictJsonSchema(tool.parameters) : tool.parameters);
129
+ }
130
+ export function getGrammarToolInput(toolName, arguments_, inputProperty) {
131
+ const input = arguments_[inputProperty];
132
+ if (typeof input !== "string") {
133
+ throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
134
+ }
135
+ return input;
136
+ }
137
+ /**
138
+ * Append `inputDelta` to a streaming grammar tool input and return the matching piece of its JSON arguments text, or
139
+ * `undefined` for an empty delta. Costs time linear in the delta, never in the input so far.
140
+ */
141
+ export function appendGrammarToolInputJsonDelta(buffer, inputProperty, inputDelta) {
142
+ if (buffer.closed) {
143
+ throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
144
+ }
145
+ if (inputDelta.length === 0)
146
+ return undefined;
147
+ buffer.input += inputDelta;
148
+ return grammarToolInputJsonStart(buffer, inputProperty) + JSON.stringify(inputDelta).slice(1, -1);
149
+ }
150
+ /**
151
+ * Close a streaming grammar tool input and return the rest of its JSON arguments text. `finalInput` is the complete
152
+ * input when the provider sends one; it must continue the input streamed so far. Closing again with the same input
153
+ * returns `undefined`.
154
+ */
155
+ export function closeGrammarToolInputJson(buffer, inputProperty, finalInput) {
156
+ if (buffer.closed) {
157
+ if (finalInput === undefined || finalInput === buffer.input)
158
+ return undefined;
159
+ throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
160
+ }
161
+ if (finalInput !== undefined && !finalInput.startsWith(buffer.input)) {
162
+ throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
163
+ }
164
+ const rest = finalInput === undefined ? "" : finalInput.slice(buffer.input.length);
165
+ if (finalInput !== undefined)
166
+ buffer.input = finalInput;
167
+ buffer.closed = true;
168
+ return `${grammarToolInputJsonStart(buffer, inputProperty)}${JSON.stringify(rest).slice(1, -1)}"}`;
169
+ }
170
+ /** The opening of the JSON arguments text, once. */
171
+ function grammarToolInputJsonStart(buffer, inputProperty) {
172
+ if (buffer.started)
173
+ return "";
174
+ buffer.started = true;
175
+ return `{${JSON.stringify(inputProperty)}:"`;
176
+ }
177
+ function inferGrammarInputProperty(tool) {
178
+ const schema = tool.parameters;
179
+ if (schema.type !== "object") {
180
+ throw new Error("grammar constrained sampling requires an object parameter schema");
181
+ }
182
+ if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== "string") {
183
+ throw new Error("grammar constrained sampling requires exactly one required string property");
184
+ }
185
+ const inputProperty = schema.required[0];
186
+ if (!schema.properties?.[inputProperty]) {
187
+ throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);
188
+ }
189
+ if (schema.properties[inputProperty]?.type !== "string") {
190
+ throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
191
+ }
192
+ return inputProperty;
193
+ }
194
+ /**
195
+ * Decide whether a JSON-schema tool is sent in strict mode. `isUnsupportedKeyword` lets a provider
196
+ * reject extra keywords its strict mode does not accept, so "prefer" tools fall back to non-strict.
197
+ */
198
+ export function resolveJsonSchemaStrictSampling(tool, supportsStrictMode, isUnsupportedKeyword) {
199
+ const config = tool.constrainedSampling;
200
+ if (!config || config.type !== "json_schema")
201
+ return undefined;
202
+ if (supportsStrictMode) {
203
+ try {
204
+ makeStrictJsonSchema(tool.parameters, isUnsupportedKeyword);
205
+ return true;
206
+ }
207
+ catch (error) {
208
+ if (!(error instanceof UnsupportedStrictJsonSchemaError))
209
+ throw error;
210
+ if (config.strict !== "require")
211
+ return undefined;
212
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but ${error.message}.`);
213
+ }
214
+ }
215
+ if (config.strict === "require") {
216
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
217
+ }
218
+ return undefined;
219
+ }
220
+ export function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {
221
+ const config = tool.constrainedSampling;
222
+ if (!config || config.type !== "grammar") {
223
+ return undefined;
224
+ }
225
+ if (!supportsOpenAIGrammarTools) {
226
+ return undefined;
227
+ }
228
+ const larkDefinition = config.variants.openai_lark;
229
+ const regexDefinition = config.variants.openai_regex;
230
+ const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
231
+ const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
232
+ if (!hasLarkDefinition && !hasRegexDefinition) {
233
+ throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);
234
+ }
235
+ try {
236
+ return {
237
+ format: hasLarkDefinition ? "lark" : "regex",
238
+ definition: hasLarkDefinition ? larkDefinition : regexDefinition,
239
+ inputProperty: inferGrammarInputProperty(tool),
240
+ };
241
+ }
242
+ catch (error) {
243
+ const message = error instanceof Error ? error.message : String(error);
244
+ throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
245
+ }
246
+ }
247
+ export function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {
248
+ const properties = new Map();
249
+ for (const tool of tools ?? []) {
250
+ const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
251
+ if (grammar) {
252
+ properties.set(tool.name, grammar.inputProperty);
253
+ }
254
+ }
255
+ return properties;
256
+ }
257
+ //# sourceMappingURL=constrained-sampling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constrained-sampling.js","sourceRoot":"","sources":["../../src/api/constrained-sampling.ts"],"names":[],"mappings":"AASA,MAAM,gCAAiC,SAAQ,KAAK;CAAG;AAKvD,MAAM,8BAA8B,GAAG;IACtC,MAAM;IACN,OAAO;IACP,aAAa;IACb,OAAO;IACP,OAAO;IACP,mBAAmB;IACnB,kBAAkB;IAClB,cAAc;IACd,uBAAuB;IACvB,eAAe;IACf,UAAU;IACV,aAAa;IACb,KAAK;IACL,IAAI;IACJ,MAAM;IACN,MAAM;CACG,CAAC;AAEX,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAe;IAC1C,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,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CAAC,eAAgB;YACjE,aAAa,EAAE,yBAAyB,CAAC,IAAI,CAAC;SAC9C,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,8CAA8C,OAAO,GAAG,CAAC,CAAC;IAC7F,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC/C,KAAyB,EACzB,0BAAmC;IAEnC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,iCAAiC,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACpF,IAAI,OAAO,EAAE,CAAC;YACb,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAClD,CAAC;IACF,CAAC;IACD,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import type { Tool } from \"../types.ts\";\n\ninterface JsonSchemaObject {\n\t[key: string]: unknown;\n\ttype?: unknown;\n\tproperties?: Record<string, JsonSchemaObject | undefined>;\n\trequired?: unknown;\n}\n\nclass UnsupportedStrictJsonSchemaError extends Error {}\n\n/** Returns true when a provider's strict mode rejects this schema keyword with this value. */\nexport type UnsupportedStrictSchemaKeywordCheck = (key: string, value: unknown) => boolean;\n\nconst UNSUPPORTED_STRICT_SCHEMA_KEYS = [\n\t\"$ref\",\n\t\"$defs\",\n\t\"definitions\",\n\t\"allOf\",\n\t\"oneOf\",\n\t\"patternProperties\",\n\t\"dependentSchemas\",\n\t\"dependencies\",\n\t\"unevaluatedProperties\",\n\t\"propertyNames\",\n\t\"contains\",\n\t\"prefixItems\",\n\t\"not\",\n\t\"if\",\n\t\"then\",\n\t\"else\",\n] as const;\n\nfunction isJsonSchemaObject(value: unknown): value is JsonSchemaObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isStructuredSchema(schema: unknown): boolean {\n\tif (!isJsonSchemaObject(schema)) return false;\n\tconst types = typeof schema.type === \"string\" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];\n\treturn (\n\t\ttypes.includes(\"object\") ||\n\t\ttypes.includes(\"array\") ||\n\t\tschema.properties !== undefined ||\n\t\tschema.items !== undefined\n\t);\n}\n\nfunction schemaAllowsNull(schema: unknown): boolean {\n\tif (!isJsonSchemaObject(schema)) return false;\n\tif (schema.type === \"null\" || (Array.isArray(schema.type) && schema.type.includes(\"null\"))) return true;\n\tif (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null))) return true;\n\treturn Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));\n}\n\nfunction makeJsonSchemaNodeStrict(schema: unknown, isUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck): void {\n\tif (!isJsonSchemaObject(schema)) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"boolean schemas are unsupported\");\n\t}\n\tfor (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {\n\t\tif (schema[key] !== undefined) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);\n\t\t}\n\t}\n\tif (isUnsupportedKeyword) {\n\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\tif (isUnsupportedKeyword(key, value)) {\n\t\t\t\tthrow new UnsupportedStrictJsonSchemaError(`${key}: ${JSON.stringify(value)} is unsupported`);\n\t\t\t}\n\t\t}\n\t}\n\n\t// OpenAI strict mode rejects nodes without a type; a bare enum counts as typed, a bare const does not.\n\tif (schema.type === undefined && schema.anyOf === undefined && schema.enum === undefined) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"schemas without a type are unsupported\");\n\t}\n\n\tif (schema.anyOf !== undefined) {\n\t\tif (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(\"anyOf must contain at least one schema\");\n\t\t}\n\t\tfor (const variant of schema.anyOf) {\n\t\t\tif (isStructuredSchema(variant)) {\n\t\t\t\tthrow new UnsupportedStrictJsonSchemaError(\"object and array unions are unsupported\");\n\t\t\t}\n\t\t\tmakeJsonSchemaNodeStrict(variant, isUnsupportedKeyword);\n\t\t}\n\t}\n\n\tif (schema.items !== undefined) {\n\t\tif (Array.isArray(schema.items)) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(\"tuple schemas are unsupported\");\n\t\t}\n\t\tmakeJsonSchemaNodeStrict(schema.items, isUnsupportedKeyword);\n\t}\n\n\tconst isObjectSchema = schema.type === \"object\";\n\tif (schema.properties !== undefined && !isObjectSchema) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"properties require type object\");\n\t}\n\tif (!isObjectSchema) return;\n\tif (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"schema-valued or true additionalProperties is unsupported\");\n\t}\n\tif (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"object properties must be a schema map\");\n\t}\n\tif (\n\t\tschema.required !== undefined &&\n\t\t(!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== \"string\"))\n\t) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"object required must be a string array\");\n\t}\n\n\tconst properties = schema.properties ?? {};\n\tconst propertyNames = Object.keys(properties);\n\tconst required = new Set(Array.isArray(schema.required) ? schema.required : []);\n\tif ([...required].some((key) => !propertyNames.includes(key))) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"required contains an unknown property\");\n\t}\n\tfor (const [key, property] of Object.entries(properties)) {\n\t\tmakeJsonSchemaNodeStrict(property, isUnsupportedKeyword);\n\t\tif (!required.has(key) && !schemaAllowsNull(property)) {\n\t\t\tproperties[key] = { anyOf: [property, { type: \"null\" }] };\n\t\t}\n\t}\n\tschema.required = propertyNames;\n\tschema.additionalProperties = false;\n}\n\n/** Convert a tool schema to the strict subset expected by provider constrained sampling. */\nexport function makeStrictJsonSchema(\n\tschema: Tool[\"parameters\"],\n\tisUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck,\n): Record<string, unknown> {\n\tconst cloned: unknown = structuredClone(schema);\n\tif (!isJsonSchemaObject(cloned)) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\tmakeJsonSchemaNodeStrict(cloned, isUnsupportedKeyword);\n\tif (cloned.type !== \"object\") {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\treturn cloned;\n}\n\n/** Returns true for a tool that asks for strict JSON-schema sampling only when possible (`strict: \"prefer\"`). */\nexport function prefersJsonSchemaStrictSampling(tool: Tool): boolean {\n\tconst config = tool.constrainedSampling;\n\treturn !!config && config.type === \"json_schema\" && config.strict === \"prefer\";\n}\n\nexport function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined): Tool[\"parameters\"] {\n\treturn (strict === true ? makeStrictJsonSchema(tool.parameters) : tool.parameters) as Tool[\"parameters\"];\n}\n\nexport interface GrammarConstrainedSampling {\n\tformat: \"lark\" | \"regex\";\n\tdefinition: string;\n\tinputProperty: string;\n}\n\nexport interface GrammarToolInputJsonBuffer {\n\tinput: string;\n\tstarted: boolean;\n\tclosed: boolean;\n}\n\nexport function getGrammarToolInput(\n\ttoolName: string,\n\targuments_: Record<string, unknown>,\n\tinputProperty: string,\n): string {\n\tconst input = arguments_[inputProperty];\n\tif (typeof input !== \"string\") {\n\t\tthrow new Error(`Grammar tool call \"${toolName}\" requires argument \"${inputProperty}\" to be a string.`);\n\t}\n\treturn input;\n}\n\n/**\n * Append `inputDelta` to a streaming grammar tool input and return the matching piece of its JSON arguments text, or\n * `undefined` for an empty delta. Costs time linear in the delta, never in the input so far.\n */\nexport function appendGrammarToolInputJsonDelta(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tinputDelta: string,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (inputDelta.length === 0) return undefined;\n\tbuffer.input += inputDelta;\n\treturn grammarToolInputJsonStart(buffer, inputProperty) + JSON.stringify(inputDelta).slice(1, -1);\n}\n\n/**\n * Close a streaming grammar tool input and return the rest of its JSON arguments text. `finalInput` is the complete\n * input when the provider sends one; it must continue the input streamed so far. Closing again with the same input\n * returns `undefined`.\n */\nexport function closeGrammarToolInputJson(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tfinalInput: string | undefined,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tif (finalInput === undefined || finalInput === buffer.input) return undefined;\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (finalInput !== undefined && !finalInput.startsWith(buffer.input)) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n\t}\n\tconst rest = finalInput === undefined ? \"\" : finalInput.slice(buffer.input.length);\n\tif (finalInput !== undefined) buffer.input = finalInput;\n\tbuffer.closed = true;\n\treturn `${grammarToolInputJsonStart(buffer, inputProperty)}${JSON.stringify(rest).slice(1, -1)}\"}`;\n}\n\n/** The opening of the JSON arguments text, once. */\nfunction grammarToolInputJsonStart(buffer: GrammarToolInputJsonBuffer, inputProperty: string): string {\n\tif (buffer.started) return \"\";\n\tbuffer.started = true;\n\treturn `{${JSON.stringify(inputProperty)}:\"`;\n}\n\nfunction inferGrammarInputProperty(tool: Tool): string {\n\tconst schema = tool.parameters as JsonSchemaObject;\n\tif (schema.type !== \"object\") {\n\t\tthrow new Error(\"grammar constrained sampling requires an object parameter schema\");\n\t}\n\tif (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== \"string\") {\n\t\tthrow new Error(\"grammar constrained sampling requires exactly one required string property\");\n\t}\n\n\tconst inputProperty = schema.required[0];\n\tif (!schema.properties?.[inputProperty]) {\n\t\tthrow new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);\n\t}\n\tif (schema.properties[inputProperty]?.type !== \"string\") {\n\t\tthrow new Error(`grammar constrained sampling property ${inputProperty} must have type string`);\n\t}\n\treturn inputProperty;\n}\n\n/**\n * Decide whether a JSON-schema tool is sent in strict mode. `isUnsupportedKeyword` lets a provider\n * reject extra keywords its strict mode does not accept, so \"prefer\" tools fall back to non-strict.\n */\nexport function resolveJsonSchemaStrictSampling(\n\ttool: Tool,\n\tsupportsStrictMode: boolean,\n\tisUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck,\n): boolean | undefined {\n\tconst config = tool.constrainedSampling;\n\tif (!config || config.type !== \"json_schema\") return undefined;\n\n\tif (supportsStrictMode) {\n\t\ttry {\n\t\t\tmakeStrictJsonSchema(tool.parameters, isUnsupportedKeyword);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof UnsupportedStrictJsonSchemaError)) throw error;\n\t\t\tif (config.strict !== \"require\") return undefined;\n\t\t\tthrow new Error(`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but ${error.message}.`);\n\t\t}\n\t}\n\tif (config.strict === \"require\") {\n\t\tthrow new Error(\n\t\t\t`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but strict tools are unsupported.`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\nexport function resolveGrammarConstrainedSampling(\n\ttool: Tool,\n\tsupportsOpenAIGrammarTools: boolean,\n): GrammarConstrainedSampling | undefined {\n\tconst config = tool.constrainedSampling;\n\tif (!config || config.type !== \"grammar\") {\n\t\treturn undefined;\n\t}\n\n\tif (!supportsOpenAIGrammarTools) {\n\t\treturn undefined;\n\t}\n\n\tconst larkDefinition = config.variants.openai_lark;\n\tconst regexDefinition = config.variants.openai_regex;\n\tconst hasLarkDefinition = typeof larkDefinition === \"string\" && larkDefinition.trim().length > 0;\n\tconst hasRegexDefinition = typeof regexDefinition === \"string\" && regexDefinition.trim().length > 0;\n\tif (!hasLarkDefinition && !hasRegexDefinition) {\n\t\tthrow new Error(\n\t\t\t`Tool \"${tool.name}\" cannot use grammar constrained sampling: no supported grammar variant was provided.`,\n\t\t);\n\t}\n\n\ttry {\n\t\treturn {\n\t\t\tformat: hasLarkDefinition ? \"lark\" : \"regex\",\n\t\t\tdefinition: hasLarkDefinition ? larkDefinition : regexDefinition!,\n\t\t\tinputProperty: inferGrammarInputProperty(tool),\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.`);\n\t}\n}\n\nexport function createGrammarToolInputProperties(\n\ttools: Tool[] | undefined,\n\tsupportsOpenAIGrammarTools: boolean,\n): ReadonlyMap<string, string> {\n\tconst properties = new Map<string, string>();\n\tfor (const tool of tools ?? []) {\n\t\tconst grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n\t\tif (grammar) {\n\t\t\tproperties.set(tool.name, grammar.inputProperty);\n\t\t}\n\t}\n\treturn properties;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Message } from "../types.ts";
2
+ export declare function inferCopilotInitiator(messages: Message[]): "user" | "agent";
3
+ export declare function hasCopilotVisionInput(messages: Message[]): boolean;
4
+ export declare function buildCopilotDynamicHeaders(params: {
5
+ messages: Message[];
6
+ hasImages: boolean;
7
+ }): Record<string, string>;
8
+ //# sourceMappingURL=github-copilot-headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-copilot-headers.d.ts","sourceRoot":"","sources":["../../src/api/github-copilot-headers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3C,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,OAAO,CAG3E;AAGD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAUlE;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IAClD,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACnB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWzB"}
@@ -0,0 +1,29 @@
1
+ // Copilot expects X-Initiator to indicate whether the request is user-initiated
2
+ // or agent-initiated (e.g. follow-up after assistant/tool messages).
3
+ export function inferCopilotInitiator(messages) {
4
+ const last = messages[messages.length - 1];
5
+ return last && last.role !== "user" ? "agent" : "user";
6
+ }
7
+ // Copilot requires Copilot-Vision-Request header when sending images
8
+ export function hasCopilotVisionInput(messages) {
9
+ return messages.some((msg) => {
10
+ if (msg.role === "user" && Array.isArray(msg.content)) {
11
+ return msg.content.some((c) => c.type === "image");
12
+ }
13
+ if (msg.role === "toolResult" && Array.isArray(msg.content)) {
14
+ return msg.content.some((c) => c.type === "image");
15
+ }
16
+ return false;
17
+ });
18
+ }
19
+ export function buildCopilotDynamicHeaders(params) {
20
+ const headers = {
21
+ "X-Initiator": inferCopilotInitiator(params.messages),
22
+ "Openai-Intent": "conversation-edits",
23
+ };
24
+ if (params.hasImages) {
25
+ headers["Copilot-Vision-Request"] = "true";
26
+ }
27
+ return headers;
28
+ }
29
+ //# sourceMappingURL=github-copilot-headers.js.map