mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
3f38621024
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.
67 lines
3.1 KiB
TypeScript
67 lines
3.1 KiB
TypeScript
import { noAccess } from '../../mcp/tools/_shared';
|
|
import {
|
|
McpController,
|
|
Tool,
|
|
TOOL_ANNOTATIONS_READONLY,
|
|
TOOL_ANNOTATIONS_WRITE,
|
|
ok,
|
|
type McpContext,
|
|
} from '../../nest-mcp';
|
|
import { TripAccessService } from '../trip-membership/trip-access.service';
|
|
import { TripAddonsService } from './trip-addons.service';
|
|
import { idSchema, tripAddonIdSchema, tripAddonUpdateRequestSchema } from '@trek/shared';
|
|
|
|
/**
|
|
* The MCP side of GET and PUT /api/trips/:tripId/addons, over the same
|
|
* TripAddonsService. The REST owner check is TripOwnerGuard; here the service
|
|
* makes the same literal check, so a member or an admin who does not own the
|
|
* trip is refused with the REST text.
|
|
*
|
|
* Neither tool has an addon gate: they are how a trip turns an addon on that
|
|
* the instance has off, so they must be there whatever the instance says.
|
|
*/
|
|
@McpController()
|
|
export class TripAddonsMcp {
|
|
constructor(
|
|
private readonly tripAddons: TripAddonsService,
|
|
private readonly trips: TripAccessService,
|
|
) {}
|
|
|
|
@Tool({
|
|
name: 'get_trip_addons',
|
|
description:
|
|
'List the trip addons of one trip (lists, costs, files, collab, road trip, tours) and whether each applies to this trip. enabled is what applies here; instanceEnabled is the instance-wide setting; overridden is true when the trip owner chose enabled for this trip instead of following the instance. An addon that is off here has its tools refused for this trip, and its data is kept. Every member can read this.',
|
|
inputSchema: { tripId: idSchema },
|
|
annotations: TOOL_ANNOTATIONS_READONLY,
|
|
access: { group: 'trips', mode: 'read' },
|
|
})
|
|
async list({ tripId }: { tripId: number }, ctx: McpContext) {
|
|
const trip = await this.trips.findAccessible(tripId, ctx.userId);
|
|
if (!trip) return noAccess();
|
|
return ok({ tripId: trip.id, addons: await this.tripAddons.effectiveTripAddons(trip.id) });
|
|
}
|
|
|
|
@Tool({
|
|
name: 'set_trip_addon',
|
|
description:
|
|
'Switch one trip addon on or off for this trip only, whatever the instance-wide setting is, or pass enabled null to follow the instance setting again. Only the trip owner may do this. Turning an addon off hides it for every member of this trip and keeps its data; turning it on again brings everything back. addonId is an id from get_trip_addons, such as packing, budget, documents, collab, roadtrip or tours. Answers the trip addons as they stand afterwards.',
|
|
inputSchema: {
|
|
tripId: idSchema,
|
|
addonId: tripAddonIdSchema,
|
|
enabled: tripAddonUpdateRequestSchema.shape.enabled,
|
|
},
|
|
annotations: TOOL_ANNOTATIONS_WRITE,
|
|
access: { group: 'trips', mode: 'write' },
|
|
})
|
|
async set(
|
|
{ tripId, addonId, enabled }: { tripId: number; addonId: string; enabled: boolean | null },
|
|
ctx: McpContext,
|
|
) {
|
|
const trip = await this.trips.findAccessible(tripId, ctx.userId);
|
|
if (!trip) return noAccess();
|
|
// The owner check and the addon check are the service's, so they read the same as on REST.
|
|
const addons = await this.tripAddons.setTripOverride(trip.id, ctx.userId, addonId, enabled);
|
|
return ok({ tripId: trip.id, addons });
|
|
}
|
|
}
|