@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,535 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preDialAllows = exports.runAfterCall = exports.appliesTo = exports.runBeforeCall = exports.runLookupIntegration = exports.runIntegration = exports.startAnswerHooks = exports.hookApi = exports.integrationEnabled = exports.isHookIntegration = exports.isHttpIntegration = void 0;
|
|
4
|
+
// Integrations: the agent's HTTP calls to a client — before a dial (yes/no), during the call (from hooks), after the
|
|
5
|
+
// call (CRM, client report, SMS). Every request goes through `httpRequest` (correlation ids, one log line);
|
|
6
|
+
// every one is bounded (`timeoutMs`), switched (`enabledBy`), retried (`retries`, `retryOn`) and never throws.
|
|
7
|
+
const agent_sdk_1 = require("@voctiv/agent-sdk");
|
|
8
|
+
const outbound_1 = require("../../call/outbound");
|
|
9
|
+
const http_1 = require("../../call/http");
|
|
10
|
+
const env_1 = require("../../call/env");
|
|
11
|
+
const sources_1 = require("./sources");
|
|
12
|
+
const compiled_1 = require("../expr/compiled");
|
|
13
|
+
const evaluate_1 = require("../expr/evaluate");
|
|
14
|
+
const values_1 = require("../expr/values");
|
|
15
|
+
const agent_integrations_1 = require("./agent-integrations");
|
|
16
|
+
const integration_data_1 = require("./integration-data");
|
|
17
|
+
/** An HTTP integration (not a hook step, not an uncompiled agent kind). */
|
|
18
|
+
function isHttpIntegration(x) {
|
|
19
|
+
return !('run' in x) && (!('kind' in x) || x.kind == null || x.kind === 'http');
|
|
20
|
+
}
|
|
21
|
+
exports.isHttpIntegration = isHttpIntegration;
|
|
22
|
+
/** A hook step. */
|
|
23
|
+
function isHookIntegration(x) {
|
|
24
|
+
return 'run' in x;
|
|
25
|
+
}
|
|
26
|
+
exports.isHookIntegration = isHookIntegration;
|
|
27
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
28
|
+
const DEFAULT_HOOK_TIMEOUT_MS = 30_000;
|
|
29
|
+
/** Pause before a repeated request. */
|
|
30
|
+
const RETRY_DELAY_MS = 500;
|
|
31
|
+
/** Keys never copied from a hook's result into the row. */
|
|
32
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
33
|
+
function fillPlaceholders(text, scope) {
|
|
34
|
+
const ctx = scope.context;
|
|
35
|
+
const known = {
|
|
36
|
+
...scope.call.vars,
|
|
37
|
+
dialogUuid: ctx.dialogUuid,
|
|
38
|
+
callUuid: (0, env_1.readCallUuid)(ctx),
|
|
39
|
+
msisdn: scope.call.vars['msisdn'] ?? ctx.msisdn,
|
|
40
|
+
};
|
|
41
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => (known[key] == null ? whole : encodeURIComponent(String(known[key]))));
|
|
42
|
+
}
|
|
43
|
+
function parseJson(text) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(text);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** The parser's error (`String(err)` of `JSON.parse`) for an answer that is not JSON; `null` for one that is. */
|
|
52
|
+
function jsonError(text) {
|
|
53
|
+
if (text == null)
|
|
54
|
+
return null;
|
|
55
|
+
try {
|
|
56
|
+
JSON.parse(text);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return String(err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Whether the integration is switched on (`enabledBy`); default on. */
|
|
64
|
+
async function integrationEnabled(i, scope) {
|
|
65
|
+
if (!i.enabledBy)
|
|
66
|
+
return { on: true };
|
|
67
|
+
const value = await (0, sources_1.resolveValue)({ from: i.enabledBy.from }, scope);
|
|
68
|
+
if (i.enabledBy.equals !== undefined)
|
|
69
|
+
return { on: value === i.enabledBy.equals || String(value) === String(i.enabledBy.equals), value };
|
|
70
|
+
return { on: !(0, sources_1.isEmptyValue)(value) && value !== false && String(value).trim().toLowerCase() !== 'false', value };
|
|
71
|
+
}
|
|
72
|
+
exports.integrationEnabled = integrationEnabled;
|
|
73
|
+
function bodyOf(i, row, scope, api, data) {
|
|
74
|
+
if (!i.body)
|
|
75
|
+
return undefined;
|
|
76
|
+
if (typeof i.body === 'function')
|
|
77
|
+
return i.body(row, scope.call, data?.localsView());
|
|
78
|
+
const ref = i.body;
|
|
79
|
+
const hook = scope.hooks?.[ref.hook];
|
|
80
|
+
if (!hook)
|
|
81
|
+
throw new Error(`[templates/integrations] no hook "${ref.hook}"`);
|
|
82
|
+
return hook(scope.call, row, api);
|
|
83
|
+
}
|
|
84
|
+
/** A non-idempotent method is repeated only when the request carries an `Idempotency-Key` header. */
|
|
85
|
+
function repeatable(i, headers) {
|
|
86
|
+
const m = String(i.method).toUpperCase();
|
|
87
|
+
if (m !== 'POST' && m !== 'PATCH')
|
|
88
|
+
return true;
|
|
89
|
+
return Object.keys(headers).some((h) => h.toLowerCase() === 'idempotency-key');
|
|
90
|
+
}
|
|
91
|
+
function delay(ms) {
|
|
92
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
93
|
+
}
|
|
94
|
+
/** The hook API: integrations by id, the logger, the call's identity, CMS storage, the per-call hook state. */
|
|
95
|
+
function hookApi(scope, call) {
|
|
96
|
+
const full = { ...scope, call };
|
|
97
|
+
return {
|
|
98
|
+
integration: async (id, input) => {
|
|
99
|
+
const x = scope.all?.find((y) => y.id === id && !isHookIntegration(y));
|
|
100
|
+
if (!x)
|
|
101
|
+
throw new Error(`[templates/integrations] no integration "${id}"`);
|
|
102
|
+
const row = { ...(input ?? {}) };
|
|
103
|
+
const out = isHttpIntegration(x) ? await runIntegration(x, row, full)
|
|
104
|
+
: x.kind === 'startAgentDialog' ? await (0, agent_integrations_1.runAgentDialog)(x, row, full)
|
|
105
|
+
: await (0, agent_integrations_1.runAskAgent)(x, full);
|
|
106
|
+
return out.json ?? out.text;
|
|
107
|
+
},
|
|
108
|
+
log: (message, data) => scope.logger.log(message, data),
|
|
109
|
+
callUuid: (0, env_1.readCallUuid)(scope.context),
|
|
110
|
+
dialogUuid: scope.context.dialogUuid,
|
|
111
|
+
storage: async (...names) => {
|
|
112
|
+
const read = scope.context.storage;
|
|
113
|
+
if (!read)
|
|
114
|
+
throw new Error('context.storage unavailable');
|
|
115
|
+
return read(...names);
|
|
116
|
+
},
|
|
117
|
+
state: (0, sources_1.hookStateOf)(scope.context),
|
|
118
|
+
direction: (0, env_1.readCallDirection)(scope.context),
|
|
119
|
+
http: (url, opts) => (0, http_1.httpRequest)(scope.logger, url, opts),
|
|
120
|
+
agentEnv: async (key, ...rest) => {
|
|
121
|
+
const env = scope.context.agent?.env;
|
|
122
|
+
if (!env)
|
|
123
|
+
throw new Error('agent env unavailable');
|
|
124
|
+
return rest.length ? env(key, ...rest) : env(key);
|
|
125
|
+
},
|
|
126
|
+
askAgent: async (text, opts) => {
|
|
127
|
+
const llm = scope.channel?.llm;
|
|
128
|
+
if (!llm)
|
|
129
|
+
throw new Error('llm unavailable');
|
|
130
|
+
const dialog = await llm.createDialog({ agentUuid: opts.agentUuid, ...(opts.name != null ? { name: opts.name } : {}) });
|
|
131
|
+
return llm.ask(text, { agentUuid: opts.agentUuid, dialogUuid: dialog.uuid, ...(opts.hidden != null ? { hidden: opts.hidden } : {}) });
|
|
132
|
+
},
|
|
133
|
+
platform: platformOf(scope),
|
|
134
|
+
dialogEnv: (key, ...rest) => {
|
|
135
|
+
const env$ = scope.context.env$;
|
|
136
|
+
if (!rest.length)
|
|
137
|
+
return env$?.getValue?.()?.[key];
|
|
138
|
+
if (!env$) {
|
|
139
|
+
scope.logger.log('dialog_env_unavailable', { key });
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
env$.next({ ...(env$.getValue() ?? {}), [key]: rest[0] });
|
|
143
|
+
return rest[0];
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
exports.hookApi = hookApi;
|
|
148
|
+
/** `HookApi.platform`: the pass's phase, the campaign's budget and delay, where the dialog's leg goes, `platform.call`. */
|
|
149
|
+
function platformOf(scope) {
|
|
150
|
+
const { context, logger, platform } = scope;
|
|
151
|
+
const recallCount = (0, agent_sdk_1.parseRecallCount)(context.recallCount);
|
|
152
|
+
const recallDelaySec = (0, agent_sdk_1.parseRecallDelaySeconds)(context.recallDelay);
|
|
153
|
+
return {
|
|
154
|
+
phase: (0, agent_sdk_1.getScriptPhase)(context),
|
|
155
|
+
...(typeof context.attempt === 'number' ? { attempt: context.attempt } : {}),
|
|
156
|
+
...(recallCount != null ? { recallCount } : {}),
|
|
157
|
+
...(recallDelaySec != null ? { recallDelaySec } : {}),
|
|
158
|
+
...(typeof context.msisdn === 'string' ? { msisdn: context.msisdn } : {}),
|
|
159
|
+
dialogMsisdn: () => (0, outbound_1.readScheduleMsisdn)(context, false),
|
|
160
|
+
entryPoint: () => {
|
|
161
|
+
const ep = (context.dialogParams ?? {})[outbound_1.SCHEDULE_OUTBOUND_PARAM_ENTRY];
|
|
162
|
+
return typeof ep === 'string' && ep.trim() ? ep.trim() : 'main';
|
|
163
|
+
},
|
|
164
|
+
routing: () => (0, outbound_1.buildScheduleRouting)(context, logger),
|
|
165
|
+
...(platform?.call && context.legacyV3Compat
|
|
166
|
+
? { call: (msisdn, options) => platform.call(msisdn, options) }
|
|
167
|
+
: {}),
|
|
168
|
+
setDialogResult: (value) => {
|
|
169
|
+
try {
|
|
170
|
+
if (platform)
|
|
171
|
+
platform.dialog.result = value;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
/* not every platform keeps a dialog result */
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A step whose requests the agent's hook makes: bounded, never throws (a failure is logged as `<id>_failed`); what
|
|
181
|
+
* the hook returns is the outcome's `json` (an object's fields go into the row after the call).
|
|
182
|
+
*/
|
|
183
|
+
async function runHookIntegration(i, row, scope) {
|
|
184
|
+
const { logger } = scope;
|
|
185
|
+
try {
|
|
186
|
+
const enabled = await integrationEnabled(i, scope);
|
|
187
|
+
if (!enabled.on) {
|
|
188
|
+
logger.log(`${i.id}_skipped`, { reason: 'switched off (enabledBy)' });
|
|
189
|
+
return { id: i.id, skipped: 'switched off (enabledBy)', ok: false, status: null, text: null };
|
|
190
|
+
}
|
|
191
|
+
const hook = scope.hooks?.[i.run.hook];
|
|
192
|
+
if (!hook)
|
|
193
|
+
throw new Error(`[templates/integrations] no hook "${i.run.hook}"`);
|
|
194
|
+
let timer;
|
|
195
|
+
const limit = new Promise((_, reject) => {
|
|
196
|
+
timer = setTimeout(() => reject(new Error(`timed out after ${i.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS} ms`)), i.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS);
|
|
197
|
+
});
|
|
198
|
+
let out;
|
|
199
|
+
try {
|
|
200
|
+
out = await Promise.race([Promise.resolve(hook(scope.call, row, hookApi(scope, scope.call))), limit]);
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
if (timer)
|
|
204
|
+
clearTimeout(timer);
|
|
205
|
+
}
|
|
206
|
+
return { id: i.id, ok: true, status: null, text: null, json: out };
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
logger.log(`${i.id}_failed`, { err: String(err) });
|
|
210
|
+
return { id: i.id, ok: false, status: null, text: null, error: String(err) };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The `phase: 'answer'` hook steps of a live call, started at once and not waited for (each bounded by its `timeoutMs`;
|
|
215
|
+
* a failure is logged, never thrown). Their input is `{}`.
|
|
216
|
+
*/
|
|
217
|
+
function startAnswerHooks(all, scope) {
|
|
218
|
+
for (const i of all ?? []) {
|
|
219
|
+
if (i.phase !== 'answer' || !isHookIntegration(i))
|
|
220
|
+
continue;
|
|
221
|
+
void runHookIntegration(i, {}, scope);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.startAnswerHooks = startAnswerHooks;
|
|
225
|
+
/** The locals every data form of an integration sees: the call's identity and direction, plus the scope's own. */
|
|
226
|
+
function baseLocals(scope) {
|
|
227
|
+
return {
|
|
228
|
+
dialogUuid: scope.context.dialogUuid,
|
|
229
|
+
callUuid: (0, env_1.readCallUuid)(scope.context),
|
|
230
|
+
direction: (0, env_1.readCallDirection)(scope.context) ?? null,
|
|
231
|
+
...(scope.locals ?? {}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function agentEnvOf(scope) {
|
|
235
|
+
const env = scope.context.agent?.env;
|
|
236
|
+
if (!env)
|
|
237
|
+
return undefined;
|
|
238
|
+
return (key, ...rest) => (rest.length && rest[0] !== undefined ? env(key, ...rest.filter((x) => x !== undefined)) : env(key));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* One integration request. `row` is what `body` reads (the report row after the call, the hook's input in a call).
|
|
242
|
+
* Never throws: a failure is logged (`<id>_failed`) and returned.
|
|
243
|
+
*/
|
|
244
|
+
async function runIntegration(i, row, scope) {
|
|
245
|
+
const { logger, context } = scope;
|
|
246
|
+
const data = new integration_data_1.DataScope((0, integration_data_1.envOf)(i), scope.call, { row, input: row }, baseLocals(scope));
|
|
247
|
+
const lg = new integration_data_1.IntegrationLogger(i.id, i.log, logger, data);
|
|
248
|
+
const skip = (reason, checkLog) => {
|
|
249
|
+
lg.skipped(reason, checkLog);
|
|
250
|
+
data.set({ why: reason ?? null });
|
|
251
|
+
// `log.after` decides by its own `when` whether a skip gets the summary line too.
|
|
252
|
+
lg.after();
|
|
253
|
+
return { id: i.id, skipped: reason ?? 'skipWhen', ok: false, status: null, text: null, data };
|
|
254
|
+
};
|
|
255
|
+
const method = i.method;
|
|
256
|
+
try {
|
|
257
|
+
const enabled = await integrationEnabled(i, scope);
|
|
258
|
+
if (!enabled.on)
|
|
259
|
+
return skip('switched off (enabledBy)');
|
|
260
|
+
const loadInputs = (0, integration_data_1.inputReader)(i.inputs, data, scope);
|
|
261
|
+
const check = await (0, integration_data_1.firstSkip)(i.skipWhen, data, loadInputs);
|
|
262
|
+
if (check)
|
|
263
|
+
return skip(check.why, check.log);
|
|
264
|
+
await loadInputs();
|
|
265
|
+
let cooldownKey = null;
|
|
266
|
+
if (i.cooldown) {
|
|
267
|
+
const cd = await (0, integration_data_1.cooldownHolds)(i.cooldown, data, agentEnvOf(scope), Date.now());
|
|
268
|
+
if (cd.unavailable)
|
|
269
|
+
return skip('agent env unavailable');
|
|
270
|
+
if (cd.holds) {
|
|
271
|
+
data.set({ last: cd.last });
|
|
272
|
+
return skip(i.cooldown.why ?? 'cooldown', { object: { last: { local: 'last' } } });
|
|
273
|
+
}
|
|
274
|
+
cooldownKey = cd.key;
|
|
275
|
+
}
|
|
276
|
+
const headers = {};
|
|
277
|
+
for (const [name, v] of Object.entries(i.headers ?? {})) {
|
|
278
|
+
const value = await (0, integration_data_1.headerValue)(v, data, scope);
|
|
279
|
+
if (value === undefined)
|
|
280
|
+
return skip(`header ${name} has no value`);
|
|
281
|
+
headers[name] = value;
|
|
282
|
+
}
|
|
283
|
+
const rawUrl = (0, evaluate_1.isExprNode)(i.url) && !('from' in i.url) ? data.text(i.url) : await (0, sources_1.resolveValue)(i.url, scope);
|
|
284
|
+
if ((0, sources_1.isEmptyValue)(rawUrl))
|
|
285
|
+
return skip('url has no value');
|
|
286
|
+
const url = (0, integration_data_1.withQuery)(fillPlaceholders(i.path != null ? `${String(rawUrl).replace(/\/+$/, '')}${i.path}` : String(rawUrl), scope), i.query, data);
|
|
287
|
+
const api = hookApi(scope, scope.call);
|
|
288
|
+
const raw = method === 'GET' ? undefined : isDataBody(i.body) ? data.expr(i.body) : await bodyOf(i, row, scope, api, data);
|
|
289
|
+
const body = raw === undefined ? undefined : (0, integration_data_1.serializeBody)(raw, i.serialize);
|
|
290
|
+
data.set({ url: (0, http_1.urlForLog)(url), body: body ?? null });
|
|
291
|
+
const requestId = i.requestId === 'callUuid' ? (0, env_1.readCallUuid)(context) : i.requestId === 'dialogUuid' ? context.dialogUuid : undefined;
|
|
292
|
+
const attempts = 1 + Math.max(0, i.retries ?? 0);
|
|
293
|
+
const safe = repeatable(i, headers);
|
|
294
|
+
let last = { id: i.id, ok: false, status: null, text: null };
|
|
295
|
+
const startedAt = Date.now();
|
|
296
|
+
for (let n = 1; n <= attempts; n++) {
|
|
297
|
+
if (n > 1)
|
|
298
|
+
await delay(RETRY_DELAY_MS);
|
|
299
|
+
try {
|
|
300
|
+
const res = await (0, http_1.httpRequest)(logger, url, {
|
|
301
|
+
method,
|
|
302
|
+
headers,
|
|
303
|
+
...(body !== undefined ? { body: (0, integration_data_1.bodyText)(body, i.serialize).text } : {}),
|
|
304
|
+
timeoutMs: i.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
305
|
+
...(requestId ? { requestId } : {}),
|
|
306
|
+
event: lg.httpEvent,
|
|
307
|
+
});
|
|
308
|
+
const ok = res.status >= 200 && res.status < 300;
|
|
309
|
+
last = { id: i.id, ok, status: res.status, text: res.text, json: parseJson(res.text) };
|
|
310
|
+
// A redirect is not followed and would only repeat; a non-idempotent request is repeated on a 5xx other
|
|
311
|
+
// than 504 (a gateway timeout: the peer may have processed it).
|
|
312
|
+
const wanted = !ok && n < attempts && (res.status < 300 || res.status >= 400) && (i.retryOn === 'any' || res.status >= 500);
|
|
313
|
+
const allowed = safe || (res.status >= 500 && res.status !== 504);
|
|
314
|
+
if (wanted && !allowed)
|
|
315
|
+
logger.log(`${i.id}_not_retried`, { status: res.status, reason: 'non-idempotent request may have been processed' });
|
|
316
|
+
if (!wanted || !allowed)
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
last = { id: i.id, ok: false, status: null, text: null, error: String(err) };
|
|
321
|
+
if (n >= attempts)
|
|
322
|
+
break;
|
|
323
|
+
// A timeout or a reset may have reached the peer: only a request that certainly did not is repeated.
|
|
324
|
+
if (!safe && !(0, http_1.requestNotSent)(err)) {
|
|
325
|
+
logger.log(`${i.id}_not_retried`, { err: String(err), reason: 'non-idempotent request may have been processed' });
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const invalid = last.ok && i.read?.expect === 'object' && !(0, values_1.isPlainObject)(last.json);
|
|
331
|
+
if (invalid)
|
|
332
|
+
last = { ...last, ok: false };
|
|
333
|
+
data.set({
|
|
334
|
+
status: last.status, text: last.text, json: last.json ?? null, jsonError: last.json === undefined ? jsonError(last.text) : null,
|
|
335
|
+
err: last.error ?? null, ok: last.ok, ms: Date.now() - startedAt,
|
|
336
|
+
...(invalid ? { invalid: true } : {}),
|
|
337
|
+
});
|
|
338
|
+
for (const [name, path] of Object.entries(i.read?.save ?? {}))
|
|
339
|
+
data.set({ [name]: (0, integration_data_1.atPath)(last.json, path) ?? null });
|
|
340
|
+
if (last.ok || (lg.anyStatus && last.status != null)) {
|
|
341
|
+
lg.sent({ status: last.status });
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
const response = last.text?.slice(0, 500);
|
|
345
|
+
lg.failed({
|
|
346
|
+
status: last.status,
|
|
347
|
+
...(last.status != null && last.status >= 300 && last.status < 400 ? { reason: 'redirect not followed', url: (0, http_1.urlForLog)(url) } : {}),
|
|
348
|
+
...(last.error ? { err: last.error } : { response }),
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
lg.after();
|
|
352
|
+
if (last.ok && cooldownKey != null && i.cooldown)
|
|
353
|
+
await (0, integration_data_1.stampCooldown)(i.cooldown, cooldownKey, agentEnvOf(scope), new Date());
|
|
354
|
+
return { ...last, data };
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
data.set({ err: String(err), status: null, text: null, ok: false });
|
|
358
|
+
lg.failed({ err: String(err) });
|
|
359
|
+
lg.after();
|
|
360
|
+
return { id: i.id, ok: false, status: null, text: null, error: String(err), data };
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.runIntegration = runIntegration;
|
|
364
|
+
/** A body written in the data language (evaluated at run time with the integration's locals). */
|
|
365
|
+
function isDataBody(b) {
|
|
366
|
+
return b !== undefined && typeof b !== 'function' && (0, evaluate_1.isExprNode)(b) && !((0, values_1.isPlainObject)(b) && 'hook' in b && Object.keys(b).length === 1);
|
|
367
|
+
}
|
|
368
|
+
/** Row fields an after-call integration writes from its outcome (`rowFields`, `onSkip`, `onFail`). */
|
|
369
|
+
function writeRowFields(i, r, row, logger) {
|
|
370
|
+
const fields = r.skipped ? i.onSkip : r.ok ? i.rowFields : i.onFail ?? i.rowFields;
|
|
371
|
+
if (!fields || !r.data)
|
|
372
|
+
return;
|
|
373
|
+
try {
|
|
374
|
+
for (const [k, v] of Object.entries(r.data.record(fields)))
|
|
375
|
+
if (!UNSAFE_KEYS.has(k))
|
|
376
|
+
row[k] = v;
|
|
377
|
+
}
|
|
378
|
+
catch (err) {
|
|
379
|
+
logger.log(`${i.id}_row_fields_failed`, { err: String(err) });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* `phase: 'lookup'`: the request of `input.lookup`, and the field's value from its outcome (`value`; locals of the
|
|
384
|
+
* outcome plus `outcome`: `sent`, `skipped`, `failed`). Without `value`: the parsed answer of a 2xx, else `null`.
|
|
385
|
+
*/
|
|
386
|
+
async function runLookupIntegration(i, scope) {
|
|
387
|
+
const r = await runIntegration(i, {}, scope);
|
|
388
|
+
const outcome = r.skipped ? 'skipped' : r.ok ? 'sent' : 'failed';
|
|
389
|
+
if (i.value === undefined || !r.data)
|
|
390
|
+
return r.ok ? r.json ?? r.text : null;
|
|
391
|
+
r.data.set({ outcome, why: r.skipped ?? null });
|
|
392
|
+
return r.data.expr(i.value);
|
|
393
|
+
}
|
|
394
|
+
exports.runLookupIntegration = runLookupIntegration;
|
|
395
|
+
/**
|
|
396
|
+
* The `phase: 'beforeCall'` steps of the pre-call pass, in order (hook steps and `askAgent`), awaited; each never
|
|
397
|
+
* throws.
|
|
398
|
+
*/
|
|
399
|
+
async function runBeforeCall(all, scope) {
|
|
400
|
+
for (const i of all ?? []) {
|
|
401
|
+
if (i.phase !== 'beforeCall')
|
|
402
|
+
continue;
|
|
403
|
+
if (isHookIntegration(i))
|
|
404
|
+
await runHookIntegration(i, {}, scope);
|
|
405
|
+
else if (!isHttpIntegration(i) && i.kind === 'askAgent')
|
|
406
|
+
await (0, agent_integrations_1.runAskAgent)(i, scope);
|
|
407
|
+
else if (!isHttpIntegration(i))
|
|
408
|
+
await (0, agent_integrations_1.runAgentDialog)(i, {}, scope);
|
|
409
|
+
else
|
|
410
|
+
await runIntegration(i, {}, scope);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
exports.runBeforeCall = runBeforeCall;
|
|
414
|
+
/** Whether an after-call integration applies to this row. */
|
|
415
|
+
function appliesTo(i, row, call, answered) {
|
|
416
|
+
const when = i.when ?? 'answered';
|
|
417
|
+
if (when === 'always')
|
|
418
|
+
return true;
|
|
419
|
+
if (when === 'answered')
|
|
420
|
+
return answered;
|
|
421
|
+
if (when === 'failedDial')
|
|
422
|
+
return !answered;
|
|
423
|
+
return (0, compiled_1.noData)(when)(row, call);
|
|
424
|
+
}
|
|
425
|
+
exports.appliesTo = appliesTo;
|
|
426
|
+
/** {@link appliesTo} for the after-call run: a `when` that throws skips the integration (logged). */
|
|
427
|
+
function appliesSafely(i, row, call, answered, logger) {
|
|
428
|
+
try {
|
|
429
|
+
return appliesTo(i, row, call, answered);
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
logger.log(`${i.id}_skipped`, { reason: 'when threw', err: String(err) });
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/** A hook's result fields into the row: own keys only, never `__proto__` / `constructor` / `prototype`. */
|
|
437
|
+
function mergeInto(row, fields) {
|
|
438
|
+
for (const key of Object.keys(fields)) {
|
|
439
|
+
if (UNSAFE_KEYS.has(key))
|
|
440
|
+
continue;
|
|
441
|
+
Object.defineProperty(row, key, { value: fields[key], enumerable: true, writable: true, configurable: true });
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/** Runs the `afterCall` integrations that apply to the row, in order; writes `writeBack` statuses into the row. */
|
|
445
|
+
async function runAfterCall(integrations, row, answered, scope) {
|
|
446
|
+
const out = [];
|
|
447
|
+
// A `when` condition reads `{ fact: 'connected' }` / `rowKind` of the row it runs after.
|
|
448
|
+
const whenCall = scope.call.rowFacts ? scope.call : {
|
|
449
|
+
...scope.call,
|
|
450
|
+
rowFacts: {
|
|
451
|
+
kind: answered ? 'call' : 'failedDial', connected: answered, service: {}, callUuid: null, dialogUuid: null,
|
|
452
|
+
asrDurationSec: null, sipCode: null, sipPhrase: null, replyLanguage: null, replyLanguageProvisional: false,
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
for (const i of integrations ?? []) {
|
|
456
|
+
if (i.phase !== 'afterCall' || ('kind' in i && i.kind === 'askAgent'))
|
|
457
|
+
continue;
|
|
458
|
+
if (!appliesSafely(i, row, whenCall, answered, scope.logger)) {
|
|
459
|
+
if (isHttpIntegration(i) && i.writeBack && typeof i.writeBack !== 'string')
|
|
460
|
+
writeBack(i, { applied: false, skipped: null, status: null, error: null }, row, scope);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (!isHttpIntegration(i) && !isHookIntegration(i)) {
|
|
464
|
+
out.push(await (0, agent_integrations_1.runAgentDialog)(i, row, { ...scope, all: scope.all ?? integrations }));
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if ('run' in i) {
|
|
468
|
+
const r = await runHookIntegration(i, row, { ...scope, all: scope.all ?? integrations });
|
|
469
|
+
// The fields a hook step returns go into the row.
|
|
470
|
+
if (r.ok && r.json != null && typeof r.json === 'object')
|
|
471
|
+
mergeInto(row, r.json);
|
|
472
|
+
out.push(r);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const r = await runIntegration(i, row, { ...scope, all: scope.all ?? integrations });
|
|
476
|
+
writeRowFields(i, r, row, scope.logger);
|
|
477
|
+
if (typeof i.writeBack === 'string')
|
|
478
|
+
row[i.writeBack] = r.skipped ? null : r.status ?? 'failed';
|
|
479
|
+
else if (i.writeBack)
|
|
480
|
+
writeBack(i, { applied: true, skipped: r.skipped ?? null, status: r.status, error: r.error ?? null }, row, scope);
|
|
481
|
+
out.push(r);
|
|
482
|
+
}
|
|
483
|
+
return out;
|
|
484
|
+
}
|
|
485
|
+
exports.runAfterCall = runAfterCall;
|
|
486
|
+
/** `writeBack: { field, value }`: the field gets what `value` returns (`undefined` or a throw: nothing is written). */
|
|
487
|
+
function writeBack(i, outcome, row, scope) {
|
|
488
|
+
const wb = i.writeBack;
|
|
489
|
+
let v;
|
|
490
|
+
try {
|
|
491
|
+
v = (0, compiled_1.noData)(wb.value)(outcome, row, scope.call);
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
scope.logger.log(`${i.id}_write_back_failed`, { field: wb.field, err: String(err) });
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (v !== undefined)
|
|
498
|
+
row[wb.field] = v;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* The pre-dial gate (`platform.preDial`): `true` to dial. A switched-off or unconfigured gate dials; a failed request
|
|
502
|
+
* or an answer that reads as neither yes nor no dials only with `failOpen`.
|
|
503
|
+
*/
|
|
504
|
+
async function preDialAllows(gate, integrations, scope) {
|
|
505
|
+
const i = integrations?.find((x) => x.id === gate.integration && isHttpIntegration(x));
|
|
506
|
+
if (!i)
|
|
507
|
+
throw new Error(`[templates/integrations] no preDial integration "${gate.integration}"`);
|
|
508
|
+
const r = await runIntegration(i, {}, { ...scope, all: scope.all ?? integrations });
|
|
509
|
+
if (r.skipped)
|
|
510
|
+
return true;
|
|
511
|
+
if (!r.ok)
|
|
512
|
+
return gate.failOpen;
|
|
513
|
+
let answer;
|
|
514
|
+
try {
|
|
515
|
+
const read = i.read?.answer;
|
|
516
|
+
if (read) {
|
|
517
|
+
const v = (0, integration_data_1.atPath)(r.json, read.path);
|
|
518
|
+
answer = typeof v !== 'boolean' ? null : v || (read.or !== undefined && r.data != null && r.data.cond(read.or));
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
answer = i.answer ? (0, compiled_1.noData)(i.answer)(r.json, scope.call) : r.json === true;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
catch (err) {
|
|
525
|
+
scope.logger.log(`${i.id}_failed`, { reason: 'answer threw', err: String(err) });
|
|
526
|
+
answer = null;
|
|
527
|
+
}
|
|
528
|
+
if (answer === null) {
|
|
529
|
+
scope.logger.log(`${i.id}_failed`, { reason: 'no usable answer', response: r.text?.slice(0, 500) });
|
|
530
|
+
return gate.failOpen;
|
|
531
|
+
}
|
|
532
|
+
scope.logger.log(`${i.id}_done`, { status: r.status, answer });
|
|
533
|
+
return answer;
|
|
534
|
+
}
|
|
535
|
+
exports.preDialAllows = preDialAllows;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ExprEnv } from '../expr/context';
|
|
2
|
+
import type { AfterLegPolicy, CallbackPolicy, RouteRule, TrunkPool } from '../integration-forms';
|
|
3
|
+
import type { AnyHook, CallView } from '../spec';
|
|
4
|
+
type Obj = Record<string, unknown>;
|
|
5
|
+
/** Legs of the dialog already done: the larger of the count kept at `memoryKey` and the platform's `attempt − 1`. */
|
|
6
|
+
export declare function completedLegs(call: CallView, memoryKey: string): number;
|
|
7
|
+
/**
|
|
8
|
+
* The `platform.afterLeg` hook of an {@link AfterLegPolicy}: counts the leg (dialog env), writes the pass's values,
|
|
9
|
+
* decides, logs, places the next leg — or runs the `onDone` integrations and writes the dialog result.
|
|
10
|
+
*/
|
|
11
|
+
export declare function afterLegPolicyHook(policy: AfterLegPolicy, env: ExprEnv): AnyHook;
|
|
12
|
+
/** A trunk of the pool, picked by `random` (default `Math.random`). */
|
|
13
|
+
export declare function pickTrunk(pool: TrunkPool, random?: () => number): TrunkPool['trunks'][number] | null;
|
|
14
|
+
/** The picked trunk's SIP extras (`{callerId}`, `{name}`, `{id}`, `{domain}` filled). */
|
|
15
|
+
export declare function trunkHeaders(pool: TrunkPool, t: TrunkPool['trunks'][number]): Record<string, string>;
|
|
16
|
+
/** The `platform.legs.route` hook of route rules and a trunk pool: the first rule that holds, else a trunk of the pool. */
|
|
17
|
+
export declare function routeHook(rules: readonly RouteRule[] | undefined, pool: TrunkPool | undefined, env: ExprEnv): AnyHook;
|
|
18
|
+
/** The instant a wall-clock time of a zone names. */
|
|
19
|
+
export declare function zonedInstant(year: number, month: number, day: number, hour: number, minute: number, timeZone: string): Date;
|
|
20
|
+
/** 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. */
|
|
21
|
+
export declare function parseCallbackTime(raw: unknown, cfg: Pick<CallbackPolicy, 'timeZone' | 'hours'>): {
|
|
22
|
+
at: Date;
|
|
23
|
+
kind: 'clock' | 'part_of_day' | 'day';
|
|
24
|
+
} | null;
|
|
25
|
+
/** When the callback is due: the named time (or soon, when it passed), the campaign's delay, or the fallback delay. */
|
|
26
|
+
export declare function callbackDue(time: unknown, now: Date, recallDelaySec: number | undefined, cfg: Pick<CallbackPolicy, 'timeZone' | 'hours' | 'passedDelaySec' | 'fallbackDelaySec'>): {
|
|
27
|
+
at: Date;
|
|
28
|
+
source: string;
|
|
29
|
+
named: string;
|
|
30
|
+
} | {
|
|
31
|
+
at: Date;
|
|
32
|
+
source: string;
|
|
33
|
+
named: null;
|
|
34
|
+
};
|
|
35
|
+
/** Which call of the dialog this is: its attempt (platform count or failed-leg redials), or the callbacks and redials before it plus one. */
|
|
36
|
+
export declare function callOrdinal(hostAttempt: number, env: Obj, callUuid: string | null, envKey: string): number;
|
|
37
|
+
/**
|
|
38
|
+
* The after-call hook step of a {@link CallbackPolicy}: books the callback the conversation asked for (once per
|
|
39
|
+
* call), at the named time, over the trunk pool, within the campaign's calls of the dialog. Lines:
|
|
40
|
+
* `callback_scheduled`, `callback_not_scheduled` (`reason`), `callback_schedule_failed`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function callbackHook(cfg: CallbackPolicy, pool: TrunkPool | undefined, dialNumber: ((msisdn: string) => string) | undefined, env: ExprEnv): AnyHook;
|
|
43
|
+
export {};
|