@ai-sdk/xai 3.0.80 → 3.0.81
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 +6 -0
- package/dist/index.js +49 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/responses/map-xai-responses-finish-reason.ts +1 -0
- package/src/responses/xai-responses-api.ts +20 -0
- package/src/responses/xai-responses-language-model.ts +28 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.81",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"tsup": "^8",
|
|
39
39
|
"typescript": "5.8.3",
|
|
40
40
|
"zod": "3.25.76",
|
|
41
|
-
"@
|
|
42
|
-
"@ai-
|
|
41
|
+
"@ai-sdk/test-server": "1.0.3",
|
|
42
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"zod": "^3.25.76 || ^4.1.8"
|
|
@@ -518,6 +518,26 @@ export const xaiResponsesChunkSchema = z.union([
|
|
|
518
518
|
output_index: z.number(),
|
|
519
519
|
output: z.string().optional(),
|
|
520
520
|
}),
|
|
521
|
+
z.object({
|
|
522
|
+
type: z.literal('response.incomplete'),
|
|
523
|
+
response: z.object({
|
|
524
|
+
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
525
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
526
|
+
}),
|
|
527
|
+
}),
|
|
528
|
+
z.object({
|
|
529
|
+
type: z.literal('response.failed'),
|
|
530
|
+
response: z.object({
|
|
531
|
+
error: z
|
|
532
|
+
.object({
|
|
533
|
+
code: z.string().nullish(),
|
|
534
|
+
message: z.string(),
|
|
535
|
+
})
|
|
536
|
+
.nullish(),
|
|
537
|
+
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
538
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
539
|
+
}),
|
|
540
|
+
}),
|
|
521
541
|
z.object({
|
|
522
542
|
type: z.literal('response.done'),
|
|
523
543
|
response: xaiResponsesResponseSchema,
|
|
@@ -638,7 +638,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
638
638
|
|
|
639
639
|
if (
|
|
640
640
|
event.type === 'response.done' ||
|
|
641
|
-
event.type === 'response.completed'
|
|
641
|
+
event.type === 'response.completed' ||
|
|
642
|
+
event.type === 'response.incomplete'
|
|
642
643
|
) {
|
|
643
644
|
const response = event.response;
|
|
644
645
|
|
|
@@ -646,7 +647,18 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
646
647
|
usage = convertXaiResponsesUsage(response.usage);
|
|
647
648
|
}
|
|
648
649
|
|
|
649
|
-
if (response.
|
|
650
|
+
if (event.type === 'response.incomplete') {
|
|
651
|
+
const reason =
|
|
652
|
+
'incomplete_details' in response
|
|
653
|
+
? response.incomplete_details?.reason
|
|
654
|
+
: undefined;
|
|
655
|
+
finishReason = {
|
|
656
|
+
unified: reason
|
|
657
|
+
? mapXaiResponsesFinishReason(reason)
|
|
658
|
+
: 'other',
|
|
659
|
+
raw: reason ?? 'incomplete',
|
|
660
|
+
};
|
|
661
|
+
} else if ('status' in response && response.status) {
|
|
650
662
|
finishReason = {
|
|
651
663
|
unified: hasFunctionCall
|
|
652
664
|
? 'tool-calls'
|
|
@@ -658,6 +670,20 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
658
670
|
return;
|
|
659
671
|
}
|
|
660
672
|
|
|
673
|
+
if (event.type === 'response.failed') {
|
|
674
|
+
const reason = event.response.incomplete_details?.reason;
|
|
675
|
+
finishReason = {
|
|
676
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : 'error',
|
|
677
|
+
raw: reason ?? 'error',
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
if (event.response.usage) {
|
|
681
|
+
usage = convertXaiResponsesUsage(event.response.usage);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
|
|
661
687
|
// Custom tool call input streaming - already handled by output_item events
|
|
662
688
|
if (
|
|
663
689
|
event.type === 'response.custom_tool_call_input.delta' ||
|