import { _ as runSealgwMediaTask, f as resolveSealgwAllowPrivateNetwork, g as resolveSealgwRequestModel, i as SEALGW_PROVIDER_ID, m as resolveSealgwBaseUrl, p as resolveSealgwAuth, r as SEALGW_DISPLAY_DEFAULT_MODEL, s as downloadSealgwAsset, u as isSealgwAuthConfigured } from "./media-gateway-pQeaOUl7.js";
//#region extensions/sealgw/image-generation-provider.ts
const PROVIDER_LABEL = "SealGW Image";
function buildSealgwImageGenerationProvider() {
	return {
		id: SEALGW_PROVIDER_ID,
		label: "SealSeek Media Gateway",
		defaultModel: SEALGW_DISPLAY_DEFAULT_MODEL,
		capabilities: {
			generate: {
				maxCount: 4,
				supportsSize: true,
				supportsAspectRatio: false,
				supportsResolution: false
			},
			edit: { enabled: false }
		},
		isConfigured: ({ cfg, agentDir }) => isSealgwAuthConfigured(cfg, agentDir),
		async generateImage(req) {
			const fetchFn = fetch;
			const auth = await resolveSealgwAuth({
				cfg: req.cfg,
				agentDir: req.agentDir,
				store: req.authStore
			});
			if (!auth.apiKey) throw new Error("SealSeek media gateway API key missing: configure models.providers.sealseek (or sealgw) apiKey, or set SEALGW_API_KEY.");
			const baseUrl = resolveSealgwBaseUrl(req.cfg);
			const timeoutMs = req.timeoutMs ?? 6e5;
			const model = resolveSealgwRequestModel(req.model, req.cfg);
			const count = clampCount(req.count);
			const body = {
				prompt: req.prompt,
				n: count,
				model
			};
			if (req.size?.trim()) body.size = req.size.trim();
			const extra = req.providerOptions;
			if (extra && Object.keys(extra).length > 0) body.extra = extra;
			const { resultUrls, actualModel } = await runSealgwMediaTask({
				pathSegment: "images",
				body,
				apiKey: auth.apiKey,
				baseUrl,
				timeoutMs,
				providerLabel: PROVIDER_LABEL,
				capability: "image",
				fetchFn,
				allowPrivateNetwork: resolveSealgwAllowPrivateNetwork(req.cfg)
			});
			const images = [];
			for (const url of resultUrls) {
				const { buffer, mimeType } = await downloadSealgwAsset({
					url,
					timeoutMs,
					fetchFn,
					providerLabel: PROVIDER_LABEL
				});
				images.push({
					buffer,
					mimeType
				});
			}
			return {
				images,
				model: actualModel ?? model
			};
		}
	};
}
function clampCount(count) {
	if (typeof count !== "number" || !Number.isFinite(count) || count < 1) return 1;
	return Math.min(Math.floor(count), 10);
}
//#endregion
export { buildSealgwImageGenerationProvider as t };
