@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,11 @@
|
|
|
1
|
+
import type { AsrByReply, ScriptRule } from '../spec';
|
|
2
|
+
/**
|
|
3
|
+
* The key of the script `text` is written in by the rule (`null`: none of its scripts, or the winner is below
|
|
4
|
+
* `minLetters` / `minShare`). The most letters wins; a tie goes to the key listed first.
|
|
5
|
+
*/
|
|
6
|
+
export declare function scriptOf(rule: ScriptRule, where?: string): (text: string) => string | null;
|
|
7
|
+
/** `voice.asrByReply` as the media reads it: a detector of the recognizer key from a reply so far. */
|
|
8
|
+
export declare function replyAsrDetector(byReply: AsrByReply): {
|
|
9
|
+
readonly detect: (textSoFar: string) => string | null;
|
|
10
|
+
readonly noReturnTo?: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replyAsrDetector = exports.scriptOf = void 0;
|
|
4
|
+
const compiled = new WeakMap();
|
|
5
|
+
function scriptPattern(script, where) {
|
|
6
|
+
try {
|
|
7
|
+
return new RegExp(`\\p{Script=${script}}`, 'gu');
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
throw new Error(`[templates/engine] ${where}: "${script}" is not a Unicode script name`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function countOf(text, pattern) {
|
|
14
|
+
pattern.lastIndex = 0;
|
|
15
|
+
let n = 0;
|
|
16
|
+
while (pattern.exec(text) != null)
|
|
17
|
+
n += 1;
|
|
18
|
+
pattern.lastIndex = 0;
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The key of the script `text` is written in by the rule (`null`: none of its scripts, or the winner is below
|
|
23
|
+
* `minLetters` / `minShare`). The most letters wins; a tie goes to the key listed first.
|
|
24
|
+
*/
|
|
25
|
+
function scriptOf(rule, where = 'script') {
|
|
26
|
+
const hit = compiled.get(rule);
|
|
27
|
+
if (hit)
|
|
28
|
+
return hit;
|
|
29
|
+
const entries = Object.entries(rule.scripts).map(([key, script]) => ({ key, pattern: scriptPattern(script, where) }));
|
|
30
|
+
const minLetters = Math.max(1, rule.minLetters ?? 1);
|
|
31
|
+
const minShare = rule.minShare ?? 0;
|
|
32
|
+
const fn = (text) => {
|
|
33
|
+
let total = 0;
|
|
34
|
+
let best = null;
|
|
35
|
+
for (const e of entries) {
|
|
36
|
+
const count = countOf(text, e.pattern);
|
|
37
|
+
total += count;
|
|
38
|
+
if (best == null || count > best.count)
|
|
39
|
+
best = { key: e.key, count };
|
|
40
|
+
}
|
|
41
|
+
if (best == null || total === 0)
|
|
42
|
+
return null;
|
|
43
|
+
if (best.count < minLetters)
|
|
44
|
+
return null;
|
|
45
|
+
if (best.count / total < minShare)
|
|
46
|
+
return null;
|
|
47
|
+
return best.key;
|
|
48
|
+
};
|
|
49
|
+
compiled.set(rule, fn);
|
|
50
|
+
return fn;
|
|
51
|
+
}
|
|
52
|
+
exports.scriptOf = scriptOf;
|
|
53
|
+
/** `voice.asrByReply` as the media reads it: a detector of the recognizer key from a reply so far. */
|
|
54
|
+
function replyAsrDetector(byReply) {
|
|
55
|
+
const noReturn = byReply.noReturnTo != null ? { noReturnTo: byReply.noReturnTo } : {};
|
|
56
|
+
if (byReply.detect)
|
|
57
|
+
return { detect: byReply.detect, ...noReturn };
|
|
58
|
+
const rule = byReply.byScript;
|
|
59
|
+
const read = scriptOf(rule, 'voice.asrByReply.byScript');
|
|
60
|
+
const allowed = rule.switchTo ? new Set(rule.switchTo) : null;
|
|
61
|
+
return {
|
|
62
|
+
detect: (text) => {
|
|
63
|
+
const key = read(text);
|
|
64
|
+
return key != null && (!allowed || allowed.has(key)) ? key : null;
|
|
65
|
+
},
|
|
66
|
+
...noReturn,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.replyAsrDetector = replyAsrDetector;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Action } from '../../spec';
|
|
2
|
+
import type { EngineState } from '../dialog';
|
|
3
|
+
import type { Done, RunContext } from './events';
|
|
4
|
+
import type { Turn } from './context';
|
|
5
|
+
export declare function runActions(cx: Turn, s0: EngineState, actions: readonly Action[], ctx: RunContext): Done;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runActions = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const language_1 = require("./language");
|
|
6
|
+
const transfer_1 = require("./transfer");
|
|
7
|
+
const compiled_1 = require("../../expr/compiled");
|
|
8
|
+
const state_1 = require("./state");
|
|
9
|
+
function runActions(cx, s0, actions, ctx) {
|
|
10
|
+
cx.set(s0);
|
|
11
|
+
const effects = [];
|
|
12
|
+
const own = cx.fx.length;
|
|
13
|
+
let answered = false;
|
|
14
|
+
let next = false;
|
|
15
|
+
// The acting rule's count (`{ nth }` in its texts); none outside a rule.
|
|
16
|
+
const nth = cx.d.fired[ctx.id];
|
|
17
|
+
for (const a of actions) {
|
|
18
|
+
if (cx.d.phase === 'closing')
|
|
19
|
+
break;
|
|
20
|
+
if ('say' in a) {
|
|
21
|
+
const said = cx.sayText(a.say, ctx.line, nth);
|
|
22
|
+
if (said) {
|
|
23
|
+
const { line, parts } = said;
|
|
24
|
+
cx.staticTurn(line, a.alias ?? ctx.id, parts ? { parts } : undefined);
|
|
25
|
+
if (a.speechOver === 'answer')
|
|
26
|
+
cx.d.answerOver = true;
|
|
27
|
+
cx.d.said = [...cx.d.said, line];
|
|
28
|
+
cx.note(line);
|
|
29
|
+
answered = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if ('llm' in a) {
|
|
33
|
+
const line = cx.core.text(a.llm, cx.d, ctx.line, { attempt: cx.d.silence.attempt, heardSpeech: cx.d.silence.heardSpeech }, nth) ?? '';
|
|
34
|
+
(0, language_1.syncAsr)(cx);
|
|
35
|
+
const text = (0, language_1.nextTurnText)(cx, line);
|
|
36
|
+
cx.llmTurn(text);
|
|
37
|
+
answered = true;
|
|
38
|
+
}
|
|
39
|
+
else if ('play' in a) {
|
|
40
|
+
const p = (0, config_1.enginePlay)(a.play, cx.d.lines.length);
|
|
41
|
+
// A sequence read from the call (`records`): each record with its own text.
|
|
42
|
+
const items = p.records
|
|
43
|
+
? p.records(cx.core.view(cx.d)).map((record) => ({ record, text: cx.core.text(p.text, cx.d, record) ?? '' }))
|
|
44
|
+
: undefined;
|
|
45
|
+
cx.playClip(p, items ? items.map((x) => x.text).filter(Boolean).join(' ') : cx.core.text(p.text, cx.d, ctx.line) ?? '', items);
|
|
46
|
+
answered = true;
|
|
47
|
+
}
|
|
48
|
+
else if ('mark' in a) {
|
|
49
|
+
cx.d.marks = [...cx.d.marks, a.mark];
|
|
50
|
+
}
|
|
51
|
+
else if ('next' in a) {
|
|
52
|
+
next = true;
|
|
53
|
+
}
|
|
54
|
+
else if ('close' in a) {
|
|
55
|
+
const said = a.close == null ? null : cx.sayText(a.close, ctx.line, nth);
|
|
56
|
+
const line = said?.line ?? null;
|
|
57
|
+
const of = (x) => (typeof x === 'function' ? x(cx.core.view(cx.d)) : x);
|
|
58
|
+
const reason = of((0, compiled_1.noData)(a.reason)) ?? ctx.id;
|
|
59
|
+
const alias = of((0, compiled_1.noData)(a.alias)) ?? ctx.id;
|
|
60
|
+
cx.d.result = cx.core.decide(ctx.at, cx.d, of((0, compiled_1.noData)(a.result)));
|
|
61
|
+
cx.log('close', { reason, result: cx.d.result, text: line });
|
|
62
|
+
if (line) {
|
|
63
|
+
cx.staticTurn(line, alias, { hangupReason: reason, ...(said?.parts ? { parts: said.parts } : {}) });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
cx.fx.push({ type: 'hangupNow', reason });
|
|
67
|
+
}
|
|
68
|
+
cx.d.phase = 'closing';
|
|
69
|
+
answered = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
else if ('hangup' in a) {
|
|
73
|
+
cx.d.result = a.result == null ? cx.d.result : cx.core.decide(ctx.at, cx.d, a.result);
|
|
74
|
+
cx.log(`${a.hangup}, hanging up`, { result: cx.d.result });
|
|
75
|
+
cx.fx.push({ type: 'hangupNow', reason: a.hangup, ...(a.graceMs != null ? { tailMs: a.graceMs } : {}) });
|
|
76
|
+
cx.d.phase = 'closing';
|
|
77
|
+
answered = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
else if ('hold' in a) {
|
|
81
|
+
cx.setHold(a.hold);
|
|
82
|
+
}
|
|
83
|
+
else if ('flag' in a) {
|
|
84
|
+
cx.d.flags = { ...cx.d.flags, [a.flag]: a.value ?? true };
|
|
85
|
+
}
|
|
86
|
+
else if ('set' in a) {
|
|
87
|
+
// A data value is a function of the call and the line by now (`compileDataForms`).
|
|
88
|
+
const v = a.value;
|
|
89
|
+
cx.d.vars = { ...cx.d.vars, [a.set]: typeof v === 'function' ? v(cx.core.view(cx.d), ctx.line) : v };
|
|
90
|
+
}
|
|
91
|
+
else if ('ladder' in a) {
|
|
92
|
+
// The ladder's next line (or its terminal actions) runs as this rule's.
|
|
93
|
+
effects.push(...cx.fx.splice(own));
|
|
94
|
+
const done = runActions(cx, cx.d, (0, state_1.ladderStep)(cx, a.ladder, ctx), ctx);
|
|
95
|
+
cx.set(done.state);
|
|
96
|
+
effects.push(...done.effects);
|
|
97
|
+
answered ||= done.answered;
|
|
98
|
+
next ||= done.next;
|
|
99
|
+
if (done.answered)
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
else if ('count' in a) {
|
|
103
|
+
(0, state_1.countUp)(cx, a, ctx);
|
|
104
|
+
}
|
|
105
|
+
else if ('log' in a) {
|
|
106
|
+
const data = typeof a.data === 'function' ? a.data(cx.core.view(cx.d), ctx.line) : a.data ?? {};
|
|
107
|
+
cx.log(a.log, { ...data });
|
|
108
|
+
}
|
|
109
|
+
else if ('transfer' in a) {
|
|
110
|
+
if (cx.cfg.transfer && cx.d.transfer == null) {
|
|
111
|
+
(0, transfer_1.transferStart)(cx, 'rule', false, ctx.line);
|
|
112
|
+
answered = true;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if ('hook' in a) {
|
|
117
|
+
// Agent code returns the actions (of a silence rung); they run when it answers (`HOOK_RESULT`).
|
|
118
|
+
const key = `act-${cx.d.lines.length}-${cx.d.callerTurns}-${ctx.id}`;
|
|
119
|
+
cx.d.actionHook = { key, id: ctx.id, ...(ctx.at ? { at: ctx.at } : {}), turns: cx.d.callerTurns };
|
|
120
|
+
cx.fx.push({ type: 'runHook', key, name: a.hook, line: ctx.line ?? '' });
|
|
121
|
+
answered = true;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
effects.push(...cx.fx.splice(own));
|
|
126
|
+
return { state: cx.d, effects, answered, next };
|
|
127
|
+
}
|
|
128
|
+
exports.runActions = runActions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Turn } from './context';
|
|
2
|
+
/** The LLM turn just requested answers `line`: until its reply is on the line, the caller may take it back. */
|
|
3
|
+
export declare function openCarry(cx: Turn, line: string): void;
|
|
4
|
+
/** The turn that may be taken back is still the current one, with at most `playedMs` of its audio heard. */
|
|
5
|
+
export declare function carryWithin(cx: Turn, playedMs: number): boolean;
|
|
6
|
+
/** The caller began speaking: does this speech begin while the reply can still be taken back? */
|
|
7
|
+
export declare function speechStart(cx: Turn): void;
|
|
8
|
+
/** Words of the speech in progress: rules on partials; they take the reply back. */
|
|
9
|
+
export declare function partial(cx: Turn, text: string): void;
|
|
10
|
+
/** `text` has words of its own: not a filler, not the answered line come round again. */
|
|
11
|
+
export declare function carriesNewWords(cx: Turn, text: string): boolean;
|
|
12
|
+
/** The reply is superseded and stopped; no turn starts (the caller's line, when final, carries the mark). */
|
|
13
|
+
export declare function takeBack(cx: Turn, trigger: 'partial' | 'result', text: string): boolean;
|
|
14
|
+
/** A reply taken back and nothing usable came after it: the LLM says it again. */
|
|
15
|
+
export declare function carryLapsed(cx: Turn): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.carryLapsed = exports.takeBack = exports.carriesNewWords = exports.partial = exports.speechStart = exports.carryWithin = exports.openCarry = void 0;
|
|
4
|
+
// `turn.carryOn`: a caller who was only pausing takes the reply in the making back; when nothing usable follows, the
|
|
5
|
+
// LLM says it again.
|
|
6
|
+
const match_1 = require("../match");
|
|
7
|
+
const language_1 = require("./language");
|
|
8
|
+
const rules_1 = require("./rules");
|
|
9
|
+
/** The LLM turn just requested answers `line`: until its reply is on the line, the caller may take it back. */
|
|
10
|
+
function openCarry(cx, line) {
|
|
11
|
+
cx.d.carry = { seq: cx.turnSeqNow(), line };
|
|
12
|
+
cx.d.carrySegment = cx.m?.userSpeaking === true;
|
|
13
|
+
}
|
|
14
|
+
exports.openCarry = openCarry;
|
|
15
|
+
/** The turn that may be taken back is still the current one, with at most `playedMs` of its audio heard. */
|
|
16
|
+
function carryWithin(cx, playedMs) {
|
|
17
|
+
const m = cx.m;
|
|
18
|
+
const turn = cx.d.carry;
|
|
19
|
+
return m != null && turn != null && cx.turnSeqNow() === turn.seq && !m.callEnding && !m.closingPhraseActive && m.now - m.playbackStartedAt <= playedMs;
|
|
20
|
+
}
|
|
21
|
+
exports.carryWithin = carryWithin;
|
|
22
|
+
/** The caller began speaking: does this speech begin while the reply can still be taken back? */
|
|
23
|
+
function speechStart(cx) {
|
|
24
|
+
const c = cx.v.carryOn;
|
|
25
|
+
cx.d.carrySegment = c != null && carryWithin(cx, c.startGraceMs);
|
|
26
|
+
}
|
|
27
|
+
exports.speechStart = speechStart;
|
|
28
|
+
/** Words of the speech in progress: rules on partials; they take the reply back. */
|
|
29
|
+
function partial(cx, text) {
|
|
30
|
+
if (cx.env.hasPartialRules)
|
|
31
|
+
(0, rules_1.partialRules)(cx, text);
|
|
32
|
+
if (!cx.d.carrySegment || !carriesNewWords(cx, text))
|
|
33
|
+
return;
|
|
34
|
+
takeBack(cx, 'partial', text);
|
|
35
|
+
}
|
|
36
|
+
exports.partial = partial;
|
|
37
|
+
/** `text` has words of its own: not a filler, not the answered line come round again. */
|
|
38
|
+
function carriesNewWords(cx, text) {
|
|
39
|
+
const norm = (0, match_1.normalizeLine)(text);
|
|
40
|
+
if (!/\p{L}{2}/u.test(norm))
|
|
41
|
+
return false;
|
|
42
|
+
if (cx.v.carryOn?.filler?.test(text.trim()) === true)
|
|
43
|
+
return false;
|
|
44
|
+
return !(0, match_1.normalizeLine)(cx.d.carry?.line ?? '').includes(norm);
|
|
45
|
+
}
|
|
46
|
+
exports.carriesNewWords = carriesNewWords;
|
|
47
|
+
/** The reply is superseded and stopped; no turn starts (the caller's line, when final, carries the mark). */
|
|
48
|
+
function takeBack(cx, trigger, text) {
|
|
49
|
+
const d = cx.d;
|
|
50
|
+
const turn = d.carry;
|
|
51
|
+
const c = cx.v.carryOn;
|
|
52
|
+
if (turn == null || c == null || !carryWithin(cx, c.maxPlayedMs))
|
|
53
|
+
return false;
|
|
54
|
+
const m = cx.m;
|
|
55
|
+
d.carry = null;
|
|
56
|
+
d.carrySegment = false;
|
|
57
|
+
d.carriedFrom = turn.line;
|
|
58
|
+
d.replying = false;
|
|
59
|
+
cx.bumps += 1;
|
|
60
|
+
cx.fx.push({ type: 'cutReply' });
|
|
61
|
+
cx.log('caller_continued_reply_cut', { trigger, text, line: turn.line, playedMs: m.now - m.playbackStartedAt });
|
|
62
|
+
cx.timing('playbackEnd');
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
exports.takeBack = takeBack;
|
|
66
|
+
/** A reply taken back and nothing usable came after it: the LLM says it again. */
|
|
67
|
+
function carryLapsed(cx) {
|
|
68
|
+
const line = cx.d.carriedFrom;
|
|
69
|
+
cx.d.carriedFrom = null;
|
|
70
|
+
cx.log('caller_continuation_lapsed', { line });
|
|
71
|
+
(0, language_1.syncAsr)(cx);
|
|
72
|
+
cx.llmTurn((0, language_1.nextTurnText)(cx, cx.v.carryOn.lapsedMark));
|
|
73
|
+
}
|
|
74
|
+
exports.carryLapsed = carryLapsed;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ExprContext } from '../../expr/types';
|
|
2
|
+
import type { ChoiceSetSpec } from './state-spec';
|
|
3
|
+
/** The offer the transcript is on and the options chosen in it so far. */
|
|
4
|
+
export interface OfferSelection {
|
|
5
|
+
/** The offer's id and its 1-based place in `offers`. */
|
|
6
|
+
readonly offer: string;
|
|
7
|
+
readonly n: number;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly chosen: readonly string[];
|
|
10
|
+
readonly complete: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Letters only: lower case, every run of non-letters (`latin`: of anything but `a`–`z`) one space. */
|
|
13
|
+
export declare function lettersOnly(text: string, letters?: 'any' | 'latin'): string;
|
|
14
|
+
/** The selection read off the transcript; `undefined` when no choice question was asked. */
|
|
15
|
+
export declare function offerSelection(s: ChoiceSetSpec, ctx: ExprContext): OfferSelection | undefined;
|
|
16
|
+
/** The last agent line with words asks one of the choice questions. */
|
|
17
|
+
export declare function lastAsked(s: ChoiceSetSpec, ctx: ExprContext): boolean;
|
|
18
|
+
/** The offer's text, then the options chosen (`interested`); `null` without an offer. */
|
|
19
|
+
export declare function interestedText(s: ChoiceSetSpec, ctx: ExprContext): string | null;
|
|
20
|
+
/** The operator-leg headers of the offer chosen (`{}`: none). */
|
|
21
|
+
export declare function offerHeaders(s: ChoiceSetSpec, ctx: ExprContext, spokenText: string | null): Record<string, string>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.offerHeaders = exports.interestedText = exports.lastAsked = exports.offerSelection = exports.lettersOnly = void 0;
|
|
4
|
+
// `choices.<set>.offers`: the product a caller took and the options chosen in it, read off the transcript (the latest
|
|
5
|
+
// choice question the agent asked names the offer), and what reads it: the offer's interest text, the operator leg's
|
|
6
|
+
// headers, whether the last agent line asked a choice question. Pure.
|
|
7
|
+
const evaluate_1 = require("../../expr/evaluate");
|
|
8
|
+
const transcript_1 = require("../../expr/transcript");
|
|
9
|
+
const values_1 = require("../../expr/values");
|
|
10
|
+
/** Letters only: lower case, every run of non-letters (`latin`: of anything but `a`–`z`) one space. */
|
|
11
|
+
function lettersOnly(text, letters = 'any') {
|
|
12
|
+
const t = text.toLowerCase();
|
|
13
|
+
return (letters === 'latin' ? t.replace(/[^a-z]+/g, ' ') : t.replace(/[^\p{L}]+/gu, ' ')).trim();
|
|
14
|
+
}
|
|
15
|
+
exports.lettersOnly = lettersOnly;
|
|
16
|
+
/** The transcript as `AGENT: ` / `USER: ` text split into lines again (a line with a newline splits as the text does). */
|
|
17
|
+
function transcriptLines(ctx) {
|
|
18
|
+
const text = (ctx.call?.lines ?? []).map((l) => `${l.who === 'agent' ? 'AGENT' : 'USER'}: ${l.text}`).join('\n');
|
|
19
|
+
return text.split('\n').map((line) => ({ agent: line.startsWith('AGENT: '), text: line.replace(/^(?:AGENT|USER): /, '') }));
|
|
20
|
+
}
|
|
21
|
+
/** The option named by the latest line that names exactly one of the options. */
|
|
22
|
+
function latestNamed(lines, options, ctx) {
|
|
23
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
24
|
+
const hits = options.filter((o) => (0, transcript_1.matches)(o.match, lines[i], ctx));
|
|
25
|
+
if (hits.length === 1)
|
|
26
|
+
return hits[0].name;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Every choice question as compared: later questions first, offers in order. */
|
|
31
|
+
function questionsOf(offers, ctx, letters = 'any') {
|
|
32
|
+
const depth = Math.max(0, ...offers.map((o) => o.questions.length));
|
|
33
|
+
const out = [];
|
|
34
|
+
for (let q = depth - 1; q >= 0; q--) {
|
|
35
|
+
offers.forEach((o, oi) => {
|
|
36
|
+
const ask = o.questions[q]?.ask;
|
|
37
|
+
if (ask != null)
|
|
38
|
+
out.push({ offer: oi, q, text: lettersOnly((0, values_1.toText)((0, evaluate_1.evalExpr)(ask, ctx)), letters) });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** The selection read off the transcript; `undefined` when no choice question was asked. */
|
|
44
|
+
function offerSelection(s, ctx) {
|
|
45
|
+
const offers = s.offers ?? [];
|
|
46
|
+
if (!offers.length)
|
|
47
|
+
return undefined;
|
|
48
|
+
const lines = transcriptLines(ctx);
|
|
49
|
+
const questions = questionsOf(offers, ctx, s.letters);
|
|
50
|
+
const askedAt = (from, q) => {
|
|
51
|
+
for (let i = from; i >= 0; i--) {
|
|
52
|
+
if (!lines[i].agent)
|
|
53
|
+
continue;
|
|
54
|
+
const said = lettersOnly(lines[i].text, s.letters);
|
|
55
|
+
if (questions.some((x) => x.q === q && said.includes(x.text)))
|
|
56
|
+
return i;
|
|
57
|
+
}
|
|
58
|
+
return -1;
|
|
59
|
+
};
|
|
60
|
+
const callerBetween = (from, to) => lines.slice(from + 1, to).filter((l) => !l.agent).map((l) => l.text);
|
|
61
|
+
let last;
|
|
62
|
+
for (let i = lines.length - 1; i >= 0 && last == null; i--) {
|
|
63
|
+
if (!lines[i].agent)
|
|
64
|
+
continue;
|
|
65
|
+
const said = lettersOnly(lines[i].text, s.letters);
|
|
66
|
+
const hit = questions.find((x) => said.includes(x.text));
|
|
67
|
+
if (hit)
|
|
68
|
+
last = { at: i, offer: hit.offer, q: hit.q };
|
|
69
|
+
}
|
|
70
|
+
if (last == null)
|
|
71
|
+
return undefined;
|
|
72
|
+
const offer = offers[last.offer];
|
|
73
|
+
// Earlier questions, each between where it was last asked and where the next one was.
|
|
74
|
+
const earlier = [];
|
|
75
|
+
let to = last.at;
|
|
76
|
+
for (let q = last.q - 1; q >= 0; q--) {
|
|
77
|
+
const at = askedAt(to - 1, q);
|
|
78
|
+
earlier[q] = at >= 0 ? latestNamed(callerBetween(at, to), offer.questions[q].options, ctx) : undefined;
|
|
79
|
+
if (at >= 0)
|
|
80
|
+
to = at;
|
|
81
|
+
}
|
|
82
|
+
const chosen = [...earlier.filter((x) => x != null)];
|
|
83
|
+
const own = latestNamed(callerBetween(last.at, lines.length), offer.questions[last.q].options, ctx);
|
|
84
|
+
if (own != null)
|
|
85
|
+
chosen.push(own);
|
|
86
|
+
return {
|
|
87
|
+
offer: offer.id, n: last.offer + 1, text: (0, values_1.toText)((0, evaluate_1.evalExpr)(offer.text, ctx)), chosen,
|
|
88
|
+
complete: chosen.length >= offer.questions.length,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.offerSelection = offerSelection;
|
|
92
|
+
/** The last agent line with words asks one of the choice questions. */
|
|
93
|
+
function lastAsked(s, ctx) {
|
|
94
|
+
const agent = transcriptLines(ctx).filter((l) => l.agent && !/^[\s….]*$/.test(l.text));
|
|
95
|
+
const last = lettersOnly(agent[agent.length - 1]?.text ?? '', s.letters);
|
|
96
|
+
return questionsOf(s.offers ?? [], ctx, s.letters).some((q) => last.includes(q.text));
|
|
97
|
+
}
|
|
98
|
+
exports.lastAsked = lastAsked;
|
|
99
|
+
/** The offer's text, then the options chosen (`interested`); `null` without an offer. */
|
|
100
|
+
function interestedText(s, ctx) {
|
|
101
|
+
const sel = offerSelection(s, ctx);
|
|
102
|
+
if (!sel)
|
|
103
|
+
return null;
|
|
104
|
+
const i = s.interested ?? { chose: ': ', sep: ', ' };
|
|
105
|
+
return sel.chosen.length ? `${sel.text}${i.chose}${sel.chosen.join(i.sep)}` : sel.text;
|
|
106
|
+
}
|
|
107
|
+
exports.interestedText = interestedText;
|
|
108
|
+
/** The last agent line of the call as it is (dots and ellipses too). */
|
|
109
|
+
function lastAgentLineAsIs(ctx) {
|
|
110
|
+
const agent = (ctx.call?.lines ?? []).filter((l) => l.who === 'agent');
|
|
111
|
+
return agent.length ? agent[agent.length - 1].text : '';
|
|
112
|
+
}
|
|
113
|
+
/** The operator-leg headers of the offer chosen (`{}`: none). */
|
|
114
|
+
function offerHeaders(s, ctx, spokenText) {
|
|
115
|
+
const h = s.headers;
|
|
116
|
+
if (!h)
|
|
117
|
+
throw new Error('[templates/choices] op "headers" needs `headers` on the choice set');
|
|
118
|
+
const cut = (v) => {
|
|
119
|
+
const t = h.cap != null ? v.slice(0, h.cap) : v;
|
|
120
|
+
return h.encode === 'uri' ? encodeURIComponent(t) : t;
|
|
121
|
+
};
|
|
122
|
+
const spoken = spokenText ?? lastAgentLineAsIs(ctx);
|
|
123
|
+
const clause = h.spoken ? h.spoken.clause.exec(spoken)?.[1]?.trim() : undefined;
|
|
124
|
+
if (!clause) {
|
|
125
|
+
const sel = offerSelection(s, ctx);
|
|
126
|
+
if (sel == null)
|
|
127
|
+
return {};
|
|
128
|
+
const text = sel.chosen.length ? `${sel.chosen.join(h.sep)}${h.between}${sel.text}` : sel.text;
|
|
129
|
+
return { [h.id]: idOf(h.idFormat, sel.n, sel.offer), [h.text]: cut(text) };
|
|
130
|
+
}
|
|
131
|
+
const haystack = spoken.toLowerCase();
|
|
132
|
+
const offers = s.offers ?? [];
|
|
133
|
+
const index = offers.findIndex((o) => {
|
|
134
|
+
const key = h.spoken.identifyBy.exec((0, values_1.toText)((0, evaluate_1.evalExpr)(o.text, ctx)))?.[1];
|
|
135
|
+
return key != null && haystack.includes(key.toLowerCase());
|
|
136
|
+
});
|
|
137
|
+
const out = { [h.text]: cut(clause) };
|
|
138
|
+
if (index >= 0)
|
|
139
|
+
out[h.id] = idOf(h.idFormat, index + 1, offers[index].id);
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
exports.offerHeaders = offerHeaders;
|
|
143
|
+
const idOf = (format, n, id) => format.replace(/\{n\}/g, String(n)).replace(/\{id\}/g, id);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ExprContext } from '../../expr/types';
|
|
2
|
+
import type { ChoiceSetSpec } from './state-spec';
|
|
3
|
+
/** An option a text picks: its key and the words that picked it. */
|
|
4
|
+
export interface Pick {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly said: string;
|
|
7
|
+
}
|
|
8
|
+
/** The option a number stands for: the same whole value, else within `closeRatio`, else its digits inside (one or none). */
|
|
9
|
+
export declare function nearestOption(value: number, options: readonly {
|
|
10
|
+
key: string;
|
|
11
|
+
value: number;
|
|
12
|
+
}[], near: NonNullable<ChoiceSetSpec['numbers']>['nearest']): string | null;
|
|
13
|
+
/** Every option a text picks, by its words, then (with `numbers`) by a number nearest to its value; first words win. */
|
|
14
|
+
export declare function picked(ctx: ExprContext, set: string, text: string): Pick[];
|
|
15
|
+
/** The one option a text picks (`null`: none, or more than one). */
|
|
16
|
+
export declare function chosen(ctx: ExprContext, set: string, text: string): Pick | null;
|
|
17
|
+
/** The options whose value a number of the text equals (whole units), in option order. */
|
|
18
|
+
export declare function named(ctx: ExprContext, set: string, text: string): string[];
|
|
19
|
+
/** The fields a note or a ladder reads of an option. */
|
|
20
|
+
export declare function optionItem(ctx: ExprContext, set: string, key: string, said: string): Record<string, unknown>;
|
|
21
|
+
/** The `{ choice, op }` expression (`text`: the expression's `of`, `null` when it has none). */
|
|
22
|
+
export declare function choiceValue(ctx: ExprContext, set: string, op: string, text: string | null): unknown;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.choiceValue = exports.optionItem = exports.named = exports.chosen = exports.picked = exports.nearestOption = void 0;
|
|
4
|
+
// `choices`: named option sets read off a line (which option the caller's words pick, which a bot line names by number)
|
|
5
|
+
// and offers read off the transcript (the product the bot asked about and the options chosen inside it). Pure.
|
|
6
|
+
const locales_1 = require("../../locales");
|
|
7
|
+
const evaluate_1 = require("../../expr/evaluate");
|
|
8
|
+
const transcript_1 = require("../../expr/transcript");
|
|
9
|
+
const values_1 = require("../../expr/values");
|
|
10
|
+
const choices_offers_1 = require("./choices-offers");
|
|
11
|
+
function setOf(ctx, name) {
|
|
12
|
+
const s = ctx.blocks?.choices?.[name];
|
|
13
|
+
if (!s)
|
|
14
|
+
throw new Error(`[templates/choices] no choice set "${name}" (AgentSpec.choices)`);
|
|
15
|
+
return s;
|
|
16
|
+
}
|
|
17
|
+
const enabled = (s, ctx) => s.enabledWhen == null || (0, evaluate_1.evalCondition)(s.enabledWhen, ctx);
|
|
18
|
+
/** The words of `text` that name the option (`null`: none): a regular expression's first match, else whole words. */
|
|
19
|
+
function namedBy(o, text, ctx) {
|
|
20
|
+
const w = o.words;
|
|
21
|
+
if (w instanceof RegExp) {
|
|
22
|
+
const re = new RegExp(w.source, w.flags.replace('g', ''));
|
|
23
|
+
return re.exec(text)?.[0] ?? null;
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(w)) {
|
|
26
|
+
const spaced = ` ${(0, values_1.normalizeText)(text)} `;
|
|
27
|
+
return w.find((x) => spaced.includes(` ${(0, values_1.normalizeText)(x)} `)) ?? null;
|
|
28
|
+
}
|
|
29
|
+
return (0, transcript_1.matches)(w, text, ctx) ? text.trim() : null;
|
|
30
|
+
}
|
|
31
|
+
function optionValue(o, ctx) {
|
|
32
|
+
return o.value == null ? null : (0, values_1.toNumber)((0, evaluate_1.evalExpr)(o.value, ctx));
|
|
33
|
+
}
|
|
34
|
+
/** Numbers of a text in the reply language (figures or words), with the words said. */
|
|
35
|
+
function numbersIn(text, ctx) {
|
|
36
|
+
const parse = (0, locales_1.getLocale)(ctx.locale)?.parse?.numbers;
|
|
37
|
+
return parse ? parse(text) : [];
|
|
38
|
+
}
|
|
39
|
+
/** The option a number stands for: the same whole value, else within `closeRatio`, else its digits inside (one or none). */
|
|
40
|
+
function nearestOption(value, options, near) {
|
|
41
|
+
const whole = (n) => String(Math.floor(n));
|
|
42
|
+
const rules = [
|
|
43
|
+
(o) => Math.floor(value) === Math.floor(o.value),
|
|
44
|
+
(o) => o.value > 0 && Math.abs(value - o.value) / o.value <= near.closeRatio,
|
|
45
|
+
];
|
|
46
|
+
if (near.digitsInside) {
|
|
47
|
+
const min = near.digitsInside.minValue;
|
|
48
|
+
rules.push((o) => value >= min && whole(o.value).includes(whole(value)));
|
|
49
|
+
}
|
|
50
|
+
for (const rule of rules) {
|
|
51
|
+
const hits = options.filter(rule);
|
|
52
|
+
if (hits.length === 1)
|
|
53
|
+
return hits[0].key;
|
|
54
|
+
if (hits.length > 1)
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
exports.nearestOption = nearestOption;
|
|
60
|
+
/** Every option a text picks, by its words, then (with `numbers`) by a number nearest to its value; first words win. */
|
|
61
|
+
function picked(ctx, set, text) {
|
|
62
|
+
const s = setOf(ctx, set);
|
|
63
|
+
if (!enabled(s, ctx))
|
|
64
|
+
return [];
|
|
65
|
+
const out = new Map();
|
|
66
|
+
for (const [key, o] of Object.entries(s.options ?? {})) {
|
|
67
|
+
const said = namedBy(o, text, ctx);
|
|
68
|
+
if (said != null)
|
|
69
|
+
out.set(key, said);
|
|
70
|
+
}
|
|
71
|
+
if (s.numbers) {
|
|
72
|
+
const opts = Object.entries(s.options ?? {}).flatMap(([key, o]) => {
|
|
73
|
+
const v = optionValue(o, ctx);
|
|
74
|
+
return v == null ? [] : [{ key, value: v }];
|
|
75
|
+
});
|
|
76
|
+
for (const n of numbersIn(text, ctx)) {
|
|
77
|
+
const key = nearestOption(n.value, opts, s.numbers.nearest);
|
|
78
|
+
if (key != null && !out.has(key))
|
|
79
|
+
out.set(key, n.said);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [...out].map(([key, said]) => ({ key, said }));
|
|
83
|
+
}
|
|
84
|
+
exports.picked = picked;
|
|
85
|
+
/** The one option a text picks (`null`: none, or more than one). */
|
|
86
|
+
function chosen(ctx, set, text) {
|
|
87
|
+
const p = picked(ctx, set, text);
|
|
88
|
+
return p.length === 1 ? p[0] : null;
|
|
89
|
+
}
|
|
90
|
+
exports.chosen = chosen;
|
|
91
|
+
/** The options whose value a number of the text equals (whole units), in option order. */
|
|
92
|
+
function named(ctx, set, text) {
|
|
93
|
+
const s = setOf(ctx, set);
|
|
94
|
+
if (!enabled(s, ctx))
|
|
95
|
+
return [];
|
|
96
|
+
const nums = numbersIn(text, ctx).map((n) => Math.floor(n.value));
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const [key, o] of Object.entries(s.options ?? {})) {
|
|
99
|
+
const v = optionValue(o, ctx);
|
|
100
|
+
if (v != null && nums.includes(Math.floor(v)))
|
|
101
|
+
out.push(key);
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
exports.named = named;
|
|
106
|
+
/** The fields a note or a ladder reads of an option. */
|
|
107
|
+
function optionItem(ctx, set, key, said) {
|
|
108
|
+
const o = setOf(ctx, set).options?.[key];
|
|
109
|
+
return {
|
|
110
|
+
key, said,
|
|
111
|
+
name: o?.name ?? key,
|
|
112
|
+
spoken: o?.spoken != null ? (0, values_1.toText)((0, evaluate_1.evalExpr)(o.spoken, ctx)) : '',
|
|
113
|
+
value: o?.value != null ? (0, evaluate_1.evalExpr)(o.value, ctx) : null,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
exports.optionItem = optionItem;
|
|
117
|
+
// ── offers (./choices-offers) ─────────────────────────────────────────────────────────────────
|
|
118
|
+
/** The `{ choice, op }` expression (`text`: the expression's `of`, `null` when it has none). */
|
|
119
|
+
function choiceValue(ctx, set, op, text) {
|
|
120
|
+
const line = text ?? ctx.line ?? '';
|
|
121
|
+
switch (op) {
|
|
122
|
+
case 'chosen': return chosen(ctx, set, line)?.key ?? null;
|
|
123
|
+
case 'said': return chosen(ctx, set, line)?.said ?? null;
|
|
124
|
+
case 'picked': return picked(ctx, set, line).map((p) => p.key);
|
|
125
|
+
case 'named': return named(ctx, set, line);
|
|
126
|
+
}
|
|
127
|
+
const s = setOf(ctx, set);
|
|
128
|
+
if (!enabled(s, ctx))
|
|
129
|
+
return op === 'headers' ? {} : op === 'selected' ? [] : op === 'complete' || op === 'lastAsked' ? false : null;
|
|
130
|
+
switch (op) {
|
|
131
|
+
case 'offer': return (0, choices_offers_1.offerSelection)(s, ctx)?.offer ?? null;
|
|
132
|
+
case 'offerText': return (0, choices_offers_1.offerSelection)(s, ctx)?.text ?? null;
|
|
133
|
+
case 'selected': return (0, choices_offers_1.offerSelection)(s, ctx)?.chosen ?? [];
|
|
134
|
+
case 'complete': return (0, choices_offers_1.offerSelection)(s, ctx)?.complete ?? false;
|
|
135
|
+
case 'lastAsked': return (0, choices_offers_1.lastAsked)(s, ctx);
|
|
136
|
+
case 'interested': return (0, choices_offers_1.interestedText)(s, ctx);
|
|
137
|
+
case 'headers': return (0, choices_offers_1.offerHeaders)(s, ctx, text);
|
|
138
|
+
default: throw new Error(`[templates/choices] unknown op "${op}"`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.choiceValue = choiceValue;
|