@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,32 @@
|
|
|
1
|
+
import type { PlatformApi, ScriptLogger } from '@voctiv/agent-sdk';
|
|
2
|
+
export interface IntentInterruptConfig {
|
|
3
|
+
readonly intents: readonly string[];
|
|
4
|
+
/** Partials shorter than this are not read. */
|
|
5
|
+
readonly minChars: number;
|
|
6
|
+
readonly throttleMs: number;
|
|
7
|
+
readonly language?: string;
|
|
8
|
+
}
|
|
9
|
+
/** The agent's line as the detector samples it: playing, and when it started playing (one value per line). */
|
|
10
|
+
export interface AgentLineState {
|
|
11
|
+
readonly speaking: boolean;
|
|
12
|
+
readonly startedAt: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class IntentInterrupt {
|
|
15
|
+
private readonly platform;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
private readonly config;
|
|
18
|
+
private readonly line;
|
|
19
|
+
private readonly onIntent;
|
|
20
|
+
private matchedLine;
|
|
21
|
+
private armedFor;
|
|
22
|
+
private inFlight;
|
|
23
|
+
private disposed;
|
|
24
|
+
private available;
|
|
25
|
+
private lastText;
|
|
26
|
+
private nextAt;
|
|
27
|
+
private errors;
|
|
28
|
+
constructor(platform: PlatformApi | null, logger: ScriptLogger, config: IntentInterruptConfig, line: () => AgentLineState, onIntent: (intent: string, text: string) => void);
|
|
29
|
+
onPartial(text: string): void;
|
|
30
|
+
dispose(): void;
|
|
31
|
+
private check;
|
|
32
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntentInterrupt = void 0;
|
|
4
|
+
const MAX_ERRORS = 3;
|
|
5
|
+
class IntentInterrupt {
|
|
6
|
+
constructor(platform, logger, config, line, onIntent) {
|
|
7
|
+
this.platform = platform;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.line = line;
|
|
11
|
+
this.onIntent = onIntent;
|
|
12
|
+
this.matchedLine = false;
|
|
13
|
+
this.armedFor = 0;
|
|
14
|
+
this.inFlight = false;
|
|
15
|
+
this.disposed = false;
|
|
16
|
+
this.available = true;
|
|
17
|
+
this.lastText = '';
|
|
18
|
+
this.nextAt = 0;
|
|
19
|
+
this.errors = 0;
|
|
20
|
+
}
|
|
21
|
+
onPartial(text) {
|
|
22
|
+
void this.check(text);
|
|
23
|
+
}
|
|
24
|
+
dispose() {
|
|
25
|
+
this.disposed = true;
|
|
26
|
+
}
|
|
27
|
+
async check(raw) {
|
|
28
|
+
const { config, logger } = this;
|
|
29
|
+
if (this.disposed || !this.available)
|
|
30
|
+
return;
|
|
31
|
+
const line = this.line();
|
|
32
|
+
if (!line.speaking)
|
|
33
|
+
return;
|
|
34
|
+
if (line.startedAt !== this.armedFor) {
|
|
35
|
+
this.armedFor = line.startedAt;
|
|
36
|
+
this.matchedLine = false;
|
|
37
|
+
this.lastText = '';
|
|
38
|
+
}
|
|
39
|
+
if (this.matchedLine || this.inFlight)
|
|
40
|
+
return;
|
|
41
|
+
const nlu = this.platform?.nlu;
|
|
42
|
+
if (!nlu) {
|
|
43
|
+
this.available = false;
|
|
44
|
+
logger.log('interrupt_nlu_unavailable', { reason: 'no platform api' });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const text = raw.trim();
|
|
48
|
+
if (text.length < config.minChars || text === this.lastText)
|
|
49
|
+
return;
|
|
50
|
+
const startedAt = Date.now();
|
|
51
|
+
if (startedAt < this.nextAt)
|
|
52
|
+
return;
|
|
53
|
+
this.inFlight = true;
|
|
54
|
+
this.lastText = text;
|
|
55
|
+
this.nextAt = startedAt + config.throttleMs;
|
|
56
|
+
try {
|
|
57
|
+
const result = await nlu.extract(text, {
|
|
58
|
+
intents: [...config.intents],
|
|
59
|
+
use_neuro_api: false,
|
|
60
|
+
...(config.language != null ? { language: config.language } : {}),
|
|
61
|
+
context: null,
|
|
62
|
+
});
|
|
63
|
+
this.errors = 0;
|
|
64
|
+
if (this.disposed || this.matchedLine)
|
|
65
|
+
return;
|
|
66
|
+
const now = this.line();
|
|
67
|
+
if (!now.speaking || now.startedAt !== this.armedFor) {
|
|
68
|
+
logger.log('interrupt_intent_stale', { text });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const matched = config.intents.find((i) => result.has_intent(i));
|
|
72
|
+
if (matched == null)
|
|
73
|
+
return;
|
|
74
|
+
this.matchedLine = true;
|
|
75
|
+
logger.log('interrupt_intent_matched', { intent: matched, text, nluMs: Date.now() - startedAt });
|
|
76
|
+
this.onIntent(matched, text);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
this.errors += 1;
|
|
80
|
+
logger.log('interrupt_nlu_error', { textLen: text.length, consecutiveErrors: this.errors, err: String(err) });
|
|
81
|
+
if (this.errors >= MAX_ERRORS) {
|
|
82
|
+
this.available = false;
|
|
83
|
+
logger.log('interrupt_nlu_disabled', { afterErrors: this.errors });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
this.inFlight = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.IntentInterrupt = IntentInterrupt;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface SelfEchoConfig {
|
|
2
|
+
/** Caller words of one run that must reproduce the agent line (the long path). */
|
|
3
|
+
readonly minEchoTokens: number;
|
|
4
|
+
/** Share of the agent line's distinct words the run must reproduce. */
|
|
5
|
+
readonly minAgentCoverage: number;
|
|
6
|
+
/** Caller words between two reproduced words before the run ends. */
|
|
7
|
+
readonly maxGapTokens: number;
|
|
8
|
+
/** How many of the agent's last lines are compared (most recent first). */
|
|
9
|
+
readonly lookback: number;
|
|
10
|
+
/**
|
|
11
|
+
* The short path: a final shorter than `minEchoTokens` that reproduces a whole non-final sentence of the agent's
|
|
12
|
+
* last line exactly (at least this many words) and nothing else is an echo. `0`: off.
|
|
13
|
+
*/
|
|
14
|
+
readonly sentenceEchoMinTokens: number;
|
|
15
|
+
/** A caller word (normalized) as the words the agent may have spoken for it (a number in digits); `null`: as is. */
|
|
16
|
+
readonly expandToken?: (word: string) => readonly string[] | null;
|
|
17
|
+
}
|
|
18
|
+
export interface SelfEchoVerdict {
|
|
19
|
+
/** What the caller said around the echo (`''`: nothing, a pure echo). */
|
|
20
|
+
readonly residue: string;
|
|
21
|
+
readonly echoTokens: number;
|
|
22
|
+
readonly echoSpan: number;
|
|
23
|
+
readonly totalTokens: number;
|
|
24
|
+
readonly agentCoverage: number;
|
|
25
|
+
readonly agentText: string;
|
|
26
|
+
}
|
|
27
|
+
/** The echo in a caller final of one of the agent's recent lines (most recent first); `null`: none. */
|
|
28
|
+
export declare function detectSelfEcho(callerText: string, recentAgent: readonly string[], cfg: SelfEchoConfig): SelfEchoVerdict | null;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Self-echo of the agent on the caller's line: on an echoing line the agent's own reply comes back on the inbound leg
|
|
3
|
+
// and the recognizer writes it as the caller's words. A caller final that reproduces a run of one of the agent's last
|
|
4
|
+
// lines is an echo: dropped when nothing else is in it, or cut down to what the caller said around it (the residue).
|
|
5
|
+
// Words are compared lower case without punctuation, one edit apart for words of 4+ letters; a number the recognizer
|
|
6
|
+
// wrote in digits may be expanded into the words the agent spoke (`expandToken`, agent data). Pure functions.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.detectSelfEcho = void 0;
|
|
9
|
+
function tokenize(text, expand) {
|
|
10
|
+
return text
|
|
11
|
+
.split(/[\s–—/-]+/)
|
|
12
|
+
.map((raw) => ({ raw, norm: raw.toLowerCase().replace(/[^\p{L}\p{N}]/gu, '') }))
|
|
13
|
+
.filter((t) => t.norm.length > 0)
|
|
14
|
+
.flatMap((t) => {
|
|
15
|
+
const words = expand?.(t.norm);
|
|
16
|
+
if (words == null || words.length === 0)
|
|
17
|
+
return [t];
|
|
18
|
+
// The caller's spelling rides on the first expanded word only, so a residue reproduces it once.
|
|
19
|
+
return words.map((norm, i) => ({ raw: i === 0 ? t.raw : '', norm }));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function withinEditDistance(a, b, max) {
|
|
23
|
+
if (Math.abs(a.length - b.length) > max)
|
|
24
|
+
return false;
|
|
25
|
+
let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
26
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
27
|
+
const row = [i];
|
|
28
|
+
let rowMin = i;
|
|
29
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
30
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
31
|
+
row[j] = Math.min(row[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);
|
|
32
|
+
if (row[j] < rowMin)
|
|
33
|
+
rowMin = row[j];
|
|
34
|
+
}
|
|
35
|
+
if (rowMin > max)
|
|
36
|
+
return false;
|
|
37
|
+
prev = row;
|
|
38
|
+
}
|
|
39
|
+
return prev[b.length] <= max;
|
|
40
|
+
}
|
|
41
|
+
function tokensEqual(a, b) {
|
|
42
|
+
if (a === b)
|
|
43
|
+
return true;
|
|
44
|
+
if (Math.max(a.length, b.length) < 4 || Math.min(a.length, b.length) < 3)
|
|
45
|
+
return false;
|
|
46
|
+
return withinEditDistance(a, b, 1);
|
|
47
|
+
}
|
|
48
|
+
function alignFrom(tokens, agent, startIdx, agentStart, maxGap) {
|
|
49
|
+
let cursor = agentStart;
|
|
50
|
+
let gap = 0;
|
|
51
|
+
let count = 0;
|
|
52
|
+
let end = -1;
|
|
53
|
+
const reproduced = new Set();
|
|
54
|
+
for (let i = startIdx; i < tokens.length; i += 1) {
|
|
55
|
+
const limit = Math.min(agent.length, cursor + 2 + gap);
|
|
56
|
+
let hit = -1;
|
|
57
|
+
for (let q = cursor; q < limit; q += 1)
|
|
58
|
+
if (tokensEqual(agent[q].norm, tokens[i].norm))
|
|
59
|
+
hit = q;
|
|
60
|
+
if (hit >= 0) {
|
|
61
|
+
// An expanded number bridges the run but counts once (a real answer repeating an amount stays an answer).
|
|
62
|
+
if (tokens[i].raw !== '')
|
|
63
|
+
count += 1;
|
|
64
|
+
end = i;
|
|
65
|
+
cursor = hit + 1;
|
|
66
|
+
gap = 0;
|
|
67
|
+
reproduced.add(agent[hit].norm);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
gap += 1;
|
|
71
|
+
if (gap > maxGap)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return end < 0 ? null : { start: startIdx, end, count, reproduced };
|
|
76
|
+
}
|
|
77
|
+
function verdictFor(tokens, agentText, cfg) {
|
|
78
|
+
const agent = tokenize(agentText, cfg.expandToken);
|
|
79
|
+
if (agent.length === 0)
|
|
80
|
+
return null;
|
|
81
|
+
const distinct = new Set(agent.map((t) => t.norm)).size;
|
|
82
|
+
let best = null;
|
|
83
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
84
|
+
for (let p = 0; p < agent.length; p += 1) {
|
|
85
|
+
if (!tokensEqual(agent[p].norm, tokens[i].norm))
|
|
86
|
+
continue;
|
|
87
|
+
const run = alignFrom(tokens, agent, i, p, cfg.maxGapTokens);
|
|
88
|
+
if (run != null && (best == null || run.count > best.count))
|
|
89
|
+
best = run;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (best == null || best.count < cfg.minEchoTokens)
|
|
93
|
+
return null;
|
|
94
|
+
const agentCoverage = best.reproduced.size / distinct;
|
|
95
|
+
if (agentCoverage < cfg.minAgentCoverage)
|
|
96
|
+
return null;
|
|
97
|
+
const run = best;
|
|
98
|
+
const residue = tokens.filter((t, i) => (i < run.start || i > run.end) && t.raw !== '').map((t) => t.raw).join(' ').trim();
|
|
99
|
+
return { residue, echoTokens: run.count, echoSpan: run.end - run.start + 1, totalTokens: tokens.length, agentCoverage, agentText };
|
|
100
|
+
}
|
|
101
|
+
/** The sentences of a line but its last (a question at the end is answered in its own words, not echoed). */
|
|
102
|
+
function nonFinalSentences(text) {
|
|
103
|
+
return text.split(/(?<=[.!?…])[\s"')\]]*(?=\p{Lu}|$)/u).map((s) => s.trim()).filter((s) => s.length > 0).slice(0, -1);
|
|
104
|
+
}
|
|
105
|
+
function sentenceVerdictFor(tokens, agentText, cfg) {
|
|
106
|
+
if (cfg.sentenceEchoMinTokens <= 0 || tokens.length < cfg.sentenceEchoMinTokens)
|
|
107
|
+
return null;
|
|
108
|
+
const exact = { ...cfg, minEchoTokens: cfg.sentenceEchoMinTokens, minAgentCoverage: 1 };
|
|
109
|
+
for (const sentence of nonFinalSentences(agentText)) {
|
|
110
|
+
if (tokenize(sentence, cfg.expandToken).length < cfg.sentenceEchoMinTokens)
|
|
111
|
+
continue;
|
|
112
|
+
const verdict = verdictFor(tokens, sentence, exact);
|
|
113
|
+
if (verdict != null && verdict.residue === '')
|
|
114
|
+
return verdict;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/** The echo in a caller final of one of the agent's recent lines (most recent first); `null`: none. */
|
|
119
|
+
function detectSelfEcho(callerText, recentAgent, cfg) {
|
|
120
|
+
const tokens = tokenize(callerText, cfg.expandToken);
|
|
121
|
+
let best = null;
|
|
122
|
+
if (tokens.length >= cfg.minEchoTokens) {
|
|
123
|
+
for (const agentText of recentAgent.slice(0, cfg.lookback)) {
|
|
124
|
+
const verdict = verdictFor(tokens, agentText, cfg);
|
|
125
|
+
if (verdict != null && (best == null || verdict.echoTokens > best.echoTokens))
|
|
126
|
+
best = verdict;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (best != null)
|
|
130
|
+
return best;
|
|
131
|
+
// A reflection this short is speech unless it reproduces a whole sentence of the last line exactly.
|
|
132
|
+
const previous = recentAgent[0];
|
|
133
|
+
return previous == null ? null : sentenceVerdictFor(tokens, previous, cfg);
|
|
134
|
+
}
|
|
135
|
+
exports.detectSelfEcho = detectSelfEcho;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type OperatorFunction } from 'rxjs';
|
|
2
|
+
/** `text` with `tag` in front of every sentence. */
|
|
3
|
+
export declare function tagText(text: string, tag: string): string;
|
|
4
|
+
/** Streaming `tagText`: one tagged sentence as soon as it is complete, the rest when the stream ends. */
|
|
5
|
+
export declare function tagSentences(tag: string): OperatorFunction<string, string>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tagSentences = exports.tagText = void 0;
|
|
4
|
+
// A delivery tag in front of every sentence of a spoken line (`voice.tts.sentenceTag`): each sentence is synthesized
|
|
5
|
+
// alone, so each needs the tag. Pure text functions and a streaming operator; no words of any language.
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
/** Sentence end: terminal punctuation and a space; a closing `...` / `…` stays with the sentence before it. */
|
|
8
|
+
const SENTENCE_END = /[.!?…]+\s+(?!(?:\.{3}|…)\s*$)/;
|
|
9
|
+
/** `buf` as its complete sentences (each with its trailing space) and the unfinished rest. */
|
|
10
|
+
function cut(buf) {
|
|
11
|
+
const done = [];
|
|
12
|
+
for (let m = SENTENCE_END.exec(buf); m; m = SENTENCE_END.exec(buf)) {
|
|
13
|
+
const end = m.index + m[0].length;
|
|
14
|
+
done.push(buf.slice(0, end));
|
|
15
|
+
buf = buf.slice(end);
|
|
16
|
+
}
|
|
17
|
+
return [done, buf];
|
|
18
|
+
}
|
|
19
|
+
/** `text` with `tag` in front of every sentence. */
|
|
20
|
+
function tagText(text, tag) {
|
|
21
|
+
const [done, rest] = cut(text);
|
|
22
|
+
return [...done, rest].filter((s) => s.trim()).map((s) => `${tag} ${s}`).join('');
|
|
23
|
+
}
|
|
24
|
+
exports.tagText = tagText;
|
|
25
|
+
/** Streaming `tagText`: one tagged sentence as soon as it is complete, the rest when the stream ends. */
|
|
26
|
+
function tagSentences(tag) {
|
|
27
|
+
return (src$) => new rxjs_1.Observable((sub) => {
|
|
28
|
+
let buf = '';
|
|
29
|
+
const emit = (s) => { if (s.trim())
|
|
30
|
+
sub.next(`${tag} ${s}`); };
|
|
31
|
+
return src$.subscribe({
|
|
32
|
+
next: (chunk) => {
|
|
33
|
+
const [done, rest] = cut(buf + chunk);
|
|
34
|
+
buf = rest;
|
|
35
|
+
done.forEach(emit);
|
|
36
|
+
},
|
|
37
|
+
error: (err) => sub.error(err),
|
|
38
|
+
complete: () => { emit(buf); sub.complete(); },
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.tagSentences = tagSentences;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE MODEL'S NOTES MUST NEVER REACH THE SPEAKER.
|
|
3
|
+
*
|
|
4
|
+
* Every character of an LLM reply streams straight into `say()`, so whatever the model writes is
|
|
5
|
+
* synthesized and played to the caller. With reasoning switched off the model still plans — and
|
|
6
|
+
* now and then the plan comes out as the reply itself: «We need respond Kazakh, after two
|
|
7
|
+
* objections close inform_close_2 because debt stated…» was read aloud to a contact person on
|
|
8
|
+
* call 615f2709, and 35ba6bdd ended on the same kind of line. Eight such replies went out in the
|
|
9
|
+
* 09-25…09-29 batch, plus one that echoed an internal `<<< customer_silent; …` marker verbatim.
|
|
10
|
+
*
|
|
11
|
+
* The filter sits between the LLM stream and TTS and works a SENTENCE at a time, because that is
|
|
12
|
+
* the unit the leak comes in: a whole English paragraph, or English sentences after a Kazakh one.
|
|
13
|
+
* Each sentence is held only until it can be judged — its first {@link JUDGE_LETTERS} letters, or
|
|
14
|
+
* its end, whichever comes first — then either passed through (and the rest of it streamed without
|
|
15
|
+
* buffering) or dropped whole. A Russian/Kazakh reply is therefore delayed by a few characters at
|
|
16
|
+
* the start of each sentence and by nothing else.
|
|
17
|
+
*
|
|
18
|
+
* A sentence is a leak when it
|
|
19
|
+
* - carries an internal marker (`<<<`) or a snake_case identifier (`inform_close_2`,
|
|
20
|
+
* `required_action`) — phrase names and marker fields are never speech; or
|
|
21
|
+
* - is predominantly Latin script once the words that legitimately are Latin have been set aside:
|
|
22
|
+
* the brand names, and the names on THIS call's campaign row, which some clients ship in Latin
|
|
23
|
+
* for some customers («SHODIYORBEK OLIMJONOV» is a real contact name, not a leak).
|
|
24
|
+
*
|
|
25
|
+
* Agent-agnostic: the allowed words come in through {@link SpeechLeakFilterConfig}.
|
|
26
|
+
*/
|
|
27
|
+
import { type OperatorFunction } from 'rxjs';
|
|
28
|
+
export interface SpeechLeakFilterConfig {
|
|
29
|
+
/**
|
|
30
|
+
* Latin-script words that are legitimate speech on this call, compared case-insensitively:
|
|
31
|
+
* brand names and the words of the names on the campaign row.
|
|
32
|
+
*/
|
|
33
|
+
readonly allowedLatinWords: readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* A sentence is a leak when its Latin letters are more than this share of its Latin and Cyrillic letters together
|
|
36
|
+
* (default 0.5: more Latin than Cyrillic).
|
|
37
|
+
*/
|
|
38
|
+
readonly maxForeignShare?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether one whole sentence is model-internal text rather than speech. Exported for tests and
|
|
42
|
+
* for callers that already hold a complete reply.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isLeakedSentence(sentence: string, config: SpeechLeakFilterConfig): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Streaming filter for one reply. Feed chunks to {@link push}, emit what it returns, and call
|
|
47
|
+
* {@link flush} when the stream completes. {@link suppressed} lists what was held back.
|
|
48
|
+
*/
|
|
49
|
+
export declare class SpeechLeakFilter {
|
|
50
|
+
private readonly allowed;
|
|
51
|
+
private readonly maxShare;
|
|
52
|
+
/** Text of the current sentence not yet emitted or dropped. */
|
|
53
|
+
private pending;
|
|
54
|
+
/** How the rest of the current sentence is handled once it has been judged. */
|
|
55
|
+
private mode;
|
|
56
|
+
private readonly dropped;
|
|
57
|
+
private droppedCurrent;
|
|
58
|
+
constructor(config: SpeechLeakFilterConfig);
|
|
59
|
+
/** Sentences (or sentence fragments) withheld from TTS, in order. */
|
|
60
|
+
get suppressed(): readonly string[];
|
|
61
|
+
push(chunk: string): string;
|
|
62
|
+
/** The stream completed: whatever is left is the last sentence. */
|
|
63
|
+
flush(): string;
|
|
64
|
+
/** No boundary yet: judge on the prefix once there is enough of it, else keep holding. */
|
|
65
|
+
private handlePartial;
|
|
66
|
+
/** A complete sentence arrived — in whatever mode its start was judged in. */
|
|
67
|
+
private finishSentence;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The filter as an operator over a reply stream: emits only what may be spoken, and the held-back
|
|
71
|
+
* tail of the last sentence when the source completes. Unsubscribing (a superseded turn) drops
|
|
72
|
+
* whatever was still held — it was never going to be spoken anyway.
|
|
73
|
+
*/
|
|
74
|
+
export declare function filterSpeechLeaks(filter: SpeechLeakFilter): OperatorFunction<string, string>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// █████
|
|
3
|
+
// ███
|
|
4
|
+
// █████ ████████ ██████ ██████ ███████ ████ ██████ ██████ █████ ████
|
|
5
|
+
// ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
|
|
6
|
+
// █████ ███ ███ ███████ ███████ ███ ███ ███ ███████ ███████ ██████
|
|
7
|
+
// ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
|
|
8
|
+
// ██████ ███████ ██████ ██████ ████████ █████ ██████ ████████ ████ █████
|
|
9
|
+
// ███
|
|
10
|
+
// █████
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.filterSpeechLeaks = exports.SpeechLeakFilter = exports.isLeakedSentence = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* THE MODEL'S NOTES MUST NEVER REACH THE SPEAKER.
|
|
15
|
+
*
|
|
16
|
+
* Every character of an LLM reply streams straight into `say()`, so whatever the model writes is
|
|
17
|
+
* synthesized and played to the caller. With reasoning switched off the model still plans — and
|
|
18
|
+
* now and then the plan comes out as the reply itself: «We need respond Kazakh, after two
|
|
19
|
+
* objections close inform_close_2 because debt stated…» was read aloud to a contact person on
|
|
20
|
+
* call 615f2709, and 35ba6bdd ended on the same kind of line. Eight such replies went out in the
|
|
21
|
+
* 09-25…09-29 batch, plus one that echoed an internal `<<< customer_silent; …` marker verbatim.
|
|
22
|
+
*
|
|
23
|
+
* The filter sits between the LLM stream and TTS and works a SENTENCE at a time, because that is
|
|
24
|
+
* the unit the leak comes in: a whole English paragraph, or English sentences after a Kazakh one.
|
|
25
|
+
* Each sentence is held only until it can be judged — its first {@link JUDGE_LETTERS} letters, or
|
|
26
|
+
* its end, whichever comes first — then either passed through (and the rest of it streamed without
|
|
27
|
+
* buffering) or dropped whole. A Russian/Kazakh reply is therefore delayed by a few characters at
|
|
28
|
+
* the start of each sentence and by nothing else.
|
|
29
|
+
*
|
|
30
|
+
* A sentence is a leak when it
|
|
31
|
+
* - carries an internal marker (`<<<`) or a snake_case identifier (`inform_close_2`,
|
|
32
|
+
* `required_action`) — phrase names and marker fields are never speech; or
|
|
33
|
+
* - is predominantly Latin script once the words that legitimately are Latin have been set aside:
|
|
34
|
+
* the brand names, and the names on THIS call's campaign row, which some clients ship in Latin
|
|
35
|
+
* for some customers («SHODIYORBEK OLIMJONOV» is a real contact name, not a leak).
|
|
36
|
+
*
|
|
37
|
+
* Agent-agnostic: the allowed words come in through {@link SpeechLeakFilterConfig}.
|
|
38
|
+
*/
|
|
39
|
+
const rxjs_1 = require("rxjs");
|
|
40
|
+
/** Letters a sentence must show before it is judged on its prefix alone. */
|
|
41
|
+
const JUDGE_LETTERS = 12;
|
|
42
|
+
/** Fewer Latin letters than this never make a leak on their own — «OK», an initial. */
|
|
43
|
+
const MIN_LEAK_LATIN_LETTERS = 4;
|
|
44
|
+
/** Internal marker or snake_case identifier — never speech, whatever the script around it. */
|
|
45
|
+
const INTERNAL_TOKEN = /<<<|[A-Za-z][A-Za-z0-9]*_[A-Za-z0-9_]+/;
|
|
46
|
+
/** Voice-tag markup (`[pause]`) — stripped before counting, as the drain floor does. */
|
|
47
|
+
const BRACKET_TAG = /\[[^\]]*\]/g;
|
|
48
|
+
const LATIN_LETTER = /[A-Za-z]/g;
|
|
49
|
+
const CYRILLIC_LETTER = /\p{Script=Cyrillic}/gu;
|
|
50
|
+
/** Sentence-final punctuation; a boundary also needs the whitespace after it (see below). */
|
|
51
|
+
const SENTENCE_END = /[.!?…]/;
|
|
52
|
+
function countMatches(text, re) {
|
|
53
|
+
return (text.match(re) ?? []).length;
|
|
54
|
+
}
|
|
55
|
+
function countScripts(text, allowed) {
|
|
56
|
+
const internal = INTERNAL_TOKEN.test(text);
|
|
57
|
+
let latin = 0;
|
|
58
|
+
let cyrillic = 0;
|
|
59
|
+
for (const token of text.replace(BRACKET_TAG, ' ').split(/[^\p{L}\p{N}]+/u)) {
|
|
60
|
+
if (!token || allowed.has(token.toLowerCase()))
|
|
61
|
+
continue;
|
|
62
|
+
latin += countMatches(token, LATIN_LETTER);
|
|
63
|
+
cyrillic += countMatches(token, CYRILLIC_LETTER);
|
|
64
|
+
}
|
|
65
|
+
return { latin, cyrillic, internal };
|
|
66
|
+
}
|
|
67
|
+
function isLeak(c, maxShare) {
|
|
68
|
+
if (c.internal)
|
|
69
|
+
return true;
|
|
70
|
+
if (c.latin < MIN_LEAK_LATIN_LETTERS)
|
|
71
|
+
return false;
|
|
72
|
+
return maxShare == null ? c.latin > c.cyrillic : c.latin > maxShare * (c.latin + c.cyrillic);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether one whole sentence is model-internal text rather than speech. Exported for tests and
|
|
76
|
+
* for callers that already hold a complete reply.
|
|
77
|
+
*/
|
|
78
|
+
function isLeakedSentence(sentence, config) {
|
|
79
|
+
return isLeak(countScripts(sentence, allowedSet(config)), config.maxForeignShare);
|
|
80
|
+
}
|
|
81
|
+
exports.isLeakedSentence = isLeakedSentence;
|
|
82
|
+
function allowedSet(config) {
|
|
83
|
+
return new Set(config.allowedLatinWords.map((w) => w.toLowerCase()));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Index just past the first sentence boundary in `text`, or `-1`. A boundary is sentence-final
|
|
87
|
+
* punctuation (plus any closing quotes) FOLLOWED BY WHITESPACE, or a newline: the whitespace is
|
|
88
|
+
* what proves the sentence is over — «brand.kz» and «0.5» are not boundaries, and a `.` at the
|
|
89
|
+
* very end of a chunk may still be followed by more of the same token in the next one.
|
|
90
|
+
*/
|
|
91
|
+
function sentenceBoundary(text) {
|
|
92
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
93
|
+
const ch = text[i];
|
|
94
|
+
if (ch === '\n')
|
|
95
|
+
return i + 1;
|
|
96
|
+
if (!SENTENCE_END.test(ch))
|
|
97
|
+
continue;
|
|
98
|
+
let j = i + 1;
|
|
99
|
+
while (j < text.length && /[.!?…"»)']/.test(text[j]))
|
|
100
|
+
j += 1;
|
|
101
|
+
if (j < text.length && /\s/.test(text[j])) {
|
|
102
|
+
while (j < text.length && /\s/.test(text[j]))
|
|
103
|
+
j += 1;
|
|
104
|
+
return j;
|
|
105
|
+
}
|
|
106
|
+
i = j - 1;
|
|
107
|
+
}
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Streaming filter for one reply. Feed chunks to {@link push}, emit what it returns, and call
|
|
112
|
+
* {@link flush} when the stream completes. {@link suppressed} lists what was held back.
|
|
113
|
+
*/
|
|
114
|
+
class SpeechLeakFilter {
|
|
115
|
+
constructor(config) {
|
|
116
|
+
/** Text of the current sentence not yet emitted or dropped. */
|
|
117
|
+
this.pending = '';
|
|
118
|
+
/** How the rest of the current sentence is handled once it has been judged. */
|
|
119
|
+
this.mode = 'judging';
|
|
120
|
+
this.dropped = [];
|
|
121
|
+
this.droppedCurrent = '';
|
|
122
|
+
this.allowed = allowedSet(config);
|
|
123
|
+
this.maxShare = config.maxForeignShare;
|
|
124
|
+
}
|
|
125
|
+
/** Sentences (or sentence fragments) withheld from TTS, in order. */
|
|
126
|
+
get suppressed() {
|
|
127
|
+
return this.dropped;
|
|
128
|
+
}
|
|
129
|
+
push(chunk) {
|
|
130
|
+
this.pending += chunk;
|
|
131
|
+
let out = '';
|
|
132
|
+
for (;;) {
|
|
133
|
+
const end = sentenceBoundary(this.pending);
|
|
134
|
+
if (end < 0) {
|
|
135
|
+
out += this.handlePartial();
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
const sentence = this.pending.slice(0, end);
|
|
139
|
+
this.pending = this.pending.slice(end);
|
|
140
|
+
out += this.finishSentence(sentence);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** The stream completed: whatever is left is the last sentence. */
|
|
144
|
+
flush() {
|
|
145
|
+
const rest = this.pending;
|
|
146
|
+
this.pending = '';
|
|
147
|
+
// A sentence already being dropped has nothing left in `pending` — its text is in
|
|
148
|
+
// `droppedCurrent` — and still has to be closed off and recorded.
|
|
149
|
+
return rest || this.mode !== 'judging' ? this.finishSentence(rest) : '';
|
|
150
|
+
}
|
|
151
|
+
/** No boundary yet: judge on the prefix once there is enough of it, else keep holding. */
|
|
152
|
+
handlePartial() {
|
|
153
|
+
if (this.mode === 'passing') {
|
|
154
|
+
const text = this.pending;
|
|
155
|
+
this.pending = '';
|
|
156
|
+
return text;
|
|
157
|
+
}
|
|
158
|
+
if (this.mode === 'dropping') {
|
|
159
|
+
this.droppedCurrent += this.pending;
|
|
160
|
+
this.pending = '';
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
const counts = countScripts(this.pending, this.allowed);
|
|
164
|
+
if (counts.internal) {
|
|
165
|
+
this.mode = 'dropping';
|
|
166
|
+
return this.handlePartial();
|
|
167
|
+
}
|
|
168
|
+
if (counts.latin + counts.cyrillic < JUDGE_LETTERS)
|
|
169
|
+
return '';
|
|
170
|
+
this.mode = isLeak(counts, this.maxShare) ? 'dropping' : 'passing';
|
|
171
|
+
return this.handlePartial();
|
|
172
|
+
}
|
|
173
|
+
/** A complete sentence arrived — in whatever mode its start was judged in. */
|
|
174
|
+
finishSentence(sentence) {
|
|
175
|
+
const mode = this.mode;
|
|
176
|
+
this.mode = 'judging';
|
|
177
|
+
if (mode === 'passing')
|
|
178
|
+
return sentence;
|
|
179
|
+
if (mode === 'dropping') {
|
|
180
|
+
this.dropped.push((this.droppedCurrent + sentence).trim());
|
|
181
|
+
this.droppedCurrent = '';
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
184
|
+
if (isLeak(countScripts(sentence, this.allowed), this.maxShare)) {
|
|
185
|
+
this.dropped.push(sentence.trim());
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
return sentence;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.SpeechLeakFilter = SpeechLeakFilter;
|
|
192
|
+
/**
|
|
193
|
+
* The filter as an operator over a reply stream: emits only what may be spoken, and the held-back
|
|
194
|
+
* tail of the last sentence when the source completes. Unsubscribing (a superseded turn) drops
|
|
195
|
+
* whatever was still held — it was never going to be spoken anyway.
|
|
196
|
+
*/
|
|
197
|
+
function filterSpeechLeaks(filter) {
|
|
198
|
+
return (source) => new rxjs_1.Observable((subscriber) => {
|
|
199
|
+
const inner = source.subscribe({
|
|
200
|
+
next: (chunk) => {
|
|
201
|
+
const text = filter.push(chunk);
|
|
202
|
+
if (text)
|
|
203
|
+
subscriber.next(text);
|
|
204
|
+
},
|
|
205
|
+
error: (err) => subscriber.error(err),
|
|
206
|
+
complete: () => {
|
|
207
|
+
const text = filter.flush();
|
|
208
|
+
if (text)
|
|
209
|
+
subscriber.next(text);
|
|
210
|
+
subscriber.complete();
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
return () => inner.unsubscribe();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
exports.filterSpeechLeaks = filterSpeechLeaks;
|