@@ -117,7 +117,7 @@ function handleMessageMetadata(event: AnthropicAiStreamingEvent, state: Streamin
117
117
*/
118
118
function handleContentBlockStart ( event : AnthropicAiStreamingEvent , state : StreamingState ) : void {
119
119
if ( event . type !== 'content_block_start' || typeof event . index !== 'number' || ! event . content_block ) return ;
120
- if ( event . content_block . type === 'tool_use' ) {
120
+ if ( event . content_block . type === 'tool_use' || event . content_block . type === 'server_tool_use' ) {
121
121
state . activeToolBlocks [ event . index ] = {
122
122
id : event . content_block . id ,
123
123
name : event . content_block . name ,
@@ -164,7 +164,13 @@ function handleContentBlockStop(event: AnthropicAiStreamingEvent, state: Streami
164
164
if ( ! active ) return ;
165
165
166
166
const raw = active . inputJsonParts . join ( '' ) ;
167
- const parsedInput = raw ? JSON . parse ( raw ) : { } ;
167
+ let parsedInput : unknown ;
168
+
169
+ try {
170
+ parsedInput = raw ? JSON . parse ( raw ) : { } ;
171
+ } catch ( error ) {
172
+ parsedInput = { __unparsed : raw } ;
173
+ }
168
174
169
175
state . toolCalls . push ( {
170
176
type : 'tool_use' ,
@@ -173,9 +179,8 @@ function handleContentBlockStop(event: AnthropicAiStreamingEvent, state: Streami
173
179
input : parsedInput ,
174
180
} ) ;
175
181
176
- // Avoid deleting a dynamic key; rebuild the map without this index
177
- const remainingEntries = Object . entries ( state . activeToolBlocks ) . filter ( ( [ key ] ) => key !== String ( event . index ) ) ;
178
- state . activeToolBlocks = Object . fromEntries ( remainingEntries ) ;
182
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
183
+ delete state . activeToolBlocks [ event . index ] ;
179
184
}
180
185
181
186
/**
0 commit comments