@ai-sdk/xai 3.0.53 → 3.0.54
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 +36 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/responses/xai-responses-api.ts +13 -0
- package/src/responses/xai-responses-language-model.ts +34 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.54",
|
|
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": "2.0.29",
|
|
32
33
|
"@ai-sdk/provider": "3.0.8",
|
|
33
|
-
"@ai-sdk/provider-utils": "4.0.14"
|
|
34
|
-
"@ai-sdk/openai-compatible": "2.0.29"
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.14"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "20.17.24",
|
|
@@ -460,6 +460,19 @@ export const xaiResponsesChunkSchema = z.union([
|
|
|
460
460
|
output_index: z.number(),
|
|
461
461
|
input: z.string(),
|
|
462
462
|
}),
|
|
463
|
+
// Function call arguments streaming events (standard function tools)
|
|
464
|
+
z.object({
|
|
465
|
+
type: z.literal('response.function_call_arguments.delta'),
|
|
466
|
+
item_id: z.string(),
|
|
467
|
+
output_index: z.number(),
|
|
468
|
+
delta: z.string(),
|
|
469
|
+
}),
|
|
470
|
+
z.object({
|
|
471
|
+
type: z.literal('response.function_call_arguments.done'),
|
|
472
|
+
item_id: z.string(),
|
|
473
|
+
output_index: z.number(),
|
|
474
|
+
arguments: z.string(),
|
|
475
|
+
}),
|
|
463
476
|
z.object({
|
|
464
477
|
type: z.literal('response.mcp_call.in_progress'),
|
|
465
478
|
item_id: z.string(),
|
|
@@ -450,6 +450,13 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
450
450
|
const contentBlocks: Record<string, { type: 'text' }> = {};
|
|
451
451
|
const seenToolCalls = new Set<string>();
|
|
452
452
|
|
|
453
|
+
// Track ongoing function calls by output_index so we can stream
|
|
454
|
+
// arguments via response.function_call_arguments.delta events.
|
|
455
|
+
const ongoingToolCalls: Record<
|
|
456
|
+
number,
|
|
457
|
+
{ toolName: string; toolCallId: string } | undefined
|
|
458
|
+
> = {};
|
|
459
|
+
|
|
453
460
|
const activeReasoning: Record<
|
|
454
461
|
string,
|
|
455
462
|
{ encryptedContent?: string | null }
|
|
@@ -647,6 +654,24 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
647
654
|
return;
|
|
648
655
|
}
|
|
649
656
|
|
|
657
|
+
// Function call arguments streaming (standard function tools)
|
|
658
|
+
if (event.type === 'response.function_call_arguments.delta') {
|
|
659
|
+
const toolCall = ongoingToolCalls[event.output_index];
|
|
660
|
+
if (toolCall != null) {
|
|
661
|
+
controller.enqueue({
|
|
662
|
+
type: 'tool-input-delta',
|
|
663
|
+
id: toolCall.toolCallId,
|
|
664
|
+
delta: event.delta,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (event.type === 'response.function_call_arguments.done') {
|
|
670
|
+
// Arguments are fully received; output_item.done will
|
|
671
|
+
// emit tool-input-end and tool-call with the final arguments.
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
|
|
650
675
|
if (
|
|
651
676
|
event.type === 'response.output_item.added' ||
|
|
652
677
|
event.type === 'response.output_item.done'
|
|
@@ -867,20 +892,21 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
867
892
|
}
|
|
868
893
|
}
|
|
869
894
|
} else if (part.type === 'function_call') {
|
|
870
|
-
if (
|
|
871
|
-
|
|
895
|
+
if (event.type === 'response.output_item.added') {
|
|
896
|
+
// Track the call so function_call_arguments.delta events
|
|
897
|
+
// can stream the arguments incrementally.
|
|
898
|
+
ongoingToolCalls[event.output_index] = {
|
|
899
|
+
toolName: part.name,
|
|
900
|
+
toolCallId: part.call_id,
|
|
901
|
+
};
|
|
872
902
|
|
|
873
903
|
controller.enqueue({
|
|
874
904
|
type: 'tool-input-start',
|
|
875
905
|
id: part.call_id,
|
|
876
906
|
toolName: part.name,
|
|
877
907
|
});
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
type: 'tool-input-delta',
|
|
881
|
-
id: part.call_id,
|
|
882
|
-
delta: part.arguments,
|
|
883
|
-
});
|
|
908
|
+
} else if (event.type === 'response.output_item.done') {
|
|
909
|
+
ongoingToolCalls[event.output_index] = undefined;
|
|
884
910
|
|
|
885
911
|
controller.enqueue({
|
|
886
912
|
type: 'tool-input-end',
|