@elizaos/plugin-commands 2.0.0-alpha.3 → 2.0.0-alpha.4
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 +208 -138
- package/dist/cjs/index.cjs.map +10 -10
- package/dist/index.js +208 -138
- package/dist/index.js.map +10 -10
- 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 = [
|
|
@@ -149,9 +151,7 @@ var DEFAULT_COMMANDS = [
|
|
|
149
151
|
scope: "both",
|
|
150
152
|
category: "session",
|
|
151
153
|
acceptsArgs: true,
|
|
152
|
-
args: [
|
|
153
|
-
{ name: "instructions", description: "Optional compaction instructions" }
|
|
154
|
-
]
|
|
154
|
+
args: [{ name: "instructions", description: "Optional compaction instructions" }]
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
157
|
key: "think",
|
|
@@ -161,9 +161,7 @@ var DEFAULT_COMMANDS = [
|
|
|
161
161
|
scope: "both",
|
|
162
162
|
category: "options",
|
|
163
163
|
acceptsArgs: true,
|
|
164
|
-
args: [
|
|
165
|
-
{ name: "level", description: "off, minimal, low, medium, high, xhigh" }
|
|
166
|
-
]
|
|
164
|
+
args: [{ name: "level", description: "off, minimal, low, medium, high, xhigh" }]
|
|
167
165
|
},
|
|
168
166
|
{
|
|
169
167
|
key: "verbose",
|
|
@@ -338,21 +336,39 @@ var DEFAULT_COMMANDS = [
|
|
|
338
336
|
requiresElevated: true
|
|
339
337
|
}
|
|
340
338
|
];
|
|
341
|
-
var
|
|
342
|
-
var
|
|
339
|
+
var runtimeStores = new Map;
|
|
340
|
+
var fallbackStore = {
|
|
341
|
+
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
342
|
+
aliasMap: null
|
|
343
|
+
};
|
|
344
|
+
var activeStore = fallbackStore;
|
|
345
|
+
function initForRuntime(agentId) {
|
|
346
|
+
const store = {
|
|
347
|
+
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
348
|
+
aliasMap: null
|
|
349
|
+
};
|
|
350
|
+
runtimeStores.set(agentId, store);
|
|
351
|
+
activeStore = store;
|
|
352
|
+
}
|
|
353
|
+
function useRuntime(agentId) {
|
|
354
|
+
const store = runtimeStores.get(agentId);
|
|
355
|
+
if (store) {
|
|
356
|
+
activeStore = store;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
343
359
|
function getCommands() {
|
|
344
|
-
return [...commands];
|
|
360
|
+
return [...activeStore.commands];
|
|
345
361
|
}
|
|
346
362
|
function getEnabledCommands() {
|
|
347
|
-
return commands.filter((cmd) => cmd.enabled !== false);
|
|
363
|
+
return activeStore.commands.filter((cmd) => cmd.enabled !== false);
|
|
348
364
|
}
|
|
349
365
|
function getCommandsByCategory(category) {
|
|
350
|
-
return commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
366
|
+
return activeStore.commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
351
367
|
}
|
|
352
368
|
function registerCommand(command) {
|
|
353
|
-
commands = commands.filter((c) => c.key !== command.key);
|
|
354
|
-
commands.push(command);
|
|
355
|
-
aliasMap = null;
|
|
369
|
+
activeStore.commands = activeStore.commands.filter((c) => c.key !== command.key);
|
|
370
|
+
activeStore.commands.push(command);
|
|
371
|
+
activeStore.aliasMap = null;
|
|
356
372
|
}
|
|
357
373
|
function registerCommands(newCommands) {
|
|
358
374
|
for (const command of newCommands) {
|
|
@@ -360,35 +376,35 @@ function registerCommands(newCommands) {
|
|
|
360
376
|
}
|
|
361
377
|
}
|
|
362
378
|
function unregisterCommand(key) {
|
|
363
|
-
commands = commands.filter((c) => c.key !== key);
|
|
364
|
-
aliasMap = null;
|
|
379
|
+
activeStore.commands = activeStore.commands.filter((c) => c.key !== key);
|
|
380
|
+
activeStore.aliasMap = null;
|
|
365
381
|
}
|
|
366
382
|
function resetCommands() {
|
|
367
|
-
commands =
|
|
368
|
-
aliasMap = null;
|
|
383
|
+
activeStore.commands = DEFAULT_COMMANDS.map((c) => ({ ...c }));
|
|
384
|
+
activeStore.aliasMap = null;
|
|
369
385
|
}
|
|
370
386
|
function getAliasMap() {
|
|
371
|
-
if (aliasMap)
|
|
372
|
-
return aliasMap;
|
|
373
|
-
aliasMap = new Map;
|
|
374
|
-
for (const command of commands) {
|
|
387
|
+
if (activeStore.aliasMap)
|
|
388
|
+
return activeStore.aliasMap;
|
|
389
|
+
activeStore.aliasMap = new Map;
|
|
390
|
+
for (const command of activeStore.commands) {
|
|
375
391
|
if (command.enabled === false)
|
|
376
392
|
continue;
|
|
377
393
|
for (const alias of command.textAliases) {
|
|
378
394
|
const normalized = alias.toLowerCase().trim();
|
|
379
|
-
if (!aliasMap.has(normalized)) {
|
|
380
|
-
aliasMap.set(normalized, command);
|
|
395
|
+
if (!activeStore.aliasMap.has(normalized)) {
|
|
396
|
+
activeStore.aliasMap.set(normalized, command);
|
|
381
397
|
}
|
|
382
398
|
}
|
|
383
399
|
}
|
|
384
|
-
return aliasMap;
|
|
400
|
+
return activeStore.aliasMap;
|
|
385
401
|
}
|
|
386
402
|
function findCommandByAlias(alias) {
|
|
387
403
|
const map = getAliasMap();
|
|
388
404
|
return map.get(alias.toLowerCase().trim());
|
|
389
405
|
}
|
|
390
406
|
function findCommandByKey(key) {
|
|
391
|
-
return commands.find((c) => c.key === key);
|
|
407
|
+
return activeStore.commands.find((c) => c.key === key);
|
|
392
408
|
}
|
|
393
409
|
function startsWithCommand(text) {
|
|
394
410
|
const map = getAliasMap();
|
|
@@ -397,7 +413,7 @@ function startsWithCommand(text) {
|
|
|
397
413
|
if (normalized === alias) {
|
|
398
414
|
return command;
|
|
399
415
|
}
|
|
400
|
-
if (normalized.startsWith(alias
|
|
416
|
+
if (normalized.startsWith(`${alias} `) || normalized.startsWith(`${alias}:`)) {
|
|
401
417
|
return command;
|
|
402
418
|
}
|
|
403
419
|
}
|
|
@@ -441,7 +457,7 @@ function parseCommand(text, definition) {
|
|
|
441
457
|
matchedAlias = alias;
|
|
442
458
|
break;
|
|
443
459
|
}
|
|
444
|
-
if (trimmed.toLowerCase().startsWith(normalized
|
|
460
|
+
if (trimmed.toLowerCase().startsWith(`${normalized} `) || trimmed.toLowerCase().startsWith(`${normalized}:`)) {
|
|
445
461
|
matchedAlias = alias;
|
|
446
462
|
break;
|
|
447
463
|
}
|
|
@@ -550,18 +566,18 @@ function extractCommand(text) {
|
|
|
550
566
|
// src/actions/commands-list.ts
|
|
551
567
|
var commandsListAction = {
|
|
552
568
|
name: "COMMANDS_LIST",
|
|
553
|
-
description: "List all available commands with their aliases",
|
|
554
|
-
similes: ["/commands", "/cmds"
|
|
555
|
-
async validate(
|
|
569
|
+
description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
|
|
570
|
+
similes: ["/commands", "/cmds"],
|
|
571
|
+
async validate(_runtime, message) {
|
|
556
572
|
const text = message.content?.text ?? "";
|
|
557
573
|
const detection = detectCommand(text);
|
|
558
574
|
return detection.isCommand && detection.command?.key === "commands";
|
|
559
575
|
},
|
|
560
|
-
async handler(
|
|
561
|
-
const
|
|
562
|
-
const lines = [`**Commands (${
|
|
576
|
+
async handler(_runtime, _message, _state, _options, callback) {
|
|
577
|
+
const commands = getEnabledCommands();
|
|
578
|
+
const lines = [`**Commands (${commands.length}):**
|
|
563
579
|
`];
|
|
564
|
-
for (const cmd of
|
|
580
|
+
for (const cmd of commands) {
|
|
565
581
|
const aliases = cmd.textAliases.join(", ");
|
|
566
582
|
const authNote = cmd.requiresAuth ? " [auth]" : "";
|
|
567
583
|
const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
|
|
@@ -573,7 +589,7 @@ var commandsListAction = {
|
|
|
573
589
|
return {
|
|
574
590
|
success: true,
|
|
575
591
|
text: replyText,
|
|
576
|
-
data: { commandCount:
|
|
592
|
+
data: { commandCount: commands.length }
|
|
577
593
|
};
|
|
578
594
|
},
|
|
579
595
|
examples: [
|
|
@@ -593,7 +609,7 @@ var commandsListAction = {
|
|
|
593
609
|
};
|
|
594
610
|
|
|
595
611
|
// src/actions/help.ts
|
|
596
|
-
function formatCommandList(
|
|
612
|
+
function formatCommandList(commands) {
|
|
597
613
|
const lines = [`**Available Commands:**
|
|
598
614
|
`];
|
|
599
615
|
const categories = [
|
|
@@ -605,7 +621,7 @@ function formatCommandList(commands2) {
|
|
|
605
621
|
{ key: "tools", name: "Tools" }
|
|
606
622
|
];
|
|
607
623
|
for (const cat of categories) {
|
|
608
|
-
const catCommands =
|
|
624
|
+
const catCommands = commands.filter((c) => c.category === cat.key);
|
|
609
625
|
if (catCommands.length === 0)
|
|
610
626
|
continue;
|
|
611
627
|
lines.push(`
|
|
@@ -615,7 +631,7 @@ function formatCommandList(commands2) {
|
|
|
615
631
|
lines.push(`• ${aliases} - ${cmd.description}`);
|
|
616
632
|
}
|
|
617
633
|
}
|
|
618
|
-
const uncategorized =
|
|
634
|
+
const uncategorized = commands.filter((c) => !c.category);
|
|
619
635
|
if (uncategorized.length > 0) {
|
|
620
636
|
lines.push(`
|
|
621
637
|
**Other:**`);
|
|
@@ -629,21 +645,21 @@ function formatCommandList(commands2) {
|
|
|
629
645
|
}
|
|
630
646
|
var helpAction = {
|
|
631
647
|
name: "HELP_COMMAND",
|
|
632
|
-
description: "Show available commands and their descriptions",
|
|
633
|
-
similes: ["/help", "/h", "/?"
|
|
634
|
-
async validate(
|
|
648
|
+
description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
|
|
649
|
+
similes: ["/help", "/h", "/?"],
|
|
650
|
+
async validate(_runtime, message) {
|
|
635
651
|
const text = message.content?.text ?? "";
|
|
636
652
|
const detection = detectCommand(text);
|
|
637
653
|
return detection.isCommand && detection.command?.key === "help";
|
|
638
654
|
},
|
|
639
|
-
async handler(
|
|
640
|
-
const
|
|
641
|
-
const helpText = formatCommandList(
|
|
655
|
+
async handler(_runtime, _message, _state, _options, callback) {
|
|
656
|
+
const commands = getEnabledCommands();
|
|
657
|
+
const helpText = formatCommandList(commands);
|
|
642
658
|
await callback?.({ text: helpText });
|
|
643
659
|
return {
|
|
644
660
|
success: true,
|
|
645
661
|
text: helpText,
|
|
646
|
-
data: { commandCount:
|
|
662
|
+
data: { commandCount: commands.length }
|
|
647
663
|
};
|
|
648
664
|
},
|
|
649
665
|
examples: [
|
|
@@ -675,49 +691,74 @@ var helpAction = {
|
|
|
675
691
|
};
|
|
676
692
|
|
|
677
693
|
// src/actions/models.ts
|
|
694
|
+
var import_core = require("@elizaos/core");
|
|
695
|
+
function describeModelType(modelType) {
|
|
696
|
+
const descriptions = {
|
|
697
|
+
[import_core.ModelType.TEXT_SMALL]: "Text (Small)",
|
|
698
|
+
[import_core.ModelType.TEXT_LARGE]: "Text (Large)",
|
|
699
|
+
[import_core.ModelType.TEXT_REASONING_SMALL]: "Reasoning (Small)",
|
|
700
|
+
[import_core.ModelType.TEXT_REASONING_LARGE]: "Reasoning (Large)",
|
|
701
|
+
[import_core.ModelType.TEXT_COMPLETION]: "Text Completion",
|
|
702
|
+
[import_core.ModelType.TEXT_EMBEDDING]: "Embedding",
|
|
703
|
+
[import_core.ModelType.IMAGE]: "Image Generation",
|
|
704
|
+
[import_core.ModelType.IMAGE_DESCRIPTION]: "Image Description",
|
|
705
|
+
[import_core.ModelType.TRANSCRIPTION]: "Transcription",
|
|
706
|
+
[import_core.ModelType.TEXT_TO_SPEECH]: "Text-to-Speech",
|
|
707
|
+
[import_core.ModelType.AUDIO]: "Audio",
|
|
708
|
+
[import_core.ModelType.VIDEO]: "Video",
|
|
709
|
+
[import_core.ModelType.OBJECT_SMALL]: "Object (Small)",
|
|
710
|
+
[import_core.ModelType.OBJECT_LARGE]: "Object (Large)",
|
|
711
|
+
[import_core.ModelType.RESEARCH]: "Research"
|
|
712
|
+
};
|
|
713
|
+
return descriptions[modelType] ?? modelType;
|
|
714
|
+
}
|
|
678
715
|
var modelsAction = {
|
|
679
716
|
name: "MODELS_COMMAND",
|
|
680
|
-
description: "List available AI models and providers",
|
|
681
|
-
similes: ["/models"
|
|
682
|
-
async validate(
|
|
717
|
+
description: "List available AI models and providers. Only activates for /models slash command.",
|
|
718
|
+
similes: ["/models"],
|
|
719
|
+
async validate(_runtime, message) {
|
|
683
720
|
const text = message.content?.text ?? "";
|
|
684
721
|
const detection = detectCommand(text);
|
|
685
722
|
return detection.isCommand && detection.command?.key === "models";
|
|
686
723
|
},
|
|
687
|
-
async handler(runtime,
|
|
724
|
+
async handler(runtime, _message, _state, _options, callback) {
|
|
688
725
|
const lines = [`**Available Models:**
|
|
689
726
|
`];
|
|
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"]
|
|
727
|
+
try {
|
|
728
|
+
const registeredTypes = [];
|
|
729
|
+
const seen = new Set;
|
|
730
|
+
for (const modelType of Object.values(import_core.ModelType)) {
|
|
731
|
+
if (seen.has(modelType))
|
|
732
|
+
continue;
|
|
733
|
+
seen.add(modelType);
|
|
734
|
+
try {
|
|
735
|
+
const handler = runtime.getModel(modelType);
|
|
736
|
+
if (handler) {
|
|
737
|
+
registeredTypes.push(modelType);
|
|
738
|
+
}
|
|
739
|
+
} catch {}
|
|
713
740
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
741
|
+
if (registeredTypes.length > 0) {
|
|
742
|
+
lines.push("**Registered Model Types:**");
|
|
743
|
+
for (const modelType of registeredTypes) {
|
|
744
|
+
lines.push(`• ${describeModelType(modelType)} (\`${modelType}\`)`);
|
|
745
|
+
}
|
|
746
|
+
} else {
|
|
747
|
+
lines.push("No model handlers are currently registered.");
|
|
748
|
+
}
|
|
749
|
+
const modelProvider = runtime.getSetting("MODEL_PROVIDER");
|
|
750
|
+
const modelName = runtime.getSetting("MODEL_NAME");
|
|
751
|
+
if (modelProvider || modelName) {
|
|
752
|
+
lines.push(`
|
|
753
|
+
**Current Configuration:**`);
|
|
754
|
+
if (modelProvider)
|
|
755
|
+
lines.push(`• Provider: ${modelProvider}`);
|
|
756
|
+
if (modelName)
|
|
757
|
+
lines.push(`• Model: ${modelName}`);
|
|
720
758
|
}
|
|
759
|
+
} catch (err) {
|
|
760
|
+
import_core.logger.warn({ src: "plugin-commands", err }, "Error querying runtime models");
|
|
761
|
+
lines.push("Unable to query available models.");
|
|
721
762
|
}
|
|
722
763
|
lines.push(`
|
|
723
764
|
|
|
@@ -727,8 +768,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
727
768
|
await callback?.({ text: replyText });
|
|
728
769
|
return {
|
|
729
770
|
success: true,
|
|
730
|
-
text: replyText
|
|
731
|
-
data: { providers }
|
|
771
|
+
text: replyText
|
|
732
772
|
};
|
|
733
773
|
},
|
|
734
774
|
examples: [
|
|
@@ -737,11 +777,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
737
777
|
{
|
|
738
778
|
user: "assistant",
|
|
739
779
|
content: {
|
|
740
|
-
text:
|
|
741
|
-
|
|
742
|
-
**Anthropic:**
|
|
743
|
-
• anthropic/claude-3-opus
|
|
744
|
-
• anthropic/claude-3-sonnet...`
|
|
780
|
+
text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
|
|
745
781
|
}
|
|
746
782
|
}
|
|
747
783
|
]
|
|
@@ -752,7 +788,7 @@ _Use /model <provider/model> to switch models._`);
|
|
|
752
788
|
async function buildStatusReport(runtime, roomId) {
|
|
753
789
|
const lines = [`**Session Status:**
|
|
754
790
|
`];
|
|
755
|
-
lines.push(`**Agent:** ${runtime.agentId}`);
|
|
791
|
+
lines.push(`**Agent:** ${runtime.character.name ?? runtime.agentId}`);
|
|
756
792
|
lines.push(`**Room:** ${roomId}`);
|
|
757
793
|
try {
|
|
758
794
|
const directiveService = runtime.getService("directive-parser");
|
|
@@ -772,19 +808,26 @@ async function buildStatusReport(runtime, roomId) {
|
|
|
772
808
|
}
|
|
773
809
|
}
|
|
774
810
|
} catch {}
|
|
811
|
+
try {
|
|
812
|
+
const tasks = await runtime.getTasks({ roomId });
|
|
813
|
+
if (tasks.length > 0) {
|
|
814
|
+
lines.push(`
|
|
815
|
+
**Tasks:** ${tasks.length} pending`);
|
|
816
|
+
}
|
|
817
|
+
} catch {}
|
|
775
818
|
return lines.join(`
|
|
776
819
|
`);
|
|
777
820
|
}
|
|
778
821
|
var statusAction = {
|
|
779
822
|
name: "STATUS_COMMAND",
|
|
780
|
-
description: "Show
|
|
781
|
-
similes: ["/status", "/s"
|
|
782
|
-
async validate(
|
|
823
|
+
description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
|
|
824
|
+
similes: ["/status", "/s"],
|
|
825
|
+
async validate(_runtime, message) {
|
|
783
826
|
const text = message.content?.text ?? "";
|
|
784
827
|
const detection = detectCommand(text);
|
|
785
828
|
return detection.isCommand && detection.command?.key === "status";
|
|
786
829
|
},
|
|
787
|
-
async handler(runtime, message,
|
|
830
|
+
async handler(runtime, message, _state, _options, callback) {
|
|
788
831
|
const statusText = await buildStatusReport(runtime, message.roomId);
|
|
789
832
|
await callback?.({ text: statusText });
|
|
790
833
|
return {
|
|
@@ -800,7 +843,7 @@ var statusAction = {
|
|
|
800
843
|
content: {
|
|
801
844
|
text: `**Session Status:**
|
|
802
845
|
|
|
803
|
-
**Agent:**
|
|
846
|
+
**Agent:** Eliza
|
|
804
847
|
**Room:** room-456
|
|
805
848
|
|
|
806
849
|
**Directives:**
|
|
@@ -812,23 +855,34 @@ var statusAction = {
|
|
|
812
855
|
};
|
|
813
856
|
|
|
814
857
|
// src/actions/stop.ts
|
|
858
|
+
var import_core2 = require("@elizaos/core");
|
|
815
859
|
var stopAction = {
|
|
816
860
|
name: "STOP_COMMAND",
|
|
817
|
-
description: "Stop current operation or abort running tasks",
|
|
818
|
-
similes: ["/stop", "/abort", "/cancel"
|
|
819
|
-
async validate(
|
|
861
|
+
description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
|
|
862
|
+
similes: ["/stop", "/abort", "/cancel"],
|
|
863
|
+
async validate(_runtime, message) {
|
|
820
864
|
const text = message.content?.text ?? "";
|
|
821
865
|
const detection = detectCommand(text);
|
|
822
866
|
return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
|
|
823
867
|
},
|
|
824
|
-
async handler(runtime, message,
|
|
868
|
+
async handler(runtime, message, _state, _options, callback) {
|
|
825
869
|
try {
|
|
826
|
-
await runtime.emitEvent
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
870
|
+
await runtime.emitEvent(import_core2.EventType.HOOK_COMMAND_STOP, {
|
|
871
|
+
runtime,
|
|
872
|
+
sessionKey: message.roomId,
|
|
873
|
+
messages: [],
|
|
874
|
+
timestamp: new Date,
|
|
875
|
+
context: {
|
|
876
|
+
entityId: message.entityId,
|
|
877
|
+
source: message.content?.source
|
|
878
|
+
},
|
|
879
|
+
command: "stop",
|
|
880
|
+
senderId: message.entityId,
|
|
881
|
+
commandSource: message.content?.source
|
|
830
882
|
});
|
|
831
|
-
} catch {
|
|
883
|
+
} catch (err) {
|
|
884
|
+
import_core2.logger.warn({ src: "plugin-commands", err }, "Failed to emit HOOK_COMMAND_STOP event");
|
|
885
|
+
}
|
|
832
886
|
const replyText = "✓ Stop requested. Current operations will be cancelled.";
|
|
833
887
|
await callback?.({ text: replyText });
|
|
834
888
|
return {
|
|
@@ -864,28 +918,44 @@ var commandRegistryProvider = {
|
|
|
864
918
|
description: "Available chat commands and their descriptions",
|
|
865
919
|
dynamic: true,
|
|
866
920
|
async get(runtime, message, _state) {
|
|
867
|
-
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
921
|
+
useRuntime(runtime.agentId);
|
|
922
|
+
const text = message.content?.text ?? "";
|
|
923
|
+
const isCommand = hasCommand(text);
|
|
924
|
+
const commands = getEnabledCommands();
|
|
925
|
+
if (isCommand) {
|
|
926
|
+
const commandList = commands.map((cmd) => {
|
|
927
|
+
const auth = cmd.requiresAuth ? " (requires auth)" : "";
|
|
928
|
+
return `- ${cmd.textAliases[0]}: ${cmd.description}${auth}`;
|
|
929
|
+
});
|
|
930
|
+
return {
|
|
931
|
+
text: `The user sent a slash command. Available commands:
|
|
874
932
|
${commandList.join(`
|
|
875
|
-
`)}
|
|
933
|
+
`)}
|
|
934
|
+
|
|
935
|
+
IMPORTANT: This is a slash command — respond by executing the matching command action, not with conversational text.`,
|
|
936
|
+
values: {
|
|
937
|
+
commandCount: commands.length,
|
|
938
|
+
isCommand: true,
|
|
939
|
+
hasElevatedCommands: commands.some((c) => c.requiresElevated)
|
|
940
|
+
},
|
|
941
|
+
data: { commands, isCommand: true }
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
return {
|
|
945
|
+
text: "",
|
|
876
946
|
values: {
|
|
877
|
-
commandCount:
|
|
878
|
-
|
|
947
|
+
commandCount: commands.length,
|
|
948
|
+
isCommand: false
|
|
879
949
|
},
|
|
880
|
-
data: {
|
|
950
|
+
data: { isCommand: false }
|
|
881
951
|
};
|
|
882
952
|
}
|
|
883
953
|
};
|
|
884
954
|
function formatCommandResult(result) {
|
|
885
955
|
if (result.error) {
|
|
886
|
-
return
|
|
956
|
+
return `Error: ${result.error}`;
|
|
887
957
|
}
|
|
888
|
-
return result.reply ?? "
|
|
958
|
+
return result.reply ?? "Command executed";
|
|
889
959
|
}
|
|
890
960
|
function isAuthorized(context, command) {
|
|
891
961
|
if (!command.requiresAuth) {
|
|
@@ -903,13 +973,7 @@ var commandsPlugin = {
|
|
|
903
973
|
name: "commands",
|
|
904
974
|
description: "Chat command system with /help, /status, /reset, etc.",
|
|
905
975
|
providers: [commandRegistryProvider],
|
|
906
|
-
actions: [
|
|
907
|
-
helpAction,
|
|
908
|
-
statusAction,
|
|
909
|
-
stopAction,
|
|
910
|
-
modelsAction,
|
|
911
|
-
commandsListAction
|
|
912
|
-
],
|
|
976
|
+
actions: [helpAction, statusAction, stopAction, modelsAction, commandsListAction],
|
|
913
977
|
config: {
|
|
914
978
|
COMMANDS_ENABLED: "true",
|
|
915
979
|
COMMANDS_CONFIG_ENABLED: "false",
|
|
@@ -933,7 +997,7 @@ var commandsPlugin = {
|
|
|
933
997
|
if (hasCommand("hello world")) {
|
|
934
998
|
throw new Error("Should not detect plain text as command");
|
|
935
999
|
}
|
|
936
|
-
|
|
1000
|
+
import_core3.logger.success("Command prefix detection works correctly");
|
|
937
1001
|
}
|
|
938
1002
|
},
|
|
939
1003
|
{
|
|
@@ -949,7 +1013,7 @@ var commandsPlugin = {
|
|
|
949
1013
|
if (detection.command?.args[0] !== "high") {
|
|
950
1014
|
throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
|
|
951
1015
|
}
|
|
952
|
-
|
|
1016
|
+
import_core3.logger.success("Command argument parsing works correctly");
|
|
953
1017
|
}
|
|
954
1018
|
},
|
|
955
1019
|
{
|
|
@@ -963,7 +1027,7 @@ var commandsPlugin = {
|
|
|
963
1027
|
if (normalized2 !== "/help") {
|
|
964
1028
|
throw new Error(`Expected '/help', got '${normalized2}'`);
|
|
965
1029
|
}
|
|
966
|
-
|
|
1030
|
+
import_core3.logger.success("Command normalization works correctly");
|
|
967
1031
|
}
|
|
968
1032
|
},
|
|
969
1033
|
{
|
|
@@ -976,7 +1040,7 @@ var commandsPlugin = {
|
|
|
976
1040
|
if (cmd.key !== "help") {
|
|
977
1041
|
throw new Error(`Expected key 'help', got '${cmd.key}'`);
|
|
978
1042
|
}
|
|
979
|
-
|
|
1043
|
+
import_core3.logger.success("Command alias lookup works correctly");
|
|
980
1044
|
}
|
|
981
1045
|
},
|
|
982
1046
|
{
|
|
@@ -989,7 +1053,7 @@ var commandsPlugin = {
|
|
|
989
1053
|
if (cmd.key !== "status") {
|
|
990
1054
|
throw new Error(`Expected key 'status', got '${cmd.key}'`);
|
|
991
1055
|
}
|
|
992
|
-
|
|
1056
|
+
import_core3.logger.success("Command key lookup works correctly");
|
|
993
1057
|
}
|
|
994
1058
|
}
|
|
995
1059
|
]
|
|
@@ -1000,16 +1064,16 @@ var commandsPlugin = {
|
|
|
1000
1064
|
{
|
|
1001
1065
|
name: "Get enabled commands",
|
|
1002
1066
|
fn: async (_runtime) => {
|
|
1003
|
-
const
|
|
1004
|
-
if (
|
|
1067
|
+
const commands = getEnabledCommands();
|
|
1068
|
+
if (commands.length === 0) {
|
|
1005
1069
|
throw new Error("Should have enabled commands");
|
|
1006
1070
|
}
|
|
1007
|
-
const
|
|
1008
|
-
const
|
|
1009
|
-
if (!
|
|
1071
|
+
const cmdHelp = commands.some((c) => c.key === "help");
|
|
1072
|
+
const cmdStatus = commands.some((c) => c.key === "status");
|
|
1073
|
+
if (!cmdHelp || !cmdStatus) {
|
|
1010
1074
|
throw new Error("Should have help and status commands");
|
|
1011
1075
|
}
|
|
1012
|
-
|
|
1076
|
+
import_core3.logger.success("Command registry works correctly");
|
|
1013
1077
|
}
|
|
1014
1078
|
},
|
|
1015
1079
|
{
|
|
@@ -1031,7 +1095,7 @@ var commandsPlugin = {
|
|
|
1031
1095
|
if (notFound) {
|
|
1032
1096
|
throw new Error("Should not find unregistered command");
|
|
1033
1097
|
}
|
|
1034
|
-
|
|
1098
|
+
import_core3.logger.success("Custom command registration works correctly");
|
|
1035
1099
|
}
|
|
1036
1100
|
},
|
|
1037
1101
|
{
|
|
@@ -1045,17 +1109,19 @@ var commandsPlugin = {
|
|
|
1045
1109
|
if (!allStatus) {
|
|
1046
1110
|
throw new Error("All returned commands should be in status category");
|
|
1047
1111
|
}
|
|
1048
|
-
|
|
1112
|
+
import_core3.logger.success("Command categorization works correctly");
|
|
1049
1113
|
}
|
|
1050
1114
|
}
|
|
1051
1115
|
]
|
|
1052
1116
|
}
|
|
1053
1117
|
],
|
|
1054
1118
|
async init(config, runtime) {
|
|
1055
|
-
|
|
1119
|
+
import_core3.logger.log("[plugin-commands] Initializing command system");
|
|
1120
|
+
initForRuntime(runtime.agentId);
|
|
1056
1121
|
const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
|
|
1057
1122
|
const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
|
|
1058
1123
|
const bashEnabled = config.COMMANDS_BASH_ENABLED === "true";
|
|
1124
|
+
const restartEnabled = config.COMMANDS_RESTART_ENABLED !== "false";
|
|
1059
1125
|
const configCmd = findCommandByKey("config");
|
|
1060
1126
|
if (configCmd) {
|
|
1061
1127
|
configCmd.enabled = configEnabled;
|
|
@@ -1068,10 +1134,14 @@ var commandsPlugin = {
|
|
|
1068
1134
|
if (bashCmd) {
|
|
1069
1135
|
bashCmd.enabled = bashEnabled;
|
|
1070
1136
|
}
|
|
1137
|
+
const restartCmd = findCommandByKey("restart");
|
|
1138
|
+
if (restartCmd) {
|
|
1139
|
+
restartCmd.enabled = restartEnabled;
|
|
1140
|
+
}
|
|
1071
1141
|
const enabledCount = getEnabledCommands().length;
|
|
1072
|
-
|
|
1142
|
+
import_core3.logger.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
|
|
1073
1143
|
}
|
|
1074
1144
|
};
|
|
1075
1145
|
var src_default = commandsPlugin;
|
|
1076
1146
|
|
|
1077
|
-
//# debugId=
|
|
1147
|
+
//# debugId=6FF2A15CEA611B5664756E2164756E21
|