import { i as loadBundledPluginPublicSurfaceModuleSync } from "./facade-runtime-f64sgY_b.js";
import { i as streamSimple, o as getApiProvider } from "./stream-BJE9dn5k.js";
import { _ as sanitizeGoogleThinkingPayload } from "./provider-stream-shared-CXQ8xXG4.js";
import { i as streamWithPayloadPatch } from "./moonshot-thinking-RT-IFIsx.js";
import { a as prepareTransportAwareSimpleModel, i as createOpenClawTransportStreamFnForModel, n as buildTransportAwareSimpleStreamFn, o as resolveTransportAwareSimpleApi, s as ensureCustomApiRegistered, t as registerProviderStreamForModel } from "./provider-stream-DYTT3LLt.js";
//#region src/agents/anthropic-vertex-stream.ts
function loadAnthropicVertexStreamFacade() {
	return loadBundledPluginPublicSurfaceModuleSync({
		dirName: "anthropic-vertex",
		artifactBasename: "api.js"
	});
}
function createAnthropicVertexStreamFnForModel(model, env = process.env) {
	return loadAnthropicVertexStreamFacade().createAnthropicVertexStreamFnForModel(model, env);
}
//#endregion
//#region src/agents/google-simple-completion-stream.ts
const GOOGLE_SIMPLE_COMPLETION_API = "openclaw-google-generative-ai-simple";
const SOURCE_API = "google-generative-ai";
function resolveGoogleSimpleThinkingLevel(reasoning) {
	switch (reasoning) {
		case "off":
		case "minimal":
		case "low":
		case "medium":
		case "adaptive":
		case "high":
		case "max":
		case "xhigh": return reasoning;
		default: return;
	}
}
function buildGoogleSimpleCompletionStreamFn() {
	return (model, context, options) => {
		return streamWithPayloadPatch(streamSimple, {
			...model,
			api: SOURCE_API
		}, context, options, (payload) => {
			sanitizeGoogleThinkingPayload({
				payload,
				modelId: model.id,
				thinkingLevel: resolveGoogleSimpleThinkingLevel(options?.reasoning)
			});
		});
	};
}
function prepareGoogleSimpleCompletionModel(model) {
	if (model.api !== SOURCE_API) return model;
	ensureCustomApiRegistered(GOOGLE_SIMPLE_COMPLETION_API, buildGoogleSimpleCompletionStreamFn());
	return {
		...model,
		api: GOOGLE_SIMPLE_COMPLETION_API
	};
}
//#endregion
//#region src/agents/simple-completion-transport.ts
function resolveAnthropicVertexSimpleApi(baseUrl) {
	return `openclaw-anthropic-vertex-simple:${baseUrl?.trim() ? encodeURIComponent(baseUrl.trim()) : "default"}`;
}
function normalizeCodexResponsesBaseUrlForOpenAISdk(baseUrl) {
	const normalized = baseUrl?.trim().replace(/\/+$/u, "") || "https://chatgpt.com/backend-api";
	try {
		const parsed = new URL(normalized);
		const path = parsed.pathname.replace(/\/+$/u, "").toLowerCase();
		if (parsed.hostname.toLowerCase() === "chatgpt.com" && [
			"/backend-api",
			"/backend-api/v1",
			"/backend-api/codex",
			"/backend-api/codex/v1",
			"/backend-api/codex/responses"
		].includes(path)) {
			parsed.pathname = "/backend-api/codex";
			parsed.search = "";
			parsed.hash = "";
			return parsed.toString().replace(/\/$/u, "");
		}
	} catch {}
	if (normalized.endsWith("/codex/responses")) return normalized.slice(0, -10);
	if (normalized.endsWith("/codex")) return normalized;
	return `${normalized}/codex`;
}
function prepareCodexSimpleTransportModel(model, cfg) {
	if (model.provider !== "openai" || model.api !== "openai-chatgpt-responses") return;
	const transportModel = {
		...model,
		baseUrl: normalizeCodexResponsesBaseUrlForOpenAISdk(model.baseUrl)
	};
	const api = resolveTransportAwareSimpleApi(model.api);
	const streamFn = createOpenClawTransportStreamFnForModel(transportModel, { cfg });
	if (!api || !streamFn) return;
	ensureCustomApiRegistered(api, streamFn);
	return {
		...transportModel,
		api
	};
}
function prepareModelForSimpleCompletion(params) {
	const { model, cfg } = params;
	if (!getApiProvider(model.api) && registerProviderStreamForModel({
		model,
		cfg
	})) return model;
	const codexTransportModel = prepareCodexSimpleTransportModel(model, cfg);
	if (codexTransportModel) return codexTransportModel;
	const transportAwareModel = prepareTransportAwareSimpleModel(model, { cfg });
	if (transportAwareModel !== model) {
		const streamFn = buildTransportAwareSimpleStreamFn(model, { cfg });
		if (streamFn) {
			ensureCustomApiRegistered(transportAwareModel.api, streamFn);
			return transportAwareModel;
		}
	}
	if (model.api === "google-generative-ai") return prepareGoogleSimpleCompletionModel(model);
	if (model.provider === "anthropic-vertex") {
		const api = resolveAnthropicVertexSimpleApi(model.baseUrl);
		ensureCustomApiRegistered(api, createAnthropicVertexStreamFnForModel(model));
		return {
			...model,
			api
		};
	}
	return model;
}
//#endregion
export { createAnthropicVertexStreamFnForModel as n, prepareModelForSimpleCompletion as t };
