@@ -25,7 +25,12 @@ describe("accumulateChunk / finalizeAccumulator", () => {
2525 {
2626 delta : {
2727 tool_calls : [
28- { index : 0 , id : "call_1" , type : "function" , function : { name : "run_check" , arguments : "" } } ,
28+ {
29+ index : 0 ,
30+ id : "call_1" ,
31+ type : "function" ,
32+ function : { name : "run_check" , arguments : "" } ,
33+ } ,
2934 ] ,
3035 } ,
3136 } ,
@@ -35,15 +40,21 @@ describe("accumulateChunk / finalizeAccumulator", () => {
3540 choices : [ { delta : { tool_calls : [ { index : 0 , function : { arguments : '{"re' } } ] } } ] ,
3641 } ) ;
3742 accumulateChunk ( acc , {
38- choices : [ { delta : { tool_calls : [ { index : 0 , function : { arguments : 'source":"doc:x"}' } } ] } } ] ,
43+ choices : [
44+ { delta : { tool_calls : [ { index : 0 , function : { arguments : 'source":"doc:x"}' } } ] } } ,
45+ ] ,
3946 } ) ;
4047 accumulateChunk ( acc , { choices : [ { delta : { } , finish_reason : "tool_calls" } ] } ) ;
4148
4249 const final = finalizeAccumulator ( acc ) ;
4350 expect ( final . finish_reason ) . toBe ( "tool_calls" ) ;
4451 expect ( final . message . content ) . toBeNull ( ) ;
4552 expect ( final . message . tool_calls ) . toEqual ( [
46- { id : "call_1" , type : "function" , function : { name : "run_check" , arguments : '{"resource":"doc:x"}' } } ,
53+ {
54+ id : "call_1" ,
55+ type : "function" ,
56+ function : { name : "run_check" , arguments : '{"resource":"doc:x"}' } ,
57+ } ,
4758 ] ) ;
4859 } ) ;
4960
@@ -54,8 +65,18 @@ describe("accumulateChunk / finalizeAccumulator", () => {
5465 {
5566 delta : {
5667 tool_calls : [
57- { index : 0 , id : "call_a" , type : "function" , function : { name : "a" , arguments : "{}" } } ,
58- { index : 1 , id : "call_b" , type : "function" , function : { name : "b" , arguments : "{}" } } ,
68+ {
69+ index : 0 ,
70+ id : "call_a" ,
71+ type : "function" ,
72+ function : { name : "a" , arguments : "{}" } ,
73+ } ,
74+ {
75+ index : 1 ,
76+ id : "call_b" ,
77+ type : "function" ,
78+ function : { name : "b" , arguments : "{}" } ,
79+ } ,
5980 ] ,
6081 } ,
6182 } ,
@@ -126,13 +147,15 @@ describe("createOpenRouterClient", () => {
126147 }
127148
128149 it ( "streams text deltas and resolves the final message" , async ( ) => {
129- const fetchImpl = vi . fn ( ) . mockResolvedValue (
130- sseResponse ( [
131- 'data: {"choices":[{"delta":{"content":"Hi"}}]}\n\n' ,
132- 'data: {"choices":[{"delta":{},"finish_reason":"stop"}]}\n\n' ,
133- "data: [DONE]\n\n" ,
134- ] ) ,
135- ) ;
150+ const fetchImpl = vi
151+ . fn ( )
152+ . mockResolvedValue (
153+ sseResponse ( [
154+ 'data: {"choices":[{"delta":{"content":"Hi"}}]}\n\n' ,
155+ 'data: {"choices":[{"delta":{},"finish_reason":"stop"}]}\n\n' ,
156+ "data: [DONE]\n\n" ,
157+ ] ) ,
158+ ) ;
136159 const client = createOpenRouterClient ( "sk-test" , fetchImpl ) ;
137160 const stream = client . stream ( {
138161 model : "anthropic/claude-sonnet-5" ,
@@ -195,9 +218,11 @@ describe("createOpenRouterClient", () => {
195218 } ) ;
196219
197220 it ( "throws OpenRouterApiError on a mid-stream inline error chunk" , async ( ) => {
198- const fetchImpl = vi . fn ( ) . mockResolvedValue (
199- sseResponse ( [ 'data: {"error":{"message":"provider overloaded","code":503}}\n\n' ] ) ,
200- ) ;
221+ const fetchImpl = vi
222+ . fn ( )
223+ . mockResolvedValue (
224+ sseResponse ( [ 'data: {"error":{"message":"provider overloaded","code":503}}\n\n' ] ) ,
225+ ) ;
201226 const client = createOpenRouterClient ( "sk-test" , fetchImpl ) ;
202227 const stream = client . stream ( {
203228 model : "anthropic/claude-sonnet-5" ,
@@ -213,11 +238,13 @@ describe("createOpenRouterClient", () => {
213238 // https://openrouter.ai/docs/api_reference/streaming#handling-errors-during-streaming
214239 // — once tokens have streamed, HTTP 200 is already committed, so the
215240 // error arrives as a string type code, not a numeric HTTP status.
216- const fetchImpl = vi . fn ( ) . mockResolvedValue (
217- sseResponse ( [
218- 'data: {"id":"cmpl-abc123","object":"chat.completion.chunk","created":1234567890,"model":"openai/gpt-4o","provider":"openai","error":{"code":"server_error","message":"Provider disconnected unexpectedly"},"choices":[{"index":0,"delta":{"content":""},"finish_reason":"error"}]}\n\n' ,
219- ] ) ,
220- ) ;
241+ const fetchImpl = vi
242+ . fn ( )
243+ . mockResolvedValue (
244+ sseResponse ( [
245+ 'data: {"id":"cmpl-abc123","object":"chat.completion.chunk","created":1234567890,"model":"openai/gpt-4o","provider":"openai","error":{"code":"server_error","message":"Provider disconnected unexpectedly"},"choices":[{"index":0,"delta":{"content":""},"finish_reason":"error"}]}\n\n' ,
246+ ] ) ,
247+ ) ;
221248 const client = createOpenRouterClient ( "sk-test" , fetchImpl ) ;
222249 const stream = client . stream ( {
223250 model : "anthropic/claude-sonnet-5" ,
@@ -312,7 +339,10 @@ describe("createOpenRouterClient", () => {
312339 return Promise . resolve ( new Response ( body , { status : 503 } ) ) ;
313340 }
314341 return Promise . resolve (
315- sseResponse ( [ 'data: {"choices":[{"delta":{},"finish_reason":"stop"}]}\n\n' , "data: [DONE]\n\n" ] ) ,
342+ sseResponse ( [
343+ 'data: {"choices":[{"delta":{},"finish_reason":"stop"}]}\n\n' ,
344+ "data: [DONE]\n\n" ,
345+ ] ) ,
316346 ) ;
317347 } ) ;
318348 const client = createOpenRouterClient ( "sk-test" , fetchImpl ) ;
@@ -333,9 +363,11 @@ describe("createOpenRouterClient", () => {
333363 } ) ;
334364
335365 it ( "does not retry a non-retryable HTTP status" , async ( ) => {
336- const fetchImpl = vi . fn ( ) . mockResolvedValue (
337- new Response ( JSON . stringify ( { error : { message : "Invalid API key" } } ) , { status : 401 } ) ,
338- ) ;
366+ const fetchImpl = vi
367+ . fn ( )
368+ . mockResolvedValue (
369+ new Response ( JSON . stringify ( { error : { message : "Invalid API key" } } ) , { status : 401 } ) ,
370+ ) ;
339371 const client = createOpenRouterClient ( "sk-test" , fetchImpl ) ;
340372 const stream = client . stream ( {
341373 model : "anthropic/claude-sonnet-5" ,
0 commit comments