Add HTTP server API and run resumption support#1
Open
htyredc wants to merge 6 commits into
Open
Conversation
Wraps the CLI exploration loop in a FastAPI service (webwright-server, [server] extra) so a web UI can start runs, stream step-by-step code and progress over SSE, continue a run with follow-ups (reusing the same local_cdp browser tab), and re-execute the generated artifact with different parameters. - src/webwright/server/: app (routes), run_manager (single-active- operation lock, subprocess-per-run, SIGINT cancellation, restart reconciliation from server_meta.json), worker (run_one adapter), replay_worker (parameterized re-execution: final_function.py via the LocalBrowserEnvironment primitive against the original tab, step replay fallback, final_script.py subprocess mode), artifacts (read-only run-directory readers), sse, schemas, config_presets, doctor_api. - src/webwright/config/crafted_browser_fn.yaml: prompt-only modifier porting crafted_cli.yaml's reusable-parameterized-function contract to the headed local_browser mode; the deliverable is final_function.py with PARAMS_SPEC + async run(page, context, browser, params). - No changes to the core agent/environment code: progress is read from the artifacts the loop already writes every step, and runs execute in child processes to satisfy run_async()'s no-nested-event-loop guard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE
The doctor/health key check now passes when either provider key is set, matching the model_openai.yaml / model_claude.yaml config options. check_openai_key remains as an alias for backwards compatibility. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a complete HTTP server API for managing Webwright exploration runs and introduces support for resuming prior runs with follow-up instructions. The server exposes run lifecycle management, execution of parameterized functions, and live progress streaming over Server-Sent Events.
Key Changes
Server API (
src/webwright/server/)app.py: FastAPI application exposing HTTP endpoints for run management, follow-ups, script execution, and health checksrun_manager.py: Single-active-operation manager ensuring only one run/follow-up/execution can be live at a time; handles process lifecycle, reconciliation after server crashes, and re-attachment to orphaned workersworker.py: Subprocess entrypoint for exploration runs and follow-ups; runs outside asyncio event loop to avoid nested-loop conflictsreplay_worker.py: Subprocess entrypoint for executing parameterized functions or replaying recorded steps against a live browser sessionartifacts.py: Read-only helpers for accessing per-run artifact directories (trajectory.json, debug steps, final_function.py, etc.)schemas.py: Pydantic models for HTTP request/response validationsse.py: Server-Sent Events stream for live run progress by polling filesystem artifactsconfig_presets.py: Built-in YAML config preset enumeration and server defaultsdoctor_api.py: JSON adapter over environment health checksRun Resumption
src/webwright/utils/trajectory.py: Utilities to load trajectory.json, extract resume state, and resolve trajectory pathssrc/webwright/run/cli.py: Extendedrun_one()to acceptresume_fromandfollowupparameters; integrates resume state into agent initializationsrc/webwright/agents/default.py: Addedresume()method to agents for continuing from prior state; drops exit messages and appends follow-up instructionsEnvironment Updates
src/webwright/environments/local_browser.py: Added target-finding helpers (_find_cdp_target_by_id,_find_cdp_target_by_url,_find_new_cdp_target) and resume configuration options (resume_existing_output,resume_existing_page)src/webwright/environments/local_workspace.py: Addedresume_existing_outputconfig optionConfiguration
src/webwright/config/crafted_browser_fn.yaml: New config preset for authoring reusable parameterized browser functions (mirrors crafted_cli.yaml for live browser context)src/webwright/config/model_claude.yaml: Updated model endpoint configurationTesting
tests/unit/test_server_run_manager.py: Tests for run manager state, operation queueing, and process lifecycletests/unit/test_server_app.py: Tests for HTTP API endpoints and run CRUD operationstests/unit/test_server_artifacts.py: Tests for artifact parsing (params spec extraction, trajectory info)tests/unit/test_resume_flow.py: Tests for trajectory loading, resume state building, and agent resumptiontests/unit/test_model_json_parsing.py: Tests for JSON output parsing with various formatting stylesDocumentation & Dependencies
README.md: Updated installation and usage instructions to useuvpackage manager; added resume workflow examplespyproject.toml: Added[server]optional dependency group (fastapi, uvicorn); added dev dependencies for testingsrc/webwright/run/doctor.py: Generalized API key check to support multiple model backends (OpenAI, Anthropic, OpenRouter)Notable Implementation Details
https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE