import asyncio async def _do(): action = params_kw.get("action", "") kb_id = params_kw.get("kb_id", "") env = request._run_ns folder_label = params_kw.get("folder_label", "") if action == "create_dir": dir_name = params_kw.get("dir_name", "") parent_id = params_kw.get("parent_id", "") if dir_name: async with get_sor_context(env, 'rag') as sor: dir_id = "dir_" + str(abs(hash(dir_name + parent_id)))[:12] await sor.sqlExe( "INSERT INTO document_chunks (id, doc_id, kb_id, chunk_index, chunk_type, content, description, created_at) " "VALUES (${id}$, '', ${kb_id}$, 0, 'directory', ${name}$, ${parent}$, NOW())", {"id": dir_id, "kb_id": kb_id, "name": dir_name, "parent": parent_id}) folder_label = folder_label or dir_name elif action == "delete_item": item_id = params_kw.get("item_id", "") if item_id: async with get_sor_context(env, 'rag') as sor: await sor.sqlExe("DELETE FROM document_chunks WHERE id=${id}$", {"id": item_id}) return { "widgettype": "VBox", "options": {"spacing": "12px"}, "subwidgets": [ { "widgettype": "HBox", "options": {"spacing": "4px"}, "subwidgets": [ {"widgettype": "Text", "options": {"text": "📂 " + str(folder_label), "cfontsize": 16, "fontWeight": "bold", "color": "#333"}}, {"widgettype": "Text", "options": {"text": "操作成功", "cfontsize": 12, "color": "#50b86c"}} ] } ] } result = asyncio.get_event_loop().run_until_complete(_do())