import { g as getActiveEndpoint } from './endpoints-UdQGgKsR.js';

//#region src/lib/server/opencode/http.ts
/**
* HTTP transport for talking to the active OpenCode endpoint.
*
* Used by sibling modules (`config.ts`, `catalog.ts`) — not part of the
* public API of `$lib/server/opencode`. Reads the active endpoint per-call
* so user switches in the UI take effect immediately.
*/
async function opencodeFetch(path, init) {
	const endpoint = getActiveEndpoint();
	const headers = {
		"content-type": "application/json",
		...init?.headers
	};
	if (endpoint.password) {
		const user = endpoint.username || "openpalm";
		headers["authorization"] = `Basic ${btoa(`${user}:${endpoint.password}`)}`;
	}
	const response = await fetch(`${endpoint.url}${path}`, {
		...init,
		headers
	});
	if (!response.ok) throw new Error(`${init?.method ?? "GET"} ${path} failed with ${response.status}`);
	if (response.status === 204) return;
	return await response.json();
}

export { opencodeFetch as o };
//# sourceMappingURL=http-D8YVIqJa.js.map
