@pixerate/editor 0.23.0 → 0.24.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 +96 -1
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/dist/agent/index.cjs +9 -8
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +4 -3
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.js +3 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/canvas/index.cjs +1210 -17
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +318 -1
- package/dist/canvas/index.d.ts +318 -1
- package/dist/canvas/index.js +1199 -6
- package/dist/canvas/index.js.map +1 -1
- package/dist/{chunk-QBJ22YZR.js → chunk-3CN2WD3X.js} +1354 -206
- package/dist/chunk-3CN2WD3X.js.map +1 -0
- package/dist/{chunk-JJDLPEWL.js → chunk-3LV6RRPH.js} +2 -2
- package/dist/{chunk-MJZBNWG7.js → chunk-5S3Z4PPF.js} +78 -557
- package/dist/chunk-5S3Z4PPF.js.map +1 -0
- package/dist/chunk-664LQYFJ.js +115 -0
- package/dist/chunk-664LQYFJ.js.map +1 -0
- package/dist/{chunk-AA4ZEVCC.cjs → chunk-D27YFC46.cjs} +101 -580
- package/dist/chunk-D27YFC46.cjs.map +1 -0
- package/dist/chunk-D6FH2YAX.cjs +131 -0
- package/dist/chunk-D6FH2YAX.cjs.map +1 -0
- package/dist/{chunk-4SUNJZWB.cjs → chunk-FD4LPFAE.cjs} +48 -200
- package/dist/chunk-FD4LPFAE.cjs.map +1 -0
- package/dist/chunk-FODNLX5N.js +749 -0
- package/dist/chunk-FODNLX5N.js.map +1 -0
- package/dist/{chunk-OYXSKQFR.js → chunk-FPENXAEJ.js} +35 -187
- package/dist/chunk-FPENXAEJ.js.map +1 -0
- package/dist/chunk-HLIMTC6N.js +1 -0
- package/dist/chunk-HLIMTC6N.js.map +1 -0
- package/dist/{chunk-QGHGJ56O.js → chunk-ITBSKI26.js} +1483 -19
- package/dist/chunk-ITBSKI26.js.map +1 -0
- package/dist/{chunk-XDMXXC4Z.cjs → chunk-MA2F5KHF.cjs} +350 -227
- package/dist/chunk-MA2F5KHF.cjs.map +1 -0
- package/dist/{chunk-RIKBJLS2.cjs → chunk-MCSJFWAO.cjs} +1356 -208
- package/dist/chunk-MCSJFWAO.cjs.map +1 -0
- package/dist/chunk-MKA3AHLV.cjs +256 -0
- package/dist/chunk-MKA3AHLV.cjs.map +1 -0
- package/dist/chunk-OLZJXL4R.cjs +749 -0
- package/dist/chunk-OLZJXL4R.cjs.map +1 -0
- package/dist/chunk-OXSV64JX.js +689 -0
- package/dist/chunk-OXSV64JX.js.map +1 -0
- package/dist/chunk-P3RQ5UJE.cjs +689 -0
- package/dist/chunk-P3RQ5UJE.cjs.map +1 -0
- package/dist/chunk-P6ODPZ4W.js +256 -0
- package/dist/chunk-P6ODPZ4W.js.map +1 -0
- package/dist/chunk-PGNZKFQS.js +685 -0
- package/dist/chunk-PGNZKFQS.js.map +1 -0
- package/dist/chunk-PL4JB3BF.cjs +1 -0
- package/dist/chunk-PL4JB3BF.cjs.map +1 -0
- package/dist/{chunk-GVSMRPHB.cjs → chunk-SBCZ6RN5.cjs} +1568 -104
- package/dist/chunk-SBCZ6RN5.cjs.map +1 -0
- package/dist/{chunk-CL37JGFW.cjs → chunk-SML64VJG.cjs} +4 -4
- package/dist/{chunk-CL37JGFW.cjs.map → chunk-SML64VJG.cjs.map} +1 -1
- package/dist/chunk-TNNJXF46.cjs +115 -0
- package/dist/chunk-TNNJXF46.cjs.map +1 -0
- package/dist/chunk-U5HZSFCS.js +131 -0
- package/dist/chunk-U5HZSFCS.js.map +1 -0
- package/dist/{chunk-K3R5NG2D.js → chunk-U5KWZU4X.js} +251 -128
- package/dist/chunk-U5KWZU4X.js.map +1 -0
- package/dist/chunk-XNORY7M6.cjs +685 -0
- package/dist/chunk-XNORY7M6.cjs.map +1 -0
- package/dist/commands/index.d.cts +5 -353
- package/dist/commands/index.d.ts +5 -353
- package/dist/comment-store-BEMgVlAA.d.cts +135 -0
- package/dist/comment-store-BEMgVlAA.d.ts +135 -0
- package/dist/compare/index.cjs +15 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +58 -0
- package/dist/compare/index.d.ts +58 -0
- package/dist/compare/index.js +15 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/{controller-pePCJLT1.d.cts → controller-BhLLAoi8.d.cts} +45 -4
- package/dist/{controller-pePCJLT1.d.ts → controller-BhLLAoi8.d.ts} +45 -4
- package/dist/documents-BQjzJNe2.d.ts +76 -0
- package/dist/documents-KRTPhvst.d.cts +76 -0
- package/dist/extensions/index.cjs +53 -5
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +7 -3
- package/dist/extensions/index.d.ts +7 -3
- package/dist/extensions/index.js +52 -4
- package/dist/generation/index.cjs +1373 -0
- package/dist/generation/index.cjs.map +1 -0
- package/dist/generation/index.d.cts +554 -0
- package/dist/generation/index.d.ts +554 -0
- package/dist/generation/index.js +1373 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/grammar/index.cjs +48 -3
- package/dist/grammar/index.cjs.map +1 -1
- package/dist/grammar/index.d.cts +322 -100
- package/dist/grammar/index.d.ts +322 -100
- package/dist/grammar/index.js +54 -9
- package/dist/image-editor/index.cjs +1831 -30
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +590 -3
- package/dist/image-editor/index.d.ts +590 -3
- package/dist/image-editor/index.js +1807 -6
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-CCr_z9kF.d.cts → index-BhJBSm2d.d.cts} +370 -4
- package/dist/{index-Ck6ajwXh.d.ts → index-fJrlkJCd.d.ts} +370 -4
- package/dist/index.cjs +162 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -8
- package/dist/index.d.ts +14 -8
- package/dist/index.js +174 -37
- package/dist/index.js.map +1 -1
- package/dist/migrate-iTlm3a8h.d.cts +112 -0
- package/dist/migrate-iTlm3a8h.d.ts +112 -0
- package/dist/persistence/index.cjs +676 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +347 -0
- package/dist/persistence/index.d.ts +347 -0
- package/dist/persistence/index.js +676 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/{registry-D5-R90p0.d.cts → registry-BDe-vlv3.d.ts} +2 -40
- package/dist/registry-D32LpIc4.d.cts +354 -0
- package/dist/{registry-D5-R90p0.d.ts → registry-DnzpgY27.d.cts} +2 -40
- package/dist/registry-evKTP4ls.d.ts +354 -0
- package/dist/schema-DYDGdYL9.d.cts +41 -0
- package/dist/schema-DYDGdYL9.d.ts +41 -0
- package/dist/serializers/index.cjs +4 -3
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +2 -1
- package/dist/serializers/index.d.ts +2 -1
- package/dist/serializers/index.js +3 -2
- package/dist/sourcemap-C8AH3MBQ.d.cts +91 -0
- package/dist/sourcemap-DA1Evhrv.d.ts +91 -0
- package/dist/spreadsheet/index.cjs +37 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +188 -17
- package/dist/spreadsheet/index.d.ts +188 -17
- package/dist/spreadsheet/index.js +43 -9
- package/dist/{tokens-CyLZmIei.d.cts → tokens-D7yXvUU6.d.cts} +15 -2
- package/dist/{tokens-CyLZmIei.d.ts → tokens-D7yXvUU6.d.ts} +15 -2
- package/dist/{track-changes-BSF58RK0.d.ts → track-changes-BK5sVf4_.d.cts} +18 -136
- package/dist/{track-changes-BSF58RK0.d.cts → track-changes-CDjCrwKe.d.ts} +18 -136
- package/package.json +16 -1
- package/dist/chunk-4SUNJZWB.cjs.map +0 -1
- package/dist/chunk-AA4ZEVCC.cjs.map +0 -1
- package/dist/chunk-AXV2ZW34.cjs +0 -118
- package/dist/chunk-AXV2ZW34.cjs.map +0 -1
- package/dist/chunk-B2ZRLN4S.js +0 -118
- package/dist/chunk-B2ZRLN4S.js.map +0 -1
- package/dist/chunk-GVSMRPHB.cjs.map +0 -1
- package/dist/chunk-K3R5NG2D.js.map +0 -1
- package/dist/chunk-MJZBNWG7.js.map +0 -1
- package/dist/chunk-OYXSKQFR.js.map +0 -1
- package/dist/chunk-QBJ22YZR.js.map +0 -1
- package/dist/chunk-QGHGJ56O.js.map +0 -1
- package/dist/chunk-RIKBJLS2.cjs.map +0 -1
- package/dist/chunk-XDMXXC4Z.cjs.map +0 -1
- /package/dist/{chunk-JJDLPEWL.js.map → chunk-3LV6RRPH.js.map} +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkMKA3AHLVcjs = require('./chunk-MKA3AHLV.cjs');
|
|
10
10
|
|
|
11
11
|
// src/grammar/tokenizer.ts
|
|
12
12
|
function tokenizePrompt(text) {
|
|
@@ -20,7 +20,7 @@ function tokenizePromptWithDiagnostics(text) {
|
|
|
20
20
|
return { tokens: [], diagnostics: [] };
|
|
21
21
|
}
|
|
22
22
|
const rawMatches = [];
|
|
23
|
-
const tmplRegex = new RegExp(
|
|
23
|
+
const tmplRegex = new RegExp(_chunkMKA3AHLVcjs.TEMPLATE_REGEX.source, _chunkMKA3AHLVcjs.TEMPLATE_REGEX.flags);
|
|
24
24
|
let match;
|
|
25
25
|
while ((match = tmplRegex.exec(text)) !== null) {
|
|
26
26
|
rawMatches.push({
|
|
@@ -31,7 +31,7 @@ function tokenizePromptWithDiagnostics(text) {
|
|
|
31
31
|
end: match.index + match[0].length
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
const varRegex = new RegExp(
|
|
34
|
+
const varRegex = new RegExp(_chunkMKA3AHLVcjs.VARIABLE_REGEX.source, _chunkMKA3AHLVcjs.VARIABLE_REGEX.flags);
|
|
35
35
|
while ((match = varRegex.exec(text)) !== null) {
|
|
36
36
|
const start = match.index;
|
|
37
37
|
const end = start + match[0].length;
|
|
@@ -39,7 +39,7 @@ function tokenizePromptWithDiagnostics(text) {
|
|
|
39
39
|
(m) => !(end <= m.start || start >= m.end)
|
|
40
40
|
);
|
|
41
41
|
if (!overlaps) {
|
|
42
|
-
const parsed =
|
|
42
|
+
const parsed = _chunkMKA3AHLVcjs.parseVariableBody.call(void 0, match[1]);
|
|
43
43
|
if (parsed.kind === "conditional") {
|
|
44
44
|
rawMatches.push({
|
|
45
45
|
type: "conditional",
|
|
@@ -68,8 +68,8 @@ function tokenizePromptWithDiagnostics(text) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
const instRegex = new RegExp(
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
_chunkMKA3AHLVcjs.INSTRUCTION_REGEX.source,
|
|
72
|
+
_chunkMKA3AHLVcjs.INSTRUCTION_REGEX.flags
|
|
73
73
|
);
|
|
74
74
|
while ((match = instRegex.exec(text)) !== null) {
|
|
75
75
|
const start = match.index;
|
|
@@ -93,12 +93,30 @@ function tokenizePromptWithDiagnostics(text) {
|
|
|
93
93
|
const conditionals = rawMatches.filter(
|
|
94
94
|
(m) => m.type === "conditional"
|
|
95
95
|
);
|
|
96
|
-
|
|
96
|
+
_chunkMKA3AHLVcjs.matchConditionalTags.call(void 0,
|
|
97
97
|
conditionals.map((m) => ({ conditional: m.conditional, name: m.value }))
|
|
98
98
|
).forEach((result, i) => {
|
|
99
|
-
if (!result.error) return;
|
|
100
99
|
const tag = conditionals[i];
|
|
100
|
+
const parsed = result.comparison;
|
|
101
|
+
if (!result.error) {
|
|
102
|
+
if (_optionalChain([parsed, 'optionalAccess', _ => _.comparison]) && tag.conditional !== "end") {
|
|
103
|
+
tag.value = parsed.subject;
|
|
104
|
+
tag.comparison = parsed.comparison;
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
101
108
|
literal.add(tag);
|
|
109
|
+
if (result.error === "invalid-condition") {
|
|
110
|
+
if (tag.conditional === "end") return;
|
|
111
|
+
diagnostics.push({
|
|
112
|
+
code: result.error,
|
|
113
|
+
message: `Invalid condition "${tag.raw}": ${_nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _2 => _2.error]), () => ( "malformed comparison"))}`,
|
|
114
|
+
name: _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _3 => _3.subject]), () => ( tag.value)),
|
|
115
|
+
start: tag.start,
|
|
116
|
+
end: tag.end
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
102
120
|
diagnostics.push({
|
|
103
121
|
code: result.error,
|
|
104
122
|
message: result.error === "unclosed-section" ? `Section "${tag.raw}" is never closed with "{/${tag.value}}"` : `"${tag.raw}" does not close any open section`,
|
|
@@ -107,11 +125,12 @@ function tokenizePromptWithDiagnostics(text) {
|
|
|
107
125
|
end: tag.end
|
|
108
126
|
});
|
|
109
127
|
});
|
|
128
|
+
diagnostics.sort((a, b) => a.start - b.start);
|
|
110
129
|
const tokens = [];
|
|
111
130
|
let currentIdx = 0;
|
|
112
131
|
const pushText = (start, end) => {
|
|
113
132
|
const previous = tokens[tokens.length - 1];
|
|
114
|
-
if (_optionalChain([previous, 'optionalAccess',
|
|
133
|
+
if (_optionalChain([previous, 'optionalAccess', _4 => _4.type]) === "text" && previous.end === start) {
|
|
115
134
|
previous.raw = previous.value = text.slice(previous.start, end);
|
|
116
135
|
previous.end = end;
|
|
117
136
|
return;
|
|
@@ -165,14 +184,14 @@ function getLatestVersion(template) {
|
|
|
165
184
|
var TEMPLATE_LOOP_ERROR = "[Template loop detected]";
|
|
166
185
|
var TEMPLATE_DEPTH_ERROR = "[Template max depth exceeded]";
|
|
167
186
|
function getTemplateBody(template, bindings) {
|
|
168
|
-
const boundVersionId = _optionalChain([bindings, 'optionalAccess',
|
|
187
|
+
const boundVersionId = _optionalChain([bindings, 'optionalAccess', _5 => _5[template.name]]);
|
|
169
188
|
if (boundVersionId && template.versions) {
|
|
170
189
|
const boundVersion = template.versions.find(
|
|
171
190
|
(v) => v.id === boundVersionId || v.version === boundVersionId
|
|
172
191
|
);
|
|
173
|
-
return _optionalChain([boundVersion, 'optionalAccess',
|
|
192
|
+
return _optionalChain([boundVersion, 'optionalAccess', _6 => _6.body]);
|
|
174
193
|
}
|
|
175
|
-
return _nullishCoalesce(_optionalChain([getLatestVersion, 'call',
|
|
194
|
+
return _nullishCoalesce(_optionalChain([getLatestVersion, 'call', _7 => _7(template), 'optionalAccess', _8 => _8.body]), () => ( template.body));
|
|
176
195
|
}
|
|
177
196
|
var Output = (_class = class {
|
|
178
197
|
constructor(segments) {;_class.prototype.__init.call(this);
|
|
@@ -204,7 +223,7 @@ var Output = (_class = class {
|
|
|
204
223
|
replaced(rawStart, rawEnd, value, extra) {
|
|
205
224
|
const resolvedStart = this.text.length;
|
|
206
225
|
this.text += value;
|
|
207
|
-
_optionalChain([this, 'access',
|
|
226
|
+
_optionalChain([this, 'access', _9 => _9.segments, 'optionalAccess', _10 => _10.push, 'call', _11 => _11({
|
|
208
227
|
resolvedStart,
|
|
209
228
|
resolvedEnd: this.text.length,
|
|
210
229
|
rawStart,
|
|
@@ -282,7 +301,7 @@ function resolvePrompt(text, templates = [], options = {}) {
|
|
|
282
301
|
continue;
|
|
283
302
|
}
|
|
284
303
|
if (values && token.type === "variable") {
|
|
285
|
-
const supplied =
|
|
304
|
+
const supplied = _chunkMKA3AHLVcjs.getSuppliedValue.call(void 0, values, token.value);
|
|
286
305
|
const value = _nullishCoalesce(supplied, () => ( token.defaultValue));
|
|
287
306
|
if (value !== void 0) {
|
|
288
307
|
out2.replaced(token.start, token.end, value, {
|
|
@@ -300,7 +319,12 @@ function resolvePrompt(text, templates = [], options = {}) {
|
|
|
300
319
|
};
|
|
301
320
|
if (token.conditional !== "end") {
|
|
302
321
|
const close = pairs.get(i);
|
|
303
|
-
if (!
|
|
322
|
+
if (!_chunkMKA3AHLVcjs.evaluateCondition.call(void 0,
|
|
323
|
+
token.conditional,
|
|
324
|
+
token.value,
|
|
325
|
+
values,
|
|
326
|
+
token.comparison
|
|
327
|
+
)) {
|
|
304
328
|
out2.replaced(token.start, tokens[close].end, "", tagInfo);
|
|
305
329
|
i = close;
|
|
306
330
|
continue;
|
|
@@ -336,13 +360,18 @@ function evaluatePromptTokens(text, values) {
|
|
|
336
360
|
for (let i = 0; i < tokens.length; i++) {
|
|
337
361
|
const token = tokens[i];
|
|
338
362
|
if (token.type === "conditional") {
|
|
339
|
-
if (token.conditional !== "end" && !
|
|
363
|
+
if (token.conditional !== "end" && !_chunkMKA3AHLVcjs.evaluateCondition.call(void 0,
|
|
364
|
+
token.conditional,
|
|
365
|
+
token.value,
|
|
366
|
+
values,
|
|
367
|
+
token.comparison
|
|
368
|
+
)) {
|
|
340
369
|
i = pairs.get(i);
|
|
341
370
|
}
|
|
342
371
|
continue;
|
|
343
372
|
}
|
|
344
373
|
if (token.type === "variable") {
|
|
345
|
-
const supplied =
|
|
374
|
+
const supplied = _chunkMKA3AHLVcjs.getSuppliedValue.call(void 0, values, token.value);
|
|
346
375
|
const value = _nullishCoalesce(supplied, () => ( token.defaultValue));
|
|
347
376
|
if (value !== void 0) {
|
|
348
377
|
result.push({
|
|
@@ -358,187 +387,6 @@ function evaluatePromptTokens(text, values) {
|
|
|
358
387
|
return result;
|
|
359
388
|
}
|
|
360
389
|
|
|
361
|
-
// src/grammar/resolver.ts
|
|
362
|
-
function resolveTemplates(text, templates = [], options) {
|
|
363
|
-
return resolvePrompt(text, templates, options).text;
|
|
364
|
-
}
|
|
365
|
-
function resolveVariables(text, values) {
|
|
366
|
-
if (!text) return "";
|
|
367
|
-
return resolvePrompt(text, [], { values }).text;
|
|
368
|
-
}
|
|
369
|
-
function extractTemplateNames(text) {
|
|
370
|
-
if (!text) return [];
|
|
371
|
-
const set = /* @__PURE__ */ new Set();
|
|
372
|
-
const regex = new RegExp(_chunkAXV2ZW34cjs.TEMPLATE_REGEX.source, _chunkAXV2ZW34cjs.TEMPLATE_REGEX.flags);
|
|
373
|
-
let match;
|
|
374
|
-
while ((match = regex.exec(text)) !== null) {
|
|
375
|
-
set.add(match[1].trim());
|
|
376
|
-
}
|
|
377
|
-
return Array.from(set);
|
|
378
|
-
}
|
|
379
|
-
function extractVariableNames(text) {
|
|
380
|
-
if (!text) return [];
|
|
381
|
-
const set = /* @__PURE__ */ new Set();
|
|
382
|
-
const regex = new RegExp(_chunkAXV2ZW34cjs.VARIABLE_REGEX.source, _chunkAXV2ZW34cjs.VARIABLE_REGEX.flags);
|
|
383
|
-
let match;
|
|
384
|
-
while ((match = regex.exec(text)) !== null) {
|
|
385
|
-
set.add(_chunkAXV2ZW34cjs.parseVariableBody.call(void 0, match[1]).name);
|
|
386
|
-
}
|
|
387
|
-
return Array.from(set);
|
|
388
|
-
}
|
|
389
|
-
function extractInstructionNames(text) {
|
|
390
|
-
if (!text) return [];
|
|
391
|
-
const set = /* @__PURE__ */ new Set();
|
|
392
|
-
const regex = new RegExp(_chunkAXV2ZW34cjs.INSTRUCTION_REGEX.source, _chunkAXV2ZW34cjs.INSTRUCTION_REGEX.flags);
|
|
393
|
-
let match;
|
|
394
|
-
while ((match = regex.exec(text)) !== null) {
|
|
395
|
-
set.add(match[1].trim());
|
|
396
|
-
}
|
|
397
|
-
return Array.from(set);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// src/grammar/sourcemap.ts
|
|
401
|
-
function resolveTemplatesWithMapping(text, templates = [], templateBindings, options) {
|
|
402
|
-
if (_optionalChain([options, 'optionalAccess', _9 => _9.values]) === void 0 && (!templates || templates.length === 0 || !text.includes("{{"))) {
|
|
403
|
-
return {
|
|
404
|
-
diagnostics: getPromptDiagnostics(text),
|
|
405
|
-
text,
|
|
406
|
-
map: [
|
|
407
|
-
{
|
|
408
|
-
resolvedStart: 0,
|
|
409
|
-
resolvedEnd: text.length,
|
|
410
|
-
source: "raw",
|
|
411
|
-
rawStart: 0,
|
|
412
|
-
rawEnd: text.length
|
|
413
|
-
}
|
|
414
|
-
]
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
return resolvePrompt(text, templates, {
|
|
418
|
-
bindings: templateBindings,
|
|
419
|
-
maxDepth: _optionalChain([options, 'optionalAccess', _10 => _10.maxDepth]),
|
|
420
|
-
values: _optionalChain([options, 'optionalAccess', _11 => _11.values])
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
function mapResolvedOffsetToRaw(resolvedOffset, map) {
|
|
424
|
-
for (let i = 0; i < map.length; i++) {
|
|
425
|
-
const seg = map[i];
|
|
426
|
-
const isLast = i === map.length - 1;
|
|
427
|
-
const inRange = isLast ? resolvedOffset >= seg.resolvedStart && resolvedOffset <= seg.resolvedEnd : resolvedOffset >= seg.resolvedStart && resolvedOffset < seg.resolvedEnd;
|
|
428
|
-
if (inRange) {
|
|
429
|
-
if (seg.source === "raw") {
|
|
430
|
-
return seg.rawStart + (resolvedOffset - seg.resolvedStart);
|
|
431
|
-
}
|
|
432
|
-
if (resolvedOffset === seg.resolvedEnd) {
|
|
433
|
-
return seg.rawEnd;
|
|
434
|
-
}
|
|
435
|
-
return seg.rawStart;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return resolvedOffset;
|
|
439
|
-
}
|
|
440
|
-
function mapRawOffsetToResolved(rawOffset, map) {
|
|
441
|
-
for (let i = 0; i < map.length; i++) {
|
|
442
|
-
const seg = map[i];
|
|
443
|
-
const isLast = i === map.length - 1;
|
|
444
|
-
const inRange = isLast ? rawOffset >= seg.rawStart && rawOffset <= seg.rawEnd : rawOffset >= seg.rawStart && rawOffset < seg.rawEnd;
|
|
445
|
-
if (inRange) {
|
|
446
|
-
if (seg.source === "raw") {
|
|
447
|
-
return seg.resolvedStart + (rawOffset - seg.rawStart);
|
|
448
|
-
}
|
|
449
|
-
if (rawOffset === seg.rawEnd) {
|
|
450
|
-
return seg.resolvedEnd;
|
|
451
|
-
}
|
|
452
|
-
return seg.resolvedStart;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return rawOffset;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// src/grammar/fields.ts
|
|
459
|
-
function extractVariables(text, options = {}) {
|
|
460
|
-
const descriptors = /* @__PURE__ */ new Map();
|
|
461
|
-
const templateMap = new Map(
|
|
462
|
-
(_nullishCoalesce(options.templates, () => ( []))).map((t) => [t.name, t])
|
|
463
|
-
);
|
|
464
|
-
const maxDepth = _nullishCoalesce(options.maxDepth, () => ( 10));
|
|
465
|
-
const describe = (name, templateName) => {
|
|
466
|
-
let descriptor = descriptors.get(name);
|
|
467
|
-
if (!descriptor) {
|
|
468
|
-
descriptor = {
|
|
469
|
-
name,
|
|
470
|
-
usedAsValue: false,
|
|
471
|
-
usedInCondition: false,
|
|
472
|
-
occurrences: 0,
|
|
473
|
-
templates: []
|
|
474
|
-
};
|
|
475
|
-
descriptors.set(name, descriptor);
|
|
476
|
-
}
|
|
477
|
-
descriptor.occurrences++;
|
|
478
|
-
if (templateName && !descriptor.templates.includes(templateName)) {
|
|
479
|
-
descriptor.templates.push(templateName);
|
|
480
|
-
}
|
|
481
|
-
return descriptor;
|
|
482
|
-
};
|
|
483
|
-
const visit = (source, visited, depth, templateName) => {
|
|
484
|
-
for (const token of tokenizePrompt(source)) {
|
|
485
|
-
if (token.type === "variable") {
|
|
486
|
-
const descriptor = describe(token.value, templateName);
|
|
487
|
-
descriptor.usedAsValue = true;
|
|
488
|
-
if (descriptor.defaultValue === void 0 && token.defaultValue !== void 0) {
|
|
489
|
-
descriptor.defaultValue = token.defaultValue;
|
|
490
|
-
}
|
|
491
|
-
if (descriptor.description === void 0 && token.description !== void 0) {
|
|
492
|
-
descriptor.description = token.description;
|
|
493
|
-
}
|
|
494
|
-
} else if (token.type === "conditional" && token.conditional !== "end") {
|
|
495
|
-
describe(token.value, templateName).usedInCondition = true;
|
|
496
|
-
} else if (token.type === "template") {
|
|
497
|
-
const template = templateMap.get(token.value);
|
|
498
|
-
if (!template || visited.has(token.value) || depth + 1 > maxDepth) {
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
const body = getTemplateBody(template, options.bindings);
|
|
502
|
-
if (body === void 0) continue;
|
|
503
|
-
visit(body, new Set(visited).add(token.value), depth + 1, token.value);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
if (text) visit(text, /* @__PURE__ */ new Set(), 0);
|
|
508
|
-
return Array.from(descriptors.values());
|
|
509
|
-
}
|
|
510
|
-
function getVariableFormFields(text, options = {}) {
|
|
511
|
-
return extractVariables(text, options).map((variable) => ({
|
|
512
|
-
name: variable.name,
|
|
513
|
-
label: variable.description || variable.name,
|
|
514
|
-
placeholder: _nullishCoalesce(variable.defaultValue, () => ( "")),
|
|
515
|
-
...variable.defaultValue !== void 0 ? { defaultValue: variable.defaultValue } : {},
|
|
516
|
-
...variable.description !== void 0 ? { description: variable.description } : {},
|
|
517
|
-
required: variable.usedAsValue && variable.defaultValue === void 0,
|
|
518
|
-
conditionOnly: !variable.usedAsValue
|
|
519
|
-
}));
|
|
520
|
-
}
|
|
521
|
-
function compactVariableValues(input) {
|
|
522
|
-
const values = {};
|
|
523
|
-
for (const [name, value] of Object.entries(input)) {
|
|
524
|
-
if (value !== null && value !== void 0 && value.trim() !== "") {
|
|
525
|
-
values[name] = value;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
return values;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
390
|
|
|
543
391
|
|
|
544
392
|
|
|
@@ -549,5 +397,5 @@ function compactVariableValues(input) {
|
|
|
549
397
|
|
|
550
398
|
|
|
551
399
|
|
|
552
|
-
exports.tokenizePrompt = tokenizePrompt; exports.getPromptDiagnostics = getPromptDiagnostics; exports.tokenizePromptWithDiagnostics = tokenizePromptWithDiagnostics; exports.getLatestVersion = getLatestVersion; exports.TEMPLATE_LOOP_ERROR = TEMPLATE_LOOP_ERROR; exports.TEMPLATE_DEPTH_ERROR = TEMPLATE_DEPTH_ERROR; exports.getTemplateBody = getTemplateBody; exports.resolvePrompt = resolvePrompt; exports.evaluatePromptTokens = evaluatePromptTokens;
|
|
553
|
-
//# sourceMappingURL=chunk-
|
|
400
|
+
exports.tokenizePrompt = tokenizePrompt; exports.getPromptDiagnostics = getPromptDiagnostics; exports.tokenizePromptWithDiagnostics = tokenizePromptWithDiagnostics; exports.getLatestVersion = getLatestVersion; exports.TEMPLATE_LOOP_ERROR = TEMPLATE_LOOP_ERROR; exports.TEMPLATE_DEPTH_ERROR = TEMPLATE_DEPTH_ERROR; exports.getTemplateBody = getTemplateBody; exports.resolvePrompt = resolvePrompt; exports.evaluatePromptTokens = evaluatePromptTokens;
|
|
401
|
+
//# sourceMappingURL=chunk-FD4LPFAE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-FD4LPFAE.cjs","../src/grammar/tokenizer.ts","../src/grammar/engine.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACeO,SAAS,cAAA,CAAe,IAAA,EAAuB;AACpD,EAAA,OAAO,6BAAA,CAA8B,IAAI,CAAA,CAAE,MAAA;AAC7C;AAKO,SAAS,oBAAA,CAAqB,IAAA,EAAkC;AACrE,EAAA,OAAO,6BAAA,CAA8B,IAAI,CAAA,CAAE,WAAA;AAC7C;AAKO,SAAS,6BAAA,CAA8B,IAAA,EAA8B;AAC1E,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM;AACT,IAAA,OAAO,EAAE,MAAA,EAAQ,CAAC,CAAA,EAAG,WAAA,EAAa,CAAC,EAAE,CAAA;AAAA,EACvC;AAEA,EAAA,MAAM,WAAA,EAAyB,CAAC,CAAA;AAGhC,EAAA,MAAM,UAAA,EA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A;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-FD4LPFAE.cjs","sourcesContent":[null,"import {\n TEMPLATE_REGEX,\n VARIABLE_REGEX,\n INSTRUCTION_REGEX,\n Token,\n PromptDiagnostic,\n} from \"./tokens\";\nimport { matchConditionalTags, parseVariableBody } from \"./variables\";\n\ntype RawMatch = Token & { type: \"template\" | \"variable\" | \"instruction\" | \"conditional\" };\n\nexport interface TokenizeResult {\n tokens: Token[];\n /** Unbalanced conditional tags, which were emitted as text. */\n diagnostics: PromptDiagnostic[];\n}\n\n/**\n * Parses any prompt string into an array of typed tokens in linear order.\n * Plain text between tokens is preserved as `{ type: 'text' }`.\n *\n * Conditional section tags (`{?name}`, `{!name}`, `{/name}`) are only emitted\n * as `conditional` tokens when balanced; unbalanced tags become text. Use\n * `tokenizePromptWithDiagnostics` to find out which tags were rejected.\n */\nexport function tokenizePrompt(text: string): Token[] {\n return tokenizePromptWithDiagnostics(text).tokens;\n}\n\n/**\n * Returns the diagnostics `tokenizePrompt` would report for `text`.\n */\nexport function getPromptDiagnostics(text: string): PromptDiagnostic[] {\n return tokenizePromptWithDiagnostics(text).diagnostics;\n}\n\n/**\n * Like `tokenizePrompt`, but also reports unbalanced conditional tags.\n */\nexport function tokenizePromptWithDiagnostics(text: string): TokenizeResult {\n if (!text) {\n return { tokens: [], diagnostics: [] };\n }\n\n const rawMatches: RawMatch[] = [];\n\n // Match {{template}}\n const tmplRegex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);\n let match: RegExpExecArray | null;\n while ((match = tmplRegex.exec(text)) !== null) {\n rawMatches.push({\n type: \"template\",\n raw: match[0],\n value: match[1].trim(),\n start: match.index,\n end: match.index + match[0].length,\n });\n }\n\n // Match {variable}\n const varRegex = new RegExp(VARIABLE_REGEX.source, VARIABLE_REGEX.flags);\n while ((match = varRegex.exec(text)) !== null) {\n // Avoid double matching if overlapping with template\n const start = match.index;\n const end = start + match[0].length;\n const overlaps = rawMatches.some(\n (m) => !(end <= m.start || start >= m.end),\n );\n if (!overlaps) {\n const parsed = parseVariableBody(match[1]);\n if (parsed.kind === \"conditional\") {\n rawMatches.push({\n type: \"conditional\",\n raw: match[0],\n value: parsed.name,\n start,\n end,\n conditional: parsed.conditional,\n });\n } else {\n const token: RawMatch = {\n type: \"variable\",\n raw: match[0],\n value: parsed.name,\n start,\n end,\n };\n if (parsed.defaultValue !== undefined) {\n token.defaultValue = parsed.defaultValue;\n }\n if (parsed.description !== undefined) {\n token.description = parsed.description;\n }\n rawMatches.push(token);\n }\n }\n }\n\n // Match __instruction__\n const instRegex = new RegExp(\n INSTRUCTION_REGEX.source,\n INSTRUCTION_REGEX.flags,\n );\n while ((match = instRegex.exec(text)) !== null) {\n const start = match.index;\n const end = start + match[0].length;\n const overlaps = rawMatches.some(\n (m) => !(end <= m.start || start >= m.end),\n );\n if (!overlaps) {\n rawMatches.push({\n type: \"instruction\",\n raw: match[0],\n value: match[1].trim(),\n start,\n end,\n });\n }\n }\n\n // Sort matches by start index\n rawMatches.sort((a, b) => a.start - b.start);\n\n // Pair conditional tags; unbalanced ones are demoted to text below.\n const diagnostics: PromptDiagnostic[] = [];\n const literal = new Set<RawMatch>();\n const conditionals = rawMatches.filter(\n (m): m is RawMatch & Required<Pick<Token, \"conditional\">> =>\n m.type === \"conditional\",\n );\n matchConditionalTags(\n conditionals.map((m) => ({ conditional: m.conditional, name: m.value })),\n ).forEach((result, i) => {\n const tag = conditionals[i];\n const parsed = result.comparison;\n if (!result.error) {\n if (parsed?.comparison && tag.conditional !== \"end\") {\n // `{?amount>100}` closed by `{/amount}`: a comparison on `amount`.\n tag.value = parsed.subject;\n tag.comparison = parsed.comparison;\n }\n return;\n }\n literal.add(tag);\n if (result.error === \"invalid-condition\") {\n // Reported once, on the opening tag.\n if (tag.conditional === \"end\") return;\n diagnostics.push({\n code: result.error,\n message: `Invalid condition \"${tag.raw}\": ${parsed?.error ?? \"malformed comparison\"}`,\n name: parsed?.subject ?? tag.value,\n start: tag.start,\n end: tag.end,\n });\n return;\n }\n diagnostics.push({\n code: result.error,\n message:\n result.error === \"unclosed-section\"\n ? `Section \"${tag.raw}\" is never closed with \"{/${tag.value}}\"`\n : `\"${tag.raw}\" does not close any open section`,\n name: tag.value,\n start: tag.start,\n end: tag.end,\n });\n });\n // Keep diagnostics in document order (an invalid pair is found at its close).\n diagnostics.sort((a, b) => a.start - b.start);\n\n const tokens: Token[] = [];\n let currentIdx = 0;\n\n const pushText = (start: number, end: number) => {\n const previous = tokens[tokens.length - 1];\n if (previous?.type === \"text\" && previous.end === start) {\n // Merge with text produced by a demoted conditional tag.\n previous.raw = previous.value = text.slice(previous.start, end);\n previous.end = end;\n return;\n }\n const textChunk = text.slice(start, end);\n tokens.push({\n type: \"text\",\n raw: textChunk,\n value: textChunk,\n start,\n end,\n });\n };\n\n for (const m of rawMatches) {\n if (m.start > currentIdx) {\n pushText(currentIdx, m.start);\n }\n if (literal.has(m)) {\n pushText(m.start, m.end);\n } else {\n tokens.push({ ...m });\n }\n currentIdx = m.end;\n }\n\n if (currentIdx < text.length) {\n pushText(currentIdx, text.length);\n }\n\n return { tokens, diagnostics };\n}\n","import type {\n PromptDiagnostic,\n PromptValues,\n Template,\n TemplateVersion,\n Token,\n} from \"./tokens\";\nimport type { SourceMapSegment } from \"./sourcemap\";\nimport { tokenizePromptWithDiagnostics } from \"./tokenizer\";\nimport { evaluateCondition, getSuppliedValue } from \"./variables\";\n\n/**\n * Finds the latest version of a template based on `latestVersion` or last version entry.\n */\nexport function getLatestVersion(\n template: Template,\n): TemplateVersion | undefined {\n if (!template.versions || template.versions.length === 0) {\n if (template.body !== undefined) {\n return {\n id: template.id || \"default\",\n version: \"1.0\",\n body: template.body,\n };\n }\n return undefined;\n }\n if (template.latestVersion) {\n const found = template.versions.find(\n (v) => v.version === template.latestVersion,\n );\n if (found) return found;\n }\n return template.versions[template.versions.length - 1];\n}\n\n/** Marker substituted for a template tag that would recurse into itself. */\nexport const TEMPLATE_LOOP_ERROR = \"[Template loop detected]\";\n/** Marker substituted for a template tag nested deeper than `maxDepth`. */\nexport const TEMPLATE_DEPTH_ERROR = \"[Template max depth exceeded]\";\n\n/**\n * Returns the body a template tag resolves to, honoring version bindings.\n */\nexport function getTemplateBody(\n template: Template,\n bindings?: Record<string, string>,\n): string | undefined {\n const boundVersionId = bindings?.[template.name];\n if (boundVersionId && template.versions) {\n const boundVersion = template.versions.find(\n (v) => v.id === boundVersionId || v.version === boundVersionId,\n );\n return boundVersion?.body;\n }\n return getLatestVersion(template)?.body ?? template.body;\n}\n\nexport interface ResolvePromptOptions {\n /** Template version bindings (`{ templateName: versionIdOrVersion }`). */\n bindings?: Record<string, string>;\n /** Maximum template nesting depth (default 10). */\n maxDepth?: number;\n /**\n * Values for `{variable}` slots and `{?variable}` / `{!variable}` sections.\n * When omitted, variables and section tags are left exactly as written.\n */\n values?: PromptValues;\n}\n\nexport interface ResolvePromptResult {\n text: string;\n map: SourceMapSegment[];\n diagnostics: PromptDiagnostic[];\n}\n\ntype Segment = SourceMapSegment & { locked?: boolean };\n\n/** Accumulates resolved text and, at the top level, source map segments. */\nclass Output {\n text = \"\";\n constructor(readonly segments: Segment[] | null) {}\n\n /** Text copied verbatim from the raw input. Locked segments never merge. */\n raw(rawStart: number, rawEnd: number, value: string, locked = false) {\n const resolvedStart = this.text.length;\n this.text += value;\n if (!this.segments) return;\n const last = this.segments[this.segments.length - 1];\n if (\n !locked &&\n last &&\n last.source === \"raw\" &&\n !last.locked &&\n last.rawEnd === rawStart &&\n last.resolvedEnd === resolvedStart\n ) {\n last.rawEnd = rawEnd;\n last.resolvedEnd = this.text.length;\n return;\n }\n this.segments.push({\n resolvedStart,\n resolvedEnd: this.text.length,\n source: \"raw\",\n rawStart,\n rawEnd,\n ...(locked ? { locked } : {}),\n });\n }\n\n /** Text that replaces a raw range (template body, value, removed section). */\n replaced(\n rawStart: number,\n rawEnd: number,\n value: string,\n extra: Pick<\n SourceMapSegment,\n \"source\" | \"templateName\" | \"variableName\" | \"valueSource\"\n >,\n ) {\n const resolvedStart = this.text.length;\n this.text += value;\n this.segments?.push({\n resolvedStart,\n resolvedEnd: this.text.length,\n rawStart,\n rawEnd,\n ...extra,\n });\n }\n}\n\n/** Pairs balanced conditional tokens (the tokenizer guarantees nesting). */\nfunction pairSections(tokens: Token[]): Map<number, number> {\n const pairs = new Map<number, number>();\n const stack: number[] = [];\n tokens.forEach((token, index) => {\n if (token.type !== \"conditional\") return;\n if (token.conditional === \"end\") {\n const open = stack.pop();\n if (open !== undefined) pairs.set(open, index);\n } else {\n stack.push(index);\n }\n });\n return pairs;\n}\n\n/**\n * Resolves a prompt: expands `{{templates}}` recursively (with loop and depth\n * protection), and, when `values` are given, substitutes `{variables}` (falling\n * back to their `|default`) and keeps or removes `{?name}…{/name}` sections.\n *\n * Template bodies are parsed on their own, so a section must open and close\n * within the same body. Templates inside a removed section are never expanded\n * and cannot trigger loop or depth errors. Unbalanced section tags are kept as\n * literal text and reported in `diagnostics`.\n *\n * Returns the resolved text, a source map from resolved to raw offsets, and\n * diagnostics. With no `values` the text matches the original template-only\n * resolver exactly.\n */\nexport function resolvePrompt(\n text: string,\n templates: Template[] = [],\n options: ResolvePromptOptions = {},\n): ResolvePromptResult {\n const templateMap = new Map<string, Template>();\n for (const t of templates) {\n templateMap.set(t.name, t);\n }\n const maxDepth = options.maxDepth ?? 10;\n const values = options.values;\n const diagnostics: PromptDiagnostic[] = [];\n const reported = new Set<string>();\n\n function resolveInto(\n source: string,\n out: Output,\n visited: Set<string>,\n depth: number,\n templateName: string | undefined,\n ): void {\n const { tokens, diagnostics: found } =\n tokenizePromptWithDiagnostics(source);\n for (const diagnostic of found) {\n const key = `${templateName ?? \"\"}\\u0000${diagnostic.start}\\u0000${diagnostic.code}`;\n if (reported.has(key)) continue;\n reported.add(key);\n diagnostics.push(\n templateName === undefined ? diagnostic : { ...diagnostic, templateName },\n );\n }\n const pairs = values ? pairSections(tokens) : null;\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n\n if (token.type === \"template\") {\n const name = token.value;\n if (visited.has(name)) {\n out.replaced(token.start, token.end, TEMPLATE_LOOP_ERROR, {\n source: \"template\",\n templateName: name,\n });\n continue;\n }\n const template = templateMap.get(name);\n const body = template\n ? getTemplateBody(template, options.bindings)\n : undefined;\n if (body === undefined) {\n out.raw(token.start, token.end, token.raw, true);\n continue;\n }\n if (depth + 1 > maxDepth) {\n out.replaced(token.start, token.end, TEMPLATE_DEPTH_ERROR, {\n source: \"template\",\n templateName: name,\n });\n continue;\n }\n const nested = new Output(null);\n const nextVisited = new Set(visited);\n nextVisited.add(name);\n resolveInto(body, nested, nextVisited, depth + 1, name);\n out.replaced(token.start, token.end, nested.text, {\n source: \"template\",\n templateName: name,\n });\n continue;\n }\n\n if (values && token.type === \"variable\") {\n const supplied = getSuppliedValue(values, token.value);\n const value = supplied ?? token.defaultValue;\n if (value !== undefined) {\n out.replaced(token.start, token.end, value, {\n source: \"variable\",\n variableName: token.value,\n valueSource: supplied !== undefined ? \"value\" : \"default\",\n });\n continue;\n }\n }\n\n if (values && token.type === \"conditional\" && token.conditional) {\n const tagInfo = {\n source: \"conditional\" as const,\n variableName: token.value,\n };\n if (token.conditional !== \"end\") {\n const close = pairs!.get(i)!;\n if (\n !evaluateCondition(\n token.conditional,\n token.value,\n values,\n token.comparison,\n )\n ) {\n // Drop the whole section, tags included.\n out.replaced(token.start, tokens[close].end, \"\", tagInfo);\n i = close;\n continue;\n }\n }\n out.replaced(token.start, token.end, \"\", tagInfo);\n continue;\n }\n\n out.raw(token.start, token.end, token.raw);\n }\n }\n\n const out = new Output([]);\n resolveInto(text, out, new Set(), 0, undefined);\n\n const map: SourceMapSegment[] = out.segments!.map(\n ({ locked: _locked, ...segment }) => segment,\n );\n if (map.length === 0) {\n map.push({\n resolvedStart: 0,\n resolvedEnd: 0,\n source: \"raw\",\n rawStart: 0,\n rawEnd: 0,\n });\n }\n return { text: out.text, map, diagnostics };\n}\n\n/** A token annotated with the value it resolves to. */\nexport interface EvaluatedToken extends Token {\n /** Variables only, when values were given: the substituted text. */\n resolvedValue?: string;\n /** Variables only: whether `resolvedValue` came from `values` or the default. */\n valueSource?: \"value\" | \"default\";\n}\n\n/**\n * Tokenizes a prompt for display. Without `values` this is `tokenizePrompt`.\n * With `values`, sections whose condition fails are removed (tags included),\n * the tags of kept sections are dropped, and each variable that has a value or\n * a default carries it in `resolvedValue`. Templates are not expanded; resolve\n * them first (without values) if the display should show their bodies.\n */\nexport function evaluatePromptTokens(\n text: string,\n values?: PromptValues,\n): EvaluatedToken[] {\n const tokens = tokenizePromptWithDiagnostics(text).tokens;\n if (!values) return tokens;\n\n const pairs = pairSections(tokens);\n const result: EvaluatedToken[] = [];\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n if (token.type === \"conditional\") {\n if (\n token.conditional !== \"end\" &&\n !evaluateCondition(\n token.conditional!,\n token.value,\n values,\n token.comparison,\n )\n ) {\n i = pairs.get(i)!;\n }\n continue;\n }\n if (token.type === \"variable\") {\n const supplied = getSuppliedValue(values, token.value);\n const value = supplied ?? token.defaultValue;\n if (value !== undefined) {\n result.push({\n ...token,\n resolvedValue: value,\n valueSource: supplied !== undefined ? \"value\" : \"default\",\n });\n continue;\n }\n }\n result.push(token);\n }\n return result;\n}\n"]}
|