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.

930 B
Raw Blame
import { useState } from 'react';
import { useSearchParams } from 'react-router';
import { openrouterReturnCode } from '../../Settings/ai/aiConnectModel';
import type { Addon } from './addonModel';
import { usesConnection } from './aiAddons';

/**
 * The AI tile behind both admin shells: its three switches, how many are on,
 * and the settings dialog. The dialog opens by itself when OpenRouter's
 * sign-in returns here (`?ai=openrouter`), since the connection form that
 * finishes it lives inside.
 */
export function useAiAddonTile(aiAddons: Addon[]) {
  const [params] = useSearchParams();
  const [open, setOpen] = useState(() => openrouterReturnCode(params) !== undefined);
  const canSetUp = usesConnection(aiAddons);
  return {
    enabledCount: aiAddons.filter((a) => a.enabled).length,
    canSetUp,
    dialogOpen: open && canSetUp,
    openDialog: () => setOpen(true),
    closeDialog: () => setOpen(false),
  };
}