feat(server): design_book offers the designed templates

The design_book tool says in one sentence that layouts: 'templates' lays
every page on the Studio's designed templates in the archetype of the
book's theme, as the Studio's Auto layout does, and that each plan row then
names its template; style classic alone stays the old built-in Auto
layout. The field comes from the directives contract in @trek/shared, so
the tool's schema takes it without a zod line of its own, and the answer's
plan row gains an optional template. The REST draft routes take no
directives, so nothing changes there. Without the field the answer is the
same as before, no row naming a template.
This commit is contained in:
Maurice
2026-10-24 19:53:45 +02:00
parent 35acdb8ba1
commit 9729b0b575
5 changed files with 53 additions and 1 deletions
@@ -61,7 +61,7 @@ export class JourneyBookDesignMcp {
@Tool({
name: 'design_book',
description: `Design the whole photo book of a journey as a draft: chapters, pacing, the pages, the photos picked for each, type and colours, with the engine's own check run on every page and repaired where it can. directives says what the person wants (style, density, page count, scope, chapters, photos, cover, type, palette, words, travel pages, what to keep) and the art direction: the brief (energy, decoration, collages, theme), the cover's archetype and lockup, and pages.overrides giving single pages of the plan another beat or layout. It answers the draft's design_id, the plan page by page (what each page becomes and its findings), the look, the photos left out and why, and the findings left. ${DRAFT_FLOW} ${LIMITS} Only the book's owner and editors can design it.`,
description: `Design the whole photo book of a journey as a draft: chapters, pacing, the pages, the photos picked for each, type and colours, with the engine's own check run on every page and repaired where it can. directives says what the person wants (style, density, page count, scope, chapters, photos, cover, type, palette, words, travel pages, what to keep) and the art direction: the brief (energy, decoration, collages, theme), the cover's archetype and lockup, and pages.overrides giving single pages of the plan another beat or layout. With layouts: 'templates' every page is laid on the Studio's designed templates in the archetype of the book's theme, as the Studio's Auto layout does, and each plan row names its template; style classic alone is the old built-in Auto layout. It answers the draft's design_id, the plan page by page (what each page becomes and its findings), the look, the photos left out and why, and the findings left. ${DRAFT_FLOW} ${LIMITS} Only the book's owner and editors can design it.`,
inputSchema: { journeyId: idSchema, ...designBookArgs },
annotations: TOOL_ANNOTATIONS_READONLY,
when: journeyAddonOn,
@@ -29,6 +29,7 @@ import {
bookDesignAnswerSchema,
bookDesignApplyResultSchema,
bookDesignDraftResponseSchema,
bookDocumentSchema,
bookWriteResultSchema,
} from '@trek/shared';
@@ -197,4 +198,20 @@ describe('the whole-book design over MCP and REST', () => {
expect(names.filter((name) => DESIGN_TOOLS.includes(name))).toEqual([]);
expect(names.length).toBeGreaterThan(0);
});
it('JBDSNE2E-004: a design on the designed templates applies as a valid book GET reads back', async () => {
const { editor, journey } = await journeyWithBook();
const directives = { style: 'field-notes', layouts: 'templates', seed: 2 };
const draft = bookDesignAnswerSchema.parse(
await callTool(editor.id, 'design_book', { journeyId: journey.id, directives }),
);
expect(draft.plan.filter((row) => row.template).length).toBeGreaterThan(0);
const applied = bookDesignApplyResultSchema.parse(
await callTool(editor.id, 'apply_book_design', { journeyId: journey.id, designId: draft.design_id }),
);
const after = await book(journey.id, editor.id);
expect(after.body.book.version).toBe(applied.version);
expect(bookDocumentSchema.safeParse(after.body.book.document).success).toBe(true);
expect(after.body.book.document.theme.id).toBe('field-notes');
});
});
@@ -236,4 +236,14 @@ describe('the design tools', () => {
await expect(books.restoreBookLayout(putBack, ctx(viewer.id))).rejects.toThrow('Not allowed');
expect(t.realtime.broadcastToUserMock).not.toHaveBeenCalled();
});
it('JBDMCP-006: design_book takes layouts templates and answers the template of each page', async () => {
const { journey, editor } = await crew();
const directives = { style: 'postcard' as const, layouts: 'templates' as const, seed: 1 };
const designed = await designs.designBook({ journeyId: journey.id, directives }, ctx(editor.id));
const draft = bookDesignAnswerSchema.parse(answered(designed));
expect(draft.plan.some((row) => row.template !== undefined)).toBe(true);
expect(draft.style.style).toBe('postcard');
expect(t.realtime.broadcastToUserMock).not.toHaveBeenCalled();
});
});
@@ -418,3 +418,26 @@ describe('the art direction', () => {
expect(free.findings.map((f) => f.code)).not.toContain('energy_mismatch');
});
});
describe('the designed templates', () => {
it("JBDSN-014: layouts templates lays the draft on the designed templates and names each page's template", async () => {
const { journey, owner, created } = await crew();
const answer = await designs.design(journey.id, owner.id, { style: 'riso', layouts: 'templates', seed: 3 });
expect(bookDesignAnswerSchema.parse(answer)).toEqual(answer);
const named = answer.plan.filter((row) => row.template);
expect(named.length).toBeGreaterThan(1);
expect(answer.plan[0]?.beat).toBe('cover');
const { document } = await designs.draftView(journey.id, owner.id, answer.design_id);
expect(document.theme?.id).toBe('riso');
expect(answer.findings.filter((f) => f.severity === 'severe')).toEqual([]);
expect(await version(journey.id, owner.id)).toBe(created?.version);
expect(told()).toEqual([]);
});
it('JBDSN-015: without layouts the plan names no template, as every design answered before', async () => {
const { journey, owner } = await crew();
const answer = await designs.design(journey.id, owner.id, { style: 'riso', seed: 3 });
expect(answer.plan.every((row) => !('template' in row))).toBe(true);
});
});
@@ -93,6 +93,8 @@ export const bookDesignPlanRowSchema = z.object({
entryId: z.number().int().positive().nullable(),
photoIds: z.array(z.number().int().positive()).max(MAX_SPREAD_ELEMENTS),
findings: z.object({ severe: z.number().int().nonnegative(), warn: z.number().int().nonnegative() }),
/** The designed template the page was laid on, for a design with `layouts: 'templates'`. */
template: z.string().max(40).optional(),
});
export type BookDesignPlanRowOut = z.infer<typeof bookDesignPlanRowSchema>;