mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 06:37:33 +00:00
feat(tours): plan, create and change hikes on the server, for the assistant too
The hiking costing moves to shared, so the planner and the server ask the router the same way. The road trip router learns to plan a hike on foot with that costing (Valhalla only: OSRM knows no trail difficulty), to read heights along a line in chunks and to read the OSM ways a line follows, all through its one paced queue. A hike router builds on it: the way, its heights, distance, climb and DIN walking time, and the SAC grades of its stretches from the trail grade service, each part best effort. New MCP tools in HikePlanMcp, in the assistant's tours group: - propose_hike plans a hike without saving it. - create_hike saves a confirmed hike through the planner's own creation; a router that does not answer leaves it pending for the planner, a way that cannot be planned is refused and nothing is saved. - update_tour changes a saved hike against its revision, keeping linked stations and refusing what would silently drop drawn legs or stages. - import_tour_gpx takes a GPX file's text in as tours, like the import. Same permission checks as REST, broadcasts from the services. In the assistant a new hike or city walk is an "Add tour" card with its route and difficulty, undone through delete_place while the tour is untouched, and a hike being planned shows as a live step.
This commit is contained in:
@@ -84,6 +84,9 @@ const VERB_LOOK: Record<AssistantChangeVerbKey, { Icon: typeof Check; tone: Tone
|
||||
addReservation: { Icon: Ticket, tone: 'success' },
|
||||
importBooking: { Icon: Ticket, tone: 'success' },
|
||||
rememberNote: { Icon: NotebookPen, tone: 'info' },
|
||||
addTour: { Icon: MapPinPlus, tone: 'success' },
|
||||
updateTour: { Icon: PencilLine, tone: 'info' },
|
||||
importTour: { Icon: Plus, tone: 'success' },
|
||||
genericCreate: { Icon: Plus, tone: 'success' },
|
||||
genericUpdate: { Icon: PencilLine, tone: 'info' },
|
||||
genericRemove: { Icon: Trash2, tone: 'danger' },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* FE-AI-MODEL-001 to FE-AI-MODEL-010
|
||||
* FE-AI-MODEL-001 to FE-AI-MODEL-012
|
||||
*
|
||||
* The pure half of the assistant's views: how a stored message reaches
|
||||
* @assistant-ui, what each error offers, how a reading tool is named while it
|
||||
@@ -150,6 +150,15 @@ describe('toolStepKey', () => {
|
||||
expect(liveStepText('search_nearby_places', null)).toEqual({ key: 'assistant.step.nearby' });
|
||||
expect(liveStepText('list_places', 'Kyoto')).toEqual({ key: 'assistant.step.reading' });
|
||||
});
|
||||
|
||||
it('FE-AI-MODEL-012: a hike being planned says so, and names its goal once the step names one', () => {
|
||||
expect(toolStepKey('propose_hike')).toBe('assistant.step.planningHike');
|
||||
expect(liveStepText('propose_hike', 'Herzogstand')).toEqual({
|
||||
key: 'assistant.step.planningHikeTo',
|
||||
params: { place: 'Herzogstand' },
|
||||
});
|
||||
expect(liveStepText('propose_hike', null)).toEqual({ key: 'assistant.step.planningHike' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('suggestions', () => {
|
||||
|
||||
@@ -167,6 +167,10 @@ const STEPS: Partial<Record<string, StepLook>> = {
|
||||
get_weather: { stepKey: 'assistant.step.weather', live: { liveKey: 'assistant.step.weatherAt', param: 'place' } },
|
||||
list_todos: { stepKey: 'assistant.step.todos' },
|
||||
get_settlement_summary: { stepKey: 'assistant.step.costs' },
|
||||
propose_hike: {
|
||||
stepKey: 'assistant.step.planningHike',
|
||||
live: { liveKey: 'assistant.step.planningHikeTo', param: 'place' },
|
||||
},
|
||||
search_help: { stepKey: 'assistant.step.help' },
|
||||
read_booking_file: { stepKey: 'assistant.step.readingBooking' },
|
||||
};
|
||||
|
||||
@@ -288,4 +288,5 @@ export const CHANGE_LABELS: Record<AssistantChangeLabelKey, { labelKey: string }
|
||||
stay: { labelKey: 'assistant.change.label.stay' },
|
||||
members: { labelKey: 'assistant.change.label.members' },
|
||||
route: { labelKey: 'assistant.change.label.route' },
|
||||
difficulty: { labelKey: 'assistant.change.label.difficulty' },
|
||||
};
|
||||
|
||||
@@ -17,9 +17,10 @@ const ICON: Record<HikingPreferenceKey, ComponentType<{ size?: number; strokeWid
|
||||
/**
|
||||
* MF-08: what a hike asks the router for besides its difficulty limit, as
|
||||
* switches under it. Only preferences the router was seen to honour are here
|
||||
* (hikingCostingOptions says which and how they were checked), each with what
|
||||
* it really does in a line of its own; the info dot says they weigh the way
|
||||
* and give way where there is none other, and that none of them grades a path.
|
||||
* (hikingCostingOptions in @trek/shared says which and how they were checked),
|
||||
* each with what it really does in a line of its own; the info dot says they
|
||||
* weigh the way and give way where there is none other, and that none of them
|
||||
* grades a path.
|
||||
* Switching one plans the route again, as one step of the history.
|
||||
*/
|
||||
export function HikingPreferencesField({
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { HikingPreferences } from '@trek/shared';
|
||||
import type { CostingOptions } from '../../Map/valhallaRoute';
|
||||
|
||||
/**
|
||||
* Defensive fallback only. Normal planner calls pass the persisted/draft value.
|
||||
* TREK exposes 1..6 and never exposes Valhalla's internal 0.
|
||||
*/
|
||||
export const TOURS_MAX_HIKING_DIFFICULTY = 2;
|
||||
|
||||
/**
|
||||
* MF-08, RTE-01: a hike's preferences as Valhalla's pedestrian costing
|
||||
* options. Each one was checked against the public instance before it was
|
||||
* offered, and is a weighting that gives way where there is no other path:
|
||||
* - avoid_climbs, `use_hills` 0.2: Freiburg Martinstor to the Schlossberg went
|
||||
* from 1.64 km with a 37 % pitch and 30 m over 25 % to 1.73 km whose steepest
|
||||
* stretch is 23 % (heights every 30 m). It weighs the grade, not the climb in
|
||||
* sum: the same height is still gained. 0.1 and below sent Garmisch station
|
||||
* to the Eckbauer round a 10 km detour with more steep metres, 0.25 and up
|
||||
* left Freiburg as it was; 0.2 does neither.
|
||||
* - avoid_steps, `step_penalty` 600 s: Würzburg Altstadt to the Festung went
|
||||
* from four flights of steps over 1.49 km to one over 2.67 km.
|
||||
* - avoid_ferries, `use_ferry` 0: Kiel Reventlou to Dietrichsdorf went from the
|
||||
* Förde ferry (2.7 km) round the fjord on land (8.3 km); Hamburg
|
||||
* Landungsbrücken to Steinwerder through the old Elbe tunnel instead of the ferry.
|
||||
* The router has no option for marked, paved or rough ways on foot.
|
||||
*/
|
||||
export function hikingCostingOptions(preferences: HikingPreferences | null | undefined): Record<string, number> {
|
||||
return {
|
||||
...(preferences?.avoid_climbs ? { use_hills: 0.2 } : {}),
|
||||
...(preferences?.avoid_steps ? { step_penalty: 600 } : {}),
|
||||
...(preferences?.avoid_ferries ? { use_ferry: 0 } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything a hike asks the pedestrian costing for: its limit and its
|
||||
* preferences. One reading for the whole tour and for the ways offered for one
|
||||
* of its sections (RTE-02), so both are weighed by the same rules.
|
||||
*/
|
||||
export function hikingCosting(
|
||||
maxHikingDifficulty: number = TOURS_MAX_HIKING_DIFFICULTY,
|
||||
preferences: HikingPreferences | null = null
|
||||
): CostingOptions {
|
||||
return { max_hiking_difficulty: maxHikingDifficulty, ...hikingCostingOptions(preferences) };
|
||||
}
|
||||
@@ -1,24 +1,6 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { HikingPreferencesField } from './HikingPreferencesField';
|
||||
import { hikingCosting, hikingCostingOptions } from './hikingCosting';
|
||||
|
||||
describe('hikingCostingOptions (MF-08, RTE-01)', () => {
|
||||
it('asks the router only for what was switched on, in the options it was checked with', () => {
|
||||
expect(hikingCostingOptions(null)).toEqual({});
|
||||
expect(hikingCostingOptions({ avoid_steps: false })).toEqual({});
|
||||
expect(hikingCostingOptions({ avoid_climbs: true, avoid_steps: true, avoid_ferries: true })).toEqual({
|
||||
use_hills: 0.2,
|
||||
step_penalty: 600,
|
||||
use_ferry: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('weighs the whole tour and one of its sections alike: the limit with the preferences (RTE-02)', () => {
|
||||
expect(hikingCosting()).toEqual({ max_hiking_difficulty: 2 });
|
||||
expect(hikingCosting(4, { avoid_steps: true })).toEqual({ max_hiking_difficulty: 4, step_penalty: 600 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('HikingPreferencesField (MF-08, RTE-01)', () => {
|
||||
it('shows the three preferences in order with what each does, and switching one keeps the others', () => {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import type {
|
||||
BikeProfile,
|
||||
HikingPreferences,
|
||||
RunProfile,
|
||||
SkiColourScheme,
|
||||
SkiRunDifficulty,
|
||||
SkiSegmentKind,
|
||||
TourFixedLeg,
|
||||
import {
|
||||
hikingCosting,
|
||||
TOURS_MAX_HIKING_DIFFICULTY,
|
||||
type BikeProfile,
|
||||
type HikingPreferences,
|
||||
type RunProfile,
|
||||
type SkiColourScheme,
|
||||
type SkiRunDifficulty,
|
||||
type SkiSegmentKind,
|
||||
type TourFixedLeg,
|
||||
} from '@trek/shared'
|
||||
import type { Waypoint } from '../../../types'
|
||||
import {
|
||||
@@ -20,7 +22,6 @@ import {
|
||||
type ValhallaNoPath,
|
||||
type ValhallaRun,
|
||||
} from '../../Map/valhallaRoute'
|
||||
import { hikingCosting, TOURS_MAX_HIKING_DIFFICULTY } from './hikingCosting'
|
||||
import { densifyLine, lineLengthM } from './tourFixedLegs'
|
||||
import { MAX_TOUR_SNAP_M, type TourRouteGap, type TourRouteUnreachable } from './tourRouteOutcome'
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import type { HikingPreferences, PlannableTourType, TourMaxHikingDifficulty } from '@trek/shared';
|
||||
import {
|
||||
hikingCosting,
|
||||
type HikingPreferences,
|
||||
type PlannableTourType,
|
||||
type TourMaxHikingDifficulty,
|
||||
} from '@trek/shared';
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { CostingOptions } from '../../Map/valhallaRoute';
|
||||
import { pinAlternative } from '../../Roadtrip/alternativePins';
|
||||
import { hikingCosting } from './hikingCosting';
|
||||
import { askOtherWays, routeSection, type OtherWaysAnswer } from './legVariantRouting';
|
||||
import {
|
||||
comparedLegOf,
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import type { HikingPreferences, PlannableTourType, TourMaxHikingDifficulty } from '@trek/shared';
|
||||
import {
|
||||
hikingCosting,
|
||||
type HikingPreferences,
|
||||
type PlannableTourType,
|
||||
type TourMaxHikingDifficulty,
|
||||
} from '@trek/shared';
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import { randomId } from '../../../utils/randomId';
|
||||
import type { CostingOptions } from '../../Map/valhallaRoute';
|
||||
import { hikingCosting } from './hikingCosting';
|
||||
import { findRoundHikes, type RoundSearchReport } from './roundHikeRouting';
|
||||
import {
|
||||
canStartRound,
|
||||
|
||||
Reference in New Issue
Block a user