//#region src/gateway/hono/lib/agent-model.ts
const TYPED_MODEL_ID_RE = /^[a-z][a-z0-9_-]{0,63}$/;
function isValidProviderModelRef(ref) {
	const trimmed = ref.trim();
	const idx = trimmed.indexOf("/");
	return idx > 0 && idx < trimmed.length - 1;
}
/**
* Coerce PATCH body `models[]` into validated typed model entries.
* Returns `null` to clear, `undefined` when input should be skipped, or cleaned array.
* Empty array after filtering → `null` (same as clear).
*/
function normalizePatchTypedModels(v) {
	if (v === void 0) return void 0;
	if (v === null) return null;
	if (!Array.isArray(v)) return void 0;
	const byId = /* @__PURE__ */ new Map();
	for (const raw of v) {
		if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
		const o = raw;
		const id = typeof o.id === "string" ? o.id.trim() : "";
		const model = typeof o.model === "string" ? o.model.trim() : "";
		if (!id || !TYPED_MODEL_ID_RE.test(id) || !model || !isValidProviderModelRef(model)) continue;
		const description = typeof o.description === "string" && o.description.trim() ? o.description.trim().slice(0, 500) : void 0;
		byId.set(id, description ? {
			id,
			description,
			model
		} : {
			id,
			model
		});
	}
	if (byId.size === 0) return null;
	return [...byId.values()];
}
/** Read `primary` from an `AgentModelConfig` object. */
function agentModelRefToString(ref) {
	if (!ref || typeof ref !== "object" || Array.isArray(ref)) return void 0;
	const p = ref.primary;
	return typeof p === "string" && p.trim() ? p : void 0;
}
function agentModelFallbacksToArray(ref) {
	if (!ref || typeof ref !== "object" || Array.isArray(ref)) return [];
	const f = ref.fallbacks;
	if (!Array.isArray(f)) return [];
	return f.filter((x) => typeof x === "string" && x.trim().length > 0);
}
/**
* Coerce a PATCH body `model` value into the canonical `{ primary, fallbacks? }`
* object form. Returns `undefined` when the input has no usable primary so the
* caller can skip the assignment.
*/
function normalizePatchAgentModel(v) {
	if (!v || typeof v !== "object" || Array.isArray(v)) return void 0;
	const o = v;
	const primary = typeof o.primary === "string" ? o.primary.trim() : "";
	if (!primary) return void 0;
	const fallbacks = Array.isArray(o.fallbacks) ? o.fallbacks.filter((x) => typeof x === "string" && x.trim().length > 0) : [];
	return fallbacks.length > 0 ? {
		primary,
		fallbacks
	} : { primary };
}
/** Read `timeoutMs` from an image-generation model ref (only set when ref is an object). */
function agentImageGenerationModelTimeoutMs(ref) {
	if (!ref || typeof ref !== "object" || Array.isArray(ref)) return null;
	const v = ref.timeoutMs;
	return typeof v === "number" && Number.isFinite(v) && v > 0 ? v : null;
}
/** Read `autoProviderFallback` from an image-generation model ref. Defaults to false. */
function agentImageGenerationModelAutoProviderFallback(ref) {
	if (!ref || typeof ref !== "object" || Array.isArray(ref)) return false;
	return ref.autoProviderFallback === true;
}
/**
* PATCH body normalizer for `agents.defaults.imageGenerationModel`. Always
* emits `{ primary, fallbacks?, timeoutMs?, autoProviderFallback? }`. Returns
* `undefined` when the input has no usable primary so the caller can skip the
* assignment.
*/
function normalizePatchAgentImageGenerationModel(v) {
	if (!v || typeof v !== "object" || Array.isArray(v)) return void 0;
	const o = v;
	const primary = typeof o.primary === "string" ? o.primary.trim() : "";
	if (!primary) return void 0;
	const out = { primary };
	const fallbacks = Array.isArray(o.fallbacks) ? o.fallbacks.filter((x) => typeof x === "string" && x.trim().length > 0).map((x) => x.trim()) : [];
	if (fallbacks.length > 0) out.fallbacks = fallbacks;
	if (typeof o.timeoutMs === "number" && Number.isFinite(o.timeoutMs) && o.timeoutMs > 0) out.timeoutMs = Math.floor(o.timeoutMs);
	if (o.autoProviderFallback === true) out.autoProviderFallback = true;
	return out;
}
//#endregion
export { agentImageGenerationModelAutoProviderFallback, agentImageGenerationModelTimeoutMs, agentModelFallbacksToArray, agentModelRefToString, normalizePatchAgentImageGenerationModel, normalizePatchAgentModel, normalizePatchTypedModels };

//# sourceMappingURL=agent-model.js.map