import { normalizeProviderId } from "./model-selection.js";
import { isGoogleModelApi } from "./google-api.js";
import { isAnthropicProviderFamily, isOpenAiProviderFamily, preservesAnthropicThinkingSignatures, resolveTranscriptToolCallIdMode, shouldDropThinkingBlocksForModel, shouldSanitizeGeminiThoughtSignaturesForModel, supportsOpenAiCompatTurnValidation } from "./provider-capabilities.js";
//#region src/agent/transcript/transcript-policy.ts
const OPENAI_MODEL_APIS = new Set([
	"openai",
	"openai-completions",
	"openai-responses",
	"openai-codex-responses"
]);
function isOpenAiApi(modelApi) {
	if (!modelApi) return false;
	return OPENAI_MODEL_APIS.has(modelApi);
}
function isOpenAiProvider(provider) {
	return isOpenAiProviderFamily(provider);
}
function isAnthropicApi(modelApi, provider) {
	if (modelApi === "anthropic-messages" || modelApi === "bedrock-converse-stream") return true;
	return isAnthropicProviderFamily(provider);
}
function resolveToolCallIdMode(providerToolCallIdMode, sanitizeToolCallIds, isMistral) {
	if (providerToolCallIdMode) return providerToolCallIdMode;
	if (isMistral) return "strict9";
	if (sanitizeToolCallIds) return "strict";
}
function resolveTranscriptPolicy(params) {
	const provider = normalizeProviderId(params.provider ?? "");
	const modelId = params.modelId ?? "";
	const isGoogle = isGoogleModelApi(params.modelApi);
	const isAnthropic = isAnthropicApi(params.modelApi, provider);
	const isOpenAi = isOpenAiProvider(provider) || !provider && isOpenAiApi(params.modelApi);
	const isStrictOpenAiCompatible = params.modelApi === "openai-completions" && !isOpenAi && supportsOpenAiCompatTurnValidation(provider);
	const providerToolCallIdMode = resolveTranscriptToolCallIdMode(provider, modelId);
	const isMistral = providerToolCallIdMode === "strict9";
	const shouldSanitizeGeminiThoughtSignaturesForProvider = shouldSanitizeGeminiThoughtSignaturesForModel({
		provider,
		modelId
	});
	const requiresOpenAiCompatibleToolIdSanitization = params.modelApi === "openai-completions";
	const dropThinkingBlocks = shouldDropThinkingBlocksForModel({
		provider,
		modelId
	});
	const needsNonImageSanitize = isGoogle || isAnthropic || isMistral || shouldSanitizeGeminiThoughtSignaturesForProvider;
	const sanitizeToolCallIds = isGoogle || isMistral || isAnthropic || requiresOpenAiCompatibleToolIdSanitization;
	const toolCallIdMode = resolveToolCallIdMode(providerToolCallIdMode, sanitizeToolCallIds, isMistral);
	const repairToolUseResultPairing = true;
	const sanitizeThoughtSignatures = shouldSanitizeGeminiThoughtSignaturesForProvider || isGoogle ? {
		allowBase64Only: true,
		includeCamelCase: true
	} : void 0;
	return {
		sanitizeMode: isOpenAi ? "images-only" : needsNonImageSanitize ? "full" : "images-only",
		sanitizeToolCallIds: !isOpenAi && sanitizeToolCallIds || requiresOpenAiCompatibleToolIdSanitization,
		toolCallIdMode,
		repairToolUseResultPairing,
		preserveSignatures: isAnthropic && preservesAnthropicThinkingSignatures(provider),
		sanitizeThoughtSignatures: isOpenAi ? void 0 : sanitizeThoughtSignatures,
		sanitizeThinkingSignatures: false,
		dropThinkingBlocks,
		applyGoogleTurnOrdering: !isOpenAi && (isGoogle || isStrictOpenAiCompatible),
		validateGeminiTurns: !isOpenAi && (isGoogle || isStrictOpenAiCompatible),
		validateAnthropicTurns: !isOpenAi && (isAnthropic || isStrictOpenAiCompatible),
		allowSyntheticToolResults: !isOpenAi && (isGoogle || isAnthropic)
	};
}
//#endregion
export { resolveTranscriptPolicy };

//# sourceMappingURL=transcript-policy.js.map