import { t as createSubsystemLogger } from "./subsystem-_lp1q2Mi.js";
import { t as loadEdwinPAIPlugins } from "./loader-364nXh92.js";
import { a as readConfigFileSnapshot, s as writeConfigFile } from "./config-VoJVjSgT.js";
import { N as normalizeAgentId, t as listAgentIds } from "./agent-scope-u760_XKU.js";
import { C as VENICE_MODEL_CATALOG, D as SYNTHETIC_MODEL_CATALOG, E as SYNTHETIC_DEFAULT_MODEL_REF, G as resolveCloudflareAiGatewayBaseUrl, O as buildSyntheticModelDefinition, S as VENICE_DEFAULT_MODEL_REF, T as SYNTHETIC_BASE_URL, U as CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF, W as buildCloudflareAiGatewayModelDefinition, at as upsertAuthProfile, f as resolveModelRefFromString, ft as resolveEdwinPAIAgentDir, h as buildXiaomiProvider, m as XIAOMI_DEFAULT_MODEL_ID, n as buildModelAliasIndex, w as buildVeniceModelDefinition, x as VENICE_BASE_URL, yt as DEFAULT_PROVIDER } from "./model-selection-CMHF17-l.js";
import { t as formatCliCommand } from "./command-format-D8drL8c2.js";
import { n as callGateway } from "./call-BuuyfSRn.js";
import { n as isWSLEnv } from "./wsl-BFoXHNBM.js";

//#region ../../src/plugins/providers.ts
const log = createSubsystemLogger("plugins");
function resolvePluginProviders(params) {
	return loadEdwinPAIPlugins({
		config: params.config,
		workspaceDir: params.workspaceDir,
		logger: {
			info: (msg) => log.info(msg),
			warn: (msg) => log.warn(msg),
			error: (msg) => log.error(msg),
			debug: (msg) => log.debug(msg)
		}
	}).providers.map((entry) => entry.provider);
}

//#endregion
//#region ../../src/commands/oauth-env.ts
function isRemoteEnvironment() {
	if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) return true;
	if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) return true;
	if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY && !isWSLEnv()) return true;
	return false;
}

//#endregion
//#region ../../src/commands/oauth-flow.ts
const validateRequiredInput = (value) => value.trim().length > 0 ? void 0 : "Required";
function createVpsAwareOAuthHandlers(params) {
	const manualPromptMessage = params.manualPromptMessage ?? "Paste the redirect URL (or authorization code)";
	let manualCodePromise;
	return {
		onAuth: async ({ url }) => {
			if (params.isRemote) {
				params.spin.stop("OAuth URL ready");
				params.runtime.log(`\nOpen this URL in your LOCAL browser:\n\n${url}\n`);
				manualCodePromise = params.prompter.text({
					message: manualPromptMessage,
					validate: validateRequiredInput
				}).then((value) => String(value));
				return;
			}
			params.spin.update(params.localBrowserMessage);
			await params.openUrl(url);
			params.runtime.log(`Open: ${url}`);
		},
		onPrompt: async (prompt) => {
			if (manualCodePromise) return manualCodePromise;
			const code = await params.prompter.text({
				message: prompt.message,
				placeholder: prompt.placeholder,
				validate: validateRequiredInput
			});
			return String(code);
		}
	};
}

//#endregion
//#region ../../src/commands/onboard-auth.credentials.ts
const resolveAuthAgentDir = (agentDir) => agentDir ?? resolveEdwinPAIAgentDir();
async function setAnthropicApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "anthropic:default",
		credential: {
			type: "api_key",
			provider: "anthropic",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setGeminiApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "google:default",
		credential: {
			type: "api_key",
			provider: "google",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setMinimaxApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "minimax:default",
		credential: {
			type: "api_key",
			provider: "minimax",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setMoonshotApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "moonshot:default",
		credential: {
			type: "api_key",
			provider: "moonshot",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setKimiCodingApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "kimi-coding:default",
		credential: {
			type: "api_key",
			provider: "kimi-coding",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setSyntheticApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "synthetic:default",
		credential: {
			type: "api_key",
			provider: "synthetic",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setVeniceApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "venice:default",
		credential: {
			type: "api_key",
			provider: "venice",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
const ZAI_DEFAULT_MODEL_REF = "zai/glm-4.7";
const XIAOMI_DEFAULT_MODEL_REF = "xiaomi/mimo-v2-flash";
const OPENROUTER_DEFAULT_MODEL_REF = "openrouter/auto";
const VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF = "vercel-ai-gateway/anthropic/claude-opus-4.5";
async function setZaiApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "zai:default",
		credential: {
			type: "api_key",
			provider: "zai",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setXiaomiApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "xiaomi:default",
		credential: {
			type: "api_key",
			provider: "xiaomi",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setOpenrouterApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "openrouter:default",
		credential: {
			type: "api_key",
			provider: "openrouter",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setCloudflareAiGatewayConfig(accountId, gatewayId, apiKey, agentDir) {
	const normalizedAccountId = accountId.trim();
	const normalizedGatewayId = gatewayId.trim();
	upsertAuthProfile({
		profileId: "cloudflare-ai-gateway:default",
		credential: {
			type: "api_key",
			provider: "cloudflare-ai-gateway",
			key: apiKey.trim(),
			metadata: {
				accountId: normalizedAccountId,
				gatewayId: normalizedGatewayId
			}
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setVercelAiGatewayApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "vercel-ai-gateway:default",
		credential: {
			type: "api_key",
			provider: "vercel-ai-gateway",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}
async function setOpencodeZenApiKey(key, agentDir) {
	upsertAuthProfile({
		profileId: "opencode:default",
		credential: {
			type: "api_key",
			provider: "opencode",
			key
		},
		agentDir: resolveAuthAgentDir(agentDir)
	});
}

//#endregion
//#region ../../src/commands/onboard-auth.models.ts
const MINIMAX_API_BASE_URL = "https://api.minimax.io/anthropic";
const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.1";
const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
const DEFAULT_MINIMAX_CONTEXT_WINDOW = 2e5;
const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
const MOONSHOT_CN_BASE_URL = "https://api.moonshot.cn/v1";
const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2.5";
const MOONSHOT_DEFAULT_MODEL_REF = `moonshot/${MOONSHOT_DEFAULT_MODEL_ID}`;
const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 256e3;
const MOONSHOT_DEFAULT_MAX_TOKENS = 8192;
const KIMI_CODING_MODEL_ID = "k2p5";
const KIMI_CODING_MODEL_REF = `kimi-coding/${KIMI_CODING_MODEL_ID}`;
const MINIMAX_API_COST = {
	input: 15,
	output: 60,
	cacheRead: 2,
	cacheWrite: 10
};
const MINIMAX_LM_STUDIO_COST = {
	input: 0,
	output: 0,
	cacheRead: 0,
	cacheWrite: 0
};
const MOONSHOT_DEFAULT_COST = {
	input: 0,
	output: 0,
	cacheRead: 0,
	cacheWrite: 0
};
const MINIMAX_MODEL_CATALOG = {
	"MiniMax-M2.1": {
		name: "MiniMax M2.1",
		reasoning: false
	},
	"MiniMax-M2.1-lightning": {
		name: "MiniMax M2.1 Lightning",
		reasoning: false
	}
};
function buildMinimaxModelDefinition(params) {
	const catalog = MINIMAX_MODEL_CATALOG[params.id];
	return {
		id: params.id,
		name: params.name ?? catalog?.name ?? `MiniMax ${params.id}`,
		reasoning: params.reasoning ?? catalog?.reasoning ?? false,
		input: ["text"],
		cost: params.cost,
		contextWindow: params.contextWindow,
		maxTokens: params.maxTokens
	};
}
function buildMinimaxApiModelDefinition(modelId) {
	return buildMinimaxModelDefinition({
		id: modelId,
		cost: MINIMAX_API_COST,
		contextWindow: DEFAULT_MINIMAX_CONTEXT_WINDOW,
		maxTokens: DEFAULT_MINIMAX_MAX_TOKENS
	});
}
function buildMoonshotModelDefinition() {
	return {
		id: MOONSHOT_DEFAULT_MODEL_ID,
		name: "Kimi K2.5",
		reasoning: false,
		input: ["text"],
		cost: MOONSHOT_DEFAULT_COST,
		contextWindow: MOONSHOT_DEFAULT_CONTEXT_WINDOW,
		maxTokens: MOONSHOT_DEFAULT_MAX_TOKENS
	};
}

//#endregion
//#region ../../src/commands/onboard-auth.config-core.ts
function applyZaiConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[ZAI_DEFAULT_MODEL_REF] = {
		...models[ZAI_DEFAULT_MODEL_REF],
		alias: models[ZAI_DEFAULT_MODEL_REF]?.alias ?? "GLM"
	};
	const existingModel = cfg.agents?.defaults?.model;
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: ZAI_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyOpenrouterProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[OPENROUTER_DEFAULT_MODEL_REF] = {
		...models[OPENROUTER_DEFAULT_MODEL_REF],
		alias: models[OPENROUTER_DEFAULT_MODEL_REF]?.alias ?? "OpenRouter"
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		}
	};
}
function applyVercelAiGatewayProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF] = {
		...models[VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF],
		alias: models[VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF]?.alias ?? "Vercel AI Gateway"
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		}
	};
}
function applyCloudflareAiGatewayProviderConfig(cfg, params) {
	const models = { ...cfg.agents?.defaults?.models };
	models[CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF] = {
		...models[CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF],
		alias: models[CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF]?.alias ?? "Cloudflare AI Gateway"
	};
	const providers = { ...cfg.models?.providers };
	const existingProvider = providers["cloudflare-ai-gateway"];
	const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
	const defaultModel = buildCloudflareAiGatewayModelDefinition();
	const mergedModels = existingModels.some((model) => model.id === defaultModel.id) ? existingModels : [...existingModels, defaultModel];
	const baseUrl = params?.accountId && params?.gatewayId ? resolveCloudflareAiGatewayBaseUrl({
		accountId: params.accountId,
		gatewayId: params.gatewayId
	}) : existingProvider?.baseUrl;
	if (!baseUrl) return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		}
	};
	const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {};
	const normalizedApiKey = (typeof existingApiKey === "string" ? existingApiKey : void 0)?.trim();
	providers["cloudflare-ai-gateway"] = {
		...existingProviderRest,
		baseUrl,
		api: "anthropic-messages",
		...normalizedApiKey ? { apiKey: normalizedApiKey } : {},
		models: mergedModels.length > 0 ? mergedModels : [defaultModel]
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
function applyVercelAiGatewayConfig(cfg) {
	const next = applyVercelAiGatewayProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyCloudflareAiGatewayConfig(cfg, params) {
	const next = applyCloudflareAiGatewayProviderConfig(cfg, params);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyOpenrouterConfig(cfg) {
	const next = applyOpenrouterProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: OPENROUTER_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyMoonshotProviderConfig(cfg) {
	return applyMoonshotProviderConfigWithBaseUrl(cfg, MOONSHOT_BASE_URL);
}
function applyMoonshotProviderConfigCn(cfg) {
	return applyMoonshotProviderConfigWithBaseUrl(cfg, MOONSHOT_CN_BASE_URL);
}
function applyMoonshotProviderConfigWithBaseUrl(cfg, baseUrl) {
	const models = { ...cfg.agents?.defaults?.models };
	models[MOONSHOT_DEFAULT_MODEL_REF] = {
		...models[MOONSHOT_DEFAULT_MODEL_REF],
		alias: models[MOONSHOT_DEFAULT_MODEL_REF]?.alias ?? "Kimi"
	};
	const providers = { ...cfg.models?.providers };
	const existingProvider = providers.moonshot;
	const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
	const defaultModel = buildMoonshotModelDefinition();
	const mergedModels = existingModels.some((model) => model.id === MOONSHOT_DEFAULT_MODEL_ID) ? existingModels : [...existingModels, defaultModel];
	const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {};
	const normalizedApiKey = (typeof existingApiKey === "string" ? existingApiKey : void 0)?.trim();
	providers.moonshot = {
		...existingProviderRest,
		baseUrl,
		api: "openai-completions",
		...normalizedApiKey ? { apiKey: normalizedApiKey } : {},
		models: mergedModels.length > 0 ? mergedModels : [defaultModel]
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
function applyMoonshotConfig(cfg) {
	const next = applyMoonshotProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: MOONSHOT_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyMoonshotConfigCn(cfg) {
	const next = applyMoonshotProviderConfigCn(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: MOONSHOT_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyKimiCodeProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[KIMI_CODING_MODEL_REF] = {
		...models[KIMI_CODING_MODEL_REF],
		alias: models[KIMI_CODING_MODEL_REF]?.alias ?? "Kimi K2.5"
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		}
	};
}
function applyKimiCodeConfig(cfg) {
	const next = applyKimiCodeProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: KIMI_CODING_MODEL_REF
				}
			}
		}
	};
}
function applySyntheticProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[SYNTHETIC_DEFAULT_MODEL_REF] = {
		...models[SYNTHETIC_DEFAULT_MODEL_REF],
		alias: models[SYNTHETIC_DEFAULT_MODEL_REF]?.alias ?? "MiniMax M2.1"
	};
	const providers = { ...cfg.models?.providers };
	const existingProvider = providers.synthetic;
	const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
	const syntheticModels = SYNTHETIC_MODEL_CATALOG.map(buildSyntheticModelDefinition);
	const mergedModels = [...existingModels, ...syntheticModels.filter((model) => !existingModels.some((existing) => existing.id === model.id))];
	const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {};
	const normalizedApiKey = (typeof existingApiKey === "string" ? existingApiKey : void 0)?.trim();
	providers.synthetic = {
		...existingProviderRest,
		baseUrl: SYNTHETIC_BASE_URL,
		api: "anthropic-messages",
		...normalizedApiKey ? { apiKey: normalizedApiKey } : {},
		models: mergedModels.length > 0 ? mergedModels : syntheticModels
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
function applySyntheticConfig(cfg) {
	const next = applySyntheticProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: SYNTHETIC_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyXiaomiProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[XIAOMI_DEFAULT_MODEL_REF] = {
		...models[XIAOMI_DEFAULT_MODEL_REF],
		alias: models[XIAOMI_DEFAULT_MODEL_REF]?.alias ?? "Xiaomi"
	};
	const providers = { ...cfg.models?.providers };
	const existingProvider = providers.xiaomi;
	const defaultProvider = buildXiaomiProvider();
	const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
	const defaultModels = defaultProvider.models ?? [];
	const hasDefaultModel = existingModels.some((model) => model.id === XIAOMI_DEFAULT_MODEL_ID);
	const mergedModels = existingModels.length > 0 ? hasDefaultModel ? existingModels : [...existingModels, ...defaultModels] : defaultModels;
	const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {};
	const normalizedApiKey = (typeof existingApiKey === "string" ? existingApiKey : void 0)?.trim();
	providers.xiaomi = {
		...existingProviderRest,
		baseUrl: defaultProvider.baseUrl,
		api: defaultProvider.api,
		...normalizedApiKey ? { apiKey: normalizedApiKey } : {},
		models: mergedModels.length > 0 ? mergedModels : defaultProvider.models
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
function applyXiaomiConfig(cfg) {
	const next = applyXiaomiProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: XIAOMI_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
/**
* Apply Venice provider configuration without changing the default model.
* Registers Venice models and sets up the provider, but preserves existing model selection.
*/
function applyVeniceProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[VENICE_DEFAULT_MODEL_REF] = {
		...models[VENICE_DEFAULT_MODEL_REF],
		alias: models[VENICE_DEFAULT_MODEL_REF]?.alias ?? "Llama 3.3 70B"
	};
	const providers = { ...cfg.models?.providers };
	const existingProvider = providers.venice;
	const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
	const veniceModels = VENICE_MODEL_CATALOG.map(buildVeniceModelDefinition);
	const mergedModels = [...existingModels, ...veniceModels.filter((model) => !existingModels.some((existing) => existing.id === model.id))];
	const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {};
	const normalizedApiKey = (typeof existingApiKey === "string" ? existingApiKey : void 0)?.trim();
	providers.venice = {
		...existingProviderRest,
		baseUrl: VENICE_BASE_URL,
		api: "openai-completions",
		...normalizedApiKey ? { apiKey: normalizedApiKey } : {},
		models: mergedModels.length > 0 ? mergedModels : veniceModels
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
/**
* Apply Venice provider configuration AND set Venice as the default model.
* Use this when Venice is the primary provider choice during onboarding.
*/
function applyVeniceConfig(cfg) {
	const next = applyVeniceProviderConfig(cfg);
	const existingModel = next.agents?.defaults?.model;
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...existingModel && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
					primary: VENICE_DEFAULT_MODEL_REF
				}
			}
		}
	};
}
function applyAuthProfileConfig(cfg, params) {
	const profiles = {
		...cfg.auth?.profiles,
		[params.profileId]: {
			provider: params.provider,
			mode: params.mode,
			...params.email ? { email: params.email } : {}
		}
	};
	const existingProviderOrder = cfg.auth?.order?.[params.provider];
	const preferProfileFirst = params.preferProfileFirst ?? true;
	const reorderedProviderOrder = existingProviderOrder && preferProfileFirst ? [params.profileId, ...existingProviderOrder.filter((profileId) => profileId !== params.profileId)] : existingProviderOrder;
	const order = existingProviderOrder !== void 0 ? {
		...cfg.auth?.order,
		[params.provider]: reorderedProviderOrder?.includes(params.profileId) ? reorderedProviderOrder : [...reorderedProviderOrder ?? [], params.profileId]
	} : cfg.auth?.order;
	return {
		...cfg,
		auth: {
			...cfg.auth,
			profiles,
			...order ? { order } : {}
		}
	};
}

//#endregion
//#region ../../src/commands/onboard-auth.config-minimax.ts
function applyMinimaxProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models["anthropic/claude-opus-4-5"] = {
		...models["anthropic/claude-opus-4-5"],
		alias: models["anthropic/claude-opus-4-5"]?.alias ?? "Opus"
	};
	models["lmstudio/minimax-m2.1-gs32"] = {
		...models["lmstudio/minimax-m2.1-gs32"],
		alias: models["lmstudio/minimax-m2.1-gs32"]?.alias ?? "Minimax"
	};
	const providers = { ...cfg.models?.providers };
	if (!providers.lmstudio) providers.lmstudio = {
		baseUrl: "http://127.0.0.1:1234/v1",
		apiKey: "lmstudio",
		api: "openai-responses",
		models: [buildMinimaxModelDefinition({
			id: "minimax-m2.1-gs32",
			name: "MiniMax M2.1 GS32",
			reasoning: false,
			cost: MINIMAX_LM_STUDIO_COST,
			contextWindow: 196608,
			maxTokens: 8192
		})]
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
function applyMinimaxConfig(cfg) {
	const next = applyMinimaxProviderConfig(cfg);
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...next.agents?.defaults?.model && "fallbacks" in next.agents.defaults.model ? { fallbacks: next.agents.defaults.model.fallbacks } : void 0,
					primary: "lmstudio/minimax-m2.1-gs32"
				}
			}
		}
	};
}
function applyMinimaxApiProviderConfig(cfg, modelId = "MiniMax-M2.1") {
	const providers = { ...cfg.models?.providers };
	const existingProvider = providers.minimax;
	const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
	const apiModel = buildMinimaxApiModelDefinition(modelId);
	const mergedModels = existingModels.some((model) => model.id === modelId) ? existingModels : [...existingModels, apiModel];
	const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {};
	const resolvedApiKey = typeof existingApiKey === "string" ? existingApiKey : void 0;
	const normalizedApiKey = resolvedApiKey?.trim() === "minimax" ? "" : resolvedApiKey;
	providers.minimax = {
		...existingProviderRest,
		baseUrl: MINIMAX_API_BASE_URL,
		api: "anthropic-messages",
		...normalizedApiKey?.trim() ? { apiKey: normalizedApiKey } : {},
		models: mergedModels.length > 0 ? mergedModels : [apiModel]
	};
	const models = { ...cfg.agents?.defaults?.models };
	models[`minimax/${modelId}`] = {
		...models[`minimax/${modelId}`],
		alias: "Minimax"
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		},
		models: {
			mode: cfg.models?.mode ?? "merge",
			providers
		}
	};
}
function applyMinimaxApiConfig(cfg, modelId = "MiniMax-M2.1") {
	const next = applyMinimaxApiProviderConfig(cfg, modelId);
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...next.agents?.defaults?.model && "fallbacks" in next.agents.defaults.model ? { fallbacks: next.agents.defaults.model.fallbacks } : void 0,
					primary: `minimax/${modelId}`
				}
			}
		}
	};
}

//#endregion
//#region ../../src/agents/opencode-zen-models.ts
const OPENCODE_ZEN_DEFAULT_MODEL = "claude-opus-4-5";
const OPENCODE_ZEN_DEFAULT_MODEL_REF = `opencode/${OPENCODE_ZEN_DEFAULT_MODEL}`;
const CACHE_TTL_MS = 3600 * 1e3;

//#endregion
//#region ../../src/commands/onboard-auth.config-opencode.ts
function applyOpencodeZenProviderConfig(cfg) {
	const models = { ...cfg.agents?.defaults?.models };
	models[OPENCODE_ZEN_DEFAULT_MODEL_REF] = {
		...models[OPENCODE_ZEN_DEFAULT_MODEL_REF],
		alias: models[OPENCODE_ZEN_DEFAULT_MODEL_REF]?.alias ?? "Opus"
	};
	return {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...cfg.agents?.defaults,
				models
			}
		}
	};
}
function applyOpencodeZenConfig(cfg) {
	const next = applyOpencodeZenProviderConfig(cfg);
	return {
		...next,
		agents: {
			...next.agents,
			defaults: {
				...next.agents?.defaults,
				model: {
					...next.agents?.defaults?.model && "fallbacks" in next.agents.defaults.model ? { fallbacks: next.agents.defaults.model.fallbacks } : void 0,
					primary: OPENCODE_ZEN_DEFAULT_MODEL_REF
				}
			}
		}
	};
}

//#endregion
//#region ../../src/commands/provider-auth-vault-import.ts
async function requestProviderAuthVaultImports(params) {
	const imports = params.result.vaultImports ?? [];
	if (imports.length === 0) return;
	for (const entry of imports) try {
		await callGateway({
			config: params.config,
			method: "vault.import.request",
			params: entry,
			timeoutMs: 5e3
		});
		params.runtime.log(`Vault import requested: ${entry.label} (${entry.credentialId}) from ${entry.sourceKind}:${entry.source}`);
	} catch (err) {
		params.runtime.log(`Vault import pending failed for ${entry.credentialId}; credential remains in auth profile fallback. ${String(err instanceof Error ? err.message : err)}`);
	}
}

//#endregion
//#region ../../src/commands/models/shared.ts
const ensureFlagCompatibility = (opts) => {
	if (opts.json && opts.plain) throw new Error("Choose either --json or --plain, not both.");
};
const formatTokenK = (value) => {
	if (!value || !Number.isFinite(value)) return "-";
	if (value < 1024) return `${Math.round(value)}`;
	return `${Math.round(value / 1024)}k`;
};
const formatMs = (value) => {
	if (value === null || value === void 0) return "-";
	if (!Number.isFinite(value)) return "-";
	if (value < 1e3) return `${Math.round(value)}ms`;
	return `${Math.round(value / 100) / 10}s`;
};
async function updateConfig(mutator) {
	const snapshot = await readConfigFileSnapshot();
	if (!snapshot.valid) {
		const issues = snapshot.issues.map((issue) => `- ${issue.path}: ${issue.message}`).join("\n");
		throw new Error(`Invalid config at ${snapshot.path}\n${issues}`);
	}
	const next = mutator(snapshot.config);
	await writeConfigFile(next);
	return next;
}
function resolveModelTarget(params) {
	const aliasIndex = buildModelAliasIndex({
		cfg: params.cfg,
		defaultProvider: DEFAULT_PROVIDER
	});
	const resolved = resolveModelRefFromString({
		raw: params.raw,
		defaultProvider: DEFAULT_PROVIDER,
		aliasIndex
	});
	if (!resolved) throw new Error(`Invalid model reference: ${params.raw}`);
	return resolved.ref;
}
function normalizeAlias(alias) {
	const trimmed = alias.trim();
	if (!trimmed) throw new Error("Alias cannot be empty.");
	if (!/^[A-Za-z0-9_.:-]+$/.test(trimmed)) throw new Error("Alias must use letters, numbers, dots, underscores, colons, or dashes.");
	return trimmed;
}
function resolveKnownAgentId(params) {
	const raw = params.rawAgentId?.trim();
	if (!raw) return;
	const agentId = normalizeAgentId(raw);
	if (!listAgentIds(params.cfg).includes(agentId)) throw new Error(`Unknown agent id "${raw}". Use "${formatCliCommand("edwinpai agents list")}" to see configured agents.`);
	return agentId;
}
/**
* Model key format: "provider/model"
*
* The model key is displayed in `/model status` and used to reference models.
* When using `/model <key>`, use the exact format shown (e.g., "openrouter/moonshotai/kimi-k2").
*
* For providers with hierarchical model IDs (e.g., OpenRouter), the model ID may include
* sub-providers (e.g., "moonshotai/kimi-k2"), resulting in a key like "openrouter/moonshotai/kimi-k2".
*/

//#endregion
export { setZaiApiKey as $, applyVercelAiGatewayConfig as A, ZAI_DEFAULT_MODEL_REF as B, applyMoonshotProviderConfigCn as C, applySyntheticProviderConfig as D, applySyntheticConfig as E, KIMI_CODING_MODEL_REF as F, setMinimaxApiKey as G, setCloudflareAiGatewayConfig as H, MOONSHOT_DEFAULT_MODEL_REF as I, setOpenrouterApiKey as J, setMoonshotApiKey as K, OPENROUTER_DEFAULT_MODEL_REF as L, applyXiaomiConfig as M, applyXiaomiProviderConfig as N, applyVeniceConfig as O, applyZaiConfig as P, setXiaomiApiKey as Q, VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF as R, applyMoonshotProviderConfig as S, applyOpenrouterProviderConfig as T, setGeminiApiKey as U, setAnthropicApiKey as V, setKimiCodingApiKey as W, setVeniceApiKey as X, setSyntheticApiKey as Y, setVercelAiGatewayApiKey as Z, applyCloudflareAiGatewayProviderConfig as _, resolveKnownAgentId as a, applyMoonshotConfig as b, requestProviderAuthVaultImports as c, applyMinimaxApiConfig as d, createVpsAwareOAuthHandlers as et, applyMinimaxApiProviderConfig as f, applyCloudflareAiGatewayConfig as g, applyAuthProfileConfig as h, normalizeAlias as i, applyVercelAiGatewayProviderConfig as j, applyVeniceProviderConfig as k, applyOpencodeZenConfig as l, applyMinimaxProviderConfig as m, formatMs as n, resolvePluginProviders as nt, resolveModelTarget as o, applyMinimaxConfig as p, setOpencodeZenApiKey as q, formatTokenK as r, updateConfig as s, ensureFlagCompatibility as t, isRemoteEnvironment as tt, applyOpencodeZenProviderConfig as u, applyKimiCodeConfig as v, applyOpenrouterConfig as w, applyMoonshotConfigCn as x, applyKimiCodeProviderConfig as y, XIAOMI_DEFAULT_MODEL_REF as z };