chirli 0.0.0-stage → 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 +103 -0
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +22 -0
- package/README.md +281 -2
- package/SECURITY.md +55 -0
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/dist/allowlist.d.ts +3 -0
- package/dist/allowlist.js +9 -0
- package/dist/announcements.d.ts +25 -0
- package/dist/announcements.js +142 -0
- package/dist/attachments.d.ts +43 -0
- package/dist/attachments.js +340 -0
- package/dist/blossom.d.ts +30 -0
- package/dist/blossom.js +233 -0
- package/dist/bot-handlers.d.ts +70 -0
- package/dist/bot-handlers.js +317 -0
- package/dist/bot.d.ts +63 -0
- package/dist/bot.js +244 -0
- package/dist/client.d.ts +221 -0
- package/dist/client.js +1197 -0
- package/dist/command-discovery.d.ts +4 -0
- package/dist/command-discovery.js +33 -0
- package/dist/command-schema.d.ts +4 -0
- package/dist/command-schema.js +101 -0
- package/dist/commands.d.ts +32 -0
- package/dist/commands.js +253 -0
- package/dist/defaults.d.ts +9 -0
- package/dist/defaults.js +22 -0
- package/dist/errors.d.ts +55 -0
- package/dist/errors.js +126 -0
- package/dist/inbox.d.ts +55 -0
- package/dist/inbox.js +376 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +11 -0
- package/dist/key-sync.d.ts +33 -0
- package/dist/key-sync.js +293 -0
- package/dist/keys.d.ts +66 -0
- package/dist/keys.js +418 -0
- package/dist/message-storage-sqlite.d.ts +6 -0
- package/dist/message-storage-sqlite.js +90 -0
- package/dist/message-storage.d.ts +32 -0
- package/dist/message-storage.js +1 -0
- package/dist/messaging-metadata.d.ts +48 -0
- package/dist/messaging-metadata.js +280 -0
- package/dist/metadata.d.ts +7 -0
- package/dist/metadata.js +63 -0
- package/dist/modes.d.ts +26 -0
- package/dist/modes.js +108 -0
- package/dist/nip4e-compat.d.ts +4 -0
- package/dist/nip4e-compat.js +14 -0
- package/dist/nipcd.d.ts +109 -0
- package/dist/nipcd.js +555 -0
- package/dist/protocol.d.ts +68 -0
- package/dist/protocol.js +302 -0
- package/dist/public-inbox.d.ts +66 -0
- package/dist/public-inbox.js +295 -0
- package/dist/public-thread.d.ts +62 -0
- package/dist/public-thread.js +436 -0
- package/dist/relay-pool.d.ts +43 -0
- package/dist/relay-pool.js +429 -0
- package/dist/relay-roles.d.ts +18 -0
- package/dist/relay-roles.js +55 -0
- package/dist/relay.d.ts +52 -0
- package/dist/relay.js +493 -0
- package/dist/request-timing.d.ts +12 -0
- package/dist/request-timing.js +37 -0
- package/dist/session.d.ts +16 -0
- package/dist/session.js +51 -0
- package/dist/signer.d.ts +13 -0
- package/dist/signer.js +1 -0
- package/dist/signers/bunker-relays.d.ts +15 -0
- package/dist/signers/bunker-relays.js +87 -0
- package/dist/signers/bunker.d.ts +7 -0
- package/dist/signers/bunker.js +194 -0
- package/dist/signers/nsec.d.ts +3 -0
- package/dist/signers/nsec.js +62 -0
- package/dist/signers.d.ts +18 -0
- package/dist/signers.js +59 -0
- package/dist/storage-sqlite.d.ts +29 -0
- package/dist/storage-sqlite.js +221 -0
- package/dist/storage.d.ts +85 -0
- package/dist/storage.js +1 -0
- package/dist/store.d.ts +96 -0
- package/dist/store.js +404 -0
- package/docs/ACCESS.md +28 -0
- package/docs/API.md +382 -0
- package/docs/INTEROPERABILITY.md +32 -0
- package/docs/KEYS.md +75 -0
- package/docs/NIP-CD.md +112 -0
- package/docs/PUBLIC.md +88 -0
- package/docs/RECOVERY.md +59 -0
- package/docs/RELAYS.md +145 -0
- package/docs/SESSIONS.md +108 -0
- package/docs/SIGNERS.md +59 -0
- package/docs/STORAGE.md +71 -0
- package/docs/TUTORIAL.md +178 -0
- package/package.json +47 -4
package/dist/bot.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { Client, rejectRemovedIntakeOptions, } from "./client.js";
|
|
2
|
+
import { BotHandlers } from "./bot-handlers.js";
|
|
3
|
+
export class Bot {
|
|
4
|
+
#client;
|
|
5
|
+
#opening;
|
|
6
|
+
#starting;
|
|
7
|
+
#stopping;
|
|
8
|
+
#closing;
|
|
9
|
+
#generation = 0;
|
|
10
|
+
#handlers;
|
|
11
|
+
#errorHandlers = new Set();
|
|
12
|
+
#observers = new Set();
|
|
13
|
+
#options;
|
|
14
|
+
constructor(input) {
|
|
15
|
+
rejectRemovedIntakeOptions(input);
|
|
16
|
+
const { sessionStore, ...options } = input;
|
|
17
|
+
this.#options = {
|
|
18
|
+
...options,
|
|
19
|
+
relays: options.relays?.slice(),
|
|
20
|
+
dmRelays: options.dmRelays?.slice(),
|
|
21
|
+
readRelays: options.readRelays?.slice(),
|
|
22
|
+
writeRelays: options.writeRelays?.slice(),
|
|
23
|
+
discoveryRelays: options.discoveryRelays?.slice(),
|
|
24
|
+
blossomServers: options.blossomServers?.slice(),
|
|
25
|
+
blossomDownloadOrigins: options.blossomDownloadOrigins?.slice(),
|
|
26
|
+
publicInbox: options.publicInbox
|
|
27
|
+
? {
|
|
28
|
+
...options.publicInbox,
|
|
29
|
+
relays: options.publicInbox.relays.slice(),
|
|
30
|
+
thread: options.publicInbox.thread
|
|
31
|
+
? { ...options.publicInbox.thread }
|
|
32
|
+
: undefined,
|
|
33
|
+
}
|
|
34
|
+
: undefined,
|
|
35
|
+
storageKey: options.storageKey?.slice(),
|
|
36
|
+
};
|
|
37
|
+
this.#handlers = new BotHandlers(undefined, { sessionStore });
|
|
38
|
+
}
|
|
39
|
+
#ready() {
|
|
40
|
+
if (!this.#client)
|
|
41
|
+
throw new Error("Call and await bot.start() before accessing bot state");
|
|
42
|
+
return this.#client;
|
|
43
|
+
}
|
|
44
|
+
#open() {
|
|
45
|
+
if (this.#closing)
|
|
46
|
+
return Promise.reject(new Error("Bot is closed or closing"));
|
|
47
|
+
if (this.#client)
|
|
48
|
+
return Promise.resolve(this.#client);
|
|
49
|
+
this.#opening ??= Client.create(this.#options)
|
|
50
|
+
.then((client) => {
|
|
51
|
+
try {
|
|
52
|
+
this.#handlers.attach(client);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return client.close().then(() => {
|
|
56
|
+
throw error;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
client.onError((error, message) => {
|
|
60
|
+
for (const handler of this.#errorHandlers) {
|
|
61
|
+
void Promise.resolve()
|
|
62
|
+
.then(() => handler(error, message))
|
|
63
|
+
.catch(() => { });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
client.on("message", (message) => {
|
|
67
|
+
for (const observer of this.#observers) {
|
|
68
|
+
void Promise.resolve()
|
|
69
|
+
.then(() => observer(client.withAttachment(structuredClone(message))))
|
|
70
|
+
.catch((error) => client.report(error, structuredClone(message)));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
this.#client = client;
|
|
74
|
+
return client;
|
|
75
|
+
})
|
|
76
|
+
.finally(() => {
|
|
77
|
+
this.#opening = undefined;
|
|
78
|
+
});
|
|
79
|
+
return this.#opening;
|
|
80
|
+
}
|
|
81
|
+
get pubkey() {
|
|
82
|
+
return this.#ready().pubkey;
|
|
83
|
+
}
|
|
84
|
+
get mode() {
|
|
85
|
+
return this.#options.mode ?? "nip17";
|
|
86
|
+
}
|
|
87
|
+
use(fn) {
|
|
88
|
+
this.#handlers.use(fn);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
catch(fn) {
|
|
92
|
+
this.#handlers.catch(fn);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
command(command, fn, options) {
|
|
96
|
+
this.#handlers.command(command, fn, options);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
getCommandDefinitions() {
|
|
100
|
+
return this.#handlers.getCommandDefinitions();
|
|
101
|
+
}
|
|
102
|
+
handle(handler) {
|
|
103
|
+
return this.#handlers.handle(handler);
|
|
104
|
+
}
|
|
105
|
+
observe(observer) {
|
|
106
|
+
this.#observers.add(observer);
|
|
107
|
+
return () => {
|
|
108
|
+
this.#observers.delete(observer);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
onError(handler) {
|
|
112
|
+
this.#errorHandlers.add(handler);
|
|
113
|
+
return () => {
|
|
114
|
+
this.#errorHandlers.delete(handler);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
start() {
|
|
118
|
+
if (this.#closing)
|
|
119
|
+
return Promise.reject(new Error("Bot is closed or closing"));
|
|
120
|
+
if (this.#stopping)
|
|
121
|
+
return this.#stopping.then(() => this.start());
|
|
122
|
+
const generation = this.#generation;
|
|
123
|
+
this.#starting ??= this.#open()
|
|
124
|
+
.then((client) => {
|
|
125
|
+
if (this.#generation === generation)
|
|
126
|
+
return client.start(true);
|
|
127
|
+
})
|
|
128
|
+
.finally(() => {
|
|
129
|
+
this.#starting = undefined;
|
|
130
|
+
});
|
|
131
|
+
return this.#starting;
|
|
132
|
+
}
|
|
133
|
+
async stop() {
|
|
134
|
+
this.#client?.assertOutsideHandler();
|
|
135
|
+
if (this.#closing)
|
|
136
|
+
return this.#closing;
|
|
137
|
+
this.#stopping ??= this.#shutdown(false).finally(() => {
|
|
138
|
+
this.#stopping = undefined;
|
|
139
|
+
});
|
|
140
|
+
return this.#stopping;
|
|
141
|
+
}
|
|
142
|
+
async close() {
|
|
143
|
+
this.#client?.assertOutsideHandler();
|
|
144
|
+
if (this.#closing)
|
|
145
|
+
return this.#closing;
|
|
146
|
+
const task = this.#shutdown(true);
|
|
147
|
+
this.#closing = task;
|
|
148
|
+
void task.catch(() => {
|
|
149
|
+
if (this.#closing === task)
|
|
150
|
+
this.#closing = undefined;
|
|
151
|
+
});
|
|
152
|
+
return task;
|
|
153
|
+
}
|
|
154
|
+
async #shutdown(close) {
|
|
155
|
+
this.#generation++;
|
|
156
|
+
const client = this.#client ?? (await this.#opening?.catch(() => undefined));
|
|
157
|
+
if (client) {
|
|
158
|
+
if (close)
|
|
159
|
+
await client.close();
|
|
160
|
+
else
|
|
161
|
+
await client.stop();
|
|
162
|
+
}
|
|
163
|
+
if (close)
|
|
164
|
+
this.#handlers.dispose();
|
|
165
|
+
}
|
|
166
|
+
requestStop() {
|
|
167
|
+
this.#generation++;
|
|
168
|
+
this.#ready().requestStop();
|
|
169
|
+
}
|
|
170
|
+
async announce(options) {
|
|
171
|
+
await (await this.#open()).announce(options);
|
|
172
|
+
}
|
|
173
|
+
async reply(event, text, options) {
|
|
174
|
+
return this.#ready().reply(event, text, options);
|
|
175
|
+
}
|
|
176
|
+
async replyFile(event, data, options) {
|
|
177
|
+
return this.#ready().replyFile(event, data, options);
|
|
178
|
+
}
|
|
179
|
+
async thread(event, options) {
|
|
180
|
+
return this.#ready().thread(event, options);
|
|
181
|
+
}
|
|
182
|
+
send(peer, text, options) {
|
|
183
|
+
return this.#ready().send(peer, text, options);
|
|
184
|
+
}
|
|
185
|
+
uploadFile(data, options) {
|
|
186
|
+
return this.#ready().uploadFile(data, options);
|
|
187
|
+
}
|
|
188
|
+
sendFile(peer, data, options) {
|
|
189
|
+
return this.#ready().sendFile(peer, data, options);
|
|
190
|
+
}
|
|
191
|
+
dmHistory(peerPubkey, options) {
|
|
192
|
+
return this.#ready().history(peerPubkey, options);
|
|
193
|
+
}
|
|
194
|
+
async react(event, reaction) {
|
|
195
|
+
return this.#ready().react(event, reaction);
|
|
196
|
+
}
|
|
197
|
+
getMessage(id) {
|
|
198
|
+
return this.#ready().getMessage(id);
|
|
199
|
+
}
|
|
200
|
+
idle() {
|
|
201
|
+
return this.#ready().idle();
|
|
202
|
+
}
|
|
203
|
+
receive(event, source, metadata) {
|
|
204
|
+
return this.#ready().receive(event, source, metadata);
|
|
205
|
+
}
|
|
206
|
+
getMessageState(id) {
|
|
207
|
+
return this.#ready().getMessageState(id);
|
|
208
|
+
}
|
|
209
|
+
listMessages(options) {
|
|
210
|
+
return this.#ready().listMessages(options);
|
|
211
|
+
}
|
|
212
|
+
async getSession(peer) {
|
|
213
|
+
return structuredClone(await this.#handlers.sessionStore(this.#ready()).get(peer));
|
|
214
|
+
}
|
|
215
|
+
async setSession(peer, value) {
|
|
216
|
+
await this.#handlers
|
|
217
|
+
.sessionStore(this.#ready())
|
|
218
|
+
.set(peer, structuredClone(value));
|
|
219
|
+
}
|
|
220
|
+
syncHistory() {
|
|
221
|
+
return this.#ready().syncHistory();
|
|
222
|
+
}
|
|
223
|
+
syncCommands() {
|
|
224
|
+
return this.#ready().syncCommands();
|
|
225
|
+
}
|
|
226
|
+
discoverCommands(options) {
|
|
227
|
+
return this.#ready().discoverCommands(options);
|
|
228
|
+
}
|
|
229
|
+
flushAnnouncements() {
|
|
230
|
+
return this.#ready().flushAnnouncements();
|
|
231
|
+
}
|
|
232
|
+
flushOutbox() {
|
|
233
|
+
return this.#ready().flushOutbox();
|
|
234
|
+
}
|
|
235
|
+
encryptionKeys() {
|
|
236
|
+
return this.#ready().encryptionKeys();
|
|
237
|
+
}
|
|
238
|
+
rotateEncryptionKey() {
|
|
239
|
+
return this.#ready().rotateEncryptionKey();
|
|
240
|
+
}
|
|
241
|
+
refreshPeer(peer) {
|
|
242
|
+
return this.#ready().refreshPeer(peer);
|
|
243
|
+
}
|
|
244
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { type ReplyFileOptions, type SendFileOptions, type UploadFileOptions, type UploadFileResult } from "./blossom.js";
|
|
2
|
+
import { type PublicInboxOptions, type PublicInput } from "./public-inbox.js";
|
|
3
|
+
import { type Input, type ThreadOptions, type ThreadResult } from "./public-thread.js";
|
|
4
|
+
import { type Event } from "nostr-tools";
|
|
5
|
+
import type { Signer } from "./signer.js";
|
|
6
|
+
import { type Message } from "./store.js";
|
|
7
|
+
import { type Transport, type WebSocketTransportOptions } from "./relay.js";
|
|
8
|
+
import { type DecodedEnvelope, type Rumor } from "./protocol.js";
|
|
9
|
+
import { type ProtocolMode } from "./modes.js";
|
|
10
|
+
import { type ReconnectOptions, type RecoveryOptions } from "./inbox.js";
|
|
11
|
+
import { type CommandDefinition, type DiscoverCommandsOptions } from "./nipcd.js";
|
|
12
|
+
import { type RelayRoles } from "./relay-roles.js";
|
|
13
|
+
import { type KeySyncOptions } from "./key-sync.js";
|
|
14
|
+
import { type MetadataCacheOptions } from "./messaging-metadata.js";
|
|
15
|
+
import { type CommandSyncResult } from "./commands.js";
|
|
16
|
+
import type { MessageState } from "./storage.js";
|
|
17
|
+
import type { MessageStorage } from "./message-storage.js";
|
|
18
|
+
import { type AnnounceOptions, type KeyRotationOptions } from "./keys.js";
|
|
19
|
+
export declare function rejectRemovedIntakeOptions(options: object): void;
|
|
20
|
+
export interface SendResult {
|
|
21
|
+
id: string;
|
|
22
|
+
status: "relay-accepted" | "pending";
|
|
23
|
+
}
|
|
24
|
+
export interface SendOptions {
|
|
25
|
+
/** ID of the decrypted private message being replied to. */
|
|
26
|
+
replyTo?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface IntakeMetadata {
|
|
29
|
+
relay?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface CommonClientOptions {
|
|
32
|
+
publicInbox?: PublicInboxOptions;
|
|
33
|
+
metadataCache?: false | MetadataCacheOptions;
|
|
34
|
+
keySync?: false | KeySyncOptions;
|
|
35
|
+
nip4eCompatibility?: boolean;
|
|
36
|
+
reconnect?: false | ReconnectOptions;
|
|
37
|
+
recovery?: false | RecoveryOptions;
|
|
38
|
+
relays?: string[];
|
|
39
|
+
dmRelays?: string[];
|
|
40
|
+
readRelays?: string[];
|
|
41
|
+
writeRelays?: string[];
|
|
42
|
+
discoveryRelays?: readonly string[];
|
|
43
|
+
blossomServers?: readonly string[];
|
|
44
|
+
blossomDownloadOrigins?: readonly string[];
|
|
45
|
+
/** Root for verified plaintext attachments, scoped by account below this directory. */
|
|
46
|
+
attachmentDirectory?: string;
|
|
47
|
+
storageKey?: Uint8Array;
|
|
48
|
+
historyLimit?: number;
|
|
49
|
+
database?: string;
|
|
50
|
+
messageStorage?: MessageStorage;
|
|
51
|
+
}
|
|
52
|
+
/** Invalid backend and protocol combinations are rejected before runtime in TypeScript. */
|
|
53
|
+
type ClientConfiguration = CommonClientOptions & ({
|
|
54
|
+
transport: Transport;
|
|
55
|
+
transportOptions?: never;
|
|
56
|
+
} | {
|
|
57
|
+
transport?: undefined;
|
|
58
|
+
transportOptions?: WebSocketTransportOptions;
|
|
59
|
+
}) & ({
|
|
60
|
+
mode?: ProtocolMode;
|
|
61
|
+
keyRotation?: false;
|
|
62
|
+
} | {
|
|
63
|
+
mode: "nip4e";
|
|
64
|
+
keyRotation: KeyRotationOptions;
|
|
65
|
+
});
|
|
66
|
+
/** Account credentials are supplied only through signer capabilities. */
|
|
67
|
+
export type ClientOptions = ClientConfiguration & {
|
|
68
|
+
signer: Signer;
|
|
69
|
+
};
|
|
70
|
+
export type CommandRegistration = (() => void) & {
|
|
71
|
+
active(): boolean;
|
|
72
|
+
};
|
|
73
|
+
type AdmitMessage = () => void;
|
|
74
|
+
export type MessageHandler = (message: Message, admit: AdmitMessage, anchor: DecodedEnvelope) => void | Promise<void>;
|
|
75
|
+
export type MessageObserver = (message: Readonly<Message>) => void | Promise<void>;
|
|
76
|
+
export type ErrorHandler = (error: unknown, message?: Message) => void | Promise<void>;
|
|
77
|
+
export declare class Client {
|
|
78
|
+
readonly options: ClientConfiguration & RelayRoles & {
|
|
79
|
+
relays: string[];
|
|
80
|
+
};
|
|
81
|
+
private metadataLookupRelays;
|
|
82
|
+
private readonly attachments;
|
|
83
|
+
private readonly blossomServers;
|
|
84
|
+
private readonly blossomDownloadOrigins;
|
|
85
|
+
private announcements;
|
|
86
|
+
private metadata;
|
|
87
|
+
private keySync?;
|
|
88
|
+
private commandDefinitions;
|
|
89
|
+
private commands;
|
|
90
|
+
private publicInbox?;
|
|
91
|
+
private publicHandlers;
|
|
92
|
+
private commandRevision;
|
|
93
|
+
private syncedCommandRevision;
|
|
94
|
+
private managesCommandCatalog;
|
|
95
|
+
private commandSyncScheduled;
|
|
96
|
+
private revokedCommands;
|
|
97
|
+
private synchronizing?;
|
|
98
|
+
private announcing?;
|
|
99
|
+
private readonly coreStore;
|
|
100
|
+
private readonly account;
|
|
101
|
+
readonly mode: ProtocolMode;
|
|
102
|
+
readonly nip4eCompatibility: boolean;
|
|
103
|
+
private keys;
|
|
104
|
+
private rotationTimer?;
|
|
105
|
+
private protocol;
|
|
106
|
+
private transport;
|
|
107
|
+
private ownsTransport;
|
|
108
|
+
private observers;
|
|
109
|
+
private handlers;
|
|
110
|
+
private errors;
|
|
111
|
+
private queues;
|
|
112
|
+
private intake;
|
|
113
|
+
private sub?;
|
|
114
|
+
private running;
|
|
115
|
+
private dmActivatedAt?;
|
|
116
|
+
private closed;
|
|
117
|
+
private starting?;
|
|
118
|
+
private stopping?;
|
|
119
|
+
private closing?;
|
|
120
|
+
private generation;
|
|
121
|
+
private handlerContext;
|
|
122
|
+
private flushing?;
|
|
123
|
+
get pubkey(): string;
|
|
124
|
+
/** Resolve the account asynchronously, regardless of local or remote signing. */
|
|
125
|
+
static create(options: ClientOptions): Promise<Client>;
|
|
126
|
+
private constructor();
|
|
127
|
+
/** Internal Bot handlers manage history admission through the middleware chain. */
|
|
128
|
+
handle(handler: MessageHandler, managesAdmission?: boolean): () => void;
|
|
129
|
+
/** Receipt observer only: failures cannot change inbox state or replay business work. */
|
|
130
|
+
on(_event: "message", observer: MessageObserver): () => void;
|
|
131
|
+
onError(handler: ErrorHandler): () => void;
|
|
132
|
+
report(error: unknown, message?: Message): void;
|
|
133
|
+
private assertOpen;
|
|
134
|
+
start(publishMetadata?: boolean): Promise<void>;
|
|
135
|
+
private startUp;
|
|
136
|
+
/** Verify and persist a relay event using the same asynchronous signer capabilities. */
|
|
137
|
+
receive(event: Event, source: "live" | "history", metadata?: IntakeMetadata): Promise<boolean>;
|
|
138
|
+
private accept;
|
|
139
|
+
private enqueue;
|
|
140
|
+
idle(): Promise<void>;
|
|
141
|
+
private drainInbox;
|
|
142
|
+
getMessage(id: string, peer?: string): Message | undefined;
|
|
143
|
+
getMessageState(id: string): MessageState | undefined;
|
|
144
|
+
listMessages(options?: import("./store.js").MessageListOptions): import("./store.js").MessageList;
|
|
145
|
+
private assertSessionOpen;
|
|
146
|
+
getSession<T>(peer: string): T | undefined;
|
|
147
|
+
setSession(peer: string, value: unknown): void;
|
|
148
|
+
assertOutsideHandler(operation?: string): void;
|
|
149
|
+
private quiesce;
|
|
150
|
+
private drainStop;
|
|
151
|
+
private stopInternal;
|
|
152
|
+
/** Handler-safe stop request; await stop() outside handlers to drain current work. */
|
|
153
|
+
requestStop(): void;
|
|
154
|
+
stop(): Promise<void>;
|
|
155
|
+
close(): Promise<void>;
|
|
156
|
+
syncHistory(): Promise<import("./inbox.js").HistorySyncResult[]>;
|
|
157
|
+
history(peer: string, options?: {
|
|
158
|
+
limit?: number;
|
|
159
|
+
cursor?: string;
|
|
160
|
+
}): import("./store.js").HistoryPage;
|
|
161
|
+
withAttachment(message: Message): Message;
|
|
162
|
+
inputForMessage(message: Message): Input;
|
|
163
|
+
/** Rebind an unsigned rumor only to this account's authenticated incoming record. */
|
|
164
|
+
private authenticatedInput;
|
|
165
|
+
/** Application-owned delayed work uses the exact event exposed by ctx.input.event. */
|
|
166
|
+
reply(event: Event | Rumor, text: string, options?: SendOptions): Promise<SendResult>;
|
|
167
|
+
replyFile(event: Event | Rumor, data: Uint8Array, options?: ReplyFileOptions): Promise<SendResult>;
|
|
168
|
+
/** Verified public context retains its source relay without journaling the input. */
|
|
169
|
+
replyPublicFile(target: PublicInput, data: Uint8Array, options?: ReplyFileOptions): Promise<SendResult>;
|
|
170
|
+
thread(event: Event | Rumor, options?: ThreadOptions): Promise<ThreadResult>;
|
|
171
|
+
private publicKinds;
|
|
172
|
+
handlePublic(handler: (input: PublicInput) => Promise<void>): () => void;
|
|
173
|
+
replyPublic(input: PublicInput, text: string): Promise<{
|
|
174
|
+
id: string;
|
|
175
|
+
status: "pending" | "relay-accepted";
|
|
176
|
+
}>;
|
|
177
|
+
threadPublic(input: PublicInput, options?: ThreadOptions): Promise<ThreadResult>;
|
|
178
|
+
getPublicSession<T>(key: string): T | undefined;
|
|
179
|
+
setPublicSession(key: string, value: unknown): void;
|
|
180
|
+
threadPrivate(message: Message, options?: ThreadOptions): Promise<ThreadResult>;
|
|
181
|
+
/** Register one public command coordinate. Startup reconciles the complete local set. */
|
|
182
|
+
registerCommandDefinition(definition: CommandDefinition): CommandRegistration;
|
|
183
|
+
/** Claim the bot-owned command catalog, including an intentionally empty registry. */
|
|
184
|
+
manageCommands(): void;
|
|
185
|
+
hasCommand(id: string): boolean;
|
|
186
|
+
private publicCommandDefinitions;
|
|
187
|
+
private scheduleCommandSync;
|
|
188
|
+
/** Synchronize public definitions and NIP-09 withdrawals on write relays. */
|
|
189
|
+
syncCommands(): Promise<CommandSyncResult>;
|
|
190
|
+
announce(options?: AnnounceOptions): Promise<void>;
|
|
191
|
+
private publishKeyMetadata;
|
|
192
|
+
private publishMetadata;
|
|
193
|
+
/** Retry exact persisted public metadata; it does not register/execute discovered commands. */
|
|
194
|
+
flushAnnouncements(): Promise<void>;
|
|
195
|
+
encryptionKeys(): import("./keys.js").EncryptionKeyStatus;
|
|
196
|
+
rotateEncryptionKey(): Promise<import("./keys.js").EncryptionKeyStatus>;
|
|
197
|
+
private scheduleRotation;
|
|
198
|
+
refreshPeer(peer: string): Promise<{
|
|
199
|
+
encryptionPubkey: string;
|
|
200
|
+
relays: string[];
|
|
201
|
+
}>;
|
|
202
|
+
publishCommand(definition: CommandDefinition): Promise<{
|
|
203
|
+
event: import("nostr-tools").NostrEvent;
|
|
204
|
+
status: "relay-accepted";
|
|
205
|
+
}>;
|
|
206
|
+
revokeCommand(id: string): Promise<{
|
|
207
|
+
event: import("nostr-tools").NostrEvent;
|
|
208
|
+
status: "relay-accepted";
|
|
209
|
+
}>;
|
|
210
|
+
discoverCommands(options: DiscoverCommandsOptions): Promise<import("./nipcd.js").CommandDiscoveryResult>;
|
|
211
|
+
send(peer: string, text: string, { replyTo }?: SendOptions, input?: DecodedEnvelope): Promise<SendResult>;
|
|
212
|
+
uploadFile(data: Uint8Array, options?: UploadFileOptions): Promise<UploadFileResult>;
|
|
213
|
+
sendFile(peer: string, data: Uint8Array, options?: SendFileOptions, input?: DecodedEnvelope): Promise<SendResult>;
|
|
214
|
+
react(event: Event | Rumor, reaction?: string): Promise<SendResult>;
|
|
215
|
+
reactPublic(input: PublicInput, reaction?: string): Promise<SendResult>;
|
|
216
|
+
/** The Bot may use a verified incoming anchor before admitting it to history. */
|
|
217
|
+
reactToMessage(target: Message, reaction?: string, input?: DecodedEnvelope): Promise<SendResult>;
|
|
218
|
+
private publishPrivate;
|
|
219
|
+
flushOutbox(): Promise<void>;
|
|
220
|
+
}
|
|
221
|
+
export {};
|