create-message-kit 1.1.7-beta.32 → 1.1.7-beta.33
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +2 -0
- package/package.json +1 -1
- package/templates/agent/src/prompt.ts +1 -0
- package/templates/gm/.env.example +1 -1
- package/templates/gm/src/index.ts +2 -17
- package/templates/group/.env.example +1 -1
- package/templates/group/src/handler/payment.ts +28 -0
- package/templates/group/src/handler/tipping.ts +1 -13
- package/templates/group/src/index.ts +0 -1
- package/templates/group/src/prompt.ts +9 -0
- package/templates/group/src/skills.ts +6 -37
- package/templates/group/src/handler/agent.ts +0 -31
- package/templates/group/src/handler/transaction.ts +0 -69
package/index.js
CHANGED
@@ -22,6 +22,8 @@ program
|
|
22
22
|
// Add Yarn 4 check at the start of the action
|
23
23
|
const pkgManager = await detectPackageManager();
|
24
24
|
|
25
|
+
log.info(pc.cyan(`pkgManager detected: ${pkgManager}`));
|
26
|
+
|
25
27
|
log.info(pc.cyan(`Welcome to MessageKit CLI v${version}!`));
|
26
28
|
const coolLogo = `
|
27
29
|
███╗ ███╗███████╗███████╗███████╗ █████╗ ██████╗ ███████╗██╗ ██╗██╗████████╗
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
KEY= # the private key of the
|
1
|
+
KEY= # the private key of the agent wallet
|
@@ -1,20 +1,5 @@
|
|
1
1
|
import { run, HandlerContext } from "@xmtp/message-kit";
|
2
|
-
run(async (context: HandlerContext) => {
|
3
|
-
// To reply, just call `reply` on the HandlerContext
|
4
|
-
await context.send(`gm`);
|
5
2
|
|
6
|
-
|
7
|
-
context.
|
8
|
-
console.log("awaited handler");
|
9
|
-
const userResponse = responseContext?.message?.content?.text?.toLowerCase();
|
10
|
-
if (userResponse === "yes") {
|
11
|
-
await responseContext.send("Action confirmed.");
|
12
|
-
} else if (userResponse === "no") {
|
13
|
-
await responseContext.send("Action canceled.");
|
14
|
-
} else {
|
15
|
-
await responseContext.send("Please respond with 'yes' or 'no'.");
|
16
|
-
// Re-set the handler to await the correct response again
|
17
|
-
context.setAwaitedHandler(responseContext?.awaitedHandler!);
|
18
|
-
}
|
19
|
-
});
|
3
|
+
run(async (context: HandlerContext) => {
|
4
|
+
context.send("gm");
|
20
5
|
});
|
@@ -1,2 +1,2 @@
|
|
1
|
-
KEY= # the private key of the
|
1
|
+
KEY= # the private key of the agent wallet
|
2
2
|
OPEN_AI_API_KEY= # openai api key
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { getUserInfo, HandlerContext } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export async function handler(context: HandlerContext) {
|
4
|
+
const {
|
5
|
+
message: {
|
6
|
+
content: { skill, params },
|
7
|
+
},
|
8
|
+
} = context;
|
9
|
+
const baseUrl = "https://txpay.vercel.app";
|
10
|
+
|
11
|
+
if (skill === "pay") {
|
12
|
+
const { amount: amountSend, token: tokenSend, username } = params; // [!code hl] // [!code focus]
|
13
|
+
let senderInfo = await getUserInfo(username);
|
14
|
+
if (!amountSend || !tokenSend || !senderInfo) {
|
15
|
+
context.reply(
|
16
|
+
"Missing required parameters. Please provide amount, token, and username.",
|
17
|
+
);
|
18
|
+
return {
|
19
|
+
code: 400,
|
20
|
+
message:
|
21
|
+
"Missing required parameters. Please provide amount, token, and username.",
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
let sendUrl = `${baseUrl}/?transaction_type=send&amount=${amountSend}&token=${tokenSend}&receiver=${senderInfo.address}`;
|
26
|
+
await context.send(`${sendUrl}`);
|
27
|
+
}
|
28
|
+
}
|
@@ -5,14 +5,10 @@ import {
|
|
5
5
|
} from "@xmtp/message-kit";
|
6
6
|
import { getUserInfo } from "@xmtp/message-kit";
|
7
7
|
|
8
|
-
export async function handler(context: HandlerContext)
|
8
|
+
export async function handler(context: HandlerContext) {
|
9
9
|
const {
|
10
|
-
members,
|
11
10
|
message: {
|
12
11
|
content: {
|
13
|
-
reference,
|
14
|
-
reply,
|
15
|
-
text,
|
16
12
|
skill,
|
17
13
|
params: { amount, username },
|
18
14
|
},
|
@@ -28,10 +24,6 @@ export async function handler(context: HandlerContext): Promise<SkillResponse> {
|
|
28
24
|
}
|
29
25
|
if (!sender || receivers.length === 0 || amount === 0) {
|
30
26
|
context.reply("Sender or receiver or amount not found.");
|
31
|
-
return {
|
32
|
-
code: 400,
|
33
|
-
message: "Sender or receiver or amount not found.",
|
34
|
-
};
|
35
27
|
}
|
36
28
|
const receiverAddresses = receivers.map((receiver) => receiver.address);
|
37
29
|
|
@@ -45,8 +37,4 @@ export async function handler(context: HandlerContext): Promise<SkillResponse> {
|
|
45
37
|
`You sent ${amount * receiverAddresses.length} tokens in total.`,
|
46
38
|
[sender.address],
|
47
39
|
);
|
48
|
-
return {
|
49
|
-
code: 200,
|
50
|
-
message: "Success",
|
51
|
-
};
|
52
40
|
}
|
@@ -13,6 +13,15 @@ export async function agent_prompt(userInfo: UserInfo) {
|
|
13
13
|
PROMPT_USER_CONTENT(userInfo) +
|
14
14
|
PROMPT_SKILLS_AND_EXAMPLES(skills, "@bot");
|
15
15
|
|
16
|
+
let fineTunedPrompt = `
|
17
|
+
## Example response
|
18
|
+
1. If user wants to play a game, use the skill 'game' and specify the game type.
|
19
|
+
Hey! Sure let's do that.\n/game wordle
|
20
|
+
1. If user wants to pay, use the skill 'pay' and if not specified default to 1 USDC.
|
21
|
+
Hey! Sure let's do that.\n/pay 1 USDC vitalik.eth
|
22
|
+
`;
|
23
|
+
|
24
|
+
systemPrompt += fineTunedPrompt;
|
16
25
|
// Replace the variables in the system prompt
|
17
26
|
systemPrompt = PROMPT_REPLACE_VARIABLES(
|
18
27
|
systemPrompt,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { handler as tipping } from "./handler/tipping.js";
|
2
|
-
import { handler as
|
2
|
+
import { handler as payment } from "./handler/payment.js";
|
3
3
|
import { handler as games } from "./handler/game.js";
|
4
4
|
import { handler as help } from "./handler/helpers.js";
|
5
5
|
import type { SkillGroup } from "@xmtp/message-kit";
|
@@ -8,7 +8,7 @@ export const skills: SkillGroup[] = [
|
|
8
8
|
{
|
9
9
|
name: "Group bot",
|
10
10
|
tag: "@bot",
|
11
|
-
description: "Group
|
11
|
+
description: "Group agent for tipping and transactions.",
|
12
12
|
skills: [
|
13
13
|
{
|
14
14
|
skill: "/tip [usernames] [amount] [token]",
|
@@ -29,12 +29,12 @@ export const skills: SkillGroup[] = [
|
|
29
29
|
},
|
30
30
|
},
|
31
31
|
{
|
32
|
-
skill: "/
|
33
|
-
triggers: ["/
|
34
|
-
examples: ["/
|
32
|
+
skill: "/pay [amount] [token] [username]",
|
33
|
+
triggers: ["/pay"],
|
34
|
+
examples: ["/pay 10 vitalik.eth"],
|
35
35
|
description:
|
36
36
|
"Send a specified amount of a cryptocurrency to a destination address.",
|
37
|
-
handler:
|
37
|
+
handler: payment,
|
38
38
|
params: {
|
39
39
|
amount: {
|
40
40
|
default: 10,
|
@@ -51,37 +51,6 @@ export const skills: SkillGroup[] = [
|
|
51
51
|
},
|
52
52
|
},
|
53
53
|
},
|
54
|
-
{
|
55
|
-
skill: "/swap [amount] [token_from] [token_to]",
|
56
|
-
triggers: ["/swap"],
|
57
|
-
examples: ["/swap 10 usdc eth"],
|
58
|
-
description: "Exchange one type of cryptocurrency for another.",
|
59
|
-
handler: transaction,
|
60
|
-
params: {
|
61
|
-
amount: {
|
62
|
-
default: 10,
|
63
|
-
type: "number",
|
64
|
-
},
|
65
|
-
token_from: {
|
66
|
-
default: "usdc",
|
67
|
-
type: "string",
|
68
|
-
values: ["eth", "dai", "usdc", "degen"], // Accepted tokens
|
69
|
-
},
|
70
|
-
token_to: {
|
71
|
-
default: "eth",
|
72
|
-
type: "string",
|
73
|
-
values: ["eth", "dai", "usdc", "degen"], // Accepted tokenss
|
74
|
-
},
|
75
|
-
},
|
76
|
-
},
|
77
|
-
{
|
78
|
-
skill: "/show",
|
79
|
-
triggers: ["/show"],
|
80
|
-
examples: ["/show"],
|
81
|
-
handler: transaction,
|
82
|
-
description: "Show the whole frame.",
|
83
|
-
params: {},
|
84
|
-
},
|
85
54
|
{
|
86
55
|
skill: "/game [game]",
|
87
56
|
triggers: ["/game", "🔎", "🔍"],
|
@@ -1,31 +0,0 @@
|
|
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";
|
5
|
-
|
6
|
-
run(async (context: HandlerContext) => {
|
7
|
-
const {
|
8
|
-
message: {
|
9
|
-
content: { text, params },
|
10
|
-
sender,
|
11
|
-
},
|
12
|
-
} = context;
|
13
|
-
|
14
|
-
try {
|
15
|
-
let userPrompt = params?.prompt ?? text;
|
16
|
-
const userInfo = await getUserInfo(sender.address);
|
17
|
-
if (!userInfo) {
|
18
|
-
console.log("User info not found");
|
19
|
-
return;
|
20
|
-
}
|
21
|
-
const { reply } = await textGeneration(
|
22
|
-
sender.address,
|
23
|
-
userPrompt,
|
24
|
-
await agent_prompt(userInfo),
|
25
|
-
);
|
26
|
-
await processMultilineResponse(sender.address, reply, context);
|
27
|
-
} catch (error) {
|
28
|
-
console.error("Error during OpenAI call:", error);
|
29
|
-
await context.send("An error occurred while processing your request.");
|
30
|
-
}
|
31
|
-
});
|
@@ -1,69 +0,0 @@
|
|
1
|
-
import { getUserInfo, HandlerContext, SkillResponse } from "@xmtp/message-kit";
|
2
|
-
|
3
|
-
// Main handler function for processing
|
4
|
-
export async function handler(context: HandlerContext): Promise<SkillResponse> {
|
5
|
-
const {
|
6
|
-
message: {
|
7
|
-
content: { skill, params },
|
8
|
-
},
|
9
|
-
} = context;
|
10
|
-
const baseUrl = "https://base-tx-frame.vercel.app/transaction";
|
11
|
-
|
12
|
-
switch (skill) {
|
13
|
-
case "send":
|
14
|
-
// Destructure and validate parameters for the send
|
15
|
-
const { amount: amountSend, token: tokenSend, username } = params; // [!code hl] // [!code focus]
|
16
|
-
let senderInfo = await getUserInfo(username);
|
17
|
-
if (!amountSend || !tokenSend || !senderInfo) {
|
18
|
-
context.reply(
|
19
|
-
"Missing required parameters. Please provide amount, token, and username.",
|
20
|
-
);
|
21
|
-
return {
|
22
|
-
code: 400,
|
23
|
-
message:
|
24
|
-
"Missing required parameters. Please provide amount, token, and username.",
|
25
|
-
};
|
26
|
-
}
|
27
|
-
|
28
|
-
let sendUrl = `${baseUrl}/?transaction_type=send&amount=${amountSend}&token=${tokenSend}&receiver=${senderInfo.address}`;
|
29
|
-
context.send(`${sendUrl}`);
|
30
|
-
return {
|
31
|
-
code: 200,
|
32
|
-
message: `${sendUrl}`,
|
33
|
-
};
|
34
|
-
case "swap":
|
35
|
-
// Destructure and validate parameters for the swap
|
36
|
-
const { amount, token_from, token_to } = params; // [!code hl] // [!code focus]
|
37
|
-
|
38
|
-
if (!amount || !token_from || !token_to) {
|
39
|
-
context.reply(
|
40
|
-
"Missing required parameters. Please provide amount, token_from, and token_to.",
|
41
|
-
);
|
42
|
-
return {
|
43
|
-
code: 400,
|
44
|
-
message:
|
45
|
-
"Missing required parameters. Please provide amount, token_from, and token_to.",
|
46
|
-
};
|
47
|
-
}
|
48
|
-
|
49
|
-
let swapUrl = `${baseUrl}/?transaction_type=swap&token_from=${token_from}&token_to=${token_to}&amount=${amount}`;
|
50
|
-
context.send(`${swapUrl}`);
|
51
|
-
return {
|
52
|
-
code: 200,
|
53
|
-
message: `${swapUrl}`,
|
54
|
-
};
|
55
|
-
case "show": // [!code hl] // [!code focus]
|
56
|
-
// Show the base URL without the transaction path
|
57
|
-
context.reply(`${baseUrl.replace("/transaction", "")}`);
|
58
|
-
return {
|
59
|
-
code: 200,
|
60
|
-
message: `${baseUrl.replace("/transaction", "")}`,
|
61
|
-
};
|
62
|
-
default:
|
63
|
-
context.reply("Unknown skill. Use help to see all available skills.");
|
64
|
-
return {
|
65
|
-
code: 400,
|
66
|
-
message: "Unknown skill. Use help to see all available skills.",
|
67
|
-
};
|
68
|
-
}
|
69
|
-
}
|