/**
 * GET /api/chat/link-patterns
 *
 * Returns the chat-output linkify rules with all `{base_url}` placeholders
 * expanded against installed connector configs. Patterns whose connector
 * isn't installed/configured are filtered out — chat UI just renders the
 * remaining ones via remarkLinkify (lib/chat/remark-linkify.ts).
 */

import { NextResponse } from 'next/server';
import { getActiveLinkPatterns, serializePatterns } from '@/lib/chat/link-patterns';

export async function GET() {
  try {
    const patterns = serializePatterns(getActiveLinkPatterns());
    return NextResponse.json({ ok: true, patterns });
  } catch (e) {
    return NextResponse.json(
      { ok: false, error: e instanceof Error ? e.message : String(e), patterns: [] },
      { status: 500 },
    );
  }
}
