@xmtp/agent-sdk 0.0.9 → 0.0.11
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.
- package/README.md +63 -7
- package/dist/bin/generateKeys.js +11 -1
- package/dist/bin/generateKeys.js.map +1 -1
- package/dist/core/Agent.js +12 -11
- package/dist/core/Agent.js.map +1 -1
- package/dist/middleware/CommandRouter.js +2 -2
- package/dist/middleware/CommandRouter.js.map +1 -1
- package/dist/utils/filter.d.ts +54 -14
- package/dist/utils/filter.js +63 -21
- package/dist/utils/filter.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/utils/crypto.d.ts +0 -19
- package/dist/utils/crypto.js +0 -43
- package/dist/utils/crypto.js.map +0 -1
- package/dist/utils/message.d.ts +0 -38
- package/dist/utils/message.js +0 -31
- package/dist/utils/message.js.map +0 -1
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ Subscribe only to what you need using Node’s `EventEmitter` interface. Events
|
|
|
108
108
|
```ts
|
|
109
109
|
// Handle different message types
|
|
110
110
|
agent.on("text", async (ctx) => {
|
|
111
|
-
console.log(`Text message: ${ctx.
|
|
111
|
+
console.log(`Text message: ${ctx.message.content}`);
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
agent.on("reaction", async (ctx) => {
|
|
@@ -138,18 +138,74 @@ agent.on("unhandledError", (error) => {
|
|
|
138
138
|
|
|
139
139
|
Extend your agent with custom business logic using middlewares. Compose cross-cutting behavior like routing, telemetry, rate limiting, analytics, and feature flags, or plug in your own.
|
|
140
140
|
|
|
141
|
+
#### Standard Middleware
|
|
142
|
+
|
|
143
|
+
Middlewares can be registered with `agent.use` either one at a time or as an array. They are executed in the order they were added.
|
|
144
|
+
|
|
145
|
+
Middleware functions receive a `ctx` (context) object and a `next` function. Normally, a middleware calls `next()` to hand off control to the next one in the chain. However, a middleware can also alter the flow in the following ways:
|
|
146
|
+
|
|
147
|
+
1. Use `next()` to continue the chain and pass control to the next middleware
|
|
148
|
+
2. Use `return` to stop the chain and prevent events from firing
|
|
149
|
+
3. Use `throw` to trigger the error-handling middleware chain
|
|
150
|
+
|
|
141
151
|
**Example**
|
|
142
152
|
|
|
143
153
|
```ts
|
|
144
|
-
import {
|
|
154
|
+
import { Agent, AgentMiddleware } from "@xmtp/agent-sdk";
|
|
145
155
|
|
|
146
|
-
const
|
|
156
|
+
const onlyText: AgentMiddleware = async (ctx, next) => {
|
|
157
|
+
if (typeof ctx.message.content === "string") {
|
|
158
|
+
// Continue to next middleware
|
|
159
|
+
await next();
|
|
160
|
+
}
|
|
161
|
+
// Break middleware chain
|
|
162
|
+
return;
|
|
163
|
+
};
|
|
147
164
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
165
|
+
const agent = await Agent.createFromEnv();
|
|
166
|
+
agent.use(onlyText);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Error-Handling Middleware
|
|
170
|
+
|
|
171
|
+
Error middleware can be registered with `agent.errors.use` either one at a time or as an array. They are executed in the order they were added.
|
|
172
|
+
|
|
173
|
+
Error middleware receives the `error`, `ctx`, and a `next` function. Just like regular middleware, the flow in error middleware depends on how to use `next`:
|
|
174
|
+
|
|
175
|
+
1. Use `next()` to mark the error as handled and continue with the main middleware chain
|
|
176
|
+
2. Use `next(error)` to forward the original (or transformed) error to the next error handler
|
|
177
|
+
3. Use `return` to end error handling and stop the middleware chain
|
|
178
|
+
4. Use `throw` to raise a new error to be caught by the error chain
|
|
179
|
+
|
|
180
|
+
**Example**
|
|
151
181
|
|
|
152
|
-
|
|
182
|
+
```ts
|
|
183
|
+
import { Agent, AgentErrorMiddleware } from "@xmtp/agent-sdk";
|
|
184
|
+
|
|
185
|
+
const errorHandler: AgentErrorMiddleware = async (error, ctx, next) => {
|
|
186
|
+
if (error instanceof Error) {
|
|
187
|
+
// Transform the error and pass it along
|
|
188
|
+
await next(`Validation failed: ${error.message}`);
|
|
189
|
+
} else {
|
|
190
|
+
// Let other error handlers deal with it
|
|
191
|
+
await next(error);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const agent = await Agent.createFromEnv();
|
|
196
|
+
agent.errors.use(errorHandler);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### Default Error Handler
|
|
200
|
+
|
|
201
|
+
Any error not handled by custom error middleware is caught by the default error handler and published to the `unhandledError` topic, where it can be observed.
|
|
202
|
+
|
|
203
|
+
**Example**
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
agent.on("unhandledError", (error) => {
|
|
207
|
+
console.log("Caught error", error);
|
|
208
|
+
});
|
|
153
209
|
```
|
|
154
210
|
|
|
155
211
|
### 3. Built‑in Filters
|
package/dist/bin/generateKeys.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { getRandomValues } from "node:crypto";
|
|
2
3
|
import { writeFileSync } from "node:fs";
|
|
3
4
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
5
|
+
import { toString } from "uint8arrays";
|
|
6
|
+
import { generatePrivateKey } from "viem/accounts";
|
|
7
|
+
const generateClientKeys = () => {
|
|
8
|
+
const walletKey = generatePrivateKey();
|
|
9
|
+
const dbEncryptionKey = toString(getRandomValues(new Uint8Array(32)), "hex");
|
|
10
|
+
return {
|
|
11
|
+
XMTP_DB_ENCRYPTION_KEY: dbEncryptionKey,
|
|
12
|
+
XMTP_WALLET_KEY: walletKey,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
5
15
|
/**
|
|
6
16
|
* Generates client keys and saves them to a .env file in the project root.
|
|
7
17
|
* This script creates the necessary environment variables for XMTP agent initialization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateKeys.js","sourceRoot":"","sources":["../../src/bin/generateKeys.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EA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AC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEvD,aAAa,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QAE/C,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC;QAC3E,OAAO,CAAC,GAAG,CAAC,qBAAqB,WAAW,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/core/Agent.js
CHANGED
|
@@ -3,10 +3,9 @@ import { ReactionCodec } from "@xmtp/content-type-reaction";
|
|
|
3
3
|
import { RemoteAttachmentCodec } from "@xmtp/content-type-remote-attachment";
|
|
4
4
|
import { ReplyCodec } from "@xmtp/content-type-reply";
|
|
5
5
|
import { ApiUrls, Client, Dm, Group, } from "@xmtp/node-sdk";
|
|
6
|
+
import { fromString } from "uint8arrays/from-string";
|
|
6
7
|
import { isHex } from "viem/utils";
|
|
7
|
-
import { getEncryptionKeyFromHex } from "../utils/crypto.js";
|
|
8
8
|
import { filter } from "../utils/filter.js";
|
|
9
|
-
import { hasDefinedContent, isReaction, isRemoteAttachment, isReply, isText, } from "../utils/message.js";
|
|
10
9
|
import { createSigner, createUser } from "../utils/user.js";
|
|
11
10
|
import { ConversationContext } from "./ConversationContext.js";
|
|
12
11
|
import { AgentContext } from "./MessageContext.js";
|
|
@@ -72,7 +71,7 @@ export class Agent extends EventEmitter {
|
|
|
72
71
|
const signer = createSigner(createUser(process.env.XMTP_WALLET_KEY));
|
|
73
72
|
const initializedOptions = { ...(options ?? {}) };
|
|
74
73
|
if (process.env.XMTP_DB_ENCRYPTION_KEY) {
|
|
75
|
-
initializedOptions.dbEncryptionKey =
|
|
74
|
+
initializedOptions.dbEncryptionKey = fromString(process.env.XMTP_DB_ENCRYPTION_KEY, "hex");
|
|
76
75
|
}
|
|
77
76
|
if (process.env.XMTP_ENV &&
|
|
78
77
|
Object.keys(ApiUrls).includes(process.env.XMTP_ENV)) {
|
|
@@ -134,16 +133,16 @@ export class Agent extends EventEmitter {
|
|
|
134
133
|
break;
|
|
135
134
|
try {
|
|
136
135
|
switch (true) {
|
|
137
|
-
case isRemoteAttachment(message):
|
|
136
|
+
case filter.isRemoteAttachment(message):
|
|
138
137
|
await this.#processMessage(message, "attachment");
|
|
139
138
|
break;
|
|
140
|
-
case isReaction(message):
|
|
139
|
+
case filter.isReaction(message):
|
|
141
140
|
await this.#processMessage(message, "reaction");
|
|
142
141
|
break;
|
|
143
|
-
case isReply(message):
|
|
142
|
+
case filter.isReply(message):
|
|
144
143
|
await this.#processMessage(message, "reply");
|
|
145
144
|
break;
|
|
146
|
-
case isText(message):
|
|
145
|
+
case filter.isText(message):
|
|
147
146
|
await this.#processMessage(message, "text");
|
|
148
147
|
break;
|
|
149
148
|
default:
|
|
@@ -171,7 +170,11 @@ export class Agent extends EventEmitter {
|
|
|
171
170
|
}
|
|
172
171
|
async #processMessage(message, topic = "unhandledMessage") {
|
|
173
172
|
// Skip messages with undefined content (failed to decode)
|
|
174
|
-
if (!hasDefinedContent(message)) {
|
|
173
|
+
if (!filter.hasDefinedContent(message)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// Skip messages from agent itself
|
|
177
|
+
if (filter.fromSelf(message, this.#client)) {
|
|
175
178
|
return;
|
|
176
179
|
}
|
|
177
180
|
let context = null;
|
|
@@ -185,9 +188,7 @@ export class Agent extends EventEmitter {
|
|
|
185
188
|
async #runMiddlewareChain(context, topic = "unhandledMessage") {
|
|
186
189
|
const finalEmit = async () => {
|
|
187
190
|
try {
|
|
188
|
-
|
|
189
|
-
this.emit(topic, context);
|
|
190
|
-
}
|
|
191
|
+
this.emit(topic, context);
|
|
191
192
|
}
|
|
192
193
|
catch (error) {
|
|
193
194
|
await this.#runErrorChain(error, context);
|
package/dist/core/Agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Agent.js","sourceRoot":"","sources":["../../src/core/Agent.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EACL,OAAO,EACP,MAAM,EACN,EAAE,EACF,KAAK,GAKN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Agent.js","sourceRoot":"","sources":["../../src/core/Agent.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EACL,OAAO,EACP,MAAM,EACN,EAAE,EACF,KAAK,GAKN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;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AG,MAAM,IAAI,CAAC,gBAAgB,CACzC,KAAK,CAAC,CAAC,CAAC,EACR,OAAO,EACP,YAAY,CACb,CAAC;YAEF,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;gBACrB,KAAK,SAAS;oBACZ,mDAAmD;oBACnD,OAAO,IAAI,CAAC;gBACd,KAAK,SAAS;oBACZ,2DAA2D;oBAC3D,OAAO,KAAK,CAAC;gBACf,KAAK,UAAU;oBACb,sCAAsC;oBACtC,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;YACjC,CAAC;QACH,CAAC;QAED,wCAAwC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filter } from "../utils/filter.js";
|
|
2
2
|
export class CommandRouter {
|
|
3
3
|
commandMap = new Map();
|
|
4
4
|
defaultHandler = null;
|
|
@@ -14,7 +14,7 @@ export class CommandRouter {
|
|
|
14
14
|
return this;
|
|
15
15
|
}
|
|
16
16
|
async handle(ctx) {
|
|
17
|
-
if (!isText(ctx.message)) {
|
|
17
|
+
if (!filter.isText(ctx.message)) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
const messageText = ctx.message.content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandRouter.js","sourceRoot":"","sources":["../../src/middleware/CommandRouter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
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YACd,CAAC;QACH,CAAC;QAED,8DAA8D;QAC9D,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,UAAU,GAAwC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC1E,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;IACH,CAAC,CAAC;CACH"}
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Reaction } from "@xmtp/content-type-reaction";
|
|
2
|
+
import { type RemoteAttachment } from "@xmtp/content-type-remote-attachment";
|
|
3
|
+
import { type Reply } from "@xmtp/content-type-reply";
|
|
4
|
+
import type { Client, Conversation, DecodedMessage } from "@xmtp/node-sdk";
|
|
2
5
|
import type { AgentContext } from "../core/MessageContext.js";
|
|
3
|
-
|
|
4
|
-
* Function type for filtering messages based on content and client state.
|
|
5
|
-
*/
|
|
6
|
-
export type MessageFilter<ContentTypes> = (message: DecodedMessage, client: Client<ContentTypes>) => boolean;
|
|
6
|
+
export type MessageFilter<ContentTypes> = (message: DecodedMessage, client: Client<ContentTypes>, conversation: Conversation) => boolean | Promise<boolean>;
|
|
7
7
|
/**
|
|
8
8
|
* Creates a filter for messages from specific senders
|
|
9
9
|
*
|
|
10
10
|
* @param senderInboxId - Single sender ID or array of sender IDs to match
|
|
11
11
|
* @returns Filter function
|
|
12
12
|
*/
|
|
13
|
-
declare function fromSender
|
|
13
|
+
declare function fromSender(senderInboxId: string | string[]): (message: DecodedMessage) => boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Creates a filter that matches text messages starting with a specific string.
|
|
16
16
|
*
|
|
17
17
|
* @param prefix - The string prefix to match against
|
|
18
18
|
* @returns Filter function
|
|
19
19
|
*/
|
|
20
|
-
declare function startsWith
|
|
20
|
+
declare function startsWith(prefix: string): (message: DecodedMessage) => boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Creates a filter that requires all provided filters to pass
|
|
23
23
|
*
|
|
@@ -43,9 +43,29 @@ declare function not<ContentTypes>(filter: MessageFilter<ContentTypes>): Message
|
|
|
43
43
|
* Pre-configured filter instances and factory functions for common filtering scenarios
|
|
44
44
|
*/
|
|
45
45
|
export declare const filter: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
fromSelf: (message: DecodedMessage, client: Client<unknown>) => boolean;
|
|
47
|
+
hasDefinedContent: (message: DecodedMessage) => message is DecodedMessage<unknown> & {
|
|
48
|
+
content: {};
|
|
49
|
+
};
|
|
50
|
+
isDM: MessageFilter<unknown>;
|
|
51
|
+
isGroup: MessageFilter<unknown>;
|
|
52
|
+
isReaction: (message: DecodedMessage) => message is DecodedMessage & {
|
|
53
|
+
content: Reaction;
|
|
54
|
+
};
|
|
55
|
+
isRemoteAttachment: (message: DecodedMessage) => message is DecodedMessage & {
|
|
56
|
+
content: RemoteAttachment;
|
|
57
|
+
};
|
|
58
|
+
isReply: (message: DecodedMessage) => message is DecodedMessage & {
|
|
59
|
+
content: Reply;
|
|
60
|
+
};
|
|
61
|
+
isText: (message: DecodedMessage) => message is DecodedMessage & {
|
|
62
|
+
content: string;
|
|
63
|
+
};
|
|
64
|
+
isTextReply: (message: DecodedMessage) => message is DecodedMessage & {
|
|
65
|
+
content: Reply & {
|
|
66
|
+
content: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
49
69
|
fromSender: typeof fromSender;
|
|
50
70
|
startsWith: typeof startsWith;
|
|
51
71
|
and: typeof and;
|
|
@@ -53,14 +73,34 @@ export declare const filter: {
|
|
|
53
73
|
not: typeof not;
|
|
54
74
|
};
|
|
55
75
|
export declare const f: {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
fromSelf: (message: DecodedMessage, client: Client<unknown>) => boolean;
|
|
77
|
+
hasDefinedContent: (message: DecodedMessage) => message is DecodedMessage<unknown> & {
|
|
78
|
+
content: {};
|
|
79
|
+
};
|
|
80
|
+
isDM: MessageFilter<unknown>;
|
|
81
|
+
isGroup: MessageFilter<unknown>;
|
|
82
|
+
isReaction: (message: DecodedMessage) => message is DecodedMessage & {
|
|
83
|
+
content: Reaction;
|
|
84
|
+
};
|
|
85
|
+
isRemoteAttachment: (message: DecodedMessage) => message is DecodedMessage & {
|
|
86
|
+
content: RemoteAttachment;
|
|
87
|
+
};
|
|
88
|
+
isReply: (message: DecodedMessage) => message is DecodedMessage & {
|
|
89
|
+
content: Reply;
|
|
90
|
+
};
|
|
91
|
+
isText: (message: DecodedMessage) => message is DecodedMessage & {
|
|
92
|
+
content: string;
|
|
93
|
+
};
|
|
94
|
+
isTextReply: (message: DecodedMessage) => message is DecodedMessage & {
|
|
95
|
+
content: Reply & {
|
|
96
|
+
content: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
59
99
|
fromSender: typeof fromSender;
|
|
60
100
|
startsWith: typeof startsWith;
|
|
61
101
|
and: typeof and;
|
|
62
102
|
or: typeof or;
|
|
63
103
|
not: typeof not;
|
|
64
104
|
};
|
|
65
|
-
export declare const withFilter: <ContentTypes>(
|
|
105
|
+
export declare const withFilter: <ContentTypes>(filterFn: MessageFilter<ContentTypes>, listener: (ctx: AgentContext<ContentTypes>) => void | Promise<void>) => (ctx: AgentContext<ContentTypes>) => Promise<void>;
|
|
66
106
|
export {};
|
package/dist/utils/filter.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
+
import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
2
|
+
import { ContentTypeRemoteAttachment, } from "@xmtp/content-type-remote-attachment";
|
|
3
|
+
import { ContentTypeReply } from "@xmtp/content-type-reply";
|
|
1
4
|
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
2
|
-
import { getTextContent } from "./message.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a filter that excludes messages from the agent itself.
|
|
5
|
-
*
|
|
6
|
-
* @returns Filter function
|
|
7
|
-
*/
|
|
8
|
-
function notFromSelf() {
|
|
9
|
-
return (message, client) => {
|
|
10
|
-
return message.senderInboxId !== client.inboxId;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
5
|
/**
|
|
14
6
|
* Creates a filter that includes only messages from the agent itself.
|
|
15
7
|
*
|
|
@@ -20,6 +12,36 @@ function fromSelf() {
|
|
|
20
12
|
return message.senderInboxId === client.inboxId;
|
|
21
13
|
};
|
|
22
14
|
}
|
|
15
|
+
function hasDefinedContent() {
|
|
16
|
+
return (message) => {
|
|
17
|
+
return !!message.content;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isDM() {
|
|
21
|
+
return async (_message, _client, conversation) => {
|
|
22
|
+
return (await conversation.metadata()).conversationType === "dm";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function isGroup() {
|
|
26
|
+
return async (_message, _client, conversation) => {
|
|
27
|
+
return (await conversation.metadata()).conversationType === "group";
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function isReaction() {
|
|
31
|
+
return (message) => {
|
|
32
|
+
return !!message.contentType?.sameAs(ContentTypeReaction);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function isReply() {
|
|
36
|
+
return (message) => {
|
|
37
|
+
return !!message.contentType?.sameAs(ContentTypeReply);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function isRemoteAttachment() {
|
|
41
|
+
return (message) => {
|
|
42
|
+
return !!message.contentType?.sameAs(ContentTypeRemoteAttachment);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
23
45
|
/**
|
|
24
46
|
* Creates a filter that includes only text messages.
|
|
25
47
|
*
|
|
@@ -30,6 +52,11 @@ function isText() {
|
|
|
30
52
|
return !!message.contentType?.sameAs(ContentTypeText);
|
|
31
53
|
};
|
|
32
54
|
}
|
|
55
|
+
function isTextReply() {
|
|
56
|
+
return (message) => {
|
|
57
|
+
return isReply()(message) && typeof message.content.content === "string";
|
|
58
|
+
};
|
|
59
|
+
}
|
|
33
60
|
/**
|
|
34
61
|
* Creates a filter for messages from specific senders
|
|
35
62
|
*
|
|
@@ -52,6 +79,15 @@ function fromSender(senderInboxId) {
|
|
|
52
79
|
*/
|
|
53
80
|
function startsWith(prefix) {
|
|
54
81
|
return (message) => {
|
|
82
|
+
const getTextContent = (message) => {
|
|
83
|
+
switch (true) {
|
|
84
|
+
case filter.isReaction(message):
|
|
85
|
+
case filter.isTextReply(message):
|
|
86
|
+
return message.content.content;
|
|
87
|
+
case filter.isText(message):
|
|
88
|
+
return message.content;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
55
91
|
const text = getTextContent(message);
|
|
56
92
|
return !!(text && text.startsWith(prefix));
|
|
57
93
|
};
|
|
@@ -63,9 +99,9 @@ function startsWith(prefix) {
|
|
|
63
99
|
* @returns Filter function
|
|
64
100
|
*/
|
|
65
101
|
function and(...filters) {
|
|
66
|
-
return (message, client) => {
|
|
102
|
+
return async (message, client, conversation) => {
|
|
67
103
|
for (const filter of filters) {
|
|
68
|
-
const result = filter(message, client);
|
|
104
|
+
const result = await filter(message, client, conversation);
|
|
69
105
|
if (!result)
|
|
70
106
|
return false;
|
|
71
107
|
}
|
|
@@ -79,9 +115,9 @@ function and(...filters) {
|
|
|
79
115
|
* @returns Filter function
|
|
80
116
|
*/
|
|
81
117
|
function or(...filters) {
|
|
82
|
-
return (message, client) => {
|
|
118
|
+
return async (message, client, conversation) => {
|
|
83
119
|
for (const filter of filters) {
|
|
84
|
-
const result = filter(message, client);
|
|
120
|
+
const result = await filter(message, client, conversation);
|
|
85
121
|
if (result)
|
|
86
122
|
return true;
|
|
87
123
|
}
|
|
@@ -95,8 +131,8 @@ function or(...filters) {
|
|
|
95
131
|
* @returns Filter function
|
|
96
132
|
*/
|
|
97
133
|
function not(filter) {
|
|
98
|
-
return (message, client) => {
|
|
99
|
-
return !filter(message, client);
|
|
134
|
+
return async (message, client, conversation) => {
|
|
135
|
+
return !(await filter(message, client, conversation));
|
|
100
136
|
};
|
|
101
137
|
}
|
|
102
138
|
/**
|
|
@@ -104,9 +140,15 @@ function not(filter) {
|
|
|
104
140
|
*/
|
|
105
141
|
export const filter = {
|
|
106
142
|
// basic filters
|
|
107
|
-
notFromSelf: notFromSelf(),
|
|
108
143
|
fromSelf: fromSelf(),
|
|
144
|
+
hasDefinedContent: hasDefinedContent(),
|
|
145
|
+
isDM: isDM(),
|
|
146
|
+
isGroup: isGroup(),
|
|
147
|
+
isReaction: isReaction(),
|
|
148
|
+
isRemoteAttachment: isRemoteAttachment(),
|
|
149
|
+
isReply: isReply(),
|
|
109
150
|
isText: isText(),
|
|
151
|
+
isTextReply: isTextReply(),
|
|
110
152
|
// factory functions
|
|
111
153
|
fromSender,
|
|
112
154
|
startsWith,
|
|
@@ -116,9 +158,9 @@ export const filter = {
|
|
|
116
158
|
not,
|
|
117
159
|
};
|
|
118
160
|
export const f = filter;
|
|
119
|
-
export const withFilter = (
|
|
120
|
-
if (
|
|
121
|
-
listener(ctx);
|
|
161
|
+
export const withFilter = (filterFn, listener) => async (ctx) => {
|
|
162
|
+
if (await filterFn(ctx.message, ctx.client, ctx.conversation)) {
|
|
163
|
+
await listener(ctx);
|
|
122
164
|
}
|
|
123
165
|
};
|
|
124
166
|
//# sourceMappingURL=filter.js.map
|
package/dist/utils/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/utils/filter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/utils/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,6BAA6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EAAE,QAAQ,EAAE;IACpB,iBAAiB,EAAE,iBAAiB,EAAE;IACtC,IAAI,EAAE,IAAI,EAAE;IACZ,OAAO,EAAE,OAAO,EAAE;IAClB,UAAU,EAAE,UAAU,EAAE;IACxB,kBAAkB,EAAE,kBAAkB,EAAE;IACxC,OAAO,EAAE,OAAO,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE;IAChB,WAAW,EAAE,WAAW,EAAE;IAC1B,oBAAoB;IACpB,UAAU;IACV,UAAU;IACV,cAAc;IACd,GAAG;IACH,EAAE;IACF,GAAG;CACJ,CAAC;AAEF,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,UAAU,GACrB,CACE,QAAqC,EACrC,QAAmE,EACnE,EAAE,CACJ,KAAK,EAAE,GAA+B,EAAE,EAAE;IACxC,IAAI,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9D,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"dev": "tsx --watch src/main.ts",
|
|
66
66
|
"gen:keys": "tsx src/bin/generateKeys.ts",
|
|
67
67
|
"start": "yarn demo",
|
|
68
|
-
"test": "yarn typecheck && vitest --typecheck",
|
|
68
|
+
"test": "yarn typecheck && vitest run --typecheck",
|
|
69
69
|
"test:cov": "vitest run --coverage",
|
|
70
70
|
"typecheck": "tsc --noEmit"
|
|
71
71
|
},
|
|
72
72
|
"type": "module",
|
|
73
|
-
"version": "0.0.
|
|
73
|
+
"version": "0.0.11"
|
|
74
74
|
}
|
package/dist/utils/crypto.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a hex string to a Uint8Array encryption key.
|
|
3
|
-
* @param hex - The hex string
|
|
4
|
-
* @returns The encryption key
|
|
5
|
-
*/
|
|
6
|
-
export declare const getEncryptionKeyFromHex: (hex: string) => Uint8Array;
|
|
7
|
-
/**
|
|
8
|
-
* Generates a complete set of client keys required for XMTP agent initialization.
|
|
9
|
-
*
|
|
10
|
-
* Creates both a wallet private key for client authentication and a database
|
|
11
|
-
* encryption key for secure local storage. The returned keys can be used
|
|
12
|
-
* directly as environment variables.
|
|
13
|
-
*
|
|
14
|
-
* @returns An object containing the keys
|
|
15
|
-
*/
|
|
16
|
-
export declare const generateClientKeys: () => {
|
|
17
|
-
XMTP_DB_ENCRYPTION_KEY: string;
|
|
18
|
-
XMTP_WALLET_KEY: `0x${string}`;
|
|
19
|
-
};
|
package/dist/utils/crypto.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getRandomValues } from "node:crypto";
|
|
2
|
-
import { fromString, toString } from "uint8arrays";
|
|
3
|
-
import { generatePrivateKey } from "viem/accounts";
|
|
4
|
-
/**
|
|
5
|
-
* Convert a hex string to a Uint8Array encryption key.
|
|
6
|
-
* @param hex - The hex string
|
|
7
|
-
* @returns The encryption key
|
|
8
|
-
*/
|
|
9
|
-
export const getEncryptionKeyFromHex = (hex) => {
|
|
10
|
-
return fromString(hex, "hex");
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Generates a cryptographically secure random encryption key for database encryption.
|
|
14
|
-
*
|
|
15
|
-
* Creates a 256-bit (32-byte) encryption key using the Node.js crypto module's
|
|
16
|
-
* secure random number generator.
|
|
17
|
-
*
|
|
18
|
-
* @returns A hex-encoded encryption key string (64 characters)
|
|
19
|
-
*/
|
|
20
|
-
const generateEncryptionKeyHex = () => {
|
|
21
|
-
/* Generate a random encryption key */
|
|
22
|
-
const uint8Array = getRandomValues(new Uint8Array(32));
|
|
23
|
-
/* Convert the encryption key to a hex string */
|
|
24
|
-
return toString(uint8Array, "hex");
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Generates a complete set of client keys required for XMTP agent initialization.
|
|
28
|
-
*
|
|
29
|
-
* Creates both a wallet private key for client authentication and a database
|
|
30
|
-
* encryption key for secure local storage. The returned keys can be used
|
|
31
|
-
* directly as environment variables.
|
|
32
|
-
*
|
|
33
|
-
* @returns An object containing the keys
|
|
34
|
-
*/
|
|
35
|
-
export const generateClientKeys = () => {
|
|
36
|
-
const walletKey = generatePrivateKey();
|
|
37
|
-
const dbEncryptionKey = generateEncryptionKeyHex();
|
|
38
|
-
return {
|
|
39
|
-
XMTP_DB_ENCRYPTION_KEY: dbEncryptionKey,
|
|
40
|
-
XMTP_WALLET_KEY: walletKey,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=crypto.js.map
|
package/dist/utils/crypto.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAc,EAAE;IACjE,OAAO,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG,GAAG,EAAE;IACpC,sCAAsC;IACtC,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACvD,gDAAgD;IAChD,OAAO,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;IACvC,MAAM,eAAe,GAAG,wBAAwB,EAAE,CAAC;IACnD,OAAO;QACL,sBAAsB,EAAE,eAAe;QACvC,eAAe,EAAE,SAAS;KAC3B,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/utils/message.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { type Reaction } from "@xmtp/content-type-reaction";
|
|
2
|
-
import { type RemoteAttachment } from "@xmtp/content-type-remote-attachment";
|
|
3
|
-
import { type Reply } from "@xmtp/content-type-reply";
|
|
4
|
-
import type { DecodedMessage } from "@xmtp/node-sdk";
|
|
5
|
-
type ContentMessage = Pick<DecodedMessage, "content" | "contentType" | "fallback">;
|
|
6
|
-
export declare const hasDefinedContent: <ContentTypes = unknown>(message: DecodedMessage<ContentTypes>) => message is DecodedMessage<ContentTypes> & {
|
|
7
|
-
content: ContentTypes;
|
|
8
|
-
};
|
|
9
|
-
export declare const isReaction: <M extends ContentMessage>(m: M) => m is M & {
|
|
10
|
-
content: Reaction;
|
|
11
|
-
};
|
|
12
|
-
export declare const isReply: <M extends ContentMessage>(m: M) => m is M & {
|
|
13
|
-
content: Reply;
|
|
14
|
-
};
|
|
15
|
-
export declare const isTextReply: <M extends ContentMessage>(m: M) => m is M & {
|
|
16
|
-
content: Reply & {
|
|
17
|
-
content: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export declare const isText: <M extends ContentMessage>(m: M) => m is M & {
|
|
21
|
-
content: string;
|
|
22
|
-
};
|
|
23
|
-
export declare const isRemoteAttachment: <M extends ContentMessage>(m: M) => m is M & {
|
|
24
|
-
content: RemoteAttachment;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Extracts the text content from various XMTP message types.
|
|
28
|
-
*
|
|
29
|
-
* Supports extracting text from:
|
|
30
|
-
* - Text messages: Returns the direct string content
|
|
31
|
-
* - Text replies: Returns the reply content text
|
|
32
|
-
* - Reactions: Returns the reaction content (emoji/text)
|
|
33
|
-
*
|
|
34
|
-
* @param message - The decoded message to extract text from
|
|
35
|
-
* @returns The text content as a string, or `undefined` for message types that don't contain extractable text content
|
|
36
|
-
*/
|
|
37
|
-
export declare const getTextContent: (message: ContentMessage) => string | undefined;
|
|
38
|
-
export {};
|
package/dist/utils/message.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
2
|
-
import { ContentTypeRemoteAttachment, } from "@xmtp/content-type-remote-attachment";
|
|
3
|
-
import { ContentTypeReply } from "@xmtp/content-type-reply";
|
|
4
|
-
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
5
|
-
export const hasDefinedContent = (message) => message.content !== undefined;
|
|
6
|
-
export const isReaction = (m) => !!m.contentType?.sameAs(ContentTypeReaction);
|
|
7
|
-
export const isReply = (m) => !!m.contentType?.sameAs(ContentTypeReply);
|
|
8
|
-
export const isTextReply = (m) => isReply(m) && typeof m.content.content === "string";
|
|
9
|
-
export const isText = (m) => !!m.contentType?.sameAs(ContentTypeText);
|
|
10
|
-
export const isRemoteAttachment = (m) => !!m.contentType?.sameAs(ContentTypeRemoteAttachment);
|
|
11
|
-
/**
|
|
12
|
-
* Extracts the text content from various XMTP message types.
|
|
13
|
-
*
|
|
14
|
-
* Supports extracting text from:
|
|
15
|
-
* - Text messages: Returns the direct string content
|
|
16
|
-
* - Text replies: Returns the reply content text
|
|
17
|
-
* - Reactions: Returns the reaction content (emoji/text)
|
|
18
|
-
*
|
|
19
|
-
* @param message - The decoded message to extract text from
|
|
20
|
-
* @returns The text content as a string, or `undefined` for message types that don't contain extractable text content
|
|
21
|
-
*/
|
|
22
|
-
export const getTextContent = (message) => {
|
|
23
|
-
switch (true) {
|
|
24
|
-
case isReaction(message):
|
|
25
|
-
case isTextReply(message):
|
|
26
|
-
return message.content.content;
|
|
27
|
-
case isText(message):
|
|
28
|
-
return message.content;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/utils/message.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,2BAA2B,GAE5B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAc,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAqC,EAGrC,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC;AAEnC,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,CAAI,EAC4B,EAAE,CAClC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,CAAI,EACyB,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,CAAI,EAC+C,EAAE,CACrD,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC;AAEtD,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB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