openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
32 lines (31 loc) • 1.55 kB
JavaScript
import { t as createSubsystemLogger } from "./subsystem-BzXSmsuh.js";
import { n as createAnthropicThinkingPrefillPayloadWrapper } from "./provider-stream-shared-BIV_zuwB.js";
import "./runtime-env-D_2q8-VK.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 };