|
8 | 8 | import uuid |
9 | 9 | from dataclasses import dataclass |
10 | 10 | from datetime import datetime, timedelta |
11 | | -from typing import Optional |
| 11 | +from typing import Any, Optional |
12 | 12 | from loguru import logger |
| 13 | +from pydantic import RootModel |
| 14 | + |
| 15 | + |
| 16 | +class GenericExtractSchema(RootModel[Any]): |
| 17 | + pass |
| 18 | + |
13 | 19 |
|
14 | 20 | from agentbay import AgentBay, CreateSessionParams |
15 | 21 | from app.core.logging_config import _disable_agentbay_logger_override, configure_logging |
@@ -268,15 +274,18 @@ async def browser_extract(self, instruction: str, selector: str = "") -> dict: |
268 | 274 | await asyncio.sleep(3) |
269 | 275 |
|
270 | 276 | from agentbay._common.models.browser_operator import ExtractOptions |
271 | | - # Use a generic dict schema since we cannot define a Pydantic model at runtime |
| 277 | + # Use a generic RootModel schema since we cannot define a custom Pydantic model at runtime |
272 | 278 | options = ExtractOptions( |
273 | 279 | instruction=instruction, |
274 | | - schema=dict, |
| 280 | + schema=GenericExtractSchema, |
275 | 281 | selector=selector or None, |
276 | 282 | ) |
277 | 283 | success, data = await asyncio.to_thread( |
278 | 284 | self._session.browser.operator.extract, options |
279 | 285 | ) |
| 286 | + if success and data: |
| 287 | + if hasattr(data, "model_dump"): |
| 288 | + data = data.model_dump() |
280 | 289 | return {"success": success, "data": data} |
281 | 290 |
|
282 | 291 | async def browser_observe(self, instruction: str, selector: str = "") -> dict: |
|
0 commit comments