create-message-kit 1.2.18 → 1.2.20

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.18";
10
+ const defVersion = "1.2.20";
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.18",
3
+ "version": "1.2.20",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -5,7 +5,7 @@ import { LearnWeb3Client, Network } from "../plugins/learnweb3.js";
5
5
 
6
6
  export const registerSkill: Skill[] = [
7
7
  {
8
- skill: "/drip [network] [address]",
8
+ skill: "drip",
9
9
  handler: handler,
10
10
  examples: [
11
11
  "/drip base_sepolia 0x123456789",
@@ -4,7 +4,7 @@ import { baseUrl } from "../index.js";
4
4
 
5
5
  export const registerSkill: Skill[] = [
6
6
  {
7
- skill: "/mint [collection] [token_id] [url]",
7
+ skill: "mint",
8
8
  examples: [
9
9
  "/mint 0x73a333cb82862d4f66f0154229755b184fb4f5b0 1",
10
10
  "/mint https://zora.co/collect/base/0x123456789/1...",
@@ -3,7 +3,7 @@ import type { Skill } from "@xmtp/message-kit";
3
3
 
4
4
  export const registerSkill: Skill[] = [
5
5
  {
6
- skill: "/pay [amount] [token] [username]",
6
+ skill: "pay",
7
7
  examples: ["/pay 10 vitalik.eth"],
8
8
  description:
9
9
  "Send a specified amount of a cryptocurrency to a destination address.",
@@ -4,7 +4,7 @@ import { baseUrl } from "../index.js";
4
4
 
5
5
  export const registerSkill: Skill[] = [
6
6
  {
7
- skill: "/swap [amount] [token_from] [token_to]",
7
+ skill: "swap",
8
8
  examples: ["/swap 10 usdc eth", "/swap 1 dai usdc"],
9
9
  handler: handler,
10
10
  description: "Exchange one type of cryptocurrency for another.",
@@ -39,7 +39,7 @@ export async function handler(context: XMTPContext) {
39
39
 
40
40
  if (!amount || !token_from || !token_to) {
41
41
  context.reply(
42
- "Missing required parameters. Please provide amount, token_from, and token_to."
42
+ "Missing required parameters. Please provide amount, token_from, and token_to.",
43
43
  );
44
44
  return;
45
45
  }
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -8,7 +8,8 @@
8
8
  "start": "node dist/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@xmtp/message-kit": "workspace:*"
11
+ "@xmtp/message-kit": "workspace:*",
12
+ "resend": "^4.0.1"
12
13
  },
13
14
  "devDependencies": {
14
15
  "@types/node": "^20.14.2",
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -26,7 +26,7 @@ export const faucet: Skill[] = [
26
26
  },
27
27
  },
28
28
  {
29
- skill: "/networks",
29
+ skill: "networks",
30
30
  handler: handleFaucet,
31
31
  examples: ["/networks"],
32
32
  description: "Get the list of supported networks.",
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -18,20 +18,17 @@ export const agent: Agent = {
18
18
  skills: [...web, ...cryptoPrice, ...search],
19
19
  };
20
20
 
21
- // [!region gated]
22
- const { client } = await xmtpClient({
23
- hideInitLogMessage: true,
24
- });
25
-
26
21
  run(
27
22
  async (context: XMTPContext) => {
28
23
  const {
29
- message: { sender },
24
+ message: {
25
+ sender,
26
+ content: { text },
27
+ },
30
28
  agent,
31
29
  } = context;
32
30
 
33
31
  let prompt = await replaceVariables(systemPrompt, sender.address, agent);
34
-
35
32
  //This is only used for to update the docs.
36
33
  fs.writeFileSync("example_prompt.md", prompt);
37
34
  await agentReply(context, prompt);
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -2,6 +2,5 @@ KEY= # the private key of the wallet
2
2
  TEST_ENCRYPTION_KEY= # a different private key for encryption
3
3
  OPENAI_API_KEY= # the API key for OpenAI
4
4
  REDIS_CONNECTION_STRING= # the connection to the toss database in Redis
5
- COINBASE_API_REDIS_URL= # the API key for OpenAI
6
5
  COINBASE_API_KEY_NAME= # the API key name for Coinbase
7
6
  COINBASE_API_KEY_PRIVATE_KEY= # the private key for Coinbase
@@ -1,4 +1,9 @@
1
1
  compressionLevel: mixed
2
+
2
3
  enableGlobalCache: false
4
+
3
5
  enableTelemetry: false
6
+
4
7
  nodeLinker: node-modules
8
+
9
+ yarnPath: .yarn/releases/yarn-4.5.1.cjs
@@ -9,8 +9,7 @@ import {
9
9
  import { systemPrompt } from "./prompt.js";
10
10
  import { toss } from "./skills/toss.js";
11
11
  import fs from "fs";
12
- import { getWalletService } from "./plugins/redis.js";
13
- const walletServiceDB = await getWalletService();
12
+
14
13
  export const agent: Agent = {
15
14
  name: "Toss Bot",
16
15
  tag: "@toss",
@@ -29,5 +28,5 @@ run(
29
28
  fs.writeFileSync("example_prompt.md", prompt);
30
29
  await agentReply(context, prompt);
31
30
  },
32
- { agent, walletServiceDB },
31
+ { agent },
33
32
  );
@@ -1,7 +1,6 @@
1
1
  import { XMTPContext } from "@xmtp/message-kit";
2
2
  import { getRedisClient } from "./redis.js";
3
3
 
4
- const tossDBClient = await getRedisClient();
5
4
  interface Participant {
6
5
  response: string;
7
6
  name: string;
@@ -18,8 +17,7 @@ export interface TossData {
18
17
  created_at: string;
19
18
  end_time: string;
20
19
  description: string;
21
- encrypted_participants: string[];
22
- participants?: Participant[];
20
+ participants: Participant[];
23
21
  toss_wallet_address: string;
24
22
  }
25
23
  export async function checkTossCorrect(
@@ -29,9 +27,9 @@ export async function checkTossCorrect(
29
27
  message: {
30
28
  content: { previousMsg },
31
29
  },
32
- walletService,
33
30
  group,
34
31
  } = context;
32
+
35
33
  if (!group) {
36
34
  await context.reply("This command can only be used in a group.");
37
35
  return undefined;
@@ -47,15 +45,14 @@ export async function checkTossCorrect(
47
45
  );
48
46
  return undefined;
49
47
  }
50
- let encryptedKey = walletService.encrypt(toss_id);
51
- const tossDataString = await tossDBClient.get(`toss:${encryptedKey}`);
52
- const hexString = tossDataString?.replace(/"/g, "");
53
- let tossData = hexString ? walletService.decrypt(hexString) : null;
48
+ const tossDBClient = await getRedisClient();
49
+ const tossDataString = await tossDBClient.get(`toss:${toss_id}`);
50
+ let tossData = tossDataString ? JSON.parse(tossDataString) : null;
54
51
 
55
52
  if (typeof tossData === "string") {
56
53
  tossData = JSON.parse(tossData) as TossData;
57
54
  }
58
- console.log("tossData", tossData);
55
+
59
56
  if (!tossData) {
60
57
  await context.reply("Toss not found");
61
58
  return undefined;
@@ -66,13 +63,8 @@ export async function checkTossCorrect(
66
63
  await context.reply("This toss is not in this group.");
67
64
  return undefined;
68
65
  }
69
- tossData.participants = [];
70
- if (tossData.encrypted_participants?.length) {
71
- tossData.participants = tossData.encrypted_participants?.map((p: string) =>
72
- walletService.decrypt(p),
73
- );
74
- }
75
- const pool = tossData.amount * (tossData?.participants?.length || 0);
66
+
67
+ const pool = tossData.amount * (tossData.participants?.length || 0);
76
68
  return { ...tossData, toss_id, pool };
77
69
  }
78
70
 
@@ -1,18 +1,7 @@
1
1
  import { createClient } from "@redis/client";
2
- import type { RedisClientType } from "@redis/client";
3
-
4
- let redisClient: RedisClientType | null = null;
2
+ import { RedisClientType } from "@redis/client";
5
3
 
6
4
  export const getRedisClient = async () => {
7
- if (redisClient?.isOpen) {
8
- return redisClient;
9
- }
10
-
11
- if (!process.env.REDIS_CONNECTION_STRING) {
12
- throw new Error(
13
- "REDIS_CONNECTION_STRING not found in environment variables",
14
- );
15
- }
16
5
  const client = createClient({
17
6
  url: process.env.REDIS_CONNECTION_STRING,
18
7
  });
@@ -22,57 +11,5 @@ export const getRedisClient = async () => {
22
11
  });
23
12
 
24
13
  await client.connect();
25
- redisClient = client as RedisClientType;
26
- return client as RedisClientType;
27
- };
28
-
29
- let walletService: RedisClientType | null = null;
30
-
31
- export const getWalletService = async (): Promise<RedisClientType> => {
32
- if (walletService?.isOpen) {
33
- return walletService;
34
- }
35
-
36
- if (!process.env.COINBASE_API_REDIS_URL) {
37
- throw new Error(
38
- "COINBASE_API_REDIS_URL not found in environment variables",
39
- );
40
- }
41
-
42
- const client = createClient({
43
- url: process.env.COINBASE_API_REDIS_URL,
44
- });
45
-
46
- client.on("error", (error: Error) => {
47
- console.error("Toss wallet Redis client error:", error);
48
- });
49
-
50
- client.on("connect", () => {
51
- console.log("Connected to Toss Wallet Redis");
52
- });
53
- await client.connect();
54
- walletService = client as RedisClientType;
55
14
  return client as RedisClientType;
56
15
  };
57
-
58
- export async function updateField(
59
- client: RedisClientType,
60
- key: string,
61
- updateObject: any,
62
- ) {
63
- // Check if the key exists
64
- const data = await client.get(key);
65
-
66
- let updatedData;
67
- if (data) {
68
- // If the key exists, parse it and merge the updates
69
- const parsedData = JSON.parse(data);
70
- updatedData = { ...parsedData, ...updateObject };
71
- } else {
72
- // If the key doesn't exist, use the updateObject as the initial value
73
- updatedData = updateObject;
74
- }
75
-
76
- // Save the updated or new data back to Redis
77
- await client.set(key, JSON.stringify(updatedData));
78
- }
@@ -1,5 +1,4 @@
1
1
  import { Skill, XMTPContext, getUserInfo } from "@xmtp/message-kit";
2
- import { TimeoutError } from "@coinbase/coinbase-sdk";
3
2
  import { getRedisClient } from "../plugins/redis.js";
4
3
  import {
5
4
  checkTossCorrect,
@@ -11,11 +10,9 @@ import {
11
10
  DM_HELP_MESSAGE,
12
11
  } from "../plugins/helpers.js";
13
12
 
14
- const tossDBClient = await getRedisClient();
15
-
16
13
  export const toss: Skill[] = [
17
14
  {
18
- skill: "/end [option]",
15
+ skill: "end",
19
16
  description: "End a toss.",
20
17
  handler: handleEndToss,
21
18
  examples: ["/end yes", "/end no"],
@@ -26,14 +23,13 @@ export const toss: Skill[] = [
26
23
  },
27
24
  },
28
25
  {
29
- skill: "/create",
26
+ skill: "create",
30
27
  description: "Create an agent wallet.",
31
28
  handler: handleDM,
32
29
  examples: ["/create"],
33
- params: {},
34
30
  },
35
31
  {
36
- skill: "/fund [amount]",
32
+ skill: "fund",
37
33
  description: "Fund your account.",
38
34
  handler: handleDM,
39
35
  examples: ["/fund 10"],
@@ -44,7 +40,7 @@ export const toss: Skill[] = [
44
40
  },
45
41
  },
46
42
  {
47
- skill: "/withdraw [amount]",
43
+ skill: "withdraw",
48
44
  description: "Withdraw funds from your account.",
49
45
  handler: handleDM,
50
46
  examples: ["/withdraw 10"],
@@ -55,28 +51,25 @@ export const toss: Skill[] = [
55
51
  },
56
52
  },
57
53
  {
58
- skill: "/help",
54
+ skill: "help",
59
55
  description: "Get help with tossing.",
60
56
  handler: handleDM,
61
57
  examples: ["/help"],
62
- params: {},
63
58
  },
64
59
  {
65
- skill: "/cancel",
60
+ skill: "cancel",
66
61
  description: "Cancel a toss.",
67
62
  handler: handleCancelToss,
68
63
  examples: ["/cancel"],
69
- params: {},
70
64
  },
71
65
  {
72
- skill: "/balance",
66
+ skill: "balance",
73
67
  description: "Check your balance.",
74
68
  handler: handleDM,
75
69
  examples: ["/balance"],
76
- params: {},
77
70
  },
78
71
  {
79
- skill: "/join [response]",
72
+ skill: "join",
80
73
  description: "Join a toss.",
81
74
  params: {
82
75
  response: {
@@ -87,15 +80,13 @@ export const toss: Skill[] = [
87
80
  examples: ["/join yes", "/join no"],
88
81
  },
89
82
  {
90
- skill: "/status",
83
+ skill: "status",
91
84
  description: "Check the status of the toss.",
92
85
  handler: handleTossStatus,
93
86
  examples: ["/status"],
94
- params: {},
95
87
  },
96
88
  {
97
- skill:
98
- "/toss [description] [options (separated by comma)] [amount] [judge(optional)] [endTime(optional)]",
89
+ skill: "toss",
99
90
  description:
100
91
  "Create a toss with a description, options, amount and judge(optional).",
101
92
  handler: handleTossCreation,
@@ -120,9 +111,11 @@ export const toss: Skill[] = [
120
111
  },
121
112
  judge: {
122
113
  type: "username",
114
+ optional: true,
123
115
  },
124
116
  endTime: {
125
117
  type: "quoted",
118
+ optional: true,
126
119
  },
127
120
  },
128
121
  },
@@ -142,6 +135,7 @@ export async function handleTossCreation(context: XMTPContext) {
142
135
  return;
143
136
  }
144
137
 
138
+ const tossDBClient = await getRedisClient();
145
139
  if (params.description && params.options && !isNaN(Number(params.amount))) {
146
140
  const keys = await tossDBClient.keys("*");
147
141
  let tossId = keys.length + 1;
@@ -163,17 +157,18 @@ export async function handleTossCreation(context: XMTPContext) {
163
157
  end_time: params.endTime
164
158
  ? new Date(params.endTime).toLocaleString()
165
159
  : new Date(Date.now() + 24 * 60 * 60 * 1000).toLocaleString(),
166
- encrypted_participants: [],
167
160
  participants: [],
168
161
  toss_wallet_address: createdTossWallet?.address,
169
162
  };
170
163
  await tossDBClient.set(
171
- "toss:" + walletService.encrypt(tossId.toString()),
172
- walletService.encrypt(tossData),
164
+ "toss:" + tossId.toString(),
165
+ JSON.stringify(tossData),
173
166
  );
174
-
167
+ console.log(tossData);
175
168
  if (tossId !== undefined) {
176
- await context.send(generateTossMessage(tossData));
169
+ let msg = generateTossMessage(tossData);
170
+ console.log(msg);
171
+ await context.send(msg);
177
172
  } else {
178
173
  await context.reply(
179
174
  `An error occurred while creating the toss. ${JSON.stringify(tossId)}`,
@@ -188,7 +183,7 @@ export async function handleJoinToss(context: XMTPContext) {
188
183
  return;
189
184
  }
190
185
 
191
- const { toss_id, participants, encrypted_participants, amount } = tossData;
186
+ const { toss_id, participants, amount } = tossData;
192
187
 
193
188
  const {
194
189
  message: {
@@ -201,6 +196,7 @@ export async function handleJoinToss(context: XMTPContext) {
201
196
  walletService,
202
197
  } = context;
203
198
 
199
+ const tossDBClient = await getRedisClient();
204
200
  if (participants?.some((p) => p.address === sender.address)) {
205
201
  await context.reply("You have already joined this toss.");
206
202
  return;
@@ -231,21 +227,19 @@ export async function handleJoinToss(context: XMTPContext) {
231
227
  amount,
232
228
  );
233
229
  console.log("Transfer:", transfer.getTransactionHash());
234
- const encryptedParticipant = walletService.encrypt({
230
+ const participant = {
235
231
  address: sender.address,
236
232
  agent_address: senderWallet.address,
237
233
  response: response,
238
234
  name:
239
235
  (await context.getUserInfo(sender.address))?.preferredName ??
240
236
  sender.address,
241
- });
242
- encrypted_participants.push(encryptedParticipant as string);
237
+ };
238
+ participants.push(participant);
243
239
 
244
240
  await tossDBClient.set(
245
- `toss:${walletService.encrypt(toss_id)}`,
246
- walletService.encrypt(
247
- JSON.stringify({ ...tossData, encrypted_participants }),
248
- ),
241
+ `toss:${toss_id}`,
242
+ JSON.stringify({ ...tossData, participants }),
249
243
  );
250
244
 
251
245
  await context.reply("Successfully joined the toss!");
@@ -275,6 +269,7 @@ export async function handleEndToss(context: XMTPContext) {
275
269
  walletService,
276
270
  } = context;
277
271
 
272
+ const tossDBClient = await getRedisClient();
278
273
  if (participants?.length === 0) {
279
274
  await context.reply("No participants for this toss.");
280
275
  return;
@@ -323,10 +318,8 @@ export async function handleEndToss(context: XMTPContext) {
323
318
  );
324
319
  console.log("Transfer:", transfer.getTransactionHash());
325
320
  await tossDBClient.set(
326
- `toss:${walletService.encrypt(toss_id)}`,
327
- walletService.encrypt(
328
- JSON.stringify({ ...tossData, status: "closed" }),
329
- ),
321
+ `toss:${toss_id}`,
322
+ JSON.stringify({ ...tossData, status: "closed" }),
330
323
  );
331
324
  }
332
325
  // Clean up
@@ -355,6 +348,7 @@ export async function handleCancelToss(context: XMTPContext) {
355
348
  walletService,
356
349
  } = context;
357
350
 
351
+ const tossDBClient = await getRedisClient();
358
352
  if (participants?.length === 0) {
359
353
  await context.reply("No participants for this toss.");
360
354
  return;
@@ -395,8 +389,8 @@ export async function handleCancelToss(context: XMTPContext) {
395
389
  //await walletService.deleteTempWallet(tossWalletRedis, tossId.toString());
396
390
 
397
391
  await tossDBClient.set(
398
- `toss:${walletService.encrypt(toss_id)}`,
399
- walletService.encrypt(JSON.stringify({ ...tossData, status: "cancelled" })),
392
+ `toss:${toss_id}`,
393
+ JSON.stringify({ ...tossData, status: "cancelled" }),
400
394
  );
401
395
 
402
396
  await context.reply(