mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-26 17:38:36 +00:00
Adds a first-run Desktop choice between installing Hermes locally and connecting to an existing remote Hermes gateway. The choice appears after backend resolution but before ensureRuntime(), so selecting remote cannot accidentally trigger local bootstrap. New modules: - first-run-setup-gate: concurrent first-run decision gate and reset semantics - primary-backend-startup: Electron-free orchestration seam (saved remote resolution, gate decision, remote re-resolution, local continuation) - primary-connection-rehome: prevents dual-owner race where both cold boot() and renderer softSwitch() could connect simultaneously - first-run-remote-form: extracted remote form with stale-result guards Reuses existing connection-config IPC, encrypted token storage, OAuth session partition, and primary backend resolution. Fixes #38602 Fixes #36970
57 lines
954 B
TypeScript
57 lines
954 B
TypeScript
async function applyConnectionChange({
|
|
cancelAndWait,
|
|
isPrimary,
|
|
rehomePrimary = null,
|
|
scope,
|
|
sendApplied,
|
|
stopPool,
|
|
teardownPrimary,
|
|
teardownSsh
|
|
}) {
|
|
await cancelAndWait(scope)
|
|
await teardownSsh(scope)
|
|
|
|
if (!isPrimary) {
|
|
stopPool(scope)
|
|
|
|
return
|
|
}
|
|
|
|
if (rehomePrimary) {
|
|
await rehomePrimary()
|
|
|
|
return
|
|
}
|
|
|
|
await teardownPrimary()
|
|
sendApplied()
|
|
}
|
|
|
|
function commitConnectionFailure(current, starting, commit) {
|
|
if (current !== starting) {
|
|
return false
|
|
}
|
|
|
|
commit()
|
|
|
|
return true
|
|
}
|
|
|
|
async function resolveTerminalConnection(getTarget, ensureBackend) {
|
|
let target = getTarget()
|
|
|
|
if (target !== 'pending') {
|
|
return target
|
|
}
|
|
|
|
await ensureBackend()
|
|
target = getTarget()
|
|
|
|
if (target === 'pending') {
|
|
throw new Error('Remote connection is not ready yet. Try again in a moment.')
|
|
}
|
|
|
|
return target
|
|
}
|
|
|
|
export { applyConnectionChange, commitConnectionFailure, resolveTerminalConnection }
|