@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
@@ -3,8 +3,9 @@ import { ImageModel, ImageResponse } from "../image.js";
3
3
  import { Media } from "../media.js";
4
4
  import { MediaProtocol } from "../route/media-protocol.js";
5
5
  import { MediaRoute } from "../route/media.js";
6
- import { mergeJsonRecords } from "../schema/index.js";
6
+ import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
7
7
  import { JsonObject, ProviderShared, optionalNull } from "./shared.js";
8
+ import { ImageSizing } from "./utils/image-sizing.js";
8
9
  import { MediaInput } from "./utils/media-input.js";
9
10
  const route = MediaProtocol.identity({ id: "meta-images", name: "Meta Images", provider: "meta" });
10
11
  export const DEFAULT_BASE_URL = "https://api.meta.ai/v1";
@@ -40,14 +41,17 @@ const isEdit = (request) => (request.images?.length ?? 0) > 0;
40
41
  const reference = (asset) => ProviderShared.mediaReference(asset, undefined, route.name).pipe(Effect.map((item) => ({ image_url: item.value })));
41
42
  const fromRequest = Effect.fn("MetaImages.fromRequest")(function* (request) {
42
43
  const images = yield* Effect.forEach(request.images ?? [], reference);
43
- const { responseFormat, reasoningStrength, toolEnablement, ...native } = request.providerOptions ?? {};
44
+ const { outputFormat, responseFormat, reasoningStrength, toolEnablement, ...native } = request.providerOptions ?? {};
45
+ if (native.size !== undefined && request.aspect !== undefined)
46
+ return yield* ProviderShared.invalidRequest("Meta providerOptions.size replaces aspect; set one or the other");
47
+ const hint = request.aspect === undefined ? undefined : ImageSizing.fit({ aspect: request.aspect }, { multiple: 16 });
44
48
  const payload = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
45
49
  model: request.model.id,
46
50
  prompt: request.prompt,
47
51
  images: images.length === 0 ? undefined : images,
48
52
  n: request.n,
49
- size: request.size,
50
- output_format: request.format,
53
+ size: hint === undefined ? undefined : `${hint.width}x${hint.height}`,
54
+ output_format: outputFormat,
51
55
  response_format: responseFormat,
52
56
  reasoning_strength: reasoningStrength,
53
57
  tool_enablement: toolEnablement,
@@ -73,13 +77,12 @@ const decodeResponse = Effect.fn("MetaImages.decodeResponse")(function* (respons
73
77
  images,
74
78
  usage: decoded.usage === undefined
75
79
  ? undefined
76
- : {
77
- type: "tokens",
80
+ : tokenUsage({
78
81
  input: decoded.usage.input_tokens,
79
82
  output: decoded.usage.output_tokens,
80
83
  total: decoded.usage.total_tokens,
81
84
  details: { meta: decoded.usage },
82
- },
85
+ }),
83
86
  providerMetadata: { meta: { outputFormat: format } },
84
87
  });
85
88
  });
@@ -87,7 +90,6 @@ const decodeResponse = Effect.fn("MetaImages.decodeResponse")(function* (respons
87
90
  // 7. Protocol and route
88
91
  // ---------------------------------------------------------------------------
89
92
  export const protocol = MediaProtocol.inline(route, {
90
- unsupported: ["mask", "aspectRatio", "seed"],
91
93
  body: { from: fromRequest },
92
94
  response: { decode: decodeResponse },
93
95
  });
@@ -17,7 +17,7 @@ export declare const protocol: Protocol<{
17
17
  readonly text: string;
18
18
  readonly cache_control?: {
19
19
  readonly type: "ephemeral";
20
- readonly ttl?: "1h" | "5m" | undefined;
20
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
21
21
  } | undefined;
22
22
  }[] | undefined;
23
23
  readonly messages: readonly ({
@@ -27,7 +27,7 @@ export declare const protocol: Protocol<{
27
27
  readonly text: string;
28
28
  readonly cache_control?: {
29
29
  readonly type: "ephemeral";
30
- readonly ttl?: "1h" | "5m" | undefined;
30
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
31
31
  } | undefined;
32
32
  } | {
33
33
  readonly type: "image";
@@ -44,11 +44,28 @@ export declare const protocol: Protocol<{
44
44
  };
45
45
  readonly cache_control?: {
46
46
  readonly type: "ephemeral";
47
- readonly ttl?: "1h" | "5m" | undefined;
47
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
48
48
  } | undefined;
49
49
  readonly transformations?: {
50
50
  readonly oversized_image?: "downsize" | "error" | undefined;
51
51
  } | undefined;
52
+ } | {
53
+ readonly type: "video";
54
+ readonly source: {
55
+ readonly type: "base64";
56
+ readonly media_type: string;
57
+ readonly data: string;
58
+ } | {
59
+ readonly type: "url";
60
+ readonly url: string;
61
+ } | {
62
+ readonly type: "file";
63
+ readonly file_id: string;
64
+ };
65
+ readonly cache_control?: {
66
+ readonly type: "ephemeral";
67
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
68
+ } | undefined;
52
69
  } | {
53
70
  readonly type: "document";
54
71
  readonly source: {
@@ -68,7 +85,7 @@ export declare const protocol: Protocol<{
68
85
  };
69
86
  readonly cache_control?: {
70
87
  readonly type: "ephemeral";
71
- readonly ttl?: "1h" | "5m" | undefined;
88
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
72
89
  } | undefined;
73
90
  readonly title?: string | undefined;
74
91
  readonly context?: string | undefined;
@@ -83,7 +100,7 @@ export declare const protocol: Protocol<{
83
100
  readonly text: string;
84
101
  readonly cache_control?: {
85
102
  readonly type: "ephemeral";
86
- readonly ttl?: "1h" | "5m" | undefined;
103
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
87
104
  } | undefined;
88
105
  } | {
89
106
  readonly type: "image";
@@ -100,11 +117,28 @@ export declare const protocol: Protocol<{
100
117
  };
101
118
  readonly cache_control?: {
102
119
  readonly type: "ephemeral";
103
- readonly ttl?: "1h" | "5m" | undefined;
120
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
104
121
  } | undefined;
105
122
  readonly transformations?: {
106
123
  readonly oversized_image?: "downsize" | "error" | undefined;
107
124
  } | undefined;
125
+ } | {
126
+ readonly type: "video";
127
+ readonly source: {
128
+ readonly type: "base64";
129
+ readonly media_type: string;
130
+ readonly data: string;
131
+ } | {
132
+ readonly type: "url";
133
+ readonly url: string;
134
+ } | {
135
+ readonly type: "file";
136
+ readonly file_id: string;
137
+ };
138
+ readonly cache_control?: {
139
+ readonly type: "ephemeral";
140
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
141
+ } | undefined;
108
142
  } | {
109
143
  readonly type: "document";
110
144
  readonly source: {
@@ -124,7 +158,7 @@ export declare const protocol: Protocol<{
124
158
  };
125
159
  readonly cache_control?: {
126
160
  readonly type: "ephemeral";
127
- readonly ttl?: "1h" | "5m" | undefined;
161
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
128
162
  } | undefined;
129
163
  readonly title?: string | undefined;
130
164
  readonly context?: string | undefined;
@@ -135,43 +169,35 @@ export declare const protocol: Protocol<{
135
169
  readonly is_error?: boolean | undefined;
136
170
  readonly cache_control?: {
137
171
  readonly type: "ephemeral";
138
- readonly ttl?: "1h" | "5m" | undefined;
172
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
139
173
  } | undefined;
140
174
  })[];
141
175
  } | {
142
176
  readonly role: "assistant";
143
177
  readonly content: readonly ({
178
+ readonly type: "compaction";
179
+ readonly content: string | null;
180
+ } | {
144
181
  readonly type: "text";
145
182
  readonly text: string;
146
183
  readonly cache_control?: {
147
184
  readonly type: "ephemeral";
148
- readonly ttl?: "1h" | "5m" | undefined;
149
- } | undefined;
150
- } | {
151
- readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
152
- readonly tool_use_id: string;
153
- readonly content: unknown;
154
- readonly cache_control?: {
155
- readonly type: "ephemeral";
156
- readonly ttl?: "1h" | "5m" | undefined;
185
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
157
186
  } | undefined;
158
- } | {
159
- readonly type: "compaction";
160
- readonly content: string | null;
161
187
  } | {
162
188
  readonly type: "thinking";
163
189
  readonly thinking: string;
164
190
  readonly signature: string;
165
191
  readonly cache_control?: {
166
192
  readonly type: "ephemeral";
167
- readonly ttl?: "1h" | "5m" | undefined;
193
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
168
194
  } | undefined;
169
195
  } | {
170
196
  readonly type: "redacted_thinking";
171
197
  readonly data: string;
172
198
  readonly cache_control?: {
173
199
  readonly type: "ephemeral";
174
- readonly ttl?: "1h" | "5m" | undefined;
200
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
175
201
  } | undefined;
176
202
  } | {
177
203
  readonly type: "tool_use";
@@ -180,7 +206,7 @@ export declare const protocol: Protocol<{
180
206
  readonly input: unknown;
181
207
  readonly cache_control?: {
182
208
  readonly type: "ephemeral";
183
- readonly ttl?: "1h" | "5m" | undefined;
209
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
184
210
  } | undefined;
185
211
  } | {
186
212
  readonly type: "server_tool_use";
@@ -189,7 +215,15 @@ export declare const protocol: Protocol<{
189
215
  readonly input: unknown;
190
216
  readonly cache_control?: {
191
217
  readonly type: "ephemeral";
192
- readonly ttl?: "1h" | "5m" | undefined;
218
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
219
+ } | undefined;
220
+ } | {
221
+ readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
222
+ readonly tool_use_id: string;
223
+ readonly content: unknown;
224
+ readonly cache_control?: {
225
+ readonly type: "ephemeral";
226
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
193
227
  } | undefined;
194
228
  })[];
195
229
  } | {
@@ -199,7 +233,7 @@ export declare const protocol: Protocol<{
199
233
  readonly text: string;
200
234
  readonly cache_control?: {
201
235
  readonly type: "ephemeral";
202
- readonly ttl?: "1h" | "5m" | undefined;
236
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
203
237
  } | undefined;
204
238
  }[];
205
239
  readonly output_config?: {
@@ -221,6 +255,8 @@ export declare const protocol: Protocol<{
221
255
  readonly top_k?: number | undefined;
222
256
  readonly stop_sequences?: readonly string[] | undefined;
223
257
  readonly thinking?: {
258
+ readonly type: "between_tools" | "disabled";
259
+ } | {
224
260
  readonly display?: import("../schema/options.js").OpenString<"omitted" | "summarized"> | undefined;
225
261
  readonly block_binding?: {
226
262
  readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"drop_block" | "error"> | undefined;
@@ -233,8 +269,6 @@ export declare const protocol: Protocol<{
233
269
  readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"drop_block" | "error"> | undefined;
234
270
  } | undefined;
235
271
  readonly type: "adaptive";
236
- } | {
237
- readonly type: "between_tools" | "disabled";
238
272
  } | undefined;
239
273
  readonly output_config?: {
240
274
  readonly effort?: string | undefined;
@@ -247,7 +281,7 @@ export declare const protocol: Protocol<{
247
281
  } | undefined;
248
282
  readonly cache_control?: {
249
283
  readonly type: "ephemeral";
250
- readonly ttl?: "1h" | "5m" | undefined;
284
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
251
285
  } | undefined;
252
286
  readonly container?: string | {
253
287
  readonly id?: string | null | undefined;
@@ -260,17 +294,8 @@ export declare const protocol: Protocol<{
260
294
  readonly user_id?: string | null | undefined;
261
295
  } | undefined;
262
296
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
297
+ readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
263
298
  readonly tools?: readonly ({
264
- readonly name: string;
265
- readonly description: string;
266
- readonly input_schema: {
267
- readonly [x: string]: unknown;
268
- };
269
- readonly cache_control?: {
270
- readonly type: "ephemeral";
271
- readonly ttl?: "1h" | "5m" | undefined;
272
- } | undefined;
273
- } | {
274
299
  readonly type: "web_search";
275
300
  readonly name: "web_search";
276
301
  readonly user_location?: {
@@ -280,6 +305,16 @@ export declare const protocol: Protocol<{
280
305
  readonly country?: string | undefined;
281
306
  readonly timezone?: string | undefined;
282
307
  } | undefined;
308
+ } | {
309
+ readonly name: string;
310
+ readonly description: string;
311
+ readonly input_schema: {
312
+ readonly [x: string]: unknown;
313
+ };
314
+ readonly cache_control?: {
315
+ readonly type: "ephemeral";
316
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
317
+ } | undefined;
283
318
  })[] | undefined;
284
319
  }, string, {
285
320
  readonly [x: string]: unknown;
@@ -1,5 +1,6 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { Protocol } from "../route/protocol.js";
3
+ import { CacheTTL } from "../schema/index.js";
3
4
  import { AnthropicMessages } from "./anthropic-messages.js";
4
5
  import { MetaResponses } from "./meta-responses.js";
5
6
  import { JsonObject, optionalArray, ProviderShared } from "./shared.js";
@@ -10,7 +11,7 @@ const WebSearch = Schema.Struct({
10
11
  });
11
12
  const MetaCacheControl = Schema.Struct({
12
13
  type: Schema.tag("ephemeral"),
13
- ttl: Schema.optional(Schema.Literals(["5m", "1h"])),
14
+ ttl: Schema.optional(CacheTTL),
14
15
  });
15
16
  const FunctionTool = Schema.Struct({
16
17
  name: Schema.String,
@@ -27,6 +28,18 @@ const fromRequest = Effect.fn("MetaMessages.fromRequest")(function* (request) {
27
28
  const body = yield* AnthropicMessages.protocol.body.from(projected.request);
28
29
  return {
29
30
  ...body,
31
+ messages: body.messages.map((message) => {
32
+ if (message.role !== "user")
33
+ return message;
34
+ const videos = [];
35
+ const content = message.content.map((block) => {
36
+ if (block.type !== "tool_result" || typeof block.content === "string")
37
+ return block;
38
+ videos.push(...block.content.filter((item) => item.type === "video"));
39
+ return { ...block, content: block.content.filter((item) => item.type !== "video") };
40
+ });
41
+ return videos.length === 0 ? message : { ...message, content: [...content, ...videos] };
42
+ }),
30
43
  tools: body.tools === undefined
31
44
  ? undefined
32
45
  : yield* Effect.forEach(body.tools, (tool, index) => Effect.gen(function* () {
@@ -27,14 +27,6 @@ interface ParserState extends OpenResponses.ParserState {
27
27
  export declare const protocol: Protocol<{
28
28
  readonly model: string;
29
29
  readonly input: readonly ({
30
- readonly [x: string]: unknown;
31
- readonly type: string;
32
- readonly id: string;
33
- } | {
34
- readonly type: "compaction";
35
- readonly id?: string | null | undefined;
36
- readonly encrypted_content: string;
37
- } | {
38
30
  readonly type: "configuration_update";
39
31
  readonly reasoning: {
40
32
  readonly effort: import("../schema/options.js").ReasoningEffort;
@@ -47,10 +39,48 @@ export declare const protocol: Protocol<{
47
39
  readonly type: "message";
48
40
  readonly role: "developer";
49
41
  readonly content: string;
42
+ } | {
43
+ readonly type: "function_call_output";
44
+ readonly call_id: string;
45
+ readonly output: string | readonly ({
46
+ readonly type: "input_text";
47
+ readonly text: string;
48
+ } | {
49
+ readonly type: "input_video";
50
+ readonly video_url: string;
51
+ } | {
52
+ readonly type: "input_image";
53
+ readonly image_url: string;
54
+ readonly detail?: string | undefined;
55
+ } | {
56
+ readonly type: "input_file";
57
+ readonly filename: string;
58
+ readonly detail?: string | undefined;
59
+ readonly file_data?: string | undefined;
60
+ readonly file_url?: string | undefined;
61
+ })[];
62
+ } | {
63
+ readonly type: "reasoning";
64
+ readonly id?: string | undefined;
65
+ readonly summary: readonly {
66
+ readonly type: "summary_text";
67
+ readonly text: string;
68
+ }[];
69
+ readonly encrypted_content?: string | null | undefined;
70
+ } | {
71
+ readonly type: "compaction";
72
+ readonly id?: string | null | undefined;
73
+ readonly encrypted_content: string;
50
74
  } | {
51
75
  readonly type: "message";
52
76
  readonly role: "user";
53
77
  readonly content: readonly ({
78
+ readonly type: "input_text";
79
+ readonly text: string;
80
+ } | {
81
+ readonly type: "input_video";
82
+ readonly video_url: string;
83
+ } | {
54
84
  readonly type: "input_image";
55
85
  readonly image_url: string;
56
86
  readonly detail?: string | undefined;
@@ -60,9 +90,6 @@ export declare const protocol: Protocol<{
60
90
  readonly detail?: string | undefined;
61
91
  readonly file_data?: string | undefined;
62
92
  readonly file_url?: string | undefined;
63
- } | {
64
- readonly type: "input_text";
65
- readonly text: string;
66
93
  })[];
67
94
  readonly id?: string | undefined;
68
95
  readonly status?: string | undefined;
@@ -76,14 +103,6 @@ export declare const protocol: Protocol<{
76
103
  }[];
77
104
  readonly phase?: "commentary" | "final_answer" | null | undefined;
78
105
  readonly status?: string | undefined;
79
- } | {
80
- readonly type: "reasoning";
81
- readonly id?: string | undefined;
82
- readonly summary: readonly {
83
- readonly type: "summary_text";
84
- readonly text: string;
85
- }[];
86
- readonly encrypted_content?: string | null | undefined;
87
106
  } | {
88
107
  readonly type: "function_call";
89
108
  readonly id?: string | undefined;
@@ -91,26 +110,6 @@ export declare const protocol: Protocol<{
91
110
  readonly name: string;
92
111
  readonly namespace?: string | undefined;
93
112
  readonly arguments: string;
94
- } | {
95
- readonly type: "function_call_output";
96
- readonly call_id: string;
97
- readonly output: string | readonly ({
98
- readonly type: "input_image";
99
- readonly image_url: string;
100
- readonly detail?: string | undefined;
101
- } | {
102
- readonly type: "input_file";
103
- readonly filename: string;
104
- readonly detail?: string | undefined;
105
- readonly file_data?: string | undefined;
106
- readonly file_url?: string | undefined;
107
- } | {
108
- readonly type: "input_text";
109
- readonly text: string;
110
- } | {
111
- readonly type: "input_video";
112
- readonly video_url: string;
113
- })[];
114
113
  } | {
115
114
  readonly [x: string]: unknown;
116
115
  readonly type: "web_search_call";
@@ -148,6 +147,10 @@ export declare const protocol: Protocol<{
148
147
  readonly arguments?: string | undefined;
149
148
  readonly output?: string | null | undefined;
150
149
  readonly error?: unknown;
150
+ } | {
151
+ readonly [x: string]: unknown;
152
+ readonly type: string;
153
+ readonly id: string;
151
154
  })[];
152
155
  readonly instructions?: string | undefined;
153
156
  readonly tools?: readonly ({
@@ -263,14 +266,6 @@ export declare const protocol: Protocol<{
263
266
  export declare const httpTransport: import("../route/transport/http.js").HttpJsonTransport<{
264
267
  readonly model: string;
265
268
  readonly input: readonly ({
266
- readonly [x: string]: unknown;
267
- readonly type: string;
268
- readonly id: string;
269
- } | {
270
- readonly type: "compaction";
271
- readonly id?: string | null | undefined;
272
- readonly encrypted_content: string;
273
- } | {
274
269
  readonly type: "configuration_update";
275
270
  readonly reasoning: {
276
271
  readonly effort: import("../schema/options.js").ReasoningEffort;
@@ -283,10 +278,48 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
283
278
  readonly type: "message";
284
279
  readonly role: "developer";
285
280
  readonly content: string;
281
+ } | {
282
+ readonly type: "function_call_output";
283
+ readonly call_id: string;
284
+ readonly output: string | readonly ({
285
+ readonly type: "input_text";
286
+ readonly text: string;
287
+ } | {
288
+ readonly type: "input_video";
289
+ readonly video_url: string;
290
+ } | {
291
+ readonly type: "input_image";
292
+ readonly image_url: string;
293
+ readonly detail?: string | undefined;
294
+ } | {
295
+ readonly type: "input_file";
296
+ readonly filename: string;
297
+ readonly detail?: string | undefined;
298
+ readonly file_data?: string | undefined;
299
+ readonly file_url?: string | undefined;
300
+ })[];
301
+ } | {
302
+ readonly type: "reasoning";
303
+ readonly id?: string | undefined;
304
+ readonly summary: readonly {
305
+ readonly type: "summary_text";
306
+ readonly text: string;
307
+ }[];
308
+ readonly encrypted_content?: string | null | undefined;
309
+ } | {
310
+ readonly type: "compaction";
311
+ readonly id?: string | null | undefined;
312
+ readonly encrypted_content: string;
286
313
  } | {
287
314
  readonly type: "message";
288
315
  readonly role: "user";
289
316
  readonly content: readonly ({
317
+ readonly type: "input_text";
318
+ readonly text: string;
319
+ } | {
320
+ readonly type: "input_video";
321
+ readonly video_url: string;
322
+ } | {
290
323
  readonly type: "input_image";
291
324
  readonly image_url: string;
292
325
  readonly detail?: string | undefined;
@@ -296,9 +329,6 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
296
329
  readonly detail?: string | undefined;
297
330
  readonly file_data?: string | undefined;
298
331
  readonly file_url?: string | undefined;
299
- } | {
300
- readonly type: "input_text";
301
- readonly text: string;
302
332
  })[];
303
333
  readonly id?: string | undefined;
304
334
  readonly status?: string | undefined;
@@ -312,14 +342,6 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
312
342
  }[];
313
343
  readonly phase?: "commentary" | "final_answer" | null | undefined;
314
344
  readonly status?: string | undefined;
315
- } | {
316
- readonly type: "reasoning";
317
- readonly id?: string | undefined;
318
- readonly summary: readonly {
319
- readonly type: "summary_text";
320
- readonly text: string;
321
- }[];
322
- readonly encrypted_content?: string | null | undefined;
323
345
  } | {
324
346
  readonly type: "function_call";
325
347
  readonly id?: string | undefined;
@@ -327,26 +349,6 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
327
349
  readonly name: string;
328
350
  readonly namespace?: string | undefined;
329
351
  readonly arguments: string;
330
- } | {
331
- readonly type: "function_call_output";
332
- readonly call_id: string;
333
- readonly output: string | readonly ({
334
- readonly type: "input_image";
335
- readonly image_url: string;
336
- readonly detail?: string | undefined;
337
- } | {
338
- readonly type: "input_file";
339
- readonly filename: string;
340
- readonly detail?: string | undefined;
341
- readonly file_data?: string | undefined;
342
- readonly file_url?: string | undefined;
343
- } | {
344
- readonly type: "input_text";
345
- readonly text: string;
346
- } | {
347
- readonly type: "input_video";
348
- readonly video_url: string;
349
- })[];
350
352
  } | {
351
353
  readonly [x: string]: unknown;
352
354
  readonly type: "web_search_call";
@@ -384,6 +386,10 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
384
386
  readonly arguments?: string | undefined;
385
387
  readonly output?: string | null | undefined;
386
388
  readonly error?: unknown;
389
+ } | {
390
+ readonly [x: string]: unknown;
391
+ readonly type: string;
392
+ readonly id: string;
387
393
  })[];
388
394
  readonly instructions?: string | undefined;
389
395
  readonly tools?: readonly ({
@@ -48,7 +48,7 @@ const adapter = {
48
48
  };
49
49
  const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
50
50
  const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
51
- return yield* OpenResponses.fromRequestWithAdapter(LLMRequest.update(request, {
51
+ const body = yield* OpenResponses.fromRequestWithAdapter(LLMRequest.update(request, {
52
52
  messages: request.messages.map((message) => Message.make({
53
53
  ...message,
54
54
  content: message.content.map((part) => {
@@ -69,7 +69,35 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
69
69
  }),
70
70
  })),
71
71
  }), adapter);
72
+ // Meta cannot see video nested in tool results; attach it after the complete result batch.
73
+ const input = [];
74
+ const videos = [];
75
+ const flushVideos = () => {
76
+ if (videos.length > 0)
77
+ input.push({ type: "message", role: "user", content: videos.splice(0) });
78
+ };
79
+ for (const item of body.input) {
80
+ if (!isFunctionCallOutput(item)) {
81
+ flushVideos();
82
+ input.push(item);
83
+ continue;
84
+ }
85
+ if (typeof item.output === "string") {
86
+ input.push(item);
87
+ continue;
88
+ }
89
+ const content = item.output.filter((part) => part.type !== "input_video");
90
+ videos.push(...item.output.filter((part) => part.type === "input_video"));
91
+ input.push({
92
+ ...item,
93
+ output: content.length === 0 && item.output.length > 0 ? "Video attached in the following user message." : content,
94
+ });
95
+ }
96
+ flushVideos();
97
+ return { ...body, input };
72
98
  });
99
+ // Hosted replay items have an open `type`, so a plain tag check does not narrow the union.
100
+ const isFunctionCallOutput = (item) => item.type === "function_call_output";
73
101
  const HOSTED_TOOLS = {
74
102
  web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
75
103
  image_generation_call: {