Skip to content

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: jiuwenclaw-tui,命令/model 选择模型后,最上方显示没有变化

cycong_18300548ef441
diff --git a/jiuwenclaw/channel/cli_channel.py b/jiuwenclaw/channel/cli_channel.py
index b534ba7ab8..2c04fe1810 100644
--- a/jiuwenclaw/channel/cli_channel.py
+++ b/jiuwenclaw/channel/cli_channel.py
@@ -19,6 +19,7 @@ from openjiuwen.core.foundation.llm.schema.config import (
from jiuwenclaw.config import (
get_config,
get_config_raw,
+ get_default_models,
resolve_env_vars,
update_context_engine_enabled_in_config,
update_memory_forbidden_enabled_in_config,
@@ -1197,9 +1198,34 @@ def register_cli_handlers(bind: CliHandlersBindParams) -> None:
error=resp.error or "Model switch failed on agent server",
)
+ async def _models_list(ws, req_id, params, session_id):
+ try:
+ config = get_config()
+ models = get_default_models(config)
+ result = []
+ for entry in models:
+ mcc = entry.get("model_client_config", {})
+ mco = entry.get("model_config_obj", {})
+ result.append({
+ "model_name": mcc.get("model_name", ""),
+ "api_base": mcc.get("api_base", ""),
+ "api_key": mcc.get("api_key", ""),
+ "model_provider": mcc.get("client_provider", ""),
+ "temperature": mco.get("temperature", 0.95),
+ })
+ active_model = result[0]["model_name"] if result else ""
+ await channel.send_response(ws, req_id, ok=True, payload={
+ "models": result,
+ "active_model": active_model,
+ })
+ except Exception as exc:
+ logger.warning("[models.list] %s", exc)
+ await channel.send_response(ws, req_id, ok=False, error=str(exc), code="INTERNAL_ERROR")
+
channel.register_local_handler(path, "config.get", _config_get)
channel.register_local_handler(path, "config.set", _config_set)
channel.register_local_handler(path, "config.validate_model", _config_validate_model)
+ channel.register_local_handler(path, "models.list", _models_list)
channel.register_local_handler(path, "session.list", _session_list)
channel.register_local_handler(path, "session.create", _session_create)
channel.register_local_handler(path, "session.delete", _session_delete)
diff --git a/jiuwenclaw/cli/src/app-state.ts b/jiuwenclaw/cli/src/app-state.ts
index 74dfb0045c..7af9c188dd 100644
--- a/jiuwenclaw/cli/src/app-state.ts
+++ b/jiuwenclaw/cli/src/app-state.ts
@@ -258,16 +258,27 @@ export class CliPiAppState {
private async fetchModelInfo(): Promise<void> {
try {
- const payload = await this.request("config.get", {});
- if (payload && typeof payload === "object") {
- const config = payload as Record<string, unknown>;
- this.modelInfo = {
- provider: String(config.model_provider ?? ""),
- model: String(config.model ?? ""),
- version: String(config.app_version ?? ""),
- };
- this.emitChange();
- }
+ const [configPayload, modelsPayload] = await Promise.allSettled([
+ this.request("config.get", {}),
+ this.request("models.list", {}),
+ ]);
+ const config =
+ configPayload.status === "fulfilled" && configPayload.value && typeof configPayload.value === "object"
+ ? (configPayload.value as Record<string, unknown>)
+ : {};
+ const modelsResult =
+ modelsPayload.status === "fulfilled" && modelsPayload.value && typeof modelsPayload.value === "object"
+ ? (modelsPayload.value as Record<string, unknown>)
+ : {};
+ const activeModelName = String(modelsResult.active_model ?? "").trim();
+ const models = Array.isArray(modelsResult.models) ? (modelsResult.models as Record<string, unknown>[]) : [];
+ const activeModel = activeModelName ? models.find((m) => m.model_name === activeModelName) : models[0];
+ this.modelInfo = {
+ provider: String(activeModel?.model_provider ?? config.model_provider ?? ""),
+ model: activeModelName || String(config.model ?? ""),
+ version: String(config.app_version ?? ""),
+ };
+ this.emitChange();
} catch {
// ignore error, use defaults
}
@@ -359,6 +370,7 @@ export class CliPiAppState {
connectionStatus: snapshot.connectionStatus,
mode: snapshot.mode,
setMode: this.setMode,
+ setModel: this.setModel,
setThemeName: this.setThemeName,
setAccentColor: this.setAccentColor,
transcriptMode: snapshot.transcriptMode,
@@ -479,6 +491,14 @@ readonly request = async <T = Record<string, unknown>>(
}
};
+ readonly setModel = (name: string): void => {
+ const trimmed = name.trim();
+ if (trimmed && this.modelInfo.model !== trimmed) {
+ this.modelInfo = { ...this.modelInfo, model: trimmed };
+ this.emitChange();
+ }
+ };
+
readonly setThemeName = (theme: ThemeName): void => {
if (this.themeName !== theme) {
this.themeName = theme;
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/model.ts b/jiuwenclaw/cli/src/core/commands/builtins/model.ts
index b121f88bda..d831647f14 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/model.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/model.ts
@@ -142,6 +142,9 @@ export function createModelCommand(): SlashCommand {
}>("command.model", { model: value });
const isSwitch = !!payload.requested;
+ if (isSwitch) {
+ ctx.setModel(payload.requested ?? payload.current ?? "");
+ }
const title = isSwitch
? `Switched to: ${payload.requested}`
: "Model Configuration";
diff --git a/jiuwenclaw/cli/src/core/commands/types.ts b/jiuwenclaw/cli/src/core/commands/types.ts
index c44ea23f20..a6f1e07963 100644
--- a/jiuwenclaw/cli/src/core/commands/types.ts
+++ b/jiuwenclaw/cli/src/core/commands/types.ts
@@ -43,6 +43,7 @@ export interface CommandContext {
connectionStatus: ConnectionStatus;
mode: "agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team";
setMode: (mode: "agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team") => void;
+ setModel: (name: string) => void;
setThemeName: (theme: ThemeName) => void;
setAccentColor: (color: AccentColorName) => void;
transcriptMode: "compact" | "detailed";
diff --git a/jiuwenclaw/cli/src/ui/app-screen.ts b/jiuwenclaw/cli/src/ui/app-screen.ts
index bc8340f9f7..c8624c85be 100644
--- a/jiuwenclaw/cli/src/ui/app-screen.ts
+++ b/jiuwenclaw/cli/src/ui/app-screen.ts
@@ -940,6 +940,7 @@ export class AppScreen implements Component, Focusable {
applied?: boolean;
}>("command.model", { model: modelName });
const nextModel = payload.current ?? modelName;
+ this.state.setModel(nextModel);
this.state.clearEntries();
this.state.addItem(
addInfo(this.state.getSnapshot().sessionId, `Switched model to: ${nextModel}`, "m"),