hyperpocket 0.3.5__py3-none-any.whl → 0.3.7__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.
@@ -70,6 +70,8 @@ class AuthProvider(Enum):
70
70
  LINKEDIN = "linkedin"
71
71
  WANDB = "wandb"
72
72
  APITOKEN = "apitoken"
73
+ ZINC = "zinc"
74
+ SEMANTIC_SCHOLAR = "semantic_scholar"
73
75
 
74
76
  @classmethod
75
77
  def get_auth_provider(cls, auth_provider_name: str) -> "AuthProvider":
File without changes
@@ -0,0 +1,12 @@
1
+
2
+ from hyperpocket.auth.context import AuthContext
3
+ class SemanticScholarAuthContext(AuthContext):
4
+ _ACCESS_TOKEN_KEY: str = "SEMANTIC_SCHOLAR_TOKEN"
5
+ def to_dict(self) -> dict[str, str]:
6
+ return {
7
+ self._ACCESS_TOKEN_KEY: self.access_token,
8
+ }
9
+ def to_profiled_dict(self, profile: str) -> dict[str, str]:
10
+ return {
11
+ f"{profile.upper()}_{self._ACCESS_TOKEN_KEY}": self.access_token,
12
+ }
@@ -0,0 +1,11 @@
1
+ from hyperpocket.auth.semantic_scholar.context import SemanticScholarAuthContext
2
+ from hyperpocket.auth.semantic_scholar.token_schema import SemanticScholarTokenResponse
3
+ class SemanticScholarTokenAuthContext(SemanticScholarAuthContext):
4
+ @classmethod
5
+ def from_semantic_scholar_token_response(cls, response: SemanticScholarTokenResponse):
6
+ description = f'SemanticScholar Token Context logged in'
7
+ return cls(
8
+ access_token=response.access_token,
9
+ description=description,
10
+ expires_at=None
11
+ )
@@ -0,0 +1,64 @@
1
+ from typing import Optional
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from hyperpocket.auth import AuthProvider
5
+ from hyperpocket.auth.context import AuthContext
6
+ from hyperpocket.auth.handler import AuthHandlerInterface, AuthenticateRequest
7
+ from hyperpocket.auth.semantic_scholar.token_context import SemanticScholarTokenAuthContext
8
+ from hyperpocket.auth.semantic_scholar.token_schema import SemanticScholarTokenResponse, SemanticScholarTokenRequest
9
+ from hyperpocket.config import config
10
+ from hyperpocket.futures import FutureStore
11
+
12
+
13
+ class SemanticScholarTokenAuthHandler(AuthHandlerInterface):
14
+ name: str = "semantic-scholar-token"
15
+ description: str = "This handler is used to authenticate users using the SemanticScholar token."
16
+ scoped: bool = False
17
+
18
+ _TOKEN_URL: str = urljoin(config().public_base_url + "/", f"{config().callback_url_rewrite_prefix}/auth/token")
19
+
20
+ @staticmethod
21
+ def provider() -> AuthProvider:
22
+ return AuthProvider.SEMANTIC_SCHOLAR
23
+
24
+ @staticmethod
25
+ def recommended_scopes() -> set[str]:
26
+ return set()
27
+
28
+ def prepare(self, auth_req: SemanticScholarTokenRequest, thread_id: str, profile: str,
29
+ future_uid: str, *args, **kwargs) -> str:
30
+ redirect_uri = urljoin(
31
+ config().public_base_url + "/",
32
+ f"{config().callback_url_rewrite_prefix}/auth/semantic_scholar/token/callback",
33
+ )
34
+ url = self._make_auth_url(auth_req=auth_req, redirect_uri=redirect_uri, state=future_uid)
35
+ FutureStore.create_future(future_uid, data={
36
+ "redirect_uri": redirect_uri,
37
+ "thread_id": thread_id,
38
+ "profile": profile,
39
+ })
40
+
41
+ return f'User needs to authenticate using the following URL: {url}'
42
+
43
+ async def authenticate(self, auth_req: SemanticScholarTokenRequest, future_uid: str, *args, **kwargs) -> AuthContext:
44
+ future_data = FutureStore.get_future(future_uid)
45
+ access_token = await future_data.future
46
+
47
+ response = SemanticScholarTokenResponse(access_token=access_token)
48
+ context = SemanticScholarTokenAuthContext.from_semantic_scholar_token_response(response)
49
+
50
+ return context
51
+
52
+ async def refresh(self, auth_req: SemanticScholarTokenRequest, context: AuthContext, *args, **kwargs) -> AuthContext:
53
+ raise Exception("SemanticScholar token doesn't support refresh")
54
+
55
+ def _make_auth_url(self, auth_req: SemanticScholarTokenRequest, redirect_uri: str, state: str):
56
+ params = {
57
+ "redirect_uri": redirect_uri,
58
+ "state": state,
59
+ }
60
+ auth_url = f"{self._TOKEN_URL}?{urlencode(params)}"
61
+ return auth_url
62
+
63
+ def make_request(self, auth_scopes: Optional[list[str]] = None, **kwargs) -> SemanticScholarTokenRequest:
64
+ return SemanticScholarTokenRequest()
@@ -0,0 +1,7 @@
1
+ from typing import List, Optional
2
+ from pydantic import BaseModel
3
+ from hyperpocket.auth.schema import AuthenticateRequest, AuthenticateResponse
4
+ class SemanticScholarTokenRequest(AuthenticateRequest):
5
+ pass
6
+ class SemanticScholarTokenResponse(AuthenticateResponse):
7
+ access_token: str
File without changes
@@ -0,0 +1,12 @@
1
+
2
+ from hyperpocket.auth.context import AuthContext
3
+ class ZincAuthContext(AuthContext):
4
+ _ACCESS_TOKEN_KEY: str = "ZINC_TOKEN"
5
+ def to_dict(self) -> dict[str, str]:
6
+ return {
7
+ self._ACCESS_TOKEN_KEY: self.access_token,
8
+ }
9
+ def to_profiled_dict(self, profile: str) -> dict[str, str]:
10
+ return {
11
+ f"{profile.upper()}_{self._ACCESS_TOKEN_KEY}": self.access_token,
12
+ }
@@ -0,0 +1,11 @@
1
+ from hyperpocket.auth.zinc.context import ZincAuthContext
2
+ from hyperpocket.auth.zinc.token_schema import ZincTokenResponse
3
+ class ZincTokenAuthContext(ZincAuthContext):
4
+ @classmethod
5
+ def from_zinc_token_response(cls, response: ZincTokenResponse):
6
+ description = f'Zinc Token Context logged in'
7
+ return cls(
8
+ access_token=response.access_token,
9
+ description=description,
10
+ expires_at=None
11
+ )
@@ -0,0 +1,64 @@
1
+ from typing import Optional
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from hyperpocket.auth import AuthProvider
5
+ from hyperpocket.auth.context import AuthContext
6
+ from hyperpocket.auth.handler import AuthHandlerInterface, AuthenticateRequest
7
+ from hyperpocket.auth.zinc.token_context import ZincTokenAuthContext
8
+ from hyperpocket.auth.zinc.token_schema import ZincTokenResponse, ZincTokenRequest
9
+ from hyperpocket.config import config
10
+ from hyperpocket.futures import FutureStore
11
+
12
+
13
+ class ZincTokenAuthHandler(AuthHandlerInterface):
14
+ name: str = "zinc-token"
15
+ description: str = "This handler is used to authenticate users using the Zinc token."
16
+ scoped: bool = False
17
+
18
+ _TOKEN_URL: str = urljoin(config().public_base_url + "/", f"{config().callback_url_rewrite_prefix}/auth/token")
19
+
20
+ @staticmethod
21
+ def provider() -> AuthProvider:
22
+ return AuthProvider.ZINC
23
+
24
+ @staticmethod
25
+ def recommended_scopes() -> set[str]:
26
+ return set()
27
+
28
+ def prepare(self, auth_req: ZincTokenRequest, thread_id: str, profile: str,
29
+ future_uid: str, *args, **kwargs) -> str:
30
+ redirect_uri = urljoin(
31
+ config().public_base_url + "/",
32
+ f"{config().callback_url_rewrite_prefix}/auth/zinc/token/callback",
33
+ )
34
+ url = self._make_auth_url(auth_req=auth_req, redirect_uri=redirect_uri, state=future_uid)
35
+ FutureStore.create_future(future_uid, data={
36
+ "redirect_uri": redirect_uri,
37
+ "thread_id": thread_id,
38
+ "profile": profile,
39
+ })
40
+
41
+ return f'User needs to authenticate using the following URL: {url}'
42
+
43
+ async def authenticate(self, auth_req: ZincTokenRequest, future_uid: str, *args, **kwargs) -> AuthContext:
44
+ future_data = FutureStore.get_future(future_uid)
45
+ access_token = await future_data.future
46
+
47
+ response = ZincTokenResponse(access_token=access_token)
48
+ context = ZincTokenAuthContext.from_zinc_token_response(response)
49
+
50
+ return context
51
+
52
+ async def refresh(self, auth_req: ZincTokenRequest, context: AuthContext, *args, **kwargs) -> AuthContext:
53
+ raise Exception("Zinc token doesn't support refresh")
54
+
55
+ def _make_auth_url(self, auth_req: ZincTokenRequest, redirect_uri: str, state: str):
56
+ params = {
57
+ "redirect_uri": redirect_uri,
58
+ "state": state,
59
+ }
60
+ auth_url = f"{self._TOKEN_URL}?{urlencode(params)}"
61
+ return auth_url
62
+
63
+ def make_request(self, auth_scopes: Optional[list[str]] = None, **kwargs) -> ZincTokenRequest:
64
+ return ZincTokenRequest()
@@ -0,0 +1,7 @@
1
+ from typing import List, Optional
2
+ from pydantic import BaseModel
3
+ from hyperpocket.auth.schema import AuthenticateRequest, AuthenticateResponse
4
+ class ZincTokenRequest(AuthenticateRequest):
5
+ pass
6
+ class ZincTokenResponse(AuthenticateResponse):
7
+ access_token: str
@@ -0,0 +1,27 @@
1
+ from fastapi import APIRouter
2
+ from starlette.responses import HTMLResponse
3
+ from hyperpocket.futures import FutureStore
4
+
5
+ semantic_scholar_auth_router = APIRouter(
6
+ prefix="/semantic_scholar"
7
+ )
8
+
9
+
10
+ @semantic_scholar_auth_router.get("/oauth2/callback")
11
+ async def semantic_scholar_oauth2_callback(state: str, code: str):
12
+ try:
13
+ FutureStore.resolve_future(state, code)
14
+ except ValueError:
15
+ return HTMLResponse(content="failed")
16
+
17
+ return HTMLResponse(content="success")
18
+
19
+
20
+ @semantic_scholar_auth_router.get("/token/callback")
21
+ async def semantic_scholar_token_callback(state: str, token: str):
22
+ try:
23
+ FutureStore.resolve_future(state, token)
24
+ except ValueError:
25
+ return HTMLResponse(content="failed")
26
+
27
+ return HTMLResponse(content="success")
@@ -0,0 +1,27 @@
1
+ from fastapi import APIRouter
2
+ from starlette.responses import HTMLResponse
3
+ from hyperpocket.futures import FutureStore
4
+
5
+ zinc_auth_router = APIRouter(
6
+ prefix="/zinc"
7
+ )
8
+
9
+
10
+ @zinc_auth_router.get("/oauth2/callback")
11
+ async def zinc_oauth2_callback(state: str, code: str):
12
+ try:
13
+ FutureStore.resolve_future(state, code)
14
+ except ValueError:
15
+ return HTMLResponse(content="failed")
16
+
17
+ return HTMLResponse(content="success")
18
+
19
+
20
+ @zinc_auth_router.get("/token/callback")
21
+ async def zinc_token_callback(state: str, token: str):
22
+ try:
23
+ FutureStore.resolve_future(state, token)
24
+ except ValueError:
25
+ return HTMLResponse(content="failed")
26
+
27
+ return HTMLResponse(content="success")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperpocket
3
- Version: 0.3.5
3
+ Version: 0.3.7
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
@@ -10,7 +10,7 @@ hyperpocket/auth/README.md,sha256=zn4QqnFZCA_4X3x8Wb6lE3OP5otYxpByZaCiUkBvaNs,11
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=X2NseyRS_48Hwi1yUwezbvHkQZZUleqtF_1Z_XhnzzE,1975
13
+ hyperpocket/auth/provider.py,sha256=bTJn6Atm4E9nm9vf8Ggudf7-XxAWMOIPo6xiZnGqDvM,2035
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
@@ -360,6 +360,11 @@ hyperpocket/auth/salesforce/context.py,sha256=JuxwHIBfubOi_7VWWy0d9tKN3XOV9bT2FY
360
360
  hyperpocket/auth/salesforce/oauth2_context.py,sha256=7STo2n6yIHK-QHeFGf0t7MSxlJwCwvX-tuB34mi3vRU,1088
361
361
  hyperpocket/auth/salesforce/oauth2_handler.py,sha256=2zZ58usN5DjxBbrynhN9DPMr2Vzmm8iAN8TpHEKuf-c,4717
362
362
  hyperpocket/auth/salesforce/oauth2_schema.py,sha256=XY26_-pxxD8XMvks34-_G-FJb2xitFDSesIiuztw628,477
363
+ hyperpocket/auth/semantic_scholar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
364
+ hyperpocket/auth/semantic_scholar/context.py,sha256=wQzQLW0Hkv4DW1VC1bD6XZ4UsZw07f4rnuPmZFZKlac,442
365
+ hyperpocket/auth/semantic_scholar/token_context.py,sha256=t1F5iF0-Jte2pvFP5C74lL_OLH3CwywerikPmD1D-9I,551
366
+ hyperpocket/auth/semantic_scholar/token_handler.py,sha256=FTUBLEorMPJ8BjdL877SHRwIJ78dJK9ZeM2CpN511Lw,2800
367
+ hyperpocket/auth/semantic_scholar/token_schema.py,sha256=Kw8H6DozQ_NGekODhPvWXr5HX73HbDJCP7YSh2WkKX8,287
363
368
  hyperpocket/auth/sendgrid/README.md,sha256=u_5Cg6OGV2EvwvV_jQp0ZmY1wvjuTAcVPaw_1W0k-WI,305
364
369
  hyperpocket/auth/sendgrid/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
365
370
  hyperpocket/auth/sendgrid/context.py,sha256=uaJoo7lS2KEtab9fUC1FgECe3kH2EqEfdnXyBWZ6iKU,431
@@ -435,6 +440,11 @@ hyperpocket/auth/x/context.py,sha256=5Ur9GI8og49E-8FToKlqR3TtPn6vWAdu1boLqYxJL8k
435
440
  hyperpocket/auth/x/oauth2_context.py,sha256=q2HB14WENz2LU7Qe7KkE7-AtsEOtzXIj7n8alykac8M,955
436
441
  hyperpocket/auth/x/oauth2_handler.py,sha256=kEnsbL1YIeIQUlMVPIZYqOswk9_t-sNGiaixj43M1Yc,5634
437
442
  hyperpocket/auth/x/oauth2_schema.py,sha256=PKeaHccpxGLJjEd8RxP2wVcrIPCE-W9HEtP8EMzU4To,401
443
+ hyperpocket/auth/zinc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
444
+ hyperpocket/auth/zinc/context.py,sha256=nsjUnNcOVUB2C3tjN2jT94dWPI9wRagtpyrV452pieY,419
445
+ hyperpocket/auth/zinc/token_context.py,sha256=CG0aVRO-xEIk39zHLu2-IF46VMrKnKlxg4mqTtv2H-s,449
446
+ hyperpocket/auth/zinc/token_handler.py,sha256=S0if3Zb8TFRP52XwHpanm_AbthkojLmsnKaeJU8RyxA,2574
447
+ hyperpocket/auth/zinc/token_schema.py,sha256=18C50Wnr9Vq-YJBS4qzjUotoEJy5zLWqFKK2G7nmcMg,265
438
448
  hyperpocket/auth/zoom/README.md,sha256=xzfcoAiWyFxUdHfOgnXwMXygt_RkaAsaZuCH3ylTcVQ,401
439
449
  hyperpocket/auth/zoom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
440
450
  hyperpocket/auth/zoom/context.py,sha256=26S_aMbvtdzXYoXdDNpnHGJ-tmMcOSt0F15cMYwQZaM,423
@@ -533,6 +543,7 @@ hyperpocket/server/auth/posthog.py,sha256=Cdi9OeNn1icCeokrTbLc02oA2UMk-kx6nFTlYV
533
543
  hyperpocket/server/auth/ravenseotools.py,sha256=StkE9c4nrm-9ftzbaqQ8gNb8lN_N2iIYw7Hn-3o7Cb4,469
534
544
  hyperpocket/server/auth/reddit.py,sha256=UloBQNEdhU1_eXaF8qVSQ5ivq5xtWINsHvBDGwgFSLM,443
535
545
  hyperpocket/server/auth/salesforce.py,sha256=MxwrS_2XkMJXA1UuHayHBHKVGgdBA-zmOrkSJit0XJY,739
546
+ hyperpocket/server/auth/semantic_scholar.py,sha256=H4FSPjHiZqLPI4eZU-zfjBt4nY3o4OoFtOhGZpP-9Ik,780
536
547
  hyperpocket/server/auth/sendgrid.py,sha256=rOMHV76lVArwsFLuVrJ-nbC4oR-Fq3Xk-Yu11tDl8nA,449
537
548
  hyperpocket/server/auth/serpapi.py,sha256=gHqEC93Sw3JI4-s9zxlL3FrvPEiGPLq5U7IaOKuXVWQ,445
538
549
  hyperpocket/server/auth/slack.py,sha256=frMNtBEfe3fbeNzsQ8udapeau45NZmS8guATmS46qyA,710
@@ -546,6 +557,7 @@ hyperpocket/server/auth/trello.py,sha256=1T3ez62h8-KMvu2Zj1Tyv2afgqLUbtG2LM4QbIS
546
557
  hyperpocket/server/auth/wandb.py,sha256=jfwg-lQVrr5TgEL7QETnaFucDvi057SJvVZlBe7cOqQ,709
547
558
  hyperpocket/server/auth/workiom.py,sha256=0apFB5-3rmcJaQeEl1_XZ_QlsZORdq8kixJBGkTpZ3Y,445
548
559
  hyperpocket/server/auth/x.py,sha256=CYCD_ajBY6Jt04E2bSEBZFRRIUZmNjF2gn6F0ZV5XuA,450
560
+ hyperpocket/server/auth/zinc.py,sha256=xgVV5lWP6YSEHTCmH0gipG5lh4Wvf716tHTnOvTTj3w,708
549
561
  hyperpocket/server/auth/zoom.py,sha256=kWp4MB4i9FKMA4ZYcj4g4_90Y1ZMEoAQTTjbb0rsMRs,703
550
562
  hyperpocket/server/tool/__init__.py,sha256=khNLe3H2W7WXKQlHjXuuvd9R87eHOAZhDsQmjDcbYsg,210
551
563
  hyperpocket/server/tool/wasm.py,sha256=VJyp6RGsq8llKT_sY6DhV52wsETu-W9bzJ7C9wC17Oo,1698
@@ -581,7 +593,7 @@ hyperpocket/util/flatten_json_schema.py,sha256=iuNBEmMSKFtPi-uqo6fb3RWN0koHOAihW
581
593
  hyperpocket/util/function_to_model.py,sha256=TXUs-qPbzL8C9-qqpz4Ad4D9MOPP61n_p0iPU6SoBeM,2318
582
594
  hyperpocket/util/get_objects_from_subpackage.py,sha256=4mR_S8eaJSdU68YfCkiXeIcXxb6q7LjFGsY_IHeNIZw,929
583
595
  hyperpocket/util/json_schema_to_model.py,sha256=PqI87pU5dWwcrQWB8eQxRdfgAEvvC1x_DKZnhcsRV-o,3586
584
- hyperpocket-0.3.5.dist-info/METADATA,sha256=0tAI6rXugUdATKDBk6qvdwDIz1t23YsZN5fYkRfHsSQ,12958
585
- hyperpocket-0.3.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
586
- hyperpocket-0.3.5.dist-info/entry_points.txt,sha256=KpBleaYr0SaENXOa-dFvJ_cvFCHYFEQ4LMl11ShAcBI,61
587
- hyperpocket-0.3.5.dist-info/RECORD,,
596
+ hyperpocket-0.3.7.dist-info/METADATA,sha256=oZuYOmr2Tx0PdrjFsKiptOTJP5eUffygor8VdhNITOU,12958
597
+ hyperpocket-0.3.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
598
+ hyperpocket-0.3.7.dist-info/entry_points.txt,sha256=KpBleaYr0SaENXOa-dFvJ_cvFCHYFEQ4LMl11ShAcBI,61
599
+ hyperpocket-0.3.7.dist-info/RECORD,,