Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

1.3 KB
Raw Blame
// GET /api/billing/withdrawals/:id — single withdrawal details

import { sql } from '../../_lib/db.js';
import { getSessionUser } from '../../_lib/auth.js';
import { cors, json, method, wrap, error, rateLimited } from '../../_lib/http.js';
import { limits, clientIp } from '../../_lib/rate-limit.js';
import { isUuid } from '../../_lib/validate.js';

export default wrap(async (req, res) => {
	if (cors(req, res, { methods: 'GET,OPTIONS', credentials: true })) return;
	if (!method(req, res, ['GET'])) return;

	const user = await getSessionUser(req);
	if (!user) return error(res, 401, 'unauthorized', 'sign in required');

	const rl = await limits.authedReadIp(clientIp(req));
	if (!rl.success) return rateLimited(res, rl);

	const id = req.query?.id;
	// `agent_withdrawals.id` is a uuid column: comparing it to a non-uuid string
	// makes Postgres raise 22P02, which surfaces as a 500 on a mistyped URL.
	if (!isUuid(id)) return error(res, 400, 'validation_error', 'withdrawal id must be a UUID');

	const [withdrawal] = await sql`
		select id, agent_id, amount, currency_mint, chain, to_address,
		       status, tx_signature, created_at, updated_at
		from agent_withdrawals
		where id = ${id} and user_id = ${user.id}
	`;

	if (!withdrawal) return error(res, 404, 'not_found', 'withdrawal not found');

	return json(res, 200, { withdrawal });
});