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

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
  }
@@ -517,13 +517,22 @@ function extractCommand(text) {
517
517
  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
+ descriptionCompressed: "List available commands. Trigger: /commands, /cmds.",
520
521
  similes: ["/commands", "/cmds"],
521
- async validate(runtime, message) {
522
- const text = message.content?.text ?? "";
523
- const detection = detectCommand(text);
522
+ validate: async (runtime, message) => {
523
+ const textRaw = message.content?.text ?? "";
524
+ const text = textRaw.toLowerCase();
525
+ const hasKeyword = text.includes("/commands") || text.includes("/cmds") || text.includes("commands");
526
+ const hasRegex = /^(?:\/|!)\s*(?:commands|cmds)\b/i.test(textRaw);
527
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
528
+ const hasInput = textRaw.trim().length > 0;
529
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
530
+ return false;
531
+ }
532
+ const detection = detectCommand(textRaw);
524
533
  return detection.isCommand && detection.command?.key === "commands";
525
534
  },
526
- async handler(runtime, message, state, options, callback) {
535
+ async handler(_runtime, _message, _state, _options, callback) {
527
536
  const commands = getEnabledCommands();
528
537
  const lines = [`**Commands (${commands.length}):**
529
538
  `];
@@ -544,9 +553,9 @@ var commandsListAction = {
544
553
  },
545
554
  examples: [
546
555
  [
547
- { user: "user", content: { text: "/commands" } },
556
+ { name: "user", content: { text: "/commands" } },
548
557
  {
549
- user: "assistant",
558
+ name: "assistant",
550
559
  content: {
551
560
  text: `**Commands (15):**
552
561
 
@@ -596,13 +605,26 @@ function formatCommandList(commands) {
596
605
  var helpAction = {
597
606
  name: "HELP_COMMAND",
598
607
  description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
608
+ descriptionCompressed: "Show commands and descriptions. Trigger: /help, /h, /?.",
599
609
  similes: ["/help", "/h", "/?"],
600
- async validate(runtime, message) {
601
- const text = message.content?.text ?? "";
602
- const detection = detectCommand(text);
610
+ validate: async (runtime, message) => {
611
+ const textRaw = message.content?.text ?? "";
612
+ const text = textRaw.toLowerCase();
613
+ const hasKeyword = text.includes("/help") || text.includes("/h") || text.includes("/?");
614
+ const hasRegex = /^(?:\/|!)\s*(?:help|h|\?)(?:\s|$|:)/i.test(textRaw);
615
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
616
+ const hasInput = textRaw.trim().length > 0;
617
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
618
+ return false;
619
+ }
620
+ const detection = detectCommand(textRaw);
603
621
  return detection.isCommand && detection.command?.key === "help";
604
622
  },
605
- async handler(runtime, message, state, options, callback) {
623
+ async handler(_runtime, message, _state, _options, callback) {
624
+ const detection = detectCommand(message?.content?.text ?? "");
625
+ if (!detection.isCommand || detection.command?.key !== "help") {
626
+ return { success: false, text: "" };
627
+ }
606
628
  const commands = getEnabledCommands();
607
629
  const helpText = formatCommandList(commands);
608
630
  await callback?.({ text: helpText });
@@ -614,9 +636,9 @@ var helpAction = {
614
636
  },
615
637
  examples: [
616
638
  [
617
- { user: "user", content: { text: "/help" } },
639
+ { name: "user", content: { text: "/help" } },
618
640
  {
619
- user: "assistant",
641
+ name: "assistant",
620
642
  content: {
621
643
  text: `**Available Commands:**
622
644
 
@@ -626,9 +648,9 @@ var helpAction = {
626
648
  }
627
649
  ],
628
650
  [
629
- { user: "user", content: { text: "/?" } },
651
+ { name: "user", content: { text: "/?" } },
630
652
  {
631
- user: "assistant",
653
+ name: "assistant",
632
654
  content: {
633
655
  text: `**Available Commands:**
634
656
 
@@ -641,13 +663,11 @@ var helpAction = {
641
663
  };
642
664
 
643
665
  // src/actions/models.ts
644
- import { ModelType, logger } from "@elizaos/core";
666
+ import { logger, ModelType } from "@elizaos/core";
645
667
  function describeModelType(modelType) {
646
668
  const descriptions = {
647
669
  [ModelType.TEXT_SMALL]: "Text (Small)",
648
670
  [ModelType.TEXT_LARGE]: "Text (Large)",
649
- [ModelType.TEXT_REASONING_SMALL]: "Reasoning (Small)",
650
- [ModelType.TEXT_REASONING_LARGE]: "Reasoning (Large)",
651
671
  [ModelType.TEXT_COMPLETION]: "Text Completion",
652
672
  [ModelType.TEXT_EMBEDDING]: "Embedding",
653
673
  [ModelType.IMAGE]: "Image Generation",
@@ -665,13 +685,22 @@ function describeModelType(modelType) {
665
685
  var modelsAction = {
666
686
  name: "MODELS_COMMAND",
667
687
  description: "List available AI models and providers. Only activates for /models slash command.",
688
+ descriptionCompressed: "List AI models/providers. Trigger: /models.",
668
689
  similes: ["/models"],
669
- async validate(runtime, message) {
670
- const text = message.content?.text ?? "";
671
- const detection = detectCommand(text);
690
+ validate: async (runtime, message) => {
691
+ const textRaw = message.content?.text ?? "";
692
+ const text = textRaw.toLowerCase();
693
+ const hasKeyword = text.includes("/models") || text.includes("models");
694
+ const hasRegex = /^(?:\/|!)\s*models\b/i.test(textRaw);
695
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
696
+ const hasInput = textRaw.trim().length > 0;
697
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
698
+ return false;
699
+ }
700
+ const detection = detectCommand(textRaw);
672
701
  return detection.isCommand && detection.command?.key === "models";
673
702
  },
674
- async handler(runtime, message, state, options, callback) {
703
+ async handler(runtime, _message, _state, _options, callback) {
675
704
  const lines = [`**Available Models:**
676
705
  `];
677
706
  try {
@@ -723,9 +752,9 @@ _Use /model <provider/model> to switch models._`);
723
752
  },
724
753
  examples: [
725
754
  [
726
- { user: "user", content: { text: "/models" } },
755
+ { name: "user", content: { text: "/models" } },
727
756
  {
728
- user: "assistant",
757
+ name: "assistant",
729
758
  content: {
730
759
  text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
731
760
  }
@@ -759,7 +788,10 @@ async function buildStatusReport(runtime, roomId) {
759
788
  }
760
789
  } catch {}
761
790
  try {
762
- const tasks = await runtime.getTasks({ roomId });
791
+ const tasks = await runtime.getTasks({
792
+ roomId,
793
+ agentIds: [runtime.agentId]
794
+ });
763
795
  if (tasks.length > 0) {
764
796
  lines.push(`
765
797
  **Tasks:** ${tasks.length} pending`);
@@ -771,13 +803,22 @@ async function buildStatusReport(runtime, roomId) {
771
803
  var statusAction = {
772
804
  name: "STATUS_COMMAND",
773
805
  description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
806
+ descriptionCompressed: "Show session settings. Trigger: /status, /s.",
774
807
  similes: ["/status", "/s"],
775
- async validate(runtime, message) {
776
- const text = message.content?.text ?? "";
777
- const detection = detectCommand(text);
808
+ validate: async (runtime, message) => {
809
+ const textRaw = message.content?.text ?? "";
810
+ const text = textRaw.toLowerCase();
811
+ const hasKeyword = text.includes("/status") || text.includes("/s") || text.includes("status");
812
+ const hasRegex = /^(?:\/|!)\s*(?:status|s)\b/i.test(textRaw);
813
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
814
+ const hasInput = textRaw.trim().length > 0;
815
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
816
+ return false;
817
+ }
818
+ const detection = detectCommand(textRaw);
778
819
  return detection.isCommand && detection.command?.key === "status";
779
820
  },
780
- async handler(runtime, message, state, options, callback) {
821
+ async handler(runtime, message, _state, _options, callback) {
781
822
  const statusText = await buildStatusReport(runtime, message.roomId);
782
823
  await callback?.({ text: statusText });
783
824
  return {
@@ -787,9 +828,9 @@ var statusAction = {
787
828
  },
788
829
  examples: [
789
830
  [
790
- { user: "user", content: { text: "/status" } },
831
+ { name: "user", content: { text: "/status" } },
791
832
  {
792
- user: "assistant",
833
+ name: "assistant",
793
834
  content: {
794
835
  text: `**Session Status:**
795
836
 
@@ -809,13 +850,22 @@ import { EventType, logger as logger2 } from "@elizaos/core";
809
850
  var stopAction = {
810
851
  name: "STOP_COMMAND",
811
852
  description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
853
+ descriptionCompressed: "Stop/abort running tasks. Trigger: /stop, /abort, /cancel.",
812
854
  similes: ["/stop", "/abort", "/cancel"],
813
- async validate(runtime, message) {
814
- const text = message.content?.text ?? "";
815
- const detection = detectCommand(text);
855
+ validate: async (runtime, message) => {
856
+ const textRaw = message.content?.text ?? "";
857
+ const text = textRaw.toLowerCase();
858
+ const hasKeyword = text.includes("/stop") || text.includes("/abort") || text.includes("/cancel") || text.includes("stop");
859
+ const hasRegex = /^(?:\/|!)\s*(?:stop|abort|cancel)\b/i.test(textRaw);
860
+ const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
861
+ const hasInput = textRaw.trim().length > 0;
862
+ if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
863
+ return false;
864
+ }
865
+ const detection = detectCommand(textRaw);
816
866
  return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
817
867
  },
818
- async handler(runtime, message, state, options, callback) {
868
+ async handler(runtime, message, _state, _options, callback) {
819
869
  try {
820
870
  await runtime.emitEvent(EventType.HOOK_COMMAND_STOP, {
821
871
  runtime,
@@ -842,18 +892,18 @@ var stopAction = {
842
892
  },
843
893
  examples: [
844
894
  [
845
- { user: "user", content: { text: "/stop" } },
895
+ { name: "user", content: { text: "/stop" } },
846
896
  {
847
- user: "assistant",
897
+ name: "assistant",
848
898
  content: {
849
899
  text: "✓ Stop requested. Current operations will be cancelled."
850
900
  }
851
901
  }
852
902
  ],
853
903
  [
854
- { user: "user", content: { text: "/abort" } },
904
+ { name: "user", content: { text: "/abort" } },
855
905
  {
856
- user: "assistant",
906
+ name: "assistant",
857
907
  content: {
858
908
  text: "✓ Stop requested. Current operations will be cancelled."
859
909
  }
@@ -866,6 +916,7 @@ var stopAction = {
866
916
  var commandRegistryProvider = {
867
917
  name: "COMMAND_REGISTRY",
868
918
  description: "Available chat commands and their descriptions",
919
+ descriptionCompressed: "Available chat commands and descriptions.",
869
920
  dynamic: true,
870
921
  async get(runtime, message, _state) {
871
922
  useRuntime(runtime.agentId);
@@ -1126,4 +1177,4 @@ export {
1126
1177
  commandRegistryProvider
1127
1178
  };
1128
1179
 
1129
- //# debugId=C6086C11EDA7A75E64756E2164756E21
1180
+ //# debugId=CAE533D89EAF426E64756E2164756E21