From 57104fa29ab08cb9c1d4635c17fcb7c71c4f88aa Mon Sep 17 00:00:00 2001 From: Dustin Healy <54083382+dustinhealy@users.noreply.github.com> Date: Tue, 10 Nov 2026 21:04:04 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AC=20feat:=20Configure=20Slack=20Conn?= =?UTF-8?q?ections=20in=20the=20Agent=20Builder=20(#17614)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * đź’¬ feat: Configure Slack Connections in the Agent Builder * fix: Bound Channel Credentials to One Activation Attempt * fix: Scope Channel Completion to Its Dialog Lifetime --- .../SidePanel/Agents/AgentConfig.tsx | 13 + .../components/SidePanel/Agents/Channels.tsx | 662 ++++++++++++++++ .../Agents/__tests__/Channels.spec.tsx | 729 ++++++++++++++++++ client/src/locales/en/translation.json | 47 +- packages/data-provider/src/api-endpoints.ts | 5 + packages/data-provider/src/data-service.ts | 69 ++ packages/data-provider/src/keys.ts | 7 + 7 files changed, 1531 insertions(+), 1 deletion(-) create mode 100644 client/src/components/SidePanel/Agents/Channels.tsx create mode 100644 client/src/components/SidePanel/Agents/__tests__/Channels.spec.tsx diff --git a/client/src/components/SidePanel/Agents/AgentConfig.tsx b/client/src/components/SidePanel/Agents/AgentConfig.tsx index c9e00247b5..87e3ac8858 100644 --- a/client/src/components/SidePanel/Agents/AgentConfig.tsx +++ b/client/src/components/SidePanel/Agents/AgentConfig.tsx @@ -13,6 +13,7 @@ import { validateEmail, cn } from '~/utils'; import Instructions from './Instructions'; import FileContext from './FileContext'; import AgentAvatar from './AgentAvatar'; +import Channels from './Channels'; import Starters from './Starters'; import { Panel } from '~/common'; @@ -21,9 +22,17 @@ const fieldClass = 'h-9'; export default function AgentConfig({ instructionsPromptStatus, onRetryInstructionsPrompt, + showChannels = false, + channelsAgentId, + channelsUserId, + channelsTenantId, }: { instructionsPromptStatus?: InstructionsPromptStatus; onRetryInstructionsPrompt?: () => void; + showChannels?: boolean; + channelsAgentId?: string; + channelsUserId?: string; + channelsTenantId?: string; }) { const localize = useLocalize(); const methods = useFormContext(); @@ -168,6 +177,10 @@ export default function AgentConfig({ )} + {showChannels && channelsUserId && ( + + )} + {/* CONVERSATION STARTERS */} diff --git a/client/src/components/SidePanel/Agents/Channels.tsx b/client/src/components/SidePanel/Agents/Channels.tsx new file mode 100644 index 0000000000..938b18b0fb --- /dev/null +++ b/client/src/components/SidePanel/Agents/Channels.tsx @@ -0,0 +1,662 @@ +import { useId, useRef, useState, useEffect } from 'react'; +import { Info, Plus, Power, Trash2 } from 'lucide-react'; +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import { dataService, MutationKeys, QueryKeys } from 'librechat-data-provider'; +import { + Button, + Input, + Label, + Tag, + Textarea, + Separator, + TooltipAnchor, + OGDialog, + OGDialogContent, + OGDialogTitle, + OGDialogFooter, +} from '@librechat/client'; +import type { AgentChannel } from 'librechat-data-provider'; +import type { TranslationKeys } from '~/hooks'; +import { useLocalize } from '~/hooks'; + +const statusLabels: Record = { + pending_install: 'com_ui_channels_pending', + active: 'com_ui_channels_active', + disabled: 'com_ui_channels_disabled', + deleting: 'com_ui_channels_deleting', +}; + +const actionLabels: Record = { + pending_install: 'com_ui_channels_setup', + active: 'com_ui_channels_manage', + disabled: 'com_ui_channels_manage', + deleting: 'com_ui_channels_manage', +}; + +const statusColors: Record = { + pending_install: 'bg-status-warning', + active: 'bg-status-success', + disabled: 'bg-status-neutral', + deleting: 'bg-status-info', +}; + +function ChannelStatus({ status }: { status: AgentChannel['status'] }) { + const localize = useLocalize(); + return ( + + + ); +} + +function Channel({ + agentId, + channel, + onClose, + userId, + tenantId, + enabled, +}: { + agentId: string; + channel: AgentChannel; + onClose: () => void; + userId: string; + tenantId?: string; + enabled: boolean; +}) { + const localize = useLocalize(); + const queryClient = useQueryClient(); + const id = useId(); + const [panel, setPanel] = useState<'setup' | 'delete' | 'mode' | null>( + channel.status === 'pending_install' ? 'setup' : null, + ); + const setup = panel === 'setup'; + const [appId, setAppId] = useState(channel.slack?.appId ?? ''); + const [botToken, setBotToken] = useState(''); + const [signingSecret, setSigningSecret] = useState(''); + const credentials = useRef({ botToken: '', signingSecret: '' }); + const active = useRef(true); + useEffect(() => { + active.current = true; + return () => { + active.current = false; + credentials.current = { botToken: '', signingSecret: '' }; + }; + }, []); + const manifest = useQuery( + [QueryKeys.agentChannelManifest, userId, tenantId, agentId, channel.channelId], + () => dataService.getAgentChannelManifest(agentId, channel.channelId), + { retry: false }, + ); + const needsSigningSecret = manifest.data?.settings.socket_mode_enabled === false; + let signingLabel: TranslationKeys = 'com_ui_channels_signing_secret'; + if (needsSigningSecret) signingLabel = 'com_ui_channels_signing_secret_required'; + else if (manifest.data?.settings.socket_mode_enabled === true) + signingLabel = 'com_ui_channels_signing_secret_optional'; + const canActivate = + enabled && + manifest.isSuccess && + !manifest.isFetching && + Boolean(appId.trim() && botToken.trim() && (!needsSigningSecret || signingSecret.trim())); + const manifestText = manifest.data ? JSON.stringify(manifest.data, null, 2) : ''; + const readiness = useRef({ enabled, canActivate }); + readiness.current = { enabled, canActivate }; + const clearCredentials = () => { + credentials.current = { botToken: '', signingSecret: '' }; + if (!active.current) return; + setBotToken(''); + setSigningSecret(''); + }; + const mutation = useMutation({ + mutationKey: [MutationKeys.agentChannels, userId, tenantId, agentId, channel.channelId], + // Cached callbacks retain only a revocable holder, never render snapshots of secrets. + mutationFn: async (action: 'activate' | 'disable' | 'delete' | 'mode') => { + try { + if (!active.current || !readiness.current.enabled || channel.createdBy !== userId) + throw new Error('Channel unavailable'); + if (action === 'mode') { + if (!channel.revision || channel.status !== 'disabled') + throw new Error('Channel mode changed'); + return await dataService.changeAgentChannelMode( + agentId, + channel.channelId, + channel.credentialMode === 'shared' ? 'per_user' : 'shared', + channel.revision, + ); + } + if (action === 'activate') { + const token = credentials.current.botToken.trim(); + const secret = credentials.current.signingSecret.trim(); + if (!readiness.current.canActivate || !token || (needsSigningSecret && !secret)) + throw new Error('Channel activation unavailable'); + const slack = { + appId: appId.trim(), + botToken: token, + ...(secret ? { signingSecret: secret } : {}), + }; + // Consume the form before dispatch; only the pending HTTP invocation owns its payload. + clearCredentials(); + return await dataService.activateAgentChannel(agentId, channel.channelId, { slack }); + } + if (action === 'disable') + return await dataService.disableAgentChannel(agentId, channel.channelId); + await dataService.deleteAgentChannel(agentId, channel.channelId); + } finally { + clearCredentials(); + } + }, + onSuccess: async () => { + if (active.current) onClose(); + await queryClient.invalidateQueries([QueryKeys.agentChannels, userId, tenantId, agentId]); + await queryClient.invalidateQueries([ + QueryKeys.agentChannelManifest, + userId, + tenantId, + agentId, + channel.channelId, + ]); + }, + }); + const busy = !enabled || mutation.isLoading || channel.status === 'deleting'; + return ( + <> +
+
+ {localize('com_ui_channels_slack')} + +
+
+
+
{localize('com_ui_channels_connection_type')}
+
+ +
+
+
+
+ {localize('com_ui_channels_connection_id_label')} +
+
+ {channel.channelId} +
+
+ {channel.slack?.teamId && ( +
+
{localize('com_ui_channels_workspace_label')}
+
{channel.slack.teamId}
+
+ )} + {channel.slack?.appId && ( +
+
{localize('com_ui_channels_app_id')}
+
{channel.slack.appId}
+
+ )} +
+ {mutation.isError && ( +

+ {localize('com_ui_channels_action_error')} +

+ )} + {mutation.isError && mutation.variables === 'activate' && ( +

+ {localize('com_ui_channels_activation_retry')} +

+ )} + {panel === 'mode' && ( +
+

{localize('com_ui_channel_link_mode_confirm')}

+

+ {localize( + channel.credentialMode === 'shared' + ? 'com_ui_channel_link_per_user_notice' + : 'com_ui_channels_shared_notice', + )} +

+
+ + +
+
+ )} + {panel === 'delete' && ( +
+

{localize('com_ui_channels_delete_confirm')}

+
+ + +
+
+ )} +
+ {setup && ( + <> +

{localize('com_ui_channels_install_step')}

+

+ {localize('com_ui_channels_instructions')} +

+ + )} + {manifest.isLoading &&

{localize('com_ui_channels_loading')}

} + {manifest.isError && ( +
+

{localize('com_ui_channels_manifest_error')}

+ +
+ )} + {manifest.data && ( +
+ {localize('com_ui_channels_manifest')} + +