Open History to see the last commit
1import { openAIProviderTool } from './openai-provider-tool'
2import { getComputerUseToolMetadata } from '@tanstack/ai/adapter-internals'
3import type { ComputerTool } from 'openai/resources/responses/responses'
4import type { Tool } from '@tanstack/ai'
5
6/**
7 * The computer tool: `{ type: 'computer' }`.
8 */
9export type ComputerUseToolConfig = ComputerTool
10
11/**
12 * Converts a standard Tool to OpenAI ComputerUseTool format
13 */
14export function convertComputerUseToolToAdapterFormat(
15 _tool: Tool,
16): ComputerUseToolConfig {
17 return { type: 'computer' }
18}
19
20/**
21 * Creates a standard Tool from ComputerUseTool parameters. The tool name is
22 * the tool type: `computer`.
23 *
24 * Base (non-branded) factory. Providers that need branded return types should
25 * re-wrap this in their own package.
26 */
27export function computerUseTool(toolData: ComputerUseToolConfig): Tool {
28 return openAIProviderTool(
29 {
30 name: toolData.type,
31 description: 'Control a virtual computer',
32 metadata: {
33 ...toolData,
34 },
35 },
36 'computer_use',
37 )
38}
39
40/**
41 * Swaps a portable computer-use tool for the native OpenAI computer tool,
42 * `{ type: 'computer' }`. The result keeps the name `computer` and the
43 * `execute` of the portable tool. Other tools come back unchanged.
44 *
45 * @param tool - A tool from the chat tool list.
46 */
47export function resolveComputerUseTool(tool: Tool): Tool {
48 if (!getComputerUseToolMetadata(tool)) return tool
49 const native = computerUseTool({ type: 'computer' })
50 return { ...native, name: 'computer', execute: tool.execute }
51}