@bastani/pi-ai 0.9.14

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 (745) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +22 -0
  3. package/NOTICE.md +16 -0
  4. package/README.md +1672 -0
  5. package/dist/api/anthropic-messages.d.ts +71 -0
  6. package/dist/api/anthropic-messages.d.ts.map +1 -0
  7. package/dist/api/anthropic-messages.js +1060 -0
  8. package/dist/api/anthropic-messages.js.map +1 -0
  9. package/dist/api/anthropic-messages.lazy.d.ts +3 -0
  10. package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
  11. package/dist/api/anthropic-messages.lazy.js +3 -0
  12. package/dist/api/anthropic-messages.lazy.js.map +1 -0
  13. package/dist/api/azure-openai-responses.d.ts +15 -0
  14. package/dist/api/azure-openai-responses.d.ts.map +1 -0
  15. package/dist/api/azure-openai-responses.js +242 -0
  16. package/dist/api/azure-openai-responses.js.map +1 -0
  17. package/dist/api/azure-openai-responses.lazy.d.ts +3 -0
  18. package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -0
  19. package/dist/api/azure-openai-responses.lazy.js +3 -0
  20. package/dist/api/azure-openai-responses.lazy.js.map +1 -0
  21. package/dist/api/bedrock-converse-stream.d.ts +38 -0
  22. package/dist/api/bedrock-converse-stream.d.ts.map +1 -0
  23. package/dist/api/bedrock-converse-stream.js +967 -0
  24. package/dist/api/bedrock-converse-stream.js.map +1 -0
  25. package/dist/api/bedrock-converse-stream.lazy.d.ts +9 -0
  26. package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
  27. package/dist/api/bedrock-converse-stream.lazy.js +30 -0
  28. package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
  29. package/dist/api/cloudflare-gateway-binding.d.ts +69 -0
  30. package/dist/api/cloudflare-gateway-binding.d.ts.map +1 -0
  31. package/dist/api/cloudflare-gateway-binding.js +159 -0
  32. package/dist/api/cloudflare-gateway-binding.js.map +1 -0
  33. package/dist/api/cloudflare.d.ts +9 -0
  34. package/dist/api/cloudflare.d.ts.map +1 -0
  35. package/dist/api/cloudflare.js +9 -0
  36. package/dist/api/cloudflare.js.map +1 -0
  37. package/dist/api/constrained-sampling.d.ts +20 -0
  38. package/dist/api/constrained-sampling.d.ts.map +1 -0
  39. package/dist/api/constrained-sampling.js +222 -0
  40. package/dist/api/constrained-sampling.js.map +1 -0
  41. package/dist/api/github-copilot-headers.d.ts +8 -0
  42. package/dist/api/github-copilot-headers.d.ts.map +1 -0
  43. package/dist/api/github-copilot-headers.js +29 -0
  44. package/dist/api/github-copilot-headers.js.map +1 -0
  45. package/dist/api/google-generative-ai.d.ts +13 -0
  46. package/dist/api/google-generative-ai.d.ts.map +1 -0
  47. package/dist/api/google-generative-ai.js +417 -0
  48. package/dist/api/google-generative-ai.js.map +1 -0
  49. package/dist/api/google-generative-ai.lazy.d.ts +3 -0
  50. package/dist/api/google-generative-ai.lazy.d.ts.map +1 -0
  51. package/dist/api/google-generative-ai.lazy.js +3 -0
  52. package/dist/api/google-generative-ai.lazy.js.map +1 -0
  53. package/dist/api/google-shared.d.ts +81 -0
  54. package/dist/api/google-shared.d.ts.map +1 -0
  55. package/dist/api/google-shared.js +384 -0
  56. package/dist/api/google-shared.js.map +1 -0
  57. package/dist/api/google-vertex.d.ts +15 -0
  58. package/dist/api/google-vertex.d.ts.map +1 -0
  59. package/dist/api/google-vertex.js +466 -0
  60. package/dist/api/google-vertex.js.map +1 -0
  61. package/dist/api/google-vertex.lazy.d.ts +3 -0
  62. package/dist/api/google-vertex.lazy.d.ts.map +1 -0
  63. package/dist/api/google-vertex.lazy.js +3 -0
  64. package/dist/api/google-vertex.lazy.js.map +1 -0
  65. package/dist/api/lazy.d.ts +19 -0
  66. package/dist/api/lazy.d.ts.map +1 -0
  67. package/dist/api/lazy.js +70 -0
  68. package/dist/api/lazy.js.map +1 -0
  69. package/dist/api/mistral-conversations.d.ts +25 -0
  70. package/dist/api/mistral-conversations.d.ts.map +1 -0
  71. package/dist/api/mistral-conversations.js +736 -0
  72. package/dist/api/mistral-conversations.js.map +1 -0
  73. package/dist/api/mistral-conversations.lazy.d.ts +3 -0
  74. package/dist/api/mistral-conversations.lazy.d.ts.map +1 -0
  75. package/dist/api/mistral-conversations.lazy.js +3 -0
  76. package/dist/api/mistral-conversations.lazy.js.map +1 -0
  77. package/dist/api/openai-codex-responses.d.ts +31 -0
  78. package/dist/api/openai-codex-responses.d.ts.map +1 -0
  79. package/dist/api/openai-codex-responses.js +1294 -0
  80. package/dist/api/openai-codex-responses.js.map +1 -0
  81. package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
  82. package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
  83. package/dist/api/openai-codex-responses.lazy.js +3 -0
  84. package/dist/api/openai-codex-responses.lazy.js.map +1 -0
  85. package/dist/api/openai-completions.d.ts +22 -0
  86. package/dist/api/openai-completions.d.ts.map +1 -0
  87. package/dist/api/openai-completions.js +1279 -0
  88. package/dist/api/openai-completions.js.map +1 -0
  89. package/dist/api/openai-completions.lazy.d.ts +3 -0
  90. package/dist/api/openai-completions.lazy.d.ts.map +1 -0
  91. package/dist/api/openai-completions.lazy.js +3 -0
  92. package/dist/api/openai-completions.lazy.js.map +1 -0
  93. package/dist/api/openai-prompt-cache.d.ts +3 -0
  94. package/dist/api/openai-prompt-cache.d.ts.map +1 -0
  95. package/dist/api/openai-prompt-cache.js +10 -0
  96. package/dist/api/openai-prompt-cache.js.map +1 -0
  97. package/dist/api/openai-responses-shared.d.ts +26 -0
  98. package/dist/api/openai-responses-shared.d.ts.map +1 -0
  99. package/dist/api/openai-responses-shared.js +686 -0
  100. package/dist/api/openai-responses-shared.js.map +1 -0
  101. package/dist/api/openai-responses.d.ts +14 -0
  102. package/dist/api/openai-responses.d.ts.map +1 -0
  103. package/dist/api/openai-responses.js +283 -0
  104. package/dist/api/openai-responses.js.map +1 -0
  105. package/dist/api/openai-responses.lazy.d.ts +3 -0
  106. package/dist/api/openai-responses.lazy.d.ts.map +1 -0
  107. package/dist/api/openai-responses.lazy.js +3 -0
  108. package/dist/api/openai-responses.lazy.js.map +1 -0
  109. package/dist/api/openrouter-images.d.ts +3 -0
  110. package/dist/api/openrouter-images.d.ts.map +1 -0
  111. package/dist/api/openrouter-images.js +132 -0
  112. package/dist/api/openrouter-images.js.map +1 -0
  113. package/dist/api/openrouter-images.lazy.d.ts +3 -0
  114. package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
  115. package/dist/api/openrouter-images.lazy.js +4 -0
  116. package/dist/api/openrouter-images.lazy.js.map +1 -0
  117. package/dist/api/pi-messages.d.ts +97 -0
  118. package/dist/api/pi-messages.d.ts.map +1 -0
  119. package/dist/api/pi-messages.js +307 -0
  120. package/dist/api/pi-messages.js.map +1 -0
  121. package/dist/api/pi-messages.lazy.d.ts +3 -0
  122. package/dist/api/pi-messages.lazy.d.ts.map +1 -0
  123. package/dist/api/pi-messages.lazy.js +3 -0
  124. package/dist/api/pi-messages.lazy.js.map +1 -0
  125. package/dist/api/simple-options.d.ts +11 -0
  126. package/dist/api/simple-options.d.ts.map +1 -0
  127. package/dist/api/simple-options.js +59 -0
  128. package/dist/api/simple-options.js.map +1 -0
  129. package/dist/api/transform-messages.d.ts +8 -0
  130. package/dist/api/transform-messages.d.ts.map +1 -0
  131. package/dist/api/transform-messages.js +187 -0
  132. package/dist/api/transform-messages.js.map +1 -0
  133. package/dist/auth/context.d.ts +7 -0
  134. package/dist/auth/context.d.ts.map +1 -0
  135. package/dist/auth/context.js +42 -0
  136. package/dist/auth/context.js.map +1 -0
  137. package/dist/auth/credential-store.d.ts +17 -0
  138. package/dist/auth/credential-store.d.ts.map +1 -0
  139. package/dist/auth/credential-store.js +51 -0
  140. package/dist/auth/credential-store.js.map +1 -0
  141. package/dist/auth/helpers.d.ts +22 -0
  142. package/dist/auth/helpers.d.ts.map +1 -0
  143. package/dist/auth/helpers.js +53 -0
  144. package/dist/auth/helpers.js.map +1 -0
  145. package/dist/auth/oauth/anthropic.d.ts +9 -0
  146. package/dist/auth/oauth/anthropic.d.ts.map +1 -0
  147. package/dist/auth/oauth/anthropic.js +308 -0
  148. package/dist/auth/oauth/anthropic.js.map +1 -0
  149. package/dist/auth/oauth/device-code.d.ts +23 -0
  150. package/dist/auth/oauth/device-code.d.ts.map +1 -0
  151. package/dist/auth/oauth/device-code.js +69 -0
  152. package/dist/auth/oauth/device-code.js.map +1 -0
  153. package/dist/auth/oauth/github-copilot.d.ts +6 -0
  154. package/dist/auth/oauth/github-copilot.d.ts.map +1 -0
  155. package/dist/auth/oauth/github-copilot.js +328 -0
  156. package/dist/auth/oauth/github-copilot.js.map +1 -0
  157. package/dist/auth/oauth/kimi-coding.d.ts +10 -0
  158. package/dist/auth/oauth/kimi-coding.d.ts.map +1 -0
  159. package/dist/auth/oauth/kimi-coding.js +261 -0
  160. package/dist/auth/oauth/kimi-coding.js.map +1 -0
  161. package/dist/auth/oauth/load.d.ts +27 -0
  162. package/dist/auth/oauth/load.d.ts.map +1 -0
  163. package/dist/auth/oauth/load.js +59 -0
  164. package/dist/auth/oauth/load.js.map +1 -0
  165. package/dist/auth/oauth/oauth-page.d.ts +3 -0
  166. package/dist/auth/oauth/oauth-page.d.ts.map +1 -0
  167. package/dist/auth/oauth/oauth-page.js +105 -0
  168. package/dist/auth/oauth/oauth-page.js.map +1 -0
  169. package/dist/auth/oauth/openai-codex.d.ts +9 -0
  170. package/dist/auth/oauth/openai-codex.d.ts.map +1 -0
  171. package/dist/auth/oauth/openai-codex.js +450 -0
  172. package/dist/auth/oauth/openai-codex.js.map +1 -0
  173. package/dist/auth/oauth/openrouter.d.ts +15 -0
  174. package/dist/auth/oauth/openrouter.d.ts.map +1 -0
  175. package/dist/auth/oauth/openrouter.js +277 -0
  176. package/dist/auth/oauth/openrouter.js.map +1 -0
  177. package/dist/auth/oauth/pkce.d.ts +13 -0
  178. package/dist/auth/oauth/pkce.d.ts.map +1 -0
  179. package/dist/auth/oauth/pkce.js +31 -0
  180. package/dist/auth/oauth/pkce.js.map +1 -0
  181. package/dist/auth/oauth/radius.d.ts +17 -0
  182. package/dist/auth/oauth/radius.d.ts.map +1 -0
  183. package/dist/auth/oauth/radius.js +321 -0
  184. package/dist/auth/oauth/radius.js.map +1 -0
  185. package/dist/auth/oauth/xai.d.ts +6 -0
  186. package/dist/auth/oauth/xai.d.ts.map +1 -0
  187. package/dist/auth/oauth/xai.js +190 -0
  188. package/dist/auth/oauth/xai.js.map +1 -0
  189. package/dist/auth/resolve.d.ts +27 -0
  190. package/dist/auth/resolve.d.ts.map +1 -0
  191. package/dist/auth/resolve.js +132 -0
  192. package/dist/auth/resolve.js.map +1 -0
  193. package/dist/auth/types.d.ts +231 -0
  194. package/dist/auth/types.d.ts.map +1 -0
  195. package/dist/auth/types.js +2 -0
  196. package/dist/auth/types.js.map +1 -0
  197. package/dist/bedrock-provider.d.ts +5 -0
  198. package/dist/bedrock-provider.d.ts.map +1 -0
  199. package/dist/bedrock-provider.js +6 -0
  200. package/dist/bedrock-provider.js.map +1 -0
  201. package/dist/bun-oauth.d.ts +3 -0
  202. package/dist/bun-oauth.d.ts.map +1 -0
  203. package/dist/bun-oauth.js +21 -0
  204. package/dist/bun-oauth.js.map +1 -0
  205. package/dist/cli.d.ts +3 -0
  206. package/dist/cli.d.ts.map +1 -0
  207. package/dist/cli.js +113 -0
  208. package/dist/cli.js.map +1 -0
  209. package/dist/compat/extension-oauth-types.d.ts +39 -0
  210. package/dist/compat/extension-oauth-types.d.ts.map +1 -0
  211. package/dist/compat/extension-oauth-types.js +2 -0
  212. package/dist/compat/extension-oauth-types.js.map +1 -0
  213. package/dist/compat.d.ts +67 -0
  214. package/dist/compat.d.ts.map +1 -0
  215. package/dist/compat.js +199 -0
  216. package/dist/compat.js.map +1 -0
  217. package/dist/env-api-keys.d.ts +21 -0
  218. package/dist/env-api-keys.d.ts.map +1 -0
  219. package/dist/env-api-keys.js +156 -0
  220. package/dist/env-api-keys.js.map +1 -0
  221. package/dist/image-models.d.ts +10 -0
  222. package/dist/image-models.d.ts.map +1 -0
  223. package/dist/image-models.generated.d.ts +680 -0
  224. package/dist/image-models.generated.d.ts.map +1 -0
  225. package/dist/image-models.generated.js +682 -0
  226. package/dist/image-models.generated.js.map +1 -0
  227. package/dist/image-models.js +23 -0
  228. package/dist/image-models.js.map +1 -0
  229. package/dist/images-api-registry.d.ts +14 -0
  230. package/dist/images-api-registry.d.ts.map +1 -0
  231. package/dist/images-api-registry.js +22 -0
  232. package/dist/images-api-registry.js.map +1 -0
  233. package/dist/images-models.d.ts +95 -0
  234. package/dist/images-models.d.ts.map +1 -0
  235. package/dist/images-models.js +143 -0
  236. package/dist/images-models.js.map +1 -0
  237. package/dist/images.d.ts +4 -0
  238. package/dist/images.d.ts.map +1 -0
  239. package/dist/images.js +14 -0
  240. package/dist/images.js.map +1 -0
  241. package/dist/index.d.ts +35 -0
  242. package/dist/index.d.ts.map +1 -0
  243. package/dist/index.js +22 -0
  244. package/dist/index.js.map +1 -0
  245. package/dist/legacy-api-aliases.d.ts +42 -0
  246. package/dist/legacy-api-aliases.d.ts.map +1 -0
  247. package/dist/legacy-api-aliases.js +49 -0
  248. package/dist/legacy-api-aliases.js.map +1 -0
  249. package/dist/model-catalog.d.ts +17 -0
  250. package/dist/model-catalog.d.ts.map +1 -0
  251. package/dist/model-catalog.js +4 -0
  252. package/dist/model-catalog.js.map +1 -0
  253. package/dist/models-store.d.ts +29 -0
  254. package/dist/models-store.d.ts.map +1 -0
  255. package/dist/models-store.js +17 -0
  256. package/dist/models-store.js.map +1 -0
  257. package/dist/models.d.ts +200 -0
  258. package/dist/models.d.ts.map +1 -0
  259. package/dist/models.generated.d.ts +81 -0
  260. package/dist/models.generated.d.ts.map +1 -0
  261. package/dist/models.generated.js +83 -0
  262. package/dist/models.generated.js.map +1 -0
  263. package/dist/models.js +588 -0
  264. package/dist/models.js.map +1 -0
  265. package/dist/oauth.d.ts +3 -0
  266. package/dist/oauth.d.ts.map +1 -0
  267. package/dist/oauth.js +2 -0
  268. package/dist/oauth.js.map +1 -0
  269. package/dist/providers/all.d.ts +28 -0
  270. package/dist/providers/all.d.ts.map +1 -0
  271. package/dist/providers/all.js +131 -0
  272. package/dist/providers/all.js.map +1 -0
  273. package/dist/providers/amazon-bedrock.d.ts +3 -0
  274. package/dist/providers/amazon-bedrock.d.ts.map +1 -0
  275. package/dist/providers/amazon-bedrock.js +93 -0
  276. package/dist/providers/amazon-bedrock.js.map +1 -0
  277. package/dist/providers/amazon-bedrock.models.d.ts +4 -0
  278. package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
  279. package/dist/providers/amazon-bedrock.models.js +6 -0
  280. package/dist/providers/amazon-bedrock.models.js.map +1 -0
  281. package/dist/providers/ant-ling.d.ts +3 -0
  282. package/dist/providers/ant-ling.d.ts.map +1 -0
  283. package/dist/providers/ant-ling.js +15 -0
  284. package/dist/providers/ant-ling.js.map +1 -0
  285. package/dist/providers/ant-ling.models.d.ts +4 -0
  286. package/dist/providers/ant-ling.models.d.ts.map +1 -0
  287. package/dist/providers/ant-ling.models.js +6 -0
  288. package/dist/providers/ant-ling.models.js.map +1 -0
  289. package/dist/providers/anthropic.d.ts +3 -0
  290. package/dist/providers/anthropic.d.ts.map +1 -0
  291. package/dist/providers/anthropic.js +56 -0
  292. package/dist/providers/anthropic.js.map +1 -0
  293. package/dist/providers/anthropic.models.d.ts +4 -0
  294. package/dist/providers/anthropic.models.d.ts.map +1 -0
  295. package/dist/providers/anthropic.models.js +6 -0
  296. package/dist/providers/anthropic.models.js.map +1 -0
  297. package/dist/providers/azure-openai-responses.d.ts +3 -0
  298. package/dist/providers/azure-openai-responses.d.ts.map +1 -0
  299. package/dist/providers/azure-openai-responses.js +14 -0
  300. package/dist/providers/azure-openai-responses.js.map +1 -0
  301. package/dist/providers/azure-openai-responses.models.d.ts +4 -0
  302. package/dist/providers/azure-openai-responses.models.d.ts.map +1 -0
  303. package/dist/providers/azure-openai-responses.models.js +6 -0
  304. package/dist/providers/azure-openai-responses.models.js.map +1 -0
  305. package/dist/providers/baseten.d.ts +3 -0
  306. package/dist/providers/baseten.d.ts.map +1 -0
  307. package/dist/providers/baseten.js +15 -0
  308. package/dist/providers/baseten.js.map +1 -0
  309. package/dist/providers/baseten.models.d.ts +4 -0
  310. package/dist/providers/baseten.models.d.ts.map +1 -0
  311. package/dist/providers/baseten.models.js +6 -0
  312. package/dist/providers/baseten.models.js.map +1 -0
  313. package/dist/providers/cerebras.d.ts +3 -0
  314. package/dist/providers/cerebras.d.ts.map +1 -0
  315. package/dist/providers/cerebras.js +15 -0
  316. package/dist/providers/cerebras.js.map +1 -0
  317. package/dist/providers/cerebras.models.d.ts +4 -0
  318. package/dist/providers/cerebras.models.d.ts.map +1 -0
  319. package/dist/providers/cerebras.models.js +6 -0
  320. package/dist/providers/cerebras.models.js.map +1 -0
  321. package/dist/providers/cloudflare-ai-gateway.d.ts +3 -0
  322. package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
  323. package/dist/providers/cloudflare-ai-gateway.js +21 -0
  324. package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
  325. package/dist/providers/cloudflare-ai-gateway.models.d.ts +4 -0
  326. package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
  327. package/dist/providers/cloudflare-ai-gateway.models.js +6 -0
  328. package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
  329. package/dist/providers/cloudflare-auth.d.ts +4 -0
  330. package/dist/providers/cloudflare-auth.d.ts.map +1 -0
  331. package/dist/providers/cloudflare-auth.js +86 -0
  332. package/dist/providers/cloudflare-auth.js.map +1 -0
  333. package/dist/providers/cloudflare-stream.d.ts +8 -0
  334. package/dist/providers/cloudflare-stream.d.ts.map +1 -0
  335. package/dist/providers/cloudflare-stream.js +21 -0
  336. package/dist/providers/cloudflare-stream.js.map +1 -0
  337. package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
  338. package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
  339. package/dist/providers/cloudflare-workers-ai.js +15 -0
  340. package/dist/providers/cloudflare-workers-ai.js.map +1 -0
  341. package/dist/providers/cloudflare-workers-ai.models.d.ts +4 -0
  342. package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
  343. package/dist/providers/cloudflare-workers-ai.models.js +6 -0
  344. package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
  345. package/dist/providers/data/.manifest.json +1 -0
  346. package/dist/providers/data/amazon-bedrock.json +1 -0
  347. package/dist/providers/data/ant-ling.json +1 -0
  348. package/dist/providers/data/anthropic.json +1 -0
  349. package/dist/providers/data/azure-openai-responses.json +1 -0
  350. package/dist/providers/data/baseten.json +1 -0
  351. package/dist/providers/data/cerebras.json +1 -0
  352. package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
  353. package/dist/providers/data/cloudflare-workers-ai.json +1 -0
  354. package/dist/providers/data/deepseek.json +1 -0
  355. package/dist/providers/data/fireworks.json +1 -0
  356. package/dist/providers/data/github-copilot.json +1 -0
  357. package/dist/providers/data/google-vertex.json +1 -0
  358. package/dist/providers/data/google.json +1 -0
  359. package/dist/providers/data/groq.json +1 -0
  360. package/dist/providers/data/huggingface.json +1 -0
  361. package/dist/providers/data/kimi-coding.json +1 -0
  362. package/dist/providers/data/minimax-cn.json +1 -0
  363. package/dist/providers/data/minimax.json +1 -0
  364. package/dist/providers/data/mistral.json +1 -0
  365. package/dist/providers/data/moonshotai-cn.json +1 -0
  366. package/dist/providers/data/moonshotai.json +1 -0
  367. package/dist/providers/data/nvidia.json +1 -0
  368. package/dist/providers/data/openai-codex.json +1 -0
  369. package/dist/providers/data/openai.json +1 -0
  370. package/dist/providers/data/opencode-go.json +1 -0
  371. package/dist/providers/data/opencode.json +1 -0
  372. package/dist/providers/data/openrouter.json +1 -0
  373. package/dist/providers/data/qwen-token-plan-cn.json +1 -0
  374. package/dist/providers/data/qwen-token-plan-individual.json +1 -0
  375. package/dist/providers/data/qwen-token-plan.json +1 -0
  376. package/dist/providers/data/together.json +1 -0
  377. package/dist/providers/data/vercel-ai-gateway.json +1 -0
  378. package/dist/providers/data/xai.json +1 -0
  379. package/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
  380. package/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
  381. package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
  382. package/dist/providers/data/xiaomi.json +1 -0
  383. package/dist/providers/data/zai-coding-cn.json +1 -0
  384. package/dist/providers/data/zai.json +1 -0
  385. package/dist/providers/deepseek.d.ts +3 -0
  386. package/dist/providers/deepseek.d.ts.map +1 -0
  387. package/dist/providers/deepseek.js +15 -0
  388. package/dist/providers/deepseek.js.map +1 -0
  389. package/dist/providers/deepseek.models.d.ts +4 -0
  390. package/dist/providers/deepseek.models.d.ts.map +1 -0
  391. package/dist/providers/deepseek.models.js +6 -0
  392. package/dist/providers/deepseek.models.js.map +1 -0
  393. package/dist/providers/faux.d.ts +102 -0
  394. package/dist/providers/faux.d.ts.map +1 -0
  395. package/dist/providers/faux.js +488 -0
  396. package/dist/providers/faux.js.map +1 -0
  397. package/dist/providers/fireworks.d.ts +3 -0
  398. package/dist/providers/fireworks.d.ts.map +1 -0
  399. package/dist/providers/fireworks.js +19 -0
  400. package/dist/providers/fireworks.js.map +1 -0
  401. package/dist/providers/fireworks.models.d.ts +4 -0
  402. package/dist/providers/fireworks.models.d.ts.map +1 -0
  403. package/dist/providers/fireworks.models.js +6 -0
  404. package/dist/providers/fireworks.models.js.map +1 -0
  405. package/dist/providers/github-copilot.d.ts +3 -0
  406. package/dist/providers/github-copilot.d.ts.map +1 -0
  407. package/dist/providers/github-copilot.js +35 -0
  408. package/dist/providers/github-copilot.js.map +1 -0
  409. package/dist/providers/github-copilot.models.d.ts +4 -0
  410. package/dist/providers/github-copilot.models.d.ts.map +1 -0
  411. package/dist/providers/github-copilot.models.js +6 -0
  412. package/dist/providers/github-copilot.models.js.map +1 -0
  413. package/dist/providers/google-vertex.d.ts +3 -0
  414. package/dist/providers/google-vertex.d.ts.map +1 -0
  415. package/dist/providers/google-vertex.js +94 -0
  416. package/dist/providers/google-vertex.js.map +1 -0
  417. package/dist/providers/google-vertex.models.d.ts +4 -0
  418. package/dist/providers/google-vertex.models.d.ts.map +1 -0
  419. package/dist/providers/google-vertex.models.js +6 -0
  420. package/dist/providers/google-vertex.models.js.map +1 -0
  421. package/dist/providers/google.d.ts +3 -0
  422. package/dist/providers/google.d.ts.map +1 -0
  423. package/dist/providers/google.js +15 -0
  424. package/dist/providers/google.js.map +1 -0
  425. package/dist/providers/google.models.d.ts +4 -0
  426. package/dist/providers/google.models.d.ts.map +1 -0
  427. package/dist/providers/google.models.js +6 -0
  428. package/dist/providers/google.models.js.map +1 -0
  429. package/dist/providers/groq.d.ts +3 -0
  430. package/dist/providers/groq.d.ts.map +1 -0
  431. package/dist/providers/groq.js +15 -0
  432. package/dist/providers/groq.js.map +1 -0
  433. package/dist/providers/groq.models.d.ts +4 -0
  434. package/dist/providers/groq.models.d.ts.map +1 -0
  435. package/dist/providers/groq.models.js +6 -0
  436. package/dist/providers/groq.models.js.map +1 -0
  437. package/dist/providers/huggingface.d.ts +3 -0
  438. package/dist/providers/huggingface.d.ts.map +1 -0
  439. package/dist/providers/huggingface.js +15 -0
  440. package/dist/providers/huggingface.js.map +1 -0
  441. package/dist/providers/huggingface.models.d.ts +4 -0
  442. package/dist/providers/huggingface.models.d.ts.map +1 -0
  443. package/dist/providers/huggingface.models.js +6 -0
  444. package/dist/providers/huggingface.models.js.map +1 -0
  445. package/dist/providers/images/register-builtins.d.ts +4 -0
  446. package/dist/providers/images/register-builtins.d.ts.map +1 -0
  447. package/dist/providers/images/register-builtins.js +34 -0
  448. package/dist/providers/images/register-builtins.js.map +1 -0
  449. package/dist/providers/kimi-coding.d.ts +3 -0
  450. package/dist/providers/kimi-coding.d.ts.map +1 -0
  451. package/dist/providers/kimi-coding.js +24 -0
  452. package/dist/providers/kimi-coding.js.map +1 -0
  453. package/dist/providers/kimi-coding.models.d.ts +4 -0
  454. package/dist/providers/kimi-coding.models.d.ts.map +1 -0
  455. package/dist/providers/kimi-coding.models.js +6 -0
  456. package/dist/providers/kimi-coding.models.js.map +1 -0
  457. package/dist/providers/minimax-cn.d.ts +3 -0
  458. package/dist/providers/minimax-cn.d.ts.map +1 -0
  459. package/dist/providers/minimax-cn.js +15 -0
  460. package/dist/providers/minimax-cn.js.map +1 -0
  461. package/dist/providers/minimax-cn.models.d.ts +4 -0
  462. package/dist/providers/minimax-cn.models.d.ts.map +1 -0
  463. package/dist/providers/minimax-cn.models.js +6 -0
  464. package/dist/providers/minimax-cn.models.js.map +1 -0
  465. package/dist/providers/minimax.d.ts +3 -0
  466. package/dist/providers/minimax.d.ts.map +1 -0
  467. package/dist/providers/minimax.js +15 -0
  468. package/dist/providers/minimax.js.map +1 -0
  469. package/dist/providers/minimax.models.d.ts +4 -0
  470. package/dist/providers/minimax.models.d.ts.map +1 -0
  471. package/dist/providers/minimax.models.js +6 -0
  472. package/dist/providers/minimax.models.js.map +1 -0
  473. package/dist/providers/mistral.d.ts +3 -0
  474. package/dist/providers/mistral.d.ts.map +1 -0
  475. package/dist/providers/mistral.js +15 -0
  476. package/dist/providers/mistral.js.map +1 -0
  477. package/dist/providers/mistral.models.d.ts +4 -0
  478. package/dist/providers/mistral.models.d.ts.map +1 -0
  479. package/dist/providers/mistral.models.js +6 -0
  480. package/dist/providers/mistral.models.js.map +1 -0
  481. package/dist/providers/moonshotai-cn.d.ts +3 -0
  482. package/dist/providers/moonshotai-cn.d.ts.map +1 -0
  483. package/dist/providers/moonshotai-cn.js +15 -0
  484. package/dist/providers/moonshotai-cn.js.map +1 -0
  485. package/dist/providers/moonshotai-cn.models.d.ts +4 -0
  486. package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
  487. package/dist/providers/moonshotai-cn.models.js +6 -0
  488. package/dist/providers/moonshotai-cn.models.js.map +1 -0
  489. package/dist/providers/moonshotai.d.ts +3 -0
  490. package/dist/providers/moonshotai.d.ts.map +1 -0
  491. package/dist/providers/moonshotai.js +15 -0
  492. package/dist/providers/moonshotai.js.map +1 -0
  493. package/dist/providers/moonshotai.models.d.ts +4 -0
  494. package/dist/providers/moonshotai.models.d.ts.map +1 -0
  495. package/dist/providers/moonshotai.models.js +6 -0
  496. package/dist/providers/moonshotai.models.js.map +1 -0
  497. package/dist/providers/nvidia.d.ts +3 -0
  498. package/dist/providers/nvidia.d.ts.map +1 -0
  499. package/dist/providers/nvidia.js +15 -0
  500. package/dist/providers/nvidia.js.map +1 -0
  501. package/dist/providers/nvidia.models.d.ts +4 -0
  502. package/dist/providers/nvidia.models.d.ts.map +1 -0
  503. package/dist/providers/nvidia.models.js +6 -0
  504. package/dist/providers/nvidia.models.js.map +1 -0
  505. package/dist/providers/openai-codex.d.ts +3 -0
  506. package/dist/providers/openai-codex.d.ts.map +1 -0
  507. package/dist/providers/openai-codex.js +22 -0
  508. package/dist/providers/openai-codex.js.map +1 -0
  509. package/dist/providers/openai-codex.models.d.ts +4 -0
  510. package/dist/providers/openai-codex.models.d.ts.map +1 -0
  511. package/dist/providers/openai-codex.models.js +6 -0
  512. package/dist/providers/openai-codex.models.js.map +1 -0
  513. package/dist/providers/openai.d.ts +3 -0
  514. package/dist/providers/openai.d.ts.map +1 -0
  515. package/dist/providers/openai.js +15 -0
  516. package/dist/providers/openai.js.map +1 -0
  517. package/dist/providers/openai.models.d.ts +4 -0
  518. package/dist/providers/openai.models.d.ts.map +1 -0
  519. package/dist/providers/openai.models.js +6 -0
  520. package/dist/providers/openai.models.js.map +1 -0
  521. package/dist/providers/opencode-go.d.ts +3 -0
  522. package/dist/providers/opencode-go.d.ts.map +1 -0
  523. package/dist/providers/opencode-go.js +20 -0
  524. package/dist/providers/opencode-go.js.map +1 -0
  525. package/dist/providers/opencode-go.models.d.ts +4 -0
  526. package/dist/providers/opencode-go.models.d.ts.map +1 -0
  527. package/dist/providers/opencode-go.models.js +6 -0
  528. package/dist/providers/opencode-go.models.js.map +1 -0
  529. package/dist/providers/opencode.d.ts +3 -0
  530. package/dist/providers/opencode.d.ts.map +1 -0
  531. package/dist/providers/opencode.js +22 -0
  532. package/dist/providers/opencode.js.map +1 -0
  533. package/dist/providers/opencode.models.d.ts +4 -0
  534. package/dist/providers/opencode.models.d.ts.map +1 -0
  535. package/dist/providers/opencode.models.js +6 -0
  536. package/dist/providers/opencode.models.js.map +1 -0
  537. package/dist/providers/openrouter-images.d.ts +3 -0
  538. package/dist/providers/openrouter-images.d.ts.map +1 -0
  539. package/dist/providers/openrouter-images.js +22 -0
  540. package/dist/providers/openrouter-images.js.map +1 -0
  541. package/dist/providers/openrouter.d.ts +3 -0
  542. package/dist/providers/openrouter.d.ts.map +1 -0
  543. package/dist/providers/openrouter.js +23 -0
  544. package/dist/providers/openrouter.js.map +1 -0
  545. package/dist/providers/openrouter.models.d.ts +4 -0
  546. package/dist/providers/openrouter.models.d.ts.map +1 -0
  547. package/dist/providers/openrouter.models.js +6 -0
  548. package/dist/providers/openrouter.models.js.map +1 -0
  549. package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
  550. package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
  551. package/dist/providers/qwen-token-plan-cn.js +15 -0
  552. package/dist/providers/qwen-token-plan-cn.js.map +1 -0
  553. package/dist/providers/qwen-token-plan-cn.models.d.ts +4 -0
  554. package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
  555. package/dist/providers/qwen-token-plan-cn.models.js +6 -0
  556. package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
  557. package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
  558. package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
  559. package/dist/providers/qwen-token-plan-individual.js +15 -0
  560. package/dist/providers/qwen-token-plan-individual.js.map +1 -0
  561. package/dist/providers/qwen-token-plan-individual.models.d.ts +4 -0
  562. package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
  563. package/dist/providers/qwen-token-plan-individual.models.js +6 -0
  564. package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
  565. package/dist/providers/qwen-token-plan.d.ts +3 -0
  566. package/dist/providers/qwen-token-plan.d.ts.map +1 -0
  567. package/dist/providers/qwen-token-plan.js +15 -0
  568. package/dist/providers/qwen-token-plan.js.map +1 -0
  569. package/dist/providers/qwen-token-plan.models.d.ts +4 -0
  570. package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
  571. package/dist/providers/qwen-token-plan.models.js +6 -0
  572. package/dist/providers/qwen-token-plan.models.js.map +1 -0
  573. package/dist/providers/radius-config.d.ts +26 -0
  574. package/dist/providers/radius-config.d.ts.map +1 -0
  575. package/dist/providers/radius-config.js +63 -0
  576. package/dist/providers/radius-config.js.map +1 -0
  577. package/dist/providers/radius.d.ts +9 -0
  578. package/dist/providers/radius.d.ts.map +1 -0
  579. package/dist/providers/radius.js +64 -0
  580. package/dist/providers/radius.js.map +1 -0
  581. package/dist/providers/together.d.ts +3 -0
  582. package/dist/providers/together.d.ts.map +1 -0
  583. package/dist/providers/together.js +15 -0
  584. package/dist/providers/together.js.map +1 -0
  585. package/dist/providers/together.models.d.ts +4 -0
  586. package/dist/providers/together.models.d.ts.map +1 -0
  587. package/dist/providers/together.models.js +6 -0
  588. package/dist/providers/together.models.js.map +1 -0
  589. package/dist/providers/vercel-ai-gateway.d.ts +3 -0
  590. package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
  591. package/dist/providers/vercel-ai-gateway.js +15 -0
  592. package/dist/providers/vercel-ai-gateway.js.map +1 -0
  593. package/dist/providers/vercel-ai-gateway.models.d.ts +4 -0
  594. package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
  595. package/dist/providers/vercel-ai-gateway.models.js +6 -0
  596. package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
  597. package/dist/providers/xai.d.ts +3 -0
  598. package/dist/providers/xai.d.ts.map +1 -0
  599. package/dist/providers/xai.js +28 -0
  600. package/dist/providers/xai.js.map +1 -0
  601. package/dist/providers/xai.models.d.ts +4 -0
  602. package/dist/providers/xai.models.d.ts.map +1 -0
  603. package/dist/providers/xai.models.js +6 -0
  604. package/dist/providers/xai.models.js.map +1 -0
  605. package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
  606. package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
  607. package/dist/providers/xiaomi-token-plan-ams.js +15 -0
  608. package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
  609. package/dist/providers/xiaomi-token-plan-ams.models.d.ts +4 -0
  610. package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
  611. package/dist/providers/xiaomi-token-plan-ams.models.js +6 -0
  612. package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
  613. package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
  614. package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
  615. package/dist/providers/xiaomi-token-plan-cn.js +15 -0
  616. package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
  617. package/dist/providers/xiaomi-token-plan-cn.models.d.ts +4 -0
  618. package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
  619. package/dist/providers/xiaomi-token-plan-cn.models.js +6 -0
  620. package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
  621. package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
  622. package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
  623. package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
  624. package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
  625. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +4 -0
  626. package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
  627. package/dist/providers/xiaomi-token-plan-sgp.models.js +6 -0
  628. package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
  629. package/dist/providers/xiaomi.d.ts +3 -0
  630. package/dist/providers/xiaomi.d.ts.map +1 -0
  631. package/dist/providers/xiaomi.js +15 -0
  632. package/dist/providers/xiaomi.js.map +1 -0
  633. package/dist/providers/xiaomi.models.d.ts +4 -0
  634. package/dist/providers/xiaomi.models.d.ts.map +1 -0
  635. package/dist/providers/xiaomi.models.js +6 -0
  636. package/dist/providers/xiaomi.models.js.map +1 -0
  637. package/dist/providers/zai-coding-cn.d.ts +3 -0
  638. package/dist/providers/zai-coding-cn.d.ts.map +1 -0
  639. package/dist/providers/zai-coding-cn.js +15 -0
  640. package/dist/providers/zai-coding-cn.js.map +1 -0
  641. package/dist/providers/zai-coding-cn.models.d.ts +4 -0
  642. package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
  643. package/dist/providers/zai-coding-cn.models.js +6 -0
  644. package/dist/providers/zai-coding-cn.models.js.map +1 -0
  645. package/dist/providers/zai.d.ts +3 -0
  646. package/dist/providers/zai.d.ts.map +1 -0
  647. package/dist/providers/zai.js +15 -0
  648. package/dist/providers/zai.js.map +1 -0
  649. package/dist/providers/zai.models.d.ts +4 -0
  650. package/dist/providers/zai.models.d.ts.map +1 -0
  651. package/dist/providers/zai.models.js +6 -0
  652. package/dist/providers/zai.models.js.map +1 -0
  653. package/dist/session-resources.d.ts +4 -0
  654. package/dist/session-resources.d.ts.map +1 -0
  655. package/dist/session-resources.js +22 -0
  656. package/dist/session-resources.js.map +1 -0
  657. package/dist/types.d.ts +697 -0
  658. package/dist/types.d.ts.map +1 -0
  659. package/dist/types.js +2 -0
  660. package/dist/types.js.map +1 -0
  661. package/dist/utils/abort-signals.d.ts +6 -0
  662. package/dist/utils/abort-signals.d.ts.map +1 -0
  663. package/dist/utils/abort-signals.js +34 -0
  664. package/dist/utils/abort-signals.js.map +1 -0
  665. package/dist/utils/abort.d.ts +8 -0
  666. package/dist/utils/abort.d.ts.map +1 -0
  667. package/dist/utils/abort.js +49 -0
  668. package/dist/utils/abort.js.map +1 -0
  669. package/dist/utils/deferred-tools.d.ts +9 -0
  670. package/dist/utils/deferred-tools.d.ts.map +1 -0
  671. package/dist/utils/deferred-tools.js +36 -0
  672. package/dist/utils/deferred-tools.js.map +1 -0
  673. package/dist/utils/diagnostics.d.ts +19 -0
  674. package/dist/utils/diagnostics.d.ts.map +1 -0
  675. package/dist/utils/diagnostics.js +25 -0
  676. package/dist/utils/diagnostics.js.map +1 -0
  677. package/dist/utils/error-body.d.ts +25 -0
  678. package/dist/utils/error-body.d.ts.map +1 -0
  679. package/dist/utils/error-body.js +133 -0
  680. package/dist/utils/error-body.js.map +1 -0
  681. package/dist/utils/estimate.d.ts +17 -0
  682. package/dist/utils/estimate.d.ts.map +1 -0
  683. package/dist/utils/estimate.js +116 -0
  684. package/dist/utils/estimate.js.map +1 -0
  685. package/dist/utils/event-stream.d.ts +21 -0
  686. package/dist/utils/event-stream.d.ts.map +1 -0
  687. package/dist/utils/event-stream.js +81 -0
  688. package/dist/utils/event-stream.js.map +1 -0
  689. package/dist/utils/hash.d.ts +3 -0
  690. package/dist/utils/hash.d.ts.map +1 -0
  691. package/dist/utils/hash.js +14 -0
  692. package/dist/utils/hash.js.map +1 -0
  693. package/dist/utils/headers.d.ts +4 -0
  694. package/dist/utils/headers.d.ts.map +1 -0
  695. package/dist/utils/headers.js +18 -0
  696. package/dist/utils/headers.js.map +1 -0
  697. package/dist/utils/json-parse.d.ts +16 -0
  698. package/dist/utils/json-parse.d.ts.map +1 -0
  699. package/dist/utils/json-parse.js +113 -0
  700. package/dist/utils/json-parse.js.map +1 -0
  701. package/dist/utils/node-http-proxy.d.ts +4 -0
  702. package/dist/utils/node-http-proxy.d.ts.map +1 -0
  703. package/dist/utils/node-http-proxy.js +92 -0
  704. package/dist/utils/node-http-proxy.js.map +1 -0
  705. package/dist/utils/overflow.d.ts +68 -0
  706. package/dist/utils/overflow.d.ts.map +1 -0
  707. package/dist/utils/overflow.js +172 -0
  708. package/dist/utils/overflow.js.map +1 -0
  709. package/dist/utils/pi-user-agent.d.ts +2 -0
  710. package/dist/utils/pi-user-agent.d.ts.map +1 -0
  711. package/dist/utils/pi-user-agent.js +12 -0
  712. package/dist/utils/pi-user-agent.js.map +1 -0
  713. package/dist/utils/provider-env.d.ts +7 -0
  714. package/dist/utils/provider-env.d.ts.map +1 -0
  715. package/dist/utils/provider-env.js +44 -0
  716. package/dist/utils/provider-env.js.map +1 -0
  717. package/dist/utils/provider-retry.d.ts +16 -0
  718. package/dist/utils/provider-retry.d.ts.map +1 -0
  719. package/dist/utils/provider-retry.js +94 -0
  720. package/dist/utils/provider-retry.js.map +1 -0
  721. package/dist/utils/retry.d.ts +53 -0
  722. package/dist/utils/retry.d.ts.map +1 -0
  723. package/dist/utils/retry.js +174 -0
  724. package/dist/utils/retry.js.map +1 -0
  725. package/dist/utils/sanitize-unicode.d.ts +22 -0
  726. package/dist/utils/sanitize-unicode.d.ts.map +1 -0
  727. package/dist/utils/sanitize-unicode.js +26 -0
  728. package/dist/utils/sanitize-unicode.js.map +1 -0
  729. package/dist/utils/text.d.ts +6 -0
  730. package/dist/utils/text.d.ts.map +1 -0
  731. package/dist/utils/text.js +10 -0
  732. package/dist/utils/text.js.map +1 -0
  733. package/dist/utils/typebox-helpers.d.ts +17 -0
  734. package/dist/utils/typebox-helpers.d.ts.map +1 -0
  735. package/dist/utils/typebox-helpers.js +21 -0
  736. package/dist/utils/typebox-helpers.js.map +1 -0
  737. package/dist/utils/uuid.d.ts +3 -0
  738. package/dist/utils/uuid.d.ts.map +1 -0
  739. package/dist/utils/uuid.js +46 -0
  740. package/dist/utils/uuid.js.map +1 -0
  741. package/dist/utils/validation.d.ts +18 -0
  742. package/dist/utils/validation.d.ts.map +1 -0
  743. package/dist/utils/validation.js +309 -0
  744. package/dist/utils/validation.js.map +1 -0
  745. package/package.json +122 -0
@@ -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;AAmHxC,4FAA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properties?: Record<string, JsonSchemaObject | undefined>;\n\trequired?: unknown;\n}\n\nclass UnsupportedStrictJsonSchemaError extends Error {}\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): 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\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);\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);\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);\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(schema: Tool[\"parameters\"]): 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);\n\tif (cloned.type !== \"object\") {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\treturn cloned;\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\nexport function appendGrammarToolInputJsonDelta(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tnextInput: string,\n\tclose: boolean,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tif (close && nextInput === buffer.input) return undefined;\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (!nextInput.startsWith(buffer.input)) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n\t}\n\n\tconst inputDelta = nextInput.slice(buffer.input.length);\n\tif (!close && inputDelta.length === 0) return undefined;\n\n\tlet delta = \"\";\n\tif (!buffer.started) {\n\t\tdelta += `{${JSON.stringify(inputProperty)}:\"`;\n\t\tbuffer.started = true;\n\t}\n\tdelta += JSON.stringify(inputDelta).slice(1, -1);\n\tbuffer.input = nextInput;\n\n\tif (close) {\n\t\tdelta += '\"}';\n\t\tbuffer.closed = true;\n\t}\n\treturn delta;\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\nexport function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean): 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);\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,222 @@
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) {
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 (schema.anyOf !== undefined) {
52
+ if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
53
+ throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
54
+ }
55
+ for (const variant of schema.anyOf) {
56
+ if (isStructuredSchema(variant)) {
57
+ throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
58
+ }
59
+ makeJsonSchemaNodeStrict(variant);
60
+ }
61
+ }
62
+ if (schema.items !== undefined) {
63
+ if (Array.isArray(schema.items)) {
64
+ throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
65
+ }
66
+ makeJsonSchemaNodeStrict(schema.items);
67
+ }
68
+ const isObjectSchema = schema.type === "object";
69
+ if (schema.properties !== undefined && !isObjectSchema) {
70
+ throw new UnsupportedStrictJsonSchemaError("properties require type object");
71
+ }
72
+ if (!isObjectSchema)
73
+ return;
74
+ if (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {
75
+ throw new UnsupportedStrictJsonSchemaError("schema-valued or true additionalProperties is unsupported");
76
+ }
77
+ if (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {
78
+ throw new UnsupportedStrictJsonSchemaError("object properties must be a schema map");
79
+ }
80
+ if (schema.required !== undefined &&
81
+ (!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
82
+ throw new UnsupportedStrictJsonSchemaError("object required must be a string array");
83
+ }
84
+ const properties = schema.properties ?? {};
85
+ const propertyNames = Object.keys(properties);
86
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
87
+ if ([...required].some((key) => !propertyNames.includes(key))) {
88
+ throw new UnsupportedStrictJsonSchemaError("required contains an unknown property");
89
+ }
90
+ for (const [key, property] of Object.entries(properties)) {
91
+ makeJsonSchemaNodeStrict(property);
92
+ if (!required.has(key) && !schemaAllowsNull(property)) {
93
+ properties[key] = { anyOf: [property, { type: "null" }] };
94
+ }
95
+ }
96
+ schema.required = propertyNames;
97
+ schema.additionalProperties = false;
98
+ }
99
+ /** Convert a tool schema to the strict subset expected by provider constrained sampling. */
100
+ export function makeStrictJsonSchema(schema) {
101
+ const cloned = structuredClone(schema);
102
+ if (!isJsonSchemaObject(cloned)) {
103
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
104
+ }
105
+ makeJsonSchemaNodeStrict(cloned);
106
+ if (cloned.type !== "object") {
107
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
108
+ }
109
+ return cloned;
110
+ }
111
+ export function getJsonSchemaToolParameters(tool, strict) {
112
+ return (strict === true ? makeStrictJsonSchema(tool.parameters) : tool.parameters);
113
+ }
114
+ export function getGrammarToolInput(toolName, arguments_, inputProperty) {
115
+ const input = arguments_[inputProperty];
116
+ if (typeof input !== "string") {
117
+ throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
118
+ }
119
+ return input;
120
+ }
121
+ export function appendGrammarToolInputJsonDelta(buffer, inputProperty, nextInput, close) {
122
+ if (buffer.closed) {
123
+ if (close && nextInput === buffer.input)
124
+ return undefined;
125
+ throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
126
+ }
127
+ if (!nextInput.startsWith(buffer.input)) {
128
+ throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
129
+ }
130
+ const inputDelta = nextInput.slice(buffer.input.length);
131
+ if (!close && inputDelta.length === 0)
132
+ return undefined;
133
+ let delta = "";
134
+ if (!buffer.started) {
135
+ delta += `{${JSON.stringify(inputProperty)}:"`;
136
+ buffer.started = true;
137
+ }
138
+ delta += JSON.stringify(inputDelta).slice(1, -1);
139
+ buffer.input = nextInput;
140
+ if (close) {
141
+ delta += '"}';
142
+ buffer.closed = true;
143
+ }
144
+ return delta;
145
+ }
146
+ function inferGrammarInputProperty(tool) {
147
+ const schema = tool.parameters;
148
+ if (schema.type !== "object") {
149
+ throw new Error("grammar constrained sampling requires an object parameter schema");
150
+ }
151
+ if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== "string") {
152
+ throw new Error("grammar constrained sampling requires exactly one required string property");
153
+ }
154
+ const inputProperty = schema.required[0];
155
+ if (!schema.properties?.[inputProperty]) {
156
+ throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);
157
+ }
158
+ if (schema.properties[inputProperty]?.type !== "string") {
159
+ throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
160
+ }
161
+ return inputProperty;
162
+ }
163
+ export function resolveJsonSchemaStrictSampling(tool, supportsStrictMode) {
164
+ const config = tool.constrainedSampling;
165
+ if (!config || config.type !== "json_schema")
166
+ return undefined;
167
+ if (supportsStrictMode) {
168
+ try {
169
+ makeStrictJsonSchema(tool.parameters);
170
+ return true;
171
+ }
172
+ catch (error) {
173
+ if (!(error instanceof UnsupportedStrictJsonSchemaError))
174
+ throw error;
175
+ if (config.strict !== "require")
176
+ return undefined;
177
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but ${error.message}.`);
178
+ }
179
+ }
180
+ if (config.strict === "require") {
181
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
182
+ }
183
+ return undefined;
184
+ }
185
+ export function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {
186
+ const config = tool.constrainedSampling;
187
+ if (!config || config.type !== "grammar") {
188
+ return undefined;
189
+ }
190
+ if (!supportsOpenAIGrammarTools) {
191
+ return undefined;
192
+ }
193
+ const larkDefinition = config.variants.openai_lark;
194
+ const regexDefinition = config.variants.openai_regex;
195
+ const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
196
+ const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
197
+ if (!hasLarkDefinition && !hasRegexDefinition) {
198
+ throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);
199
+ }
200
+ try {
201
+ return {
202
+ format: hasLarkDefinition ? "lark" : "regex",
203
+ definition: hasLarkDefinition ? larkDefinition : regexDefinition,
204
+ inputProperty: inferGrammarInputProperty(tool),
205
+ };
206
+ }
207
+ catch (error) {
208
+ const message = error instanceof Error ? error.message : String(error);
209
+ throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
210
+ }
211
+ }
212
+ export function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {
213
+ const properties = new Map();
214
+ for (const tool of tools ?? []) {
215
+ const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
216
+ if (grammar) {
217
+ properties.set(tool.name, grammar.inputProperty);
218
+ }
219
+ }
220
+ return properties;
221
+ }
222
+ //# sourceMappingURL=constrained-sampling.js.map
@@ -0,0 +1 @@
1
+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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;AAAA,CAClB","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\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): 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\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);\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);\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);\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(schema: Tool[\"parameters\"]): 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);\n\tif (cloned.type !== \"object\") {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\treturn cloned;\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\nexport function appendGrammarToolInputJsonDelta(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tnextInput: string,\n\tclose: boolean,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tif (close && nextInput === buffer.input) return undefined;\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (!nextInput.startsWith(buffer.input)) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n\t}\n\n\tconst inputDelta = nextInput.slice(buffer.input.length);\n\tif (!close && inputDelta.length === 0) return undefined;\n\n\tlet delta = \"\";\n\tif (!buffer.started) {\n\t\tdelta += `{${JSON.stringify(inputProperty)}:\"`;\n\t\tbuffer.started = true;\n\t}\n\tdelta += JSON.stringify(inputDelta).slice(1, -1);\n\tbuffer.input = nextInput;\n\n\tif (close) {\n\t\tdelta += '\"}';\n\t\tbuffer.closed = true;\n\t}\n\treturn delta;\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\nexport function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean): 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);\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","sourcesContent":["import type { Message } from \"../types.ts\";\n\n// Copilot expects X-Initiator to indicate whether the request is user-initiated\n// or agent-initiated (e.g. follow-up after assistant/tool messages).\nexport function inferCopilotInitiator(messages: Message[]): \"user\" | \"agent\" {\n\tconst last = messages[messages.length - 1];\n\treturn last && last.role !== \"user\" ? \"agent\" : \"user\";\n}\n\n// Copilot requires Copilot-Vision-Request header when sending images\nexport function hasCopilotVisionInput(messages: Message[]): boolean {\n\treturn messages.some((msg) => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\treturn msg.content.some((c) => c.type === \"image\");\n\t\t}\n\t\tif (msg.role === \"toolResult\" && Array.isArray(msg.content)) {\n\t\t\treturn msg.content.some((c) => c.type === \"image\");\n\t\t}\n\t\treturn false;\n\t});\n}\n\nexport function buildCopilotDynamicHeaders(params: {\n\tmessages: Message[];\n\thasImages: boolean;\n}): Record<string, string> {\n\tconst headers: Record<string, string> = {\n\t\t\"X-Initiator\": inferCopilotInitiator(params.messages),\n\t\t\"Openai-Intent\": \"conversation-edits\",\n\t};\n\n\tif (params.hasImages) {\n\t\theaders[\"Copilot-Vision-Request\"] = \"true\";\n\t}\n\n\treturn headers;\n}\n"]}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-copilot-headers.js","sourceRoot":"","sources":["../../src/api/github-copilot-headers.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,UAAU,qBAAqB,CAAC,QAAmB,EAAoB;IAC5E,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAAA,CACvD;AAED,qEAAqE;AACrE,MAAM,UAAU,qBAAqB,CAAC,QAAmB,EAAW;IACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;QAC7B,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACvD,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,KAAK,CAAC;IAAA,CACb,CAAC,CAAC;AAAA,CACH;AAED,MAAM,UAAU,0BAA0B,CAAC,MAG1C,EAA0B;IAC1B,MAAM,OAAO,GAA2B;QACvC,aAAa,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC;QACrD,eAAe,EAAE,oBAAoB;KACrC,CAAC;IAEF,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAAC;IAC5C,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { Message } from \"../types.ts\";\n\n// Copilot expects X-Initiator to indicate whether the request is user-initiated\n// or agent-initiated (e.g. follow-up after assistant/tool messages).\nexport function inferCopilotInitiator(messages: Message[]): \"user\" | \"agent\" {\n\tconst last = messages[messages.length - 1];\n\treturn last && last.role !== \"user\" ? \"agent\" : \"user\";\n}\n\n// Copilot requires Copilot-Vision-Request header when sending images\nexport function hasCopilotVisionInput(messages: Message[]): boolean {\n\treturn messages.some((msg) => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\treturn msg.content.some((c) => c.type === \"image\");\n\t\t}\n\t\tif (msg.role === \"toolResult\" && Array.isArray(msg.content)) {\n\t\t\treturn msg.content.some((c) => c.type === \"image\");\n\t\t}\n\t\treturn false;\n\t});\n}\n\nexport function buildCopilotDynamicHeaders(params: {\n\tmessages: Message[];\n\thasImages: boolean;\n}): Record<string, string> {\n\tconst headers: Record<string, string> = {\n\t\t\"X-Initiator\": inferCopilotInitiator(params.messages),\n\t\t\"Openai-Intent\": \"conversation-edits\",\n\t};\n\n\tif (params.hasImages) {\n\t\theaders[\"Copilot-Vision-Request\"] = \"true\";\n\t}\n\n\treturn headers;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { SimpleStreamOptions, StreamFunction, StreamOptions } from "../types.ts";
2
+ import type { GoogleThinkingLevel } from "./google-shared.ts";
3
+ export interface GoogleOptions extends StreamOptions {
4
+ toolChoice?: "auto" | "none" | "any";
5
+ thinking?: {
6
+ enabled: boolean;
7
+ budgetTokens?: number;
8
+ level?: GoogleThinkingLevel;
9
+ };
10
+ }
11
+ export declare const stream: StreamFunction<"google-generative-ai", GoogleOptions>;
12
+ export declare const streamSimple: StreamFunction<"google-generative-ai", SimpleStreamOptions>;
13
+ //# sourceMappingURL=google-generative-ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-generative-ai.d.ts","sourceRoot":"","sources":["../../src/api/google-generative-ai.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAMX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AAKrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAa9D,MAAM,WAAW,aAAc,SAAQ,aAAa;IACnD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IACrC,QAAQ,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,mBAAmB,CAAC;KAC5B,CAAC;CACF;AAKD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,sBAAsB,EAAE,aAAa,CAkPxE,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,sBAAsB,EAAE,mBAAmB,CAoCpF,CAAC","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\ttype ThinkingConfig,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tProviderHeaders,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tThinkingLevel,\n\tToolCall,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { providerHeadersToRecord } from \"../utils/headers.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tresolveGoogleFunctionCallingMode,\n\tretainThoughtSignature,\n\tretryGoogleRequest,\n\tsupportsGoogleStrictToolSampling,\n} from \"./google-shared.ts\";\nimport { buildBaseOptions } from \"./simple-options.ts\";\n\nexport interface GoogleOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n}\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const stream: StreamFunction<\"google-generative-ai\", GoogleOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: GoogleOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-generative-ai\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"pending\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tif (options?.fetch && options.fetch !== globalThis.fetch) {\n\t\t\t\tthrow new Error(\"Custom fetch is not supported by the Google Generative AI adapter\");\n\t\t\t}\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\t\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// @google/genai documents GenerateContentResponse.responseId as an output-only field\n\t\t\t\t// used to identify each response. Keep the first non-empty one from the stream.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Generate unique ID if not provided or if it's a duplicate\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.rawStopReason = candidate.finishReason;\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\treasoning: chunk.usageMetadata.thoughtsTokenCount || 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Google stream ended without a finish reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tconst errorMessage = output.rawStopReason\n\t\t\t\t\t? `Provider stopped with: ${output.rawStopReason}`\n\t\t\t\t\t: \"An unknown error occurred\";\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error));\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimple: StreamFunction<\"google-generative-ai\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, context, options, apiKey);\n\tif (!options?.reasoning) {\n\t\treturn stream(model, context, { ...base, thinking: { enabled: false } } satisfies GoogleOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\tconst googleModel = model as Model<\"google-generative-ai\">;\n\n\tif (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) {\n\t\treturn stream(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getThinkingLevel(effort, googleModel),\n\t\t\t},\n\t\t} satisfies GoogleOptions);\n\t}\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(googleModel, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-generative-ai\">,\n\tapiKey?: string,\n\toptionsHeaders?: ProviderHeaders,\n): GoogleGenAI {\n\tconst httpOptions: { baseUrl?: string; apiVersion?: string; headers?: Record<string, string> } = {};\n\tif (model.baseUrl) {\n\t\thttpOptions.baseUrl = model.baseUrl;\n\t\thttpOptions.apiVersion = \"\"; // baseUrl already includes version path, don't append\n\t}\n\tconst headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });\n\tif (headers) {\n\t\thttpOptions.headers = headers;\n\t}\n\n\treturn new GoogleGenAI({\n\t\tapiKey,\n\t\thttpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : undefined,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions: GoogleOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context);\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst supportsStrictMode = supportsGoogleStrictToolSampling(model.id);\n\tconst functionCallingMode = context.tools?.length\n\t\t? resolveGoogleFunctionCallingMode(context.tools, options.toolChoice, supportsStrictMode)\n\t\t: undefined;\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools &&\n\t\t\tcontext.tools.length > 0 && {\n\t\t\t\ttools: convertTools(context.tools, false, supportsStrictMode),\n\t\t\t}),\n\t\t...(functionCallingMode !== undefined && {\n\t\t\ttoolConfig: { functionCallingConfig: { mode: functionCallingMode } },\n\t\t}),\n\t};\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\t// Cast to any since our GoogleThinkingLevel mirrors Google's ThinkingLevel enum values\n\t\t\tthinkingConfig.thinkingLevel = options.thinking.level as any;\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<ThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemma4Model(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemma-?4/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3ProModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Model<\"google-generative-ai\">): boolean {\n\tconst id = model.id.toLowerCase();\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(id) || id === \"gemini-flash-latest\" || id === \"gemini-flash-lite-latest\";\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-generative-ai\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: \"LOW\" as any };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: \"MINIMAL\" as any };\n\t}\n\tif (isGemma4Model(model)) {\n\t\treturn { thinkingLevel: \"MINIMAL\" as any };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getThinkingLevel(effort: ClampedThinkingLevel, model: Model<\"google-generative-ai\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tif (isGemma4Model(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"MINIMAL\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Model<\"google-generative-ai\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash-lite\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 512,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}