{
    "widgettype": "VBox",
    "options": {"padding": "20px", "spacing": "16px", "width": "100%", "height": "100%", "css": "filler"},
    "subwidgets": [
        {"widgettype": "Text", "options": {"text": "🔍 知识检索", "cfontsize": 22, "fontWeight": "bold", "color": "#1a1a2e"}},
        {"widgettype": "Text", "options": {"text": "选择知识库，输入文字或上传文件检索", "cfontsize": 13, "color": "#888"}},
        {
            "widgettype": "HBox",
            "options": {"spacing": "12px", "alignItems": "center"},
            "subwidgets": [
                {"widgettype": "Text", "options": {"text": "知识库:", "cfontsize": 13, "color": "#666"}},
                {
                    "widgettype": "UiCode",
                    "id": "kb_selector",
                    "options": {"name": "kb_id", "dataurl": "{{entire_url('./kb_options.dspy')}}", "text": "全部", "cwidth": 18}
                },
                {
                    "widgettype": "SearchBar",
                    "id": "search_bar",
                    "options": {"cwidth": 25, "cfontsize": 14, "placeholder": "输入检索关键词..."}
                },
                {
                    "widgettype": "UiFile",
                    "id": "search_file",
                    "options": {"accept": "", "multiple": false, "preview": false, "otext": "📎 文件检索", "cwidth": 10, "cheight": 3, "css": "card", "border": "1px dashed #ccc"}
                }
            ]
        },
        {
            "widgettype": "VBox",
            "options": {"css": "filler", "marginTop": "16px", "width": "100%", "padding": "0", "spacing": "0"},
            "subwidgets": [
                {
                    "widgettype": "VScrollPanel",
                    "id": "search_results",
                    "options": {"css": "filler", "padding": "0", "spacing": "0"},
                    "subwidgets": [
                        {"widgettype": "Text", "options": {"text": "选择知识库，输入文字或上传文件开始检索", "cfontsize": 14, "color": "#aaa", "halign": "center", "marginTop": "40px"}}
                    ]
                }
            ]
        }
    ],
    "binds": [
        {
            "wid": "search_bar",
            "event": "search",
            "actiontype": "script",
            "script": "var kw=event.params.keyword||'';var kb=bricks.getWidgetById('kb_selector',this);var kb_id=(kb&&kb.resultValue())||'all';var target=bricks.getWidgetById('search_results',this);if(target){bricks.buildUrlwidgetHandler(this,target,{},{options:{url:'/rag/knowledge_bases_list/search_result.dspy',params:{_webbricks_:1,kb_id:kb_id,keyword:kw}},mode:'replace'})()}"
        },
        {
            "wid": "search_file",
            "event": "changed",
            "actiontype": "script",
            "target": "search_file",
            "script": "var f=this.value;if(!f)return;if(Array.isArray(f))f=f[0];if(!f)return;var kb=bricks.getWidgetById('kb_selector',this.parent);var kb_id=(kb&&kb.resultValue())||'all';var fd=new FormData();fd.append('file',f);var u='/rag/knowledge_bases_list/search_result.dspy?_webbricks_=1&kb_id='+encodeURIComponent(kb_id)+'&file_name='+encodeURIComponent(f.name);var pv=this.parent.parent;fetch(u,{method:'POST',body:fd}).then(function(r){return r.json()}).then(function(d){var fp=bricks.getWidgetById('search_results',pv);if(fp){fp.clear_widgets();bricks.widgetBuild(d,fp).then(function(w){if(w)fp.add_widget(w)})}})"
        }
    ]
}
