@elizaos/prompts 2.0.0-alpha.98 → 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.
@@ -1,19 +1,10 @@
1
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
-
2
+ import { execFileSync } from "node:child_process";
14
3
  import fs from "node:fs";
15
4
  import path from "node:path";
16
5
  import { fileURLToPath } from "node:url";
6
+ import { ensureDirectory, readJson } from "./file-utils.js";
7
+ import { compressPromptDescription } from "./prompt-compression.js";
17
8
 
18
9
  const __filename = fileURLToPath(import.meta.url);
19
10
  const __dirname = path.dirname(__filename);
@@ -23,14 +14,12 @@ const PROMPTS_ROOT = path.resolve(__dirname, "..");
23
14
 
24
15
  const ACTIONS_SPECS_DIR = path.join(PROMPTS_ROOT, "specs", "actions");
25
16
  const PROVIDERS_SPECS_DIR = path.join(PROMPTS_ROOT, "specs", "providers");
26
- const EVALUATORS_SPECS_DIR = path.join(PROMPTS_ROOT, "specs", "evaluators");
27
17
 
28
18
  const CORE_ACTIONS_SPEC_PATH = path.join(ACTIONS_SPECS_DIR, "core.json");
29
19
  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
20
 
32
21
  /**
33
- * @typedef {"string" | "number" | "boolean" | "object" | "array"} JsonSchemaType
22
+ * @typedef {"string" | "number" | "integer" | "boolean" | "object" | "array"} JsonSchemaType
34
23
  */
35
24
 
36
25
  /**
@@ -55,6 +44,28 @@ function assertString(value, name) {
55
44
  }
56
45
  }
57
46
 
47
+ /**
48
+ * @param {Record<string, unknown>} value
49
+ * @param {string} name
50
+ */
51
+ function assertCompressedDescriptionAliases(value, name) {
52
+ if (value.descriptionCompressed !== undefined) {
53
+ assertString(value.descriptionCompressed, `${name}.descriptionCompressed`);
54
+ }
55
+ if (value.compressedDescription !== undefined) {
56
+ assertString(value.compressedDescription, `${name}.compressedDescription`);
57
+ }
58
+ if (
59
+ typeof value.descriptionCompressed === "string" &&
60
+ typeof value.compressedDescription === "string" &&
61
+ value.descriptionCompressed !== value.compressedDescription
62
+ ) {
63
+ throw new Error(
64
+ `${name}.descriptionCompressed and ${name}.compressedDescription must match when both are provided`,
65
+ );
66
+ }
67
+ }
68
+
58
69
  /**
59
70
  * @param {unknown} value
60
71
  * @param {string} name
@@ -102,11 +113,25 @@ function assertExampleValuesArray(value, name) {
102
113
  */
103
114
  function assertParameterSchema(schema, name) {
104
115
  assertRecord(schema, name);
116
+ if (Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
117
+ for (let i = 0; i < schema.oneOf.length; i++) {
118
+ assertParameterSchema(schema.oneOf[i], `${name}.oneOf[${i}]`);
119
+ }
120
+ return;
121
+ }
122
+ if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
123
+ for (let i = 0; i < schema.anyOf.length; i++) {
124
+ assertParameterSchema(schema.anyOf[i], `${name}.anyOf[${i}]`);
125
+ }
126
+ return;
127
+ }
105
128
  const t = schema.type;
106
129
  assertString(t, `${name}.type`);
107
- if (!["string", "number", "boolean", "object", "array"].includes(t)) {
130
+ if (
131
+ !["string", "number", "integer", "boolean", "object", "array"].includes(t)
132
+ ) {
108
133
  throw new Error(
109
- `${name}.type must be one of string|number|boolean|object|array`,
134
+ `${name}.type must be one of string|number|integer|boolean|object|array`,
110
135
  );
111
136
  }
112
137
  if (schema.enum !== undefined) {
@@ -144,6 +169,7 @@ function assertActionParameter(param, name) {
144
169
  assertRecord(param, name);
145
170
  assertString(param.name, `${name}.name`);
146
171
  assertString(param.description, `${name}.description`);
172
+ assertCompressedDescriptionAliases(param, name);
147
173
  if (param.required !== undefined) {
148
174
  assertBoolean(param.required, `${name}.required`);
149
175
  }
@@ -162,6 +188,7 @@ function assertActionDoc(action, name) {
162
188
  assertRecord(action, name);
163
189
  assertString(action.name, `${name}.name`);
164
190
  assertString(action.description, `${name}.description`);
191
+ assertCompressedDescriptionAliases(action, name);
165
192
  if (action.similes !== undefined) {
166
193
  assertArray(action.similes, `${name}.similes`);
167
194
  for (let i = 0; i < action.similes.length; i++) {
@@ -191,6 +218,7 @@ function assertProviderDoc(provider, name) {
191
218
  assertRecord(provider, name);
192
219
  assertString(provider.name, `${name}.name`);
193
220
  assertString(provider.description, `${name}.description`);
221
+ assertCompressedDescriptionAliases(provider, name);
194
222
  if (
195
223
  provider.position !== undefined &&
196
224
  typeof provider.position !== "number"
@@ -202,38 +230,6 @@ function assertProviderDoc(provider, name) {
202
230
  }
203
231
  }
204
232
 
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
233
  /**
238
234
  * Recursively list .json files in a directory.
239
235
  * @param {string} rootDir
@@ -295,21 +291,6 @@ function parseProvidersSpec(root, label) {
295
291
  return { version: root.version, providers: root.providers };
296
292
  }
297
293
 
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
294
  /**
314
295
  * @param {unknown[]} docs
315
296
  * @param {string} label
@@ -332,85 +313,53 @@ function assertUniqueNames(docs, label) {
332
313
  /**
333
314
  * @param {string} dir
334
315
  * @param {string} corePath
335
- * @param {"actions" | "providers" | "evaluators"} kind
316
+ * @param {"actions" | "providers"} kind
336
317
  * @returns {{ core: { version: string, items: unknown[] }, all: { version: string, items: unknown[] } }}
337
318
  */
338
319
  function loadSpecs(dir, corePath, kind) {
339
320
  if (!fs.existsSync(corePath)) {
340
- return {
341
- core: { version: "1.0.0", items: [] },
342
- all: { version: "1.0.0", items: [] },
343
- };
321
+ throw new Error(`Missing ${kind} core spec: ${corePath}`);
344
322
  }
345
323
 
346
324
  const coreRoot = readJson(corePath);
347
325
  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
- }
326
+ const coreParsed =
327
+ kind === "actions"
328
+ ? parseActionsSpec(coreRoot, coreLabel)
329
+ : parseProvidersSpec(coreRoot, coreLabel);
357
330
 
358
331
  const allFiles = listJsonFiles(dir).filter(
359
332
  (p) => path.resolve(p) !== path.resolve(corePath),
360
333
  );
361
334
  /** @type {unknown[]} */
362
335
  const merged = [
363
- ...(kind === "actions"
364
- ? coreParsed.actions
365
- : kind === "providers"
366
- ? coreParsed.providers
367
- : coreParsed.evaluators),
336
+ ...(kind === "actions" ? coreParsed.actions : coreParsed.providers),
368
337
  ];
369
338
 
370
339
  for (const filePath of allFiles) {
371
340
  const root = readJson(filePath);
372
341
  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
- }
342
+ const parsed =
343
+ kind === "actions"
344
+ ? parseActionsSpec(root, label)
345
+ : parseProvidersSpec(root, label);
382
346
 
383
347
  if (parsed.version !== coreParsed.version) {
384
348
  throw new Error(
385
349
  `${label}.version (${parsed.version}) must match core version (${coreParsed.version})`,
386
350
  );
387
351
  }
388
- merged.push(
389
- ...(kind === "actions"
390
- ? parsed.actions
391
- : kind === "providers"
392
- ? parsed.providers
393
- : parsed.evaluators),
394
- );
352
+ merged.push(...(kind === "actions" ? parsed.actions : parsed.providers));
395
353
  }
396
354
 
397
355
  const itemsLabel =
398
- kind === "actions"
399
- ? "actions spec.actions"
400
- : kind === "providers"
401
- ? "providers spec.providers"
402
- : "evaluators spec.evaluators";
356
+ kind === "actions" ? "actions spec.actions" : "providers spec.providers";
403
357
  assertUniqueNames(merged, itemsLabel);
404
358
 
405
359
  return {
406
360
  core: {
407
361
  version: coreParsed.version,
408
- items:
409
- kind === "actions"
410
- ? coreParsed.actions
411
- : kind === "providers"
412
- ? coreParsed.providers
413
- : coreParsed.evaluators,
362
+ items: kind === "actions" ? coreParsed.actions : coreParsed.providers,
414
363
  },
415
364
  all: {
416
365
  version: coreParsed.version,
@@ -420,48 +369,81 @@ function loadSpecs(dir, corePath, kind) {
420
369
  }
421
370
 
422
371
  /**
423
- * Ensures a directory exists, creating it and parent directories if necessary.
424
- * @param {string} dir - The directory path to ensure exists
425
- * @throws {Error} If the directory path is empty or whitespace-only
372
+ * @param {Record<string, unknown>} doc
373
+ * @returns {string | undefined}
426
374
  */
427
- function ensureDir(dir) {
428
- if (!dir || dir.trim() === "") {
429
- throw new Error("Directory path cannot be empty");
375
+ function getCompressedAlias(doc) {
376
+ const preferred = doc.descriptionCompressed;
377
+ if (typeof preferred === "string" && preferred.trim()) {
378
+ return preferred;
430
379
  }
431
- fs.mkdirSync(dir, { recursive: true });
380
+ const alias = doc.compressedDescription;
381
+ if (typeof alias === "string" && alias.trim()) {
382
+ return alias;
383
+ }
384
+ return undefined;
432
385
  }
433
386
 
434
387
  /**
435
- * @param {string} content
436
- * @returns {{ content: string, hashCount: number }}
388
+ * @param {Record<string, unknown>} doc
437
389
  */
438
- function escapeRustRawString(content) {
439
- let hashCount = 1;
440
- while (content.includes(`"${"#".repeat(hashCount)}`)) {
441
- hashCount++;
390
+ function normalizeCompressedDescription(doc) {
391
+ if (typeof doc.description !== "string") {
392
+ return;
442
393
  }
443
- return { content, hashCount };
394
+ doc.descriptionCompressed =
395
+ getCompressedAlias(doc) ?? compressPromptDescription(doc.description);
444
396
  }
445
397
 
446
398
  /**
447
- * Escape a string for use in Python triple-quoted string.
448
- * JSON won't normally contain `"""` but we escape defensively.
449
- * @param {string} content
450
- * @returns {string}
399
+ * @param {Record<string, unknown>} action
451
400
  */
452
- function escapePythonTripleQuoted(content) {
453
- return content.replace(/\\/g, "\\\\").replace(/"""/g, '\\"\\"\\"');
401
+ function normalizeActionDoc(action) {
402
+ normalizeCompressedDescription(action);
403
+ if (!Array.isArray(action.parameters)) {
404
+ return;
405
+ }
406
+ for (const p of action.parameters) {
407
+ if (!p || typeof p !== "object") {
408
+ continue;
409
+ }
410
+ const param = /** @type {Record<string, unknown>} */ (p);
411
+ if (typeof param.description !== "string") {
412
+ continue;
413
+ }
414
+ normalizeCompressedDescription(param);
415
+ }
454
416
  }
455
417
 
456
- function generateTypeScript(actionsSpec, providersSpec, evaluatorsSpec) {
457
- const outDir = path.join(
458
- REPO_ROOT,
459
- "packages",
460
- "typescript",
461
- "src",
462
- "generated",
463
- );
464
- ensureDir(outDir);
418
+ /**
419
+ * @param {Record<string, unknown>} provider
420
+ */
421
+ function normalizeProviderDoc(provider) {
422
+ normalizeCompressedDescription(provider);
423
+ }
424
+
425
+ /**
426
+ * @param {{ core: { items: unknown[] }; all: { items: unknown[] } }} actionsSpec
427
+ * @param {{ core: { items: unknown[] }; all: { items: unknown[] } }} providersSpec
428
+ */
429
+ function normalizeSpecsInPlace(actionsSpec, providersSpec) {
430
+ for (const action of actionsSpec.core.items) {
431
+ normalizeActionDoc(/** @type {Record<string, unknown>} */ (action));
432
+ }
433
+ for (const action of actionsSpec.all.items) {
434
+ normalizeActionDoc(/** @type {Record<string, unknown>} */ (action));
435
+ }
436
+ for (const p of providersSpec.core.items) {
437
+ normalizeProviderDoc(/** @type {Record<string, unknown>} */ (p));
438
+ }
439
+ for (const p of providersSpec.all.items) {
440
+ normalizeProviderDoc(/** @type {Record<string, unknown>} */ (p));
441
+ }
442
+ }
443
+
444
+ function generateTypeScript(actionsSpec, providersSpec) {
445
+ const outDir = path.join(REPO_ROOT, "packages", "core", "src", "generated");
446
+ ensureDirectory(outDir);
465
447
 
466
448
  const actionsJson = JSON.stringify(
467
449
  { version: actionsSpec.core.version, actions: actionsSpec.core.items },
@@ -486,37 +468,29 @@ function generateTypeScript(actionsSpec, providersSpec, evaluatorsSpec) {
486
468
  null,
487
469
  2,
488
470
  );
489
- const evaluatorsJson = JSON.stringify(
490
- {
491
- version: evaluatorsSpec.core.version,
492
- evaluators: evaluatorsSpec.core.items,
493
- },
494
- null,
495
- 2,
496
- );
497
- const evaluatorsAllJson = JSON.stringify(
498
- {
499
- version: evaluatorsSpec.all.version,
500
- evaluators: evaluatorsSpec.all.items,
501
- },
502
- null,
503
- 2,
504
- );
505
471
 
506
472
  const content = `/**
507
- * Auto-generated canonical action/provider/evaluator docs.
473
+ * Auto-generated action/provider docs.
508
474
  * DO NOT EDIT - Generated from packages/prompts/specs/**.
509
475
  */
510
476
 
511
- export type ActionDocParameterExampleValue = string | number | boolean | null;
477
+ export type ActionDocParameterExampleValue =
478
+ | string
479
+ | number
480
+ | boolean
481
+ | null
482
+ | readonly ActionDocParameterExampleValue[]
483
+ | { readonly [key: string]: ActionDocParameterExampleValue };
512
484
 
513
485
  export type ActionDocParameterSchema = {
514
- type: "string" | "number" | "boolean" | "object" | "array";
486
+ type: "string" | "number" | "integer" | "boolean" | "object" | "array";
515
487
  description?: string;
516
488
  default?: ActionDocParameterExampleValue;
517
489
  enum?: string[];
518
490
  properties?: Record<string, ActionDocParameterSchema>;
519
491
  items?: ActionDocParameterSchema;
492
+ oneOf?: ActionDocParameterSchema[];
493
+ anyOf?: ActionDocParameterSchema[];
520
494
  minimum?: number;
521
495
  maximum?: number;
522
496
  pattern?: string;
@@ -525,6 +499,8 @@ export type ActionDocParameterSchema = {
525
499
  export type ActionDocParameter = {
526
500
  name: string;
527
501
  description: string;
502
+ descriptionCompressed?: string;
503
+ compressedDescription?: string;
528
504
  required?: boolean;
529
505
  schema: ActionDocParameterSchema;
530
506
  examples?: readonly ActionDocParameterExampleValue[];
@@ -547,6 +523,8 @@ export type ActionDocExampleMessage = {
547
523
  export type ActionDoc = {
548
524
  name: string;
549
525
  description: string;
526
+ descriptionCompressed?: string;
527
+ compressedDescription?: string;
550
528
  similes?: readonly string[];
551
529
  parameters?: readonly ActionDocParameter[];
552
530
  examples?: readonly (readonly ActionDocExampleMessage[])[];
@@ -556,338 +534,39 @@ export type ActionDoc = {
556
534
  export type ProviderDoc = {
557
535
  name: string;
558
536
  description: string;
537
+ descriptionCompressed?: string;
538
+ compressedDescription?: string;
559
539
  position?: number;
560
540
  dynamic?: boolean;
561
541
  };
562
542
 
563
- export type EvaluatorDocMessageContent = {
564
- text: string;
565
- type?: string;
566
- };
567
-
568
- export type EvaluatorDocMessage = {
569
- name: string;
570
- content: EvaluatorDocMessageContent;
571
- };
572
-
573
- export type EvaluatorDocExample = {
574
- prompt: string;
575
- messages: readonly EvaluatorDocMessage[];
576
- outcome: string;
577
- };
578
-
579
- export type EvaluatorDoc = {
580
- name: string;
581
- description: string;
582
- similes?: readonly string[];
583
- alwaysRun?: boolean;
584
- examples?: readonly EvaluatorDocExample[];
585
- };
586
-
587
543
  export const coreActionsSpecVersion = ${JSON.stringify(actionsSpec.core.version)} as const;
588
544
  export const allActionsSpecVersion = ${JSON.stringify(actionsSpec.all.version)} as const;
589
545
  export const coreProvidersSpecVersion = ${JSON.stringify(providersSpec.core.version)} as const;
590
546
  export const allProvidersSpecVersion = ${JSON.stringify(providersSpec.all.version)} as const;
591
- export const coreEvaluatorsSpecVersion = ${JSON.stringify(evaluatorsSpec.core.version)} as const;
592
- export const allEvaluatorsSpecVersion = ${JSON.stringify(evaluatorsSpec.all.version)} as const;
593
547
 
594
548
  export const coreActionsSpec = ${actionsJson} as const satisfies { version: string; actions: readonly ActionDoc[] };
595
549
  export const allActionsSpec = ${actionsAllJson} as const satisfies { version: string; actions: readonly ActionDoc[] };
596
550
  export const coreProvidersSpec = ${providersJson} as const satisfies { version: string; providers: readonly ProviderDoc[] };
597
551
  export const allProvidersSpec = ${providersAllJson} as const satisfies { version: string; providers: readonly ProviderDoc[] };
598
- export const coreEvaluatorsSpec = ${evaluatorsJson} as const satisfies {
599
- version: string;
600
- evaluators: readonly EvaluatorDoc[];
601
- };
602
- export const allEvaluatorsSpec = ${evaluatorsAllJson} as const satisfies {
603
- version: string;
604
- evaluators: readonly EvaluatorDoc[];
605
- };
606
552
 
607
553
  export const coreActionDocs: readonly ActionDoc[] = coreActionsSpec.actions;
608
554
  export const allActionDocs: readonly ActionDoc[] = allActionsSpec.actions;
609
555
  export const coreProviderDocs: readonly ProviderDoc[] = coreProvidersSpec.providers;
610
556
  export const allProviderDocs: readonly ProviderDoc[] = allProvidersSpec.providers;
611
- export const coreEvaluatorDocs: readonly EvaluatorDoc[] = coreEvaluatorsSpec.evaluators;
612
- export const allEvaluatorDocs: readonly EvaluatorDoc[] = allEvaluatorsSpec.evaluators;
613
557
  `;
614
558
 
615
- fs.writeFileSync(path.join(outDir, "action-docs.ts"), content);
616
- }
617
-
618
- function generatePython(actionsSpec, providersSpec, evaluatorsSpec) {
619
- const outDir = path.join(
620
- REPO_ROOT,
621
- "packages",
622
- "python",
623
- "elizaos",
624
- "generated",
625
- );
626
- ensureDir(outDir);
627
-
628
- const initPath = path.join(outDir, "__init__.py");
629
- if (!fs.existsSync(initPath)) {
630
- fs.writeFileSync(initPath, '"""Auto-generated module package."""\n');
559
+ const actionDocsPath = path.join(outDir, "action-docs.ts");
560
+ fs.writeFileSync(actionDocsPath, content);
561
+ try {
562
+ execFileSync(
563
+ "bunx",
564
+ ["@biomejs/biome", "check", "--write", actionDocsPath],
565
+ { cwd: REPO_ROOT, stdio: "pipe" },
566
+ );
567
+ } catch (error) {
568
+ throw new Error(`Failed to format ${actionDocsPath}`, { cause: error });
631
569
  }
632
-
633
- const actionsJson = JSON.stringify(
634
- { version: actionsSpec.core.version, actions: actionsSpec.core.items },
635
- null,
636
- 2,
637
- );
638
- const actionsAllJson = JSON.stringify(
639
- { version: actionsSpec.all.version, actions: actionsSpec.all.items },
640
- null,
641
- 2,
642
- );
643
- const providersJson = JSON.stringify(
644
- {
645
- version: providersSpec.core.version,
646
- providers: providersSpec.core.items,
647
- },
648
- null,
649
- 2,
650
- );
651
- const providersAllJson = JSON.stringify(
652
- { version: providersSpec.all.version, providers: providersSpec.all.items },
653
- null,
654
- 2,
655
- );
656
- const evaluatorsJson = JSON.stringify(
657
- {
658
- version: evaluatorsSpec.core.version,
659
- evaluators: evaluatorsSpec.core.items,
660
- },
661
- null,
662
- 2,
663
- );
664
- const evaluatorsAllJson = JSON.stringify(
665
- {
666
- version: evaluatorsSpec.all.version,
667
- evaluators: evaluatorsSpec.all.items,
668
- },
669
- null,
670
- 2,
671
- );
672
-
673
- const content = `"""
674
- Auto-generated canonical action/provider/evaluator docs.
675
- DO NOT EDIT - Generated from packages/prompts/specs/**.
676
- """
677
-
678
- from __future__ import annotations
679
-
680
- import json
681
-
682
- from typing import Literal, TypedDict
683
-
684
-
685
- JsonSchemaType = Literal["string", "number", "boolean", "object", "array"]
686
- ActionDocParameterExampleValue = str | int | float | bool | None
687
-
688
-
689
- class ActionDocParameterSchema(TypedDict, total=False):
690
- type: JsonSchemaType
691
- description: str
692
- default: ActionDocParameterExampleValue
693
- enum: list[str]
694
- properties: dict[str, "ActionDocParameterSchema"]
695
- items: "ActionDocParameterSchema"
696
- minimum: float
697
- maximum: float
698
- pattern: str
699
-
700
-
701
- class ActionDocParameter(TypedDict, total=False):
702
- name: str
703
- description: str
704
- required: bool
705
- schema: ActionDocParameterSchema
706
- examples: list[ActionDocParameterExampleValue]
707
-
708
-
709
- class ActionDocExampleCall(TypedDict, total=False):
710
- user: str
711
- actions: list[str]
712
- params: dict[str, dict[str, ActionDocParameterExampleValue]]
713
-
714
-
715
- class ActionDocExampleMessage(TypedDict, total=False):
716
- name: str
717
- content: dict[str, object]
718
-
719
-
720
- class ActionDoc(TypedDict, total=False):
721
- name: str
722
- description: str
723
- similes: list[str]
724
- parameters: list[ActionDocParameter]
725
- examples: list[list[ActionDocExampleMessage]]
726
- exampleCalls: list[ActionDocExampleCall]
727
-
728
-
729
- class ProviderDoc(TypedDict, total=False):
730
- name: str
731
- description: str
732
- position: int
733
- dynamic: bool
734
-
735
-
736
- class EvaluatorDocMessageContent(TypedDict, total=False):
737
- text: str
738
- type: str
739
-
740
-
741
- class EvaluatorDocMessage(TypedDict):
742
- name: str
743
- content: EvaluatorDocMessageContent
744
-
745
-
746
- class EvaluatorDocExample(TypedDict):
747
- prompt: str
748
- messages: list[EvaluatorDocMessage]
749
- outcome: str
750
-
751
-
752
- class EvaluatorDoc(TypedDict, total=False):
753
- name: str
754
- description: str
755
- similes: list[str]
756
- alwaysRun: bool
757
- examples: list[EvaluatorDocExample]
758
-
759
-
760
- core_actions_spec_version: str = ${JSON.stringify(actionsSpec.core.version)}
761
- all_actions_spec_version: str = ${JSON.stringify(actionsSpec.all.version)}
762
- core_providers_spec_version: str = ${JSON.stringify(providersSpec.core.version)}
763
- all_providers_spec_version: str = ${JSON.stringify(providersSpec.all.version)}
764
- core_evaluators_spec_version: str = ${JSON.stringify(evaluatorsSpec.core.version)}
765
- all_evaluators_spec_version: str = ${JSON.stringify(evaluatorsSpec.all.version)}
766
-
767
- _CORE_ACTION_DOCS_JSON = """${escapePythonTripleQuoted(actionsJson)}"""
768
- _ALL_ACTION_DOCS_JSON = """${escapePythonTripleQuoted(actionsAllJson)}"""
769
- _CORE_PROVIDER_DOCS_JSON = """${escapePythonTripleQuoted(providersJson)}"""
770
- _ALL_PROVIDER_DOCS_JSON = """${escapePythonTripleQuoted(providersAllJson)}"""
771
- _CORE_EVALUATOR_DOCS_JSON = """${escapePythonTripleQuoted(evaluatorsJson)}"""
772
- _ALL_EVALUATOR_DOCS_JSON = """${escapePythonTripleQuoted(evaluatorsAllJson)}"""
773
-
774
- core_action_docs: dict[str, object] = json.loads(_CORE_ACTION_DOCS_JSON)
775
- all_action_docs: dict[str, object] = json.loads(_ALL_ACTION_DOCS_JSON)
776
- core_provider_docs: dict[str, object] = json.loads(_CORE_PROVIDER_DOCS_JSON)
777
- all_provider_docs: dict[str, object] = json.loads(_ALL_PROVIDER_DOCS_JSON)
778
- core_evaluator_docs: dict[str, object] = json.loads(_CORE_EVALUATOR_DOCS_JSON)
779
- all_evaluator_docs: dict[str, object] = json.loads(_ALL_EVALUATOR_DOCS_JSON)
780
-
781
- __all__ = [
782
- "ActionDoc",
783
- "ActionDocExampleCall",
784
- "ActionDocExampleMessage",
785
- "ActionDocParameter",
786
- "ActionDocParameterSchema",
787
- "ActionDocParameterExampleValue",
788
- "ProviderDoc",
789
- "EvaluatorDoc",
790
- "EvaluatorDocExample",
791
- "EvaluatorDocMessage",
792
- "EvaluatorDocMessageContent",
793
- "core_actions_spec_version",
794
- "all_actions_spec_version",
795
- "core_providers_spec_version",
796
- "all_providers_spec_version",
797
- "core_evaluators_spec_version",
798
- "all_evaluators_spec_version",
799
- "core_action_docs",
800
- "all_action_docs",
801
- "core_provider_docs",
802
- "all_provider_docs",
803
- "core_evaluator_docs",
804
- "all_evaluator_docs",
805
- ]
806
- `;
807
-
808
- fs.writeFileSync(path.join(outDir, "action_docs.py"), content);
809
- }
810
-
811
- function generateRust(actionsSpec, providersSpec, evaluatorsSpec) {
812
- const outDir = path.join(REPO_ROOT, "packages", "rust", "src", "generated");
813
- ensureDir(outDir);
814
-
815
- const actionsJson = JSON.stringify(
816
- { version: actionsSpec.core.version, actions: actionsSpec.core.items },
817
- null,
818
- 2,
819
- );
820
- const actionsAllJson = JSON.stringify(
821
- { version: actionsSpec.all.version, actions: actionsSpec.all.items },
822
- null,
823
- 2,
824
- );
825
- const providersJson = JSON.stringify(
826
- {
827
- version: providersSpec.core.version,
828
- providers: providersSpec.core.items,
829
- },
830
- null,
831
- 2,
832
- );
833
- const providersAllJson = JSON.stringify(
834
- { version: providersSpec.all.version, providers: providersSpec.all.items },
835
- null,
836
- 2,
837
- );
838
- const evaluatorsJson = JSON.stringify(
839
- {
840
- version: evaluatorsSpec.core.version,
841
- evaluators: evaluatorsSpec.core.items,
842
- },
843
- null,
844
- 2,
845
- );
846
- const evaluatorsAllJson = JSON.stringify(
847
- {
848
- version: evaluatorsSpec.all.version,
849
- evaluators: evaluatorsSpec.all.items,
850
- },
851
- null,
852
- 2,
853
- );
854
-
855
- const { content: actionsContent, hashCount: actionsHashCount } =
856
- escapeRustRawString(actionsJson);
857
- const { content: actionsAllContent, hashCount: actionsAllHashCount } =
858
- escapeRustRawString(actionsAllJson);
859
- const { content: providersContent, hashCount: providersHashCount } =
860
- escapeRustRawString(providersJson);
861
- const { content: providersAllContent, hashCount: providersAllHashCount } =
862
- escapeRustRawString(providersAllJson);
863
- const { content: evalContent, hashCount: evalHashCount } =
864
- escapeRustRawString(evaluatorsJson);
865
- const { content: evalAllContent, hashCount: evalAllHashCount } =
866
- escapeRustRawString(evaluatorsAllJson);
867
-
868
- const actionsDelim = "#".repeat(actionsHashCount);
869
- const actionsAllDelim = "#".repeat(actionsAllHashCount);
870
- const providersDelim = "#".repeat(providersHashCount);
871
- const providersAllDelim = "#".repeat(providersAllHashCount);
872
- const evalDelim = "#".repeat(evalHashCount);
873
- const evalAllDelim = "#".repeat(evalAllHashCount);
874
-
875
- const content = `//! Auto-generated canonical action/provider/evaluator docs.
876
- //! DO NOT EDIT - Generated from packages/prompts/specs/**.
877
-
878
- pub const CORE_ACTION_DOCS_JSON: &str = r${actionsDelim}"${actionsContent}"${actionsDelim};
879
- pub const ALL_ACTION_DOCS_JSON: &str = r${actionsAllDelim}"${actionsAllContent}"${actionsAllDelim};
880
- pub const CORE_PROVIDER_DOCS_JSON: &str = r${providersDelim}"${providersContent}"${providersDelim};
881
- pub const ALL_PROVIDER_DOCS_JSON: &str = r${providersAllDelim}"${providersAllContent}"${providersAllDelim};
882
- pub const CORE_EVALUATOR_DOCS_JSON: &str = r${evalDelim}"${evalContent}"${evalDelim};
883
- pub const ALL_EVALUATOR_DOCS_JSON: &str = r${evalAllDelim}"${evalAllContent}"${evalAllDelim};
884
- `;
885
-
886
- fs.writeFileSync(path.join(outDir, "action_docs.rs"), content);
887
-
888
- const modPath = path.join(outDir, "mod.rs");
889
- const modContent = `//! Auto-generated docs module.\n\npub mod action_docs;\n`;
890
- fs.writeFileSync(modPath, modContent);
891
570
  }
892
571
 
893
572
  function main() {
@@ -901,17 +580,12 @@ function main() {
901
580
  CORE_PROVIDERS_SPEC_PATH,
902
581
  "providers",
903
582
  );
904
- const evaluatorsSpec = loadSpecs(
905
- EVALUATORS_SPECS_DIR,
906
- CORE_EVALUATORS_SPEC_PATH,
907
- "evaluators",
908
- );
909
583
 
910
- generateTypeScript(actionsSpec, providersSpec, evaluatorsSpec);
911
- generatePython(actionsSpec, providersSpec, evaluatorsSpec);
912
- generateRust(actionsSpec, providersSpec, evaluatorsSpec);
584
+ normalizeSpecsInPlace(actionsSpec, providersSpec);
585
+
586
+ generateTypeScript(actionsSpec, providersSpec);
913
587
 
914
- console.log("Generated action/provider/evaluator docs.");
588
+ console.log("Generated action/provider docs.");
915
589
  }
916
590
 
917
591
  main();