import { t as formatDocsLink } from "./links-CM5vg8_V.js";
import { r as theme } from "./theme-D58JpUfy.js";
import { n as runCommandWithRuntime } from "./cli-utils-Bcv5KNkB.js";
import { a as resolveManifestProviderOnboardAuthFlags } from "./provider-auth-choices-81Kva3W2.js";
import { r as formatAuthChoiceChoicesForCli } from "./auth-choice-options-DAjA3_Gy.js";
import { t as CORE_ONBOARD_AUTH_FLAGS } from "./onboard-core-auth-flags-CINE1eGu.js";
//#region src/cli/program/register.onboard.ts
function resolveInstallDaemonFlag(command, opts) {
	if (!command || typeof command !== "object") return;
	const getOptionValueSource = "getOptionValueSource" in command ? command.getOptionValueSource : void 0;
	if (typeof getOptionValueSource !== "function") return;
	if (getOptionValueSource.call(command, "skipDaemon") === "cli") return false;
	if (getOptionValueSource.call(command, "installDaemon") === "cli") return Boolean(opts.installDaemon);
}
const AUTH_CHOICE_HELP = formatAuthChoiceChoicesForCli({
	includeLegacyAliases: true,
	includeSkip: true
});
function extractCliFlags(cliOption) {
	return cliOption.split(/[ ,|]+/).filter((part) => part.startsWith("-")).map((part) => {
		const equalsIndex = part.indexOf("=");
		return equalsIndex === -1 ? part : part.slice(0, equalsIndex);
	});
}
function resolveOnboardAuthFlags() {
	const seenCliFlags = /* @__PURE__ */ new Set();
	const flags = [];
	for (const flag of [...CORE_ONBOARD_AUTH_FLAGS, ...resolveManifestProviderOnboardAuthFlags()]) {
		const cliFlags = extractCliFlags(flag.cliOption);
		if (cliFlags.some((cliFlag) => seenCliFlags.has(cliFlag))) continue;
		for (const cliFlag of cliFlags) seenCliFlags.add(cliFlag);
		flags.push(flag);
	}
	return flags;
}
const ONBOARD_AUTH_FLAGS = resolveOnboardAuthFlags();
function pickOnboardProviderAuthOptionValues(opts) {
	return Object.fromEntries(ONBOARD_AUTH_FLAGS.map((flag) => [flag.optionKey, opts[flag.optionKey]]));
}
function registerOnboardCommand(program) {
	const command = program.command("onboard").description("引导设置认证、模型、网关、工作区、渠道和技能").addHelpText("after", () => `\n${theme.muted("文档：")} ${formatDocsLink("/cli/onboard", "docs.openclaw.ai/cli/onboard")}\n`).option("--workspace <dir>", "代理工作区目录（默认：~/.openclaw/workspace）").option("--reset", "在运行 onboard 前重置配置、凭证和会话（工作区仅在 --reset-scope full 时重置）").option("--reset-scope <scope>", "重置范围：config|config+creds+sessions|full").option("--non-interactive", "无提示运行", false).option("--modern", "使用对话式安装/修复助手", false).option("--accept-risk", "确认代理能力强大且完全系统访问存在风险（--non-interactive 时必需）", false).option("--flow <flow>", "引导流程：quickstart|advanced|manual|import").option("--mode <mode>", "引导模式：local|remote").option("--auth-choice <choice>", `认证：${AUTH_CHOICE_HELP}`).option("--token-provider <id>", "令牌提供商 ID（非交互式；与 --auth-choice token 一起使用）").option("--token <token>", "令牌值（非交互式；与 --auth-choice token 一起使用）").option("--token-profile-id <id>", "认证配置文件 ID（非交互式；默认：<provider>:manual）").option("--token-expires-in <duration>", "可选的令牌过期时长（例如 365d、12h）").option("--secret-input-mode <mode>", "API 密钥持久化模式：plaintext|ref（默认：plaintext）").option("--cloudflare-ai-gateway-account-id <id>", "Cloudflare 账户 ID").option("--cloudflare-ai-gateway-gateway-id <id>", "Cloudflare AI Gateway ID");
	for (const providerFlag of ONBOARD_AUTH_FLAGS) command.option(providerFlag.cliOption, providerFlag.description);
	command.option("--custom-base-url <url>", "自定义提供商基础 URL").option("--custom-api-key <key>", "自定义提供商 API 密钥（可选）").option("--custom-model-id <id>", "自定义提供商模型 ID").option("--custom-provider-id <id>", "自定义提供商 ID（可选；默认自动推导）").option("--custom-compatibility <mode>", "自定义提供商 API 兼容性：openai|anthropic（默认：openai）").option("--custom-image-input", "Mark the custom provider model as image-capable").option("--custom-text-input", "Mark the custom provider model as text-only").option("--gateway-port <port>", "网关端口").option("--gateway-bind <mode>", "网关绑定：loopback|tailnet|lan|auto|custom").option("--gateway-auth <mode>", "网关认证：token|password").option("--gateway-token <token>", "网关令牌（token 认证）").option("--gateway-token-ref-env <name>", "网关令牌 SecretRef 环境变量名（token 认证；例如 OPENCLAW_GATEWAY_TOKEN）").option("--gateway-password <password>", "网关密码（password 认证）").option("--remote-url <url>", "远程网关 WebSocket URL").option("--remote-token <token>", "远程网关令牌（可选）").option("--tailscale <mode>", "Tailscale：off|serve|funnel").option("--tailscale-reset-on-exit", "退出时重置 tailscale serve/funnel").option("--install-daemon", "安装网关服务").option("--no-install-daemon", "跳过网关服务安装").option("--skip-daemon", "跳过网关服务安装").option("--daemon-runtime <runtime>", "守护进程运行时：node|bun").option("--skip-channels", "跳过渠道设置").option("--skip-skills", "跳过技能设置").option("--skip-bootstrap", "Skip creating default agent workspace files").option("--skip-search", "跳过搜索提供商设置").option("--skip-health", "跳过健康检查").option("--skip-ui", "跳过控制面板/TUI 提示").option("--suppress-gateway-token-output", "Suppress token-bearing Gateway/UI output").option("--skip-hooks", "跳过钩子设置").option("--node-manager <name>", "技能的 Node 管理器：npm|pnpm|bun").option("--import-from <provider>", "Migration provider to run during onboarding").option("--import-source <path>", "Source agent home for --import-from").option("--import-secrets", "Import supported secrets during onboarding migration", false).option("--json", "输出 JSON 摘要", false);
	command.action(async (opts, commandRuntime) => {
		const { defaultRuntime } = await import("./runtime-DRhjCMq8.js");
		await runCommandWithRuntime(defaultRuntime, async () => {
			if (opts.modern) {
				const { runCrestodian } = await import("./crestodian/crestodian.js");
				await runCrestodian({
					message: opts.nonInteractive ? "overview" : void 0,
					yes: false,
					json: Boolean(opts.json),
					interactive: !opts.nonInteractive
				});
				return;
			}
			const installDaemon = resolveInstallDaemonFlag(commandRuntime, { installDaemon: Boolean(opts.installDaemon) });
			const gatewayPort = typeof opts.gatewayPort === "string" ? Number.parseInt(opts.gatewayPort, 10) : void 0;
			const providerAuthOptionValues = pickOnboardProviderAuthOptionValues(opts);
			const { setupWizardCommand } = await import("./onboard-CpI66ui1.js");
			await setupWizardCommand({
				workspace: opts.workspace,
				nonInteractive: Boolean(opts.nonInteractive),
				acceptRisk: Boolean(opts.acceptRisk),
				flow: opts.flow,
				mode: opts.mode,
				authChoice: opts.authChoice,
				tokenProvider: opts.tokenProvider,
				token: opts.token,
				tokenProfileId: opts.tokenProfileId,
				tokenExpiresIn: opts.tokenExpiresIn,
				secretInputMode: opts.secretInputMode,
				...providerAuthOptionValues,
				cloudflareAiGatewayAccountId: opts.cloudflareAiGatewayAccountId,
				cloudflareAiGatewayGatewayId: opts.cloudflareAiGatewayGatewayId,
				customBaseUrl: opts.customBaseUrl,
				customApiKey: opts.customApiKey,
				customModelId: opts.customModelId,
				customProviderId: opts.customProviderId,
				customCompatibility: opts.customCompatibility,
				customImageInput: opts.customTextInput === true ? false : opts.customImageInput === true ? true : void 0,
				gatewayPort: typeof gatewayPort === "number" && Number.isFinite(gatewayPort) ? gatewayPort : void 0,
				gatewayBind: opts.gatewayBind,
				gatewayAuth: opts.gatewayAuth,
				gatewayToken: opts.gatewayToken,
				gatewayTokenRefEnv: opts.gatewayTokenRefEnv,
				gatewayPassword: opts.gatewayPassword,
				remoteUrl: opts.remoteUrl,
				remoteToken: opts.remoteToken,
				tailscale: opts.tailscale,
				tailscaleResetOnExit: Boolean(opts.tailscaleResetOnExit),
				reset: Boolean(opts.reset),
				resetScope: opts.resetScope,
				installDaemon,
				daemonRuntime: opts.daemonRuntime,
				skipChannels: Boolean(opts.skipChannels),
				skipSkills: Boolean(opts.skipSkills),
				skipBootstrap: Boolean(opts.skipBootstrap),
				skipSearch: Boolean(opts.skipSearch),
				skipHealth: Boolean(opts.skipHealth),
				skipUi: Boolean(opts.skipUi),
				suppressGatewayTokenOutput: Boolean(opts.suppressGatewayTokenOutput),
				skipHooks: Boolean(opts.skipHooks),
				nodeManager: opts.nodeManager,
				importFrom: opts.importFrom,
				importSource: opts.importSource,
				importSecrets: Boolean(opts.importSecrets),
				json: Boolean(opts.json)
			}, defaultRuntime);
		});
	});
}
//#endregion
export { registerOnboardCommand };
