hybrid 1.2.2 → 1.2.3

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.
@@ -0,0 +1,706 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/tools/index.ts
21
+ var tools_exports = {};
22
+ __export(tools_exports, {
23
+ blockchainTools: () => blockchainTools,
24
+ estimateGasTool: () => estimateGasTool,
25
+ getBalanceTool: () => getBalanceTool,
26
+ getBlockTool: () => getBlockTool,
27
+ getGasPriceTool: () => getGasPriceTool,
28
+ getMessageTool: () => getMessageTool,
29
+ getTransactionTool: () => getTransactionTool,
30
+ sendMessageTool: () => sendMessageTool,
31
+ sendReactionTool: () => sendReactionTool,
32
+ sendReplyTool: () => sendReplyTool,
33
+ sendTransactionTool: () => sendTransactionTool,
34
+ xmtpTools: () => xmtpTools
35
+ });
36
+ module.exports = __toCommonJS(tools_exports);
37
+
38
+ // src/tools/blockchain.ts
39
+ var import_viem = require("viem");
40
+ var import_accounts = require("viem/accounts");
41
+ var import_chains = require("viem/chains");
42
+ var import_zod = require("zod");
43
+
44
+ // src/core/tool.ts
45
+ function toolFactory() {
46
+ return (config) => {
47
+ return {
48
+ description: config.description,
49
+ inputSchema: config.inputSchema,
50
+ outputSchema: config.outputSchema,
51
+ execute: async (args) => {
52
+ const input = config.inputSchema.parse(args.input);
53
+ const result = await config.execute({
54
+ input,
55
+ runtime: args.runtime,
56
+ messages: args.messages
57
+ });
58
+ if (config.outputSchema) {
59
+ return config.outputSchema.parse(result);
60
+ }
61
+ return result;
62
+ }
63
+ };
64
+ };
65
+ }
66
+ var createTool = toolFactory();
67
+
68
+ // src/tools/blockchain.ts
69
+ var SUPPORTED_CHAINS = {
70
+ mainnet: import_chains.mainnet,
71
+ sepolia: import_chains.sepolia,
72
+ polygon: import_chains.polygon,
73
+ arbitrum: import_chains.arbitrum,
74
+ optimism: import_chains.optimism,
75
+ base: import_chains.base
76
+ };
77
+ var getBalanceTool = createTool({
78
+ id: "getBalance",
79
+ description: "Get the native token balance for a wallet address on a blockchain",
80
+ inputSchema: import_zod.z.object({
81
+ address: import_zod.z.string().describe("The wallet address to check balance for"),
82
+ chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
83
+ }),
84
+ outputSchema: import_zod.z.object({
85
+ success: import_zod.z.boolean(),
86
+ balance: import_zod.z.string().describe("Balance in human readable format (ETH, MATIC, etc.)"),
87
+ balanceWei: import_zod.z.string().describe("Balance in wei (smallest unit)"),
88
+ address: import_zod.z.string(),
89
+ chain: import_zod.z.string(),
90
+ error: import_zod.z.string().optional()
91
+ }),
92
+ execute: async ({ input, runtime }) => {
93
+ try {
94
+ const { address, chain } = input;
95
+ const chainConfig = SUPPORTED_CHAINS[chain];
96
+ const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
97
+ const client = (0, import_viem.createPublicClient)({
98
+ chain: chainConfig,
99
+ transport: (0, import_viem.http)(rpcUrl)
100
+ });
101
+ console.log(`\u{1F50D} [getBalance] Checking balance for ${address} on ${chain}`);
102
+ const balanceWei = await client.getBalance({
103
+ address
104
+ });
105
+ const balance = (0, import_viem.formatEther)(balanceWei);
106
+ console.log(
107
+ `\u2705 [getBalance] Balance: ${balance} ${chainConfig.nativeCurrency.symbol}`
108
+ );
109
+ return {
110
+ success: true,
111
+ balance: `${balance} ${chainConfig.nativeCurrency.symbol}`,
112
+ balanceWei: balanceWei.toString(),
113
+ address,
114
+ chain
115
+ };
116
+ } catch (error) {
117
+ const errorMessage = error instanceof Error ? error.message : String(error);
118
+ console.error("\u274C [getBalance] Error:", errorMessage);
119
+ return {
120
+ success: false,
121
+ balance: "0",
122
+ balanceWei: "0",
123
+ address: input.address,
124
+ chain: input.chain,
125
+ error: errorMessage
126
+ };
127
+ }
128
+ }
129
+ });
130
+ var getTransactionTool = createTool({
131
+ id: "getTransaction",
132
+ description: "Get transaction details by transaction hash",
133
+ inputSchema: import_zod.z.object({
134
+ hash: import_zod.z.string().describe("The transaction hash to look up"),
135
+ chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
136
+ }),
137
+ outputSchema: import_zod.z.object({
138
+ success: import_zod.z.boolean(),
139
+ transaction: import_zod.z.object({
140
+ hash: import_zod.z.string(),
141
+ from: import_zod.z.string(),
142
+ to: import_zod.z.string().nullable(),
143
+ value: import_zod.z.string(),
144
+ gasUsed: import_zod.z.string().optional(),
145
+ gasPrice: import_zod.z.string().optional(),
146
+ blockNumber: import_zod.z.string().optional(),
147
+ status: import_zod.z.string().optional()
148
+ }).optional(),
149
+ error: import_zod.z.string().optional()
150
+ }),
151
+ execute: async ({ input, runtime }) => {
152
+ try {
153
+ const { hash, chain } = input;
154
+ const chainConfig = SUPPORTED_CHAINS[chain];
155
+ const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
156
+ const client = (0, import_viem.createPublicClient)({
157
+ chain: chainConfig,
158
+ transport: (0, import_viem.http)(rpcUrl)
159
+ });
160
+ console.log(
161
+ `\u{1F50D} [getTransaction] Looking up transaction ${hash} on ${chain}`
162
+ );
163
+ const transaction = await client.getTransaction({
164
+ hash
165
+ });
166
+ const receipt = await client.getTransactionReceipt({
167
+ hash
168
+ }).catch(() => null);
169
+ console.log(
170
+ `\u2705 [getTransaction] Found transaction from ${transaction.from} to ${transaction.to}`
171
+ );
172
+ return {
173
+ success: true,
174
+ transaction: {
175
+ hash: transaction.hash,
176
+ from: transaction.from,
177
+ to: transaction.to,
178
+ value: (0, import_viem.formatEther)(transaction.value),
179
+ gasUsed: receipt?.gasUsed.toString(),
180
+ gasPrice: transaction.gasPrice?.toString(),
181
+ blockNumber: transaction.blockNumber?.toString(),
182
+ status: receipt?.status === "success" ? "success" : receipt?.status === "reverted" ? "failed" : "pending"
183
+ }
184
+ };
185
+ } catch (error) {
186
+ const errorMessage = error instanceof Error ? error.message : String(error);
187
+ console.error("\u274C [getTransaction] Error:", errorMessage);
188
+ return {
189
+ success: false,
190
+ error: errorMessage
191
+ };
192
+ }
193
+ }
194
+ });
195
+ var sendTransactionTool = createTool({
196
+ id: "sendTransaction",
197
+ description: "Send native tokens to another address",
198
+ inputSchema: import_zod.z.object({
199
+ to: import_zod.z.string().describe("The recipient address"),
200
+ amount: import_zod.z.string().describe("The amount to send (in ETH, MATIC, etc.)"),
201
+ chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to send on")
202
+ }),
203
+ outputSchema: import_zod.z.object({
204
+ success: import_zod.z.boolean(),
205
+ hash: import_zod.z.string().optional(),
206
+ from: import_zod.z.string().optional(),
207
+ to: import_zod.z.string(),
208
+ amount: import_zod.z.string(),
209
+ chain: import_zod.z.string(),
210
+ error: import_zod.z.string().optional()
211
+ }),
212
+ execute: async ({ input, runtime }) => {
213
+ try {
214
+ const { to, amount, chain } = input;
215
+ const chainConfig = SUPPORTED_CHAINS[chain];
216
+ const privateKey = runtime.privateKey;
217
+ if (!privateKey) {
218
+ return {
219
+ success: false,
220
+ to,
221
+ amount,
222
+ chain,
223
+ error: "Private key not configured in runtime"
224
+ };
225
+ }
226
+ const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
227
+ const account = (0, import_accounts.privateKeyToAccount)(privateKey);
228
+ const client = (0, import_viem.createWalletClient)({
229
+ account,
230
+ chain: chainConfig,
231
+ transport: (0, import_viem.http)(rpcUrl)
232
+ });
233
+ console.log(
234
+ `\u{1F4B8} [sendTransaction] Sending ${amount} ${chainConfig.nativeCurrency.symbol} to ${to} on ${chain}`
235
+ );
236
+ const hash = await client.sendTransaction({
237
+ to,
238
+ value: (0, import_viem.parseEther)(amount)
239
+ });
240
+ console.log(`\u2705 [sendTransaction] Transaction sent: ${hash}`);
241
+ return {
242
+ success: true,
243
+ hash,
244
+ from: account.address,
245
+ to,
246
+ amount,
247
+ chain
248
+ };
249
+ } catch (error) {
250
+ const errorMessage = error instanceof Error ? error.message : String(error);
251
+ console.error("\u274C [sendTransaction] Error:", errorMessage);
252
+ return {
253
+ success: false,
254
+ to: input.to,
255
+ amount: input.amount,
256
+ chain: input.chain,
257
+ error: errorMessage
258
+ };
259
+ }
260
+ }
261
+ });
262
+ var getBlockTool = createTool({
263
+ id: "getBlock",
264
+ description: "Get information about a blockchain block",
265
+ inputSchema: import_zod.z.object({
266
+ blockNumber: import_zod.z.string().optional().describe("Block number (defaults to latest)"),
267
+ chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
268
+ }),
269
+ outputSchema: import_zod.z.object({
270
+ success: import_zod.z.boolean(),
271
+ block: import_zod.z.object({
272
+ number: import_zod.z.string(),
273
+ hash: import_zod.z.string(),
274
+ timestamp: import_zod.z.string(),
275
+ transactionCount: import_zod.z.number(),
276
+ gasUsed: import_zod.z.string(),
277
+ gasLimit: import_zod.z.string()
278
+ }).optional(),
279
+ error: import_zod.z.string().optional()
280
+ }),
281
+ execute: async ({ input, runtime }) => {
282
+ try {
283
+ const { blockNumber, chain } = input;
284
+ const chainConfig = SUPPORTED_CHAINS[chain];
285
+ const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
286
+ const client = (0, import_viem.createPublicClient)({
287
+ chain: chainConfig,
288
+ transport: (0, import_viem.http)(rpcUrl)
289
+ });
290
+ console.log(
291
+ `\u{1F50D} [getBlock] Getting block ${blockNumber || "latest"} on ${chain}`
292
+ );
293
+ const block = await client.getBlock({
294
+ blockNumber: blockNumber ? BigInt(blockNumber) : void 0
295
+ });
296
+ console.log(
297
+ `\u2705 [getBlock] Found block ${block.number} with ${block.transactions.length} transactions`
298
+ );
299
+ return {
300
+ success: true,
301
+ block: {
302
+ number: block.number.toString(),
303
+ hash: block.hash,
304
+ timestamp: block.timestamp.toString(),
305
+ transactionCount: block.transactions.length,
306
+ gasUsed: block.gasUsed.toString(),
307
+ gasLimit: block.gasLimit.toString()
308
+ }
309
+ };
310
+ } catch (error) {
311
+ const errorMessage = error instanceof Error ? error.message : String(error);
312
+ console.error("\u274C [getBlock] Error:", errorMessage);
313
+ return {
314
+ success: false,
315
+ error: errorMessage
316
+ };
317
+ }
318
+ }
319
+ });
320
+ var getGasPriceTool = createTool({
321
+ id: "getGasPrice",
322
+ description: "Get current gas price for a blockchain",
323
+ inputSchema: import_zod.z.object({
324
+ chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
325
+ }),
326
+ outputSchema: import_zod.z.object({
327
+ success: import_zod.z.boolean(),
328
+ gasPrice: import_zod.z.string().optional().describe("Gas price in gwei"),
329
+ gasPriceWei: import_zod.z.string().optional().describe("Gas price in wei"),
330
+ chain: import_zod.z.string(),
331
+ error: import_zod.z.string().optional()
332
+ }),
333
+ execute: async ({ input, runtime }) => {
334
+ try {
335
+ const { chain } = input;
336
+ const chainConfig = SUPPORTED_CHAINS[chain];
337
+ const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
338
+ const client = (0, import_viem.createPublicClient)({
339
+ chain: chainConfig,
340
+ transport: (0, import_viem.http)(rpcUrl)
341
+ });
342
+ console.log(`\u26FD [getGasPrice] Getting gas price for ${chain}`);
343
+ const gasPrice = await client.getGasPrice();
344
+ const gasPriceGwei = (0, import_viem.formatEther)(gasPrice * BigInt(1e9));
345
+ console.log(`\u2705 [getGasPrice] Current gas price: ${gasPriceGwei} gwei`);
346
+ return {
347
+ success: true,
348
+ gasPrice: `${gasPriceGwei} gwei`,
349
+ gasPriceWei: gasPrice.toString(),
350
+ chain
351
+ };
352
+ } catch (error) {
353
+ const errorMessage = error instanceof Error ? error.message : String(error);
354
+ console.error("\u274C [getGasPrice] Error:", errorMessage);
355
+ return {
356
+ success: false,
357
+ chain: input.chain,
358
+ error: errorMessage
359
+ };
360
+ }
361
+ }
362
+ });
363
+ var estimateGasTool = createTool({
364
+ id: "estimateGas",
365
+ description: "Estimate gas required for a transaction",
366
+ inputSchema: import_zod.z.object({
367
+ to: import_zod.z.string().describe("The recipient address"),
368
+ amount: import_zod.z.string().default("0").describe("The amount to send (defaults to 0)"),
369
+ data: import_zod.z.string().optional().describe("Transaction data (for contract calls)"),
370
+ chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to estimate on")
371
+ }),
372
+ outputSchema: import_zod.z.object({
373
+ success: import_zod.z.boolean(),
374
+ gasEstimate: import_zod.z.string().optional(),
375
+ to: import_zod.z.string(),
376
+ amount: import_zod.z.string(),
377
+ chain: import_zod.z.string(),
378
+ error: import_zod.z.string().optional()
379
+ }),
380
+ execute: async ({ input, runtime }) => {
381
+ try {
382
+ const { to, amount, data, chain } = input;
383
+ const chainConfig = SUPPORTED_CHAINS[chain];
384
+ const privateKey = runtime.privateKey;
385
+ if (!privateKey) {
386
+ return {
387
+ success: false,
388
+ to,
389
+ amount,
390
+ chain,
391
+ error: "Private key not configured in runtime"
392
+ };
393
+ }
394
+ const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
395
+ const account = (0, import_accounts.privateKeyToAccount)(privateKey);
396
+ const client = (0, import_viem.createPublicClient)({
397
+ chain: chainConfig,
398
+ transport: (0, import_viem.http)(rpcUrl)
399
+ });
400
+ console.log(
401
+ `\u26FD [estimateGas] Estimating gas for transaction to ${to} on ${chain}`
402
+ );
403
+ const gasEstimate = await client.estimateGas({
404
+ account: account.address,
405
+ to,
406
+ value: (0, import_viem.parseEther)(amount),
407
+ data
408
+ });
409
+ console.log(`\u2705 [estimateGas] Estimated gas: ${gasEstimate.toString()}`);
410
+ return {
411
+ success: true,
412
+ gasEstimate: gasEstimate.toString(),
413
+ to,
414
+ amount,
415
+ chain
416
+ };
417
+ } catch (error) {
418
+ const errorMessage = error instanceof Error ? error.message : String(error);
419
+ console.error("\u274C [estimateGas] Error:", errorMessage);
420
+ return {
421
+ success: false,
422
+ to: input.to,
423
+ amount: input.amount,
424
+ chain: input.chain,
425
+ error: errorMessage
426
+ };
427
+ }
428
+ }
429
+ });
430
+ var blockchainTools = {
431
+ getBalance: getBalanceTool,
432
+ getTransaction: getTransactionTool,
433
+ sendTransaction: sendTransactionTool,
434
+ getBlock: getBlockTool,
435
+ getGasPrice: getGasPriceTool,
436
+ estimateGas: estimateGasTool
437
+ };
438
+
439
+ // src/tools/xmtp.ts
440
+ var import_zod2 = require("zod");
441
+ var sendReactionTool = createTool({
442
+ id: "sendReaction",
443
+ description: "Send an emoji reaction to a message to indicate it has been seen",
444
+ inputSchema: import_zod2.z.object({
445
+ emoji: import_zod2.z.string().default("\u{1F440}").describe(
446
+ "The emoji to send as a reaction (supports common emoji like \u{1F44D}, \u2764\uFE0F, \u{1F525}, etc.)"
447
+ ),
448
+ referenceMessageId: import_zod2.z.string().optional().describe(
449
+ "The message ID to react to (uses current message if not provided)"
450
+ )
451
+ }),
452
+ outputSchema: import_zod2.z.object({
453
+ success: import_zod2.z.boolean(),
454
+ emoji: import_zod2.z.string(),
455
+ error: import_zod2.z.string().optional()
456
+ }),
457
+ execute: async ({ input, runtime }) => {
458
+ try {
459
+ const xmtpClient = runtime.xmtpClient;
460
+ const currentMessage = runtime.message;
461
+ if (!xmtpClient) {
462
+ const errorMsg = "\u274C XMTP service not available";
463
+ return { success: false, emoji: input.emoji, error: errorMsg };
464
+ }
465
+ if (!currentMessage) {
466
+ const errorMsg = "\u274C No message to react to";
467
+ return { success: false, emoji: input.emoji, error: errorMsg };
468
+ }
469
+ const messageIdToReactTo = input.referenceMessageId || currentMessage.id;
470
+ console.log(
471
+ `\u{1F440} [sendReaction] Sending ${input.emoji} reaction to message ${messageIdToReactTo}`
472
+ );
473
+ const reactionResult = await xmtpClient.sendReaction({
474
+ messageId: messageIdToReactTo,
475
+ emoji: input.emoji,
476
+ action: "added"
477
+ });
478
+ if (!reactionResult.success) {
479
+ const errorMsg = `\u274C Failed to send reaction: ${reactionResult.error || "Unknown error"}`;
480
+ return { success: false, emoji: input.emoji, error: errorMsg };
481
+ }
482
+ console.log(`\u2705 [sendReaction] Successfully sent ${input.emoji} reaction`);
483
+ return { success: true, emoji: input.emoji };
484
+ } catch (error) {
485
+ const errorMessage = error instanceof Error ? error.message : String(error);
486
+ console.error("\u274C [sendReaction] Error:", errorMessage);
487
+ return { success: false, emoji: input.emoji, error: errorMessage };
488
+ }
489
+ }
490
+ });
491
+ var sendMessageTool = createTool({
492
+ id: "sendMessage",
493
+ description: "Send a message to an XMTP conversation",
494
+ inputSchema: import_zod2.z.object({
495
+ content: import_zod2.z.string().describe("The message content to send"),
496
+ recipientAddress: import_zod2.z.string().optional().describe("Recipient address for new conversations"),
497
+ conversationId: import_zod2.z.string().optional().describe("Existing conversation ID to send to")
498
+ }).refine((data) => data.recipientAddress || data.conversationId, {
499
+ message: "Either recipientAddress or conversationId must be provided"
500
+ }),
501
+ outputSchema: import_zod2.z.object({
502
+ success: import_zod2.z.boolean(),
503
+ messageId: import_zod2.z.string().optional(),
504
+ conversationId: import_zod2.z.string().optional(),
505
+ content: import_zod2.z.string(),
506
+ error: import_zod2.z.string().optional()
507
+ }),
508
+ execute: async ({ input, runtime }) => {
509
+ try {
510
+ const xmtpClient = runtime.xmtpClient;
511
+ const { content, recipientAddress, conversationId } = input;
512
+ if (!xmtpClient) {
513
+ return {
514
+ success: false,
515
+ content,
516
+ error: "XMTP service not available"
517
+ };
518
+ }
519
+ console.log(
520
+ `\u{1F4AC} [sendMessage] Sending message: "${content.substring(0, 50)}${content.length > 50 ? "..." : ""}"`
521
+ );
522
+ let targetConversationId = conversationId;
523
+ if (!targetConversationId && recipientAddress) {
524
+ console.log(
525
+ `\u{1F50D} [sendMessage] Creating/finding conversation with ${recipientAddress}`
526
+ );
527
+ targetConversationId = recipientAddress;
528
+ }
529
+ const messageResult = await xmtpClient.sendMessage({
530
+ content
531
+ });
532
+ if (!messageResult.success) {
533
+ return {
534
+ success: false,
535
+ content,
536
+ error: messageResult.error || "Failed to send message"
537
+ };
538
+ }
539
+ console.log(`\u2705 [sendMessage] Message sent successfully`);
540
+ return {
541
+ success: true,
542
+ messageId: messageResult.data?.conversationId,
543
+ conversationId: messageResult.data?.conversationId,
544
+ content
545
+ };
546
+ } catch (error) {
547
+ const errorMessage = error instanceof Error ? error.message : String(error);
548
+ console.error("\u274C [sendMessage] Error:", errorMessage);
549
+ return {
550
+ success: false,
551
+ content: input.content,
552
+ error: errorMessage
553
+ };
554
+ }
555
+ }
556
+ });
557
+ var sendReplyTool = createTool({
558
+ id: "sendReply",
559
+ description: "Send a reply to a specific message in an XMTP conversation",
560
+ inputSchema: import_zod2.z.object({
561
+ content: import_zod2.z.string().describe("The reply content to send"),
562
+ replyToMessageId: import_zod2.z.string().optional().describe("Message ID to reply to (uses current message if not provided)")
563
+ }),
564
+ outputSchema: import_zod2.z.object({
565
+ success: import_zod2.z.boolean(),
566
+ messageId: import_zod2.z.string().optional(),
567
+ replyToMessageId: import_zod2.z.string().optional(),
568
+ content: import_zod2.z.string(),
569
+ error: import_zod2.z.string().optional()
570
+ }),
571
+ execute: async ({ input, runtime }) => {
572
+ try {
573
+ const xmtpClient = runtime.xmtpClient;
574
+ const currentMessage = runtime.message;
575
+ const { content, replyToMessageId } = input;
576
+ if (!xmtpClient) {
577
+ return {
578
+ success: false,
579
+ content,
580
+ error: "XMTP service not available"
581
+ };
582
+ }
583
+ if (!currentMessage && !replyToMessageId) {
584
+ return {
585
+ success: false,
586
+ content,
587
+ error: "No message to reply to"
588
+ };
589
+ }
590
+ const targetMessageId = replyToMessageId || currentMessage?.id;
591
+ console.log(
592
+ `\u21A9\uFE0F [sendReply] Sending reply to message ${targetMessageId}: "${content.substring(0, 50)}${content.length > 50 ? "..." : ""}"`
593
+ );
594
+ const replyResult = await xmtpClient.sendReply({
595
+ content,
596
+ messageId: targetMessageId
597
+ });
598
+ if (!replyResult.success) {
599
+ return {
600
+ success: false,
601
+ content,
602
+ replyToMessageId: targetMessageId,
603
+ error: replyResult.error || "Failed to send reply"
604
+ };
605
+ }
606
+ console.log(`\u2705 [sendReply] Reply sent successfully`);
607
+ return {
608
+ success: true,
609
+ messageId: replyResult.data?.conversationId,
610
+ replyToMessageId: targetMessageId,
611
+ content
612
+ };
613
+ } catch (error) {
614
+ const errorMessage = error instanceof Error ? error.message : String(error);
615
+ console.error("\u274C [sendReply] Error:", errorMessage);
616
+ return {
617
+ success: false,
618
+ content: input.content,
619
+ replyToMessageId: input.replyToMessageId,
620
+ error: errorMessage
621
+ };
622
+ }
623
+ }
624
+ });
625
+ var getMessageTool = createTool({
626
+ id: "getMessage",
627
+ description: "Get a specific message by ID from XMTP",
628
+ inputSchema: import_zod2.z.object({
629
+ messageId: import_zod2.z.string().describe("The message ID to retrieve")
630
+ }),
631
+ outputSchema: import_zod2.z.object({
632
+ success: import_zod2.z.boolean(),
633
+ message: import_zod2.z.object({
634
+ id: import_zod2.z.string(),
635
+ conversationId: import_zod2.z.string(),
636
+ content: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.record(import_zod2.z.unknown())]),
637
+ senderInboxId: import_zod2.z.string(),
638
+ sentAt: import_zod2.z.string(),
639
+ contentType: import_zod2.z.object({
640
+ typeId: import_zod2.z.string(),
641
+ authorityId: import_zod2.z.string().optional(),
642
+ versionMajor: import_zod2.z.number().optional(),
643
+ versionMinor: import_zod2.z.number().optional()
644
+ }).optional()
645
+ }).optional(),
646
+ error: import_zod2.z.string().optional()
647
+ }),
648
+ execute: async ({ input, runtime }) => {
649
+ try {
650
+ const xmtpClient = runtime.xmtpClient;
651
+ const { messageId } = input;
652
+ if (!xmtpClient) {
653
+ return {
654
+ success: false,
655
+ error: "XMTP service not available"
656
+ };
657
+ }
658
+ console.log(`\u{1F4DC} [getMessage] Retrieving message ${messageId}`);
659
+ const messageResult = await xmtpClient.getMessage({
660
+ messageId
661
+ });
662
+ if (!messageResult.success) {
663
+ return {
664
+ success: false,
665
+ error: messageResult.error || "Failed to get message"
666
+ };
667
+ }
668
+ console.log(
669
+ `\u2705 [getMessage] Retrieved message from ${messageResult.data?.senderInboxId}`
670
+ );
671
+ return {
672
+ success: true,
673
+ message: messageResult.data
674
+ };
675
+ } catch (error) {
676
+ const errorMessage = error instanceof Error ? error.message : String(error);
677
+ console.error("\u274C [getMessage] Error:", errorMessage);
678
+ return {
679
+ success: false,
680
+ error: errorMessage
681
+ };
682
+ }
683
+ }
684
+ });
685
+ var xmtpTools = {
686
+ sendMessage: sendMessageTool,
687
+ sendReply: sendReplyTool,
688
+ sendReaction: sendReactionTool,
689
+ getMessage: getMessageTool
690
+ };
691
+ // Annotate the CommonJS export names for ESM import in node:
692
+ 0 && (module.exports = {
693
+ blockchainTools,
694
+ estimateGasTool,
695
+ getBalanceTool,
696
+ getBlockTool,
697
+ getGasPriceTool,
698
+ getMessageTool,
699
+ getTransactionTool,
700
+ sendMessageTool,
701
+ sendReactionTool,
702
+ sendReplyTool,
703
+ sendTransactionTool,
704
+ xmtpTools
705
+ });
706
+ //# sourceMappingURL=index.cjs.map