diff --git a/src/engines/hermes/pages/setup.js b/src/engines/hermes/pages/setup.js index 883b607..9b72a7f 100644 --- a/src/engines/hermes/pages/setup.js +++ b/src/engines/hermes/pages/setup.js @@ -34,6 +34,8 @@ export function render() { let logs = [] let installing = false let installError = null + let installMode = 'local' // 'local' | 'custom' + let customGatewayUrl = 'http://127.0.0.1:8642' let progress = 0 let unlisten = null @@ -130,6 +132,46 @@ export function render() { // --- 安装阶段 --- function renderInstall() { + // 模式切换按钮 + const modeSwitch = ` +
+ + +
` + + if (installMode === 'custom') { + // 自定义模式:输入已有 Gateway 地址 + return `
+
+

${t('engine.installTitle')}

+

${t('engine.installCustomDesc')}

+ ${modeSwitch} + ${installError ? ` +
+ ${esc(installError)} +
+ ` : ''} +
+ +
+
+ +
+
+
` + } + + // 本地模式:一键安装 const btnText = installing ? `${ICONS.spinner} ${t('engine.installingBtn')}` : `${ICONS.rocket} ${t('engine.installBtn')}` const btnDisabled = installing ? 'disabled' : '' @@ -174,6 +216,7 @@ export function render() {

${t('engine.installTitle')}

${t('engine.installDescSimple')}

+ ${modeSwitch} ${errorBlock} ${progressBlock}
@@ -274,8 +317,21 @@ export function render() { draw() }) }) - // 安装按钮 + // 安装模式切换 + el.querySelectorAll('.hermes-mode-btn').forEach(btn => { + btn.addEventListener('click', () => { + const mode = btn.dataset.mode + if (mode && mode !== installMode) { + installMode = mode + installError = null + draw() + } + }) + }) + // 安装按钮(本地模式) el.querySelector('.hermes-install-btn')?.addEventListener('click', doInstall) + // 自定义连接按钮 + el.querySelector('.hermes-custom-connect')?.addEventListener('click', doCustomConnect) // 服务商预设按钮 el.querySelectorAll('.hermes-preset-btn').forEach(btn => { btn.addEventListener('click', () => { @@ -366,6 +422,39 @@ export function render() { } } + // --- 自定义连接流程 --- + async function doCustomConnect() { + const urlInput = el.querySelector('#hm-custom-url') + const url = urlInput?.value?.trim() + if (!url) { installError = t('engine.installCustomEmpty'); draw(); return } + + // 基础 URL 格式检查 + try { new URL(url) } catch { installError = t('engine.installCustomInvalidUrl'); draw(); return } + + installing = true + installError = null + draw() + + try { + // 保存 Gateway URL + await api.hermesSetGatewayUrl(url) + + // 测试连接 + const health = await api.hermesHealthCheck() + if (!health) throw new Error(t('engine.installCustomNoResponse')) + + installing = false + customGatewayUrl = url + // 连接成功,跳到配置步骤 + phase = 'configure' + draw() + } catch (e) { + installing = false + installError = t('engine.installCustomFailed', { error: e.message || e }) + draw() + } + } + // --- 安装流程 --- async function doInstall() { installing = true diff --git a/src/locales/modules/engine.js b/src/locales/modules/engine.js index 88af0bf..48618c4 100644 --- a/src/locales/modules/engine.js +++ b/src/locales/modules/engine.js @@ -30,6 +30,16 @@ export default { installInfoUv: _('自动下载 uv 包管理器(如未安装)', 'Auto-download uv package manager (if not installed)', '自動下載 uv 包管理器(如未安裝)'), installInfoCore: _('安装 hermes-agent 核心包', 'Install hermes-agent core package', '安裝 hermes-agent 核心包'), installInfoExtrasLater: _('扩展组件(定时任务、MCP、消息渠道等)可在安装后按需添加', 'Extensions (cron, MCP, messaging, etc.) can be added later as needed', '擴展組件(定時任務、MCP、訊息頻道等)可在安裝後按需添加'), + installModeLocal: _('本地', 'Local', '本地'), + installModeCustom: _('自定义', 'Custom', '自訂'), + installCustomDesc: _('连接到已有的 Hermes Agent Gateway 实例,适用于已在其他机器或手动安装的场景。', 'Connect to an existing Hermes Agent Gateway instance, for setups on other machines or manual installations.', '連接到已有的 Hermes Agent Gateway 實例,適用於已在其他機器或手動安裝的場景。'), + installCustomHint: _('输入已运行的 Hermes Agent Gateway 地址,例如 http://192.168.1.100:8642', 'Enter the URL of a running Hermes Agent Gateway, e.g. http://192.168.1.100:8642', '輸入已運行的 Hermes Agent Gateway 地址,例如 http://192.168.1.100:8642'), + installCustomConnect: _('测试连接', 'Test Connection', '測試連接'), + installCustomTesting: _('连接中...', 'Connecting...', '連接中...'), + installCustomEmpty: _('请输入 Gateway URL', 'Please enter Gateway URL', '請輸入 Gateway URL'), + installCustomInvalidUrl: _('URL 格式不正确', 'Invalid URL format', 'URL 格式不正確'), + installCustomNoResponse: _('Gateway 无响应', 'Gateway not responding', 'Gateway 無回應'), + installCustomFailed: _('连接失败: {error}', 'Connection failed: {error}', '連接失敗: {error}'), installBtn: _('一键安装', 'Install Now', '一鍵安裝'), installingBtn: _('正在安装...', 'Installing...', '正在安裝...'), installSuccess: _('安装成功!', 'Installation successful!', '安裝成功!'),