1// POST /api/keys/link-token (bearer): a single-use claim link for this2// machine, 10 minutes; opened while logged in, it binds the machine to3// the account.4import { define } from "../../../utils.ts";5import { createLink, machineOfBearer } from "../../../lib/identity.ts";6import { machineRegistry } from "../../../lib/mcp.ts";7import { publicOrigin } from "../../../lib/prompt.ts";89export const handler = define.handlers({10 async POST(ctx) {11 const store = await machineRegistry();12 const m = await machineOfBearer(13 store,14 ctx.req.headers.get("authorization"),15 );16 if (!m) {17 return Response.json({18 error: "a bearer token from /api/keys/auth is required",19 }, {20 status: 401,21 });22 }23 const link = await createLink(store, m.machine_id, publicOrigin());24 return Response.json({ ...link, machine_id: m.machine_id }, {25 headers: { "Cache-Control": "no-store" },26 });27 },28});