jsfe 1.97.0 → 1.99.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
@@ -966,6 +966,8 @@ See the [retry/yield/recovery contract](docs/copilot-reference.md#retry-yield-an
966
966
 
967
967
  ### Host Responsibilities: Tool Calls, Cancellation and Concurrency
968
968
 
969
+ > Transfer departments (`transfer-to-line`): the host stamps `cargo.transferLines` and consumes `cargo.transferTo`, see [docs/transfer-lines.md](docs/transfer-lines.md).
970
+
969
971
  A flow can take actions in the outside world through `CALL-TOOL` — charge a card, send an SMS,
970
972
  create a ticket. For ordinary `CALL-TOOL` flows, **the session returned by `updateActivity` records
971
973
  which steps already ran**; the host owns its persistence. Native performers can additionally use an
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forms/index.js"],"names":[],"mappings":"AAOA,0BAA8J"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forms/index.js"],"names":[],"mappings":"AAQA,0BAA+K"}
@@ -5,7 +5,8 @@ import { FLOWS as FORM_FLOWS } from './flows.js';
5
5
  import { FLOWS as CHOICE_FLOWS } from './choice-flow.js';
6
6
  import { FLOWS as IDENTITY } from './identity-flows.js';
7
7
  import { FLOWS as SEND_COPY } from './send-copy-flow.js';
8
- export const FLOWS = [...FORM_FLOWS, ...ADDRESS_FLOWS, ...CHOICE_FLOWS, ...IDENTITY, ...SEND_COPY].map(flow => withSafetyRevision(flow, 'dispatch-intake-2026-10-22'));
8
+ import { FLOWS as TRANSFER_LINE } from './transfer-line-flow.js';
9
+ export const FLOWS = [...FORM_FLOWS, ...ADDRESS_FLOWS, ...CHOICE_FLOWS, ...IDENTITY, ...SEND_COPY, ...TRANSFER_LINE].map(flow => withSafetyRevision(flow, 'dispatch-intake-2026-10-22'));
9
10
  export { FIELD_PRESETS, formFlow, declinedFlow, textValue, confirmationFirmness } from './flows.js';
10
11
  export { FLOWS as IDENTITY_FLOWS } from './identity-flows.js';
11
12
  export { linkFormSchemas, defineWorker, defineProvider, defineForm, definePerformer, validateFlowContracts, operationWorkers, providerQuestions, providerParameter } from './contracts.js';
@@ -1 +1 @@
1
- {"version":3,"file":"send-copy-flow.d.ts","sourceRoot":"","sources":["../../src/forms/send-copy-flow.js"],"names":[],"mappings":"AAsOA,0BAAmD"}
1
+ {"version":3,"file":"send-copy-flow.d.ts","sourceRoot":"","sources":["../../src/forms/send-copy-flow.js"],"names":[],"mappings":"AAwOA,0BAAmD"}
@@ -30,8 +30,9 @@ const when = (id, condition, step) => ({ id, type: 'CASE', branches: { [`conditi
30
30
  const say = (id, value, value_es) => ({ id, type: 'SAY', value, value_es });
31
31
  const end = (id, extra = {}) => ({ id, type: 'END', ...extra });
32
32
  const call = (id, value, parameters) => ({ id, type: 'FLOW', value, callType: 'call', ...(parameters ? { parameters } : {}) });
33
- const ANYTHING_ELSE = ' Is there anything else I can help you with?';
34
- const ANYTHING_ELSE_ES = ' ¿Hay algo más en lo que le pueda ayudar?';
33
+ // The closing question, unless the calling flow continues the conversation itself (no_closing; owner 2026-11-28).
34
+ const ANYTHING_ELSE = "{{typeof no_closing !== 'undefined' && (no_closing === true || no_closing === 'true') ? '' : ' Is there anything else I can help you with?'}}";
35
+ const ANYTHING_ELSE_ES = "{{typeof no_closing !== 'undefined' && (no_closing === true || no_closing === 'true') ? '' : ' ¿Hay algo más en lo que le pueda ayudar?'}}";
35
36
  const TEXT_WORDS = ['1', 'text', 'texto', 'sms', 'message', 'text message', 'mensaje', 'mensaje de texto'];
36
37
  // A text message is one message: Twilio rejects a body over 1,600 characters (error 21617), so longer content goes by email.
37
38
  const TEXT_MAX = 1600;
@@ -51,6 +52,7 @@ const sendCopy = defineWorker({
51
52
  { name: 'item', type: 'string', enum_from: 'sendables', description: "What the user asks to have sent: the reply or document they name or point to. 'That', 'it', 'this', 'eso' or 'lo que me dijo' is the latest reply; the whole chat, conversation or transcript ('toda la conversación') is the whole conversation; continuing on the web, a computer or another device is the link to continue on the web." },
52
53
  { name: 'medium', type: 'string', enum: ['text', 'email'], description: "How the user asks to have it sent: text for a text message or SMS ('mensaje', 'texto'), email for an email ('correo')." },
53
54
  { name: 'destination', type: 'string', description: 'The phone number or email address the user gave to send it to, as given.' },
55
+ { name: 'no_closing', type: 'boolean', internal: true, description: 'Internal: true when the calling flow continues the conversation itself, so no closing question is asked.' },
54
56
  { name: 'other_destination', type: 'boolean', description: "true when the user asks to send it to a different, new or other phone number or email than their own, without saying what it is ('another number', 'a different email', 'otro número', 'a mi otro correo'); false when they give the number or email, or name none." },
55
57
  ],
56
58
  variables: vars({
@@ -188,7 +190,7 @@ const sendCopy = defineWorker({
188
190
  // another email address or phone number: SendCopy again with it, so it is read back in its turn
189
191
  when('sc_corrected', "!sc_trusted && (cargo.choice === 'email' || cargo.choice === 'text')", set('sc_corrected_set', 'sc_given', `cargo.choice === 'email' ? ${EMAIL_IN_JS}(cargo.choiceText) : readPhone(String(cargo.choiceText || ''))`)),
190
192
  when('sc_corrected_medium', "!sc_trusted && (cargo.choice === 'email' || cargo.choice === 'text')", set('sc_corrected_medium_set', 'sc_medium', 'cargo.choice')),
191
- when('sc_corrected_again', "!sc_trusted && !!sc_given && (sc_medium === 'email' || sc_medium === 'text') && (cargo.choice === 'email' || cargo.choice === 'text')", { id: 'sc_corrected_again_flow', type: 'FLOW', value: 'send-copy', callType: 'replace', parameters: { item: '{{sc_item.key}}', medium: '{{sc_medium}}', destination: '{{sc_given}}' } }),
193
+ when('sc_corrected_again', "!sc_trusted && !!sc_given && (sc_medium === 'email' || sc_medium === 'text') && (cargo.choice === 'email' || cargo.choice === 'text')", { id: 'sc_corrected_again_flow', type: 'FLOW', value: 'send-copy', callType: 'replace', parameters: { item: '{{sc_item.key}}', medium: '{{sc_medium}}', destination: '{{sc_given}}', no_closing: '{{no_closing}}' } }),
192
194
  when('sc_confirm_no', "!sc_trusted && cargo.choice !== 'yes'", say('sc_confirm_no_say', "Okay, I didn't send it." + ANYTHING_ELSE, 'De acuerdo, no lo envié.' + ANYTHING_ELSE_ES)),
193
195
  when('sc_confirm_no_end', "!sc_trusted && cargo.choice !== 'yes'", end('sc_confirm_no_done', { outcome: 'unresolved', reason: 'declined' })),
194
196
  // send: a sender item runs its flow (it tells the caller); content goes as is
@@ -0,0 +1,2 @@
1
+ export const FLOWS: any[];
2
+ //# sourceMappingURL=transfer-line-flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-line-flow.d.ts","sourceRoot":"","sources":["../../src/forms/transfer-line-flow.js"],"names":[],"mappings":"AAyFA,0BAAsC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * TransferToLine (owner 2026-11-29): offer a warm transfer to one of the tenant's approved departments, by its key.
3
+ * Tenant-agnostic; built into the system set by AIDevelopment forms/system-forms.mjs.
4
+ *
5
+ * The departments are the tenant's own (user-admin → Channels → Transfer departments). The host stamps them on every
6
+ * turn as cargo.transferLines = { <key>: { name, name_es, phone, hours, hours_es, available } }: `available` is true
7
+ * only on a call, inside the department's schedule. A flow names a KEY, never a number: the host dials only the number
8
+ * the tenant configured for that key.
9
+ * - Available: the caller is asked (unless `confirmed`: they already asked to be connected); YES sets cargo.transferTo = key
10
+ * and ends every flow with the connecting line, and the host ends the call's session and dials the department. NO gives
11
+ * the number.
12
+ * - Not available (closed, or not a call): the department's number and hours are given.
13
+ * - An unknown key says the team cannot be reached here.
14
+ */
15
+ import { defineWorker } from './contracts.js';
16
+ const vars = (o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, { type: Array.isArray(v) ? 'array' : v === null || typeof v === 'object' ? 'object' : typeof v, value: v }]));
17
+ const set = (id, variable, value) => ({ id, type: 'SET', variable, value });
18
+ const effect = (id, value) => set(id, 'assignment_side_effect', value);
19
+ const noop = (id) => set(id, 'noop', 'true');
20
+ const when = (id, condition, step) => ({ id, type: 'CASE', branches: { [`condition: ${condition}`]: step, default: noop(`${id}_skip`) } });
21
+ const say = (id, value, value_es) => ({ id, type: 'SAY', value, value_es });
22
+ const end = (id, extra = {}) => ({ id, type: 'END', ...extra });
23
+ const call = (id, value, parameters) => ({ id, type: 'FLOW', value, callType: 'call', ...(parameters ? { parameters } : {}) });
24
+ const ANYTHING_ELSE = "{{typeof no_closing !== 'undefined' && (no_closing === true || no_closing === 'true') ? '' : ' Is there anything else I can help you with?'}}";
25
+ const ANYTHING_ELSE_ES = "{{typeof no_closing !== 'undefined' && (no_closing === true || no_closing === 'true') ? '' : ' ¿Hay algo más en lo que le pueda ayudar?'}}";
26
+ const LEAD = "(typeof lead === 'string' && lead ? lead + ' ' : '')";
27
+ const LEAD_ES = "(typeof lead_es === 'string' && lead_es ? lead_es + ' ' : (typeof lead === 'string' && lead ? lead + ' ' : ''))";
28
+ const transferToLine = defineWorker({
29
+ contract: { role: 'router', summary: "Offers a warm transfer to one of the tenant's departments by key; gives its number and hours when it cannot transfer" },
30
+ id: 'transfer-to-line',
31
+ name: 'TransferToLine',
32
+ version: '1.0.0',
33
+ scope: 'isolated',
34
+ description: "Worker: offer to connect the caller with the tenant's department `line` (a key of cargo.transferLines). On a call inside its hours YES sets cargo.transferTo and ends the flows with the connecting line; otherwise, or on NO, its number and hours are given.",
35
+ parameters: [
36
+ { name: 'line', type: 'string', description: 'The department key (cargo.transferLines)', required: true },
37
+ { name: 'lead', type: 'string', description: 'Optional sentence said before the offer (English)' },
38
+ { name: 'lead_es', type: 'string', description: 'Optional sentence said before the offer (Spanish)' },
39
+ { name: 'confirmed', type: 'boolean', description: 'true when the caller already asked to be connected: no question, the transfer starts' },
40
+ { name: 'no_closing', type: 'boolean', internal: true, description: 'Internal: true when the calling flow continues the conversation itself, so no closing question is asked.' },
41
+ ],
42
+ variables: vars({ noop: false, tl: null, tl_name: '', tl_name_es: '', tl_reach: '', tl_reach_es: '', tl_q: '', tl_q_es: '' }),
43
+ steps: [
44
+ set('tl_line', 'tl', "(cargo.transferLines && typeof line === 'string' && cargo.transferLines[line]) || null"),
45
+ when('tl_unknown', '!tl', say('tl_unknown_say', "{{" + LEAD + "}}Sorry, I can't connect you with that team from here." + ANYTHING_ELSE, "{{" + LEAD_ES + "}}Lo siento, no puedo comunicarle con ese equipo desde aquí." + ANYTHING_ELSE_ES)),
46
+ when('tl_unknown_end', '!tl', end('tl_unknown_done', { outcome: 'unresolved', reason: 'no_transfer_line' })),
47
+ set('tl_name', 'tl_name', "String(tl.name || '')"),
48
+ set('tl_name_es', 'tl_name_es', "String(tl.name_es || tl.name || '')"),
49
+ // how to reach it: the number, then its hours when it has any
50
+ set('tl_reach', 'tl_reach', "'You can reach ' + tl_name + (tl.phone ? ' at ' + tl.phone : '') + (tl.hours ? ', ' + tl.hours : '') + '.'"),
51
+ set('tl_reach_es', 'tl_reach_es', "'Puede comunicarse con ' + tl_name_es + (tl.phone ? ' al ' + tl.phone : '') + (tl.hours_es ? ', ' + tl.hours_es : '') + '.'"),
52
+ // not available now (closed, or not a call): the number and hours
53
+ when('tl_closed_call', "tl.available !== true && cargo.voice", say('tl_closed_call_say', "{{" + LEAD + " + tl_name.charAt(0).toUpperCase() + tl_name.slice(1)}} isn't available right now. {{tl_reach}}" + ANYTHING_ELSE, "{{" + LEAD_ES + " + tl_name_es.charAt(0).toUpperCase() + tl_name_es.slice(1)}} no está disponible en este momento. {{tl_reach_es}}" + ANYTHING_ELSE_ES)),
54
+ when('tl_closed_text', "tl.available !== true && !cargo.voice", say('tl_closed_text_say', "{{" + LEAD + " + tl_reach}}" + ANYTHING_ELSE, "{{" + LEAD_ES + " + tl_reach_es}}" + ANYTHING_ELSE_ES)),
55
+ when('tl_closed_end', 'tl.available !== true', end('tl_closed_done', { outcome: 'resolved', reason: 'transfer_line_number' })),
56
+ // already asked for by the caller: connected without a question
57
+ when('tl_confirmed_mark', "confirmed === true || confirmed === 'true'", effect('tl_confirmed_mark_set', 'cargo.transferTo = line')),
58
+ when('tl_confirmed', "confirmed === true || confirmed === 'true'", {
59
+ id: 'tl_confirmed_connecting', type: 'RETURN',
60
+ value: "language == 'es' ? 'Le comunico con ' + tl_name_es + '.' : 'Connecting you with ' + tl_name + '.'",
61
+ outcome: 'resolved', reason: 'transferred', keepSay: true,
62
+ }),
63
+ // available: asked; the answer is the caller's consent to the transfer
64
+ set('tl_q', 'tl_q', LEAD + " + 'Would you like me to connect you with ' + tl_name + ' now? ' + yesNoKeys('en', cargo)"),
65
+ set('tl_q_es', 'tl_q_es', LEAD_ES + " + '¿Desea que le comunique ahora con ' + tl_name_es + '? ' + yesNoKeys('es', cargo)"),
66
+ call('tl_ask', 'ask-choice', {
67
+ question: '{{tl_q}}',
68
+ question_es: '{{tl_q_es}}',
69
+ choices: [{ key: 'yes', phrases: ['1'] }, { key: 'no', phrases: ['2'] }],
70
+ digits: { min: 1, max: 1 },
71
+ rank: 'insist',
72
+ }),
73
+ when('tl_yes_mark', "cargo.choice === 'yes'", effect('tl_yes_mark_set', 'cargo.transferTo = line')),
74
+ when('tl_yes', "cargo.choice === 'yes'", {
75
+ id: 'tl_connecting', type: 'RETURN',
76
+ value: "language == 'es' ? 'Le comunico con ' + tl_name_es + '.' : 'Connecting you with ' + tl_name + '.'",
77
+ outcome: 'resolved', reason: 'transferred', keepSay: true,
78
+ }),
79
+ say('tl_no_say', "Okay. {{tl_reach}}" + ANYTHING_ELSE, "De acuerdo. {{tl_reach_es}}" + ANYTHING_ELSE_ES),
80
+ end('tl_no_done', { outcome: 'resolved', reason: 'transfer_declined' }),
81
+ ],
82
+ });
83
+ export const FLOWS = [transferToLine];
@@ -1 +1 @@
1
- export const JSFE_RUNTIME_FINGERPRINT = "sha256:1b4415bf9907a3a361dffd0cbf55141f72a462dde413ce0c98d4589dba9c62ed";
1
+ export const JSFE_RUNTIME_FINGERPRINT = "sha256:6efbb0b6a5588df279c801c7656eb8b680528a35eb4006c7909f2c8cd4353bc2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfe",
3
- "version": "1.97.0",
3
+ "version": "1.99.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",