import { logger } from "../../../logger/index.mjs";
import { readAsset } from "../../../_virtual/_utils_asset.mjs";
import { extractJson } from "../../extractJSON.mjs";
import { generateText } from "ai";

//#region src/utils/AI/auditDictionaryMetadata/index.ts
const CHAT_GPT_PROMPT = readAsset("./PROMPT.md");
const aiDefaultOptions = {};
/**
* 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 auditDictionaryMetadata = async ({ tags, fileContent, applicationContext, aiConfig }) => {
	const prompt = CHAT_GPT_PROMPT.replace("{{tags}}", `${JSON.stringify(tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n"), null, 2)}`).replace("{{contentDeclaration}}", fileContent).replace("{{applicationContext}}", applicationContext ?? "");
	if (!aiConfig) {
		logger.error("Failed to configure AI model");
		return;
	}
	const { text: newContent, usage } = await generateText({
		...aiConfig,
		messages: [{
			role: "system",
			content: prompt
		}]
	});
	logger.info(`${usage?.totalTokens ?? 0} tokens used in the request`);
	return {
		fileContent: extractJson(newContent),
		tokenUsed: usage?.totalTokens ?? 0
	};
};

//#endregion
export { aiDefaultOptions, auditDictionaryMetadata };
//# sourceMappingURL=index.mjs.map