From b2844cdef484ae83455baf6ce09dcea8bf8fefd6 Mon Sep 17 00:00:00 2001 From: ymq Date: Fri, 28 Aug 2026 12:26:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(cockpit):=20=E4=BC=9A=E8=AF=9D=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E9=80=89=E6=8B=A9=E6=8C=81=E4=B9=85=E5=8C=96=E2=80=94?= =?UTF-8?q?=E2=80=94cockpit=5Fchat=5Fv2=20=E4=BC=A0=20model=5Fid+session?= =?UTF-8?q?=5Fid=E3=80=81=E4=B8=8B=E6=8B=89=E6=8C=89=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E9=80=89=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/cockpit_chat_v2.dspy | 5 ++++- wwwroot/api/cockpit_model_options.dspy | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/wwwroot/api/cockpit_chat_v2.dspy b/wwwroot/api/cockpit_chat_v2.dspy index d2689de..059de20 100644 --- a/wwwroot/api/cockpit_chat_v2.dspy +++ b/wwwroot/api/cockpit_chat_v2.dspy @@ -96,6 +96,9 @@ if action == 'send_message': ctx['pipeline_id'] = getattr(proj_recs[0], 'pipeline_id', '') or '' # ── 走 gateway 统一入口(Web AgentIO 通道)── + # model_id:前端模型下拉选中的模型 → gateway 校验后持久化到项目(项目模型一经设置 + # 即生效,直到用户再次选择),空 = 沿用项目已设模型。 + model_id = (params_kw or {}).get('model_id', '') or '' from pipeline_service.gateway import get_gateway gateway = get_gateway() @@ -105,7 +108,7 @@ if action == 'send_message': yield json.dumps({"reasoning_content": "项目: " + ctx['name'] + "\n"}, ensure_ascii=False) + '\n' # 运行 gateway(输出 content 流式格式,供前端 AgentIO→AgentOut 渲染) - async for chunk in gateway.run_message("web", uid, prompt): + async for chunk in gateway.run_message("web", uid, prompt, model_id=model_id, session_id=session_id): data = json.loads(chunk) t = data.get('type', '') diff --git a/wwwroot/api/cockpit_model_options.dspy b/wwwroot/api/cockpit_model_options.dspy index 2488045..7da4a46 100644 --- a/wwwroot/api/cockpit_model_options.dspy +++ b/wwwroot/api/cockpit_model_options.dspy @@ -1,11 +1,14 @@ # cockpit_model_options.dspy - Returns active models with capabilities for dropdown # Used by cockpit model selector # org_id 多租户隔离:非系统级机构只看到本机构的模型(不含系统级兜底) -# 返回每项带 selected 标记,标识个人之前选择的默认模型(default_llm_id) +# selected 标记 = 当前项目的已设模型(sd_projects.default_model,产线通用、跨会话持久); +# 项目未设模型时回退个人全局选择(default_llm_id)。前端 UiCode 按 selected 恢复选中项, +# 不再每次重建都回退第一项。 dbname = get_module_dbname('pipeline-sdlc') uid = await get_user() org_id = (await get_userorgid()) or '' +session_id = (params_kw or {}).get('session_id', '') or '' async with DBPools().sqlorContext(dbname) as sor: sql = "SELECT id, name, provider, model_id, capabilities FROM llm WHERE status='active'" @@ -16,7 +19,22 @@ async with DBPools().sqlorContext(dbname) as sor: sql += " ORDER BY name" recs = await sor.sqlExe(sql, params) - # 个人之前选择的默认模型 + # 项目级模型(优先级最高):按会话解析当前项目 → sd_projects.default_model。 + # session_id 为空/无会话记录时自动回退全局设置,与消息链路的项目解析同一函数,不漂移。 + project_model = '' + try: + from pipeline_service.workspace import get_session_project_id + _pid = await get_session_project_id(sor, uid or '', session_id) + if _pid: + _p = await sor.sqlExe( + "SELECT default_model FROM sd_projects WHERE id=${p}$", {"p": _pid}) + await sor.sqlExe("COMMIT", {}) + if _p: + project_model = getattr(_p[0], 'default_model', '') or '' + except Exception as e: + debug(f'cockpit_model_options project_model error: {e}') + + # 个人之前选择的默认模型(项目未设模型时的回退选中项) current_llm_id = '' if uid: _s = await sor.sqlExe( @@ -32,7 +50,7 @@ for r in recs: 'provider': r.provider, 'model_id': r.model_id, 'capabilities': r.capabilities or 'text', - 'selected': r.id == current_llm_id, + 'selected': (r.name == project_model) if project_model else (r.id == current_llm_id), }) return rows