Files
TREK/server/src/nest/addons/addon.guard.ts
T
Maurice 123e27643d feat(assistant): one AI tile for assistant, parsing and MCP, a planner-aware chat
The three AI addons share one tile in the integration column; a dialog holds
the connection, the assistant's limits and AI parsing, which now reads with
the assistant's connection unless an install keeps its own. Existing parsing
configs stay where they are and keep winning.

The chat sees the map on screen, offers next questions under an answer,
shows its live step in the window head, previews waiting changes inside the
day list, checks whether a day still works, folds a multi-day plan into a
week grid, keeps per-trip notes and can estimate costs. An empty or cut-off
answer gets one push instead of ending silently, and the assistant's own
step and size limits are raised.
2026-10-22 21:30:26 +00:00

36 lines
1.4 KiB
TypeScript

import { AddonsService } from './addons.service';
import { REQUIRE_ADDON, type RequireAddonMeta } from './require-addon.decorator';
import { CanActivate, ExecutionContext, HttpException, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
/**
* Enforces @RequireAddon. Replaces the three hand-written addon guards
* (collections, airtrail, journey), which differed only in which addon id they
* read and which word led the 404 body.
*
* A handler-level @RequireAddon overrides the controller's, so a route group
* can carry one addon and a single endpoint another. Without the decorator the
* guard is a no-op — it never gates a route that did not ask for it.
*/
@Injectable()
export class AddonGuard implements CanActivate {
constructor(
private readonly addons: AddonsService,
private readonly reflector: Reflector,
) {}
async canActivate(context: ExecutionContext): Promise<boolean> {
const meta = this.reflector.getAllAndOverride<RequireAddonMeta | undefined>(REQUIRE_ADDON, [
context.getHandler(),
context.getClass(),
]);
if (!meta) return true;
const ids = typeof meta.addonId === 'string' ? [meta.addonId] : meta.addonId;
const enabled = await Promise.all(ids.map((id) => this.addons.isAddonEnabled(id)));
if (!enabled.includes(true)) {
throw new HttpException({ error: `${meta.label} addon is not enabled` }, 404);
}
return true;
}
}