11import asyncio
2+ from typing import Union
23
34from hyperbrowser .models .consts import POLLING_ATTEMPTS
5+ from ....models .params import (
6+ coerce_to_model ,
7+ GetCrawlJobParamsDict ,
8+ StartCrawlJobParamsDict ,
9+ )
410from ....models .crawl import (
511 CrawlJobResponse ,
612 CrawlJobStatus ,
@@ -16,7 +22,10 @@ class CrawlManager:
1622 def __init__ (self , client ):
1723 self ._client = client
1824
19- async def start (self , params : StartCrawlJobParams ) -> StartCrawlJobResponse :
25+ async def start (
26+ self , params : Union [StartCrawlJobParams , StartCrawlJobParamsDict ]
27+ ) -> StartCrawlJobResponse :
28+ params = coerce_to_model (StartCrawlJobParams , params )
2029 response = await self ._client .transport .post (
2130 self ._client ._build_url ("/crawl" ),
2231 data = params .model_dump (exclude_none = True , by_alias = True ),
@@ -30,16 +39,21 @@ async def get_status(self, job_id: str) -> CrawlJobStatusResponse:
3039 return CrawlJobStatusResponse (** response .data )
3140
3241 async def get (
33- self , job_id : str , params : GetCrawlJobParams = GetCrawlJobParams ()
42+ self ,
43+ job_id : str ,
44+ params : Union [GetCrawlJobParams , GetCrawlJobParamsDict ] = GetCrawlJobParams (),
3445 ) -> CrawlJobResponse :
46+ params = coerce_to_model (GetCrawlJobParams , params )
3547 response = await self ._client .transport .get (
3648 self ._client ._build_url (f"/crawl/{ job_id } " ),
3749 params = params .model_dump (exclude_none = True , by_alias = True ),
3850 )
3951 return CrawlJobResponse (** response .data )
4052
4153 async def start_and_wait (
42- self , params : StartCrawlJobParams , return_all_pages : bool = True
54+ self ,
55+ params : Union [StartCrawlJobParams , StartCrawlJobParamsDict ],
56+ return_all_pages : bool = True ,
4357 ) -> CrawlJobResponse :
4458 job_start_resp = await self .start (params )
4559 job_id = job_start_resp .job_id
0 commit comments