@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/README.md +3 -0
- package/dist/cli.cjs +52 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +52 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +54 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +215 -26
- package/dist/index.d.ts +215 -26
- package/dist/index.js +53 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -157,7 +157,7 @@ function runBuildContext(plugins, ctx, persona, suite, target) {
|
|
|
157
157
|
let accumulated = ctx;
|
|
158
158
|
for (const plugin of plugins) {
|
|
159
159
|
if (typeof plugin.onBuildContext === "function") {
|
|
160
|
-
accumulated = plugin.onBuildContext(accumulated, persona, suite, target);
|
|
160
|
+
accumulated = plugin.onBuildContext(accumulated, persona, suite, target) ?? accumulated;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
return accumulated;
|
|
@@ -166,11 +166,29 @@ function runPostRender(plugins, rendered, persona, target) {
|
|
|
166
166
|
let output = rendered;
|
|
167
167
|
for (const plugin of plugins) {
|
|
168
168
|
if (typeof plugin.onPostRender === "function") {
|
|
169
|
-
output = plugin.onPostRender(output, persona, target);
|
|
169
|
+
output = plugin.onPostRender(output, persona, target) ?? output;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
return output;
|
|
173
173
|
}
|
|
174
|
+
function runPartials(plugins, partialsMap, suiteName, suite) {
|
|
175
|
+
let accumulated = partialsMap;
|
|
176
|
+
for (const plugin of plugins) {
|
|
177
|
+
if (typeof plugin.onPartials === "function") {
|
|
178
|
+
accumulated = plugin.onPartials(accumulated, suiteName, suite) ?? accumulated;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return accumulated;
|
|
182
|
+
}
|
|
183
|
+
function runPersonaPartials(plugins, partialsMap, persona, context, suite, target) {
|
|
184
|
+
let accumulated = partialsMap;
|
|
185
|
+
for (const plugin of plugins) {
|
|
186
|
+
if (typeof plugin.onPersonaPartials === "function") {
|
|
187
|
+
accumulated = plugin.onPersonaPartials(accumulated, persona, context, suite, target) ?? accumulated;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return accumulated;
|
|
191
|
+
}
|
|
174
192
|
function runValidate(plugins, persona, suite, target) {
|
|
175
193
|
const results = [];
|
|
176
194
|
for (const plugin of plugins) {
|
|
@@ -393,9 +411,20 @@ async function buildAgentNameMap(config) {
|
|
|
393
411
|
}
|
|
394
412
|
return agentMap;
|
|
395
413
|
}
|
|
396
|
-
function buildContext(
|
|
414
|
+
function buildContext(options) {
|
|
415
|
+
const {
|
|
416
|
+
personaMeta,
|
|
417
|
+
sharedMeta,
|
|
418
|
+
agentMap = {},
|
|
419
|
+
target,
|
|
420
|
+
registry,
|
|
421
|
+
configVariables,
|
|
422
|
+
suiteVariables
|
|
423
|
+
} = options;
|
|
397
424
|
const version = typeof personaMeta["version"] === "string" ? personaMeta["version"] : typeof sharedMeta["default_version"] === "string" ? sharedMeta["default_version"] : "0.0.0";
|
|
398
425
|
const merged = {
|
|
426
|
+
...configVariables ?? {},
|
|
427
|
+
...suiteVariables ?? {},
|
|
399
428
|
...sharedMeta,
|
|
400
429
|
...personaMeta,
|
|
401
430
|
version
|
|
@@ -450,16 +479,32 @@ function buildContext(personaMeta, sharedMeta, agentMap = {}, target, registry)
|
|
|
450
479
|
}
|
|
451
480
|
async function buildPersona(personaYamlPath, suiteName, suiteConfig, sharedMeta, partialsMap, config, plugins, target, agentMap = {}, registry = defaultRegistry) {
|
|
452
481
|
const personaMeta = await loadPersonaYaml(personaYamlPath);
|
|
453
|
-
let context = buildContext(
|
|
482
|
+
let context = buildContext({
|
|
483
|
+
personaMeta,
|
|
484
|
+
sharedMeta,
|
|
485
|
+
agentMap,
|
|
486
|
+
target,
|
|
487
|
+
registry,
|
|
488
|
+
configVariables: config.variables,
|
|
489
|
+
suiteVariables: suiteConfig.variables
|
|
490
|
+
});
|
|
454
491
|
const personaMetaTyped = personaMeta;
|
|
455
492
|
context = runBuildContext(plugins, context, personaMetaTyped, suiteConfig, target);
|
|
493
|
+
const personaPartialsMap = runPersonaPartials(
|
|
494
|
+
plugins,
|
|
495
|
+
{ ...partialsMap },
|
|
496
|
+
personaMetaTyped,
|
|
497
|
+
context,
|
|
498
|
+
suiteConfig,
|
|
499
|
+
target
|
|
500
|
+
);
|
|
456
501
|
const fmTemplate = resolveFrontmatterTemplate(target, plugins, config.frontmatter, registry);
|
|
457
502
|
const contentBasename = path4__default.default.basename(personaYamlPath, ".yaml") + ".md";
|
|
458
503
|
const frontmatter = renderFrontmatter(fmTemplate, context, contentBasename);
|
|
459
504
|
const contentSubdir = suiteConfig.contentSubdir ?? "content";
|
|
460
505
|
const contentPath = path4__default.default.join(suiteConfig.srcDir, contentSubdir, contentBasename);
|
|
461
506
|
const bodyTemplate = normalizeNewlines(await promises.readFile(contentPath, "utf8"));
|
|
462
|
-
let body = resolvePartials(bodyTemplate,
|
|
507
|
+
let body = resolvePartials(bodyTemplate, personaPartialsMap);
|
|
463
508
|
body = resolveConditionals(body, context);
|
|
464
509
|
body = resolveVariables(body, context, contentBasename);
|
|
465
510
|
body = collapseBlankLines(body);
|
|
@@ -497,7 +542,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
|
|
|
497
542
|
const metaSubdir = suiteConfig.metaSubdir ?? "meta";
|
|
498
543
|
const sharedYamlPath = path4__default.default.join(suiteConfig.srcDir, metaSubdir, "_shared.yaml");
|
|
499
544
|
const sharedMeta = await loadRawYaml(sharedYamlPath);
|
|
500
|
-
let partialsMap = {};
|
|
545
|
+
let partialsMap = { ...config.partials ?? {} };
|
|
501
546
|
if (config.sharedPartialsDir && fs.existsSync(config.sharedPartialsDir)) {
|
|
502
547
|
partialsMap = { ...partialsMap, ...await loadPartials(config.sharedPartialsDir) };
|
|
503
548
|
}
|
|
@@ -507,6 +552,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
|
|
|
507
552
|
partialsMap = { ...partialsMap, ...await loadPartials(suitePartialsDir) };
|
|
508
553
|
}
|
|
509
554
|
runSuiteInit(plugins, suiteConfig, sharedMeta);
|
|
555
|
+
partialsMap = runPartials(plugins, partialsMap, suiteName, suiteConfig);
|
|
510
556
|
const personaYamlPaths = await discoverSuitePersonaYamls(suiteConfig);
|
|
511
557
|
const results = [];
|
|
512
558
|
for (const yamlPath of personaYamlPaths) {
|
|
@@ -648,6 +694,8 @@ exports.resolveFrontmatterTemplate = resolveFrontmatterTemplate;
|
|
|
648
694
|
exports.resolvePartials = resolvePartials;
|
|
649
695
|
exports.resolveVariables = resolveVariables;
|
|
650
696
|
exports.runBuildContext = runBuildContext;
|
|
697
|
+
exports.runPartials = runPartials;
|
|
698
|
+
exports.runPersonaPartials = runPersonaPartials;
|
|
651
699
|
exports.runPostRender = runPostRender;
|
|
652
700
|
exports.runSuiteInit = runSuiteInit;
|
|
653
701
|
exports.runValidate = runValidate;
|