Update transform.ts

This commit is contained in:
suyao 2025-09-22 16:11:19 +08:00
parent 335bf47dbd
commit 634c478e18
No known key found for this signature in database

View File

@ -21,7 +21,7 @@ type contentBlock =
type: 'tool-call' type: 'tool-call'
toolCallId: string toolCallId: string
toolName: string toolName: string
input?: string input: unknown
} }
const contentBlockState = new Map<string, contentBlock>() const contentBlockState = new Map<string, contentBlock>()
@ -122,18 +122,20 @@ function handleUserOrAssistantMessage(message: Extract<SDKMessage, { type: 'assi
contentBlockState.set(block.id, { contentBlockState.set(block.id, {
type: 'tool-call', type: 'tool-call',
toolCallId: block.id, toolCallId: block.id,
toolName: block.name toolName: block.name,
input: block.input
}) })
break break
case 'tool_result': { case 'tool_result': {
logger.debug('Handling tool result:', { block }) logger.debug('Handling tool result:', { block })
logger.debug('contentblockState', { content: contentBlockState }) logger.debug('contentblockState', { content: contentBlockState })
const hasToolCall = contentBlockState.has(block.tool_use_id)
const toolCall = contentBlockState.get(block.tool_use_id) as toolCallBlock const toolCall = contentBlockState.get(block.tool_use_id) as toolCallBlock
chunks.push({ chunks.push({
type: 'tool-result', type: 'tool-result',
toolCallId: block.tool_use_id, toolCallId: block.tool_use_id,
toolName: contentBlockState.has(block.tool_use_id) ? toolCall.toolName : 'Unknown', toolName: hasToolCall ? toolCall.toolName : 'Unknown',
input: '', input: hasToolCall ? toolCall.input : '',
output: block.content output: block.content
}) })
break break