@opencode/ai 2.0.14 → 2.0.16

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 (208) hide show
  1. package/README.md +399 -56
  2. package/dist/experimental/evaluation-client.d.ts +1 -1
  3. package/dist/experimental/evaluation-client.js +39 -3
  4. package/dist/experimental/evaluation.d.ts +4 -4
  5. package/dist/experimental/evaluation.js +2 -2
  6. package/dist/experimental/system-one.d.ts +3 -3
  7. package/dist/experimental/system-one.js +40 -51
  8. package/dist/generation.d.ts +83 -0
  9. package/dist/generation.js +113 -0
  10. package/dist/image-client.d.ts +16 -7
  11. package/dist/image-client.js +29 -13
  12. package/dist/image.d.ts +1410 -81
  13. package/dist/image.js +97 -67
  14. package/dist/index.d.ts +17 -2
  15. package/dist/index.js +12 -1
  16. package/dist/llm.d.ts +9 -1
  17. package/dist/media-model.d.ts +44 -0
  18. package/dist/media-model.js +49 -0
  19. package/dist/media.d.ts +213 -0
  20. package/dist/media.js +227 -0
  21. package/dist/promise.d.ts +974 -0
  22. package/dist/promise.js +81 -0
  23. package/dist/protocols/alibaba-chat.d.ts +12 -0
  24. package/dist/protocols/alibaba-responses.d.ts +2 -2
  25. package/dist/protocols/anthropic-messages.js +8 -19
  26. package/dist/protocols/assemblyai-transcription.d.ts +40 -0
  27. package/dist/protocols/assemblyai-transcription.js +138 -0
  28. package/dist/protocols/bedrock-converse.d.ts +4 -4
  29. package/dist/protocols/bedrock-converse.js +6 -17
  30. package/dist/protocols/bfl-images.d.ts +32 -0
  31. package/dist/protocols/bfl-images.js +153 -0
  32. package/dist/protocols/cartesia-speech.d.ts +127 -0
  33. package/dist/protocols/cartesia-speech.js +126 -0
  34. package/dist/protocols/deepgram-speech.d.ts +119 -0
  35. package/dist/protocols/deepgram-speech.js +92 -0
  36. package/dist/protocols/deepgram-transcription.d.ts +25 -0
  37. package/dist/protocols/deepgram-transcription.js +129 -0
  38. package/dist/protocols/elevenlabs-speech.d.ts +122 -0
  39. package/dist/protocols/elevenlabs-speech.js +115 -0
  40. package/dist/protocols/fal-images.d.ts +24 -0
  41. package/dist/protocols/fal-images.js +114 -0
  42. package/dist/protocols/fal-video.d.ts +29 -0
  43. package/dist/protocols/fal-video.js +88 -0
  44. package/dist/protocols/gemini.d.ts +30 -9
  45. package/dist/protocols/gemini.js +45 -35
  46. package/dist/protocols/google-images.d.ts +9 -21
  47. package/dist/protocols/google-images.js +158 -133
  48. package/dist/protocols/google-speech.d.ts +130 -0
  49. package/dist/protocols/google-speech.js +84 -0
  50. package/dist/protocols/google-transcription.d.ts +173 -0
  51. package/dist/protocols/google-transcription.js +138 -0
  52. package/dist/protocols/google-video.d.ts +26 -0
  53. package/dist/protocols/google-video.js +158 -0
  54. package/dist/protocols/meta-images.d.ts +7 -12
  55. package/dist/protocols/meta-images.js +85 -66
  56. package/dist/protocols/meta-responses.d.ts +4 -4
  57. package/dist/protocols/meta-responses.js +1 -1
  58. package/dist/protocols/mistral-chat.js +7 -6
  59. package/dist/protocols/open-responses.d.ts +17 -9
  60. package/dist/protocols/open-responses.js +24 -14
  61. package/dist/protocols/openai-chat.d.ts +118 -1
  62. package/dist/protocols/openai-chat.js +125 -44
  63. package/dist/protocols/openai-compatible-chat.d.ts +12 -0
  64. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  65. package/dist/protocols/openai-images.d.ts +128 -18
  66. package/dist/protocols/openai-images.js +177 -154
  67. package/dist/protocols/openai-responses.d.ts +15 -15
  68. package/dist/protocols/openai-responses.js +5 -6
  69. package/dist/protocols/openai-speech.d.ts +116 -0
  70. package/dist/protocols/openai-speech.js +98 -0
  71. package/dist/protocols/openai-transcription.d.ts +207 -0
  72. package/dist/protocols/openai-transcription.js +190 -0
  73. package/dist/protocols/replicate-images.d.ts +28 -0
  74. package/dist/protocols/replicate-images.js +133 -0
  75. package/dist/protocols/runway-video.d.ts +38 -0
  76. package/dist/protocols/runway-video.js +146 -0
  77. package/dist/protocols/shared.d.ts +27 -17
  78. package/dist/protocols/shared.js +52 -35
  79. package/dist/protocols/stability-images.d.ts +38 -0
  80. package/dist/protocols/stability-images.js +148 -0
  81. package/dist/protocols/utils/bedrock-media.d.ts +2 -3
  82. package/dist/protocols/utils/bedrock-media.js +4 -4
  83. package/dist/protocols/utils/fal-queue.d.ts +28 -0
  84. package/dist/protocols/utils/fal-queue.js +69 -0
  85. package/dist/protocols/utils/gemini-generate-content.d.ts +65 -0
  86. package/dist/protocols/utils/gemini-generate-content.js +65 -0
  87. package/dist/protocols/utils/gemini-json-schema.d.ts +3 -0
  88. package/dist/protocols/utils/gemini-json-schema.js +76 -0
  89. package/dist/protocols/utils/media-input.d.ts +18 -0
  90. package/dist/protocols/utils/media-input.js +35 -0
  91. package/dist/protocols/utils/responses-compaction.js +6 -5
  92. package/dist/protocols/utils/speech-stream.d.ts +49 -0
  93. package/dist/protocols/utils/speech-stream.js +67 -0
  94. package/dist/protocols/utils/tool-schema.d.ts +2 -2
  95. package/dist/protocols/utils/tool-schema.js +40 -17
  96. package/dist/protocols/utils/tool-stream.d.ts +27 -3
  97. package/dist/protocols/xai-images.d.ts +9 -15
  98. package/dist/protocols/xai-images.js +75 -84
  99. package/dist/protocols/xai-responses.d.ts +2 -2
  100. package/dist/protocols/xai-video.d.ts +34 -0
  101. package/dist/protocols/xai-video.js +147 -0
  102. package/dist/protocols/zai-chat.d.ts +13 -1
  103. package/dist/protocols/zai-images.d.ts +9 -13
  104. package/dist/protocols/zai-images.js +59 -57
  105. package/dist/provider-error.js +3 -0
  106. package/dist/providers/alibaba.d.ts +14 -2
  107. package/dist/providers/amazon-bedrock-mantle.d.ts +14 -2
  108. package/dist/providers/amazon-bedrock.d.ts +2 -2
  109. package/dist/providers/assemblyai.d.ts +25 -0
  110. package/dist/providers/assemblyai.js +29 -0
  111. package/dist/providers/azure.d.ts +18 -6
  112. package/dist/providers/baseten.d.ts +24 -0
  113. package/dist/providers/black-forest-labs.d.ts +25 -0
  114. package/dist/providers/black-forest-labs.js +28 -0
  115. package/dist/providers/cartesia.d.ts +24 -0
  116. package/dist/providers/cartesia.js +22 -0
  117. package/dist/providers/cerebras.d.ts +24 -0
  118. package/dist/providers/cerebras.js +6 -1
  119. package/dist/providers/cloudflare-ai-gateway.d.ts +30 -6
  120. package/dist/providers/cloudflare-workers-ai.d.ts +24 -0
  121. package/dist/providers/deepgram.d.ts +29 -0
  122. package/dist/providers/deepgram.js +31 -0
  123. package/dist/providers/deepinfra.d.ts +24 -0
  124. package/dist/providers/deepinfra.js +6 -1
  125. package/dist/providers/deepseek.d.ts +24 -0
  126. package/dist/providers/elevenlabs.d.ts +24 -0
  127. package/dist/providers/elevenlabs.js +28 -0
  128. package/dist/providers/fal.d.ts +29 -0
  129. package/dist/providers/fal.js +33 -0
  130. package/dist/providers/fireworks.d.ts +24 -0
  131. package/dist/providers/google-vertex-chat.d.ts +12 -0
  132. package/dist/providers/google-vertex-responses.d.ts +2 -2
  133. package/dist/providers/google-vertex.d.ts +10 -3
  134. package/dist/providers/google.d.ts +25 -3
  135. package/dist/providers/google.js +11 -2
  136. package/dist/providers/groq.d.ts +24 -0
  137. package/dist/providers/index.d.ts +10 -0
  138. package/dist/providers/index.js +10 -0
  139. package/dist/providers/meta.d.ts +14 -2
  140. package/dist/providers/minimax.d.ts +14 -2
  141. package/dist/providers/moonshot.d.ts +14 -2
  142. package/dist/providers/moonshot.js +3 -3
  143. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  144. package/dist/providers/openai-compatible.d.ts +12 -0
  145. package/dist/providers/openai.d.ts +25 -3
  146. package/dist/providers/openai.js +10 -1
  147. package/dist/providers/openrouter.d.ts +67 -0
  148. package/dist/providers/openrouter.js +13 -1
  149. package/dist/providers/replicate.d.ts +25 -0
  150. package/dist/providers/replicate.js +22 -0
  151. package/dist/providers/runway.d.ts +24 -0
  152. package/dist/providers/runway.js +22 -0
  153. package/dist/providers/stability.d.ts +28 -0
  154. package/dist/providers/stability.js +23 -0
  155. package/dist/providers/togetherai.d.ts +24 -0
  156. package/dist/providers/vercel-ai-gateway.d.ts +41 -0
  157. package/dist/providers/vercel-ai-gateway.js +85 -0
  158. package/dist/providers/xai.d.ts +17 -0
  159. package/dist/providers/xai.js +5 -2
  160. package/dist/providers/zai-coding-plan.d.ts +15 -3
  161. package/dist/providers/zai.d.ts +13 -1
  162. package/dist/route/auth.d.ts +4 -1
  163. package/dist/route/auth.js +6 -0
  164. package/dist/route/client.d.ts +9 -1
  165. package/dist/route/endpoint.d.ts +10 -10
  166. package/dist/route/executor-service.d.ts +12 -0
  167. package/dist/route/executor-service.js +3 -0
  168. package/dist/route/executor.d.ts +4 -9
  169. package/dist/route/executor.js +3 -3
  170. package/dist/route/framing.d.ts +5 -1
  171. package/dist/route/framing.js +9 -0
  172. package/dist/route/index.d.ts +2 -0
  173. package/dist/route/index.js +2 -0
  174. package/dist/route/media-protocol.d.ts +158 -0
  175. package/dist/route/media-protocol.js +96 -0
  176. package/dist/route/media.d.ts +97 -0
  177. package/dist/route/media.js +236 -0
  178. package/dist/schema/errors.d.ts +13 -3
  179. package/dist/schema/errors.js +7 -0
  180. package/dist/schema/events.d.ts +557 -40
  181. package/dist/schema/events.js +35 -2
  182. package/dist/schema/messages.d.ts +95 -8
  183. package/dist/schema/messages.js +8 -6
  184. package/dist/schema/options.d.ts +6 -3
  185. package/dist/schema/options.js +6 -2
  186. package/dist/speech-client.d.ts +21 -0
  187. package/dist/speech-client.js +25 -0
  188. package/dist/speech.d.ts +1150 -0
  189. package/dist/speech.js +119 -0
  190. package/dist/testing.d.ts +72 -8
  191. package/dist/transcription-client.d.ts +28 -0
  192. package/dist/transcription-client.js +44 -0
  193. package/dist/transcription.d.ts +1504 -0
  194. package/dist/transcription.js +133 -0
  195. package/dist/utils/bytes.d.ts +1 -0
  196. package/dist/utils/bytes.js +10 -0
  197. package/dist/utils/media-type.d.ts +7 -0
  198. package/dist/utils/media-type.js +70 -0
  199. package/dist/utils/sanitize.js +3 -1
  200. package/dist/video-client.d.ts +28 -0
  201. package/dist/video-client.js +40 -0
  202. package/dist/video.d.ts +1359 -0
  203. package/dist/video.js +119 -0
  204. package/package.json +7 -3
  205. package/dist/protocols/utils/gemini-tool-schema.d.ts +0 -2
  206. package/dist/protocols/utils/gemini-tool-schema.js +0 -103
  207. package/dist/protocols/utils/image-input.d.ts +0 -21
  208. package/dist/protocols/utils/image-input.js +0 -20
@@ -28,6 +28,12 @@ export declare const route: Route<{
28
28
  readonly image_url: {
29
29
  readonly url: string;
30
30
  };
31
+ } | {
32
+ readonly type: "file";
33
+ readonly file: {
34
+ readonly filename: string;
35
+ readonly file_data: string;
36
+ };
31
37
  })[];
32
38
  } | {
33
39
  readonly role: "user";
@@ -43,6 +49,12 @@ export declare const route: Route<{
43
49
  readonly image_url: {
44
50
  readonly url: string;
45
51
  };
52
+ } | {
53
+ readonly type: "file";
54
+ readonly file: {
55
+ readonly filename: string;
56
+ readonly file_data: string;
57
+ };
46
58
  })[];
47
59
  } | {
48
60
  readonly [x: string]: unknown;
@@ -127,6 +139,12 @@ export declare const routes: Route<{
127
139
  readonly image_url: {
128
140
  readonly url: string;
129
141
  };
142
+ } | {
143
+ readonly type: "file";
144
+ readonly file: {
145
+ readonly filename: string;
146
+ readonly file_data: string;
147
+ };
130
148
  })[];
131
149
  } | {
132
150
  readonly role: "user";
@@ -142,6 +160,12 @@ export declare const routes: Route<{
142
160
  readonly image_url: {
143
161
  readonly url: string;
144
162
  };
163
+ } | {
164
+ readonly type: "file";
165
+ readonly file: {
166
+ readonly filename: string;
167
+ readonly file_data: string;
168
+ };
145
169
  })[];
146
170
  } | {
147
171
  readonly [x: string]: unknown;
@@ -0,0 +1,41 @@
1
+ import { EvaluationModel } from "../experimental/evaluation.js";
2
+ import { type ProviderAuthOption } from "../route/auth-options.js";
3
+ import { HttpOptions, ModelID } from "../schema/index.js";
4
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
5
+ export interface EvaluationOptions {
6
+ readonly [key: string]: unknown;
7
+ readonly gateway?: Readonly<{
8
+ readonly [key: string]: unknown;
9
+ readonly zeroDataRetention?: boolean;
10
+ readonly only?: ReadonlyArray<string>;
11
+ }>;
12
+ }
13
+ export type Options = ProviderAuthOption<"optional"> & {
14
+ readonly baseURL?: string;
15
+ readonly headers?: Record<string, string>;
16
+ readonly http?: HttpOptions.Input;
17
+ };
18
+ export declare const configure: (input?: Options) => {
19
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
20
+ experimental: {
21
+ evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
22
+ };
23
+ configure: (input?: Options) => /*elided*/ any;
24
+ };
25
+ export declare const provider: {
26
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
27
+ experimental: {
28
+ evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
29
+ };
30
+ configure: (input?: Options) => {
31
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
32
+ experimental: {
33
+ evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
34
+ };
35
+ configure: /*elided*/ any;
36
+ };
37
+ };
38
+ export declare const experimental: {
39
+ evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
40
+ };
41
+ export * as VercelAIGateway from "./vercel-ai-gateway.js";
@@ -0,0 +1,85 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Headers, HttpClientRequest } from "effect/unstable/http";
3
+ import { EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationQuestion, EvaluationResponse, EvaluationRounding, } from "../experimental/evaluation.js";
4
+ import { Auth } from "../route/auth.js";
5
+ import { AuthOptions } from "../route/auth-options.js";
6
+ import { AIError, HttpContext, HttpOptions, InvalidProviderOutputError, InvalidRequestError, ModelID, ProviderID, ProviderMetadata, Usage, } from "../schema/index.js";
7
+ export const id = ProviderID.make("vercel-ai-gateway");
8
+ const baseURL = "https://ai-gateway.vercel.sh/v1";
9
+ const Request = Schema.StructWithRest(Schema.Struct({
10
+ model: Schema.String,
11
+ state: EvaluationInput,
12
+ questions: Schema.Record(Schema.String, EvaluationQuestion),
13
+ providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
14
+ }), [Schema.Record(Schema.String, Schema.Any)]);
15
+ const Response = Schema.Struct({
16
+ model: Schema.optional(Schema.String),
17
+ answers: Schema.Record(Schema.String, EvaluationAnswer),
18
+ usage: Schema.optional(Schema.Struct({
19
+ inputTokens: Schema.optional(Schema.Number),
20
+ outputTokens: Schema.optional(Schema.Number),
21
+ })),
22
+ rounding: Schema.optional(EvaluationRounding),
23
+ providerMetadata: Schema.optional(ProviderMetadata),
24
+ });
25
+ export const configure = (input = {}) => {
26
+ const evaluation = (modelID) => EvaluationModel.make({
27
+ id: modelID,
28
+ provider: id,
29
+ http: input.http === undefined ? undefined : HttpOptions.make(input.http),
30
+ route: {
31
+ id: "vercel-evaluation",
32
+ evaluate: (req, send) => Effect.gen(function* () {
33
+ const url = new URL(`${(input.baseURL ?? baseURL).replace(/\/$/, "")}/evaluate`);
34
+ Object.entries(req.http?.query ?? {}).forEach(([key, value]) => url.searchParams.set(key, value));
35
+ const body = yield* Schema.encodeUnknownEffect(Schema.fromJsonString(Request))({
36
+ ...req.http?.body,
37
+ model: req.model.id,
38
+ state: req.state,
39
+ questions: req.questions,
40
+ providerOptions: req.options,
41
+ }).pipe(Effect.mapError((cause) => new AIError({ reason: new InvalidRequestError({ message: cause.message, cause }) })));
42
+ const headers = yield* Auth.toEffect(AuthOptions.bearer(input, ["AI_GATEWAY_API_KEY", "VERCEL_OIDC_TOKEN"]))({
43
+ request: req,
44
+ method: "POST",
45
+ url: url.toString(),
46
+ body,
47
+ headers: Headers.fromInput({ ...input.headers, ...req.http?.headers }),
48
+ });
49
+ const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
50
+ const http = new HttpContext({ url: res.request.url, status: res.status, headers: res.headers });
51
+ const fail = (message, cause, body) => new AIError({
52
+ reason: new InvalidProviderOutputError({
53
+ route: "vercel-evaluation",
54
+ message,
55
+ body,
56
+ http,
57
+ cause,
58
+ }),
59
+ });
60
+ const text = yield* res.text.pipe(Effect.mapError((cause) => fail("Failed to read the Vercel AI Gateway evaluation response", cause)));
61
+ const data = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => fail("Vercel AI Gateway returned an invalid evaluation response", cause, text)));
62
+ return new EvaluationResponse({
63
+ model: ModelID.make(data.model ?? req.model.id),
64
+ answers: data.answers,
65
+ usage: data.usage
66
+ ? new Usage({
67
+ inputTokens: data.usage.inputTokens,
68
+ outputTokens: data.usage.outputTokens,
69
+ totalTokens: data.usage.inputTokens === undefined && data.usage.outputTokens === undefined
70
+ ? undefined
71
+ : (data.usage.inputTokens ?? 0) + (data.usage.outputTokens ?? 0),
72
+ providerMetadata: { gateway: data.usage },
73
+ })
74
+ : undefined,
75
+ rounding: data.rounding,
76
+ providerMetadata: data.providerMetadata,
77
+ });
78
+ }),
79
+ },
80
+ });
81
+ return { id, experimental: { evaluation }, configure };
82
+ };
83
+ export const provider = configure();
84
+ export const experimental = provider.experimental;
85
+ export * as VercelAIGateway from "./vercel-ai-gateway.js";
@@ -16,6 +16,7 @@ export type Settings = ProviderPackage.Settings & XAIProviderOptionsInput & {
16
16
  readonly baseURL?: string;
17
17
  };
18
18
  export type { XAIImageOptions } from "../protocols/xai-images.js";
19
+ export type { XAIVideoOptions } from "../protocols/xai-video.js";
19
20
  declare const responsesRoute: Route<unknown, import("../protocols/open-responses-channel.js").Prepared, {
20
21
  endpoint: import("../route/client.js").CompactOperation;
21
22
  }>;
@@ -35,6 +36,12 @@ export declare const routes: (Route<{
35
36
  readonly image_url: {
36
37
  readonly url: string;
37
38
  };
39
+ } | {
40
+ readonly type: "file";
41
+ readonly file: {
42
+ readonly filename: string;
43
+ readonly file_data: string;
44
+ };
38
45
  })[];
39
46
  } | {
40
47
  readonly role: "user";
@@ -50,6 +57,12 @@ export declare const routes: (Route<{
50
57
  readonly image_url: {
51
58
  readonly url: string;
52
59
  };
60
+ } | {
61
+ readonly type: "file";
62
+ readonly file: {
63
+ readonly filename: string;
64
+ readonly file_data: string;
65
+ };
53
66
  })[];
54
67
  } | {
55
68
  readonly [x: string]: unknown;
@@ -130,6 +143,7 @@ export declare const configure: (input?: LanguageModelOptions) => {
130
143
  }>;
131
144
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
132
145
  image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
146
+ video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
133
147
  configure: (input?: LanguageModelOptions) => /*elided*/ any;
134
148
  };
135
149
  export declare const provider: {
@@ -142,6 +156,7 @@ export declare const provider: {
142
156
  }>;
143
157
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
144
158
  image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
159
+ video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
145
160
  configure: (input?: LanguageModelOptions) => {
146
161
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
147
162
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, {
@@ -152,6 +167,7 @@ export declare const provider: {
152
167
  }>;
153
168
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
154
169
  image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
170
+ video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
155
171
  configure: /*elided*/ any;
156
172
  };
157
173
  };
@@ -161,3 +177,4 @@ export declare const responses: (modelID: string | ModelID) => import("../schema
161
177
  }>;
162
178
  export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
163
179
  export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
180
+ export declare const video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
@@ -6,6 +6,7 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
6
6
  import { OpenResponsesChannel } from "../protocols/open-responses-channel.js";
7
7
  import { XAIResponses } from "../protocols/xai-responses.js";
8
8
  import { XAIImages } from "../protocols/xai-images.js";
9
+ import { XAIVideo } from "../protocols/xai-video.js";
9
10
  export const id = ProviderID.make("xai");
10
11
  const baseURL = "https://api.x.ai/v1";
11
12
  const RESPONSES_WEBSOCKET_ROTATE_AFTER_MS = 24 * 60 * 1000;
@@ -59,7 +60,7 @@ export const configure = (input = {}) => {
59
60
  const chatRoute = configuredChatRoute(input);
60
61
  const responses = (modelID) => responsesRoute.model({ id: modelID });
61
62
  const chat = (modelID) => chatRoute.model({ id: modelID });
62
- const image = (modelID) => XAIImages.model({
63
+ const media = (modelID) => ({
63
64
  id: modelID,
64
65
  auth: auth(input),
65
66
  baseURL: input.baseURL ?? baseURL,
@@ -71,7 +72,8 @@ export const configure = (input = {}) => {
71
72
  model: responses,
72
73
  responses,
73
74
  chat,
74
- image,
75
+ image: (modelID) => XAIImages.model(media(modelID)),
76
+ video: (modelID) => XAIVideo.model(media(modelID)),
75
77
  configure,
76
78
  };
77
79
  };
@@ -86,3 +88,4 @@ export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOpti
86
88
  export const responses = provider.responses;
87
89
  export const chat = provider.chat;
88
90
  export const image = provider.image;
91
+ export const video = provider.video;
@@ -86,8 +86,8 @@ export declare const routes: (Route<{
86
86
  } | {
87
87
  readonly type: "input_file";
88
88
  readonly filename: string;
89
- readonly detail?: string | undefined;
90
89
  readonly file_data?: string | undefined;
90
+ readonly detail?: string | undefined;
91
91
  readonly file_url?: string | undefined;
92
92
  } | {
93
93
  readonly type: "input_text";
@@ -123,8 +123,8 @@ export declare const routes: (Route<{
123
123
  } | {
124
124
  readonly type: "input_file";
125
125
  readonly filename: string;
126
- readonly detail?: string | undefined;
127
126
  readonly file_data?: string | undefined;
127
+ readonly detail?: string | undefined;
128
128
  readonly file_url?: string | undefined;
129
129
  } | {
130
130
  readonly type: "input_text";
@@ -200,6 +200,12 @@ export declare const routes: (Route<{
200
200
  readonly image_url: {
201
201
  readonly url: string;
202
202
  };
203
+ } | {
204
+ readonly type: "file";
205
+ readonly file: {
206
+ readonly filename: string;
207
+ readonly file_data: string;
208
+ };
203
209
  })[];
204
210
  } | {
205
211
  readonly role: "user";
@@ -215,6 +221,12 @@ export declare const routes: (Route<{
215
221
  readonly image_url: {
216
222
  readonly url: string;
217
223
  };
224
+ } | {
225
+ readonly type: "file";
226
+ readonly file: {
227
+ readonly filename: string;
228
+ readonly file_data: string;
229
+ };
218
230
  })[];
219
231
  } | {
220
232
  readonly [x: string]: unknown;
@@ -290,8 +302,8 @@ export declare const routes: (Route<{
290
302
  readonly response_format?: {
291
303
  readonly type: string;
292
304
  } | undefined;
293
- readonly do_sample?: boolean | undefined;
294
305
  readonly request_id?: string | undefined;
306
+ readonly do_sample?: boolean | undefined;
295
307
  }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
296
308
  readonly max_tokens: number;
297
309
  readonly model: string;
@@ -30,6 +30,12 @@ export declare const routes: Route<{
30
30
  readonly image_url: {
31
31
  readonly url: string;
32
32
  };
33
+ } | {
34
+ readonly type: "file";
35
+ readonly file: {
36
+ readonly filename: string;
37
+ readonly file_data: string;
38
+ };
33
39
  })[];
34
40
  } | {
35
41
  readonly role: "user";
@@ -45,6 +51,12 @@ export declare const routes: Route<{
45
51
  readonly image_url: {
46
52
  readonly url: string;
47
53
  };
54
+ } | {
55
+ readonly type: "file";
56
+ readonly file: {
57
+ readonly filename: string;
58
+ readonly file_data: string;
59
+ };
48
60
  })[];
49
61
  } | {
50
62
  readonly [x: string]: unknown;
@@ -120,8 +132,8 @@ export declare const routes: Route<{
120
132
  readonly response_format?: {
121
133
  readonly type: string;
122
134
  } | undefined;
123
- readonly do_sample?: boolean | undefined;
124
135
  readonly request_id?: string | undefined;
136
+ readonly do_sample?: boolean | undefined;
125
137
  }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
126
138
  export declare const configure: (input?: Config) => {
127
139
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -13,7 +13,7 @@ export interface AuthInput {
13
13
  readonly request: {
14
14
  readonly http?: HttpOptions;
15
15
  };
16
- readonly method: "POST" | "GET";
16
+ readonly method: "POST" | "GET" | "PUT" | "DELETE";
17
17
  readonly url: string;
18
18
  readonly body: string;
19
19
  readonly headers: Headers.Headers;
@@ -47,5 +47,8 @@ export declare function header(name: string): (source: Secret | Credential) => D
47
47
  export declare function header(name: string, source: Secret | Credential): Definition;
48
48
  export declare function bearerHeader(name: string): (source: Secret | Credential) => Definition;
49
49
  export declare function bearerHeader(name: string, source: Secret | Credential): Definition;
50
+ /** `Authorization: <scheme> <secret>` for providers whose scheme is not `Bearer`, such as fal's `Key`. */
51
+ export declare function scheme(name: string): (source: Secret | Credential) => Definition;
52
+ export declare function scheme(name: string, source: Secret | Credential): Definition;
50
53
  export declare const toEffect: (input: Definition) => (authInput: AuthInput) => Effect.Effect<Headers.Headers, AIError>;
51
54
  export * as Auth from "./auth.js";
@@ -73,6 +73,12 @@ export function bearerHeader(name, source) {
73
73
  return render;
74
74
  return render(source);
75
75
  }
76
+ export function scheme(name, source) {
77
+ const render = (input) => fromCredential(credentialInput(input), (secret) => ({ authorization: `${name} ${secret}` }));
78
+ if (source === undefined)
79
+ return render;
80
+ return render(source);
81
+ }
76
82
  const toAIError = (error) => {
77
83
  if (error instanceof MissingCredentialError || error instanceof Config.ConfigError) {
78
84
  return new AIError({
@@ -381,6 +381,14 @@ export declare const streamRequest: (request: LLMRequest, options?: StreamOption
381
381
  };
382
382
  } | undefined;
383
383
  readonly namespace?: string | undefined;
384
+ } | {
385
+ readonly type: "media";
386
+ readonly media: import("../media.js").Asset;
387
+ readonly providerMetadata?: {
388
+ readonly [x: string]: {
389
+ readonly [x: string]: unknown;
390
+ };
391
+ } | undefined;
384
392
  } | {
385
393
  readonly type: "step-finish";
386
394
  readonly reason: {
@@ -409,12 +417,12 @@ export declare const streamRequest: (request: LLMRequest, options?: StreamOption
409
417
  } | {
410
418
  readonly type: "provider-error";
411
419
  readonly message: string;
420
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
412
421
  readonly providerMetadata?: {
413
422
  readonly [x: string]: {
414
423
  readonly [x: string]: unknown;
415
424
  };
416
425
  } | undefined;
417
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
418
426
  }, AIError, Service>;
419
427
  export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
420
428
  export declare const Route: {
@@ -1,9 +1,9 @@
1
1
  import type { LLMRequest } from "../schema/index.js";
2
- export interface EndpointInput<Body> {
3
- readonly request: LLMRequest;
2
+ export interface EndpointInput<Body, Request = LLMRequest> {
3
+ readonly request: Request;
4
4
  readonly body: Body;
5
5
  }
6
- export type EndpointPart<Body> = string | ((input: EndpointInput<Body>) => string);
6
+ export type EndpointPart<Body, Request = LLMRequest> = string | ((input: EndpointInput<Body, Request>) => string);
7
7
  /**
8
8
  * Declarative URL construction for one route.
9
9
  *
@@ -13,16 +13,16 @@ export type EndpointPart<Body> = string | ((input: EndpointInput<Body>) => strin
13
13
  *
14
14
  * `path` may be a string or a function of `EndpointInput`, for routes whose
15
15
  * URL embeds the model id, region, or another body field (e.g. Bedrock,
16
- * Gemini).
16
+ * Gemini). Media routes reuse the same shape with their own request type.
17
17
  */
18
- export interface Definition<Body> {
18
+ export interface Definition<Body, Request = LLMRequest> {
19
19
  readonly baseURL?: string;
20
- readonly path: EndpointPart<Body>;
20
+ readonly path: EndpointPart<Body, Request>;
21
21
  readonly query?: Record<string, string>;
22
22
  }
23
- export type EndpointPatch<Body> = Partial<Definition<Body>>;
23
+ export type EndpointPatch<Body, Request = LLMRequest> = Partial<Definition<Body, Request>>;
24
24
  /** Construct an `Endpoint` from a path string or path function. */
25
- export declare const path: <Body>(value: EndpointPart<Body>, options?: Omit<Definition<Body>, "path">) => Definition<Body>;
26
- export declare const merge: <Body>(base: Definition<Body>, patch: EndpointPatch<Body>) => Definition<Body>;
27
- export declare const render: <Body>(endpoint: Definition<Body>, input: EndpointInput<Body>) => URL;
25
+ export declare const path: <Body, Request = LLMRequest>(value: EndpointPart<Body, Request>, options?: Omit<Definition<Body, Request>, "path">) => Definition<Body, Request>;
26
+ export declare const merge: <Body, Request = LLMRequest>(base: Definition<Body, Request>, patch: EndpointPatch<Body, Request>) => Definition<Body, Request>;
27
+ export declare const render: <Body, Request = LLMRequest>(endpoint: Definition<Body, Request>, input: EndpointInput<Body, Request>) => URL;
28
28
  export * as Endpoint from "./endpoint.js";
@@ -0,0 +1,12 @@
1
+ import { Context, type Effect } from "effect";
2
+ import type { HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
3
+ import type { AIError } from "../schema/errors.js";
4
+ export interface Interface {
5
+ readonly execute: (request: HttpClientRequest.HttpClientRequest, middleware?: HttpMiddleware) => Effect.Effect<HttpClientResponse.HttpClientResponse, AIError>;
6
+ }
7
+ export type HttpHandler = (request: HttpClientRequest.HttpClientRequest) => Effect.Effect<HttpClientResponse.HttpClientResponse, Error>;
8
+ export type HttpMiddleware = (request: HttpClientRequest.HttpClientRequest, handler: HttpHandler) => Effect.Effect<HttpClientResponse.HttpClientResponse, Error>;
9
+ declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/RequestExecutor", Interface>;
10
+ export declare class Service extends Service_base {
11
+ }
12
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Context } from "effect";
2
+ export class Service extends Context.Service()("@opencode/AI/RequestExecutor") {
3
+ }
@@ -1,14 +1,9 @@
1
- import { Context, Effect, Layer, Stream } from "effect";
1
+ import { Layer, Stream } from "effect";
2
2
  import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
3
3
  import { HttpContext, AIError } from "../schema/index.js";
4
- export interface Interface {
5
- readonly execute: (request: HttpClientRequest.HttpClientRequest, middleware?: HttpMiddleware) => Effect.Effect<HttpClientResponse.HttpClientResponse, AIError>;
6
- }
7
- export type HttpHandler = (request: HttpClientRequest.HttpClientRequest) => Effect.Effect<HttpClientResponse.HttpClientResponse, Error>;
8
- export type HttpMiddleware = (request: HttpClientRequest.HttpClientRequest, handler: HttpHandler) => Effect.Effect<HttpClientResponse.HttpClientResponse, Error>;
9
- declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/RequestExecutor", Interface>;
10
- export declare class Service extends Service_base {
11
- }
4
+ import { Service, type HttpMiddleware, type Interface } from "./executor-service.js";
5
+ export { Service } from "./executor-service.js";
6
+ export type { HttpHandler, HttpMiddleware, Interface } from "./executor-service.js";
12
7
  export declare const responseHttp: (response: HttpClientResponse.HttpClientResponse) => HttpContext;
13
8
  /** Preserve HTTP diagnostics for executor and externally captured failures alike. */
14
9
  export declare const httpFailure: (input: {
@@ -1,9 +1,9 @@
1
- import { Cause, Context, Effect, Layer, Option, Schema, Stream } from "effect";
1
+ import { Cause, Effect, Layer, Option, Schema, Stream } from "effect";
2
2
  import { FetchHttpClient, Headers, HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse, } from "effect/unstable/http";
3
3
  import { HttpContext, HttpRateLimitDetails, AIError, TransportError } from "../schema/index.js";
4
4
  import { classifyProviderFailure } from "../provider-error.js";
5
- export class Service extends Context.Service()("@opencode/AI/RequestExecutor") {
6
- }
5
+ import { Service } from "./executor-service.js";
6
+ export { Service } from "./executor-service.js";
7
7
  const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)]));
8
8
  const normalizedHeaders = (headers) => Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value]));
9
9
  const retryAfterMs = (headers) => {
@@ -1,4 +1,4 @@
1
- import type { Stream } from "effect";
1
+ import { Stream } from "effect";
2
2
  import type { AIError } from "../schema/index.js";
3
3
  /**
4
4
  * Decode a streaming HTTP response body into provider-protocol frames.
@@ -10,6 +10,8 @@ import type { AIError } from "../schema/index.js";
10
10
  * `[DONE]`; protocols that use it as a terminal select `sseWithDone`.
11
11
  * - AWS event stream — length-prefixed binary frames with CRC checksums.
12
12
  * Each emitted frame is one parsed binary event record.
13
+ * - Media streams — newline-delimited JSON (`lines`) or the whole body as one
14
+ * frame (`document`); chunked binary bodies need no framing.
13
15
  *
14
16
  * The frame type is opaque to this layer; the protocol's event schema decodes
15
17
  * each frame before its state machine handles it.
@@ -26,4 +28,6 @@ export declare const sse: Definition<string>;
26
28
  export declare const sseWithDone: Definition<string>;
27
29
  /** SSE framing restricted to protocol-recognized event names. */
28
30
  export declare const sseEvents: (events: ReadonlySet<string>) => Definition<string>;
31
+ export declare const lines: Definition<string>;
32
+ export declare const document: Definition<string>;
29
33
  export * as Framing from "./framing.js";
@@ -1,3 +1,4 @@
1
+ import { Stream } from "effect";
1
2
  import * as ProviderShared from "../protocols/shared.js";
2
3
  /** Server-Sent Events framing. Used by every JSON-streaming HTTP provider. */
3
4
  export const sse = { id: "sse", frame: ProviderShared.sseFraming };
@@ -11,4 +12,12 @@ export const sseEvents = (events) => ({
11
12
  id: "sse",
12
13
  frame: (bytes) => ProviderShared.sseFraming(bytes, events),
13
14
  });
15
+ export const lines = {
16
+ id: "lines",
17
+ frame: (bytes) => bytes.pipe(Stream.decodeText(), Stream.splitLines, Stream.filter((line) => line.trim().length > 0)),
18
+ };
19
+ export const document = {
20
+ id: "document",
21
+ frame: (bytes) => Stream.fromEffect(Stream.mkString(bytes.pipe(Stream.decodeText()))),
22
+ };
14
23
  export * as Framing from "./framing.js";
@@ -4,6 +4,8 @@ export * from "./executor.js";
4
4
  export { Auth } from "./auth.js";
5
5
  export { AuthOptions } from "./auth-options.js";
6
6
  export { Endpoint } from "./endpoint.js";
7
+ export { MediaRoute } from "./media.js";
8
+ export { MediaProtocol } from "./media-protocol.js";
7
9
  export { Framing } from "./framing.js";
8
10
  export { Protocol } from "./protocol.js";
9
11
  export { HttpTransport, WebSocketTransport } from "./transport/index.js";
@@ -3,6 +3,8 @@ export * from "./executor.js";
3
3
  export { Auth } from "./auth.js";
4
4
  export { AuthOptions } from "./auth-options.js";
5
5
  export { Endpoint } from "./endpoint.js";
6
+ export { MediaRoute } from "./media.js";
7
+ export { MediaProtocol } from "./media-protocol.js";
6
8
  export { Framing } from "./framing.js";
7
9
  export { Protocol } from "./protocol.js";
8
10
  export { HttpTransport, WebSocketTransport } from "./transport/index.js";