jsfe 1.7.8 → 1.7.10
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 +2 -3
- package/dist/forms/authoring.d.ts +10 -0
- package/dist/forms/authoring.d.ts.map +1 -0
- package/dist/forms/authoring.js +110 -0
- package/dist/forms/choice-flow.d.ts +0 -4
- package/dist/forms/choice-flow.d.ts.map +1 -1
- package/dist/forms/choice-flow.js +10 -14
- package/dist/forms/continuation-safety.d.ts.map +1 -1
- package/dist/forms/continuation-safety.js +2 -1
- package/dist/forms/contracts.d.ts +8 -4
- package/dist/forms/contracts.d.ts.map +1 -1
- package/dist/forms/contracts.js +46 -23
- package/dist/forms/declaration-capture.d.ts +7 -0
- package/dist/forms/declaration-capture.d.ts.map +1 -0
- package/dist/forms/declaration-capture.js +15 -0
- package/dist/forms/declarations.d.ts +20 -0
- package/dist/forms/declarations.d.ts.map +1 -0
- package/dist/forms/declarations.js +272 -0
- package/dist/forms/flows.d.ts.map +1 -1
- package/dist/forms/flows.js +47 -50
- package/dist/forms/identity-flows.js +8 -8
- package/dist/forms/index.d.ts +4 -0
- package/dist/forms/index.js +5 -1
- package/dist/forms/inspection.d.ts +12 -0
- package/dist/forms/inspection.d.ts.map +1 -0
- package/dist/forms/inspection.js +120 -0
- package/dist/forms/prompt-compiler.d.ts.map +1 -1
- package/dist/forms/prompt-compiler.js +5 -1
- package/dist/helpers/answer.d.ts +1 -1
- package/dist/helpers/answer.js +2 -2
- package/dist/helpers/contextual-response.d.ts +3 -0
- package/dist/helpers/contextual-response.d.ts.map +1 -1
- package/dist/helpers/contextual-response.js +7 -0
- package/dist/helpers/form-sources.js +1 -1
- package/dist/helpers/form-state.d.ts +1 -1
- package/dist/helpers/form-state.d.ts.map +1 -1
- package/dist/helpers/form-state.js +7 -5
- package/dist/helpers/index.d.ts +6 -5
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/match-inputs.d.ts.map +1 -1
- package/dist/helpers/match-inputs.js +12 -40
- package/dist/helpers/money.d.ts +5 -3
- package/dist/helpers/money.d.ts.map +1 -1
- package/dist/helpers/money.js +25 -10
- package/dist/helpers/named-functions.d.ts +5 -0
- package/dist/helpers/named-functions.d.ts.map +1 -0
- package/dist/helpers/named-functions.js +54 -0
- package/dist/helpers/proposal-contract.js +4 -4
- package/dist/host/capabilities.d.ts.map +1 -1
- package/dist/host/capabilities.js +11 -3
- package/dist/host/registry-composition.d.ts.map +1 -1
- package/dist/host/registry-composition.js +9 -3
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +80 -51
- package/dist/runtime-identity.js +1 -1
- package/docs/copilot-reference.md +336 -66
- package/docs/development-release.md +16 -1
- package/package.json +1 -2
- package/dist/helpers/semantic-input-prompt.d.ts +0 -2
- package/dist/helpers/semantic-input-prompt.d.ts.map +0 -1
- package/dist/helpers/semantic-input-prompt.js +0 -153
- package/dist/helpers/semantic-input.d.ts +0 -28
- package/dist/helpers/semantic-input.d.ts.map +0 -1
- package/dist/helpers/semantic-input.js +0 -47
- package/docs/forms.md +0 -271
package/README.md
CHANGED
|
@@ -12,8 +12,7 @@ npm i jsfe
|
|
|
12
12
|
- **[JavaScript Flow Engine User Guide](user-guide.md)**
|
|
13
13
|
- Comprehensive tutorials, examples, and best practices
|
|
14
14
|
- **[README.md](README.md)** - Technical API reference (this document)
|
|
15
|
-
- **[Flow author reference](docs/copilot-reference.md)** - the engine
|
|
16
|
-
- **[Native forms, providers and performers](docs/forms.md)** - owned reentrant collection, fact catalogs, confirmed effects and durable recovery
|
|
15
|
+
- **[Flow author reference](docs/copilot-reference.md)** - the authoritative engine and JSON authoring specification for flow authors and AI flow generators (shipped in the package; the Flow Designer's CoPilot reads it from the published version, so change it with the engine)
|
|
17
16
|
- **[Development candidate acceptance](docs/development-release.md)** - reproducible package and cross-repository verification
|
|
18
17
|
- **[System Flows](docs/system-flows.md)** and **[Shopify Flows](docs/shopify-flows.md)** - the bundled flow and tool libraries in `flows/`, step by step
|
|
19
18
|
|
|
@@ -772,7 +771,7 @@ return aiResponse;
|
|
|
772
771
|
Native FORM collection in 1.7.2 acknowledges an unreadable answer once, then yields the current
|
|
773
772
|
utterance while retaining its draft. Explicit recovery metadata distinguishes resumption, required
|
|
774
773
|
restart, unknown-action hold and no promised recovery; business completion remains independent.
|
|
775
|
-
See the [retry/yield/recovery contract](docs/
|
|
774
|
+
See the [retry/yield/recovery contract](docs/copilot-reference.md#retry-yield-and-recovery).
|
|
776
775
|
|
|
777
776
|
### Host Responsibilities: Tool Calls, Cancellation and Concurrency
|
|
778
777
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Compile an authored synchronous calculation inside an existing SET/CASE expression.
|
|
2
|
+
* Arguments are developer-authored JavaScript source, never caller text or runtime values.
|
|
3
|
+
* This advanced helper does not change Worker.calculate's path-only argument validation.
|
|
4
|
+
*/
|
|
5
|
+
export function compileExpression(fn: any, ...args: any[]): any;
|
|
6
|
+
export function Worker(spec: any): any;
|
|
7
|
+
export function Provider(spec: any): any;
|
|
8
|
+
export function Form(spec: any): any;
|
|
9
|
+
export function Performer(spec: any): any;
|
|
10
|
+
//# sourceMappingURL=authoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","sourceRoot":"","sources":["../../src/forms/authoring.js"],"names":[],"mappings":"AAiDA;;;GAGG;AACH,gEAGC;AASD,uCAUC;AACD,yCAAiG;AACjG,qCAAiG;AACjG,0CASC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Concise author declarations compiled to the existing builders. No additional runtime protocol. */
|
|
2
|
+
import { defineForm, defineProvider, definePerformer, defineWorker } from './contracts.js';
|
|
3
|
+
import { FIELD_PRESETS } from './flows.js';
|
|
4
|
+
import { captureAuthorSpec, rememberExpression } from './declaration-capture.js';
|
|
5
|
+
const own = (o, k) => Object.prototype.hasOwnProperty.call(o || {}, k);
|
|
6
|
+
const namePattern = /^[A-Za-z_$][\w$]*$/;
|
|
7
|
+
const forbidden = new Set(['__proto__', 'prototype', 'constructor']);
|
|
8
|
+
const safeName = name => namePattern.test(name) && !forbidden.has(name);
|
|
9
|
+
const fail = message => { throw new Error('Flow authoring: ' + message); };
|
|
10
|
+
const descriptor = value => value && typeof value === 'object' && !Array.isArray(value) && typeof value.type === 'string' && ['string', 'boolean', 'number', 'integer', 'object', 'array'].includes(value.type);
|
|
11
|
+
const variable = value => descriptor(value) ? structuredClone(value) : { type: Array.isArray(value) ? 'array' : value === null || typeof value === 'object' ? 'object' : typeof value, value: structuredClone(value) };
|
|
12
|
+
function parametersFor(parameters = []) {
|
|
13
|
+
const list = Array.isArray(parameters) ? parameters : Object.entries(parameters).map(([name, p]) => typeof p === 'string' ? { name, type: 'string', description: p } : { name, ...p });
|
|
14
|
+
const variables = {}, seen = new Set();
|
|
15
|
+
const declarations = list.map(p => {
|
|
16
|
+
if (!p || !safeName(p.name) || seen.has(p.name))
|
|
17
|
+
fail('parameter names must be unique safe identifiers');
|
|
18
|
+
seen.add(p.name);
|
|
19
|
+
const { default: initial, ...declaration } = p;
|
|
20
|
+
const type = p.type || 'string';
|
|
21
|
+
if (!['string', 'boolean', 'number', 'integer', 'object', 'array'].includes(type))
|
|
22
|
+
fail('unsupported parameter type ' + type);
|
|
23
|
+
const defaultValue = own(p, 'default') ? initial : type === 'object' ? null : type === 'array' ? [] : type === 'boolean' ? false : type === 'number' || type === 'integer' ? 0 : '';
|
|
24
|
+
variables[p.name] = { type: type === 'integer' ? 'number' : type, value: structuredClone(defaultValue) };
|
|
25
|
+
return declaration;
|
|
26
|
+
});
|
|
27
|
+
return { parameters: declarations, variables };
|
|
28
|
+
}
|
|
29
|
+
function normalize(spec, { form = false } = {}) {
|
|
30
|
+
if (!spec || typeof spec.id !== 'string' || !spec.id.trim() || spec.id !== spec.id.trim() || forbidden.has(spec.id))
|
|
31
|
+
fail('a stable flow id is required');
|
|
32
|
+
const normalized = parametersFor(spec.parameters);
|
|
33
|
+
// A field's existing description is also its public extraction declaration. Aliases stay explicit parameters.
|
|
34
|
+
if (form && spec.primary)
|
|
35
|
+
for (const field of (spec.inputs || []).flatMap(input => input.any_of || [input])) {
|
|
36
|
+
if (!field.description || normalized.parameters.some(p => p.name === field.name))
|
|
37
|
+
continue;
|
|
38
|
+
const profile = field.profile || FIELD_PRESETS[field.field]?.profile;
|
|
39
|
+
if (!profile)
|
|
40
|
+
continue;
|
|
41
|
+
const parameter = { name: field.name, type: 'string', description: field.description, ...(profile.kind === 'choice' && !profile.accept_other ? { enum: [...new Set((profile.choices || []).map(choice => choice.key))] } : {}) };
|
|
42
|
+
const extra = parametersFor([parameter]);
|
|
43
|
+
normalized.parameters.push(parameter);
|
|
44
|
+
Object.assign(normalized.variables, extra.variables);
|
|
45
|
+
}
|
|
46
|
+
const rawVariables = form ? spec.extraVars : spec.variables;
|
|
47
|
+
const variables = { ...normalized.variables, ...Object.fromEntries(Object.entries(rawVariables || {}).map(([name, v]) => [name, variable(v)])) };
|
|
48
|
+
const contract = { summary: spec.description || spec.name || spec.id, ...spec.contract };
|
|
49
|
+
return { ...spec, name: spec.name || spec.id.split(/[-:]/).map(part => part.charAt(0).toUpperCase() + part.slice(1)).join(''), parameters: normalized.parameters, contract, ...(form ? { extraVars: Object.fromEntries(Object.entries(variables).map(([name, v]) => [name, v.value])) } : { variables }) };
|
|
50
|
+
}
|
|
51
|
+
/** Serialize only declared synchronous functions; dependencies must be explicit rather than captured closures. */
|
|
52
|
+
function functionSource(fn) {
|
|
53
|
+
if (typeof fn !== 'function' || fn.constructor.name !== 'Function')
|
|
54
|
+
fail('calculations and projections require synchronous functions');
|
|
55
|
+
const source = Function.prototype.toString.call(fn);
|
|
56
|
+
if (source.includes('[native code]'))
|
|
57
|
+
fail('native functions cannot be compiled');
|
|
58
|
+
return source;
|
|
59
|
+
}
|
|
60
|
+
/** Compile an authored synchronous calculation inside an existing SET/CASE expression.
|
|
61
|
+
* Arguments are developer-authored JavaScript source, never caller text or runtime values.
|
|
62
|
+
* This advanced helper does not change Worker.calculate's path-only argument validation.
|
|
63
|
+
*/
|
|
64
|
+
export function compileExpression(fn, ...args) {
|
|
65
|
+
if (args.some(arg => typeof arg !== 'string' || !arg.trim()))
|
|
66
|
+
fail('expression arguments must be nonempty authored JavaScript expressions');
|
|
67
|
+
return rememberExpression(`(${functionSource(fn)})(${args.join(',')})`, fn, args);
|
|
68
|
+
}
|
|
69
|
+
function expression(fn, args = [], helpers = {}) {
|
|
70
|
+
if (!Array.isArray(args) || args.some(arg => typeof arg !== 'string' || !/^[$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)*$/.test(arg)))
|
|
71
|
+
fail('function arguments must be explicit variable paths');
|
|
72
|
+
const bindings = Object.entries(helpers).map(([name, helper]) => { if (!safeName(name) || ['cargo', 'form', 'formSnapshot', 'request', 'result', 'key'].includes(name))
|
|
73
|
+
fail('invalid helper binding ' + name); return `const ${name}=(${functionSource(helper)});`; }).join('\n');
|
|
74
|
+
return `(function(){${bindings}return (${functionSource(fn)})(${args.join(',')});})()`;
|
|
75
|
+
}
|
|
76
|
+
const authored = (flow, component, spec) => captureAuthorSpec({ ...flow, metadata: { ...flow.metadata, authoring: { component } } }, component, spec);
|
|
77
|
+
export function Worker(spec) {
|
|
78
|
+
const { call, calculate, before = [], ...rest } = normalize(spec);
|
|
79
|
+
if ([call !== undefined, calculate !== undefined, spec.steps !== undefined].filter(Boolean).length > 1)
|
|
80
|
+
fail('Worker declares one of steps, call or calculate');
|
|
81
|
+
if (call) {
|
|
82
|
+
if (typeof call.flow !== 'string' || !call.flow)
|
|
83
|
+
fail('Worker.call needs a flow');
|
|
84
|
+
rest.steps = [...before, { id: spec.id + '_call', type: 'FLOW', value: call.flow, callType: 'call', ...(call.parameters ? { parameters: call.parameters } : {}) }];
|
|
85
|
+
}
|
|
86
|
+
else if (calculate) {
|
|
87
|
+
if (typeof calculate.result !== 'string' || !/^cargo(?:\.[A-Za-z_$][\w$]*)+$/.test(calculate.result) || calculate.result.split('.').some(part => forbidden.has(part)))
|
|
88
|
+
fail('Worker.calculate.result must be a safe cargo path');
|
|
89
|
+
rest.steps = [...before, { id: spec.id + '_calculate', type: 'SET', variable: 'noop', value: `(${calculate.result}=${expression(calculate.value, calculate.args, calculate.helpers)},true)`, requireTrue: true }];
|
|
90
|
+
rest.contract = { result: { path: calculate.result, type: 'object' }, ...rest.contract };
|
|
91
|
+
}
|
|
92
|
+
else if (before.length)
|
|
93
|
+
rest.steps = [...before, ...(rest.steps || [])];
|
|
94
|
+
return authored(defineWorker({ ...rest, contract: { role: 'worker', ...rest.contract } }), 'Worker', spec);
|
|
95
|
+
}
|
|
96
|
+
export function Provider(spec) { return authored(defineProvider(normalize(spec)), 'Provider', spec); }
|
|
97
|
+
export function Form(spec) { return authored(defineForm(normalize(spec, { form: true })), 'Form', spec); }
|
|
98
|
+
export function Performer(spec) {
|
|
99
|
+
const normalized = normalize(spec, { form: true });
|
|
100
|
+
if (spec.provides) {
|
|
101
|
+
normalized.extraVars.provides = spec.provides;
|
|
102
|
+
}
|
|
103
|
+
if (spec.project && !Array.isArray(spec.project)) {
|
|
104
|
+
const project = spec.project;
|
|
105
|
+
const helpers = Object.entries(project.helpers || {}).map(([name, fn]) => { if (!safeName(name) || ['cargo', 'form', 'formSnapshot', 'request', 'result', 'key'].includes(name))
|
|
106
|
+
fail('invalid projection helper'); return `const ${name}=(${functionSource(fn)});`; }).join('\n');
|
|
107
|
+
normalized.project = [{ id: spec.id + '_project', type: 'SET', variable: 'noop', value: `(function(){${helpers}if((${functionSource(project.apply)})(cargo,{form:form,formSnapshot:formSnapshot,request:request,result:result,key:key})!==true)throw new Error('Performer projection must return true');return true;})()` }];
|
|
108
|
+
}
|
|
109
|
+
return authored(definePerformer(normalized), 'Performer', spec);
|
|
110
|
+
}
|
|
@@ -380,8 +380,6 @@ export const FLOWS: {
|
|
|
380
380
|
"condition: ac_key === '__elsewhere'": {
|
|
381
381
|
id: string;
|
|
382
382
|
type: string;
|
|
383
|
-
outcome: string;
|
|
384
|
-
reason: string;
|
|
385
383
|
};
|
|
386
384
|
"condition: ac_key === '' && ac_other": {
|
|
387
385
|
id: string;
|
|
@@ -392,8 +390,6 @@ export const FLOWS: {
|
|
|
392
390
|
"condition: ac_key === ''": {
|
|
393
391
|
id: string;
|
|
394
392
|
type: string;
|
|
395
|
-
outcome: string;
|
|
396
|
-
reason: string;
|
|
397
393
|
};
|
|
398
394
|
default: {
|
|
399
395
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choice-flow.d.ts","sourceRoot":"","sources":["../../src/forms/choice-flow.js"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F
|
|
1
|
+
{"version":3,"file":"choice-flow.d.ts","sourceRoot":"","sources":["../../src/forms/choice-flow.js"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6rBE"}
|
|
@@ -4,7 +4,7 @@ export const FLOWS = [
|
|
|
4
4
|
"id": "ask-choice",
|
|
5
5
|
"name": "AskChoice",
|
|
6
6
|
"version": "1.19.0",
|
|
7
|
-
"description": "Worker: ask one question
|
|
7
|
+
"description": "Worker: ask one question and return cargo.choice plus the original cargo.choiceText. Declared choices, precheck keys and typed answer-validator keys keep priority across both read passes. Exact negative choices accept only their own declared words and keys. With amount, an unowned legacy payment question accepts a complete USD monetary answer or a simple payment instruction through readMoneyAmount; uncertain prose yields to DISPATCH without declaring an action failure. A lone digit keeps the question's keypad policy; amount:'marked' still requires marked money. An owning FORM supplies form_context and performs its own field, correction, provider-question and confirmation matching before deciding to retry or yield, retaining its draft and safety guards. Optional answer_precheck runs before choices; answer_validator runs only when no choice matched. AGENT/0 requests a person; EXIT/* leaves the request; a consumed switch offer routes its declared flow. Params include question(_es), choices [{key,phrases,exact?,negative?,neutral?}], retry(_es), accept_other, expect, amount, digits, exit_context(_es), pii and form_context.",
|
|
8
8
|
"parameters": [
|
|
9
9
|
{ "name": "form_context", "type": "object", "description": "Optional declared FORM reader context {form,current,names,questions}; valid field readings take precedence over stale verification-code echoes." },
|
|
10
10
|
{
|
|
@@ -22,7 +22,7 @@ export const FLOWS = [
|
|
|
22
22
|
{
|
|
23
23
|
"name": "choices",
|
|
24
24
|
"type": "array",
|
|
25
|
-
"description": "[{key,
|
|
25
|
+
"description": "[{key, phrases}] in priority order",
|
|
26
26
|
"required": true
|
|
27
27
|
},
|
|
28
28
|
{
|
|
@@ -401,13 +401,13 @@ export const FLOWS = [
|
|
|
401
401
|
"id": "ac_match_offer",
|
|
402
402
|
"type": "SET",
|
|
403
403
|
"variable": "ac_key",
|
|
404
|
-
"value": "ac_offer && Array.isArray(ac_offer.words) && matchesChoice(ac_answer, ac_offer.words) ? '__switch' : ac_key"
|
|
404
|
+
"value": "ac_offer && Array.isArray(ac_offer.phrases ?? ac_offer.words) && matchesChoice(ac_answer, ac_offer.phrases ?? ac_offer.words) ? '__switch' : ac_key"
|
|
405
405
|
},
|
|
406
406
|
{
|
|
407
407
|
"id": "ac_exact_no_own_words",
|
|
408
408
|
"type": "SET",
|
|
409
409
|
"variable": "ac_key",
|
|
410
|
-
"value": "(function() { var cs = Array.isArray(choices) ? choices : []; var isExactNo = function(c) { return !!c && c.exact === true && (['no', 'decline', 'done', 'cancel'].indexOf(c.key) > -1 || c.negative === true); }; var c = cs.filter(function(x) { return !!x && x.key === ac_key; })[0]; if (!isExactNo(c)) { return ac_key; } else if (pickChoice(ac_answer, [{ key: 'ac_own',
|
|
410
|
+
"value": "(function() { var cs = Array.isArray(choices) ? choices : []; var isExactNo = function(c) { return !!c && c.exact === true && (['no', 'decline', 'done', 'cancel'].indexOf(c.key) > -1 || c.negative === true); }; var c = cs.filter(function(x) { return !!x && x.key === ac_key; })[0]; if (!isExactNo(c)) { return ac_key; } else if (pickChoice(ac_answer, [{ key: 'ac_own', phrases: c.phrases ?? c.words, exact: true }], false) === 'ac_own') { return ac_key; } else { return pickChoice(ac_answer, cs.filter(function(x) { return !isExactNo(x); }), ac_other); } })()"
|
|
411
411
|
},
|
|
412
412
|
{
|
|
413
413
|
"id": "ac_init_answer_key",
|
|
@@ -446,7 +446,7 @@ export const FLOWS = [
|
|
|
446
446
|
"id": "ac_amount_check",
|
|
447
447
|
"type": "SET",
|
|
448
448
|
"variable": "ac_key",
|
|
449
|
-
"value": "ac_amount && Number.isFinite(
|
|
449
|
+
"value": "ac_key !== '' || !ac_amount || (typeof form_context !== 'undefined' && form_context && form_context.form) ? ac_key : (String(ac_answer||'').trim() && !Number.isFinite(readMoneyAmount(ac_answer,{currency:'USD',cardinals:true,intent:'payment'}))) ? '__elsewhere' : (ac_amount && (isAmountAnswer(ac_answer) || (ac_marked ? (ac_key === '' && /\\d\\s*(?:con|and)\\s*(?:un\\s+)?\\d{2}\\b(?!\\s*\\d)/i.test(String(ac_answer || ''))) : (ac_key === '' && (!/^\\D*\\d\\D*$/.test(String(ac_answer || '')) || /\\b(?:pay|paying|pagar|pagarle|abonar)\\b/i.test(String(ac_answer || ''))) && !/^[\\s,.;]*\\d(?:[\\s,.;]+\\d)+[\\s,.;]*$/.test(String(ac_answer || '')) && !isNaN(readMoneyAmount(ac_answer,{currency:'USD',cardinals:true,intent:'payment'}))))) ? '__amount' : ac_key)"
|
|
450
450
|
},
|
|
451
451
|
{
|
|
452
452
|
"id": "ac_switch_to_text_key",
|
|
@@ -572,13 +572,13 @@ export const FLOWS = [
|
|
|
572
572
|
"id": "ac_match_again_offer",
|
|
573
573
|
"type": "SET",
|
|
574
574
|
"variable": "ac_key",
|
|
575
|
-
"value": "ac_offer && Array.isArray(ac_offer.words) && matchesChoice(ac_answer, ac_offer.words) ? '__switch' : ac_key"
|
|
575
|
+
"value": "ac_offer && Array.isArray(ac_offer.phrases ?? ac_offer.words) && matchesChoice(ac_answer, ac_offer.phrases ?? ac_offer.words) ? '__switch' : ac_key"
|
|
576
576
|
},
|
|
577
577
|
{
|
|
578
578
|
"id": "ac_exact_no_own_words_again",
|
|
579
579
|
"type": "SET",
|
|
580
580
|
"variable": "ac_key",
|
|
581
|
-
"value": "ac_key === '' ? ac_key : (function() { var cs = Array.isArray(choices) ? choices : []; var isExactNo = function(c) { return !!c && c.exact === true && (['no', 'decline', 'done', 'cancel'].indexOf(c.key) > -1 || c.negative === true); }; var c = cs.filter(function(x) { return !!x && x.key === ac_key; })[0]; if (!isExactNo(c)) { return ac_key; } else if (pickChoice(ac_answer, [{ key: 'ac_own',
|
|
581
|
+
"value": "ac_key === '' ? ac_key : (function() { var cs = Array.isArray(choices) ? choices : []; var isExactNo = function(c) { return !!c && c.exact === true && (['no', 'decline', 'done', 'cancel'].indexOf(c.key) > -1 || c.negative === true); }; var c = cs.filter(function(x) { return !!x && x.key === ac_key; })[0]; if (!isExactNo(c)) { return ac_key; } else if (pickChoice(ac_answer, [{ key: 'ac_own', phrases: c.phrases ?? c.words, exact: true }], false) === 'ac_own') { return ac_key; } else { return pickChoice(ac_answer, cs.filter(function(x) { return !isExactNo(x); }), ac_other); } })()"
|
|
582
582
|
},
|
|
583
583
|
{
|
|
584
584
|
"id": "ac_init_answer_key_again",
|
|
@@ -617,7 +617,7 @@ export const FLOWS = [
|
|
|
617
617
|
"id": "ac_amount_check_again",
|
|
618
618
|
"type": "SET",
|
|
619
619
|
"variable": "ac_key",
|
|
620
|
-
"value": "ac_amount && Number.isFinite(
|
|
620
|
+
"value": "ac_key !== '' || !ac_amount || (typeof form_context !== 'undefined' && form_context && form_context.form) ? ac_key : (String(ac_answer||'').trim() && !Number.isFinite(readMoneyAmount(ac_answer,{currency:'USD',cardinals:true,intent:'payment'}))) ? '__elsewhere' : (ac_amount && (isAmountAnswer(ac_answer) || (ac_marked ? (ac_key === '' && /\\d\\s*(?:con|and)\\s*(?:un\\s+)?\\d{2}\\b(?!\\s*\\d)/i.test(String(ac_answer || ''))) : (ac_key === '' && (!/^\\D*\\d\\D*$/.test(String(ac_answer || '')) || /\\b(?:pay|paying|pagar|pagarle|abonar)\\b/i.test(String(ac_answer || ''))) && !/^[\\s,.;]*\\d(?:[\\s,.;]+\\d)+[\\s,.;]*$/.test(String(ac_answer || '')) && !isNaN(readMoneyAmount(ac_answer,{currency:'USD',cardinals:true,intent:'payment'}))))) ? '__amount' : ac_key)"
|
|
621
621
|
},
|
|
622
622
|
{
|
|
623
623
|
"id": "ac_other_request_check",
|
|
@@ -677,9 +677,7 @@ export const FLOWS = [
|
|
|
677
677
|
},
|
|
678
678
|
"condition: ac_key === '__elsewhere'": {
|
|
679
679
|
"id": "ac_elsewhere",
|
|
680
|
-
"type": "DISPATCH"
|
|
681
|
-
"outcome": "{{ac_exit_ctx === 'payment' ? 'unresolved' : ''}}",
|
|
682
|
-
"reason": "{{ac_exit_ctx === 'payment' ? 'payment_incomplete' : ''}}"
|
|
680
|
+
"type": "DISPATCH"
|
|
683
681
|
},
|
|
684
682
|
"condition: ac_key === '' && ac_other": {
|
|
685
683
|
"id": "ac_return_other",
|
|
@@ -689,9 +687,7 @@ export const FLOWS = [
|
|
|
689
687
|
},
|
|
690
688
|
"condition: ac_key === ''": {
|
|
691
689
|
"id": "ac_other_request",
|
|
692
|
-
"type": "DISPATCH"
|
|
693
|
-
"outcome": "{{ac_exit_ctx === 'payment' ? 'unresolved' : ''}}",
|
|
694
|
-
"reason": "{{ac_exit_ctx === 'payment' ? 'payment_incomplete' : ''}}"
|
|
690
|
+
"type": "DISPATCH"
|
|
695
691
|
},
|
|
696
692
|
"default": {
|
|
697
693
|
"id": "ac_return_choice",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"continuation-safety.d.ts","sourceRoot":"","sources":["../../src/forms/continuation-safety.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"continuation-safety.d.ts","sourceRoot":"","sources":["../../src/forms/continuation-safety.js"],"names":[],"mappings":"AAIA,kEAQC;AAVM,qDAAsC;AAC7C,8CAA6C,6BAA6B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inheritFlowDeclaration } from './declaration-capture.js';
|
|
1
2
|
/** Opt in deliberately when a safety fix makes old serialized steps unsafe to resume. */
|
|
2
3
|
export const continuationSafetyProtocol = () => 1;
|
|
3
4
|
export const CONTINUATION_SAFETY_REQUIREMENT = 'jsfe:continuation-safety:v1';
|
|
@@ -10,5 +11,5 @@ export function withSafetyRevision(flow, revision) {
|
|
|
10
11
|
// A safety upgrade does not invent a partial declarative FORM contract for legacy workers.
|
|
11
12
|
if (original)
|
|
12
13
|
variables.contract = { ...original, value: { ...original.value, requires: [...new Set([...(original.value?.requires || []), CONTINUATION_SAFETY_REQUIREMENT])] } };
|
|
13
|
-
return { ...flow, safetyRevision: revision, steps: [guard, ...steps], variables };
|
|
14
|
+
return inheritFlowDeclaration(flow, { ...flow, safetyRevision: revision, steps: [guard, ...steps], variables });
|
|
14
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function providerQuestions(provides: any): {
|
|
2
2
|
key: any;
|
|
3
|
-
|
|
3
|
+
phrases: any;
|
|
4
4
|
}[];
|
|
5
5
|
export function providerParameter(provides: any): {
|
|
6
6
|
name: string;
|
|
@@ -16,25 +16,29 @@ export function defineWorker({ contract, ...flow }: {
|
|
|
16
16
|
[x: string]: any;
|
|
17
17
|
contract: any;
|
|
18
18
|
}): any;
|
|
19
|
-
export function defineProvider({ provides, contract, parameters, variables, steps, ...flow }: {
|
|
19
|
+
export function defineProvider({ provides, contract, parameters, variables, steps, before, gateParameters, ...flow }: {
|
|
20
20
|
[x: string]: any;
|
|
21
21
|
provides: any;
|
|
22
22
|
contract: any;
|
|
23
23
|
parameters?: never[] | undefined;
|
|
24
24
|
variables?: {} | undefined;
|
|
25
25
|
steps: any;
|
|
26
|
+
before?: never[] | undefined;
|
|
27
|
+
gateParameters: any;
|
|
26
28
|
}): any;
|
|
27
|
-
export function defineForm({ contract, ...spec }: {
|
|
29
|
+
export function defineForm({ contract, provides, ...spec }: {
|
|
28
30
|
[x: string]: any;
|
|
29
31
|
contract: any;
|
|
32
|
+
provides: any;
|
|
30
33
|
}): any;
|
|
31
|
-
export function definePerformer({ performs, contract, prepare, present, project, ...spec }: {
|
|
34
|
+
export function definePerformer({ performs, contract, prepare, present, project, provides, ...spec }: {
|
|
32
35
|
[x: string]: any;
|
|
33
36
|
performs: any;
|
|
34
37
|
contract: any;
|
|
35
38
|
prepare: any;
|
|
36
39
|
present: any;
|
|
37
40
|
project?: never[] | undefined;
|
|
41
|
+
provides: any;
|
|
38
42
|
}): any;
|
|
39
43
|
/** A registered tool gets one generated adapter with explicit args; no dynamic tool-name interpreter is needed. */
|
|
40
44
|
export function operationWorkers(tools: any): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/forms/contracts.js"],"names":[],"mappings":"AAgBA;;;IAGC;AACD;;;;;EAGC;AACD,qGAAqG;AACrG;;QAqCC;
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/forms/contracts.js"],"names":[],"mappings":"AAgBA;;;IAGC;AACD;;;;;EAGC;AACD,qGAAqG;AACrG;;QAqCC;AAqBD;;;QAEC;AAgBD;;;;;;;;;QASC;AACD;;;;QAGC;AACD;;;;;;;;QA8BC;AAED,mHAAmH;AACnH,kDAgBC;AAED,+GAA+G;AAC/G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyEC"}
|
package/dist/forms/contracts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CONTEXTUAL_RESPONSES_REQUIREMENT, validateContextualResponseStep, contextualResponseRuntimeSteps } from '../helpers/contextual-response.js';
|
|
1
|
+
import { inheritFlowDeclaration } from './declaration-capture.js';
|
|
2
|
+
import { CONTEXTUAL_RESPONSES_REQUIREMENT, hasFormResponse, validateContextualResponseStep, contextualResponseRuntimeSteps } from '../helpers/contextual-response.js';
|
|
3
3
|
/** Build-time contracts for conversational flows. Transport operations remain registered tools. */
|
|
4
4
|
import { INPUT_PROPOSALS_REQUIREMENT, hasInputProposals, proposalRuntimeSteps } from './proposal-runtime.js';
|
|
5
5
|
import { ACTION_TOOLS } from './action-tools.js';
|
|
@@ -13,12 +13,12 @@ const value = v => ({ type: Array.isArray(v) ? 'array' : v !== null && typeof v
|
|
|
13
13
|
const fail = (id, message) => { throw new Error(`Flow contract ${id}: ${message}`); };
|
|
14
14
|
const stepList = steps => (steps || []).flatMap(step => [step, ...stepList(Object.values(step.branches || {})), ...(step.onFail ? stepList([step.onFail]) : [])]);
|
|
15
15
|
export function providerQuestions(provides) {
|
|
16
|
-
return [...(provides.facts || []), ...(provides.sets || [])].filter(f => (f.words
|
|
17
|
-
.map(f => ({ key: f.key,
|
|
16
|
+
return [...(provides.facts || []), ...(provides.sets || [])].filter(f => (f.phrases ?? f.words ?? f.asks ?? []).length)
|
|
17
|
+
.map(f => ({ key: f.key, phrases: f.phrases ?? f.words ?? f.asks }));
|
|
18
18
|
}
|
|
19
19
|
export function providerParameter(provides) {
|
|
20
|
-
const entries = [...(provides.facts || []).filter(f => f.gloss || f.asks?.length), ...(provides.sets || [])];
|
|
21
|
-
return { name: 'asked', type: 'string', enum: entries.map(f => f.key), description: entries.map(f => `${f.key}: ${f.gloss || (f.asks || []).join('; ') || f.label || f.key}`).join('. ') };
|
|
20
|
+
const entries = [...(provides.facts || []).filter(f => f.description || f.gloss || f.asks?.length), ...(provides.sets || [])];
|
|
21
|
+
return { name: 'asked', type: 'string', enum: entries.map(f => f.key), description: entries.map(f => `${f.key}: ${f.description || f.gloss || (f.asks || []).join('; ') || f.label || f.key}`).join('. ') };
|
|
22
22
|
}
|
|
23
23
|
/** Link declarative sub-forms before runtime so any descendant field can receive an early answer. */
|
|
24
24
|
export function linkFormSchemas(flows, { externalFlows = [] } = {}) {
|
|
@@ -50,8 +50,8 @@ export function linkFormSchemas(flows, { externalFlows = [] } = {}) {
|
|
|
50
50
|
if (input.schema)
|
|
51
51
|
return objectSchema(input.schema.inputs);
|
|
52
52
|
if (input.profile?.kind === 'choice' && !input.profile.accept_other)
|
|
53
|
-
return { type: 'string', enum: (input.profile.choices || []).map(c => c.key), description: input.description || input.label || input.name };
|
|
54
|
-
return { type: 'string', description: input.description || input.label || input.name };
|
|
53
|
+
return { type: 'string', enum: (input.profile.choices || []).map(c => c.key), description: input.response?.description || input.description || input.label || input.name };
|
|
54
|
+
return { type: 'string', description: input.response?.description || input.description || input.label || input.name };
|
|
55
55
|
};
|
|
56
56
|
const objectSchema = inputs => {
|
|
57
57
|
const fields = inputs.flatMap(input => input.any_of || [input]).filter(input => input.schema || input.profile);
|
|
@@ -66,12 +66,12 @@ export function linkFormSchemas(flows, { externalFlows = [] } = {}) {
|
|
|
66
66
|
for (const input of inputs.flatMap(input => input.any_of || [input])) {
|
|
67
67
|
if (parameters.some(p => p.name === input.name) || !input.profile && !input.schema)
|
|
68
68
|
continue;
|
|
69
|
-
parameters.push(input.schema ? { name: input.name, type: 'object', jsonSchema: objectSchema(input.schema.inputs), description: input.description || input.label || input.name }
|
|
70
|
-
: { name: input.name, type: 'string', ...(input.profile.kind === 'choice' && !input.profile.accept_other ? { enum: input.profile.choices.map(c => c.key) } : {}), description: input.description || input.label || input.name });
|
|
69
|
+
parameters.push(input.schema ? { name: input.name, type: 'object', jsonSchema: objectSchema(input.schema.inputs), description: input.response?.description || input.description || input.label || input.name }
|
|
70
|
+
: { name: input.name, type: 'string', ...(input.profile.kind === 'choice' && !input.profile.accept_other ? { enum: input.profile.choices.map(c => c.key) } : {}), description: input.response?.description || input.description || input.label || input.name });
|
|
71
71
|
}
|
|
72
72
|
const linked = { ...flow, parameters, variables: { ...flow.variables, inputs: { ...flow.variables.inputs, value: inputs } } };
|
|
73
73
|
// Descendant schemas are linked after declaration; propagate their runtime requirement to the root entry.
|
|
74
|
-
return flow.variables?.contract ? declared(linked, flow.variables.contract.value) : { ...linked, steps: proposalRuntimeSteps(flow.id, linked.steps, hasInputProposals(inputs) ? [INPUT_PROPOSALS_REQUIREMENT] : []) };
|
|
74
|
+
return inheritFlowDeclaration(flow, flow.variables?.contract ? declared(linked, flow.variables.contract.value) : { ...linked, steps: proposalRuntimeSteps(flow.id, linked.steps, hasInputProposals(inputs) ? [INPUT_PROPOSALS_REQUIREMENT] : []) });
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
function declared(flow, contract) {
|
|
@@ -85,8 +85,7 @@ function declared(flow, contract) {
|
|
|
85
85
|
...(step.branches ? { branches: Object.fromEntries(Object.entries(step.branches).map(([key, branch]) => [key, replacementDefaults(branch)])) } : {}),
|
|
86
86
|
...(step.onFail ? { onFail: replacementDefaults(step.onFail) } : {}) });
|
|
87
87
|
const contextual = stepList(flow.steps).filter(step => step.type === 'DISPATCH').map(step => validateContextualResponseStep(step, flow)).some(Boolean);
|
|
88
|
-
const
|
|
89
|
-
const requirements = [...normalizeHostRequirements(contract.requires, flow.id), ...(semantic ? [SEMANTIC_INPUT_REQUIREMENT] : []), ...(hasInputProposals(flow.variables?.inputs?.value) ? [INPUT_PROPOSALS_REQUIREMENT] : []), ...(contextual ? [CONTEXTUAL_RESPONSES_REQUIREMENT] : [])];
|
|
88
|
+
const requirements = [...normalizeHostRequirements(contract.requires, flow.id), ...(hasInputProposals(flow.variables?.inputs?.value) ? [INPUT_PROPOSALS_REQUIREMENT] : []), ...(contextual || hasFormResponse(flow.variables?.inputs?.value) ? [CONTEXTUAL_RESPONSES_REQUIREMENT] : [])];
|
|
90
89
|
const metadata = { version: 1, ...contract, parametersFrom: 'parameters' };
|
|
91
90
|
if (requirements.length || contract.requires !== undefined)
|
|
92
91
|
Object.defineProperty(metadata, 'requires', {
|
|
@@ -94,26 +93,50 @@ function declared(flow, contract) {
|
|
|
94
93
|
});
|
|
95
94
|
const guardedSteps = flow.steps.map(replacementDefaults);
|
|
96
95
|
// Linking a form may declare it again. Rebuild an existing protocol-only prefix once.
|
|
97
|
-
const rebuiltGuards = [...(requirements.includes(
|
|
98
|
-
if (requirements.includes(CONTEXTUAL_RESPONSES_REQUIREMENT)
|
|
96
|
+
const rebuiltGuards = [...(requirements.includes(CONTEXTUAL_RESPONSES_REQUIREMENT) ? ['contextualResponseProtocol() === 1'] : []), ...(requirements.includes(INPUT_PROPOSALS_REQUIREMENT) ? ['formProposalProtocol() === 1'] : [])];
|
|
97
|
+
if (requirements.includes(CONTEXTUAL_RESPONSES_REQUIREMENT))
|
|
99
98
|
while (guardedSteps[0]?.type === 'SET' && guardedSteps[0]?.requireTrue === true && rebuiltGuards.includes(guardedSteps[0]?.value))
|
|
100
99
|
guardedSteps.shift();
|
|
101
|
-
return { ...flow, steps:
|
|
100
|
+
return { ...flow, steps: contextualResponseRuntimeSteps(flow.id, proposalRuntimeSteps(flow.id, guardedSteps, requirements), requirements), variables: { ...flow.variables, contract: value(metadata) } };
|
|
102
101
|
}
|
|
103
102
|
export function defineWorker({ contract, ...flow }) {
|
|
104
103
|
return declared({ scope: 'isolated', version: '1.0.0', ...flow }, contract);
|
|
105
104
|
}
|
|
106
|
-
|
|
105
|
+
// Lower declarative gate arguments to a SET expression; FLOW arguments remain paths only.
|
|
106
|
+
function gateArgumentExpression(value) {
|
|
107
|
+
if (typeof value === 'string') {
|
|
108
|
+
const expression = /^\{\{([\s\S]+)\}\}$/.exec(value);
|
|
109
|
+
if (expression)
|
|
110
|
+
return '(' + expression[1] + ')';
|
|
111
|
+
if (value.includes('{{'))
|
|
112
|
+
throw new Error('Provider gate argument templates must be whole expressions');
|
|
113
|
+
return JSON.stringify(value);
|
|
114
|
+
}
|
|
115
|
+
if (Array.isArray(value))
|
|
116
|
+
return '[' + value.map(gateArgumentExpression).join(',') + ']';
|
|
117
|
+
if (value && typeof value === 'object')
|
|
118
|
+
return '{' + Object.entries(value).map(([key, entry]) => {
|
|
119
|
+
if (['__proto__', 'prototype', 'constructor'].includes(key))
|
|
120
|
+
throw new Error('Provider gate argument uses an unsafe key');
|
|
121
|
+
return JSON.stringify(key) + ':' + gateArgumentExpression(entry);
|
|
122
|
+
}).join(',') + '}';
|
|
123
|
+
return JSON.stringify(value);
|
|
124
|
+
}
|
|
125
|
+
export function defineProvider({ provides, contract, parameters = [], variables = {}, steps, before = [], gateParameters, ...flow }) {
|
|
107
126
|
const asked = providerParameter(provides);
|
|
127
|
+
if (provides.default !== undefined && ![...(provides.facts || []), ...(provides.sets || [])].some(entry => entry.key === provides.default))
|
|
128
|
+
fail(flow.id, 'provider default must name a declared fact or set');
|
|
108
129
|
return declared({ scope: 'isolated', version: '1.0.0', primary: true, ...flow,
|
|
109
|
-
parameters: [...parameters, asked], variables: { ...variables, asked: value(''), provides: value(provides) },
|
|
110
|
-
steps: steps || [{ id: `${flow.id}
|
|
130
|
+
parameters: [...parameters, asked], variables: { ...variables, ...(gateParameters !== undefined ? { provider_gate_arguments: value(null) } : {}), asked: value(''), provides: value(provides) },
|
|
131
|
+
steps: steps || [...before, ...(provides.default !== undefined ? [{ id: `${flow.id}_default`, type: 'SET', variable: 'asked', value: `asked || ${JSON.stringify(provides.default)}` }] : []),
|
|
132
|
+
...(gateParameters !== undefined ? [{ id: `${flow.id}_gate_arguments`, type: 'SET', variable: 'provider_gate_arguments', value: gateArgumentExpression(gateParameters) }] : []),
|
|
133
|
+
{ id: `${flow.id}_provide`, type: 'FLOW', value: 'provide-data', callType: 'call', parameters: { provides: '{{provides}}', asked: '{{asked}}', ...(gateParameters !== undefined ? { gate_params: '{{provider_gate_arguments}}' } : {}) } }] }, { role: 'provider', ...contract, catalog: 'provides' });
|
|
111
134
|
}
|
|
112
|
-
export function defineForm({ contract, ...spec }) {
|
|
113
|
-
const flow = formFlow(spec);
|
|
135
|
+
export function defineForm({ contract, provides, ...spec }) {
|
|
136
|
+
const flow = formFlow({ ...spec, ...(provides ? { extraVars: { ...spec.extraVars, provides, questions: providerQuestions(provides) } } : {}) });
|
|
114
137
|
return declared(flow, { role: 'collector', ...contract, form: { inputs: 'inputs' } });
|
|
115
138
|
}
|
|
116
|
-
export function definePerformer({ performs, contract, prepare, present, project = [], ...spec }) {
|
|
139
|
+
export function definePerformer({ performs, contract, prepare, present, project = [], provides, ...spec }) {
|
|
117
140
|
validateActionProjection(project, spec.id);
|
|
118
141
|
if (!Array.isArray(performs) || !performs.length || !prepare || !present)
|
|
119
142
|
fail(spec.id, 'performer needs actions, request preparation and outcome presentation');
|
|
@@ -132,7 +155,7 @@ export function definePerformer({ performs, contract, prepare, present, project
|
|
|
132
155
|
set('proposal', 'pf_record', "pf_action ? prepareFormAction(cargo, form_instance, pf_action, pf_request) : null"),
|
|
133
156
|
];
|
|
134
157
|
const flow = formFlow({ ...spec, confirm, confirmation_condition: "pf_action !== null && pf_action && typeof pf_action === 'object'",
|
|
135
|
-
extraVars: { ...spec.extraVars, performs, projection: project, pf_action: null, pf_request: null, pf_record: null, pf_result: null, pf_receipt: null },
|
|
158
|
+
extraVars: { ...spec.extraVars, ...(provides ? { provides, questions: providerQuestions(provides) } : {}), performs, projection: project, pf_action: null, pf_request: null, pf_record: null, pf_result: null, pf_receipt: null },
|
|
136
159
|
before_confirm: confirm ? [...prepareSteps, ...(spec.before_confirm || [])] : spec.before_confirm || [],
|
|
137
160
|
after: [...(confirm ? [] : prepareSteps),
|
|
138
161
|
when('perform', 'pf_action && typeof pf_action === \'object\'', call('execute', 'perform-action', { form: '{{form_instance}}', action: '{{pf_action}}', request: '{{pf_request}}', defer_receipt: true })),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function copyAuthorSpec(value: any): any;
|
|
2
|
+
export function captureAuthorSpec(flow: any, component: any, spec: any): any;
|
|
3
|
+
export function capturedAuthorSpec(flow: any): any;
|
|
4
|
+
export function rememberExpression(source: any, fn: any, args: any): any;
|
|
5
|
+
export function authoredExpressions(): Map<any, any>;
|
|
6
|
+
export function inheritFlowDeclaration(source: any, target: any): any;
|
|
7
|
+
//# sourceMappingURL=declaration-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration-capture.d.ts","sourceRoot":"","sources":["../../src/forms/declaration-capture.js"],"names":[],"mappings":"AAEA,gDAIC;AACD,6EAAgJ;AAChJ,mDAAqE;AACrE,yEAAoK;AACpK,qDAA0D;AAE1D,sEAA4I"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Authoring migration support. Captures live functions without putting executable objects in JSON. */
|
|
2
|
+
const originals = new WeakMap(), expressions = new Map();
|
|
3
|
+
export function copyAuthorSpec(value) {
|
|
4
|
+
if (Array.isArray(value))
|
|
5
|
+
return value.map(copyAuthorSpec);
|
|
6
|
+
if (value && typeof value === 'object')
|
|
7
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, copyAuthorSpec(item)]));
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function captureAuthorSpec(flow, component, spec) { const saved = { component, spec: copyAuthorSpec(spec) }; originals.set(flow, saved); return flow; }
|
|
11
|
+
export function capturedAuthorSpec(flow) { return originals.get(flow); }
|
|
12
|
+
export function rememberExpression(source, fn, args) { expressions.set(source, { source: Function.prototype.toString.call(fn), name: fn.name, args: [...args] }); return source; }
|
|
13
|
+
export function authoredExpressions() { return expressions; }
|
|
14
|
+
export function inheritFlowDeclaration(source, target) { const saved = originals.get(source); if (saved)
|
|
15
|
+
originals.set(target, saved); return target; }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Compile only explicitly versioned declarations. Ordinary executable JSON is unchanged.
|
|
2
|
+
* @param {any[]} flows
|
|
3
|
+
* @param {{tools?: any[], externalFlows?: any[], validate?: boolean}} options
|
|
4
|
+
* @returns {any[]}
|
|
5
|
+
*/
|
|
6
|
+
export function compileFlowDeclarations(flows: any[], { tools, externalFlows, validate }?: {
|
|
7
|
+
tools?: any[];
|
|
8
|
+
externalFlows?: any[];
|
|
9
|
+
validate?: boolean;
|
|
10
|
+
}): any[];
|
|
11
|
+
/** Return the original programmatic declaration, even after ordinary spread/clone transformations. */
|
|
12
|
+
export function captureOriginalDeclaration(flow: any): {
|
|
13
|
+
component: any;
|
|
14
|
+
spec: any;
|
|
15
|
+
} | null;
|
|
16
|
+
/** One-time migration of an authored builder to the editable, self-contained JSON format. */
|
|
17
|
+
export function serializeFlowDeclaration(flow: any, { resolvedFlow }?: {
|
|
18
|
+
resolvedFlow?: any;
|
|
19
|
+
}): any;
|
|
20
|
+
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../../src/forms/declarations.js"],"names":[],"mappings":"AAcA;;;;GAIG;AACH,+CAJW,GAAG,EAAE,uCACL;IAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAC,GACxD,GAAG,EAAE,CAwCjB;AAED,sGAAsG;AACtG;;;SAAqK;AAuBrK,6FAA6F;AAC7F;;QAuCC"}
|