create-message-kit 1.2.22 → 1.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +2 -5
  2. package/index.js +15 -15
  3. package/package.json +1 -2
  4. package/templates/ens/.cursorrules +0 -112
  5. package/templates/ens/package.json +1 -2
  6. package/templates/ens/src/index.ts +4 -38
  7. package/templates/ens/src/prompt.ts +1 -1
  8. package/templates/ens/src/skills/info.ts +6 -3
  9. package/templates/simple/.cursorrules +0 -112
  10. package/templates/simple/src/index.ts +10 -9
  11. package/templates/coinbase-agent/.cursorrules +0 -290
  12. package/templates/coinbase-agent/.env.example +0 -4
  13. package/templates/coinbase-agent/.yarnrc.yml +0 -9
  14. package/templates/coinbase-agent/package.json +0 -22
  15. package/templates/coinbase-agent/src/index.ts +0 -31
  16. package/templates/coinbase-agent/src/plugins/learnweb3.ts +0 -96
  17. package/templates/coinbase-agent/src/plugins/redis.ts +0 -15
  18. package/templates/coinbase-agent/src/prompt.ts +0 -64
  19. package/templates/coinbase-agent/src/skills/drip.ts +0 -83
  20. package/templates/coinbase-agent/src/skills/mint.ts +0 -99
  21. package/templates/coinbase-agent/src/skills/pay.ts +0 -35
  22. package/templates/coinbase-agent/src/skills/swap.ts +0 -52
  23. package/templates/faucet/.cursorrules +0 -290
  24. package/templates/faucet/.env.example +0 -5
  25. package/templates/faucet/.yarnrc.yml +0 -9
  26. package/templates/faucet/package.json +0 -22
  27. package/templates/faucet/src/index.ts +0 -39
  28. package/templates/faucet/src/plugins/learnweb3.ts +0 -96
  29. package/templates/faucet/src/plugins/redis.ts +0 -15
  30. package/templates/faucet/src/prompt.ts +0 -11
  31. package/templates/faucet/src/skills/faucet.ts +0 -140
  32. package/templates/gated-group/.cursorrules +0 -290
  33. package/templates/gated-group/.env.example +0 -3
  34. package/templates/gated-group/.yarnrc.yml +0 -9
  35. package/templates/gated-group/package.json +0 -23
  36. package/templates/gated-group/src/index.ts +0 -17
  37. package/templates/gated-group/src/plugins/alchemy.ts +0 -27
  38. package/templates/gated-group/src/plugins/xmtp.ts +0 -137
  39. package/templates/gated-group/src/prompt.ts +0 -11
  40. package/templates/gated-group/src/skills/gated.ts +0 -88
  41. package/templates/gm/.cursorrules +0 -290
  42. package/templates/gm/.env.example +0 -2
  43. package/templates/gm/.yarnrc.yml +0 -9
  44. package/templates/gm/package.json +0 -20
  45. package/templates/gm/src/index.ts +0 -8
  46. package/templates/playground/.cursorrules +0 -290
  47. package/templates/playground/.env.example +0 -6
  48. package/templates/playground/.yarnrc.yml +0 -9
  49. package/templates/playground/package.json +0 -26
  50. package/templates/playground/src/index.ts +0 -37
  51. package/templates/playground/src/plugins/alchemy.ts +0 -27
  52. package/templates/playground/src/plugins/minilog.ts +0 -26
  53. package/templates/playground/src/plugins/usdc.ts +0 -99
  54. package/templates/playground/src/plugins/xmtp.ts +0 -137
  55. package/templates/playground/src/prompt.ts +0 -11
  56. package/templates/playground/src/skills/broadcast.ts +0 -39
  57. package/templates/playground/src/skills/cash.ts +0 -122
  58. package/templates/playground/src/skills/cryptoPrice.ts +0 -63
  59. package/templates/playground/src/skills/dalle.ts +0 -61
  60. package/templates/playground/src/skills/gated.ts +0 -88
  61. package/templates/playground/src/skills/search.ts +0 -159
  62. package/templates/playground/src/skills/todo.ts +0 -79
  63. package/templates/playground/src/skills/token.ts +0 -57
  64. package/templates/playground/src/skills/web.ts +0 -83
  65. package/templates/playground/src/skills/wordle.ts +0 -96
  66. package/templates/toss/.cursorrules +0 -290
  67. package/templates/toss/.env.example +0 -6
  68. package/templates/toss/.yarnrc.yml +0 -9
  69. package/templates/toss/package.json +0 -21
  70. package/templates/toss/src/index.ts +0 -32
  71. package/templates/toss/src/plugins/helpers.ts +0 -174
  72. package/templates/toss/src/plugins/redis.ts +0 -15
  73. package/templates/toss/src/prompt.ts +0 -54
  74. package/templates/toss/src/skills/toss.ts +0 -432
  75. package/templates.json +0 -58
@@ -1,432 +0,0 @@
1
- import { Skill, XMTPContext, getUserInfo } from "@xmtp/message-kit";
2
- import { getRedisClient } from "../plugins/redis.js";
3
- import {
4
- checkTossCorrect,
5
- extractWinners,
6
- TossData,
7
- generateTossMessage,
8
- generateEndTossMessage,
9
- generateTossStatusMessage,
10
- DM_HELP_MESSAGE,
11
- } from "../plugins/helpers.js";
12
-
13
- export const toss: Skill[] = [
14
- {
15
- skill: "end",
16
- description: "End a toss.",
17
- handler: handleEndToss,
18
- examples: ["/end yes", "/end no"],
19
- params: {
20
- option: {
21
- type: "string",
22
- },
23
- },
24
- },
25
- {
26
- skill: "create",
27
- description: "Create an agent wallet.",
28
- handler: handleDM,
29
- examples: ["/create"],
30
- },
31
- {
32
- skill: "fund",
33
- description: "Fund your account.",
34
- handler: handleDM,
35
- examples: ["/fund 10"],
36
- params: {
37
- amount: {
38
- type: "number",
39
- },
40
- },
41
- },
42
- {
43
- skill: "withdraw",
44
- description: "Withdraw funds from your account.",
45
- handler: handleDM,
46
- examples: ["/withdraw 10"],
47
- params: {
48
- amount: {
49
- type: "number",
50
- },
51
- },
52
- },
53
- {
54
- skill: "help",
55
- description: "Get help with tossing.",
56
- handler: handleDM,
57
- examples: ["/help"],
58
- },
59
- {
60
- skill: "cancel",
61
- description: "Cancel a toss.",
62
- handler: handleCancelToss,
63
- examples: ["/cancel"],
64
- },
65
- {
66
- skill: "balance",
67
- description: "Check your balance.",
68
- handler: handleDM,
69
- examples: ["/balance"],
70
- },
71
- {
72
- skill: "join",
73
- description: "Join a toss.",
74
- params: {
75
- response: {
76
- type: "string",
77
- },
78
- },
79
- handler: handleJoinToss,
80
- examples: ["/join yes", "/join no"],
81
- },
82
- {
83
- skill: "status",
84
- description: "Check the status of the toss.",
85
- handler: handleTossStatus,
86
- examples: ["/status"],
87
- },
88
- {
89
- skill: "toss",
90
- description:
91
- "Create a toss with a description, options, amount and judge(optional).",
92
- handler: handleTossCreation,
93
- examples: [
94
- "/toss 'Shane vs John at pickeball' 'Yes,No' 10",
95
- "/toss 'Will argentina win the world cup' 'Yes,No' 10",
96
- "/toss 'Race to the end' 'Fabri,John' 10 @fabri",
97
- "/toss 'Will argentina win the world cup' 'Yes,No' 5 '27 Oct 2023 23:59:59 GMT'",
98
- "/toss 'Will the niks win on sunday?' 'Yes,No' 10 vitalik.eth '27 Oct 2023 23:59:59 GMT'",
99
- "/toss 'Will it rain tomorrow' 'Yes,No' 0",
100
- ],
101
- params: {
102
- description: {
103
- type: "quoted",
104
- },
105
- options: {
106
- default: "Yes, No",
107
- type: "quoted",
108
- },
109
- amount: {
110
- type: "number",
111
- },
112
- judge: {
113
- type: "username",
114
- optional: true,
115
- },
116
- endTime: {
117
- type: "quoted",
118
- optional: true,
119
- },
120
- },
121
- },
122
- ];
123
-
124
- export async function handleTossCreation(context: XMTPContext) {
125
- const {
126
- message: {
127
- content: { params },
128
- sender,
129
- },
130
- walletService,
131
- group,
132
- } = context;
133
- if (!group) {
134
- await context.reply("This command can only be used in a group.");
135
- return;
136
- }
137
-
138
- const tossDBClient = await getRedisClient();
139
- if (params.description && params.options && !isNaN(Number(params.amount))) {
140
- const keys = await tossDBClient.keys("*");
141
- let tossId = keys.length + 1;
142
- const isCreated = await walletService.createWallet(
143
- tossId + ":" + sender.address,
144
- );
145
- if (!isCreated) {
146
- await context.reply("Failed to create toss wallet");
147
- return;
148
- }
149
-
150
- let tossData: TossData = {
151
- toss_id: tossId.toString(),
152
- description: params.description,
153
- options: params.options,
154
- amount: params.amount,
155
- group_id: group.id,
156
- admin_name:
157
- (await getUserInfo(params.judge ?? sender.address))?.preferredName ??
158
- "",
159
- admin_address: params.judge ?? sender.address,
160
- created_at: new Date().toLocaleString(),
161
- end_time: params.endTime
162
- ? new Date(params.endTime).toLocaleString()
163
- : new Date(Date.now() + 24 * 60 * 60 * 1000).toLocaleString(),
164
- participants: [],
165
- };
166
- await tossDBClient.set("toss:" + tossId, JSON.stringify(tossData));
167
- if (tossId !== undefined) {
168
- await context.send(generateTossMessage(tossData));
169
- } else {
170
- await context.reply(
171
- `An error occurred while creating the toss. ${tossId}`,
172
- );
173
- }
174
- }
175
- }
176
-
177
- export async function handleJoinToss(context: XMTPContext) {
178
- const tossData = await checkTossCorrect(context);
179
- if (!tossData) {
180
- return;
181
- }
182
-
183
- const { toss_id, participants, amount, admin_address } = tossData;
184
-
185
- const {
186
- message: {
187
- sender,
188
- content: {
189
- params: { response },
190
- },
191
- },
192
- walletService,
193
- } = context;
194
-
195
- const tossDBClient = await getRedisClient();
196
- if (participants?.some((p) => p.address === sender.address)) {
197
- await context.reply("You have already joined this toss.");
198
- return;
199
- }
200
- //Create wallet for sender
201
- await walletService.createWallet(sender.address);
202
- const balance = await walletService.checkBalance(sender.address);
203
- if (balance < amount) return walletService.requestFunds(amount);
204
-
205
- try {
206
- let tempWalletID = toss_id + ":" + admin_address;
207
- await walletService.transfer(sender.address, tempWalletID, amount);
208
- const participant = {
209
- address: sender.address,
210
- response: response,
211
- name:
212
- (await context.getUserInfo(sender.address))?.preferredName ??
213
- sender.address,
214
- };
215
- participants.push(participant);
216
-
217
- await tossDBClient.set(
218
- `toss:${toss_id}`,
219
- JSON.stringify({ ...tossData, participants }),
220
- );
221
-
222
- await context.reply("Successfully joined the toss!");
223
- await context.sendTo(
224
- `Your balance was deducted by $${amount}. Now is $${balance - amount}. You can check your balance with /balance`,
225
- [sender.address],
226
- );
227
- await context.executeSkill(`/status ${toss_id}`);
228
- } catch (error) {
229
- console.error(error);
230
- await context.reply("Failed to process your entry. Please try again.");
231
- }
232
- }
233
-
234
- export async function handleEndToss(context: XMTPContext) {
235
- const tossData = await checkTossCorrect(context);
236
- if (!tossData) return;
237
- const { toss_id, admin_address, options, participants } = tossData;
238
-
239
- const {
240
- message: {
241
- sender,
242
- content: {
243
- params: { option },
244
- },
245
- },
246
- walletService,
247
- } = context;
248
-
249
- const tossDBClient = await getRedisClient();
250
- if (participants?.length === 0) {
251
- await context.reply("No participants for this toss.");
252
- return;
253
- } else if (admin_address.toLowerCase() !== sender.address.toLowerCase()) {
254
- await context.reply("Only the admin can cancel the toss.");
255
- return;
256
- }
257
-
258
- let tempWalletID = toss_id + ":" + admin_address;
259
- const balance = await walletService.checkBalance(tempWalletID);
260
- const fundsNeeded = tossData.amount * participants?.length;
261
- if (balance < fundsNeeded) {
262
- await context.reply(
263
- `Toss wallet does not have enough funds ${fundsNeeded}, has ${balance}`,
264
- );
265
- return;
266
- }
267
-
268
- //Winners
269
-
270
- const { winners, losers } = await extractWinners(participants, option);
271
-
272
- const prize =
273
- (tossData.amount * (participants?.length ?? 0)) / (winners.length ?? 1);
274
-
275
- try {
276
- for (const winner of winners) {
277
- await walletService.transfer(tempWalletID, winner.address, prize);
278
- await tossDBClient.set(
279
- `toss:${toss_id}`,
280
- JSON.stringify({ ...tossData, status: "closed" }),
281
- );
282
- }
283
- // Clean up
284
- //await walletService.deleteTempWallet(tossWalletRedis, tossId.toString());
285
- if (winners.length > 0) {
286
- await context.reply(generateEndTossMessage(winners, losers, prize));
287
- }
288
-
289
- await context.sendTo(
290
- `You received $${prize} from the toss! Check your balance with /balance`,
291
- winners.map((w) => w.address),
292
- );
293
- } catch (error) {
294
- await context.reply(`Failed to send prize to ${winners.length} winners`);
295
- }
296
- }
297
-
298
- export async function handleCancelToss(context: XMTPContext) {
299
- const tossData = await checkTossCorrect(context);
300
- if (!tossData) return;
301
-
302
- const { toss_id, admin_address, participants, amount } = tossData;
303
-
304
- const {
305
- message: { sender },
306
- walletService,
307
- } = context;
308
-
309
- const tossDBClient = await getRedisClient();
310
- if (participants?.length === 0) {
311
- await context.reply("No participants for this toss.");
312
- return;
313
- } else if (admin_address.toLowerCase() !== sender.address.toLowerCase()) {
314
- await context.reply("Only the admin can cancel the toss.");
315
- return;
316
- }
317
-
318
- let tempWalletID = toss_id + ":" + admin_address;
319
- const balance = await walletService.checkBalance(tempWalletID);
320
- const fundsNeeded = tossData.amount * participants?.length;
321
- if (balance < fundsNeeded) {
322
- await context.reply(
323
- `Toss wallet does not have enough funds ${fundsNeeded}, has ${balance}`,
324
- );
325
- return;
326
- }
327
- for (const participant of participants) {
328
- try {
329
- await walletService.transfer(tempWalletID, participant.address, amount);
330
- } catch (error) {
331
- console.error(
332
- `Failed to send prize to ${participant.address} agent wallet:`,
333
- error,
334
- );
335
- await context.reply(
336
- `Failed to send prize to ${participant.address} agent wallet`,
337
- );
338
- }
339
- }
340
-
341
- // Clean up
342
- //await walletService.deleteTempWallet(tossWalletRedis, tossId.toString());
343
-
344
- await tossDBClient.set(
345
- `toss:${toss_id}`,
346
- JSON.stringify({ ...tossData, status: "cancelled" }),
347
- );
348
-
349
- await context.reply(
350
- `Toss cancelled successfully.\nFunds distributed to participants:\n
351
- ${participants?.map((p) => `${p.name} - $${amount}`).join("\n")}`,
352
- );
353
- }
354
- export async function handleTossStatus(context: XMTPContext) {
355
- const tossData = await checkTossCorrect(context);
356
- if (!tossData) return;
357
- await context.reply(await generateTossStatusMessage(tossData));
358
- }
359
-
360
- export async function handleDM(context: XMTPContext) {
361
- const {
362
- message: {
363
- content: {
364
- skill,
365
- params: { amount },
366
- },
367
- sender,
368
- },
369
- group,
370
- walletService,
371
- } = context;
372
- if (group && skill == "help") {
373
- await context.reply("Check your DM's");
374
- await context.sendTo(DM_HELP_MESSAGE, [sender.address]);
375
- return;
376
- }
377
- if (skill === "help") {
378
- await context.send(DM_HELP_MESSAGE);
379
- } else if (skill === "create") {
380
- const walletExist = await walletService.getWallet(sender.address);
381
- if (walletExist) {
382
- await context.reply("You already have an agent wallet.");
383
- return;
384
- }
385
- await walletService.createWallet(sender.address);
386
- } else if (skill === "balance") {
387
- const userWallet = await walletService.getWallet(sender.address);
388
-
389
- context.sendTo(
390
- `Your agent wallet for address is ${sender.address}\nBalance: $${await walletService.checkBalance(sender.address)}`,
391
- [sender.address],
392
- );
393
- } else if (skill === "fund") {
394
- const balance = await walletService.checkBalance(sender.address);
395
- if (balance === 10) {
396
- await context.reply("You have maxed out your funds.");
397
- return;
398
- } else if (amount) {
399
- if (amount + balance <= 10) {
400
- return walletService.requestFunds(Number(amount));
401
- } else {
402
- await context.send("Wrong amount. Max 10 USDC.");
403
- return;
404
- }
405
- }
406
- await context.reply(
407
- `You have $${balance} in your account. You can fund up to $${10 - balance} more.`,
408
- );
409
- const options = Array.from({ length: Math.floor(10 - balance) }, (_, i) =>
410
- (i + 1).toString(),
411
- );
412
- const response = await context.awaitResponse(
413
- `Please specify the amount of USDC to prefund (1 to ${10 - balance}):`,
414
- options,
415
- );
416
- return walletService.requestFunds(Number(response));
417
- } else if (skill === "withdraw") {
418
- const balance = await walletService.checkBalance(sender.address);
419
- if (balance === 0) {
420
- await context.reply("You have no funds to withdraw.");
421
- return;
422
- }
423
- const options = Array.from({ length: Math.floor(balance) }, (_, i) =>
424
- (i + 1).toString(),
425
- );
426
- const response = await context.awaitResponse(
427
- `Please specify the amount of USDC to withdraw (1 to ${balance}):`,
428
- options,
429
- );
430
- await walletService.withdrawFunds(Number(response));
431
- }
432
- }
package/templates.json DELETED
@@ -1,58 +0,0 @@
1
- [
2
- {
3
- "href": "/templates/ens",
4
- "title": "ENS Agent",
5
- "description": "A template for working with ENS domains.",
6
- "icon": "🔗",
7
- "author": "humanagent"
8
- },
9
- {
10
- "href": "/templates/simple",
11
- "title": "Simple Template",
12
- "description": "A simple template without skills.",
13
- "icon": "🤖",
14
- "author": "humanagent"
15
- },
16
- {
17
- "href": "/templates/coinbase-agent",
18
- "title": "Coinbase Agent",
19
- "description": "A template for a Coinbase features.",
20
- "icon": "💰",
21
- "author": "humanagent"
22
- },
23
- {
24
- "href": "/templates/thegeneralstore",
25
- "title": "The General Store",
26
- "description": "All the goodies needed in a hackathon.",
27
- "icon": "🏪",
28
- "author": "humanagent"
29
- },
30
- {
31
- "href": "/templates/faucet",
32
- "title": "Faucet Agent",
33
- "description": "A template for requesting testnet funds.",
34
- "icon": "💧",
35
- "author": "humanagent"
36
- },
37
- {
38
- "href": "/templates/gated-group",
39
- "title": "Gated Group",
40
- "description": "A template for a gated group.",
41
- "icon": "🔒",
42
- "author": "humanagent"
43
- },
44
- {
45
- "href": "/templates/gm",
46
- "title": "GM Bot",
47
- "description": "A template for a GM bot.",
48
- "icon": "👑",
49
- "author": "humanagent"
50
- },
51
- {
52
- "href": "/templates/toss",
53
- "title": "Toss",
54
- "description": "A friendly game for groups.",
55
- "icon": "🪙",
56
- "author": "humanagent"
57
- }
58
- ]