@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,253 @@
|
|
|
1
|
+
import type { DialogDefinition, PortErrorEvent } from '../../dialog/dialog-definition';
|
|
2
|
+
import type { CallView } from '../spec';
|
|
3
|
+
import type { EngineDialogConfig } from './config';
|
|
4
|
+
import { type VoiceEffect, type VoiceEvent } from './voice-dialog';
|
|
5
|
+
import type { NoteLadders } from './turns/ladders';
|
|
6
|
+
export interface EngineLine {
|
|
7
|
+
readonly who: 'agent' | 'caller';
|
|
8
|
+
readonly text: string;
|
|
9
|
+
/** An agent line's mixer alias (a fixed line's name, `reply` for the LLM's), when the media named it. */
|
|
10
|
+
readonly unit?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The engine's state, one flat object (the reducer copies it shallowly per event). Its fields are grouped by the block
|
|
14
|
+
* of ./turns that owns them; a block may read any group, it writes its own (and the call's).
|
|
15
|
+
*/
|
|
16
|
+
export interface EngineState extends CallState, OpeningState, LanguageState, GateState, SilenceState, OvertalkState, VoicemailState, PendingState, TransferState, ClosingState, CarryState, HooksState, NoteLaddersState {
|
|
17
|
+
}
|
|
18
|
+
/** The note ladders of `ladders` (./turns/ladders): stage, counts and the note waiting to be heard, by ladder. */
|
|
19
|
+
export interface NoteLaddersState {
|
|
20
|
+
readonly noteLadders?: NoteLadders;
|
|
21
|
+
}
|
|
22
|
+
/** The call: phase, result, transcript, counts, the rules' marks and counters, variables and flags. */
|
|
23
|
+
export interface CallState {
|
|
24
|
+
readonly phase: 'opening' | 'conversation' | 'closing';
|
|
25
|
+
/** An LLM reply is in flight. */
|
|
26
|
+
readonly replying: boolean;
|
|
27
|
+
readonly result: string;
|
|
28
|
+
readonly lines: readonly EngineLine[];
|
|
29
|
+
/** Caller lines that reached the turn loop / caller finals heard at all. */
|
|
30
|
+
readonly callerTurns: number;
|
|
31
|
+
readonly callerFinals: number;
|
|
32
|
+
/** Text of the last LLM request. */
|
|
33
|
+
readonly lastRequest: string;
|
|
34
|
+
/** Marks for the next LLM turn. */
|
|
35
|
+
readonly marks: readonly string[];
|
|
36
|
+
readonly flags: Readonly<Record<string, boolean>>;
|
|
37
|
+
readonly vars: Readonly<Record<string, unknown>>;
|
|
38
|
+
/** Rule counters: matches, times acted (`max`). */
|
|
39
|
+
readonly counters: Readonly<Record<string, number>>;
|
|
40
|
+
readonly fired: Readonly<Record<string, number>>;
|
|
41
|
+
/** Fixed lines said. */
|
|
42
|
+
readonly said: readonly string[];
|
|
43
|
+
/** The request text of the reply in the making when it answers a caller line (`turn.supersede: 'join'`). */
|
|
44
|
+
readonly replyFor?: string | null;
|
|
45
|
+
/** `input.lookup` still runs (eager greetings wait); the variables it brought (over the input fields). */
|
|
46
|
+
readonly lookupPending?: boolean;
|
|
47
|
+
readonly inputVars?: Readonly<Record<string, unknown>>;
|
|
48
|
+
/** Fixed lines not reported to the LLM yet (`prompt.systemNotes`). */
|
|
49
|
+
readonly notes: readonly string[];
|
|
50
|
+
/** `voice.asrByReply`: every change of the key the agent's replies read as. */
|
|
51
|
+
readonly replyAsrKeys: readonly string[];
|
|
52
|
+
/** Agent lines that played out (`turn.maxLines`). */
|
|
53
|
+
readonly linesDrained?: number;
|
|
54
|
+
/** Wall clock of the last media event (`call.elapsedMs` counts from the call's start to it). */
|
|
55
|
+
readonly at?: number;
|
|
56
|
+
/** Values the `remember` action kept in this call (over the dialog's memory read at answer). */
|
|
57
|
+
readonly memory?: Readonly<Record<string, unknown>>;
|
|
58
|
+
}
|
|
59
|
+
/** The opening (./turns/opening). */
|
|
60
|
+
export interface OpeningState {
|
|
61
|
+
/** Index of the current step. */
|
|
62
|
+
readonly step: number;
|
|
63
|
+
/** Key of the line / clip / greeting the opening waits for (it plays). */
|
|
64
|
+
readonly playing: string | null;
|
|
65
|
+
/** The playing step said something (an empty LLM greeting did not). */
|
|
66
|
+
readonly stepSpoke: boolean;
|
|
67
|
+
/** Next rung of the listen step's silence ladder. */
|
|
68
|
+
readonly rung: number;
|
|
69
|
+
/** Lines the opening said, in order; the caller's answer to it; speech over the previous step. */
|
|
70
|
+
readonly openingSaid: readonly string[];
|
|
71
|
+
readonly openingAnswer: string | null;
|
|
72
|
+
/** The opening answer to ask the LLM with once the opening is over (`listen.answer: 'toLlm'` without a handoff). */
|
|
73
|
+
readonly toLlm: string | null;
|
|
74
|
+
readonly firstReply: string | null;
|
|
75
|
+
readonly beforeQuestion: string | null;
|
|
76
|
+
readonly overPrevious: string | null;
|
|
77
|
+
readonly overPreviousAt: number;
|
|
78
|
+
}
|
|
79
|
+
/** The reply language (./turns/language). */
|
|
80
|
+
export interface LanguageState {
|
|
81
|
+
/** Reply language and whether the pick is provisional; the caller asked for it; lines toward the fallback. */
|
|
82
|
+
readonly lang: string;
|
|
83
|
+
readonly provisional: boolean;
|
|
84
|
+
readonly langRequested: boolean;
|
|
85
|
+
readonly fallbackTurns: number;
|
|
86
|
+
/** Why the language changed, for the marker in front of the next turn. */
|
|
87
|
+
readonly langReason: string | null;
|
|
88
|
+
/** Language the opening question was asked in. */
|
|
89
|
+
readonly askedLanguage: string | null;
|
|
90
|
+
/** The first LLM turn carries `prompt.handoff`. */
|
|
91
|
+
readonly handoffPending: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** Gates, the held line and rules on partials (./turns/rules). */
|
|
94
|
+
export interface GateState {
|
|
95
|
+
/** Gates whose pass the caller has not heard the reply to yet. */
|
|
96
|
+
readonly gateUnheard: readonly string[];
|
|
97
|
+
/** The line is held; held silence turns so far. */
|
|
98
|
+
readonly held: boolean;
|
|
99
|
+
readonly heldTurns: number;
|
|
100
|
+
/** A rule on partials acted on the caller's current utterance (none acts again until its final). */
|
|
101
|
+
readonly partialActed?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/** Silence (./turns/silence). */
|
|
104
|
+
export interface SilenceState {
|
|
105
|
+
/** The silence turn in flight (its rung's name) and the facts of the last window. */
|
|
106
|
+
readonly silence: {
|
|
107
|
+
readonly pendingRung: string | null;
|
|
108
|
+
readonly attempt: number;
|
|
109
|
+
readonly heardSpeech: boolean;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Speech over the agent, its buffer and replay, the trigger line it may continue (./turns/overtalk, ./turns/turn). */
|
|
113
|
+
export interface OvertalkState {
|
|
114
|
+
/** Speech heard over the agent, waiting for the replay. */
|
|
115
|
+
readonly buffered: string | null;
|
|
116
|
+
readonly bufferedAt: number;
|
|
117
|
+
/** How far into the reply's playback the buffered line was heard (`overtalk.reverse.preReplyMs`). */
|
|
118
|
+
readonly bufferedElapsedMs?: number;
|
|
119
|
+
/** The buffered line was heard while a silence turn's reply played (`overtalk.reverse.exceptSilenceTurn`). */
|
|
120
|
+
readonly bufferedOnSilence?: boolean;
|
|
121
|
+
readonly replayHoldAt: number;
|
|
122
|
+
/** The mark of `overtalk.cutMark` for the caller's line being answered (the reply before it was cut). */
|
|
123
|
+
readonly cutMark: string | null;
|
|
124
|
+
/** The caller's text of the last turn and when it was heard (`turn.continuation`). */
|
|
125
|
+
readonly trigger: string;
|
|
126
|
+
readonly triggerAt: number;
|
|
127
|
+
/** The buffered line continues `trigger` (it is its tail). */
|
|
128
|
+
readonly bufferContinues: boolean;
|
|
129
|
+
/** The buffered line's speech began before the reply played (`overtalk.buffer.predating`). */
|
|
130
|
+
readonly bufferedContinuation?: boolean;
|
|
131
|
+
/** The buffered line is a backchannel held at the drain (`overtalk.buffer.backchannel`). */
|
|
132
|
+
readonly bufferedBackchannel: boolean;
|
|
133
|
+
/** A marker for the next caller line's LLM request (`marker`, where it goes), taken by that turn. */
|
|
134
|
+
readonly callerNote: {
|
|
135
|
+
readonly text: string;
|
|
136
|
+
readonly at: 'before' | 'after';
|
|
137
|
+
} | null;
|
|
138
|
+
/** The trigger line of turn `seq` with the speech `overtalk.startedBeforeReply` added to it. */
|
|
139
|
+
readonly triggerJoin: {
|
|
140
|
+
readonly seq: number;
|
|
141
|
+
readonly text: string;
|
|
142
|
+
} | null;
|
|
143
|
+
/** The fixed line now playing takes speech over it as the answer (`say` with `speechOver: 'answer'`). */
|
|
144
|
+
readonly answerOver: boolean;
|
|
145
|
+
}
|
|
146
|
+
/** Looped recordings and cycling menus (./turns/voicemail). */
|
|
147
|
+
export interface VoicemailState {
|
|
148
|
+
readonly vm: {
|
|
149
|
+
readonly last: string;
|
|
150
|
+
readonly loops: number;
|
|
151
|
+
readonly seq: number;
|
|
152
|
+
readonly recent: readonly {
|
|
153
|
+
text: string;
|
|
154
|
+
seq: number;
|
|
155
|
+
}[];
|
|
156
|
+
readonly menu: readonly {
|
|
157
|
+
text: string;
|
|
158
|
+
seq: number;
|
|
159
|
+
}[];
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** Lines waiting for NLU or a hook (./turns/pending). */
|
|
163
|
+
export interface PendingState {
|
|
164
|
+
/**
|
|
165
|
+
* A caller line waiting for an asynchronous rule: the NLU, or a hook that answers later (`held`: the LLM turn
|
|
166
|
+
* already started and waits for its text).
|
|
167
|
+
*/
|
|
168
|
+
readonly pending: {
|
|
169
|
+
readonly key: string;
|
|
170
|
+
readonly line: string;
|
|
171
|
+
readonly filler: string | null;
|
|
172
|
+
readonly hook?: boolean;
|
|
173
|
+
readonly held?: boolean;
|
|
174
|
+
readonly fillerAfterMs?: number;
|
|
175
|
+
/** The hook rule that fired (its answer is that rule's). */
|
|
176
|
+
readonly rule?: string;
|
|
177
|
+
} | null;
|
|
178
|
+
/** A `hook` action (of a silence rung) whose actions are awaited: its key, where it ran, caller turns then. */
|
|
179
|
+
readonly actionHook: {
|
|
180
|
+
readonly key: string;
|
|
181
|
+
readonly id: string;
|
|
182
|
+
readonly at?: 'goodbye' | 'silenceLimit' | 'callEnd';
|
|
183
|
+
readonly turns: number;
|
|
184
|
+
} | null;
|
|
185
|
+
}
|
|
186
|
+
/** The transfer (./turns/transfer). */
|
|
187
|
+
export interface TransferState {
|
|
188
|
+
/** The transfer: started (the conversation is over), bridged, or failed back to the line. */
|
|
189
|
+
readonly transfer: 'started' | 'bridged' | 'failed' | null;
|
|
190
|
+
/** The result the call had when the transfer started (a transfer that did not connect falls back to it). */
|
|
191
|
+
readonly resultBeforeTransfer?: string;
|
|
192
|
+
/** The row's result when the call ends with the transfer still running (the customer left before it connected). */
|
|
193
|
+
readonly transferDroppedResult?: string;
|
|
194
|
+
}
|
|
195
|
+
/** A goodbye the caller may talk into (./turns/closing). */
|
|
196
|
+
export interface ClosingState {
|
|
197
|
+
/** The LLM goodbye now playing out (`closing.reopenOnSpeech`), and whether the call was reopened once. */
|
|
198
|
+
readonly goodbyeLine: string | null;
|
|
199
|
+
readonly reopened: boolean;
|
|
200
|
+
}
|
|
201
|
+
/** The hooks' state (./hook-state). */
|
|
202
|
+
export interface HooksState {
|
|
203
|
+
/**
|
|
204
|
+
* What the call's hooks keep (`HookApi.state`) as of this event: a snapshot the host takes before every event
|
|
205
|
+
* (plain data copied and frozen, other values by reference). Agent code in the reducer reads it as `call.hookState`
|
|
206
|
+
* (a writable copy for the event); its writes come out here and the host commits them to the hooks' state.
|
|
207
|
+
*/
|
|
208
|
+
readonly hookState?: Readonly<Record<string, unknown>>;
|
|
209
|
+
}
|
|
210
|
+
/** `turn.carryOn` (./turns/carry). */
|
|
211
|
+
export interface CarryState {
|
|
212
|
+
/**
|
|
213
|
+
* The LLM turn that may still be taken back (its media turn and the line it answers), whether the caller's current
|
|
214
|
+
* speech began while it could be, and the line of a reply taken back (for the next turn's mark).
|
|
215
|
+
*/
|
|
216
|
+
readonly carry: {
|
|
217
|
+
readonly seq: number;
|
|
218
|
+
readonly line: string;
|
|
219
|
+
} | null;
|
|
220
|
+
readonly carrySegment: boolean;
|
|
221
|
+
readonly carriedFrom: string | null;
|
|
222
|
+
}
|
|
223
|
+
export type EngineEvent = {
|
|
224
|
+
type: 'CALL_STARTED';
|
|
225
|
+
}
|
|
226
|
+
/** A voicemail detector of the event source fired (NLU on partials and finals). */
|
|
227
|
+
| {
|
|
228
|
+
type: 'VOICEMAIL';
|
|
229
|
+
text: string;
|
|
230
|
+
} | VoiceEvent | PortErrorEvent;
|
|
231
|
+
export type EngineEffect = VoiceEffect;
|
|
232
|
+
/** What the reducer knows of the call besides its own state. */
|
|
233
|
+
export interface EngineCallFacts {
|
|
234
|
+
readonly vars: Readonly<Record<string, unknown>>;
|
|
235
|
+
readonly attempt: number;
|
|
236
|
+
readonly memory: Readonly<Record<string, unknown>>;
|
|
237
|
+
/** The hooks' state the call starts with (`HookApi.state`); the dialog's `initial.hookState` is its snapshot. */
|
|
238
|
+
readonly hookState?: Readonly<Record<string, unknown>>;
|
|
239
|
+
/** Wall clock of the call's start, read when needed (`call.elapsedMs`; absent: 0). */
|
|
240
|
+
readonly startedAt?: () => number;
|
|
241
|
+
}
|
|
242
|
+
export interface EngineDialog extends DialogDefinition<EngineState, EngineEvent, EngineEffect> {
|
|
243
|
+
view(state: EngineState): CallView;
|
|
244
|
+
/**
|
|
245
|
+
* An LLM tool call of the reply in flight (`transfer.toolName`): `latched` (the reply ends in the transfer),
|
|
246
|
+
* `refused` (`transfer.requireRequest` did not hold: the reply is cut) or `null` (not the transfer's tool).
|
|
247
|
+
*/
|
|
248
|
+
toolDecision(state: EngineState, names: readonly string[]): 'latched' | 'refused' | null;
|
|
249
|
+
}
|
|
250
|
+
export declare function initialEngineState(language?: string, provisional?: boolean): EngineState;
|
|
251
|
+
export declare function createEngineDialog(cfg: EngineDialogConfig, facts: EngineCallFacts): EngineDialog;
|
|
252
|
+
/** The transcript as `AGENT: …` / `USER: …` lines (the report row and the extraction read it). */
|
|
253
|
+
export declare function transcriptLines(s: EngineState | null): string[];
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transcriptLines = exports.createEngineDialog = exports.initialEngineState = void 0;
|
|
4
|
+
const core_1 = require("../../call/extraction/core");
|
|
5
|
+
const hook_state_1 = require("./hook-state");
|
|
6
|
+
const match_1 = require("./match");
|
|
7
|
+
const voice_dialog_1 = require("./voice-dialog");
|
|
8
|
+
function initialEngineState(language = '', provisional = false) {
|
|
9
|
+
return {
|
|
10
|
+
phase: 'opening', step: 0, playing: null, stepSpoke: false, rung: 0, replying: false,
|
|
11
|
+
result: core_1.BaseResult.GREETING_DROP, lines: [], callerTurns: 0, callerFinals: 0,
|
|
12
|
+
lastRequest: '', marks: [], flags: {}, vars: {}, counters: {}, fired: {}, said: [],
|
|
13
|
+
lang: language, provisional, langRequested: false, fallbackTurns: 0, langReason: null, askedLanguage: null,
|
|
14
|
+
handoffPending: false, openingSaid: [], openingAnswer: null, toLlm: null, firstReply: null, beforeQuestion: null,
|
|
15
|
+
overPrevious: null, overPreviousAt: 0, gateUnheard: [], held: false, heldTurns: 0,
|
|
16
|
+
silence: { pendingRung: null, attempt: 0, heardSpeech: false }, buffered: null, bufferedAt: 0, replayHoldAt: 0, cutMark: null,
|
|
17
|
+
vm: { last: '', loops: 0, seq: 0, recent: [], menu: [] }, pending: null, transfer: null,
|
|
18
|
+
notes: [], replyAsrKeys: [], trigger: '', triggerAt: 0, bufferContinues: false, triggerJoin: null,
|
|
19
|
+
bufferedBackchannel: false, callerNote: null, goodbyeLine: null, reopened: false, answerOver: false, actionHook: null,
|
|
20
|
+
carry: null, carrySegment: false, carriedFrom: null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.initialEngineState = initialEngineState;
|
|
24
|
+
function createEngineDialog(cfg, facts) {
|
|
25
|
+
const language = cfg.languages[0];
|
|
26
|
+
const gates = cfg.voice.gates;
|
|
27
|
+
const view = (s, extra) => {
|
|
28
|
+
const agentLines = s.lines.filter((l) => l.who === 'agent').map((l) => l.text);
|
|
29
|
+
const callerLines = s.lines.filter((l) => l.who === 'caller').map((l) => l.text);
|
|
30
|
+
let flags = s.flags;
|
|
31
|
+
for (const g of gates) {
|
|
32
|
+
const key = `${g.id}.passed`;
|
|
33
|
+
if (flags[key] || !g.passedBy)
|
|
34
|
+
continue;
|
|
35
|
+
const pre = { vars: {}, language: s.lang || language };
|
|
36
|
+
if (agentLines.some((l) => g.passedBy(l, pre)))
|
|
37
|
+
flags = { ...flags, [key]: true };
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
vars: extra ? { ...facts.vars, ...s.inputVars, ...s.vars, ...extra } : { ...facts.vars, ...s.inputVars, ...s.vars },
|
|
41
|
+
language: s.lang || language,
|
|
42
|
+
languageProvisional: s.provisional,
|
|
43
|
+
phase: s.transfer === 'started' || s.transfer === 'bridged' ? 'transfer' : s.phase,
|
|
44
|
+
lines: s.lines.map((l) => ({ who: l.who, text: l.text, atMs: 0, ...(l.unit != null ? { unit: l.unit } : {}) })),
|
|
45
|
+
agentLines,
|
|
46
|
+
callerLines,
|
|
47
|
+
callerTurns: s.callerTurns,
|
|
48
|
+
callerFinals: s.callerFinals,
|
|
49
|
+
counters: s.counters,
|
|
50
|
+
flags,
|
|
51
|
+
elapsedMs: facts.startedAt != null && s.at != null ? Math.max(0, s.at - facts.startedAt()) : 0,
|
|
52
|
+
attempt: facts.attempt,
|
|
53
|
+
previous: null,
|
|
54
|
+
memory: s.memory ? { ...facts.memory, ...s.memory } : facts.memory,
|
|
55
|
+
...(s.hookState ? { hookState: s.hookState } : {}),
|
|
56
|
+
...(s.replyAsrKeys.length ? { replyAsr: s.replyAsrKeys[s.replyAsrKeys.length - 1], replyAsrKeys: s.replyAsrKeys } : {}),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const text = (t, s, line, extra, ruleCount) => (0, match_1.resolveText)(t, ruleCount ? { ...view(s, extra), ruleCount } : view(s, extra), line);
|
|
60
|
+
const decide = (at, s, result) => at && cfg.resultRule
|
|
61
|
+
? cfg.resultRule(at, {
|
|
62
|
+
result, callerTurns: s.callerTurns, callerFinals: s.callerFinals, closing: s.phase === 'closing', counters: s.counters, flags: s.flags,
|
|
63
|
+
afterSilence: s.silence.pendingRung != null,
|
|
64
|
+
...(s.hookState ? { hookState: s.hookState } : {}),
|
|
65
|
+
})
|
|
66
|
+
: result;
|
|
67
|
+
// ── rules ────────────────────────────────────────────────────────────────────────────────────
|
|
68
|
+
const ruleApplies = (r, s) => {
|
|
69
|
+
if (!r.phases.includes(s.phase))
|
|
70
|
+
return false;
|
|
71
|
+
if (r.held != null && s.held !== r.held)
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Rules on one event, in order: the first that acts ends the pass unless it has `continue`. `runner` runs the
|
|
77
|
+
* actions; `asyncHits`: rules whose NLU intents matched (absent: no NLU this pass).
|
|
78
|
+
*/
|
|
79
|
+
function rules(s0, on, line, id, runner, asyncHits, hookActions) {
|
|
80
|
+
let s = s0;
|
|
81
|
+
const list = cfg.rules.filter((r) => r.on === on);
|
|
82
|
+
if (!list.length)
|
|
83
|
+
return { state: s, effects: [], answered: false, next: false };
|
|
84
|
+
const v = view(s);
|
|
85
|
+
const matched = new Map(list.map((r) => [r.id, ruleApplies(r, s) && (r.intents || r.hook ? asyncHits?.has(r.id) === true : r.test(line, v))]));
|
|
86
|
+
const effects = [];
|
|
87
|
+
let answered = false;
|
|
88
|
+
let next = false;
|
|
89
|
+
for (const r of list) {
|
|
90
|
+
if (!matched.get(r.id))
|
|
91
|
+
continue;
|
|
92
|
+
// A condition rule reads the call as the rules before it left it.
|
|
93
|
+
if (r.lazy && !r.lazy(view(s), line))
|
|
94
|
+
continue;
|
|
95
|
+
const n = (s.counters[r.id] ?? 0) + 1;
|
|
96
|
+
s = { ...s, counters: { ...s.counters, [r.id]: n } };
|
|
97
|
+
if (r.max != null && (s.fired[r.id] ?? 0) >= r.max)
|
|
98
|
+
continue;
|
|
99
|
+
s = { ...s, fired: { ...s.fired, [r.id]: (s.fired[r.id] ?? 0) + 1 } };
|
|
100
|
+
const d = runner(s, (r.hook ? hookActions?.get(r.id) : undefined) ?? r.actions, { line, id: r.id });
|
|
101
|
+
s = d.state;
|
|
102
|
+
effects.push(...d.effects);
|
|
103
|
+
answered ||= d.answered;
|
|
104
|
+
next ||= d.next;
|
|
105
|
+
if (!r.continue || s.phase === 'closing')
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return { state: s, effects, answered, next };
|
|
109
|
+
}
|
|
110
|
+
const voice = (0, voice_dialog_1.createVoiceTurns)({ cfg, v: cfg.voice, view, text, decide, rules });
|
|
111
|
+
const yesWords = new Map(cfg.languages.map((l) => [l, (0, match_1.lexiconWords)([l], 'yes')]));
|
|
112
|
+
const toolDecision = (s, names) => {
|
|
113
|
+
const t = cfg.transfer;
|
|
114
|
+
if (!t?.toolName || s.transfer != null || !names.includes(t.toolName))
|
|
115
|
+
return null;
|
|
116
|
+
const rr = t.requireRequest;
|
|
117
|
+
if (!rr)
|
|
118
|
+
return 'latched';
|
|
119
|
+
const caller = s.lines.filter((l) => l.who === 'caller').slice(-rr.lookbackTurns).map((l) => l.text);
|
|
120
|
+
return rr.test(caller.join(' '), view(s)) ? 'latched' : 'refused';
|
|
121
|
+
};
|
|
122
|
+
function reduceEvent(s, e) {
|
|
123
|
+
try {
|
|
124
|
+
if (e.type === 'CALL_STARTED') {
|
|
125
|
+
if (s.phase !== 'opening' || s.step !== 0 || s.playing || s.openingSaid.length)
|
|
126
|
+
return { state: s };
|
|
127
|
+
return voice.start(s);
|
|
128
|
+
}
|
|
129
|
+
if (e.type === 'PORT_ERROR')
|
|
130
|
+
return voice.failed(s, `effect:${effectName(e.effect)}`, e.error);
|
|
131
|
+
return voice.reduce(s, e, yesWords);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
// Agent code in a rule, text or matcher threw: the event is lost, the call must not hang on it.
|
|
135
|
+
return voice.failed(s, `event:${e.type}`, err instanceof Error ? err.message : String(err));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const dialog = {
|
|
139
|
+
initial: {
|
|
140
|
+
...initialEngineState(language, cfg.voice.language != null && cfg.voice.language.provisional),
|
|
141
|
+
...(facts.hookState ? { hookState: (0, hook_state_1.snapshotHookState)(facts.hookState) } : {}),
|
|
142
|
+
},
|
|
143
|
+
view,
|
|
144
|
+
toolDecision,
|
|
145
|
+
reduce(s0, e) {
|
|
146
|
+
// Agent code of this event reads and writes a copy of the hooks' state; the new state carries what it wrote.
|
|
147
|
+
const before = s0.hookState;
|
|
148
|
+
const draft = before ? (0, hook_state_1.draftHookState)(before) : undefined;
|
|
149
|
+
const s = draft ? { ...s0, hookState: draft } : s0;
|
|
150
|
+
const t = reduceEvent(s, e);
|
|
151
|
+
if (!before || !draft)
|
|
152
|
+
return t;
|
|
153
|
+
return { ...t, state: { ...t.state, hookState: (0, hook_state_1.settleHookState)(before, draft) } };
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
return dialog;
|
|
157
|
+
}
|
|
158
|
+
exports.createEngineDialog = createEngineDialog;
|
|
159
|
+
function effectName(effect) {
|
|
160
|
+
const t = effect != null && typeof effect === 'object' ? effect.type : undefined;
|
|
161
|
+
return typeof t === 'string' ? t : 'unknown';
|
|
162
|
+
}
|
|
163
|
+
/** The transcript as `AGENT: …` / `USER: …` lines (the report row and the extraction read it). */
|
|
164
|
+
function transcriptLines(s) {
|
|
165
|
+
return (s?.lines ?? []).map((l) => `${l.who === 'agent' ? 'AGENT' : 'USER'}: ${l.text}`);
|
|
166
|
+
}
|
|
167
|
+
exports.transcriptLines = transcriptLines;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LocaleFormat } from '../locale';
|
|
2
|
+
export interface ExpandNumbers {
|
|
3
|
+
readonly prefixes?: readonly string[];
|
|
4
|
+
readonly ordinals?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** The `expandToken` of `expandNumbers` for a pack's read-out forms. */
|
|
7
|
+
export declare function numberExpander(format: LocaleFormat, o: ExpandNumbers): (word: string) => readonly string[] | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numberExpander = void 0;
|
|
4
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
5
|
+
/** The `expandToken` of `expandNumbers` for a pack's read-out forms. */
|
|
6
|
+
function numberExpander(format, o) {
|
|
7
|
+
const prefixes = (o.prefixes ?? []).map((p) => escape(p.toLowerCase()));
|
|
8
|
+
const suffixes = o.ordinals === false ? [] : (format.ordinalSuffixes ?? []).map(escape);
|
|
9
|
+
const re = new RegExp(`^(?:${prefixes.length ? `(?:${prefixes.join('|')})?` : ''})(\\d{1,9})${suffixes.length ? `(${suffixes.join('|')})?` : '()'}$`, 'u');
|
|
10
|
+
return (word) => {
|
|
11
|
+
const m = re.exec(word);
|
|
12
|
+
if (!m)
|
|
13
|
+
return null;
|
|
14
|
+
const n = Number(m[1]);
|
|
15
|
+
const words = m[2] && format.ordinalNumber ? format.ordinalNumber(n) : format.number(n);
|
|
16
|
+
return words.split(/[\s-]+/).filter(Boolean);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.numberExpander = numberExpander;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AgentHooks, EngineSpec } from '../spec';
|
|
2
|
+
/** The agent file and hooks with the blocks wired in (the same objects when the file has no block). */
|
|
3
|
+
export declare function withBlocks(file: EngineSpec, hooks: AgentHooks | undefined): {
|
|
4
|
+
file: EngineSpec;
|
|
5
|
+
hooks: AgentHooks | undefined;
|
|
6
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withBlocks = void 0;
|
|
4
|
+
const block_1 = require("../knowledge/block");
|
|
5
|
+
const block_2 = require("../catalog-match/block");
|
|
6
|
+
const ALWAYS = () => true;
|
|
7
|
+
function lazy(make) {
|
|
8
|
+
let value;
|
|
9
|
+
return () => (value ??= make());
|
|
10
|
+
}
|
|
11
|
+
function decisionOf(own, file, path) {
|
|
12
|
+
const d = own ?? file.decisionModel;
|
|
13
|
+
if (!d)
|
|
14
|
+
throw new Error(`[templates/engine] ${path}: no decision model (set it there or in decisionModel)`);
|
|
15
|
+
return d;
|
|
16
|
+
}
|
|
17
|
+
function mapActions(a, f) {
|
|
18
|
+
if (a == null)
|
|
19
|
+
return a;
|
|
20
|
+
return Array.isArray(a) ? a.map(f) : f(a);
|
|
21
|
+
}
|
|
22
|
+
function mapSilence(s, f) {
|
|
23
|
+
if (!s)
|
|
24
|
+
return s;
|
|
25
|
+
const rung = (r) => ({
|
|
26
|
+
...r,
|
|
27
|
+
do: mapActions(r.do, f),
|
|
28
|
+
...(r.otherwise != null ? { otherwise: mapActions(r.otherwise, f) } : {}),
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
...s,
|
|
32
|
+
ladder: s.ladder.map(rung),
|
|
33
|
+
...(s.held ? { held: { ...s.held, rungs: s.held.rungs.map(rung) } } : {}),
|
|
34
|
+
...(s.speechWithoutText?.do != null ? { speechWithoutText: { ...s.speechWithoutText, do: mapActions(s.speechWithoutText.do, f) } } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function mapReport(file, f) {
|
|
38
|
+
const fields = file.report.fields;
|
|
39
|
+
if (!fields)
|
|
40
|
+
return file.report;
|
|
41
|
+
return { ...file.report, fields: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, f(v)])) };
|
|
42
|
+
}
|
|
43
|
+
function addHooks(hooks, extra) {
|
|
44
|
+
for (const name of Object.keys(extra)) {
|
|
45
|
+
if (hooks?.[name])
|
|
46
|
+
throw new Error(`[templates/engine] hook "${name}" is reserved for a block`);
|
|
47
|
+
}
|
|
48
|
+
return { ...(hooks ?? {}), ...extra };
|
|
49
|
+
}
|
|
50
|
+
/** `{ knowledge }` actions anywhere the file allows them, with no `knowledgeAnswer` block: an error. */
|
|
51
|
+
function rejectKnowledgeActions(file) {
|
|
52
|
+
const bad = (a) => {
|
|
53
|
+
if ('knowledge' in a)
|
|
54
|
+
throw new Error('[templates/engine] silence: a { knowledge } action needs knowledgeAnswer');
|
|
55
|
+
return a;
|
|
56
|
+
};
|
|
57
|
+
mapSilence(file.silence, bad);
|
|
58
|
+
}
|
|
59
|
+
/** The agent file and hooks with the blocks wired in (the same objects when the file has no block). */
|
|
60
|
+
function withBlocks(file, hooks) {
|
|
61
|
+
let f = file;
|
|
62
|
+
let h = hooks;
|
|
63
|
+
const ka = file.knowledgeAnswer;
|
|
64
|
+
if (ka) {
|
|
65
|
+
const spec = { ...ka, decision: decisionOf(ka.decision, file, 'knowledgeAnswer.decision') };
|
|
66
|
+
const index = lazy(() => (0, block_1.knowledgeIndex)(spec, file.languages));
|
|
67
|
+
const unheard = ka.unheardLine ?? file.silence?.speechWithoutText?.transcriptLine ?? '';
|
|
68
|
+
h = addHooks(h, (0, block_1.knowledgeHooks)(spec, index, unheard));
|
|
69
|
+
const toHook = (a) => 'knowledge' in a ? { hook: a.knowledge === 'silence' ? block_1.KNOWLEDGE_HOOKS.silence : block_1.KNOWLEDGE_HOOKS.unheard } : a;
|
|
70
|
+
const rule = { id: ka.ruleId ?? 'knowledge', on: 'callerLine', match: ALWAYS, then: { hook: block_1.KNOWLEDGE_HOOKS.answer } };
|
|
71
|
+
const { answered, unanswered } = ka.results;
|
|
72
|
+
const presay = ka.presay === 'systemPhrases' && f.voice.tts.presay == null
|
|
73
|
+
? Object.entries(ka.phrases).filter(([id]) => !ka.greeting.includes(id)).map(([, p]) => p.text)
|
|
74
|
+
: undefined;
|
|
75
|
+
f = {
|
|
76
|
+
...f,
|
|
77
|
+
...(presay ? { voice: { ...f.voice, tts: { ...f.voice.tts, presay } } } : {}),
|
|
78
|
+
...(f.silence ? { silence: mapSilence(f.silence, toHook) } : {}),
|
|
79
|
+
rules: [...(f.rules ?? []), rule],
|
|
80
|
+
integrations: [...(f.integrations ?? []), { id: ka.startId ?? 'knowledge_start', phase: 'answer', run: { hook: block_1.KNOWLEDGE_HOOKS.start } }],
|
|
81
|
+
results: {
|
|
82
|
+
...f.results,
|
|
83
|
+
fromFacts: [
|
|
84
|
+
...(f.results.fromFacts ?? []),
|
|
85
|
+
{ at: 'callEnd', when: (c) => (0, block_1.knowledgeResult)(c) === answered, result: answered },
|
|
86
|
+
{ at: 'callEnd', when: (c) => (0, block_1.knowledgeResult)(c) === unanswered, result: unanswered },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
f = {
|
|
91
|
+
...f,
|
|
92
|
+
report: mapReport(f, (src) => src != null && typeof src === 'object' && 'knowledgeTrace' in src
|
|
93
|
+
? src.knowledgeTrace === 'call'
|
|
94
|
+
? { spread: (_row, c) => ((0, block_1.knowledgeTraced)(c) ? (0, block_1.knowledgeTrace)(c) : undefined) }
|
|
95
|
+
: { spread: (_row, c) => ((0, block_1.knowledgeTraced)(c) ? undefined : (0, block_1.knowledgeTrace)(c)) }
|
|
96
|
+
: src),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
rejectKnowledgeActions(file);
|
|
101
|
+
}
|
|
102
|
+
const cm = file.catalogMatch;
|
|
103
|
+
if (cm) {
|
|
104
|
+
const spec = { ...cm, pick: { ...cm.pick, decision: decisionOf(cm.pick.decision, file, 'catalogMatch.pick.decision') } };
|
|
105
|
+
const requests = lazy(() => (0, block_2.catalogRequests)(spec, file.languages));
|
|
106
|
+
h = addHooks(h, (0, block_2.catalogHooks)(spec, requests));
|
|
107
|
+
const rule = {
|
|
108
|
+
id: cm.ruleId ?? 'catalogMatch',
|
|
109
|
+
on: 'callerLine',
|
|
110
|
+
match: ALWAYS,
|
|
111
|
+
then: { hook: block_2.CATALOG_HOOK },
|
|
112
|
+
...(cm.hold ? { whileWaiting: cm.hold } : {}),
|
|
113
|
+
};
|
|
114
|
+
const names = (file.extraction?.entities ?? []).map((e) => e.name);
|
|
115
|
+
f = {
|
|
116
|
+
...f,
|
|
117
|
+
rules: [...(f.rules ?? []), rule],
|
|
118
|
+
report: mapReport(f, (src) => src != null && typeof src === 'object' && 'catalogMatch' in src
|
|
119
|
+
? { spread: (_row, c) => (0, block_2.catalogRow)(spec, requests, c, src.entities === 'all' ? names : null) }
|
|
120
|
+
: src),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return { file: f, hooks: h };
|
|
124
|
+
}
|
|
125
|
+
exports.withBlocks = withBlocks;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import type { AgentHooks, CallView, ReplyFilterSpec, TtsSpec } from '../spec';
|
|
3
|
+
import { type InvalidHookResult } from './hooks';
|
|
4
|
+
export type TextOperator = (text$: Observable<string>) => Observable<string>;
|
|
5
|
+
/** What a filter reads of the call while the reply streams. */
|
|
6
|
+
export interface FilterContext {
|
|
7
|
+
/** The call as it is now (reply language, variables, lines). */
|
|
8
|
+
readonly view: () => CallView;
|
|
9
|
+
/** Per-call scratch (`insertAfter` with `once`). */
|
|
10
|
+
readonly state: Record<string, unknown>;
|
|
11
|
+
/** The reply's turn: its sequence number, tag (`bootstrap`: the LLM greeting), the caller's words it answers, and
|
|
12
|
+
* whether it answers a silence turn. */
|
|
13
|
+
readonly turn?: {
|
|
14
|
+
readonly seq: number;
|
|
15
|
+
readonly tag: string;
|
|
16
|
+
readonly trigger?: string;
|
|
17
|
+
readonly silence?: boolean;
|
|
18
|
+
/** The text sent to the LLM; why the turn is a regeneration (`null`: it is not). */
|
|
19
|
+
readonly request?: string;
|
|
20
|
+
readonly regenerated?: string | null;
|
|
21
|
+
};
|
|
22
|
+
/** Reports a hook's answer of the wrong shape (it is ignored). */
|
|
23
|
+
readonly invalid?: InvalidHookResult;
|
|
24
|
+
}
|
|
25
|
+
/** What `turn.review` decides on a held reply. */
|
|
26
|
+
export type ReviewVerdict = null | 'release' | {
|
|
27
|
+
readonly regenerate: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly then: readonly import('../spec').Action[];
|
|
30
|
+
};
|
|
31
|
+
/** `turn.review` as the filters run it: the agent's hook at the turn's start and on the held text. */
|
|
32
|
+
export interface ReviewGate {
|
|
33
|
+
start(view: CallView, turn: {
|
|
34
|
+
request: string;
|
|
35
|
+
trigger: string;
|
|
36
|
+
regenerated: string | null;
|
|
37
|
+
silence: boolean;
|
|
38
|
+
}): {
|
|
39
|
+
holdChars: number;
|
|
40
|
+
} | null;
|
|
41
|
+
judge(view: CallView, turn: {
|
|
42
|
+
held: string;
|
|
43
|
+
final: boolean;
|
|
44
|
+
request: string;
|
|
45
|
+
trigger: string;
|
|
46
|
+
regenerated: string | null;
|
|
47
|
+
}): ReviewVerdict;
|
|
48
|
+
}
|
|
49
|
+
/** The reply guard of `closing.guard` as the filters run it. */
|
|
50
|
+
export interface ReplyGuard {
|
|
51
|
+
readonly closings: (call: CallView) => readonly string[];
|
|
52
|
+
readonly openings: (call: CallView) => readonly string[];
|
|
53
|
+
readonly holdChars: number;
|
|
54
|
+
readonly leading?: RegExp;
|
|
55
|
+
/** The fixed line that replaces a held line (`null`: it is spoken as it is). */
|
|
56
|
+
readonly replace: (call: CallView, line: string) => string | null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The reply filters of the agent file (and the reply guard, where `closingGuard` stands; first when not listed) as
|
|
60
|
+
* one operator per turn; `null` when there are none on the reply.
|
|
61
|
+
*/
|
|
62
|
+
export declare function replyFilters(filters: readonly ReplyFilterSpec[], languages: readonly string[], ctx: FilterContext, hooks?: AgentHooks, guard?: ReplyGuard, review?: ReviewGate, transfer?: boolean): ((turn?: ReplyFilterTurn) => TextOperator) | null;
|
|
63
|
+
/** The turn a reply is filtered for. */
|
|
64
|
+
export type ReplyFilterTurn = {
|
|
65
|
+
readonly seq: number;
|
|
66
|
+
readonly tag: string;
|
|
67
|
+
readonly state?: Record<string, unknown>;
|
|
68
|
+
readonly trigger?: string;
|
|
69
|
+
readonly silence?: boolean;
|
|
70
|
+
readonly request?: string;
|
|
71
|
+
readonly regenerated?: string | null;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* {@link replyFilters} in two steps: the matchers are compiled once (`guarded`, `reviewed`: the agent has a closing
|
|
75
|
+
* guard, a review), the filters of one call are bound to its context, guard and review.
|
|
76
|
+
*/
|
|
77
|
+
export declare function compileReplyFilters(filters: readonly ReplyFilterSpec[], languages: readonly string[], hooks: AgentHooks | undefined, guarded: boolean, reviewed: boolean, transfer?: boolean): ((ctx: FilterContext, guard?: ReplyGuard, review?: ReviewGate) => (turn?: ReplyFilterTurn) => TextOperator) | null;
|
|
78
|
+
/** The voice-only respelling of a text: the agent's list. */
|
|
79
|
+
export declare function respellText(tts: TtsSpec): ((text: string) => string) | null;
|
|
80
|
+
/** A text stream respelled up to its last space; the rest waits for the next chunk (`respellBy: 'word'`). */
|
|
81
|
+
export declare function respellByWord(respell: (text: string) => string): (text$: Observable<string>) => Observable<string>;
|