@voctiv/agent-runtime 0.2.1 → 0.4.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 +45 -20
- package/dist/barge-in/barge-in-module.d.ts +0 -1
- package/dist/barge-in/barge-in-module.js +0 -1
- package/dist/barge-in/barge-in-service.d.ts +1 -1
- package/dist/barge-in/barge-in-service.js +33 -2
- package/dist/barge-in/barge-in-strategy.d.ts +11 -9
- package/dist/barge-in/barge-in-strategy.js +39 -23
- package/dist/barge-in/echo-cancellation.d.ts +0 -1
- package/dist/barge-in/echo-cancellation.js +0 -1
- package/dist/barge-in/echo.d.ts +0 -1
- package/dist/barge-in/echo.js +0 -1
- package/dist/barge-in/lexicon.d.ts +0 -1
- package/dist/barge-in/lexicon.js +8 -2
- package/dist/barge-in/speech-ledger.d.ts +0 -2
- package/dist/barge-in/speech-ledger.js +3 -4
- package/dist/barge-in/word-classifier.d.ts +0 -1
- package/dist/barge-in/word-classifier.js +0 -1
- package/dist/call/asr-usage.d.ts +53 -0
- package/dist/call/asr-usage.js +42 -0
- package/dist/call/async.d.ts +2 -0
- package/dist/call/async.js +14 -0
- package/dist/call/env.d.ts +88 -0
- package/dist/call/env.js +294 -0
- package/dist/call/extraction/core.d.ts +99 -0
- package/dist/call/extraction/core.js +259 -0
- package/dist/call/extraction/defaults.d.ts +10 -0
- package/dist/call/extraction/defaults.js +25 -0
- package/dist/call/extraction/index.d.ts +7 -0
- package/dist/call/extraction/index.js +24 -0
- package/dist/call/extraction/orchestrator.d.ts +144 -0
- package/dist/call/extraction/orchestrator.js +309 -0
- package/dist/call/failed-leg.d.ts +43 -0
- package/dist/call/failed-leg.js +77 -0
- package/dist/call/http.d.ts +94 -0
- package/dist/call/http.js +145 -0
- package/dist/call/ledger.d.ts +18 -0
- package/dist/call/ledger.js +80 -0
- package/dist/call/llm-tap.d.ts +7 -0
- package/dist/call/llm-tap.js +41 -0
- package/dist/call/logging.d.ts +16 -0
- package/dist/call/logging.js +92 -0
- package/dist/call/outbound.d.ts +144 -0
- package/dist/call/outbound.js +404 -0
- package/dist/call/output.d.ts +108 -0
- package/dist/call/output.js +77 -0
- package/dist/call/plan.d.ts +119 -0
- package/dist/call/plan.js +2 -0
- package/dist/call/recall.d.ts +115 -0
- package/dist/call/recall.js +312 -0
- package/dist/call/records.d.ts +9 -0
- package/dist/call/records.js +71 -0
- package/dist/call/report.d.ts +65 -0
- package/dist/call/report.js +263 -0
- package/dist/call/sanitize.d.ts +16 -0
- package/dist/call/sanitize.js +72 -0
- package/dist/call/sip.d.ts +111 -0
- package/dist/call/sip.js +212 -0
- package/dist/call/voicemail.d.ts +159 -0
- package/dist/call/voicemail.js +246 -0
- package/dist/core/call-disposables.d.ts +2 -2
- package/dist/core/call-disposables.js +8 -3
- package/dist/core/call-ended-budget.d.ts +11 -0
- package/dist/core/call-ended-budget.js +31 -0
- package/dist/core/container.d.ts +1 -3
- package/dist/core/container.js +9 -49
- package/dist/core/create-agent-script.d.ts +6 -1
- package/dist/core/create-agent-script.js +161 -28
- package/dist/core/decorators.d.ts +0 -1
- package/dist/core/decorators.js +0 -1
- package/dist/core/define-module.d.ts +0 -1
- package/dist/core/define-module.js +0 -1
- package/dist/core/dump-policy.d.ts +0 -1
- package/dist/core/dump-policy.js +0 -1
- package/dist/core/hooks.d.ts +15 -4
- package/dist/core/hooks.js +0 -1
- package/dist/core/media-bootstrap.d.ts +19 -4
- package/dist/core/media-bootstrap.js +53 -13
- package/dist/core/open-timeout.d.ts +12 -0
- package/dist/core/open-timeout.js +48 -0
- package/dist/core/provide-media.d.ts +0 -8
- package/dist/core/provide-media.js +1 -22
- package/dist/core/runtime-events.d.ts +28 -0
- package/dist/{llm/llm-module.js → core/runtime-events.js} +19 -16
- package/dist/core/tokens.d.ts +0 -10
- package/dist/core/tokens.js +0 -1
- package/dist/core/types.d.ts +0 -1
- package/dist/core/types.js +0 -1
- package/dist/core/version.d.ts +2 -3
- package/dist/core/version.js +2 -3
- package/dist/dialog/dialog-definition.d.ts +0 -5
- package/dist/dialog/dialog-definition.js +1 -6
- package/dist/dialog/dialog-ports.d.ts +3 -1
- package/dist/dialog/dialog-ports.js +10 -2
- package/dist/dialog/online-call-host.d.ts +26 -4
- package/dist/dialog/online-call-host.js +94 -12
- package/dist/dialog/online-call-module.d.ts +5 -11
- package/dist/dialog/online-call-module.js +4 -36
- package/dist/dialog/turn-metrics.d.ts +46 -0
- package/dist/dialog/turn-metrics.js +141 -0
- package/dist/dialog-events/active-media.d.ts +50 -2
- package/dist/dialog-events/active-media.js +146 -34
- package/dist/dialog-events/event-source.d.ts +0 -1
- package/dist/dialog-events/event-source.js +0 -1
- package/dist/dialog-events/virtual-finals-module.d.ts +0 -1
- package/dist/dialog-events/virtual-finals-module.js +0 -1
- package/dist/dialog-events/virtual-finals.d.ts +2 -1
- package/dist/dialog-events/virtual-finals.js +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +8 -26
- package/dist/lifecycle/lifecycle.d.ts +25 -3
- package/dist/lifecycle/lifecycle.js +92 -14
- package/dist/result/result-store.d.ts +0 -1
- package/dist/result/result-store.js +0 -1
- package/dist/templates/authoring.d.ts +222 -0
- package/dist/templates/authoring.js +2 -0
- package/dist/templates/builder/agent.d.ts +34 -0
- package/dist/templates/builder/agent.js +87 -0
- package/dist/templates/builder/blocks.d.ts +54 -0
- package/dist/templates/builder/blocks.js +92 -0
- package/dist/templates/builder/data-check.d.ts +2 -0
- package/dist/templates/builder/data-check.js +61 -0
- package/dist/templates/builder/draft.d.ts +73 -0
- package/dist/templates/builder/draft.js +142 -0
- package/dist/templates/builder/index.d.ts +8 -0
- package/dist/templates/builder/index.js +55 -0
- package/dist/templates/builder/presets.d.ts +34 -0
- package/dist/templates/builder/presets.js +45 -0
- package/dist/templates/builder/spec-of.d.ts +13 -0
- package/dist/templates/builder/spec-of.js +18 -0
- package/dist/templates/builder/steps.d.ts +25 -0
- package/dist/templates/builder/steps.js +27 -0
- package/dist/templates/business/adapter.d.ts +12 -0
- package/dist/templates/business/adapter.js +980 -0
- package/dist/templates/business/agent-integrations.d.ts +24 -0
- package/dist/templates/business/agent-integrations.js +233 -0
- package/dist/templates/business/extraction-rules-transcript.d.ts +158 -0
- package/dist/templates/business/extraction-rules-transcript.js +405 -0
- package/dist/templates/business/extraction-rules.d.ts +107 -0
- package/dist/templates/business/extraction-rules.js +267 -0
- package/dist/templates/business/index.d.ts +6 -0
- package/dist/{result → templates/business}/index.js +8 -2
- package/dist/templates/business/input.d.ts +56 -0
- package/dist/templates/business/input.js +299 -0
- package/dist/templates/business/integration-data.d.ts +87 -0
- package/dist/templates/business/integration-data.js +312 -0
- package/dist/templates/business/integrations.d.ts +76 -0
- package/dist/templates/business/integrations.js +535 -0
- package/dist/templates/business/legs-policy.d.ts +43 -0
- package/dist/templates/business/legs-policy.js +268 -0
- package/dist/templates/business/report-label.d.ts +7 -0
- package/dist/templates/business/report-label.js +29 -0
- package/dist/templates/business/report.d.ts +67 -0
- package/dist/templates/business/report.js +284 -0
- package/dist/templates/business/result-catalog.d.ts +142 -0
- package/dist/templates/business/result-catalog.js +208 -0
- package/dist/templates/business/result-rules.d.ts +105 -0
- package/dist/templates/business/result-rules.js +167 -0
- package/dist/templates/business/results.d.ts +73 -0
- package/dist/templates/business/results.js +183 -0
- package/dist/templates/business/rule-env.d.ts +18 -0
- package/dist/templates/business/rule-env.js +38 -0
- package/dist/templates/business/sources.d.ts +76 -0
- package/dist/templates/business/sources.js +239 -0
- package/dist/templates/business/test-presets.d.ts +10 -0
- package/dist/templates/business/test-presets.js +68 -0
- package/dist/templates/catalog-match/block.d.ts +32 -0
- package/dist/templates/catalog-match/block.js +95 -0
- package/dist/templates/catalog-match/catalog.d.ts +77 -0
- package/dist/templates/catalog-match/catalog.js +222 -0
- package/dist/templates/catalog-match/recognizer.d.ts +44 -0
- package/dist/templates/catalog-match/recognizer.js +206 -0
- package/dist/templates/catalog-match/reconcile.d.ts +4 -0
- package/dist/templates/catalog-match/reconcile.js +39 -0
- package/dist/templates/catalog-match/request.d.ts +57 -0
- package/dist/templates/catalog-match/request.js +139 -0
- package/dist/templates/catalog-match/types.d.ts +197 -0
- package/dist/templates/catalog-match/types.js +2 -0
- package/dist/templates/catalog-match/verify.d.ts +76 -0
- package/dist/templates/catalog-match/verify.js +220 -0
- package/dist/templates/decision-model/index.d.ts +52 -0
- package/dist/templates/decision-model/index.js +68 -0
- package/dist/templates/engine/asr-picks.d.ts +11 -0
- package/dist/templates/engine/asr-picks.js +44 -0
- package/dist/templates/engine/call.d.ts +104 -0
- package/dist/templates/engine/call.js +322 -0
- package/dist/templates/engine/config.d.ts +447 -0
- package/dist/templates/engine/config.js +493 -0
- package/dist/templates/engine/define.d.ts +1 -0
- package/dist/templates/engine/define.js +9 -0
- package/dist/templates/engine/dialog.d.ts +253 -0
- package/dist/templates/engine/dialog.js +167 -0
- package/dist/templates/engine/echo-numbers.d.ts +7 -0
- package/dist/templates/engine/echo-numbers.js +19 -0
- package/dist/templates/engine/expand.d.ts +6 -0
- package/dist/templates/engine/expand.js +125 -0
- package/dist/templates/engine/filters.d.ts +81 -0
- package/dist/templates/engine/filters.js +654 -0
- package/dist/templates/engine/hook-state.d.ts +18 -0
- package/dist/templates/engine/hook-state.js +100 -0
- package/dist/templates/engine/hooks.d.ts +51 -0
- package/dist/templates/engine/hooks.js +310 -0
- package/dist/templates/engine/index.d.ts +13 -0
- package/dist/templates/engine/index.js +30 -0
- package/dist/templates/engine/language-vars.d.ts +6 -0
- package/dist/templates/engine/language-vars.js +40 -0
- package/dist/templates/engine/language.d.ts +32 -0
- package/dist/templates/engine/language.js +155 -0
- package/dist/templates/engine/lookup.d.ts +20 -0
- package/dist/templates/engine/lookup.js +52 -0
- package/dist/templates/engine/match.d.ts +48 -0
- package/dist/templates/engine/match.js +253 -0
- package/dist/templates/engine/media.d.ts +428 -0
- package/dist/templates/engine/media.js +1240 -0
- package/dist/templates/engine/script.d.ts +11 -0
- package/dist/templates/engine/script.js +69 -0
- package/dist/templates/engine/turns/actions.d.ts +5 -0
- package/dist/templates/engine/turns/actions.js +128 -0
- package/dist/templates/engine/turns/carry.d.ts +15 -0
- package/dist/templates/engine/turns/carry.js +74 -0
- package/dist/templates/engine/turns/choices-offers.d.ts +21 -0
- package/dist/templates/engine/turns/choices-offers.js +143 -0
- package/dist/templates/engine/turns/choices.d.ts +22 -0
- package/dist/templates/engine/turns/choices.js +141 -0
- package/dist/templates/engine/turns/closing-guard.d.ts +73 -0
- package/dist/templates/engine/turns/closing-guard.js +162 -0
- package/dist/templates/engine/turns/closing.d.ts +10 -0
- package/dist/templates/engine/turns/closing.js +82 -0
- package/dist/templates/engine/turns/compile-forms.d.ts +24 -0
- package/dist/templates/engine/turns/compile-forms.js +68 -0
- package/dist/templates/engine/turns/context.d.ts +96 -0
- package/dist/templates/engine/turns/context.js +158 -0
- package/dist/templates/engine/turns/events.d.ts +409 -0
- package/dist/templates/engine/turns/events.js +5 -0
- package/dist/templates/engine/turns/hook-forms.d.ts +62 -0
- package/dist/templates/engine/turns/hook-forms.js +79 -0
- package/dist/templates/engine/turns/ladders.d.ts +42 -0
- package/dist/templates/engine/turns/ladders.js +119 -0
- package/dist/templates/engine/turns/language.d.ts +8 -0
- package/dist/templates/engine/turns/language.js +121 -0
- package/dist/templates/engine/turns/notes-dates.d.ts +9 -0
- package/dist/templates/engine/turns/notes-dates.js +42 -0
- package/dist/templates/engine/turns/notes-detect.d.ts +13 -0
- package/dist/templates/engine/turns/notes-detect.js +36 -0
- package/dist/templates/engine/turns/notes.d.ts +27 -0
- package/dist/templates/engine/turns/notes.js +176 -0
- package/dist/templates/engine/turns/opening.d.ts +34 -0
- package/dist/templates/engine/turns/opening.js +306 -0
- package/dist/templates/engine/turns/overtalk.d.ts +21 -0
- package/dist/templates/engine/turns/overtalk.js +247 -0
- package/dist/templates/engine/turns/pending.d.ts +9 -0
- package/dist/templates/engine/turns/pending.js +88 -0
- package/dist/templates/engine/turns/reply-rules.d.ts +184 -0
- package/dist/templates/engine/turns/reply-rules.js +335 -0
- package/dist/templates/engine/turns/rules.d.ts +20 -0
- package/dist/templates/engine/turns/rules.js +144 -0
- package/dist/templates/engine/turns/silence.d.ts +7 -0
- package/dist/templates/engine/turns/silence.js +127 -0
- package/dist/templates/engine/turns/state-spec.d.ts +305 -0
- package/dist/templates/engine/turns/state-spec.js +2 -0
- package/dist/templates/engine/turns/state.d.ts +38 -0
- package/dist/templates/engine/turns/state.js +101 -0
- package/dist/templates/engine/turns/tracking.d.ts +50 -0
- package/dist/templates/engine/turns/tracking.js +184 -0
- package/dist/templates/engine/turns/transfer.d.ts +19 -0
- package/dist/templates/engine/turns/transfer.js +93 -0
- package/dist/templates/engine/turns/turn.d.ts +17 -0
- package/dist/templates/engine/turns/turn.js +363 -0
- package/dist/templates/engine/turns/voicemail.d.ts +8 -0
- package/dist/templates/engine/turns/voicemail.js +101 -0
- package/dist/templates/engine/variants.d.ts +36 -0
- package/dist/templates/engine/variants.js +159 -0
- package/dist/templates/engine/voice-dialog.d.ts +24 -0
- package/dist/templates/engine/voice-dialog.js +157 -0
- package/dist/templates/engine/voice.d.ts +174 -0
- package/dist/templates/engine/voice.js +1337 -0
- package/dist/templates/expr/caller-after.d.ts +20 -0
- package/dist/templates/expr/caller-after.js +53 -0
- package/dist/templates/expr/check.d.ts +19 -0
- package/dist/templates/expr/check.js +314 -0
- package/dist/templates/expr/compiled.d.ts +8 -0
- package/dist/templates/expr/compiled.js +8 -0
- package/dist/templates/expr/context.d.ts +28 -0
- package/dist/templates/expr/context.js +55 -0
- package/dist/templates/expr/day-table.d.ts +4 -0
- package/dist/templates/expr/day-table.js +80 -0
- package/dist/templates/expr/evaluate.d.ts +26 -0
- package/dist/templates/expr/evaluate.js +885 -0
- package/dist/templates/expr/facts.d.ts +7 -0
- package/dist/templates/expr/facts.js +81 -0
- package/dist/templates/expr/index.d.ts +4 -0
- package/dist/templates/expr/index.js +11 -0
- package/dist/templates/expr/line-tally.d.ts +64 -0
- package/dist/templates/expr/line-tally.js +88 -0
- package/dist/templates/expr/matchers-state.d.ts +23 -0
- package/dist/templates/expr/matchers-state.js +37 -0
- package/dist/templates/expr/matchers.d.ts +12 -0
- package/dist/templates/expr/matchers.js +99 -0
- package/dist/templates/expr/readers.d.ts +14 -0
- package/dist/templates/expr/readers.js +351 -0
- package/dist/templates/expr/slots.d.ts +14 -0
- package/dist/templates/expr/slots.js +678 -0
- package/dist/templates/expr/template.d.ts +12 -0
- package/dist/templates/expr/template.js +76 -0
- package/dist/templates/expr/test-call.d.ts +8 -0
- package/dist/templates/expr/test-call.js +32 -0
- package/dist/templates/expr/transcript.d.ts +36 -0
- package/dist/templates/expr/transcript.js +394 -0
- package/dist/templates/expr/types.d.ts +1011 -0
- package/dist/templates/expr/types.js +2 -0
- package/dist/templates/expr/values.d.ts +42 -0
- package/dist/templates/expr/values.js +166 -0
- package/dist/templates/expr/voice-ops.d.ts +26 -0
- package/dist/templates/expr/voice-ops.js +85 -0
- package/dist/templates/helpers/decision.d.ts +55 -0
- package/dist/templates/helpers/decision.js +83 -0
- package/dist/templates/helpers/fuzzy.d.ts +9 -0
- package/dist/templates/helpers/fuzzy.js +44 -0
- package/dist/templates/helpers/index.d.ts +6 -0
- package/dist/templates/helpers/index.js +35 -0
- package/dist/templates/index.d.ts +9 -0
- package/dist/templates/index.js +68 -0
- package/dist/templates/integration-forms.d.ts +252 -0
- package/dist/templates/integration-forms.js +2 -0
- package/dist/templates/knowledge/block.d.ts +44 -0
- package/dist/templates/knowledge/block.js +199 -0
- package/dist/templates/knowledge/dense.d.ts +87 -0
- package/dist/templates/knowledge/dense.js +158 -0
- package/dist/templates/knowledge/flow.d.ts +328 -0
- package/dist/templates/knowledge/flow.js +509 -0
- package/dist/templates/knowledge/retriever.d.ts +75 -0
- package/dist/templates/knowledge/retriever.js +204 -0
- package/dist/templates/knowledge/service.d.ts +77 -0
- package/dist/templates/knowledge/service.js +316 -0
- package/dist/templates/knowledge/text.d.ts +31 -0
- package/dist/templates/knowledge/text.js +66 -0
- package/dist/templates/knowledge/types.d.ts +120 -0
- package/dist/templates/knowledge/types.js +2 -0
- package/dist/templates/locale.d.ts +259 -0
- package/dist/templates/locale.js +4 -0
- package/dist/templates/locales/en-lexicons.d.ts +9 -0
- package/dist/templates/locales/en-lexicons.js +101 -0
- package/dist/templates/locales/en.d.ts +132 -0
- package/dist/templates/locales/en.js +261 -0
- package/dist/templates/locales/es.d.ts +65 -0
- package/dist/templates/locales/es.js +208 -0
- package/dist/templates/locales/hi.d.ts +47 -0
- package/dist/templates/locales/hi.js +235 -0
- package/dist/templates/locales/id.d.ts +43 -0
- package/dist/templates/locales/id.js +127 -0
- package/dist/templates/locales/index.d.ts +34 -0
- package/dist/templates/locales/index.js +112 -0
- package/dist/templates/locales/kk-lexicons.d.ts +22 -0
- package/dist/templates/locales/kk-lexicons.js +89 -0
- package/dist/templates/locales/kk.d.ts +140 -0
- package/dist/templates/locales/kk.js +306 -0
- package/dist/templates/locales/kn.d.ts +29 -0
- package/dist/templates/locales/kn.js +22 -0
- package/dist/templates/locales/listen-only.d.ts +15 -0
- package/dist/templates/locales/listen-only.js +27 -0
- package/dist/templates/locales/ms-lexicons.d.ts +13 -0
- package/dist/templates/locales/ms-lexicons.js +113 -0
- package/dist/templates/locales/ms.d.ts +76 -0
- package/dist/templates/locales/ms.js +179 -0
- package/dist/templates/locales/parse.d.ts +86 -0
- package/dist/templates/locales/parse.js +461 -0
- package/dist/templates/locales/ru-lexicons.d.ts +27 -0
- package/dist/templates/locales/ru-lexicons.js +127 -0
- package/dist/templates/locales/ru-stem.d.ts +2 -0
- package/dist/templates/locales/ru-stem.js +53 -0
- package/dist/templates/locales/ru.d.ts +143 -0
- package/dist/templates/locales/ru.js +387 -0
- package/dist/templates/locales/shared.d.ts +122 -0
- package/dist/templates/locales/shared.js +318 -0
- package/dist/templates/locales/ta.d.ts +29 -0
- package/dist/templates/locales/ta.js +22 -0
- package/dist/templates/locales/te.d.ts +29 -0
- package/dist/templates/locales/te.js +22 -0
- package/dist/templates/locales/tl-lexicons.d.ts +2 -0
- package/dist/templates/locales/tl-lexicons.js +230 -0
- package/dist/templates/locales/tl.d.ts +59 -0
- package/dist/templates/locales/tl.js +82 -0
- package/dist/templates/locales/vi.d.ts +59 -0
- package/dist/templates/locales/vi.js +160 -0
- package/dist/templates/locales/word-regex.d.ts +13 -0
- package/dist/templates/locales/word-regex.js +43 -0
- package/dist/templates/locales/words-kk.d.ts +2 -0
- package/dist/templates/locales/words-kk.js +23 -0
- package/dist/templates/locales/words-ru.d.ts +4 -0
- package/dist/templates/locales/words-ru.js +92 -0
- package/dist/templates/spec.d.ts +2856 -0
- package/dist/templates/spec.js +2 -0
- package/dist/testing/fake-channel.d.ts +0 -1
- package/dist/testing/fake-channel.js +0 -1
- package/dist/testing/index.d.ts +24 -1
- package/dist/testing/index.js +117 -2
- package/dist/voice/call-voice.d.ts +581 -0
- package/dist/voice/call-voice.js +1399 -0
- package/dist/voice/intent-interrupt.d.ts +32 -0
- package/dist/voice/intent-interrupt.js +91 -0
- package/dist/voice/self-echo.d.ts +28 -0
- package/dist/voice/self-echo.js +135 -0
- package/dist/voice/sentence-tag.d.ts +5 -0
- package/dist/voice/sentence-tag.js +42 -0
- package/dist/voice/speech-leak.d.ts +74 -0
- package/dist/voice/speech-leak.js +216 -0
- package/dist/voice/transfer.d.ts +90 -0
- package/dist/voice/transfer.js +331 -0
- package/dist/voice/turn-timing.d.ts +293 -0
- package/dist/voice/turn-timing.js +567 -0
- package/docs/README.md +3 -6
- package/docs/framework/README.md +6 -10
- package/docs/framework/architecture.md +2 -2
- package/docs/framework/container-and-di.md +1 -2
- package/docs/framework/invariants.md +6 -6
- package/docs/framework/package-layout.md +16 -23
- package/docs/framework/testing.md +8 -6
- package/package.json +10 -54
- package/skill/SKILL.md +213 -0
- package/skill/references/agent-file.md +230 -0
- package/skill/references/blocks.md +246 -0
- package/skill/references/builder.md +163 -0
- package/skill/references/business.md +659 -0
- package/skill/references/conversation.md +586 -0
- package/skill/references/core.md +89 -0
- package/skill/references/examples.md +73 -0
- package/skill/references/expressions.md +342 -0
- package/skill/references/format.md +114 -0
- package/skill/references/locales.md +149 -0
- package/skill/references/migration.md +133 -0
- package/skill/references/new-agent.md +81 -0
- package/skill/references/porting.md +109 -0
- package/templates/agent/README.md +50 -0
- package/templates/agent/package.json +24 -0
- package/templates/agent/src/agent.spec.ts +51 -0
- package/templates/agent/src/agent.ts +268 -0
- package/templates/agent/src/entities.ts +44 -0
- package/templates/agent/src/prompt.sqrl +21 -0
- package/templates/agent/src/variants/fixed-opening.ts +144 -0
- package/templates/agent/tsconfig.build.json +4 -0
- package/templates/agent/tsconfig.json +18 -0
- package/dist/asr/index.d.ts +0 -3
- package/dist/asr/index.d.ts.map +0 -1
- package/dist/asr/index.js +0 -6
- package/dist/asr/index.js.map +0 -1
- package/dist/barge-in/barge-in-module.d.ts.map +0 -1
- package/dist/barge-in/barge-in-module.js.map +0 -1
- package/dist/barge-in/barge-in-service.d.ts.map +0 -1
- package/dist/barge-in/barge-in-service.js.map +0 -1
- package/dist/barge-in/barge-in-strategy.d.ts.map +0 -1
- package/dist/barge-in/barge-in-strategy.js.map +0 -1
- package/dist/barge-in/echo-cancellation.d.ts.map +0 -1
- package/dist/barge-in/echo-cancellation.js.map +0 -1
- package/dist/barge-in/echo.d.ts.map +0 -1
- package/dist/barge-in/echo.js.map +0 -1
- package/dist/barge-in/index.d.ts +0 -13
- package/dist/barge-in/index.d.ts.map +0 -1
- package/dist/barge-in/index.js +0 -28
- package/dist/barge-in/index.js.map +0 -1
- package/dist/barge-in/lexicon.d.ts.map +0 -1
- package/dist/barge-in/lexicon.js.map +0 -1
- package/dist/barge-in/lexicons/en.d.ts +0 -2
- package/dist/barge-in/lexicons/en.d.ts.map +0 -1
- package/dist/barge-in/lexicons/en.js +0 -36
- package/dist/barge-in/lexicons/en.js.map +0 -1
- package/dist/barge-in/lexicons/id.d.ts +0 -2
- package/dist/barge-in/lexicons/id.d.ts.map +0 -1
- package/dist/barge-in/lexicons/id.js +0 -39
- package/dist/barge-in/lexicons/id.js.map +0 -1
- package/dist/barge-in/lexicons/index.d.ts +0 -10
- package/dist/barge-in/lexicons/index.d.ts.map +0 -1
- package/dist/barge-in/lexicons/index.js +0 -11
- package/dist/barge-in/lexicons/index.js.map +0 -1
- package/dist/barge-in/lexicons/ru.d.ts +0 -2
- package/dist/barge-in/lexicons/ru.d.ts.map +0 -1
- package/dist/barge-in/lexicons/ru.js +0 -39
- package/dist/barge-in/lexicons/ru.js.map +0 -1
- package/dist/barge-in/speech-ledger.d.ts.map +0 -1
- package/dist/barge-in/speech-ledger.js.map +0 -1
- package/dist/barge-in/word-classifier.d.ts.map +0 -1
- package/dist/barge-in/word-classifier.js.map +0 -1
- package/dist/bridge/bridge.d.ts +0 -28
- package/dist/bridge/bridge.d.ts.map +0 -1
- package/dist/bridge/bridge.js +0 -117
- package/dist/bridge/bridge.js.map +0 -1
- package/dist/bridge/index.d.ts +0 -3
- package/dist/bridge/index.d.ts.map +0 -1
- package/dist/bridge/index.js +0 -8
- package/dist/bridge/index.js.map +0 -1
- package/dist/core/call-disposables.d.ts.map +0 -1
- package/dist/core/call-disposables.js.map +0 -1
- package/dist/core/container.d.ts.map +0 -1
- package/dist/core/container.js.map +0 -1
- package/dist/core/create-agent-script.d.ts.map +0 -1
- package/dist/core/create-agent-script.js.map +0 -1
- package/dist/core/decorators.d.ts.map +0 -1
- package/dist/core/decorators.js.map +0 -1
- package/dist/core/define-module.d.ts.map +0 -1
- package/dist/core/define-module.js.map +0 -1
- package/dist/core/dump-policy.d.ts.map +0 -1
- package/dist/core/dump-policy.js.map +0 -1
- package/dist/core/hooks.d.ts.map +0 -1
- package/dist/core/hooks.js.map +0 -1
- package/dist/core/index.d.ts +0 -16
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -36
- package/dist/core/index.js.map +0 -1
- package/dist/core/media-bootstrap.d.ts.map +0 -1
- package/dist/core/media-bootstrap.js.map +0 -1
- package/dist/core/provide-media.d.ts.map +0 -1
- package/dist/core/provide-media.js.map +0 -1
- package/dist/core/tokens.d.ts.map +0 -1
- package/dist/core/tokens.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/version.d.ts.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/dialog/basic-ports.d.ts +0 -54
- package/dist/dialog/basic-ports.d.ts.map +0 -1
- package/dist/dialog/basic-ports.js +0 -206
- package/dist/dialog/basic-ports.js.map +0 -1
- package/dist/dialog/define-dialog.d.ts +0 -21
- package/dist/dialog/define-dialog.d.ts.map +0 -1
- package/dist/dialog/define-dialog.js +0 -21
- package/dist/dialog/define-dialog.js.map +0 -1
- package/dist/dialog/dialog-definition.d.ts.map +0 -1
- package/dist/dialog/dialog-definition.js.map +0 -1
- package/dist/dialog/dialog-ports.d.ts.map +0 -1
- package/dist/dialog/dialog-ports.js.map +0 -1
- package/dist/dialog/index.d.ts +0 -7
- package/dist/dialog/index.d.ts.map +0 -1
- package/dist/dialog/index.js +0 -23
- package/dist/dialog/index.js.map +0 -1
- package/dist/dialog/online-call-host.d.ts.map +0 -1
- package/dist/dialog/online-call-host.js.map +0 -1
- package/dist/dialog/online-call-module.d.ts.map +0 -1
- package/dist/dialog/online-call-module.js.map +0 -1
- package/dist/dialog-events/active-media.d.ts.map +0 -1
- package/dist/dialog-events/active-media.js.map +0 -1
- package/dist/dialog-events/event-source.d.ts.map +0 -1
- package/dist/dialog-events/event-source.js.map +0 -1
- package/dist/dialog-events/index.d.ts +0 -8
- package/dist/dialog-events/index.d.ts.map +0 -1
- package/dist/dialog-events/index.js +0 -24
- package/dist/dialog-events/index.js.map +0 -1
- package/dist/dialog-events/max-listen-source.d.ts +0 -27
- package/dist/dialog-events/max-listen-source.d.ts.map +0 -1
- package/dist/dialog-events/max-listen-source.js +0 -98
- package/dist/dialog-events/max-listen-source.js.map +0 -1
- package/dist/dialog-events/overtalk-source.d.ts +0 -61
- package/dist/dialog-events/overtalk-source.d.ts.map +0 -1
- package/dist/dialog-events/overtalk-source.js +0 -232
- package/dist/dialog-events/overtalk-source.js.map +0 -1
- package/dist/dialog-events/silence-source.d.ts +0 -32
- package/dist/dialog-events/silence-source.d.ts.map +0 -1
- package/dist/dialog-events/silence-source.js +0 -128
- package/dist/dialog-events/silence-source.js.map +0 -1
- package/dist/dialog-events/virtual-finals-module.d.ts.map +0 -1
- package/dist/dialog-events/virtual-finals-module.js.map +0 -1
- package/dist/dialog-events/virtual-finals.d.ts.map +0 -1
- package/dist/dialog-events/virtual-finals.js.map +0 -1
- package/dist/dtmf/dtmf.d.ts +0 -27
- package/dist/dtmf/dtmf.d.ts.map +0 -1
- package/dist/dtmf/dtmf.js +0 -87
- package/dist/dtmf/dtmf.js.map +0 -1
- package/dist/dtmf/index.d.ts +0 -3
- package/dist/dtmf/index.d.ts.map +0 -1
- package/dist/dtmf/index.js +0 -8
- package/dist/dtmf/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lifecycle/index.d.ts +0 -3
- package/dist/lifecycle/index.d.ts.map +0 -1
- package/dist/lifecycle/index.js +0 -9
- package/dist/lifecycle/index.js.map +0 -1
- package/dist/lifecycle/lifecycle.d.ts.map +0 -1
- package/dist/lifecycle/lifecycle.js.map +0 -1
- package/dist/llm/index.d.ts +0 -7
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/index.js +0 -18
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/llm-markers-module.d.ts +0 -15
- package/dist/llm/llm-markers-module.d.ts.map +0 -1
- package/dist/llm/llm-markers-module.js +0 -48
- package/dist/llm/llm-markers-module.js.map +0 -1
- package/dist/llm/llm-markers.d.ts +0 -36
- package/dist/llm/llm-markers.d.ts.map +0 -1
- package/dist/llm/llm-markers.js +0 -210
- package/dist/llm/llm-markers.js.map +0 -1
- package/dist/llm/llm-module.d.ts +0 -20
- package/dist/llm/llm-module.d.ts.map +0 -1
- package/dist/llm/llm-module.js.map +0 -1
- package/dist/match/index.d.ts +0 -3
- package/dist/match/index.d.ts.map +0 -1
- package/dist/match/index.js +0 -10
- package/dist/match/index.js.map +0 -1
- package/dist/match/match.d.ts +0 -33
- package/dist/match/match.d.ts.map +0 -1
- package/dist/match/match.js +0 -85
- package/dist/match/match.js.map +0 -1
- package/dist/outbound/index.d.ts +0 -3
- package/dist/outbound/index.d.ts.map +0 -1
- package/dist/outbound/index.js +0 -8
- package/dist/outbound/index.js.map +0 -1
- package/dist/outbound/outbound.d.ts +0 -40
- package/dist/outbound/outbound.d.ts.map +0 -1
- package/dist/outbound/outbound.js +0 -84
- package/dist/outbound/outbound.js.map +0 -1
- package/dist/result/index.d.ts +0 -2
- package/dist/result/index.d.ts.map +0 -1
- package/dist/result/index.js.map +0 -1
- package/dist/result/result-store.d.ts.map +0 -1
- package/dist/result/result-store.js.map +0 -1
- package/dist/testing/fake-channel.d.ts.map +0 -1
- package/dist/testing/fake-channel.js.map +0 -1
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/docs/agents/README.md +0 -41
- package/docs/agents/barge-in.md +0 -67
- package/docs/agents/dialog.md +0 -98
- package/docs/agents/getting-started.md +0 -142
- package/docs/agents/imports.md +0 -40
- package/docs/agents/media-and-ports.md +0 -82
- package/docs/agents/modules.md +0 -83
- package/docs/agents/phases.md +0 -83
- package/docs/framework/extending.md +0 -59
- package/docs/framework/idn-parity.md +0 -18
- package/examples/minimal-agent/README.md +0 -7
- package/examples/minimal-agent/agent.ts +0 -94
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entityView = exports.applyExtractionRules = exports.impliedResult = void 0;
|
|
4
|
+
// T5 `extraction.rules`: ordered fixes of the extracted entities (null words, trims, allow-lists, patterns, coercion,
|
|
5
|
+
// conditional sets and clears, amount repairs, transcript-backed corrections), run after `extraction.normalize` and
|
|
6
|
+
// before the result is picked from the entities. The same list as a report-only view: `report.fields.x: { entities:
|
|
7
|
+
// '*', view }`.
|
|
8
|
+
//
|
|
9
|
+
// Every rule may carry `when` (a `Condition`); it is evaluated over the running entities (`{ entity }`), the call, the
|
|
10
|
+
// pre-result (`{ fact: 'preResult' }`, also `{ fact: 'result' }`) and the locals `picked` (the result the running
|
|
11
|
+
// entities imply by priority, `null` when none) and `extracted` (the extractor's own entities).
|
|
12
|
+
const context_1 = require("../expr/context");
|
|
13
|
+
const evaluate_1 = require("../expr/evaluate");
|
|
14
|
+
const values_1 = require("../expr/values");
|
|
15
|
+
const extraction_rules_transcript_1 = require("./extraction-rules-transcript");
|
|
16
|
+
const rule_env_1 = require("./rule-env");
|
|
17
|
+
/** The result the entities imply by priority (the library's pick); `null` when none. */
|
|
18
|
+
function impliedResult(entities, defs) {
|
|
19
|
+
let best = null;
|
|
20
|
+
for (const e of defs) {
|
|
21
|
+
if (!e.implies || !entities[e.name])
|
|
22
|
+
continue;
|
|
23
|
+
const priority = e.priority ?? 0;
|
|
24
|
+
if (best === null || priority > best.priority)
|
|
25
|
+
best = { implies: e.implies, priority };
|
|
26
|
+
}
|
|
27
|
+
return best?.implies ?? null;
|
|
28
|
+
}
|
|
29
|
+
exports.impliedResult = impliedResult;
|
|
30
|
+
/** The entities after `rules` (a new object; the input is not changed). `now` fixes the clock (tests). */
|
|
31
|
+
function applyExtractionRules(spec, rules, entities, call, input, now) {
|
|
32
|
+
let out = { ...entities };
|
|
33
|
+
const defs = spec.extraction?.entities ?? [];
|
|
34
|
+
for (const rule of rules) {
|
|
35
|
+
const base = (0, rule_env_1.ruleContext)(spec, call, { entities: out, result: input.preResult, preResult: input.preResult }, now);
|
|
36
|
+
const ctx = (0, context_1.withLocals)(base, { picked: impliedResult(out, defs), extracted: input.extracted });
|
|
37
|
+
const r = rule;
|
|
38
|
+
if (r['when'] !== undefined && !(0, evaluate_1.evalCondition)(r['when'], ctx))
|
|
39
|
+
continue;
|
|
40
|
+
const t = (0, extraction_rules_transcript_1.applyTranscriptRule)(rule, out, ctx);
|
|
41
|
+
if (t !== undefined) {
|
|
42
|
+
out = t;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
out = applyOne(rule, out, ctx, defs, input);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
exports.applyExtractionRules = applyExtractionRules;
|
|
50
|
+
/** The entities as `view` would leave them, for a report row only (`{ entities: '*', view }`). */
|
|
51
|
+
function entityView(spec, view, entities, call, now) {
|
|
52
|
+
return applyExtractionRules(spec, view, entities, call, { extracted: entities, preResult: call.preResult ?? '' }, now);
|
|
53
|
+
}
|
|
54
|
+
exports.entityView = entityView;
|
|
55
|
+
// ── one rule ──────────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
function targets(entity, out) {
|
|
57
|
+
return entity === '*' ? Object.keys(out) : [entity];
|
|
58
|
+
}
|
|
59
|
+
function applyOne(rule, cur, ctx, defs, input) {
|
|
60
|
+
const r = rule;
|
|
61
|
+
if ('set' in r)
|
|
62
|
+
return setRule(rule, cur, ctx, defs, input);
|
|
63
|
+
if ('coerce' in r)
|
|
64
|
+
return coerceRule(rule, cur);
|
|
65
|
+
if ('allowed' in r || 'pattern' in r)
|
|
66
|
+
return vocabularyRule(r, cur, defs);
|
|
67
|
+
const out = { ...cur };
|
|
68
|
+
if ('replace' in r) {
|
|
69
|
+
const x = rule;
|
|
70
|
+
for (const k of targets(x.entity, out)) {
|
|
71
|
+
const v = out[k];
|
|
72
|
+
if (typeof v === 'string')
|
|
73
|
+
out[k] = v.replace(x.replace.re, x.replace.with);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
const op = r['op'];
|
|
78
|
+
const entity = r['entity'];
|
|
79
|
+
if (op === 'nullStrings') {
|
|
80
|
+
const re = r['match'] ?? /^null$/i;
|
|
81
|
+
const value = 'value' in r ? r['value'] : null;
|
|
82
|
+
for (const k of targets(entity, out)) {
|
|
83
|
+
const v = out[k];
|
|
84
|
+
if (typeof v === 'string' && test(re, v.trim()))
|
|
85
|
+
out[k] = value;
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
if (op === 'trim') {
|
|
90
|
+
for (const k of targets(entity, out))
|
|
91
|
+
if (typeof out[k] === 'string')
|
|
92
|
+
out[k] = out[k].trim();
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
if (op === 'emptyAs') {
|
|
96
|
+
for (const k of targets(entity, out))
|
|
97
|
+
if (out[k] === '')
|
|
98
|
+
out[k] = r['value'];
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
if (op === 'restoreDecimalOf' || op === 'capAt') {
|
|
102
|
+
const refs = r['refs'].map((e) => (0, evaluate_1.evalExpr)(e, ctx));
|
|
103
|
+
const ignore = r['ignore'] ?? ',';
|
|
104
|
+
const fixed = op === 'restoreDecimalOf' ? restoreDecimal(out[entity], refs, ignore) : capAt(out[entity], refs[0], ignore);
|
|
105
|
+
if (fixed !== null)
|
|
106
|
+
out[entity] = fixed;
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`[templates/extraction.rules] unknown rule ${JSON.stringify(Object.keys(r))}`);
|
|
110
|
+
}
|
|
111
|
+
function setRule(rule, cur, ctx, defs, input) {
|
|
112
|
+
// Values read the entities before the rule.
|
|
113
|
+
const values = Object.entries(rule.set).map(([k, e]) => [k, (0, evaluate_1.evalExpr)(e, ctx)]);
|
|
114
|
+
const out = rule.from === 'extracted' ? { ...input.extracted } : { ...cur };
|
|
115
|
+
for (const [k, v] of values) {
|
|
116
|
+
if (v === undefined)
|
|
117
|
+
continue;
|
|
118
|
+
if (rule.onlyPresent && !(k in out))
|
|
119
|
+
continue;
|
|
120
|
+
out[k] = v;
|
|
121
|
+
}
|
|
122
|
+
if (rule.clearAbove !== undefined) {
|
|
123
|
+
const floor = defs.find((d) => d.name === rule.clearAbove)?.priority ?? 0;
|
|
124
|
+
for (const d of defs)
|
|
125
|
+
if (d.implies && (d.priority ?? 0) > floor)
|
|
126
|
+
out[d.name] = false;
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
const COERCE_TRUE = /^(true|yes|1)$/i;
|
|
131
|
+
function coerceRule(rule, cur) {
|
|
132
|
+
const out = rule.keepOthers === false ? {} : { ...cur };
|
|
133
|
+
for (const [k, kind] of Object.entries(rule.coerce)) {
|
|
134
|
+
const v = cur[k];
|
|
135
|
+
if (kind === 'boolean')
|
|
136
|
+
out[k] = v === true || COERCE_TRUE.test(String(v ?? '').trim());
|
|
137
|
+
else if (kind === 'number') {
|
|
138
|
+
const n = typeof v === 'number' ? v : Number(String(v ?? '').replace(/[^\d.]/g, ''));
|
|
139
|
+
out[k] = Number.isFinite(n) ? n : 0;
|
|
140
|
+
}
|
|
141
|
+
else
|
|
142
|
+
out[k] = typeof v === 'string' ? v : v == null ? '' : String(v);
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
/** The values the first line starting with `marker` lists (`MARKER a, b, c`, not empty); `null` when none. */
|
|
147
|
+
function describedValues(description, marker) {
|
|
148
|
+
if (typeof description !== 'string')
|
|
149
|
+
return null;
|
|
150
|
+
for (const line of description.split('\n')) {
|
|
151
|
+
const t = line.trim();
|
|
152
|
+
if (!t.startsWith(marker))
|
|
153
|
+
continue;
|
|
154
|
+
const rest = t.slice(marker.length).trim();
|
|
155
|
+
if (!rest)
|
|
156
|
+
continue;
|
|
157
|
+
const values = new Set(rest.split(',').map((v) => v.trim()).filter(Boolean));
|
|
158
|
+
return values.size ? values : null;
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
function vocabularyRule(r, cur, defs) {
|
|
163
|
+
const out = { ...cur };
|
|
164
|
+
const entity = r['entity'];
|
|
165
|
+
const otherwise = 'otherwise' in r ? r['otherwise'] : '';
|
|
166
|
+
const nullAs = r['nullAs'] ?? 'keep';
|
|
167
|
+
const trimmed = r['write'] === 'trimmed';
|
|
168
|
+
const check = (name, accepts) => {
|
|
169
|
+
const raw = out[name];
|
|
170
|
+
if (raw == null && nullAs === 'keep')
|
|
171
|
+
return;
|
|
172
|
+
const text = typeof raw === 'string' ? raw.trim() : '';
|
|
173
|
+
if (!accepts(text))
|
|
174
|
+
out[name] = otherwise;
|
|
175
|
+
else if (trimmed)
|
|
176
|
+
out[name] = text;
|
|
177
|
+
};
|
|
178
|
+
if ('pattern' in r) {
|
|
179
|
+
const re = r['pattern'];
|
|
180
|
+
for (const k of targets(entity, out))
|
|
181
|
+
check(k, (t) => test(re, t));
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
const allowed = r['allowed'];
|
|
185
|
+
if (Array.isArray(allowed)) {
|
|
186
|
+
const set = new Set(allowed);
|
|
187
|
+
for (const k of targets(entity, out))
|
|
188
|
+
check(k, (t) => set.has(t));
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
const marker = allowed.fromDescription;
|
|
192
|
+
for (const d of defs) {
|
|
193
|
+
if (entity !== '*' && d.name !== entity)
|
|
194
|
+
continue;
|
|
195
|
+
if (!(0, values_1.isPlainObject)(d.schema) || d.schema['type'] !== 'string')
|
|
196
|
+
continue;
|
|
197
|
+
const set = describedValues(d.description, marker);
|
|
198
|
+
if (set)
|
|
199
|
+
check(d.name, (t) => set.has(t));
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
function test(re, text) {
|
|
204
|
+
re.lastIndex = 0;
|
|
205
|
+
return re.test(text);
|
|
206
|
+
}
|
|
207
|
+
// ── amounts ───────────────────────────────────────────────────────────────────────────────────
|
|
208
|
+
/** An amount as plain digits and a dot: whitespace and the `ignore` characters removed. */
|
|
209
|
+
function plain(raw, ignore) {
|
|
210
|
+
if (typeof raw === 'number' && Number.isFinite(raw))
|
|
211
|
+
return String(raw);
|
|
212
|
+
if (typeof raw !== 'string')
|
|
213
|
+
return '';
|
|
214
|
+
let s = raw.trim().replace(/\s/g, '');
|
|
215
|
+
for (const ch of ignore)
|
|
216
|
+
s = s.split(ch).join('');
|
|
217
|
+
return s;
|
|
218
|
+
}
|
|
219
|
+
/** A positive amount from an extracted value, or `null`. */
|
|
220
|
+
function positiveAmount(raw, ignore) {
|
|
221
|
+
if (typeof raw === 'number')
|
|
222
|
+
return Number.isFinite(raw) && raw > 0 ? raw : null;
|
|
223
|
+
if (typeof raw !== 'string')
|
|
224
|
+
return null;
|
|
225
|
+
const s = plain(raw, ignore);
|
|
226
|
+
if (!/^\d+(\.\d+)?$/.test(s))
|
|
227
|
+
return null;
|
|
228
|
+
const n = Number(s);
|
|
229
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
230
|
+
}
|
|
231
|
+
function restoreDecimal(raw, refs, ignore) {
|
|
232
|
+
const extracted = positiveAmount(raw, ignore);
|
|
233
|
+
if (extracted === null)
|
|
234
|
+
return null;
|
|
235
|
+
for (const ref of refs) {
|
|
236
|
+
const p = plain(ref == null ? '' : String(ref), ignore);
|
|
237
|
+
const parts = /^(\d+)\.(\d+)$/.exec(p);
|
|
238
|
+
if (!parts || /^0+$/.test(parts[2]))
|
|
239
|
+
continue;
|
|
240
|
+
const glued = Number(parts[1] + parts[2]);
|
|
241
|
+
const numeric = Number(p);
|
|
242
|
+
if (!Number.isFinite(glued) || !Number.isFinite(numeric) || glued === numeric)
|
|
243
|
+
continue;
|
|
244
|
+
if (Math.abs(extracted - glued) <= 1e-6)
|
|
245
|
+
return p;
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
/** Hundredths of a plain amount (a third decimal rounds), or `null` when not a positive plain amount. */
|
|
250
|
+
function hundredths(p) {
|
|
251
|
+
const parts = /^(\d+)(?:\.(\d+))?$/.exec(p);
|
|
252
|
+
if (!parts)
|
|
253
|
+
return null;
|
|
254
|
+
const frac = parts[2] ?? '';
|
|
255
|
+
const head = Number((frac + '00').slice(0, 2));
|
|
256
|
+
const up = frac.length > 2 && frac[2] >= '5';
|
|
257
|
+
const n = Number(parts[1]) * 100 + head + (up ? 1 : 0);
|
|
258
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
259
|
+
}
|
|
260
|
+
function capAt(raw, ref, ignore) {
|
|
261
|
+
const value = hundredths(plain(raw, ignore));
|
|
262
|
+
const cap = plain(ref == null ? '' : String(ref), ignore);
|
|
263
|
+
const limit = hundredths(cap);
|
|
264
|
+
if (value === null || limit === null || value <= limit)
|
|
265
|
+
return null;
|
|
266
|
+
return cap;
|
|
267
|
+
}
|
|
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// Business templates: the agent file's input, results, report and integrations as library code, and the adapter that
|
|
18
|
+
// turns them into the call plan of the engine.
|
|
19
|
+
__exportStar(require("./sources"), exports);
|
|
20
|
+
__exportStar(require("./input"), exports);
|
|
21
|
+
__exportStar(require("./results"), exports);
|
|
22
|
+
__exportStar(require("./report"), exports);
|
|
23
|
+
__exportStar(require("./integrations"), exports);
|
|
24
|
+
__exportStar(require("./adapter"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ScriptDialogContext } from '@voctiv/agent-sdk';
|
|
2
|
+
import type { LocaleCode, LocalePack } from '../locale';
|
|
3
|
+
import type { CallFacts, FieldSpec, InputSpec } from '../spec';
|
|
4
|
+
import { type SourceScope } from './sources';
|
|
5
|
+
/** The call's variables and what the prompt sees of them. */
|
|
6
|
+
export interface CallVars {
|
|
7
|
+
/** Every field (formatted). */
|
|
8
|
+
readonly vars: Record<string, unknown>;
|
|
9
|
+
/** The fields the prompt sees, in declaration order (`prompt: false` left out, `omitEmpty` when empty). */
|
|
10
|
+
readonly prompt: Record<string, unknown>;
|
|
11
|
+
/** `required.fields` that came out empty. */
|
|
12
|
+
readonly missing: readonly string[];
|
|
13
|
+
readonly facts: CallFacts;
|
|
14
|
+
/** Test values were switched on for this call. */
|
|
15
|
+
readonly testData: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Keeps the call variables of the current pass (built once by its prelude, again by a lookup at answer). */
|
|
18
|
+
export declare function keepCallVars(context: ScriptDialogContext, vars: CallVars): void;
|
|
19
|
+
/** The call variables of the current pass, if its prelude built them. */
|
|
20
|
+
export declare function callVarsOf(context: ScriptDialogContext): CallVars | undefined;
|
|
21
|
+
export interface BuildVarsOptions extends SourceScope {
|
|
22
|
+
/** Call languages, the first is the reply language (default: the first bundled pack is not assumed — `['en']`). */
|
|
23
|
+
readonly languages?: readonly LocaleCode[];
|
|
24
|
+
/** Wall clock of the call (default: now). */
|
|
25
|
+
readonly now?: Date;
|
|
26
|
+
/** Raw values of named fields in place of their sources (`input.lookup`); formats and later fields still apply. */
|
|
27
|
+
readonly overrides?: Readonly<Record<string, unknown>>;
|
|
28
|
+
/** Call variables set before the fields (the voice variant's `voice`); a field of the same name replaces one. */
|
|
29
|
+
readonly seed?: Readonly<Record<string, unknown>>;
|
|
30
|
+
}
|
|
31
|
+
type Format = NonNullable<FieldSpec['format']>;
|
|
32
|
+
/** A calendar day by pattern; month and weekday names from the pack (`MMM`, `ddd`: their first three letters). */
|
|
33
|
+
export declare function formatDatePattern(d: {
|
|
34
|
+
year: number;
|
|
35
|
+
month: number;
|
|
36
|
+
day: number;
|
|
37
|
+
}, pattern: string, p: LocalePack): string;
|
|
38
|
+
/**
|
|
39
|
+
* An instant (epoch ms, an ISO text or a `Date`) on the wall clock of `timeZone` by pattern: the date tokens of
|
|
40
|
+
* {@link formatDatePattern} and `HH` / `H` (hour 0-23), `mm`, `ss`. `''` for a value that is not an instant (also one
|
|
41
|
+
* outside the range of dates).
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatTimestamp(value: unknown, pattern: string, timeZone: string, p: LocalePack): string;
|
|
44
|
+
/**
|
|
45
|
+
* One value read out by a locale pack. `undefined` / `null` stay as they are, except for the kinds that read the call
|
|
46
|
+
* hour (`timeOfDayGreeting`, `timeOfDay`) or `today`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatValue(value: unknown, format: Format, code: LocaleCode, facts: CallFacts): unknown;
|
|
49
|
+
/** CMS globals the input reads (`global` / `storage` sources, the test-data switch), in field order. */
|
|
50
|
+
export declare function inputGlobalKeys(input: InputSpec): string[];
|
|
51
|
+
/**
|
|
52
|
+
* The call's variables from the `input` block. Synchronous: CMS globals must be in `scope.globals` (see
|
|
53
|
+
* {@link inputGlobalKeys} and `fetchGlobals`); a field reading a global that was not fetched reads nothing.
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildCallVars(input: InputSpec, scope: BuildVarsOptions): CallVars;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCallVars = exports.inputGlobalKeys = exports.formatValue = exports.formatTimestamp = exports.formatDatePattern = exports.callVarsOf = exports.keepCallVars = void 0;
|
|
4
|
+
const locales_1 = require("../locales");
|
|
5
|
+
const shared_1 = require("../locales/shared");
|
|
6
|
+
const context_1 = require("../expr/context");
|
|
7
|
+
const evaluate_1 = require("../expr/evaluate");
|
|
8
|
+
const readers_1 = require("../expr/readers");
|
|
9
|
+
const sources_1 = require("./sources");
|
|
10
|
+
const passVars = new WeakMap();
|
|
11
|
+
/** Keeps the call variables of the current pass (built once by its prelude, again by a lookup at answer). */
|
|
12
|
+
function keepCallVars(context, vars) {
|
|
13
|
+
passVars.set(context, vars);
|
|
14
|
+
}
|
|
15
|
+
exports.keepCallVars = keepCallVars;
|
|
16
|
+
/** The call variables of the current pass, if its prelude built them. */
|
|
17
|
+
function callVarsOf(context) {
|
|
18
|
+
return passVars.get(context);
|
|
19
|
+
}
|
|
20
|
+
exports.callVarsOf = callVarsOf;
|
|
21
|
+
function isGroup(f) {
|
|
22
|
+
return 'group' in f;
|
|
23
|
+
}
|
|
24
|
+
function pack(code) {
|
|
25
|
+
const p = (0, locales_1.getLocale)(code);
|
|
26
|
+
if (!p)
|
|
27
|
+
throw new Error(`[templates/input] no locale pack for "${code}"`);
|
|
28
|
+
return p;
|
|
29
|
+
}
|
|
30
|
+
/** Text as read from a source: strings trimmed, numbers as their decimal text. */
|
|
31
|
+
function asRead(v) {
|
|
32
|
+
if (typeof v === 'string')
|
|
33
|
+
return v.trim();
|
|
34
|
+
if (typeof v === 'number' && Number.isFinite(v))
|
|
35
|
+
return String(v);
|
|
36
|
+
return v;
|
|
37
|
+
}
|
|
38
|
+
const PATTERN_TOKEN = /YYYY|YY|MMMM|MMM|MM|M|dddd|ddd|DD|D/g;
|
|
39
|
+
/** A calendar day by pattern; month and weekday names from the pack (`MMM`, `ddd`: their first three letters). */
|
|
40
|
+
function formatDatePattern(d, pattern, p) {
|
|
41
|
+
const parts = (0, shared_1.partsOf)(d);
|
|
42
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
43
|
+
return pattern.replace(PATTERN_TOKEN, (t) => {
|
|
44
|
+
switch (t) {
|
|
45
|
+
case 'YYYY': return String(parts.year);
|
|
46
|
+
case 'YY': return two(parts.year % 100);
|
|
47
|
+
case 'MMMM': return p.format.months[parts.month - 1];
|
|
48
|
+
case 'MMM': return p.format.months[parts.month - 1].slice(0, 3);
|
|
49
|
+
case 'MM': return two(parts.month);
|
|
50
|
+
case 'M': return String(parts.month);
|
|
51
|
+
case 'dddd': return p.format.weekdays[parts.weekday];
|
|
52
|
+
case 'ddd': return p.format.weekdays[parts.weekday].slice(0, 3);
|
|
53
|
+
case 'DD': return two(parts.day);
|
|
54
|
+
default: return String(parts.day);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.formatDatePattern = formatDatePattern;
|
|
59
|
+
const TIME_TOKEN = /YYYY|YY|MMMM|MMM|MM|M|dddd|ddd|DD|D|HH|H|mm|ss/g;
|
|
60
|
+
/**
|
|
61
|
+
* An instant (epoch ms, an ISO text or a `Date`) on the wall clock of `timeZone` by pattern: the date tokens of
|
|
62
|
+
* {@link formatDatePattern} and `HH` / `H` (hour 0-23), `mm`, `ss`. `''` for a value that is not an instant (also one
|
|
63
|
+
* outside the range of dates).
|
|
64
|
+
*/
|
|
65
|
+
function formatTimestamp(value, pattern, timeZone, p) {
|
|
66
|
+
const ms = value instanceof Date ? value.getTime() : typeof value === 'number' ? value : typeof value === 'string' ? Date.parse(value) : NaN;
|
|
67
|
+
// Outside the range of dates (an epoch in micro- or nanoseconds) is not an instant either.
|
|
68
|
+
if (!Number.isFinite(ms) || Number.isNaN(new Date(ms).getTime()))
|
|
69
|
+
return '';
|
|
70
|
+
const z = (0, shared_1.zonedParts)(new Date(ms), timeZone);
|
|
71
|
+
const sec = new Date(ms).getUTCSeconds();
|
|
72
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
73
|
+
return pattern.replace(TIME_TOKEN, (t) => {
|
|
74
|
+
switch (t) {
|
|
75
|
+
case 'HH': return two(z.hour);
|
|
76
|
+
case 'H': return String(z.hour);
|
|
77
|
+
case 'mm': return two(z.minute);
|
|
78
|
+
case 'ss': return two(sec);
|
|
79
|
+
default: return formatDatePattern({ year: z.year, month: z.month, day: z.day }, t, p);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.formatTimestamp = formatTimestamp;
|
|
84
|
+
const FORMAT_KEYS = new Set(['kind', 'locale', 'style', 'pattern', 'currency', 'forms']);
|
|
85
|
+
function formatOptions(f) {
|
|
86
|
+
const out = {};
|
|
87
|
+
for (const [k, v] of Object.entries(f))
|
|
88
|
+
if (!FORMAT_KEYS.has(k))
|
|
89
|
+
out[k] = v;
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* One value read out by a locale pack. `undefined` / `null` stay as they are, except for the kinds that read the call
|
|
94
|
+
* hour (`timeOfDayGreeting`, `timeOfDay`) or `today`.
|
|
95
|
+
*/
|
|
96
|
+
function formatValue(value, format, code, facts) {
|
|
97
|
+
const f = typeof format === 'string' ? { kind: format } : format;
|
|
98
|
+
const p = pack(f.locale ?? code);
|
|
99
|
+
const opts = formatOptions(f);
|
|
100
|
+
const kind = f.kind;
|
|
101
|
+
if (kind === 'timeOfDayGreeting' || kind === 'timeOfDay') {
|
|
102
|
+
const hour = (0, sources_1.isEmptyValue)(value) ? facts.hour : Number(value);
|
|
103
|
+
const fn = kind === 'timeOfDay' ? p.format.timeOfDay : p.format.timeOfDayGreeting;
|
|
104
|
+
if (!fn)
|
|
105
|
+
throw new Error(`[templates/input] pack "${p.code}" has no ${kind} formatter`);
|
|
106
|
+
return fn(hour, opts);
|
|
107
|
+
}
|
|
108
|
+
if ((0, sources_1.isEmptyValue)(value))
|
|
109
|
+
return value;
|
|
110
|
+
switch (kind) {
|
|
111
|
+
case 'timestamp':
|
|
112
|
+
return formatTimestamp(value, String(f['pattern'] ?? 'YYYY-MM-DD HH:mm:ss'), String(f['timeZone'] ?? facts.timeZone), p);
|
|
113
|
+
case 'amount':
|
|
114
|
+
return p.format.amount(value, f['currency'], opts);
|
|
115
|
+
case 'date': {
|
|
116
|
+
const day = (0, shared_1.parseCalendarDate)(value);
|
|
117
|
+
if (!day)
|
|
118
|
+
return '';
|
|
119
|
+
if (typeof f['pattern'] === 'string')
|
|
120
|
+
return formatDatePattern(day, f['pattern'], p);
|
|
121
|
+
return p.format.date(day, f['style'], opts);
|
|
122
|
+
}
|
|
123
|
+
case 'number':
|
|
124
|
+
return p.format.number(Number(value), opts);
|
|
125
|
+
case 'digits':
|
|
126
|
+
return p.format.digits ? p.format.digits(String(value)) : String(value);
|
|
127
|
+
case 'name':
|
|
128
|
+
return p.format.name ? p.format.name(String(value), f['case'], opts) : String(value);
|
|
129
|
+
case 'text':
|
|
130
|
+
return p.format.text ? p.format.text(String(value)) : String(value);
|
|
131
|
+
case 'count': {
|
|
132
|
+
if (!p.format.count)
|
|
133
|
+
throw new Error(`[templates/input] pack "${p.code}" has no count formatter`);
|
|
134
|
+
return p.format.count(Number(value), f['forms'] ?? [], opts);
|
|
135
|
+
}
|
|
136
|
+
case 'relativeDay': {
|
|
137
|
+
const day = (0, shared_1.parseCalendarDate)(value);
|
|
138
|
+
if (!day || !p.format.relativeDay)
|
|
139
|
+
return null;
|
|
140
|
+
const t = facts.today;
|
|
141
|
+
return p.format.relativeDay(new Date(Date.UTC(day.year, day.month - 1, day.day)), new Date(Date.UTC(t.year, t.month - 1, t.day)));
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
throw new Error(`[templates/input] unknown format kind "${kind}"`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.formatValue = formatValue;
|
|
148
|
+
function sourcesOf(from) {
|
|
149
|
+
return from == null || typeof from === 'function' ? [] : (0, sources_1.sourceList)(from);
|
|
150
|
+
}
|
|
151
|
+
/** CMS globals the input reads (`global` / `storage` sources, the test-data switch), in field order. */
|
|
152
|
+
function inputGlobalKeys(input) {
|
|
153
|
+
const keys = [];
|
|
154
|
+
const add = (src) => {
|
|
155
|
+
const k = (0, sources_1.isAsyncSource)(src) ? (0, sources_1.storageKey)(src) : undefined;
|
|
156
|
+
if (k != null && !keys.includes(k))
|
|
157
|
+
keys.push(k);
|
|
158
|
+
};
|
|
159
|
+
const visit = (f) => {
|
|
160
|
+
if (isGroup(f))
|
|
161
|
+
Object.values(f.group).forEach(visit);
|
|
162
|
+
else
|
|
163
|
+
sourcesOf(f.from).forEach(add);
|
|
164
|
+
};
|
|
165
|
+
Object.values(input.fields).forEach(visit);
|
|
166
|
+
if (input.testData) {
|
|
167
|
+
add(input.testData.enabledBy);
|
|
168
|
+
Object.values(input.testData.presets?.sources ?? {}).forEach(add);
|
|
169
|
+
}
|
|
170
|
+
return keys;
|
|
171
|
+
}
|
|
172
|
+
exports.inputGlobalKeys = inputGlobalKeys;
|
|
173
|
+
function computeField(name, f, vars, scope, facts, test, onlyWhenEmpty) {
|
|
174
|
+
let raw;
|
|
175
|
+
if (typeof f.from === 'function') {
|
|
176
|
+
raw = f.from(vars, facts);
|
|
177
|
+
for (const r of readEachOf(f))
|
|
178
|
+
if (!(0, sources_1.isEmptyValue)(raw))
|
|
179
|
+
raw = (0, readers_1.readValue)(raw, r, (0, context_1.exprContext)({ vars, timeZone: facts.timeZone, now: facts.now }), (e, ctx) => (0, evaluate_1.evalExpr)(e, ctx));
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
for (const src of sourcesOf(f.from)) {
|
|
183
|
+
let v = asRead((0, sources_1.readSource)(src, scope));
|
|
184
|
+
if (f.decode === 'uri' && typeof v === 'string' && ('header' in src || 'proto' in src))
|
|
185
|
+
v = decodeUri(v);
|
|
186
|
+
for (const r of readEachOf(f))
|
|
187
|
+
if (!(0, sources_1.isEmptyValue)(v))
|
|
188
|
+
v = (0, readers_1.readValue)(v, r, (0, context_1.exprContext)({ vars, timeZone: facts.timeZone, now: facts.now }), (e, ctx) => (0, evaluate_1.evalExpr)(e, ctx));
|
|
189
|
+
if ((0, sources_1.isEmptyValue)(v))
|
|
190
|
+
continue;
|
|
191
|
+
raw = v;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (test && Object.prototype.hasOwnProperty.call(test, name) && (!onlyWhenEmpty || (0, sources_1.isEmptyValue)(raw)))
|
|
196
|
+
raw = test[name];
|
|
197
|
+
if (f.read && !(0, sources_1.isEmptyValue)(raw))
|
|
198
|
+
raw = (0, readers_1.readValue)(raw, f.read, (0, context_1.exprContext)({ vars, timeZone: facts.timeZone, now: facts.now }), (e, ctx) => (0, evaluate_1.evalExpr)(e, ctx));
|
|
199
|
+
if ((0, sources_1.isEmptyValue)(raw) && f.default !== undefined)
|
|
200
|
+
return { raw: defaultOf(f, vars, facts), usedDefault: true };
|
|
201
|
+
return { raw, usedDefault: false };
|
|
202
|
+
}
|
|
203
|
+
/** The readers `readEach` runs on every source's value. */
|
|
204
|
+
function readEachOf(f) {
|
|
205
|
+
const r = f.readEach;
|
|
206
|
+
if (r === undefined)
|
|
207
|
+
return [];
|
|
208
|
+
return Array.isArray(r) ? r : [r];
|
|
209
|
+
}
|
|
210
|
+
/** A URI-encoded header value decoded; a malformed one kept as it is. */
|
|
211
|
+
function decodeUri(v) {
|
|
212
|
+
try {
|
|
213
|
+
return decodeURIComponent(v);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return v;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Whether any of these fields has a value from its own sources (test data is then not used). */
|
|
220
|
+
function anyFieldFromSources(input, names, scope) {
|
|
221
|
+
return names.some((name) => {
|
|
222
|
+
const f = input.fields[name];
|
|
223
|
+
if (!f || isGroup(f))
|
|
224
|
+
return false;
|
|
225
|
+
return sourcesOf(f.from).some((src) => !(0, sources_1.isEmptyValue)(asRead((0, sources_1.readSource)(src, scope))));
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function defaultOf(f, vars, facts) {
|
|
229
|
+
return typeof f.default === 'function' ? f.default(vars, facts) : f.default;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The call's variables from the `input` block. Synchronous: CMS globals must be in `scope.globals` (see
|
|
233
|
+
* {@link inputGlobalKeys} and `fetchGlobals`); a field reading a global that was not fetched reads nothing.
|
|
234
|
+
*/
|
|
235
|
+
function buildCallVars(input, scope) {
|
|
236
|
+
const languages = scope.languages?.length ? scope.languages : ['en'];
|
|
237
|
+
const facts = scope.facts ?? (0, sources_1.callFacts)(input.timeZone, scope.now ?? new Date());
|
|
238
|
+
const s = { ...(input.headerBagEnvKey != null ? { headerBagEnvKey: input.headerBagEnvKey } : {}), ...scope, facts };
|
|
239
|
+
const vars = { ...(scope.seed ?? {}) };
|
|
240
|
+
const prompt = {};
|
|
241
|
+
let test = null;
|
|
242
|
+
if (input.testData) {
|
|
243
|
+
const on = (0, sources_1.readSource)(input.testData.enabledBy, s);
|
|
244
|
+
const real = input.testData.unlessAnyOf?.length ? anyFieldFromSources(input, input.testData.unlessAnyOf, s) : false;
|
|
245
|
+
if (!real && !(0, sources_1.isEmptyValue)(on) && String(on).trim().toLowerCase() !== 'false' && on !== false) {
|
|
246
|
+
const values = input.testData.values;
|
|
247
|
+
test = typeof values === 'function'
|
|
248
|
+
? values((0, sources_1.businessCallView)({ vars: {}, language: languages[0], phase: 'opening' }), on, facts, Object.fromEntries(Object.entries(input.testData.presets?.sources ?? {}).map(([k, src]) => [k, asRead((0, sources_1.readSource)(src, s))])))
|
|
249
|
+
: values ?? null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const onlyWhenEmpty = input.testData?.onlyWhenEmpty ?? true;
|
|
253
|
+
const overrides = scope.overrides;
|
|
254
|
+
const one = (name, f, target, view) => {
|
|
255
|
+
const r = overrides && Object.prototype.hasOwnProperty.call(overrides, name)
|
|
256
|
+
? { raw: overrides[name], usedDefault: false }
|
|
257
|
+
: computeField(name, f, view, s, facts, test, onlyWhenEmpty);
|
|
258
|
+
let value = r.raw;
|
|
259
|
+
if (f.format) {
|
|
260
|
+
const fmt = f.format;
|
|
261
|
+
const read = (code) => {
|
|
262
|
+
let out = formatValue(r.raw, fmt, code, facts);
|
|
263
|
+
if ((0, sources_1.isEmptyValue)(out) && !r.usedDefault && f.default !== undefined) {
|
|
264
|
+
out = formatValue(defaultOf(f, view, facts), fmt, code, facts);
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
};
|
|
268
|
+
value = read(languages[0]);
|
|
269
|
+
}
|
|
270
|
+
target[name] = value;
|
|
271
|
+
return value;
|
|
272
|
+
};
|
|
273
|
+
for (const [name, spec] of Object.entries(input.fields)) {
|
|
274
|
+
if (isGroup(spec)) {
|
|
275
|
+
const obj = {};
|
|
276
|
+
const shown = {};
|
|
277
|
+
for (const [sub, f] of Object.entries(spec.group)) {
|
|
278
|
+
const value = one(sub, f, obj, { ...vars, ...obj });
|
|
279
|
+
if (f.prompt === false || (f.prompt === 'omitEmpty' && (0, sources_1.isEmptyValue)(value)))
|
|
280
|
+
continue;
|
|
281
|
+
shown[sub] = value;
|
|
282
|
+
}
|
|
283
|
+
vars[name] = obj;
|
|
284
|
+
// A group none of whose fields the prompt sees is not in the prompt.
|
|
285
|
+
if (Object.keys(shown).length)
|
|
286
|
+
prompt[name] = shown;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const value = one(name, spec, vars, vars);
|
|
290
|
+
if (spec.prompt === false)
|
|
291
|
+
continue;
|
|
292
|
+
if (spec.prompt === 'omitEmpty' && (0, sources_1.isEmptyValue)(value))
|
|
293
|
+
continue;
|
|
294
|
+
prompt[name] = value;
|
|
295
|
+
}
|
|
296
|
+
const missing = (input.required?.fields ?? []).filter((f) => (0, sources_1.isEmptyValue)(vars[f]));
|
|
297
|
+
return { vars, prompt, missing, facts, testData: test != null };
|
|
298
|
+
}
|
|
299
|
+
exports.buildCallVars = buildCallVars;
|