@kendoo.agentdesk/agentdesk 0.6.1 → 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 +23 -3
- package/package.json +1 -1
package/cli/team.mjs
CHANGED
|
@@ -276,7 +276,8 @@ export async function runTeam(taskId, opts = {}) {
|
|
|
276
276
|
const PHASE_NAMES = ["INTAKE", "BRAINSTORM", "PLANNING", "EXECUTION", "REVIEW"];
|
|
277
277
|
|
|
278
278
|
// Build agent name regex dynamically from resolved team
|
|
279
|
-
const
|
|
279
|
+
const escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
280
|
+
const agentNames = teamSections.names.map(escapeRegex).join("|");
|
|
280
281
|
const agentRegex = new RegExp(`^(${agentNames})\\s*[●◆▲■◈☾✦*]*\\s*:?\\s*`, "i");
|
|
281
282
|
|
|
282
283
|
function detectAgent(text) {
|
|
@@ -323,12 +324,25 @@ export async function runTeam(taskId, opts = {}) {
|
|
|
323
324
|
console.log("\n━━━ INTAKE ━━━\n");
|
|
324
325
|
vizSend({ type: "phase:change", phase: "INTAKE" });
|
|
325
326
|
|
|
327
|
+
let totalInputTokens = 0;
|
|
328
|
+
let totalOutputTokens = 0;
|
|
329
|
+
|
|
326
330
|
const rl = createInterface({ input: child.stdout });
|
|
327
331
|
|
|
328
332
|
for await (const line of rl) {
|
|
329
333
|
try {
|
|
330
334
|
const event = JSON.parse(line);
|
|
331
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
|
+
|
|
332
346
|
if (event.type === "assistant" && event.message?.content) {
|
|
333
347
|
for (const block of event.message.content) {
|
|
334
348
|
if (block.type === "text" && block.text.trim()) {
|
|
@@ -417,10 +431,16 @@ export async function runTeam(taskId, opts = {}) {
|
|
|
417
431
|
}
|
|
418
432
|
|
|
419
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;
|
|
420
440
|
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
421
441
|
console.log(`\n━━━ DONE ━━━`);
|
|
422
|
-
console.log(` ${totalTime}s | ${stepCount} steps\n`);
|
|
423
|
-
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 });
|
|
424
444
|
clearInterval(inboxTimer);
|
|
425
445
|
setTimeout(() => { try { vizWs?.close(); } catch {} }, 500);
|
|
426
446
|
}
|