jsfe 1.79.0 → 1.81.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/dist/forms/send-copy-flow.d.ts.map +1 -1
- package/dist/forms/send-copy-flow.js +18 -1
- package/dist/helpers/index.d.ts +7 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +3 -2
- package/dist/helpers/match-inputs.d.ts.map +1 -1
- package/dist/helpers/match-inputs.js +2 -5
- package/dist/helpers/numbers.d.ts +35 -0
- package/dist/helpers/numbers.d.ts.map +1 -0
- package/dist/helpers/numbers.js +189 -0
- package/dist/helpers/spoken-money.d.ts +4 -0
- package/dist/helpers/spoken-money.d.ts.map +1 -1
- package/dist/helpers/spoken-money.js +4 -0
- package/dist/runtime-identity.js +1 -1
- package/docs/architecture-guide.md +66 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-copy-flow.d.ts","sourceRoot":"","sources":["../../src/forms/send-copy-flow.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"send-copy-flow.d.ts","sourceRoot":"","sources":["../../src/forms/send-copy-flow.js"],"names":[],"mappings":"AAoKA,0BAAgC"}
|
|
@@ -40,10 +40,11 @@ const sendCopy = defineWorker({
|
|
|
40
40
|
{ 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." },
|
|
41
41
|
{ 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')." },
|
|
42
42
|
{ name: 'destination', type: 'string', description: 'The phone number or email address the user gave to send it to, as given.' },
|
|
43
|
+
{ 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." },
|
|
43
44
|
],
|
|
44
45
|
variables: vars({
|
|
45
46
|
noop: false, sc_items: [], sc_key: '', sc_item: null, sc_last: null, sc_last_head: '', sc_offer_q: '', sc_offer_q_es: '', sc_doc_list: '', sc_email: '', sc_phone: '',
|
|
46
|
-
sc_medium: '', sc_medium_q: '', sc_medium_q_es: '', sc_given: '', sc_media: [], sc_forced: '', sc_to: '', sc_subject: '', sc_content: '', sc_sent: false,
|
|
47
|
+
sc_medium: '', sc_medium_q: '', sc_medium_q_es: '', sc_given: '', sc_other: false, sc_media: [], sc_forced: '', sc_to: '', sc_subject: '', sc_content: '', sc_sent: false,
|
|
47
48
|
}),
|
|
48
49
|
steps: [
|
|
49
50
|
set('sc_items', 'sc_items', 'sendables(cargo)'),
|
|
@@ -91,6 +92,22 @@ const sendCopy = defineWorker({
|
|
|
91
92
|
})),
|
|
92
93
|
when('sc_ask_medium_read', '!sc_medium', set('sc_medium_pick', 'sc_medium', "cargo.choice === 'text' || cargo.choice === 'email' ? cargo.choice : ''")),
|
|
93
94
|
when('sc_no_medium_end', '!sc_medium', end('sc_no_medium_done')),
|
|
95
|
+
// another number or email, not given (prod 2026-11-19 14:57: "Can you text it to another number?" was texted to the
|
|
96
|
+
// number on file again): asked here, before any sender or the number on file is used
|
|
97
|
+
set('sc_other', 'sc_other', "typeof other_destination !== 'undefined' && other_destination === true && !(sc_medium === 'email' ? sc_email : sc_phone)"),
|
|
98
|
+
when('sc_other_number', "sc_other && sc_medium === 'text'", call('sc_other_number_call', 'ask-choice', {
|
|
99
|
+
question: 'What phone number should I text it to?', question_es: '¿A qué número de teléfono se lo envío?',
|
|
100
|
+
choices: [], accept_other: true, expect: 'number', digits: { min: 10, max: 11 },
|
|
101
|
+
})),
|
|
102
|
+
when('sc_other_number_read', "sc_other && sc_medium === 'text'", set('sc_other_number_set', 'sc_phone', "readPhone(cargo.choiceText || '')")),
|
|
103
|
+
when('sc_other_number_bad', "sc_other && sc_medium === 'text' && !sc_phone", say('sc_other_number_bad_say', "Sorry, I couldn't read that phone number." + ANYTHING_ELSE, 'Lo siento, no pude entender ese número de teléfono.' + ANYTHING_ELSE_ES)),
|
|
104
|
+
when('sc_other_number_end', "sc_other && sc_medium === 'text' && !sc_phone", end('sc_other_number_done', { outcome: 'unresolved', reason: 'no_phone_number' })),
|
|
105
|
+
when('sc_other_email_clear', "sc_other && sc_medium === 'email'", effect('sc_other_email_clear_set', "cargo.email = ''")),
|
|
106
|
+
when('sc_other_email', "sc_other && sc_medium === 'email'", call('sc_other_email_call', 'ask-email', {
|
|
107
|
+
question: 'What email address should I send it to?', question_es: '¿A qué correo electrónico se lo envío?', on_file: '',
|
|
108
|
+
})),
|
|
109
|
+
when('sc_other_email_read', "sc_other && sc_medium === 'email'", set('sc_other_email_set', 'sc_email', "cargo.email && validateEmail(String(cargo.email)) ? String(cargo.email) : ''")),
|
|
110
|
+
when('sc_other_email_end', "sc_other && sc_medium === 'email' && !sc_email", end('sc_other_email_done')),
|
|
94
111
|
// a sender item: its flow collects what it needs (destination, identity) and tells the caller every outcome
|
|
95
112
|
set('sc_given', 'sc_given', "sc_medium === 'email' ? sc_email : sc_phone"),
|
|
96
113
|
when('sc_sender_reset', '!!sc_item.sender', effect('sc_sender_reset_set', 'cargo.copyHandled = false')),
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -94,6 +94,9 @@ export namespace STANDARD_FUNCTIONS {
|
|
|
94
94
|
export { readFormAnswer };
|
|
95
95
|
export { readArgument };
|
|
96
96
|
export { groundAmount };
|
|
97
|
+
export { joinSpokenNumbers };
|
|
98
|
+
export { findNumbers };
|
|
99
|
+
export { assignNumbers };
|
|
97
100
|
export { readInputProfile };
|
|
98
101
|
export { formAcceptanceTrace };
|
|
99
102
|
export { resolveFormInputs };
|
|
@@ -243,6 +246,9 @@ import { matchInputs } from './match-inputs.js';
|
|
|
243
246
|
import { readFormAnswer } from './match-inputs.js';
|
|
244
247
|
import { readArgument } from './match-inputs.js';
|
|
245
248
|
import { groundAmount } from './match-inputs.js';
|
|
249
|
+
import { joinSpokenNumbers } from './numbers.js';
|
|
250
|
+
import { findNumbers } from './numbers.js';
|
|
251
|
+
import { assignNumbers } from './numbers.js';
|
|
246
252
|
import { readInputProfile } from './match-inputs.js';
|
|
247
253
|
import { formAcceptanceTrace } from './match-inputs.js';
|
|
248
254
|
import { resolveFormInputs } from './form-state.js';
|
|
@@ -300,5 +306,5 @@ import { sendables } from './sendables.js';
|
|
|
300
306
|
import { chatTranscript } from './sendables.js';
|
|
301
307
|
import { conversationCopy } from './sendables.js';
|
|
302
308
|
import { CONVERSATION_KEY } from './sendables.js';
|
|
303
|
-
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, retireStaleFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, keepFormLine, deferFormClarification, takeFormClarification, formClarificationKept, clearFormLines, 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, emailWithoutEnding, emailEnding, emailSaid, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, yesNoKeys, channelVerb, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readArgument, groundAmount, 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, registerSendable, sendables, chatTranscript, conversationCopy, CONVERSATION_KEY };
|
|
309
|
+
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, retireStaleFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, keepFormLine, deferFormClarification, takeFormClarification, formClarificationKept, clearFormLines, 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, emailWithoutEnding, emailEnding, emailSaid, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, yesNoKeys, channelVerb, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readArgument, groundAmount, joinSpokenNumbers, findNumbers, assignNumbers, 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, registerSendable, sendables, chatTranscript, conversationCopy, CONVERSATION_KEY };
|
|
304
310
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CACyC,iCAAiC;+BAIoO,wBAAwB;2CAHxP,0BAA0B;qCAA1B,0BAA0B;gCAA1B,0BAA0B;mCAC8F,qBAAqB;kCAArB,qBAAqB;iCAArB,qBAAqB;qCAArB,qBAAqB;iCAArB,qBAAqB;wCAArB,qBAAqB;mCAArB,qBAAqB;oCAArB,qBAAqB;6CAArB,qBAAqB;qCACvG,wBAAwB;2CAAxB,wBAAwB;+CAAxB,wBAAwB;uCAAxB,wBAAwB;gCACkK,wBAAwB;4BAAxB,wBAAwB;8BAAxB,wBAAwB;iCAAxB,wBAAwB;gCAAxB,wBAAwB;0CAAxB,wBAAwB;gCAAxB,wBAAwB;iCAAxB,wBAAwB;oCAAxB,wBAAwB;6BAAxB,wBAAwB;uCAAxB,wBAAwB;sCAAxB,wBAAwB;sCAAxB,wBAAwB;+BAAxB,wBAAwB;wCAAxB,wBAAwB;gCAoBvM,YAAY;8BAAZ,YAAY;kCAAZ,YAAY;uCAAZ,YAAY;qCAAZ,YAAY;qCAAZ,YAAY;gCAnB3G,mBAAmB;gCA2BiH,mBAAmB;4BAAnB,mBAAmB;sCAAnB,mBAAmB;8BATzJ,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;0BACb,cAAc;mCAAd,cAAc;4BAAd,cAAc;0BAAd,cAAc;0BAAd,cAAc;uCAAd,cAAc;+BAAd,cAAc;sBAAd,cAAc;0BAAd,cAAc;iCAAd,cAAc;gCAAd,cAAc;sCAAd,cAAc;wCAC3K,cAAc;6BACiC,cAAc;wBAAd,cAAc;wBAAd,cAAc;+BAAd,cAAc;0BAAd,cAAc;4BAAd,cAAc;4BACzE,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;4BAUgD,mBAAmB;+BAAnB,mBAAmB;6BAAnB,mBAAmB;6BAAnB,mBAAmB;kCAKzH,cAAc;4BAAd,cAAc;8BAAd,cAAc;iCALwF,mBAAmB;oCAAnB,mBAAmB;kCACijB,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;4BAG7B,iBAAiB;oCAAjB,iBAAiB;iCAFI,oBAAoB;iCAApB,oBAAoB;kCAApB,oBAAoB;iCA9BM,gBAAgB;0BAAhB,gBAAgB;+BAAhB,gBAAgB;iCAAhB,gBAAgB;iCAAhB,gBAAgB"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -36,8 +36,9 @@ import { resolveFormInputs, formInputApplies, formInputFilled, nextFormInput, fo
|
|
|
36
36
|
import { checkOtp, clearOtp, maskDestination, validateOTP, OTP_EXPIRY_MS } from './otp-check.js';
|
|
37
37
|
import { validateDigits, validatePhone, validateEmail } from './validators.js';
|
|
38
38
|
import { joinSpokenDigits, spokenDigitsText, wholeSpokenNumber } from './spoken-digits.js';
|
|
39
|
+
import { findNumbers, assignNumbers, joinSpokenNumbers } from './numbers.js';
|
|
39
40
|
import { urlToSpeech, textWithUrlToSpeech } from './url-speech.js';
|
|
40
|
-
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, retireStaleFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, keepFormLine, deferFormClarification, takeFormClarification, formClarificationKept, clearFormLines, 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, emailWithoutEnding, emailEnding, emailSaid, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, yesNoKeys, channelVerb, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readArgument, groundAmount, 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, registerSendable, sendables, chatTranscript, conversationCopy, CONVERSATION_KEY, };
|
|
41
|
+
export { continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse, formProposalPolicy, stageFormProposal, nextFormProposal, formProposalReadings, bindFormProposal, retireStaleFormProposal, decideFormProposal, commitFormProposals, settleFormProposalValidation, formProposalProtocol, validateFormProposalPolicy, validateFormProposalDescriptor, formProposalDescriptor, clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, keepFormLine, deferFormClarification, takeFormClarification, formClarificationKept, clearFormLines, 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, emailWithoutEnding, emailEnding, emailSaid, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational, normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, yesNoKeys, channelVerb, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readArgument, groundAmount, joinSpokenNumbers, findNumbers, assignNumbers, 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, registerSendable, sendables, chatTranscript, conversationCopy, CONVERSATION_KEY, };
|
|
41
42
|
/** The functions flows call by name, ready to spread into a host's approved functions. */
|
|
42
43
|
export const STANDARD_FUNCTIONS = {
|
|
43
44
|
continuationSafetyProtocol, cancelFormTask, contextualResponseProtocol, validateFormResponse, hasFormResponse,
|
|
@@ -45,7 +46,7 @@ export const STANDARD_FUNCTIONS = {
|
|
|
45
46
|
clearFormMisses, formNoOwner, missFormInput, formMustComplete, formInputPrompt, formUserDescriptionSource, formConcernLine, formAcknowledges, consumeFormFeedback, keepFormLine, deferFormClarification, takeFormClarification, formClarificationKept, clearFormLines, formConversationOutcome,
|
|
46
47
|
readMoneyAmount, isMoneyAmount, moneyIntentAllows, isPastPaymentStatement, isPartialMoneyAnswer, validateMoneyOptions, takeChoiceOffer, saysConfirmWord, confirmOutOfOrderLine, matchesChoice, isAnswer, isAgentRequest, isExitRequest, isGlobalExit, isOtherRequest, isSpelledFragment, isAmountAnswer, amountInAnswer, pickChoice, withoutPromptEcho,
|
|
47
48
|
readEmail, emailWithoutEnding, emailEnding, emailSaid, readPhone, readInternationalPhone, readIdentifier, last4, maskEmail, callerTextNumber, textDestination, callerIsInternational,
|
|
48
|
-
normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, yesNoKeys, channelVerb, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readArgument, groundAmount, 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,
|
|
49
|
+
normalizeAndFindCapture, anythingElse, goodbye, sayName, sorryNotCaught, yesNoKeys, channelVerb, dateToWords, amountToSpeech, validateCardNumber, validateExpiration, consumeActionReceipt, authorizeFormActionRetry, formSignature, selectFormAction, confirmFormRevision, prepareFormAction, actionConfirmationValid, beginFormAction, finishFormAction, actionGateVerified, sourceNeedsLoad, beginSourceRefresh, completeSourceRefresh, pickProviderQuestion, matchInputs, readFormAnswer, readArgument, groundAmount, joinSpokenNumbers, findNumbers, assignNumbers, 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,
|
|
49
50
|
validateOTP, validateDigits, validatePhone, validateEmail, urlToSpeech, textWithUrlToSpeech, joinSpokenDigits, wholeSpokenNumber,
|
|
50
51
|
registerSendable, sendables, chatTranscript, conversationCopy,
|
|
51
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,sEAQC;AA8FD;;;GAGG;AACH,sFAiIC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAGD,gGAOC;AAYD,kDAGC;AAED;;;;;;;GAOG;AACH;;;;SAcC;AACD;;;;;GAKG;AACH;;;;;;;;;;;;;;;;;;;;;;EAaC;AACD;;;;;;;;;;;;;;;;;;;;;;EAeC;AACD;;;;;;;;;;;;;;;;;;;;;;;EAgXC"}
|
|
@@ -15,6 +15,7 @@ import { readSpokenMoney } from './spoken-money.js';
|
|
|
15
15
|
import { readMoneyAmount, isPartialMoneyAnswer } from './money.js';
|
|
16
16
|
import { pickProviderQuestion } from './form-sources.js';
|
|
17
17
|
import { spokenDigitsText, wholeSpokenNumber } from './spoken-digits.js';
|
|
18
|
+
import { DIGIT_RUN } from './numbers.js';
|
|
18
19
|
/**
|
|
19
20
|
* This turn's acceptance decisions for the host to log, appended per match: fields filled out of order, in a compound
|
|
20
21
|
* answer or as an invited input, and every refused reading, by form, field and rule. Field names and rules only, never
|
|
@@ -34,11 +35,7 @@ export function formAcceptanceTrace(previous, matches) {
|
|
|
34
35
|
function unescape(answer) {
|
|
35
36
|
return String(answer ?? '').replace(/\\(['"\\])/g, '$1');
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
* joins it, and so does a comma (or a period and a space) after a group of one to three digits: speech-to-text writes the
|
|
39
|
-
* pauses between spoken groups that way (prod 2026-10-31: the ZIP 92610 said as "926, 1 0.", the code as "7, 9, 984. 5."). A comma after a
|
|
40
|
-
* longer number separates two numbers ("92610, 56035214"). */
|
|
41
|
-
const DIGIT_RUN = /\d(?:[\s.-]?\d|(?<=(?:^|\D)\d{1,3})(?:,\s?|\.\s)(?=\d))*/g;
|
|
38
|
+
// DIGIT_RUN, the run of digits as said, lives with the number finder (numbers.js), so the rule is written once.
|
|
42
39
|
function digitRuns(raw) {
|
|
43
40
|
return (raw.match(DIGIT_RUN) || []).map((r) => r.replace(/\D/g, ''));
|
|
44
41
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every number in the answer, in order: [{value, said, start, end, restarts}]. value is the complete number's digits; said the
|
|
3
|
+
* text it was read from (start/end index the answer); restarts the readings of the number once when the caller repeated it
|
|
4
|
+
* (restartsOf), else []. Number words
|
|
5
|
+
* are numbers ("one thousand and 3" → 1003, "cinco cinco cinco" → 555); every other word separates two numbers.
|
|
6
|
+
*/
|
|
7
|
+
export function findNumbers(answer: any): {
|
|
8
|
+
value: string;
|
|
9
|
+
said: string;
|
|
10
|
+
start: any;
|
|
11
|
+
end: any;
|
|
12
|
+
restarts: any[];
|
|
13
|
+
}[];
|
|
14
|
+
/**
|
|
15
|
+
* Which numbers are which, by the caller's tests: kinds = {name: (digits) => false | true | normalized value}. One value per kind.
|
|
16
|
+
* A number is read by every test its complete digits pass and, for a restart, every test the number once passes. A number
|
|
17
|
+
* read more than one way is ambiguous, and so is a kind given two different values: those kinds take no value, so the caller
|
|
18
|
+
* asks (the longest match wins only when it is the only match: "5603 5603" is an 8-digit account or SSN 5603 said twice).
|
|
19
|
+
* A number no test reads is ignored here; the caller decides whether that means asking again.
|
|
20
|
+
* → {values: {name: value}, ambiguous: [names], unread: [numbers]}
|
|
21
|
+
*/
|
|
22
|
+
export function assignNumbers(numbers: any, kinds: any): {
|
|
23
|
+
values: {};
|
|
24
|
+
ambiguous: any[];
|
|
25
|
+
unread: any[];
|
|
26
|
+
};
|
|
27
|
+
/** The answer with each number written as its digits (a restart as the number once unless {restarts: false}), for a reader
|
|
28
|
+
* that reads text: "323 5713211" → "3235713211", "one thousand and 3" → "1003". */
|
|
29
|
+
export function joinSpokenNumbers(answer: any, options?: {}): string;
|
|
30
|
+
/** A run of digits as said: spoken digits come apart ("4 3 2 1", "555-123-4567"), so a single space, dash or dot inside a run
|
|
31
|
+
* joins it, and so does a comma (or a period and a space) after a group of one to three digits: speech-to-text writes the
|
|
32
|
+
* pauses between spoken groups that way (prod 2026-10-31: the ZIP 92610 said as "926, 1 0.", the code as "7, 9, 984. 5."). A
|
|
33
|
+
* comma after a longer number separates two numbers ("92610, 56035214"). */
|
|
34
|
+
export const DIGIT_RUN: RegExp;
|
|
35
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/helpers/numbers.js"],"names":[],"mappings":"AAoFA;;;;;GAKG;AACH;;;;;;IAoBC;AAED;;;;;;;GAOG;AACH;;;;EA0BC;AAED;mFACmF;AACnF,qEASC;AApJD;;;4EAG4E;AAC5E,+BAAqF"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one number finder (owner 2026-11-19): every number in an answer, each read complete, as said. A value is only ever a
|
|
3
|
+
* complete number (spaces, pauses and punctuation inside it allowed) or a qualified restart, never a piece of one: a reader
|
|
4
|
+
* that took pieces read a phone typed "323 5713211" as account 5713211 (prod 2026-11-17) and the year of a spoken date as an
|
|
5
|
+
* SSN's last four (11-18).
|
|
6
|
+
*
|
|
7
|
+
* findNumbers finds; it never decides what a number is. The caller's own tests decide that (assignNumbers), so a tenant's
|
|
8
|
+
* proprietary identifier is one more test, not a matcher here. Shape reading only; part of jsfe/helpers, imports a sibling.
|
|
9
|
+
*/
|
|
10
|
+
import { cardinalWords, isNumberWord, plainWord } from './spoken-money.js';
|
|
11
|
+
/** A run of digits as said: spoken digits come apart ("4 3 2 1", "555-123-4567"), so a single space, dash or dot inside a run
|
|
12
|
+
* joins it, and so does a comma (or a period and a space) after a group of one to three digits: speech-to-text writes the
|
|
13
|
+
* pauses between spoken groups that way (prod 2026-10-31: the ZIP 92610 said as "926, 1 0.", the code as "7, 9, 984. 5."). A
|
|
14
|
+
* comma after a longer number separates two numbers ("92610, 56035214"). */
|
|
15
|
+
export const DIGIT_RUN = /\d(?:[\s.-]?\d|(?<=(?:^|\D)\d{1,3})(?:,\s?|\.\s)(?=\d))*/g;
|
|
16
|
+
const DIGIT_WORDS = { zero: 0, one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9,
|
|
17
|
+
cero: 0, uno: 1, dos: 2, tres: 3, cuatro: 4, cinco: 5, seis: 6, siete: 7, ocho: 8, nueve: 9 };
|
|
18
|
+
// Words that are a number only next to another number word: an article alone ("una cuenta", "a payment") is not one.
|
|
19
|
+
const ARTICLES = new Set(['a', 'an', 'un', 'una']);
|
|
20
|
+
const CONNECTORS = new Set(['and', 'y']);
|
|
21
|
+
const SCALES = [[1000000, ['million', 'millon', 'millones']], [1000, ['thousand', 'mil']], [100, ['hundred', 'cien', 'ciento']]];
|
|
22
|
+
/** Number words in the answer, each run with its digits: "one thousand and 3" → 1003, "cinco cinco cinco" → 555. */
|
|
23
|
+
function wordNumbers(raw) {
|
|
24
|
+
const tokens = [...raw.matchAll(/\p{L}+|\d+/gu)].map((m) => ({ word: plainWord(m[0]), start: m.index, end: m.index + m[0].length }));
|
|
25
|
+
const gapOk = (a, b) => /^[\s-]*$/.test(raw.slice(a.end, b.start));
|
|
26
|
+
const found = [];
|
|
27
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
28
|
+
const first = tokens[i].word;
|
|
29
|
+
if (!isNumberWord(first) || CONNECTORS.has(first)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
else { /* a run starts here */ }
|
|
33
|
+
let j = i;
|
|
34
|
+
while (j + 1 < tokens.length && isNumberWord(tokens[j + 1].word) && gapOk(tokens[j], tokens[j + 1]))
|
|
35
|
+
j++;
|
|
36
|
+
while (j > i && (CONNECTORS.has(tokens[j].word) || ARTICLES.has(tokens[j].word)))
|
|
37
|
+
j--;
|
|
38
|
+
const words = tokens.slice(i, j + 1).map((t) => t.word);
|
|
39
|
+
if (words.length === 1 && ARTICLES.has(words[0])) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
else { /* a number word */ }
|
|
43
|
+
let value = cardinalWords(words);
|
|
44
|
+
let digits = value === null ? null : String(value);
|
|
45
|
+
if (digits === null && words.every((w) => Object.hasOwn(DIGIT_WORDS, w))) {
|
|
46
|
+
digits = words.map((w) => DIGIT_WORDS[w]).join(''); // digits said one by one
|
|
47
|
+
}
|
|
48
|
+
else { /* a cardinal, or not a number */ }
|
|
49
|
+
if (digits === null) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
else { /* read */ }
|
|
53
|
+
// A digit said after a scale word completes it: "one thousand and 3", "mil 3", "two hundred 5".
|
|
54
|
+
let end = tokens[j].end;
|
|
55
|
+
let k = j + 1;
|
|
56
|
+
if (value !== null && k < tokens.length && CONNECTORS.has(tokens[k].word) && gapOk(tokens[j], tokens[k]))
|
|
57
|
+
k++;
|
|
58
|
+
else { /* no connector */ }
|
|
59
|
+
const tail = tokens[k];
|
|
60
|
+
const scale = value === null ? 0 : (SCALES.find(([size, names]) => words.some((w) => names.includes(w)) && value % size === 0)?.[0] || 0);
|
|
61
|
+
if (scale && tail && /^\d+$/.test(tail.word) && gapOk(tokens[k - 1], tail) && Number(tail.word) < scale) {
|
|
62
|
+
digits = String(value + Number(tail.word));
|
|
63
|
+
end = tail.end;
|
|
64
|
+
j = k;
|
|
65
|
+
}
|
|
66
|
+
else { /* nothing completes it */ }
|
|
67
|
+
found.push({ start: tokens[i].start, end, digits });
|
|
68
|
+
i = j;
|
|
69
|
+
}
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
72
|
+
/** A caller on the phone repeats themselves (owner 2026-11-19), so a run may hold a restart: the number once.
|
|
73
|
+
* - The whole number said twice ("6119 6119", "04 13 1955 04 13 1955"): two identical halves of four digits or more.
|
|
74
|
+
* - Its last part said again ("323 571 3211 3211"): trailing groups that repeat the digits just before them, three digits
|
|
75
|
+
* or more (one repeated digit is no restart: "5 6 0 3 3" may be the number).
|
|
76
|
+
* - A false start ("57. 57, 21, 80."): digits cut off at a pause the transcript marks (a comma or a period), then the number
|
|
77
|
+
* again from its start (the rule the OTP reader has used since 2026-11-18, otpDigits).
|
|
78
|
+
* A restart is only a candidate: assignNumbers takes it when the whole number fits nothing, and asks when both fit. */
|
|
79
|
+
function restartsOf(said) {
|
|
80
|
+
const groups = said.split(/\D+/).filter(Boolean);
|
|
81
|
+
const pauses = said.match(/\D+/g) || []; // pauses[i - 1] separates groups[i - 1] and groups[i]
|
|
82
|
+
const found = new Set();
|
|
83
|
+
for (let i = 1; i < groups.length; i++) {
|
|
84
|
+
const before = groups.slice(0, i).join(''), after = groups.slice(i).join('');
|
|
85
|
+
if (before === after && before.length >= 4) {
|
|
86
|
+
found.add(before);
|
|
87
|
+
}
|
|
88
|
+
else if (after.length >= 3 && before.length > after.length && before.endsWith(after)) {
|
|
89
|
+
found.add(before);
|
|
90
|
+
}
|
|
91
|
+
else if (/[,.]/.test(pauses[i - 1] || '') && after.length > before.length && after.startsWith(before)) {
|
|
92
|
+
found.add(after);
|
|
93
|
+
}
|
|
94
|
+
else { /* no repeat at this boundary */ }
|
|
95
|
+
}
|
|
96
|
+
return [...found];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Every number in the answer, in order: [{value, said, start, end, restarts}]. value is the complete number's digits; said the
|
|
100
|
+
* text it was read from (start/end index the answer); restarts the readings of the number once when the caller repeated it
|
|
101
|
+
* (restartsOf), else []. Number words
|
|
102
|
+
* are numbers ("one thousand and 3" → 1003, "cinco cinco cinco" → 555); every other word separates two numbers.
|
|
103
|
+
*/
|
|
104
|
+
export function findNumbers(answer) {
|
|
105
|
+
const raw = String(answer ?? '');
|
|
106
|
+
// A line break separates two numbers, as a word does (prod WhatsApp 2026-10-18: a date, then the account on the next line).
|
|
107
|
+
const lines = raw.replace(/[\r\n]/g, '|');
|
|
108
|
+
// Number words become their digits first, so a number said partly in words joins like any other ("five five five 1212").
|
|
109
|
+
let text = '';
|
|
110
|
+
const origin = [];
|
|
111
|
+
let from = 0;
|
|
112
|
+
for (const w of wordNumbers(lines)) {
|
|
113
|
+
for (let i = from; i < w.start; i++) {
|
|
114
|
+
text += lines[i];
|
|
115
|
+
origin.push(i);
|
|
116
|
+
}
|
|
117
|
+
for (const d of w.digits) {
|
|
118
|
+
text += d;
|
|
119
|
+
origin.push(w.start);
|
|
120
|
+
}
|
|
121
|
+
origin[origin.length - 1] = w.end - 1;
|
|
122
|
+
from = w.end;
|
|
123
|
+
}
|
|
124
|
+
for (let i = from; i < raw.length; i++) {
|
|
125
|
+
text += lines[i];
|
|
126
|
+
origin.push(i);
|
|
127
|
+
}
|
|
128
|
+
return [...text.matchAll(DIGIT_RUN)].map((m) => {
|
|
129
|
+
const said = m[0].replace(/[\s.,-]+$/, '');
|
|
130
|
+
const start = origin[m.index], end = origin[m.index + said.length - 1] + 1;
|
|
131
|
+
return { value: said.replace(/\D/g, ''), said: raw.slice(start, end), start, end, restarts: restartsOf(said) };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Which numbers are which, by the caller's tests: kinds = {name: (digits) => false | true | normalized value}. One value per kind.
|
|
136
|
+
* A number is read by every test its complete digits pass and, for a restart, every test the number once passes. A number
|
|
137
|
+
* read more than one way is ambiguous, and so is a kind given two different values: those kinds take no value, so the caller
|
|
138
|
+
* asks (the longest match wins only when it is the only match: "5603 5603" is an 8-digit account or SSN 5603 said twice).
|
|
139
|
+
* A number no test reads is ignored here; the caller decides whether that means asking again.
|
|
140
|
+
* → {values: {name: value}, ambiguous: [names], unread: [numbers]}
|
|
141
|
+
*/
|
|
142
|
+
export function assignNumbers(numbers, kinds) {
|
|
143
|
+
const seen = {}, ambiguous = new Set(), unread = [];
|
|
144
|
+
const read = (test, digits) => { const r = test(digits); return r === true ? digits : r ? String(r) : ''; };
|
|
145
|
+
for (const n of numbers || []) {
|
|
146
|
+
const readings = [];
|
|
147
|
+
for (const [kind, test] of Object.entries(kinds || {})) {
|
|
148
|
+
const whole = read(test, n.value);
|
|
149
|
+
if (whole)
|
|
150
|
+
readings.push([kind, whole]);
|
|
151
|
+
else { /* the complete number is not this kind */ }
|
|
152
|
+
for (const restart of n.restarts || []) {
|
|
153
|
+
const once = read(test, restart);
|
|
154
|
+
if (once)
|
|
155
|
+
readings.push([kind, once]);
|
|
156
|
+
else { /* not this kind */ }
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (readings.length === 1) {
|
|
160
|
+
(seen[readings[0][0]] ||= new Set()).add(readings[0][1]);
|
|
161
|
+
}
|
|
162
|
+
else if (readings.length > 1) {
|
|
163
|
+
readings.forEach(([kind]) => ambiguous.add(kind));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
unread.push(n);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const values = {};
|
|
170
|
+
for (const [kind, set] of Object.entries(seen)) {
|
|
171
|
+
if (set.size === 1 && !ambiguous.has(kind))
|
|
172
|
+
values[kind] = [...set][0];
|
|
173
|
+
else
|
|
174
|
+
ambiguous.add(kind);
|
|
175
|
+
}
|
|
176
|
+
return { values, ambiguous: [...ambiguous], unread };
|
|
177
|
+
}
|
|
178
|
+
/** The answer with each number written as its digits (a restart as the number once unless {restarts: false}), for a reader
|
|
179
|
+
* that reads text: "323 5713211" → "3235713211", "one thousand and 3" → "1003". */
|
|
180
|
+
export function joinSpokenNumbers(answer, options = {}) {
|
|
181
|
+
const raw = String(answer ?? '');
|
|
182
|
+
const restarts = options?.restarts !== false;
|
|
183
|
+
let out = '', from = 0;
|
|
184
|
+
for (const n of findNumbers(raw)) {
|
|
185
|
+
out += raw.slice(from, n.start) + (restarts && n.restarts.length === 1 ? n.restarts[0] : n.value);
|
|
186
|
+
from = n.end;
|
|
187
|
+
}
|
|
188
|
+
return out + raw.slice(from);
|
|
189
|
+
}
|
|
@@ -17,4 +17,8 @@ export function readSpokenMoney(answer: any): {
|
|
|
17
17
|
start: number;
|
|
18
18
|
end: number;
|
|
19
19
|
}[];
|
|
20
|
+
/** For the number finder (numbers.js), so the cardinal grammar lives here once: a run of number words' value, or null. */
|
|
21
|
+
export function cardinalWords(words: any): any;
|
|
22
|
+
export function isNumberWord(word: any): boolean;
|
|
23
|
+
export function plainWord(word: any): any;
|
|
20
24
|
//# sourceMappingURL=spoken-money.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spoken-money.d.ts","sourceRoot":"","sources":["../../src/helpers/spoken-money.js"],"names":[],"mappings":"AAqDA;wHACwH;AACxH;;;;;;;;;;;EA+BC;AAED;;;;IAAkF"}
|
|
1
|
+
{"version":3,"file":"spoken-money.d.ts","sourceRoot":"","sources":["../../src/helpers/spoken-money.js"],"names":[],"mappings":"AAqDA;wHACwH;AACxH;;;;;;;;;;;EA+BC;AAED;;;;IAAkF;AAElF,0HAA0H;AAC1H,+CAAqG;AACrG,iDAAmE;AACnE,0CAAqD"}
|
|
@@ -141,3 +141,7 @@ export function scanSpokenMoney(answer) {
|
|
|
141
141
|
return { readings, invalid };
|
|
142
142
|
}
|
|
143
143
|
export function readSpokenMoney(answer) { return scanSpokenMoney(answer).readings; }
|
|
144
|
+
/** For the number finder (numbers.js), so the cardinal grammar lives here once: a run of number words' value, or null. */
|
|
145
|
+
export function cardinalWords(words) { return words.some(word => /\d/.test(word)) ? null : cardinal(words); }
|
|
146
|
+
export function isNumberWord(word) { return NUMBER_WORDS.has(word); }
|
|
147
|
+
export function plainWord(word) { return plain(word); }
|
package/dist/runtime-identity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSFE_RUNTIME_FINGERPRINT = "sha256:
|
|
1
|
+
export const JSFE_RUNTIME_FINGERPRINT = "sha256:1b727c897b055e1f8084fffdf3f305aff21a6f44788da5192d9825203c3dd001";
|
|
@@ -327,8 +327,14 @@ rules should decide.
|
|
|
327
327
|
|
|
328
328
|
**How the values are taken:**
|
|
329
329
|
|
|
330
|
-
- Each value is read by the readers as if said alone, then validated and stored like a typed answer, with the same
|
|
330
|
+
- Each value is read by the readers as if said alone, then validated and stored like a typed answer, with the same
|
|
331
331
|
acknowledgement, attempts and confirmation. A value read at a confirmation changes the form, which is confirmed again.
|
|
332
|
+
- An AMOUNT's digits come only from the caller's own words (jsfe 1.77). A model's amount (these arguments, or an
|
|
333
|
+
activation parameter intent detection extracted) is taken only where the caller said it as a whole number, read from
|
|
334
|
+
those words with their money mark (`groundAmount`); a number the caller did not say, or a piece of one ("43" in
|
|
335
|
+
"43, 4, 97"), is not taken.
|
|
336
|
+
- Extraction reads the latest message and the assistant's last message only, never the caller's earlier words (jsfe
|
|
337
|
+
1.78.1): a ZIP code said at an earlier question is never taken as a later request's phone number.
|
|
332
338
|
- Nothing read: the question is asked again, as without the declaration. Extraction failing behaves the same.
|
|
333
339
|
- Two readings of one input that differ take nothing: the question is asked again.
|
|
334
340
|
- A picked choice is applied first, then its arguments. An argument that answers the choice's own exclusive group
|
|
@@ -414,6 +420,60 @@ Each stage is one `aiCallback` call that carries instructions for both a classif
|
|
|
414
420
|
either, or race both. JSFE builds both sets of instructions and decodes both answers (`jsfe/host`), which keeps a
|
|
415
421
|
production host and a test harness on one implementation.
|
|
416
422
|
|
|
423
|
+
### Who reads what: options and descriptions
|
|
424
|
+
|
|
425
|
+
Every model in a turn decides from a closed list, and it sees only what is declared to it. Most "the model chose wrong"
|
|
426
|
+
symptoms are an option that was never offered, or offered under words that do not describe it. Check this first.
|
|
427
|
+
|
|
428
|
+
| Reader | Decides | Reads | Never sees |
|
|
429
|
+
| --- | --- | --- | --- |
|
|
430
|
+
| Deterministic readers | keys, numbers, emails, whole-answer phrases | the reply, against the question asked and what it invites | anything not a whole, exact match |
|
|
431
|
+
| Reply ranker | what a reply does with the question asked | each offered choice's `label`; without one, its key and up to six worded `phrases` | a choice's `description`; any option not offered |
|
|
432
|
+
| Stage 1 (intent) | which primary flow starts, or None | each primary's `description` | workers; parameters |
|
|
433
|
+
| Stage 2 (intent) and argument extraction | a flow's or a pick's arguments | each parameter's `description`; for a closed choice, each choice's `description`, else its `label` | the caller's earlier messages |
|
|
434
|
+
|
|
435
|
+
**What the ranker is offered at each kind of question:**
|
|
436
|
+
|
|
437
|
+
- **A form question with a `choice` profile:** its choices, the choices of the chain's other `choice` inputs the reader
|
|
438
|
+
would accept, and a person. A firm confirmation's YES, a `current_only` choice at another question, and text are
|
|
439
|
+
never offered.
|
|
440
|
+
- **A form question with any other profile** (`pattern`, `text`, `digits`, `amount`…): no options of its own; the chain's
|
|
441
|
+
other `choice` inputs, the built-in verdicts (`answers`, `abort`, `new_request`, `irrelevant`, `concern` where
|
|
442
|
+
declared) and a person.
|
|
443
|
+
- **A flow's contextual DISPATCH** (`onResponse: "continue"`): ONLY the step's `responseChoices`, plus the built-in
|
|
444
|
+
verdicts. Code after the DISPATCH that reads the reply for other options is reachable only when a reader reads them
|
|
445
|
+
first.
|
|
446
|
+
- **A provider menu** (`whole_phrases`): every fact with phrases, every action, `done` and a person.
|
|
447
|
+
|
|
448
|
+
**The traps, each seen in production:**
|
|
449
|
+
|
|
450
|
+
1. **An option handled only by a word list or a regex is invisible to the ranker.** Said as the whole reply, the reader
|
|
451
|
+
takes it. Inside a sentence the ranker cannot pick it, so the reply becomes `answers` or `irrelevant` and the question
|
|
452
|
+
is asked again. Example (2026-11-19): "It's okay, I wanna say thank you for your time" at a product list was not
|
|
453
|
+
read as DONE, because DONE was a regex after the DISPATCH and not in its `responseChoices`. **Fix:** declare it as a
|
|
454
|
+
choice with a label.
|
|
455
|
+
2. **A choice without a label is offered as its key and phrases.** A key like `4` or `other_method` tells the model
|
|
456
|
+
nothing. Every offered choice needs a `label` written for the ranker: what the caller does or asks, and what it is
|
|
457
|
+
not.
|
|
458
|
+
3. **The ranker and stage 2 read different fields.** `label` is the ranker's; `description` is stage 2's. A choice that
|
|
459
|
+
can be both picked at its question and extracted from a first message needs both. Editing one never changes the
|
|
460
|
+
other.
|
|
461
|
+
4. **A reply that fits no offered option is `answers`.** It is not routed anywhere: the question is asked again, counted
|
|
462
|
+
as an attempt. "Asked the same question again" usually means a missing option, not a reader defect. Example
|
|
463
|
+
(2026-11-19): a refund question at the order-status prompt heard the delivery line again until the order prompt
|
|
464
|
+
offered `other`.
|
|
465
|
+
5. **Stage 1 reads only descriptions, so a description is a routing rule.** One that reads as "any mention of X"
|
|
466
|
+
starts its flow on a question about X. Write the trigger as an action or a report, and give the near misses a
|
|
467
|
+
`Not:` with the right flow (or None). Example (2026-11-19): "Quería saber sobre la tarjeta doblada" started a
|
|
468
|
+
damaged-card case until ServiceCase's `Not:` said that asking about one is None.
|
|
469
|
+
6. **A reader that is too wide takes what the ranker should decide.** Readers are tight and exact on purpose: a whole
|
|
470
|
+
answer, or a signature that fits only one field. A reader widened to catch a phrase inside a sentence will also
|
|
471
|
+
catch it where it means something else. Widen the declared options instead, and let the ranker read the sentence.
|
|
472
|
+
|
|
473
|
+
**Diagnosing a wrong verdict:** read the turn's `reply_rank` (the verdict and its scores; the row does not list what was offered) and the step's offered
|
|
474
|
+
choices as the set declares them. Was the right option offered? Was its label written for this reply? Only when both
|
|
475
|
+
are yes is it the model's judgement, which is measured live (n of N) before anything changes.
|
|
476
|
+
|
|
417
477
|
## 5. Why the transactions stay safe
|
|
418
478
|
|
|
419
479
|
The conversational freedom above never reaches the transaction directly. These are the guarantees, and where each one
|
|
@@ -547,11 +607,13 @@ it from the company's documents.
|
|
|
547
607
|
6. **Sensitive decisions are bound.** Any action that charges, cancels or cannot be reversed declares
|
|
548
608
|
`confirm: {exact: true}`: it runs only on the exact values the caller confirmed. How the YES is read is separate: a
|
|
549
609
|
charge is asked as a firm confirmation, everything else softly, unless the form declares `confirm.confirmation`.
|
|
550
|
-
7. **
|
|
610
|
+
7. **Every option a caller may say is declared where the ranker sees it,** with a label written for the ranker. A word
|
|
611
|
+
list or a regex is a fast path for a whole answer, never the only way to an option.
|
|
612
|
+
8. **Descriptions are for detection only.** A primary's description says what starts it and what does not; caller
|
|
551
613
|
wording belongs in questions and fact renderers.
|
|
552
|
-
|
|
614
|
+
9. **`call` for a closed sub-task, `DISPATCH` for what the caller asked for.** A loop that grows the stack is a design
|
|
553
615
|
bug, and the validator refuses it.
|
|
554
|
-
|
|
616
|
+
10. **Test journeys, not just units.** Run the real engine on the real set: in order, out of order, all at once,
|
|
555
617
|
corrected, a mid-form question, a change of subject, a decline, voice and text, every language.
|
|
556
618
|
|
|
557
619
|
## Where to read next
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsfe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.81.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",
|