import { getIntlayerAPIProxy } from "@intlayer/api";
import { retryManager } from "@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 retryManager(async () => {
		const response = await 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
export { chunkInference };
//# sourceMappingURL=chunkInference.mjs.map