@mushinjs/plugin-bots 0.3.0 → 0.4.0-next.20261127155650
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/dist/bot.d.ts +31 -5
- package/dist/bot.js +91 -12
- package/dist/bot.js.map +1 -1
- package/dist/commands.d.ts +1 -1
- package/dist/commands.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts +182 -13
- package/dist/manager.js +282 -26
- package/dist/manager.js.map +1 -1
- package/dist/media.d.ts +28 -0
- package/dist/media.js +91 -0
- package/dist/media.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { BotManager } from './manager'\n\nexport * from './archive'\nexport * from './bot'\nexport * from './commands'\nexport * from './manager'\nexport * from './types'\n\nexport default BotManager\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { BotManager } from './manager'\n\nexport * from './archive'\nexport * from './bot'\nexport * from './commands'\nexport * from './manager'\nexport * from './media'\nexport * from './types'\n\nexport default BotManager\n"],"mappings":";;;;;;;AASA,IAAA,cAAe"}
|
package/dist/manager.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AdapterType, BotConnectionInfo, BotPluginEntry, BotRecord, BotRole, BotStatus, Contact, ForwardedMessage, PermissionProvider, ResolvedMedia } from "./types.js";
|
|
1
|
+
import { AdapterType, BotConnectionInfo, BotPluginEntry, BotRecord, BotRole, BotStatus, Contact, ForwardedMessage, PermissionProvider, PluginRun, ResolvedMedia } from "./types.js";
|
|
2
2
|
import { ArgValue, CommandArg, CommandDef, CommandEntry, CommandSettings, CommandSource } from "./commands.js";
|
|
3
3
|
import { Bot, Session } from "./bot.js";
|
|
4
|
-
import { ChannelInfo, Context, LogTag, Message, MessageRecord, MissingDependency, Plugin, Provenance, Segment, Service, UsageEvent } from "@mushinjs/core";
|
|
4
|
+
import { ChannelInfo, Context, Fiber, LogTag, Message, MessageRecord, MissingDependency, Plugin, Provenance, Segment, Service, UsageEvent } from "@mushinjs/core";
|
|
5
5
|
declare module '@mushinjs/core' {
|
|
6
6
|
interface Context {
|
|
7
7
|
bots: BotManager;
|
|
@@ -13,6 +13,7 @@ declare module '@mushinjs/core' {
|
|
|
13
13
|
'bots/message'(record: MessageRecord): void;
|
|
14
14
|
'bots/log'(line: BotLogLine): void;
|
|
15
15
|
'bots/command'(call: CommandCall): void;
|
|
16
|
+
'bots/run'(run: PluginRun): void;
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
/** One log line written inside a bot's context: its adapter, its plugins, or the bot service itself. */
|
|
@@ -58,13 +59,28 @@ export interface RunCommandInput {
|
|
|
58
59
|
}
|
|
59
60
|
/** Lists commands a plugin provides on a bot, e.g. the command nodes of the flows attached to it. */
|
|
60
61
|
export type CommandProvider = (botId: string) => CommandEntry[];
|
|
61
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* A command an app plugin answers on the bots it is turned on for (`BotRecord.appPlugins`), or, when the plugin
|
|
64
|
+
* picks the bots itself, on the bots `bots` picks.
|
|
65
|
+
*/
|
|
62
66
|
interface AppCommand {
|
|
63
67
|
def: CommandDef;
|
|
64
68
|
plugin: string;
|
|
69
|
+
fiber: Fiber;
|
|
65
70
|
handler: (session: Session) => Promise<unknown> | unknown;
|
|
66
71
|
bots?: (botId: string) => boolean;
|
|
67
72
|
}
|
|
73
|
+
/** A chat plugin across the project, for the Plugins page: its switch and the bots that have it on. */
|
|
74
|
+
export interface ProjectChatPlugin {
|
|
75
|
+
package: string;
|
|
76
|
+
kind: 'app' | 'bot';
|
|
77
|
+
/** For a bot plugin, its project switch; an app plugin's is its entry on the Plugins page. */
|
|
78
|
+
enabled: boolean;
|
|
79
|
+
/** An essential bot plugin has no project switch. */
|
|
80
|
+
essential?: boolean;
|
|
81
|
+
/** Bots that have it on. */
|
|
82
|
+
bots: string[];
|
|
83
|
+
}
|
|
68
84
|
export interface BotStatusInfo {
|
|
69
85
|
id: string;
|
|
70
86
|
status: BotStatus;
|
|
@@ -72,6 +88,8 @@ export interface BotStatusInfo {
|
|
|
72
88
|
selfId?: string;
|
|
73
89
|
selfName?: string;
|
|
74
90
|
selfAvatar?: string;
|
|
91
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
92
|
+
invite?: string;
|
|
75
93
|
}
|
|
76
94
|
/** What handling one message cost; see `bots.usage`. */
|
|
77
95
|
export interface MessageUsage {
|
|
@@ -106,6 +124,11 @@ export declare class BotManager extends Service {
|
|
|
106
124
|
private botLogSns;
|
|
107
125
|
private commandProviders;
|
|
108
126
|
private appCommands;
|
|
127
|
+
/** Bot plugins turned off for the whole project; they run on no bot, whatever each bot says. */
|
|
128
|
+
private projectOff;
|
|
129
|
+
private runs;
|
|
130
|
+
/** The context that registered each adapter, to tell which installed plugin adds it. */
|
|
131
|
+
private adapterFibers;
|
|
109
132
|
private permissionProvider?;
|
|
110
133
|
constructor(ctx: Context);
|
|
111
134
|
/**
|
|
@@ -116,9 +139,12 @@ export declare class BotManager extends Service {
|
|
|
116
139
|
[Service.init](): AsyncGenerator<import("cordis").Disposable<Promise<void>>, void, unknown>;
|
|
117
140
|
/** Registers an adapter type. Bots using it start when it loads and stop when it unloads. */
|
|
118
141
|
defineAdapter<C>(adapter: AdapterType<C>): import("cordis").Disposable<Promise<void>>;
|
|
142
|
+
/** The adapters by their `order`, then in the order they were added. */
|
|
119
143
|
adapters(): {
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
qrSetup?: {
|
|
145
|
+
start: string;
|
|
146
|
+
poll: string;
|
|
147
|
+
} | undefined;
|
|
122
148
|
configSchema: import("@mushinjs/core").JsonSchema;
|
|
123
149
|
secrets: string[];
|
|
124
150
|
segments: string[];
|
|
@@ -127,6 +153,16 @@ export declare class BotManager extends Service {
|
|
|
127
153
|
user?: string;
|
|
128
154
|
group?: string;
|
|
129
155
|
};
|
|
156
|
+
hiddenFields: Record<string, string[]>;
|
|
157
|
+
links: {
|
|
158
|
+
url: string;
|
|
159
|
+
label: import("@mushinjs/core").LocalizedText;
|
|
160
|
+
}[];
|
|
161
|
+
color?: string | undefined;
|
|
162
|
+
icon?: string | undefined;
|
|
163
|
+
description?: import("@mushinjs/core").LocalizedText | undefined;
|
|
164
|
+
id: string;
|
|
165
|
+
displayName: import("@mushinjs/core").LocalizedText;
|
|
130
166
|
}[];
|
|
131
167
|
/** Adapters that can send every segment in a message. */
|
|
132
168
|
platformsFor(segments: Segment[]): string[];
|
|
@@ -147,6 +183,8 @@ export declare class BotManager extends Service {
|
|
|
147
183
|
selfId?: string;
|
|
148
184
|
selfName?: string;
|
|
149
185
|
selfAvatar?: string;
|
|
186
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
187
|
+
invite?: string;
|
|
150
188
|
adapter: {
|
|
151
189
|
config: {
|
|
152
190
|
[x: string]: any;
|
|
@@ -156,6 +194,7 @@ export declare class BotManager extends Service {
|
|
|
156
194
|
name: string;
|
|
157
195
|
enabled: boolean;
|
|
158
196
|
plugins: BotPluginEntry[];
|
|
197
|
+
appPlugins?: string[];
|
|
159
198
|
provider?: string;
|
|
160
199
|
commands?: CommandSettings;
|
|
161
200
|
createdAt: number;
|
|
@@ -169,6 +208,8 @@ export declare class BotManager extends Service {
|
|
|
169
208
|
selfId?: string;
|
|
170
209
|
selfName?: string;
|
|
171
210
|
selfAvatar?: string;
|
|
211
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
212
|
+
invite?: string;
|
|
172
213
|
adapter: {
|
|
173
214
|
config: {
|
|
174
215
|
[x: string]: any;
|
|
@@ -178,12 +219,18 @@ export declare class BotManager extends Service {
|
|
|
178
219
|
name: string;
|
|
179
220
|
enabled: boolean;
|
|
180
221
|
plugins: BotPluginEntry[];
|
|
222
|
+
appPlugins?: string[];
|
|
181
223
|
provider?: string;
|
|
182
224
|
commands?: CommandSettings;
|
|
183
225
|
createdAt: number;
|
|
184
226
|
}[];
|
|
185
227
|
private save;
|
|
186
228
|
private validateAdapter;
|
|
229
|
+
/**
|
|
230
|
+
* A new bot's adapter config. A bot created stopped may be saved half filled in (its connection
|
|
231
|
+
* set up later, e.g. "connect later" in the dashboard); it is checked again when it starts.
|
|
232
|
+
*/
|
|
233
|
+
private adapterConfigFor;
|
|
187
234
|
create(input: {
|
|
188
235
|
name: string;
|
|
189
236
|
adapter: {
|
|
@@ -205,6 +252,8 @@ export declare class BotManager extends Service {
|
|
|
205
252
|
selfId?: string;
|
|
206
253
|
selfName?: string;
|
|
207
254
|
selfAvatar?: string;
|
|
255
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
256
|
+
invite?: string;
|
|
208
257
|
adapter: {
|
|
209
258
|
config: {
|
|
210
259
|
[x: string]: any;
|
|
@@ -214,6 +263,7 @@ export declare class BotManager extends Service {
|
|
|
214
263
|
name: string;
|
|
215
264
|
enabled: boolean;
|
|
216
265
|
plugins: BotPluginEntry[];
|
|
266
|
+
appPlugins?: string[];
|
|
217
267
|
provider?: string;
|
|
218
268
|
commands?: CommandSettings;
|
|
219
269
|
createdAt: number;
|
|
@@ -234,6 +284,8 @@ export declare class BotManager extends Service {
|
|
|
234
284
|
selfId?: string;
|
|
235
285
|
selfName?: string;
|
|
236
286
|
selfAvatar?: string;
|
|
287
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
288
|
+
invite?: string;
|
|
237
289
|
adapter: {
|
|
238
290
|
config: {
|
|
239
291
|
[x: string]: any;
|
|
@@ -243,6 +295,7 @@ export declare class BotManager extends Service {
|
|
|
243
295
|
name: string;
|
|
244
296
|
enabled: boolean;
|
|
245
297
|
plugins: BotPluginEntry[];
|
|
298
|
+
appPlugins?: string[];
|
|
246
299
|
provider?: string;
|
|
247
300
|
commands?: CommandSettings;
|
|
248
301
|
createdAt: number;
|
|
@@ -257,9 +310,12 @@ export declare class BotManager extends Service {
|
|
|
257
310
|
/** Log lines name a bot by its id; the dashboard links it to the bot. */
|
|
258
311
|
private label;
|
|
259
312
|
loadBotPlugin(name: string): Promise<Plugin>;
|
|
260
|
-
|
|
313
|
+
/**
|
|
314
|
+
* The plugins a bot can turn on: every installed bot plugin, then each app plugin with chat commands (`kind: 'app'`),
|
|
315
|
+
* with whether it is on for this bot and whether it is turned off for the whole project.
|
|
316
|
+
*/
|
|
317
|
+
plugins(id: string): Promise<({
|
|
261
318
|
missing?: MissingDependency[] | undefined;
|
|
262
|
-
package: string;
|
|
263
319
|
version: string;
|
|
264
320
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
265
321
|
enabled: boolean;
|
|
@@ -271,12 +327,35 @@ export declare class BotManager extends Service {
|
|
|
271
327
|
requires: import("@mushinjs/core").DependencyState[];
|
|
272
328
|
optional: import("@mushinjs/core").DependencyState[];
|
|
273
329
|
};
|
|
274
|
-
|
|
330
|
+
projectOff?: true | undefined;
|
|
331
|
+
package: string;
|
|
332
|
+
kind: "bot";
|
|
333
|
+
} | {
|
|
334
|
+
status: string;
|
|
335
|
+
commands: string[];
|
|
336
|
+
package: string;
|
|
337
|
+
kind: "app";
|
|
338
|
+
version: string;
|
|
339
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
340
|
+
enabled: boolean;
|
|
341
|
+
} | {
|
|
342
|
+
status: string;
|
|
343
|
+
projectOff: boolean;
|
|
344
|
+
package: string;
|
|
345
|
+
kind: "app";
|
|
346
|
+
version: string;
|
|
347
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
348
|
+
enabled: boolean;
|
|
349
|
+
})[]>;
|
|
350
|
+
private botPlugins;
|
|
275
351
|
/** Required app plugins that are not installed, do not fit or are disabled. */
|
|
276
352
|
private missingApps;
|
|
353
|
+
/** The bot's entry for a plugin in `plugins()`. */
|
|
354
|
+
private pluginInfo;
|
|
355
|
+
/** Turns an app plugin's chat commands on or off for one bot. */
|
|
356
|
+
private setAppPlugin;
|
|
277
357
|
enablePlugin(id: string, name: string, config?: Record<string, any>): Promise<{
|
|
278
358
|
missing?: MissingDependency[] | undefined;
|
|
279
|
-
package: string;
|
|
280
359
|
version: string;
|
|
281
360
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
282
361
|
enabled: boolean;
|
|
@@ -288,10 +367,28 @@ export declare class BotManager extends Service {
|
|
|
288
367
|
requires: import("@mushinjs/core").DependencyState[];
|
|
289
368
|
optional: import("@mushinjs/core").DependencyState[];
|
|
290
369
|
};
|
|
370
|
+
projectOff?: true | undefined;
|
|
371
|
+
package: string;
|
|
372
|
+
kind: "bot";
|
|
373
|
+
} | {
|
|
374
|
+
status: string;
|
|
375
|
+
commands: string[];
|
|
376
|
+
package: string;
|
|
377
|
+
kind: "app";
|
|
378
|
+
version: string;
|
|
379
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
380
|
+
enabled: boolean;
|
|
381
|
+
} | {
|
|
382
|
+
status: string;
|
|
383
|
+
projectOff: boolean;
|
|
384
|
+
package: string;
|
|
385
|
+
kind: "app";
|
|
386
|
+
version: string;
|
|
387
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
388
|
+
enabled: boolean;
|
|
291
389
|
} | undefined>;
|
|
292
390
|
disablePlugin(id: string, name: string): Promise<{
|
|
293
391
|
missing?: MissingDependency[] | undefined;
|
|
294
|
-
package: string;
|
|
295
392
|
version: string;
|
|
296
393
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
297
394
|
enabled: boolean;
|
|
@@ -303,10 +400,28 @@ export declare class BotManager extends Service {
|
|
|
303
400
|
requires: import("@mushinjs/core").DependencyState[];
|
|
304
401
|
optional: import("@mushinjs/core").DependencyState[];
|
|
305
402
|
};
|
|
403
|
+
projectOff?: true | undefined;
|
|
404
|
+
package: string;
|
|
405
|
+
kind: "bot";
|
|
406
|
+
} | {
|
|
407
|
+
status: string;
|
|
408
|
+
commands: string[];
|
|
409
|
+
package: string;
|
|
410
|
+
kind: "app";
|
|
411
|
+
version: string;
|
|
412
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
413
|
+
enabled: boolean;
|
|
414
|
+
} | {
|
|
415
|
+
status: string;
|
|
416
|
+
projectOff: boolean;
|
|
417
|
+
package: string;
|
|
418
|
+
kind: "app";
|
|
419
|
+
version: string;
|
|
420
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
421
|
+
enabled: boolean;
|
|
306
422
|
} | undefined>;
|
|
307
423
|
configurePlugin(id: string, name: string, config: Record<string, any>): Promise<{
|
|
308
424
|
missing?: MissingDependency[] | undefined;
|
|
309
|
-
package: string;
|
|
310
425
|
version: string;
|
|
311
426
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
312
427
|
enabled: boolean;
|
|
@@ -318,21 +433,57 @@ export declare class BotManager extends Service {
|
|
|
318
433
|
requires: import("@mushinjs/core").DependencyState[];
|
|
319
434
|
optional: import("@mushinjs/core").DependencyState[];
|
|
320
435
|
};
|
|
436
|
+
projectOff?: true | undefined;
|
|
437
|
+
package: string;
|
|
438
|
+
kind: "bot";
|
|
439
|
+
} | {
|
|
440
|
+
status: string;
|
|
441
|
+
commands: string[];
|
|
442
|
+
package: string;
|
|
443
|
+
kind: "app";
|
|
444
|
+
version: string;
|
|
445
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
446
|
+
enabled: boolean;
|
|
447
|
+
} | {
|
|
448
|
+
status: string;
|
|
449
|
+
projectOff: boolean;
|
|
450
|
+
package: string;
|
|
451
|
+
kind: "app";
|
|
452
|
+
version: string;
|
|
453
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
454
|
+
enabled: boolean;
|
|
321
455
|
} | undefined>;
|
|
322
456
|
/** Puts the plain values of a bot plugin's secret fields into .env and returns the config with `${NAME}` references. */
|
|
323
457
|
private securePlugin;
|
|
324
458
|
private reloadPlugin;
|
|
459
|
+
/**
|
|
460
|
+
* Turns a bot plugin on or off for the whole project. Off, it runs on no bot; each bot keeps its own switch and
|
|
461
|
+
* settings, so turning it back on starts it again where it was on.
|
|
462
|
+
*/
|
|
463
|
+
setProjectPlugin(name: string, enabled: boolean): Promise<ProjectChatPlugin | undefined>;
|
|
464
|
+
/**
|
|
465
|
+
* The chat plugins across the project: each bot plugin with its project switch, and each app plugin with chat
|
|
466
|
+
* commands, with the bots that have it on.
|
|
467
|
+
*/
|
|
468
|
+
projectPlugins(): Promise<ProjectChatPlugin[]>;
|
|
469
|
+
private projectPlugin;
|
|
325
470
|
/** Adds commands to every bot's list. Removed when the calling plugin unloads. */
|
|
326
471
|
defineCommands(provider: CommandProvider): import("cordis").Disposable<Promise<void>>;
|
|
327
472
|
/**
|
|
328
|
-
* Answers a command
|
|
329
|
-
*
|
|
473
|
+
* Answers a command from an app plugin, such as `/persona`, on the bots the user turned the plugin on for (on the
|
|
474
|
+
* bot's Plugins page, or with `bots.plugins.enable`). A plugin that decides itself which bots answer, from its own
|
|
475
|
+
* per-bot settings, passes `bots`, and then has no switch on the bot's page. It answers after flows, like `/help`,
|
|
476
|
+
* and shows in the command list of each bot it answers on.
|
|
330
477
|
*/
|
|
331
478
|
defineCommand(def: CommandDef, handler: AppCommand['handler'], options?: {
|
|
332
479
|
bots?: (botId: string) => boolean;
|
|
333
480
|
}): import("cordis").Disposable<Promise<void>>;
|
|
334
481
|
/** The app plugin command behind a command entry, if an app plugin answers it. */
|
|
335
482
|
appCommandFor(botId: string, entry: CommandEntry): AppCommand | undefined;
|
|
483
|
+
/** Whether an app plugin's command answers on a bot: the plugin's own choice, or the bot's switch for the plugin. */
|
|
484
|
+
private answersOn;
|
|
485
|
+
/** App plugins whose commands have a switch on each bot, with the names of those commands, by package. */
|
|
486
|
+
private chatApps;
|
|
336
487
|
/** Lets the permissions plugin say who is master, admin or user on each bot. */
|
|
337
488
|
usePermissions(provider: PermissionProvider): import("cordis").Disposable<Promise<void>>;
|
|
338
489
|
/** A user's role on a bot; nothing when the permissions plugin is not running. */
|
|
@@ -368,6 +519,24 @@ export declare class BotManager extends Service {
|
|
|
368
519
|
replies: string[];
|
|
369
520
|
route?: undefined;
|
|
370
521
|
}>;
|
|
522
|
+
/** The installed plugin a context of a bot belongs to: one of the bot's plugins, else an app plugin. */
|
|
523
|
+
private packageIn;
|
|
524
|
+
private recordRun;
|
|
525
|
+
/**
|
|
526
|
+
* What plugins did with a bot's messages, newest first: each message a plugin replied to, kept from the plugins
|
|
527
|
+
* after it, or failed on. Flow runs are in `flows.history`.
|
|
528
|
+
*/
|
|
529
|
+
pluginRuns(id: string, query?: {
|
|
530
|
+
limit?: number;
|
|
531
|
+
before?: number;
|
|
532
|
+
plugin?: string;
|
|
533
|
+
status?: PluginRun['status'];
|
|
534
|
+
}): Promise<{
|
|
535
|
+
runs: PluginRun[];
|
|
536
|
+
more: boolean;
|
|
537
|
+
}>;
|
|
538
|
+
/** What this plugin knows of what others add: chat commands (app plugins' and bot plugins'), and adapters. */
|
|
539
|
+
private provided;
|
|
371
540
|
/** Finds the bot whose context wrote a log message, by walking up from the writing fiber. */
|
|
372
541
|
private botOf;
|
|
373
542
|
/** True when a log line was written inside a bot; it belongs in that bot's log, not the global one. */
|