feat(agent): 开发产线多会话 TabPanel + 新建会话按钮

This commit is contained in:
yumoqing 2026-08-20 17:39:34 +08:00
parent 6826d49f01
commit 03745f38e9
2 changed files with 39 additions and 8 deletions

View File

@ -8,7 +8,19 @@
"subwidgets": [ "subwidgets": [
{"widgettype": "Title2", "options": {"text": "智能助手"}}, {"widgettype": "Title2", "options": {"text": "智能助手"}},
{"widgettype": "Text", "options": {"text": "通用 AI 对话能力", "cfontsize": 0.9, "color": "#94a3b8"}}, {"widgettype": "Text", "options": {"text": "通用 AI 对话能力", "cfontsize": 0.9, "color": "#94a3b8"}},
{"widgettype": "Filler"} {"widgettype": "Filler"},
{
"widgettype": "Button",
"id": "new_session_btn",
"options": {"label": "+ 新建会话", "css": "small"},
"binds": [{
"wid": "self",
"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:'AgentIO',options:{css:'filler',url:'/pipeline_core/api/agent_chat.dspy?session_id='+sid,model_dataurl:'/pipeline_core/api/agent_model_options.dspy',model_cwidth:14,placeholder:'输入你的需求...'}}});"
}]
}
] ]
}, },
{ {
@ -17,14 +29,30 @@
"options": {"url": "{{entire_url('/pipeline_core/api/agent_menus.dspy')}}", "method": "GET"} "options": {"url": "{{entire_url('/pipeline_core/api/agent_menus.dspy')}}", "method": "GET"}
}, },
{ {
"widgettype": "AgentIO", "widgettype": "TabPanel",
"id": "chat_io", "id": "session_tabs",
"options": { "options": {
"css": "filler", "css": "filler",
"url": "/pipeline_core/api/agent_chat.dspy", "width": "100%",
"model_dataurl": "/pipeline_core/api/agent_model_options.dspy", "height": "100%",
"model_cwidth": 14, "tab_pos": "top",
"placeholder": "输入你的需求..." "items": [
{
"name": "session_default",
"label": "会话 1",
"removable": false,
"content": {
"widgettype": "AgentIO",
"options": {
"css": "filler",
"url": "/pipeline_core/api/agent_chat.dspy?session_id=default",
"model_dataurl": "/pipeline_core/api/agent_model_options.dspy",
"model_cwidth": 14,
"placeholder": "输入你的需求..."
}
}
}
]
} }
} }
] ]

View File

@ -74,13 +74,16 @@ if action == 'send_message':
if not uid: if not uid:
uid = 'user-01' # 测试兼容 uid = 'user-01' # 测试兼容
# ── 会话内唯一标识(web 多 tab 独立会话):前端每个 tab 传独立 session_id ──
session_id = (params_kw or {}).get('session_id', '') or ''
# ── 走 gateway 统一入口(Web AgentIO 通道)── # ── 走 gateway 统一入口(Web AgentIO 通道)──
from pipeline_service.gateway import get_gateway from pipeline_service.gateway import get_gateway
gateway = get_gateway() gateway = get_gateway()
async def agent_stream(): async def agent_stream():
_base = entire_url("/") _base = entire_url("/")
async for chunk in gateway.run_message("web", uid, prompt, base_url=_base): async for chunk in gateway.run_message("web", uid, prompt, base_url=_base, session_id=session_id):
data = json.loads(chunk) data = json.loads(chunk)
t = data.get('type', '') t = data.get('type', '')