fix(assistant): tighten the journal cards' types and keep their helpers private

A Dawarich stay's row read fields one side of a union did not have, the
photo cards narrowed an entry's day through an optional chain, and the
settings service cast a journey row straight to a record. Helpers only
their own file reads are no longer exported, and the photo tests seed
their rows with insertRow like the other journey suites.
This commit is contained in:
Maurice
2026-10-24 22:12:58 +02:00
parent 0050072b76
commit 8a2cb10f7b
10 changed files with 30 additions and 21 deletions
@@ -26,7 +26,7 @@ export interface JournalCardEntry {
}
/** A trip the journey holds. */
export interface JournalCardTrip {
interface JournalCardTrip {
id: number;
title: string;
startDate: string | null;
@@ -73,7 +73,7 @@ export const JOURNAL_DENIED_TOOLS: Readonly<Record<string, string>> = {
* taken into a journal names it `journalId`. The session pins and hides them
* like `journeyId`; renaming the argument would break every MCP client.
*/
export const JOURNEY_PIN_ALIASES: readonly string[] = ['journalId'];
const JOURNEY_PIN_ALIASES: readonly string[] = ['journalId'];
/** Every argument a journey's session pins to its journey. */
export const JOURNEY_PIN_ARGS: readonly string[] = [JOURNEY_PINNED_ARG, ...JOURNEY_PIN_ALIASES];
@@ -30,7 +30,7 @@ export interface JournalHeaderLoaded {
}
/** The tools these cards are for. */
export const JOURNAL_HEADER_TOOLS = [
const JOURNAL_HEADER_TOOLS = [
'create_journey',
'update_journey',
'delete_journey',
@@ -131,7 +131,7 @@ function stayEntry(args: ToolArgs, stay: Row): Row {
/** The row of a stay taken in: what the entry is about, its day, time, place and text. */
export function describeStay(ctx: PreviewContext, args: ToolArgs, loaded: StayLoaded | null): Described {
const entry = loaded?.stay
const entry: Row = loaded?.stay
? stayEntry(args, loaded.stay)
: { title: args.name, story: args.notes, entry_date: args.date };
const day = typeof entry.entry_date === 'string' ? formatDate(ctx, entry.entry_date) : '';
@@ -88,8 +88,8 @@ function photoLook(row: Row | undefined): JourneyPhotoLook | null {
function entryRef(entry: Row | undefined, entryId: number | null): JourneyPhotosEntry | null {
if (entryId === null) return null;
const date =
typeof entry?.entry_date === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(entry.entry_date) ? entry.entry_date : null;
const raw = entry?.entry_date;
const date = typeof raw === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(raw) ? raw : null;
const title =
clipped(entry?.title, JOURNEY_PHOTOS_LIMITS.title) ?? clipped(entry?.location_name, JOURNEY_PHOTOS_LIMITS.title);
return { entryId, title, date };
@@ -156,7 +156,8 @@ export function journalPhotosCard(
/** What an entry is called on a row: its title, else its place, else its day. */
function entryName(ctx: PreviewContext, entry: Row | undefined): string {
const day = typeof entry?.entry_date === 'string' ? formatDate(ctx, entry.entry_date) : '';
const raw = entry?.entry_date;
const day = typeof raw === 'string' ? formatDate(ctx, raw) : '';
return text(entry?.title) || text(entry?.location_name) || day;
}
@@ -30,7 +30,7 @@ export type JourneyEntryUpdateInput = Partial<{
}>;
/** The columns an update writes, as they are stored. */
export interface JourneyEntryColumns {
interface JourneyEntryColumns {
type: string;
title: string | null;
story: string | null;
@@ -25,7 +25,7 @@ export type JourneySettingsInput = Partial<{
}>;
/** The columns an update writes, as they are stored. */
export interface JourneySettingsColumns {
interface JourneySettingsColumns {
title: string;
subtitle: string | null;
cover_gradient: string | null;
@@ -45,7 +45,7 @@ const ALLOWED_STATUSES: readonly string[] = ['draft', 'active', 'completed', 'ar
const ALLOWED_OVERRIDES: readonly (string | null)[] = [null, 'draft', 'live', 'completed'];
/** The flag columns, stored 0/1 and spoken as booleans. */
export const JOURNEY_SETTING_FLAGS = [
const JOURNEY_SETTING_FLAGS = [
'show_trip_tracks',
'photo_location',
'show_verdict',
@@ -13,7 +13,7 @@ import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
/** A settings update as the MCP tool answers it: the journey as stored now, and what the update replaced. */
export interface JourneySettingsUpdate {
interface JourneySettingsUpdate {
journey: Journey;
previous: JourneySettingsPrevious;
}
@@ -47,7 +47,7 @@ export class JourneySettingsService {
const previous = await this.uow.transactional(async () => {
const before = await this.journeysRepo.findById(journeyId);
if (written) await this.journeysRepo.updateFields(journeyId, { ...patch, updated_at: Date.now() });
return previousSettings(before as Readonly<Record<string, unknown>> | undefined, patch);
return previousSettings(before as unknown as Readonly<Record<string, unknown>> | undefined, patch);
});
if (written) await this.journeys.broadcastJourneyEvent(journeyId, 'journey:updated', {}, sid);
const journey = (await this.journeysRepo.findById(journeyId)) as Journey | undefined;