Skip to content

Instantly share code, notes, and snippets.

@slashthinking
Created December 15, 2025 04:48
Show Gist options
  • Select an option

  • Save slashthinking/88bbcb4f9e6488b1f1a0cda275e1e879 to your computer and use it in GitHub Desktop.

Select an option

Save slashthinking/88bbcb4f9e6488b1f1a0cda275e1e879 to your computer and use it in GitHub Desktop.
使用ProviderToolSchema
// packages/anthropic/src/tool/code-execution_20250522.ts
import {
createProviderToolFactoryWithOutputSchema,
lazySchema,
zodSchema,
} from '@ai-sdk/provider-utils';
import { z } from 'zod/v4';
export const codeExecution_20250522OutputSchema = lazySchema(() =>
zodSchema(
z.object({
type: z.literal('code_execution_result'),
stdout: z.string(),
stderr: z.string(),
return_code: z.number(),
}),
),
);
const codeExecution_20250522InputSchema = lazySchema(() =>
zodSchema(
z.object({
code: z.string(),
}),
),
);
const factory = createProviderToolFactoryWithOutputSchema<
{
/**
* The Python code to execute.
*/
code: string;
},
{
type: 'code_execution_result';
stdout: string;
stderr: string;
return_code: number;
},
{}
>({
id: 'anthropic.code_execution_20250522',
inputSchema: codeExecution_20250522InputSchema,
outputSchema: codeExecution_20250522OutputSchema,
});
export const codeExecution_20250522 = (
args: Parameters<typeof factory>[0] = {},
) => {
return factory(args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment