const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
let __intlayer_api = require("@intlayer/api");
let __intlayer_config = require("@intlayer/config");

//#region src/utils/chunkInference.ts
/**
* Translates a single chunk via the OpenAI API.
* Includes retry logic if the call fails.
*/
const chunkInference = async (messages, aiOptions, configuration) => {
	let lastResult;
	await (0, __intlayer_config.retryManager)(async () => {
		const response = await (0, __intlayer_api.getIntlayerAPIProxy)(void 0, configuration).ai.customQuery({
			aiOptions,
			messages
		});
		if (!response.data) throw new Error("No response from AI API");
		const { fileContent, tokenUsed } = response.data;
		lastResult = {
			fileContent: fileContent.replaceAll("///chunksStart///", "").replaceAll("///chunkStart///", "").replaceAll("///chunksEnd///", "").replaceAll("///chunkEnd///", "").replaceAll("///chunksStart///", "").replaceAll("chunkStart///", "").replaceAll("chunksEnd///", "").replaceAll("chunkEnd///", "").replaceAll("///chunksStart", "").replaceAll("///chunkStart", "").replaceAll("///chunksEnd", "").replaceAll("///chunkEnd", "").replaceAll("chunksStart", "").replaceAll("chunkStart", "").replaceAll("chunksEnd", "").replaceAll("chunkEnd", ""),
			tokenUsed
		};
	})();
	return lastResult;
};

//#endregion
exports.chunkInference = chunkInference;
//# sourceMappingURL=chunkInference.cjs.map