Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat(server): design_book offers the designed templates

Maurice9729b0b5756f
diff --git a/server/src/nest/journey/journey-book-design.mcp.ts b/server/src/nest/journey/journey-book-design.mcp.ts
index 657ac08e3..e828bc8ae 100644
--- a/server/src/nest/journey/journey-book-design.mcp.ts
+++ b/server/src/nest/journey/journey-book-design.mcp.ts
@@ -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,
diff --git a/server/tests/e2e/journey-book-design.e2e.test.ts b/server/tests/e2e/journey-book-design.e2e.test.ts
index dec94dfd3..1731fe1fe 100644
--- a/server/tests/e2e/journey-book-design.e2e.test.ts
+++ b/server/tests/e2e/journey-book-design.e2e.test.ts
@@ -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');
+ });
});
diff --git a/server/tests/unit/nest/journey/journey-book-design.mcp.test.ts b/server/tests/unit/nest/journey/journey-book-design.mcp.test.ts
index 15445f62c..7b5080644 100644
--- a/server/tests/unit/nest/journey/journey-book-design.mcp.test.ts
+++ b/server/tests/unit/nest/journey/journey-book-design.mcp.test.ts
@@ -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();
+ });
});
diff --git a/server/tests/unit/nest/journey/journey-book-design.service.test.ts b/server/tests/unit/nest/journey/journey-book-design.service.test.ts
index d59bc1498..e9b18e501 100644
--- a/server/tests/unit/nest/journey/journey-book-design.service.test.ts
+++ b/server/tests/unit/nest/journey/journey-book-design.service.test.ts
@@ -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);
+ });
+});
diff --git a/shared/src/book/book-design-tools.schema.ts b/shared/src/book/book-design-tools.schema.ts
index 0c87397f4..95a9074c6 100644
--- a/shared/src/book/book-design-tools.schema.ts
+++ b/shared/src/book/book-design-tools.schema.ts
@@ -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>;