From f84da9d189dd3f606389b909bc9ceeb6380adfc5 Mon Sep 17 00:00:00 2001 From: ymq Date: Mon, 24 Aug 2026 18:32:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(workspace):=20=E6=96=B0=E5=A2=9E=20get=5Fs?= =?UTF-8?q?ession=5Fcontext(per-session=20=E4=BC=98=E5=85=88=E8=AF=BB=20pr?= =?UTF-8?q?oject+iteration)=20=E6=94=AF=E6=8C=81=E5=A4=9A=20tab=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=8A=E4=B8=8B=E6=96=87=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_service/workspace.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pipeline_service/workspace.py b/pipeline_service/workspace.py index 1deeded..5fb1f77 100644 --- a/pipeline_service/workspace.py +++ b/pipeline_service/workspace.py @@ -127,6 +127,38 @@ async def get_session_project_id(sor, uid, session_id=''): return '' +async def get_session_context(sor, uid, session_id=''): + """按会话解析 (project_id, iteration_id)。per-session 优先,回退 per-user 全局。 + + 多 tab 隔离:session_id 非空时优先读 pipeline_session_settings(每个 user+session 一条), + 无记录回退 pipeline_agent_settings.current_project_id/current_iteration_id。 + """ + if session_id: + try: + recs = await sor.sqlExe( + "SELECT current_project_id, current_iteration_id FROM pipeline_session_settings " + "WHERE user_id=${u}$ AND session_id=${s}$", + {"u": uid, "s": session_id}) + if recs: + pid = getattr(recs[0], 'current_project_id', '') or '' + iid = getattr(recs[0], 'current_iteration_id', '') or '' + if pid or iid: + return pid, iid + except Exception: + pass + try: + recs = await sor.sqlExe( + "SELECT current_project_id, current_iteration_id FROM pipeline_agent_settings " + "WHERE user_id=${u}$", + {"u": uid}) + if recs: + return (getattr(recs[0], 'current_project_id', '') or '', + getattr(recs[0], 'current_iteration_id', '') or '') + except Exception: + pass + return '', '' + + async def get_workspace_dir(sor, uid, session_id=''): """读当前项目的 workspace 目录(统一 workspace_*.dspy 的重复逻辑)。 @@ -414,6 +446,8 @@ def load_workspace(): g.get_space_dir = get_space_dir g.get_project_dir = get_project_dir g.get_project_apps_modules = get_project_apps_modules + g.get_session_project_id = get_session_project_id + g.get_session_context = get_session_context g.build_workspace_path = build_workspace_path g.build_space_path = build_space_path g.resolve_workspace_path = resolve_workspace_path