keyring-chatbot-agent-sdk-test 1.0.26 → 1.0.27
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 +340 -580
- package/dist/chat-widget.es.js +76 -59
- package/dist/chat-widget.umd.js +2 -2
- package/dist/lib.d.ts +414 -56
- package/package.json +15 -30
- package/.vscode/extensions.json +0 -6
- package/dist/chat-widget-wc.es.js +0 -62
- package/dist/chat-widget-wc.umd.js +0 -2
package/dist/lib.d.ts
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
|
+
import { AgentConfig } from 'keyring-agent-core';
|
|
2
|
+
import { AgentCore } from 'keyring-agent-core';
|
|
3
|
+
import { AgentResponse } from 'keyring-agent-core';
|
|
4
|
+
import { Chain } from 'viem/chains';
|
|
5
|
+
import { CSSProperties } from 'react';
|
|
6
|
+
import { Dispatch } from 'react';
|
|
1
7
|
import { JSX } from 'react/jsx-runtime';
|
|
8
|
+
import { ReactNode } from 'react';
|
|
9
|
+
import { SetStateAction } from 'react';
|
|
2
10
|
|
|
3
11
|
export declare interface Account {
|
|
4
12
|
address: string;
|
|
5
13
|
chainId: number | string;
|
|
6
14
|
}
|
|
7
15
|
|
|
16
|
+
export declare const ActionForm: ({ action, initialValues, onSubmit, onCancel, isSubmitting, tokenInfo, nftInfo, disabled, language, }: ActionFormProps) => JSX.Element | null;
|
|
17
|
+
|
|
18
|
+
declare interface ActionFormProps {
|
|
19
|
+
action: AgentActionType;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
initialValues: Record<string, string>;
|
|
22
|
+
onSubmit: (action: AgentActionType, values: Record<string, string>) => void;
|
|
23
|
+
onCancel: () => void;
|
|
24
|
+
isSubmitting?: boolean;
|
|
25
|
+
tokenInfo?: MessageTokenInfo;
|
|
26
|
+
nftInfo?: MessageNftInfo;
|
|
27
|
+
/** BCP-47 tag core stamped on this action; the form translates against it. */
|
|
28
|
+
language?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare interface AddMessageOptions {
|
|
32
|
+
walletActions?: MessageWalletAction[];
|
|
33
|
+
actionButtons?: MessageActionButton[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare type AgentActionType = 'send_native' | 'send_token' | 'swap_token' | 'approve_token' | 'wrap_native' | 'unwrap_native' | 'send_nft' | 'view_nfts' | 'view_balances' | 'check_balance' | 'token_info' | 'chat';
|
|
37
|
+
|
|
38
|
+
export { AgentConfig }
|
|
39
|
+
|
|
40
|
+
export { AgentResponse }
|
|
41
|
+
|
|
8
42
|
export declare interface ChatUICustomization {
|
|
9
43
|
chatTitle?: string;
|
|
10
44
|
welcomeMessage?: string;
|
|
@@ -14,46 +48,7 @@ export declare interface ChatUICustomization {
|
|
|
14
48
|
chatIcon?: string;
|
|
15
49
|
}
|
|
16
50
|
|
|
17
|
-
|
|
18
|
-
* `ChatWidget` is the main entry point for embedding the Keyring AI chat assistant
|
|
19
|
-
* into your dApp. It renders a floating chat button that opens a full-featured
|
|
20
|
-
* chat modal with AI-powered responses, token/NFT lookups, and on-chain transaction support.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* import { ChatWidget } from '@keyringpro/chatbot-agent-sdk';
|
|
25
|
-
*
|
|
26
|
-
* function App() {
|
|
27
|
-
* const { account, sendTransaction } = useWallet(); // your wallet hook
|
|
28
|
-
*
|
|
29
|
-
* return (
|
|
30
|
-
* <ChatWidget
|
|
31
|
-
* account={{ address: account.address, chainId: account.chainId }}
|
|
32
|
-
* onTransaction={sendTransaction}
|
|
33
|
-
* language="en"
|
|
34
|
-
* position="bottom-right"
|
|
35
|
-
* theme={{ primaryColor: '#6366f1', buttonSize: 56 }}
|
|
36
|
-
* rpcUrls={{ 1: 'https://mainnet.infura.io/v3/YOUR_KEY' }}
|
|
37
|
-
* />
|
|
38
|
-
* );
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @param position - Corner to anchor the widget. `'bottom-right'` (default) or `'bottom-left'`.
|
|
43
|
-
* @param theme - Visual customisation: `primaryColor` (hex/CSS), `buttonSize` (px), `zIndex`.
|
|
44
|
-
* @param defaultOpen - If `true`, the chat modal is open on first render. Defaults to `false`.
|
|
45
|
-
* @param onOpen - Callback fired when the chat modal opens.
|
|
46
|
-
* @param onClose - Callback fired when the chat modal closes.
|
|
47
|
-
* @param account - Connected wallet info (`address` + `chainId`). Pass `undefined` when not connected.
|
|
48
|
-
* @param onTransaction - **Required for on-chain actions.** Receives an unsigned transaction object
|
|
49
|
-
* and must return a promise that resolves to `{ status, transactionHash?, error? }`.
|
|
50
|
-
* The widget uses this to sign & broadcast swap / send transactions.
|
|
51
|
-
* @param language - UI language: `'en'` (English, default), `'ja'` (Japanese), `'cn'` (Chinese).
|
|
52
|
-
* @param rpcUrls - Optional map of `chainId → RPC URL`. When provided, these URLs take priority
|
|
53
|
-
* over the built-in defaults for balance queries and fee estimation.
|
|
54
|
-
* e.g. `{ 1: 'https://...', 137: 'https://...' }`
|
|
55
|
-
*/
|
|
56
|
-
export declare const ChatWidget: ({ position, theme, defaultOpen, onOpen, onClose, account, onTransaction, language, rpcUrls, chatTitle, welcomeMessage, customSuggestions, additionalSuggestions, buttonIcon, chatIcon, customChatButton, styleButtonChat, modalConfig, }: ChatWidgetProps) => JSX.Element | null;
|
|
51
|
+
export declare const ChatWidget: ({ position, theme, defaultOpen, onOpen, onClose, account, language, rpcUrls, chatTitle, welcomeMessage, customSuggestions, additionalSuggestions, buttonIcon, chatIcon, customChatButton, styleButtonChat, modalConfig, onTransaction, }: ChatWidgetProps) => JSX.Element | null;
|
|
57
52
|
|
|
58
53
|
/** Alias kept for backwards-compatibility */
|
|
59
54
|
export declare type ChatWidgetLanguage = Language;
|
|
@@ -65,7 +60,6 @@ export declare interface ChatWidgetProps {
|
|
|
65
60
|
onOpen?: () => void;
|
|
66
61
|
onClose?: () => void;
|
|
67
62
|
account?: Account;
|
|
68
|
-
onTransaction?: (tx: Transaction) => Promise<TransactionResult>;
|
|
69
63
|
language?: ChatWidgetLanguage;
|
|
70
64
|
rpcUrls?: Record<number, string>;
|
|
71
65
|
chatTitle?: string;
|
|
@@ -74,11 +68,19 @@ export declare interface ChatWidgetProps {
|
|
|
74
68
|
additionalSuggestions?: SuggestionButtonConfig[];
|
|
75
69
|
buttonIcon?: string;
|
|
76
70
|
chatIcon?: string;
|
|
77
|
-
customChatButton?:
|
|
78
|
-
styleButtonChat?:
|
|
71
|
+
customChatButton?: ReactNode;
|
|
72
|
+
styleButtonChat?: CSSProperties;
|
|
79
73
|
modalConfig?: {
|
|
80
74
|
isShowIcon?: boolean;
|
|
81
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Invoked when the user confirms an `ActionForm` or `BuyTokenConfirmTx`. The
|
|
78
|
+
* widget hands over the unsigned tx `{from, to, data, value, chainId}`; the
|
|
79
|
+
* host signs and broadcasts, then returns
|
|
80
|
+
* `{status, transactionHash?, error?}`. Required for send / approve /
|
|
81
|
+
* wrap / unwrap / send_nft / buy.
|
|
82
|
+
*/
|
|
83
|
+
onTransaction?: (tx: Transaction) => Promise<TransactionResult>;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export declare interface ChatWidgetTheme {
|
|
@@ -104,29 +106,304 @@ export declare interface Config {
|
|
|
104
106
|
[key: string]: unknown;
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
declare interface ConfigContextValue {
|
|
110
|
+
config: Config | null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export declare const ConfigProvider: ({ children, initialConfig, }: ConfigProviderProps) => JSX.Element;
|
|
114
|
+
|
|
115
|
+
declare interface ConfigProviderProps {
|
|
116
|
+
children: React.ReactNode;
|
|
117
|
+
initialConfig?: Config;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare interface ConnectContextDerived extends ConnectContextValue {
|
|
121
|
+
chainData: IChainData | undefined;
|
|
122
|
+
chainId: number | string | undefined;
|
|
123
|
+
chainType: string;
|
|
124
|
+
chainTypeMoralis: string;
|
|
125
|
+
isChainSupported: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare interface ConnectContextValue {
|
|
129
|
+
account: Account | null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export declare const ConnectProvider: ({ children, initialAccount, }: ConnectProviderProps) => JSX.Element;
|
|
133
|
+
|
|
134
|
+
declare interface ConnectProviderProps {
|
|
135
|
+
children: React.ReactNode;
|
|
136
|
+
initialAccount?: Account | null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
declare const _default: {
|
|
140
|
+
"chatTitle": "Keyring Agent",
|
|
141
|
+
"closeChat": "Close chat",
|
|
142
|
+
"messagePlaceholder": "Message ....",
|
|
143
|
+
"sendMessage": "Send message",
|
|
144
|
+
"botIsTyping": "Bot is typing",
|
|
145
|
+
"canIHelpYou": "Can I help you with anything?",
|
|
146
|
+
"suggestionAskText": "Ask a question",
|
|
147
|
+
"suggestionAskUserMessage": "I have a question",
|
|
148
|
+
"suggestionAskBotReply": "Ask me anything",
|
|
149
|
+
"suggestionBuyText": "Buy trending token",
|
|
150
|
+
"walletConnectedChainUnsupported": "Your wallet is connected but the chain is not supported for trading. Please switch to a supported chain to see trending tokens.",
|
|
151
|
+
"walletNotConnected": "Please connect your wallet to see trending tokens.",
|
|
152
|
+
"actionProcessing": "⏳ Processing transaction...",
|
|
153
|
+
"actionSuccess": "✅ Transaction completed",
|
|
154
|
+
"actionFail": "❌ Action cancelled or failed",
|
|
155
|
+
"txSubmitted": "⏳ Transaction submitted. Waiting for confirmation...",
|
|
156
|
+
"txConfirmed": "✅ Transaction confirmed!",
|
|
157
|
+
"txReverted": "❌ Transaction reverted on-chain.",
|
|
158
|
+
"txTimeout": "⚠️ Transaction submitted but confirmation timed out. Please check manually.",
|
|
159
|
+
"txSuccessful": "✅ Transaction successful!",
|
|
160
|
+
"txFailed": "❌ Transaction failed. Please try again.",
|
|
161
|
+
"txNoHandler": "⚠️ No transaction handler configured.",
|
|
162
|
+
"txInsufficientGas": "⚠️ **Insufficient {symbol} for gas!** You have {balance} {symbol} but need ~{fee} {symbol} for the transaction fee. Please top up your wallet and try again.",
|
|
163
|
+
"txError": "❌ Error: {message}",
|
|
164
|
+
"swapConfirmButton": "Confirm",
|
|
165
|
+
"swapConfirmValue": "Confirm swap",
|
|
166
|
+
"swapReadyToProceed": "Ready to proceed with the swap?",
|
|
167
|
+
"swapEstimationError": "⚠️ Unable to get swap estimation. Error: {error}",
|
|
168
|
+
"formCancel": "Cancel",
|
|
169
|
+
"formExecute": "Execute",
|
|
170
|
+
"formProcessing": "⏳ Processing...",
|
|
171
|
+
"formBalance": "Balance:",
|
|
172
|
+
"formTokenNotFound": "Token not found in your wallet.",
|
|
173
|
+
"formNoBalance": "You have no {symbol} balance in your wallet.",
|
|
174
|
+
"formInsufficientBalance": "Insufficient balance. Spendable: {balance} {symbol}",
|
|
175
|
+
"formFieldRequired": "{field} is required",
|
|
176
|
+
"formInvalidAddress": "Invalid address (Must contain 0x and 40 hex chars)",
|
|
177
|
+
"formMustBePositive": "Must be a positive number",
|
|
178
|
+
"formMustBeValidNumber": "Must be a valid number",
|
|
179
|
+
"openChat": "Open chat",
|
|
180
|
+
"openChatTitle": "Open chat support",
|
|
181
|
+
"walletBalanceSpendable": "This is the spendable balance of your wallet on {chain} chain. Please choose the coins you want to use for this trade.",
|
|
182
|
+
"walletNoTokensFound": "Sorry, I couldn't find any tokens in your wallet on {chain} chain. Please make sure you have some tokens to trade.",
|
|
183
|
+
"walletFetchFailed": "Sorry, I could not fetch your wallet balance. Please try again.",
|
|
184
|
+
"walletFetchError": "Sorry, I encountered an error fetching your wallet balance.",
|
|
185
|
+
"insufficientFeeToken": "Insufficient fee. Please ensure you have enough {symbol} to cover the transaction fees, or select a different token.",
|
|
186
|
+
"selectAmountOf": "Select the amount of {symbol} to use:\n\nSpendable: {balance} {symbol}",
|
|
187
|
+
"swapFeeWarning": "\n⚠️ **Insufficient {symbol} for fees!**\n You have {balance} {symbol} but need ~{needed} {symbol}.\n",
|
|
188
|
+
"swapNeedApprove": "You need to approve {symbol} first before swapping.",
|
|
189
|
+
"swapApproveButton": "Approve {symbol}",
|
|
190
|
+
"swapApproveValue": "Approve {symbol} for swap",
|
|
191
|
+
"swapNoSourceToken": "⚠️ You don't have the source token in your wallet or balance is 0.",
|
|
192
|
+
"swapSelectAmount": "Swap {from} → {to}\n\nSelect the amount of {from} to swap:\n\nSpendable: {balance} {from}",
|
|
193
|
+
"swapApprovalRequired": "⚠️ Token approval required before swapping.\n\nStep 1: Approve {symbol}\nStep 2: Confirm Swap",
|
|
194
|
+
"swapEstimationFailed": "⚠️ Failed to get swap estimation. Please try again.",
|
|
195
|
+
"swapInsufficientNativeBalance": "⚠️ Insufficient balance! You have {balance} {symbol} but need {amount} {symbol}. Please top up your wallet or reduce the amount.",
|
|
196
|
+
"swapTokenNotInWallet": "⚠️ You don't have {symbol} in your wallet. Please acquire some first before swapping.",
|
|
197
|
+
"swapInsufficientTokenBalance": "⚠️ Insufficient balance! You have {balance} {symbol} but need {amount} {symbol}. Please reduce the amount or add more tokens.",
|
|
198
|
+
"selectAmountToSwap": "Select the amount of {symbol} to swap:\n\nSpendable: {balance} {symbol}",
|
|
199
|
+
"couldNotLoadTokenList": "⚠️ Could not load token list. Please specify the destination token.",
|
|
200
|
+
"trendingTokensForReceive": "📈 Trending tokens on {chain} chain. Pick the token you want to receive or type the token you want to receive:",
|
|
201
|
+
"txProcessing": "⏳ Transaction processing... Please confirm in your wallet.",
|
|
202
|
+
"txConfirmedSwap": "✅ Transaction confirmed! Your swap has been completed.",
|
|
203
|
+
"txRevertedSwap": "❌ Transaction reverted on-chain. Please try again.",
|
|
204
|
+
"txSuccessfulSwap": "✅ Transaction successful! Your swap has been completed.",
|
|
205
|
+
"txSuccessfulSendToken": "✅ Sent successfully **{amount} {symbol}** to {to}",
|
|
206
|
+
"txSuccessfulSendNative": "✅ Sent successfully **{amount} {symbol}** to {to}",
|
|
207
|
+
"txSuccessfulSendNft": "✅ Sent successfully NFT **{name}** (#{tokenId}) to {to}",
|
|
208
|
+
"txSuccessfulWrapNative": "✅ Wrapped successfully **{amount} {from}** → **{to}**",
|
|
209
|
+
"txSuccessfulUnwrapNative": "✅ Unwrapped successfully **{amount} {from}** → **{to}**",
|
|
210
|
+
"txDataNotAvailable": "⚠️ Transaction data not available.",
|
|
211
|
+
"approvalDataNotAvailable": "⚠️ Approval data not available.",
|
|
212
|
+
"approving": "Approving {symbol}... Please confirm in your wallet.",
|
|
213
|
+
"approvalSuccess": "✅ {symbol} approved successfully!",
|
|
214
|
+
"approvalConfirmSwap": "Now you can execute the swap.",
|
|
215
|
+
"confirmSwapButton": "Confirm Swap",
|
|
216
|
+
"approvalFailed": "❌ Approval failed. Please try again.",
|
|
217
|
+
"couldNotFetchBalance": "⚠️ Could not fetch your wallet balance.",
|
|
218
|
+
"couldNotLoadBalance": "⚠️ Could not load balance. Please try again.",
|
|
219
|
+
"couldNotFetchBalanceRetry": "⚠️ Could not fetch your balance. Please try again.",
|
|
220
|
+
"nftSendReview": "📤 Send **{name}** ({standard} #{tokenId})\n\nPlease review and fill in the recipient address below:",
|
|
221
|
+
"nftCollectionHeader": "Your NFTs :\n\n{list}",
|
|
222
|
+
"nftMoreItems": "\n\nAnd {count} more NFTs...",
|
|
223
|
+
"nftSelectBelow": "\n\nSelect an NFT below to send",
|
|
224
|
+
"nftNoCollection": "You don't have any NFTs in your wallet on this chain.",
|
|
225
|
+
"nftMultipleMatchesForTokenId": "I found {count} NFTs with Token ID #{tokenId} in your wallet. Please select the one you want to send:",
|
|
226
|
+
"nftNotFoundInWallet": "I couldn't find \"{name}\" in your NFT collection. You don't own this NFT on this chain.",
|
|
227
|
+
"nftFetchError": "Sorry, I encountered an error fetching your NFTs.",
|
|
228
|
+
"trendingTokensHeader": "📈 Here is the list of tokens that are currently trending upwards on {chain} chain",
|
|
229
|
+
"trendingTokensQuestion": "\nIs there any token you want to buy?",
|
|
230
|
+
"trendingTokensError": "Sorry, I encountered an error fetching trending tokens.",
|
|
231
|
+
"errorProcessingRequest": "Sorry, I encountered an error processing your request.Please try again in a few moments.",
|
|
232
|
+
"buttonBuyWith": "Buy with {symbol}",
|
|
233
|
+
"buttonUsePercent": "Use {percent}% of {symbol}",
|
|
234
|
+
"buttonBuyToken": "Buy {name} ({symbol})",
|
|
235
|
+
"buttonSendNft": "Send {name}",
|
|
236
|
+
"buttonSwapTo": "Swap to {name} ({symbol})",
|
|
237
|
+
"buttonBuySymbol": "Buy {symbol}",
|
|
238
|
+
"viewBalancesLoading": "Fetching your wallet balances...",
|
|
239
|
+
"viewBalancesHeader": "Your token balances on {chain}:\n\n{list}",
|
|
240
|
+
"viewBalancesEmpty": "You don't have any tokens in your wallet on this chain.",
|
|
241
|
+
"viewBalancesFetchError": "Sorry, I encountered an error fetching your balances.",
|
|
242
|
+
"buttonSendToken": "Send {symbol}",
|
|
243
|
+
"formMax": "MAX",
|
|
244
|
+
"buttonSwapToken": "Swap {symbol}",
|
|
245
|
+
"buttonBuyMoreToken": "Buy more {symbol}",
|
|
246
|
+
"actionSendNativeLabel": "Send Native Token",
|
|
247
|
+
"actionSendNativeDesc": "Send native token (ETH, BNB, MATIC, etc.) to an address",
|
|
248
|
+
"actionSendTokenLabel": "Send Token (ERC20)",
|
|
249
|
+
"actionSendTokenDesc": "Send an ERC20 token to an address",
|
|
250
|
+
"actionSwapTokenLabel": "Swap Token",
|
|
251
|
+
"actionSwapTokenDesc": "Swap one token for another",
|
|
252
|
+
"actionApproveTokenLabel": "Approve Token",
|
|
253
|
+
"actionApproveTokenDesc": "Approve a spender to use your tokens",
|
|
254
|
+
"actionWrapNativeLabel": "Wrap Native Token",
|
|
255
|
+
"actionWrapNativeDesc": "Wrap native token (ETH → WETH)",
|
|
256
|
+
"actionUnwrapNativeLabel": "Unwrap Native Token",
|
|
257
|
+
"actionUnwrapNativeDesc": "Unwrap native token (WETH → ETH)",
|
|
258
|
+
"actionSendNftLabel": "Send NFT",
|
|
259
|
+
"actionSendNftDesc": "Transfer an ERC721 or ERC1155 NFT to another address",
|
|
260
|
+
"fieldToAddress": "Recipient Address",
|
|
261
|
+
"fieldAmount": "Amount",
|
|
262
|
+
"fieldTokenContract": "Token Contract",
|
|
263
|
+
"fieldTokenSymbol": "Token Symbol",
|
|
264
|
+
"fieldDecimals": "Decimals",
|
|
265
|
+
"fieldTokenIn": "From Token",
|
|
266
|
+
"fieldTokenInSymbol": "From Symbol",
|
|
267
|
+
"fieldTokenOut": "To Token",
|
|
268
|
+
"fieldTokenOutSymbol": "To Symbol",
|
|
269
|
+
"fieldTokenInDecimals": "From Decimals",
|
|
270
|
+
"fieldTokenOutDecimals": "To Decimals",
|
|
271
|
+
"fieldSpenderAddress": "Spender Address",
|
|
272
|
+
"fieldAmountUnlimited": "Amount (empty = unlimited)",
|
|
273
|
+
"fieldNftContract": "NFT Contract",
|
|
274
|
+
"fieldTokenId": "Token ID",
|
|
275
|
+
"fieldTokenStandard": "Token Standard",
|
|
276
|
+
"fieldNftName": "NFT Name",
|
|
277
|
+
"formMustBePositiveInteger": "Must be a positive integer",
|
|
278
|
+
"formAmountExceedsNft": "Amount cannot exceed available balance {max}",
|
|
279
|
+
"receivedButtonValue": "Received: {value}",
|
|
280
|
+
"actionExecutedFor": "Action \"{action}\" executed for: {value}",
|
|
281
|
+
"buyTokenHelp": "I'll help you buy {symbol}. Let me show your available tokens to trade with.",
|
|
282
|
+
"tokenNotFoundOnChain": "I couldn't find the token \"{symbol}\" on this chain. Here are the trending tokens you can buy",
|
|
283
|
+
"swapPreparing": "Preparing your swap...",
|
|
284
|
+
"swapConfirmYes": "Yes",
|
|
285
|
+
"swapChooseFrom": "Please choose which token you want to swap from:",
|
|
286
|
+
"swapChooseTo": "You want to swap {symbol}. Please choose which token you want to receive:",
|
|
287
|
+
"swapNeedDetails": "I need more details for your swap. Please specify which tokens you want to swap (e.g. \"Swap 1 ETH to USDC\").",
|
|
288
|
+
"viewNftsLoading": "Let me show you your NFT collection!",
|
|
289
|
+
"sendTokenNotInWallet": "You don't have {symbol} in your wallet on this chain. Please acquire some first before sending.",
|
|
290
|
+
"sendTokenChoose": "Which token would you like to send?",
|
|
291
|
+
"sendNftChoose": "Which NFT would you like to send?",
|
|
292
|
+
"swapChooseToken": "Which token would you like to swap? Here are your current balances:",
|
|
293
|
+
"spendable": "Spendable",
|
|
294
|
+
"welcomeMessage": "**Welcome! 🚀**\nYou’re now connected and ready to explore the world of Blockchain. I can assist you anytime with NFT insights, trading, price tracking, and portfolio analysis.",
|
|
295
|
+
"sendOtherNfts": "\nIf the NFT you want to send is not in the list above, please visit our website to send it.",
|
|
296
|
+
"sendNftViaWebsite": "Please select the NFT you would like to send from the list and proceed via this website.",
|
|
297
|
+
"sendNftViaWebsiteWithLink": "Please select the NFT you would like to send from the list and proceed via [this website]({link}).",
|
|
298
|
+
"viewNftViaWebsite": "Please view your NFT collection on this website for more details.",
|
|
299
|
+
"viewNftViaWebsiteWithLink": "Please view your NFT collection on [this website]({link}) for more details.",
|
|
300
|
+
"buyingOnChain": "Buying {symbol} on {chain}",
|
|
301
|
+
"viewOnExplorer": "View on Explorer",
|
|
302
|
+
"copyWalletAddress": "Copy wallet address",
|
|
303
|
+
"copied": "Copied!",
|
|
304
|
+
"copyAddress": "Copy address",
|
|
305
|
+
"poolGeneralInfoIntro": "💧 **Liquidity Pools** are smart contracts where users deposit token pairs to provide liquidity for DEX trading (like Uniswap). Liquidity providers (LPs) earn trading fees from each swap.",
|
|
306
|
+
"poolGeneralInfoMetricsTitle": "**Key Metrics:**",
|
|
307
|
+
"poolGeneralInfoMetricTVL": "**TVL** - Total Value Locked in the pool",
|
|
308
|
+
"poolGeneralInfoMetricAPR": "**APR** - Estimated annual return from fees",
|
|
309
|
+
"poolGeneralInfoMetricVol24h": "**Volume 24h** - Trading volume in last 24 hours",
|
|
310
|
+
"poolGeneralInfoMetricFeeTier": "**Fee Tier** - Trading fee (0.01%, 0.05%, 0.3%, 1%)",
|
|
311
|
+
"poolGeneralInfoTryAsk": "Try asking something specific, like: *\"ETH/USDC pools on Base\"* or *\"Highest APR pools\"*.",
|
|
312
|
+
"poolNoMatch": "❌ No matching pools found.",
|
|
313
|
+
"poolNoMatchForTokenOnChain": "❌ No matching pools found for **{token}** on **{chain}**.",
|
|
314
|
+
"poolSuggestionsTitle": "💡 **Suggestions:**",
|
|
315
|
+
"poolSuggestionTryChain": "Try a different chain (Ethereum, Base, Arbitrum...)",
|
|
316
|
+
"poolSuggestionTryPair": "Try a more popular pair (ETH/USDC, ETH/USDT)",
|
|
317
|
+
"poolSuggestionRelaxFilters": "Remove filters if too narrow",
|
|
318
|
+
"poolHeaderBest": "🏆 Best Pool",
|
|
319
|
+
"poolHeaderSafe": "🛡️ Safest Pools",
|
|
320
|
+
"poolHeaderTrending": "🔥 Trending Pools",
|
|
321
|
+
"poolHeaderHighApr": "📈 Highest APR Pools",
|
|
322
|
+
"poolHeaderLowFee": "💰 Lowest Fee Pools",
|
|
323
|
+
"poolHeaderCompare": "⚖️ Pool Comparison",
|
|
324
|
+
"poolHeaderDetail": "🔎 Pool Details",
|
|
325
|
+
"poolHeaderGeneral": "💧 Pool Info",
|
|
326
|
+
"poolHeaderSearch": "🔍 Search Results",
|
|
327
|
+
"poolTableMetric": "Metric",
|
|
328
|
+
"poolTableValue": "Value",
|
|
329
|
+
"poolTableLink": "Link",
|
|
330
|
+
"poolLinkView": "View on Uniswap",
|
|
331
|
+
"poolRecommendationHighApr": "👉 **Recommended:** [{pair}]({link}) - Highest APR at **{apr}%**. _Note: Higher APR may come with higher risk._",
|
|
332
|
+
"poolRecommendationLowFee": "👉 **Recommended:** [{pair}]({link}) - Lowest fee at **{fee}%**, ideal for frequent trading.",
|
|
333
|
+
"poolRecommendationSafe": "👉 **Recommended:** [{pair}]({link}) - Highest TVL at **{tvl}**, deep liquidity and stable.",
|
|
334
|
+
"poolRecommendationTrending": "👉 **Most Active:** [{pair}]({link}) - 24h Volume **{volume}**, highest trading activity.",
|
|
335
|
+
"poolRecommendationTopPick": "👉 **Top pick:** [{pair}]({link}) - TVL **{tvl}**, best match for your criteria.",
|
|
336
|
+
"sendPositionNoId": "Please provide your LP position ID to send it. For example: \"send position 12345 to 0x...\".",
|
|
337
|
+
"sendPositionNotFound": "Position #{id} was not found in your wallet on {chain}. Please make sure you own this position.",
|
|
338
|
+
"sendPositionReview": "📤 Send LP Position **#{positionId}** ({pair})\n\nPlease enter the recipient address below:",
|
|
339
|
+
"sendPositionFetchError": "Error fetching your positions. Please try again.",
|
|
340
|
+
"poolUnsupportedChain": "This chain is not supported for data queries. Sorry for the inconvenience.",
|
|
341
|
+
"poolUniswapV3Only": "I can only get information of pools that is on Subgraph Uniswap V3."
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
declare interface IChainData extends Chain {
|
|
345
|
+
logo?: string;
|
|
346
|
+
chainId?: number | string;
|
|
347
|
+
chainType?: string;
|
|
348
|
+
chainTypeMoralis?: string;
|
|
349
|
+
customName?: string;
|
|
350
|
+
isSupported?: boolean;
|
|
351
|
+
}
|
|
352
|
+
|
|
107
353
|
export declare type Language = 'en' | 'ja' | 'cn';
|
|
108
354
|
|
|
355
|
+
declare interface LanguageContextValue {
|
|
356
|
+
language: Language;
|
|
357
|
+
setLanguage: (language: Language) => void;
|
|
358
|
+
/** Translate `key` into the current language. */
|
|
359
|
+
t: (key: TranslationKey) => string;
|
|
360
|
+
/** Translate `key` and substitute `{placeholder}` tokens in one step. */
|
|
361
|
+
ti: (key: TranslationKey, vars: Record<string, string>) => string;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export declare const LanguageProvider: ({ children, initialLanguage, }: LanguageProviderProps) => JSX.Element;
|
|
365
|
+
|
|
366
|
+
declare interface LanguageProviderProps {
|
|
367
|
+
children: React.ReactNode;
|
|
368
|
+
initialLanguage?: Language;
|
|
369
|
+
}
|
|
370
|
+
|
|
109
371
|
export declare interface Message {
|
|
110
372
|
id: string;
|
|
111
373
|
text: string;
|
|
112
374
|
sender: 'user' | 'bot';
|
|
113
375
|
timestamp: Date;
|
|
114
|
-
replyTo?: {
|
|
115
|
-
id: string;
|
|
116
|
-
text: string;
|
|
117
|
-
sender: 'user' | 'bot';
|
|
118
|
-
};
|
|
119
376
|
buttons?: MessageButton[];
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
377
|
+
/**
|
|
378
|
+
* One or more wallet-action forms the FE should render below this message
|
|
379
|
+
* (send/swap/wrap/approve/...). Populated from `AgentResponse.uiActions`.
|
|
380
|
+
*/
|
|
381
|
+
walletActions?: MessageWalletAction[];
|
|
382
|
+
/**
|
|
383
|
+
* Agent-suggested follow-up buttons rendered at the bottom of this message.
|
|
384
|
+
* Each one re-submits its `prompt` when clicked. Stacked one-per-line.
|
|
385
|
+
*/
|
|
386
|
+
actionButtons?: MessageActionButton[];
|
|
127
387
|
typeChat?: TypeChat;
|
|
128
388
|
}
|
|
129
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Suggested-action button emitted by the agent (`AgentResponse.actionButtons`).
|
|
392
|
+
* Click submits `prompt` as the next user message.
|
|
393
|
+
*/
|
|
394
|
+
export declare interface MessageActionButton {
|
|
395
|
+
/** Display text on the button. */
|
|
396
|
+
label: string;
|
|
397
|
+
/** Text sent back to the agent on click. */
|
|
398
|
+
prompt: string;
|
|
399
|
+
/**
|
|
400
|
+
* BCP-47 language tag of the conversation when this button was emitted.
|
|
401
|
+
* `prompt` is often a synthetic English command, so on click pass this back
|
|
402
|
+
* as `chat(prompt, { language })` to keep the reply in the right language.
|
|
403
|
+
*/
|
|
404
|
+
language?: string;
|
|
405
|
+
}
|
|
406
|
+
|
|
130
407
|
export declare interface MessageButton {
|
|
131
408
|
id: string;
|
|
132
409
|
text: string;
|
|
@@ -136,7 +413,7 @@ export declare interface MessageButton {
|
|
|
136
413
|
fullWidth?: boolean;
|
|
137
414
|
}
|
|
138
415
|
|
|
139
|
-
declare interface MessageNftInfo {
|
|
416
|
+
export declare interface MessageNftInfo {
|
|
140
417
|
name: string;
|
|
141
418
|
image?: string;
|
|
142
419
|
tokenId: string;
|
|
@@ -149,6 +426,12 @@ export declare interface MessageTokenInfo {
|
|
|
149
426
|
name: string;
|
|
150
427
|
balance: string;
|
|
151
428
|
balanceFormatted: string;
|
|
429
|
+
/**
|
|
430
|
+
* Spendable balance (held − gas reserve) for native coins, as supplied by
|
|
431
|
+
* core in the action `parameters`. Undefined for ERC-20s and when core
|
|
432
|
+
* couldn't compute it — callers fall back to `balanceFormatted`.
|
|
433
|
+
*/
|
|
434
|
+
spendableFormatted?: string;
|
|
152
435
|
usdValue?: number;
|
|
153
436
|
usdPrice?: number;
|
|
154
437
|
decimals: number;
|
|
@@ -156,6 +439,55 @@ export declare interface MessageTokenInfo {
|
|
|
156
439
|
contractAddress: string;
|
|
157
440
|
}
|
|
158
441
|
|
|
442
|
+
/**
|
|
443
|
+
* One UI payload emitted by a `wallet-action` tool, attached to a bot message.
|
|
444
|
+
*
|
|
445
|
+
* Comes in two shapes:
|
|
446
|
+
* - **Form** payloads (`SendNativeForm`, `SendTokenForm`, `SwapTokenForm`,
|
|
447
|
+
* …): props is a `WalletActionProps` — `action`, `parameters`, etc.
|
|
448
|
+
* populated.
|
|
449
|
+
* - **Custom UI** payloads (`BuyTokenConfirmTx`, …): the tool emits a bespoke
|
|
450
|
+
* shape. `action` is empty; the raw props are in `componentProps` for the
|
|
451
|
+
* matching renderer to consume.
|
|
452
|
+
*/
|
|
453
|
+
export declare interface MessageWalletAction {
|
|
454
|
+
/** Component the FE renders (e.g. "SendNativeForm", "BuyTokenConfirmTx"). */
|
|
455
|
+
component: string;
|
|
456
|
+
/** WalletActionType — empty when this is a custom-UI payload. */
|
|
457
|
+
action: string;
|
|
458
|
+
chainId: string;
|
|
459
|
+
walletAddress: string;
|
|
460
|
+
parameters: Record<string, string>;
|
|
461
|
+
/**
|
|
462
|
+
* Verbatim props for custom-UI payloads (e.g. `BuyTokenConfirmTx`). When set,
|
|
463
|
+
* the FE switches on `component` and forwards this to a bespoke renderer
|
|
464
|
+
* instead of `ActionForm`.
|
|
465
|
+
*/
|
|
466
|
+
componentProps?: Record<string, unknown>;
|
|
467
|
+
/** Optional BCP-47 tag stamped by AgentCore (en/vi/ja/zh/...). */
|
|
468
|
+
language?: string;
|
|
469
|
+
status?: WalletActionStatus;
|
|
470
|
+
/** Hash returned by `onTransaction` after a successful submit. */
|
|
471
|
+
transactionHash?: string;
|
|
472
|
+
/** Error message if the submit fails. */
|
|
473
|
+
errorMessage?: string;
|
|
474
|
+
/**
|
|
475
|
+
* For a `BuyTokenConfirmTx` with an approve step: true once the ERC-20 approve
|
|
476
|
+
* tx has confirmed on-chain. Persisted with the message so a page reload
|
|
477
|
+
* resumes at the swap step instead of asking the user to approve again.
|
|
478
|
+
*/
|
|
479
|
+
approveDone?: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Pre-resolved ERC-20 / native token info — symbol, balance, logo, USD price.
|
|
482
|
+
* Used by `ActionForm` to render the token info card and to clamp the amount
|
|
483
|
+
* field against the available balance. Built from `agent.invokeTool` lookups
|
|
484
|
+
* before the form is shown.
|
|
485
|
+
*/
|
|
486
|
+
tokenInfo?: MessageTokenInfo;
|
|
487
|
+
/** Pre-resolved NFT info for `send_nft` forms. */
|
|
488
|
+
nftInfo?: MessageNftInfo;
|
|
489
|
+
}
|
|
490
|
+
|
|
159
491
|
export declare interface SuggestionButtonConfig {
|
|
160
492
|
icon?: string;
|
|
161
493
|
text: string;
|
|
@@ -186,6 +518,32 @@ export declare interface TransactionResult {
|
|
|
186
518
|
*/
|
|
187
519
|
export declare type TransactionStatus = 'pending' | 'process' | 'success' | 'fail';
|
|
188
520
|
|
|
521
|
+
/** Union of every valid translation key (derived from the English locale). */
|
|
522
|
+
declare type TranslationKey = keyof typeof _default;
|
|
523
|
+
|
|
189
524
|
declare type TypeChat = 'web3' | 'normal';
|
|
190
525
|
|
|
526
|
+
export declare function useAgent(): AgentCore;
|
|
527
|
+
|
|
528
|
+
export declare function useAgentChat({ agent, addMessage }: UseAgentChatParams): {
|
|
529
|
+
send: (rawText: string, language?: string) => Promise<void>;
|
|
530
|
+
isTyping: boolean;
|
|
531
|
+
suggestedPrompts: string[];
|
|
532
|
+
setSuggestedPrompts: Dispatch<SetStateAction<string[]>>;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
declare interface UseAgentChatParams {
|
|
536
|
+
agent: AgentCore;
|
|
537
|
+
addMessage: (text: string, sender: 'user' | 'bot', options?: AddMessageOptions) => Message;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export declare const useConfig: () => ConfigContextValue;
|
|
541
|
+
|
|
542
|
+
export declare const useConnect: () => ConnectContextDerived;
|
|
543
|
+
|
|
544
|
+
export declare const useLanguage: () => LanguageContextValue;
|
|
545
|
+
|
|
546
|
+
/** Status of a wallet-action form attached to a bot message. */
|
|
547
|
+
export declare type WalletActionStatus = 'pending' | 'submitted' | 'success' | 'fail' | 'idle';
|
|
548
|
+
|
|
191
549
|
export { }
|
package/package.json
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyring-chatbot-agent-sdk-test",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "React chat widget for keyring-agent-core — floating chatbot UI with AI answers, wallet/token/NFT lookups",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
8
8
|
"chat",
|
|
9
9
|
"widget",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"ai-agent",
|
|
11
|
+
"keyring",
|
|
12
|
+
"chatbot"
|
|
12
13
|
],
|
|
13
|
-
"homepage": "https://bitbucket.org/bacoorteam/keyring-chatbot-agent-sdk#readme",
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://bitbucket.org/bacoorteam/keyring-chatbot-agent-sdk/issues"
|
|
16
|
-
},
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "git+ssh://git@bitbucket.org/bacoorteam/keyring-chatbot-agent-sdk.git"
|
|
20
|
-
},
|
|
21
14
|
"license": "ISC",
|
|
22
|
-
"author": "",
|
|
23
15
|
"type": "module",
|
|
24
16
|
"exports": {
|
|
25
17
|
".": {
|
|
@@ -28,35 +20,27 @@
|
|
|
28
20
|
"require": "./dist/chat-widget.umd.js",
|
|
29
21
|
"default": "./dist/chat-widget.es.js"
|
|
30
22
|
},
|
|
31
|
-
"./web-component": {
|
|
32
|
-
"import": "./dist/chat-widget-wc.es.js",
|
|
33
|
-
"require": "./dist/chat-widget-wc.umd.js",
|
|
34
|
-
"default": "./dist/chat-widget-wc.es.js"
|
|
35
|
-
},
|
|
36
23
|
"./package.json": "./package.json"
|
|
37
24
|
},
|
|
38
25
|
"main": "./dist/chat-widget.umd.js",
|
|
26
|
+
"module": "./dist/chat-widget.es.js",
|
|
39
27
|
"types": "./dist/lib.d.ts",
|
|
40
28
|
"files": [
|
|
41
29
|
"dist"
|
|
42
30
|
],
|
|
43
31
|
"scripts": {
|
|
44
32
|
"dev": "vite",
|
|
45
|
-
"build": "
|
|
46
|
-
"build:
|
|
47
|
-
"
|
|
48
|
-
"build:production": "yarn build:react:production && yarn build:wc:production",
|
|
49
|
-
"build:react:production": "tsc -b && vite build",
|
|
50
|
-
"build:wc:production": "BUILD_TARGET=web-component vite build",
|
|
51
|
-
"watch": "chokidar 'src/**/*.{ts,tsx,css,json}' -c 'yarn build:react'",
|
|
52
|
-
"watch:production": "chokidar 'src/**/*.{ts,tsx,css,json}' -c 'yarn build:react:production'",
|
|
33
|
+
"build": "tsc -b && vite build --mode development",
|
|
34
|
+
"build:production": "tsc -b && vite build",
|
|
35
|
+
"watch": "chokidar 'src/**/*.{ts,tsx,css,json}' -c 'yarn build'",
|
|
53
36
|
"lint": "eslint .",
|
|
54
37
|
"lint:fix": "eslint . --fix",
|
|
55
38
|
"format": "prettier --write \"src/**/*.{ts,tsx,css,json}\"",
|
|
56
39
|
"preview": "vite preview",
|
|
57
|
-
"
|
|
58
|
-
"publish
|
|
59
|
-
"
|
|
40
|
+
"set-package": "node scripts/set-package.mjs",
|
|
41
|
+
"publish-package": "./scripts/release.sh",
|
|
42
|
+
"release": "./scripts/release.sh",
|
|
43
|
+
"publish-all": "./scripts/publish-all.sh"
|
|
60
44
|
},
|
|
61
45
|
"dependencies": {
|
|
62
46
|
"@solana/web3.js": "^1.98.4",
|
|
@@ -64,6 +48,7 @@
|
|
|
64
48
|
"bignumber.js": "^9.3.1",
|
|
65
49
|
"lodash": "^4.17.23",
|
|
66
50
|
"react-device-detect": "^2.2.3",
|
|
51
|
+
"react-markdown": "^10.1.0",
|
|
67
52
|
"react-syntax-highlighter": "^16.1.0",
|
|
68
53
|
"remark-gfm": "^4.0.1",
|
|
69
54
|
"viem": "^2.45.1"
|
|
@@ -94,10 +79,10 @@
|
|
|
94
79
|
"vite-plugin-dts": "^4.5.4"
|
|
95
80
|
},
|
|
96
81
|
"peerDependencies": {
|
|
82
|
+
"keyring-agent-core": "^0.1.0",
|
|
97
83
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
98
84
|
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
99
85
|
},
|
|
100
|
-
"module": "./dist/chat-widget.es.js",
|
|
101
86
|
"sideEffects": [
|
|
102
87
|
"**/*.css"
|
|
103
88
|
],
|