@elizaos/plugin-directives 1.0.0
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 +696 -0
- package/dist/cjs/index.cjs.map +11 -0
- package/dist/index.js +668 -0
- package/dist/index.js.map +11 -0
- package/package.json +89 -0
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var exports_src = {};
|
|
31
|
+
__export(exports_src, {
|
|
32
|
+
setDirectiveState: () => setDirectiveState,
|
|
33
|
+
parseDirectives: () => parseDirectives,
|
|
34
|
+
normalizeVerboseLevel: () => normalizeVerboseLevel,
|
|
35
|
+
normalizeThinkLevel: () => normalizeThinkLevel,
|
|
36
|
+
normalizeReasoningLevel: () => normalizeReasoningLevel,
|
|
37
|
+
normalizeExecSecurity: () => normalizeExecSecurity,
|
|
38
|
+
normalizeExecHost: () => normalizeExecHost,
|
|
39
|
+
normalizeExecAsk: () => normalizeExecAsk,
|
|
40
|
+
normalizeElevatedLevel: () => normalizeElevatedLevel,
|
|
41
|
+
getDirectiveState: () => getDirectiveState,
|
|
42
|
+
formatDirectiveState: () => formatDirectiveState,
|
|
43
|
+
formatDirectiveAcknowledgment: () => formatDirectiveAcknowledgment,
|
|
44
|
+
extractVerboseDirective: () => extractVerboseDirective,
|
|
45
|
+
extractThinkDirective: () => extractThinkDirective,
|
|
46
|
+
extractStatusDirective: () => extractStatusDirective,
|
|
47
|
+
extractReasoningDirective: () => extractReasoningDirective,
|
|
48
|
+
extractModelDirective: () => extractModelDirective,
|
|
49
|
+
extractExecDirective: () => extractExecDirective,
|
|
50
|
+
extractElevatedDirective: () => extractElevatedDirective,
|
|
51
|
+
directivesPlugin: () => directivesPlugin,
|
|
52
|
+
directiveStateProvider: () => directiveStateProvider,
|
|
53
|
+
default: () => src_default,
|
|
54
|
+
clearDirectiveState: () => clearDirectiveState,
|
|
55
|
+
applyDirectives: () => applyDirectives
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(exports_src);
|
|
58
|
+
var import_core = require("@elizaos/core");
|
|
59
|
+
|
|
60
|
+
// src/parsers.ts
|
|
61
|
+
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
62
|
+
function matchLevelDirective(body, names) {
|
|
63
|
+
const namePattern = names.map(escapeRegExp).join("|");
|
|
64
|
+
const match = body.match(new RegExp(`(?:^|\\s)\\/(?:${namePattern})(?=$|\\s|:)`, "i"));
|
|
65
|
+
if (!match || match.index === undefined) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const start = match.index;
|
|
69
|
+
let end = match.index + match[0].length;
|
|
70
|
+
let i = end;
|
|
71
|
+
while (i < body.length && /\s/.test(body[i])) {
|
|
72
|
+
i += 1;
|
|
73
|
+
}
|
|
74
|
+
if (body[i] === ":") {
|
|
75
|
+
i += 1;
|
|
76
|
+
while (i < body.length && /\s/.test(body[i])) {
|
|
77
|
+
i += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const argStart = i;
|
|
81
|
+
while (i < body.length && /[A-Za-z0-9-]/.test(body[i])) {
|
|
82
|
+
i += 1;
|
|
83
|
+
}
|
|
84
|
+
const rawLevel = i > argStart ? body.slice(argStart, i) : undefined;
|
|
85
|
+
end = i;
|
|
86
|
+
return { start, end, rawLevel };
|
|
87
|
+
}
|
|
88
|
+
function extractLevelDirective(body, names, normalize) {
|
|
89
|
+
const match = matchLevelDirective(body, names);
|
|
90
|
+
if (!match) {
|
|
91
|
+
return { cleaned: body.trim(), hasDirective: false };
|
|
92
|
+
}
|
|
93
|
+
const rawLevel = match.rawLevel;
|
|
94
|
+
const level = normalize(rawLevel);
|
|
95
|
+
const cleaned = body.slice(0, match.start).concat(" ").concat(body.slice(match.end)).replace(/\s+/g, " ").trim();
|
|
96
|
+
return {
|
|
97
|
+
cleaned,
|
|
98
|
+
level,
|
|
99
|
+
rawLevel,
|
|
100
|
+
hasDirective: true
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function extractSimpleDirective(body, names) {
|
|
104
|
+
const namePattern = names.map(escapeRegExp).join("|");
|
|
105
|
+
const match = body.match(new RegExp(`(?:^|\\s)\\/(?:${namePattern})(?=$|\\s|:)(?:\\s*:\\s*)?`, "i"));
|
|
106
|
+
const cleaned = match ? body.replace(match[0], " ").replace(/\s+/g, " ").trim() : body.trim();
|
|
107
|
+
return {
|
|
108
|
+
cleaned,
|
|
109
|
+
hasDirective: Boolean(match)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function normalizeThinkLevel(raw) {
|
|
113
|
+
if (!raw)
|
|
114
|
+
return;
|
|
115
|
+
const key = raw.toLowerCase();
|
|
116
|
+
if (["off"].includes(key))
|
|
117
|
+
return "off";
|
|
118
|
+
if (["on", "enable", "enabled"].includes(key))
|
|
119
|
+
return "low";
|
|
120
|
+
if (["min", "minimal"].includes(key))
|
|
121
|
+
return "minimal";
|
|
122
|
+
if (["low", "thinkhard", "think-hard", "think_hard"].includes(key))
|
|
123
|
+
return "low";
|
|
124
|
+
if (["mid", "med", "medium", "thinkharder", "think-harder", "harder"].includes(key))
|
|
125
|
+
return "medium";
|
|
126
|
+
if ([
|
|
127
|
+
"high",
|
|
128
|
+
"ultra",
|
|
129
|
+
"ultrathink",
|
|
130
|
+
"think-hard",
|
|
131
|
+
"thinkhardest",
|
|
132
|
+
"highest",
|
|
133
|
+
"max"
|
|
134
|
+
].includes(key))
|
|
135
|
+
return "high";
|
|
136
|
+
if (["xhigh", "x-high", "x_high"].includes(key))
|
|
137
|
+
return "xhigh";
|
|
138
|
+
if (["think"].includes(key))
|
|
139
|
+
return "minimal";
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
function normalizeVerboseLevel(raw) {
|
|
143
|
+
if (!raw)
|
|
144
|
+
return;
|
|
145
|
+
const key = raw.toLowerCase();
|
|
146
|
+
if (["off", "false", "no", "0"].includes(key))
|
|
147
|
+
return "off";
|
|
148
|
+
if (["full", "all", "everything"].includes(key))
|
|
149
|
+
return "full";
|
|
150
|
+
if (["on", "minimal", "true", "yes", "1"].includes(key))
|
|
151
|
+
return "on";
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
function normalizeReasoningLevel(raw) {
|
|
155
|
+
if (!raw)
|
|
156
|
+
return;
|
|
157
|
+
const key = raw.toLowerCase();
|
|
158
|
+
if ([
|
|
159
|
+
"off",
|
|
160
|
+
"false",
|
|
161
|
+
"no",
|
|
162
|
+
"0",
|
|
163
|
+
"hide",
|
|
164
|
+
"hidden",
|
|
165
|
+
"disable",
|
|
166
|
+
"disabled"
|
|
167
|
+
].includes(key))
|
|
168
|
+
return "off";
|
|
169
|
+
if (["on", "true", "yes", "1", "show", "visible", "enable", "enabled"].includes(key))
|
|
170
|
+
return "on";
|
|
171
|
+
if (["stream", "streaming", "draft", "live"].includes(key))
|
|
172
|
+
return "stream";
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
function normalizeElevatedLevel(raw) {
|
|
176
|
+
if (!raw)
|
|
177
|
+
return;
|
|
178
|
+
const key = raw.toLowerCase();
|
|
179
|
+
if (["off", "false", "no", "0"].includes(key))
|
|
180
|
+
return "off";
|
|
181
|
+
if (["full", "auto", "auto-approve", "autoapprove"].includes(key))
|
|
182
|
+
return "full";
|
|
183
|
+
if (["ask", "prompt", "approval", "approve"].includes(key))
|
|
184
|
+
return "ask";
|
|
185
|
+
if (["on", "true", "yes", "1"].includes(key))
|
|
186
|
+
return "on";
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
function normalizeExecHost(raw) {
|
|
190
|
+
if (!raw)
|
|
191
|
+
return;
|
|
192
|
+
const key = raw.toLowerCase();
|
|
193
|
+
if (["sandbox", "sb"].includes(key))
|
|
194
|
+
return "sandbox";
|
|
195
|
+
if (["gateway", "gw", "local"].includes(key))
|
|
196
|
+
return "gateway";
|
|
197
|
+
if (["node", "remote"].includes(key))
|
|
198
|
+
return "node";
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
function normalizeExecSecurity(raw) {
|
|
202
|
+
if (!raw)
|
|
203
|
+
return;
|
|
204
|
+
const key = raw.toLowerCase();
|
|
205
|
+
if (["deny", "none", "off"].includes(key))
|
|
206
|
+
return "deny";
|
|
207
|
+
if (["allowlist", "allow", "list"].includes(key))
|
|
208
|
+
return "allowlist";
|
|
209
|
+
if (["full", "all", "any"].includes(key))
|
|
210
|
+
return "full";
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
function normalizeExecAsk(raw) {
|
|
214
|
+
if (!raw)
|
|
215
|
+
return;
|
|
216
|
+
const key = raw.toLowerCase();
|
|
217
|
+
if (["off", "never", "no"].includes(key))
|
|
218
|
+
return "off";
|
|
219
|
+
if (["on-miss", "miss", "fallback"].includes(key))
|
|
220
|
+
return "on-miss";
|
|
221
|
+
if (["always", "on", "yes"].includes(key))
|
|
222
|
+
return "always";
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
function extractThinkDirective(body) {
|
|
226
|
+
if (!body)
|
|
227
|
+
return { cleaned: "", hasDirective: false };
|
|
228
|
+
const extracted = extractLevelDirective(body, ["thinking", "think", "t"], normalizeThinkLevel);
|
|
229
|
+
return {
|
|
230
|
+
cleaned: extracted.cleaned,
|
|
231
|
+
thinkLevel: extracted.level,
|
|
232
|
+
rawLevel: extracted.rawLevel,
|
|
233
|
+
hasDirective: extracted.hasDirective
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function extractVerboseDirective(body) {
|
|
237
|
+
if (!body)
|
|
238
|
+
return { cleaned: "", hasDirective: false };
|
|
239
|
+
const extracted = extractLevelDirective(body, ["verbose", "v"], normalizeVerboseLevel);
|
|
240
|
+
return {
|
|
241
|
+
cleaned: extracted.cleaned,
|
|
242
|
+
verboseLevel: extracted.level,
|
|
243
|
+
rawLevel: extracted.rawLevel,
|
|
244
|
+
hasDirective: extracted.hasDirective
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function extractReasoningDirective(body) {
|
|
248
|
+
if (!body)
|
|
249
|
+
return { cleaned: "", hasDirective: false };
|
|
250
|
+
const extracted = extractLevelDirective(body, ["reasoning", "reason"], normalizeReasoningLevel);
|
|
251
|
+
return {
|
|
252
|
+
cleaned: extracted.cleaned,
|
|
253
|
+
reasoningLevel: extracted.level,
|
|
254
|
+
rawLevel: extracted.rawLevel,
|
|
255
|
+
hasDirective: extracted.hasDirective
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function extractElevatedDirective(body) {
|
|
259
|
+
if (!body)
|
|
260
|
+
return { cleaned: "", hasDirective: false };
|
|
261
|
+
const extracted = extractLevelDirective(body, ["elevated", "elev"], normalizeElevatedLevel);
|
|
262
|
+
return {
|
|
263
|
+
cleaned: extracted.cleaned,
|
|
264
|
+
elevatedLevel: extracted.level,
|
|
265
|
+
rawLevel: extracted.rawLevel,
|
|
266
|
+
hasDirective: extracted.hasDirective
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function extractStatusDirective(body) {
|
|
270
|
+
if (!body)
|
|
271
|
+
return { cleaned: "", hasDirective: false };
|
|
272
|
+
return extractSimpleDirective(body, ["status"]);
|
|
273
|
+
}
|
|
274
|
+
function extractModelDirective(body, options) {
|
|
275
|
+
if (!body)
|
|
276
|
+
return { cleaned: "", hasDirective: false };
|
|
277
|
+
const modelMatch = body.match(/(?:^|\s)\/model(?:\s*:\s*|\s+)([a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9._-]+)?(?:@[a-zA-Z0-9_-]+)?)/i);
|
|
278
|
+
if (modelMatch) {
|
|
279
|
+
const fullMatch = modelMatch[1];
|
|
280
|
+
const atIndex = fullMatch.indexOf("@");
|
|
281
|
+
const rawModel = atIndex >= 0 ? fullMatch.slice(0, atIndex) : fullMatch;
|
|
282
|
+
const rawProfile = atIndex >= 0 ? fullMatch.slice(atIndex + 1) : undefined;
|
|
283
|
+
const cleaned = body.replace(modelMatch[0], " ").replace(/\s+/g, " ").trim();
|
|
284
|
+
return { cleaned, rawModel, rawProfile, hasDirective: true };
|
|
285
|
+
}
|
|
286
|
+
const simpleMatch = body.match(/(?:^|\s)\/model(?=$|\s|:)/i);
|
|
287
|
+
if (simpleMatch) {
|
|
288
|
+
const cleaned = body.replace(simpleMatch[0], " ").replace(/\s+/g, " ").trim();
|
|
289
|
+
return { cleaned, hasDirective: true };
|
|
290
|
+
}
|
|
291
|
+
if (options?.aliases?.length) {
|
|
292
|
+
for (const alias of options.aliases) {
|
|
293
|
+
const aliasPattern = new RegExp(`(?:^|\\s)/${escapeRegExp(alias)}(?=$|\\s)`, "i");
|
|
294
|
+
const aliasMatch = body.match(aliasPattern);
|
|
295
|
+
if (aliasMatch) {
|
|
296
|
+
const cleaned = body.replace(aliasMatch[0], " ").replace(/\s+/g, " ").trim();
|
|
297
|
+
return { cleaned, rawModel: alias, hasDirective: true };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { cleaned: body.trim(), hasDirective: false };
|
|
302
|
+
}
|
|
303
|
+
function extractExecDirective(body) {
|
|
304
|
+
if (!body) {
|
|
305
|
+
return {
|
|
306
|
+
cleaned: "",
|
|
307
|
+
hasExecOptions: false,
|
|
308
|
+
invalidHost: false,
|
|
309
|
+
invalidSecurity: false,
|
|
310
|
+
invalidAsk: false,
|
|
311
|
+
invalidNode: false,
|
|
312
|
+
hasDirective: false
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
const execMatch = body.match(/(?:^|\s)\/exec(?:\s+([^\/\n]+))?(?=$|\s|\/)/i);
|
|
316
|
+
if (!execMatch) {
|
|
317
|
+
return {
|
|
318
|
+
cleaned: body.trim(),
|
|
319
|
+
hasExecOptions: false,
|
|
320
|
+
invalidHost: false,
|
|
321
|
+
invalidSecurity: false,
|
|
322
|
+
invalidAsk: false,
|
|
323
|
+
invalidNode: false,
|
|
324
|
+
hasDirective: false
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const args = execMatch[1]?.trim() ?? "";
|
|
328
|
+
const cleaned = body.replace(execMatch[0], " ").replace(/\s+/g, " ").trim();
|
|
329
|
+
let rawExecHost;
|
|
330
|
+
let rawExecSecurity;
|
|
331
|
+
let rawExecAsk;
|
|
332
|
+
let rawExecNode;
|
|
333
|
+
const kvPattern = /(\w+)\s*=\s*([^\s]+)/g;
|
|
334
|
+
let match;
|
|
335
|
+
while ((match = kvPattern.exec(args)) !== null) {
|
|
336
|
+
const key = match[1].toLowerCase();
|
|
337
|
+
const value = match[2];
|
|
338
|
+
if (key === "host")
|
|
339
|
+
rawExecHost = value;
|
|
340
|
+
else if (key === "security")
|
|
341
|
+
rawExecSecurity = value;
|
|
342
|
+
else if (key === "ask")
|
|
343
|
+
rawExecAsk = value;
|
|
344
|
+
else if (key === "node")
|
|
345
|
+
rawExecNode = value;
|
|
346
|
+
}
|
|
347
|
+
const execHost = normalizeExecHost(rawExecHost);
|
|
348
|
+
const execSecurity = normalizeExecSecurity(rawExecSecurity);
|
|
349
|
+
const execAsk = normalizeExecAsk(rawExecAsk);
|
|
350
|
+
return {
|
|
351
|
+
cleaned,
|
|
352
|
+
execHost,
|
|
353
|
+
execSecurity,
|
|
354
|
+
execAsk,
|
|
355
|
+
execNode: rawExecNode,
|
|
356
|
+
rawExecHost,
|
|
357
|
+
rawExecSecurity,
|
|
358
|
+
rawExecAsk,
|
|
359
|
+
rawExecNode,
|
|
360
|
+
hasExecOptions: Boolean(rawExecHost || rawExecSecurity || rawExecAsk || rawExecNode),
|
|
361
|
+
invalidHost: Boolean(rawExecHost && !execHost),
|
|
362
|
+
invalidSecurity: Boolean(rawExecSecurity && !execSecurity),
|
|
363
|
+
invalidAsk: Boolean(rawExecAsk && !execAsk),
|
|
364
|
+
invalidNode: false,
|
|
365
|
+
hasDirective: true
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/index.ts
|
|
370
|
+
var sessionStates = new Map;
|
|
371
|
+
function getDefaultState() {
|
|
372
|
+
return {
|
|
373
|
+
thinking: "low",
|
|
374
|
+
verbose: "off",
|
|
375
|
+
reasoning: "off",
|
|
376
|
+
elevated: "off",
|
|
377
|
+
exec: {},
|
|
378
|
+
model: {}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function getDirectiveState(roomId) {
|
|
382
|
+
return sessionStates.get(roomId) ?? getDefaultState();
|
|
383
|
+
}
|
|
384
|
+
function setDirectiveState(roomId, state) {
|
|
385
|
+
sessionStates.set(roomId, state);
|
|
386
|
+
}
|
|
387
|
+
function clearDirectiveState(roomId) {
|
|
388
|
+
sessionStates.delete(roomId);
|
|
389
|
+
}
|
|
390
|
+
function parseDirectives(body, options) {
|
|
391
|
+
const {
|
|
392
|
+
cleaned: thinkCleaned,
|
|
393
|
+
thinkLevel,
|
|
394
|
+
rawLevel: rawThinkLevel,
|
|
395
|
+
hasDirective: hasThinkDirective
|
|
396
|
+
} = extractThinkDirective(body);
|
|
397
|
+
const {
|
|
398
|
+
cleaned: verboseCleaned,
|
|
399
|
+
verboseLevel,
|
|
400
|
+
rawLevel: rawVerboseLevel,
|
|
401
|
+
hasDirective: hasVerboseDirective
|
|
402
|
+
} = extractVerboseDirective(thinkCleaned);
|
|
403
|
+
const {
|
|
404
|
+
cleaned: reasoningCleaned,
|
|
405
|
+
reasoningLevel,
|
|
406
|
+
rawLevel: rawReasoningLevel,
|
|
407
|
+
hasDirective: hasReasoningDirective
|
|
408
|
+
} = extractReasoningDirective(verboseCleaned);
|
|
409
|
+
const {
|
|
410
|
+
cleaned: elevatedCleaned,
|
|
411
|
+
elevatedLevel,
|
|
412
|
+
rawLevel: rawElevatedLevel,
|
|
413
|
+
hasDirective: hasElevatedDirective
|
|
414
|
+
} = options?.disableElevated ? {
|
|
415
|
+
cleaned: reasoningCleaned,
|
|
416
|
+
elevatedLevel: undefined,
|
|
417
|
+
rawLevel: undefined,
|
|
418
|
+
hasDirective: false
|
|
419
|
+
} : extractElevatedDirective(reasoningCleaned);
|
|
420
|
+
const {
|
|
421
|
+
cleaned: execCleaned,
|
|
422
|
+
execHost,
|
|
423
|
+
execSecurity,
|
|
424
|
+
execAsk,
|
|
425
|
+
execNode,
|
|
426
|
+
rawExecHost,
|
|
427
|
+
rawExecSecurity,
|
|
428
|
+
rawExecAsk,
|
|
429
|
+
rawExecNode,
|
|
430
|
+
hasExecOptions,
|
|
431
|
+
invalidHost: invalidExecHost,
|
|
432
|
+
invalidSecurity: invalidExecSecurity,
|
|
433
|
+
invalidAsk: invalidExecAsk,
|
|
434
|
+
invalidNode: invalidExecNode,
|
|
435
|
+
hasDirective: hasExecDirective
|
|
436
|
+
} = extractExecDirective(elevatedCleaned);
|
|
437
|
+
const allowStatusDirective = options?.allowStatusDirective !== false;
|
|
438
|
+
const { cleaned: statusCleaned, hasDirective: hasStatusDirective } = allowStatusDirective ? extractStatusDirective(execCleaned) : { cleaned: execCleaned, hasDirective: false };
|
|
439
|
+
const {
|
|
440
|
+
cleaned: modelCleaned,
|
|
441
|
+
rawModel,
|
|
442
|
+
rawProfile,
|
|
443
|
+
hasDirective: hasModelDirective
|
|
444
|
+
} = extractModelDirective(statusCleaned, {
|
|
445
|
+
aliases: options?.modelAliases
|
|
446
|
+
});
|
|
447
|
+
const hasAnyDirective = hasThinkDirective || hasVerboseDirective || hasReasoningDirective || hasElevatedDirective || hasExecDirective || hasModelDirective;
|
|
448
|
+
const directivesOnly = hasAnyDirective && modelCleaned.trim().length === 0;
|
|
449
|
+
return {
|
|
450
|
+
cleanedText: modelCleaned,
|
|
451
|
+
directivesOnly,
|
|
452
|
+
hasThinkDirective,
|
|
453
|
+
thinkLevel,
|
|
454
|
+
rawThinkLevel,
|
|
455
|
+
hasVerboseDirective,
|
|
456
|
+
verboseLevel,
|
|
457
|
+
rawVerboseLevel,
|
|
458
|
+
hasReasoningDirective,
|
|
459
|
+
reasoningLevel,
|
|
460
|
+
rawReasoningLevel,
|
|
461
|
+
hasElevatedDirective,
|
|
462
|
+
elevatedLevel,
|
|
463
|
+
rawElevatedLevel,
|
|
464
|
+
hasExecDirective,
|
|
465
|
+
execHost,
|
|
466
|
+
execSecurity,
|
|
467
|
+
execAsk,
|
|
468
|
+
execNode,
|
|
469
|
+
rawExecHost,
|
|
470
|
+
rawExecSecurity,
|
|
471
|
+
rawExecAsk,
|
|
472
|
+
rawExecNode,
|
|
473
|
+
hasExecOptions,
|
|
474
|
+
invalidExecHost,
|
|
475
|
+
invalidExecSecurity,
|
|
476
|
+
invalidExecAsk,
|
|
477
|
+
invalidExecNode,
|
|
478
|
+
hasStatusDirective,
|
|
479
|
+
hasModelDirective,
|
|
480
|
+
rawModelDirective: rawModel,
|
|
481
|
+
rawModelProfile: rawProfile
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function applyDirectives(roomId, directives, persist = true) {
|
|
485
|
+
const current = getDirectiveState(roomId);
|
|
486
|
+
const updated = { ...current };
|
|
487
|
+
if (directives.hasThinkDirective && directives.thinkLevel) {
|
|
488
|
+
updated.thinking = directives.thinkLevel;
|
|
489
|
+
}
|
|
490
|
+
if (directives.hasVerboseDirective && directives.verboseLevel) {
|
|
491
|
+
updated.verbose = directives.verboseLevel;
|
|
492
|
+
}
|
|
493
|
+
if (directives.hasReasoningDirective && directives.reasoningLevel) {
|
|
494
|
+
updated.reasoning = directives.reasoningLevel;
|
|
495
|
+
}
|
|
496
|
+
if (directives.hasElevatedDirective && directives.elevatedLevel) {
|
|
497
|
+
updated.elevated = directives.elevatedLevel;
|
|
498
|
+
}
|
|
499
|
+
if (directives.hasExecDirective) {
|
|
500
|
+
updated.exec = {
|
|
501
|
+
...updated.exec,
|
|
502
|
+
...directives.execHost && { host: directives.execHost },
|
|
503
|
+
...directives.execSecurity && { security: directives.execSecurity },
|
|
504
|
+
...directives.execAsk && { ask: directives.execAsk },
|
|
505
|
+
...directives.execNode && { node: directives.execNode }
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
if (directives.hasModelDirective && directives.rawModelDirective) {
|
|
509
|
+
const parts = directives.rawModelDirective.split("/");
|
|
510
|
+
if (parts.length === 2) {
|
|
511
|
+
updated.model = {
|
|
512
|
+
provider: parts[0],
|
|
513
|
+
model: parts[1],
|
|
514
|
+
authProfile: directives.rawModelProfile
|
|
515
|
+
};
|
|
516
|
+
} else {
|
|
517
|
+
updated.model = {
|
|
518
|
+
model: directives.rawModelDirective,
|
|
519
|
+
authProfile: directives.rawModelProfile
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (persist) {
|
|
524
|
+
setDirectiveState(roomId, updated);
|
|
525
|
+
}
|
|
526
|
+
return updated;
|
|
527
|
+
}
|
|
528
|
+
function formatDirectiveState(state) {
|
|
529
|
+
const lines = [];
|
|
530
|
+
lines.push(`Thinking: ${state.thinking}`);
|
|
531
|
+
lines.push(`Verbose: ${state.verbose}`);
|
|
532
|
+
lines.push(`Reasoning: ${state.reasoning}`);
|
|
533
|
+
lines.push(`Elevated: ${state.elevated}`);
|
|
534
|
+
if (state.model.provider || state.model.model) {
|
|
535
|
+
const modelStr = state.model.provider ? `${state.model.provider}/${state.model.model}` : state.model.model;
|
|
536
|
+
lines.push(`Model: ${modelStr}${state.model.authProfile ? ` @${state.model.authProfile}` : ""}`);
|
|
537
|
+
}
|
|
538
|
+
return lines.join(`
|
|
539
|
+
`);
|
|
540
|
+
}
|
|
541
|
+
function formatDirectiveAcknowledgment(directives) {
|
|
542
|
+
const changes = [];
|
|
543
|
+
if (directives.hasThinkDirective) {
|
|
544
|
+
changes.push(`Thinking: ${directives.thinkLevel ?? "status"}`);
|
|
545
|
+
}
|
|
546
|
+
if (directives.hasVerboseDirective) {
|
|
547
|
+
changes.push(`Verbose: ${directives.verboseLevel ?? "status"}`);
|
|
548
|
+
}
|
|
549
|
+
if (directives.hasReasoningDirective) {
|
|
550
|
+
changes.push(`Reasoning: ${directives.reasoningLevel ?? "status"}`);
|
|
551
|
+
}
|
|
552
|
+
if (directives.hasElevatedDirective) {
|
|
553
|
+
changes.push(`Elevated: ${directives.elevatedLevel ?? "status"}`);
|
|
554
|
+
}
|
|
555
|
+
if (directives.hasModelDirective) {
|
|
556
|
+
changes.push(`Model: ${directives.rawModelDirective ?? "status"}`);
|
|
557
|
+
}
|
|
558
|
+
return changes.length > 0 ? `✓ ${changes.join(", ")}` : "No changes applied";
|
|
559
|
+
}
|
|
560
|
+
var directiveStateProvider = {
|
|
561
|
+
name: "DIRECTIVE_STATE",
|
|
562
|
+
description: "Current directive levels (thinking, verbose, model, etc.)",
|
|
563
|
+
async get(runtime, message, _state) {
|
|
564
|
+
const roomId = message.roomId;
|
|
565
|
+
const directives = getDirectiveState(roomId);
|
|
566
|
+
return {
|
|
567
|
+
text: formatDirectiveState(directives),
|
|
568
|
+
values: {
|
|
569
|
+
thinkingLevel: directives.thinking,
|
|
570
|
+
verboseLevel: directives.verbose,
|
|
571
|
+
reasoningLevel: directives.reasoning,
|
|
572
|
+
elevatedLevel: directives.elevated,
|
|
573
|
+
modelProvider: directives.model.provider ?? "",
|
|
574
|
+
modelName: directives.model.model ?? "",
|
|
575
|
+
isElevated: directives.elevated !== "off"
|
|
576
|
+
},
|
|
577
|
+
data: { directives }
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
var directivesPlugin = {
|
|
582
|
+
name: "directives",
|
|
583
|
+
description: "Inline directive parsing (@think, @model, @verbose, etc.) for controlling agent behavior",
|
|
584
|
+
providers: [directiveStateProvider],
|
|
585
|
+
config: {
|
|
586
|
+
DEFAULT_THINKING: "low",
|
|
587
|
+
DEFAULT_VERBOSE: "off",
|
|
588
|
+
ALLOW_ELEVATED: "true",
|
|
589
|
+
ALLOW_EXEC: "false"
|
|
590
|
+
},
|
|
591
|
+
tests: [
|
|
592
|
+
{
|
|
593
|
+
name: "directive-parsing",
|
|
594
|
+
tests: [
|
|
595
|
+
{
|
|
596
|
+
name: "Parse think directive",
|
|
597
|
+
fn: async (_runtime) => {
|
|
598
|
+
const result = parseDirectives("/think:high hello world");
|
|
599
|
+
if (!result.hasThinkDirective) {
|
|
600
|
+
throw new Error("Should detect think directive");
|
|
601
|
+
}
|
|
602
|
+
if (result.thinkLevel !== "high") {
|
|
603
|
+
throw new Error(`Expected 'high', got '${result.thinkLevel}'`);
|
|
604
|
+
}
|
|
605
|
+
if (result.cleanedText !== "hello world") {
|
|
606
|
+
throw new Error(`Expected 'hello world', got '${result.cleanedText}'`);
|
|
607
|
+
}
|
|
608
|
+
import_core.logger.success("Think directive parsed correctly");
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
name: "Parse verbose directive",
|
|
613
|
+
fn: async (_runtime) => {
|
|
614
|
+
const result = parseDirectives("/v on test message");
|
|
615
|
+
if (!result.hasVerboseDirective) {
|
|
616
|
+
throw new Error("Should detect verbose directive");
|
|
617
|
+
}
|
|
618
|
+
if (result.verboseLevel !== "on") {
|
|
619
|
+
throw new Error(`Expected 'on', got '${result.verboseLevel}'`);
|
|
620
|
+
}
|
|
621
|
+
import_core.logger.success("Verbose directive parsed correctly");
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
name: "Parse model directive",
|
|
626
|
+
fn: async (_runtime) => {
|
|
627
|
+
const result = parseDirectives("/model anthropic/claude-3-opus what is 2+2");
|
|
628
|
+
if (!result.hasModelDirective) {
|
|
629
|
+
throw new Error("Should detect model directive");
|
|
630
|
+
}
|
|
631
|
+
if (result.rawModelDirective !== "anthropic/claude-3-opus") {
|
|
632
|
+
throw new Error(`Expected 'anthropic/claude-3-opus', got '${result.rawModelDirective}'`);
|
|
633
|
+
}
|
|
634
|
+
import_core.logger.success("Model directive parsed correctly");
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: "Detect directive-only message",
|
|
639
|
+
fn: async (_runtime) => {
|
|
640
|
+
const result = parseDirectives("/think:high /verbose on");
|
|
641
|
+
if (!result.directivesOnly) {
|
|
642
|
+
throw new Error("Should detect directive-only message");
|
|
643
|
+
}
|
|
644
|
+
import_core.logger.success("Directive-only detection works correctly");
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
name: "Parse multiple directives",
|
|
649
|
+
fn: async (_runtime) => {
|
|
650
|
+
const result = parseDirectives("/think:medium /v full /elevated on hello");
|
|
651
|
+
if (!result.hasThinkDirective || !result.hasVerboseDirective || !result.hasElevatedDirective) {
|
|
652
|
+
throw new Error("Should detect all directives");
|
|
653
|
+
}
|
|
654
|
+
if (result.thinkLevel !== "medium") {
|
|
655
|
+
throw new Error(`Expected 'medium', got '${result.thinkLevel}'`);
|
|
656
|
+
}
|
|
657
|
+
if (result.verboseLevel !== "full") {
|
|
658
|
+
throw new Error(`Expected 'full', got '${result.verboseLevel}'`);
|
|
659
|
+
}
|
|
660
|
+
if (result.elevatedLevel !== "on") {
|
|
661
|
+
throw new Error(`Expected 'on', got '${result.elevatedLevel}'`);
|
|
662
|
+
}
|
|
663
|
+
if (result.cleanedText !== "hello") {
|
|
664
|
+
throw new Error(`Expected 'hello', got '${result.cleanedText}'`);
|
|
665
|
+
}
|
|
666
|
+
import_core.logger.success("Multiple directives parsed correctly");
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
name: "Session state management",
|
|
671
|
+
fn: async (_runtime) => {
|
|
672
|
+
const roomId = "test-room-123";
|
|
673
|
+
clearDirectiveState(roomId);
|
|
674
|
+
const directives = parseDirectives("/think:high /verbose on");
|
|
675
|
+
applyDirectives(roomId, directives);
|
|
676
|
+
const state = getDirectiveState(roomId);
|
|
677
|
+
if (state.thinking !== "high") {
|
|
678
|
+
throw new Error(`Expected thinking 'high', got '${state.thinking}'`);
|
|
679
|
+
}
|
|
680
|
+
if (state.verbose !== "on") {
|
|
681
|
+
throw new Error(`Expected verbose 'on', got '${state.verbose}'`);
|
|
682
|
+
}
|
|
683
|
+
clearDirectiveState(roomId);
|
|
684
|
+
import_core.logger.success("Session state management works correctly");
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
]
|
|
688
|
+
}
|
|
689
|
+
],
|
|
690
|
+
async init(_config, runtime) {
|
|
691
|
+
import_core.logger.log("[plugin-directives] Initializing directive parser");
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
var src_default = directivesPlugin;
|
|
695
|
+
|
|
696
|
+
//# debugId=DB05CA1BBD0B951464756E2164756E21
|