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.
- package/dist/{agent-BxbcW5UC.d.cts → agent-6fncjbIG.d.ts} +4 -71
- package/dist/{agent-BxbcW5UC.d.ts → agent-MbcG6CoX.d.cts} +4 -71
- package/dist/index.cjs +654 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +654 -1
- package/dist/index.js.map +1 -1
- package/dist/ponder/index.d.cts +2 -1
- package/dist/ponder/index.d.ts +2 -1
- package/dist/tool-CoVdD8Fb.d.cts +73 -0
- package/dist/tool-CoVdD8Fb.d.ts +73 -0
- package/dist/tools/index.cjs +706 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +1860 -0
- package/dist/tools/index.d.ts +1860 -0
- package/dist/tools/index.js +681 -0
- package/dist/tools/index.js.map +1 -0
- package/package.json +10 -5
- package/src/index.ts +3 -0
- package/src/tools/blockchain.ts +607 -0
- package/src/tools/index.ts +50 -0
- package/src/tools/xmtp.ts +392 -0
package/dist/index.cjs
CHANGED
|
@@ -32,12 +32,24 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Agent: () => Agent,
|
|
34
34
|
PluginRegistry: () => PluginRegistry,
|
|
35
|
+
blockchainTools: () => blockchainTools,
|
|
35
36
|
createTool: () => createTool,
|
|
37
|
+
estimateGasTool: () => estimateGasTool,
|
|
36
38
|
generateXMTPToolsToken: () => generateXMTPToolsToken,
|
|
39
|
+
getBalanceTool: () => getBalanceTool,
|
|
37
40
|
getBgState: () => getBgState,
|
|
41
|
+
getBlockTool: () => getBlockTool,
|
|
42
|
+
getGasPriceTool: () => getGasPriceTool,
|
|
43
|
+
getMessageTool: () => getMessageTool,
|
|
44
|
+
getTransactionTool: () => getTransactionTool,
|
|
38
45
|
listen: () => listen,
|
|
46
|
+
sendMessageTool: () => sendMessageTool,
|
|
47
|
+
sendReactionTool: () => sendReactionTool,
|
|
48
|
+
sendReplyTool: () => sendReplyTool,
|
|
49
|
+
sendTransactionTool: () => sendTransactionTool,
|
|
39
50
|
stopBackground: () => stopBackground,
|
|
40
|
-
toolFactory: () => toolFactory
|
|
51
|
+
toolFactory: () => toolFactory,
|
|
52
|
+
xmtpTools: () => xmtpTools
|
|
41
53
|
});
|
|
42
54
|
module.exports = __toCommonJS(src_exports);
|
|
43
55
|
|
|
@@ -729,15 +741,655 @@ var Agent = class {
|
|
|
729
741
|
listen({ ...opts, agent: this });
|
|
730
742
|
}
|
|
731
743
|
};
|
|
744
|
+
|
|
745
|
+
// src/tools/blockchain.ts
|
|
746
|
+
var import_viem2 = require("viem");
|
|
747
|
+
var import_accounts = require("viem/accounts");
|
|
748
|
+
var import_chains2 = require("viem/chains");
|
|
749
|
+
var import_zod = require("zod");
|
|
750
|
+
var SUPPORTED_CHAINS = {
|
|
751
|
+
mainnet: import_chains2.mainnet,
|
|
752
|
+
sepolia: import_chains2.sepolia,
|
|
753
|
+
polygon: import_chains2.polygon,
|
|
754
|
+
arbitrum: import_chains2.arbitrum,
|
|
755
|
+
optimism: import_chains2.optimism,
|
|
756
|
+
base: import_chains2.base
|
|
757
|
+
};
|
|
758
|
+
var getBalanceTool = createTool({
|
|
759
|
+
id: "getBalance",
|
|
760
|
+
description: "Get the native token balance for a wallet address on a blockchain",
|
|
761
|
+
inputSchema: import_zod.z.object({
|
|
762
|
+
address: import_zod.z.string().describe("The wallet address to check balance for"),
|
|
763
|
+
chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
|
|
764
|
+
}),
|
|
765
|
+
outputSchema: import_zod.z.object({
|
|
766
|
+
success: import_zod.z.boolean(),
|
|
767
|
+
balance: import_zod.z.string().describe("Balance in human readable format (ETH, MATIC, etc.)"),
|
|
768
|
+
balanceWei: import_zod.z.string().describe("Balance in wei (smallest unit)"),
|
|
769
|
+
address: import_zod.z.string(),
|
|
770
|
+
chain: import_zod.z.string(),
|
|
771
|
+
error: import_zod.z.string().optional()
|
|
772
|
+
}),
|
|
773
|
+
execute: async ({ input, runtime }) => {
|
|
774
|
+
try {
|
|
775
|
+
const { address, chain } = input;
|
|
776
|
+
const chainConfig = SUPPORTED_CHAINS[chain];
|
|
777
|
+
const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
|
|
778
|
+
const client = (0, import_viem2.createPublicClient)({
|
|
779
|
+
chain: chainConfig,
|
|
780
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
781
|
+
});
|
|
782
|
+
console.log(`\u{1F50D} [getBalance] Checking balance for ${address} on ${chain}`);
|
|
783
|
+
const balanceWei = await client.getBalance({
|
|
784
|
+
address
|
|
785
|
+
});
|
|
786
|
+
const balance = (0, import_viem2.formatEther)(balanceWei);
|
|
787
|
+
console.log(
|
|
788
|
+
`\u2705 [getBalance] Balance: ${balance} ${chainConfig.nativeCurrency.symbol}`
|
|
789
|
+
);
|
|
790
|
+
return {
|
|
791
|
+
success: true,
|
|
792
|
+
balance: `${balance} ${chainConfig.nativeCurrency.symbol}`,
|
|
793
|
+
balanceWei: balanceWei.toString(),
|
|
794
|
+
address,
|
|
795
|
+
chain
|
|
796
|
+
};
|
|
797
|
+
} catch (error) {
|
|
798
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
799
|
+
console.error("\u274C [getBalance] Error:", errorMessage);
|
|
800
|
+
return {
|
|
801
|
+
success: false,
|
|
802
|
+
balance: "0",
|
|
803
|
+
balanceWei: "0",
|
|
804
|
+
address: input.address,
|
|
805
|
+
chain: input.chain,
|
|
806
|
+
error: errorMessage
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
var getTransactionTool = createTool({
|
|
812
|
+
id: "getTransaction",
|
|
813
|
+
description: "Get transaction details by transaction hash",
|
|
814
|
+
inputSchema: import_zod.z.object({
|
|
815
|
+
hash: import_zod.z.string().describe("The transaction hash to look up"),
|
|
816
|
+
chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
|
|
817
|
+
}),
|
|
818
|
+
outputSchema: import_zod.z.object({
|
|
819
|
+
success: import_zod.z.boolean(),
|
|
820
|
+
transaction: import_zod.z.object({
|
|
821
|
+
hash: import_zod.z.string(),
|
|
822
|
+
from: import_zod.z.string(),
|
|
823
|
+
to: import_zod.z.string().nullable(),
|
|
824
|
+
value: import_zod.z.string(),
|
|
825
|
+
gasUsed: import_zod.z.string().optional(),
|
|
826
|
+
gasPrice: import_zod.z.string().optional(),
|
|
827
|
+
blockNumber: import_zod.z.string().optional(),
|
|
828
|
+
status: import_zod.z.string().optional()
|
|
829
|
+
}).optional(),
|
|
830
|
+
error: import_zod.z.string().optional()
|
|
831
|
+
}),
|
|
832
|
+
execute: async ({ input, runtime }) => {
|
|
833
|
+
try {
|
|
834
|
+
const { hash, chain } = input;
|
|
835
|
+
const chainConfig = SUPPORTED_CHAINS[chain];
|
|
836
|
+
const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
|
|
837
|
+
const client = (0, import_viem2.createPublicClient)({
|
|
838
|
+
chain: chainConfig,
|
|
839
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
840
|
+
});
|
|
841
|
+
console.log(
|
|
842
|
+
`\u{1F50D} [getTransaction] Looking up transaction ${hash} on ${chain}`
|
|
843
|
+
);
|
|
844
|
+
const transaction = await client.getTransaction({
|
|
845
|
+
hash
|
|
846
|
+
});
|
|
847
|
+
const receipt = await client.getTransactionReceipt({
|
|
848
|
+
hash
|
|
849
|
+
}).catch(() => null);
|
|
850
|
+
console.log(
|
|
851
|
+
`\u2705 [getTransaction] Found transaction from ${transaction.from} to ${transaction.to}`
|
|
852
|
+
);
|
|
853
|
+
return {
|
|
854
|
+
success: true,
|
|
855
|
+
transaction: {
|
|
856
|
+
hash: transaction.hash,
|
|
857
|
+
from: transaction.from,
|
|
858
|
+
to: transaction.to,
|
|
859
|
+
value: (0, import_viem2.formatEther)(transaction.value),
|
|
860
|
+
gasUsed: receipt?.gasUsed.toString(),
|
|
861
|
+
gasPrice: transaction.gasPrice?.toString(),
|
|
862
|
+
blockNumber: transaction.blockNumber?.toString(),
|
|
863
|
+
status: receipt?.status === "success" ? "success" : receipt?.status === "reverted" ? "failed" : "pending"
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
} catch (error) {
|
|
867
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
868
|
+
console.error("\u274C [getTransaction] Error:", errorMessage);
|
|
869
|
+
return {
|
|
870
|
+
success: false,
|
|
871
|
+
error: errorMessage
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
var sendTransactionTool = createTool({
|
|
877
|
+
id: "sendTransaction",
|
|
878
|
+
description: "Send native tokens to another address",
|
|
879
|
+
inputSchema: import_zod.z.object({
|
|
880
|
+
to: import_zod.z.string().describe("The recipient address"),
|
|
881
|
+
amount: import_zod.z.string().describe("The amount to send (in ETH, MATIC, etc.)"),
|
|
882
|
+
chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to send on")
|
|
883
|
+
}),
|
|
884
|
+
outputSchema: import_zod.z.object({
|
|
885
|
+
success: import_zod.z.boolean(),
|
|
886
|
+
hash: import_zod.z.string().optional(),
|
|
887
|
+
from: import_zod.z.string().optional(),
|
|
888
|
+
to: import_zod.z.string(),
|
|
889
|
+
amount: import_zod.z.string(),
|
|
890
|
+
chain: import_zod.z.string(),
|
|
891
|
+
error: import_zod.z.string().optional()
|
|
892
|
+
}),
|
|
893
|
+
execute: async ({ input, runtime }) => {
|
|
894
|
+
try {
|
|
895
|
+
const { to, amount, chain } = input;
|
|
896
|
+
const chainConfig = SUPPORTED_CHAINS[chain];
|
|
897
|
+
const privateKey = runtime.privateKey;
|
|
898
|
+
if (!privateKey) {
|
|
899
|
+
return {
|
|
900
|
+
success: false,
|
|
901
|
+
to,
|
|
902
|
+
amount,
|
|
903
|
+
chain,
|
|
904
|
+
error: "Private key not configured in runtime"
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
|
|
908
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
909
|
+
const client = (0, import_viem2.createWalletClient)({
|
|
910
|
+
account,
|
|
911
|
+
chain: chainConfig,
|
|
912
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
913
|
+
});
|
|
914
|
+
console.log(
|
|
915
|
+
`\u{1F4B8} [sendTransaction] Sending ${amount} ${chainConfig.nativeCurrency.symbol} to ${to} on ${chain}`
|
|
916
|
+
);
|
|
917
|
+
const hash = await client.sendTransaction({
|
|
918
|
+
to,
|
|
919
|
+
value: (0, import_viem2.parseEther)(amount)
|
|
920
|
+
});
|
|
921
|
+
console.log(`\u2705 [sendTransaction] Transaction sent: ${hash}`);
|
|
922
|
+
return {
|
|
923
|
+
success: true,
|
|
924
|
+
hash,
|
|
925
|
+
from: account.address,
|
|
926
|
+
to,
|
|
927
|
+
amount,
|
|
928
|
+
chain
|
|
929
|
+
};
|
|
930
|
+
} catch (error) {
|
|
931
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
932
|
+
console.error("\u274C [sendTransaction] Error:", errorMessage);
|
|
933
|
+
return {
|
|
934
|
+
success: false,
|
|
935
|
+
to: input.to,
|
|
936
|
+
amount: input.amount,
|
|
937
|
+
chain: input.chain,
|
|
938
|
+
error: errorMessage
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
var getBlockTool = createTool({
|
|
944
|
+
id: "getBlock",
|
|
945
|
+
description: "Get information about a blockchain block",
|
|
946
|
+
inputSchema: import_zod.z.object({
|
|
947
|
+
blockNumber: import_zod.z.string().optional().describe("Block number (defaults to latest)"),
|
|
948
|
+
chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
|
|
949
|
+
}),
|
|
950
|
+
outputSchema: import_zod.z.object({
|
|
951
|
+
success: import_zod.z.boolean(),
|
|
952
|
+
block: import_zod.z.object({
|
|
953
|
+
number: import_zod.z.string(),
|
|
954
|
+
hash: import_zod.z.string(),
|
|
955
|
+
timestamp: import_zod.z.string(),
|
|
956
|
+
transactionCount: import_zod.z.number(),
|
|
957
|
+
gasUsed: import_zod.z.string(),
|
|
958
|
+
gasLimit: import_zod.z.string()
|
|
959
|
+
}).optional(),
|
|
960
|
+
error: import_zod.z.string().optional()
|
|
961
|
+
}),
|
|
962
|
+
execute: async ({ input, runtime }) => {
|
|
963
|
+
try {
|
|
964
|
+
const { blockNumber, chain } = input;
|
|
965
|
+
const chainConfig = SUPPORTED_CHAINS[chain];
|
|
966
|
+
const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
|
|
967
|
+
const client = (0, import_viem2.createPublicClient)({
|
|
968
|
+
chain: chainConfig,
|
|
969
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
970
|
+
});
|
|
971
|
+
console.log(
|
|
972
|
+
`\u{1F50D} [getBlock] Getting block ${blockNumber || "latest"} on ${chain}`
|
|
973
|
+
);
|
|
974
|
+
const block = await client.getBlock({
|
|
975
|
+
blockNumber: blockNumber ? BigInt(blockNumber) : void 0
|
|
976
|
+
});
|
|
977
|
+
console.log(
|
|
978
|
+
`\u2705 [getBlock] Found block ${block.number} with ${block.transactions.length} transactions`
|
|
979
|
+
);
|
|
980
|
+
return {
|
|
981
|
+
success: true,
|
|
982
|
+
block: {
|
|
983
|
+
number: block.number.toString(),
|
|
984
|
+
hash: block.hash,
|
|
985
|
+
timestamp: block.timestamp.toString(),
|
|
986
|
+
transactionCount: block.transactions.length,
|
|
987
|
+
gasUsed: block.gasUsed.toString(),
|
|
988
|
+
gasLimit: block.gasLimit.toString()
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
} catch (error) {
|
|
992
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
993
|
+
console.error("\u274C [getBlock] Error:", errorMessage);
|
|
994
|
+
return {
|
|
995
|
+
success: false,
|
|
996
|
+
error: errorMessage
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
var getGasPriceTool = createTool({
|
|
1002
|
+
id: "getGasPrice",
|
|
1003
|
+
description: "Get current gas price for a blockchain",
|
|
1004
|
+
inputSchema: import_zod.z.object({
|
|
1005
|
+
chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to check on")
|
|
1006
|
+
}),
|
|
1007
|
+
outputSchema: import_zod.z.object({
|
|
1008
|
+
success: import_zod.z.boolean(),
|
|
1009
|
+
gasPrice: import_zod.z.string().optional().describe("Gas price in gwei"),
|
|
1010
|
+
gasPriceWei: import_zod.z.string().optional().describe("Gas price in wei"),
|
|
1011
|
+
chain: import_zod.z.string(),
|
|
1012
|
+
error: import_zod.z.string().optional()
|
|
1013
|
+
}),
|
|
1014
|
+
execute: async ({ input, runtime }) => {
|
|
1015
|
+
try {
|
|
1016
|
+
const { chain } = input;
|
|
1017
|
+
const chainConfig = SUPPORTED_CHAINS[chain];
|
|
1018
|
+
const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
|
|
1019
|
+
const client = (0, import_viem2.createPublicClient)({
|
|
1020
|
+
chain: chainConfig,
|
|
1021
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
1022
|
+
});
|
|
1023
|
+
console.log(`\u26FD [getGasPrice] Getting gas price for ${chain}`);
|
|
1024
|
+
const gasPrice = await client.getGasPrice();
|
|
1025
|
+
const gasPriceGwei = (0, import_viem2.formatEther)(gasPrice * BigInt(1e9));
|
|
1026
|
+
console.log(`\u2705 [getGasPrice] Current gas price: ${gasPriceGwei} gwei`);
|
|
1027
|
+
return {
|
|
1028
|
+
success: true,
|
|
1029
|
+
gasPrice: `${gasPriceGwei} gwei`,
|
|
1030
|
+
gasPriceWei: gasPrice.toString(),
|
|
1031
|
+
chain
|
|
1032
|
+
};
|
|
1033
|
+
} catch (error) {
|
|
1034
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1035
|
+
console.error("\u274C [getGasPrice] Error:", errorMessage);
|
|
1036
|
+
return {
|
|
1037
|
+
success: false,
|
|
1038
|
+
chain: input.chain,
|
|
1039
|
+
error: errorMessage
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
var estimateGasTool = createTool({
|
|
1045
|
+
id: "estimateGas",
|
|
1046
|
+
description: "Estimate gas required for a transaction",
|
|
1047
|
+
inputSchema: import_zod.z.object({
|
|
1048
|
+
to: import_zod.z.string().describe("The recipient address"),
|
|
1049
|
+
amount: import_zod.z.string().default("0").describe("The amount to send (defaults to 0)"),
|
|
1050
|
+
data: import_zod.z.string().optional().describe("Transaction data (for contract calls)"),
|
|
1051
|
+
chain: import_zod.z.enum(["mainnet", "sepolia", "polygon", "arbitrum", "optimism", "base"]).default("mainnet").describe("The blockchain network to estimate on")
|
|
1052
|
+
}),
|
|
1053
|
+
outputSchema: import_zod.z.object({
|
|
1054
|
+
success: import_zod.z.boolean(),
|
|
1055
|
+
gasEstimate: import_zod.z.string().optional(),
|
|
1056
|
+
to: import_zod.z.string(),
|
|
1057
|
+
amount: import_zod.z.string(),
|
|
1058
|
+
chain: import_zod.z.string(),
|
|
1059
|
+
error: import_zod.z.string().optional()
|
|
1060
|
+
}),
|
|
1061
|
+
execute: async ({ input, runtime }) => {
|
|
1062
|
+
try {
|
|
1063
|
+
const { to, amount, data, chain } = input;
|
|
1064
|
+
const chainConfig = SUPPORTED_CHAINS[chain];
|
|
1065
|
+
const privateKey = runtime.privateKey;
|
|
1066
|
+
if (!privateKey) {
|
|
1067
|
+
return {
|
|
1068
|
+
success: false,
|
|
1069
|
+
to,
|
|
1070
|
+
amount,
|
|
1071
|
+
chain,
|
|
1072
|
+
error: "Private key not configured in runtime"
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
const rpcUrl = runtime.rpcUrl || chainConfig.rpcUrls.default.http[0];
|
|
1076
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
1077
|
+
const client = (0, import_viem2.createPublicClient)({
|
|
1078
|
+
chain: chainConfig,
|
|
1079
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
1080
|
+
});
|
|
1081
|
+
console.log(
|
|
1082
|
+
`\u26FD [estimateGas] Estimating gas for transaction to ${to} on ${chain}`
|
|
1083
|
+
);
|
|
1084
|
+
const gasEstimate = await client.estimateGas({
|
|
1085
|
+
account: account.address,
|
|
1086
|
+
to,
|
|
1087
|
+
value: (0, import_viem2.parseEther)(amount),
|
|
1088
|
+
data
|
|
1089
|
+
});
|
|
1090
|
+
console.log(`\u2705 [estimateGas] Estimated gas: ${gasEstimate.toString()}`);
|
|
1091
|
+
return {
|
|
1092
|
+
success: true,
|
|
1093
|
+
gasEstimate: gasEstimate.toString(),
|
|
1094
|
+
to,
|
|
1095
|
+
amount,
|
|
1096
|
+
chain
|
|
1097
|
+
};
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1100
|
+
console.error("\u274C [estimateGas] Error:", errorMessage);
|
|
1101
|
+
return {
|
|
1102
|
+
success: false,
|
|
1103
|
+
to: input.to,
|
|
1104
|
+
amount: input.amount,
|
|
1105
|
+
chain: input.chain,
|
|
1106
|
+
error: errorMessage
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
var blockchainTools = {
|
|
1112
|
+
getBalance: getBalanceTool,
|
|
1113
|
+
getTransaction: getTransactionTool,
|
|
1114
|
+
sendTransaction: sendTransactionTool,
|
|
1115
|
+
getBlock: getBlockTool,
|
|
1116
|
+
getGasPrice: getGasPriceTool,
|
|
1117
|
+
estimateGas: estimateGasTool
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
// src/tools/xmtp.ts
|
|
1121
|
+
var import_zod2 = require("zod");
|
|
1122
|
+
var sendReactionTool = createTool({
|
|
1123
|
+
id: "sendReaction",
|
|
1124
|
+
description: "Send an emoji reaction to a message to indicate it has been seen",
|
|
1125
|
+
inputSchema: import_zod2.z.object({
|
|
1126
|
+
emoji: import_zod2.z.string().default("\u{1F440}").describe(
|
|
1127
|
+
"The emoji to send as a reaction (supports common emoji like \u{1F44D}, \u2764\uFE0F, \u{1F525}, etc.)"
|
|
1128
|
+
),
|
|
1129
|
+
referenceMessageId: import_zod2.z.string().optional().describe(
|
|
1130
|
+
"The message ID to react to (uses current message if not provided)"
|
|
1131
|
+
)
|
|
1132
|
+
}),
|
|
1133
|
+
outputSchema: import_zod2.z.object({
|
|
1134
|
+
success: import_zod2.z.boolean(),
|
|
1135
|
+
emoji: import_zod2.z.string(),
|
|
1136
|
+
error: import_zod2.z.string().optional()
|
|
1137
|
+
}),
|
|
1138
|
+
execute: async ({ input, runtime }) => {
|
|
1139
|
+
try {
|
|
1140
|
+
const xmtpClient = runtime.xmtpClient;
|
|
1141
|
+
const currentMessage = runtime.message;
|
|
1142
|
+
if (!xmtpClient) {
|
|
1143
|
+
const errorMsg = "\u274C XMTP service not available";
|
|
1144
|
+
return { success: false, emoji: input.emoji, error: errorMsg };
|
|
1145
|
+
}
|
|
1146
|
+
if (!currentMessage) {
|
|
1147
|
+
const errorMsg = "\u274C No message to react to";
|
|
1148
|
+
return { success: false, emoji: input.emoji, error: errorMsg };
|
|
1149
|
+
}
|
|
1150
|
+
const messageIdToReactTo = input.referenceMessageId || currentMessage.id;
|
|
1151
|
+
console.log(
|
|
1152
|
+
`\u{1F440} [sendReaction] Sending ${input.emoji} reaction to message ${messageIdToReactTo}`
|
|
1153
|
+
);
|
|
1154
|
+
const reactionResult = await xmtpClient.sendReaction({
|
|
1155
|
+
messageId: messageIdToReactTo,
|
|
1156
|
+
emoji: input.emoji,
|
|
1157
|
+
action: "added"
|
|
1158
|
+
});
|
|
1159
|
+
if (!reactionResult.success) {
|
|
1160
|
+
const errorMsg = `\u274C Failed to send reaction: ${reactionResult.error || "Unknown error"}`;
|
|
1161
|
+
return { success: false, emoji: input.emoji, error: errorMsg };
|
|
1162
|
+
}
|
|
1163
|
+
console.log(`\u2705 [sendReaction] Successfully sent ${input.emoji} reaction`);
|
|
1164
|
+
return { success: true, emoji: input.emoji };
|
|
1165
|
+
} catch (error) {
|
|
1166
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1167
|
+
console.error("\u274C [sendReaction] Error:", errorMessage);
|
|
1168
|
+
return { success: false, emoji: input.emoji, error: errorMessage };
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1172
|
+
var sendMessageTool = createTool({
|
|
1173
|
+
id: "sendMessage",
|
|
1174
|
+
description: "Send a message to an XMTP conversation",
|
|
1175
|
+
inputSchema: import_zod2.z.object({
|
|
1176
|
+
content: import_zod2.z.string().describe("The message content to send"),
|
|
1177
|
+
recipientAddress: import_zod2.z.string().optional().describe("Recipient address for new conversations"),
|
|
1178
|
+
conversationId: import_zod2.z.string().optional().describe("Existing conversation ID to send to")
|
|
1179
|
+
}).refine((data) => data.recipientAddress || data.conversationId, {
|
|
1180
|
+
message: "Either recipientAddress or conversationId must be provided"
|
|
1181
|
+
}),
|
|
1182
|
+
outputSchema: import_zod2.z.object({
|
|
1183
|
+
success: import_zod2.z.boolean(),
|
|
1184
|
+
messageId: import_zod2.z.string().optional(),
|
|
1185
|
+
conversationId: import_zod2.z.string().optional(),
|
|
1186
|
+
content: import_zod2.z.string(),
|
|
1187
|
+
error: import_zod2.z.string().optional()
|
|
1188
|
+
}),
|
|
1189
|
+
execute: async ({ input, runtime }) => {
|
|
1190
|
+
try {
|
|
1191
|
+
const xmtpClient = runtime.xmtpClient;
|
|
1192
|
+
const { content, recipientAddress, conversationId } = input;
|
|
1193
|
+
if (!xmtpClient) {
|
|
1194
|
+
return {
|
|
1195
|
+
success: false,
|
|
1196
|
+
content,
|
|
1197
|
+
error: "XMTP service not available"
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
console.log(
|
|
1201
|
+
`\u{1F4AC} [sendMessage] Sending message: "${content.substring(0, 50)}${content.length > 50 ? "..." : ""}"`
|
|
1202
|
+
);
|
|
1203
|
+
let targetConversationId = conversationId;
|
|
1204
|
+
if (!targetConversationId && recipientAddress) {
|
|
1205
|
+
console.log(
|
|
1206
|
+
`\u{1F50D} [sendMessage] Creating/finding conversation with ${recipientAddress}`
|
|
1207
|
+
);
|
|
1208
|
+
targetConversationId = recipientAddress;
|
|
1209
|
+
}
|
|
1210
|
+
const messageResult = await xmtpClient.sendMessage({
|
|
1211
|
+
content
|
|
1212
|
+
});
|
|
1213
|
+
if (!messageResult.success) {
|
|
1214
|
+
return {
|
|
1215
|
+
success: false,
|
|
1216
|
+
content,
|
|
1217
|
+
error: messageResult.error || "Failed to send message"
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
console.log(`\u2705 [sendMessage] Message sent successfully`);
|
|
1221
|
+
return {
|
|
1222
|
+
success: true,
|
|
1223
|
+
messageId: messageResult.data?.conversationId,
|
|
1224
|
+
conversationId: messageResult.data?.conversationId,
|
|
1225
|
+
content
|
|
1226
|
+
};
|
|
1227
|
+
} catch (error) {
|
|
1228
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1229
|
+
console.error("\u274C [sendMessage] Error:", errorMessage);
|
|
1230
|
+
return {
|
|
1231
|
+
success: false,
|
|
1232
|
+
content: input.content,
|
|
1233
|
+
error: errorMessage
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
var sendReplyTool = createTool({
|
|
1239
|
+
id: "sendReply",
|
|
1240
|
+
description: "Send a reply to a specific message in an XMTP conversation",
|
|
1241
|
+
inputSchema: import_zod2.z.object({
|
|
1242
|
+
content: import_zod2.z.string().describe("The reply content to send"),
|
|
1243
|
+
replyToMessageId: import_zod2.z.string().optional().describe("Message ID to reply to (uses current message if not provided)")
|
|
1244
|
+
}),
|
|
1245
|
+
outputSchema: import_zod2.z.object({
|
|
1246
|
+
success: import_zod2.z.boolean(),
|
|
1247
|
+
messageId: import_zod2.z.string().optional(),
|
|
1248
|
+
replyToMessageId: import_zod2.z.string().optional(),
|
|
1249
|
+
content: import_zod2.z.string(),
|
|
1250
|
+
error: import_zod2.z.string().optional()
|
|
1251
|
+
}),
|
|
1252
|
+
execute: async ({ input, runtime }) => {
|
|
1253
|
+
try {
|
|
1254
|
+
const xmtpClient = runtime.xmtpClient;
|
|
1255
|
+
const currentMessage = runtime.message;
|
|
1256
|
+
const { content, replyToMessageId } = input;
|
|
1257
|
+
if (!xmtpClient) {
|
|
1258
|
+
return {
|
|
1259
|
+
success: false,
|
|
1260
|
+
content,
|
|
1261
|
+
error: "XMTP service not available"
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
if (!currentMessage && !replyToMessageId) {
|
|
1265
|
+
return {
|
|
1266
|
+
success: false,
|
|
1267
|
+
content,
|
|
1268
|
+
error: "No message to reply to"
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
const targetMessageId = replyToMessageId || currentMessage?.id;
|
|
1272
|
+
console.log(
|
|
1273
|
+
`\u21A9\uFE0F [sendReply] Sending reply to message ${targetMessageId}: "${content.substring(0, 50)}${content.length > 50 ? "..." : ""}"`
|
|
1274
|
+
);
|
|
1275
|
+
const replyResult = await xmtpClient.sendReply({
|
|
1276
|
+
content,
|
|
1277
|
+
messageId: targetMessageId
|
|
1278
|
+
});
|
|
1279
|
+
if (!replyResult.success) {
|
|
1280
|
+
return {
|
|
1281
|
+
success: false,
|
|
1282
|
+
content,
|
|
1283
|
+
replyToMessageId: targetMessageId,
|
|
1284
|
+
error: replyResult.error || "Failed to send reply"
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
console.log(`\u2705 [sendReply] Reply sent successfully`);
|
|
1288
|
+
return {
|
|
1289
|
+
success: true,
|
|
1290
|
+
messageId: replyResult.data?.conversationId,
|
|
1291
|
+
replyToMessageId: targetMessageId,
|
|
1292
|
+
content
|
|
1293
|
+
};
|
|
1294
|
+
} catch (error) {
|
|
1295
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1296
|
+
console.error("\u274C [sendReply] Error:", errorMessage);
|
|
1297
|
+
return {
|
|
1298
|
+
success: false,
|
|
1299
|
+
content: input.content,
|
|
1300
|
+
replyToMessageId: input.replyToMessageId,
|
|
1301
|
+
error: errorMessage
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
var getMessageTool = createTool({
|
|
1307
|
+
id: "getMessage",
|
|
1308
|
+
description: "Get a specific message by ID from XMTP",
|
|
1309
|
+
inputSchema: import_zod2.z.object({
|
|
1310
|
+
messageId: import_zod2.z.string().describe("The message ID to retrieve")
|
|
1311
|
+
}),
|
|
1312
|
+
outputSchema: import_zod2.z.object({
|
|
1313
|
+
success: import_zod2.z.boolean(),
|
|
1314
|
+
message: import_zod2.z.object({
|
|
1315
|
+
id: import_zod2.z.string(),
|
|
1316
|
+
conversationId: import_zod2.z.string(),
|
|
1317
|
+
content: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.record(import_zod2.z.unknown())]),
|
|
1318
|
+
senderInboxId: import_zod2.z.string(),
|
|
1319
|
+
sentAt: import_zod2.z.string(),
|
|
1320
|
+
contentType: import_zod2.z.object({
|
|
1321
|
+
typeId: import_zod2.z.string(),
|
|
1322
|
+
authorityId: import_zod2.z.string().optional(),
|
|
1323
|
+
versionMajor: import_zod2.z.number().optional(),
|
|
1324
|
+
versionMinor: import_zod2.z.number().optional()
|
|
1325
|
+
}).optional()
|
|
1326
|
+
}).optional(),
|
|
1327
|
+
error: import_zod2.z.string().optional()
|
|
1328
|
+
}),
|
|
1329
|
+
execute: async ({ input, runtime }) => {
|
|
1330
|
+
try {
|
|
1331
|
+
const xmtpClient = runtime.xmtpClient;
|
|
1332
|
+
const { messageId } = input;
|
|
1333
|
+
if (!xmtpClient) {
|
|
1334
|
+
return {
|
|
1335
|
+
success: false,
|
|
1336
|
+
error: "XMTP service not available"
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
console.log(`\u{1F4DC} [getMessage] Retrieving message ${messageId}`);
|
|
1340
|
+
const messageResult = await xmtpClient.getMessage({
|
|
1341
|
+
messageId
|
|
1342
|
+
});
|
|
1343
|
+
if (!messageResult.success) {
|
|
1344
|
+
return {
|
|
1345
|
+
success: false,
|
|
1346
|
+
error: messageResult.error || "Failed to get message"
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
console.log(
|
|
1350
|
+
`\u2705 [getMessage] Retrieved message from ${messageResult.data?.senderInboxId}`
|
|
1351
|
+
);
|
|
1352
|
+
return {
|
|
1353
|
+
success: true,
|
|
1354
|
+
message: messageResult.data
|
|
1355
|
+
};
|
|
1356
|
+
} catch (error) {
|
|
1357
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1358
|
+
console.error("\u274C [getMessage] Error:", errorMessage);
|
|
1359
|
+
return {
|
|
1360
|
+
success: false,
|
|
1361
|
+
error: errorMessage
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
var xmtpTools = {
|
|
1367
|
+
sendMessage: sendMessageTool,
|
|
1368
|
+
sendReply: sendReplyTool,
|
|
1369
|
+
sendReaction: sendReactionTool,
|
|
1370
|
+
getMessage: getMessageTool
|
|
1371
|
+
};
|
|
732
1372
|
// Annotate the CommonJS export names for ESM import in node:
|
|
733
1373
|
0 && (module.exports = {
|
|
734
1374
|
Agent,
|
|
735
1375
|
PluginRegistry,
|
|
1376
|
+
blockchainTools,
|
|
736
1377
|
createTool,
|
|
1378
|
+
estimateGasTool,
|
|
737
1379
|
generateXMTPToolsToken,
|
|
1380
|
+
getBalanceTool,
|
|
738
1381
|
getBgState,
|
|
1382
|
+
getBlockTool,
|
|
1383
|
+
getGasPriceTool,
|
|
1384
|
+
getMessageTool,
|
|
1385
|
+
getTransactionTool,
|
|
739
1386
|
listen,
|
|
1387
|
+
sendMessageTool,
|
|
1388
|
+
sendReactionTool,
|
|
1389
|
+
sendReplyTool,
|
|
1390
|
+
sendTransactionTool,
|
|
740
1391
|
stopBackground,
|
|
741
|
-
toolFactory
|
|
1392
|
+
toolFactory,
|
|
1393
|
+
xmtpTools
|
|
742
1394
|
});
|
|
743
1395
|
//# sourceMappingURL=index.cjs.map
|