agentenv-framework-protocol 0.1.533__tar.gz → 0.1.537__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 (190) hide show
  1. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/PKG-INFO +1 -1
  2. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/pyproject.toml +1 -1
  3. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/card.py +3 -0
  4. agentenv_framework_protocol-0.1.537/src/agentenv_protocol/computer/clock.py +100 -0
  5. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/extensions.py +7 -1
  6. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/operations.py +3 -1
  7. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/results.py +2 -0
  8. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/tools.py +2 -1
  9. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/cdp.py +61 -8
  10. agentenv_framework_protocol-0.1.537/src/agentenv_protocol/website_browser/contexts.py +241 -0
  11. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/control.py +249 -108
  12. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/data.py +21 -7
  13. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/environment.py +150 -50
  14. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/log.py +11 -8
  15. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/recording.py +17 -6
  16. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/shapes.py +37 -5
  17. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_browser_cdp.py +63 -6
  18. agentenv_framework_protocol-0.1.537/tests/test_browser_contexts.py +387 -0
  19. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_browser_data.py +11 -7
  20. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_browser_log.py +13 -0
  21. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_browser_recording.py +123 -4
  22. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_browser_state.py +1 -1
  23. agentenv_framework_protocol-0.1.537/tests/test_computer_clock.py +110 -0
  24. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/.gitignore +0 -0
  25. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/LICENSE +0 -0
  26. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/NOTICE +0 -0
  27. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/README.md +0 -0
  28. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/THIRD_PARTY_NOTICES.md +0 -0
  29. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/__init__.py +0 -0
  30. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/advanced_agent.py +0 -0
  31. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/basic_agent.py +0 -0
  32. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/custom_extensions_agent.py +0 -0
  33. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/multimodal_agent.py +0 -0
  34. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/reference_model.py +0 -0
  35. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/streaming_agent.py +0 -0
  36. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/.gitignore +0 -0
  37. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/Dockerfile +0 -0
  38. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/Dockerfile.dockerignore +0 -0
  39. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/README.md +0 -0
  40. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/data/seed.json +0 -0
  41. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/env.toml +0 -0
  42. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/site.py +0 -0
  43. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/web/index.html +0 -0
  44. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/web/package-lock.json +0 -0
  45. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/web/package.json +0 -0
  46. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/web/src/main.js +0 -0
  47. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/web/src/style.css +0 -0
  48. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/examples/website/notes/web/vite.config.js +0 -0
  49. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/__init__.py +0 -0
  50. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/__init__.py +0 -0
  51. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/_trajectory_log.py +0 -0
  52. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/_triggers.py +0 -0
  53. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/extensions.py +0 -0
  54. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/framework.py +0 -0
  55. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/peer_agents.py +0 -0
  56. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/proxy.py +0 -0
  57. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/registry.py +0 -0
  58. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/staging.py +0 -0
  59. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/tasks/__init__.py +0 -0
  60. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/a2a_agent/tasks/v1.py +0 -0
  61. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/agent_env_environment.py +0 -0
  62. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/client.py +0 -0
  63. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/__init__.py +0 -0
  64. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_declare.py +0 -0
  65. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_desktop.py +0 -0
  66. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_job.py +0 -0
  67. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_linux.py +0 -0
  68. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_load.py +0 -0
  69. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_macos.py +0 -0
  70. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_reaping.py +0 -0
  71. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_session_posix.py +0 -0
  72. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_session_windows.py +0 -0
  73. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_windows.py +0 -0
  74. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_with_fds.py +0 -0
  75. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/_x11.py +0 -0
  76. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/app.py +0 -0
  77. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/app_data.py +0 -0
  78. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/app_runtime.py +0 -0
  79. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/apps.py +0 -0
  80. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/checks.py +0 -0
  81. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/__init__.py +0 -0
  82. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/__main__.py +0 -0
  83. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/checks.py +0 -0
  84. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/client.py +0 -0
  85. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/desk.py +0 -0
  86. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/fixture.py +0 -0
  87. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/mp4.py +0 -0
  88. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/page_fixture.py +0 -0
  89. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/report.py +0 -0
  90. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/conformance/wayland_fixture.py +0 -0
  91. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/dataplane.py +0 -0
  92. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/driver.py +0 -0
  93. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/errors.py +0 -0
  94. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/frames.py +0 -0
  95. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/keys.py +0 -0
  96. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/launch.py +0 -0
  97. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/manifest.py +0 -0
  98. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/platform.py +0 -0
  99. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/prefix.py +0 -0
  100. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/queue.py +0 -0
  101. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/recording.py +0 -0
  102. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/run_install_step.py +0 -0
  103. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/runtime.py +0 -0
  104. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/seed.py +0 -0
  105. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/serve.py +0 -0
  106. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/serve_app.py +0 -0
  107. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/served.py +0 -0
  108. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/session.py +0 -0
  109. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/settings.py +0 -0
  110. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/skill.py +0 -0
  111. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/spaces.py +0 -0
  112. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/computer/svc.py +0 -0
  113. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/errors.py +0 -0
  114. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/manifest.py +0 -0
  115. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/preflight.py +0 -0
  116. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/tool_access.py +0 -0
  117. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/tool_client.py +0 -0
  118. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/tool_context.py +0 -0
  119. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/transfers.py +0 -0
  120. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/types.py +0 -0
  121. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/__init__.py +0 -0
  122. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/clock.py +0 -0
  123. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/conformance.py +0 -0
  124. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/environment.py +0 -0
  125. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/errors.py +0 -0
  126. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/readiness.py +0 -0
  127. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/routes.py +0 -0
  128. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website/session.py +0 -0
  129. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/__init__.py +0 -0
  130. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/devtools.py +0 -0
  131. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/src/agentenv_protocol/website_browser/network.py +0 -0
  132. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/computer_fake.py +0 -0
  133. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/probe_fake.py +0 -0
  134. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_agent.py +0 -0
  135. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_agent_examples.py +0 -0
  136. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_cdp_config.py +0 -0
  137. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_object_transfers.py +0 -0
  138. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_peer_agents.py +0 -0
  139. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_proxy.py +0 -0
  140. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_staging.py +0 -0
  141. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_a2a_trajectory_log.py +0 -0
  142. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_agent_env_environment.py +0 -0
  143. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_browser_network.py +0 -0
  144. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_client.py +0 -0
  145. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_app_data.py +0 -0
  146. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_app_server.py +0 -0
  147. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_conformance.py +0 -0
  148. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_conformance_checks.py +0 -0
  149. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_conformance_page.py +0 -0
  150. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_conformance_recording.py +0 -0
  151. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_dataplane.py +0 -0
  152. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_declare.py +0 -0
  153. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_driver.py +0 -0
  154. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_driver_keys.py +0 -0
  155. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_extensions.py +0 -0
  156. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_frames.py +0 -0
  157. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_macos.py +0 -0
  158. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_page.py +0 -0
  159. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_queue.py +0 -0
  160. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_recording.py +0 -0
  161. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_seed.py +0 -0
  162. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_serve.py +0 -0
  163. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_served.py +0 -0
  164. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_session_windows.py +0 -0
  165. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_spaces.py +0 -0
  166. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_svc_forward.py +0 -0
  167. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_tool_prefix.py +0 -0
  168. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_computer_windows_driver.py +0 -0
  169. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_control_token.py +0 -0
  170. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_data_objects.py +0 -0
  171. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_devtools_pipe.py +0 -0
  172. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_errors.py +0 -0
  173. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_extension_methods.py +0 -0
  174. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_intake.py +0 -0
  175. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_manifest.py +0 -0
  176. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_preflight.py +0 -0
  177. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_tool_access.py +0 -0
  178. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_tool_annotations.py +0 -0
  179. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_tool_client.py +0 -0
  180. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_tool_context.py +0 -0
  181. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_tool_context_fastmcp.py +0 -0
  182. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_tool_context_injection.py +0 -0
  183. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_api.py +0 -0
  184. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_browser.py +0 -0
  185. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_conformance.py +0 -0
  186. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_environment.py +0 -0
  187. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_live.py +0 -0
  188. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_mcp.py +0 -0
  189. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/tests/test_website_notes_example.py +0 -0
  190. {agentenv_framework_protocol-0.1.533 → agentenv_framework_protocol-0.1.537}/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.533
3
+ Version: 0.1.537
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.533"
3
+ version = "0.1.537"
4
4
  description = "Open data-plane protocol and server SDK for agent environments."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
 
6
6
  from typing import TYPE_CHECKING
7
7
 
8
+ from . import clock
8
9
  from .dataplane import DEFAULT_DATA_PATHS
9
10
  from .recording import recording_params
10
11
  from ..types import METHOD_ADD, EnvironmentExtension, EnvironmentTool, IntakeDeclaration, IntakeFormat, intake_extension
@@ -55,6 +56,8 @@ def served_extensions(driver: ComputerDriverEnvironment,
55
56
  continue
56
57
  if extension.uri == COMPUTER_RECORDING and driver.recording is None:
57
58
  continue
59
+ if extension.uri == clock.CLOCK and not clock.follows():
60
+ continue
58
61
  dropped = {op for (uri, op), need in _METHOD_NEEDS.items() if uri == extension.uri and not driver.has(need)}
59
62
  if dropped:
60
63
  methods = {op: entry for op, entry in extension.params["methods"].items() if op not in dropped}
@@ -0,0 +1,100 @@
1
+ """A computer's side of clock/v1. A base that follows the universe clock runs a follower (its image has ``FOLLOWER``),
2
+ which core configures through the sandbox's root channel (``CONFIG``, root's and the follower's alone, holding the
3
+ computer's read token) and which says how it's doing in ``STATUS``, holding no token. The driver serves clock/v1's
4
+ ``sync_time``, the method every server that follows the clock serves, so the computer's card is what tells core and the
5
+ gateway that it follows: called when the clock is armed, it checks the task's zone against the one the computer booted
6
+ with and answers once the follower shows the gateway's current version, or says why it doesn't. That version it reads
7
+ from the gateway's watch, as any reader may: a watch naming no follower is answered at once and acknowledges nothing."""
8
+ from __future__ import annotations
9
+
10
+ import asyncio
11
+ import json
12
+ import os
13
+ import time
14
+ import urllib.parse
15
+ import urllib.request
16
+ from pathlib import Path
17
+ from typing import Optional
18
+
19
+ from .errors import InvalidArgument, TargetUnavailable
20
+
21
+ CLOCK = "urn:agentenv:clock/v1"
22
+ FOLLOWER = "/usr/local/lib/agentenv-clock/clock-follower"
23
+ #: The follower's user, whose group may read ``CONFIG``.
24
+ FOLLOWER_USER = "agentenv-clock"
25
+ CONFIG = "/etc/agentenv/clock/follower.json"
26
+ STATUS = "/run/agentenv-clock/status.json"
27
+ #: What a disk form's guest has, made from the computer's container image: core's root channel reaches its launcher,
28
+ #: not the guest, so it can't configure a follower there, and a disk computer stays on real time for now.
29
+ DISK_GUEST = "/etc/agentenv/vm/image.env"
30
+ #: How long ``sync_time`` waits for the follower to show the gateway's current version, as after a gateway restart
31
+ #: or a clock change it catches up.
32
+ CONNECT_WAIT_S = 10.0
33
+ _DIRECT = urllib.request.build_opener(urllib.request.ProxyHandler({}))
34
+
35
+
36
+ def follows() -> bool:
37
+ """Whether this computer follows the universe clock: its base runs the follower, and it isn't a disk guest."""
38
+ return os.path.exists(FOLLOWER) and not os.path.exists(DISK_GUEST)
39
+
40
+
41
+ def session_zone() -> str:
42
+ """The zone the computer booted with, which every session program is in."""
43
+ try:
44
+ return os.environ.get("TZ") or Path("/etc/timezone").read_text().strip() or "UTC"
45
+ except OSError:
46
+ return "UTC"
47
+
48
+
49
+ def follower_status() -> dict:
50
+ try:
51
+ status = json.loads(Path(STATUS).read_text())
52
+ except (OSError, ValueError):
53
+ return {}
54
+ return status if isinstance(status, dict) else {}
55
+
56
+
57
+ def gateway_version(watch_url: str) -> str:
58
+ """The version the gateway's clock has now, read from its watch naming no version and no follower."""
59
+ with _DIRECT.open(f"{watch_url}?{urllib.parse.urlencode({'after': ''})}", timeout=5) as answer:
60
+ return json.loads(answer.read())["version"]
61
+
62
+
63
+ def _why(status: dict, current: Optional[str], unread: Optional[str]) -> str:
64
+ if status.get("error"):
65
+ return f"it can't reach the gateway at {status.get('url')}: {status['error']}"
66
+ if not status.get("url"):
67
+ return "core hasn't written its config, which it does when a multi env deploys this computer"
68
+ if not status.get("connected"):
69
+ return f"it hasn't heard from the gateway at {status['url']} yet"
70
+ if unread is not None:
71
+ return f"this computer can't read the gateway's version at {status['url']}: {unread}"
72
+ return f"it shows the gateway's version {status.get('version')!r}, and the gateway is at {current!r}"
73
+
74
+
75
+ async def sync_time(env_get_time_url: str, timezone: Optional[str] = None) -> dict:
76
+ """``clock/v1``'s ``sync_time`` on a computer: its follower already follows the gateway core configured it with,
77
+ so ``env_get_time_url`` is taken as every server takes it and not used; ``timezone``, the task's, must be the one
78
+ the computer booted with, which a deploy sets (``computer_settings.timezone``)."""
79
+ if not follows():
80
+ raise TargetUnavailable("this computer's base doesn't follow the universe clock")
81
+ zone = session_zone()
82
+ if timezone is not None and timezone.strip() != zone:
83
+ raise InvalidArgument(f"the task's clock is in {timezone.strip()!r} and this computer's session in {zone!r}; "
84
+ f"deploy it with computer_settings.timezone = {timezone.strip()!r}")
85
+ deadline = time.monotonic() + CONNECT_WAIT_S
86
+ while True:
87
+ status, current, unread = follower_status(), None, None
88
+ if status.get("connected") and status.get("url"):
89
+ try:
90
+ current = await asyncio.to_thread(gateway_version, status["url"])
91
+ except Exception as e: # noqa: BLE001 - away or answering something else: said as why, tried again
92
+ unread = f"{type(e).__name__}: {e}"[:300]
93
+ status = follower_status()
94
+ if current is not None and status.get("connected") and status.get("version") == current:
95
+ return {"synced": True, "timezone": zone, "env_get_time_url": env_get_time_url,
96
+ "follower": {key: status.get(key) for key in ("name", "url", "version", "armed")}}
97
+ if time.monotonic() >= deadline:
98
+ raise TargetUnavailable("this computer's clock follower isn't following the gateway: "
99
+ + _why(status, current, unread))
100
+ await asyncio.sleep(0.1)
@@ -5,7 +5,7 @@ from __future__ import annotations
5
5
  from typing import TYPE_CHECKING, Callable, Optional
6
6
 
7
7
  from ..agent_env_environment import agent_skill, extension
8
- from . import card
8
+ from . import card, clock
9
9
  from .card import (
10
10
  COMPUTER_DISPLAY,
11
11
  COMPUTER_EXEC,
@@ -52,6 +52,12 @@ class Extensions:
52
52
  status["failed"] = "; ".join(f"{c.name}: {c.detail}" for c in failed)
53
53
  return status
54
54
 
55
+ @extension(clock.CLOCK, description="Follow the gateway's universe clock: the computer's clock follower already "
56
+ "follows the gateway core configured it with; this checks the task's zone against the one the computer "
57
+ "booted with and answers once the follower is connected, or says why it isn't.")
58
+ async def sync_time(self, env_get_time_url: str, timezone: Optional[str] = None) -> dict:
59
+ return await clock.sync_time(env_get_time_url, timezone)
60
+
55
61
  @extension(COMPUTER_DISPLAY, op="get", method="GET", description="Get or set the display's resolution and scale.")
56
62
  async def _computer_display_get(self) -> dict:
57
63
  return _display_data(await self._computer.display_now(), self.display_modes)
@@ -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, and its page's URL and title."""
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)
@@ -78,6 +78,8 @@ class TabData(BaseModel):
78
78
  url: str
79
79
  title: str
80
80
  active: bool
81
+ #: The label of the lease it's in, None for the browser's default context.
82
+ context: Optional[str] = None
81
83
 
82
84
 
83
85
  class TabsResult(InputResult):
@@ -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) for t in tabs or []]
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, open the browser's own pages or race the dialogs agentenv answers when
164
- ``dialogs_answered``: a guardrail, since the sandbox's network is the boundary."""
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
- **{key: params[key] for key in ("browserContextId", "eventsEnabled") if key in params}}
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 = guard(method, params, dialogs_answered=self.dialogs_answered)
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}")