@blackhull/agentkit 0.0.0-stage → 0.1.1
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.
- package/LICENSE +202 -0
- package/README.md +65 -2
- package/dist/blackhullActionProvider.d.ts +78 -0
- package/dist/blackhullActionProvider.js +237 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/package.json +77 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @blackhull/agentkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/blackhull-systems/agentkit/actions/workflows/ci.yml) [](https://github.com/blackhull-systems/agentkit/actions/workflows/security.yml)
|
|
4
|
+
|
|
5
|
+
A [Coinbase AgentKit](https://github.com/coinbase/agentkit) action provider for **Blackhull**: checks your agent runs
|
|
6
|
+
*before* it pays or trades, sold per call over [x402](https://x402.org). Every answer is a measurement of public data
|
|
7
|
+
with its evidence. Facts, not financial advice.
|
|
8
|
+
|
|
9
|
+
| Action | What it answers | Price |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `check_token` | A Base token's owner, mint / pause / blacklist / fee powers in its code (proxies resolved), upgradeability and its pools' liquidity on Uniswap v2, v3 and v4, Aerodrome and Slipstream, with finding codes such as `CAN_MINT`, `UPGRADEABLE`, `THIN_LIQUIDITY` | $0.01 |
|
|
12
|
+
| `check_x402_service` | A paid x402 service's grade and finding codes (`detailed: true` for the full report with evidence) | $0.003 / $0.008 |
|
|
13
|
+
| `find_provider` | The best-rated paid providers for a job within a budget, ranked neutrally | $0.003 |
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @blackhull/agentkit
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { AgentKit } from "@coinbase/agentkit";
|
|
23
|
+
import { blackhullActionProvider } from "@blackhull/agentkit";
|
|
24
|
+
|
|
25
|
+
const agentkit = await AgentKit.from({
|
|
26
|
+
walletProvider, // any EVM wallet provider on base-mainnet
|
|
27
|
+
actionProviders: [blackhullActionProvider()], // add it next to your other providers
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Your agent's own wallet pays, in USDC on Base. It needs a little USDC (a dollar covers 100 token checks).
|
|
32
|
+
|
|
33
|
+
## Safety
|
|
34
|
+
|
|
35
|
+
- **Price cap:** every price quote is read before anything is signed, and a quote above `maxPriceUsdc` (default
|
|
36
|
+
`0.05`), or one whose price cannot be read, is refused. The cap applies to whichever client signs, including one you
|
|
37
|
+
bring; the client the provider builds from your wallet also has the x402 library's own spend cap. An invalid cap
|
|
38
|
+
(`NaN`, `Infinity`, zero or negative) is refused when the provider is created. To tighten it:
|
|
39
|
+
`blackhullActionProvider({ maxPriceUsdc: 0.02 })`.
|
|
40
|
+
- **No charge for no answer:** if Blackhull cannot answer (for example the chain cannot be read), it declines before the
|
|
41
|
+
payment settles.
|
|
42
|
+
- **Try it free:** `blackhullActionProvider({ trialMode: true })` answers each action's fixed sample query at no charge.
|
|
43
|
+
|
|
44
|
+
## Payment receipts and custom signers
|
|
45
|
+
|
|
46
|
+
A paid answer includes the settlement `receipt` (transaction hash, network, payer), so your agent can keep proof of
|
|
47
|
+
every check it bought. To pay through a custodial or policy-controlled signer instead of the agent's wallet, pass your
|
|
48
|
+
own client: `blackhullActionProvider({ x402Client })`.
|
|
49
|
+
|
|
50
|
+
## Verification
|
|
51
|
+
|
|
52
|
+
`npm test` runs the provider's safety behaviour offline (trial mode, the price cap with the wallet's client and with
|
|
53
|
+
your own, unreadable quotes, invalid caps, no charge for no answer, receipts), with nothing paid or sent, and fails
|
|
54
|
+
below its coverage thresholds. CI also runs Prettier, ESLint, the TypeScript compiler and the package checks (publint,
|
|
55
|
+
are-the-types-wrong) on Node 22 and 24, from the committed lockfile. Every release is also verified with a **real paid
|
|
56
|
+
call** through this provider's code, paid by Blackhull's own test wallet to Blackhull. [VERIFICATION.md](VERIFICATION.md) records that run
|
|
57
|
+
and its on-chain transaction.
|
|
58
|
+
|
|
59
|
+
Built and maintained by Blackhull's AI system; every release is reviewed and signed by its owner.
|
|
60
|
+
|
|
61
|
+
## Docs
|
|
62
|
+
|
|
63
|
+
Products, prices, codes and errors: <https://blackhullsystems.com/docs> · Terms: <https://blackhull.systems/terms>
|
|
64
|
+
|
|
65
|
+
Made by [Black Hull Systems LLC](https://blackhull.systems), veteran-owned, Charleston, South Carolina. Support:
|
|
66
|
+
support@blackhull.systems
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blackhull Action Provider for Coinbase AgentKit.
|
|
3
|
+
*
|
|
4
|
+
* Checks an agent should run BEFORE it pays or trades, sold per call over x402 by Blackhull (https://blackhull.systems):
|
|
5
|
+
* - check_token a Base token's owner, mint/pause/blacklist/fee powers, upgradeability and liquidity ($0.01)
|
|
6
|
+
* - check_x402_service grade and finding codes (or the full findings report) for a paid x402 service ($0.003-$0.008)
|
|
7
|
+
* - find_provider the best-rated paid providers for a job within a budget ($0.003)
|
|
8
|
+
* Every answer is a measurement of public data with its evidence. Facts, not financial advice.
|
|
9
|
+
*
|
|
10
|
+
* The agent's own wallet pays (or a client you bring). Every price quote is read before anything is signed, and any
|
|
11
|
+
* quote above maxPriceUsdc, or one that cannot be read, is refused.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { ActionProvider, EvmWalletProvider, Network } from "@coinbase/agentkit";
|
|
15
|
+
import { x402Client } from "@x402/fetch";
|
|
16
|
+
import type { ClientEvmSigner } from "@x402/evm";
|
|
17
|
+
export interface BlackhullConfig {
|
|
18
|
+
/** Most the provider will ever pay for one call, in USDC: a finite number of at least 0.000001 (default 0.05). */
|
|
19
|
+
maxPriceUsdc?: number;
|
|
20
|
+
/** Free trial: answer each action's fixed sample query (?sample=1) instead of paying. */
|
|
21
|
+
trialMode?: boolean;
|
|
22
|
+
/** Override the API origin (tests). */
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
/** Bring your own x402 payment client (e.g. a custodial or policy-controlled signer). Default: one built from the
|
|
25
|
+
* agent's wallet provider, as AgentKit's own x402 provider builds it. The price cap applies to either. */
|
|
26
|
+
x402Client?: x402Client;
|
|
27
|
+
}
|
|
28
|
+
export declare const CheckTokenSchema: z.ZodObject<{
|
|
29
|
+
address: z.ZodString;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
address: string;
|
|
32
|
+
}, {
|
|
33
|
+
address: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const CheckServiceSchema: z.ZodObject<{
|
|
36
|
+
url: z.ZodString;
|
|
37
|
+
detailed: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
url: string;
|
|
40
|
+
detailed?: boolean | undefined;
|
|
41
|
+
}, {
|
|
42
|
+
url: string;
|
|
43
|
+
detailed?: boolean | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
export declare const FindProviderSchema: z.ZodObject<{
|
|
46
|
+
capability: z.ZodString;
|
|
47
|
+
maxPriceUsdc: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
capability: string;
|
|
50
|
+
maxPriceUsdc?: number | undefined;
|
|
51
|
+
}, {
|
|
52
|
+
capability: string;
|
|
53
|
+
maxPriceUsdc?: number | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
export declare class BlackhullActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
56
|
+
private readonly base;
|
|
57
|
+
private readonly maxAtomic;
|
|
58
|
+
private readonly trial;
|
|
59
|
+
private readonly client?;
|
|
60
|
+
constructor(config?: BlackhullConfig);
|
|
61
|
+
checkToken(walletProvider: EvmWalletProvider, args: z.infer<typeof CheckTokenSchema>): Promise<string>;
|
|
62
|
+
checkService(walletProvider: EvmWalletProvider, args: z.infer<typeof CheckServiceSchema>): Promise<string>;
|
|
63
|
+
findProvider(walletProvider: EvmWalletProvider, args: z.infer<typeof FindProviderSchema>): Promise<string>;
|
|
64
|
+
supportsNetwork: (network: Network) => boolean;
|
|
65
|
+
/** One check: quote, refuse above the cap, pay, return the answer (or a JSON error, never a throw). */
|
|
66
|
+
call(walletProvider: EvmWalletProvider, path: string, query: Record<string, string>): Promise<string>;
|
|
67
|
+
private walletClient;
|
|
68
|
+
private answer;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The most an x402 v2 quote (its PAYMENT-REQUIRED header) can charge, in atomic USDC, taken over every payment option
|
|
72
|
+
* it offers, since the signing client picks the option. null when there is no header, it does not parse, or any option
|
|
73
|
+
* is not an integer amount of USDC on Base: a quote that cannot be read is never paid.
|
|
74
|
+
*/
|
|
75
|
+
export declare function quotedAtomic(quote: Response): number | null;
|
|
76
|
+
/** The x402 signer for an AgentKit wallet: the wallet's own account, reading the chain through the wallet provider. */
|
|
77
|
+
export declare function walletSigner(walletProvider: EvmWalletProvider): ClientEvmSigner;
|
|
78
|
+
export declare const blackhullActionProvider: (config?: BlackhullConfig) => BlackhullActionProvider;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.blackhullActionProvider = exports.BlackhullActionProvider = exports.FindProviderSchema = exports.CheckServiceSchema = exports.CheckTokenSchema = void 0;
|
|
13
|
+
exports.quotedAtomic = quotedAtomic;
|
|
14
|
+
exports.walletSigner = walletSigner;
|
|
15
|
+
/**
|
|
16
|
+
* Blackhull Action Provider for Coinbase AgentKit.
|
|
17
|
+
*
|
|
18
|
+
* Checks an agent should run BEFORE it pays or trades, sold per call over x402 by Blackhull (https://blackhull.systems):
|
|
19
|
+
* - check_token a Base token's owner, mint/pause/blacklist/fee powers, upgradeability and liquidity ($0.01)
|
|
20
|
+
* - check_x402_service grade and finding codes (or the full findings report) for a paid x402 service ($0.003-$0.008)
|
|
21
|
+
* - find_provider the best-rated paid providers for a job within a budget ($0.003)
|
|
22
|
+
* Every answer is a measurement of public data with its evidence. Facts, not financial advice.
|
|
23
|
+
*
|
|
24
|
+
* The agent's own wallet pays (or a client you bring). Every price quote is read before anything is signed, and any
|
|
25
|
+
* quote above maxPriceUsdc, or one that cannot be read, is refused.
|
|
26
|
+
*/
|
|
27
|
+
const zod_1 = require("zod");
|
|
28
|
+
const agentkit_1 = require("@coinbase/agentkit");
|
|
29
|
+
const fetch_1 = require("@x402/fetch");
|
|
30
|
+
const client_1 = require("@x402/evm/exact/client");
|
|
31
|
+
const version_1 = require("./version");
|
|
32
|
+
const UA = `blackhull-agentkit/${version_1.VERSION}`;
|
|
33
|
+
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
34
|
+
/** The only asset and network Blackhull is paid in: USDC on Base. */
|
|
35
|
+
const USDC_BASE = { network: "eip155:8453", asset: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" };
|
|
36
|
+
exports.CheckTokenSchema = zod_1.z
|
|
37
|
+
.object({ address: zod_1.z.string().regex(ADDRESS).describe("The token contract address on Base (0x + 40 hex)") })
|
|
38
|
+
.strip();
|
|
39
|
+
exports.CheckServiceSchema = zod_1.z
|
|
40
|
+
.object({
|
|
41
|
+
url: zod_1.z.string().url().describe("The x402 resource URL of the paid service to check"),
|
|
42
|
+
detailed: zod_1.z
|
|
43
|
+
.boolean()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe("Full findings report with evidence ($0.008) instead of grade and codes ($0.003)"),
|
|
46
|
+
})
|
|
47
|
+
.strip();
|
|
48
|
+
exports.FindProviderSchema = zod_1.z
|
|
49
|
+
.object({
|
|
50
|
+
capability: zod_1.z.string().min(1).describe("A category, e.g. search, ai-analysis, llm-inference, web-data, onchain"),
|
|
51
|
+
maxPriceUsdc: zod_1.z
|
|
52
|
+
.number()
|
|
53
|
+
.positive()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe("The most your agent will pay that provider per call, USDC"),
|
|
56
|
+
})
|
|
57
|
+
.strip();
|
|
58
|
+
/** Atomic USDC (6 decimals) as a plain decimal string, e.g. 10000 -> "0.01". */
|
|
59
|
+
const usdc = (atomic) => (atomic / 1e6).toString();
|
|
60
|
+
/** Thrown inside the payment path when a quote is refused, so nothing is signed; reported as a JSON error. */
|
|
61
|
+
class NotPaid extends Error {
|
|
62
|
+
}
|
|
63
|
+
class BlackhullActionProvider extends agentkit_1.ActionProvider {
|
|
64
|
+
base;
|
|
65
|
+
maxAtomic;
|
|
66
|
+
trial;
|
|
67
|
+
client;
|
|
68
|
+
constructor(config = {}) {
|
|
69
|
+
super("blackhull", []);
|
|
70
|
+
const max = config.maxPriceUsdc ?? 0.05;
|
|
71
|
+
// floor, so the cap is never above what was asked; NaN, Infinity or a cap that rounds to 0 is a setup error
|
|
72
|
+
const atomic = Math.floor(max * 1e6);
|
|
73
|
+
if (typeof max !== "number" || !Number.isFinite(max) || atomic < 1) {
|
|
74
|
+
throw new RangeError(`maxPriceUsdc must be a finite number of at least 0.000001 USDC, got ${String(max)}`);
|
|
75
|
+
}
|
|
76
|
+
this.base = new URL(config.baseUrl ?? "https://blackhullsystems.com").href.replace(/\/+$/, "");
|
|
77
|
+
this.maxAtomic = atomic;
|
|
78
|
+
this.trial = Boolean(config.trialMode);
|
|
79
|
+
this.client = config.x402Client;
|
|
80
|
+
}
|
|
81
|
+
async checkToken(walletProvider, args) {
|
|
82
|
+
return this.call(walletProvider, "/check/token", { address: args.address });
|
|
83
|
+
}
|
|
84
|
+
async checkService(walletProvider, args) {
|
|
85
|
+
return this.call(walletProvider, args.detailed ? "/verdict/x402" : "/flags", { url: args.url });
|
|
86
|
+
}
|
|
87
|
+
async findProvider(walletProvider, args) {
|
|
88
|
+
const q = { capability: args.capability };
|
|
89
|
+
if (args.maxPriceUsdc !== undefined)
|
|
90
|
+
q.max_price = String(args.maxPriceUsdc);
|
|
91
|
+
return this.call(walletProvider, "/route", q);
|
|
92
|
+
}
|
|
93
|
+
supportsNetwork = (network) => network.networkId === "base-mainnet";
|
|
94
|
+
/** One check: quote, refuse above the cap, pay, return the answer (or a JSON error, never a throw). */
|
|
95
|
+
async call(walletProvider, path, query) {
|
|
96
|
+
const url = new URL(this.base + path);
|
|
97
|
+
const headers = { "user-agent": UA };
|
|
98
|
+
try {
|
|
99
|
+
if (this.trial) {
|
|
100
|
+
url.searchParams.set("sample", "1");
|
|
101
|
+
return await this.answer(await fetch(url, { headers }), { trial: true });
|
|
102
|
+
}
|
|
103
|
+
for (const [k, v] of Object.entries(query))
|
|
104
|
+
url.searchParams.set(k, v);
|
|
105
|
+
let paidAtomic;
|
|
106
|
+
// The payment wrapper asks for the quote through this fetch and signs only what it returns, so the cap is
|
|
107
|
+
// checked on the very quote that gets signed, whichever x402 client signs it.
|
|
108
|
+
const guarded = async (input, init) => {
|
|
109
|
+
const res = await fetch(input, init);
|
|
110
|
+
if (res.status === 402) {
|
|
111
|
+
const amount = quotedAtomic(res);
|
|
112
|
+
if (amount === null)
|
|
113
|
+
throw new NotPaid("price unreadable or not in USDC on Base; not paid");
|
|
114
|
+
if (amount > this.maxAtomic) {
|
|
115
|
+
throw new NotPaid(`price ${usdc(amount)} USDC is above maxPriceUsdc ${usdc(this.maxAtomic)}; not paid`);
|
|
116
|
+
}
|
|
117
|
+
paidAtomic = amount;
|
|
118
|
+
}
|
|
119
|
+
return res;
|
|
120
|
+
};
|
|
121
|
+
const pay = (0, fetch_1.wrapFetchWithPayment)(guarded, this.client ?? this.walletClient(walletProvider));
|
|
122
|
+
const res = await pay(url.toString(), { headers });
|
|
123
|
+
// 404 and other non-402 answers are never charged
|
|
124
|
+
return await this.answer(res, paidAtomic !== undefined && res.ok ? { price_usdc: paidAtomic / 1e6 } : {});
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
return JSON.stringify({ error: true, message: e instanceof Error ? e.message : String(e) });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
walletClient(walletProvider) {
|
|
131
|
+
// a second, independent cap: the x402 library refuses to sign above it too
|
|
132
|
+
const client = new fetch_1.x402Client().setSpendControls({ maxAmountPerPayment: `$${usdc(this.maxAtomic)}` });
|
|
133
|
+
(0, client_1.registerExactEvmScheme)(client, { signer: walletSigner(walletProvider) });
|
|
134
|
+
return client;
|
|
135
|
+
}
|
|
136
|
+
async answer(res, extra) {
|
|
137
|
+
const text = await res.text();
|
|
138
|
+
let body = text;
|
|
139
|
+
try {
|
|
140
|
+
body = JSON.parse(text);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// not JSON: keep the text
|
|
144
|
+
}
|
|
145
|
+
if (!res.ok)
|
|
146
|
+
return JSON.stringify({ error: true, status: res.status, ...extra, body });
|
|
147
|
+
// the settlement receipt (transaction hash, network, payer), when a payment was made
|
|
148
|
+
const r = res.headers.get("payment-response") ?? res.headers.get("x-payment-response");
|
|
149
|
+
let receipt;
|
|
150
|
+
try {
|
|
151
|
+
receipt = r ? JSON.parse(Buffer.from(r, "base64").toString("utf8")) : undefined;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
receipt = undefined;
|
|
155
|
+
}
|
|
156
|
+
return JSON.stringify({ ...extra, ...(receipt ? { receipt } : {}), result: body });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.BlackhullActionProvider = BlackhullActionProvider;
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, agentkit_1.CreateAction)({
|
|
162
|
+
name: "check_token",
|
|
163
|
+
description: `Check a token on Base before trading it. Returns measured facts read live from the chain, each with its evidence:
|
|
164
|
+
who controls the contract (owner), whether its code can mint, pause, blacklist or change fees, whether it is an upgradeable
|
|
165
|
+
proxy, and how much WETH, ETH or USDC its pools hold on Uniswap v2, v3 and v4, Aerodrome and Slipstream, plus finding
|
|
166
|
+
codes such as OWNER_ACTIVE, CAN_MINT, UPGRADEABLE, THIN_LIQUIDITY or NO_POOL_FOUND. Costs $0.01 USDC per call via x402 (paid from this wallet). Facts, not financial advice.`,
|
|
167
|
+
schema: exports.CheckTokenSchema,
|
|
168
|
+
}),
|
|
169
|
+
__metadata("design:type", Function),
|
|
170
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
171
|
+
__metadata("design:returntype", Promise)
|
|
172
|
+
], BlackhullActionProvider.prototype, "checkToken", null);
|
|
173
|
+
__decorate([
|
|
174
|
+
(0, agentkit_1.CreateAction)({
|
|
175
|
+
name: "check_x402_service",
|
|
176
|
+
description: `Check a paid x402 service before your agent pays it: Blackhull's grade (CLEAN / CAUTION / WARNING /
|
|
177
|
+
INSUFFICIENT_DATA) and coded findings measured from on-chain payments — e.g. whether it is actually paid at its listed
|
|
178
|
+
price, by how many independent buyers, whether its demand is concentrated or self-funded. $0.003 for grade and codes,
|
|
179
|
+
$0.008 for the full report with evidence (detailed: true). Facts, not advice.`,
|
|
180
|
+
schema: exports.CheckServiceSchema,
|
|
181
|
+
}),
|
|
182
|
+
__metadata("design:type", Function),
|
|
183
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
184
|
+
__metadata("design:returntype", Promise)
|
|
185
|
+
], BlackhullActionProvider.prototype, "checkService", null);
|
|
186
|
+
__decorate([
|
|
187
|
+
(0, agentkit_1.CreateAction)({
|
|
188
|
+
name: "find_provider",
|
|
189
|
+
description: `Find the best-rated paid x402 providers for a job within a budget, ranked neutrally by grade, then
|
|
190
|
+
chain-verified buyers, then price (WARNING-graded providers excluded). $0.003 per call via x402.`,
|
|
191
|
+
schema: exports.FindProviderSchema,
|
|
192
|
+
}),
|
|
193
|
+
__metadata("design:type", Function),
|
|
194
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
195
|
+
__metadata("design:returntype", Promise)
|
|
196
|
+
], BlackhullActionProvider.prototype, "findProvider", null);
|
|
197
|
+
/**
|
|
198
|
+
* The most an x402 v2 quote (its PAYMENT-REQUIRED header) can charge, in atomic USDC, taken over every payment option
|
|
199
|
+
* it offers, since the signing client picks the option. null when there is no header, it does not parse, or any option
|
|
200
|
+
* is not an integer amount of USDC on Base: a quote that cannot be read is never paid.
|
|
201
|
+
*/
|
|
202
|
+
function quotedAtomic(quote) {
|
|
203
|
+
const h = quote.headers.get("payment-required");
|
|
204
|
+
if (!h)
|
|
205
|
+
return null;
|
|
206
|
+
let accepts;
|
|
207
|
+
try {
|
|
208
|
+
accepts = JSON.parse(Buffer.from(h, "base64").toString("utf8")).accepts;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
if (!Array.isArray(accepts) || accepts.length === 0)
|
|
214
|
+
return null;
|
|
215
|
+
let most = 0;
|
|
216
|
+
for (const a of accepts) {
|
|
217
|
+
const usdc = a.network === USDC_BASE.network && String(a.asset).toLowerCase() === USDC_BASE.asset;
|
|
218
|
+
if (!usdc || typeof a.amount !== "string" || !/^\d{1,15}$/.test(a.amount))
|
|
219
|
+
return null;
|
|
220
|
+
most = Math.max(most, Number(a.amount));
|
|
221
|
+
}
|
|
222
|
+
return most;
|
|
223
|
+
}
|
|
224
|
+
/** The x402 signer for an AgentKit wallet: the wallet's own account, reading the chain through the wallet provider. */
|
|
225
|
+
function walletSigner(walletProvider) {
|
|
226
|
+
return {
|
|
227
|
+
...walletProvider.toSigner(),
|
|
228
|
+
readContract: (a) => walletProvider.readContract({
|
|
229
|
+
address: a.address,
|
|
230
|
+
abi: a.abi,
|
|
231
|
+
functionName: a.functionName,
|
|
232
|
+
args: a.args,
|
|
233
|
+
}),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const blackhullActionProvider = (config) => new BlackhullActionProvider(config);
|
|
237
|
+
exports.blackhullActionProvider = blackhullActionProvider;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BlackhullActionProvider, blackhullActionProvider, type BlackhullConfig } from "./blackhullActionProvider";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blackhullActionProvider = exports.BlackhullActionProvider = void 0;
|
|
4
|
+
var blackhullActionProvider_1 = require("./blackhullActionProvider");
|
|
5
|
+
Object.defineProperty(exports, "BlackhullActionProvider", { enumerable: true, get: function () { return blackhullActionProvider_1.BlackhullActionProvider; } });
|
|
6
|
+
Object.defineProperty(exports, "blackhullActionProvider", { enumerable: true, get: function () { return blackhullActionProvider_1.blackhullActionProvider; } });
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackhull/agentkit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Coinbase AgentKit action provider for Blackhull: check a Base token, an x402 service or find the best provider before your agent pays or trades. Paid per call over x402; facts with evidence, not advice.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Black Hull Systems LLC <support@blackhull.systems>",
|
|
7
|
+
"homepage": "https://blackhullsystems.com/docs",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/blackhull-systems/agentkit.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/blackhull-systems/agentkit/issues",
|
|
14
|
+
"email": "support@blackhull.systems"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"agentkit",
|
|
18
|
+
"x402",
|
|
19
|
+
"base",
|
|
20
|
+
"ai-agents",
|
|
21
|
+
"token-risk",
|
|
22
|
+
"action-provider",
|
|
23
|
+
"blackhull"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"type": "commonjs",
|
|
29
|
+
"main": "dist/index.js",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist/*.js",
|
|
40
|
+
"dist/*.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"lint": "eslint --max-warnings 0 .",
|
|
46
|
+
"format": "prettier --write .",
|
|
47
|
+
"format:check": "prettier --check .",
|
|
48
|
+
"test": "npm run build && node --test --experimental-test-coverage --test-coverage-include=dist/** --test-coverage-lines=95 --test-coverage-branches=90 --test-coverage-functions=95 test/*.test.cjs",
|
|
49
|
+
"check:package": "npm run build && publint --strict && attw --pack . --profile node16",
|
|
50
|
+
"check": "npm run format:check && npm run lint && npm run typecheck && npm test && npm run check:package",
|
|
51
|
+
"prepublishOnly": "npm run check"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@coinbase/agentkit": "^0.10.0"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@x402/evm": "^2.29.0",
|
|
58
|
+
"@x402/fetch": "^2.29.0",
|
|
59
|
+
"zod": "^3.23.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
63
|
+
"@coinbase/agentkit": "^0.10.4",
|
|
64
|
+
"@eslint/js": "^10.0.1",
|
|
65
|
+
"@types/node": "^22.20.5",
|
|
66
|
+
"eslint": "^10.14.0",
|
|
67
|
+
"eslint-config-prettier": "^10.1.8",
|
|
68
|
+
"globals": "^17.14.0",
|
|
69
|
+
"prettier": "^3.9.10",
|
|
70
|
+
"publint": "^0.3.25",
|
|
71
|
+
"typescript": "~6.0.3",
|
|
72
|
+
"typescript-eslint": "^8.72.1",
|
|
73
|
+
"viem": "^2.57.16"
|
|
74
|
+
},
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public",
|
|
77
|
+
"provenance": true
|
|
78
|
+
}
|
|
79
|
+
}
|