@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.
package/dist/index.js CHANGED
@@ -363,7 +363,7 @@ function startsWithCommand(text) {
363
363
  if (normalized === alias) {
364
364
  return command;
365
365
  }
366
- if (normalized.startsWith(alias + " ") || normalized.startsWith(alias + ":")) {
366
+ if (normalized.startsWith(`${alias} `) || normalized.startsWith(`${alias}:`)) {
367
367
  return command;
368
368
  }
369
369
  }
@@ -407,7 +407,7 @@ function parseCommand(text, definition) {
407
407
  matchedAlias = alias;
408
408
  break;
409
409
  }
410
- if (trimmed.toLowerCase().startsWith(normalized + " ") || trimmed.toLowerCase().startsWith(normalized + ":")) {
410
+ if (trimmed.toLowerCase().startsWith(`${normalized} `) || trimmed.toLowerCase().startsWith(`${normalized}:`)) {
411
411
  matchedAlias = alias;
412
412
  break;
413
413
  }
@@ -518,12 +518,20 @@ var commandsListAction = {
518
518
  name: "COMMANDS_LIST",
519
519
  description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
520
520
  similes: ["/commands", "/cmds"],
521
- async validate(runtime, message) {
522
- const text = message.content?.text ?? "";
523
- const detection = detectCommand(text);
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);
524
532
  return detection.isCommand && detection.command?.key === "commands";
525
533
  },
526
- async handler(runtime, message, state, options, callback) {
534
+ async handler(_runtime, _message, _state, _options, callback) {
527
535
  const commands = getEnabledCommands();
528
536
  const lines = [`**Commands (${commands.length}):**
529
537
  `];
@@ -544,9 +552,9 @@ var commandsListAction = {
544
552
  },
545
553
  examples: [
546
554
  [
547
- { user: "user", content: { text: "/commands" } },
555
+ { name: "user", content: { text: "/commands" } },
548
556
  {
549
- user: "assistant",
557
+ name: "assistant",
550
558
  content: {
551
559
  text: `**Commands (15):**
552
560
 
@@ -597,12 +605,20 @@ var helpAction = {
597
605
  name: "HELP_COMMAND",
598
606
  description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
599
607
  similes: ["/help", "/h", "/?"],
600
- async validate(runtime, message) {
601
- const text = message.content?.text ?? "";
602
- const detection = detectCommand(text);
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);
603
619
  return detection.isCommand && detection.command?.key === "help";
604
620
  },
605
- async handler(runtime, message, state, options, callback) {
621
+ async handler(_runtime, _message, _state, _options, callback) {
606
622
  const commands = getEnabledCommands();
607
623
  const helpText = formatCommandList(commands);
608
624
  await callback?.({ text: helpText });
@@ -614,9 +630,9 @@ var helpAction = {
614
630
  },
615
631
  examples: [
616
632
  [
617
- { user: "user", content: { text: "/help" } },
633
+ { name: "user", content: { text: "/help" } },
618
634
  {
619
- user: "assistant",
635
+ name: "assistant",
620
636
  content: {
621
637
  text: `**Available Commands:**
622
638
 
@@ -626,9 +642,9 @@ var helpAction = {
626
642
  }
627
643
  ],
628
644
  [
629
- { user: "user", content: { text: "/?" } },
645
+ { name: "user", content: { text: "/?" } },
630
646
  {
631
- user: "assistant",
647
+ name: "assistant",
632
648
  content: {
633
649
  text: `**Available Commands:**
634
650
 
@@ -641,7 +657,7 @@ var helpAction = {
641
657
  };
642
658
 
643
659
  // src/actions/models.ts
644
- import { ModelType, logger } from "@elizaos/core";
660
+ import { logger, ModelType } from "@elizaos/core";
645
661
  function describeModelType(modelType) {
646
662
  const descriptions = {
647
663
  [ModelType.TEXT_SMALL]: "Text (Small)",
@@ -666,12 +682,20 @@ var modelsAction = {
666
682
  name: "MODELS_COMMAND",
667
683
  description: "List available AI models and providers. Only activates for /models slash command.",
668
684
  similes: ["/models"],
669
- async validate(runtime, message) {
670
- const text = message.content?.text ?? "";
671
- const detection = detectCommand(text);
685
+ validate: async (runtime, message) => {
686
+ const textRaw = message.content?.text ?? "";
687
+ const text = textRaw.toLowerCase();
688
+ const hasKeyword = text.includes("/models") || text.includes("models");
689
+ const hasRegex = /^(?:\/|!)\s*models\b/i.test(textRaw);
690
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
691
+ const hasInput = textRaw.trim().length > 0;
692
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
693
+ return false;
694
+ }
695
+ const detection = detectCommand(textRaw);
672
696
  return detection.isCommand && detection.command?.key === "models";
673
697
  },
674
- async handler(runtime, message, state, options, callback) {
698
+ async handler(runtime, _message, _state, _options, callback) {
675
699
  const lines = [`**Available Models:**
676
700
  `];
677
701
  try {
@@ -723,9 +747,9 @@ _Use /model <provider/model> to switch models._`);
723
747
  },
724
748
  examples: [
725
749
  [
726
- { user: "user", content: { text: "/models" } },
750
+ { name: "user", content: { text: "/models" } },
727
751
  {
728
- user: "assistant",
752
+ name: "assistant",
729
753
  content: {
730
754
  text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
731
755
  }
@@ -772,12 +796,20 @@ var statusAction = {
772
796
  name: "STATUS_COMMAND",
773
797
  description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
774
798
  similes: ["/status", "/s"],
775
- async validate(runtime, message) {
776
- const text = message.content?.text ?? "";
777
- const detection = detectCommand(text);
799
+ validate: async (runtime, message) => {
800
+ const textRaw = message.content?.text ?? "";
801
+ const text = textRaw.toLowerCase();
802
+ const hasKeyword = text.includes("/status") || text.includes("/s") || text.includes("status");
803
+ const hasRegex = /^(?:\/|!)\s*(?:status|s)\b/i.test(textRaw);
804
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
805
+ const hasInput = textRaw.trim().length > 0;
806
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
807
+ return false;
808
+ }
809
+ const detection = detectCommand(textRaw);
778
810
  return detection.isCommand && detection.command?.key === "status";
779
811
  },
780
- async handler(runtime, message, state, options, callback) {
812
+ async handler(runtime, message, _state, _options, callback) {
781
813
  const statusText = await buildStatusReport(runtime, message.roomId);
782
814
  await callback?.({ text: statusText });
783
815
  return {
@@ -787,9 +819,9 @@ var statusAction = {
787
819
  },
788
820
  examples: [
789
821
  [
790
- { user: "user", content: { text: "/status" } },
822
+ { name: "user", content: { text: "/status" } },
791
823
  {
792
- user: "assistant",
824
+ name: "assistant",
793
825
  content: {
794
826
  text: `**Session Status:**
795
827
 
@@ -810,12 +842,20 @@ var stopAction = {
810
842
  name: "STOP_COMMAND",
811
843
  description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
812
844
  similes: ["/stop", "/abort", "/cancel"],
813
- async validate(runtime, message) {
814
- const text = message.content?.text ?? "";
815
- const detection = detectCommand(text);
845
+ validate: async (runtime, message) => {
846
+ const textRaw = message.content?.text ?? "";
847
+ const text = textRaw.toLowerCase();
848
+ const hasKeyword = text.includes("/stop") || text.includes("/abort") || text.includes("/cancel") || text.includes("stop");
849
+ const hasRegex = /^(?:\/|!)\s*(?:stop|abort|cancel)\b/i.test(textRaw);
850
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
851
+ const hasInput = textRaw.trim().length > 0;
852
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
853
+ return false;
854
+ }
855
+ const detection = detectCommand(textRaw);
816
856
  return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
817
857
  },
818
- async handler(runtime, message, state, options, callback) {
858
+ async handler(runtime, message, _state, _options, callback) {
819
859
  try {
820
860
  await runtime.emitEvent(EventType.HOOK_COMMAND_STOP, {
821
861
  runtime,
@@ -842,18 +882,18 @@ var stopAction = {
842
882
  },
843
883
  examples: [
844
884
  [
845
- { user: "user", content: { text: "/stop" } },
885
+ { name: "user", content: { text: "/stop" } },
846
886
  {
847
- user: "assistant",
887
+ name: "assistant",
848
888
  content: {
849
889
  text: "✓ Stop requested. Current operations will be cancelled."
850
890
  }
851
891
  }
852
892
  ],
853
893
  [
854
- { user: "user", content: { text: "/abort" } },
894
+ { name: "user", content: { text: "/abort" } },
855
895
  {
856
- user: "assistant",
896
+ name: "assistant",
857
897
  content: {
858
898
  text: "✓ Stop requested. Current operations will be cancelled."
859
899
  }
@@ -1126,4 +1166,4 @@ export {
1126
1166
  commandRegistryProvider
1127
1167
  };
1128
1168
 
1129
- //# debugId=C6086C11EDA7A75E64756E2164756E21
1169
+ //# debugId=B67A62E4C9BE0E2864756E2164756E21