frontend: replace AgentIO with TextArea+Button+XHR streaming
Simple controlled approach: TextArea input, Button click handler does XHR POST with url-encoded body, onprogress splits 0x0a, JSON.parse each line, appends Text widget to chat. No AgentIO interference.
This commit is contained in:
parent
e2291b7735
commit
78c3a926d1
@ -174,25 +174,48 @@
|
||||
"border": "1px solid #e2e8f0",
|
||||
"borderTop": "none",
|
||||
"borderRadius": "0 0 8px 8px",
|
||||
"padding": "0"
|
||||
"padding": "8px 12px",
|
||||
"gap": "4px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "AgentIO",
|
||||
"id": "chat_input",
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"placeholder": "输入你的需求...",
|
||||
"url": "/pipeline-sdlc/api/cockpit_chat.dspy",
|
||||
"model_dataurl": "/pipeline-sdlc/api/cockpit_model_options.dspy",
|
||||
"model_cwidth": 14
|
||||
"gap": "8px",
|
||||
"alignItems": "center"
|
||||
},
|
||||
"binds": [
|
||||
"subwidgets": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "inputed",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var ai=bricks.getWidgetById('chat_input',bricks.app);if(ai&&ai.inputw&&!ai._hooked){ai._hooked=true;ai.inputw.unbind('inputed');ai.inputw.bind('inputed',function(e){console.log('HOOKED inputed');var p=e.params.prompt||'';var mid=e.params.model_id||'';var chat=bricks.getWidgetById('chat_scroll',bricks.app);var at=null;if(chat){var ab=new bricks.HBox({width:'100%'});var am=new bricks.VBox({width:'85%',alignSelf:'flex-start',bgcolor:'#e8f0fe',borderRadius:'12px',padding:'12px 16px',marginBottom:'10px',gap:'4px'});am.add_widget(new bricks.Text({text:'Agent',cfontsize:0.75,color:'#3b82f6',fontWeight:'bold'}));at=new bricks.Text({text:'...',cfontsize:0.85,color:'#64748b'});am.add_widget(at);ab.add_widget(new bricks.Svg({rate:2,url:bricks_resource('imgs/llm.svg')}));ab.add_widget(am);ab.add_widget(new bricks.VBox({css:'filler'}));chat.add_widget(ab)}var xhr=new XMLHttpRequest();xhr.open('POST','/pipeline-sdlc/api/cockpit_chat.dspy');xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');var lastLen=0;xhr.onprogress=function(){var t=xhr.responseText;var d=t.substring(lastLen);lastLen=t.length;var lines=d.split(String.fromCharCode(10));for(var j=0;j<lines.length;j++){var line=lines[j].trim();if(!line)continue;try{var obj=JSON.parse(line);if(obj.content&&at){var pw=at.parent();if(pw){pw.remove_widget(at);at=null}var tw=new bricks.Text({text:obj.content,cfontsize:0.85,color:'#334155',whiteSpace:'pre-wrap',width:'100%'});pw.add_widget(tw);chat.scrollToBottom()}}catch(e){console.log(e)}}};xhr.onload=function(){var s=bricks.getWidgetById('stats_row',bricks.app);if(s)s.render({})};xhr.onerror=function(){if(at)at.set_text('网络错误')};xhr.send('message_text='+encodeURIComponent(p)+'&model_id='+encodeURIComponent(mid))})}"
|
||||
"widgettype": "Filler",
|
||||
"options": {
|
||||
"css": "filler"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "TextArea",
|
||||
"id": "msg_input",
|
||||
"options": {
|
||||
"placeholder": "输入你的需求...",
|
||||
"cheight": 3,
|
||||
"css": "filler"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"id": "send_btn",
|
||||
"options": {
|
||||
"label": "发送",
|
||||
"css": "primary"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var ta=bricks.getWidgetById('msg_input',bricks.app);var p=(ta?ta.getValue():'')||'';if(!p.trim())return;var ctx=bricks.getWidgetById('context_data',bricks.app);var cd=ctx?ctx.getValue():{};var iid=cd.iteration_id||'';var pid=cd.project_id||'';var chat=bricks.getWidgetById('chat_scroll',bricks.app);if(!chat)return;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'}));ub.add_widget(new bricks.VBox({css:'filler'}));ub.add_widget(um);ub.add_widget(new bricks.Svg({rate:2,url:bricks_resource('imgs/chat-user.svg')}));chat.add_widget(ub);ta.setValue('');var ab=new bricks.HBox({width:'100%'});var am=new bricks.VBox({width:'85%',alignSelf:'flex-start',bgcolor:'#e8f0fe',borderRadius:'12px',padding:'12px 16px',marginBottom:'10px',gap:'4px'});am.add_widget(new bricks.Text({text:'Agent',cfontsize:0.75,color:'#3b82f6',fontWeight:'bold'}));ab.add_widget(new bricks.Svg({rate:2,url:bricks_resource('imgs/llm.svg')}));ab.add_widget(am);ab.add_widget(new bricks.VBox({css:'filler'}));chat.add_widget(ab);var xhr=new XMLHttpRequest();xhr.open('POST','/pipeline-sdlc/api/cockpit_chat.dspy');xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');var lastLen=0;xhr.onprogress=function(){var t=xhr.responseText;var d=t.substring(lastLen);lastLen=t.length;d.split('\\n').forEach(function(line){line=line.trim();if(!line)return;try{var obj=JSON.parse(line);if(obj.content){var tw=new bricks.Text({text:obj.content,cfontsize:0.85,color:'#334155',whiteSpace:'pre-wrap'});am.add_widget(tw);chat.scrollToBottom()}}catch(e){console.log('parse err:',line.substring(0,50))}})};xhr.onload=function(){var s=bricks.getWidgetById('stats_row',bricks.app);if(s)s.render({})};xhr.send('action=send_message&message_text='+encodeURIComponent(p)+'&model_id=&iteration_id='+encodeURIComponent(iid)+'&project_id='+encodeURIComponent(pid))"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user