chirli 0.1.0 → 0.2.0
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/ARCHITECTURE.md +18 -20
- package/CONTRIBUTING.md +7 -3
- package/README.md +63 -55
- package/SECURITY.md +11 -11
- package/dist/allowlist.d.ts +3 -0
- package/dist/allowlist.js +9 -0
- package/dist/announcements.d.ts +4 -4
- package/dist/announcements.js +66 -34
- package/dist/attachments.d.ts +43 -0
- package/dist/attachments.js +340 -0
- package/dist/blossom.d.ts +2 -2
- package/dist/blossom.js +120 -66
- package/dist/bot-handlers.d.ts +9 -18
- package/dist/bot-handlers.js +125 -66
- package/dist/bot.d.ts +17 -20
- package/dist/bot.js +150 -55
- package/dist/client.d.ts +43 -39
- package/dist/client.js +476 -290
- package/dist/command-discovery.d.ts +2 -2
- package/dist/command-discovery.js +16 -7
- package/dist/command-schema.d.ts +2 -2
- package/dist/command-schema.js +62 -31
- package/dist/commands.d.ts +7 -6
- package/dist/commands.js +116 -51
- package/dist/defaults.js +13 -6
- package/dist/errors.d.ts +12 -12
- package/dist/errors.js +55 -18
- package/dist/inbox.d.ts +9 -7
- package/dist/inbox.js +107 -62
- package/dist/index.d.ts +25 -24
- package/dist/index.js +11 -11
- package/dist/key-sync.d.ts +4 -4
- package/dist/key-sync.js +88 -50
- package/dist/keys.d.ts +7 -6
- package/dist/keys.js +187 -93
- package/dist/message-storage-sqlite.d.ts +1 -1
- package/dist/message-storage-sqlite.js +32 -27
- package/dist/message-storage.d.ts +2 -2
- package/dist/messaging-metadata.d.ts +4 -4
- package/dist/messaging-metadata.js +73 -46
- package/dist/metadata.d.ts +3 -3
- package/dist/metadata.js +29 -15
- package/dist/modes.d.ts +7 -7
- package/dist/modes.js +53 -24
- package/dist/nip4e-compat.d.ts +2 -2
- package/dist/nip4e-compat.js +2 -2
- package/dist/nipcd.d.ts +14 -14
- package/dist/nipcd.js +225 -126
- package/dist/protocol.d.ts +7 -6
- package/dist/protocol.js +101 -54
- package/dist/public-inbox.d.ts +17 -15
- package/dist/public-inbox.js +129 -138
- package/dist/public-thread.d.ts +7 -4
- package/dist/public-thread.js +205 -88
- package/dist/relay-pool.d.ts +5 -5
- package/dist/relay-pool.js +172 -67
- package/dist/relay-roles.js +22 -13
- package/dist/relay.d.ts +11 -11
- package/dist/relay.js +194 -100
- package/dist/request-timing.d.ts +2 -2
- package/dist/request-timing.js +19 -7
- package/dist/session.js +7 -5
- package/dist/signer.d.ts +1 -1
- package/dist/signers/bunker-relays.d.ts +2 -2
- package/dist/signers/bunker-relays.js +16 -13
- package/dist/signers/bunker.d.ts +2 -2
- package/dist/signers/bunker.js +57 -37
- package/dist/signers/nsec.d.ts +2 -2
- package/dist/signers/nsec.js +8 -8
- package/dist/signers.d.ts +8 -8
- package/dist/signers.js +25 -18
- package/dist/storage-sqlite.d.ts +3 -1
- package/dist/storage-sqlite.js +110 -58
- package/dist/storage.d.ts +10 -6
- package/dist/store.d.ts +12 -8
- package/dist/store.js +156 -78
- package/docs/ACCESS.md +14 -25
- package/docs/API.md +125 -79
- package/docs/KEYS.md +3 -3
- package/docs/NIP-CD.md +29 -19
- package/docs/PUBLIC.md +33 -23
- package/docs/RECOVERY.md +7 -5
- package/docs/RELAYS.md +6 -6
- package/docs/SESSIONS.md +25 -21
- package/docs/SIGNERS.md +5 -3
- package/docs/STORAGE.md +15 -15
- package/docs/TUTORIAL.md +42 -39
- package/package.json +1 -37
- package/dist/inbound-policy.d.ts +0 -4
- package/dist/inbound-policy.js +0 -9
package/dist/bot-handlers.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { markDeferredRequestFailure } from
|
|
3
|
-
import { commandArguments } from
|
|
4
|
-
import { InvalidArgsError } from
|
|
5
|
-
import { inputOf } from
|
|
6
|
-
import { messageSession } from
|
|
7
|
-
import { parseCommandHead, matchesCommandScopes, parseCommand, validateCommandDefinition } from
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { markDeferredRequestFailure } from "./request-timing.js";
|
|
3
|
+
import { commandArguments } from "./command-schema.js";
|
|
4
|
+
import { InvalidArgsError } from "./errors.js";
|
|
5
|
+
import { inputOf, } from "./public-thread.js";
|
|
6
|
+
import { messageSession } from "./session.js";
|
|
7
|
+
import { parseCommandHead, matchesCommandScopes, parseCommand, validateCommandDefinition, } from "./nipcd.js";
|
|
8
|
+
const defaultCommandScopes = [
|
|
9
|
+
"kind:14",
|
|
10
|
+
"kind:1",
|
|
11
|
+
"kind:1111",
|
|
12
|
+
];
|
|
8
13
|
export class BotHandlers {
|
|
9
14
|
options;
|
|
10
15
|
middleware = [];
|
|
@@ -15,13 +20,16 @@ export class BotHandlers {
|
|
|
15
20
|
detachPublic;
|
|
16
21
|
validatorFailures = new WeakMap();
|
|
17
22
|
invalidArgs = new WeakMap();
|
|
18
|
-
argumentError(ctx, error) {
|
|
23
|
+
argumentError(ctx, error) {
|
|
24
|
+
this.invalidArgs.set(ctx, error);
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
19
27
|
routing = new WeakMap();
|
|
20
28
|
disposed = false;
|
|
21
29
|
boundClient;
|
|
22
30
|
get client() {
|
|
23
31
|
if (!this.boundClient)
|
|
24
|
-
throw new Error(
|
|
32
|
+
throw new Error("Bot handlers are not attached");
|
|
25
33
|
return this.boundClient;
|
|
26
34
|
}
|
|
27
35
|
releaseDefinitions = new Map();
|
|
@@ -37,12 +45,12 @@ export class BotHandlers {
|
|
|
37
45
|
for (const definition of this.definitions.values()) {
|
|
38
46
|
this.releaseDefinitions.set(definition.id, client.registerCommandDefinition(definition));
|
|
39
47
|
}
|
|
40
|
-
this.detach = client.handle(message => this.dispatchMessage(client, message));
|
|
41
|
-
this.detachPublic = client.handlePublic(input => this.dispatchPublic(client, input));
|
|
48
|
+
this.detach = client.handle((message, admit, evidence) => this.dispatchMessage(client, message, admit, evidence), true);
|
|
49
|
+
this.detachPublic = client.handlePublic((input) => this.dispatchPublic(client, input));
|
|
42
50
|
}
|
|
43
51
|
assertActive() {
|
|
44
52
|
if (this.disposed) {
|
|
45
|
-
throw new Error(
|
|
53
|
+
throw new Error("Bot is disposed");
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
use(fn) {
|
|
@@ -52,7 +60,7 @@ export class BotHandlers {
|
|
|
52
60
|
}
|
|
53
61
|
register(definition) {
|
|
54
62
|
if (this.definitions.has(definition.id))
|
|
55
|
-
throw new TypeError(
|
|
63
|
+
throw new TypeError("Duplicate local command definition id");
|
|
56
64
|
if (this.boundClient)
|
|
57
65
|
this.releaseDefinitions.set(definition.id, this.client.registerCommandDefinition(definition));
|
|
58
66
|
this.definitions.set(definition.id, definition);
|
|
@@ -60,34 +68,53 @@ export class BotHandlers {
|
|
|
60
68
|
/** All definitions are public on configured write relays. Authorization stays separate. */
|
|
61
69
|
command(command, fn, options = {}) {
|
|
62
70
|
this.assertActive();
|
|
63
|
-
if (
|
|
64
|
-
throw new TypeError(
|
|
65
|
-
if (
|
|
66
|
-
|
|
71
|
+
if ("publish" in options)
|
|
72
|
+
throw new TypeError("Commands are always public");
|
|
73
|
+
if ("id" in options ||
|
|
74
|
+
(typeof command === "object" && command !== null && "id" in command))
|
|
75
|
+
throw new TypeError("Custom command id is not supported; the command name determines its published identifier");
|
|
67
76
|
const { title, description, authorize } = options;
|
|
68
|
-
if (typeof command !==
|
|
69
|
-
throw new TypeError(
|
|
77
|
+
if (typeof command !== "object" || command === null)
|
|
78
|
+
throw new TypeError("Use a command definition object");
|
|
70
79
|
const schema = command.args ?? z.object({});
|
|
71
|
-
const definition = {
|
|
80
|
+
const definition = {
|
|
81
|
+
...command,
|
|
82
|
+
scopes: command.scopes ?? defaultCommandScopes,
|
|
83
|
+
args: commandArguments(schema),
|
|
84
|
+
id: command.command,
|
|
85
|
+
title: command.title ?? title ?? command.command,
|
|
86
|
+
description: command.description ?? description ?? `Run /${command.command}.`,
|
|
87
|
+
};
|
|
72
88
|
const snapshot = validateCommandDefinition(definition);
|
|
73
|
-
const kinds = (snapshot.scopes ?? []).filter(scope => scope.startsWith(
|
|
74
|
-
if (!kinds.length ||
|
|
75
|
-
|
|
89
|
+
const kinds = (snapshot.scopes ?? []).filter((scope) => scope.startsWith("kind:"));
|
|
90
|
+
if (!kinds.length ||
|
|
91
|
+
kinds.some((scope) => !defaultCommandScopes.includes(scope)) ||
|
|
92
|
+
new Set(kinds).size !== kinds.length)
|
|
93
|
+
throw new TypeError(`Commands require distinct supported kind scopes: ${defaultCommandScopes.join(", ")}`);
|
|
76
94
|
this.register(snapshot);
|
|
77
95
|
this.commandHandlers.set(snapshot.id, async (ctx, executor) => {
|
|
78
|
-
if (this.definitions.get(snapshot.id) !== snapshot ||
|
|
96
|
+
if (this.definitions.get(snapshot.id) !== snapshot ||
|
|
97
|
+
!this.releaseDefinitions.get(snapshot.id)?.active()) {
|
|
79
98
|
return false;
|
|
80
99
|
}
|
|
81
100
|
const routing = this.routing.get(ctx);
|
|
101
|
+
if (!routing)
|
|
102
|
+
throw new Error("Missing authenticated command context");
|
|
82
103
|
const head = parseCommandHead(routing.event.content, snapshot.command, executor);
|
|
83
|
-
if (head.status !==
|
|
104
|
+
if (head.status !== "matched" ||
|
|
105
|
+
!matchesCommandScopes(snapshot.scopes ?? [], routing.event, {
|
|
106
|
+
relay: routing.relay,
|
|
107
|
+
}))
|
|
84
108
|
return false;
|
|
85
|
-
const parsed = parseCommand(snapshot, routing.event, {
|
|
109
|
+
const parsed = parseCommand(snapshot, routing.event, {
|
|
110
|
+
executor,
|
|
111
|
+
relay: routing.relay,
|
|
112
|
+
});
|
|
86
113
|
// An args-dependent authorization cannot authorize an error response for malformed input.
|
|
87
|
-
if (parsed.status !==
|
|
114
|
+
if (parsed.status !== "matched") {
|
|
88
115
|
if (authorize)
|
|
89
116
|
return true;
|
|
90
|
-
throw this.argumentError(ctx, new InvalidArgsError(snapshot.command,
|
|
117
|
+
throw this.argumentError(ctx, new InvalidArgsError(snapshot.command, "decode"));
|
|
91
118
|
}
|
|
92
119
|
let validated;
|
|
93
120
|
try {
|
|
@@ -103,15 +130,35 @@ export class BotHandlers {
|
|
|
103
130
|
if (!validated.success) {
|
|
104
131
|
if (authorize)
|
|
105
132
|
return true;
|
|
106
|
-
const names = new Set((snapshot.args ?? []).map(argument => argument.name));
|
|
107
|
-
const codes = new Set([
|
|
108
|
-
|
|
133
|
+
const names = new Set((snapshot.args ?? []).map((argument) => argument.name));
|
|
134
|
+
const codes = new Set([
|
|
135
|
+
"invalid_type",
|
|
136
|
+
"too_small",
|
|
137
|
+
"too_big",
|
|
138
|
+
"invalid_format",
|
|
139
|
+
"invalid_value",
|
|
140
|
+
"custom",
|
|
141
|
+
"unrecognized_keys",
|
|
142
|
+
"invalid_union",
|
|
143
|
+
"not_multiple_of",
|
|
144
|
+
]);
|
|
145
|
+
throw this.argumentError(ctx, new InvalidArgsError(snapshot.command, "validation", validated.error.issues.slice(0, 20).map((issue) => ({
|
|
146
|
+
code: codes.has(issue.code) ? issue.code : "custom",
|
|
147
|
+
path: typeof issue.path[0] === "string" && names.has(issue.path[0])
|
|
148
|
+
? [issue.path[0]]
|
|
149
|
+
: [],
|
|
150
|
+
}))));
|
|
109
151
|
}
|
|
110
152
|
const args = validated.data;
|
|
111
153
|
const invocation = { ...parsed.invocation, args };
|
|
112
|
-
if (!authorize || await authorize(ctx, invocation)) {
|
|
154
|
+
if (!authorize || (await authorize(ctx, invocation))) {
|
|
113
155
|
const descriptors = Object.getOwnPropertyDescriptors(ctx);
|
|
114
|
-
descriptors.args = {
|
|
156
|
+
descriptors.args = {
|
|
157
|
+
value: args,
|
|
158
|
+
enumerable: true,
|
|
159
|
+
configurable: false,
|
|
160
|
+
writable: false,
|
|
161
|
+
};
|
|
115
162
|
const commandContext = Object.create(Object.getPrototypeOf(ctx), descriptors);
|
|
116
163
|
await fn(commandContext, args);
|
|
117
164
|
}
|
|
@@ -121,14 +168,15 @@ export class BotHandlers {
|
|
|
121
168
|
return this;
|
|
122
169
|
}
|
|
123
170
|
getCommandDefinitions() {
|
|
124
|
-
return structuredClone([...this.definitions.values()].filter(definition => !this.boundClient ||
|
|
171
|
+
return structuredClone([...this.definitions.values()].filter((definition) => !this.boundClient ||
|
|
172
|
+
this.releaseDefinitions.get(definition.id)?.active()));
|
|
125
173
|
}
|
|
126
174
|
/** Register the handler for messages with no matching command. */
|
|
127
175
|
handle(fn) {
|
|
128
176
|
this.assertActive();
|
|
129
177
|
if (this.fallback)
|
|
130
|
-
throw new Error(
|
|
131
|
-
const fallback = ctx => fn(ctx);
|
|
178
|
+
throw new Error("A message handler is already registered");
|
|
179
|
+
const fallback = (ctx) => fn(ctx);
|
|
132
180
|
this.fallback = fallback;
|
|
133
181
|
return () => {
|
|
134
182
|
if (this.fallback === fallback)
|
|
@@ -140,47 +188,55 @@ export class BotHandlers {
|
|
|
140
188
|
return this;
|
|
141
189
|
}
|
|
142
190
|
sessionStore(client) {
|
|
143
|
-
return this.options.sessionStore ?? {
|
|
144
|
-
get: peer => client.getSession(peer),
|
|
191
|
+
return (this.options.sessionStore ?? {
|
|
192
|
+
get: (peer) => client.getSession(peer),
|
|
145
193
|
set: (peer, value) => client.setSession(peer, value),
|
|
146
|
-
};
|
|
194
|
+
});
|
|
147
195
|
}
|
|
148
|
-
async dispatchMessage(client, message) {
|
|
196
|
+
async dispatchMessage(client, message, admit, evidence) {
|
|
149
197
|
if (this.disposed) {
|
|
150
198
|
return;
|
|
151
199
|
}
|
|
152
|
-
const anchor = structuredClone(message
|
|
200
|
+
const anchor = structuredClone(message);
|
|
153
201
|
const { session, commit } = messageSession(this.sessionStore(client), message.conversation);
|
|
154
202
|
const ctx = {
|
|
155
203
|
session,
|
|
156
|
-
input:
|
|
157
|
-
thread: options => client.
|
|
158
|
-
message,
|
|
204
|
+
input: client.inputForMessage(message),
|
|
205
|
+
thread: (options) => client.threadPrivate(anchor, options),
|
|
159
206
|
sender: message.sender,
|
|
160
207
|
conversation: message.conversation,
|
|
161
|
-
reply: (text, options) => client.
|
|
162
|
-
replyFile: (data, options) => client.
|
|
163
|
-
react: (reaction
|
|
164
|
-
getMessage: id => client.getMessage(id, message.conversation),
|
|
165
|
-
history: options => client.history(message.conversation, options)
|
|
208
|
+
reply: (text, options) => client.send(anchor.conversation, text, options, evidence),
|
|
209
|
+
replyFile: (data, options) => client.sendFile(anchor.conversation, data, { ...options, replyTo: anchor.id }, evidence),
|
|
210
|
+
react: (reaction) => client.reactToMessage(anchor, reaction, evidence),
|
|
166
211
|
};
|
|
167
|
-
return this.dispatch(client, ctx, commit,
|
|
212
|
+
return this.dispatch(client, ctx, commit, anchor.rumor, anchor.relay, admit);
|
|
168
213
|
}
|
|
169
214
|
async dispatchPublic(client, input) {
|
|
170
215
|
if (this.disposed)
|
|
171
216
|
return;
|
|
172
|
-
const anchor = structuredClone(input
|
|
173
|
-
const store = this.options.sessionStore ?? {
|
|
217
|
+
const anchor = structuredClone(input);
|
|
218
|
+
const store = this.options.sessionStore ?? {
|
|
219
|
+
get: (key) => client.getPublicSession(key),
|
|
220
|
+
set: (key, value) => client.setPublicSession(key, value),
|
|
221
|
+
};
|
|
174
222
|
const { session, commit } = messageSession(store, input.conversation);
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
223
|
+
const ctx = {
|
|
224
|
+
input: inputOf(input.event),
|
|
225
|
+
sender: input.event.pubkey,
|
|
226
|
+
conversation: input.conversation,
|
|
227
|
+
session,
|
|
228
|
+
reply: (text, options) => {
|
|
229
|
+
if (options && Object.keys(options).length)
|
|
230
|
+
return Promise.reject(new TypeError("DM send options are not valid for public replies"));
|
|
231
|
+
return client.replyPublic(anchor, text);
|
|
232
|
+
},
|
|
233
|
+
replyFile: (data, options) => client.replyPublicFile(anchor, data, options),
|
|
234
|
+
thread: (options) => client.threadPublic(anchor, options),
|
|
235
|
+
react: (reaction) => client.reactPublic(anchor, reaction),
|
|
236
|
+
};
|
|
181
237
|
return this.dispatch(client, ctx, commit, input.event, input.relay);
|
|
182
238
|
}
|
|
183
|
-
async dispatch(client, ctx, commit, event, relay) {
|
|
239
|
+
async dispatch(client, ctx, commit, event, relay, admit) {
|
|
184
240
|
this.routing.set(ctx, { event: structuredClone(event), relay });
|
|
185
241
|
const middleware = [...this.middleware];
|
|
186
242
|
const commands = [...this.commandHandlers.values()];
|
|
@@ -188,16 +244,19 @@ export class BotHandlers {
|
|
|
188
244
|
let last = -1;
|
|
189
245
|
const dispatch = async (i) => {
|
|
190
246
|
if (i <= last) {
|
|
191
|
-
throw new Error(
|
|
247
|
+
throw new Error("next() called more than once");
|
|
192
248
|
}
|
|
193
249
|
last = i;
|
|
194
250
|
if (middleware[i]) {
|
|
195
251
|
await middleware[i](ctx, () => dispatch(i + 1));
|
|
196
252
|
}
|
|
197
253
|
else {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
254
|
+
admit?.();
|
|
255
|
+
if (event.kind !== 15) {
|
|
256
|
+
for (const command of commands) {
|
|
257
|
+
if (await command(ctx, client.pubkey))
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
201
260
|
}
|
|
202
261
|
await fallback?.(ctx);
|
|
203
262
|
}
|
|
@@ -216,12 +275,12 @@ export class BotHandlers {
|
|
|
216
275
|
await this.errorHandler(e, ctx);
|
|
217
276
|
}
|
|
218
277
|
catch {
|
|
219
|
-
// An observer failure must not replace the original
|
|
278
|
+
// An observer failure must not replace the original error.
|
|
220
279
|
}
|
|
221
280
|
}
|
|
222
281
|
if (e instanceof InvalidArgsError && e === this.invalidArgs.get(ctx))
|
|
223
|
-
return; //
|
|
224
|
-
// Business errors
|
|
282
|
+
return; // Expected input errors are observed once and not reported as operations.
|
|
283
|
+
// Business errors reach the operational observer; the input ID stays claimed.
|
|
225
284
|
throw e;
|
|
226
285
|
}
|
|
227
286
|
// Exit the reply-capable middleware/catch chain before reporting an unapproved validator exception.
|
package/dist/bot.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { ReplyFileOptions, SendFileOptions, UploadFileOptions } from
|
|
2
|
-
import type { SessionStore } from
|
|
3
|
-
import { type ClientOptions, type ErrorHandler, type IntakeMetadata, type SendOptions, type MessageObserver } from
|
|
4
|
-
import { type Middleware } from
|
|
5
|
-
import type { AnnounceOptions } from
|
|
6
|
-
import type { BotCommandOptions, CommandHandler, Context, MessageHandler } from
|
|
7
|
-
import type { BotCommandDefinition, DiscoverCommandsOptions } from
|
|
8
|
-
import type { Event } from
|
|
9
|
-
import type { Rumor } from
|
|
10
|
-
import type { ThreadOptions } from
|
|
11
|
-
import type { Message, MessageListOptions } from
|
|
12
|
-
export type { CommandContext, BotCommandOptions, CommandHandler, Context, MessageHandler, Middleware, Next } from
|
|
13
|
-
export type { Session, SessionStore } from
|
|
1
|
+
import type { ReplyFileOptions, SendFileOptions, UploadFileOptions } from "./blossom.js";
|
|
2
|
+
import type { SessionStore } from "./session.js";
|
|
3
|
+
import { type ClientOptions, type ErrorHandler, type IntakeMetadata, type SendOptions, type MessageObserver } from "./client.js";
|
|
4
|
+
import { type Middleware } from "./bot-handlers.js";
|
|
5
|
+
import type { AnnounceOptions } from "./keys.js";
|
|
6
|
+
import type { BotCommandOptions, CommandHandler, Context, MessageHandler } from "./bot-handlers.js";
|
|
7
|
+
import type { BotCommandDefinition, DiscoverCommandsOptions } from "./nipcd.js";
|
|
8
|
+
import type { Event } from "nostr-tools";
|
|
9
|
+
import type { Rumor } from "./protocol.js";
|
|
10
|
+
import type { ThreadOptions } from "./public-thread.js";
|
|
11
|
+
import type { Message, MessageListOptions } from "./store.js";
|
|
12
|
+
export type { CommandContext, BotCommandOptions, CommandHandler, Context, MessageHandler, Middleware, Next, } from "./bot-handlers.js";
|
|
13
|
+
export type { Session, SessionStore } from "./session.js";
|
|
14
14
|
export type BotOptions<S = Record<string, unknown>> = ClientOptions & {
|
|
15
15
|
sessionStore?: SessionStore<S>;
|
|
16
16
|
};
|
|
17
17
|
export declare class Bot<S = Record<string, unknown>> {
|
|
18
18
|
#private;
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(input: BotOptions<S>);
|
|
20
20
|
get pubkey(): string;
|
|
21
21
|
get mode(): import("./modes.js").ProtocolMode;
|
|
22
22
|
use(fn: Middleware<S>): this;
|
|
@@ -37,19 +37,16 @@ export declare class Bot<S = Record<string, unknown>> {
|
|
|
37
37
|
send(peer: string, text: string, options?: SendOptions): Promise<import("./client.js").SendResult>;
|
|
38
38
|
uploadFile(data: Uint8Array, options?: UploadFileOptions): Promise<import("./blossom.js").UploadFileResult>;
|
|
39
39
|
sendFile(peer: string, data: Uint8Array, options?: SendFileOptions): Promise<import("./client.js").SendResult>;
|
|
40
|
-
|
|
40
|
+
dmHistory(peerPubkey: string, options?: {
|
|
41
41
|
limit?: number;
|
|
42
42
|
cursor?: string;
|
|
43
43
|
}): import("./store.js").HistoryPage;
|
|
44
|
-
react(
|
|
44
|
+
react(event: Event | Rumor, reaction?: string): Promise<import("./client.js").SendResult>;
|
|
45
45
|
getMessage(id: string): Message | undefined;
|
|
46
46
|
idle(): Promise<void>;
|
|
47
|
-
receive(event: Event, source:
|
|
47
|
+
receive(event: Event, source: "live" | "history", metadata?: IntakeMetadata): Promise<boolean>;
|
|
48
48
|
getMessageState(id: string): import("./storage.js").MessageState | undefined;
|
|
49
49
|
listMessages(options?: MessageListOptions): import("./store.js").MessageList;
|
|
50
|
-
retryInbox(options?: {
|
|
51
|
-
ids?: readonly string[];
|
|
52
|
-
}): Promise<void>;
|
|
53
50
|
getSession(peer: string): Promise<Partial<S> | undefined>;
|
|
54
51
|
setSession(peer: string, value: Partial<S>): Promise<void>;
|
|
55
52
|
syncHistory(): Promise<import("./inbox.js").HistorySyncResult[]>;
|