@circuitorg/agent-sdk 1.0.8 → 1.0.11
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 +268 -10
- package/index.d.ts +177 -96
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,18 +15,18 @@ A TypeScript SDK for building automated agents to deploy on Circuit. Features a
|
|
|
15
15
|
## 🚀 Quick Start
|
|
16
16
|
### Install the SDK
|
|
17
17
|
```bash
|
|
18
|
-
npm install @circuitorg/
|
|
18
|
+
npm install @circuitorg/agent-sdk
|
|
19
19
|
# or
|
|
20
|
-
yarn add @circuitorg/
|
|
20
|
+
yarn add @circuitorg/agent-sdk
|
|
21
21
|
# or
|
|
22
|
-
bun add @circuitorg/
|
|
22
|
+
bun add @circuitorg/agent-sdk
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Sample SDK Usage
|
|
26
26
|
>**NOTE:** The fastest, and recommended, way to get started is to setup an agent via the circuit [CLI](https://github.com/circuitorg/agents-cli)'s 'circuit agent init' command. This will setup a sample agent directory with the necessary agent wireframe, and configure the cli to allow you for easy testing and deployment. You just simply need to add in your secret formula to the execution and stop functions.
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
|
-
import { AgentSdk } from "@circuitorg/
|
|
29
|
+
import { AgentSdk } from "@circuitorg/agent-sdk";
|
|
30
30
|
|
|
31
31
|
// Initialize the sdk
|
|
32
32
|
const sdk = new AgentSdk({
|
|
@@ -84,12 +84,13 @@ await sdk.signAndSend({
|
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
## 🔧
|
|
87
|
+
## 🔧 Examples
|
|
88
88
|
|
|
89
|
-
###
|
|
89
|
+
### Barebones Agent
|
|
90
|
+
>This is the wireframe structure all agents need to have (executionFunction, stopFunction, and export default agent.getWorkerExport()). The main thing an agent dev needs to focus on is the execution logic, and any cleanup logic that would need to be ran whenever a user decides to stop an agent session.
|
|
90
91
|
|
|
91
92
|
```typescript
|
|
92
|
-
import { Agent, AgentSdk, ExecutionFunctionContract, StopFunctionContract } from "@circuitorg/
|
|
93
|
+
import { Agent, AgentSdk, ExecutionFunctionContract, StopFunctionContract } from "@circuitorg/agent-sdk";
|
|
93
94
|
|
|
94
95
|
// Agent execution function using the new AgentSdk v1.0 API
|
|
95
96
|
const executionFunction: ExecutionFunctionContract = async (request) => {
|
|
@@ -138,12 +139,269 @@ const stopFunction: StopFunctionContract = async (request) => {
|
|
|
138
139
|
// DONT MODIFY BELOW THIS
|
|
139
140
|
const agent = new Agent({ executionFunction, stopFunction });
|
|
140
141
|
|
|
141
|
-
// Start the server for local development
|
|
142
|
-
agent.run();
|
|
143
|
-
|
|
144
142
|
// Export the agent for Cloudflare Workers
|
|
145
143
|
export default agent.getWorkerExport();
|
|
146
144
|
|
|
147
145
|
```
|
|
148
146
|
|
|
149
147
|
|
|
148
|
+
### Sample self sender
|
|
149
|
+
>This demonstrates a very basic structure of fetching balances and sending 1% of that amount to yourself. It highlights what stage in the transaction process you will "hand off" the transaction to the circuit infrastructure for signing and sending (broadcasting).
|
|
150
|
+
```typescript
|
|
151
|
+
import {
|
|
152
|
+
Agent,
|
|
153
|
+
AgentSdk,
|
|
154
|
+
ExecutionFunctionContract,
|
|
155
|
+
StopFunctionContract,
|
|
156
|
+
} from "@circuitorg/agent-sdk";
|
|
157
|
+
import { encodeFunctionData, parseAbi } from "viem";
|
|
158
|
+
|
|
159
|
+
export type BalanceResponse = {
|
|
160
|
+
/** Raw amount as string (wei, lamports, or token units) */
|
|
161
|
+
amount: string;
|
|
162
|
+
/** Number of decimals for the asset */
|
|
163
|
+
decimals: number;
|
|
164
|
+
/** Whether this is a token (true) or native asset (false) */
|
|
165
|
+
isToken: boolean;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export async function getEvmTokenBalance(params: {
|
|
169
|
+
address: string;
|
|
170
|
+
token: string;
|
|
171
|
+
rpcUrl: string;
|
|
172
|
+
}): Promise<BalanceResponse> {
|
|
173
|
+
// balanceOf(address) - ERC-20 standard
|
|
174
|
+
const data = `0x70a08231${params.address
|
|
175
|
+
.replace(/^0x/, "")
|
|
176
|
+
.padStart(64, "0")}`;
|
|
177
|
+
|
|
178
|
+
const balanceCall = {
|
|
179
|
+
jsonrpc: "2.0",
|
|
180
|
+
id: 1,
|
|
181
|
+
method: "eth_call",
|
|
182
|
+
params: [{ to: params.token, data }, "latest"],
|
|
183
|
+
} as const;
|
|
184
|
+
|
|
185
|
+
const balanceRes = await fetch(params.rpcUrl, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers: { "content-type": "application/json" },
|
|
188
|
+
body: JSON.stringify(balanceCall),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const balanceJson = (await balanceRes.json()) as { result?: string };
|
|
192
|
+
const balHex = balanceJson.result || "0x0";
|
|
193
|
+
const amount = BigInt(balHex);
|
|
194
|
+
|
|
195
|
+
// decimals() - ERC-20 standard
|
|
196
|
+
const decimalsCall = {
|
|
197
|
+
jsonrpc: "2.0",
|
|
198
|
+
id: 2,
|
|
199
|
+
method: "eth_call",
|
|
200
|
+
params: [{ to: params.token, data: "0x313ce567" }, "latest"],
|
|
201
|
+
} as const;
|
|
202
|
+
|
|
203
|
+
const decimalsRes = await fetch(params.rpcUrl, {
|
|
204
|
+
method: "POST",
|
|
205
|
+
headers: { "content-type": "application/json" },
|
|
206
|
+
body: JSON.stringify(decimalsCall),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const decimalsJson = (await decimalsRes.json()) as { result?: string };
|
|
210
|
+
const decimals = decimalsJson.result
|
|
211
|
+
? Number(BigInt(decimalsJson.result))
|
|
212
|
+
: 18;
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
amount: amount.toString(),
|
|
216
|
+
decimals,
|
|
217
|
+
isToken: true,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const toSubscript = (num: number): string => {
|
|
222
|
+
const map: Record<string, string> = {
|
|
223
|
+
"0": "₀",
|
|
224
|
+
"1": "₁",
|
|
225
|
+
"2": "₂",
|
|
226
|
+
"3": "₃",
|
|
227
|
+
"4": "₄",
|
|
228
|
+
"5": "₅",
|
|
229
|
+
"6": "₆",
|
|
230
|
+
"7": "₇",
|
|
231
|
+
"8": "₈",
|
|
232
|
+
"9": "₉",
|
|
233
|
+
};
|
|
234
|
+
return String(num)
|
|
235
|
+
.split("")
|
|
236
|
+
.map((c) => map[c] ?? c)
|
|
237
|
+
.join("");
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const formatTokenAmount = (
|
|
241
|
+
amount: bigint,
|
|
242
|
+
decimals: number,
|
|
243
|
+
subscriptDecimals: number = 4,
|
|
244
|
+
standardDecimals: number = 6
|
|
245
|
+
): string => {
|
|
246
|
+
const sign = amount < 0n ? "-" : "";
|
|
247
|
+
const s = (amount < 0n ? -amount : amount).toString();
|
|
248
|
+
|
|
249
|
+
const hasFraction = decimals > 0;
|
|
250
|
+
const integerPart =
|
|
251
|
+
s.length > decimals ? s.slice(0, s.length - decimals) : "0";
|
|
252
|
+
const fractional = hasFraction
|
|
253
|
+
? s.length > decimals
|
|
254
|
+
? s.slice(s.length - decimals)
|
|
255
|
+
: s.padStart(decimals, "0")
|
|
256
|
+
: "";
|
|
257
|
+
|
|
258
|
+
const groupedInt = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
259
|
+
|
|
260
|
+
if (!hasFraction) return sign + groupedInt;
|
|
261
|
+
if (/^0+$/.test(fractional)) return sign + groupedInt;
|
|
262
|
+
|
|
263
|
+
const leadingZeros = fractional.match(/^0+/)?.[0].length ?? 0;
|
|
264
|
+
|
|
265
|
+
if (leadingZeros >= 3) {
|
|
266
|
+
// Use subscript notation for numbers with 3+ leading zeros
|
|
267
|
+
const rest = fractional.slice(leadingZeros);
|
|
268
|
+
const truncatedRest = rest.slice(0, subscriptDecimals);
|
|
269
|
+
const compressedFrac = `0${toSubscript(leadingZeros)}${truncatedRest}`;
|
|
270
|
+
return `${sign}${groupedInt}.${compressedFrac}`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// For 0-2 leading zeros, use standard decimal formatting
|
|
274
|
+
const truncatedFrac = fractional.slice(0, standardDecimals);
|
|
275
|
+
const trimmedFrac = truncatedFrac.replace(/0+$/, ""); // Remove trailing zeros
|
|
276
|
+
|
|
277
|
+
if (trimmedFrac === "") return sign + groupedInt;
|
|
278
|
+
return `${sign}${groupedInt}.${trimmedFrac}`;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Agent execution function using the new AgentSdk v1.0 API
|
|
282
|
+
const executionFunction: ExecutionFunctionContract = async (request) => {
|
|
283
|
+
console.log(`🚀 Agent execution called for session ${request.sessionId}`);
|
|
284
|
+
|
|
285
|
+
const sdk = new AgentSdk({
|
|
286
|
+
sessionId: request.sessionId,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
await sdk.addMessage({
|
|
291
|
+
type: "observe",
|
|
292
|
+
shortMessage:
|
|
293
|
+
"🚀 Starting Agent SDK v1.0 comprehensive demo -- live test",
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const PEPE_ARB = "0x25d887Ce7a35172C62FeBFD67a1856F20FaEbB00" as `0x${string}`;
|
|
297
|
+
const pepeBalance = await getEvmTokenBalance({
|
|
298
|
+
rpcUrl: "https://arb-mainnet.g.alchemy.com/v2/<YOUR_API_KEY>",
|
|
299
|
+
address: request.sessionWalletAddress,
|
|
300
|
+
token: PEPE_ARB,
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const pepeBalanceFormatted = formatTokenAmount(
|
|
304
|
+
BigInt(pepeBalance.amount),
|
|
305
|
+
pepeBalance.decimals
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
await sdk.addMessage({
|
|
309
|
+
type: "observe",
|
|
310
|
+
shortMessage: `PEPE Balance (Arbitrum): ${pepeBalanceFormatted} PEPE`,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
const abi = parseAbi([
|
|
315
|
+
"function transfer(address to, uint256 value) returns (bool)",
|
|
316
|
+
]);
|
|
317
|
+
const demoAmount = BigInt(pepeBalance.amount) / 100n;
|
|
318
|
+
|
|
319
|
+
const data = encodeFunctionData({
|
|
320
|
+
abi,
|
|
321
|
+
functionName: "transfer",
|
|
322
|
+
args: [request.sessionWalletAddress as `0x${string}`, demoAmount],
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// Demo custom contract call
|
|
326
|
+
await sdk.signAndSend({
|
|
327
|
+
network: "ethereum:42161",
|
|
328
|
+
request: {
|
|
329
|
+
toAddress: PEPE_ARB,
|
|
330
|
+
data: data,
|
|
331
|
+
value: "0", // No ETH value for token transfers
|
|
332
|
+
},
|
|
333
|
+
message: "Custom PEPE transfer demo",
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
await sdk.addMessage({
|
|
338
|
+
type: "observe",
|
|
339
|
+
shortMessage:
|
|
340
|
+
"✅ Agent SDK v1.0 comprehensive demo completed successfully!",
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
return { success: true };
|
|
344
|
+
} catch (error) {
|
|
345
|
+
console.error("💥 Agent execution error:", error);
|
|
346
|
+
|
|
347
|
+
await sdk.addMessage({
|
|
348
|
+
type: "error",
|
|
349
|
+
shortMessage: `Agent execution error: ${
|
|
350
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
351
|
+
}`,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Optional - Return detailed error information for the CLI to display
|
|
355
|
+
return {
|
|
356
|
+
success: false,
|
|
357
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
358
|
+
errorDetails: {
|
|
359
|
+
name: error instanceof Error ? error.name : "Unknown",
|
|
360
|
+
message: error instanceof Error ? error.message : String(error),
|
|
361
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
362
|
+
timestamp: new Date().toISOString(),
|
|
363
|
+
sessionId: request.sessionId,
|
|
364
|
+
agentSlug: (globalThis as any).CIRCUIT_AGENT_SLUG || "unknown",
|
|
365
|
+
errorType: "AGENT_EXECUTION_ERROR",
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const stopFunction: StopFunctionContract = async (request) => {
|
|
372
|
+
const sdk = new AgentSdk({
|
|
373
|
+
sessionId: request.sessionId,
|
|
374
|
+
testing: true,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
await sdk.addMessage({
|
|
379
|
+
type: "observe",
|
|
380
|
+
shortMessage: "🛑 Agent stopping with new SDK v1.0",
|
|
381
|
+
});
|
|
382
|
+
return { success: true };
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error("💥 Agent stop error:", error);
|
|
385
|
+
|
|
386
|
+
return {
|
|
387
|
+
success: false,
|
|
388
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
389
|
+
errorDetails: {
|
|
390
|
+
name: error instanceof Error ? error.name : "Unknown",
|
|
391
|
+
message: error instanceof Error ? error.message : String(error),
|
|
392
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
393
|
+
timestamp: new Date().toISOString(),
|
|
394
|
+
sessionId: request.sessionId,
|
|
395
|
+
agentSlug: (globalThis as any).CIRCUIT_AGENT_SLUG || "unknown",
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
// Create the agent
|
|
402
|
+
const agent = new Agent({ executionFunction, stopFunction });
|
|
403
|
+
|
|
404
|
+
// Export the agent for both Bun local development and Cloudflare Workers
|
|
405
|
+
export default agent.getWorkerExport();
|
|
406
|
+
|
|
407
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -1,48 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Configuration for the SDK client
|
|
9
|
-
*/
|
|
10
|
-
interface SDKConfig {
|
|
11
|
-
/** Session ID for the current agent instance */
|
|
12
|
-
sessionId: number;
|
|
13
|
-
/** Enable verbose logging for debugging */
|
|
14
|
-
verbose?: boolean;
|
|
15
|
-
/** Enable testing mode to return mock responses */
|
|
16
|
-
testing?: boolean;
|
|
17
|
-
/** Optional base URL for local development (auto-detected if omitted) */
|
|
18
|
-
baseUrl?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Network type definitions and guard functions
|
|
4
|
+
* Network type definitions
|
|
23
5
|
*/
|
|
24
6
|
type Network = `ethereum:${number}` | "solana";
|
|
25
|
-
/**
|
|
26
|
-
* Type guard to check if network is Ethereum-based
|
|
27
|
-
* @param network - Network to check
|
|
28
|
-
* @returns true if network is ethereum:chainId format
|
|
29
|
-
*/
|
|
30
|
-
declare function isEthereumNetwork(network: Network): network is `ethereum:${number}`;
|
|
31
|
-
/**
|
|
32
|
-
* Type guard to check if network is Solana
|
|
33
|
-
* @param network - Network to check
|
|
34
|
-
* @returns true if network is "solana"
|
|
35
|
-
*/
|
|
36
|
-
declare function isSolanaNetwork(network: Network): network is "solana";
|
|
37
|
-
/**
|
|
38
|
-
* Extract chain ID from Ethereum network string
|
|
39
|
-
* @param network - Ethereum network string
|
|
40
|
-
* @returns Chain ID as number
|
|
41
|
-
*/
|
|
42
|
-
declare function getChainIdFromNetwork(network: `ethereum:${number}`): number;
|
|
43
7
|
|
|
44
8
|
/**
|
|
45
|
-
*
|
|
9
|
+
* Transaction type definitions for agent operations
|
|
46
10
|
*/
|
|
47
11
|
|
|
48
12
|
/**
|
|
@@ -65,17 +29,6 @@ type SignAndSendRequest = {
|
|
|
65
29
|
hexTransaction: string;
|
|
66
30
|
};
|
|
67
31
|
});
|
|
68
|
-
/**
|
|
69
|
-
* Message request for addMessage function
|
|
70
|
-
*/
|
|
71
|
-
type AddMessageRequest = {
|
|
72
|
-
type: "observe" | "validate" | "reflect" | "error" | "warning";
|
|
73
|
-
shortMessage: string;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Response type definitions
|
|
78
|
-
*/
|
|
79
32
|
/**
|
|
80
33
|
* Standard response from signAndSend operations
|
|
81
34
|
*/
|
|
@@ -87,6 +40,101 @@ type SignAndSendResponse = {
|
|
|
87
40
|
/** Optional transaction URL (explorer link) */
|
|
88
41
|
transactionUrl?: string;
|
|
89
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* EIP712 TypedData schema for typed message signing
|
|
45
|
+
*/
|
|
46
|
+
declare const EIP712TypedDataSchema: z.ZodObject<{
|
|
47
|
+
domain: z.ZodObject<{
|
|
48
|
+
name: z.ZodOptional<z.ZodString>;
|
|
49
|
+
version: z.ZodOptional<z.ZodString>;
|
|
50
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
verifyingContract: z.ZodOptional<z.ZodString>;
|
|
52
|
+
salt: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
types: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
type: z.ZodString;
|
|
57
|
+
}, z.core.$strip>>>;
|
|
58
|
+
primaryType: z.ZodString;
|
|
59
|
+
message: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
/**
|
|
62
|
+
* EIP191 Message schema for simple message signing
|
|
63
|
+
*/
|
|
64
|
+
declare const EIP191MessageSchema: z.ZodObject<{
|
|
65
|
+
message: z.ZodString;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
/**
|
|
68
|
+
* Main signMessage request type with network-specific conditional shapes
|
|
69
|
+
*/
|
|
70
|
+
type SignMessageRequest = {
|
|
71
|
+
network: Network;
|
|
72
|
+
} & ({
|
|
73
|
+
network: `ethereum:${number}`;
|
|
74
|
+
request: {
|
|
75
|
+
messageType: "eip712";
|
|
76
|
+
data: z.infer<typeof EIP712TypedDataSchema>;
|
|
77
|
+
chainId: number;
|
|
78
|
+
};
|
|
79
|
+
} | {
|
|
80
|
+
network: `ethereum:${number}`;
|
|
81
|
+
request: {
|
|
82
|
+
messageType: "eip191";
|
|
83
|
+
data: z.infer<typeof EIP191MessageSchema>;
|
|
84
|
+
chainId: number;
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Standard response from signMessage operations
|
|
89
|
+
*/
|
|
90
|
+
type SignMessageResponse = {
|
|
91
|
+
/** Signature component v */
|
|
92
|
+
v: number;
|
|
93
|
+
/** Signature component r */
|
|
94
|
+
r: string;
|
|
95
|
+
/** Signature component s */
|
|
96
|
+
s: string;
|
|
97
|
+
/** Formatted signature string */
|
|
98
|
+
formattedSignature: string;
|
|
99
|
+
/** Signature type */
|
|
100
|
+
type: "evm";
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Agent log type definitions for agent communication
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Structure for individual agent logs
|
|
109
|
+
*/
|
|
110
|
+
declare const AgentLogSchema: z.ZodObject<{
|
|
111
|
+
type: z.ZodEnum<{
|
|
112
|
+
error: "error";
|
|
113
|
+
observe: "observe";
|
|
114
|
+
validate: "validate";
|
|
115
|
+
reflect: "reflect";
|
|
116
|
+
warning: "warning";
|
|
117
|
+
}>;
|
|
118
|
+
shortMessage: z.ZodString;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
type AgentLog = z.infer<typeof AgentLogSchema>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Configuration type definitions for the Agent SDK
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Configuration for the SDK client
|
|
127
|
+
*/
|
|
128
|
+
interface SDKConfig {
|
|
129
|
+
/** Session ID for the current agent instance */
|
|
130
|
+
sessionId: number;
|
|
131
|
+
/** Enable verbose logging for debugging */
|
|
132
|
+
verbose?: boolean;
|
|
133
|
+
/** Enable testing mode to return mock responses */
|
|
134
|
+
testing?: boolean;
|
|
135
|
+
/** Optional base URL for local development (auto-detected if omitted) */
|
|
136
|
+
baseUrl?: string;
|
|
137
|
+
}
|
|
90
138
|
|
|
91
139
|
/**
|
|
92
140
|
* Main AgentSdk class with simplified API surface
|
|
@@ -98,7 +146,7 @@ type SignAndSendResponse = {
|
|
|
98
146
|
* Provides a minimal, type-safe surface with two core methods that cover the
|
|
99
147
|
* majority of agent interactions:
|
|
100
148
|
*
|
|
101
|
-
* - `
|
|
149
|
+
* - `sendLog()` — emit timeline logs for observability and UX
|
|
102
150
|
* - `signAndSend()` — sign and broadcast transactions across networks
|
|
103
151
|
*
|
|
104
152
|
* Quick start:
|
|
@@ -109,7 +157,7 @@ type SignAndSendResponse = {
|
|
|
109
157
|
* sessionId: 12345,
|
|
110
158
|
* });
|
|
111
159
|
*
|
|
112
|
-
* await sdk.
|
|
160
|
+
* await sdk.sendLog({ type: "observe", shortMessage: "Starting" });
|
|
113
161
|
* const tx = await sdk.signAndSend({
|
|
114
162
|
* network: "ethereum:42161",
|
|
115
163
|
* request: {
|
|
@@ -138,23 +186,23 @@ declare class AgentSdk {
|
|
|
138
186
|
* ```
|
|
139
187
|
*/
|
|
140
188
|
constructor(config: SDKConfig);
|
|
141
|
-
private
|
|
189
|
+
private logging;
|
|
142
190
|
/**
|
|
143
|
-
* Add a
|
|
191
|
+
* Add a log to the agent timeline.
|
|
144
192
|
*
|
|
145
193
|
* Messages show up in session traces and UIs and are useful for observability,
|
|
146
194
|
* human-in-the-loop reviews, and debugging.
|
|
147
195
|
*
|
|
148
|
-
* @param
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @returns Resolves when the
|
|
196
|
+
* @param log - Timeline message
|
|
197
|
+
* @param log.type - One of: `"observe" | "validate" | "reflect" | "error" | "warning"`
|
|
198
|
+
* @param log.shortMessage - Short, human-readable message (<= 250 chars)
|
|
199
|
+
* @returns Resolves when the log is accepted by the backend
|
|
152
200
|
* @example
|
|
153
201
|
* ```ts
|
|
154
|
-
* await sdk.
|
|
202
|
+
* await sdk.sendLog({ type: "observe", shortMessage: "Starting swap" });
|
|
155
203
|
* ```
|
|
156
204
|
*/
|
|
157
|
-
|
|
205
|
+
sendLog(log: AgentLog): Promise<void>;
|
|
158
206
|
/**
|
|
159
207
|
* Sign and broadcast a transaction on the specified network.
|
|
160
208
|
*
|
|
@@ -195,6 +243,42 @@ declare class AgentSdk {
|
|
|
195
243
|
* ```
|
|
196
244
|
*/
|
|
197
245
|
signAndSend(request: SignAndSendRequest): Promise<SignAndSendResponse>;
|
|
246
|
+
/**
|
|
247
|
+
* Sign a message using the agent's key.
|
|
248
|
+
*
|
|
249
|
+
* This is useful for signing arbitrary messages, such as EIP-712 typed data.
|
|
250
|
+
*
|
|
251
|
+
* @param request - Message signing request with network-specific parameters
|
|
252
|
+
* @param request.network - `"ethereum:${number}"` for EVM networks
|
|
253
|
+
* @param request.request - Message signing parameters
|
|
254
|
+
* - For EIP-712: `{ messageType: "eip712", data: { domain, types, primaryType, message }, chainId }`
|
|
255
|
+
* - For EIP-191: `{ messageType: "eip191", data: { message }, chainId }`
|
|
256
|
+
* @returns Promise resolving to signature components `{ v, r, s, formattedSignature, type }`
|
|
257
|
+
* @throws Error if the network is unsupported or the backend rejects the request
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* // EIP-191 simple message signing
|
|
261
|
+
* const signature = await sdk.signMessage({
|
|
262
|
+
* network: "ethereum:1",
|
|
263
|
+
* request: {
|
|
264
|
+
* messageType: "eip191",
|
|
265
|
+
* data: { message: "Hello, world!" },
|
|
266
|
+
* chainId: 1
|
|
267
|
+
* }
|
|
268
|
+
* });
|
|
269
|
+
*
|
|
270
|
+
* // EIP-712 typed data signing
|
|
271
|
+
* const signature = await sdk.signMessage({
|
|
272
|
+
* network: "ethereum:1",
|
|
273
|
+
* request: {
|
|
274
|
+
* messageType: "eip712",
|
|
275
|
+
* data: { domain: {...}, types: {...}, primaryType: "Message", message: {...} },
|
|
276
|
+
* chainId: 1
|
|
277
|
+
* }
|
|
278
|
+
* });
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
signMessage(request: SignMessageRequest): Promise<SignMessageResponse>;
|
|
198
282
|
/**
|
|
199
283
|
* Handle EVM transaction signing and broadcasting
|
|
200
284
|
*/
|
|
@@ -204,9 +288,13 @@ declare class AgentSdk {
|
|
|
204
288
|
*/
|
|
205
289
|
private handleSolanaTransaction;
|
|
206
290
|
/**
|
|
207
|
-
*
|
|
291
|
+
* Handle EVM message signing
|
|
208
292
|
*/
|
|
209
|
-
private
|
|
293
|
+
private handleEvmSignMessage;
|
|
294
|
+
/**
|
|
295
|
+
* Send logs to the agent timeline (migrated from AgentToolset)
|
|
296
|
+
*/
|
|
297
|
+
private _sendLog;
|
|
210
298
|
}
|
|
211
299
|
|
|
212
300
|
/**
|
|
@@ -237,7 +325,7 @@ declare class APIClient {
|
|
|
237
325
|
private getAgentSlug;
|
|
238
326
|
private getAuthHeaders;
|
|
239
327
|
private loadAuthConfig;
|
|
240
|
-
private
|
|
328
|
+
private logging;
|
|
241
329
|
/**
|
|
242
330
|
* Perform a JSON HTTP request.
|
|
243
331
|
*
|
|
@@ -301,7 +389,7 @@ type HealthResponse = z.infer<typeof HealthResponseSchema>;
|
|
|
301
389
|
*
|
|
302
390
|
* try {
|
|
303
391
|
* // Send status message
|
|
304
|
-
* await agentToolset.
|
|
392
|
+
* await agentToolset.sendLog([{
|
|
305
393
|
* type: "observe",
|
|
306
394
|
* shortMessage: "Starting agent execution..."
|
|
307
395
|
* }]);
|
|
@@ -350,10 +438,9 @@ type ExecutionFunctionContract = (request: AgentRequest) => Promise<AgentRespons
|
|
|
350
438
|
*
|
|
351
439
|
* try {
|
|
352
440
|
* // Notify about shutdown
|
|
353
|
-
* await agentToolset.
|
|
441
|
+
* await agentToolset.sendLog([{
|
|
354
442
|
* type: "observe",
|
|
355
443
|
* shortMessage: "Agent shutting down...",
|
|
356
|
-
* longMessage: "Cleaning up resources and saving state"
|
|
357
444
|
* }]);
|
|
358
445
|
*
|
|
359
446
|
* // Example: Update sleep interval before shutdown
|
|
@@ -362,10 +449,9 @@ type ExecutionFunctionContract = (request: AgentRequest) => Promise<AgentRespons
|
|
|
362
449
|
* });
|
|
363
450
|
*
|
|
364
451
|
* // Example: Final status message
|
|
365
|
-
* await agentToolset.
|
|
452
|
+
* await agentToolset.sendLog([{
|
|
366
453
|
* type: "observe",
|
|
367
454
|
* shortMessage: "Shutdown complete",
|
|
368
|
-
* longMessage: `Agent ${request.sessionId} successfully shut down`
|
|
369
455
|
* }]);
|
|
370
456
|
*
|
|
371
457
|
* return {
|
|
@@ -383,30 +469,6 @@ type ExecutionFunctionContract = (request: AgentRequest) => Promise<AgentRespons
|
|
|
383
469
|
* ```
|
|
384
470
|
*/
|
|
385
471
|
type StopFunctionContract = (request: AgentRequest) => Promise<AgentResponse>;
|
|
386
|
-
/**
|
|
387
|
-
* Contract for agent chat functions. Handle interactive messaging with the agent.
|
|
388
|
-
* @param request - Contains session information and wallet address to operate with
|
|
389
|
-
* @returns Promise resolving to a success/error response
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* // Chat function implementation
|
|
393
|
-
* const chatFunction: ChatFunctionContract = async (request) => {
|
|
394
|
-
* const agentToolset = new AgentToolset({ sessionId: request.sessionId });
|
|
395
|
-
*
|
|
396
|
-
* await agentToolset.messageSend([{
|
|
397
|
-
* type: "observe",
|
|
398
|
-
* shortMessage: "Processing chat message",
|
|
399
|
-
* longMessage: `Received message for wallet ${request.sessionWalletAddress}`
|
|
400
|
-
* }]);
|
|
401
|
-
*
|
|
402
|
-
* return {
|
|
403
|
-
* success: true,
|
|
404
|
-
* message: "Chat message processed"
|
|
405
|
-
* };
|
|
406
|
-
* };
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
type ChatFunctionContract = (request: AgentRequest) => Promise<AgentResponse>;
|
|
410
472
|
/**
|
|
411
473
|
* Contract for agent health check functions. Handle health status requests.
|
|
412
474
|
* @returns Promise resolving to an object with a status field
|
|
@@ -433,8 +495,6 @@ type HealthCheckFunctionContract = () => Promise<HealthResponse>;
|
|
|
433
495
|
interface AgentConfig {
|
|
434
496
|
/** Main execution function that implements the agent's core logic */
|
|
435
497
|
executionFunction: ExecutionFunctionContract;
|
|
436
|
-
/** Optional chat function for handling interactive messaging */
|
|
437
|
-
chatFunction?: ChatFunctionContract;
|
|
438
498
|
/** Optional winddown function for cleanup operations, this is called when the agent is stopped */
|
|
439
499
|
stopFunction?: StopFunctionContract;
|
|
440
500
|
/** Optional health check function for monitoring agent health status */
|
|
@@ -445,14 +505,12 @@ interface AgentConfig {
|
|
|
445
505
|
*
|
|
446
506
|
* Exposes the following endpoints:
|
|
447
507
|
* - `POST /execute` — required, calls your execution function
|
|
448
|
-
* - `POST /chat` — optional, when a `chatFunction` is provided
|
|
449
508
|
* - `POST /stop` and `DELETE /` — optional, when a `stopFunction` is provided
|
|
450
509
|
* - `GET /health` — always available, uses provided or default health check
|
|
451
510
|
*/
|
|
452
511
|
declare class Agent {
|
|
453
512
|
private app;
|
|
454
513
|
private executionFunction;
|
|
455
|
-
private chatFunction?;
|
|
456
514
|
private stopFunction?;
|
|
457
515
|
private healthCheckFunction?;
|
|
458
516
|
/**
|
|
@@ -471,4 +529,27 @@ declare class Agent {
|
|
|
471
529
|
};
|
|
472
530
|
}
|
|
473
531
|
|
|
474
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Utility functions for network operations
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Type guard to check if network is Ethereum-based
|
|
538
|
+
* @param network - Network to check
|
|
539
|
+
* @returns true if network is ethereum:chainId format
|
|
540
|
+
*/
|
|
541
|
+
declare function isEthereumNetwork(network: Network): network is `ethereum:${number}`;
|
|
542
|
+
/**
|
|
543
|
+
* Type guard to check if network is Solana
|
|
544
|
+
* @param network - Network to check
|
|
545
|
+
* @returns true if network is "solana"
|
|
546
|
+
*/
|
|
547
|
+
declare function isSolanaNetwork(network: Network): network is "solana";
|
|
548
|
+
/**
|
|
549
|
+
* Extract chain ID from Ethereum network string
|
|
550
|
+
* @param network - Ethereum network string
|
|
551
|
+
* @returns Chain ID as number
|
|
552
|
+
*/
|
|
553
|
+
declare function getChainIdFromNetwork(network: `ethereum:${number}`): number;
|
|
554
|
+
|
|
555
|
+
export { APIClient, Agent, AgentSdk, type ExecutionFunctionContract, type Network, type SDKConfig, type SignAndSendRequest, type SignAndSendResponse, type SignMessageRequest, type SignMessageResponse, type StopFunctionContract, getChainIdFromNetwork, isEthereumNetwork, isSolanaNetwork };
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __getOwnPropNames=Object.getOwnPropertyNames,__require=(t=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(t,{get:(t,e)=>("undefined"!=typeof require?require:t)[e]}):t)(function(t){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),__commonJS=(t,e)=>function(){return e||(0,t[__getOwnPropNames(t)[0]])((e={exports:{}}).exports,e),e.exports},require_auth_loader=__commonJS({"src/utils/auth-loader.cjs"(exports,module){function loadAuthFromFileSystem(){try{if("undefined"==typeof process||!process.env?.HOME)return;const fs=eval("require")("fs"),path=eval("require")("path"),authPath=path.join(process.env.HOME,".config","circuit","auth.json");if(!fs.existsSync(authPath))return;const authContent=fs.readFileSync(authPath,"utf-8");return JSON.parse(authContent)}catch(t){return}}module.exports={loadAuthFromFileSystem:loadAuthFromFileSystem}}})
|
|
1
|
+
var __getOwnPropNames=Object.getOwnPropertyNames,__require=(t=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(t,{get:(t,e)=>("undefined"!=typeof require?require:t)[e]}):t)(function(t){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),__commonJS=(t,e)=>function(){return e||(0,t[__getOwnPropNames(t)[0]])((e={exports:{}}).exports,e),e.exports},require_auth_loader=__commonJS({"src/utils/auth-loader.cjs"(exports,module){function loadAuthFromFileSystem(){try{if("undefined"==typeof process||!process.env?.HOME)return;const fs=eval("require")("fs"),path=eval("require")("path"),authPath=path.join(process.env.HOME,".config","circuit","auth.json");if(!fs.existsSync(authPath))return;const authContent=fs.readFileSync(authPath,"utf-8");return JSON.parse(authContent)}catch(t){return}}module.exports={loadAuthFromFileSystem:loadAuthFromFileSystem}}}),API_BASE_URL_LOCAL="https://agents.circuit.org",APIClient=class{config;baseUrl;isCloudflareWorker(){return"undefined"!=typeof globalThis&&void 0!==globalThis.Cloudflare}hasServiceBinding(){let t=!1;return this.isCloudflareWorker()&&(void 0!==globalThis.AGENTS_TO_API_PROXY||void 0!==globalThis.__AGENT_ENV__&&globalThis.__AGENT_ENV__?.AGENTS_TO_API_PROXY)&&(t=!0),this.config.verbose,t}constructor(t){this.config=t,this.baseUrl=t.baseUrl||API_BASE_URL_LOCAL}getAgentSlug(){return"undefined"!=typeof process&&process.env?.CIRCUIT_AGENT_SLUG?process.env.CIRCUIT_AGENT_SLUG:void 0!==globalThis.CIRCUIT_AGENT_SLUG?globalThis.CIRCUIT_AGENT_SLUG:void 0}getAuthHeaders(){const t={};t["X-Session-Id"]=this.config.sessionId.toString();const e=this.getAgentSlug();if(e&&(t["X-Agent-Slug"]=e),!this.hasServiceBinding())try{const e=this.loadAuthConfig();e?.sessionToken&&(t.Authorization=`Bearer ${e.sessionToken}`)}catch(t){}return t}loadAuthConfig(){try{const{loadAuthFromFileSystem:t}=require_auth_loader();return t()}catch(t){this.config.verbose}}logging(t,e){this.config.verbose}async makeRequest(t,e={}){const s={...{"Content-Type":"application/json",...this.getAuthHeaders()},...e.headers};let r;if(this.logging("=== REQUEST DETAILS ==="),this.logging("Endpoint:",t),this.logging("Method:",e.method||"GET"),this.logging("Headers:",s),this.logging("Body:",e.body),this.logging("Session ID:",this.config.sessionId),this.logging("Agent Slug:",this.getAgentSlug()||"not set"),this.logging("Using Service Binding:",this.hasServiceBinding()),this.logging("====================="),this.hasServiceBinding()){let n;if(void 0!==globalThis.AGENTS_TO_API_PROXY)n=globalThis.AGENTS_TO_API_PROXY;else{if(void 0===globalThis.__AGENT_ENV__||!globalThis.__AGENT_ENV__?.AGENTS_TO_API_PROXY)throw new Error("Service binding detected but not accessible");n=globalThis.__AGENT_ENV__.AGENTS_TO_API_PROXY}this.logging("Using service binding AGENTS_TO_API_PROXY"),this.logging("Service binding type:",typeof n);const o={...e,headers:s},i=`https://agents-to-api-proxy.circuit-0bc.workers.dev${t}`;r=await n.fetch(i,o)}else{this.logging("Using HTTP fallback to:",this.baseUrl);const n=`${this.baseUrl}${t}`,o={...e,headers:s};r=await fetch(n,o)}if(this.logging("=== RESPONSE DETAILS ==="),this.logging("Status:",r.status),this.logging("Status Text:",r.statusText),this.logging("Response Headers:",Object.fromEntries(r.headers.entries())),this.logging("======================"),!r.ok){const t=await r.json().catch(()=>({}));throw this.logging("=== ERROR RESPONSE ==="),this.logging("Error Data:",t),this.logging("===================="),new Error(t.message||`HTTP ${r.status}: ${r.statusText}`)}const n=await r.json();return this.logging("=== SUCCESS RESPONSE ==="),this.logging("Response Data:",n),this.logging("======================"),n}async get(t){return this.makeRequest(t,{method:"GET"})}async post(t,e){return this.makeRequest(t,{method:"POST",body:e?JSON.stringify(e):void 0})}};function isEthereumNetwork(t){return t.startsWith("ethereum:")}function isSolanaNetwork(t){return"solana"===t}function getChainIdFromNetwork(t){return Number(t.split(":")[1])}var AgentSdk=class{client;config;constructor(t){this.config=t,this.client=new APIClient(t)}logging(t,e){this.config.verbose}async sendLog(t){this.logging("=== ADD MESSAGE ==="),this.logging("Message:",t),this.logging("==================="),await this.t([t])}async signAndSend(t){if(this.logging("=== SIGN AND SEND ==="),this.logging("Request:",t),this.logging("Testing mode:",this.config.testing),this.logging("===================="),this.config.testing)return{internalTransactionId:123,txHash:isEthereumNetwork(t.network)?"0xTEST":"TEST_SOL_TX",transactionUrl:void 0};if(isEthereumNetwork(t.network)){const e=getChainIdFromNetwork(t.network);if("toAddress"in t.request)return this.handleEvmTransaction({chainId:e,toAddress:t.request.toAddress,data:t.request.data,valueWei:t.request.value,message:t.message})}if(isSolanaNetwork(t.network)&&"hexTransaction"in t.request)return this.handleSolanaTransaction({hexTransaction:t.request.hexTransaction,message:t.message});throw new Error(`Unsupported network: ${t.network}`)}async signMessage(t){if(this.logging("=== SIGN MESSAGE ==="),this.logging("Request:",t),this.logging("Testing mode:",this.config.testing),this.logging("===================="),this.config.testing)return{v:27,r:"0xTEST_R",s:"0xTEST_S",formattedSignature:"0xTEST_FORMATTED",type:"evm"};if(isEthereumNetwork(t.network))return this.handleEvmSignMessage(t);throw new Error(`Unsupported network: ${t.network}`)}async handleEvmTransaction(t){const e=await this.client.post("/v1/transactions/evm",t),s=await this.client.post(`/v1/transactions/evm/${e.internalTransactionId}/broadcast`);return{internalTransactionId:e.internalTransactionId,txHash:s.txHash,transactionUrl:s.transactionUrl}}async handleSolanaTransaction(t){const e=await this.client.post("/v1/transactions/solana",t),s=await this.client.post(`/v1/transactions/solana/${e.internalTransactionId}/broadcast`);return{internalTransactionId:e.internalTransactionId,txHash:s.txHash,transactionUrl:s.transactionUrl}}async handleEvmSignMessage(t){return await this.client.post("/v1/messages/evm",{messageType:t.request.messageType,data:t.request.data,chainId:t.request.chainId})}async t(t){return this.config.testing?{status:200,message:"Logs added successfully (TESTING)"}:this.client.post("/v1/logs",t)}};import{zValidator}from"@hono/zod-validator";import{Hono}from"hono";import{cors}from"hono/cors";import{z}from"zod";var AgentRequestSchema=z.object({sessionId:z.number(),sessionWalletAddress:z.string(),otherParameters:z.object().optional()}),AgentResponseSchema=z.object({success:z.boolean(),error:z.string().optional(),message:z.string().optional()}),HealthResponseSchema=z.object({status:z.string()}),Agent=class{app;executionFunction;stopFunction;healthCheckFunction;constructor(t){this.app=new Hono,this.executionFunction=t.executionFunction,this.stopFunction=t.stopFunction,this.healthCheckFunction=t.healthCheckFunction||(async()=>({status:"healthy"})),this.app.use("*",cors()),this.setupRoutes()}setupRoutes(){this.app.post("/execute",zValidator("json",AgentRequestSchema),async t=>{try{const e=t.req.valid("json"),s=await this.executionFunction(e);return t.json(s)}catch(e){return t.json({success:!1,error:e instanceof Error?e.message:"Unknown error",message:"Execution failed"},500)}}),this.stopFunction&&(this.app.post("/stop",zValidator("json",AgentRequestSchema),async t=>{try{const e=t.req.valid("json"),s=await(this.stopFunction?.(e));return t.json(s)}catch(e){return t.json({success:!1,error:e instanceof Error?e.message:"Unknown error",message:"Stop operation failed"},500)}}),this.app.delete("/",zValidator("json",AgentRequestSchema),async t=>{try{const e=t.req.valid("json"),s=await(this.stopFunction?.(e));return t.json(s)}catch(e){return t.json({success:!1,error:e instanceof Error?e.message:"Unknown error",message:"Stop operation failed"},500)}})),this.app.get("/health",async t=>{try{const e=await(this.healthCheckFunction?.());return t.json(e)}catch(e){return t.json({status:"unhealthy",error:e instanceof Error?e.message:"Unknown error",timestamp:(new Date).toISOString()},500)}})}getPortFromPackageJson(){try{const t=__require("fs"),e=__require("path").join(process.cwd(),"package.json");if(t.existsSync(e)){const s=JSON.parse(t.readFileSync(e,"utf-8"));if(s.circuit?.port)return Number.parseInt(s.circuit.port,10)}}catch(t){}return null}run(port){const isCloudflareWorker="undefined"!=typeof globalThis&&void 0!==globalThis.Cloudflare;if(isCloudflareWorker)return this.getWorkerExport();const bunEnv=globalThis.Bun?.env,envPort=process.env.AGENT_PORT||bunEnv?.AGENT_PORT,packageJsonPort=this.getPortFromPackageJson();let finalPort=port;!finalPort&&envPort&&(finalPort=Number.parseInt(envPort,10)),!finalPort&&packageJsonPort&&(finalPort=packageJsonPort),finalPort||(finalPort=3e3);try{const req=eval("require"),{serve:serve}=req("@hono/node-server");serve({fetch:this.app.fetch,port:finalPort})}catch(t){process.exit(1)}}getWorkerExport(){return{fetch:async(t,e,s)=>(e&&"undefined"!=typeof globalThis&&(globalThis.__AGENT_ENV__=e),this.app.fetch(t,e,s))}}};function createAgentHandler(t,e,s){return new Agent({executionFunction:t,stopFunction:e,healthCheckFunction:s})}export{APIClient,Agent,AgentSdk,getChainIdFromNetwork,isEthereumNetwork,isSolanaNetwork};
|