Skip to content

Commit 3518013

Browse files
authored
feat(ai): add the xAI video entrypoint and keep video provider options (#63707)
1 parent 73abe63 commit 3518013

6 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎packages/ai/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"./providers/vercel-ai-gateway/responses": "./src/providers/vercel-ai-gateway/responses.ts",
137137
"./providers/xai": "./src/providers/xai.ts",
138138
"./providers/xai/images": "./src/providers/xai/images.ts",
139+
"./providers/xai/videos": "./src/providers/xai/videos.ts",
139140
"./providers/zai": "./src/providers/zai.ts",
140141
"./providers/zai-coding-plan": "./src/providers/zai-coding-plan.ts",
141142
"./providers/zai-coding-plan/chat": "./src/providers/zai-coding-plan/chat.ts",

‎packages/ai/src/providers/google.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export const configure = (input: Config = {}) => {
7474
interactionsRoute(input).model<GoogleInteractions.ProviderOptionsInput>({ id: modelID }),
7575
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) =>
7676
GoogleImages.model({ ...media, id: modelID, providerOptions }),
77-
video: (modelID: string | ModelID) => GoogleInteractionsVideo.model({ ...media, id: modelID }),
77+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) =>
78+
GoogleInteractionsVideo.model({ ...media, id: modelID, providerOptions }),
7879
speech: (modelID: string | ModelID) => GoogleSpeech.model({ ...media, id: modelID }),
7980
transcription: (modelID: string | ModelID) => GoogleTranscription.model({ ...media, id: modelID }),
8081
embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) =>
@@ -94,7 +95,10 @@ export const imageModel = (modelID: string, settings?: Settings) => {
9495
const input = toConfig(settings)
9596
return configure(input).image(modelID, input.providerOptions)
9697
}
97-
export const videoModel = (modelID: string, settings?: Settings) => configure(toConfig(settings)).video(modelID)
98+
export const videoModel = (modelID: string, settings?: Settings) => {
99+
const input = toConfig(settings)
100+
return configure(input).video(modelID, input.providerOptions)
101+
}
98102
export const embeddingModel = (modelID: string, settings?: Settings) => {
99103
const input = toConfig(settings)
100104
return configure(input).embedding(modelID, input.providerOptions)

‎packages/ai/src/providers/xai.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export const configure = (input: Config = {}) => {
100100
chat,
101101
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) =>
102102
XAIImages.model({ ...media, id: modelID, providerOptions }),
103-
video: (modelID: string | ModelID) => XAIVideo.model({ ...media, id: modelID }),
103+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) =>
104+
XAIVideo.model({ ...media, id: modelID, providerOptions }),
104105
configure,
105106
}
106107
}
@@ -114,6 +115,10 @@ export const imageModel = (modelID: string, settings?: Settings) => {
114115
const input = toConfig(settings)
115116
return configure(input).image(modelID, input.providerOptions)
116117
}
118+
export const videoModel = (modelID: string, settings?: Settings) => {
119+
const input = toConfig(settings)
120+
return configure(input).video(modelID, input.providerOptions)
121+
}
117122
export const responses = provider.responses
118123
export const chat = provider.chat
119124
export const image = provider.image
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { videoModel as model } from "../xai.js"
2+
export type { Settings } from "../xai.js"

‎packages/ai/test/provider/media-entrypoints.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,15 @@ const videos: ReadonlyArray<Case<VideoModel>> = [
561561
auth: ["x-goog-api-key", "google-key"],
562562
provider: "google",
563563
},
564+
{
565+
name: "xai",
566+
load: async () => {
567+
const { model } = await import("@opencode/ai/providers/xai/videos")
568+
return model("grok-imagine-video-1.5", { ...shared, apiKey: "xai-key" })
569+
},
570+
url: "https://api.x.ai/v1/videos/generations",
571+
auth: ["authorization", "Bearer xai-key"],
572+
},
564573
]
565574

566575
describe("video entrypoints", () => {
@@ -573,6 +582,21 @@ describe("video entrypoints", () => {
573582
)
574583
})
575584

585+
describe("video entrypoint model options", () => {
586+
// Model-level options from settings (as models.dev or config set them) become defaults on every request.
587+
for (const entry of [
588+
{ name: "xai", modelID: "grok-imagine-video-1.5", load: () => import("@opencode/ai/providers/xai/videos") },
589+
{ name: "google", modelID: "gemini-omni-1.2-flash", load: () => import("@opencode/ai/providers/google/videos") },
590+
])
591+
it.effect(`providers/${entry.name}/videos keeps provider options from settings`, () =>
592+
Effect.gen(function* () {
593+
const { model } = yield* Effect.promise(entry.load)
594+
const calls = yield* sentVideo(model(entry.modelID, { apiKey: "key", future_option: true }))
595+
expect(JSON.parse(calls[0].body).future_option).toBe(true)
596+
}),
597+
)
598+
})
599+
576600
describe("decision entrypoints", () => {
577601
for (const entry of decisions)
578602
it.effect(`providers/${entry.name}/decisions sends a configured request`, () =>

‎packages/core/src/provider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ const builtins = new Map<string, () => Promise<unknown>>([
180180
],
181181
["@opencode/ai/providers/xai", () => import("@opencode/ai/providers/xai")],
182182
["@opencode/ai/providers/xai/images", () => import("@opencode/ai/providers/xai/images")],
183+
["@opencode/ai/providers/xai/videos", () => import("@opencode/ai/providers/xai/videos")],
183184
["@opencode/ai/providers/zai", () => import("@opencode/ai/providers/zai")],
184185
["@opencode/ai/providers/zai/chat", () => import("@opencode/ai/providers/zai/chat")],
185186
["@opencode/ai/providers/zai/images", () => import("@opencode/ai/providers/zai/images")],

0 commit comments

Comments
 (0)