@@ -79,6 +79,7 @@ export interface LLMClient {
7979 readonly temperature : number ;
8080 readonly maxTokens : number ;
8181 readonly thinkingBudget : number ;
82+ readonly reasoningEffort ?: "low" | "medium" | "high" ;
8283 } ;
8384}
8485
@@ -114,6 +115,7 @@ export function createLLMClient(config: LLMConfig): LLMClient {
114115 temperature : config . temperature ?? 0.7 ,
115116 maxTokens : config . maxTokens ?? 8192 ,
116117 thinkingBudget : config . thinkingBudget ?? 0 ,
118+ reasoningEffort : config . reasoningEffort ,
117119 } ;
118120
119121 const apiFormat = config . apiFormat ?? "chat" ;
@@ -218,6 +220,7 @@ export async function chatCompletion(
218220 const resolved = {
219221 temperature : options ?. temperature ?? client . defaults . temperature ,
220222 maxTokens : options ?. maxTokens ?? client . defaults . maxTokens ,
223+ reasoningEffort : client . defaults . reasoningEffort ,
221224 } ;
222225 const onStreamProgress = options ?. onStreamProgress ;
223226 const errorCtx = { baseUrl : client . _openai ?. baseURL ?? "(anthropic)" , model } ;
@@ -321,21 +324,22 @@ async function chatCompletionOpenAIChat(
321324 client : OpenAI ,
322325 model : string ,
323326 messages : ReadonlyArray < LLMMessage > ,
324- options : { readonly temperature : number ; readonly maxTokens : number } ,
327+ options : { readonly temperature : number ; readonly maxTokens : number ; readonly reasoningEffort ?: "low" | "medium" | "high" } ,
325328 webSearch ?: boolean ,
326329 onStreamProgress ?: OnStreamProgress ,
327330) : Promise < LLMResponse > {
328- const stream = await client . chat . completions . create ( {
331+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
332+ const createParams : any = {
329333 model,
330- messages : messages . map ( ( m ) => ( {
331- role : m . role ,
332- content : m . content ,
333- } ) ) ,
334+ messages : messages . map ( ( m ) => ( { role : m . role , content : m . content } ) ) ,
334335 temperature : options . temperature ,
335336 max_tokens : options . maxTokens ,
336337 stream : true ,
337338 ...( webSearch ? { web_search_options : { search_context_size : "medium" as const } } : { } ) ,
338- } ) ;
339+ ...( options . reasoningEffort ? { reasoning_effort : options . reasoningEffort } : { } ) ,
340+ } ;
341+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
342+ const stream = await client . chat . completions . create ( createParams ) as any ;
339343
340344 const chunks : string [ ] = [ ] ;
341345 let inputTokens = 0 ;
@@ -382,16 +386,19 @@ async function chatCompletionOpenAIChatSync(
382386 client : OpenAI ,
383387 model : string ,
384388 messages : ReadonlyArray < LLMMessage > ,
385- options : { readonly temperature : number ; readonly maxTokens : number } ,
389+ options : { readonly temperature : number ; readonly maxTokens : number ; readonly reasoningEffort ?: "low" | "medium" | "high" } ,
386390 _webSearch ?: boolean ,
387391) : Promise < LLMResponse > {
388- const response = await client . chat . completions . create ( {
392+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
393+ const syncParams : any = {
389394 model,
390395 messages : messages . map ( ( m ) => ( { role : m . role , content : m . content } ) ) ,
391396 temperature : options . temperature ,
392397 max_tokens : options . maxTokens ,
393398 stream : false ,
394- } ) ;
399+ ...( options . reasoningEffort ? { reasoning_effort : options . reasoningEffort } : { } ) ,
400+ } ;
401+ const response = await client . chat . completions . create ( syncParams ) ;
395402
396403 const content = response . choices [ 0 ] ?. message ?. content ?? "" ;
397404 if ( ! content ) throw new Error ( "LLM returned empty response" ) ;
0 commit comments