(
config: BridgeConfig,
)
| 140 | |
| 141 | return { |
| 142 | async registerBridgeEnvironment( |
| 143 | config: BridgeConfig, |
| 144 | ): Promise<{ environment_id: string; environment_secret: string }> { |
| 145 | debug( |
| 146 | `[bridge:api] POST /v1/environments/bridge bridgeId=${config.bridgeId}`, |
| 147 | ) |
| 148 | |
| 149 | const response = await withOAuthRetry( |
| 150 | (token: string) => |
| 151 | axios.post<{ |
| 152 | environment_id: string |
| 153 | environment_secret: string |
| 154 | }>( |
| 155 | `${deps.baseUrl}/v1/environments/bridge`, |
| 156 | { |
| 157 | machine_name: config.machineName, |
| 158 | directory: config.dir, |
| 159 | branch: config.branch, |
| 160 | git_repo_url: config.gitRepoUrl, |
| 161 | // Advertise session capacity so claude.ai/code can show |
| 162 | // "2/4 sessions" badges and only block the picker when |
| 163 | // actually at capacity. Backends that don't yet accept |
| 164 | // this field will silently ignore it. |
| 165 | max_sessions: config.maxSessions, |
| 166 | // worker_type lets claude.ai filter environments by origin |
| 167 | // (e.g. assistant picker only shows assistant-mode workers). |
| 168 | // Desktop cowork app sends "cowork"; we send a distinct value. |
| 169 | metadata: { worker_type: config.workerType }, |
| 170 | // Idempotent re-registration: if we have a backend-issued |
| 171 | // environment_id from a prior session (--session-id resume), |
| 172 | // send it back so the backend reattaches instead of creating |
| 173 | // a new env. The backend may still hand back a fresh ID if |
| 174 | // the old one expired — callers must compare the response. |
| 175 | ...(config.reuseEnvironmentId && { |
| 176 | environment_id: config.reuseEnvironmentId, |
| 177 | }), |
| 178 | }, |
| 179 | { |
| 180 | headers: getHeaders(token), |
| 181 | timeout: 15_000, |
| 182 | validateStatus: status => status < 500, |
| 183 | }, |
| 184 | ), |
| 185 | 'Registration', |
| 186 | ) |
| 187 | |
| 188 | handleErrorStatus(response.status, response.data, 'Registration') |
| 189 | debug( |
| 190 | `[bridge:api] POST /v1/environments/bridge -> ${response.status} environment_id=${response.data.environment_id}`, |
| 191 | ) |
| 192 | debug( |
| 193 | `[bridge:api] >>> ${debugBody({ machine_name: config.machineName, directory: config.dir, branch: config.branch, git_repo_url: config.gitRepoUrl, max_sessions: config.maxSessions, metadata: { worker_type: config.workerType } })}`, |
| 194 | ) |
| 195 | debug(`[bridge:api] <<< ${debugBody(response.data)}`) |
| 196 | return response.data |
| 197 | }, |
| 198 | |
| 199 | async pollForWork( |
nothing calls this directly
no test coverage detected