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