// List all marketplace connections (kind=connection).
//
// GET /api/connections
//   → { ok: true, connections: ConnectionItem[] }
//
// Each connection carries setup contract (setup_kind, credentials,
// verify_endpoint), the legacy single-row install state (installed,
// last_verified_at, account_label, last_4 — for back-compat), and
// `installs[]` — one row per scope (global/project/agent) that has a
// verified install on this Mac.

import { listConnections } from '../../../lib/connections.js';
import { listInstances } from '../../../lib/connection-instances.js';
import { summarizeConnection } from '../../../lib/connection-status.js';

export const dynamic = 'force-dynamic';
export const runtime = 'nodejs';

export async function GET() {
  const items = listConnections().map(connection => ({
    ...connection,
    status: summarizeConnection(connection),
    installs: listInstances(connection.slug),
  }));
  return Response.json({ ok: true, connections: items });
}
