Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.4 KB
Raw Blame
import { NextRequest, NextResponse } from "next/server";
import { readJson } from "@/lib/host/request-api";
import { handleA2ACredentialAction } from "./route-credentials";
import { handleA2AMessageAction } from "./route-messages";
import {
  a2aOwnerContext,
  a2aRouteError,
  auditA2AFailure,
} from "./route-shared";

export async function handleA2APost(req: NextRequest) {
  const context = await a2aOwnerContext();
  if (!context)
    return NextResponse.json({ error: "owner_role_required" }, { status: 403 });
  const actor = context.session.device_id || "owner";
  const body = (await readJson(req)) as Record<string, unknown> | null;
  const action = String(body?.action || "");
  const target = typeof body?.target === "string" ? body.target : "";
  try {
    if (!body)
      return NextResponse.json({ error: "bad_request" }, { status: 400 });
    const credential = await handleA2ACredentialAction(
      action,
      body,
      actor,
      target,
    );
    if (credential) return credential;
    const message = await handleA2AMessageAction(
      req,
      action,
      body,
      actor,
      target,
      `cli:${context.session.device_id}`,
    );
    return (
      message ?? NextResponse.json({ error: "unknown_action" }, { status: 400 })
    );
  } catch (error) {
    auditA2AFailure(action, actor, target, body, error);
    return a2aRouteError(error);
  }
}