@elizaos/prompts 2.0.0-alpha

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.
@@ -0,0 +1,912 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Action/Provider/Evaluator Docs Generator
4
+ *
5
+ * Reads canonical specs from packages/prompts/specs/** and generates
6
+ * language-native docs modules for:
7
+ * - packages/typescript
8
+ * - packages/python
9
+ * - packages/rust
10
+ *
11
+ * This is intentionally dependency-free (no zod/yup) to keep builds lightweight.
12
+ */
13
+
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+
21
+ const REPO_ROOT = path.resolve(__dirname, "../../..");
22
+ const PROMPTS_ROOT = path.resolve(__dirname, "..");
23
+
24
+ const ACTIONS_SPECS_DIR = path.join(PROMPTS_ROOT, "specs", "actions");
25
+ const PROVIDERS_SPECS_DIR = path.join(PROMPTS_ROOT, "specs", "providers");
26
+ const EVALUATORS_SPECS_DIR = path.join(PROMPTS_ROOT, "specs", "evaluators");
27
+
28
+ const CORE_ACTIONS_SPEC_PATH = path.join(ACTIONS_SPECS_DIR, "core.json");
29
+ const CORE_PROVIDERS_SPEC_PATH = path.join(PROVIDERS_SPECS_DIR, "core.json");
30
+ const CORE_EVALUATORS_SPEC_PATH = path.join(EVALUATORS_SPECS_DIR, "core.json");
31
+
32
+ /**
33
+ * @typedef {"string" | "number" | "boolean" | "object" | "array"} JsonSchemaType
34
+ */
35
+
36
+ /**
37
+ * @param {unknown} value
38
+ * @param {string} name
39
+ * @returns {asserts value is Record<string, unknown>}
40
+ */
41
+ function assertRecord(value, name) {
42
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
43
+ throw new Error(`${name} must be an object`);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * @param {unknown} value
49
+ * @param {string} name
50
+ * @returns {asserts value is string}
51
+ */
52
+ function assertString(value, name) {
53
+ if (typeof value !== "string") {
54
+ throw new Error(`${name} must be a string`);
55
+ }
56
+ }
57
+
58
+ /**
59
+ * @param {unknown} value
60
+ * @param {string} name
61
+ * @returns {asserts value is boolean}
62
+ */
63
+ function assertBoolean(value, name) {
64
+ if (typeof value !== "boolean") {
65
+ throw new Error(`${name} must be a boolean`);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * @param {unknown} value
71
+ * @param {string} name
72
+ * @returns {asserts value is unknown[]}
73
+ */
74
+ function assertArray(value, name) {
75
+ if (!Array.isArray(value)) {
76
+ throw new Error(`${name} must be an array`);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @param {unknown} value
82
+ * @param {string} name
83
+ * @returns {asserts value is (string | number | boolean | null)[]}
84
+ */
85
+ function assertExampleValuesArray(value, name) {
86
+ assertArray(value, name);
87
+ for (let i = 0; i < value.length; i++) {
88
+ const v = value[i];
89
+ const t = typeof v;
90
+ if (v !== null && t !== "string" && t !== "number" && t !== "boolean") {
91
+ throw new Error(
92
+ `${name}[${i}] must be string | number | boolean | null (got ${t})`,
93
+ );
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * @param {unknown} schema
100
+ * @param {string} name
101
+ * @returns {asserts schema is Record<string, unknown> & { type: JsonSchemaType }}
102
+ */
103
+ function assertParameterSchema(schema, name) {
104
+ assertRecord(schema, name);
105
+ const t = schema.type;
106
+ assertString(t, `${name}.type`);
107
+ if (!["string", "number", "boolean", "object", "array"].includes(t)) {
108
+ throw new Error(
109
+ `${name}.type must be one of string|number|boolean|object|array`,
110
+ );
111
+ }
112
+ if (schema.enum !== undefined) {
113
+ assertArray(schema.enum, `${name}.enum`);
114
+ for (let i = 0; i < schema.enum.length; i++) {
115
+ assertString(schema.enum[i], `${name}.enum[${i}]`);
116
+ }
117
+ }
118
+ if (schema.default !== undefined) {
119
+ const dv = schema.default;
120
+ const dt = typeof dv;
121
+ if (dv !== null && dt !== "string" && dt !== "number" && dt !== "boolean") {
122
+ throw new Error(
123
+ `${name}.default must be string|number|boolean|null if provided`,
124
+ );
125
+ }
126
+ }
127
+ if (schema.minimum !== undefined && typeof schema.minimum !== "number") {
128
+ throw new Error(`${name}.minimum must be a number if provided`);
129
+ }
130
+ if (schema.maximum !== undefined && typeof schema.maximum !== "number") {
131
+ throw new Error(`${name}.maximum must be a number if provided`);
132
+ }
133
+ if (schema.pattern !== undefined) {
134
+ assertString(schema.pattern, `${name}.pattern`);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * @param {unknown} param
140
+ * @param {string} name
141
+ * @returns {asserts param is Record<string, unknown>}
142
+ */
143
+ function assertActionParameter(param, name) {
144
+ assertRecord(param, name);
145
+ assertString(param.name, `${name}.name`);
146
+ assertString(param.description, `${name}.description`);
147
+ if (param.required !== undefined) {
148
+ assertBoolean(param.required, `${name}.required`);
149
+ }
150
+ assertParameterSchema(param.schema, `${name}.schema`);
151
+ if (param.examples !== undefined) {
152
+ assertExampleValuesArray(param.examples, `${name}.examples`);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * @param {unknown} action
158
+ * @param {string} name
159
+ * @returns {asserts action is Record<string, unknown>}
160
+ */
161
+ function assertActionDoc(action, name) {
162
+ assertRecord(action, name);
163
+ assertString(action.name, `${name}.name`);
164
+ assertString(action.description, `${name}.description`);
165
+ if (action.similes !== undefined) {
166
+ assertArray(action.similes, `${name}.similes`);
167
+ for (let i = 0; i < action.similes.length; i++) {
168
+ assertString(action.similes[i], `${name}.similes[${i}]`);
169
+ }
170
+ }
171
+ if (action.parameters !== undefined) {
172
+ assertArray(action.parameters, `${name}.parameters`);
173
+ for (let i = 0; i < action.parameters.length; i++) {
174
+ assertActionParameter(action.parameters[i], `${name}.parameters[${i}]`);
175
+ }
176
+ }
177
+ if (action.examples !== undefined) {
178
+ assertArray(action.examples, `${name}.examples`);
179
+ }
180
+ if (action.exampleCalls !== undefined) {
181
+ assertArray(action.exampleCalls, `${name}.exampleCalls`);
182
+ }
183
+ }
184
+
185
+ /**
186
+ * @param {unknown} provider
187
+ * @param {string} name
188
+ * @returns {asserts provider is Record<string, unknown>}
189
+ */
190
+ function assertProviderDoc(provider, name) {
191
+ assertRecord(provider, name);
192
+ assertString(provider.name, `${name}.name`);
193
+ assertString(provider.description, `${name}.description`);
194
+ if (
195
+ provider.position !== undefined &&
196
+ typeof provider.position !== "number"
197
+ ) {
198
+ throw new Error(`${name}.position must be a number if provided`);
199
+ }
200
+ if (provider.dynamic !== undefined) {
201
+ assertBoolean(provider.dynamic, `${name}.dynamic`);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * @param {unknown} evaluator
207
+ * @param {string} name
208
+ * @returns {asserts evaluator is Record<string, unknown>}
209
+ */
210
+ function assertEvaluatorDoc(evaluator, name) {
211
+ assertRecord(evaluator, name);
212
+ assertString(evaluator.name, `${name}.name`);
213
+ assertString(evaluator.description, `${name}.description`);
214
+ if (evaluator.similes !== undefined) {
215
+ assertArray(evaluator.similes, `${name}.similes`);
216
+ for (let i = 0; i < evaluator.similes.length; i++) {
217
+ assertString(evaluator.similes[i], `${name}.similes[${i}]`);
218
+ }
219
+ }
220
+ if (evaluator.alwaysRun !== undefined) {
221
+ assertBoolean(evaluator.alwaysRun, `${name}.alwaysRun`);
222
+ }
223
+ if (evaluator.examples !== undefined) {
224
+ assertArray(evaluator.examples, `${name}.examples`);
225
+ }
226
+ }
227
+
228
+ /**
229
+ * @param {string} filePath
230
+ * @returns {unknown}
231
+ */
232
+ function readJson(filePath) {
233
+ const raw = fs.readFileSync(filePath, "utf-8");
234
+ return JSON.parse(raw);
235
+ }
236
+
237
+ /**
238
+ * Recursively list .json files in a directory.
239
+ * @param {string} rootDir
240
+ * @returns {string[]}
241
+ */
242
+ function listJsonFiles(rootDir) {
243
+ /** @type {string[]} */
244
+ const out = [];
245
+ if (!fs.existsSync(rootDir)) {
246
+ return out;
247
+ }
248
+ /** @type {string[]} */
249
+ const stack = [rootDir];
250
+ while (stack.length > 0) {
251
+ const dir = stack.pop();
252
+ if (!dir) break;
253
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
254
+ for (const entry of entries) {
255
+ const full = path.join(dir, entry.name);
256
+ if (entry.isDirectory()) {
257
+ stack.push(full);
258
+ continue;
259
+ }
260
+ if (entry.isFile() && entry.name.endsWith(".json")) {
261
+ out.push(full);
262
+ }
263
+ }
264
+ }
265
+ return out.sort((a, b) => a.localeCompare(b));
266
+ }
267
+
268
+ /**
269
+ * @param {unknown} root
270
+ * @param {string} label
271
+ * @returns {{ version: string, actions: unknown[] }}
272
+ */
273
+ function parseActionsSpec(root, label) {
274
+ assertRecord(root, label);
275
+ assertString(root.version, `${label}.version`);
276
+ assertArray(root.actions, `${label}.actions`);
277
+ for (let i = 0; i < root.actions.length; i++) {
278
+ assertActionDoc(root.actions[i], `${label}.actions[${i}]`);
279
+ }
280
+ return { version: root.version, actions: root.actions };
281
+ }
282
+
283
+ /**
284
+ * @param {unknown} root
285
+ * @param {string} label
286
+ * @returns {{ version: string, providers: unknown[] }}
287
+ */
288
+ function parseProvidersSpec(root, label) {
289
+ assertRecord(root, label);
290
+ assertString(root.version, `${label}.version`);
291
+ assertArray(root.providers, `${label}.providers`);
292
+ for (let i = 0; i < root.providers.length; i++) {
293
+ assertProviderDoc(root.providers[i], `${label}.providers[${i}]`);
294
+ }
295
+ return { version: root.version, providers: root.providers };
296
+ }
297
+
298
+ /**
299
+ * @param {unknown} root
300
+ * @param {string} label
301
+ * @returns {{ version: string, evaluators: unknown[] }}
302
+ */
303
+ function parseEvaluatorsSpec(root, label) {
304
+ assertRecord(root, label);
305
+ assertString(root.version, `${label}.version`);
306
+ assertArray(root.evaluators, `${label}.evaluators`);
307
+ for (let i = 0; i < root.evaluators.length; i++) {
308
+ assertEvaluatorDoc(root.evaluators[i], `${label}.evaluators[${i}]`);
309
+ }
310
+ return { version: root.version, evaluators: root.evaluators };
311
+ }
312
+
313
+ /**
314
+ * @param {unknown[]} docs
315
+ * @param {string} label
316
+ */
317
+ function assertUniqueNames(docs, label) {
318
+ /** @type {Set<string>} */
319
+ const seen = new Set();
320
+ for (let i = 0; i < docs.length; i++) {
321
+ const d = docs[i];
322
+ assertRecord(d, `${label}[${i}]`);
323
+ assertString(d.name, `${label}[${i}].name`);
324
+ const name = d.name;
325
+ if (seen.has(name)) {
326
+ throw new Error(`${label} contains duplicate name: ${name}`);
327
+ }
328
+ seen.add(name);
329
+ }
330
+ }
331
+
332
+ /**
333
+ * @param {string} dir
334
+ * @param {string} corePath
335
+ * @param {"actions" | "providers" | "evaluators"} kind
336
+ * @returns {{ core: { version: string, items: unknown[] }, all: { version: string, items: unknown[] } }}
337
+ */
338
+ function loadSpecs(dir, corePath, kind) {
339
+ if (!fs.existsSync(corePath)) {
340
+ return {
341
+ core: { version: "1.0.0", items: [] },
342
+ all: { version: "1.0.0", items: [] },
343
+ };
344
+ }
345
+
346
+ const coreRoot = readJson(corePath);
347
+ const coreLabel = `${kind} core spec`;
348
+ let coreParsed;
349
+
350
+ if (kind === "actions") {
351
+ coreParsed = parseActionsSpec(coreRoot, coreLabel);
352
+ } else if (kind === "providers") {
353
+ coreParsed = parseProvidersSpec(coreRoot, coreLabel);
354
+ } else {
355
+ coreParsed = parseEvaluatorsSpec(coreRoot, coreLabel);
356
+ }
357
+
358
+ const allFiles = listJsonFiles(dir).filter(
359
+ (p) => path.resolve(p) !== path.resolve(corePath),
360
+ );
361
+ /** @type {unknown[]} */
362
+ const merged = [
363
+ ...(kind === "actions"
364
+ ? coreParsed.actions
365
+ : kind === "providers"
366
+ ? coreParsed.providers
367
+ : coreParsed.evaluators),
368
+ ];
369
+
370
+ for (const filePath of allFiles) {
371
+ const root = readJson(filePath);
372
+ const label = `${kind} spec (${path.relative(PROMPTS_ROOT, filePath)})`;
373
+ let parsed;
374
+
375
+ if (kind === "actions") {
376
+ parsed = parseActionsSpec(root, label);
377
+ } else if (kind === "providers") {
378
+ parsed = parseProvidersSpec(root, label);
379
+ } else {
380
+ parsed = parseEvaluatorsSpec(root, label);
381
+ }
382
+
383
+ if (parsed.version !== coreParsed.version) {
384
+ throw new Error(
385
+ `${label}.version (${parsed.version}) must match core version (${coreParsed.version})`,
386
+ );
387
+ }
388
+ merged.push(
389
+ ...(kind === "actions"
390
+ ? parsed.actions
391
+ : kind === "providers"
392
+ ? parsed.providers
393
+ : parsed.evaluators),
394
+ );
395
+ }
396
+
397
+ const itemsLabel =
398
+ kind === "actions"
399
+ ? "actions spec.actions"
400
+ : kind === "providers"
401
+ ? "providers spec.providers"
402
+ : "evaluators spec.evaluators";
403
+ assertUniqueNames(merged, itemsLabel);
404
+
405
+ return {
406
+ core: {
407
+ version: coreParsed.version,
408
+ items:
409
+ kind === "actions"
410
+ ? coreParsed.actions
411
+ : kind === "providers"
412
+ ? coreParsed.providers
413
+ : coreParsed.evaluators,
414
+ },
415
+ all: {
416
+ version: coreParsed.version,
417
+ items: merged,
418
+ },
419
+ };
420
+ }
421
+
422
+ /**
423
+ * @param {string} dir
424
+ */
425
+ function ensureDir(dir) {
426
+ fs.mkdirSync(dir, { recursive: true });
427
+ }
428
+
429
+ /**
430
+ * @param {string} content
431
+ * @returns {{ content: string, hashCount: number }}
432
+ */
433
+ function escapeRustRawString(content) {
434
+ let hashCount = 1;
435
+ while (content.includes(`"${"#".repeat(hashCount)}`)) {
436
+ hashCount++;
437
+ }
438
+ return { content, hashCount };
439
+ }
440
+
441
+ /**
442
+ * Escape a string for use in Python triple-quoted string.
443
+ * JSON won't normally contain `"""` but we escape defensively.
444
+ * @param {string} content
445
+ * @returns {string}
446
+ */
447
+ function escapePythonTripleQuoted(content) {
448
+ return content.replace(/\\/g, "\\\\").replace(/"""/g, '\\"\\"\\"');
449
+ }
450
+
451
+ function generateTypeScript(actionsSpec, providersSpec, evaluatorsSpec) {
452
+ const outDir = path.join(
453
+ REPO_ROOT,
454
+ "packages",
455
+ "typescript",
456
+ "src",
457
+ "generated",
458
+ );
459
+ ensureDir(outDir);
460
+
461
+ const actionsJson = JSON.stringify(
462
+ { version: actionsSpec.core.version, actions: actionsSpec.core.items },
463
+ null,
464
+ 2,
465
+ );
466
+ const actionsAllJson = JSON.stringify(
467
+ { version: actionsSpec.all.version, actions: actionsSpec.all.items },
468
+ null,
469
+ 2,
470
+ );
471
+ const providersJson = JSON.stringify(
472
+ {
473
+ version: providersSpec.core.version,
474
+ providers: providersSpec.core.items,
475
+ },
476
+ null,
477
+ 2,
478
+ );
479
+ const providersAllJson = JSON.stringify(
480
+ { version: providersSpec.all.version, providers: providersSpec.all.items },
481
+ null,
482
+ 2,
483
+ );
484
+ const evaluatorsJson = JSON.stringify(
485
+ {
486
+ version: evaluatorsSpec.core.version,
487
+ evaluators: evaluatorsSpec.core.items,
488
+ },
489
+ null,
490
+ 2,
491
+ );
492
+ const evaluatorsAllJson = JSON.stringify(
493
+ {
494
+ version: evaluatorsSpec.all.version,
495
+ evaluators: evaluatorsSpec.all.items,
496
+ },
497
+ null,
498
+ 2,
499
+ );
500
+
501
+ const content = `/**
502
+ * Auto-generated canonical action/provider/evaluator docs.
503
+ * DO NOT EDIT - Generated from packages/prompts/specs/**.
504
+ */
505
+
506
+ export type ActionDocParameterExampleValue = string | number | boolean | null;
507
+
508
+ export type ActionDocParameterSchema = {
509
+ type: "string" | "number" | "boolean" | "object" | "array";
510
+ description?: string;
511
+ default?: ActionDocParameterExampleValue;
512
+ enum?: string[];
513
+ properties?: Record<string, ActionDocParameterSchema>;
514
+ items?: ActionDocParameterSchema;
515
+ minimum?: number;
516
+ maximum?: number;
517
+ pattern?: string;
518
+ };
519
+
520
+ export type ActionDocParameter = {
521
+ name: string;
522
+ description: string;
523
+ required?: boolean;
524
+ schema: ActionDocParameterSchema;
525
+ examples?: readonly ActionDocParameterExampleValue[];
526
+ };
527
+
528
+ export type ActionDocExampleCall = {
529
+ user: string;
530
+ actions: readonly string[];
531
+ params?: Record<string, Record<string, ActionDocParameterExampleValue>>;
532
+ };
533
+
534
+ export type ActionDocExampleMessage = {
535
+ name: string;
536
+ content: {
537
+ text: string;
538
+ actions?: readonly string[];
539
+ };
540
+ };
541
+
542
+ export type ActionDoc = {
543
+ name: string;
544
+ description: string;
545
+ similes?: readonly string[];
546
+ parameters?: readonly ActionDocParameter[];
547
+ examples?: readonly (readonly ActionDocExampleMessage[])[];
548
+ exampleCalls?: readonly ActionDocExampleCall[];
549
+ };
550
+
551
+ export type ProviderDoc = {
552
+ name: string;
553
+ description: string;
554
+ position?: number;
555
+ dynamic?: boolean;
556
+ };
557
+
558
+ export type EvaluatorDocMessageContent = {
559
+ text: string;
560
+ type?: string;
561
+ };
562
+
563
+ export type EvaluatorDocMessage = {
564
+ name: string;
565
+ content: EvaluatorDocMessageContent;
566
+ };
567
+
568
+ export type EvaluatorDocExample = {
569
+ prompt: string;
570
+ messages: readonly EvaluatorDocMessage[];
571
+ outcome: string;
572
+ };
573
+
574
+ export type EvaluatorDoc = {
575
+ name: string;
576
+ description: string;
577
+ similes?: readonly string[];
578
+ alwaysRun?: boolean;
579
+ examples?: readonly EvaluatorDocExample[];
580
+ };
581
+
582
+ export const coreActionsSpecVersion = ${JSON.stringify(actionsSpec.core.version)} as const;
583
+ export const allActionsSpecVersion = ${JSON.stringify(actionsSpec.all.version)} as const;
584
+ export const coreProvidersSpecVersion = ${JSON.stringify(providersSpec.core.version)} as const;
585
+ export const allProvidersSpecVersion = ${JSON.stringify(providersSpec.all.version)} as const;
586
+ export const coreEvaluatorsSpecVersion = ${JSON.stringify(evaluatorsSpec.core.version)} as const;
587
+ export const allEvaluatorsSpecVersion = ${JSON.stringify(evaluatorsSpec.all.version)} as const;
588
+
589
+ export const coreActionsSpec = ${actionsJson} as const satisfies { version: string; actions: readonly ActionDoc[] };
590
+ export const allActionsSpec = ${actionsAllJson} as const satisfies { version: string; actions: readonly ActionDoc[] };
591
+ export const coreProvidersSpec = ${providersJson} as const satisfies { version: string; providers: readonly ProviderDoc[] };
592
+ export const allProvidersSpec = ${providersAllJson} as const satisfies { version: string; providers: readonly ProviderDoc[] };
593
+ export const coreEvaluatorsSpec = ${evaluatorsJson} as const satisfies {
594
+ version: string;
595
+ evaluators: readonly EvaluatorDoc[];
596
+ };
597
+ export const allEvaluatorsSpec = ${evaluatorsAllJson} as const satisfies {
598
+ version: string;
599
+ evaluators: readonly EvaluatorDoc[];
600
+ };
601
+
602
+ export const coreActionDocs: readonly ActionDoc[] = coreActionsSpec.actions;
603
+ export const allActionDocs: readonly ActionDoc[] = allActionsSpec.actions;
604
+ export const coreProviderDocs: readonly ProviderDoc[] = coreProvidersSpec.providers;
605
+ export const allProviderDocs: readonly ProviderDoc[] = allProvidersSpec.providers;
606
+ export const coreEvaluatorDocs: readonly EvaluatorDoc[] = coreEvaluatorsSpec.evaluators;
607
+ export const allEvaluatorDocs: readonly EvaluatorDoc[] = allEvaluatorsSpec.evaluators;
608
+ `;
609
+
610
+ fs.writeFileSync(path.join(outDir, "action-docs.ts"), content);
611
+ }
612
+
613
+ function generatePython(actionsSpec, providersSpec, evaluatorsSpec) {
614
+ const outDir = path.join(
615
+ REPO_ROOT,
616
+ "packages",
617
+ "python",
618
+ "elizaos",
619
+ "generated",
620
+ );
621
+ ensureDir(outDir);
622
+
623
+ const initPath = path.join(outDir, "__init__.py");
624
+ if (!fs.existsSync(initPath)) {
625
+ fs.writeFileSync(initPath, '"""Auto-generated module package."""\n');
626
+ }
627
+
628
+ const actionsJson = JSON.stringify(
629
+ { version: actionsSpec.core.version, actions: actionsSpec.core.items },
630
+ null,
631
+ 2,
632
+ );
633
+ const actionsAllJson = JSON.stringify(
634
+ { version: actionsSpec.all.version, actions: actionsSpec.all.items },
635
+ null,
636
+ 2,
637
+ );
638
+ const providersJson = JSON.stringify(
639
+ {
640
+ version: providersSpec.core.version,
641
+ providers: providersSpec.core.items,
642
+ },
643
+ null,
644
+ 2,
645
+ );
646
+ const providersAllJson = JSON.stringify(
647
+ { version: providersSpec.all.version, providers: providersSpec.all.items },
648
+ null,
649
+ 2,
650
+ );
651
+ const evaluatorsJson = JSON.stringify(
652
+ {
653
+ version: evaluatorsSpec.core.version,
654
+ evaluators: evaluatorsSpec.core.items,
655
+ },
656
+ null,
657
+ 2,
658
+ );
659
+ const evaluatorsAllJson = JSON.stringify(
660
+ {
661
+ version: evaluatorsSpec.all.version,
662
+ evaluators: evaluatorsSpec.all.items,
663
+ },
664
+ null,
665
+ 2,
666
+ );
667
+
668
+ const content = `"""
669
+ Auto-generated canonical action/provider/evaluator docs.
670
+ DO NOT EDIT - Generated from packages/prompts/specs/**.
671
+ """
672
+
673
+ from __future__ import annotations
674
+
675
+ import json
676
+
677
+ from typing import Literal, TypedDict
678
+
679
+
680
+ JsonSchemaType = Literal["string", "number", "boolean", "object", "array"]
681
+ ActionDocParameterExampleValue = str | int | float | bool | None
682
+
683
+
684
+ class ActionDocParameterSchema(TypedDict, total=False):
685
+ type: JsonSchemaType
686
+ description: str
687
+ default: ActionDocParameterExampleValue
688
+ enum: list[str]
689
+ properties: dict[str, "ActionDocParameterSchema"]
690
+ items: "ActionDocParameterSchema"
691
+ minimum: float
692
+ maximum: float
693
+ pattern: str
694
+
695
+
696
+ class ActionDocParameter(TypedDict, total=False):
697
+ name: str
698
+ description: str
699
+ required: bool
700
+ schema: ActionDocParameterSchema
701
+ examples: list[ActionDocParameterExampleValue]
702
+
703
+
704
+ class ActionDocExampleCall(TypedDict, total=False):
705
+ user: str
706
+ actions: list[str]
707
+ params: dict[str, dict[str, ActionDocParameterExampleValue]]
708
+
709
+
710
+ class ActionDocExampleMessage(TypedDict, total=False):
711
+ name: str
712
+ content: dict[str, object]
713
+
714
+
715
+ class ActionDoc(TypedDict, total=False):
716
+ name: str
717
+ description: str
718
+ similes: list[str]
719
+ parameters: list[ActionDocParameter]
720
+ examples: list[list[ActionDocExampleMessage]]
721
+ exampleCalls: list[ActionDocExampleCall]
722
+
723
+
724
+ class ProviderDoc(TypedDict, total=False):
725
+ name: str
726
+ description: str
727
+ position: int
728
+ dynamic: bool
729
+
730
+
731
+ class EvaluatorDocMessageContent(TypedDict, total=False):
732
+ text: str
733
+ type: str
734
+
735
+
736
+ class EvaluatorDocMessage(TypedDict):
737
+ name: str
738
+ content: EvaluatorDocMessageContent
739
+
740
+
741
+ class EvaluatorDocExample(TypedDict):
742
+ prompt: str
743
+ messages: list[EvaluatorDocMessage]
744
+ outcome: str
745
+
746
+
747
+ class EvaluatorDoc(TypedDict, total=False):
748
+ name: str
749
+ description: str
750
+ similes: list[str]
751
+ alwaysRun: bool
752
+ examples: list[EvaluatorDocExample]
753
+
754
+
755
+ core_actions_spec_version: str = ${JSON.stringify(actionsSpec.core.version)}
756
+ all_actions_spec_version: str = ${JSON.stringify(actionsSpec.all.version)}
757
+ core_providers_spec_version: str = ${JSON.stringify(providersSpec.core.version)}
758
+ all_providers_spec_version: str = ${JSON.stringify(providersSpec.all.version)}
759
+ core_evaluators_spec_version: str = ${JSON.stringify(evaluatorsSpec.core.version)}
760
+ all_evaluators_spec_version: str = ${JSON.stringify(evaluatorsSpec.all.version)}
761
+
762
+ _CORE_ACTION_DOCS_JSON = """${escapePythonTripleQuoted(actionsJson)}"""
763
+ _ALL_ACTION_DOCS_JSON = """${escapePythonTripleQuoted(actionsAllJson)}"""
764
+ _CORE_PROVIDER_DOCS_JSON = """${escapePythonTripleQuoted(providersJson)}"""
765
+ _ALL_PROVIDER_DOCS_JSON = """${escapePythonTripleQuoted(providersAllJson)}"""
766
+ _CORE_EVALUATOR_DOCS_JSON = """${escapePythonTripleQuoted(evaluatorsJson)}"""
767
+ _ALL_EVALUATOR_DOCS_JSON = """${escapePythonTripleQuoted(evaluatorsAllJson)}"""
768
+
769
+ core_action_docs: dict[str, object] = json.loads(_CORE_ACTION_DOCS_JSON)
770
+ all_action_docs: dict[str, object] = json.loads(_ALL_ACTION_DOCS_JSON)
771
+ core_provider_docs: dict[str, object] = json.loads(_CORE_PROVIDER_DOCS_JSON)
772
+ all_provider_docs: dict[str, object] = json.loads(_ALL_PROVIDER_DOCS_JSON)
773
+ core_evaluator_docs: dict[str, object] = json.loads(_CORE_EVALUATOR_DOCS_JSON)
774
+ all_evaluator_docs: dict[str, object] = json.loads(_ALL_EVALUATOR_DOCS_JSON)
775
+
776
+ __all__ = [
777
+ "ActionDoc",
778
+ "ActionDocExampleCall",
779
+ "ActionDocExampleMessage",
780
+ "ActionDocParameter",
781
+ "ActionDocParameterSchema",
782
+ "ActionDocParameterExampleValue",
783
+ "ProviderDoc",
784
+ "EvaluatorDoc",
785
+ "EvaluatorDocExample",
786
+ "EvaluatorDocMessage",
787
+ "EvaluatorDocMessageContent",
788
+ "core_actions_spec_version",
789
+ "all_actions_spec_version",
790
+ "core_providers_spec_version",
791
+ "all_providers_spec_version",
792
+ "core_evaluators_spec_version",
793
+ "all_evaluators_spec_version",
794
+ "core_action_docs",
795
+ "all_action_docs",
796
+ "core_provider_docs",
797
+ "all_provider_docs",
798
+ "core_evaluator_docs",
799
+ "all_evaluator_docs",
800
+ ]
801
+ `;
802
+
803
+ fs.writeFileSync(path.join(outDir, "action_docs.py"), content);
804
+ }
805
+
806
+ function generateRust(actionsSpec, providersSpec, evaluatorsSpec) {
807
+ const outDir = path.join(REPO_ROOT, "packages", "rust", "src", "generated");
808
+ ensureDir(outDir);
809
+
810
+ const actionsJson = JSON.stringify(
811
+ { version: actionsSpec.core.version, actions: actionsSpec.core.items },
812
+ null,
813
+ 2,
814
+ );
815
+ const actionsAllJson = JSON.stringify(
816
+ { version: actionsSpec.all.version, actions: actionsSpec.all.items },
817
+ null,
818
+ 2,
819
+ );
820
+ const providersJson = JSON.stringify(
821
+ {
822
+ version: providersSpec.core.version,
823
+ providers: providersSpec.core.items,
824
+ },
825
+ null,
826
+ 2,
827
+ );
828
+ const providersAllJson = JSON.stringify(
829
+ { version: providersSpec.all.version, providers: providersSpec.all.items },
830
+ null,
831
+ 2,
832
+ );
833
+ const evaluatorsJson = JSON.stringify(
834
+ {
835
+ version: evaluatorsSpec.core.version,
836
+ evaluators: evaluatorsSpec.core.items,
837
+ },
838
+ null,
839
+ 2,
840
+ );
841
+ const evaluatorsAllJson = JSON.stringify(
842
+ {
843
+ version: evaluatorsSpec.all.version,
844
+ evaluators: evaluatorsSpec.all.items,
845
+ },
846
+ null,
847
+ 2,
848
+ );
849
+
850
+ const { content: actionsContent, hashCount: actionsHashCount } =
851
+ escapeRustRawString(actionsJson);
852
+ const { content: actionsAllContent, hashCount: actionsAllHashCount } =
853
+ escapeRustRawString(actionsAllJson);
854
+ const { content: providersContent, hashCount: providersHashCount } =
855
+ escapeRustRawString(providersJson);
856
+ const { content: providersAllContent, hashCount: providersAllHashCount } =
857
+ escapeRustRawString(providersAllJson);
858
+ const { content: evalContent, hashCount: evalHashCount } =
859
+ escapeRustRawString(evaluatorsJson);
860
+ const { content: evalAllContent, hashCount: evalAllHashCount } =
861
+ escapeRustRawString(evaluatorsAllJson);
862
+
863
+ const actionsDelim = "#".repeat(actionsHashCount);
864
+ const actionsAllDelim = "#".repeat(actionsAllHashCount);
865
+ const providersDelim = "#".repeat(providersHashCount);
866
+ const providersAllDelim = "#".repeat(providersAllHashCount);
867
+ const evalDelim = "#".repeat(evalHashCount);
868
+ const evalAllDelim = "#".repeat(evalAllHashCount);
869
+
870
+ const content = `//! Auto-generated canonical action/provider/evaluator docs.
871
+ //! DO NOT EDIT - Generated from packages/prompts/specs/**.
872
+
873
+ pub const CORE_ACTION_DOCS_JSON: &str = r${actionsDelim}"${actionsContent}"${actionsDelim};
874
+ pub const ALL_ACTION_DOCS_JSON: &str = r${actionsAllDelim}"${actionsAllContent}"${actionsAllDelim};
875
+ pub const CORE_PROVIDER_DOCS_JSON: &str = r${providersDelim}"${providersContent}"${providersDelim};
876
+ pub const ALL_PROVIDER_DOCS_JSON: &str = r${providersAllDelim}"${providersAllContent}"${providersAllDelim};
877
+ pub const CORE_EVALUATOR_DOCS_JSON: &str = r${evalDelim}"${evalContent}"${evalDelim};
878
+ pub const ALL_EVALUATOR_DOCS_JSON: &str = r${evalAllDelim}"${evalAllContent}"${evalAllDelim};
879
+ `;
880
+
881
+ fs.writeFileSync(path.join(outDir, "action_docs.rs"), content);
882
+
883
+ const modPath = path.join(outDir, "mod.rs");
884
+ const modContent = `//! Auto-generated docs module.\n\npub mod action_docs;\n`;
885
+ fs.writeFileSync(modPath, modContent);
886
+ }
887
+
888
+ function main() {
889
+ const actionsSpec = loadSpecs(
890
+ ACTIONS_SPECS_DIR,
891
+ CORE_ACTIONS_SPEC_PATH,
892
+ "actions",
893
+ );
894
+ const providersSpec = loadSpecs(
895
+ PROVIDERS_SPECS_DIR,
896
+ CORE_PROVIDERS_SPEC_PATH,
897
+ "providers",
898
+ );
899
+ const evaluatorsSpec = loadSpecs(
900
+ EVALUATORS_SPECS_DIR,
901
+ CORE_EVALUATORS_SPEC_PATH,
902
+ "evaluators",
903
+ );
904
+
905
+ generateTypeScript(actionsSpec, providersSpec, evaluatorsSpec);
906
+ generatePython(actionsSpec, providersSpec, evaluatorsSpec);
907
+ generateRust(actionsSpec, providersSpec, evaluatorsSpec);
908
+
909
+ console.log("Generated action/provider/evaluator docs.");
910
+ }
911
+
912
+ main();