PicoBot/web/src/components/Settings/useSharedModalData.ts
oudecheng c2cc072b2e feat(settings): 拆分设置页为懒加载标签页并支持子代理创建/删除
- ConfigPage 拆分为 16 个懒加载 tab + 2 个 modal,首屏体积大幅下降
- 抽取 CapabilityTabs 共享组件,统一专家/子代理能力配置 UI
- 后端新增 POST /api/subagents/create、DELETE /api/subagents/delete
- SubagentRuntime 新增 create_subagent/delete_subagent,含路径校验与 builtin 保护
- SubagentModal 支持 create/edit 双模式、body 编辑、自身排除防自递归
- SubagentsTab 增加搜索、provider/model 标签、删除二次确认
- 修复 reload() 使用进程 cwd 而非 self.cwd 的隔离缺陷
2026-08-04 21:06:17 +08:00

56 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 共享数据 hook专家/子代理模态框打开时加载能力勾选列表所需的数据
// 在模态框挂载时触发,避免在 ConfigPage 顶层预加载
import { useEffect, useState } from 'react';
import { listSkills } from '../../api/skills';
import { listTools } from '../../api/tools';
import { listSubagents } from '../../api/subagents';
import { listModelOptions } from '../../api/experts';
import type {
SkillListResponse,
ToolsListResponse,
SubagentListResponse,
ModelOptionsResponse,
} from './types';
export interface SharedModalData {
skillList: SkillListResponse | null;
toolList: ToolsListResponse | null;
subagentList: SubagentListResponse | null;
modelOptions: ModelOptionsResponse | null;
loading: boolean;
}
/**
* 在模态框挂载时一次性加载 skills/tools/subagents/modelOptions。
* 用于专家/子代理编辑模态框的能力勾选列表与 provider/model 下拉框。
*/
export function useSharedModalData(enabled: boolean): SharedModalData {
const [skillList, setSkillList] = useState<SkillListResponse | null>(null);
const [toolList, setToolList] = useState<ToolsListResponse | null>(null);
const [subagentList, setSubagentList] = useState<SubagentListResponse | null>(null);
const [modelOptions, setModelOptions] = useState<ModelOptionsResponse | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (!enabled) return;
let cancelled = false;
setLoading(true);
Promise.all([listSkills(), listTools(), listSubagents(), listModelOptions()])
.then(([s, t, sub, m]) => {
if (cancelled) return;
if (s) setSkillList(s);
if (t) setToolList(t);
if (sub) setSubagentList(sub);
if (m) setModelOptions(m);
})
.finally(() => {
if (!cancelled) setLoading(false);
});
return () => {
cancelled = true;
};
}, [enabled]);
return { skillList, toolList, subagentList, modelOptions, loading };
}