@elizaos/plugin-commands 2.0.0-alpha.9 → 2.0.3-beta.2

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