create-message-kit 1.1.7-beta.16 → 1.1.7-beta.19

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-message-kit",
3
- "version": "1.1.7-beta.16",
3
+ "version": "1.1.7-beta.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -13,15 +13,15 @@ export async function handleEns(
13
13
  const {
14
14
  message: {
15
15
  sender,
16
- content: { command, params },
16
+ content: { skill, params },
17
17
  },
18
18
  } = context;
19
- console.log(command, params);
20
- if (command == "reset") {
19
+
20
+ if (skill == "reset") {
21
21
  clearMemory();
22
22
  return { code: 200, message: "Conversation reset." };
23
- } else if (command == "renew") {
24
- // Destructure and validate parameters for the ens command
23
+ } else if (skill == "renew") {
24
+ // Destructure and validate parameters for the ens
25
25
  const { domain } = params;
26
26
  // Check if the user holds the domain
27
27
  if (!domain) {
@@ -44,8 +44,8 @@ export async function handleEns(
44
44
  // Generate URL for the ens
45
45
  let url_ens = frameUrl + "frames/manage?name=" + domain;
46
46
  return { code: 200, message: `${url_ens}` };
47
- } else if (command == "register") {
48
- // Destructure and validate parameters for the ens command
47
+ } else if (skill == "register") {
48
+ // Destructure and validate parameters for the ens
49
49
  const { domain } = params;
50
50
 
51
51
  if (!domain) {
@@ -57,7 +57,7 @@ export async function handleEns(
57
57
  // Generate URL for the ens
58
58
  let url_ens = ensUrl + domain;
59
59
  return { code: 200, message: `${url_ens}` };
60
- } else if (command == "info") {
60
+ } else if (skill == "info") {
61
61
  const { domain } = params;
62
62
 
63
63
  const data = await getUserInfo(domain);
@@ -94,7 +94,7 @@ export async function handleEns(
94
94
  );
95
95
  }
96
96
  return { code: 200, message };
97
- } else if (command == "check") {
97
+ } else if (skill == "check") {
98
98
  const { domain } = params;
99
99
 
100
100
  if (!domain) {
@@ -119,7 +119,7 @@ export async function handleEns(
119
119
  message,
120
120
  };
121
121
  }
122
- } else if (command == "tip") {
122
+ } else if (skill == "tip") {
123
123
  const { address } = params;
124
124
  if (!address) {
125
125
  return {
@@ -136,7 +136,7 @@ export async function handleEns(
136
136
  code: 200,
137
137
  message: txUrl,
138
138
  };
139
- } else if (command == "cool") {
139
+ } else if (skill == "cool") {
140
140
  const { domain } = params;
141
141
  //What about these cool alternatives?\
142
142
  return {
@@ -144,7 +144,7 @@ export async function handleEns(
144
144
  message: `${generateCoolAlternatives(domain)}`,
145
145
  };
146
146
  } else {
147
- return { code: 400, message: "Command not found." };
147
+ return { code: 400, message: "Skill not found." };
148
148
  }
149
149
  }
150
150
 
@@ -13,7 +13,7 @@ export async function agent_prompt(userInfo: UserInfo) {
13
13
  PROMPT_USER_CONTENT(userInfo) +
14
14
  PROMPT_SKILLS_AND_EXAMPLES(skills, "@ens");
15
15
 
16
- systemPrompt += `
16
+ let fineTunning = `
17
17
 
18
18
  ## Example responses:
19
19
 
@@ -53,12 +53,16 @@ export async function agent_prompt(userInfo: UserInfo) {
53
53
  But you forgot to add the command at the end of the message.
54
54
  You should have said something like: "Looks like vitalik.eth is registered! What about these cool alternatives?\n/cool vitalik.eth
55
55
  `;
56
+
57
+ // Add the fine tuning to the system prompt
58
+ systemPrompt += fineTunning;
59
+
60
+ // Replace the variables in the system prompt
56
61
  systemPrompt = PROMPT_REPLACE_VARIABLES(
57
62
  systemPrompt,
58
63
  userInfo?.address ?? "",
59
64
  userInfo,
60
65
  "@ens",
61
66
  );
62
- console.log(systemPrompt);
63
67
  return systemPrompt;
64
68
  }
@@ -8,7 +8,7 @@ export const skills: SkillGroup[] = [
8
8
  description: "Register ENS domains.",
9
9
  skills: [
10
10
  {
11
- command: "/register [domain]",
11
+ skill: "/register [domain]",
12
12
  triggers: ["/register"],
13
13
  handler: handleEns,
14
14
  description:
@@ -21,7 +21,7 @@ export const skills: SkillGroup[] = [
21
21
  },
22
22
  },
23
23
  {
24
- command: "/exists",
24
+ skill: "/exists",
25
25
  examples: ["/exists"],
26
26
  handler: handleEns,
27
27
  triggers: ["/exists"],
@@ -33,7 +33,7 @@ export const skills: SkillGroup[] = [
33
33
  },
34
34
  },
35
35
  {
36
- command: "/info [domain]",
36
+ skill: "/info [domain]",
37
37
  triggers: ["/info"],
38
38
  handler: handleEns,
39
39
  description:
@@ -46,7 +46,7 @@ export const skills: SkillGroup[] = [
46
46
  },
47
47
  },
48
48
  {
49
- command: "/renew [domain]",
49
+ skill: "/renew [domain]",
50
50
  triggers: ["/renew"],
51
51
  handler: handleEns,
52
52
  description:
@@ -59,7 +59,7 @@ export const skills: SkillGroup[] = [
59
59
  },
60
60
  },
61
61
  {
62
- command: "/check [domain]",
62
+ skill: "/check [domain]",
63
63
  triggers: ["/check"],
64
64
  handler: handleEns,
65
65
  examples: ["/check vitalik.eth", "/check fabri.base.eth"],
@@ -71,7 +71,7 @@ export const skills: SkillGroup[] = [
71
71
  },
72
72
  },
73
73
  {
74
- command: "/cool [domain]",
74
+ skill: "/cool [domain]",
75
75
  triggers: ["/cool"],
76
76
  examples: ["/cool vitalik.eth"],
77
77
  handler: handleEns,
@@ -83,7 +83,7 @@ export const skills: SkillGroup[] = [
83
83
  },
84
84
  },
85
85
  {
86
- command: "/reset",
86
+ skill: "/reset",
87
87
  triggers: ["/reset"],
88
88
  examples: ["/reset"],
89
89
  handler: handleEns,
@@ -91,7 +91,7 @@ export const skills: SkillGroup[] = [
91
91
  params: {},
92
92
  },
93
93
  {
94
- command: "/tip [address]",
94
+ skill: "/tip [address]",
95
95
  description: "Show a URL for tipping a domain owner.",
96
96
  triggers: ["/tip"],
97
97
  handler: handleEns,
@@ -1,9 +1,14 @@
1
1
  import { run, HandlerContext } from "@xmtp/message-kit";
2
+ import { skills } from "./skills.js";
3
+ run(
4
+ async (context: HandlerContext) => {
5
+ // Get the message and the address from the sender
6
+ const { content, sender } = context.message;
2
7
 
3
- run(async (context: HandlerContext) => {
4
- // Get the message and the address from the sender
5
- const { content, sender } = context.message;
6
-
7
- // To reply, just call `reply` on the HandlerContext
8
- await context.send(`gm`);
9
- });
8
+ // To reply, just call `reply` on the HandlerContext
9
+ await context.send(`gm`);
10
+ },
11
+ {
12
+ skills: skills,
13
+ },
14
+ );
@@ -0,0 +1,29 @@
1
+ import type { SkillGroup } from "@xmtp/message-kit";
2
+
3
+ export const skills: SkillGroup[] = [
4
+ {
5
+ name: "Group bot",
6
+ tag: "@bot",
7
+ description: "Group bot for tipping and transactions.",
8
+ skills: [
9
+ {
10
+ skill: "/tip [usernames] [amount] [token]",
11
+ triggers: ["/tip"],
12
+ examples: ["/tip @vitalik 10 usdc"],
13
+ description: "Tip users in a specified token.",
14
+ handler: undefined,
15
+ params: {
16
+ username: {
17
+ default: "",
18
+ plural: true,
19
+ type: "username",
20
+ },
21
+ amount: {
22
+ default: 10,
23
+ type: "number",
24
+ },
25
+ },
26
+ },
27
+ ],
28
+ },
29
+ ];
@@ -1,68 +1,31 @@
1
- import { HandlerContext, AbstractedMember } from "@xmtp/message-kit";
2
- import { textGeneration } from "@xmtp/message-kit";
1
+ import { run, HandlerContext } from "@xmtp/message-kit";
2
+ import { textGeneration, processMultilineResponse } from "@xmtp/message-kit";
3
+ import { agent_prompt } from "../prompt.js";
4
+ import { getUserInfo } from "@xmtp/message-kit";
3
5
 
4
- export async function handler(context: HandlerContext) {
6
+ run(async (context: HandlerContext) => {
5
7
  const {
6
8
  message: {
9
+ content: { text, params },
7
10
  sender,
8
- content: { params, text },
9
11
  },
10
12
  } = context;
11
13
 
12
- const systemPrompt = generateSystemPrompt(context);
13
14
  try {
14
15
  let userPrompt = params?.prompt ?? text;
15
-
16
+ const userInfo = await getUserInfo(sender.address);
17
+ if (!userInfo) {
18
+ console.log("User info not found");
19
+ return;
20
+ }
16
21
  const { reply } = await textGeneration(
17
22
  sender.address,
18
23
  userPrompt,
19
- systemPrompt,
24
+ await agent_prompt(userInfo),
20
25
  );
21
-
22
- try {
23
- await context.executeSkill(reply);
24
- } catch (error) {
25
- console.error("Error executing skill:", error);
26
- await context.reply("Failed to execute the requested action.");
27
- }
26
+ await processMultilineResponse(sender.address, reply, context);
28
27
  } catch (error) {
29
28
  console.error("Error during OpenAI call:", error);
30
- await context.reply("An error occurred while processing your request.");
29
+ await context.send("An error occurred while processing your request.");
31
30
  }
32
- }
33
-
34
- function generateSystemPrompt(context: HandlerContext) {
35
- const {
36
- members,
37
- skills,
38
- message: { sender },
39
- } = context;
40
-
41
- const systemPrompt = `
42
- ### Context
43
-
44
- You are a helpful bot agent that lives inside a web3 messaging group that helps interpret user requests and execute commands.
45
- #### Users
46
- ${JSON.stringify(
47
- members?.map((member: AbstractedMember) => ({
48
- ...member,
49
- username: `@${member.accountAddresses[0]}`,
50
- })),
51
- )}\n
52
- #### Commands
53
- ${JSON.stringify(skills)}\n
54
- The message was sent by @${sender?.address}
55
-
56
- ### Examples
57
- prompt /agent tip alix and bo
58
- reply /tip @alix @bo 10
59
-
60
- Important:
61
- - If a user asks jokes, make jokes about web3 devs\n
62
- - If the user asks about performing an action and you can think of a command that would help, answer directly with the command and nothing else.
63
- - Populate the command with the correct or random values. Always return skills with real values only, using usernames with @ and excluding addresses.\n
64
- - If the user asks a question or makes a statement that does not clearly map to a command, respond with helpful information or a clarification question.\n
65
- - If the user is grateful, respond asking for a tip in a playful manner.
66
- `;
67
- return systemPrompt;
68
- }
31
+ });
@@ -1,13 +1,13 @@
1
1
  import { HandlerContext } from "@xmtp/message-kit";
2
2
 
3
- // Handler function to process game-related commands
3
+ // Handler function to process game-related
4
4
  export async function handler(context: HandlerContext) {
5
5
  const {
6
6
  message: {
7
- content: { command, params, text },
7
+ content: { skill, params, text },
8
8
  },
9
9
  } = context;
10
- if (!command) {
10
+ if (!skill) {
11
11
  if (text === "🔎" || text === "🔍") {
12
12
  // Send the URL for the requested game
13
13
  context.reply("https://framedl.xyz/");
@@ -35,7 +35,7 @@ export async function handler(context: HandlerContext) {
35
35
  default:
36
36
  // Inform the user about unrecognized skills and provide available options
37
37
  context.send(
38
- "Command not recognized. Available games: wordle, slot, or help.",
38
+ "Skill not recognized. Available games: wordle, slot, or help.",
39
39
  );
40
40
  }
41
41
  }
@@ -4,22 +4,25 @@ export async function handler(context: HandlerContext) {
4
4
  const {
5
5
  skills,
6
6
  message: {
7
- content: { command },
7
+ content: { skill },
8
8
  },
9
9
  group,
10
10
  } = context;
11
11
 
12
- if (command == "help") {
12
+ if (skill == "help") {
13
13
  const intro =
14
14
  "Available experiences:\n" +
15
15
  skills
16
16
  ?.flatMap((app) => app.skills)
17
- .map((skill) => `${skill.command} - ${skill.description}`)
17
+ .map((skill) => `${skill.skill} - ${skill.description}`)
18
18
  .join("\n") +
19
19
  "\nUse these skills to interact with specific apps.";
20
20
  context.send(intro);
21
- } else if (command == "id") {
22
- console.log(group?.id);
21
+ } else if (skill == "id") {
22
+ if (!group?.id) {
23
+ context.send("This skill only works in group chats.");
24
+ return;
25
+ }
23
26
  context.send(group?.id);
24
27
  }
25
28
  }
@@ -8,33 +8,20 @@ import { getUserInfo } from "@xmtp/message-kit";
8
8
  export async function handler(context: HandlerContext): Promise<SkillResponse> {
9
9
  const {
10
10
  members,
11
- getMessageById,
12
11
  message: {
13
- content: { reference, reply, text, params },
12
+ content: {
13
+ reference,
14
+ reply,
15
+ text,
16
+ skill,
17
+ params: { amount, username },
18
+ },
14
19
  sender,
15
- typeId,
16
20
  },
17
21
  } = context;
18
- const msg = reference ? await getMessageById(reference) : undefined;
19
- const replyReceiver = members?.find(
20
- (member) => member.inboxId === msg?.senderInboxId,
21
- );
22
- let amount: number = 0,
23
- receivers: AbstractedMember[] = [];
24
- // Handle different types of messages
25
- if (typeId === "reply" && replyReceiver) {
26
- if (reply?.includes("degen")) {
27
- receivers = [replyReceiver];
28
- const match = reply.match(/(\d+)/);
29
- if (match)
30
- amount = parseInt(match[0]); // Extract amount from reply
31
- else amount = 10;
32
- }
33
- } else if (typeId === "text" && text?.startsWith("/tip") && params) {
34
- // Process text skills starting with "/tip"
35
- const { amount: extractedAmount, username } = params;
36
- amount = extractedAmount || 10; // Default amount if not specified
22
+ let receivers: AbstractedMember[] = [];
37
23
 
24
+ if (skill === "tip") {
38
25
  receivers = await Promise.all(
39
26
  username.map((username: string) => getUserInfo(username)),
40
27
  );
@@ -47,7 +34,6 @@ export async function handler(context: HandlerContext): Promise<SkillResponse> {
47
34
  };
48
35
  }
49
36
  const receiverAddresses = receivers.map((receiver) => receiver.address);
50
- // Process sending tokens to each receiver
51
37
 
52
38
  context.sendTo(
53
39
  `You received ${amount} tokens from ${sender.address}.`,
@@ -1,17 +1,17 @@
1
1
  import { getUserInfo, HandlerContext, SkillResponse } from "@xmtp/message-kit";
2
2
 
3
- // Main handler function for processing commands
3
+ // Main handler function for processing
4
4
  export async function handler(context: HandlerContext): Promise<SkillResponse> {
5
5
  const {
6
6
  message: {
7
- content: { command, params },
7
+ content: { skill, params },
8
8
  },
9
9
  } = context;
10
10
  const baseUrl = "https://base-tx-frame.vercel.app/transaction";
11
11
 
12
- switch (command) {
12
+ switch (skill) {
13
13
  case "send":
14
- // Destructure and validate parameters for the send command
14
+ // Destructure and validate parameters for the send
15
15
  const { amount: amountSend, token: tokenSend, username } = params; // [!code hl] // [!code focus]
16
16
  let senderInfo = await getUserInfo(username);
17
17
  if (!amountSend || !tokenSend || !senderInfo) {
@@ -32,7 +32,7 @@ export async function handler(context: HandlerContext): Promise<SkillResponse> {
32
32
  message: `${sendUrl}`,
33
33
  };
34
34
  case "swap":
35
- // Destructure and validate parameters for the swap command
35
+ // Destructure and validate parameters for the swap
36
36
  const { amount, token_from, token_to } = params; // [!code hl] // [!code focus]
37
37
 
38
38
  if (!amount || !token_from || !token_to) {
@@ -60,11 +60,10 @@ export async function handler(context: HandlerContext): Promise<SkillResponse> {
60
60
  message: `${baseUrl.replace("/transaction", "")}`,
61
61
  };
62
62
  default:
63
- // Handle unknown commands
64
- context.reply("Unknown command. Use help to see all available commands.");
63
+ context.reply("Unknown skill. Use help to see all available skills.");
65
64
  return {
66
65
  code: 400,
67
- message: "Unknown command. Use help to see all available commands.",
66
+ message: "Unknown skill. Use help to see all available skills.",
68
67
  };
69
68
  }
70
69
  }
@@ -1,12 +1,32 @@
1
1
  import { run, HandlerContext } from "@xmtp/message-kit";
2
+ import { textGeneration, processMultilineResponse } from "@xmtp/message-kit";
3
+ import { agent_prompt } from "./prompt.js";
4
+ import { getUserInfo } from "@xmtp/message-kit";
2
5
 
3
- // Main function to run the app
4
6
  run(async (context: HandlerContext) => {
5
- const { group } = context;
7
+ const {
8
+ message: {
9
+ content: { text, params },
10
+ sender,
11
+ },
12
+ group,
13
+ } = context;
6
14
 
7
- if (!group) {
8
- context.send(
9
- "This bot only works in group chats. Please add this bot to a group to continue",
15
+ try {
16
+ let userPrompt = params?.prompt ?? text;
17
+ const userInfo = await getUserInfo(sender.address);
18
+ if (!userInfo) {
19
+ console.log("User info not found");
20
+ return;
21
+ }
22
+ const { reply } = await textGeneration(
23
+ sender.address,
24
+ userPrompt,
25
+ await agent_prompt(userInfo),
10
26
  );
27
+ await processMultilineResponse(sender.address, reply, context);
28
+ } catch (error) {
29
+ console.error("Error during OpenAI call:", error);
30
+ await context.send("An error occurred while processing your request.");
11
31
  }
12
32
  });
@@ -0,0 +1,25 @@
1
+ import { skills } from "./skills.js";
2
+ import {
3
+ UserInfo,
4
+ PROMPT_USER_CONTENT,
5
+ PROMPT_RULES,
6
+ PROMPT_SKILLS_AND_EXAMPLES,
7
+ PROMPT_REPLACE_VARIABLES,
8
+ } from "@xmtp/message-kit";
9
+
10
+ export async function agent_prompt(userInfo: UserInfo) {
11
+ let systemPrompt =
12
+ PROMPT_RULES +
13
+ PROMPT_USER_CONTENT(userInfo) +
14
+ PROMPT_SKILLS_AND_EXAMPLES(skills, "@bot");
15
+
16
+ // Replace the variables in the system prompt
17
+ systemPrompt = PROMPT_REPLACE_VARIABLES(
18
+ systemPrompt,
19
+ userInfo?.address ?? "",
20
+ userInfo,
21
+ "@bot",
22
+ );
23
+ console.log(systemPrompt);
24
+ return systemPrompt;
25
+ }
@@ -1,18 +1,17 @@
1
1
  import { handler as tipping } from "./handler/tipping.js";
2
- import { handler as agent } from "./handler/agent.js";
3
2
  import { handler as transaction } from "./handler/transaction.js";
4
3
  import { handler as games } from "./handler/game.js";
5
- import { handler as groupHelp } from "./handler/helpers.js";
4
+ import { handler as help } from "./handler/helpers.js";
6
5
  import type { SkillGroup } from "@xmtp/message-kit";
7
6
 
8
7
  export const skills: SkillGroup[] = [
9
8
  {
10
- name: "Tipping",
9
+ name: "Group bot",
11
10
  tag: "@bot",
12
- description: "Tip tokens via emoji, replies or command.",
11
+ description: "Group bot for tipping and transactions.",
13
12
  skills: [
14
13
  {
15
- command: "/tip [@usernames] [amount] [token]",
14
+ skill: "/tip [usernames] [amount] [token]",
16
15
  triggers: ["/tip"],
17
16
  examples: ["/tip @vitalik 10 usdc"],
18
17
  description: "Tip users in a specified token.",
@@ -29,15 +28,8 @@ export const skills: SkillGroup[] = [
29
28
  },
30
29
  },
31
30
  },
32
- ],
33
- },
34
-
35
- {
36
- name: "Transactions",
37
- description: "Multipurpose transaction frame built onbase.",
38
- skills: [
39
31
  {
40
- command: "/send [amount] [token] [username]",
32
+ skill: "/send [amount] [token] [username]",
41
33
  triggers: ["/send"],
42
34
  examples: ["/send 10 usdc @vitalik"],
43
35
  description:
@@ -60,7 +52,7 @@ export const skills: SkillGroup[] = [
60
52
  },
61
53
  },
62
54
  {
63
- command: "/swap [amount] [token_from] [token_to]",
55
+ skill: "/swap [amount] [token_from] [token_to]",
64
56
  triggers: ["/swap"],
65
57
  examples: ["/swap 10 usdc eth"],
66
58
  description: "Exchange one type of cryptocurrency for another.",
@@ -83,24 +75,19 @@ export const skills: SkillGroup[] = [
83
75
  },
84
76
  },
85
77
  {
86
- command: "/show",
78
+ skill: "/show",
87
79
  triggers: ["/show"],
88
80
  examples: ["/show"],
89
81
  handler: transaction,
90
82
  description: "Show the whole frame.",
91
83
  params: {},
92
84
  },
93
- ],
94
- },
95
- {
96
- name: "Games",
97
- description: "Provides various gaming experiences.",
98
- skills: [
99
85
  {
100
- command: "/game [game]",
86
+ skill: "/game [game]",
101
87
  triggers: ["/game", "🔎", "🔍"],
102
88
  handler: games,
103
89
  description: "Play a game.",
90
+ examples: ["/game wordle", "/game slot", "/game help"],
104
91
  params: {
105
92
  game: {
106
93
  default: "",
@@ -109,43 +96,19 @@ export const skills: SkillGroup[] = [
109
96
  },
110
97
  },
111
98
  },
112
- ],
113
- },
114
- {
115
- name: "Agent",
116
- description: "Manage agent commands.",
117
- skills: [
118
- {
119
- command: "/agent [prompt]",
120
- triggers: ["/agent", "@agent", "@bot"],
121
- examples: ["/agent @vitalik"],
122
- handler: agent,
123
- description: "Manage agent commands.",
124
- params: {
125
- prompt: {
126
- default: "",
127
- type: "prompt",
128
- },
129
- },
130
- },
131
- ],
132
- },
133
- {
134
- name: "Help",
135
- description: "Get help with the bot.",
136
- skills: [
137
99
  {
138
- command: "/help",
100
+ skill: "/help",
139
101
  triggers: ["/help"],
140
102
  examples: ["/help"],
141
- handler: groupHelp,
103
+ handler: help,
142
104
  description: "Get help with the bot.",
143
105
  params: {},
144
106
  },
145
107
  {
146
- command: "/id",
108
+ skill: "/id",
147
109
  adminOnly: true,
148
- handler: groupHelp,
110
+ examples: ["/id"],
111
+ handler: help,
149
112
  triggers: ["/id"],
150
113
  description: "Get the group ID.",
151
114
  params: {},