import { isOfficeDocumentMimeType, normalizeMimeType } from "@inkeep/agents-core/constants/allowed-file-formats";

//#region src/domains/run/utils/model-file-support.ts
function supportsOfficeDocuments(modelId) {
	if (!modelId) return false;
	const lower = modelId.toLowerCase();
	return lower.startsWith("openai/") || lower.startsWith("azure/") || /^(gpt-|o1-|o3-|o4-|chatgpt-)/.test(lower);
}
function stripIncompatibleOfficeParts(fileParts, modelId) {
	if (supportsOfficeDocuments(modelId)) return {
		compatible: fileParts,
		stripped: []
	};
	const compatible = [];
	const stripped = [];
	for (const part of fileParts) {
		const mimeType = normalizeMimeType(part.file.mimeType ?? "");
		if (isOfficeDocumentMimeType(mimeType)) stripped.push({
			mimeType,
			filename: typeof part.metadata?.filename === "string" ? part.metadata.filename : void 0
		});
		else compatible.push(part);
	}
	return {
		compatible,
		stripped
	};
}
function buildStrippedPartsNote(stripped) {
	return stripped.map(({ mimeType, filename }) => {
		return `[Attachment omitted: ${filename ? JSON.stringify(filename) : "(unnamed)"} (${mimeType}) — this file type is not supported in the current configuration. Please tell the user you are unable to access this file because the current assistant configuration does not support this file type.]`;
	}).join("\n");
}

//#endregion
export { buildStrippedPartsNote, stripIncompatibleOfficeParts, supportsOfficeDocuments };