@xmtp/agent-sdk 1.2.3 → 1.2.4
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.
|
@@ -4,8 +4,8 @@ import type { MessageContext } from "../core/MessageContext.js";
|
|
|
4
4
|
/** Content type supported by the "CommandRouter" */
|
|
5
5
|
type SupportedType = ReturnType<TextCodec["decode"]>;
|
|
6
6
|
export declare class CommandRouter {
|
|
7
|
-
private
|
|
8
|
-
|
|
7
|
+
#private;
|
|
8
|
+
get commandList(): string[];
|
|
9
9
|
command(command: string, handler: AgentMessageHandler<SupportedType>): this;
|
|
10
10
|
default(handler: AgentMessageHandler<SupportedType>): this;
|
|
11
11
|
handle(ctx: MessageContext<SupportedType>): Promise<boolean>;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
export class CommandRouter {
|
|
2
|
-
commandMap = new Map();
|
|
3
|
-
defaultHandler = null;
|
|
2
|
+
#commandMap = new Map();
|
|
3
|
+
#defaultHandler = null;
|
|
4
|
+
get commandList() {
|
|
5
|
+
return Array.from(this.#commandMap.keys());
|
|
6
|
+
}
|
|
4
7
|
command(command, handler) {
|
|
5
8
|
if (!command.startsWith("/")) {
|
|
6
9
|
throw new Error('Command must start with "/"');
|
|
7
10
|
}
|
|
8
|
-
this
|
|
11
|
+
this.#commandMap.set(command.toLowerCase(), handler);
|
|
9
12
|
return this;
|
|
10
13
|
}
|
|
11
14
|
default(handler) {
|
|
12
|
-
this
|
|
15
|
+
this.#defaultHandler = handler;
|
|
13
16
|
return this;
|
|
14
17
|
}
|
|
15
18
|
async handle(ctx) {
|
|
@@ -21,7 +24,7 @@ export class CommandRouter {
|
|
|
21
24
|
}
|
|
22
25
|
// Check if this is a command message
|
|
23
26
|
if (command.startsWith("/")) {
|
|
24
|
-
const handler = this
|
|
27
|
+
const handler = this.#commandMap.get(command);
|
|
25
28
|
if (handler) {
|
|
26
29
|
// Create a new context with modified content (everything after the command)
|
|
27
30
|
const argsText = parts.slice(1).join(" ");
|
|
@@ -31,8 +34,8 @@ export class CommandRouter {
|
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
// If no command matched and there's a default handler, use it
|
|
34
|
-
if (this
|
|
35
|
-
await this
|
|
37
|
+
if (this.#defaultHandler) {
|
|
38
|
+
await this.#defaultHandler(ctx);
|
|
36
39
|
return true;
|
|
37
40
|
}
|
|
38
41
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandRouter.js","sourceRoot":"","sources":["../../src/middleware/CommandRouter.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"CommandRouter.js","sourceRoot":"","sources":["../../src/middleware/CommandRouter.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,aAAa;IACxB,WAAW,GAAG,IAAI,GAAG,EAA8C,CAAC;IACpE,eAAe,GAA8C,IAAI,CAAC;IAElE,IAAI,WAAW;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,CAAC,OAAe,EAAE,OAA2C;QAClE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,OAA2C;QACjD,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAkC;QAC7C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;QACxC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,C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k",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "XMTP Agent SDK for interacting with XMTP networks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -57,8 +57,7 @@
|
|
|
57
57
|
"build": "yarn clean:dist && tsc -p tsconfig.build.json && tsc-alias && attw --pack --profile node16 . --ignore-rules cjs-resolves-to-esm",
|
|
58
58
|
"clean": "rm -rf .turbo && rm -rf node_modules && yarn clean:dist",
|
|
59
59
|
"clean:dist": "rm -rf dist",
|
|
60
|
-
"
|
|
61
|
-
"dev": "tsx --watch src/demo.ts",
|
|
60
|
+
"dev": "tsx watch src/demo.ts",
|
|
62
61
|
"fix": "npx prettier --log-level error -w . && npx eslint . --fix",
|
|
63
62
|
"gen:keys": "tsx src/bin/generateKeys.ts",
|
|
64
63
|
"start": "yarn demo",
|