|
1 | 1 | // Xai plugin module implements code execution shared behavior. |
2 | | -import { readProviderJsonObjectResponse } from "openclaw/plugin-sdk/provider-http"; |
3 | | -import { postTrustedWebToolsJson } from "openclaw/plugin-sdk/provider-web-search"; |
4 | 2 | import { XAI_DEFAULT_MODEL_ID } from "../model-definitions.js"; |
5 | 3 | import { |
6 | | - buildXaiResponsesToolBody, |
| 4 | + requestXaiResponsesTool, |
7 | 5 | requireXaiResponseTextAndCitations, |
8 | 6 | XAI_RESPONSES_ENDPOINT, |
9 | 7 | } from "./responses-tool-shared.js"; |
10 | 8 | import { |
11 | 9 | resolveNormalizedXaiToolModel, |
12 | 10 | resolvePositiveIntegerToolConfig, |
13 | 11 | } from "./tool-config-shared.js"; |
14 | | -import type { XaiWebSearchResponse } from "./web-search-shared.js"; |
15 | 12 |
|
16 | 13 | const XAI_CODE_EXECUTION_ENDPOINT = XAI_RESPONSES_ENDPOINT; |
17 | 14 | const XAI_DEFAULT_CODE_EXECUTION_MODEL = XAI_DEFAULT_MODEL_ID; |
18 | 15 |
|
19 | | -type XaiCodeExecutionResponse = XaiWebSearchResponse & { |
20 | | - output?: Array<{ |
21 | | - type?: string; |
22 | | - }>; |
23 | | -}; |
24 | | - |
25 | 16 | type XaiCodeExecutionResult = { |
26 | 17 | content: string; |
27 | 18 | citations: string[]; |
@@ -70,25 +61,16 @@ export async function requestXaiCodeExecution(params: { |
70 | 61 | maxTurns?: number; |
71 | 62 | task: string; |
72 | 63 | }): Promise<XaiCodeExecutionResult> { |
73 | | - return await postTrustedWebToolsJson( |
| 64 | + return await requestXaiResponsesTool( |
74 | 65 | { |
75 | | - url: XAI_CODE_EXECUTION_ENDPOINT, |
76 | | - timeoutSeconds: params.timeoutSeconds, |
77 | | - apiKey: params.apiKey, |
78 | | - body: buildXaiResponsesToolBody({ |
79 | | - model: params.model, |
80 | | - inputText: params.task, |
81 | | - tools: [{ type: "code_interpreter" }], |
82 | | - maxTurns: params.maxTurns, |
83 | | - reasoningEffort: params.model === XAI_DEFAULT_CODE_EXECUTION_MODEL ? "low" : undefined, |
84 | | - }), |
85 | | - errorLabel: "xAI", |
| 66 | + ...params, |
| 67 | + endpoint: XAI_CODE_EXECUTION_ENDPOINT, |
| 68 | + inputText: params.task, |
| 69 | + tools: [{ type: "code_interpreter" }], |
| 70 | + reasoningEffort: params.model === XAI_DEFAULT_CODE_EXECUTION_MODEL ? "low" : undefined, |
| 71 | + errorLabel: "xAI code execution failed", |
86 | 72 | }, |
87 | | - async (response) => { |
88 | | - const data = (await readProviderJsonObjectResponse( |
89 | | - response, |
90 | | - "xAI code execution failed", |
91 | | - )) as XaiCodeExecutionResponse; |
| 73 | + (data) => { |
92 | 74 | const { content, citations } = requireXaiResponseTextAndCitations( |
93 | 75 | data, |
94 | 76 | "xAI code execution failed", |
|
0 commit comments