@voctiv/agent-runtime 0.2.2 → 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 +0 -1
- 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,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callbackHook = exports.callOrdinal = exports.callbackDue = exports.parseCallbackTime = exports.zonedInstant = exports.routeHook = exports.trunkHeaders = exports.pickTrunk = exports.afterLegPolicyHook = exports.completedLegs = void 0;
|
|
4
|
+
// Leg policy as data (T13): the agent's own redials after a leg (`platform.afterLeg` as an `AfterLegPolicy`), the
|
|
5
|
+
// re-routing of a leg by rules and over a trunk pool (`platform.legs.routeRules` / `trunkPool`), and callbacks at the
|
|
6
|
+
// time the caller named (`platform.legs.callbacks`). Each is compiled to a hook of the engine's existing slots.
|
|
7
|
+
const context_1 = require("../expr/context");
|
|
8
|
+
const evaluate_1 = require("../expr/evaluate");
|
|
9
|
+
const values_1 = require("../expr/values");
|
|
10
|
+
const outbound_1 = require("../../call/outbound");
|
|
11
|
+
const toWhole = (v) => {
|
|
12
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' && v.trim() !== '' ? Number(v.trim()) : NaN;
|
|
13
|
+
return Number.isFinite(n) && n >= 0 ? Math.trunc(n) : null;
|
|
14
|
+
};
|
|
15
|
+
const toNum = (v) => {
|
|
16
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' && v.trim() !== '' ? Number(v.trim()) : NaN;
|
|
17
|
+
return Number.isFinite(n) ? n : null;
|
|
18
|
+
};
|
|
19
|
+
/** Legs of the dialog already done: the larger of the count kept at `memoryKey` and the platform's `attempt − 1`. */
|
|
20
|
+
function completedLegs(call, memoryKey) {
|
|
21
|
+
return Math.max(toWhole(call.memory[memoryKey]) ?? 0, call.attempt - 1);
|
|
22
|
+
}
|
|
23
|
+
exports.completedLegs = completedLegs;
|
|
24
|
+
function setting(places, s) {
|
|
25
|
+
for (const p of s.from) {
|
|
26
|
+
const v = places?.[p];
|
|
27
|
+
if (v != null)
|
|
28
|
+
return v;
|
|
29
|
+
}
|
|
30
|
+
return s.default;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The `platform.afterLeg` hook of an {@link AfterLegPolicy}: counts the leg (dialog env), writes the pass's values,
|
|
34
|
+
* decides, logs, places the next leg — or runs the `onDone` integrations and writes the dialog result.
|
|
35
|
+
*/
|
|
36
|
+
function afterLegPolicyHook(policy, env) {
|
|
37
|
+
return async (call, input, api) => {
|
|
38
|
+
const { pass, recall } = input;
|
|
39
|
+
const count = setting(recall?.count, policy.settings.count);
|
|
40
|
+
const delaySec = setting(recall?.delaySec, policy.settings.delaySec);
|
|
41
|
+
const attempt = completedLegs(call, policy.attempts.memoryKey) + 1;
|
|
42
|
+
api.dialogEnv(policy.attempts.memoryKey, attempt);
|
|
43
|
+
const p = pass === 'failed' ? policy.onFailed : policy.onSuccess;
|
|
44
|
+
const locals = { attempt, count, delaySec, pass, nowMs: Date.now() };
|
|
45
|
+
const ctx = () => (0, context_1.withLocals)((0, context_1.callContext)(env, call, { input }), locals);
|
|
46
|
+
for (const [key, e] of Object.entries(p.write ?? {})) {
|
|
47
|
+
const v = (0, evaluate_1.isExprNode)(e) ? (0, evaluate_1.evalExpr)(e, ctx()) : e;
|
|
48
|
+
api.dialogEnv(key, v === undefined ? null : v);
|
|
49
|
+
}
|
|
50
|
+
const out = (0, evaluate_1.evalExpr)(p.decide, ctx());
|
|
51
|
+
const decision = (0, values_1.isPlainObject)(out) ? out : { redial: out === true };
|
|
52
|
+
locals['decision'] = decision;
|
|
53
|
+
if (p.log) {
|
|
54
|
+
const fields = p.log.fields !== undefined ? (0, evaluate_1.evalExpr)(p.log.fields, ctx()) : { attempt, ...decision, recallCount: count, recallDelaySec: delaySec };
|
|
55
|
+
api.log(p.log.event, (0, values_1.isPlainObject)(fields) ? fields : {});
|
|
56
|
+
}
|
|
57
|
+
if (decision['redial'] === true) {
|
|
58
|
+
const d = toNum(decision['delaySec']) ?? delaySec;
|
|
59
|
+
if (await api.platform.redial({ delaySec: d }))
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
for (const id of p.onDone?.integrations ?? [])
|
|
63
|
+
await api.integration(id, { pass });
|
|
64
|
+
if (p.onDone?.dialogResult != null)
|
|
65
|
+
api.platform.setDialogResult(p.onDone.dialogResult);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.afterLegPolicyHook = afterLegPolicyHook;
|
|
69
|
+
/** A trunk of the pool, picked by `random` (default `Math.random`). */
|
|
70
|
+
function pickTrunk(pool, random = Math.random) {
|
|
71
|
+
const n = pool.trunks.length;
|
|
72
|
+
if (n === 0)
|
|
73
|
+
return null;
|
|
74
|
+
return pool.trunks[Math.min(n - 1, Math.max(0, Math.floor(random() * n)))];
|
|
75
|
+
}
|
|
76
|
+
exports.pickTrunk = pickTrunk;
|
|
77
|
+
/** The picked trunk's SIP extras (`{callerId}`, `{name}`, `{id}`, `{domain}` filled). */
|
|
78
|
+
function trunkHeaders(pool, t) {
|
|
79
|
+
const known = { callerId: t.callerId, name: t.name, id: t.id, domain: pool.domain ?? '' };
|
|
80
|
+
const fill = (s) => s.replace(/\{(\w+)\}/g, (whole, k) => (known[k] == null ? whole : String(known[k])));
|
|
81
|
+
return Object.fromEntries(Object.entries(pool.headers).map(([k, v]) => [k, fill(v)]));
|
|
82
|
+
}
|
|
83
|
+
exports.trunkHeaders = trunkHeaders;
|
|
84
|
+
/** The `platform.legs.route` hook of route rules and a trunk pool: the first rule that holds, else a trunk of the pool. */
|
|
85
|
+
function routeHook(rules, pool, env) {
|
|
86
|
+
return (call, input) => {
|
|
87
|
+
const msisdn = String(input?.msisdn ?? '');
|
|
88
|
+
const ctx = (0, context_1.withLocals)((0, context_1.callContext)(env, call, { input }), { msisdn });
|
|
89
|
+
for (const r of rules ?? []) {
|
|
90
|
+
if (!(0, evaluate_1.evalCondition)(r.when, ctx))
|
|
91
|
+
continue;
|
|
92
|
+
const to = r.msisdn !== undefined ? ((0, evaluate_1.isExprNode)(r.msisdn) ? (0, values_1.toText)((0, evaluate_1.evalExpr)(r.msisdn, ctx)) : String(r.msisdn)) : msisdn;
|
|
93
|
+
const proto = r.protoAdditional
|
|
94
|
+
? Object.fromEntries(Object.entries(r.protoAdditional).map(([k, e]) => [k, (0, evaluate_1.isExprNode)(e) ? (0, values_1.toText)((0, evaluate_1.evalExpr)(e, ctx)) : String(e)]))
|
|
95
|
+
: undefined;
|
|
96
|
+
return { msisdn: to, ...(r.channel ? { channel: r.channel } : {}), ...(proto ? { protoAdditional: proto } : {}) };
|
|
97
|
+
}
|
|
98
|
+
if (!pool)
|
|
99
|
+
return null;
|
|
100
|
+
const t = pickTrunk(pool);
|
|
101
|
+
if (!t)
|
|
102
|
+
return null;
|
|
103
|
+
return (0, outbound_1.nameLegTrunk)({ msisdn, trunkId: t.id, protoAdditional: trunkHeaders(pool, t) }, { name: t.name, callerId: t.callerId });
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
exports.routeHook = routeHook;
|
|
107
|
+
// ── callbacks ──
|
|
108
|
+
const CALLBACK_TIME = /^(\d{4})-(\d{2})-(\d{2})(?:(?:[ T](\d{1,2}):(\d{2}))|\s+(morning|afternoon|evening))?$/i;
|
|
109
|
+
function wallClockAt(instantMs, timeZone) {
|
|
110
|
+
const p = {};
|
|
111
|
+
for (const part of new Intl.DateTimeFormat('en-US', {
|
|
112
|
+
timeZone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false,
|
|
113
|
+
}).formatToParts(new Date(instantMs)))
|
|
114
|
+
if (part.type !== 'literal')
|
|
115
|
+
p[part.type] = part.value;
|
|
116
|
+
return Date.UTC(Number(p['year']), Number(p['month']) - 1, Number(p['day']), Number(p['hour']) % 24, Number(p['minute']), Number(p['second']));
|
|
117
|
+
}
|
|
118
|
+
/** The instant a wall-clock time of a zone names. */
|
|
119
|
+
function zonedInstant(year, month, day, hour, minute, timeZone) {
|
|
120
|
+
const wanted = Date.UTC(year, month - 1, day, hour, minute);
|
|
121
|
+
let guess = wanted;
|
|
122
|
+
for (let i = 0; i < 2; i += 1)
|
|
123
|
+
guess += wanted - wallClockAt(guess, timeZone);
|
|
124
|
+
return new Date(guess);
|
|
125
|
+
}
|
|
126
|
+
exports.zonedInstant = zonedInstant;
|
|
127
|
+
/** A named callback time: a day, a day and a clock time, or a day and a part of the day, in the policy's zone. */
|
|
128
|
+
function parseCallbackTime(raw, cfg) {
|
|
129
|
+
if (typeof raw !== 'string')
|
|
130
|
+
return null;
|
|
131
|
+
const m = CALLBACK_TIME.exec(raw.trim());
|
|
132
|
+
if (m == null)
|
|
133
|
+
return null;
|
|
134
|
+
const year = Number(m[1]), month = Number(m[2]), day = Number(m[3]);
|
|
135
|
+
if (month < 1 || month > 12 || day < 1 || day > 31)
|
|
136
|
+
return null;
|
|
137
|
+
let hour;
|
|
138
|
+
let minute = 0;
|
|
139
|
+
let kind;
|
|
140
|
+
if (m[4] != null) {
|
|
141
|
+
hour = Number(m[4]);
|
|
142
|
+
minute = Number(m[5]);
|
|
143
|
+
if (hour > 23 || minute > 59)
|
|
144
|
+
return null;
|
|
145
|
+
kind = 'clock';
|
|
146
|
+
}
|
|
147
|
+
else if (m[6] != null) {
|
|
148
|
+
hour = cfg.hours[m[6].toLowerCase()];
|
|
149
|
+
kind = 'part_of_day';
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
hour = cfg.hours.dayOnly;
|
|
153
|
+
kind = 'day';
|
|
154
|
+
}
|
|
155
|
+
const at = zonedInstant(year, month, day, hour, minute, cfg.timeZone);
|
|
156
|
+
return Number.isNaN(at.getTime()) ? null : { at, kind };
|
|
157
|
+
}
|
|
158
|
+
exports.parseCallbackTime = parseCallbackTime;
|
|
159
|
+
/** When the callback is due: the named time (or soon, when it passed), the campaign's delay, or the fallback delay. */
|
|
160
|
+
function callbackDue(time, now, recallDelaySec, cfg) {
|
|
161
|
+
const named = parseCallbackTime(time, cfg);
|
|
162
|
+
if (named != null) {
|
|
163
|
+
const text = String(time).trim();
|
|
164
|
+
if (named.at.getTime() > now.getTime())
|
|
165
|
+
return { at: named.at, source: `named_${named.kind}`, named: text };
|
|
166
|
+
return { at: new Date(now.getTime() + cfg.passedDelaySec * 1000), source: 'named_time_passed', named: text };
|
|
167
|
+
}
|
|
168
|
+
if (typeof recallDelaySec === 'number' && recallDelaySec > 0)
|
|
169
|
+
return { at: new Date(now.getTime() + recallDelaySec * 1000), source: 'contact_rule_delay', named: null };
|
|
170
|
+
return { at: new Date(now.getTime() + cfg.fallbackDelaySec * 1000), source: 'fallback_delay', named: null };
|
|
171
|
+
}
|
|
172
|
+
exports.callbackDue = callbackDue;
|
|
173
|
+
/** The library's ledger of failed-leg redials (`failed_leg_redials`, see `redialFailedLeg`). */
|
|
174
|
+
const FAILED_LEG_REDIALS = 'failed_leg_redials';
|
|
175
|
+
const count = (v) => (typeof v === 'number' && v >= 0 ? Math.trunc(v) : 0);
|
|
176
|
+
const strOrNull = (v) => (typeof v === 'string' ? v : null);
|
|
177
|
+
function redialsBefore(env, callUuid) {
|
|
178
|
+
const r = env[FAILED_LEG_REDIALS];
|
|
179
|
+
const n = count(r?.['count']);
|
|
180
|
+
const last = strOrNull(r?.['last_call_uuid']);
|
|
181
|
+
return last != null && last === callUuid ? Math.max(0, n - 1) : n;
|
|
182
|
+
}
|
|
183
|
+
function bookedOf(env, key) {
|
|
184
|
+
const r = env[key];
|
|
185
|
+
return { scheduled: count(r?.['scheduled']), last_call_uuid: strOrNull(r?.['last_call_uuid']) };
|
|
186
|
+
}
|
|
187
|
+
/** Which call of the dialog this is: its attempt (platform count or failed-leg redials), or the callbacks and redials before it plus one. */
|
|
188
|
+
function callOrdinal(hostAttempt, env, callUuid, envKey) {
|
|
189
|
+
const before = redialsBefore(env, callUuid);
|
|
190
|
+
return Math.max(Math.max(hostAttempt, before) + 1, bookedOf(env, envKey).scheduled + before + 1);
|
|
191
|
+
}
|
|
192
|
+
exports.callOrdinal = callOrdinal;
|
|
193
|
+
const booked = new WeakSet();
|
|
194
|
+
/**
|
|
195
|
+
* The after-call hook step of a {@link CallbackPolicy}: books the callback the conversation asked for (once per
|
|
196
|
+
* call), at the named time, over the trunk pool, within the campaign's calls of the dialog. Lines:
|
|
197
|
+
* `callback_scheduled`, `callback_not_scheduled` (`reason`), `callback_schedule_failed`.
|
|
198
|
+
*/
|
|
199
|
+
function callbackHook(cfg, pool, dialNumber, env) {
|
|
200
|
+
const dial = (raw) => {
|
|
201
|
+
if (typeof raw !== 'string' || raw.trim() === '')
|
|
202
|
+
return null;
|
|
203
|
+
const n = dialNumber ? dialNumber(raw) : raw.trim();
|
|
204
|
+
return n ? n : null;
|
|
205
|
+
};
|
|
206
|
+
return async (call, _input, api) => {
|
|
207
|
+
if (call.outcome === undefined)
|
|
208
|
+
return undefined;
|
|
209
|
+
const o = call.outcome;
|
|
210
|
+
const p = api.platform;
|
|
211
|
+
const callUuid = api.callUuid ?? null;
|
|
212
|
+
const memory = call.memory;
|
|
213
|
+
const ctx = (0, context_1.callContext)(env, call);
|
|
214
|
+
const requested = o == null ? true : cfg.when !== undefined ? (0, evaluate_1.evalCondition)(cfg.when, ctx) : o.triggersCallback === true;
|
|
215
|
+
const time = o == null ? null : cfg.time !== undefined ? (0, evaluate_1.evalExpr)(cfg.time, ctx) : o.entities['callback_time'] ?? null;
|
|
216
|
+
const result = o == null ? 'undefined' : o.result;
|
|
217
|
+
const maxCalls = typeof p?.recallCount === 'number' && p.recallCount > 0 ? Math.trunc(p.recallCount) : cfg.fallbackMaxCalls;
|
|
218
|
+
const callsSoFar = callOrdinal(Number(p?.attempt ?? 0), memory, callUuid, cfg.envKey);
|
|
219
|
+
if (!requested)
|
|
220
|
+
return undefined;
|
|
221
|
+
if (callsSoFar >= maxCalls) {
|
|
222
|
+
api.log('callback_not_scheduled', { reason: 'attempts_exhausted', result, callsSoFar, maxCalls });
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
if ((o != null && booked.has(o)) || (callUuid != null && bookedOf(memory, cfg.envKey).last_call_uuid === callUuid)) {
|
|
226
|
+
api.log('callback_not_scheduled', { reason: 'already_booked', result, callUuid });
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
if (!p?.call) {
|
|
230
|
+
api.log('callback_not_scheduled', { reason: 'platform_unavailable', result });
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const msisdn = dial(p.dialogMsisdn()) ?? dial(p.msisdn);
|
|
234
|
+
if (msisdn == null) {
|
|
235
|
+
api.log('callback_not_scheduled', { reason: 'no_msisdn', result });
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
const now = new Date();
|
|
239
|
+
const due = callbackDue(time, now, p.recallDelaySec, cfg);
|
|
240
|
+
const trunk = pool ? pickTrunk(pool) : null;
|
|
241
|
+
const routing = { ...p.routing() };
|
|
242
|
+
if (trunk && pool) {
|
|
243
|
+
delete routing['channel'];
|
|
244
|
+
routing['trunkId'] = trunk.id;
|
|
245
|
+
routing['protoAdditional'] = { ...(routing['protoAdditional'] ?? {}), ...trunkHeaders(pool, trunk) };
|
|
246
|
+
}
|
|
247
|
+
const options = { ...routing, entryPoint: cfg.entryPoint, ...(cfg.onFailedCall ? { onFailedCall: cfg.onFailedCall } : {}), date: due.at };
|
|
248
|
+
try {
|
|
249
|
+
await p.call(msisdn, options);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
api.log('callback_schedule_failed', { result, msisdn, dueAt: due.at.toISOString(), err: String(err) });
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
if (o != null)
|
|
256
|
+
booked.add(o);
|
|
257
|
+
const prev = bookedOf(memory, cfg.envKey);
|
|
258
|
+
api.dialogEnv(cfg.envKey, { scheduled: prev.scheduled + 1, last_due: due.at.toISOString(), last_source: due.source, last_call_uuid: callUuid });
|
|
259
|
+
p.setDialogResult(cfg.dialogResult ?? 'pending');
|
|
260
|
+
api.log('callback_scheduled', {
|
|
261
|
+
result, msisdn, dueAt: due.at.toISOString(), dueInSec: Math.round((due.at.getTime() - now.getTime()) / 1000),
|
|
262
|
+
source: due.source, named: due.named, callsSoFar, maxCalls, entryPoint: cfg.entryPoint,
|
|
263
|
+
selectedTrunk: trunk?.name, trunkNumber: trunk?.callerId, trunkId: routing['trunkId'],
|
|
264
|
+
});
|
|
265
|
+
return undefined;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
exports.callbackHook = callbackHook;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CallView, ExtractionSpec, ResultsSpec } from '../spec';
|
|
2
|
+
import type { RuleSpec } from './rule-env';
|
|
3
|
+
/** The label written to the row's `result` field for the decided result `result`. */
|
|
4
|
+
export declare function reportLabel(spec: Partial<RuleSpec> & {
|
|
5
|
+
readonly results: ResultsSpec;
|
|
6
|
+
readonly extraction?: ExtractionSpec;
|
|
7
|
+
}, result: string, row: Readonly<Record<string, unknown>>, call: CallView, suffix?: string): string | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportLabel = void 0;
|
|
4
|
+
const result_catalog_1 = require("./result-catalog");
|
|
5
|
+
const result_rules_1 = require("./result-rules");
|
|
6
|
+
const results_1 = require("./results");
|
|
7
|
+
/** The label written to the row's `result` field for the decided result `result`. */
|
|
8
|
+
function reportLabel(spec, result, row, call, suffix) {
|
|
9
|
+
let r = result;
|
|
10
|
+
let sfx = suffix;
|
|
11
|
+
const rules = spec.results.rules;
|
|
12
|
+
if (rules?.length && spec.results.rulesOn === 'report') {
|
|
13
|
+
const entities = call.extracted ?? {};
|
|
14
|
+
const out = (0, result_rules_1.applyResultRules)(spec, rules, {
|
|
15
|
+
result: r, preResult: call.preResult ?? r, extractedResult: call.extractedResult ?? null,
|
|
16
|
+
triggersCallback: call.triggersCallback === true, extractionSkipped: false, entities,
|
|
17
|
+
}, call);
|
|
18
|
+
r = out.result;
|
|
19
|
+
if (out.labelSuffix)
|
|
20
|
+
sfx = out.labelSuffix;
|
|
21
|
+
}
|
|
22
|
+
const catalog = spec.results.catalog;
|
|
23
|
+
let label = r;
|
|
24
|
+
if (catalog && (catalog.applyTo ?? 'row') === 'row')
|
|
25
|
+
label = (0, result_catalog_1.catalogLabel)(spec, catalog, r, call, row);
|
|
26
|
+
label = (0, results_1.labelFor)(spec.results, label);
|
|
27
|
+
return label != null && sfx ? label + sfx : label;
|
|
28
|
+
}
|
|
29
|
+
exports.reportLabel = reportLabel;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type CmsLinks, type CommonCallContext, type StatusLineCallContext } from '../../call/output';
|
|
2
|
+
import type { CallView, ExtractionSpec, ReportSpec, ResultsSpec } from '../spec';
|
|
3
|
+
import type { RuleSpec } from './rule-env';
|
|
4
|
+
/**
|
|
5
|
+
* Which row: a connected call after extraction (`call`), a connected call whose extraction threw (`error`), a dial
|
|
6
|
+
* that never connected (`failedDial`), a call cancelled before the dial (`cancelled`), a leg that never connected
|
|
7
|
+
* reported by its `after_call_failed` pass on the engine's call media (`failedLeg`: like `error`, with the leg's
|
|
8
|
+
* service fields).
|
|
9
|
+
*/
|
|
10
|
+
export type RowKind = 'call' | 'error' | 'failedDial' | 'cancelled' | 'failedLeg' | 'headless';
|
|
11
|
+
/** What the row is built from. Absent facts write `null`. */
|
|
12
|
+
export interface RowFacts {
|
|
13
|
+
readonly result?: string | null;
|
|
14
|
+
readonly preResult?: string | null;
|
|
15
|
+
readonly extractedResult?: string | null;
|
|
16
|
+
readonly triggersCallback?: boolean;
|
|
17
|
+
readonly extractionSkipped?: boolean;
|
|
18
|
+
/** The extraction request failed and the call kept its own pre-result (`extraction.onFailure: 'keepResult'`). */
|
|
19
|
+
readonly extractionFailed?: boolean;
|
|
20
|
+
readonly summary?: string | null;
|
|
21
|
+
readonly entities?: Readonly<Record<string, unknown>>;
|
|
22
|
+
/** Service fields (see {@link serviceFields}). */
|
|
23
|
+
readonly service?: Readonly<Record<string, unknown>>;
|
|
24
|
+
readonly voiceTag?: string;
|
|
25
|
+
readonly endedBy?: string;
|
|
26
|
+
readonly language?: string;
|
|
27
|
+
readonly agentVersion?: string;
|
|
28
|
+
readonly asrDurationSec?: number;
|
|
29
|
+
readonly sipCode?: number | null;
|
|
30
|
+
readonly sipPhrase?: string | null;
|
|
31
|
+
/** The call UUID when the service fields do not carry it (a leg that never connected). */
|
|
32
|
+
readonly callUuid?: string;
|
|
33
|
+
/** The dialog UUID when the service fields do not carry it (a leg that never connected). */
|
|
34
|
+
readonly dialogUuid?: string;
|
|
35
|
+
/** The reply language at the end of the call (as the prompt names it) and whether it was still a provisional pick. */
|
|
36
|
+
readonly replyLanguage?: string;
|
|
37
|
+
readonly replyLanguageProvisional?: boolean;
|
|
38
|
+
/** A text appended to the row's result label (`results.rules[].then.suffix`). */
|
|
39
|
+
readonly labelSuffix?: string;
|
|
40
|
+
}
|
|
41
|
+
/** The service fields of a call context with the CMS links of the deployment. */
|
|
42
|
+
export declare function serviceFields(common: CommonCallContext | StatusLineCallContext | undefined, links: CmsLinks | null, startTimeFormat?: ReportSpec['startTimeFormat'], service?: Exclude<ReportSpec['service'], false> & {
|
|
43
|
+
readonly failedDial?: boolean;
|
|
44
|
+
}, timeZone?: string): Record<string, unknown>;
|
|
45
|
+
/** `2026-09-08T15:10:12+08:00`: the instant as the wall clock of `timeZone`, to the second, with the zone's offset. */
|
|
46
|
+
export declare function isoWithOffset(epochMs: number, timeZone: string): string;
|
|
47
|
+
/** `DD-MM-YYYY HH:mm:ss` in UTC (production hosts run in UTC; the result must not depend on the host zone). */
|
|
48
|
+
export declare function dayFirstUtc(ms: number): string;
|
|
49
|
+
/** Moves the row's CMS links from one set of hosts to another (a host resolved after the call). Mutates `row`. */
|
|
50
|
+
export declare function moveLinks(row: Record<string, unknown>, from: CmsLinks, to: CmsLinks): string[];
|
|
51
|
+
/** A report field that threw while its row was built (the field was written null). */
|
|
52
|
+
export interface ReportFieldFailure {
|
|
53
|
+
readonly key: string;
|
|
54
|
+
readonly err: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One report row. Field order is the agent file's; `labels.map` renames the `result` field's label;
|
|
58
|
+
* `extraction.normalize` fixes are expected to be applied to `facts.entities` already. A field that throws is written
|
|
59
|
+
* null and listed in `failures` (with its error); the row is always built.
|
|
60
|
+
*/
|
|
61
|
+
export declare function buildReportRow(spec: Partial<RuleSpec> & {
|
|
62
|
+
readonly report: ReportSpec;
|
|
63
|
+
readonly results: ResultsSpec;
|
|
64
|
+
readonly extraction?: ExtractionSpec;
|
|
65
|
+
}, kind: RowKind, facts: RowFacts, call: CallView, failures?: ReportFieldFailure[]): Record<string, unknown>;
|
|
66
|
+
/** Facts of a dial that never connected: no result, a redial candidate, nothing extracted. */
|
|
67
|
+
export declare function failedDialFacts(service: Readonly<Record<string, unknown>>, triggersCallback?: boolean): RowFacts;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.failedDialFacts = exports.buildReportRow = exports.moveLinks = exports.dayFirstUtc = exports.isoWithOffset = exports.serviceFields = void 0;
|
|
4
|
+
// The report row from the agent file's `report` block and the call's facts. Service fields (status, attempt,
|
|
5
|
+
// duration, start time, SIP status, transcript, ids, CMS links) come from `buildCommonFields` (`call/output`), the
|
|
6
|
+
// same fields for every agent.
|
|
7
|
+
const output_1 = require("../../call/output");
|
|
8
|
+
const extraction_rules_1 = require("./extraction-rules");
|
|
9
|
+
const report_label_1 = require("./report-label");
|
|
10
|
+
const result_catalog_1 = require("./result-catalog");
|
|
11
|
+
const values_1 = require("../expr/values");
|
|
12
|
+
/** Facts read from extraction: not written in a row whose extraction did not run. */
|
|
13
|
+
const EXTRACTION_FACTS = new Set(['preResult', 'extractedResult', 'triggersCallback', 'extractionSkipped', 'extractionFailed', 'summary']);
|
|
14
|
+
/** The service fields of a call context with the CMS links of the deployment. */
|
|
15
|
+
function serviceFields(common, links, startTimeFormat, service, timeZone) {
|
|
16
|
+
if (!common)
|
|
17
|
+
return {};
|
|
18
|
+
const cms = links ?? { cmsUrl: '', cmsUrlLlm: '', extractUrl: '' };
|
|
19
|
+
const all = (0, output_1.buildCommonFields)(common, cms);
|
|
20
|
+
// `iso-ms`: the start time with its milliseconds (the platform's status line writes it to the second).
|
|
21
|
+
if (startTimeFormat === 'iso-ms' && Number.isFinite(common.callStartedAtMs) && 'call_start_time' in all) {
|
|
22
|
+
all['call_start_time'] = new Date(common.callStartedAtMs).toISOString();
|
|
23
|
+
}
|
|
24
|
+
// `iso-offset`: the wall clock of the agent's time zone with its offset.
|
|
25
|
+
if (startTimeFormat === 'iso-offset' && Number.isFinite(common.callStartedAtMs) && 'call_start_time' in all) {
|
|
26
|
+
all['call_start_time'] = isoWithOffset(common.callStartedAtMs, timeZone ?? 'UTC');
|
|
27
|
+
}
|
|
28
|
+
if (startTimeFormat === 'dd-mm-yyyy hh:mm:ss' && Number.isFinite(common.callStartedAtMs) && 'call_start_time' in all) {
|
|
29
|
+
// Day first, in the script host's local time (the legacy log format).
|
|
30
|
+
all['call_start_time'] = dayFirstUtc(common.callStartedAtMs);
|
|
31
|
+
}
|
|
32
|
+
if (service?.failedDial && service.failedDialStartTime === 'none' && 'call_start_time' in all)
|
|
33
|
+
all['call_start_time'] = null;
|
|
34
|
+
if (service?.recordLink === 'records' && 'call_record' in all) {
|
|
35
|
+
all['call_record'] = `${cms.cmsUrl}/records?lng=en&agent_uuid=${common.agentUuid}&call_uuid=${common.callUuid}`;
|
|
36
|
+
}
|
|
37
|
+
if (links)
|
|
38
|
+
return all;
|
|
39
|
+
for (const k of ['call_log', 'call_llm_log', 'call_record', 'llm_dialog_link'])
|
|
40
|
+
delete all[k];
|
|
41
|
+
return all;
|
|
42
|
+
}
|
|
43
|
+
exports.serviceFields = serviceFields;
|
|
44
|
+
/** `2026-09-08T15:10:12+08:00`: the instant as the wall clock of `timeZone`, to the second, with the zone's offset. */
|
|
45
|
+
function isoWithOffset(epochMs, timeZone) {
|
|
46
|
+
const parts = {};
|
|
47
|
+
const fmt = new Intl.DateTimeFormat('en-US', {
|
|
48
|
+
timeZone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false,
|
|
49
|
+
});
|
|
50
|
+
for (const part of fmt.formatToParts(new Date(epochMs)))
|
|
51
|
+
if (part.type !== 'literal')
|
|
52
|
+
parts[part.type] = part.value;
|
|
53
|
+
// `hour12: false` may write midnight as `24`.
|
|
54
|
+
const hour = String(Number(parts['hour']) % 24).padStart(2, '0');
|
|
55
|
+
const local = `${parts['year']}-${parts['month']}-${parts['day']}T${hour}:${parts['minute']}:${parts['second']}`;
|
|
56
|
+
const offsetMin = Math.round((Date.parse(`${local}Z`) - epochMs) / 60_000);
|
|
57
|
+
const abs = Math.abs(offsetMin);
|
|
58
|
+
return `${local}${offsetMin < 0 ? '-' : '+'}${String(Math.floor(abs / 60)).padStart(2, '0')}:${String(abs % 60).padStart(2, '0')}`;
|
|
59
|
+
}
|
|
60
|
+
exports.isoWithOffset = isoWithOffset;
|
|
61
|
+
/** `DD-MM-YYYY HH:mm:ss` in UTC (production hosts run in UTC; the result must not depend on the host zone). */
|
|
62
|
+
function dayFirstUtc(ms) {
|
|
63
|
+
const d = new Date(ms);
|
|
64
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
65
|
+
return `${p(d.getUTCDate())}-${p(d.getUTCMonth() + 1)}-${d.getUTCFullYear()} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}`;
|
|
66
|
+
}
|
|
67
|
+
exports.dayFirstUtc = dayFirstUtc;
|
|
68
|
+
/** Row keys of the CMS links and which host each starts with. */
|
|
69
|
+
const LINK_HOSTS = [
|
|
70
|
+
['call_log', 'cmsUrl'],
|
|
71
|
+
['call_llm_log', 'cmsUrlLlm'],
|
|
72
|
+
['call_record', 'cmsUrl'],
|
|
73
|
+
['llm_dialog_link', 'extractUrl'],
|
|
74
|
+
];
|
|
75
|
+
/** Moves the row's CMS links from one set of hosts to another (a host resolved after the call). Mutates `row`. */
|
|
76
|
+
function moveLinks(row, from, to) {
|
|
77
|
+
const moved = [];
|
|
78
|
+
for (const [key, host] of LINK_HOSTS) {
|
|
79
|
+
const link = row[key];
|
|
80
|
+
if (from[host] === to[host] || typeof link !== 'string' || !link.startsWith(`${from[host]}/`))
|
|
81
|
+
continue;
|
|
82
|
+
row[key] = to[host] + link.slice(from[host].length);
|
|
83
|
+
moved.push(key);
|
|
84
|
+
}
|
|
85
|
+
return moved;
|
|
86
|
+
}
|
|
87
|
+
exports.moveLinks = moveLinks;
|
|
88
|
+
const SERVICE_FACT = {
|
|
89
|
+
status: 'status',
|
|
90
|
+
attempt: 'attempt',
|
|
91
|
+
durationSec: 'duration',
|
|
92
|
+
callUuid: 'call_uuid',
|
|
93
|
+
dialogUuid: 'dialog_uuid',
|
|
94
|
+
llmDialogUuid: 'llm_dialog_uuid',
|
|
95
|
+
transcript: 'call_transcript',
|
|
96
|
+
startTime: 'call_start_time',
|
|
97
|
+
recordUrl: 'call_record',
|
|
98
|
+
transcriptUrl: 'call_log',
|
|
99
|
+
llmLogUrl: 'call_llm_log',
|
|
100
|
+
};
|
|
101
|
+
function factValue(fact, f, results) {
|
|
102
|
+
switch (fact) {
|
|
103
|
+
case 'result': return f.result ?? null;
|
|
104
|
+
case 'preResult': return f.preResult ?? null;
|
|
105
|
+
case 'extractedResult': return f.extractedResult ?? null;
|
|
106
|
+
case 'triggersCallback': return f.triggersCallback ?? null;
|
|
107
|
+
case 'extractionSkipped': return f.extractionSkipped ?? null;
|
|
108
|
+
case 'extractionFailed': return f.extractionFailed ?? null;
|
|
109
|
+
case 'summary': return f.summary ?? null;
|
|
110
|
+
case 'voiceTag': return f.voiceTag ?? null;
|
|
111
|
+
case 'endedBy': return f.endedBy ?? null;
|
|
112
|
+
case 'language': return f.language ?? null;
|
|
113
|
+
case 'agentVersion': return f.agentVersion ?? null;
|
|
114
|
+
case 'asrDurationSec': return f.asrDurationSec == null ? null : Math.max(0, Math.round(f.asrDurationSec));
|
|
115
|
+
case 'callUuid': return f.service?.['call_uuid'] ?? f.callUuid ?? null;
|
|
116
|
+
case 'sipCode': return f.sipCode ?? f.service?.['call_status'] ?? null;
|
|
117
|
+
case 'sipPhrase': return f.sipPhrase ?? f.service?.['call_status_phrase'] ?? null;
|
|
118
|
+
default: {
|
|
119
|
+
void results;
|
|
120
|
+
const key = SERVICE_FACT[fact];
|
|
121
|
+
return key ? f.service?.[key] ?? null : null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function isFact(src, fact) {
|
|
126
|
+
return typeof src === 'object' && 'fact' in src && src.fact === fact;
|
|
127
|
+
}
|
|
128
|
+
function isAllEntities(src) {
|
|
129
|
+
return typeof src === 'object' && 'entity' in src && src.entity === '*';
|
|
130
|
+
}
|
|
131
|
+
/** The keys a field that threw is written null under: its own, none for a form that adds several keys. */
|
|
132
|
+
function keysOnFailure(key, src) {
|
|
133
|
+
if (typeof src === 'function')
|
|
134
|
+
return [key];
|
|
135
|
+
if ('spread' in src)
|
|
136
|
+
return [];
|
|
137
|
+
if ('catalog' in src)
|
|
138
|
+
return src.catalog === 'columns' ? [] : [key];
|
|
139
|
+
if ('view' in src && 'entities' in src)
|
|
140
|
+
return src.pick ?? [];
|
|
141
|
+
if ('fact' in src && src.fact === 'service')
|
|
142
|
+
return [];
|
|
143
|
+
return [key];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* One report row. Field order is the agent file's; `labels.map` renames the `result` field's label;
|
|
147
|
+
* `extraction.normalize` fixes are expected to be applied to `facts.entities` already. A field that throws is written
|
|
148
|
+
* null and listed in `failures` (with its error); the row is always built.
|
|
149
|
+
*/
|
|
150
|
+
function buildReportRow(spec, kind, facts, call, failures) {
|
|
151
|
+
const row = {};
|
|
152
|
+
// The data forms of the fields are functions by now (`compileDataForms`).
|
|
153
|
+
const fields = Object.entries(spec.report.fields);
|
|
154
|
+
let entityNames = [];
|
|
155
|
+
try {
|
|
156
|
+
entityNames = (typeof spec.extraction?.catalog === 'function' ? spec.extraction.catalog(call) : spec.extraction?.entities ?? []).map((e) => e.name);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
failures?.push({ key: 'extraction.catalog', err: String(err) });
|
|
160
|
+
}
|
|
161
|
+
const entities = facts.entities ?? {};
|
|
162
|
+
// A connected call writes the entities extraction returned (none when it was skipped or failed); other rows write
|
|
163
|
+
// every entity as null.
|
|
164
|
+
const allEntities = () => (kind === 'call' ? { ...entities } : Object.fromEntries(entityNames.map((n) => [n, null])));
|
|
165
|
+
const service = facts.service ?? {};
|
|
166
|
+
const resultOnly = kind === 'error' || kind === 'cancelled' || kind === 'failedLeg' || kind === 'headless';
|
|
167
|
+
// A failed dial: entities first, so named fields win where the two share a key.
|
|
168
|
+
const entitiesFirst = spec.report.failedDialEntities !== 'inPlace';
|
|
169
|
+
if (kind === 'failedDial' && entitiesFirst && fields.some(([, src]) => isAllEntities(src)))
|
|
170
|
+
Object.assign(row, allEntities());
|
|
171
|
+
const withFacts = {
|
|
172
|
+
...call, preResult: facts.preResult ?? null, extractedResult: facts.extractedResult ?? null, triggersCallback: facts.triggersCallback ?? null,
|
|
173
|
+
extractionFailed: facts.extractionFailed ?? null,
|
|
174
|
+
rowFacts: {
|
|
175
|
+
kind,
|
|
176
|
+
connected: kind === 'call' || kind === 'error',
|
|
177
|
+
service,
|
|
178
|
+
callUuid: service['call_uuid'] ?? facts.callUuid ?? null,
|
|
179
|
+
dialogUuid: service['dialog_uuid'] ?? facts.dialogUuid ?? null,
|
|
180
|
+
asrDurationSec: facts.asrDurationSec ?? null,
|
|
181
|
+
sipCode: facts.sipCode ?? null,
|
|
182
|
+
sipPhrase: facts.sipPhrase ?? null,
|
|
183
|
+
replyLanguage: facts.replyLanguage ?? null,
|
|
184
|
+
replyLanguageProvisional: facts.replyLanguage != null && facts.replyLanguageProvisional === true,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
const writeField = (key, src) => {
|
|
188
|
+
if (typeof src === 'function') {
|
|
189
|
+
const value = src(row, withFacts);
|
|
190
|
+
if (value !== undefined)
|
|
191
|
+
row[key] = value;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if ('spread' in src) {
|
|
195
|
+
const more = src.spread(row, withFacts);
|
|
196
|
+
if (more)
|
|
197
|
+
Object.assign(row, more);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if ('var' in src) {
|
|
201
|
+
// A key of the variables as written, else a dotted path into them (`customer.name`).
|
|
202
|
+
row[key] = (Object.prototype.hasOwnProperty.call(call.vars, src.var) ? call.vars[src.var] : (0, values_1.getPath)(call.vars, src.var)) ?? null;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if ('value' in src) {
|
|
206
|
+
row[key] = src.value;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if ('entity' in src) {
|
|
210
|
+
if (resultOnly)
|
|
211
|
+
return;
|
|
212
|
+
if (src.entity === '*') {
|
|
213
|
+
if (kind !== 'failedDial' || !entitiesFirst)
|
|
214
|
+
Object.assign(row, allEntities());
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
row[key] = kind === 'call' ? entities[src.entity] ?? null : null;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if ('catalog' in src) {
|
|
221
|
+
const out = (0, result_catalog_1.catalogField)(spec, src, key, row, withFacts, kind);
|
|
222
|
+
if (out)
|
|
223
|
+
Object.assign(row, out);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if ('view' in src && 'entities' in src) {
|
|
227
|
+
// A connected call's row only (other rows write nothing here); `pick`: only these keys of the view.
|
|
228
|
+
if (kind !== 'call')
|
|
229
|
+
return;
|
|
230
|
+
const v = src;
|
|
231
|
+
const seen = (0, extraction_rules_1.entityView)(spec, v.view, entities, withFacts);
|
|
232
|
+
if (v.pick)
|
|
233
|
+
for (const k of v.pick)
|
|
234
|
+
row[k] = seen[k];
|
|
235
|
+
else
|
|
236
|
+
Object.assign(row, seen);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!('fact' in src)) {
|
|
240
|
+
// Block fields are made ordinary ones by `withBlocks` (defineVoiceAgent) before a row is built.
|
|
241
|
+
throw new Error(`[templates/report] ${key}: a block field without its block (use withBlocks)`);
|
|
242
|
+
}
|
|
243
|
+
if (src.fact === 'service') {
|
|
244
|
+
const omit = src.omit ?? [];
|
|
245
|
+
for (const [k, v] of Object.entries(service))
|
|
246
|
+
if (!omit.includes(k))
|
|
247
|
+
row[k] = v;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (resultOnly && EXTRACTION_FACTS.has(src.fact))
|
|
251
|
+
return;
|
|
252
|
+
row[key] = factValue(src.fact, facts, spec.results);
|
|
253
|
+
};
|
|
254
|
+
for (const [key, src] of fields) {
|
|
255
|
+
try {
|
|
256
|
+
writeField(key, src);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
// One field that throws costs that field only: it is written null (a spread writes nothing), the row goes on.
|
|
260
|
+
failures?.push({ key, err: String(err) });
|
|
261
|
+
for (const k of keysOnFailure(key, src))
|
|
262
|
+
row[k] = null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (spec.report.service !== false && !fields.some(([, src]) => isFact(src, 'service')))
|
|
266
|
+
Object.assign(row, service);
|
|
267
|
+
const v = row['result'];
|
|
268
|
+
if (typeof v === 'string') {
|
|
269
|
+
try {
|
|
270
|
+
row['result'] = (0, report_label_1.reportLabel)(spec, v, row, withFacts, facts.labelSuffix);
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
// The label that threw: the result as decided.
|
|
274
|
+
failures?.push({ key: 'result', err: String(err) });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return row;
|
|
278
|
+
}
|
|
279
|
+
exports.buildReportRow = buildReportRow;
|
|
280
|
+
/** Facts of a dial that never connected: no result, a redial candidate, nothing extracted. */
|
|
281
|
+
function failedDialFacts(service, triggersCallback = true) {
|
|
282
|
+
return { result: null, preResult: null, extractedResult: null, triggersCallback, extractionSkipped: true, summary: null, service };
|
|
283
|
+
}
|
|
284
|
+
exports.failedDialFacts = failedDialFacts;
|