@ai-sdk/xai 2.0.65 → 2.0.67
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.
- package/CHANGELOG.md +12 -0
- package/dist/index.js +56 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1204,6 +1204,30 @@ var xaiResponsesChunkSchema = z4.union([
|
|
|
1204
1204
|
output_index: z4.number(),
|
|
1205
1205
|
arguments: z4.string()
|
|
1206
1206
|
}),
|
|
1207
|
+
z4.object({
|
|
1208
|
+
type: z4.literal("response.incomplete"),
|
|
1209
|
+
response: z4.object({
|
|
1210
|
+
incomplete_details: z4.object({ reason: z4.string() }).nullish(),
|
|
1211
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1212
|
+
})
|
|
1213
|
+
}),
|
|
1214
|
+
z4.object({
|
|
1215
|
+
type: z4.literal("response.failed"),
|
|
1216
|
+
response: z4.object({
|
|
1217
|
+
error: z4.object({
|
|
1218
|
+
code: z4.string().nullish(),
|
|
1219
|
+
message: z4.string()
|
|
1220
|
+
}).nullish(),
|
|
1221
|
+
incomplete_details: z4.object({ reason: z4.string() }).nullish(),
|
|
1222
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1223
|
+
})
|
|
1224
|
+
}),
|
|
1225
|
+
z4.object({
|
|
1226
|
+
type: z4.literal("error"),
|
|
1227
|
+
code: z4.string().nullish(),
|
|
1228
|
+
message: z4.string(),
|
|
1229
|
+
param: z4.string().nullish()
|
|
1230
|
+
}),
|
|
1207
1231
|
z4.object({
|
|
1208
1232
|
type: z4.literal("response.done"),
|
|
1209
1233
|
response: xaiResponsesResponseSchema
|
|
@@ -1221,6 +1245,7 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1221
1245
|
case "completed":
|
|
1222
1246
|
return "stop";
|
|
1223
1247
|
case "length":
|
|
1248
|
+
case "max_output_tokens":
|
|
1224
1249
|
return "length";
|
|
1225
1250
|
case "tool_calls":
|
|
1226
1251
|
case "function_call":
|
|
@@ -1943,7 +1968,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1943
1968
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1944
1969
|
},
|
|
1945
1970
|
transform(chunk, controller) {
|
|
1946
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
1971
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1947
1972
|
if (options.includeRawChunks) {
|
|
1948
1973
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1949
1974
|
}
|
|
@@ -2065,7 +2090,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2065
2090
|
}
|
|
2066
2091
|
return;
|
|
2067
2092
|
}
|
|
2068
|
-
if (event.type === "response.done" || event.type === "response.completed") {
|
|
2093
|
+
if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
|
|
2069
2094
|
const response2 = event.response;
|
|
2070
2095
|
if (response2.usage) {
|
|
2071
2096
|
const converted = convertXaiResponsesUsage(response2.usage);
|
|
@@ -2075,11 +2100,33 @@ var XaiResponsesLanguageModel = class {
|
|
|
2075
2100
|
usage.reasoningTokens = converted.reasoningTokens;
|
|
2076
2101
|
usage.cachedInputTokens = converted.cachedInputTokens;
|
|
2077
2102
|
}
|
|
2078
|
-
if (
|
|
2103
|
+
if (event.type === "response.incomplete") {
|
|
2104
|
+
const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
|
|
2105
|
+
finishReason = reason ? mapXaiResponsesFinishReason(reason) : "other";
|
|
2106
|
+
} else if ("status" in response2 && response2.status) {
|
|
2079
2107
|
finishReason = hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status);
|
|
2080
2108
|
}
|
|
2081
2109
|
return;
|
|
2082
2110
|
}
|
|
2111
|
+
if (event.type === "response.failed") {
|
|
2112
|
+
const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
|
|
2113
|
+
finishReason = reason ? mapXaiResponsesFinishReason(reason) : "error";
|
|
2114
|
+
if (event.response.usage) {
|
|
2115
|
+
const converted = convertXaiResponsesUsage(
|
|
2116
|
+
event.response.usage
|
|
2117
|
+
);
|
|
2118
|
+
usage.inputTokens = converted.inputTokens;
|
|
2119
|
+
usage.outputTokens = converted.outputTokens;
|
|
2120
|
+
usage.totalTokens = converted.totalTokens;
|
|
2121
|
+
usage.reasoningTokens = converted.reasoningTokens;
|
|
2122
|
+
usage.cachedInputTokens = converted.cachedInputTokens;
|
|
2123
|
+
}
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
if (event.type === "error") {
|
|
2127
|
+
controller.enqueue({ type: "error", error: event });
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2083
2130
|
if (event.type === "response.function_call_arguments.delta") {
|
|
2084
2131
|
const toolCall = ongoingToolCalls[event.output_index];
|
|
2085
2132
|
if (toolCall != null) {
|
|
@@ -2137,15 +2184,15 @@ var XaiResponsesLanguageModel = class {
|
|
|
2137
2184
|
"x_semantic_search",
|
|
2138
2185
|
"x_thread_fetch"
|
|
2139
2186
|
];
|
|
2140
|
-
let toolName = (
|
|
2141
|
-
if (webSearchSubTools.includes((
|
|
2187
|
+
let toolName = (_e = part.name) != null ? _e : "";
|
|
2188
|
+
if (webSearchSubTools.includes((_f = part.name) != null ? _f : "") || part.type === "web_search_call") {
|
|
2142
2189
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2143
|
-
} else if (xSearchSubTools.includes((
|
|
2190
|
+
} else if (xSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "x_search_call") {
|
|
2144
2191
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2145
2192
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2146
2193
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2147
2194
|
}
|
|
2148
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2195
|
+
const toolInput = part.type === "custom_tool_call" ? (_h = part.input) != null ? _h : "" : (_i = part.arguments) != null ? _i : "";
|
|
2149
2196
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2150
2197
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2151
2198
|
seenToolCalls.add(part.id);
|
|
@@ -2198,7 +2245,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2198
2245
|
sourceType: "url",
|
|
2199
2246
|
id: self.config.generateId(),
|
|
2200
2247
|
url: annotation.url,
|
|
2201
|
-
title: (
|
|
2248
|
+
title: (_j = annotation.title) != null ? _j : annotation.url
|
|
2202
2249
|
});
|
|
2203
2250
|
}
|
|
2204
2251
|
}
|
|
@@ -2307,7 +2354,7 @@ var xaiTools = {
|
|
|
2307
2354
|
};
|
|
2308
2355
|
|
|
2309
2356
|
// src/version.ts
|
|
2310
|
-
var VERSION = true ? "2.0.
|
|
2357
|
+
var VERSION = true ? "2.0.67" : "0.0.0-test";
|
|
2311
2358
|
|
|
2312
2359
|
// src/xai-provider.ts
|
|
2313
2360
|
var xaiErrorStructure = {
|