fix: AgentIO.sys_post() + global ref — reliable Conform confirm handler
This commit is contained in:
parent
bf6b14f81e
commit
1fd689ca62
@ -70,27 +70,9 @@ bricks.AgentOut = class extends bricks.VBox {
|
|||||||
w.bind('conformed', function(){
|
w.bind('conformed', function(){
|
||||||
var payload = opts._payload || {};
|
var payload = opts._payload || {};
|
||||||
payload._system_action = opts._action;
|
payload._system_action = opts._action;
|
||||||
// Find parent AgentIO
|
var agentio = bricks._active_agentio;
|
||||||
var agentio = this.parent_widget;
|
if (agentio && agentio.sys_post){
|
||||||
while (agentio && !(agentio instanceof bricks.AgentIO)){
|
agentio.sys_post(payload);
|
||||||
agentio = agentio.parent_widget;
|
|
||||||
}
|
|
||||||
if (agentio && agentio.opts && agentio.opts.url){
|
|
||||||
// Create output widget and process streaming response
|
|
||||||
var mout = new bricks.AgentOutput({
|
|
||||||
reply_url: agentio.opts.reply_url
|
|
||||||
});
|
|
||||||
agentio.msg_box.add_widget(mout);
|
|
||||||
var hr = new bricks.HttpResponseStream();
|
|
||||||
hr.post(agentio.opts.url, {params: payload}).then(function(resp){
|
|
||||||
if (resp){
|
|
||||||
return hr.handle_chunk(resp, agentio.chunk_response.bind(agentio, mout));
|
|
||||||
} else {
|
|
||||||
mout.run_stopped();
|
|
||||||
}
|
|
||||||
}).then(function(){
|
|
||||||
agentio.chunk_ended();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@ -357,6 +339,26 @@ bricks.AgentIO = class extends bricks.VBox {
|
|||||||
this.inputw.bind('inputed', this.user_inputed.bind(this));
|
this.inputw.bind('inputed', this.user_inputed.bind(this));
|
||||||
this.add_widget(this.msg_box);
|
this.add_widget(this.msg_box);
|
||||||
this.add_widget(this.inputw);
|
this.add_widget(this.inputw);
|
||||||
|
// Store reference for Conform/system action handlers
|
||||||
|
bricks._active_agentio = this;
|
||||||
|
}
|
||||||
|
// Called by Conform confirm handler to post system actions
|
||||||
|
sys_post(payload){
|
||||||
|
var mout = new bricks.AgentOutput({
|
||||||
|
reply_url: this.opts.reply_url
|
||||||
|
});
|
||||||
|
this.msg_box.add_widget(mout);
|
||||||
|
var hr = new bricks.HttpResponseStream();
|
||||||
|
var self = this;
|
||||||
|
hr.post(this.opts.url, {params: payload}).then(function(resp){
|
||||||
|
if (resp){
|
||||||
|
return hr.handle_chunk(resp, self.chunk_response.bind(self, mout));
|
||||||
|
} else {
|
||||||
|
mout.run_stopped();
|
||||||
|
}
|
||||||
|
}).then(function(){
|
||||||
|
self.chunk_ended();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
chunk_response(mout, l){
|
chunk_response(mout, l){
|
||||||
l = l.trim();
|
l = l.trim();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user