fix: AgentInput 用 bricks.UiCode 替代 Form,消除嵌套Form

This commit is contained in:
yumoqing 2026-08-06 14:05:44 +08:00
parent 0a6baa0d52
commit 255863aa66

View File

@ -1,5 +1,5 @@
// AgentInput — 集成模型选择的输入控件
// options: { model_dataurl, placeholder, url(提交图标), ...TextFiles 原有属性 }
// options: { model_dataurl, model_cwidth, placeholder, url(提交图标), ...VBox 原有属性 }
// event: inputed → { prompt, add_files, model_id }
bricks.AgentInput = class extends bricks.VBox {
@ -17,25 +17,18 @@ bricks.AgentInput = class extends bricks.VBox {
// text input
this.textw = new bricks.UiText({
name: 'prompt',
placeholder: opts.placeholder || '输入你的需求...'
placeholder: opts.placeholder || ''
});
// model selector (UiCode dropdown)
this.model_selector = new bricks.Form({
name: 'model_selector',
cols: 1,
cwidth: opts.model_cwidth || 14,
fields: [{
name: 'model_id',
uitype: 'code',
label: '',
placeholder: '选择模型',
cwidth: 12,
dataurl: opts.model_dataurl || '',
valueField: 'model_id',
textField: 'model_id_text',
params: { valueField: 'model_id', textField: 'model_id_text' }
}]
// model selector — 直接用 UiCode不用 Form
this.model_selector = new bricks.UiCode({
name: 'model_id',
valueField: 'model_id',
textField: 'model_id_text',
dataurl: opts.model_dataurl || '',
params: opts.model_params || {},
cwidth: opts.model_cwidth || 12,
cfontsize: 0.85
});
// add file button
@ -52,7 +45,7 @@ bricks.AgentInput = class extends bricks.VBox {
});
inputw.bind('click', this.input_finished.bind(this));
// button row: [add_file] [model_selector] [filler] [submit]
// button row: [+add] [model_selector] [filler] [submit]
var hbox = new bricks.HBox({cheight: 1.5, gap: '4px', alignItems: 'center'});
hbox.add_widget(addfilew);
hbox.add_widget(this.model_selector);
@ -73,11 +66,10 @@ bricks.AgentInput = class extends bricks.VBox {
var txt = this.textw.getValue();
if (!txt.prompt || txt.prompt.length < 1) return;
var p = this.params || {};
var mv = this.model_selector.getValue() || {};
var d = Object.assign({}, p, {
add_files: this.add_files,
prompt: txt.prompt,
model_id: mv.model_id || ''
model_id: this.model_selector.getValue() || ''
});
this.dispatch('inputed', d);
this.textw.setValue('');
@ -106,10 +98,9 @@ bricks.AgentInput = class extends bricks.VBox {
}
getValue() {
var mv = this.model_selector.getValue() || {};
return {
prompt: (this.textw.getValue() || {}).prompt || '',
model_id: mv.model_id || ''
model_id: this.model_selector.getValue() || ''
};
}
};