@kendoo.agentdesk/agentdesk 0.6.2 → 0.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/cli/team.mjs +21 -2
- package/package.json +1 -1
package/cli/team.mjs
CHANGED
|
@@ -324,12 +324,25 @@ export async function runTeam(taskId, opts = {}) {
|
|
|
324
324
|
console.log("\n━━━ INTAKE ━━━\n");
|
|
325
325
|
vizSend({ type: "phase:change", phase: "INTAKE" });
|
|
326
326
|
|
|
327
|
+
let totalInputTokens = 0;
|
|
328
|
+
let totalOutputTokens = 0;
|
|
329
|
+
|
|
327
330
|
const rl = createInterface({ input: child.stdout });
|
|
328
331
|
|
|
329
332
|
for await (const line of rl) {
|
|
330
333
|
try {
|
|
331
334
|
const event = JSON.parse(line);
|
|
332
335
|
|
|
336
|
+
// Track token usage from any event that reports it
|
|
337
|
+
if (event.usage) {
|
|
338
|
+
if (event.usage.input_tokens) totalInputTokens = Math.max(totalInputTokens, event.usage.input_tokens);
|
|
339
|
+
if (event.usage.output_tokens) totalOutputTokens += (event.usage.output_tokens_delta || 0);
|
|
340
|
+
}
|
|
341
|
+
if (event.message?.usage) {
|
|
342
|
+
if (event.message.usage.input_tokens) totalInputTokens = Math.max(totalInputTokens, event.message.usage.input_tokens);
|
|
343
|
+
if (event.message.usage.output_tokens) totalOutputTokens = Math.max(totalOutputTokens, event.message.usage.output_tokens);
|
|
344
|
+
}
|
|
345
|
+
|
|
333
346
|
if (event.type === "assistant" && event.message?.content) {
|
|
334
347
|
for (const block of event.message.content) {
|
|
335
348
|
if (block.type === "text" && block.text.trim()) {
|
|
@@ -418,10 +431,16 @@ export async function runTeam(taskId, opts = {}) {
|
|
|
418
431
|
}
|
|
419
432
|
|
|
420
433
|
if (event.type === "result") {
|
|
434
|
+
// Final usage from result event
|
|
435
|
+
if (event.usage) {
|
|
436
|
+
if (event.usage.input_tokens) totalInputTokens = Math.max(totalInputTokens, event.usage.input_tokens);
|
|
437
|
+
if (event.usage.output_tokens) totalOutputTokens = Math.max(totalOutputTokens, event.usage.output_tokens);
|
|
438
|
+
}
|
|
439
|
+
const totalTokens = totalInputTokens + totalOutputTokens;
|
|
421
440
|
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
422
441
|
console.log(`\n━━━ DONE ━━━`);
|
|
423
|
-
console.log(` ${totalTime}s | ${stepCount} steps\n`);
|
|
424
|
-
vizSend({ type: "session:end", duration: `${totalTime}s`, steps: stepCount });
|
|
442
|
+
console.log(` ${totalTime}s | ${stepCount} steps${totalTokens ? ` | ${totalTokens.toLocaleString()} tokens` : ""}\n`);
|
|
443
|
+
vizSend({ type: "session:end", duration: `${totalTime}s`, steps: stepCount, inputTokens: totalInputTokens, outputTokens: totalOutputTokens });
|
|
425
444
|
clearInterval(inboxTimer);
|
|
426
445
|
setTimeout(() => { try { vizWs?.close(); } catch {} }, 500);
|
|
427
446
|
}
|