mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
🐛 fix: slove the group member agents cant set skills problem (#12021)
fix: slove the group member agents cant set skills problem
This commit is contained in:
parent
9c653e0053
commit
2302940079
4 changed files with 86 additions and 20 deletions
|
|
@ -15,6 +15,11 @@ const POLL_INTERVAL_MS = 1000; // 每秒轮询一次
|
|||
const POLL_TIMEOUT_MS = 15_000; // 15 秒超时
|
||||
|
||||
interface KlavisServerItemProps {
|
||||
/**
|
||||
* Optional agent ID to use instead of currentAgentConfig
|
||||
* Used in group profile to specify which member's plugins to toggle
|
||||
*/
|
||||
agentId?: string;
|
||||
/**
|
||||
* Identifier used for storage (e.g., 'google-calendar')
|
||||
*/
|
||||
|
|
@ -28,7 +33,7 @@ interface KlavisServerItemProps {
|
|||
}
|
||||
|
||||
const KlavisServerItem = memo<KlavisServerItemProps>(
|
||||
({ identifier, label, server, serverName }) => {
|
||||
({ identifier, label, server, serverName, agentId }) => {
|
||||
const { t } = useTranslation('setting');
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const [isToggling, setIsToggling] = useState(false);
|
||||
|
|
@ -43,6 +48,10 @@ const KlavisServerItem = memo<KlavisServerItemProps>(
|
|||
const createKlavisServer = useToolStore((s) => s.createKlavisServer);
|
||||
const refreshKlavisServerTools = useToolStore((s) => s.refreshKlavisServerTools);
|
||||
|
||||
// Get effective agent ID (agentId prop or current active agent)
|
||||
const activeAgentId = useAgentStore((s) => s.activeAgentId);
|
||||
const effectiveAgentId = agentId || activeAgentId || '';
|
||||
|
||||
// 清理所有定时器
|
||||
const cleanup = useCallback(() => {
|
||||
if (windowCheckIntervalRef.current) {
|
||||
|
|
@ -162,10 +171,24 @@ const KlavisServerItem = memo<KlavisServerItemProps>(
|
|||
|
||||
// Get plugin ID for this server (使用 identifier 作为 pluginId)
|
||||
const pluginId = server ? server.identifier : '';
|
||||
const [checked, togglePlugin] = useAgentStore((s) => [
|
||||
agentSelectors.currentAgentPlugins(s).includes(pluginId),
|
||||
s.togglePlugin,
|
||||
]);
|
||||
const plugins =
|
||||
useAgentStore(agentSelectors.getAgentConfigById(effectiveAgentId))?.plugins || [];
|
||||
const checked = plugins.includes(pluginId);
|
||||
const updateAgentConfigById = useAgentStore((s) => s.updateAgentConfigById);
|
||||
|
||||
// Toggle plugin for the effective agent
|
||||
const togglePlugin = useCallback(
|
||||
async (pluginIdToToggle: string) => {
|
||||
if (!effectiveAgentId) return;
|
||||
const currentPlugins = plugins;
|
||||
const hasPlugin = currentPlugins.includes(pluginIdToToggle);
|
||||
const newPlugins = hasPlugin
|
||||
? currentPlugins.filter((id) => id !== pluginIdToToggle)
|
||||
: [...currentPlugins, pluginIdToToggle];
|
||||
await updateAgentConfigById(effectiveAgentId, { plugins: newPlugins });
|
||||
},
|
||||
[effectiveAgentId, plugins, updateAgentConfigById],
|
||||
);
|
||||
|
||||
const handleConnect = async () => {
|
||||
if (!userId) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ const POLL_INTERVAL_MS = 1000;
|
|||
const POLL_TIMEOUT_MS = 15_000;
|
||||
|
||||
interface LobehubSkillServerItemProps {
|
||||
/**
|
||||
* Optional agent ID to use instead of currentAgentConfig
|
||||
* Used in group profile to specify which member's plugins to toggle
|
||||
*/
|
||||
agentId?: string;
|
||||
/**
|
||||
* Display label for the provider
|
||||
*/
|
||||
|
|
@ -23,7 +28,7 @@ interface LobehubSkillServerItemProps {
|
|||
provider: string;
|
||||
}
|
||||
|
||||
const LobehubSkillServerItem = memo<LobehubSkillServerItemProps>(({ provider, label }) => {
|
||||
const LobehubSkillServerItem = memo<LobehubSkillServerItemProps>(({ provider, label, agentId }) => {
|
||||
const { t } = useTranslation('setting');
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const [isToggling, setIsToggling] = useState(false);
|
||||
|
|
@ -38,6 +43,10 @@ const LobehubSkillServerItem = memo<LobehubSkillServerItemProps>(({ provider, la
|
|||
const checkStatus = useToolStore((s) => s.checkLobehubSkillStatus);
|
||||
const getAuthorizeUrl = useToolStore((s) => s.getLobehubSkillAuthorizeUrl);
|
||||
|
||||
// Get effective agent ID (agentId prop or current active agent)
|
||||
const activeAgentId = useAgentStore((s) => s.activeAgentId);
|
||||
const effectiveAgentId = agentId || activeAgentId || '';
|
||||
|
||||
const cleanup = useCallback(() => {
|
||||
if (windowCheckIntervalRef.current) {
|
||||
clearInterval(windowCheckIntervalRef.current);
|
||||
|
|
@ -129,10 +138,23 @@ const LobehubSkillServerItem = memo<LobehubSkillServerItemProps>(({ provider, la
|
|||
);
|
||||
|
||||
const pluginId = server ? server.identifier : '';
|
||||
const [checked, togglePlugin] = useAgentStore((s) => [
|
||||
agentSelectors.currentAgentPlugins(s).includes(pluginId),
|
||||
s.togglePlugin,
|
||||
]);
|
||||
const plugins = useAgentStore(agentSelectors.getAgentConfigById(effectiveAgentId))?.plugins || [];
|
||||
const checked = plugins.includes(pluginId);
|
||||
const updateAgentConfigById = useAgentStore((s) => s.updateAgentConfigById);
|
||||
|
||||
// Toggle plugin for the effective agent
|
||||
const togglePlugin = useCallback(
|
||||
async (pluginIdToToggle: string) => {
|
||||
if (!effectiveAgentId) return;
|
||||
const currentPlugins = plugins;
|
||||
const hasPlugin = currentPlugins.includes(pluginIdToToggle);
|
||||
const newPlugins = hasPlugin
|
||||
? currentPlugins.filter((id) => id !== pluginIdToToggle)
|
||||
: [...currentPlugins, pluginIdToToggle];
|
||||
await updateAgentConfigById(effectiveAgentId, { plugins: newPlugins });
|
||||
},
|
||||
[effectiveAgentId, plugins, updateAgentConfigById],
|
||||
);
|
||||
|
||||
// Listen for OAuth success message from popup window
|
||||
useEffect(() => {
|
||||
|
|
@ -156,9 +178,10 @@ const LobehubSkillServerItem = memo<LobehubSkillServerItemProps>(({ provider, la
|
|||
.lobehubSkillServers?.find((s) => s.identifier === provider);
|
||||
if (latestServer?.status === LobehubSkillStatus.CONNECTED) {
|
||||
const newPluginId = latestServer.identifier;
|
||||
const isAlreadyEnabled = agentSelectors
|
||||
.currentAgentPlugins(useAgentStore.getState())
|
||||
.includes(newPluginId);
|
||||
const currentAgentPlugins =
|
||||
agentSelectors.getAgentConfigById(effectiveAgentId)(useAgentStore.getState())
|
||||
?.plugins || [];
|
||||
const isAlreadyEnabled = currentAgentPlugins.includes(newPluginId);
|
||||
if (!isAlreadyEnabled) {
|
||||
console.log('[LobehubSkill] Auto-enabling plugin:', newPluginId);
|
||||
togglePlugin(newPluginId);
|
||||
|
|
@ -169,7 +192,7 @@ const LobehubSkillServerItem = memo<LobehubSkillServerItemProps>(({ provider, la
|
|||
|
||||
window.addEventListener('message', handleMessage);
|
||||
return () => window.removeEventListener('message', handleMessage);
|
||||
}, [provider, cleanup, checkStatus, togglePlugin]);
|
||||
}, [provider, cleanup, checkStatus, togglePlugin, effectiveAgentId]);
|
||||
|
||||
const handleConnect = async () => {
|
||||
// 只有已连接状态才阻止重新连接
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ export const useControls = ({ setUpdating }: { setUpdating: (updating: boolean)
|
|||
key: type.identifier,
|
||||
label: (
|
||||
<KlavisServerItem
|
||||
agentId={agentId}
|
||||
identifier={type.identifier}
|
||||
label={type.label}
|
||||
server={getServerByName(type.identifier)}
|
||||
|
|
@ -184,7 +185,7 @@ export const useControls = ({ setUpdating }: { setUpdating: (updating: boolean)
|
|||
),
|
||||
}))
|
||||
: [],
|
||||
[isKlavisEnabledInEnv, allKlavisServers, installedKlavisIds, recommendedKlavisIds],
|
||||
[isKlavisEnabledInEnv, allKlavisServers, installedKlavisIds, recommendedKlavisIds, agentId],
|
||||
);
|
||||
|
||||
// LobeHub Skill Provider 列表项 - 只展示已安装或推荐的
|
||||
|
|
@ -197,10 +198,22 @@ export const useControls = ({ setUpdating }: { setUpdating: (updating: boolean)
|
|||
).map((provider) => ({
|
||||
icon: <LobehubSkillIcon icon={provider.icon} label={provider.label} />,
|
||||
key: provider.id, // 使用 provider.id 作为 key,与 pluginId 保持一致
|
||||
label: <LobehubSkillServerItem label={provider.label} provider={provider.id} />,
|
||||
label: (
|
||||
<LobehubSkillServerItem
|
||||
agentId={agentId}
|
||||
label={provider.label}
|
||||
provider={provider.id}
|
||||
/>
|
||||
),
|
||||
}))
|
||||
: [],
|
||||
[isLobehubSkillEnabled, allLobehubSkillServers, installedLobehubIds, recommendedLobehubIds],
|
||||
[
|
||||
isLobehubSkillEnabled,
|
||||
allLobehubSkillServers,
|
||||
installedLobehubIds,
|
||||
recommendedLobehubIds,
|
||||
agentId,
|
||||
],
|
||||
);
|
||||
|
||||
// Builtin 工具列表项(不包含 Klavis 和 LobeHub Skill)
|
||||
|
|
|
|||
|
|
@ -271,6 +271,7 @@ const AgentTool = memo<AgentToolProps>(
|
|||
key: type.identifier,
|
||||
label: (
|
||||
<KlavisServerItem
|
||||
agentId={effectiveAgentId}
|
||||
identifier={type.identifier}
|
||||
label={type.label}
|
||||
server={getServerByName(type.identifier)}
|
||||
|
|
@ -279,7 +280,7 @@ const AgentTool = memo<AgentToolProps>(
|
|||
),
|
||||
}))
|
||||
: [],
|
||||
[isKlavisEnabledInEnv, allKlavisServers],
|
||||
[isKlavisEnabledInEnv, allKlavisServers, effectiveAgentId],
|
||||
);
|
||||
|
||||
// LobeHub Skill Provider 列表项
|
||||
|
|
@ -289,10 +290,16 @@ const AgentTool = memo<AgentToolProps>(
|
|||
? LOBEHUB_SKILL_PROVIDERS.map((provider) => ({
|
||||
icon: <LobehubSkillIcon icon={provider.icon} label={provider.label} />,
|
||||
key: provider.id, // 使用 provider.id 作为 key,与 pluginId 保持一致
|
||||
label: <LobehubSkillServerItem label={provider.label} provider={provider.id} />,
|
||||
label: (
|
||||
<LobehubSkillServerItem
|
||||
agentId={effectiveAgentId}
|
||||
label={provider.label}
|
||||
provider={provider.id}
|
||||
/>
|
||||
),
|
||||
}))
|
||||
: [],
|
||||
[isLobehubSkillEnabled, allLobehubSkillServers],
|
||||
[isLobehubSkillEnabled, allLobehubSkillServers, effectiveAgentId],
|
||||
);
|
||||
|
||||
// Handle plugin remove via Tag close - use byId actions
|
||||
|
|
|
|||
Loading…
Reference in a new issue