@opencode/ai 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/README.md +283 -114
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/cache-policy.d.ts +4 -0
  5. package/dist/cache-policy.js +20 -6
  6. package/dist/decision-client.d.ts +21 -0
  7. package/dist/decision-client.js +55 -0
  8. package/dist/decision.d.ts +472 -0
  9. package/dist/decision.js +158 -0
  10. package/dist/effect.d.ts +38 -0
  11. package/dist/effect.js +27 -0
  12. package/dist/effort-updates.d.ts +2 -2
  13. package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
  14. package/dist/experimental/cloudflare-run-extraction.js +83 -0
  15. package/dist/experimental/extraction.d.ts +183 -0
  16. package/dist/experimental/extraction.js +102 -0
  17. package/dist/experimental/realtime.d.ts +7 -2
  18. package/dist/experimental/realtime.js +5 -5
  19. package/dist/experimental.d.ts +2 -3
  20. package/dist/experimental.js +1 -2
  21. package/dist/image-client.d.ts +13 -22
  22. package/dist/image-client.js +0 -1
  23. package/dist/image.d.ts +154 -324
  24. package/dist/image.js +4 -11
  25. package/dist/index.d.ts +1426 -34
  26. package/dist/index.js +127 -24
  27. package/dist/llm.d.ts +16 -1
  28. package/dist/llm.js +34 -0
  29. package/dist/media-client.d.ts +2 -1
  30. package/dist/media-model.d.ts +3 -0
  31. package/dist/media-model.js +4 -1
  32. package/dist/media.d.ts +0 -7
  33. package/dist/media.js +0 -6
  34. package/dist/protocols/alibaba-chat.d.ts +32 -12
  35. package/dist/protocols/alibaba-images.d.ts +22 -0
  36. package/dist/protocols/alibaba-images.js +77 -0
  37. package/dist/protocols/alibaba-messages.d.ts +62 -27
  38. package/dist/protocols/alibaba-responses.d.ts +41 -38
  39. package/dist/protocols/anthropic-messages.d.ts +196 -94
  40. package/dist/protocols/anthropic-messages.js +47 -16
  41. package/dist/protocols/bedrock-converse.d.ts +140 -47
  42. package/dist/protocols/bedrock-converse.js +114 -18
  43. package/dist/protocols/bedrock-event-stream.js +1 -0
  44. package/dist/protocols/bfl-images.d.ts +9 -0
  45. package/dist/protocols/bfl-images.js +17 -15
  46. package/dist/protocols/cartesia-speech.d.ts +32 -50
  47. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  48. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  49. package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
  50. package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
  51. package/dist/protocols/cohere-chat.d.ts +7 -8
  52. package/dist/protocols/deepgram-speech.d.ts +32 -50
  53. package/dist/protocols/elevenlabs-speech.d.ts +32 -50
  54. package/dist/protocols/fal-images.d.ts +10 -1
  55. package/dist/protocols/fal-images.js +16 -25
  56. package/dist/protocols/fal-video.js +1 -1
  57. package/dist/protocols/gemini.d.ts +37 -34
  58. package/dist/protocols/gemini.js +13 -8
  59. package/dist/protocols/google-images.d.ts +2 -2
  60. package/dist/protocols/google-images.js +8 -37
  61. package/dist/protocols/google-interactions.d.ts +18 -14
  62. package/dist/protocols/google-interactions.js +14 -7
  63. package/dist/protocols/google-speech.d.ts +32 -50
  64. package/dist/protocols/google-speech.js +0 -1
  65. package/dist/protocols/google-transcription.d.ts +32 -50
  66. package/dist/protocols/google-transcription.js +0 -1
  67. package/dist/protocols/google-video.d.ts +1 -1
  68. package/dist/protocols/google-video.js +2 -7
  69. package/dist/protocols/index.d.ts +3 -0
  70. package/dist/protocols/index.js +3 -0
  71. package/dist/protocols/meta-images.d.ts +7 -1
  72. package/dist/protocols/meta-images.js +10 -8
  73. package/dist/protocols/meta-messages.d.ts +73 -38
  74. package/dist/protocols/meta-messages.js +14 -1
  75. package/dist/protocols/meta-responses.d.ts +84 -78
  76. package/dist/protocols/meta-responses.js +29 -1
  77. package/dist/protocols/mistral-chat.d.ts +81 -78
  78. package/dist/protocols/mistral-chat.js +2 -1
  79. package/dist/protocols/open-responses-channel.js +47 -46
  80. package/dist/protocols/open-responses-continuation.d.ts +8 -2
  81. package/dist/protocols/open-responses-continuation.js +3 -1
  82. package/dist/protocols/open-responses.d.ts +426 -396
  83. package/dist/protocols/open-responses.js +16 -25
  84. package/dist/protocols/openai-chat.d.ts +764 -52
  85. package/dist/protocols/openai-chat.js +38 -25
  86. package/dist/protocols/openai-compatible-chat.d.ts +35 -15
  87. package/dist/protocols/openai-compatible-responses.d.ts +44 -42
  88. package/dist/protocols/openai-decisions.d.ts +22 -0
  89. package/dist/protocols/openai-decisions.js +128 -0
  90. package/dist/protocols/openai-images.d.ts +53 -56
  91. package/dist/protocols/openai-images.js +100 -34
  92. package/dist/protocols/openai-responses.d.ts +322 -264
  93. package/dist/protocols/openai-responses.js +33 -3
  94. package/dist/protocols/openai-speech.d.ts +32 -50
  95. package/dist/protocols/openai-speech.js +15 -5
  96. package/dist/protocols/openai-transcription.d.ts +32 -50
  97. package/dist/protocols/openai-transcription.js +15 -11
  98. package/dist/protocols/replicate-images.js +1 -1
  99. package/dist/protocols/runway-video.d.ts +1 -1
  100. package/dist/protocols/runway-video.js +1 -1
  101. package/dist/protocols/shared.d.ts +9 -1
  102. package/dist/protocols/shared.js +13 -2
  103. package/dist/protocols/stability-images.d.ts +5 -0
  104. package/dist/protocols/stability-images.js +4 -9
  105. package/dist/protocols/system-one.d.ts +101 -0
  106. package/dist/protocols/system-one.js +230 -0
  107. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  108. package/dist/protocols/utils/bedrock-cache.js +7 -6
  109. package/dist/protocols/utils/cache.d.ts +14 -3
  110. package/dist/protocols/utils/cache.js +11 -4
  111. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  112. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  113. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  114. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  115. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  116. package/dist/protocols/utils/image-sizing.js +73 -0
  117. package/dist/protocols/utils/media-input.d.ts +4 -5
  118. package/dist/protocols/utils/media-input.js +8 -5
  119. package/dist/protocols/utils/partial-json-options.d.ts +0 -1
  120. package/dist/protocols/utils/partial-json-options.js +0 -1
  121. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  122. package/dist/protocols/utils/speech-stream.js +0 -1
  123. package/dist/protocols/utils/tool-schema.js +15 -5
  124. package/dist/protocols/utils/tool-stream.d.ts +10 -1
  125. package/dist/protocols/venice-chat.d.ts +71 -53
  126. package/dist/protocols/venice-chat.js +7 -6
  127. package/dist/protocols/xai-images.d.ts +1 -2
  128. package/dist/protocols/xai-images.js +9 -2
  129. package/dist/protocols/xai-responses.d.ts +88 -78
  130. package/dist/protocols/xai-responses.js +28 -2
  131. package/dist/protocols/xai-video.d.ts +1 -1
  132. package/dist/protocols/xai-video.js +11 -8
  133. package/dist/protocols/zai-chat.d.ts +54 -30
  134. package/dist/protocols/zai-chat.js +8 -3
  135. package/dist/protocols/zai-images.d.ts +3 -1
  136. package/dist/protocols/zai-images.js +12 -11
  137. package/dist/protocols/zai-messages.d.ts +72 -35
  138. package/dist/protocols/zai-messages.js +3 -2
  139. package/dist/provider-error.js +24 -7
  140. package/dist/providers/alibaba/images.d.ts +2 -0
  141. package/dist/providers/alibaba/images.js +1 -0
  142. package/dist/providers/alibaba.d.ts +146 -85
  143. package/dist/providers/alibaba.js +16 -8
  144. package/dist/providers/amazon-bedrock-mantle.d.ts +277 -218
  145. package/dist/providers/amazon-bedrock.d.ts +48 -28
  146. package/dist/providers/amazon-bedrock.js +11 -11
  147. package/dist/providers/anthropic-compatible.d.ts +64 -29
  148. package/dist/providers/anthropic.d.ts +64 -29
  149. package/dist/providers/azure/images.d.ts +2 -0
  150. package/dist/providers/azure/images.js +1 -0
  151. package/dist/providers/azure.d.ts +156 -115
  152. package/dist/providers/azure.js +19 -1
  153. package/dist/providers/baseten/decisions.d.ts +2 -0
  154. package/dist/providers/baseten/decisions.js +1 -0
  155. package/dist/providers/baseten.d.ts +75 -25
  156. package/dist/providers/baseten.js +41 -8
  157. package/dist/providers/cerebras.d.ts +66 -24
  158. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  159. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  160. package/dist/providers/cloudflare-ai-gateway.d.ts +409 -272
  161. package/dist/providers/cloudflare-ai-gateway.js +33 -6
  162. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  163. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  164. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  165. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  166. package/dist/providers/cloudflare-workers-ai.d.ts +79 -25
  167. package/dist/providers/cloudflare-workers-ai.js +45 -9
  168. package/dist/providers/cohere.d.ts +117 -75
  169. package/dist/providers/deepinfra.d.ts +66 -24
  170. package/dist/providers/deepseek.d.ts +66 -24
  171. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  172. package/dist/providers/digitalocean/decisions.js +1 -0
  173. package/dist/providers/digitalocean/images.d.ts +2 -0
  174. package/dist/providers/digitalocean/images.js +1 -0
  175. package/dist/providers/digitalocean.d.ts +108 -37
  176. package/dist/providers/digitalocean.js +39 -8
  177. package/dist/providers/fireworks.d.ts +66 -24
  178. package/dist/providers/google/images.d.ts +2 -0
  179. package/dist/providers/google/images.js +1 -0
  180. package/dist/providers/google-vertex/images.d.ts +2 -0
  181. package/dist/providers/google-vertex/images.js +1 -0
  182. package/dist/providers/google-vertex-chat.d.ts +33 -12
  183. package/dist/providers/google-vertex-messages.d.ts +64 -29
  184. package/dist/providers/google-vertex-mistral.d.ts +17 -17
  185. package/dist/providers/google-vertex-responses.d.ts +38 -35
  186. package/dist/providers/google-vertex.d.ts +20 -18
  187. package/dist/providers/google-vertex.js +32 -15
  188. package/dist/providers/google.d.ts +22 -21
  189. package/dist/providers/google.js +15 -8
  190. package/dist/providers/groq.d.ts +66 -28
  191. package/dist/providers/groq.js +0 -6
  192. package/dist/providers/meta.d.ts +144 -85
  193. package/dist/providers/minimax.d.ts +145 -86
  194. package/dist/providers/mistral.d.ts +28 -28
  195. package/dist/providers/moonshot.d.ts +277 -218
  196. package/dist/providers/open-responses-options.d.ts +0 -1
  197. package/dist/providers/open-responses-options.js +1 -1
  198. package/dist/providers/openai/images.d.ts +2 -0
  199. package/dist/providers/openai/images.js +1 -0
  200. package/dist/providers/openai-compatible/images.d.ts +2 -0
  201. package/dist/providers/openai-compatible/images.js +1 -0
  202. package/dist/providers/openai-compatible-responses.d.ts +38 -35
  203. package/dist/providers/openai-compatible.d.ts +36 -13
  204. package/dist/providers/openai-compatible.js +22 -10
  205. package/dist/providers/openai-options.d.ts +3 -2
  206. package/dist/providers/openai-options.js +0 -1
  207. package/dist/providers/openai.d.ts +146 -109
  208. package/dist/providers/openai.js +20 -4
  209. package/dist/providers/opencode/decisions.d.ts +2 -0
  210. package/dist/providers/opencode/decisions.js +1 -0
  211. package/dist/providers/opencode.d.ts +9 -10
  212. package/dist/providers/opencode.js +10 -8
  213. package/dist/providers/openrouter/decisions.d.ts +2 -0
  214. package/dist/providers/openrouter/decisions.js +1 -0
  215. package/dist/providers/openrouter/images.d.ts +2 -0
  216. package/dist/providers/openrouter/images.js +1 -0
  217. package/dist/providers/openrouter.d.ts +128 -47
  218. package/dist/providers/openrouter.js +38 -16
  219. package/dist/providers/togetherai.d.ts +66 -24
  220. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  221. package/dist/providers/typesafe-ai/decisions.js +1 -0
  222. package/dist/providers/typesafe-ai.d.ts +9 -10
  223. package/dist/providers/typesafe-ai.js +10 -8
  224. package/dist/providers/venice.d.ts +214 -20
  225. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  226. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  227. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  228. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  229. package/dist/providers/vercel-ai-gateway.d.ts +10 -16
  230. package/dist/providers/vercel-ai-gateway.js +31 -85
  231. package/dist/providers/xai/images.d.ts +2 -0
  232. package/dist/providers/xai/images.js +1 -0
  233. package/dist/providers/xai.d.ts +40 -17
  234. package/dist/providers/xai.js +15 -8
  235. package/dist/providers/zai/images.d.ts +2 -0
  236. package/dist/providers/zai/images.js +1 -0
  237. package/dist/providers/zai-coding-plan.d.ts +224 -85
  238. package/dist/providers/zai.d.ts +110 -23
  239. package/dist/providers/zai.js +15 -8
  240. package/dist/route/auth-options.d.ts +0 -3
  241. package/dist/route/auth.d.ts +0 -2
  242. package/dist/route/auth.js +0 -2
  243. package/dist/route/client.d.ts +2 -4
  244. package/dist/route/client.js +29 -8
  245. package/dist/route/decision.d.ts +58 -0
  246. package/dist/route/decision.js +75 -0
  247. package/dist/route/executor-service.js +1 -1
  248. package/dist/route/executor.d.ts +1 -1
  249. package/dist/route/framing.d.ts +2 -0
  250. package/dist/route/index.d.ts +3 -0
  251. package/dist/route/index.js +3 -0
  252. package/dist/route/media-protocol.d.ts +1 -0
  253. package/dist/route/media-protocol.js +12 -8
  254. package/dist/route/media.d.ts +5 -1
  255. package/dist/route/media.js +6 -2
  256. package/dist/route/transport/http.js +1 -0
  257. package/dist/route/transport/index.d.ts +1 -0
  258. package/dist/schema/events.d.ts +148 -6
  259. package/dist/schema/events.js +20 -0
  260. package/dist/schema/messages.d.ts +6 -2
  261. package/dist/schema/messages.js +3 -0
  262. package/dist/schema/options.d.ts +5 -3
  263. package/dist/schema/options.js +8 -3
  264. package/dist/speech-client.d.ts +13 -22
  265. package/dist/speech-client.js +0 -1
  266. package/dist/speech.d.ts +148 -283
  267. package/dist/speech.js +2 -4
  268. package/dist/testing.d.ts +25 -24
  269. package/dist/testing.js +3 -21
  270. package/dist/transcription-client.d.ts +13 -22
  271. package/dist/transcription.d.ts +148 -283
  272. package/dist/transcription.js +1 -1
  273. package/dist/utils/media-type.js +22 -1
  274. package/dist/video-client.d.ts +13 -22
  275. package/dist/video-client.js +0 -1
  276. package/dist/video.d.ts +115 -250
  277. package/dist/video.js +3 -5
  278. package/package.json +516 -13
  279. package/dist/experimental/evaluation-client.d.ts +0 -21
  280. package/dist/experimental/evaluation-client.js +0 -64
  281. package/dist/experimental/evaluation.d.ts +0 -242
  282. package/dist/experimental/evaluation.js +0 -115
  283. package/dist/experimental/system-one.d.ts +0 -16
  284. package/dist/experimental/system-one.js +0 -135
  285. package/dist/promise.d.ts +0 -1021
  286. package/dist/promise.js +0 -101
  287. package/dist/provider.d.ts +0 -23
  288. package/dist/provider.js +0 -2
@@ -16,14 +16,6 @@ export type DeepgramSpeechOptions = {
16
16
  } & Record<string, unknown>;
17
17
  export type Request = SpeechRequestFor<DeepgramSpeechOptions>;
18
18
  export declare const protocol: MediaProtocol.Streamed<Request, {
19
- readonly type: "generation-queued";
20
- readonly id: string;
21
- readonly position?: number | undefined;
22
- } | {
23
- readonly type: "generation-progress";
24
- readonly id: string;
25
- readonly progress?: number | undefined;
26
- } | {
27
19
  readonly type: "audio-delta";
28
20
  readonly chunk: Uint8Array<ArrayBufferLike>;
29
21
  } | {
@@ -33,18 +25,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
33
25
  readonly startSeconds: number;
34
26
  readonly endSeconds: number;
35
27
  }[];
28
+ } | {
29
+ readonly type: "generation-queued";
30
+ readonly id: string;
31
+ readonly position?: number | undefined;
32
+ } | {
33
+ readonly type: "generation-progress";
34
+ readonly id: string;
35
+ readonly progress?: number | undefined;
36
36
  } | {
37
37
  readonly type: "finish";
38
38
  readonly audio: import("../media.js").Asset;
39
39
  readonly usage?: {
40
- readonly type: "tokens";
41
- readonly input?: number | undefined;
42
- readonly output?: number | undefined;
43
- readonly total?: number | undefined;
44
- readonly details?: {
45
- readonly [x: string]: unknown;
46
- } | undefined;
47
- } | {
48
40
  readonly type: "seconds";
49
41
  readonly seconds: number;
50
42
  } | {
@@ -56,16 +48,15 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
56
48
  } | {
57
49
  readonly type: "compute";
58
50
  readonly seconds: number;
59
- } | undefined;
60
- readonly notices?: readonly {
61
- readonly type: "filtered" | "moderated" | "other";
62
- readonly message: string;
63
- readonly providerMetadata?: {
64
- readonly [x: string]: {
65
- readonly [x: string]: unknown;
66
- };
51
+ } | {
52
+ readonly type: "tokens";
53
+ readonly input?: number | undefined;
54
+ readonly output?: number | undefined;
55
+ readonly total?: number | undefined;
56
+ readonly details?: {
57
+ readonly [x: string]: unknown;
67
58
  } | undefined;
68
- }[] | undefined;
59
+ } | undefined;
69
60
  readonly providerMetadata?: {
70
61
  readonly [x: string]: {
71
62
  readonly [x: string]: unknown;
@@ -75,14 +66,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
75
66
  export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<DeepgramSpeechOptions>;
76
67
  export declare const DeepgramSpeech: {
77
68
  readonly protocol: MediaProtocol.Streamed<Request, {
78
- readonly type: "generation-queued";
79
- readonly id: string;
80
- readonly position?: number | undefined;
81
- } | {
82
- readonly type: "generation-progress";
83
- readonly id: string;
84
- readonly progress?: number | undefined;
85
- } | {
86
69
  readonly type: "audio-delta";
87
70
  readonly chunk: Uint8Array<ArrayBufferLike>;
88
71
  } | {
@@ -92,18 +75,18 @@ export declare const DeepgramSpeech: {
92
75
  readonly startSeconds: number;
93
76
  readonly endSeconds: number;
94
77
  }[];
78
+ } | {
79
+ readonly type: "generation-queued";
80
+ readonly id: string;
81
+ readonly position?: number | undefined;
82
+ } | {
83
+ readonly type: "generation-progress";
84
+ readonly id: string;
85
+ readonly progress?: number | undefined;
95
86
  } | {
96
87
  readonly type: "finish";
97
88
  readonly audio: import("../media.js").Asset;
98
89
  readonly usage?: {
99
- readonly type: "tokens";
100
- readonly input?: number | undefined;
101
- readonly output?: number | undefined;
102
- readonly total?: number | undefined;
103
- readonly details?: {
104
- readonly [x: string]: unknown;
105
- } | undefined;
106
- } | {
107
90
  readonly type: "seconds";
108
91
  readonly seconds: number;
109
92
  } | {
@@ -115,16 +98,15 @@ export declare const DeepgramSpeech: {
115
98
  } | {
116
99
  readonly type: "compute";
117
100
  readonly seconds: number;
118
- } | undefined;
119
- readonly notices?: readonly {
120
- readonly type: "filtered" | "moderated" | "other";
121
- readonly message: string;
122
- readonly providerMetadata?: {
123
- readonly [x: string]: {
124
- readonly [x: string]: unknown;
125
- };
101
+ } | {
102
+ readonly type: "tokens";
103
+ readonly input?: number | undefined;
104
+ readonly output?: number | undefined;
105
+ readonly total?: number | undefined;
106
+ readonly details?: {
107
+ readonly [x: string]: unknown;
126
108
  } | undefined;
127
- }[] | undefined;
109
+ } | undefined;
128
110
  readonly providerMetadata?: {
129
111
  readonly [x: string]: {
130
112
  readonly [x: string]: unknown;
@@ -19,14 +19,6 @@ export type ElevenLabsSpeechOptions = {
19
19
  } & Record<string, unknown>;
20
20
  export type Request = SpeechRequestFor<ElevenLabsSpeechOptions>;
21
21
  export declare const protocol: MediaProtocol.Streamed<Request, {
22
- readonly type: "generation-queued";
23
- readonly id: string;
24
- readonly position?: number | undefined;
25
- } | {
26
- readonly type: "generation-progress";
27
- readonly id: string;
28
- readonly progress?: number | undefined;
29
- } | {
30
22
  readonly type: "audio-delta";
31
23
  readonly chunk: Uint8Array<ArrayBufferLike>;
32
24
  } | {
@@ -36,18 +28,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
36
28
  readonly startSeconds: number;
37
29
  readonly endSeconds: number;
38
30
  }[];
31
+ } | {
32
+ readonly type: "generation-queued";
33
+ readonly id: string;
34
+ readonly position?: number | undefined;
35
+ } | {
36
+ readonly type: "generation-progress";
37
+ readonly id: string;
38
+ readonly progress?: number | undefined;
39
39
  } | {
40
40
  readonly type: "finish";
41
41
  readonly audio: import("../media.js").Asset;
42
42
  readonly usage?: {
43
- readonly type: "tokens";
44
- readonly input?: number | undefined;
45
- readonly output?: number | undefined;
46
- readonly total?: number | undefined;
47
- readonly details?: {
48
- readonly [x: string]: unknown;
49
- } | undefined;
50
- } | {
51
43
  readonly type: "seconds";
52
44
  readonly seconds: number;
53
45
  } | {
@@ -59,16 +51,15 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
59
51
  } | {
60
52
  readonly type: "compute";
61
53
  readonly seconds: number;
62
- } | undefined;
63
- readonly notices?: readonly {
64
- readonly type: "filtered" | "moderated" | "other";
65
- readonly message: string;
66
- readonly providerMetadata?: {
67
- readonly [x: string]: {
68
- readonly [x: string]: unknown;
69
- };
54
+ } | {
55
+ readonly type: "tokens";
56
+ readonly input?: number | undefined;
57
+ readonly output?: number | undefined;
58
+ readonly total?: number | undefined;
59
+ readonly details?: {
60
+ readonly [x: string]: unknown;
70
61
  } | undefined;
71
- }[] | undefined;
62
+ } | undefined;
72
63
  readonly providerMetadata?: {
73
64
  readonly [x: string]: {
74
65
  readonly [x: string]: unknown;
@@ -78,14 +69,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
78
69
  export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<ElevenLabsSpeechOptions>;
79
70
  export declare const ElevenLabsSpeech: {
80
71
  readonly protocol: MediaProtocol.Streamed<Request, {
81
- readonly type: "generation-queued";
82
- readonly id: string;
83
- readonly position?: number | undefined;
84
- } | {
85
- readonly type: "generation-progress";
86
- readonly id: string;
87
- readonly progress?: number | undefined;
88
- } | {
89
72
  readonly type: "audio-delta";
90
73
  readonly chunk: Uint8Array<ArrayBufferLike>;
91
74
  } | {
@@ -95,18 +78,18 @@ export declare const ElevenLabsSpeech: {
95
78
  readonly startSeconds: number;
96
79
  readonly endSeconds: number;
97
80
  }[];
81
+ } | {
82
+ readonly type: "generation-queued";
83
+ readonly id: string;
84
+ readonly position?: number | undefined;
85
+ } | {
86
+ readonly type: "generation-progress";
87
+ readonly id: string;
88
+ readonly progress?: number | undefined;
98
89
  } | {
99
90
  readonly type: "finish";
100
91
  readonly audio: import("../media.js").Asset;
101
92
  readonly usage?: {
102
- readonly type: "tokens";
103
- readonly input?: number | undefined;
104
- readonly output?: number | undefined;
105
- readonly total?: number | undefined;
106
- readonly details?: {
107
- readonly [x: string]: unknown;
108
- } | undefined;
109
- } | {
110
93
  readonly type: "seconds";
111
94
  readonly seconds: number;
112
95
  } | {
@@ -118,16 +101,15 @@ export declare const ElevenLabsSpeech: {
118
101
  } | {
119
102
  readonly type: "compute";
120
103
  readonly seconds: number;
121
- } | undefined;
122
- readonly notices?: readonly {
123
- readonly type: "filtered" | "moderated" | "other";
124
- readonly message: string;
125
- readonly providerMetadata?: {
126
- readonly [x: string]: {
127
- readonly [x: string]: unknown;
128
- };
104
+ } | {
105
+ readonly type: "tokens";
106
+ readonly input?: number | undefined;
107
+ readonly output?: number | undefined;
108
+ readonly total?: number | undefined;
109
+ readonly details?: {
110
+ readonly [x: string]: unknown;
129
111
  } | undefined;
130
- }[] | undefined;
112
+ } | undefined;
131
113
  readonly providerMetadata?: {
132
114
  readonly [x: string]: {
133
115
  readonly [x: string]: unknown;
@@ -1,9 +1,18 @@
1
1
  import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
2
+ import { Media } from "../media.js";
2
3
  import { MediaProtocol } from "../route/media-protocol.js";
3
4
  import { MediaRoute } from "../route/media.js";
4
5
  import { type OpenString } from "../schema/index.js";
6
+ /** Model-defined `input` fields; `aspect` and `resolution` lower to `image_size` or `aspect_ratio` per model. */
5
7
  export type FalImageOptions = {
6
- readonly image_size?: OpenString<"square_hd" | "square" | "portrait_4_3" | "portrait_16_9" | "landscape_4_3" | "landscape_16_9">;
8
+ readonly image_size?: OpenString<"square_hd" | "square" | "portrait_4_3" | "portrait_16_9" | "landscape_4_3" | "landscape_16_9"> | {
9
+ readonly width: number;
10
+ readonly height: number;
11
+ };
12
+ readonly seed?: number;
13
+ readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
14
+ /** Inpainting mask, sent as `mask_url`. */
15
+ readonly mask?: Media.Asset;
7
16
  readonly enable_safety_checker?: boolean;
8
17
  } & Record<string, unknown>;
9
18
  export type Request = ImageRequestFor<FalImageOptions>;
@@ -4,9 +4,9 @@ import { Media } from "../media.js";
4
4
  import { MediaProtocol } from "../route/media-protocol.js";
5
5
  import { MediaRoute } from "../route/media.js";
6
6
  import { mergeJsonRecords } from "../schema/index.js";
7
- import { ProviderShared, optionalNull } from "./shared.js";
7
+ import { optionalNull } from "./shared.js";
8
8
  import { FalQueue } from "./utils/fal-queue.js";
9
- import { MediaInput } from "./utils/media-input.js";
9
+ import { ImageSizing } from "./utils/image-sizing.js";
10
10
  const route = MediaProtocol.identity({ id: "fal-images", name: "fal Images", provider: "fal" });
11
11
  // ---------------------------------------------------------------------------
12
12
  // 2. Response schema
@@ -24,8 +24,11 @@ const QueueResult = Schema.StructWithRest(Schema.Struct({
24
24
  // ---------------------------------------------------------------------------
25
25
  // 5. Request body construction
26
26
  // ---------------------------------------------------------------------------
27
+ /** Nano Banana takes `aspect_ratio` and `resolution` tiers, FLUX Ultra and Kontext only `aspect_ratio`, FLUX `image_size`. */
27
28
  const sizing = (model) => {
28
- if (/^fal-ai\/(nano-banana|flux-pro\/(v1\.1-ultra|kontext))/.test(model))
29
+ if (model.startsWith("fal-ai/nano-banana"))
30
+ return "tiers";
31
+ if (/^fal-ai\/flux-pro\/(v1\.1-ultra|kontext)/.test(model))
29
32
  return "aspect_ratio";
30
33
  if (model.startsWith("fal-ai/flux"))
31
34
  return "image_size";
@@ -33,13 +36,8 @@ const sizing = (model) => {
33
36
  };
34
37
  const validate = (request) => {
35
38
  const id = request.model.id;
36
- const field = sizing(id);
37
- if (request.size !== undefined && request.aspectRatio !== undefined)
38
- return Effect.fail(ProviderShared.invalidRequest(`${route.name} accepts either size or aspectRatio, not both`));
39
- if (request.size !== undefined && field === "aspect_ratio")
40
- return Effect.fail(route.unsupported("media.size", `${id} sizes by aspectRatio`));
41
- if (request.aspectRatio !== undefined && field === "image_size")
42
- return Effect.fail(route.unsupported("media.aspectRatio", `${id} sizes by size (image_size)`));
39
+ if (request.resolution !== undefined && sizing(id) === "aspect_ratio")
40
+ return Effect.fail(route.unsupported("media.resolution", `${id} sizes by aspect only`));
43
41
  if ((request.images?.length ?? 0) > 1 && !takesImageList(id))
44
42
  return Effect.fail(route.unsupported("media.images", `${id} takes one image_url; use an /edit or /multi endpoint for several images`));
45
43
  return Effect.void;
@@ -51,17 +49,18 @@ const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
51
49
  yield* validate(request);
52
50
  const images = yield* Effect.forEach(request.images ?? [], (image) => FalQueue.mediaUrl(image, route.name));
53
51
  const list = takesImageList(request.model.id);
52
+ const { mask, ...native } = request.providerOptions ?? {};
53
+ const field = sizing(request.model.id);
54
54
  return MediaProtocol.json(mergeJsonRecords({
55
55
  prompt: request.prompt,
56
56
  num_images: request.n,
57
- seed: request.seed,
58
- image_size: request.size === undefined ? undefined : MediaInput.dimensions(request.size),
59
- aspect_ratio: request.aspectRatio,
60
- output_format: request.format,
57
+ ...(field === "image_size"
58
+ ? { image_size: yield* ImageSizing.exact(route, request, { multiple: 16 }) }
59
+ : { aspect_ratio: request.aspect, resolution: request.resolution }),
61
60
  image_urls: list && images.length > 0 ? images : undefined,
62
61
  image_url: list ? undefined : images[0],
63
- mask_url: request.mask === undefined ? undefined : yield* FalQueue.mediaUrl(request.mask, route.name),
64
- }, request.providerOptions, request.http?.body) ?? {});
62
+ mask_url: mask === undefined ? undefined : yield* FalQueue.mediaUrl(mask, route.name),
63
+ }, native, request.http?.body) ?? {});
65
64
  });
66
65
  // ---------------------------------------------------------------------------
67
66
  // 6. Response decoding
@@ -69,11 +68,9 @@ const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
69
68
  const decodeQueueResult = route.decodeJson(QueueResult);
70
69
  const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, context) {
71
70
  const output = yield* decodeQueueResult(response);
72
- const { images, seed, has_nsfw_concepts, ...rest } = output.value;
71
+ const { images, seed, ...rest } = output.value;
73
72
  if (images.length === 0)
74
73
  return yield* output.invalid(`${route.name} returned no images`);
75
- // With the safety checker on, flagged images come back blacked out rather than omitted.
76
- const flagged = (has_nsfw_concepts ?? []).flatMap((value, index) => (value ? [index] : []));
77
74
  return new ImageResponse({
78
75
  images: images.map((image) => {
79
76
  const info = { width: image.width ?? undefined, height: image.height ?? undefined };
@@ -81,12 +78,6 @@ const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, co
81
78
  return (Media.parseDataUrl(image.url, { info }) ??
82
79
  Media.url(image.url, { mediaType: image.content_type ?? undefined, info }));
83
80
  }),
84
- notices: flagged.length === 0
85
- ? undefined
86
- : flagged.map((index) => ({
87
- type: "moderated",
88
- message: `${route.name} flagged image ${index} as NSFW`,
89
- })),
90
81
  providerMetadata: { fal: { requestId: context.token.requestID, seed: seed ?? undefined, ...rest } },
91
82
  });
92
83
  });
@@ -31,7 +31,7 @@ const fromRequest = Effect.fn("FalVideo.fromRequest")(function* (request) {
31
31
  prompt: request.prompt,
32
32
  negative_prompt: request.negativePrompt,
33
33
  seed: request.seed,
34
- aspect_ratio: request.aspectRatio,
34
+ aspect_ratio: request.aspect,
35
35
  resolution: request.resolution,
36
36
  generate_audio: request.audio,
37
37
  image_url: imageUrl,
@@ -105,6 +105,7 @@ declare const GeminiBody: Schema.Struct<{
105
105
  }>;
106
106
  export type GeminiBody = Schema.Schema.Type<typeof GeminiBody>;
107
107
  declare const GeminiUsage: Schema.Struct<{
108
+ readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
108
109
  readonly cachedContentTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
109
110
  readonly thoughtsTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
110
111
  readonly promptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
@@ -158,27 +159,10 @@ export declare const protocol: Protocol<{
158
159
  readonly contents: readonly {
159
160
  readonly role?: "model" | "user" | null | undefined;
160
161
  readonly parts?: readonly ({
161
- readonly inlineData: {
162
- readonly mimeType: string;
163
- readonly data: string;
164
- };
165
- readonly thoughtSignature?: string | null | undefined;
166
- } | {
167
- readonly text: string;
168
- readonly thought?: boolean | null | undefined;
169
- readonly thoughtSignature?: string | null | undefined;
170
- } | {
171
162
  readonly fileData: {
172
163
  readonly mimeType: string;
173
164
  readonly fileUri: string;
174
165
  };
175
- } | {
176
- readonly functionCall: {
177
- readonly id?: string | null | undefined;
178
- readonly name: string;
179
- readonly args?: unknown;
180
- };
181
- readonly thoughtSignature?: string | null | undefined;
182
166
  } | {
183
167
  readonly functionResponse: {
184
168
  readonly id?: string | undefined;
@@ -192,6 +176,23 @@ export declare const protocol: Protocol<{
192
176
  readonly thoughtSignature?: string | null | undefined;
193
177
  }[] | undefined;
194
178
  };
179
+ } | {
180
+ readonly text: string;
181
+ readonly thought?: boolean | null | undefined;
182
+ readonly thoughtSignature?: string | null | undefined;
183
+ } | {
184
+ readonly inlineData: {
185
+ readonly mimeType: string;
186
+ readonly data: string;
187
+ };
188
+ readonly thoughtSignature?: string | null | undefined;
189
+ } | {
190
+ readonly functionCall: {
191
+ readonly id?: string | null | undefined;
192
+ readonly name: string;
193
+ readonly args?: unknown;
194
+ };
195
+ readonly thoughtSignature?: string | null | undefined;
195
196
  })[] | null | undefined;
196
197
  }[];
197
198
  readonly labels?: {
@@ -259,6 +260,7 @@ export declare const protocol: Protocol<{
259
260
  readonly safetyRatings?: unknown;
260
261
  } | null | undefined;
261
262
  readonly usageMetadata?: {
263
+ readonly cost?: number | undefined;
262
264
  readonly cachedContentTokenCount?: number | null | undefined;
263
265
  readonly thoughtsTokenCount?: number | null | undefined;
264
266
  readonly promptTokenCount?: number | null | undefined;
@@ -286,6 +288,7 @@ export declare const protocol: Protocol<{
286
288
  readonly safetyRatings?: unknown;
287
289
  } | null | undefined;
288
290
  readonly usageMetadata?: {
291
+ readonly cost?: number | undefined;
289
292
  readonly cachedContentTokenCount?: number | null | undefined;
290
293
  readonly thoughtsTokenCount?: number | null | undefined;
291
294
  readonly promptTokenCount?: number | null | undefined;
@@ -298,27 +301,10 @@ export declare const route: Route<{
298
301
  readonly contents: readonly {
299
302
  readonly role?: "model" | "user" | null | undefined;
300
303
  readonly parts?: readonly ({
301
- readonly inlineData: {
302
- readonly mimeType: string;
303
- readonly data: string;
304
- };
305
- readonly thoughtSignature?: string | null | undefined;
306
- } | {
307
- readonly text: string;
308
- readonly thought?: boolean | null | undefined;
309
- readonly thoughtSignature?: string | null | undefined;
310
- } | {
311
304
  readonly fileData: {
312
305
  readonly mimeType: string;
313
306
  readonly fileUri: string;
314
307
  };
315
- } | {
316
- readonly functionCall: {
317
- readonly id?: string | null | undefined;
318
- readonly name: string;
319
- readonly args?: unknown;
320
- };
321
- readonly thoughtSignature?: string | null | undefined;
322
308
  } | {
323
309
  readonly functionResponse: {
324
310
  readonly id?: string | undefined;
@@ -332,6 +318,23 @@ export declare const route: Route<{
332
318
  readonly thoughtSignature?: string | null | undefined;
333
319
  }[] | undefined;
334
320
  };
321
+ } | {
322
+ readonly text: string;
323
+ readonly thought?: boolean | null | undefined;
324
+ readonly thoughtSignature?: string | null | undefined;
325
+ } | {
326
+ readonly inlineData: {
327
+ readonly mimeType: string;
328
+ readonly data: string;
329
+ };
330
+ readonly thoughtSignature?: string | null | undefined;
331
+ } | {
332
+ readonly functionCall: {
333
+ readonly id?: string | null | undefined;
334
+ readonly name: string;
335
+ readonly args?: unknown;
336
+ };
337
+ readonly thoughtSignature?: string | null | undefined;
335
338
  })[] | null | undefined;
336
339
  }[];
337
340
  readonly labels?: {
@@ -59,7 +59,6 @@ const GeminiInlineDataPart = Schema.Struct({
59
59
  }),
60
60
  thoughtSignature: optionalNull(Schema.String),
61
61
  });
62
- /** Gemini Files API reference; the only remote input Gemini accepts. */
63
62
  const GeminiFileDataPart = Schema.Struct({
64
63
  fileData: Schema.Struct({
65
64
  mimeType: Schema.String,
@@ -172,6 +171,7 @@ const GeminiUsage = Schema.Struct({
172
171
  promptTokenCount: optionalNull(Schema.Number),
173
172
  candidatesTokenCount: optionalNull(Schema.Number),
174
173
  totalTokenCount: optionalNull(Schema.Number),
174
+ ...ProviderShared.ReportedBilling.fields,
175
175
  });
176
176
  const GeminiCandidate = Schema.Struct({
177
177
  content: optionalNull(GeminiResponseContent),
@@ -224,7 +224,7 @@ const lowerToolCall = (part, omitIds, metadataKey) => ({
224
224
  });
225
225
  const lowerMessages = Effect.fnUntraced(function* (request) {
226
226
  const contents = [];
227
- const metadataKey = request.model.route.providerMetadataKey ?? String(request.model.provider);
227
+ const metadataKey = request.model.route.providerMetadataKey ?? request.model.provider;
228
228
  const omitCallIds = omitsFunctionCallIds(request.model.id);
229
229
  const legacyToolMedia = routesLegacyToolMedia(request.model.id);
230
230
  let pendingMedia;
@@ -329,11 +329,13 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
329
329
  for (const item of content) {
330
330
  if (item.type === "text")
331
331
  continue;
332
- const value = yield* ProviderShared.requireInlineMedia("Gemini", ProviderShared.toolFileMedia(item).media);
333
- media.push({ inlineData: { mimeType: value.mime, data: value.base64 } });
332
+ const value = yield* GeminiGenerateContent.mediaPart("Gemini", GeminiGenerateContent.toolMedia(item));
333
+ // Nested fileData can be accepted without the model seeing the video, even on newer Gemini models.
334
+ if (legacyToolMedia || "fileData" in value)
335
+ (pendingMedia ??= []).push(value);
336
+ else
337
+ media.push(value);
334
338
  }
335
- if (legacyToolMedia && media.length > 0)
336
- (pendingMedia ??= []).push(...media);
337
339
  parts.push({
338
340
  functionResponse: {
339
341
  ...(omitCallIds ? {} : { id: part.id }),
@@ -342,7 +344,7 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
342
344
  name: part.name,
343
345
  content: text.join("\n"),
344
346
  },
345
- parts: legacyToolMedia || media.length === 0 ? undefined : media,
347
+ parts: media.length === 0 ? undefined : media,
346
348
  },
347
349
  });
348
350
  }
@@ -430,6 +432,7 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
430
432
  cacheReadInputTokens: cached,
431
433
  reasoningTokens: thoughts,
432
434
  totalTokens: ProviderShared.totalTokens(promptTokens, outputTokens, usage.totalTokenCount ?? undefined),
435
+ cost: usage.cost,
433
436
  providerMetadata: providerMetadata(metadataKey, metadata),
434
437
  });
435
438
  };
@@ -443,6 +446,8 @@ const mapContinuedUsage = (requests, metadataKey) => {
443
446
  cachedContentTokenCount: requests[0].cachedContentTokenCount,
444
447
  candidatesTokenCount: sum("candidatesTokenCount"),
445
448
  thoughtsTokenCount: sum("thoughtsTokenCount"),
449
+ // Every continued request is billed on its own.
450
+ cost: sum("cost"),
446
451
  }, metadataKey, {
447
452
  promptTokenCount: sum("promptTokenCount"),
448
453
  cachedContentTokenCount: sum("cachedContentTokenCount"),
@@ -750,7 +755,7 @@ export const protocol = Protocol.make({
750
755
  event: Schema.Union([Schema.instanceOf(NextRequest), GeminiEvent]),
751
756
  initial: (request) => ({
752
757
  route: `${request.model.provider}/${request.model.route.id}`,
753
- providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
758
+ providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
754
759
  hasToolCalls: false,
755
760
  lifecycle: Lifecycle.initial(),
756
761
  nextReasoningId: 0,
@@ -3,9 +3,9 @@ import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
5
5
  export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
6
- /** Provider-native options. Common fields (`aspectRatio`, `seed`, `images`) live on the request. */
6
+ /** Provider-native `generationConfig` fields. Common fields (`aspect`, `resolution`, `images`) live on the request. */
7
7
  export type GoogleImageOptions = {
8
- readonly imageSize?: OpenString<"1K" | "2K" | "4K">;
8
+ readonly seed?: number;
9
9
  readonly thinkingLevel?: OpenString<"MINIMAL" | "LOW" | "MEDIUM" | "HIGH">;
10
10
  readonly includeThoughts?: boolean;
11
11
  } & Record<string, unknown>;