@voctiv/agent-runtime 0.2.2 → 0.4.1
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 +53 -20
- package/bin/voctiv-agent-check.js +98 -0
- package/dist/barge-in/barge-in-module.d.ts +0 -1
- package/dist/barge-in/barge-in-module.js +0 -1
- package/dist/barge-in/barge-in-service.d.ts +1 -1
- package/dist/barge-in/barge-in-service.js +33 -2
- package/dist/barge-in/barge-in-strategy.d.ts +11 -9
- package/dist/barge-in/barge-in-strategy.js +39 -23
- package/dist/barge-in/echo-cancellation.d.ts +0 -1
- package/dist/barge-in/echo-cancellation.js +0 -1
- package/dist/barge-in/echo.d.ts +0 -1
- package/dist/barge-in/echo.js +0 -1
- package/dist/barge-in/lexicon.d.ts +0 -1
- package/dist/barge-in/lexicon.js +0 -1
- package/dist/barge-in/speech-ledger.d.ts +0 -2
- package/dist/barge-in/speech-ledger.js +3 -4
- package/dist/barge-in/word-classifier.d.ts +0 -1
- package/dist/barge-in/word-classifier.js +0 -1
- package/dist/call/asr-usage.d.ts +53 -0
- package/dist/call/asr-usage.js +42 -0
- package/dist/call/async.d.ts +2 -0
- package/dist/call/async.js +14 -0
- package/dist/call/env.d.ts +88 -0
- package/dist/call/env.js +294 -0
- package/dist/call/extraction/core.d.ts +99 -0
- package/dist/call/extraction/core.js +259 -0
- package/dist/call/extraction/defaults.d.ts +10 -0
- package/dist/call/extraction/defaults.js +25 -0
- package/dist/call/extraction/index.d.ts +7 -0
- package/dist/call/extraction/index.js +24 -0
- package/dist/call/extraction/orchestrator.d.ts +144 -0
- package/dist/call/extraction/orchestrator.js +309 -0
- package/dist/call/failed-leg.d.ts +43 -0
- package/dist/call/failed-leg.js +77 -0
- package/dist/call/http.d.ts +94 -0
- package/dist/call/http.js +145 -0
- package/dist/call/ledger.d.ts +18 -0
- package/dist/call/ledger.js +80 -0
- package/dist/call/llm-tap.d.ts +7 -0
- package/dist/call/llm-tap.js +41 -0
- package/dist/call/logging.d.ts +16 -0
- package/dist/call/logging.js +92 -0
- package/dist/call/outbound.d.ts +144 -0
- package/dist/call/outbound.js +404 -0
- package/dist/call/output.d.ts +108 -0
- package/dist/call/output.js +77 -0
- package/dist/call/plan.d.ts +119 -0
- package/dist/call/plan.js +2 -0
- package/dist/call/recall.d.ts +115 -0
- package/dist/call/recall.js +312 -0
- package/dist/call/records.d.ts +9 -0
- package/dist/call/records.js +71 -0
- package/dist/call/report.d.ts +65 -0
- package/dist/call/report.js +263 -0
- package/dist/call/sanitize.d.ts +16 -0
- package/dist/call/sanitize.js +72 -0
- package/dist/call/sip.d.ts +111 -0
- package/dist/call/sip.js +212 -0
- package/dist/call/voicemail.d.ts +159 -0
- package/dist/call/voicemail.js +246 -0
- package/dist/core/call-disposables.d.ts +2 -2
- package/dist/core/call-disposables.js +8 -3
- package/dist/core/call-ended-budget.d.ts +11 -0
- package/dist/core/call-ended-budget.js +31 -0
- package/dist/core/container.d.ts +1 -3
- package/dist/core/container.js +9 -49
- package/dist/core/create-agent-script.d.ts +6 -1
- package/dist/core/create-agent-script.js +161 -28
- package/dist/core/decorators.d.ts +0 -1
- package/dist/core/decorators.js +0 -1
- package/dist/core/define-module.d.ts +0 -1
- package/dist/core/define-module.js +0 -1
- package/dist/core/dump-policy.d.ts +0 -1
- package/dist/core/dump-policy.js +0 -1
- package/dist/core/hooks.d.ts +15 -4
- package/dist/core/hooks.js +0 -1
- package/dist/core/media-bootstrap.d.ts +19 -4
- package/dist/core/media-bootstrap.js +53 -13
- package/dist/core/open-timeout.d.ts +12 -0
- package/dist/core/open-timeout.js +48 -0
- package/dist/core/provide-media.d.ts +0 -8
- package/dist/core/provide-media.js +1 -22
- package/dist/core/runtime-events.d.ts +28 -0
- package/dist/{llm/llm-module.js → core/runtime-events.js} +19 -16
- package/dist/core/tokens.d.ts +0 -10
- package/dist/core/tokens.js +0 -1
- package/dist/core/types.d.ts +0 -1
- package/dist/core/types.js +0 -1
- package/dist/core/version.d.ts +2 -3
- package/dist/core/version.js +2 -3
- package/dist/dialog/dialog-definition.d.ts +0 -5
- package/dist/dialog/dialog-definition.js +1 -6
- package/dist/dialog/dialog-ports.d.ts +3 -1
- package/dist/dialog/dialog-ports.js +10 -2
- package/dist/dialog/online-call-host.d.ts +26 -4
- package/dist/dialog/online-call-host.js +94 -12
- package/dist/dialog/online-call-module.d.ts +5 -11
- package/dist/dialog/online-call-module.js +4 -36
- package/dist/dialog/turn-metrics.d.ts +46 -0
- package/dist/dialog/turn-metrics.js +141 -0
- package/dist/dialog-events/active-media.d.ts +50 -2
- package/dist/dialog-events/active-media.js +146 -34
- package/dist/dialog-events/event-source.d.ts +0 -1
- package/dist/dialog-events/event-source.js +0 -1
- package/dist/dialog-events/virtual-finals-module.d.ts +0 -1
- package/dist/dialog-events/virtual-finals-module.js +0 -1
- package/dist/dialog-events/virtual-finals.d.ts +2 -1
- package/dist/dialog-events/virtual-finals.js +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +8 -26
- package/dist/lifecycle/lifecycle.d.ts +25 -3
- package/dist/lifecycle/lifecycle.js +92 -14
- package/dist/result/result-store.d.ts +0 -1
- package/dist/result/result-store.js +0 -1
- package/dist/templates/authoring.d.ts +222 -0
- package/dist/templates/authoring.js +2 -0
- package/dist/templates/builder/agent.d.ts +34 -0
- package/dist/templates/builder/agent.js +87 -0
- package/dist/templates/builder/blocks.d.ts +54 -0
- package/dist/templates/builder/blocks.js +92 -0
- package/dist/templates/builder/data-check.d.ts +2 -0
- package/dist/templates/builder/data-check.js +61 -0
- package/dist/templates/builder/draft.d.ts +73 -0
- package/dist/templates/builder/draft.js +142 -0
- package/dist/templates/builder/index.d.ts +8 -0
- package/dist/templates/builder/index.js +55 -0
- package/dist/templates/builder/presets.d.ts +34 -0
- package/dist/templates/builder/presets.js +45 -0
- package/dist/templates/builder/spec-of.d.ts +13 -0
- package/dist/templates/builder/spec-of.js +18 -0
- package/dist/templates/builder/steps.d.ts +25 -0
- package/dist/templates/builder/steps.js +27 -0
- package/dist/templates/business/adapter.d.ts +12 -0
- package/dist/templates/business/adapter.js +980 -0
- package/dist/templates/business/agent-integrations.d.ts +24 -0
- package/dist/templates/business/agent-integrations.js +233 -0
- package/dist/templates/business/extraction-rules-transcript.d.ts +158 -0
- package/dist/templates/business/extraction-rules-transcript.js +405 -0
- package/dist/templates/business/extraction-rules.d.ts +107 -0
- package/dist/templates/business/extraction-rules.js +267 -0
- package/dist/templates/business/index.d.ts +6 -0
- package/dist/{result → templates/business}/index.js +8 -2
- package/dist/templates/business/input.d.ts +56 -0
- package/dist/templates/business/input.js +299 -0
- package/dist/templates/business/integration-data.d.ts +87 -0
- package/dist/templates/business/integration-data.js +312 -0
- package/dist/templates/business/integrations.d.ts +76 -0
- package/dist/templates/business/integrations.js +535 -0
- package/dist/templates/business/legs-policy.d.ts +43 -0
- package/dist/templates/business/legs-policy.js +268 -0
- package/dist/templates/business/report-label.d.ts +7 -0
- package/dist/templates/business/report-label.js +29 -0
- package/dist/templates/business/report.d.ts +67 -0
- package/dist/templates/business/report.js +284 -0
- package/dist/templates/business/result-catalog.d.ts +142 -0
- package/dist/templates/business/result-catalog.js +208 -0
- package/dist/templates/business/result-rules.d.ts +105 -0
- package/dist/templates/business/result-rules.js +167 -0
- package/dist/templates/business/results.d.ts +73 -0
- package/dist/templates/business/results.js +183 -0
- package/dist/templates/business/rule-env.d.ts +18 -0
- package/dist/templates/business/rule-env.js +38 -0
- package/dist/templates/business/sources.d.ts +76 -0
- package/dist/templates/business/sources.js +239 -0
- package/dist/templates/business/test-presets.d.ts +10 -0
- package/dist/templates/business/test-presets.js +68 -0
- package/dist/templates/catalog-match/block.d.ts +32 -0
- package/dist/templates/catalog-match/block.js +95 -0
- package/dist/templates/catalog-match/catalog.d.ts +77 -0
- package/dist/templates/catalog-match/catalog.js +222 -0
- package/dist/templates/catalog-match/recognizer.d.ts +44 -0
- package/dist/templates/catalog-match/recognizer.js +206 -0
- package/dist/templates/catalog-match/reconcile.d.ts +4 -0
- package/dist/templates/catalog-match/reconcile.js +39 -0
- package/dist/templates/catalog-match/request.d.ts +57 -0
- package/dist/templates/catalog-match/request.js +139 -0
- package/dist/templates/catalog-match/types.d.ts +197 -0
- package/dist/templates/catalog-match/types.js +2 -0
- package/dist/templates/catalog-match/verify.d.ts +76 -0
- package/dist/templates/catalog-match/verify.js +220 -0
- package/dist/templates/decision-model/index.d.ts +52 -0
- package/dist/templates/decision-model/index.js +68 -0
- package/dist/templates/engine/asr-picks.d.ts +11 -0
- package/dist/templates/engine/asr-picks.js +44 -0
- package/dist/templates/engine/call.d.ts +104 -0
- package/dist/templates/engine/call.js +322 -0
- package/dist/templates/engine/config.d.ts +447 -0
- package/dist/templates/engine/config.js +493 -0
- package/dist/templates/engine/define.d.ts +1 -0
- package/dist/templates/engine/define.js +9 -0
- package/dist/templates/engine/dialog.d.ts +253 -0
- package/dist/templates/engine/dialog.js +167 -0
- package/dist/templates/engine/echo-numbers.d.ts +7 -0
- package/dist/templates/engine/echo-numbers.js +19 -0
- package/dist/templates/engine/expand.d.ts +6 -0
- package/dist/templates/engine/expand.js +125 -0
- package/dist/templates/engine/filters.d.ts +81 -0
- package/dist/templates/engine/filters.js +654 -0
- package/dist/templates/engine/hook-state.d.ts +18 -0
- package/dist/templates/engine/hook-state.js +100 -0
- package/dist/templates/engine/hooks.d.ts +51 -0
- package/dist/templates/engine/hooks.js +310 -0
- package/dist/templates/engine/index.d.ts +13 -0
- package/dist/templates/engine/index.js +30 -0
- package/dist/templates/engine/language-vars.d.ts +6 -0
- package/dist/templates/engine/language-vars.js +40 -0
- package/dist/templates/engine/language.d.ts +32 -0
- package/dist/templates/engine/language.js +155 -0
- package/dist/templates/engine/lookup.d.ts +20 -0
- package/dist/templates/engine/lookup.js +52 -0
- package/dist/templates/engine/match.d.ts +48 -0
- package/dist/templates/engine/match.js +253 -0
- package/dist/templates/engine/media.d.ts +428 -0
- package/dist/templates/engine/media.js +1240 -0
- package/dist/templates/engine/script.d.ts +11 -0
- package/dist/templates/engine/script.js +69 -0
- package/dist/templates/engine/turns/actions.d.ts +5 -0
- package/dist/templates/engine/turns/actions.js +128 -0
- package/dist/templates/engine/turns/carry.d.ts +15 -0
- package/dist/templates/engine/turns/carry.js +74 -0
- package/dist/templates/engine/turns/choices-offers.d.ts +21 -0
- package/dist/templates/engine/turns/choices-offers.js +143 -0
- package/dist/templates/engine/turns/choices.d.ts +22 -0
- package/dist/templates/engine/turns/choices.js +141 -0
- package/dist/templates/engine/turns/closing-guard.d.ts +73 -0
- package/dist/templates/engine/turns/closing-guard.js +162 -0
- package/dist/templates/engine/turns/closing.d.ts +10 -0
- package/dist/templates/engine/turns/closing.js +82 -0
- package/dist/templates/engine/turns/compile-forms.d.ts +24 -0
- package/dist/templates/engine/turns/compile-forms.js +68 -0
- package/dist/templates/engine/turns/context.d.ts +96 -0
- package/dist/templates/engine/turns/context.js +158 -0
- package/dist/templates/engine/turns/events.d.ts +409 -0
- package/dist/templates/engine/turns/events.js +5 -0
- package/dist/templates/engine/turns/hook-forms.d.ts +62 -0
- package/dist/templates/engine/turns/hook-forms.js +79 -0
- package/dist/templates/engine/turns/ladders.d.ts +42 -0
- package/dist/templates/engine/turns/ladders.js +119 -0
- package/dist/templates/engine/turns/language.d.ts +8 -0
- package/dist/templates/engine/turns/language.js +121 -0
- package/dist/templates/engine/turns/notes-dates.d.ts +9 -0
- package/dist/templates/engine/turns/notes-dates.js +42 -0
- package/dist/templates/engine/turns/notes-detect.d.ts +13 -0
- package/dist/templates/engine/turns/notes-detect.js +36 -0
- package/dist/templates/engine/turns/notes.d.ts +27 -0
- package/dist/templates/engine/turns/notes.js +176 -0
- package/dist/templates/engine/turns/opening.d.ts +34 -0
- package/dist/templates/engine/turns/opening.js +306 -0
- package/dist/templates/engine/turns/overtalk.d.ts +21 -0
- package/dist/templates/engine/turns/overtalk.js +247 -0
- package/dist/templates/engine/turns/pending.d.ts +9 -0
- package/dist/templates/engine/turns/pending.js +88 -0
- package/dist/templates/engine/turns/reply-rules.d.ts +184 -0
- package/dist/templates/engine/turns/reply-rules.js +335 -0
- package/dist/templates/engine/turns/rules.d.ts +20 -0
- package/dist/templates/engine/turns/rules.js +144 -0
- package/dist/templates/engine/turns/silence.d.ts +7 -0
- package/dist/templates/engine/turns/silence.js +127 -0
- package/dist/templates/engine/turns/state-spec.d.ts +305 -0
- package/dist/templates/engine/turns/state-spec.js +2 -0
- package/dist/templates/engine/turns/state.d.ts +38 -0
- package/dist/templates/engine/turns/state.js +101 -0
- package/dist/templates/engine/turns/tracking.d.ts +50 -0
- package/dist/templates/engine/turns/tracking.js +184 -0
- package/dist/templates/engine/turns/transfer.d.ts +19 -0
- package/dist/templates/engine/turns/transfer.js +93 -0
- package/dist/templates/engine/turns/turn.d.ts +17 -0
- package/dist/templates/engine/turns/turn.js +363 -0
- package/dist/templates/engine/turns/voicemail.d.ts +8 -0
- package/dist/templates/engine/turns/voicemail.js +101 -0
- package/dist/templates/engine/variants.d.ts +36 -0
- package/dist/templates/engine/variants.js +159 -0
- package/dist/templates/engine/voice-dialog.d.ts +24 -0
- package/dist/templates/engine/voice-dialog.js +157 -0
- package/dist/templates/engine/voice.d.ts +174 -0
- package/dist/templates/engine/voice.js +1337 -0
- package/dist/templates/expr/caller-after.d.ts +20 -0
- package/dist/templates/expr/caller-after.js +53 -0
- package/dist/templates/expr/check.d.ts +19 -0
- package/dist/templates/expr/check.js +314 -0
- package/dist/templates/expr/compiled.d.ts +8 -0
- package/dist/templates/expr/compiled.js +8 -0
- package/dist/templates/expr/context.d.ts +28 -0
- package/dist/templates/expr/context.js +55 -0
- package/dist/templates/expr/day-table.d.ts +4 -0
- package/dist/templates/expr/day-table.js +80 -0
- package/dist/templates/expr/evaluate.d.ts +26 -0
- package/dist/templates/expr/evaluate.js +885 -0
- package/dist/templates/expr/facts.d.ts +7 -0
- package/dist/templates/expr/facts.js +81 -0
- package/dist/templates/expr/index.d.ts +4 -0
- package/dist/templates/expr/index.js +11 -0
- package/dist/templates/expr/line-tally.d.ts +64 -0
- package/dist/templates/expr/line-tally.js +88 -0
- package/dist/templates/expr/matchers-state.d.ts +23 -0
- package/dist/templates/expr/matchers-state.js +37 -0
- package/dist/templates/expr/matchers.d.ts +12 -0
- package/dist/templates/expr/matchers.js +99 -0
- package/dist/templates/expr/readers.d.ts +14 -0
- package/dist/templates/expr/readers.js +351 -0
- package/dist/templates/expr/slots.d.ts +14 -0
- package/dist/templates/expr/slots.js +678 -0
- package/dist/templates/expr/template.d.ts +12 -0
- package/dist/templates/expr/template.js +76 -0
- package/dist/templates/expr/test-call.d.ts +8 -0
- package/dist/templates/expr/test-call.js +32 -0
- package/dist/templates/expr/transcript.d.ts +36 -0
- package/dist/templates/expr/transcript.js +394 -0
- package/dist/templates/expr/types.d.ts +1011 -0
- package/dist/templates/expr/types.js +2 -0
- package/dist/templates/expr/values.d.ts +42 -0
- package/dist/templates/expr/values.js +166 -0
- package/dist/templates/expr/voice-ops.d.ts +26 -0
- package/dist/templates/expr/voice-ops.js +85 -0
- package/dist/templates/helpers/decision.d.ts +55 -0
- package/dist/templates/helpers/decision.js +83 -0
- package/dist/templates/helpers/fuzzy.d.ts +9 -0
- package/dist/templates/helpers/fuzzy.js +44 -0
- package/dist/templates/helpers/index.d.ts +6 -0
- package/dist/templates/helpers/index.js +35 -0
- package/dist/templates/index.d.ts +9 -0
- package/dist/templates/index.js +68 -0
- package/dist/templates/integration-forms.d.ts +252 -0
- package/dist/templates/integration-forms.js +2 -0
- package/dist/templates/knowledge/block.d.ts +44 -0
- package/dist/templates/knowledge/block.js +199 -0
- package/dist/templates/knowledge/dense.d.ts +87 -0
- package/dist/templates/knowledge/dense.js +158 -0
- package/dist/templates/knowledge/flow.d.ts +328 -0
- package/dist/templates/knowledge/flow.js +509 -0
- package/dist/templates/knowledge/retriever.d.ts +75 -0
- package/dist/templates/knowledge/retriever.js +204 -0
- package/dist/templates/knowledge/service.d.ts +77 -0
- package/dist/templates/knowledge/service.js +316 -0
- package/dist/templates/knowledge/text.d.ts +31 -0
- package/dist/templates/knowledge/text.js +66 -0
- package/dist/templates/knowledge/types.d.ts +120 -0
- package/dist/templates/knowledge/types.js +2 -0
- package/dist/templates/locale.d.ts +259 -0
- package/dist/templates/locale.js +4 -0
- package/dist/templates/locales/en-lexicons.d.ts +9 -0
- package/dist/templates/locales/en-lexicons.js +101 -0
- package/dist/templates/locales/en.d.ts +132 -0
- package/dist/templates/locales/en.js +261 -0
- package/dist/templates/locales/es.d.ts +65 -0
- package/dist/templates/locales/es.js +208 -0
- package/dist/templates/locales/hi.d.ts +47 -0
- package/dist/templates/locales/hi.js +235 -0
- package/dist/templates/locales/id.d.ts +43 -0
- package/dist/templates/locales/id.js +127 -0
- package/dist/templates/locales/index.d.ts +34 -0
- package/dist/templates/locales/index.js +112 -0
- package/dist/templates/locales/kk-lexicons.d.ts +22 -0
- package/dist/templates/locales/kk-lexicons.js +89 -0
- package/dist/templates/locales/kk.d.ts +140 -0
- package/dist/templates/locales/kk.js +306 -0
- package/dist/templates/locales/kn.d.ts +29 -0
- package/dist/templates/locales/kn.js +22 -0
- package/dist/templates/locales/listen-only.d.ts +15 -0
- package/dist/templates/locales/listen-only.js +27 -0
- package/dist/templates/locales/ms-lexicons.d.ts +13 -0
- package/dist/templates/locales/ms-lexicons.js +113 -0
- package/dist/templates/locales/ms.d.ts +76 -0
- package/dist/templates/locales/ms.js +179 -0
- package/dist/templates/locales/parse.d.ts +86 -0
- package/dist/templates/locales/parse.js +461 -0
- package/dist/templates/locales/ru-lexicons.d.ts +27 -0
- package/dist/templates/locales/ru-lexicons.js +127 -0
- package/dist/templates/locales/ru-stem.d.ts +2 -0
- package/dist/templates/locales/ru-stem.js +53 -0
- package/dist/templates/locales/ru.d.ts +143 -0
- package/dist/templates/locales/ru.js +387 -0
- package/dist/templates/locales/shared.d.ts +122 -0
- package/dist/templates/locales/shared.js +318 -0
- package/dist/templates/locales/ta.d.ts +29 -0
- package/dist/templates/locales/ta.js +22 -0
- package/dist/templates/locales/te.d.ts +29 -0
- package/dist/templates/locales/te.js +22 -0
- package/dist/templates/locales/tl-lexicons.d.ts +2 -0
- package/dist/templates/locales/tl-lexicons.js +230 -0
- package/dist/templates/locales/tl.d.ts +59 -0
- package/dist/templates/locales/tl.js +82 -0
- package/dist/templates/locales/vi.d.ts +59 -0
- package/dist/templates/locales/vi.js +160 -0
- package/dist/templates/locales/word-regex.d.ts +13 -0
- package/dist/templates/locales/word-regex.js +43 -0
- package/dist/templates/locales/words-kk.d.ts +2 -0
- package/dist/templates/locales/words-kk.js +23 -0
- package/dist/templates/locales/words-ru.d.ts +4 -0
- package/dist/templates/locales/words-ru.js +92 -0
- package/dist/templates/spec.d.ts +2856 -0
- package/dist/templates/spec.js +2 -0
- package/dist/testing/fake-channel.d.ts +0 -1
- package/dist/testing/fake-channel.js +0 -1
- package/dist/testing/index.d.ts +24 -1
- package/dist/testing/index.js +117 -2
- package/dist/voice/call-voice.d.ts +581 -0
- package/dist/voice/call-voice.js +1399 -0
- package/dist/voice/intent-interrupt.d.ts +32 -0
- package/dist/voice/intent-interrupt.js +91 -0
- package/dist/voice/self-echo.d.ts +28 -0
- package/dist/voice/self-echo.js +135 -0
- package/dist/voice/sentence-tag.d.ts +5 -0
- package/dist/voice/sentence-tag.js +42 -0
- package/dist/voice/speech-leak.d.ts +74 -0
- package/dist/voice/speech-leak.js +216 -0
- package/dist/voice/transfer.d.ts +90 -0
- package/dist/voice/transfer.js +331 -0
- package/dist/voice/turn-timing.d.ts +293 -0
- package/dist/voice/turn-timing.js +567 -0
- package/docs/README.md +3 -6
- package/docs/framework/README.md +6 -10
- package/docs/framework/architecture.md +2 -2
- package/docs/framework/container-and-di.md +1 -2
- package/docs/framework/invariants.md +6 -6
- package/docs/framework/package-layout.md +17 -23
- package/docs/framework/testing.md +8 -6
- package/package.json +22 -55
- package/skill/AGENTS.md +43 -0
- package/skill/AGENTS.recommend.md +27 -0
- package/skill/SKILL.md +100 -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/library-dev.md +84 -0
- package/skill/references/locales.md +149 -0
- package/skill/references/migration.md +133 -0
- package/skill/references/new-agent.md +170 -0
- package/skill/references/porting.md +165 -0
- package/templates/agent/README.md +55 -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,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripLettersExcept = exports.evalReplyCondition = exports.dominantScript = exports.replyRuleFilter = void 0;
|
|
4
|
+
const evaluate_1 = require("../../expr/evaluate");
|
|
5
|
+
const transcript_1 = require("../../expr/transcript");
|
|
6
|
+
const values_1 = require("../../expr/values");
|
|
7
|
+
const match_1 = require("../match");
|
|
8
|
+
/** The reply filter of one rule set. */
|
|
9
|
+
function replyRuleFilter(set, path, c) {
|
|
10
|
+
if ('sentenceRules' in set)
|
|
11
|
+
return { filter: 'sentences', fn: sentenceRulesHook(set.sentenceRules, path, c) };
|
|
12
|
+
if ('unclearLadder' in set)
|
|
13
|
+
return { filter: 'stream', fn: unclearLadderHook(set.unclearLadder, path, c) };
|
|
14
|
+
if ('insertAfterFirst' in set)
|
|
15
|
+
return { filter: 'stream', fn: insertAfterFirstHook(set.insertAfterFirst, path, c) };
|
|
16
|
+
if ('asClip' in set)
|
|
17
|
+
return { filter: 'stream', fn: asClipHook(set.asClip, path, c) };
|
|
18
|
+
if ('stripLetters' in set) {
|
|
19
|
+
const strip = stripLettersExcept(set.stripLetters.keep);
|
|
20
|
+
return { filter: 'hook', fn: (_call, input) => strip(String(input ?? '')) };
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`[templates/engine] ${path}: unknown reply rule set ${JSON.stringify(Object.keys(set))}`);
|
|
23
|
+
}
|
|
24
|
+
exports.replyRuleFilter = replyRuleFilter;
|
|
25
|
+
const LETTER = /\p{L}/gu;
|
|
26
|
+
/** The sentence split of earlier agent lines. */
|
|
27
|
+
const EARLIER_SPLIT = /(?<=[.!?।…])\s+/u;
|
|
28
|
+
function countOf(re, text) {
|
|
29
|
+
re.lastIndex = 0;
|
|
30
|
+
let n = 0;
|
|
31
|
+
while (re.exec(text) != null)
|
|
32
|
+
n += 1;
|
|
33
|
+
re.lastIndex = 0;
|
|
34
|
+
return n;
|
|
35
|
+
}
|
|
36
|
+
const scriptPatterns = new Map();
|
|
37
|
+
function scriptPattern(name) {
|
|
38
|
+
let re = scriptPatterns.get(name);
|
|
39
|
+
if (!re) {
|
|
40
|
+
re = new RegExp(`\\p{Script=${name}}`, 'gu');
|
|
41
|
+
scriptPatterns.set(name, re);
|
|
42
|
+
}
|
|
43
|
+
return re;
|
|
44
|
+
}
|
|
45
|
+
/** The script of `scripts` with the most letters in `text` (ties: the first listed), `null` for none. */
|
|
46
|
+
function dominantScript(text, scripts) {
|
|
47
|
+
let best = null;
|
|
48
|
+
let bestCount = 0;
|
|
49
|
+
for (const s of scripts) {
|
|
50
|
+
const n = countOf(scriptPattern(s), text);
|
|
51
|
+
if (n > bestCount) {
|
|
52
|
+
best = s;
|
|
53
|
+
bestCount = n;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return best;
|
|
57
|
+
}
|
|
58
|
+
exports.dominantScript = dominantScript;
|
|
59
|
+
function has(o, k) {
|
|
60
|
+
return Object.prototype.hasOwnProperty.call(o, k);
|
|
61
|
+
}
|
|
62
|
+
/** A reply condition on the sentence of `s`. */
|
|
63
|
+
function evalReplyCondition(c, s) {
|
|
64
|
+
if (typeof c === 'boolean')
|
|
65
|
+
return c;
|
|
66
|
+
const o = c;
|
|
67
|
+
if (has(o, 'all'))
|
|
68
|
+
return o['all'].every((x) => evalReplyCondition(x, s));
|
|
69
|
+
if (has(o, 'any'))
|
|
70
|
+
return o['any'].some((x) => evalReplyCondition(x, s));
|
|
71
|
+
if (has(o, 'not'))
|
|
72
|
+
return !evalReplyCondition(o['not'], s);
|
|
73
|
+
if (has(o, 'sentence'))
|
|
74
|
+
return (0, transcript_1.matches)(o['sentence'], s.sentence, s.ctx);
|
|
75
|
+
if (has(o, 'first'))
|
|
76
|
+
return s.first === o['first'];
|
|
77
|
+
if (has(o, 'turn')) {
|
|
78
|
+
const t = o['turn'];
|
|
79
|
+
return (t.tag == null || t.tag === s.tag) && (t.silence == null || t.silence === s.silence);
|
|
80
|
+
}
|
|
81
|
+
if (has(o, 'scriptChanged')) {
|
|
82
|
+
const k = o['scriptChanged'];
|
|
83
|
+
const enough = (t) => countOf(LETTER, t) >= k.minLetters;
|
|
84
|
+
let reference = null;
|
|
85
|
+
for (let i = s.agentLines.length - 1; i >= 0; i--) {
|
|
86
|
+
if (enough(s.agentLines[i])) {
|
|
87
|
+
reference = s.agentLines[i];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (reference == null || !enough(s.sentence))
|
|
92
|
+
return false;
|
|
93
|
+
return dominantScript(s.sentence, k.scripts) !== dominantScript(reference, k.scripts);
|
|
94
|
+
}
|
|
95
|
+
if (has(o, 'earlier')) {
|
|
96
|
+
const inner = o['earlier'];
|
|
97
|
+
return s.agentLines.some((line) => line.split(EARLIER_SPLIT).some((x) => evalReplyCondition(inner, { ...s, sentence: x, ctx: { ...s.ctx, line: x } })));
|
|
98
|
+
}
|
|
99
|
+
if (has(o, 'count')) {
|
|
100
|
+
const { count, ...tests } = o;
|
|
101
|
+
return (0, evaluate_1.compare)(s.counters[count] ?? 0, tests, s.ctx);
|
|
102
|
+
}
|
|
103
|
+
if (has(o, 'answered')) {
|
|
104
|
+
const last = s.agentLines.length ? s.agentLines[s.agentLines.length - 1] : null;
|
|
105
|
+
return last != null && (0, transcript_1.matches)(o['answered'], last, s.ctx);
|
|
106
|
+
}
|
|
107
|
+
return (0, evaluate_1.evalCondition)(c, s.ctx);
|
|
108
|
+
}
|
|
109
|
+
exports.evalReplyCondition = evalReplyCondition;
|
|
110
|
+
function replyText(t, ctx, sentence) {
|
|
111
|
+
if (t && typeof t === 'object' && !Array.isArray(t) && !(t instanceof RegExp) && has(t, 'byScript')) {
|
|
112
|
+
const b = t.byScript;
|
|
113
|
+
const script = dominantScript(sentence, Object.keys(b.texts));
|
|
114
|
+
return (0, evaluate_1.evalText)(script != null ? b.texts[script] : b.else, ctx) ?? '';
|
|
115
|
+
}
|
|
116
|
+
return (0, evaluate_1.evalText)(t, ctx) ?? '';
|
|
117
|
+
}
|
|
118
|
+
function sentenceRulesHook(spec, path, c) {
|
|
119
|
+
const replyKey = `${path}:reply`;
|
|
120
|
+
const countersKey = `${path}:counters`;
|
|
121
|
+
return (call, input, api) => {
|
|
122
|
+
const s = input;
|
|
123
|
+
const st = api.state ?? {};
|
|
124
|
+
if (s.index === 0 || st[replyKey] == null)
|
|
125
|
+
st[replyKey] = { view: call, tag: s.tag, silence: s.silence, allDropped: true };
|
|
126
|
+
const r = st[replyKey];
|
|
127
|
+
const counters = (st[countersKey] ?? {});
|
|
128
|
+
const scope = {
|
|
129
|
+
ctx: c.ctx(r.view, { line: s.sentence }), sentence: s.sentence, first: r.allDropped, tag: r.tag, silence: r.silence,
|
|
130
|
+
agentLines: r.view.agentLines, counters,
|
|
131
|
+
};
|
|
132
|
+
const rule = spec.rules.find((x) => evalReplyCondition(x.when, scope));
|
|
133
|
+
const then = rule?.then;
|
|
134
|
+
if (then !== 'drop' && then !== 'cut' && r.allDropped && spec.counters?.length) {
|
|
135
|
+
const next = { ...counters };
|
|
136
|
+
for (const k of spec.counters) {
|
|
137
|
+
if (k.when !== undefined && !evalReplyCondition(k.when, scope))
|
|
138
|
+
continue;
|
|
139
|
+
next[k.name] = evalReplyCondition(k.inc, scope) ? (counters[k.name] ?? 0) + 1 : 0;
|
|
140
|
+
}
|
|
141
|
+
st[countersKey] = next;
|
|
142
|
+
}
|
|
143
|
+
if (then !== 'drop')
|
|
144
|
+
r.allDropped = false;
|
|
145
|
+
if (!rule)
|
|
146
|
+
return s.sentence;
|
|
147
|
+
if (rule.log)
|
|
148
|
+
api.log('llm_reply_rejected', { reason: rule.log, sentence: s.sentence });
|
|
149
|
+
if (then === 'drop')
|
|
150
|
+
return null;
|
|
151
|
+
if (then === 'cut')
|
|
152
|
+
return { cut: true };
|
|
153
|
+
const t = then;
|
|
154
|
+
return {
|
|
155
|
+
replace: replyText(t.replace, scope.ctx, s.sentence),
|
|
156
|
+
...(t.alias ? { alias: t.alias } : {}),
|
|
157
|
+
...(t.close ? { close: { result: t.close.result, ...(t.close.reason ? { reason: t.close.reason } : {}) } } : {}),
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
// ── stream filters ─────────────────────────────────────────────────────────────────────────────
|
|
162
|
+
/** Per-reply scratch of a generated stream filter in the call's hook state: a new reply starts it over. */
|
|
163
|
+
function scratch(api, key, seq, init) {
|
|
164
|
+
const state = api.state ?? {};
|
|
165
|
+
const cur = state[key];
|
|
166
|
+
if (cur && cur.seq === seq)
|
|
167
|
+
return cur;
|
|
168
|
+
const fresh = { ...init(), seq };
|
|
169
|
+
state[key] = fresh;
|
|
170
|
+
return fresh;
|
|
171
|
+
}
|
|
172
|
+
const DEFAULT_SENTENCE_END = /[.?!…]/;
|
|
173
|
+
function skipped(skip, defaults, turn) {
|
|
174
|
+
const greeting = skip?.greeting ?? defaults.greeting;
|
|
175
|
+
const silence = skip?.silence ?? defaults.silence;
|
|
176
|
+
return (greeting && turn.tag === 'bootstrap') || (silence && turn.silence);
|
|
177
|
+
}
|
|
178
|
+
function nfc(on) {
|
|
179
|
+
return on === 'NFC' ? (t) => t.normalize('NFC') : (t) => t;
|
|
180
|
+
}
|
|
181
|
+
function unclearLadderHook(spec, path, c) {
|
|
182
|
+
const end = spec.sentenceEnd ?? DEFAULT_SENTENCE_END;
|
|
183
|
+
const norm = nfc(spec.normalize);
|
|
184
|
+
const onExhausted = c.actions(spec.onExhausted, `${path}.onExhausted`);
|
|
185
|
+
const early = spec.early ? { when: spec.early.when, then: c.actions(spec.early.then, `${path}.early.then`) } : null;
|
|
186
|
+
const list = (x) => (Array.isArray(x) ? [...x] : [x]);
|
|
187
|
+
return (call, input, api) => {
|
|
188
|
+
const { chunk, at, turn } = input;
|
|
189
|
+
const r = scratch(api, path, turn.seq, () => ({
|
|
190
|
+
mode: skipped(spec.skip, { greeting: true, silence: true }, turn) ? 'off' : 'pending',
|
|
191
|
+
held: '', dropped: null, streak: Number(call.vars[spec.countVar] ?? 0),
|
|
192
|
+
early: early != null && (0, evaluate_1.evalCondition)(early.when, c.ctx(call)),
|
|
193
|
+
}));
|
|
194
|
+
if (r.mode === 'off')
|
|
195
|
+
return chunk;
|
|
196
|
+
if (at === 'start')
|
|
197
|
+
return null;
|
|
198
|
+
const emit = (text) => {
|
|
199
|
+
if (r.dropped != null) {
|
|
200
|
+
if (text.trim().length === 0)
|
|
201
|
+
return '';
|
|
202
|
+
r.dropped = null;
|
|
203
|
+
return text.trimStart();
|
|
204
|
+
}
|
|
205
|
+
return text;
|
|
206
|
+
};
|
|
207
|
+
const decide = (first) => {
|
|
208
|
+
const sentence = norm(first);
|
|
209
|
+
const ctx = c.ctx(call, { line: sentence });
|
|
210
|
+
const probe = (0, transcript_1.matches)(spec.probe, sentence, ctx);
|
|
211
|
+
const whole = !probe && spec.whole != null && (0, transcript_1.matches)(spec.whole, sentence, ctx);
|
|
212
|
+
if (!probe && !whole) {
|
|
213
|
+
r.mode = 'pass';
|
|
214
|
+
return r.streak !== 0 ? { vars: { [spec.countVar]: 0 } } : {};
|
|
215
|
+
}
|
|
216
|
+
const machine = r.early && probe;
|
|
217
|
+
r.mode = machine ? 'suppress' : r.streak === 0 ? 'pass' : r.streak < spec.rungs ? (whole ? 'pass' : 'drop') : 'suppress';
|
|
218
|
+
if (r.mode !== 'suppress')
|
|
219
|
+
return { vars: { [spec.countVar]: r.streak + 1 } };
|
|
220
|
+
return { then: machine ? list(early.then) : list(onExhausted) };
|
|
221
|
+
};
|
|
222
|
+
const mode = () => r.mode;
|
|
223
|
+
if (at === 'end') {
|
|
224
|
+
if (r.mode === 'pending' && r.held.length > 0) {
|
|
225
|
+
const d = decide(r.held);
|
|
226
|
+
return mode() === 'suppress' ? d : { ...d, text: r.held };
|
|
227
|
+
}
|
|
228
|
+
if (r.dropped != null)
|
|
229
|
+
return r.dropped;
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
if (r.mode === 'suppress')
|
|
233
|
+
return null;
|
|
234
|
+
if (r.mode !== 'pending')
|
|
235
|
+
return emit(chunk);
|
|
236
|
+
r.held += chunk;
|
|
237
|
+
const i = r.held.search(end);
|
|
238
|
+
if (i < 0)
|
|
239
|
+
return null;
|
|
240
|
+
const d = decide(r.held.slice(0, i + 1));
|
|
241
|
+
if (mode() === 'suppress')
|
|
242
|
+
return d;
|
|
243
|
+
let text;
|
|
244
|
+
if (mode() === 'drop') {
|
|
245
|
+
r.dropped = r.held.slice(0, i + 1);
|
|
246
|
+
text = emit(r.held.slice(i + 1));
|
|
247
|
+
}
|
|
248
|
+
else
|
|
249
|
+
text = r.held;
|
|
250
|
+
r.held = '';
|
|
251
|
+
return { ...d, text };
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function insertAfterFirstHook(spec, path, c) {
|
|
255
|
+
const end = spec.sentenceEnd ?? DEFAULT_SENTENCE_END;
|
|
256
|
+
const norm = nfc(spec.normalize);
|
|
257
|
+
return (call, input, api) => {
|
|
258
|
+
const { chunk, at, turn } = input;
|
|
259
|
+
const r = scratch(api, path, turn.seq, () => ({
|
|
260
|
+
mode: (skipped(spec.skip, { greeting: true, silence: true }, turn) || !(0, evaluate_1.evalCondition)(spec.when, c.ctx(call, { line: norm(turn.trigger) })) ? 'pass' : 'first'),
|
|
261
|
+
held: '', titleEnd: -1,
|
|
262
|
+
}));
|
|
263
|
+
const ctx = () => c.ctx(call);
|
|
264
|
+
const test = (m, text) => (0, transcript_1.matches)(m, norm(text), ctx());
|
|
265
|
+
const release = (add) => {
|
|
266
|
+
r.mode = 'pass';
|
|
267
|
+
const held = r.held;
|
|
268
|
+
r.held = '';
|
|
269
|
+
if (!add)
|
|
270
|
+
return held;
|
|
271
|
+
return `${held.slice(0, r.titleEnd)} ${(0, evaluate_1.evalText)(spec.text, ctx()) ?? ''}${held.slice(r.titleEnd)}`;
|
|
272
|
+
};
|
|
273
|
+
if (at === 'end')
|
|
274
|
+
return r.held.length > 0 ? release(r.mode === 'second' && !test(spec.unless, r.held.slice(r.titleEnd))) : null;
|
|
275
|
+
if (r.mode === 'pass')
|
|
276
|
+
return chunk;
|
|
277
|
+
r.held += chunk;
|
|
278
|
+
if (r.mode === 'first') {
|
|
279
|
+
const i = r.held.search(end);
|
|
280
|
+
if (i < 0)
|
|
281
|
+
return null;
|
|
282
|
+
const first = r.held.slice(0, i + 1);
|
|
283
|
+
if (!test(spec.after, first) || test(spec.unless, first))
|
|
284
|
+
return release(false);
|
|
285
|
+
r.titleEnd = i + 1;
|
|
286
|
+
r.mode = 'second';
|
|
287
|
+
}
|
|
288
|
+
const rest = r.held.slice(r.titleEnd);
|
|
289
|
+
if (test(spec.unless, rest))
|
|
290
|
+
return release(false);
|
|
291
|
+
return rest.search(end) >= 0 ? release(true) : null;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function asClipHook(spec, path, c) {
|
|
295
|
+
const norm = (x) => x.normalize('NFC').trim().toLowerCase();
|
|
296
|
+
return (call, input, api) => {
|
|
297
|
+
const { chunk, at, turn } = input;
|
|
298
|
+
if (skipped(spec.skip, { greeting: true, silence: false }, turn))
|
|
299
|
+
return chunk;
|
|
300
|
+
const text = spec.play.text;
|
|
301
|
+
const want = norm(typeof text === 'string' || typeof text === 'function' ? (0, match_1.resolveText)(text, call) ?? '' : (0, values_1.toText)((0, evaluate_1.evalExpr)(text, c.ctx(call))));
|
|
302
|
+
const r = scratch(api, path, turn.seq, () => ({ held: '', holding: true }));
|
|
303
|
+
if (at === 'start')
|
|
304
|
+
return null;
|
|
305
|
+
if (at === 'end') {
|
|
306
|
+
if (!r.holding || !r.held.length)
|
|
307
|
+
return null;
|
|
308
|
+
return norm(r.held) === want ? { clip: { play: spec.play, line: r.held.trim() } } : r.held;
|
|
309
|
+
}
|
|
310
|
+
if (!r.holding)
|
|
311
|
+
return chunk;
|
|
312
|
+
r.held += chunk;
|
|
313
|
+
if (want.startsWith(norm(r.held)))
|
|
314
|
+
return null;
|
|
315
|
+
r.holding = false;
|
|
316
|
+
return r.held;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
// ── stray letters ──────────────────────────────────────────────────────────────────────────────
|
|
320
|
+
/** A text without the letters of words that have a letter of a script not kept (see `stripLetters`). */
|
|
321
|
+
function stripLettersExcept(keep) {
|
|
322
|
+
const kept = [...keep, 'Common', 'Inherited'].map((s) => `\\p{Script=${s}}`).join('');
|
|
323
|
+
const foreign = new RegExp(`(?![${kept}])[\\p{L}\\p{M}]`, 'u');
|
|
324
|
+
return (text) => {
|
|
325
|
+
if (!foreign.test(text))
|
|
326
|
+
return text;
|
|
327
|
+
return text.replace(/\S+\s*/g, (piece) => {
|
|
328
|
+
if (!foreign.test(piece))
|
|
329
|
+
return piece;
|
|
330
|
+
const rest = piece.replace(/[\p{L}\p{M}]/gu, '');
|
|
331
|
+
return rest.trim() ? rest : '';
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
exports.stripLettersExcept = stripLettersExcept;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CallView } from '../../spec';
|
|
2
|
+
import type { EngineGate, EngineRule } from '../config';
|
|
3
|
+
import type { Turn } from './context';
|
|
4
|
+
/** A detector set a flag. */
|
|
5
|
+
export declare function flagged(cx: Turn, flag: string): void;
|
|
6
|
+
/** Rules `on: 'callerPartial'`: once one acted, no more until the caller's next final. */
|
|
7
|
+
export declare function partialRules(cx: Turn, text: string): void;
|
|
8
|
+
/** Rules `on: 'toolCall'`: their `match` reads the tool's name. */
|
|
9
|
+
export declare function toolCall(cx: Turn, name: string): void;
|
|
10
|
+
/** NLU rules that read caller lines before the LLM now. */
|
|
11
|
+
export declare function nluRules(cx: Turn): EngineRule[];
|
|
12
|
+
/** The hook rule that reads this caller line, if any. */
|
|
13
|
+
export declare function hookRuleFor(cx: Turn, text: string): EngineRule | undefined;
|
|
14
|
+
export declare function ruleApplies(cx: Turn, r: EngineRule): boolean;
|
|
15
|
+
export declare function kind(cx: Turn, g: EngineGate, line: string | undefined, view: CallView): 'skip' | 'reask' | 'asked' | 'other';
|
|
16
|
+
export declare function classify(cx: Turn, g: EngineGate, line: string, view: CallView): string | null;
|
|
17
|
+
/** The answer answers the gate's question: the governing agent line is the question (or a re-ask of it). */
|
|
18
|
+
export declare function answersQuestion(cx: Turn, g: EngineGate, agentLines: readonly string[], cls: string, view: CallView): boolean;
|
|
19
|
+
/** Gates read the caller's line: the turn's text with their marks, or `null` when a gate closed the call. */
|
|
20
|
+
export declare function gates(cx: Turn, line: string): string | null;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gates = exports.answersQuestion = exports.classify = exports.kind = exports.ruleApplies = exports.hookRuleFor = exports.nluRules = exports.toolCall = exports.partialRules = exports.flagged = void 0;
|
|
4
|
+
/** A detector set a flag. */
|
|
5
|
+
function flagged(cx, flag) {
|
|
6
|
+
const d = cx.d;
|
|
7
|
+
d.flags = { ...d.flags, [flag]: true };
|
|
8
|
+
}
|
|
9
|
+
exports.flagged = flagged;
|
|
10
|
+
/** Rules `on: 'callerPartial'`: once one acted, no more until the caller's next final. */
|
|
11
|
+
function partialRules(cx, text) {
|
|
12
|
+
const d = cx.d;
|
|
13
|
+
if (d.partialActed || d.phase === 'closing' || cx.m?.callEnding || !text.trim())
|
|
14
|
+
return;
|
|
15
|
+
const fired = (s) => cx.env.partialRuleIds.reduce((n, id) => n + (s.fired[id] ?? 0), 0);
|
|
16
|
+
const before = fired(d);
|
|
17
|
+
const done = cx.core.rules(d, 'callerPartial', text, 'callerPartial', cx.run);
|
|
18
|
+
cx.set(done.state);
|
|
19
|
+
cx.fx.push(...done.effects);
|
|
20
|
+
if (fired(cx.d) > before)
|
|
21
|
+
cx.d.partialActed = true;
|
|
22
|
+
}
|
|
23
|
+
exports.partialRules = partialRules;
|
|
24
|
+
/** Rules `on: 'toolCall'`: their `match` reads the tool's name. */
|
|
25
|
+
function toolCall(cx, name) {
|
|
26
|
+
if (cx.d.phase === 'closing' || cx.m?.callEnding)
|
|
27
|
+
return;
|
|
28
|
+
cx.log('tool_call', { name });
|
|
29
|
+
const done = cx.core.rules(cx.d, 'toolCall', name, 'toolCall', cx.run);
|
|
30
|
+
cx.set(done.state);
|
|
31
|
+
cx.fx.push(...done.effects);
|
|
32
|
+
}
|
|
33
|
+
exports.toolCall = toolCall;
|
|
34
|
+
/** NLU rules that read caller lines before the LLM now. */
|
|
35
|
+
function nluRules(cx) {
|
|
36
|
+
return cx.cfg.rules.filter((r) => r.on === 'callerLine' && r.intents && ruleApplies(cx, r));
|
|
37
|
+
}
|
|
38
|
+
exports.nluRules = nluRules;
|
|
39
|
+
/** The hook rule that reads this caller line, if any. */
|
|
40
|
+
function hookRuleFor(cx, text) {
|
|
41
|
+
const view = cx.core.view(cx.d);
|
|
42
|
+
return cx.cfg.rules.find((r) => r.on === 'callerLine' && r.hook != null && ruleApplies(cx, r) && r.test(text, view) && (!r.lazy || r.lazy(view, text)));
|
|
43
|
+
}
|
|
44
|
+
exports.hookRuleFor = hookRuleFor;
|
|
45
|
+
function ruleApplies(cx, r) {
|
|
46
|
+
const d = cx.d;
|
|
47
|
+
if (!r.phases.includes(d.phase))
|
|
48
|
+
return false;
|
|
49
|
+
if (r.held != null && d.held !== r.held)
|
|
50
|
+
return false;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
exports.ruleApplies = ruleApplies;
|
|
54
|
+
function kind(cx, g, line, view) {
|
|
55
|
+
if (line == null)
|
|
56
|
+
return 'other';
|
|
57
|
+
if (g.skip?.(line, view))
|
|
58
|
+
return 'skip';
|
|
59
|
+
if (g.reask?.test(line, view))
|
|
60
|
+
return 'reask';
|
|
61
|
+
if (g.asked(line, view))
|
|
62
|
+
return 'asked';
|
|
63
|
+
return 'other';
|
|
64
|
+
}
|
|
65
|
+
exports.kind = kind;
|
|
66
|
+
function classify(cx, g, line, view) {
|
|
67
|
+
return g.answers.find((a) => a.test(line, view))?.name ?? null;
|
|
68
|
+
}
|
|
69
|
+
exports.classify = classify;
|
|
70
|
+
/** The answer answers the gate's question: the governing agent line is the question (or a re-ask of it). */
|
|
71
|
+
function answersQuestion(cx, g, agentLines, cls, view) {
|
|
72
|
+
const kindAt = (i) => kind(cx, g, agentLines[i], view);
|
|
73
|
+
let i = agentLines.length - 1;
|
|
74
|
+
while (i >= 0 && kindAt(i) === 'skip')
|
|
75
|
+
i--;
|
|
76
|
+
if (i < 0)
|
|
77
|
+
return false;
|
|
78
|
+
const governing = kindAt(i);
|
|
79
|
+
if (governing === 'asked')
|
|
80
|
+
return true;
|
|
81
|
+
if (governing !== 'reask' || !g.reask?.answers.includes(cls))
|
|
82
|
+
return false;
|
|
83
|
+
i--;
|
|
84
|
+
while (i >= 0 && (kindAt(i) === 'skip' || kindAt(i) === 'reask'))
|
|
85
|
+
i--;
|
|
86
|
+
return i >= 0 && kindAt(i) === 'asked';
|
|
87
|
+
}
|
|
88
|
+
exports.answersQuestion = answersQuestion;
|
|
89
|
+
/** Gates read the caller's line: the turn's text with their marks, or `null` when a gate closed the call. */
|
|
90
|
+
function gates(cx, line) {
|
|
91
|
+
let text = cx.d.marks.length ? [...cx.d.marks, line].join('\n') : line;
|
|
92
|
+
cx.d.marks = [];
|
|
93
|
+
for (const g of cx.v.gates) {
|
|
94
|
+
const d = cx.d;
|
|
95
|
+
const view = cx.core.view(d);
|
|
96
|
+
const agentLines = cx.agentLines();
|
|
97
|
+
const passedFlag = `${g.id}.passed`;
|
|
98
|
+
if (g.passedBy && agentLines.some((l) => g.passedBy(l, view))) {
|
|
99
|
+
d.flags = { ...d.flags, [passedFlag]: true };
|
|
100
|
+
d.gateUnheard = d.gateUnheard.filter((x) => x !== g.id);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const cls = classify(cx, g, line, view);
|
|
104
|
+
const passing = Object.entries(g.on).filter(([, o]) => o.passed).map(([n]) => n);
|
|
105
|
+
const confirms = cls != null && passing.includes(cls)
|
|
106
|
+
&& answersQuestion(cx, g, agentLines, cls, view)
|
|
107
|
+
&& cx.callerSinceAgent().every((l) => passing.includes(classify(cx, g, l, view) ?? ''));
|
|
108
|
+
let voided = false;
|
|
109
|
+
if (d.gateUnheard.includes(g.id)) {
|
|
110
|
+
d.gateUnheard = d.gateUnheard.filter((x) => x !== g.id);
|
|
111
|
+
if (!confirms) {
|
|
112
|
+
d.flags = { ...d.flags, [passedFlag]: false };
|
|
113
|
+
voided = true;
|
|
114
|
+
cx.log('gate_pass_voided', { gate: g.id, userText: line });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (confirms) {
|
|
118
|
+
const on = g.on[cls];
|
|
119
|
+
d.flags = { ...d.flags, [passedFlag]: true };
|
|
120
|
+
d.gateUnheard = [...d.gateUnheard, g.id];
|
|
121
|
+
cx.log('gate_passed', { gate: g.id, userText: line, answer: cls });
|
|
122
|
+
if (on.mark)
|
|
123
|
+
text = `${on.mark}\n${text}`;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (voided && g.unheardMark)
|
|
127
|
+
text = `${g.unheardMark}\n${text}`;
|
|
128
|
+
if (cls != null && g.on[cls] && !g.on[cls].passed && g.on[cls].mark)
|
|
129
|
+
text = `${g.on[cls].mark}\n${text}`;
|
|
130
|
+
if (cx.d.flags[passedFlag] || cls != null)
|
|
131
|
+
continue;
|
|
132
|
+
const asked = agentLines.filter((l) => kind(cx, g, l, view) === 'asked').length;
|
|
133
|
+
if (asked < g.maxAsks)
|
|
134
|
+
continue;
|
|
135
|
+
cx.log('gate_exhausted', { gate: g.id, userText: line, asked, maxAsks: g.maxAsks });
|
|
136
|
+
const done = cx.run(cx.d, g.onExhausted, { line, id: `${g.id}_exhausted` });
|
|
137
|
+
cx.set(done.state);
|
|
138
|
+
cx.fx.push(...done.effects);
|
|
139
|
+
if (done.answered)
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return text;
|
|
143
|
+
}
|
|
144
|
+
exports.gates = gates;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SilenceFacts } from './events';
|
|
2
|
+
import type { Turn } from './context';
|
|
3
|
+
/** A silence turn the caller cut before hearing it never happened. */
|
|
4
|
+
export declare function voidRung(cx: Turn, text: string): string;
|
|
5
|
+
export declare function silence(cx: Turn, t: SilenceFacts): void;
|
|
6
|
+
export declare function noProgress(cx: Turn): void;
|
|
7
|
+
export declare function deadAudio(cx: Turn): void;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deadAudio = exports.noProgress = exports.silence = exports.voidRung = void 0;
|
|
4
|
+
const carry_1 = require("./carry");
|
|
5
|
+
const opening_1 = require("./opening");
|
|
6
|
+
const overtalk_1 = require("./overtalk");
|
|
7
|
+
const turn_1 = require("./turn");
|
|
8
|
+
/** A silence turn the caller cut before hearing it never happened. */
|
|
9
|
+
function voidRung(cx, text) {
|
|
10
|
+
const rung = cx.d.silence.pendingRung;
|
|
11
|
+
if (rung == null)
|
|
12
|
+
return text;
|
|
13
|
+
cx.d.silence = { ...cx.d.silence, pendingRung: null };
|
|
14
|
+
cx.log('silence_marker_voided', { requiredAction: rung });
|
|
15
|
+
if (cx.v.silence.voidMark == null)
|
|
16
|
+
return text;
|
|
17
|
+
return `${cx.v.silence.voidMark.replace(/\{action\}/g, rung)}\n${text}`;
|
|
18
|
+
}
|
|
19
|
+
exports.voidRung = voidRung;
|
|
20
|
+
function silence(cx, t) {
|
|
21
|
+
const d = cx.d;
|
|
22
|
+
if (cx.m?.callEnding)
|
|
23
|
+
return;
|
|
24
|
+
if (d.phase === 'closing')
|
|
25
|
+
return;
|
|
26
|
+
if (d.phase === 'opening') {
|
|
27
|
+
const st = cx.steps[d.step];
|
|
28
|
+
if (st?.kind !== 'listen' || d.playing != null)
|
|
29
|
+
return;
|
|
30
|
+
// The listen step's own ladder: rung n on the n-th silence (no rungs: go on); when it ran out, keep waiting.
|
|
31
|
+
let i = d.rung;
|
|
32
|
+
while (i < st.rungs.length && st.rungs[i].when && !st.rungs[i].when(cx.core.view(d)))
|
|
33
|
+
i++;
|
|
34
|
+
const rung = st.rungs[i];
|
|
35
|
+
if (!rung && st.rungs.length)
|
|
36
|
+
return;
|
|
37
|
+
d.rung = i + 1;
|
|
38
|
+
if (st.transcriptLine)
|
|
39
|
+
cx.addLine('caller', st.transcriptLine);
|
|
40
|
+
const done = cx.run(d, rung?.actions ?? [{ next: true }], { id: 'silence', at: 'silenceLimit' });
|
|
41
|
+
cx.set(done.state);
|
|
42
|
+
cx.fx.push(...done.effects);
|
|
43
|
+
if (done.next) {
|
|
44
|
+
(0, opening_1.takeAnswer)(cx, null);
|
|
45
|
+
cx.timing('refund');
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const buffered = d.buffered;
|
|
50
|
+
if (buffered != null && buffered.length > 0 && cx.v.overtalk.silenceWaitsForReplay) {
|
|
51
|
+
// `answerOnSilence: false`: the line is answered by its replay (armed again from now), not by the silence window.
|
|
52
|
+
cx.log('silence_timeout_buffer_waits_for_replay', { userText: buffered, attempt: t.attempt });
|
|
53
|
+
(0, overtalk_1.scheduleReplay)(cx);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (buffered != null && buffered.length > 0) {
|
|
57
|
+
d.buffered = null;
|
|
58
|
+
cx.clearReplay();
|
|
59
|
+
(0, overtalk_1.takeBackchannel)(cx);
|
|
60
|
+
cx.log('silence_timeout_with_buffered_result', { userText: buffered, attempt: t.attempt });
|
|
61
|
+
(0, turn_1.callerLine)(cx, buffered, undefined, undefined, undefined, d.bufferedAt);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (d.carriedFrom != null && cx.v.carryOn) {
|
|
65
|
+
cx.timing('refund');
|
|
66
|
+
(0, carry_1.carryLapsed)(cx);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
d.silence = { ...d.silence, attempt: t.attempt, heardSpeech: t.heardSpeech };
|
|
70
|
+
let rung;
|
|
71
|
+
const ladder = cx.v.silence.ladder;
|
|
72
|
+
if (t.exhausted)
|
|
73
|
+
rung = ladder[ladder.length - 1];
|
|
74
|
+
else if (t.awaitingHandover && cx.v.silence.held.length) {
|
|
75
|
+
d.heldTurns += 1;
|
|
76
|
+
rung = cx.v.silence.held[Math.min(d.heldTurns, cx.v.silence.held.length) - 1];
|
|
77
|
+
}
|
|
78
|
+
else if (t.heardSpeech && cx.v.silence.heardNoText)
|
|
79
|
+
rung = cx.v.silence.heardNoText;
|
|
80
|
+
else
|
|
81
|
+
rung = ladder[Math.max(0, Math.min(t.silentTurns, ladder.length) - 1)];
|
|
82
|
+
if (!rung)
|
|
83
|
+
return;
|
|
84
|
+
let actions = rung.actions;
|
|
85
|
+
if (rung.when && !rung.when(cx.core.view(d))) {
|
|
86
|
+
if (!rung.otherwise)
|
|
87
|
+
return;
|
|
88
|
+
actions = rung.otherwise;
|
|
89
|
+
}
|
|
90
|
+
cx.log('silence_turn', { ...t, rung: rung.name ?? null });
|
|
91
|
+
const heardLine = rung === cx.v.silence.heardNoText ? cx.v.silence.heardNoText.transcriptLine : undefined;
|
|
92
|
+
if (heardLine != null)
|
|
93
|
+
cx.addLine('caller', heardLine);
|
|
94
|
+
const llm = actions.some((a) => 'llm' in a);
|
|
95
|
+
const done = cx.run(d, actions.length ? actions : [{ llm: cx.cfg.silenceSignal }], { id: 'silence', at: 'silenceLimit' });
|
|
96
|
+
cx.set(done.state);
|
|
97
|
+
cx.fx.push(...done.effects);
|
|
98
|
+
if (llm && cx.d.phase !== 'closing')
|
|
99
|
+
cx.d.silence = { ...cx.d.silence, pendingRung: rung.name ?? 'silence' };
|
|
100
|
+
}
|
|
101
|
+
exports.silence = silence;
|
|
102
|
+
function noProgress(cx) {
|
|
103
|
+
const m = cx.m;
|
|
104
|
+
const np = cx.v.noProgress;
|
|
105
|
+
if (!np || m.callEnding || m.terminated || cx.d.phase === 'closing')
|
|
106
|
+
return;
|
|
107
|
+
const actions = cx.d.phase === 'opening' && np.inOpening ? np.inOpening : np.do;
|
|
108
|
+
const done = cx.run(cx.d, actions, { id: 'no_progress' });
|
|
109
|
+
cx.set(done.state);
|
|
110
|
+
cx.fx.push(...done.effects);
|
|
111
|
+
}
|
|
112
|
+
exports.noProgress = noProgress;
|
|
113
|
+
function deadAudio(cx) {
|
|
114
|
+
const m = cx.m;
|
|
115
|
+
if (m.callEnding || m.terminated || cx.d.phase === 'closing')
|
|
116
|
+
return;
|
|
117
|
+
if (cx.d.callerTurns > 0) {
|
|
118
|
+
cx.log('audio_path_dead_ignored', { reason: 'caller_already_heard' });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!cx.v.deadAudio)
|
|
122
|
+
return;
|
|
123
|
+
const done = cx.run(cx.d, cx.v.deadAudio, { id: 'audio_path_dead' });
|
|
124
|
+
cx.set(done.state);
|
|
125
|
+
cx.fx.push(...done.effects);
|
|
126
|
+
}
|
|
127
|
+
exports.deadAudio = deadAudio;
|