@radheim/ai 0.0.0-stage → 2.4.3

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 (560) hide show
  1. package/README.md +1890 -3
  2. package/dist/ai.d.ts +36 -0
  3. package/dist/ai.js +46 -0
  4. package/dist/cache-policy.d.ts +6 -0
  5. package/dist/cache-policy.js +205 -0
  6. package/dist/decision-client.d.ts +10 -0
  7. package/dist/decision-client.js +42 -0
  8. package/dist/decision.d.ts +378 -0
  9. package/dist/decision.js +171 -0
  10. package/dist/effect.d.ts +59 -0
  11. package/dist/effect.js +33 -0
  12. package/dist/effort-updates.d.ts +12 -0
  13. package/dist/effort-updates.js +23 -0
  14. package/dist/embedding-client.d.ts +10 -0
  15. package/dist/embedding-client.js +17 -0
  16. package/dist/embedding.d.ts +113 -0
  17. package/dist/embedding.js +76 -0
  18. package/dist/experimental/cloudflare-run-extraction.d.ts +17 -0
  19. package/dist/experimental/cloudflare-run-extraction.js +85 -0
  20. package/dist/experimental/extraction.d.ts +153 -0
  21. package/dist/experimental/extraction.js +103 -0
  22. package/dist/experimental/realtime.d.ts +80 -0
  23. package/dist/experimental/realtime.js +96 -0
  24. package/dist/experimental.d.ts +10 -0
  25. package/dist/experimental.js +6 -0
  26. package/dist/fetch-middleware.d.ts +7 -0
  27. package/dist/fetch-middleware.js +41 -0
  28. package/dist/generation.d.ts +77 -0
  29. package/dist/generation.js +109 -0
  30. package/dist/image-client.d.ts +14 -0
  31. package/dist/image-client.js +39 -0
  32. package/dist/image.d.ts +323 -0
  33. package/dist/image.js +103 -0
  34. package/dist/index.d.ts +300 -0
  35. package/dist/index.js +179 -0
  36. package/dist/llm.d.ts +109 -0
  37. package/dist/llm.js +177 -0
  38. package/dist/loop.d.ts +38 -0
  39. package/dist/loop.js +139 -0
  40. package/dist/media-client.d.ts +30 -0
  41. package/dist/media-client.js +44 -0
  42. package/dist/media-model.d.ts +49 -0
  43. package/dist/media-model.js +55 -0
  44. package/dist/media.d.ts +237 -0
  45. package/dist/media.js +285 -0
  46. package/dist/promise-media.d.ts +20 -0
  47. package/dist/promise-media.js +16 -0
  48. package/dist/protocols/alibaba-chat.d.ts +315 -0
  49. package/dist/protocols/alibaba-chat.js +78 -0
  50. package/dist/protocols/alibaba-images.d.ts +22 -0
  51. package/dist/protocols/alibaba-images.js +77 -0
  52. package/dist/protocols/alibaba-messages.d.ts +413 -0
  53. package/dist/protocols/alibaba-messages.js +44 -0
  54. package/dist/protocols/alibaba-responses.d.ts +298 -0
  55. package/dist/protocols/alibaba-responses.js +67 -0
  56. package/dist/protocols/anthropic-messages.d.ts +1213 -0
  57. package/dist/protocols/anthropic-messages.js +1412 -0
  58. package/dist/protocols/assemblyai-transcription.d.ts +41 -0
  59. package/dist/protocols/assemblyai-transcription.js +137 -0
  60. package/dist/protocols/bedrock-converse.d.ts +548 -0
  61. package/dist/protocols/bedrock-converse.js +801 -0
  62. package/dist/protocols/bedrock-event-stream.d.ts +14 -0
  63. package/dist/protocols/bedrock-event-stream.js +100 -0
  64. package/dist/protocols/cartesia-speech.d.ts +117 -0
  65. package/dist/protocols/cartesia-speech.js +120 -0
  66. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  67. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  68. package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
  69. package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
  70. package/dist/protocols/cohere-chat.d.ts +184 -0
  71. package/dist/protocols/cohere-chat.js +317 -0
  72. package/dist/protocols/deepgram-speech.d.ts +109 -0
  73. package/dist/protocols/deepgram-speech.js +93 -0
  74. package/dist/protocols/deepgram-transcription.d.ts +26 -0
  75. package/dist/protocols/deepgram-transcription.js +119 -0
  76. package/dist/protocols/elevenlabs-speech.d.ts +112 -0
  77. package/dist/protocols/elevenlabs-speech.js +111 -0
  78. package/dist/protocols/elevenlabs-transcription.d.ts +28 -0
  79. package/dist/protocols/elevenlabs-transcription.js +137 -0
  80. package/dist/protocols/gemini.d.ts +388 -0
  81. package/dist/protocols/gemini.js +741 -0
  82. package/dist/protocols/google-decisions.d.ts +13 -0
  83. package/dist/protocols/google-decisions.js +133 -0
  84. package/dist/protocols/google-embed-content.d.ts +34 -0
  85. package/dist/protocols/google-embed-content.js +110 -0
  86. package/dist/protocols/google-images.d.ts +18 -0
  87. package/dist/protocols/google-images.js +169 -0
  88. package/dist/protocols/google-interactions-video.d.ts +38 -0
  89. package/dist/protocols/google-interactions-video.js +185 -0
  90. package/dist/protocols/google-interactions.d.ts +554 -0
  91. package/dist/protocols/google-interactions.js +756 -0
  92. package/dist/protocols/google-speech.d.ts +120 -0
  93. package/dist/protocols/google-speech.js +94 -0
  94. package/dist/protocols/google-transcription.d.ts +148 -0
  95. package/dist/protocols/google-transcription.js +129 -0
  96. package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
  97. package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
  98. package/dist/protocols/index.d.ts +21 -0
  99. package/dist/protocols/index.js +21 -0
  100. package/dist/protocols/meta-images.d.ts +26 -0
  101. package/dist/protocols/meta-images.js +101 -0
  102. package/dist/protocols/meta-messages.d.ts +423 -0
  103. package/dist/protocols/meta-messages.js +63 -0
  104. package/dist/protocols/meta-responses.d.ts +533 -0
  105. package/dist/protocols/meta-responses.js +189 -0
  106. package/dist/protocols/minimax-images.d.ts +25 -0
  107. package/dist/protocols/minimax-images.js +150 -0
  108. package/dist/protocols/minimax-video.d.ts +45 -0
  109. package/dist/protocols/minimax-video.js +296 -0
  110. package/dist/protocols/mistral-chat.d.ts +565 -0
  111. package/dist/protocols/mistral-chat.js +606 -0
  112. package/dist/protocols/open-responses-channel.d.ts +25 -0
  113. package/dist/protocols/open-responses-channel.js +137 -0
  114. package/dist/protocols/open-responses-continuation.d.ts +18 -0
  115. package/dist/protocols/open-responses-continuation.js +172 -0
  116. package/dist/protocols/open-responses.d.ts +2509 -0
  117. package/dist/protocols/open-responses.js +1335 -0
  118. package/dist/protocols/openai-chat.d.ts +2571 -0
  119. package/dist/protocols/openai-chat.js +1140 -0
  120. package/dist/protocols/openai-compatible-chat.d.ts +184 -0
  121. package/dist/protocols/openai-compatible-chat.js +19 -0
  122. package/dist/protocols/openai-compatible-responses.d.ts +231 -0
  123. package/dist/protocols/openai-compatible-responses.js +18 -0
  124. package/dist/protocols/openai-decisions.d.ts +22 -0
  125. package/dist/protocols/openai-decisions.js +141 -0
  126. package/dist/protocols/openai-embeddings.d.ts +16 -0
  127. package/dist/protocols/openai-embeddings.js +76 -0
  128. package/dist/protocols/openai-freeform.d.ts +78 -0
  129. package/dist/protocols/openai-freeform.js +222 -0
  130. package/dist/protocols/openai-images.d.ts +148 -0
  131. package/dist/protocols/openai-images.js +303 -0
  132. package/dist/protocols/openai-responses.d.ts +1600 -0
  133. package/dist/protocols/openai-responses.js +360 -0
  134. package/dist/protocols/openai-speech.d.ts +110 -0
  135. package/dist/protocols/openai-speech.js +112 -0
  136. package/dist/protocols/openai-transcription.d.ts +185 -0
  137. package/dist/protocols/openai-transcription.js +206 -0
  138. package/dist/protocols/openrouter-video.d.ts +36 -0
  139. package/dist/protocols/openrouter-video.js +139 -0
  140. package/dist/protocols/seedance-video.d.ts +45 -0
  141. package/dist/protocols/seedance-video.js +217 -0
  142. package/dist/protocols/shared.d.ts +249 -0
  143. package/dist/protocols/shared.js +446 -0
  144. package/dist/protocols/system-one.d.ts +145 -0
  145. package/dist/protocols/system-one.js +272 -0
  146. package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
  147. package/dist/protocols/utils/bedrock-auth.js +86 -0
  148. package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
  149. package/dist/protocols/utils/bedrock-cache.js +49 -0
  150. package/dist/protocols/utils/bedrock-media.d.ts +53 -0
  151. package/dist/protocols/utils/bedrock-media.js +98 -0
  152. package/dist/protocols/utils/cache.d.ts +25 -0
  153. package/dist/protocols/utils/cache.js +33 -0
  154. package/dist/protocols/utils/claude-model.d.ts +8 -0
  155. package/dist/protocols/utils/claude-model.js +15 -0
  156. package/dist/protocols/utils/gateway-protocol.d.ts +17 -0
  157. package/dist/protocols/utils/gateway-protocol.js +59 -0
  158. package/dist/protocols/utils/gemini-generate-content.d.ts +75 -0
  159. package/dist/protocols/utils/gemini-generate-content.js +96 -0
  160. package/dist/protocols/utils/gemini-json-schema.d.ts +8 -0
  161. package/dist/protocols/utils/gemini-json-schema.js +76 -0
  162. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  163. package/dist/protocols/utils/image-sizing.js +73 -0
  164. package/dist/protocols/utils/lifecycle.d.ts +24 -0
  165. package/dist/protocols/utils/lifecycle.js +62 -0
  166. package/dist/protocols/utils/media-input.d.ts +32 -0
  167. package/dist/protocols/utils/media-input.js +62 -0
  168. package/dist/protocols/utils/mistral-tool-id.d.ts +5 -0
  169. package/dist/protocols/utils/mistral-tool-id.js +31 -0
  170. package/dist/protocols/utils/open-responses-options.d.ts +54 -0
  171. package/dist/protocols/utils/open-responses-options.js +59 -0
  172. package/dist/protocols/utils/partial-json-options.d.ts +61 -0
  173. package/dist/protocols/utils/partial-json-options.js +51 -0
  174. package/dist/protocols/utils/partial-json.d.ts +8 -0
  175. package/dist/protocols/utils/partial-json.js +280 -0
  176. package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
  177. package/dist/protocols/utils/responses-checkpoint.js +103 -0
  178. package/dist/protocols/utils/responses-compaction.d.ts +6 -0
  179. package/dist/protocols/utils/responses-compaction.js +162 -0
  180. package/dist/protocols/utils/responses-hosted-tools.d.ts +122 -0
  181. package/dist/protocols/utils/responses-hosted-tools.js +63 -0
  182. package/dist/protocols/utils/speaker-turns.d.ts +3 -0
  183. package/dist/protocols/utils/speaker-turns.js +9 -0
  184. package/dist/protocols/utils/speech-stream.d.ts +49 -0
  185. package/dist/protocols/utils/speech-stream.js +64 -0
  186. package/dist/protocols/utils/tool-schema.d.ts +10 -0
  187. package/dist/protocols/utils/tool-schema.js +109 -0
  188. package/dist/protocols/utils/tool-stream.d.ts +478 -0
  189. package/dist/protocols/utils/tool-stream.js +153 -0
  190. package/dist/protocols/venice-chat.d.ts +340 -0
  191. package/dist/protocols/venice-chat.js +283 -0
  192. package/dist/protocols/xai-images.d.ts +25 -0
  193. package/dist/protocols/xai-images.js +87 -0
  194. package/dist/protocols/xai-responses.d.ts +294 -0
  195. package/dist/protocols/xai-responses.js +86 -0
  196. package/dist/protocols/xai-video.d.ts +35 -0
  197. package/dist/protocols/xai-video.js +159 -0
  198. package/dist/protocols/zai-chat.d.ts +296 -0
  199. package/dist/protocols/zai-chat.js +56 -0
  200. package/dist/protocols/zai-images.d.ts +20 -0
  201. package/dist/protocols/zai-images.js +79 -0
  202. package/dist/protocols/zai-messages.d.ts +409 -0
  203. package/dist/protocols/zai-messages.js +30 -0
  204. package/dist/protocols.d.ts +1 -0
  205. package/dist/protocols.js +1 -0
  206. package/dist/provider-error.d.ts +22 -0
  207. package/dist/provider-error.js +228 -0
  208. package/dist/provider-package.d.ts +17 -0
  209. package/dist/provider-package.js +1 -0
  210. package/dist/providers/alibaba/chat.d.ts +1 -0
  211. package/dist/providers/alibaba/chat.js +1 -0
  212. package/dist/providers/alibaba/embeddings.d.ts +2 -0
  213. package/dist/providers/alibaba/embeddings.js +1 -0
  214. package/dist/providers/alibaba/images.d.ts +2 -0
  215. package/dist/providers/alibaba/images.js +1 -0
  216. package/dist/providers/alibaba/messages.d.ts +3 -0
  217. package/dist/providers/alibaba/messages.js +1 -0
  218. package/dist/providers/alibaba/responses.d.ts +3 -0
  219. package/dist/providers/alibaba/responses.js +1 -0
  220. package/dist/providers/alibaba.d.ts +905 -0
  221. package/dist/providers/alibaba.js +119 -0
  222. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  223. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  224. package/dist/providers/amazon-bedrock/mantle/messages.d.ts +2 -0
  225. package/dist/providers/amazon-bedrock/mantle/messages.js +1 -0
  226. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  227. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  228. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  229. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  230. package/dist/providers/amazon-bedrock-mantle.d.ts +789 -0
  231. package/dist/providers/amazon-bedrock-mantle.js +107 -0
  232. package/dist/providers/amazon-bedrock.d.ts +190 -0
  233. package/dist/providers/amazon-bedrock.js +44 -0
  234. package/dist/providers/anthropic-compatible.d.ts +364 -0
  235. package/dist/providers/anthropic-compatible.js +47 -0
  236. package/dist/providers/anthropic.d.ts +362 -0
  237. package/dist/providers/anthropic.js +36 -0
  238. package/dist/providers/assemblyai.d.ts +19 -0
  239. package/dist/providers/assemblyai.js +19 -0
  240. package/dist/providers/azure/chat.d.ts +2 -0
  241. package/dist/providers/azure/chat.js +1 -0
  242. package/dist/providers/azure/embeddings.d.ts +2 -0
  243. package/dist/providers/azure/embeddings.js +1 -0
  244. package/dist/providers/azure/images.d.ts +2 -0
  245. package/dist/providers/azure/images.js +1 -0
  246. package/dist/providers/azure/messages.d.ts +2 -0
  247. package/dist/providers/azure/messages.js +1 -0
  248. package/dist/providers/azure/responses.d.ts +2 -0
  249. package/dist/providers/azure/responses.js +1 -0
  250. package/dist/providers/azure.d.ts +1074 -0
  251. package/dist/providers/azure.js +150 -0
  252. package/dist/providers/baseten/decisions.d.ts +2 -0
  253. package/dist/providers/baseten/decisions.js +1 -0
  254. package/dist/providers/baseten.d.ts +384 -0
  255. package/dist/providers/baseten.js +56 -0
  256. package/dist/providers/byteplus/videos.d.ts +2 -0
  257. package/dist/providers/byteplus/videos.js +1 -0
  258. package/dist/providers/byteplus.d.ts +24 -0
  259. package/dist/providers/byteplus.js +21 -0
  260. package/dist/providers/cartesia.d.ts +18 -0
  261. package/dist/providers/cartesia.js +17 -0
  262. package/dist/providers/cerebras.d.ts +375 -0
  263. package/dist/providers/cerebras.js +33 -0
  264. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  265. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  266. package/dist/providers/cloudflare-ai-gateway.d.ts +1581 -0
  267. package/dist/providers/cloudflare-ai-gateway.js +120 -0
  268. package/dist/providers/cloudflare-shared.d.ts +9 -0
  269. package/dist/providers/cloudflare-shared.js +25 -0
  270. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  271. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  272. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  273. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  274. package/dist/providers/cloudflare-workers-ai.d.ts +391 -0
  275. package/dist/providers/cloudflare-workers-ai.js +69 -0
  276. package/dist/providers/cohere/chat.d.ts +4 -0
  277. package/dist/providers/cohere/chat.js +3 -0
  278. package/dist/providers/cohere/embeddings.d.ts +2 -0
  279. package/dist/providers/cohere/embeddings.js +1 -0
  280. package/dist/providers/cohere.d.ts +502 -0
  281. package/dist/providers/cohere.js +55 -0
  282. package/dist/providers/deepgram.d.ts +22 -0
  283. package/dist/providers/deepgram.js +20 -0
  284. package/dist/providers/deepinfra/embeddings.d.ts +2 -0
  285. package/dist/providers/deepinfra/embeddings.js +1 -0
  286. package/dist/providers/deepinfra.d.ts +378 -0
  287. package/dist/providers/deepinfra.js +52 -0
  288. package/dist/providers/deepseek.d.ts +376 -0
  289. package/dist/providers/deepseek.js +30 -0
  290. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  291. package/dist/providers/digitalocean/decisions.js +1 -0
  292. package/dist/providers/digitalocean/embeddings.d.ts +2 -0
  293. package/dist/providers/digitalocean/embeddings.js +1 -0
  294. package/dist/providers/digitalocean/images.d.ts +2 -0
  295. package/dist/providers/digitalocean/images.js +1 -0
  296. package/dist/providers/digitalocean/responses.d.ts +4 -0
  297. package/dist/providers/digitalocean/responses.js +1 -0
  298. package/dist/providers/digitalocean.d.ts +874 -0
  299. package/dist/providers/digitalocean.js +106 -0
  300. package/dist/providers/elevenlabs.d.ts +22 -0
  301. package/dist/providers/elevenlabs.js +22 -0
  302. package/dist/providers/fireworks/embeddings.d.ts +2 -0
  303. package/dist/providers/fireworks/embeddings.js +1 -0
  304. package/dist/providers/fireworks.d.ts +379 -0
  305. package/dist/providers/fireworks.js +40 -0
  306. package/dist/providers/google/decisions.d.ts +2 -0
  307. package/dist/providers/google/decisions.js +1 -0
  308. package/dist/providers/google/embeddings.d.ts +2 -0
  309. package/dist/providers/google/embeddings.js +1 -0
  310. package/dist/providers/google/images.d.ts +2 -0
  311. package/dist/providers/google/images.js +1 -0
  312. package/dist/providers/google/interactions.d.ts +7 -0
  313. package/dist/providers/google/interactions.js +3 -0
  314. package/dist/providers/google/videos.d.ts +2 -0
  315. package/dist/providers/google/videos.js +1 -0
  316. package/dist/providers/google-vertex/chat.d.ts +2 -0
  317. package/dist/providers/google-vertex/chat.js +1 -0
  318. package/dist/providers/google-vertex/embeddings.d.ts +2 -0
  319. package/dist/providers/google-vertex/embeddings.js +1 -0
  320. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  321. package/dist/providers/google-vertex/gemini.js +1 -0
  322. package/dist/providers/google-vertex/images.d.ts +2 -0
  323. package/dist/providers/google-vertex/images.js +1 -0
  324. package/dist/providers/google-vertex/interactions.d.ts +2 -0
  325. package/dist/providers/google-vertex/interactions.js +1 -0
  326. package/dist/providers/google-vertex/messages.d.ts +2 -0
  327. package/dist/providers/google-vertex/messages.js +1 -0
  328. package/dist/providers/google-vertex/mistral.d.ts +2 -0
  329. package/dist/providers/google-vertex/mistral.js +1 -0
  330. package/dist/providers/google-vertex/responses.d.ts +2 -0
  331. package/dist/providers/google-vertex/responses.js +1 -0
  332. package/dist/providers/google-vertex-chat.d.ts +204 -0
  333. package/dist/providers/google-vertex-chat.js +29 -0
  334. package/dist/providers/google-vertex-interactions.d.ts +111 -0
  335. package/dist/providers/google-vertex-interactions.js +62 -0
  336. package/dist/providers/google-vertex-messages.d.ts +362 -0
  337. package/dist/providers/google-vertex-messages.js +51 -0
  338. package/dist/providers/google-vertex-mistral.d.ts +120 -0
  339. package/dist/providers/google-vertex-mistral.js +43 -0
  340. package/dist/providers/google-vertex-responses.d.ts +253 -0
  341. package/dist/providers/google-vertex-responses.js +30 -0
  342. package/dist/providers/google-vertex-shared.d.ts +58 -0
  343. package/dist/providers/google-vertex-shared.js +128 -0
  344. package/dist/providers/google-vertex.d.ts +132 -0
  345. package/dist/providers/google-vertex.js +161 -0
  346. package/dist/providers/google.d.ts +246 -0
  347. package/dist/providers/google.js +80 -0
  348. package/dist/providers/groq.d.ts +470 -0
  349. package/dist/providers/groq.js +63 -0
  350. package/dist/providers/index.d.ts +45 -0
  351. package/dist/providers/index.js +45 -0
  352. package/dist/providers/meta/chat.d.ts +2 -0
  353. package/dist/providers/meta/chat.js +1 -0
  354. package/dist/providers/meta/images.d.ts +2 -0
  355. package/dist/providers/meta/images.js +1 -0
  356. package/dist/providers/meta/messages.d.ts +2 -0
  357. package/dist/providers/meta/messages.js +1 -0
  358. package/dist/providers/meta/responses.d.ts +2 -0
  359. package/dist/providers/meta/responses.js +1 -0
  360. package/dist/providers/meta.d.ts +804 -0
  361. package/dist/providers/meta.js +96 -0
  362. package/dist/providers/minimax/chat.d.ts +4 -0
  363. package/dist/providers/minimax/chat.js +3 -0
  364. package/dist/providers/minimax/images.d.ts +3 -0
  365. package/dist/providers/minimax/images.js +1 -0
  366. package/dist/providers/minimax/messages.d.ts +1 -0
  367. package/dist/providers/minimax/messages.js +1 -0
  368. package/dist/providers/minimax/responses.d.ts +4 -0
  369. package/dist/providers/minimax/responses.js +3 -0
  370. package/dist/providers/minimax/videos.d.ts +3 -0
  371. package/dist/providers/minimax/videos.js +1 -0
  372. package/dist/providers/minimax.d.ts +798 -0
  373. package/dist/providers/minimax.js +99 -0
  374. package/dist/providers/mistral.d.ts +208 -0
  375. package/dist/providers/mistral.js +17 -0
  376. package/dist/providers/moonshot/chat.d.ts +1 -0
  377. package/dist/providers/moonshot/chat.js +1 -0
  378. package/dist/providers/moonshot/messages.d.ts +4 -0
  379. package/dist/providers/moonshot/messages.js +3 -0
  380. package/dist/providers/moonshot/responses.d.ts +4 -0
  381. package/dist/providers/moonshot/responses.js +3 -0
  382. package/dist/providers/moonshot.d.ts +785 -0
  383. package/dist/providers/moonshot.js +78 -0
  384. package/dist/providers/open-responses-options.d.ts +5 -0
  385. package/dist/providers/open-responses-options.js +1 -0
  386. package/dist/providers/openai/chat.d.ts +2 -0
  387. package/dist/providers/openai/chat.js +1 -0
  388. package/dist/providers/openai/embeddings.d.ts +2 -0
  389. package/dist/providers/openai/embeddings.js +1 -0
  390. package/dist/providers/openai/images.d.ts +2 -0
  391. package/dist/providers/openai/images.js +1 -0
  392. package/dist/providers/openai/responses.d.ts +2 -0
  393. package/dist/providers/openai/responses.js +1 -0
  394. package/dist/providers/openai-compatible/decisions.d.ts +2 -0
  395. package/dist/providers/openai-compatible/decisions.js +1 -0
  396. package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
  397. package/dist/providers/openai-compatible/embeddings.js +1 -0
  398. package/dist/providers/openai-compatible/images.d.ts +2 -0
  399. package/dist/providers/openai-compatible/images.js +1 -0
  400. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  401. package/dist/providers/openai-compatible/responses.js +1 -0
  402. package/dist/providers/openai-compatible-responses.d.ts +250 -0
  403. package/dist/providers/openai-compatible-responses.js +26 -0
  404. package/dist/providers/openai-compatible.d.ts +208 -0
  405. package/dist/providers/openai-compatible.js +71 -0
  406. package/dist/providers/openai-options.d.ts +21 -0
  407. package/dist/providers/openai-options.js +37 -0
  408. package/dist/providers/openai.d.ts +522 -0
  409. package/dist/providers/openai.js +118 -0
  410. package/dist/providers/opencode/decisions.d.ts +2 -0
  411. package/dist/providers/opencode/decisions.js +1 -0
  412. package/dist/providers/opencode.d.ts +23 -0
  413. package/dist/providers/opencode.js +25 -0
  414. package/dist/providers/openrouter/decisions.d.ts +2 -0
  415. package/dist/providers/openrouter/decisions.js +1 -0
  416. package/dist/providers/openrouter/embeddings.d.ts +2 -0
  417. package/dist/providers/openrouter/embeddings.js +1 -0
  418. package/dist/providers/openrouter/images.d.ts +2 -0
  419. package/dist/providers/openrouter/images.js +1 -0
  420. package/dist/providers/openrouter/responses.d.ts +3 -0
  421. package/dist/providers/openrouter/responses.js +1 -0
  422. package/dist/providers/openrouter/videos.d.ts +2 -0
  423. package/dist/providers/openrouter/videos.js +1 -0
  424. package/dist/providers/openrouter.d.ts +1204 -0
  425. package/dist/providers/openrouter.js +210 -0
  426. package/dist/providers/settings.d.ts +40 -0
  427. package/dist/providers/settings.js +18 -0
  428. package/dist/providers/togetherai.d.ts +375 -0
  429. package/dist/providers/togetherai.js +30 -0
  430. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  431. package/dist/providers/typesafe-ai/decisions.js +1 -0
  432. package/dist/providers/typesafe-ai.d.ts +23 -0
  433. package/dist/providers/typesafe-ai.js +25 -0
  434. package/dist/providers/venice/responses.d.ts +4 -0
  435. package/dist/providers/venice/responses.js +1 -0
  436. package/dist/providers/venice.d.ts +632 -0
  437. package/dist/providers/venice.js +57 -0
  438. package/dist/providers/vercel-ai-gateway/chat.d.ts +2 -0
  439. package/dist/providers/vercel-ai-gateway/chat.js +1 -0
  440. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  441. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  442. package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
  443. package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
  444. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  445. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  446. package/dist/providers/vercel-ai-gateway/messages.d.ts +2 -0
  447. package/dist/providers/vercel-ai-gateway/messages.js +1 -0
  448. package/dist/providers/vercel-ai-gateway/responses.d.ts +2 -0
  449. package/dist/providers/vercel-ai-gateway/responses.js +1 -0
  450. package/dist/providers/vercel-ai-gateway.d.ts +111 -0
  451. package/dist/providers/vercel-ai-gateway.js +181 -0
  452. package/dist/providers/volcengine/videos.d.ts +2 -0
  453. package/dist/providers/volcengine/videos.js +1 -0
  454. package/dist/providers/volcengine.d.ts +24 -0
  455. package/dist/providers/volcengine.js +21 -0
  456. package/dist/providers/xai/images.d.ts +2 -0
  457. package/dist/providers/xai/images.js +1 -0
  458. package/dist/providers/xai/videos.d.ts +2 -0
  459. package/dist/providers/xai/videos.js +1 -0
  460. package/dist/providers/xai.d.ts +235 -0
  461. package/dist/providers/xai.js +89 -0
  462. package/dist/providers/zai/chat.d.ts +1 -0
  463. package/dist/providers/zai/chat.js +1 -0
  464. package/dist/providers/zai/images.d.ts +2 -0
  465. package/dist/providers/zai/images.js +1 -0
  466. package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
  467. package/dist/providers/zai-coding-plan/chat.js +1 -0
  468. package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
  469. package/dist/providers/zai-coding-plan/messages.js +3 -0
  470. package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
  471. package/dist/providers/zai-coding-plan/responses.js +3 -0
  472. package/dist/providers/zai-coding-plan.d.ts +846 -0
  473. package/dist/providers/zai-coding-plan.js +56 -0
  474. package/dist/providers/zai.d.ts +285 -0
  475. package/dist/providers/zai.js +44 -0
  476. package/dist/providers.d.ts +1 -0
  477. package/dist/providers.js +1 -0
  478. package/dist/public.d.ts +18 -0
  479. package/dist/public.js +7 -0
  480. package/dist/route/auth-options.d.ts +35 -0
  481. package/dist/route/auth-options.js +17 -0
  482. package/dist/route/auth.d.ts +52 -0
  483. package/dist/route/auth.js +92 -0
  484. package/dist/route/client.d.ts +229 -0
  485. package/dist/route/client.js +293 -0
  486. package/dist/route/decision.d.ts +55 -0
  487. package/dist/route/decision.js +73 -0
  488. package/dist/route/embedding.d.ts +58 -0
  489. package/dist/route/embedding.js +85 -0
  490. package/dist/route/endpoint.d.ts +29 -0
  491. package/dist/route/endpoint.js +21 -0
  492. package/dist/route/executor-service.d.ts +54 -0
  493. package/dist/route/executor-service.js +115 -0
  494. package/dist/route/executor.d.ts +37 -0
  495. package/dist/route/executor.js +225 -0
  496. package/dist/route/framing.d.ts +44 -0
  497. package/dist/route/framing.js +63 -0
  498. package/dist/route/index.d.ts +21 -0
  499. package/dist/route/index.js +18 -0
  500. package/dist/route/media-protocol.d.ts +187 -0
  501. package/dist/route/media-protocol.js +117 -0
  502. package/dist/route/media.d.ts +91 -0
  503. package/dist/route/media.js +251 -0
  504. package/dist/route/protocol.d.ts +85 -0
  505. package/dist/route/protocol.js +19 -0
  506. package/dist/route/transport/http.d.ts +34 -0
  507. package/dist/route/transport/http.js +67 -0
  508. package/dist/route/transport/index.d.ts +42 -0
  509. package/dist/route/transport/index.js +4 -0
  510. package/dist/route/transport/websocket-channel.d.ts +56 -0
  511. package/dist/route/transport/websocket-channel.js +1 -0
  512. package/dist/route/transport/websocket.d.ts +32 -0
  513. package/dist/route/transport/websocket.js +315 -0
  514. package/dist/route.d.ts +1 -0
  515. package/dist/route.js +1 -0
  516. package/dist/schema/errors.d.ts +194 -0
  517. package/dist/schema/errors.js +217 -0
  518. package/dist/schema/events.d.ts +11001 -0
  519. package/dist/schema/events.js +542 -0
  520. package/dist/schema/ids.d.ts +17 -0
  521. package/dist/schema/ids.js +10 -0
  522. package/dist/schema/index.d.ts +5 -0
  523. package/dist/schema/index.js +5 -0
  524. package/dist/schema/messages.d.ts +2706 -0
  525. package/dist/schema/messages.js +344 -0
  526. package/dist/schema/options.d.ts +270 -0
  527. package/dist/schema/options.js +198 -0
  528. package/dist/speech.d.ts +266 -0
  529. package/dist/speech.js +114 -0
  530. package/dist/test-ai.d.ts +15 -0
  531. package/dist/test-ai.js +49 -0
  532. package/dist/testing.d.ts +1585 -0
  533. package/dist/testing.js +108 -0
  534. package/dist/tool-history.d.ts +2 -0
  535. package/dist/tool-history.js +91 -0
  536. package/dist/tool-runtime.d.ts +22 -0
  537. package/dist/tool-runtime.js +55 -0
  538. package/dist/tool-updates.d.ts +34 -0
  539. package/dist/tool-updates.js +93 -0
  540. package/dist/tool.d.ts +150 -0
  541. package/dist/tool.js +159 -0
  542. package/dist/transcription.d.ts +254 -0
  543. package/dist/transcription.js +119 -0
  544. package/dist/utils/bytes.d.ts +1 -0
  545. package/dist/utils/bytes.js +10 -0
  546. package/dist/utils/json.d.ts +4 -0
  547. package/dist/utils/json.js +4 -0
  548. package/dist/utils/media-type.d.ts +8 -0
  549. package/dist/utils/media-type.js +93 -0
  550. package/dist/utils/provider-codes.d.ts +3 -0
  551. package/dist/utils/provider-codes.js +41 -0
  552. package/dist/utils/record.d.ts +2 -0
  553. package/dist/utils/record.js +2 -0
  554. package/dist/utils/sanitize.d.ts +5 -0
  555. package/dist/utils/sanitize.js +31 -0
  556. package/dist/video-client.d.ts +12 -0
  557. package/dist/video-client.js +24 -0
  558. package/dist/video.d.ts +178 -0
  559. package/dist/video.js +79 -0
  560. package/package.json +648 -4
@@ -0,0 +1,44 @@
1
+ import { Stream } from "effect";
2
+ import { AIError } from "../schema/index.js";
3
+ /**
4
+ * Decode a streaming HTTP response body into provider-protocol frames.
5
+ *
6
+ * `Framing` is the byte-stream-shaped seam between transport and protocol:
7
+ *
8
+ * - SSE (`Framing.sse`) — UTF-8 decode the body, run the SSE channel decoder,
9
+ * and emit the `data:` payload of each non-empty event. The default drops
10
+ * `[DONE]`; protocols that use it as a terminal select `sseWithDone`.
11
+ * - AWS event stream — length-prefixed binary frames with CRC checksums.
12
+ * Each emitted frame is one parsed binary event record.
13
+ * - Media streams — newline-delimited JSON (`lines`) or the whole body as one
14
+ * frame (`document`); chunked binary bodies need no framing.
15
+ *
16
+ * The frame type is opaque to this layer; the protocol's event schema decodes
17
+ * each frame before its state machine handles it.
18
+ */
19
+ export interface Definition<Frame> {
20
+ readonly id: string;
21
+ readonly frame: (bytes: Stream.Stream<Uint8Array, AIError>) => Stream.Stream<Frame, AIError>;
22
+ /** Original wire representation when framing transforms the provider payload. */
23
+ readonly body?: (frame: Frame) => string | undefined;
24
+ /** Provider value exposed as a `raw` event when framing adds fields of its own. Defaults to the frame. */
25
+ readonly raw?: (frame: Frame) => unknown;
26
+ }
27
+ /**
28
+ * `framing` step for Server-Sent Events. Decodes UTF-8, runs the SSE channel
29
+ * decoder, optionally filters named events, and drops empty events and known
30
+ * keepalives that proxies send as data. `[DONE]` is dropped by default or
31
+ * retained for protocols that use it as their stream boundary. Retry control events are ignored without
32
+ * interrupting the stream. Decoder failures become provider output errors so
33
+ * the public error channel stays `AIError`.
34
+ */
35
+ export declare const sseFraming: (bytes: Stream.Stream<Uint8Array, AIError>, events?: ReadonlySet<string>, includeDone?: boolean) => Stream.Stream<string, AIError>;
36
+ /** Server-Sent Events framing. Used by every JSON-streaming HTTP provider. */
37
+ export declare const sse: Definition<string>;
38
+ /** Server-Sent Events framing that retains the conventional `[DONE]` sentinel. */
39
+ export declare const sseWithDone: Definition<string>;
40
+ /** SSE framing restricted to protocol-recognized event names. */
41
+ export declare const sseEvents: (events: ReadonlySet<string>) => Definition<string>;
42
+ export declare const lines: Definition<string>;
43
+ export declare const document: Definition<string>;
44
+ export * as Framing from "./framing.js";
@@ -0,0 +1,63 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { makeParser } from "effect/encoding/Sse";
3
+ import { AIError, InvalidProviderOutputError } from "../schema/index.js";
4
+ /**
5
+ * `framing` step for Server-Sent Events. Decodes UTF-8, runs the SSE channel
6
+ * decoder, optionally filters named events, and drops empty events and known
7
+ * keepalives that proxies send as data. `[DONE]` is dropped by default or
8
+ * retained for protocols that use it as their stream boundary. Retry control events are ignored without
9
+ * interrupting the stream. Decoder failures become provider output errors so
10
+ * the public error channel stays `AIError`.
11
+ */
12
+ export const sseFraming = (bytes, events, includeDone = false) => bytes.pipe(Stream.decodeText(), Stream.mapAccumEffect(() => {
13
+ const output = [];
14
+ return {
15
+ output,
16
+ parser: makeParser((event) => {
17
+ if (event._tag === "Event" &&
18
+ (events === undefined || events.has(event.event)) &&
19
+ event.data.length > 0 &&
20
+ // Some OpenAI-compatible proxies serialize an empty flush as a bare
21
+ // `data: null`, between events or after `[DONE]`. No protocol has a
22
+ // null event, so it carries nothing and must not abort the stream.
23
+ event.data !== "null" &&
24
+ // Vertex AI partner models (e.g. `xai/grok-4.6`) send their SSE
25
+ // keepalive comment as `data: : keepalive` while reasoning.
26
+ event.data !== ": keepalive" &&
27
+ (event.data !== "[DONE]" || includeDone || (events !== undefined && event.event !== "message")))
28
+ output.push(event.data);
29
+ }),
30
+ };
31
+ }, (state, chunk) => {
32
+ const error = state.parser.feed(chunk);
33
+ if (!error)
34
+ return Effect.succeed([state, state.output.splice(0)]);
35
+ const reason = new InvalidProviderOutputError({
36
+ route: "sse",
37
+ message: error.message,
38
+ body: chunk,
39
+ cause: error,
40
+ });
41
+ return Effect.fail(new AIError({ reason }));
42
+ }));
43
+ /** Server-Sent Events framing. Used by every JSON-streaming HTTP provider. */
44
+ export const sse = { id: "sse", frame: sseFraming };
45
+ /** Server-Sent Events framing that retains the conventional `[DONE]` sentinel. */
46
+ export const sseWithDone = {
47
+ id: "sse",
48
+ frame: (bytes) => sseFraming(bytes, undefined, true),
49
+ };
50
+ /** SSE framing restricted to protocol-recognized event names. */
51
+ export const sseEvents = (events) => ({
52
+ id: "sse",
53
+ frame: (bytes) => sseFraming(bytes, events),
54
+ });
55
+ export const lines = {
56
+ id: "lines",
57
+ frame: (bytes) => bytes.pipe(Stream.decodeText(), Stream.splitLines, Stream.filter((line) => line.trim().length > 0)),
58
+ };
59
+ export const document = {
60
+ id: "document",
61
+ frame: (bytes) => Stream.fromEffect(Stream.mkString(bytes.pipe(Stream.decodeText()))),
62
+ };
63
+ export * as Framing from "./framing.js";
@@ -0,0 +1,21 @@
1
+ export { Route } from "./client.js";
2
+ export type { AnyRoute, StreamOptions, CompactMethod, CompactionOperations, CompactionRequest, CheckpointRequest, EndpointCompactOptions, TriggerCompactOptions, } from "./client.js";
3
+ export { RequestExecutor } from "./executor.js";
4
+ export type { HttpMiddleware } from "./executor.js";
5
+ export { Auth } from "./auth.js";
6
+ export { DecisionRoute } from "./decision.js";
7
+ export { EmbeddingRoute } from "./embedding.js";
8
+ export { AuthOptions } from "./auth-options.js";
9
+ export { Endpoint } from "./endpoint.js";
10
+ export { MediaRoute } from "./media.js";
11
+ export { MediaProtocol } from "./media-protocol.js";
12
+ export { Framing } from "./framing.js";
13
+ export { Protocol } from "./protocol.js";
14
+ export { HttpTransport, WebSocketTransport } from "./transport/index.js";
15
+ export * as Transport from "./transport/index.js";
16
+ export { ProviderShared } from "../protocols/shared.js";
17
+ export { classifyProviderFailure } from "../provider-error.js";
18
+ export { mergeTransport, ProtocolID, RouteID } from "../schema/index.js";
19
+ export { emptyInputJsonSchema } from "../tool.js";
20
+ export { ProviderPackage } from "../provider-package.js";
21
+ export type { ChannelCheckpoint, ChannelCreate, ChannelObservation, WebSocketConnection, WebSocketChannelDriver, WebSocketChannelExchange, WebSocketChannelExecution, WebSocketChannelExecutor, WebSocketConnector, WebSocketRequest, } from "./transport/index.js";
@@ -0,0 +1,18 @@
1
+ export { Route } from "./client.js";
2
+ export { RequestExecutor } from "./executor.js";
3
+ export { Auth } from "./auth.js";
4
+ export { DecisionRoute } from "./decision.js";
5
+ export { EmbeddingRoute } from "./embedding.js";
6
+ export { AuthOptions } from "./auth-options.js";
7
+ export { Endpoint } from "./endpoint.js";
8
+ export { MediaRoute } from "./media.js";
9
+ export { MediaProtocol } from "./media-protocol.js";
10
+ export { Framing } from "./framing.js";
11
+ export { Protocol } from "./protocol.js";
12
+ export { HttpTransport, WebSocketTransport } from "./transport/index.js";
13
+ export * as Transport from "./transport/index.js";
14
+ export { ProviderShared } from "../protocols/shared.js";
15
+ export { classifyProviderFailure } from "../provider-error.js";
16
+ export { mergeTransport, ProtocolID, RouteID } from "../schema/index.js";
17
+ export { emptyInputJsonSchema } from "../tool.js";
18
+ export { ProviderPackage } from "../provider-package.js";
@@ -0,0 +1,187 @@
1
+ import { Duration, Effect, Schema, type Stream } from "effect";
2
+ import { HttpClientResponse } from "effect/http";
3
+ import type { Reason, Snapshot } from "../generation.js";
4
+ import { Media } from "../media.js";
5
+ import type { AuthInput } from "./auth.js";
6
+ import { RequestExecutor } from "./executor.js";
7
+ import { AIError, AuthenticationError, type HttpContext, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError } from "../schema/index.js";
8
+ /** Array values become repeated parameters (`keyterm=a&keyterm=b`). */
9
+ export type Query = Readonly<Record<string, string | ReadonlyArray<string>>>;
10
+ /** `query` is appended to the endpoint URL before the route and caller `http.query` overlays. */
11
+ export type Body = {
12
+ readonly type: "json";
13
+ readonly value: Record<string, unknown>;
14
+ readonly query?: Query;
15
+ } | {
16
+ readonly type: "multipart";
17
+ readonly value: FormData;
18
+ } | {
19
+ readonly type: "binary";
20
+ readonly value: Uint8Array;
21
+ readonly contentType: string;
22
+ readonly query?: Query;
23
+ };
24
+ export declare const json: (value: Record<string, unknown>, query?: Query) => Body;
25
+ export declare const multipart: (value: FormData) => Body;
26
+ export declare const binary: (value: Uint8Array, contentType: string, query?: Query) => Body;
27
+ export type Send = (path: string, body: Body) => Effect.Effect<HttpClientResponse.HttpClientResponse, AIError>;
28
+ /** Runs after unsupported-field rejection and before `body.from`, for providers that need an upload first. */
29
+ export type Prepare<Request> = (request: Request, send: Send) => Effect.Effect<Request, AIError>;
30
+ export interface DecodeContext<Request> {
31
+ readonly request: Request;
32
+ readonly body: Body;
33
+ }
34
+ /** One request, one response. JSON or multipart in; JSON or raw bytes out. */
35
+ export interface Inline<Request, Response> {
36
+ readonly kind: "inline";
37
+ readonly id: string;
38
+ readonly provider: ProviderID;
39
+ /** Common request fields this protocol cannot lower; the route rejects them before `body.from` runs. */
40
+ readonly unsupported?: ReadonlyArray<keyof Request & string>;
41
+ readonly body: {
42
+ readonly from: (request: Request) => Effect.Effect<Body, AIError>;
43
+ };
44
+ readonly response: {
45
+ readonly decode: (response: HttpClientResponse.HttpClientResponse, context: DecodeContext<Request>) => Effect.Effect<Response, AIError>;
46
+ };
47
+ }
48
+ export declare const inline: <Request, Response>(route: Identity, input: Omit<Inline<Request, Response>, "kind" | "id" | "provider">) => Inline<Request, Response>;
49
+ /** What `start` learned from the submission response: the route-owned handle plus the first observation. */
50
+ export interface Started<Token> {
51
+ readonly token: Token;
52
+ readonly snapshot: Snapshot;
53
+ }
54
+ /** A follow-up call's inputs: the decoded token. */
55
+ export interface PollContext<Token> {
56
+ readonly token: Token;
57
+ /**
58
+ * What an authenticated download of `url` needs, for result URLs that only download with the API key: the headers a
59
+ * GET would send (deployment headers plus auth) and the caller's scoped middleware. Spread it into `Media.url`. URLs
60
+ * on another origin than the route's base URL get neither, so credentials and hooks never leave the provider's host.
61
+ */
62
+ readonly credentials: (url: string) => Effect.Effect<Pick<Media.AssetOptions, "headers" | "middleware">, AIError>;
63
+ /**
64
+ * A further GET with the same auth and headers, retried like the poll itself, for providers whose result needs a
65
+ * second lookup (MiniMax v1 answers with a file id that resolves to a download URL).
66
+ */
67
+ readonly get: (path: string) => Effect.Effect<HttpClientResponse.HttpClientResponse, AIError>;
68
+ }
69
+ /**
70
+ * Submit, then poll. `start` posts the body to the route endpoint; `status`, `result`, and `cancel` are follow-up
71
+ * calls addressed by the token. Paths are relative to the route base URL unless the provider hands back absolute
72
+ * URLs, in which case they are used verbatim. `result` is always its own GET: providers that
73
+ * return the output inside the status body (xAI) point `result.path` at the status path and decode the
74
+ * same document, so `Generation.await` and `Video.resume(...).await()` behave identically everywhere.
75
+ */
76
+ export interface Queued<Request, Response, Token> {
77
+ readonly kind: "queued";
78
+ readonly id: string;
79
+ readonly provider: ProviderID;
80
+ /** Common request fields this protocol cannot lower; the route rejects them before `start.body.from` runs. */
81
+ readonly unsupported?: ReadonlyArray<keyof Request & string>;
82
+ /** Serializable handle. `Generation.token` carries the encoded form so it can be persisted and resumed elsewhere. */
83
+ readonly token: Schema.Codec<Token, unknown>;
84
+ readonly start: {
85
+ readonly prepare?: Prepare<Request>;
86
+ readonly body: {
87
+ readonly from: (request: Request) => Effect.Effect<Body, AIError>;
88
+ };
89
+ readonly decode: (response: HttpClientResponse.HttpClientResponse, context: DecodeContext<Request>) => Effect.Effect<Started<Token>, AIError>;
90
+ };
91
+ readonly status: {
92
+ readonly path: (token: Token) => string;
93
+ readonly decode: (response: HttpClientResponse.HttpClientResponse, context: PollContext<Token>) => Effect.Effect<Snapshot, AIError>;
94
+ };
95
+ readonly result: {
96
+ readonly path: (token: Token) => string;
97
+ readonly decode: (response: HttpClientResponse.HttpClientResponse, context: PollContext<Token>) => Effect.Effect<Response, AIError>;
98
+ };
99
+ readonly cancel?: {
100
+ readonly method: AuthInput["method"];
101
+ readonly path: (token: Token) => string;
102
+ };
103
+ }
104
+ export declare const queued: <Request, Response, Token>(route: Identity, input: Omit<Queued<Request, Response, Token>, "kind" | "id" | "provider">) => Queued<Request, Response, Token>;
105
+ export type Mode = "generate" | "stream";
106
+ export type Addressed<Request> = Request & {
107
+ readonly mode: Mode;
108
+ };
109
+ export interface ResponseContext<Request> extends DecodeContext<Addressed<Request>> {
110
+ readonly http: HttpContext;
111
+ }
112
+ /**
113
+ * One request whose body is parsed incrementally, like LLM protocols: `frames` → `step`* → `finish`. `generate` and
114
+ * `stream` share this state machine; `request.mode` lets a protocol pick a different body, path, or framing.
115
+ */
116
+ export interface Streamed<Request, Event, Frame, State> {
117
+ readonly kind: "stream";
118
+ readonly id: string;
119
+ readonly provider: ProviderID;
120
+ /** Common request fields this protocol cannot lower; the route rejects them before `body.from` runs. */
121
+ readonly unsupported?: ReadonlyArray<keyof Request & string>;
122
+ readonly body: {
123
+ readonly from: (request: Addressed<Request>) => Effect.Effect<Body, AIError>;
124
+ };
125
+ readonly frames: (bytes: Stream.Stream<Uint8Array, AIError>, context: DecodeContext<Addressed<Request>>) => Stream.Stream<Frame, AIError>;
126
+ readonly initial: () => State;
127
+ readonly step: (state: State, frame: Frame) => Effect.Effect<readonly [State, ReadonlyArray<Event>], AIError>;
128
+ /** Emit exactly one terminal event, or fail when the provider stopped before completing. */
129
+ readonly finish: (state: State, context: ResponseContext<Request>) => Effect.Effect<ReadonlyArray<Event>, AIError>;
130
+ }
131
+ export declare const stream: <Request, Event, Frame, State>(route: Identity, input: Omit<Streamed<Request, Event, Frame, State>, "kind" | "id" | "provider">) => Streamed<Request, Event, Frame, State>;
132
+ /** Reasons a provider can report for a `failed` generation; anything it does not classify is `ProviderInternal`. */
133
+ declare const FAILURES: {
134
+ InvalidRequest: typeof InvalidRequestError;
135
+ Authentication: typeof AuthenticationError;
136
+ RateLimit: typeof RateLimitError;
137
+ ProviderInternal: typeof ProviderInternalError;
138
+ };
139
+ export type Failure = keyof typeof FAILURES;
140
+ /** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
141
+ export declare const identity: (input: {
142
+ readonly id: string;
143
+ readonly name: string;
144
+ readonly provider: string;
145
+ }) => {
146
+ id: string;
147
+ name: string;
148
+ provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
149
+ text: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<{
150
+ body: string;
151
+ http: HttpContext;
152
+ invalid: (message: string, cause?: unknown) => AIError;
153
+ ended: (reason: Reason, message: string, failure?: Failure) => AIError;
154
+ pending: (id: string) => AIError;
155
+ contentPolicy: (message: string) => AIError;
156
+ }, AIError, never>;
157
+ bytes: typeof RequestExecutor.responseBytes;
158
+ decodeJson: <A>(schema: Schema.Codec<A, unknown>) => (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<{
159
+ body: string;
160
+ http: HttpContext;
161
+ invalid: (message: string, cause?: unknown) => AIError;
162
+ ended: (reason: Reason, message: string, failure?: Failure) => AIError;
163
+ pending: (id: string) => AIError;
164
+ contentPolicy: (message: string) => AIError;
165
+ value: A;
166
+ }, AIError, never>;
167
+ /** Decode a submission response into the token and first snapshot. */
168
+ decodeStarted: <A, Token>(schema: Schema.Codec<A, unknown>, started: (value: A) => Started<Token>) => (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<Started<Token>, AIError, never>;
169
+ /** Schema-decode one JSON stream frame. Decode failures keep the frame as `reason.body`. */
170
+ decodeFrame: <A>(schema: Schema.Codec<A, unknown>) => (frame: string) => Effect.Effect<A, AIError, never>;
171
+ /** A stream-time failure; the frame stays on `reason.body`. */
172
+ frameError: (message: string, body?: string, cause?: unknown) => AIError;
173
+ incomplete: () => AIError;
174
+ unsupported: (operation: string, message: string) => AIError;
175
+ };
176
+ export type Identity = ReturnType<typeof identity>;
177
+ /** A provider status in package terms: still running, completed, or the reason it ended in `error`. */
178
+ export type State = "running" | "completed" | Reason;
179
+ /** Map a provider status string through the protocol's table; unknown values keep the generation running. */
180
+ export declare const state: (table: Readonly<Record<string, State>>, raw: string) => State;
181
+ /** The snapshot `status` and `reason` for a provider status string. */
182
+ export declare const status: (table: Readonly<Record<string, State>>, raw: string) => Pick<Snapshot, "status" | "reason">;
183
+ /** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
184
+ export declare const failure: (table: Readonly<Record<string, Failure>>, code: string | number | undefined) => Failure;
185
+ /** A `url` asset whose provider-declared retention window starts now. */
186
+ export declare const expiringUrl: (url: string, retention: Duration.Duration, options?: Parameters<typeof Media.url>[1]) => Effect.Effect<Media.Asset, never, never>;
187
+ export * as MediaProtocol from "./media-protocol.js";
@@ -0,0 +1,117 @@
1
+ import { Clock, Duration, Effect, Schema } from "effect";
2
+ import { HttpClientResponse } from "effect/http";
3
+ import { Media } from "../media.js";
4
+ import { RequestExecutor } from "./executor.js";
5
+ import { AIError, AuthenticationError, ContentPolicyError, InvalidProviderOutputError, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError, UnsupportedOperationError, } from "../schema/index.js";
6
+ export const json = (value, query) => ({
7
+ type: "json",
8
+ value,
9
+ query,
10
+ });
11
+ export const multipart = (value) => ({ type: "multipart", value });
12
+ export const binary = (value, contentType, query) => ({
13
+ type: "binary",
14
+ value,
15
+ contentType,
16
+ query,
17
+ });
18
+ export const inline = (route, input) => ({ kind: "inline", id: route.id, provider: route.provider, ...input });
19
+ export const queued = (route, input) => ({ kind: "queued", id: route.id, provider: route.provider, ...input });
20
+ export const stream = (route, input) => ({ kind: "stream", id: route.id, provider: route.provider, ...input });
21
+ // ---------------------------------------------------------------------------
22
+ // Response helpers
23
+ // ---------------------------------------------------------------------------
24
+ /** Reasons a provider can report for a `failed` generation; anything it does not classify is `ProviderInternal`. */
25
+ const FAILURES = {
26
+ InvalidRequest: InvalidRequestError,
27
+ Authentication: AuthenticationError,
28
+ RateLimit: RateLimitError,
29
+ ProviderInternal: ProviderInternalError,
30
+ };
31
+ /** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
32
+ export const identity = (input) => {
33
+ const provider = ProviderID.make(input.provider);
34
+ const frameError = (message, body, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, cause }) });
35
+ /**
36
+ * Read a text body while retaining the original payload and HTTP context on every downstream error. `invalid` is a
37
+ * malformed provider document; `ended` is a generation that ended in `error` without output (reason `failed`
38
+ * carries the provider's classification, defaulting to `ProviderInternal`; `cancelled`/`expired` mean the result
39
+ * will never exist); `pending` is a `result()` read before the generation finished, which is caller misuse;
40
+ * `contentPolicy` is a moderated result.
41
+ */
42
+ const text = Effect.fn("MediaProtocol.text")(function* (response) {
43
+ const http = RequestExecutor.responseHttp(response);
44
+ const body = yield* RequestExecutor.responseText(response);
45
+ return {
46
+ body,
47
+ http,
48
+ invalid: (message, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, http, cause }) }),
49
+ ended: (reason, message, failure = "ProviderInternal") => new AIError({
50
+ reason: reason === "failed"
51
+ ? new FAILURES[failure]({ message, body, http })
52
+ : new InvalidRequestError({ message, body, http }),
53
+ }),
54
+ pending: (id) => new AIError({
55
+ reason: new InvalidRequestError({
56
+ message: `${input.name} generation ${id} has not finished; await it before reading the result`,
57
+ body,
58
+ http,
59
+ }),
60
+ }),
61
+ contentPolicy: (message) => new AIError({ reason: new ContentPolicyError({ message, body, http }) }),
62
+ };
63
+ });
64
+ /** Read and Schema-decode a JSON body. Decode failures keep the raw body as `reason.body`. */
65
+ const decodeJson = (schema) => {
66
+ const decode = Schema.decodeUnknownEffect(Schema.fromJsonString(schema));
67
+ return Effect.fn("MediaProtocol.decodeJson")(function* (response) {
68
+ const output = yield* text(response);
69
+ const value = yield* decode(output.body).pipe(Effect.mapError((cause) => output.invalid(`${input.name} returned an invalid response`, cause)));
70
+ return { ...output, value };
71
+ });
72
+ };
73
+ /** Read a raw binary body, for providers that answer with the media bytes themselves. */
74
+ const bytes = RequestExecutor.responseBytes;
75
+ return {
76
+ id: input.id,
77
+ name: input.name,
78
+ provider,
79
+ text,
80
+ bytes,
81
+ decodeJson,
82
+ /** Decode a submission response into the token and first snapshot. */
83
+ decodeStarted: (schema, started) => {
84
+ const decode = decodeJson(schema);
85
+ return (response) => decode(response).pipe(Effect.map((output) => started(output.value)));
86
+ },
87
+ /** Schema-decode one JSON stream frame. Decode failures keep the frame as `reason.body`. */
88
+ decodeFrame: (schema) => {
89
+ const decode = Schema.decodeUnknownEffect(Schema.fromJsonString(schema));
90
+ return (frame) => decode(frame).pipe(Effect.mapError((cause) => frameError(`${input.name} sent an invalid stream event`, frame, cause)));
91
+ },
92
+ /** A stream-time failure; the frame stays on `reason.body`. */
93
+ frameError,
94
+ incomplete: () => new AIError({
95
+ reason: new InvalidProviderOutputError({
96
+ route: input.id,
97
+ message: "The provider response ended unexpectedly.",
98
+ classification: "incomplete-stream",
99
+ }),
100
+ }),
101
+ unsupported: (operation, message) => new AIError({ reason: new UnsupportedOperationError({ operation, provider, route: input.id, message }) }),
102
+ };
103
+ };
104
+ /** Map a provider status string through the protocol's table; unknown values keep the generation running. */
105
+ export const state = (table, raw) => Object.hasOwn(table, raw) ? table[raw] : "running";
106
+ /** The snapshot `status` and `reason` for a provider status string. */
107
+ export const status = (table, raw) => {
108
+ const mapped = state(table, raw);
109
+ if (mapped === "running" || mapped === "completed")
110
+ return { status: mapped };
111
+ return { status: "error", reason: mapped };
112
+ };
113
+ /** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
114
+ export const failure = (table, code) => code !== undefined && Object.hasOwn(table, code) ? table[code] : "ProviderInternal";
115
+ /** A `url` asset whose provider-declared retention window starts now. */
116
+ export const expiringUrl = (url, retention, options) => Clock.currentTimeMillis.pipe(Effect.map((now) => Media.url(url, { ...options, expiresAt: now + Duration.toMillis(retention) })));
117
+ export * as MediaProtocol from "./media-protocol.js";
@@ -0,0 +1,91 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { Auth } from "./auth.js";
3
+ import { Endpoint } from "./endpoint.js";
4
+ import type { Interface } from "./executor-service.js";
5
+ import { MediaProtocol } from "./media-protocol.js";
6
+ import { Generation } from "../generation.js";
7
+ import { AIError, ProviderID, type BaseRequest, type ProviderOptions, type TransportOptions } from "../schema/index.js";
8
+ export type Execute = Interface["execute"];
9
+ /** The minimum a media request must carry for the route to build a transport request. */
10
+ export type MediaRequest = BaseRequest<{
11
+ readonly id: string;
12
+ readonly provider: ProviderID;
13
+ readonly transport?: TransportOptions;
14
+ readonly providerOptions?: ProviderOptions;
15
+ }>;
16
+ /** Deployment inputs every media model factory accepts; provider facades fill these from `configure(...)`. */
17
+ export interface ModelInput {
18
+ readonly id: string;
19
+ readonly auth: Auth.Definition;
20
+ readonly baseURL?: string;
21
+ /** Deployment `http` settings every request of the model starts from. */
22
+ readonly transport?: TransportOptions;
23
+ /** Defaults under each request's `providerOptions`. */
24
+ readonly providerOptions?: ProviderOptions;
25
+ }
26
+ /** A provider facade's `configure(...)` input as the `ModelInput` every media selector shares, minus the model id. */
27
+ export declare const deployment: (input: TransportOptions & {
28
+ readonly baseURL?: string;
29
+ }, auth: Auth.Definition) => Omit<ModelInput, "id">;
30
+ /** One request, one response. */
31
+ export interface InlineRoute<Request extends MediaRequest, Response> {
32
+ readonly kind: "inline";
33
+ readonly id: string;
34
+ readonly provider: ProviderID;
35
+ readonly protocol: string;
36
+ readonly generate: (request: Request, execute: Execute) => Effect.Effect<Response, AIError>;
37
+ }
38
+ /** Submit, then poll through the returned `Generation`. */
39
+ export interface QueuedRoute<Request extends MediaRequest, Response> {
40
+ readonly kind: "queued";
41
+ readonly id: string;
42
+ readonly provider: ProviderID;
43
+ readonly protocol: string;
44
+ readonly start: (request: Request, execute: Execute) => Effect.Effect<Generation<Response>, AIError>;
45
+ /** Rebuild a handle from a persisted `Generation.token`; fails typed when the token is not this route's. */
46
+ readonly resume: (model: MediaRequest["model"], token: unknown, execute: Execute) => Effect.Effect<Generation<Response>, AIError>;
47
+ /** The status, result and cancel operations for a persisted token, without reading its status first. */
48
+ readonly attach: (model: MediaRequest["model"], token: unknown, execute: Execute) => Effect.Effect<Generation<Response>["route"], AIError>;
49
+ }
50
+ /** One request whose response parses into events; `generate` runs the same stream and collects it. */
51
+ export interface StreamRoute<Request extends MediaRequest, Event, Response> {
52
+ readonly kind: "stream";
53
+ readonly id: string;
54
+ readonly provider: ProviderID;
55
+ readonly protocol: string;
56
+ readonly stream: (request: Request, execute: Execute) => Stream.Stream<Event, AIError>;
57
+ readonly generate: (request: Request, execute: Execute) => Effect.Effect<Response, AIError>;
58
+ }
59
+ export type AnyRoute<Request extends MediaRequest, Event, Response> = InlineRoute<Request, Response> | StreamRoute<Request, Event, Response> | QueuedRoute<Request, Response>;
60
+ export interface Composition<Request extends MediaRequest> {
61
+ readonly endpoint: Endpoint.Definition<MediaProtocol.Body, Request>;
62
+ readonly auth: Auth.Definition;
63
+ /** Headers the protocol requires on every call; the model's transport headers win. */
64
+ readonly headers?: Record<string, string>;
65
+ }
66
+ export interface InlineInput<Request extends MediaRequest, Response> extends Composition<Request> {
67
+ readonly protocol: MediaProtocol.Inline<Request, Response>;
68
+ }
69
+ export interface QueuedInput<Request extends MediaRequest, Response, Token> extends Composition<Request> {
70
+ readonly protocol: MediaProtocol.Queued<Request, Response, Token>;
71
+ }
72
+ export interface StreamInput<Request extends MediaRequest, Event, Response, Frame, State> extends Composition<MediaProtocol.Addressed<Request>> {
73
+ readonly protocol: MediaProtocol.Streamed<Request, Event, Frame, State>;
74
+ readonly collect: (events: ReadonlyArray<Event>) => Effect.Effect<Response, AIError>;
75
+ }
76
+ /**
77
+ * Compose an inline media protocol with an endpoint and auth into a runnable route. The route owns the transport
78
+ * plumbing every media protocol would otherwise duplicate: option merging, surrogate sanitizing, unsupported-field
79
+ * rejection, URL and query rendering, auth headers, JSON, multipart, or binary encoding, and handing responses back
80
+ * to the protocol.
81
+ */
82
+ export declare const inline: <Request extends MediaRequest, Response>(input: InlineInput<Request, Response>) => InlineRoute<Request, Response>;
83
+ /**
84
+ * Compose a queued media protocol the same way, adding `start`/`resume` handles whose polls reuse the route's auth,
85
+ * deployment headers, and (for `start`) the request's `http` overlay. The token is decoded once at the boundary and
86
+ * closed over by the resulting `Generation.Route`.
87
+ */
88
+ export declare const queued: <Request extends MediaRequest, Response, Token>(input: QueuedInput<Request, Response, Token>) => QueuedRoute<Request, Response>;
89
+ /** Compose a streaming media protocol; `generate` runs the same stream in `generate` mode and folds it with `collect`. */
90
+ export declare const stream: <Request extends MediaRequest, Event, Response, Frame, State>(input: StreamInput<Request, Event, Response, Frame, State>) => StreamRoute<Request, Event, Response>;
91
+ export * as MediaRoute from "./media.js";