@absol-labs/agent 0.4.0 → 0.6.0
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/README.md +187 -0
- package/dist/capability/invocation-capability.d.ts +184 -0
- package/dist/capability/invocation-capability.d.ts.map +1 -0
- package/dist/capability/invocation-capability.js +183 -0
- package/dist/capability/invocation-capability.js.map +1 -0
- package/dist/discovery/registry.d.ts +260 -15
- package/dist/discovery/registry.d.ts.map +1 -1
- package/dist/discovery/registry.js +174 -31
- package/dist/discovery/registry.js.map +1 -1
- package/dist/frameworks/agentkit.js +3 -3
- package/dist/frameworks/agentkit.js.map +1 -1
- package/dist/frameworks/crewai.js +1 -1
- package/dist/frameworks/crewai.js.map +1 -1
- package/dist/frameworks/eliza.js +2 -2
- package/dist/frameworks/eliza.js.map +1 -1
- package/dist/frameworks/langchain.js +2 -2
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/gateway/caller-auth-gateway.d.ts +108 -0
- package/dist/gateway/caller-auth-gateway.d.ts.map +1 -0
- package/dist/gateway/caller-auth-gateway.js +191 -0
- package/dist/gateway/caller-auth-gateway.js.map +1 -0
- package/dist/gateway/http-server.d.ts +51 -0
- package/dist/gateway/http-server.d.ts.map +1 -0
- package/dist/gateway/http-server.js +241 -0
- package/dist/gateway/http-server.js.map +1 -0
- package/dist/gateway/server-entry.d.ts +2 -0
- package/dist/gateway/server-entry.d.ts.map +1 -0
- package/dist/gateway/server-entry.js +30 -0
- package/dist/gateway/server-entry.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.js +4 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/sdk/invoke.d.ts +136 -0
- package/dist/sdk/invoke.d.ts.map +1 -0
- package/dist/sdk/invoke.js +274 -0
- package/dist/sdk/invoke.js.map +1 -0
- package/dist/wallet/lifecycle.d.ts +101 -0
- package/dist/wallet/lifecycle.d.ts.map +1 -0
- package/dist/wallet/lifecycle.js +57 -0
- package/dist/wallet/lifecycle.js.map +1 -0
- package/package.json +6 -3
- package/src/capability/invocation-capability.ts +255 -0
- package/src/discovery/registry.ts +213 -35
- package/src/frameworks/agentkit.ts +3 -3
- package/src/frameworks/crewai.ts +1 -1
- package/src/frameworks/eliza.ts +2 -2
- package/src/frameworks/langchain.ts +2 -2
- package/src/gateway/caller-auth-gateway.ts +332 -0
- package/src/gateway/http-server.ts +342 -0
- package/src/gateway/server-entry.ts +38 -0
- package/src/index.ts +86 -0
- package/src/mcp/server.ts +4 -2
- package/src/sdk/invoke.ts +495 -0
- package/src/wallet/lifecycle.ts +158 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { erc20Abi, type Address } from "viem";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent wallet lifecycle helpers (metrik-agent#65).
|
|
5
|
+
*
|
|
6
|
+
* `../wallet/provider.ts` already resolves a wallet (injected key or a
|
|
7
|
+
* Coinbase CDP Server Wallet v2 account) and hands back a viem `Account` that
|
|
8
|
+
* can sign directly — `resolveAgentWallet()`'s CDP path is create-OR-restore
|
|
9
|
+
* by construction (`cdp.evm.getOrCreateAccount({ name })` is idempotent: the
|
|
10
|
+
* same `ownerName` always resolves to the same on-chain address, so a second
|
|
11
|
+
* run with the same env "restores" rather than creates a new wallet).
|
|
12
|
+
*
|
|
13
|
+
* This module adds the remaining thin, non-custodial lifecycle pieces the
|
|
14
|
+
* issue asks for: reading balances, a testnet faucet hint, and requesting
|
|
15
|
+
* funds from the CDP faucet. It deliberately does NOT wrap signing — a
|
|
16
|
+
* `ResolvedAgentWallet.account` is already a plain viem `Account`
|
|
17
|
+
* (`signMessage` / `signTypedData` / `signTransaction` all work as-is), and
|
|
18
|
+
* adding a second signing surface here would be exactly the "second wallet
|
|
19
|
+
* system" AGENTS.md warns against.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** Native gas balance + USDC balance for one address. */
|
|
23
|
+
export interface WalletBalances {
|
|
24
|
+
/** Native token balance (ETH on Base/Base Sepolia), in wei. */
|
|
25
|
+
readonly nativeWei: bigint;
|
|
26
|
+
/** USDC balance, in atomic units (6 decimals). */
|
|
27
|
+
readonly usdcAtomic: bigint;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The subset of a viem `PublicClient` balance reads need. Duck-typed so any real client satisfies it. */
|
|
31
|
+
export interface BalanceReader {
|
|
32
|
+
getBalance(args: { readonly address: Address }): Promise<bigint>;
|
|
33
|
+
readContract(args: {
|
|
34
|
+
readonly address: Address;
|
|
35
|
+
readonly abi: typeof erc20Abi;
|
|
36
|
+
readonly functionName: "balanceOf";
|
|
37
|
+
readonly args: readonly [Address];
|
|
38
|
+
}): Promise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface GetWalletBalancesOptions {
|
|
42
|
+
readonly publicClient: BalanceReader;
|
|
43
|
+
readonly address: Address;
|
|
44
|
+
/** The USDC token contract to read the ERC-20 balance from. */
|
|
45
|
+
readonly usdc: Address;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Reads a wallet's native gas balance and USDC balance in one call. Read-only — no signing, no writes. */
|
|
49
|
+
export async function getWalletBalances(
|
|
50
|
+
options: GetWalletBalancesOptions,
|
|
51
|
+
): Promise<WalletBalances> {
|
|
52
|
+
const [nativeWei, usdcAtomic] = await Promise.all([
|
|
53
|
+
options.publicClient.getBalance({ address: options.address }),
|
|
54
|
+
options.publicClient.readContract({
|
|
55
|
+
address: options.usdc,
|
|
56
|
+
abi: erc20Abi,
|
|
57
|
+
functionName: "balanceOf",
|
|
58
|
+
args: [options.address],
|
|
59
|
+
}),
|
|
60
|
+
]);
|
|
61
|
+
return { nativeWei, usdcAtomic: usdcAtomic as bigint };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Human-facing pointers to fund a freshly created/restored testnet wallet. */
|
|
65
|
+
export interface FaucetHint {
|
|
66
|
+
readonly network: string;
|
|
67
|
+
/** Coinbase CDP faucet — funds native ETH (and, on some networks, USDC) for a CDP-managed address. */
|
|
68
|
+
readonly cdpFaucetUrl: string;
|
|
69
|
+
/** Circle's own Base Sepolia USDC faucet — an alternative USDC source that doesn't require a CDP account. */
|
|
70
|
+
readonly usdcFaucetUrl: string;
|
|
71
|
+
/** How to request the same funds programmatically from a CDP wallet — see {@link requestCdpFaucet}. */
|
|
72
|
+
readonly programmaticHint: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class UnsupportedFaucetChainError extends Error {
|
|
76
|
+
constructor(chainId: number) {
|
|
77
|
+
super(
|
|
78
|
+
`no known testnet faucet for chainId ${chainId} (Metrik is Base Sepolia (84532) only)`,
|
|
79
|
+
);
|
|
80
|
+
this.name = "UnsupportedFaucetChainError";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
85
|
+
|
|
86
|
+
const BASE_SEPOLIA_FAUCET_HINT: FaucetHint = {
|
|
87
|
+
network: "base-sepolia",
|
|
88
|
+
cdpFaucetUrl: "https://portal.cdp.coinbase.com/products/faucet",
|
|
89
|
+
usdcFaucetUrl: "https://faucet.circle.com",
|
|
90
|
+
programmaticHint:
|
|
91
|
+
"requestCdpFaucet({ cdp, address, token: 'eth' | 'usdc' }) — subject to a 24h per-address rate limit",
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** A faucet hint for the given chain. Only Base Sepolia (84532) is supported — Metrik is testnet-only, single-chain. */
|
|
95
|
+
export function faucetHint(chainId: number): FaucetHint {
|
|
96
|
+
if (chainId !== BASE_SEPOLIA_CHAIN_ID) {
|
|
97
|
+
throw new UnsupportedFaucetChainError(chainId);
|
|
98
|
+
}
|
|
99
|
+
return BASE_SEPOLIA_FAUCET_HINT;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type FaucetToken = "eth" | "usdc";
|
|
103
|
+
|
|
104
|
+
/** The subset of the Coinbase CDP client the faucet request needs. Duck-typed for testability. */
|
|
105
|
+
export interface CdpFaucetClientLike {
|
|
106
|
+
readonly evm: {
|
|
107
|
+
requestFaucet(options: {
|
|
108
|
+
readonly address: Address;
|
|
109
|
+
readonly network: string;
|
|
110
|
+
readonly token: FaucetToken;
|
|
111
|
+
}): Promise<{ readonly transactionHash: string }>;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface RequestCdpFaucetOptions {
|
|
116
|
+
readonly cdp: CdpFaucetClientLike;
|
|
117
|
+
readonly address: Address;
|
|
118
|
+
readonly token: FaucetToken;
|
|
119
|
+
/** Default `"base-sepolia"`. */
|
|
120
|
+
readonly network?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface FaucetRequestResult {
|
|
124
|
+
/** `true` iff the faucet accepted the request (a tx hash was returned). */
|
|
125
|
+
readonly requested: boolean;
|
|
126
|
+
readonly txHash?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Set when `requested` is `false`. The CDP faucet enforces a 24h per-address
|
|
129
|
+
* rate limit, so a failure here is an EXPECTED, non-fatal outcome — never
|
|
130
|
+
* thrown. Callers should log this and fall back to checking whether the
|
|
131
|
+
* balance is already sufficient.
|
|
132
|
+
*/
|
|
133
|
+
readonly error?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Requests testnet funds from the Coinbase CDP faucet for a CDP-managed
|
|
138
|
+
* address. Tolerates the faucet's 24h rate limit and any other request
|
|
139
|
+
* failure by returning `{ requested: false, error }` — it never throws, so a
|
|
140
|
+
* caller can always fall through to reading the current balance instead.
|
|
141
|
+
*/
|
|
142
|
+
export async function requestCdpFaucet(
|
|
143
|
+
options: RequestCdpFaucetOptions,
|
|
144
|
+
): Promise<FaucetRequestResult> {
|
|
145
|
+
try {
|
|
146
|
+
const result = await options.cdp.evm.requestFaucet({
|
|
147
|
+
address: options.address,
|
|
148
|
+
network: options.network ?? "base-sepolia",
|
|
149
|
+
token: options.token,
|
|
150
|
+
});
|
|
151
|
+
return { requested: true, txHash: result.transactionHash };
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return {
|
|
154
|
+
requested: false,
|
|
155
|
+
error: error instanceof Error ? error.message : String(error),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|