diff --git a/bin/omarchy-cn-ai-setup b/bin/omarchy-cn-ai-setup index d64f16ff..ff9f070f 100755 --- a/bin/omarchy-cn-ai-setup +++ b/bin/omarchy-cn-ai-setup @@ -50,15 +50,27 @@ if ! omarchy-cn-ai-secret get "$provider" > /dev/null 2>&1; then printf '%s' "$key" | omarchy-cn-ai-secret set "$provider" fi +# Keep any existing profile intact until the new config proves itself +profile_file="$CN_AI_PROFILE_DIR/$name.toml" +if [[ -f $profile_file ]]; then + cp "$profile_file" "$profile_file.omarchycn-prev" +fi + omarchy-cn-ai-profile-create "$name" "$harness" "$provider" "$model" -# Activate only after the test passes (or the user skips it) if gum confirm "运行连接测试?"; then if ! omarchy-cn-ai-test "$name"; then - echo "测试未通过,Profile $name 已创建但未设为默认;修复后运行: omarchycn ai profile use $name" >&2 + if [[ -f $profile_file.omarchycn-prev ]]; then + mv "$profile_file.omarchycn-prev" "$profile_file" + echo "测试未通过,已恢复原 Profile $name" >&2 + else + rm -f "$profile_file" + echo "测试未通过,Profile $name 未保留" >&2 + fi exit 1 fi fi +rm -f "$profile_file.omarchycn-prev" omarchy-cn-ai-profile-use "$name" echo "完成。启动: omarchycn ai launch"