feat(server): let a trip owner switch trip addons for one trip

A trip can now turn a trip addon (lists, costs, documents, collab, road
trip, tours) on or off for itself, whatever the instance switch says. No
row in the new trip_addon_overrides table means the trip follows the
instance; a row is the owner's choice. Going back to the instance setting
deletes the row, and no addon data is touched either way.

- GET/PUT /api/trips/:tripId/addons[/:addonId] (every member reads, the
  owner writes) and the MCP tools get_trip_addons and set_trip_addon, on
  the shared tripAddons contract; tripAddons:changed tells the members.
- Every trip-scoped addon surface asks the trip: REST through
  TripAddonGuard, MCP through a per-call gate on the named or pinned trip,
  plugin RPC and events, the share link, the offline bundle, reminders,
  doc sync, the assistant (tools, keep_attached_file), booking costs, the
  trip summary prompt, and the cross-trip tour reads (library, Atlas
  stats, collection save).
- Routes without a trip open while the addon is on in any of the user's
  trips. Switching an addon on that the instance has off ends the members'
  MCP sessions so they reconnect with its tools.
- A copied trip takes its owner's choices along.

Behaviour changes: an anonymous call to an addon route that is off now
gets 401 instead of 404, and with an instance switch off the packing,
todo and files plugin RPC methods, the files MCP tools, todo reminder
mails, core plugin events, plugin view contributions, the share link's
lists, costs and chat sections and the offline bundle's lists follow it.
This commit is contained in:
Maurice
2026-11-21 13:23:02 +01:00
parent 2f7b8357ce
commit 3f38621024
203 changed files with 3710 additions and 498 deletions
@@ -1,6 +1,7 @@
import { ADDON_IDS } from '../../addons';
import { McpController, Prompt, type McpContext } from '../../nest-mcp';
import { addonGate } from '../addons/addon-gate';
import { addonOffMessage } from '../addons/addons.constants';
import { AddonsService } from '../addons/addons.service';
import { tripIdPromptArg } from '../mcp-shared/prompt-args';
import { PackingService } from '../packing/packing.service';
@@ -10,6 +11,12 @@ import { TripsService } from './trips.service';
const budgetAddonOn = addonGate(ADDON_IDS.BUDGET);
const packingAddonOn = addonGate(ADDON_IDS.PACKING);
/** A prompt's answer while its addon is off for the trip it names. */
function addonOffPrompt(addonId: string) {
const text = `${addonOffMessage(addonId)}.`;
return { messages: [{ role: 'user' as const, content: { type: 'text' as const, text } }] };
}
/**
* The two cross-domain prompts, relocated from budget.mcp.ts / packing.mcp.ts
* (where the 1:1 port from src/mcp/tools/prompts.ts had left them). Both read
@@ -47,6 +54,7 @@ export class TripPromptsMcp {
],
};
}
if (!(await this.addons.isEnabledForTrip(tripId, ADDON_IDS.BUDGET))) return addonOffPrompt(ADDON_IDS.BUDGET);
const summary = await this.readModel.getTripSummary(tripId, ctx.userId);
if (!summary) {
return { messages: [{ role: 'user' as const, content: { type: 'text' as const, text: 'Trip not found.' } }] };
@@ -105,6 +113,7 @@ export class TripPromptsMcp {
],
};
}
if (!(await this.addons.isEnabledForTrip(tripId, ADDON_IDS.PACKING))) return addonOffPrompt(ADDON_IDS.PACKING);
// Hide other members' private items (#858) from the requesting user.
const items = await this.packing.listItems(tripId, ctx.userId);
if (!items.length) {
+1 -1
View File
@@ -336,7 +336,7 @@ export class TripsController {
@Get(':id/bundle')
async bundle(@CurrentUser() user: User, @Param('id') id: string) {
const trip = (await this.trips.get(id, user.id)) as { user_id: number } | undefined;
const trip = (await this.trips.get(id, user.id)) as { id: number; user_id: number } | undefined;
if (!trip) {
throw new HttpException({ error: 'Trip not found' }, 404);
}
+15 -9
View File
@@ -432,10 +432,10 @@ export class TripsMcp {
const summary = await this.readModel.getTripSummary(tripId, ctx.userId);
if (!summary) return noAccess();
const R = canReadTrips(ctx.scopes);
// Addon availability gates
const packingEnabled = await this.addons.isAddonEnabled(ADDON_IDS.PACKING);
const budgetEnabled = await this.addons.isAddonEnabled(ADDON_IDS.BUDGET);
const collabEnabled = await this.addons.isAddonEnabled(ADDON_IDS.COLLAB);
// Addon availability gates, as they apply to this trip
const packingEnabled = await this.addons.isEnabledForTrip(tripId, ADDON_IDS.PACKING);
const budgetEnabled = await this.addons.isEnabledForTrip(tripId, ADDON_IDS.BUDGET);
const collabEnabled = await this.addons.isEnabledForTrip(tripId, ADDON_IDS.COLLAB);
const collabFeatures = collabEnabled ? await this.addons.getCollabFeatures() : null;
// Scope gates — sections not covered by the client's OAuth scopes are omitted.
// Core trip data (metadata, days, members, accommodations) is always included
@@ -781,15 +781,21 @@ export class TripsMcp {
}
const { trip, days, members, budget, packing, reservations, collab_notes } = summary as any;
const memberList = [members?.owner, ...(members?.collaborators || [])].filter(Boolean);
// A section whose addon is off for this trip is left out, as get_trip_summary leaves it out.
const [packingOn, budgetOn, collabOn] = await Promise.all(
[ADDON_IDS.PACKING, ADDON_IDS.BUDGET, ADDON_IDS.COLLAB].map((id) => this.addons.isEnabledForTrip(tripId, id)),
);
const sections = [
packingOn ? `Packing: ${packing?.checked || 0}/${packing?.total || 0} items packed\n` : '',
budgetOn ? `Budget: ${budget?.total || 0} ${trip?.currency || 'EUR'} total\n` : '',
].join('');
const notes = collabOn ? `Collab Notes: ${collab_notes?.length || 0}\n` : '';
const text = `Trip: ${trip?.title || 'Untitled'}${trip?.description ? `\n${trip.description}` : ''}
Dates: ${trip?.start_date || '?'} to ${trip?.end_date || '?'}
Members: ${memberList.length} (${memberList.map((m: any) => m.name || m.email).join(', ') || 'none'})
Days: ${days?.length || 0}
Packing: ${packing?.checked || 0}/${packing?.total || 0} items packed
Budget: ${budget?.total || 0} ${trip?.currency || 'EUR'} total
Reservations: ${reservations?.length || 0}
Collab Notes: ${collab_notes?.length || 0}
${days?.map((d: any, i: number) => `Day ${i + 1} (${d.date}): ${d.assignments?.length || 0} places${d.title ? ` - ${d.title}` : ''}`).join('\n') || 'No days yet'}`;
${sections}Reservations: ${reservations?.length || 0}
${notes}${days?.map((d: any, i: number) => `Day ${i + 1} (${d.date}): ${d.assignments?.length || 0} places${d.title ? ` - ${d.title}` : ''}`).join('\n') || 'No days yet'}`;
return {
description: `Summary of trip "${trip?.title || tripId}"`,
messages: [{ role: 'user' as const, content: { type: 'text' as const, text } }],
+3
View File
@@ -47,6 +47,7 @@ import { VacayService } from '../vacay/vacay.service';
import { UnsplashService } from '../unsplash/unsplash.service';
import { StorageReleaseService } from '../storage/storage-release.service';
import { SettingsService } from '../settings/settings.service';
import { TripAddonsService } from '../addons/trip-addons.service';
import { escapeLikePattern } from '../places/places.helpers';
import { NotFoundError, ValidationError } from '../common/domain-errors';
import { inOrder } from '../common/in-order';
@@ -128,6 +129,7 @@ export class TripsService {
// .forRoot`'s core module), so no module needs new wiring.
private readonly em: EntityManager,
private readonly settings: SettingsService,
private readonly tripAddons: TripAddonsService, // the owner's per-trip addon switches travel with a copy
) {}
// Plan 3c Task 7: the raw better-sqlite3 handle used to back `remove`'s
@@ -755,6 +757,7 @@ export class TripsService {
await this.roadtripPreferencesRepo.upsertValue(newTripId, pref.key, pref.value); // TP50
}
await this.tripAddons.copyOverrides(Number(sourceTripId), newTripId); // the trip addons switched on or off for the trip
const oldBoundaries = await this.roadtripDayBoundariesRepo.listForTrip(Number(sourceTripId)); // TP51
for (const boundary of oldBoundaries) {
const from = assignmentMap.get(boundary.from_assignment_id);