@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,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replyPlayed = exports.playedTracking = exports.answersCount = exports.askedCount = exports.openQuestionIs = exports.stageIs = exports.lineFlag = exports.trackOf = exports.trackOfLines = exports.stageOf = exports.platformLines = void 0;
|
|
4
|
+
const evaluate_1 = require("../../expr/evaluate");
|
|
5
|
+
const transcript_1 = require("../../expr/transcript");
|
|
6
|
+
const LINE_PREFIX = /^(USER|AGENT):\s?/;
|
|
7
|
+
/** The platform's transcript text (`USER:` / `AGENT:` lines; a line without a prefix continues the one before). */
|
|
8
|
+
function platformLines(text) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const raw of (text ?? '').split('\n')) {
|
|
11
|
+
const m = LINE_PREFIX.exec(raw);
|
|
12
|
+
if (m)
|
|
13
|
+
out.push({ who: m[1] === 'USER' ? 'caller' : 'agent', text: raw.slice(m[0].length).trim() });
|
|
14
|
+
else if (out.length > 0 && raw.trim())
|
|
15
|
+
out[out.length - 1].text = `${out[out.length - 1].text} ${raw.trim()}`;
|
|
16
|
+
}
|
|
17
|
+
return out.filter((l) => l.text.length > 0);
|
|
18
|
+
}
|
|
19
|
+
exports.platformLines = platformLines;
|
|
20
|
+
const speaks = (on, l) => on === 'anyLine' || (on === 'agentLine' ? l.who === 'agent' : l.who === 'caller');
|
|
21
|
+
function test(m, text, ctx) {
|
|
22
|
+
return m == null || (0, transcript_1.matches)(m, text, ctx);
|
|
23
|
+
}
|
|
24
|
+
function fromHolds(r, stage) {
|
|
25
|
+
if (r.from == null)
|
|
26
|
+
return true;
|
|
27
|
+
if (Array.isArray(r.from))
|
|
28
|
+
return r.from.includes(stage);
|
|
29
|
+
return !r.from.not.includes(stage);
|
|
30
|
+
}
|
|
31
|
+
/** The stage the lines reach (`null` without `stages`). */
|
|
32
|
+
function stageOf(spec, lines, ctx) {
|
|
33
|
+
const st = spec.stages;
|
|
34
|
+
if (!st || !st.list.length)
|
|
35
|
+
return null;
|
|
36
|
+
let stage = st.list[0];
|
|
37
|
+
for (const l of lines) {
|
|
38
|
+
const r = st.rules.find((x) => speaks(x.on, l) && fromHolds(x, stage) && test(x.match, l.text, ctx));
|
|
39
|
+
if (!r)
|
|
40
|
+
continue;
|
|
41
|
+
if (st.list.indexOf(r.to) > st.list.indexOf(stage))
|
|
42
|
+
stage = r.to;
|
|
43
|
+
}
|
|
44
|
+
return stage;
|
|
45
|
+
}
|
|
46
|
+
exports.stageOf = stageOf;
|
|
47
|
+
const cache = new WeakMap();
|
|
48
|
+
/** The track of a transcript (cached per lines array and spec). */
|
|
49
|
+
function trackOfLines(spec, lines, ctx) {
|
|
50
|
+
let bySpec = cache.get(lines);
|
|
51
|
+
if (!bySpec) {
|
|
52
|
+
bySpec = new WeakMap();
|
|
53
|
+
cache.set(lines, bySpec);
|
|
54
|
+
}
|
|
55
|
+
const hit = bySpec.get(spec);
|
|
56
|
+
if (hit)
|
|
57
|
+
return hit;
|
|
58
|
+
const flags = {};
|
|
59
|
+
for (const [name, f] of Object.entries(spec.flags ?? {})) {
|
|
60
|
+
if (f.on === 'heard' || f.on === 'cut')
|
|
61
|
+
continue;
|
|
62
|
+
flags[name] = lines.some((l) => speaks(f.on, l) && (0, transcript_1.matches)(f.match, f.normalize === 'NFC' ? l.text.normalize('NFC') : l.text, ctx));
|
|
63
|
+
}
|
|
64
|
+
const q = spec.questions;
|
|
65
|
+
let open = null;
|
|
66
|
+
const asked = {};
|
|
67
|
+
const answers = [];
|
|
68
|
+
if (q) {
|
|
69
|
+
for (const l of lines) {
|
|
70
|
+
if (l.who === 'caller') {
|
|
71
|
+
answers.push({ text: l.text, open });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const hitQ = q.list.find((x) => (0, transcript_1.matches)(x.asked, l.text, ctx));
|
|
75
|
+
if (hitQ) {
|
|
76
|
+
open = hitQ.id;
|
|
77
|
+
asked[hitQ.id] = (asked[hitQ.id] ?? 0) + 1;
|
|
78
|
+
}
|
|
79
|
+
else if (q.keepOn == null || !(0, transcript_1.matches)(q.keepOn, l.text, ctx)) {
|
|
80
|
+
open = q.else ?? null;
|
|
81
|
+
if (q.else != null)
|
|
82
|
+
asked[q.else] = (asked[q.else] ?? 0) + 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const track = { flags, stage: stageOf(spec, lines, ctx), openQuestion: open, asked, answers };
|
|
87
|
+
bySpec.set(spec, track);
|
|
88
|
+
return track;
|
|
89
|
+
}
|
|
90
|
+
exports.trackOfLines = trackOfLines;
|
|
91
|
+
/** The track of the call an expression reads (`stages.source` decides the stage's lines). */
|
|
92
|
+
function trackOf(ctx) {
|
|
93
|
+
const spec = ctx.blocks?.tracking;
|
|
94
|
+
if (!spec)
|
|
95
|
+
return null;
|
|
96
|
+
const lines = (ctx.call?.lines ?? []);
|
|
97
|
+
const t = trackOfLines(spec, lines, ctx);
|
|
98
|
+
if (spec.stages?.source !== 'platformTranscript')
|
|
99
|
+
return t;
|
|
100
|
+
const text = ctx.call?.rowFacts?.service['call_transcript'];
|
|
101
|
+
if (typeof text !== 'string')
|
|
102
|
+
return t;
|
|
103
|
+
return { ...t, stage: stageOf(spec, platformLines(text), ctx) };
|
|
104
|
+
}
|
|
105
|
+
exports.trackOf = trackOf;
|
|
106
|
+
/** A line flag's value (`undefined`: not a line flag of `tracking`). */
|
|
107
|
+
function lineFlag(ctx, name) {
|
|
108
|
+
const f = ctx.blocks?.tracking?.flags?.[name];
|
|
109
|
+
if (!f || f.on === 'heard' || f.on === 'cut')
|
|
110
|
+
return undefined;
|
|
111
|
+
return trackOf(ctx)?.flags[name] ?? false;
|
|
112
|
+
}
|
|
113
|
+
exports.lineFlag = lineFlag;
|
|
114
|
+
const ids = (v) => (Array.isArray(v) ? v : [v]);
|
|
115
|
+
/** `{ stage: name | names }`. */
|
|
116
|
+
function stageIs(ctx, want) {
|
|
117
|
+
const s = trackOf(ctx)?.stage ?? null;
|
|
118
|
+
return s != null && ids(want).includes(s);
|
|
119
|
+
}
|
|
120
|
+
exports.stageIs = stageIs;
|
|
121
|
+
/** `{ openQuestion: id | ids | null }`. */
|
|
122
|
+
function openQuestionIs(ctx, want) {
|
|
123
|
+
const q = trackOf(ctx)?.openQuestion ?? null;
|
|
124
|
+
return want === null ? q === null : ids(want).includes(q);
|
|
125
|
+
}
|
|
126
|
+
exports.openQuestionIs = openQuestionIs;
|
|
127
|
+
/** `{ asked: id | ids }`: agent lines that asked it. */
|
|
128
|
+
function askedCount(ctx, want) {
|
|
129
|
+
const t = trackOf(ctx);
|
|
130
|
+
return t ? ids(want).reduce((n, id) => n + (t.asked[String(id)] ?? 0), 0) : 0;
|
|
131
|
+
}
|
|
132
|
+
exports.askedCount = askedCount;
|
|
133
|
+
/** `{ answers: { question, match } }`: caller lines said while the question was open, matching. */
|
|
134
|
+
function answersCount(ctx, want) {
|
|
135
|
+
const t = trackOf(ctx);
|
|
136
|
+
if (!t)
|
|
137
|
+
return 0;
|
|
138
|
+
const qs = ids(want.question);
|
|
139
|
+
return t.answers.filter((a) => qs.includes(a.open) && test(want.match, a.text, ctx)).length;
|
|
140
|
+
}
|
|
141
|
+
exports.answersCount = answersCount;
|
|
142
|
+
function playedTracking(spec) {
|
|
143
|
+
const flags = Object.entries(spec?.flags ?? {}).filter(([, f]) => f.on === 'heard' || f.on === 'cut');
|
|
144
|
+
return spec && flags.length ? { spec, flags } : null;
|
|
145
|
+
}
|
|
146
|
+
exports.playedTracking = playedTracking;
|
|
147
|
+
/** A reply the caller heard to its end (`heard`) or not: the heard / cut flags it sets, and their log. */
|
|
148
|
+
function replyPlayed(cx, p, text, heard, ctxOf) {
|
|
149
|
+
const before = cx.d.flags;
|
|
150
|
+
const view = cx.core.view(cx.d);
|
|
151
|
+
const ctx = ctxOf(view);
|
|
152
|
+
const next = { ...before };
|
|
153
|
+
const kind = heard ? 'heard' : 'cut';
|
|
154
|
+
const mine = p.flags.filter(([, f]) => f.on === kind);
|
|
155
|
+
for (const [name, f] of mine) {
|
|
156
|
+
if (next[name])
|
|
157
|
+
continue;
|
|
158
|
+
if (f.on === 'heard' && (f.match == null || (0, transcript_1.matches)(f.match, text, ctx)))
|
|
159
|
+
next[name] = true;
|
|
160
|
+
if (f.on === 'cut' && (f.when == null || (0, evaluate_1.evalCondition)(f.when, ctx)))
|
|
161
|
+
next[name] = true;
|
|
162
|
+
}
|
|
163
|
+
// Implied flags, until nothing changes (a flag implied by one implied in turn).
|
|
164
|
+
for (let changed = true; changed;) {
|
|
165
|
+
changed = false;
|
|
166
|
+
for (const [name, f] of mine) {
|
|
167
|
+
if (next[name] || f.on !== 'heard' || !f.impliedBy?.some((x) => next[x]))
|
|
168
|
+
continue;
|
|
169
|
+
next[name] = true;
|
|
170
|
+
changed = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!mine.some(([name]) => (next[name] ?? false) !== (before[name] ?? false)))
|
|
174
|
+
return;
|
|
175
|
+
cx.d.flags = next;
|
|
176
|
+
if (p.spec.log) {
|
|
177
|
+
const data = {};
|
|
178
|
+
for (const [name, f] of mine)
|
|
179
|
+
if ('log' in f && f.log)
|
|
180
|
+
data[f.log] = next[name] === true;
|
|
181
|
+
cx.log(p.spec.log, data);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.replyPlayed = replyPlayed;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Turn } from './context';
|
|
2
|
+
/** The transfer starts: the conversation is over; its phrase (when the reply said none), headers, whisper. */
|
|
3
|
+
export declare function transferStart(cx: Turn, via: 'tool' | 'spoken' | 'rule', spokeWords: boolean, line?: string, blank?: boolean): void;
|
|
4
|
+
export declare function transferBridged(cx: Turn): void;
|
|
5
|
+
/**
|
|
6
|
+
* The transfer did not connect (`failure`: its outcome). The call is not transferred: its result is
|
|
7
|
+
* `results.customerDropped` (the customer left) or `results.notAnswered`, each by default the result the call had
|
|
8
|
+
* before the transfer; with the customer on the line the agent's `onFailure` runs.
|
|
9
|
+
*/
|
|
10
|
+
export declare function transferFailed(cx: Turn, failure: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* The call ended with the transfer still running: the customer left before it connected. The call is not
|
|
13
|
+
* transferred; its result is `transferDroppedResult`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function transferAtCallEnd<S extends {
|
|
16
|
+
readonly transfer: 'started' | 'bridged' | 'failed' | null;
|
|
17
|
+
readonly result: string;
|
|
18
|
+
readonly transferDroppedResult?: string;
|
|
19
|
+
}>(st: S): S;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferAtCallEnd = exports.transferFailed = exports.transferBridged = exports.transferStart = void 0;
|
|
4
|
+
/** The transfer starts: the conversation is over; its phrase (when the reply said none), headers, whisper. */
|
|
5
|
+
function transferStart(cx, via, spokeWords, line, blank = !spokeWords) {
|
|
6
|
+
const t = cx.cfg.transfer;
|
|
7
|
+
const d = cx.d;
|
|
8
|
+
if (!t || d.transfer != null)
|
|
9
|
+
return;
|
|
10
|
+
d.transfer = 'started';
|
|
11
|
+
d.phase = 'closing';
|
|
12
|
+
d.resultBeforeTransfer = d.result;
|
|
13
|
+
d.transferDroppedResult = t.results.customerDropped ?? d.result;
|
|
14
|
+
d.result = t.results.started;
|
|
15
|
+
d.pending = null;
|
|
16
|
+
cx.clearReplay();
|
|
17
|
+
d.buffered = null;
|
|
18
|
+
d.bufferedBackchannel = false;
|
|
19
|
+
let say = null;
|
|
20
|
+
// Whether the reply already said the transfer line: words (`replyEmpty`), or any character (`replyBlank`).
|
|
21
|
+
const said = t.text?.when === 'replyBlank' ? !blank : spokeWords;
|
|
22
|
+
if (t.text && (t.text.when === 'always' || !said)) {
|
|
23
|
+
say = cx.core.text(t.text.say, d, line) || null;
|
|
24
|
+
}
|
|
25
|
+
const view = cx.core.view(d);
|
|
26
|
+
const headers = t.headers ? t.headers(view) : {};
|
|
27
|
+
const whisper = t.whisper != null ? cx.core.text(t.whisper, d) : null;
|
|
28
|
+
cx.log('transfer_started', { via, mode: t.mode, spokeWords, result: d.result, say });
|
|
29
|
+
const did = t.target.did;
|
|
30
|
+
const target = typeof did === 'function' ? { ...t.target, did: did(view) } : t.target;
|
|
31
|
+
const c = t.text?.clip;
|
|
32
|
+
const clip = say == null && c && (t.text.when === 'always' || !said)
|
|
33
|
+
? { ...(c.url != null ? { url: c.url } : {}), ...(c.record != null ? { record: c.record } : {}), text: cx.core.text(c.text, d) ?? '', playMs: c.playMs }
|
|
34
|
+
: null;
|
|
35
|
+
cx.fx.push({ type: 'transfer', mode: t.mode, say, alias: t.text?.alias ?? 'transfer', whisper, headers, target, ...(clip ? { clip } : {}) });
|
|
36
|
+
}
|
|
37
|
+
exports.transferStart = transferStart;
|
|
38
|
+
function transferBridged(cx) {
|
|
39
|
+
const t = cx.cfg.transfer;
|
|
40
|
+
if (!t || cx.d.transfer !== 'started')
|
|
41
|
+
return;
|
|
42
|
+
cx.d.transfer = 'bridged';
|
|
43
|
+
cx.d.result = t.results.connected;
|
|
44
|
+
}
|
|
45
|
+
exports.transferBridged = transferBridged;
|
|
46
|
+
/**
|
|
47
|
+
* The transfer did not connect (`failure`: its outcome). The call is not transferred: its result is
|
|
48
|
+
* `results.customerDropped` (the customer left) or `results.notAnswered`, each by default the result the call had
|
|
49
|
+
* before the transfer; with the customer on the line the agent's `onFailure` runs.
|
|
50
|
+
*/
|
|
51
|
+
function transferFailed(cx, failure) {
|
|
52
|
+
const t = cx.cfg.transfer;
|
|
53
|
+
const d = cx.d;
|
|
54
|
+
if (!t || d.transfer !== 'started')
|
|
55
|
+
return;
|
|
56
|
+
d.transfer = 'failed';
|
|
57
|
+
const before = d.resultBeforeTransfer ?? d.result;
|
|
58
|
+
if (failure === 'customer_gone') {
|
|
59
|
+
d.result = t.results.customerDropped ?? before;
|
|
60
|
+
cx.log('transfer_failed', { failure, result: d.result });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
d.result = t.results.notAnswered ?? before;
|
|
64
|
+
const f = t.onFailure;
|
|
65
|
+
cx.log('transfer_failed', { failure, result: d.result, then: f.then });
|
|
66
|
+
if (f.then === 'log')
|
|
67
|
+
return;
|
|
68
|
+
const line = f.say != null ? cx.core.text(f.say, d) : null;
|
|
69
|
+
if (f.then === 'continue') {
|
|
70
|
+
d.phase = 'conversation';
|
|
71
|
+
d.transfer = null;
|
|
72
|
+
if (line)
|
|
73
|
+
cx.staticTurn(line, f.alias);
|
|
74
|
+
else
|
|
75
|
+
cx.timing('playbackEnd');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (line)
|
|
79
|
+
cx.staticTurn(line, f.alias, { hangupReason: `transfer_${failure}` });
|
|
80
|
+
else
|
|
81
|
+
cx.fx.push({ type: 'hangupNow', reason: `transfer_${failure}` });
|
|
82
|
+
}
|
|
83
|
+
exports.transferFailed = transferFailed;
|
|
84
|
+
/**
|
|
85
|
+
* The call ended with the transfer still running: the customer left before it connected. The call is not
|
|
86
|
+
* transferred; its result is `transferDroppedResult`.
|
|
87
|
+
*/
|
|
88
|
+
function transferAtCallEnd(st) {
|
|
89
|
+
if (st.transfer !== 'started')
|
|
90
|
+
return st;
|
|
91
|
+
return { ...st, transfer: 'failed', result: st.transferDroppedResult ?? st.result };
|
|
92
|
+
}
|
|
93
|
+
exports.transferAtCallEnd = transferAtCallEnd;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Action } from '../../spec';
|
|
2
|
+
import type { Turn } from './context';
|
|
3
|
+
/** The vendor's wording of an early final: it replaces that line's text while it is the caller's last line. */
|
|
4
|
+
export declare function reworded(cx: Turn, text: string, virtual: string): void;
|
|
5
|
+
export declare function drained(cx: Turn): void;
|
|
6
|
+
export declare function final(cx: Turn, text: string): void;
|
|
7
|
+
export declare function callerLine(cx: Turn, input: string, asyncHits?: ReadonlySet<string>, hookActions?: ReadonlyMap<string, readonly Action[]>, heldKey?: string, heardAt?: number): void;
|
|
8
|
+
/** The LLM answered nothing `turn.emptyReply.max` times in a row: `onExhausted`. */
|
|
9
|
+
export declare function emptyExhausted(cx: Turn, errored: boolean, probe?: number): void;
|
|
10
|
+
/** `turn.review` dropped the reply: its actions run instead (the reply never was a line). */
|
|
11
|
+
export declare function reviewActions(cx: Turn, actions: readonly Action[]): void;
|
|
12
|
+
/** The reply guard held back the reply: its replacement is said instead (a goodbye closes the call). */
|
|
13
|
+
export declare function guardReplaced(cx: Turn, text: string, alias?: string, close?: {
|
|
14
|
+
result: string;
|
|
15
|
+
reason?: string;
|
|
16
|
+
}): void;
|
|
17
|
+
export declare function spoken(cx: Turn, text: string, unit?: string | null): void;
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spoken = exports.guardReplaced = exports.reviewActions = exports.emptyExhausted = exports.callerLine = exports.final = exports.drained = exports.reworded = void 0;
|
|
4
|
+
// The turn loop: a caller final (over the agent or not), the caller line through rules and gates to the LLM turn, an
|
|
5
|
+
// agent line spoken and played out, the reply filters' verdicts the media sends back (empty replies, review, guard).
|
|
6
|
+
const core_1 = require("../../../call/extraction/core");
|
|
7
|
+
const match_1 = require("../match");
|
|
8
|
+
const carry_1 = require("./carry");
|
|
9
|
+
const closing_1 = require("./closing");
|
|
10
|
+
const language_1 = require("./language");
|
|
11
|
+
const opening_1 = require("./opening");
|
|
12
|
+
const overtalk_1 = require("./overtalk");
|
|
13
|
+
const rules_1 = require("./rules");
|
|
14
|
+
const silence_1 = require("./silence");
|
|
15
|
+
const voicemail_1 = require("./voicemail");
|
|
16
|
+
const state_1 = require("./state");
|
|
17
|
+
/** The vendor's wording of an early final: it replaces that line's text while it is the caller's last line. */
|
|
18
|
+
function reworded(cx, text, virtual) {
|
|
19
|
+
if (!cx.cfg.voice.vendorFinalInTranscript)
|
|
20
|
+
return;
|
|
21
|
+
const lines = cx.d.lines;
|
|
22
|
+
let i = lines.length - 1;
|
|
23
|
+
while (i >= 0 && lines[i].who !== 'caller')
|
|
24
|
+
i--;
|
|
25
|
+
const t = text.trim();
|
|
26
|
+
if (i < 0 || !t || lines[i].text !== virtual.trim())
|
|
27
|
+
return;
|
|
28
|
+
cx.log('transcript_vendor_final', { from: lines[i].text, to: t });
|
|
29
|
+
cx.d.lines = lines.map((l, k) => (k === i ? { ...l, text: t } : l));
|
|
30
|
+
}
|
|
31
|
+
exports.reworded = reworded;
|
|
32
|
+
function drained(cx) {
|
|
33
|
+
const d = cx.d;
|
|
34
|
+
d.carry = null;
|
|
35
|
+
d.carrySegment = false;
|
|
36
|
+
d.answerOver = false;
|
|
37
|
+
const silenceTurn = d.silence.pendingRung != null;
|
|
38
|
+
d.silence = { ...d.silence, pendingRung: null };
|
|
39
|
+
d.gateUnheard = [];
|
|
40
|
+
d.replying = false;
|
|
41
|
+
if (cx.v.maxLines && d.phase !== 'closing') {
|
|
42
|
+
d.linesDrained = (d.linesDrained ?? 0) + 1;
|
|
43
|
+
if (d.linesDrained >= cx.v.maxLines.count) {
|
|
44
|
+
// The call has had its number of agent lines.
|
|
45
|
+
cx.log('max_lines_reached', { lines: d.linesDrained, limit: cx.v.maxLines.count });
|
|
46
|
+
d.playing = null;
|
|
47
|
+
const done = cx.run(cx.d, cx.v.maxLines.do, { id: 'max_lines' });
|
|
48
|
+
cx.set(done.state);
|
|
49
|
+
cx.fx.push(...done.effects);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (d.phase === 'opening' && d.playing != null) {
|
|
54
|
+
(0, opening_1.openingDrained)(cx);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (d.buffered != null) {
|
|
58
|
+
(0, overtalk_1.bufferDrained)(cx, silenceTurn);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
cx.timing('playbackEnd');
|
|
62
|
+
}
|
|
63
|
+
exports.drained = drained;
|
|
64
|
+
function final(cx, text) {
|
|
65
|
+
const d = cx.d;
|
|
66
|
+
const m = cx.m;
|
|
67
|
+
// A new utterance: rules on partials may act again.
|
|
68
|
+
if (d.partialActed)
|
|
69
|
+
d.partialActed = false;
|
|
70
|
+
if ((0, voicemail_1.voicemail)(cx, text, 'result'))
|
|
71
|
+
return;
|
|
72
|
+
if ((0, voicemail_1.looped)(cx, text)) {
|
|
73
|
+
(0, voicemail_1.voicemailThen)(cx, text);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (cx.v.ignoreLine?.(text, cx.core.view(d))) {
|
|
77
|
+
cx.log('asr result ignored — not the caller', { userText: text });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (cx.cfg.reopen && d.goodbyeLine != null && d.phase === 'closing' && !m.closingPhraseActive) {
|
|
81
|
+
const why = (0, closing_1.reopen)(cx, text);
|
|
82
|
+
if (why != null)
|
|
83
|
+
cx.log('asr result ignored — call ending', { userText: text, reopen: why });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (m.closingPhraseActive || d.phase === 'closing') {
|
|
87
|
+
cx.log('asr result ignored — closing', { userText: text });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (m.callEnding)
|
|
91
|
+
return;
|
|
92
|
+
const pendingMs = cx.v.overtalk.pendingMs;
|
|
93
|
+
if (pendingMs > 0 && d.phase === 'conversation' && !m.agentSpeaking && (m.turnStartedAt ?? 0) > 0 && m.now - m.turnStartedAt < pendingMs) {
|
|
94
|
+
// The turn has started and nothing of it plays yet: speech now is over the agent.
|
|
95
|
+
(0, overtalk_1.buffer)(cx, text);
|
|
96
|
+
cx.log('overtalk_buffered_before_playback', { userText: text, speechPendingMs: m.now - m.turnStartedAt, pendingWindowMs: pendingMs });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const hl = cx.cfg.holdLiveness;
|
|
100
|
+
if (hl && d.phase === 'conversation' && m.llmWaitingSince && m.now - m.llmWaitingSince <= hl.maxMs && hl.test(text, cx.core.view(d))) {
|
|
101
|
+
// «Hello?» while the LLM has not answered yet: not a turn, the reply in flight goes on.
|
|
102
|
+
cx.log('liveness_prompt_held_during_llm_wait', { userText: text, llmWaitMs: m.now - m.llmWaitingSince, holdMaxMs: hl.maxMs });
|
|
103
|
+
cx.addLine('caller', text);
|
|
104
|
+
cx.timing('realResult');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (d.phase === 'opening' && d.playing != null) {
|
|
108
|
+
d.overPrevious = text;
|
|
109
|
+
d.overPreviousAt = m.now;
|
|
110
|
+
cx.log('opening_speech_buffered', { userText: text });
|
|
111
|
+
// Written as heard; a later listen step that takes it as its answer does not write it again.
|
|
112
|
+
if (cx.cfg.voice.transcriptHeard && !cx.steps.slice(d.step + 1).some((s) => s.kind === 'listen'))
|
|
113
|
+
cx.addLine('caller', text);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const carried = d.carrySegment && (0, carry_1.carriesNewWords)(cx, text) && (0, carry_1.takeBack)(cx, 'result', text);
|
|
117
|
+
if (m.agentSpeaking && !m.agentTurnInterrupted && !carried && !(0, overtalk_1.overSilenceTurn)(cx, text)) {
|
|
118
|
+
if ((0, overtalk_1.continuesTrigger)(cx, text))
|
|
119
|
+
return;
|
|
120
|
+
const elapsedMs = m.now - m.playbackStartedAt;
|
|
121
|
+
const o = cx.v.overtalk;
|
|
122
|
+
if (elapsedMs < o.guardMs) {
|
|
123
|
+
const norm = (0, match_1.normalizeLine)(text);
|
|
124
|
+
const trigger = (0, match_1.normalizeLine)((0, overtalk_1.triggerText)(cx) ?? '');
|
|
125
|
+
if (norm.length === 0 || (o.dropEcho && trigger.length > 0 && trigger.includes(norm)) || o.guardDrop?.(text, cx.core.view(d))) {
|
|
126
|
+
cx.log('overtalk_dropped_within_guard', { userText: text, elapsedMs });
|
|
127
|
+
if (cx.cfg.voice.transcriptHeard && norm.length > 0)
|
|
128
|
+
cx.addLine('caller', text);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (d.answerOver) {
|
|
133
|
+
// Speech over a re-prompt answers it now.
|
|
134
|
+
cx.log('overtalk_reprompt_answered', { userText: text, elapsedMs });
|
|
135
|
+
d.answerOver = false;
|
|
136
|
+
callerLine(cx, text);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!(0, overtalk_1.buffer)(cx, text, elapsedMs))
|
|
140
|
+
return;
|
|
141
|
+
if (o.predating?.by === 'speechBeforeReply') {
|
|
142
|
+
// Speech begun before the reply played: the rest of the caller's last line (`buffer.predating`).
|
|
143
|
+
const continuation = (m.userSpeechStartedAt ?? 0) > 0 && m.userSpeechStartedAt <= m.playbackStartedAt;
|
|
144
|
+
d.bufferedContinuation = continuation;
|
|
145
|
+
cx.log('overtalk_buffered', { userText: text, elapsedMs, continuation, buffered: d.buffered });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
cx.log('overtalk_buffered', { userText: text, elapsedMs, buffered: d.buffered });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
callerLine(cx, text);
|
|
152
|
+
}
|
|
153
|
+
exports.final = final;
|
|
154
|
+
function callerLine(cx, input, asyncHits, hookActions, heldKey, heardAt) {
|
|
155
|
+
const d = cx.d;
|
|
156
|
+
let text = input;
|
|
157
|
+
if (!asyncHits && d.phase === 'opening') {
|
|
158
|
+
cx.clearReplay();
|
|
159
|
+
(0, opening_1.openingLine)(cx, text);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!asyncHits) {
|
|
163
|
+
cx.clearReplay();
|
|
164
|
+
// The reply before this line was cut: agent code may mark the line's request (read before the line is in).
|
|
165
|
+
const m = cx.m;
|
|
166
|
+
d.cutMark = m?.agentTurnInterrupted && m.cutHeardMs != null && cx.v.cutMark ? cx.v.cutMark(cx.core.view(d), m.cutHeardMs) : null;
|
|
167
|
+
if (d.cutMark != null)
|
|
168
|
+
cx.log('interrupted_reply_mark', { heardMs: m.cutHeardMs, mark: d.cutMark });
|
|
169
|
+
const buffered = d.buffered;
|
|
170
|
+
const continues = d.bufferContinues;
|
|
171
|
+
const backchannel = d.bufferedBackchannel;
|
|
172
|
+
cx.carriedLine = d.carriedFrom;
|
|
173
|
+
d.carriedFrom = null;
|
|
174
|
+
d.buffered = null;
|
|
175
|
+
d.bufferContinues = false;
|
|
176
|
+
d.bufferedBackchannel = false;
|
|
177
|
+
if (buffered != null && backchannel) {
|
|
178
|
+
// The caller answered after all: the held backchannel was them listening, not the start of this line.
|
|
179
|
+
cx.log('overtalk_backchannel_dropped', { bufferedText: buffered, userText: text });
|
|
180
|
+
}
|
|
181
|
+
else if (buffered != null && buffered.length > 0) {
|
|
182
|
+
cx.log('overtalk_buffered_merged', { bufferedText: buffered, userText: text });
|
|
183
|
+
text = `${buffered} ${text}`;
|
|
184
|
+
}
|
|
185
|
+
// The tail of a line the recognizer split: the two go as one, the transcript keeps one line when it can.
|
|
186
|
+
const trigger = d.trigger;
|
|
187
|
+
let recorded = false;
|
|
188
|
+
if (continues && trigger.length > 0 && !(0, match_1.normalizeLine)(text).includes((0, match_1.normalizeLine)(trigger))) {
|
|
189
|
+
const joined = `${trigger} ${text}`;
|
|
190
|
+
cx.log('asr_continuation_merged', { trigger, tail: text, joined });
|
|
191
|
+
const last = d.lines[d.lines.length - 1];
|
|
192
|
+
if (last?.who === 'caller') {
|
|
193
|
+
d.lines = [...d.lines.slice(0, -1), { who: 'caller', text: joined.trim() }];
|
|
194
|
+
recorded = true;
|
|
195
|
+
}
|
|
196
|
+
if (!recorded) {
|
|
197
|
+
cx.addLine('caller', text);
|
|
198
|
+
recorded = true;
|
|
199
|
+
}
|
|
200
|
+
text = joined;
|
|
201
|
+
}
|
|
202
|
+
d.trigger = text;
|
|
203
|
+
d.triggerAt = heardAt ?? cx.now();
|
|
204
|
+
if (!recorded)
|
|
205
|
+
cx.addLine('caller', text);
|
|
206
|
+
d.callerTurns += 1;
|
|
207
|
+
d.callerFinals += 1;
|
|
208
|
+
d.heldTurns = 0;
|
|
209
|
+
if (d.result === core_1.BaseResult.GREETING_DROP)
|
|
210
|
+
d.result = core_1.BaseResult.DEFAULT;
|
|
211
|
+
cx.timing('realResult');
|
|
212
|
+
(0, language_1.resolveProvisional)(cx, text);
|
|
213
|
+
(0, language_1.explicitRequest)(cx, text);
|
|
214
|
+
(0, language_1.fallback)(cx, text);
|
|
215
|
+
// A hook rule: the turn waits for the hook (it may answer at once). A line said while an earlier one waits
|
|
216
|
+
// joins it: the two go as one turn. With NLU rules too, the NLU answers first (the hook runs after it).
|
|
217
|
+
const hookRule = (0, rules_1.nluRules)(cx).length ? undefined : (0, rules_1.hookRuleFor)(cx, text);
|
|
218
|
+
if (hookRule) {
|
|
219
|
+
const joined = d.pending?.hook ? `${d.pending.line} ${text}` : text;
|
|
220
|
+
const key = `hook-${d.callerTurns}`;
|
|
221
|
+
const wait = hookRule.whileWaiting;
|
|
222
|
+
d.pending = { key, line: joined, filler: wait ? cx.core.text(wait.say, d, text) : null, hook: true, rule: hookRule.id, ...(wait ? { fillerAfterMs: wait.afterMs } : {}) };
|
|
223
|
+
cx.fx.push({ type: 'runHook', key, name: hookRule.hook, line: text });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
// Asynchronous rules: the turn waits for the NLU. A line said while an earlier one is checked joins it.
|
|
227
|
+
const pending = (0, rules_1.nluRules)(cx);
|
|
228
|
+
if (pending.length) {
|
|
229
|
+
const joined = d.pending && !d.pending.hook ? `${d.pending.line} ${text}` : text;
|
|
230
|
+
const key = `nlu-${d.callerTurns}`;
|
|
231
|
+
const wait = pending.find((r) => r.whileWaiting)?.whileWaiting;
|
|
232
|
+
const nlu = pending.find((r) => r.nlu)?.nlu;
|
|
233
|
+
d.pending = { key, line: joined, filler: wait ? cx.core.text(wait.say, d, text) : null };
|
|
234
|
+
cx.fx.push({
|
|
235
|
+
type: 'classify', key, text: joined, intents: [...new Set(pending.flatMap((r) => r.intents ?? []))],
|
|
236
|
+
...(wait ? { fillerAfterMs: wait.afterMs } : {}),
|
|
237
|
+
...(nlu ? { nlu: { ...(nlu.language != null ? { language: nlu.language } : {}), ...(nlu.timeoutMs != null ? { timeoutMs: nlu.timeoutMs } : {}), ...(nlu.normalized ? { normalized: true } : {}) } } : {}),
|
|
238
|
+
});
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (!hookActions && (0, rules_1.nluRules)(cx).length && ![...asyncHits].some((id) => cx.cfg.rules.find((r) => r.id === id)?.intents)) {
|
|
243
|
+
// The NLU found nothing of its rules: a hook rule reads the line now.
|
|
244
|
+
const hookRule = (0, rules_1.hookRuleFor)(cx, text);
|
|
245
|
+
if (hookRule) {
|
|
246
|
+
const key = `hook-${d.callerTurns}`;
|
|
247
|
+
const wait = hookRule.whileWaiting;
|
|
248
|
+
d.pending = { key, line: text, filler: wait ? cx.core.text(wait.say, d, text) : null, hook: true, rule: hookRule.id, ...(wait ? { fillerAfterMs: wait.afterMs } : {}) };
|
|
249
|
+
cx.fx.push({ type: 'runHook', key, name: hookRule.hook, line: text });
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const r = cx.core.rules(d, 'callerLine', text, 'turn', cx.run, asyncHits ?? new Set(), hookActions);
|
|
254
|
+
cx.set(r.state);
|
|
255
|
+
cx.fx.push(...r.effects);
|
|
256
|
+
const note = cx.d.callerNote;
|
|
257
|
+
cx.d.callerNote = null;
|
|
258
|
+
const unheld = () => { if (heldKey != null)
|
|
259
|
+
cx.fx.push({ type: 'heldText', key: heldKey, text: '' }); };
|
|
260
|
+
if (r.answered || cx.d.phase === 'closing')
|
|
261
|
+
return unheld();
|
|
262
|
+
const gated0 = (0, rules_1.gates)(cx, text);
|
|
263
|
+
if (gated0 == null)
|
|
264
|
+
return unheld();
|
|
265
|
+
// The caller paused mid-sentence: the reply to their first part (nothing of it plays yet) is asked again with both.
|
|
266
|
+
const prev = cx.cfg.voice.supersedeJoin && cx.d.replying && cx.m != null && !cx.m.agentSpeaking ? cx.d.replyFor ?? null : null;
|
|
267
|
+
const gated = prev ? `${prev} ${gated0}` : gated0;
|
|
268
|
+
if (prev) {
|
|
269
|
+
// One turn: the line it joins was counted already.
|
|
270
|
+
cx.d.callerTurns = Math.max(0, cx.d.callerTurns - 1);
|
|
271
|
+
cx.log('turn_restarted_on_speech', { text: gated });
|
|
272
|
+
}
|
|
273
|
+
(0, language_1.syncAsr)(cx);
|
|
274
|
+
const annotated0 = cx.v.annotateCaller != null ? (cx.core.text(cx.v.annotateCaller, cx.d, gated) ?? gated) : (0, state_1.noteLine)(cx, gated);
|
|
275
|
+
// A marker for this line (a held backchannel, a reopened goodbye): with the words, not in the transcript.
|
|
276
|
+
const annotated = note == null ? annotated0 : note.at === 'after' ? `${annotated0} ${note.text}` : `${note.text} ${annotated0}`;
|
|
277
|
+
const noted = cx.takeNotes(annotated);
|
|
278
|
+
const cutMark = cx.d.cutMark;
|
|
279
|
+
cx.d.cutMark = null;
|
|
280
|
+
const unmarked = (0, silence_1.voidRung)(cx, (0, language_1.nextTurnText)(cx, noted));
|
|
281
|
+
const turnText = cutMark != null ? `${cutMark} ${unmarked}` : unmarked;
|
|
282
|
+
if (heldKey != null) {
|
|
283
|
+
cx.d.replying = true;
|
|
284
|
+
cx.d.lastRequest = turnText;
|
|
285
|
+
cx.fx.push({ type: 'heldText', key: heldKey, text: turnText });
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
const carried = cx.carriedLine;
|
|
289
|
+
cx.carriedLine = null;
|
|
290
|
+
const carryOn = cx.v.carryOn;
|
|
291
|
+
const sent = carryOn && carried != null ? `${carryOn.mark.replace(/\{line\}/g, carried)}\n${turnText}` : turnText;
|
|
292
|
+
cx.llmTurn(sent, cx.v.systemNotes != null || cx.cfg.voice.continuation != null || note != null || cx.v.overtalk.startedBeforeReply != null || cx.v.annotatePerRequest || cutMark != null ? { trigger: text, ...(noted !== annotated ? { retry: annotated } : {}) } : undefined);
|
|
293
|
+
if (cx.cfg.voice.supersedeJoin)
|
|
294
|
+
cx.d.replyFor = gated;
|
|
295
|
+
// Until its reply is on the line, the caller may take this turn back (`turn.carryOn`).
|
|
296
|
+
if (carryOn)
|
|
297
|
+
(0, carry_1.openCarry)(cx, carried == null ? text : `${carried} ${text}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.callerLine = callerLine;
|
|
301
|
+
/** The LLM answered nothing `turn.emptyReply.max` times in a row: `onExhausted`. */
|
|
302
|
+
function emptyExhausted(cx, errored, probe) {
|
|
303
|
+
const x = cx.cfg.emptyExhausted;
|
|
304
|
+
if (!x || cx.d.phase === 'closing')
|
|
305
|
+
return;
|
|
306
|
+
const p = probe != null ? x.probes[probe - 1] : undefined;
|
|
307
|
+
if (p) {
|
|
308
|
+
const done = cx.run(cx.d, [{ say: p.text, alias: p.alias }], { id: p.alias });
|
|
309
|
+
cx.set(done.state);
|
|
310
|
+
cx.fx.push(...done.effects);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const done = cx.run(cx.d, x.actions, { id: 'llm_unavailable' });
|
|
314
|
+
cx.set(done.state);
|
|
315
|
+
cx.fx.push(...done.effects);
|
|
316
|
+
if (errored && x.erroredResult != null)
|
|
317
|
+
cx.d.result = x.erroredResult;
|
|
318
|
+
}
|
|
319
|
+
exports.emptyExhausted = emptyExhausted;
|
|
320
|
+
/** `turn.review` dropped the reply: its actions run instead (the reply never was a line). */
|
|
321
|
+
function reviewActions(cx, actions) {
|
|
322
|
+
if (cx.d.phase === 'closing')
|
|
323
|
+
return;
|
|
324
|
+
cx.d.replying = false;
|
|
325
|
+
const done = cx.run(cx.d, actions, { id: 'review', line: cx.d.trigger });
|
|
326
|
+
cx.set(done.state);
|
|
327
|
+
cx.fx.push(...done.effects);
|
|
328
|
+
if (!done.answered)
|
|
329
|
+
cx.timing('playbackEnd');
|
|
330
|
+
}
|
|
331
|
+
exports.reviewActions = reviewActions;
|
|
332
|
+
/** The reply guard held back the reply: its replacement is said instead (a goodbye closes the call). */
|
|
333
|
+
function guardReplaced(cx, text, alias = cx.cfg.guardAlias, close) {
|
|
334
|
+
if (cx.d.phase === 'closing')
|
|
335
|
+
return;
|
|
336
|
+
cx.d.replying = false;
|
|
337
|
+
const goodbye = close == null && cx.cfg.goodbye(text, cx.core.view(cx.d));
|
|
338
|
+
const action = close
|
|
339
|
+
? { close: text, result: close.result, alias, ...(close.reason ? { reason: close.reason } : {}) }
|
|
340
|
+
: goodbye
|
|
341
|
+
? { close: text, result: cx.cfg.goodbyeResult, alias, reason: 'goodbye_reply' }
|
|
342
|
+
: { say: text, alias };
|
|
343
|
+
const done = cx.run(cx.d, [action], { id: alias, ...(goodbye ? { at: 'goodbye' } : {}) });
|
|
344
|
+
cx.set(done.state);
|
|
345
|
+
cx.fx.push(...done.effects);
|
|
346
|
+
}
|
|
347
|
+
exports.guardReplaced = guardReplaced;
|
|
348
|
+
function spoken(cx, text, unit) {
|
|
349
|
+
if (!text.trim())
|
|
350
|
+
return;
|
|
351
|
+
if (cx.d.phase === 'opening')
|
|
352
|
+
cx.d.stepSpoke = true;
|
|
353
|
+
cx.addLine('agent', text, unit);
|
|
354
|
+
cx.d.replying = false;
|
|
355
|
+
for (const on of ['agentLine', 'agentLineHeard']) {
|
|
356
|
+
const r = cx.core.rules(cx.d, on, text, on, cx.run);
|
|
357
|
+
cx.set(r.state);
|
|
358
|
+
cx.fx.push(...r.effects);
|
|
359
|
+
if (cx.d.phase === 'closing')
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.spoken = spoken;
|