@@ -65,17 +65,21 @@ function convertChatToResponsesTools(tools: models.ToolDefinitionJson[]): models
6565 */
6666function convertChatToResponsesInput ( messages : models . Message [ ] ) : models . OpenResponsesInput {
6767 return messages . map ( ( msg ) : models . OpenResponsesEasyInputMessage | models . OpenResponsesFunctionCallOutput => {
68- if ( msg . role === "tool" ) {
68+ // Extract extra fields like cache_control
69+ const { role, content, ...extraFields } = msg as any ;
70+
71+ if ( role === "tool" ) {
6972 const toolMsg = msg as models . ToolResponseMessage ;
7073 return {
7174 type : "function_call_output" ,
7275 callId : toolMsg . toolCallId ,
7376 output : typeof toolMsg . content === "string" ? toolMsg . content : JSON . stringify ( toolMsg . content ) ,
77+ ...extraFields ,
7478 } as models . OpenResponsesFunctionCallOutput ;
7579 }
7680
7781 // Handle assistant messages with tool calls
78- if ( msg . role === "assistant" ) {
82+ if ( role === "assistant" ) {
7983 const assistantMsg = msg as models . AssistantMessage ;
8084 // If it has tool calls, we need to convert them
8185 // For now, just convert the content part
@@ -86,19 +90,21 @@ function convertChatToResponsesInput(messages: models.Message[]): models.OpenRes
8690 : assistantMsg . content === null
8791 ? ""
8892 : JSON . stringify ( assistantMsg . content ) ,
93+ ...extraFields ,
8994 } as models . OpenResponsesEasyInputMessage ;
9095 }
9196
9297 // System, user, developer messages
93- const content = typeof msg . content === "string"
94- ? msg . content
95- : msg . content === null || msg . content === undefined
98+ const convertedContent = typeof content === "string"
99+ ? content
100+ : content === null || content === undefined
96101 ? ""
97- : JSON . stringify ( msg . content ) ;
102+ : JSON . stringify ( content ) ;
98103
99104 return {
100- role : msg . role as "user" | "system" | "developer" ,
101- content,
105+ role : role as "user" | "system" | "developer" ,
106+ content : convertedContent ,
107+ ...extraFields ,
102108 } as models . OpenResponsesEasyInputMessage ;
103109 } ) as models . OpenResponsesInput ;
104110}
0 commit comments