Open History to see the last commit
1import type { Tool as SDKTool } from 'openai/resources/responses/responses'
2import type { Tool } from '@tanstack/ai'
3
4type CodeInterpreterToolConfig = SDKTool.CodeInterpreter
5
6export type { CodeInterpreterToolConfig }
7
8/** @deprecated Renamed to `CodeInterpreterToolConfig`. Will be removed in a future release. */
9export type CodeInterpreterTool = CodeInterpreterToolConfig
10
11/**
12 * Converts a standard Tool to OpenAI CodeInterpreterTool format
13 */
14export function convertCodeInterpreterToolToAdapterFormat(
15 tool: Tool,
16): CodeInterpreterToolConfig {
17 const metadata = tool.metadata as CodeInterpreterToolConfig
18 return {
19 type: 'code_interpreter',
20 container: metadata.container,
21 }
22}
23
24/**
25 * Creates a standard Tool from CodeInterpreterTool parameters.
26 *
27 * Base (non-branded) factory. Providers that need branded return types should
28 * re-wrap this in their own package.
29 */
30export function codeInterpreterTool(
31 container: CodeInterpreterToolConfig,
32): Tool {
33 return {
34 name: 'code_interpreter',
35 description: 'Execute code in a sandboxed environment',
36 metadata: {
37 type: 'code_interpreter',
38 container,
39 },
40 }
41}