@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,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The hooks' state of a call as the reducer sees it. Hooks keep one mutable object per call (`HookApi.state`, the
|
|
3
|
+
// store); the reducer never reads the store: it reads `EngineState.hookState`, a snapshot the host takes of the store
|
|
4
|
+
// before every event, and agent code inside the reduce (prompt variables, texts, matchers, `annotateCaller`) gets a
|
|
5
|
+
// draft copy of that snapshot as `call.hookState`. What it writes there comes out in the new state's snapshot, and the
|
|
6
|
+
// host commits those keys back to the store after the event. So `reduce(state, event)` is a function of its arguments.
|
|
7
|
+
//
|
|
8
|
+
// A snapshot copies plain data (objects whose prototype is `Object.prototype` or `null`, and arrays) and freezes the
|
|
9
|
+
// copy; anything else (class instances, functions, maps, dates, promises) is kept by reference — opaque values the
|
|
10
|
+
// hooks own (a recognizer, a planner), which the reducer only passes on.
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.commitHookState = exports.settleHookState = exports.hookStateChanges = exports.draftHookState = exports.snapshotHookState = void 0;
|
|
13
|
+
function isPlainObject(x) {
|
|
14
|
+
if (x == null || typeof x !== 'object' || Array.isArray(x))
|
|
15
|
+
return false;
|
|
16
|
+
const p = Object.getPrototypeOf(x);
|
|
17
|
+
return p === Object.prototype || p === null;
|
|
18
|
+
}
|
|
19
|
+
function copy(x, freeze, seen) {
|
|
20
|
+
if (Array.isArray(x)) {
|
|
21
|
+
const done = seen.get(x);
|
|
22
|
+
if (done !== undefined)
|
|
23
|
+
return done;
|
|
24
|
+
const out = [];
|
|
25
|
+
seen.set(x, out);
|
|
26
|
+
for (const v of x)
|
|
27
|
+
out.push(copy(v, freeze, seen));
|
|
28
|
+
return freeze ? Object.freeze(out) : out;
|
|
29
|
+
}
|
|
30
|
+
if (isPlainObject(x)) {
|
|
31
|
+
const done = seen.get(x);
|
|
32
|
+
if (done !== undefined)
|
|
33
|
+
return done;
|
|
34
|
+
const out = Object.getPrototypeOf(x) === null ? Object.create(null) : {};
|
|
35
|
+
seen.set(x, out);
|
|
36
|
+
for (const k of Object.keys(x))
|
|
37
|
+
out[k] = copy(x[k], freeze, seen);
|
|
38
|
+
return freeze ? Object.freeze(out) : out;
|
|
39
|
+
}
|
|
40
|
+
return x;
|
|
41
|
+
}
|
|
42
|
+
/** The store as the reducer reads it: its plain data copied and frozen, other values as they are. */
|
|
43
|
+
function snapshotHookState(store) {
|
|
44
|
+
return copy(store, true, new Map());
|
|
45
|
+
}
|
|
46
|
+
exports.snapshotHookState = snapshotHookState;
|
|
47
|
+
/** A writable copy of a snapshot (what agent code inside one reduce gets as `call.hookState`). */
|
|
48
|
+
function draftHookState(snapshot) {
|
|
49
|
+
return copy(snapshot, false, new Map());
|
|
50
|
+
}
|
|
51
|
+
exports.draftHookState = draftHookState;
|
|
52
|
+
function same(a, b, seen) {
|
|
53
|
+
if (Object.is(a, b))
|
|
54
|
+
return true;
|
|
55
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
56
|
+
if (a.length !== b.length)
|
|
57
|
+
return false;
|
|
58
|
+
if (seen.has(a))
|
|
59
|
+
return true;
|
|
60
|
+
seen.add(a);
|
|
61
|
+
return a.every((v, i) => same(v, b[i], seen));
|
|
62
|
+
}
|
|
63
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
64
|
+
const ka = Object.keys(a);
|
|
65
|
+
if (ka.length !== Object.keys(b).length || ka.some((k) => !Object.prototype.hasOwnProperty.call(b, k)))
|
|
66
|
+
return false;
|
|
67
|
+
if (seen.has(a))
|
|
68
|
+
return true;
|
|
69
|
+
seen.add(a);
|
|
70
|
+
return ka.every((k) => same(a[k], b[k], seen));
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
/** The keys a draft changed against the snapshot it was made of (set or replaced, and removed). */
|
|
75
|
+
function hookStateChanges(before, after) {
|
|
76
|
+
const set = Object.keys(after).filter((k) => !Object.prototype.hasOwnProperty.call(before, k) || !same(before[k], after[k], new Set()));
|
|
77
|
+
const removed = Object.keys(before).filter((k) => !Object.prototype.hasOwnProperty.call(after, k));
|
|
78
|
+
return { set, removed };
|
|
79
|
+
}
|
|
80
|
+
exports.hookStateChanges = hookStateChanges;
|
|
81
|
+
/** The new snapshot of a reduce: the old one when the draft changed nothing, else the draft frozen. */
|
|
82
|
+
function settleHookState(before, draft) {
|
|
83
|
+
const c = hookStateChanges(before, draft);
|
|
84
|
+
return c.set.length || c.removed.length ? snapshotHookState(draft) : before;
|
|
85
|
+
}
|
|
86
|
+
exports.settleHookState = settleHookState;
|
|
87
|
+
/**
|
|
88
|
+
* The commit after an event: the keys the reduce changed (`before` → `after`) written to the store as writable
|
|
89
|
+
* copies, removed keys deleted; keys it did not touch keep their values (hooks may hold them across an `await`).
|
|
90
|
+
*/
|
|
91
|
+
function commitHookState(store, before, after) {
|
|
92
|
+
if (before === after)
|
|
93
|
+
return;
|
|
94
|
+
const c = hookStateChanges(before, after);
|
|
95
|
+
for (const k of c.set)
|
|
96
|
+
store[k] = copy(after[k], false, new Map());
|
|
97
|
+
for (const k of c.removed)
|
|
98
|
+
delete store[k];
|
|
99
|
+
}
|
|
100
|
+
exports.commitHookState = commitHookState;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Action, AgentHooks, EngineSpec, HookKind, HookLegRoute, PlaySpec, SentenceVerdict } from '../spec';
|
|
2
|
+
/** One place of the agent file that names a hook. */
|
|
3
|
+
export interface HookUse {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly kind: HookKind;
|
|
7
|
+
}
|
|
8
|
+
/** Reports an answer of a hook that is not what its kind returns (it is ignored). */
|
|
9
|
+
export type InvalidHookResult = (name: string, kind: HookKind, reason: string) => void;
|
|
10
|
+
/** Every hook the agent file names, with where and as what kind. */
|
|
11
|
+
export declare function hookUses(spec: EngineSpec): HookUse[];
|
|
12
|
+
/** Fails at definition when the agent file names a hook that `hooks` does not have (or that is not a function). */
|
|
13
|
+
export declare function checkHookNames(spec: EngineSpec, hooks: AgentHooks | undefined): void;
|
|
14
|
+
/** The actions of a hook's answer that can run; the others are reported and dropped. */
|
|
15
|
+
export declare function hookActions(out: unknown, transfer: boolean, invalid: (reason: string) => void): Action[];
|
|
16
|
+
/** A text answer (`closingGuard`, `transferVeto`, `cutMark`, `label`): the text, or `null` for nothing / a bad answer. */
|
|
17
|
+
export declare function hookText(out: unknown, invalid: (reason: string) => void): string | null;
|
|
18
|
+
/** `turn.review` at the start of a turn: `{ holdChars }` or `null`. */
|
|
19
|
+
export declare function reviewStart(out: unknown, invalid: (reason: string) => void): {
|
|
20
|
+
holdChars: number;
|
|
21
|
+
} | null;
|
|
22
|
+
/** `turn.review` on the held text: `null`, `'release'`, `{ regenerate }` or `{ then }` (its actions checked). */
|
|
23
|
+
export declare function reviewVerdict(out: unknown, transfer: boolean, invalid: (reason: string) => void): null | 'release' | {
|
|
24
|
+
readonly regenerate: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly then: readonly Action[];
|
|
27
|
+
};
|
|
28
|
+
/** A `stream` filter's answer: the text to pass on now, `then` actions (checked) and `vars`; a bad answer passes nothing. */
|
|
29
|
+
export declare function replyChunkAnswer(out: unknown, transfer: boolean, invalid: (reason: string) => void): {
|
|
30
|
+
readonly text: string;
|
|
31
|
+
readonly then?: readonly Action[];
|
|
32
|
+
readonly vars?: Readonly<Record<string, unknown>>;
|
|
33
|
+
readonly clip?: {
|
|
34
|
+
readonly play: PlaySpec;
|
|
35
|
+
readonly line: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** A `sentences` filter's verdict on one sentence; a bad one keeps the sentence as it is. */
|
|
39
|
+
export declare function sentenceVerdict(out: unknown, sentence: string, invalid: (reason: string) => void): SentenceVerdict;
|
|
40
|
+
/** `results.decide`: a label, nothing, or `{ result?, recall?, entities?, extractedResult? }`; a bad answer is nothing. */
|
|
41
|
+
export declare function decideAnswer(out: unknown, invalid: (reason: string) => void): unknown;
|
|
42
|
+
/** `extraction.normalize`: the entities as an object; anything else leaves them as they were. */
|
|
43
|
+
export declare function normalizedEntities(out: unknown, invalid: (reason: string) => void): Record<string, unknown> | null;
|
|
44
|
+
/** `platform.legs.route`: `{ msisdn, channel?, trunkId?, protoAdditional? }` or `null`. */
|
|
45
|
+
export declare function legRoute(out: unknown, invalid: (reason: string) => void): HookLegRoute | null;
|
|
46
|
+
/** A yes/no answer (`replayHold`): `true` only for `true`; anything else but nothing is reported. */
|
|
47
|
+
export declare function hookYes(out: unknown, invalid: (reason: string) => void): boolean;
|
|
48
|
+
/** `transfer.toolReply`: `'over'`, `'drop'` or `null`. */
|
|
49
|
+
export declare function toolReplyVerdict(out: unknown, invalid: (reason: string) => void): 'over' | 'drop' | null;
|
|
50
|
+
/** A promise where the kind answers at once. */
|
|
51
|
+
export declare function isPromise(x: unknown): boolean;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPromise = exports.toolReplyVerdict = exports.hookYes = exports.legRoute = exports.normalizedEntities = exports.decideAnswer = exports.sentenceVerdict = exports.replyChunkAnswer = exports.reviewVerdict = exports.reviewStart = exports.hookText = exports.hookActions = exports.checkHookNames = exports.hookUses = void 0;
|
|
4
|
+
const slots_1 = require("../expr/slots");
|
|
5
|
+
const list = (x) => (x == null ? [] : Array.isArray(x) ? x : [x]);
|
|
6
|
+
/** Every hook the agent file names, with where and as what kind. */
|
|
7
|
+
function hookUses(spec) {
|
|
8
|
+
const out = [];
|
|
9
|
+
const use = (path, name, kind) => {
|
|
10
|
+
if (name != null)
|
|
11
|
+
out.push({ path, name, kind });
|
|
12
|
+
};
|
|
13
|
+
const actions = (path, x) => {
|
|
14
|
+
for (const [i, a] of list(x).entries())
|
|
15
|
+
if (a && typeof a === 'object' && 'hook' in a)
|
|
16
|
+
use(`${path}[${i}].hook`, a.hook, 'action');
|
|
17
|
+
};
|
|
18
|
+
const rungs = (path, r) => {
|
|
19
|
+
for (const [i, x] of (r ?? []).entries()) {
|
|
20
|
+
actions(`${path}[${i}].do`, x.do);
|
|
21
|
+
actions(`${path}[${i}].otherwise`, x.otherwise);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const p = spec.platform;
|
|
25
|
+
use('platform.beforeCall', p.beforeCall?.hook, 'beforeCall');
|
|
26
|
+
use('platform.afterLeg', (0, slots_1.hookName)(p.afterLeg), 'afterLeg');
|
|
27
|
+
use('platform.legs.route', p.legs?.route?.hook, 'route');
|
|
28
|
+
if (spec.input.lookup?.hook)
|
|
29
|
+
use('input.lookup', spec.input.lookup.hook, 'lookup');
|
|
30
|
+
for (const [i, st] of spec.opening.entries()) {
|
|
31
|
+
if (st.step === 'hook')
|
|
32
|
+
use(`opening[${i}].name`, st.name, 'step');
|
|
33
|
+
if (st.step === 'listen')
|
|
34
|
+
rungs(`opening[${i}].silence`, st.silence);
|
|
35
|
+
}
|
|
36
|
+
const t = spec.turn;
|
|
37
|
+
if (t) {
|
|
38
|
+
for (const [i, f] of (t.filters ?? []).entries()) {
|
|
39
|
+
if (f.filter === 'hook')
|
|
40
|
+
use(`turn.filters[${i}].name`, f.name, 'replyText');
|
|
41
|
+
else if (f.filter === 'sentences')
|
|
42
|
+
use(`turn.filters[${i}].hook`, f.hook, 'sentence');
|
|
43
|
+
else if (f.filter === 'stream')
|
|
44
|
+
use(`turn.filters[${i}].hook`, f.hook, 'replyChunk');
|
|
45
|
+
else if (f.filter === 'labels' && 'hook' in f.lines && typeof f.lines.hook === 'string')
|
|
46
|
+
use(`turn.filters[${i}].lines.hook`, f.lines.hook, 'label');
|
|
47
|
+
}
|
|
48
|
+
use('turn.replyPlayed', t.replyPlayed?.hook, 'replyPlayed');
|
|
49
|
+
use('turn.review', (0, slots_1.hookName)(t.review), 'review');
|
|
50
|
+
actions('turn.emptyReply.onExhausted', t.emptyReply?.onExhausted);
|
|
51
|
+
actions('turn.maxLines.do', t.maxLines?.do);
|
|
52
|
+
}
|
|
53
|
+
use('overtalk.cutMark', (0, slots_1.hookName)(spec.overtalk?.cutMark), 'cutMark');
|
|
54
|
+
use('overtalk.buffer.holdWhileSpeaking.extend', (0, slots_1.hookName)(spec.overtalk?.buffer?.holdWhileSpeaking?.extend), 'replayHold');
|
|
55
|
+
const s = spec.silence;
|
|
56
|
+
if (s) {
|
|
57
|
+
rungs('silence.ladder', s.ladder);
|
|
58
|
+
rungs('silence.held.rungs', s.held?.rungs);
|
|
59
|
+
actions('silence.speechWithoutText.do', s.speechWithoutText?.do);
|
|
60
|
+
actions('silence.deadAudio.do', s.deadAudio?.do);
|
|
61
|
+
actions('silence.noProgress.do', s.noProgress?.do);
|
|
62
|
+
actions('silence.noProgress.inOpening', s.noProgress?.inOpening);
|
|
63
|
+
}
|
|
64
|
+
actions('voicemail.then', spec.voicemail?.then);
|
|
65
|
+
for (const [i, r] of (spec.rules ?? []).entries())
|
|
66
|
+
actions(`rules[${i}].then`, r.then);
|
|
67
|
+
for (const g of spec.gates ?? [])
|
|
68
|
+
actions(`gates.${g.id}.onExhausted`, g.onExhausted);
|
|
69
|
+
use('closing.guard.replace', (0, slots_1.hookName)(spec.closing?.guard?.replace), 'closingGuard');
|
|
70
|
+
use('transfer.veto', (0, slots_1.hookName)(spec.transfer?.veto), 'transferVeto');
|
|
71
|
+
use('transfer.toolReply', (0, slots_1.hookName)(spec.transfer?.toolReply), 'toolReply');
|
|
72
|
+
const norm = spec.extraction?.normalize;
|
|
73
|
+
if (norm && !Array.isArray(norm))
|
|
74
|
+
use('extraction.normalize', norm.hook, 'normalize');
|
|
75
|
+
use('results.decide', spec.results.decide?.hook, 'decide');
|
|
76
|
+
for (const [i, x] of (spec.integrations ?? []).entries()) {
|
|
77
|
+
if ('run' in x)
|
|
78
|
+
use(`integrations[${i}].run`, x.run.hook, 'integration');
|
|
79
|
+
else if ('body' in x && x.body && typeof x.body === 'object')
|
|
80
|
+
use(`integrations[${i}].body`, (0, slots_1.hookName)(x.body), 'body');
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
exports.hookUses = hookUses;
|
|
85
|
+
/** Fails at definition when the agent file names a hook that `hooks` does not have (or that is not a function). */
|
|
86
|
+
function checkHookNames(spec, hooks) {
|
|
87
|
+
const missing = hookUses(spec).filter((u) => typeof hooks?.[u.name] !== 'function');
|
|
88
|
+
if (missing.length) {
|
|
89
|
+
throw new Error(`[templates/engine] ${missing.map((u) => `${u.path}: no hook "${u.name}"`).join('; ')}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.checkHookNames = checkHookNames;
|
|
93
|
+
/** Keys of each action (the first is the action's own; the rest its options). */
|
|
94
|
+
const ACTION_KEYS = {
|
|
95
|
+
say: ['say', 'alias', 'speechOver'],
|
|
96
|
+
play: ['play'],
|
|
97
|
+
llm: ['llm'],
|
|
98
|
+
mark: ['mark'],
|
|
99
|
+
hold: ['hold'],
|
|
100
|
+
next: ['next'],
|
|
101
|
+
close: ['close', 'result', 'reason', 'alias'],
|
|
102
|
+
hangup: ['hangup', 'result', 'graceMs'],
|
|
103
|
+
transfer: ['transfer'],
|
|
104
|
+
flag: ['flag', 'value'],
|
|
105
|
+
set: ['set', 'value'],
|
|
106
|
+
};
|
|
107
|
+
/** Why an action a hook returned cannot run (`null`: it can). */
|
|
108
|
+
function actionProblem(a, transfer) {
|
|
109
|
+
if (a == null || typeof a !== 'object' || Array.isArray(a))
|
|
110
|
+
return `not an action: ${preview(a)}`;
|
|
111
|
+
const keys = Object.keys(a);
|
|
112
|
+
if ('hook' in a)
|
|
113
|
+
return 'a hook action in a hook answer';
|
|
114
|
+
const own = keys.filter((k) => k in ACTION_KEYS);
|
|
115
|
+
if (own.length !== 1)
|
|
116
|
+
return own.length ? `more than one action in one object: ${own.join(', ')}` : `unknown action: ${keys.join(', ') || '{}'}`;
|
|
117
|
+
const kind = own[0];
|
|
118
|
+
const extra = keys.filter((k) => !ACTION_KEYS[kind].includes(k));
|
|
119
|
+
if (extra.length)
|
|
120
|
+
return `unknown keys of a ${kind} action: ${extra.join(', ')}`;
|
|
121
|
+
if (kind === 'transfer' && !transfer)
|
|
122
|
+
return 'transfer action without a transfer block';
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
/** The actions of a hook's answer that can run; the others are reported and dropped. */
|
|
126
|
+
function hookActions(out, transfer, invalid) {
|
|
127
|
+
if (out == null)
|
|
128
|
+
return [];
|
|
129
|
+
const all = Array.isArray(out) ? out : [out];
|
|
130
|
+
const ok = [];
|
|
131
|
+
for (const a of all) {
|
|
132
|
+
const problem = actionProblem(a, transfer);
|
|
133
|
+
if (problem)
|
|
134
|
+
invalid(problem);
|
|
135
|
+
else
|
|
136
|
+
ok.push(a);
|
|
137
|
+
}
|
|
138
|
+
return ok;
|
|
139
|
+
}
|
|
140
|
+
exports.hookActions = hookActions;
|
|
141
|
+
/** A text answer (`closingGuard`, `transferVeto`, `cutMark`, `label`): the text, or `null` for nothing / a bad answer. */
|
|
142
|
+
function hookText(out, invalid) {
|
|
143
|
+
if (out == null)
|
|
144
|
+
return null;
|
|
145
|
+
if (typeof out === 'string')
|
|
146
|
+
return out || null;
|
|
147
|
+
invalid(`not a text: ${preview(out)}`);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
exports.hookText = hookText;
|
|
151
|
+
/** `turn.review` at the start of a turn: `{ holdChars }` or `null`. */
|
|
152
|
+
function reviewStart(out, invalid) {
|
|
153
|
+
if (out == null)
|
|
154
|
+
return null;
|
|
155
|
+
if (typeof out === 'object' && typeof out.holdChars === 'number' && Object.keys(out).length === 1) {
|
|
156
|
+
return { holdChars: out.holdChars };
|
|
157
|
+
}
|
|
158
|
+
invalid(`not { holdChars } or null at the start of a turn: ${preview(out)}`);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
exports.reviewStart = reviewStart;
|
|
162
|
+
/** `turn.review` on the held text: `null`, `'release'`, `{ regenerate }` or `{ then }` (its actions checked). */
|
|
163
|
+
function reviewVerdict(out, transfer, invalid) {
|
|
164
|
+
if (out == null)
|
|
165
|
+
return null;
|
|
166
|
+
if (out === 'release')
|
|
167
|
+
return 'release';
|
|
168
|
+
const o = out;
|
|
169
|
+
if (typeof out === 'object' && Object.keys(out).length === 1) {
|
|
170
|
+
if ('regenerate' in o && typeof o.regenerate === 'string')
|
|
171
|
+
return { regenerate: o.regenerate };
|
|
172
|
+
if ('then' in o && o.then != null)
|
|
173
|
+
return { then: hookActions(o.then, transfer, invalid) };
|
|
174
|
+
}
|
|
175
|
+
invalid(`not null, 'release', { regenerate } or { then } on the held text: ${preview(out)}`);
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
exports.reviewVerdict = reviewVerdict;
|
|
179
|
+
/** A `stream` filter's answer: the text to pass on now, `then` actions (checked) and `vars`; a bad answer passes nothing. */
|
|
180
|
+
function replyChunkAnswer(out, transfer, invalid) {
|
|
181
|
+
if (out == null || typeof out === 'string')
|
|
182
|
+
return { text: out ?? '' };
|
|
183
|
+
if (typeof out === 'object' && !Array.isArray(out)) {
|
|
184
|
+
const o = out;
|
|
185
|
+
const extra = Object.keys(o).filter((k) => k !== 'text' && k !== 'then' && k !== 'vars' && k !== 'clip');
|
|
186
|
+
const clip = o['clip'];
|
|
187
|
+
const bad = extra.length ? `unknown keys: ${extra.join(', ')}`
|
|
188
|
+
: o['text'] !== undefined && typeof o['text'] !== 'string' ? 'text is not a text'
|
|
189
|
+
: o['vars'] !== undefined && (o['vars'] === null || typeof o['vars'] !== 'object' || Array.isArray(o['vars'])) ? 'vars is not an object'
|
|
190
|
+
: clip !== undefined && (clip === null || typeof clip !== 'object' || clip.play == null || typeof clip.play !== 'object' || typeof clip.line !== 'string')
|
|
191
|
+
? 'clip is not { play, line }'
|
|
192
|
+
: null;
|
|
193
|
+
if (!bad) {
|
|
194
|
+
return {
|
|
195
|
+
text: o['text'] ?? '',
|
|
196
|
+
...(o['then'] != null ? { then: hookActions(o['then'], transfer, invalid) } : {}),
|
|
197
|
+
...(o['vars'] != null ? { vars: o['vars'] } : {}),
|
|
198
|
+
...(clip != null ? { clip: clip } : {}),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
invalid(bad);
|
|
202
|
+
return { text: '' };
|
|
203
|
+
}
|
|
204
|
+
invalid(`not a text or { text, then, vars, clip }: ${preview(out)}`);
|
|
205
|
+
return { text: '' };
|
|
206
|
+
}
|
|
207
|
+
exports.replyChunkAnswer = replyChunkAnswer;
|
|
208
|
+
/** A `sentences` filter's verdict on one sentence; a bad one keeps the sentence as it is. */
|
|
209
|
+
function sentenceVerdict(out, sentence, invalid) {
|
|
210
|
+
if (out == null || typeof out === 'string')
|
|
211
|
+
return out ?? null;
|
|
212
|
+
if (typeof out === 'object') {
|
|
213
|
+
const o = out;
|
|
214
|
+
const keys = Object.keys(o);
|
|
215
|
+
if (o['cut'] === true && keys.length === 1)
|
|
216
|
+
return { cut: true };
|
|
217
|
+
const close = o['close'];
|
|
218
|
+
if (typeof o['replace'] === 'string' && keys.every((k) => k === 'replace' || k === 'alias' || k === 'close')
|
|
219
|
+
&& (o['alias'] === undefined || typeof o['alias'] === 'string')
|
|
220
|
+
&& (close === undefined || (close != null && typeof close === 'object' && typeof close.result === 'string'))) {
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
invalid(`not a sentence verdict: ${preview(out)}`);
|
|
225
|
+
return sentence;
|
|
226
|
+
}
|
|
227
|
+
exports.sentenceVerdict = sentenceVerdict;
|
|
228
|
+
/** `results.decide`: a label, nothing, or `{ result?, recall?, entities?, extractedResult? }`; a bad answer is nothing. */
|
|
229
|
+
function decideAnswer(out, invalid) {
|
|
230
|
+
if (out == null || typeof out === 'string')
|
|
231
|
+
return out;
|
|
232
|
+
if (typeof out === 'object' && !Array.isArray(out)) {
|
|
233
|
+
const o = out;
|
|
234
|
+
const allowed = ['result', 'recall', 'entities', 'extractedResult'];
|
|
235
|
+
const extra = Object.keys(o).filter((k) => !allowed.includes(k));
|
|
236
|
+
const bad = extra.length ? `unknown keys: ${extra.join(', ')}`
|
|
237
|
+
: o['result'] !== undefined && typeof o['result'] !== 'string' ? 'result is not a text'
|
|
238
|
+
: o['recall'] !== undefined && typeof o['recall'] !== 'boolean' ? 'recall is not a boolean'
|
|
239
|
+
: o['entities'] !== undefined && (o['entities'] === null || typeof o['entities'] !== 'object') ? 'entities is not an object'
|
|
240
|
+
: o['extractedResult'] !== undefined && o['extractedResult'] !== null && typeof o['extractedResult'] !== 'string' ? 'extractedResult is not a text'
|
|
241
|
+
: null;
|
|
242
|
+
if (!bad)
|
|
243
|
+
return out;
|
|
244
|
+
invalid(bad);
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
invalid(`not a label or a decision: ${preview(out)}`);
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
exports.decideAnswer = decideAnswer;
|
|
251
|
+
/** `extraction.normalize`: the entities as an object; anything else leaves them as they were. */
|
|
252
|
+
function normalizedEntities(out, invalid) {
|
|
253
|
+
if (out == null)
|
|
254
|
+
return null;
|
|
255
|
+
if (typeof out === 'object' && !Array.isArray(out))
|
|
256
|
+
return out;
|
|
257
|
+
invalid(`not the entities: ${preview(out)}`);
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
exports.normalizedEntities = normalizedEntities;
|
|
261
|
+
/** `platform.legs.route`: `{ msisdn, channel?, trunkId?, protoAdditional? }` or `null`. */
|
|
262
|
+
function legRoute(out, invalid) {
|
|
263
|
+
if (out == null)
|
|
264
|
+
return null;
|
|
265
|
+
const o = out;
|
|
266
|
+
if (typeof out === 'object' && typeof o['msisdn'] === 'string'
|
|
267
|
+
&& Object.keys(o).every((k) => k === 'msisdn' || k === 'channel' || k === 'trunkId' || k === 'protoAdditional')
|
|
268
|
+
&& (o['channel'] === undefined || typeof o['channel'] === 'string')
|
|
269
|
+
&& (o['trunkId'] === undefined || typeof o['trunkId'] === 'number')
|
|
270
|
+
&& (o['protoAdditional'] === undefined || (o['protoAdditional'] != null && typeof o['protoAdditional'] === 'object'))) {
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
invalid(`not a leg route: ${preview(out)}`);
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
exports.legRoute = legRoute;
|
|
277
|
+
/** A yes/no answer (`replayHold`): `true` only for `true`; anything else but nothing is reported. */
|
|
278
|
+
function hookYes(out, invalid) {
|
|
279
|
+
if (out == null || typeof out === 'boolean')
|
|
280
|
+
return out === true;
|
|
281
|
+
invalid(`not a boolean: ${preview(out)}`);
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
exports.hookYes = hookYes;
|
|
285
|
+
/** `transfer.toolReply`: `'over'`, `'drop'` or `null`. */
|
|
286
|
+
function toolReplyVerdict(out, invalid) {
|
|
287
|
+
if (out == null)
|
|
288
|
+
return null;
|
|
289
|
+
if (out === 'over' || out === 'drop')
|
|
290
|
+
return out;
|
|
291
|
+
invalid(`not 'over', 'drop' or null: ${preview(out)}`);
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
exports.toolReplyVerdict = toolReplyVerdict;
|
|
295
|
+
/** A promise where the kind answers at once. */
|
|
296
|
+
function isPromise(x) {
|
|
297
|
+
return x != null && typeof x.then === 'function';
|
|
298
|
+
}
|
|
299
|
+
exports.isPromise = isPromise;
|
|
300
|
+
function preview(x) {
|
|
301
|
+
if (isPromise(x))
|
|
302
|
+
return 'a promise';
|
|
303
|
+
try {
|
|
304
|
+
const s = JSON.stringify(x);
|
|
305
|
+
return s === undefined ? String(x) : s.length > 120 ? `${s.slice(0, 120)}…` : s;
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return String(x);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { defineVoiceAgent } from './define';
|
|
2
|
+
export { createEngineDialog, initialEngineState, transcriptLines } from './dialog';
|
|
3
|
+
export type { EngineCallFacts, EngineDialog, EngineEffect, EngineEvent, EngineLine, EngineState } from './dialog';
|
|
4
|
+
export { engineDialogConfig } from './config';
|
|
5
|
+
export type { EngineDialogConfig, EnginePlay, EngineRule, EngineRung, ResultPoint, ResultRule } from './config';
|
|
6
|
+
export { compileMatcher, lineWords, matcherPatterns, normalizeLine, NotRunByEngine, resolveText, spacedLine } from './match';
|
|
7
|
+
export type { LineTest } from './match';
|
|
8
|
+
export { flattenLines, languageLadder } from './language';
|
|
9
|
+
export type { LanguageLadder, LanguagePick } from './language';
|
|
10
|
+
export { replyFilters, respellByWord, respellText } from './filters';
|
|
11
|
+
export { EngineMedia, type EngineMediaSettings } from './media';
|
|
12
|
+
export type { SilenceFacts, VoiceEffect, VoiceEvent, VoiceSnapshot } from './voice-dialog';
|
|
13
|
+
export type { EngineGate, VoiceDialogConfig, VoiceStep } from './config';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EngineMedia = exports.respellText = exports.respellByWord = exports.replyFilters = exports.languageLadder = exports.flattenLines = exports.spacedLine = exports.resolveText = exports.NotRunByEngine = exports.normalizeLine = exports.matcherPatterns = exports.lineWords = exports.compileMatcher = exports.engineDialogConfig = exports.transcriptLines = exports.initialEngineState = exports.createEngineDialog = exports.defineVoiceAgent = void 0;
|
|
4
|
+
// The conversation engine: one reducer driven by the agent file's blocks, and `defineVoiceAgent`, the whole agent
|
|
5
|
+
// from its agent file.
|
|
6
|
+
var define_1 = require("./define");
|
|
7
|
+
Object.defineProperty(exports, "defineVoiceAgent", { enumerable: true, get: function () { return define_1.defineVoiceAgent; } });
|
|
8
|
+
var dialog_1 = require("./dialog");
|
|
9
|
+
Object.defineProperty(exports, "createEngineDialog", { enumerable: true, get: function () { return dialog_1.createEngineDialog; } });
|
|
10
|
+
Object.defineProperty(exports, "initialEngineState", { enumerable: true, get: function () { return dialog_1.initialEngineState; } });
|
|
11
|
+
Object.defineProperty(exports, "transcriptLines", { enumerable: true, get: function () { return dialog_1.transcriptLines; } });
|
|
12
|
+
var config_1 = require("./config");
|
|
13
|
+
Object.defineProperty(exports, "engineDialogConfig", { enumerable: true, get: function () { return config_1.engineDialogConfig; } });
|
|
14
|
+
var match_1 = require("./match");
|
|
15
|
+
Object.defineProperty(exports, "compileMatcher", { enumerable: true, get: function () { return match_1.compileMatcher; } });
|
|
16
|
+
Object.defineProperty(exports, "lineWords", { enumerable: true, get: function () { return match_1.lineWords; } });
|
|
17
|
+
Object.defineProperty(exports, "matcherPatterns", { enumerable: true, get: function () { return match_1.matcherPatterns; } });
|
|
18
|
+
Object.defineProperty(exports, "normalizeLine", { enumerable: true, get: function () { return match_1.normalizeLine; } });
|
|
19
|
+
Object.defineProperty(exports, "NotRunByEngine", { enumerable: true, get: function () { return match_1.NotRunByEngine; } });
|
|
20
|
+
Object.defineProperty(exports, "resolveText", { enumerable: true, get: function () { return match_1.resolveText; } });
|
|
21
|
+
Object.defineProperty(exports, "spacedLine", { enumerable: true, get: function () { return match_1.spacedLine; } });
|
|
22
|
+
var language_1 = require("./language");
|
|
23
|
+
Object.defineProperty(exports, "flattenLines", { enumerable: true, get: function () { return language_1.flattenLines; } });
|
|
24
|
+
Object.defineProperty(exports, "languageLadder", { enumerable: true, get: function () { return language_1.languageLadder; } });
|
|
25
|
+
var filters_1 = require("./filters");
|
|
26
|
+
Object.defineProperty(exports, "replyFilters", { enumerable: true, get: function () { return filters_1.replyFilters; } });
|
|
27
|
+
Object.defineProperty(exports, "respellByWord", { enumerable: true, get: function () { return filters_1.respellByWord; } });
|
|
28
|
+
Object.defineProperty(exports, "respellText", { enumerable: true, get: function () { return filters_1.respellText; } });
|
|
29
|
+
var media_1 = require("./media");
|
|
30
|
+
Object.defineProperty(exports, "EngineMedia", { enumerable: true, get: function () { return media_1.EngineMedia; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CallView, LanguageCallVar, PromptSpec } from '../spec';
|
|
2
|
+
import type { LocaleCode } from '../locale';
|
|
3
|
+
/** The usual set, `prompt.callVars: true`. */
|
|
4
|
+
export declare const DEFAULT_CALL_VARS: Readonly<Record<string, LanguageCallVar>>;
|
|
5
|
+
/** The call variables of the prompt (`null`: none declared, or `callVars: false`). */
|
|
6
|
+
export declare function languageCallVars(prompt: Pick<PromptSpec, 'callVars' | 'languageNames'>, languages: readonly LocaleCode[]): ((call: CallView) => Readonly<Record<string, unknown>>) | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.languageCallVars = exports.DEFAULT_CALL_VARS = void 0;
|
|
4
|
+
/** The usual set, `prompt.callVars: true`. */
|
|
5
|
+
exports.DEFAULT_CALL_VARS = {
|
|
6
|
+
reply_language: 'languageName',
|
|
7
|
+
reply_language_provisional: 'languageProvisional',
|
|
8
|
+
opening_language: 'languageName',
|
|
9
|
+
};
|
|
10
|
+
/** The call variables of the prompt (`null`: none declared, or `callVars: false`). */
|
|
11
|
+
function languageCallVars(prompt, languages) {
|
|
12
|
+
void languages;
|
|
13
|
+
const declared = prompt.callVars;
|
|
14
|
+
if (declared == null || declared === false)
|
|
15
|
+
return null;
|
|
16
|
+
const vars = declared === true ? exports.DEFAULT_CALL_VARS : declared;
|
|
17
|
+
if (!vars || !Object.keys(vars).length)
|
|
18
|
+
return null;
|
|
19
|
+
const names = (prompt.languageNames ?? {});
|
|
20
|
+
const entries = Object.entries(vars);
|
|
21
|
+
return (call) => {
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const [key, fact] of entries) {
|
|
24
|
+
switch (fact) {
|
|
25
|
+
case 'languageName':
|
|
26
|
+
out[key] = names[call.language] ?? call.language;
|
|
27
|
+
break;
|
|
28
|
+
case 'languageProvisional':
|
|
29
|
+
out[key] = call.languageProvisional;
|
|
30
|
+
break;
|
|
31
|
+
case 'language':
|
|
32
|
+
out[key] = call.language;
|
|
33
|
+
break;
|
|
34
|
+
default: throw new Error(`[templates/engine] prompt.callVars.${key}: unknown fact "${String(fact)}"`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.languageCallVars = languageCallVars;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LocaleCode } from '../locale';
|
|
2
|
+
/** What the ladder decided for one line. `reason` names the rung (with the language as the prompt names it). */
|
|
3
|
+
export interface LanguagePick {
|
|
4
|
+
readonly language: LocaleCode;
|
|
5
|
+
readonly reason: string;
|
|
6
|
+
readonly provisional: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface LanguageLadder {
|
|
9
|
+
readonly languages: readonly LocaleCode[];
|
|
10
|
+
/** The pick from a line (`null`: nothing said — the first language, provisional). */
|
|
11
|
+
decide(text: string | null): LanguagePick;
|
|
12
|
+
/** A language the caller asks for (or the other one when they refuse one), `null` when the line asks nothing. */
|
|
13
|
+
requested(text: string): LocaleCode | null;
|
|
14
|
+
/** For a one-way fallback to `to`: the line is plainly in `to` (`'fallback'`), in another call language, or says nothing. */
|
|
15
|
+
fallbackEvidence(text: string, to: LocaleCode): 'fallback' | 'other' | null;
|
|
16
|
+
/** How the prompt names a language. */
|
|
17
|
+
name(code: LocaleCode): string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The ladder for the call's languages. `neutral`: the agent's own words that carry no evidence (brand names); `strong`:
|
|
21
|
+
* the agent's own strong markers.
|
|
22
|
+
*/
|
|
23
|
+
export declare function languageLadder(languages: readonly LocaleCode[], opts?: {
|
|
24
|
+
readonly neutral?: readonly string[];
|
|
25
|
+
/** Words of the packs' neutral lists this agent reads as evidence after all. */
|
|
26
|
+
readonly notNeutral?: readonly string[];
|
|
27
|
+
readonly names?: Partial<Record<LocaleCode, string>>;
|
|
28
|
+
/** The agent's own strong markers, added to the pack's. */
|
|
29
|
+
readonly strong?: Partial<Record<LocaleCode, readonly RegExp[]>>;
|
|
30
|
+
}): LanguageLadder;
|
|
31
|
+
/** Lines of an answer joined for a marker (`a | b`). */
|
|
32
|
+
export declare function flattenLines(text: string): string;
|