@mistralys/persona-builder 2.3.0 → 2.4.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/cli.js CHANGED
@@ -123,7 +123,7 @@ function runBuildContext(plugins, ctx, persona, suite, target) {
123
123
  let accumulated = ctx;
124
124
  for (const plugin of plugins) {
125
125
  if (typeof plugin.onBuildContext === "function") {
126
- accumulated = plugin.onBuildContext(accumulated, persona, suite, target);
126
+ accumulated = plugin.onBuildContext(accumulated, persona, suite, target) ?? accumulated;
127
127
  }
128
128
  }
129
129
  return accumulated;
@@ -132,11 +132,29 @@ function runPostRender(plugins, rendered, persona, target) {
132
132
  let output = rendered;
133
133
  for (const plugin of plugins) {
134
134
  if (typeof plugin.onPostRender === "function") {
135
- output = plugin.onPostRender(output, persona, target);
135
+ output = plugin.onPostRender(output, persona, target) ?? output;
136
136
  }
137
137
  }
138
138
  return output;
139
139
  }
140
+ function runPartials(plugins, partialsMap, suiteName, suite) {
141
+ let accumulated = partialsMap;
142
+ for (const plugin of plugins) {
143
+ if (typeof plugin.onPartials === "function") {
144
+ accumulated = plugin.onPartials(accumulated, suiteName, suite) ?? accumulated;
145
+ }
146
+ }
147
+ return accumulated;
148
+ }
149
+ function runPersonaPartials(plugins, partialsMap, persona, context, suite, target) {
150
+ let accumulated = partialsMap;
151
+ for (const plugin of plugins) {
152
+ if (typeof plugin.onPersonaPartials === "function") {
153
+ accumulated = plugin.onPersonaPartials(accumulated, persona, context, suite, target) ?? accumulated;
154
+ }
155
+ }
156
+ return accumulated;
157
+ }
140
158
  function runValidate(plugins, persona, suite, target) {
141
159
  const results = [];
142
160
  for (const plugin of plugins) {
@@ -359,9 +377,20 @@ async function buildAgentNameMap(config) {
359
377
  }
360
378
  return agentMap;
361
379
  }
362
- function buildContext(personaMeta, sharedMeta, agentMap = {}, target, registry) {
380
+ function buildContext(options) {
381
+ const {
382
+ personaMeta,
383
+ sharedMeta,
384
+ agentMap = {},
385
+ target,
386
+ registry,
387
+ configVariables,
388
+ suiteVariables
389
+ } = options;
363
390
  const version = typeof personaMeta["version"] === "string" ? personaMeta["version"] : typeof sharedMeta["default_version"] === "string" ? sharedMeta["default_version"] : "0.0.0";
364
391
  const merged = {
392
+ ...configVariables ?? {},
393
+ ...suiteVariables ?? {},
365
394
  ...sharedMeta,
366
395
  ...personaMeta,
367
396
  version
@@ -416,16 +445,32 @@ function buildContext(personaMeta, sharedMeta, agentMap = {}, target, registry)
416
445
  }
417
446
  async function buildPersona(personaYamlPath, suiteName, suiteConfig, sharedMeta, partialsMap, config, plugins, target, agentMap = {}, registry = defaultRegistry) {
418
447
  const personaMeta = await loadPersonaYaml(personaYamlPath);
419
- let context = buildContext(personaMeta, sharedMeta, agentMap, target, registry);
448
+ let context = buildContext({
449
+ personaMeta,
450
+ sharedMeta,
451
+ agentMap,
452
+ target,
453
+ registry,
454
+ configVariables: config.variables,
455
+ suiteVariables: suiteConfig.variables
456
+ });
420
457
  const personaMetaTyped = personaMeta;
421
458
  context = runBuildContext(plugins, context, personaMetaTyped, suiteConfig, target);
459
+ const personaPartialsMap = runPersonaPartials(
460
+ plugins,
461
+ { ...partialsMap },
462
+ personaMetaTyped,
463
+ context,
464
+ suiteConfig,
465
+ target
466
+ );
422
467
  const fmTemplate = resolveFrontmatterTemplate(target, plugins, config.frontmatter, registry);
423
468
  const contentBasename = path2.basename(personaYamlPath, ".yaml") + ".md";
424
469
  const frontmatter = renderFrontmatter(fmTemplate, context, contentBasename);
425
470
  const contentSubdir = suiteConfig.contentSubdir ?? "content";
426
471
  const contentPath = path2.join(suiteConfig.srcDir, contentSubdir, contentBasename);
427
472
  const bodyTemplate = normalizeNewlines(await readFile(contentPath, "utf8"));
428
- let body = resolvePartials(bodyTemplate, partialsMap);
473
+ let body = resolvePartials(bodyTemplate, personaPartialsMap);
429
474
  body = resolveConditionals(body, context);
430
475
  body = resolveVariables(body, context, contentBasename);
431
476
  body = collapseBlankLines(body);
@@ -463,7 +508,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
463
508
  const metaSubdir = suiteConfig.metaSubdir ?? "meta";
464
509
  const sharedYamlPath = path2.join(suiteConfig.srcDir, metaSubdir, "_shared.yaml");
465
510
  const sharedMeta = await loadRawYaml(sharedYamlPath);
466
- let partialsMap = {};
511
+ let partialsMap = { ...config.partials ?? {} };
467
512
  if (config.sharedPartialsDir && existsSync(config.sharedPartialsDir)) {
468
513
  partialsMap = { ...partialsMap, ...await loadPartials(config.sharedPartialsDir) };
469
514
  }
@@ -473,6 +518,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
473
518
  partialsMap = { ...partialsMap, ...await loadPartials(suitePartialsDir) };
474
519
  }
475
520
  runSuiteInit(plugins, suiteConfig, sharedMeta);
521
+ partialsMap = runPartials(plugins, partialsMap, suiteName, suiteConfig);
476
522
  const personaYamlPaths = await discoverSuitePersonaYamls(suiteConfig);
477
523
  const results = [];
478
524
  for (const yamlPath of personaYamlPaths) {