hyperpocket 0.0.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- hyperpocket/__init__.py +7 -0
- hyperpocket/auth/README.KR.md +309 -0
- hyperpocket/auth/README.md +323 -0
- hyperpocket/auth/__init__.py +24 -0
- hyperpocket/auth/calendly/__init__.py +0 -0
- hyperpocket/auth/calendly/context.py +13 -0
- hyperpocket/auth/calendly/oauth2_context.py +25 -0
- hyperpocket/auth/calendly/oauth2_handler.py +146 -0
- hyperpocket/auth/calendly/oauth2_schema.py +16 -0
- hyperpocket/auth/context.py +38 -0
- hyperpocket/auth/github/__init__.py +0 -0
- hyperpocket/auth/github/context.py +13 -0
- hyperpocket/auth/github/oauth2_context.py +25 -0
- hyperpocket/auth/github/oauth2_handler.py +143 -0
- hyperpocket/auth/github/oauth2_schema.py +16 -0
- hyperpocket/auth/github/token_context.py +12 -0
- hyperpocket/auth/github/token_handler.py +79 -0
- hyperpocket/auth/github/token_schema.py +9 -0
- hyperpocket/auth/google/__init__.py +0 -0
- hyperpocket/auth/google/context.py +15 -0
- hyperpocket/auth/google/oauth2_context.py +31 -0
- hyperpocket/auth/google/oauth2_handler.py +137 -0
- hyperpocket/auth/google/oauth2_schema.py +18 -0
- hyperpocket/auth/handler.py +171 -0
- hyperpocket/auth/linear/__init__.py +0 -0
- hyperpocket/auth/linear/context.py +15 -0
- hyperpocket/auth/linear/token_context.py +15 -0
- hyperpocket/auth/linear/token_handler.py +68 -0
- hyperpocket/auth/linear/token_schema.py +9 -0
- hyperpocket/auth/provider.py +16 -0
- hyperpocket/auth/schema.py +19 -0
- hyperpocket/auth/slack/__init__.py +0 -0
- hyperpocket/auth/slack/context.py +15 -0
- hyperpocket/auth/slack/oauth2_context.py +40 -0
- hyperpocket/auth/slack/oauth2_handler.py +151 -0
- hyperpocket/auth/slack/oauth2_schema.py +40 -0
- hyperpocket/auth/slack/tests/__init__.py +0 -0
- hyperpocket/auth/slack/tests/test_oauth2_handler.py +32 -0
- hyperpocket/auth/slack/tests/test_token_handler.py +23 -0
- hyperpocket/auth/slack/token_context.py +14 -0
- hyperpocket/auth/slack/token_handler.py +64 -0
- hyperpocket/auth/slack/token_schema.py +9 -0
- hyperpocket/auth/tests/__init__.py +0 -0
- hyperpocket/auth/tests/test_google_oauth2_handler.py +147 -0
- hyperpocket/auth/tests/test_slack_oauth2_handler.py +147 -0
- hyperpocket/auth/tests/test_slack_token_handler.py +66 -0
- hyperpocket/cli/__init__.py +0 -0
- hyperpocket/cli/__main__.py +12 -0
- hyperpocket/cli/pull.py +18 -0
- hyperpocket/cli/sync.py +17 -0
- hyperpocket/config/__init__.py +9 -0
- hyperpocket/config/auth.py +36 -0
- hyperpocket/config/git.py +17 -0
- hyperpocket/config/logger.py +81 -0
- hyperpocket/config/session.py +35 -0
- hyperpocket/config/settings.py +62 -0
- hyperpocket/constants.py +0 -0
- hyperpocket/curated_tools.py +10 -0
- hyperpocket/external/__init__.py +7 -0
- hyperpocket/external/github_client.py +19 -0
- hyperpocket/futures/__init__.py +7 -0
- hyperpocket/futures/futurestore.py +48 -0
- hyperpocket/pocket_auth.py +344 -0
- hyperpocket/pocket_main.py +351 -0
- hyperpocket/prompts.py +15 -0
- hyperpocket/repository/__init__.py +5 -0
- hyperpocket/repository/lock.py +156 -0
- hyperpocket/repository/lockfile.py +56 -0
- hyperpocket/repository/repository.py +18 -0
- hyperpocket/server/__init__.py +3 -0
- hyperpocket/server/auth/__init__.py +15 -0
- hyperpocket/server/auth/calendly.py +16 -0
- hyperpocket/server/auth/github.py +25 -0
- hyperpocket/server/auth/google.py +16 -0
- hyperpocket/server/auth/linear.py +18 -0
- hyperpocket/server/auth/slack.py +28 -0
- hyperpocket/server/auth/token.py +51 -0
- hyperpocket/server/proxy.py +63 -0
- hyperpocket/server/server.py +178 -0
- hyperpocket/server/tool/__init__.py +10 -0
- hyperpocket/server/tool/dto/__init__.py +0 -0
- hyperpocket/server/tool/dto/script.py +15 -0
- hyperpocket/server/tool/wasm.py +31 -0
- hyperpocket/session/README.KR.md +62 -0
- hyperpocket/session/README.md +61 -0
- hyperpocket/session/__init__.py +4 -0
- hyperpocket/session/in_memory.py +76 -0
- hyperpocket/session/interface.py +118 -0
- hyperpocket/session/redis.py +126 -0
- hyperpocket/session/tests/__init__.py +0 -0
- hyperpocket/session/tests/test_in_memory.py +145 -0
- hyperpocket/session/tests/test_redis.py +151 -0
- hyperpocket/tests/__init__.py +0 -0
- hyperpocket/tests/test_pocket.py +118 -0
- hyperpocket/tests/test_pocket_auth.py +982 -0
- hyperpocket/tool/README.KR.md +68 -0
- hyperpocket/tool/README.md +75 -0
- hyperpocket/tool/__init__.py +13 -0
- hyperpocket/tool/builtins/__init__.py +0 -0
- hyperpocket/tool/builtins/example/__init__.py +0 -0
- hyperpocket/tool/builtins/example/add_tool.py +18 -0
- hyperpocket/tool/function/README.KR.md +159 -0
- hyperpocket/tool/function/README.md +169 -0
- hyperpocket/tool/function/__init__.py +9 -0
- hyperpocket/tool/function/annotation.py +30 -0
- hyperpocket/tool/function/tool.py +87 -0
- hyperpocket/tool/tests/__init__.py +0 -0
- hyperpocket/tool/tests/test_function_tool.py +266 -0
- hyperpocket/tool/tool.py +106 -0
- hyperpocket/tool/wasm/README.KR.md +144 -0
- hyperpocket/tool/wasm/README.md +144 -0
- hyperpocket/tool/wasm/__init__.py +3 -0
- hyperpocket/tool/wasm/browser.py +63 -0
- hyperpocket/tool/wasm/invoker.py +41 -0
- hyperpocket/tool/wasm/script.py +82 -0
- hyperpocket/tool/wasm/templates/__init__.py +28 -0
- hyperpocket/tool/wasm/templates/node.py +87 -0
- hyperpocket/tool/wasm/templates/python.py +75 -0
- hyperpocket/tool/wasm/tool.py +147 -0
- hyperpocket/util/__init__.py +1 -0
- hyperpocket/util/extract_func_param_desc_from_docstring.py +97 -0
- hyperpocket/util/find_all_leaf_class_in_package.py +17 -0
- hyperpocket/util/find_all_subclass_in_package.py +29 -0
- hyperpocket/util/flatten_json_schema.py +45 -0
- hyperpocket/util/function_to_model.py +46 -0
- hyperpocket/util/get_objects_from_subpackage.py +28 -0
- hyperpocket/util/json_schema_to_model.py +69 -0
- hyperpocket-0.0.1.dist-info/METADATA +304 -0
- hyperpocket-0.0.1.dist-info/RECORD +131 -0
- hyperpocket-0.0.1.dist-info/WHEEL +4 -0
- hyperpocket-0.0.1.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
import unittest
|
2
|
+
|
3
|
+
from hyperpocket.auth import AuthProvider, SlackTokenAuthContext
|
4
|
+
from hyperpocket.config.session import SessionConfigRedis
|
5
|
+
from hyperpocket.session.in_memory import InMemorySessionValue
|
6
|
+
from hyperpocket.session.redis import RedisSessionStorage, RedisSessionValue
|
7
|
+
|
8
|
+
|
9
|
+
class TestRedisSessionStorage(unittest.TestCase):
|
10
|
+
storage: RedisSessionStorage
|
11
|
+
context: SlackTokenAuthContext
|
12
|
+
|
13
|
+
def setUp(self):
|
14
|
+
self.storage = RedisSessionStorage(SessionConfigRedis(
|
15
|
+
host="localhost",
|
16
|
+
port=6379,
|
17
|
+
db="9"
|
18
|
+
))
|
19
|
+
self.storage.client.flushdb()
|
20
|
+
|
21
|
+
self.auth_context = SlackTokenAuthContext(
|
22
|
+
access_token="test",
|
23
|
+
description="test-description",
|
24
|
+
expires_at=None,
|
25
|
+
detail=None,
|
26
|
+
)
|
27
|
+
|
28
|
+
def tearDown(self):
|
29
|
+
self.storage.client.flushdb()
|
30
|
+
|
31
|
+
def test_make_session_key(self):
|
32
|
+
key = self.storage._make_session_key(
|
33
|
+
auth_provider=AuthProvider.SLACK,
|
34
|
+
thread_id="default_thread_id",
|
35
|
+
profile="default_profile"
|
36
|
+
)
|
37
|
+
|
38
|
+
self.assertEqual(key, "SLACK__default_thread_id__default_profile")
|
39
|
+
|
40
|
+
def test_make_session(self):
|
41
|
+
session = self.storage._make_session(
|
42
|
+
auth_provider_name=AuthProvider.SLACK.name,
|
43
|
+
auth_scopes=["scope1", "scope2"],
|
44
|
+
auth_context=self.auth_context,
|
45
|
+
auth_resolve_uid="test-resolve-uid",
|
46
|
+
is_auth_scope_universal=True
|
47
|
+
)
|
48
|
+
|
49
|
+
# then
|
50
|
+
self.assertIsInstance(session, RedisSessionValue)
|
51
|
+
self.assertEqual(session.auth_provider_name, AuthProvider.SLACK.name)
|
52
|
+
self.assertEqual(session.auth_context.access_token, "test")
|
53
|
+
self.assertEqual(session.auth_context.description, "test-description")
|
54
|
+
|
55
|
+
def test_set(self):
|
56
|
+
session = self.storage.set(
|
57
|
+
auth_provider=AuthProvider.SLACK,
|
58
|
+
thread_id="default_thread_id",
|
59
|
+
profile="default_profile",
|
60
|
+
auth_scopes=["scope1", "scope2"],
|
61
|
+
auth_resolve_uid="test-resolve-uid",
|
62
|
+
auth_context=self.auth_context,
|
63
|
+
is_auth_scope_universal=True
|
64
|
+
)
|
65
|
+
|
66
|
+
self.assertIsInstance(session, InMemorySessionValue)
|
67
|
+
self.assertEqual(session.auth_provider_name, AuthProvider.SLACK.name)
|
68
|
+
self.assertEqual(session.auth_context.access_token, self.auth_context.access_token)
|
69
|
+
self.assertEqual(session.auth_context.description, self.auth_context.description)
|
70
|
+
|
71
|
+
def test_get_existing_data(self):
|
72
|
+
# given
|
73
|
+
self.storage.set(
|
74
|
+
auth_provider=AuthProvider.SLACK,
|
75
|
+
thread_id="default_thread_id",
|
76
|
+
profile="default_profile",
|
77
|
+
auth_scopes=["scope1", "scope2"],
|
78
|
+
auth_resolve_uid="test-resolve-uid",
|
79
|
+
auth_context=self.auth_context,
|
80
|
+
is_auth_scope_universal=True
|
81
|
+
)
|
82
|
+
|
83
|
+
# when
|
84
|
+
session = self.storage.get(
|
85
|
+
auth_provider=AuthProvider.SLACK,
|
86
|
+
thread_id="default_thread_id",
|
87
|
+
profile="default_profile",
|
88
|
+
)
|
89
|
+
|
90
|
+
# then
|
91
|
+
self.assertIsInstance(session, InMemorySessionValue)
|
92
|
+
self.assertEqual(session.auth_provider_name, AuthProvider.SLACK.name)
|
93
|
+
self.assertEqual(session.auth_context.access_token, "test")
|
94
|
+
self.assertEqual(session.auth_context.description, "test-description")
|
95
|
+
|
96
|
+
def test_get_not_existing_data(self):
|
97
|
+
# when
|
98
|
+
session = self.storage.get(
|
99
|
+
auth_provider=AuthProvider.SLACK,
|
100
|
+
thread_id="default_thread_id",
|
101
|
+
profile="default_profile",
|
102
|
+
)
|
103
|
+
|
104
|
+
# then
|
105
|
+
self.assertIsNone(session)
|
106
|
+
|
107
|
+
def test_delete_existing_data(self):
|
108
|
+
# given
|
109
|
+
self.storage.set(
|
110
|
+
auth_provider=AuthProvider.SLACK,
|
111
|
+
thread_id="default_thread_id",
|
112
|
+
profile="default_profile",
|
113
|
+
auth_scopes=["scope1", "scope2"],
|
114
|
+
auth_resolve_uid="test-resolve-uid",
|
115
|
+
auth_context=self.auth_context,
|
116
|
+
is_auth_scope_universal=True
|
117
|
+
)
|
118
|
+
|
119
|
+
# when
|
120
|
+
before_session = self.storage.get(
|
121
|
+
auth_provider=AuthProvider.SLACK,
|
122
|
+
thread_id="default_thread_id",
|
123
|
+
profile="default_profile",
|
124
|
+
)
|
125
|
+
|
126
|
+
deleted = self.storage.delete(
|
127
|
+
auth_provider=AuthProvider.SLACK,
|
128
|
+
thread_id="default_thread_id",
|
129
|
+
profile="default_profile",
|
130
|
+
)
|
131
|
+
|
132
|
+
after_session = self.storage.get(
|
133
|
+
auth_provider=AuthProvider.SLACK,
|
134
|
+
thread_id="default_thread_id",
|
135
|
+
profile="default_profile",
|
136
|
+
)
|
137
|
+
|
138
|
+
# then
|
139
|
+
self.assertTrue(deleted)
|
140
|
+
self.assertIsNotNone(before_session)
|
141
|
+
self.assertIsNone(after_session)
|
142
|
+
|
143
|
+
def test_delete_not_existing_data(self):
|
144
|
+
deleted = self.storage.delete(
|
145
|
+
auth_provider=AuthProvider.SLACK,
|
146
|
+
thread_id="default_thread_id",
|
147
|
+
profile="default_profile",
|
148
|
+
)
|
149
|
+
|
150
|
+
# then
|
151
|
+
self.assertFalse(deleted)
|
File without changes
|
@@ -0,0 +1,118 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
from unittest.async_case import IsolatedAsyncioTestCase
|
3
|
+
|
4
|
+
from pydantic import BaseModel
|
5
|
+
|
6
|
+
from hyperpocket import Pocket
|
7
|
+
from hyperpocket.config import config
|
8
|
+
from hyperpocket.tool import from_local
|
9
|
+
|
10
|
+
|
11
|
+
class TestPocket(IsolatedAsyncioTestCase):
|
12
|
+
|
13
|
+
async def asyncSetUp(self):
|
14
|
+
self.profile = "test-profile"
|
15
|
+
self.thread_id = "test_thread_id"
|
16
|
+
|
17
|
+
config.public_server_port = "https"
|
18
|
+
config.public_hostname = "localhost"
|
19
|
+
config.public_server_port = 8001
|
20
|
+
config.internal_server_port = 8000
|
21
|
+
config.enable_local_callback_proxy = True
|
22
|
+
|
23
|
+
import hyperpocket
|
24
|
+
path = Path(hyperpocket.__file__).parent.parent.parent.parent / "examples/tool/simple-echo-tool"
|
25
|
+
self.pocket = Pocket(
|
26
|
+
tools=[
|
27
|
+
from_local(str(path)),
|
28
|
+
self.add,
|
29
|
+
self.add_pydantic_args
|
30
|
+
],
|
31
|
+
)
|
32
|
+
|
33
|
+
async def test_function_tool(self):
|
34
|
+
# given
|
35
|
+
tool_name = "add"
|
36
|
+
|
37
|
+
# when
|
38
|
+
result = await self.pocket.ainvoke(
|
39
|
+
tool_name=tool_name,
|
40
|
+
body={
|
41
|
+
"a": 1,
|
42
|
+
"b": 3
|
43
|
+
},
|
44
|
+
thread_id=self.thread_id,
|
45
|
+
profile=self.profile,
|
46
|
+
)
|
47
|
+
|
48
|
+
# then
|
49
|
+
self.assertEqual(result, "4")
|
50
|
+
|
51
|
+
async def test_pydantic_arg_function_tool(self):
|
52
|
+
# given
|
53
|
+
tool_name = "add_pydantic_args"
|
54
|
+
|
55
|
+
# when
|
56
|
+
result = await self.pocket.ainvoke(
|
57
|
+
tool_name=tool_name,
|
58
|
+
body={
|
59
|
+
"a": {
|
60
|
+
"first": 1
|
61
|
+
},
|
62
|
+
"b": {
|
63
|
+
"second": 3
|
64
|
+
}
|
65
|
+
},
|
66
|
+
thread_id=self.thread_id,
|
67
|
+
profile=self.profile,
|
68
|
+
)
|
69
|
+
|
70
|
+
# then
|
71
|
+
self.assertEqual(result, "4")
|
72
|
+
|
73
|
+
async def test_wasm_tool(self):
|
74
|
+
# given
|
75
|
+
tool_name = "simple_echo_text"
|
76
|
+
|
77
|
+
# when
|
78
|
+
result = await self.pocket.ainvoke(
|
79
|
+
tool_name=tool_name,
|
80
|
+
body={
|
81
|
+
"text": "test"
|
82
|
+
},
|
83
|
+
thread_id=self.thread_id,
|
84
|
+
profile=self.profile,
|
85
|
+
)
|
86
|
+
|
87
|
+
# then
|
88
|
+
self.assertTrue(result.startswith("echo message : test"))
|
89
|
+
|
90
|
+
@staticmethod
|
91
|
+
def add(a: int, b: int) -> int:
|
92
|
+
"""
|
93
|
+
Add two numbers
|
94
|
+
|
95
|
+
Args:
|
96
|
+
a(int): first number
|
97
|
+
b(int): second number
|
98
|
+
|
99
|
+
"""
|
100
|
+
|
101
|
+
return a + b
|
102
|
+
|
103
|
+
class FirstNumber(BaseModel):
|
104
|
+
first: int
|
105
|
+
|
106
|
+
class SecondNumber(BaseModel):
|
107
|
+
second: int
|
108
|
+
|
109
|
+
@staticmethod
|
110
|
+
def add_pydantic_args(a: FirstNumber, b: SecondNumber):
|
111
|
+
"""
|
112
|
+
Add two numbers
|
113
|
+
|
114
|
+
Args:
|
115
|
+
a(FirstNumber): first number
|
116
|
+
b(SecondNumber): second number
|
117
|
+
"""
|
118
|
+
return a.first + b.second
|