feat(studio): change a book page by page over MCP, and pick its photos from the gallery

This commit is contained in:
Maurice
2026-10-22 15:50:44 +02:00
parent 18daedecda
commit 809002adb3
24 changed files with 2558 additions and 129 deletions
@@ -15,6 +15,28 @@ import { PACKAGE_HELD_READS, PACKAGE_TOOL_CONTROLLERS } from './cards/registry';
* and the model loads an addon's tools when it needs them (USE_TOOLS_TOOL).
*/
/**
* The Studio book tools wait for the Studio's own chat: a trip chat has no
* page to show a change on, no way yet to take one back and no forced
* `returnPrevious`, and an applied write would reload an open Studio from its
* cover. External MCP clients keep them; only the assistant leaves them out
* until the journey scope offers them.
*/
const STUDIO_ONLY_TOOLS: Readonly<Record<string, string>> = Object.fromEntries(
[
'get_book',
'describe_book_page',
'list_book_layouts',
'create_book',
'add_book_pages',
'move_book_page',
'delete_book_pages',
'edit_book_page',
'set_book_cover',
'suggest_book_photos',
].map((name) => [name, 'a Studio book tool: offered in the Studio chat only, never in a trip chat']),
);
/** Never offered, whatever the user approves, each for the reason beside it. */
export const ASSISTANT_DENIED_TOOLS: Readonly<Record<string, string>> = {
delete_trip: 'irreversible, and it takes the conversation with it',
@@ -60,6 +82,8 @@ export const ASSISTANT_DENIED_TOOLS: Readonly<Record<string, string>> = {
update_manual_school_holiday_region: 'changes the holidays of every user',
delete_manual_school_holiday_region: 'changes the holidays of every user',
delete_manual_school_holiday_country: 'changes the holidays of every user',
...STUDIO_ONLY_TOOLS,
restore_book_page: 'an undo target only: it puts a book page back as an earlier change left it',
};
/**
@@ -121,7 +145,7 @@ const CORE_TOOL_GROUPS: ToolGroups = {
about:
'Tours: hikes, bike tours, city walks, paddling and ski routes; plan, create, change and export them ' +
'(hikes with their heights and SAC grades), their packing, the tour library and imports from GPX files ' +
'and Google Maps.',
'and Google Maps walks.',
controllers: [
'ToursMcp',
'CityWalkMcp',
@@ -136,11 +160,12 @@ const CORE_TOOL_GROUPS: ToolGroups = {
'CollectionToursMcp',
'PaddleRoutingMcp',
'SkiRoutingMcp',
'GoogleRouteMcp',
],
},
roadtrip: {
about: 'Road trips and transit: the driving route and its stops, charging, hazards, public transport journeys.',
about:
'Road trips and transit: the driving route and its stops, where each day ends, charging, hazards, ' +
'public transport journeys and driving routes imported from Google Maps.',
controllers: [
'RoadtripMcp',
'RoadtripPlanningMcp',
@@ -158,6 +183,8 @@ const CORE_TOOL_GROUPS: ToolGroups = {
'JourneyMcp',
'JourneyMapMcp',
'JourneyTracksMcp',
'JourneyBookMcp',
'JourneyBookPhotosMcp',
'JourneyRecordingsMcp',
'JourneyDayImportMcp',
'TripJournalLinkMcp',
@@ -0,0 +1,324 @@
import { JourneyEntries } from '../../db/entities/JourneyEntries.entity';
import { JourneyPhotos } from '../../db/entities/JourneyPhotos.entity';
import type { JourneyEntriesRepository } from '../../db/repositories/JourneyEntries.repository';
import type { JourneyPhotosRepository } from '../../db/repositories/JourneyPhotos.repository';
import { DomainError } from '../common/domain-error';
import { JourneyBookService } from './journey-book.service';
import { JourneyDomainService } from './journey-domain.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import {
addBookPages,
applyBookOps,
blankBook,
BOOK_OP_LIMITS,
bookPageSetupSchema,
deleteBookPages,
describeSpread,
listBookLayouts,
moveBookPage,
restoreBookPage,
setBookCover,
spreadFindings,
summarizeBook,
summarizeSpread,
type AddBookPagesRequest,
type BookDocument,
type BookEditResult,
type BookOpError,
type BookOpsContext,
type BookOverview,
type BookPageDescription,
type BookPreviousSpread,
type BookSpreadSummary,
type BookWriteResult,
type CreateBookRequest,
type DeleteBookPagesRequest,
type EditBookPageRequest,
type MoveBookPageRequest,
type RestoreBookPageRequest,
type SetBookCoverRequest,
} from '@trek/shared';
/** A book write's answer, in the shared result's shape. */
export type BookWriteAnswer = BookWriteResult;
/** One write as the engine runs it: the stored document (null without a book) and the journey in, a result out. */
type BookChange = (doc: BookDocument | null, ctx: BookOpsContext) => BookEditResult;
/** A successful engine result. */
type BookMade = Extract<BookEditResult, { ok: true }>;
/** What of the journey a binding reads. */
interface JourneyWords {
title: string;
subtitle?: string | null;
}
/** How one write answers beyond the pages it touched. */
interface WriteOptions {
returnPrevious?: boolean;
expectedVersion?: number;
/** More of the answer, from the book as it was before the write. */
extra?: (before: BookDocument | null) => Partial<BookWriteResult>;
}
/**
* The assistant's and every MCP client's way to read and change a TREK Studio
* book (journey-book.mcp.ts), one page at a time.
*
* The edits themselves are the shared engine (shared/src/book/), pure and the
* same one the Studio previews and a chat card draws with. What needs I/O
* stays here: the journey's access, its gallery and entries for the engine to
* check ids against, and the answer a model reads. Every write goes through
* `JourneyBookService.editBook`, so it is one transaction against the stored
* version, refused whole when an operation is refused, and announced after the
* commit like a save from the Studio.
*
* The rights are the save route's: any member reads, the owner and editors
* write, a viewer is refused (403), an outsider is told the journey is not
* there (404). Unlike the save route a tool may only bring in photos of the
* journey's own gallery: the REST save stays as it is.
*/
@Injectable()
export class JourneyBookEditService {
constructor(
private readonly books: JourneyBookService,
private readonly journey: JourneyDomainService,
@InjectRepository(JourneyPhotos) private readonly photosRepo: JourneyPhotosRepository,
@InjectRepository(JourneyEntries) private readonly entriesRepo: JourneyEntriesRepository,
) {}
// ── Reads ────────────────────────────────────────────────────────────────
/** `get_book`: the book without its document; a journey without one answers `exists: false`. */
async overview(journeyId: number, userId: number): Promise<BookOverview> {
const { record } = await this.readable(journeyId, userId);
return summarizeBook(record?.document ?? null, record?.version ?? null);
}
/** `describe_book_page`: one page in words, with its findings and its elements. */
async describePage(journeyId: number, userId: number, spreadId: string): Promise<BookPageDescription> {
const { journey, record } = await this.readable(journeyId, userId);
if (!record) throw noBook();
const ctx = await this.context(journeyId, journey);
const described = describeSpread(record.document, spreadId, ctx.photos);
if (!described) throw pageNotFound(spreadId);
return described;
}
/** `list_book_layouts`: the layouts a page can take, with what each does to what is on it. */
async layouts(journeyId: number, userId: number, role?: 'inner' | 'single') {
const { record } = await this.readable(journeyId, userId);
const doc = record?.document ?? null;
return listBookLayouts(doc, doc?.page ?? bookPageSetupSchema.parse({}), role);
}
// ── Writes ───────────────────────────────────────────────────────────────
/** A blank book (cover, first page, one spread, last page, back) for a journey that has none. */
async createBook(journeyId: number, userId: number, args: CreateBookRequest): Promise<BookWriteAnswer> {
return this.write(journeyId, userId, (doc, ctx) => {
if (doc) {
throw new DomainError(409, 'This journey has a book already', {
code: 'book_exists',
mcpMessage: 'This journey has a book already: read it with get_book and change it instead.',
});
}
const title = args.title?.trim() || ctx.journey?.title || '';
const book = blankBook({ title, preset: args.preset });
const ids = book.spreads.map((s) => s.id);
return { ok: true, doc: book, spreadIds: ids, created: ids, dropped: [] };
});
}
async addPages(journeyId: number, userId: number, args: AddBookPagesRequest): Promise<BookWriteAnswer> {
return this.write(journeyId, userId, (doc, ctx) => addBookPages(stored(doc), args, ctx));
}
/** The answer's `from_index` is where the page stood, so the assistant's undo can move it back. */
async movePage(journeyId: number, userId: number, args: MoveBookPageRequest): Promise<BookWriteAnswer> {
return this.write(journeyId, userId, (doc) => moveBookPage(stored(doc), args), {
extra: (before) => {
const from = before?.spreads.findIndex((s) => s.id === args.spreadId) ?? -1;
return from >= 0 ? { from_index: from } : {};
},
});
}
async deletePages(journeyId: number, userId: number, args: DeleteBookPagesRequest): Promise<BookWriteAnswer> {
return this.write(journeyId, userId, (doc) => deleteBookPages(stored(doc), args), {
returnPrevious: args.returnPrevious,
});
}
async editPage(journeyId: number, userId: number, args: EditBookPageRequest): Promise<BookWriteAnswer> {
const edit = { spreadId: args.spreadId, ops: args.ops };
return this.write(journeyId, userId, (doc, ctx) => applyBookOps(stored(doc), edit, ctx), {
returnPrevious: args.returnPrevious,
});
}
async setCover(journeyId: number, userId: number, args: SetBookCoverRequest): Promise<BookWriteAnswer> {
return this.write(journeyId, userId, (doc, ctx) => setBookCover(stored(doc), args, ctx), {
returnPrevious: args.returnPrevious,
});
}
/**
* Pages put back as they were, for the assistant's undo: all the pages one
* change answered under `previous_spreads` in one call, and only while the
* book is still at `expectedVersion`, so an undo never overwrites what anyone
* saved after the change it takes back (409 instead). The engine holds a
* restore to an edit's rules: photos from the gallery or the book, locked
* elements as they are.
*/
async restorePage(journeyId: number, userId: number, args: RestoreBookPageRequest): Promise<BookWriteAnswer> {
return this.write(journeyId, userId, (doc, ctx) => restoreBookPage(stored(doc), args, ctx), {
expectedVersion: args.expectedVersion,
});
}
// ── The pieces ───────────────────────────────────────────────────────────
/** The journey as a member sees it and its book. 404 for anyone else. */
private async readable(journeyId: number, userId: number) {
const journey = await this.journey.canAccessJourney(journeyId, userId);
if (!journey) throw journeyNotFound();
const record = await this.books.getBook(journeyId, userId);
return { journey, record };
}
/**
* The gallery and the entries, for the engine: a photo an operation brings in
* must be in the gallery, an entry a page or a binding names must be the
* journey's. Sizes are left out on purpose: `trek_photos.width/height` hold
* a thumbnail's size for an uploaded photo and nothing for a provider's, and
* the print check must read the original's or say nothing.
*/
private async context(journeyId: number, journey: JourneyWords): Promise<BookOpsContext> {
const gallery = await this.photosRepo.galleryRead(journeyId);
const entries = await this.entriesRepo.listForJourney(journeyId);
return {
photos: gallery.map((p) => ({ photoId: p.photo_id, caption: p.caption ?? null })),
journey: {
title: journey.title,
subtitle: journey.subtitle ?? null,
entries: entries.map((e) => ({
id: e.id,
title: e.title ?? null,
story: e.story ?? null,
location: e.location_name ?? null,
})),
},
};
}
/**
* One write: the change run on the stored document inside `editBook`'s
* transaction, with the gallery and the entries read in that same
* transaction, so a photo taken out of the gallery a moment before cannot be
* placed. A refusal from the engine throws there, so the transaction rolls
* back with nothing written or sent. An engine answer that is the stored
* document itself changed nothing, and nothing is written.
*/
private async write(
journeyId: number,
userId: number,
change: BookChange,
options: WriteOptions = {},
): Promise<BookWriteAnswer> {
const journey = await this.journey.canAccessJourney(journeyId, userId);
if (!journey) throw journeyNotFound();
const { record, result } = await this.books.editBook(
journeyId,
userId,
async (current) => {
const ctx = await this.context(journeyId, journey);
const before = current?.document ?? null;
const made = change(before, ctx);
if (made.ok === false) throw refused(made.error);
const unchanged = before !== null && made.doc === before;
const title = current?.title ?? made.doc.title;
return { title, document: made.doc, unchanged, result: { before, made, ctx } };
},
{ expectedVersion: options.expectedVersion },
);
const answer = pagesOf(record.document, result.made, result.ctx);
return {
version: record.version,
spread_ids: result.made.spreadIds,
pages: answer.pages,
findings: answer.findings,
dropped: result.made.dropped,
...(options.returnPrevious ? { previous_spreads: previousOf(result.before, result.made.spreadIds) } : {}),
...options.extra?.(result.before),
};
}
}
/** The pages a write touched as they are stored now, with their findings, severe first and capped. */
function pagesOf(doc: BookDocument, made: BookMade, ctx: BookOpsContext) {
const pages: BookSpreadSummary[] = [];
const findings: BookWriteResult['findings'] = [];
for (const id of made.spreadIds) {
const index = doc.spreads.findIndex((s) => s.id === id);
const spread = doc.spreads[index];
if (!spread) continue;
pages.push(summarizeSpread(spread, index));
findings.push(...spreadFindings(spread, doc.page, ctx.photos));
}
const order = { severe: 0, warn: 1, info: 2 } as const;
findings.sort((a, b) => order[a.severity] - order[b.severity]);
return { pages, findings: findings.slice(0, BOOK_OP_LIMITS.findings) };
}
/**
* The pages as they were before the write, lowest index first, for the
* assistant's undo (`restore_book_page` puts them back in that order, so each
* index means what it meant before). Only pages that existed before.
*/
function previousOf(before: BookDocument | null, spreadIds: readonly string[]): BookPreviousSpread[] {
if (!before) return [];
return before.spreads.flatMap((spread, index) => (spreadIds.includes(spread.id) ? [{ index, spread }] : []));
}
/** Every write but `create_book` needs a book to change. */
function stored(doc: BookDocument | null): BookDocument {
if (!doc) throw noBook();
return doc;
}
function journeyNotFound(): DomainError {
return new DomainError(404, 'Journey not found', { mcpMessage: 'Journey not found or access denied.' });
}
function noBook(): DomainError {
return new DomainError(404, 'This journey has no book yet', {
code: 'book_missing',
mcpMessage: 'This journey has no book yet: create_book makes one.',
});
}
function pageNotFound(spreadId: string): DomainError {
return new DomainError(404, `No page ${spreadId} in this book`, {
code: 'book_page_missing',
mcpMessage: `The book has no page ${spreadId}: get_book lists the pages with their ids.`,
});
}
/**
* An operation the engine refused, as a 422 that names it: which of the
* call's operations (from 0) and the engine's sentence, which says what to do.
*/
function refused(error: BookOpError): DomainError {
const message = error.opIndex === null ? error.message : `ops[${error.opIndex}]: ${error.message}`;
return new DomainError(422, message, {
code: `book_${error.code}`,
details: {
code: error.code,
opIndex: error.opIndex,
...(error.elementId ? { elementId: error.elementId } : {}),
},
});
}
@@ -0,0 +1,45 @@
import { ADDON_IDS } from '../../addons';
import { McpController, TOOL_ANNOTATIONS_READONLY, Tool, ok, type McpContext } from '../../nest-mcp';
import { addonGate } from '../addons/addon-gate';
import { AddonsService } from '../addons/addons.service';
import { JourneyBookPhotosService } from './journey-book-photos.service';
import { idSchema, PHOTO_PICK, suggestBookPhotosArgs, type SuggestBookPhotosRequest } from '@trek/shared';
const journeyAddonOn = addonGate(ADDON_IDS.JOURNEY);
/**
* Photos for a TREK Studio book, picked over MCP from the journey's gallery
* (JourneyBookPhotosService). Read only: any member may ask, as anyone who
* sees the gallery may. Every field comes from @trek/shared.
*/
@McpController()
export class JourneyBookPhotosMcp {
constructor(
private readonly photos: JourneyBookPhotosService,
// Read by the addon gate.
readonly addons: AddonsService,
) {}
@Tool({
name: 'suggest_book_photos',
description:
`Photos of a journey's gallery for a page of its book or for the cover, without looking at them: grouped by day ` +
`(the linked entry's date, else when the photo was taken) and by place (${PHOTO_PICK.placeRadiusM} m around, ` +
`named after the nearest entry), best first. Each pick says why (sharpest of several similar, landscape, not in ` +
`the book yet, has a caption); dropped names what was left out and why: near_duplicate_of another photo (a burst ` +
`or a near-identical picture), possibly_blurry, or low_resolution for print, and dropped_more counts those it ` +
`has no room to name. Say what you left out. entryId or ` +
`date narrows it to one entry or day, purpose cover prefers wide photos with more pixels, limit caps the picks ` +
`(${PHOTO_PICK.defaultLimit} unless told, at most ${PHOTO_PICK.maxLimit}), shared over the groups. Sharpness and ` +
`likeness are measured once per photo; signals_pending counts photos judged on their date, place and size alone ` +
`because they are still being measured, and asking again later knows more. It cannot judge beauty, faces, closed ` +
`eyes, who or what is in a photo, or the same scene from another angle.`,
inputSchema: { journeyId: idSchema, ...suggestBookPhotosArgs },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
access: { group: 'journey', mode: 'read' },
})
async suggestBookPhotos({ journeyId, ...args }: { journeyId: number } & SuggestBookPhotosRequest, ctx: McpContext) {
return ok(await this.photos.suggest(journeyId, ctx.userId, args));
}
}
@@ -0,0 +1,116 @@
import { JourneyEntries } from '../../db/entities/JourneyEntries.entity';
import { JourneyEntryPhotos } from '../../db/entities/JourneyEntryPhotos.entity';
import type { JourneyEntriesRepository } from '../../db/repositories/JourneyEntries.repository';
import type { JourneyEntryPhotosRepository } from '../../db/repositories/JourneyEntryPhotos.repository';
import { DomainError } from '../common/domain-error';
import { PhotoSignalsService } from '../photos/photo-signals.service';
import { JourneyBookService } from './journey-book.service';
import { JourneyDomainService } from './journey-domain.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import {
photosInScope,
pickBookPhotos,
type BookDocument,
type BookPhotoSuggestions,
type PhotoPickCandidate,
type SuggestBookPhotosRequest,
} from '@trek/shared';
/**
* `suggest_book_photos`: photos of a journey's gallery for a book page or
* the cover, grouped by day and place, near duplicates folded onto the best
* of them and the doubtful ones named, so the assistant picks from a short
* list instead of the whole gallery.
*
* The picking is the shared `pickBookPhotos`; what needs I/O is here: the
* journey's access (any member may ask, as anyone who sees the gallery may),
* its entries and which photos they show, the photos the book has already,
* and the pixel signals, which PhotoSignalsService measures off the event loop
* and this waits for only so long. The photos an entry or a day narrows to go
* first in that line; the rest of the gallery follows behind, unwaited, since
* the journey's typical sharpness is taken over every photo measured so far.
*/
@Injectable()
export class JourneyBookPhotosService {
constructor(
private readonly journey: JourneyDomainService,
private readonly books: JourneyBookService,
private readonly signals: PhotoSignalsService,
@InjectRepository(JourneyEntries) private readonly entriesRepo: JourneyEntriesRepository,
@InjectRepository(JourneyEntryPhotos) private readonly entryPhotosRepo: JourneyEntryPhotosRepository,
) {}
async suggest(journeyId: number, userId: number, args: SuggestBookPhotosRequest): Promise<BookPhotoSuggestions> {
if (!(await this.journey.canAccessJourney(journeyId, userId))) {
throw new DomainError(404, 'Journey not found', { mcpMessage: 'Journey not found or access denied.' });
}
const entries = await this.entriesRepo.listForJourney(journeyId);
if (args.entryId !== undefined && !entries.some((e) => e.id === args.entryId)) {
throw new DomainError(404, `No entry ${args.entryId} in this journey`, {
code: 'entry_not_found',
mcpMessage: `This journey has no entry ${args.entryId}: get_journey lists its entries.`,
});
}
const links = await this.entryPhotosRepo.listForJourney(journeyId);
const record = await this.books.getBook(journeyId, userId);
const gallery = await this.signals.galleryFacts(journeyId);
// Links to a dismissed entry are left out: get_journey does not list that entry either.
const listed = new Set(entries.map((e) => e.id));
const entriesOf = new Map<number, number[]>();
for (const link of links) {
if (listed.has(link.entry_id)) {
entriesOf.set(link.photo_id, [...(entriesOf.get(link.photo_id) ?? []), link.entry_id]);
}
}
const inBook = photosInBook(record?.document ?? null);
const candidates: PhotoPickCandidate[] = gallery.map((p) => ({
photoId: p.photo_id,
takenAt: p.taken_at,
lat: p.lat,
lng: p.lng,
width: p.width,
height: p.height,
caption: p.caption,
entryIds: entriesOf.get(p.photo_id) ?? [],
inBook: inBook.has(p.photo_id),
signals: null,
}));
const pickEntries = entries.map((e) => ({
id: e.id,
date: e.entry_date,
title: e.title ?? null,
location: e.location_name ?? null,
lat: e.location_lat ?? null,
lng: e.location_lng ?? null,
}));
const scope = photosInScope(candidates, pickEntries, { entryId: args.entryId, date: args.date });
const ids = candidates.map((c) => c.photoId);
const asked = ids.filter((id) => scope.has(id));
const rest = ids.filter((id) => !scope.has(id));
const { byPhoto, pending } = await this.signals.signalsFor(asked, { later: rest });
const measured = candidates.map((c) => ({ ...c, signals: byPhoto.get(c.photoId) ?? null }));
return pickBookPhotos(measured, pickEntries, {
entryId: args.entryId,
date: args.date,
purpose: args.purpose,
limit: args.limit,
signalsPending: pending,
});
}
}
/**
* The photos the book shows in a frame, placed or parked. A map marker's
* photo is not counted: a pin's thumbnail is not the photo printed on a page.
*/
function photosInBook(doc: BookDocument | null): Set<number> {
const ids = new Set<number>();
for (const spread of doc?.spreads ?? []) {
for (const element of [...spread.elements, ...spread.parked]) {
if (element.kind === 'photo' && element.photoId != null) ids.add(element.photoId);
}
}
return ids;
}
+200
View File
@@ -0,0 +1,200 @@
import { ADDON_IDS } from '../../addons';
import {
McpController,
TOOL_ANNOTATIONS_DELETE,
TOOL_ANNOTATIONS_NON_IDEMPOTENT,
TOOL_ANNOTATIONS_READONLY,
TOOL_ANNOTATIONS_WRITE,
Tool,
ok,
type McpContext,
} from '../../nest-mcp';
import { addonGate } from '../addons/addon-gate';
import { AddonsService } from '../addons/addons.service';
import { JourneyBookEditService } from './journey-book-edit.service';
import {
addBookPagesArgs,
BOOK_OP_LIMITS,
bookPageSetupForPreset,
createBookArgs,
deleteBookPagesArgs,
describeBookPageArgs,
editBookPageArgs,
idSchema,
listBookLayouts,
listBookLayoutsArgs,
moveBookPageArgs,
restoreBookPageArgs,
setBookCoverArgs,
type AddBookPagesRequest,
type CreateBookRequest,
type DeleteBookPagesRequest,
type EditBookPageRequest,
type MoveBookPageRequest,
type RestoreBookPageRequest,
type SetBookCoverRequest,
} from '@trek/shared';
const journeyAddonOn = addonGate(ADDON_IDS.JOURNEY);
/** What a layout does to what is on the page, said where a model picks one (list_book_layouts answers it too). */
const LAYOUT_NOTES = listBookLayouts(null, bookPageSetupForPreset('square-210')).notes;
const UNITS =
'A book is a list of pages (spreads): the cover, the first page, inner double spreads, the last page and the back. ' +
'Positions and sizes are millimetres from the top left of the page, a double spread being twice the page width ' +
'with the fold at one page width.';
const WRITE_ANSWER =
'It answers the new version, the ids of the pages it changed, each of those pages as get_book lists it, their ' +
'findings (severe ones are faults to fix, such as overlapping photos, words past their frame or in the fold, ' +
'empty frames) and dropped, the elements whose content left the page. Nothing is written when any part is refused.';
interface OnJourney {
journeyId: number;
}
/**
* TREK Studio books over MCP: read a book page by page, and change it with the
* same edit engine the Studio and the assistant's cards use. The rights are
* those of PUT /api/journeys/:id/book: any member reads, the owner and editors
* write, a viewer is refused, an outsider is told the journey is not there.
* Every write is one transaction against the stored version and sends
* journey:book:saved to every member's tabs after the commit, the asking one
* included, like a save from the Studio.
*
* Every field comes from the book contracts in @trek/shared, so a bound that
* changes there changes here.
*/
@McpController()
export class JourneyBookMcp {
constructor(
private readonly books: JourneyBookEditService,
// Read by the addon gate of every tool here.
readonly addons: AddonsService,
) {}
// ── Read ────────────────────────────────────────────────────────────────
@Tool({
name: 'get_book',
description: `The TREK Studio book of a journey, without its document: whether it exists, its version, title and page setup, every page with its index, id, role, entry, photo ids, the first words of each text and how many elements, empty frames and parked elements it holds, and the book's own saved layouts. ${UNITS} Read it before changing the book: page and element ids are never invented, they come from here and from describe_book_page.`,
inputSchema: { journeyId: idSchema },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
access: { group: 'journey', mode: 'read' },
})
async getBook({ journeyId }: OnJourney, ctx: McpContext) {
return ok(await this.books.overview(journeyId, ctx.userId));
}
@Tool({
name: 'describe_book_page',
description: `One page of a journey's book in words: its size and role, every element back to front with its id, kind, frame in mm, rotation, lock, photo id or first words and binding, then the findings (overlaps, content in the fold or past the trim, empty frames, low print resolution, words past their frame, parked elements). ${UNITS} Read it before editing a page and again after, to check the result.`,
inputSchema: { journeyId: idSchema, ...describeBookPageArgs },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
access: { group: 'journey', mode: 'read' },
})
async describeBookPage({ journeyId, spreadId }: OnJourney & { spreadId: string }, ctx: McpContext) {
return ok(await this.books.describePage(journeyId, ctx.userId, spreadId));
}
@Tool({
name: 'list_book_layouts',
description: `The layouts a page of a journey's book can take: the templates for inner double spreads and for single pages (the cover, first, last and back) with their photo and text slots, the photo grids with their cell count, and the book's own saved layouts. role narrows the answer to inner or single. ${LAYOUT_NOTES.templates} ${LAYOUT_NOTES.grids}`,
inputSchema: { journeyId: idSchema, ...listBookLayoutsArgs },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
access: { group: 'journey', mode: 'read' },
})
async listLayouts({ journeyId, role }: OnJourney & { role?: 'inner' | 'single' }, ctx: McpContext) {
return ok(await this.books.layouts(journeyId, ctx.userId, role));
}
// ── Write ───────────────────────────────────────────────────────────────
@Tool({
name: 'create_book',
description: `Lay down a blank book for a journey that has none yet: a cover, the first page, one empty double spread, the last page and the back, in the page format preset names (a 21 cm square unless told otherwise), titled title or else the journey's title. A journey that has a book already is refused. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...createBookArgs },
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async createBook({ journeyId, ...args }: OnJourney & CreateBookRequest, ctx: McpContext) {
return ok(await this.books.createBook(journeyId, ctx.userId, args));
}
@Tool({
name: 'add_book_pages',
description: `Add 1 to ${BOOK_OP_LIMITS.pagesPerCall} empty double spreads after afterSpreadId, always kept between the first and the last page, laid out on template when one is named and tied to the journey entry entryId when given. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...addBookPagesArgs },
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async addBookPages({ journeyId, ...args }: OnJourney & AddBookPagesRequest, ctx: McpContext) {
return ok(await this.books.addPages(journeyId, ctx.userId, args));
}
@Tool({
name: 'move_book_page',
description: `Move one inner double spread to toIndex, which must lie between the first and the last page (get_book gives the indexes). The cover, first, last and back pages keep their place. The answer also says where the page stood, under from_index; a move to where the page already is writes nothing. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...moveBookPageArgs },
annotations: TOOL_ANNOTATIONS_WRITE,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async moveBookPage({ journeyId, ...args }: OnJourney & MoveBookPageRequest, ctx: McpContext) {
return ok(await this.books.movePage(journeyId, ctx.userId, args));
}
@Tool({
name: 'delete_book_pages',
description: `Delete 1 to ${BOOK_OP_LIMITS.pagesPerCall} inner double spreads with everything on them. The cover, first, last and back pages cannot be deleted. Only when the person asked for it. With returnPrevious the answer also holds the deleted pages as they were, under previous_spreads. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...deleteBookPagesArgs },
annotations: TOOL_ANNOTATIONS_DELETE,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async deleteBookPages({ journeyId, ...args }: OnJourney & DeleteBookPagesRequest, ctx: McpContext) {
return ok(await this.books.deletePages(journeyId, ctx.userId, args));
}
@Tool({
name: 'edit_book_page',
description: `Change one page with 1 to ${BOOK_OP_LIMITS.opsPerCall} operations, run in order, all or nothing: layout (a template, grid or saved layout), place_photo (a photo of the journey's gallery into a frame by elementId, by its slot among the page's frames, or into a new frame), photo_look (the crop as fit and focal point, mask, frame style, filter, radius), swap_photos, text (by elementId, or by role heading, body or meta, which creates the text when the page has none), caption (under a photo, bound to its caption in the journal unless words are given), frame (move, resize, turn), remove (parked with the page by default, park false deletes) and background (null is the paper). A locked element refuses any operation that would change it. ${LAYOUT_NOTES.templates} ${LAYOUT_NOTES.grids} ${UNITS} With returnPrevious the answer also holds the page as it was, under previous_spreads. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...editBookPageArgs },
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async editBookPage({ journeyId, ...args }: OnJourney & EditBookPageRequest, ctx: McpContext) {
return ok(await this.books.editPage(journeyId, ctx.userId, args));
}
@Tool({
name: 'set_book_cover',
description: `The cover of a journey's book: its layout (a single page template), its photo (from the journey's gallery, into a free frame, else a full bleed one behind everything), its title and its subtitle. A title or subtitle bound to the journey's own stays bound unless other words are given. With returnPrevious the answer also holds the cover as it was, under previous_spreads. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...setBookCoverArgs },
annotations: TOOL_ANNOTATIONS_WRITE,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async setBookCover({ journeyId, ...args }: OnJourney & SetBookCoverRequest, ctx: McpContext) {
return ok(await this.books.setCover(journeyId, ctx.userId, args));
}
@Tool({
name: 'restore_book_page',
description: `Put pages of a journey's book back exactly as pages gives them, all in one call: each in its place when the book still has a page with its id, else at its index, lowest index first. Refused unless the book is still at expectedVersion, so nothing saved since is overwritten. A photo must be in the journey's gallery or already in the book, and a locked element stays as it is. This takes back an earlier change (pages is that change's previous_spreads, whole); it is not a way to edit a page. ${WRITE_ANSWER}`,
inputSchema: { journeyId: idSchema, ...restoreBookPageArgs },
annotations: TOOL_ANNOTATIONS_WRITE,
when: journeyAddonOn,
access: { group: 'journey', mode: 'write' },
})
async restoreBookPage({ journeyId, ...args }: OnJourney & RestoreBookPageRequest, ctx: McpContext) {
return ok(await this.books.restorePage(journeyId, ctx.userId, args));
}
}
@@ -0,0 +1,44 @@
import { JourneyBooks } from '../../db/entities/JourneyBooks.entity';
import { JourneyEntries } from '../../db/entities/JourneyEntries.entity';
import { JourneyEntryPhotos } from '../../db/entities/JourneyEntryPhotos.entity';
import { JourneyPhotos } from '../../db/entities/JourneyPhotos.entity';
import { AddonsModule } from '../addons/addons.module';
import { PhotoSignalsModule } from '../photos/photo-signals.module';
import { JourneyBookEditService } from './journey-book-edit.service';
import { JourneyBookPhotosMcp } from './journey-book-photos.mcp';
import { JourneyBookPhotosService } from './journey-book-photos.service';
import { JourneyBookMcp } from './journey-book.mcp';
import { JourneyBookService } from './journey-book.service';
import { JourneyDomainModule } from './journey-domain.module';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module } from '@nestjs/common';
/**
* TREK Studio books: storing them (`JourneyBookService`, the REST routes in
* journey.controller.ts) and changing them page by page through the shared
* edit engine (`JourneyBookEditService`, the MCP tools in journey-book.mcp.ts),
* and picking photos for it from the gallery (`JourneyBookPhotosService`,
* `suggest_book_photos`, on the pixel signals of PhotoSignalsModule).
*
* The storing and the editing service are exported: the journey controller
* saves through the first, and the assistant's Studio chat reads and writes
* through both.
*/
@Module({
imports: [
AddonsModule,
JourneyDomainModule,
PhotoSignalsModule,
// JB1-JB7, the gallery and entries the edit engine checks ids against, and which photos each entry shows.
MikroOrmModule.forFeature([JourneyBooks, JourneyPhotos, JourneyEntries, JourneyEntryPhotos]),
],
providers: [
JourneyBookService,
JourneyBookEditService,
JourneyBookMcp,
JourneyBookPhotosService,
JourneyBookPhotosMcp,
],
exports: [JourneyBookService, JourneyBookEditService],
})
export class JourneyBookModule {}
+119 -4
View File
@@ -1,12 +1,31 @@
import { JourneyBooks } from '../../db/entities/JourneyBooks.entity';
import type { JourneyBookRow, JourneyBooksRepository } from '../../db/repositories/JourneyBooks.repository';
import { DomainError } from '../common/domain-error';
import { UnitOfWork } from '../database/unit-of-work';
import { JourneyDomainService } from './journey-domain.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import type { BookRecord, BookSummary } from '@trek/shared';
import type { BookDocument, BookRecord, BookSummary } from '@trek/shared';
import { normalizeBookDocument } from '@trek/shared';
/**
* What an edit of the book hands back to `editBook`: the record's title and
* the whole new document, plus whatever the caller wants returned beside the
* saved record. `unchanged` says the edit left the stored book as it is (a
* page moved to where it already was): nothing is written or announced then.
*/
interface BookEdit<T> {
title: string;
document: BookDocument;
result: T;
unchanged?: boolean;
}
/** Where a write came from: REST names the requesting tab, an MCP or assistant write none. */
interface BookWriteOrigin {
socketId?: string;
}
/**
* Storing TREK Studio books.
*
@@ -112,14 +131,27 @@ export class JourneyBookService {
* Returns the saved record, or `{ conflict }` when the base version has
* moved. Throwing would be the obvious shape and the wrong one: a conflict is
* an ordinary outcome of two people working, not an exception.
*
* A save that lands is announced once the transaction has committed, never
* from inside it and never for a conflict: nothing was written then.
*/
async saveBook(
journeyId: number,
userId: number,
input: { title: string; document: unknown; baseVersion?: number },
origin: BookWriteOrigin = {},
): Promise<{ record: BookRecord } | { conflict: BookRecord } | null> {
if (!(await this.canWrite(journeyId, userId))) return null;
const outcome = await this.storeSave(journeyId, userId, input);
if ('record' in outcome) await this.broadcastSaved(journeyId, userId, outcome.record, origin.socketId);
return outcome;
}
private async storeSave(
journeyId: number,
userId: number,
input: { title: string; document: unknown; baseVersion?: number },
): Promise<{ record: BookRecord } | { conflict: BookRecord }> {
const document = JSON.stringify(normalizeBookDocument(input.document));
// M1 (rule 11/24) — JB3's existing-link read and JB4's insert are
@@ -167,6 +199,69 @@ export class JourneyBookService {
});
}
/**
* Change the book by a pure edit of what is stored now: the book tools' one
* way to write (journey-book-edit.service.ts).
*
* The read, the edit and the conditional update run in one transaction, so
* the connection mutex serializes them against a REST save: the edit always
* sees the version it replaces, and no retry loop is needed. `edit` gets the
* current record (null for a journey without a book, which the update then
* creates), may read what else it checks against inside the same
* transaction, and may throw a refusal; a throw rolls back before anything
* is written, and nobody is told anything. `expectedVersion` is the undo's
* guard: the book must still be at that version, else 409 and nothing moves.
* An edit that answers `unchanged` for a stored book writes nothing, bumps
* no version and sends nothing.
*
* The event goes out after the commit. A write that names no socket (MCP,
* the assistant) reaches every tab of every member, the asking one too, so
* the Studio a person has open shows what the assistant did.
*/
async editBook<T>(
journeyId: number,
userId: number,
edit: (current: BookRecord | null) => BookEdit<T> | Promise<BookEdit<T>>,
options: BookWriteOrigin & { expectedVersion?: number } = {},
): Promise<{ record: BookRecord; result: T }> {
await this.requireEditor(journeyId, userId);
const done = await this.uow.transactional(async () => {
const row = await this.booksRepo.findFirstForJourney(journeyId);
const current = row ? this.toRecord(row) : null;
if (options.expectedVersion !== undefined && current?.version !== options.expectedVersion) {
throw bookMoved(current);
}
const next = await edit(current);
if (current && next.unchanged) return { record: current, result: next.result, wrote: false };
const document = JSON.stringify(normalizeBookDocument(next.document));
if (!row) {
const id = await this.booksRepo.insertBook(journeyId, next.title, document, userId);
return { record: await this.written(id), result: next.result, wrote: true };
}
const changes = await this.booksRepo.casUpdate(row.id, row.version, {
title: next.title,
document,
updatedBy: userId,
});
if (changes === 0) throw bookMoved(await this.byId(row.id));
return { record: await this.written(row.id), result: next.result, wrote: true };
});
if (done.wrote) await this.broadcastSaved(journeyId, userId, done.record, options.socketId);
return { record: done.record, result: done.result };
}
/** 404 for someone who cannot see the journey (no existence oracle), 403 for a viewer. */
private async requireEditor(journeyId: number, userId: number): Promise<void> {
if (await this.canWrite(journeyId, userId)) return;
if (await this.canAccess(journeyId, userId)) {
throw new DomainError(403, 'Not allowed', {
code: 'book_read_only',
mcpMessage: "You can read this journey's book but not change it: only its owner and editors can.",
});
}
throw new DomainError(404, 'Journey not found', { mcpMessage: 'Journey not found or access denied.' });
}
async deleteBook(journeyId: number, userId: number): Promise<boolean | null> {
if (!(await this.canWrite(journeyId, userId))) return null;
// JB6.
@@ -182,10 +277,11 @@ export class JourneyBookService {
* Broadcasting a few hundred kilobytes of JSON on every autosave would make
* the notification the size of the thing being edited.
*
* The saver is excluded by socket id, the same way every other TREK mutation
* does it, so the client that just saved does not process its own change.
* A REST save excludes the saving tab by socket id, the same way every other
* TREK mutation does it, so the client that just saved does not process its
* own change. An MCP or assistant write has no socket, so every tab hears it.
*/
async broadcastSaved(journeyId: number, userId: number, record: BookRecord, socketId?: string) {
private async broadcastSaved(journeyId: number, userId: number, record: BookRecord, socketId?: string) {
await this.journey.broadcastJourneyEvent(
journeyId,
'journey:book:saved',
@@ -199,6 +295,25 @@ export class JourneyBookService {
const row = await this.booksRepo.findById(id);
return row ? this.toRecord(row) : null;
}
/** The row a write just made or changed, read back inside the same transaction, so it is there. */
private async written(id: number): Promise<BookRecord> {
const record = await this.byId(id);
if (!record) throw new Error(`Book ${id} is gone inside the transaction that wrote it`);
return record;
}
}
/**
* The book is not at the version a write was made against. The record rides
* along for REST like the save route's conflict; a tool answers the sentence.
*/
function bookMoved(current: BookRecord | null): DomainError {
return new DomainError(409, 'Book was changed by someone else', {
code: 'book_conflict',
details: { current },
mcpMessage: 'The book was changed since that version. Read it again with get_book before changing it.',
});
}
/** JSON that will not parse is an empty document, never an exception. */
@@ -683,11 +683,13 @@ export class JourneyController {
@Body() body: BookSaveDto,
@Headers('x-socket-id') socketId?: string,
) {
const result = await this.books.saveBook(Number(id), user.id, {
title: body.title ?? '',
document: body.document,
baseVersion: body.baseVersion,
});
// The service announces the save after its commit, leaving out this tab.
const result = await this.books.saveBook(
Number(id),
user.id,
{ title: body.title ?? '', document: body.document, baseVersion: body.baseVersion },
{ socketId },
);
if (result === null) {
throw await this.bookRefusal(Number(id), user.id);
}
@@ -705,7 +707,6 @@ export class JourneyController {
409,
);
}
await this.books.broadcastSaved(Number(id), user.id, result.record, socketId);
return result.record;
}
+50 -29
View File
@@ -17,7 +17,17 @@ import { AddonsService } from '../addons/addons.service';
import { JourneyDomainService } from './journey-domain.service';
import { JourneyPhotoCaptureService } from './journey-photo-capture.service';
import { JourneyShareService } from './journey-share.service';
import { idSchema, journeyShareLinkRequestSchema, journeyUpdateRequestSchema } from '@trek/shared';
import {
idSchema,
journeyEntriesRangeSchema,
journeyEntryProsConsSchema,
journeyEntryTypeSchema,
journeyEntryVisibilitySchema,
journeyShareLinkRequestSchema,
journeyUpdateRequestSchema,
type JourneyEntryType,
type JourneyEntryVisibility,
} from '@trek/shared';
import { z } from 'zod';
@@ -58,26 +68,13 @@ function jsonContent(uri: string, data: unknown) {
}
/*
* The three entry fields with a fixed set of values. `journey_entries.type` and
* `.visibility` are plain TEXT columns and the REST route forwards whatever the
* client sent, but the row type (JourneyEntry in src/types) only ever models
* these, so the tools name them rather than take a free string: a model that
* The entry types, visibilities and the verdict come from @trek/shared
* (journey.schema.ts), where the assistant's cards read them too: a model that
* invents "friends-only" would write a value nothing reads.
*/
const ENTRY_TYPE = z.enum(['entry', 'checkin', 'skeleton']);
const ENTRY_VISIBILITY = z.enum(['private', 'shared', 'public']);
type EntryType = z.infer<typeof ENTRY_TYPE>;
type EntryVisibility = z.infer<typeof ENTRY_VISIBILITY>;
/**
* The verdict on a place. Either side defaults to empty so a caller can send
* only the half it has, which is what the entry editor does when a place was
* all good or all bad. The service stores nothing when both come back empty.
*/
const PROS_CONS = z.strictObject({
pros: z.array(z.string()).default([]),
cons: z.array(z.string()).default([]),
});
const ENTRY_TYPE = journeyEntryTypeSchema;
const ENTRY_VISIBILITY = journeyEntryVisibilitySchema;
const PROS_CONS = journeyEntryProsConsSchema;
/**
* The photo backends a journey can reference. The REST route forwards whatever
@@ -181,16 +178,40 @@ export class JourneyMcp {
@Tool({
name: 'list_journey_entries',
description: 'List all entries in a journey.',
inputSchema: { journeyId: idSchema },
description:
'List the entries of a journey in reading order, with the id and title of the journey. from/to keep only the entries of those days (YYYY-MM-DD, both included), so asking for one day reads that day and no more.',
inputSchema: { journeyId: idSchema, ...journeyEntriesRangeSchema.shape },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
access: { group: 'journey', mode: 'read' },
})
async listJourneyEntries({ journeyId }: { journeyId: number }, ctx: McpContext) {
if (!(await this.journey.canAccessJourney(journeyId, ctx.userId)))
return notFound('Journey not found or access denied.');
return ok({ entries: await this.journey.listEntries(journeyId, ctx.userId) });
async listJourneyEntries(
{ journeyId, from, to }: { journeyId: number; from?: string; to?: string },
ctx: McpContext,
) {
const journey = await this.journey.canAccessJourney(journeyId, ctx.userId);
const entries = journey ? await this.journey.listEntries(journeyId, ctx.userId) : null;
if (!journey || !entries) return notFound('Journey not found or access denied.');
const inRange = entries.filter((e) => (!from || e.entry_date >= from) && (!to || e.entry_date <= to));
return ok({ entries: inRange, journey: { id: journey.id, title: journey.title } });
}
@Tool({
name: 'get_journey_entry',
description:
'One journal entry by its id, as list_journey_entries answers it (photos included), with the id and title of its journey.',
inputSchema: { entryId: idSchema },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
access: { group: 'journey', mode: 'read' },
})
async getJourneyEntry({ entryId }: { entryId: number }, ctx: McpContext) {
const journeyId = await this.journey.journeyIdOfEntry(entryId);
const journey = journeyId === null ? null : await this.journey.canAccessJourney(journeyId, ctx.userId);
const entries = journey ? await this.journey.listEntries(journey.id, ctx.userId) : null;
const entry = entries?.find((e) => e.id === entryId);
if (!journey || !entry) return notFound('Entry not found or access denied.');
return ok({ entry, journey: { id: journey.id, title: journey.title } });
}
@Tool({
@@ -426,8 +447,8 @@ export class JourneyMcp {
weather?: string;
tags?: string[];
pros_cons?: { pros: string[]; cons: string[] };
visibility?: EntryVisibility;
type?: EntryType;
visibility?: JourneyEntryVisibility;
type?: JourneyEntryType;
sort_order?: number;
is_draft?: boolean;
},
@@ -509,8 +530,8 @@ export class JourneyMcp {
weather?: string | null;
tags?: string[] | null;
pros_cons?: { pros: string[]; cons: string[] } | null;
visibility?: EntryVisibility;
type?: EntryType;
visibility?: JourneyEntryVisibility;
type?: JourneyEntryType;
sort_order?: number;
stats_excluded?: boolean;
dismissed?: boolean;
+7 -6
View File
@@ -1,4 +1,3 @@
import { JourneyBooks } from '../../db/entities/JourneyBooks.entity';
import { Users } from '../../db/entities/Users.entity';
import { AddonsModule } from '../addons/addons.module';
import { UserConnectionRepositoriesModule } from '../database/user-connection-repositories.module';
@@ -8,7 +7,7 @@ import { MemoriesModule } from '../memories/memories.module';
import { buildStorageUploadOptions } from '../storage/storage-upload.factory';
import { StorageModule } from '../storage/storage.module';
import { StorageService } from '../storage/storage.service';
import { JourneyBookService } from './journey-book.service';
import { JourneyBookModule } from './journey-book.module';
import { JourneyDomainModule } from './journey-domain.module';
import { JourneyMapController } from './journey-map.controller';
import { JourneyMapMcp } from './journey-map.mcp';
@@ -44,16 +43,18 @@ import { MulterModule } from '@nestjs/platform-express';
MemoriesModule,
JourneyDomainModule,
JourneyPhotoCaptureModule,
// The Studio book: its service (the book routes below) and its MCP tools.
JourneyBookModule,
// JourneyService's JV1 read (`UserImmichRepository.getImmichAutoUpload`).
UserConnectionRepositoriesModule,
// Plan 3g Task 3: `JourneyService` (JV1, now through the module above)
// and `JourneyBookService` (JB1-JB7, `JourneyBooksRepository`) both
// constructed HERE — `@InjectRepository` resolves from this module's own
// `forFeature` graph, not from `AuthModule`'s (which registers `Users`
// for its own providers only, per that module's own docstring).
MikroOrmModule.forFeature([Users, JourneyBooks]),
// for its own providers only, per that module's own docstring). The
// book's repository moved with `JourneyBookService` to JourneyBookModule.
MikroOrmModule.forFeature([Users]),
],
controllers: [JourneyController, JourneyMapController, JourneyPublicController],
providers: [JourneyService, JourneyBookService, JourneyMcp, JourneyMapMcp, JourneyTracksMcp],
providers: [JourneyService, JourneyMcp, JourneyMapMcp, JourneyTracksMcp],
})
export class JourneyModule {}