JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix: update tui mode status and backend status when switch_mode
huanggawaa5d5df803620
diff --git a/jiuwenclaw/cli/src/app-state.ts b/jiuwenclaw/cli/src/app-state.tsindex 5809f3b86e..d9b8311249 100644--- a/jiuwenclaw/cli/src/app-state.ts+++ b/jiuwenclaw/cli/src/app-state.ts@@ -149,6 +149,7 @@ export class CliPiAppState {setMode: (mode) => {this.mode = mode;},+ getMode: () => this.mode,getEntries: () => this.entries,setEntries: (entries) => {this.entries = entries;diff --git a/jiuwenclaw/cli/src/core/event-handlers.ts b/jiuwenclaw/cli/src/core/event-handlers.tsindex 1a78043c68..6827d1e742 100644--- a/jiuwenclaw/cli/src/core/event-handlers.ts+++ b/jiuwenclaw/cli/src/core/event-handlers.ts@@ -50,6 +50,7 @@ export interface AppEventDelegate {getSessionId(): string;setSessionId(sessionId: string): void;setMode(mode: "agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team"): void;+ getMode(): "agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team";getEntries(): HistoryItem[];setEntries(entries: HistoryItem[]): void;setStreamingState(state: StreamingState): void;@@ -97,6 +98,56 @@ export interface AppEventDelegate {notifyHistoryPageDone(pageIdx: number): void;}+function _handleSwitchModeToolResult(+ delegate: AppEventDelegate,+ payload: Record<string, unknown>,+): void {+ if (payload.tool_name !== "switch_mode") return;++ const resultRaw = payload.result;+ let subMode: string | null = null;++ if (typeof resultRaw === "object" && resultRaw !== null) {+ // result 已经是解析后的对象+ const data = (resultRaw as Record<string, unknown>).data;+ if (typeof data === "object" && data !== null) {+ const cm = (data as Record<string, unknown>).current_mode;+ if (typeof cm === "string") subMode = cm;+ }+ } else if (typeof resultRaw === "string") {+ // 先尝试 JSON 解析+ try {+ const parsed = JSON.parse(resultRaw);+ if (typeof parsed === "object" && parsed !== null) {+ const data = (parsed as Record<string, unknown>).data;+ if (typeof data === "object" && data !== null) {+ const cm = (data as Record<string, unknown>).current_mode;+ if (typeof cm === "string") subMode = cm;+ }+ }+ } catch {+ // JSON 解析失败,尝试从 Python str 表示中提取+ // 格式如: "success=True data={'current_mode': 'normal', 'message': '...'} error=None"+ const match = resultRaw.match(/current_mode['"]\s*:\s*['"](\w+)['"]/);+ if (match) subMode = match[1];+ }+ }++ if (!subMode) return;++ const existingMode = delegate.getMode();+ let newMode: string | null = null;+ if (existingMode.startsWith("code.")) {+ newMode = subMode === "plan" ? "code.plan" : "code.normal";+ } else if (existingMode.startsWith("agent.")) {+ newMode = subMode === "plan" ? "agent.plan" : "agent.fast";+ }++ if (newMode && newMode !== existingMode) {+ delegate.setMode(newMode as "agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team");+ }+}+function appendEntry(delegate: AppEventDelegate, entry: HistoryItem): void {delegate.setEntries([...delegate.getEntries(), entry]);}@@ -599,6 +650,7 @@ export function handleIncomingFrame(delegate: AppEventDelegate, frame: EventFramreturn true;case "chat.tool_result":+ _handleSwitchModeToolResult(delegate, payload);delegate.addToolResultPayload(payload,activeSessionId,