import { i as buildBaseOptions } from "./sanitize-unicode-tdmtQ8a9.js";
import { t as AssistantMessageEventStream } from "./event-stream-CtKg0rzA.js";
import { n as getEnvApiKey } from "./env-api-keys-DrHBA-r2.js";
import { a as runGoogleGenerateContentLifecycle, i as getDisabledGoogleThinkingConfig, n as buildGoogleSimpleThinking, r as createGoogleAssistantOutput, t as buildGoogleGenerateContentParams } from "./google-shared-EGuqp9lq.js";
import { GoogleGenAI } from "@google/genai";
//#region src/llm/providers/google.ts
let toolCallCounter = 0;
const streamGoogle = (model, context, options) => {
	const stream = new AssistantMessageEventStream();
	runGoogleGenerateContentLifecycle({
		stream,
		model,
		output: createGoogleAssistantOutput(model, "google-generative-ai"),
		options,
		createClient: () => {
			return createClient(model, options?.apiKey || getEnvApiKey(model.provider) || "", options?.headers);
		},
		buildParams: () => buildParams(model, context, options),
		nextToolCallId: (name) => `${name}_${Date.now()}_${++toolCallCounter}`
	});
	return stream;
};
const streamSimpleGoogle = (model, context, options) => {
	const apiKey = options?.apiKey || getEnvApiKey(model.provider);
	if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
	return streamGoogle(model, context, {
		...buildBaseOptions(model, options, apiKey),
		thinking: buildGoogleSimpleThinking(model, options, {
			includeGemma4ThinkingLevel: true,
			useFlashLiteBudgets: true
		})
	});
};
function createClient(model, apiKey, optionsHeaders) {
	const httpOptions = {};
	if (model.baseUrl) {
		httpOptions.baseUrl = model.baseUrl;
		httpOptions.apiVersion = "";
	}
	if (model.headers || optionsHeaders) httpOptions.headers = {
		...model.headers,
		...optionsHeaders
	};
	return new GoogleGenAI({
		apiKey,
		httpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : void 0
	});
}
function buildParams(model, context, options = {}) {
	return buildGoogleGenerateContentParams(model, context, options, { getDisabledThinkingConfig: (model) => getDisabledGoogleThinkingConfig(model, { includeGemma4: true }) });
}
//#endregion
export { streamGoogle, streamSimpleGoogle };
