From d573fa40f7210aa5e7a9e924d446c45d821b5bde Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 19 Apr 2024 17:13:05 +0800 Subject: [PATCH] bugfix --- bricks/bricks.js | 18 +++++++++--------- bricks/form.js | 5 +++++ bricks/llm_dialog.js | 38 +++++++++++++++++++++++++++++++------- bricks/running.js | 37 ++++++++++++++++++++++++++----------- examples/add_widget.ui | 17 +++++++++++++++++ examples/form.ui | 11 ++++++++++- examples/script_action.ui | 18 ++++++++++++++++++ 7 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 examples/script_action.ui diff --git a/bricks/bricks.js b/bricks/bricks.js index f4be44e..63ea645 100755 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -171,10 +171,10 @@ bricks.buildEventBind = function(from_widget, widget, event, desc){ } -bricks.universal_handler = function(from_widget, widget, desc, event){ - var f = bricks.buildEventHandler(from_widget, desc, event); +bricks.universal_handler = async function(from_widget, widget, desc, event){ + var f = await bricks.buildEventHandler(from_widget, desc, event); if (f){ - return f(event); + return await f(event); } bricks.debug('universal_handler() error', 'from_widget=', from_widget, @@ -182,7 +182,7 @@ bricks.universal_handler = function(from_widget, widget, desc, event){ 'desc=', desc, event); } -bricks.buildEventHandler = function(w, desc, event){ +bricks.buildEventHandler = async function(w, desc, event){ var target = bricks.getWidgetById(desc.target, w); if (! target){ bricks.debug('target miss desc=', desc, 'w=', w); @@ -198,7 +198,7 @@ bricks.buildEventHandler = function(w, desc, event){ params:desc.dataparams, script:desc.datascript } - rtdata = bricks.getRealtimeData(w, data_desc); + rtdata = await bricks.getRealtimeData(w, data_desc); } if (typeof event.params == typeof {}){ rtdata = bricks.extend(rtdata, event.params); @@ -228,7 +228,7 @@ bricks.buildEventHandler = function(w, desc, event){ break; } } -bricks.getRealtimeData = function(w, desc){ +bricks.getRealtimeData = async function(w, desc){ var target = bricks.getWidgetById(desc.widget, w); var f; bricks.debug('getRealtimeData() calling ...'); @@ -242,7 +242,7 @@ bricks.getRealtimeData = function(w, desc){ } if (desc.script){ f = bricks.buildScriptHandler(null, target, null, desc) - return f(); + return await f(); } debug('getRealtimeData():desc=', desc, 'f=', f); return null; @@ -341,8 +341,8 @@ bricks.buildScriptHandler = function(w, target, rtdata, desc){ bricks.extend(params, desc.params) bricks.extend(params, rtdata); params = bricks.apply_data(params, rtdata); - var f = new Function('target', 'params', 'event', desc.script); - bricks.debug('params=', params, 'buildScriptHandler() ..........'); + var AsyncFunction = Object.getPrototypeOf(async function(){}).constructor; + var f = new AsyncFunction('target', 'params', 'event', desc.script); return f.bind(target, target, params); } bricks.buildDispatchEventHandler = function(w, target, rtdata, desc){ diff --git a/bricks/form.js b/bricks/form.js index 39b63fa..d1610fe 100644 --- a/bricks/form.js +++ b/bricks/form.js @@ -2,6 +2,11 @@ var bricks = window.bricks || {}; bricks.need_formdata_fields = ['file', 'image', 'video', 'audio']; +bricks.show_resp_message_or_error = async function(resp){ + var desc = await resp.json(); + await bricks.widgetBuild(desc, bricks.Body); +} + bricks.FieldGroup = class extends bricks.VBox { constructor(opts){ opts.leftMargin = '10px'; diff --git a/bricks/llm_dialog.js b/bricks/llm_dialog.js index 4883e38..4056696 100644 --- a/bricks/llm_dialog.js +++ b/bricks/llm_dialog.js @@ -51,14 +51,16 @@ bricks.LlmMsgBox = class extends bricks.HBox { super(opts); var img = new bricks.Icon({rate:2,url:this.icon||bricks_resource('imgs/user.png')}); this.w = new bricks.MdWidget({mdtext:' '}); - this.run = new bricks.Running({target:this}); + this.run = new bricks.BaseRunning({target:this}); this.w.set_css(this.msg_css||'llm_msg'); this.add_widget(img); + this.add_widget(this.run) this.add_widget(this.w); this.messages = []; } responsed(){ - this.run.dismiss(); + this.run.stop_timepass(); + this.remove_widget(this.run); this.w.md_content = ''; } user_msg_format(){ @@ -147,18 +149,40 @@ bricks.LlmDialog = class extends bricks.VBox { opts.height = opts.height || '100%'; super(opts); this.title_w = new bricks.HBox({cheight:2}); - this.title_w.add_widget(new bricks.Icon({ - rate:2,url:this.llm_icon||bricks_resource('imgs/llm.png') - })); this.title_w.set_css(this.title_ccs||'llm_title'); - var t_w = new bricks.Text({text:this.model}); - this.title_w.add_widget(t_w); this.add_widget(this.title_w); + this.model_info_ws = {}; + this.show_models_info(); var filler = new bricks.Filler({}); this.body = new bricks.VScrollPanel({height:'100%'}); filler.add_widget(this.body); this.add_widget(filler); } + show_models_info(){ + for(var i=0;i