const require_retryManager = require('../../../../config/dist/esm/retryManager.cjs');
const require_proxy = require('../api/dist/esm/proxy.cjs');

//#region ../@intlayer/cli/dist/esm/utils/chunkInference.mjs
/**
* Translates a single chunk via the OpenAI API.
* Includes retry logic if the call fails.
*/
const chunkInference = async (messages, aiOptions, configuration) => {
	let lastResult;
	await require_retryManager.retryManager(async () => {
		const response = await require_proxy.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