feat(agent): 工作空间控件按会话传递session_id
- agent_menus.dspy 按 session 解析项目 + 工作空间按钮URL拼 session_id - index.ui 默认tab/新建会话 tab 的 agent_menus urlwidget 带 session_id
This commit is contained in:
parent
0bc23c1d69
commit
7842d2570f
@ -18,7 +18,7 @@
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var tp=bricks.getWidgetById('session_tabs',bricks.app);if(!tp)return;var sid='s'+Date.now()+'_'+Math.floor(Math.random()*100000);var n=tp.opts.items.length+1;tp.open_tab({name:'session_'+sid,label:'会话 '+n,removable:true,content:{widgettype:'VBox',options:{css:'filler',width:'100%',height:'100%'},subwidgets:[{widgettype:'urlwidget',options:{url:'/pipeline_core/api/agent_menus.dspy',method:'GET'}},{widgettype:'AgentIO',options:{css:'filler',margin:'0 24px 24px 24px',url:'/pipeline_core/api/agent_chat.dspy?session_id='+sid,model_dataurl:'/pipeline_core/api/agent_model_options.dspy',model_cwidth:14,placeholder:'输入你的需求...'}}]}});"
|
||||
"script": "var tp=bricks.getWidgetById('session_tabs',bricks.app);if(!tp)return;var sid='s'+Date.now()+'_'+Math.floor(Math.random()*100000);var n=tp.opts.items.length+1;tp.open_tab({name:'session_'+sid,label:'会话 '+n,removable:true,content:{widgettype:'VBox',options:{css:'filler',width:'100%',height:'100%'},subwidgets:[{widgettype:'urlwidget',options:{url:'/pipeline_core/api/agent_menus.dspy?session_id='+sid,method:'GET'}},{widgettype:'AgentIO',options:{css:'filler',margin:'0 24px 24px 24px',url:'/pipeline_core/api/agent_chat.dspy?session_id='+sid,model_dataurl:'/pipeline_core/api/agent_model_options.dspy',model_cwidth:14,placeholder:'输入你的需求...'}}]}});"
|
||||
}]
|
||||
}
|
||||
]
|
||||
@ -42,7 +42,7 @@
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "urlwidget",
|
||||
"options": {"url": "{{entire_url('/pipeline_core/api/agent_menus.dspy')}}", "method": "GET"}
|
||||
"options": {"url": "{{entire_url('/pipeline_core/api/agent_menus.dspy')}}?session_id=default", "method": "GET"}
|
||||
},
|
||||
{
|
||||
"widgettype": "AgentIO",
|
||||
|
||||
@ -7,16 +7,30 @@ uid = await get_user()
|
||||
if not uid:
|
||||
uid = 'user-01'
|
||||
|
||||
# 1. 解析当前产线:用户当前项目 → sd_projects.pipeline_id
|
||||
# 会话内唯一标识(web 多 tab;工作空间按钮按会话解析项目)
|
||||
session_id = (params_kw or {}).get('session_id', '') or ''
|
||||
|
||||
# 1. 解析当前产线:当前会话项目 → sd_projects.pipeline_id
|
||||
pipeline_id = ''
|
||||
pid = ''
|
||||
try:
|
||||
dbname = get_module_dbname('pipeline_core')
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
||||
{"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
# 按会话解析项目:session 表优先,回退全局(多 tab 各自项目,互不覆盖)
|
||||
if session_id:
|
||||
try:
|
||||
_srecs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_session_settings "
|
||||
"WHERE user_id=${u}$ AND session_id=${s}$",
|
||||
{"u": uid, "s": session_id})
|
||||
pid = getattr(_srecs[0], 'current_project_id', '') if _srecs else ''
|
||||
except Exception:
|
||||
pid = ''
|
||||
if not pid:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
||||
{"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
if pid:
|
||||
precs = await sor.sqlExe(
|
||||
"SELECT pipeline_id FROM sd_projects WHERE id=${p}$", {"p": pid})
|
||||
@ -61,10 +75,13 @@ def _bind(url, require_project):
|
||||
}
|
||||
|
||||
# 固定「工作空间」按钮(通用能力,所有 agent 都有;依赖当前项目)
|
||||
_ws_url = entire_url("/pipeline-sdlc/api/workspace_popup.dspy")
|
||||
if session_id:
|
||||
_ws_url += "?session_id=" + session_id
|
||||
buttons.append({
|
||||
"widgettype": "Button",
|
||||
"options": {"label": "🗂 工作空间", "css": "small", "id": "menu_btn_ws"},
|
||||
"binds": [_bind(entire_url("/pipeline-sdlc/api/workspace_popup.dspy"), True)],
|
||||
"binds": [_bind(_ws_url, True)],
|
||||
})
|
||||
|
||||
for i, m in enumerate(menus):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user