11import { describe , expect , test } from "bun:test" ;
22import { createResponsesPassthroughAdapter } from "../src/adapters/openai-responses" ;
3+ import { sanitizeEncryptedContentInPlace } from "../src/server/responses" ;
34
45const provider = {
56 adapter : "openai-responses" ,
@@ -8,6 +9,50 @@ const provider = {
89} ;
910
1011describe ( "OpenAI Responses passthrough sanitization" , ( ) => {
12+ test ( "agent_message conversion removes its non-OpenAI item id" , ( ) => {
13+ const input = [ {
14+ type : "agent_message" ,
15+ id : "019f5e7f-ac31-7610-b69c-43ae41759fce" ,
16+ author : "/root" ,
17+ recipient : "/root/worker" ,
18+ content : [ { type : "encrypted_content" , encrypted_content : "delegated task" } ] ,
19+ } ] ;
20+
21+ expect ( sanitizeEncryptedContentInPlace ( input ) ) . toBe ( 1 ) ;
22+ expect ( input [ 0 ] ) . toEqual ( {
23+ type : "message" ,
24+ role : "user" ,
25+ content : [ { type : "input_text" , text : "delegated task" } ] ,
26+ } ) ;
27+ expect ( input [ 0 ] ) . not . toHaveProperty ( "id" ) ;
28+ } ) ;
29+
30+ test ( "strips only non-msg ids from serialized message input items" , ( ) => {
31+ const adapter = createResponsesPassthroughAdapter ( provider ) ;
32+ const encryptedContent = "opaque-openai-encrypted-content" ;
33+ const input = [
34+ { type : "message" , id : "019f5e7f-ac31-7610-b69c-43ae41759fce" , role : "user" , content : "first" } ,
35+ { type : "message" , id : "msg_abc" , role : "assistant" , content : "second" } ,
36+ { type : "reasoning" , id : "rs_1" , summary : [ ] , encrypted_content : encryptedContent } ,
37+ { type : "function_call" , id : "fc_1" , call_id : "call_1" , name : "ping" , arguments : "{}" } ,
38+ { type : "function_call_output" , call_id : "call_1" , output : "pong" } ,
39+ ] ;
40+ const request = adapter . buildRequest ( {
41+ modelId : "gpt-5.5" ,
42+ context : { messages : [ ] } ,
43+ stream : true ,
44+ options : { } ,
45+ _rawBody : { model : "gpt-5.5" , input } ,
46+ } , { headers : new Headers ( { authorization : "Bearer token" } ) } ) ;
47+ const body = JSON . parse ( request . body ) as { input : Record < string , unknown > [ ] } ;
48+
49+ expect ( body . input [ 0 ] ) . not . toHaveProperty ( "id" ) ;
50+ expect ( body . input [ 1 ] . id ) . toBe ( "msg_abc" ) ;
51+ expect ( body . input [ 2 ] ) . toMatchObject ( { id : "rs_1" , encrypted_content : encryptedContent } ) ;
52+ expect ( body . input [ 3 ] ) . toMatchObject ( { id : "fc_1" , call_id : "call_1" } ) ;
53+ expect ( body . input [ 4 ] ) . toMatchObject ( { type : "function_call_output" , call_id : "call_1" } ) ;
54+ } ) ;
55+
1156 test ( "drops raw reasoning input content before native GPT passthrough" , ( ) => {
1257 const adapter = createResponsesPassthroughAdapter ( provider ) ;
1358 const request = adapter . buildRequest ( {
0 commit comments