Skip to content

Commit b3d0446

Browse files
JaaneekJaaneek
andauthored
feat: switch xai provider to responses API (#18175)
Co-authored-by: Jaaneek <jankiewiczmilosz@gmail.com>
1 parent 949191a commit b3d0446

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
},
113113
"patchedDependencies": {
114114
"@standard-community/standard-openapi@0.2.9": "patches/@standard-community%2Fstandard-openapi@0.2.9.patch",
115-
"@openrouter/ai-sdk-provider@1.5.4": "patches/@openrouter%2Fai-sdk-provider@1.5.4.patch"
115+
"@openrouter/ai-sdk-provider@1.5.4": "patches/@openrouter%2Fai-sdk-provider@1.5.4.patch",
116+
"@ai-sdk/xai@2.0.51": "patches/@ai-sdk%2Fxai@2.0.51.patch"
116117
}
117118
}

packages/opencode/src/provider/provider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ export namespace Provider {
184184
options: {},
185185
}
186186
},
187+
xai: async () => {
188+
return {
189+
autoload: false,
190+
async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
191+
return sdk.responses(modelID)
192+
},
193+
options: {},
194+
}
195+
},
187196
"github-copilot": async () => {
188197
return {
189198
autoload: false,

patches/@ai-sdk%2Fxai@2.0.51.patch

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
diff --git a/dist/index.mjs b/dist/index.mjs
2+
--- a/dist/index.mjs
3+
+++ b/dist/index.mjs
4+
@@ -959,7 +959,7 @@
5+
model: z4.string().nullish(),
6+
object: z4.literal("response"),
7+
output: z4.array(outputItemSchema),
8+
- usage: xaiResponsesUsageSchema,
9+
+ usage: xaiResponsesUsageSchema.nullish(),
10+
status: z4.string()
11+
});
12+
var xaiResponsesChunkSchema = z4.union([
13+
\ No newline at end of file
14+
@@ -1143,6 +1143,18 @@
15+
z4.object({
16+
type: z4.literal("response.completed"),
17+
response: xaiResponsesResponseSchema
18+
+ }),
19+
+ z4.object({
20+
+ type: z4.literal("response.function_call_arguments.delta"),
21+
+ item_id: z4.string(),
22+
+ output_index: z4.number(),
23+
+ delta: z4.string()
24+
+ }),
25+
+ z4.object({
26+
+ type: z4.literal("response.function_call_arguments.done"),
27+
+ item_id: z4.string(),
28+
+ output_index: z4.number(),
29+
+ arguments: z4.string()
30+
})
31+
]);
32+
33+
\ No newline at end of file
34+
@@ -1940,6 +1952,9 @@
35+
if (response2.status) {
36+
finishReason = mapXaiResponsesFinishReason(response2.status);
37+
}
38+
+ if (seenToolCalls.size > 0 && finishReason !== "tool-calls") {
39+
+ finishReason = "tool-calls";
40+
+ }
41+
return;
42+
}
43+
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
44+
\ No newline at end of file
45+
@@ -2024,7 +2039,7 @@
46+
}
47+
}
48+
} else if (part.type === "function_call") {
49+
- if (!seenToolCalls.has(part.call_id)) {
50+
+ if (event.type === "response.output_item.done" && !seenToolCalls.has(part.call_id)) {
51+
seenToolCalls.add(part.call_id);
52+
controller.enqueue({
53+
type: "tool-input-start",
54+
\ No newline at end of file
55+
diff --git a/dist/index.js b/dist/index.js
56+
--- a/dist/index.js
57+
+++ b/dist/index.js
58+
@@ -964,7 +964,7 @@
59+
model: import_v44.z.string().nullish(),
60+
object: import_v44.z.literal("response"),
61+
output: import_v44.z.array(outputItemSchema),
62+
- usage: xaiResponsesUsageSchema,
63+
+ usage: xaiResponsesUsageSchema.nullish(),
64+
status: import_v44.z.string()
65+
});
66+
var xaiResponsesChunkSchema = import_v44.z.union([
67+
\ No newline at end of file
68+
@@ -1148,6 +1148,18 @@
69+
import_v44.z.object({
70+
type: import_v44.z.literal("response.completed"),
71+
response: xaiResponsesResponseSchema
72+
+ }),
73+
+ import_v44.z.object({
74+
+ type: import_v44.z.literal("response.function_call_arguments.delta"),
75+
+ item_id: import_v44.z.string(),
76+
+ output_index: import_v44.z.number(),
77+
+ delta: import_v44.z.string()
78+
+ }),
79+
+ import_v44.z.object({
80+
+ type: import_v44.z.literal("response.function_call_arguments.done"),
81+
+ item_id: import_v44.z.string(),
82+
+ output_index: import_v44.z.number(),
83+
+ arguments: import_v44.z.string()
84+
})
85+
]);
86+
87+
\ No newline at end of file
88+
@@ -1935,6 +1947,9 @@
89+
if (response2.status) {
90+
finishReason = mapXaiResponsesFinishReason(response2.status);
91+
}
92+
+ if (seenToolCalls.size > 0 && finishReason !== "tool-calls") {
93+
+ finishReason = "tool-calls";
94+
+ }
95+
return;
96+
}
97+
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
98+
\ No newline at end of file
99+
@@ -2019,7 +2034,7 @@
100+
}
101+
}
102+
} else if (part.type === "function_call") {
103+
- if (!seenToolCalls.has(part.call_id)) {
104+
+ if (event.type === "response.output_item.done" && !seenToolCalls.has(part.call_id)) {
105+
seenToolCalls.add(part.call_id);
106+
controller.enqueue({
107+
type: "tool-input-start",
108+
\ No newline at end of file

0 commit comments

Comments
 (0)