@@ -42,6 +42,15 @@ import { translateChunkToAnthropicEvents } from "./stream-translation"
4242
4343const logger = createHandlerLogger ( "messages-handler" )
4444
45+ interface OutLogOptions {
46+ model : string
47+ chunks : number
48+ done : boolean
49+ }
50+
51+ const formatOutLog = ( { model, chunks, done } : OutLogOptions ) : string =>
52+ `\x1b[2K\r↪ ${ model } ${ chunks } ${ done ? " ✓" : "" } `
53+
4554export async function handleCompletion ( c : Context ) {
4655 await checkRateLimit ( state )
4756
@@ -55,10 +64,6 @@ export async function handleCompletion(c: Context) {
5564
5665 const useResponsesApi = shouldUseResponsesApi ( anthropicPayload . model )
5766
58- consola . info (
59- `[/v1/messages] Original model: ${ anthropicPayload . model } , API path: ${ useResponsesApi ? "Responses" : "ChatCompletions" } ` ,
60- )
61-
6267 if ( state . manualApprove ) {
6368 await awaitApproval ( )
6469 }
@@ -77,7 +82,9 @@ const handleWithChatCompletions = async (
7782 anthropicPayload : AnthropicMessagesPayload ,
7883) => {
7984 const openAIPayload = translateToOpenAI ( anthropicPayload )
80- consola . info ( `[/v1/messages] Translated model: ${ openAIPayload . model } ` )
85+ consola . info (
86+ `[/v1/messages] IN ${ anthropicPayload . model } → ${ openAIPayload . model } (ChatCompletions)` ,
87+ )
8188 logger . debug (
8289 "Translated OpenAI request payload:" ,
8390 JSON . stringify ( openAIPayload ) ,
@@ -95,6 +102,9 @@ const handleWithChatCompletions = async (
95102 "Translated Anthropic response:" ,
96103 JSON . stringify ( anthropicResponse ) ,
97104 )
105+ process . stdout . write (
106+ `${ formatOutLog ( { model : openAIPayload . model , chunks : 0 , done : true } ) } \n` ,
107+ )
98108 return c . json ( anthropicResponse )
99109 }
100110
@@ -110,6 +120,7 @@ const handleWithChatCompletions = async (
110120 thinkingBlockOpen : false ,
111121 }
112122
123+ let chunkCount = 0
113124 try {
114125 for await ( const rawEvent of response ) {
115126 logger . debug ( "Copilot raw stream event:" , JSON . stringify ( rawEvent ) )
@@ -121,6 +132,15 @@ const handleWithChatCompletions = async (
121132 continue
122133 }
123134
135+ chunkCount ++
136+ process . stdout . write (
137+ formatOutLog ( {
138+ model : openAIPayload . model ,
139+ chunks : chunkCount ,
140+ done : false ,
141+ } ) ,
142+ )
143+
124144 const chunk = JSON . parse ( rawEvent . data ) as ChatCompletionChunk
125145 const events = translateChunkToAnthropicEvents ( chunk , streamState )
126146
@@ -134,6 +154,9 @@ const handleWithChatCompletions = async (
134154 }
135155 } finally {
136156 clearInterval ( pingInterval )
157+ process . stdout . write (
158+ `${ formatOutLog ( { model : openAIPayload . model , chunks : chunkCount , done : true } ) } \n` ,
159+ )
137160 }
138161 } )
139162}
@@ -144,7 +167,9 @@ const handleWithResponsesApi = async (
144167) => {
145168 const responsesPayload =
146169 translateAnthropicMessagesToResponsesPayload ( anthropicPayload )
147- consola . info ( `[/v1/messages] Using model: ${ responsesPayload . model } ` )
170+ consola . info (
171+ `[/v1/messages] IN ${ anthropicPayload . model } → ${ responsesPayload . model } (Responses)` ,
172+ )
148173 logger . debug (
149174 "Translated Responses payload:" ,
150175 JSON . stringify ( responsesPayload ) ,
@@ -163,6 +188,7 @@ const handleWithResponsesApi = async (
163188
164189 const streamState = createResponsesStreamState ( )
165190
191+ let chunkCount = 0
166192 try {
167193 for await ( const chunk of response ) {
168194 const eventName = chunk . event
@@ -176,6 +202,15 @@ const handleWithResponsesApi = async (
176202 continue
177203 }
178204
205+ chunkCount ++
206+ process . stdout . write (
207+ formatOutLog ( {
208+ model : responsesPayload . model ,
209+ chunks : chunkCount ,
210+ done : false ,
211+ } ) ,
212+ )
213+
179214 logger . debug ( "Responses raw stream event:" , data )
180215
181216 const events = translateResponsesStreamEvent (
@@ -211,6 +246,9 @@ const handleWithResponsesApi = async (
211246 }
212247 } finally {
213248 clearInterval ( pingInterval )
249+ process . stdout . write (
250+ `${ formatOutLog ( { model : responsesPayload . model , chunks : chunkCount , done : true } ) } \n` ,
251+ )
214252 }
215253 } )
216254 }
@@ -226,6 +264,9 @@ const handleWithResponsesApi = async (
226264 "Translated Anthropic response:" ,
227265 JSON . stringify ( anthropicResponse ) ,
228266 )
267+ process . stdout . write (
268+ `${ formatOutLog ( { model : responsesPayload . model , chunks : 0 , done : true } ) } \n` ,
269+ )
229270 return c . json ( anthropicResponse )
230271}
231272
0 commit comments