Skip to content

Commit e16ecd6

Browse files
committed
feat: add fork_profile method on sessions for on-the-fly profile forking
Adds UpdateSessionForkProfileParams, UpdateSessionForkProfileResponse models and sessions.fork_profile(id, params) method on both sync and async managers. Calls PUT /session/:id/update with type 'fork' to create a new independent profile mid-session without mutating the source.
1 parent 2c40360 commit e16ecd6

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

‎hyperbrowser/client/managers/async_manager/session.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
UpdateSessionScreenParams,
2222
UpdateSessionSolveCaptchasParams,
2323
UpdateSessionSolveCaptchasResponse,
24+
UpdateSessionForkProfileParams,
25+
UpdateSessionForkProfileResponse,
2426
SessionGetParams,
2527
)
2628

@@ -264,6 +266,24 @@ async def stop_captcha_solving(self, id: str) -> UpdateSessionSolveCaptchasRespo
264266
)
265267
return UpdateSessionSolveCaptchasResponse(**response.data)
266268

269+
async def fork_profile(
270+
self,
271+
id: str,
272+
params: UpdateSessionForkProfileParams = UpdateSessionForkProfileParams(),
273+
) -> UpdateSessionForkProfileResponse:
274+
"""Fork the session's profile on the fly. Creates a new independent profile;
275+
the original source profile is never mutated."""
276+
response = await self._client.transport.put(
277+
self._client._build_url(f"/session/{id}/update"),
278+
data={
279+
"type": "fork",
280+
"params": params.model_dump(
281+
exclude_none=True, by_alias=True
282+
),
283+
},
284+
)
285+
return UpdateSessionForkProfileResponse(**response.data)
286+
267287
def _warn_update_profile_params_boolean_deprecated(self) -> None:
268288
if SessionManager._has_warned_update_profile_params_boolean_deprecated:
269289
return

‎hyperbrowser/client/managers/sync_manager/session.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
UpdateSessionScreenParams,
2121
UpdateSessionSolveCaptchasParams,
2222
UpdateSessionSolveCaptchasResponse,
23+
UpdateSessionForkProfileParams,
24+
UpdateSessionForkProfileResponse,
2325
SessionGetParams,
2426
)
2527

@@ -259,6 +261,24 @@ def stop_captcha_solving(self, id: str) -> UpdateSessionSolveCaptchasResponse:
259261
)
260262
return UpdateSessionSolveCaptchasResponse(**response.data)
261263

264+
def fork_profile(
265+
self,
266+
id: str,
267+
params: UpdateSessionForkProfileParams = UpdateSessionForkProfileParams(),
268+
) -> UpdateSessionForkProfileResponse:
269+
"""Fork the session's profile on the fly. Creates a new independent profile;
270+
the original source profile is never mutated."""
271+
response = self._client.transport.put(
272+
self._client._build_url(f"/session/{id}/update"),
273+
data={
274+
"type": "fork",
275+
"params": params.model_dump(
276+
exclude_none=True, by_alias=True
277+
),
278+
},
279+
)
280+
return UpdateSessionForkProfileResponse(**response.data)
281+
262282
def _warn_update_profile_params_boolean_deprecated(self) -> None:
263283
if SessionManager._has_warned_update_profile_params_boolean_deprecated:
264284
return

‎hyperbrowser/models/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@
270270
CaptchaEvaluationTarget,
271271
CaptchaEvaluationType,
272272
UpdateSessionProfileParams,
273+
UpdateSessionForkProfileParams,
274+
UpdateSessionForkProfileResponse,
273275
UpdateSessionProxyLocationParams,
274276
UpdateSessionProxyParams,
275277
UpdateSessionScreenParams,
@@ -541,6 +543,8 @@
541543
"CaptchaEvaluationTarget",
542544
"CaptchaEvaluationType",
543545
"UpdateSessionProfileParams",
546+
"UpdateSessionForkProfileParams",
547+
"UpdateSessionForkProfileResponse",
544548
"UpdateSessionProxyLocationParams",
545549
"UpdateSessionProxyParams",
546550
"UpdateSessionScreenParams",

‎hyperbrowser/models/session.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ class UpdateSessionProfileParams(BaseModel):
7979
)
8080

8181

82+
class UpdateSessionForkProfileParams(BaseModel):
83+
"""
84+
Parameters for forking a session's profile on the fly.
85+
Creates a new independent profile; the original source profile is never mutated.
86+
"""
87+
88+
model_config = ConfigDict(
89+
populate_by_alias=True,
90+
)
91+
92+
name: Optional[str] = Field(default=None, serialization_alias="name")
93+
94+
95+
class UpdateSessionForkProfileResponse(BasicResponse):
96+
"""
97+
Response from a session profile fork operation.
98+
"""
99+
100+
forked_profile_id: Optional[str] = Field(
101+
default=None, alias="forkedProfileId"
102+
)
103+
104+
82105
class UpdateSessionProxyLocationParams(BaseModel):
83106
"""
84107
Managed proxy geolocation overrides for a running session.

0 commit comments

Comments
 (0)