fix: 文件传输改用file_names数组(避免File对象序列化丢失)
This commit is contained in:
parent
03d3116a30
commit
fe15f4861b
@ -12,6 +12,7 @@ bricks.AgentInput = class extends bricks.VBox {
|
||||
this.inputfilew = new bricks.UiFile({name: 'add_file'});
|
||||
this.filesbar = new bricks.DynamicColumn({col_cwidth: 10});
|
||||
this.add_files = [];
|
||||
this.file_names = [];
|
||||
this.inputfilew.bind('changed', this.file_added.bind(this));
|
||||
|
||||
// text input
|
||||
@ -76,12 +77,14 @@ bricks.AgentInput = class extends bricks.VBox {
|
||||
}
|
||||
var d = Object.assign({}, p, {
|
||||
add_files: this.add_files,
|
||||
file_names: this.file_names,
|
||||
prompt: txt.prompt,
|
||||
model_id: mid
|
||||
});
|
||||
this.dispatch('inputed', d);
|
||||
this.textw.setValue('');
|
||||
this.add_files = [];
|
||||
this.file_names = [];
|
||||
this.filesbar.clear_widgets();
|
||||
this.filesbar.hide();
|
||||
}
|
||||
@ -91,6 +94,7 @@ bricks.AgentInput = class extends bricks.VBox {
|
||||
var file = this.inputfilew.getValue().add_file;
|
||||
this.inputfilew.reset();
|
||||
this.add_files.push(file);
|
||||
this.file_names.push(file.name);
|
||||
this.filesbar.clear_widgets();
|
||||
var w = new bricks.DeletableLabel({label: file.name});
|
||||
this.filesbar.add_widget(w);
|
||||
@ -100,6 +104,7 @@ bricks.AgentInput = class extends bricks.VBox {
|
||||
|
||||
deleted_file(file) {
|
||||
this.add_files = this.add_files.filter(i => i !== file);
|
||||
this.file_names = this.file_names.filter(n => n !== file.name);
|
||||
if (this.add_files.length === 0) this.filesbar.hide();
|
||||
}
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@
|
||||
"event": "inputed",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var p=params.prompt;var files=params.add_files||[];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 chat=bricks.getWidgetById('chat_scroll',bricks.app);var at=null;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:'\u4f60',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);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:'\u6b63\u5728\u5206\u6790\u9700\u6c42...',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 fnames=files.map(function(f){return(f&&f.name)||''}).filter(Boolean);var body='message_text='+encodeURIComponent(p)+'&iteration_id='+encodeURIComponent(iid)+'&project_id='+encodeURIComponent(pid)+'&model_id='+encodeURIComponent(mid)+'&action=send_message&file_paths='+encodeURIComponent(JSON.stringify(fnames));fetch('/pipeline-sdlc/api/cockpit_chat.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(r){if(r.success){if(at)at.set_text(r.agent_reply||'\u5df2\u5904\u7406');var s=bricks.getWidgetById('stats_row',bricks.app);if(s)s.render({});}else{if(at)at.set_text('\u9519\u8bef: '+(r.error||'\u672a\u77e5\u9519\u8bef'));}});"
|
||||
"script": "var p=params.prompt;var files=params.add_files||[];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 chat=bricks.getWidgetById('chat_scroll',bricks.app);var at=null;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'}));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);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 fnames=params.file_names||[];var body='message_text='+encodeURIComponent(p)+'&iteration_id='+encodeURIComponent(iid)+'&project_id='+encodeURIComponent(pid)+'&model_id='+encodeURIComponent(mid)+'&action=send_message&file_paths='+encodeURIComponent(JSON.stringify(fnames));fetch('/pipeline-sdlc/api/cockpit_chat.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(r){if(r.success){if(at)at.set_text(r.agent_reply||'已处理');var s=bricks.getWidgetById('stats_row',bricks.app);if(s)s.render({});}else{if(at)at.set_text('错误: '+(r.error||'未知错误'));}});"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user