@@ -54,8 +54,10 @@ const completionAnswer = [
5454 frame ( "metadataEvent" , { stopReason : "TOOL_USE" } ) ,
5555 ...tail ,
5656] ;
57+ /** A Kiro event-stream response that replays the given frames in order. */
5758function response ( frames : Uint8Array [ ] ) : Response {
5859 return new Response ( new ReadableStream < Uint8Array > ( {
60+ /** Enqueue every frame, then close the stream. */
5961 start ( controller ) {
6062 for ( const value of frames ) controller . enqueue ( value ) ;
6163 controller . close ( ) ;
@@ -64,6 +66,11 @@ function response(frames: Uint8Array[]): Response {
6466}
6567afterEach ( resetKiroThrottleStateForTests ) ;
6668
69+ /**
70+ * Run one Claude Code-shaped turn through the adapter: the first send answers with `first`, the
71+ * bounded retry with `retry`. Returns the client events, the physical send ordinals, every request
72+ * body, and the retry's parsed `conversationState` when a retry was sent.
73+ */
6774async function run ( first : Uint8Array [ ] , retry : Uint8Array [ ] ) {
6875 const adapter = createKiroAdapter ( provider ) ;
6976 const budget = createTranslatorBudget ( ) ;
@@ -73,6 +80,7 @@ async function run(first: Uint8Array[], retry: Uint8Array[]) {
7380 try {
7481 const request = await adapter . buildRequest ( structuredClone ( parsed ) ) ;
7582 const upstream = await adapter . fetchResponse ! ( request , {
83+ /** Record each request body and answer the first send and the retry with their frames. */
7684 executor : ( async ( _url , init ) => {
7785 bodies . push ( String ( init ?. body ) ) ;
7886 return response ( bodies . length === 1 ? first : retry ) ;
0 commit comments