mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🎛️ refactor: Move Composer Leaf Controls and Steering Into the Chat Package (#17521)
This commit is contained in:
parent
0bcb0aaec1
commit
cb92a34d76
58 changed files with 345 additions and 106 deletions
|
|
@ -5,19 +5,22 @@ import { useForm } from 'react-hook-form';
|
|||
import { Spinner } from '@librechat/client';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { Constants, buildTree } from 'librechat-data-provider';
|
||||
import { submissionByIndex, ComposerRestoreProvider } from '@librechat/chat/react';
|
||||
import { QueuedTurnPortalProvider } from '@librechat/chat/components';
|
||||
import {
|
||||
submissionByIndex,
|
||||
ComposerRestoreProvider,
|
||||
composerLiftFamily,
|
||||
} from '@librechat/chat/react';
|
||||
import type { TChatProject, TMessage } from 'librechat-data-provider';
|
||||
import type { ChatFormValues } from '~/common';
|
||||
import { AddedChatContext, ChatFormProvider, useChatContext, useFileMapContext } from '~/Providers';
|
||||
import { useScrollbarGutterSeed, useAddedResponse, useLocalize } from '~/hooks';
|
||||
import Footer, { useLandingFooter, useConfiguredFooter } from './Footer';
|
||||
import { QueuedTurnPortalProvider } from './Steering/QueuedTurnPortal';
|
||||
import { useChatSettings } from '~/Providers/ChatSettingsContext';
|
||||
import ApprovalProvider from './Messages/Content/ApprovalContext';
|
||||
import ConversationStarters from './Input/ConversationStarters';
|
||||
import { pendingApprovalActionFamily } from './approval/state';
|
||||
import ProjectBadge from '~/components/Projects/ProjectBadge';
|
||||
import { composerLiftFamily } from './Input/Composer/state';
|
||||
import { ChatSessionProvider } from '~/hooks/Chat/provider';
|
||||
import { OwnerTextProvider } from './Messages/PrivateText';
|
||||
import { AskAnswerHostProvider } from './ask/state';
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { memo, useCallback, useEffect, useRef } from 'react';
|
||||
import { useWatch } from 'react-hook-form';
|
||||
import { Button, TooltipAnchor } from '@librechat/client';
|
||||
import { useComposerOverlay } from '@librechat/chat/react';
|
||||
import { ChevronDown, CornerDownLeft, TriangleAlert } from 'lucide-react';
|
||||
import AskUserQuestions from '~/components/Chat/Messages/Content/AskUserQuestions';
|
||||
import useAskAnswerMode from '~/hooks/Input/useAskAnswerMode';
|
||||
import AskOptions from '~/components/Chat/ask/options';
|
||||
import { useChatFormContext } from '~/Providers';
|
||||
import { isCancelKey } from '~/utils/shortcuts';
|
||||
import { useComposerOverlay } from './overlay';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@ import { useAtom, useAtomValue } from 'jotai';
|
|||
import { useNavigate } from 'react-router-dom';
|
||||
import { useDirection } from '@radix-ui/react-direction';
|
||||
import { useSteering, showStopButtonByIndex, useComposerRestoreHost } from '@librechat/chat/react';
|
||||
import {
|
||||
submitFromComposer,
|
||||
composerClearance,
|
||||
CollapseChat,
|
||||
StopButton,
|
||||
} from '@librechat/chat/components';
|
||||
import {
|
||||
composerSurfaceClasses,
|
||||
composerSurfaceShadow,
|
||||
|
|
@ -74,16 +80,12 @@ import CodeWorkspaceMenu from './CodeWorkspaceMenu';
|
|||
import CodeApprovalMenu from './CodeApprovalMenu';
|
||||
import TextareaHeader from './TextareaHeader';
|
||||
import PromptsCommand from './PromptsCommand';
|
||||
import { submitFromComposer } from './submit';
|
||||
import SkillsCommand from './SkillsCommand';
|
||||
import AutoPlayAudio from './AutoPlayAudio';
|
||||
import composerClearance from './clearance';
|
||||
import Waveform from './Composer/Waveform';
|
||||
import { mainTextareaId } from '~/common';
|
||||
import CollapseChat from './CollapseChat';
|
||||
import QuoteButton from './QuoteButton';
|
||||
import ToolDialogs from './ToolDialogs';
|
||||
import StopButton from './StopButton';
|
||||
import SendButton from './SendButton';
|
||||
import Queue from './Composer/Queue';
|
||||
import Tray from './Composer/Tray';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React, { memo, useMemo, useState, useCallback } from 'react';
|
||||
import * as Ariakit from '@ariakit/react';
|
||||
import { ComposerChip as Chip } from '@librechat/chat/components';
|
||||
import { Mic, Plus, Check, Square, ChevronDown } from 'lucide-react';
|
||||
import { IconButton, TooltipAnchor, SendIcon } from '@librechat/client';
|
||||
import type { TConversation, EModelEndpoint, EndpointFileConfig } from 'librechat-data-provider';
|
||||
|
|
@ -17,7 +18,6 @@ import { useLocalize } from '~/hooks';
|
|||
import Thinking from './Thinking';
|
||||
import Palette from './Palette';
|
||||
import { cn } from '~/utils';
|
||||
import Chip from './Chip';
|
||||
|
||||
/** Stable identity so the memo below is not defeated when tools are hidden. */
|
||||
const EMPTY_ENTRIES: PaletteEntry[] = [];
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import React, {
|
|||
import { useSetAtom } from 'jotai';
|
||||
import * as Ariakit from '@ariakit/react';
|
||||
import { AutoSizer, List } from 'react-virtualized';
|
||||
import { composerLiftFamily } from '@librechat/chat/react';
|
||||
import { Star, Plus, Search, ChevronDown } from 'lucide-react';
|
||||
import { Button, FileUpload, IconButton, TooltipAnchor, useMediaQuery } from '@librechat/client';
|
||||
import type {
|
||||
|
|
@ -34,7 +35,6 @@ import useAttachItems from '~/hooks/Input/useAttachItems';
|
|||
import { useMCPRefresh } from '~/hooks/MCP/useMCPRefresh';
|
||||
import { isMacPlatform } from '~/utils/shortcuts';
|
||||
import { useBadgeRowContext } from '~/Providers';
|
||||
import { composerLiftFamily } from './state';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import Catalog from './Catalog';
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { createPortal } from 'react-dom';
|
|||
import * as Ariakit from '@ariakit/react';
|
||||
import { useDrag, useDrop } from 'react-dnd';
|
||||
import { queuedMessagesByConvoId } from '@librechat/chat/react';
|
||||
import { useQueuedTurnPortal } from '@librechat/chat/components';
|
||||
import { AnimatePresence, motion, useReducedMotion } from 'framer-motion';
|
||||
import { claimQueuedIntent, releaseQueuedIntent, hasQueuedIntent } from '@librechat/chat';
|
||||
import {
|
||||
|
|
@ -35,7 +36,6 @@ import type { RestoreToComposer } from '@librechat/chat/react';
|
|||
import type { SteeringControls } from '@librechat/chat/react';
|
||||
import type { MenuItemProps } from '@librechat/client';
|
||||
import type { QueuedMessage } from '@librechat/chat';
|
||||
import { useQueuedTurnPortal } from '~/components/Chat/Steering/QueuedTurnPortal';
|
||||
import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { memo, useCallback, useEffect, useRef } from 'react';
|
||||
import { TextQuote, WandSparkles } from 'lucide-react';
|
||||
import { ComposerChip as Chip } from '@librechat/chat/components';
|
||||
import type { TConversation } from 'librechat-data-provider';
|
||||
import type { ComposerItem, ComposerItemKind } from '~/hooks/Input/useComposerItems';
|
||||
import type { ExtendedFile, FileSetter } from '~/common';
|
||||
import { useFileHandlingNoChatContext, useLocalize } from '~/hooks';
|
||||
import FileRow from '../Files/FileRow';
|
||||
import Chip from './Chip';
|
||||
|
||||
const KIND_ICON: Record<ComposerItemKind, JSX.Element> = {
|
||||
quote: <TextQuote className="h-4 w-4" aria-hidden="true" />,
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ import React from 'react';
|
|||
import { RecoilRoot } from 'recoil';
|
||||
import { getDefaultStore } from 'jotai';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { composerLiftFamily } from '@librechat/chat/react';
|
||||
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
|
||||
import type { TConversation } from 'librechat-data-provider';
|
||||
import type { PaletteEntry } from '~/hooks/Input/usePaletteEntries';
|
||||
import type { AttachEntry } from '~/hooks/Input/useAttachItems';
|
||||
import { composerLiftFamily } from '../state';
|
||||
import Palette from '../Palette';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,12 +8,9 @@ import { hasQueuedIntent, releaseQueuedIntent } from '@librechat/chat';
|
|||
import { queuedMessagesByConvoId, resetQueueFamilies } from '@librechat/chat/react';
|
||||
import { revealedQueuedTurnFamily, resetSteerFamilies } from '@librechat/chat/react';
|
||||
import { act, render, screen, within, waitFor, fireEvent } from '@testing-library/react';
|
||||
import { QueuedTurnPortalProvider, useQueuedTurnPortal } from '@librechat/chat/components';
|
||||
import type { SteeringControls } from '@librechat/chat/react';
|
||||
import type { QueuedMessage } from '@librechat/chat';
|
||||
import {
|
||||
QueuedTurnPortalProvider,
|
||||
useQueuedTurnPortal,
|
||||
} from '~/components/Chat/Steering/QueuedTurnPortal';
|
||||
import Queue from '../Queue';
|
||||
jest.mock('~/hooks', () => ({
|
||||
useLocalize: () => (key: string, options?: Record<string, string | number>) => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,12 @@ const collectSourceModules = (directory: string): string[] =>
|
|||
return entry.isFile() && /\.tsx?$/.test(entry.name) ? [sourcePath] : [];
|
||||
});
|
||||
|
||||
const composerModules = collectSourceModules(composerRoot);
|
||||
const composerModules = [
|
||||
...collectSourceModules(composerRoot),
|
||||
...collectSourceModules(
|
||||
join(__dirname, '../../../../../../../packages/chat/src/components/composer'),
|
||||
),
|
||||
];
|
||||
|
||||
const protectedModules = [
|
||||
...composerModules,
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
import { atom } from 'jotai';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
|
||||
/** Landing-page lift is composer-owned UI state, scoped to its split pane. */
|
||||
export const composerLiftFamily = atomFamily((_index: number) => atom(0));
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { memo, useState, useRef, useEffect } from 'react';
|
||||
import { AutoSizer, List } from 'react-virtualized';
|
||||
import { EModelEndpoint } from 'librechat-data-provider';
|
||||
import { MentionItem } from '@librechat/chat/components';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { Input, Spinner, useCombobox, useRemScale } from '@librechat/client';
|
||||
import type { RecoilState } from 'recoil';
|
||||
|
|
@ -11,7 +12,6 @@ import useSelectMention from '~/hooks/Input/useSelectMention';
|
|||
import { useAssistantsMapContext } from '~/Providers';
|
||||
import useMentions from '~/hooks/Input/useMentions';
|
||||
import { removeCharIfLast } from '~/utils';
|
||||
import MentionItem from './MentionItem';
|
||||
|
||||
const ROW_HEIGHT = 44;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useState, useRef, useEffect, useMemo, memo, useCallback } from 'react';
|
||||
import { AutoSizer, List } from 'react-virtualized';
|
||||
import { MentionItem } from '@librechat/chat/components';
|
||||
import { useSetRecoilState, useRecoilValue } from 'recoil';
|
||||
import { Input, Spinner, useCombobox, useRemScale, useToastContext } from '@librechat/client';
|
||||
import type { TPromptGroup } from 'librechat-data-provider';
|
||||
|
|
@ -16,7 +17,6 @@ import useInitPopoverInput from '~/hooks/Input/useInitPopoverInput';
|
|||
import { useRecordPromptUsage } from '~/data-provider';
|
||||
import { VariableDialog } from '~/components/Prompts';
|
||||
import { usePromptGroupsContext } from '~/Providers';
|
||||
import MentionItem from './MentionItem';
|
||||
import store from '~/store';
|
||||
|
||||
const commandChar = '/';
|
||||
|
|
|
|||
|
|
@ -3,19 +3,18 @@ import { ScrollText } from 'lucide-react';
|
|||
import { useSetRecoilState } from 'recoil';
|
||||
import { useSetAtom, useAtomValue } from 'jotai';
|
||||
import { AutoSizer, List } from 'react-virtualized';
|
||||
import { pendingManualSkillsByConvoId } from '@librechat/chat/react';
|
||||
import { MentionItem } from '@librechat/chat/components';
|
||||
import { Input, Spinner, useCombobox, useRemScale } from '@librechat/client';
|
||||
import { SkillsScope, resolveAgentSkillsScope } from 'librechat-data-provider';
|
||||
import { pendingManualSkillsByConvoId, showSkillsPopoverFamily } from '@librechat/chat/react';
|
||||
import type { TSkillSummary } from 'librechat-data-provider';
|
||||
import type { MentionOption } from '~/common';
|
||||
import useInitPopoverInput from '~/hooks/Input/useInitPopoverInput';
|
||||
import { useLocalize, useSkillActiveState } from '~/hooks';
|
||||
import { useSkillsInfiniteQuery } from '~/data-provider';
|
||||
import { showSkillsPopoverFamily } from './skillsState';
|
||||
import { useAgentsMapContext } from '~/Providers';
|
||||
import { ephemeralAgentByConvoId } from '~/store';
|
||||
import { isEphemeralAgent } from '~/common';
|
||||
import MentionItem from './MentionItem';
|
||||
|
||||
const commandChar = '$';
|
||||
const ROW_HEIGHT = 44;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ jest.mock('~/components/Chat/Messages/Content/ApprovalContext', () => ({
|
|||
useResumeSubmit: () => ({ submitAskAnswer: jest.fn() }),
|
||||
}));
|
||||
|
||||
jest.mock('../overlay', () => ({
|
||||
jest.mock('@librechat/chat/react', () => ({
|
||||
...jest.requireActual('@librechat/chat/react'),
|
||||
useComposerOverlay: jest.fn(),
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@ import { EModelEndpoint } from 'librechat-data-provider';
|
|||
import { act, render, screen } from '@testing-library/react';
|
||||
import { Provider as JotaiProvider, createStore } from 'jotai';
|
||||
import { revealedQueuedTurnFamily } from '@librechat/chat/react';
|
||||
import { QueuedTurnPortalProvider, useQueuedTurnPortal } from '@librechat/chat/components';
|
||||
import type { TConversation } from 'librechat-data-provider';
|
||||
import {
|
||||
QueuedTurnPortalProvider,
|
||||
useQueuedTurnPortal,
|
||||
} from '~/components/Chat/Steering/QueuedTurnPortal';
|
||||
import PendingTurn from '~/components/Chat/Messages/PendingTurn';
|
||||
import { ChatContext } from '~/Providers';
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,6 @@ jest.mock('jotai', () => ({
|
|||
jest.mock('@librechat/chat/react', () => ({
|
||||
...jest.requireActual('@librechat/chat/react'),
|
||||
pendingManualSkillsByConvoId: () => 'pending-manual-skills',
|
||||
}));
|
||||
|
||||
jest.mock('../skillsState', () => ({
|
||||
showSkillsPopoverFamily: () => 'show-skills-popover',
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
import { join } from 'node:path';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
|
||||
const inputRoot = join(__dirname, '..');
|
||||
const source = (file: string): string => readFileSync(join(inputRoot, file), 'utf8');
|
||||
const packageRoot = join(__dirname, '../../../../../../packages/chat/src/components/composer');
|
||||
/** Composer modules live in `@librechat/chat` once they move; the rest are still app-side. */
|
||||
const source = (file: string): string => {
|
||||
const moved = join(packageRoot, file);
|
||||
return readFileSync(existsSync(moved) ? moved : join(inputRoot, file), 'utf8');
|
||||
};
|
||||
|
||||
/** Send and stop take the slot's recipe from IconButton's `submit` variant,
|
||||
* which is built from `composerSubmitClasses()`. */
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ const PACKAGE_PANELS = [
|
|||
'MultiSelect.tsx',
|
||||
];
|
||||
const COMPONENTS_DIR = path.resolve(CHAT_DIR, '..');
|
||||
const CHAT_PACKAGE_COMPONENTS = path.resolve(
|
||||
__dirname,
|
||||
'../../../../../../packages/chat/src/components',
|
||||
);
|
||||
const CLIENT_PANELS = [
|
||||
'ui/LocalizedDateRangePicker.tsx',
|
||||
'Nav/AccountSettings.tsx',
|
||||
|
|
@ -45,6 +49,7 @@ function sourcesUnder(dir: string): string[] {
|
|||
describe('menu, popover and picker panels', () => {
|
||||
const files = [
|
||||
...SCAN_DIRS.flatMap((dir) => sourcesUnder(path.join(CHAT_DIR, dir))),
|
||||
...sourcesUnder(CHAT_PACKAGE_COMPONENTS),
|
||||
...PACKAGE_PANELS.map((file) => path.join(PACKAGE_COMPONENTS, file)),
|
||||
...CLIENT_PANELS.map((file) => path.join(COMPONENTS_DIR, file)),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
import { atom } from 'jotai';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
|
||||
export const showSkillsPopoverFamily = atomFamily((_index: string | number | null) => atom(false));
|
||||
|
|
@ -11,7 +11,7 @@ import {
|
|||
useSteerEscalate,
|
||||
useSteerRecovery,
|
||||
} from '@librechat/chat/react';
|
||||
import type { SteerReceiptState } from '~/components/Chat/Steering/Receipt';
|
||||
import type { SteerReceiptState } from '@librechat/chat/components';
|
||||
import { getMessageRowWidthClass } from '~/components/Chat/Messages/ui/width';
|
||||
import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { memo, useMemo, useState, useEffect, useCallback } from 'react';
|
||||
import { CollapsibleText } from '@librechat/chat/components';
|
||||
import { SteerReceipt, CollapsibleText } from '@librechat/chat/components';
|
||||
import type { SteerReceiptState } from '@librechat/chat/components';
|
||||
import type { TFile, TMessage } from 'librechat-data-provider';
|
||||
import SteerReceipt, { type SteerReceiptState } from '~/components/Chat/Steering/Receipt';
|
||||
import FilePreviewDialog from '~/components/Chat/Messages/Content/FilePreviewDialog';
|
||||
import MessageTimestamp from '~/components/Chat/Messages/ui/MessageTimestamp';
|
||||
import MessageQuotes from '~/components/Chat/Messages/Content/MessageQuotes';
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const mockShowToast = jest.fn();
|
|||
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize: () => (key: string) => key,
|
||||
useToastContext: () => ({ showToast: mockShowToast }),
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { QueryKeys } from 'librechat-data-provider';
|
||||
import { STEER_ICON } from '@librechat/chat/components';
|
||||
import { Provider, createStore, useAtomValue } from 'jotai';
|
||||
import { liveAppliedSteerIdsAtom } from '@librechat/chat/react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import { STEER_ICON } from '~/components/Chat/Steering/identity';
|
||||
import SteerPart from '../SteerPart';
|
||||
import store from '~/store';
|
||||
|
||||
let mockShareContext: { isSharedConvo?: boolean; shareId?: string } = {};
|
||||
let mockFileMap: Record<string, { llmDeliveryPath?: 'provider' | 'text' | 'none' }> = {};
|
||||
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize: () => (key: string) => key,
|
||||
}));
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
useLocalize: () => (key: string) => key,
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { useQueuedTurnPortal } from '@librechat/chat/components';
|
||||
import {
|
||||
hasRevealSuccessor,
|
||||
buildRevealedMessage,
|
||||
|
|
@ -9,7 +10,6 @@ import {
|
|||
import type { TMessage } from 'librechat-data-provider';
|
||||
import type { RefObject } from 'react';
|
||||
import type { TMessageIcon } from '~/common';
|
||||
import { useQueuedTurnPortal } from '~/components/Chat/Steering/QueuedTurnPortal';
|
||||
import { getHeaderPrefixForScreenReader, getMessageAriaLabel } from '~/utils';
|
||||
import { messageFooterClasses } from '~/components/Chat/Messages/styles';
|
||||
import MessageRow from '~/components/Chat/Messages/ui/MessageRow';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { memo, useState, useRef, useEffect } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import { composerOverlayCountFamily } from '~/components/Chat/Input/overlay';
|
||||
import { composerOverlayCountFamily } from '@librechat/chat/react';
|
||||
import ScrollToBottom from '~/components/Messages/ScrollToBottom';
|
||||
|
||||
const intersectionThreshold = 0.85;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import { Provider, createStore } from 'jotai';
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import { composerOverlayCountFamily } from '~/components/Chat/Input/overlay';
|
||||
import { composerOverlayCountFamily } from '@librechat/chat/react';
|
||||
import ScrollButton from '../ScrollButton';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import Receipt from '../Receipt';
|
||||
import { SteerReceipt as Receipt } from '@librechat/chat/components';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize: () => (key: string) => {
|
||||
const english: Record<string, string> = jest.requireActual('~/locales/en/translation.json');
|
||||
return english[key] ?? key;
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@librechat/client', () => ({
|
||||
ESide: { Top: 'top' },
|
||||
InfoHoverCard: ({ text, children }: { text: string; children: React.ReactNode }) => (
|
||||
<span aria-label={text}>{children}</span>
|
||||
),
|
||||
|
|
|
|||
|
|
@ -224,9 +224,9 @@ jest.mock('~/components/Chat/Messages/Content/ToolApproval', () => ({
|
|||
default: () => <div data-testid="tool-approval">approval</div>,
|
||||
}));
|
||||
|
||||
jest.mock('~/components/Chat/Steering/Receipt', () => ({
|
||||
__esModule: true,
|
||||
default: ({ state }: { state: string }) => (
|
||||
jest.mock('@librechat/chat/components', () => ({
|
||||
...jest.requireActual('@librechat/chat/components'),
|
||||
SteerReceipt: ({ state }: { state: string }) => (
|
||||
<span data-testid="steer-receipt" data-receipt-state={state} />
|
||||
),
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import { Maximize2, Minimize2 } from 'lucide-react';
|
|||
import { CSSTransition } from 'react-transition-group';
|
||||
import { ContentTypes, QueryKeys, dataService } from 'librechat-data-provider';
|
||||
import type { SearchResultData, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { SteerReceiptState } from '@librechat/chat/components';
|
||||
import type { ToolContentQuery } from '~/components/Chat/Messages/Content/disclosure';
|
||||
import type { SteerReceiptState } from '~/components/Chat/Steering/Receipt';
|
||||
import type { TaskContentScope } from '~/data-provider/Subagents/content';
|
||||
import type { ChildActivity, ChildActivityItem } from './adapters';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { memo, useEffect, useMemo } from 'react';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { Button, TooltipAnchor } from '@librechat/client';
|
||||
import { useComposerOverlay } from '@librechat/chat/react';
|
||||
import { ChevronDown, ChevronUp, ShieldQuestion, TriangleAlert } from 'lucide-react';
|
||||
import type { Agents } from 'librechat-data-provider';
|
||||
import type { KeyboardEvent, RefObject } from 'react';
|
||||
|
|
@ -15,7 +16,6 @@ import {
|
|||
} from '~/components/Chat/approval/state';
|
||||
import { buildApprovalPreview, buildApprovalPreviews } from '~/components/Chat/approval/preview';
|
||||
import ToolApproval from '~/components/Chat/Messages/Content/ToolApproval';
|
||||
import { useComposerOverlay } from '~/components/Chat/Input/overlay';
|
||||
import { isCancelKey } from '~/utils/shortcuts';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import React from 'react';
|
|||
import { RecoilRoot } from 'recoil';
|
||||
import { Provider as JotaiProvider, createStore } from 'jotai';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { composerOverlayCountFamily } from '@librechat/chat/react';
|
||||
import type { Agents } from 'librechat-data-provider';
|
||||
import { PendingToolApprovalButton, PendingToolApprovalPanel } from '../Review';
|
||||
import { composerOverlayCountFamily } from '~/components/Chat/Input/overlay';
|
||||
import ApprovalProvider from '../../Messages/Content/ApprovalContext';
|
||||
import { pendingApprovalActionFamily } from '../state';
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ import {
|
|||
showStopButtonByIndex,
|
||||
submissionStartFamily,
|
||||
useClearSubmissions,
|
||||
showSkillsPopoverFamily,
|
||||
} from '@librechat/chat/react';
|
||||
import { siblingIdxFamily, siblingKey } from '~/components/Chat/Messages/Thread/state';
|
||||
import { showFilesDialogAtom, filesDialogTriggerAtom } from '~/store/filesDialog';
|
||||
import { showSkillsPopoverFamily } from '~/components/Chat/Input/skillsState';
|
||||
import { clearLocalStorage } from '~/utils/localStorage';
|
||||
import { activeRunFamily } from '~/hooks/SSE/atoms';
|
||||
import store from '~/store';
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ jest.mock('jotai', () => ({
|
|||
),
|
||||
}));
|
||||
|
||||
jest.mock('~/components/Chat/Input/skillsState', () => ({
|
||||
jest.mock('@librechat/chat/react', () => ({
|
||||
...jest.requireActual('@librechat/chat/react'),
|
||||
showSkillsPopoverFamily: (idx: number) => `showSkillsPopoverFamily-${idx}`,
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useSetRecoilState, useRecoilValue } from 'recoil';
|
||||
import { showSkillsPopoverFamily } from '@librechat/chat/react';
|
||||
import { PermissionTypes, Permissions, isAssistantsEndpoint } from 'librechat-data-provider';
|
||||
import { showSkillsPopoverFamily } from '~/components/Chat/Input/skillsState';
|
||||
import { useGetLatestMessage } from '~/hooks/Messages/useLatestMessage';
|
||||
import useAgentCapabilities from '~/hooks/Agents/useAgentCapabilities';
|
||||
import useGetAgentsConfig from '~/hooks/Agents/useGetAgentsConfig';
|
||||
|
|
|
|||
8
packages/chat/components.json
Normal file
8
packages/chat/components.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"tailwind": {
|
||||
"css": "../client/src/theme/theme.css"
|
||||
},
|
||||
"aliases": {
|
||||
"ui": "@librechat/client"
|
||||
}
|
||||
}
|
||||
|
|
@ -15,3 +15,21 @@ export type {
|
|||
PartRenderProps,
|
||||
ToolRenderProps,
|
||||
} from './components/Part';
|
||||
|
||||
/** Composer: the chat input, its controls and the steering queue. */
|
||||
export { default as StopButton } from './components/composer/StopButton';
|
||||
export { default as MentionItem } from './components/composer/MentionItem';
|
||||
export { default as CollapseChat } from './components/composer/CollapseChat';
|
||||
export { default as ComposerChip } from './components/composer/bar/Chip';
|
||||
export { default as composerClearance } from './components/composer/clearance';
|
||||
export { default as SteerReceipt } from './components/composer/steering/Receipt';
|
||||
export { submitFromComposer } from './components/composer/submit';
|
||||
export { STEER_DOT, STEER_ICON, QUEUE_ICON } from './components/composer/steering/identity';
|
||||
export {
|
||||
useQueuedTurnPortal,
|
||||
QueuedTurnPortalProvider,
|
||||
} from './components/composer/steering/QueuedTurnPortal';
|
||||
export type { ComposerSubmitRoute } from './components/composer/submit';
|
||||
export type { MentionItemProps } from './components/composer/MentionItem';
|
||||
export type { ChipProps as ComposerChipProps } from './components/composer/bar/Chip';
|
||||
export type { SteerReceiptState } from './components/composer/steering/Receipt';
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
import React from 'react';
|
||||
import { ChevronDown, ChevronUp } from 'lucide';
|
||||
import { MorphIcon, TooltipAnchor } from '@librechat/client';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
import { cn, MorphIcon, useLocalize, TooltipAnchor } from '@librechat/client';
|
||||
import type { NamedExoticComponent } from 'react';
|
||||
|
||||
type CollapseChatProps = {
|
||||
isScrollable: boolean;
|
||||
isCollapsed: boolean;
|
||||
setIsCollapsed: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
};
|
||||
|
||||
const CollapseChat = ({
|
||||
isScrollable,
|
||||
isCollapsed,
|
||||
setIsCollapsed,
|
||||
}: {
|
||||
isScrollable: boolean;
|
||||
isCollapsed: boolean;
|
||||
setIsCollapsed: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}) => {
|
||||
}: CollapseChatProps): React.JSX.Element | null => {
|
||||
const localize = useLocalize();
|
||||
if (!isScrollable) {
|
||||
return null;
|
||||
|
|
@ -48,4 +49,6 @@ const CollapseChat = ({
|
|||
);
|
||||
};
|
||||
|
||||
export default React.memo(CollapseChat);
|
||||
const MemoCollapseChat: NamedExoticComponent<CollapseChatProps> = React.memo(CollapseChat);
|
||||
|
||||
export default MemoCollapseChat;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Clock4 } from 'lucide-react';
|
||||
import { cn } from '~/utils';
|
||||
import { cn } from '@librechat/client';
|
||||
|
||||
export interface MentionItemProps {
|
||||
name: string;
|
||||
|
|
@ -22,7 +22,7 @@ export default function MentionItem({
|
|||
description,
|
||||
style,
|
||||
type = 'mention',
|
||||
}: MentionItemProps) {
|
||||
}: MentionItemProps): React.JSX.Element {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
|
|
@ -1,13 +1,8 @@
|
|||
import { memo } from 'react';
|
||||
import { IconButton, TooltipAnchor } from '@librechat/client';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { IconButton, useLocalize, TooltipAnchor } from '@librechat/client';
|
||||
import type { NamedExoticComponent } from 'react';
|
||||
|
||||
export default memo(function StopButton({
|
||||
stop,
|
||||
setShowStopButton,
|
||||
canStop = true,
|
||||
hidden = false,
|
||||
}: {
|
||||
type StopButtonProps = {
|
||||
stop: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
||||
setShowStopButton: (value: boolean) => void;
|
||||
/** False while the abort would be a no-op (the generation epoch is not
|
||||
|
|
@ -20,7 +15,14 @@ export default memo(function StopButton({
|
|||
* types a steer is what made the shortcut reach into another pane or do
|
||||
* nothing at all, which is exactly when a hard stop is wanted. */
|
||||
hidden?: boolean;
|
||||
}) {
|
||||
};
|
||||
|
||||
const StopButton: NamedExoticComponent<StopButtonProps> = memo(function StopButton({
|
||||
stop,
|
||||
setShowStopButton,
|
||||
canStop = true,
|
||||
hidden = false,
|
||||
}: StopButtonProps) {
|
||||
const localize = useLocalize();
|
||||
|
||||
return (
|
||||
|
|
@ -60,3 +62,5 @@ export default memo(function StopButton({
|
|||
></TooltipAnchor>
|
||||
);
|
||||
});
|
||||
|
||||
export default StopButton;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import React from 'react';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import CollapseChat from '../CollapseChat';
|
||||
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize: () => (key: string) => key,
|
||||
}));
|
||||
|
||||
describe('CollapseChat', () => {
|
||||
it('renders nothing while the composer does not scroll', () => {
|
||||
const { container } = render(
|
||||
<CollapseChat isScrollable={false} isCollapsed={false} setIsCollapsed={jest.fn()} />,
|
||||
);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it('names the action it will take and toggles the collapsed state', () => {
|
||||
const setIsCollapsed = jest.fn();
|
||||
const { rerender } = render(
|
||||
<CollapseChat isScrollable isCollapsed={false} setIsCollapsed={setIsCollapsed} />,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_collapse_chat' }));
|
||||
const toggle = setIsCollapsed.mock.calls[0][0] as (prev: boolean) => boolean;
|
||||
expect(toggle(false)).toBe(true);
|
||||
|
||||
rerender(<CollapseChat isScrollable isCollapsed setIsCollapsed={setIsCollapsed} />);
|
||||
expect(screen.getByRole('button', { name: 'com_ui_expand_chat' })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import React from 'react';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import MentionItem from '../MentionItem';
|
||||
|
||||
describe('MentionItem', () => {
|
||||
it('renders the name and description and reports clicks', () => {
|
||||
const onClick = jest.fn();
|
||||
render(
|
||||
<MentionItem
|
||||
name="Writer"
|
||||
description="Drafts prose"
|
||||
index={2}
|
||||
type="skill"
|
||||
onClick={onClick}
|
||||
/>,
|
||||
);
|
||||
|
||||
const button = screen.getByRole('button', { name: /Writer/ });
|
||||
expect(button).toHaveAttribute('id', 'skill-item-2');
|
||||
expect(button).toHaveTextContent('Drafts prose');
|
||||
|
||||
fireEvent.click(button);
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('highlights the active row with the active surface role', () => {
|
||||
const { rerender } = render(<MentionItem name="Writer" index={0} onClick={jest.fn()} />);
|
||||
const row = () => screen.getByRole('button').firstElementChild;
|
||||
expect(row()).toHaveClass('bg-transparent');
|
||||
|
||||
rerender(<MentionItem name="Writer" index={0} isActive onClick={jest.fn()} />);
|
||||
expect(row()).toHaveClass('bg-surface-active');
|
||||
});
|
||||
});
|
||||
|
|
@ -1,7 +1,11 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import StopButton from '../StopButton';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize: () => (key: string) => key,
|
||||
}));
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { memo } from 'react';
|
||||
import { Chip as SharedChip } from '@librechat/client';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { ReactNode, NamedExoticComponent } from 'react';
|
||||
|
||||
export interface ChipProps {
|
||||
label: string;
|
||||
|
|
@ -24,7 +24,7 @@ function Chip({
|
|||
removeLabel,
|
||||
className,
|
||||
'data-testid': testId,
|
||||
}: ChipProps) {
|
||||
}: ChipProps): React.JSX.Element {
|
||||
return (
|
||||
<SharedChip
|
||||
role="listitem"
|
||||
|
|
@ -50,4 +50,6 @@ function Chip({
|
|||
);
|
||||
}
|
||||
|
||||
export default memo(Chip);
|
||||
const MemoChip: NamedExoticComponent<ChipProps> = memo(Chip);
|
||||
|
||||
export default MemoChip;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { ReactNode, JSX } from 'react';
|
||||
|
||||
type QueuedTurnTarget = {
|
||||
conversationId: string;
|
||||
|
|
@ -15,7 +15,7 @@ type QueuedTurnPortalContextValue = {
|
|||
const QueuedTurnPortalContext = createContext<QueuedTurnPortalContextValue | null>(null);
|
||||
|
||||
/** The composer owns queue actions; the transcript only supplies their mount point. */
|
||||
export function QueuedTurnPortalProvider({ children }: { children: ReactNode }) {
|
||||
export function QueuedTurnPortalProvider({ children }: { children: ReactNode }): JSX.Element {
|
||||
const [target, setTargetState] = useState<QueuedTurnTarget | null>(null);
|
||||
const setTarget = useCallback((next: QueuedTurnTarget | null) => {
|
||||
setTargetState((current) =>
|
||||
|
|
@ -32,4 +32,5 @@ export function QueuedTurnPortalProvider({ children }: { children: ReactNode })
|
|||
);
|
||||
}
|
||||
|
||||
export const useQueuedTurnPortal = () => useContext(QueuedTurnPortalContext);
|
||||
export const useQueuedTurnPortal = (): QueuedTurnPortalContextValue | null =>
|
||||
useContext(QueuedTurnPortalContext);
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
import { memo } from 'react';
|
||||
import { Check, CheckCheck } from 'lucide-react';
|
||||
import { InfoHoverCard, ESide } from '@librechat/client';
|
||||
import { cn, ESide, useLocalize, InfoHoverCard } from '@librechat/client';
|
||||
import type { NamedExoticComponent } from 'react';
|
||||
import { STEER_DOT, STEER_ICON } from './identity';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
export type SteerReceiptState = 'sending' | 'delivered' | 'interrupting' | 'applied';
|
||||
|
||||
|
|
@ -27,13 +26,7 @@ export type SteerReceiptState = 'sending' | 'delivered' | 'interrupting' | 'appl
|
|||
* The hover explanations render through the shared `InfoHoverCard` with the
|
||||
* receipt as the trigger, so the info text doubles as the accessible name.
|
||||
*/
|
||||
const SteerReceipt = memo(function SteerReceipt({
|
||||
state,
|
||||
live = false,
|
||||
confirmed = true,
|
||||
animateIn = false,
|
||||
className,
|
||||
}: {
|
||||
type SteerReceiptProps = {
|
||||
state: SteerReceiptState;
|
||||
/** Applied only: the owning response is still generating, so the receipt is
|
||||
* the newest thing on screen and keeps the steering identity color. Off
|
||||
|
|
@ -45,7 +38,15 @@ const SteerReceipt = memo(function SteerReceipt({
|
|||
/** Plays the one-shot draw-in at the live chip→inline hand-off only. */
|
||||
animateIn?: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
};
|
||||
|
||||
const SteerReceipt: NamedExoticComponent<SteerReceiptProps> = memo(function SteerReceipt({
|
||||
state,
|
||||
live = false,
|
||||
confirmed = true,
|
||||
animateIn = false,
|
||||
className,
|
||||
}: SteerReceiptProps) {
|
||||
const localize = useLocalize();
|
||||
|
||||
if (state === 'sending') {
|
||||
|
|
@ -53,7 +54,7 @@ const SteerReceipt = memo(function SteerReceipt({
|
|||
<span
|
||||
data-testid="steer-receipt"
|
||||
data-receipt-state="sending"
|
||||
className={cn('text-xs text-text-secondary', className)}
|
||||
className={cn('text-text-secondary text-xs', className)}
|
||||
>
|
||||
{localize('com_ui_steer_sending')}
|
||||
</span>
|
||||
|
|
@ -71,9 +72,9 @@ const SteerReceipt = memo(function SteerReceipt({
|
|||
<InfoHoverCard side={ESide.Top} text={localize('com_ui_steer_applied_info')}>
|
||||
<CheckCheck
|
||||
className={cn(
|
||||
'h-4 w-4 transition-colors duration-theme-normal motion-reduce:transition-none',
|
||||
'duration-theme-normal h-4 w-4 transition-colors motion-reduce:transition-none',
|
||||
live ? STEER_ICON : 'text-text-secondary',
|
||||
animateIn && 'ease-out animate-in fade-in-0 zoom-in-50 motion-reduce:animate-none',
|
||||
animateIn && 'animate-in fade-in-0 zoom-in-50 ease-out motion-reduce:animate-none',
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import React from 'react';
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { QueuedTurnPortalProvider, useQueuedTurnPortal } from '../QueuedTurnPortal';
|
||||
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<QueuedTurnPortalProvider>{children}</QueuedTurnPortalProvider>
|
||||
);
|
||||
|
||||
describe('QueuedTurnPortal', () => {
|
||||
it('is null outside a provider', () => {
|
||||
const { result } = renderHook(() => useQueuedTurnPortal());
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
|
||||
it('keeps the same target object when an identical mount point is set again', () => {
|
||||
const { result } = renderHook(() => useQueuedTurnPortal(), { wrapper });
|
||||
const element = document.createElement('span');
|
||||
|
||||
act(() => result.current?.setTarget({ conversationId: 'c1', clientRequestId: 'r1', element }));
|
||||
const first = result.current?.target;
|
||||
expect(first).toEqual({ conversationId: 'c1', clientRequestId: 'r1', element });
|
||||
|
||||
act(() => result.current?.setTarget({ conversationId: 'c1', clientRequestId: 'r1', element }));
|
||||
expect(result.current?.target).toBe(first);
|
||||
|
||||
act(() => result.current?.setTarget({ conversationId: 'c1', clientRequestId: 'r2', element }));
|
||||
expect(result.current?.target?.clientRequestId).toBe('r2');
|
||||
|
||||
act(() => result.current?.setTarget(null));
|
||||
expect(result.current?.target).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import SteerReceipt from '../Receipt';
|
||||
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize: () => (key: string) => key,
|
||||
InfoHoverCard: ({ text, children }: { text: string; children: React.ReactNode }) => (
|
||||
<span aria-label={text}>{children}</span>
|
||||
),
|
||||
}));
|
||||
|
||||
const receipt = () => screen.getByTestId('steer-receipt');
|
||||
|
||||
describe('SteerReceipt', () => {
|
||||
it('shows a plain sending label before the server accepts the steer', () => {
|
||||
render(<SteerReceipt state="sending" />);
|
||||
|
||||
expect(receipt()).toHaveAttribute('data-receipt-state', 'sending');
|
||||
expect(receipt()).toHaveTextContent('com_ui_steer_sending');
|
||||
expect(receipt().querySelector('svg')).toBeNull();
|
||||
});
|
||||
|
||||
it('marks an accepted steer as waiting, with its explanation as the label', () => {
|
||||
render(<SteerReceipt state="delivered" />);
|
||||
|
||||
expect(receipt()).toHaveTextContent('com_ui_steer_delivered');
|
||||
expect(screen.getByLabelText('com_ui_steer_delivered_info')).toBeInTheDocument();
|
||||
expect(receipt().querySelectorAll('svg')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('pulses the steer dot and holds the check until an interrupt is confirmed', () => {
|
||||
const { rerender } = render(<SteerReceipt state="interrupting" confirmed={false} />);
|
||||
|
||||
expect(receipt()).toHaveTextContent('com_ui_steer_in_flight_preempt');
|
||||
expect(screen.getByLabelText('com_ui_steer_interrupting_info')).toBeInTheDocument();
|
||||
expect(receipt().querySelector('.bg-status-warning')).not.toBeNull();
|
||||
expect(receipt().querySelector('svg')).toBeNull();
|
||||
|
||||
rerender(<SteerReceipt state="interrupting" confirmed />);
|
||||
expect(receipt().querySelector('svg')).toHaveClass('text-status-warning');
|
||||
});
|
||||
|
||||
it('keeps the steer color on an applied receipt only while its response is live', () => {
|
||||
const { rerender } = render(<SteerReceipt state="applied" live />);
|
||||
|
||||
expect(screen.getByLabelText('com_ui_steer_applied_info')).toBeInTheDocument();
|
||||
expect(receipt()).toHaveAttribute('data-receipt-live', 'true');
|
||||
expect(receipt().querySelector('svg')).toHaveClass('text-status-warning');
|
||||
|
||||
rerender(<SteerReceipt state="applied" />);
|
||||
expect(receipt()).not.toHaveAttribute('data-receipt-live');
|
||||
expect(receipt().querySelector('svg')).toHaveClass('text-text-secondary');
|
||||
});
|
||||
});
|
||||
|
|
@ -111,3 +111,6 @@ export {
|
|||
} from './react/steering/useQueuedTurnReveal';
|
||||
export { ReactQueryChatState } from './react/state';
|
||||
export type { ReactQueryChatStateOptions } from './react/state';
|
||||
export { composerLiftFamily } from './react/lift';
|
||||
export { showSkillsPopoverFamily } from './react/skills';
|
||||
export { useComposerOverlay, composerOverlayCountFamily } from './react/overlay';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import React from 'react';
|
||||
import { Provider, createStore } from 'jotai';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
9
packages/chat/src/react/lift.ts
Normal file
9
packages/chat/src/react/lift.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { atom } from 'jotai';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
import type { PrimitiveAtom } from 'jotai';
|
||||
import type { Family } from './steer/family';
|
||||
|
||||
/** Landing-page lift is composer-owned UI state, scoped to its split pane. */
|
||||
export const composerLiftFamily: Family<number, PrimitiveAtom<number>, number> = atomFamily(
|
||||
(_index: number) => atom(0),
|
||||
);
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { useEffect } from 'react';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
import { atom, useSetAtom } from 'jotai';
|
||||
import type { Family } from './steer/family';
|
||||
|
||||
/**
|
||||
* How many composer panels are open over the bottom of a conversation's
|
||||
|
|
@ -13,7 +14,9 @@ import { atom, useSetAtom } from 'jotai';
|
|||
* can never go stale; the family is never GC'd but holds one number per
|
||||
* visited conversation.
|
||||
*/
|
||||
export const composerOverlayCountFamily = atomFamily((_conversationId: string) => atom<number>(0));
|
||||
export const composerOverlayCountFamily: Family<number> = atomFamily((_conversationId: string) =>
|
||||
atom<number>(0),
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers a composer panel as open for `conversationId` while `open` holds.
|
||||
10
packages/chat/src/react/skills.ts
Normal file
10
packages/chat/src/react/skills.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { atom } from 'jotai';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
import type { PrimitiveAtom } from 'jotai';
|
||||
import type { Family } from './steer/family';
|
||||
|
||||
export const showSkillsPopoverFamily: Family<
|
||||
boolean,
|
||||
PrimitiveAtom<boolean>,
|
||||
string | number | null
|
||||
> = atomFamily((_index: string | number | null) => atom(false));
|
||||
Loading…
Add table
Add a link
Reference in a new issue