[feat]: support client routing for worker gateway & cache requests

Merged
SE
2d ago
+2076-263

why

this PR connects the worker's model gateway & cache clients to the new RPC transport. aisdk continues to build gateway requests, interpret responses, & decide when to retry

what changed

  • added a worker adapter that sends browserbase.request & reconstructs a native Response or the corresponding transport error for existing callers
  • added cancellable RPC sends using the existing request ID, including cleanup on abort, disconnect, & late replies
  • routed Gateway requests through the adapter when initialization selects client transport. automatic model selection, explicit headers, & AI SDK retry behavior remain in the worker
  • routed cache reads & writes through the same adapter. each cache request keeps one five-second budget across serialization, RPC, & HTTP response buffering
  • preserved direct-provider inference, custom LLM callbacks, batch overrides, & cache failure fallback

test plan

  • response-adapter tests cover HTTP status & headers, empty bodies, transport errors, cancellation ordering, disconnects, & late replies.
  • Gateway tests exercise both transports against the same header, response, retry, & backoff expectations.
  • cache tests cover hits, misses, read/write failures, & the shared timeout budget without adding retries
  • runtime tests cover ordinary & batch calls, custom callbacks, model overrides, close/drain behavior, & disconnects during inference

Summary by cubic

Connects the worker's Browserbase Model Gateway and cache clients to the new RPC transport, so inference and cache HTTP requests are sent by the connected SDK instead of direct HTTP from the worker.

  • Adds a worker adapter that sends browserbase.request over RPC and reconstructs a native Response or the matching transport error for existing callers.
  • Makes RPC sends cancellable via the existing request ID, with cleanup on abort, disconnect, and late replies.
  • Routes Gateway requests through the adapter when initialization selects client transport; AI SDK retry and backoff behavior, explicit headers, and automatic model selection stay in the worker.
  • Routes cache reads and writes through the same adapter, keeping one shared five-second budget per request across serialization, RPC, and response buffering.
  • Preserves direct-provider inference, custom LLM callbacks, batch overrides, and cache failure fallback.
  • Rebuilds the extension assets bundle, removes duplicated gateway tests, and updates the client/server version compatibility tests.