jsfe 1.48.0 → 1.50.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 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, narrowed by other fields (`context`) since 1.47.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,7 +17,7 @@ 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'], context: ['zip'] } },
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
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.' }],
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?' },
@@ -1 +1 @@
1
- {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AAgHA;;;;;;;GAOG;AACH;;;;GAIG;AACH,8HAA8H;AAC9H,uFAIC;AA2ED;;2EAE2E;AAC3E,qEAEC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyEC;AACD;;;GAGG;AACH;;;;;;EAGC;AAolBD,wHAAwH;AACxH,wEAaC;AACD,4FAA4F;AAC5F;;;EAYC;AACD,sGAAsG;AACtG;;;EAOC;AAn3BM,6CAAuG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6kC9G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOG"}
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;AA+kBD,wHAAwH;AACxH,wEAaC;AACD,4FAA4F;AAC5F;;;EAYC;AACD,sGAAsG;AACtG;;;EAOC;AAh2BM,6CAAuG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAujC9G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOG"}
@@ -10,8 +10,8 @@ import { CONTEXTUAL_RESPONSES_REQUIREMENT, hasFormResponse, contextualResponseRu
10
10
  *
11
11
  * Collection: run-form (the reentrant loop, shared scope), collect-input (ask one input, read the answer against the
12
12
  * form chain), collect-input-accept (validate + store, one reading at a time), disambiguate-input,
13
- * form-done (hand the result to the parent, clear the form), the field collectors (collect-phone…) and
14
- * the sub-forms collect-address and collect-credit-card, validate-card-number / validate-card-expiration.
13
+ * form-done (hand the result to the parent, clear the form), the sub-forms collect-address and
14
+ * collect-credit-card, validate-card-number / validate-card-expiration.
15
15
  * Retrieval: provide-data (gate → load → answer), load-source, answer-facts.
16
16
  *
17
17
  * State lives in cargo.forms[<form id>] = { values, attempts, replays, parent, result_input, specs }: cargo is the only
@@ -99,10 +99,6 @@ export const FIELD_PRESETS = {
99
99
  confirm_out_of_order: { word: 'ZIP', word_es: 'CÓDIGO POSTAL', message: 'If {value} is the billing ZIP code of the card, add the word {word}.', message_es: 'Si {value} es el código postal de facturación de la tarjeta, agregue las palabras {word}.' },
100
100
  question: 'What is the billing ZIP code for the card?', question_es: '¿Cuál es el código postal de facturación de la tarjeta?' },
101
101
  };
102
- // Field collectors: one-input forms over a preset, callable directly (result in cargo.formResults[<id>]).
103
- const FIELD_COLLECTORS = { 'collect-phone': 'phone', 'collect-email': 'email', 'collect-zip': 'zip', 'collect-street-address': 'street_address',
104
- 'collect-city': 'city', 'collect-card-number': 'card_number', 'collect-card-expiration': 'card_expiration', 'collect-card-cvv': 'card_cvv',
105
- 'collect-card-zip': 'card_zip' };
106
102
  // ── a form flow (the shape every form follows; tenant forms are written the same way) ──────────────────────────────
107
103
  /**
108
104
  * The form shell: declare inputs, run the loop, hand the result on. `after` = the form's own steps once complete.
@@ -154,10 +150,9 @@ function validateAcceptanceDeclarations(id, inputs) {
154
150
  * regions?}. A date's min and max are whole days from today in `timezone` (required with either); range_from names the
155
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
156
152
  * place suggests what the caller types from the host's place service: types 'cities' or 'address', regions up to 15
157
- * ISO 3166-1 alpha-2 country codes, context up to 5 other inputs of this form whose values narrow the lookup (a ZIP code
158
- * for a street). Checked at definition time; malformed fails.
153
+ * ISO 3166-1 alpha-2 country codes. Checked at definition time; malformed fails.
159
154
  */
160
- const FORM_CLIENT_KEYS = { date: ['control', 'range_from', 'min', 'max', 'timezone'], number: ['control', 'min', 'max'], place: ['control', 'types', 'regions', 'context'] };
155
+ const FORM_CLIENT_KEYS = { date: ['control', 'range_from', 'min', 'max', 'timezone'], number: ['control', 'min', 'max'], place: ['control', 'types', 'regions'] };
161
156
  const FORM_CLIENT_KINDS = ['pattern', 'text', 'digits', 'amount', 'identifier'];
162
157
  const FORM_PLACE_KINDS = ['pattern', 'text'];
163
158
  const FORM_PLACE_TYPES = ['cities', 'address'];
@@ -215,19 +210,6 @@ function validateFormClientControls(id, inputs) {
215
210
  !declared.regions.every((region) => typeof region === 'string' && /^[a-z]{2}$/i.test(region))))
216
211
  fail(input, 'regions must be 1 to 15 two-letter country codes');
217
212
  else { /* any region, or a valid list */ }
218
- if (declared.context !== undefined) {
219
- if (!Array.isArray(declared.context) || !declared.context.length || declared.context.length > 5)
220
- fail(input, 'context must list 1 to 5 inputs of this form');
221
- for (const name of declared.context) {
222
- const other = all.find((candidate) => candidate.name === name);
223
- if (!other || other === input)
224
- fail(input, `context ${JSON.stringify(name)} must name another input of this form`);
225
- else if (other.pii === true)
226
- fail(input, `context ${name} is a sensitive input`);
227
- else { /* a field whose value narrows the lookup */ }
228
- }
229
- }
230
- else { /* no context */ }
231
213
  }
232
214
  else { /* a number */ }
233
215
  }
@@ -889,12 +871,7 @@ const validators = [
889
871
  parameters: [{ name: 'input', type: 'string', description: 'input name' }, { name: 'value', type: 'string', description: 'the reading' }, { name: 'values', type: 'object', description: "the form's values, for the card number" }],
890
872
  steps: [SIDE('vcc_check', "(function (v, n) { var d = String(v).replace(/\\D/g, ''); var pan = String(n || '').replace(/\\D/g, ''); var want = pan ? (/^3[47]/.test(pan) ? 4 : 3) : 0; var ok = want ? d.length === want : d.length === 3 || d.length === 4; cargo.inputCheck = ok ? { ok: true, value: d } : want === 4 ? { ok: false, message: \"That security code doesn't look right. It is the 4 digits on the front of the card.\", message_es: 'Ese código de seguridad no parece correcto. Son los 4 dígitos al frente de la tarjeta.' } : { ok: false, message: \"That security code doesn't look right. It is the 3 digits on the back of the card.\", message_es: 'Ese código de seguridad no parece correcto. Son los 3 dígitos al reverso de la tarjeta.' }; return true; })(value, typeof values !== 'undefined' && values ? values.card_number : '')")] },
891
873
  ];
892
- // ── field collectors and sub-forms ──────────────────────────────────────────────────────────────────────────────────
893
- const fieldCollectors = Object.entries(FIELD_COLLECTORS).map(([id, field]) => formFlow({
894
- id, name: id.split('-').map((w) => w[0].toUpperCase() + w.slice(1)).join(''), version: '1.0.0',
895
- description: `Field collector: the ${FIELD_PRESETS[field].label} (preset '${field}'). Result: cargo.formResults['${id}'].${field}.`,
896
- inputs: [{ name: field, field }],
897
- }));
874
+ // ── sub-forms ──────────────────────────────────────────────────────────────────────────────────
898
875
  const subForms = [
899
876
  formFlow({ id: 'collect-address', name: 'CollectAddress', version: '1.0.0',
900
877
  description: "Sub-form: street address, city, state, ZIP, in any order. Result: the parent's result input (or cargo.formResults['collect-address']).",
@@ -1157,7 +1134,7 @@ const resumeForm = { id: 'resume-form', name: 'ResumeForm', version: '1.0.0', sc
1157
1134
  SET('resume_definition', 'target', 'cargo.forms[form].definition'), SET('resume_parent', 'parent', "cargo.forms[form].parent || ''"), SET('resume_slot', 'slot', "cargo.forms[form].result_input || ''"),
1158
1135
  FLOW('resume_owned_form', '{{target}}', 'replace', { form_instance: '{{form}}', parent_form: '{{parent}}', result_input: '{{slot}}' })
1159
1136
  ] };
1160
- const LIBRARY_FLOWS = [providerUnanswered, readProviderReply, readFormChoice, readConfirmReply, confirmInputProposal, proposalDeclined, resumeForm, performAction, sendTextAction, prepareInput, runForm, collectInput, validateBatch, requestCancelled, readFormResponse, collectContextualAnswer, accept, acceptedEffects, disambiguate, confirmForm, formDone, providerMenu, ...validators, ...fieldCollectors, ...subForms, provideData, provideQueuedData, loadSource, answerFacts];
1137
+ const LIBRARY_FLOWS = [providerUnanswered, readProviderReply, readFormChoice, readConfirmReply, confirmInputProposal, proposalDeclined, resumeForm, performAction, sendTextAction, prepareInput, runForm, collectInput, validateBatch, requestCancelled, readFormResponse, collectContextualAnswer, accept, acceptedEffects, disambiguate, confirmForm, formDone, providerMenu, ...validators, ...subForms, provideData, provideQueuedData, loadSource, answerFacts];
1161
1138
  const LIBRARY_CONTRACTS = {
1162
1139
  'confirm-input-proposal': { role: 'collector', requires: [INPUT_PROPOSALS_REQUIREMENT] }, 'confirm-input-proposal-declined': { role: 'worker', requires: [INPUT_PROPOSALS_REQUIREMENT] },
1163
1140
  'resume-form': { role: 'worker' },
@@ -1176,9 +1153,6 @@ const LIBRARY_CONTRACTS = {
1176
1153
  'validate-card-number': { role: 'worker', result: { path: 'cargo.inputCheck', type: 'object' } },
1177
1154
  'validate-card-expiration': { role: 'worker', result: { path: 'cargo.inputCheck', type: 'object' } },
1178
1155
  'validate-card-cvv': { role: 'worker', result: { path: 'cargo.inputCheck', type: 'object' } },
1179
- 'collect-phone': { role: 'collector' }, 'collect-email': { role: 'collector' }, 'collect-zip': { role: 'collector' },
1180
- 'collect-street-address': { role: 'collector' }, 'collect-city': { role: 'collector' }, 'collect-card-number': { role: 'collector' },
1181
- 'collect-card-expiration': { role: 'collector' }, 'collect-card-cvv': { role: 'collector' }, 'collect-card-zip': { role: 'collector' },
1182
1156
  'collect-address': { role: 'collector' }, 'collect-credit-card': { role: 'collector' }
1183
1157
  };
1184
1158
  export const FLOWS = LIBRARY_FLOWS.map(flow => {
@@ -1 +1 @@
1
- {"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AAiCA,iGAAiG;AACjG;;;;;SA2FC;AAED,+GAA+G;AAC/G;wHACwH;AACxH,qEAWC;AAED;;;;SAgCC;AAED;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BC;AA3MD,qCAAsC,eAAe,CAAC"}
1
+ {"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AAiCA,iGAAiG;AACjG;;;;;SA0FC;AAED,+GAA+G;AAC/G;wHACwH;AACxH,qEAWC;AAED;;;;SAgCC;AAED;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BC;AA1MD,qCAAsC,eAAe,CAAC"}
@@ -122,8 +122,7 @@ 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 */ }
129
128
  if (!field.sensitive && ['string', 'number', 'boolean'].includes(typeof state.values?.[input.name]))
@@ -1 +1 @@
1
- export const JSFE_RUNTIME_FINGERPRINT = "sha256:f2f3837d791750331ec451959674b066ae943952b83dcd312f057f65e7d44b48";
1
+ export const JSFE_RUNTIME_FINGERPRINT = "sha256:3d77bb664db3e526a638ace68f03116c07d669b06d89c6ab3255fe6f84cb7790";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfe",
3
- "version": "1.48.0",
3
+ "version": "1.50.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",