| |
| |
| |
| |
| |
| |
| |
|
|
| import type { BetaContentBlock } from '@anthropic-ai/sdk/resources/beta/messages.js' |
| import type { z } from 'zod/v4' |
|
|
| |
| |
| |
| export function extractToolUseBlock( |
| content: BetaContentBlock[], |
| toolName: string, |
| ): Extract<BetaContentBlock, { type: 'tool_use' }> | null { |
| const block = content.find(b => b.type === 'tool_use' && b.name === toolName) |
| if (!block || block.type !== 'tool_use') { |
| return null |
| } |
| return block |
| } |
|
|
| |
| |
| |
| |
| export function parseClassifierResponse<T extends z.ZodTypeAny>( |
| toolUseBlock: Extract<BetaContentBlock, { type: 'tool_use' }>, |
| schema: T, |
| ): z.infer<T> | null { |
| const parseResult = schema.safeParse(toolUseBlock.input) |
| if (!parseResult.success) { |
| return null |
| } |
| return parseResult.data |
| } |
|
|