import { t as createSubsystemLogger } from "./subsystem-DE1xogkX.js";
import { n as createAnthropicThinkingPrefillPayloadWrapper } from "./provider-stream-shared-CmiFKfvZ.js";
import "./runtime-env-BIbsgQm4.js";
//#region extensions/cloudflare-ai-gateway/stream-wrappers.ts
const log = createSubsystemLogger("cloudflare-ai-gateway-stream");
function shouldPatchAnthropicMessagesPayload(model) {
	return model?.api === void 0 || model.api === "anthropic-messages";
}
/**
* Creates a wrapper that removes trailing assistant prefill messages before
* extended-thinking Anthropic requests are sent through Cloudflare.
*/
function createCloudflareAiGatewayAnthropicThinkingPrefillWrapper(baseStreamFn) {
	return createAnthropicThinkingPrefillPayloadWrapper(baseStreamFn, (stripped) => {
		log.warn(`removed ${stripped} trailing assistant prefill message${stripped === 1 ? "" : "s"} because Anthropic extended thinking requires conversations to end with a user turn`);
	});
}
/**
* Applies the Anthropic payload wrapper only for Anthropic-compatible models.
*/
function wrapCloudflareAiGatewayProviderStream(ctx) {
	if (!shouldPatchAnthropicMessagesPayload(ctx.model)) return ctx.streamFn;
	return createCloudflareAiGatewayAnthropicThinkingPrefillWrapper(ctx.streamFn);
}
/** Test-only access to wrapper decisions and logger injection points. */
const testing = {
	log,
	shouldPatchAnthropicMessagesPayload
};
//#endregion
export { testing as n, wrapCloudflareAiGatewayProviderStream as r, createCloudflareAiGatewayAnthropicThinkingPrefillWrapper as t };
