11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- import type { ChunkParser } from "../types" ;
4+ import type { ChunkParser } from "../types"
55
66/**
77 * Parses SSE chunks from Claude Agent SDK agents.
@@ -13,44 +13,44 @@ import type { ChunkParser } from "../types";
1313 * - {"claude_session_id": "..."} → session ID for resumption
1414 */
1515export const parseClaudeAgentSdkChunk : ChunkParser = ( line , callback ) => {
16- if ( ! line . startsWith ( "data: " ) ) return ;
16+ if ( ! line . startsWith ( "data: " ) ) return
1717
18- const data = line . substring ( 6 ) . trim ( ) ;
19- if ( ! data ) return ;
18+ const data = line . substring ( 6 ) . trim ( )
19+ if ( ! data ) return
2020
2121 try {
22- const json = JSON . parse ( data ) ;
22+ const json = JSON . parse ( data )
2323
2424 // Text streaming
2525 if ( typeof json . data === "string" ) {
26- callback ( { type : "text" , content : json . data } ) ;
27- return ;
26+ callback ( { type : "text" , content : json . data } )
27+ return
2828 }
2929
3030 // Tool use — claude-agent-sdk sends complete tool info per event
3131 if ( json . current_tool_use ) {
32- const tool = json . current_tool_use ;
32+ const tool = json . current_tool_use
3333 callback ( {
3434 type : "tool_use_start" ,
3535 toolUseId : tool . toolUseId ,
3636 name : tool . name ,
37- } ) ;
37+ } )
3838 if ( tool . input ) {
3939 callback ( {
4040 type : "tool_use_delta" ,
4141 toolUseId : tool . toolUseId ,
4242 input : JSON . stringify ( tool . input ) ,
43- } ) ;
43+ } )
4444 }
45- return ;
45+ return
4646 }
4747
4848 // Claude session ID for conversation resumption
4949 if ( json . claude_session_id ) {
50- callback ( { type : "lifecycle" , event : "session_id" } ) ;
51- return ;
50+ callback ( { type : "lifecycle" , event : "session_id" } )
51+ return
5252 }
5353 } catch {
54- console . debug ( "Failed to parse claude-agent-sdk event:" , data ) ;
54+ console . debug ( "Failed to parse claude-agent-sdk event:" , data )
5555 }
56- } ;
56+ }
0 commit comments