TUI: fix /reasoning by supporting stream + normalization

This commit is contained in:
AaronWander 2026-01-29 09:31:10 +08:00
parent fdcac0ccf4
commit 6b379bc423
4 changed files with 59 additions and 5 deletions

View File

@ -19,4 +19,13 @@ describe("tui slash commands", () => {
expect(commands.some((command) => command.name === "context")).toBe(true);
expect(commands.some((command) => command.name === "commands")).toBe(true);
});
it("offers reasoning stream mode", () => {
const commands = getSlashCommands({});
const reasoning = commands.find((command) => command.name === "reasoning");
expect(reasoning).toBeTruthy();
expect(reasoning?.getArgumentCompletions?.("")).toEqual(
expect.arrayContaining([{ value: "stream", label: "stream" }]),
);
});
});

View File

@ -4,7 +4,7 @@ import { formatThinkingLevels, listThinkingLevelLabels } from "../auto-reply/thi
import type { MoltbotConfig } from "../config/types.js";
const VERBOSE_LEVELS = ["on", "off"];
const REASONING_LEVELS = ["on", "off"];
const REASONING_LEVELS = ["on", "off", "stream"];
const ELEVATED_LEVELS = ["on", "off", "ask", "full"];
const ACTIVATION_LEVELS = ["mention", "always"];
const USAGE_FOOTER_LEVELS = ["off", "tokens", "full"];
@ -68,7 +68,7 @@ export function getSlashCommands(options: SlashCommandOptions = {}): SlashComman
},
{
name: "reasoning",
description: "Set reasoning on/off",
description: "Set reasoning visibility",
getArgumentCompletions: (prefix) =>
REASONING_LEVELS.filter((v) => v.startsWith(prefix.toLowerCase())).map((value) => ({
value,

View File

@ -44,4 +44,43 @@ describe("tui command handlers", () => {
);
expect(requestRender).toHaveBeenCalled();
});
it("normalizes /reasoning streaming to stream", async () => {
const patchSession = vi.fn().mockResolvedValue(undefined);
const addUser = vi.fn();
const addSystem = vi.fn();
const requestRender = vi.fn();
const refreshSessionInfo = vi.fn().mockResolvedValue(undefined);
const { handleCommand } = createCommandHandlers({
client: { patchSession } as never,
chatLog: { addUser, addSystem } as never,
tui: { requestRender } as never,
opts: {},
state: {
currentSessionKey: "agent:main:main",
activeChatRunId: null,
sessionInfo: {},
} as never,
deliverDefault: false,
openOverlay: vi.fn(),
closeOverlay: vi.fn(),
refreshSessionInfo,
loadHistory: vi.fn(),
setSession: vi.fn(),
refreshAgents: vi.fn(),
abortActive: vi.fn(),
setActivityStatus: vi.fn(),
formatSessionKey: vi.fn(),
});
await handleCommand("/reasoning streaming");
expect(patchSession).toHaveBeenCalledWith({
key: "agent:main:main",
reasoningLevel: "stream",
});
expect(addSystem).toHaveBeenCalledWith("reasoning set to stream");
expect(refreshSessionInfo).toHaveBeenCalled();
});
});

View File

@ -1,6 +1,7 @@
import type { Component, TUI } from "@mariozechner/pi-tui";
import {
formatThinkingLevels,
normalizeReasoningLevel,
normalizeUsageDisplay,
resolveResponseUsageMode,
} from "../auto-reply/thinking.js";
@ -333,15 +334,20 @@ export function createCommandHandlers(context: CommandHandlerContext) {
break;
case "reasoning":
if (!args) {
chatLog.addSystem("usage: /reasoning <on|off>");
chatLog.addSystem("usage: /reasoning <on|off|stream>");
break;
}
try {
const normalized = normalizeReasoningLevel(args);
if (!normalized) {
chatLog.addSystem("usage: /reasoning <on|off|stream>");
break;
}
await client.patchSession({
key: state.currentSessionKey,
reasoningLevel: args,
reasoningLevel: normalized,
});
chatLog.addSystem(`reasoning set to ${args}`);
chatLog.addSystem(`reasoning set to ${normalized}`);
await refreshSessionInfo();
} catch (err) {
chatLog.addSystem(`reasoning failed: ${String(err)}`);