@@ -115,6 +115,26 @@ describe("buildOllamaChatRequest", () => {
115115 } ) ;
116116 expect ( request . model ) . toBe ( "library/qwen3:32b" ) ;
117117 } ) ;
118+
119+ it ( "keeps native Ollama replay tool arguments as objects" , ( ) => {
120+ const messages = convertToOllamaMessages ( [
121+ {
122+ role : "assistant" ,
123+ content : [
124+ {
125+ type : "toolCall" ,
126+ name : "gateway" ,
127+ arguments : '{"action":"config.get","path":"gateway.port"}' ,
128+ } ,
129+ ] ,
130+ } ,
131+ ] ) ;
132+
133+ expect ( messages [ 0 ] ?. tool_calls ?. [ 0 ] ?. function . arguments ) . toEqual ( {
134+ action : "config.get" ,
135+ path : "gateway.port" ,
136+ } ) ;
137+ } ) ;
118138} ) ;
119139
120140describe ( "createConfiguredOllamaCompatStreamWrapper" , ( ) => {
@@ -156,6 +176,67 @@ describe("createConfiguredOllamaCompatStreamWrapper", () => {
156176 expect ( payload . options ) . toEqual ( { num_ctx : 65536 } ) ;
157177 } ) ;
158178
179+ it ( "preserves OpenAI-compatible replay tool arguments as strings" , async ( ) => {
180+ let patchedPayload : Record < string , unknown > | undefined ;
181+ const baseStreamFn = vi . fn ( ( _model , _context , options ) => {
182+ options ?. onPayload ?.( {
183+ messages : [
184+ {
185+ role : "assistant" ,
186+ function_call : {
187+ name : "legacy_gateway" ,
188+ arguments : '{"action":"config.get"}' ,
189+ } ,
190+ tool_calls : [
191+ {
192+ id : "call_gateway" ,
193+ type : "function" ,
194+ function : {
195+ name : "gateway" ,
196+ arguments : '{"action":"config.get","path":"gateway.port"}' ,
197+ } ,
198+ } ,
199+ ] ,
200+ } ,
201+ ] ,
202+ } ) ;
203+ return ( async function * ( ) { } ) ( ) ;
204+ } ) ;
205+ const model = {
206+ api : "openai-completions" ,
207+ provider : "ollama" ,
208+ id : "glm-5.2:cloud" ,
209+ contextWindow : 262144 ,
210+ } ;
211+
212+ const wrapped = createConfiguredOllamaCompatStreamWrapper ( {
213+ provider : "ollama" ,
214+ modelId : "glm-5.2:cloud" ,
215+ model,
216+ streamFn : baseStreamFn ,
217+ } as never ) ;
218+
219+ await wrapped ?.(
220+ model as never ,
221+ { messages : [ ] } as never ,
222+ {
223+ onPayload : ( payload : unknown ) => {
224+ patchedPayload = payload as Record < string , unknown > ;
225+ } ,
226+ } as never ,
227+ ) ;
228+
229+ const payload = requireRecord ( patchedPayload , "patched payload" ) ;
230+ const messages = payload . messages as Array < Record < string , unknown > > ;
231+ const assistantMessage = requireRecord ( messages [ 0 ] , "assistant message" ) ;
232+ const functionCall = requireRecord ( assistantMessage . function_call , "function call" ) ;
233+ const toolCalls = assistantMessage . tool_calls as Array < Record < string , unknown > > ;
234+ const toolCallFunction = requireRecord ( toolCalls [ 0 ] ?. function , "tool call function" ) ;
235+ expect ( functionCall . arguments ) . toBe ( '{"action":"config.get"}' ) ;
236+ expect ( toolCallFunction . arguments ) . toBe ( '{"action":"config.get","path":"gateway.port"}' ) ;
237+ expect ( payload . options ) . toEqual ( { num_ctx : 262144 } ) ;
238+ } ) ;
239+
159240 it ( "falls back to contextWindow when configured num_ctx is invalid" , async ( ) => {
160241 let patchedPayload : Record < string , unknown > | undefined ;
161242 const baseStreamFn = vi . fn ( ( _model , _context , options ) => {
0 commit comments