feat(tours): assistant takes found places into saved tours and route files from the chat

P6: insert_tour_stop and remove_tour_stop take a place into a saved hike or
city walk as one stop and out again, each the other's undo, with change
cards in the chat. The planner's insertion rule (poiInsertion) moved to
shared so the planner and the server place a stop the same way. "+ Tour" on
a found place holds it as a stop of the saved tour open in the planner.

P7: GPX, KML and KMZ files attached in the chat are read into their tracks
and each is held as a change that takes it in as a hike through
import_tour_gpx, undoable per track; the GPX text stays on the held call.
This commit is contained in:
Maurice
2026-10-23 21:18:19 +02:00
parent 454fc1a5f4
commit cd60d4d859
92 changed files with 3257 additions and 111 deletions
@@ -9,10 +9,12 @@ import {
assistantChatRequestSchema,
assistantDecisionsRequestSchema,
assistantFoundPlaceSchema,
assistantInsertFoundPlaceRequestSchema,
assistantMessageSchema,
assistantPlacesSchema,
assistantStopRequestSchema,
assistantWeatherSchema,
isAssistantTourFile,
UI_STREAM_DONE,
uiStreamChunkSchema,
type UiStreamChunk,
@@ -263,6 +265,32 @@ describe('assistantAddFoundPlaceRequestSchema', () => {
});
});
describe('assistantInsertFoundPlaceRequestSchema', () => {
const parse = (body: Record<string, unknown>) =>
assistantInsertFoundPlaceRequestSchema.safeParse({ ...ctx, ...body });
it('names a found place by its ref and the saved tour it goes into', () => {
expect(parse({ ref: 'toolu_01:2', tourId: 64 }).success).toBe(true);
});
it('refuses a bad tour, a day instead of a tour and anything about the stop itself', () => {
expect(parse({ ref: 'a:1', tourId: 0 }).success).toBe(false);
expect(parse({ ref: 'a:1', dayId: 3 }).success).toBe(false);
expect(parse({ ref: 'a:1', tourId: 64, after_key: 'abc123' }).success).toBe(false);
expect(assistantInsertFoundPlaceRequestSchema.safeParse({ ref: 'a:1', tourId: 64 }).success).toBe(false);
});
});
describe('route files attached in the chat', () => {
it('tells a GPX, KML or KMZ file by its name, whatever its case', () => {
expect(isAssistantTourFile('Herzogstand.GPX')).toBe(true);
expect(isAssistantTourFile('map.kml')).toBe(true);
expect(isAssistantTourFile('map.kmz')).toBe(true);
expect(isAssistantTourFile('ticket.pdf')).toBe(false);
expect(isAssistantTourFile('gpx')).toBe(false);
});
});
describe('the effect of a change', () => {
const preview = {
toolCallId: 'c1',
+26
View File
@@ -68,6 +68,8 @@ export const ASSISTANT_ERROR_CODES = [
'empty_answer',
'offline',
'no_bookings_found',
// An attached GPX, KML or KMZ file without a single track or route to take in as a tour.
'no_tracks_found',
'import_unavailable',
// A found place was suggested while the thread still holds changes nobody decided on.
'decide_first',
@@ -293,6 +295,30 @@ export const assistantAddFoundPlaceRequestSchema = assistantClientCtxSchema
.strict();
export type AssistantAddFoundPlaceRequest = z.infer<typeof assistantAddFoundPlaceRequestSchema>;
/**
* POST /threads/:threadId/found-places/tour: "+ Tour" on a place a search
* found, while a saved tour is open in the planner. Held like "+ Day 3": the
* place comes from the stored search results, the tour must be one of this
* trip's, and the server picks where along it the stop goes.
*/
export const assistantInsertFoundPlaceRequestSchema = assistantClientCtxSchema
.extend({
ref: z.string().min(1).max(80),
tourId: idSchema,
})
.strict();
export type AssistantInsertFoundPlaceRequest = z.infer<typeof assistantInsertFoundPlaceRequestSchema>;
/** The route files the chat takes in as tours (P7), beside the booking files. */
export const ASSISTANT_TOUR_FILE_EXTENSIONS = ['.gpx', '.kml', '.kmz'] as const;
/** Whether a file the user attached is a route file, by its name. */
export function isAssistantTourFile(fileName: string): boolean {
const dot = fileName.lastIndexOf('.');
const ext = dot < 0 ? '' : fileName.slice(dot).toLowerCase();
return (ASSISTANT_TOUR_FILE_EXTENSIONS as readonly string[]).includes(ext);
}
/**
* POST /threads/:threadId/proposals: take a proposal an answer showed as a
* card ("Plan this"). `toolCallId` names the read whose card it was; the
@@ -37,6 +37,9 @@ export const TOUR_VERB_KEYS = [
'setPaddlePlan',
'decideObstacles',
'restoreTrack',
// A found place taken into a saved tour as a stop, or taken out again (P6).
'addTourStop',
'removeTourStop',
] as const;
/** 'tour' is a core entity already. */
export const TOUR_APPLIED_ENTITIES = [] as const;