dominusnode-langchain 1.0.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.
- dominusnode_langchain/__init__.py +55 -0
- dominusnode_langchain/toolkit.py +195 -0
- dominusnode_langchain/tools.py +1706 -0
- dominusnode_langchain-1.0.0.dist-info/METADATA +220 -0
- dominusnode_langchain-1.0.0.dist-info/RECORD +7 -0
- dominusnode_langchain-1.0.0.dist-info/WHEEL +4 -0
- dominusnode_langchain-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""LangChain tools for DomiNode rotating proxy service.
|
|
2
|
+
|
|
3
|
+
Provides LangChain-compatible tools for making proxied HTTP requests,
|
|
4
|
+
checking wallet balance, viewing usage statistics, and querying proxy
|
|
5
|
+
configuration through the DomiNode platform.
|
|
6
|
+
|
|
7
|
+
Example::
|
|
8
|
+
|
|
9
|
+
from dominusnode_langchain import DominusNodeToolkit
|
|
10
|
+
|
|
11
|
+
toolkit = DominusNodeToolkit(api_key="dn_live_...", base_url="http://localhost:3000")
|
|
12
|
+
tools = toolkit.get_tools()
|
|
13
|
+
|
|
14
|
+
# Use with a LangChain agent
|
|
15
|
+
from langchain.agents import AgentExecutor, create_tool_calling_agent
|
|
16
|
+
agent = create_tool_calling_agent(llm, tools, prompt)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .tools import (
|
|
20
|
+
DominusNodeAgenticTransactionsTool,
|
|
21
|
+
DominusNodeAgenticWalletBalanceTool,
|
|
22
|
+
DominusNodeBalanceTool,
|
|
23
|
+
DominusNodeCreateAgenticWalletTool,
|
|
24
|
+
DominusNodeDeleteAgenticWalletTool,
|
|
25
|
+
DominusNodeFreezeAgenticWalletTool,
|
|
26
|
+
DominusNodeFundAgenticWalletTool,
|
|
27
|
+
DominusNodeListAgenticWalletsTool,
|
|
28
|
+
DominusNodeProxiedFetchTool,
|
|
29
|
+
DominusNodeProxyConfigTool,
|
|
30
|
+
DominusNodeTopupPaypalTool,
|
|
31
|
+
DominusNodeUnfreezeAgenticWalletTool,
|
|
32
|
+
DominusNodeUpdateWalletPolicyTool,
|
|
33
|
+
DominusNodeUsageTool,
|
|
34
|
+
DominusNodeX402InfoTool,
|
|
35
|
+
)
|
|
36
|
+
from .toolkit import DominusNodeToolkit
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"DominusNodeToolkit",
|
|
40
|
+
"DominusNodeProxiedFetchTool",
|
|
41
|
+
"DominusNodeBalanceTool",
|
|
42
|
+
"DominusNodeUsageTool",
|
|
43
|
+
"DominusNodeProxyConfigTool",
|
|
44
|
+
"DominusNodeTopupPaypalTool",
|
|
45
|
+
"DominusNodeX402InfoTool",
|
|
46
|
+
"DominusNodeCreateAgenticWalletTool",
|
|
47
|
+
"DominusNodeFundAgenticWalletTool",
|
|
48
|
+
"DominusNodeAgenticWalletBalanceTool",
|
|
49
|
+
"DominusNodeListAgenticWalletsTool",
|
|
50
|
+
"DominusNodeAgenticTransactionsTool",
|
|
51
|
+
"DominusNodeFreezeAgenticWalletTool",
|
|
52
|
+
"DominusNodeUnfreezeAgenticWalletTool",
|
|
53
|
+
"DominusNodeDeleteAgenticWalletTool",
|
|
54
|
+
"DominusNodeUpdateWalletPolicyTool",
|
|
55
|
+
]
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""DomiNode LangChain Toolkit -- bundles all DomiNode tools for agent use.
|
|
2
|
+
|
|
3
|
+
The :class:`DominusNodeToolkit` creates a :class:`DominusNodeClient` internally
|
|
4
|
+
and injects it into each tool so that a single authenticated session is shared
|
|
5
|
+
across all tools in a LangChain agent.
|
|
6
|
+
|
|
7
|
+
Example::
|
|
8
|
+
|
|
9
|
+
from dominusnode_langchain import DominusNodeToolkit
|
|
10
|
+
|
|
11
|
+
toolkit = DominusNodeToolkit(
|
|
12
|
+
api_key="dn_live_abc123",
|
|
13
|
+
base_url="http://localhost:3000",
|
|
14
|
+
)
|
|
15
|
+
tools = toolkit.get_tools()
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
from typing import List, Optional
|
|
22
|
+
|
|
23
|
+
from langchain_core.tools import BaseTool, BaseToolkit
|
|
24
|
+
|
|
25
|
+
from dominusnode import AsyncDominusNodeClient, DominusNodeClient
|
|
26
|
+
|
|
27
|
+
from .tools import (
|
|
28
|
+
DominusNodeAgenticTransactionsTool,
|
|
29
|
+
DominusNodeAgenticWalletBalanceTool,
|
|
30
|
+
DominusNodeBalanceTool,
|
|
31
|
+
DominusNodeCreateAgenticWalletTool,
|
|
32
|
+
DominusNodeDeleteAgenticWalletTool,
|
|
33
|
+
DominusNodeFreezeAgenticWalletTool,
|
|
34
|
+
DominusNodeFundAgenticWalletTool,
|
|
35
|
+
DominusNodeListAgenticWalletsTool,
|
|
36
|
+
DominusNodeProxiedFetchTool,
|
|
37
|
+
DominusNodeProxyConfigTool,
|
|
38
|
+
DominusNodeTopupPaypalTool,
|
|
39
|
+
DominusNodeUnfreezeAgenticWalletTool,
|
|
40
|
+
DominusNodeUpdateWalletPolicyTool,
|
|
41
|
+
DominusNodeUsageTool,
|
|
42
|
+
DominusNodeX402InfoTool,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class DominusNodeToolkit(BaseToolkit):
|
|
47
|
+
"""LangChain toolkit that provides all DomiNode proxy service tools.
|
|
48
|
+
|
|
49
|
+
Creates and manages a :class:`DominusNodeClient` (sync) and optionally
|
|
50
|
+
an :class:`AsyncDominusNodeClient` (async) for use by LangChain agents.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
api_key: DomiNode API key (``dn_live_...``). Falls back to the
|
|
54
|
+
``DOMINUSNODE_API_KEY`` environment variable if not provided.
|
|
55
|
+
base_url: Base URL for the DomiNode REST API. Falls back to
|
|
56
|
+
``DOMINUSNODE_BASE_URL`` or the SDK default.
|
|
57
|
+
proxy_host: Hostname of the DomiNode proxy server. Falls back to
|
|
58
|
+
``DOMINUSNODE_PROXY_HOST`` or the SDK default.
|
|
59
|
+
http_proxy_port: HTTP proxy port (default 8080).
|
|
60
|
+
socks5_proxy_port: SOCKS5 proxy port (default 1080).
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
ValueError: If no API key is provided or found in environment.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
# Stored so tools can reference them; not exposed to LLM
|
|
67
|
+
_sync_client: Optional[DominusNodeClient] = None
|
|
68
|
+
_async_client: Optional[AsyncDominusNodeClient] = None
|
|
69
|
+
_tools: Optional[List[BaseTool]] = None
|
|
70
|
+
|
|
71
|
+
model_config = {"arbitrary_types_allowed": True}
|
|
72
|
+
|
|
73
|
+
def __init__(
|
|
74
|
+
self,
|
|
75
|
+
api_key: Optional[str] = None,
|
|
76
|
+
base_url: Optional[str] = None,
|
|
77
|
+
*,
|
|
78
|
+
proxy_host: Optional[str] = None,
|
|
79
|
+
http_proxy_port: int = 8080,
|
|
80
|
+
socks5_proxy_port: int = 1080,
|
|
81
|
+
) -> None:
|
|
82
|
+
super().__init__()
|
|
83
|
+
|
|
84
|
+
resolved_key = api_key or os.environ.get("DOMINUSNODE_API_KEY")
|
|
85
|
+
if not resolved_key:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
"A DomiNode API key is required. Pass api_key= or set the "
|
|
88
|
+
"DOMINUSNODE_API_KEY environment variable."
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
resolved_base = base_url or os.environ.get(
|
|
92
|
+
"DOMINUSNODE_BASE_URL", "https://api.dominusnode.com"
|
|
93
|
+
)
|
|
94
|
+
resolved_proxy_host = proxy_host or os.environ.get(
|
|
95
|
+
"DOMINUSNODE_PROXY_HOST", "proxy.dominusnode.com"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# Store credentials for agentic wallet tools (direct REST API calls)
|
|
99
|
+
self._api_key = resolved_key
|
|
100
|
+
self._base_url = resolved_base
|
|
101
|
+
|
|
102
|
+
# Create sync client
|
|
103
|
+
self._sync_client = DominusNodeClient(
|
|
104
|
+
base_url=resolved_base,
|
|
105
|
+
api_key=resolved_key,
|
|
106
|
+
proxy_host=resolved_proxy_host,
|
|
107
|
+
http_proxy_port=http_proxy_port,
|
|
108
|
+
socks5_proxy_port=socks5_proxy_port,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Create async client (deferred connect -- will connect in __aenter__)
|
|
112
|
+
self._async_client = AsyncDominusNodeClient(
|
|
113
|
+
base_url=resolved_base,
|
|
114
|
+
api_key=resolved_key,
|
|
115
|
+
proxy_host=resolved_proxy_host,
|
|
116
|
+
http_proxy_port=http_proxy_port,
|
|
117
|
+
socks5_proxy_port=socks5_proxy_port,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Build tools once
|
|
121
|
+
self._tools = self._build_tools()
|
|
122
|
+
|
|
123
|
+
def _build_tools(self) -> List[BaseTool]:
|
|
124
|
+
"""Construct tool instances with injected clients."""
|
|
125
|
+
fetch_tool = DominusNodeProxiedFetchTool(
|
|
126
|
+
sync_client=self._sync_client,
|
|
127
|
+
async_client=self._async_client,
|
|
128
|
+
)
|
|
129
|
+
balance_tool = DominusNodeBalanceTool(
|
|
130
|
+
sync_client=self._sync_client,
|
|
131
|
+
async_client=self._async_client,
|
|
132
|
+
)
|
|
133
|
+
usage_tool = DominusNodeUsageTool(
|
|
134
|
+
sync_client=self._sync_client,
|
|
135
|
+
async_client=self._async_client,
|
|
136
|
+
)
|
|
137
|
+
config_tool = DominusNodeProxyConfigTool(
|
|
138
|
+
sync_client=self._sync_client,
|
|
139
|
+
async_client=self._async_client,
|
|
140
|
+
)
|
|
141
|
+
topup_paypal_tool = DominusNodeTopupPaypalTool(
|
|
142
|
+
sync_client=self._sync_client,
|
|
143
|
+
async_client=self._async_client,
|
|
144
|
+
)
|
|
145
|
+
x402_info_tool = DominusNodeX402InfoTool(
|
|
146
|
+
sync_client=self._sync_client,
|
|
147
|
+
async_client=self._async_client,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Agentic wallet tools use direct REST API calls
|
|
151
|
+
_ak = self._api_key
|
|
152
|
+
_bu = self._base_url
|
|
153
|
+
create_wallet_tool = DominusNodeCreateAgenticWalletTool(api_key=_ak, base_url=_bu)
|
|
154
|
+
fund_wallet_tool = DominusNodeFundAgenticWalletTool(api_key=_ak, base_url=_bu)
|
|
155
|
+
wallet_balance_tool = DominusNodeAgenticWalletBalanceTool(api_key=_ak, base_url=_bu)
|
|
156
|
+
list_wallets_tool = DominusNodeListAgenticWalletsTool(api_key=_ak, base_url=_bu)
|
|
157
|
+
transactions_tool = DominusNodeAgenticTransactionsTool(api_key=_ak, base_url=_bu)
|
|
158
|
+
freeze_tool = DominusNodeFreezeAgenticWalletTool(api_key=_ak, base_url=_bu)
|
|
159
|
+
unfreeze_tool = DominusNodeUnfreezeAgenticWalletTool(api_key=_ak, base_url=_bu)
|
|
160
|
+
delete_wallet_tool = DominusNodeDeleteAgenticWalletTool(api_key=_ak, base_url=_bu)
|
|
161
|
+
update_policy_tool = DominusNodeUpdateWalletPolicyTool(api_key=_ak, base_url=_bu)
|
|
162
|
+
|
|
163
|
+
return [
|
|
164
|
+
fetch_tool,
|
|
165
|
+
balance_tool,
|
|
166
|
+
usage_tool,
|
|
167
|
+
config_tool,
|
|
168
|
+
topup_paypal_tool,
|
|
169
|
+
x402_info_tool,
|
|
170
|
+
create_wallet_tool,
|
|
171
|
+
fund_wallet_tool,
|
|
172
|
+
wallet_balance_tool,
|
|
173
|
+
list_wallets_tool,
|
|
174
|
+
transactions_tool,
|
|
175
|
+
freeze_tool,
|
|
176
|
+
unfreeze_tool,
|
|
177
|
+
delete_wallet_tool,
|
|
178
|
+
update_policy_tool,
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
def get_tools(self) -> List[BaseTool]:
|
|
182
|
+
"""Return the list of DomiNode LangChain tools."""
|
|
183
|
+
if self._tools is None:
|
|
184
|
+
self._tools = self._build_tools()
|
|
185
|
+
return list(self._tools)
|
|
186
|
+
|
|
187
|
+
def close(self) -> None:
|
|
188
|
+
"""Close the underlying SDK clients and release resources."""
|
|
189
|
+
if self._sync_client is not None:
|
|
190
|
+
self._sync_client.close()
|
|
191
|
+
self._sync_client = None
|
|
192
|
+
if self._async_client is not None:
|
|
193
|
+
self._async_client.close()
|
|
194
|
+
self._async_client = None
|
|
195
|
+
self._tools = None
|