agentenv-framework-protocol 0.1.533__tar.gz → 0.1.536__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/PKG-INFO +1 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/pyproject.toml +1 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/operations.py +3 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/results.py +2 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/tools.py +2 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/cdp.py +61 -8
- agentenv_framework_protocol-0.1.536/src/agentenv_protocol/website_browser/contexts.py +241 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/control.py +242 -108
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/data.py +21 -7
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/environment.py +150 -50
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/log.py +1 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/recording.py +9 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/shapes.py +37 -5
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_browser_cdp.py +63 -6
- agentenv_framework_protocol-0.1.536/tests/test_browser_contexts.py +387 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_browser_data.py +11 -7
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_browser_recording.py +84 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_browser_state.py +1 -1
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/.gitignore +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/LICENSE +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/NOTICE +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/README.md +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/THIRD_PARTY_NOTICES.md +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/advanced_agent.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/basic_agent.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/custom_extensions_agent.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/multimodal_agent.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/reference_model.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/streaming_agent.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/.gitignore +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/Dockerfile +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/Dockerfile.dockerignore +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/README.md +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/data/seed.json +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/env.toml +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/site.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/web/index.html +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/web/package-lock.json +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/web/package.json +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/web/src/main.js +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/web/src/style.css +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/examples/website/notes/web/vite.config.js +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/_trajectory_log.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/_triggers.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/extensions.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/framework.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/peer_agents.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/proxy.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/registry.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/staging.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/tasks/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/a2a_agent/tasks/v1.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/agent_env_environment.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/client.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_declare.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_desktop.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_job.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_linux.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_load.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_macos.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_reaping.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_session_posix.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_session_windows.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_windows.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_with_fds.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/_x11.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/app.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/app_data.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/app_runtime.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/apps.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/card.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/checks.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/__main__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/checks.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/client.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/desk.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/fixture.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/mp4.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/page_fixture.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/report.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/conformance/wayland_fixture.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/dataplane.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/driver.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/errors.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/extensions.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/frames.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/keys.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/launch.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/manifest.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/platform.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/prefix.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/queue.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/recording.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/run_install_step.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/runtime.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/seed.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/serve.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/serve_app.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/served.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/session.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/settings.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/skill.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/spaces.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/computer/svc.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/errors.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/manifest.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/preflight.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/tool_access.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/tool_client.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/tool_context.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/transfers.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/types.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/clock.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/conformance.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/environment.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/errors.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/readiness.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/routes.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website/session.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/devtools.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/src/agentenv_protocol/website_browser/network.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/computer_fake.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/probe_fake.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_agent.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_agent_examples.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_cdp_config.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_object_transfers.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_peer_agents.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_proxy.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_staging.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_a2a_trajectory_log.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_agent_env_environment.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_browser_log.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_browser_network.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_client.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_app_data.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_app_server.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_conformance.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_conformance_checks.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_conformance_page.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_conformance_recording.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_dataplane.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_declare.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_driver.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_driver_keys.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_extensions.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_frames.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_macos.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_page.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_queue.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_recording.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_seed.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_serve.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_served.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_session_windows.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_spaces.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_svc_forward.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_tool_prefix.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_computer_windows_driver.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_control_token.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_data_objects.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_devtools_pipe.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_errors.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_extension_methods.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_intake.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_manifest.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_preflight.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_tool_access.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_tool_annotations.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_tool_client.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_tool_context.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_tool_context_fastmcp.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_tool_context_injection.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_api.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_browser.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_conformance.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_environment.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_live.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_mcp.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_notes_example.py +0 -0
- {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.536}/tests/test_website_readiness.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: agentenv-framework-protocol
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.536
|
|
4
4
|
Summary: Open data-plane protocol and server SDK for agent environments.
|
|
5
5
|
Project-URL: Homepage, https://www.agentenvframework.com
|
|
6
6
|
Project-URL: Documentation, https://www.agentenvframework.com/docs
|
|
@@ -76,11 +76,13 @@ class Effect:
|
|
|
76
76
|
|
|
77
77
|
@dataclass(frozen=True)
|
|
78
78
|
class Tab:
|
|
79
|
-
"""A tab of a website browser: its id, the browser's own,
|
|
79
|
+
"""A tab of a website browser: its id, the browser's own, its page's URL and title, and the label of the lease
|
|
80
|
+
it's in, None for the browser's default context."""
|
|
80
81
|
id: str
|
|
81
82
|
url: str
|
|
82
83
|
title: str
|
|
83
84
|
active: bool = False
|
|
85
|
+
context: str | None = None
|
|
84
86
|
|
|
85
87
|
|
|
86
88
|
@dataclass(frozen=True)
|
|
@@ -405,7 +405,8 @@ class Tools:
|
|
|
405
405
|
"switch": f"Switched to tab {tab}", "close": f"Closed tab {tab}"}[action]
|
|
406
406
|
|
|
407
407
|
def listed(result: InputResult, tabs: Any) -> TabsResult:
|
|
408
|
-
rows = [TabData(tab=t.id, url=t.url, title=t.title, active=t.active
|
|
408
|
+
rows = [TabData(tab=t.id, url=t.url, title=t.title, active=t.active, context=t.context)
|
|
409
|
+
for t in tabs or []]
|
|
409
410
|
active = next((row for row in rows if row.active), None)
|
|
410
411
|
shown = f', the active one "{active.title}" ({active.url})' if active is not None else ""
|
|
411
412
|
return TabsResult(**{**result.model_dump(), "summary": f"{verb}; {len(rows)} open{shown}"
|
|
@@ -22,6 +22,7 @@ from .log import (ERROR_CHARS, KEY_FIELDS, TYPING_METHODS, BrowserLog, acts, red
|
|
|
22
22
|
redacted_params)
|
|
23
23
|
|
|
24
24
|
if TYPE_CHECKING:
|
|
25
|
+
from .contexts import Contexts
|
|
25
26
|
from .control import BrowserControl
|
|
26
27
|
from .devtools import DevToolsPipe
|
|
27
28
|
|
|
@@ -51,6 +52,8 @@ MALFORMED = {"code": -32600, "message": "a command is an object with a string me
|
|
|
51
52
|
ENDS_BROWSER = frozenset({"Browser.close", "Browser.crash", "Browser.crashGpuProcess"})
|
|
52
53
|
#: The commands that set how and where downloads are saved, which agentenv keeps as its own.
|
|
53
54
|
SETS_DOWNLOADS = frozenset({"Browser.setDownloadBehavior", "Page.setDownloadBehavior"})
|
|
55
|
+
#: The commands that make and end a browser context, which agentenv records as leases.
|
|
56
|
+
MAKES_CONTEXT, ENDS_CONTEXT = "Target.createBrowserContext", "Target.disposeBrowserContext"
|
|
54
57
|
#: The schemes of the browser's own files, settings and tools, which an agent's navigation or new tab may not open.
|
|
55
58
|
OWN_SCHEMES = frozenset({"file", "chrome", "chrome-extension", "chrome-untrusted", "view-source", "devtools"})
|
|
56
59
|
#: The ``about:`` pages that aren't the browser's own under another name.
|
|
@@ -158,10 +161,11 @@ class Verdict:
|
|
|
158
161
|
changed: bool = False
|
|
159
162
|
|
|
160
163
|
|
|
161
|
-
def guard(method: str, params: dict, *, dialogs_answered: bool) -> Verdict:
|
|
164
|
+
def guard(method: str, params: dict, *, dialogs_answered: bool, download_path: Optional[str] = None) -> Verdict:
|
|
162
165
|
"""What the relay does with an agent's ``method``, so it can't end the browser others share, route around the site
|
|
163
|
-
proxy, save downloads elsewhere
|
|
164
|
-
``dialogs_answered``: a guardrail, since the sandbox's network is
|
|
166
|
+
proxy, save downloads elsewhere than its context's folder, ``download_path`` for a lease's, open the browser's own
|
|
167
|
+
pages or race the dialogs agentenv answers when ``dialogs_answered``: a guardrail, since the sandbox's network is
|
|
168
|
+
the boundary."""
|
|
165
169
|
if method in ENDS_BROWSER:
|
|
166
170
|
return Verdict("close", params)
|
|
167
171
|
if method == "Target.exposeDevToolsProtocol":
|
|
@@ -173,8 +177,8 @@ def guard(method: str, params: dict, *, dialogs_answered: bool) -> Verdict:
|
|
|
173
177
|
if method in ("Page.navigate", "Target.createTarget") and (scheme := _own_scheme(params.get("url"))):
|
|
174
178
|
return Verdict("refuse", params, f"{scheme}: URLs open the browser's own files, settings and tools")
|
|
175
179
|
if method in SETS_DOWNLOADS:
|
|
176
|
-
pinned = {"behavior": "default",
|
|
177
|
-
|
|
180
|
+
pinned = {"behavior": "default"} if download_path is None else {"behavior": "allow", "downloadPath": download_path}
|
|
181
|
+
pinned.update({key: params[key] for key in ("browserContextId", "eventsEnabled") if key in params})
|
|
178
182
|
return Verdict("send", pinned, changed=pinned != params)
|
|
179
183
|
if method == "Page.handleJavaScriptDialog" and dialogs_answered:
|
|
180
184
|
return Verdict("answer", params)
|
|
@@ -212,6 +216,9 @@ class _Connection:
|
|
|
212
216
|
self.outbox: asyncio.Queue[str | tuple[int, str]] = asyncio.Queue()
|
|
213
217
|
self.waiting_bytes = 0
|
|
214
218
|
self.closing = False
|
|
219
|
+
#: Whether it set how downloads are saved, and the contexts it made that end as it detaches.
|
|
220
|
+
self.set_downloads = False
|
|
221
|
+
self.ends_on_detach: set[str] = set()
|
|
215
222
|
|
|
216
223
|
|
|
217
224
|
class _Call:
|
|
@@ -242,11 +249,14 @@ class Relay:
|
|
|
242
249
|
browser's dialogs itself. With a ``log``, each command is an entry in it, on the tab its session is on, and
|
|
243
250
|
``control``, agentenv's own connection, tells its tab's URL, whether a password field has focus there, and what
|
|
244
251
|
causes the tab events a command brings. An agent's tool call a driver serves through a CDP user's connections,
|
|
245
|
-
such as Playwright MCP's, is an entry too, which that user's commands are credited to while it's open.
|
|
252
|
+
such as Playwright MCP's, is an entry too, which that user's commands are credited to while it's open. With
|
|
253
|
+
``contexts``, a context a connection makes is leased to its user, only one it made may it dispose, and a lease's
|
|
254
|
+
downloads stay in its folder."""
|
|
246
255
|
|
|
247
256
|
def __init__(self, devtools: DevToolsPipe, *, dialogs_answered: bool = False, log: Optional[BrowserLog] = None,
|
|
248
|
-
control: Optional[BrowserControl] = None) -> None:
|
|
257
|
+
control: Optional[BrowserControl] = None, contexts: Optional[Contexts] = None) -> None:
|
|
249
258
|
self.devtools, self.dialogs_answered, self.log, self.control = devtools, dialogs_answered, log, control
|
|
259
|
+
self.contexts = contexts
|
|
250
260
|
self.connections: list[dict] = []
|
|
251
261
|
self._by_session: dict[str, _Connection] = {}
|
|
252
262
|
self._open: set[_Connection] = set()
|
|
@@ -315,6 +325,7 @@ class Relay:
|
|
|
315
325
|
await asyncio.gather(*connection.commands, sending, return_exceptions=True)
|
|
316
326
|
with contextlib.suppress(Exception):
|
|
317
327
|
await self.devtools.call("Target.detachFromTarget", {"sessionId": session})
|
|
328
|
+
self._detached(connection)
|
|
318
329
|
|
|
319
330
|
def ended(self) -> None:
|
|
320
331
|
"""The browser has gone: every connection is closed with a reason a client may connect again after."""
|
|
@@ -329,7 +340,7 @@ class Relay:
|
|
|
329
340
|
return
|
|
330
341
|
method, params = message["method"], message.get("params") or {}
|
|
331
342
|
session = message.get("sessionId") or connection.session
|
|
332
|
-
verdict =
|
|
343
|
+
verdict = self._verdict(connection, session, method, params)
|
|
333
344
|
logged = self._begin(connection, session, method, params)
|
|
334
345
|
answer, guarded = {"error": {"code": SERVER_ERROR, "message": ENDED_UNANSWERED}}, None
|
|
335
346
|
sending: Optional[asyncio.Future] = None
|
|
@@ -338,6 +349,8 @@ class Relay:
|
|
|
338
349
|
def reply(answer: dict) -> None:
|
|
339
350
|
nonlocal replied
|
|
340
351
|
replied = True
|
|
352
|
+
if sending is not None and isinstance(answer.get("result"), dict):
|
|
353
|
+
self._answered(connection, method, params, answer["result"])
|
|
341
354
|
self._put(connection, _reply(message, answer))
|
|
342
355
|
|
|
343
356
|
try:
|
|
@@ -373,6 +386,46 @@ class Relay:
|
|
|
373
386
|
if logged is not None:
|
|
374
387
|
logged.finish(answer, guarded)
|
|
375
388
|
|
|
389
|
+
def _verdict(self, connection: _Connection, session: str, method: str, params: dict) -> Verdict:
|
|
390
|
+
"""The guard's verdict on ``connection``'s command, with what its contexts say: where a lease's downloads
|
|
391
|
+
go, and that only a context it made may it dispose."""
|
|
392
|
+
if self.contexts is None:
|
|
393
|
+
return guard(method, params, dialogs_answered=self.dialogs_answered)
|
|
394
|
+
if method == ENDS_CONTEXT and (reason := self.contexts.may_dispose(connection.user,
|
|
395
|
+
params.get("browserContextId"))):
|
|
396
|
+
return Verdict("refuse", params, reason)
|
|
397
|
+
download_path = None
|
|
398
|
+
if method in SETS_DOWNLOADS:
|
|
399
|
+
connection.set_downloads = True
|
|
400
|
+
context = params.get("browserContextId") if method.startswith("Browser.") else \
|
|
401
|
+
self._context_of(connection.targets.get(session))
|
|
402
|
+
download_path = self.contexts.download_path(context)
|
|
403
|
+
return guard(method, params, dialogs_answered=self.dialogs_answered, download_path=download_path)
|
|
404
|
+
|
|
405
|
+
def _context_of(self, target: Optional[str]) -> Optional[str]:
|
|
406
|
+
return self.control.tabs.get(target, {}).get("context_id") if self.control is not None and target else None
|
|
407
|
+
|
|
408
|
+
def _answered(self, connection: _Connection, method: str, params: dict, result: dict) -> None:
|
|
409
|
+
"""A context ``connection`` made leased to its user before it hears the answer, and one it disposed ended."""
|
|
410
|
+
if self.contexts is None:
|
|
411
|
+
return
|
|
412
|
+
if method == MAKES_CONTEXT and isinstance(made := result.get("browserContextId"), str):
|
|
413
|
+
self.contexts.made_by_agent(connection.user, made)
|
|
414
|
+
if params.get("disposeOnDetach"):
|
|
415
|
+
connection.ends_on_detach.add(made)
|
|
416
|
+
elif method == ENDS_CONTEXT:
|
|
417
|
+
self.contexts.disposed(params.get("browserContextId"))
|
|
418
|
+
|
|
419
|
+
def _detached(self, connection: _Connection) -> None:
|
|
420
|
+
"""``connection`` gone: the contexts it made to end as it detached ended, and the leases' downloads sent to
|
|
421
|
+
their folders again if it set downloads, which its session's end may set otherwise."""
|
|
422
|
+
if self.contexts is None:
|
|
423
|
+
return
|
|
424
|
+
for context in connection.ends_on_detach:
|
|
425
|
+
self.contexts.disposed(context)
|
|
426
|
+
if connection.set_downloads:
|
|
427
|
+
self.contexts.resend_downloads()
|
|
428
|
+
|
|
376
429
|
def _begin(self, connection: _Connection, session: str, method: str, params: dict) -> Optional[_Logged]:
|
|
377
430
|
"""``connection``'s command, begun in the log, if there is one, on the tab ``session`` is on, or for a browser
|
|
378
431
|
command the tab it names, ``for`` the tool calls of its user's open now; what it causes made known to the
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""The contexts a website browser leases beside its default one: each a browser context with its own cookies, local
|
|
2
|
+
storage, tabs and downloads folder, named by a label, granted to the agents a task or the relay names, and ended by its
|
|
3
|
+
release, a reset or the browser's relaunch, which no context outlives. A context an agent makes over CDP is leased to
|
|
4
|
+
that agent as ``agent-<user>-<n>``; one made unseen, ``agent-unknown-<n>``, to nobody. Grants are recorded, not
|
|
5
|
+
enforced: the CDP addresses agents hold still see every context."""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import contextlib
|
|
10
|
+
import logging
|
|
11
|
+
import re
|
|
12
|
+
import shutil
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import TYPE_CHECKING, Callable, Optional
|
|
16
|
+
|
|
17
|
+
from ..computer.errors import InvalidArgument, TargetUnavailable
|
|
18
|
+
from .control import DOWNLOADS
|
|
19
|
+
from .devtools import DevToolsError
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
from .control import BrowserControl
|
|
23
|
+
from .devtools import DevToolsPipe
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
#: Where each lease's files are under the session user's home, a folder per label.
|
|
28
|
+
CONTEXTS = "Contexts"
|
|
29
|
+
#: Who made a lease: the task, through ``contexts/lease``; else the agent that made it over CDP, by its user, or
|
|
30
|
+
#: ``UNKNOWN`` for one made where the relay didn't see.
|
|
31
|
+
TASK, UNKNOWN = "task", "unknown"
|
|
32
|
+
#: How the labels of contexts agents make start, which a task's labels may not.
|
|
33
|
+
AGENT_PREFIX = "agent-"
|
|
34
|
+
#: The longest label, so ``chromium-<label>`` stays a short name.
|
|
35
|
+
LABEL_CHARS = 40
|
|
36
|
+
_LABEL = re.compile(r"[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def label_problem(label: object, *, by_task: bool = True) -> Optional[str]:
|
|
40
|
+
"""Why ``label`` can't name a lease, or None: lowercase letters, digits and ``-``, not at either end, at most
|
|
41
|
+
``LABEL_CHARS`` of them; a task's may not start ``agent-``, which names the contexts agents make."""
|
|
42
|
+
if not isinstance(label, str) or len(label) > LABEL_CHARS or not _LABEL.fullmatch(label):
|
|
43
|
+
return (f"a context's label is lowercase letters, digits and '-', not at either end, at most {LABEL_CHARS} "
|
|
44
|
+
f"characters, not {label!r}")
|
|
45
|
+
if by_task and label.startswith(AGENT_PREFIX):
|
|
46
|
+
return f"a label starting {AGENT_PREFIX!r} names a context an agent made, so a task's can't: {label!r}"
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class Lease:
|
|
52
|
+
"""A leased context: its ``label``, the browser's ``id`` for it, who made it and the agents it's granted to."""
|
|
53
|
+
|
|
54
|
+
label: str
|
|
55
|
+
id: str
|
|
56
|
+
made_by: str = TASK
|
|
57
|
+
grants: list[str] = field(default_factory=list)
|
|
58
|
+
|
|
59
|
+
def folder(self, home: Path) -> Path:
|
|
60
|
+
return home / CONTEXTS / self.label
|
|
61
|
+
|
|
62
|
+
def under(self) -> str:
|
|
63
|
+
"""Its downloads folder's path under the home."""
|
|
64
|
+
return f"{CONTEXTS}/{self.label}/{DOWNLOADS}"
|
|
65
|
+
|
|
66
|
+
def downloads(self, home: Path) -> Path:
|
|
67
|
+
return home / self.under()
|
|
68
|
+
|
|
69
|
+
def record(self) -> dict:
|
|
70
|
+
return {"context": self.label, "id": self.id, "made_by": self.made_by, "grants": list(self.grants)}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Contexts:
|
|
74
|
+
"""A browser's leases by label, in memory, since a server that restarts relaunches the browser and so ends them
|
|
75
|
+
all, and what leasing, releasing and recording them does over its pipe ``devtools``. ``control`` follows each
|
|
76
|
+
context's tabs, storage and downloads; ``home`` is the session user's home."""
|
|
77
|
+
|
|
78
|
+
def __init__(self, devtools: DevToolsPipe, control: BrowserControl,
|
|
79
|
+
home: Callable[[], Path] = Path.home) -> None:
|
|
80
|
+
self.devtools, self.control, self.home = devtools, control, home
|
|
81
|
+
self.leases: dict[str, Lease] = {}
|
|
82
|
+
self._made: dict[str, int] = {}
|
|
83
|
+
self._tasks: set[asyncio.Future] = set()
|
|
84
|
+
self._lock = asyncio.Lock()
|
|
85
|
+
|
|
86
|
+
def __iter__(self):
|
|
87
|
+
return iter(list(self.leases.values()))
|
|
88
|
+
|
|
89
|
+
def get(self, label: str) -> Optional[Lease]:
|
|
90
|
+
return self.leases.get(label)
|
|
91
|
+
|
|
92
|
+
def of(self, context_id: Optional[str]) -> Optional[Lease]:
|
|
93
|
+
return next((lease for lease in self.leases.values() if lease.id == context_id), None) \
|
|
94
|
+
if context_id else None
|
|
95
|
+
|
|
96
|
+
def id_of(self, label: Optional[str]) -> Optional[str]:
|
|
97
|
+
"""The browser's id for the lease ``label``, None for the default context; TargetUnavailable for a label that
|
|
98
|
+
isn't leased."""
|
|
99
|
+
if label is None:
|
|
100
|
+
return None
|
|
101
|
+
if (lease := self.leases.get(label)) is None:
|
|
102
|
+
raise TargetUnavailable(f"no context {label!r} is leased; contexts/list names the leased ones")
|
|
103
|
+
return lease.id
|
|
104
|
+
|
|
105
|
+
async def lease(self, label: str, *, made_by: str = TASK, grants: tuple[str, ...] = ()) -> Lease:
|
|
106
|
+
"""The lease ``label``: the one leased under it before, as a retried step finds it, else a new context, its
|
|
107
|
+
downloads going to its own folder. A task's label is checked; one ``made_by`` an agent may start ``agent-``,
|
|
108
|
+
as a load of a snapshot restores such leases."""
|
|
109
|
+
async with self._lock:
|
|
110
|
+
if (lease := self.leases.get(label)) is None:
|
|
111
|
+
if problem := label_problem(label, by_task=made_by == TASK):
|
|
112
|
+
raise InvalidArgument(problem)
|
|
113
|
+
context_id = (await self.devtools.call("Target.createBrowserContext", {"disposeOnDetach": False}))[
|
|
114
|
+
"browserContextId"]
|
|
115
|
+
lease = self._record(Lease(label, context_id, made_by))
|
|
116
|
+
await self._send_downloads(lease)
|
|
117
|
+
for user in grants:
|
|
118
|
+
self.grant(label, user)
|
|
119
|
+
return lease
|
|
120
|
+
|
|
121
|
+
def grant(self, label: str, user: str) -> Lease:
|
|
122
|
+
"""The lease ``label`` granted to ``user`` too, recorded; granting a user twice changes nothing."""
|
|
123
|
+
if not isinstance(user, str) or not user:
|
|
124
|
+
raise InvalidArgument("a grant names the agent's user, a non-empty string")
|
|
125
|
+
if (lease := self.leases.get(label)) is None:
|
|
126
|
+
raise TargetUnavailable(f"no context {label!r} is leased; contexts/list names the leased ones")
|
|
127
|
+
if user not in lease.grants:
|
|
128
|
+
lease.grants.append(user)
|
|
129
|
+
return lease
|
|
130
|
+
|
|
131
|
+
async def release(self, label: str) -> bool:
|
|
132
|
+
"""The lease ``label`` ended: its context disposed, which closes its tabs, and its folder deleted. Whether
|
|
133
|
+
there was one: releasing a label that isn't leased does nothing, so a retried step is harmless."""
|
|
134
|
+
async with self._lock:
|
|
135
|
+
if (lease := self.leases.pop(label, None)) is None:
|
|
136
|
+
return False
|
|
137
|
+
self.control.closing_context(lease.id)
|
|
138
|
+
with contextlib.suppress(DevToolsError):
|
|
139
|
+
await self.devtools.call("Target.disposeBrowserContext", {"browserContextId": lease.id})
|
|
140
|
+
await asyncio.to_thread(shutil.rmtree, lease.folder(self.home()), True)
|
|
141
|
+
return True
|
|
142
|
+
|
|
143
|
+
def made_by_agent(self, user: str, context_id: str) -> Lease:
|
|
144
|
+
"""The context ``context_id`` an agent made over CDP as ``user``, leased to it as ``agent-<user>-<n>``,
|
|
145
|
+
starting empty, its downloads sent to its own folder."""
|
|
146
|
+
if (known := self.of(context_id)) is not None:
|
|
147
|
+
return known
|
|
148
|
+
lease = self._record(Lease(self._agent_label(user), context_id, user, [user]))
|
|
149
|
+
self._spawn(self._send_downloads(lease))
|
|
150
|
+
return lease
|
|
151
|
+
|
|
152
|
+
async def find_unseen(self) -> list[Lease]:
|
|
153
|
+
"""Each context the browser has that no lease names, made where the relay didn't see, leased to nobody as
|
|
154
|
+
``agent-unknown-<n>``; the leases it made."""
|
|
155
|
+
try:
|
|
156
|
+
ids = (await self.devtools.call("Target.getBrowserContexts"))["browserContextIds"]
|
|
157
|
+
except (ConnectionError, DevToolsError, KeyError):
|
|
158
|
+
return []
|
|
159
|
+
found = []
|
|
160
|
+
for context_id in ids:
|
|
161
|
+
if self.of(context_id) is None:
|
|
162
|
+
found.append(self._record(Lease(self._agent_label(UNKNOWN), context_id, UNKNOWN)))
|
|
163
|
+
await self._send_downloads(found[-1])
|
|
164
|
+
return found
|
|
165
|
+
|
|
166
|
+
def may_dispose(self, user: str, context_id: Optional[str]) -> Optional[str]:
|
|
167
|
+
"""Why an agent ``user`` may not dispose the context ``context_id``, or None: only a context it made ends
|
|
168
|
+
that way; a task's lease ends by its release, and another agent's isn't its to end."""
|
|
169
|
+
lease = self.of(context_id)
|
|
170
|
+
if lease is None or lease.made_by == user:
|
|
171
|
+
return None
|
|
172
|
+
return (f"the context {lease.label!r} is the task's, which ends by its release" if lease.made_by == TASK else
|
|
173
|
+
f"the context {lease.label!r} is another agent's")
|
|
174
|
+
|
|
175
|
+
def disposed(self, context_id: Optional[str]) -> None:
|
|
176
|
+
"""The context ``context_id`` an agent disposed: its lease ended and its folder moved aside at once, then
|
|
177
|
+
deleted, so a lease of its label after has a folder of its own."""
|
|
178
|
+
if (lease := self.of(context_id)) is not None:
|
|
179
|
+
self.leases.pop(lease.label, None)
|
|
180
|
+
folder, gone = lease.folder(self.home()), self.home() / CONTEXTS / f".gone-{lease.id}"
|
|
181
|
+
with contextlib.suppress(OSError):
|
|
182
|
+
folder.rename(gone)
|
|
183
|
+
self._spawn(asyncio.to_thread(shutil.rmtree, gone, True))
|
|
184
|
+
|
|
185
|
+
def download_path(self, context_id: Optional[str]) -> Optional[str]:
|
|
186
|
+
"""Where the lease of the context ``context_id`` saves downloads, None for the default context or one that
|
|
187
|
+
isn't leased."""
|
|
188
|
+
lease = self.of(context_id)
|
|
189
|
+
return str(lease.downloads(self.home())) if lease is not None else None
|
|
190
|
+
|
|
191
|
+
def holding(self, path: str) -> Optional[str]:
|
|
192
|
+
"""The browser's id for the lease whose downloads folder holds ``path``, None for any other path."""
|
|
193
|
+
home = self.home()
|
|
194
|
+
return next((lease.id for lease in self.leases.values() if Path(path).is_relative_to(lease.downloads(home))),
|
|
195
|
+
None)
|
|
196
|
+
|
|
197
|
+
def resend_downloads(self) -> None:
|
|
198
|
+
"""Each lease's downloads sent to its own folder again, as an agent's session that set them may leave them
|
|
199
|
+
set otherwise as it ends."""
|
|
200
|
+
for lease in self:
|
|
201
|
+
self._spawn(self._send_downloads(lease))
|
|
202
|
+
|
|
203
|
+
def ended(self) -> None:
|
|
204
|
+
"""The browser has gone, and every context with it: no lease is left, and their folders are deleted."""
|
|
205
|
+
self.leases.clear()
|
|
206
|
+
self._made.clear()
|
|
207
|
+
shutil.rmtree(self.home() / CONTEXTS, ignore_errors=True)
|
|
208
|
+
|
|
209
|
+
def _record(self, lease: Lease) -> Lease:
|
|
210
|
+
self.leases[lease.label] = lease
|
|
211
|
+
self.control.other_contexts[lease.id] = lease.label
|
|
212
|
+
lease.downloads(self.home()).mkdir(parents=True, exist_ok=True)
|
|
213
|
+
return lease
|
|
214
|
+
|
|
215
|
+
def _agent_label(self, user: str) -> str:
|
|
216
|
+
"""The label of the next context ``user`` makes: ``agent-<user>-<n>``, its user lowercased, each run of
|
|
217
|
+
other characters a ``-``, and cut to fit."""
|
|
218
|
+
name = re.sub(r"[^a-z0-9]+", "-", user.lower()).strip("-") or UNKNOWN
|
|
219
|
+
while True:
|
|
220
|
+
self._made[name] = self._made.get(name, 0) + 1
|
|
221
|
+
tail = f"-{self._made[name]}"
|
|
222
|
+
label = f"{AGENT_PREFIX}{name[:LABEL_CHARS - len(AGENT_PREFIX) - len(tail)].rstrip('-')}{tail}"
|
|
223
|
+
if label not in self.leases:
|
|
224
|
+
return label
|
|
225
|
+
|
|
226
|
+
async def _send_downloads(self, lease: Lease) -> None:
|
|
227
|
+
"""The lease's downloads sent to its own folder, which reports them on agentenv's connection."""
|
|
228
|
+
with contextlib.suppress(ConnectionError, DevToolsError):
|
|
229
|
+
await self.devtools.call("Browser.setDownloadBehavior", {
|
|
230
|
+
"behavior": "allow", "browserContextId": lease.id, "downloadPath": str(lease.downloads(self.home())),
|
|
231
|
+
"eventsEnabled": True})
|
|
232
|
+
|
|
233
|
+
def _spawn(self, work) -> None:
|
|
234
|
+
task = asyncio.ensure_future(work)
|
|
235
|
+
self._tasks.add(task)
|
|
236
|
+
task.add_done_callback(self._finished)
|
|
237
|
+
|
|
238
|
+
def _finished(self, task: asyncio.Future) -> None:
|
|
239
|
+
self._tasks.discard(task)
|
|
240
|
+
if not task.cancelled() and (error := task.exception()) is not None:
|
|
241
|
+
logger.warning(f"the browser's contexts: {type(error).__name__}: {error}")
|