feat(assistant): curated cards and undo for the changes of a journal itself

Starting a journal, changing its settings, linking or unlinking a trip,
bringing back its suggestions, the user's own view of it and deleting it
fell back to the generic card, which names ids and offers no way back.
They now share a journeyHeader card: the journal with its trips, the one
the change links or unlinks marked, what a new journal brings in and what
a deletion or an unlink takes, and each setting old to new in the
journal's own words. A new journal is deleted again while nothing was
written, added or laid out in it, changed settings are written back from
what the tool answered, a linked trip is unlinked by its owner while none
of its suggestions was written up, and the own switch flips back.
This commit is contained in:
Maurice
2026-10-24 21:36:20 +02:00
parent cf35dc7afd
commit 48ff1b3a98
39 changed files with 2044 additions and 11 deletions
@@ -0,0 +1,39 @@
import { storedTrekCardSchema, trekCardSchema } from './index';
import { JOURNEY_HEADER_LIMITS, journeyHeaderCardSchema } from './journey-header.card';
import { describe, expect, it } from 'vitest';
const card = {
kind: 'journeyHeader',
journeyId: 12,
title: 'Japan 2026',
subtitle: null,
change: 'changed',
trips: [{ id: 5, title: 'Tokyo days', startDate: '2026-11-02', endDate: null, change: 'link' }],
entries: 3,
photos: null,
suggestions: 9,
} as const;
describe('journeyHeaderCardSchema', () => {
it('JOURNEYHEADER-001: is part of the card union and reads as itself', () => {
expect(trekCardSchema.parse(card)).toEqual(card);
expect(storedTrekCardSchema.parse(card)).toEqual(card);
});
it('JOURNEYHEADER-002: takes a new journal without an id, and a trip the user trips do not list', () => {
const fresh = { ...card, journeyId: null, change: 'new', trips: [{ ...card.trips[0], id: null }] };
expect(journeyHeaderCardSchema.parse(fresh)).toEqual(fresh);
});
it('JOURNEYHEADER-003: refuses an unknown change, too many trips, an empty title or a negative count', () => {
expect(journeyHeaderCardSchema.safeParse({ ...card, change: 'renamed' }).success).toBe(false);
const many = Array.from({ length: JOURNEY_HEADER_LIMITS.trips + 1 }, () => card.trips[0]);
expect(journeyHeaderCardSchema.safeParse({ ...card, trips: many }).success).toBe(false);
expect(journeyHeaderCardSchema.safeParse({ ...card, title: '' }).success).toBe(false);
expect(journeyHeaderCardSchema.safeParse({ ...card, entries: -1 }).success).toBe(false);
expect(journeyHeaderCardSchema.safeParse({ ...card, trips: [{ ...card.trips[0], change: 'moved' }] }).success).toBe(
false,
);
});
});
@@ -0,0 +1,47 @@
import { idSchema } from '../../common/primitives.schema';
import { cardCountSchema, cardDateSchema, cardText } from './card-parts';
import { z } from 'zod';
/**
* A journal itself as the assistant chat shows a change of it: a new one,
* its settings changed, a trip linked or unlinked, its suggestions brought
* back, or the whole journal deleted. The rows of the change card say what
* changes field by field; this card is the journal under them, its trips and
* what a change takes with it.
*/
/** How much of a journal the card carries; the server clips to the same numbers. */
export const JOURNEY_HEADER_LIMITS = { title: 200, subtitle: 300, trips: 12, tripTitle: 120 } as const;
/** What the change does to the journal: makes it, changes it, deletes it. */
export const JOURNEY_HEADER_CHANGES = ['new', 'changed', 'willDelete'] as const;
/** What the change does to one of its trips. */
export const JOURNEY_HEADER_TRIP_CHANGES = ['kept', 'link', 'unlink'] as const;
export const journeyHeaderTripSchema = z.object({
/** Null for a trip a new journal names that the user's trips do not list. */
id: idSchema.nullable(),
title: cardText(JOURNEY_HEADER_LIMITS.tripTitle),
startDate: cardDateSchema.nullable(),
endDate: cardDateSchema.nullable(),
change: z.enum(JOURNEY_HEADER_TRIP_CHANGES),
});
export type JourneyHeaderTrip = z.infer<typeof journeyHeaderTripSchema>;
export const journeyHeaderCardSchema = z.object({
kind: z.literal('journeyHeader'),
/** Null for a journal a held change has not made yet. */
journeyId: idSchema.nullable(),
title: cardText(JOURNEY_HEADER_LIMITS.title),
subtitle: cardText(JOURNEY_HEADER_LIMITS.subtitle).nullable(),
change: z.enum(JOURNEY_HEADER_CHANGES),
trips: z.array(journeyHeaderTripSchema).max(JOURNEY_HEADER_LIMITS.trips),
/** What the journal holds: what a deletion takes with it, what an unlinked trip leaves behind. */
entries: cardCountSchema.nullable(),
photos: cardCountSchema.nullable(),
/** Places of the linked trips that come in as suggestions; null when unknown. */
suggestions: cardCountSchema.nullable(),
});
export type JourneyHeaderCard = z.infer<typeof journeyHeaderCardSchema>;
+24 -5
View File
@@ -1,6 +1,8 @@
import { journeyEntriesCardSchema } from './journey-entries.card';
import { journeyHeaderCardSchema } from './journey-header.card';
export * from './journey-entries.card';
export * from './journey-header.card';
/**
* What the travel journal brings to the assistant chat: the kinds of card it draws,
@@ -9,8 +11,25 @@ export * from './journey-entries.card';
* spread these into the card union and the shared enums, so a new kind, verb
* or entity is added here and nowhere else.
*/
export const JOURNEY_CARD_SCHEMAS = [journeyEntriesCardSchema] as const;
/** An entry written, changed or deleted. */
export const JOURNEY_VERB_KEYS = ['addJournalEntry', 'updateJournalEntry', 'removeJournalEntry'] as const;
/** An entry of a journal; the receipt opens it there. */
export const JOURNEY_APPLIED_ENTITIES = ['journey_entry'] as const;
export const JOURNEY_CARD_SCHEMAS = [journeyEntriesCardSchema, journeyHeaderCardSchema] as const;
/**
* An entry written, changed or deleted; a journal started, renamed, given
* another status or other settings, deleted; a trip linked or unlinked; its
* suggestions brought back; the user's own view of it changed.
*/
export const JOURNEY_VERB_KEYS = [
'addJournalEntry',
'updateJournalEntry',
'removeJournalEntry',
'createJournal',
'renameJournal',
'setJournalStatus',
'updateJournalSettings',
'deleteJournal',
'linkJournalTrip',
'unlinkJournalTrip',
'restoreJournalSuggestions',
'setJournalPreferences',
] as const;
/** An entry of a journal, or the journal itself; the receipt opens it there. */
export const JOURNEY_APPLIED_ENTITIES = ['journey_entry', 'journey'] as const;