Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion client/src/components/Artifacts/Artifact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import throttle from 'lodash/throttle';
import { visit } from 'unist-util-visit';
import { useSetRecoilState } from 'recoil';
import { useLocation } from 'react-router-dom';
import { useIsPartsPreview } from '@librechat/chat/react';
import type { Pluggable } from 'unified';
import type { Artifact } from '~/common';
import { useMessageContext, useArtifactContext } from '~/Providers';
Expand Down Expand Up @@ -48,6 +49,8 @@ export function Artifact({
node: unknown;
}) {
const location = useLocation();
/** A picture of a row drawn elsewhere: the row itself registers the artifact. */
const isPreview = useIsPartsPreview();
const { messageId } = useMessageContext();
const { getNextIndex, resetCounter } = useArtifactContext();
const artifactIndex = useRef(getNextIndex(false)).current;
Expand Down Expand Up @@ -89,7 +92,7 @@ export function Artifact({
lastUpdateTime: now,
};

if (!isArtifactRoute(location.pathname)) {
if (isPreview || !isArtifactRoute(location.pathname)) {
return setArtifact(currentArtifact);
}

Expand Down Expand Up @@ -118,6 +121,7 @@ export function Artifact({
messageId,
artifactIndex,
location.pathname,
isPreview,
]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { RecoilRoot, useRecoilValue } from 'recoil';
import { act, render } from '@testing-library/react';
import { PartsPreviewContext } from '@librechat/chat/react';
import type { ReactNode } from 'react';
import { MessageContext, ArtifactProvider } from '~/Providers';
import { artifactsState } from '~/store/artifacts';
import { Artifact } from '../Artifact';

jest.mock('../ArtifactButton', () => ({
__esModule: true,
default: () => null,
}));

let registered: Record<string, unknown> | null | undefined;

function Registry(): null {
registered = useRecoilValue(artifactsState) as Record<string, unknown> | null;
return null;
}

const message = {
messageId: 'message-1',
conversationId: 'conversation-1',
partIndex: 0,
isExpanded: false,
isSubmitting: false,
isLatestMessage: false,
} as unknown as React.ContextType<typeof MessageContext>;

const page = (ui: ReactNode) => (
<RecoilRoot>
<MemoryRouter initialEntries={['/c/conversation-1']}>
<MessageContext.Provider value={message}>
<ArtifactProvider>
<Registry />
{ui}
</ArtifactProvider>
</MessageContext.Provider>
</MemoryRouter>
</RecoilRoot>
);

const artifact = (
<Artifact identifier="chart" title="Chart" type="text/html" node={null}>

Check failure on line 46 in client/src/components/Artifacts/__tests__/Artifact.preview.test.tsx

View workflow job for this annotation

GitHub Actions / TypeScript type checks (client)

TS2739

Type '{ identifier: string; title: string; type: string; node: null; children: string; }' is missing the following properties from type 'Artifact': id, lastUpdateTime
{'<p>hello</p>'}
</Artifact>
);

const settle = () =>
act(async () => {
await new Promise((resolve) => setTimeout(resolve, 80));
});

describe('Artifact registration', () => {
beforeEach(() => {
registered = undefined;
});

it('registers an artifact a message row draws', async () => {
render(page(artifact));
await settle();

expect(Object.keys(registered ?? {})).toEqual(['chart_text/html_chart_message-1']);
});

it('registers nothing for a picture of a row drawn elsewhere', async () => {
render(
page(<PartsPreviewContext.Provider value={true}>{artifact}</PartsPreviewContext.Provider>),
);
await settle();

expect(Object.keys(registered ?? {})).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useMessageContext } from '~/Providers/MessageContext';
import { useShareContext } from '~/Providers/ShareContext';
import MessageIcon from '~/components/Share/MessageIcon';
import { MCPAppViews } from '~/components/MCPUIResource';
import { useMCPServerNames } from '~/hooks/MCP';
import { useLocalize } from '~/hooks';

const agentMessage = { endpoint: EModelEndpoint.agents, isCreatedByUser: false } as TMessage;
Expand All @@ -28,7 +27,6 @@ export default function SubagentCall(props: SubagentCallProps) {
const message = useMessageContext();
const share = useShareContext();
const agentsMap = useAgentsMapContext();
const mcpServerNames = useMCPServerNames();
const translate = useLocalize();
const localize = useCallback<SubagentCallContext['localize']>(
(key, values) => translate(key as TranslationKeys, values),
Expand All @@ -40,7 +38,6 @@ export default function SubagentCall(props: SubagentCallProps) {
{...share}
message={message}
agentsMap={agentsMap}
mcpServerNames={mcpServerNames}
localize={localize}
renderAgentIcon={renderAgentIcon}
renderAttachments={renderAttachments}
Expand Down
5 changes: 0 additions & 5 deletions client/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3500,11 +3500,6 @@
"com_ui_subagent_trigger_truncated": "Trigger summary shortened for display.",
"com_ui_subagent_turn": "Turn",
"com_ui_subagent_running": "Running agent",
"com_ui_subagent_ticker_error": "Error",
"com_ui_subagent_ticker_reasoning": "Reasoning",
"com_ui_subagent_ticker_tool_done": "done",
"com_ui_subagent_ticker_using": "Using",
"com_ui_subagent_ticker_writing": "Writing",
"com_ui_subagent_waiting": "Working…",
"com_ui_submit": "Submit",
"com_ui_submit_decisions": "Submit {{0}} decisions",
Expand Down
43 changes: 30 additions & 13 deletions e2e/specs/mock/subagent-activity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,29 @@ test.describe('detached subagent activity', () => {
await expect(cards).toHaveCount(2, { timeout: 30_000 });
await expect(cards.first()).toHaveAttribute('data-subagent-thread', /.+/);
const firstThreadId = (await cards.first().getAttribute('data-subagent-thread')) ?? '';
const threadReadPromise = page.waitForResponse((candidate) => {
const read = THREAD_MESSAGES_PATH.exec(new URL(candidate.url()).pathname);
return read != null && decodeURIComponent(read[1]) === firstThreadId;
});
const attachesOf = (threadId: string) =>
streamAttaches.filter((attached) => attached === threadId).length;

/** With no panel open, each running child's card shows the row its thread is on: the
* thread's own content, drawn by the thread's renderer, one row at a time. The page
* follows each child once for that. */
const rows = page.locator('[data-subagent-preview]');
await expect(rows).toHaveCount(2, { timeout: 30_000 });
await expect(rows.first()).toContainText(/child-1-phase-\d+/);
await expect(rows.nth(1)).toContainText(/child-2-phase-\d+/);
await expect(cards.first()).toContainText('Running');
await expect.poll(() => messageReads).toContain(firstThreadId);
/** A collapsed group shows no cards and follows nothing, so the count so far depends on
* how long the group stood open before the parent's turn ended. What is fixed is that the
* child is being followed now, and that opening it adds no stream of its own. */
const followedByCard = attachesOf(firstThreadId);
expect(followedByCard).toBeGreaterThanOrEqual(1);
await cards.first().click();

/** The child's thread opens as a conversation: its messages, read through the parent, and
* its own generation stream while it runs. The bounded activity feed is not read at all. */
* the generation stream the card was already reading. The bounded activity feed is not
* read at all. */
const panel = childActivityPanel(page);
expect((await threadReadPromise).ok()).toBeTruthy();
await expect(panel).toBeVisible();
await expect(panel).toContainText('child-1-phase-10');
await expect(panel.getByText('Running', { exact: true })).toHaveCount(0);
Expand All @@ -182,12 +195,13 @@ test.describe('detached subagent activity', () => {
timeout: 30_000,
});
await expect(panel.getByText('Completed', { exact: true })).toHaveCount(0);
const attachesOf = (threadId: string) =>
streamAttaches.filter((attached) => attached === threadId).length;
/** At most one attachment, and none added once the run is over: a finished child is read
* from its stored messages, and a running one is followed by a single stream. */
/** One attachment for the card and the panel together, and none added once the run is
* over: a finished child is read from its stored messages. Its card drops its row. */
const attaches = attachesOf(firstThreadId);
expect(attaches).toBeLessThanOrEqual(1);
expect(attaches).toBe(followedByCard);
await expect(
cards.first().locator('xpath=..').locator('[data-subagent-preview]'),
).toHaveCount(0);
await page.waitForTimeout(ACTIVITY_RECONNECT_GUARD_MS);
expect(attachesOf(firstThreadId)).toBe(attaches);
expect(messageReads).toContain(firstThreadId);
Expand Down Expand Up @@ -228,9 +242,12 @@ test.describe('detached subagent activity', () => {
});
});

/** A subagent card's row is a picture of the child's thread, not part of this one: its folds
* take no pointer and are not this history's to expand. */
const NOT_A_PREVIEW = ':not([data-subagent-preview] *)';
const HISTORY_FOLDS =
'[data-fold-root] > div > button[aria-expanded="false"]:visible, ' +
'[data-testid="activity-phase-card"] > div > div > button[aria-expanded="false"]:visible';
`[data-fold-root] > div > button[aria-expanded="false"]${NOT_A_PREVIEW}:visible, ` +
`[data-testid="activity-phase-card"] > div > div > button[aria-expanded="false"]${NOT_A_PREVIEW}:visible`;

/** How long a click waits for a fold that was counted a moment ago. */
const FOLD_CLICK_TIMEOUT_MS = 1_000;
Expand Down
Loading
Loading