@mushinjs/plugin-bots 0.3.0 → 0.4.0-next.20261124175848
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 +30 -4
- package/dist/bot.js +90 -11
- 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 +171 -11
- package/dist/manager.js +259 -21
- 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 +53 -0
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
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
|
/**
|
|
@@ -117,6 +140,10 @@ export declare class BotManager extends Service {
|
|
|
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>>;
|
|
119
142
|
adapters(): {
|
|
143
|
+
qrSetup?: {
|
|
144
|
+
start: string;
|
|
145
|
+
poll: string;
|
|
146
|
+
} | undefined;
|
|
120
147
|
id: string;
|
|
121
148
|
displayName: import("@mushinjs/core").LocalizedText;
|
|
122
149
|
configSchema: import("@mushinjs/core").JsonSchema;
|
|
@@ -127,6 +154,11 @@ export declare class BotManager extends Service {
|
|
|
127
154
|
user?: string;
|
|
128
155
|
group?: string;
|
|
129
156
|
};
|
|
157
|
+
hiddenFields: Record<string, string[]>;
|
|
158
|
+
links: {
|
|
159
|
+
url: string;
|
|
160
|
+
label: import("@mushinjs/core").LocalizedText;
|
|
161
|
+
}[];
|
|
130
162
|
}[];
|
|
131
163
|
/** Adapters that can send every segment in a message. */
|
|
132
164
|
platformsFor(segments: Segment[]): string[];
|
|
@@ -147,6 +179,8 @@ export declare class BotManager extends Service {
|
|
|
147
179
|
selfId?: string;
|
|
148
180
|
selfName?: string;
|
|
149
181
|
selfAvatar?: string;
|
|
182
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
183
|
+
invite?: string;
|
|
150
184
|
adapter: {
|
|
151
185
|
config: {
|
|
152
186
|
[x: string]: any;
|
|
@@ -156,6 +190,7 @@ export declare class BotManager extends Service {
|
|
|
156
190
|
name: string;
|
|
157
191
|
enabled: boolean;
|
|
158
192
|
plugins: BotPluginEntry[];
|
|
193
|
+
appPlugins?: string[];
|
|
159
194
|
provider?: string;
|
|
160
195
|
commands?: CommandSettings;
|
|
161
196
|
createdAt: number;
|
|
@@ -169,6 +204,8 @@ export declare class BotManager extends Service {
|
|
|
169
204
|
selfId?: string;
|
|
170
205
|
selfName?: string;
|
|
171
206
|
selfAvatar?: string;
|
|
207
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
208
|
+
invite?: string;
|
|
172
209
|
adapter: {
|
|
173
210
|
config: {
|
|
174
211
|
[x: string]: any;
|
|
@@ -178,6 +215,7 @@ export declare class BotManager extends Service {
|
|
|
178
215
|
name: string;
|
|
179
216
|
enabled: boolean;
|
|
180
217
|
plugins: BotPluginEntry[];
|
|
218
|
+
appPlugins?: string[];
|
|
181
219
|
provider?: string;
|
|
182
220
|
commands?: CommandSettings;
|
|
183
221
|
createdAt: number;
|
|
@@ -205,6 +243,8 @@ export declare class BotManager extends Service {
|
|
|
205
243
|
selfId?: string;
|
|
206
244
|
selfName?: string;
|
|
207
245
|
selfAvatar?: string;
|
|
246
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
247
|
+
invite?: string;
|
|
208
248
|
adapter: {
|
|
209
249
|
config: {
|
|
210
250
|
[x: string]: any;
|
|
@@ -214,6 +254,7 @@ export declare class BotManager extends Service {
|
|
|
214
254
|
name: string;
|
|
215
255
|
enabled: boolean;
|
|
216
256
|
plugins: BotPluginEntry[];
|
|
257
|
+
appPlugins?: string[];
|
|
217
258
|
provider?: string;
|
|
218
259
|
commands?: CommandSettings;
|
|
219
260
|
createdAt: number;
|
|
@@ -234,6 +275,8 @@ export declare class BotManager extends Service {
|
|
|
234
275
|
selfId?: string;
|
|
235
276
|
selfName?: string;
|
|
236
277
|
selfAvatar?: string;
|
|
278
|
+
/** An address that adds the bot to a group or server, from `bot.setInvite()`. */
|
|
279
|
+
invite?: string;
|
|
237
280
|
adapter: {
|
|
238
281
|
config: {
|
|
239
282
|
[x: string]: any;
|
|
@@ -243,6 +286,7 @@ export declare class BotManager extends Service {
|
|
|
243
286
|
name: string;
|
|
244
287
|
enabled: boolean;
|
|
245
288
|
plugins: BotPluginEntry[];
|
|
289
|
+
appPlugins?: string[];
|
|
246
290
|
provider?: string;
|
|
247
291
|
commands?: CommandSettings;
|
|
248
292
|
createdAt: number;
|
|
@@ -257,9 +301,12 @@ export declare class BotManager extends Service {
|
|
|
257
301
|
/** Log lines name a bot by its id; the dashboard links it to the bot. */
|
|
258
302
|
private label;
|
|
259
303
|
loadBotPlugin(name: string): Promise<Plugin>;
|
|
260
|
-
|
|
304
|
+
/**
|
|
305
|
+
* The plugins a bot can turn on: every installed bot plugin, then each app plugin with chat commands (`kind: 'app'`),
|
|
306
|
+
* with whether it is on for this bot and whether it is turned off for the whole project.
|
|
307
|
+
*/
|
|
308
|
+
plugins(id: string): Promise<({
|
|
261
309
|
missing?: MissingDependency[] | undefined;
|
|
262
|
-
package: string;
|
|
263
310
|
version: string;
|
|
264
311
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
265
312
|
enabled: boolean;
|
|
@@ -271,12 +318,35 @@ export declare class BotManager extends Service {
|
|
|
271
318
|
requires: import("@mushinjs/core").DependencyState[];
|
|
272
319
|
optional: import("@mushinjs/core").DependencyState[];
|
|
273
320
|
};
|
|
274
|
-
|
|
321
|
+
projectOff?: true | undefined;
|
|
322
|
+
package: string;
|
|
323
|
+
kind: "bot";
|
|
324
|
+
} | {
|
|
325
|
+
status: string;
|
|
326
|
+
commands: string[];
|
|
327
|
+
package: string;
|
|
328
|
+
kind: "app";
|
|
329
|
+
version: string;
|
|
330
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
331
|
+
enabled: boolean;
|
|
332
|
+
} | {
|
|
333
|
+
status: string;
|
|
334
|
+
projectOff: boolean;
|
|
335
|
+
package: string;
|
|
336
|
+
kind: "app";
|
|
337
|
+
version: string;
|
|
338
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
339
|
+
enabled: boolean;
|
|
340
|
+
})[]>;
|
|
341
|
+
private botPlugins;
|
|
275
342
|
/** Required app plugins that are not installed, do not fit or are disabled. */
|
|
276
343
|
private missingApps;
|
|
344
|
+
/** The bot's entry for a plugin in `plugins()`. */
|
|
345
|
+
private pluginInfo;
|
|
346
|
+
/** Turns an app plugin's chat commands on or off for one bot. */
|
|
347
|
+
private setAppPlugin;
|
|
277
348
|
enablePlugin(id: string, name: string, config?: Record<string, any>): Promise<{
|
|
278
349
|
missing?: MissingDependency[] | undefined;
|
|
279
|
-
package: string;
|
|
280
350
|
version: string;
|
|
281
351
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
282
352
|
enabled: boolean;
|
|
@@ -288,10 +358,28 @@ export declare class BotManager extends Service {
|
|
|
288
358
|
requires: import("@mushinjs/core").DependencyState[];
|
|
289
359
|
optional: import("@mushinjs/core").DependencyState[];
|
|
290
360
|
};
|
|
361
|
+
projectOff?: true | undefined;
|
|
362
|
+
package: string;
|
|
363
|
+
kind: "bot";
|
|
364
|
+
} | {
|
|
365
|
+
status: string;
|
|
366
|
+
commands: string[];
|
|
367
|
+
package: string;
|
|
368
|
+
kind: "app";
|
|
369
|
+
version: string;
|
|
370
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
371
|
+
enabled: boolean;
|
|
372
|
+
} | {
|
|
373
|
+
status: string;
|
|
374
|
+
projectOff: boolean;
|
|
375
|
+
package: string;
|
|
376
|
+
kind: "app";
|
|
377
|
+
version: string;
|
|
378
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
379
|
+
enabled: boolean;
|
|
291
380
|
} | undefined>;
|
|
292
381
|
disablePlugin(id: string, name: string): Promise<{
|
|
293
382
|
missing?: MissingDependency[] | undefined;
|
|
294
|
-
package: string;
|
|
295
383
|
version: string;
|
|
296
384
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
297
385
|
enabled: boolean;
|
|
@@ -303,10 +391,28 @@ export declare class BotManager extends Service {
|
|
|
303
391
|
requires: import("@mushinjs/core").DependencyState[];
|
|
304
392
|
optional: import("@mushinjs/core").DependencyState[];
|
|
305
393
|
};
|
|
394
|
+
projectOff?: true | undefined;
|
|
395
|
+
package: string;
|
|
396
|
+
kind: "bot";
|
|
397
|
+
} | {
|
|
398
|
+
status: string;
|
|
399
|
+
commands: string[];
|
|
400
|
+
package: string;
|
|
401
|
+
kind: "app";
|
|
402
|
+
version: string;
|
|
403
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
404
|
+
enabled: boolean;
|
|
405
|
+
} | {
|
|
406
|
+
status: string;
|
|
407
|
+
projectOff: boolean;
|
|
408
|
+
package: string;
|
|
409
|
+
kind: "app";
|
|
410
|
+
version: string;
|
|
411
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
412
|
+
enabled: boolean;
|
|
306
413
|
} | undefined>;
|
|
307
414
|
configurePlugin(id: string, name: string, config: Record<string, any>): Promise<{
|
|
308
415
|
missing?: MissingDependency[] | undefined;
|
|
309
|
-
package: string;
|
|
310
416
|
version: string;
|
|
311
417
|
manifest: import("@mushinjs/core").PluginManifest;
|
|
312
418
|
enabled: boolean;
|
|
@@ -318,21 +424,57 @@ export declare class BotManager extends Service {
|
|
|
318
424
|
requires: import("@mushinjs/core").DependencyState[];
|
|
319
425
|
optional: import("@mushinjs/core").DependencyState[];
|
|
320
426
|
};
|
|
427
|
+
projectOff?: true | undefined;
|
|
428
|
+
package: string;
|
|
429
|
+
kind: "bot";
|
|
430
|
+
} | {
|
|
431
|
+
status: string;
|
|
432
|
+
commands: string[];
|
|
433
|
+
package: string;
|
|
434
|
+
kind: "app";
|
|
435
|
+
version: string;
|
|
436
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
437
|
+
enabled: boolean;
|
|
438
|
+
} | {
|
|
439
|
+
status: string;
|
|
440
|
+
projectOff: boolean;
|
|
441
|
+
package: string;
|
|
442
|
+
kind: "app";
|
|
443
|
+
version: string;
|
|
444
|
+
manifest: import("@mushinjs/core").PluginManifest;
|
|
445
|
+
enabled: boolean;
|
|
321
446
|
} | undefined>;
|
|
322
447
|
/** Puts the plain values of a bot plugin's secret fields into .env and returns the config with `${NAME}` references. */
|
|
323
448
|
private securePlugin;
|
|
324
449
|
private reloadPlugin;
|
|
450
|
+
/**
|
|
451
|
+
* Turns a bot plugin on or off for the whole project. Off, it runs on no bot; each bot keeps its own switch and
|
|
452
|
+
* settings, so turning it back on starts it again where it was on.
|
|
453
|
+
*/
|
|
454
|
+
setProjectPlugin(name: string, enabled: boolean): Promise<ProjectChatPlugin | undefined>;
|
|
455
|
+
/**
|
|
456
|
+
* The chat plugins across the project: each bot plugin with its project switch, and each app plugin with chat
|
|
457
|
+
* commands, with the bots that have it on.
|
|
458
|
+
*/
|
|
459
|
+
projectPlugins(): Promise<ProjectChatPlugin[]>;
|
|
460
|
+
private projectPlugin;
|
|
325
461
|
/** Adds commands to every bot's list. Removed when the calling plugin unloads. */
|
|
326
462
|
defineCommands(provider: CommandProvider): import("cordis").Disposable<Promise<void>>;
|
|
327
463
|
/**
|
|
328
|
-
* Answers a command
|
|
329
|
-
*
|
|
464
|
+
* Answers a command from an app plugin, such as `/persona`, on the bots the user turned the plugin on for (on the
|
|
465
|
+
* bot's Plugins page, or with `bots.plugins.enable`). A plugin that decides itself which bots answer, from its own
|
|
466
|
+
* per-bot settings, passes `bots`, and then has no switch on the bot's page. It answers after flows, like `/help`,
|
|
467
|
+
* and shows in the command list of each bot it answers on.
|
|
330
468
|
*/
|
|
331
469
|
defineCommand(def: CommandDef, handler: AppCommand['handler'], options?: {
|
|
332
470
|
bots?: (botId: string) => boolean;
|
|
333
471
|
}): import("cordis").Disposable<Promise<void>>;
|
|
334
472
|
/** The app plugin command behind a command entry, if an app plugin answers it. */
|
|
335
473
|
appCommandFor(botId: string, entry: CommandEntry): AppCommand | undefined;
|
|
474
|
+
/** Whether an app plugin's command answers on a bot: the plugin's own choice, or the bot's switch for the plugin. */
|
|
475
|
+
private answersOn;
|
|
476
|
+
/** App plugins whose commands have a switch on each bot, with the names of those commands, by package. */
|
|
477
|
+
private chatApps;
|
|
336
478
|
/** Lets the permissions plugin say who is master, admin or user on each bot. */
|
|
337
479
|
usePermissions(provider: PermissionProvider): import("cordis").Disposable<Promise<void>>;
|
|
338
480
|
/** A user's role on a bot; nothing when the permissions plugin is not running. */
|
|
@@ -368,6 +510,24 @@ export declare class BotManager extends Service {
|
|
|
368
510
|
replies: string[];
|
|
369
511
|
route?: undefined;
|
|
370
512
|
}>;
|
|
513
|
+
/** The installed plugin a context of a bot belongs to: one of the bot's plugins, else an app plugin. */
|
|
514
|
+
private packageIn;
|
|
515
|
+
private recordRun;
|
|
516
|
+
/**
|
|
517
|
+
* What plugins did with a bot's messages, newest first: each message a plugin replied to, kept from the plugins
|
|
518
|
+
* after it, or failed on. Flow runs are in `flows.history`.
|
|
519
|
+
*/
|
|
520
|
+
pluginRuns(id: string, query?: {
|
|
521
|
+
limit?: number;
|
|
522
|
+
before?: number;
|
|
523
|
+
plugin?: string;
|
|
524
|
+
status?: PluginRun['status'];
|
|
525
|
+
}): Promise<{
|
|
526
|
+
runs: PluginRun[];
|
|
527
|
+
more: boolean;
|
|
528
|
+
}>;
|
|
529
|
+
/** What this plugin knows of what others add: chat commands (app plugins' and bot plugins'), and adapters. */
|
|
530
|
+
private provided;
|
|
371
531
|
/** Finds the bot whose context wrote a log message, by walking up from the writing fiber. */
|
|
372
532
|
private botOf;
|
|
373
533
|
/** True when a log line was written inside a bot; it belongs in that bot's log, not the global one. */
|