@ai-sdk/xai 0.0.0-64aae7dd-20260114144918 → 0.0.0-98261322-20260122142521
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 +64 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/01-xai.mdx +697 -0
- package/package.json +11 -6
- package/src/convert-to-xai-chat-messages.test.ts +243 -0
- package/src/convert-to-xai-chat-messages.ts +142 -0
- package/src/convert-xai-chat-usage.test.ts +240 -0
- package/src/convert-xai-chat-usage.ts +23 -0
- package/src/get-response-metadata.ts +19 -0
- package/src/index.ts +14 -0
- package/src/map-xai-finish-reason.ts +19 -0
- package/src/responses/__fixtures__/xai-code-execution-tool.1.json +68 -0
- package/src/responses/__fixtures__/xai-text-streaming.1.chunks.txt +698 -0
- package/src/responses/__fixtures__/xai-text-with-reasoning-streaming-store-false.1.chunks.txt +655 -0
- package/src/responses/__fixtures__/xai-text-with-reasoning-streaming.1.chunks.txt +679 -0
- package/src/responses/__fixtures__/xai-web-search-tool.1.chunks.txt +274 -0
- package/src/responses/__fixtures__/xai-web-search-tool.1.json +90 -0
- package/src/responses/__fixtures__/xai-x-search-tool.1.json +149 -0
- package/src/responses/__fixtures__/xai-x-search-tool.chunks.txt +1757 -0
- package/src/responses/__snapshots__/xai-responses-language-model.test.ts.snap +21929 -0
- package/src/responses/convert-to-xai-responses-input.test.ts +463 -0
- package/src/responses/convert-to-xai-responses-input.ts +206 -0
- package/src/responses/convert-xai-responses-usage.ts +24 -0
- package/src/responses/map-xai-responses-finish-reason.ts +20 -0
- package/src/responses/xai-responses-api.ts +393 -0
- package/src/responses/xai-responses-language-model.test.ts +1803 -0
- package/src/responses/xai-responses-language-model.ts +732 -0
- package/src/responses/xai-responses-options.ts +34 -0
- package/src/responses/xai-responses-prepare-tools.test.ts +497 -0
- package/src/responses/xai-responses-prepare-tools.ts +226 -0
- package/src/tool/code-execution.ts +17 -0
- package/src/tool/index.ts +15 -0
- package/src/tool/view-image.ts +20 -0
- package/src/tool/view-x-video.ts +18 -0
- package/src/tool/web-search.ts +56 -0
- package/src/tool/x-search.ts +63 -0
- package/src/version.ts +6 -0
- package/src/xai-chat-language-model.test.ts +1805 -0
- package/src/xai-chat-language-model.ts +681 -0
- package/src/xai-chat-options.ts +131 -0
- package/src/xai-chat-prompt.ts +44 -0
- package/src/xai-error.ts +19 -0
- package/src/xai-image-settings.ts +1 -0
- package/src/xai-prepare-tools.ts +95 -0
- package/src/xai-provider.test.ts +167 -0
- package/src/xai-provider.ts +162 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function getResponseMetadata({
|
|
2
|
+
id,
|
|
3
|
+
model,
|
|
4
|
+
created,
|
|
5
|
+
created_at,
|
|
6
|
+
}: {
|
|
7
|
+
id?: string | undefined | null;
|
|
8
|
+
created?: number | undefined | null;
|
|
9
|
+
created_at?: number | undefined | null;
|
|
10
|
+
model?: string | undefined | null;
|
|
11
|
+
}) {
|
|
12
|
+
const unixTime = created ?? created_at;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
id: id ?? undefined,
|
|
16
|
+
modelId: model ?? undefined,
|
|
17
|
+
timestamp: unixTime != null ? new Date(unixTime * 1000) : undefined,
|
|
18
|
+
};
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { XaiProviderOptions } from './xai-chat-options';
|
|
2
|
+
export type { XaiErrorData } from './xai-error';
|
|
3
|
+
export type { XaiResponsesProviderOptions } from './responses/xai-responses-options';
|
|
4
|
+
export { createXai, xai } from './xai-provider';
|
|
5
|
+
export type { XaiProvider, XaiProviderSettings } from './xai-provider';
|
|
6
|
+
export {
|
|
7
|
+
codeExecution,
|
|
8
|
+
viewImage,
|
|
9
|
+
viewXVideo,
|
|
10
|
+
webSearch,
|
|
11
|
+
xSearch,
|
|
12
|
+
xaiTools,
|
|
13
|
+
} from './tool';
|
|
14
|
+
export { VERSION } from './version';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LanguageModelV3FinishReason } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
export function mapXaiFinishReason(
|
|
4
|
+
finishReason: string | null | undefined,
|
|
5
|
+
): LanguageModelV3FinishReason['unified'] {
|
|
6
|
+
switch (finishReason) {
|
|
7
|
+
case 'stop':
|
|
8
|
+
return 'stop';
|
|
9
|
+
case 'length':
|
|
10
|
+
return 'length';
|
|
11
|
+
case 'tool_calls':
|
|
12
|
+
case 'function_call':
|
|
13
|
+
return 'tool-calls';
|
|
14
|
+
case 'content_filter':
|
|
15
|
+
return 'content-filter';
|
|
16
|
+
default:
|
|
17
|
+
return 'other';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"created_at": 1761768921,
|
|
3
|
+
"id": "5138abcf-4c4e-b0ab-7e0b-f4c81b98f455_us-east-1",
|
|
4
|
+
"max_output_tokens": null,
|
|
5
|
+
"model": "grok-4-fast-reasoning",
|
|
6
|
+
"object": "response",
|
|
7
|
+
"output": [
|
|
8
|
+
{
|
|
9
|
+
"arguments": "{\"code\":\"def fibonacci(n):\\n if n <= 0:\\n return 0\\n elif n == 1:\\n return 1\\n else:\\n a, b = 0, 1\\n for _ in range(2, n + 1):\\n a, b = b, a + b\\n return b\\n\\nprint(fibonacci(10))\"}",
|
|
10
|
+
"call_id": "",
|
|
11
|
+
"name": "code_execution",
|
|
12
|
+
"type": "code_interpreter_call",
|
|
13
|
+
"id": "fc_5138abcf-4c4e-b0ab-7e0b-f4c81b98f455_us-east-1_0",
|
|
14
|
+
"status": "completed"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"content": [
|
|
18
|
+
{
|
|
19
|
+
"type": "output_text",
|
|
20
|
+
"text": "55",
|
|
21
|
+
"logprobs": [],
|
|
22
|
+
"annotations": []
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"id": "msg_5138abcf-4c4e-b0ab-7e0b-f4c81b98f455_us-east-1",
|
|
26
|
+
"role": "assistant",
|
|
27
|
+
"type": "message",
|
|
28
|
+
"status": "completed"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"parallel_tool_calls": true,
|
|
32
|
+
"previous_response_id": null,
|
|
33
|
+
"reasoning": {
|
|
34
|
+
"effort": null,
|
|
35
|
+
"summary": null
|
|
36
|
+
},
|
|
37
|
+
"temperature": null,
|
|
38
|
+
"text": {
|
|
39
|
+
"format": {
|
|
40
|
+
"type": "text"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"tool_choice": "auto",
|
|
44
|
+
"tools": [
|
|
45
|
+
{
|
|
46
|
+
"type": "code_interpreter"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"top_p": null,
|
|
50
|
+
"usage": {
|
|
51
|
+
"input_tokens": 1606,
|
|
52
|
+
"input_tokens_details": {
|
|
53
|
+
"cached_tokens": 1235
|
|
54
|
+
},
|
|
55
|
+
"output_tokens": 292,
|
|
56
|
+
"output_tokens_details": {
|
|
57
|
+
"reasoning_tokens": 190
|
|
58
|
+
},
|
|
59
|
+
"total_tokens": 1898,
|
|
60
|
+
"num_sources_used": 0,
|
|
61
|
+
"num_server_side_tools_used": 1
|
|
62
|
+
},
|
|
63
|
+
"user": null,
|
|
64
|
+
"incomplete_details": null,
|
|
65
|
+
"status": "completed",
|
|
66
|
+
"store": true,
|
|
67
|
+
"metadata": {}
|
|
68
|
+
}
|