fix(assistant): readable cards for any tool, and the CI round

- A card for a tool without one of its own names what it works on: the place
  of an assignment, the day, the note, the booking; its arguments sit under
  the labels the other cards use, a new order reads as the names in order.
  28 frequent tools carry their own action name in every language.
- The server's own steps without a card still refuse, as before.
- Tests: the rate limit is asked one request after another, the mention list
  closes on the caret move a browser reports, the place factory hands its
  category over as a plain id, eleven files formatted.
This commit is contained in:
Maurice
2026-10-21 22:28:34 +02:00
parent 4406d5085f
commit c37d3f773e
47 changed files with 1019 additions and 76 deletions
@@ -152,7 +152,10 @@ function useInstanceConnection(onChanged: () => void) {
live,
provider,
models: live
? modelOptions(models, live.model, { free: t('assistant.model.free'), recommended: t('assistant.model.recommended') })
? modelOptions(models, live.model, {
free: t('assistant.model.free'),
recommended: t('assistant.model.recommended'),
})
: [],
busy,
setModel,
@@ -125,13 +125,20 @@ function KindTile({
}
/** The verb as a quiet line over the name of what it touches. */
/** What the change does: the tool's own action where TREK names it, else add, change or remove. */
function verbLabel(preview: AssistantChangePreview, t: (key: string) => string): string {
const own = preview.tool ? `assistant.tool.${preview.tool}` : null;
const named = own ? t(own) : null;
return named && named !== own ? named : t(`assistant.change.verb.${preview.verbKey}`);
}
function ChangeHead({ preview, struck = false }: { preview: AssistantChangePreview | null; struck?: boolean }) {
const { t } = useTranslation();
if (!preview) return <span className="trek-skeleton inline-block h-4 w-40" aria-hidden="true" />;
return (
<span className="flex min-w-0 flex-col">
<span className="flex min-w-0 items-center gap-1.5 text-caption text-content-muted">
<span className="truncate">{t(`assistant.change.verb.${preview.verbKey}`)}</span>
<span className="truncate">{verbLabel(preview, t)}</span>
{preview.domain && (
// Where in TREK a change outside the trip plan lands: the vacation planner, the journal.
<span className="flex-shrink-0 rounded-full bg-surface-secondary px-1.5 font-medium text-content-secondary">
@@ -80,6 +80,8 @@ describe('AssistantComposer mentions', () => {
fireEvent.keyDown(field, { key: 'Enter' });
await waitFor(() => expect(field.value).toBe('Is @Louvre '));
expect(send).not.toHaveBeenCalled();
// A browser reports where the caret went after the pick; jsdom does not on its own.
fireEvent.select(field);
await waitFor(() => expect(screen.queryByRole('listbox')).toBeNull());
expect(mentions()).toEqual([{ kind: 'place', id: 21, label: 'Louvre' }]);
expect(chatOf(useAssistantStore.getState(), TRIP).draft).toBe('Is @Louvre ');
@@ -98,7 +98,14 @@ describe('AssistantError', () => {
it('FE-AI-ERR-006: an own key that stopped working says so before anything is sent', () => {
withError(null, {
...STATUS,
own: { scope: 'user', kind: 'anthropic', model: 'claude', hint: '…a1b2', status: 'error', host: 'api.anthropic.com' },
own: {
scope: 'user',
kind: 'anthropic',
model: 'claude',
hint: '…a1b2',
status: 'error',
host: 'api.anthropic.com',
},
});
renderLine();
fireEvent.click(screen.getByRole('button', { name: 'Replace key' }));
@@ -103,7 +103,7 @@ function HintRow({
className={`absolute grid place-items-center rounded-lg text-content-faint transition-opacity hover:bg-surface-hover hover:text-content ${
phone
? 'end-0.5 top-0.5 h-10 w-10'
: 'end-1 top-1 h-7 w-7 [@media(hover:hover)]:opacity-0 focus-visible:opacity-100 group-focus-within:opacity-100 group-hover:opacity-100'
: 'end-1 top-1 h-7 w-7 focus-visible:opacity-100 group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:hover)]:opacity-0'
}`}
>
<X size={13} aria-hidden="true" />
@@ -35,7 +35,9 @@ export default function AssistantLauncher({
const open = useAssistantStore((s) => s.window.open && !s.window.minimized);
const toggle = useAssistantStore((s) => s.toggle);
// An answer still being written in a closed window: the floating button breathes until it is opened.
const busy = useAssistantStore((s) => !s.window.open || s.window.minimized ? Object.values(s.byTrip).some((c) => c?.isRunning) : false);
const busy = useAssistantStore((s) =>
!s.window.open || s.window.minimized ? Object.values(s.byTrip).some((c) => c?.isRunning) : false
);
const keys = useAssistantShortcutKeys();
const hints = useAssistantHints(variant === 'floating' ? tripId : null, { withStays: false });
const floating = useRef<HTMLButtonElement>(null);
@@ -86,7 +88,10 @@ export default function AssistantLauncher({
}}
>
{busy && (
<span aria-hidden="true" className="trek-assistant-busy absolute inset-0 rounded-full border-2 border-current opacity-40" />
<span
aria-hidden="true"
className="trek-assistant-busy absolute inset-0 rounded-full border-2 border-current opacity-40"
/>
)}
<Sparkles size={20} aria-hidden="true" />
{hints.unseenWarn > 0 && (
@@ -9,7 +9,14 @@ import { splitMentions } from './assistantMentionModel';
* the question's own mentions part, so a stray `@` in the text stays text.
*/
export default function AssistantMentionText({ text, items }: { text: string; items: AssistantMentions['items'] }) {
const segments = useMemo(() => splitMentions(text, items.map((i) => i.label)), [text, items]);
const segments = useMemo(
() =>
splitMentions(
text,
items.map((i) => i.label)
),
[text, items]
);
return (
<>
{segments.map((s) =>
@@ -144,9 +144,7 @@ export function splitMentions(text: string, labels: readonly string[]): MentionS
let i = 0;
while (i < text.length) {
const token =
text[i] === '@'
? tokens.find((tk) => text.startsWith(tk, i) && endsWord(text, i + tk.length))
: undefined;
text[i] === '@' ? tokens.find((tk) => text.startsWith(tk, i) && endsWord(text, i + tk.length)) : undefined;
if (token) {
if (i > start) out.push({ text: text.slice(start, i), at: start, mention: false });
out.push({ text: token, at: i, mention: true });
@@ -251,6 +251,7 @@ export function undoLeftMs(applied: AssistantApplied | null, now: number): numbe
export const CHANGE_LABELS: Record<AssistantChangeLabelKey, { labelKey: string }> = {
// A tool's own argument: the row names it in `field`, this is only its fallback.
field: { labelKey: 'assistant.change.label.field' },
order: { labelKey: 'assistant.change.label.order' },
name: { labelKey: 'assistant.change.label.name' },
description: { labelKey: 'assistant.change.label.description' },
address: { labelKey: 'assistant.change.label.address' },
@@ -68,7 +68,10 @@ export function markdownToText(markdown: string): string {
const text = plainLine(line);
if (text !== null) lines.push(text.trimEnd());
}
return lines.join('\n').replace(/\n{3,}/g, '\n\n').trim();
return lines
.join('\n')
.replace(/\n{3,}/g, '\n\n')
.trim();
}
/** The text cut to `max` characters at the last line or word end before it, marked with an ellipsis. */
@@ -10,9 +10,7 @@ import { useAssistantStore } from '../../store/assistantStore';
*/
export function useChangeHover(tripId: number, toolCallId: string | null) {
const hovered = useAssistantStore((s) =>
toolCallId !== null && s.mapLink?.tripId === tripId && s.mapLink.hoveredId === toolCallId
? s.mapLink.source
: null
toolCallId !== null && s.mapLink?.tripId === tripId && s.mapLink.hoveredId === toolCallId ? s.mapLink.source : null
);
const setMapHover = useAssistantStore((s) => s.setMapHover);
@@ -107,7 +107,9 @@ function ProviderChips({
const { t } = useTranslation();
const tile = (kind: AiApiKeyKind) =>
`flex min-w-0 items-center gap-2 rounded-lg border px-2 py-1.5 text-start transition-colors hover:bg-surface-hover ${
picked === kind ? 'border-accent bg-surface-card ring-1 ring-accent' : 'border-edge-faint bg-surface-card hover:border-edge'
picked === kind
? 'border-accent bg-surface-card ring-1 ring-accent'
: 'border-edge-faint bg-surface-card hover:border-edge'
}`;
return (
<div className="flex flex-col gap-1.5">
@@ -97,7 +97,7 @@ describe('useKeyConnect', () => {
});
expect(taken).toBe(true);
await waitFor(() =>
expect(repo.connectKey).toHaveBeenCalledWith({ kind: 'openrouter', apiKey: 'unknown-format-key' }),
expect(repo.connectKey).toHaveBeenCalledWith({ kind: 'openrouter', apiKey: 'unknown-format-key' })
);
});