//#region src/agent/workflow/meta-locale.ts
function normalizeWorkflowLocale(language) {
	return language === "zh" ? "zh" : "en";
}
function resolveWorkflowLocalizedCopy(meta, locale) {
	const bundle = locale !== "en" ? meta.i18n?.[locale] : void 0;
	const examplePrompts = bundle?.examplePrompts && bundle.examplePrompts.length > 0 ? bundle.examplePrompts : meta.examplePrompts ?? [];
	return {
		description: pickNonEmpty(bundle?.description, meta.description),
		whenToUse: pickOptional(bundle?.whenToUse, meta.whenToUse),
		examplePrompts
	};
}
function pickNonEmpty(localized, fallback) {
	const trimmed = localized?.trim();
	return trimmed ? trimmed : fallback;
}
function pickOptional(localized, fallback) {
	const trimmed = localized?.trim();
	if (trimmed) return trimmed;
	return fallback?.trim() || void 0;
}
function validateExamplePrompts(value, path) {
	if (value === void 0) return void 0;
	if (!Array.isArray(value)) throw new Error(`${path} must be an array`);
	const prompts = [];
	for (let index = 0; index < value.length; index++) {
		const item = value[index];
		if (!item || typeof item !== "object") throw new Error(`${path}[${index}] must be an object`);
		const field = item.field;
		const text = item.text;
		if (typeof field !== "string" || !field.trim()) throw new Error(`${path}[${index}].field must be a non-empty string`);
		if (typeof text !== "string" || !text.trim()) throw new Error(`${path}[${index}].text must be a non-empty string`);
		prompts.push({
			field: field.trim(),
			text: text.trim()
		});
	}
	return prompts;
}
function validateMetaLocale(value, path) {
	if (!value || typeof value !== "object") throw new Error(`${path} must be an object`);
	const record = value;
	if (record.description !== void 0 && (typeof record.description !== "string" || !record.description.trim())) throw new Error(`${path}.description must be a non-empty string`);
	if (record.whenToUse !== void 0 && typeof record.whenToUse !== "string") throw new Error(`${path}.whenToUse must be a string`);
	validateExamplePrompts(record.examplePrompts, `${path}.examplePrompts`);
	return record;
}
function validateMetaI18n(value) {
	if (value === void 0) return void 0;
	if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("meta.i18n must be an object");
	const locales = {};
	for (const [locale, bundle] of Object.entries(value)) {
		if (!/^[a-z]{2}(-[A-Za-z]{2})?$/.test(locale)) throw new Error(`meta.i18n key "${locale}" must be a language tag like "zh" or "en"`);
		locales[locale] = validateMetaLocale(bundle, `meta.i18n.${locale}`);
	}
	return locales;
}
//#endregion
export { normalizeWorkflowLocale, resolveWorkflowLocalizedCopy, validateExamplePrompts, validateMetaI18n, validateMetaLocale };

//# sourceMappingURL=meta-locale.js.map