@xmtp/agent-sdk 0.0.12 → 0.0.14
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 +48 -39
- package/dist/core/Agent.d.ts +13 -17
- package/dist/core/Agent.js +14 -40
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/AgentContext.d.ts +9 -0
- package/dist/core/AgentContext.js +2 -0
- package/dist/core/AgentContext.js.map +1 -0
- package/dist/core/ConversationContext.d.ts +3 -1
- package/dist/core/ConversationContext.js +7 -0
- package/dist/core/ConversationContext.js.map +1 -1
- package/dist/core/MessageContext.d.ts +14 -7
- package/dist/core/MessageContext.js +14 -1
- package/dist/core/MessageContext.js.map +1 -1
- package/dist/demo.js +6 -10
- package/dist/demo.js.map +1 -1
- package/dist/utils/filter.d.ts +19 -75
- package/dist/utils/filter.js +51 -158
- package/dist/utils/filter.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -87,16 +87,12 @@ Subscribe only to what you need using Node’s `EventEmitter` interface. Events
|
|
|
87
87
|
|
|
88
88
|
**Message Events**
|
|
89
89
|
|
|
90
|
-
- `
|
|
90
|
+
- `attachment` – a new incoming remote attachment message
|
|
91
|
+
- `message` – all incoming messages (fires for every message regardless of type)
|
|
91
92
|
- `reaction` – a new incoming reaction message
|
|
92
93
|
- `reply` – a new incoming reply message
|
|
93
|
-
- `
|
|
94
|
-
- `
|
|
95
|
-
|
|
96
|
-
**Conversation Events**
|
|
97
|
-
|
|
98
|
-
- `dm` – a new DM conversation
|
|
99
|
-
- `group` – a new group conversation
|
|
94
|
+
- `text` – a new incoming text message
|
|
95
|
+
- `unknownMessage` – a message that doesn't match any specific type
|
|
100
96
|
|
|
101
97
|
**Lifecycle Events**
|
|
102
98
|
|
|
@@ -106,7 +102,7 @@ Subscribe only to what you need using Node’s `EventEmitter` interface. Events
|
|
|
106
102
|
**Example**
|
|
107
103
|
|
|
108
104
|
```ts
|
|
109
|
-
//
|
|
105
|
+
// Listen to specific message types
|
|
110
106
|
agent.on("text", async (ctx) => {
|
|
111
107
|
console.log(`Text message: ${ctx.message.content}`);
|
|
112
108
|
});
|
|
@@ -119,18 +115,28 @@ agent.on("reply", async (ctx) => {
|
|
|
119
115
|
console.log(`Reply to: ${ctx.message.content.reference}`);
|
|
120
116
|
});
|
|
121
117
|
|
|
122
|
-
//
|
|
123
|
-
agent.on("
|
|
124
|
-
|
|
118
|
+
// Listen to unhandled events
|
|
119
|
+
agent.on("unhandledError", (error) => {
|
|
120
|
+
console.error("Agent error", error);
|
|
125
121
|
});
|
|
126
122
|
|
|
127
|
-
agent.on("
|
|
128
|
-
|
|
123
|
+
agent.on("unknownMessage", (ctx) => {
|
|
124
|
+
console.error("Message type is unknown", ctx);
|
|
129
125
|
});
|
|
126
|
+
```
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
> **⚠️ Important:** The `"message"` event fires for **every** incoming message, regardless of type. When using the `"message"` event, always filter message types to prevent infinite loops. Without proper filtering, your agent might respond to its own messages or react to system messages like read receipts.
|
|
129
|
+
|
|
130
|
+
**Best Practice Example**
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { filter } from "@xmtp/agent-sdk";
|
|
134
|
+
|
|
135
|
+
agent.on("message", async (ctx) => {
|
|
136
|
+
// Filter for specific message types
|
|
137
|
+
if (filter.isText(ctx.message)) {
|
|
138
|
+
await ctx.conversation.send(`Echo: ${ctx.message.content}`);
|
|
139
|
+
}
|
|
134
140
|
});
|
|
135
141
|
```
|
|
136
142
|
|
|
@@ -151,10 +157,10 @@ Middleware functions receive a `ctx` (context) object and a `next` function. Nor
|
|
|
151
157
|
**Example**
|
|
152
158
|
|
|
153
159
|
```ts
|
|
154
|
-
import { Agent, AgentMiddleware } from "@xmtp/agent-sdk";
|
|
160
|
+
import { Agent, AgentMiddleware, filter } from "@xmtp/agent-sdk";
|
|
155
161
|
|
|
156
162
|
const onlyText: AgentMiddleware = async (ctx, next) => {
|
|
157
|
-
if (
|
|
163
|
+
if (filter.isText(ctx.message)) {
|
|
158
164
|
// Continue to next middleware
|
|
159
165
|
await next();
|
|
160
166
|
}
|
|
@@ -210,30 +216,30 @@ agent.on("unhandledError", (error) => {
|
|
|
210
216
|
|
|
211
217
|
### 3. Built‑in Filters
|
|
212
218
|
|
|
213
|
-
Instead of manually checking every incoming message, you can
|
|
219
|
+
Instead of manually checking every incoming message, you can use the provided filters.
|
|
214
220
|
|
|
215
221
|
**Example**
|
|
216
222
|
|
|
217
223
|
```ts
|
|
218
|
-
import {
|
|
224
|
+
import { filter } from "@xmtp/agent-sdk";
|
|
219
225
|
|
|
220
226
|
// Using filter in message handler
|
|
221
|
-
agent.on(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await ctx.conversation.send("
|
|
235
|
-
}
|
|
236
|
-
);
|
|
227
|
+
agent.on("text", async (ctx) => {
|
|
228
|
+
if (filter.isText(ctx.message)) {
|
|
229
|
+
await ctx.conversation.send("You sent a text message!");
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// Combine multiple conditions
|
|
234
|
+
agent.on("text", async (ctx) => {
|
|
235
|
+
if (
|
|
236
|
+
filter.hasDefinedContent(ctx.message) &&
|
|
237
|
+
!filter.fromSelf(ctx.message, ctx.client) &&
|
|
238
|
+
filter.isText(ctx.message)
|
|
239
|
+
) {
|
|
240
|
+
await ctx.conversation.send("Valid text message received ✅");
|
|
241
|
+
}
|
|
242
|
+
});
|
|
237
243
|
```
|
|
238
244
|
|
|
239
245
|
For convenience, the `filter` object can also be imported as `f`:
|
|
@@ -243,10 +249,13 @@ For convenience, the `filter` object can also be imported as `f`:
|
|
|
243
249
|
import { filter, f } from "@xmtp/agent-sdk";
|
|
244
250
|
|
|
245
251
|
// Both work the same way:
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
if (f.isText(ctx.message)) {
|
|
253
|
+
// Handle message...
|
|
254
|
+
}
|
|
248
255
|
```
|
|
249
256
|
|
|
257
|
+
**Available Filters:**
|
|
258
|
+
|
|
250
259
|
You can find all available prebuilt filters [here](https://github.com/xmtp/xmtp-js/blob/main/sdks/agent-sdk/src/utils/filter.ts).
|
|
251
260
|
|
|
252
261
|
### 4. Rich Context
|
package/dist/core/Agent.d.ts
CHANGED
|
@@ -4,47 +4,43 @@ import { ReactionCodec } from "@xmtp/content-type-reaction";
|
|
|
4
4
|
import { RemoteAttachmentCodec } from "@xmtp/content-type-remote-attachment";
|
|
5
5
|
import { ReplyCodec } from "@xmtp/content-type-reply";
|
|
6
6
|
import type { TextCodec } from "@xmtp/content-type-text";
|
|
7
|
-
import { Client,
|
|
8
|
-
import {
|
|
7
|
+
import { Client, type ClientOptions } from "@xmtp/node-sdk";
|
|
8
|
+
import type { AgentErrorContext } from "./AgentContext.js";
|
|
9
|
+
import type { ConversationContext } from "./ConversationContext.js";
|
|
9
10
|
import { MessageContext } from "./MessageContext.js";
|
|
10
|
-
|
|
11
|
+
type EventHandlerMap<ContentTypes> = {
|
|
11
12
|
attachment: [
|
|
12
13
|
ctx: MessageContext<ReturnType<RemoteAttachmentCodec["decode"]>>
|
|
13
14
|
];
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
conversation: [ctx: ConversationContext<ContentTypes>];
|
|
16
|
+
message: [ctx: MessageContext<ContentTypes>];
|
|
16
17
|
reaction: [ctx: MessageContext<ReturnType<ReactionCodec["decode"]>>];
|
|
17
18
|
reply: [ctx: MessageContext<ReturnType<ReplyCodec["decode"]>>];
|
|
18
19
|
start: [];
|
|
19
20
|
stop: [];
|
|
20
21
|
text: [ctx: MessageContext<ReturnType<TextCodec["decode"]>>];
|
|
21
22
|
unhandledError: [error: Error];
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
export type AgentErrorContext<ContentTypes = unknown> = {
|
|
25
|
-
message?: DecodedMessage<ContentTypes>;
|
|
26
|
-
client: Client<ContentTypes>;
|
|
27
|
-
conversation?: Conversation;
|
|
23
|
+
unknownMessage: [ctx: MessageContext<ContentTypes>];
|
|
28
24
|
};
|
|
29
|
-
export
|
|
25
|
+
export type AgentOptions<ContentTypes> = {
|
|
30
26
|
client: Client<ContentTypes>;
|
|
31
|
-
}
|
|
27
|
+
};
|
|
32
28
|
export type AgentMessageHandler<ContentTypes = unknown> = (ctx: MessageContext<ContentTypes>) => Promise<void> | void;
|
|
33
29
|
export type AgentMiddleware<ContentTypes = unknown> = (ctx: MessageContext<ContentTypes>, next: () => Promise<void> | void) => Promise<void>;
|
|
34
30
|
export type AgentErrorMiddleware<ContentTypes = unknown> = (error: unknown, ctx: AgentErrorContext<ContentTypes>, next: (err?: unknown) => Promise<void> | void) => Promise<void> | void;
|
|
35
31
|
export type StreamAllMessagesOptions<ContentTypes> = Parameters<Client<ContentTypes>["conversations"]["streamAllMessages"]>[0];
|
|
36
|
-
export
|
|
32
|
+
export type AgentErrorRegistrar<ContentTypes> = {
|
|
37
33
|
use(...errorMiddleware: Array<AgentErrorMiddleware<ContentTypes> | AgentErrorMiddleware<ContentTypes>[]>): AgentErrorRegistrar<ContentTypes>;
|
|
38
|
-
}
|
|
34
|
+
};
|
|
39
35
|
export declare class Agent<ContentTypes = unknown> extends EventEmitter<EventHandlerMap<ContentTypes>> {
|
|
40
36
|
#private;
|
|
41
37
|
constructor({ client }: AgentOptions<ContentTypes>);
|
|
42
38
|
static create<ContentCodecs extends ContentCodec[] = []>(signer: Parameters<typeof Client.create>[0], options?: Omit<ClientOptions, "codecs"> & {
|
|
43
39
|
codecs?: ContentCodecs;
|
|
44
|
-
}): Promise<Agent<import("@xmtp/node-sdk").ExtractCodecContentTypes<(
|
|
40
|
+
}): Promise<Agent<import("@xmtp/node-sdk").ExtractCodecContentTypes<(ReplyCodec | ReactionCodec | RemoteAttachmentCodec | (never[] | ContentCodecs)[number])[]>>>;
|
|
45
41
|
static createFromEnv<ContentCodecs extends ContentCodec[] = []>(options?: Omit<ClientOptions, "codecs"> & {
|
|
46
42
|
codecs?: ContentCodecs;
|
|
47
|
-
}): Promise<Agent<import("@xmtp/node-sdk").ExtractCodecContentTypes<(
|
|
43
|
+
}): Promise<Agent<import("@xmtp/node-sdk").ExtractCodecContentTypes<(ReplyCodec | ReactionCodec | RemoteAttachmentCodec | (never[] | ContentCodecs)[number])[]>>>;
|
|
48
44
|
use(...middleware: Array<AgentMiddleware<ContentTypes> | AgentMiddleware<ContentTypes>[]>): this;
|
|
49
45
|
start(options?: StreamAllMessagesOptions<ContentTypes>): Promise<void>;
|
|
50
46
|
get client(): Client<ContentTypes>;
|
package/dist/core/Agent.js
CHANGED
|
@@ -2,18 +2,16 @@ import EventEmitter from "node:events";
|
|
|
2
2
|
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
|
-
import { ApiUrls, Client,
|
|
5
|
+
import { ApiUrls, Client, } from "@xmtp/node-sdk";
|
|
6
6
|
import { fromString } from "uint8arrays/from-string";
|
|
7
7
|
import { isHex } from "viem/utils";
|
|
8
8
|
import { AgentError } from "../utils/error.js";
|
|
9
9
|
import { filter } from "../utils/filter.js";
|
|
10
10
|
import { createSigner, createUser } from "../utils/user.js";
|
|
11
|
-
import { ClientContext } from "./ClientContext.js";
|
|
12
|
-
import { ConversationContext } from "./ConversationContext.js";
|
|
13
11
|
import { MessageContext } from "./MessageContext.js";
|
|
14
12
|
export class Agent extends EventEmitter {
|
|
15
13
|
#client;
|
|
16
|
-
#
|
|
14
|
+
#messageStream;
|
|
17
15
|
#middleware = [];
|
|
18
16
|
#errorMiddleware = [];
|
|
19
17
|
#isListening = false;
|
|
@@ -97,36 +95,9 @@ export class Agent extends EventEmitter {
|
|
|
97
95
|
try {
|
|
98
96
|
this.#isListening = true;
|
|
99
97
|
void this.emit("start");
|
|
100
|
-
this.#
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (conversation instanceof Group) {
|
|
104
|
-
this.emit("group", new ConversationContext({
|
|
105
|
-
conversation,
|
|
106
|
-
client: this.#client,
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
else if (conversation instanceof Dm) {
|
|
110
|
-
this.emit("dm", new ConversationContext({
|
|
111
|
-
conversation,
|
|
112
|
-
client: this.#client,
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
const recovered = await this.#runErrorChain(new AgentError(1001, "Emitted value from conversation stream caused an error.", error), new ClientContext({ client: this.#client }));
|
|
118
|
-
if (!recovered)
|
|
119
|
-
await this.stop();
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
onError: async (error) => {
|
|
123
|
-
const recovered = await this.#runErrorChain(new AgentError(1002, "Error occured during conversation streaming.", error), new ClientContext({ client: this.#client }));
|
|
124
|
-
if (!recovered)
|
|
125
|
-
await this.stop();
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
const messages = await this.#client.conversations.streamAllMessages(options);
|
|
129
|
-
for await (const message of messages) {
|
|
98
|
+
this.#messageStream =
|
|
99
|
+
await this.#client.conversations.streamAllMessages(options);
|
|
100
|
+
for await (const message of this.#messageStream) {
|
|
130
101
|
// The "stop()" method sets "isListening"
|
|
131
102
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
132
103
|
if (!this.#isListening)
|
|
@@ -172,31 +143,31 @@ export class Agent extends EventEmitter {
|
|
|
172
143
|
}
|
|
173
144
|
}
|
|
174
145
|
}
|
|
175
|
-
async #processMessage(message, topic = "
|
|
146
|
+
async #processMessage(message, topic = "unknownMessage") {
|
|
176
147
|
// Skip messages with undefined content (failed to decode)
|
|
177
|
-
if (!filter.
|
|
148
|
+
if (!filter.hasContent(message)) {
|
|
178
149
|
return;
|
|
179
150
|
}
|
|
180
151
|
// Skip messages from agent itself
|
|
181
152
|
if (filter.fromSelf(message, this.#client)) {
|
|
182
153
|
return;
|
|
183
154
|
}
|
|
184
|
-
let context = null;
|
|
185
155
|
const conversation = await this.#client.conversations.getConversationById(message.conversationId);
|
|
186
156
|
if (!conversation) {
|
|
187
157
|
throw new AgentError(1003, `Failed to process message ID "${message.id}" for conversation ID "${message.conversationId}" because the conversation could not be found.`);
|
|
188
158
|
}
|
|
189
|
-
context = new MessageContext({
|
|
159
|
+
const context = new MessageContext({
|
|
190
160
|
message,
|
|
191
161
|
conversation,
|
|
192
162
|
client: this.#client,
|
|
193
163
|
});
|
|
194
164
|
await this.#runMiddlewareChain(context, topic);
|
|
195
165
|
}
|
|
196
|
-
async #runMiddlewareChain(context, topic = "
|
|
166
|
+
async #runMiddlewareChain(context, topic = "unknownMessage") {
|
|
197
167
|
const finalEmit = async () => {
|
|
198
168
|
try {
|
|
199
169
|
this.emit(topic, context);
|
|
170
|
+
this.emit("message", context);
|
|
200
171
|
}
|
|
201
172
|
catch (error) {
|
|
202
173
|
await this.#runErrorChain(error, context);
|
|
@@ -268,8 +239,11 @@ export class Agent extends EventEmitter {
|
|
|
268
239
|
return this.#errors;
|
|
269
240
|
}
|
|
270
241
|
async stop() {
|
|
271
|
-
await this.#conversationsStream?.end();
|
|
272
242
|
this.#isListening = false;
|
|
243
|
+
if (this.#messageStream) {
|
|
244
|
+
await this.#messageStream.end();
|
|
245
|
+
this.#messageStream = undefined;
|
|
246
|
+
}
|
|
273
247
|
this.emit("stop");
|
|
274
248
|
}
|
|
275
249
|
}
|
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;AA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;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,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;YAChC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAClC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Client, Conversation, DecodedMessage } from "@xmtp/node-sdk";
|
|
2
|
+
export type AgentBaseContext<ContentTypes = unknown> = {
|
|
3
|
+
client: Client<ContentTypes>;
|
|
4
|
+
conversation: Conversation;
|
|
5
|
+
message: DecodedMessage;
|
|
6
|
+
};
|
|
7
|
+
export type AgentErrorContext<ContentTypes = unknown> = Partial<AgentBaseContext<ContentTypes>> & {
|
|
8
|
+
client: Client<ContentTypes>;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentContext.js","sourceRoot":"","sources":["../../src/core/AgentContext.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Client, type Conversation, type Dm, type Group } from "@xmtp/node-sdk";
|
|
2
2
|
import { ClientContext } from "./ClientContext.js";
|
|
3
3
|
export declare class ConversationContext<ContentTypes = unknown, ConversationType extends Conversation = Conversation> extends ClientContext<ContentTypes> {
|
|
4
4
|
#private;
|
|
@@ -6,6 +6,8 @@ export declare class ConversationContext<ContentTypes = unknown, ConversationTyp
|
|
|
6
6
|
conversation: ConversationType;
|
|
7
7
|
client: Client<ContentTypes>;
|
|
8
8
|
});
|
|
9
|
+
isDm(): this is ConversationContext<ContentTypes, Dm<ContentTypes>>;
|
|
10
|
+
isGroup(): this is ConversationContext<ContentTypes, Group<ContentTypes>>;
|
|
9
11
|
sendText(text: string): Promise<void>;
|
|
10
12
|
get conversation(): ConversationType;
|
|
11
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
2
|
+
import { filter } from "../utils/filter.js";
|
|
2
3
|
import { ClientContext } from "./ClientContext.js";
|
|
3
4
|
export class ConversationContext extends ClientContext {
|
|
4
5
|
#conversation;
|
|
@@ -6,6 +7,12 @@ export class ConversationContext extends ClientContext {
|
|
|
6
7
|
super({ client });
|
|
7
8
|
this.#conversation = conversation;
|
|
8
9
|
}
|
|
10
|
+
isDm() {
|
|
11
|
+
return filter.isDM(this.#conversation);
|
|
12
|
+
}
|
|
13
|
+
isGroup() {
|
|
14
|
+
return filter.isGroup(this.#conversation);
|
|
15
|
+
}
|
|
9
16
|
async sendText(text) {
|
|
10
17
|
await this.#conversation.send(text, ContentTypeText);
|
|
11
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationContext.js","sourceRoot":"","sources":["../../src/core/ConversationContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"ConversationContext.js","sourceRoot":"","sources":["../../src/core/ConversationContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAO1D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,mBAGX,SAAQ,aAA2B;IACnC,aAAa,CAAmB;IAEhC,YAAY,EACV,YAAY,EACZ,MAAM,GAIP;QACC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACzC,CAAC;IAED,OAAO;QACL,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import { type Reaction } from "@xmtp/content-type-reaction";
|
|
2
|
-
import
|
|
1
|
+
import { type Reaction, type ReactionCodec } from "@xmtp/content-type-reaction";
|
|
2
|
+
import { type RemoteAttachmentCodec } from "@xmtp/content-type-remote-attachment";
|
|
3
|
+
import { type ReplyCodec } from "@xmtp/content-type-reply";
|
|
4
|
+
import { type TextCodec } from "@xmtp/content-type-text";
|
|
5
|
+
import type { DecodedMessage } from "@xmtp/node-sdk";
|
|
6
|
+
import type { AgentBaseContext } from "./AgentContext.js";
|
|
3
7
|
import { ConversationContext } from "./ConversationContext.js";
|
|
4
8
|
type DecodedMessageWithContent<ContentTypes = unknown> = DecodedMessage<ContentTypes> & {
|
|
5
9
|
content: ContentTypes;
|
|
6
10
|
};
|
|
11
|
+
export type MessageContextParams<ContentTypes = unknown> = Omit<AgentBaseContext<ContentTypes>, "message"> & {
|
|
12
|
+
message: DecodedMessageWithContent<ContentTypes>;
|
|
13
|
+
};
|
|
7
14
|
export declare class MessageContext<ContentTypes = unknown> extends ConversationContext<ContentTypes> {
|
|
8
15
|
#private;
|
|
9
|
-
constructor({ message, conversation, client, }:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
constructor({ message, conversation, client, }: MessageContextParams<ContentTypes>);
|
|
17
|
+
isText(): this is MessageContext<ReturnType<TextCodec["decode"]>>;
|
|
18
|
+
isReply(): this is MessageContext<ReturnType<ReplyCodec["decode"]>>;
|
|
19
|
+
isReaction(): this is MessageContext<ReturnType<ReactionCodec["decode"]>>;
|
|
20
|
+
isRemoteAttachment(): this is MessageContext<ReturnType<RemoteAttachmentCodec["decode"]>>;
|
|
14
21
|
sendReaction(content: string, schema?: Reaction["schema"]): Promise<void>;
|
|
15
22
|
sendTextReply(text: string): Promise<void>;
|
|
16
23
|
getSenderAddress(): Promise<string>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
2
|
-
import { ContentTypeReply } from "@xmtp/content-type-reply";
|
|
2
|
+
import { ContentTypeReply, } from "@xmtp/content-type-reply";
|
|
3
3
|
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
4
|
+
import { filter } from "../utils/filter.js";
|
|
4
5
|
import { ConversationContext } from "./ConversationContext.js";
|
|
5
6
|
export class MessageContext extends ConversationContext {
|
|
6
7
|
#message;
|
|
@@ -8,6 +9,18 @@ export class MessageContext extends ConversationContext {
|
|
|
8
9
|
super({ conversation, client });
|
|
9
10
|
this.#message = message;
|
|
10
11
|
}
|
|
12
|
+
isText() {
|
|
13
|
+
return filter.isText(this.#message);
|
|
14
|
+
}
|
|
15
|
+
isReply() {
|
|
16
|
+
return filter.isReply(this.#message);
|
|
17
|
+
}
|
|
18
|
+
isReaction() {
|
|
19
|
+
return filter.isReaction(this.#message);
|
|
20
|
+
}
|
|
21
|
+
isRemoteAttachment() {
|
|
22
|
+
return filter.isRemoteAttachment(this.#message);
|
|
23
|
+
}
|
|
11
24
|
async sendReaction(content, schema = "unicode") {
|
|
12
25
|
const reaction = {
|
|
13
26
|
action: "added",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageContext.js","sourceRoot":"","sources":["../../src/core/MessageContext.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"MessageContext.js","sourceRoot":"","sources":["../../src/core/MessageContext.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAGpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,gBAAgB,GAGjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAkB,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAc/D,MAAM,OAAO,cAEX,SAAQ,mBAAiC;IACzC,QAAQ,CAA0C;IAElD,YAAY,EACV,OAAO,EACP,YAAY,EACZ,MAAM,GAC6B;QACnC,KAAK,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED,OAAO;QACL,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED,UAAU;QACR,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,kBAAkB;QAGhB,OAAO,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,SAA6B,SAAS;QACxE,MAAM,QAAQ,GAAa;YACzB,MAAM,EAAE,OAAO;YACf,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3B,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;YAC7C,MAAM;YACN,OAAO;SACR,CAAC;QACF,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAAY;QAC9B,MAAM,KAAK,GAAU;YACnB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3B,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;YAC7C,WAAW,EAAE,eAAe;YAC5B,OAAO,EAAE,IAAI;SACd,CAAC;QACF,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,sBAAsB,CAAC;YACtE,IAAI,CAAC,QAAQ,CAAC,aAAa;SAC5B,CAAC,CAAC;QACH,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IACjD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
|
package/dist/demo.js
CHANGED
|
@@ -2,7 +2,7 @@ import { loadEnvFile } from "node:process";
|
|
|
2
2
|
import { Agent } from "./core/index.js";
|
|
3
3
|
import { CommandRouter } from "./middleware/CommandRouter.js";
|
|
4
4
|
import { getTestUrl } from "./utils/debug.js";
|
|
5
|
-
import { AgentError, createSigner, createUser
|
|
5
|
+
import { AgentError, createSigner, createUser } from "./utils/index.js";
|
|
6
6
|
try {
|
|
7
7
|
loadEnvFile(".env");
|
|
8
8
|
console.info(`Loaded keys from ".env" file.`);
|
|
@@ -18,12 +18,6 @@ router.command("/version", async (ctx) => {
|
|
|
18
18
|
await ctx.conversation.send(`v${process.env.npm_package_version}`);
|
|
19
19
|
});
|
|
20
20
|
agent.use(router.middleware());
|
|
21
|
-
agent.on("dm", (ctx) => {
|
|
22
|
-
console.log("Got new direct message in:", ctx.conversation.id);
|
|
23
|
-
});
|
|
24
|
-
agent.on("group", (ctx) => {
|
|
25
|
-
console.log("Got new group message in:", ctx.conversation.id);
|
|
26
|
-
});
|
|
27
21
|
agent.on("attachment", (ctx) => {
|
|
28
22
|
console.log("Got attachment:", ctx.message.content);
|
|
29
23
|
});
|
|
@@ -36,9 +30,11 @@ agent.on("reaction", (ctx) => {
|
|
|
36
30
|
agent.on("reply", (ctx) => {
|
|
37
31
|
console.log("Got reply:", ctx.message.content);
|
|
38
32
|
});
|
|
39
|
-
agent.on("text",
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
agent.on("text", async (ctx) => {
|
|
34
|
+
if (ctx.message.content.startsWith("@agent")) {
|
|
35
|
+
await ctx.conversation.send("How can I help you?");
|
|
36
|
+
}
|
|
37
|
+
});
|
|
42
38
|
const errorHandler = (error) => {
|
|
43
39
|
if (error instanceof AgentError) {
|
|
44
40
|
console.log(`Caught error ID "${error.code}"`, error);
|
package/dist/demo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,E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AAC,CAAC;AACrD,CAAC,CAAC,CAAC;AAEH,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
import { type Reaction } from "@xmtp/content-type-reaction";
|
|
2
2
|
import { type RemoteAttachment } from "@xmtp/content-type-remote-attachment";
|
|
3
3
|
import { type Reply } from "@xmtp/content-type-reply";
|
|
4
|
-
import type
|
|
5
|
-
import type { MessageContext } from "../core/MessageContext.js";
|
|
6
|
-
export type MessageFilter<ContentTypes> = (message: DecodedMessage, client: Client<ContentTypes>, conversation: Conversation) => boolean | Promise<boolean>;
|
|
7
|
-
/**
|
|
8
|
-
* Creates a filter for messages from specific senders
|
|
9
|
-
*
|
|
10
|
-
* @param senderInboxId - Single sender ID or array of sender IDs to match
|
|
11
|
-
* @returns Filter function
|
|
12
|
-
*/
|
|
13
|
-
declare function fromSender(senderInboxId: string | string[]): (message: DecodedMessage) => boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Creates a filter that matches text messages starting with a specific string.
|
|
16
|
-
*
|
|
17
|
-
* @param prefix - The string prefix to match against
|
|
18
|
-
* @returns Filter function
|
|
19
|
-
*/
|
|
20
|
-
declare function startsWith(prefix: string): (message: DecodedMessage) => boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Creates a filter that requires all provided filters to pass
|
|
23
|
-
*
|
|
24
|
-
* @param filters - Array of filters that must all return true
|
|
25
|
-
* @returns Filter function
|
|
26
|
-
*/
|
|
27
|
-
declare function and<ContentTypes>(...filters: MessageFilter<ContentTypes>[]): MessageFilter<ContentTypes>;
|
|
28
|
-
/**
|
|
29
|
-
* Creates a filter that requires at least one provided filter to pass.
|
|
30
|
-
*
|
|
31
|
-
* @param filters - Array of filters where at least one must return true
|
|
32
|
-
* @returns Filter function
|
|
33
|
-
*/
|
|
34
|
-
declare function or<ContentTypes>(...filters: MessageFilter<ContentTypes>[]): MessageFilter<ContentTypes>;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a filter that inverts the result of another filter.
|
|
37
|
-
*
|
|
38
|
-
* @param filter - The filter to negate
|
|
39
|
-
* @returns Filter function
|
|
40
|
-
*/
|
|
41
|
-
declare function not<ContentTypes>(filter: MessageFilter<ContentTypes>): MessageFilter<ContentTypes>;
|
|
42
|
-
/**
|
|
43
|
-
* Pre-configured filter instances and factory functions for common filtering scenarios
|
|
44
|
-
*/
|
|
4
|
+
import { Dm, Group, type Client, type Conversation, type DecodedMessage } from "@xmtp/node-sdk";
|
|
45
5
|
export declare const filter: {
|
|
46
|
-
fromSelf: (message: DecodedMessage
|
|
47
|
-
|
|
48
|
-
content:
|
|
49
|
-
};
|
|
50
|
-
isDM:
|
|
51
|
-
isGroup:
|
|
6
|
+
fromSelf: <ContentTypes>(message: DecodedMessage<ContentTypes>, client: Client<ContentTypes>) => boolean;
|
|
7
|
+
hasContent: <ContentTypes>(message: DecodedMessage<ContentTypes>) => message is DecodedMessage<ContentTypes> & {
|
|
8
|
+
content: NonNullable<ContentTypes>;
|
|
9
|
+
};
|
|
10
|
+
isDM: (conversation: Conversation) => conversation is Dm;
|
|
11
|
+
isGroup: (conversation: Conversation) => conversation is Group;
|
|
12
|
+
isGroupAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
13
|
+
isGroupSuperAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
52
14
|
isReaction: (message: DecodedMessage) => message is DecodedMessage & {
|
|
53
15
|
content: Reaction;
|
|
54
16
|
};
|
|
@@ -61,24 +23,17 @@ export declare const filter: {
|
|
|
61
23
|
isText: (message: DecodedMessage) => message is DecodedMessage & {
|
|
62
24
|
content: string;
|
|
63
25
|
};
|
|
64
|
-
isTextReply: (message: DecodedMessage) =>
|
|
65
|
-
content: Reply & {
|
|
66
|
-
content: string;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
fromSender: typeof fromSender;
|
|
70
|
-
startsWith: typeof startsWith;
|
|
71
|
-
and: typeof and;
|
|
72
|
-
or: typeof or;
|
|
73
|
-
not: typeof not;
|
|
26
|
+
isTextReply: (message: DecodedMessage) => boolean;
|
|
74
27
|
};
|
|
75
28
|
export declare const f: {
|
|
76
|
-
fromSelf: (message: DecodedMessage
|
|
77
|
-
|
|
78
|
-
content:
|
|
79
|
-
};
|
|
80
|
-
isDM:
|
|
81
|
-
isGroup:
|
|
29
|
+
fromSelf: <ContentTypes>(message: DecodedMessage<ContentTypes>, client: Client<ContentTypes>) => boolean;
|
|
30
|
+
hasContent: <ContentTypes>(message: DecodedMessage<ContentTypes>) => message is DecodedMessage<ContentTypes> & {
|
|
31
|
+
content: NonNullable<ContentTypes>;
|
|
32
|
+
};
|
|
33
|
+
isDM: (conversation: Conversation) => conversation is Dm;
|
|
34
|
+
isGroup: (conversation: Conversation) => conversation is Group;
|
|
35
|
+
isGroupAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
36
|
+
isGroupSuperAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
82
37
|
isReaction: (message: DecodedMessage) => message is DecodedMessage & {
|
|
83
38
|
content: Reaction;
|
|
84
39
|
};
|
|
@@ -91,16 +46,5 @@ export declare const f: {
|
|
|
91
46
|
isText: (message: DecodedMessage) => message is DecodedMessage & {
|
|
92
47
|
content: string;
|
|
93
48
|
};
|
|
94
|
-
isTextReply: (message: DecodedMessage) =>
|
|
95
|
-
content: Reply & {
|
|
96
|
-
content: string;
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
fromSender: typeof fromSender;
|
|
100
|
-
startsWith: typeof startsWith;
|
|
101
|
-
and: typeof and;
|
|
102
|
-
or: typeof or;
|
|
103
|
-
not: typeof not;
|
|
49
|
+
isTextReply: (message: DecodedMessage) => boolean;
|
|
104
50
|
};
|
|
105
|
-
export declare const withFilter: <ContentTypes>(filterFn: MessageFilter<ContentTypes>, listener: (ctx: MessageContext<ContentTypes>) => void | Promise<void>) => (ctx: MessageContext<ContentTypes>) => Promise<void>;
|
|
106
|
-
export {};
|
package/dist/utils/filter.js
CHANGED
|
@@ -2,165 +2,58 @@ import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
|
2
2
|
import { ContentTypeRemoteAttachment, } from "@xmtp/content-type-remote-attachment";
|
|
3
3
|
import { ContentTypeReply } from "@xmtp/content-type-reply";
|
|
4
4
|
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @returns Filter function
|
|
9
|
-
*/
|
|
10
|
-
function fromSelf() {
|
|
11
|
-
return (message, client) => {
|
|
12
|
-
return message.senderInboxId === client.inboxId;
|
|
13
|
-
};
|
|
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
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Creates a filter that includes only text messages.
|
|
47
|
-
*
|
|
48
|
-
* @returns Filter function
|
|
49
|
-
*/
|
|
50
|
-
function isText() {
|
|
51
|
-
return (message) => {
|
|
52
|
-
return !!message.contentType?.sameAs(ContentTypeText);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function isTextReply() {
|
|
56
|
-
return (message) => {
|
|
57
|
-
return isReply()(message) && typeof message.content.content === "string";
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Creates a filter for messages from specific senders
|
|
62
|
-
*
|
|
63
|
-
* @param senderInboxId - Single sender ID or array of sender IDs to match
|
|
64
|
-
* @returns Filter function
|
|
65
|
-
*/
|
|
66
|
-
function fromSender(senderInboxId) {
|
|
67
|
-
const senderIds = Array.isArray(senderInboxId)
|
|
68
|
-
? senderInboxId
|
|
69
|
-
: [senderInboxId];
|
|
70
|
-
return (message) => {
|
|
71
|
-
return senderIds.includes(message.senderInboxId);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Creates a filter that matches text messages starting with a specific string.
|
|
76
|
-
*
|
|
77
|
-
* @param prefix - The string prefix to match against
|
|
78
|
-
* @returns Filter function
|
|
79
|
-
*/
|
|
80
|
-
function startsWith(prefix) {
|
|
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
|
-
};
|
|
91
|
-
const text = getTextContent(message);
|
|
92
|
-
return !!(text && text.startsWith(prefix));
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Creates a filter that requires all provided filters to pass
|
|
97
|
-
*
|
|
98
|
-
* @param filters - Array of filters that must all return true
|
|
99
|
-
* @returns Filter function
|
|
100
|
-
*/
|
|
101
|
-
function and(...filters) {
|
|
102
|
-
return async (message, client, conversation) => {
|
|
103
|
-
for (const filter of filters) {
|
|
104
|
-
const result = await filter(message, client, conversation);
|
|
105
|
-
if (!result)
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Creates a filter that requires at least one provided filter to pass.
|
|
113
|
-
*
|
|
114
|
-
* @param filters - Array of filters where at least one must return true
|
|
115
|
-
* @returns Filter function
|
|
116
|
-
*/
|
|
117
|
-
function or(...filters) {
|
|
118
|
-
return async (message, client, conversation) => {
|
|
119
|
-
for (const filter of filters) {
|
|
120
|
-
const result = await filter(message, client, conversation);
|
|
121
|
-
if (result)
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Creates a filter that inverts the result of another filter.
|
|
129
|
-
*
|
|
130
|
-
* @param filter - The filter to negate
|
|
131
|
-
* @returns Filter function
|
|
132
|
-
*/
|
|
133
|
-
function not(filter) {
|
|
134
|
-
return async (message, client, conversation) => {
|
|
135
|
-
return !(await filter(message, client, conversation));
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Pre-configured filter instances and factory functions for common filtering scenarios
|
|
140
|
-
*/
|
|
141
|
-
export const filter = {
|
|
142
|
-
// basic filters
|
|
143
|
-
fromSelf: fromSelf(),
|
|
144
|
-
hasDefinedContent: hasDefinedContent(),
|
|
145
|
-
isDM: isDM(),
|
|
146
|
-
isGroup: isGroup(),
|
|
147
|
-
isReaction: isReaction(),
|
|
148
|
-
isRemoteAttachment: isRemoteAttachment(),
|
|
149
|
-
isReply: isReply(),
|
|
150
|
-
isText: isText(),
|
|
151
|
-
isTextReply: isTextReply(),
|
|
152
|
-
// factory functions
|
|
153
|
-
fromSender,
|
|
154
|
-
startsWith,
|
|
155
|
-
// combinators
|
|
156
|
-
and,
|
|
157
|
-
or,
|
|
158
|
-
not,
|
|
5
|
+
import { Dm, Group, } from "@xmtp/node-sdk";
|
|
6
|
+
const fromSelf = (message, client) => {
|
|
7
|
+
return message.senderInboxId === client.inboxId;
|
|
159
8
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
9
|
+
const hasContent = (message) => {
|
|
10
|
+
return message.content !== undefined && message.content !== null;
|
|
11
|
+
};
|
|
12
|
+
const isDM = (conversation) => {
|
|
13
|
+
return conversation instanceof Dm;
|
|
14
|
+
};
|
|
15
|
+
const isGroup = (conversation) => {
|
|
16
|
+
return conversation instanceof Group;
|
|
17
|
+
};
|
|
18
|
+
const isGroupAdmin = (conversation, message) => {
|
|
19
|
+
if (isGroup(conversation)) {
|
|
20
|
+
return conversation.isAdmin(message.senderInboxId);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
const isGroupSuperAdmin = (conversation, message) => {
|
|
25
|
+
if (isGroup(conversation)) {
|
|
26
|
+
return conversation.isSuperAdmin(message.senderInboxId);
|
|
164
27
|
}
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
const isReaction = (message) => {
|
|
31
|
+
return !!message.contentType?.sameAs(ContentTypeReaction);
|
|
165
32
|
};
|
|
33
|
+
const isReply = (message) => {
|
|
34
|
+
return !!message.contentType?.sameAs(ContentTypeReply);
|
|
35
|
+
};
|
|
36
|
+
const isRemoteAttachment = (message) => {
|
|
37
|
+
return !!message.contentType?.sameAs(ContentTypeRemoteAttachment);
|
|
38
|
+
};
|
|
39
|
+
const isText = (message) => {
|
|
40
|
+
return !!message.contentType?.sameAs(ContentTypeText);
|
|
41
|
+
};
|
|
42
|
+
const isTextReply = (message) => {
|
|
43
|
+
return isReply(message) && typeof message.content.content === "string";
|
|
44
|
+
};
|
|
45
|
+
export const filter = {
|
|
46
|
+
fromSelf,
|
|
47
|
+
hasContent,
|
|
48
|
+
isDM,
|
|
49
|
+
isGroup,
|
|
50
|
+
isGroupAdmin,
|
|
51
|
+
isGroupSuperAdmin,
|
|
52
|
+
isReaction,
|
|
53
|
+
isRemoteAttachment,
|
|
54
|
+
isReply,
|
|
55
|
+
isText,
|
|
56
|
+
isTextReply,
|
|
57
|
+
};
|
|
58
|
+
export const f = filter;
|
|
166
59
|
//# 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,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;
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/utils/filter.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;AAC1D,OAAO,EACL,EAAE,EACF,KAAK,GAIN,MAAM,gBAAgB,CAAC;AAExB,MAAM,QAAQ,GAAG,CACf,OAAqC,EACrC,MAA4B,EAC5B,EAAE;IACF,OAAO,OAAO,CAAC,aAAa,KAAK,MAAM,CAAC,OAAO,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CACjB,OAAqC,EAGrC,EAAE;IACF,OAAO,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC;AACnE,CAAC,CAAC;AAEF,MAAM,IAAI,GAAG,CAAC,YAA0B,EAAsB,EAAE;IAC9D,OAAO,YAAY,YAAY,EAAE,CAAC;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AC9C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC;AACzE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,OAAO;IACP,YAAY;IACZ,iBAAiB;IACjB,UAAU;IACV,kBAAkB;IAClB,OAAO;IACP,MAAM;IACN,WAAW;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"@xmtp/content-type-remote-attachment": "^2.0.2",
|
|
9
9
|
"@xmtp/content-type-reply": "^2.0.2",
|
|
10
10
|
"@xmtp/content-type-text": "^2.0.2",
|
|
11
|
-
"@xmtp/node-sdk": "^4.1.
|
|
11
|
+
"@xmtp/node-sdk": "^4.1.1",
|
|
12
12
|
"uint8arrays": "^5.1.0",
|
|
13
|
-
"viem": "^2.
|
|
13
|
+
"viem": "^2.37.6"
|
|
14
14
|
},
|
|
15
15
|
"description": "XMTP Agent SDK for interacting with XMTP networks",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
18
|
-
"@types/node": "^22.
|
|
18
|
+
"@types/node": "^22.18.4",
|
|
19
19
|
"@vitest/coverage-v8": "^3.2.4",
|
|
20
20
|
"tsc-alias": "^1.8.16",
|
|
21
|
-
"tsx": "^4.20.
|
|
22
|
-
"typescript": "^5.
|
|
23
|
-
"vite": "^7.
|
|
21
|
+
"tsx": "^4.20.5",
|
|
22
|
+
"typescript": "^5.9.2",
|
|
23
|
+
"vite": "^7.1.5",
|
|
24
24
|
"vite-tsconfig-paths": "^5.1.4",
|
|
25
25
|
"vitest": "^3.2.4"
|
|
26
26
|
},
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"typecheck": "tsc --noEmit"
|
|
71
71
|
},
|
|
72
72
|
"type": "module",
|
|
73
|
-
"version": "0.0.
|
|
73
|
+
"version": "0.0.14"
|
|
74
74
|
}
|