import { j as json } from './exports-D1quPX8S.js';
import { g as getOpenCodeClient } from './helpers-kzwksNq1.js';
import './utils-BSRjJDrZ.js';
import './src-CidJbygh.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';
import './endpoints-UdQGgKsR.js';
import './state-fxN45gBp.js';

//#region src/routes/api/setup/opencode/provider/[provider]/oauth/authorize/+server.ts
var PROVIDER_ID_RE = /^[a-zA-Z0-9_-]{1,64}$/;
var POST = async ({ params, request }) => {
	if (!PROVIDER_ID_RE.test(params.provider)) return json({
		ok: false,
		message: "Invalid provider"
	}, { status: 400 });
	try {
		const body = await request.json();
		const method = Number.isInteger(body.method) ? body.method : 0;
		const result = await getOpenCodeClient().startProviderOAuth(params.provider, method);
		if (!result.ok) return json({
			ok: false,
			message: "OAuth authorization failed"
		}, { status: 400 });
		return json({
			ok: true,
			...result.data
		});
	} catch {
		return json({
			ok: false,
			message: "OAuth authorization failed"
		}, { status: 500 });
	}
};

export { POST };
//# sourceMappingURL=_server.ts-CPQlueaR.js.map
