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.

1.4 KB
Raw Blame
import { Cable, type LucideIcon, MessagesSquare, ScanText } from 'lucide-react';
import type { Addon } from './addonModel';

/**
 * The three addons that talk to a language model, shown as one AI tile in the
 * integration column: the assistant in the trip, AI parsing (booking import)
 * and MCP (TREK inside other AI apps). Their ids, rows and settings stay their
 * own; only the page groups them. Assistant and parsing share one connection.
 */
const AI_ADDON_IDS = ['ai_assistant', 'llm_parsing', 'mcp'] as const;
export type AiAddonId = (typeof AI_ADDON_IDS)[number];

/** Each one's glyph, keyed by id: the icon column of an existing install still holds what it was seeded with. */
export const AI_ADDON_ICONS: Record<AiAddonId, LucideIcon> = {
  ai_assistant: MessagesSquare,
  llm_parsing: ScanText,
  mcp: Cable,
};

export function isAiAddon(addon: Addon): boolean {
  return (AI_ADDON_IDS as readonly string[]).includes(addon.id);
}

/** The AI addons this install has, in the tile's order. */
export function aiAddonsOf(addons: Addon[]): Addon[] {
  return AI_ADDON_IDS.flatMap((id) => addons.find((a) => a.id === id) ?? []);
}

/** Whether the shared connection is used at all: the assistant or AI parsing is on. */
export function usesConnection(addons: Addon[]): boolean {
  return addons.some((a) => (a.id === 'ai_assistant' || a.id === 'llm_parsing') && a.enabled);
}