const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
const require_logger_index = require('../../../logger/index.cjs');
const require__utils_asset = require('../../../_virtual/_utils_asset.cjs');
let __intlayer_types = require("@intlayer/types");
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
let __intlayer_core = require("@intlayer/core");
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
let ai = require("ai");
ai = require_rolldown_runtime.__toESM(ai);

//#region src/utils/AI/auditDictionaryField/index.ts
const CHAT_GPT_PROMPT = require__utils_asset.readAsset("./PROMPT.md");
const aiDefaultOptions = {};
/**
* Format a locale with its name.
*
* @param locale - The locale to format.
* @returns A string in the format "locale: name", e.g. "en: English".
*/
const formatLocaleWithName = (locale) => {
	return `${locale}: ${(0, __intlayer_core.getLocaleName)(locale, __intlayer_types.Locales.ENGLISH)}`;
};
/**
* Formats tag instructions for the AI prompt.
*
* @param tags - Array of tags to format
* @returns A formatted string with tag instructions
*/
const formatTagInstructions = (tags) => {
	if (!tags || tags.length === 0) return "";
	return `Based on the dictionary content, identify specific tags from the list below that would be relevant:
  
${tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n")}`;
};
/**
* Audits a content declaration file by constructing a prompt for AI models.
* The prompt includes details about the project's locales, file paths of content declarations,
* and requests for identifying issues or inconsistencies.
*/
const auditDictionaryField = async ({ fileContent, applicationContext, locales, keyPath, tags, aiConfig }) => {
	const prompt = CHAT_GPT_PROMPT.replace("{{otherLocales}}", `{${locales.map(formatLocaleWithName).join(", ")}}`).replace("{{keyPath}}", JSON.stringify(keyPath)).replace("{{fileContent}}", fileContent).replace("{{applicationContext}}", applicationContext ?? "").replace("{{tagsInstructions}}", formatTagInstructions(tags));
	if (!aiConfig) {
		require_logger_index.logger.error("Failed to configure AI model");
		return;
	}
	const { text: newContent, usage } = await (0, ai.generateText)({
		...aiConfig,
		messages: [{
			role: "system",
			content: prompt
		}]
	});
	require_logger_index.logger.info(`${usage?.totalTokens ?? 0} tokens used in the request`);
	return {
		fileContent: newContent,
		tokenUsed: usage?.totalTokens ?? 0
	};
};

//#endregion
exports.aiDefaultOptions = aiDefaultOptions;
exports.auditDictionaryField = auditDictionaryField;
//# sourceMappingURL=index.cjs.map