hyperpocket 0.4.4__py3-none-any.whl → 0.4.5__py3-none-any.whl
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.
- hyperpocket/auth/kraken/README.md +8 -0
- hyperpocket/auth/kraken/__init__.py +0 -0
- hyperpocket/auth/kraken/context.py +14 -0
- hyperpocket/auth/kraken/keypair_context.py +17 -0
- hyperpocket/auth/kraken/keypair_handler.py +97 -0
- hyperpocket/auth/kraken/keypair_schema.py +10 -0
- hyperpocket/auth/provider.py +1 -0
- hyperpocket/auth/valyu/token_handler.py +1 -2
- hyperpocket/pocket_main.py +8 -5
- hyperpocket/server/auth/kraken.py +58 -0
- hyperpocket/util/json_schema_to_model.py +2 -2
- {hyperpocket-0.4.4.dist-info → hyperpocket-0.4.5.dist-info}/METADATA +1 -1
- {hyperpocket-0.4.4.dist-info → hyperpocket-0.4.5.dist-info}/RECORD +15 -8
- {hyperpocket-0.4.4.dist-info → hyperpocket-0.4.5.dist-info}/WHEEL +0 -0
- {hyperpocket-0.4.4.dist-info → hyperpocket-0.4.5.dist-info}/entry_points.txt +0 -0
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from hyperpocket.auth.context import AuthContext
|
2
|
+
|
3
|
+
|
4
|
+
class KrakenAuthContext(AuthContext):
|
5
|
+
def to_dict(self) -> dict[str, str]:
|
6
|
+
return {
|
7
|
+
'KRAKEN_API_KEY': self.detail["KRAKEN_API_KEY"],
|
8
|
+
'KRAKEN_API_SECRET': self.detail["KRAKEN_API_SECRET"],
|
9
|
+
}
|
10
|
+
|
11
|
+
def to_profiled_dict(self, profile: str) -> dict[str, str]:
|
12
|
+
return {
|
13
|
+
f"{profile.upper()}_{self._ACCESS_TOKEN_KEY}": self.access_token,
|
14
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from hyperpocket.auth.kraken.context import KrakenAuthContext
|
2
|
+
from hyperpocket.auth.kraken.keypair_schema import KrakenKeypairResponse
|
3
|
+
|
4
|
+
|
5
|
+
class KrakenKeypairAuthContext(KrakenAuthContext):
|
6
|
+
@classmethod
|
7
|
+
def from_kraken_keypair_response(cls, response: KrakenKeypairResponse):
|
8
|
+
description = f"Kraken Keypair Context logged in"
|
9
|
+
return cls(
|
10
|
+
access_token="",
|
11
|
+
detail={
|
12
|
+
"KRAKEN_API_KEY": response.kraken_api_key,
|
13
|
+
"KRAKEN_API_SECRET": response.kraken_api_secret,
|
14
|
+
},
|
15
|
+
description=description,
|
16
|
+
expires_at=None,
|
17
|
+
)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
from urllib.parse import urljoin, urlencode
|
3
|
+
|
4
|
+
from hyperpocket.auth import AuthProvider
|
5
|
+
from hyperpocket.auth.ahrefs.token_schema import AhrefsTokenRequest
|
6
|
+
from hyperpocket.auth.context import AuthContext
|
7
|
+
from hyperpocket.auth.handler import AuthHandlerInterface
|
8
|
+
from hyperpocket.auth.kraken.keypair_context import KrakenKeypairAuthContext
|
9
|
+
from hyperpocket.auth.kraken.keypair_schema import KrakenKeypairRequest, KrakenKeypairResponse
|
10
|
+
from hyperpocket.config import config
|
11
|
+
from hyperpocket.futures import FutureStore
|
12
|
+
|
13
|
+
|
14
|
+
class KrakeyKeypairAuthHandler(AuthHandlerInterface):
|
15
|
+
name: str = "kraken-keypair"
|
16
|
+
description: str = (
|
17
|
+
"This handler is used to authenticate users using the Kraken keypair."
|
18
|
+
)
|
19
|
+
scoped: bool = False
|
20
|
+
|
21
|
+
_TOKEN_URL: str = urljoin(
|
22
|
+
config().public_base_url + "/",
|
23
|
+
f"{config().callback_url_rewrite_prefix}/auth/kraken/keypair",
|
24
|
+
)
|
25
|
+
|
26
|
+
@staticmethod
|
27
|
+
def provider() -> AuthProvider:
|
28
|
+
return AuthProvider.KRAKEN
|
29
|
+
|
30
|
+
@staticmethod
|
31
|
+
def provider_default() -> bool:
|
32
|
+
return True
|
33
|
+
|
34
|
+
@staticmethod
|
35
|
+
def recommended_scopes() -> set[str]:
|
36
|
+
return set()
|
37
|
+
|
38
|
+
def prepare(
|
39
|
+
self,
|
40
|
+
auth_req: AhrefsTokenRequest,
|
41
|
+
thread_id: str,
|
42
|
+
profile: str,
|
43
|
+
future_uid: str,
|
44
|
+
*args,
|
45
|
+
**kwargs,
|
46
|
+
) -> str:
|
47
|
+
redirect_uri = urljoin(
|
48
|
+
config().public_base_url + "/",
|
49
|
+
f"{config().callback_url_rewrite_prefix}/auth/kraken/keypair/callback",
|
50
|
+
)
|
51
|
+
url = self._make_auth_url(
|
52
|
+
auth_req=auth_req, redirect_uri=redirect_uri, state=future_uid
|
53
|
+
)
|
54
|
+
FutureStore.create_future(
|
55
|
+
future_uid,
|
56
|
+
data={
|
57
|
+
"redirect_uri": redirect_uri,
|
58
|
+
"thread_id": thread_id,
|
59
|
+
"profile": profile,
|
60
|
+
},
|
61
|
+
)
|
62
|
+
|
63
|
+
return f"User needs to authenticate using the following URL: {url}"
|
64
|
+
|
65
|
+
async def authenticate(
|
66
|
+
self, auth_req: KrakenKeypairRequest, future_uid: str, *args, **kwargs
|
67
|
+
) -> AuthContext:
|
68
|
+
future_data = FutureStore.get_future(future_uid)
|
69
|
+
kraken_api_keypair = await future_data.future
|
70
|
+
|
71
|
+
response = KrakenKeypairResponse(
|
72
|
+
kraken_api_key=kraken_api_keypair["kraken_api_key"],
|
73
|
+
kraken_api_secret=kraken_api_keypair["kraken_api_secret"],
|
74
|
+
)
|
75
|
+
context = KrakenKeypairAuthContext.from_kraken_keypair_response(response)
|
76
|
+
|
77
|
+
return context
|
78
|
+
|
79
|
+
async def refresh(
|
80
|
+
self, auth_req: KrakenKeypairRequest, context: AuthContext, *args, **kwargs
|
81
|
+
) -> AuthContext:
|
82
|
+
raise Exception("Kraken keypair doesn't support refresh")
|
83
|
+
|
84
|
+
def _make_auth_url(
|
85
|
+
self, auth_req: KrakenKeypairRequest, redirect_uri: str, state: str
|
86
|
+
):
|
87
|
+
params = {
|
88
|
+
"redirect_uri": redirect_uri,
|
89
|
+
"state": state,
|
90
|
+
}
|
91
|
+
auth_url = f"{self._TOKEN_URL}?{urlencode(params)}"
|
92
|
+
return auth_url
|
93
|
+
|
94
|
+
def make_request(
|
95
|
+
self, auth_scopes: Optional[list[str]] = None, **kwargs
|
96
|
+
) -> KrakenKeypairRequest:
|
97
|
+
return KrakenKeypairRequest()
|
hyperpocket/auth/provider.py
CHANGED
@@ -2,7 +2,6 @@ from typing import Optional
|
|
2
2
|
from urllib.parse import urljoin, urlencode
|
3
3
|
|
4
4
|
from hyperpocket.auth import AuthProvider
|
5
|
-
from hyperpocket.auth.ahrefs.token_schema import AhrefsTokenRequest
|
6
5
|
from hyperpocket.auth.context import AuthContext
|
7
6
|
from hyperpocket.auth.handler import AuthHandlerInterface
|
8
7
|
from hyperpocket.auth.valyu.token_context import ValyuTokenAuthContext
|
@@ -37,7 +36,7 @@ class ValyuTokenAuthHandler(AuthHandlerInterface):
|
|
37
36
|
|
38
37
|
def prepare(
|
39
38
|
self,
|
40
|
-
auth_req:
|
39
|
+
auth_req: ValyuTokenRequest,
|
41
40
|
thread_id: str,
|
42
41
|
profile: str,
|
43
42
|
future_uid: str,
|
hyperpocket/pocket_main.py
CHANGED
@@ -30,10 +30,9 @@ class Pocket(object):
|
|
30
30
|
auth=auth,
|
31
31
|
)
|
32
32
|
except Exception as e:
|
33
|
-
|
34
|
-
self.server.refcnt_down(self._uid)
|
33
|
+
self.teardown()
|
35
34
|
pocket_logger.error(f"Failed to initialize pocket server. error : {e}")
|
36
|
-
self._teardown_server()
|
35
|
+
# self._teardown_server()
|
37
36
|
raise e
|
38
37
|
|
39
38
|
try:
|
@@ -337,15 +336,19 @@ class Pocket(object):
|
|
337
336
|
|
338
337
|
def _teardown_server(self):
|
339
338
|
self.server.teardown()
|
339
|
+
|
340
|
+
def teardown(self):
|
341
|
+
if hasattr(self, 'server'):
|
342
|
+
self.server.refcnt_down(self._uid)
|
340
343
|
|
341
344
|
def __enter__(self):
|
342
345
|
return self
|
343
346
|
|
344
347
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
345
|
-
self.
|
348
|
+
self.teardown()
|
346
349
|
|
347
350
|
def __del__(self):
|
348
|
-
self.
|
351
|
+
self.teardown()
|
349
352
|
|
350
353
|
def __getstate__(self):
|
351
354
|
state = self.__dict__.copy()
|
@@ -0,0 +1,58 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
|
3
|
+
from fastapi import APIRouter, Form
|
4
|
+
from starlette.responses import HTMLResponse, RedirectResponse
|
5
|
+
from hyperpocket.futures import FutureStore
|
6
|
+
from hyperpocket.server.auth.token import add_query_params
|
7
|
+
|
8
|
+
kraken_auth_router = APIRouter(prefix="/kraken")
|
9
|
+
|
10
|
+
@kraken_auth_router.get("/keypair", response_class=HTMLResponse)
|
11
|
+
async def keypair_form(redirect_uri: str, state: str = ""):
|
12
|
+
html = f"""
|
13
|
+
<html>
|
14
|
+
<body>
|
15
|
+
<h2>Enter Token</h2>
|
16
|
+
<form action="submit" method="post">
|
17
|
+
<input type="hidden" name="redirect_uri" value="{redirect_uri}">
|
18
|
+
<input type="hidden" name="state" value="{state}">
|
19
|
+
|
20
|
+
<label for="kraken_api_key">Kraken API Key:</label>
|
21
|
+
<input type="text" id="kraken_api_key" name="kraken_api_key" required>
|
22
|
+
|
23
|
+
<label for="kraken_api_secret">Kraken API Secret:</label>
|
24
|
+
<input type="text" id="kraken_api_secret" name="kraken_api_secret" required>
|
25
|
+
|
26
|
+
<button type="submit">submit</button>
|
27
|
+
</form>
|
28
|
+
</body>
|
29
|
+
</html>
|
30
|
+
"""
|
31
|
+
return HTMLResponse(content=html)
|
32
|
+
|
33
|
+
@kraken_auth_router.post("/submit", response_class=RedirectResponse)
|
34
|
+
async def submit_keypair(
|
35
|
+
kraken_api_key: str = Form(...),
|
36
|
+
kraken_api_secret: str = Form(...),
|
37
|
+
redirect_uri: str = Form(...),
|
38
|
+
state: str = Form(...),
|
39
|
+
):
|
40
|
+
new_callback_url = add_query_params(
|
41
|
+
redirect_uri, {
|
42
|
+
"kraken_api_key": kraken_api_key,
|
43
|
+
"kraken_api_secret": kraken_api_secret,
|
44
|
+
"state": state,
|
45
|
+
}
|
46
|
+
)
|
47
|
+
return RedirectResponse(url=new_callback_url, status_code=HTTPStatus.SEE_OTHER)
|
48
|
+
|
49
|
+
@kraken_auth_router.get("/keypair/callback")
|
50
|
+
async def kraken_keypair_callback(state: str, kraken_api_key: str, kraken_api_secret: str):
|
51
|
+
try:
|
52
|
+
FutureStore.resolve_future(state, {
|
53
|
+
"kraken_api_key": kraken_api_key,
|
54
|
+
"kraken_api_secret": kraken_api_secret,
|
55
|
+
})
|
56
|
+
except ValueError:
|
57
|
+
return HTMLResponse(content="failed")
|
58
|
+
return HTMLResponse(content="success")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Type, Union
|
1
|
+
from typing import Type, Union, Optional
|
2
2
|
|
3
3
|
from pydantic import BaseModel, Field, create_model
|
4
4
|
|
@@ -42,7 +42,7 @@ def json_schema_to_model(
|
|
42
42
|
fields[property_name] = (field_type, Field(description=field_description))
|
43
43
|
else:
|
44
44
|
fields[property_name] = (
|
45
|
-
field_type,
|
45
|
+
Optional[field_type],
|
46
46
|
Field(default=field_default, description=field_description),
|
47
47
|
)
|
48
48
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.5
|
4
4
|
Summary: Building AI agent with hyperpocket tool in a flash
|
5
5
|
Project-URL: Homepage, https://vessl-ai.github.io/hyperpocket
|
6
6
|
Project-URL: Repository, https://github.com/vessl-ai/hyperpocket
|
@@ -3,14 +3,14 @@ hyperpocket/builtin.py,sha256=SOrVrNjoKadDMksfB1rt6pKreJFzHG2YGBsLGVsg72c,2385
|
|
3
3
|
hyperpocket/constants.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hyperpocket/pocket_auth.py,sha256=VzpGpHOOQIiEgrk1sYg5DYa5WYV6gRQmFlm8Kb2C9V0,17611
|
5
5
|
hyperpocket/pocket_core.py,sha256=WkY7Dp7KcJTORAFNuxDbZ5PDgicRANUtKkpZmI5gg6s,10021
|
6
|
-
hyperpocket/pocket_main.py,sha256=
|
6
|
+
hyperpocket/pocket_main.py,sha256=_YoxA01tFqnU3MavJndiXn1cKYWZ7z9_v0IihCzlHmo,10228
|
7
7
|
hyperpocket/prompts.py,sha256=N1bCzCLZvGUVhH1Vn_cgeBPsdY3MdIU7ZGqVgexoj5E,472
|
8
8
|
hyperpocket/tool_like.py,sha256=lUk9kUHPUmugqHCLbnWflKtZbCwtgcoYWtqGqUQtV38,187
|
9
9
|
hyperpocket/auth/README.md,sha256=zn4QqnFZCA_4X3x8Wb6lE3OP5otYxpByZaCiUkBvaNs,11562
|
10
10
|
hyperpocket/auth/__init__.py,sha256=pO8M6SAuq0EPqi848_Iy650wqaLekx98e3RRnEAM_r0,607
|
11
11
|
hyperpocket/auth/context.py,sha256=m-j2gDYUKBMsiakLHsu9thhM4dYyFiXP0Wp0S_iC0bU,1303
|
12
12
|
hyperpocket/auth/handler.py,sha256=5cusl9ANEyG3gORVFjqh709txC0alw6eKtxgV6wjf6k,6683
|
13
|
-
hyperpocket/auth/provider.py,sha256=
|
13
|
+
hyperpocket/auth/provider.py,sha256=qZGenhTsL8vqd9zmUMM52TVlmdNNOTsmLmCPmZshUNg,2103
|
14
14
|
hyperpocket/auth/schema.py,sha256=pl4oRTNj8PdqQg6UVPWf8ei2uYQ4DtOmmD58cVFMYQw,537
|
15
15
|
hyperpocket/auth/activeloop/README.md,sha256=xp8n0itbY9VNt8XEvCAE4Ealvj4uf_f1uSZyWG4Q5FE,172
|
16
16
|
hyperpocket/auth/activeloop/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -240,6 +240,12 @@ hyperpocket/auth/klaviyo/context.py,sha256=JLALnthzihgMZkAQhKpzf8X07iHt0Iz2lEYsD
|
|
240
240
|
hyperpocket/auth/klaviyo/token_context.py,sha256=OwckVoIbJaNH65WmIgi7C03TCHR0eCInA20RYmNX9Vc,455
|
241
241
|
hyperpocket/auth/klaviyo/token_handler.py,sha256=0IiLFRhMhAm2LAMSGhkOoIoSiBbx0b776YTfB9VlJpw,2938
|
242
242
|
hyperpocket/auth/klaviyo/token_schema.py,sha256=-x9e36JdNkMmgjRkXzzmpDBdeLsA_yA1wS2svhqNqlI,276
|
243
|
+
hyperpocket/auth/kraken/README.md,sha256=QeSzmWSS86cXG1CmhAnGWLaVAeAo4ZpMWYwJ8OlCOMg,148
|
244
|
+
hyperpocket/auth/kraken/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
245
|
+
hyperpocket/auth/kraken/context.py,sha256=LNa6UjosOg880PmBinubg8pHqjQWFqJ5sKBklZrhD38,455
|
246
|
+
hyperpocket/auth/kraken/keypair_context.py,sha256=KyyJOlCE2wo3EIFFz5DGmHCPNb0tBOICvma9KrPyJHA,624
|
247
|
+
hyperpocket/auth/kraken/keypair_handler.py,sha256=JdYLFV-S9IcCHQuKa2xYLh7oYAmxO29GQrcUvvmik_c,3123
|
248
|
+
hyperpocket/auth/kraken/keypair_schema.py,sha256=xpZqmIg743Gf0OOfq9KNOg6Y-q5Yv67xOf9uBL7xq-0,242
|
243
249
|
hyperpocket/auth/lever/README.md,sha256=00OuO_5cJ7RwZ4ZuWzYonSaQwnO4BYYycH3IvbBNgPM,166
|
244
250
|
hyperpocket/auth/lever/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
245
251
|
hyperpocket/auth/lever/context.py,sha256=rNqjJyM4AToXEKT9DDKMdux2xk5vhwy6B6Fg84YCPIg,425
|
@@ -426,7 +432,7 @@ hyperpocket/auth/valyu/README.md,sha256=QeSzmWSS86cXG1CmhAnGWLaVAeAo4ZpMWYwJ8OlC
|
|
426
432
|
hyperpocket/auth/valyu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
427
433
|
hyperpocket/auth/valyu/context.py,sha256=He1n_Yo9CNOoOG_2ESKEJi8F5OphLbMruxK20zgUDHA,427
|
428
434
|
hyperpocket/auth/valyu/token_context.py,sha256=0FKxYQUu4Zvu2gywcNdvRIEto4k_Iff9qQt_hE3-gd4,437
|
429
|
-
hyperpocket/auth/valyu/token_handler.py,sha256=
|
435
|
+
hyperpocket/auth/valyu/token_handler.py,sha256=iDLEkB3dG5Ag8jm7xP7bkLL3wElfU6Xdyxjwr7P7YL8,2864
|
430
436
|
hyperpocket/auth/valyu/token_schema.py,sha256=1yaf4fSREnTpvwmzKDrVh1oBxrwPSRnRPbKPOub-iPM,207
|
431
437
|
hyperpocket/auth/wandb/README.md,sha256=Zsohbn6yELf8pfhBddDRm_iqs4NgQBZZhnC00yP5mVE,252
|
432
438
|
hyperpocket/auth/wandb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -533,6 +539,7 @@ hyperpocket/server/auth/heygen.py,sha256=dtHq_CkBkDFsj2QfebpLRuFIByVE9PXX3fe3z8P
|
|
533
539
|
hyperpocket/server/auth/hubspot.py,sha256=6ApquQXemvjuFattNDALrz3932w20rFEOZaz_71bvBg,722
|
534
540
|
hyperpocket/server/auth/jira.py,sha256=xYzQ7Ve-z90wvChoVF_7rWuez9vcjHXB3FdZEVshSXo,703
|
535
541
|
hyperpocket/server/auth/klaviyo.py,sha256=5EShL4tD5JpeYh7lserpv_PFEC-fyn4QpKNNP8RUVJo,445
|
542
|
+
hyperpocket/server/auth/kraken.py,sha256=vhKhEI8NQiaMOBWbw1dROBBOCia91AYXYRozX8TyDds,2146
|
536
543
|
hyperpocket/server/auth/lever.py,sha256=AJjd852iUgfbudd-ILknC7HykgaKBKlMWfEUIWZ81ok,437
|
537
544
|
hyperpocket/server/auth/lever_sandbox.py,sha256=RrhBvEZUAfj26Nj7Ic5MQAauyMmhT9rE__tkMhmAT6Y,469
|
538
545
|
hyperpocket/server/auth/linear.py,sha256=vUW4TEqdOYqAyx9YLJC4-dVldPTDuIPXRvoo-a89ai8,988
|
@@ -593,8 +600,8 @@ hyperpocket/util/flatten_json_schema.py,sha256=iuNBEmMSKFtPi-uqo6fb3RWN0koHOAihW
|
|
593
600
|
hyperpocket/util/function_to_model.py,sha256=TXUs-qPbzL8C9-qqpz4Ad4D9MOPP61n_p0iPU6SoBeM,2318
|
594
601
|
hyperpocket/util/generate_slug.py,sha256=gwwf9gfTlqribrvybMQQj7VIHX5FspVoTm5-EYH-X74,150
|
595
602
|
hyperpocket/util/get_objects_from_subpackage.py,sha256=4mR_S8eaJSdU68YfCkiXeIcXxb6q7LjFGsY_IHeNIZw,929
|
596
|
-
hyperpocket/util/json_schema_to_model.py,sha256=
|
597
|
-
hyperpocket-0.4.
|
598
|
-
hyperpocket-0.4.
|
599
|
-
hyperpocket-0.4.
|
600
|
-
hyperpocket-0.4.
|
603
|
+
hyperpocket/util/json_schema_to_model.py,sha256=nc5AmnqkrdeFLELu-7_O9sEAaUaD8_KGlvIMDRobt-4,3751
|
604
|
+
hyperpocket-0.4.5.dist-info/METADATA,sha256=vFdzt3Dz_z0naddvIBneuu-KAqGYi1lwtnUaYnAKUmk,13074
|
605
|
+
hyperpocket-0.4.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
606
|
+
hyperpocket-0.4.5.dist-info/entry_points.txt,sha256=KpBleaYr0SaENXOa-dFvJ_cvFCHYFEQ4LMl11ShAcBI,61
|
607
|
+
hyperpocket-0.4.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|