diff --git a/wwwroot/engine_configs_list/engine_form.dspy b/wwwroot/engine_configs_list/engine_form.dspy index dd48c9e..e21ec76 100644 --- a/wwwroot/engine_configs_list/engine_form.dspy +++ b/wwwroot/engine_configs_list/engine_form.dspy @@ -19,6 +19,22 @@ def card(title, desc, prefix, cfg): shielded = (not cfg["model_id"]) or cfg["status"] != "active" state = "⛔ 已屏蔽" if shielded else "✅ 启用中" key_hint = "已配置(留空沿用)" if cfg["has_key"] else "未配置" + test_script = ("var p=this.parent.parent;" + "var m=bricks.getWidgetById('" + prefix + "_model',p).resultValue()||'';" + "var b=bricks.getWidgetById('" + prefix + "_base',p).resultValue()||'';" + "var k=bricks.getWidgetById('" + prefix + "_key',p).resultValue()||'';" + "fetch('./engine_test.dspy?_webbricks_=1&engine_type=" + prefix + + "&model_id='+encodeURIComponent(m)+'&api_base='+encodeURIComponent(b)+'&api_key='+encodeURIComponent(k))" + ".then(function(r){return r.json()}).then(function(d){" + "bricks.show_message({title:'" + title + " 测试',message:d.message||d.error||JSON.stringify(d)})})") + save_script = ("var p=this.parent.parent;" + "var m=bricks.getWidgetById('" + prefix + "_model',p).resultValue()||'';" + "var b=bricks.getWidgetById('" + prefix + "_base',p).resultValue()||'';" + "var k=bricks.getWidgetById('" + prefix + "_key',p).resultValue()||'';" + "fetch('./engine_save.dspy?_webbricks_=1&engine_type=" + prefix + + "&model_id='+encodeURIComponent(m)+'&api_base='+encodeURIComponent(b)+'&api_key='+encodeURIComponent(k))" + ".then(function(r){return r.json()}).then(function(d){" + "bricks.show_message({title:'保存',message:(d.error||('已保存:'+(d.shielded?'能力屏蔽':'已启用')))+'(刷新页面查看状态)'})})") return { "widgettype": "VBox", "options": {"width": "100%", "spacing": "12px", "bgcolor": "#f8f9fa", "padding": "16px", "css": "card"}, "subwidgets": [ @@ -33,8 +49,8 @@ def card(title, desc, prefix, cfg): {"widgettype": "Input", "id": prefix + "_key", "options": {"label": "API Key(" + key_hint + ")", "name": prefix + "_key", "type": "password", "cwidth": 24}} ]}, {"widgettype": "HBox", "options": {"spacing": "12px"}, "subwidgets": [ - {"widgettype": "Button", "options": {"label": "测试连通", "css": "outline", "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": "var p=this.parent.parent;var m=bricks.getWidgetById('" + prefix + "_model',p).resultValue()||'';var b=bricks.getWidgetById('" + prefix + "_base',p).resultValue()||'';var k=bricks.getWidgetById('" + prefix + "_key',p).resultValue()||'';fetch('./engine_test.dspy?_webbricks_=1&engine_type=" + prefix + "&model_id='+encodeURIComponent(m)+'&api_base='+encodeURIComponent(b)+'&api_key='+encodeURIComponent(k)).then(function(r){return r.json()}).then(function(d){bricks.show_message({title:'" + title + " 测试',message:d.message||d.error||JSON.stringify(d)})})"}]}, - {"widgettype": "Button", "options": {"label": "保存", "bgcolor": "#10b981", "color": "#fff", "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": "var p=this.parent.parent;var m=bricks.getWidgetById('" + prefix + "_model',p).resultValue()||'';var b=bricks.getWidgetById('" + prefix + "_base',p).resultValue()||'';var k=bricks.getWidgetById('" + prefix + "_key',p).resultValue()||'';fetch('./engine_save.dspy?_webbricks_=1&engine_type=" + prefix + "&model_id='+encodeURIComponent(m)+'&api_base='+encodeURIComponent(b)+'&api_key='+encodeURIComponent(k)).then(function(r){return r.json()}).then(function(d){bricks.show_message({title:'保存',message:(d.error||('已保存:'+(d.shielded?'能力屏蔽':'已启用')))+'(刷新页面查看状态)'})})"}]} + {"widgettype": "Button", "options": {"label": "测试连通", "css": "outline", "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": test_script}]}}, + {"widgettype": "Button", "options": {"label": "保存", "bgcolor": "#10b981", "color": "#fff", "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": save_script}]}} ]} ] }