@@ -9,6 +9,7 @@ import type {
99 ToolUnion ,
1010 ToolUseBlock ,
1111} from "@anthropic-ai/sdk/resources/messages/messages" ;
12+ import { logger } from "../shared/logger" ;
1213import { ToolRegistry } from "../tools/registry" ;
1314
1415const MAX_ITERATIONS = 10 ;
@@ -29,6 +30,9 @@ export async function processWithMiniMax(
2930 model : string ,
3031 toolRegistry ?: ToolRegistry ,
3132) : Promise < string > {
33+ const startTime = Date . now ( ) ;
34+ logger . debug ( `[MiniMax] Request → model=${ model } , prompt=${ instruction . length } chars` ) ;
35+
3236 try {
3337 // MiniMax uses Anthropic-compatible API
3438 const client = new Anthropic ( {
@@ -43,6 +47,7 @@ export async function processWithMiniMax(
4347 const messages : MessageParam [ ] = [ { role : "user" , content : instruction } ] ;
4448
4549 for ( let i = 0 ; i < MAX_ITERATIONS ; i ++ ) {
50+ const iterStart = Date . now ( ) ;
4651 const response = await client . messages . create ( {
4752 model,
4853 max_tokens : 4096 ,
@@ -51,6 +56,12 @@ export async function processWithMiniMax(
5156 ...( tools ? { tools } : { } ) ,
5257 } ) ;
5358
59+ logger . debug (
60+ `[MiniMax] Response ← iteration=${ i + 1 } , stop=${ response . stop_reason } , ` +
61+ `tokens=${ response . usage . input_tokens } in/${ response . usage . output_tokens } out, ` +
62+ `time=${ Date . now ( ) - iterStart } ms` ,
63+ ) ;
64+
5465 const textParts = response . content
5566 . filter ( ( block : ContentBlock ) : block is TextBlock => block . type === "text" )
5667 . map ( ( block : TextBlock ) => block . text ) ;
@@ -60,9 +71,12 @@ export async function processWithMiniMax(
6071 ) ;
6172
6273 if ( toolCalls . length === 0 || ! toolRegistry ) {
74+ logger . debug ( `[MiniMax] Done in ${ Date . now ( ) - startTime } ms (${ i + 1 } iteration(s))` ) ;
6375 return textParts . join ( "\n" ) || "No response from MiniMax" ;
6476 }
6577
78+ logger . debug ( `[MiniMax] Tool calls: ${ toolCalls . map ( ( t ) => t . name ) . join ( ", " ) } ` ) ;
79+
6680 messages . push ( { role : "assistant" , content : response . content } ) ;
6781
6882 const toolResults : ToolResultBlockParam [ ] = [ ] ;
@@ -81,8 +95,10 @@ export async function processWithMiniMax(
8195 messages . push ( { role : "user" , content : toolResults } ) ;
8296 }
8397
98+ logger . warn ( `[MiniMax] Reached max ${ MAX_ITERATIONS } iterations` ) ;
8499 return "Reached maximum tool iterations." ;
85100 } catch ( error : unknown ) {
101+ logger . error ( `[MiniMax] API error after ${ Date . now ( ) - startTime } ms` , error ) ;
86102 throw new Error (
87103 `MiniMax API error: ${ error instanceof Error ? error . message : "Unknown error" } ` ,
88104 { cause : error } ,
0 commit comments