Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changeset/comment-composer-agent-menu-catalog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] The catalog words both lines of each agent in the comment composer's `/` menu: `@astryx.commentComposer.agentCommandUsage` ("/{command} '<prompt>'") and `@astryx.commentComposer.agentCommandSummary` ("{name} · {description}"), so a locale can translate the placeholder word and the separator. English output is unchanged.

@ernestt
8 changes: 8 additions & 0 deletions packages/core/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,14 @@
"defaultMessage": "Agents",
"description": "Accessible name of a lab CommentComposer's slash-command menu, which lists the AI agents a comment can address."
},
"@astryx.commentComposer.agentCommandUsage": {
"defaultMessage": "/{command} '<prompt>'",
"description": "First line of an AI agent in a lab CommentComposer's slash-command menu: how to address the agent. {command} is the command after the slash, such as ask. Keep /{command}. Translate only the word prompt, the placeholder for what the viewer asks; the apostrophes keep the angle brackets as text."
},
"@astryx.commentComposer.agentCommandSummary": {
"defaultMessage": "{name} · {description}",
"description": "Second line of an AI agent in a lab CommentComposer's slash-command menu. {name} is the agent's name and {description} says what asking it does; the app writes both."
},
"@astryx.commentComposer.uploadFailed": {
"defaultMessage": "Images couldn't be added",
"description": "Error Banner title in a lab CommentComposer when uploading attached images failed; a Retry action follows."
Expand Down
38 changes: 38 additions & 0 deletions packages/lab/src/Comments/CommentComposer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type ComponentProps,
} from 'react';
import {act, fireEvent, render, screen, within} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
afterAll,
afterEach,
Expand Down Expand Up @@ -36,6 +37,7 @@ vi.mock('../EmojiPicker/emojiData', () => ({
],
}));

import {InternationalizationProvider} from '@astryxdesign/core/i18n';
import {CommentComposer, CommentComposerBase} from './CommentComposer';

const originalMatches = HTMLElement.prototype.matches;
Expand Down Expand Up @@ -125,6 +127,42 @@ describe('CommentComposer', () => {
expect(onAncestorClick).toHaveBeenCalledTimes(1);
});

it('words the agent command menu through the catalog', async () => {
const user = userEvent.setup();
function Host() {
const [value, setValue] = useState('');
return (
<InternationalizationProvider
locale="fr"
overrides={{
fr: {
'@astryx.commentComposer.agentCommandUsage':
"/{command} '<demande>'",
'@astryx.commentComposer.agentCommandSummary':
'{name} : {description}',
},
}}>
<CommentComposer
value={value}
onChange={setValue}
onSubmit={vi.fn()}
agentCommands={[
{
command: 'ask',
name: 'Assistant',
description: 'Répond aux questions',
},
]}
/>
</InternationalizationProvider>
);
}
render(<Host />);
await user.type(screen.getByRole('combobox'), '/');
expect(await screen.findByText('/ask <demande>')).toBeTruthy();
expect(screen.getByText('Assistant : Répond aux questions')).toBeTruthy();
});

it('posts the draft from Post, and never an empty one', async () => {
const onSubmit = vi.fn();
const {rerender} = render(
Expand Down
21 changes: 17 additions & 4 deletions packages/lab/src/Comments/CommentComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ type AgentCommandItem = ChatComposerTriggerItem & {
auxiliaryData: CommentAgentCommand;
};

function renderAgentCommandItem(item: ChatComposerTriggerItem): ReactNode {
const agent = (item as AgentCommandItem).auxiliaryData;
function AgentCommandOption({agent}: {agent: CommentAgentCommand}) {
const t = useTranslator();
return (
<HStack gap={2} align="center">
<Avatar
Expand All @@ -128,15 +128,28 @@ function renderAgentCommandItem(item: ChatComposerTriggerItem): ReactNode {
tooltip={false}
/>
<VStack gap={0.5}>
<Text weight="semibold">{`/${agent.command} <prompt>`}</Text>
<Text weight="semibold">
{t('@astryx.commentComposer.agentCommandUsage', {
command: agent.command,
})}
</Text>
<Text type="supporting" color="secondary">
{`${agent.name} · ${agent.description}`}
{t('@astryx.commentComposer.agentCommandSummary', {
name: agent.name,
description: agent.description,
})}
</Text>
</VStack>
</HStack>
);
}

function renderAgentCommandItem(item: ChatComposerTriggerItem): ReactNode {
return (
<AgentCommandOption agent={(item as AgentCommandItem).auxiliaryData} />
);
}

/** The `/` menu of the agents a comment can address, or null for none. */
function useAgentCommandTrigger(
agents: readonly CommentAgentCommand[],
Expand Down