jsfe 1.101.5 → 1.102.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)
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); a form's `introduction` heads the card since 1.102.0
18
18
  - **[Sendables](docs/sendables.md)** - what a flow can send the caller (registered sendables and their media) and how a host delivers it
19
19
  - **[Engine internals](docs/engine-internals.md)** - how the engine runs a turn: stacks, the form loop, attempts, queued lines and every exit
20
20
  - **[Template interpolation design notes](docs/template-interpolation-design-notes.md)** - how `{{...}}` templates are resolved
@@ -464,6 +464,11 @@ question asked again ("Sorry, I didn't catch that. " / "Disculpe, no le entendí
464
464
  and the provider menu. A flow set that sets `cargo.sorryByName = true` (for example once the caller is verified) gets it with
465
465
  `cargo.displayName` ("Disculpe, Ana, no le entendí. "); without it the wording is unchanged.
466
466
 
467
+ **A form's introduction (jsfe 1.102.0, owner 2026-12-03):** `introduction` / `introduction_es` on a form is plain text (a `{{...}}`
468
+ fails at definition time; without the Spanish the text is said as written) said once for the form instance, before `before` and
469
+ the first question. `projectForm` carries it as `introduction`, with `question` when the reply asks the input's declared question
470
+ in exactly its words, so a client draws both on its card and leaves them out of the message (docs/form-client.md).
471
+
467
472
  **Acknowledging only data, opt-in (jsfe 1.20.0):** a form declaring `acknowledge: 'data'` (or the nearest enclosing form
468
473
  that declares it) says "Got it, your …" / "Okay, I noted your …" only for a value the caller supplied, an input whose profile
469
474
  kind is digits, email, phone, amount, identifier, account or text. A pick among offered words (`choice`, `pattern`), such as
@@ -4,7 +4,7 @@ import { linkFormSchemas, validateFlowContracts } from './contracts.js';
4
4
  import { compileFormPrompts } from './prompt-compiler.js';
5
5
  import { withSafetyRevision } from './continuation-safety.js';
6
6
  import { capturedAuthorSpec, copyAuthorSpec, authoredExpressions } from './declaration-capture.js';
7
- const formKeys = new Set(['inputs', 'before', 'after', 'confirm', 'before_confirm', 'declined', 'stop', 'close_on_stop', 'resume_on_parent_change', 'done', 'validator', 'confirmation_condition', 'prompt', 'prompt_es', 'incomplete_outcome', 'on_exhausted', 'on_no', 'must_complete', 'first_task', 'first_task_es', 'user_description', 'user_description_es', 'acknowledge']);
7
+ const formKeys = new Set(['inputs', 'before', 'after', 'confirm', 'before_confirm', 'declined', 'stop', 'close_on_stop', 'resume_on_parent_change', 'done', 'validator', 'confirmation_condition', 'prompt', 'prompt_es', 'incomplete_outcome', 'on_exhausted', 'on_no', 'must_complete', 'first_task', 'first_task_es', 'user_description', 'user_description_es', 'introduction', 'introduction_es', 'acknowledge']);
8
8
  const sharedKeys = ['id', 'name', 'description', 'version', 'scope', 'primary', 'parameters', 'contract', 'parameterInstructions'];
9
9
  const safe = /^[A-Za-z_$][\w$]*$/;
10
10
  const fail = message => { throw new Error('Flow declaration: ' + message); };
@@ -17,7 +17,7 @@ export function validateRankParameters(id: any, name: any, what: any, list: any)
17
17
  * confirmation is soft, a plain form's (no action) included (owner 2026-11-09). confirm.exact is separate: it binds the
18
18
  * action to the confirmed values, whatever the confirmation's firmness. */
19
19
  export function confirmationFirmness(performs: any): "firm" | "soft";
20
- export function formFlow({ id, name, version, description, inputs, after, extraVars, parameters, confirm, confirm_soft, before_confirm, declined, stop, close_on_stop, on_no, resume_on_parent_change, before, done, primary, scope, validator, confirmation_condition, prompt, prompt_es, incomplete_outcome, on_exhausted, must_complete, first_task, first_task_es, user_description, user_description_es, acknowledge }: {
20
+ export function formFlow({ id, name, version, description, inputs, after, extraVars, parameters, confirm, confirm_soft, before_confirm, declined, stop, close_on_stop, on_no, resume_on_parent_change, before, done, primary, scope, validator, confirmation_condition, prompt, prompt_es, incomplete_outcome, on_exhausted, must_complete, first_task, first_task_es, user_description, user_description_es, introduction, introduction_es, acknowledge }: {
21
21
  id: any;
22
22
  name: any;
23
23
  version: any;
@@ -49,6 +49,8 @@ export function formFlow({ id, name, version, description, inputs, after, extraV
49
49
  first_task_es?: string | undefined;
50
50
  user_description?: string | undefined;
51
51
  user_description_es?: string | undefined;
52
+ introduction?: string | undefined;
53
+ introduction_es?: string | undefined;
52
54
  acknowledge?: string | undefined;
53
55
  }): {
54
56
  variables: {
@@ -1 +1 @@
1
- {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AAqIA;;;;;;;GAOG;AACH;;;;GAIG;AACH,8HAA8H;AAC9H,uFAIC;AAsGD;;2EAE2E;AAC3E,qEAEC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2EC;AACD;;;GAGG;AACH;;;;;;EAGC;AAsoBD,wHAAwH;AACxH,wEAaC;AACD,4FAA4F;AAC5F;;;EAYC;AACD,sGAAsG;AACtG;;;EAOC;AAv9BM,6CAAuG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2J9G,4CAEqI;AA4hCrI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOG"}
@@ -291,8 +291,13 @@ function validateFormClientControls(id, inputs) {
291
291
  export function confirmationFirmness(performs) {
292
292
  return Array.isArray(performs) && performs.some((action) => action?.effect === 'charge') ? 'firm' : 'soft';
293
293
  }
294
- export function formFlow({ id, name, version, description, inputs, after = [], extraVars = {}, parameters = [], confirm = null, confirm_soft = confirmationFirmness([]) === 'soft', before_confirm = [], declined = [], stop = '', close_on_stop = false, on_no = '', resume_on_parent_change = false, before = [], done = true, primary = false, scope = 'isolated', validator = '', confirmation_condition = 'true', prompt = undefined, prompt_es = undefined, incomplete_outcome = null, on_exhausted = null, must_complete = false, first_task = '', first_task_es = '', user_description = '', user_description_es = '', acknowledge = 'all' }) {
294
+ export function formFlow({ id, name, version, description, inputs, after = [], extraVars = {}, parameters = [], confirm = null, confirm_soft = confirmationFirmness([]) === 'soft', before_confirm = [], declined = [], stop = '', close_on_stop = false, on_no = '', resume_on_parent_change = false, before = [], done = true, primary = false, scope = 'isolated', validator = '', confirmation_condition = 'true', prompt = undefined, prompt_es = undefined, incomplete_outcome = null, on_exhausted = null, must_complete = false, first_task = '', first_task_es = '', user_description = '', user_description_es = '', introduction = '', introduction_es = '', acknowledge = 'all' }) {
295
295
  validateFormExhaustion(on_exhausted);
296
+ for (const [key, text] of Object.entries({ introduction, introduction_es }))
297
+ if (typeof text !== 'string' || text.includes('{{'))
298
+ throw new Error(`FORM ${id}: ${key} must be plain text`);
299
+ if (introduction_es && !introduction)
300
+ throw new Error(`FORM ${id}: introduction_es needs introduction`);
296
301
  if (acknowledge !== 'all' && acknowledge !== 'data')
297
302
  throw new Error(`FORM ${id}: acknowledge must be 'all' or 'data'`);
298
303
  if (on_no !== '' && (typeof on_no !== 'string' || !/^[\w-]+$/.test(on_no)))
@@ -347,6 +352,9 @@ export function formFlow({ id, name, version, description, inputs, after = [], e
347
352
  SIDE(`${id}_pass_reset`, '(cargo.forms[form_instance].replays = 0, form_internal_resume ? true : (cargo.forms[form_instance].attempts = {},cargo.forms[form_instance].misses={},cargo.forms[form_instance].feedback={}), true)'),
348
353
  SET(`${id}_arguments`, 'form_arguments', `rememberFormArguments(cargo.forms[form_instance], currentContext, ${JSON.stringify(parameters.filter(p => !p.internal && !/^internal\b/i.test(p.description || '')).map(p => p.name))}, form_internal_resume)`),
349
354
  ...parameters.filter(p => !p.internal && !/^internal\b/i.test(p.description || '')).map(p => SET(`${id}_restore_${p.name}`, p.name, `form_internal_resume ? form_arguments[${JSON.stringify(p.name)}] : currentContext[${JSON.stringify(p.name)}]`)),
355
+ // The introduction is said once for an instance, before anything the form does; a card shows it itself (projectForm).
356
+ ...(introduction ? [WHEN(`${id}_introduce`, '!cargo.forms[form_instance].introduction', SAY(`${id}_introduction`, introduction, introduction_es || introduction)),
357
+ SIDE(`${id}_introduced`, `(cargo.forms[form_instance].introduction = ${JSON.stringify({ en: introduction, es: introduction_es || introduction })}, true)`)] : []),
350
358
  ...before,
351
359
  SET(`${id}_initial`, 'initial_readings', 'form_internal_resume ? [] : formInitialReadings(cargo.forms[form_instance], currentContext, cargo)'),
352
360
  WHEN(`${id}_accept_initial`, 'initial_readings.length > 0', FLOW(`${id}_initial_accept`, 'collect-input-accept', 'call', { hits: '{{initial_readings}}' })),
@@ -1,9 +1,23 @@
1
1
  /** A public rendering projection, never a serialized flow, executable expression, or session. */
2
2
  export function projectForm(session: any, flows: any): {
3
+ fields: any;
4
+ question: string;
5
+ introduction: any;
6
+ version: number;
7
+ form: any;
8
+ language: any;
9
+ } | {
10
+ fields: any;
11
+ question?: undefined;
12
+ introduction: any;
3
13
  version: number;
4
14
  form: any;
5
15
  language: any;
16
+ } | {
6
17
  fields: any;
18
+ version: number;
19
+ form: any;
20
+ language: any;
7
21
  } | null;
8
22
  /**
9
23
  * The options of the question asked now, when it has a closed, labelled set, for a client that draws them as buttons or a list:
@@ -1 +1 @@
1
- {"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AAiCA,iGAAiG;AACjG;;;;;SA4HC;AAMD;;;;;;;;GAQG;AACH;;;;;;;;SAoBC;AAED;;;;yGAIyG;AACzG,oDAyBC;AACD,+GAA+G;AAC/G;wHACwH;AACxH,qEAWC;AAED;;;;SA4CC;AAED;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDC;AAlVD,qCAAsC,eAAe,CAAC"}
1
+ {"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AA0CA,iGAAiG;AACjG;;;;;;;;;;;;;;;;;;;SA6HC;AAMD;;;;;;;;GAQG;AACH;;;;;;;;SAoBC;AAED;;;;yGAIyG;AACzG,oDAyBC;AACD,+GAA+G;AAC/G;wHACwH;AACxH,qEAWC;AAED;;;;SA4CC;AAED;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDC;AA5VD,qCAAsC,eAAe,CAAC"}
@@ -25,8 +25,16 @@ const pendingForm = session => {
25
25
  return null;
26
26
  state = parent;
27
27
  }
28
- return { state, context };
28
+ return { state, context, frame };
29
29
  };
30
+ /** The question asked now, when it is exactly the one its input declares. With anything else in it (a refusal, an
31
+ * acknowledgment, a computed wording) the card does not stand for it and it is left out. */
32
+ function askedPlainly(frame, root, context, language) {
33
+ const input = root.id === context.form && (root.specs || []).find(spec => spec.name === context.current);
34
+ const words = source => source ? (language === 'es' ? source.question_es || source.question : source.question) : undefined;
35
+ const asked = words(frame.variables);
36
+ return typeof asked === 'string' && asked && asked === words(input) ? { question: asked } : {};
37
+ }
30
38
  /** Today in an IANA time zone, moved by whole days, as YYYY-MM-DD (UTC arithmetic: no DST shift). */
31
39
  function daysFromToday(days, timeZone) {
32
40
  const [year, month, day] = new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()).split('-').map(Number);
@@ -42,7 +50,7 @@ export function projectForm(session, flows) {
42
50
  const pending = pendingForm(session);
43
51
  if (!pending)
44
52
  return null;
45
- const { state: root, context } = pending, cargo = session.cargo, language = session.language || 'en';
53
+ const { state: root, context, frame } = pending, cargo = session.cargo, language = session.language || 'en';
46
54
  // Both the code field and its free-text fallback can contain the one-time code.
47
55
  const collectingOtp = session.flowStacks.flat().some(frame => frame.flowId === 'get-and-validate-otp-code');
48
56
  let askedShown = false;
@@ -190,7 +198,8 @@ export function projectForm(session, flows) {
190
198
  const plain = field => field.kind !== 'choice' && !field.control && !field.sensitive;
191
199
  if (leaves.length === 1 && plain(leaves[0]))
192
200
  return null;
193
- return { version: 1, form: root.id, language, fields: projected };
201
+ const introduction = root.introduction && String(language === 'es' ? root.introduction.es : root.introduction.en);
202
+ return { version: 1, form: root.id, language, ...(introduction ? { introduction, ...askedPlainly(frame, root, context, language) } : {}), fields: projected };
194
203
  }
195
204
  const STANDARD_LABELS = { yes: { en: 'Yes', es: 'Sí' }, no: { en: 'No', es: 'No' } };
196
205
  const MAX_CHOICE_OPTIONS = 12;
@@ -1 +1 @@
1
- export const JSFE_RUNTIME_FINGERPRINT = "sha256:9a448c75606040e83a5e77050944a8ee30e01f4db45addc43496930b3537b5b7";
1
+ export const JSFE_RUNTIME_FINGERPRINT = "sha256:f22f72d7d7656766155745899dc3b0d3ad38c4648b35d208b4400c65214b0d93";
@@ -300,6 +300,11 @@ does this reply do with the question the flow asked? The model picks from a clos
300
300
  expressions, its inputs in scope, '' until answered); the nearest form in the chain that declares one is used. It is never offered at a reason question. A
301
301
  top-scoring `concern` (cut 0.6) wins over a cleared choice.
302
302
 
303
+ **Introducing a form.** A form declares `introduction` / `introduction_es` (plain text, jsfe 1.102.0): what the caller is told
304
+ before its first question, such as why the information is asked. It is said once for that form, never again when the form
305
+ resumes, runs again after a change or asks a field again. On the web a card that draws the form shows it at its top, in place of
306
+ a message above the card; every other channel says it. A SAY in `before` is only ever a message: a card cannot show it.
307
+
303
308
  **Options with arguments.** A declared choice may carry `parameters` (`{name,type,description}`): a pick then extracts them from the reply with the same stage as a flow's parameters, and the flow reads `{ key, arguments }`. The pick stands when extraction finds nothing or fails. The ranker is generic, so the flow supplies the context: a form's `confirm.reply_context` says what a reply may contain. The address read-back uses this: "It's Long Beach, apartment 4" changes the city and the apartment and reads the address back, with no further question.
304
309
 
305
310
  ### Arguments in free-form answers
@@ -128,6 +128,7 @@ A form declaration has top-level common fields and `form:{inputs:[...]}`. Do not
128
128
  | Option | Meaning |
129
129
  | --- | --- |
130
130
  | `inputs` | Ordered field/group/sub-form declarations. Order controls which ready missing field is asked next, not which fields may be accepted. |
131
+ | `introduction`, `introduction_es` | Plain text said once before the first question; a web card shows it at its top. |
131
132
  | `before`, `after` | Ordinary step arrays before collection and after completed collection/confirmation. |
132
133
  | `validator` | Whole-form validation worker, called with `{form,values}`. |
133
134
  | `confirm`, `before_confirm`, `declined` | Confirmation descriptor, preceding steps and declined step array. |
@@ -282,6 +283,8 @@ An unreadable answer with any words goes to the reply ranker, offered the questi
282
283
 
283
284
  **Yes/no keys.** Every yes/no question names 1 for YES and 2 for NO on a call; word it with `yesNoKeys(lang, cargo, yes?, no?)` rather than by hand: voice "Press 1 or say YES to submit it, or press 2 or say NO.", text "Type YES to submit it, or type NO." (Spanish SÍ, "Presione 1 o diga", "escriba"). `channelVerb(lang, cargo, capital?)` gives the verb alone: the host's `cargo.verb` / `cargo.verb_es`, else "say" on a call and "type" elsewhere. On a form confirmation, key 1 confirms and key 2 declines on every channel.
284
285
 
286
+ `introduction` / `introduction_es` on a form (jsfe 1.102.0): plain text said once, before its first question. A web card shows it at its top in place of the message. Write it here, not as a SAY in `before`, which a card cannot draw.
287
+
285
288
  `must_complete:true` on a form (inherited by every field of it and of the forms nested in it) or on one field (`false` on a field opts out): an unreadable answer is never yielded to DISPATCH, however long, and neither is a confirmation miss or an unresolved ambiguity — the question is asked again, acknowledged. A worded reply always reaches the reply ranker, offered every choice the chain's reader accepts: a pick is taken, a clear withdrawal ends the flows, and any other verdict (a new request included) stays and says `first_task` / `first_task_es` from the nearest form declaring it, "I understand, first let's enter your new card details." / "Entiendo, primero vamos a ingresar los datos de su tarjeta nueva.", then the field's `retry` or its question. It uses no attempt. Use it where leaving would strand an effect in progress (a payment's card, its billing-ZIP correction). Other exits stay explicit: the form's stop words, `max_attempts` with `on_exhausted`, and whatever the host intercepts before the engine. The form runaway guard counts passes without a caller answer only.
286
289
 
287
290
  `confirm.named_fields: true` lets a caller correct a read-back in their own words: each input of this form that declares `names` and holds a value is offered to the reply ranker, and a pick extracts the new value of every such input, so one reply can change several. `confirm.reply_context` tells the ranker and the extraction what a reply may contain (never spoken); an input's `argument_description` says what its value looks like ("apartment or unit number alone, such as 4 or 12B"). A reply the word readers only partly account for goes to the ranker, so none of it is lost.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfe",
3
- "version": "1.101.5",
3
+ "version": "1.102.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",