@elizaos/plugin-commands 2.0.0-beta.1 → 2.0.3-beta.2
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/LICENSE +21 -0
- package/README.md +83 -0
- package/auto-enable.ts +1 -1
- package/package.json +26 -16
- package/dist/cjs/index.cjs +0 -822
- package/dist/cjs/index.cjs.map +0 -12
- package/dist/index.js +0 -784
- package/dist/index.js.map +0 -12
package/dist/cjs/index.cjs
DELETED
|
@@ -1,822 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
function __accessProp(key) {
|
|
6
|
-
return this[key];
|
|
7
|
-
}
|
|
8
|
-
var __toCommonJS = (from) => {
|
|
9
|
-
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
-
if (entry)
|
|
11
|
-
return entry;
|
|
12
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (var key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(entry, key))
|
|
16
|
-
__defProp(entry, key, {
|
|
17
|
-
get: __accessProp.bind(from, key),
|
|
18
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
__moduleCache.set(from, entry);
|
|
22
|
-
return entry;
|
|
23
|
-
};
|
|
24
|
-
var __moduleCache;
|
|
25
|
-
var __returnValue = (v) => v;
|
|
26
|
-
function __exportSetter(name, newValue) {
|
|
27
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
-
}
|
|
29
|
-
var __export = (target, all) => {
|
|
30
|
-
for (var name in all)
|
|
31
|
-
__defProp(target, name, {
|
|
32
|
-
get: all[name],
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
set: __exportSetter.bind(all, name)
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
|
-
var exports_src = {};
|
|
41
|
-
__export(exports_src, {
|
|
42
|
-
useRuntime: () => useRuntime,
|
|
43
|
-
unregisterCommand: () => unregisterCommand,
|
|
44
|
-
startsWithCommand: () => startsWithCommand,
|
|
45
|
-
resetCommands: () => resetCommands,
|
|
46
|
-
registerCommands: () => registerCommands,
|
|
47
|
-
registerCommand: () => registerCommand,
|
|
48
|
-
parseCommand: () => parseCommand,
|
|
49
|
-
normalizeCommandBody: () => normalizeCommandBody,
|
|
50
|
-
isElevated: () => isElevated,
|
|
51
|
-
isCommandOnly: () => isCommandOnly,
|
|
52
|
-
isAuthorized: () => isAuthorized,
|
|
53
|
-
initForRuntime: () => initForRuntime,
|
|
54
|
-
hasCommand: () => hasCommand,
|
|
55
|
-
getEnabledCommands: () => getEnabledCommands,
|
|
56
|
-
getCommandsByCategory: () => getCommandsByCategory,
|
|
57
|
-
getCommands: () => getCommands,
|
|
58
|
-
formatCommandResult: () => formatCommandResult,
|
|
59
|
-
findCommandByKey: () => findCommandByKey,
|
|
60
|
-
findCommandByAlias: () => findCommandByAlias,
|
|
61
|
-
extractCommand: () => extractCommand,
|
|
62
|
-
detectCommand: () => detectCommand,
|
|
63
|
-
default: () => src_default,
|
|
64
|
-
commandsPlugin: () => commandsPlugin,
|
|
65
|
-
commandRegistryProvider: () => commandRegistryProvider
|
|
66
|
-
});
|
|
67
|
-
module.exports = __toCommonJS(exports_src);
|
|
68
|
-
var import_core = require("@elizaos/core");
|
|
69
|
-
|
|
70
|
-
// src/registry.ts
|
|
71
|
-
var DEFAULT_COMMANDS = [
|
|
72
|
-
{
|
|
73
|
-
key: "help",
|
|
74
|
-
nativeName: "help",
|
|
75
|
-
description: "Show available commands",
|
|
76
|
-
textAliases: ["/help", "/h", "/?"],
|
|
77
|
-
scope: "both",
|
|
78
|
-
category: "status",
|
|
79
|
-
acceptsArgs: false
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
key: "commands",
|
|
83
|
-
nativeName: "commands",
|
|
84
|
-
description: "List all commands",
|
|
85
|
-
textAliases: ["/commands", "/cmds"],
|
|
86
|
-
scope: "both",
|
|
87
|
-
category: "status",
|
|
88
|
-
acceptsArgs: false
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
key: "status",
|
|
92
|
-
nativeName: "status",
|
|
93
|
-
description: "Show current session status",
|
|
94
|
-
textAliases: ["/status", "/s"],
|
|
95
|
-
scope: "both",
|
|
96
|
-
category: "status",
|
|
97
|
-
acceptsArgs: false
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
key: "context",
|
|
101
|
-
nativeName: "context",
|
|
102
|
-
description: "Show current context information",
|
|
103
|
-
textAliases: ["/context", "/ctx"],
|
|
104
|
-
scope: "both",
|
|
105
|
-
category: "status",
|
|
106
|
-
acceptsArgs: true,
|
|
107
|
-
args: [{ name: "mode", description: "Output mode (list, detail, json)" }]
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
key: "whoami",
|
|
111
|
-
nativeName: "whoami",
|
|
112
|
-
description: "Show your identity information",
|
|
113
|
-
textAliases: ["/whoami", "/who"],
|
|
114
|
-
scope: "both",
|
|
115
|
-
category: "status",
|
|
116
|
-
acceptsArgs: false
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
key: "stop",
|
|
120
|
-
nativeName: "stop",
|
|
121
|
-
description: "Stop current operation",
|
|
122
|
-
textAliases: ["/stop", "/abort", "/cancel"],
|
|
123
|
-
scope: "both",
|
|
124
|
-
category: "session",
|
|
125
|
-
acceptsArgs: false
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
key: "restart",
|
|
129
|
-
nativeName: "restart",
|
|
130
|
-
description: "Restart the session",
|
|
131
|
-
textAliases: ["/restart"],
|
|
132
|
-
scope: "both",
|
|
133
|
-
category: "session",
|
|
134
|
-
acceptsArgs: false,
|
|
135
|
-
requiresAuth: true
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
key: "reset",
|
|
139
|
-
nativeName: "reset",
|
|
140
|
-
description: "Reset session state",
|
|
141
|
-
textAliases: ["/reset"],
|
|
142
|
-
scope: "both",
|
|
143
|
-
category: "session",
|
|
144
|
-
acceptsArgs: false,
|
|
145
|
-
requiresAuth: true
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
key: "new",
|
|
149
|
-
nativeName: "new",
|
|
150
|
-
description: "Start a new conversation",
|
|
151
|
-
textAliases: ["/new"],
|
|
152
|
-
scope: "both",
|
|
153
|
-
category: "session",
|
|
154
|
-
acceptsArgs: false
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
key: "compact",
|
|
158
|
-
nativeName: "compact",
|
|
159
|
-
description: "Compact conversation history",
|
|
160
|
-
textAliases: ["/compact"],
|
|
161
|
-
scope: "both",
|
|
162
|
-
category: "session",
|
|
163
|
-
acceptsArgs: true,
|
|
164
|
-
args: [
|
|
165
|
-
{ name: "instructions", description: "Optional compaction instructions" }
|
|
166
|
-
]
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
key: "think",
|
|
170
|
-
nativeName: "think",
|
|
171
|
-
description: "Set thinking level",
|
|
172
|
-
textAliases: ["/think", "/thinking", "/t"],
|
|
173
|
-
scope: "both",
|
|
174
|
-
category: "options",
|
|
175
|
-
acceptsArgs: true,
|
|
176
|
-
args: [
|
|
177
|
-
{ name: "level", description: "off, minimal, low, medium, high, xhigh" }
|
|
178
|
-
]
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
key: "verbose",
|
|
182
|
-
nativeName: "verbose",
|
|
183
|
-
description: "Set verbose output level",
|
|
184
|
-
textAliases: ["/verbose", "/v"],
|
|
185
|
-
scope: "both",
|
|
186
|
-
category: "options",
|
|
187
|
-
acceptsArgs: true,
|
|
188
|
-
args: [{ name: "level", description: "off, on, full" }]
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
key: "reasoning",
|
|
192
|
-
nativeName: "reasoning",
|
|
193
|
-
description: "Set reasoning visibility",
|
|
194
|
-
textAliases: ["/reasoning", "/reason"],
|
|
195
|
-
scope: "both",
|
|
196
|
-
category: "options",
|
|
197
|
-
acceptsArgs: true,
|
|
198
|
-
args: [{ name: "level", description: "off, on, stream" }]
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
key: "elevated",
|
|
202
|
-
nativeName: "elevated",
|
|
203
|
-
description: "Set elevated permission mode",
|
|
204
|
-
textAliases: ["/elevated", "/elev"],
|
|
205
|
-
scope: "both",
|
|
206
|
-
category: "options",
|
|
207
|
-
acceptsArgs: true,
|
|
208
|
-
args: [{ name: "level", description: "off, on, ask, full" }],
|
|
209
|
-
requiresAuth: true
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
key: "model",
|
|
213
|
-
nativeName: "model",
|
|
214
|
-
description: "Set or show current model",
|
|
215
|
-
textAliases: ["/model", "/m"],
|
|
216
|
-
scope: "both",
|
|
217
|
-
category: "options",
|
|
218
|
-
acceptsArgs: true,
|
|
219
|
-
args: [{ name: "model", description: "provider/model or alias" }]
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
key: "models",
|
|
223
|
-
nativeName: "models",
|
|
224
|
-
description: "List available models",
|
|
225
|
-
textAliases: ["/models"],
|
|
226
|
-
scope: "both",
|
|
227
|
-
category: "options",
|
|
228
|
-
acceptsArgs: false
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
key: "usage",
|
|
232
|
-
nativeName: "usage",
|
|
233
|
-
description: "Show token usage",
|
|
234
|
-
textAliases: ["/usage"],
|
|
235
|
-
scope: "both",
|
|
236
|
-
category: "options",
|
|
237
|
-
acceptsArgs: false
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
key: "queue",
|
|
241
|
-
nativeName: "queue",
|
|
242
|
-
description: "Set queue mode",
|
|
243
|
-
textAliases: ["/queue", "/q"],
|
|
244
|
-
scope: "both",
|
|
245
|
-
category: "options",
|
|
246
|
-
acceptsArgs: true,
|
|
247
|
-
args: [
|
|
248
|
-
{
|
|
249
|
-
name: "mode",
|
|
250
|
-
description: "steer, followup, collect, interrupt, or options"
|
|
251
|
-
}
|
|
252
|
-
]
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
key: "allowlist",
|
|
256
|
-
nativeName: "allowlist",
|
|
257
|
-
description: "Manage sender allowlist",
|
|
258
|
-
textAliases: ["/allowlist", "/allow"],
|
|
259
|
-
scope: "both",
|
|
260
|
-
category: "management",
|
|
261
|
-
acceptsArgs: true,
|
|
262
|
-
args: [
|
|
263
|
-
{ name: "action", description: "list, add, remove" },
|
|
264
|
-
{ name: "value", description: "sender to add/remove" }
|
|
265
|
-
],
|
|
266
|
-
requiresAuth: true
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
key: "approve",
|
|
270
|
-
nativeName: "approve",
|
|
271
|
-
description: "Approve or deny a pending action",
|
|
272
|
-
textAliases: ["/approve"],
|
|
273
|
-
scope: "both",
|
|
274
|
-
category: "management",
|
|
275
|
-
acceptsArgs: true,
|
|
276
|
-
args: [
|
|
277
|
-
{ name: "id", description: "Approval ID", required: true },
|
|
278
|
-
{ name: "action", description: "allow-once, allow-always, deny" }
|
|
279
|
-
],
|
|
280
|
-
requiresAuth: true
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
key: "subagents",
|
|
284
|
-
nativeName: "subagents",
|
|
285
|
-
description: "Manage subagents",
|
|
286
|
-
textAliases: ["/subagents", "/sub"],
|
|
287
|
-
scope: "both",
|
|
288
|
-
category: "management",
|
|
289
|
-
acceptsArgs: true,
|
|
290
|
-
args: [{ name: "action", description: "list, stop, log, info, send" }],
|
|
291
|
-
requiresAuth: true
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
key: "config",
|
|
295
|
-
nativeName: "config",
|
|
296
|
-
description: "View or set configuration",
|
|
297
|
-
textAliases: ["/config", "/cfg"],
|
|
298
|
-
scope: "both",
|
|
299
|
-
category: "management",
|
|
300
|
-
acceptsArgs: true,
|
|
301
|
-
args: [
|
|
302
|
-
{ name: "key", description: "Configuration key" },
|
|
303
|
-
{ name: "value", description: "Value to set" }
|
|
304
|
-
],
|
|
305
|
-
requiresAuth: true,
|
|
306
|
-
enabled: false
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
key: "debug",
|
|
310
|
-
nativeName: "debug",
|
|
311
|
-
description: "Debug information",
|
|
312
|
-
textAliases: ["/debug"],
|
|
313
|
-
scope: "both",
|
|
314
|
-
category: "management",
|
|
315
|
-
acceptsArgs: true,
|
|
316
|
-
requiresAuth: true,
|
|
317
|
-
enabled: false
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
key: "tts",
|
|
321
|
-
nativeName: "tts",
|
|
322
|
-
description: "Text-to-speech settings",
|
|
323
|
-
textAliases: ["/tts", "/voice"],
|
|
324
|
-
scope: "both",
|
|
325
|
-
category: "media",
|
|
326
|
-
acceptsArgs: true,
|
|
327
|
-
args: [
|
|
328
|
-
{
|
|
329
|
-
name: "action",
|
|
330
|
-
description: "on, off, status, provider, limit, audio"
|
|
331
|
-
}
|
|
332
|
-
]
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
key: "bash",
|
|
336
|
-
nativeName: "bash",
|
|
337
|
-
description: "Execute shell command",
|
|
338
|
-
textAliases: ["/bash", "/sh", "/!"],
|
|
339
|
-
scope: "text",
|
|
340
|
-
category: "tools",
|
|
341
|
-
acceptsArgs: true,
|
|
342
|
-
args: [
|
|
343
|
-
{
|
|
344
|
-
name: "command",
|
|
345
|
-
description: "Shell command to execute",
|
|
346
|
-
captureRemaining: true
|
|
347
|
-
}
|
|
348
|
-
],
|
|
349
|
-
requiresAuth: true,
|
|
350
|
-
requiresElevated: true
|
|
351
|
-
}
|
|
352
|
-
];
|
|
353
|
-
var runtimeStores = new Map;
|
|
354
|
-
var fallbackStore = {
|
|
355
|
-
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
356
|
-
aliasMap: null
|
|
357
|
-
};
|
|
358
|
-
var activeStore = fallbackStore;
|
|
359
|
-
function initForRuntime(agentId) {
|
|
360
|
-
const store = {
|
|
361
|
-
commands: DEFAULT_COMMANDS.map((c) => ({ ...c })),
|
|
362
|
-
aliasMap: null
|
|
363
|
-
};
|
|
364
|
-
runtimeStores.set(agentId, store);
|
|
365
|
-
activeStore = store;
|
|
366
|
-
}
|
|
367
|
-
function useRuntime(agentId) {
|
|
368
|
-
const store = runtimeStores.get(agentId);
|
|
369
|
-
if (store) {
|
|
370
|
-
activeStore = store;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function getCommands() {
|
|
374
|
-
return [...activeStore.commands];
|
|
375
|
-
}
|
|
376
|
-
function getEnabledCommands() {
|
|
377
|
-
return activeStore.commands.filter((cmd) => cmd.enabled !== false);
|
|
378
|
-
}
|
|
379
|
-
function getCommandsByCategory(category) {
|
|
380
|
-
return activeStore.commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
|
|
381
|
-
}
|
|
382
|
-
function registerCommand(command) {
|
|
383
|
-
activeStore.commands = activeStore.commands.filter((c) => c.key !== command.key);
|
|
384
|
-
activeStore.commands.push(command);
|
|
385
|
-
activeStore.aliasMap = null;
|
|
386
|
-
}
|
|
387
|
-
function registerCommands(newCommands) {
|
|
388
|
-
for (const command of newCommands) {
|
|
389
|
-
registerCommand(command);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function unregisterCommand(key) {
|
|
393
|
-
activeStore.commands = activeStore.commands.filter((c) => c.key !== key);
|
|
394
|
-
activeStore.aliasMap = null;
|
|
395
|
-
}
|
|
396
|
-
function resetCommands() {
|
|
397
|
-
activeStore.commands = DEFAULT_COMMANDS.map((c) => ({ ...c }));
|
|
398
|
-
activeStore.aliasMap = null;
|
|
399
|
-
}
|
|
400
|
-
function getAliasMap() {
|
|
401
|
-
if (activeStore.aliasMap)
|
|
402
|
-
return activeStore.aliasMap;
|
|
403
|
-
activeStore.aliasMap = new Map;
|
|
404
|
-
for (const command of activeStore.commands) {
|
|
405
|
-
if (command.enabled === false)
|
|
406
|
-
continue;
|
|
407
|
-
for (const alias of command.textAliases) {
|
|
408
|
-
const normalized = alias.toLowerCase().trim();
|
|
409
|
-
if (!activeStore.aliasMap.has(normalized)) {
|
|
410
|
-
activeStore.aliasMap.set(normalized, command);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return activeStore.aliasMap;
|
|
415
|
-
}
|
|
416
|
-
function findCommandByAlias(alias) {
|
|
417
|
-
const map = getAliasMap();
|
|
418
|
-
return map.get(alias.toLowerCase().trim());
|
|
419
|
-
}
|
|
420
|
-
function findCommandByKey(key) {
|
|
421
|
-
return activeStore.commands.find((c) => c.key === key);
|
|
422
|
-
}
|
|
423
|
-
function startsWithCommand(text) {
|
|
424
|
-
const map = getAliasMap();
|
|
425
|
-
const normalized = text.toLowerCase().trim();
|
|
426
|
-
for (const [alias, command] of map) {
|
|
427
|
-
if (normalized === alias) {
|
|
428
|
-
return command;
|
|
429
|
-
}
|
|
430
|
-
if (normalized.startsWith(`${alias} `) || normalized.startsWith(`${alias}:`)) {
|
|
431
|
-
return command;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// src/parser.ts
|
|
438
|
-
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
439
|
-
function hasCommand(text) {
|
|
440
|
-
if (!text)
|
|
441
|
-
return false;
|
|
442
|
-
const trimmed = text.trim();
|
|
443
|
-
if (!trimmed.startsWith("/") && !trimmed.startsWith("!"))
|
|
444
|
-
return false;
|
|
445
|
-
return Boolean(startsWithCommand(trimmed));
|
|
446
|
-
}
|
|
447
|
-
function detectCommand(text) {
|
|
448
|
-
if (!text) {
|
|
449
|
-
return { isCommand: false };
|
|
450
|
-
}
|
|
451
|
-
const trimmed = text.trim();
|
|
452
|
-
if (!trimmed.startsWith("/") && !trimmed.startsWith("!")) {
|
|
453
|
-
return { isCommand: false };
|
|
454
|
-
}
|
|
455
|
-
const command = startsWithCommand(trimmed);
|
|
456
|
-
if (!command) {
|
|
457
|
-
return { isCommand: false };
|
|
458
|
-
}
|
|
459
|
-
const parsed = parseCommand(trimmed, command);
|
|
460
|
-
if (!parsed) {
|
|
461
|
-
return { isCommand: false };
|
|
462
|
-
}
|
|
463
|
-
return { isCommand: true, command: parsed };
|
|
464
|
-
}
|
|
465
|
-
function parseCommand(text, definition) {
|
|
466
|
-
const trimmed = text.trim();
|
|
467
|
-
let matchedAlias = null;
|
|
468
|
-
for (const alias of definition.textAliases) {
|
|
469
|
-
const normalized = alias.toLowerCase();
|
|
470
|
-
if (trimmed.toLowerCase() === normalized) {
|
|
471
|
-
matchedAlias = alias;
|
|
472
|
-
break;
|
|
473
|
-
}
|
|
474
|
-
if (trimmed.toLowerCase().startsWith(`${normalized} `) || trimmed.toLowerCase().startsWith(`${normalized}:`)) {
|
|
475
|
-
matchedAlias = alias;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
if (!matchedAlias) {
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
let rawArgs = trimmed.slice(matchedAlias.length).trim();
|
|
483
|
-
if (rawArgs.startsWith(":")) {
|
|
484
|
-
rawArgs = rawArgs.slice(1).trim();
|
|
485
|
-
}
|
|
486
|
-
const args = parseArgs(rawArgs, definition);
|
|
487
|
-
return {
|
|
488
|
-
key: definition.key,
|
|
489
|
-
canonical: definition.textAliases[0] ?? `/${definition.key}`,
|
|
490
|
-
args,
|
|
491
|
-
rawArgs: rawArgs || undefined
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
function parseArgs(rawArgs, definition) {
|
|
495
|
-
if (!rawArgs || !definition.acceptsArgs) {
|
|
496
|
-
return [];
|
|
497
|
-
}
|
|
498
|
-
const parsing = definition.argsParsing ?? "positional";
|
|
499
|
-
if (parsing === "none") {
|
|
500
|
-
return rawArgs ? [rawArgs] : [];
|
|
501
|
-
}
|
|
502
|
-
const args = [];
|
|
503
|
-
const argDefs = definition.args ?? [];
|
|
504
|
-
const tokens = tokenize(rawArgs);
|
|
505
|
-
for (let i = 0;i < tokens.length; i++) {
|
|
506
|
-
const argDef = argDefs[i];
|
|
507
|
-
if (argDef?.captureRemaining) {
|
|
508
|
-
args.push(tokens.slice(i).join(" "));
|
|
509
|
-
break;
|
|
510
|
-
}
|
|
511
|
-
args.push(tokens[i]);
|
|
512
|
-
}
|
|
513
|
-
return args;
|
|
514
|
-
}
|
|
515
|
-
function tokenize(input) {
|
|
516
|
-
const tokens = [];
|
|
517
|
-
let current = "";
|
|
518
|
-
let inQuote = false;
|
|
519
|
-
let quoteChar = "";
|
|
520
|
-
for (let i = 0;i < input.length; i++) {
|
|
521
|
-
const char = input[i];
|
|
522
|
-
if (inQuote) {
|
|
523
|
-
if (char === quoteChar) {
|
|
524
|
-
inQuote = false;
|
|
525
|
-
if (current) {
|
|
526
|
-
tokens.push(current);
|
|
527
|
-
current = "";
|
|
528
|
-
}
|
|
529
|
-
} else {
|
|
530
|
-
current += char;
|
|
531
|
-
}
|
|
532
|
-
} else if (char === '"' || char === "'") {
|
|
533
|
-
inQuote = true;
|
|
534
|
-
quoteChar = char;
|
|
535
|
-
} else if (/\s/.test(char)) {
|
|
536
|
-
if (current) {
|
|
537
|
-
tokens.push(current);
|
|
538
|
-
current = "";
|
|
539
|
-
}
|
|
540
|
-
} else {
|
|
541
|
-
current += char;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
if (current) {
|
|
545
|
-
tokens.push(current);
|
|
546
|
-
}
|
|
547
|
-
return tokens;
|
|
548
|
-
}
|
|
549
|
-
function normalizeCommandBody(text, botMention) {
|
|
550
|
-
let normalized = text.trim();
|
|
551
|
-
if (botMention) {
|
|
552
|
-
const mentionPattern = new RegExp(`^@${escapeRegExp(botMention)}\\s*`, "i");
|
|
553
|
-
normalized = normalized.replace(mentionPattern, "");
|
|
554
|
-
}
|
|
555
|
-
normalized = normalized.replace(/^(\/\w+):\s*/, "$1 ");
|
|
556
|
-
return normalized.trim();
|
|
557
|
-
}
|
|
558
|
-
function isCommandOnly(text) {
|
|
559
|
-
const detection = detectCommand(text);
|
|
560
|
-
if (!detection.isCommand || !detection.command) {
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
if (!detection.command.rawArgs) {
|
|
564
|
-
return true;
|
|
565
|
-
}
|
|
566
|
-
return detection.command.rawArgs.trim().length === 0;
|
|
567
|
-
}
|
|
568
|
-
function extractCommand(text) {
|
|
569
|
-
const detection = detectCommand(text);
|
|
570
|
-
if (!detection.isCommand || !detection.command) {
|
|
571
|
-
return null;
|
|
572
|
-
}
|
|
573
|
-
const { command } = detection;
|
|
574
|
-
if (!command.rawArgs) {
|
|
575
|
-
return { command, remainingText: "" };
|
|
576
|
-
}
|
|
577
|
-
return { command, remainingText: command.rawArgs };
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// src/index.ts
|
|
581
|
-
var commandRegistryProvider = {
|
|
582
|
-
name: "COMMAND_REGISTRY",
|
|
583
|
-
description: "Available chat commands and their descriptions",
|
|
584
|
-
descriptionCompressed: "Available chat commands and descriptions.",
|
|
585
|
-
dynamic: true,
|
|
586
|
-
contexts: ["general", "automation"],
|
|
587
|
-
contextGate: { anyOf: ["general", "automation"] },
|
|
588
|
-
cacheStable: true,
|
|
589
|
-
cacheScope: "agent",
|
|
590
|
-
async get(runtime, message, _state) {
|
|
591
|
-
useRuntime(runtime.agentId);
|
|
592
|
-
const text = message.content?.text ?? "";
|
|
593
|
-
const isCommand = hasCommand(text);
|
|
594
|
-
const commands = getEnabledCommands();
|
|
595
|
-
if (isCommand) {
|
|
596
|
-
const commandList = commands.map((cmd) => {
|
|
597
|
-
const auth = cmd.requiresAuth ? " (requires auth)" : "";
|
|
598
|
-
return `- ${cmd.textAliases[0]}: ${cmd.description}${auth}`;
|
|
599
|
-
});
|
|
600
|
-
return {
|
|
601
|
-
text: `The user sent a slash command. Available commands:
|
|
602
|
-
${commandList.join(`
|
|
603
|
-
`)}
|
|
604
|
-
|
|
605
|
-
IMPORTANT: This is a slash command — respond by executing the matching command action, not with conversational text.`,
|
|
606
|
-
values: {
|
|
607
|
-
commandCount: commands.length,
|
|
608
|
-
isCommand: true,
|
|
609
|
-
hasElevatedCommands: commands.some((c) => c.requiresElevated)
|
|
610
|
-
},
|
|
611
|
-
data: { commands, isCommand: true }
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
return {
|
|
615
|
-
text: "",
|
|
616
|
-
values: {
|
|
617
|
-
commandCount: commands.length,
|
|
618
|
-
isCommand: false
|
|
619
|
-
},
|
|
620
|
-
data: { isCommand: false }
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
function formatCommandResult(result) {
|
|
625
|
-
if (result.error) {
|
|
626
|
-
return `Error: ${result.error}`;
|
|
627
|
-
}
|
|
628
|
-
return result.reply ?? "Command executed";
|
|
629
|
-
}
|
|
630
|
-
function isAuthorized(context, command) {
|
|
631
|
-
if (!command.requiresAuth) {
|
|
632
|
-
return true;
|
|
633
|
-
}
|
|
634
|
-
return context.isAuthorized;
|
|
635
|
-
}
|
|
636
|
-
function isElevated(context, command) {
|
|
637
|
-
if (!command.requiresElevated) {
|
|
638
|
-
return true;
|
|
639
|
-
}
|
|
640
|
-
return context.isElevated;
|
|
641
|
-
}
|
|
642
|
-
var commandsPlugin = {
|
|
643
|
-
name: "commands",
|
|
644
|
-
description: "Chat command system with /help, /status, /reset, etc.",
|
|
645
|
-
providers: [commandRegistryProvider],
|
|
646
|
-
autoEnable: {
|
|
647
|
-
shouldEnable: (_env, config) => {
|
|
648
|
-
const f = config?.features?.commands;
|
|
649
|
-
return f === true || typeof f === "object" && f !== null && f.enabled !== false;
|
|
650
|
-
}
|
|
651
|
-
},
|
|
652
|
-
config: {
|
|
653
|
-
COMMANDS_ENABLED: "true",
|
|
654
|
-
COMMANDS_CONFIG_ENABLED: "false",
|
|
655
|
-
COMMANDS_DEBUG_ENABLED: "false",
|
|
656
|
-
COMMANDS_BASH_ENABLED: "false",
|
|
657
|
-
COMMANDS_RESTART_ENABLED: "true"
|
|
658
|
-
},
|
|
659
|
-
tests: [
|
|
660
|
-
{
|
|
661
|
-
name: "command-detection",
|
|
662
|
-
tests: [
|
|
663
|
-
{
|
|
664
|
-
name: "Detect command prefix",
|
|
665
|
-
fn: async (_runtime) => {
|
|
666
|
-
if (!hasCommand("/help")) {
|
|
667
|
-
throw new Error("Should detect /help command");
|
|
668
|
-
}
|
|
669
|
-
if (!hasCommand("/status test")) {
|
|
670
|
-
throw new Error("Should detect /status with args");
|
|
671
|
-
}
|
|
672
|
-
if (hasCommand("hello world")) {
|
|
673
|
-
throw new Error("Should not detect plain text as command");
|
|
674
|
-
}
|
|
675
|
-
import_core.logger.success("Command prefix detection works correctly");
|
|
676
|
-
}
|
|
677
|
-
},
|
|
678
|
-
{
|
|
679
|
-
name: "Parse command with args",
|
|
680
|
-
fn: async (_runtime) => {
|
|
681
|
-
const detection = detectCommand("/think:high");
|
|
682
|
-
if (!detection.isCommand) {
|
|
683
|
-
throw new Error("Should detect think command");
|
|
684
|
-
}
|
|
685
|
-
if (detection.command?.key !== "think") {
|
|
686
|
-
throw new Error(`Expected key 'think', got '${detection.command?.key}'`);
|
|
687
|
-
}
|
|
688
|
-
if (detection.command?.args[0] !== "high") {
|
|
689
|
-
throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
|
|
690
|
-
}
|
|
691
|
-
import_core.logger.success("Command argument parsing works correctly");
|
|
692
|
-
}
|
|
693
|
-
},
|
|
694
|
-
{
|
|
695
|
-
name: "Normalize command body",
|
|
696
|
-
fn: async (_runtime) => {
|
|
697
|
-
const normalized1 = normalizeCommandBody("/status: test");
|
|
698
|
-
if (normalized1 !== "/status test") {
|
|
699
|
-
throw new Error(`Expected '/status test', got '${normalized1}'`);
|
|
700
|
-
}
|
|
701
|
-
const normalized2 = normalizeCommandBody("@bot /help", "bot");
|
|
702
|
-
if (normalized2 !== "/help") {
|
|
703
|
-
throw new Error(`Expected '/help', got '${normalized2}'`);
|
|
704
|
-
}
|
|
705
|
-
import_core.logger.success("Command normalization works correctly");
|
|
706
|
-
}
|
|
707
|
-
},
|
|
708
|
-
{
|
|
709
|
-
name: "Find command by alias",
|
|
710
|
-
fn: async (_runtime) => {
|
|
711
|
-
const cmd = findCommandByAlias("/h");
|
|
712
|
-
if (!cmd) {
|
|
713
|
-
throw new Error("Should find help command by /h alias");
|
|
714
|
-
}
|
|
715
|
-
if (cmd.key !== "help") {
|
|
716
|
-
throw new Error(`Expected key 'help', got '${cmd.key}'`);
|
|
717
|
-
}
|
|
718
|
-
import_core.logger.success("Command alias lookup works correctly");
|
|
719
|
-
}
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
name: "Find command by key",
|
|
723
|
-
fn: async (_runtime) => {
|
|
724
|
-
const cmd = findCommandByKey("status");
|
|
725
|
-
if (!cmd) {
|
|
726
|
-
throw new Error("Should find status command by key");
|
|
727
|
-
}
|
|
728
|
-
if (cmd.key !== "status") {
|
|
729
|
-
throw new Error(`Expected key 'status', got '${cmd.key}'`);
|
|
730
|
-
}
|
|
731
|
-
import_core.logger.success("Command key lookup works correctly");
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
]
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
name: "command-registry",
|
|
738
|
-
tests: [
|
|
739
|
-
{
|
|
740
|
-
name: "Get enabled commands",
|
|
741
|
-
fn: async (_runtime) => {
|
|
742
|
-
const commands = getEnabledCommands();
|
|
743
|
-
if (commands.length === 0) {
|
|
744
|
-
throw new Error("Should have enabled commands");
|
|
745
|
-
}
|
|
746
|
-
const cmdHelp = commands.some((c) => c.key === "help");
|
|
747
|
-
const cmdStatus = commands.some((c) => c.key === "status");
|
|
748
|
-
if (!cmdHelp || !cmdStatus) {
|
|
749
|
-
throw new Error("Should have help and status commands");
|
|
750
|
-
}
|
|
751
|
-
import_core.logger.success("Command registry works correctly");
|
|
752
|
-
}
|
|
753
|
-
},
|
|
754
|
-
{
|
|
755
|
-
name: "Register custom command",
|
|
756
|
-
fn: async (_runtime) => {
|
|
757
|
-
const customCmd = {
|
|
758
|
-
key: "test-custom",
|
|
759
|
-
description: "Test custom command",
|
|
760
|
-
textAliases: ["/test-custom", "/tc"],
|
|
761
|
-
scope: "text"
|
|
762
|
-
};
|
|
763
|
-
registerCommand(customCmd);
|
|
764
|
-
const found = findCommandByKey("test-custom");
|
|
765
|
-
if (!found) {
|
|
766
|
-
throw new Error("Should find registered custom command");
|
|
767
|
-
}
|
|
768
|
-
unregisterCommand("test-custom");
|
|
769
|
-
const notFound = findCommandByKey("test-custom");
|
|
770
|
-
if (notFound) {
|
|
771
|
-
throw new Error("Should not find unregistered command");
|
|
772
|
-
}
|
|
773
|
-
import_core.logger.success("Custom command registration works correctly");
|
|
774
|
-
}
|
|
775
|
-
},
|
|
776
|
-
{
|
|
777
|
-
name: "Get commands by category",
|
|
778
|
-
fn: async (_runtime) => {
|
|
779
|
-
const statusCommands = getCommandsByCategory("status");
|
|
780
|
-
if (statusCommands.length === 0) {
|
|
781
|
-
throw new Error("Should have status category commands");
|
|
782
|
-
}
|
|
783
|
-
const allStatus = statusCommands.every((c) => c.category === "status");
|
|
784
|
-
if (!allStatus) {
|
|
785
|
-
throw new Error("All returned commands should be in status category");
|
|
786
|
-
}
|
|
787
|
-
import_core.logger.success("Command categorization works correctly");
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
]
|
|
791
|
-
}
|
|
792
|
-
],
|
|
793
|
-
async init(config, runtime) {
|
|
794
|
-
import_core.logger.log("[plugin-commands] Initializing command system");
|
|
795
|
-
initForRuntime(runtime.agentId);
|
|
796
|
-
const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
|
|
797
|
-
const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
|
|
798
|
-
const bashEnabled = config.COMMANDS_BASH_ENABLED === "true";
|
|
799
|
-
const restartEnabled = config.COMMANDS_RESTART_ENABLED !== "false";
|
|
800
|
-
const configCmd = findCommandByKey("config");
|
|
801
|
-
if (configCmd) {
|
|
802
|
-
configCmd.enabled = configEnabled;
|
|
803
|
-
}
|
|
804
|
-
const debugCmd = findCommandByKey("debug");
|
|
805
|
-
if (debugCmd) {
|
|
806
|
-
debugCmd.enabled = debugEnabled;
|
|
807
|
-
}
|
|
808
|
-
const bashCmd = findCommandByKey("bash");
|
|
809
|
-
if (bashCmd) {
|
|
810
|
-
bashCmd.enabled = bashEnabled;
|
|
811
|
-
}
|
|
812
|
-
const restartCmd = findCommandByKey("restart");
|
|
813
|
-
if (restartCmd) {
|
|
814
|
-
restartCmd.enabled = restartEnabled;
|
|
815
|
-
}
|
|
816
|
-
const enabledCount = getEnabledCommands().length;
|
|
817
|
-
import_core.logger.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
var src_default = commandsPlugin;
|
|
821
|
-
|
|
822
|
-
//# debugId=00FC26667A6E870A64756E2164756E21
|