create-message-kit 1.2.24 → 1.2.26

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -7,7 +7,7 @@ import { default as fs } from "fs-extra";
7
7
  import { isCancel } from "@clack/prompts";
8
8
  import { detect } from "detect-package-manager";
9
9
  import pc from "picocolors";
10
- const defVersion = "1.2.24";
10
+ const defVersion = "1.2.26";
11
11
  const __dirname = dirname(fileURLToPath(import.meta.url));
12
12
 
13
13
  // Read package.json to get the version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-message-kit",
3
- "version": "1.2.24",
3
+ "version": "1.2.26",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,6 +1,6 @@
1
- # MessageKit Skill Template
1
+ # MessageKit
2
2
 
3
- ## Examples
3
+ # Skill Examples
4
4
 
5
5
  ### Check if a Domain is Available
6
6
 
@@ -109,70 +109,101 @@ export async function handler(context: XMTPContext) {
109
109
  receiverAddress = address;
110
110
  }
111
111
 
112
- await context.requestPayment(amount, token, receiverAddress);
112
+ await context.requestPayment(receiverAddress, amount, token);
113
113
  }
114
114
 
115
- ## Example final prompt
116
-
117
- Your are a helpful and playful ens agent called @bot that lives inside a messaging app called Converse.
118
-
119
-
120
- # Rules
121
- - You can respond with multiple messages if needed. Each message should be separated by a newline character.
122
- - You can trigger skills by only sending the command in a newline message.
123
- - Each command starts with a slash (/).
124
- - Never announce actions without using a command separated by a newline character.
125
- - Never use markdown in your responses.
126
- - Do not make guesses or assumptions
127
- - Only answer if the verified information is in the prompt.
128
- - Check that you are not missing a command
129
- - Focus only on helping users with operations detailed below.
130
- - Date: Fri, 06 Dec 2024 16:03:22 GMT
131
- - When mentioning any action related to available skills, you MUST trigger the corresponding command in a new line
132
- - If you suggest an action that has a command, you must trigger that command
133
-
134
-
135
- ## User context
136
- - Start by fetch their domain from or Converse username
137
- - Call the user by their name or domain, in case they have one
138
- - Ask for a name (if they don't have one) so you can suggest domains.
139
- - Message sent date: 2024-12-06T16:03:36.582Z
140
- - Users address is: 0x40f08f0f853d1c42c61815652b7ccd5a50f0be09
141
- - Users name is: ArizonaOregon
142
- - Converse username is: ArizonaOregon
143
-
144
- ## Commands
145
- /check [domain] - Check if a domain is available.
146
- /cool [domain] - Get cool alternatives for a .eth domain.
147
- /info [domain] - Get detailed information about an ENS domain including owner, expiry date, and resolver.
148
- /register [domain] - Register a new ENS domain. Returns a URL to complete the registration process.
149
- /renew [domain] - Extend the registration period of your ENS domain. Returns a URL to complete the renewal.
150
- /reset - Reset the conversation clearing memory and usernames cache.
151
- /pay [amount] [token] [username] [address] - Send a specified amount of a cryptocurrency to a destination address.
152
- When tipping, you can asume its 1 usdc.
153
-
154
- ## Examples
155
- /check vitalik.eth
156
- /check fabri.base.eth
157
- /cool vitalik.eth
158
- /info nick.eth
159
- /register vitalik.eth
160
- /renew fabri.base.eth
161
- /reset
162
- /pay 10 vitalik.eth
163
- /pay 1 usdc to 0xC60E6Bb79322392761BFe3081E302aEB79B30B03
164
-
165
- ## Scenarios
166
- 1. Missing commands in responses
167
- **Issue**: Sometimes responses are sent without the required command.
168
- **Example**:
169
- Incorrect:
170
- > "Looks like vitalik.eth is registered! What about these cool alternatives?"
171
- Correct:
172
- > "Looks like vitalik.eth is registered! What about these cool alternatives?
173
- > /cool vitalik.eth"
174
-
175
- Incorrect:
176
- > Here is a summary of your TODOs. I will now send it via email.
177
- Correct:
178
- > /todo
115
+
116
+ # Docs
117
+
118
+ # Structure
119
+
120
+ ## File structure
121
+
122
+ Each app consists of the following files:
123
+
124
+ ```
125
+ agent/
126
+ ├── src/
127
+ │ └── index.ts
128
+ │ └── prompt.ts
129
+ │ └── plugins/
130
+ │ └── ...
131
+ │ └── skills/
132
+ │ └── ...
133
+ │ └── vibes/
134
+ │ └── ...
135
+ ├── tsconfig.json
136
+ ├── package.json
137
+ └── .env
138
+ ```
139
+
140
+ ## Agent
141
+
142
+ This is the main function that runs the listener.
143
+
144
+ ```jsx
145
+ import { Agent, run, XMTPContext } from "@xmtp/message-kit";
146
+
147
+ const agent: Agent = {
148
+ name: "Agent Name",
149
+ tag: "@bot",
150
+ description: "Agent Description",
151
+ skills: [skill1, skill2],
152
+ onMessage: async (context: XMTPContext) => {
153
+ /* Logs every message in a conversation.
154
+ If not declared, the agent will automatically use the defined skills.
155
+ Alternatively, you can implement your own logic here. */
156
+ },
157
+ config: {
158
+ // Optional parameters
159
+ },
160
+ };
161
+ //starts the agent
162
+ run(agent);
163
+ ```
164
+
165
+ #### Config parameters
166
+
167
+ - `privateKey`: the private key of the agent wallet, like any normal wallet private key.
168
+ - `experimental`: experimental features like logging all group messages. Default is `false`.
169
+ - `attachments`: to receive attachments. Default is `false`.
170
+ - `gptModel`: model to be used. Default is `gpt-4o`.
171
+ - `client`: Optional parameters to pass to the XMTP client.
172
+ - `agent`: Custom agent to be used. Default is to create the skills in the `src/skills.ts` file.
173
+ - `hideInitLogMessage`: hide the init log message with messagekit logo and stuff
174
+ - `memberChange`: if true, member changes will be enabled, like adding members to the group
175
+
176
+ ## Skills
177
+
178
+ Skills are the actions of the agent. They are defined in the `src/skills/your-skill.ts` file.
179
+
180
+ ```tsx
181
+ import { Skill } from "@xmtp/message-kit";
182
+
183
+ export const checkDomain: Skill[] = [
184
+ {
185
+ skill: // name of the skill
186
+ handler: // function to handle the skill
187
+ examples: // examples of the skill
188
+ description: // description of the skill
189
+ params: // params of the skill
190
+ },
191
+ ];
192
+ ```
193
+
194
+ ## Vibes
195
+
196
+ Vibes are the personalities of the agent. They are defined in the `src/vibes/your-vibe.ts` file.
197
+
198
+ ```tsx
199
+ import { Vibe } from "@xmtp/message-kit";
200
+
201
+ export const chill: Vibe = {
202
+ vibe: // name of the vibe
203
+ description: // description of the vibe
204
+ tone: // tone of the vibe
205
+ style: // style of the vibe
206
+ };
207
+ ```
208
+
209
+ > See [Vibes](/community/vibes) for more information.
@@ -6,13 +6,12 @@ import { info } from "./skills/info.js";
6
6
  import { register } from "./skills/register.js";
7
7
  import { renew } from "./skills/renew.js";
8
8
  import { pay } from "./skills/pay.js";
9
- import { reset } from "./skills/reset.js";
10
9
 
11
10
  export const agent: Agent = {
12
11
  name: "Ens Agent",
13
12
  tag: "@bot",
14
13
  description: "A ens agent with a lot of skills.",
15
- skills: [checkDomain, cool, info, register, renew, reset, pay],
14
+ skills: [checkDomain, cool, info, register, renew, pay],
16
15
  systemPrompt: systemPrompt,
17
16
  };
18
17
 
@@ -2,13 +2,20 @@ import { XMTPContext } from "@xmtp/message-kit";
2
2
 
3
3
  import type { Skill } from "@xmtp/message-kit";
4
4
 
5
+ // [!region define]
5
6
  export const info: Skill[] = [
6
7
  {
7
8
  skill: "info",
8
9
  handler: handler,
9
10
  description:
10
11
  "Get detailed information about an ENS domain including owner, expiry date, and resolver.",
11
- examples: ["/info nick.eth"],
12
+ examples: [
13
+ "/info humanagent.eth",
14
+ "/info fabri.base.eth",
15
+ "/info @fabri",
16
+ "/info fabri.converse.xyz",
17
+ "/info vitalik.eth",
18
+ ],
12
19
  params: {
13
20
  domain: {
14
21
  type: "string",
@@ -16,7 +23,9 @@ export const info: Skill[] = [
16
23
  },
17
24
  },
18
25
  ];
26
+ // [!endregion define]
19
27
 
28
+ // [!region handle]
20
29
  export async function handler(context: XMTPContext) {
21
30
  const {
22
31
  message: {
@@ -28,15 +37,17 @@ export async function handler(context: XMTPContext) {
28
37
  } = context;
29
38
 
30
39
  const data = await context.getUserInfo(domain);
31
- if (!data?.ensDomain) {
40
+ if (!data?.address) {
32
41
  return {
33
42
  code: 404,
34
43
  message: "Domain not found.",
35
44
  };
36
45
  }
37
- console.log(data);
38
- let message = `Domain information:\n\n`;
39
- message += `URL: https://app.ens.domains/${data?.ensDomain}\n`;
46
+ let message = `Information:\n\n`;
47
+ if (data?.ensDomain)
48
+ message += `URL: https://app.ens.domains/${data?.ensDomain}\n`;
49
+ if (data?.converseUsername)
50
+ message += `Converse: https://converse.xyz/dm/${data?.converseUsername}\n`;
40
51
  if (data?.address) message += `Address: ${data?.address}\n`;
41
52
  if (data?.ensInfo?.avatar) message += `Avatar: ${data?.ensInfo?.avatar}\n`;
42
53
  if (data?.ensInfo?.description)
@@ -47,18 +58,6 @@ export async function handler(context: XMTPContext) {
47
58
  if (data?.ensInfo?.twitter) message += `Twitter: ${data?.ensInfo?.twitter}\n`;
48
59
  message += `\n\nWould you like to tip the domain owner for getting there first 🤣?`;
49
60
  message = message.trim();
50
-
51
- const { v2, v3 } = await context.isOnXMTP(
52
- context.client,
53
- context.v2client,
54
- sender?.address,
55
- );
56
- if (v2 || v3) {
57
- await context.send(
58
- `Ah, this domains is in XMTP, you can message it directly`,
59
- );
60
- await context.sendConverseDmFrame(domain);
61
- }
62
-
63
61
  return { code: 200, message };
64
62
  }
63
+ // [!endregion handle]
@@ -31,11 +31,24 @@ export const pay: Skill[] = [
31
31
  },
32
32
  },
33
33
  },
34
+ {
35
+ skill: "tip",
36
+ examples: ["/tip vitalik.eth"],
37
+ description: "Send 1 usdc.",
38
+ handler: handler,
39
+ params: {
40
+ username: {
41
+ default: "",
42
+ type: "username",
43
+ },
44
+ },
45
+ },
34
46
  ];
35
47
  export async function handler(context: XMTPContext) {
36
48
  const {
37
49
  message: {
38
50
  content: {
51
+ skill,
39
52
  params: { amount, token, username, address },
40
53
  },
41
54
  },
@@ -48,6 +61,12 @@ export async function handler(context: XMTPContext) {
48
61
  //Prioritize address over username
49
62
  receiverAddress = address;
50
63
  }
51
-
52
- await context.requestPayment(amount, token, receiverAddress);
64
+ if (skill === "tip") {
65
+ let tipAmount = 1;
66
+ await context.send("Sure, here is the tip link: ");
67
+ await context.requestPayment(receiverAddress, tipAmount);
68
+ } else if (skill === "pay") {
69
+ await context.send("Sure, here is the payment link: ");
70
+ await context.requestPayment(receiverAddress, amount, token);
71
+ }
53
72
  }
@@ -1,6 +1,6 @@
1
- # MessageKit Skill Template
1
+ # MessageKit
2
2
 
3
- ## Examples
3
+ # Skill Examples
4
4
 
5
5
  ### Check if a Domain is Available
6
6
 
@@ -109,70 +109,101 @@ export async function handler(context: XMTPContext) {
109
109
  receiverAddress = address;
110
110
  }
111
111
 
112
- await context.requestPayment(amount, token, receiverAddress);
112
+ await context.requestPayment(receiverAddress, amount, token);
113
113
  }
114
114
 
115
- ## Example final prompt
116
-
117
- Your are a helpful and playful ens agent called @bot that lives inside a messaging app called Converse.
118
-
119
-
120
- # Rules
121
- - You can respond with multiple messages if needed. Each message should be separated by a newline character.
122
- - You can trigger skills by only sending the command in a newline message.
123
- - Each command starts with a slash (/).
124
- - Never announce actions without using a command separated by a newline character.
125
- - Never use markdown in your responses.
126
- - Do not make guesses or assumptions
127
- - Only answer if the verified information is in the prompt.
128
- - Check that you are not missing a command
129
- - Focus only on helping users with operations detailed below.
130
- - Date: Fri, 06 Dec 2024 16:03:22 GMT
131
- - When mentioning any action related to available skills, you MUST trigger the corresponding command in a new line
132
- - If you suggest an action that has a command, you must trigger that command
133
-
134
-
135
- ## User context
136
- - Start by fetch their domain from or Converse username
137
- - Call the user by their name or domain, in case they have one
138
- - Ask for a name (if they don't have one) so you can suggest domains.
139
- - Message sent date: 2024-12-06T16:03:36.582Z
140
- - Users address is: 0x40f08f0f853d1c42c61815652b7ccd5a50f0be09
141
- - Users name is: ArizonaOregon
142
- - Converse username is: ArizonaOregon
143
-
144
- ## Commands
145
- /check [domain] - Check if a domain is available.
146
- /cool [domain] - Get cool alternatives for a .eth domain.
147
- /info [domain] - Get detailed information about an ENS domain including owner, expiry date, and resolver.
148
- /register [domain] - Register a new ENS domain. Returns a URL to complete the registration process.
149
- /renew [domain] - Extend the registration period of your ENS domain. Returns a URL to complete the renewal.
150
- /reset - Reset the conversation clearing memory and usernames cache.
151
- /pay [amount] [token] [username] [address] - Send a specified amount of a cryptocurrency to a destination address.
152
- When tipping, you can asume its 1 usdc.
153
-
154
- ## Examples
155
- /check vitalik.eth
156
- /check fabri.base.eth
157
- /cool vitalik.eth
158
- /info nick.eth
159
- /register vitalik.eth
160
- /renew fabri.base.eth
161
- /reset
162
- /pay 10 vitalik.eth
163
- /pay 1 usdc to 0xC60E6Bb79322392761BFe3081E302aEB79B30B03
164
-
165
- ## Scenarios
166
- 1. Missing commands in responses
167
- **Issue**: Sometimes responses are sent without the required command.
168
- **Example**:
169
- Incorrect:
170
- > "Looks like vitalik.eth is registered! What about these cool alternatives?"
171
- Correct:
172
- > "Looks like vitalik.eth is registered! What about these cool alternatives?
173
- > /cool vitalik.eth"
174
-
175
- Incorrect:
176
- > Here is a summary of your TODOs. I will now send it via email.
177
- Correct:
178
- > /todo
115
+
116
+ # Docs
117
+
118
+ # Structure
119
+
120
+ ## File structure
121
+
122
+ Each app consists of the following files:
123
+
124
+ ```
125
+ agent/
126
+ ├── src/
127
+ │ └── index.ts
128
+ │ └── prompt.ts
129
+ │ └── plugins/
130
+ │ └── ...
131
+ │ └── skills/
132
+ │ └── ...
133
+ │ └── vibes/
134
+ │ └── ...
135
+ ├── tsconfig.json
136
+ ├── package.json
137
+ └── .env
138
+ ```
139
+
140
+ ## Agent
141
+
142
+ This is the main function that runs the listener.
143
+
144
+ ```jsx
145
+ import { Agent, run, XMTPContext } from "@xmtp/message-kit";
146
+
147
+ const agent: Agent = {
148
+ name: "Agent Name",
149
+ tag: "@bot",
150
+ description: "Agent Description",
151
+ skills: [skill1, skill2],
152
+ onMessage: async (context: XMTPContext) => {
153
+ /* Logs every message in a conversation.
154
+ If not declared, the agent will automatically use the defined skills.
155
+ Alternatively, you can implement your own logic here. */
156
+ },
157
+ config: {
158
+ // Optional parameters
159
+ },
160
+ };
161
+ //starts the agent
162
+ run(agent);
163
+ ```
164
+
165
+ #### Config parameters
166
+
167
+ - `privateKey`: the private key of the agent wallet, like any normal wallet private key.
168
+ - `experimental`: experimental features like logging all group messages. Default is `false`.
169
+ - `attachments`: to receive attachments. Default is `false`.
170
+ - `gptModel`: model to be used. Default is `gpt-4o`.
171
+ - `client`: Optional parameters to pass to the XMTP client.
172
+ - `agent`: Custom agent to be used. Default is to create the skills in the `src/skills.ts` file.
173
+ - `hideInitLogMessage`: hide the init log message with messagekit logo and stuff
174
+ - `memberChange`: if true, member changes will be enabled, like adding members to the group
175
+
176
+ ## Skills
177
+
178
+ Skills are the actions of the agent. They are defined in the `src/skills/your-skill.ts` file.
179
+
180
+ ```tsx
181
+ import { Skill } from "@xmtp/message-kit";
182
+
183
+ export const checkDomain: Skill[] = [
184
+ {
185
+ skill: // name of the skill
186
+ handler: // function to handle the skill
187
+ examples: // examples of the skill
188
+ description: // description of the skill
189
+ params: // params of the skill
190
+ },
191
+ ];
192
+ ```
193
+
194
+ ## Vibes
195
+
196
+ Vibes are the personalities of the agent. They are defined in the `src/vibes/your-vibe.ts` file.
197
+
198
+ ```tsx
199
+ import { Vibe } from "@xmtp/message-kit";
200
+
201
+ export const chill: Vibe = {
202
+ vibe: // name of the vibe
203
+ description: // description of the vibe
204
+ tone: // tone of the vibe
205
+ style: // style of the vibe
206
+ };
207
+ ```
208
+
209
+ > See [Vibes](/community/vibes) for more information.
@@ -1,7 +1,8 @@
1
+ // [!region index]
1
2
  import {
2
3
  run,
3
4
  agentReply,
4
- replaceVariables,
5
+ parsePrompt,
5
6
  XMTPContext,
6
7
  Agent,
7
8
  } from "@xmtp/message-kit";
@@ -11,16 +12,22 @@ export const agent: Agent = {
11
12
  name: "GPT Bot",
12
13
  tag: "@bot",
13
14
  description: "Use GPT to generate text responses.",
14
- skills: [],
15
15
  onMessage: async (context: XMTPContext) => {
16
16
  const {
17
- message: { sender },
17
+ message: {
18
+ sender,
19
+ content: { text },
20
+ },
18
21
  agent,
19
22
  } = context;
23
+ // [!endregion index]
20
24
 
21
- let prompt = await replaceVariables(systemPrompt, sender.address, agent);
25
+ let prompt = await parsePrompt(systemPrompt, sender.address, agent);
22
26
  await agentReply(context, prompt);
27
+
28
+ // [!region final]
23
29
  },
24
30
  };
25
31
 
26
32
  run(agent);
33
+ // [!endregion final]
@@ -1,25 +0,0 @@
1
- import { clearInfoCache, clearMemory } from "@xmtp/message-kit";
2
- import { XMTPContext } from "@xmtp/message-kit";
3
-
4
- import type { Skill } from "@xmtp/message-kit";
5
-
6
- export const reset: Skill[] = [
7
- {
8
- skill: "reset",
9
- examples: ["/reset"],
10
- handler: handler,
11
- description: "Reset the conversation clearing memory and usernames cache.",
12
- },
13
- ];
14
- export async function handler(context: XMTPContext) {
15
- const {
16
- message: { sender },
17
- } = context;
18
- try {
19
- clearMemory(sender.address);
20
- clearInfoCache(sender.address);
21
- return { code: 200, message: "Memory and usernames cache cleared." };
22
- } catch (error) {
23
- return { code: 500, message: "Error clearing memory and usernames cache." };
24
- }
25
- }
@@ -1 +0,0 @@
1
-