Move custom code to dedicated files and cleanup v1 vs v2 checks

Merged
PI
7mo ago
+572-232

Summary by cubic

Moved Pydantic extract logic into a dedicated module and auto-patched Session/AsyncSession to use it. Hard-required pydantic v2 at import time and added tests for extract behavior.

  • Refactors

    • Added src/stagehand/_session_extract.py and auto-installed the extract patch in sessions_helpers.
    • Centralized Pydantic response validation in _pydantic_extract.py with cached model config and strict_response_validation.
    • Enforced pydantic v2 in _compat.py with a clear ImportError.
    • Simplified session.py by delegating extract logic and removing v1/v2 conditionals; added focused tests for session extract.
  • Migration

    • stagehand now requires pydantic>=2,<3. Install or upgrade to v2.
    • Removed the pydantic-v2 extra from pyproject.toml; use standard pydantic v2 installation.