mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
feat(assistant): found places open the place form, notes kept on its own, city walk stops checked off
- Found places: the strip shows only when the answer names one of them, the named ones first. A click on a card, or "Add to trip", opens the planner's place form filled in with the place on the day in focus, its Google details (photos, hours, description) loading beside it; "+ Day" and the day grid are gone. - Trip notes: remember_for_trip runs at once without a card. The assistant keeps lasting facts the user mentions (who travels, needs, likes, budget, pace) on its own and offers the unsure ones as a follow-up; the chat shows "Noted for this trip: ..." with the notes a tap away, and reads them again so the dialog never saves over the new note. - City walks: set_city_walk_visit checks a station off on its day (visited, skipped, or the mark taken back), with day_edit as in the day plan, a change card naming the station and its walk, and an undo that restores the status before while the station is as the change left it. - Card heads are a step smaller (32px tile, smaller title and count), and the dot beside "Working on it" in the header is gone.
This commit is contained in:
@@ -3,7 +3,13 @@
|
||||
* same note is not added twice, notes that would run past the limit are
|
||||
* refused whole, and other trips' notes stay as they are.
|
||||
*/
|
||||
import { noteOf, REMEMBER_SPEC, rememberForTrip } from '../../../../src/nest/assistant/assistant-memory';
|
||||
import type { AgentToolPort } from '../../../../src/nest/assistant/assistant-agent';
|
||||
import {
|
||||
noteOf,
|
||||
REMEMBER_SPEC,
|
||||
rememberForTrip,
|
||||
rememberingPort,
|
||||
} from '../../../../src/nest/assistant/assistant-memory';
|
||||
import type { SettingsService } from '../../../../src/nest/settings/settings.service';
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
@@ -54,4 +60,31 @@ describe('the trip notes', () => {
|
||||
expect(noteOf({ note: 'y'.repeat(600) })).toHaveLength(500);
|
||||
expect(REMEMBER_SPEC.parameters).toMatchObject({ required: ['note'], additionalProperties: false });
|
||||
});
|
||||
|
||||
it('ASTMEM-005: in a trip turn the note is kept at once as a read; other tools and a journey keep the port as it is', async () => {
|
||||
const port: AgentToolPort = {
|
||||
specs: () => [REMEMBER_SPEC],
|
||||
kindOf: (name) => (name === 'remember_for_trip' || name === 'create_place' ? 'write' : null),
|
||||
pinArgs: (_name, args) => ({ args: { ...args, tripId: 4 } }),
|
||||
call: vi.fn(async () => ({ ok: true, value: 'port' })),
|
||||
};
|
||||
const remember = vi.fn(async () => ({ ok: true, value: { notes: 'Vegetarian' } }));
|
||||
const kept = rememberingPort(port, remember);
|
||||
expect(kept.kindOf('remember_for_trip')).toBe('read');
|
||||
expect(kept.kindOf('create_place')).toBe('write');
|
||||
expect(kept.kindOf('nope')).toBeNull();
|
||||
expect(kept.pinArgs('remember_for_trip', { note: 'x' })).toEqual({ args: { note: 'x' } });
|
||||
expect(kept.pinArgs('create_place', {})).toEqual({ args: { tripId: 4 } });
|
||||
expect(await kept.call('remember_for_trip', { note: 'Vegetarian' })).toEqual({
|
||||
ok: true,
|
||||
value: { notes: 'Vegetarian' },
|
||||
});
|
||||
expect(await kept.call('create_place', {})).toEqual({ ok: true, value: 'port' });
|
||||
expect(kept.specs()).toEqual([REMEMBER_SPEC]);
|
||||
expect(remember).toHaveBeenCalledTimes(1);
|
||||
expect(rememberingPort(port, null)).toBe(port);
|
||||
// A session that does not hold the tool (a journey's) never gains it.
|
||||
const journey = rememberingPort({ ...port, kindOf: () => null }, remember);
|
||||
expect(journey.kindOf('remember_for_trip')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* ASTCARD-TOUR-050 to ASTCARD-TOUR-052
|
||||
*
|
||||
* A station of a city walk checked off on its day (set_city_walk_visit): the
|
||||
* card names the station and its walk with the verb of the mark, and the way
|
||||
* back sets the status the station had before, while it still has the one the
|
||||
* change gave it.
|
||||
*/
|
||||
import { buildTripCard } from '../../../../../../src/nest/assistant/assistant-context';
|
||||
import { unchangedSinceApplied } from '../../../../../../src/nest/assistant/assistant-undo.helpers';
|
||||
import { loadFor } from '../../../../../../src/nest/assistant/cards/card-context';
|
||||
import type { PreviewContext } from '../../../../../../src/nest/assistant/cards/card-types';
|
||||
import { readKey } from '../../../../../../src/nest/assistant/cards/card-values';
|
||||
import { ASSISTANT_UNDO_MAP, ASSISTANT_WRITE_TOOLS } from '../../../../../../src/nest/assistant/cards/registry';
|
||||
import { describeToolCall } from '../../../../../../src/nest/assistant/tool-call-preview.helpers';
|
||||
import { assistantChangePreviewSchema } from '@trek/shared';
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const logMock = vi.hoisted(() => ({ logInfo: vi.fn(), logError: vi.fn(), logWarn: vi.fn(), logDebug: vi.fn() }));
|
||||
vi.mock('../../../../../../src/nest/audit/audit-log.logger', () => logMock);
|
||||
|
||||
const card = buildTripCard(
|
||||
1,
|
||||
7,
|
||||
{ trip: { title: 'Lisbon' }, days: [{ id: 31, day_number: 1, date: '2026-11-11', assignments: [] }] },
|
||||
{ places: [{ id: 61, name: 'Old town walk', lat: 38.71, lng: -9.14 }] },
|
||||
null,
|
||||
);
|
||||
const ctx: PreviewContext = { card, categories: new Map(), locale: 'en-GB', today: '2026-11-01', airport: () => null };
|
||||
|
||||
const PROGRESS = {
|
||||
place_id: 61,
|
||||
day_id: 31,
|
||||
assignment_id: 90,
|
||||
stations: [
|
||||
{ key: 'stop-se', name: 'Sé Cathedral', status: 'visited' },
|
||||
{ key: 'stop-castle', name: 'Castle', status: 'planned' },
|
||||
],
|
||||
};
|
||||
const ARGS = { placeId: 61, dayId: 31, stationKey: 'stop-castle', status: 'skipped' };
|
||||
const RESULT = {
|
||||
station_key: 'stop-castle',
|
||||
name: 'Castle',
|
||||
previous_status: 'planned',
|
||||
status: 'skipped',
|
||||
walk: { assignment_id: 90 },
|
||||
};
|
||||
|
||||
describe('set_city_walk_visit in the chat', () => {
|
||||
it('ASTCARD-TOUR-050: the card names the station, its walk and day, with the verb of the mark', async () => {
|
||||
const read = vi.fn(async () => PROGRESS);
|
||||
const loaded = await loadFor('set_city_walk_visit', ARGS, read);
|
||||
expect(read).toHaveBeenCalledWith('get_city_walk_progress', { placeId: 61, dayId: 31 });
|
||||
const preview = describeToolCall('set_city_walk_visit', 'tc-1', ARGS, ctx, loaded);
|
||||
expect(assistantChangePreviewSchema.safeParse(preview).success).toBe(true);
|
||||
expect(preview).toMatchObject({ subject: 'Castle', verbKey: 'markSkipped', dayId: 31, placeIds: [61] });
|
||||
expect(preview.rows.map((row) => row.labelKey)).toEqual(['route', 'day']);
|
||||
expect(ASSISTANT_WRITE_TOOLS.set_city_walk_visit).toMatchObject({ entity: 'tour' });
|
||||
// Without the walk read, the card still names the walk and says what the mark does.
|
||||
const blind = describeToolCall('set_city_walk_visit', 'tc-2', { ...ARGS, status: 'visited' }, ctx, null);
|
||||
expect(blind).toMatchObject({ subject: 'Old town walk', verbKey: 'markVisited' });
|
||||
expect(await loadFor('set_city_walk_visit', { stationKey: 'x' }, read)).toBeNull();
|
||||
});
|
||||
|
||||
it('ASTCARD-TOUR-051: a mark the station already has offers no way back', () => {
|
||||
const same = describeToolCall(
|
||||
'set_city_walk_visit',
|
||||
'tc-3',
|
||||
{ ...ARGS, stationKey: 'stop-se', status: 'visited' },
|
||||
ctx,
|
||||
PROGRESS,
|
||||
);
|
||||
expect(same.undoable).toBe(false);
|
||||
});
|
||||
|
||||
it('ASTCARD-TOUR-052: the way back sets the status before, while the station still has the one the change gave it', () => {
|
||||
const undo = ASSISTANT_UNDO_MAP.set_city_walk_visit;
|
||||
expect(undo.tool).toBe('set_city_walk_visit');
|
||||
expect(undo.args(ARGS, RESULT, null)).toEqual({
|
||||
placeId: 61,
|
||||
dayId: 31,
|
||||
stationKey: 'stop-castle',
|
||||
status: 'planned',
|
||||
assignmentId: 90,
|
||||
});
|
||||
expect(undo.args(ARGS, { status: 'skipped' }, null)).toBeNull();
|
||||
const at = (status: string) => ({
|
||||
summary: { days: [] },
|
||||
places: { places: [] },
|
||||
reads: new Map([
|
||||
[
|
||||
readKey('get_city_walk_progress', { placeId: 61, dayId: 31 }),
|
||||
{ ...PROGRESS, stations: [{ key: 'stop-castle', status }] },
|
||||
],
|
||||
]),
|
||||
});
|
||||
const call = { args: ARGS, preview: null };
|
||||
expect(unchangedSinceApplied('set_city_walk_visit', RESULT, at('skipped'), call)).toBe(true);
|
||||
expect(unchangedSinceApplied('set_city_walk_visit', RESULT, at('visited'), call)).toBe(false);
|
||||
expect(unchangedSinceApplied('set_city_walk_visit', RESULT, at('skipped'))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import { TourWaypoints } from '../../../src/db/entities/TourWaypoints.entity';
|
||||
import { Tours } from '../../../src/db/entities/Tours.entity';
|
||||
import type { McpContext } from '../../../src/nest-mcp';
|
||||
import { getEntry, type ClassRef } from '../../../src/nest-mcp/metadata';
|
||||
import { McpToolGuardsService } from '../../../src/nest/mcp-shared/mcp-tool-guards.service';
|
||||
import { PlacesMcp } from '../../../src/nest/places/places.mcp';
|
||||
import { TourLibraryMcp } from '../../../src/nest/tours/tour-library.mcp';
|
||||
import { TOUR_PLAN_LINE_POINTS } from '../../../src/nest/tours/tour-plan-read';
|
||||
@@ -249,6 +250,57 @@ describe('ToursMcp', () => {
|
||||
expect(answers).toEqual(notThere.map(() => ({ error: 'No city walk of this trip is on that day.' })));
|
||||
});
|
||||
|
||||
it('TOURS-MCP-033: set_city_walk_visit checks a station off on its day, says what it was, and takes a mark back', async () => {
|
||||
const { member, trip, day1, walk, onDay1 } = await walkFixture();
|
||||
const at = { tripId: trip.id, placeId: walk.id, dayId: day1.id };
|
||||
const marked = read(
|
||||
await mcp.setCityWalkVisit({ ...at, stationKey: 'stop-park', status: 'visited' }, ctx(member.id)),
|
||||
);
|
||||
expect(marked).toMatchObject({
|
||||
station_key: 'stop-park',
|
||||
name: null,
|
||||
previous_status: 'planned',
|
||||
status: 'visited',
|
||||
walk: { assignment_id: onDay1.id },
|
||||
});
|
||||
expect(marked.walk.stations.map((station: { status: string }) => station.status)).toEqual([
|
||||
'visited',
|
||||
'skipped',
|
||||
'visited',
|
||||
]);
|
||||
const back = read(
|
||||
await mcp.setCityWalkVisit({ ...at, stationKey: 'stop-market', status: 'planned' }, ctx(member.id)),
|
||||
);
|
||||
expect(back).toMatchObject({ name: null, previous_status: 'skipped', status: 'planned' });
|
||||
const orm = await createTestOrm(db);
|
||||
expect(await countRows(orm, TourStationVisits, { station_key: 'stop-market' })).toBe(0);
|
||||
await orm.close();
|
||||
});
|
||||
|
||||
it('TOURS-MCP-034: set_city_walk_visit refuses an outsider, a member without day_edit, an unknown station and a day without the walk', async () => {
|
||||
const { user, outsider, trip, day1, day2, walk } = await walkFixture();
|
||||
const at = { tripId: trip.id, placeId: walk.id, dayId: day1.id, status: 'visited' as const };
|
||||
expect(read(await mcp.setCityWalkVisit({ ...at, stationKey: 'stop-park' }, ctx(outsider.id)))).toEqual({
|
||||
error: 'Trip not found or access denied.',
|
||||
});
|
||||
const guards = t.get(McpToolGuardsService);
|
||||
const denied = vi.spyOn(guards, 'hasTripPermission').mockResolvedValueOnce(false);
|
||||
try {
|
||||
expect(read(await mcp.setCityWalkVisit({ ...at, stationKey: 'stop-park' }, ctx(user.id)))).toEqual({
|
||||
error: 'You do not have permission to perform this action on this trip.',
|
||||
});
|
||||
expect(denied).toHaveBeenCalledWith('day_edit', trip.id, user.id);
|
||||
} finally {
|
||||
denied.mockRestore();
|
||||
}
|
||||
expect(read(await mcp.setCityWalkVisit({ ...at, stationKey: 'stop-nowhere' }, ctx(user.id))).error).toMatch(
|
||||
/no station with that key/,
|
||||
);
|
||||
expect(read(await mcp.setCityWalkVisit({ ...at, dayId: day2.id, stationKey: 'stop-park' }, ctx(user.id)))).toEqual({
|
||||
error: 'No city walk of this trip is on that day.',
|
||||
});
|
||||
});
|
||||
|
||||
it('TOURS-MCP-010: a failure other than a missing walk is not passed off as no walk', async () => {
|
||||
const { user, trip, day1, walk } = await walkFixture();
|
||||
const failure = new Error('database gone');
|
||||
|
||||
Reference in New Issue
Block a user