@@ -7,6 +7,20 @@ import OpenAI from "openai"
77import { Package } from "../../../shared/package"
88import axios from "axios"
99
10+ type ErrorWithStatus = Error & { status ?: number }
11+
12+ function getMockCallsOf ( fn : unknown ) : any [ ] {
13+ const isObj = ( v : unknown ) : v is Record < string , unknown > => typeof v === "object" && v !== null
14+ if ( isObj ( fn ) || typeof fn === "function" ) {
15+ const rec = fn as Record < string , unknown >
16+ const mock = rec [ "mock" ]
17+ if ( isObj ( mock ) ) {
18+ const calls = mock [ "calls" ]
19+ if ( Array . isArray ( calls ) ) return calls
20+ }
21+ }
22+ return [ ]
23+ }
1024const mockCreate = vitest . fn ( )
1125const mockResponsesCreate = vitest . fn ( )
1226
@@ -424,9 +438,9 @@ describe("OpenAiHandler", () => {
424438 } )
425439
426440 it ( "should handle rate limiting" , async ( ) => {
427- const rateLimitError = new Error ( "Rate limit exceeded" )
441+ const rateLimitError : ErrorWithStatus = new Error ( "Rate limit exceeded" )
428442 rateLimitError . name = "Error"
429- ; ( rateLimitError as any ) . status = 429
443+ rateLimitError . status = 429
430444 mockCreate . mockRejectedValueOnce ( rateLimitError )
431445
432446 const stream = handler . createMessage ( "system prompt" , testMessages )
@@ -1198,9 +1212,9 @@ describe("OpenAI Compatible - Responses API", () => {
11981212
11991213 it ( "Verbosity (Responses): include when set; if server rejects, retry without it (warn once)" , async ( ) => {
12001214 // First call throws 400 for 'verbosity', second succeeds
1201- mockResponsesCreate . mockImplementationOnce ( ( _opts : any ) => {
1202- const err = new Error ( "Unsupported parameter: 'verbosity'" )
1203- ; ( err as any ) . status = 400
1215+ mockResponsesCreate . mockImplementationOnce ( ( _opts : unknown ) => {
1216+ const err : ErrorWithStatus = new Error ( "Unsupported parameter: 'verbosity'" )
1217+ err . status = 400
12041218 throw err
12051219 } )
12061220
@@ -1295,10 +1309,13 @@ describe("OpenAI Compatible - Responses API", () => {
12951309
12961310 // Ensure SDK constructor was called with normalized baseURL and 'preview' apiVersion (per requirement)
12971311 // Note: AzureOpenAI and OpenAI share same mock constructor; inspect last call
1298- const ctorCalls = vi . mocked ( OpenAI as unknown as any ) . mock . calls as any [ ]
1299- const lastCtorArgs = ctorCalls [ ctorCalls . length - 1 ] ?. [ 0 ] || { }
1300- expect ( lastCtorArgs . baseURL ) . toBe ( "https://sample-name.openai.azure.com/openai/v1" )
1301- expect ( lastCtorArgs . apiVersion ) . toBe ( "preview" )
1312+ const ctorCalls = getMockCallsOf ( OpenAI )
1313+ const lastCall = ctorCalls [ ctorCalls . length - 1 ]
1314+ const lastArg0 = Array . isArray ( lastCall ) ? lastCall [ 0 ] : undefined
1315+ const lastCtorArgs =
1316+ typeof lastArg0 === "object" && lastArg0 !== null ? ( lastArg0 as Record < string , unknown > ) : { }
1317+ expect ( lastCtorArgs [ "baseURL" ] ) . toBe ( "https://sample-name.openai.azure.com/openai/v1" )
1318+ expect ( lastCtorArgs [ "apiVersion" ] ) . toBe ( "preview" )
13021319 } )
13031320
13041321 it ( "streams Responses API when provider returns AsyncIterable" , async ( ) => {
@@ -1461,7 +1478,7 @@ describe("OpenAI Compatible - Responses API (multimodal)", () => {
14611478 {
14621479 type : "image" as const ,
14631480 // Minimal Anthropic-style inline image (base64) block
1464- source : { media_type : "image/png" , data : "BASE64DATA" } as any ,
1481+ source : { type : "base64" as const , media_type : "image/png" , data : "BASE64DATA" } ,
14651482 } ,
14661483 ] ,
14671484 } ,
@@ -1478,7 +1495,7 @@ describe("OpenAI Compatible - Responses API (multimodal)", () => {
14781495
14791496 // Input should be an array (structured input mode)
14801497 expect ( Array . isArray ( args . input ) ) . toBe ( true )
1481- const arr = args . input as any [ ]
1498+ const arr = Array . isArray ( args . input ) ? args . input : [ ]
14821499
14831500 // First element should be Developer preface as input_text
14841501 expect ( arr [ 0 ] ?. role ) . toBe ( "user" )
@@ -1537,7 +1554,7 @@ describe("OpenAI Compatible - Responses API (multimodal)", () => {
15371554 { type : "text" as const , text : "Look at this" } ,
15381555 {
15391556 type : "image" as const ,
1540- source : { media_type : "image/jpeg" , data : "IMGDATA" } as any ,
1557+ source : { type : "base64" as const , media_type : "image/jpeg" , data : "IMGDATA" } ,
15411558 } ,
15421559 ] ,
15431560 } ,
@@ -1648,7 +1665,7 @@ describe("OpenAI Compatible - Responses API conversation continuity", () => {
16481665 for await ( const _ of handler . createMessage (
16491666 "sys" ,
16501667 [ { role : "user" , content : [ { type : "text" as const , text : "Turn 2" } ] } ] ,
1651- { suppressPreviousResponseId : true } as any ,
1668+ { taskId : "test" , suppressPreviousResponseId : true } ,
16521669 ) ) {
16531670 }
16541671
@@ -1668,9 +1685,9 @@ describe("OpenAI Compatible - Responses API parity improvements", () => {
16681685 it ( "retries without previous_response_id when server returns 400 'Previous response ... not found' (non-streaming)" , async ( ) => {
16691686 // First call throws 400 for previous_response_id, second succeeds
16701687 mockResponsesCreate
1671- . mockImplementationOnce ( ( _opts : any ) => {
1672- const err = new Error ( "Previous response rid-bad not found" )
1673- ; ( err as any ) . status = 400
1688+ . mockImplementationOnce ( ( _opts : unknown ) => {
1689+ const err : ErrorWithStatus = new Error ( "Previous response rid-bad not found" )
1690+ err . status = 400
16741691 throw err
16751692 } )
16761693 . mockImplementationOnce ( async ( _opts : any ) => {
@@ -1688,7 +1705,7 @@ describe("OpenAI Compatible - Responses API parity improvements", () => {
16881705 for await ( const ch of h . createMessage (
16891706 "sys" ,
16901707 [ { role : "user" , content : [ { type : "text" as const , text : "Turn" } ] } ] ,
1691- { previousResponseId : "rid-bad" } as any ,
1708+ { taskId : "test" , previousResponseId : "rid-bad" } ,
16921709 ) ) {
16931710 chunks . push ( ch )
16941711 }
@@ -1709,9 +1726,9 @@ describe("OpenAI Compatible - Responses API parity improvements", () => {
17091726 it ( "retries without previous_response_id when server returns 400 (streaming)" , async ( ) => {
17101727 // First call throws, second returns a stream
17111728 mockResponsesCreate
1712- . mockImplementationOnce ( ( _opts : any ) => {
1713- const err = new Error ( "Previous response not found" )
1714- ; ( err as any ) . status = 400
1729+ . mockImplementationOnce ( ( _opts : unknown ) => {
1730+ const err : ErrorWithStatus = new Error ( "Previous response not found" )
1731+ err . status = 400
17151732 throw err
17161733 } )
17171734 . mockImplementationOnce ( async ( _opts : any ) => {
@@ -1734,7 +1751,7 @@ describe("OpenAI Compatible - Responses API parity improvements", () => {
17341751 for await ( const ch of h . createMessage (
17351752 "sys" ,
17361753 [ { role : "user" , content : [ { type : "text" as const , text : "Hi" } ] } ] ,
1737- { previousResponseId : "bad-id" } as any ,
1754+ { taskId : "test" , previousResponseId : "bad-id" } ,
17381755 ) ) {
17391756 out . push ( ch )
17401757 }
@@ -1884,7 +1901,10 @@ describe("OpenAI Compatible - Responses API minimal input parity (new tests)", (
18841901 ]
18851902
18861903 const chunks : any [ ] = [ ]
1887- for await ( const ch of handler . createMessage ( "System Inst" , msgs , { previousResponseId : "prev-1" } as any ) ) {
1904+ for await ( const ch of handler . createMessage ( "System Inst" , msgs , {
1905+ taskId : "test" ,
1906+ previousResponseId : "prev-1" ,
1907+ } ) ) {
18881908 chunks . push ( ch )
18891909 }
18901910
@@ -1914,12 +1934,15 @@ describe("OpenAI Compatible - Responses API minimal input parity (new tests)", (
19141934 role : "user" ,
19151935 content : [
19161936 { type : "text" as const , text : "See" } ,
1917- { type : "image" as const , source : { media_type : "image/png" , data : "IMGDATA" } as any } ,
1937+ {
1938+ type : "image" as const ,
1939+ source : { type : "base64" as const , media_type : "image/png" , data : "IMGDATA" } ,
1940+ } ,
19181941 ] ,
19191942 } ,
19201943 ]
19211944
1922- const iter = handler . createMessage ( "Sys" , msgs , { previousResponseId : "prev-2" } as any )
1945+ const iter = handler . createMessage ( "Sys" , msgs , { taskId : "test" , previousResponseId : "prev-2" } )
19231946 for await ( const _ of iter ) {
19241947 // consume
19251948 }
@@ -1928,7 +1951,7 @@ describe("OpenAI Compatible - Responses API minimal input parity (new tests)", (
19281951 const args = mockResponsesCreate . mock . calls . pop ( ) ?. [ 0 ]
19291952 expect ( Array . isArray ( args . input ) ) . toBe ( true )
19301953
1931- const arr = args . input as any [ ]
1954+ const arr = Array . isArray ( args . input ) ? args . input : [ ]
19321955 expect ( arr . length ) . toBe ( 1 )
19331956 expect ( arr [ 0 ] ?. role ) . toBe ( "user" )
19341957
0 commit comments