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

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  import {
3
- logger as logger3
3
+ logger
4
4
  } from "@elizaos/core";
5
5
 
6
6
  // src/registry.ts
@@ -513,407 +513,16 @@ function extractCommand(text) {
513
513
  return { command, remainingText: command.rawArgs };
514
514
  }
515
515
 
516
- // src/actions/commands-list.ts
517
- var commandsListAction = {
518
- name: "COMMANDS_LIST",
519
- description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
520
- similes: ["/commands", "/cmds"],
521
- validate: async (runtime, message) => {
522
- const textRaw = message.content?.text ?? "";
523
- const text = textRaw.toLowerCase();
524
- const hasKeyword = text.includes("/commands") || text.includes("/cmds") || text.includes("commands");
525
- const hasRegex = /^(?:\/|!)\s*(?:commands|cmds)\b/i.test(textRaw);
526
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
527
- const hasInput = textRaw.trim().length > 0;
528
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
529
- return false;
530
- }
531
- const detection = detectCommand(textRaw);
532
- return detection.isCommand && detection.command?.key === "commands";
533
- },
534
- async handler(_runtime, _message, _state, _options, callback) {
535
- const commands = getEnabledCommands();
536
- const lines = [`**Commands (${commands.length}):**
537
- `];
538
- for (const cmd of commands) {
539
- const aliases = cmd.textAliases.join(", ");
540
- const authNote = cmd.requiresAuth ? " [auth]" : "";
541
- const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
542
- lines.push(`• **${cmd.key}**: ${aliases}${authNote}${elevatedNote}`);
543
- }
544
- const replyText = lines.join(`
545
- `);
546
- await callback?.({ text: replyText });
547
- return {
548
- success: true,
549
- text: replyText,
550
- data: { commandCount: commands.length }
551
- };
552
- },
553
- examples: [
554
- [
555
- { name: "user", content: { text: "/commands" } },
556
- {
557
- name: "assistant",
558
- content: {
559
- text: `**Commands (15):**
560
-
561
- • **help**: /help, /h, /?
562
- • **status**: /status, /s...`
563
- }
564
- }
565
- ]
566
- ]
567
- };
568
-
569
- // src/actions/help.ts
570
- function formatCommandList(commands) {
571
- const lines = [`**Available Commands:**
572
- `];
573
- const categories = [
574
- { key: "status", name: "Status" },
575
- { key: "session", name: "Session" },
576
- { key: "options", name: "Options" },
577
- { key: "management", name: "Management" },
578
- { key: "media", name: "Media" },
579
- { key: "tools", name: "Tools" }
580
- ];
581
- for (const cat of categories) {
582
- const catCommands = commands.filter((c) => c.category === cat.key);
583
- if (catCommands.length === 0)
584
- continue;
585
- lines.push(`
586
- **${cat.name}:**`);
587
- for (const cmd of catCommands) {
588
- const aliases = cmd.textAliases.slice(0, 2).join(", ");
589
- lines.push(`• ${aliases} - ${cmd.description}`);
590
- }
591
- }
592
- const uncategorized = commands.filter((c) => !c.category);
593
- if (uncategorized.length > 0) {
594
- lines.push(`
595
- **Other:**`);
596
- for (const cmd of uncategorized) {
597
- const aliases = cmd.textAliases.slice(0, 2).join(", ");
598
- lines.push(`• ${aliases} - ${cmd.description}`);
599
- }
600
- }
601
- return lines.join(`
602
- `);
603
- }
604
- var helpAction = {
605
- name: "HELP_COMMAND",
606
- description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
607
- similes: ["/help", "/h", "/?"],
608
- validate: async (runtime, message) => {
609
- const textRaw = message.content?.text ?? "";
610
- const text = textRaw.toLowerCase();
611
- const hasKeyword = text.includes("/help") || text.includes("/h") || text.includes("/?");
612
- const hasRegex = /^(?:\/|!)\s*(?:help|h|\?)(?:\s|$|:)/i.test(textRaw);
613
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
614
- const hasInput = textRaw.trim().length > 0;
615
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
616
- return false;
617
- }
618
- const detection = detectCommand(textRaw);
619
- return detection.isCommand && detection.command?.key === "help";
620
- },
621
- async handler(_runtime, message, _state, _options, callback) {
622
- const detection = detectCommand(message?.content?.text ?? "");
623
- if (!detection.isCommand || detection.command?.key !== "help") {
624
- return { success: false, text: "" };
625
- }
626
- const commands = getEnabledCommands();
627
- const helpText = formatCommandList(commands);
628
- await callback?.({ text: helpText });
629
- return {
630
- success: true,
631
- text: helpText,
632
- data: { commandCount: commands.length }
633
- };
634
- },
635
- examples: [
636
- [
637
- { name: "user", content: { text: "/help" } },
638
- {
639
- name: "assistant",
640
- content: {
641
- text: `**Available Commands:**
642
-
643
- **Status:**
644
- • /help - Show available commands...`
645
- }
646
- }
647
- ],
648
- [
649
- { name: "user", content: { text: "/?" } },
650
- {
651
- name: "assistant",
652
- content: {
653
- text: `**Available Commands:**
654
-
655
- **Status:**
656
- • /help - Show available commands...`
657
- }
658
- }
659
- ]
660
- ]
661
- };
662
-
663
- // src/actions/models.ts
664
- import { logger, ModelType } from "@elizaos/core";
665
- function describeModelType(modelType) {
666
- const descriptions = {
667
- [ModelType.TEXT_SMALL]: "Text (Small)",
668
- [ModelType.TEXT_LARGE]: "Text (Large)",
669
- [ModelType.TEXT_REASONING_SMALL]: "Reasoning (Small)",
670
- [ModelType.TEXT_REASONING_LARGE]: "Reasoning (Large)",
671
- [ModelType.TEXT_COMPLETION]: "Text Completion",
672
- [ModelType.TEXT_EMBEDDING]: "Embedding",
673
- [ModelType.IMAGE]: "Image Generation",
674
- [ModelType.IMAGE_DESCRIPTION]: "Image Description",
675
- [ModelType.TRANSCRIPTION]: "Transcription",
676
- [ModelType.TEXT_TO_SPEECH]: "Text-to-Speech",
677
- [ModelType.AUDIO]: "Audio",
678
- [ModelType.VIDEO]: "Video",
679
- [ModelType.OBJECT_SMALL]: "Object (Small)",
680
- [ModelType.OBJECT_LARGE]: "Object (Large)",
681
- [ModelType.RESEARCH]: "Research"
682
- };
683
- return descriptions[modelType] ?? modelType;
684
- }
685
- var modelsAction = {
686
- name: "MODELS_COMMAND",
687
- description: "List available AI models and providers. Only activates for /models slash command.",
688
- similes: ["/models"],
689
- validate: async (runtime, message) => {
690
- const textRaw = message.content?.text ?? "";
691
- const text = textRaw.toLowerCase();
692
- const hasKeyword = text.includes("/models") || text.includes("models");
693
- const hasRegex = /^(?:\/|!)\s*models\b/i.test(textRaw);
694
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
695
- const hasInput = textRaw.trim().length > 0;
696
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
697
- return false;
698
- }
699
- const detection = detectCommand(textRaw);
700
- return detection.isCommand && detection.command?.key === "models";
701
- },
702
- async handler(runtime, _message, _state, _options, callback) {
703
- const lines = [`**Available Models:**
704
- `];
705
- try {
706
- const registeredTypes = [];
707
- const seen = new Set;
708
- for (const modelType of Object.values(ModelType)) {
709
- if (seen.has(modelType))
710
- continue;
711
- seen.add(modelType);
712
- try {
713
- const handler = runtime.getModel(modelType);
714
- if (handler) {
715
- registeredTypes.push(modelType);
716
- }
717
- } catch {}
718
- }
719
- if (registeredTypes.length > 0) {
720
- lines.push("**Registered Model Types:**");
721
- for (const modelType of registeredTypes) {
722
- lines.push(`• ${describeModelType(modelType)} (\`${modelType}\`)`);
723
- }
724
- } else {
725
- lines.push("No model handlers are currently registered.");
726
- }
727
- const modelProvider = runtime.getSetting("MODEL_PROVIDER");
728
- const modelName = runtime.getSetting("MODEL_NAME");
729
- if (modelProvider || modelName) {
730
- lines.push(`
731
- **Current Configuration:**`);
732
- if (modelProvider)
733
- lines.push(`• Provider: ${modelProvider}`);
734
- if (modelName)
735
- lines.push(`• Model: ${modelName}`);
736
- }
737
- } catch (err) {
738
- logger.warn({ src: "plugin-commands", err }, "Error querying runtime models");
739
- lines.push("Unable to query available models.");
740
- }
741
- lines.push(`
742
-
743
- _Use /model <provider/model> to switch models._`);
744
- const replyText = lines.join(`
745
- `);
746
- await callback?.({ text: replyText });
747
- return {
748
- success: true,
749
- text: replyText
750
- };
751
- },
752
- examples: [
753
- [
754
- { name: "user", content: { text: "/models" } },
755
- {
756
- name: "assistant",
757
- content: {
758
- text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
759
- }
760
- }
761
- ]
762
- ]
763
- };
764
-
765
- // src/actions/status.ts
766
- async function buildStatusReport(runtime, roomId) {
767
- const lines = [`**Session Status:**
768
- `];
769
- lines.push(`**Agent:** ${runtime.character.name ?? runtime.agentId}`);
770
- lines.push(`**Room:** ${roomId}`);
771
- try {
772
- const directiveService = runtime.getService("directive-parser");
773
- if (directiveService) {
774
- const state = directiveService.getSessionState?.(roomId);
775
- if (state) {
776
- lines.push(`
777
- **Directives:**`);
778
- lines.push(`• Thinking: ${state.thinking}`);
779
- lines.push(`• Verbose: ${state.verbose}`);
780
- lines.push(`• Reasoning: ${state.reasoning}`);
781
- lines.push(`• Elevated: ${state.elevated}`);
782
- if (state.model?.provider || state.model?.model) {
783
- const modelStr = state.model.provider ? `${state.model.provider}/${state.model.model}` : state.model.model;
784
- lines.push(`• Model: ${modelStr}`);
785
- }
786
- }
787
- }
788
- } catch {}
789
- try {
790
- const tasks = await runtime.getTasks({
791
- roomId,
792
- agentIds: [runtime.agentId]
793
- });
794
- if (tasks.length > 0) {
795
- lines.push(`
796
- **Tasks:** ${tasks.length} pending`);
797
- }
798
- } catch {}
799
- return lines.join(`
800
- `);
801
- }
802
- var statusAction = {
803
- name: "STATUS_COMMAND",
804
- description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
805
- similes: ["/status", "/s"],
806
- validate: async (runtime, message) => {
807
- const textRaw = message.content?.text ?? "";
808
- const text = textRaw.toLowerCase();
809
- const hasKeyword = text.includes("/status") || text.includes("/s") || text.includes("status");
810
- const hasRegex = /^(?:\/|!)\s*(?:status|s)\b/i.test(textRaw);
811
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
812
- const hasInput = textRaw.trim().length > 0;
813
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
814
- return false;
815
- }
816
- const detection = detectCommand(textRaw);
817
- return detection.isCommand && detection.command?.key === "status";
818
- },
819
- async handler(runtime, message, _state, _options, callback) {
820
- const statusText = await buildStatusReport(runtime, message.roomId);
821
- await callback?.({ text: statusText });
822
- return {
823
- success: true,
824
- text: statusText
825
- };
826
- },
827
- examples: [
828
- [
829
- { name: "user", content: { text: "/status" } },
830
- {
831
- name: "assistant",
832
- content: {
833
- text: `**Session Status:**
834
-
835
- **Agent:** Eliza
836
- **Room:** room-456
837
-
838
- **Directives:**
839
- • Thinking: low...`
840
- }
841
- }
842
- ]
843
- ]
844
- };
845
-
846
- // src/actions/stop.ts
847
- import { EventType, logger as logger2 } from "@elizaos/core";
848
- var stopAction = {
849
- name: "STOP_COMMAND",
850
- description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
851
- similes: ["/stop", "/abort", "/cancel"],
852
- validate: async (runtime, message) => {
853
- const textRaw = message.content?.text ?? "";
854
- const text = textRaw.toLowerCase();
855
- const hasKeyword = text.includes("/stop") || text.includes("/abort") || text.includes("/cancel") || text.includes("stop");
856
- const hasRegex = /^(?:\/|!)\s*(?:stop|abort|cancel)\b/i.test(textRaw);
857
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
858
- const hasInput = textRaw.trim().length > 0;
859
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
860
- return false;
861
- }
862
- const detection = detectCommand(textRaw);
863
- return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
864
- },
865
- async handler(runtime, message, _state, _options, callback) {
866
- try {
867
- await runtime.emitEvent(EventType.HOOK_COMMAND_STOP, {
868
- runtime,
869
- sessionKey: message.roomId,
870
- messages: [],
871
- timestamp: new Date,
872
- context: {
873
- entityId: message.entityId,
874
- source: message.content?.source
875
- },
876
- command: "stop",
877
- senderId: message.entityId,
878
- commandSource: message.content?.source
879
- });
880
- } catch (err) {
881
- logger2.warn({ src: "plugin-commands", err }, "Failed to emit HOOK_COMMAND_STOP event");
882
- }
883
- const replyText = "✓ Stop requested. Current operations will be cancelled.";
884
- await callback?.({ text: replyText });
885
- return {
886
- success: true,
887
- text: replyText
888
- };
889
- },
890
- examples: [
891
- [
892
- { name: "user", content: { text: "/stop" } },
893
- {
894
- name: "assistant",
895
- content: {
896
- text: "✓ Stop requested. Current operations will be cancelled."
897
- }
898
- }
899
- ],
900
- [
901
- { name: "user", content: { text: "/abort" } },
902
- {
903
- name: "assistant",
904
- content: {
905
- text: "✓ Stop requested. Current operations will be cancelled."
906
- }
907
- }
908
- ]
909
- ]
910
- };
911
-
912
516
  // src/index.ts
913
517
  var commandRegistryProvider = {
914
518
  name: "COMMAND_REGISTRY",
915
519
  description: "Available chat commands and their descriptions",
520
+ descriptionCompressed: "Available chat commands and descriptions.",
916
521
  dynamic: true,
522
+ contexts: ["general", "automation"],
523
+ contextGate: { anyOf: ["general", "automation"] },
524
+ cacheStable: true,
525
+ cacheScope: "agent",
917
526
  async get(runtime, message, _state) {
918
527
  useRuntime(runtime.agentId);
919
528
  const text = message.content?.text ?? "";
@@ -970,13 +579,12 @@ var commandsPlugin = {
970
579
  name: "commands",
971
580
  description: "Chat command system with /help, /status, /reset, etc.",
972
581
  providers: [commandRegistryProvider],
973
- actions: [
974
- helpAction,
975
- statusAction,
976
- stopAction,
977
- modelsAction,
978
- commandsListAction
979
- ],
582
+ autoEnable: {
583
+ shouldEnable: (_env, config) => {
584
+ const f = config?.features?.commands;
585
+ return f === true || typeof f === "object" && f !== null && f.enabled !== false;
586
+ }
587
+ },
980
588
  config: {
981
589
  COMMANDS_ENABLED: "true",
982
590
  COMMANDS_CONFIG_ENABLED: "false",
@@ -1000,7 +608,7 @@ var commandsPlugin = {
1000
608
  if (hasCommand("hello world")) {
1001
609
  throw new Error("Should not detect plain text as command");
1002
610
  }
1003
- logger3.success("Command prefix detection works correctly");
611
+ logger.success("Command prefix detection works correctly");
1004
612
  }
1005
613
  },
1006
614
  {
@@ -1016,7 +624,7 @@ var commandsPlugin = {
1016
624
  if (detection.command?.args[0] !== "high") {
1017
625
  throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
1018
626
  }
1019
- logger3.success("Command argument parsing works correctly");
627
+ logger.success("Command argument parsing works correctly");
1020
628
  }
1021
629
  },
1022
630
  {
@@ -1030,7 +638,7 @@ var commandsPlugin = {
1030
638
  if (normalized2 !== "/help") {
1031
639
  throw new Error(`Expected '/help', got '${normalized2}'`);
1032
640
  }
1033
- logger3.success("Command normalization works correctly");
641
+ logger.success("Command normalization works correctly");
1034
642
  }
1035
643
  },
1036
644
  {
@@ -1043,7 +651,7 @@ var commandsPlugin = {
1043
651
  if (cmd.key !== "help") {
1044
652
  throw new Error(`Expected key 'help', got '${cmd.key}'`);
1045
653
  }
1046
- logger3.success("Command alias lookup works correctly");
654
+ logger.success("Command alias lookup works correctly");
1047
655
  }
1048
656
  },
1049
657
  {
@@ -1056,7 +664,7 @@ var commandsPlugin = {
1056
664
  if (cmd.key !== "status") {
1057
665
  throw new Error(`Expected key 'status', got '${cmd.key}'`);
1058
666
  }
1059
- logger3.success("Command key lookup works correctly");
667
+ logger.success("Command key lookup works correctly");
1060
668
  }
1061
669
  }
1062
670
  ]
@@ -1076,7 +684,7 @@ var commandsPlugin = {
1076
684
  if (!cmdHelp || !cmdStatus) {
1077
685
  throw new Error("Should have help and status commands");
1078
686
  }
1079
- logger3.success("Command registry works correctly");
687
+ logger.success("Command registry works correctly");
1080
688
  }
1081
689
  },
1082
690
  {
@@ -1098,7 +706,7 @@ var commandsPlugin = {
1098
706
  if (notFound) {
1099
707
  throw new Error("Should not find unregistered command");
1100
708
  }
1101
- logger3.success("Custom command registration works correctly");
709
+ logger.success("Custom command registration works correctly");
1102
710
  }
1103
711
  },
1104
712
  {
@@ -1112,14 +720,14 @@ var commandsPlugin = {
1112
720
  if (!allStatus) {
1113
721
  throw new Error("All returned commands should be in status category");
1114
722
  }
1115
- logger3.success("Command categorization works correctly");
723
+ logger.success("Command categorization works correctly");
1116
724
  }
1117
725
  }
1118
726
  ]
1119
727
  }
1120
728
  ],
1121
729
  async init(config, runtime) {
1122
- logger3.log("[plugin-commands] Initializing command system");
730
+ logger.log("[plugin-commands] Initializing command system");
1123
731
  initForRuntime(runtime.agentId);
1124
732
  const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
1125
733
  const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
@@ -1142,7 +750,7 @@ var commandsPlugin = {
1142
750
  restartCmd.enabled = restartEnabled;
1143
751
  }
1144
752
  const enabledCount = getEnabledCommands().length;
1145
- logger3.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
753
+ logger.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
1146
754
  }
1147
755
  };
1148
756
  var src_default = commandsPlugin;
@@ -1173,4 +781,4 @@ export {
1173
781
  commandRegistryProvider
1174
782
  };
1175
783
 
1176
- //# debugId=24A386E734B88BB864756E2164756E21
784
+ //# debugId=BAB16333EBF522DA64756E2164756E21