Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { getTaskManager } from "@/lib/a2a/taskManager";
import { getCachedSettings } from "@/lib/db/settings";

export async function GET(request?: NextRequest) {
  try {
    const [settings, stats] = await Promise.all([
      getCachedSettings(),
      Promise.resolve(getTaskManager().getStats()),
    ]);
    const enabled = settings.a2aEnabled === true;

    let agentCard: any = null;
    if (enabled) {
      try {
        const agentModule = await import("@/app/.well-known/agent.json/route");
        const cardResponse = await agentModule.GET(request);
        agentCard = await cardResponse.json();
      } catch {
        agentCard = null;
      }
    }

    return NextResponse.json({
      status: enabled ? "ok" : "disabled",
      online: enabled,
      enabled,
      tasks: stats,
      agent: agentCard
        ? {
            name: agentCard.name,
            description: agentCard.description,
            version: agentCard.version,
            url: agentCard.url,
          }
        : null,
      capabilities: agentCard?.capabilities || null,
      skills: Array.isArray(agentCard?.skills) ? agentCard.skills : [],
    });
  } catch (error) {
    const message = error instanceof Error ? error.message : "Failed to load A2A status";
    return NextResponse.json({ error: message }, { status: 500 });
  }
}