mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 05:20:55 +00:00
💬 feat: Configure Slack Connections in the Agent Builder (#17614)
* 💬 feat: Configure Slack Connections in the Agent Builder
* fix: Bound Channel Credentials to One Activation Attempt
* fix: Scope Channel Completion to Its Dialog Lifetime
This commit is contained in:
parent
0c6c223cdd
commit
57104fa29a
7 changed files with 1531 additions and 1 deletions
|
|
@ -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<AgentForm>();
|
||||
|
|
@ -168,6 +177,10 @@ export default function AgentConfig({
|
|||
</div>
|
||||
)}
|
||||
|
||||
{showChannels && channelsUserId && (
|
||||
<Channels agentId={channelsAgentId} userId={channelsUserId} tenantId={channelsTenantId} />
|
||||
)}
|
||||
|
||||
{/* CONVERSATION STARTERS */}
|
||||
<Starters />
|
||||
|
||||
|
|
|
|||
662
client/src/components/SidePanel/Agents/Channels.tsx
Normal file
662
client/src/components/SidePanel/Agents/Channels.tsx
Normal file
|
|
@ -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<AgentChannel['status'], TranslationKeys> = {
|
||||
pending_install: 'com_ui_channels_pending',
|
||||
active: 'com_ui_channels_active',
|
||||
disabled: 'com_ui_channels_disabled',
|
||||
deleting: 'com_ui_channels_deleting',
|
||||
};
|
||||
|
||||
const actionLabels: Record<AgentChannel['status'], TranslationKeys> = {
|
||||
pending_install: 'com_ui_channels_setup',
|
||||
active: 'com_ui_channels_manage',
|
||||
disabled: 'com_ui_channels_manage',
|
||||
deleting: 'com_ui_channels_manage',
|
||||
};
|
||||
|
||||
const statusColors: Record<AgentChannel['status'], string> = {
|
||||
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 (
|
||||
<span className="text-text-secondary inline-flex shrink-0 items-center gap-1.5 text-xs">
|
||||
<span aria-hidden="true" className={`size-1.5 rounded-full ${statusColors[status]}`} />
|
||||
{localize(statusLabels[status])}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<>
|
||||
<div className="min-h-0 space-y-4 overflow-y-auto px-6 pb-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<span className="font-medium">{localize('com_ui_channels_slack')}</span>
|
||||
<ChannelStatus status={channel.status} />
|
||||
</div>
|
||||
<dl className="border-border-light bg-surface-secondary space-y-3 rounded-lg border p-3 text-sm">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<dt className="text-text-secondary">{localize('com_ui_channels_connection_type')}</dt>
|
||||
<dd>
|
||||
<Tag
|
||||
variant="neutral"
|
||||
label={localize(
|
||||
channel.credentialMode === 'shared'
|
||||
? 'com_ui_channel_link_shared'
|
||||
: 'com_ui_channel_link_per_user',
|
||||
)}
|
||||
/>
|
||||
</dd>
|
||||
</div>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<dt className="text-text-secondary shrink-0">
|
||||
{localize('com_ui_channels_connection_id_label')}
|
||||
</dt>
|
||||
<dd className="text-text-primary min-w-0 text-end font-mono text-xs break-all">
|
||||
{channel.channelId}
|
||||
</dd>
|
||||
</div>
|
||||
{channel.slack?.teamId && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<dt className="text-text-secondary">{localize('com_ui_channels_workspace_label')}</dt>
|
||||
<dd className="text-text-primary font-mono text-xs">{channel.slack.teamId}</dd>
|
||||
</div>
|
||||
)}
|
||||
{channel.slack?.appId && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<dt className="text-text-secondary">{localize('com_ui_channels_app_id')}</dt>
|
||||
<dd className="text-text-primary font-mono text-xs">{channel.slack.appId}</dd>
|
||||
</div>
|
||||
)}
|
||||
</dl>
|
||||
{mutation.isError && (
|
||||
<p role="alert" className="text-text-primary text-sm">
|
||||
{localize('com_ui_channels_action_error')}
|
||||
</p>
|
||||
)}
|
||||
{mutation.isError && mutation.variables === 'activate' && (
|
||||
<p className="text-text-secondary text-sm">
|
||||
{localize('com_ui_channels_activation_retry')}
|
||||
</p>
|
||||
)}
|
||||
{panel === 'mode' && (
|
||||
<div
|
||||
role="group"
|
||||
aria-label={localize('com_ui_channel_link_mode_confirm')}
|
||||
className="space-y-2"
|
||||
>
|
||||
<p>{localize('com_ui_channel_link_mode_confirm')}</p>
|
||||
<p>
|
||||
{localize(
|
||||
channel.credentialMode === 'shared'
|
||||
? 'com_ui_channel_link_per_user_notice'
|
||||
: 'com_ui_channels_shared_notice',
|
||||
)}
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" disabled={busy} onClick={() => mutation.mutate('mode')}>
|
||||
{localize(
|
||||
channel.credentialMode === 'shared'
|
||||
? 'com_ui_channel_link_switch_per_user'
|
||||
: 'com_ui_channel_link_switch_shared',
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => setPanel(null)}
|
||||
>
|
||||
{localize('com_ui_cancel')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{panel === 'delete' && (
|
||||
<div
|
||||
className="space-y-2"
|
||||
role="group"
|
||||
aria-label={localize('com_ui_channels_delete_confirm')}
|
||||
>
|
||||
<p className="text-sm">{localize('com_ui_channels_delete_confirm')}</p>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => setPanel(null)}
|
||||
>
|
||||
{localize('com_ui_cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
disabled={busy}
|
||||
onClick={() => mutation.mutate('delete')}
|
||||
>
|
||||
{localize('com_ui_delete')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-3">
|
||||
{setup && (
|
||||
<>
|
||||
<h4 className="text-sm font-medium">{localize('com_ui_channels_install_step')}</h4>
|
||||
<p className="text-text-secondary text-sm">
|
||||
{localize('com_ui_channels_instructions')}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
{manifest.isLoading && <p role="status">{localize('com_ui_channels_loading')}</p>}
|
||||
{manifest.isError && (
|
||||
<div role="alert" className="space-y-2 text-sm">
|
||||
<p>{localize('com_ui_channels_manifest_error')}</p>
|
||||
<Button type="button" variant="outline" onClick={() => void manifest.refetch()}>
|
||||
{localize('com_ui_channels_retry')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{manifest.data && (
|
||||
<details open className="space-y-2 text-sm">
|
||||
<summary className="cursor-pointer">{localize('com_ui_channels_manifest')}</summary>
|
||||
<Label className="sr-only" htmlFor={`${id}-manifest`}>
|
||||
{localize('com_ui_channels_manifest')}
|
||||
</Label>
|
||||
<Textarea id={`${id}-manifest`} rows={8} value={manifestText} readOnly />
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
{setup && (
|
||||
<div id={`${id}-setup`} className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{localize('com_ui_channels_credentials_step')}</h4>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor={`${id}-app`}>{localize('com_ui_channels_app_id')}</Label>
|
||||
<Input
|
||||
id={`${id}-app`}
|
||||
autoComplete="off"
|
||||
value={appId}
|
||||
disabled={busy}
|
||||
onChange={(event) => setAppId(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor={`${id}-token`}>{localize('com_ui_channels_bot_token')}</Label>
|
||||
<Input
|
||||
id={`${id}-token`}
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={botToken}
|
||||
disabled={busy}
|
||||
onChange={(event) => {
|
||||
credentials.current.botToken = event.target.value;
|
||||
setBotToken(event.target.value);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor={`${id}-secret`}>{localize(signingLabel)}</Label>
|
||||
<Input
|
||||
id={`${id}-secret`}
|
||||
type="password"
|
||||
required={needsSigningSecret}
|
||||
aria-required={needsSigningSecret}
|
||||
autoComplete="new-password"
|
||||
value={signingSecret}
|
||||
disabled={busy}
|
||||
onChange={(event) => {
|
||||
credentials.current.signingSecret = event.target.value;
|
||||
setSigningSecret(event.target.value);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={busy || channel.status === 'active' || !canActivate}
|
||||
onClick={() => mutation.mutate('activate')}
|
||||
>
|
||||
{localize('com_ui_channels_activate')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Separator />
|
||||
<OGDialogFooter className="flex-wrap gap-2 px-6 py-4 sm:justify-between">
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive-soft"
|
||||
disabled={busy || panel === 'delete'}
|
||||
onClick={() => {
|
||||
clearCredentials();
|
||||
setPanel('delete');
|
||||
}}
|
||||
>
|
||||
<Trash2 className="size-4" aria-hidden="true" />
|
||||
{localize('com_ui_delete')}
|
||||
</Button>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{channel.status !== 'active' && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
aria-expanded={setup}
|
||||
aria-controls={`${id}-setup`}
|
||||
onClick={() => {
|
||||
clearCredentials();
|
||||
mutation.reset();
|
||||
setPanel(setup ? null : 'setup');
|
||||
}}
|
||||
>
|
||||
{localize(setup ? 'com_ui_cancel' : 'com_ui_channels_setup')}
|
||||
</Button>
|
||||
)}
|
||||
{channel.status === 'disabled' && channel.revision && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
clearCredentials();
|
||||
setPanel('mode');
|
||||
}}
|
||||
>
|
||||
{localize('com_ui_channel_link_change_mode')}
|
||||
</Button>
|
||||
)}
|
||||
{channel.status === 'active' && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => mutation.mutate('disable')}
|
||||
>
|
||||
<Power className="size-4" aria-hidden="true" />
|
||||
{localize('com_ui_channels_disable')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</OGDialogFooter>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** The host controls feature availability and SHARE permission. */
|
||||
interface ChannelsProps {
|
||||
agentId?: string;
|
||||
userId: string;
|
||||
tenantId?: string;
|
||||
}
|
||||
export default function Channels(props: ChannelsProps) {
|
||||
return (
|
||||
<OwnedChannels key={JSON.stringify([props.userId, props.tenantId, props.agentId])} {...props} />
|
||||
);
|
||||
}
|
||||
function OwnedChannels({ agentId, userId, tenantId }: ChannelsProps) {
|
||||
const localize = useLocalize();
|
||||
const queryClient = useQueryClient();
|
||||
const id = useId();
|
||||
const triggerRef = useRef<HTMLButtonElement | null>(null);
|
||||
const [dialog, setDialog] = useState<string | null>(null);
|
||||
const [credentialMode, setCredentialMode] = useState<AgentChannel['credentialMode']>('per_user');
|
||||
const channels = useQuery(
|
||||
[QueryKeys.agentChannels, userId, tenantId, agentId],
|
||||
() => dataService.listAgentChannels(agentId!),
|
||||
{
|
||||
enabled: Boolean(agentId && userId),
|
||||
retry: false,
|
||||
// Presentation refresh only; the server owns deletion recovery and its timeouts.
|
||||
refetchInterval: (data, query) =>
|
||||
query.state.status !== 'error' && data?.some((channel) => channel.status === 'deleting')
|
||||
? 2_000
|
||||
: false,
|
||||
refetchIntervalInBackground: false,
|
||||
},
|
||||
);
|
||||
const create = useMutation({
|
||||
mutationKey: [MutationKeys.agentChannels, userId, tenantId, agentId],
|
||||
mutationFn: () => {
|
||||
if (!agentId || !userId || !channels.isSuccess) throw new Error('Channel owner unavailable');
|
||||
return dataService.createAgentChannel(agentId, credentialMode);
|
||||
},
|
||||
onSuccess: async (channel) => {
|
||||
queryClient.setQueryData<AgentChannel[]>(
|
||||
[QueryKeys.agentChannels, userId, tenantId, agentId],
|
||||
(current) => [
|
||||
...(current ?? []).filter((entry) => entry.channelId !== channel.channelId),
|
||||
channel,
|
||||
],
|
||||
);
|
||||
setDialog(channel.channelId);
|
||||
await queryClient.invalidateQueries([QueryKeys.agentChannels, userId, tenantId, agentId]);
|
||||
},
|
||||
});
|
||||
const selected = channels.data?.find((channel) => channel.channelId === dialog);
|
||||
const connectionTitle =
|
||||
selected?.status === 'pending_install'
|
||||
? 'com_ui_channels_setup_title'
|
||||
: 'com_ui_channels_manage';
|
||||
return (
|
||||
<section aria-labelledby={`${id}-heading`} className="mb-3 flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<h3
|
||||
id={`${id}-heading`}
|
||||
className="text-text-secondary text-2xs truncate font-medium tracking-wide uppercase"
|
||||
>
|
||||
{localize('com_ui_channels_title')}
|
||||
</h3>
|
||||
<TooltipAnchor
|
||||
description={localize('com_ui_channels_description')}
|
||||
side="top"
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
aria-label={localize('com_ui_channels_description')}
|
||||
className="text-text-tertiary hover:text-text-secondary focus-visible:ring-ring-primary flex size-4 shrink-0 items-center justify-center rounded focus:outline-hidden focus-visible:ring-2"
|
||||
>
|
||||
<Info className="size-3.5" aria-hidden="true" />
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="section-action"
|
||||
size="compact"
|
||||
disabled={!agentId || !userId || !channels.isSuccess}
|
||||
aria-label={localize('com_ui_channels_add')}
|
||||
onClick={(event) => {
|
||||
triggerRef.current = event.currentTarget;
|
||||
create.reset();
|
||||
setCredentialMode('per_user');
|
||||
setDialog('add');
|
||||
}}
|
||||
>
|
||||
<Plus className="size-3.5" strokeWidth={1.75} aria-hidden="true" />
|
||||
{localize('com_ui_add')}
|
||||
</Button>
|
||||
</div>
|
||||
{!agentId && (
|
||||
<p className="text-text-secondary text-2xs">{localize('com_ui_channels_save_first')}</p>
|
||||
)}
|
||||
{agentId && channels.isLoading && (
|
||||
<p role="status" className="text-text-secondary text-xs">
|
||||
{localize('com_ui_channels_loading')}
|
||||
</p>
|
||||
)}
|
||||
{channels.isError && (
|
||||
<div role="alert" className="space-y-2 text-sm">
|
||||
<p>{localize('com_ui_channels_list_error')}</p>
|
||||
<Button type="button" variant="outline" onClick={() => void channels.refetch()}>
|
||||
{localize('com_ui_channels_retry')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{channels.data?.map((channel) => (
|
||||
<div key={channel.channelId} className="flex items-center justify-between gap-2 text-sm">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
{localize('com_ui_channels_slack')}
|
||||
<ChannelStatus status={channel.status} />
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="section-action"
|
||||
size="compact"
|
||||
disabled={
|
||||
channels.isError || channel.status === 'deleting' || channel.createdBy !== userId
|
||||
}
|
||||
onClick={(event) => {
|
||||
triggerRef.current = event.currentTarget;
|
||||
setDialog(channel.channelId);
|
||||
}}
|
||||
>
|
||||
{localize(
|
||||
channel.createdBy !== userId
|
||||
? 'com_ui_channels_read_only'
|
||||
: actionLabels[channel.status],
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
<OGDialog
|
||||
open={dialog !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && !create.isLoading) setDialog(null);
|
||||
}}
|
||||
>
|
||||
<OGDialogContent
|
||||
className="w-11/12 max-w-lg gap-0 overflow-hidden p-0"
|
||||
aria-describedby={undefined}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
triggerRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<div className="flex max-h-[85dvh] flex-col">
|
||||
<div className="space-y-1 px-6 pt-6 pb-4">
|
||||
<OGDialogTitle>
|
||||
{localize(dialog === 'add' ? 'com_ui_channels_add' : connectionTitle)}
|
||||
</OGDialogTitle>
|
||||
</div>
|
||||
<div
|
||||
className="flex min-h-0 flex-1 flex-col"
|
||||
onKeyDown={(event) => {
|
||||
// The builder owns a form; credentials must never submit that form.
|
||||
if (event.key === 'Enter' && event.target instanceof HTMLInputElement)
|
||||
event.preventDefault();
|
||||
}}
|
||||
>
|
||||
{dialog === 'add' && (
|
||||
<div className="space-y-4 overflow-y-auto px-6 pb-6">
|
||||
<h4 className="text-sm font-medium">{localize('com_ui_channel_link_mode')}</h4>
|
||||
{create.isError && (
|
||||
<p role="alert" className="text-sm">
|
||||
{localize('com_ui_channels_action_error')}
|
||||
</p>
|
||||
)}
|
||||
<div
|
||||
role="group"
|
||||
aria-label={localize('com_ui_channel_link_mode')}
|
||||
className="flex flex-wrap gap-2"
|
||||
>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline-toggle"
|
||||
disabled={create.isLoading}
|
||||
aria-pressed={credentialMode === 'per_user'}
|
||||
onClick={() => setCredentialMode('per_user')}
|
||||
>
|
||||
{localize('com_ui_channel_link_per_user')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline-toggle"
|
||||
disabled={create.isLoading}
|
||||
aria-pressed={credentialMode === 'shared'}
|
||||
onClick={() => setCredentialMode('shared')}
|
||||
>
|
||||
{localize('com_ui_channel_link_shared')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-text-secondary text-sm">
|
||||
{localize(
|
||||
credentialMode === 'shared'
|
||||
? 'com_ui_channels_owner_help'
|
||||
: 'com_ui_channels_per_user_help',
|
||||
)}
|
||||
</p>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={create.isLoading}
|
||||
onClick={() => setDialog(null)}
|
||||
>
|
||||
{localize('com_ui_cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={create.isLoading || !channels.isSuccess}
|
||||
onClick={() => create.mutate()}
|
||||
>
|
||||
{localize('com_ui_continue')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{selected && selected.createdBy === userId && agentId && (
|
||||
<Channel
|
||||
key={selected.channelId}
|
||||
agentId={agentId}
|
||||
channel={selected}
|
||||
userId={userId}
|
||||
tenantId={tenantId}
|
||||
enabled={channels.isSuccess && !channels.isFetching}
|
||||
onClose={() =>
|
||||
setDialog((current) => (current === selected.channelId ? null : current))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{dialog !== 'add' && !selected && (
|
||||
<p role="status">{localize('com_ui_channels_loading')}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</OGDialogContent>
|
||||
</OGDialog>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,729 @@
|
|||
import React from 'react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { act, cleanup, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import { dataService, request, QueryKeys, MutationKeys } from 'librechat-data-provider';
|
||||
import type { AgentChannel, SlackChannelManifest } from 'librechat-data-provider';
|
||||
import Channels from '../Channels';
|
||||
|
||||
jest.mock('~/hooks', () => ({ useLocalize: () => (key: string) => key }));
|
||||
jest.mock('librechat-data-provider', () => ({
|
||||
...jest.requireActual('librechat-data-provider'),
|
||||
dataService: {
|
||||
...jest.requireActual('librechat-data-provider').dataService,
|
||||
listAgentChannels: jest.fn(),
|
||||
createAgentChannel: jest.fn(),
|
||||
getAgentChannelManifest: jest.fn(),
|
||||
activateAgentChannel: jest.fn(),
|
||||
disableAgentChannel: jest.fn(),
|
||||
deleteAgentChannel: jest.fn(),
|
||||
changeAgentChannelMode: jest.fn(),
|
||||
},
|
||||
}));
|
||||
const pending: AgentChannel = {
|
||||
channelId: 'channel-1',
|
||||
agentId: 'agent-1',
|
||||
createdBy: 'admin-1',
|
||||
type: 'slack',
|
||||
status: 'pending_install',
|
||||
credentialMode: 'per_user',
|
||||
};
|
||||
const manifest: SlackChannelManifest = {
|
||||
display_information: { name: 'Test agent' },
|
||||
features: { bot_user: { display_name: 'Test agent' } },
|
||||
oauth_config: { scopes: { bot: ['app_mentions:read'] } },
|
||||
settings: {
|
||||
socket_mode_enabled: true,
|
||||
event_subscriptions: { bot_events: ['app_mention'] },
|
||||
org_deploy_enabled: false,
|
||||
token_rotation_enabled: false,
|
||||
},
|
||||
};
|
||||
function renderChannels({
|
||||
agentId = 'agent-1',
|
||||
wrapInForm = false,
|
||||
userId = 'admin-1',
|
||||
tenantId = 'tenant-a',
|
||||
} = {}) {
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
||||
logger: { log: () => {}, warn: () => {}, error: () => {} },
|
||||
});
|
||||
const submit = jest.fn((event) => event.preventDefault());
|
||||
const component = <Channels agentId={agentId || undefined} userId={userId} tenantId={tenantId} />;
|
||||
const view = render(
|
||||
<QueryClientProvider client={client}>
|
||||
{wrapInForm ? (
|
||||
<form onSubmit={submit}>
|
||||
{component}
|
||||
<button type="submit">{'Save agent'}</button>
|
||||
</form>
|
||||
) : (
|
||||
component
|
||||
)}
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
return { ...view, client, submit };
|
||||
}
|
||||
async function openConnection(
|
||||
user: ReturnType<typeof userEvent.setup>,
|
||||
status: AgentChannel['status'] = 'pending_install',
|
||||
) {
|
||||
await user.click(
|
||||
await screen.findByRole('button', {
|
||||
name: status === 'pending_install' ? 'com_ui_channels_setup' : 'com_ui_channels_manage',
|
||||
}),
|
||||
);
|
||||
}
|
||||
async function openAdd(user: ReturnType<typeof userEvent.setup>) {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_add' })).toBeEnabled(),
|
||||
);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_add' }));
|
||||
}
|
||||
beforeEach(() => {
|
||||
jest.mocked(dataService.listAgentChannels).mockReset().mockResolvedValue([]);
|
||||
jest.mocked(dataService.createAgentChannel).mockReset().mockResolvedValue(pending);
|
||||
jest.mocked(dataService.getAgentChannelManifest).mockReset().mockResolvedValue(manifest);
|
||||
jest
|
||||
.mocked(dataService.activateAgentChannel)
|
||||
.mockReset()
|
||||
.mockResolvedValue({ ...pending, status: 'active' });
|
||||
jest
|
||||
.mocked(dataService.disableAgentChannel)
|
||||
.mockReset()
|
||||
.mockResolvedValue({ ...pending, status: 'disabled' });
|
||||
jest.mocked(dataService.deleteAgentChannel).mockReset().mockResolvedValue(undefined);
|
||||
jest
|
||||
.mocked(dataService.changeAgentChannelMode)
|
||||
.mockReset()
|
||||
.mockResolvedValue({ ...pending, status: 'disabled', credentialMode: 'shared' });
|
||||
});
|
||||
test('unsaved Agent shows a disabled row without fetching', () => {
|
||||
renderChannels({ agentId: '' });
|
||||
expect(screen.getByRole('heading', { name: 'com_ui_channels_title' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_add' })).toBeDisabled();
|
||||
expect(screen.getByText('com_ui_channels_save_first')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument();
|
||||
expect(dataService.listAgentChannels).not.toHaveBeenCalled();
|
||||
});
|
||||
test('Add opens without creating; Escape returns focus and resets mode', async () => {
|
||||
const user = userEvent.setup();
|
||||
renderChannels();
|
||||
expect(screen.queryByText('com_ui_channels_shared_notice')).not.toBeInTheDocument();
|
||||
await openAdd(user);
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channel_link_per_user' })).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channel_link_shared' }));
|
||||
expect(dataService.createAgentChannel).not.toHaveBeenCalled();
|
||||
await user.keyboard('{Escape}');
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_add' })).toHaveFocus();
|
||||
await openAdd(user);
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channel_link_per_user' })).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
});
|
||||
test.each(['per_user', 'shared'] as const)(
|
||||
'Continue creates %s then activation keeps credentials write-only',
|
||||
async (mode) => {
|
||||
const user = userEvent.setup();
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValueOnce([])
|
||||
.mockResolvedValue([pending]);
|
||||
const { client, submit } = renderChannels({ wrapInForm: true });
|
||||
await openAdd(user);
|
||||
if (mode === 'shared')
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channel_link_shared' }));
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_continue' }));
|
||||
await waitFor(() =>
|
||||
expect(dataService.createAgentChannel).toHaveBeenCalledWith('agent-1', mode),
|
||||
);
|
||||
expect(
|
||||
(await screen.findByText('com_ui_channels_manifest', { selector: 'summary' })).closest(
|
||||
'details',
|
||||
),
|
||||
).toHaveAttribute('open');
|
||||
expect(screen.getByLabelText('com_ui_channels_manifest')).toHaveValue(
|
||||
JSON.stringify(manifest, null, 2),
|
||||
);
|
||||
expect(screen.getByLabelText('com_ui_channels_manifest')).toHaveAttribute('readonly');
|
||||
expect(
|
||||
screen.queryByRole('link', { name: 'com_ui_channels_download_manifest' }),
|
||||
).not.toBeInTheDocument();
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123{Enter}');
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveAttribute('type', 'password');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.type(screen.getByLabelText(/com_ui_channels_signing_secret/), 'test-secret');
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue([{ ...pending, status: 'active' }]);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await waitFor(() =>
|
||||
expect(dataService.activateAgentChannel).toHaveBeenCalledWith('agent-1', 'channel-1', {
|
||||
slack: { appId: 'A123', botToken: 'test-token', signingSecret: 'test-secret' },
|
||||
}),
|
||||
);
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
expect(submit).not.toHaveBeenCalled();
|
||||
expect(
|
||||
JSON.stringify(
|
||||
client
|
||||
.getMutationCache()
|
||||
.getAll()
|
||||
.map((x) => x.state.variables),
|
||||
),
|
||||
).not.toContain('test-token');
|
||||
},
|
||||
);
|
||||
test('pending setup is resumable and closing clears secrets', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
renderChannels();
|
||||
await screen.findByText('com_ui_channels_pending');
|
||||
expect(screen.queryByLabelText('com_ui_channels_bot_token')).not.toBeInTheDocument();
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.keyboard('{Escape}');
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
await openConnection(user);
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('');
|
||||
expect(screen.getByLabelText(/com_ui_channels_signing_secret/)).toHaveValue('');
|
||||
expect(dataService.deleteAgentChannel).not.toHaveBeenCalled();
|
||||
});
|
||||
test('manifest is a read-only definition without editing or download controls', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
renderChannels();
|
||||
await openConnection(user);
|
||||
const field = await screen.findByLabelText('com_ui_channels_manifest');
|
||||
expect(field).toHaveAttribute('readonly');
|
||||
await user.type(field, 'changed');
|
||||
expect(field).toHaveValue(JSON.stringify(manifest, null, 2));
|
||||
expect(
|
||||
screen.queryByRole('link', { name: 'com_ui_channels_download_manifest' }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'com_ui_channels_manifest_reset' }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(dataService.activateAgentChannel).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('active credentials require disabling before replacement', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([{ ...pending, status: 'active' }]);
|
||||
renderChannels();
|
||||
await openConnection(user, 'active');
|
||||
expect(screen.queryByText('com_ui_channels_replace_notice')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'com_ui_channels_setup' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByLabelText('com_ui_channels_bot_token')).not.toBeInTheDocument();
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue([{ ...pending, status: 'disabled', revision: 'r1' }]);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_disable' }));
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
await openConnection(user, 'disabled');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_setup' }));
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('');
|
||||
});
|
||||
test.each(['per_user', 'shared'] as const)(
|
||||
'Manage shows the %s connection indicator, metadata and expanded manifest',
|
||||
async (credentialMode) => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([
|
||||
{
|
||||
...pending,
|
||||
status: 'active',
|
||||
credentialMode,
|
||||
slack: { teamId: 'T123', appId: 'A123', botUserId: 'B123' },
|
||||
},
|
||||
]);
|
||||
renderChannels();
|
||||
await openConnection(user, 'active');
|
||||
const dialog = screen.getByRole('dialog');
|
||||
const type = within(dialog).getByText('com_ui_channels_connection_type').closest('div')!;
|
||||
expect(
|
||||
within(type).getByText(
|
||||
credentialMode === 'shared' ? 'com_ui_channel_link_shared' : 'com_ui_channel_link_per_user',
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(within(dialog).getByText('channel-1')).toHaveClass('font-mono', 'text-end');
|
||||
expect(within(dialog).getByText('channel-1').closest('div')).toHaveClass('justify-between');
|
||||
expect(
|
||||
within(dialog).queryByText('com_ui_channels_manifest_description'),
|
||||
).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByText('com_ui_channels_gateway_required')).not.toBeInTheDocument();
|
||||
expect(within(dialog).getByText('T123')).toHaveClass('font-mono');
|
||||
expect(within(dialog).getByText('A123')).toBeInTheDocument();
|
||||
expect(await within(dialog).findByLabelText('com_ui_channels_manifest')).toHaveValue(
|
||||
JSON.stringify(manifest, null, 2),
|
||||
);
|
||||
expect(
|
||||
within(dialog)
|
||||
.getByText('com_ui_channels_manifest', { selector: 'summary' })
|
||||
.closest('details'),
|
||||
).toHaveAttribute('open');
|
||||
expect(dataService.getAgentChannelManifest).toHaveBeenCalledWith('agent-1', 'channel-1');
|
||||
expect(within(dialog).queryByLabelText('com_ui_channels_bot_token')).not.toBeInTheDocument();
|
||||
const remove = within(dialog).getByRole('button', { name: 'com_ui_delete' });
|
||||
expect(remove).toHaveClass('bg-surface-destructive');
|
||||
expect(remove.parentElement).toHaveClass('sm:justify-between');
|
||||
expect(remove.parentElement!.firstElementChild).toBe(remove);
|
||||
expect(within(dialog).queryByRole('button', { name: 'com_ui_done' })).not.toBeInTheDocument();
|
||||
await user.keyboard('{Escape}');
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
expect(dataService.disableAgentChannel).not.toHaveBeenCalled();
|
||||
expect(dataService.deleteAgentChannel).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
test('manifest failure in Manage can retry without hiding connection controls', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([{ ...pending, status: 'active' }]);
|
||||
jest
|
||||
.mocked(dataService.getAgentChannelManifest)
|
||||
.mockRejectedValueOnce(new Error('private-error'))
|
||||
.mockResolvedValue(manifest);
|
||||
renderChannels();
|
||||
await openConnection(user, 'active');
|
||||
await screen.findByText('com_ui_channels_manifest_error');
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_disable' })).toBeEnabled();
|
||||
expect(screen.queryByText('private-error')).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_retry' }));
|
||||
expect(await screen.findByLabelText('com_ui_channels_manifest')).toHaveValue(
|
||||
JSON.stringify(manifest, null, 2),
|
||||
);
|
||||
});
|
||||
test('mode/delete confirmations replace setup and discard secrets; mode requires revision', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue([{ ...pending, status: 'disabled', revision: 'r1' }]);
|
||||
renderChannels();
|
||||
await openConnection(user, 'disabled');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_setup' }));
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channel_link_change_mode' }));
|
||||
expect(screen.queryByLabelText('com_ui_channels_bot_token')).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_delete' }));
|
||||
expect(
|
||||
screen.queryByRole('group', { name: 'com_ui_channel_link_mode_confirm' }),
|
||||
).not.toBeInTheDocument();
|
||||
await user.click(
|
||||
within(screen.getByRole('group', { name: 'com_ui_channels_delete_confirm' })).getByRole(
|
||||
'button',
|
||||
{ name: 'com_ui_cancel' },
|
||||
),
|
||||
);
|
||||
expect(dataService.deleteAgentChannel).not.toHaveBeenCalled();
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_setup' }));
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channel_link_change_mode' }));
|
||||
expect(dataService.changeAgentChannelMode).not.toHaveBeenCalled();
|
||||
await user.click(
|
||||
within(screen.getByRole('group', { name: 'com_ui_channel_link_mode_confirm' })).getByRole(
|
||||
'button',
|
||||
{ name: 'com_ui_channel_link_switch_shared' },
|
||||
),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(dataService.changeAgentChannelMode).toHaveBeenCalledWith(
|
||||
'agent-1',
|
||||
'channel-1',
|
||||
'shared',
|
||||
'r1',
|
||||
),
|
||||
);
|
||||
});
|
||||
test.each(['active', 'pending_install', 'disabled'] as const)(
|
||||
'legacy %s connection has no mode control',
|
||||
async (status) => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([{ ...pending, status }]);
|
||||
renderChannels();
|
||||
await openConnection(user, status);
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'com_ui_channel_link_change_mode' }),
|
||||
).not.toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
test('list/manifest/activation errors can retry without exposing backend details; signing secret optional', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockRejectedValueOnce(new Error('private-error'))
|
||||
.mockResolvedValue([pending]);
|
||||
jest
|
||||
.mocked(dataService.getAgentChannelManifest)
|
||||
.mockRejectedValueOnce(new Error('private-error'))
|
||||
.mockResolvedValue(manifest);
|
||||
jest
|
||||
.mocked(dataService.activateAgentChannel)
|
||||
.mockRejectedValueOnce(new Error('private-error'))
|
||||
.mockResolvedValue({ ...pending, status: 'active' });
|
||||
renderChannels();
|
||||
await user.click(await screen.findByRole('button', { name: 'com_ui_channels_retry' }));
|
||||
await openConnection(user);
|
||||
await user.click(await screen.findByRole('button', { name: 'com_ui_channels_retry' }));
|
||||
await screen.findByText('com_ui_channels_manifest', { selector: 'summary' });
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await screen.findByText('com_ui_channels_action_error');
|
||||
expect(screen.getByText('com_ui_channels_activation_retry')).toBeInTheDocument();
|
||||
expect(screen.getByText('com_ui_channels_signing_secret_optional')).toBeInTheDocument();
|
||||
expect(screen.queryByText('private-error')).not.toBeInTheDocument();
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await waitFor(() =>
|
||||
expect(dataService.activateAgentChannel).toHaveBeenLastCalledWith('agent-1', 'channel-1', {
|
||||
slack: { appId: 'A123', botToken: 'test-token' },
|
||||
}),
|
||||
);
|
||||
});
|
||||
test('creation failure stays retryable inside Add', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.createAgentChannel).mockRejectedValueOnce(new Error('private-error'));
|
||||
renderChannels();
|
||||
await openAdd(user);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_continue' }));
|
||||
await screen.findByText('com_ui_channels_action_error');
|
||||
expect(screen.getByRole('button', { name: 'com_ui_continue' })).toBeEnabled();
|
||||
expect(screen.queryByText('private-error')).not.toBeInTheDocument();
|
||||
});
|
||||
describe('asynchronous deletion refresh', () => {
|
||||
beforeEach(() => jest.useFakeTimers());
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
jest.useRealTimers();
|
||||
});
|
||||
const advance = (ms: number) =>
|
||||
act(async () => {
|
||||
await jest.advanceTimersByTimeAsync(ms);
|
||||
});
|
||||
test('requires confirmation, disables draining row and stops polling after deletion', async () => {
|
||||
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValueOnce([pending])
|
||||
.mockResolvedValueOnce([{ ...pending, status: 'deleting' }])
|
||||
.mockResolvedValue([]);
|
||||
renderChannels();
|
||||
await openConnection(user);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_delete' }));
|
||||
expect(dataService.deleteAgentChannel).not.toHaveBeenCalled();
|
||||
await user.click(
|
||||
within(screen.getByRole('group', { name: 'com_ui_channels_delete_confirm' })).getByRole(
|
||||
'button',
|
||||
{ name: 'com_ui_delete' },
|
||||
),
|
||||
);
|
||||
await screen.findByText('com_ui_channels_deleting');
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_manage' })).toBeDisabled();
|
||||
await advance(2000);
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByText('com_ui_channels_deleting')).not.toBeInTheDocument(),
|
||||
);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(3);
|
||||
await advance(10000);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
test.each(['active', 'pending_install', 'disabled', 'empty'] as const)(
|
||||
'does not poll idle %s list',
|
||||
async (status) => {
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue(status === 'empty' ? [] : [{ ...pending, status }]);
|
||||
renderChannels();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_add' })).toBeEnabled(),
|
||||
);
|
||||
await advance(10000);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
);
|
||||
test('mixed list stops polling when deleting row disappears', async () => {
|
||||
const active: AgentChannel = { ...pending, channelId: 'channel-active', status: 'active' };
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValueOnce([active, { ...pending, status: 'deleting' }])
|
||||
.mockResolvedValue([active]);
|
||||
renderChannels();
|
||||
await screen.findByText('com_ui_channels_deleting');
|
||||
await advance(2000);
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByText('com_ui_channels_deleting')).not.toBeInTheDocument(),
|
||||
);
|
||||
expect(screen.getByText('com_ui_channels_active')).toBeInTheDocument();
|
||||
await advance(10000);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
test('refetch error stops polling until successful manual retry', async () => {
|
||||
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValueOnce([{ ...pending, status: 'deleting' }])
|
||||
.mockRejectedValueOnce(new Error('private-error'))
|
||||
.mockResolvedValueOnce([{ ...pending, status: 'deleting' }])
|
||||
.mockResolvedValue([]);
|
||||
renderChannels();
|
||||
await screen.findByText('com_ui_channels_deleting');
|
||||
await advance(2000);
|
||||
await screen.findByText('com_ui_channels_list_error');
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_manage' })).toBeDisabled();
|
||||
await advance(10000);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(2);
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_retry' }));
|
||||
await waitFor(() => expect(dataService.listAgentChannels).toHaveBeenCalledTimes(3));
|
||||
await advance(2000);
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByText('com_ui_channels_deleting')).not.toBeInTheDocument(),
|
||||
);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
test('unmount stops polling', async () => {
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue([{ ...pending, status: 'deleting' }]);
|
||||
const { unmount } = renderChannels();
|
||||
await screen.findByText('com_ui_channels_deleting');
|
||||
unmount();
|
||||
await advance(10000);
|
||||
expect(dataService.listAgentChannels).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
test('does not read or create channels before the owner is available', () => {
|
||||
renderChannels({ userId: '' });
|
||||
expect(dataService.listAgentChannels).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_add' })).toBeDisabled();
|
||||
});
|
||||
|
||||
test.each(['pending_install', 'active', 'disabled'] as const)(
|
||||
'foreign %s connections are read-only without owner-only requests',
|
||||
async (status) => {
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue([{ ...pending, status, createdBy: 'another-owner' }]);
|
||||
renderChannels();
|
||||
expect(await screen.findByRole('button', { name: 'com_ui_channels_read_only' })).toBeDisabled();
|
||||
expect(dataService.getAgentChannelManifest).not.toHaveBeenCalled();
|
||||
expect(dataService.activateAgentChannel).not.toHaveBeenCalled();
|
||||
expect(dataService.disableAgentChannel).not.toHaveBeenCalled();
|
||||
expect(dataService.deleteAgentChannel).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
test('requires the signing secret advertised by a webhook manifest before activation', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
jest.mocked(dataService.getAgentChannelManifest).mockResolvedValue({
|
||||
...manifest,
|
||||
settings: { ...manifest.settings, socket_mode_enabled: false },
|
||||
});
|
||||
renderChannels();
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
const activate = screen.getByRole('button', { name: 'com_ui_channels_activate' });
|
||||
expect(activate).toBeDisabled();
|
||||
const signing = screen.getByLabelText(/com_ui_channels_signing_secret/);
|
||||
expect(signing).toBeRequired();
|
||||
expect(screen.getByText('com_ui_channels_signing_secret_required')).toBeInTheDocument();
|
||||
expect(screen.queryByText('com_ui_channels_signing_secret_optional')).not.toBeInTheDocument();
|
||||
await user.type(signing, 'test-secret');
|
||||
expect(activate).toBeEnabled();
|
||||
await user.click(activate);
|
||||
expect(dataService.activateAgentChannel).toHaveBeenCalledWith('agent-1', 'channel-1', {
|
||||
slack: { appId: 'A123', botToken: 'test-token', signingSecret: 'test-secret' },
|
||||
});
|
||||
});
|
||||
|
||||
test('does not send credentials when the installation manifest is unavailable', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
jest.mocked(dataService.getAgentChannelManifest).mockRejectedValue(new Error('offline'));
|
||||
renderChannels();
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.type(screen.getByLabelText(/com_ui_channels_signing_secret/), 'test-secret');
|
||||
expect(screen.getByRole('button', { name: 'com_ui_channels_activate' })).toBeDisabled();
|
||||
expect(dataService.activateAgentChannel).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('a late operation for A cannot close B or discard B credentials', async () => {
|
||||
const user = userEvent.setup();
|
||||
const second = { ...pending, channelId: 'channel-2' };
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending, second]);
|
||||
let finish!: (channel: AgentChannel) => void;
|
||||
jest.mocked(dataService.activateAgentChannel).mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
finish = resolve;
|
||||
}),
|
||||
);
|
||||
renderChannels();
|
||||
await user.click((await screen.findAllByRole('button', { name: 'com_ui_channels_setup' }))[0]);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'A-token');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await user.keyboard('{Escape}');
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
await user.click(screen.getAllByRole('button', { name: 'com_ui_channels_setup' })[1]);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'B-token');
|
||||
await act(async () => {
|
||||
finish({ ...pending, status: 'active' });
|
||||
});
|
||||
await waitFor(() =>
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('B-token'),
|
||||
);
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
||||
expect(dataService.activateAgentChannel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('the actual activation adapter prevents credential-bearing failures reaching the mutation cache', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
jest
|
||||
.mocked(dataService.activateAgentChannel)
|
||||
.mockImplementation(
|
||||
jest.requireActual('librechat-data-provider').dataService.activateAgentChannel,
|
||||
);
|
||||
const unsafe = Object.assign(new Error('test-token'), {
|
||||
config: { data: JSON.stringify({ botToken: 'test-token', signingSecret: 'test-secret' }) },
|
||||
request: { authorization: 'test-token' },
|
||||
});
|
||||
const patch = jest.spyOn(request, 'patch').mockRejectedValueOnce(unsafe);
|
||||
const { client } = renderChannels();
|
||||
try {
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'test-token');
|
||||
await user.type(screen.getByLabelText(/com_ui_channels_signing_secret/), 'test-secret');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await screen.findByText('com_ui_channels_action_error');
|
||||
await user.keyboard('{Escape}');
|
||||
const errors = client
|
||||
.getMutationCache()
|
||||
.getAll()
|
||||
.map((mutation) => mutation.state.error);
|
||||
expect(errors).toHaveLength(1);
|
||||
expect(errors[0]).toEqual(new Error('Channel activation failed'));
|
||||
expect(errors[0]).not.toBe(unsafe);
|
||||
const cache = JSON.stringify(
|
||||
client
|
||||
.getMutationCache()
|
||||
.getAll()
|
||||
.map((mutation) => mutation.state),
|
||||
);
|
||||
expect(cache).not.toContain('test-token');
|
||||
expect(cache).not.toContain('test-secret');
|
||||
} finally {
|
||||
patch.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test('switching owner isolates channel caches and discards the old credential form', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
const mounted = renderChannels();
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'Owner-A-secret');
|
||||
jest
|
||||
.mocked(dataService.listAgentChannels)
|
||||
.mockResolvedValue([{ ...pending, channelId: 'channel-2', createdBy: 'admin-2' }]);
|
||||
mounted.rerender(
|
||||
<QueryClientProvider client={mounted.client}>
|
||||
<Channels agentId="agent-1" userId="admin-2" tenantId="tenant-b" />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
||||
await openConnection(user);
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('');
|
||||
expect(dataService.getAgentChannelManifest).toHaveBeenLastCalledWith('agent-1', 'channel-2');
|
||||
expect(
|
||||
mounted.client.getQueryData([QueryKeys.agentChannels, 'admin-1', 'tenant-a', 'agent-1']),
|
||||
).not.toEqual(
|
||||
mounted.client.getQueryData([QueryKeys.agentChannels, 'admin-2', 'tenant-b', 'agent-1']),
|
||||
);
|
||||
});
|
||||
|
||||
test.each(['success', 'failure', 'pending-close'] as const)(
|
||||
'cached activation callbacks cannot reuse credentials after %s',
|
||||
async (outcome) => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
let settle!: (value: AgentChannel) => void;
|
||||
if (outcome === 'failure')
|
||||
jest
|
||||
.mocked(dataService.activateAgentChannel)
|
||||
.mockRejectedValueOnce(new Error('safe failure'));
|
||||
if (outcome === 'pending-close')
|
||||
jest.mocked(dataService.activateAgentChannel).mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
settle = resolve;
|
||||
}),
|
||||
);
|
||||
const { client } = renderChannels();
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'one-use-token');
|
||||
await user.type(screen.getByLabelText(/com_ui_channels_signing_secret/), 'one-use-secret');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await waitFor(() => expect(dataService.activateAgentChannel).toHaveBeenCalledTimes(1));
|
||||
const cached = client.getMutationCache().find<AgentChannel | void, Error, 'activate'>({
|
||||
mutationKey: [MutationKeys.agentChannels, 'admin-1', 'tenant-a', 'agent-1', 'channel-1'],
|
||||
exact: true,
|
||||
});
|
||||
expect(cached?.options.mutationFn).toEqual(expect.any(Function));
|
||||
if (outcome === 'failure') {
|
||||
await screen.findByText('com_ui_channels_action_error');
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('');
|
||||
expect(screen.getByLabelText(/com_ui_channels_signing_secret/)).toHaveValue('');
|
||||
} else if (outcome === 'pending-close') {
|
||||
await user.keyboard('{Escape}');
|
||||
} else {
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
}
|
||||
await act(async () => {
|
||||
await expect(cached?.options.mutationFn?.('activate')).rejects.toThrow(/unavailable/);
|
||||
});
|
||||
expect(dataService.activateAgentChannel).toHaveBeenCalledTimes(1);
|
||||
expect(dataService.activateAgentChannel).toHaveBeenCalledWith('agent-1', 'channel-1', {
|
||||
slack: { appId: 'A123', botToken: 'one-use-token', signingSecret: 'one-use-secret' },
|
||||
});
|
||||
if (outcome === 'pending-close')
|
||||
await act(async () => settle({ ...pending, status: 'active' }));
|
||||
},
|
||||
);
|
||||
|
||||
test('a completed closed operation cannot close a new dialog for the same channel', async () => {
|
||||
const user = userEvent.setup();
|
||||
jest.mocked(dataService.listAgentChannels).mockResolvedValue([pending]);
|
||||
let finish!: (value: AgentChannel) => void;
|
||||
jest.mocked(dataService.activateAgentChannel).mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
finish = resolve;
|
||||
}),
|
||||
);
|
||||
renderChannels();
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_app_id'), 'A123');
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'old-operation-token');
|
||||
await user.click(screen.getByRole('button', { name: 'com_ui_channels_activate' }));
|
||||
await waitFor(() => expect(dataService.activateAgentChannel).toHaveBeenCalledTimes(1));
|
||||
await user.keyboard('{Escape}');
|
||||
await openConnection(user);
|
||||
await user.type(screen.getByLabelText('com_ui_channels_bot_token'), 'new-dialog-token');
|
||||
await act(async () => finish({ ...pending, status: 'active' }));
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText('com_ui_channels_bot_token')).toHaveValue('new-dialog-token');
|
||||
expect(dataService.activateAgentChannel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
|
@ -22,6 +22,50 @@
|
|||
"com_ui_response_review_oauth_unavailable": "This sign-in request is unavailable. Return to the app that started it.",
|
||||
"com_ui_response_review_oauth_expired": "This sign-in request has expired. Return to the app that started it.",
|
||||
"com_ui_response_review_return": "After authorizing, you can return to the app that started this request.",
|
||||
"com_ui_channel_link_mode": "Account access",
|
||||
"com_ui_channel_link_shared": "Channel owner only",
|
||||
"com_ui_channel_link_per_user": "Per-user accounts",
|
||||
"com_ui_channel_link_per_user_notice": "Each Slack user must link and confirm their own account. Requests use that user's permissions and connected accounts. Linking does not grant offline OAuth access.",
|
||||
"com_ui_channel_link_change_mode": "Change identity mode",
|
||||
"com_ui_channel_link_mode_confirm": "Change identity mode? Existing links and pending requests will no longer authorize execution. Activate the channel again after the change.",
|
||||
"com_ui_channel_link_switch_per_user": "Switch to per-user accounts",
|
||||
"com_ui_channel_link_switch_shared": "Switch to channel owner only",
|
||||
"com_ui_channels_title": "Channels",
|
||||
"com_ui_channels_slack": "Slack",
|
||||
"com_ui_channels_shared_notice": "Owner-only mode: the Slack sender must link and confirm the channel creator's account. Other Slack users cannot inherit that account's permissions by joining a thread. Use per-user mode for multiple users.",
|
||||
"com_ui_channels_pending": "Pending installation",
|
||||
"com_ui_channels_active": "Active",
|
||||
"com_ui_channels_disabled": "Disabled",
|
||||
"com_ui_channels_deleting": "Deleting",
|
||||
"com_ui_channels_action_error": "Couldn't update this channel. Check the configuration and try again.",
|
||||
"com_ui_channels_setup": "Continue setup",
|
||||
"com_ui_channels_manage": "Manage connection",
|
||||
"com_ui_channels_setup_title": "Connect to Slack",
|
||||
"com_ui_channels_install_step": "1. Install the Slack app",
|
||||
"com_ui_channels_credentials_step": "Add Credentials",
|
||||
"com_ui_channels_description": "Connect this Agent to messaging apps through a compatible gateway.",
|
||||
"com_ui_channels_save_first": "Save this Agent to configure channels.",
|
||||
"com_ui_channels_per_user_help": "Each person uses their own account and permissions.",
|
||||
"com_ui_channels_owner_help": "Only you can use this connection, with your account and permissions.",
|
||||
"com_ui_channels_connection_type": "Connection type:",
|
||||
"com_ui_channels_connection_id_label": "Connection ID",
|
||||
"com_ui_channels_workspace_label": "Workspace",
|
||||
"com_ui_channels_disable": "Disable",
|
||||
"com_ui_channels_delete_confirm": "Delete this channel and its stored credentials? The Slack app is not uninstalled.",
|
||||
"com_ui_channels_instructions": "Create a Slack app from this manifest, install it in your workspace, then enter its app ID and bot token. Activation validates the credentials with Slack.",
|
||||
"com_ui_channels_loading": "Loading channels…",
|
||||
"com_ui_channels_manifest_error": "Couldn't load the app manifest.",
|
||||
"com_ui_channels_retry": "Try again",
|
||||
"com_ui_channels_manifest": "Slack app manifest",
|
||||
"com_ui_channels_app_id": "Slack app ID",
|
||||
"com_ui_channels_bot_token": "Bot token",
|
||||
"com_ui_channels_signing_secret": "Signing secret",
|
||||
"com_ui_channels_signing_secret_required": "Signing secret (required)",
|
||||
"com_ui_channels_signing_secret_optional": "Signing secret (optional)",
|
||||
"com_ui_channels_activation_retry": "Enter the credentials again to retry activation.",
|
||||
"com_ui_channels_activate": "Activate channel",
|
||||
"com_ui_channels_list_error": "Couldn't load channels.",
|
||||
"com_ui_channels_add": "Add Slack channel",
|
||||
"com_ui_pr_account_checking": "Checking connection",
|
||||
"com_ui_pr_account_connect": "Connect",
|
||||
"com_ui_pr_account_connect_aria": "Connect {{0}}",
|
||||
|
|
@ -3819,5 +3863,6 @@
|
|||
"com_ui_code_setup_approve": "Approve setup",
|
||||
"com_ui_code_setup_deny": "Deny setup",
|
||||
"com_ui_code_setup_saving": "Saving your decision…",
|
||||
"com_ui_terms_accept_failed": "Could not accept the terms. Please try again."
|
||||
"com_ui_terms_accept_failed": "Could not accept the terms. Please try again.",
|
||||
"com_ui_channels_read_only": "Managed by another account"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ export const responseReview = (responseId: string): string =>
|
|||
export const responseCancel = (responseId: string): string =>
|
||||
`${BASE_URL}/api/agents/responses/${encodeURIComponent(responseId)}/cancel`;
|
||||
|
||||
export const agentChannels = (agentId: string, channelId?: string): string =>
|
||||
`${BASE_URL}/api/agents/${encodeURIComponent(agentId)}/channels${
|
||||
channelId ? `/${encodeURIComponent(channelId)}` : ''
|
||||
}`;
|
||||
|
||||
// Testing this buildQuery function
|
||||
const buildQuery = (params: Record<string, unknown>): string => {
|
||||
const query = Object.entries(params)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,13 @@ import type {
|
|||
TTraceRecordParams,
|
||||
TTraceRecordDetail,
|
||||
} from './types/traces';
|
||||
import type {
|
||||
ChannelIdentityClient,
|
||||
ChannelIdentityResult,
|
||||
ChannelLinkView,
|
||||
} from './types/channelIdentity';
|
||||
import type { TInsightsAccessResponse, TInsightsParams, TInsightsResponse } from './types/insights';
|
||||
import type { AgentChannel, ActivateAgentChannel, SlackChannelManifest } from './types/channels';
|
||||
import type { ScheduleMCPConsentView, ConfirmScheduleMCPConsent } from './types/scheduleConsent';
|
||||
import type { CodeSetupAttempt, CodeSetupApprovalRequest } from './codeSetup';
|
||||
import type { TFileConfig } from './file-config';
|
||||
|
|
@ -42,6 +48,10 @@ import request from './request';
|
|||
import * as s from './schemas';
|
||||
import * as r from './roles';
|
||||
|
||||
export function listAgentChannels(agentId: string): Promise<AgentChannel[]> {
|
||||
return request.get(endpoints.agentChannels(agentId));
|
||||
}
|
||||
|
||||
export function getResponseReview(responseId: string): Promise<ResponseReviewView> {
|
||||
return request.get(endpoints.responseReview(responseId));
|
||||
}
|
||||
|
|
@ -69,6 +79,65 @@ export async function submitResponseReviewDecision(
|
|||
return receipt.data;
|
||||
}
|
||||
|
||||
export function createAgentChannel(
|
||||
agentId: string,
|
||||
credentialMode: AgentChannel['credentialMode'] = 'shared',
|
||||
): Promise<AgentChannel> {
|
||||
return request.post(endpoints.agentChannels(agentId), { type: 'slack', credentialMode });
|
||||
}
|
||||
|
||||
export function getAgentChannelManifest(
|
||||
agentId: string,
|
||||
channelId: string,
|
||||
): Promise<SlackChannelManifest> {
|
||||
return request.get(`${endpoints.agentChannels(agentId, channelId)}/manifest`);
|
||||
}
|
||||
|
||||
export function activateAgentChannel(
|
||||
agentId: string,
|
||||
channelId: string,
|
||||
input: ActivateAgentChannel,
|
||||
): Promise<AgentChannel> {
|
||||
return request.patch(endpoints.agentChannels(agentId, channelId), input).catch(() => {
|
||||
// Axios failures carry serialized credentials in config/request; never retain them in query state.
|
||||
throw new Error('Channel activation failed');
|
||||
});
|
||||
}
|
||||
|
||||
export function disableAgentChannel(agentId: string, channelId: string): Promise<AgentChannel> {
|
||||
return request.patch(endpoints.agentChannels(agentId, channelId), { status: 'disabled' });
|
||||
}
|
||||
|
||||
export function changeAgentChannelMode(
|
||||
agentId: string,
|
||||
channelId: string,
|
||||
credentialMode: AgentChannel['credentialMode'],
|
||||
revision: string,
|
||||
): Promise<AgentChannel> {
|
||||
return request.patch(endpoints.agentChannels(agentId, channelId), { credentialMode, revision });
|
||||
}
|
||||
|
||||
export function deleteAgentChannel(agentId: string, channelId: string): Promise<void> {
|
||||
return request.delete(endpoints.agentChannels(agentId, channelId));
|
||||
}
|
||||
|
||||
export const channelIdentityClient: ChannelIdentityClient = {
|
||||
preview: (ticket): Promise<ChannelIdentityResult<ChannelLinkView>> =>
|
||||
request.post(`${endpoints.apiBaseUrl()}/api/channels/links/preview`, { ticket }),
|
||||
accept: ({ ticket, expectedRevision }): Promise<ChannelIdentityResult<ChannelLinkView>> =>
|
||||
request.post(`${endpoints.apiBaseUrl()}/api/channels/links/accept`, {
|
||||
ticket,
|
||||
revision: expectedRevision,
|
||||
}),
|
||||
list: (): Promise<ChannelLinkView[]> =>
|
||||
request.get(`${endpoints.apiBaseUrl()}/api/channels/links`),
|
||||
revoke: (linkId, revision): Promise<ChannelIdentityResult<ChannelLinkView>> =>
|
||||
request.deleteWithOptions(
|
||||
`${endpoints.apiBaseUrl()}/api/channels/links/${encodeURIComponent(linkId)}`,
|
||||
{ data: { revision } },
|
||||
),
|
||||
};
|
||||
|
||||
export function getInsights(params: TInsightsParams = {}): Promise<TInsightsResponse> {
|
||||
const query = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,11 @@ export enum QueryKeys {
|
|||
assistant = 'assistant',
|
||||
agents = 'agents',
|
||||
agent = 'agent',
|
||||
agentChannels = 'agentChannels',
|
||||
responseReview = 'responseReview',
|
||||
channelLinkTicket = 'channelLinkTicket',
|
||||
channelLinks = 'channelLinks',
|
||||
agentChannelManifest = 'agentChannelManifest',
|
||||
files = 'files',
|
||||
fileConfig = 'fileConfig',
|
||||
tools = 'tools',
|
||||
|
|
@ -142,6 +146,9 @@ export enum MutationKeys {
|
|||
denyCodeSetup = 'denyCodeSetup',
|
||||
responseReviewDecision = 'responseReviewDecision',
|
||||
responseCancel = 'responseCancel',
|
||||
agentChannels = 'agentChannels',
|
||||
channelLinkTicket = 'channelLinkTicket',
|
||||
channelLinks = 'channelLinks',
|
||||
resetToolApprovalGrants = 'resetToolApprovalGrants',
|
||||
subagentControl = 'subagentControl',
|
||||
cancelBackgroundTasks = 'cancelBackgroundTasks',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue