@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,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flattenLines = exports.languageLadder = void 0;
|
|
4
|
+
// The reply language of a call with several languages: the evidence ladder over the caller's own words, read from the
|
|
5
|
+
// locale packs (`LocalePack.evidence`): explicit requests and refusals, strong markers, pairs of weak markers, a line
|
|
6
|
+
// the recognizer labelled, plain orthography (no letters of the other languages), else a provisional pick. The
|
|
7
|
+
// language that is not picked by evidence is the call's first (`languages[0]`).
|
|
8
|
+
const locales_1 = require("../locales");
|
|
9
|
+
const match_1 = require("./match");
|
|
10
|
+
/** Weak markers count only in pairs; a labelled line needs this many words; plain orthography this many. */
|
|
11
|
+
const WEAK_PAIR = 2;
|
|
12
|
+
const LABELLED_MIN_WORDS = 3;
|
|
13
|
+
const LABELLED_MIN_LETTER_WORDS = 2;
|
|
14
|
+
const LABELLED_MIN_SHARE = 0.4;
|
|
15
|
+
const PLAIN_MIN_WORDS = 4;
|
|
16
|
+
const PLAIN_MAX_SHARE = 0.2;
|
|
17
|
+
/** A bare language name (no request words around it) is a request only on a short line. */
|
|
18
|
+
const BARE_MAX_WORDS = 3;
|
|
19
|
+
const LABEL = /^\s*\[([a-z-]{2,8})\]\s*/i;
|
|
20
|
+
const anyTest = (list, text) => list.some((p) => {
|
|
21
|
+
p.lastIndex = 0;
|
|
22
|
+
return p.test(text);
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* The ladder for the call's languages. `neutral`: the agent's own words that carry no evidence (brand names); `strong`:
|
|
26
|
+
* the agent's own strong markers.
|
|
27
|
+
*/
|
|
28
|
+
function languageLadder(languages, opts = {}) {
|
|
29
|
+
const first = languages[0];
|
|
30
|
+
const packs = languages.map((code) => {
|
|
31
|
+
const e = (0, locales_1.getLocale)(code)?.evidence ?? {};
|
|
32
|
+
return {
|
|
33
|
+
code,
|
|
34
|
+
strong: [...(e.strong ?? []), ...(opts.strong?.[code] ?? [])],
|
|
35
|
+
weak: e.weak ?? [],
|
|
36
|
+
request: e.request ?? [],
|
|
37
|
+
reject: e.reject ?? [],
|
|
38
|
+
...(e.requestCue ? { cue: e.requestCue } : {}),
|
|
39
|
+
...(e.metaQuestion ? { meta: e.metaQuestion } : {}),
|
|
40
|
+
...(e.letters ? { letters: e.letters } : {}),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const neutral = new Set(opts.neutral?.map((w) => w.toLowerCase()) ?? []);
|
|
44
|
+
for (const code of languages)
|
|
45
|
+
for (const w of (0, locales_1.getLocale)(code)?.evidence?.neutralWords ?? [])
|
|
46
|
+
neutral.add(w.toLowerCase());
|
|
47
|
+
for (const w of opts.notNeutral ?? [])
|
|
48
|
+
neutral.delete(w.toLowerCase());
|
|
49
|
+
const name = (code) => opts.names?.[code] ?? code;
|
|
50
|
+
const packOf = (code) => packs.find((p) => p.code === code);
|
|
51
|
+
const evidenceWords = (text) => (0, match_1.lineWords)(text).filter((w) => w.length > 1 && !neutral.has(w));
|
|
52
|
+
const hits = (words, patterns) => [...new Set(words.filter((w) => patterns.some((p) => p.test(w))))];
|
|
53
|
+
/** Share of words with letters of a language other than `code`. */
|
|
54
|
+
const foreignShare = (words, code) => {
|
|
55
|
+
if (!words.length)
|
|
56
|
+
return 0;
|
|
57
|
+
const others = packs.filter((p) => p.code !== code && p.letters);
|
|
58
|
+
return words.filter((w) => others.some((p) => p.letters.test(w))).length / words.length;
|
|
59
|
+
};
|
|
60
|
+
const lines = (text) => text.split('\n').map((l) => {
|
|
61
|
+
const m = LABEL.exec(l);
|
|
62
|
+
return { label: m ? m[1].toLowerCase() : null, text: l.replace(LABEL, '').trim() };
|
|
63
|
+
}).filter((l) => l.text.length > 0);
|
|
64
|
+
const isBare = (text, own) => {
|
|
65
|
+
const ls = lines(text);
|
|
66
|
+
const others = packs.filter((p) => p !== own);
|
|
67
|
+
return ls.length > 0 && ls.every((l) => (0, match_1.lineWords)(l.text).length <= BARE_MAX_WORDS
|
|
68
|
+
&& anyTest(own.request, l.text) && !others.some((o) => anyTest(o.request, l.text)));
|
|
69
|
+
};
|
|
70
|
+
const requested = (text) => {
|
|
71
|
+
if (packs.some((p) => p.meta && p.meta.test(text)))
|
|
72
|
+
return null;
|
|
73
|
+
const rejected = packs.filter((p) => anyTest(p.reject, text));
|
|
74
|
+
if (rejected.length > 0 && rejected.length < packs.length) {
|
|
75
|
+
const kept = packs.filter((p) => !rejected.includes(p));
|
|
76
|
+
return (kept.find((p) => p.code === first) ?? kept[0]).code;
|
|
77
|
+
}
|
|
78
|
+
const asked = packs.filter((p) => anyTest(p.request, text));
|
|
79
|
+
if (asked.length !== 1)
|
|
80
|
+
return null;
|
|
81
|
+
const target = asked[0];
|
|
82
|
+
const cue = packs.some((p) => p.cue && p.cue.test(text));
|
|
83
|
+
if (!cue && !isBare(text, target))
|
|
84
|
+
return null;
|
|
85
|
+
return target.code;
|
|
86
|
+
};
|
|
87
|
+
const labelled = (text) => {
|
|
88
|
+
const ls = lines(text);
|
|
89
|
+
if (ls.length !== 1)
|
|
90
|
+
return null;
|
|
91
|
+
const own = packs.find((p) => p.code !== first && p.letters && ls[0].label === name(p.code).toLowerCase());
|
|
92
|
+
if (!own)
|
|
93
|
+
return null;
|
|
94
|
+
const words = (0, match_1.lineWords)(ls[0].text);
|
|
95
|
+
if (words.length < LABELLED_MIN_WORDS)
|
|
96
|
+
return null;
|
|
97
|
+
if (hits(words, packOf(first).strong).length > 0)
|
|
98
|
+
return null;
|
|
99
|
+
const lettered = words.filter((w) => own.letters.test(w)).length;
|
|
100
|
+
return lettered >= LABELLED_MIN_LETTER_WORDS && lettered / words.length >= LABELLED_MIN_SHARE ? own.code : null;
|
|
101
|
+
};
|
|
102
|
+
const reason = (rung, found) => `${rung}:${found.slice(0, 3).join(',')}`;
|
|
103
|
+
const decide = (text) => {
|
|
104
|
+
if (text == null || !text.trim())
|
|
105
|
+
return { language: first, reason: 'no_reply', provisional: true };
|
|
106
|
+
const req = requested(text);
|
|
107
|
+
if (req != null)
|
|
108
|
+
return { language: req, reason: `explicit_language_request:${name(req)}`, provisional: false };
|
|
109
|
+
const words = evidenceWords(text);
|
|
110
|
+
const strong = packs.map((p) => ({ p, found: hits(words, p.strong) }));
|
|
111
|
+
const top = Math.max(...strong.map((x) => x.found.length));
|
|
112
|
+
const leaders = strong.filter((x) => x.found.length === top);
|
|
113
|
+
if (top > 0 && leaders.length === 1) {
|
|
114
|
+
const l = leaders[0];
|
|
115
|
+
return { language: l.p.code, reason: reason(`${name(l.p.code)}_marker`, l.found), provisional: false };
|
|
116
|
+
}
|
|
117
|
+
if (top > 0)
|
|
118
|
+
return { language: first, reason: reason('mixed_evidence', strong.flatMap((x) => x.found)), provisional: false };
|
|
119
|
+
for (const p of packs) {
|
|
120
|
+
if (p.code === first)
|
|
121
|
+
continue;
|
|
122
|
+
const weak = hits(words, p.weak);
|
|
123
|
+
if (weak.length >= WEAK_PAIR)
|
|
124
|
+
return { language: p.code, reason: reason(`${name(p.code)}_weak_pair`, weak), provisional: false };
|
|
125
|
+
}
|
|
126
|
+
const label = labelled(text);
|
|
127
|
+
if (label)
|
|
128
|
+
return { language: label, reason: `${name(label)}_selected_reading`, provisional: false };
|
|
129
|
+
if (words.length >= PLAIN_MIN_WORDS && foreignShare(words, first) <= PLAIN_MAX_SHARE) {
|
|
130
|
+
return { language: first, reason: `${name(first)}_plain_orthography`, provisional: false };
|
|
131
|
+
}
|
|
132
|
+
return { language: first, reason: 'neutral_reply', provisional: true };
|
|
133
|
+
};
|
|
134
|
+
const fallbackEvidence = (text, to) => {
|
|
135
|
+
const words = evidenceWords(text);
|
|
136
|
+
for (const p of packs) {
|
|
137
|
+
if (p.code === to)
|
|
138
|
+
continue;
|
|
139
|
+
if (hits(words, p.strong).length > 0 || hits(words, p.weak).length > 0)
|
|
140
|
+
return 'other';
|
|
141
|
+
}
|
|
142
|
+
if (hits(words, packOf(to).strong).length >= WEAK_PAIR)
|
|
143
|
+
return 'fallback';
|
|
144
|
+
if (words.length >= PLAIN_MIN_WORDS && foreignShare(words, to) <= PLAIN_MAX_SHARE)
|
|
145
|
+
return 'fallback';
|
|
146
|
+
return null;
|
|
147
|
+
};
|
|
148
|
+
return { languages, decide, requested, fallbackEvidence, name };
|
|
149
|
+
}
|
|
150
|
+
exports.languageLadder = languageLadder;
|
|
151
|
+
/** Lines of an answer joined for a marker (`a | b`). */
|
|
152
|
+
function flattenLines(text) {
|
|
153
|
+
return text.split('\n').map((l) => l.trim()).filter(Boolean).join(' | ');
|
|
154
|
+
}
|
|
155
|
+
exports.flattenLines = flattenLines;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MediaChannel, ScriptDialogContext, ScriptLogger } from '@voctiv/agent-sdk';
|
|
2
|
+
import type { AgentHooks } from '../spec';
|
|
3
|
+
import { type CallVars } from '../business/input';
|
|
4
|
+
import type { EngineSpec } from '../spec';
|
|
5
|
+
export interface LookupOutcome {
|
|
6
|
+
/** The call's variables built again with the looked-up value. */
|
|
7
|
+
readonly vars: Readonly<Record<string, unknown>>;
|
|
8
|
+
/** The call's result from now on (`input.lookup.result`), or none. */
|
|
9
|
+
readonly result: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface LookupState {
|
|
12
|
+
/** Settles once the lookup is over (never rejects): its outcome, or null when it failed. */
|
|
13
|
+
promise: Promise<LookupOutcome | null>;
|
|
14
|
+
/** `undefined` while the lookup runs. */
|
|
15
|
+
done: LookupOutcome | null | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The lookup of this pass, if the agent file has one and the pass started it. */
|
|
18
|
+
export declare function lookupOf(context: ScriptDialogContext): LookupState | undefined;
|
|
19
|
+
/** Starts `input.lookup` (not awaited): the payload of the pass is replaced by the rebuilt one when it is in. */
|
|
20
|
+
export declare function startLookup(spec: EngineSpec, hooks: AgentHooks | undefined, rebuild: (context: ScriptDialogContext, channel: MediaChannel, overrides: Readonly<Record<string, unknown>>) => CallVars, context: ScriptDialogContext, channel: MediaChannel, logger: ScriptLogger, payload: CallVars): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startLookup = exports.lookupOf = void 0;
|
|
4
|
+
const sip_1 = require("../../call/sip");
|
|
5
|
+
const integrations_1 = require("../business/integrations");
|
|
6
|
+
const sources_1 = require("../business/sources");
|
|
7
|
+
const input_1 = require("../business/input");
|
|
8
|
+
const compiled_1 = require("../expr/compiled");
|
|
9
|
+
const lookups = new WeakMap();
|
|
10
|
+
/** The lookup of this pass, if the agent file has one and the pass started it. */
|
|
11
|
+
function lookupOf(context) {
|
|
12
|
+
return lookups.get(context);
|
|
13
|
+
}
|
|
14
|
+
exports.lookupOf = lookupOf;
|
|
15
|
+
/** Starts `input.lookup` (not awaited): the payload of the pass is replaced by the rebuilt one when it is in. */
|
|
16
|
+
function startLookup(spec, hooks, rebuild, context, channel, logger, payload) {
|
|
17
|
+
const lookup = spec.input.lookup;
|
|
18
|
+
const call = (0, sources_1.businessCallView)({ vars: payload.vars, language: spec.languages[0], phase: 'opening' });
|
|
19
|
+
const sipHeaders = (0, sip_1.readInviteSipHeaders)(channel);
|
|
20
|
+
const scope = { context, logger, ...(hooks ? { hooks } : {}), ...(spec.integrations ? { all: spec.integrations } : {}) };
|
|
21
|
+
let run;
|
|
22
|
+
if (lookup.integration != null) {
|
|
23
|
+
// A lookup request as data: the integration's `value` is the field's value.
|
|
24
|
+
const i = spec.integrations?.find((x) => x.id === lookup.integration && (0, integrations_1.isHttpIntegration)(x));
|
|
25
|
+
if (!i)
|
|
26
|
+
throw new Error(`[templates/engine] input.lookup: no integration "${lookup.integration}"`);
|
|
27
|
+
run = () => (0, integrations_1.runLookupIntegration)(i, { ...scope, call, channel, locals: { sipHeaders: sipHeaders ?? null } });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const hook = lookup.hook != null ? hooks?.[lookup.hook] : undefined;
|
|
31
|
+
if (!hook)
|
|
32
|
+
throw new Error(`[templates/engine] input.lookup: no hook "${lookup.hook}"`);
|
|
33
|
+
const api = { ...(0, integrations_1.hookApi)(scope, call), ...(sipHeaders ? { sipHeaders } : {}) };
|
|
34
|
+
run = () => hook(call, undefined, api);
|
|
35
|
+
}
|
|
36
|
+
const state = { promise: Promise.resolve(null), done: undefined };
|
|
37
|
+
state.promise = Promise.resolve()
|
|
38
|
+
.then(run)
|
|
39
|
+
.then((value) => {
|
|
40
|
+
const next = rebuild(context, channel, { [lookup.field]: value });
|
|
41
|
+
(0, input_1.keepCallVars)(context, next);
|
|
42
|
+
const outcome = { vars: next.vars, result: (0, compiled_1.noData)(lookup.result)?.(next.vars) ?? null };
|
|
43
|
+
state.done = outcome;
|
|
44
|
+
return outcome;
|
|
45
|
+
}, (err) => {
|
|
46
|
+
logger.log('input_lookup_failed', { err: String(err) });
|
|
47
|
+
state.done = null;
|
|
48
|
+
return null;
|
|
49
|
+
});
|
|
50
|
+
lookups.set(context, state);
|
|
51
|
+
}
|
|
52
|
+
exports.startLookup = startLookup;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { LocaleCode } from '../locale';
|
|
2
|
+
import type { CallView, Matcher, Text } from '../spec';
|
|
3
|
+
import type { NamedMatchers } from '../expr/types';
|
|
4
|
+
/** A compiled matcher. */
|
|
5
|
+
export type LineTest = (text: string, call: CallView) => boolean;
|
|
6
|
+
/** Thrown for a part of the agent file the engine does not run yet; names the field. */
|
|
7
|
+
export declare class NotRunByEngine extends Error {
|
|
8
|
+
constructor(field: string);
|
|
9
|
+
}
|
|
10
|
+
/** Lower case, letters/digits/spaces only, single spaces. */
|
|
11
|
+
export declare function normalizeLine(text: string): string;
|
|
12
|
+
/** Recognizer labels in front of a line (`[ru] …`) are engine names, not speech. */
|
|
13
|
+
export declare function stripLabels(text: string): string;
|
|
14
|
+
/** Lower-case words of a line (labels dropped), split on anything that is not a letter or a digit. */
|
|
15
|
+
export declare function lineWords(text: string): string[];
|
|
16
|
+
/** Lower case, every non-letter/digit turned into one space (for `tail` with `words: true`). */
|
|
17
|
+
export declare function spacedLine(text: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* A lexicon name that names its pack (`'hi:voicemail'`): that pack's list, whatever the call's languages are. `null`
|
|
20
|
+
* for a plain name (the call's languages).
|
|
21
|
+
*/
|
|
22
|
+
export declare function lexiconRef(name: string): {
|
|
23
|
+
readonly pack: LocaleCode;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
} | null;
|
|
26
|
+
/** Words of a lexicon in every given language (union), lower case; a `pack:name` reads that pack only. */
|
|
27
|
+
export declare function lexiconWords(languages: readonly LocaleCode[], name: string): Set<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Compile a matcher. `intent` (platform NLU, asynchronous) is not a line test: `where` names the field in the error.
|
|
30
|
+
* `named`: the agent file's named matchers (`{ matcher: name }`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function compileMatcher(m: Matcher, languages: readonly LocaleCode[], where: string, named?: NamedMatchers): LineTest;
|
|
33
|
+
/**
|
|
34
|
+
* A matcher as a plain list of regular expressions, for runtime parts that take patterns (barge-in words, the
|
|
35
|
+
* voicemail fallback): a `RegExp`, or `{ any }` of them. `null` when the matcher is anything else.
|
|
36
|
+
*/
|
|
37
|
+
export declare function matcherPatterns(m: Matcher): RegExp[] | null;
|
|
38
|
+
/** A text for the call: the reply language's variant, `{name}` filled from the call's variables; `null` = nothing. */
|
|
39
|
+
export declare function resolveText(t: Text, call: CallView, line?: string): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* A matcher as patterns for runtime parts that test lines with regular expressions (barge-in words, the voicemail
|
|
42
|
+
* fallback, `minPeakVad.except`, the dial transfer's queue): its own `RegExp`s when it is only those, else one pattern
|
|
43
|
+
* that runs the compiled matcher. Media parts know no reply language: a lexicon matcher reads the agent's first
|
|
44
|
+
* language (`in: 'all'`: every language). `field` names the pattern in the media's logs.
|
|
45
|
+
*/
|
|
46
|
+
export declare function matcherAsPatterns(m: Matcher, languages: readonly LocaleCode[], field: string): RegExp[];
|
|
47
|
+
/** One pattern of a matcher (see `matcherAsPatterns`): a `RegExp` as it is. */
|
|
48
|
+
export declare function matcherAsPattern(m: Matcher, languages: readonly LocaleCode[], field: string): RegExp;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matcherAsPattern = exports.matcherAsPatterns = exports.resolveText = exports.matcherPatterns = exports.compileMatcher = exports.lexiconWords = exports.lexiconRef = exports.spacedLine = exports.lineWords = exports.stripLabels = exports.normalizeLine = exports.NotRunByEngine = void 0;
|
|
4
|
+
// Matchers and texts of the agent file, compiled for the engine: a `Matcher` becomes a synchronous test of a line,
|
|
5
|
+
// a `Text` a string for the active reply language with `{name}` placeholders filled from the call's variables.
|
|
6
|
+
const locales_1 = require("../locales");
|
|
7
|
+
const matchers_1 = require("../expr/matchers");
|
|
8
|
+
const compiled_1 = require("../expr/compiled");
|
|
9
|
+
/** Thrown for a part of the agent file the engine does not run yet; names the field. */
|
|
10
|
+
class NotRunByEngine extends Error {
|
|
11
|
+
constructor(field) {
|
|
12
|
+
super(`[templates/engine] ${field}: not run by the engine yet`);
|
|
13
|
+
this.name = 'NotRunByEngine';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.NotRunByEngine = NotRunByEngine;
|
|
17
|
+
/** Lower case, letters/digits/spaces only, single spaces. */
|
|
18
|
+
function normalizeLine(text) {
|
|
19
|
+
return text.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, '').replace(/\s+/g, ' ').trim();
|
|
20
|
+
}
|
|
21
|
+
exports.normalizeLine = normalizeLine;
|
|
22
|
+
function wholeWords(phrases) {
|
|
23
|
+
const norm = phrases.map(normalizeLine).filter((p) => p.length > 0);
|
|
24
|
+
return (text) => {
|
|
25
|
+
const t = ` ${normalizeLine(text)} `;
|
|
26
|
+
return norm.some((p) => t.includes(` ${p} `));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function isRegExp(m) {
|
|
30
|
+
return m instanceof RegExp;
|
|
31
|
+
}
|
|
32
|
+
/** Recognizer labels in front of a line (`[ru] …`) are engine names, not speech. */
|
|
33
|
+
function stripLabels(text) {
|
|
34
|
+
return text.replace(/^\s*\[[a-z-]{2,8}\]\s*/gim, '');
|
|
35
|
+
}
|
|
36
|
+
exports.stripLabels = stripLabels;
|
|
37
|
+
/** Lower-case words of a line (labels dropped), split on anything that is not a letter or a digit. */
|
|
38
|
+
function lineWords(text) {
|
|
39
|
+
return stripLabels(text).toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
exports.lineWords = lineWords;
|
|
42
|
+
/** Lower case, every non-letter/digit turned into one space (for `tail` with `words: true`). */
|
|
43
|
+
function spacedLine(text) {
|
|
44
|
+
return text.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, ' ').replace(/\s+/g, ' ').trim();
|
|
45
|
+
}
|
|
46
|
+
exports.spacedLine = spacedLine;
|
|
47
|
+
function testPatterns(list, text) {
|
|
48
|
+
return list.some((p) => {
|
|
49
|
+
p.lastIndex = 0;
|
|
50
|
+
return p.test(text);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** A lexicon of one pack as a line test: its phrases (whole words, normalized) or its patterns (the line as it is). */
|
|
54
|
+
function lexiconTest(lang, name, where) {
|
|
55
|
+
const pack = (0, locales_1.getLocale)(lang);
|
|
56
|
+
if (!pack)
|
|
57
|
+
throw new Error(`[templates/engine] ${where}: no locale pack for "${lang}"`);
|
|
58
|
+
const phrases = wholeWords(pack.lexicons[name] ?? []);
|
|
59
|
+
const patterns = pack.patterns?.[name] ?? [];
|
|
60
|
+
return (text) => phrases(text) || testPatterns(patterns, text);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A lexicon name that names its pack (`'hi:voicemail'`): that pack's list, whatever the call's languages are. `null`
|
|
64
|
+
* for a plain name (the call's languages).
|
|
65
|
+
*/
|
|
66
|
+
function lexiconRef(name) {
|
|
67
|
+
const i = name.indexOf(':');
|
|
68
|
+
return i > 0 ? { pack: name.slice(0, i), name: name.slice(i + 1) } : null;
|
|
69
|
+
}
|
|
70
|
+
exports.lexiconRef = lexiconRef;
|
|
71
|
+
/** Words of a lexicon in every given language (union), lower case; a `pack:name` reads that pack only. */
|
|
72
|
+
function lexiconWords(languages, name) {
|
|
73
|
+
const ref = lexiconRef(name);
|
|
74
|
+
const out = new Set();
|
|
75
|
+
for (const lang of ref ? [ref.pack] : languages) {
|
|
76
|
+
for (const w of (0, locales_1.getLocale)(lang)?.lexicons[ref ? ref.name : name] ?? [])
|
|
77
|
+
out.add(w.toLowerCase());
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
exports.lexiconWords = lexiconWords;
|
|
82
|
+
function shapeTest(shape, languages) {
|
|
83
|
+
if ('has' in shape) {
|
|
84
|
+
const has = lexiconWords(languages, shape.has);
|
|
85
|
+
return (text) => lineWords(text).some((w) => has.has(w));
|
|
86
|
+
}
|
|
87
|
+
const ignore = shape.ignore ? lexiconWords(languages, shape.ignore) : null;
|
|
88
|
+
const lead = shape.lead ? lexiconWords(languages, shape.lead) : new Set();
|
|
89
|
+
const core = lexiconWords(languages, shape.core);
|
|
90
|
+
const min = shape.min ?? 1;
|
|
91
|
+
const rest = shape.rest;
|
|
92
|
+
const restPhrase = typeof rest === 'string' ? lexiconWords(languages, rest) : null;
|
|
93
|
+
const restAll = rest && typeof rest === 'object' ? lexiconWords(languages, rest.all) : null;
|
|
94
|
+
const restSome = rest && typeof rest === 'object' ? lexiconWords(languages, rest.some) : null;
|
|
95
|
+
return (text) => {
|
|
96
|
+
const words = ignore ? lineWords(text).filter((w) => !ignore.has(w)) : lineWords(text);
|
|
97
|
+
let i = 0;
|
|
98
|
+
while (i < words.length && lead.has(words[i]))
|
|
99
|
+
i++;
|
|
100
|
+
let n = 0;
|
|
101
|
+
while (i < words.length && core.has(words[i])) {
|
|
102
|
+
i++;
|
|
103
|
+
n++;
|
|
104
|
+
}
|
|
105
|
+
if (n < min)
|
|
106
|
+
return false;
|
|
107
|
+
const tail = words.slice(i);
|
|
108
|
+
if (tail.length === 0)
|
|
109
|
+
return rest == null && n > 0;
|
|
110
|
+
if (restPhrase)
|
|
111
|
+
return restPhrase.has(tail.join(' '));
|
|
112
|
+
if (restAll && restSome)
|
|
113
|
+
return tail.every((w) => restAll.has(w)) && tail.some((w) => restSome.has(w));
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Compile a matcher. `intent` (platform NLU, asynchronous) is not a line test: `where` names the field in the error.
|
|
119
|
+
* `named`: the agent file's named matchers (`{ matcher: name }`).
|
|
120
|
+
*/
|
|
121
|
+
function compileMatcher(m, languages, where, named) {
|
|
122
|
+
if (typeof m === 'function')
|
|
123
|
+
return (text, call) => m(text, call);
|
|
124
|
+
if (isRegExp(m)) {
|
|
125
|
+
return (text) => {
|
|
126
|
+
m.lastIndex = 0;
|
|
127
|
+
return m.test(text);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if ('phrases' in m) {
|
|
131
|
+
const p = m.phrases;
|
|
132
|
+
if (Array.isArray(p)) {
|
|
133
|
+
const test = wholeWords(p);
|
|
134
|
+
return (text) => test(text);
|
|
135
|
+
}
|
|
136
|
+
const byLang = p;
|
|
137
|
+
const tests = new Map(Object.entries(byLang).map(([lang, list]) => [lang, wholeWords(list ?? [])]));
|
|
138
|
+
return (text, call) => tests.get(call.language)?.(text) ?? false;
|
|
139
|
+
}
|
|
140
|
+
if ('lexicon' in m) {
|
|
141
|
+
const ref = lexiconRef(m.lexicon);
|
|
142
|
+
if (ref) {
|
|
143
|
+
const test = lexiconTest(ref.pack, ref.name, where);
|
|
144
|
+
return (text) => test(text);
|
|
145
|
+
}
|
|
146
|
+
const tests = new Map(languages.map((lang) => [lang, lexiconTest(lang, m.lexicon, where)]));
|
|
147
|
+
if (m.in === 'all')
|
|
148
|
+
return (text) => [...tests.values()].some((t) => t(text));
|
|
149
|
+
return (text, call) => (tests.get(call.language) ?? tests.get(languages[0]))?.(text) ?? false;
|
|
150
|
+
}
|
|
151
|
+
if ('intent' in m)
|
|
152
|
+
throw new NotRunByEngine(`${where} (intent matcher: an asynchronous rule)`);
|
|
153
|
+
if ('tail' in m) {
|
|
154
|
+
const inner = compileMatcher(m.tail, languages, where, named);
|
|
155
|
+
if (m.words) {
|
|
156
|
+
return (text, call) => {
|
|
157
|
+
const t = spacedLine(text.trimEnd());
|
|
158
|
+
return text.trimEnd() !== '' && inner(t.slice(-m.chars), call);
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return (text, call) => {
|
|
162
|
+
const t = text.trimEnd();
|
|
163
|
+
return t !== '' && inner(t.slice(-m.chars), call);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if ('normalized' in m) {
|
|
167
|
+
const inner = compileMatcher(m.normalized, languages, where, named);
|
|
168
|
+
return (text, call) => inner(normalizeLine(text), call);
|
|
169
|
+
}
|
|
170
|
+
if ('tokens' in m) {
|
|
171
|
+
const test = shapeTest(m.tokens, languages);
|
|
172
|
+
return (text) => test(text);
|
|
173
|
+
}
|
|
174
|
+
if ('any' in m) {
|
|
175
|
+
const all = m.any.map((x) => compileMatcher(x, languages, where, named));
|
|
176
|
+
return (text, call) => all.some((f) => f(text, call));
|
|
177
|
+
}
|
|
178
|
+
if ('all' in m) {
|
|
179
|
+
const all = m.all.map((x) => compileMatcher(x, languages, where, named));
|
|
180
|
+
return (text, call) => all.every((f) => f(text, call));
|
|
181
|
+
}
|
|
182
|
+
if ('not' in m) {
|
|
183
|
+
const inner = compileMatcher(m.not, languages, where, named);
|
|
184
|
+
return (text, call) => !inner(text, call);
|
|
185
|
+
}
|
|
186
|
+
const added = (0, matchers_1.compileMatcherAddition)(m, languages, where, named, compileMatcher);
|
|
187
|
+
if (added)
|
|
188
|
+
return added;
|
|
189
|
+
throw new Error(`[templates/engine] ${where}: unknown matcher`);
|
|
190
|
+
}
|
|
191
|
+
exports.compileMatcher = compileMatcher;
|
|
192
|
+
/**
|
|
193
|
+
* A matcher as a plain list of regular expressions, for runtime parts that take patterns (barge-in words, the
|
|
194
|
+
* voicemail fallback): a `RegExp`, or `{ any }` of them. `null` when the matcher is anything else.
|
|
195
|
+
*/
|
|
196
|
+
function matcherPatterns(m) {
|
|
197
|
+
if (isRegExp(m))
|
|
198
|
+
return [m];
|
|
199
|
+
if (typeof m === 'object' && m && 'any' in m) {
|
|
200
|
+
const out = [];
|
|
201
|
+
for (const x of m.any) {
|
|
202
|
+
const p = matcherPatterns(x);
|
|
203
|
+
if (!p)
|
|
204
|
+
return null;
|
|
205
|
+
out.push(...p);
|
|
206
|
+
}
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
exports.matcherPatterns = matcherPatterns;
|
|
212
|
+
/** A text for the call: the reply language's variant, `{name}` filled from the call's variables; `null` = nothing. */
|
|
213
|
+
function resolveText(t, call, line) {
|
|
214
|
+
const v = typeof t === 'function' ? t(call, line) : (0, compiled_1.noData)(t);
|
|
215
|
+
if (v == null)
|
|
216
|
+
return null;
|
|
217
|
+
const s = typeof v === 'string' ? v : (v[call.language] ?? Object.values(v)[0] ?? '');
|
|
218
|
+
return s.replace(/(?<!\{)\{(\w+)\}(?!\})/g, (whole, key) => (key in call.vars ? String(call.vars[key] ?? '') : whole));
|
|
219
|
+
}
|
|
220
|
+
exports.resolveText = resolveText;
|
|
221
|
+
/** A compiled matcher in the shape of a `RegExp` (only `test` is read), for runtime parts that take patterns. */
|
|
222
|
+
class MatcherPattern extends RegExp {
|
|
223
|
+
constructor(line, label) {
|
|
224
|
+
super('(?:)');
|
|
225
|
+
this.line = line;
|
|
226
|
+
Object.defineProperty(this, 'source', { value: label });
|
|
227
|
+
}
|
|
228
|
+
test(text) {
|
|
229
|
+
return this.line(text);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* A matcher as patterns for runtime parts that test lines with regular expressions (barge-in words, the voicemail
|
|
234
|
+
* fallback, `minPeakVad.except`, the dial transfer's queue): its own `RegExp`s when it is only those, else one pattern
|
|
235
|
+
* that runs the compiled matcher. Media parts know no reply language: a lexicon matcher reads the agent's first
|
|
236
|
+
* language (`in: 'all'`: every language). `field` names the pattern in the media's logs.
|
|
237
|
+
*/
|
|
238
|
+
function matcherAsPatterns(m, languages, field) {
|
|
239
|
+
const plain = matcherPatterns(m);
|
|
240
|
+
if (plain)
|
|
241
|
+
return plain;
|
|
242
|
+
return [matcherAsPattern(m, languages, field)];
|
|
243
|
+
}
|
|
244
|
+
exports.matcherAsPatterns = matcherAsPatterns;
|
|
245
|
+
/** One pattern of a matcher (see `matcherAsPatterns`): a `RegExp` as it is. */
|
|
246
|
+
function matcherAsPattern(m, languages, field) {
|
|
247
|
+
if (isRegExp(m))
|
|
248
|
+
return m;
|
|
249
|
+
const test = compileMatcher(m, languages, field);
|
|
250
|
+
const view = { language: languages[0], vars: {}, flags: {}, counters: {}, lines: [], agentLines: [], callerLines: [] };
|
|
251
|
+
return new MatcherPattern((text) => test(text, view), field);
|
|
252
|
+
}
|
|
253
|
+
exports.matcherAsPattern = matcherAsPattern;
|