fix: AgentInput 用 bricks.UiCode 替代 Form,消除嵌套Form
This commit is contained in:
parent
0a6baa0d52
commit
255863aa66
@ -1,5 +1,5 @@
|
|||||||
// AgentInput — 集成模型选择的输入控件
|
// AgentInput — 集成模型选择的输入控件
|
||||||
// options: { model_dataurl, placeholder, url(提交图标), ...TextFiles 原有属性 }
|
// options: { model_dataurl, model_cwidth, placeholder, url(提交图标), ...VBox 原有属性 }
|
||||||
// event: inputed → { prompt, add_files, model_id }
|
// event: inputed → { prompt, add_files, model_id }
|
||||||
|
|
||||||
bricks.AgentInput = class extends bricks.VBox {
|
bricks.AgentInput = class extends bricks.VBox {
|
||||||
@ -17,25 +17,18 @@ bricks.AgentInput = class extends bricks.VBox {
|
|||||||
// text input
|
// text input
|
||||||
this.textw = new bricks.UiText({
|
this.textw = new bricks.UiText({
|
||||||
name: 'prompt',
|
name: 'prompt',
|
||||||
placeholder: opts.placeholder || '输入你的需求...'
|
placeholder: opts.placeholder || ''
|
||||||
});
|
});
|
||||||
|
|
||||||
// model selector (UiCode dropdown)
|
// model selector — 直接用 UiCode,不用 Form
|
||||||
this.model_selector = new bricks.Form({
|
this.model_selector = new bricks.UiCode({
|
||||||
name: 'model_selector',
|
|
||||||
cols: 1,
|
|
||||||
cwidth: opts.model_cwidth || 14,
|
|
||||||
fields: [{
|
|
||||||
name: 'model_id',
|
name: 'model_id',
|
||||||
uitype: 'code',
|
|
||||||
label: '',
|
|
||||||
placeholder: '选择模型',
|
|
||||||
cwidth: 12,
|
|
||||||
dataurl: opts.model_dataurl || '',
|
|
||||||
valueField: 'model_id',
|
valueField: 'model_id',
|
||||||
textField: 'model_id_text',
|
textField: 'model_id_text',
|
||||||
params: { 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
|
// add file button
|
||||||
@ -52,7 +45,7 @@ bricks.AgentInput = class extends bricks.VBox {
|
|||||||
});
|
});
|
||||||
inputw.bind('click', this.input_finished.bind(this));
|
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'});
|
var hbox = new bricks.HBox({cheight: 1.5, gap: '4px', alignItems: 'center'});
|
||||||
hbox.add_widget(addfilew);
|
hbox.add_widget(addfilew);
|
||||||
hbox.add_widget(this.model_selector);
|
hbox.add_widget(this.model_selector);
|
||||||
@ -73,11 +66,10 @@ bricks.AgentInput = class extends bricks.VBox {
|
|||||||
var txt = this.textw.getValue();
|
var txt = this.textw.getValue();
|
||||||
if (!txt.prompt || txt.prompt.length < 1) return;
|
if (!txt.prompt || txt.prompt.length < 1) return;
|
||||||
var p = this.params || {};
|
var p = this.params || {};
|
||||||
var mv = this.model_selector.getValue() || {};
|
|
||||||
var d = Object.assign({}, p, {
|
var d = Object.assign({}, p, {
|
||||||
add_files: this.add_files,
|
add_files: this.add_files,
|
||||||
prompt: txt.prompt,
|
prompt: txt.prompt,
|
||||||
model_id: mv.model_id || ''
|
model_id: this.model_selector.getValue() || ''
|
||||||
});
|
});
|
||||||
this.dispatch('inputed', d);
|
this.dispatch('inputed', d);
|
||||||
this.textw.setValue('');
|
this.textw.setValue('');
|
||||||
@ -106,10 +98,9 @@ bricks.AgentInput = class extends bricks.VBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue() {
|
||||||
var mv = this.model_selector.getValue() || {};
|
|
||||||
return {
|
return {
|
||||||
prompt: (this.textw.getValue() || {}).prompt || '',
|
prompt: (this.textw.getValue() || {}).prompt || '',
|
||||||
model_id: mv.model_id || ''
|
model_id: this.model_selector.getValue() || ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user