[feat]: add HTTP transport to TS SDK

Merged
SE
2d ago
+1103-6

why

the protocol now lets the worker ask an SDK to make an HTTP request. the TS SDK needs an implementation that can receive that request, send it over HTTP, & return the response while the original Stagehand call is still waiting

this PR adds that transport using native fetch & the existing RPC connection

what changed

  • added a connection snapshot that resolves the bb key, session, & API endpoint using existing browser-factory precedence, regions, & URL overrides
  • added an executor for Gateway, cache read, & cache write requests. it adds the bb headers, sends the supplied body, & returns the complete response.
  • kept each execution to one HTTP attempt. HTTP errors & redirects are returned to the worker; retry decisions remain with the worker.
  • carried cancellation & the remaining timeout through response body buffering.
  • added RPC handler registration & disposal. cancellation targets one request, disconnects stop pending work, & disposal removes handlers without closing the shared RPC connection.

test plan

  • shared fixtures verify endpoint selection, connection precedence, & headers.
  • local HTTP tests cover request bodies, compressed & empty responses, redirects, HTTP/network failures, cancellation, & timeouts during body delivery.
  • RPC tests verify a reverse request completes while a Stagehand call is pending, equal request IDs on separate connections stay independent, & cleanup stops active HTTP work.

Summary by cubic

Adds an HTTP transport to the TS SDK so the worker can ask the SDK to make Browserbase Gateway and cache requests while the original Stagehand call is still pending.

  • Resolves the Browserbase connection from existing browser-factory precedence, region, and API URL overrides, and snapshots it per connection.
  • Executes gateway.responses, cache.get, and cache.set over native fetch, adds the Browserbase headers, and returns the response without retrying.
  • Carries cancellation and the remaining timeout through body buffering; the worker owns retry decisions.
  • Registers RPC request and cancel-notification handlers and aborts active HTTP on disposal without closing the shared RPC connection.