create-message-kit 1.1.8-beta.2 → 1.1.8-beta.4

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -79,13 +79,17 @@ async function addPackagejson(destDir, name, pkgManager) {
79
79
  dependencies: {
80
80
  "@xmtp/message-kit": "latest",
81
81
  },
82
+ devDependencies: {
83
+ "@types/node": "latest",
84
+ typescript: "latest",
85
+ },
82
86
  engines: {
83
87
  node: ">=20",
84
88
  },
85
89
  };
86
90
 
87
- if (pkgManager.startsWith("yarn")) {
88
- packageTemplate.packageManager = `${pkgManager}`;
91
+ if (pkgManager.includes("yarn")) {
92
+ //packageTemplate.packageManager = `${pkgManager}`;
89
93
  // Add .yarnrc.yml to disable PnP mode
90
94
  }
91
95
 
@@ -101,7 +105,7 @@ async function addPackagejson(destDir, name, pkgManager) {
101
105
 
102
106
  async function gatherProjectInfo() {
103
107
  const templateOptions = [
104
- { value: "gm", label: "GM" },
108
+ { value: "gpt", label: "GPT" },
105
109
  { value: "agent", label: "Agent" },
106
110
  { value: "group", label: "Group" },
107
111
  ];
@@ -203,11 +207,27 @@ yarn-error.log*
203
207
 
204
208
  fs.writeFileSync(resolve(destDir, ".gitignore"), gitignoreContent.trim());
205
209
  }
206
-
207
210
  async function detectPackageManager() {
208
211
  try {
209
- const pkgManager = await detect();
212
+ // Check if running through bun create
213
+ if (process.env.BUN_CREATE === "true" || process.env._?.includes("bun")) {
214
+ return "bun";
215
+ }
216
+
210
217
  const userAgent = process.env.npm_config_user_agent;
218
+
219
+ // Check if running through npm init
220
+ if (userAgent?.startsWith("npm")) {
221
+ return "npm";
222
+ }
223
+
224
+ // Check for Bun in process.argv
225
+ if (process.argv.some((arg) => arg.includes("bun"))) {
226
+ return "bun";
227
+ }
228
+
229
+ // Fallback to detect for other cases
230
+ const pkgManager = await detect();
211
231
  let version = "";
212
232
 
213
233
  if (userAgent && pkgManager === "yarn") {
@@ -219,11 +239,9 @@ async function detectPackageManager() {
219
239
 
220
240
  return pkgManager + version;
221
241
  } catch (error) {
222
- // Fallback to npm if detection fails
223
242
  return "npm";
224
243
  }
225
244
  }
226
-
227
245
  function kebabcase(str) {
228
246
  return str
229
247
  .replace(/([a-z])([A-Z])/g, "$1-$2")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-message-kit",
3
- "version": "1.1.8-beta.2",
3
+ "version": "1.1.8-beta.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -56,6 +56,7 @@ export async function handleEns(
56
56
  }
57
57
  // Generate URL for the ens
58
58
  let url_ens = ensUrl + domain;
59
+ context.send(`${url_ens}`);
59
60
  return { code: 200, message: `${url_ens}` };
60
61
  } else if (skill == "info") {
61
62
  const { domain } = params;
@@ -1,26 +1,14 @@
1
1
  import { run, HandlerContext } from "@xmtp/message-kit";
2
- import { textGeneration, processMultilineResponse } from "@xmtp/message-kit";
2
+ import { agentRun } from "@xmtp/message-kit";
3
3
  import { agent_prompt } from "./prompt.js";
4
4
 
5
5
  run(async (context: HandlerContext) => {
6
6
  const {
7
- message: {
8
- content: { text, params },
9
- sender,
10
- },
7
+ message: { sender },
11
8
  } = context;
12
9
 
13
- try {
14
- let userPrompt = params?.prompt ?? text;
15
-
16
- const { reply } = await textGeneration(
17
- sender.address,
18
- userPrompt,
19
- await agent_prompt(sender.address),
20
- );
21
- await processMultilineResponse(sender.address, reply, context);
22
- } catch (error) {
23
- console.error("Error during OpenAI call:", error);
24
- await context.send("An error occurred while processing your request.");
25
- }
10
+ agentRun(context, async (address: string) => {
11
+ const result = (await agent_prompt(address)) ?? "No response available";
12
+ return result;
13
+ });
26
14
  });
@@ -9,7 +9,6 @@ export const skills: SkillGroup[] = [
9
9
  skills: [
10
10
  {
11
11
  skill: "/register [domain]",
12
- triggers: ["/register"],
13
12
  handler: handleEns,
14
13
  description:
15
14
  "Register a new ENS domain. Returns a URL to complete the registration process.",
@@ -22,7 +21,6 @@ export const skills: SkillGroup[] = [
22
21
  },
23
22
  {
24
23
  skill: "/info [domain]",
25
- triggers: ["/info"],
26
24
  handler: handleEns,
27
25
  description:
28
26
  "Get detailed information about an ENS domain including owner, expiry date, and resolver.",
@@ -35,7 +33,6 @@ export const skills: SkillGroup[] = [
35
33
  },
36
34
  {
37
35
  skill: "/renew [domain]",
38
- triggers: ["/renew"],
39
36
  handler: handleEns,
40
37
  description:
41
38
  "Extend the registration period of your ENS domain. Returns a URL to complete the renewal.",
@@ -48,7 +45,6 @@ export const skills: SkillGroup[] = [
48
45
  },
49
46
  {
50
47
  skill: "/check [domain]",
51
- triggers: ["/check"],
52
48
  handler: handleEns,
53
49
  examples: ["/check vitalik.eth", "/check fabri.base.eth"],
54
50
  description: "Check if a domain is available.",
@@ -60,7 +56,6 @@ export const skills: SkillGroup[] = [
60
56
  },
61
57
  {
62
58
  skill: "/cool [domain]",
63
- triggers: ["/cool"],
64
59
  examples: ["/cool vitalik.eth"],
65
60
  handler: handleEns,
66
61
  description: "Get cool alternatives for a .eth domain.",
@@ -72,7 +67,6 @@ export const skills: SkillGroup[] = [
72
67
  },
73
68
  {
74
69
  skill: "/reset",
75
- triggers: ["/reset"],
76
70
  examples: ["/reset"],
77
71
  handler: handleEns,
78
72
  description: "Reset the conversation.",
@@ -81,7 +75,6 @@ export const skills: SkillGroup[] = [
81
75
  {
82
76
  skill: "/tip [address]",
83
77
  description: "Show a URL for tipping a domain owner.",
84
- triggers: ["/tip"],
85
78
  handler: handleEns,
86
79
  examples: ["/tip 0x1234567890123456789012345678901234567890"],
87
80
  params: {
@@ -0,0 +1,2 @@
1
+ KEY= # the private key of the agent wallet
2
+ OPEN_AI_API_KEY= # the API key for OpenAI
@@ -0,0 +1,38 @@
1
+ import {
2
+ run,
3
+ HandlerContext,
4
+ textGeneration,
5
+ processMultilineResponse,
6
+ } from "@xmtp/message-kit";
7
+ import { agent_prompt } from "./prompt.js";
8
+
9
+ if (!process.env.OPEN_AI_API_KEY) {
10
+ console.error("OPEN_AI_API_KEY is not set");
11
+ }
12
+
13
+ run(async (context: HandlerContext) => {
14
+ if (!process.env.OPEN_AI_API_KEY) {
15
+ context.send("gm");
16
+ return;
17
+ }
18
+
19
+ const {
20
+ message: {
21
+ content: { text, params },
22
+ sender,
23
+ },
24
+ } = context;
25
+
26
+ try {
27
+ let userPrompt = params?.prompt ?? text;
28
+ const { reply } = await textGeneration(
29
+ sender.address,
30
+ userPrompt,
31
+ await agent_prompt(sender.address),
32
+ );
33
+ await processMultilineResponse(sender.address, reply, context);
34
+ } catch (error) {
35
+ console.error("Error during OpenAI call:", error);
36
+ await context.send("An error occurred while processing your request.");
37
+ }
38
+ });
@@ -0,0 +1,20 @@
1
+ import { defaultPromptTemplate } from "@xmtp/message-kit";
2
+
3
+ export async function agent_prompt(senderAddress: string) {
4
+ let fineTunedPrompt = `
5
+
6
+ ### Context
7
+
8
+ You are a helpful agent that lives inside a web3 messaging group that helps interpret user requests and execute commands.
9
+ The message was sent by @${senderAddress}
10
+
11
+
12
+ Important:
13
+ - If a user asks jokes, make jokes about web3 devs\n
14
+ - 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.
15
+ - Populate the command with the correct or random values. Always return commands with real values only, using usernames with @ and excluding addresses.\n
16
+ - 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
17
+ - If the user is grateful, respond asking for a tip in a playful manner.
18
+ `;
19
+ return defaultPromptTemplate(fineTunedPrompt, senderAddress, [], "@bot");
20
+ }
@@ -12,7 +12,6 @@ export const skills: SkillGroup[] = [
12
12
  skills: [
13
13
  {
14
14
  skill: "/tip [usernames] [amount] [token]",
15
- triggers: ["/tip"],
16
15
  examples: ["/tip @vitalik 10 usdc"],
17
16
  description: "Tip users in a specified token.",
18
17
  handler: tipping,
@@ -35,7 +34,6 @@ export const skills: SkillGroup[] = [
35
34
  },
36
35
  {
37
36
  skill: "/pay [amount] [token] [username]",
38
- triggers: ["/pay"],
39
37
  examples: ["/pay 10 usdc vitalik.eth", "/pay 1 @alix"],
40
38
  description:
41
39
  "Send a specified amount of a cryptocurrency to a destination address.",
@@ -58,7 +56,6 @@ export const skills: SkillGroup[] = [
58
56
  },
59
57
  {
60
58
  skill: "/game [game]",
61
- triggers: ["/game", "🔎", "🔍"],
62
59
  handler: games,
63
60
  description: "Play a game.",
64
61
  examples: ["/game wordle", "/game slot", "/game help"],
@@ -72,7 +69,6 @@ export const skills: SkillGroup[] = [
72
69
  },
73
70
  {
74
71
  skill: "/help",
75
- triggers: ["/help"],
76
72
  examples: ["/help"],
77
73
  handler: help,
78
74
  description: "Get help with the bot.",
@@ -83,7 +79,6 @@ export const skills: SkillGroup[] = [
83
79
  adminOnly: true,
84
80
  examples: ["/id"],
85
81
  handler: help,
86
- triggers: ["/id"],
87
82
  description: "Get the group ID.",
88
83
  params: {},
89
84
  },
@@ -1 +0,0 @@
1
- KEY= # the private key of the agent wallet
@@ -1,5 +0,0 @@
1
- import { run, HandlerContext } from "@xmtp/message-kit";
2
-
3
- run(async (context: HandlerContext) => {
4
- context.send("gm");
5
- });