fix(ci): repair trip assistant checks

Fix the mobile dashboard import and align the assistant UI with client layer and lint rules. Document the OpenRouter setting, share the reservation status schema, and update coverage for external POI identifiers and the empty costs view.
This commit is contained in:
Maurice
2026-12-02 22:56:54 +01:00
parent 3945037ff3
commit 7196ad30da
18 changed files with 635 additions and 514 deletions
@@ -11,7 +11,7 @@ import type { Place } from '../../types';
import { formatTime } from '../../utils/formatters';
import { TimePill } from '../Planner/planParts';
import { getCategoryIcon } from '../shared/categoryIcons';
import { isDayNoteProposal, isVisitProposal, planField, proposalNote } from './AssistantPlanFields';
import { isDayNoteProposal, isVisitProposal, planField, proposalNote } from './assistantPlanFieldsModel';
/** What a waiting change does to one day, as a row of the preview. */
interface PreviewRow {
@@ -54,28 +54,57 @@ function rowOf(
detail: proposalNote(preview, edits) ?? undefined,
};
}
const kind = visitKind(preview, dayId);
if (!kind) return null;
const place = places.find((p) => p.id === effect?.placeId);
const row = {
toolCallId,
name: edits?.place?.name ?? effect?.place?.name ?? place?.name ?? subject,
categoryId:
edits?.categoryId === undefined ? (effect?.place?.categoryId ?? place?.category_id ?? null) : edits.categoryId,
categoryName: edits?.categoryId === undefined ? planField(preview, 'category') : undefined,
start: edits?.startTime === undefined ? planField(preview, 'time') : (edits.startTime ?? undefined),
end: edits?.endTime === undefined ? planField(preview, 'endTime') : (edits.endTime ?? undefined),
return { toolCallId, kind, ...visitSubject(preview, place, edits), ...visitDetails(preview, place, edits) };
}
function visitSubject(
preview: AssistantChangePreview,
place: Place | undefined,
edits: AssistantPlanEdits | undefined
) {
const proposed = preview.effect?.place;
const categoryId = edits?.categoryId;
return {
name: edits?.place?.name ?? proposed?.name ?? place?.name ?? preview.subject,
categoryId: categoryId === undefined ? (proposed?.categoryId ?? place?.category_id ?? null) : categoryId,
categoryName: categoryId === undefined ? planField(preview, 'category') : undefined,
};
}
function editedText(value: string | null | undefined, original: string | undefined): string | undefined {
return value === undefined ? original : (value ?? undefined);
}
function visitDetails(
preview: AssistantChangePreview,
place: Place | undefined,
edits: AssistantPlanEdits | undefined
) {
return {
start: editedText(edits?.startTime, planField(preview, 'time')),
end: editedText(edits?.endTime, planField(preview, 'endTime')),
detail:
(edits?.notes === undefined ? planField(preview, 'notes') : edits.notes) ||
(edits?.place?.description === undefined ? planField(preview, 'description') : edits.place.description) ||
editedText(edits?.notes, planField(preview, 'notes')) ||
editedText(edits?.place?.description, planField(preview, 'description')) ||
place?.description ||
(edits?.place?.address === undefined ? planField(preview, 'address') : edits.place.address) ||
editedText(edits?.place?.address, planField(preview, 'address')) ||
place?.address ||
undefined,
};
if (!effect) return preview.dayId === dayId && isVisitProposal(preview) ? { ...row, kind: 'add' } : null;
if (effect.dayId === dayId)
return { ...row, kind: effect.kind === 'remove' ? 'remove' : effect.kind === 'move' ? 'in' : 'add' };
if (effect.kind === 'move' && effect.fromDayId === dayId) return { ...row, kind: 'out' };
return null;
}
function visitKind(preview: AssistantChangePreview, dayId: number): PreviewRow['kind'] | null {
const { effect } = preview;
if (!effect) return preview.dayId === dayId && isVisitProposal(preview) ? 'add' : null;
if (effect.dayId === dayId) {
if (effect.kind === 'remove') return 'remove';
if (effect.kind === 'move') return 'in';
return 'add';
}
return effect.kind === 'move' && effect.fromDayId === dayId ? 'out' : null;
}
const LOOK: Record<PreviewRow['kind'], { icon: LucideIcon; row: string; name: string; badgeKey: string }> = {
@@ -3,12 +3,12 @@ import { assistantPlanEditsSchema, parsePlaceHours, placeOpeningHoursSchema } fr
import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from '../../i18n';
import { useIsPhone } from '../../mobile/useIsPhone';
import { useIsPhone } from '../../hooks/useIsPhone';
import { useAssistantStore } from '../../store/assistantStore';
import { useTripStore } from '../../store/tripStore';
import PlaceFormModal from '../Planner/PlaceFormModal';
import { DEFAULT_FORM, formPin, type PlaceFormData } from '../Planner/PlaceFormModal.helpers';
import { planField } from './AssistantPlanFields';
import { planField } from './assistantPlanFieldsModel';
import { useAssistantView } from './assistantViewContext';
type PlacePatch = NonNullable<AssistantPlanEdits['place']>;
@@ -17,14 +17,16 @@ function originalForm(preview: AssistantChangePreview, rawArgs: unknown, categor
const args = rawArgs && typeof rawArgs === 'object' ? (rawArgs as Record<string, unknown>) : {};
const value = (key: string) => (typeof args[key] === 'string' ? args[key] : '');
const point = preview.effect?.place;
const coordinate = (key: 'lat' | 'lng') => String(typeof args[key] === 'number' ? args[key] : (point?.[key] ?? ''));
const text = (key: 'address' | 'description') => value(key) || planField(preview, key) || '';
const hours = placeOpeningHoursSchema.safeParse(args.opening_hours);
return {
...DEFAULT_FORM,
name: value('name') || point?.name || preview.subject,
address: value('address') || planField(preview, 'address') || '',
description: value('description') || planField(preview, 'description') || '',
lat: String(typeof args.lat === 'number' ? args.lat : (point?.lat ?? '')),
lng: String(typeof args.lng === 'number' ? args.lng : (point?.lng ?? '')),
address: text('address'),
description: text('description'),
lat: coordinate('lat'),
lng: coordinate('lng'),
category_id: String(categoryId ?? ''),
place_time: planField(preview, 'time') ?? '',
end_time: planField(preview, 'endTime') ?? '',
@@ -53,10 +55,16 @@ function restoreDraft(form: PlaceFormData, edits: AssistantPlanEdits | undefined
...(lng === undefined ? {} : { lng: String(lng ?? '') }),
...(place_notes === undefined ? {} : { notes: place_notes ?? '' }),
...(opening_hours === undefined ? {} : { opening_hours: opening_hours ? JSON.stringify(opening_hours) : '' }),
...(edits?.startTime === undefined ? {} : { place_time: edits.startTime ?? '' }),
...(edits?.endTime === undefined ? {} : { end_time: edits.endTime ?? '' }),
...(edits?.notes === undefined ? {} : { assignment_notes: edits.notes ?? '' }),
...(edits?.categoryId === undefined ? {} : { category_id: String(edits.categoryId ?? '') }),
...visitDraft(edits ?? {}),
};
}
function visitDraft({ startTime, endTime, notes, categoryId }: AssistantPlanEdits): Partial<PlaceFormData> {
return {
...(startTime === undefined ? {} : { place_time: startTime ?? '' }),
...(endTime === undefined ? {} : { end_time: endTime ?? '' }),
...(notes === undefined ? {} : { assignment_notes: notes ?? '' }),
...(categoryId === undefined ? {} : { category_id: String(categoryId ?? '') }),
};
}
@@ -1,4 +1,4 @@
import type { AssistantChangeLabelKey, AssistantChangePreview, AssistantPlanEdits } from '@trek/shared';
import type { AssistantChangePreview, AssistantPlanEdits } from '@trek/shared';
import { Check, Pencil } from 'lucide-react';
import { lazy, Suspense, useEffect, useId, useState } from 'react';
@@ -15,36 +15,11 @@ import {
NEUTRAL_TINT,
} from '../shared/DialogShell';
import { Tooltip } from '../shared/Tooltip';
import { isVisitProposal, planField, proposalNote } from './assistantPlanFieldsModel';
import { useAssistantView } from './assistantViewContext';
const AssistantPlaceProposal = lazy(() => import('./AssistantPlaceProposal'));
export function isVisitProposal(preview: AssistantChangePreview | null | undefined) {
return preview?.verbKey === 'addPlaceToDay' || preview?.verbKey === 'assignPlace';
}
export function isDayNoteProposal(preview: AssistantChangePreview | null | undefined) {
return preview?.verbKey === 'addDayNote' || preview?.verbKey === 'updateDayNote';
}
export function planField(preview: AssistantChangePreview, field: AssistantChangeLabelKey) {
return preview.rows.find((row) => row.labelKey === field)?.after;
}
export function dayNoteBody(preview: AssistantChangePreview) {
return planField(preview, 'content') ?? (preview.verbKey === 'addDayNote' ? planField(preview, 'time') : undefined);
}
export function proposalNote(preview: AssistantChangePreview, edits: AssistantPlanEdits | undefined) {
return isVisitProposal(preview)
? edits?.notes === undefined
? planField(preview, 'notes')
: edits.notes
: edits?.noteBody === undefined
? dayNoteBody(preview)
: edits.noteBody;
}
interface ProposalEditProps {
preview: AssistantChangePreview;
args?: unknown;
@@ -0,0 +1,27 @@
import type { AssistantChangeLabelKey, AssistantChangePreview, AssistantPlanEdits } from '@trek/shared';
export function isVisitProposal(preview: AssistantChangePreview | null | undefined) {
return preview?.verbKey === 'addPlaceToDay' || preview?.verbKey === 'assignPlace';
}
export function isDayNoteProposal(preview: AssistantChangePreview | null | undefined) {
return preview?.verbKey === 'addDayNote' || preview?.verbKey === 'updateDayNote';
}
export function planField(preview: AssistantChangePreview, field: AssistantChangeLabelKey) {
return preview.rows.find((row) => row.labelKey === field)?.after;
}
export function dayNoteBody(preview: AssistantChangePreview) {
return planField(preview, 'content') ?? (preview.verbKey === 'addDayNote' ? planField(preview, 'time') : undefined);
}
export function proposalNote(preview: AssistantChangePreview, edits: AssistantPlanEdits | undefined) {
return isVisitProposal(preview)
? edits?.notes === undefined
? planField(preview, 'notes')
: edits.notes
: edits?.noteBody === undefined
? dayNoteBody(preview)
: edits.noteBody;
}
@@ -6,12 +6,8 @@ import { useTranslation } from '../../../i18n';
import { Tooltip } from '../../shared/Tooltip';
import AssistantChangeFields from '../AssistantChangeFields';
import type { ChangeItem } from '../assistantParts';
import AssistantPlanFields, {
isDayNoteProposal,
isVisitProposal,
planField,
proposalNote,
} from '../AssistantPlanFields';
import AssistantPlanFields from '../AssistantPlanFields';
import { isDayNoteProposal, isVisitProposal, planField, proposalNote } from '../assistantPlanFieldsModel';
import { useAssistantView } from '../assistantViewContext';
import { useChangeHover } from '../useChangeHover';
import { isSingleBookingDraft } from './booking/bookingCardModel';
@@ -244,15 +240,7 @@ function PendingRow({
const preview = item.preview;
const view = item.card ? viewOf(item.card) : null;
const inlineBooking = inlineBookingCard(item);
const aside = <Slot item={item} view={view} name="Aside" />;
const visit = isVisitProposal(preview);
const dayNote = isDayNoteProposal(preview);
const editable = preview && (visit || dayNote);
const note = editable ? proposalNote(preview, edits) : null;
const receipt = preview?.verbKey === 'importBooking' ? planField(preview, 'attachedTo') : undefined;
const rows = preview?.rows.filter(
(row) => !(groupedDay && row.labelKey === 'day') && !(dayNote && row.labelKey === 'time')
);
const editable = preview && (isVisitProposal(preview) || isDayNoteProposal(preview));
return (
<div
{...handlers}
@@ -285,38 +273,7 @@ function PendingRow({
{inlineBooking ? (
<Slot name="Body" item={item} view={view} fallback={<ChangeHead item={item} view={view} struck={false} />} />
) : preview ? (
<>
{view?.ownsSubject ? (
aside
) : (
<SubjectLine
subject={edits?.place?.name ?? edits?.noteTitle ?? preview.subject}
struck={false}
aside={view?.Aside && aside}
block
/>
)}
<span className="mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-caption text-content-faint">
{!visit && <span className="me-0.5 min-w-0 truncate">{verbLabel(preview, t)}</span>}
<DomainChip domain={preview.domain} />
{view?.Facts ? (
<Slot item={item} view={view} name="Facts" fallback={<AssistantChangeFields rows={preview.rows} />} />
) : (
<AssistantChangeFields rows={rows ?? preview.rows} visit={visit} edits={edits} />
)}
</span>
{receipt && (
<div
className="mt-1 flex min-w-0 items-center gap-1.5 text-caption text-content-muted"
title={t('assistant.attach.chip.keepWithBooking')}
>
<Paperclip size={13} className="flex-none" aria-hidden="true" />
<span className="sr-only">{t('assistant.attach.chip.keepWithBooking')}</span>
<bdi className="truncate">{receipt}</bdi>
</div>
)}
{note && <bdi className="mt-1 block truncate text-caption text-content-muted">{note}</bdi>}
</>
<PendingDetails item={item} preview={preview} view={view} edits={edits} groupedDay={groupedDay} />
) : (
<span className="trek-skeleton inline-block h-4 w-40" aria-hidden="true" />
)}
@@ -334,6 +291,64 @@ function PendingRow({
);
}
function PendingDetails({
item,
preview,
view,
edits,
groupedDay,
}: {
item: ChangeItem;
preview: AssistantChangePreview;
view: View | null;
edits: AssistantPlanEdits | undefined;
groupedDay: boolean;
}) {
const { t } = useTranslation();
const aside = <Slot item={item} view={view} name="Aside" />;
const visit = isVisitProposal(preview);
const dayNote = isDayNoteProposal(preview);
const note = visit || dayNote ? proposalNote(preview, edits) : null;
const receipt = preview.verbKey === 'importBooking' ? planField(preview, 'attachedTo') : undefined;
const rows = preview.rows.filter(
(row) => !(groupedDay && row.labelKey === 'day') && !(dayNote && row.labelKey === 'time')
);
return (
<>
{view?.ownsSubject ? (
aside
) : (
<SubjectLine
subject={edits?.place?.name ?? edits?.noteTitle ?? preview.subject}
struck={false}
aside={view?.Aside && aside}
block
/>
)}
<span className="mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-caption text-content-faint">
{!visit && <span className="me-0.5 min-w-0 truncate">{verbLabel(preview, t)}</span>}
<DomainChip domain={preview.domain} />
{view?.Facts ? (
<Slot item={item} view={view} name="Facts" fallback={<AssistantChangeFields rows={preview.rows} />} />
) : (
<AssistantChangeFields rows={rows} visit={visit} edits={edits} />
)}
</span>
{receipt && (
<div
className="mt-1 flex min-w-0 items-center gap-1.5 text-caption text-content-muted"
title={t('assistant.attach.chip.keepWithBooking')}
>
<Paperclip size={13} className="flex-none" aria-hidden="true" />
<span className="sr-only">{t('assistant.attach.chip.keepWithBooking')}</span>
<bdi className="truncate">{receipt}</bdi>
</div>
)}
{note && <bdi className="mt-1 block truncate text-caption text-content-muted">{note}</bdi>}
</>
);
}
interface RowsProps {
items: readonly ChangeItem[];
/** The waiting rows wait behind the week grid. */