HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
// Sign in to a self-hosted instance. Sets the session cookie; the middleware does the checking.
import type { NextRequest } from 'next/server';
import {
AUTH_DISABLED, SELF_HOSTED, SESSION_COOKIE, SESSION_TTL_MS, mintSession,
} from '@/lib/selfhost-auth';
import { credentialsValid } from '@/lib/selfhost-credentials';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
/** Deliberately uniform: "user not found" and "wrong password" are the same answer, because the
* difference only helps someone who doesn't know either. */
const REJECT = { detail: 'Incorrect username or password.' };
export async function POST(req: NextRequest) {
if (!SELF_HOSTED || AUTH_DISABLED) {
return Response.json({ detail: 'sign-in is not enabled on this instance' }, { status: 404 });
}
let body: { username?: string; password?: string };
try {
body = await req.json();
} catch {
return Response.json(REJECT, { status: 401 });
}
if (!credentialsValid(String(body.username || ''), String(body.password || ''))) {
// A small delay costs an honest user nothing and makes online guessing tediously slow.
await new Promise((r) => setTimeout(r, 400));
return Response.json(REJECT, { status: 401 });
}
const res = Response.json({ ok: true });
const secure = req.nextUrl.protocol === 'https:' ? '; Secure' : '';
res.headers.set('set-cookie',
`${SESSION_COOKIE}=${await mintSession()}; Path=/; Max-Age=${Math.floor(SESSION_TTL_MS / 1000)}`
+ `; HttpOnly; SameSite=Lax${secure}`);
return res;
}