@vertesia/studio-utils 1.5.0 → 1.5.1
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/lib/conditions/index.d.ts +1 -0
- package/lib/conditions/index.d.ts.map +1 -1
- package/lib/conditions/index.js +1 -0
- package/lib/conditions/index.js.map +1 -1
- package/lib/conditions/principal-context.d.ts +55 -0
- package/lib/conditions/principal-context.d.ts.map +1 -0
- package/lib/conditions/principal-context.js +81 -0
- package/lib/conditions/principal-context.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/prompts/extract-vars.d.ts +44 -12
- package/lib/prompts/extract-vars.d.ts.map +1 -1
- package/lib/prompts/extract-vars.js +165 -75
- package/lib/prompts/extract-vars.js.map +1 -1
- package/lib/prompts/render.d.ts +7 -9
- package/lib/prompts/render.d.ts.map +1 -1
- package/lib/prompts/render.js +12 -15
- package/lib/prompts/render.js.map +1 -1
- package/lib/prompts/validate.d.ts +8 -2
- package/lib/prompts/validate.d.ts.map +1 -1
- package/lib/prompts/validate.js +87 -50
- package/lib/prompts/validate.js.map +1 -1
- package/lib/roles/system.d.ts.map +1 -1
- package/lib/roles/system.js +15 -0
- package/lib/roles/system.js.map +1 -1
- package/lib/vertesia-studio-utils.js +2 -1
- package/lib/vertesia-studio-utils.js.map +1 -1
- package/package.json +6 -5
- package/src/conditions/index.ts +6 -0
- package/src/conditions/principal-context.ts +122 -0
- package/src/index.ts +20 -1
- package/src/prompts/extract-vars.ts +212 -68
- package/src/prompts/render.test.ts +13 -2
- package/src/prompts/render.ts +24 -15
- package/src/prompts/validate.test.ts +115 -0
- package/src/prompts/validate.ts +113 -56
- package/src/roles/index.test.ts +9 -9
- package/src/roles/system.ts +16 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/prompts/render.ts"],"names":[],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IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAOxE;AAqCD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,cAAc,EAAE,CAU/G;AAED,wBAAgB,sBAAsB,CAClC,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAC5C,YAAY,EAAE,MAAM,GAAG,UAAU,GAClC,cAAc,EAAE,CAsBlB;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,aAAa,EAAE,CAwB/G"}
|
package/lib/prompts/render.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import { PromptSegmentDefType, TemplateType } from '@vertesia/common';
|
|
2
|
-
import { CompositeError, renderHandlebarsTemplate, renderJsTemplate } from '@vertesia/jst';
|
|
2
|
+
import { CompositeError, renderHandlebarsTemplate, renderJsTemplate, withTemplateSystemVariables, } from '@vertesia/jst';
|
|
3
3
|
/**
|
|
4
4
|
* Render a prompt template with the given input data.
|
|
5
5
|
*
|
|
6
|
-
* Handlebars templates use {{variable}} interpolation against `data`.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* studio-server executor
|
|
10
|
-
*
|
|
11
|
-
* and `apps/studio-server/src/executor/rendering/template.ts`). Listing it here keeps
|
|
12
|
-
* the Playground preview and `validatePrompt` in sync with runtime resolution — a JST
|
|
13
|
-
* template referencing `_model` validates fine here and renders fine in production.
|
|
6
|
+
* Handlebars templates use {{variable}} interpolation against `data`. JST (JavaScript template)
|
|
7
|
+
* bodies evaluate against `data` with the schema's top-level property names exposed as globals.
|
|
8
|
+
* Both see the system variables (`TEMPLATE_SYSTEM_VARIABLES` in `@vertesia/jst`), added here the
|
|
9
|
+
* same way the studio-server executor adds them, so a preview renders what an execution would.
|
|
10
|
+
* `_model` is only set when the caller passes `system.model` or the data already carries it.
|
|
14
11
|
*
|
|
15
12
|
* For `TemplateType.text`, the content is returned verbatim — it is static text, not a
|
|
16
13
|
* template — matching the studio-server executor (see `apps/studio-server/src/executor/
|
|
17
14
|
* rendering/template.ts`). Routing it through the JST evaluator would compile the prose as
|
|
18
15
|
* JavaScript and throw on any plain sentence (e.g. "You are a helpful assistant.").
|
|
19
16
|
*/
|
|
20
|
-
export function renderTemplate(code, contentType, schema, data) {
|
|
21
|
-
if (contentType === TemplateType.handlebars) {
|
|
22
|
-
return renderHandlebarsTemplate(code, data);
|
|
23
|
-
}
|
|
17
|
+
export function renderTemplate(code, contentType, schema, data, system) {
|
|
24
18
|
if (contentType === TemplateType.text) {
|
|
25
19
|
return code;
|
|
26
20
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
21
|
+
const input = withTemplateSystemVariables(data, system);
|
|
22
|
+
if (contentType === TemplateType.handlebars) {
|
|
23
|
+
return renderHandlebarsTemplate(code, input);
|
|
24
|
+
}
|
|
25
|
+
return renderJsTemplate(code, schema.properties ? Object.keys(schema.properties) : [], input);
|
|
29
26
|
}
|
|
30
27
|
/**
|
|
31
28
|
* Execute a JST (JavaScript Template) with given data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/prompts/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,oBAAoB,EAAuB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAClH,OAAO,
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/prompts/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,oBAAoB,EAAuB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAClH,OAAO,EACH,cAAc,EACd,wBAAwB,EACxB,gBAAgB,EAEhB,2BAA2B,GAC9B,MAAM,eAAe,CAAC;AASvB;;;;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AAS,eAAe,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,CAAC;AAChG,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type JSONSchema, TemplateType } from '@vertesia/common';
|
|
2
|
-
export type PromptValidationIssueType = 'undeclared_template_variable' | 'unused_schema_variable' | 'handlebars_render_error' | 'jst_unsafe_construct' | 'jst_render_error';
|
|
2
|
+
export type PromptValidationIssueType = 'undeclared_template_variable' | 'unused_schema_variable' | 'reserved_variable_declared' | 'system_variable_property_access' | 'helper_used_as_value' | 'helper_missing_arguments' | 'handlebars_render_error' | 'jst_unsafe_construct' | 'jst_render_error';
|
|
3
3
|
export type PromptValidationIssueSeverity = 'error' | 'warning';
|
|
4
4
|
export interface PromptValidationIssue {
|
|
5
5
|
/** Discriminator for issue kind */
|
|
@@ -32,9 +32,15 @@ export interface PromptValidationInput {
|
|
|
32
32
|
*
|
|
33
33
|
* For `handlebars` and `jst` templates, the following checks are performed:
|
|
34
34
|
* 1. Every variable referenced in the template must be declared as a top-level property
|
|
35
|
-
* in `inputSchema.properties` (else → `undeclared_template_variable` error).
|
|
35
|
+
* in `inputSchema.properties` (else → `undeclared_template_variable` error). System variables
|
|
36
|
+
* (`TEMPLATE_SYSTEM_VARIABLES` in `@vertesia/jst`) are supplied at runtime and need no declaration;
|
|
37
|
+
* declaring one → `reserved_variable_declared` warning, reading a property of one →
|
|
38
|
+
* `system_variable_property_access` error.
|
|
36
39
|
* 2. Every property declared in `inputSchema.properties` should be referenced by the template
|
|
37
40
|
* (else → `unused_schema_variable` warning — non-blocking).
|
|
41
|
+
* For Handlebars only: a helper passed as an argument (`{{#if stringify}}`) →
|
|
42
|
+
* `helper_used_as_value` error; a helper called bare without the arguments it needs
|
|
43
|
+
* (`{{stringify}}`) → `helper_missing_arguments` error.
|
|
38
44
|
* 3. The template must render successfully against schema-derived mock data
|
|
39
45
|
* (else → `handlebars_render_error` / `jst_render_error` error).
|
|
40
46
|
* 4. For JST only: unsafe constructs (`with`, `for`, `while`, `import`, class, `this`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/prompts/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/prompts/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAcjE,MAAM,MAAM,yBAAyB,GAC/B,8BAA8B,GAC9B,wBAAwB,GACxB,4BAA4B,GAC5B,iCAAiC,GACjC,sBAAsB,GACtB,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,kBAAkB,CAAC;AAEzB,MAAM,MAAM,6BAA6B,GAAG,OAAO,GAAG,SAAS,CAAC;AAEhE,MAAM,WAAW,qBAAqB;IAClC,mCAAmC;IACnC,IAAI,EAAE,yBAAyB,CAAC;IAChC,uEAAuE;IACvE,QAAQ,EAAE,6BAA6B,CAAC;IACxC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACnC,2FAA2F;IAC3F,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAChC,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;IACpB,+FAA+F;IAC/F,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,qBAAqB;IAClC,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,sFAAsF;IACtF,WAAW,EAAE,YAAY,CAAC;IAC1B,gEAAgE;IAChE,WAAW,CAAC,EAAE,UAAU,CAAC;CAC5B;AAyLD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,qBAAqB,GAAG,sBAAsB,CAWnF"}
|
package/lib/prompts/validate.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { TemplateType } from '@vertesia/common';
|
|
2
|
-
import { getFreeVariables, renderJsTemplate } from '@vertesia/jst';
|
|
3
|
-
import {
|
|
2
|
+
import { describeTemplateSystemVariables, getFreeVariables, isTemplateSystemVariable, JST_TEMPLATE_GLOBALS, renderJsTemplate, TEMPLATE_SYSTEM_VARIABLES, withTemplateSystemVariables, } from '@vertesia/jst';
|
|
3
|
+
import { analyzeHandlebarsTemplate } from './extract-vars.js';
|
|
4
4
|
import { generateMockData } from './mock-data.js';
|
|
5
5
|
import { executeHandlebars } from './render.js';
|
|
6
|
-
// JST's renderJsTemplate auto-adds `_` (helpers object) and runtime injects `Set` and `Array`
|
|
7
|
-
// — treat them as globals so they don't appear as free vars in user templates.
|
|
8
|
-
// Globals always available to JST templates regardless of schema:
|
|
9
|
-
// - `_`, `Array`, `Set`: runtime-injected by `renderJsTemplate` (jst library)
|
|
10
|
-
// - `_model`: runtime-injected by the studio-server executor as `{ ..._model: run.modelId }`
|
|
11
|
-
// (see ExecutionRequest.ts:313 and executor/rendering/template.ts:13)
|
|
12
|
-
// Keeping these in sync with `renderTemplate` in ./render.ts so a JST template that runs in
|
|
13
|
-
// production also passes the validator.
|
|
14
|
-
const JST_AUTO_GLOBALS = ['_', 'Array', 'Set', '_model'];
|
|
15
6
|
function countSeverities(issues) {
|
|
16
7
|
let error_count = 0;
|
|
17
8
|
let warning_count = 0;
|
|
@@ -25,38 +16,96 @@ function countSeverities(issues) {
|
|
|
25
16
|
}
|
|
26
17
|
return { error_count, warning_count };
|
|
27
18
|
}
|
|
28
|
-
|
|
19
|
+
/** Mock data for the render smoke test: schema-shaped input plus the runtime system values. */
|
|
20
|
+
function buildMockInput(inputSchema) {
|
|
21
|
+
const mockData = generateMockData(inputSchema);
|
|
22
|
+
const mockObject = typeof mockData === 'object' && mockData !== null && !Array.isArray(mockData) ? mockData : {};
|
|
23
|
+
return withTemplateSystemVariables(mockObject, { model: 'validation-model' });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Issues shared by both template languages: reserved names declared in the schema, and
|
|
27
|
+
* unused schema properties. `usedVars` holds the input variables the template reads.
|
|
28
|
+
*/
|
|
29
|
+
function checkDeclarations(declaredVars, usedVars, usageHint) {
|
|
29
30
|
const issues = [];
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
for (const used of usedVars) {
|
|
33
|
-
if (!declaredVars.has(used)) {
|
|
31
|
+
for (const declared of declaredVars) {
|
|
32
|
+
if (isTemplateSystemVariable(declared)) {
|
|
34
33
|
issues.push({
|
|
35
|
-
type: '
|
|
36
|
-
severity: '
|
|
37
|
-
variable:
|
|
38
|
-
message: `
|
|
34
|
+
type: 'reserved_variable_declared',
|
|
35
|
+
severity: 'warning',
|
|
36
|
+
variable: declared,
|
|
37
|
+
message: `Schema declares '${declared}', a system variable the runtime supplies and overrides. Remove it from input_schema.`,
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
for (const declared of declaredVars) {
|
|
43
|
-
if (!usedVars.has(declared)) {
|
|
40
|
+
else if (!usedVars.has(declared)) {
|
|
44
41
|
issues.push({
|
|
45
42
|
type: 'unused_schema_variable',
|
|
46
43
|
severity: 'warning',
|
|
47
44
|
variable: declared,
|
|
48
|
-
message: `Schema declares property '${declared}' but the template never references it. Remove it from input_schema or
|
|
45
|
+
message: `Schema declares property '${declared}' but the template never references it. Remove it from input_schema or ${usageHint(declared)}.`,
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
48
|
}
|
|
49
|
+
return issues;
|
|
50
|
+
}
|
|
51
|
+
function undeclaredVariableIssue(name, where) {
|
|
52
|
+
return {
|
|
53
|
+
type: 'undeclared_template_variable',
|
|
54
|
+
severity: 'error',
|
|
55
|
+
variable: name,
|
|
56
|
+
message: `Template reads variable '${name}' ${where} but it is not declared in input_schema.properties. ` +
|
|
57
|
+
`Add '${name}' to the schema with an appropriate type. ` +
|
|
58
|
+
`System variables need no declaration: ${describeTemplateSystemVariables()}.`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function validateHandlebarsPrompt(content, inputSchema) {
|
|
62
|
+
const issues = [];
|
|
63
|
+
const analysis = analyzeHandlebarsTemplate(content);
|
|
64
|
+
const declaredVars = new Set(inputSchema?.properties ? Object.keys(inputSchema.properties) : []);
|
|
65
|
+
const usedVars = new Set();
|
|
66
|
+
const reported = new Set();
|
|
67
|
+
for (const ref of analysis?.references ?? []) {
|
|
68
|
+
if (isTemplateSystemVariable(ref.name)) {
|
|
69
|
+
const variable = TEMPLATE_SYSTEM_VARIABLES.find((v) => v.name === ref.name);
|
|
70
|
+
if (ref.hasPath && variable?.type === 'string' && !reported.has(`path:${ref.expression}`)) {
|
|
71
|
+
reported.add(`path:${ref.expression}`);
|
|
72
|
+
issues.push({
|
|
73
|
+
type: 'system_variable_property_access',
|
|
74
|
+
severity: 'error',
|
|
75
|
+
variable: ref.name,
|
|
76
|
+
message: `'${ref.expression}' in ${ref.tag} reads a property of system variable '${ref.name}', which is a string (${variable.description}). Use '${ref.name}' directly.`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
usedVars.add(ref.name);
|
|
82
|
+
if (!declaredVars.has(ref.name) && !reported.has(ref.name)) {
|
|
83
|
+
reported.add(ref.name);
|
|
84
|
+
issues.push(undeclaredVariableIssue(ref.name, `in ${ref.tag}`));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const misuse of analysis?.helperMisuses ?? []) {
|
|
88
|
+
issues.push(misuse.problem === 'used_as_value'
|
|
89
|
+
? {
|
|
90
|
+
type: 'helper_used_as_value',
|
|
91
|
+
severity: 'error',
|
|
92
|
+
variable: misuse.helper,
|
|
93
|
+
message: `'${misuse.helper}' in ${misuse.tag} is a helper, but as an argument Handlebars reads it as data, which is empty. Call it as a subexpression: (${misuse.helper} ...).`,
|
|
94
|
+
}
|
|
95
|
+
: {
|
|
96
|
+
type: 'helper_missing_arguments',
|
|
97
|
+
severity: 'error',
|
|
98
|
+
variable: misuse.helper,
|
|
99
|
+
message: `${misuse.tag} calls helper '${misuse.helper}' without arguments. Pass the value it operates on, e.g. {{${misuse.helper} value}}.`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
issues.push(...checkDeclarations(declaredVars, usedVars, (name) => `use it via {{${name}}}`));
|
|
52
103
|
// Render-time smoke test — always runs so syntax errors and failing helper calls are
|
|
53
104
|
// surfaced even when undeclared-variable errors are already in the list. Handlebars renders
|
|
54
105
|
// missing vars as empty strings (non-strict by default), so the render check does NOT echo
|
|
55
106
|
// the var errors — anything it reports is a distinct template problem worth showing.
|
|
56
107
|
const renderSchema = inputSchema ?? {};
|
|
57
|
-
const
|
|
58
|
-
const mockObject = typeof mockData === 'object' && mockData !== null && !Array.isArray(mockData) ? mockData : {};
|
|
59
|
-
const renderResult = executeHandlebars(content, renderSchema, mockObject);
|
|
108
|
+
const renderResult = executeHandlebars(content, renderSchema, buildMockInput(renderSchema));
|
|
60
109
|
if (!renderResult.success) {
|
|
61
110
|
issues.push({
|
|
62
111
|
type: 'handlebars_render_error',
|
|
@@ -72,7 +121,7 @@ function validateJstPrompt(content, inputSchema) {
|
|
|
72
121
|
let referenced;
|
|
73
122
|
try {
|
|
74
123
|
const result = getFreeVariables(content, {
|
|
75
|
-
globals:
|
|
124
|
+
globals: [...JST_TEMPLATE_GLOBALS],
|
|
76
125
|
acorn: { allowReturnOutsideFunction: true, locations: true },
|
|
77
126
|
});
|
|
78
127
|
referenced = result.vars;
|
|
@@ -95,35 +144,17 @@ function validateJstPrompt(content, inputSchema) {
|
|
|
95
144
|
}
|
|
96
145
|
for (const used of referenced) {
|
|
97
146
|
if (!declaredVars.has(used)) {
|
|
98
|
-
issues.push(
|
|
99
|
-
type: 'undeclared_template_variable',
|
|
100
|
-
severity: 'error',
|
|
101
|
-
variable: used,
|
|
102
|
-
message: `Template references variable '${used}' but it is not declared in input_schema.properties. Add '${used}' to the schema with an appropriate type.`,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
for (const declared of declaredVars) {
|
|
107
|
-
if (!referenced.has(declared)) {
|
|
108
|
-
issues.push({
|
|
109
|
-
type: 'unused_schema_variable',
|
|
110
|
-
severity: 'warning',
|
|
111
|
-
variable: declared,
|
|
112
|
-
message: `Schema declares property '${declared}' but the template never references it. Remove it from input_schema or use it in the template.`,
|
|
113
|
-
});
|
|
147
|
+
issues.push(undeclaredVariableIssue(used, 'in the template'));
|
|
114
148
|
}
|
|
115
149
|
}
|
|
150
|
+
issues.push(...checkDeclarations(declaredVars, referenced, () => 'use it in the template'));
|
|
116
151
|
// Render-time smoke test — only if there are no blocking errors so far, otherwise
|
|
117
152
|
// the failure mode would just echo what we already reported.
|
|
118
153
|
const blockingSoFar = issues.some((i) => i.severity === 'error');
|
|
119
154
|
if (!blockingSoFar) {
|
|
120
155
|
const renderSchema = inputSchema ?? {};
|
|
121
|
-
const mockData = generateMockData(renderSchema);
|
|
122
|
-
const mockObject = typeof mockData === 'object' && mockData !== null && !Array.isArray(mockData)
|
|
123
|
-
? mockData
|
|
124
|
-
: {};
|
|
125
156
|
try {
|
|
126
|
-
renderJsTemplate(content, [...declaredVars],
|
|
157
|
+
renderJsTemplate(content, [...declaredVars], buildMockInput(renderSchema));
|
|
127
158
|
}
|
|
128
159
|
catch (renderError) {
|
|
129
160
|
issues.push({
|
|
@@ -140,9 +171,15 @@ function validateJstPrompt(content, inputSchema) {
|
|
|
140
171
|
*
|
|
141
172
|
* For `handlebars` and `jst` templates, the following checks are performed:
|
|
142
173
|
* 1. Every variable referenced in the template must be declared as a top-level property
|
|
143
|
-
* in `inputSchema.properties` (else → `undeclared_template_variable` error).
|
|
174
|
+
* in `inputSchema.properties` (else → `undeclared_template_variable` error). System variables
|
|
175
|
+
* (`TEMPLATE_SYSTEM_VARIABLES` in `@vertesia/jst`) are supplied at runtime and need no declaration;
|
|
176
|
+
* declaring one → `reserved_variable_declared` warning, reading a property of one →
|
|
177
|
+
* `system_variable_property_access` error.
|
|
144
178
|
* 2. Every property declared in `inputSchema.properties` should be referenced by the template
|
|
145
179
|
* (else → `unused_schema_variable` warning — non-blocking).
|
|
180
|
+
* For Handlebars only: a helper passed as an argument (`{{#if stringify}}`) →
|
|
181
|
+
* `helper_used_as_value` error; a helper called bare without the arguments it needs
|
|
182
|
+
* (`{{stringify}}`) → `helper_missing_arguments` error.
|
|
146
183
|
* 3. The template must render successfully against schema-derived mock data
|
|
147
184
|
* (else → `handlebars_render_error` / `jst_render_error` error).
|
|
148
185
|
* 4. For JST only: unsafe constructs (`with`, `for`, `while`, `import`, class, `this`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/prompts/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/prompts/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACH,+BAA+B,EAC/B,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,yBAAyB,EACzB,2BAA2B,GAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA4ChD,SAAS,eAAe,CAAC,MAA+B;IACpD,IAAI,WAAW,GAAG,CAAC,CAAC;IAC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AO,EAAa,KAAK,aAAa,EAAc,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/roles/system.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,aAAa,EAAc,MAAM,cAAc,CAAC;AAuNzE,eAAO,MAAM,eAAe,EAAE,aAG7B,CAAC"}
|
package/lib/roles/system.js
CHANGED
|
@@ -15,6 +15,20 @@ class AdminRole extends OrgMemberRole {
|
|
|
15
15
|
super(SystemRoles.admin, Object.values(Permission));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Full `admin` rights minus Studio UI access. For an account administrator who operates the
|
|
20
|
+
* platform through a custom admin UI and must not reach Vertesia Studio itself.
|
|
21
|
+
*
|
|
22
|
+
* Keep in lockstep with `AdminRole`: `studio_access` is the only intended difference, so a new
|
|
23
|
+
* permission added to the central enum reaches both roles automatically.
|
|
24
|
+
*/
|
|
25
|
+
class AppAdminRole extends AdminRole {
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this.name = SystemRoles.app_admin;
|
|
29
|
+
this.permissions.delete(Permission.studio_access);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
18
32
|
class ManagerRole extends OrgMemberRole {
|
|
19
33
|
constructor() {
|
|
20
34
|
super(SystemRoles.manager, Object.values(Permission));
|
|
@@ -165,6 +179,7 @@ class ContentSuperAdmin extends DeveloperRole {
|
|
|
165
179
|
const systemRoles = {
|
|
166
180
|
[SystemRoles.owner]: new OwnerRole(),
|
|
167
181
|
[SystemRoles.admin]: new AdminRole(),
|
|
182
|
+
[SystemRoles.app_admin]: new AppAdminRole(),
|
|
168
183
|
[SystemRoles.manager]: new ManagerRole(),
|
|
169
184
|
[SystemRoles.developer]: new DeveloperRole(),
|
|
170
185
|
[SystemRoles.application]: new ApplicationRole(),
|
package/lib/roles/system.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.js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,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,UAAU,EAAE;IACtC,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,iBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC;IACjE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,iBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC;IACjE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,WAAW,EAAE;IACxC,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,IAAI,aAAa,EAAE;IAC7C,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,aAAa,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;IAC/D,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,IAAI,iBAAiB,EAAE;CAC5D,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC1C,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;CAC9C,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import e from"handlebars";import{Permission as t,PromptSegmentDefType as n,SystemRoles as r,TemplateType as i}from"@vertesia/common";import{CompositeError as a,getFreeVariables as o,renderHandlebarsTemplate as s,renderJsTemplate as c}from"@vertesia/jst";function l(e,t){return!e||!t?e:e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>{let r=t[n];return typeof r!=`string`||!r?e:u(r)})}function u(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)t--;return t===e.length?e:e.slice(0,t)}function d(t){let n;try{n=e.parse(t)}catch{return new Set}let r=new Set,i=[],a=e=>i.some(t=>t.has(e)),o=e=>{if(!e||typeof e!=`object`)return;let t=e;switch(t.type){case`Program`:{let e=t.body;if(e)for(let t of e)o(t);break}case`BlockStatement`:{let e=t.params;if(e)for(let t of e)o(t);o(t.hash);let n=t.program,r=t.inverse,a=new Set([...n?.blockParams??[],...r?.blockParams??[]]);i.push(a),o(t.program),o(t.inverse),i.pop();break}case`MustacheStatement`:{let e=t.params,n=t.hash;if((e?.length??0)>0||(n?.pairs?.length??0)>0||o(t.path),e)for(let t of e)o(t);o(n);break}case`SubExpression`:{let e=t.params;if(e)for(let t of e)o(t);o(t.hash);break}case`PathExpression`:{if(t.data)break;let e=t.parts;if(!e||e.length===0)break;let n=e[0];if(a(n))break;r.add(n);break}case`Hash`:{let e=t.pairs;if(e)for(let t of e)o(t.value);break}}};return o(n),r}function f(e,t=`value`){if(`$ref`in e)return`%${t}%`;switch((Array.isArray(e.type)?e.type:[e.type])[0]){case`string`:return`%${t}%`;case`number`:case`integer`:return Math.floor(Math.random()*101);case`boolean`:return!0;case`array`:{let n=e.items;if(n){let e=Math.floor(Math.random()*2)+1;return Array.from({length:e},(e,r)=>f(n,`${t}_${r}`))}return[]}case`object`:{let t={};if(e.properties)for(let[n,r]of Object.entries(e.properties))t[n]=f(r,n);return t}case`null`:return null;default:return`%${t}%`}}function p(e,t,n,r){if(t===i.handlebars)return s(e,r);if(t===i.text)return e;let a=[...n.properties?Object.keys(n.properties):[],`_model`];return c(e,a,r)}function m(e,t,n){try{return{success:!0,content:p(e,i.jst,t,n)}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}function h(e,t,n){try{return{success:!0,content:p(e,i.handlebars,t,n)}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}function g(e,t){let n=x(e.configuration),r=t[n],i;return i=Array.isArray(r)?JSON.stringify(r,void 0,2):`No "${n}" property found on input data`,{title:`Chat history`,content:i}}function _(e,t){if(!e.template)return{title:`(unknown segment)`,content:``,error:Error(`Prompt segment is missing its template`)};let n=e.template.inputSchema||{},r=`@${e.template.role}`;try{return{title:r,content:p(e.template.content,e.template.content_type,n,t),segmentId:e.template.id}}catch(t){return{title:r,content:t instanceof Error?t.message:String(t),segmentId:e.template.id,error:t instanceof Error?t:Error(String(t))}}}function v(e,t){let r=[];for(let i of e)i.type===n.chat?r.push(g(i,t)):i.type===n.template&&r.push(_(i,t));return r}function y(e,t){try{return v(e,typeof t==`string`?JSON.parse(t.trim()):t||{})}catch(e){return e instanceof a?e.errors.map(e=>({error:e,title:`Rendering Error`,content:e.message})):[{error:e instanceof Error?e:Error(String(e)),title:`Rendering Error`,content:e instanceof Error?e.message:String(e)}]}}function b(e,t){let r=[];for(let i of e)if(i.template){let e=i.template.inputSchema||{},n=p(i.template.content,i.template.content_type,e,t);r.push({role:i.template.role,content:n})}else if(i.type===n.chat){let e=t[x(i.configuration)];if(!ee(e))throw Error(`Chat prompt segment must have a messages array`);for(let t of e){if(!t.role)throw Error(`Chat prompt segment must have a role`);r.push({role:t.role,content:t.content})}}else throw Error(`Unknown prompt segment type: ${i.type}`);return r}function x(e){return typeof e==`object`&&e&&`chatKey`in e&&typeof e.chatKey==`string`?e.chatKey:`chat`}function ee(e){return Array.isArray(e)&&e.every(S)}function S(e){return typeof e==`object`&&!!e&&`role`in e&&`content`in e}const te=[`_`,`Array`,`Set`,`_model`];function ne(e){let t=0,n=0;for(let r of e)r.severity===`error`?t++:r.severity===`warning`&&n++;return{error_count:t,warning_count:n}}function re(e,t){let n=[],r=d(e),i=new Set(t?.properties?Object.keys(t.properties):[]);for(let e of r)i.has(e)||n.push({type:`undeclared_template_variable`,severity:`error`,variable:e,message:`Template references variable '{{${e}}}' but it is not declared in input_schema.properties. Add '${e}' to the schema with an appropriate type.`});for(let e of i)r.has(e)||n.push({type:`unused_schema_variable`,severity:`warning`,variable:e,message:`Schema declares property '${e}' but the template never references it. Remove it from input_schema or use it via {{${e}}}.`});let a=t??{},o=f(a),s=h(e,a,typeof o==`object`&&o&&!Array.isArray(o)?o:{});return s.success||n.push({type:`handlebars_render_error`,severity:`error`,message:`Handlebars rendering failed: ${s.error}`}),n}function ie(e,t){let n=[],r=new Set(t?.properties?Object.keys(t.properties):[]),i;try{let t=o(e,{globals:te,acorn:{allowReturnOutsideFunction:!0,locations:!0}});i=t.vars;for(let e of t.errors)n.push({type:`jst_unsafe_construct`,severity:`error`,message:`JST validation error at ${e.location}: ${e.message}`})}catch(e){return n.push({type:`jst_render_error`,severity:`error`,message:`JST parse failed: ${e instanceof Error?e.message:String(e)}`}),n}for(let e of i)r.has(e)||n.push({type:`undeclared_template_variable`,severity:`error`,variable:e,message:`Template references variable '${e}' but it is not declared in input_schema.properties. Add '${e}' to the schema with an appropriate type.`});for(let e of r)i.has(e)||n.push({type:`unused_schema_variable`,severity:`warning`,variable:e,message:`Schema declares property '${e}' but the template never references it. Remove it from input_schema or use it in the template.`});if(!n.some(e=>e.severity===`error`)){let i=f(t??{}),a=typeof i==`object`&&i&&!Array.isArray(i)?i:{};try{c(e,[...r],a)}catch(e){n.push({type:`jst_render_error`,severity:`error`,message:`JST rendering failed: ${e instanceof Error?e.message:String(e)}`})}}return n}function C(e){let t;t=e.contentType===i.handlebars?re(e.content,e.inputSchema):e.contentType===i.jst?ie(e.content,e.inputSchema):[];let{error_count:n,warning_count:r}=ne(t);return{issues:t,error_count:n,warning_count:r}}var w=class{name;domain;permissions;constructor(e,t,n){this.name=e,this.domain=n,this.permissions=new Set(t)}hasPermission(e){return this.permissions.has(e)}},T=class extends w{constructor(e,t){super(e,t,`system`)}},E=class extends w{applicableScopes;constructor(e,t,n,r){super(e,t,n),this.applicableScopes=r}};const D=`content`,O=[`document`,`collection`];var k;(function(e){e.content_reader=`content:reader`,e.content_writer=`content:writer`,e.content_manager=`content:manager`})(k||={});var A=class extends E{constructor(){super(k.content_reader,[`read`],D,O)}},j=class extends E{constructor(){super(k.content_writer,[`read`,`write`],D,O)}},M=class extends E{constructor(){super(k.content_manager,[`read`,`write`,`delete`],D,O)}};const N={[k.content_reader]:new A,[k.content_writer]:new j,[k.content_manager]:new M},P={domain:D,roles:new Map(Object.entries(N))};var F=class extends T{constructor(e,n){super(e,[t.account_member,...n])}},I=class extends F{constructor(){super(r.owner,Object.values(t))}},L=class extends F{constructor(){super(r.admin,Object.values(t))}},R=class extends F{constructor(){super(r.manager,Object.values(t)),this.permissions.delete(t.account_admin),this.permissions.delete(t.manage_billing),this.permissions.delete(t.audit_read),this.permissions.delete(t.agent_run_read),this.permissions.delete(t.content_read_all),this.permissions.delete(t.content_superadmin),this.permissions.delete(t.workflow_superadmin)}},z=class extends F{constructor(){super(r.developer,Object.values(t)),this.permissions.delete(t.account_admin),this.permissions.delete(t.project_admin),this.permissions.delete(t.project_settings_write),this.permissions.delete(t.env_admin),this.permissions.delete(t.manage_billing),this.permissions.delete(t.audit_read),this.permissions.delete(t.agent_run_read),this.permissions.delete(t.content_read_all),this.permissions.delete(t.content_superadmin),this.permissions.delete(t.workflow_superadmin)}},B=class extends F{constructor(){super(r.application,[t.int_read,t.int_execute,t.int_write,t.run_read,t.content_write,t.content_read,t.content_write,t.content_admin,t.project_admin,t.workflow_run,t.project_settings_write,t.account_write])}},V=class extends F{constructor(){super(r.automation,[t.content_read,t.content_write,t.content_admin,t.int_read,t.int_execute,t.run_read,t.workflow_run,t.project_integration_read])}},H=class extends F{constructor(){super(r.content_processor,[t.content_read,t.content_write,t.content_admin,t.content_superadmin,t.int_execute,t.workflow_read,t.workflow_run,t.run_read])}},U=class extends F{constructor(){super(r.consumer,[t.content_admin,t.content_read,t.content_write,t.content_delete,t.int_read,t.int_execute,t.run_read,t.workflow_run])}},W=class extends F{constructor(){super(r.executor,[t.int_execute,t.run_read,t.workflow_run])}},G=class extends F{constructor(){super(r.reader,[t.int_read,t.run_read,t.content_read])}};const K=[t.studio_access,t.account_read,t.project_integration_read,t.api_key_read,t.billing_read,t.audit_read,t.int_read,t.run_read,t.content_read,t.content_read_all,t.task_read,t.workflow_read,t.agent_run_read];var q=class extends F{constructor(e){super(e,K)}},J=class extends F{constructor(){super(r.billing,[t.manage_billing])}},Y=class extends F{constructor(){super(r.app_member,[t.int_read,t.int_execute,t.int_write,t.run_read,t.content_write,t.content_read,t.content_delete,t.workflow_run])}},ae=class extends z{constructor(){super(),this.name=r.content_superadmin,this.permissions.add(t.content_superadmin)}};const oe={[r.owner]:new I,[r.admin]:new L,[r.manager]:new R,[r.developer]:new z,[r.application]:new B,[r.automation]:new V,[r.content_processor]:new H,[r.consumer]:new U,[r.executor]:new W,[r.reader]:new G,[r.auditor]:new q(r.auditor),[r.support]:new q(r.support),[r.billing]:new J,[r.app_member]:new Y,[r.member]:new F(r.member,[]),[r.content_superadmin]:new ae},X=[{domain:`system`,roles:new Map(Object.entries(oe))},P];function Z(e){for(let t of X){let n=t.roles.get(e);if(n)return n}throw Error(`Role ${e} not found`)}function Q(){let e=[];for(let t of X)for(let n of t.roles.values())e.push(n);return e}function $(e){let t=X.find(t=>t.domain===e);return t?Array.from(t.roles.values()):[]}function se(e){return Q().filter(t=>t instanceof E&&t.applicableScopes.includes(e))}function ce(){return Q().filter(e=>e instanceof T)}function le(){return Q().map(e=>e.name)}function ue(e){let t=new Set;for(let n of e){let e=Z(n);for(let n of e.permissions)t.add(n)}return Array.from(t)}function de(e){let t=Z(e);return t instanceof E?[...t.permissions].map(e=>`${t.domain}:${e}`):[...t.permissions]}var fe=class e{roles;constructor(e){this.roles=e}static fromRoleNames(t){let n=t.map(e=>Z(e));return new e(n)}static fromRoleName(t){let n=[Z(t)];return new e(n)}hasPermission(e){return this.roles.some(t=>t.hasPermission(e))}};export{E as AbacRole,k as ContentRoleNames,w as Role,fe as RoleList,T as SystemRole,h as executeHandlebars,m as executeJST,d as extractHandlebarsVariables,f as generateMockData,le as getAllRoleNames,de as getDelegablePermissionsForRole,ue as getPermissionsForRoles,Z as getRoleByName,se as listAbacRolesForScope,Q as listRoles,$ as listRolesByDomain,ce as listSystemRoles,b as renderPrompt,v as renderSegments,y as renderSegmentsOrErrors,p as renderTemplate,l as substituteEndpoints,C as validatePrompt};
|
|
1
|
+
import{CompositeError as e,HANDLEBARS_CONTEXT_HELPERS as t,HANDLEBARS_HELPER_NAMES as n,JST_TEMPLATE_GLOBALS as r,TEMPLATE_SYSTEM_VARIABLES as i,TEMPLATE_SYSTEM_VARIABLES as a,TEMPLATE_SYSTEM_VARIABLE_NAMES as o,describeTemplateSystemVariables as s,describeTemplateSystemVariables as c,getFreeVariables as l,isHandlebarsHelper as u,isTemplateSystemVariable as d,isTemplateSystemVariable as f,renderHandlebarsTemplate as p,renderJsTemplate as m,withTemplateSystemVariables as h,withTemplateSystemVariables as g}from"@vertesia/jst";import _ from"handlebars";import{Permission as v,PromptSegmentDefType as y,SystemRoles as b,TemplateType as x}from"@vertesia/common";function ee(e,t){return!e||!t?e:e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>{let r=t[n];return typeof r!=`string`||!r?e:S(r)})}function S(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)t--;return t===e.length?e:e.slice(0,t)}function C(e){return!!e&&typeof e==`object`&&e.type===`PathExpression`}function w(e){return/^\.|this\b/.test(e.original)}function T(e){return e.parts.length===1&&!w(e)&&!e.data&&e.depth===0}function E(e){let t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
2
|
+
`&&t.push(n+1);return t}function D(e){let n;try{n=_.parse(e)}catch{return null}let r=E(e),i=t=>{if(!t)return``;let n=(r[t.start.line-1]??0)+t.start.column,i=e.indexOf(`}}`,n);return i<0?e.slice(n):e.slice(n,e[i+2]===`}`?i+3:i+2)},a=[],o=[],s=[`root`],c=[],l=``,d=e=>c.some(t=>t.has(e)),p=e=>{if(e.data){e.parts[0]===`root`&&e.parts.length>1&&a.push({name:e.parts[1],expression:e.original,hasPath:e.parts.length>2,tag:l});return}if(e.parts.length===0)return;let t=e.parts[0];e.depth===0&&!w(e)&&d(t)||s[Math.max(0,s.length-1-e.depth)]===`root`&&a.push({name:t,expression:e.original,hasPath:e.parts.length>1,tag:l})},m=e=>{if(C(e)){let t=e.parts[0];if(T(e)&&!d(t)&&u(t)&&!f(t)){o.push({helper:t,problem:`used_as_value`,tag:l});return}p(e);return}v(e)},h=e=>{let t=e.params??[];for(let e of t)m(e);let n=e.hash?.pairs??[];for(let e of n)m(e.value)},g=e=>(e.params?.length??0)>0||(e.hash?.pairs?.length??0)>0,v=e=>{if(!e||typeof e!=`object`)return;let n=e;switch(n.type){case`Program`:for(let e of n.body??[])v(e);break;case`MustacheStatement`:{l=i(n.loc);let e=n.path;if(g(n))h(n);else if(C(e)){let t=e.parts[0];T(e)&&!d(t)&&u(t)?f(t)||o.push({helper:t,problem:`missing_arguments`,tag:l}):p(e)}else v(e);break}case`BlockStatement`:{l=i(n.loc);let e=n.path,r=C(e)&&T(e)?e.parts[0]:void 0,a;g(n)||r&&u(r)?(h(n),a=!!r&&t.includes(r)):(C(e)&&p(e),a=!0);let o=n.program,d=n.inverse;c.push(new Set(o?.blockParams??[])),s.push(a?`item`:s[s.length-1]),v(n.program),s.pop(),c.pop(),c.push(new Set(d?.blockParams??[])),v(n.inverse),c.pop();break}case`SubExpression`:h(n)}};return v(n),{references:a,helperMisuses:o}}function O(e){let t=D(e);return new Set(t?.references.map(e=>e.name)??[])}function k(e,t=`value`){if(`$ref`in e)return`%${t}%`;switch((Array.isArray(e.type)?e.type:[e.type])[0]){case`string`:return`%${t}%`;case`number`:case`integer`:return Math.floor(Math.random()*101);case`boolean`:return!0;case`array`:{let n=e.items;if(n){let e=Math.floor(Math.random()*2)+1;return Array.from({length:e},(e,r)=>k(n,`${t}_${r}`))}return[]}case`object`:{let t={};if(e.properties)for(let[n,r]of Object.entries(e.properties))t[n]=k(r,n);return t}case`null`:return null;default:return`%${t}%`}}function A(e,t,n,r,i){if(t===x.text)return e;let a=g(r,i);return t===x.handlebars?p(e,a):m(e,n.properties?Object.keys(n.properties):[],a)}function j(e,t,n){try{return{success:!0,content:A(e,x.jst,t,n)}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}function M(e,t,n){try{return{success:!0,content:A(e,x.handlebars,t,n)}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}function te(e,t){let n=P(e.configuration),r=t[n],i;return i=Array.isArray(r)?JSON.stringify(r,void 0,2):`No "${n}" property found on input data`,{title:`Chat history`,content:i}}function ne(e,t){if(!e.template)return{title:`(unknown segment)`,content:``,error:Error(`Prompt segment is missing its template`)};let n=e.template.inputSchema||{},r=`@${e.template.role}`;try{return{title:r,content:A(e.template.content,e.template.content_type,n,t),segmentId:e.template.id}}catch(t){return{title:r,content:t instanceof Error?t.message:String(t),segmentId:e.template.id,error:t instanceof Error?t:Error(String(t))}}}function N(e,t){let n=[];for(let r of e)r.type===y.chat?n.push(te(r,t)):r.type===y.template&&n.push(ne(r,t));return n}function re(t,n){try{return N(t,typeof n==`string`?JSON.parse(n.trim()):n||{})}catch(t){return t instanceof e?t.errors.map(e=>({error:e,title:`Rendering Error`,content:e.message})):[{error:t instanceof Error?t:Error(String(t)),title:`Rendering Error`,content:t instanceof Error?t.message:String(t)}]}}function ie(e,t){let n=[];for(let r of e)if(r.template){let e=r.template.inputSchema||{},i=A(r.template.content,r.template.content_type,e,t);n.push({role:r.template.role,content:i})}else if(r.type===y.chat){let e=t[P(r.configuration)];if(!ae(e))throw Error(`Chat prompt segment must have a messages array`);for(let t of e){if(!t.role)throw Error(`Chat prompt segment must have a role`);n.push({role:t.role,content:t.content})}}else throw Error(`Unknown prompt segment type: ${r.type}`);return n}function P(e){return typeof e==`object`&&e&&`chatKey`in e&&typeof e.chatKey==`string`?e.chatKey:`chat`}function ae(e){return Array.isArray(e)&&e.every(oe)}function oe(e){return typeof e==`object`&&!!e&&`role`in e&&`content`in e}function F(e){let t=0,n=0;for(let r of e)r.severity===`error`?t++:r.severity===`warning`&&n++;return{error_count:t,warning_count:n}}function I(e){let t=k(e);return g(typeof t==`object`&&t&&!Array.isArray(t)?t:{},{model:`validation-model`})}function L(e,t,n){let r=[];for(let i of e)f(i)?r.push({type:`reserved_variable_declared`,severity:`warning`,variable:i,message:`Schema declares '${i}', a system variable the runtime supplies and overrides. Remove it from input_schema.`}):t.has(i)||r.push({type:`unused_schema_variable`,severity:`warning`,variable:i,message:`Schema declares property '${i}' but the template never references it. Remove it from input_schema or ${n(i)}.`});return r}function R(e,t){return{type:`undeclared_template_variable`,severity:`error`,variable:e,message:`Template reads variable '${e}' ${t} but it is not declared in input_schema.properties. Add '${e}' to the schema with an appropriate type. System variables need no declaration: ${c()}.`}}function se(e,t){let n=[],r=D(e),i=new Set(t?.properties?Object.keys(t.properties):[]),o=new Set,s=new Set;for(let e of r?.references??[]){if(f(e.name)){let t=a.find(t=>t.name===e.name);e.hasPath&&t?.type===`string`&&!s.has(`path:${e.expression}`)&&(s.add(`path:${e.expression}`),n.push({type:`system_variable_property_access`,severity:`error`,variable:e.name,message:`'${e.expression}' in ${e.tag} reads a property of system variable '${e.name}', which is a string (${t.description}). Use '${e.name}' directly.`}));continue}o.add(e.name),!i.has(e.name)&&!s.has(e.name)&&(s.add(e.name),n.push(R(e.name,`in ${e.tag}`)))}for(let e of r?.helperMisuses??[])n.push(e.problem===`used_as_value`?{type:`helper_used_as_value`,severity:`error`,variable:e.helper,message:`'${e.helper}' in ${e.tag} is a helper, but as an argument Handlebars reads it as data, which is empty. Call it as a subexpression: (${e.helper} ...).`}:{type:`helper_missing_arguments`,severity:`error`,variable:e.helper,message:`${e.tag} calls helper '${e.helper}' without arguments. Pass the value it operates on, e.g. {{${e.helper} value}}.`});n.push(...L(i,o,e=>`use it via {{${e}}}`));let c=t??{},l=M(e,c,I(c));return l.success||n.push({type:`handlebars_render_error`,severity:`error`,message:`Handlebars rendering failed: ${l.error}`}),n}function ce(e,t){let n=[],i=new Set(t?.properties?Object.keys(t.properties):[]),a;try{let t=l(e,{globals:[...r],acorn:{allowReturnOutsideFunction:!0,locations:!0}});a=t.vars;for(let e of t.errors)n.push({type:`jst_unsafe_construct`,severity:`error`,message:`JST validation error at ${e.location}: ${e.message}`})}catch(e){return n.push({type:`jst_render_error`,severity:`error`,message:`JST parse failed: ${e instanceof Error?e.message:String(e)}`}),n}for(let e of a)i.has(e)||n.push(R(e,`in the template`));if(n.push(...L(i,a,()=>`use it in the template`)),!n.some(e=>e.severity===`error`)){let r=t??{};try{m(e,[...i],I(r))}catch(e){n.push({type:`jst_render_error`,severity:`error`,message:`JST rendering failed: ${e instanceof Error?e.message:String(e)}`})}}return n}function z(e){let t;t=e.contentType===x.handlebars?se(e.content,e.inputSchema):e.contentType===x.jst?ce(e.content,e.inputSchema):[];let{error_count:n,warning_count:r}=F(t);return{issues:t,error_count:n,warning_count:r}}var B=class{name;domain;permissions;constructor(e,t,n){this.name=e,this.domain=n,this.permissions=new Set(t)}hasPermission(e){return this.permissions.has(e)}},V=class extends B{constructor(e,t){super(e,t,`system`)}},H=class extends B{applicableScopes;constructor(e,t,n,r){super(e,t,n),this.applicableScopes=r}};const U=`content`,W=[`document`,`collection`];var G;(function(e){e.content_reader=`content:reader`,e.content_writer=`content:writer`,e.content_manager=`content:manager`})(G||={});var le=class extends H{constructor(){super(G.content_reader,[`read`],U,W)}},ue=class extends H{constructor(){super(G.content_writer,[`read`,`write`],U,W)}},de=class extends H{constructor(){super(G.content_manager,[`read`,`write`,`delete`],U,W)}};const fe={[G.content_reader]:new le,[G.content_writer]:new ue,[G.content_manager]:new de},pe={domain:U,roles:new Map(Object.entries(fe))};var K=class extends V{constructor(e,t){super(e,[v.account_member,...t])}},q=class extends K{constructor(){super(b.owner,Object.values(v))}},J=class extends K{constructor(){super(b.admin,Object.values(v))}},me=class extends J{constructor(){super(),this.name=b.app_admin,this.permissions.delete(v.studio_access)}},he=class extends K{constructor(){super(b.manager,Object.values(v)),this.permissions.delete(v.account_admin),this.permissions.delete(v.manage_billing),this.permissions.delete(v.audit_read),this.permissions.delete(v.agent_run_read),this.permissions.delete(v.content_read_all),this.permissions.delete(v.content_superadmin),this.permissions.delete(v.workflow_superadmin)}},Y=class extends K{constructor(){super(b.developer,Object.values(v)),this.permissions.delete(v.account_admin),this.permissions.delete(v.project_admin),this.permissions.delete(v.project_settings_write),this.permissions.delete(v.env_admin),this.permissions.delete(v.manage_billing),this.permissions.delete(v.audit_read),this.permissions.delete(v.agent_run_read),this.permissions.delete(v.content_read_all),this.permissions.delete(v.content_superadmin),this.permissions.delete(v.workflow_superadmin)}},ge=class extends K{constructor(){super(b.application,[v.int_read,v.int_execute,v.int_write,v.run_read,v.content_write,v.content_read,v.content_write,v.content_admin,v.project_admin,v.workflow_run,v.project_settings_write,v.account_write])}},_e=class extends K{constructor(){super(b.automation,[v.content_read,v.content_write,v.content_admin,v.int_read,v.int_execute,v.run_read,v.workflow_run,v.project_integration_read])}},ve=class extends K{constructor(){super(b.content_processor,[v.content_read,v.content_write,v.content_admin,v.content_superadmin,v.int_execute,v.workflow_read,v.workflow_run,v.run_read])}},ye=class extends K{constructor(){super(b.consumer,[v.content_admin,v.content_read,v.content_write,v.content_delete,v.int_read,v.int_execute,v.run_read,v.workflow_run])}},be=class extends K{constructor(){super(b.executor,[v.int_execute,v.run_read,v.workflow_run])}},xe=class extends K{constructor(){super(b.reader,[v.int_read,v.run_read,v.content_read])}};const Se=[v.studio_access,v.account_read,v.project_integration_read,v.api_key_read,v.billing_read,v.audit_read,v.int_read,v.run_read,v.content_read,v.content_read_all,v.task_read,v.workflow_read,v.agent_run_read];var X=class extends K{constructor(e){super(e,Se)}},Ce=class extends K{constructor(){super(b.billing,[v.manage_billing])}},we=class extends K{constructor(){super(b.app_member,[v.int_read,v.int_execute,v.int_write,v.run_read,v.content_write,v.content_read,v.content_delete,v.workflow_run])}},Te=class extends Y{constructor(){super(),this.name=b.content_superadmin,this.permissions.add(v.content_superadmin)}};const Ee={[b.owner]:new q,[b.admin]:new J,[b.app_admin]:new me,[b.manager]:new he,[b.developer]:new Y,[b.application]:new ge,[b.automation]:new _e,[b.content_processor]:new ve,[b.consumer]:new ye,[b.executor]:new be,[b.reader]:new xe,[b.auditor]:new X(b.auditor),[b.support]:new X(b.support),[b.billing]:new Ce,[b.app_member]:new we,[b.member]:new K(b.member,[]),[b.content_superadmin]:new Te},Z=[{domain:`system`,roles:new Map(Object.entries(Ee))},pe];function Q(e){for(let t of Z){let n=t.roles.get(e);if(n)return n}throw Error(`Role ${e} not found`)}function $(){let e=[];for(let t of Z)for(let n of t.roles.values())e.push(n);return e}function De(e){let t=Z.find(t=>t.domain===e);return t?Array.from(t.roles.values()):[]}function Oe(e){return $().filter(t=>t instanceof H&&t.applicableScopes.includes(e))}function ke(){return $().filter(e=>e instanceof V)}function Ae(){return $().map(e=>e.name)}function je(e){let t=new Set;for(let n of e){let e=Q(n);for(let n of e.permissions)t.add(n)}return Array.from(t)}function Me(e){let t=Q(e);return t instanceof H?[...t.permissions].map(e=>`${t.domain}:${e}`):[...t.permissions]}var Ne=class e{roles;constructor(e){this.roles=e}static fromRoleNames(t){let n=t.map(e=>Q(e));return new e(n)}static fromRoleName(t){let n=[Q(t)];return new e(n)}hasPermission(e){return this.roles.some(t=>t.hasPermission(e))}};export{H as AbacRole,G as ContentRoleNames,n as HANDLEBARS_HELPER_NAMES,B as Role,Ne as RoleList,V as SystemRole,i as TEMPLATE_SYSTEM_VARIABLES,o as TEMPLATE_SYSTEM_VARIABLE_NAMES,D as analyzeHandlebarsTemplate,s as describeTemplateSystemVariables,M as executeHandlebars,j as executeJST,O as extractHandlebarsVariables,k as generateMockData,Ae as getAllRoleNames,Me as getDelegablePermissionsForRole,je as getPermissionsForRoles,Q as getRoleByName,d as isTemplateSystemVariable,Oe as listAbacRolesForScope,$ as listRoles,De as listRolesByDomain,ke as listSystemRoles,ie as renderPrompt,N as renderSegments,re as renderSegmentsOrErrors,A as renderTemplate,ee as substituteEndpoints,z as validatePrompt,h as withTemplateSystemVariables};
|
|
2
3
|
//# sourceMappingURL=vertesia-studio-utils.js.map
|