@opencode/ai 2.2.5 → 2.2.6

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 (264) hide show
  1. package/README.md +133 -69
  2. package/dist/cache-policy.d.ts +1 -1
  3. package/dist/cache-policy.js +16 -4
  4. package/dist/decision-client.d.ts +3 -3
  5. package/dist/decision.d.ts +20 -125
  6. package/dist/decision.js +25 -15
  7. package/dist/effect.d.ts +4 -15
  8. package/dist/effect.js +2 -6
  9. package/dist/effort-updates.d.ts +3 -3
  10. package/dist/effort-updates.js +2 -2
  11. package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
  12. package/dist/experimental/cloudflare-run-extraction.js +4 -1
  13. package/dist/experimental/extraction.d.ts +10 -40
  14. package/dist/experimental/extraction.js +14 -13
  15. package/dist/experimental.d.ts +8 -8
  16. package/dist/experimental.js +4 -4
  17. package/dist/generation.d.ts +0 -2
  18. package/dist/generation.js +2 -2
  19. package/dist/image-client.d.ts +13 -7
  20. package/dist/image-client.js +1 -1
  21. package/dist/image.d.ts +357 -464
  22. package/dist/image.js +17 -15
  23. package/dist/index.d.ts +28 -465
  24. package/dist/index.js +18 -17
  25. package/dist/llm.d.ts +65 -266
  26. package/dist/llm.js +101 -92
  27. package/dist/loop.d.ts +38 -0
  28. package/dist/loop.js +136 -0
  29. package/dist/media-model.d.ts +1 -1
  30. package/dist/media-model.js +8 -6
  31. package/dist/media.d.ts +9 -0
  32. package/dist/media.js +37 -2
  33. package/dist/protocols/alibaba-chat.d.ts +5 -1
  34. package/dist/protocols/alibaba-chat.js +3 -3
  35. package/dist/protocols/alibaba-images.d.ts +2 -2
  36. package/dist/protocols/alibaba-messages.js +3 -3
  37. package/dist/protocols/alibaba-responses.js +8 -20
  38. package/dist/protocols/anthropic-messages.d.ts +1 -1
  39. package/dist/protocols/anthropic-messages.js +54 -173
  40. package/dist/protocols/assemblyai-transcription.d.ts +2 -2
  41. package/dist/protocols/bedrock-converse.js +10 -16
  42. package/dist/protocols/cartesia-speech.d.ts +2 -2
  43. package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
  44. package/dist/protocols/cohere-chat.js +9 -12
  45. package/dist/protocols/deepgram-speech.d.ts +2 -2
  46. package/dist/protocols/deepgram-transcription.d.ts +2 -2
  47. package/dist/protocols/elevenlabs-speech.d.ts +2 -2
  48. package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
  49. package/dist/protocols/gemini.d.ts +3 -0
  50. package/dist/protocols/gemini.js +54 -72
  51. package/dist/protocols/google-images.d.ts +2 -2
  52. package/dist/protocols/google-interactions.d.ts +3 -4
  53. package/dist/protocols/google-interactions.js +44 -30
  54. package/dist/protocols/google-speech.d.ts +2 -2
  55. package/dist/protocols/google-transcription.d.ts +2 -2
  56. package/dist/protocols/google-video.d.ts +2 -2
  57. package/dist/protocols/meta-images.d.ts +2 -2
  58. package/dist/protocols/meta-responses.js +26 -23
  59. package/dist/protocols/minimax-images.d.ts +2 -2
  60. package/dist/protocols/mistral-chat.js +7 -10
  61. package/dist/protocols/open-responses-channel.js +6 -19
  62. package/dist/protocols/open-responses-continuation.d.ts +1 -5
  63. package/dist/protocols/open-responses-continuation.js +1 -3
  64. package/dist/protocols/open-responses.d.ts +1 -21
  65. package/dist/protocols/open-responses.js +10 -15
  66. package/dist/protocols/openai-chat.d.ts +3 -23
  67. package/dist/protocols/openai-chat.js +26 -47
  68. package/dist/protocols/openai-compatible-chat.d.ts +1 -1
  69. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  70. package/dist/protocols/openai-compatible-responses.js +1 -1
  71. package/dist/protocols/openai-decisions.js +1 -1
  72. package/dist/protocols/openai-images.d.ts +2 -2
  73. package/dist/protocols/openai-responses.js +10 -29
  74. package/dist/protocols/openai-speech.d.ts +2 -2
  75. package/dist/protocols/openai-transcription.d.ts +2 -2
  76. package/dist/protocols/runway-video.d.ts +2 -2
  77. package/dist/protocols/shared.d.ts +1 -4
  78. package/dist/protocols/shared.js +13 -11
  79. package/dist/protocols/system-one.d.ts +4 -4
  80. package/dist/protocols/utils/bedrock-cache.js +2 -5
  81. package/dist/protocols/utils/bedrock-media.d.ts +0 -3
  82. package/dist/protocols/utils/cache.d.ts +3 -0
  83. package/dist/protocols/utils/cache.js +15 -2
  84. package/dist/protocols/utils/image-sizing.d.ts +1 -1
  85. package/dist/protocols/utils/responses-checkpoint.js +1 -1
  86. package/dist/protocols/utils/responses-compaction.d.ts +1 -1
  87. package/dist/protocols/utils/responses-compaction.js +6 -5
  88. package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
  89. package/dist/protocols/utils/responses-hosted-tools.js +31 -0
  90. package/dist/protocols/utils/tool-stream.d.ts +5 -271
  91. package/dist/protocols/utils/tool-stream.js +3 -13
  92. package/dist/protocols/venice-chat.d.ts +3 -1
  93. package/dist/protocols/venice-chat.js +4 -4
  94. package/dist/protocols/xai-images.d.ts +2 -2
  95. package/dist/protocols/xai-responses.js +5 -25
  96. package/dist/protocols/xai-video.d.ts +2 -2
  97. package/dist/protocols/zai-chat.d.ts +5 -1
  98. package/dist/protocols/zai-chat.js +1 -1
  99. package/dist/protocols/zai-images.d.ts +2 -2
  100. package/dist/protocols/zai-messages.js +3 -3
  101. package/dist/provider-error.d.ts +0 -1
  102. package/dist/provider-error.js +7 -80
  103. package/dist/providers/alibaba.d.ts +67 -4
  104. package/dist/providers/alibaba.js +6 -1
  105. package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
  106. package/dist/providers/amazon-bedrock-mantle.js +6 -3
  107. package/dist/providers/amazon-bedrock.d.ts +6 -7
  108. package/dist/providers/amazon-bedrock.js +1 -1
  109. package/dist/providers/anthropic-compatible.d.ts +7 -8
  110. package/dist/providers/anthropic-compatible.js +2 -5
  111. package/dist/providers/anthropic.d.ts +8 -9
  112. package/dist/providers/anthropic.js +2 -7
  113. package/dist/providers/assemblyai.d.ts +2 -2
  114. package/dist/providers/assemblyai.js +2 -7
  115. package/dist/providers/azure/messages.d.ts +2 -0
  116. package/dist/providers/azure/messages.js +1 -0
  117. package/dist/providers/azure.d.ts +322 -7
  118. package/dist/providers/azure.js +25 -9
  119. package/dist/providers/baseten.d.ts +5 -5
  120. package/dist/providers/baseten.js +7 -21
  121. package/dist/providers/cartesia.d.ts +1 -1
  122. package/dist/providers/cerebras.d.ts +5 -5
  123. package/dist/providers/cerebras.js +4 -15
  124. package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
  125. package/dist/providers/cloudflare-ai-gateway.js +28 -40
  126. package/dist/providers/cloudflare-shared.d.ts +9 -0
  127. package/dist/providers/cloudflare-shared.js +25 -0
  128. package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
  129. package/dist/providers/cloudflare-workers-ai.js +4 -20
  130. package/dist/providers/cohere/chat.js +2 -7
  131. package/dist/providers/cohere.d.ts +6 -5
  132. package/dist/providers/cohere.js +7 -13
  133. package/dist/providers/deepgram.d.ts +2 -2
  134. package/dist/providers/deepgram.js +2 -7
  135. package/dist/providers/deepinfra.d.ts +5 -5
  136. package/dist/providers/deepinfra.js +5 -13
  137. package/dist/providers/deepseek.d.ts +5 -5
  138. package/dist/providers/deepseek.js +3 -14
  139. package/dist/providers/digitalocean.d.ts +8 -5
  140. package/dist/providers/digitalocean.js +13 -14
  141. package/dist/providers/elevenlabs.d.ts +2 -2
  142. package/dist/providers/elevenlabs.js +2 -7
  143. package/dist/providers/fireworks.d.ts +5 -5
  144. package/dist/providers/fireworks.js +4 -15
  145. package/dist/providers/google/interactions.d.ts +1 -1
  146. package/dist/providers/google/interactions.js +2 -7
  147. package/dist/providers/google-vertex-chat.d.ts +3 -3
  148. package/dist/providers/google-vertex-chat.js +3 -29
  149. package/dist/providers/google-vertex-interactions.d.ts +3 -3
  150. package/dist/providers/google-vertex-messages.d.ts +3 -3
  151. package/dist/providers/google-vertex-messages.js +3 -29
  152. package/dist/providers/google-vertex-mistral.d.ts +3 -3
  153. package/dist/providers/google-vertex-mistral.js +3 -29
  154. package/dist/providers/google-vertex-responses.d.ts +3 -3
  155. package/dist/providers/google-vertex-responses.js +4 -30
  156. package/dist/providers/google-vertex-shared.d.ts +31 -0
  157. package/dist/providers/google-vertex-shared.js +25 -0
  158. package/dist/providers/google-vertex.d.ts +3 -3
  159. package/dist/providers/google.d.ts +15 -13
  160. package/dist/providers/google.js +9 -19
  161. package/dist/providers/groq.d.ts +5 -5
  162. package/dist/providers/groq.js +4 -15
  163. package/dist/providers/meta.d.ts +5 -5
  164. package/dist/providers/meta.js +10 -23
  165. package/dist/providers/minimax/chat.js +2 -7
  166. package/dist/providers/minimax/responses.js +2 -7
  167. package/dist/providers/minimax.d.ts +5 -5
  168. package/dist/providers/minimax.js +7 -22
  169. package/dist/providers/mistral.d.ts +10 -11
  170. package/dist/providers/mistral.js +3 -14
  171. package/dist/providers/moonshot/messages.js +2 -7
  172. package/dist/providers/moonshot/responses.js +2 -7
  173. package/dist/providers/moonshot.d.ts +5 -5
  174. package/dist/providers/moonshot.js +4 -16
  175. package/dist/providers/openai-compatible-responses.d.ts +6 -7
  176. package/dist/providers/openai-compatible-responses.js +2 -8
  177. package/dist/providers/openai-compatible.d.ts +6 -7
  178. package/dist/providers/openai-compatible.js +4 -10
  179. package/dist/providers/openai.d.ts +4 -4
  180. package/dist/providers/openai.js +3 -3
  181. package/dist/providers/opencode.d.ts +4 -4
  182. package/dist/providers/opencode.js +6 -2
  183. package/dist/providers/openrouter.d.ts +8 -5
  184. package/dist/providers/openrouter.js +16 -24
  185. package/dist/providers/runway.d.ts +1 -1
  186. package/dist/providers/settings.d.ts +40 -0
  187. package/dist/providers/settings.js +19 -0
  188. package/dist/providers/togetherai.d.ts +5 -5
  189. package/dist/providers/togetherai.js +5 -15
  190. package/dist/providers/typesafe-ai.d.ts +4 -4
  191. package/dist/providers/typesafe-ai.js +6 -2
  192. package/dist/providers/venice.d.ts +4 -4
  193. package/dist/providers/venice.js +6 -2
  194. package/dist/providers/vercel-ai-gateway.d.ts +5 -5
  195. package/dist/providers/vercel-ai-gateway.js +15 -28
  196. package/dist/providers/xai.d.ts +4 -4
  197. package/dist/providers/xai.js +4 -12
  198. package/dist/providers/zai-coding-plan/messages.js +2 -7
  199. package/dist/providers/zai-coding-plan/responses.js +2 -7
  200. package/dist/providers/zai-coding-plan.d.ts +5 -5
  201. package/dist/providers/zai-coding-plan.js +8 -15
  202. package/dist/providers/zai.d.ts +5 -5
  203. package/dist/providers/zai.js +10 -22
  204. package/dist/public.d.ts +12 -0
  205. package/dist/public.js +5 -0
  206. package/dist/route/auth-options.d.ts +9 -5
  207. package/dist/route/auth-options.js +10 -7
  208. package/dist/route/client.d.ts +50 -37
  209. package/dist/route/client.js +42 -53
  210. package/dist/route/decision.d.ts +8 -8
  211. package/dist/route/decision.js +3 -3
  212. package/dist/route/executor.d.ts +5 -0
  213. package/dist/route/executor.js +10 -0
  214. package/dist/route/index.d.ts +5 -7
  215. package/dist/route/index.js +1 -1
  216. package/dist/route/media.d.ts +7 -11
  217. package/dist/route/media.js +22 -26
  218. package/dist/route/transport/http.js +6 -5
  219. package/dist/route/transport/websocket.js +7 -1
  220. package/dist/schema/errors.d.ts +16 -17
  221. package/dist/schema/errors.js +63 -12
  222. package/dist/schema/events.d.ts +2563 -2954
  223. package/dist/schema/events.js +54 -109
  224. package/dist/schema/messages.d.ts +194 -137
  225. package/dist/schema/messages.js +66 -83
  226. package/dist/schema/options.d.ts +112 -65
  227. package/dist/schema/options.js +52 -101
  228. package/dist/speech-client.d.ts +7 -7
  229. package/dist/speech.d.ts +306 -316
  230. package/dist/speech.js +16 -14
  231. package/dist/testing.d.ts +31 -175
  232. package/dist/testing.js +60 -5
  233. package/dist/tool-history.d.ts +1 -1
  234. package/dist/tool-history.js +3 -10
  235. package/dist/tool-runtime.d.ts +9 -2
  236. package/dist/tool-runtime.js +17 -31
  237. package/dist/tool.d.ts +39 -43
  238. package/dist/tool.js +16 -26
  239. package/dist/transcription-client.d.ts +7 -7
  240. package/dist/transcription.d.ts +314 -265
  241. package/dist/transcription.js +16 -14
  242. package/dist/utils/provider-codes.d.ts +3 -0
  243. package/dist/utils/provider-codes.js +41 -0
  244. package/dist/video-client.d.ts +7 -7
  245. package/dist/video-client.js +1 -1
  246. package/dist/video.d.ts +269 -287
  247. package/dist/video.js +16 -14
  248. package/package.json +9 -9
  249. package/dist/experimental/testing.d.ts +0 -3
  250. package/dist/experimental/testing.js +0 -3
  251. package/dist/testing/decision.d.ts +0 -16
  252. package/dist/testing/decision.js +0 -20
  253. package/dist/testing/image.d.ts +0 -14
  254. package/dist/testing/image.js +0 -12
  255. package/dist/testing/media.d.ts +0 -18
  256. package/dist/testing/media.js +0 -36
  257. package/dist/testing/script.d.ts +0 -28
  258. package/dist/testing/script.js +0 -60
  259. package/dist/testing/speech.d.ts +0 -14
  260. package/dist/testing/speech.js +0 -12
  261. package/dist/testing/transcription.d.ts +0 -14
  262. package/dist/testing/transcription.js +0 -12
  263. package/dist/testing/video.d.ts +0 -14
  264. package/dist/testing/video.js +0 -12
@@ -1,7 +1,7 @@
1
1
  import { Option, Schema } from "effect";
2
2
  import { withStatics } from "@opencode/schema/schema";
3
3
  import { Tool } from "@opencode/schema/tool";
4
- import { CacheHint, CachePolicy, GenerationOptions, HttpOptions, JsonSchema, LanguageModelSchema, ProviderMetadata, ProviderOptions, ReasoningEffort, } from "./options.js";
4
+ import { CacheHint, JsonSchema, ProviderMetadata, ReasoningEffort, } from "./options.js";
5
5
  import { ProviderID } from "./ids.js";
6
6
  import { Media } from "../media.js";
7
7
  import { Json } from "../utils/json.js";
@@ -25,7 +25,6 @@ export const TextPart = Schema.Struct({
25
25
  type: Schema.Literal("text"),
26
26
  text: Schema.String,
27
27
  cache: Schema.optional(CacheHint),
28
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
29
28
  providerMetadata: Schema.optional(ProviderMetadata),
30
29
  }).annotate({ identifier: "LLM.Content.Text" });
31
30
  export const MediaPart = Schema.Struct({
@@ -33,9 +32,12 @@ export const MediaPart = Schema.Struct({
33
32
  media: Media.AssetSchema,
34
33
  filename: Schema.optional(Schema.String),
35
34
  cache: Schema.optional(CacheHint),
36
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
37
35
  providerMetadata: Schema.optional(ProviderMetadata),
38
36
  }).annotate({ identifier: "LLM.Content.Media" });
37
+ const mediaPart = (input) => {
38
+ const { mediaType, ...part } = input;
39
+ return { ...part, media: Media.make(input.media, mediaType) };
40
+ };
39
41
  const toolResultValueSchema = Schema.Union([
40
42
  Schema.Struct({
41
43
  type: Schema.Literal("json"),
@@ -104,7 +106,6 @@ export const ToolCallPart = withStatics(Schema.Struct({
104
106
  input: Schema.Unknown,
105
107
  providerExecuted: Schema.optional(Schema.Boolean),
106
108
  cache: Schema.optional(CacheHint),
107
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
108
109
  providerMetadata: Schema.optional(ProviderMetadata),
109
110
  }).annotate({ identifier: "LLM.Content.ToolCall" }), {
110
111
  make: (input) => ({ type: "tool-call", ...input }),
@@ -117,7 +118,6 @@ export const ToolResultPart = withStatics(Schema.Struct({
117
118
  result: ToolResultValue,
118
119
  providerExecuted: Schema.optional(Schema.Boolean),
119
120
  cache: Schema.optional(CacheHint),
120
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
121
121
  providerMetadata: Schema.optional(ProviderMetadata),
122
122
  }).annotate({ identifier: "LLM.Content.ToolResult" }), {
123
123
  make: (input) => ({
@@ -128,7 +128,6 @@ export const ToolResultPart = withStatics(Schema.Struct({
128
128
  result: ToolResultValue.make(input.result, input.resultType),
129
129
  providerExecuted: input.providerExecuted,
130
130
  cache: input.cache,
131
- metadata: input.metadata,
132
131
  providerMetadata: input.providerMetadata,
133
132
  }),
134
133
  });
@@ -137,7 +136,6 @@ export const ReasoningPart = Schema.Struct({
137
136
  text: Schema.String,
138
137
  encrypted: Schema.optional(Schema.String),
139
138
  cache: Schema.optional(CacheHint),
140
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
141
139
  providerMetadata: Schema.optional(ProviderMetadata),
142
140
  }).annotate({ identifier: "LLM.Content.Reasoning" });
143
141
  const compactionPartSchema = Schema.Struct({
@@ -168,40 +166,77 @@ export const ContentPart = Schema.Union([
168
166
  CompactionPart,
169
167
  EffortPart,
170
168
  ]).pipe(Schema.toTaggedUnion("type"));
171
- export class Message extends Schema.Class("LLM.Message")({
169
+ export class SystemMessage extends Schema.Class("LLM.SystemMessage")({
172
170
  id: Schema.optional(Schema.String),
173
- role: MessageRole,
174
- content: Schema.Array(ContentPart),
175
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
171
+ role: Schema.Literal("system"),
172
+ content: Schema.Array(Schema.Union([TextPart, EffortPart]).pipe(Schema.toTaggedUnion("type"))),
173
+ }) {
174
+ }
175
+ export class UserMessage extends Schema.Class("LLM.UserMessage")({
176
+ id: Schema.optional(Schema.String),
177
+ role: Schema.Literal("user"),
178
+ content: Schema.Array(Schema.Union([TextPart, MediaPart]).pipe(Schema.toTaggedUnion("type"))),
176
179
  providerMetadata: Schema.optional(ProviderMetadata),
177
- native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
178
180
  }) {
179
181
  }
180
- (function (Message) {
181
- Message.text = (value) => ({ type: "text", text: value });
182
- Message.media = (asset, options) => ({
183
- type: "media",
184
- media: asset,
185
- ...options,
186
- });
187
- Message.content = (input) => typeof input === "string" ? [Message.text(input)] : Array.isArray(input) ? [...input] : [input];
188
- Message.make = (input) => {
189
- if (input instanceof Message)
190
- return input;
191
- return new Message({ ...input, content: Message.content(input.content) });
192
- };
193
- Message.user = (content) => Message.make({ role: "user", content });
194
- Message.assistant = (content) => Message.make({ role: "assistant", content });
182
+ export class AssistantMessage extends Schema.Class("LLM.AssistantMessage")({
183
+ id: Schema.optional(Schema.String),
184
+ role: Schema.Literal("assistant"),
185
+ content: Schema.Array(Schema.Union([TextPart, ReasoningPart, ToolCallPart, ToolResultPart, MediaPart, CompactionPart]).pipe(Schema.toTaggedUnion("type"))),
186
+ providerMetadata: Schema.optional(ProviderMetadata),
187
+ }) {
188
+ }
189
+ export class ToolMessage extends Schema.Class("LLM.ToolMessage")({
190
+ id: Schema.optional(Schema.String),
191
+ role: Schema.Literal("tool"),
192
+ content: Schema.Array(ToolResultPart),
193
+ }) {
194
+ }
195
+ const messageSchema = Schema.Union([SystemMessage, UserMessage, AssistantMessage, ToolMessage]).pipe(Schema.toTaggedUnion("role"), Schema.annotate({ identifier: "LLM.Message" }));
196
+ const text = (value) => ({ type: "text", text: value });
197
+ const isParts = (input) => Array.isArray(input);
198
+ const content = (input) => (typeof input === "string" ? [text(input)] : isParts(input) ? [...input] : [input]);
199
+ function contentWithMedia(input) {
200
+ return content(input).map((part) => (part.type === "media" ? mediaPart(part) : part));
201
+ }
202
+ function make(input) {
203
+ switch (input.role) {
204
+ case "system":
205
+ return input instanceof SystemMessage ? input : new SystemMessage({ ...input, content: content(input.content) });
206
+ case "user":
207
+ return input instanceof UserMessage
208
+ ? input
209
+ : new UserMessage({ ...input, content: contentWithMedia(input.content) });
210
+ case "assistant":
211
+ return input instanceof AssistantMessage
212
+ ? input
213
+ : new AssistantMessage({ ...input, content: contentWithMedia(input.content) });
214
+ case "tool":
215
+ return input instanceof ToolMessage
216
+ ? input
217
+ : new ToolMessage({ ...input, content: isParts(input.content) ? [...input.content] : [input.content] });
218
+ }
219
+ // Untyped callers can still pass an unknown role; reject it the way the schema does.
220
+ return Schema.decodeUnknownSync(messageSchema)(input);
221
+ }
222
+ export const Message = withStatics(messageSchema, {
223
+ text,
224
+ // Typed through `MediaPartInput` so packages that infer types from `Message` can still emit declarations.
225
+ media: (media, options) => mediaPart({ type: "media", media, ...options }),
226
+ content: contentWithMedia,
227
+ make,
228
+ user: (input) => make({ role: "user", content: input }),
229
+ assistant: (input) => make({ role: "assistant", content: input }),
195
230
  /**
196
231
  * Add an operator-authored instruction at this chronological point in the
197
232
  * conversation. This is distinct from the initial `LLMRequest.system`
198
233
  * prompt. Keep raw retrieved, tool, and web content out of privileged system
199
234
  * updates; pass that untrusted content through ordinary user/tool channels.
200
235
  */
201
- Message.system = (content) => Message.make({ role: "system", content });
202
- Message.effort = (input) => Message.make({ role: "system", content: [{ type: "effort", effort: input.effort, previous: input.previous }] });
203
- Message.tool = (result) => Message.make({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] });
204
- })(Message || (Message = {}));
236
+ system: (input) => make({ role: "system", content: input }),
237
+ effort: (input) => make({ role: "system", content: [{ type: "effort", effort: input.effort, previous: input.previous }] }),
238
+ tool: (result) => make({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] }),
239
+ });
205
240
  /**
206
241
  * Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
207
242
  * write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
@@ -218,7 +253,6 @@ const toolDefinitionFields = {
218
253
  outputSchema: Schema.optional(JsonSchema),
219
254
  freeform: Schema.optional(Freeform),
220
255
  cache: Schema.optional(CacheHint),
221
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
222
256
  native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
223
257
  };
224
258
  export class ToolDefinition extends Schema.Class("LLM.ToolDefinition")({
@@ -279,54 +313,3 @@ export class ToolChoice extends Schema.Class("LLM.ToolChoice")({
279
313
  return new ToolChoice(input);
280
314
  };
281
315
  })(ToolChoice || (ToolChoice = {}));
282
- const requestSchema = Schema.Struct({
283
- id: Schema.optional(Schema.String),
284
- model: LanguageModelSchema,
285
- system: Schema.Array(SystemPart),
286
- messages: Schema.Array(Message),
287
- tools: Schema.Array(ToolEntry),
288
- toolChoice: Schema.optional(ToolChoice),
289
- generation: Schema.optional(GenerationOptions),
290
- providerOptions: Schema.optional(ProviderOptions),
291
- http: Schema.optional(HttpOptions),
292
- cache: Schema.optional(CachePolicy),
293
- // Stable cache affinity for protocols that support provider-managed prompt caching.
294
- promptCacheKey: Schema.optional(Schema.String),
295
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
296
- /** Emit a `raw` event with each provider frame before the events parsed from it. */
297
- includeRaw: Schema.optional(Schema.Boolean),
298
- });
299
- export class LLMRequest extends Schema.Class("LLM.Request")(requestSchema.fields) {
300
- // Preserve model inference instead of inheriting the schema's erased constructor signature.
301
- // oxlint-disable-next-line no-useless-constructor
302
- constructor(input) {
303
- super(input);
304
- }
305
- }
306
- (function (LLMRequest) {
307
- LLMRequest.input = (request) => ({
308
- id: request.id,
309
- model: request.model,
310
- system: request.system,
311
- messages: request.messages,
312
- tools: request.tools,
313
- toolChoice: request.toolChoice,
314
- generation: request.generation,
315
- providerOptions: request.providerOptions,
316
- http: request.http,
317
- cache: request.cache,
318
- promptCacheKey: request.promptCacheKey,
319
- metadata: request.metadata,
320
- includeRaw: request.includeRaw,
321
- });
322
- function update(request, patch) {
323
- if (Object.keys(patch).length === 0)
324
- return request;
325
- return new LLMRequest({
326
- ...LLMRequest.input(request),
327
- ...patch,
328
- model: patch.model ?? request.model,
329
- });
330
- }
331
- LLMRequest.update = update;
332
- })(LLMRequest || (LLMRequest = {}));
@@ -12,56 +12,55 @@ export declare const mergeProviderOptions: (...items: ReadonlyArray<ProviderOpti
12
12
  /** Milliseconds for an HTTP timeout, or `false` to disable it. */
13
13
  export declare const HttpTimeout: Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>;
14
14
  export type HttpTimeout = Schema.Schema.Type<typeof HttpTimeout>;
15
- /** Applied to `headerTimeout` when a request leaves it unset. */
15
+ /** Applied to `timeout.headers` when a request leaves it unset. */
16
16
  export declare const DEFAULT_HTTP_TIMEOUT_MS = 300000;
17
17
  /**
18
- * Applied to `chunkTimeout` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
18
+ * Applied to `timeout.chunk` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
19
19
  * clients to allow at least 15 minutes, because their models can stream nothing for minutes while they reason.
20
20
  */
21
21
  export declare const DEFAULT_CHUNK_TIMEOUT_MS = 900000;
22
22
  /** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
23
23
  export declare const RequestEncoding: Schema.Literals<readonly ["zstd", "gzip", "none"]>;
24
24
  export type RequestEncoding = Schema.Schema.Type<typeof RequestEncoding>;
25
- declare const HttpOptions_base: Schema.Class<HttpOptions, Schema.Struct<{
26
- readonly body: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
27
- readonly headers: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
28
- readonly query: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
29
- /** Time allowed for the whole request, from send until the response completes. Unbounded when unset. */
30
- readonly timeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
31
- /** Time allowed for response headers to arrive. */
32
- readonly headerTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
33
- /** Time allowed between streamed response chunks once headers have arrived. */
34
- readonly chunkTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
25
+ /** Rare wire-level overrides. */
26
+ export interface HttpOptions {
27
+ readonly query?: Record<string, string>;
28
+ /** Deep-merged over the provider-native JSON body. */
29
+ readonly body?: Record<string, unknown>;
35
30
  /** Compression for JSON request bodies. Only set it for endpoints known to decode it. */
36
- readonly encoding: Schema.optional<Schema.Literals<readonly ["zstd", "gzip", "none"]>>;
37
- }>, {}>;
38
- export declare class HttpOptions extends HttpOptions_base {
31
+ readonly encoding?: RequestEncoding;
39
32
  }
40
- export declare namespace HttpOptions {
41
- type Input = HttpOptions | ConstructorParameters<typeof HttpOptions>[0];
42
- /** Normalize HTTP option input into the canonical `HttpOptions` class; `undefined` stays `undefined`. */
43
- function make(input: Input): HttpOptions;
44
- function make(input: Input | undefined): HttpOptions | undefined;
33
+ /** Per-phase time limits in milliseconds. */
34
+ export interface TimeoutConfig {
35
+ /** The whole request, from send until the response completes. Unbounded when unset. */
36
+ readonly total?: HttpTimeout;
37
+ /** Until response headers arrive. */
38
+ readonly headers?: HttpTimeout;
39
+ /** Between streamed response chunks once headers have arrived. */
40
+ readonly chunk?: HttpTimeout;
45
41
  }
46
- export declare const mergeHttpOptions: (...items: ReadonlyArray<HttpOptions | undefined>) => HttpOptions | undefined;
47
- declare const GenerationOptions_base: Schema.Class<GenerationOptions, Schema.Struct<{
48
- readonly maxTokens: Schema.optional<Schema.Number>;
49
- readonly temperature: Schema.optional<Schema.Number>;
50
- readonly topP: Schema.optional<Schema.Number>;
51
- readonly topK: Schema.optional<Schema.Number>;
52
- readonly frequencyPenalty: Schema.optional<Schema.Number>;
53
- readonly presencePenalty: Schema.optional<Schema.Number>;
54
- readonly seed: Schema.optional<Schema.Number>;
55
- readonly stop: Schema.optional<Schema.$Array<Schema.String>>;
56
- }>, {}>;
57
- export declare class GenerationOptions extends GenerationOptions_base {
42
+ /** Milliseconds for the whole request, `false` to disable it, or per-phase limits. */
43
+ export type RequestTimeout = HttpTimeout | TimeoutConfig;
44
+ /** Transport settings shared by requests, models and routes. */
45
+ export interface TransportOptions {
46
+ /** Merged over the provider's headers; these win. */
47
+ readonly headers?: Record<string, string>;
48
+ /** Applied to text requests; media requests do not apply it yet. */
49
+ readonly timeout?: RequestTimeout;
50
+ readonly http?: HttpOptions;
58
51
  }
59
- export declare namespace GenerationOptions {
60
- type Input = GenerationOptions | ConstructorParameters<typeof GenerationOptions>[0];
61
- /** Normalize generation option input into the canonical `GenerationOptions` class. */
62
- const make: (input?: Input) => GenerationOptions;
52
+ /** The fields every request shares, whatever its modality. */
53
+ export interface BaseRequest<Model, Options = ProviderOptions> extends TransportOptions {
54
+ readonly model: Model;
55
+ readonly providerOptions?: Options;
56
+ /** Sends this call through `fetch` instead of the client's HTTP executor. */
57
+ readonly fetch?: typeof globalThis.fetch;
63
58
  }
64
- export type GenerationOptionsFields = {
59
+ export declare const timeoutConfig: (timeout: RequestTimeout | undefined) => TimeoutConfig;
60
+ /** Merge transport settings; later items win, headers, query and body merge by key. */
61
+ export declare const mergeTransport: (...items: ReadonlyArray<TransportOptions | undefined>) => TransportOptions;
62
+ /** Portable sampling knobs, set at the top level of text requests, model defaults and route defaults. */
63
+ export interface GenerationOptionsFields {
65
64
  readonly maxTokens?: number;
66
65
  readonly temperature?: number;
67
66
  readonly topP?: number;
@@ -70,25 +69,17 @@ export type GenerationOptionsFields = {
70
69
  readonly presencePenalty?: number;
71
70
  readonly seed?: number;
72
71
  readonly stop?: ReadonlyArray<string>;
73
- };
74
- export type GenerationOptionsInput = GenerationOptions | GenerationOptionsFields;
75
- export declare const mergeGenerationOptions: (...items: ReadonlyArray<GenerationOptionsInput | undefined>) => GenerationOptions | undefined;
76
- declare const LanguageModelDefaults_base: Schema.Class<LanguageModelDefaults, Schema.Struct<{
77
- readonly generation: Schema.optional<typeof GenerationOptions>;
78
- readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
79
- readonly http: Schema.optional<typeof HttpOptions>;
80
- }>, {}>;
81
- export declare class LanguageModelDefaults extends LanguageModelDefaults_base {
82
72
  }
83
- export declare namespace LanguageModelDefaults {
84
- type Input = LanguageModelDefaults | {
85
- readonly generation?: GenerationOptions.Input;
86
- readonly providerOptions?: ProviderOptions;
87
- readonly http?: HttpOptions.Input;
88
- };
89
- /** Normalize selected-model request defaults without applying precedence. */
90
- const make: (input: Input) => LanguageModelDefaults;
73
+ /** The keys of `GenerationOptionsFields`, for splitting a flat record into portable knobs and provider options. */
74
+ export declare const GENERATION_KEYS: ReadonlySet<string>;
75
+ /** Pick the generation knobs out of each item; later items win per knob. */
76
+ export declare const mergeGeneration: (...items: ReadonlyArray<GenerationOptionsFields | undefined>) => GenerationOptionsFields;
77
+ /** Request options a model applies under each request: the same keys as a request, and the request wins. */
78
+ export interface RequestOptions extends TransportOptions, GenerationOptionsFields {
79
+ readonly providerOptions?: ProviderOptions;
91
80
  }
81
+ /** Merge model options; later items win per key. Empty results are `undefined`. */
82
+ export declare const mergeRequestOptions: (...items: ReadonlyArray<RequestOptions | undefined>) => RequestOptions | undefined;
92
83
  /** Provider-defined string enum: known values for autocomplete, any string accepted. */
93
84
  export type OpenString<Known extends string> = Known | (string & {});
94
85
  export declare const ReasoningEfforts: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
@@ -109,19 +100,12 @@ declare const LanguageModelCompatibility_base: Schema.Class<LanguageModelCompati
109
100
  readonly maxTokensField: Schema.optional<Schema.Literals<readonly ["max_completion_tokens", "max_tokens"]>>;
110
101
  readonly requireFinishReason: Schema.optional<Schema.Boolean>;
111
102
  readonly requireAssistantAfterTool: Schema.optional<Schema.Boolean>;
112
- readonly supportsStore: Schema.optional<Schema.Boolean>;
113
- /** Request usage in the stream with `stream_options.include_usage`. Defaults to true. */
114
- readonly streamUsage: Schema.optional<Schema.Boolean>;
115
- readonly supportsStrictMode: Schema.optional<Schema.Boolean>;
116
- readonly supportsPromptCacheKey: Schema.optional<Schema.Boolean>;
117
103
  /** Prompt-cache marker syntax the endpoint accepts. Overrides the route default; both send `cache_control`, and `alibaba` skips tool definitions. */
118
104
  readonly cacheFormat: Schema.optional<Schema.Literals<readonly ["anthropic", "alibaba"]>>;
119
105
  readonly zaiToolStream: Schema.optional<Schema.Boolean>;
120
106
  readonly requireSignature: Schema.optional<Schema.Boolean>;
121
107
  /** Supports Anthropic's thinking-prefix mismatch controls. Overrides model-ID detection. */
122
108
  readonly supportsThinkingBlockBinding: Schema.optional<Schema.Boolean>;
123
- /** Supports per-message effort updates. Overrides model-ID detection. */
124
- readonly supportsEffortUpdates: Schema.optional<Schema.Boolean>;
125
109
  }>, {}>;
126
110
  export declare class LanguageModelCompatibility extends LanguageModelCompatibility_base {
127
111
  }
@@ -130,12 +114,75 @@ export declare namespace LanguageModelCompatibility {
130
114
  /** Normalize model/upstream compatibility metadata without projecting requests. */
131
115
  const make: (input: Input) => LanguageModelCompatibility;
132
116
  }
117
+ /**
118
+ * What the model accepts on its API: models.dev v2 `capabilities` in camelCase, with the API's own overrides merged in.
119
+ * Unset fields keep the protocol default, which may still guess from the provider, base URL or model ID.
120
+ */
121
+ export interface Capabilities {
122
+ readonly tools?: {
123
+ readonly supported?: boolean;
124
+ /** Accepts `strict` on function tools. OpenAI Chat detects it from the provider when unset. */
125
+ readonly strict?: boolean;
126
+ readonly choice?: ReadonlyArray<"auto" | "none" | "required" | "tool">;
127
+ readonly search?: boolean;
128
+ /** Input formats accepted by custom (free-form) tools. */
129
+ readonly freeform?: ReadonlyArray<"text" | "lark" | "regex">;
130
+ /** Accepts a changed tool list mid-conversation. */
131
+ readonly updates?: boolean;
132
+ };
133
+ readonly reasoning?: {
134
+ readonly supported?: boolean;
135
+ readonly default?: {
136
+ readonly type: "toggle";
137
+ readonly value: boolean;
138
+ } | {
139
+ readonly type: "effort";
140
+ readonly value: ReasoningEffort;
141
+ } | {
142
+ readonly type: "budget";
143
+ readonly value: number;
144
+ };
145
+ readonly toggle?: boolean;
146
+ readonly effort?: ReadonlyArray<ReasoningEffort>;
147
+ readonly budget?: {
148
+ readonly min?: number;
149
+ readonly max?: number;
150
+ };
151
+ /** Accepts per-message effort updates. Detected from the model ID when unset. */
152
+ readonly updates?: boolean;
153
+ };
154
+ readonly cache?: false | {
155
+ readonly implicit?: true | {
156
+ readonly ttl?: ReadonlyArray<CacheTTL>;
157
+ readonly minTokens?: number;
158
+ };
159
+ readonly explicit?: true | {
160
+ readonly ttl?: ReadonlyArray<CacheTTL>;
161
+ readonly maxBreakpoints?: number;
162
+ readonly targets?: ReadonlyArray<"tools" | "system" | "messages">;
163
+ readonly minTokens?: number;
164
+ };
165
+ };
166
+ readonly structuredOutput?: boolean;
167
+ readonly temperature?: boolean;
168
+ readonly topP?: boolean;
169
+ readonly topK?: boolean;
170
+ /** Accepts mid-conversation system messages. Anthropic Messages detects it from the model ID when unset. */
171
+ readonly systemUpdates?: boolean;
172
+ /** Accepts `store`. OpenAI Chat detects it from the provider when unset. */
173
+ readonly store?: boolean;
174
+ /** Accepts `stream_options.include_usage`. OpenAI Chat defaults to true. */
175
+ readonly streamUsage?: boolean;
176
+ readonly promptCacheKey?: boolean;
177
+ readonly serviceTier?: ReadonlyArray<OpenString<"flex" | "priority" | "fast" | "ultrafast" | "standby">>;
178
+ }
133
179
  export declare class LanguageModel<Options extends ProviderOptions = ProviderOptions, Compact extends CompactionOperations | undefined = CompactionOperations | undefined> {
134
180
  protected readonly _ProviderOptions: Options;
135
181
  readonly id: ModelID;
136
182
  readonly provider: ProviderID;
137
183
  readonly route: AnyRoute<Compact>;
138
- readonly defaults?: LanguageModelDefaults;
184
+ readonly options?: RequestOptions;
185
+ readonly capabilities?: Capabilities;
139
186
  readonly compatibility?: LanguageModelCompatibility;
140
187
  constructor(input: LanguageModel.ConstructorInput<Compact>);
141
188
  static make<Options extends ProviderOptions = ProviderOptions, Compact extends CompactionOperations | undefined = CompactionOperations | undefined>(input: LanguageModel.Input<Compact>): LanguageModel<Options, Compact>;
@@ -153,13 +200,13 @@ export declare namespace LanguageModel {
153
200
  readonly id: ModelID;
154
201
  readonly provider: ProviderID;
155
202
  readonly route: AnyRoute<Compact>;
156
- readonly defaults?: LanguageModelDefaults;
203
+ readonly options?: RequestOptions;
204
+ readonly capabilities?: Capabilities;
157
205
  readonly compatibility?: LanguageModelCompatibility;
158
206
  };
159
- type Input<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Omit<ConstructorInput<Compact>, "id" | "provider" | "defaults" | "compatibility"> & {
207
+ type Input<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Omit<ConstructorInput<Compact>, "id" | "provider" | "compatibility"> & {
160
208
  readonly id: string | ModelID;
161
209
  readonly provider: string | ProviderID;
162
- readonly defaults?: LanguageModelDefaults.Input;
163
210
  readonly compatibility?: LanguageModelCompatibility.Input;
164
211
  };
165
212
  }