import { o as resolveAgentModelPrimary, r as resolveAgentConfig } from "./agent-scope-DOrZjOnW.js";

//#region src/agents/defaults.ts
const DEFAULT_PROVIDER = "anthropic";
const DEFAULT_MODEL = "claude-opus-4-6";
const DEFAULT_CONTEXT_TOKENS = 2e5;

//#endregion
//#region src/agents/providers/anthropic.ts
const ANTHROPIC_PREFIXES$1 = [
	"claude-opus-4-6",
	"claude-sonnet-4-6",
	"claude-opus-4-5",
	"claude-sonnet-4-5",
	"claude-haiku-4-5"
];
const ANTHROPIC_MODEL_ALIASES = {
	"opus-4.6": "claude-opus-4-6",
	"opus-4.5": "claude-opus-4-5",
	"sonnet-4.6": "claude-sonnet-4-6",
	"sonnet-4.5": "claude-sonnet-4-5"
};
const anthropicAdapter = {
	id: "anthropic",
	aliases: ["claude-cli"],
	modernModelSubstrings: ANTHROPIC_PREFIXES$1,
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return ANTHROPIC_PREFIXES$1.some((prefix) => norm.startsWith(prefix));
	},
	normalizeModelId(id) {
		const trimmed = id.trim();
		if (!trimmed) return trimmed;
		return ANTHROPIC_MODEL_ALIASES[trimmed.toLowerCase()] ?? trimmed;
	}
};

//#endregion
//#region src/agents/providers/bedrock.ts
const bedrockAdapter = {
	id: "bedrock",
	isLiveModel() {
		return false;
	}
};

//#endregion
//#region src/agents/providers/github-copilot.ts
const githubCopilotAdapter = {
	id: "github-copilot",
	isLiveModel() {
		return false;
	},
	transcriptHints() {
		return { hostsCopilotClaude: true };
	},
	async resolveRuntimeApiKey(rawApiKey) {
		const { resolveCopilotApiToken } = await import("./github-copilot-token-D-FdDfee.js").then((n) => n.n);
		return (await resolveCopilotApiToken({ githubToken: rawApiKey })).token;
	}
};

//#endregion
//#region src/agents/providers/google-antigravity.ts
const GOOGLE_PREFIXES$2 = ["gemini-3"];
const ANTHROPIC_PREFIXES = [
	"claude-opus-4-6",
	"claude-sonnet-4-6",
	"claude-opus-4-5",
	"claude-sonnet-4-5",
	"claude-haiku-4-5"
];
const googleAntigravityAdapter = {
	id: "google-antigravity",
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		if (GOOGLE_PREFIXES$2.some((prefix) => norm.startsWith(prefix))) return true;
		return ANTHROPIC_PREFIXES.some((prefix) => norm.startsWith(prefix));
	},
	oauthNeedsProjectId() {
		return true;
	}
};

//#endregion
//#region src/agents/providers/google-gemini-cli.ts
const GOOGLE_PREFIXES$1 = ["gemini-3"];
const googleGeminiCliAdapter = {
	id: "google-gemini-cli",
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return GOOGLE_PREFIXES$1.some((prefix) => norm.startsWith(prefix));
	},
	oauthNeedsProjectId() {
		return true;
	}
};

//#endregion
//#region src/agents/providers/google.ts
const GOOGLE_PREFIXES = ["gemini-3"];
function normalizeGoogleModelId(id) {
	if (id === "gemini-3-pro") return "gemini-3-pro-preview";
	if (id === "gemini-3-flash") return "gemini-3-flash-preview";
	return id;
}
const googleAdapter = {
	id: "google",
	modernModelSubstrings: GOOGLE_PREFIXES,
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return GOOGLE_PREFIXES.some((prefix) => norm.startsWith(prefix));
	},
	normalizeModelId(id) {
		return normalizeGoogleModelId(id);
	}
};

//#endregion
//#region src/agents/providers/grok.ts
const grokAdapter = {
	id: "grok",
	isLiveModel() {
		return false;
	}
};

//#endregion
//#region src/agents/providers/minimax.ts
const MINIMAX_PREFIXES$1 = ["minimax-m2.1", "minimax-m2.5"];
const minimaxAdapter = {
	id: "minimax",
	modernModelSubstrings: MINIMAX_PREFIXES$1,
	imageInputModelId: "MiniMax-VL-01",
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return MINIMAX_PREFIXES$1.some((prefix) => norm.startsWith(prefix));
	}
};

//#endregion
//#region src/agents/providers/mistral.ts
const mistralAdapter = {
	id: "mistral",
	isLiveModel() {
		return false;
	},
	transcriptHints() {
		return { defaultToMistral: true };
	}
};

//#endregion
//#region src/agents/providers/ollama.ts
const ollamaAdapter = {
	id: "ollama",
	isLiveModel() {
		return false;
	}
};

//#endregion
//#region src/agents/providers/openai-codex.ts
const CODEX_MODELS = [
	"gpt-5.2",
	"gpt-5.2-codex",
	"gpt-5.3-codex",
	"gpt-5.3-codex-spark",
	"gpt-5.1-codex",
	"gpt-5.1-codex-mini",
	"gpt-5.1-codex-max"
];
const openaiCodexAdapter = {
	id: "openai-codex",
	aliases: ["codex-cli"],
	modernModelSubstrings: CODEX_MODELS,
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return CODEX_MODELS.some((value) => norm === value || norm.startsWith(value));
	}
};

//#endregion
//#region src/agents/providers/openai.ts
const OPENAI_MODELS = ["gpt-5.2", "gpt-5.0"];
const CODEX_OAUTH_MODEL_PREFIXES = ["gpt-5.3-codex"];
const openaiAdapter = {
	id: "openai",
	modernModelSubstrings: OPENAI_MODELS,
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return OPENAI_MODELS.some((value) => norm === value || norm.startsWith(value));
	},
	routeToProvider(modelId) {
		const norm = modelId.trim().toLowerCase();
		if (!norm) return;
		return CODEX_OAUTH_MODEL_PREFIXES.some((prefix) => norm === prefix || norm.startsWith(`${prefix}-`)) ? "openai-codex" : void 0;
	},
	conflictingOAuthProviders() {
		return ["openai-codex"];
	}
};

//#endregion
//#region src/agents/providers/meta-helpers.ts
/**
* Used by meta-providers (openrouter, opencode) to detect models from
* any first-party provider's modern catalog. Exclude self-references to
* avoid infinite recursion if a meta-provider were to declare its own
* `modernModelSubstrings`.
*/
function collectAllModernSubstringsExcluding(excludeIds) {
	const exclude = new Set(excludeIds);
	const out = [];
	for (const adapter of listProviderAdapters()) {
		if (exclude.has(adapter.id)) continue;
		const subs = adapter.modernModelSubstrings;
		if (subs && subs.length > 0) out.push(...subs);
	}
	return out;
}

//#endregion
//#region src/agents/providers/opencode.ts
const MINIMAX_PREFIXES = ["minimax-m2.1", "minimax-m2.5"];
const opencodeAdapter = {
	id: "opencode",
	aliases: ["opencode-zen"],
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		if (norm.endsWith("-free")) return false;
		if (norm === "alpha-glm-4.7") return false;
		if (MINIMAX_PREFIXES.some((prefix) => norm.startsWith(prefix))) return false;
		return collectAllModernSubstringsExcluding(["openrouter", "opencode"]).some((value) => norm.includes(value));
	},
	transcriptHints() {
		return { routesGeminiVariants: true };
	}
};

//#endregion
//#region src/agents/providers/openrouter.ts
const openrouterAdapter = {
	id: "openrouter",
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return collectAllModernSubstringsExcluding(["openrouter", "opencode"]).some((value) => norm.includes(value));
	},
	streamHints() {
		return { openrouterHeaders: true };
	},
	transcriptHints() {
		return { routesGeminiVariants: true };
	}
};

//#endregion
//#region src/agents/providers/perplexity.ts
const perplexityAdapter = {
	id: "perplexity",
	isLiveModel() {
		return false;
	}
};

//#endregion
//#region src/agents/providers/redsand.ts
const redsandAdapter = {
	id: "redsand",
	isLiveModel() {
		return false;
	},
	transcriptHints() {
		return { defaultToGemma: true };
	}
};

//#endregion
//#region src/agents/providers/xai.ts
const XAI_PREFIXES = ["grok-4"];
const xaiAdapter = {
	id: "xai",
	modernModelSubstrings: XAI_PREFIXES,
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return XAI_PREFIXES.some((prefix) => norm.startsWith(prefix));
	}
};

//#endregion
//#region src/agents/providers/zai.ts
const ZAI_PREFIXES = [
	"glm-5",
	"glm-4.7",
	"glm-4.7-flash",
	"glm-4.7-flashx"
];
const zaiAdapter = {
	id: "zai",
	aliases: ["z.ai", "z-ai"],
	modernModelSubstrings: ZAI_PREFIXES,
	isLiveModel(id) {
		const norm = id.trim().toLowerCase();
		return ZAI_PREFIXES.some((prefix) => norm.startsWith(prefix));
	},
	streamHints() {
		return { zaiToolStream: true };
	}
};

//#endregion
//#region src/agents/providers/registry.ts
const ADAPTERS = [
	anthropicAdapter,
	bedrockAdapter,
	githubCopilotAdapter,
	googleAdapter,
	googleAntigravityAdapter,
	googleGeminiCliAdapter,
	grokAdapter,
	minimaxAdapter,
	mistralAdapter,
	ollamaAdapter,
	openaiAdapter,
	openaiCodexAdapter,
	opencodeAdapter,
	openrouterAdapter,
	perplexityAdapter,
	redsandAdapter,
	xaiAdapter,
	zaiAdapter
];
const BY_KEY = (() => {
	const map = /* @__PURE__ */ new Map();
	for (const adapter of ADAPTERS) {
		map.set(adapter.id.toLowerCase(), adapter);
		if (adapter.aliases) for (const alias of adapter.aliases) map.set(alias.toLowerCase(), adapter);
	}
	return map;
})();
/**
* Sentinel adapter returned when no specific adapter matches the
* provider key. Defaults all behavior to "no provider-specific logic"
* so callers can always invoke methods without null-checks.
*/
const DEFAULT_ADAPTER = {
	id: "<unknown>",
	isLiveModel() {
		return false;
	}
};
/**
* Look up a provider adapter by canonical id or alias. Returns the
* default sentinel adapter (which is safe to call) when the key is
* unknown — never returns null.
*/
function getProviderAdapter(provider) {
	if (!provider) return DEFAULT_ADAPTER;
	const key = provider.trim().toLowerCase();
	if (!key) return DEFAULT_ADAPTER;
	return BY_KEY.get(key) ?? DEFAULT_ADAPTER;
}
/** All registered adapters. Used by meta-helpers to collect modern substrings. */
function listProviderAdapters() {
	return ADAPTERS;
}

//#endregion
//#region src/agents/model-selection.ts
function normalizeAliasKey(value) {
	return value.trim().toLowerCase();
}
function modelKey(provider, model) {
	return `${provider}/${model}`;
}
function normalizeProviderId(provider) {
	const normalized = provider.trim().toLowerCase();
	if (normalized === "z.ai" || normalized === "z-ai") return "zai";
	if (normalized === "opencode-zen") return "opencode";
	if (normalized === "qwen") return "qwen-portal";
	if (normalized === "kimi-code") return "kimi-coding";
	if (normalized === "bytedance" || normalized === "doubao") return "volcengine";
	return normalized;
}
function findNormalizedProviderValue(entries, provider) {
	if (!entries) return;
	const providerKey = normalizeProviderId(provider);
	for (const [key, value] of Object.entries(entries)) if (normalizeProviderId(key) === providerKey) return value;
}
function findNormalizedProviderKey(entries, provider) {
	if (!entries) return;
	const providerKey = normalizeProviderId(provider);
	return Object.keys(entries).find((key) => normalizeProviderId(key) === providerKey);
}
function isCliProvider(provider, cfg) {
	const normalized = normalizeProviderId(provider);
	if (normalized === "claude-cli") return true;
	if (normalized === "codex-cli") return true;
	const backends = cfg?.agents?.defaults?.cliBackends ?? {};
	return Object.keys(backends).some((key) => normalizeProviderId(key) === normalized);
}
function normalizeProviderModelId(provider, model) {
	const adapter = getProviderAdapter(provider);
	if (adapter.normalizeModelId) return adapter.normalizeModelId(model);
	return model;
}
function shouldUseOpenAICodexProvider(provider, model) {
	return getProviderAdapter(provider).routeToProvider?.(model) === "openai-codex";
}
function normalizeModelRef(provider, model) {
	const normalizedProvider = normalizeProviderId(provider);
	const normalizedModel = normalizeProviderModelId(normalizedProvider, model.trim());
	if (shouldUseOpenAICodexProvider(normalizedProvider, normalizedModel)) return {
		provider: "openai-codex",
		model: normalizedModel
	};
	return {
		provider: normalizedProvider,
		model: normalizedModel
	};
}
function parseModelRef(raw, defaultProvider) {
	const trimmed = raw.trim();
	if (!trimmed) return null;
	const slash = trimmed.indexOf("/");
	if (slash === -1) return normalizeModelRef(defaultProvider, trimmed);
	const providerRaw = trimmed.slice(0, slash).trim();
	const model = trimmed.slice(slash + 1).trim();
	if (!providerRaw || !model) return null;
	return normalizeModelRef(providerRaw, model);
}
function normalizeModelSelection(value) {
	if (typeof value === "string") return value.trim() || void 0;
	if (!value || typeof value !== "object") return;
	const primary = value.primary;
	if (typeof primary === "string") return primary.trim() || void 0;
}
function resolveAllowlistModelKey(raw, defaultProvider) {
	const parsed = parseModelRef(raw, defaultProvider);
	if (!parsed) return null;
	return modelKey(parsed.provider, parsed.model);
}
function buildConfiguredAllowlistKeys(params) {
	const rawAllowlist = Object.keys(params.cfg?.agents?.defaults?.models ?? {});
	if (rawAllowlist.length === 0) return null;
	const keys = /* @__PURE__ */ new Set();
	for (const raw of rawAllowlist) {
		const key = resolveAllowlistModelKey(String(raw ?? ""), params.defaultProvider);
		if (key) keys.add(key);
	}
	return keys.size > 0 ? keys : null;
}
function buildModelAliasIndex(params) {
	const byAlias = /* @__PURE__ */ new Map();
	const byKey = /* @__PURE__ */ new Map();
	const rawModels = params.cfg.agents?.defaults?.models ?? {};
	for (const [keyRaw, entryRaw] of Object.entries(rawModels)) {
		const parsed = parseModelRef(String(keyRaw ?? ""), params.defaultProvider);
		if (!parsed) continue;
		const alias = String(entryRaw?.alias ?? "").trim();
		if (!alias) continue;
		const aliasKey = normalizeAliasKey(alias);
		byAlias.set(aliasKey, {
			alias,
			ref: parsed
		});
		const key = modelKey(parsed.provider, parsed.model);
		const existing = byKey.get(key) ?? [];
		existing.push(alias);
		byKey.set(key, existing);
	}
	return {
		byAlias,
		byKey
	};
}
function resolveModelRefFromString(params) {
	const trimmed = params.raw.trim();
	if (!trimmed) return null;
	if (!trimmed.includes("/")) {
		const aliasKey = normalizeAliasKey(trimmed);
		const aliasMatch = params.aliasIndex?.byAlias.get(aliasKey);
		if (aliasMatch) return {
			ref: aliasMatch.ref,
			alias: aliasMatch.alias
		};
	}
	const parsed = parseModelRef(trimmed, params.defaultProvider);
	if (!parsed) return null;
	return { ref: parsed };
}
function resolveConfiguredModelRef(params) {
	const rawModel = (() => {
		const raw = params.cfg.agents?.defaults?.model;
		if (typeof raw === "string") return raw.trim();
		return raw?.primary?.trim() ?? "";
	})();
	if (rawModel) {
		const trimmed = rawModel.trim();
		const aliasIndex = buildModelAliasIndex({
			cfg: params.cfg,
			defaultProvider: params.defaultProvider
		});
		if (!trimmed.includes("/")) {
			const aliasKey = normalizeAliasKey(trimmed);
			const aliasMatch = aliasIndex.byAlias.get(aliasKey);
			if (aliasMatch) return aliasMatch.ref;
			console.warn(`[symi] Model "${trimmed}" specified without provider. Falling back to "anthropic/${trimmed}". Please use "anthropic/${trimmed}" in your config.`);
			return {
				provider: "anthropic",
				model: trimmed
			};
		}
		const resolved = resolveModelRefFromString({
			raw: trimmed,
			defaultProvider: params.defaultProvider,
			aliasIndex
		});
		if (resolved) return resolved.ref;
	}
	return {
		provider: params.defaultProvider,
		model: params.defaultModel
	};
}
function resolveDefaultModelForAgent(params) {
	const agentModelOverride = params.agentId ? resolveAgentModelPrimary(params.cfg, params.agentId) : void 0;
	return resolveConfiguredModelRef({
		cfg: agentModelOverride && agentModelOverride.length > 0 ? {
			...params.cfg,
			agents: {
				...params.cfg.agents,
				defaults: {
					...params.cfg.agents?.defaults,
					model: {
						...typeof params.cfg.agents?.defaults?.model === "object" ? params.cfg.agents.defaults.model : void 0,
						primary: agentModelOverride
					}
				}
			}
		} : params.cfg,
		defaultProvider: DEFAULT_PROVIDER,
		defaultModel: DEFAULT_MODEL
	});
}
function resolveSubagentConfiguredModelSelection(params) {
	const agentConfig = resolveAgentConfig(params.cfg, params.agentId);
	return normalizeModelSelection(agentConfig?.subagents?.model) ?? normalizeModelSelection(params.cfg.agents?.defaults?.subagents?.model) ?? normalizeModelSelection(agentConfig?.model);
}
function resolveSubagentSpawnModelSelection(params) {
	const runtimeDefault = resolveDefaultModelForAgent({
		cfg: params.cfg,
		agentId: params.agentId
	});
	return normalizeModelSelection(params.modelOverride) ?? resolveSubagentConfiguredModelSelection({
		cfg: params.cfg,
		agentId: params.agentId
	}) ?? normalizeModelSelection(params.cfg.agents?.defaults?.model?.primary) ?? `${runtimeDefault.provider}/${runtimeDefault.model}`;
}
function buildAllowedModelSet(params) {
	const rawAllowlist = (() => {
		const modelMap = params.cfg.agents?.defaults?.models ?? {};
		return Object.keys(modelMap);
	})();
	const allowAny = rawAllowlist.length === 0;
	const defaultModel = params.defaultModel?.trim();
	const defaultRef = defaultModel && params.defaultProvider ? parseModelRef(defaultModel, params.defaultProvider) : null;
	const defaultKey = defaultRef ? modelKey(defaultRef.provider, defaultRef.model) : void 0;
	const catalogKeys = new Set(params.catalog.map((entry) => modelKey(entry.provider, entry.id)));
	if (allowAny) {
		if (defaultKey) catalogKeys.add(defaultKey);
		return {
			allowAny: true,
			allowedCatalog: params.catalog,
			allowedKeys: catalogKeys
		};
	}
	const allowedKeys = /* @__PURE__ */ new Set();
	const configuredProviders = params.cfg.models?.providers ?? {};
	for (const raw of rawAllowlist) {
		const parsed = parseModelRef(String(raw), params.defaultProvider);
		if (!parsed) continue;
		const key = modelKey(parsed.provider, parsed.model);
		const providerKey = normalizeProviderId(parsed.provider);
		if (isCliProvider(parsed.provider, params.cfg)) allowedKeys.add(key);
		else if (catalogKeys.has(key)) allowedKeys.add(key);
		else if (configuredProviders[providerKey] != null) allowedKeys.add(key);
	}
	if (defaultKey) allowedKeys.add(defaultKey);
	const allowedCatalog = params.catalog.filter((entry) => allowedKeys.has(modelKey(entry.provider, entry.id)));
	if (allowedCatalog.length === 0 && allowedKeys.size === 0) {
		if (defaultKey) catalogKeys.add(defaultKey);
		return {
			allowAny: true,
			allowedCatalog: params.catalog,
			allowedKeys: catalogKeys
		};
	}
	return {
		allowAny: false,
		allowedCatalog,
		allowedKeys
	};
}
function getModelRefStatus(params) {
	const allowed = buildAllowedModelSet({
		cfg: params.cfg,
		catalog: params.catalog,
		defaultProvider: params.defaultProvider,
		defaultModel: params.defaultModel
	});
	const key = modelKey(params.ref.provider, params.ref.model);
	return {
		key,
		inCatalog: params.catalog.some((entry) => modelKey(entry.provider, entry.id) === key),
		allowAny: allowed.allowAny,
		allowed: allowed.allowAny || allowed.allowedKeys.has(key)
	};
}
function resolveAllowedModelRef(params) {
	const trimmed = params.raw.trim();
	if (!trimmed) return { error: "invalid model: empty" };
	const aliasIndex = buildModelAliasIndex({
		cfg: params.cfg,
		defaultProvider: params.defaultProvider
	});
	const resolved = resolveModelRefFromString({
		raw: trimmed,
		defaultProvider: params.defaultProvider,
		aliasIndex
	});
	if (!resolved) return { error: `invalid model: ${trimmed}` };
	const status = getModelRefStatus({
		cfg: params.cfg,
		catalog: params.catalog,
		ref: resolved.ref,
		defaultProvider: params.defaultProvider,
		defaultModel: params.defaultModel
	});
	if (!status.allowed) return { error: `model not allowed: ${status.key}` };
	return {
		ref: resolved.ref,
		key: status.key
	};
}
function resolveThinkingDefault(params) {
	const configured = params.cfg.agents?.defaults?.thinkingDefault;
	if (configured) return configured;
	if ((params.catalog?.find((entry) => entry.provider === params.provider && entry.id === params.model))?.reasoning) return "low";
	return "off";
}
/**
* Resolve the model configured for Gmail hook processing.
* Returns null if hooks.gmail.model is not set.
*/
function resolveHooksGmailModel(params) {
	const hooksModel = params.cfg.hooks?.gmail?.model;
	if (!hooksModel?.trim()) return null;
	const aliasIndex = buildModelAliasIndex({
		cfg: params.cfg,
		defaultProvider: params.defaultProvider
	});
	return resolveModelRefFromString({
		raw: hooksModel,
		defaultProvider: params.defaultProvider,
		aliasIndex
	})?.ref ?? null;
}

//#endregion
export { DEFAULT_MODEL as C, DEFAULT_CONTEXT_TOKENS as S, resolveModelRefFromString as _, findNormalizedProviderValue as a, resolveThinkingDefault as b, modelKey as c, parseModelRef as d, resolveAllowedModelRef as f, resolveHooksGmailModel as g, resolveDefaultModelForAgent as h, findNormalizedProviderKey as i, normalizeModelRef as l, resolveConfiguredModelRef as m, buildConfiguredAllowlistKeys as n, getModelRefStatus as o, resolveAllowlistModelKey as p, buildModelAliasIndex as r, isCliProvider as s, buildAllowedModelSet as t, normalizeProviderId as u, resolveSubagentConfiguredModelSelection as v, DEFAULT_PROVIDER as w, getProviderAdapter as x, resolveSubagentSpawnModelSelection as y };