@elizaos/plugin-commands 1.0.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.
@@ -0,0 +1,1077 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/index.ts
30
+ var exports_src = {};
31
+ __export(exports_src, {
32
+ unregisterCommand: () => unregisterCommand,
33
+ startsWithCommand: () => startsWithCommand,
34
+ resetCommands: () => resetCommands,
35
+ registerCommands: () => registerCommands,
36
+ registerCommand: () => registerCommand,
37
+ parseCommand: () => parseCommand,
38
+ normalizeCommandBody: () => normalizeCommandBody,
39
+ isElevated: () => isElevated,
40
+ isCommandOnly: () => isCommandOnly,
41
+ isAuthorized: () => isAuthorized,
42
+ hasCommand: () => hasCommand,
43
+ getEnabledCommands: () => getEnabledCommands,
44
+ getCommandsByCategory: () => getCommandsByCategory,
45
+ getCommands: () => getCommands,
46
+ formatCommandResult: () => formatCommandResult,
47
+ findCommandByKey: () => findCommandByKey,
48
+ findCommandByAlias: () => findCommandByAlias,
49
+ extractCommand: () => extractCommand,
50
+ detectCommand: () => detectCommand,
51
+ default: () => src_default,
52
+ commandsPlugin: () => commandsPlugin,
53
+ commandRegistryProvider: () => commandRegistryProvider
54
+ });
55
+ module.exports = __toCommonJS(exports_src);
56
+ var import_core = require("@elizaos/core");
57
+
58
+ // src/registry.ts
59
+ var DEFAULT_COMMANDS = [
60
+ {
61
+ key: "help",
62
+ nativeName: "help",
63
+ description: "Show available commands",
64
+ textAliases: ["/help", "/h", "/?"],
65
+ scope: "both",
66
+ category: "status",
67
+ acceptsArgs: false
68
+ },
69
+ {
70
+ key: "commands",
71
+ nativeName: "commands",
72
+ description: "List all commands",
73
+ textAliases: ["/commands", "/cmds"],
74
+ scope: "both",
75
+ category: "status",
76
+ acceptsArgs: false
77
+ },
78
+ {
79
+ key: "status",
80
+ nativeName: "status",
81
+ description: "Show current session status",
82
+ textAliases: ["/status", "/s"],
83
+ scope: "both",
84
+ category: "status",
85
+ acceptsArgs: false
86
+ },
87
+ {
88
+ key: "context",
89
+ nativeName: "context",
90
+ description: "Show current context information",
91
+ textAliases: ["/context", "/ctx"],
92
+ scope: "both",
93
+ category: "status",
94
+ acceptsArgs: true,
95
+ args: [{ name: "mode", description: "Output mode (list, detail, json)" }]
96
+ },
97
+ {
98
+ key: "whoami",
99
+ nativeName: "whoami",
100
+ description: "Show your identity information",
101
+ textAliases: ["/whoami", "/who"],
102
+ scope: "both",
103
+ category: "status",
104
+ acceptsArgs: false
105
+ },
106
+ {
107
+ key: "stop",
108
+ nativeName: "stop",
109
+ description: "Stop current operation",
110
+ textAliases: ["/stop", "/abort", "/cancel"],
111
+ scope: "both",
112
+ category: "session",
113
+ acceptsArgs: false
114
+ },
115
+ {
116
+ key: "restart",
117
+ nativeName: "restart",
118
+ description: "Restart the session",
119
+ textAliases: ["/restart"],
120
+ scope: "both",
121
+ category: "session",
122
+ acceptsArgs: false,
123
+ requiresAuth: true
124
+ },
125
+ {
126
+ key: "reset",
127
+ nativeName: "reset",
128
+ description: "Reset session state",
129
+ textAliases: ["/reset"],
130
+ scope: "both",
131
+ category: "session",
132
+ acceptsArgs: false,
133
+ requiresAuth: true
134
+ },
135
+ {
136
+ key: "new",
137
+ nativeName: "new",
138
+ description: "Start a new conversation",
139
+ textAliases: ["/new"],
140
+ scope: "both",
141
+ category: "session",
142
+ acceptsArgs: false
143
+ },
144
+ {
145
+ key: "compact",
146
+ nativeName: "compact",
147
+ description: "Compact conversation history",
148
+ textAliases: ["/compact"],
149
+ scope: "both",
150
+ category: "session",
151
+ acceptsArgs: true,
152
+ args: [
153
+ { name: "instructions", description: "Optional compaction instructions" }
154
+ ]
155
+ },
156
+ {
157
+ key: "think",
158
+ nativeName: "think",
159
+ description: "Set thinking level",
160
+ textAliases: ["/think", "/thinking", "/t"],
161
+ scope: "both",
162
+ category: "options",
163
+ acceptsArgs: true,
164
+ args: [
165
+ { name: "level", description: "off, minimal, low, medium, high, xhigh" }
166
+ ]
167
+ },
168
+ {
169
+ key: "verbose",
170
+ nativeName: "verbose",
171
+ description: "Set verbose output level",
172
+ textAliases: ["/verbose", "/v"],
173
+ scope: "both",
174
+ category: "options",
175
+ acceptsArgs: true,
176
+ args: [{ name: "level", description: "off, on, full" }]
177
+ },
178
+ {
179
+ key: "reasoning",
180
+ nativeName: "reasoning",
181
+ description: "Set reasoning visibility",
182
+ textAliases: ["/reasoning", "/reason"],
183
+ scope: "both",
184
+ category: "options",
185
+ acceptsArgs: true,
186
+ args: [{ name: "level", description: "off, on, stream" }]
187
+ },
188
+ {
189
+ key: "elevated",
190
+ nativeName: "elevated",
191
+ description: "Set elevated permission mode",
192
+ textAliases: ["/elevated", "/elev"],
193
+ scope: "both",
194
+ category: "options",
195
+ acceptsArgs: true,
196
+ args: [{ name: "level", description: "off, on, ask, full" }],
197
+ requiresAuth: true
198
+ },
199
+ {
200
+ key: "model",
201
+ nativeName: "model",
202
+ description: "Set or show current model",
203
+ textAliases: ["/model", "/m"],
204
+ scope: "both",
205
+ category: "options",
206
+ acceptsArgs: true,
207
+ args: [{ name: "model", description: "provider/model or alias" }]
208
+ },
209
+ {
210
+ key: "models",
211
+ nativeName: "models",
212
+ description: "List available models",
213
+ textAliases: ["/models"],
214
+ scope: "both",
215
+ category: "options",
216
+ acceptsArgs: false
217
+ },
218
+ {
219
+ key: "usage",
220
+ nativeName: "usage",
221
+ description: "Show token usage",
222
+ textAliases: ["/usage"],
223
+ scope: "both",
224
+ category: "options",
225
+ acceptsArgs: false
226
+ },
227
+ {
228
+ key: "queue",
229
+ nativeName: "queue",
230
+ description: "Set queue mode",
231
+ textAliases: ["/queue", "/q"],
232
+ scope: "both",
233
+ category: "options",
234
+ acceptsArgs: true,
235
+ args: [
236
+ {
237
+ name: "mode",
238
+ description: "steer, followup, collect, interrupt, or options"
239
+ }
240
+ ]
241
+ },
242
+ {
243
+ key: "allowlist",
244
+ nativeName: "allowlist",
245
+ description: "Manage sender allowlist",
246
+ textAliases: ["/allowlist", "/allow"],
247
+ scope: "both",
248
+ category: "management",
249
+ acceptsArgs: true,
250
+ args: [
251
+ { name: "action", description: "list, add, remove" },
252
+ { name: "value", description: "sender to add/remove" }
253
+ ],
254
+ requiresAuth: true
255
+ },
256
+ {
257
+ key: "approve",
258
+ nativeName: "approve",
259
+ description: "Approve or deny a pending action",
260
+ textAliases: ["/approve"],
261
+ scope: "both",
262
+ category: "management",
263
+ acceptsArgs: true,
264
+ args: [
265
+ { name: "id", description: "Approval ID", required: true },
266
+ { name: "action", description: "allow-once, allow-always, deny" }
267
+ ],
268
+ requiresAuth: true
269
+ },
270
+ {
271
+ key: "subagents",
272
+ nativeName: "subagents",
273
+ description: "Manage subagents",
274
+ textAliases: ["/subagents", "/sub"],
275
+ scope: "both",
276
+ category: "management",
277
+ acceptsArgs: true,
278
+ args: [{ name: "action", description: "list, stop, log, info, send" }],
279
+ requiresAuth: true
280
+ },
281
+ {
282
+ key: "config",
283
+ nativeName: "config",
284
+ description: "View or set configuration",
285
+ textAliases: ["/config", "/cfg"],
286
+ scope: "both",
287
+ category: "management",
288
+ acceptsArgs: true,
289
+ args: [
290
+ { name: "key", description: "Configuration key" },
291
+ { name: "value", description: "Value to set" }
292
+ ],
293
+ requiresAuth: true,
294
+ enabled: false
295
+ },
296
+ {
297
+ key: "debug",
298
+ nativeName: "debug",
299
+ description: "Debug information",
300
+ textAliases: ["/debug"],
301
+ scope: "both",
302
+ category: "management",
303
+ acceptsArgs: true,
304
+ requiresAuth: true,
305
+ enabled: false
306
+ },
307
+ {
308
+ key: "tts",
309
+ nativeName: "tts",
310
+ description: "Text-to-speech settings",
311
+ textAliases: ["/tts", "/voice"],
312
+ scope: "both",
313
+ category: "media",
314
+ acceptsArgs: true,
315
+ args: [
316
+ {
317
+ name: "action",
318
+ description: "on, off, status, provider, limit, audio"
319
+ }
320
+ ]
321
+ },
322
+ {
323
+ key: "bash",
324
+ nativeName: "bash",
325
+ description: "Execute shell command",
326
+ textAliases: ["/bash", "/sh", "/!"],
327
+ scope: "text",
328
+ category: "tools",
329
+ acceptsArgs: true,
330
+ args: [
331
+ {
332
+ name: "command",
333
+ description: "Shell command to execute",
334
+ captureRemaining: true
335
+ }
336
+ ],
337
+ requiresAuth: true,
338
+ requiresElevated: true
339
+ }
340
+ ];
341
+ var commands = [...DEFAULT_COMMANDS];
342
+ var aliasMap = null;
343
+ function getCommands() {
344
+ return [...commands];
345
+ }
346
+ function getEnabledCommands() {
347
+ return commands.filter((cmd) => cmd.enabled !== false);
348
+ }
349
+ function getCommandsByCategory(category) {
350
+ return commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
351
+ }
352
+ function registerCommand(command) {
353
+ commands = commands.filter((c) => c.key !== command.key);
354
+ commands.push(command);
355
+ aliasMap = null;
356
+ }
357
+ function registerCommands(newCommands) {
358
+ for (const command of newCommands) {
359
+ registerCommand(command);
360
+ }
361
+ }
362
+ function unregisterCommand(key) {
363
+ commands = commands.filter((c) => c.key !== key);
364
+ aliasMap = null;
365
+ }
366
+ function resetCommands() {
367
+ commands = [...DEFAULT_COMMANDS];
368
+ aliasMap = null;
369
+ }
370
+ function getAliasMap() {
371
+ if (aliasMap)
372
+ return aliasMap;
373
+ aliasMap = new Map;
374
+ for (const command of commands) {
375
+ if (command.enabled === false)
376
+ continue;
377
+ for (const alias of command.textAliases) {
378
+ const normalized = alias.toLowerCase().trim();
379
+ if (!aliasMap.has(normalized)) {
380
+ aliasMap.set(normalized, command);
381
+ }
382
+ }
383
+ }
384
+ return aliasMap;
385
+ }
386
+ function findCommandByAlias(alias) {
387
+ const map = getAliasMap();
388
+ return map.get(alias.toLowerCase().trim());
389
+ }
390
+ function findCommandByKey(key) {
391
+ return commands.find((c) => c.key === key);
392
+ }
393
+ function startsWithCommand(text) {
394
+ const map = getAliasMap();
395
+ const normalized = text.toLowerCase().trim();
396
+ for (const [alias, command] of map) {
397
+ if (normalized === alias) {
398
+ return command;
399
+ }
400
+ if (normalized.startsWith(alias + " ") || normalized.startsWith(alias + ":")) {
401
+ return command;
402
+ }
403
+ }
404
+ return;
405
+ }
406
+
407
+ // src/parser.ts
408
+ var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
409
+ function hasCommand(text) {
410
+ if (!text)
411
+ return false;
412
+ const trimmed = text.trim();
413
+ if (!trimmed.startsWith("/") && !trimmed.startsWith("!"))
414
+ return false;
415
+ return Boolean(startsWithCommand(trimmed));
416
+ }
417
+ function detectCommand(text) {
418
+ if (!text) {
419
+ return { isCommand: false };
420
+ }
421
+ const trimmed = text.trim();
422
+ if (!trimmed.startsWith("/") && !trimmed.startsWith("!")) {
423
+ return { isCommand: false };
424
+ }
425
+ const command = startsWithCommand(trimmed);
426
+ if (!command) {
427
+ return { isCommand: false };
428
+ }
429
+ const parsed = parseCommand(trimmed, command);
430
+ if (!parsed) {
431
+ return { isCommand: false };
432
+ }
433
+ return { isCommand: true, command: parsed };
434
+ }
435
+ function parseCommand(text, definition) {
436
+ const trimmed = text.trim();
437
+ let matchedAlias = null;
438
+ for (const alias of definition.textAliases) {
439
+ const normalized = alias.toLowerCase();
440
+ if (trimmed.toLowerCase() === normalized) {
441
+ matchedAlias = alias;
442
+ break;
443
+ }
444
+ if (trimmed.toLowerCase().startsWith(normalized + " ") || trimmed.toLowerCase().startsWith(normalized + ":")) {
445
+ matchedAlias = alias;
446
+ break;
447
+ }
448
+ }
449
+ if (!matchedAlias) {
450
+ return null;
451
+ }
452
+ let rawArgs = trimmed.slice(matchedAlias.length).trim();
453
+ if (rawArgs.startsWith(":")) {
454
+ rawArgs = rawArgs.slice(1).trim();
455
+ }
456
+ const args = parseArgs(rawArgs, definition);
457
+ return {
458
+ key: definition.key,
459
+ canonical: definition.textAliases[0] ?? `/${definition.key}`,
460
+ args,
461
+ rawArgs: rawArgs || undefined
462
+ };
463
+ }
464
+ function parseArgs(rawArgs, definition) {
465
+ if (!rawArgs || !definition.acceptsArgs) {
466
+ return [];
467
+ }
468
+ const parsing = definition.argsParsing ?? "positional";
469
+ if (parsing === "none") {
470
+ return rawArgs ? [rawArgs] : [];
471
+ }
472
+ const args = [];
473
+ const argDefs = definition.args ?? [];
474
+ const tokens = tokenize(rawArgs);
475
+ for (let i = 0;i < tokens.length; i++) {
476
+ const argDef = argDefs[i];
477
+ if (argDef?.captureRemaining) {
478
+ args.push(tokens.slice(i).join(" "));
479
+ break;
480
+ }
481
+ args.push(tokens[i]);
482
+ }
483
+ return args;
484
+ }
485
+ function tokenize(input) {
486
+ const tokens = [];
487
+ let current = "";
488
+ let inQuote = false;
489
+ let quoteChar = "";
490
+ for (let i = 0;i < input.length; i++) {
491
+ const char = input[i];
492
+ if (inQuote) {
493
+ if (char === quoteChar) {
494
+ inQuote = false;
495
+ if (current) {
496
+ tokens.push(current);
497
+ current = "";
498
+ }
499
+ } else {
500
+ current += char;
501
+ }
502
+ } else if (char === '"' || char === "'") {
503
+ inQuote = true;
504
+ quoteChar = char;
505
+ } else if (/\s/.test(char)) {
506
+ if (current) {
507
+ tokens.push(current);
508
+ current = "";
509
+ }
510
+ } else {
511
+ current += char;
512
+ }
513
+ }
514
+ if (current) {
515
+ tokens.push(current);
516
+ }
517
+ return tokens;
518
+ }
519
+ function normalizeCommandBody(text, botMention) {
520
+ let normalized = text.trim();
521
+ if (botMention) {
522
+ const mentionPattern = new RegExp(`^@${escapeRegExp(botMention)}\\s*`, "i");
523
+ normalized = normalized.replace(mentionPattern, "");
524
+ }
525
+ normalized = normalized.replace(/^(\/\w+):\s*/, "$1 ");
526
+ return normalized.trim();
527
+ }
528
+ function isCommandOnly(text) {
529
+ const detection = detectCommand(text);
530
+ if (!detection.isCommand || !detection.command) {
531
+ return false;
532
+ }
533
+ if (!detection.command.rawArgs) {
534
+ return true;
535
+ }
536
+ return detection.command.rawArgs.trim().length === 0;
537
+ }
538
+ function extractCommand(text) {
539
+ const detection = detectCommand(text);
540
+ if (!detection.isCommand || !detection.command) {
541
+ return null;
542
+ }
543
+ const { command } = detection;
544
+ if (!command.rawArgs) {
545
+ return { command, remainingText: "" };
546
+ }
547
+ return { command, remainingText: command.rawArgs };
548
+ }
549
+
550
+ // src/actions/commands-list.ts
551
+ var commandsListAction = {
552
+ name: "COMMANDS_LIST",
553
+ description: "List all available commands with their aliases",
554
+ similes: ["/commands", "/cmds", "list all commands"],
555
+ async validate(runtime, message) {
556
+ const text = message.content?.text ?? "";
557
+ const detection = detectCommand(text);
558
+ return detection.isCommand && detection.command?.key === "commands";
559
+ },
560
+ async handler(runtime, message, state, options, callback) {
561
+ const commands2 = getEnabledCommands();
562
+ const lines = [`**Commands (${commands2.length}):**
563
+ `];
564
+ for (const cmd of commands2) {
565
+ const aliases = cmd.textAliases.join(", ");
566
+ const authNote = cmd.requiresAuth ? " [auth]" : "";
567
+ const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
568
+ lines.push(`• **${cmd.key}**: ${aliases}${authNote}${elevatedNote}`);
569
+ }
570
+ const replyText = lines.join(`
571
+ `);
572
+ await callback?.({ text: replyText });
573
+ return {
574
+ success: true,
575
+ text: replyText,
576
+ data: { commandCount: commands2.length }
577
+ };
578
+ },
579
+ examples: [
580
+ [
581
+ { user: "user", content: { text: "/commands" } },
582
+ {
583
+ user: "assistant",
584
+ content: {
585
+ text: `**Commands (15):**
586
+
587
+ • **help**: /help, /h, /?
588
+ • **status**: /status, /s...`
589
+ }
590
+ }
591
+ ]
592
+ ]
593
+ };
594
+
595
+ // src/actions/help.ts
596
+ function formatCommandList(commands2) {
597
+ const lines = [`**Available Commands:**
598
+ `];
599
+ const categories = [
600
+ { key: "status", name: "Status" },
601
+ { key: "session", name: "Session" },
602
+ { key: "options", name: "Options" },
603
+ { key: "management", name: "Management" },
604
+ { key: "media", name: "Media" },
605
+ { key: "tools", name: "Tools" }
606
+ ];
607
+ for (const cat of categories) {
608
+ const catCommands = commands2.filter((c) => c.category === cat.key);
609
+ if (catCommands.length === 0)
610
+ continue;
611
+ lines.push(`
612
+ **${cat.name}:**`);
613
+ for (const cmd of catCommands) {
614
+ const aliases = cmd.textAliases.slice(0, 2).join(", ");
615
+ lines.push(`• ${aliases} - ${cmd.description}`);
616
+ }
617
+ }
618
+ const uncategorized = commands2.filter((c) => !c.category);
619
+ if (uncategorized.length > 0) {
620
+ lines.push(`
621
+ **Other:**`);
622
+ for (const cmd of uncategorized) {
623
+ const aliases = cmd.textAliases.slice(0, 2).join(", ");
624
+ lines.push(`• ${aliases} - ${cmd.description}`);
625
+ }
626
+ }
627
+ return lines.join(`
628
+ `);
629
+ }
630
+ var helpAction = {
631
+ name: "HELP_COMMAND",
632
+ description: "Show available commands and their descriptions",
633
+ similes: ["/help", "/h", "/?", "help", "show help", "list commands"],
634
+ async validate(runtime, message) {
635
+ const text = message.content?.text ?? "";
636
+ const detection = detectCommand(text);
637
+ return detection.isCommand && detection.command?.key === "help";
638
+ },
639
+ async handler(runtime, message, state, options, callback) {
640
+ const commands2 = getEnabledCommands();
641
+ const helpText = formatCommandList(commands2);
642
+ await callback?.({ text: helpText });
643
+ return {
644
+ success: true,
645
+ text: helpText,
646
+ data: { commandCount: commands2.length }
647
+ };
648
+ },
649
+ examples: [
650
+ [
651
+ { user: "user", content: { text: "/help" } },
652
+ {
653
+ user: "assistant",
654
+ content: {
655
+ text: `**Available Commands:**
656
+
657
+ **Status:**
658
+ • /help - Show available commands...`
659
+ }
660
+ }
661
+ ],
662
+ [
663
+ { user: "user", content: { text: "/?" } },
664
+ {
665
+ user: "assistant",
666
+ content: {
667
+ text: `**Available Commands:**
668
+
669
+ **Status:**
670
+ • /help - Show available commands...`
671
+ }
672
+ }
673
+ ]
674
+ ]
675
+ };
676
+
677
+ // src/actions/models.ts
678
+ var modelsAction = {
679
+ name: "MODELS_COMMAND",
680
+ description: "List available AI models and providers",
681
+ similes: ["/models", "list models", "show models", "available models"],
682
+ async validate(runtime, message) {
683
+ const text = message.content?.text ?? "";
684
+ const detection = detectCommand(text);
685
+ return detection.isCommand && detection.command?.key === "models";
686
+ },
687
+ async handler(runtime, message, state, options, callback) {
688
+ const lines = [`**Available Models:**
689
+ `];
690
+ const providers = [
691
+ {
692
+ name: "Anthropic",
693
+ models: [
694
+ "claude-3-opus",
695
+ "claude-3-sonnet",
696
+ "claude-3-haiku",
697
+ "claude-3.5-sonnet"
698
+ ]
699
+ },
700
+ {
701
+ name: "OpenAI",
702
+ models: [
703
+ "gpt-4o",
704
+ "gpt-4o-mini",
705
+ "gpt-4-turbo",
706
+ "gpt-4",
707
+ "gpt-3.5-turbo"
708
+ ]
709
+ },
710
+ {
711
+ name: "Google",
712
+ models: ["gemini-pro", "gemini-pro-vision", "gemini-ultra"]
713
+ }
714
+ ];
715
+ for (const provider of providers) {
716
+ lines.push(`
717
+ **${provider.name}:**`);
718
+ for (const model of provider.models) {
719
+ lines.push(`• ${provider.name.toLowerCase()}/${model}`);
720
+ }
721
+ }
722
+ lines.push(`
723
+
724
+ _Use /model <provider/model> to switch models._`);
725
+ const replyText = lines.join(`
726
+ `);
727
+ await callback?.({ text: replyText });
728
+ return {
729
+ success: true,
730
+ text: replyText,
731
+ data: { providers }
732
+ };
733
+ },
734
+ examples: [
735
+ [
736
+ { user: "user", content: { text: "/models" } },
737
+ {
738
+ user: "assistant",
739
+ content: {
740
+ text: `**Available Models:**
741
+
742
+ **Anthropic:**
743
+ • anthropic/claude-3-opus
744
+ • anthropic/claude-3-sonnet...`
745
+ }
746
+ }
747
+ ]
748
+ ]
749
+ };
750
+
751
+ // src/actions/status.ts
752
+ async function buildStatusReport(runtime, roomId) {
753
+ const lines = [`**Session Status:**
754
+ `];
755
+ lines.push(`**Agent:** ${runtime.agentId}`);
756
+ lines.push(`**Room:** ${roomId}`);
757
+ try {
758
+ const directiveService = runtime.getService("directive-parser");
759
+ if (directiveService) {
760
+ const state = directiveService.getSessionState?.(roomId);
761
+ if (state) {
762
+ lines.push(`
763
+ **Directives:**`);
764
+ lines.push(`• Thinking: ${state.thinking}`);
765
+ lines.push(`• Verbose: ${state.verbose}`);
766
+ lines.push(`• Reasoning: ${state.reasoning}`);
767
+ lines.push(`• Elevated: ${state.elevated}`);
768
+ if (state.model?.provider || state.model?.model) {
769
+ const modelStr = state.model.provider ? `${state.model.provider}/${state.model.model}` : state.model.model;
770
+ lines.push(`• Model: ${modelStr}`);
771
+ }
772
+ }
773
+ }
774
+ } catch {}
775
+ return lines.join(`
776
+ `);
777
+ }
778
+ var statusAction = {
779
+ name: "STATUS_COMMAND",
780
+ description: "Show current session status, model, and settings",
781
+ similes: ["/status", "/s", "status", "show status", "what's my status"],
782
+ async validate(runtime, message) {
783
+ const text = message.content?.text ?? "";
784
+ const detection = detectCommand(text);
785
+ return detection.isCommand && detection.command?.key === "status";
786
+ },
787
+ async handler(runtime, message, state, options, callback) {
788
+ const statusText = await buildStatusReport(runtime, message.roomId);
789
+ await callback?.({ text: statusText });
790
+ return {
791
+ success: true,
792
+ text: statusText
793
+ };
794
+ },
795
+ examples: [
796
+ [
797
+ { user: "user", content: { text: "/status" } },
798
+ {
799
+ user: "assistant",
800
+ content: {
801
+ text: `**Session Status:**
802
+
803
+ **Agent:** agent-123
804
+ **Room:** room-456
805
+
806
+ **Directives:**
807
+ • Thinking: low...`
808
+ }
809
+ }
810
+ ]
811
+ ]
812
+ };
813
+
814
+ // src/actions/stop.ts
815
+ var stopAction = {
816
+ name: "STOP_COMMAND",
817
+ description: "Stop current operation or abort running tasks",
818
+ similes: ["/stop", "/abort", "/cancel", "stop", "abort", "cancel"],
819
+ async validate(runtime, message) {
820
+ const text = message.content?.text ?? "";
821
+ const detection = detectCommand(text);
822
+ return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
823
+ },
824
+ async handler(runtime, message, state, options, callback) {
825
+ try {
826
+ await runtime.emitEvent?.("ABORT_REQUESTED", {
827
+ roomId: message.roomId,
828
+ userId: message.userId,
829
+ requestedAt: Date.now()
830
+ });
831
+ } catch {}
832
+ const replyText = "✓ Stop requested. Current operations will be cancelled.";
833
+ await callback?.({ text: replyText });
834
+ return {
835
+ success: true,
836
+ text: replyText
837
+ };
838
+ },
839
+ examples: [
840
+ [
841
+ { user: "user", content: { text: "/stop" } },
842
+ {
843
+ user: "assistant",
844
+ content: {
845
+ text: "✓ Stop requested. Current operations will be cancelled."
846
+ }
847
+ }
848
+ ],
849
+ [
850
+ { user: "user", content: { text: "/abort" } },
851
+ {
852
+ user: "assistant",
853
+ content: {
854
+ text: "✓ Stop requested. Current operations will be cancelled."
855
+ }
856
+ }
857
+ ]
858
+ ]
859
+ };
860
+
861
+ // src/index.ts
862
+ var commandRegistryProvider = {
863
+ name: "COMMAND_REGISTRY",
864
+ description: "Available chat commands and their descriptions",
865
+ dynamic: true,
866
+ async get(runtime, message, _state) {
867
+ const commands2 = getEnabledCommands();
868
+ const commandList = commands2.map((cmd) => {
869
+ const auth = cmd.requiresAuth ? " (requires auth)" : "";
870
+ return `- ${cmd.textAliases[0]}: ${cmd.description}${auth}`;
871
+ });
872
+ return {
873
+ text: `Available commands:
874
+ ${commandList.join(`
875
+ `)}`,
876
+ values: {
877
+ commandCount: commands2.length,
878
+ hasElevatedCommands: commands2.some((c) => c.requiresElevated)
879
+ },
880
+ data: { commands: commands2 }
881
+ };
882
+ }
883
+ };
884
+ function formatCommandResult(result) {
885
+ if (result.error) {
886
+ return `❌ Error: ${result.error}`;
887
+ }
888
+ return result.reply ?? "✓ Command executed";
889
+ }
890
+ function isAuthorized(context, command) {
891
+ if (!command.requiresAuth) {
892
+ return true;
893
+ }
894
+ return context.isAuthorized;
895
+ }
896
+ function isElevated(context, command) {
897
+ if (!command.requiresElevated) {
898
+ return true;
899
+ }
900
+ return context.isElevated;
901
+ }
902
+ var commandsPlugin = {
903
+ name: "commands",
904
+ description: "Chat command system with /help, /status, /reset, etc.",
905
+ providers: [commandRegistryProvider],
906
+ actions: [
907
+ helpAction,
908
+ statusAction,
909
+ stopAction,
910
+ modelsAction,
911
+ commandsListAction
912
+ ],
913
+ config: {
914
+ COMMANDS_ENABLED: "true",
915
+ COMMANDS_CONFIG_ENABLED: "false",
916
+ COMMANDS_DEBUG_ENABLED: "false",
917
+ COMMANDS_BASH_ENABLED: "false",
918
+ COMMANDS_RESTART_ENABLED: "true"
919
+ },
920
+ tests: [
921
+ {
922
+ name: "command-detection",
923
+ tests: [
924
+ {
925
+ name: "Detect command prefix",
926
+ fn: async (_runtime) => {
927
+ if (!hasCommand("/help")) {
928
+ throw new Error("Should detect /help command");
929
+ }
930
+ if (!hasCommand("/status test")) {
931
+ throw new Error("Should detect /status with args");
932
+ }
933
+ if (hasCommand("hello world")) {
934
+ throw new Error("Should not detect plain text as command");
935
+ }
936
+ import_core.logger.success("Command prefix detection works correctly");
937
+ }
938
+ },
939
+ {
940
+ name: "Parse command with args",
941
+ fn: async (_runtime) => {
942
+ const detection = detectCommand("/think:high");
943
+ if (!detection.isCommand) {
944
+ throw new Error("Should detect think command");
945
+ }
946
+ if (detection.command?.key !== "think") {
947
+ throw new Error(`Expected key 'think', got '${detection.command?.key}'`);
948
+ }
949
+ if (detection.command?.args[0] !== "high") {
950
+ throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
951
+ }
952
+ import_core.logger.success("Command argument parsing works correctly");
953
+ }
954
+ },
955
+ {
956
+ name: "Normalize command body",
957
+ fn: async (_runtime) => {
958
+ const normalized1 = normalizeCommandBody("/status: test");
959
+ if (normalized1 !== "/status test") {
960
+ throw new Error(`Expected '/status test', got '${normalized1}'`);
961
+ }
962
+ const normalized2 = normalizeCommandBody("@bot /help", "bot");
963
+ if (normalized2 !== "/help") {
964
+ throw new Error(`Expected '/help', got '${normalized2}'`);
965
+ }
966
+ import_core.logger.success("Command normalization works correctly");
967
+ }
968
+ },
969
+ {
970
+ name: "Find command by alias",
971
+ fn: async (_runtime) => {
972
+ const cmd = findCommandByAlias("/h");
973
+ if (!cmd) {
974
+ throw new Error("Should find help command by /h alias");
975
+ }
976
+ if (cmd.key !== "help") {
977
+ throw new Error(`Expected key 'help', got '${cmd.key}'`);
978
+ }
979
+ import_core.logger.success("Command alias lookup works correctly");
980
+ }
981
+ },
982
+ {
983
+ name: "Find command by key",
984
+ fn: async (_runtime) => {
985
+ const cmd = findCommandByKey("status");
986
+ if (!cmd) {
987
+ throw new Error("Should find status command by key");
988
+ }
989
+ if (cmd.key !== "status") {
990
+ throw new Error(`Expected key 'status', got '${cmd.key}'`);
991
+ }
992
+ import_core.logger.success("Command key lookup works correctly");
993
+ }
994
+ }
995
+ ]
996
+ },
997
+ {
998
+ name: "command-registry",
999
+ tests: [
1000
+ {
1001
+ name: "Get enabled commands",
1002
+ fn: async (_runtime) => {
1003
+ const commands2 = getEnabledCommands();
1004
+ if (commands2.length === 0) {
1005
+ throw new Error("Should have enabled commands");
1006
+ }
1007
+ const hasHelp = commands2.some((c) => c.key === "help");
1008
+ const hasStatus = commands2.some((c) => c.key === "status");
1009
+ if (!hasHelp || !hasStatus) {
1010
+ throw new Error("Should have help and status commands");
1011
+ }
1012
+ import_core.logger.success("Command registry works correctly");
1013
+ }
1014
+ },
1015
+ {
1016
+ name: "Register custom command",
1017
+ fn: async (_runtime) => {
1018
+ const customCmd = {
1019
+ key: "test-custom",
1020
+ description: "Test custom command",
1021
+ textAliases: ["/test-custom", "/tc"],
1022
+ scope: "text"
1023
+ };
1024
+ registerCommand(customCmd);
1025
+ const found = findCommandByKey("test-custom");
1026
+ if (!found) {
1027
+ throw new Error("Should find registered custom command");
1028
+ }
1029
+ unregisterCommand("test-custom");
1030
+ const notFound = findCommandByKey("test-custom");
1031
+ if (notFound) {
1032
+ throw new Error("Should not find unregistered command");
1033
+ }
1034
+ import_core.logger.success("Custom command registration works correctly");
1035
+ }
1036
+ },
1037
+ {
1038
+ name: "Get commands by category",
1039
+ fn: async (_runtime) => {
1040
+ const statusCommands = getCommandsByCategory("status");
1041
+ if (statusCommands.length === 0) {
1042
+ throw new Error("Should have status category commands");
1043
+ }
1044
+ const allStatus = statusCommands.every((c) => c.category === "status");
1045
+ if (!allStatus) {
1046
+ throw new Error("All returned commands should be in status category");
1047
+ }
1048
+ import_core.logger.success("Command categorization works correctly");
1049
+ }
1050
+ }
1051
+ ]
1052
+ }
1053
+ ],
1054
+ async init(config, runtime) {
1055
+ import_core.logger.log("[plugin-commands] Initializing command system");
1056
+ const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
1057
+ const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
1058
+ const bashEnabled = config.COMMANDS_BASH_ENABLED === "true";
1059
+ const configCmd = findCommandByKey("config");
1060
+ if (configCmd) {
1061
+ configCmd.enabled = configEnabled;
1062
+ }
1063
+ const debugCmd = findCommandByKey("debug");
1064
+ if (debugCmd) {
1065
+ debugCmd.enabled = debugEnabled;
1066
+ }
1067
+ const bashCmd = findCommandByKey("bash");
1068
+ if (bashCmd) {
1069
+ bashCmd.enabled = bashEnabled;
1070
+ }
1071
+ const enabledCount = getEnabledCommands().length;
1072
+ import_core.logger.log(`[plugin-commands] ${enabledCount} commands enabled`);
1073
+ }
1074
+ };
1075
+ var src_default = commandsPlugin;
1076
+
1077
+ //# debugId=F42BC7360B07F25664756E2164756E21