mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +00:00
🍂 refactor: Move Tool Disclosure State and Leaf Part Components Into the Chat Package (#17560)
* refactor: Move Tool Disclosure State and Leaf Part Components Into @librechat/chat Disclosure contexts and atoms, tool intent labels, useRowHandoff and useFollowScroll move to packages/chat/src/react/parts (exported from @librechat/chat/react); CancelledIcon, InProgressCall, AuthorHeader, Stdout, BareStatus and the row class constants move to packages/chat/src/components/parts (exported from @librechat/chat/components). Disclosure reads the package host, and ToolContentQuery is declared from data-provider and react-query types. The AuthorHeader and useFollowScroll specs move with their modules. * test: Cover the Author Header That Resumes After a Steer * test: Keep the Package Entry Intact When Mocking AuthorHeader
This commit is contained in:
parent
09a7d13eac
commit
dfa2b84eb7
76 changed files with 354 additions and 194 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { v4 } from 'uuid';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { getToolCallIntent } from '@librechat/chat/react';
|
||||
import { useQuery, useQueries } from '@tanstack/react-query';
|
||||
import { QueryKeys, dataService } from 'librechat-data-provider';
|
||||
import type { TMessage, ParentSubagentSummary } from 'librechat-data-provider';
|
||||
|
|
@ -19,7 +20,6 @@ import {
|
|||
useCancelBackgroundTasksMutation,
|
||||
} from '~/data-provider';
|
||||
import { useParentSubagents } from '~/components/Chat/Subagents/ParentSubagentsProvider';
|
||||
import { getToolCallIntent } from '~/components/Chat/Messages/Content/Parts/intent';
|
||||
|
||||
const noThreads: ReadonlyMap<string, ParentSubagentSummary> = new Map();
|
||||
const noRefresh = async () => undefined;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||
import { useTimeTick } from '@librechat/chat/react';
|
||||
import { ContentTypes } from 'librechat-data-provider';
|
||||
import { Check, CircleX, Lightbulb, ChevronDown, TriangleAlert } from 'lucide-react';
|
||||
import { FOLD_RAIL_CLASSES, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '@librechat/chat/components';
|
||||
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { CSSProperties, ReactNode } from 'react';
|
||||
import type { RailHover } from './rail';
|
||||
|
|
@ -30,7 +31,6 @@ import {
|
|||
FoldHeaderContext,
|
||||
} from './rail';
|
||||
import { FailedRevealContext, FailedRevealPill, useFailedRevealTrigger } from './reveal';
|
||||
import { FOLD_RAIL_CLASSES, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from './rows';
|
||||
import { getOutcomeStatus, isSpanFailed, summarizeSpan } from './outcome';
|
||||
import useSmoothStreaming from '~/hooks/Messages/useSmoothStreaming';
|
||||
import useThrottledValue from '~/hooks/Messages/useThrottledValue';
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import { ChevronDown } from 'lucide-react';
|
|||
import { Button } from '@librechat/client';
|
||||
import { unescapeJsonString } from '@librechat/chat';
|
||||
import { EModelEndpoint, Constants } from 'librechat-data-provider';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import {
|
||||
useToolContentRequest,
|
||||
useToolContentPending,
|
||||
toolPanelSpacingClassName,
|
||||
} from './disclosure';
|
||||
} from '@librechat/chat/react';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import MessageIcon from '~/components/Share/MessageIcon';
|
||||
import { useLocalize, useExpandCollapse } from '~/hooks';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useCallback } from 'react';
|
||||
import { EmptyText } from '@librechat/chat/components';
|
||||
import { useToolExpansion } from '@librechat/chat/react';
|
||||
import { MessageCircleQuestion, TriangleAlert } from 'lucide-react';
|
||||
import { EmptyText, TOOL_ROW_CLASSES } from '@librechat/chat/components';
|
||||
import type { Agents, PartMetadata } from 'librechat-data-provider';
|
||||
import {
|
||||
getSubmittedAskAnswer,
|
||||
|
|
@ -9,9 +10,7 @@ import {
|
|||
} from '~/utils/approval';
|
||||
import AskUserQuestionProgress from './AskUserQuestionProgress';
|
||||
import { useLocalize, useExpandCollapse } from '~/hooks';
|
||||
import { useToolExpansion } from './disclosure';
|
||||
import ProgressText from './ProgressText';
|
||||
import { TOOL_ROW_CLASSES } from './rows';
|
||||
import Container from './Container';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
import { X } from 'lucide-react';
|
||||
|
||||
export default function CancelledIcon() {
|
||||
return (
|
||||
<div className="flex h-full w-full items-center justify-center rounded-full bg-transparent text-text-secondary">
|
||||
<X className="size-4" aria-hidden="true" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Terminal } from 'lucide-react';
|
||||
import { useToolExpansion } from '@librechat/chat/react';
|
||||
import type { ToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import { useProgress, useLocalize } from '~/hooks';
|
||||
import { useToolExpansion } from './disclosure';
|
||||
import ProgressText from './ProgressText';
|
||||
import MarkdownLite from './MarkdownLite';
|
||||
import { cn } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
import { memo, useRef, useMemo, useEffect, useCallback, useContext, Fragment } from 'react';
|
||||
import { useStore } from 'jotai';
|
||||
import { Constants, ContentTypes, Tools } from 'librechat-data-provider';
|
||||
import {
|
||||
ReasoningDisclosureContext,
|
||||
reasoningDisclosure,
|
||||
ToolDisclosureContext,
|
||||
ToolDisclosureKeyContext,
|
||||
SoleToolContext,
|
||||
} from '@librechat/chat/react';
|
||||
import type {
|
||||
SubagentAttachmentFile,
|
||||
TMessageContentParts,
|
||||
|
|
@ -8,8 +15,8 @@ import type {
|
|||
TAttachment,
|
||||
Agents,
|
||||
} from 'librechat-data-provider';
|
||||
import type { ReasoningDisclosures, ToolDisclosures } from '@librechat/chat/react';
|
||||
import type { ReactNode, ReactElement } from 'react';
|
||||
import type { ReasoningDisclosures, ToolDisclosures } from './disclosure';
|
||||
import type { NestedCall } from '~/components/Chat/Subagents/attachments';
|
||||
import type { ToolCallGroupExpansionState } from './ToolCallGroup';
|
||||
import type { ActivityPhaseSegment } from '~/utils/activityLabels';
|
||||
|
|
@ -30,13 +37,6 @@ import {
|
|||
filterAttachmentsForPart,
|
||||
groupSequentialToolCalls,
|
||||
} from '~/utils';
|
||||
import {
|
||||
ReasoningDisclosureContext,
|
||||
reasoningDisclosure,
|
||||
ToolDisclosureContext,
|
||||
ToolDisclosureKeyContext,
|
||||
SoleToolContext,
|
||||
} from './disclosure';
|
||||
import {
|
||||
groupActivityPhases,
|
||||
lastCursorContentIdx,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { useId, useMemo, useState } from 'react';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
import { Tools } from 'librechat-data-provider';
|
||||
import { toolPanelSpacingClassName } from '@librechat/chat/react';
|
||||
import { Button, disclosureChevronVariants } from '@librechat/client';
|
||||
import type { MemoryArtifact, TAttachment } from 'librechat-data-provider';
|
||||
import { toolPanelSpacingClassName } from './disclosure';
|
||||
import { useExpandCollapse, useLocalize } from '~/hooks';
|
||||
import MemoryInfo from './MemoryInfo';
|
||||
import { cn } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import { forwardRef } from 'react';
|
||||
import { Button } from '@librechat/client';
|
||||
import {
|
||||
ARTIFACT_ROW_NAV_SPACING,
|
||||
ROW_GLYPH_SLOT,
|
||||
TOOL_ROW_CLASSES,
|
||||
} from '@librechat/chat/components';
|
||||
import {
|
||||
AppWindow,
|
||||
Download,
|
||||
|
|
@ -10,7 +15,6 @@ import {
|
|||
Workflow,
|
||||
} from 'lucide-react';
|
||||
import type { ArtifactGlyph, ArtifactRowKind } from '~/utils/artifacts';
|
||||
import { ARTIFACT_ROW_NAV_SPACING, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import LangIcon, { hasLangIcon } from '~/components/Messages/Content/LangIcon';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@ import { memo, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } fr
|
|||
import { Tools } from 'librechat-data-provider';
|
||||
import { Button, useRemScale } from '@librechat/client';
|
||||
import { Loader2, AlertCircle, Download, ChevronDown, Files as FilesIcon } from 'lucide-react';
|
||||
import {
|
||||
ARTIFACT_ROW_NAV_SPACING,
|
||||
ROW_GLYPH_SLOT,
|
||||
TOOL_ROW_CLASSES,
|
||||
} from '@librechat/chat/components';
|
||||
import type { TAttachment, TFile, TAttachmentMetadata } from 'librechat-data-provider';
|
||||
import type { ToolArtifactType } from '~/utils/artifacts';
|
||||
import {
|
||||
|
|
@ -14,7 +19,6 @@ import {
|
|||
isTextAttachment,
|
||||
renderAttachmentKey,
|
||||
} from './attachmentTypes';
|
||||
import { ARTIFACT_ROW_NAV_SPACING, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import { useLocalize, useAttachmentPreviewSync, useExpandCollapse } from '~/hooks';
|
||||
import FileContainer from '~/components/Chat/Input/Files/FileContainer';
|
||||
import { fileToArtifact, TOOL_ARTIFACT_TYPES } from '~/utils/artifacts';
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
import { memo } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
/**
|
||||
* Re-attributes response content to its author mid-message. A `SteerPart`
|
||||
* renders a full user turn inside the response, so the parts that resume
|
||||
* after it need the author's icon and label restated. The message-level
|
||||
* header only renders once, above the first part. Sits on the same left
|
||||
* edge as the message body.
|
||||
*/
|
||||
const AuthorHeader = memo(function AuthorHeader({
|
||||
icon,
|
||||
label,
|
||||
}: {
|
||||
icon: ReactNode;
|
||||
label: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="relative flex min-h-7 w-full items-center gap-2" data-testid="author-header">
|
||||
<div
|
||||
className="flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
<h2 className="text-text-primary min-w-0 truncate text-sm font-semibold select-none">
|
||||
{label}
|
||||
</h2>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export default AuthorHeader;
|
||||
|
|
@ -1,20 +1,19 @@
|
|||
import { useMemo, useState, useCallback } from 'react';
|
||||
import { TOOL_ROW_CLASSES } from '@librechat/chat/components';
|
||||
import { backgroundTaskOutcome, parseBackgroundTaskOutput } from '@librechat/chat';
|
||||
import { toolPanelSpacingClassName, useToolCallIntent } from '@librechat/chat/react';
|
||||
import type { PartMetadata, TAttachment } from 'librechat-data-provider';
|
||||
import { backgroundListGuidanceKeys, backgroundTaskNoticeKey } from './guidance';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
|
||||
import { useLocalize, useLazyCollapseBody } from '~/hooks';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import { ToolIcon, OutputRenderer } from '../ToolOutput';
|
||||
import { MCPAppViews } from '~/components/MCPUIResource';
|
||||
import BackgroundTaskCard from '../BackgroundTaskCard';
|
||||
import { useToolPreparation } from '../preparation';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import ToolCallInfo from '../ToolCallInfo';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import { cn } from '~/utils';
|
||||
import './BackgroundTaskCall.css';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
import { useMemo, useRef, useState, useCallback, useEffect } from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { Button } from '@librechat/client';
|
||||
import { PANE_COPY_REVEAL, TOOL_ROW_CLASSES, BareStatus } from '@librechat/chat/components';
|
||||
import {
|
||||
toolPanelSpacingClassName,
|
||||
useToolContentPending,
|
||||
useFollowScroll,
|
||||
useToolCallIntent,
|
||||
} from '@librechat/chat/react';
|
||||
import {
|
||||
parseBackgroundHandle,
|
||||
splitBackgroundAttachments,
|
||||
|
|
@ -9,21 +16,16 @@ import {
|
|||
parseCommandOutput,
|
||||
} from '@librechat/chat';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import { toolPanelSpacingClassName, useToolContentPending } from '../disclosure';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import LangIcon from '~/components/Messages/Content/LangIcon';
|
||||
import { PANE_COPY_REVEAL, TOOL_ROW_CLASSES } from '../rows';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import useLazyHighlight from './useLazyHighlight';
|
||||
import useFollowScroll from './useFollowScroll';
|
||||
import { OutputRenderer } from '../ToolOutput';
|
||||
import { ERROR_PATTERNS } from './ExecuteCode';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import PtcToolTrace from './PtcToolTrace';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { useToolContentPending } from '@librechat/chat/react';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import LangIcon from '~/components/Messages/Content/LangIcon';
|
||||
import { useToolContentPending } from '../disclosure';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
interface CodeWindowHeaderProps {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import { useMemo } from 'react';
|
||||
import { SquareTerminal } from 'lucide-react';
|
||||
import { TOOL_ROW_CLASSES, BareStatus, Stdout } from '@librechat/chat/components';
|
||||
import { parseBackgroundHandle, splitBackgroundAttachments } from '@librechat/chat';
|
||||
import {
|
||||
toolPanelSpacingClassName,
|
||||
useFollowScroll,
|
||||
useToolCallIntent,
|
||||
} from '@librechat/chat/react';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import useLazyHighlight from './useLazyHighlight';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import CodeWindowHeader from './CodeWindowHeader';
|
||||
import useFollowScroll from './useFollowScroll';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import PtcToolTrace from './PtcToolTrace';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import Stdout from './Stdout';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
interface ParsedArgs {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
import { useMemo } from 'react';
|
||||
import { FilePenLine, FilePlus2 } from 'lucide-react';
|
||||
import { TOOL_ROW_CLASSES, BareStatus } from '@librechat/chat/components';
|
||||
import { parseJsonField, parseJsonFieldOccurrences } from '@librechat/chat';
|
||||
import {
|
||||
toolPanelSpacingClassName,
|
||||
useFollowScroll,
|
||||
useToolCallIntent,
|
||||
} from '@librechat/chat/react';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import DiffView, {
|
||||
parseUnifiedDiff,
|
||||
|
|
@ -9,16 +15,11 @@ import DiffView, {
|
|||
type TextEditPreview,
|
||||
} from './DiffView';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import useLazyHighlight from './useLazyHighlight';
|
||||
import CodeWindowHeader from './CodeWindowHeader';
|
||||
import useFollowScroll from './useFollowScroll';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { langFromPath } from './ReadFileCall';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import { useMemo } from 'react';
|
|||
import { Brain } from 'lucide-react';
|
||||
import { Tools } from 'librechat-data-provider';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { BareStatus } from '@librechat/chat/components';
|
||||
import { toolPanelSpacingClassName } from '@librechat/chat/react';
|
||||
import type { PartMetadata, TAttachment, MemoryArtifact } from 'librechat-data-provider';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import MemoryInfo from '../MemoryInfo';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { AGENT_STYLE_TOOLS } from '.';
|
||||
import { PixelCard } from '@librechat/client';
|
||||
import { useToolCallIntent } from '@librechat/chat/react';
|
||||
import { ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import type {
|
||||
TAttachment,
|
||||
TFile,
|
||||
|
|
@ -11,8 +13,6 @@ import { ToolIcon, isError } from '~/components/Chat/Messages/Content/ToolOutput
|
|||
import Image from '~/components/Chat/Messages/Content/Image';
|
||||
import { useToolPreparation } from '../../preparation';
|
||||
import { useProgress, useLocalize } from '~/hooks';
|
||||
import { useToolCallIntent } from '../intent';
|
||||
import { ROW_GLYPH_SLOT } from '../../rows';
|
||||
import ProgressText from './ProgressText';
|
||||
import { scaleImage } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ScrollText } from 'lucide-react';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '@librechat/chat/components';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { useTranslation } from 'react-i18next';
|
||||
import { useFollowScroll } from '@librechat/chat/react';
|
||||
import { isReportableRunStepDuration } from 'librechat-data-provider';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import type { PtcTraceEntry } from '~/common';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { cn, parseToolName, getRunStepDurationLabels } from '~/utils';
|
||||
import { useMCPServerNames } from '~/hooks/MCP';
|
||||
import useFollowScroll from './useFollowScroll';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
/** Terminal-style status column: one glyph wide for every state, so the
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
import { useMemo } from 'react';
|
||||
import { FileText } from 'lucide-react';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { TOOL_ROW_CLASSES, BareStatus } from '@librechat/chat/components';
|
||||
import { toolPanelSpacingClassName, useToolCallIntent } from '@librechat/chat/react';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import useLazyHighlight from './useLazyHighlight';
|
||||
import CodeWindowHeader from './CodeWindowHeader';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { memo, useMemo, useState, useEffect, useCallback, useRef, useId } from '
|
|||
import { useAtom } from 'jotai';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { Lightbulb, ChevronDown } from 'lucide-react';
|
||||
import { ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import { useReasoningDisclosure } from '@librechat/chat/react';
|
||||
import { Button, disclosureChevronVariants } from '@librechat/client';
|
||||
import { ContentTypes, readableReasoning } from 'librechat-data-provider';
|
||||
import type { MouseEvent, FocusEvent } from 'react';
|
||||
|
|
@ -16,8 +18,6 @@ import { useLocalize, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
|
|||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import useSmoothStreaming from '~/hooks/Messages/useSmoothStreaming';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import { useReasoningDisclosure } from '../disclosure';
|
||||
import { ROW_GLYPH_SLOT } from '../rows';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
const stripThinkTags = (reasoning: string): string =>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { memo } from 'react';
|
||||
import { AuthorHeader } from '@librechat/chat/components';
|
||||
import { useAuthorContext } from '~/Providers';
|
||||
import AuthorHeader from './AuthorHeader';
|
||||
|
||||
/**
|
||||
* Restates the message author where content resumes after a steer, reading the
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
import { useMemo } from 'react';
|
||||
import { ScrollText } from 'lucide-react';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { TOOL_ROW_CLASSES, BareStatus, Stdout } from '@librechat/chat/components';
|
||||
import { toolPanelSpacingClassName, useToolCallIntent } from '@librechat/chat/react';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import useToolCallState from './useToolCallState';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import Stdout from './Stdout';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
export default function SkillCall({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { useCallback, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { ChevronRight, Users } from 'lucide-react';
|
||||
import { useToolCallIntent } from '@librechat/chat/react';
|
||||
import { FOLD_GLYPH_CLASS } from '@librechat/chat/components';
|
||||
import { parseSubagentBackgroundHandle } from '@librechat/chat';
|
||||
import { ContentTypes, EModelEndpoint } from 'librechat-data-provider';
|
||||
import type {
|
||||
|
|
@ -32,10 +34,8 @@ import { useToolPreparation } from '../preparation';
|
|||
import { useAgentsMapContext } from '~/Providers';
|
||||
import { useMCPServerNames } from '~/hooks/MCP';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { useFailedReveal } from '../reveal';
|
||||
import { cn, parseToolName } from '~/utils';
|
||||
import { FOLD_GLYPH_CLASS } from '../rows';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
interface SubagentCallProps {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
type MouseEvent,
|
||||
} from 'react';
|
||||
import { Lightbulb, ChevronDown } from 'lucide-react';
|
||||
import { ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import { Button, MorphIcon, TooltipAnchor } from '@librechat/client';
|
||||
import { ChevronUp as ChevronUpNode, ChevronDown as ChevronDownNode } from 'lucide';
|
||||
import type { FocusEvent, FC } from 'react';
|
||||
|
|
@ -16,7 +17,6 @@ import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
|||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import { useLocalize, useExpandCollapse } from '~/hooks';
|
||||
import { AnimatedText } from '../animate';
|
||||
import { ROW_GLYPH_SLOT } from '../rows';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
/** Whether any part of `el` is inside the viewport and every clipping ancestor. */
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ import React from 'react';
|
|||
import { RecoilRoot } from 'recoil';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { LoneGroupContext, SoleToolContext, ToolContentRequestContext } from '../../disclosure';
|
||||
import {
|
||||
LoneGroupContext,
|
||||
SoleToolContext,
|
||||
ToolContentRequestContext,
|
||||
} from '@librechat/chat/react';
|
||||
import BashCall from '../BashCall';
|
||||
import store from '~/store';
|
||||
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ jest.mock('../Attachment', () => ({
|
|||
AttachmentGroup: () => <div data-testid="attachment-group" />,
|
||||
}));
|
||||
|
||||
jest.mock('../Stdout', () => ({
|
||||
__esModule: true,
|
||||
default: () => <div data-testid="stdout" />,
|
||||
jest.mock('@librechat/chat/components', () => ({
|
||||
...jest.requireActual('@librechat/chat/components'),
|
||||
Stdout: () => <div data-testid="stdout" />,
|
||||
}));
|
||||
|
||||
jest.mock('../useLazyHighlight', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import { ReasoningCompact } from '../Reasoning';
|
||||
import { ROW_GLYPH_SLOT } from '../../rows';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
useLocalize: () => (key: string) => key,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { SoleToolContext } from '@librechat/chat/react';
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import { SoleToolContext } from '../../disclosure';
|
||||
import BashCall from '../BashCall';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { SoleToolContext } from '@librechat/chat/react';
|
||||
import FileAuthoringCall from '../FileAuthoringCall';
|
||||
import { SoleToolContext } from '../../disclosure';
|
||||
import ReadFileCall from '../ReadFileCall';
|
||||
import MemoryCall from '../MemoryCall';
|
||||
import SkillCall from '../SkillCall';
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import { RecoilRoot } from 'recoil';
|
||||
import { useAtomValue, useStore } from 'jotai';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { FOLD_GLYPH_SELECTOR } from '@librechat/chat/components';
|
||||
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import type {
|
||||
PartMetadata,
|
||||
|
|
@ -31,7 +32,6 @@ import SubagentCall, { SUBAGENT_TICKER_THROTTLE_MS } from '../SubagentCall';
|
|||
import { MessageContext } from '~/Providers/MessageContext';
|
||||
import { FailedRevealContext } from '../../reveal';
|
||||
import { ChatSurfaceHarness } from 'test/harness';
|
||||
import { FOLD_GLYPH_SELECTOR } from '../../rows';
|
||||
import { litFoldPath } from '../../rail';
|
||||
|
||||
const mockMCPServerNames: string[] = [];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import { SoleToolContext, useToolAutoExpand } from '@librechat/chat/react';
|
||||
import { render, renderHook, screen, fireEvent } from '@testing-library/react';
|
||||
import type { TAttachment } from 'librechat-data-provider';
|
||||
import type {
|
||||
|
|
@ -8,7 +9,6 @@ import type {
|
|||
} from '~/hooks/Chat/contract';
|
||||
import type { Artifact, PtcTrace } from '~/common';
|
||||
import { MessagePartsHostProvider, appMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { SoleToolContext, useToolAutoExpand } from '../../disclosure';
|
||||
import ToolArtifactCard from '../ToolArtifactCard';
|
||||
import { Text as TextPart } from '../index';
|
||||
import PtcToolTrace from '../PtcToolTrace';
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ export { default as BashCall } from './BashCall';
|
|||
export { default as PtcToolTrace } from './PtcToolTrace';
|
||||
export { default as SubagentCall } from './SubagentCall';
|
||||
export { default as SteerPart } from './SteerPart';
|
||||
export { default as AuthorHeader } from './AuthorHeader';
|
||||
export { AuthorHeader } from '@librechat/chat/components';
|
||||
export { default as ResumeAuthorHeader } from './ResumeAuthorHeader';
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import { useCallback, useContext } from 'react';
|
||||
import type { PartMetadata } from 'librechat-data-provider';
|
||||
import type { ToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import {
|
||||
SoleToolContext,
|
||||
LoneGroupContext,
|
||||
useToolExpansion,
|
||||
useToolContentRequest,
|
||||
} from '../disclosure';
|
||||
useRowHandoff,
|
||||
} from '@librechat/chat/react';
|
||||
import type { PartMetadata } from 'librechat-data-provider';
|
||||
import type { ToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import { isError } from '~/components/Chat/Messages/Content/ToolOutput';
|
||||
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import { useProgress, useExpandCollapse } from '~/hooks';
|
||||
import useRowHandoff from '../handoff';
|
||||
|
||||
interface ToolCallState {
|
||||
showCode: boolean;
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@ import { useCallback, useRef } from 'react';
|
|||
import { ChevronDown } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import * as Popover from '@radix-ui/react-popover';
|
||||
import { ElapsedTimer } from '@librechat/chat/components';
|
||||
import { Button, disclosureChevronVariants } from '@librechat/client';
|
||||
import { isReportableRunStepDuration } from 'librechat-data-provider';
|
||||
import { ElapsedTimer, CancelledIcon, ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import type { ToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import { cn, getRunStepDurationLabels } from '~/utils';
|
||||
import { useToolPreparation } from './preparation';
|
||||
import CancelledIcon from './CancelledIcon';
|
||||
import { useFailedReveal } from './reveal';
|
||||
import { ROW_GLYPH_SLOT } from './rows';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
const wrapperClass =
|
||||
|
|
|
|||
|
|
@ -2,14 +2,17 @@ import { useMemo, useState, useCallback } from 'react';
|
|||
import { Tools } from 'librechat-data-provider';
|
||||
import { TooltipAnchor } from '@librechat/client';
|
||||
import { FileText, FileSpreadsheet, FileCode, FileImage, File } from 'lucide-react';
|
||||
import {
|
||||
toolPanelSpacingClassName,
|
||||
useToolExpansion,
|
||||
useToolCallIntent,
|
||||
} from '@librechat/chat/react';
|
||||
import type { TAttachment, TFile, PartMetadata } from 'librechat-data-provider';
|
||||
import { toolPanelSpacingClassName, useToolExpansion } from './disclosure';
|
||||
import { useLocalize, useProgress, useExpandCollapse } from '~/hooks';
|
||||
import { ToolIcon, OutputRenderer, isError } from './ToolOutput';
|
||||
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import FilePreviewDialog from './FilePreviewDialog';
|
||||
import { sortPagesByRelevance, cn } from '~/utils';
|
||||
import { useToolCallIntent } from './Parts/intent';
|
||||
import { useToolPreparation } from './preparation';
|
||||
import { useGetFiles } from '~/data-provider';
|
||||
import ProgressText from './ProgressText';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import React, { useMemo, useState, useEffect, useContext, useCallback } from 'react';
|
||||
import { Button } from '@librechat/client';
|
||||
import { hasToolParams } from '@librechat/chat';
|
||||
import { TOOL_ROW_CLASSES } from '@librechat/chat/components';
|
||||
import {
|
||||
Constants,
|
||||
dataService,
|
||||
|
|
@ -8,14 +9,16 @@ import {
|
|||
actionDomainSeparator,
|
||||
splitToolCallName,
|
||||
} from 'librechat-data-provider';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import {
|
||||
toolPanelSpacingClassName,
|
||||
useToolContentRequest,
|
||||
useToolExpansion,
|
||||
LoneGroupContext,
|
||||
SoleToolContext,
|
||||
} from './disclosure';
|
||||
useToolCallIntent,
|
||||
useRowHandoff,
|
||||
} from '@librechat/chat/react';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import { useLocalize, useProgress, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
|
||||
import { ToolIcon, getToolIconType, isError, hasRenderableOutput } from './ToolOutput';
|
||||
import { cn, getToolDisplayLabel, logger, openInNewTab } from '~/utils';
|
||||
|
|
@ -23,14 +26,11 @@ import { isToolCallPreparing, useToolPreparation } from './preparation';
|
|||
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
|
||||
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import { MCPAppViews } from '~/components/MCPUIResource';
|
||||
import { useToolCallIntent } from './Parts/intent';
|
||||
import { AttachmentGroup } from './Parts';
|
||||
import ToolCallInfo from './ToolCallInfo';
|
||||
import ProgressText from './ProgressText';
|
||||
import { TOOL_ROW_CLASSES } from './rows';
|
||||
import { ToolAuthWarning } from './auth';
|
||||
import { firstErrorLine } from './live';
|
||||
import useRowHandoff from './handoff';
|
||||
|
||||
export default function ToolCall({
|
||||
initialProgress = 0.1,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { useState, useRef, useMemo, useEffect, useContext, useCallback } from 'react';
|
||||
import { LoneGroupContext, SoleToolContext } from '@librechat/chat/react';
|
||||
import { FOLD_RAIL_CLASSES, ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import { Tools, Constants, ContentTypes, isOpaqueReasoning } from 'librechat-data-provider';
|
||||
import { ChevronDown, ListChecks, MessageCircleQuestion, TriangleAlert, Users } from 'lucide-react';
|
||||
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
|
||||
|
|
@ -31,11 +33,9 @@ import { useLocalize, useExpandCollapse, scheduleMessageContentLayoutReconcile }
|
|||
import { ASK_USER_QUESTION, getSubmittedAskAnswer } from '~/utils/approval';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { ToolAuthWarning, ToolAuthWarningContext } from './auth';
|
||||
import { LoneGroupContext, SoleToolContext } from './disclosure';
|
||||
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
|
||||
import { AttachmentGroup, ReasoningCompact } from './Parts';
|
||||
import { getOutcomeStatus, summarizeSpan } from './outcome';
|
||||
import { FOLD_RAIL_CLASSES, ROW_GLYPH_SLOT } from './rows';
|
||||
import { MCPAppViews } from '~/components/MCPUIResource';
|
||||
import { parseToolName } from '~/utils/toolLabels';
|
||||
import { StackedToolIcons } from './ToolOutput';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { useRef, useState, useMemo, useCallback, useLayoutEffect } from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { Button } from '@librechat/client';
|
||||
import { useToolContentPending } from '@librechat/chat/react';
|
||||
import { PANE_COPY_REVEAL } from '@librechat/chat/components';
|
||||
import { hasToolCallErrorPrefix, stripToolCallErrorPrefix } from 'librechat-data-provider';
|
||||
import type { UIEvent } from 'react';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import { useToolContentPending } from '../disclosure';
|
||||
import { PANE_COPY_REVEAL } from '../rows';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { ToolContentPendingContext } from '@librechat/chat/react';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { ToolContentPendingContext } from '../../disclosure';
|
||||
import OutputRenderer, { isError } from '../OutputRenderer';
|
||||
|
||||
jest.mock('copy-to-clipboard', () => jest.fn());
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@ import { useMemo, useState } from 'react';
|
|||
import { Tools } from 'librechat-data-provider';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { Globe, ChevronDown, Info } from 'lucide-react';
|
||||
import { ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import {
|
||||
useToolExpansion,
|
||||
useToolContentRequest,
|
||||
toolPanelSpacingClassName,
|
||||
useToolCallIntent,
|
||||
} from '@librechat/chat/react';
|
||||
import {
|
||||
Button,
|
||||
HoverCard,
|
||||
|
|
@ -17,17 +24,14 @@ import type {
|
|||
PartMetadata,
|
||||
AnswerBoxResult,
|
||||
} from 'librechat-data-provider';
|
||||
import { useToolExpansion, useToolContentRequest, toolPanelSpacingClassName } from './disclosure';
|
||||
import { FaviconImage, getCleanDomain } from '~/components/Web/SourceHovercard';
|
||||
import { useLocalize, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
|
||||
import { collectSources, getUniqueDomainSources } from './sources';
|
||||
import { StackedFavicons } from '~/components/Web/Sources';
|
||||
import { isError } from './ToolOutput/OutputRenderer';
|
||||
import { useToolCallIntent } from './Parts/intent';
|
||||
import { useToolPreparation } from './preparation';
|
||||
import { useSearchContext } from '~/Providers';
|
||||
import SearchVerticals from './verticals';
|
||||
import { ROW_GLYPH_SLOT } from './rows';
|
||||
import ToolCall from './ToolCall';
|
||||
import cn from '~/utils/cn';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ContentTypes, Tools } from 'librechat-data-provider';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '@librechat/chat/components';
|
||||
import { act, fireEvent, render, screen, within } from '@testing-library/react';
|
||||
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import { MessageSurfaceContext } from '../../ui/surface';
|
||||
import ActivityPhaseGroup from '../ActivityPhaseGroup';
|
||||
import { useFailedReveal } from '../reveal';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import '~/Providers/MessagePartsHostContext';
|
||||
import AskUserQuestionCall from '../AskUserQuestionCall';
|
||||
import { FailedRevealContext } from '../reveal';
|
||||
import store from '~/store';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { FOLD_GLYPH_CLASS } from '@librechat/chat/components';
|
||||
import { Constants, ContentTypes, Tools } from 'librechat-data-provider';
|
||||
import { act, fireEvent, render, screen, within } from '@testing-library/react';
|
||||
import type { EventSubmission, TAttachment, TMessageContentParts } from 'librechat-data-provider';
|
||||
|
|
@ -8,7 +9,6 @@ import useAttachmentHandler from '~/hooks/SSE/useAttachmentHandler';
|
|||
import useAttachments from '~/hooks/Messages/useAttachments';
|
||||
import { ParallelColumns } from '../ParallelContent';
|
||||
import ContentParts from '../ContentParts';
|
||||
import { FOLD_GLYPH_CLASS } from '../rows';
|
||||
import { litFoldPath } from '../rail';
|
||||
import { Text } from '../Parts';
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ jest.mock('../Part', () => {
|
|||
const { useMessageContext } = jest.requireActual<typeof import('~/Providers/MessageContext')>(
|
||||
'~/Providers/MessageContext',
|
||||
);
|
||||
const { SoleToolContext } = jest.requireActual<typeof import('../disclosure')>('../disclosure');
|
||||
const { SoleToolContext } =
|
||||
jest.requireActual<typeof import('@librechat/chat/react')>('@librechat/chat/react');
|
||||
const { useContext } = jest.requireActual<typeof import('react')>('react');
|
||||
return {
|
||||
__esModule: true,
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ jest.mock('react-i18next', () => ({
|
|||
useTranslation: () => ({ i18n: { language: 'en' } }),
|
||||
}));
|
||||
|
||||
jest.mock('../CancelledIcon', () => ({
|
||||
__esModule: true,
|
||||
default: () => <span data-testid="cancelled-icon" />,
|
||||
jest.mock('@librechat/chat/components', () => ({
|
||||
...jest.requireActual('@librechat/chat/components'),
|
||||
CancelledIcon: () => <span data-testid="cancelled-icon" />,
|
||||
}));
|
||||
|
||||
const defaults = {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import { RecoilRoot } from 'recoil';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import type { TAttachment } from 'librechat-data-provider';
|
||||
import '~/Providers/MessagePartsHostContext';
|
||||
import RetrievalCall from '../RetrievalCall';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { Tools, Constants, dataService } from 'librechat-data-provider';
|
||||
import { LoneGroupContext, SoleToolContext } from '@librechat/chat/react';
|
||||
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
|
||||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
import { MCPAppsPolicyProvider } from '~/Providers/MCPAppsPolicyContext';
|
||||
import { LoneGroupContext, SoleToolContext } from '../disclosure';
|
||||
import { ToolAuthWarningContext } from '../auth';
|
||||
import ToolCall from '../ToolCall';
|
||||
import { logger } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import React, { useContext } from 'react';
|
|||
import { RecoilRoot } from 'recoil';
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { Tools, Constants, ContentTypes, ToolCallTypes } from 'librechat-data-provider';
|
||||
import { LoneGroupContext, SoleToolContext, useToolAutoExpand } from '@librechat/chat/react';
|
||||
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
|
||||
import { LoneGroupContext, SoleToolContext, useToolAutoExpand } from '../disclosure';
|
||||
import { FailedRevealContext, useFailedReveal } from '../reveal';
|
||||
import { scheduleMessageContentLayoutReconcile } from '~/hooks';
|
||||
import ToolCallGroup from '../ToolCallGroup';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { Tools } from 'librechat-data-provider';
|
||||
import { ROW_GLYPH_SLOT } from '@librechat/chat/components';
|
||||
import { ToolContentRequestContext } from '@librechat/chat/react';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import type {
|
||||
TAttachment,
|
||||
|
|
@ -8,10 +10,8 @@ import type {
|
|||
ValidSource,
|
||||
PartMetadata,
|
||||
} from 'librechat-data-provider';
|
||||
import { ToolContentRequestContext } from '../disclosure';
|
||||
import { FailedRevealContext } from '../reveal';
|
||||
import { SearchContext } from '~/Providers';
|
||||
import { ROW_GLYPH_SLOT } from '../rows';
|
||||
import WebSearch from '../WebSearch';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import { RecoilRoot } from 'recoil';
|
|||
import { ContentTypes, dataService } from 'librechat-data-provider';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import type { TMessageContentParts, ToolCallPartResponse } from 'librechat-data-provider';
|
||||
import type { ToolContentQuery, ToolDisclosures } from '../disclosure';
|
||||
import {
|
||||
SoleToolContext,
|
||||
ToolContentQueryContext,
|
||||
|
|
@ -12,7 +10,9 @@ import {
|
|||
useToolContentPending,
|
||||
ToolDisclosureContext,
|
||||
ToolDisclosureKeyContext,
|
||||
} from '../disclosure';
|
||||
} from '@librechat/chat/react';
|
||||
import type { TMessageContentParts, ToolCallPartResponse } from 'librechat-data-provider';
|
||||
import type { ToolContentQuery, ToolDisclosures } from '@librechat/chat/react';
|
||||
import { isPreviewedToolCallPart, PreviewedToolCallPart, withFullToolCall } from '../hydration';
|
||||
import { MessageContext } from '~/Providers';
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import {
|
|||
hasToolCallPreview,
|
||||
getToolCallPreviewRevision,
|
||||
} from 'librechat-data-provider';
|
||||
import type { FullToolCall, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { ReactNode } from 'react';
|
||||
import {
|
||||
ToolContentRequestContext,
|
||||
ToolContentPendingContext,
|
||||
ToolContentQueryContext,
|
||||
} from './disclosure';
|
||||
} from '@librechat/chat/react';
|
||||
import type { FullToolCall, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { useToolCallPartQuery } from '~/data-provider';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { boundIntentLabel, getToolCallIntent } from '@librechat/chat/react';
|
||||
import {
|
||||
Constants,
|
||||
ContentTypes,
|
||||
|
|
@ -19,7 +20,6 @@ import { hasPendingApprovalInPart, hasPendingAuthInPart } from '~/utils/groupToo
|
|||
import { ASK_USER_QUESTION, getSubmittedAskAnswer } from '~/utils/approval';
|
||||
import { getToolDisplayLabel, parseToolName } from '~/utils/toolLabels';
|
||||
import { getToolIconName, getToolMeta, summarizeSpan } from './outcome';
|
||||
import { boundIntentLabel, getToolCallIntent } from './Parts/intent';
|
||||
import { isError } from './ToolOutput';
|
||||
|
||||
/** How often a live fold's header may repaint. A streamed intent moves the
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import {
|
|||
useSyncExternalStore,
|
||||
} from 'react';
|
||||
import { CircleMinus } from 'lucide-react';
|
||||
import { ROW_GLYPH_SLOT, FOLD_GLYPH_SELECTOR } from '@librechat/chat/components';
|
||||
import type { ReactNode, RefObject } from 'react';
|
||||
import { ROW_GLYPH_SLOT, FOLD_GLYPH_SELECTOR } from './rows';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { memo, useMemo } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import {
|
||||
getHeaderModelName,
|
||||
SubRow,
|
||||
getMessageRowWidthClass,
|
||||
MessageRow,
|
||||
AuthorHeader,
|
||||
getHeaderModelName,
|
||||
getMessageRowWidthClass,
|
||||
} from '@librechat/chat/components';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import type { TMessageProps, TMessageIcon } from '~/common';
|
||||
import AuthorHeader from '~/components/Chat/Messages/Content/Parts/AuthorHeader';
|
||||
import MinimalHoverButtons from '~/components/Chat/Messages/MinimalHoverButtons';
|
||||
import { getHeaderPrefixForScreenReader, getMessageAriaLabel } from '~/utils';
|
||||
import SearchContent, { rendersMarkdownLite } from './Content/SearchContent';
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ jest.mock('~/components/Chat/Messages/Content/ContentParts', () => {
|
|||
};
|
||||
});
|
||||
|
||||
jest.mock('~/components/Chat/Messages/Content/Parts/AuthorHeader', () => ({
|
||||
__esModule: true,
|
||||
default: () => <div data-testid="author-header" />,
|
||||
jest.mock('@librechat/chat/components', () => ({
|
||||
...jest.requireActual('@librechat/chat/components'),
|
||||
AuthorHeader: () => <div data-testid="author-header" />,
|
||||
}));
|
||||
|
||||
jest.mock('~/components/Chat/Messages/MessageIcon', () => ({
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import { Alert, Button } from '@librechat/client';
|
|||
import { Maximize2, Minimize2 } from 'lucide-react';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import { MessageTimestamp } from '@librechat/chat/components';
|
||||
import { ToolContentQueryContext } from '@librechat/chat/react';
|
||||
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 { ToolContentQuery } from '@librechat/chat/react';
|
||||
import type { TaskContentScope } from '~/data-provider/Subagents/content';
|
||||
import type { ChildActivity, ChildActivityItem } from './adapters';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
|
|
@ -17,7 +18,6 @@ import {
|
|||
subagentStatusIcon,
|
||||
subagentStatusLabelKey,
|
||||
} from './status';
|
||||
import { ToolContentQueryContext } from '~/components/Chat/Messages/Content/disclosure';
|
||||
import { TaskContentScopeContext } from '~/data-provider/Subagents/content';
|
||||
import MarkdownLite from '~/components/Chat/Messages/Content/MarkdownLite';
|
||||
import ContentParts from '~/components/Chat/Messages/Content/ContentParts';
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ import {
|
|||
MessageRow,
|
||||
} from '@librechat/chat/components';
|
||||
import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { ToolContentQuery } from '@librechat/chat/react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { ToolContentQuery } from '~/components/Chat/Messages/Content/disclosure';
|
||||
import type { TaskContentScope } from '~/data-provider/Subagents/content';
|
||||
import type { MessagePartsHost } from '~/hooks/Chat/contract';
|
||||
import type { ChildConversationTurn } from './adapters';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
import { useMemo } from 'react';
|
||||
import { parseWakeupMessage } from '@librechat/chat';
|
||||
import { getHeaderHoverLabel, SiblingSwitch, SubRow, MessageRow } from '@librechat/chat/components';
|
||||
import {
|
||||
SubRow,
|
||||
MessageRow,
|
||||
AuthorHeader,
|
||||
SiblingSwitch,
|
||||
getHeaderHoverLabel,
|
||||
} from '@librechat/chat/components';
|
||||
import type { TMessageProps } from '~/common';
|
||||
import SearchContent, {
|
||||
rendersMarkdownLite,
|
||||
} from '~/components/Chat/Messages/Content/SearchContent';
|
||||
import AuthorHeader from '~/components/Chat/Messages/Content/Parts/AuthorHeader';
|
||||
import MinimalHoverButtons from '~/components/Chat/Messages/MinimalHoverButtons';
|
||||
import MessageContent from '~/components/Chat/Messages/Content/MessageContent';
|
||||
import { getHeaderPrefixForScreenReader, getMessageAriaLabel } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|||
import { QueryKeys, dataService, hasToolCallPreview } from 'librechat-data-provider';
|
||||
import type { SubagentTaskContentSnapshot, ToolCallPartResponse } from 'librechat-data-provider';
|
||||
import type { QueryClient, UseQueryOptions } from '@tanstack/react-query';
|
||||
import type { ToolContentQuery } from '~/components/Chat/Messages/Content/disclosure';
|
||||
import type { ToolContentQuery } from '@librechat/chat/react';
|
||||
import type { RecoveredContent } from '~/components/Chat/Subagents/recovery';
|
||||
import { recoverTaskContent, recoveredToolPart } from '~/components/Chat/Subagents/recovery';
|
||||
import { isLiveSubagentStatus } from '~/components/Chat/Subagents/status';
|
||||
|
|
|
|||
69
e2e/specs/mock/scenarios/steer-author-header.spec.ts
Normal file
69
e2e/specs/mock/scenarios/steer-author-header.spec.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { getE2EUser } from '../../../setup/user';
|
||||
import {
|
||||
deleteConversations,
|
||||
deleteMessagesByConversation,
|
||||
seedConversations,
|
||||
seedMessages,
|
||||
} from '../db';
|
||||
import type { SeedMessage } from '../db';
|
||||
|
||||
const userEmail = getE2EUser().email;
|
||||
const ROOT_PARENT = '00000000-0000-0000-0000-000000000000';
|
||||
|
||||
/** A reply the user steered mid-stream, seeded straight into Mongo: the steer
|
||||
* part sits between the text before and after it, as a finished run stores it. */
|
||||
async function seedSteeredReply() {
|
||||
const conversationId = randomUUID();
|
||||
const userId = randomUUID();
|
||||
const replyId = randomUUID();
|
||||
const messages: SeedMessage[] = [
|
||||
{
|
||||
messageId: userId,
|
||||
parentMessageId: ROOT_PARENT,
|
||||
text: 'Tell me about animals',
|
||||
isCreatedByUser: true,
|
||||
sender: 'User',
|
||||
},
|
||||
{
|
||||
messageId: replyId,
|
||||
parentMessageId: userId,
|
||||
text: 'Dogs are loyal. Cats are independent.',
|
||||
isCreatedByUser: false,
|
||||
sender: 'OpenAI',
|
||||
content: [
|
||||
{ type: 'text', text: 'Dogs are loyal.' },
|
||||
{ type: 'steer', steer: 'Focus on cats', steerId: randomUUID() },
|
||||
{ type: 'text', text: 'Cats are independent.' },
|
||||
],
|
||||
},
|
||||
];
|
||||
await seedConversations(userEmail, [
|
||||
{ conversationId, title: `Steer ${conversationId.slice(0, 8)}`, updatedAt: new Date() },
|
||||
]);
|
||||
await seedMessages(userEmail, conversationId, messages);
|
||||
return { conversationId, replyId };
|
||||
}
|
||||
|
||||
async function cleanup(conversationId: string) {
|
||||
await deleteMessagesByConversation([conversationId]);
|
||||
await deleteConversations([conversationId]);
|
||||
}
|
||||
|
||||
test('content that resumes after a steer restates its author @scenario:steered-reply-restates-author-after-steer', async ({
|
||||
page,
|
||||
}) => {
|
||||
const { conversationId, replyId } = await seedSteeredReply();
|
||||
try {
|
||||
await page.goto(`/c/${conversationId}`);
|
||||
const reply = page.locator(`[id="${replyId}"]`);
|
||||
await expect(reply.getByText('Focus on cats')).toBeVisible();
|
||||
await expect(reply.getByText('Cats are independent.')).toBeVisible();
|
||||
const header = reply.getByTestId('author-header');
|
||||
await expect(header).toHaveCount(1);
|
||||
await expect(header.getByRole('heading')).not.toHaveText('');
|
||||
} finally {
|
||||
await cleanup(conversationId);
|
||||
}
|
||||
});
|
||||
|
|
@ -58,3 +58,19 @@ export { default as MessageTimestamp } from './components/messages/MessageTimest
|
|||
export { getMessageRowWidthClass } from './components/messages/width';
|
||||
export { isValidTimestamp, getMessageTimestamp } from './components/messages/time';
|
||||
export type { MessageTimestamp as MessageTimestampParts } from './components/messages/time';
|
||||
|
||||
/** Parts: the leaf components and row classes tool cards share. */
|
||||
export { default as Stdout } from './components/parts/Stdout';
|
||||
export { default as BareStatus } from './components/parts/BareStatus';
|
||||
export { default as AuthorHeader } from './components/parts/AuthorHeader';
|
||||
export { default as CancelledIcon } from './components/parts/CancelledIcon';
|
||||
export { default as InProgressCall } from './components/parts/InProgressCall';
|
||||
export {
|
||||
ROW_GLYPH_SLOT,
|
||||
PANE_COPY_REVEAL,
|
||||
FOLD_GLYPH_CLASS,
|
||||
TOOL_ROW_CLASSES,
|
||||
FOLD_RAIL_CLASSES,
|
||||
FOLD_GLYPH_SELECTOR,
|
||||
ARTIFACT_ROW_NAV_SPACING,
|
||||
} from './components/parts/rows';
|
||||
|
|
|
|||
31
packages/chat/src/components/parts/AuthorHeader.tsx
Normal file
31
packages/chat/src/components/parts/AuthorHeader.tsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { memo } from 'react';
|
||||
import type { MemoExoticComponent, ReactNode } from 'react';
|
||||
|
||||
/**
|
||||
* Re-attributes response content to its author mid-message. A `SteerPart`
|
||||
* renders a full user turn inside the response, so the parts that resume
|
||||
* after it need the author's icon and label restated. The message-level
|
||||
* header only renders once, above the first part. Sits on the same left
|
||||
* edge as the message body.
|
||||
*/
|
||||
type AuthorHeaderProps = { icon: ReactNode; label: string };
|
||||
|
||||
const AuthorHeader: MemoExoticComponent<(props: AuthorHeaderProps) => ReactNode> = memo(
|
||||
function AuthorHeader({ icon, label }: AuthorHeaderProps) {
|
||||
return (
|
||||
<div className="relative flex min-h-7 w-full items-center gap-2" data-testid="author-header">
|
||||
<div
|
||||
className="flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
<h2 className="text-text-primary min-w-0 truncate text-sm font-semibold select-none">
|
||||
{label}
|
||||
</h2>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
export default AuthorHeader;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { useContext } from 'react';
|
||||
import { LoneGroupContext, SoleToolContext } from '../disclosure';
|
||||
import type { ReactNode } from 'react';
|
||||
import { LoneGroupContext, SoleToolContext } from '../../react/parts/disclosure';
|
||||
|
||||
/**
|
||||
* The settled outcome of a sole call, spoken after its row is gone. The row's
|
||||
|
|
@ -12,7 +13,7 @@ import { LoneGroupContext, SoleToolContext } from '../disclosure';
|
|||
* Only a call that can drop its row renders it, so a card with a row of its
|
||||
* own never carries a second, empty live region.
|
||||
*/
|
||||
export default function BareStatus({ active, text }: { active: boolean; text: string }) {
|
||||
export default function BareStatus({ active, text }: { active: boolean; text: string }): ReactNode {
|
||||
const sole = useContext(SoleToolContext) === true;
|
||||
const lone = useContext(LoneGroupContext);
|
||||
if (!sole && !lone) {
|
||||
10
packages/chat/src/components/parts/CancelledIcon.tsx
Normal file
10
packages/chat/src/components/parts/CancelledIcon.tsx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { X } from 'lucide-react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
export default function CancelledIcon(): ReactNode {
|
||||
return (
|
||||
<div className="text-text-secondary flex h-full w-full items-center justify-center rounded-full bg-transparent">
|
||||
<X className="size-4" aria-hidden="true" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import type { ReactNode } from 'react';
|
||||
import CancelledIcon from './CancelledIcon';
|
||||
|
||||
export default function InProgressCall({
|
||||
|
|
@ -9,8 +10,8 @@ export default function InProgressCall({
|
|||
error?: boolean;
|
||||
isSubmitting: boolean;
|
||||
progress: number;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
children: ReactNode;
|
||||
}): ReactNode {
|
||||
if ((!isSubmitting && progress < 1) || error === true) {
|
||||
return <CancelledIcon />;
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import { useMemo } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
interface StdoutProps {
|
||||
output?: string;
|
||||
}
|
||||
|
||||
export default function Stdout({ output = '' }: StdoutProps) {
|
||||
export default function Stdout({ output = '' }: StdoutProps): ReactNode {
|
||||
const processedContent = useMemo(() => {
|
||||
if (!output) {
|
||||
return '';
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AuthorHeader from '../AuthorHeader';
|
||||
|
||||
|
|
@ -24,10 +24,10 @@ export const FOLD_GLYPH_CLASS = 'fold-glyph';
|
|||
* and would carry a taller slot 2px below the row's center. `fold-glyph` is a
|
||||
* hook, not a style: see `FOLD_GLYPH_SELECTOR`.
|
||||
*/
|
||||
export const ROW_GLYPH_SLOT = `${FOLD_GLYPH_CLASS} flex h-5 min-w-6 shrink-0 items-center justify-center`;
|
||||
export const ROW_GLYPH_SLOT: string = `${FOLD_GLYPH_CLASS} flex h-5 min-w-6 shrink-0 items-center justify-center`;
|
||||
|
||||
/** Shared by normal row slots and custom header glyphs. */
|
||||
export const FOLD_GLYPH_SELECTOR = `.${FOLD_GLYPH_CLASS}`;
|
||||
export const FOLD_GLYPH_SELECTOR: string = `.${FOLD_GLYPH_CLASS}`;
|
||||
|
||||
/**
|
||||
* The panel under an open header: its rows step in by one glyph slot and a
|
||||
|
|
@ -125,3 +125,29 @@ export {
|
|||
setDefaultMessagesHost,
|
||||
} from './react/messages/host';
|
||||
export type { MessagesHost } from './react/messages/host';
|
||||
export {
|
||||
SoleToolContext,
|
||||
LoneGroupContext,
|
||||
useToolExpansion,
|
||||
useToolAutoExpand,
|
||||
useToolDisclosure,
|
||||
reasoningDisclosure,
|
||||
ToolDisclosureContext,
|
||||
useToolContentPending,
|
||||
useToolContentRequest,
|
||||
useReasoningDisclosure,
|
||||
ToolContentQueryContext,
|
||||
ToolDisclosureKeyContext,
|
||||
ToolContentPendingContext,
|
||||
ToolContentRequestContext,
|
||||
toolPanelSpacingClassName,
|
||||
ReasoningDisclosureContext,
|
||||
} from './react/parts/disclosure';
|
||||
export type {
|
||||
ToolDisclosures,
|
||||
ToolContentQuery,
|
||||
ReasoningDisclosures,
|
||||
} from './react/parts/disclosure';
|
||||
export { boundIntentLabel, getToolCallIntent, useToolCallIntent } from './react/parts/intent';
|
||||
export { default as useFollowScroll } from './react/parts/useFollowScroll';
|
||||
export { default as useRowHandoff } from './react/parts/handoff';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import React from 'react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
import useFollowScroll from '../useFollowScroll';
|
||||
|
|
@ -1,15 +1,21 @@
|
|||
import { createContext, useContext, useEffect, useMemo } from 'react';
|
||||
import { atom, useAtom } from 'jotai';
|
||||
import type { PrimitiveAtom } from 'jotai';
|
||||
import type { useToolCallPartQuery } from '~/data-provider/Messages/queries';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import type { ToolCallPartParams, ToolCallPartResponse } from 'librechat-data-provider';
|
||||
import type { UseQueryOptions, QueryObserverResult } from '@tanstack/react-query';
|
||||
import type { PrimitiveAtom, SetStateAction } from 'jotai';
|
||||
import type { Context } from 'react';
|
||||
import { useMessagePartsHost } from '../host';
|
||||
|
||||
export type ReasoningDisclosures = Map<number, PrimitiveAtom<boolean | undefined>>;
|
||||
|
||||
/** Owned by one message, above the layouts that can move its reasoning. */
|
||||
export const ReasoningDisclosureContext = createContext<ReasoningDisclosures | null>(null);
|
||||
export const ReasoningDisclosureContext: Context<ReasoningDisclosures | null> =
|
||||
createContext<ReasoningDisclosures | null>(null);
|
||||
|
||||
export function reasoningDisclosure(disclosures: ReasoningDisclosures, index: number) {
|
||||
export function reasoningDisclosure(
|
||||
disclosures: ReasoningDisclosures,
|
||||
index: number,
|
||||
): PrimitiveAtom<boolean | undefined> {
|
||||
let disclosure = disclosures.get(index);
|
||||
if (disclosure == null) {
|
||||
disclosure = atom<boolean | undefined>(undefined);
|
||||
|
|
@ -18,7 +24,7 @@ export function reasoningDisclosure(disclosures: ReasoningDisclosures, index: nu
|
|||
return disclosure;
|
||||
}
|
||||
|
||||
export function useReasoningDisclosure(index: number) {
|
||||
export function useReasoningDisclosure(index: number): PrimitiveAtom<boolean | undefined> {
|
||||
const disclosures = useContext(ReasoningDisclosureContext);
|
||||
return useMemo(
|
||||
() =>
|
||||
|
|
@ -36,10 +42,13 @@ export const toolPanelSpacingClassName = 'mb-2 mt-0';
|
|||
export type ToolDisclosures = Map<string, PrimitiveAtom<boolean | undefined>>;
|
||||
|
||||
/** Kept above part keys and activity layouts; never shared between message views. */
|
||||
export const ToolDisclosureContext = createContext<ToolDisclosures | null>(null);
|
||||
export const ToolDisclosureKeyContext = createContext<string | undefined>(undefined);
|
||||
export const ToolDisclosureContext: Context<ToolDisclosures | null> =
|
||||
createContext<ToolDisclosures | null>(null);
|
||||
export const ToolDisclosureKeyContext: Context<string | undefined> = createContext<
|
||||
string | undefined
|
||||
>(undefined);
|
||||
|
||||
export function useToolDisclosure() {
|
||||
export function useToolDisclosure(): PrimitiveAtom<boolean | undefined> {
|
||||
const disclosures = useContext(ToolDisclosureContext);
|
||||
const key = useContext(ToolDisclosureKeyContext);
|
||||
return useMemo(() => {
|
||||
|
|
@ -60,17 +69,19 @@ export function useToolDisclosure() {
|
|||
* click without adding information. `undefined` means no enclosing phase has
|
||||
* decided, so a group falls back to its own call count; a phase's decision
|
||||
* wins over the groups inside it. */
|
||||
export const SoleToolContext = createContext<boolean | undefined>(undefined);
|
||||
export const SoleToolContext: Context<boolean | undefined> = createContext<boolean | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
/** Set by a tool group for its own rows: true when the group holds exactly one
|
||||
* tool call, whatever the phase around it holds. `SoleToolContext` lets the
|
||||
* phase decide whether a card opens by default; this one decides whether the
|
||||
* card's own row is redundant under the group header it sits beneath. */
|
||||
export const LoneGroupContext = createContext<boolean>(false);
|
||||
export const LoneGroupContext: Context<boolean> = createContext<boolean>(false);
|
||||
|
||||
/** Whether a tool card opens by default: the user's "auto-expand tools"
|
||||
* preference, or being the only call inside its group. */
|
||||
export function useToolAutoExpand() {
|
||||
export function useToolAutoExpand(): boolean {
|
||||
const autoExpand = useMessagePartsHost().useAutoExpandTools();
|
||||
const soleTool = useContext(SoleToolContext);
|
||||
return autoExpand || soleTool === true;
|
||||
|
|
@ -78,18 +89,20 @@ export function useToolAutoExpand() {
|
|||
|
||||
/** Asks the enclosing tool-call part to load its stored content in place of a server preview.
|
||||
* `null` outside a part that holds a preview. */
|
||||
export const ToolContentRequestContext = createContext<(() => void) | null>(null);
|
||||
export const ToolContentRequestContext: Context<(() => void) | null> = createContext<
|
||||
(() => void) | null
|
||||
>(null);
|
||||
|
||||
/** True while the enclosing part still shows a server preview, so content actions (copy) would
|
||||
* hand out shortened text. False outside a previewed part. */
|
||||
export const ToolContentPendingContext = createContext(false);
|
||||
export const ToolContentPendingContext: Context<boolean> = createContext(false);
|
||||
|
||||
export function useToolContentPending(): boolean {
|
||||
return useContext(ToolContentPendingContext);
|
||||
}
|
||||
|
||||
/** Requests the part's full content while `active`: its card is open or its panel is showing. */
|
||||
export function useToolContentRequest(active: boolean) {
|
||||
export function useToolContentRequest(active: boolean): void {
|
||||
const request = useContext(ToolContentRequestContext);
|
||||
useEffect(() => {
|
||||
if (active) {
|
||||
|
|
@ -102,7 +115,9 @@ export function useToolContentRequest(active: boolean) {
|
|||
* per-tool atom, so it survives the card remounting when a live batch
|
||||
* regroups. Until they choose, the card follows `useToolAutoExpand` and
|
||||
* closes again if a sole call's group gains a second call. */
|
||||
export function useToolExpansion(canExpand: boolean) {
|
||||
export function useToolExpansion(
|
||||
canExpand: boolean,
|
||||
): readonly [boolean, (update: SetStateAction<boolean | undefined>) => void] {
|
||||
const autoExpand = useToolAutoExpand();
|
||||
const [override, setOverride] = useAtom(useToolDisclosure());
|
||||
const expanded = override ?? (autoExpand && canExpand);
|
||||
|
|
@ -110,9 +125,14 @@ export function useToolExpansion(canExpand: boolean) {
|
|||
return [expanded, setOverride] as const;
|
||||
}
|
||||
|
||||
export type ToolContentQuery = typeof useToolCallPartQuery;
|
||||
/** Loads a stored tool call part; the app's query, or a nested transcript's own. */
|
||||
export type ToolContentQuery = (
|
||||
params: ToolCallPartParams,
|
||||
config?: UseQueryOptions<ToolCallPartResponse>,
|
||||
revision?: string,
|
||||
) => QueryObserverResult<ToolCallPartResponse>;
|
||||
|
||||
/** Undefined uses normal message access; null keeps a nested transcript view-only. */
|
||||
export const ToolContentQueryContext = createContext<ToolContentQuery | null | undefined>(
|
||||
undefined,
|
||||
);
|
||||
export const ToolContentQueryContext: Context<ToolContentQuery | null | undefined> = createContext<
|
||||
ToolContentQuery | null | undefined
|
||||
>(undefined);
|
||||
|
|
@ -9,7 +9,7 @@ import { useCallback, useLayoutEffect, useRef } from 'react';
|
|||
* node leaves the DOM, which is the last moment `document.activeElement` still
|
||||
* says whether the row had focus, and the node can still name its group.
|
||||
*/
|
||||
export default function useRowHandoff(bare: boolean) {
|
||||
export default function useRowHandoff(bare: boolean): (node: HTMLElement | null) => void {
|
||||
const rowNode = useRef<HTMLElement | null>(null);
|
||||
const handoff = useRef<HTMLElement | null>(null);
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { useMemo } from 'react';
|
||||
import { unescapeJsonString } from '@librechat/chat';
|
||||
import { unescapeJsonString } from '../../core/parts/parseJsonField';
|
||||
|
||||
/**
|
||||
* Single-line clamp mirroring the SDK's outcome-label bound
|
||||
Loading…
Add table
Add a link
Reference in a new issue