coder-agent 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +48 -1
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -284,6 +284,47 @@ async function callGeminiAPIWithRotation(apiKey, params, maxRetries = 3, initial
|
|
|
284
284
|
if (!silent) {
|
|
285
285
|
stopSpinner();
|
|
286
286
|
}
|
|
287
|
+
let typewriterQueue = [];
|
|
288
|
+
let typewriterActive = false;
|
|
289
|
+
let resolveTypewriterFinished = null;
|
|
290
|
+
const pushToTypewriter = (text) => {
|
|
291
|
+
typewriterQueue.push(...text.split(""));
|
|
292
|
+
if (!typewriterActive) {
|
|
293
|
+
typewriterActive = true;
|
|
294
|
+
runTypewriterLoop();
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const runTypewriterLoop = async () => {
|
|
298
|
+
while (typewriterQueue.length > 0) {
|
|
299
|
+
const len = typewriterQueue.length;
|
|
300
|
+
let batchSize = 1;
|
|
301
|
+
let delay = 15; // default smooth delay
|
|
302
|
+
if (len > 80) {
|
|
303
|
+
batchSize = 8;
|
|
304
|
+
delay = 1;
|
|
305
|
+
}
|
|
306
|
+
else if (len > 40) {
|
|
307
|
+
batchSize = 4;
|
|
308
|
+
delay = 2;
|
|
309
|
+
}
|
|
310
|
+
else if (len > 20) {
|
|
311
|
+
batchSize = 2;
|
|
312
|
+
delay = 5;
|
|
313
|
+
}
|
|
314
|
+
else if (len > 10) {
|
|
315
|
+
batchSize = 1;
|
|
316
|
+
delay = 8;
|
|
317
|
+
}
|
|
318
|
+
const chars = typewriterQueue.splice(0, batchSize).join("");
|
|
319
|
+
process.stdout.write(chars);
|
|
320
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
321
|
+
}
|
|
322
|
+
typewriterActive = false;
|
|
323
|
+
if (resolveTypewriterFinished) {
|
|
324
|
+
resolveTypewriterFinished();
|
|
325
|
+
resolveTypewriterFinished = null;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
287
328
|
const processChunk = (chunk) => {
|
|
288
329
|
buffer += decoder.decode(chunk, { stream: true });
|
|
289
330
|
const lines = buffer.split("\n");
|
|
@@ -304,7 +345,7 @@ async function callGeminiAPIWithRotation(apiKey, params, maxRetries = 3, initial
|
|
|
304
345
|
if (content) {
|
|
305
346
|
accumulatedContent += content;
|
|
306
347
|
if (!silent) {
|
|
307
|
-
|
|
348
|
+
pushToTypewriter(content);
|
|
308
349
|
}
|
|
309
350
|
}
|
|
310
351
|
const toolCalls = choice.delta?.tool_calls;
|
|
@@ -361,6 +402,12 @@ async function callGeminiAPIWithRotation(apiKey, params, maxRetries = 3, initial
|
|
|
361
402
|
processChunk(value);
|
|
362
403
|
}
|
|
363
404
|
}
|
|
405
|
+
// Wait for the typewriter to finish writing before returning
|
|
406
|
+
if (typewriterActive && !silent) {
|
|
407
|
+
await new Promise((resolve) => {
|
|
408
|
+
resolveTypewriterFinished = resolve;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
364
411
|
const finalResponse = {
|
|
365
412
|
choices: [
|
|
366
413
|
{
|