import { b6 as useExistingProviderForAssistantCli, H as createLogger } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, e as errorResponse, p as parseJsonBody, j as jsonBodyError, k as jsonResponse } from './helpers-kzwksNq1.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';

//#region src/routes/admin/providers/assistant-clis/[toolId]/use-provider/+server.ts
var logger = createLogger("admin.assistant-cli-tools");
function isAssistantCliToolId(value) {
	return value === "codex" || value === "claude" || value === "copilot" || value === "pi";
}
var POST = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const toolId = event.params.toolId ?? "";
	if (!isAssistantCliToolId(toolId)) return errorResponse(400, "bad_request", "Invalid assistant CLI tool id", {}, requestId);
	const result = await parseJsonBody(event.request);
	if ("error" in result) return jsonBodyError(result, requestId);
	const providerId = typeof result.data.providerId === "string" ? result.data.providerId.trim() : "";
	if (!providerId) return errorResponse(400, "bad_request", "providerId is required", {}, requestId);
	try {
		const writtenPaths = useExistingProviderForAssistantCli(getState(), toolId, providerId);
		logger.info("assistant CLI provider mapping written", {
			requestId,
			toolId,
			providerId,
			writtenPaths
		});
		return jsonResponse(200, {
			ok: true,
			toolId,
			providerId,
			writtenPaths
		}, requestId);
	} catch (error) {
		return errorResponse(400, "bad_request", error instanceof Error ? error.message : "Failed to write assistant CLI credentials", {}, requestId);
	}
};

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