@elizaos/prompts 2.0.3-beta.2 → 2.0.3-beta.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/README.md CHANGED
@@ -16,7 +16,6 @@ packages/prompts/
16
16
  └── scripts/ # Spec + docs generators
17
17
  ├── generate-action-docs.js
18
18
  ├── generate-plugin-action-spec.js
19
- ├── prompt-compression.js
20
19
  └── check-secrets.js
21
20
  ```
22
21
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elizaos/prompts",
3
3
  "private": false,
4
- "version": "2.0.3-beta.2",
4
+ "version": "2.0.3-beta.4",
5
5
  "description": "Shared prompt templates for elizaOS across TypeScript, Python, and Rust",
6
6
  "type": "module",
7
7
  "main": "./src/index.ts",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "82fe0f44215954c2417328203f5bd6510985c1fc"
49
+ "gitHead": "f76f55793a0fb8d6b869dd8ddce03970de061e34"
50
50
  }
@@ -3,8 +3,8 @@ import { execFileSync } from "node:child_process";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { compressPromptDescription } from "../src/prompt-compression.ts";
6
7
  import { ensureDirectory, readJson } from "./file-utils.js";
7
- import { compressPromptDescription } from "./prompt-compression.js";
8
8
 
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
@@ -1143,6 +1143,79 @@ function extractConstLiterals(src) {
1143
1143
  return constants;
1144
1144
  }
1145
1145
 
1146
+ function readArrayLiteralAfter(src, marker) {
1147
+ const markerIndex = src.indexOf(marker);
1148
+ if (markerIndex < 0) return [];
1149
+ const bracketStart = src.indexOf("[", markerIndex);
1150
+ if (bracketStart < 0) return [];
1151
+ const source = readBalancedArraySource(src, bracketStart);
1152
+ if (!source) return [];
1153
+ const parsed = parseTsLiteralValue(source, 0);
1154
+ return Array.isArray(parsed.value) ? parsed.value : [];
1155
+ }
1156
+
1157
+ function dynamicCommandActionDocs(filePath, name) {
1158
+ const relativePath = path.relative(REPO_ROOT, filePath);
1159
+ const commandActionNameTemplate = "$" + "{key.toUpperCase()}_COMMAND";
1160
+ if (
1161
+ relativePath !==
1162
+ path.join(
1163
+ "plugins",
1164
+ "plugin-commands",
1165
+ "src",
1166
+ "actions",
1167
+ "command-actions.ts",
1168
+ ) ||
1169
+ name !== commandActionNameTemplate
1170
+ ) {
1171
+ return null;
1172
+ }
1173
+
1174
+ const pluginCommandsRoot = path.join(PLUGINS_ROOT, "plugin-commands");
1175
+ const handlersSrc = readText(
1176
+ path.join(pluginCommandsRoot, "src", "actions", "handlers.ts"),
1177
+ );
1178
+ const deterministicCommandKeys = extractConstLiterals(handlersSrc).get(
1179
+ "DETERMINISTIC_COMMAND_KEYS",
1180
+ );
1181
+ if (!Array.isArray(deterministicCommandKeys)) return [];
1182
+
1183
+ const registrySrc = readText(
1184
+ path.join(pluginCommandsRoot, "src", "registry.ts"),
1185
+ );
1186
+ const commandDefinitions = readArrayLiteralAfter(
1187
+ registrySrc,
1188
+ "DEFAULT_COMMANDS",
1189
+ );
1190
+ const definitionsByKey = new Map();
1191
+ for (const definition of commandDefinitions) {
1192
+ if (isRecordValue(definition) && typeof definition.key === "string") {
1193
+ definitionsByKey.set(definition.key, definition);
1194
+ }
1195
+ }
1196
+
1197
+ return deterministicCommandKeys
1198
+ .filter((key) => typeof key === "string")
1199
+ .map((key) => {
1200
+ const definition = definitionsByKey.get(key);
1201
+ const aliases = Array.isArray(definition?.textAliases)
1202
+ ? definition.textAliases.filter((alias) => typeof alias === "string")
1203
+ : [];
1204
+ const doc = {
1205
+ name: `${key.toUpperCase()}_COMMAND`,
1206
+ description:
1207
+ typeof definition?.description === "string"
1208
+ ? definition.description
1209
+ : "",
1210
+ parameters: sanitizeParameters(definition?.args),
1211
+ };
1212
+ if (aliases.length > 0) {
1213
+ doc.similes = aliases;
1214
+ }
1215
+ return doc;
1216
+ });
1217
+ }
1218
+
1146
1219
  function resolveRequireActionSpecName(src, source) {
1147
1220
  const match = source.trim().match(/^([A-Za-z_$][A-Za-z0-9_$]*)\.name$/);
1148
1221
  if (!match) return null;
@@ -1567,6 +1640,15 @@ function main() {
1567
1640
  if (!isRegisteredActionObject(filePath, obj.exportName)) continue;
1568
1641
  if (RETIRED_IMPLEMENTATION_ONLY_ACTIONS.has(name)) continue;
1569
1642
  if (coreActionNames.has(name)) continue;
1643
+ const dynamicDocs = dynamicCommandActionDocs(filePath, name);
1644
+ if (dynamicDocs) {
1645
+ for (const doc of dynamicDocs) {
1646
+ if (!actionDocsByName.has(doc.name)) {
1647
+ actionDocsByName.set(doc.name, doc);
1648
+ }
1649
+ }
1650
+ continue;
1651
+ }
1570
1652
  const description = expandDescriptionTemplateLiterals(
1571
1653
  extractTopLevelStringProp(obj.objectText, "description") ?? "",
1572
1654
  filePath,
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { compressPromptDescription } from "./prompt-compression";
2
+
1
3
  export const addContactTemplate = `task: Extract contact information to add to relationships.
2
4
 
3
5
  context:
@@ -6,9 +6,9 @@ const PROTECTED_PATTERNS = [
6
6
  /\bhttps?:\/\/[^\s)]+/g,
7
7
  /(^|[\s([{:=,])((?:\.{1,2}\/|\/|~\/)[A-Za-z0-9._~:/?#[\]@!$&'()*+,;=%-]+)/g,
8
8
  /\b[A-Z][A-Z0-9_]{2,}\b/g,
9
- ];
9
+ ] as const;
10
10
 
11
- const PHRASE_REPLACEMENTS = [
11
+ const PHRASE_REPLACEMENTS: Array<[RegExp, string]> = [
12
12
  [/\bin order to\b/gi, "to"],
13
13
  [/\b(?:please|simply|basically|actually|currently)\b/gi, ""],
14
14
  [/\bthis (?:action|provider|evaluator) (?:will|can|should)\b/gi, ""],
@@ -33,7 +33,7 @@ const PHRASE_REPLACEMENTS = [
33
33
  [/\bwhich is\b/gi, ""],
34
34
  ];
35
35
 
36
- const WORD_REPLACEMENTS = [
36
+ const WORD_REPLACEMENTS: Array<[RegExp, string]> = [
37
37
  [/\bmessages\b/gi, "msgs"],
38
38
  [/\bmessage\b/gi, "msg"],
39
39
  [/\binformation\b/gi, "info"],
@@ -57,7 +57,7 @@ const WORD_REPLACEMENTS = [
57
57
  [/\bwithout\b/gi, "without"],
58
58
  ];
59
59
 
60
- const LEADING_VERB_REPLACEMENTS = [
60
+ const LEADING_VERB_REPLACEMENTS: Array<[RegExp, string]> = [
61
61
  [/^Provides\b/i, "Provide"],
62
62
  [/^Retrieves\b/i, "Get"],
63
63
  [/^Returns\b/i, "Return"],
@@ -73,22 +73,25 @@ const LEADING_VERB_REPLACEMENTS = [
73
73
  [/^Automatically\b/i, "Auto"],
74
74
  ];
75
75
 
76
- function normalizeWhitespace(value) {
76
+ function normalizeWhitespace(value: string): string {
77
77
  return value.trim().split(/\s+/).filter(Boolean).join(" ");
78
78
  }
79
79
 
80
- function protectTechnicalSpans(value) {
81
- const protectedValues = [];
80
+ function protectTechnicalSpans(value: string): {
81
+ text: string;
82
+ restore: (text: string) => string;
83
+ } {
84
+ const protectedValues: string[] = [];
82
85
  let text = value;
83
86
 
84
- const protect = (span) => {
87
+ const protect = (span: string): string => {
85
88
  const token = `__elizaProtected${protectedValues.length}__`;
86
89
  protectedValues.push(span);
87
90
  return token;
88
91
  };
89
92
 
90
93
  for (const pattern of PROTECTED_PATTERNS) {
91
- text = text.replace(pattern, (...args) => {
94
+ text = text.replace(pattern, (...args: string[]) => {
92
95
  if (pattern.source.startsWith("(^|")) {
93
96
  const prefix = args[1] ?? "";
94
97
  const span = args[2] ?? "";
@@ -100,15 +103,15 @@ function protectTechnicalSpans(value) {
100
103
 
101
104
  return {
102
105
  text,
103
- restore: (restoredText) =>
106
+ restore: (restoredText: string) =>
104
107
  restoredText.replace(
105
108
  /__elizaProtected(\d+)__/g,
106
- (_match, index) => protectedValues[Number(index)] ?? "",
109
+ (_match, index: string) => protectedValues[Number(index)] ?? "",
107
110
  ),
108
111
  };
109
112
  }
110
113
 
111
- function truncateDescription(value) {
114
+ function truncateDescription(value: string): string {
112
115
  if (value.length <= MAX_DESCRIPTION_LENGTH) {
113
116
  return value;
114
117
  }
@@ -132,7 +135,14 @@ function truncateDescription(value) {
132
135
  return `${trimmed}...`;
133
136
  }
134
137
 
135
- export function compressPromptDescription(description) {
138
+ /**
139
+ * Deterministic compact description text for model-facing action/provider docs.
140
+ * Preserves code spans, URLs, paths, commands, env vars, and technical terms
141
+ * while dropping common filler.
142
+ */
143
+ export function compressPromptDescription(
144
+ description: string | undefined,
145
+ ): string {
136
146
  if (typeof description !== "string" || !description.trim()) {
137
147
  return "";
138
148
  }