fix: improve subagent UI display and interruption handling (#330)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
// - Exposes `onChunk` to feed SDK events and `toLines` to render.
|
||||
|
||||
import type { LettaStreamingResponse } from "@letta-ai/letta-client/resources/agents/messages";
|
||||
import { INTERRUPTED_BY_USER } from "../../constants";
|
||||
|
||||
// One line per transcript row. Tool calls evolve in-place.
|
||||
// For tool call returns, merge into the tool call matching the toolCallId
|
||||
@@ -172,7 +173,7 @@ export function markIncompleteToolsAsCancelled(b: Buffers) {
|
||||
...line,
|
||||
phase: "finished" as const,
|
||||
resultOk: false,
|
||||
resultText: "Interrupted by user",
|
||||
resultText: INTERRUPTED_BY_USER,
|
||||
};
|
||||
b.byId.set(id, updatedLine);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Format tool count and token statistics for display
|
||||
*
|
||||
* @param toolCount - Number of tool calls
|
||||
* @param totalTokens - Total tokens used
|
||||
* @param totalTokens - Total tokens used (0 or undefined means no data available)
|
||||
* @param isRunning - If true, shows "—" for tokens (since usage is only available at end)
|
||||
*/
|
||||
export function formatStats(
|
||||
@@ -16,12 +16,19 @@ export function formatStats(
|
||||
totalTokens: number,
|
||||
isRunning = false,
|
||||
): string {
|
||||
const tokenStr = isRunning
|
||||
? "—"
|
||||
: totalTokens >= 1000
|
||||
const toolStr = `${toolCount} tool use${toolCount !== 1 ? "s" : ""}`;
|
||||
|
||||
// Only show token count if we have actual data (not running and totalTokens > 0)
|
||||
const hasTokenData = !isRunning && totalTokens > 0;
|
||||
if (!hasTokenData) {
|
||||
return toolStr;
|
||||
}
|
||||
|
||||
const tokenStr =
|
||||
totalTokens >= 1000
|
||||
? `${(totalTokens / 1000).toFixed(1)}k`
|
||||
: String(totalTokens);
|
||||
return `${toolCount} tool use${toolCount !== 1 ? "s" : ""} · ${tokenStr} tokens`;
|
||||
return `${toolStr} · ${tokenStr} tokens`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -180,7 +180,7 @@ export function addToolCall(
|
||||
*/
|
||||
export function completeSubagent(
|
||||
id: string,
|
||||
result: { success: boolean; error?: string },
|
||||
result: { success: boolean; error?: string; totalTokens?: number },
|
||||
): void {
|
||||
const agent = store.agents.get(id);
|
||||
if (!agent) return;
|
||||
@@ -191,6 +191,7 @@ export function completeSubagent(
|
||||
status: result.success ? "completed" : "error",
|
||||
error: result.error,
|
||||
durationMs: Date.now() - agent.startTime,
|
||||
totalTokens: result.totalTokens ?? agent.totalTokens,
|
||||
} as SubagentState;
|
||||
store.agents.set(id, updatedAgent);
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user