hyperpocket 0.4.5__py3-none-any.whl → 0.5.0__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/builtin.py +3 -3
- hyperpocket/cli/__main__.py +0 -2
- hyperpocket/config/logger.py +2 -3
- hyperpocket/futures/futurestore.py +7 -2
- hyperpocket/pocket_auth.py +10 -8
- hyperpocket/pocket_main.py +247 -99
- hyperpocket/server/server.py +70 -239
- hyperpocket/session/in_memory.py +20 -26
- hyperpocket/tool/__init__.py +1 -2
- hyperpocket/tool/dock/dock.py +6 -25
- hyperpocket/tool/function/tool.py +1 -1
- hyperpocket/tool/tool.py +6 -35
- hyperpocket/tool_like.py +2 -3
- hyperpocket/util/git_parser.py +63 -0
- hyperpocket/util/short_hashing_str.py +5 -0
- {hyperpocket-0.4.5.dist-info → hyperpocket-0.5.0.dist-info}/METADATA +5 -5
- {hyperpocket-0.4.5.dist-info → hyperpocket-0.5.0.dist-info}/RECORD +19 -23
- hyperpocket/pocket_core.py +0 -283
- hyperpocket/repository/__init__.py +0 -4
- hyperpocket/repository/repository.py +0 -8
- hyperpocket/repository/tool_reference.py +0 -28
- hyperpocket/tool/tests/__init__.py +0 -0
- hyperpocket/util/generate_slug.py +0 -4
- {hyperpocket-0.4.5.dist-info → hyperpocket-0.5.0.dist-info}/WHEEL +0 -0
- {hyperpocket-0.4.5.dist-info → hyperpocket-0.5.0.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.5.0
|
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
|
@@ -103,7 +103,7 @@ from hyperpocket_langchain import PocketLangchain
|
|
103
103
|
if __name__ == '__main__':
|
104
104
|
pocket = PocketLangchain(
|
105
105
|
tools=[
|
106
|
-
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-
|
106
|
+
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-messages",
|
107
107
|
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
|
108
108
|
],
|
109
109
|
)
|
@@ -176,7 +176,7 @@ from hyperpocket_langchain import PocketLangchain
|
|
176
176
|
|
177
177
|
pklc = PocketLangchain(
|
178
178
|
tools=[
|
179
|
-
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-
|
179
|
+
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-messages",
|
180
180
|
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
|
181
181
|
]
|
182
182
|
)
|
@@ -235,7 +235,7 @@ from hyperpocket_langgraph import PocketLanggraph
|
|
235
235
|
|
236
236
|
pklg = PocketLanggraph(
|
237
237
|
tools=[
|
238
|
-
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-
|
238
|
+
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-messages",
|
239
239
|
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
|
240
240
|
],
|
241
241
|
)
|
@@ -272,7 +272,7 @@ from hyperpocket_llamaindex import PocketLlamaindex
|
|
272
272
|
llm = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
273
273
|
pocket = PocketLlamaindex(
|
274
274
|
tools=[
|
275
|
-
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-
|
275
|
+
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-messages",
|
276
276
|
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
|
277
277
|
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/linear/get-issues",
|
278
278
|
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/google/get-calendar-events",
|
@@ -1,11 +1,10 @@
|
|
1
1
|
hyperpocket/__init__.py,sha256=VVLbApRTiULqEVQp6lCNOcuXKx9V62O_7C9VNKBQ0G0,137
|
2
|
-
hyperpocket/builtin.py,sha256=
|
2
|
+
hyperpocket/builtin.py,sha256=w7OLxf5RCKVpLma9HieSdw6Uky5701ae6g31VPvFoZk,2439
|
3
3
|
hyperpocket/constants.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
hyperpocket/pocket_auth.py,sha256=
|
5
|
-
hyperpocket/
|
6
|
-
hyperpocket/pocket_main.py,sha256=_YoxA01tFqnU3MavJndiXn1cKYWZ7z9_v0IihCzlHmo,10228
|
4
|
+
hyperpocket/pocket_auth.py,sha256=eRRTzJh3et65EDJnQHB_Kpmco4dgCR2KL8f-FnbuGX0,17819
|
5
|
+
hyperpocket/pocket_main.py,sha256=pCbJjT7r-kzYIxzh24jKcGwh-SOnbB9ID8kwDpB1HG4,16467
|
7
6
|
hyperpocket/prompts.py,sha256=N1bCzCLZvGUVhH1Vn_cgeBPsdY3MdIU7ZGqVgexoj5E,472
|
8
|
-
hyperpocket/tool_like.py,sha256=
|
7
|
+
hyperpocket/tool_like.py,sha256=Foa-iWTnVb54JEq20Becadbz-TSbYkZk6TxexSzaaRM,116
|
9
8
|
hyperpocket/auth/README.md,sha256=zn4QqnFZCA_4X3x8Wb6lE3OP5otYxpByZaCiUkBvaNs,11562
|
10
9
|
hyperpocket/auth/__init__.py,sha256=pO8M6SAuq0EPqi848_Iy650wqaLekx98e3RRnEAM_r0,607
|
11
10
|
hyperpocket/auth/context.py,sha256=m-j2gDYUKBMsiakLHsu9thhM4dYyFiXP0Wp0S_iC0bU,1303
|
@@ -469,7 +468,7 @@ hyperpocket/auth/zoom/oauth2_context.py,sha256=f0vj1zeRzTnT-4cwe8SeEn2xz03NBy9W_
|
|
469
468
|
hyperpocket/auth/zoom/oauth2_handler.py,sha256=dMoZjuSRSBaoYLzYkjxc0KZxm9CALLm9aaEVydLBW-0,5111
|
470
469
|
hyperpocket/auth/zoom/oauth2_schema.py,sha256=OlwlEdigiqFX3-XdVp0mhrK7ZKWxVw0v1qNtfx3wN9c,469
|
471
470
|
hyperpocket/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
472
|
-
hyperpocket/cli/__main__.py,sha256=
|
471
|
+
hyperpocket/cli/__main__.py,sha256=sVGU32c27NCaqysM4TsOf6D-Tj7a3mDhUmm7CRajg_g,753
|
473
472
|
hyperpocket/cli/auth_oauth2.py,sha256=FTsaIrJY9U1uDEtZL456zOWQKfcqzOPg33ikFhFFjyA,4899
|
474
473
|
hyperpocket/cli/auth_token.py,sha256=YV1AK70Q_hNsm_xwHP5LTaUWI-omssnX8214JyD3m_w,4875
|
475
474
|
hyperpocket/cli/eject.py,sha256=utzeL4t02ML-EIgpPUiFjCbycjRpvkP1905bLeZAT2Y,321
|
@@ -491,17 +490,14 @@ hyperpocket/cli/codegen/tool/tool_main_template.py,sha256=VKxt-DbQ97DYtUClRZJwt3
|
|
491
490
|
hyperpocket/config/__init__.py,sha256=gYMHdExdPYScBB8mihSp1yJ9H-RJ8FdNz5mEFubFNAo,138
|
492
491
|
hyperpocket/config/auth.py,sha256=OOVdaAfMva6b-Kz4iy5YpnIKjT5WgcQ17toFzHqoRPY,2173
|
493
492
|
hyperpocket/config/git.py,sha256=CGbY7J1LyN4ccZr9CFGAQwwhjC9kvdU0On_nsAsZ1FQ,362
|
494
|
-
hyperpocket/config/logger.py,sha256=
|
493
|
+
hyperpocket/config/logger.py,sha256=RWPmuN6Rk4x3a4rendGkKLCowhs6LFlIV8rYNu2GoxM,2749
|
495
494
|
hyperpocket/config/session.py,sha256=1ng1mARv4R_07SF5CkZWLgX9pNeXTcM0knCRw07Fpms,816
|
496
495
|
hyperpocket/config/settings.py,sha256=aw3TiPepcmSOKsIXDFHBhhqD2Ubz-51xRbFHZ5qx8KY,2437
|
497
496
|
hyperpocket/futures/__init__.py,sha256=IObmC6hKC_Rc3vwOzINUVJ1hU2MDB5BUfXuH0vlSjtE,136
|
498
|
-
hyperpocket/futures/futurestore.py,sha256=
|
499
|
-
hyperpocket/repository/__init__.py,sha256=ML7XfV1SgcEiOBgQpfqjsT8QEKJbGQG3sVRqi_iAxqA,168
|
500
|
-
hyperpocket/repository/repository.py,sha256=KvgZnJW_TrBzaLWV0DxjReLklkni1oyLq856OyjJ__A,129
|
501
|
-
hyperpocket/repository/tool_reference.py,sha256=Nuc2ckWuH_5K-p8S_0IuJiaJiPE6XWchA2XM71nOTjM,554
|
497
|
+
hyperpocket/futures/futurestore.py,sha256=9MZTmZJyezx_HEW71-Z7RUI_xqQ8J9YSDQJ7LYGofQI,1682
|
502
498
|
hyperpocket/server/__init__.py,sha256=8laNl098-IkFkarqwOZs_gm6yG0q3NAObq4cCUxK_Tw,90
|
503
499
|
hyperpocket/server/proxy.py,sha256=ItM1qfuUBs6QiPqIpErBWUZWdtsEf0twPJY5r2UUFBU,2042
|
504
|
-
hyperpocket/server/server.py,sha256=
|
500
|
+
hyperpocket/server/server.py,sha256=lrcuE_ph39taMDj9MgIpIsUuC6VYwUgAWROH1iPCgaQ,4816
|
505
501
|
hyperpocket/server/auth/__init__.py,sha256=IMjz9PCzD7qh4QIf2g-gWIdkDeU36jt-9F55vaHvLoM,286
|
506
502
|
hyperpocket/server/auth/activeloop.py,sha256=MHh43F0j6q0r-GcevwD41ewLXdaPHfhLT9bCLuL7puU,739
|
507
503
|
hyperpocket/server/auth/adobe.py,sha256=HH6elxV3ELWUnTRlkQBBFSXMHAc0angRUfHHkZVA4Kg,437
|
@@ -579,29 +575,29 @@ hyperpocket/server/auth/zinc.py,sha256=xgVV5lWP6YSEHTCmH0gipG5lh4Wvf716tHTnOvTTj
|
|
579
575
|
hyperpocket/server/auth/zoom.py,sha256=kWp4MB4i9FKMA4ZYcj4g4_90Y1ZMEoAQTTjbb0rsMRs,703
|
580
576
|
hyperpocket/session/README.md,sha256=Wmh-qWJQ-40vU9hP5jNxuM33i0STNfaIjOecba7H-oc,1968
|
581
577
|
hyperpocket/session/__init__.py,sha256=ljqLlIMsrY9Hb8UOweaEvBM_Ku9IxBMMIXar6T7h5Lg,275
|
582
|
-
hyperpocket/session/in_memory.py,sha256=
|
578
|
+
hyperpocket/session/in_memory.py,sha256=ku0jGKqXbqhuj68DYnjezmcJwOGJbgzNrsH2gKQTI_g,3433
|
583
579
|
hyperpocket/session/interface.py,sha256=vQobJCzQe29uM6yXanRAysUhJvtfuUZ0qddMpeLn8NI,4964
|
584
580
|
hyperpocket/session/redis.py,sha256=rbW2b0C6HUNp5HpTpr6sxDKZQCuPHu2ipCyn1TXjPgM,5444
|
585
581
|
hyperpocket/tool/README.md,sha256=vbHvP3fnfihq-H481MiSZEVJNhVoUu0djENb9tiy78c,3026
|
586
|
-
hyperpocket/tool/__init__.py,sha256=
|
587
|
-
hyperpocket/tool/tool.py,sha256=
|
582
|
+
hyperpocket/tool/__init__.py,sha256=so12foM0X4rR8OUy6kziXB2KswAlXKIfVLcMTca8XeM,221
|
583
|
+
hyperpocket/tool/tool.py,sha256=1SFfTsSA_YKhH08fX9kyZRWv3VUr63YJbF_t7P8SSsk,6096
|
588
584
|
hyperpocket/tool/dock/__init__.py,sha256=gEFaYTgTIzzaAHW6Bl1CJL8RQlU23NK--bojLqPTLSc,63
|
589
|
-
hyperpocket/tool/dock/dock.py,sha256=
|
585
|
+
hyperpocket/tool/dock/dock.py,sha256=DfHS-2imgJg4VQ2R-cC-wp7r2Dl2n7ZF-GmpRRZdDKg,405
|
590
586
|
hyperpocket/tool/function/README.md,sha256=6Y9a8FlFjEdbrVqF0NoQ1j34VoV8Zt6Pf9-xlLIHkTc,3676
|
591
587
|
hyperpocket/tool/function/__init__.py,sha256=n0IYvfoyoFWv76iwK2kBC-X6468dl5XyYFl1mudYSe4,261
|
592
588
|
hyperpocket/tool/function/annotation.py,sha256=qVBhjFUXY_MXysPN61FJuX4mgVZHuMJTtn0L5QCY4eg,1159
|
593
|
-
hyperpocket/tool/function/tool.py,sha256=
|
594
|
-
hyperpocket/tool/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
589
|
+
hyperpocket/tool/function/tool.py,sha256=c3K8iqL70LOyjmvNqmWlgY8vcjEiNqZ8Wd_ut0rS9Hs,7474
|
595
590
|
hyperpocket/util/__init__.py,sha256=7vN8c7dy7nhGhjXtSUGAsc6GIlUnuBMvXSl1yW1M4js,35
|
596
591
|
hyperpocket/util/extract_func_param_desc_from_docstring.py,sha256=eGDrbigmVg1zaud1q5l2WDZkYqzy56TRznNPouc8i_Y,4170
|
597
592
|
hyperpocket/util/find_all_leaf_class_in_package.py,sha256=06n8R47BDPovxhCOnzu9GuEfeQzEbv-HdG-zfMu1gBw,533
|
598
593
|
hyperpocket/util/find_all_subclass_in_package.py,sha256=TtEb41-nzCNhC9pgelTS6MMxLT_JNZkFPJe5z2H9yik,978
|
599
594
|
hyperpocket/util/flatten_json_schema.py,sha256=iuNBEmMSKFtPi-uqo6fb3RWN0koHOAihWAAofWbd1U8,1671
|
600
595
|
hyperpocket/util/function_to_model.py,sha256=TXUs-qPbzL8C9-qqpz4Ad4D9MOPP61n_p0iPU6SoBeM,2318
|
601
|
-
hyperpocket/util/generate_slug.py,sha256=gwwf9gfTlqribrvybMQQj7VIHX5FspVoTm5-EYH-X74,150
|
602
596
|
hyperpocket/util/get_objects_from_subpackage.py,sha256=4mR_S8eaJSdU68YfCkiXeIcXxb6q7LjFGsY_IHeNIZw,929
|
597
|
+
hyperpocket/util/git_parser.py,sha256=y96nhgZXtRgA_u_0GTPo95PGkpG-n_oMIrkbckdxiR8,2496
|
603
598
|
hyperpocket/util/json_schema_to_model.py,sha256=nc5AmnqkrdeFLELu-7_O9sEAaUaD8_KGlvIMDRobt-4,3751
|
604
|
-
hyperpocket
|
605
|
-
hyperpocket-0.
|
606
|
-
hyperpocket-0.
|
607
|
-
hyperpocket-0.
|
599
|
+
hyperpocket/util/short_hashing_str.py,sha256=ahLUT8iQr-MJVbDJXrSt0cXnnSEeJ8EU3A0PDn6e0gs,119
|
600
|
+
hyperpocket-0.5.0.dist-info/METADATA,sha256=I_K2Ka3J4ABp0Y6X8ZCNAoH8cqw6xvQBJzxeIgnd60U,13078
|
601
|
+
hyperpocket-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
602
|
+
hyperpocket-0.5.0.dist-info/entry_points.txt,sha256=KpBleaYr0SaENXOa-dFvJ_cvFCHYFEQ4LMl11ShAcBI,61
|
603
|
+
hyperpocket-0.5.0.dist-info/RECORD,,
|
hyperpocket/pocket_core.py
DELETED
@@ -1,283 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
from typing import Any, Callable, List, Optional, Union
|
3
|
-
|
4
|
-
from hyperpocket.builtin import get_builtin_tools
|
5
|
-
from hyperpocket.config import pocket_logger
|
6
|
-
from hyperpocket.pocket_auth import PocketAuth
|
7
|
-
from hyperpocket.tool import Tool
|
8
|
-
from hyperpocket.tool.dock import Dock
|
9
|
-
from hyperpocket.tool.function import from_func
|
10
|
-
from hyperpocket.tool_like import ToolLike
|
11
|
-
|
12
|
-
|
13
|
-
class PocketCore:
|
14
|
-
auth: PocketAuth
|
15
|
-
tools: dict[str, Tool]
|
16
|
-
docks: list[Dock]
|
17
|
-
|
18
|
-
@staticmethod
|
19
|
-
def _default_dock() -> Dock:
|
20
|
-
try:
|
21
|
-
from hyperdock_container.dock import ContainerDock
|
22
|
-
pocket_logger.info("hyperdock-container is loaded.")
|
23
|
-
return ContainerDock()
|
24
|
-
except ImportError:
|
25
|
-
pocket_logger.warning("Failed to import hyperdock_container.")
|
26
|
-
|
27
|
-
try:
|
28
|
-
from hyperdock_wasm.dock import WasmDock
|
29
|
-
pocket_logger.info("hyperdock-wasm is loaded.")
|
30
|
-
return WasmDock()
|
31
|
-
except ImportError:
|
32
|
-
raise ImportError("No default dock available. To register a remote tool, you need to install either hyperdock_wasm or hyperdock_container.")
|
33
|
-
|
34
|
-
|
35
|
-
def __init__(
|
36
|
-
self,
|
37
|
-
tools: list[ToolLike],
|
38
|
-
auth: PocketAuth = None,
|
39
|
-
):
|
40
|
-
if auth is None:
|
41
|
-
auth = PocketAuth()
|
42
|
-
self.auth = auth
|
43
|
-
|
44
|
-
# filter strs out first and register the tools to default dock
|
45
|
-
str_tool_likes = [tool for tool in tools if (isinstance(tool, str) or isinstance(tool, tuple))]
|
46
|
-
function_tool_likes = [tool for tool in tools if (not isinstance(tool, str) and not isinstance(tool, Dock) and not isinstance(tool, tuple))]
|
47
|
-
# especially, docks are maintained by core
|
48
|
-
self.docks = [dock for dock in tools if isinstance(dock, Dock)]
|
49
|
-
|
50
|
-
if len(str_tool_likes) > 0:
|
51
|
-
default_dock = self._default_dock()
|
52
|
-
for str_tool_like in str_tool_likes:
|
53
|
-
default_dock.plug(req_like=str_tool_like)
|
54
|
-
# append default dock
|
55
|
-
self.docks.append(default_dock)
|
56
|
-
|
57
|
-
self.tools = dict()
|
58
|
-
|
59
|
-
# for each tool like, load the tool
|
60
|
-
for tool_like in function_tool_likes:
|
61
|
-
self._load_tool(tool_like)
|
62
|
-
|
63
|
-
for dock in self.docks:
|
64
|
-
tools = dock.tools()
|
65
|
-
for tool in tools:
|
66
|
-
self._load_tool(tool)
|
67
|
-
|
68
|
-
pocket_logger.info(
|
69
|
-
f"All Registered Tools Loaded successfully. total registered tools : {len(self.tools)}"
|
70
|
-
)
|
71
|
-
|
72
|
-
# load builtin tool
|
73
|
-
builtin_tools = get_builtin_tools(self.auth)
|
74
|
-
for tool in builtin_tools:
|
75
|
-
self.tools[tool.name] = tool
|
76
|
-
pocket_logger.info(
|
77
|
-
f"All BuiltIn Tools Loaded successfully. total tools : {len(self.tools)}"
|
78
|
-
)
|
79
|
-
|
80
|
-
async def acall(
|
81
|
-
self,
|
82
|
-
tool_name: str,
|
83
|
-
body: Any,
|
84
|
-
thread_id: str = "default",
|
85
|
-
profile: str = "default",
|
86
|
-
*args,
|
87
|
-
**kwargs,
|
88
|
-
) -> tuple[str, bool]:
|
89
|
-
"""
|
90
|
-
Invoke tool asynchronously, not that different from `Pocket.invoke`
|
91
|
-
But this method is called only in subprocess.
|
92
|
-
|
93
|
-
This function performs the following steps:
|
94
|
-
1. `prepare_auth` : preparing the authentication process for the tool if necessary.
|
95
|
-
2. `authenticate` : performing authentication that needs to invoke tool.
|
96
|
-
3. `tool_call` : Executing tool actually with authentication information.
|
97
|
-
|
98
|
-
Args:
|
99
|
-
tool_name(str): tool name to invoke
|
100
|
-
body(Any): tool arguments. should be json format
|
101
|
-
thread_id(str): thread id
|
102
|
-
profile(str): profile name
|
103
|
-
|
104
|
-
Returns:
|
105
|
-
tuple[str, bool]: tool result and state.
|
106
|
-
"""
|
107
|
-
tool = self._tool_instance(tool_name)
|
108
|
-
if tool.auth is not None:
|
109
|
-
callback_info = self.prepare_auth(tool_name, thread_id, profile, **kwargs)
|
110
|
-
if callback_info:
|
111
|
-
return callback_info, True
|
112
|
-
# 02. authenticate
|
113
|
-
credentials = await self.authenticate(tool_name, thread_id, profile, **kwargs)
|
114
|
-
# 03. call tool
|
115
|
-
result = await self.tool_call(tool_name, body=body, envs=credentials, **kwargs)
|
116
|
-
return result, False
|
117
|
-
|
118
|
-
def prepare_auth(
|
119
|
-
self,
|
120
|
-
tool_name: Union[str, List[str]],
|
121
|
-
thread_id: str = "default",
|
122
|
-
profile: str = "default",
|
123
|
-
**kwargs,
|
124
|
-
) -> Optional[str]:
|
125
|
-
"""
|
126
|
-
Prepares the authentication process for the tool if necessary.
|
127
|
-
Returns callback URL and whether the tool requires authentication.
|
128
|
-
|
129
|
-
Args:
|
130
|
-
tool_name(Union[str,List[str]]): tool name to invoke
|
131
|
-
thread_id(str): thread id
|
132
|
-
profile(str): profile name
|
133
|
-
|
134
|
-
Returns:
|
135
|
-
Optional[str]: callback URI if necessary
|
136
|
-
"""
|
137
|
-
|
138
|
-
if isinstance(tool_name, str):
|
139
|
-
tool_name = [tool_name]
|
140
|
-
|
141
|
-
tools: List[Tool] = []
|
142
|
-
for name in tool_name:
|
143
|
-
tool = self._tool_instance(name)
|
144
|
-
if tool.auth is not None:
|
145
|
-
tools.append(tool)
|
146
|
-
|
147
|
-
if len(tools) == 0:
|
148
|
-
return None
|
149
|
-
|
150
|
-
auth_handler_name = tools[0].auth.auth_handler
|
151
|
-
auth_provider = tools[0].auth.auth_provider
|
152
|
-
auth_scopes = set()
|
153
|
-
|
154
|
-
for tool in tools:
|
155
|
-
if tool.auth.auth_handler != auth_handler_name:
|
156
|
-
pocket_logger.error(
|
157
|
-
f"All Tools should have same auth handler. but it's different {tool.auth.auth_handler}, {auth_handler_name}"
|
158
|
-
)
|
159
|
-
|
160
|
-
return f"All Tools should have same auth handler. but it's different {tool.auth.auth_handler}, {auth_handler_name}"
|
161
|
-
if tool.auth.auth_provider != auth_provider:
|
162
|
-
pocket_logger.error(
|
163
|
-
f"All Tools should have same auth provider. but it's different {tool.auth.auth_provider}, {auth_provider}"
|
164
|
-
)
|
165
|
-
return f"All Tools should have same auth provider. but it's different {tool.auth.auth_provider}, {auth_provider}"
|
166
|
-
|
167
|
-
if tool.auth.scopes is not None:
|
168
|
-
auth_scopes |= set(tool.auth.scopes)
|
169
|
-
|
170
|
-
auth_req = self.auth.make_request(
|
171
|
-
auth_handler_name=auth_handler_name,
|
172
|
-
auth_provider=auth_provider,
|
173
|
-
auth_scopes=list(auth_scopes),
|
174
|
-
)
|
175
|
-
|
176
|
-
return self.auth.prepare(
|
177
|
-
auth_req=auth_req,
|
178
|
-
auth_handler_name=auth_handler_name,
|
179
|
-
auth_provider=auth_provider,
|
180
|
-
thread_id=thread_id,
|
181
|
-
profile=profile,
|
182
|
-
**kwargs,
|
183
|
-
)
|
184
|
-
|
185
|
-
async def authenticate(
|
186
|
-
self,
|
187
|
-
tool_name: str,
|
188
|
-
thread_id: str = "default",
|
189
|
-
profile: str = "default",
|
190
|
-
**kwargs,
|
191
|
-
) -> dict[str, str]:
|
192
|
-
"""
|
193
|
-
Authenticates the handler included in the tool and returns credentials.
|
194
|
-
|
195
|
-
Args:
|
196
|
-
tool_name(str): tool name to invoke
|
197
|
-
thread_id(str): thread id
|
198
|
-
profile(str): profile name
|
199
|
-
|
200
|
-
Returns:
|
201
|
-
dict[str, str]: credentials
|
202
|
-
"""
|
203
|
-
tool = self._tool_instance(tool_name)
|
204
|
-
if tool.auth is None:
|
205
|
-
return {}
|
206
|
-
auth_req = self.auth.make_request(
|
207
|
-
auth_handler_name=tool.auth.auth_handler,
|
208
|
-
auth_provider=tool.auth.auth_provider,
|
209
|
-
auth_scopes=tool.auth.scopes,
|
210
|
-
)
|
211
|
-
auth_ctx = await self.auth.authenticate_async(
|
212
|
-
auth_req=auth_req,
|
213
|
-
auth_handler_name=tool.auth.auth_handler,
|
214
|
-
auth_provider=tool.auth.auth_provider,
|
215
|
-
thread_id=thread_id,
|
216
|
-
profile=profile,
|
217
|
-
**kwargs,
|
218
|
-
)
|
219
|
-
return auth_ctx.to_dict()
|
220
|
-
|
221
|
-
async def tool_call(self, tool_name: str, **kwargs) -> str:
|
222
|
-
"""
|
223
|
-
Executing tool actually
|
224
|
-
|
225
|
-
Args:
|
226
|
-
tool_name(str): tool name to invoke
|
227
|
-
kwargs(dict): keyword arguments. authentication information is passed through this.
|
228
|
-
|
229
|
-
Returns:
|
230
|
-
str: tool result
|
231
|
-
"""
|
232
|
-
tool = self._tool_instance(tool_name)
|
233
|
-
try:
|
234
|
-
result = await asyncio.wait_for(tool.ainvoke(**kwargs), timeout=180)
|
235
|
-
except asyncio.TimeoutError:
|
236
|
-
pocket_logger.warning("Timeout tool call.")
|
237
|
-
return "timeout tool call"
|
238
|
-
|
239
|
-
if tool.postprocessings is not None:
|
240
|
-
for postprocessing in tool.postprocessings:
|
241
|
-
try:
|
242
|
-
result = postprocessing(result)
|
243
|
-
except Exception as e:
|
244
|
-
exception_str = (
|
245
|
-
f"Error in postprocessing `{postprocessing.__name__}`: {e}"
|
246
|
-
)
|
247
|
-
pocket_logger.error(exception_str)
|
248
|
-
return exception_str
|
249
|
-
|
250
|
-
return result
|
251
|
-
|
252
|
-
def grouping_tool_by_auth_provider(self) -> dict[str, List[Tool]]:
|
253
|
-
tool_by_provider = {}
|
254
|
-
for tool_name, tool in self.tools.items():
|
255
|
-
if tool.auth is None:
|
256
|
-
continue
|
257
|
-
|
258
|
-
auth_provider_name = tool.auth.auth_provider.name
|
259
|
-
if tool_by_provider.get(auth_provider_name):
|
260
|
-
tool_by_provider[auth_provider_name].append(tool)
|
261
|
-
else:
|
262
|
-
tool_by_provider[auth_provider_name] = [tool]
|
263
|
-
return tool_by_provider
|
264
|
-
|
265
|
-
def _tool_instance(self, tool_name: str) -> Tool:
|
266
|
-
return self.tools[tool_name]
|
267
|
-
|
268
|
-
def _load_tool(self, tool_like: ToolLike) -> Tool:
|
269
|
-
pocket_logger.info(f"Loading Tool {tool_like}")
|
270
|
-
if isinstance(tool_like, Tool):
|
271
|
-
tool = tool_like
|
272
|
-
elif isinstance(tool_like, Callable):
|
273
|
-
tool = from_func(tool_like)
|
274
|
-
else:
|
275
|
-
raise ValueError(f"Invalid tool type: {type(tool_like)}")
|
276
|
-
|
277
|
-
if tool.name in self.tools:
|
278
|
-
pocket_logger.error(f"Duplicate tool name: {tool.name}.")
|
279
|
-
raise ValueError(f"Duplicate tool name: {tool.name}")
|
280
|
-
self.tools[tool.name] = tool
|
281
|
-
|
282
|
-
pocket_logger.info(f"Complete Loading Tool {tool.name}")
|
283
|
-
return tool
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import abc
|
2
|
-
import pathlib
|
3
|
-
|
4
|
-
from pydantic import BaseModel
|
5
|
-
|
6
|
-
|
7
|
-
class ToolReference(BaseModel, abc.ABC):
|
8
|
-
tool_source: str = None
|
9
|
-
|
10
|
-
@abc.abstractmethod
|
11
|
-
def __str__(self):
|
12
|
-
raise NotImplementedError
|
13
|
-
|
14
|
-
@abc.abstractmethod
|
15
|
-
def key(self) -> str:
|
16
|
-
raise NotImplementedError
|
17
|
-
|
18
|
-
@abc.abstractmethod
|
19
|
-
def sync(self, **kwargs):
|
20
|
-
raise NotImplementedError
|
21
|
-
|
22
|
-
def eject_to_path(self, dest_path: pathlib.Path, src_sub_path: str = None):
|
23
|
-
## local locks are already tracked by git
|
24
|
-
raise NotImplementedError
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
File without changes
|
File without changes
|
File without changes
|