* Push a freshly-minted PTY cookie token to the terminal-agent so its * /ws upgrade can validate the cookie. v1.44+: also pushes the bound * sessionId so the agent can route /internal/restart and (Commit 3) * re-attach back to the same PtySession. Loopback POST authenticated * with the internal
(token: string, sessionId?: string)
| 426 | * isn't up yet, the extension just retries /pty-session. |
| 427 | */ |
| 428 | async function grantPtyToken(token: string, sessionId?: string): Promise<boolean> { |
| 429 | const port = readTerminalPort(); |
| 430 | const internal = readTerminalInternalToken(); |
| 431 | if (!port || !internal) return false; |
| 432 | try { |
| 433 | const resp = await fetch(`http://127.0.0.1:${port}/internal/grant`, { |
| 434 | method: 'POST', |
| 435 | headers: { |
| 436 | 'Content-Type': 'application/json', |
| 437 | 'Authorization': `Bearer ${internal}`, |
| 438 | }, |
| 439 | body: JSON.stringify(sessionId ? { token, sessionId } : { token }), |
| 440 | signal: AbortSignal.timeout(2000), |
| 441 | }); |
| 442 | return resp.ok; |
| 443 | } catch { return false; } |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Ask the terminal-agent to dispose the PtySession bound to `sessionId`. |
no test coverage detected