hyperpocket 0.0.3__py3-none-any.whl → 0.1.9__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. hyperpocket/auth/README.md +3 -3
  2. hyperpocket/auth/__init__.py +0 -8
  3. hyperpocket/auth/gumloop/context.py +13 -0
  4. hyperpocket/auth/gumloop/token_context.py +15 -0
  5. hyperpocket/auth/gumloop/token_handler.py +66 -0
  6. hyperpocket/auth/gumloop/token_schema.py +8 -0
  7. hyperpocket/auth/linear/token_context.py +1 -1
  8. hyperpocket/auth/notion/README.md +28 -0
  9. hyperpocket/auth/notion/context.py +15 -0
  10. hyperpocket/auth/notion/token_context.py +14 -0
  11. hyperpocket/auth/notion/token_handler.py +65 -0
  12. hyperpocket/auth/notion/token_schema.py +10 -0
  13. hyperpocket/auth/provider.py +8 -5
  14. hyperpocket/auth/reddit/context.py +15 -0
  15. hyperpocket/auth/reddit/oauth2_context.py +32 -0
  16. hyperpocket/auth/reddit/oauth2_handler.py +151 -0
  17. hyperpocket/auth/reddit/oauth2_schema.py +18 -0
  18. hyperpocket/auth/slack/token_context.py +1 -1
  19. hyperpocket/builtin.py +63 -0
  20. hyperpocket/cli/__main__.py +12 -0
  21. hyperpocket/cli/auth.py +83 -0
  22. hyperpocket/cli/codegen/auth/__init__.py +13 -0
  23. hyperpocket/cli/codegen/auth/auth_context_template.py +16 -0
  24. hyperpocket/cli/codegen/auth/auth_token_context_template.py +16 -0
  25. hyperpocket/cli/codegen/auth/auth_token_handler_template.py +69 -0
  26. hyperpocket/cli/codegen/auth/auth_token_schema_template.py +12 -0
  27. hyperpocket/cli/codegen/auth/server_auth_template.py +18 -0
  28. hyperpocket/cli/eject.py +19 -0
  29. hyperpocket/cli/sync.py +5 -5
  30. hyperpocket/config/settings.py +14 -12
  31. hyperpocket/futures/futurestore.py +0 -1
  32. hyperpocket/pocket_auth.py +25 -5
  33. hyperpocket/pocket_core.py +264 -0
  34. hyperpocket/pocket_main.py +127 -174
  35. hyperpocket/prompts.py +6 -8
  36. hyperpocket/repository/__init__.py +2 -2
  37. hyperpocket/repository/lock.py +71 -1
  38. hyperpocket/repository/lockfile.py +19 -13
  39. hyperpocket/repository/repository.py +26 -1
  40. hyperpocket/server/auth/__init__.py +0 -6
  41. hyperpocket/server/auth/gumloop.py +16 -0
  42. hyperpocket/server/auth/notion.py +19 -0
  43. hyperpocket/server/auth/reddit.py +16 -0
  44. hyperpocket/server/server.py +56 -20
  45. hyperpocket/server/tool/dto/script.py +15 -2
  46. hyperpocket/server/tool/wasm.py +20 -8
  47. hyperpocket/session/README.md +2 -2
  48. hyperpocket/session/in_memory.py +18 -5
  49. hyperpocket/session/interface.py +14 -0
  50. hyperpocket/session/redis.py +29 -5
  51. hyperpocket/tool/README.md +16 -12
  52. hyperpocket/tool/__init__.py +4 -3
  53. hyperpocket/tool/function/README.md +39 -10
  54. hyperpocket/tool/function/__init__.py +2 -0
  55. hyperpocket/tool/function/annotation.py +2 -1
  56. hyperpocket/tool/function/tool.py +108 -29
  57. hyperpocket/tool/tool.py +100 -28
  58. hyperpocket/tool/wasm/README.md +27 -5
  59. hyperpocket/tool/wasm/browser.py +2 -7
  60. hyperpocket/tool/wasm/script.py +40 -1
  61. hyperpocket/tool/wasm/templates/python.py +32 -14
  62. hyperpocket/tool/wasm/tool.py +21 -18
  63. hyperpocket/tool_like.py +5 -0
  64. hyperpocket/util/__init__.py +1 -1
  65. hyperpocket/util/extract_func_param_desc_from_docstring.py +4 -4
  66. hyperpocket/util/function_to_model.py +5 -2
  67. hyperpocket/util/json_schema_to_model.py +47 -26
  68. {hyperpocket-0.0.3.dist-info → hyperpocket-0.1.9.dist-info}/METADATA +107 -88
  69. hyperpocket-0.1.9.dist-info/RECORD +137 -0
  70. {hyperpocket-0.0.3.dist-info → hyperpocket-0.1.9.dist-info}/WHEEL +1 -1
  71. hyperpocket-0.1.9.dist-info/entry_points.txt +2 -0
  72. hyperpocket/auth/README.KR.md +0 -309
  73. hyperpocket/auth/slack/tests/test_oauth2_handler.py +0 -32
  74. hyperpocket/auth/slack/tests/test_token_handler.py +0 -23
  75. hyperpocket/auth/tests/test_google_oauth2_handler.py +0 -147
  76. hyperpocket/auth/tests/test_slack_oauth2_handler.py +0 -147
  77. hyperpocket/auth/tests/test_slack_token_handler.py +0 -66
  78. hyperpocket/external/__init__.py +0 -7
  79. hyperpocket/external/github_client.py +0 -19
  80. hyperpocket/session/README.KR.md +0 -62
  81. hyperpocket/session/tests/test_in_memory.py +0 -145
  82. hyperpocket/session/tests/test_redis.py +0 -151
  83. hyperpocket/tests/test_pocket.py +0 -116
  84. hyperpocket/tests/test_pocket_auth.py +0 -982
  85. hyperpocket/tool/README.KR.md +0 -68
  86. hyperpocket/tool/builtins/__init__.py +0 -0
  87. hyperpocket/tool/builtins/example/__init__.py +0 -0
  88. hyperpocket/tool/builtins/example/add_tool.py +0 -18
  89. hyperpocket/tool/function/README.KR.md +0 -159
  90. hyperpocket/tool/tests/test_function_tool.py +0 -266
  91. hyperpocket/tool/wasm/README.KR.md +0 -144
  92. hyperpocket-0.0.3.dist-info/RECORD +0 -130
  93. hyperpocket-0.0.3.dist-info/entry_points.txt +0 -3
  94. /hyperpocket/auth/{slack/tests → gumloop}/__init__.py +0 -0
  95. /hyperpocket/auth/{tests → notion}/__init__.py +0 -0
  96. /hyperpocket/{session/tests → auth/reddit}/__init__.py +0 -0
  97. /hyperpocket/{tests → cli/codegen}/__init__.py +0 -0
@@ -1,68 +0,0 @@
1
- # Tool
2
-
3
- ---
4
-
5
- ## ToolRequest
6
-
7
- 각 Tool을 초기화할 때 필요한 정보를 담고 있는 인터페이스
8
-
9
- ## ToolAuth
10
-
11
- ToolAuth는 Tool을 호출하기 위해 필요한 Authentication 정보를 나타내는 객체
12
-
13
- 다음과 같은 필드가 존재
14
-
15
- - auth_provider : tool 호출 시에 어떤 authentication provider의 인증 정보가 필요한지 표시
16
- - auth_provider가 명시되지 않는 경우, authentication이 필요없는 Tool로 인식된다.
17
- - auth_handler : tool 호출 시 어떤 authentication handler를 사용할 것인지를 표시
18
- - auth_handler가 명시되지 않는 경우, authentication provider의 default handler가 사용된다.
19
- - scopes : tool 호출 시에 어떤 authentication scopes가 필요한지를 표시
20
- - authentication을 수행하지 않거나, authentication handler가 non-scoped인 경우에는 None값을 사용
21
-
22
- ## Tool
23
-
24
- 실제 Tool을 실행하는 인터페이스
25
-
26
- ```python
27
- class Tool(BaseModel, abc.ABC):
28
- name: str = Field(description="tool name")
29
- description: str = Field(description="tool description")
30
- argument_json_schema: Optional[dict] = Field(default=None, description="tool argument json schema")
31
- auth: Optional[ToolAuth] = Field(default=None, description="authentication information to invoke tool")
32
- ```
33
-
34
- ### schema_model
35
-
36
- Tool.schema_model은 Tool이 호출 될 때 인자로 `profile`과 `thread_id`를 받기 위해 기존 Tool의 argument_json_schema을 wrapping한
37
- model을 반환
38
-
39
- 이때 기존의 argument_json_schema는 `body` 필드로 이동
40
-
41
- ## How to implement
42
-
43
- 1. Tool을 상속한 클래스를 생성
44
- - `invoke` 또는 `ainvoke` 내에서 툴 호출 시 수행할 작업을 정의
45
- - Tool을 초기화할 factory method를 정의
46
- - 이때 위의 필수 필드에 대한 값을 주입
47
-
48
- 2. `Pocket` 내의 `ToolLike`에 클래스를 추가(Optional)
49
- - `WasmTool`의 경우 ToolRequest, str을 입력으로 받을 수 있음
50
- - `FunctionTool`의 경우 Callable을 입력으로 받을 수 있음
51
-
52
- 3. `Pocket.__init__` 또는 `Pocket._load_tool` 함수 내에서 `ToolLike`값을 기반으로 Tool 초기화 수행
53
-
54
- ## Invoke Flow
55
-
56
- 1. `Pocket.invoke`를 통해 최초 Tool calling이 수행된다.
57
- 2. Tool 호출을 위해 authentication이 필요한 경우 `PocketAuth.invoke`를 통해 authentication을 수행
58
- 3. authentication이 완료된 후 `PocketAuth`에서 얻은 authentication 정보를 tool 호출 시 같이 전달
59
-
60
- ```mermaid
61
- flowchart TD
62
- Z["Agent"] -->|"Invoke tool"| A["Pocket"]
63
- A["Pocket"] -->|Requires Authentication?| B{"Yes"}
64
- B --> D["PocketAuth: Provide Authentication Info"]
65
- D --> E["Pocket: Invoke Tool with Auth Info"]
66
- B -->|No| F
67
- E --> F["Tool: Perform Operations"]
68
- ```
File without changes
File without changes
@@ -1,18 +0,0 @@
1
- # from pydantic import BaseModel, Field
2
- #
3
- # from pocket.tool.builtin import BuiltinTool
4
- # from pocket.tool.tool import TAny, TModelGeneric
5
- #
6
- #
7
- # class Schema(BaseModel):
8
- # a: int = Field(description="first number to add")
9
- # b: int = Field(description="second number to add")
10
- #
11
- #
12
- # class AddTool(BuiltinTool):
13
- # name: str = "add_two_number_tool"
14
- # description: str = "add two numbers"
15
- # argument_schema: TModelGeneric = Schema
16
- #
17
- # def invoke(self, a: int, b: int) -> TAny:
18
- # return a + b
@@ -1,159 +0,0 @@
1
- # Function
2
-
3
- python 함수를 tool로 등록해 사용
4
-
5
- ---
6
-
7
- ## How To Use
8
-
9
- ### No Auth
10
-
11
- python method를 pocket tool에 그대로 입력
12
-
13
- ```python
14
- from hyperpocket import Pocket
15
-
16
- pocket = Pocket(tools=[
17
- my_function]
18
- )
19
- ```
20
-
21
- ### Auth
22
-
23
- python method에 `@function_tool`를 사용해 필요한 authentication provider를 명시
24
-
25
- ```python
26
- from hyperpocket import Pocket
27
- from hyperpocket.auth import AuthProvider
28
- from hyperpocket.tool import function_tool
29
-
30
-
31
- @function_tool(
32
- auth_provider=AuthProvider.SLACK,
33
- scopes=["channels:history", "im:history", "mpim:history", "groups:history", "reactions:read", "mpim:read",
34
- "im:read"]
35
- )
36
- def my_function():
37
- pass
38
-
39
-
40
- pocket = Pocket(
41
- tools=[
42
- my_function
43
- ]
44
- )
45
- ```
46
-
47
- `from_function`을 통해 pocket을 초기화할 때에만 일시적으로 `FunctionTool`로 변환해 넣어줄 수 있다.
48
-
49
- ```python
50
- from hyperpocket import Pocket
51
- from hyperpocket.auth import AuthProvider
52
- from hyperpocket.tool import from_func
53
- from hyperpocket.tool.tool import ToolAuth
54
-
55
- Pocket(tools=[
56
- from_func(
57
- func=my_function,
58
- auth=ToolAuth(
59
- auth_provider=AuthProvider.SLACK,
60
- scopes=["channels:history", "im:history", "mpim:history", "groups:history", "reactions:read", "mpim:read",
61
- "im:read"]
62
- )
63
- )
64
- ])
65
- ```
66
-
67
- authentication access token은 python 함수의 variable keyword로 매핑되어 전달된다.
68
-
69
- ```python
70
- from hyperpocket.tool import function_tool
71
- from hyperpocket.auth import AuthProvider
72
-
73
-
74
- @function_tool(
75
- auth_provider=AuthProvider.SLACK
76
- )
77
- def my_function(**kwargs):
78
- token = kwargs["SLACK_BOT_TOKEN"]
79
-
80
- # ...
81
- ```
82
-
83
- - 각 provider 별 mapping key값은 각 provider의 `_ACCESS_TOKEN_KEY` 필드를 확인
84
-
85
- ## Docstring parsing
86
-
87
- docstring을 parsing해 argument 의미 파악
88
-
89
- 다음 docstring style을 지원
90
-
91
- - google style
92
- - sphinx
93
- - javadoc
94
- - plain
95
-
96
- ### Google Style
97
-
98
- ```python
99
- def my_function(a: int, b: int):
100
- """
101
- My Function
102
-
103
- Args:
104
- a(int): first argument
105
- b(int): second argument
106
- """
107
- pass
108
- ```
109
-
110
- ### Sphinx Style
111
-
112
- ```python
113
- def my_function(a: int, b: int):
114
- """
115
- My Function
116
-
117
- :param a: first argument
118
- :param b: second argument
119
- """
120
- pass
121
- ```
122
-
123
- ## Javadoc Style
124
-
125
- ```python
126
- def my_function(a: int, b: int):
127
- """
128
- My Function
129
-
130
- @param a: first argument
131
- @param b: second argument
132
- """
133
- pass
134
- ```
135
-
136
- ## Other Style
137
-
138
- ```python
139
- def my_function(a: int, b: int):
140
- """
141
- My Function
142
-
143
- @arg a: first argument
144
- @arg b: second argument
145
-
146
- or
147
-
148
- :arg a: first argument
149
- :arg b: second argument
150
- """
151
- pass
152
- ```
153
-
154
- 하나의 docstring에서 여러 style이 혼용되는 경우는 고려하지 않음
155
-
156
- ## Limits
157
-
158
- - input type은 python builtin type과 pydantic만 지원
159
-
@@ -1,266 +0,0 @@
1
- from unittest import TestCase
2
-
3
- from pydantic import BaseModel
4
-
5
- from hyperpocket.auth import AuthProvider
6
- from hyperpocket.tool.function.annotation import function_tool
7
- from hyperpocket.tool.function.tool import FunctionTool
8
- from hyperpocket.util.flatten_json_schema import flatten_json_schema
9
-
10
-
11
- class TestFunctionTool(TestCase):
12
-
13
- def test_function_tool_call(self):
14
- # given
15
- @function_tool
16
- def add_numbers(a: int, b: int):
17
- """
18
- add two numbers
19
- a(int): first name
20
- b(int): second name
21
- """
22
- return a + b
23
-
24
- # when
25
- result = add_numbers.invoke(body={
26
- "a": 1,
27
- "b": 2
28
- })
29
-
30
- # then
31
- self.assertEqual(result, '3')
32
-
33
- def test_pydantic_input_function_tool_call(self):
34
- # given
35
- class FirstNumber(BaseModel):
36
- first: int
37
-
38
- class SecondNumber(BaseModel):
39
- second: int
40
-
41
- @function_tool
42
- def add_numbers(a: FirstNumber, b: SecondNumber):
43
- """
44
- add two numbers
45
- a(FirstNumber): first number
46
- b(SecondNumber): second number
47
- """
48
- return a.first + b.second
49
-
50
- # when
51
- result = add_numbers.invoke(body={
52
- "a": {
53
- "first": 1,
54
- },
55
- "b": {
56
- "second": 2
57
- }
58
- })
59
-
60
- # then
61
- self.assertEqual(result, '3')
62
-
63
- def test_register_no_auth_no_init_func_case(self):
64
- """
65
- Test register functionTool in case of no-auth and no-init function
66
- """
67
-
68
- @function_tool
69
- def add_numbers(a: int, b: int):
70
- """
71
- add two numbers
72
- a(int): first name
73
- b(int): second name
74
- """
75
- return a + b
76
-
77
- # when
78
- result = add_numbers.invoke(body={
79
- "a": 1,
80
- "b": 2
81
- })
82
-
83
- # then
84
- self.assertIsInstance(add_numbers, FunctionTool)
85
- self.assertEqual(result, '3')
86
-
87
- def test_register_no_auth_init_func_case(self):
88
- """
89
- Test register functionTool in case of no-auth and init function
90
- """
91
-
92
- @function_tool()
93
- def add_numbers(a: int, b: int):
94
- """
95
- add two numbers
96
- a(int): first name
97
- b(int): second name
98
- """
99
- return a + b
100
-
101
- # when
102
- result = add_numbers.invoke(body={
103
- "a": 1,
104
- "b": 2
105
- })
106
-
107
- # then
108
- self.assertIsInstance(add_numbers, FunctionTool)
109
- self.assertEqual(result, '3')
110
-
111
- def test_register_auth_init_func_case(self):
112
- """
113
- Test register functionTool in case of auth and init function
114
-
115
- """
116
-
117
- @function_tool(auth_provider=AuthProvider.SLACK)
118
- def add_numbers(a: int, b: int):
119
- """
120
- add two numbers
121
- a(int): first name
122
- b(int): second name
123
- """
124
- return a + b
125
-
126
- # when
127
- result = add_numbers.invoke(body={
128
- "a": 1,
129
- "b": 2
130
- },
131
- envs={
132
- "SLACK_BOT_TOKEN": "test"
133
- })
134
-
135
- # then
136
- self.assertIsInstance(add_numbers, FunctionTool)
137
- self.assertEqual(result, '3')
138
-
139
- def test_google_style_docstring_parsing(self):
140
- """
141
- Test google style docstring parsing
142
- """
143
-
144
- # given
145
- @function_tool
146
- def add_numbers(a: int, b: int):
147
- """
148
- add two numbers
149
-
150
- Args:
151
- a(int): first name
152
- b(int): second name
153
- """
154
- return a + b
155
-
156
- # when
157
- schema = add_numbers.schema_model()
158
- schema_json = schema.model_json_schema()
159
- flatten_schema_json = flatten_json_schema(schema_json)
160
- func_schema = flatten_schema_json["properties"]["body"]
161
-
162
- # then
163
- self.assertTrue(str(func_schema["description"]).startswith("add two numbers"))
164
- self.assertEqual(func_schema["title"], "add_numbers")
165
- self.assertEqual(func_schema["required"], ["a", "b"])
166
- self.assertEqual(func_schema["type"], "object")
167
- self.assertEqual(func_schema["properties"]["a"]["type"], "integer")
168
- self.assertEqual(func_schema["properties"]["a"]["description"], "first name")
169
- self.assertEqual(func_schema["properties"]["b"]["type"], "integer")
170
- self.assertEqual(func_schema["properties"]["b"]["description"], "second name")
171
-
172
- def test_javadoc_style_docstring_parsing(self):
173
- """
174
- Test javadoc style docstring parsing
175
- """
176
-
177
- # given
178
- @function_tool
179
- def add_numbers(a: int, b: int):
180
- """
181
- add two numbers
182
-
183
- @param a first name
184
- @param b second name
185
- """
186
- return a + b
187
-
188
- # when
189
- schema = add_numbers.schema_model()
190
- schema_json = schema.model_json_schema()
191
- flatten_schema_json = flatten_json_schema(schema_json)
192
- func_schema = flatten_schema_json["properties"]["body"]
193
-
194
- # then
195
- self.assertTrue(str(func_schema["description"]).startswith("add two numbers"))
196
- self.assertEqual(func_schema["title"], "add_numbers")
197
- self.assertEqual(func_schema["required"], ["a", "b"])
198
- self.assertEqual(func_schema["type"], "object")
199
- self.assertEqual(func_schema["properties"]["a"]["type"], "integer")
200
- self.assertEqual(func_schema["properties"]["a"]["description"], "first name")
201
- self.assertEqual(func_schema["properties"]["b"]["type"], "integer")
202
- self.assertEqual(func_schema["properties"]["b"]["description"], "second name")
203
-
204
- def test_sphinx_style_docstring_parsing(self):
205
- """
206
- Test sphinx style docstring parsing
207
- """
208
-
209
- # given
210
- @function_tool
211
- def add_numbers(a: int, b: int):
212
- """
213
- add two numbers
214
-
215
- :param a: first name
216
- :param b: second name
217
- """
218
- return a + b
219
-
220
- # when
221
- schema = add_numbers.schema_model()
222
- schema_json = schema.model_json_schema()
223
- flatten_schema_json = flatten_json_schema(schema_json)
224
- func_schema = flatten_schema_json["properties"]["body"]
225
-
226
- # then
227
- self.assertTrue(str(func_schema["description"]).startswith("add two numbers"))
228
- self.assertEqual(func_schema["title"], "add_numbers")
229
- self.assertEqual(func_schema["required"], ["a", "b"])
230
- self.assertEqual(func_schema["type"], "object")
231
- self.assertEqual(func_schema["properties"]["a"]["type"], "integer")
232
- self.assertEqual(func_schema["properties"]["a"]["description"], "first name")
233
- self.assertEqual(func_schema["properties"]["b"]["type"], "integer")
234
- self.assertEqual(func_schema["properties"]["b"]["description"], "second name")
235
-
236
- def test_simple_style_docstring_parsing(self):
237
- """
238
- Test simple docstring parsing
239
- """
240
-
241
- # given
242
- @function_tool
243
- def add_numbers(a: int, b: int):
244
- """
245
- add two numbers
246
-
247
- a: first name
248
- b(int): second name
249
- """
250
- return a + b
251
-
252
- # when
253
- schema = add_numbers.schema_model()
254
- schema_json = schema.model_json_schema()
255
- flatten_schema_json = flatten_json_schema(schema_json)
256
- func_schema = flatten_schema_json["properties"]["body"]
257
-
258
- # then
259
- self.assertTrue(str(func_schema["description"]).startswith("add two numbers"))
260
- self.assertEqual(func_schema["title"], "add_numbers")
261
- self.assertEqual(func_schema["required"], ["a", "b"])
262
- self.assertEqual(func_schema["type"], "object")
263
- self.assertEqual(func_schema["properties"]["a"]["type"], "integer")
264
- self.assertEqual(func_schema["properties"]["a"]["description"], "first name")
265
- self.assertEqual(func_schema["properties"]["b"]["type"], "integer")
266
- self.assertEqual(func_schema["properties"]["b"]["description"], "second name")
@@ -1,144 +0,0 @@
1
- # Wasm(WebAssembly)
2
-
3
- ---
4
-
5
- ## How To Use
6
-
7
- ### plain url
8
-
9
- `Pocket` 초기화 시 github url을 넣어서 해당 툴을 불러올 수 있다.
10
-
11
- ```python
12
- from hyperpocket import Pocket
13
-
14
- pocket = Pocket(tools=[
15
- 'https://github.com/your-organization/your-repository/tree/main',
16
- ])
17
- ```
18
-
19
- - 이 경우 기본적으로 `main` branch를 기준으로 코드를 읽어오게 된다.
20
-
21
- ### from_git
22
-
23
- `from_git`을 통해 명시적으로 branch나 경로를 지정해 툴을 불러올 수 있다.
24
-
25
- ```python
26
- from hyperpocket import Pocket
27
- from hyperpocket.tool import from_git
28
-
29
- pocket = Pocket(tools=[
30
- from_git("https://github.com/your-organization/your-repository", "branch-name", "your/tool/code/path"),
31
- ])
32
- ```
33
-
34
- ### from_local
35
-
36
- `from_local`을 통해 로컬 경로를 지정해 툴을 불러올 수 있다.
37
-
38
- ```python
39
- from hyperpocket import Pocket
40
- from hyperpocket.tool import from_local
41
-
42
- pocket = Pocket(tools=[
43
- from_local("your/local/tool/code/path")
44
- ])
45
- ```
46
-
47
- ## WasmToolRequest
48
-
49
- WasmTool을 초기화 하기 위한 객체
50
-
51
- WasmToolRequest는 다음 build 함수를 제공
52
-
53
- - `from_local`
54
- - `from_git`
55
- - `from_github`
56
-
57
- WasmToolRequest는 각각 request에 대한 `lock` 객체를 가지고 있다.
58
-
59
- 해당 `lock` 객체들은 `Pocket`에서 `Lockfile` 객체를 통해 관리된다.
60
-
61
- ```mermaid
62
- classDiagram
63
- class WasmToolRequest {
64
- +Lock lock
65
- + from_git()
66
- + from_local()
67
- }
68
-
69
- class Lock{
70
- +key()
71
- +sync()
72
- }
73
-
74
- class GitLock{
75
- +key()
76
- +sync()
77
- }
78
-
79
- class LocalLock{
80
- +key()
81
- +sync()
82
- }
83
-
84
- class Lockfile {
85
- +dict[tuple,Lock] locks
86
-
87
- + add_lock()
88
- + get_lock()
89
- + sync()
90
- + write()
91
- }
92
-
93
- ToolRequest <|.. WasmToolRequest : Implementation
94
- Lock o-- WasmToolRequest : 1..1
95
- Lock <|.. GitLock : Implementation
96
- Lock <|.. LocalLock : Implementation
97
- Lock o-- Lockfile : n..1
98
- Lockfile o-- Pocket : 1..1
99
- ```
100
-
101
- ## WasmTool
102
-
103
- ```python
104
- class WasmTool(Tool):
105
- _invoker: WasmInvoker = None
106
- pkg_lock: Lock = None
107
- rel_path: str
108
- runtime: ScriptRuntime = None
109
- json_schema: Optional[dict] = None
110
- readme: Optional[str] = None
111
- ```
112
-
113
- - `_invoker` : wasm을 실행시키기 위한 클래스
114
- - `pkg_lock` : 해당 Tool의 lock 클래스
115
- - pkg_lock을 통해 현재 wasm code가 저장되어 있는 패키지 경로를 확인
116
- - `rel_path` : package 내에서 wasm code가 존재하는 상대 위치
117
- - `runtime` : wasm code의 runtime 언어
118
- - `json_schema` : wasm tool의 json schema
119
- - `schema.json`로 읽어온 정보
120
- - `readme` : readme 정보
121
-
122
- ## WasmInvoker
123
-
124
- 실제 wasm을 구동하기 위한 클래스
125
-
126
- 1. runtime 정보, auth 정보, body 정보 등을 종합해 html을 rendering
127
- 2. rendering된 html을 메모리에 저장
128
- 3. wasm 실행을 위한 browser를 실행
129
- 4. browser에서는 서버로 요청을 보내 rendering된 html을 불러옴
130
- 5. 해당 html에서 각 runtime에 맞는 코드를 실행 후 결괏값을 전달
131
-
132
- ```mermaid
133
- sequenceDiagram
134
- participant WasmTool as WasmTool (Includes Server)
135
- participant Browser as Browser (Executes WASM Runtime)
136
-
137
-
138
- WasmTool->>WasmTool: Render HTML and Store in Memory
139
- WasmTool->>Browser: Launch Browser
140
- Browser->>WasmTool: Request Rendered HTML
141
- WasmTool->>Browser: Provide Rendered HTML
142
- Browser->>Browser: Execute Injected WASM Runtime Script
143
- Browser->>WasmTool: Return Execution Result
144
- ```