1+ import { describe , expect , test } from "bun:test" ;
2+ import { createOpenAIChatAdapter } from "../src/adapters/openai-chat" ;
3+ import { routeModel } from "../src/router" ;
4+ import type { OcxConfig } from "../src/types" ;
5+
6+ function configFor ( modelId : string ) : OcxConfig {
7+ return {
8+ port : 10110 ,
9+ defaultProvider : "opencode-zen" ,
10+ providers : {
11+ "opencode-zen" : {
12+ adapter : "openai-chat" ,
13+ baseUrl : "https://opencode.ai/zen/v1" ,
14+ apiKey : "key" ,
15+ models : [ modelId ] ,
16+ } ,
17+ } ,
18+ } ;
19+ }
20+
21+ function buildToolCallBody ( modelId : string , reasoning ?: string ) : {
22+ reasoning_effort ?: string ;
23+ messages : Record < string , unknown > [ ] ;
24+ } {
25+ const route = routeModel ( configFor ( modelId ) , `opencode-zen/${ modelId } ` ) ;
26+ const req = createOpenAIChatAdapter ( route . provider ) . buildRequest ( {
27+ modelId : route . modelId ,
28+ context : {
29+ messages : [
30+ { role : "user" , content : "inspect the repo" , timestamp : 0 } ,
31+ { role : "assistant" , timestamp : 1 , content : [
32+ { type : "thinking" , thinking : "I need to inspect files before answering." } ,
33+ { type : "toolCall" , id : "call_1" , name : "read_file" , arguments : { path : "README.md" } } ,
34+ ] } ,
35+ {
36+ role : "toolResult" ,
37+ toolCallId : "call_1" ,
38+ toolName : "read_file" ,
39+ content : "contents" ,
40+ isError : false ,
41+ timestamp : 2 ,
42+ } ,
43+ ] ,
44+ } ,
45+ stream : true ,
46+ options : { reasoning : reasoning ?? "max" } ,
47+ } ) ;
48+
49+ return JSON . parse ( req . body as string ) as {
50+ reasoning_effort ?: string ;
51+ messages : Record < string , unknown > [ ] ;
52+ } ;
53+ }
54+
55+ describe ( "opencode-zen DeepSeek thinking mode" , ( ) => {
56+ test . each ( [ "deepseek-v4-flash-free" , "deepseek-v4-flash" , "deepseek-v4-pro" ] ) (
57+ "%s replays tool-call reasoning_content and maps Codex efforts (issue #950/#994)" ,
58+ modelId => {
59+ const body = buildToolCallBody ( modelId , "xhigh" ) ;
60+
61+ expect ( body . reasoning_effort ) . toBe ( "max" ) ;
62+ expect ( body . messages [ 1 ] . reasoning_content ) . toBe ( "I need to inspect files before answering." ) ;
63+ expect ( body . messages [ 1 ] ) . toMatchObject ( {
64+ role : "assistant" ,
65+ content : "" ,
66+ tool_calls : [ {
67+ id : "call_1" ,
68+ type : "function" ,
69+ function : { name : "read_file" , arguments : JSON . stringify ( { path : "README.md" } ) } ,
70+ } ] ,
71+ } ) ;
72+ } ,
73+ ) ;
74+
75+ test ( "non-DeepSeek opencode-zen models do not replay reasoning_content" , ( ) => {
76+ const body = buildToolCallBody ( "minimax-m2.7" ) ;
77+
78+ expect ( body . messages [ 1 ] . reasoning_content ) . toBeUndefined ( ) ;
79+ expect ( body . messages [ 1 ] ) . toHaveProperty ( "tool_calls" ) ;
80+ } ) ;
81+ } ) ;
0 commit comments