@@ -1530,5 +1530,161 @@ describe("GPT-5 streaming event coverage (additional)", () => {
15301530 expect ( bodyStr ) . not . toContain ( '"verbosity"' )
15311531 } )
15321532 } )
1533+
1534+ describe ( "Store parameter behavior" , ( ) => {
1535+ it ( "should default store to true when openAiStoreEnabled is not set" , async ( ) => {
1536+ const mockFetch = vitest . fn ( ) . mockResolvedValue ( {
1537+ ok : true ,
1538+ body : new ReadableStream ( {
1539+ start ( controller ) {
1540+ controller . enqueue (
1541+ new TextEncoder ( ) . encode ( 'data: {"type":"response.done","response":{}}\n\n' ) ,
1542+ )
1543+ controller . enqueue ( new TextEncoder ( ) . encode ( "data: [DONE]\n\n" ) )
1544+ controller . close ( )
1545+ } ,
1546+ } ) ,
1547+ } )
1548+ ; ( global as any ) . fetch = mockFetch as any
1549+
1550+ // Force SDK path to fail so we use fetch fallback
1551+ mockResponsesCreate . mockRejectedValue ( new Error ( "SDK not available" ) )
1552+
1553+ const handler = new OpenAiNativeHandler ( {
1554+ apiModelId : "gpt-5-2025-08-07" ,
1555+ openAiNativeApiKey : "test-api-key" ,
1556+ // openAiStoreEnabled not set - should default to true
1557+ } )
1558+
1559+ const systemPrompt = "You are a helpful assistant."
1560+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Hello!" } ]
1561+ const stream = handler . createMessage ( systemPrompt , messages )
1562+
1563+ for await ( const _ of stream ) {
1564+ // drain
1565+ }
1566+
1567+ const bodyStr = ( mockFetch . mock . calls [ 0 ] [ 1 ] as any ) . body as string
1568+ const parsedBody = JSON . parse ( bodyStr )
1569+ expect ( parsedBody . store ) . toBe ( true )
1570+ } )
1571+
1572+ it ( "should set store to false when openAiStoreEnabled is false" , async ( ) => {
1573+ const mockFetch = vitest . fn ( ) . mockResolvedValue ( {
1574+ ok : true ,
1575+ body : new ReadableStream ( {
1576+ start ( controller ) {
1577+ controller . enqueue (
1578+ new TextEncoder ( ) . encode ( 'data: {"type":"response.done","response":{}}\n\n' ) ,
1579+ )
1580+ controller . enqueue ( new TextEncoder ( ) . encode ( "data: [DONE]\n\n" ) )
1581+ controller . close ( )
1582+ } ,
1583+ } ) ,
1584+ } )
1585+ ; ( global as any ) . fetch = mockFetch as any
1586+
1587+ // Force SDK path to fail so we use fetch fallback
1588+ mockResponsesCreate . mockRejectedValue ( new Error ( "SDK not available" ) )
1589+
1590+ const handler = new OpenAiNativeHandler ( {
1591+ apiModelId : "gpt-5-2025-08-07" ,
1592+ openAiNativeApiKey : "test-api-key" ,
1593+ openAiStoreEnabled : false , // Explicitly disable store
1594+ } )
1595+
1596+ const systemPrompt = "You are a helpful assistant."
1597+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Hello!" } ]
1598+ const stream = handler . createMessage ( systemPrompt , messages )
1599+
1600+ for await ( const _ of stream ) {
1601+ // drain
1602+ }
1603+
1604+ const bodyStr = ( mockFetch . mock . calls [ 0 ] [ 1 ] as any ) . body as string
1605+ const parsedBody = JSON . parse ( bodyStr )
1606+ expect ( parsedBody . store ) . toBe ( false )
1607+ } )
1608+
1609+ it ( "should respect metadata.store=false even when openAiStoreEnabled is true" , async ( ) => {
1610+ const mockFetch = vitest . fn ( ) . mockResolvedValue ( {
1611+ ok : true ,
1612+ body : new ReadableStream ( {
1613+ start ( controller ) {
1614+ controller . enqueue (
1615+ new TextEncoder ( ) . encode ( 'data: {"type":"response.done","response":{}}\n\n' ) ,
1616+ )
1617+ controller . enqueue ( new TextEncoder ( ) . encode ( "data: [DONE]\n\n" ) )
1618+ controller . close ( )
1619+ } ,
1620+ } ) ,
1621+ } )
1622+ ; ( global as any ) . fetch = mockFetch as any
1623+
1624+ // Force SDK path to fail so we use fetch fallback
1625+ mockResponsesCreate . mockRejectedValue ( new Error ( "SDK not available" ) )
1626+
1627+ const handler = new OpenAiNativeHandler ( {
1628+ apiModelId : "gpt-5-2025-08-07" ,
1629+ openAiNativeApiKey : "test-api-key" ,
1630+ openAiStoreEnabled : true , // Store enabled globally
1631+ } )
1632+
1633+ const systemPrompt = "You are a helpful assistant."
1634+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Hello!" } ]
1635+ const stream = handler . createMessage ( systemPrompt , messages , {
1636+ taskId : "test-task" ,
1637+ store : false , // Override with metadata
1638+ } )
1639+
1640+ for await ( const _ of stream ) {
1641+ // drain
1642+ }
1643+
1644+ const bodyStr = ( mockFetch . mock . calls [ 0 ] [ 1 ] as any ) . body as string
1645+ const parsedBody = JSON . parse ( bodyStr )
1646+ expect ( parsedBody . store ) . toBe ( false )
1647+ } )
1648+
1649+ it ( "should set store to true when both openAiStoreEnabled and metadata.store are not false" , async ( ) => {
1650+ const mockFetch = vitest . fn ( ) . mockResolvedValue ( {
1651+ ok : true ,
1652+ body : new ReadableStream ( {
1653+ start ( controller ) {
1654+ controller . enqueue (
1655+ new TextEncoder ( ) . encode ( 'data: {"type":"response.done","response":{}}\n\n' ) ,
1656+ )
1657+ controller . enqueue ( new TextEncoder ( ) . encode ( "data: [DONE]\n\n" ) )
1658+ controller . close ( )
1659+ } ,
1660+ } ) ,
1661+ } )
1662+ ; ( global as any ) . fetch = mockFetch as any
1663+
1664+ // Force SDK path to fail so we use fetch fallback
1665+ mockResponsesCreate . mockRejectedValue ( new Error ( "SDK not available" ) )
1666+
1667+ const handler = new OpenAiNativeHandler ( {
1668+ apiModelId : "gpt-5-2025-08-07" ,
1669+ openAiNativeApiKey : "test-api-key" ,
1670+ openAiStoreEnabled : true ,
1671+ } )
1672+
1673+ const systemPrompt = "You are a helpful assistant."
1674+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Hello!" } ]
1675+ const stream = handler . createMessage ( systemPrompt , messages , {
1676+ taskId : "test-task" ,
1677+ // store not specified in metadata - should use global setting
1678+ } )
1679+
1680+ for await ( const _ of stream ) {
1681+ // drain
1682+ }
1683+
1684+ const bodyStr = ( mockFetch . mock . calls [ 0 ] [ 1 ] as any ) . body as string
1685+ const parsedBody = JSON . parse ( bodyStr )
1686+ expect ( parsedBody . store ) . toBe ( true )
1687+ } )
1688+ } )
15331689 } )
15341690} )
0 commit comments