mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-12-05 21:47:17 +00:00
feat: show approvals and questions above the message box (#2095)
This commit is contained in:
parent
bbe66c5083
commit
fd39e8df41
29 changed files with 785 additions and 104 deletions
|
|
@ -27,6 +27,7 @@ import {
|
|||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { DsIcon } from '@/components/ui/ds-icon';
|
||||
import { generateUniqueId } from '@/lib';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
|
|
@ -228,10 +229,7 @@ export function ApprovalModeSelect({
|
|||
)}
|
||||
>
|
||||
<span className="inline-flex min-h-[1.25rem] min-w-0 items-center gap-1.5 overflow-hidden">
|
||||
<CurrentIcon
|
||||
className="h-3.5 w-3.5 shrink-0 opacity-80"
|
||||
aria-hidden
|
||||
/>
|
||||
<DsIcon icon={CurrentIcon} className="opacity-80" />
|
||||
{!compact && (
|
||||
<span className="min-w-0 truncate !text-ds-text-meta font-semibold">
|
||||
{current.label}
|
||||
|
|
@ -262,20 +260,17 @@ export function ApprovalModeSelect({
|
|||
)}
|
||||
>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden">
|
||||
<CurrentIcon
|
||||
className="h-3.5 w-3.5 shrink-0 opacity-80"
|
||||
aria-hidden
|
||||
/>
|
||||
<DsIcon icon={CurrentIcon} className="opacity-80" />
|
||||
{!compact && (
|
||||
<span className="min-w-0 flex-1 truncate text-left !text-ds-text-meta text-ds-ink-default-default">
|
||||
{current.label}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<ChevronDown
|
||||
className="h-3.5 w-3.5 shrink-0 opacity-80"
|
||||
aria-hidden
|
||||
strokeWidth={2}
|
||||
<DsIcon
|
||||
icon={ChevronDown}
|
||||
recipe="main-compact"
|
||||
className="opacity-80"
|
||||
/>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
|
|
@ -296,10 +291,7 @@ export function ApprovalModeSelect({
|
|||
className="flex items-center justify-between gap-2"
|
||||
>
|
||||
<span className="flex min-w-0 items-start gap-2">
|
||||
<OptionIcon
|
||||
className="mt-0.5 h-4 w-4 shrink-0 opacity-80"
|
||||
aria-hidden
|
||||
/>
|
||||
<DsIcon icon={OptionIcon} className="opacity-80" />
|
||||
<span className="min-w-0">
|
||||
<span className="block text-ds-text-base">
|
||||
{option.label}
|
||||
|
|
@ -310,7 +302,10 @@ export function ApprovalModeSelect({
|
|||
</span>
|
||||
</span>
|
||||
{value === option.value && (
|
||||
<Check className="h-4 w-4 text-ds-text-success-default-default" />
|
||||
<DsIcon
|
||||
icon={Check}
|
||||
className="text-ds-text-success-default-default"
|
||||
/>
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import { MarkDown } from '@/components/ChatBox/MessageItem/MarkDown';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DsIcon } from '@/components/ui/ds-icon';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
ChevronLeft,
|
||||
|
|
@ -80,14 +81,14 @@ export function BoxHeaderDisplay({
|
|||
)}
|
||||
{title && (
|
||||
<span className="flex items-center gap-1.5 text-ds-text-base font-bold text-ds-ink-default-default">
|
||||
<span>{title}</span>
|
||||
{showQuestionIcon ? (
|
||||
<MessageCircleQuestionMark
|
||||
aria-hidden
|
||||
className="size-4 shrink-0 text-ds-ink-default-default"
|
||||
<DsIcon
|
||||
icon={MessageCircleQuestionMark}
|
||||
recipe="main"
|
||||
data-bottom-box-question-icon
|
||||
/>
|
||||
) : null}
|
||||
<span>{title}</span>
|
||||
</span>
|
||||
)}
|
||||
{description && descriptionAsMarkdown ? (
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import type {
|
|||
interface InputVariantRouterProps {
|
||||
variant: BottomBoxVariant;
|
||||
inputProps: InputboxProps;
|
||||
borderlessApproval?: boolean;
|
||||
borderlessQuestion?: boolean;
|
||||
connectorPanelOpen?: boolean;
|
||||
onToggleConnectorPanel?: () => void;
|
||||
skillPanelOpen?: boolean;
|
||||
|
|
@ -103,24 +105,41 @@ function ConfirmationInput({
|
|||
);
|
||||
}
|
||||
|
||||
function ApprovalInput({ variant }: { variant: BottomBoxApprovalVariant }) {
|
||||
function ApprovalInput({
|
||||
variant,
|
||||
borderless,
|
||||
}: {
|
||||
variant: BottomBoxApprovalVariant;
|
||||
borderless?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div
|
||||
data-bottom-box-input-surface
|
||||
data-approval-surface
|
||||
className={controlSurfaceClassName}
|
||||
className={
|
||||
borderless ? 'flex w-full flex-col gap-3' : controlSurfaceClassName
|
||||
}
|
||||
>
|
||||
<BoxHeaderDisplay
|
||||
{...variant.header}
|
||||
eyebrow={undefined}
|
||||
contextItems={undefined}
|
||||
details={undefined}
|
||||
eyebrow={variant.header.eyebrow}
|
||||
title={variant.header.title}
|
||||
className="px-0 pt-0 pb-0"
|
||||
/>
|
||||
<div data-approval-actions className="flex w-full justify-end">
|
||||
<ControlActions>
|
||||
{variant.error ? (
|
||||
<p
|
||||
role="alert"
|
||||
className="m-0 text-ds-text-meta text-ds-text-error-default-default"
|
||||
>
|
||||
{variant.error}
|
||||
</p>
|
||||
) : null}
|
||||
<div
|
||||
data-approval-actions
|
||||
className="flex w-full flex-wrap justify-end gap-ds-8"
|
||||
>
|
||||
<div className="flex flex-wrap justify-end gap-ds-8">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
|
|
@ -131,15 +150,22 @@ function ApprovalInput({ variant }: { variant: BottomBoxApprovalVariant }) {
|
|||
>
|
||||
{variant.rejectLabel ?? t('chat.control-reject')}
|
||||
</Button>
|
||||
{variant.options.map((option) => {
|
||||
{variant.options.map((option, index) => {
|
||||
return (
|
||||
<Button
|
||||
key={option.scope}
|
||||
type="button"
|
||||
variant="primary"
|
||||
tone="success"
|
||||
variant={
|
||||
option.scope === 'once' ||
|
||||
(index === 0 &&
|
||||
!variant.options.some((item) => item.scope === 'once'))
|
||||
? 'primary'
|
||||
: 'secondary'
|
||||
}
|
||||
tone={option.scope === 'once' ? 'success' : 'neutral'}
|
||||
size="sm"
|
||||
buttonRadius="full"
|
||||
title={option.description}
|
||||
disabled={variant.disabled || variant.submitting}
|
||||
onClick={() => variant.onApprove(option.scope)}
|
||||
>
|
||||
|
|
@ -147,7 +173,7 @@ function ApprovalInput({ variant }: { variant: BottomBoxApprovalVariant }) {
|
|||
</Button>
|
||||
);
|
||||
})}
|
||||
</ControlActions>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
@ -296,20 +322,30 @@ function SelectionInput({ variant }: { variant: BottomBoxSelectionVariant }) {
|
|||
);
|
||||
}
|
||||
|
||||
function FeedbackInput({ variant }: { variant: BottomBoxFeedbackVariant }) {
|
||||
function FeedbackInput({
|
||||
variant,
|
||||
borderless,
|
||||
}: {
|
||||
variant: BottomBoxFeedbackVariant;
|
||||
borderless?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const enterLabel = getEnterKeyLabel(useDesktopShortcutPlatform());
|
||||
|
||||
const isQuestion = variant.presentation === 'question';
|
||||
|
||||
return (
|
||||
<div className={controlSurfaceClassName}>
|
||||
<div
|
||||
className={
|
||||
borderless ? 'flex w-full flex-col gap-ds-12' : controlSurfaceClassName
|
||||
}
|
||||
>
|
||||
<Textarea
|
||||
aria-label={t('chat.control-feedback-label')}
|
||||
value={variant.value}
|
||||
placeholder={variant.placeholder}
|
||||
className={cn(
|
||||
variant.presentation === 'question' &&
|
||||
'border-none shadow-none focus-visible:ring-0 focus-visible:ring-offset-0'
|
||||
)}
|
||||
variant={isQuestion ? 'plain' : 'none'}
|
||||
size="sm"
|
||||
disabled={variant.disabled || variant.submitting}
|
||||
onChange={(event) => variant.onChange(event.target.value)}
|
||||
onEnter={variant.value.trim() ? variant.onSubmit : undefined}
|
||||
|
|
@ -525,6 +561,8 @@ function RunControlInput({ variant }: { variant: BottomBoxRunControlVariant }) {
|
|||
export function ControlInputRouter({
|
||||
variant,
|
||||
inputProps,
|
||||
borderlessApproval,
|
||||
borderlessQuestion,
|
||||
connectorPanelOpen,
|
||||
onToggleConnectorPanel,
|
||||
skillPanelOpen,
|
||||
|
|
@ -549,13 +587,17 @@ export function ControlInputRouter({
|
|||
content = <ConfirmationInput variant={variant} />;
|
||||
break;
|
||||
case 'approval':
|
||||
content = <ApprovalInput variant={variant} />;
|
||||
content = (
|
||||
<ApprovalInput variant={variant} borderless={borderlessApproval} />
|
||||
);
|
||||
break;
|
||||
case 'selection':
|
||||
content = <SelectionInput variant={variant} />;
|
||||
break;
|
||||
case 'feedback':
|
||||
content = <FeedbackInput variant={variant} />;
|
||||
content = (
|
||||
<FeedbackInput variant={variant} borderless={borderlessQuestion} />
|
||||
);
|
||||
break;
|
||||
case 'form':
|
||||
content = <FormInput variant={variant} />;
|
||||
|
|
|
|||
108
src/components/ChatBox/BottomBox/HumanDecisionCard.tsx
Normal file
108
src/components/ChatBox/BottomBox/HumanDecisionCard.tsx
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BoxHeaderDisplay } from './BoxHeader';
|
||||
import { ControlInputRouter } from './ControlInput';
|
||||
import type { BottomBoxVariant } from './types';
|
||||
|
||||
type HumanDecisionVariant = Exclude<
|
||||
BottomBoxVariant,
|
||||
{ kind: 'input' | 'run_control' }
|
||||
>;
|
||||
|
||||
/** One authority for the active request, anchored above the composer. */
|
||||
export function HumanDecisionCard({
|
||||
requestKey,
|
||||
variant,
|
||||
}: {
|
||||
requestKey: string | null;
|
||||
variant: HumanDecisionVariant | null;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [seenKey, setSeenKey] = useState<string | null>(null);
|
||||
const [reviewedKey, setReviewedKey] = useState<string | null>(requestKey);
|
||||
const needsReview = seenKey !== null && reviewedKey !== requestKey;
|
||||
|
||||
useEffect(() => {
|
||||
if (!requestKey) return;
|
||||
if (seenKey === null) setReviewedKey(requestKey);
|
||||
setSeenKey(requestKey);
|
||||
}, [requestKey, seenKey]);
|
||||
|
||||
if (!variant || !requestKey) return null;
|
||||
const isQuestion =
|
||||
variant.kind === 'feedback' && variant.presentation === 'question';
|
||||
|
||||
return (
|
||||
<section
|
||||
data-human-decision-card
|
||||
data-request-key={requestKey}
|
||||
className={cn(
|
||||
'mb-ds-12 w-full rounded-ds-card bg-ds-neutral-subtle-default shadow-ds-elevation-popover',
|
||||
isQuestion ? 'px-ds-16 py-ds-12' : 'p-ds-12'
|
||||
)}
|
||||
role="region"
|
||||
aria-label={t('chat.control-region-label')}
|
||||
aria-live={variant.kind === 'approval' ? 'assertive' : 'polite'}
|
||||
>
|
||||
{needsReview ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
buttonRadius="full"
|
||||
onClick={() => setReviewedKey(requestKey)}
|
||||
>
|
||||
{t('chat.control-review-next-request')}
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<BoxHeaderDisplay
|
||||
{...variant.header}
|
||||
{...(variant.kind === 'approval'
|
||||
? // The target and arguments say what is being approved.
|
||||
{ description: undefined }
|
||||
: {})}
|
||||
className="px-0 pt-0"
|
||||
descriptionAsTitle={
|
||||
variant.kind === 'feedback' && variant.presentation === 'question'
|
||||
}
|
||||
descriptionAsMarkdown={
|
||||
variant.kind === 'feedback' && variant.presentation === 'question'
|
||||
}
|
||||
showQuestionIcon={
|
||||
variant.kind === 'feedback' && variant.presentation === 'question'
|
||||
}
|
||||
/>
|
||||
{isQuestion ? (
|
||||
<Separator data-question-divider className="mb-ds-12" />
|
||||
) : null}
|
||||
<ControlInputRouter
|
||||
variant={
|
||||
variant.kind === 'approval' ? { ...variant, header: {} } : variant
|
||||
}
|
||||
borderlessApproval={variant.kind === 'approval'}
|
||||
borderlessQuestion={isQuestion}
|
||||
inputProps={{}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DsIcon } from '@/components/ui/ds-icon';
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
|
|
@ -286,9 +287,9 @@ export const Inputbox = ({
|
|||
const getFileIcon = (fileName: string) => {
|
||||
const ext = fileName.split('.').pop()?.toLowerCase() || '';
|
||||
if (['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(ext)) {
|
||||
return <Image className="size-3.5 text-ds-ink-default-default" />;
|
||||
return <DsIcon icon={Image} recipe="main-compact" />;
|
||||
}
|
||||
return <FileText className="size-3.5 text-ds-ink-default-default" />;
|
||||
return <DsIcon icon={FileText} recipe="main-compact" />;
|
||||
};
|
||||
|
||||
// Drag & drop handlers
|
||||
|
|
@ -412,7 +413,7 @@ export const Inputbox = ({
|
|||
<div
|
||||
data-bottom-box-input-surface
|
||||
className={cn(
|
||||
'relative flex w-full flex-col items-start rounded-3xl border border-x border-y border-solid border-ds-hairline-default-default bg-ds-neutral-subtle-default p-3 transition-colors',
|
||||
'relative flex w-full flex-col items-start rounded-3xl border border-x border-y border-solid border-ds-hairline-default-default bg-ds-neutral-subtle-default px-ds-panel-inset py-ds-12 transition-colors',
|
||||
(isFocused || hasContent) &&
|
||||
'border-ds-border-information-default-default',
|
||||
isDragging &&
|
||||
|
|
@ -426,7 +427,7 @@ export const Inputbox = ({
|
|||
>
|
||||
{isDragging && (
|
||||
<div className="pointer-events-none absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-3xl border-2 border-x-2 border-y-2 border-dashed border-ds-hairline-strong-default bg-ds-bg-information-subtle-default text-ds-ink-default-default backdrop-blur-sm">
|
||||
<UploadCloud className="h-8 w-8" />
|
||||
<DsIcon icon={UploadCloud} recipe="detailed" />
|
||||
<span className="block text-ds-text-base font-semibold">
|
||||
{t('chat.drop-files-to-attach')}
|
||||
</span>
|
||||
|
|
@ -466,7 +467,11 @@ export const Inputbox = ({
|
|||
title={isHovered ? t('chat.remove-file') : file.fileName}
|
||||
>
|
||||
{isHovered ? (
|
||||
<X className="size-3.5 text-ds-ink-muted-default" />
|
||||
<DsIcon
|
||||
icon={X}
|
||||
recipe="main-compact"
|
||||
className="text-ds-ink-muted-default"
|
||||
/>
|
||||
) : (
|
||||
getFileIcon(file.fileName)
|
||||
)}
|
||||
|
|
@ -544,7 +549,10 @@ export const Inputbox = ({
|
|||
}
|
||||
>
|
||||
{isHovered ? (
|
||||
<X className="size-4 text-ds-ink-muted-default" />
|
||||
<DsIcon
|
||||
icon={X}
|
||||
className="text-ds-ink-muted-default"
|
||||
/>
|
||||
) : (
|
||||
getFileIcon(file.fileName)
|
||||
)}
|
||||
|
|
@ -621,7 +629,7 @@ export const Inputbox = ({
|
|||
aria-label={t('chat.input-attach-add-files-or-photos')}
|
||||
onClick={() => onAddFile?.()}
|
||||
>
|
||||
<Paperclip />
|
||||
<DsIcon icon={Paperclip} />
|
||||
</Button>
|
||||
</TooltipSimple>
|
||||
{onToggleConnectorPanel && (
|
||||
|
|
@ -645,7 +653,7 @@ export const Inputbox = ({
|
|||
)}
|
||||
onClick={onToggleConnectorPanel}
|
||||
>
|
||||
<Cable />
|
||||
<DsIcon icon={Cable} />
|
||||
</Button>
|
||||
</TooltipSimple>
|
||||
)}
|
||||
|
|
@ -668,7 +676,7 @@ export const Inputbox = ({
|
|||
className={cn(skillPanelOpen && 'bg-ds-neutral-strong-default')}
|
||||
onClick={onToggleSkillPanel}
|
||||
>
|
||||
<WandSparkles />
|
||||
<DsIcon icon={WandSparkles} />
|
||||
</Button>
|
||||
</TooltipSimple>
|
||||
)}
|
||||
|
|
@ -711,7 +719,8 @@ export const Inputbox = ({
|
|||
className="relative grid size-ds-icon-md place-items-center leading-none"
|
||||
aria-hidden
|
||||
>
|
||||
<ArrowRight
|
||||
<DsIcon
|
||||
icon={ArrowRight}
|
||||
data-composer-primary-icon="arrow"
|
||||
style={PRIMARY_ACTION_ICON_MOTION_STYLE}
|
||||
className={cn(
|
||||
|
|
@ -723,7 +732,8 @@ export const Inputbox = ({
|
|||
: 'rotate-0 opacity-0'
|
||||
)}
|
||||
/>
|
||||
<Square
|
||||
<DsIcon
|
||||
icon={Square}
|
||||
data-composer-primary-icon="pause"
|
||||
style={PRIMARY_ACTION_ICON_MOTION_STYLE}
|
||||
className={cn(
|
||||
|
|
@ -733,7 +743,8 @@ export const Inputbox = ({
|
|||
: 'rotate-90 opacity-0'
|
||||
)}
|
||||
/>
|
||||
<Play
|
||||
<DsIcon
|
||||
icon={Play}
|
||||
data-composer-primary-icon="play"
|
||||
style={PRIMARY_ACTION_ICON_MOTION_STYLE}
|
||||
className={cn(
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@
|
|||
.queued-task-row[data-dragging] .queued-task-drag-handle {
|
||||
cursor: grabbing;
|
||||
}
|
||||
/* InputBox's border + inset, then RichChatInput's placeholder text inset. */
|
||||
/* Match InputBox's border and shared content inset. */
|
||||
.queued-task-composer-inset {
|
||||
margin-inline: calc(var(--ds-border-thin) + var(--ds-space-panel-inset));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ export const RichChatInput = React.forwardRef<
|
|||
<div className="relative isolate w-full min-w-0 flex-1">
|
||||
<div
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute top-0 left-1 z-[1] w-[calc(100%-0.25rem)] max-w-[calc(100%-0.25rem)] select-none"
|
||||
className="pointer-events-none absolute inset-x-0 top-0 z-[1] select-none"
|
||||
>
|
||||
{showPlaceholder ? (
|
||||
<motion.span
|
||||
|
|
@ -562,7 +562,7 @@ export const RichChatInput = React.forwardRef<
|
|||
}}
|
||||
className={cn(
|
||||
'w-full flex-1 resize-none overflow-auto outline-none',
|
||||
'scrollbar max-h-[200px] min-h-[40px] py-0 pl-1',
|
||||
'scrollbar max-h-[200px] min-h-[40px] p-0',
|
||||
'relative break-words whitespace-pre-wrap',
|
||||
disabled && 'cursor-not-allowed opacity-60',
|
||||
textClassName,
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ export interface BottomBoxApprovalOption {
|
|||
/** A permission request. Only options supplied by the backend are rendered. */
|
||||
export interface BottomBoxApprovalVariant extends ControlledVariantBase {
|
||||
kind: 'approval';
|
||||
error?: string;
|
||||
options: readonly BottomBoxApprovalOption[];
|
||||
rejectLabel?: string;
|
||||
onApprove: (scope: BottomBoxApprovalScope) => void;
|
||||
|
|
|
|||
|
|
@ -751,10 +751,10 @@ export function useEventNativeHumanControl({
|
|||
interaction.prompt ||
|
||||
interaction.title ||
|
||||
t('chat.control-approval-required'),
|
||||
description: activeSubmission.error || undefined,
|
||||
contextItems: header.contextItems,
|
||||
details: header.details,
|
||||
},
|
||||
error: activeSubmission.error || undefined,
|
||||
submitting,
|
||||
options: [...new Set(offeredScopes)].map((scope) => ({
|
||||
scope,
|
||||
|
|
|
|||
|
|
@ -121,10 +121,11 @@ import { useSearchParams } from 'react-router-dom';
|
|||
import { toast } from 'sonner';
|
||||
import BottomBox from './BottomBox';
|
||||
import { selectBottomBoxControl } from './BottomBox/controlArbitration';
|
||||
import { HumanDecisionCard } from './BottomBox/HumanDecisionCard';
|
||||
import { createLegacyApprovalVariant } from './BottomBox/legacyHumanControl';
|
||||
import type {
|
||||
BottomBoxApprovalScope,
|
||||
BottomBoxInputVariant,
|
||||
BottomBoxFeedbackVariant,
|
||||
BottomBoxRunControlVariant,
|
||||
} from './BottomBox/types';
|
||||
import { useEventNativeHumanControl } from './BottomBox/useEventNativeHumanControl';
|
||||
|
|
@ -2837,32 +2838,52 @@ function LegacyChatBox({ accountKey }: { accountKey: string }): JSX.Element {
|
|||
) {
|
||||
legacyApprovalVariant.disabled = true;
|
||||
}
|
||||
const legacyHumanInputVariant: BottomBoxInputVariant | 'input' =
|
||||
activeAsk && isInteractiveHumanReply && activeAskMessage
|
||||
const legacyQuestionVariant: BottomBoxFeedbackVariant | null =
|
||||
!eventNativeTimelineEnabled &&
|
||||
activeAsk &&
|
||||
!isLegacyApproval &&
|
||||
isInteractiveHumanReply &&
|
||||
activeAskMessage
|
||||
? {
|
||||
kind: 'input',
|
||||
kind: 'feedback',
|
||||
presentation: 'question',
|
||||
header: {
|
||||
eyebrow: t('chat.control-input-required'),
|
||||
title:
|
||||
title: t('chat.timeline-question'),
|
||||
description:
|
||||
activeInteraction?.question || activeAskMessage.content.trim(),
|
||||
},
|
||||
value: message,
|
||||
placeholder: t('chat.control-response-placeholder'),
|
||||
submitting: activeAskTask?.isPending,
|
||||
onChange: setMessage,
|
||||
onSubmit: () => void handleSend(),
|
||||
}
|
||||
: 'input';
|
||||
: null;
|
||||
// Timeline density is presentation-only. Select one shared BottomBox control
|
||||
// from the active authority before rendering Normal, Detailed, or Summarised.
|
||||
const bottomBoxControl = selectBottomBoxControl({
|
||||
humanInteractionVariant: eventNativeTimelineEnabled
|
||||
? eventNativeHumanControl.variant
|
||||
: legacyApprovalVariant,
|
||||
: (legacyApprovalVariant ?? legacyQuestionVariant),
|
||||
runControlVariant: eventNativeTimelineEnabled
|
||||
? eventNativeRunControlVariant
|
||||
: null,
|
||||
composerVariant: eventNativeTimelineEnabled
|
||||
? 'input'
|
||||
: legacyHumanInputVariant,
|
||||
composerVariant: 'input',
|
||||
});
|
||||
const bottomBoxVariant = bottomBoxControl.variant;
|
||||
const hasControlledBottomBoxVariant = bottomBoxControl.isControlled;
|
||||
const humanDecisionVariant =
|
||||
bottomBoxControl.source === 'human_interaction' &&
|
||||
typeof bottomBoxVariant !== 'string' &&
|
||||
bottomBoxVariant.kind !== 'input' &&
|
||||
bottomBoxVariant.kind !== 'run_control'
|
||||
? bottomBoxVariant
|
||||
: null;
|
||||
const humanDecisionKey = humanDecisionVariant
|
||||
? eventNativeTimelineEnabled && eventNativeHumanControl.interaction
|
||||
? `${activeProjectId}:${eventNativeHumanControl.interaction.runId}:${eventNativeHumanControl.interaction.interactionId}:${eventNativeHumanControl.interaction.version ?? 0}`
|
||||
: `${activeProjectId}:${activeTaskId}:${activeInteraction?.interaction_id ?? activeAskMessage?.id ?? ''}`
|
||||
: null;
|
||||
const composerTaskControlState = selectComposerTaskControlState({
|
||||
eventNativeTimelineEnabled,
|
||||
legacyControlRunId: legacyControlTaskId,
|
||||
|
|
@ -3056,6 +3077,11 @@ function LegacyChatBox({ accountKey }: { accountKey: string }): JSX.Element {
|
|||
className="pointer-events-none absolute inset-x-0 bottom-0 z-30 flex justify-center px-2.5"
|
||||
>
|
||||
<div className="pointer-events-auto mx-auto w-full max-w-[600px] rounded-t-3xl bg-ds-neutral-subtle-default pb-1">
|
||||
<HumanDecisionCard
|
||||
key={activeProjectId ?? 'no-session'}
|
||||
requestKey={humanDecisionKey}
|
||||
variant={humanDecisionVariant}
|
||||
/>
|
||||
{interruptedRun && !eventNativeTimelineEnabled && (
|
||||
<InterruptedRunBanner
|
||||
compact
|
||||
|
|
@ -3093,7 +3119,7 @@ function LegacyChatBox({ accountKey }: { accountKey: string }): JSX.Element {
|
|||
? 'running'
|
||||
: getBottomBoxState()
|
||||
}
|
||||
variant={bottomBoxVariant}
|
||||
variant={humanDecisionVariant ? 'input' : bottomBoxVariant}
|
||||
queuedMessages={queuedMessages}
|
||||
queueContext={queueContext}
|
||||
onRemoveQueuedMessage={(id) => handleRemoveTaskQueue(id)}
|
||||
|
|
@ -3132,7 +3158,7 @@ function LegacyChatBox({ accountKey }: { accountKey: string }): JSX.Element {
|
|||
onEdit={handleEditQuery}
|
||||
loading={loading}
|
||||
inputProps={{
|
||||
value: message,
|
||||
value: legacyQuestionVariant ? '' : message,
|
||||
onChange: setMessage,
|
||||
onSend: handleSend,
|
||||
queuesFollowUp: isTaskBusy && !activeAsk,
|
||||
|
|
@ -3151,7 +3177,7 @@ function LegacyChatBox({ accountKey }: { accountKey: string }): JSX.Element {
|
|||
},
|
||||
onAddFile: handleFileSelect,
|
||||
placeholder: t('chat.follow-up-placeholder'),
|
||||
disabled: isInputDisabled,
|
||||
disabled: isInputDisabled || Boolean(humanDecisionVariant),
|
||||
textareaRef: textareaRef,
|
||||
allowDragDrop: true,
|
||||
useCloudModelInDev: useCloudModelInDev,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// limitations under the License.
|
||||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
import { DsIcon } from '@/components/ui/ds-icon';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { SessionModeType } from '@/types/constants';
|
||||
import { SessionMode } from '@/types/constants';
|
||||
|
|
@ -102,15 +103,23 @@ export function ProjectModeToggle({
|
|||
className
|
||||
);
|
||||
|
||||
const chevronClass = 'size-3 shrink-0 opacity-80';
|
||||
const chevronClass = 'opacity-80';
|
||||
|
||||
const endChevrons = (
|
||||
<span
|
||||
className="inline-flex shrink-0 flex-col items-center justify-center gap-0 leading-none"
|
||||
aria-hidden
|
||||
>
|
||||
<ChevronUp className={cn(chevronClass, '-mb-1')} strokeWidth={2} />
|
||||
<ChevronDown className={chevronClass} strokeWidth={2} />
|
||||
<DsIcon
|
||||
icon={ChevronUp}
|
||||
recipe="main-compact"
|
||||
className={cn(chevronClass, '-mb-ds-4')}
|
||||
/>
|
||||
<DsIcon
|
||||
icon={ChevronDown}
|
||||
recipe="main-compact"
|
||||
className={chevronClass}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
|
||||
|
|
@ -123,11 +132,7 @@ export function ProjectModeToggle({
|
|||
className={cn(shellClass, 'pointer-events-none bg-transparent')}
|
||||
>
|
||||
<span className="inline-flex min-h-[1.25rem] items-center gap-1.5 overflow-hidden">
|
||||
<LeadingIcon
|
||||
className="size-3.5 shrink-0"
|
||||
strokeWidth={2}
|
||||
aria-hidden
|
||||
/>
|
||||
<DsIcon icon={LeadingIcon} />
|
||||
{!compact && (
|
||||
<span className="!text-ds-text-meta font-semibold">{label}</span>
|
||||
)}
|
||||
|
|
@ -161,11 +166,7 @@ export function ProjectModeToggle({
|
|||
animate="animate"
|
||||
exit="exit"
|
||||
>
|
||||
<LeadingIcon
|
||||
className="size-3.5 shrink-0"
|
||||
strokeWidth={2}
|
||||
aria-hidden
|
||||
/>
|
||||
<DsIcon icon={LeadingIcon} />
|
||||
{!compact && (
|
||||
<span className="!text-ds-text-meta font-semibold whitespace-nowrap">
|
||||
{label}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,11 @@ import {
|
|||
formFieldTextareaStateClasses,
|
||||
type TextareaFormFieldState,
|
||||
} from './formFieldSurface';
|
||||
import { DS_FOCUS_RING } from './semanticProps';
|
||||
import { formControlTokenAliases, mergeAliasStyles } from './tokenAliases';
|
||||
import { TooltipSimple } from './tooltip';
|
||||
|
||||
export type TextareaVariant = 'none' | 'enhanced' | 'outlined';
|
||||
export type TextareaVariant = 'none' | 'plain' | 'enhanced' | 'outlined';
|
||||
export type TextareaSize = 'default' | 'sm';
|
||||
export type TextareaState =
|
||||
'default' | 'hover' | 'input' | 'error' | 'success' | 'disabled';
|
||||
|
|
@ -78,19 +79,27 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, BaseTextareaProps>(
|
|||
} = props;
|
||||
const [isComposing, setIsComposing] = React.useState(false);
|
||||
// Original "none" variant - keep the original styling
|
||||
if (variant === 'none') {
|
||||
if (variant === 'none' || variant === 'plain') {
|
||||
return (
|
||||
<>
|
||||
<textarea
|
||||
{...textareaProps}
|
||||
data-scrollbar="ui-textarea"
|
||||
className={cn(
|
||||
'flex min-h-[4rem] w-full [scrollbar-gutter:stable] rounded-ds-field border border-x border-y border-ds-hairline-default-default bg-transparent py-2 pr-3 pl-3 text-ds-text-base shadow-sm placeholder:text-ds-ink-muted-default focus-visible:ring-2 focus-visible:ring-ds-ring-focus focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
|
||||
variant === 'plain'
|
||||
? cn(
|
||||
'flex w-full [scrollbar-gutter:stable] rounded-ds-field border-0 border-x-0 border-y-0 bg-transparent p-0 text-ds-text-base text-ds-ink-default-default shadow-none placeholder:text-ds-ink-muted-default disabled:cursor-not-allowed disabled:opacity-50',
|
||||
size === 'sm'
|
||||
? 'min-h-[var(--ds-textarea-sm-min-height)]'
|
||||
: 'min-h-[var(--ds-textarea-md-min-height)]',
|
||||
DS_FOCUS_RING
|
||||
)
|
||||
: 'flex min-h-[4rem] w-full [scrollbar-gutter:stable] rounded-ds-field border border-x border-y border-ds-hairline-default-default bg-transparent py-2 pr-3 pl-3 text-ds-text-base shadow-sm placeholder:text-ds-ink-muted-default focus-visible:ring-2 focus-visible:ring-ds-ring-focus focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
|
||||
isComposing && 'placeholder:opacity-0',
|
||||
className
|
||||
)}
|
||||
style={mergeAliasStyles(formControlTokenAliases, {
|
||||
paddingRight: '4px',
|
||||
...(variant === 'plain' ? {} : { paddingRight: '4px' }),
|
||||
...(style as React.CSSProperties),
|
||||
})}
|
||||
ref={ref}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "غير معروف",
|
||||
"follow-up-prepare-failed": "تعذر إعداد مهمة المتابعة.",
|
||||
"control-region-label": "طلب من الوكيل",
|
||||
"control-review-next-request": "مراجعة الطلب التالي",
|
||||
"control-input-required": "مطلوب ردّك",
|
||||
"control-input-required-message": "مطلوب ردّك: {{message}}",
|
||||
"control-input-required-count": "مطلوب ردّك · {{count}} قيد الانتظار",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "Unbekannt",
|
||||
"follow-up-prepare-failed": "Die Folgeaufgabe konnte nicht vorbereitet werden.",
|
||||
"control-region-label": "Agent-Anfrage",
|
||||
"control-review-next-request": "Nächste Anfrage prüfen",
|
||||
"control-input-required": "Eingabe erforderlich",
|
||||
"control-input-required-message": "Eingabe erforderlich: {{message}}",
|
||||
"control-input-required-count": "Eingabe erforderlich · {{count}} ausstehend",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "Unknown",
|
||||
"follow-up-prepare-failed": "Unable to prepare the follow-up task.",
|
||||
"control-region-label": "Agent request",
|
||||
"control-review-next-request": "Review next request",
|
||||
"control-input-required": "Input required",
|
||||
"control-input-required-message": "Input required: {{message}}",
|
||||
"control-input-required-count": "Input required · {{count}} pending",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "Desconocida",
|
||||
"follow-up-prepare-failed": "No se pudo preparar la tarea de seguimiento.",
|
||||
"control-region-label": "Solicitud del agente",
|
||||
"control-review-next-request": "Revisar la siguiente solicitud",
|
||||
"control-input-required": "Se necesita tu respuesta",
|
||||
"control-input-required-message": "Se necesita tu respuesta: {{message}}",
|
||||
"control-input-required-count": "Se necesita tu respuesta · {{count}} pendientes",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "Inconnu",
|
||||
"follow-up-prepare-failed": "Impossible de préparer la tâche de suivi.",
|
||||
"control-region-label": "Demande de l’agent",
|
||||
"control-review-next-request": "Examiner la demande suivante",
|
||||
"control-input-required": "Action requise",
|
||||
"control-input-required-message": "Action requise : {{message}}",
|
||||
"control-input-required-count": "Action requise · {{count}} en attente",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "Sconosciuta",
|
||||
"follow-up-prepare-failed": "Impossibile preparare l’attività di follow-up.",
|
||||
"control-region-label": "Richiesta dell’agente",
|
||||
"control-review-next-request": "Esamina la richiesta successiva",
|
||||
"control-input-required": "Serve la tua risposta",
|
||||
"control-input-required-message": "È necessaria una risposta: {{message}}",
|
||||
"control-input-required-count": "Serve la tua risposta · {{count}} in attesa",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "不明",
|
||||
"follow-up-prepare-failed": "フォローアップタスクを準備できませんでした。",
|
||||
"control-region-label": "エージェントからのリクエスト",
|
||||
"control-review-next-request": "次のリクエストを確認",
|
||||
"control-input-required": "確認が必要です",
|
||||
"control-input-required-message": "入力が必要です:{{message}}",
|
||||
"control-input-required-count": "確認が必要です · 保留中 {{count}} 件",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "알 수 없음",
|
||||
"follow-up-prepare-failed": "후속 작업을 준비하지 못했습니다.",
|
||||
"control-region-label": "에이전트 요청",
|
||||
"control-review-next-request": "다음 요청 검토",
|
||||
"control-input-required": "확인이 필요합니다",
|
||||
"control-input-required-message": "입력이 필요합니다: {{message}}",
|
||||
"control-input-required-count": "확인이 필요합니다 · 대기 중 {{count}}건",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "Неизвестно",
|
||||
"follow-up-prepare-failed": "Не удалось подготовить следующую задачу.",
|
||||
"control-region-label": "Запрос агента",
|
||||
"control-review-next-request": "Просмотреть следующий запрос",
|
||||
"control-input-required": "Нужен ваш ответ",
|
||||
"control-input-required-message": "Требуется ввод: {{message}}",
|
||||
"control-input-required-count": "Нужен ваш ответ · в очереди: {{count}}",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "未知",
|
||||
"follow-up-prepare-failed": "无法准备后续任务。",
|
||||
"control-region-label": "智能体请求",
|
||||
"control-review-next-request": "查看下一个请求",
|
||||
"control-input-required": "需要你的确认",
|
||||
"control-input-required-message": "需要你的输入:{{message}}",
|
||||
"control-input-required-count": "需要你的确认 · {{count}} 项待处理",
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
"tool-status-unknown": "未知",
|
||||
"follow-up-prepare-failed": "無法準備後續任務。",
|
||||
"control-region-label": "智慧代理請求",
|
||||
"control-review-next-request": "檢視下一個請求",
|
||||
"control-input-required": "需要你的確認",
|
||||
"control-input-required-message": "需要你的輸入:{{message}}",
|
||||
"control-input-required-count": "需要你的確認 · {{count}} 項待處理",
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|||
const mocks = vi.hoisted(() => ({
|
||||
input: null as any,
|
||||
variant: null as any,
|
||||
decisionVariant: null as any,
|
||||
snapshot: null as any,
|
||||
space: null as any,
|
||||
interrupted: null as any,
|
||||
|
|
@ -206,9 +207,24 @@ vi.mock('@/components/ChatBox/ProjectChatContainer', () => ({
|
|||
vi.mock('@/components/ChatBox/EventNativeProjectTimeline', () => ({
|
||||
EventNativeProjectTimeline: () => null,
|
||||
}));
|
||||
// The active human decision renders above the composer, which then stays a
|
||||
// plain input. Record whichever control currently owns the decision.
|
||||
vi.mock('@/components/ChatBox/BottomBox/HumanDecisionCard', () => ({
|
||||
HumanDecisionCard: ({ variant }: any) => {
|
||||
mocks.decisionVariant = variant;
|
||||
return variant?.kind === 'approval' ? (
|
||||
<button
|
||||
disabled={variant.disabled}
|
||||
onClick={() => variant.onApprove('once')}
|
||||
>
|
||||
Approve
|
||||
</button>
|
||||
) : null;
|
||||
},
|
||||
}));
|
||||
vi.mock('@/components/ChatBox/BottomBox', () => ({
|
||||
default: ({ inputProps, noModelOverlay, variant }: any) => {
|
||||
mocks.variant = variant;
|
||||
mocks.variant = mocks.decisionVariant ?? variant;
|
||||
mocks.input = inputProps;
|
||||
if (!inputProps) return null;
|
||||
return (
|
||||
|
|
@ -227,14 +243,6 @@ vi.mock('@/components/ChatBox/BottomBox', () => ({
|
|||
>
|
||||
Follow up
|
||||
</button>
|
||||
{variant?.kind === 'approval' ? (
|
||||
<button
|
||||
disabled={variant.disabled}
|
||||
onClick={() => variant.onApprove('once')}
|
||||
>
|
||||
Approve
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4325,6 +4325,95 @@ describe('ChatBox Component', async () => {
|
|||
});
|
||||
|
||||
describe('Agent Interaction', () => {
|
||||
it('answers a legacy question in a separate card while the composer stays disabled', async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseChatStoreAdapter.mockReturnValue({
|
||||
projectStore: defaultProjectStoreState as any,
|
||||
chatStore: {
|
||||
...defaultChatStoreState,
|
||||
tasks: {
|
||||
'test-task-id': {
|
||||
...defaultChatStoreState.tasks['test-task-id'],
|
||||
status: 'running',
|
||||
activeAsk: 'test-agent',
|
||||
hasMessages: true,
|
||||
messages: [
|
||||
{
|
||||
id: 'legacy-question',
|
||||
role: 'agent',
|
||||
step: 'ask',
|
||||
content: 'Which colour?',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
});
|
||||
renderChatBox();
|
||||
|
||||
const card = screen.getByRole('region', {
|
||||
name: 'chat.control-region-label',
|
||||
});
|
||||
const response = within(card).getByRole('textbox', {
|
||||
name: 'chat.control-feedback-label',
|
||||
});
|
||||
expect(within(card).getByText('Which colour?')).toBeInTheDocument();
|
||||
expect(card.querySelector('[data-question-divider]')).not.toBeNull();
|
||||
expect(screen.getByTestId('message-input')).toBeDisabled();
|
||||
expect(screen.getByTestId('bottom-box')).not.toContainElement(response);
|
||||
|
||||
await user.type(response, 'green{Shift>}{Enter}{/Shift}please');
|
||||
expect(response).toHaveValue('green\nplease');
|
||||
expect(screen.getByTestId('message-input')).toHaveValue('');
|
||||
await user.type(response, '{Enter}');
|
||||
await waitFor(() =>
|
||||
expect(_mockFetchPost).toHaveBeenCalledWith(
|
||||
'/chat/test-project-id/human-reply',
|
||||
expect.objectContaining({
|
||||
agent: 'test-agent',
|
||||
reply: 'green\nplease',
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps a failed legacy question answer in the card for retry', async () => {
|
||||
const user = userEvent.setup();
|
||||
_mockFetchPost.mockRejectedValueOnce(new Error('Reply unavailable'));
|
||||
const storeObj = {
|
||||
...defaultChatStoreState,
|
||||
tasks: {
|
||||
'test-task-id': {
|
||||
...defaultChatStoreState.tasks['test-task-id'],
|
||||
status: 'running',
|
||||
activeAsk: 'test-agent',
|
||||
hasMessages: true,
|
||||
messages: [
|
||||
{
|
||||
id: 'legacy-question',
|
||||
role: 'agent',
|
||||
step: 'ask',
|
||||
content: 'Which colour?',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as any;
|
||||
mockUseChatStoreAdapter.mockReturnValue({
|
||||
projectStore: defaultProjectStoreState as any,
|
||||
chatStore: storeObj,
|
||||
});
|
||||
renderChatBox();
|
||||
const response = screen.getByRole('textbox', {
|
||||
name: 'chat.control-feedback-label',
|
||||
});
|
||||
await user.type(response, 'green{Enter}');
|
||||
await waitFor(() => expect(storeObj.removeMessage).toHaveBeenCalled());
|
||||
expect(response).toHaveValue('green');
|
||||
expect(screen.getByTestId('message-input')).toBeDisabled();
|
||||
expect(storeObj.setActiveAsk).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle human reply when activeAsk is set', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
|
|
|
|||
|
|
@ -391,9 +391,10 @@ describe('BottomBox structure', () => {
|
|||
|
||||
expect(approvalSurface).toBeInTheDocument();
|
||||
expect(approvalHeader).toBeInTheDocument();
|
||||
expect(approvalHeader).not.toHaveTextContent('Permission required');
|
||||
expect(approvalHeader).toHaveTextContent('Permission required');
|
||||
expect(approvalHeader).toHaveTextContent('Allow todo_write?');
|
||||
expect(approvalSurface).toContainElement(approvalActions as HTMLElement);
|
||||
expect(approvalSurface).toHaveClass('border');
|
||||
expect(container.querySelector('[data-approval-actions]')).toHaveClass(
|
||||
'justify-end'
|
||||
);
|
||||
|
|
@ -404,7 +405,15 @@ describe('BottomBox structure', () => {
|
|||
approvalButtons.forEach((button) =>
|
||||
expect(button).toHaveClass('!rounded-full')
|
||||
);
|
||||
expect(container.querySelector('p, h1, h2, h3, h4, h5, h6')).toBeNull();
|
||||
expect(
|
||||
screen.queryByText('This action supports one-time approval only.')
|
||||
).not.toBeInTheDocument();
|
||||
expect(approvalActions?.firstElementChild).toContainElement(
|
||||
screen.getByRole('button', { name: 'Reject' })
|
||||
);
|
||||
expect(approvalActions?.lastElementChild).toContainElement(
|
||||
screen.getByRole('button', { name: 'Approve once' })
|
||||
);
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /always allow/i })
|
||||
).not.toBeInTheDocument();
|
||||
|
|
@ -453,7 +462,7 @@ describe('BottomBox structure', () => {
|
|||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('Input required')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Input required')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText('Allow this action one time only.')
|
||||
).not.toBeInTheDocument();
|
||||
|
|
@ -518,7 +527,7 @@ describe('BottomBox structure', () => {
|
|||
'data-layout-motion',
|
||||
'instant'
|
||||
);
|
||||
expect(screen.queryByText('Input required')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Input required')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('The agent wants to publish the report.')
|
||||
).toBeInTheDocument();
|
||||
|
|
@ -634,10 +643,11 @@ describe('BottomBox structure', () => {
|
|||
name: 'Feedback',
|
||||
});
|
||||
expect(questionTextarea).toHaveClass(
|
||||
'border-none',
|
||||
'border-0',
|
||||
'p-0',
|
||||
'shadow-none',
|
||||
'focus-visible:ring-0',
|
||||
'focus-visible:ring-offset-0'
|
||||
'focus-visible:ring-2',
|
||||
'focus-visible:ring-offset-2'
|
||||
);
|
||||
fireEvent.change(questionTextarea, {
|
||||
target: { value: 'Use a shorter title' },
|
||||
|
|
|
|||
|
|
@ -34,6 +34,60 @@ function approvalVariant(
|
|||
};
|
||||
}
|
||||
|
||||
describe('BottomBox feedback answer field', () => {
|
||||
it('renders a question answer as a plain field with a focus ring', () => {
|
||||
render(
|
||||
<ControlInputRouter
|
||||
variant={{
|
||||
kind: 'feedback',
|
||||
presentation: 'question',
|
||||
header: { title: 'Question' },
|
||||
value: '',
|
||||
onChange: vi.fn(),
|
||||
onSubmit: vi.fn(),
|
||||
}}
|
||||
inputProps={{}}
|
||||
/>
|
||||
);
|
||||
const answer = screen.getByRole('textbox', { name: 'Feedback' });
|
||||
|
||||
expect(answer).toHaveClass(
|
||||
'p-0',
|
||||
'border-0',
|
||||
'shadow-none',
|
||||
'min-h-[var(--ds-textarea-sm-min-height)]',
|
||||
'focus-visible:ring-2',
|
||||
'focus-visible:ring-offset-2'
|
||||
);
|
||||
expect(answer).not.toHaveClass('border-ds-hairline-default-default');
|
||||
});
|
||||
|
||||
it('keeps the framed field for feedback that is not a question', () => {
|
||||
render(
|
||||
<ControlInputRouter
|
||||
variant={{
|
||||
kind: 'feedback',
|
||||
header: { title: 'What should change?' },
|
||||
value: '',
|
||||
onChange: vi.fn(),
|
||||
onSubmit: vi.fn(),
|
||||
}}
|
||||
inputProps={{}}
|
||||
/>
|
||||
);
|
||||
const field = screen.getByRole('textbox', { name: 'Feedback' });
|
||||
|
||||
expect(field).toHaveClass(
|
||||
'border',
|
||||
'border-ds-hairline-default-default',
|
||||
'py-2',
|
||||
'pl-3',
|
||||
'shadow-sm'
|
||||
);
|
||||
expect(field).not.toHaveClass('p-0', 'border-0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('BottomBox approval keyboard safety', () => {
|
||||
it('does not approve from window or body Enter', () => {
|
||||
const onApprove = vi.fn();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,249 @@
|
|||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
import { HumanDecisionCard } from '@/components/ChatBox/BottomBox/HumanDecisionCard';
|
||||
import type { BottomBoxApprovalVariant } from '@/components/ChatBox/BottomBox/types';
|
||||
import { useEventNativeHumanControl } from '@/components/ChatBox/BottomBox/useEventNativeHumanControl';
|
||||
import type { HumanControlInteraction } from '@/lib/projector/control';
|
||||
import {
|
||||
fireEvent,
|
||||
render,
|
||||
renderHook,
|
||||
screen,
|
||||
within,
|
||||
} from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
interaction: null as HumanControlInteraction | null,
|
||||
}));
|
||||
|
||||
vi.mock('@/hooks/useProjectEventView', () => ({
|
||||
useProjectHumanControlProjection: () =>
|
||||
mocks.interaction
|
||||
? {
|
||||
projectId: mocks.interaction.projectId,
|
||||
interactionById: {
|
||||
[mocks.interaction.interactionId]: mocks.interaction,
|
||||
},
|
||||
orderedInteractionIds: [mocks.interaction.interactionId],
|
||||
seenEventIds: {},
|
||||
}
|
||||
: null,
|
||||
}));
|
||||
|
||||
vi.mock('@/service/humanInteractionApi', () => ({
|
||||
decideHumanInteraction: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/service/humanInteractionEventReconciliation', () => ({
|
||||
reconcileHumanInteractionEvents: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/store/authStore', () => ({
|
||||
getAuthStore: () => ({ user_id: 42 }),
|
||||
useAuthStore: (selector: (state: { user_id: number }) => unknown) =>
|
||||
selector({ user_id: 42 }),
|
||||
}));
|
||||
|
||||
function approval(
|
||||
onApprove: BottomBoxApprovalVariant['onApprove']
|
||||
): BottomBoxApprovalVariant {
|
||||
return {
|
||||
kind: 'approval',
|
||||
header: { title: 'Allow this action?' },
|
||||
options: [{ scope: 'once', label: 'Approve once' }],
|
||||
onApprove,
|
||||
onReject: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
describe('HumanDecisionCard', () => {
|
||||
it('shows the approval type, title, target and arguments above its controls', () => {
|
||||
const { container } = render(
|
||||
<HumanDecisionCard
|
||||
requestKey="run:approval-1"
|
||||
variant={{
|
||||
...approval(vi.fn()),
|
||||
header: {
|
||||
eyebrow: 'Input required',
|
||||
title: 'Run shell_exec?',
|
||||
description: 'Technical context',
|
||||
contextItems: [{ id: 'agent', label: 'single_agent' }],
|
||||
details: [
|
||||
{ id: 'args', label: 'Review details', content: 'secret' },
|
||||
],
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Input required')).toBeInTheDocument();
|
||||
expect(screen.getByText('Run shell_exec?')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Technical context')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('single_agent')).toBeInTheDocument();
|
||||
expect(screen.getByText('Review details')).toBeInTheDocument();
|
||||
const card = container.querySelector('[data-human-decision-card]');
|
||||
// A floating card uses elevation alone, not a boundary as well.
|
||||
expect(card).toHaveClass('rounded-ds-card', 'shadow-ds-elevation-popover');
|
||||
expect(card).not.toHaveClass('border');
|
||||
const approvalSurface = container.querySelector('[data-approval-surface]');
|
||||
expect(approvalSurface).not.toHaveClass('border');
|
||||
expect(approvalSurface).not.toHaveClass('border-x');
|
||||
expect(approvalSurface).not.toHaveClass('border-y');
|
||||
expect(
|
||||
screen.queryByText('This action supports one-time approval only.')
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Reject' })).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Approve once' })
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the target and arguments of an event-native approval', () => {
|
||||
mocks.interaction = {
|
||||
interactionId: 'approval-1',
|
||||
interactionType: 'approval',
|
||||
status: 'requested',
|
||||
projectId: 'project-1',
|
||||
runId: 'run-1',
|
||||
sequence: 3,
|
||||
lastSequence: 3,
|
||||
cloudCursor: null,
|
||||
lastCloudCursor: null,
|
||||
requestEventId: 'request-1',
|
||||
requestSource: 'canonical',
|
||||
lastEventId: 'request-1',
|
||||
requestedAt: '2026-08-11T10:00:03.000Z',
|
||||
updatedAt: '2026-08-11T10:00:03.000Z',
|
||||
version: 0,
|
||||
approvalId: 'approval-1',
|
||||
actionDigest: 'digest-1',
|
||||
allowedScopes: ['once'],
|
||||
title: 'Allow shell_exec?',
|
||||
prompt: 'The agent wants to run shell_exec (terminal.exec).',
|
||||
agent: 'developer_agent',
|
||||
operation: 'terminal.exec',
|
||||
targetResources: ['notes/plan.md'],
|
||||
displayArguments: { command: 'rm -rf build' },
|
||||
ruleMatcher: null,
|
||||
options: [],
|
||||
fields: [],
|
||||
};
|
||||
const { result } = renderHook(() =>
|
||||
useEventNativeHumanControl({
|
||||
projectId: 'project-1',
|
||||
activeRunId: 'run-1',
|
||||
})
|
||||
);
|
||||
const variant = result.current.variant;
|
||||
if (variant?.kind !== 'approval') throw new Error('Expected an approval');
|
||||
|
||||
const { container } = render(
|
||||
<HumanDecisionCard requestKey="run-1:approval-1" variant={variant} />
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByText('The agent wants to run shell_exec (terminal.exec).')
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText('notes/plan.md')).toBeInTheDocument();
|
||||
const details = container.querySelector('details');
|
||||
expect(details).not.toBeNull();
|
||||
expect(
|
||||
within(details as HTMLElement).getByText(
|
||||
'Review details (sensitive values hidden)'
|
||||
)
|
||||
).toBeInTheDocument();
|
||||
expect(details).toHaveTextContent('rm -rf build');
|
||||
});
|
||||
|
||||
it('keeps a failed approval decision visible without restoring technical context', () => {
|
||||
render(
|
||||
<HumanDecisionCard
|
||||
requestKey="run:approval-error"
|
||||
variant={{
|
||||
...approval(vi.fn()),
|
||||
header: { eyebrow: 'Input required', title: 'Run shell_exec?' },
|
||||
error: 'Approval could not be submitted.',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('alert')).toHaveTextContent(
|
||||
'Approval could not be submitted.'
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps question editing and Enter submission active, with blank answers disabled', () => {
|
||||
const onChange = vi.fn();
|
||||
const onSubmit = vi.fn();
|
||||
const variant = {
|
||||
kind: 'feedback' as const,
|
||||
presentation: 'question' as const,
|
||||
header: {
|
||||
title: 'Question',
|
||||
description: 'Which format would you like?',
|
||||
},
|
||||
value: 'A concise report',
|
||||
onChange,
|
||||
onSubmit,
|
||||
};
|
||||
const { rerender } = render(
|
||||
<HumanDecisionCard requestKey="run:question-1" variant={variant} />
|
||||
);
|
||||
const answer = screen.getByRole('textbox', { name: 'Feedback' });
|
||||
fireEvent.change(answer, { target: { value: 'A detailed report' } });
|
||||
expect(onChange).toHaveBeenCalledWith('A detailed report');
|
||||
fireEvent.keyDown(answer, { key: 'Enter', shiftKey: true });
|
||||
expect(onSubmit).not.toHaveBeenCalled();
|
||||
fireEvent.keyDown(answer, { key: 'Enter' });
|
||||
expect(onSubmit).toHaveBeenCalledOnce();
|
||||
rerender(
|
||||
<HumanDecisionCard
|
||||
requestKey="run:question-1"
|
||||
variant={{ ...variant, value: ' ' }}
|
||||
/>
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Send feedback' })
|
||||
).toBeDisabled();
|
||||
fireEvent.keyDown(answer, { key: 'Enter' });
|
||||
expect(onSubmit).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('requires a separate review action for a successor after the first request settles', () => {
|
||||
const first = vi.fn();
|
||||
const second = vi.fn();
|
||||
const { rerender } = render(
|
||||
<HumanDecisionCard requestKey="run:request-1" variant={approval(first)} />
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Approve once' }));
|
||||
expect(first).toHaveBeenCalledOnce();
|
||||
|
||||
rerender(<HumanDecisionCard requestKey={null} variant={null} />);
|
||||
rerender(
|
||||
<HumanDecisionCard
|
||||
requestKey="run:request-2"
|
||||
variant={approval(second)}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByRole('button', { name: 'Approve once' })).toBeNull();
|
||||
fireEvent.click(
|
||||
screen.getByRole('button', { name: 'Review next request' })
|
||||
);
|
||||
expect(second).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Approve once' }));
|
||||
expect(second).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
66
test/unit/components/ui/textarea.test.tsx
Normal file
66
test/unit/components/ui/textarea.test.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const NONE_CLASSES =
|
||||
'flex min-h-[4rem] w-full [scrollbar-gutter:stable] rounded-ds-field border border-x border-y border-ds-hairline-default-default bg-transparent py-2 pr-3 pl-3 text-ds-text-base shadow-sm placeholder:text-ds-ink-muted-default focus-visible:ring-2 focus-visible:ring-ds-ring-focus focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50';
|
||||
|
||||
describe('Textarea variants', () => {
|
||||
it('renders plain without an inner frame and with the shared focus ring', () => {
|
||||
render(<Textarea aria-label="Answer" variant="plain" size="sm" />);
|
||||
const textarea = screen.getByRole('textbox', { name: 'Answer' });
|
||||
|
||||
expect(textarea).toHaveClass(
|
||||
'p-0',
|
||||
'border-0',
|
||||
'shadow-none',
|
||||
'bg-transparent',
|
||||
'rounded-ds-field',
|
||||
'min-h-[var(--ds-textarea-sm-min-height)]',
|
||||
'outline-none',
|
||||
'focus-visible:ring-2',
|
||||
'focus-visible:ring-ds-ring-focus',
|
||||
'focus-visible:ring-offset-2'
|
||||
);
|
||||
expect(textarea).not.toHaveClass(
|
||||
'py-2',
|
||||
'pl-3',
|
||||
'pr-3',
|
||||
'border',
|
||||
'border-ds-hairline-default-default',
|
||||
'shadow-sm'
|
||||
);
|
||||
expect(textarea.style.paddingRight).toBe('');
|
||||
});
|
||||
|
||||
it('uses the default textarea min-height token for plain at the default size', () => {
|
||||
render(<Textarea aria-label="Answer" variant="plain" />);
|
||||
|
||||
expect(screen.getByRole('textbox', { name: 'Answer' })).toHaveClass(
|
||||
'min-h-[var(--ds-textarea-md-min-height)]'
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the none variant classes and padding unchanged', () => {
|
||||
render(<Textarea aria-label="Notes" />);
|
||||
const textarea = screen.getByRole('textbox', { name: 'Notes' });
|
||||
|
||||
expect(textarea).toHaveAttribute('class', cn(NONE_CLASSES));
|
||||
expect(textarea.style.paddingRight).toBe('4px');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue