jsfe 1.49.0 → 1.51.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 +1 -1
- package/dist/forms/address-flows.js +2 -2
- package/dist/forms/flows.d.ts.map +1 -1
- package/dist/forms/flows.js +11 -21
- package/dist/forms/form-client.d.ts.map +1 -1
- package/dist/forms/form-client.js +29 -6
- package/dist/helpers/address.js +1 -1
- package/dist/helpers/form-proposals.d.ts.map +1 -1
- package/dist/helpers/form-proposals.js +2 -0
- package/dist/helpers/form-state.d.ts +1 -0
- package/dist/helpers/form-state.d.ts.map +1 -1
- package/dist/helpers/form-state.js +14 -5
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +2 -2
- package/dist/helpers/match-inputs.d.ts +1 -0
- package/dist/helpers/match-inputs.d.ts.map +1 -1
- package/dist/helpers/match-inputs.js +17 -0
- package/dist/runtime-identity.js +1 -1
- package/docs/copilot-reference.md +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm i jsfe
|
|
|
14
14
|
- **[README.md](README.md)** - Technical API reference (this document)
|
|
15
15
|
- **[Flows architecture guide](docs/architecture-guide.md)** - start here: the concepts, the building blocks, what the caller experiences, and how conversational AI and exact transactional flows work together (the reply ranker and DISPATCH)
|
|
16
16
|
- **[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
|
-
- **[Form client adapter](docs/form-client.md)** - optional: a host renders the pending FORM question as a form for a capable client and reads its strict named submission through the same FORM workers; an input may name its control (`form_client`: date, date range, number since jsfe 1.44.0; place (city or address suggestions from the host) since 1.46.0
|
|
17
|
+
- **[Form client adapter](docs/form-client.md)** - optional: a host renders the pending FORM question as a form for a capable client and reads its strict named submission through the same FORM workers; an input may name its control (`form_client`: date, date range, number since jsfe 1.44.0; place (city or address suggestions from the host) since 1.46.0)
|
|
18
18
|
- **[Development candidate acceptance](docs/development-release.md)** - reproducible package and cross-repository verification
|
|
19
19
|
- **[System Flows](docs/flows/system/README.md)** and **[Shopify Flows](docs/flows/shopify/README.md)** - the bundled flow and tool libraries in `flows/`: a page and a chart per flow, generated from the JSON (`node scripts/flow-docs.mjs`), plus the conventions the system flows share
|
|
20
20
|
|
|
@@ -17,8 +17,8 @@ const address = defineForm({ id: 'collect-geocoded-address', name: 'CollectGeoco
|
|
|
17
17
|
inputs: [{ name: 'zip', field: 'zip', argument_description: '5-digit ZIP code', names: ['zip', 'zip code', 'postal code', 'código postal', 'codigo postal'], validator: 'address-zip-validate', prepare: 'address-zip-prompt', question_from: 'zip_question', question: 'What is the 5-digit zip code of your new address?', question_es: '¿Cuál es el código postal de 5 dígitos de su nueva dirección?' },
|
|
18
18
|
{ name: 'city', argument_description: 'city name alone', label: 'city', label_es: 'ciudad', names: ['city', 'ciudad'], profile: { kind: 'choice', choices: [], accept_other: true, other_needs_letter: true }, choices_from: 'city_choices', when: { 'form.data.city_known': true }, depends_on: ['zip'], reset_on: ['zip'], prepare: 'address-city-prompt', question_from: 'city_question', question: 'Which city is it?', question_es: '¿Qué ciudad es?' },
|
|
19
19
|
{ name: 'city_state', argument_description: 'city and state', label: 'city and state', label_es: 'ciudad y estado', names: ['city', 'ciudad'], profile: { kind: 'text' }, when: { 'form.data.need_city': true }, depends_on: ['zip'], question_from: 'city_state_question', question: 'What city and state is that in?', question_es: '¿En qué ciudad y estado está?' },
|
|
20
|
-
{ name: 'street', argument_description: 'street number and street name, without the apartment', label: 'street address', label_es: 'dirección', names: ['street', 'calle'], profile: { kind: 'pattern', regex: streetPattern, spoken_digits: 'house_number', accept_other: true }, depends_on: ['zip'], validator: 'address-street-validate', prepare: 'address-street-prompt', question_from: 'street_question', question: 'What is the street address?', question_es: '¿Cuál es la dirección?', form_client: { control: 'place', types: 'address', regions: ['us']
|
|
21
|
-
{ name: 'unit', argument_description: 'apartment or unit number alone, such as 4 or 12B', reset_on: ['street'], label: 'apartment or unit', label_es: 'apartamento o unidad', names: ['apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'], profile: { kind: 'pattern', regex: '(?:\\bapartment|\\bapartamento|\\bdepartamento|\\bapt\\.?|\\bunit|\\bunidad|#)\\s*([\\w-]+)', group: 1, spoken_digits: true, accept_other: true }, question_from: 'unit_question', question: 'Is there an apartment or unit number? Type the number, or NONE.', question_es: '¿Hay un número de apartamento o unidad? Escriba el número, o NINGUNO.' }],
|
|
20
|
+
{ name: 'street', argument_description: 'street number and street name, without the apartment', label: 'street address', label_es: 'dirección', names: ['street', 'calle'], profile: { kind: 'pattern', regex: streetPattern, spoken_digits: 'house_number', accept_other: true }, depends_on: ['zip'], validator: 'address-street-validate', prepare: 'address-street-prompt', question_from: 'street_question', question: 'What is the street address?', question_es: '¿Cuál es la dirección?', form_client: { control: 'place', types: 'address', regions: ['us'] } },
|
|
21
|
+
{ name: 'unit', declinable: true, argument_description: 'apartment or unit number alone, such as 4 or 12B', reset_on: ['street'], label: 'apartment or unit', label_es: 'apartamento o unidad', names: ['apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'], profile: { kind: 'pattern', regex: '(?:\\bapartment|\\bapartamento|\\bdepartamento|\\bapt\\.?|\\bunit|\\bunidad|#)\\s*([\\w-]+)', group: 1, spoken_digits: true, accept_other: true }, question_from: 'unit_question', question: 'Is there an apartment or unit number? Type the number, or NONE.', question_es: '¿Hay un número de apartamento o unidad? Escriba el número, o NINGUNO.' }],
|
|
22
22
|
before_confirm: [S('address_resolved', 'address_result', E(resolvedAddress, 'cargo.forms[form_instance].values', 'cargo.forms[form_instance].data'))],
|
|
23
23
|
confirm: { named_fields: true, reply_context: 'This is a mailing address read back for confirmation. A reply may correct one part or several at once: the street number, street name or street type, the apartment or unit, the city, or the ZIP code.', no_keys: ['2', 'not right', 'not correct', 'incorrect', 'wrong', 'no es correcto', 'no es correcta', 'incorrecta'], question: 'Your {{address_label}} is {{address_result.line}}. Is that correct?', question_es: 'Su {{address_label_es}} es {{address_result.line}}. ¿Es correcta?' },
|
|
24
24
|
after: [S('address_result_store', 'noop', '(cargo.forms[form_instance].values.resolved = address_result, cargo.address = address_result, cargo.addressDraft = null, true)')], declined: [S('address_retry_noop', 'noop', 'true')] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AA4GA;;;;;;;GAOG;AACH;;;;GAIG;AACH,8HAA8H;AAC9H,uFAIC;
|
|
1
|
+
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AA4GA;;;;;;;GAOG;AACH;;;;GAIG;AACH,8HAA8H;AAC9H,uFAIC;AAiED;;2EAE2E;AAC3E,qEAEC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyEC;AACD;;;GAGG;AACH;;;;;;EAGC;AAmlBD,wHAAwH;AACxH,wEAaC;AACD,4FAA4F;AAC5F;;;EAYC;AACD,sGAAsG;AACtG;;;EAOC;AAp2BM,6CAAuG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2jC9G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOG"}
|
package/dist/forms/flows.js
CHANGED
|
@@ -150,10 +150,9 @@ function validateAcceptanceDeclarations(id, inputs) {
|
|
|
150
150
|
* regions?}. A date's min and max are whole days from today in `timezone` (required with either); range_from names the
|
|
151
151
|
* start of a range, a date input of this form that is not itself an end. A number's min and max bound its value. A
|
|
152
152
|
* place suggests what the caller types from the host's place service: types 'cities' or 'address', regions up to 15
|
|
153
|
-
* ISO 3166-1 alpha-2 country codes
|
|
154
|
-
* for a street). Checked at definition time; malformed fails.
|
|
153
|
+
* ISO 3166-1 alpha-2 country codes. Checked at definition time; malformed fails.
|
|
155
154
|
*/
|
|
156
|
-
const FORM_CLIENT_KEYS = { date: ['control', 'range_from', 'min', 'max', 'timezone'], number: ['control', 'min', 'max'], place: ['control', 'types', 'regions'
|
|
155
|
+
const FORM_CLIENT_KEYS = { date: ['control', 'range_from', 'min', 'max', 'timezone'], number: ['control', 'min', 'max'], place: ['control', 'types', 'regions'] };
|
|
157
156
|
const FORM_CLIENT_KINDS = ['pattern', 'text', 'digits', 'amount', 'identifier'];
|
|
158
157
|
const FORM_PLACE_KINDS = ['pattern', 'text'];
|
|
159
158
|
const FORM_PLACE_TYPES = ['cities', 'address'];
|
|
@@ -211,19 +210,6 @@ function validateFormClientControls(id, inputs) {
|
|
|
211
210
|
!declared.regions.every((region) => typeof region === 'string' && /^[a-z]{2}$/i.test(region))))
|
|
212
211
|
fail(input, 'regions must be 1 to 15 two-letter country codes');
|
|
213
212
|
else { /* any region, or a valid list */ }
|
|
214
|
-
if (declared.context !== undefined) {
|
|
215
|
-
if (!Array.isArray(declared.context) || !declared.context.length || declared.context.length > 5)
|
|
216
|
-
fail(input, 'context must list 1 to 5 inputs of this form');
|
|
217
|
-
for (const name of declared.context) {
|
|
218
|
-
const other = all.find((candidate) => candidate.name === name);
|
|
219
|
-
if (!other || other === input)
|
|
220
|
-
fail(input, `context ${JSON.stringify(name)} must name another input of this form`);
|
|
221
|
-
else if (other.pii === true)
|
|
222
|
-
fail(input, `context ${name} is a sensitive input`);
|
|
223
|
-
else { /* a field whose value narrows the lookup */ }
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
else { /* no context */ }
|
|
227
213
|
}
|
|
228
214
|
else { /* a number */ }
|
|
229
215
|
}
|
|
@@ -498,11 +484,11 @@ const validateBatch = {
|
|
|
498
484
|
WHEN('vb_validator', 'vb_ready === true && vb_h.validator && !vb_known && !vb_h.invalid && !(cargo.inputCheck && cargo.inputCheck.ok === false)', FLOW('vb_validate', '{{vb_h.validator}}', 'call', { form: '{{vb_h.form}}', input: '{{vb_h.name}}', value: '{{vb_h.value}}', values: '{{vb_values}}', reading: '{{vb_h}}' })),
|
|
499
485
|
WHEN('vb_refused', 'vb_h.refused === true || vb_h.incompleteMoney === true', SIDE('vb_withhold_refusal', "(cargo.inputCheck=Object.assign({},cargo.inputCheck || {},{ok:false}),true)")),
|
|
500
486
|
SET('vb_candidate', 'vb_candidate', "Object.assign({},vb_h,{ok:!!(cargo.inputCheck && cargo.inputCheck.ok === true),value:cargo.inputCheck && cargo.inputCheck.value !== undefined && cargo.inputCheck.value !== null ? cargo.inputCheck.value : vb_h.value,message:cargo.inputCheck && cargo.inputCheck.message,message_es:cargo.inputCheck && cargo.inputCheck.message_es,quiet:!!(cargo.inputCheck && cargo.inputCheck.quiet)})"),
|
|
501
|
-
SET('vb_proposal_policy', 'vb_proposal', 'vb_relevant === true && vb_ready === true && vb_candidate.ok && !vb_known ? formProposalPolicy(cargo,vb_candidate,cargo.inputCheck,accepted) : null'),
|
|
487
|
+
SET('vb_proposal_policy', 'vb_proposal', 'vb_candidate.declined !== true && vb_relevant === true && vb_ready === true && vb_candidate.ok && !vb_known ? formProposalPolicy(cargo,vb_candidate,cargo.inputCheck,accepted) : null'),
|
|
502
488
|
SET('vb_proposal_values', 'vb_proposal_values', 'proposedFormValues(cargo,vb_h.form,accepted.concat([vb_candidate]))'),
|
|
503
489
|
SIDE('vb_proposal_reset', '(cargo.proposalCheck=undefined,true)'),
|
|
504
490
|
WHEN('vb_proposal_prepare', 'vb_proposal && vb_proposal.prepare', FLOW('vb_proposal_formatter', '{{vb_proposal.prepare}}', 'call', { form: '{{vb_candidate.form}}', input: '{{vb_candidate.name}}', value: '{{vb_candidate.value}}', values: '{{vb_proposal_values}}', reading: '{{vb_candidate}}' })),
|
|
505
|
-
SET('vb_proposal_gate', 'vb_proposal_ok', 'vb_relevant !== true || vb_ready !== true || !vb_candidate.ok || vb_known ? true : stageFormProposal(cargo,vb_candidate,formProposalDescriptor(vb_proposal,vb_proposal && vb_proposal.prepare ? cargo.proposalCheck : undefined))'),
|
|
491
|
+
SET('vb_proposal_gate', 'vb_proposal_ok', 'vb_candidate.declined === true || vb_relevant !== true || vb_ready !== true || !vb_candidate.ok || vb_known ? true : stageFormProposal(cargo,vb_candidate,formProposalDescriptor(vb_proposal,vb_proposal && vb_proposal.prepare ? cargo.proposalCheck : undefined))'),
|
|
506
492
|
{ ...SET('vb_proposal_gate_valid', 'noop', "typeof vb_proposal_ok === 'boolean'"), requireTrue: true },
|
|
507
493
|
SIDE('vb_take', "(vb_relevant !== true ? ignored.push(vb_h) : vb_ready !== true ? pending.push(Object.assign({}, vb_h, {outcome:'pending'})) : vb_candidate.ok === true ? (vb_proposal_ok === true ? accepted.push(Object.assign({}, vb_candidate, { outcome: vb_outcome })) : null) : rejected.push(Object.assign({}, vb_candidate, { outcome: 'rejected' })), true)"),
|
|
508
494
|
FLOW('vb_next', 'validate-input-batch', 'replace', { hits: '{{vb_rest}}', accepted: '{{accepted}}', rejected: '{{rejected}}', pending: '{{pending}}', ignored: '{{ignored}}' }),
|
|
@@ -599,7 +585,7 @@ const RANK_ARGUMENTS_JS = `(function(){
|
|
|
599
585
|
const readFormChoice = {
|
|
600
586
|
id: 'read-form-choice', name: 'ReadFormChoice', version: '1.4.0', scope: 'isolated', description: 'Rank an unreadable answer to a choice question and take the offered option it picks, or a request for a person or for text; otherwise ask again. A withdrawal or a new request leaves with saved form progress.',
|
|
601
587
|
parameters: [{ name: 'form', type: 'string' }, { name: 'input', type: 'string' }, { name: 'question', type: 'string' }, { name: 'question_es', type: 'string' }, { name: 'choices', type: 'array' }, { name: 'firm', type: 'string' }],
|
|
602
|
-
variables: vars({ question: '', question_es: '', choices: [], firm: '', asked: '', ranked: [], reply: null, picked: '', chain: null, reading: null, others: [], owner: null, stay: false, params: [], rank_params: [], args: null }),
|
|
588
|
+
variables: vars({ question: '', question_es: '', choices: [], firm: '', asked: '', ranked: [], reply: null, picked: '', chain: null, reading: null, others: [], owner: null, stay: false, params: [], rank_params: [], args: null, none_label: '' }),
|
|
603
589
|
steps: [SET('choice_asked', 'asked', "language === 'es' && question_es ? question_es : question"),
|
|
604
590
|
SET('choice_params', 'params', "(function(){var spec=((cargo.forms[form] || {}).specs || []).filter(function(i){return i.name===input;})[0];return spec && Array.isArray(spec.rank_parameters) ? spec.rank_parameters : [];})()"),
|
|
605
591
|
SET('choice_rank_params', 'rank_params', "params.map(function(p){return {name:p.name,type:p.type || 'string',description:p.description};})"),
|
|
@@ -607,10 +593,14 @@ const readFormChoice = {
|
|
|
607
593
|
SET('choice_stay', 'stay', 'formMustComplete(cargo,form,input)'),
|
|
608
594
|
SET('choice_others', 'others', otherChoicesJS('input', 'choices || []', "!(i.form===form && i.name===input)")),
|
|
609
595
|
rankedChoices('choice_ranked', `(choices || []).filter(function(c,i,all){return !(firm==='firm' && String(c.key)==='yes') && all.findIndex(function(o){return String(o.key)===String(c.key);})===i;}).map(function(c){return Object.assign({key:String(c.key),label:(${RANK_LABEL_JS})(c)},Array.isArray(c.parameters) && c.parameters.length ? {parameters:c.parameters.map(function(p){return {name:p.name,type:p.type || 'string',description:p.description};})} : {});}).concat(others.map(function(c){return Object.assign({key:c.key,label:c.label},c.parameters ? {parameters:c.parameters.map(function(p){return {name:p.name,type:p.type || 'string',description:p.description};})} : {});}))`),
|
|
596
|
+
// A declinable input (docs/copilot-reference.md: declinable) offers the ranker "there is none": its pick answers the
|
|
597
|
+
// field with no value, as the reader's own NONE does.
|
|
598
|
+
SET('choice_none_label', 'none_label', "(function(){var spec=((cargo.forms[form] || {}).specs || []).filter(function(i){return i.name===input;})[0];return spec && spec.declinable===true ? 'there is none: the caller has no '+String(spec.label || spec.name)+' (it does not apply to them)' : '';})()"),
|
|
599
|
+
WHEN('choice_none_offer', 'none_label', SET('choice_none_offered', 'ranked', "ranked.concat([{key:'__none',label:none_label}])")),
|
|
610
600
|
rankedDispatch('choice_dispatch', 'input_not_matched', true, 'rank_params'),
|
|
611
601
|
...escapeRoutes('choice_escape'),
|
|
612
602
|
...concernRoute('choice_concern', 'input'),
|
|
613
|
-
SET('choice_picked', 'picked', "(function(){var k=String(reply && reply.key || '');var c=(choices || []).filter(function(c){return String(c.key)===k;})[0] || others.filter(function(c){return c.key===k;})[0];return c ? String(c.key) : '';})()"),
|
|
603
|
+
SET('choice_picked', 'picked', "(function(){var k=String(reply && reply.key || '');if(k==='__none' && none_label)return 'none';var c=(choices || []).filter(function(c){return String(c.key)===k;})[0] || others.filter(function(c){return c.key===k;})[0];return c ? String(c.key) : '';})()"),
|
|
614
604
|
// A question over any_of asks one name and its choices belong to a member ('selection' asks, 'option' holds PAST DUE): the pick is read as the member's answer.
|
|
615
605
|
SET('choice_owner', 'owner', "(others.filter(function(c){return c.key===picked && !(choices || []).some(function(own){return String(own.key)===picked;});})[0] || {}).owner || (function(){var asked=(chain || []).filter(function(i){return i.form===form && i.name===input;})[0];if(asked || !picked)return null;var spec=((cargo.forms[form] || {}).specs || []).filter(function(i){return i.name===input;})[0];var names=((spec || {}).any_of || []).map(function(i){return i.name;});var member=(chain || []).filter(function(i){return i.form===form && names.indexOf(i.name)>=0 && i.profile && (i.profile.choices || []).some(function(c){return String(c.key)===picked;});})[0];return member ? {form:member.form,name:member.name} : null;})()"),
|
|
616
606
|
SET('choice_args', 'args', RANK_ARGUMENTS_JS),
|
|
@@ -650,7 +640,7 @@ const readConfirmReply = {
|
|
|
650
640
|
// confirm.named_fields: a field read back may be corrected in the caller's own words ('es Long Beach' at an address
|
|
651
641
|
// read back with the ZIP code's city): each named input of this form that holds a value is offered, and a pick asks
|
|
652
642
|
// that input again, so the caller's value replaces the one read back
|
|
653
|
-
SET('confirm_fields', 'fields', "named_fields === true || named_fields === 'true' ? (chain || []).filter(function(i){var v=cargo.forms[form] && cargo.forms[form].values;return i.form===form && !i.confirmation && Array.isArray(i.names) && i.names.length && v && v[i.name]!==undefined && v[i.name]!==null && v[i.name]!=='';}).map(function(i){var l=String(i.label || i.names[0]);return {key:'field:'+i.name,label:'says the '+l+' read back is wrong, or gives a different '+l,owner:{form:i.form,name:i.name}};}) : []"),
|
|
643
|
+
SET('confirm_fields', 'fields', "named_fields === true || named_fields === 'true' ? (chain || []).filter(function(i){var v=cargo.forms[form] && cargo.forms[form].values;return i.form===form && !i.confirmation && Array.isArray(i.names) && i.names.length && v && (v[i.name]!==undefined && v[i.name]!==null && v[i.name]!=='' || i.declinable===true && Object.prototype.hasOwnProperty.call(v,i.name) && v[i.name]===null);}).map(function(i){var l=String(i.label || i.names[0]),none=cargo.forms[form].values[i.name]===null;return {key:'field:'+i.name,label:none ? 'gives a '+l+' (the read back has none)' : 'says the '+l+' read back is wrong, or gives a different '+l,owner:{form:i.form,name:i.name}};}) : []"),
|
|
654
644
|
// A correction may name several fields ('it is Long Beach, apartment 4'): any field's pick extracts every named field's new value.
|
|
655
645
|
SET('confirm_field_arguments', 'field_arguments', "fields.map(function(c){var i=(chain || []).filter(function(i){return i.form===c.owner.form && i.name===c.owner.name;})[0];var l=String(i.label || i.names[0]);return {name:c.owner.name,type:'string',description:'The correct '+(i.argument_description || l)+' the caller gives now. Leave it empty when they give none.'};})"),
|
|
656
646
|
rankedChoices('confirm_ranked_choices', "(confirmation==='soft' ? [{key:'yes',label:'yes: agrees to what the question asks to confirm'}] : []).concat([{key:'no',label:'no: declines or refuses what the question asks to confirm'}]).concat(others.map(function(c){return Object.assign({key:c.key,label:c.label},c.parameters ? {parameters:c.parameters.map(function(p){return {name:p.name,type:p.type || 'string',description:p.description};})} : {});})).concat(fields.map(function(c){return {key:c.key,label:c.label,parameters:field_arguments};}))"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AAiCA,iGAAiG;AACjG;;;;;
|
|
1
|
+
{"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AAiCA,iGAAiG;AACjG;;;;;SA+FC;AAED,+GAA+G;AAC/G;wHACwH;AACxH,qEAWC;AAED;;;;SA4CC;AAED;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BC;AA5ND,qCAAsC,eAAe,CAAC"}
|
|
@@ -122,10 +122,15 @@ export function projectForm(session, flows) {
|
|
|
122
122
|
else if (control === 'place') {
|
|
123
123
|
// Suggestions come from the host's place service; the profile's bounds still apply to the typed text.
|
|
124
124
|
field.control = control;
|
|
125
|
-
field.place = { types: input.form_client.types, ...(input.form_client.regions ? { regions: input.form_client.regions.map(region => region.toLowerCase()) } : {})
|
|
126
|
-
...(input.form_client.context ? { context: input.form_client.context.map(name => prefix + name) } : {}) };
|
|
125
|
+
field.place = { types: input.form_client.types, ...(input.form_client.regions ? { regions: input.form_client.regions.map(region => region.toLowerCase()) } : {}) };
|
|
127
126
|
}
|
|
128
127
|
else { /* the profile's own box */ }
|
|
128
|
+
// A declinable field may be left blank: the submission names it in `declined` (answered, no value).
|
|
129
|
+
if (input.declinable === true) {
|
|
130
|
+
field.declinable = true;
|
|
131
|
+
if (field.filled && state.values[input.name] === null)
|
|
132
|
+
field.declined = true;
|
|
133
|
+
}
|
|
129
134
|
if (!field.sensitive && ['string', 'number', 'boolean'].includes(typeof state.values?.[input.name]))
|
|
130
135
|
field.value = state.values[input.name];
|
|
131
136
|
// A worded refusal is shown with its field; the bare 'invalid' flag (a refusal with no message, or a whole-form
|
|
@@ -187,13 +192,15 @@ export function parseFormSubmission(prompt, view) {
|
|
|
187
192
|
catch {
|
|
188
193
|
throw new Error('Invalid form submission JSON.');
|
|
189
194
|
}
|
|
190
|
-
if (!object(envelope) || Object.keys(envelope).some(key => !['form', 'values'].includes(key)) || !object(envelope.values))
|
|
195
|
+
if (!object(envelope) || Object.keys(envelope).some(key => !['form', 'values', 'declined'].includes(key)) || !object(envelope.values))
|
|
191
196
|
throw new Error('Expected form and values.');
|
|
197
|
+
if (envelope.declined !== undefined && (!Array.isArray(envelope.declined) || envelope.declined.some(path => typeof path !== 'string') || new Set(envelope.declined).size !== envelope.declined.length))
|
|
198
|
+
throw new Error('Declined must list field paths.');
|
|
192
199
|
if (!view || view.version !== 1 || envelope.form !== view.form)
|
|
193
200
|
throw new Error('This form is no longer the current input request.');
|
|
194
|
-
const allowed = new Set();
|
|
201
|
+
const allowed = new Set(), declinable = new Set();
|
|
195
202
|
const collect = fields => { for (const field of fields)
|
|
196
|
-
field.fields ? collect(field.fields) : allowed.add(field.path); };
|
|
203
|
+
field.fields ? collect(field.fields) : (allowed.add(field.path), field.declinable && declinable.add(field.path)); };
|
|
197
204
|
collect(view.fields);
|
|
198
205
|
let count = 0;
|
|
199
206
|
const walk = (values, prefix = '', depth = 0) => {
|
|
@@ -219,9 +226,23 @@ export function parseFormSubmission(prompt, view) {
|
|
|
219
226
|
}
|
|
220
227
|
};
|
|
221
228
|
walk(envelope.values);
|
|
229
|
+
// A declined field is answered with no value: a null at its path (a declinable field left blank, never one with text).
|
|
230
|
+
const values = structuredClone(envelope.values);
|
|
231
|
+
for (const path of envelope.declined || []) {
|
|
232
|
+
if (!declinable.has(path))
|
|
233
|
+
throw new Error('This field cannot be left without a value.');
|
|
234
|
+
const names = path.split('.'), leaf = names.pop();
|
|
235
|
+
let node = values;
|
|
236
|
+
for (const name of names)
|
|
237
|
+
node = object(node[name]) ? node[name] : (node[name] = {});
|
|
238
|
+
if (typeof node[leaf] === 'string' && node[leaf].trim())
|
|
239
|
+
throw new Error('A declined field has a value.');
|
|
240
|
+
node[leaf] = null;
|
|
241
|
+
count++;
|
|
242
|
+
}
|
|
222
243
|
if (!count)
|
|
223
244
|
throw new Error('Enter at least one field value.');
|
|
224
|
-
return { prompt, form: envelope.form, values
|
|
245
|
+
return { prompt, form: envelope.form, values };
|
|
225
246
|
}
|
|
226
247
|
/** Install these two overrides for one preflighted submission turn only; restore the host's functions afterwards.
|
|
227
248
|
* No parser, new state, or changed behavior is installed on ordinary clients/turns.
|
|
@@ -235,6 +256,8 @@ export function formSubmissionReaders(submission, getSession) {
|
|
|
235
256
|
if (!state)
|
|
236
257
|
throw new Error('Submitted form no longer exists.');
|
|
237
258
|
const hits = formInitialReadings(state, submission.values, cargo).map(hit => {
|
|
259
|
+
if (hit.declined === true)
|
|
260
|
+
return { ...hit, origin: 'form_submission', current: false, utterance: '' };
|
|
238
261
|
// Prepared enums carry their current choices in the existing candidate chain.
|
|
239
262
|
const profile = candidates.find(candidate => candidate.form === hit.form && candidate.name === hit.name)?.profile || hit.profile;
|
|
240
263
|
const raw = hit.raw;
|
package/dist/helpers/address.js
CHANGED
|
@@ -34,7 +34,7 @@ export function streetLocation(result, said, zip) {
|
|
|
34
34
|
return { street: exact ? part('street_number') + ' ' + part('route') : String(said).trim(), said: String(said).trim(), verified: !!exact, city };
|
|
35
35
|
}
|
|
36
36
|
export function resolvedAddress(values, data) {
|
|
37
|
-
const unit =
|
|
37
|
+
const unit = String(values.unit ?? '').replace(/^(apt\.?|unit|#)\s*/i, '');
|
|
38
38
|
const street = data.street?.street || values.street || '', city = values.city && data.location?.state ? values.city + ', ' + data.location.state : data.location?.line || values.city_state || '';
|
|
39
39
|
return { street, unit, city, zip: String(values.zip || ''), line: street + (unit ? ' Apt ' + unit : '') + ', ' + city + ' ' + values.zip, verified: data.street?.verified === true, said: data.street?.said || values.street || '' };
|
|
40
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-proposals.d.ts","sourceRoot":"","sources":["../../src/helpers/form-proposals.js"],"names":[],"mappings":"AAgEA,yHAAyH;AACzH,gGASC;AACD,gHAAgH;AAChH,kFAkCC;AACD,iHAAiH;AACjH,8DAOC;AACD,2GAA2G;AAC3G,uGAYC;AACD,wGAAwG;AACxG,wFAMC;AACD,0GAA0G;AAC1G,6GASC;AACD,gHAAgH;AAChH,
|
|
1
|
+
{"version":3,"file":"form-proposals.d.ts","sourceRoot":"","sources":["../../src/helpers/form-proposals.js"],"names":[],"mappings":"AAgEA,yHAAyH;AACzH,gGASC;AACD,gHAAgH;AAChH,kFAkCC;AACD,iHAAiH;AACjH,8DAOC;AACD,2GAA2G;AAC3G,uGAYC;AACD,wGAAwG;AACxG,wFAMC;AACD,0GAA0G;AAC1G,6GASC;AACD,gHAAgH;AAChH,2EAoBC;AACD,4GAA4G;AAC5G,yEAIC"}
|
|
@@ -223,6 +223,8 @@ export function decideFormProposal(cargo, owner, input, childId, decision) {
|
|
|
223
223
|
export function commitFormProposals(cargo, accepted = []) {
|
|
224
224
|
const changes = [], readings = [];
|
|
225
225
|
for (const hit of accepted) {
|
|
226
|
+
if (hit.declined === true)
|
|
227
|
+
continue; // a declinable input's "none" carries no proposal (rejected at definition time)
|
|
226
228
|
const { state } = candidate(cargo, hit);
|
|
227
229
|
readings.push({ state, hit });
|
|
228
230
|
const record = recordFor(cargo, state, hit.name);
|
|
@@ -112,4 +112,5 @@ export function formParentResume(cargo: any, id: any, explicit?: boolean, ownerW
|
|
|
112
112
|
export function formInstanceApplies(cargo: any, id: any, seen?: Set<any>): any;
|
|
113
113
|
export function closeFormInstance(cargo: any, id: any, handOn?: boolean): any;
|
|
114
114
|
export function hasFormValue(v: any): boolean;
|
|
115
|
+
export function formDeclined(input: any, values: any): boolean;
|
|
115
116
|
//# sourceMappingURL=form-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-state.d.ts","sourceRoot":"","sources":["../../src/helpers/form-state.js"],"names":[],"mappings":"AAQA,qDAKC;
|
|
1
|
+
{"version":3,"file":"form-state.d.ts","sourceRoot":"","sources":["../../src/helpers/form-state.js"],"names":[],"mappings":"AAQA,qDAKC;AAKD,oDAEC;AAED,qFAAqF;AACrF,oEAgCC;AA0CD,2FAEC;AACD,8FAcC;AACD,2DAOC;AACD,uEA8CC;AAED,kGAAkG;AAClG,2GAOC;AACD,0HAA0H;AAC1H,uEAwBC;AACD,8HAA8H;AAC9H;;;;;EAeC;AACD,uGAAuG;AACvG;;;;;;;;;;;;;;;;;;QA+CC;AAED,0FAA0F;AAC1F;;;SAIC;AACD,gGAAgG;AAChG;;;;;;;;;;;EAQC;AAED,sGAAsG;AACtG,2DAIC;AACD;;;GAGG;AACH;;;;;;;SAkBC;AAED,2FAA2F;AAC3F,oGAIC;AACD,gFAgCC;AAED,2GAA2G;AAC3G;;;EASC;AACD,mEAoBC;AACD,mEAGC;AACD,sEAUC;AACD,+EAEC;AAoCD,qFAYC;AACD,oGAqCC;AACD;;;SAKC;AACD,qEAGC;AACD,gEAgBC;AACD;;uGAEuG;AACvG,sEAGC;AACD,2DAQC;AACD,oGAUC;AAED,uEAAuE;AACvE,wHA+BC;AAED,uHAAuH;AACvH,6EAaC;AACD,mHAAmH;AACnH,iGAsDC;AACD;;;GAGG;AACH;;;SAcC;AACD,+EASC;AACD,8EAeC;AA9qBM,8CAAmE;AAGnE,+DAA4H"}
|
|
@@ -14,6 +14,9 @@ export function formValuesEqual(a, b) {
|
|
|
14
14
|
return ak.length === bk.length && ak.every(k => own(b, k) && formValuesEqual(a[k], b[k]));
|
|
15
15
|
}
|
|
16
16
|
export const hasFormValue = v => v !== undefined && v !== null && v !== '';
|
|
17
|
+
/** A `declinable` input answered "there is none" holds an explicit null: answered, with no value (never the same as
|
|
18
|
+
* unanswered, which has no key at all). Only a declinable input can hold it. */
|
|
19
|
+
export const formDeclined = (input, values) => input?.declinable === true && own(values, input.name) && values[input.name] === null;
|
|
17
20
|
export function formPath(root, path) {
|
|
18
21
|
return String(path || '').split('.').reduce((o, k) => forbidden.has(k) || o === undefined || o === null || !own(o, k) ? undefined : o[k], root);
|
|
19
22
|
}
|
|
@@ -37,6 +40,8 @@ export function resolveFormInputs(inputs, presets = {}) {
|
|
|
37
40
|
validateMoneyOptions(input.profile.money);
|
|
38
41
|
}
|
|
39
42
|
validateFormExhaustion(input.on_exhausted);
|
|
43
|
+
if (input.declinable !== undefined && (input.declinable !== true || !input.profile || input.form || input.any_of || input.bind || input.confirmation || input.profile.kind === 'choice' || input.proposal !== undefined))
|
|
44
|
+
throw new Error(`FORM declinable ${input.name} must be true on a readable leaf input that is not a choice, a confirmation or a proposal`);
|
|
40
45
|
if (input.meaning !== undefined)
|
|
41
46
|
throw new Error('FORM meaning is retired; use a contextual response description');
|
|
42
47
|
if (input.response !== undefined) {
|
|
@@ -120,7 +125,7 @@ function formCondition(input, values = {}, cargo = {}, state = {}) {
|
|
|
120
125
|
const list = [].concat(wanted).map(String);
|
|
121
126
|
const yes = list.filter(v => !v.startsWith('!'));
|
|
122
127
|
const matches = (!yes.length || yes.includes(have)) && list.filter(v => v.startsWith('!')).every(v => have !== v.slice(1));
|
|
123
|
-
return matches ? true : !hasFormValue(value(key)) ? null : false;
|
|
128
|
+
return matches ? true : !hasFormValue(value(key)) && !(own(values, key) && values[key] === null) ? null : false;
|
|
124
129
|
});
|
|
125
130
|
return conditions.includes(false) ? false : conditions.includes(null) ? null : true;
|
|
126
131
|
}
|
|
@@ -146,7 +151,7 @@ export function formInputFilled(input, state, cargo = {}, checking = new Set())
|
|
|
146
151
|
const v = formPath({ cargo }, input.bind);
|
|
147
152
|
return hasFormValue(v) && v !== false;
|
|
148
153
|
}
|
|
149
|
-
const filled = name => !(state.inputProposals?.[name] && !state.inputProposals[name].committed && ['pending', 'confirmed'].includes(state.inputProposals[name].status)) && !state.errors?.[name] && !state.pending?.[name] && hasFormValue(state.values[name]);
|
|
154
|
+
const filled = name => !(state.inputProposals?.[name] && !state.inputProposals[name].committed && ['pending', 'confirmed'].includes(state.inputProposals[name].status)) && !state.errors?.[name] && !state.pending?.[name] && (hasFormValue(state.values[name]) || formDeclined(state.specs.flatMap(s => s.any_of || [s]).find(s => s.name === name), state.values));
|
|
150
155
|
return input.any_of ? input.any_of.some(i => formInputApplies(i, state.values, cargo, state) && formInputFilled(i, state, cargo, checking)) : filled(input.name);
|
|
151
156
|
}
|
|
152
157
|
export function nextFormInput(state, cargo = {}) {
|
|
@@ -221,7 +226,7 @@ export function enrichFormMatches(matches, chain, form, names = [], asked = '')
|
|
|
221
226
|
const enrich = h => {
|
|
222
227
|
const spec = chain.find(c => c.form === h.form && c.name === h.name) || {};
|
|
223
228
|
return { ...h, label: h.option_label || spec.label || h.name, label_es: h.option_label_es || spec.label_es || spec.label || h.name, ...(h.option_label ? { option: true } : {}),
|
|
224
|
-
validator: spec.validator || '', ...((matches.decisions || []).some(d => d.form === h.form && d.name === h.name && (d.rule === 'out_of_order' || d.rule === 'compound')) ? { out_of_order: true } : {}), ...(!(h.form === form && names.includes(h.name)) && spec.profile && !['choice', 'amount', 'text'].includes(spec.profile.kind) && /\d/.test(String(h.value)) ? { out_of_order_number: true } : {}), ...(spec.response ? { response: spec.response } : {}), after: spec.after || '', validate_always: spec.validate_always === true, ...(spec.activation ? { activation: spec.activation } : {}), ...(spec.silent === true ? { silent: true } : {}), pii: spec.pii === true, current: h.form === form && names.includes(h.name), asked };
|
|
229
|
+
validator: h.declined === true ? '' : spec.validator || '', ...((matches.decisions || []).some(d => d.form === h.form && d.name === h.name && (d.rule === 'out_of_order' || d.rule === 'compound')) ? { out_of_order: true } : {}), ...(!(h.form === form && names.includes(h.name)) && spec.profile && !['choice', 'amount', 'text'].includes(spec.profile.kind) && /\d/.test(String(h.value)) ? { out_of_order_number: true } : {}), ...(spec.response ? { response: spec.response } : {}), after: spec.after || '', validate_always: spec.validate_always === true, ...(spec.activation ? { activation: spec.activation } : {}), ...(spec.silent === true ? { silent: true } : {}), pii: spec.pii === true, current: h.form === form && names.includes(h.name), asked };
|
|
225
230
|
};
|
|
226
231
|
return { ...matches, hits: matches.hits.map(enrich), ambiguous: matches.ambiguous.map(enrich), remaining: (matches.remaining || []).map(group => group.map(enrich)) };
|
|
227
232
|
}
|
|
@@ -459,6 +464,10 @@ export function formInitialReadings(state, supplied = {}, cargo = {}) {
|
|
|
459
464
|
// predecessors by the common batch, so a new controller is never hidden by its old committed value.
|
|
460
465
|
for (const group of state.specs || [])
|
|
461
466
|
for (const input of group.any_of || [group]) {
|
|
467
|
+
if (own(supplied, input.name) && supplied[input.name] === null && input.declinable === true) {
|
|
468
|
+
hits.push({ ...input, label: input.label || input.name, label_es: input.label_es || input.label || input.name, form: state.id, value: null, declined: true, invalid: false, known: formDeclined(input, state.values), current: true, origin: 'activation', raw: '', utterance: String(supplied.userInput || '') });
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
462
471
|
if (!own(supplied, input.name) || !hasFormValue(supplied[input.name]) || !input.profile)
|
|
463
472
|
continue;
|
|
464
473
|
const value = supplied[input.name];
|
|
@@ -925,7 +934,7 @@ export function acceptFormReadings(cargo, hits, additionalCandidates = []) {
|
|
|
925
934
|
if (!state || hit.ok !== true)
|
|
926
935
|
throw new Error('FORM acceptance requires an existing instance and a validated value');
|
|
927
936
|
const input = state.specs.flatMap(s => s.any_of || [s]).find(s => s.name === hit.name);
|
|
928
|
-
if (!input || !hasFormValue(hit.value))
|
|
937
|
+
if (!input || !(hasFormValue(hit.value) || hit.declined === true && hit.value === null && input.declinable === true))
|
|
929
938
|
throw new Error('FORM acceptance names an unknown input or empty value');
|
|
930
939
|
if (!groups.has(hit.form))
|
|
931
940
|
groups.set(hit.form, []);
|
|
@@ -951,7 +960,7 @@ export function acceptFormReadings(cargo, hits, additionalCandidates = []) {
|
|
|
951
960
|
}
|
|
952
961
|
}
|
|
953
962
|
const changed = [...cleared, ...readings.filter(h => !formValuesEqual(state.values[h.name], h.value)).map(h => h.name)];
|
|
954
|
-
const invalidating = changed.filter(name => cleared.includes(name) || hasFormValue(state.values[name]));
|
|
963
|
+
const invalidating = changed.filter(name => cleared.includes(name) || hasFormValue(state.values[name]) || own(state.values, name) && state.values[name] === null);
|
|
955
964
|
invalidateFormInputs(cargo, id, invalidating, readings.map(h => h.name), preservedNodes());
|
|
956
965
|
if (changed.length && !invalidating.length) {
|
|
957
966
|
state.revision++;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -164,6 +164,7 @@ import { isPartialMoneyAnswer } from './money.js';
|
|
|
164
164
|
import { validateMoneyOptions } from './money.js';
|
|
165
165
|
import { takeChoiceOffer } from './choice-offer.js';
|
|
166
166
|
import { saysConfirmWord } from './match-inputs.js';
|
|
167
|
+
import { saysNoValue } from './match-inputs.js';
|
|
167
168
|
import { confirmOutOfOrderLine } from './match-inputs.js';
|
|
168
169
|
import { matchesChoice } from './matches-choice.js';
|
|
169
170
|
import { ANSWER_WORDS } from './answer.js';
|
|
@@ -264,5 +265,5 @@ import { textWithUrlToSpeech } from './url-speech.js';
|
|
|
264
265
|
import { joinSpokenDigits } from './spoken-digits.js';
|
|
265
266
|
import { spokenDigitsText } from './spoken-digits.js';
|
|
266
267
|
import { wholeSpokenNumber } from './spoken-digits.js';
|
|
267
|
-
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, formConversationOutcome, readMoneyAmount, isMoneyAmount, moneyIntentAllows, isPastPaymentStatement, isPartialMoneyAnswer, validateMoneyOptions, takeChoiceOffer, saysConfirmWord, confirmOutOfOrderLine, matchesChoice, ANSWER_WORDS, CONFIRM_WORDS, isAnswer, isAgentRequest, isExitRequest, isGlobalExit, isOtherRequest, isSpelledFragment, isAmountAnswer, amountInAnswer, pickChoice, withoutPromptEcho, readEmail, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readInputProfile, formAcceptanceTrace, resolveFormInputs, formInputApplies, formInputFilled, nextFormInput, formInputChain, openFormInstance, validateFormIncompleteOutcome, formIncompleteOutcome, validateFormExhaustion, exhaustFormInput, formInitialReadings, orderFormReadings, proposedFormValues, applyFormValidation, formReadingDependencies, exclusiveFormReadings, enrichFormMatches, expandFormActivations, settleFormActivations, rememberFormArguments, resetFormInputs, hasFormValue, formPath, formValuesEqual, formReadingReady, formReadingRelevant, formPreparation, queueFormReadings, pendingFormReadings, formWorkLimit, answerResetsFormReplays, rejectFormReadings, invalidateFormInputs, acceptFormReadings, formInstanceApplies, formParentResume, closeFormInstance, checkOtp, clearOtp, maskDestination, validateOTP, OTP_EXPIRY_MS, validateDigits, validatePhone, validateEmail, urlToSpeech, textWithUrlToSpeech, joinSpokenDigits, spokenDigitsText, wholeSpokenNumber };
|
|
268
|
+
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, formConversationOutcome, readMoneyAmount, isMoneyAmount, moneyIntentAllows, isPastPaymentStatement, isPartialMoneyAnswer, validateMoneyOptions, takeChoiceOffer, saysConfirmWord, saysNoValue, confirmOutOfOrderLine, matchesChoice, ANSWER_WORDS, CONFIRM_WORDS, isAnswer, isAgentRequest, isExitRequest, isGlobalExit, isOtherRequest, isSpelledFragment, isAmountAnswer, amountInAnswer, pickChoice, withoutPromptEcho, readEmail, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readInputProfile, formAcceptanceTrace, resolveFormInputs, formInputApplies, formInputFilled, nextFormInput, formInputChain, openFormInstance, validateFormIncompleteOutcome, formIncompleteOutcome, validateFormExhaustion, exhaustFormInput, formInitialReadings, orderFormReadings, proposedFormValues, applyFormValidation, formReadingDependencies, exclusiveFormReadings, enrichFormMatches, expandFormActivations, settleFormActivations, rememberFormArguments, resetFormInputs, hasFormValue, formPath, formValuesEqual, formReadingReady, formReadingRelevant, formPreparation, queueFormReadings, pendingFormReadings, formWorkLimit, answerResetsFormReplays, rejectFormReadings, invalidateFormInputs, acceptFormReadings, formInstanceApplies, formParentResume, closeFormInstance, checkOtp, clearOtp, maskDestination, validateOTP, OTP_EXPIRY_MS, validateDigits, validatePhone, validateEmail, urlToSpeech, textWithUrlToSpeech, joinSpokenDigits, spokenDigitsText, wholeSpokenNumber };
|
|
268
269
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CACyC,iCAAiC;+BAIqI,wBAAwB;2CAHzJ,0BAA0B;qCAA1B,0BAA0B;gCAA1B,0BAA0B;mCACsE,qBAAqB;kCAArB,qBAAqB;iCAArB,qBAAqB;qCAArB,qBAAqB;iCAArB,qBAAqB;mCAArB,qBAAqB;oCAArB,qBAAqB;6CAArB,qBAAqB;qCAC/E,wBAAwB;2CAAxB,wBAAwB;+CAAxB,wBAAwB;uCAAxB,wBAAwB;gCACmE,wBAAwB;4BAAxB,wBAAwB;8BAAxB,wBAAwB;iCAAxB,wBAAwB;gCAAxB,wBAAwB;0CAAxB,wBAAwB;gCAAxB,wBAAwB;iCAAxB,wBAAwB;oCAAxB,wBAAwB;wCAAxB,wBAAwB;gCAmBxG,YAAY;8BAAZ,YAAY;kCAAZ,YAAY;uCAAZ,YAAY;qCAAZ,YAAY;qCAAZ,YAAY;gCAlB3G,mBAAmB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CACyC,iCAAiC;+BAIqI,wBAAwB;2CAHzJ,0BAA0B;qCAA1B,0BAA0B;gCAA1B,0BAA0B;mCACsE,qBAAqB;kCAArB,qBAAqB;iCAArB,qBAAqB;qCAArB,qBAAqB;iCAArB,qBAAqB;mCAArB,qBAAqB;oCAArB,qBAAqB;6CAArB,qBAAqB;qCAC/E,wBAAwB;2CAAxB,wBAAwB;+CAAxB,wBAAwB;uCAAxB,wBAAwB;gCACmE,wBAAwB;4BAAxB,wBAAwB;8BAAxB,wBAAwB;iCAAxB,wBAAwB;gCAAxB,wBAAwB;0CAAxB,wBAAwB;gCAAxB,wBAAwB;iCAAxB,wBAAwB;oCAAxB,wBAAwB;wCAAxB,wBAAwB;gCAmBxG,YAAY;8BAAZ,YAAY;kCAAZ,YAAY;uCAAZ,YAAY;qCAAZ,YAAY;qCAAZ,YAAY;gCAlB3G,mBAAmB;gCA0BqF,mBAAmB;4BAAnB,mBAAmB;sCAAnB,mBAAmB;8BAT7H,qBAAqB;6BAEkJ,aAAa;8BAAb,aAAa;yBAAb,aAAa;+BAAb,aAAa;8BAAb,aAAa;6BAAb,aAAa;+BAAb,aAAa;kCAAb,aAAa;+BAAb,aAAa;+BAAb,aAAa;2BAAb,aAAa;kCAAb,aAAa;0BACzD,cAAc;0BAAd,cAAc;uCAAd,cAAc;+BAAd,cAAc;sBAAd,cAAc;0BAAd,cAAc;iCAAd,cAAc;gCAAd,cAAc;sCAAd,cAAc;wCAC/H,cAAc;6BACS,cAAc;wBAAd,cAAc;wBAAd,cAAc;+BAAd,cAAc;4BACjD,iBAAiB;+BACd,uBAAuB;mCACC,kBAAkB;mCAAlB,kBAAkB;qCAxB+I,mBAAmB;yCAAnB,mBAAmB;8BAAnB,mBAAmB;iCAAnB,mBAAmB;oCAAnB,mBAAmB;kCAAnB,mBAAmB;wCAAnB,mBAAmB;gCAAnB,mBAAmB;iCAAnB,mBAAmB;mCAAnB,mBAAmB;gCAe1I,mBAAmB;mCAAnB,mBAAmB;sCAAnB,mBAAmB;qCAAnB,mBAAmB;4BAUoB,mBAAmB;+BAAnB,mBAAmB;iCAAnB,mBAAmB;oCAAnB,mBAAmB;kCAC6kB,iBAAiB;iCAAjB,iBAAiB;gCAAjB,iBAAiB;8BAAjB,iBAAiB;+BAAjB,iBAAiB;iCAAjB,iBAAiB;8CAAjB,iBAAiB;sCAAjB,iBAAiB;uCAAjB,iBAAiB;iCAAjB,iBAAiB;oCAAjB,iBAAiB;kCAAjB,iBAAiB;mCAAjB,iBAAiB;oCAAjB,iBAAiB;wCAAjB,iBAAiB;sCAAjB,iBAAiB;kCAAjB,iBAAiB;sCAAjB,iBAAiB;sCAAjB,iBAAiB;sCAAjB,iBAAiB;gCAAjB,iBAAiB;6BAAjB,iBAAiB;yBAAjB,iBAAiB;gCAAjB,iBAAiB;iCAAjB,iBAAiB;oCAAjB,iBAAiB;gCAAjB,iBAAiB;kCAAjB,iBAAiB;oCAAjB,iBAAiB;8BAAjB,iBAAiB;wCAAjB,iBAAiB;mCAAjB,iBAAiB;qCAAjB,iBAAiB;mCAAjB,iBAAiB;oCAAjB,iBAAiB;iCAAjB,iBAAiB;kCAAjB,iBAAiB;yBACzqB,gBAAgB;yBAAhB,gBAAgB;gCAAhB,gBAAgB;4BAAhB,gBAAgB;8BAAhB,gBAAgB;+BACnC,iBAAiB;8BAAjB,iBAAiB;8BAAjB,iBAAiB;4BAE7B,iBAAiB;oCAAjB,iBAAiB;iCADI,oBAAoB;iCAApB,oBAAoB;kCAApB,oBAAoB"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -30,13 +30,13 @@ import { anythingElse, goodbye, sayName, sorryNotCaught } from './phrases.js';
|
|
|
30
30
|
import { dateToWords } from './date-words.js';
|
|
31
31
|
import { amountToSpeech } from './amount-to-speech.js';
|
|
32
32
|
import { validateCardNumber, validateExpiration } from './card-checks.js';
|
|
33
|
-
import { matchInputs, readFormAnswer, saysConfirmWord, confirmOutOfOrderLine, readInputProfile, formAcceptanceTrace } from './match-inputs.js';
|
|
33
|
+
import { matchInputs, readFormAnswer, saysConfirmWord, saysNoValue, confirmOutOfOrderLine, readInputProfile, formAcceptanceTrace } from './match-inputs.js';
|
|
34
34
|
import { resolveFormInputs, formInputApplies, formInputFilled, nextFormInput, formInputChain, openFormInstance, validateFormIncompleteOutcome, formIncompleteOutcome, validateFormExhaustion, exhaustFormInput, formInitialReadings, orderFormReadings, proposedFormValues, applyFormValidation, formReadingDependencies, exclusiveFormReadings, enrichFormMatches, expandFormActivations, settleFormActivations, rememberFormArguments, resetFormInputs, hasFormValue, formPath, formValuesEqual, formReadingReady, formReadingRelevant, formPreparation, queueFormReadings, pendingFormReadings, formWorkLimit, answerResetsFormReplays, rejectFormReadings, invalidateFormInputs, acceptFormReadings, formInstanceApplies, formParentResume, closeFormInstance } from './form-state.js';
|
|
35
35
|
import { checkOtp, clearOtp, maskDestination, validateOTP, OTP_EXPIRY_MS } from './otp-check.js';
|
|
36
36
|
import { validateDigits, validatePhone, validateEmail } from './validators.js';
|
|
37
37
|
import { joinSpokenDigits, spokenDigitsText, wholeSpokenNumber } from './spoken-digits.js';
|
|
38
38
|
import { urlToSpeech, textWithUrlToSpeech } from './url-speech.js';
|
|
39
|
-
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, formConversationOutcome, readMoneyAmount, isMoneyAmount, moneyIntentAllows, isPastPaymentStatement, isPartialMoneyAnswer, validateMoneyOptions, takeChoiceOffer, saysConfirmWord, confirmOutOfOrderLine, matchesChoice, ANSWER_WORDS, CONFIRM_WORDS, isAnswer, isAgentRequest, isExitRequest, isGlobalExit, isOtherRequest, isSpelledFragment, isAmountAnswer, amountInAnswer, pickChoice, withoutPromptEcho, readEmail, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readInputProfile, formAcceptanceTrace, resolveFormInputs, formInputApplies, formInputFilled, nextFormInput, formInputChain, openFormInstance, validateFormIncompleteOutcome, formIncompleteOutcome, validateFormExhaustion, exhaustFormInput, formInitialReadings, orderFormReadings, proposedFormValues, applyFormValidation, formReadingDependencies, exclusiveFormReadings, enrichFormMatches, expandFormActivations, settleFormActivations, rememberFormArguments, resetFormInputs, hasFormValue, formPath, formValuesEqual, formReadingReady, formReadingRelevant, formPreparation, queueFormReadings, pendingFormReadings, formWorkLimit, answerResetsFormReplays, rejectFormReadings, invalidateFormInputs, acceptFormReadings, formInstanceApplies, formParentResume, closeFormInstance, checkOtp, clearOtp, maskDestination, validateOTP, OTP_EXPIRY_MS, validateDigits, validatePhone, validateEmail, urlToSpeech, textWithUrlToSpeech, joinSpokenDigits, spokenDigitsText, wholeSpokenNumber, };
|
|
39
|
+
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, formConversationOutcome, readMoneyAmount, isMoneyAmount, moneyIntentAllows, isPastPaymentStatement, isPartialMoneyAnswer, validateMoneyOptions, takeChoiceOffer, saysConfirmWord, saysNoValue, confirmOutOfOrderLine, matchesChoice, ANSWER_WORDS, CONFIRM_WORDS, isAnswer, isAgentRequest, isExitRequest, isGlobalExit, isOtherRequest, isSpelledFragment, isAmountAnswer, amountInAnswer, pickChoice, withoutPromptEcho, readEmail, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readInputProfile, formAcceptanceTrace, resolveFormInputs, formInputApplies, formInputFilled, nextFormInput, formInputChain, openFormInstance, validateFormIncompleteOutcome, formIncompleteOutcome, validateFormExhaustion, exhaustFormInput, formInitialReadings, orderFormReadings, proposedFormValues, applyFormValidation, formReadingDependencies, exclusiveFormReadings, enrichFormMatches, expandFormActivations, settleFormActivations, rememberFormArguments, resetFormInputs, hasFormValue, formPath, formValuesEqual, formReadingReady, formReadingRelevant, formPreparation, queueFormReadings, pendingFormReadings, formWorkLimit, answerResetsFormReplays, rejectFormReadings, invalidateFormInputs, acceptFormReadings, formInstanceApplies, formParentResume, closeFormInstance, checkOtp, clearOtp, maskDestination, validateOTP, OTP_EXPIRY_MS, validateDigits, validatePhone, validateEmail, urlToSpeech, textWithUrlToSpeech, joinSpokenDigits, spokenDigitsText, wholeSpokenNumber, };
|
|
40
40
|
/** The functions flows call by name, ready to spread into a host's approved functions. */
|
|
41
41
|
export const STANDARD_FUNCTIONS = {
|
|
42
42
|
continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse,
|
|
@@ -35,6 +35,7 @@ export function readInputProfile(profile: any, answer: any, isCurrent?: boolean)
|
|
|
35
35
|
* A question clause is consumed as a question; independently separated clauses remain available for collection. */
|
|
36
36
|
export function saysConfirmWord(answer: any, spec: any): boolean;
|
|
37
37
|
export function confirmOutOfOrderLine(spec: any, value: any, language: any, voice: any): string;
|
|
38
|
+
export function saysNoValue(answer: any): boolean;
|
|
38
39
|
export function readFormAnswer(answer: any, candidates: any, current: any, choiceKey: any, questions?: any[]): {
|
|
39
40
|
hits: any[];
|
|
40
41
|
ambiguous: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,sEAQC;AAyFD;;;GAGG;AACH,sFA8HC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAGD,gGAKC;AAED;;;;;;;;;;;;;;;;;;;;;;EAeC;AACD;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,sEAQC;AAyFD;;;GAGG;AACH,sFA8HC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAGD,gGAKC;AAYD,kDAGC;AAED;;;;;;;;;;;;;;;;;;;;;;EAeC;AACD;;;;;;;;;;;;;;;;;;;;;;;EAiTC"}
|
|
@@ -316,6 +316,20 @@ export function confirmOutOfOrderLine(spec, value, language, voice) {
|
|
|
316
316
|
const word = String((es && spec?.word_es) || spec?.word || '');
|
|
317
317
|
return line.replace('{value}', String(value ?? '').split('').join(voice ? ' ' : '')).replace('{word}', word);
|
|
318
318
|
}
|
|
319
|
+
// A declinable input's "there is none" (docs/copilot-reference.md: declinable): the whole answer says the caller has no
|
|
320
|
+
// value for the field asked, in English or Spanish. An answer with a digit is never one ("no, 4B" names a unit), and
|
|
321
|
+
// neither is a longer sentence: those reach the field's reader, then the reply ranker, which is offered "none".
|
|
322
|
+
const NO_VALUE = new RegExp('^(?:' + [
|
|
323
|
+
'no', 'nope', 'none', 'nothing', 'n/?a', 'not applicable', 'does ?n[o\u2019\']?t apply', 'not any', 'there is none', 'there are none', 'i have none',
|
|
324
|
+
"there (?:is|are|'s|is not|isn't|are not|aren't) (?:no|not? (?:one|any))(?: \\p{L}+){0,3}",
|
|
325
|
+
"(?:i|we) (?:do not|don't|dont|do ?n\u2019t) have(?: (?:one|any|it))?(?: (?:a|an|any|the))?(?: \\p{L}+){0,3}",
|
|
326
|
+
"no (?:\\p{L}+)(?: \\p{L}+)?",
|
|
327
|
+
'ningun[oa]?', 'nada', 'no aplica', 'sin (?:\\p{L}+)(?: \\p{L}+)?', 'no (?:tengo|hay|tiene|tenemos)(?: (?:ninguno|ninguna|uno|una))?(?: \\p{L}+){0,3}',
|
|
328
|
+
].join('|') + ')$', 'iu');
|
|
329
|
+
export function saysNoValue(answer) {
|
|
330
|
+
const text = String(answer ?? '').trim().toLowerCase().replace(/[.!¡¿?,;:]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
331
|
+
return !!text && !/\d/.test(text) && NO_VALUE.test(text);
|
|
332
|
+
}
|
|
319
333
|
export function readFormAnswer(answer, candidates, current, choiceKey, questions = []) {
|
|
320
334
|
const raw = unescape(answer), parts = raw.split(/([?;\n]|\b(?:and|y)\b)/i), asked = [];
|
|
321
335
|
let consumed = false;
|
|
@@ -343,6 +357,9 @@ export function matchInputs(answer, candidates, current, choiceKey) {
|
|
|
343
357
|
const isCur = (c) => (Array.isArray(cur.names) ? cur.names.indexOf(c.name) > -1 : c.name === cur.name) && (cur.form === undefined || c.form === cur.form);
|
|
344
358
|
const narrativeCurrent = list.some(field => isCur(field) && ['text', 'choice'].includes(field.profile.kind) && field.profile.narrative === true);
|
|
345
359
|
const own = Array.isArray(cur.names) ? undefined : list.filter(isCur)[0]; // a group has no single own choice list
|
|
360
|
+
// The asked input is declinable and the whole answer says there is none: answered, with no value (an explicit null).
|
|
361
|
+
if (own && own.declinable === true && saysNoValue(raw))
|
|
362
|
+
return { hits: [{ form: own.form, name: own.name, value: null, declined: true, known: Object.prototype.hasOwnProperty.call(own, 'value') && own.value === null }], ambiguous: [] };
|
|
346
363
|
// A form's scope level: 0 for the current input's form, then each further form in the order the chain lists them.
|
|
347
364
|
const forms = [];
|
|
348
365
|
if (own) {
|
package/dist/runtime-identity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSFE_RUNTIME_FINGERPRINT = "sha256:
|
|
1
|
+
export const JSFE_RUNTIME_FINGERPRINT = "sha256:20a0b00343fbccb8342d26b3a560a7217075daef050aef2edc7b1a765742ec12";
|
|
@@ -185,6 +185,7 @@ Field options:
|
|
|
185
185
|
| `response` | `{description}` on a readable leaf; use existing contextual DISPATCH extraction before accepting an open-ended answer. |
|
|
186
186
|
| `proposal` | Optional approval of an inferred field candidate, independent of final action consent. |
|
|
187
187
|
| `max_misses`, `max_attempts`, `on_exhausted` | Bounds for unreadable responses, validator rejections and deliberate branch recovery. |
|
|
188
|
+
| `declinable` | `true` on a readable leaf (not a choice, a confirmation or a proposal): the field may be answered "there is none". The whole answer saying so, in English or Spanish (`none`, `no`, `n/a`, `I don't have one`, `no tengo…`, `no hay…`, `ninguno`; never with a digit), stores an explicit `null`: answered, with no value, so the form moves on, while an absent key stays unanswered. The reply ranker is offered `none` at its question, and a read-back with `named_fields` offers it for correction. On a card the field may be left blank. A field that is never asked uses `required_when` instead. |
|
|
188
189
|
|
|
189
190
|
Profiles:
|
|
190
191
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsfe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.51.0",
|
|
4
4
|
"description": "TypeScript workflow engine for conversational/automation apps: multi-flow orchestration, interrupt/resume, stack-based control, robust errors, and flexible tool/REST integration.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ron Pinkas",
|