import { b8 as writeFileAtomic } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse, p as parseJsonBody, j as jsonBodyError, e as errorResponse } from './helpers-kzwksNq1.js';
import { mkdirSync, existsSync, readFileSync } from 'node:fs';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
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/akm/+server.ts
function akmConfigPath(configDir) {
	return `${configDir}/akm/config.json`;
}
function readAkmConfig(configDir) {
	const path = akmConfigPath(configDir);
	if (!existsSync(path)) return {};
	try {
		return JSON.parse(readFileSync(path, "utf-8"));
	} catch {
		return {};
	}
}
function isRec(v) {
	return typeof v === "object" && v !== null && !Array.isArray(v);
}
function expectStr(v, field) {
	return typeof v === "string" ? v : /* @__PURE__ */ new Error(`${field} must be a string`);
}
function expectBool(v, field) {
	return typeof v === "boolean" ? v : /* @__PURE__ */ new Error(`${field} must be a boolean`);
}
function expectPosInt(v, field) {
	return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : /* @__PURE__ */ new Error(`${field} must be a positive integer`);
}
function expectNum(v, field, min, max) {
	return typeof v === "number" && v >= min && v <= max ? v : /* @__PURE__ */ new Error(`${field} must be a number between ${min} and ${max}`);
}
function validateLlmProfile(raw, prefix) {
	if ("endpoint" in raw) {
		const r = expectStr(raw.endpoint, `${prefix}.endpoint`);
		if (r instanceof Error) return r;
	}
	if ("model" in raw) {
		const r = expectStr(raw.model, `${prefix}.model`);
		if (r instanceof Error) return r;
	}
	if ("provider" in raw) {
		const r = expectStr(raw.provider, `${prefix}.provider`);
		if (r instanceof Error) return r;
	}
	if ("apiKey" in raw) {
		const r = expectStr(raw.apiKey, `${prefix}.apiKey`);
		if (r instanceof Error) return r;
	}
	if ("judgeModel" in raw) {
		const r = expectStr(raw.judgeModel, `${prefix}.judgeModel`);
		if (r instanceof Error) return r;
	}
	if ("temperature" in raw) {
		const r = expectNum(raw.temperature, `${prefix}.temperature`, 0, 2);
		if (r instanceof Error) return r;
	}
	if ("maxTokens" in raw) {
		const r = expectPosInt(raw.maxTokens, `${prefix}.maxTokens`);
		if (r instanceof Error) return r;
	}
	if ("timeoutMs" in raw) {
		const r = expectPosInt(raw.timeoutMs, `${prefix}.timeoutMs`);
		if (r instanceof Error) return r;
	}
	if ("concurrency" in raw) {
		const r = expectPosInt(raw.concurrency, `${prefix}.concurrency`);
		if (r instanceof Error) return r;
	}
	if ("contextLength" in raw) {
		const r = expectPosInt(raw.contextLength, `${prefix}.contextLength`);
		if (r instanceof Error) return r;
	}
	if ("supportsJsonSchema" in raw) {
		const r = expectBool(raw.supportsJsonSchema, `${prefix}.supportsJsonSchema`);
		if (r instanceof Error) return r;
	}
	if ("enableThinking" in raw) {
		const r = expectBool(raw.enableThinking, `${prefix}.enableThinking`);
		if (r instanceof Error) return r;
	}
	if ("capabilities" in raw) {
		if (!isRec(raw.capabilities)) return /* @__PURE__ */ new Error(`${prefix}.capabilities must be an object`);
		if ("structuredOutput" in raw.capabilities) {
			const r = expectBool(raw.capabilities.structuredOutput, `${prefix}.capabilities.structuredOutput`);
			if (r instanceof Error) return r;
		}
	}
	if ("extraParams" in raw && !isRec(raw.extraParams)) return /* @__PURE__ */ new Error(`${prefix}.extraParams must be an object`);
	return null;
}
function pickLlmProfile(raw) {
	const out = {};
	for (const f of [
		"endpoint",
		"model",
		"provider",
		"judgeModel"
	]) if (f in raw && raw[f]) out[f] = raw[f];
	if ("apiKey" in raw) {
		if (raw.apiKey) out.apiKey = raw.apiKey;
	}
	for (const f of [
		"temperature",
		"maxTokens",
		"timeoutMs",
		"concurrency",
		"contextLength"
	]) if (f in raw && raw[f] !== void 0) out[f] = raw[f];
	if ("supportsJsonSchema" in raw) out.supportsJsonSchema = raw.supportsJsonSchema;
	if ("enableThinking" in raw) out.enableThinking = raw.enableThinking;
	if (isRec(raw.capabilities) && Object.keys(raw.capabilities).length) out.capabilities = raw.capabilities;
	if (isRec(raw.extraParams) && Object.keys(raw.extraParams).length) out.extraParams = raw.extraParams;
	return out;
}
var ALLOWED_IMPROVE_PROCESSES = new Set([
	"reflect",
	"distill",
	"consolidate",
	"memoryInference",
	"graphExtraction",
	"validation",
	"extract",
	"triage"
]);
var APPLY_MODES = new Set(["queue", "promote"]);
var FEAT_MODES = new Set([
	"llm",
	"agent",
	"sdk"
]);
var AGENT_PLATFORMS = new Set([
	"opencode",
	"claude",
	"opencode-sdk"
]);
var SEMANTIC_SEARCH_MODES = new Set(["auto", "off"]);
var OUTPUT_FORMATS = new Set([
	"json",
	"yaml",
	"text"
]);
var OUTPUT_DETAILS = new Set([
	"brief",
	"normal",
	"full"
]);
function validateEnabledGate(v, path) {
	if (!isRec(v)) return /* @__PURE__ */ new Error(`${path} must be an object`);
	if ("enabled" in v) {
		const r = expectBool(v.enabled, `${path}.enabled`);
		if (r instanceof Error) return r;
	}
	return null;
}
function validateImproveProcess(proc, path) {
	if ("enabled" in proc) {
		const r = expectBool(proc.enabled, `${path}.enabled`);
		if (r instanceof Error) return r;
	}
	if ("mode" in proc && (typeof proc.mode !== "string" || !FEAT_MODES.has(proc.mode))) return /* @__PURE__ */ new Error(`${path}.mode must be llm, agent, or sdk`);
	if ("profile" in proc) {
		const r = expectStr(proc.profile, `${path}.profile`);
		if (r instanceof Error) return r;
	}
	if ("timeoutMs" in proc && proc.timeoutMs !== null) {
		const r = expectPosInt(proc.timeoutMs, `${path}.timeoutMs`);
		if (r instanceof Error) return r;
	}
	if ("allowedTypes" in proc) {
		if (!Array.isArray(proc.allowedTypes) || !proc.allowedTypes.every((t) => typeof t === "string" && t.length > 0)) return /* @__PURE__ */ new Error(`${path}.allowedTypes must be an array of non-empty strings`);
	}
	if ("qualityGate" in proc) {
		const r = validateEnabledGate(proc.qualityGate, `${path}.qualityGate`);
		if (r) return r;
	}
	if ("contradictionDetection" in proc) {
		const r = validateEnabledGate(proc.contradictionDetection, `${path}.contradictionDetection`);
		if (r) return r;
	}
	if ("defaultSince" in proc) {
		const r = expectStr(proc.defaultSince, `${path}.defaultSince`);
		if (r instanceof Error) return r;
	}
	if ("maxTotalChars" in proc) {
		const r = expectPosInt(proc.maxTotalChars, `${path}.maxTotalChars`);
		if (r instanceof Error) return r;
	}
	if ("maxChunkSize" in proc) {
		if (typeof proc.maxChunkSize !== "number" || !Number.isInteger(proc.maxChunkSize) || proc.maxChunkSize < 1 || proc.maxChunkSize > 50) return /* @__PURE__ */ new Error(`${path}.maxChunkSize must be an integer 1–50`);
	}
	if ("applyMode" in proc && (typeof proc.applyMode !== "string" || !APPLY_MODES.has(proc.applyMode))) return /* @__PURE__ */ new Error(`${path}.applyMode must be queue or promote`);
	if ("policy" in proc) {
		const r = expectStr(proc.policy, `${path}.policy`);
		if (r instanceof Error) return r;
	}
	if ("maxAcceptsPerRun" in proc) {
		const r = expectPosInt(proc.maxAcceptsPerRun, `${path}.maxAcceptsPerRun`);
		if (r instanceof Error) return r;
	}
	if ("maxDiffLines" in proc) {
		const r = expectPosInt(proc.maxDiffLines, `${path}.maxDiffLines`);
		if (r instanceof Error) return r;
	}
	if ("rejectEmpty" in proc) {
		const r = expectBool(proc.rejectEmpty, `${path}.rejectEmpty`);
		if (r instanceof Error) return r;
	}
	if ("judgment" in proc) {
		if (!isRec(proc.judgment)) return /* @__PURE__ */ new Error(`${path}.judgment must be an object`);
		const j = proc.judgment;
		if ("mode" in j && (typeof j.mode !== "string" || !FEAT_MODES.has(j.mode))) return /* @__PURE__ */ new Error(`${path}.judgment.mode must be llm, agent, or sdk`);
		if ("profile" in j) {
			const r = expectStr(j.profile, `${path}.judgment.profile`);
			if (r instanceof Error) return r;
		}
		if ("timeoutMs" in j && j.timeoutMs !== null) {
			const r = expectPosInt(j.timeoutMs, `${path}.judgment.timeoutMs`);
			if (r instanceof Error) return r;
		}
	}
	return null;
}
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	return jsonResponse(200, { config: readAkmConfig(getState().configDir) }, requestId);
};
var PATCH = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const state = getState();
	const result = await parseJsonBody(event.request);
	if ("error" in result) return jsonBodyError(result, requestId);
	const body = result.data;
	const profilesBody = body.profiles;
	if (profilesBody !== void 0 && !isRec(profilesBody)) return errorResponse(400, "bad_request", "profiles must be an object", {}, requestId);
	const profilesLlmBody = profilesBody?.llm;
	if (profilesLlmBody !== void 0) {
		if (!isRec(profilesLlmBody)) return errorResponse(400, "bad_request", "profiles.llm must be an object", {}, requestId);
		for (const [name, entry] of Object.entries(profilesLlmBody)) {
			if (!isRec(entry)) return errorResponse(400, "bad_request", `profiles.llm.${name} must be an object`, {}, requestId);
			const err = validateLlmProfile(entry, `profiles.llm.${name}`);
			if (err) return errorResponse(400, "bad_request", err.message, {}, requestId);
		}
	}
	const profilesAgentBody = profilesBody?.agent;
	if (profilesAgentBody !== void 0) {
		if (!isRec(profilesAgentBody)) return errorResponse(400, "bad_request", "profiles.agent must be an object", {}, requestId);
		for (const [name, entry] of Object.entries(profilesAgentBody)) {
			if (!isRec(entry)) return errorResponse(400, "bad_request", `profiles.agent.${name} must be an object`, {}, requestId);
			if ("platform" in entry && (typeof entry.platform !== "string" || !AGENT_PLATFORMS.has(entry.platform))) return errorResponse(400, "bad_request", `profiles.agent.${name}.platform must be opencode, claude, or opencode-sdk`, {}, requestId);
			if ("bin" in entry) {
				const r = expectStr(entry.bin, `profiles.agent.${name}.bin`);
				if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
			}
			if ("workspace" in entry) {
				const r = expectStr(entry.workspace, `profiles.agent.${name}.workspace`);
				if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
			}
			if ("model" in entry) {
				const r = expectStr(entry.model, `profiles.agent.${name}.model`);
				if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
			}
			if ("args" in entry && !Array.isArray(entry.args)) return errorResponse(400, "bad_request", `profiles.agent.${name}.args must be an array`, {}, requestId);
		}
	}
	const profilesImproveBody = profilesBody?.improve;
	if (profilesImproveBody !== void 0) {
		if (!isRec(profilesImproveBody)) return errorResponse(400, "bad_request", "profiles.improve must be an object", {}, requestId);
		for (const [name, entry] of Object.entries(profilesImproveBody)) {
			if (!isRec(entry)) return errorResponse(400, "bad_request", `profiles.improve.${name} must be an object`, {}, requestId);
			if ("description" in entry) {
				const r = expectStr(entry.description, `profiles.improve.${name}.description`);
				if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
			}
			if ("limit" in entry) {
				const r = expectPosInt(entry.limit, `profiles.improve.${name}.limit`);
				if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
			}
			if ("autoAccept" in entry && (typeof entry.autoAccept !== "number" || entry.autoAccept < 0)) return errorResponse(400, "bad_request", `profiles.improve.${name}.autoAccept must be a non-negative number`, {}, requestId);
			if ("processes" in entry) {
				if (!isRec(entry.processes)) return errorResponse(400, "bad_request", `profiles.improve.${name}.processes must be an object`, {}, requestId);
				for (const [procName, proc] of Object.entries(entry.processes)) {
					if (!ALLOWED_IMPROVE_PROCESSES.has(procName)) return errorResponse(400, "bad_request", `profiles.improve.${name}.processes.${procName} is not a recognized process name`, {}, requestId);
					if (!isRec(proc)) return errorResponse(400, "bad_request", `profiles.improve.${name}.processes.${procName} must be an object`, {}, requestId);
					const err = validateImproveProcess(proc, `profiles.improve.${name}.processes.${procName}`);
					if (err) return errorResponse(400, "bad_request", err.message, {}, requestId);
				}
			}
			if ("sync" in entry) {
				if (!isRec(entry.sync)) return errorResponse(400, "bad_request", `profiles.improve.${name}.sync must be an object`, {}, requestId);
				const sync = entry.sync;
				if ("enabled" in sync) {
					const r = expectBool(sync.enabled, `profiles.improve.${name}.sync.enabled`);
					if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
				}
				if ("push" in sync) {
					const r = expectBool(sync.push, `profiles.improve.${name}.sync.push`);
					if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
				}
				if ("message" in sync) {
					const r = expectStr(sync.message, `profiles.improve.${name}.sync.message`);
					if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
				}
			}
		}
	}
	const defaultsBody = body.defaults;
	if (defaultsBody !== void 0 && !isRec(defaultsBody)) return errorResponse(400, "bad_request", "defaults must be an object", {}, requestId);
	if (defaultsBody?.llm !== void 0) {
		const r = expectStr(defaultsBody.llm, "defaults.llm");
		if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
	}
	if (defaultsBody?.agent !== void 0) {
		const r = expectStr(defaultsBody.agent, "defaults.agent");
		if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
	}
	if (defaultsBody?.improve !== void 0) {
		const r = expectStr(defaultsBody.improve, "defaults.improve");
		if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
	}
	const embBody = body.embedding;
	if (embBody !== void 0) {
		if (!isRec(embBody)) return errorResponse(400, "bad_request", "embedding must be an object", {}, requestId);
		for (const f of [
			"endpoint",
			"model",
			"provider",
			"apiKey",
			"localModel"
		]) if (f in embBody) {
			const r = expectStr(embBody[f], `embedding.${f}`);
			if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
		}
		if ("dimension" in embBody) {
			const r = expectPosInt(embBody.dimension, "embedding.dimension");
			if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
		}
		for (const f of [
			"maxTokens",
			"batchSize",
			"chunkSize",
			"contextLength"
		]) if (f in embBody) {
			const r = expectPosInt(embBody[f], `embedding.${f}`);
			if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
		}
		if (isRec(embBody.ollamaOptions) && "num_ctx" in embBody.ollamaOptions) {
			const r = expectPosInt(embBody.ollamaOptions.num_ctx, "embedding.ollamaOptions.num_ctx");
			if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
		}
	}
	if ("semanticSearchMode" in body && (typeof body.semanticSearchMode !== "string" || !SEMANTIC_SEARCH_MODES.has(body.semanticSearchMode))) return errorResponse(400, "bad_request", "semanticSearchMode must be \"auto\" or \"off\"", {}, requestId);
	const outputBody = body.output;
	if (outputBody !== void 0) {
		if (!isRec(outputBody)) return errorResponse(400, "bad_request", "output must be an object", {}, requestId);
		if ("format" in outputBody && (typeof outputBody.format !== "string" || !OUTPUT_FORMATS.has(outputBody.format))) return errorResponse(400, "bad_request", "output.format must be json, yaml, or text", {}, requestId);
		if ("detail" in outputBody && (typeof outputBody.detail !== "string" || !OUTPUT_DETAILS.has(outputBody.detail))) return errorResponse(400, "bad_request", "output.detail must be brief, normal, or full", {}, requestId);
	}
	const improveTopBody = body.improve;
	if (improveTopBody !== void 0) {
		if (!isRec(improveTopBody)) return errorResponse(400, "bad_request", "improve must be an object", {}, requestId);
		if ("utilityDecay" in improveTopBody) {
			if (!isRec(improveTopBody.utilityDecay)) return errorResponse(400, "bad_request", "improve.utilityDecay must be an object", {}, requestId);
			const d = improveTopBody.utilityDecay;
			if ("halfLifeDays" in d && (typeof d.halfLifeDays !== "number" || d.halfLifeDays < .1)) return errorResponse(400, "bad_request", "improve.utilityDecay.halfLifeDays must be a number ≥ 0.1", {}, requestId);
			if ("feedbackStabilityBoost" in d && (typeof d.feedbackStabilityBoost !== "number" || d.feedbackStabilityBoost < 1)) return errorResponse(400, "bad_request", "improve.utilityDecay.feedbackStabilityBoost must be a number ≥ 1", {}, requestId);
		}
		if ("eventRetentionDays" in improveTopBody && (typeof improveTopBody.eventRetentionDays !== "number" || improveTopBody.eventRetentionDays < 0)) return errorResponse(400, "bad_request", "improve.eventRetentionDays must be a non-negative number", {}, requestId);
	}
	const searchBody = body.search;
	if (searchBody !== void 0) {
		if (!isRec(searchBody)) return errorResponse(400, "bad_request", "search must be an object", {}, requestId);
		if ("minScore" in searchBody && (typeof searchBody.minScore !== "number" || searchBody.minScore < 0)) return errorResponse(400, "bad_request", "search.minScore must be a non-negative number", {}, requestId);
		if ("curateRerank" in searchBody) {
			const r = validateEnabledGate(searchBody.curateRerank, "search.curateRerank");
			if (r) return errorResponse(400, "bad_request", r.message, {}, requestId);
		}
	}
	const feedbackBody = body.feedback;
	if (feedbackBody !== void 0) {
		if (!isRec(feedbackBody)) return errorResponse(400, "bad_request", "feedback must be an object", {}, requestId);
		if ("requireReason" in feedbackBody) {
			const r = expectBool(feedbackBody.requireReason, "feedback.requireReason");
			if (r instanceof Error) return errorResponse(400, "bad_request", r.message, {}, requestId);
		}
		if ("allowedFailureModes" in feedbackBody && (!Array.isArray(feedbackBody.allowedFailureModes) || !feedbackBody.allowedFailureModes.every((m) => typeof m === "string" && m.length > 0))) return errorResponse(400, "bad_request", "feedback.allowedFailureModes must be an array of non-empty strings", {}, requestId);
	}
	const indexBody = body.index;
	if (indexBody !== void 0 && !isRec(indexBody)) return errorResponse(400, "bad_request", "index must be an object keyed by pass name", {}, requestId);
	try {
		const existing = readAkmConfig(state.configDir);
		const updated = { ...existing };
		if (profilesBody !== void 0) {
			const existingProfiles = existing.profiles ?? {};
			const newProfiles = { ...existingProfiles };
			if (profilesLlmBody !== void 0) {
				const built = {};
				for (const [name, entry] of Object.entries(profilesLlmBody)) built[name] = pickLlmProfile(entry);
				newProfiles.llm = built;
			}
			if (profilesAgentBody !== void 0) {
				const built = {};
				for (const [name, entry] of Object.entries(profilesAgentBody)) {
					const raw = entry;
					const agentEntry = {};
					if ("platform" in raw) agentEntry.platform = raw.platform;
					if ("bin" in raw && raw.bin) agentEntry.bin = raw.bin;
					if ("args" in raw && Array.isArray(raw.args) && raw.args.length) agentEntry.args = raw.args;
					if ("workspace" in raw && raw.workspace) agentEntry.workspace = raw.workspace;
					if ("model" in raw && raw.model) agentEntry.model = raw.model;
					built[name] = agentEntry;
				}
				newProfiles.agent = built;
			}
			if (profilesImproveBody !== void 0) {
				const existingImprove = existingProfiles.improve ?? {};
				const builtImprove = {};
				for (const [name, entry] of Object.entries(profilesImproveBody)) {
					const raw = entry;
					const existingProfile = existingImprove[name] ?? {};
					const profileEntry = { ...existingProfile };
					if ("description" in raw && raw.description) profileEntry.description = raw.description;
					if ("limit" in raw) profileEntry.limit = raw.limit;
					if ("autoAccept" in raw) profileEntry.autoAccept = raw.autoAccept;
					if ("processes" in raw && isRec(raw.processes)) {
						const newProcs = { ...existingProfile.processes ?? {} };
						for (const [procName, proc] of Object.entries(raw.processes)) newProcs[procName] = proc;
						profileEntry.processes = newProcs;
					}
					if ("sync" in raw) if (isRec(raw.sync)) profileEntry.sync = raw.sync;
					else delete profileEntry.sync;
					builtImprove[name] = profileEntry;
				}
				newProfiles.improve = builtImprove;
			}
			updated.profiles = newProfiles;
		}
		if (defaultsBody !== void 0) updated.defaults = {
			...existing.defaults ?? {},
			..."llm" in defaultsBody ? { llm: defaultsBody.llm } : {},
			..."agent" in defaultsBody ? { agent: defaultsBody.agent } : {},
			..."improve" in defaultsBody ? { improve: defaultsBody.improve } : {}
		};
		if (embBody !== void 0) {
			const merged = { ...existing.embedding ?? {} };
			for (const f of [
				"endpoint",
				"model",
				"provider",
				"localModel"
			]) if (f in embBody) if (embBody[f]) merged[f] = embBody[f];
			else delete merged[f];
			if ("apiKey" in embBody) if (embBody.apiKey) merged.apiKey = embBody.apiKey;
			else delete merged.apiKey;
			if ("dimension" in embBody) merged.dimension = embBody.dimension;
			for (const f of [
				"maxTokens",
				"batchSize",
				"chunkSize",
				"contextLength"
			]) if (f in embBody) merged[f] = embBody[f];
			if (isRec(embBody.ollamaOptions) && "num_ctx" in embBody.ollamaOptions) merged.ollamaOptions = {
				...existing.embedding?.["ollamaOptions"] ?? {},
				num_ctx: embBody.ollamaOptions.num_ctx
			};
			updated.embedding = merged;
		}
		if ("semanticSearchMode" in body) updated.semanticSearchMode = body.semanticSearchMode;
		updated.stashDir = "/stash";
		if (outputBody !== void 0) updated.output = {
			...existing.output ?? {},
			..."format" in outputBody ? { format: outputBody.format } : {},
			..."detail" in outputBody ? { detail: outputBody.detail } : {}
		};
		if (improveTopBody !== void 0) updated.improve = improveTopBody;
		if (searchBody !== void 0) updated.search = searchBody;
		if (feedbackBody !== void 0) updated.feedback = feedbackBody;
		if (indexBody !== void 0) updated.index = indexBody;
		mkdirSync(`${state.configDir}/akm`, { recursive: true });
		writeFileAtomic(akmConfigPath(state.configDir), JSON.stringify(updated, null, 2), 384);
		return jsonResponse(200, {
			ok: true,
			config: updated
		}, requestId);
	} catch (e) {
		return errorResponse(500, "internal_error", `Failed to persist akm config: ${String(e)}`, {}, requestId);
	}
};

export { GET, PATCH };
//# sourceMappingURL=_server.ts-BSe6G25o.js.map
