mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
feat(mcp): price on create_transit_journey, reservation_id on create_budget_item
- create_transit_journey takes price / budget_category, as create_transport does: a fare > 0 files the linked expense in the booking's own transaction and rides along in metadata.price. The tool now writes through ReservationWritesService.createBooking, so its events and booking notice are the ones every other booking write sends - create_budget_item and create_budget_item_with_members take reservation_id, the field POST /budget already accepts; create_budget_item now runs BudgetWritesService.createItem like its sibling, so a linked booking's mirrored price is worked out again before budget:created goes out - bookingPriceSchema / bookingBudgetCategorySchema in @trek/shared back the price fields of all three booking tools (mcp-inline-zod baseline lowered) - wiki: MCP-Tools-and-Resources describes the new params
This commit is contained in:
@@ -230,6 +230,11 @@ export class BudgetMcp {
|
||||
.describe(
|
||||
'Place on this trip the expense belongs to (the museum ticket for that museum), linking it in the planner',
|
||||
),
|
||||
reservation_id: idSchema
|
||||
.optional()
|
||||
.describe(
|
||||
'Booking or transport on this trip the expense belongs to (a booking can carry several), linking it in the planner',
|
||||
),
|
||||
note: z.string().max(500).optional(),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
|
||||
@@ -248,6 +253,7 @@ export class BudgetMcp {
|
||||
payers,
|
||||
expense_date,
|
||||
place_id,
|
||||
reservation_id,
|
||||
note,
|
||||
}: {
|
||||
tripId: number;
|
||||
@@ -260,6 +266,7 @@ export class BudgetMcp {
|
||||
payers?: { user_id: number; amount: number }[];
|
||||
expense_date?: string | null;
|
||||
place_id?: number;
|
||||
reservation_id?: number;
|
||||
note?: string;
|
||||
},
|
||||
ctx: McpContext,
|
||||
@@ -270,6 +277,8 @@ export class BudgetMcp {
|
||||
return errorResult('Pass either members (uneven split) or member_ids (equal split), not both.');
|
||||
if (place_id != null && !(await this.placeOnTrip(tripId, place_id)))
|
||||
return errorResult('place_id does not belong to this trip.');
|
||||
const linkRefusal = await this.budget.linkRefusal(tripId, { reservation_id });
|
||||
if (linkRefusal) return errorResult(linkRefusal);
|
||||
if (members !== undefined) {
|
||||
const refusal = await this.splitRefusal(
|
||||
tripId,
|
||||
@@ -293,13 +302,12 @@ export class BudgetMcp {
|
||||
payers,
|
||||
expense_date,
|
||||
place_id,
|
||||
reservation_id,
|
||||
note,
|
||||
};
|
||||
// Freeze the live FX rate at entry time so a settled position isn't re-opened
|
||||
// when live rates drift (#1445) — same as the REST create path.
|
||||
await this.budget.freezeForeignRate(tripId, itemData);
|
||||
const item = await this.budget.createBudgetItem(tripId, itemData);
|
||||
this.guards.safeBroadcast(tripId, 'budget:created', { item });
|
||||
// The REST create's use case: it freezes the live FX rate at entry time
|
||||
// (#1445), works out a linked booking's price again and sends budget:created.
|
||||
const item = await this.writes.createItem(tripId, itemData, await this.guards.tripWriter(tripId, ctx.userId));
|
||||
return ok({ item });
|
||||
}
|
||||
|
||||
@@ -486,6 +494,11 @@ export class BudgetMcp {
|
||||
.describe(
|
||||
'Place on this trip the expense belongs to (the museum ticket for that museum), linking it in the planner',
|
||||
),
|
||||
reservation_id: idSchema
|
||||
.optional()
|
||||
.describe(
|
||||
'Booking or transport on this trip the expense belongs to (a booking can carry several), linking it in the planner',
|
||||
),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
|
||||
when: budgetAddonOn,
|
||||
@@ -500,6 +513,7 @@ export class BudgetMcp {
|
||||
note,
|
||||
userIds,
|
||||
place_id,
|
||||
reservation_id,
|
||||
}: {
|
||||
tripId: number;
|
||||
name: string;
|
||||
@@ -508,6 +522,7 @@ export class BudgetMcp {
|
||||
note?: string;
|
||||
userIds?: number[];
|
||||
place_id?: number;
|
||||
reservation_id?: number;
|
||||
},
|
||||
ctx: McpContext,
|
||||
) {
|
||||
@@ -520,7 +535,7 @@ export class BudgetMcp {
|
||||
try {
|
||||
// The REST create's use case: the trip gate, the place check (#2084) and
|
||||
// budget:created alone, since the item it sends already carries its members.
|
||||
const data = { category, name, total_price, note, member_ids: members, place_id };
|
||||
const data = { category, name, total_price, note, member_ids: members, place_id, reservation_id };
|
||||
return ok({ item: await this.writes.createItem(tripId, data, writer) });
|
||||
} catch (err) {
|
||||
if (err instanceof DomainError) throw err;
|
||||
|
||||
@@ -15,7 +15,7 @@ import { findByIata } from '../airports/airports.data';
|
||||
import type { EndpointInput } from './reservations.service';
|
||||
import { AssignmentsService } from '../assignments/assignments.service';
|
||||
import {
|
||||
idSchema, transportLegInputSchema, reservationUrlSchema, type TransportLegInput,
|
||||
idSchema, transportLegInputSchema, reservationUrlSchema, type TransportLegInput, bookingPriceSchema, bookingBudgetCategorySchema,
|
||||
TRANSPORT_RESERVATION_TYPES, MCP_CREATABLE_TRANSPORT_TYPES, LEG_RESERVATION_TYPES, BOOKING_RESERVATION_TYPES,
|
||||
RESERVATION_STATUSES, type ReservationStatus,
|
||||
} from '@trek/shared';
|
||||
@@ -366,8 +366,8 @@ export class ReservationsMcp {
|
||||
check_in: z.string().max(10).optional().describe('Check-in time (e.g. "15:00", hotel type only)'),
|
||||
check_out: z.string().max(10).optional().describe('Check-out time (e.g. "11:00", hotel type only)'),
|
||||
assignment_id: idSchema.optional().describe('Link to a day assignment (restaurant, train, car, cruise, event, tour, activity, other)'),
|
||||
price: z.number().nonnegative().optional().describe(PRICE_FIELD),
|
||||
budget_category: z.string().max(100).optional().describe('Budget category for the price entry (defaults to reservation type)'),
|
||||
price: bookingPriceSchema.optional().describe(PRICE_FIELD),
|
||||
budget_category: bookingBudgetCategorySchema.optional().describe('Budget category for the price entry (defaults to reservation type)'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
|
||||
access: { group: 'reservations', mode: 'write' },
|
||||
@@ -673,8 +673,8 @@ export class ReservationsMcp {
|
||||
endpoints: endpointSchema,
|
||||
legs: legsSchema,
|
||||
needs_review: z.boolean().optional(),
|
||||
price: z.number().nonnegative().optional().describe(PRICE_FIELD),
|
||||
budget_category: z.string().max(100).optional().describe('Budget category for the price entry (defaults to transport type)'),
|
||||
price: bookingPriceSchema.optional().describe(PRICE_FIELD),
|
||||
budget_category: bookingBudgetCategorySchema.optional().describe('Budget category for the price entry (defaults to transport type)'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
|
||||
access: { group: 'reservations', mode: 'write' },
|
||||
|
||||
@@ -84,7 +84,8 @@ import { Module } from '@nestjs/common';
|
||||
// ReservationWritesService: the booking use cases the controller and the MCP tools share.
|
||||
// ReservationsReadMcp: the assistant's read of the bookings with their readable details.
|
||||
providers: [ReservationsService, ReservationWritesService, ReservationsMcp, ReservationsReadMcp, ReservationsRpc],
|
||||
// For in-container consumers (ReservationsRpc, TripsService, BookingImportService).
|
||||
exports: [ReservationsService],
|
||||
// For in-container consumers (ReservationsRpc, TripsService, BookingImportService);
|
||||
// ReservationWritesService for TransitMcp's create_transit_journey.
|
||||
exports: [ReservationsService, ReservationWritesService],
|
||||
})
|
||||
export class ReservationsModule {}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import { RateLimitService } from '../common/rate-limit.service';
|
||||
import { DaysService } from '../days/days.service';
|
||||
import { McpToolGuardsService } from '../mcp-shared/mcp-tool-guards.service';
|
||||
import { ReservationsService } from '../reservations/reservations.service';
|
||||
import { ReservationWritesService } from '../reservations/reservation-writes.service';
|
||||
import { TripAccessService } from '../trip-membership/trip-access.service';
|
||||
import {
|
||||
buildTransitReservationParts,
|
||||
@@ -22,7 +22,13 @@ import {
|
||||
} from './transit-itinerary.helpers';
|
||||
import { SCHEDULED_TRANSIT_MODES, type TransitItinerary } from './transit.helpers';
|
||||
import { TransitService } from './transit.service';
|
||||
import { adminTransitProviderRequestSchema, idSchema, type TransitProvider } from '@trek/shared';
|
||||
import {
|
||||
adminTransitProviderRequestSchema,
|
||||
bookingBudgetCategorySchema,
|
||||
bookingPriceSchema,
|
||||
idSchema,
|
||||
type TransitProvider,
|
||||
} from '@trek/shared';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -66,7 +72,7 @@ export class TransitMcp {
|
||||
constructor(
|
||||
private readonly transit: TransitService,
|
||||
private readonly days: DaysService,
|
||||
private readonly reservations: ReservationsService,
|
||||
private readonly writes: ReservationWritesService,
|
||||
// Plan 4 Task 2 — canAccessTrip's own DatabaseService delegation is gone:
|
||||
// this injects TripAccessService (trip-membership) (same constructor slot) and
|
||||
// calls findAccessible.
|
||||
@@ -178,7 +184,7 @@ export class TransitMcp {
|
||||
@Tool({
|
||||
name: 'create_transit_journey',
|
||||
description:
|
||||
'Add one itinerary returned by search_transit_routes to a trip day as a first-class automated public-transit journey. Pass the search response provider unchanged so fallback routes retain their source.',
|
||||
'Add one itinerary returned by search_transit_routes to a trip day as a first-class automated public-transit journey. Pass the search response provider unchanged so fallback routes retain their source. Set price to record the fare; it will appear on the journey and in the Budget tab.',
|
||||
inputSchema: {
|
||||
tripId: idSchema,
|
||||
dayId: idSchema.describe('Trip day on which the journey departs'),
|
||||
@@ -189,6 +195,10 @@ export class TransitMcp {
|
||||
.optional()
|
||||
.describe('Provider returned by search_transit_routes'),
|
||||
notes: z.string().max(1000).optional(),
|
||||
price: bookingPriceSchema.optional().describe('Fare — shown on the journey and linked in the Budget tab'),
|
||||
budget_category: bookingBudgetCategorySchema
|
||||
.optional()
|
||||
.describe('Budget category for the fare entry (defaults to transit)'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_OPEN_WORLD_NON_IDEMPOTENT,
|
||||
access: { group: 'reservations', mode: 'write' },
|
||||
@@ -202,6 +212,8 @@ export class TransitMcp {
|
||||
itinerary,
|
||||
provider,
|
||||
notes,
|
||||
price,
|
||||
budget_category,
|
||||
}: {
|
||||
tripId: number;
|
||||
dayId: number;
|
||||
@@ -212,6 +224,8 @@ export class TransitMcp {
|
||||
itinerary: TransitItinerary;
|
||||
provider?: TransitProvider;
|
||||
notes?: string;
|
||||
price?: number;
|
||||
budget_category?: string;
|
||||
},
|
||||
ctx: McpContext,
|
||||
) {
|
||||
@@ -268,21 +282,28 @@ export class TransitMcp {
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
const { reservation } = await this.reservations.create(tripId, {
|
||||
title: `${from.name} → ${to.name}`,
|
||||
type: 'transit',
|
||||
status: 'confirmed',
|
||||
day_id: dayId,
|
||||
end_day_id: endDay.id,
|
||||
reservation_time: `${departure.local_date}T${departure.local_time}`,
|
||||
reservation_end_time: `${arrival.local_date}T${arrival.local_time}`,
|
||||
notes,
|
||||
metadata,
|
||||
endpoints,
|
||||
needs_review: false,
|
||||
});
|
||||
this.guards.safeBroadcast(tripId, 'reservation:created', { reservation });
|
||||
await this.reservations.notifyBookingChange(tripId, ctx.userId, reservation.title, reservation.type || '');
|
||||
// The fare files the linked expense in the booking's own transaction and
|
||||
// rides along in the metadata, as create_transport's price does.
|
||||
const linkedCost =
|
||||
price != null && price > 0 ? { total_price: price, category: budget_category || 'transit' } : undefined;
|
||||
const { reservation } = await this.writes.createBooking(
|
||||
String(tripId),
|
||||
{
|
||||
title: `${from.name} → ${to.name}`,
|
||||
type: 'transit',
|
||||
status: 'confirmed',
|
||||
day_id: dayId,
|
||||
end_day_id: endDay.id,
|
||||
reservation_time: `${departure.local_date}T${departure.local_time}`,
|
||||
reservation_end_time: `${arrival.local_date}T${arrival.local_time}`,
|
||||
notes,
|
||||
metadata: price != null ? { ...metadata, price: String(price) } : metadata,
|
||||
endpoints,
|
||||
needs_review: false,
|
||||
},
|
||||
linkedCost,
|
||||
await this.guards.tripWriter(tripId, ctx.userId),
|
||||
);
|
||||
return ok({ reservation });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user