@ai-sdk/xai 4.0.0-beta.26 → 4.0.0-beta.29
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 +25 -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 +4 -4
- 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": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "3.0.0-beta.
|
|
33
|
-
"@ai-sdk/provider": "
|
|
34
|
-
"@ai-sdk/provider
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.0-beta.19",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.14",
|
|
34
|
+
"@ai-sdk/provider": "4.0.0-beta.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "20.17.24",
|
|
@@ -522,6 +522,26 @@ export const xaiResponsesChunkSchema = z.union([
|
|
|
522
522
|
output_index: z.number(),
|
|
523
523
|
output: z.string().optional(),
|
|
524
524
|
}),
|
|
525
|
+
z.object({
|
|
526
|
+
type: z.literal('response.incomplete'),
|
|
527
|
+
response: z.object({
|
|
528
|
+
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
529
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
530
|
+
}),
|
|
531
|
+
}),
|
|
532
|
+
z.object({
|
|
533
|
+
type: z.literal('response.failed'),
|
|
534
|
+
response: z.object({
|
|
535
|
+
error: z
|
|
536
|
+
.object({
|
|
537
|
+
code: z.string().nullish(),
|
|
538
|
+
message: z.string(),
|
|
539
|
+
})
|
|
540
|
+
.nullish(),
|
|
541
|
+
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
542
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
543
|
+
}),
|
|
544
|
+
}),
|
|
525
545
|
z.object({
|
|
526
546
|
type: z.literal('response.done'),
|
|
527
547
|
response: xaiResponsesResponseSchema,
|
|
@@ -671,7 +671,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV4 {
|
|
|
671
671
|
|
|
672
672
|
if (
|
|
673
673
|
event.type === 'response.done' ||
|
|
674
|
-
event.type === 'response.completed'
|
|
674
|
+
event.type === 'response.completed' ||
|
|
675
|
+
event.type === 'response.incomplete'
|
|
675
676
|
) {
|
|
676
677
|
const response = event.response;
|
|
677
678
|
|
|
@@ -679,7 +680,18 @@ export class XaiResponsesLanguageModel implements LanguageModelV4 {
|
|
|
679
680
|
usage = convertXaiResponsesUsage(response.usage);
|
|
680
681
|
}
|
|
681
682
|
|
|
682
|
-
if (response.
|
|
683
|
+
if (event.type === 'response.incomplete') {
|
|
684
|
+
const reason =
|
|
685
|
+
'incomplete_details' in response
|
|
686
|
+
? response.incomplete_details?.reason
|
|
687
|
+
: undefined;
|
|
688
|
+
finishReason = {
|
|
689
|
+
unified: reason
|
|
690
|
+
? mapXaiResponsesFinishReason(reason)
|
|
691
|
+
: 'other',
|
|
692
|
+
raw: reason ?? 'incomplete',
|
|
693
|
+
};
|
|
694
|
+
} else if ('status' in response && response.status) {
|
|
683
695
|
finishReason = {
|
|
684
696
|
unified: hasFunctionCall
|
|
685
697
|
? 'tool-calls'
|
|
@@ -691,6 +703,20 @@ export class XaiResponsesLanguageModel implements LanguageModelV4 {
|
|
|
691
703
|
return;
|
|
692
704
|
}
|
|
693
705
|
|
|
706
|
+
if (event.type === 'response.failed') {
|
|
707
|
+
const reason = event.response.incomplete_details?.reason;
|
|
708
|
+
finishReason = {
|
|
709
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : 'error',
|
|
710
|
+
raw: reason ?? 'error',
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
if (event.response.usage) {
|
|
714
|
+
usage = convertXaiResponsesUsage(event.response.usage);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
|
|
694
720
|
// Custom tool call input streaming - already handled by output_item events
|
|
695
721
|
if (
|
|
696
722
|
event.type === 'response.custom_tool_call_input.delta' ||
|