Skip to content

feat: add browser-scoped session client#93

Open
rgarcia wants to merge 9 commits intonextfrom
raf/browser-scoped-client
Open

feat: add browser-scoped session client#93
rgarcia wants to merge 9 commits intonextfrom
raf/browser-scoped-client

Conversation

@rgarcia
Copy link
Copy Markdown
Contributor

@rgarcia rgarcia commented Apr 13, 2026

Summary

  • add kernel.for_browser(...) and async_kernel.for_browser(...) to create browser-scoped clients from browser session responses
  • route browser subresource methods through the session base_url so callers stop repeating the browser id
  • expose raw HTTP through browser.request(...) and browser.stream(...) while keeping the internal /curl/raw transport path hidden
  • add focused tests for metro routing, JWT extraction, and browser-scoped raw HTTP behavior

Test plan

  • uv run python -m pytest tests/test_browser_scoped.py -o addopts= -q

Made with Cursor


Note

Medium Risk
Introduces a new client path that rewrites request URLs and injects JWT/session IDs for browser-session HTTP, so mistakes could misroute requests or leak/override auth/query parameters. Most changes are additive but touch request construction and transport reuse for both sync and async clients.

Overview
Adds Kernel.for_browser(...) / AsyncKernel.for_browser(...) to create a browser-session-scoped client that automatically injects the session id into browser subresource calls and routes those calls via the session’s base_url.

The new BrowserScopedClient/AsyncBrowserScopedClient also exposes request() and stream() helpers that proxy arbitrary HTTP through the session’s internal /curl/raw endpoint, while preventing caller-supplied query params from overriding reserved url/jwt values.

Includes an AST-based generator (scripts/generate_browser_scoped.py) that produces committed generated_bindings.py wrappers over resources.browsers.*, updates scripts/lint to regenerate/verify the file, tweaks base_url field docs in browser response types, and adds focused tests covering routing, JWT extraction, and param sanitization.

Reviewed by Cursor Bugbot for commit a80716b. Bugbot is set up for automated code reviews on this repo. Configure here.

@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR adds browser-scoped session client functionality but does not appear to modify API endpoints (packages/api/cmd/api/) or Temporal workflows (packages/api/lib/temporal) as specified in the filter.

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread src/kernel/lib/browser_scoped/client.py Outdated
Comment thread src/kernel/lib/browser_scoped/client.py Outdated
rgarcia added 9 commits April 21, 2026 13:09
Bind browser subresource calls to a browser session's base_url and expose raw HTTP through request and stream helpers so metro-routed access feels like normal httpx usage.

Made-with: Cursor
Prevent browser-scoped raw HTTP helpers from letting user params override internal routing query keys, and clean up wording around browser session base_url routing.

Made-with: Cursor
Keep the browser-scoped request helpers aligned with repo linting and reserve internal raw-request query keys without exposing implementation details.

Made-with: Cursor
Keep the browser-scoped test file aligned with the repo lint configuration so the follow-up typing fixes pass CI.

Made-with: Cursor
Tighten browser-scoped helper typing and test casts so the Python SDK passes the repository's lint and pyright checks cleanly.

Made-with: Cursor
Replace the handwritten Python browser-scoped façade with deterministic generated bindings from the browser resource graph, and enforce regeneration during lint.

Made-with: Cursor
Keep the browser-scoped Python generator compatible with the repo lint pipeline by suppressing strict pyright diagnostics that are not meaningful for the AST-walking build script.

Made-with: Cursor
Keep the Python generator and generated browser-scoped façade aligned with pyright and mypy so the deterministic regeneration path passes the repo lint pipeline.

Made-with: Cursor
Sort the generator script imports and keep the deterministic browser-scoped generation path aligned with the repo lint pipeline.

Made-with: Cursor
@rgarcia rgarcia force-pushed the raf/browser-scoped-client branch from 8f1d506 to a80716b Compare April 21, 2026 17:09
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.

Reviewed by Cursor Bugbot for commit a80716b. Configure here.

headers=_normalize_headers(headers),
content=_normalize_binary_content(content),
json_data=json,
timeout=_normalize_timeout(timeout),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout normalization loses default timeout fallback

Medium Severity

_normalize_timeout converts NotGiven to None before passing to FinalRequestOptions.construct(timeout=...). The kernel's _build_request falls back to self.timeout only when isinstance(options.timeout, NotGiven) — but since None is not NotGiven, the fallback is bypassed. This means calls to b.request(...) without an explicit timeout get timeout=None (no timeout / wait forever) instead of using the kernel's configured default. The stream method handles this correctly by resolving NotGiven against self._http.timeout before normalizing.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a80716b. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant