agentenv-framework-protocol 0.1.540__tar.gz → 0.1.542__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.
Files changed (191) hide show
  1. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/PKG-INFO +1 -1
  2. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/pyproject.toml +1 -1
  3. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/svc.py +10 -3
  4. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/cdp.py +124 -32
  5. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/contexts.py +13 -0
  6. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/control.py +12 -0
  7. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/environment.py +33 -6
  8. agentenv_framework_protocol-0.1.542/src/agentenv_protocol/website_browser/scope.py +155 -0
  9. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_cdp.py +261 -4
  10. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_contexts.py +48 -1
  11. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_svc_forward.py +5 -5
  12. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/.gitignore +0 -0
  13. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/LICENSE +0 -0
  14. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/NOTICE +0 -0
  15. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/README.md +0 -0
  16. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/THIRD_PARTY_NOTICES.md +0 -0
  17. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/__init__.py +0 -0
  18. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/advanced_agent.py +0 -0
  19. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/basic_agent.py +0 -0
  20. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/custom_extensions_agent.py +0 -0
  21. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/multimodal_agent.py +0 -0
  22. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/reference_model.py +0 -0
  23. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/streaming_agent.py +0 -0
  24. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/.gitignore +0 -0
  25. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/Dockerfile +0 -0
  26. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/Dockerfile.dockerignore +0 -0
  27. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/README.md +0 -0
  28. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/data/seed.json +0 -0
  29. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/env.toml +0 -0
  30. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/site.py +0 -0
  31. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/web/index.html +0 -0
  32. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/web/package-lock.json +0 -0
  33. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/web/package.json +0 -0
  34. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/web/src/main.js +0 -0
  35. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/web/src/style.css +0 -0
  36. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/examples/website/notes/web/vite.config.js +0 -0
  37. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/__init__.py +0 -0
  38. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/__init__.py +0 -0
  39. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/_trajectory_log.py +0 -0
  40. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/_triggers.py +0 -0
  41. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/extensions.py +0 -0
  42. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/framework.py +0 -0
  43. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/peer_agents.py +0 -0
  44. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/proxy.py +0 -0
  45. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/registry.py +0 -0
  46. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/staging.py +0 -0
  47. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/tasks/__init__.py +0 -0
  48. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/a2a_agent/tasks/v1.py +0 -0
  49. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/agent_env_environment.py +0 -0
  50. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/client.py +0 -0
  51. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/__init__.py +0 -0
  52. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_declare.py +0 -0
  53. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_desktop.py +0 -0
  54. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_job.py +0 -0
  55. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_linux.py +0 -0
  56. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_load.py +0 -0
  57. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_macos.py +0 -0
  58. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_reaping.py +0 -0
  59. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_session_posix.py +0 -0
  60. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_session_windows.py +0 -0
  61. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_windows.py +0 -0
  62. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_with_fds.py +0 -0
  63. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/_x11.py +0 -0
  64. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/app.py +0 -0
  65. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/app_data.py +0 -0
  66. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/app_runtime.py +0 -0
  67. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/apps.py +0 -0
  68. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/card.py +0 -0
  69. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/checks.py +0 -0
  70. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/clock.py +0 -0
  71. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/__init__.py +0 -0
  72. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/__main__.py +0 -0
  73. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/checks.py +0 -0
  74. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/client.py +0 -0
  75. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/desk.py +0 -0
  76. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/fixture.py +0 -0
  77. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/mp4.py +0 -0
  78. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/page_fixture.py +0 -0
  79. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/report.py +0 -0
  80. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/conformance/wayland_fixture.py +0 -0
  81. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/dataplane.py +0 -0
  82. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/driver.py +0 -0
  83. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/errors.py +0 -0
  84. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/extensions.py +0 -0
  85. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/frames.py +0 -0
  86. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/keys.py +0 -0
  87. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/launch.py +0 -0
  88. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/manifest.py +0 -0
  89. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/operations.py +0 -0
  90. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/platform.py +0 -0
  91. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/prefix.py +0 -0
  92. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/queue.py +0 -0
  93. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/recording.py +0 -0
  94. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/results.py +0 -0
  95. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/run_install_step.py +0 -0
  96. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/runtime.py +0 -0
  97. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/seed.py +0 -0
  98. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/serve.py +0 -0
  99. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/serve_app.py +0 -0
  100. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/served.py +0 -0
  101. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/session.py +0 -0
  102. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/settings.py +0 -0
  103. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/skill.py +0 -0
  104. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/spaces.py +0 -0
  105. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/computer/tools.py +0 -0
  106. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/errors.py +0 -0
  107. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/manifest.py +0 -0
  108. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/preflight.py +0 -0
  109. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/tool_access.py +0 -0
  110. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/tool_client.py +0 -0
  111. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/tool_context.py +0 -0
  112. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/transfers.py +0 -0
  113. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/types.py +0 -0
  114. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/__init__.py +0 -0
  115. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/clock.py +0 -0
  116. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/conformance.py +0 -0
  117. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/environment.py +0 -0
  118. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/errors.py +0 -0
  119. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/readiness.py +0 -0
  120. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/routes.py +0 -0
  121. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website/session.py +0 -0
  122. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/__init__.py +0 -0
  123. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/data.py +0 -0
  124. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/devtools.py +0 -0
  125. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/log.py +0 -0
  126. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/network.py +0 -0
  127. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/recording.py +0 -0
  128. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/src/agentenv_protocol/website_browser/shapes.py +0 -0
  129. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/computer_fake.py +0 -0
  130. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/probe_fake.py +0 -0
  131. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_agent.py +0 -0
  132. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_agent_examples.py +0 -0
  133. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_cdp_config.py +0 -0
  134. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_object_transfers.py +0 -0
  135. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_peer_agents.py +0 -0
  136. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_proxy.py +0 -0
  137. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_staging.py +0 -0
  138. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_a2a_trajectory_log.py +0 -0
  139. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_agent_env_environment.py +0 -0
  140. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_data.py +0 -0
  141. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_log.py +0 -0
  142. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_network.py +0 -0
  143. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_recording.py +0 -0
  144. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_browser_state.py +0 -0
  145. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_client.py +0 -0
  146. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_app_data.py +0 -0
  147. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_app_server.py +0 -0
  148. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_clock.py +0 -0
  149. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_conformance.py +0 -0
  150. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_conformance_checks.py +0 -0
  151. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_conformance_page.py +0 -0
  152. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_conformance_recording.py +0 -0
  153. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_dataplane.py +0 -0
  154. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_declare.py +0 -0
  155. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_driver.py +0 -0
  156. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_driver_keys.py +0 -0
  157. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_extensions.py +0 -0
  158. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_frames.py +0 -0
  159. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_macos.py +0 -0
  160. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_page.py +0 -0
  161. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_queue.py +0 -0
  162. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_recording.py +0 -0
  163. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_seed.py +0 -0
  164. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_serve.py +0 -0
  165. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_served.py +0 -0
  166. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_session_windows.py +0 -0
  167. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_spaces.py +0 -0
  168. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_tool_prefix.py +0 -0
  169. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_computer_windows_driver.py +0 -0
  170. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_control_token.py +0 -0
  171. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_data_objects.py +0 -0
  172. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_devtools_pipe.py +0 -0
  173. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_errors.py +0 -0
  174. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_extension_methods.py +0 -0
  175. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_intake.py +0 -0
  176. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_manifest.py +0 -0
  177. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_preflight.py +0 -0
  178. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_tool_access.py +0 -0
  179. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_tool_annotations.py +0 -0
  180. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_tool_client.py +0 -0
  181. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_tool_context.py +0 -0
  182. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_tool_context_fastmcp.py +0 -0
  183. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_tool_context_injection.py +0 -0
  184. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_api.py +0 -0
  185. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_browser.py +0 -0
  186. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_conformance.py +0 -0
  187. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_environment.py +0 -0
  188. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_live.py +0 -0
  189. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_mcp.py +0 -0
  190. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/tests/test_website_notes_example.py +0 -0
  191. {agentenv_framework_protocol-0.1.540 → agentenv_framework_protocol-0.1.542}/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.540
3
+ Version: 0.1.542
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "agentenv-framework-protocol"
3
- version = "0.1.540"
3
+ version = "0.1.542"
4
4
  description = "Open data-plane protocol and server SDK for agent environments."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -188,13 +188,17 @@ def _utf8(value: str) -> str:
188
188
 
189
189
 
190
190
  async def _both_ways(client: WebSocket, app: ClientConnection) -> None:
191
- """Each message from either side sent to the other until one side closes, then the other closed with its code."""
191
+ """Each message from either side sent to the other until one side closes, then the other closed with its code and
192
+ reason."""
192
193
  async def inbound() -> None:
193
194
  while True:
194
195
  message = await client.receive()
195
196
  if message["type"] == "websocket.disconnect":
196
197
  code = message.get("code") or 1000
197
- await app.close(1000 if code in UNSENDABLE_CLOSES else code)
198
+ if code in UNSENDABLE_CLOSES:
199
+ await app.close(1000)
200
+ else:
201
+ await app.close(code, message.get("reason") or "")
198
202
  return
199
203
  await app.send(message["text"] if message.get("text") is not None else message["bytes"])
200
204
 
@@ -207,7 +211,10 @@ async def _both_ways(client: WebSocket, app: ClientConnection) -> None:
207
211
  await client.send_bytes(message)
208
212
  code = app.close_code or 1000
209
213
  with contextlib.suppress(RuntimeError, WebSocketDisconnect):
210
- await client.close(1000 if code in UNSENDABLE_CLOSES else code)
214
+ if code in UNSENDABLE_CLOSES:
215
+ await client.close(1000)
216
+ else:
217
+ await client.close(code, app.close_reason or "")
211
218
 
212
219
  tasks = [asyncio.ensure_future(inbound()), asyncio.ensure_future(outbound())]
213
220
  try:
@@ -18,8 +18,10 @@ from typing import TYPE_CHECKING, Any, Literal, Optional
18
18
  from starlette.requests import Request
19
19
  from starlette.websockets import WebSocket, WebSocketDisconnect
20
20
 
21
+ from .devtools import DevToolsError
21
22
  from .log import (ERROR_CHARS, KEY_FIELDS, TYPING_METHODS, BrowserLog, acts, redact_text, redacted_args,
22
23
  redacted_params)
24
+ from .scope import ENDS_CONTEXT, MAKES_CONTEXT, WITH_INFO, Scope, Targets
23
25
 
24
26
  if TYPE_CHECKING:
25
27
  from .contexts import Contexts
@@ -34,6 +36,8 @@ TOKEN_BYTES = 32
34
36
  ROUTE = "/cdp/"
35
37
  #: The close code and reason a connection gets when its browser goes away, which a client may connect again after.
36
38
  RELAUNCHED = (1012, "the browser relaunched: connect again")
39
+ #: The close code and reason a connection scoped to a lease gets when the lease ends, which its address ends with.
40
+ LEASE_ENDED = (1001, "the lease ended: ask for an address again")
37
41
  #: The close code and reason a connection gets when its client falls behind by more than ``OUTBOX_LIMIT_BYTES``.
38
42
  TOO_SLOW = (1013, "the client fell too far behind: connect again")
39
43
  #: How much a connection's client may have waiting to be sent to it before it is closed; a single answer bigger than
@@ -52,8 +56,6 @@ MALFORMED = {"code": -32600, "message": "a command is an object with a string me
52
56
  ENDS_BROWSER = frozenset({"Browser.close", "Browser.crash", "Browser.crashGpuProcess"})
53
57
  #: The commands that set how and where downloads are saved, which agentenv keeps as its own.
54
58
  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"
57
59
  #: The schemes of the browser's own files, settings and tools, which an agent's navigation or new tab may not open.
58
60
  OWN_SCHEMES = frozenset({"file", "chrome", "chrome-extension", "chrome-untrusted", "view-source", "devtools"})
59
61
  #: The ``about:`` pages that aren't the browser's own under another name.
@@ -77,6 +79,8 @@ class Address:
77
79
  http_url: str
78
80
  ws_url: str
79
81
  named: bool = False
82
+ #: The label of the lease it's scoped to, None for the browser's default context.
83
+ context: Optional[str] = None
80
84
 
81
85
 
82
86
  def reached(request: Request) -> str:
@@ -102,19 +106,22 @@ def _hash(token: str) -> str:
102
106
  return hashlib.sha256(token.encode()).hexdigest()
103
107
 
104
108
 
105
- def _address(user: str, base: str, named: bool, token: str) -> Address:
109
+ def _address(user: str, base: str, named: bool, token: str, context: Optional[str] = None) -> Address:
106
110
  root = f"{base}{ROUTE}{token}"
107
- return Address(user, f"{root}/", f"{websocket_form(root)}/devtools/browser", named)
111
+ return Address(user, f"{root}/", f"{websocket_form(root)}/devtools/browser", named, context)
108
112
 
109
113
 
110
114
  class Tokens:
111
115
  """The tokens minted, one per user: in memory, so asking twice gives the same address, and in ``path`` only by
112
116
  hash, with the user, the base address and whether its caller named it, so an address still works after the server
113
- restarts while the computer's session, which can read the file, can't use one."""
117
+ restarts while the computer's session, which can read the file, can't use one. A token scoped to a lease is one per
118
+ user and lease, in memory only, as no lease outlives the server; the lease's end revokes it."""
114
119
 
115
120
  def __init__(self, path: Path) -> None:
116
121
  self.path = path
117
122
  self._minted: dict[str, Address] = {}
123
+ self._scoped: dict[tuple[str, str], Address] = {}
124
+ self._scoped_known: dict[str, tuple[str, str, bool, str]] = {}
118
125
  try:
119
126
  stored = json.loads(path.read_text())
120
127
  self._known = {digest: (entry["user"], entry["base"], entry["named"])
@@ -122,9 +129,15 @@ class Tokens:
122
129
  except (OSError, ValueError, TypeError, KeyError):
123
130
  self._known = {}
124
131
 
125
- def mint(self, user: str, base: str, *, named: bool = False) -> Address:
126
- """``user``'s address under ``base``, ``named`` when its caller named where its agent reaches the env: the one
127
- minted before, else a new one."""
132
+ def mint(self, user: str, base: str, *, named: bool = False, context: Optional[str] = None) -> Address:
133
+ """``user``'s address under ``base``, ``named`` when its caller named where its agent reaches the env, scoped
134
+ to the lease ``context`` when it names one: the one minted before, else a new one."""
135
+ if context is not None:
136
+ if (user, context) not in self._scoped:
137
+ token = secrets.token_urlsafe(TOKEN_BYTES)
138
+ self._scoped[(user, context)] = _address(user, base, named, token, context)
139
+ self._scoped_known[_hash(token)] = (user, base, named, context)
140
+ return self._scoped[(user, context)]
128
141
  if user not in self._minted:
129
142
  token = secrets.token_urlsafe(TOKEN_BYTES)
130
143
  self._minted[user] = _address(user, base, named, token)
@@ -134,13 +147,22 @@ class Tokens:
134
147
 
135
148
  def revoke_all(self) -> None:
136
149
  """Every address minted so far ended, as a reset ends them."""
137
- self._minted, self._known = {}, {}
150
+ self._minted, self._known, self._scoped, self._scoped_known = {}, {}, {}, {}
138
151
  self._save()
139
152
 
153
+ def revoke(self, context: str) -> None:
154
+ """Every address scoped to the lease ``context`` ended, as the lease has."""
155
+ self._scoped = {key: address for key, address in self._scoped.items() if key[1] != context}
156
+ self._scoped_known = {digest: known for digest, known in self._scoped_known.items() if known[3] != context}
157
+
140
158
  def address(self, token: str) -> Optional[Address]:
141
- """The address ``token`` was minted for, or None for one that wasn't."""
142
- known = self._known.get(_hash(token))
143
- return _address(*known, token) if known is not None else None
159
+ """The address ``token`` was minted for, or None for one that wasn't, or whose lease has ended."""
160
+ digest = _hash(token)
161
+ if (known := self._known.get(digest)) is not None:
162
+ return _address(*known, token)
163
+ if (scoped := self._scoped_known.get(digest)) is not None:
164
+ return _address(*scoped[:3], token, scoped[3])
165
+ return None
144
166
 
145
167
  def _save(self) -> None:
146
168
  self.path.parent.mkdir(parents=True, exist_ok=True)
@@ -159,6 +181,8 @@ class Verdict:
159
181
  params: dict
160
182
  reason: str = ""
161
183
  changed: bool = False
184
+ #: The error a refusal answers with in place of agentenv's own, as for a target the connection doesn't see.
185
+ error: Optional[dict] = None
162
186
 
163
187
 
164
188
  def guard(method: str, params: dict, *, dialogs_answered: bool, download_path: Optional[str] = None) -> Verdict:
@@ -204,11 +228,14 @@ class _Connection:
204
228
  """One client's WebSocket, its sessions over the pipe (its browser-level one and those it attached), its unanswered
205
229
  commands, what waits to be sent to it, and its entry in the record."""
206
230
 
207
- def __init__(self, websocket: WebSocket, user: str, session: str, record: dict, number: int) -> None:
231
+ def __init__(self, websocket: WebSocket, user: str, session: str, record: dict, number: int,
232
+ scope: Optional[Scope] = None) -> None:
208
233
  self.websocket, self.user, self.session, self.record, self.number = websocket, user, session, record, number
234
+ #: What it sees and acts in, a lease or the default context; None where the relay keeps no contexts.
235
+ self.scope = scope
209
236
  self.sessions = {session}
210
237
  #: The tab each session it attached is on.
211
- self.targets: dict[str, str] = {}
238
+ self.session_tabs: dict[str, str] = {}
212
239
  #: Held by each of its commands from when it arrives until it's sent, so they're sent in the order they came,
213
240
  #: whatever one waits on before it's sent.
214
241
  self.order = asyncio.Lock()
@@ -251,12 +278,16 @@ class Relay:
251
278
  causes the tab events a command brings. An agent's tool call a driver serves through a CDP user's connections,
252
279
  such as Playwright MCP's, is an entry too, which that user's commands are credited to while it's open. With
253
280
  ``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."""
281
+ downloads stay in its folder. A connection is scoped to a lease or to the default context, and sees only its scope
282
+ and the contexts its user made (``scope``)."""
255
283
 
256
284
  def __init__(self, devtools: DevToolsPipe, *, dialogs_answered: bool = False, log: Optional[BrowserLog] = None,
257
285
  control: Optional[BrowserControl] = None, contexts: Optional[Contexts] = None) -> None:
258
286
  self.devtools, self.dialogs_answered, self.log, self.control = devtools, dialogs_answered, log, control
259
287
  self.contexts = contexts
288
+ #: Each target's context, as Chromium reports it.
289
+ self.target_contexts = Targets()
290
+ self._tasks: set[asyncio.Future] = set()
260
291
  self.connections: list[dict] = []
261
292
  self._by_session: dict[str, _Connection] = {}
262
293
  self._open: set[_Connection] = set()
@@ -291,15 +322,32 @@ class Relay:
291
322
  self.log.finish(call.begun, **fields)
292
323
  return True
293
324
 
294
- async def serve(self, websocket: WebSocket, user: str) -> None:
295
- """``websocket``, a client of ``user``'s, relayed over a browser-level session of its own until either ends."""
325
+ async def serve(self, websocket: WebSocket, user: str, context: Optional[str] = None) -> None:
326
+ """``websocket``, a client of ``user``'s, relayed over a browser-level session of its own until either ends,
327
+ scoped to the lease ``context`` when it names one."""
328
+ lease_id = None
329
+ if context is not None:
330
+ lease = self.contexts.get(context) if self.contexts is not None else None
331
+ if lease is None:
332
+ await websocket.accept()
333
+ await websocket.close(code=LEASE_ENDED[0], reason=LEASE_ENDED[1])
334
+ return
335
+ lease_id = lease.id
296
336
  try:
297
337
  session = (await self.devtools.call("Target.attachToBrowserTarget"))["sessionId"]
298
338
  except Exception as e:
299
339
  await websocket.close(code=1013, reason=f"the browser isn't answering: {type(e).__name__}")
300
340
  return
301
- record = {"user": user, "opened_at": _now(), "guarded": []}
302
- connection = _Connection(websocket, user, session, record, len(self.connections) + 1)
341
+ if context is not None and ((lease := self.contexts.get(context)) is None or lease.id != lease_id):
342
+ with contextlib.suppress(Exception):
343
+ await self.devtools.call("Target.detachFromTarget", {"sessionId": session})
344
+ await websocket.accept()
345
+ await websocket.close(code=LEASE_ENDED[0], reason=LEASE_ENDED[1])
346
+ return
347
+ record = {"user": user, "opened_at": _now(), "guarded": [], **({"context": context} if context else {})}
348
+ scope = Scope(self.contexts, self.target_contexts, user, lease_id, self._frame_context) \
349
+ if self.contexts is not None else None
350
+ connection = _Connection(websocket, user, session, record, len(self.connections) + 1, scope)
303
351
  self._by_session[session] = connection
304
352
  self._open.add(connection)
305
353
  self.connections.append(record)
@@ -331,6 +379,14 @@ class Relay:
331
379
  """The browser has gone: every connection is closed with a reason a client may connect again after."""
332
380
  for connection in list(self._open):
333
381
  self._close(connection, RELAUNCHED)
382
+ self.target_contexts.forget()
383
+
384
+ def lease_ended(self, context_id: str) -> None:
385
+ """The lease the browser knows as ``context_id`` has ended: each connection scoped to it is closed, saying
386
+ so."""
387
+ for connection in list(self._open):
388
+ if connection.scope is not None and connection.scope.lease == context_id:
389
+ self._close(connection, LEASE_ENDED)
334
390
 
335
391
  async def _command(self, connection: _Connection, message: Any) -> None:
336
392
  if connection.closing:
@@ -351,6 +407,8 @@ class Relay:
351
407
  replied = True
352
408
  if sending is not None and isinstance(answer.get("result"), dict):
353
409
  self._answered(connection, method, params, answer["result"])
410
+ if connection.scope is not None:
411
+ answer = {**answer, "result": connection.scope.answer(method, answer["result"])}
354
412
  self._put(connection, _reply(message, answer))
355
413
 
356
414
  try:
@@ -360,8 +418,8 @@ class Relay:
360
418
  if session not in connection.sessions:
361
419
  verdict, answer = None, {"error": NO_SESSION}
362
420
  elif verdict.action == "refuse":
363
- answer = {"error": {"code": SERVER_ERROR,
364
- "message": f"agentenv refuses {method}: {verdict.reason}"}}
421
+ answer = {"error": verdict.error or {"code": SERVER_ERROR,
422
+ "message": f"agentenv refuses {method}: {verdict.reason}"}}
365
423
  elif verdict.action != "send":
366
424
  answer = {"result": {}}
367
425
  else:
@@ -387,24 +445,28 @@ class Relay:
387
445
  logged.finish(answer, guarded)
388
446
 
389
447
  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:
448
+ """The guard's verdict on ``connection``'s command, after its scope's (``Scope.verdict``), and with where a
449
+ lease's downloads go."""
450
+ if connection.scope is None:
393
451
  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)
452
+ ruling = connection.scope.verdict(method, params, on_browser_session=session == connection.session)
453
+ if ruling.refused:
454
+ return Verdict("refuse", params, ruling.refused, error=ruling.error)
455
+ params = ruling.params
397
456
  download_path = None
398
457
  if method in SETS_DOWNLOADS:
399
458
  connection.set_downloads = True
400
459
  context = params.get("browserContextId") if method.startswith("Browser.") else \
401
- self._context_of(connection.targets.get(session))
460
+ self._context_of(connection.session_tabs.get(session))
402
461
  download_path = self.contexts.download_path(context)
403
462
  return guard(method, params, dialogs_answered=self.dialogs_answered, download_path=download_path)
404
463
 
405
464
  def _context_of(self, target: Optional[str]) -> Optional[str]:
406
465
  return self.control.tabs.get(target, {}).get("context_id") if self.control is not None and target else None
407
466
 
467
+ def _frame_context(self, frame: object) -> Optional[str]:
468
+ return self.control.context_of_frame(frame) if self.control is not None else None
469
+
408
470
  def _answered(self, connection: _Connection, method: str, params: dict, result: dict) -> None:
409
471
  """A context ``connection`` made leased to its user before it hears the answer, and one it disposed ended."""
410
472
  if self.contexts is None:
@@ -432,7 +494,7 @@ class Relay:
432
494
  control."""
433
495
  if self.log is None:
434
496
  return None
435
- target = connection.targets.get(session) if session != connection.session else None
497
+ target = connection.session_tabs.get(session) if session != connection.session else None
436
498
  if target is None and isinstance(params.get("targetId"), str):
437
499
  target = params["targetId"]
438
500
  acting = acts(method)
@@ -451,23 +513,53 @@ class Relay:
451
513
  guarded.append({"method": method, "did": GUARDED[verdict.action], "at": _now()})
452
514
 
453
515
  def _event(self, message: dict) -> None:
516
+ params = message.get("params") or {}
517
+ if message.get("method") in WITH_INFO:
518
+ self.target_contexts.saw(params.get("targetInfo"))
454
519
  connection = self._by_session.get(message.get("sessionId"))
455
520
  if connection is None:
456
521
  return
457
- params = message.get("params") or {}
522
+ if message.get("sessionId") == connection.session and not self._hears(connection, message):
523
+ return
458
524
  if message.get("method") == "Target.attachedToTarget" and params.get("sessionId"):
459
525
  connection.sessions.add(params["sessionId"])
460
526
  self._by_session[params["sessionId"]] = connection
461
527
  if isinstance(target := (params.get("targetInfo") or {}).get("targetId"), str):
462
- connection.targets[params["sessionId"]] = target
528
+ connection.session_tabs[params["sessionId"]] = target
463
529
  elif message.get("method") == "Target.detachedFromTarget" and params.get("sessionId"):
464
530
  connection.sessions.discard(params["sessionId"])
465
- connection.targets.pop(params["sessionId"], None)
531
+ connection.session_tabs.pop(params["sessionId"], None)
466
532
  self._by_session.pop(params["sessionId"], None)
467
533
  if message["sessionId"] == connection.session:
468
534
  message = {key: value for key, value in message.items() if key != "sessionId"}
469
535
  self._put(connection, message)
470
536
 
537
+ def _hears(self, connection: _Connection, message: dict) -> bool:
538
+ """Whether ``connection`` hears an event on its browser session, as its scope says: never one about a session it
539
+ doesn't have, and a target it doesn't see that auto-attached to it let go."""
540
+ if connection.scope is None:
541
+ return True
542
+ method, params = message.get("method"), message.get("params") or {}
543
+ if method == "Target.detachedFromTarget":
544
+ return params.get("sessionId") in connection.sessions
545
+ heard, let_go = connection.scope.hears(method, params)
546
+ if let_go is not None:
547
+ self._spawn(self._let_go(connection.session, let_go, params.get("waitingForDebugger")))
548
+ return heard
549
+
550
+ async def _let_go(self, owner: str, session: str, waiting: object) -> None:
551
+ """A target auto-attached to the browser session ``owner`` as ``session`` that its connection doesn't see: told
552
+ to run when it waits for its debugger, so it isn't held, and detached."""
553
+ with contextlib.suppress(ConnectionError, DevToolsError):
554
+ if waiting:
555
+ await self.devtools.call("Runtime.runIfWaitingForDebugger", session_id=session)
556
+ await self.devtools.call("Target.detachFromTarget", {"sessionId": session}, session_id=owner)
557
+
558
+ def _spawn(self, work) -> None:
559
+ task = asyncio.ensure_future(work)
560
+ self._tasks.add(task)
561
+ task.add_done_callback(self._tasks.discard)
562
+
471
563
  def _put(self, connection: _Connection, message: dict) -> None:
472
564
  """``message`` waiting to be sent to ``connection``'s client, which is closed instead, with what waited dropped,
473
565
  once it has fallen too far behind."""
@@ -79,6 +79,8 @@ class Contexts:
79
79
  home: Callable[[], Path] = Path.home) -> None:
80
80
  self.devtools, self.control, self.home = devtools, control, home
81
81
  self.leases: dict[str, Lease] = {}
82
+ #: What hears of each lease's end, whatever ends it: its release, its disposal or the browser's.
83
+ self.on_end: list[Callable[[Lease], None]] = []
82
84
  self._made: dict[str, int] = {}
83
85
  self._tasks: set[asyncio.Future] = set()
84
86
  self._lock = asyncio.Lock()
@@ -135,6 +137,7 @@ class Contexts:
135
137
  if (lease := self.leases.pop(label, None)) is None:
136
138
  return False
137
139
  self.control.closing_context(lease.id)
140
+ self._ended(lease)
138
141
  with contextlib.suppress(DevToolsError):
139
142
  await self.devtools.call("Target.disposeBrowserContext", {"browserContextId": lease.id})
140
143
  await asyncio.to_thread(shutil.rmtree, lease.folder(self.home()), True)
@@ -177,6 +180,7 @@ class Contexts:
177
180
  deleted, so a lease of its label after has a folder of its own."""
178
181
  if (lease := self.of(context_id)) is not None:
179
182
  self.leases.pop(lease.label, None)
183
+ self._ended(lease)
180
184
  folder, gone = lease.folder(self.home()), self.home() / CONTEXTS / f".gone-{lease.id}"
181
185
  with contextlib.suppress(OSError):
182
186
  folder.rename(gone)
@@ -202,10 +206,19 @@ class Contexts:
202
206
 
203
207
  def ended(self) -> None:
204
208
  """The browser has gone, and every context with it: no lease is left, and their folders are deleted."""
209
+ for lease in list(self.leases.values()):
210
+ self._ended(lease)
205
211
  self.leases.clear()
206
212
  self._made.clear()
207
213
  shutil.rmtree(self.home() / CONTEXTS, ignore_errors=True)
208
214
 
215
+ def _ended(self, lease: Lease) -> None:
216
+ for hook in self.on_end:
217
+ try:
218
+ hook(lease)
219
+ except Exception as e:
220
+ logger.warning(f"the end of the lease {lease.label!r}: {type(e).__name__}: {e}")
221
+
209
222
  def _record(self, lease: Lease) -> Lease:
210
223
  self.leases[lease.label] = lease
211
224
  self.control.other_contexts[lease.id] = lease.label
@@ -260,6 +260,12 @@ class BrowserControl:
260
260
  return [OpenTab(**tab, active=tab["id"] == active, context=self.label_of(tab)).model_dump()
261
261
  for tab in self.tabs.values() if self.in_context(tab.get("context_id"), context)]
262
262
 
263
+ def context_of_frame(self, frame: object) -> Optional[str]:
264
+ """The context of the tab the frame ``frame`` is in, a tab's own frame among them; None for one it hasn't
265
+ seen."""
266
+ tab = self._frame_tabs.get(frame, frame) if isinstance(frame, str) else None
267
+ return self.tabs.get(tab, {}).get("context_id") if tab is not None else None
268
+
263
269
  def label_of(self, entry: dict) -> Optional[str]:
264
270
  """The label of the lease a tab or download was in, None for the default context."""
265
271
  return self.other_contexts.get(entry.get("context_id"))
@@ -937,6 +943,12 @@ class BrowserControl:
937
943
  load.commits.append(frame["loaderId"])
938
944
  load.check()
939
945
 
946
+ def _on_Page_frameAttached(self, params: dict, session: Optional[str]) -> None:
947
+ """A frame attached to a page of one of its tabs, kept as that tab's: a cross-origin one goes on in a process
948
+ of its own, whose navigations its tab's page doesn't hear of."""
949
+ if session in self._sessions and isinstance(frame := params.get("frameId"), str):
950
+ self._frame_tabs[frame] = self._sessions[session]
951
+
940
952
  def _on_Page_navigatedWithinDocument(self, params: dict, session: Optional[str]) -> None:
941
953
  """A tab's page moving to another URL of its document, a fragment or its history API: a command's, when one
942
954
  asked for it, else its page's."""
@@ -27,12 +27,13 @@ from ..computer import app as computer_app
27
27
  from ..computer import app_data
28
28
  from ..computer.app import SOCKET, agent_acted, forget_agent_acted
29
29
  from ..computer.dataplane import file_parts
30
- from ..computer.errors import DeviceUnavailable, InvalidArgument
30
+ from ..computer.errors import DeviceUnavailable, InvalidArgument, PermissionDenied, TargetUnavailable
31
31
  from ..tool_context import DEFAULT_ROLE, ROLE_HEADER, normalize_role
32
32
  from ..transfers import WriteNamespaceGrant
33
33
  from ..types import METHOD_ADD, RPC_PATH, EnvironmentExtension, IntakeDeclaration, IntakeFormat, intake_extension
34
34
  from . import data
35
35
  from .contexts import CONTEXTS, TASK, Contexts, label_problem
36
+ from .scope import Scope
36
37
  from .control import AGENT, DOWNLOADS, EXIT, LIVE_START_TAB_TIMEOUT_S, LOADED, STOP, UPLOADS, BrowserControl, _now
37
38
  from .devtools import PIPE_IN, PIPE_OUT, DevToolsError, DevToolsPipe
38
39
  from .recording import BROWSER_RECORDING, MAX_DURATION_S, MAX_FRAMES, BrowserRecordings
@@ -168,6 +169,7 @@ class WebsiteBrowserEnvironment(ComputerAppEnvironment):
168
169
  self.cdp_tokens = Tokens(SOCKET.parent / "cdp-tokens.json")
169
170
  self.relay = Relay(self.devtools, dialogs_answered=self.settings.dialogs != AGENT, log=self.log,
170
171
  control=self.control, contexts=self.contexts)
172
+ self.contexts.on_end.append(self._lease_ended)
171
173
  #: Its recordings: frames of the tab an agent last acted in, and its log, uploaded under each one's grant.
172
174
  self.recordings = BrowserRecordings(self.log, self.control)
173
175
  self.devtools.on_close(self._pipe_closed)
@@ -350,6 +352,10 @@ class WebsiteBrowserEnvironment(ComputerAppEnvironment):
350
352
  "caller's agent reaches the env, when it names one, else at the address the call reached the browser at, "
351
353
  "with a token agentenv mints in its path: each connection to it gets its own browser-level session behind a "
352
354
  "guard, and record lists them as cdp_connections, each with the commands the guard refused or changed. "
355
+ "Naming a lease's label as context, cdp returns an address scoped to it, for a user it's granted to: its "
356
+ "connections see that lease as the browser's default context, its targets alone, pages, iframes and workers, "
357
+ "with the contexts their user made, and what they open, set or download lands in it; the address ends with "
358
+ "the lease. An address with no context sees the default context and its user's own, not the leases. "
353
359
  "sites/set hands it the env's own sites, by name and domains: a start tab on one must load, its document's "
354
360
  "status 2xx, or its launch counts it failed, while one on any other site is waited on 30 s at most. record "
355
361
  "keeps each launch's start_tabs: the URL asked for and ended on, the status, any network error, the load time, "
@@ -429,16 +435,28 @@ class WebsiteBrowserEnvironment(ComputerAppEnvironment):
429
435
  return {"recordings": await self.recordings.end_all(reason)}
430
436
 
431
437
  @extension(BROWSER, op="cdp")
432
- async def browser_cdp(self, user: str, request: Request, origin: Optional[str] = None) -> dict:
438
+ async def browser_cdp(self, user: str, request: Request, origin: Optional[str] = None,
439
+ context: Optional[str] = None) -> dict:
433
440
  """``user``'s CDP address once the browser's ready, the same one each time it's asked for, as the server that
434
441
  minted it keeps it: under ``origin``, where the caller's agent reaches the env, when the caller names it, as a
435
442
  deploy names the env's other addresses, since a tunnel in front of the env may not say how it was reached;
436
- else at the address this call reached the browser at."""
443
+ else at the address this call reached the browser at. Scoped to the lease ``context`` when it names one,
444
+ which must be granted to ``user``, and which the address ends with."""
437
445
  base = under(_origin(origin), request) if origin is not None else reached(request)
438
446
  await self._until_ready()
439
- address = self.cdp_tokens.mint(user, base, named=origin is not None)
447
+ if context is not None:
448
+ if (lease := self.contexts.get(context)) is None:
449
+ raise TargetUnavailable(f"no context {context!r} is leased; contexts/list names the leased ones")
450
+ if user not in lease.grants:
451
+ raise PermissionDenied(f"the context {context!r} isn't granted to {user!r}: contexts/grant grants it")
452
+ address = self.cdp_tokens.mint(user, base, named=origin is not None, context=context)
440
453
  return {"http_url": address.http_url, "ws_url": address.ws_url}
441
454
 
455
+ def _lease_ended(self, lease: Any) -> None:
456
+ """A lease ended: the addresses scoped to it end with it, and their connections are closed."""
457
+ self.cdp_tokens.revoke(lease.label)
458
+ self.relay.lease_ended(lease.id)
459
+
442
460
  def served_asgi(self, asgi: Any) -> Any:
443
461
  return _LoggedOps(super().served_asgi(asgi), self)
444
462
 
@@ -466,7 +484,8 @@ class WebsiteBrowserEnvironment(ComputerAppEnvironment):
466
484
  "WebKit-Version": version.get("revision"),
467
485
  "webSocketDebuggerUrl": address.ws_url if address.named else
468
486
  f"{websocket_form(reached(request))}{ROUTE}{token}/devtools/browser"})
469
- tabs = await self.control.tab_list()
487
+ tabs = [tab for tab in await self.control.tab_list(every=True)
488
+ if self._sees(address, self.control.tabs.get(tab["id"], {}).get("context_id"))]
470
489
  except (ConnectionError, DevToolsError, asyncio.TimeoutError) as e:
471
490
  return JSONResponse({"error": f"the browser isn't answering: {e}"}, status_code=503)
472
491
  return JSONResponse([{"id": tab["id"], "type": "page", "title": tab["title"], "url": tab["url"],
@@ -477,7 +496,15 @@ class WebsiteBrowserEnvironment(ComputerAppEnvironment):
477
496
  if address is None:
478
497
  await websocket.close(code=1008)
479
498
  return
480
- await self.relay.serve(websocket, address.user)
499
+ await self.relay.serve(websocket, address.user, address.context)
500
+
501
+ def _sees(self, address: Any, context_id: Optional[str]) -> bool:
502
+ """Whether an address sees a tab in the browser context ``context_id``, as a connection to it does."""
503
+ lease = self.contexts.get(address.context) if address.context is not None else None
504
+ if address.context is not None and lease is None:
505
+ return False
506
+ return Scope(self.contexts, self.relay.target_contexts, address.user, lease.id if lease else None).sees(
507
+ context_id)
481
508
 
482
509
  async def _until_ready(self) -> None:
483
510
  """Back once it's ready, as ``computer-app/v1``'s ``ready`` says, or DeviceUnavailable after its ready