(input: {
readonly manifest: ExecutorLocalServerManifest;
readonly elicitationMode: "browser" | "model";
readonly artifacts: boolean;
})
| 1384 | * when stdin closes or the daemon connection drops; close is best-effort. |
| 1385 | */ |
| 1386 | const runMcpHttpBridge = async (input: { |
| 1387 | readonly manifest: ExecutorLocalServerManifest; |
| 1388 | readonly elicitationMode: "browser" | "model"; |
| 1389 | readonly artifacts: boolean; |
| 1390 | }): Promise<void> => { |
| 1391 | const stdio = new StdioServerTransport(); |
| 1392 | const authorization = getExecutorServerAuthorizationHeader(input.manifest.connection); |
| 1393 | const http = new StreamableHTTPClientTransport( |
| 1394 | mcpUrlForActiveLocalServer({ |
| 1395 | connection: input.manifest.connection, |
| 1396 | elicitationMode: input.elicitationMode, |
| 1397 | artifacts: input.artifacts, |
| 1398 | }), |
| 1399 | authorization ? { requestInit: { headers: { Authorization: authorization } } } : undefined, |
| 1400 | ); |
| 1401 | |
| 1402 | let finished = false; |
| 1403 | let closing = false; |
| 1404 | let closePromise: Promise<void> | null = null; |
| 1405 | let resolveExit: () => void = () => {}; |
| 1406 | const waitForExit = new Promise<void>((resolve) => { |
| 1407 | resolveExit = resolve; |
| 1408 | }); |
| 1409 | |
| 1410 | const finish = () => { |
| 1411 | if (finished) return; |
| 1412 | finished = true; |
| 1413 | process.off("SIGINT", shutdown); |
| 1414 | process.off("SIGTERM", shutdown); |
| 1415 | process.stdin.off("end", shutdown); |
| 1416 | process.stdin.off("close", shutdown); |
| 1417 | resolveExit(); |
| 1418 | }; |
| 1419 | |
| 1420 | const closeBoth = (): Promise<void> => { |
| 1421 | if (!closePromise) { |
| 1422 | closing = true; |
| 1423 | closePromise = Promise.allSettled([stdio.close(), http.close()]).then(() => undefined); |
| 1424 | } |
| 1425 | return closePromise; |
| 1426 | }; |
| 1427 | |
| 1428 | function shutdown() { |
| 1429 | finish(); |
| 1430 | void closeBoth(); |
| 1431 | } |
| 1432 | |
| 1433 | const isAbortDuringClose = (error: Error): boolean => |
| 1434 | error.name === "AbortError" || error.message.toLowerCase().includes("aborted"); |
| 1435 | |
| 1436 | const reportError = (context: string, cause: unknown) => { |
| 1437 | const error = toError(cause); |
| 1438 | if (closing && isAbortDuringClose(error)) return; |
| 1439 | console.error(`Executor MCP bridge ${context}: ${error.message}`); |
| 1440 | }; |
| 1441 | |
| 1442 | const forwardMessage = |
| 1443 | (send: (message: JSONRPCMessage) => Promise<void>, context: string) => |
no test coverage detected