Skip to content

Commit a06e48c

Browse files
committed
Update progress reporting to display real-time token speed and percentage during intelligent file updates
1 parent c69e81b commit a06e48c

1 file changed

Lines changed: 45 additions & 8 deletions

File tree

‎packages/vscode/src/views/panel/backend/message-handlers/handle-intelligent-update-file-in-review.ts‎

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,26 @@ export const handle_intelligent_update_file_in_review = async (
175175
resolve_receiving = resolve
176176
})
177177

178-
const on_chunk = () => {
178+
// Track progress based on original file length
179+
const original_file_size = file_state.content.length
180+
const estimated_total_tokens = Math.ceil(original_file_size / 4)
181+
let current_progress = 0
182+
let current_tokens_per_second = 0
183+
184+
const on_chunk = (tokens_per_second: number, total_tokens: number) => {
179185
if (!receiving_reported) {
180186
receiving_reported = true
181187
resolve_receiving()
182188
}
189+
190+
current_tokens_per_second = tokens_per_second
191+
192+
if (estimated_total_tokens > 0) {
193+
current_progress = Math.min(
194+
Math.round((total_tokens / estimated_total_tokens) * 100),
195+
100
196+
)
197+
}
183198
}
184199

185200
const content_promise = process_file({
@@ -267,18 +282,40 @@ export const handle_intelligent_update_file_in_review = async (
267282
cancel_token_source.cancel('User cancelled the operation')
268283
})
269284

270-
let receiving_time = 0
271-
const receiving_timer = setInterval(() => {
272-
progress.report({
273-
message: `${(receiving_time / 10).toFixed(1)}s`
274-
})
275-
receiving_time++
285+
let last_reported_progress = 0
286+
let last_reported_tps = -1 // Use -1 to ensure the first report goes through
287+
288+
const progress_timer = setInterval(() => {
289+
if (
290+
current_progress > last_reported_progress ||
291+
current_tokens_per_second !== last_reported_tps
292+
) {
293+
const message =
294+
current_tokens_per_second > 0
295+
? `${current_tokens_per_second} tokens/s`
296+
: 'Receiving'
297+
298+
progress.report({
299+
message: message,
300+
increment: current_progress - last_reported_progress
301+
})
302+
last_reported_progress = current_progress
303+
last_reported_tps = current_tokens_per_second
304+
}
276305
}, 100)
277306

278307
try {
279308
await content_promise
309+
310+
// Ensure we report 100% at the end
311+
if (last_reported_progress < 100) {
312+
progress.report({
313+
message: 'Complete',
314+
increment: 100 - last_reported_progress
315+
})
316+
}
280317
} finally {
281-
clearInterval(receiving_timer)
318+
clearInterval(progress_timer)
282319
}
283320
}
284321
)

0 commit comments

Comments
 (0)