From aeb865b02abf4d376f31649a31f57e965e5032a6 Mon Sep 17 00:00:00 2001 From: ymq Date: Sat, 8 Aug 2026 21:41:45 +0800 Subject: [PATCH] =?UTF-8?q?v3.2:=20AgentInput=20native=20handler=20?= =?UTF-8?q?=E2=80=94=20{content:...}=20format=20+=20url=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend: yields {content: 'text'} | {error: 'text'} chunks (AgentOut compatible) Frontend: AgentInput.url set, native HttpResponseStream splits \n + JSON.parse Bind script: just creates chat bubbles, no custom XHR --- wwwroot/api/cockpit_chat.dspy | 8 ++++---- wwwroot/index_cockpit.ui | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index e1324ba..a5e5ef8 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -192,7 +192,7 @@ if action == 'send_message': ctx = await _load_ctx(sor, uid) model = await _sel_model(sor, user_model_id) if not model: - d = json.dumps({"type":"widget","widget":_w_card("❌ 错误",_w_text("无可用LLM"),"error")},ensure_ascii=False)+'\n' + d = json.dumps({"error": "没有可用的LLM模型配置"}, ensure_ascii=False)+'\n' debug(f"YIELD error: {d[:80]}") yield d return @@ -215,12 +215,12 @@ if action == 'send_message': if act.get('action') == 'tool_call': tool = act.get('tool','') label = _tool_labels.get(tool,tool) - d = json.dumps({"type":"widget","widget":_w_progress(f"🔄 {label}")},ensure_ascii=False)+'\n' + d = json.dumps({"content": f"🔄 {label}..."}, ensure_ascii=False)+'\n' debug(f"YIELD progress: {d[:60]}") yield d result = await _exec_tool(sor, tool, act.get('params',{}), ctx, uid, org_id) ok = result.startswith("OK:") - d = json.dumps({"type":"widget","widget":_w_card(f"{'✅' if ok else '❌'} {label}",_w_text(result),"success" if ok else "error")},ensure_ascii=False)+'\n' + d = json.dumps({"content": f"{'✅' if ok else '❌'} {label}: {result}"}, ensure_ascii=False)+'\n' debug(f"YIELD result: {d[:60]}") yield d msgs.append({"role":"assistant","content":raw}) @@ -229,7 +229,7 @@ if action == 'send_message': agent_reply = raw; break if not agent_reply: agent_reply = "处理超时" - d = json.dumps({"type":"widget","widget":_w_card("🤖 驾驶舱 Agent",_w_text(agent_reply),"reply")},ensure_ascii=False)+'\n' + d = json.dumps({"content": agent_reply}, ensure_ascii=False)+'\n' debug(f"YIELD final: {d[:60]}") yield d await sor.C('pipeline_conversations',{'id':getID(),'role':'agent','content':agent_reply,'msg_type':'text','org_id':org_id,'created_by':'system'}) diff --git a/wwwroot/index_cockpit.ui b/wwwroot/index_cockpit.ui index a162eb1..64f651b 100644 --- a/wwwroot/index_cockpit.ui +++ b/wwwroot/index_cockpit.ui @@ -182,6 +182,7 @@ "id": "chat_input", "options": { "placeholder": "输入你的需求...", + "url": "/pipeline-sdlc/api/cockpit_chat.dspy", "model_dataurl": "/pipeline-sdlc/api/cockpit_model_options.dspy", "model_cwidth": 14 }, @@ -191,7 +192,7 @@ "event": "inputed", "actiontype": "script", "target": "self", - "script": "var p=params.prompt;var mid=params.model_id||'';if(typeof mid==='object'&&mid!==null)mid=mid.model_id||'';var ctx=bricks.getWidgetById('context_data',bricks.app);var cd=ctx?ctx.getValue():{};var iid=cd.iteration_id||'';var pid=cd.project_id||'';var fnames=params.file_names||[];var chat=bricks.getWidgetById('chat_scroll',bricks.app);var at=null;var _makeWidget=function(desc){if(!desc||!desc.widgettype)return null;var Klass=bricks.Factory.get(desc.widgettype);if(!Klass)return null;var opts=JSON.parse(JSON.stringify(desc.options||{}));if(desc.subwidgets&&desc.subwidgets.length>0){opts.subwidgets=desc.subwidgets.map(function(s){return _makeWidget(s)}).filter(function(s){return s!==null})}return new Klass(opts)};if(chat){var ub=new bricks.HBox({width:'100%'});var um=new bricks.VBox({width:'85%',alignSelf:'flex-end',bgcolor:'#dbeafe',borderRadius:'12px',padding:'12px 16px',marginBottom:'10px',gap:'4px'});um.add_widget(new bricks.Text({text:'你',cfontsize:0.75,color:'#2563eb',fontWeight:'bold'}));um.add_widget(new bricks.Text({text:p,cfontsize:0.95,color:'#1e293b',whiteSpace:'pre-wrap'}));for(var i=0;i0){opts.subwidgets=desc.subwidgets.map(function(s){return _makeWidget(s)}).filter(function(s){return s!==null})}return new Klass(opts)};if(chat){var ub=new bricks.HBox({width:'100%'});var um=new bricks.VBox({width:'85%',alignSelf:'flex-end',bgcolor:'#dbeafe',borderRadius:'12px',padding:'12px 16px',marginBottom:'10px',gap:'4px'});um.add_widget(new bricks.Text({text:'你',cfontsize:0.75,color:'#2563eb',fontWeight:'bold'}));um.add_widget(new bricks.Text({text:p,cfontsize:0.95,color:'#1e293b',whiteSpace:'pre-wrap'}));for(var i=0;i