Open History to see the last commit
1import type { FunctionShellTool as ShellToolConfig } from 'openai/resources/responses/responses'
2import type { Tool } from '@tanstack/ai'
3
4export type { ShellToolConfig }
5
6/** @deprecated Renamed to `ShellToolConfig`. Will be removed in a future release. */
7export type ShellTool = ShellToolConfig
8
9/**
10 * Config accepted by {@link shellTool}. `environment` mirrors the OpenAI
11 * Responses API shell tool environment (e.g. `container_auto` + `skills`).
12 * Typed via indexed access so it tracks the installed SDK without naming the
13 * union members directly.
14 */
15export interface ShellToolFactoryConfig {
16 environment?: NonNullable<ShellToolConfig['environment']>
17}
18
19/**
20 * Converts a standard Tool to OpenAI ShellTool format, preserving any
21 * `environment` (container config + skills) stored in metadata.
22 */
23export function convertShellToolToAdapterFormat(tool: Tool): ShellToolConfig {
24 const metadata = (tool.metadata ?? {}) as ShellToolFactoryConfig
25 return {
26 type: 'shell',
27 ...(metadata.environment !== undefined && {
28 environment: metadata.environment,
29 }),
30 }
31}
32
33/**
34 * Creates a standard Tool from ShellTool parameters.
35 *
36 * Base (non-branded) factory. Providers that need branded return types should
37 * re-wrap this in their own package.
38 */
39export function shellTool(config: ShellToolFactoryConfig = {}): Tool {
40 return {
41 name: 'shell',
42 description: 'Execute shell commands',
43 metadata: {
44 ...(config.environment !== undefined && {
45 environment: config.environment,
46 }),
47 },
48 }
49}