feat: restore /stream command with default OFF

Token streaming is now off by default. Users can toggle it with /stream.

🐾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>
This commit is contained in:
cpacker
2025-12-12 23:02:16 -08:00
parent 642692593c
commit 0dda14103a
3 changed files with 73 additions and 1 deletions

View File

@@ -220,6 +220,7 @@ export default function App({
startupApproval = null, startupApproval = null,
startupApprovals = [], startupApprovals = [],
messageHistory = [], messageHistory = [],
tokenStreaming = false,
agentProvenance = null, agentProvenance = null,
}: { }: {
agentId: string; agentId: string;
@@ -236,6 +237,7 @@ export default function App({
startupApproval?: ApprovalRequest | null; // Deprecated: use startupApprovals startupApproval?: ApprovalRequest | null; // Deprecated: use startupApprovals
startupApprovals?: ApprovalRequest[]; startupApprovals?: ApprovalRequest[];
messageHistory?: Message[]; messageHistory?: Message[];
tokenStreaming?: boolean;
agentProvenance?: AgentProvenance | null; agentProvenance?: AgentProvenance | null;
}) { }) {
// Track current agent (can change when swapping) // Track current agent (can change when swapping)
@@ -331,6 +333,10 @@ export default function App({
const [resumeSelectorOpen, setResumeSelectorOpen] = useState(false); const [resumeSelectorOpen, setResumeSelectorOpen] = useState(false);
const [messageSearchOpen, setMessageSearchOpen] = useState(false); const [messageSearchOpen, setMessageSearchOpen] = useState(false);
// Token streaming preference (can be toggled at runtime)
const [tokenStreamingEnabled, setTokenStreamingEnabled] =
useState(tokenStreaming);
// Live, approximate token counter (resets each turn) // Live, approximate token counter (resets each turn)
const [tokenCount, setTokenCount] = useState(0); const [tokenCount, setTokenCount] = useState(0);
@@ -1357,6 +1363,61 @@ export default function App({
return { submitted: true }; return { submitted: true };
} }
// Special handling for /stream command - toggle and save
if (msg.trim() === "/stream") {
const newValue = !tokenStreamingEnabled;
// Immediately add command to transcript with "running" phase and loading message
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: `${newValue ? "Enabling" : "Disabling"} token streaming...`,
phase: "running",
});
buffersRef.current.order.push(cmdId);
refreshDerived();
// Lock input during async operation
setCommandRunning(true);
try {
setTokenStreamingEnabled(newValue);
// Save to settings
const { settingsManager } = await import("../settings-manager");
settingsManager.updateSettings({ tokenStreaming: newValue });
// Update the same command with final result
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: `Token streaming ${newValue ? "enabled" : "disabled"}`,
phase: "finished",
success: true,
});
refreshDerived();
} catch (error) {
// Mark command as failed
const errorDetails = formatErrorDetails(error, agentId);
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: `Failed: ${errorDetails}`,
phase: "finished",
success: false,
});
refreshDerived();
} finally {
// Unlock input
setCommandRunning(false);
}
return { submitted: true };
}
// Special handling for /clear command - reset conversation // Special handling for /clear command - reset conversation
if (msg.trim() === "/clear") { if (msg.trim() === "/clear") {
const cmdId = uid("cmd"); const cmdId = uid("cmd");
@@ -2189,6 +2250,7 @@ ${recentCommits}
isExecutingTool, isExecutingTool,
queuedApprovalResults, queuedApprovalResults,
pendingApprovals, pendingApprovals,
tokenStreamingEnabled,
], ],
); );
@@ -3160,9 +3222,10 @@ Plan file path: ${planFilePath}`;
// Always show tool calls in progress // Always show tool calls in progress
return ln.phase !== "finished"; return ln.phase !== "finished";
} }
if (!tokenStreamingEnabled && ln.phase === "streaming") return false;
return ln.phase === "streaming"; return ln.phase === "streaming";
}); });
}, [lines]); }, [lines, tokenStreamingEnabled]);
// Commit welcome snapshot once when ready for fresh sessions (no history) // Commit welcome snapshot once when ready for fresh sessions (no history)
// Wait for agentProvenance to be available for new agents (continueSession=false) // Wait for agentProvenance to be available for new agents (continueSession=false)

View File

@@ -16,6 +16,13 @@ export const commands: Record<string, Command> = {
return "Opening model selector..."; return "Opening model selector...";
}, },
}, },
"/stream": {
desc: "Toggle token streaming on/off",
handler: () => {
// Handled specially in App.tsx for live toggling
return "Toggling token streaming...";
},
},
"/exit": { "/exit": {
desc: "Exit and show session stats", desc: "Exit and show session stats",
handler: () => { handler: () => {

View File

@@ -741,6 +741,7 @@ async function main() {
startupApproval: resumeData?.pendingApproval ?? null, startupApproval: resumeData?.pendingApproval ?? null,
startupApprovals: resumeData?.pendingApprovals ?? [], startupApprovals: resumeData?.pendingApprovals ?? [],
messageHistory: resumeData?.messageHistory ?? [], messageHistory: resumeData?.messageHistory ?? [],
tokenStreaming: settings.tokenStreaming,
agentProvenance, agentProvenance,
}); });
} }
@@ -753,6 +754,7 @@ async function main() {
startupApproval: resumeData?.pendingApproval ?? null, startupApproval: resumeData?.pendingApproval ?? null,
startupApprovals: resumeData?.pendingApprovals ?? [], startupApprovals: resumeData?.pendingApprovals ?? [],
messageHistory: resumeData?.messageHistory ?? [], messageHistory: resumeData?.messageHistory ?? [],
tokenStreaming: settings.tokenStreaming,
agentProvenance, agentProvenance,
}); });
} }