feat(tours): a city walk prepared from a briefing over MCP, and the station fields an assistant reads spelled out (CW-10, CW-11)

An assistant connected over MCP can now prepare a city walk from what the
traveller tells it. propose_city_walk takes a start (and an end), a time
frame on a day of the trip, the themes of CW-05, the stations the
traveller wishes for, the places of the trip it may use and fixed
appointments with their times, and saves nothing. Places for the themes
come from the search along a tour, at most eight, each with the theme,
category and source that brought it; nothing is made up. The stations are
ordered on estimates over the straight distance, and a place of a theme or
of the trip goes in only where it is open on arrival, keeps the frame and
the appointments, and leaves every station already on the walk open when
the walk gets there. The walk in that order is then planned on foot by the
router the road trip uses (the traveller's own routing server where they
set one), and its legs give the walking distance and time from one station
to the next. Where the router cannot be reached, or a station lies more
than 300 m off every way (the planner's limit, now shared with the
server), the times are estimates over the straight distance with an
allowance for streets at 4.5 km/h, and the answer says so and why. The
answer gives the arrival and leave times, the stay where the traveller
gave it and unknown otherwise, which makes every later arrival the
earliest one, and the opening hours checked against the arrival on that
day with the helpers the planner uses. Walking and stays are counted
apart, the total is complete only when every stay is known, and the
minutes the frame leaves for the unknown stays are named. Free time before
an appointment or at the end, wishes and appointments that cannot be kept
as asked, and places left out with their reason are listed; a tour of the
trip offered as a station is named as a tour. A wish or an appointment is
never dropped; an appointment is a must and protected. A place's default
duration is not read as a stay: every place carries one, so it says
nothing.

Once the traveller confirms, create_city_walk saves the walk through the
same creation the planner's save uses: one write, a key for every station,
the links to the trip's places checked, the trip told, with place editing
permission on the trip. Its way on foot is planned by the same router and
saved with the walk, together with its distance and walking time. Where
the router gives no way, the walk is saved with its stations only and the
answer says why: no line, no distance and no walking time. The tours list
says so (route_pending), the tour detail says in one line that the way is
planned in the planner, and opening the walk in the planner plans its way
at once and offers to save it, with a note once it is planned that it was
just planned. Such a walk can be saved as a new tour and taken over into
another trip, starting at its first stop, and is never offered as a place
to stay. A tour without a line needs two points of its own.

get_tour_plan now spells out every field of a city walk's stations: key,
name, stay (null when not known), importance (null for normal), protection
(false when not set) and opening hours (null when none are known);
list_tours names the station count and whether a walk waits for its way,
get_city_walk_progress gives each station's key and opening hours, and
take_over_tour says a walk keeps its stations with their protection. No
tool changes a walk's stations; deleting a walk's place takes its stations
along, protected ones included, and both delete tools now ask the
assistant to name those and ask the traveller first. REST answers the
stations as before.

A tour create refused for a type that is switched off, a description that
is too long or planned times out of range is a domain refusal now, so an
assistant gets the same text REST sends; REST still answers it as an error
at 400.
This commit is contained in:
Maurice
2026-10-20 06:22:30 +00:00
parent f79b2020d6
commit 554d6f1b9f
69 changed files with 2994 additions and 102 deletions
@@ -83,14 +83,12 @@ export function stayFormFrom<P>(
}
/**
* The places a stay can be at (no GPX tracks, but always the one already picked),
* The places a stay can be at (no GPX tracks or tours, but always the one already picked),
* narrowed to a category when one is chosen.
*/
export function stayPlaceChoices<P extends { id: number; route_geometry?: string | null; category_id?: number | null }>(
places: P[],
placeId: number | string | null | undefined,
categoryId: number | null
): P[] {
export function stayPlaceChoices<
P extends { id: number; route_geometry?: string | null; tour_place_id?: number | null; category_id?: number | null },
>(places: P[], placeId: number | string | null | undefined, categoryId: number | null): P[] {
const offered = stayPlaces<P>(places, placeId);
return categoryId != null ? offered.filter((p) => p.category_id === categoryId) : offered;
}
@@ -209,6 +209,24 @@ describe('TourDetailDialog', () => {
expect(screen.getByText(/Open 10:00 to 18:00/)).toBeInTheDocument()
})
it('CW-11: a walk saved with its stops only says once that its way is planned in the planner, and shows no measures yet', async () => {
const pending = {
...tour, tour_type: 'walk' as const, max_hiking_difficulty: null, distance: null, elevation_gain: null, elevation_loss: null,
station_count: 2, route_pending: true,
}
vi.spyOn(tourRepo, 'detail').mockResolvedValue({ tour: pending, waypoints: [] })
const view = render(<TourDetailDialog {...defaultProps} tour={pending} place={{ ...place, route_geometry: null }} />)
expect(screen.getByText(
'Saved with its stops only. The way between them is planned when the walk is opened in the planner and saved.'
)).toBeInTheDocument()
expect(screen.queryByText('Distance')).not.toBeInTheDocument()
expect(await screen.findByTestId('walk-stations')).toBeInTheDocument()
view.rerender(<TourDetailDialog {...defaultProps} tour={{ ...pending, route_pending: false }} />)
expect(screen.queryByText(/Saved with its stops only/)).not.toBeInTheDocument()
})
it('PAD-01: a paddle tour without heights shows distance, paddling and total side by side in one row', () => {
render(<TourDetailDialog {...defaultProps} tour={{ ...tour, tour_type: 'kayak', has_waypoints: true, duration: 50 }} />)
@@ -66,6 +66,7 @@ import {
} from './tourPresentation';
import { useTourDayAssignment } from './useTourDayAssignment';
import { useTourPermissions, type TourPermissionProps } from './useTourPermissions';
import { WalkRoutePendingHint } from './walk/WalkRoutePending';
import { WalkStationsCard } from './walk/WalkStations';
import { walkTimeFields } from './walk/walkTimeFields';
@@ -675,6 +676,7 @@ export default function TourDetailDialog({
)}
</DialogSection>
{tour.route_pending && <WalkRoutePendingHint />}
{analysis && (
<TourDetailMeasures
analysis={analysis}
@@ -42,6 +42,7 @@ import WandererMark from '../wanderer/WandererMark'
import { TourGpxExportBarButton } from '../TourGpxExportButton'
import { TourRemoteChangeNotice, TourRevisionConflictDialog } from './TourRevisionNotice'
import { WalkImportDraftNotice } from '../walk/WalkImportDialog'
import { WalkRoutePendingNotice } from '../walk/WalkRoutePending'
import TourListFilterMenu, { TourFilterEmpty } from '../TourListFilterMenu'
import { TourScopeSummary } from '../TourScopeSummary'
import { useTourListFilters } from '../useTourListFilters'
@@ -440,6 +441,7 @@ export function TourPlannerRail({ planner,
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3 py-3.5">
<TourRemoteChangeNotice planner={planner} />
<WalkImportDraftNotice planner={planner} />
<WalkRoutePendingNotice planner={planner} />
<TourNameField planner={planner} locked={locked} />
<TourTypeFields planner={planner} locked={locked} />
@@ -1,3 +1,4 @@
import { TOUR_MAX_SNAP_M } from '@trek/shared';
import type { TourRouteResult } from './tourRouting';
/**
@@ -17,4 +18,4 @@ export function isTourRoute(value: TourRouteResult | TourRouteUnreachable | null
}
/** How far the router may move a point onto its way before the point counts as unreachable for the tour's type. */
export const MAX_TOUR_SNAP_M = 300;
export const MAX_TOUR_SNAP_M = TOUR_MAX_SNAP_M;
@@ -137,6 +137,8 @@ export function useTourPlanner({ tripId, active = true, onSaved, canEdit: editPe
const [editingPlaceId, setEditingPlaceId] = useState<number | null>(restored?.editingPlaceId ?? null)
const [derivedFromPlaceId, setDerivedFromPlaceId] = useState<number | null>(restored?.derivedFromPlaceId ?? null)
const [draftSource, setDraftSource] = useState<DraftSource | null>(restored?.draftSource ?? null)
// CW-11: the open walk was saved with its stations only; its way is planned here and kept by the next save.
const [routePending, setRoutePending] = useState(false)
const [openingTourId, setOpeningTourId] = useState<number | null>(null)
const [saveOutcome, setSaveOutcome] = useState<TourListItem | null>(null)
const [retryToken, setRetryToken] = useState(0)
@@ -545,6 +547,7 @@ export function useTourPlanner({ tripId, active = true, onSaved, canEdit: editPe
editingPlaceIdRef.current = null
setDerivedFromPlaceId(null)
setDraftSource(null)
setRoutePending(false)
adoptRevision(null)
setOpeningTourId(null)
setSaveOutcome(null)
@@ -707,7 +710,10 @@ export function useTourPlanner({ tripId, active = true, onSaved, canEdit: editPe
clearHistory()
setStatus('dirty')
clearRoute()
setHasUnsavedChanges(false)
// CW-11: a walk without its way yet is planned on opening and can be saved with it at once.
const pending = result.tour.route_pending === true
setRoutePending(pending)
setHasUnsavedChanges(pending && editPermissionRef.current)
setDraftRestored(false)
setEditingPlaceId(result.tour.place_id)
editingPlaceIdRef.current = result.tour.place_id
@@ -833,6 +839,7 @@ export function useTourPlanner({ tripId, active = true, onSaved, canEdit: editPe
adoptRevision(result.tour.revision)
if (options.name) setNameState(options.name.trim())
setHasUnsavedChanges(false)
setRoutePending(false)
setStatus('saved')
clearHistory()
setEditingPlaceId(result.tour.place_id)
@@ -886,7 +893,7 @@ export function useTourPlanner({ tripId, active = true, onSaved, canEdit: editPe
draftSource,
newTourConfirmationOpen, cancelNewTour, forgetDeletedTour,
elevationProfileExpanded, toggleElevationProfile, newDraftGeneration, draftRestored, mapFocusKey,
editingPlaceId, openingTourId, openTour,
editingPlaceId, openingTourId, openTour, routePending,
saveOutcome, hasUnsavedChanges, canSave, save, discard, returnToNeutral, revision,
}
}
@@ -20,8 +20,9 @@ vi.mock('../useTourPermissions', () => ({ useTourPermissions: () => ({ canEdit:
import type { TourPlannerWaypoint } from './tourPlannerWaypoints';
import { useTourPlanner } from './useTourPlanner';
// FE-TOUR-WALK-PLANNER-001 to FE-TOUR-WALK-PLANNER-007: a city walk's stays in the planner, edited without
// planning its route again, and saved without breaks (CW-02).
// FE-TOUR-WALK-PLANNER-001 to FE-TOUR-WALK-PLANNER-008: a city walk's stays in the planner, edited without
// planning its route again, and saved without breaks (CW-02). FE-TOUR-WALK-PLANNER-009 and 010: a walk an
// assistant saved with its stops only, planned when it is opened (CW-11).
/** 45 minutes on foot between the stops. */
const routed = {
@@ -277,4 +278,69 @@ describe('useTourPlanner, city walks (CW-02)', () => {
expect(result.current.waypoints[3]?.stayMinutes).toBeUndefined();
expect(result.current.stationStays).toMatchObject({ stayMinutes: 20, stations: 3, unknownStays: 2 });
});
/** A saved walk of two stops as the detail answers it, with or without its way. */
const savedWalk = (routePending: boolean) => ({
tour: {
place_id: 42,
name: 'Briefed walk',
tour_type: 'walk' as const,
distance: routePending ? null : 3.2,
elevation_gain: null,
elevation_loss: null,
duration: routePending ? null : 45,
difficulty: null,
wanderer_ref: null,
match_confidence: 1,
max_hiking_difficulty: null,
planned: false,
caution: false,
has_waypoints: true,
revision: 1,
route_pending: routePending,
},
waypoints: [
{ lat: 48, lng: 11, role: 'start' as const, sequence: 0, key: 'stop-cathedral', name: 'Cathedral' },
{ lat: 48.01, lng: 11.02, role: 'end' as const, sequence: 1, key: 'stop-park', name: 'Park' },
],
});
it('FE-TOUR-WALK-PLANNER-009: a walk saved with its stops only is planned on opening and can be saved with its way at once', async () => {
detailTour.mockResolvedValue(savedWalk(true));
updateTour.mockImplementation(async (_trip: number, _place: number, body: TourCreateRequest) => answered(body));
const { result } = renderHook(() => useTourPlanner({ tripId: 31 }));
await act(async () => {
await result.current.openTour({ place_id: 42 });
});
expect(result.current.routePending).toBe(true);
expect(result.current.hasUnsavedChanges).toBe(true);
await settle();
expect(routeCityWalk).toHaveBeenCalledTimes(1);
expect(result.current.status).toBe('ready');
expect(result.current.canSave).toBe(true);
await act(async () => {
await result.current.save();
});
expect(updateTour).toHaveBeenCalledWith(
31,
42,
expect.objectContaining({ route_geometry: enriched, tour_type: 'walk', expected_revision: 1 })
);
expect(result.current.routePending).toBe(false);
expect(result.current.hasUnsavedChanges).toBe(false);
expect(result.current.status).toBe('saved');
});
it('FE-TOUR-WALK-PLANNER-010: a walk with its way opens with nothing to save', async () => {
detailTour.mockResolvedValue(savedWalk(false));
const { result } = renderHook(() => useTourPlanner({ tripId: 31 }));
await act(async () => {
await result.current.openTour({ place_id: 42 });
});
await settle();
expect(result.current.routePending).toBe(false);
expect(result.current.hasUnsavedChanges).toBe(false);
expect(result.current.canSave).toBe(false);
});
});
@@ -0,0 +1,37 @@
import { describe, expect, it } from 'vitest';
import { render, screen } from '../../../../tests/helpers/render';
import { WalkRoutePendingHint, WalkRoutePendingNotice } from './WalkRoutePending';
// FE-WALK-ROUTE-PENDING-001 to FE-WALK-ROUTE-PENDING-002: a walk an assistant saved with its stops only (CW-11).
describe('WalkRoutePending (CW-11)', () => {
it('FE-WALK-ROUTE-PENDING-001: the planner says the way was just planned until the walk is saved with it', () => {
const { rerender } = render(
<WalkRoutePendingNotice planner={{ routePending: true, hasUnsavedChanges: true, status: 'ready' }} />
);
expect(screen.getByRole('status')).toHaveTextContent(
'Saved with its stops only. The way between them was planned just now; save the walk to keep it.'
);
// Saved, or open for someone who may not save it: nothing to say.
rerender(<WalkRoutePendingNotice planner={{ routePending: true, hasUnsavedChanges: false, status: 'ready' }} />);
expect(screen.queryByRole('status')).toBeNull();
rerender(<WalkRoutePendingNotice planner={{ routePending: false, hasUnsavedChanges: true, status: 'ready' }} />);
expect(screen.queryByRole('status')).toBeNull();
// Still being planned, or planning it failed: nothing was planned yet.
rerender(<WalkRoutePendingNotice planner={{ routePending: true, hasUnsavedChanges: true, status: 'routing' }} />);
expect(screen.queryByRole('status')).toBeNull();
rerender(
<WalkRoutePendingNotice planner={{ routePending: true, hasUnsavedChanges: true, status: 'routing-failed' }} />
);
expect(screen.queryByRole('status')).toBeNull();
});
it('FE-WALK-ROUTE-PENDING-002: the detail says where the way gets planned', () => {
render(<WalkRoutePendingHint />);
expect(
screen.getByText(
'Saved with its stops only. The way between them is planned when the walk is opened in the planner and saved.'
)
).toBeInTheDocument();
});
});
@@ -0,0 +1,29 @@
import { Route } from 'lucide-react';
import { useTranslation } from '../../../i18n';
import type { TourPlannerController } from '../planner/useTourPlanner';
import { TourNotice } from '../tourParts';
/**
* CW-11: said in the planner once a walk an assistant saved with its stops
* only has its way planned here and not saved yet; not while the way is still
* being planned, nor when planning it failed.
*/
export function WalkRoutePendingNotice({
planner,
}: {
planner: Pick<TourPlannerController, 'routePending' | 'hasUnsavedChanges' | 'status'>;
}) {
const { t } = useTranslation();
if (!planner.routePending || !planner.hasUnsavedChanges || planner.status !== 'ready') return null;
return (
<TourNotice role="status" icon={<Route size={13} strokeWidth={2} />}>
{t('tours.walk.routePendingPlanner')}
</TourNotice>
);
}
/** CW-11: the detail of a walk saved with its stops only, whose way is still to be planned. */
export function WalkRoutePendingHint() {
const { t } = useTranslation();
return <TourNotice icon={<Route size={13} strokeWidth={2} />}>{t('tours.walk.routePending')}</TourNotice>;
}