@elizaos/plugin-commands 2.0.0-alpha.3 → 2.0.0-alpha.4
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/cjs/index.cjs +208 -138
- package/dist/cjs/index.cjs.map +10 -10
- package/dist/index.js +208 -138
- package/dist/index.js.map +10 -10
- package/package.json +8 -6
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
logger
|
|
3
|
+
logger as logger3
|
|
4
4
|
} from "@elizaos/core";
|
|
5
5
|
|
|
6
6
|
// src/registry.ts
|
|
@@ -97,9 +97,7 @@ var DEFAULT_COMMANDS = [
|
|
|
97
97
|
scope: "both",
|
|
98
98
|
category: "session",
|
|
99
99
|
acceptsArgs: true,
|
|
100
|
-
args: [
|
|
101
|
-
{ name: "instructions", description: "Optional compaction instructions" }
|
|
102
|
-
]
|
|
100
|
+
args: [{ name: "instructions", description: "Optional compaction instructions" }]
|
|
103
101
|
},
|
|
104
102
|
{
|
|
105
103
|
key: "think",
|
|
@@ -109,9 +107,7 @@ var DEFAULT_COMMANDS = [
|
|
|
109
107
|
scope: "both",
|
|
110
108
|
category: "options",
|
|
111
109
|
acceptsArgs: true,
|
|
112
|
-
args: [
|
|
113
|
-
{ name: "level", description: "off, minimal, low, medium, high, xhigh" }
|
|
114
|
-
]
|
|
110
|
+
args: [{ name: "level", description: "off, minimal, low, medium, high, xhigh" }]
|
|
115
111
|
},
|
|
116
112
|
{
|
|
117
113
|
key: "verbose",
|
|
@@ -286,21 +282,39 @@ var DEFAULT_COMMANDS = [
|
|
|
286
282
|
requiresElevated: true
|
|
287
283
|
}
|
|
288
284
|
];
|
|
289
|
-
var
|
|
290
|
-
var
|
|
285
|
+
var runtimeStores = new Map;
|
|
286
|
+
var fallbackStore = {
|
|
287
|
+
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
288
|
+
aliasMap: null
|
|
289
|
+
};
|
|
290
|
+
var activeStore = fallbackStore;
|
|
291
|
+
function initForRuntime(agentId) {
|
|
292
|
+
const store = {
|
|
293
|
+
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
294
|
+
aliasMap: null
|
|
295
|
+
};
|
|
296
|
+
runtimeStores.set(agentId, store);
|
|
297
|
+
activeStore = store;
|
|
298
|
+
}
|
|
299
|
+
function useRuntime(agentId) {
|
|
300
|
+
const store = runtimeStores.get(agentId);
|
|
301
|
+
if (store) {
|
|
302
|
+
activeStore = store;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
291
305
|
function getCommands() {
|
|
292
|
-
return [...commands];
|
|
306
|
+
return [...activeStore.commands];
|
|
293
307
|
}
|
|
294
308
|
function getEnabledCommands() {
|
|
295
|
-
return commands.filter((cmd) => cmd.enabled !== false);
|
|
309
|
+
return activeStore.commands.filter((cmd) => cmd.enabled !== false);
|
|
296
310
|
}
|
|
297
311
|
function getCommandsByCategory(category) {
|
|
298
|
-
return commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
312
|
+
return activeStore.commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
299
313
|
}
|
|
300
314
|
function registerCommand(command) {
|
|
301
|
-
commands = commands.filter((c) => c.key !== command.key);
|
|
302
|
-
commands.push(command);
|
|
303
|
-
aliasMap = null;
|
|
315
|
+
activeStore.commands = activeStore.commands.filter((c) => c.key !== command.key);
|
|
316
|
+
activeStore.commands.push(command);
|
|
317
|
+
activeStore.aliasMap = null;
|
|
304
318
|
}
|
|
305
319
|
function registerCommands(newCommands) {
|
|
306
320
|
for (const command of newCommands) {
|
|
@@ -308,35 +322,35 @@ function registerCommands(newCommands) {
|
|
|
308
322
|
}
|
|
309
323
|
}
|
|
310
324
|
function unregisterCommand(key) {
|
|
311
|
-
commands = commands.filter((c) => c.key !== key);
|
|
312
|
-
aliasMap = null;
|
|
325
|
+
activeStore.commands = activeStore.commands.filter((c) => c.key !== key);
|
|
326
|
+
activeStore.aliasMap = null;
|
|
313
327
|
}
|
|
314
328
|
function resetCommands() {
|
|
315
|
-
commands =
|
|
316
|
-
aliasMap = null;
|
|
329
|
+
activeStore.commands = DEFAULT_COMMANDS.map((c) => ({ ...c }));
|
|
330
|
+
activeStore.aliasMap = null;
|
|
317
331
|
}
|
|
318
332
|
function getAliasMap() {
|
|
319
|
-
if (aliasMap)
|
|
320
|
-
return aliasMap;
|
|
321
|
-
aliasMap = new Map;
|
|
322
|
-
for (const command of commands) {
|
|
333
|
+
if (activeStore.aliasMap)
|
|
334
|
+
return activeStore.aliasMap;
|
|
335
|
+
activeStore.aliasMap = new Map;
|
|
336
|
+
for (const command of activeStore.commands) {
|
|
323
337
|
if (command.enabled === false)
|
|
324
338
|
continue;
|
|
325
339
|
for (const alias of command.textAliases) {
|
|
326
340
|
const normalized = alias.toLowerCase().trim();
|
|
327
|
-
if (!aliasMap.has(normalized)) {
|
|
328
|
-
aliasMap.set(normalized, command);
|
|
341
|
+
if (!activeStore.aliasMap.has(normalized)) {
|
|
342
|
+
activeStore.aliasMap.set(normalized, command);
|
|
329
343
|
}
|
|
330
344
|
}
|
|
331
345
|
}
|
|
332
|
-
return aliasMap;
|
|
346
|
+
return activeStore.aliasMap;
|
|
333
347
|
}
|
|
334
348
|
function findCommandByAlias(alias) {
|
|
335
349
|
const map = getAliasMap();
|
|
336
350
|
return map.get(alias.toLowerCase().trim());
|
|
337
351
|
}
|
|
338
352
|
function findCommandByKey(key) {
|
|
339
|
-
return commands.find((c) => c.key === key);
|
|
353
|
+
return activeStore.commands.find((c) => c.key === key);
|
|
340
354
|
}
|
|
341
355
|
function startsWithCommand(text) {
|
|
342
356
|
const map = getAliasMap();
|
|
@@ -345,7 +359,7 @@ function startsWithCommand(text) {
|
|
|
345
359
|
if (normalized === alias) {
|
|
346
360
|
return command;
|
|
347
361
|
}
|
|
348
|
-
if (normalized.startsWith(alias
|
|
362
|
+
if (normalized.startsWith(`${alias} `) || normalized.startsWith(`${alias}:`)) {
|
|
349
363
|
return command;
|
|
350
364
|
}
|
|
351
365
|
}
|
|
@@ -389,7 +403,7 @@ function parseCommand(text, definition) {
|
|
|
389
403
|
matchedAlias = alias;
|
|
390
404
|
break;
|
|
391
405
|
}
|
|
392
|
-
if (trimmed.toLowerCase().startsWith(normalized
|
|
406
|
+
if (trimmed.toLowerCase().startsWith(`${normalized} `) || trimmed.toLowerCase().startsWith(`${normalized}:`)) {
|
|
393
407
|
matchedAlias = alias;
|
|
394
408
|
break;
|
|
395
409
|
}
|
|
@@ -498,18 +512,18 @@ function extractCommand(text) {
|
|
|
498
512
|
// src/actions/commands-list.ts
|
|
499
513
|
var commandsListAction = {
|
|
500
514
|
name: "COMMANDS_LIST",
|
|
501
|
-
description: "List all available commands with their aliases",
|
|
502
|
-
similes: ["/commands", "/cmds"
|
|
503
|
-
async validate(
|
|
515
|
+
description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
|
|
516
|
+
similes: ["/commands", "/cmds"],
|
|
517
|
+
async validate(_runtime, message) {
|
|
504
518
|
const text = message.content?.text ?? "";
|
|
505
519
|
const detection = detectCommand(text);
|
|
506
520
|
return detection.isCommand && detection.command?.key === "commands";
|
|
507
521
|
},
|
|
508
|
-
async handler(
|
|
509
|
-
const
|
|
510
|
-
const lines = [`**Commands (${
|
|
522
|
+
async handler(_runtime, _message, _state, _options, callback) {
|
|
523
|
+
const commands = getEnabledCommands();
|
|
524
|
+
const lines = [`**Commands (${commands.length}):**
|
|
511
525
|
`];
|
|
512
|
-
for (const cmd of
|
|
526
|
+
for (const cmd of commands) {
|
|
513
527
|
const aliases = cmd.textAliases.join(", ");
|
|
514
528
|
const authNote = cmd.requiresAuth ? " [auth]" : "";
|
|
515
529
|
const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
|
|
@@ -521,7 +535,7 @@ var commandsListAction = {
|
|
|
521
535
|
return {
|
|
522
536
|
success: true,
|
|
523
537
|
text: replyText,
|
|
524
|
-
data: { commandCount:
|
|
538
|
+
data: { commandCount: commands.length }
|
|
525
539
|
};
|
|
526
540
|
},
|
|
527
541
|
examples: [
|
|
@@ -541,7 +555,7 @@ var commandsListAction = {
|
|
|
541
555
|
};
|
|
542
556
|
|
|
543
557
|
// src/actions/help.ts
|
|
544
|
-
function formatCommandList(
|
|
558
|
+
function formatCommandList(commands) {
|
|
545
559
|
const lines = [`**Available Commands:**
|
|
546
560
|
`];
|
|
547
561
|
const categories = [
|
|
@@ -553,7 +567,7 @@ function formatCommandList(commands2) {
|
|
|
553
567
|
{ key: "tools", name: "Tools" }
|
|
554
568
|
];
|
|
555
569
|
for (const cat of categories) {
|
|
556
|
-
const catCommands =
|
|
570
|
+
const catCommands = commands.filter((c) => c.category === cat.key);
|
|
557
571
|
if (catCommands.length === 0)
|
|
558
572
|
continue;
|
|
559
573
|
lines.push(`
|
|
@@ -563,7 +577,7 @@ function formatCommandList(commands2) {
|
|
|
563
577
|
lines.push(`• ${aliases} - ${cmd.description}`);
|
|
564
578
|
}
|
|
565
579
|
}
|
|
566
|
-
const uncategorized =
|
|
580
|
+
const uncategorized = commands.filter((c) => !c.category);
|
|
567
581
|
if (uncategorized.length > 0) {
|
|
568
582
|
lines.push(`
|
|
569
583
|
**Other:**`);
|
|
@@ -577,21 +591,21 @@ function formatCommandList(commands2) {
|
|
|
577
591
|
}
|
|
578
592
|
var helpAction = {
|
|
579
593
|
name: "HELP_COMMAND",
|
|
580
|
-
description: "Show available commands and their descriptions",
|
|
581
|
-
similes: ["/help", "/h", "/?"
|
|
582
|
-
async validate(
|
|
594
|
+
description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
|
|
595
|
+
similes: ["/help", "/h", "/?"],
|
|
596
|
+
async validate(_runtime, message) {
|
|
583
597
|
const text = message.content?.text ?? "";
|
|
584
598
|
const detection = detectCommand(text);
|
|
585
599
|
return detection.isCommand && detection.command?.key === "help";
|
|
586
600
|
},
|
|
587
|
-
async handler(
|
|
588
|
-
const
|
|
589
|
-
const helpText = formatCommandList(
|
|
601
|
+
async handler(_runtime, _message, _state, _options, callback) {
|
|
602
|
+
const commands = getEnabledCommands();
|
|
603
|
+
const helpText = formatCommandList(commands);
|
|
590
604
|
await callback?.({ text: helpText });
|
|
591
605
|
return {
|
|
592
606
|
success: true,
|
|
593
607
|
text: helpText,
|
|
594
|
-
data: { commandCount:
|
|
608
|
+
data: { commandCount: commands.length }
|
|
595
609
|
};
|
|
596
610
|
},
|
|
597
611
|
examples: [
|
|
@@ -623,49 +637,74 @@ var helpAction = {
|
|
|
623
637
|
};
|
|
624
638
|
|
|
625
639
|
// src/actions/models.ts
|
|
640
|
+
import { logger, ModelType } from "@elizaos/core";
|
|
641
|
+
function describeModelType(modelType) {
|
|
642
|
+
const descriptions = {
|
|
643
|
+
[ModelType.TEXT_SMALL]: "Text (Small)",
|
|
644
|
+
[ModelType.TEXT_LARGE]: "Text (Large)",
|
|
645
|
+
[ModelType.TEXT_REASONING_SMALL]: "Reasoning (Small)",
|
|
646
|
+
[ModelType.TEXT_REASONING_LARGE]: "Reasoning (Large)",
|
|
647
|
+
[ModelType.TEXT_COMPLETION]: "Text Completion",
|
|
648
|
+
[ModelType.TEXT_EMBEDDING]: "Embedding",
|
|
649
|
+
[ModelType.IMAGE]: "Image Generation",
|
|
650
|
+
[ModelType.IMAGE_DESCRIPTION]: "Image Description",
|
|
651
|
+
[ModelType.TRANSCRIPTION]: "Transcription",
|
|
652
|
+
[ModelType.TEXT_TO_SPEECH]: "Text-to-Speech",
|
|
653
|
+
[ModelType.AUDIO]: "Audio",
|
|
654
|
+
[ModelType.VIDEO]: "Video",
|
|
655
|
+
[ModelType.OBJECT_SMALL]: "Object (Small)",
|
|
656
|
+
[ModelType.OBJECT_LARGE]: "Object (Large)",
|
|
657
|
+
[ModelType.RESEARCH]: "Research"
|
|
658
|
+
};
|
|
659
|
+
return descriptions[modelType] ?? modelType;
|
|
660
|
+
}
|
|
626
661
|
var modelsAction = {
|
|
627
662
|
name: "MODELS_COMMAND",
|
|
628
|
-
description: "List available AI models and providers",
|
|
629
|
-
similes: ["/models"
|
|
630
|
-
async validate(
|
|
663
|
+
description: "List available AI models and providers. Only activates for /models slash command.",
|
|
664
|
+
similes: ["/models"],
|
|
665
|
+
async validate(_runtime, message) {
|
|
631
666
|
const text = message.content?.text ?? "";
|
|
632
667
|
const detection = detectCommand(text);
|
|
633
668
|
return detection.isCommand && detection.command?.key === "models";
|
|
634
669
|
},
|
|
635
|
-
async handler(runtime,
|
|
670
|
+
async handler(runtime, _message, _state, _options, callback) {
|
|
636
671
|
const lines = [`**Available Models:**
|
|
637
672
|
`];
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
"gpt-4o",
|
|
652
|
-
"gpt-4o-mini",
|
|
653
|
-
"gpt-4-turbo",
|
|
654
|
-
"gpt-4",
|
|
655
|
-
"gpt-3.5-turbo"
|
|
656
|
-
]
|
|
657
|
-
},
|
|
658
|
-
{
|
|
659
|
-
name: "Google",
|
|
660
|
-
models: ["gemini-pro", "gemini-pro-vision", "gemini-ultra"]
|
|
673
|
+
try {
|
|
674
|
+
const registeredTypes = [];
|
|
675
|
+
const seen = new Set;
|
|
676
|
+
for (const modelType of Object.values(ModelType)) {
|
|
677
|
+
if (seen.has(modelType))
|
|
678
|
+
continue;
|
|
679
|
+
seen.add(modelType);
|
|
680
|
+
try {
|
|
681
|
+
const handler = runtime.getModel(modelType);
|
|
682
|
+
if (handler) {
|
|
683
|
+
registeredTypes.push(modelType);
|
|
684
|
+
}
|
|
685
|
+
} catch {}
|
|
661
686
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
687
|
+
if (registeredTypes.length > 0) {
|
|
688
|
+
lines.push("**Registered Model Types:**");
|
|
689
|
+
for (const modelType of registeredTypes) {
|
|
690
|
+
lines.push(`• ${describeModelType(modelType)} (\`${modelType}\`)`);
|
|
691
|
+
}
|
|
692
|
+
} else {
|
|
693
|
+
lines.push("No model handlers are currently registered.");
|
|
668
694
|
}
|
|
695
|
+
const modelProvider = runtime.getSetting("MODEL_PROVIDER");
|
|
696
|
+
const modelName = runtime.getSetting("MODEL_NAME");
|
|
697
|
+
if (modelProvider || modelName) {
|
|
698
|
+
lines.push(`
|
|
699
|
+
**Current Configuration:**`);
|
|
700
|
+
if (modelProvider)
|
|
701
|
+
lines.push(`• Provider: ${modelProvider}`);
|
|
702
|
+
if (modelName)
|
|
703
|
+
lines.push(`• Model: ${modelName}`);
|
|
704
|
+
}
|
|
705
|
+
} catch (err) {
|
|
706
|
+
logger.warn({ src: "plugin-commands", err }, "Error querying runtime models");
|
|
707
|
+
lines.push("Unable to query available models.");
|
|
669
708
|
}
|
|
670
709
|
lines.push(`
|
|
671
710
|
|
|
@@ -675,8 +714,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
675
714
|
await callback?.({ text: replyText });
|
|
676
715
|
return {
|
|
677
716
|
success: true,
|
|
678
|
-
text: replyText
|
|
679
|
-
data: { providers }
|
|
717
|
+
text: replyText
|
|
680
718
|
};
|
|
681
719
|
},
|
|
682
720
|
examples: [
|
|
@@ -685,11 +723,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
685
723
|
{
|
|
686
724
|
user: "assistant",
|
|
687
725
|
content: {
|
|
688
|
-
text:
|
|
689
|
-
|
|
690
|
-
**Anthropic:**
|
|
691
|
-
• anthropic/claude-3-opus
|
|
692
|
-
• anthropic/claude-3-sonnet...`
|
|
726
|
+
text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
|
|
693
727
|
}
|
|
694
728
|
}
|
|
695
729
|
]
|
|
@@ -700,7 +734,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
700
734
|
async function buildStatusReport(runtime, roomId) {
|
|
701
735
|
const lines = [`**Session Status:**
|
|
702
736
|
`];
|
|
703
|
-
lines.push(`**Agent:** ${runtime.agentId}`);
|
|
737
|
+
lines.push(`**Agent:** ${runtime.character.name ?? runtime.agentId}`);
|
|
704
738
|
lines.push(`**Room:** ${roomId}`);
|
|
705
739
|
try {
|
|
706
740
|
const directiveService = runtime.getService("directive-parser");
|
|
@@ -720,19 +754,26 @@ async function buildStatusReport(runtime, roomId) {
|
|
|
720
754
|
}
|
|
721
755
|
}
|
|
722
756
|
} catch {}
|
|
757
|
+
try {
|
|
758
|
+
const tasks = await runtime.getTasks({ roomId });
|
|
759
|
+
if (tasks.length > 0) {
|
|
760
|
+
lines.push(`
|
|
761
|
+
**Tasks:** ${tasks.length} pending`);
|
|
762
|
+
}
|
|
763
|
+
} catch {}
|
|
723
764
|
return lines.join(`
|
|
724
765
|
`);
|
|
725
766
|
}
|
|
726
767
|
var statusAction = {
|
|
727
768
|
name: "STATUS_COMMAND",
|
|
728
|
-
description: "Show
|
|
729
|
-
similes: ["/status", "/s"
|
|
730
|
-
async validate(
|
|
769
|
+
description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
|
|
770
|
+
similes: ["/status", "/s"],
|
|
771
|
+
async validate(_runtime, message) {
|
|
731
772
|
const text = message.content?.text ?? "";
|
|
732
773
|
const detection = detectCommand(text);
|
|
733
774
|
return detection.isCommand && detection.command?.key === "status";
|
|
734
775
|
},
|
|
735
|
-
async handler(runtime, message,
|
|
776
|
+
async handler(runtime, message, _state, _options, callback) {
|
|
736
777
|
const statusText = await buildStatusReport(runtime, message.roomId);
|
|
737
778
|
await callback?.({ text: statusText });
|
|
738
779
|
return {
|
|
@@ -748,7 +789,7 @@ var statusAction = {
|
|
|
748
789
|
content: {
|
|
749
790
|
text: `**Session Status:**
|
|
750
791
|
|
|
751
|
-
**Agent:**
|
|
792
|
+
**Agent:** Eliza
|
|
752
793
|
**Room:** room-456
|
|
753
794
|
|
|
754
795
|
**Directives:**
|
|
@@ -760,23 +801,34 @@ var statusAction = {
|
|
|
760
801
|
};
|
|
761
802
|
|
|
762
803
|
// src/actions/stop.ts
|
|
804
|
+
import { EventType, logger as logger2 } from "@elizaos/core";
|
|
763
805
|
var stopAction = {
|
|
764
806
|
name: "STOP_COMMAND",
|
|
765
|
-
description: "Stop current operation or abort running tasks",
|
|
766
|
-
similes: ["/stop", "/abort", "/cancel"
|
|
767
|
-
async validate(
|
|
807
|
+
description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
|
|
808
|
+
similes: ["/stop", "/abort", "/cancel"],
|
|
809
|
+
async validate(_runtime, message) {
|
|
768
810
|
const text = message.content?.text ?? "";
|
|
769
811
|
const detection = detectCommand(text);
|
|
770
812
|
return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
|
|
771
813
|
},
|
|
772
|
-
async handler(runtime, message,
|
|
814
|
+
async handler(runtime, message, _state, _options, callback) {
|
|
773
815
|
try {
|
|
774
|
-
await runtime.emitEvent
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
816
|
+
await runtime.emitEvent(EventType.HOOK_COMMAND_STOP, {
|
|
817
|
+
runtime,
|
|
818
|
+
sessionKey: message.roomId,
|
|
819
|
+
messages: [],
|
|
820
|
+
timestamp: new Date,
|
|
821
|
+
context: {
|
|
822
|
+
entityId: message.entityId,
|
|
823
|
+
source: message.content?.source
|
|
824
|
+
},
|
|
825
|
+
command: "stop",
|
|
826
|
+
senderId: message.entityId,
|
|
827
|
+
commandSource: message.content?.source
|
|
778
828
|
});
|
|
779
|
-
} catch {
|
|
829
|
+
} catch (err) {
|
|
830
|
+
logger2.warn({ src: "plugin-commands", err }, "Failed to emit HOOK_COMMAND_STOP event");
|
|
831
|
+
}
|
|
780
832
|
const replyText = "✓ Stop requested. Current operations will be cancelled.";
|
|
781
833
|
await callback?.({ text: replyText });
|
|
782
834
|
return {
|
|
@@ -812,28 +864,44 @@ var commandRegistryProvider = {
|
|
|
812
864
|
description: "Available chat commands and their descriptions",
|
|
813
865
|
dynamic: true,
|
|
814
866
|
async get(runtime, message, _state) {
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
867
|
+
useRuntime(runtime.agentId);
|
|
868
|
+
const text = message.content?.text ?? "";
|
|
869
|
+
const isCommand = hasCommand(text);
|
|
870
|
+
const commands = getEnabledCommands();
|
|
871
|
+
if (isCommand) {
|
|
872
|
+
const commandList = commands.map((cmd) => {
|
|
873
|
+
const auth = cmd.requiresAuth ? " (requires auth)" : "";
|
|
874
|
+
return `- ${cmd.textAliases[0]}: ${cmd.description}${auth}`;
|
|
875
|
+
});
|
|
876
|
+
return {
|
|
877
|
+
text: `The user sent a slash command. Available commands:
|
|
822
878
|
${commandList.join(`
|
|
823
|
-
`)}
|
|
879
|
+
`)}
|
|
880
|
+
|
|
881
|
+
IMPORTANT: This is a slash command — respond by executing the matching command action, not with conversational text.`,
|
|
882
|
+
values: {
|
|
883
|
+
commandCount: commands.length,
|
|
884
|
+
isCommand: true,
|
|
885
|
+
hasElevatedCommands: commands.some((c) => c.requiresElevated)
|
|
886
|
+
},
|
|
887
|
+
data: { commands, isCommand: true }
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
return {
|
|
891
|
+
text: "",
|
|
824
892
|
values: {
|
|
825
|
-
commandCount:
|
|
826
|
-
|
|
893
|
+
commandCount: commands.length,
|
|
894
|
+
isCommand: false
|
|
827
895
|
},
|
|
828
|
-
data: {
|
|
896
|
+
data: { isCommand: false }
|
|
829
897
|
};
|
|
830
898
|
}
|
|
831
899
|
};
|
|
832
900
|
function formatCommandResult(result) {
|
|
833
901
|
if (result.error) {
|
|
834
|
-
return
|
|
902
|
+
return `Error: ${result.error}`;
|
|
835
903
|
}
|
|
836
|
-
return result.reply ?? "
|
|
904
|
+
return result.reply ?? "Command executed";
|
|
837
905
|
}
|
|
838
906
|
function isAuthorized(context, command) {
|
|
839
907
|
if (!command.requiresAuth) {
|
|
@@ -851,13 +919,7 @@ var commandsPlugin = {
|
|
|
851
919
|
name: "commands",
|
|
852
920
|
description: "Chat command system with /help, /status, /reset, etc.",
|
|
853
921
|
providers: [commandRegistryProvider],
|
|
854
|
-
actions: [
|
|
855
|
-
helpAction,
|
|
856
|
-
statusAction,
|
|
857
|
-
stopAction,
|
|
858
|
-
modelsAction,
|
|
859
|
-
commandsListAction
|
|
860
|
-
],
|
|
922
|
+
actions: [helpAction, statusAction, stopAction, modelsAction, commandsListAction],
|
|
861
923
|
config: {
|
|
862
924
|
COMMANDS_ENABLED: "true",
|
|
863
925
|
COMMANDS_CONFIG_ENABLED: "false",
|
|
@@ -881,7 +943,7 @@ var commandsPlugin = {
|
|
|
881
943
|
if (hasCommand("hello world")) {
|
|
882
944
|
throw new Error("Should not detect plain text as command");
|
|
883
945
|
}
|
|
884
|
-
|
|
946
|
+
logger3.success("Command prefix detection works correctly");
|
|
885
947
|
}
|
|
886
948
|
},
|
|
887
949
|
{
|
|
@@ -897,7 +959,7 @@ var commandsPlugin = {
|
|
|
897
959
|
if (detection.command?.args[0] !== "high") {
|
|
898
960
|
throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
|
|
899
961
|
}
|
|
900
|
-
|
|
962
|
+
logger3.success("Command argument parsing works correctly");
|
|
901
963
|
}
|
|
902
964
|
},
|
|
903
965
|
{
|
|
@@ -911,7 +973,7 @@ var commandsPlugin = {
|
|
|
911
973
|
if (normalized2 !== "/help") {
|
|
912
974
|
throw new Error(`Expected '/help', got '${normalized2}'`);
|
|
913
975
|
}
|
|
914
|
-
|
|
976
|
+
logger3.success("Command normalization works correctly");
|
|
915
977
|
}
|
|
916
978
|
},
|
|
917
979
|
{
|
|
@@ -924,7 +986,7 @@ var commandsPlugin = {
|
|
|
924
986
|
if (cmd.key !== "help") {
|
|
925
987
|
throw new Error(`Expected key 'help', got '${cmd.key}'`);
|
|
926
988
|
}
|
|
927
|
-
|
|
989
|
+
logger3.success("Command alias lookup works correctly");
|
|
928
990
|
}
|
|
929
991
|
},
|
|
930
992
|
{
|
|
@@ -937,7 +999,7 @@ var commandsPlugin = {
|
|
|
937
999
|
if (cmd.key !== "status") {
|
|
938
1000
|
throw new Error(`Expected key 'status', got '${cmd.key}'`);
|
|
939
1001
|
}
|
|
940
|
-
|
|
1002
|
+
logger3.success("Command key lookup works correctly");
|
|
941
1003
|
}
|
|
942
1004
|
}
|
|
943
1005
|
]
|
|
@@ -948,16 +1010,16 @@ var commandsPlugin = {
|
|
|
948
1010
|
{
|
|
949
1011
|
name: "Get enabled commands",
|
|
950
1012
|
fn: async (_runtime) => {
|
|
951
|
-
const
|
|
952
|
-
if (
|
|
1013
|
+
const commands = getEnabledCommands();
|
|
1014
|
+
if (commands.length === 0) {
|
|
953
1015
|
throw new Error("Should have enabled commands");
|
|
954
1016
|
}
|
|
955
|
-
const
|
|
956
|
-
const
|
|
957
|
-
if (!
|
|
1017
|
+
const cmdHelp = commands.some((c) => c.key === "help");
|
|
1018
|
+
const cmdStatus = commands.some((c) => c.key === "status");
|
|
1019
|
+
if (!cmdHelp || !cmdStatus) {
|
|
958
1020
|
throw new Error("Should have help and status commands");
|
|
959
1021
|
}
|
|
960
|
-
|
|
1022
|
+
logger3.success("Command registry works correctly");
|
|
961
1023
|
}
|
|
962
1024
|
},
|
|
963
1025
|
{
|
|
@@ -979,7 +1041,7 @@ var commandsPlugin = {
|
|
|
979
1041
|
if (notFound) {
|
|
980
1042
|
throw new Error("Should not find unregistered command");
|
|
981
1043
|
}
|
|
982
|
-
|
|
1044
|
+
logger3.success("Custom command registration works correctly");
|
|
983
1045
|
}
|
|
984
1046
|
},
|
|
985
1047
|
{
|
|
@@ -993,17 +1055,19 @@ var commandsPlugin = {
|
|
|
993
1055
|
if (!allStatus) {
|
|
994
1056
|
throw new Error("All returned commands should be in status category");
|
|
995
1057
|
}
|
|
996
|
-
|
|
1058
|
+
logger3.success("Command categorization works correctly");
|
|
997
1059
|
}
|
|
998
1060
|
}
|
|
999
1061
|
]
|
|
1000
1062
|
}
|
|
1001
1063
|
],
|
|
1002
1064
|
async init(config, runtime) {
|
|
1003
|
-
|
|
1065
|
+
logger3.log("[plugin-commands] Initializing command system");
|
|
1066
|
+
initForRuntime(runtime.agentId);
|
|
1004
1067
|
const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
|
|
1005
1068
|
const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
|
|
1006
1069
|
const bashEnabled = config.COMMANDS_BASH_ENABLED === "true";
|
|
1070
|
+
const restartEnabled = config.COMMANDS_RESTART_ENABLED !== "false";
|
|
1007
1071
|
const configCmd = findCommandByKey("config");
|
|
1008
1072
|
if (configCmd) {
|
|
1009
1073
|
configCmd.enabled = configEnabled;
|
|
@@ -1016,12 +1080,17 @@ var commandsPlugin = {
|
|
|
1016
1080
|
if (bashCmd) {
|
|
1017
1081
|
bashCmd.enabled = bashEnabled;
|
|
1018
1082
|
}
|
|
1083
|
+
const restartCmd = findCommandByKey("restart");
|
|
1084
|
+
if (restartCmd) {
|
|
1085
|
+
restartCmd.enabled = restartEnabled;
|
|
1086
|
+
}
|
|
1019
1087
|
const enabledCount = getEnabledCommands().length;
|
|
1020
|
-
|
|
1088
|
+
logger3.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
|
|
1021
1089
|
}
|
|
1022
1090
|
};
|
|
1023
1091
|
var src_default = commandsPlugin;
|
|
1024
1092
|
export {
|
|
1093
|
+
useRuntime,
|
|
1025
1094
|
unregisterCommand,
|
|
1026
1095
|
startsWithCommand,
|
|
1027
1096
|
resetCommands,
|
|
@@ -1032,6 +1101,7 @@ export {
|
|
|
1032
1101
|
isElevated,
|
|
1033
1102
|
isCommandOnly,
|
|
1034
1103
|
isAuthorized,
|
|
1104
|
+
initForRuntime,
|
|
1035
1105
|
hasCommand,
|
|
1036
1106
|
getEnabledCommands,
|
|
1037
1107
|
getCommandsByCategory,
|
|
@@ -1046,4 +1116,4 @@ export {
|
|
|
1046
1116
|
commandRegistryProvider
|
|
1047
1117
|
};
|
|
1048
1118
|
|
|
1049
|
-
//# debugId=
|
|
1119
|
+
//# debugId=0433499C9EE6AF7764756E2164756E21
|