fix: monkey-patch handle_chunk to split on 0x0a — no AgentIO changes
This commit is contained in:
parent
f4c3ee0d56
commit
81a6126896
@ -81,7 +81,7 @@
|
||||
"event": "changed",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var v=this.getValue();var pid=(v||{}).project_id||'';if(!pid)return;fetch('/pipeline-sdlc/api/cockpit_context_update.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'project_id='+encodeURIComponent(pid)}).then(function(r){return r.json()}).then(function(r){if(r.success){var pl=bricks.getWidgetById('task_btn',bricks.app);if(pl&&pl.text_w)pl.text_w.set_text('任务');}})"
|
||||
"script": "if(!bricks.HttpResponseStream._patched){\nbricks.HttpResponseStream._patched=true;\nvar orig=bricks.HttpResponseStream.prototype.handle_chunk;\nbricks.HttpResponseStream.prototype.handle_chunk=function(resp,handler){\nconsole.log('PATCHED handle_chunk');\nconst reader=resp.body.getReader();\nconst decoder=new TextDecoder('utf-8');\nlet result=await reader.read();\nvar buff_='';\nwhile(!result.done){\nconst text=decoder.decode(result.value);\nbuff_+=text;\nconst lines=buff_.split(String.fromCharCode(10));\nfor(var i=0;i<lines.length-1;i++){handler(lines[i])}\nbuff_=lines[lines.length-1];\nresult=await reader.read()}\nif(buff_!=''){handler(buff_)}\n}};var v=this.getValue();var pid=(v||{}).project_id||'';if(!pid)return;fetch('/pipeline-sdlc/api/cockpit_context_update.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'project_id='+encodeURIComponent(pid)}).then(function(r){return r.json()}).then(function(r){if(r.success){var pl=bricks.getWidgetById('task_btn',bricks.app);if(pl&&pl.text_w)pl.text_w.set_text('任务');}})"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -157,15 +157,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "inputed",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "console.log('AGENTIO inputed bind fired',JSON.stringify(params));var ai=this;if(ai.inputw&&!ai._done){ai._done=true;var orig=ai.user_inputed.bind(ai);ai.inputw.unbind('inputed');ai.inputw.bind('inputed',function(e){console.log('HOOKED:',e.params.prompt);orig(e);var p=e.params.prompt||'';var mid=e.params.model_id||'';var xhr=new XMLHttpRequest();xhr.open('POST',ai.opts.url);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(String.fromCharCode(10)).forEach(function(line){line=line.trim();if(!line)return;try{var obj=JSON.parse(line);console.log('STREAM:',line.substring(0,40))}catch(e){}})};xhr.onload=function(){console.log('DONE')};xhr.send('action=send_message&message_text='+encodeURIComponent(p)+'&model_id='+encodeURIComponent(mid))})}"
|
||||
}
|
||||
]
|
||||
"binds": []
|
||||
},
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user