@elizaos/plugin-commands 2.0.0-alpha.3 → 2.0.0-alpha.5
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 +193 -113
- package/dist/cjs/index.cjs.map +9 -9
- package/dist/index.js +193 -113
- package/dist/index.js.map +9 -9
- package/package.json +8 -6
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __export = (target, all) => {
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var exports_src = {};
|
|
31
31
|
__export(exports_src, {
|
|
32
|
+
useRuntime: () => useRuntime,
|
|
32
33
|
unregisterCommand: () => unregisterCommand,
|
|
33
34
|
startsWithCommand: () => startsWithCommand,
|
|
34
35
|
resetCommands: () => resetCommands,
|
|
@@ -39,6 +40,7 @@ __export(exports_src, {
|
|
|
39
40
|
isElevated: () => isElevated,
|
|
40
41
|
isCommandOnly: () => isCommandOnly,
|
|
41
42
|
isAuthorized: () => isAuthorized,
|
|
43
|
+
initForRuntime: () => initForRuntime,
|
|
42
44
|
hasCommand: () => hasCommand,
|
|
43
45
|
getEnabledCommands: () => getEnabledCommands,
|
|
44
46
|
getCommandsByCategory: () => getCommandsByCategory,
|
|
@@ -53,7 +55,7 @@ __export(exports_src, {
|
|
|
53
55
|
commandRegistryProvider: () => commandRegistryProvider
|
|
54
56
|
});
|
|
55
57
|
module.exports = __toCommonJS(exports_src);
|
|
56
|
-
var
|
|
58
|
+
var import_core3 = require("@elizaos/core");
|
|
57
59
|
|
|
58
60
|
// src/registry.ts
|
|
59
61
|
var DEFAULT_COMMANDS = [
|
|
@@ -338,21 +340,39 @@ var DEFAULT_COMMANDS = [
|
|
|
338
340
|
requiresElevated: true
|
|
339
341
|
}
|
|
340
342
|
];
|
|
341
|
-
var
|
|
342
|
-
var
|
|
343
|
+
var runtimeStores = new Map;
|
|
344
|
+
var fallbackStore = {
|
|
345
|
+
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
346
|
+
aliasMap: null
|
|
347
|
+
};
|
|
348
|
+
var activeStore = fallbackStore;
|
|
349
|
+
function initForRuntime(agentId) {
|
|
350
|
+
const store = {
|
|
351
|
+
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
352
|
+
aliasMap: null
|
|
353
|
+
};
|
|
354
|
+
runtimeStores.set(agentId, store);
|
|
355
|
+
activeStore = store;
|
|
356
|
+
}
|
|
357
|
+
function useRuntime(agentId) {
|
|
358
|
+
const store = runtimeStores.get(agentId);
|
|
359
|
+
if (store) {
|
|
360
|
+
activeStore = store;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
343
363
|
function getCommands() {
|
|
344
|
-
return [...commands];
|
|
364
|
+
return [...activeStore.commands];
|
|
345
365
|
}
|
|
346
366
|
function getEnabledCommands() {
|
|
347
|
-
return commands.filter((cmd) => cmd.enabled !== false);
|
|
367
|
+
return activeStore.commands.filter((cmd) => cmd.enabled !== false);
|
|
348
368
|
}
|
|
349
369
|
function getCommandsByCategory(category) {
|
|
350
|
-
return commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
370
|
+
return activeStore.commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
351
371
|
}
|
|
352
372
|
function registerCommand(command) {
|
|
353
|
-
commands = commands.filter((c) => c.key !== command.key);
|
|
354
|
-
commands.push(command);
|
|
355
|
-
aliasMap = null;
|
|
373
|
+
activeStore.commands = activeStore.commands.filter((c) => c.key !== command.key);
|
|
374
|
+
activeStore.commands.push(command);
|
|
375
|
+
activeStore.aliasMap = null;
|
|
356
376
|
}
|
|
357
377
|
function registerCommands(newCommands) {
|
|
358
378
|
for (const command of newCommands) {
|
|
@@ -360,35 +380,35 @@ function registerCommands(newCommands) {
|
|
|
360
380
|
}
|
|
361
381
|
}
|
|
362
382
|
function unregisterCommand(key) {
|
|
363
|
-
commands = commands.filter((c) => c.key !== key);
|
|
364
|
-
aliasMap = null;
|
|
383
|
+
activeStore.commands = activeStore.commands.filter((c) => c.key !== key);
|
|
384
|
+
activeStore.aliasMap = null;
|
|
365
385
|
}
|
|
366
386
|
function resetCommands() {
|
|
367
|
-
commands =
|
|
368
|
-
aliasMap = null;
|
|
387
|
+
activeStore.commands = DEFAULT_COMMANDS.map((c) => ({ ...c }));
|
|
388
|
+
activeStore.aliasMap = null;
|
|
369
389
|
}
|
|
370
390
|
function getAliasMap() {
|
|
371
|
-
if (aliasMap)
|
|
372
|
-
return aliasMap;
|
|
373
|
-
aliasMap = new Map;
|
|
374
|
-
for (const command of commands) {
|
|
391
|
+
if (activeStore.aliasMap)
|
|
392
|
+
return activeStore.aliasMap;
|
|
393
|
+
activeStore.aliasMap = new Map;
|
|
394
|
+
for (const command of activeStore.commands) {
|
|
375
395
|
if (command.enabled === false)
|
|
376
396
|
continue;
|
|
377
397
|
for (const alias of command.textAliases) {
|
|
378
398
|
const normalized = alias.toLowerCase().trim();
|
|
379
|
-
if (!aliasMap.has(normalized)) {
|
|
380
|
-
aliasMap.set(normalized, command);
|
|
399
|
+
if (!activeStore.aliasMap.has(normalized)) {
|
|
400
|
+
activeStore.aliasMap.set(normalized, command);
|
|
381
401
|
}
|
|
382
402
|
}
|
|
383
403
|
}
|
|
384
|
-
return aliasMap;
|
|
404
|
+
return activeStore.aliasMap;
|
|
385
405
|
}
|
|
386
406
|
function findCommandByAlias(alias) {
|
|
387
407
|
const map = getAliasMap();
|
|
388
408
|
return map.get(alias.toLowerCase().trim());
|
|
389
409
|
}
|
|
390
410
|
function findCommandByKey(key) {
|
|
391
|
-
return commands.find((c) => c.key === key);
|
|
411
|
+
return activeStore.commands.find((c) => c.key === key);
|
|
392
412
|
}
|
|
393
413
|
function startsWithCommand(text) {
|
|
394
414
|
const map = getAliasMap();
|
|
@@ -550,18 +570,18 @@ function extractCommand(text) {
|
|
|
550
570
|
// src/actions/commands-list.ts
|
|
551
571
|
var commandsListAction = {
|
|
552
572
|
name: "COMMANDS_LIST",
|
|
553
|
-
description: "List all available commands with their aliases",
|
|
554
|
-
similes: ["/commands", "/cmds"
|
|
573
|
+
description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
|
|
574
|
+
similes: ["/commands", "/cmds"],
|
|
555
575
|
async validate(runtime, message) {
|
|
556
576
|
const text = message.content?.text ?? "";
|
|
557
577
|
const detection = detectCommand(text);
|
|
558
578
|
return detection.isCommand && detection.command?.key === "commands";
|
|
559
579
|
},
|
|
560
580
|
async handler(runtime, message, state, options, callback) {
|
|
561
|
-
const
|
|
562
|
-
const lines = [`**Commands (${
|
|
581
|
+
const commands = getEnabledCommands();
|
|
582
|
+
const lines = [`**Commands (${commands.length}):**
|
|
563
583
|
`];
|
|
564
|
-
for (const cmd of
|
|
584
|
+
for (const cmd of commands) {
|
|
565
585
|
const aliases = cmd.textAliases.join(", ");
|
|
566
586
|
const authNote = cmd.requiresAuth ? " [auth]" : "";
|
|
567
587
|
const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
|
|
@@ -573,7 +593,7 @@ var commandsListAction = {
|
|
|
573
593
|
return {
|
|
574
594
|
success: true,
|
|
575
595
|
text: replyText,
|
|
576
|
-
data: { commandCount:
|
|
596
|
+
data: { commandCount: commands.length }
|
|
577
597
|
};
|
|
578
598
|
},
|
|
579
599
|
examples: [
|
|
@@ -593,7 +613,7 @@ var commandsListAction = {
|
|
|
593
613
|
};
|
|
594
614
|
|
|
595
615
|
// src/actions/help.ts
|
|
596
|
-
function formatCommandList(
|
|
616
|
+
function formatCommandList(commands) {
|
|
597
617
|
const lines = [`**Available Commands:**
|
|
598
618
|
`];
|
|
599
619
|
const categories = [
|
|
@@ -605,7 +625,7 @@ function formatCommandList(commands2) {
|
|
|
605
625
|
{ key: "tools", name: "Tools" }
|
|
606
626
|
];
|
|
607
627
|
for (const cat of categories) {
|
|
608
|
-
const catCommands =
|
|
628
|
+
const catCommands = commands.filter((c) => c.category === cat.key);
|
|
609
629
|
if (catCommands.length === 0)
|
|
610
630
|
continue;
|
|
611
631
|
lines.push(`
|
|
@@ -615,7 +635,7 @@ function formatCommandList(commands2) {
|
|
|
615
635
|
lines.push(`• ${aliases} - ${cmd.description}`);
|
|
616
636
|
}
|
|
617
637
|
}
|
|
618
|
-
const uncategorized =
|
|
638
|
+
const uncategorized = commands.filter((c) => !c.category);
|
|
619
639
|
if (uncategorized.length > 0) {
|
|
620
640
|
lines.push(`
|
|
621
641
|
**Other:**`);
|
|
@@ -629,21 +649,21 @@ function formatCommandList(commands2) {
|
|
|
629
649
|
}
|
|
630
650
|
var helpAction = {
|
|
631
651
|
name: "HELP_COMMAND",
|
|
632
|
-
description: "Show available commands and their descriptions",
|
|
633
|
-
similes: ["/help", "/h", "/?"
|
|
652
|
+
description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
|
|
653
|
+
similes: ["/help", "/h", "/?"],
|
|
634
654
|
async validate(runtime, message) {
|
|
635
655
|
const text = message.content?.text ?? "";
|
|
636
656
|
const detection = detectCommand(text);
|
|
637
657
|
return detection.isCommand && detection.command?.key === "help";
|
|
638
658
|
},
|
|
639
659
|
async handler(runtime, message, state, options, callback) {
|
|
640
|
-
const
|
|
641
|
-
const helpText = formatCommandList(
|
|
660
|
+
const commands = getEnabledCommands();
|
|
661
|
+
const helpText = formatCommandList(commands);
|
|
642
662
|
await callback?.({ text: helpText });
|
|
643
663
|
return {
|
|
644
664
|
success: true,
|
|
645
665
|
text: helpText,
|
|
646
|
-
data: { commandCount:
|
|
666
|
+
data: { commandCount: commands.length }
|
|
647
667
|
};
|
|
648
668
|
},
|
|
649
669
|
examples: [
|
|
@@ -675,10 +695,31 @@ var helpAction = {
|
|
|
675
695
|
};
|
|
676
696
|
|
|
677
697
|
// src/actions/models.ts
|
|
698
|
+
var import_core = require("@elizaos/core");
|
|
699
|
+
function describeModelType(modelType) {
|
|
700
|
+
const descriptions = {
|
|
701
|
+
[import_core.ModelType.TEXT_SMALL]: "Text (Small)",
|
|
702
|
+
[import_core.ModelType.TEXT_LARGE]: "Text (Large)",
|
|
703
|
+
[import_core.ModelType.TEXT_REASONING_SMALL]: "Reasoning (Small)",
|
|
704
|
+
[import_core.ModelType.TEXT_REASONING_LARGE]: "Reasoning (Large)",
|
|
705
|
+
[import_core.ModelType.TEXT_COMPLETION]: "Text Completion",
|
|
706
|
+
[import_core.ModelType.TEXT_EMBEDDING]: "Embedding",
|
|
707
|
+
[import_core.ModelType.IMAGE]: "Image Generation",
|
|
708
|
+
[import_core.ModelType.IMAGE_DESCRIPTION]: "Image Description",
|
|
709
|
+
[import_core.ModelType.TRANSCRIPTION]: "Transcription",
|
|
710
|
+
[import_core.ModelType.TEXT_TO_SPEECH]: "Text-to-Speech",
|
|
711
|
+
[import_core.ModelType.AUDIO]: "Audio",
|
|
712
|
+
[import_core.ModelType.VIDEO]: "Video",
|
|
713
|
+
[import_core.ModelType.OBJECT_SMALL]: "Object (Small)",
|
|
714
|
+
[import_core.ModelType.OBJECT_LARGE]: "Object (Large)",
|
|
715
|
+
[import_core.ModelType.RESEARCH]: "Research"
|
|
716
|
+
};
|
|
717
|
+
return descriptions[modelType] ?? modelType;
|
|
718
|
+
}
|
|
678
719
|
var modelsAction = {
|
|
679
720
|
name: "MODELS_COMMAND",
|
|
680
|
-
description: "List available AI models and providers",
|
|
681
|
-
similes: ["/models"
|
|
721
|
+
description: "List available AI models and providers. Only activates for /models slash command.",
|
|
722
|
+
similes: ["/models"],
|
|
682
723
|
async validate(runtime, message) {
|
|
683
724
|
const text = message.content?.text ?? "";
|
|
684
725
|
const detection = detectCommand(text);
|
|
@@ -687,37 +728,41 @@ var modelsAction = {
|
|
|
687
728
|
async handler(runtime, message, state, options, callback) {
|
|
688
729
|
const lines = [`**Available Models:**
|
|
689
730
|
`];
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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"]
|
|
731
|
+
try {
|
|
732
|
+
const registeredTypes = [];
|
|
733
|
+
const seen = new Set;
|
|
734
|
+
for (const modelType of Object.values(import_core.ModelType)) {
|
|
735
|
+
if (seen.has(modelType))
|
|
736
|
+
continue;
|
|
737
|
+
seen.add(modelType);
|
|
738
|
+
try {
|
|
739
|
+
const handler = runtime.getModel(modelType);
|
|
740
|
+
if (handler) {
|
|
741
|
+
registeredTypes.push(modelType);
|
|
742
|
+
}
|
|
743
|
+
} catch {}
|
|
713
744
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
745
|
+
if (registeredTypes.length > 0) {
|
|
746
|
+
lines.push("**Registered Model Types:**");
|
|
747
|
+
for (const modelType of registeredTypes) {
|
|
748
|
+
lines.push(`• ${describeModelType(modelType)} (\`${modelType}\`)`);
|
|
749
|
+
}
|
|
750
|
+
} else {
|
|
751
|
+
lines.push("No model handlers are currently registered.");
|
|
720
752
|
}
|
|
753
|
+
const modelProvider = runtime.getSetting("MODEL_PROVIDER");
|
|
754
|
+
const modelName = runtime.getSetting("MODEL_NAME");
|
|
755
|
+
if (modelProvider || modelName) {
|
|
756
|
+
lines.push(`
|
|
757
|
+
**Current Configuration:**`);
|
|
758
|
+
if (modelProvider)
|
|
759
|
+
lines.push(`• Provider: ${modelProvider}`);
|
|
760
|
+
if (modelName)
|
|
761
|
+
lines.push(`• Model: ${modelName}`);
|
|
762
|
+
}
|
|
763
|
+
} catch (err) {
|
|
764
|
+
import_core.logger.warn({ src: "plugin-commands", err }, "Error querying runtime models");
|
|
765
|
+
lines.push("Unable to query available models.");
|
|
721
766
|
}
|
|
722
767
|
lines.push(`
|
|
723
768
|
|
|
@@ -727,8 +772,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
727
772
|
await callback?.({ text: replyText });
|
|
728
773
|
return {
|
|
729
774
|
success: true,
|
|
730
|
-
text: replyText
|
|
731
|
-
data: { providers }
|
|
775
|
+
text: replyText
|
|
732
776
|
};
|
|
733
777
|
},
|
|
734
778
|
examples: [
|
|
@@ -737,11 +781,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
737
781
|
{
|
|
738
782
|
user: "assistant",
|
|
739
783
|
content: {
|
|
740
|
-
text:
|
|
741
|
-
|
|
742
|
-
**Anthropic:**
|
|
743
|
-
• anthropic/claude-3-opus
|
|
744
|
-
• anthropic/claude-3-sonnet...`
|
|
784
|
+
text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
|
|
745
785
|
}
|
|
746
786
|
}
|
|
747
787
|
]
|
|
@@ -752,7 +792,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
752
792
|
async function buildStatusReport(runtime, roomId) {
|
|
753
793
|
const lines = [`**Session Status:**
|
|
754
794
|
`];
|
|
755
|
-
lines.push(`**Agent:** ${runtime.agentId}`);
|
|
795
|
+
lines.push(`**Agent:** ${runtime.character.name ?? runtime.agentId}`);
|
|
756
796
|
lines.push(`**Room:** ${roomId}`);
|
|
757
797
|
try {
|
|
758
798
|
const directiveService = runtime.getService("directive-parser");
|
|
@@ -772,13 +812,20 @@ async function buildStatusReport(runtime, roomId) {
|
|
|
772
812
|
}
|
|
773
813
|
}
|
|
774
814
|
} catch {}
|
|
815
|
+
try {
|
|
816
|
+
const tasks = await runtime.getTasks({ roomId });
|
|
817
|
+
if (tasks.length > 0) {
|
|
818
|
+
lines.push(`
|
|
819
|
+
**Tasks:** ${tasks.length} pending`);
|
|
820
|
+
}
|
|
821
|
+
} catch {}
|
|
775
822
|
return lines.join(`
|
|
776
823
|
`);
|
|
777
824
|
}
|
|
778
825
|
var statusAction = {
|
|
779
826
|
name: "STATUS_COMMAND",
|
|
780
|
-
description: "Show
|
|
781
|
-
similes: ["/status", "/s"
|
|
827
|
+
description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
|
|
828
|
+
similes: ["/status", "/s"],
|
|
782
829
|
async validate(runtime, message) {
|
|
783
830
|
const text = message.content?.text ?? "";
|
|
784
831
|
const detection = detectCommand(text);
|
|
@@ -800,7 +847,7 @@ var statusAction = {
|
|
|
800
847
|
content: {
|
|
801
848
|
text: `**Session Status:**
|
|
802
849
|
|
|
803
|
-
**Agent:**
|
|
850
|
+
**Agent:** Eliza
|
|
804
851
|
**Room:** room-456
|
|
805
852
|
|
|
806
853
|
**Directives:**
|
|
@@ -812,10 +859,11 @@ var statusAction = {
|
|
|
812
859
|
};
|
|
813
860
|
|
|
814
861
|
// src/actions/stop.ts
|
|
862
|
+
var import_core2 = require("@elizaos/core");
|
|
815
863
|
var stopAction = {
|
|
816
864
|
name: "STOP_COMMAND",
|
|
817
|
-
description: "Stop current operation or abort running tasks",
|
|
818
|
-
similes: ["/stop", "/abort", "/cancel"
|
|
865
|
+
description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
|
|
866
|
+
similes: ["/stop", "/abort", "/cancel"],
|
|
819
867
|
async validate(runtime, message) {
|
|
820
868
|
const text = message.content?.text ?? "";
|
|
821
869
|
const detection = detectCommand(text);
|
|
@@ -823,12 +871,22 @@ var stopAction = {
|
|
|
823
871
|
},
|
|
824
872
|
async handler(runtime, message, state, options, callback) {
|
|
825
873
|
try {
|
|
826
|
-
await runtime.emitEvent
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
874
|
+
await runtime.emitEvent(import_core2.EventType.HOOK_COMMAND_STOP, {
|
|
875
|
+
runtime,
|
|
876
|
+
sessionKey: message.roomId,
|
|
877
|
+
messages: [],
|
|
878
|
+
timestamp: new Date,
|
|
879
|
+
context: {
|
|
880
|
+
entityId: message.entityId,
|
|
881
|
+
source: message.content?.source
|
|
882
|
+
},
|
|
883
|
+
command: "stop",
|
|
884
|
+
senderId: message.entityId,
|
|
885
|
+
commandSource: message.content?.source
|
|
830
886
|
});
|
|
831
|
-
} catch {
|
|
887
|
+
} catch (err) {
|
|
888
|
+
import_core2.logger.warn({ src: "plugin-commands", err }, "Failed to emit HOOK_COMMAND_STOP event");
|
|
889
|
+
}
|
|
832
890
|
const replyText = "✓ Stop requested. Current operations will be cancelled.";
|
|
833
891
|
await callback?.({ text: replyText });
|
|
834
892
|
return {
|
|
@@ -864,28 +922,44 @@ var commandRegistryProvider = {
|
|
|
864
922
|
description: "Available chat commands and their descriptions",
|
|
865
923
|
dynamic: true,
|
|
866
924
|
async get(runtime, message, _state) {
|
|
867
|
-
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
925
|
+
useRuntime(runtime.agentId);
|
|
926
|
+
const text = message.content?.text ?? "";
|
|
927
|
+
const isCommand = hasCommand(text);
|
|
928
|
+
const commands = getEnabledCommands();
|
|
929
|
+
if (isCommand) {
|
|
930
|
+
const commandList = commands.map((cmd) => {
|
|
931
|
+
const auth = cmd.requiresAuth ? " (requires auth)" : "";
|
|
932
|
+
return `- ${cmd.textAliases[0]}: ${cmd.description}${auth}`;
|
|
933
|
+
});
|
|
934
|
+
return {
|
|
935
|
+
text: `The user sent a slash command. Available commands:
|
|
874
936
|
${commandList.join(`
|
|
875
|
-
`)}
|
|
937
|
+
`)}
|
|
938
|
+
|
|
939
|
+
IMPORTANT: This is a slash command — respond by executing the matching command action, not with conversational text.`,
|
|
940
|
+
values: {
|
|
941
|
+
commandCount: commands.length,
|
|
942
|
+
isCommand: true,
|
|
943
|
+
hasElevatedCommands: commands.some((c) => c.requiresElevated)
|
|
944
|
+
},
|
|
945
|
+
data: { commands, isCommand: true }
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
return {
|
|
949
|
+
text: "",
|
|
876
950
|
values: {
|
|
877
|
-
commandCount:
|
|
878
|
-
|
|
951
|
+
commandCount: commands.length,
|
|
952
|
+
isCommand: false
|
|
879
953
|
},
|
|
880
|
-
data: {
|
|
954
|
+
data: { isCommand: false }
|
|
881
955
|
};
|
|
882
956
|
}
|
|
883
957
|
};
|
|
884
958
|
function formatCommandResult(result) {
|
|
885
959
|
if (result.error) {
|
|
886
|
-
return
|
|
960
|
+
return `Error: ${result.error}`;
|
|
887
961
|
}
|
|
888
|
-
return result.reply ?? "
|
|
962
|
+
return result.reply ?? "Command executed";
|
|
889
963
|
}
|
|
890
964
|
function isAuthorized(context, command) {
|
|
891
965
|
if (!command.requiresAuth) {
|
|
@@ -933,7 +1007,7 @@ var commandsPlugin = {
|
|
|
933
1007
|
if (hasCommand("hello world")) {
|
|
934
1008
|
throw new Error("Should not detect plain text as command");
|
|
935
1009
|
}
|
|
936
|
-
|
|
1010
|
+
import_core3.logger.success("Command prefix detection works correctly");
|
|
937
1011
|
}
|
|
938
1012
|
},
|
|
939
1013
|
{
|
|
@@ -949,7 +1023,7 @@ var commandsPlugin = {
|
|
|
949
1023
|
if (detection.command?.args[0] !== "high") {
|
|
950
1024
|
throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
|
|
951
1025
|
}
|
|
952
|
-
|
|
1026
|
+
import_core3.logger.success("Command argument parsing works correctly");
|
|
953
1027
|
}
|
|
954
1028
|
},
|
|
955
1029
|
{
|
|
@@ -963,7 +1037,7 @@ var commandsPlugin = {
|
|
|
963
1037
|
if (normalized2 !== "/help") {
|
|
964
1038
|
throw new Error(`Expected '/help', got '${normalized2}'`);
|
|
965
1039
|
}
|
|
966
|
-
|
|
1040
|
+
import_core3.logger.success("Command normalization works correctly");
|
|
967
1041
|
}
|
|
968
1042
|
},
|
|
969
1043
|
{
|
|
@@ -976,7 +1050,7 @@ var commandsPlugin = {
|
|
|
976
1050
|
if (cmd.key !== "help") {
|
|
977
1051
|
throw new Error(`Expected key 'help', got '${cmd.key}'`);
|
|
978
1052
|
}
|
|
979
|
-
|
|
1053
|
+
import_core3.logger.success("Command alias lookup works correctly");
|
|
980
1054
|
}
|
|
981
1055
|
},
|
|
982
1056
|
{
|
|
@@ -989,7 +1063,7 @@ var commandsPlugin = {
|
|
|
989
1063
|
if (cmd.key !== "status") {
|
|
990
1064
|
throw new Error(`Expected key 'status', got '${cmd.key}'`);
|
|
991
1065
|
}
|
|
992
|
-
|
|
1066
|
+
import_core3.logger.success("Command key lookup works correctly");
|
|
993
1067
|
}
|
|
994
1068
|
}
|
|
995
1069
|
]
|
|
@@ -1000,16 +1074,16 @@ var commandsPlugin = {
|
|
|
1000
1074
|
{
|
|
1001
1075
|
name: "Get enabled commands",
|
|
1002
1076
|
fn: async (_runtime) => {
|
|
1003
|
-
const
|
|
1004
|
-
if (
|
|
1077
|
+
const commands = getEnabledCommands();
|
|
1078
|
+
if (commands.length === 0) {
|
|
1005
1079
|
throw new Error("Should have enabled commands");
|
|
1006
1080
|
}
|
|
1007
|
-
const
|
|
1008
|
-
const
|
|
1009
|
-
if (!
|
|
1081
|
+
const cmdHelp = commands.some((c) => c.key === "help");
|
|
1082
|
+
const cmdStatus = commands.some((c) => c.key === "status");
|
|
1083
|
+
if (!cmdHelp || !cmdStatus) {
|
|
1010
1084
|
throw new Error("Should have help and status commands");
|
|
1011
1085
|
}
|
|
1012
|
-
|
|
1086
|
+
import_core3.logger.success("Command registry works correctly");
|
|
1013
1087
|
}
|
|
1014
1088
|
},
|
|
1015
1089
|
{
|
|
@@ -1031,7 +1105,7 @@ var commandsPlugin = {
|
|
|
1031
1105
|
if (notFound) {
|
|
1032
1106
|
throw new Error("Should not find unregistered command");
|
|
1033
1107
|
}
|
|
1034
|
-
|
|
1108
|
+
import_core3.logger.success("Custom command registration works correctly");
|
|
1035
1109
|
}
|
|
1036
1110
|
},
|
|
1037
1111
|
{
|
|
@@ -1045,17 +1119,19 @@ var commandsPlugin = {
|
|
|
1045
1119
|
if (!allStatus) {
|
|
1046
1120
|
throw new Error("All returned commands should be in status category");
|
|
1047
1121
|
}
|
|
1048
|
-
|
|
1122
|
+
import_core3.logger.success("Command categorization works correctly");
|
|
1049
1123
|
}
|
|
1050
1124
|
}
|
|
1051
1125
|
]
|
|
1052
1126
|
}
|
|
1053
1127
|
],
|
|
1054
1128
|
async init(config, runtime) {
|
|
1055
|
-
|
|
1129
|
+
import_core3.logger.log("[plugin-commands] Initializing command system");
|
|
1130
|
+
initForRuntime(runtime.agentId);
|
|
1056
1131
|
const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
|
|
1057
1132
|
const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
|
|
1058
1133
|
const bashEnabled = config.COMMANDS_BASH_ENABLED === "true";
|
|
1134
|
+
const restartEnabled = config.COMMANDS_RESTART_ENABLED !== "false";
|
|
1059
1135
|
const configCmd = findCommandByKey("config");
|
|
1060
1136
|
if (configCmd) {
|
|
1061
1137
|
configCmd.enabled = configEnabled;
|
|
@@ -1068,10 +1144,14 @@ var commandsPlugin = {
|
|
|
1068
1144
|
if (bashCmd) {
|
|
1069
1145
|
bashCmd.enabled = bashEnabled;
|
|
1070
1146
|
}
|
|
1147
|
+
const restartCmd = findCommandByKey("restart");
|
|
1148
|
+
if (restartCmd) {
|
|
1149
|
+
restartCmd.enabled = restartEnabled;
|
|
1150
|
+
}
|
|
1071
1151
|
const enabledCount = getEnabledCommands().length;
|
|
1072
|
-
|
|
1152
|
+
import_core3.logger.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
|
|
1073
1153
|
}
|
|
1074
1154
|
};
|
|
1075
1155
|
var src_default = commandsPlugin;
|
|
1076
1156
|
|
|
1077
|
-
//# debugId=
|
|
1157
|
+
//# debugId=C959FE7FE395530C64756E2164756E21
|