@echo off
chcp 65001 >nul
setlocal
title hermes-cn 安装器

set "BASE=https://proxy.bigmodel.internal.cnwelly.com"
set "WORK=%TEMP%\hermes-cn"
if not exist "%WORK%" mkdir "%WORK%"

echo.
echo [hermes-cn] 从 %BASE% 下载 install-cn.ps1 和 sha256sums.txt ...
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; iwr '%BASE%/install-cn.ps1' -OutFile '%WORK%\install-cn.ps1' -UseBasicParsing; iwr '%BASE%/sha256sums.txt' -OutFile '%WORK%\sha256sums.txt' -UseBasicParsing"
if errorlevel 1 (
  echo.
  echo [hermes-cn] 下载失败，请确认 Windows 能访问 %BASE%
  echo [hermes-cn] 按任意键关闭窗口...
  pause >nul
  exit /b 1
)

echo [hermes-cn] 开始安装 hermes-agent（可能需要数分钟）...
powershell -NoProfile -ExecutionPolicy Bypass -File "%WORK%\install-cn.ps1" -ChecksumsPath "%WORK%\sha256sums.txt" -StatusUrl "%BASE%/report" -ProxyUrl "https://proxy.bigmodel.internal.cnwelly.com" -SkipSetup
set "RC=%ERRORLEVEL%"

echo.
if "%RC%"=="0" (
  echo [hermes-cn] 安装完成（已跳过交互式 setup wizard）。
  echo.
  echo 下一步：在 Windows Terminal 或 PowerShell 7 中运行
  echo     hermes setup
  echo 来完成 API key 等配置（旧 cmd.exe 不支持向导所需的终端控制码）。
  echo.
  echo 按任意键关闭窗口...
) else (
  echo [hermes-cn] 安装结束，退出码 %RC%。按任意键关闭窗口...
)
pause >nul
exit /b %RC%
