@elizaos/plugin-commands 2.0.0-alpha.5 → 2.0.0-alpha.7

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.
@@ -417,7 +417,7 @@ function startsWithCommand(text) {
417
417
  if (normalized === alias) {
418
418
  return command;
419
419
  }
420
- if (normalized.startsWith(alias + " ") || normalized.startsWith(alias + ":")) {
420
+ if (normalized.startsWith(`${alias} `) || normalized.startsWith(`${alias}:`)) {
421
421
  return command;
422
422
  }
423
423
  }
@@ -461,7 +461,7 @@ function parseCommand(text, definition) {
461
461
  matchedAlias = alias;
462
462
  break;
463
463
  }
464
- if (trimmed.toLowerCase().startsWith(normalized + " ") || trimmed.toLowerCase().startsWith(normalized + ":")) {
464
+ if (trimmed.toLowerCase().startsWith(`${normalized} `) || trimmed.toLowerCase().startsWith(`${normalized}:`)) {
465
465
  matchedAlias = alias;
466
466
  break;
467
467
  }
@@ -572,12 +572,20 @@ var commandsListAction = {
572
572
  name: "COMMANDS_LIST",
573
573
  description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
574
574
  similes: ["/commands", "/cmds"],
575
- async validate(runtime, message) {
576
- const text = message.content?.text ?? "";
577
- const detection = detectCommand(text);
575
+ validate: async (runtime, message) => {
576
+ const textRaw = message.content?.text ?? "";
577
+ const text = textRaw.toLowerCase();
578
+ const hasKeyword = text.includes("/commands") || text.includes("/cmds") || text.includes("commands");
579
+ const hasRegex = /^(?:\/|!)\s*(?:commands|cmds)\b/i.test(textRaw);
580
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
581
+ const hasInput = textRaw.trim().length > 0;
582
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
583
+ return false;
584
+ }
585
+ const detection = detectCommand(textRaw);
578
586
  return detection.isCommand && detection.command?.key === "commands";
579
587
  },
580
- async handler(runtime, message, state, options, callback) {
588
+ async handler(_runtime, _message, _state, _options, callback) {
581
589
  const commands = getEnabledCommands();
582
590
  const lines = [`**Commands (${commands.length}):**
583
591
  `];
@@ -598,9 +606,9 @@ var commandsListAction = {
598
606
  },
599
607
  examples: [
600
608
  [
601
- { user: "user", content: { text: "/commands" } },
609
+ { name: "user", content: { text: "/commands" } },
602
610
  {
603
- user: "assistant",
611
+ name: "assistant",
604
612
  content: {
605
613
  text: `**Commands (15):**
606
614
 
@@ -651,12 +659,20 @@ var helpAction = {
651
659
  name: "HELP_COMMAND",
652
660
  description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
653
661
  similes: ["/help", "/h", "/?"],
654
- async validate(runtime, message) {
655
- const text = message.content?.text ?? "";
656
- const detection = detectCommand(text);
662
+ validate: async (runtime, message) => {
663
+ const textRaw = message.content?.text ?? "";
664
+ const text = textRaw.toLowerCase();
665
+ const hasKeyword = text.includes("/help") || text.includes("/h") || text.includes("/?");
666
+ const hasRegex = /^(?:\/|!)\s*(?:help|h|\?)(?:\s|$|:)/i.test(textRaw);
667
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
668
+ const hasInput = textRaw.trim().length > 0;
669
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
670
+ return false;
671
+ }
672
+ const detection = detectCommand(textRaw);
657
673
  return detection.isCommand && detection.command?.key === "help";
658
674
  },
659
- async handler(runtime, message, state, options, callback) {
675
+ async handler(_runtime, _message, _state, _options, callback) {
660
676
  const commands = getEnabledCommands();
661
677
  const helpText = formatCommandList(commands);
662
678
  await callback?.({ text: helpText });
@@ -668,9 +684,9 @@ var helpAction = {
668
684
  },
669
685
  examples: [
670
686
  [
671
- { user: "user", content: { text: "/help" } },
687
+ { name: "user", content: { text: "/help" } },
672
688
  {
673
- user: "assistant",
689
+ name: "assistant",
674
690
  content: {
675
691
  text: `**Available Commands:**
676
692
 
@@ -680,9 +696,9 @@ var helpAction = {
680
696
  }
681
697
  ],
682
698
  [
683
- { user: "user", content: { text: "/?" } },
699
+ { name: "user", content: { text: "/?" } },
684
700
  {
685
- user: "assistant",
701
+ name: "assistant",
686
702
  content: {
687
703
  text: `**Available Commands:**
688
704
 
@@ -720,12 +736,20 @@ var modelsAction = {
720
736
  name: "MODELS_COMMAND",
721
737
  description: "List available AI models and providers. Only activates for /models slash command.",
722
738
  similes: ["/models"],
723
- async validate(runtime, message) {
724
- const text = message.content?.text ?? "";
725
- const detection = detectCommand(text);
739
+ validate: async (runtime, message) => {
740
+ const textRaw = message.content?.text ?? "";
741
+ const text = textRaw.toLowerCase();
742
+ const hasKeyword = text.includes("/models") || text.includes("models");
743
+ const hasRegex = /^(?:\/|!)\s*models\b/i.test(textRaw);
744
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
745
+ const hasInput = textRaw.trim().length > 0;
746
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
747
+ return false;
748
+ }
749
+ const detection = detectCommand(textRaw);
726
750
  return detection.isCommand && detection.command?.key === "models";
727
751
  },
728
- async handler(runtime, message, state, options, callback) {
752
+ async handler(runtime, _message, _state, _options, callback) {
729
753
  const lines = [`**Available Models:**
730
754
  `];
731
755
  try {
@@ -777,9 +801,9 @@ _Use /model <provider/model> to switch models._`);
777
801
  },
778
802
  examples: [
779
803
  [
780
- { user: "user", content: { text: "/models" } },
804
+ { name: "user", content: { text: "/models" } },
781
805
  {
782
- user: "assistant",
806
+ name: "assistant",
783
807
  content: {
784
808
  text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
785
809
  }
@@ -826,12 +850,20 @@ var statusAction = {
826
850
  name: "STATUS_COMMAND",
827
851
  description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
828
852
  similes: ["/status", "/s"],
829
- async validate(runtime, message) {
830
- const text = message.content?.text ?? "";
831
- const detection = detectCommand(text);
853
+ validate: async (runtime, message) => {
854
+ const textRaw = message.content?.text ?? "";
855
+ const text = textRaw.toLowerCase();
856
+ const hasKeyword = text.includes("/status") || text.includes("/s") || text.includes("status");
857
+ const hasRegex = /^(?:\/|!)\s*(?:status|s)\b/i.test(textRaw);
858
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
859
+ const hasInput = textRaw.trim().length > 0;
860
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
861
+ return false;
862
+ }
863
+ const detection = detectCommand(textRaw);
832
864
  return detection.isCommand && detection.command?.key === "status";
833
865
  },
834
- async handler(runtime, message, state, options, callback) {
866
+ async handler(runtime, message, _state, _options, callback) {
835
867
  const statusText = await buildStatusReport(runtime, message.roomId);
836
868
  await callback?.({ text: statusText });
837
869
  return {
@@ -841,9 +873,9 @@ var statusAction = {
841
873
  },
842
874
  examples: [
843
875
  [
844
- { user: "user", content: { text: "/status" } },
876
+ { name: "user", content: { text: "/status" } },
845
877
  {
846
- user: "assistant",
878
+ name: "assistant",
847
879
  content: {
848
880
  text: `**Session Status:**
849
881
 
@@ -864,12 +896,20 @@ var stopAction = {
864
896
  name: "STOP_COMMAND",
865
897
  description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
866
898
  similes: ["/stop", "/abort", "/cancel"],
867
- async validate(runtime, message) {
868
- const text = message.content?.text ?? "";
869
- const detection = detectCommand(text);
899
+ validate: async (runtime, message) => {
900
+ const textRaw = message.content?.text ?? "";
901
+ const text = textRaw.toLowerCase();
902
+ const hasKeyword = text.includes("/stop") || text.includes("/abort") || text.includes("/cancel") || text.includes("stop");
903
+ const hasRegex = /^(?:\/|!)\s*(?:stop|abort|cancel)\b/i.test(textRaw);
904
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
905
+ const hasInput = textRaw.trim().length > 0;
906
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
907
+ return false;
908
+ }
909
+ const detection = detectCommand(textRaw);
870
910
  return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
871
911
  },
872
- async handler(runtime, message, state, options, callback) {
912
+ async handler(runtime, message, _state, _options, callback) {
873
913
  try {
874
914
  await runtime.emitEvent(import_core2.EventType.HOOK_COMMAND_STOP, {
875
915
  runtime,
@@ -896,18 +936,18 @@ var stopAction = {
896
936
  },
897
937
  examples: [
898
938
  [
899
- { user: "user", content: { text: "/stop" } },
939
+ { name: "user", content: { text: "/stop" } },
900
940
  {
901
- user: "assistant",
941
+ name: "assistant",
902
942
  content: {
903
943
  text: "✓ Stop requested. Current operations will be cancelled."
904
944
  }
905
945
  }
906
946
  ],
907
947
  [
908
- { user: "user", content: { text: "/abort" } },
948
+ { name: "user", content: { text: "/abort" } },
909
949
  {
910
- user: "assistant",
950
+ name: "assistant",
911
951
  content: {
912
952
  text: "✓ Stop requested. Current operations will be cancelled."
913
953
  }
@@ -1154,4 +1194,4 @@ var commandsPlugin = {
1154
1194
  };
1155
1195
  var src_default = commandsPlugin;
1156
1196
 
1157
- //# debugId=C959FE7FE395530C64756E2164756E21
1197
+ //# debugId=82FB2D1F707579D364756E2164756E21