-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.2.33 #161
Merged
Merged
1.2.33 #161
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2e9587e
fdeeplink framekit
humanagent c2f1474
deeplinks
humanagent c3c812d
deeplinks
humanagent ada448a
circle
humanagent 11a7192
username how to
humanagent a971664
framekit
humanagent 2502f9b
frmaekit
humanagent cbf1ee0
deploy
humanagent a8190fe
deploy
humanagent 1b5ed99
deploy
humanagent 59dd57c
loading receipt
humanagent 990823c
deploy
humanagent 9c9fad1
deploy
humanagent 095425f
deploy
humanagent 1f5f3c6
deploy
humanagent 070f67f
Head html
humanagent 7eba9a0
Head html
humanagent 185a4aa
circle agent
humanagent ec87a70
circle agent
humanagent b22618b
circle agent
humanagent 478befe
circle agent
humanagent 7aeae73
fixes
humanagent 84077bd
deploy
humanagent affd2ef
deploy
humanagent 370a534
deploy
humanagent 9bf13d1
deploy
humanagent 046721d
image
humanagent a5bff9d
params
humanagent a87bbb9
push
humanagent 98711c1
fix
humanagent c3d1c9e
1.2.33
humanagent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,209 +0,0 @@ | ||
# MessageKit | ||
|
||
# Skill Examples | ||
|
||
### Check if a Domain is Available | ||
|
||
|
||
import { ensUrl } from "../index.js"; | ||
import { Context } from "@xmtp/message-kit"; | ||
import type { Skill } from "@xmtp/message-kit"; | ||
|
||
// Define Skill | ||
export const checkDomain: Skill[] = [ | ||
{ | ||
skill: "check", | ||
handler: handler, | ||
examples: ["/check vitalik.eth", "/check fabri.base.eth"], | ||
description: "Check if a domain is available.", | ||
params: { | ||
domain: { | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Handler Implementation | ||
export async function handler(context: Context) { | ||
const { | ||
message: { | ||
content: { | ||
params: { domain }, | ||
}, | ||
}, | ||
} = context; | ||
|
||
const data = await getUserInfo(domain); | ||
|
||
if (!data?.address) { | ||
let message = `Looks like ${domain} is available! Here you can register it: ${ensUrl}${domain} or would you like to see some cool alternatives?`; | ||
return { | ||
code: 200, | ||
message, | ||
}; | ||
} else { | ||
let message = `Looks like ${domain} is already registered!`; | ||
await context.executeSkill("/cool " + domain); | ||
return { | ||
code: 404, | ||
message, | ||
}; | ||
} | ||
} | ||
|
||
### Generate a payment request | ||
|
||
|
||
import { Context } from "@xmtp/message-kit"; | ||
import type { Skill } from "@xmtp/message-kit"; | ||
|
||
// Define Skill | ||
export const paymentRequest: Skill[] = [ | ||
{ | ||
skill: "pay", | ||
examples: [ | ||
"/pay 10 vitalik.eth", | ||
"/pay 1 usdc to 0xC60E6Bb79322392761BFe3081E302aEB79B30B03", | ||
], | ||
description: | ||
"Send a specified amount of a cryptocurrency to a destination address. \nWhen tipping, you can assume it's 1 USDC.", | ||
handler: handler, | ||
params: { | ||
amount: { | ||
default: 10, | ||
type: "number", | ||
}, | ||
token: { | ||
default: "usdc", | ||
type: "string", | ||
values: ["eth", "dai", "usdc", "degen"], // Accepted tokens | ||
}, | ||
username: { | ||
default: "", | ||
type: "username", | ||
}, | ||
address: { | ||
default: "", | ||
type: "address", | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Handler Implementation | ||
export async function handler(context: Context) { | ||
const { | ||
message: { | ||
content: { | ||
params: { amount, token, username, address }, | ||
}, | ||
}, | ||
} = context; | ||
let receiverAddress = address; | ||
if (username) { | ||
receiverAddress = (await getUserInfo(username))?.address; | ||
} | ||
if (address) { | ||
// Prioritize address over username | ||
receiverAddress = address; | ||
} | ||
|
||
await context.framekit.requestPayment(receiverAddress, amount, token); | ||
} | ||
|
||
|
||
# Docs | ||
|
||
# Structure | ||
|
||
## File structure | ||
|
||
Each app consists of the following files: | ||
|
||
``` | ||
agent/ | ||
├── src/ | ||
│ └── index.ts | ||
│ └── prompt.ts # Optional | ||
│ └── plugins/ # Optional | ||
│ └── ... | ||
│ └── skills/ # Optional | ||
│ └── ... | ||
│ └── vibes/ # Optional | ||
│ └── ... | ||
├── tsconfig.json | ||
├── package.json | ||
└── .env | ||
``` | ||
|
||
## Agent | ||
|
||
This is the main function that runs the listener. | ||
|
||
```jsx | ||
import { Agent, run, Context } from "@xmtp/message-kit"; | ||
|
||
const agent: Agent = { | ||
name: "Agent Name", | ||
tag: "@bot", | ||
description: "Agent Description", | ||
skills: [skill1, skill2], | ||
onMessage: async (context: Context) => { | ||
/* Logs every message in a conversation. | ||
If not declared, the agent will automatically use the defined skills. | ||
Alternatively, you can implement your own logic here. */ | ||
}, | ||
config: { | ||
// Optional parameters | ||
}, | ||
}; | ||
//starts the agent | ||
run(agent); | ||
``` | ||
|
||
#### Config parameters | ||
|
||
- `privateKey`: the private key of the agent wallet, like any normal wallet private key. | ||
- `experimental`: experimental features like logging all group messages. Default is `false`. | ||
- `attachments`: to receive attachments. Default is `false`. | ||
- `gptModel`: model to be used. Default is `gpt-4o`. | ||
- `client`: Optional parameters to pass to the XMTP client. | ||
- `agent`: Custom agent to be used. Default is to create the skills in the `src/skills.ts` file. | ||
- `hideInitLogMessage`: hide the init log message with messagekit logo and stuff | ||
- `memberChange`: if true, member changes will be enabled, like adding members to the group | ||
|
||
## Skills | ||
|
||
Skills are the actions of the agent. They are defined in the `src/skills/your-skill.ts` file. | ||
|
||
```tsx | ||
import { Skill } from "@xmtp/message-kit"; | ||
|
||
export const checkDomain: Skill[] = [ | ||
{ | ||
skill: // name of the skill | ||
handler: // function to handle the skill | ||
examples: // examples of the skill | ||
description: // description of the skill | ||
params: // params of the skill | ||
}, | ||
]; | ||
``` | ||
|
||
## Vibes | ||
|
||
Vibes are the personalities of the agent. They are defined in the `src/vibes/your-vibe.ts` file. | ||
|
||
```tsx | ||
import { Vibe } from "@xmtp/message-kit"; | ||
|
||
export const chill: Vibe = { | ||
vibe: // name of the vibe | ||
description: // description of the vibe | ||
tone: // tone of the vibe | ||
style: // style of the vibe | ||
}; | ||
``` | ||
|
||
> See [Vibes](/community/vibes) for more information. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,48 @@ | |
|
||
The `WalletService` class in MessageKit provides a way to create agent wallets that can perform gasless payments and transfers on Base. | ||
|
||
- Gasless | ||
- Onramp | ||
- Offramp | ||
- Swaps | ||
- Transfers | ||
|
||
## Wallet Management | ||
|
||
The `getWallet` method will retrieve an existing wallet or create a new one if it doesn't exist: | ||
|
||
```tsx | ||
// Get the wallet service | ||
const { walletService } = context; | ||
|
||
// Get or create a wallet | ||
const wallet = await walletService.getWallet(identifier or address); | ||
|
||
// Explicitly create a new wallet | ||
const isCreated = await walletService.createWallet(identifier or address); | ||
|
||
// Delete a wallet | ||
await walletService.deleteWallet(identifier or address); | ||
``` | ||
|
||
## Actions | ||
|
||
Perform actions on the Agent Wallet like transfers and swaps or checking the balance. | ||
|
||
```tsx | ||
// Get the wallet service | ||
const { walletService } = context; | ||
|
||
// Check balance | ||
const { address, balance } = await walletService.checkBalance(identifier or address); | ||
|
||
// Transfer between wallets | ||
await walletService.transfer(identifier or address, identifier or address, amount); | ||
|
||
// Swap assets (USDC and ETH) | ||
await walletService.swap(identifier or address, fromAssetId, toAssetId, amount); | ||
Comment on lines
+37
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling examples and return type documentation. The code examples should include error handling and document the return types for better developer experience. // Check balance
-const { address, balance } = await walletService.checkBalance(identifier or address);
+try {
+ const { address, balance } = await walletService.checkBalance(identifierOrAddress);
+ // balance is in wei (1e18)
+} catch (error) {
+ if (error instanceof WalletNotFoundError) {
+ // Handle wallet not found
+ }
+}
// Transfer between wallets
-await walletService.transfer(identifier or address, identifier or address, amount);
+try {
+ const txHash = await walletService.transfer(
+ fromAddress: string,
+ toAddress: string,
+ amount: BigNumber
+ );
+} catch (error) {
+ // Handle insufficient funds or network errors
+}
// Swap assets (USDC and ETH)
-await walletService.swap(identifier or address, fromAssetId, toAssetId, amount);
+try {
+ const txHash = await walletService.swap(
+ address: string,
+ fromAssetId: string,
+ toAssetId: string,
+ amount: BigNumber
+ );
+} catch (error) {
+ // Handle insufficient liquidity or price impact errors
+}
|
||
``` | ||
|
||
## Requirements | ||
|
||
Visit the [Circle Developer Portal](https://developer.circle.com/) to create an API key and entity secret. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve parameter documentation in code examples.
The parameter
identifier or address
is ambiguous. Consider documenting the expected format and type of each parameter.Consider adding a Properties section: