mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 23:13:35 +00:00
🧮 refactor: Move Pure Part Helpers Into the Chat Package (#17520)
* refactor: Move Pure Part Helpers Into @librechat/chat Tool output parsers (JSON fields, background handles, wakeups, background tasks, command results) and the small routing, params and rerun helpers move from client Content/ into packages/chat/src/core/parts, exported from the package root. Client importers read them from @librechat/chat; parseJsonField becomes a named export so the root barrel can carry it. * test: Cover Wake-Up Turns Rendering as Task Cards * fix: Point the API Background Spec at the Moved Parsers
This commit is contained in:
parent
01211053f5
commit
09a7d13eac
48 changed files with 148 additions and 42 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { v4 } from 'uuid';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { useQuery, useQueries } from '@tanstack/react-query';
|
||||
import { QueryKeys, dataService } from 'librechat-data-provider';
|
||||
import type { TMessage, ParentSubagentSummary } from 'librechat-data-provider';
|
||||
|
|
@ -18,7 +19,6 @@ import {
|
|||
useCancelBackgroundTasksMutation,
|
||||
} from '~/data-provider';
|
||||
import { useParentSubagents } from '~/components/Chat/Subagents/ParentSubagentsProvider';
|
||||
import parseJsonField from '~/components/Chat/Messages/Content/Parts/parseJsonField';
|
||||
import { getToolCallIntent } from '~/components/Chat/Messages/Content/Parts/intent';
|
||||
|
||||
const noThreads: ReadonlyMap<string, ParentSubagentSummary> = new Map();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React, { useEffect, useId, useMemo, useRef, useState, useCallback } from
|
|||
import copy from 'copy-to-clipboard';
|
||||
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';
|
||||
|
|
@ -11,7 +12,6 @@ import {
|
|||
toolPanelSpacingClassName,
|
||||
} from './disclosure';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import { unescapeJsonString } from './Parts/parseJsonField';
|
||||
import MessageIcon from '~/components/Share/MessageIcon';
|
||||
import { useLocalize, useExpandCollapse } from '~/hooks';
|
||||
import { useAgentsMapContext } from '~/Providers';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useContext } from 'react';
|
||||
import { MessageCircleQuestion } from 'lucide-react';
|
||||
import parseJsonField, { parseJsonFieldOccurrences } from './Parts/parseJsonField';
|
||||
import { parseJsonField, parseJsonFieldOccurrences } from '@librechat/chat';
|
||||
import { collectLiveAskToolCallIds } from '~/utils/approval';
|
||||
import { useGetMessagesByConvoId } from '~/data-provider';
|
||||
import { ChatContext } from '~/Providers/ChatContext';
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { useMemo } from 'react';
|
||||
import { Button } from '@librechat/client';
|
||||
import type { BackgroundTaskStatus, BackgroundTaskView } from './Parts/background';
|
||||
import { formatBackgroundCodeOutput } from '@librechat/chat';
|
||||
import type { BackgroundTaskStatus, BackgroundTaskView } from '@librechat/chat';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import { backgroundTaskMessageKey, backgroundTaskNoteKey } from './Parts/guidance';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { ToolIcon, getToolIconType, OutputRenderer } from './ToolOutput';
|
||||
import { useSubagentTaskPanel } from '~/components/Chat/Subagents/task';
|
||||
import { formatBackgroundCodeOutput } from './Parts/background';
|
||||
import { parseToolName } from '~/utils/toolLabels';
|
||||
import { getToolDisplayLabel, cn } from '~/utils';
|
||||
import SubagentProgress from './SubagentProgress';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { findRerunParent } from '@librechat/chat';
|
||||
import { Alert, Button, TextareaAutosize } from '@librechat/client';
|
||||
import { useUpdateMessageContentMutation } from 'librechat-data-provider/react-query';
|
||||
import {
|
||||
|
|
@ -11,7 +12,6 @@ import type { ReactNode } from 'react';
|
|||
import { getPartText, isEditablePart, withPartText } from './editableParts';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import useGetAddedConvo from '~/hooks/Conversations/useGetAddedConvo';
|
||||
import { findRerunParent } from './rerunParent';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { useRef, useEffect, useCallback, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { findRerunParent } from '@librechat/chat';
|
||||
import { Alert, Button, TextareaAutosize } from '@librechat/client';
|
||||
import { useUpdateMessageMutation } from 'librechat-data-provider/react-query';
|
||||
import type { TEditProps } from '~/common';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import useGetAddedConvo from '~/hooks/Conversations/useGetAddedConvo';
|
||||
import { cn, isSubmittableMessage } from '~/utils';
|
||||
import { findRerunParent } from './rerunParent';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import Container from './Container';
|
||||
import EditFiles from './EditFiles';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { memo } from 'react';
|
||||
import { isBashProgrammaticToolCall } from '@librechat/chat';
|
||||
import { Part as ChatPart } from '@librechat/chat/components';
|
||||
import {
|
||||
Tools,
|
||||
|
|
@ -45,7 +46,6 @@ import {
|
|||
import BackgroundTaskCall from './Parts/BackgroundTaskCall';
|
||||
import { getAskUserQuestionPart } from '~/utils/approval';
|
||||
import AskUserQuestionCall from './AskUserQuestionCall';
|
||||
import { isBashProgrammaticToolCall } from './routing';
|
||||
import { isError } from './ToolOutput/OutputRenderer';
|
||||
import { ToolPreparation } from './preparation';
|
||||
import { ErrorMessage } from './MessageContent';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useMemo, useState, useCallback } from 'react';
|
||||
import { backgroundTaskOutcome, parseBackgroundTaskOutput } from '@librechat/chat';
|
||||
import type { PartMetadata, TAttachment } from 'librechat-data-provider';
|
||||
import { backgroundListGuidanceKeys, backgroundTaskNoticeKey } from './guidance';
|
||||
import { backgroundTaskOutcome, parseBackgroundTaskOutput } from './background';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
|
||||
import { useLocalize, useLazyCollapseBody } from '~/hooks';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
import { useMemo, useRef, useState, useCallback, useEffect } from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { Button } from '@librechat/client';
|
||||
import {
|
||||
parseBackgroundHandle,
|
||||
splitBackgroundAttachments,
|
||||
parseJsonField,
|
||||
areToolCallArgsComplete,
|
||||
parseCommandOutput,
|
||||
} from '@librechat/chat';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import { toolPanelSpacingClassName, useToolContentPending } from '../disclosure';
|
||||
import { parseBackgroundHandle, splitBackgroundAttachments } from './handle';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import parseJsonField, { areToolCallArgsComplete } from './parseJsonField';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import CopyButton from '~/components/Messages/Content/CopyButton';
|
||||
import LangIcon from '~/components/Messages/Content/LangIcon';
|
||||
|
|
@ -16,7 +21,6 @@ import useFollowScroll from './useFollowScroll';
|
|||
import { OutputRenderer } from '../ToolOutput';
|
||||
import { ERROR_PATTERNS } from './ExecuteCode';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import { parseCommandOutput } from './command';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import PtcToolTrace from './PtcToolTrace';
|
||||
import BareStatus from './BareStatus';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useMemo } from 'react';
|
||||
import { SquareTerminal } from 'lucide-react';
|
||||
import { parseBackgroundHandle, splitBackgroundAttachments } from '@librechat/chat';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import { parseBackgroundHandle, splitBackgroundAttachments } from './handle';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useMemo } from 'react';
|
||||
import { FilePenLine, FilePlus2 } from 'lucide-react';
|
||||
import { parseJsonField, parseJsonFieldOccurrences } from '@librechat/chat';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import DiffView, {
|
||||
parseUnifiedDiff,
|
||||
|
|
@ -7,7 +8,6 @@ import DiffView, {
|
|||
diffPreviewText,
|
||||
type TextEditPreview,
|
||||
} from './DiffView';
|
||||
import parseJsonField, { parseJsonFieldOccurrences } from './parseJsonField';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
import useToolCallState from './useToolCallState';
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { useMemo } from 'react';
|
||||
import { Brain } from 'lucide-react';
|
||||
import { Tools } from 'librechat-data-provider';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
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 parseJsonField from './parseJsonField';
|
||||
import MemoryInfo from '../MemoryInfo';
|
||||
import BareStatus from './BareStatus';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useMemo } from 'react';
|
||||
import { FileText } from 'lucide-react';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
|
||||
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
|
||||
import { toolPanelSpacingClassName } from '../disclosure';
|
||||
|
|
@ -7,7 +8,6 @@ import useToolCallState from './useToolCallState';
|
|||
import useLazyHighlight from './useLazyHighlight';
|
||||
import CodeWindowHeader from './CodeWindowHeader';
|
||||
import { AttachmentGroup } from './Attachment';
|
||||
import parseJsonField from './parseJsonField';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import BareStatus from './BareStatus';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { useMemo } from 'react';
|
||||
import { ScrollText } from 'lucide-react';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
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 parseJsonField from './parseJsonField';
|
||||
import { useToolCallIntent } from './intent';
|
||||
import { TOOL_ROW_CLASSES } from '../rows';
|
||||
import BareStatus from './BareStatus';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useCallback, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { ChevronRight, Users } from 'lucide-react';
|
||||
import { parseSubagentBackgroundHandle } from '@librechat/chat';
|
||||
import { ContentTypes, EModelEndpoint } from 'librechat-data-provider';
|
||||
import type {
|
||||
PartMetadata,
|
||||
|
|
@ -25,7 +26,6 @@ import { tailOverflowDirection } from '~/utils/subagentContent';
|
|||
import { MessageContext } from '~/Providers/MessageContext';
|
||||
import { useShareContext } from '~/Providers/ShareContext';
|
||||
import MessageIcon from '~/components/Share/MessageIcon';
|
||||
import { parseSubagentBackgroundHandle } from './handle';
|
||||
import { MCPAppViews } from '~/components/MCPUIResource';
|
||||
import { isError } from '../ToolOutput/OutputRenderer';
|
||||
import { useToolPreparation } from '../preparation';
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { parseBackgroundTaskOutput } from '@librechat/chat';
|
||||
import {
|
||||
backgroundListGuidanceKeys,
|
||||
backgroundTaskMessageKey,
|
||||
backgroundTaskNoteKey,
|
||||
backgroundTaskNoticeKey,
|
||||
} from '../guidance';
|
||||
import { parseBackgroundTaskOutput } from '../background';
|
||||
|
||||
describe('background task host guidance', () => {
|
||||
it.each([
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { BackgroundTaskDisplay } from './background';
|
||||
import type { BackgroundTaskDisplay } from '@librechat/chat';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
|
||||
const RAW_DETAILS_KEY: TranslationKeys = 'com_ui_background_tasks_more_in_raw_details';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { useMemo } from 'react';
|
||||
import { unescapeJsonString } from './parseJsonField';
|
||||
import { unescapeJsonString } from '@librechat/chat';
|
||||
|
||||
/**
|
||||
* Single-line clamp mirroring the SDK's outcome-label bound
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React, { useMemo, useState, useEffect, useContext, useCallback } from 'react';
|
||||
import { Button } from '@librechat/client';
|
||||
import { hasToolParams } from '@librechat/chat';
|
||||
import {
|
||||
Constants,
|
||||
dataService,
|
||||
|
|
@ -27,7 +28,6 @@ import { AttachmentGroup } from './Parts';
|
|||
import ToolCallInfo from './ToolCallInfo';
|
||||
import ProgressText from './ProgressText';
|
||||
import { TOOL_ROW_CLASSES } from './rows';
|
||||
import { hasToolParams } from './params';
|
||||
import { ToolAuthWarning } from './auth';
|
||||
import { firstErrorLine } from './live';
|
||||
import useRowHandoff from './handoff';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { useState, useMemo } from 'react';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
import { hasToolParams } from '@librechat/chat';
|
||||
import { useLocalize, useExpandCollapse } from '~/hooks';
|
||||
import { OutputRenderer } from './ToolOutput';
|
||||
import { hasToolParams } from './params';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
function isSimpleObject(obj: unknown): obj is Record<string, string | number | boolean | null> {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
SystemEventIcon,
|
||||
systemEventHeaderClasses,
|
||||
} from '@librechat/chat/components';
|
||||
import type { WakeupDisplay, WakeupTask } from './Parts/wakeup';
|
||||
import type { WakeupDisplay, WakeupTask } from '@librechat/chat';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import { subagentStatusIcon, subagentStatusLabelKey } from '~/components/Chat/Subagents/status';
|
||||
import { useLocalize, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useMemo, useState } from 'react';
|
||||
import { Tools } from 'librechat-data-provider';
|
||||
import { parseJsonField } from '@librechat/chat';
|
||||
import { Globe, ChevronDown, Info } from 'lucide-react';
|
||||
import {
|
||||
Button,
|
||||
|
|
@ -22,7 +23,6 @@ import { useLocalize, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
|
|||
import { collectSources, getUniqueDomainSources } from './sources';
|
||||
import { StackedFavicons } from '~/components/Web/Sources';
|
||||
import { isError } from './ToolOutput/OutputRenderer';
|
||||
import parseJsonField from './Parts/parseJsonField';
|
||||
import { useToolCallIntent } from './Parts/intent';
|
||||
import { useToolPreparation } from './preparation';
|
||||
import { useSearchContext } from '~/Providers';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { areToolCallArgsComplete } from '@librechat/chat';
|
||||
import type { ToolPreparationInput } from '../preparation';
|
||||
import { isToolCallPreparing, ToolPreparation } from '../preparation';
|
||||
import { areToolCallArgsComplete } from '../Parts/parseJsonField';
|
||||
import ProgressText from '../ProgressText';
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
|
|
|
|||
|
|
@ -1,4 +1,12 @@
|
|||
import { Tools, Constants, ContentTypes, ToolCallTypes } from 'librechat-data-provider';
|
||||
import {
|
||||
backgroundTaskOutcome,
|
||||
parseBackgroundTaskOutput,
|
||||
parseBackgroundHandle,
|
||||
splitBackgroundAttachments,
|
||||
isBashProgrammaticToolCall,
|
||||
parseCommandOutput,
|
||||
} from '@librechat/chat';
|
||||
import type {
|
||||
Agents,
|
||||
TAttachment,
|
||||
|
|
@ -7,13 +15,9 @@ import type {
|
|||
TMessageContentParts,
|
||||
} from 'librechat-data-provider';
|
||||
import type { ToolPreparationInput } from './preparation';
|
||||
import { backgroundTaskOutcome, parseBackgroundTaskOutput } from './Parts/background';
|
||||
import { parseBackgroundHandle, splitBackgroundAttachments } from './Parts/handle';
|
||||
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
|
||||
import { isMemoryFailureOutput } from './Parts/MemoryCall';
|
||||
import { filterAttachmentsForPart } from '~/utils/map';
|
||||
import { isBashProgrammaticToolCall } from './routing';
|
||||
import { parseCommandOutput } from './Parts/command';
|
||||
import { isToolCallPreparing } from './preparation';
|
||||
import { isError } from './ToolOutput';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { createContext, useContext } from 'react';
|
||||
import { areToolCallArgsComplete } from '@librechat/chat';
|
||||
import { Constants, actionDelimiter } from 'librechat-data-provider';
|
||||
import type { PartMetadata } from 'librechat-data-provider';
|
||||
import { areToolCallArgsComplete } from './Parts/parseJsonField';
|
||||
import { getToolDisplayLabel } from '~/utils/toolLabels';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { memo, useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { parseWakeupMessage } from '@librechat/chat';
|
||||
import { ChevronUp, ChevronDown } from 'lucide-react';
|
||||
import { ContentTypes } from 'librechat-data-provider';
|
||||
import { pxToRem, useRemScale } from '@librechat/client';
|
||||
import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import { useMessagesConversation, useMessagesSubmission } from '~/Providers';
|
||||
import { parseWakeupMessage } from './Content/Parts/wakeup';
|
||||
import { useGetMessagesByConvoId } from '~/data-provider';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React, { useCallback, useMemo, memo } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { parseWakeupMessage } from '@librechat/chat';
|
||||
import {
|
||||
revealOnRowHoverClasses,
|
||||
messageFooterClasses,
|
||||
|
|
@ -19,7 +20,6 @@ import {
|
|||
areMessageFieldsEqual,
|
||||
getHeaderPrefixForScreenReader,
|
||||
} from '~/utils';
|
||||
import { parseWakeupMessage } from '~/components/Chat/Messages/Content/Parts/wakeup';
|
||||
import MessageContent from '~/components/Chat/Messages/Content/MessageContent';
|
||||
import { useLocalize, useMessageActions, useContentMetadata } from '~/hooks';
|
||||
import { PrivateText } from '~/components/Chat/Messages/PrivateText';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useMemo } from 'react';
|
||||
import { MessageRow } from '@librechat/chat/components';
|
||||
import type { WakeupTask } from '@librechat/chat';
|
||||
import type { ComponentProps } from 'react';
|
||||
import type { WakeupTask } from '../Content/Parts/wakeup';
|
||||
import {
|
||||
messageAuthor,
|
||||
resolveSubagentAuthor,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { parseSubagentBackgroundHandle } from '@librechat/chat';
|
||||
import { Constants, ContentTypes } from 'librechat-data-provider';
|
||||
import type { SubagentIdentity, TMessage } from 'librechat-data-provider';
|
||||
import { parseSubagentBackgroundHandle } from '~/components/Chat/Messages/Content/Parts/handle';
|
||||
|
||||
type Dispatch = {
|
||||
message: TMessage;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { useMemo } from 'react';
|
||||
import { parseWakeupMessage } from '@librechat/chat';
|
||||
import { getHeaderHoverLabel, SiblingSwitch, SubRow, MessageRow } from '@librechat/chat/components';
|
||||
import type { TMessageProps } from '~/common';
|
||||
import SearchContent, {
|
||||
rendersMarkdownLite,
|
||||
} from '~/components/Chat/Messages/Content/SearchContent';
|
||||
import { parseWakeupMessage } from '~/components/Chat/Messages/Content/Parts/wakeup';
|
||||
import AuthorHeader from '~/components/Chat/Messages/Content/Parts/AuthorHeader';
|
||||
import MinimalHoverButtons from '~/components/Chat/Messages/MinimalHoverButtons';
|
||||
import MessageContent from '~/components/Chat/Messages/Content/MessageContent';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { parseWakeupMessage } from '@librechat/chat';
|
||||
import { ContentTypes, SearchResultData } from 'librechat-data-provider';
|
||||
import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { MarkdownVariant, RichTextMode } from '~/utils/richtext';
|
||||
|
|
@ -11,7 +12,6 @@ import {
|
|||
STANDALONE_PATTERN,
|
||||
INVALID_CITATION_REGEX,
|
||||
} from '~/utils/citations';
|
||||
import { parseWakeupMessage } from '~/components/Chat/Messages/Content/Parts/wakeup';
|
||||
import { markdownToHtml } from '~/utils/richtext';
|
||||
import store from '~/store';
|
||||
|
||||
|
|
|
|||
88
e2e/specs/mock/scenarios/wakeup-row.spec.ts
Normal file
88
e2e/specs/mock/scenarios/wakeup-row.spec.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
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';
|
||||
|
||||
const WAKEUP_PROMPT = [
|
||||
'A background tool task has finished. Continue using its durable result below.',
|
||||
JSON.stringify([
|
||||
{
|
||||
background_task_id: 'task-1',
|
||||
tool_call_id: 'call-1',
|
||||
tool: 'execute_code',
|
||||
status: 'completed',
|
||||
result: 'build finished',
|
||||
},
|
||||
]),
|
||||
].join('\n');
|
||||
|
||||
/** A host-authored wake-up turn and the reply it resumed, seeded straight into
|
||||
* Mongo: the mock model cannot settle a background task. */
|
||||
async function seedWakeup(text: string) {
|
||||
const conversationId = randomUUID();
|
||||
const wakeupId = randomUUID();
|
||||
const messages: SeedMessage[] = [
|
||||
{
|
||||
messageId: wakeupId,
|
||||
parentMessageId: ROOT_PARENT,
|
||||
text,
|
||||
isCreatedByUser: true,
|
||||
sender: 'User',
|
||||
},
|
||||
{
|
||||
messageId: randomUUID(),
|
||||
parentMessageId: wakeupId,
|
||||
text: 'The build is done.',
|
||||
isCreatedByUser: false,
|
||||
sender: 'OpenAI',
|
||||
},
|
||||
];
|
||||
await seedConversations(userEmail, [
|
||||
{ conversationId, title: `Wakeup ${conversationId.slice(0, 8)}`, updatedAt: new Date() },
|
||||
]);
|
||||
await seedMessages(userEmail, conversationId, messages);
|
||||
return conversationId;
|
||||
}
|
||||
|
||||
async function cleanup(conversationId: string) {
|
||||
await deleteMessagesByConversation([conversationId]);
|
||||
await deleteConversations([conversationId]);
|
||||
}
|
||||
|
||||
test.describe('wake-up turns', () => {
|
||||
test('a background task wake-up renders as a task card, not its prompt @scenario:background-wakeup-renders-task-card', async ({
|
||||
page,
|
||||
}) => {
|
||||
const conversationId = await seedWakeup(WAKEUP_PROMPT);
|
||||
try {
|
||||
await page.goto(`/c/${conversationId}`);
|
||||
await expect(page.getByText('The build is done.')).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Background task finished' })).toBeVisible();
|
||||
await expect(page.getByText('"background_task_id"')).toHaveCount(0);
|
||||
} finally {
|
||||
await cleanup(conversationId);
|
||||
}
|
||||
});
|
||||
|
||||
test('a user turn quoting a wake-up prompt mid-message stays plain text @scenario:quoted-wakeup-prompt-stays-text', async ({
|
||||
page,
|
||||
}) => {
|
||||
const conversationId = await seedWakeup(`Why did I get this?\n${WAKEUP_PROMPT}`);
|
||||
try {
|
||||
await page.goto(`/c/${conversationId}`);
|
||||
await expect(page.getByText('Why did I get this?')).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Background task finished' })).toHaveCount(0);
|
||||
} finally {
|
||||
await cleanup(conversationId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -36,8 +36,8 @@ import {
|
|||
SUBAGENT_COMPLETION_DELIVERY,
|
||||
SUBAGENT_POLL_WAKEUP_GUIDANCE,
|
||||
} from './subagentDelivery';
|
||||
import { parseBackgroundTaskOutput } from '../../../../client/src/components/Chat/Messages/Content/Parts/background';
|
||||
import { parseBackgroundHandle } from '../../../../client/src/components/Chat/Messages/Content/Parts/handle';
|
||||
import { parseBackgroundTaskOutput } from '../../../chat/src/core/parts/background';
|
||||
import { parseBackgroundHandle } from '../../../chat/src/core/parts/handle';
|
||||
import { SubagentTaskOwnerUnavailableError } from './subagentTaskRouting';
|
||||
import { TOOL_SELECTION_WILDCARD } from './selection';
|
||||
import { toolOptionsSchema } from './validation';
|
||||
|
|
|
|||
|
|
@ -16,3 +16,4 @@ export * from './usage';
|
|||
export * from './regenerate';
|
||||
export * from './content';
|
||||
export * from './turns';
|
||||
export * from './parts';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import parseJsonField, {
|
||||
import {
|
||||
parseJsonField,
|
||||
parseJsonFieldOccurrences,
|
||||
areToolCallArgsComplete,
|
||||
} from '../parseJsonField';
|
||||
8
packages/chat/src/core/parts/index.ts
Normal file
8
packages/chat/src/core/parts/index.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export * from './parseJsonField';
|
||||
export * from './handle';
|
||||
export * from './wakeup';
|
||||
export * from './background';
|
||||
export * from './command';
|
||||
export * from './routing';
|
||||
export * from './params';
|
||||
export * from './rerunParent';
|
||||
|
|
@ -97,7 +97,7 @@ export function unescapeJsonString(value: string, streaming = true): string {
|
|||
}
|
||||
|
||||
/** Extracts a string field from tool call args, handling object, JSON string, and partial-JSON fallback. */
|
||||
export default function parseJsonField(args: ToolCallArgs, field: string): string {
|
||||
export function parseJsonField(args: ToolCallArgs, field: string): string {
|
||||
if (typeof args === 'object' && args !== null) {
|
||||
return String(args[field] ?? '');
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { Constants } from 'librechat-data-provider';
|
||||
import parseJsonField from './Parts/parseJsonField';
|
||||
import { parseJsonField } from './parseJsonField';
|
||||
|
||||
const PYTHON_PROGRAMMATIC_LANGS = new Set(['py', 'python']);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue