@xmtp/agent-sdk 0.0.10 → 0.0.12
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 +1 -1
- package/dist/bin/generateKeys.js +11 -1
- package/dist/bin/generateKeys.js.map +1 -1
- package/dist/core/Agent.d.ts +18 -11
- package/dist/core/Agent.js +26 -19
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/ClientContext.d.ts +9 -0
- package/dist/core/ClientContext.js +13 -0
- package/dist/core/ClientContext.js.map +1 -0
- package/dist/core/ConversationContext.d.ts +2 -3
- package/dist/core/ConversationContext.js +3 -9
- package/dist/core/ConversationContext.js.map +1 -1
- package/dist/core/MessageContext.d.ts +5 -4
- package/dist/core/MessageContext.js +1 -1
- package/dist/core/MessageContext.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/demo.js +8 -2
- package/dist/demo.js.map +1 -1
- package/dist/middleware/CommandRouter.d.ts +2 -2
- package/dist/middleware/CommandRouter.js +2 -2
- package/dist/middleware/CommandRouter.js.map +1 -1
- package/dist/utils/error.d.ts +5 -0
- package/dist/utils/error.js +11 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/filter.d.ts +55 -15
- package/dist/utils/filter.js +63 -21
- package/dist/utils/filter.js.map +1 -1
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/index.js +1 -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) => {
|
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,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"generateKeys.js","sourceRoot":"","sources":["../../src/bin/generateKeys.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,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C,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.d.ts
CHANGED
|
@@ -4,32 +4,39 @@ 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, Dm, Group, type ClientOptions } from "@xmtp/node-sdk";
|
|
7
|
+
import { Client, Dm, Group, type ClientOptions, type Conversation, type DecodedMessage } from "@xmtp/node-sdk";
|
|
8
8
|
import { ConversationContext } from "./ConversationContext.js";
|
|
9
|
-
import {
|
|
9
|
+
import { MessageContext } from "./MessageContext.js";
|
|
10
10
|
interface EventHandlerMap<ContentTypes> {
|
|
11
|
-
attachment: [
|
|
11
|
+
attachment: [
|
|
12
|
+
ctx: MessageContext<ReturnType<RemoteAttachmentCodec["decode"]>>
|
|
13
|
+
];
|
|
12
14
|
dm: [ctx: ConversationContext<ContentTypes, Dm<ContentTypes>>];
|
|
13
15
|
group: [ctx: ConversationContext<ContentTypes, Group<ContentTypes>>];
|
|
14
|
-
reaction: [ctx:
|
|
15
|
-
reply: [ctx:
|
|
16
|
+
reaction: [ctx: MessageContext<ReturnType<ReactionCodec["decode"]>>];
|
|
17
|
+
reply: [ctx: MessageContext<ReturnType<ReplyCodec["decode"]>>];
|
|
16
18
|
start: [];
|
|
17
19
|
stop: [];
|
|
18
|
-
text: [ctx:
|
|
20
|
+
text: [ctx: MessageContext<ReturnType<TextCodec["decode"]>>];
|
|
19
21
|
unhandledError: [error: Error];
|
|
20
|
-
unhandledMessage: [ctx:
|
|
22
|
+
unhandledMessage: [ctx: MessageContext<ContentTypes>];
|
|
21
23
|
}
|
|
24
|
+
export type AgentErrorContext<ContentTypes = unknown> = {
|
|
25
|
+
message?: DecodedMessage<ContentTypes>;
|
|
26
|
+
client: Client<ContentTypes>;
|
|
27
|
+
conversation?: Conversation;
|
|
28
|
+
};
|
|
22
29
|
export interface AgentOptions<ContentTypes> {
|
|
23
30
|
client: Client<ContentTypes>;
|
|
24
31
|
}
|
|
25
|
-
export type AgentMessageHandler<ContentTypes = unknown> = (ctx:
|
|
26
|
-
export type AgentMiddleware<ContentTypes = unknown> = (ctx:
|
|
27
|
-
export type AgentErrorMiddleware<ContentTypes = unknown> = (error: unknown, ctx:
|
|
32
|
+
export type AgentMessageHandler<ContentTypes = unknown> = (ctx: MessageContext<ContentTypes>) => Promise<void> | void;
|
|
33
|
+
export type AgentMiddleware<ContentTypes = unknown> = (ctx: MessageContext<ContentTypes>, next: () => Promise<void> | void) => Promise<void>;
|
|
34
|
+
export type AgentErrorMiddleware<ContentTypes = unknown> = (error: unknown, ctx: AgentErrorContext<ContentTypes>, next: (err?: unknown) => Promise<void> | void) => Promise<void> | void;
|
|
28
35
|
export type StreamAllMessagesOptions<ContentTypes> = Parameters<Client<ContentTypes>["conversations"]["streamAllMessages"]>[0];
|
|
29
36
|
export interface AgentErrorRegistrar<ContentTypes> {
|
|
30
37
|
use(...errorMiddleware: Array<AgentErrorMiddleware<ContentTypes> | AgentErrorMiddleware<ContentTypes>[]>): AgentErrorRegistrar<ContentTypes>;
|
|
31
38
|
}
|
|
32
|
-
export declare class Agent<ContentTypes> extends EventEmitter<EventHandlerMap<ContentTypes>> {
|
|
39
|
+
export declare class Agent<ContentTypes = unknown> extends EventEmitter<EventHandlerMap<ContentTypes>> {
|
|
33
40
|
#private;
|
|
34
41
|
constructor({ client }: AgentOptions<ContentTypes>);
|
|
35
42
|
static create<ContentCodecs extends ContentCodec[] = []>(signer: Parameters<typeof Client.create>[0], options?: Omit<ClientOptions, "codecs"> & {
|
package/dist/core/Agent.js
CHANGED
|
@@ -3,13 +3,14 @@ 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 {
|
|
8
|
+
import { AgentError } from "../utils/error.js";
|
|
8
9
|
import { filter } from "../utils/filter.js";
|
|
9
|
-
import { hasDefinedContent, isReaction, isRemoteAttachment, isReply, isText, } from "../utils/message.js";
|
|
10
10
|
import { createSigner, createUser } from "../utils/user.js";
|
|
11
|
+
import { ClientContext } from "./ClientContext.js";
|
|
11
12
|
import { ConversationContext } from "./ConversationContext.js";
|
|
12
|
-
import {
|
|
13
|
+
import { MessageContext } from "./MessageContext.js";
|
|
13
14
|
export class Agent extends EventEmitter {
|
|
14
15
|
#client;
|
|
15
16
|
#conversationsStream;
|
|
@@ -32,9 +33,7 @@ export class Agent extends EventEmitter {
|
|
|
32
33
|
#defaultErrorHandler = (currentError) => {
|
|
33
34
|
const emittedError = currentError instanceof Error
|
|
34
35
|
? currentError
|
|
35
|
-
: new
|
|
36
|
-
cause: currentError,
|
|
37
|
-
});
|
|
36
|
+
: new AgentError(9999, `Unhandled error caught by default error middleware.`, currentError);
|
|
38
37
|
this.emit("unhandledError", emittedError);
|
|
39
38
|
};
|
|
40
39
|
constructor({ client }) {
|
|
@@ -67,12 +66,12 @@ export class Agent extends EventEmitter {
|
|
|
67
66
|
// Note: we need to omit this so that "Client.create" can correctly infer the codecs.
|
|
68
67
|
options) {
|
|
69
68
|
if (!isHex(process.env.XMTP_WALLET_KEY)) {
|
|
70
|
-
throw new
|
|
69
|
+
throw new AgentError(1000, `XMTP_WALLET_KEY env is not in hex (0x) format.`);
|
|
71
70
|
}
|
|
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)) {
|
|
@@ -115,13 +114,13 @@ export class Agent extends EventEmitter {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
catch (error) {
|
|
118
|
-
const recovered = await this.#runErrorChain(error,
|
|
117
|
+
const recovered = await this.#runErrorChain(new AgentError(1001, "Emitted value from conversation stream caused an error.", error), new ClientContext({ client: this.#client }));
|
|
119
118
|
if (!recovered)
|
|
120
119
|
await this.stop();
|
|
121
120
|
}
|
|
122
121
|
},
|
|
123
122
|
onError: async (error) => {
|
|
124
|
-
const recovered = await this.#runErrorChain(error,
|
|
123
|
+
const recovered = await this.#runErrorChain(new AgentError(1002, "Error occured during conversation streaming.", error), new ClientContext({ client: this.#client }));
|
|
125
124
|
if (!recovered)
|
|
126
125
|
await this.stop();
|
|
127
126
|
},
|
|
@@ -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:
|
|
@@ -152,7 +151,9 @@ export class Agent extends EventEmitter {
|
|
|
152
151
|
}
|
|
153
152
|
}
|
|
154
153
|
catch (error) {
|
|
155
|
-
const recovered = await this.#runErrorChain(error,
|
|
154
|
+
const recovered = await this.#runErrorChain(error, {
|
|
155
|
+
client: this.#client,
|
|
156
|
+
});
|
|
156
157
|
if (!recovered) {
|
|
157
158
|
await this.stop();
|
|
158
159
|
break;
|
|
@@ -162,7 +163,9 @@ export class Agent extends EventEmitter {
|
|
|
162
163
|
}
|
|
163
164
|
catch (error) {
|
|
164
165
|
this.#isListening = false;
|
|
165
|
-
const recovered = await this.#runErrorChain(error,
|
|
166
|
+
const recovered = await this.#runErrorChain(error, {
|
|
167
|
+
client: this.#client,
|
|
168
|
+
});
|
|
166
169
|
if (recovered) {
|
|
167
170
|
await this.stop();
|
|
168
171
|
queueMicrotask(() => this.start(options));
|
|
@@ -171,7 +174,7 @@ export class Agent extends EventEmitter {
|
|
|
171
174
|
}
|
|
172
175
|
async #processMessage(message, topic = "unhandledMessage") {
|
|
173
176
|
// Skip messages with undefined content (failed to decode)
|
|
174
|
-
if (!hasDefinedContent(message)) {
|
|
177
|
+
if (!filter.hasDefinedContent(message)) {
|
|
175
178
|
return;
|
|
176
179
|
}
|
|
177
180
|
// Skip messages from agent itself
|
|
@@ -181,9 +184,13 @@ export class Agent extends EventEmitter {
|
|
|
181
184
|
let context = null;
|
|
182
185
|
const conversation = await this.#client.conversations.getConversationById(message.conversationId);
|
|
183
186
|
if (!conversation) {
|
|
184
|
-
throw new
|
|
187
|
+
throw new AgentError(1003, `Failed to process message ID "${message.id}" for conversation ID "${message.conversationId}" because the conversation could not be found.`);
|
|
185
188
|
}
|
|
186
|
-
context = new
|
|
189
|
+
context = new MessageContext({
|
|
190
|
+
message,
|
|
191
|
+
conversation,
|
|
192
|
+
client: this.#client,
|
|
193
|
+
});
|
|
187
194
|
await this.#runMiddlewareChain(context, topic);
|
|
188
195
|
}
|
|
189
196
|
async #runMiddlewareChain(context, topic = "unhandledMessage") {
|
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,
|
|
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,GAMN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;A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,CAAC,cAAc,CAClB,KAAc,EACd,OAAwC;QAExC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAEpE,IAAI,YAAY,GAAY,KAAK,CAAC;QAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Client } from "@xmtp/node-sdk";
|
|
2
|
+
export declare class ClientContext<ContentTypes = unknown> {
|
|
3
|
+
#private;
|
|
4
|
+
constructor({ client }: {
|
|
5
|
+
client: Client<ContentTypes>;
|
|
6
|
+
});
|
|
7
|
+
getClientAddress(): string | undefined;
|
|
8
|
+
get client(): Client<ContentTypes>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class ClientContext {
|
|
2
|
+
#client;
|
|
3
|
+
constructor({ client }) {
|
|
4
|
+
this.#client = client;
|
|
5
|
+
}
|
|
6
|
+
getClientAddress() {
|
|
7
|
+
return this.#client.accountIdentifier?.identifier;
|
|
8
|
+
}
|
|
9
|
+
get client() {
|
|
10
|
+
return this.#client;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ClientContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientContext.js","sourceRoot":"","sources":["../../src/core/ClientContext.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAa;IACxB,OAAO,CAAuB;IAE9B,YAAY,EAAE,MAAM,EAAoC;QACtD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,UAAU,CAAC;IACpD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Client, Conversation } from "@xmtp/node-sdk";
|
|
2
|
-
|
|
2
|
+
import { ClientContext } from "./ClientContext.js";
|
|
3
|
+
export declare class ConversationContext<ContentTypes = unknown, ConversationType extends Conversation = Conversation> extends ClientContext<ContentTypes> {
|
|
3
4
|
#private;
|
|
4
5
|
constructor({ conversation, client, }: {
|
|
5
6
|
conversation: ConversationType;
|
|
6
7
|
client: Client<ContentTypes>;
|
|
7
8
|
});
|
|
8
9
|
sendText(text: string): Promise<void>;
|
|
9
|
-
getOwnAddress(): string | undefined;
|
|
10
10
|
get conversation(): ConversationType;
|
|
11
|
-
get client(): Client<ContentTypes>;
|
|
12
11
|
}
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { ClientContext } from "./ClientContext.js";
|
|
3
|
+
export class ConversationContext extends ClientContext {
|
|
4
4
|
#conversation;
|
|
5
5
|
constructor({ conversation, client, }) {
|
|
6
|
+
super({ client });
|
|
6
7
|
this.#conversation = conversation;
|
|
7
|
-
this.#client = client;
|
|
8
8
|
}
|
|
9
9
|
async sendText(text) {
|
|
10
10
|
await this.#conversation.send(text, ContentTypeText);
|
|
11
11
|
}
|
|
12
|
-
getOwnAddress() {
|
|
13
|
-
return this.#client.accountIdentifier?.identifier;
|
|
14
|
-
}
|
|
15
12
|
get conversation() {
|
|
16
13
|
return this.#conversation;
|
|
17
14
|
}
|
|
18
|
-
get client() {
|
|
19
|
-
return this.#client;
|
|
20
|
-
}
|
|
21
15
|
}
|
|
22
16
|
//# sourceMappingURL=ConversationContext.js.map
|
|
@@ -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;AAE1D,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,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,18 +1,19 @@
|
|
|
1
1
|
import { type Reaction } from "@xmtp/content-type-reaction";
|
|
2
2
|
import type { Client, Conversation, DecodedMessage } from "@xmtp/node-sdk";
|
|
3
3
|
import { ConversationContext } from "./ConversationContext.js";
|
|
4
|
-
|
|
4
|
+
type DecodedMessageWithContent<ContentTypes = unknown> = DecodedMessage<ContentTypes> & {
|
|
5
5
|
content: ContentTypes;
|
|
6
6
|
};
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class MessageContext<ContentTypes = unknown> extends ConversationContext<ContentTypes> {
|
|
8
8
|
#private;
|
|
9
9
|
constructor({ message, conversation, client, }: {
|
|
10
|
-
message:
|
|
10
|
+
message: DecodedMessageWithContent<ContentTypes>;
|
|
11
11
|
conversation: Conversation;
|
|
12
12
|
client: Client<ContentTypes>;
|
|
13
13
|
});
|
|
14
14
|
sendReaction(content: string, schema?: Reaction["schema"]): Promise<void>;
|
|
15
15
|
sendTextReply(text: string): Promise<void>;
|
|
16
16
|
getSenderAddress(): Promise<string>;
|
|
17
|
-
get message():
|
|
17
|
+
get message(): DecodedMessageWithContent<ContentTypes>;
|
|
18
18
|
}
|
|
19
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
|
2
2
|
import { ContentTypeReply } from "@xmtp/content-type-reply";
|
|
3
3
|
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
4
4
|
import { ConversationContext } from "./ConversationContext.js";
|
|
5
|
-
export class
|
|
5
|
+
export class MessageContext extends ConversationContext {
|
|
6
6
|
#message;
|
|
7
7
|
constructor({ message, conversation, client, }) {
|
|
8
8
|
super({ conversation, client });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageContext.js","sourceRoot":"","sources":["../../src/core/MessageContext.ts"],"names":[],"mappings":"AAAA,OAAO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AAE,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/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
|
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 { createSigner, createUser, f, withFilter } from "./utils/index.js";
|
|
5
|
+
import { AgentError, createSigner, createUser, f, withFilter, } from "./utils/index.js";
|
|
6
6
|
try {
|
|
7
7
|
loadEnvFile(".env");
|
|
8
8
|
console.info(`Loaded keys from ".env" file.`);
|
|
@@ -40,7 +40,13 @@ agent.on("text", withFilter(f.startsWith("@agent"), async (ctx) => {
|
|
|
40
40
|
await ctx.conversation.send("How can I help you?");
|
|
41
41
|
}));
|
|
42
42
|
const errorHandler = (error) => {
|
|
43
|
-
|
|
43
|
+
if (error instanceof AgentError) {
|
|
44
|
+
console.log(`Caught error ID "${error.code}"`, error);
|
|
45
|
+
console.log("Original error", error.cause);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(`Caught error`, error);
|
|
49
|
+
}
|
|
44
50
|
};
|
|
45
51
|
agent.on("unhandledError", errorHandler);
|
|
46
52
|
agent.on("start", () => {
|
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,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,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,CAAC,EACD,UAAU,GACX,MAAM,kBAAkB,CAAC;AAE1B,IAAI,CAAC;IACH,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;AAChD,CAAC;A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AC,KAAK,EAAE,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type AgentMessageHandler, type AgentMiddleware } from "../core/Agent.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MessageContext } from "../core/MessageContext.js";
|
|
3
3
|
export declare class CommandRouter<ContentTypes> {
|
|
4
4
|
private commandMap;
|
|
5
5
|
private defaultHandler;
|
|
6
6
|
command(command: string, handler: AgentMessageHandler): this;
|
|
7
7
|
default(handler: AgentMessageHandler): this;
|
|
8
|
-
handle(ctx:
|
|
8
|
+
handle(ctx: MessageContext): Promise<boolean>;
|
|
9
9
|
middleware: () => AgentMiddleware<ContentTypes>;
|
|
10
10
|
}
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"CommandRouter.js","sourceRoot":"","sources":["../../src/middleware/CommandRouter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,OAAO,aAAa;IAChB,UAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;IACpD,cAAc,GAA+B,IAAI,CAAC;IAE1D,OAAO,CAAC,OAAe,EAAE,OAA4B;QACnD,IAAI,CAAC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AM,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,KAAK,CAAS;IAEd,YAAY,IAAY,EAAE,OAAe,EAAE,KAAe;QACxD,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type MessageFilter<ContentTypes> = (message: DecodedMessage, client: Client<ContentTypes
|
|
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";
|
|
5
|
+
import type { MessageContext } from "../core/MessageContext.js";
|
|
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: MessageContext<ContentTypes>) => void | Promise<void>) => (ctx: MessageContext<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":["../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AED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,gBAAgB;IAChB,QAAQ,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,QAAqE,EACrE,EAAE,CACJ,KAAK,EAAE,GAAiC,EAAE,EAAE;IAC1C,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,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.12"
|
|
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,IAA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