@voctiv/agent-runtime 0.2.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -20
- package/dist/barge-in/barge-in-module.d.ts +0 -1
- package/dist/barge-in/barge-in-module.js +0 -1
- package/dist/barge-in/barge-in-service.d.ts +1 -1
- package/dist/barge-in/barge-in-service.js +33 -2
- package/dist/barge-in/barge-in-strategy.d.ts +11 -9
- package/dist/barge-in/barge-in-strategy.js +39 -23
- package/dist/barge-in/echo-cancellation.d.ts +0 -1
- package/dist/barge-in/echo-cancellation.js +0 -1
- package/dist/barge-in/echo.d.ts +0 -1
- package/dist/barge-in/echo.js +0 -1
- package/dist/barge-in/lexicon.d.ts +0 -1
- package/dist/barge-in/lexicon.js +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 +16 -23
- package/docs/framework/testing.md +8 -6
- package/package.json +10 -54
- package/skill/SKILL.md +213 -0
- package/skill/references/agent-file.md +230 -0
- package/skill/references/blocks.md +246 -0
- package/skill/references/builder.md +163 -0
- package/skill/references/business.md +659 -0
- package/skill/references/conversation.md +586 -0
- package/skill/references/core.md +89 -0
- package/skill/references/examples.md +73 -0
- package/skill/references/expressions.md +342 -0
- package/skill/references/format.md +114 -0
- package/skill/references/locales.md +149 -0
- package/skill/references/migration.md +133 -0
- package/skill/references/new-agent.md +81 -0
- package/skill/references/porting.md +109 -0
- package/templates/agent/README.md +50 -0
- package/templates/agent/package.json +24 -0
- package/templates/agent/src/agent.spec.ts +51 -0
- package/templates/agent/src/agent.ts +268 -0
- package/templates/agent/src/entities.ts +44 -0
- package/templates/agent/src/prompt.sqrl +21 -0
- package/templates/agent/src/variants/fixed-opening.ts +144 -0
- package/templates/agent/tsconfig.build.json +4 -0
- package/templates/agent/tsconfig.json +18 -0
- package/dist/asr/index.d.ts +0 -3
- package/dist/asr/index.d.ts.map +0 -1
- package/dist/asr/index.js +0 -6
- package/dist/asr/index.js.map +0 -1
- package/dist/barge-in/barge-in-module.d.ts.map +0 -1
- package/dist/barge-in/barge-in-module.js.map +0 -1
- package/dist/barge-in/barge-in-service.d.ts.map +0 -1
- package/dist/barge-in/barge-in-service.js.map +0 -1
- package/dist/barge-in/barge-in-strategy.d.ts.map +0 -1
- package/dist/barge-in/barge-in-strategy.js.map +0 -1
- package/dist/barge-in/echo-cancellation.d.ts.map +0 -1
- package/dist/barge-in/echo-cancellation.js.map +0 -1
- package/dist/barge-in/echo.d.ts.map +0 -1
- package/dist/barge-in/echo.js.map +0 -1
- package/dist/barge-in/index.d.ts +0 -13
- package/dist/barge-in/index.d.ts.map +0 -1
- package/dist/barge-in/index.js +0 -28
- package/dist/barge-in/index.js.map +0 -1
- package/dist/barge-in/lexicon.d.ts.map +0 -1
- package/dist/barge-in/lexicon.js.map +0 -1
- package/dist/barge-in/lexicons/en.d.ts +0 -2
- package/dist/barge-in/lexicons/en.d.ts.map +0 -1
- package/dist/barge-in/lexicons/en.js +0 -36
- package/dist/barge-in/lexicons/en.js.map +0 -1
- package/dist/barge-in/lexicons/id.d.ts +0 -2
- package/dist/barge-in/lexicons/id.d.ts.map +0 -1
- package/dist/barge-in/lexicons/id.js +0 -39
- package/dist/barge-in/lexicons/id.js.map +0 -1
- package/dist/barge-in/lexicons/index.d.ts +0 -10
- package/dist/barge-in/lexicons/index.d.ts.map +0 -1
- package/dist/barge-in/lexicons/index.js +0 -11
- package/dist/barge-in/lexicons/index.js.map +0 -1
- package/dist/barge-in/lexicons/ru.d.ts +0 -2
- package/dist/barge-in/lexicons/ru.d.ts.map +0 -1
- package/dist/barge-in/lexicons/ru.js +0 -39
- package/dist/barge-in/lexicons/ru.js.map +0 -1
- package/dist/barge-in/speech-ledger.d.ts.map +0 -1
- package/dist/barge-in/speech-ledger.js.map +0 -1
- package/dist/barge-in/word-classifier.d.ts.map +0 -1
- package/dist/barge-in/word-classifier.js.map +0 -1
- package/dist/bridge/bridge.d.ts +0 -28
- package/dist/bridge/bridge.d.ts.map +0 -1
- package/dist/bridge/bridge.js +0 -117
- package/dist/bridge/bridge.js.map +0 -1
- package/dist/bridge/index.d.ts +0 -3
- package/dist/bridge/index.d.ts.map +0 -1
- package/dist/bridge/index.js +0 -8
- package/dist/bridge/index.js.map +0 -1
- package/dist/core/call-disposables.d.ts.map +0 -1
- package/dist/core/call-disposables.js.map +0 -1
- package/dist/core/container.d.ts.map +0 -1
- package/dist/core/container.js.map +0 -1
- package/dist/core/create-agent-script.d.ts.map +0 -1
- package/dist/core/create-agent-script.js.map +0 -1
- package/dist/core/decorators.d.ts.map +0 -1
- package/dist/core/decorators.js.map +0 -1
- package/dist/core/define-module.d.ts.map +0 -1
- package/dist/core/define-module.js.map +0 -1
- package/dist/core/dump-policy.d.ts.map +0 -1
- package/dist/core/dump-policy.js.map +0 -1
- package/dist/core/hooks.d.ts.map +0 -1
- package/dist/core/hooks.js.map +0 -1
- package/dist/core/index.d.ts +0 -16
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -36
- package/dist/core/index.js.map +0 -1
- package/dist/core/media-bootstrap.d.ts.map +0 -1
- package/dist/core/media-bootstrap.js.map +0 -1
- package/dist/core/provide-media.d.ts.map +0 -1
- package/dist/core/provide-media.js.map +0 -1
- package/dist/core/tokens.d.ts.map +0 -1
- package/dist/core/tokens.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/version.d.ts.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/dialog/basic-ports.d.ts +0 -54
- package/dist/dialog/basic-ports.d.ts.map +0 -1
- package/dist/dialog/basic-ports.js +0 -206
- package/dist/dialog/basic-ports.js.map +0 -1
- package/dist/dialog/define-dialog.d.ts +0 -21
- package/dist/dialog/define-dialog.d.ts.map +0 -1
- package/dist/dialog/define-dialog.js +0 -21
- package/dist/dialog/define-dialog.js.map +0 -1
- package/dist/dialog/dialog-definition.d.ts.map +0 -1
- package/dist/dialog/dialog-definition.js.map +0 -1
- package/dist/dialog/dialog-ports.d.ts.map +0 -1
- package/dist/dialog/dialog-ports.js.map +0 -1
- package/dist/dialog/index.d.ts +0 -7
- package/dist/dialog/index.d.ts.map +0 -1
- package/dist/dialog/index.js +0 -23
- package/dist/dialog/index.js.map +0 -1
- package/dist/dialog/online-call-host.d.ts.map +0 -1
- package/dist/dialog/online-call-host.js.map +0 -1
- package/dist/dialog/online-call-module.d.ts.map +0 -1
- package/dist/dialog/online-call-module.js.map +0 -1
- package/dist/dialog-events/active-media.d.ts.map +0 -1
- package/dist/dialog-events/active-media.js.map +0 -1
- package/dist/dialog-events/event-source.d.ts.map +0 -1
- package/dist/dialog-events/event-source.js.map +0 -1
- package/dist/dialog-events/index.d.ts +0 -8
- package/dist/dialog-events/index.d.ts.map +0 -1
- package/dist/dialog-events/index.js +0 -24
- package/dist/dialog-events/index.js.map +0 -1
- package/dist/dialog-events/max-listen-source.d.ts +0 -27
- package/dist/dialog-events/max-listen-source.d.ts.map +0 -1
- package/dist/dialog-events/max-listen-source.js +0 -98
- package/dist/dialog-events/max-listen-source.js.map +0 -1
- package/dist/dialog-events/overtalk-source.d.ts +0 -61
- package/dist/dialog-events/overtalk-source.d.ts.map +0 -1
- package/dist/dialog-events/overtalk-source.js +0 -232
- package/dist/dialog-events/overtalk-source.js.map +0 -1
- package/dist/dialog-events/silence-source.d.ts +0 -32
- package/dist/dialog-events/silence-source.d.ts.map +0 -1
- package/dist/dialog-events/silence-source.js +0 -128
- package/dist/dialog-events/silence-source.js.map +0 -1
- package/dist/dialog-events/virtual-finals-module.d.ts.map +0 -1
- package/dist/dialog-events/virtual-finals-module.js.map +0 -1
- package/dist/dialog-events/virtual-finals.d.ts.map +0 -1
- package/dist/dialog-events/virtual-finals.js.map +0 -1
- package/dist/dtmf/dtmf.d.ts +0 -27
- package/dist/dtmf/dtmf.d.ts.map +0 -1
- package/dist/dtmf/dtmf.js +0 -87
- package/dist/dtmf/dtmf.js.map +0 -1
- package/dist/dtmf/index.d.ts +0 -3
- package/dist/dtmf/index.d.ts.map +0 -1
- package/dist/dtmf/index.js +0 -8
- package/dist/dtmf/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lifecycle/index.d.ts +0 -3
- package/dist/lifecycle/index.d.ts.map +0 -1
- package/dist/lifecycle/index.js +0 -9
- package/dist/lifecycle/index.js.map +0 -1
- package/dist/lifecycle/lifecycle.d.ts.map +0 -1
- package/dist/lifecycle/lifecycle.js.map +0 -1
- package/dist/llm/index.d.ts +0 -7
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/index.js +0 -18
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/llm-markers-module.d.ts +0 -15
- package/dist/llm/llm-markers-module.d.ts.map +0 -1
- package/dist/llm/llm-markers-module.js +0 -48
- package/dist/llm/llm-markers-module.js.map +0 -1
- package/dist/llm/llm-markers.d.ts +0 -36
- package/dist/llm/llm-markers.d.ts.map +0 -1
- package/dist/llm/llm-markers.js +0 -210
- package/dist/llm/llm-markers.js.map +0 -1
- package/dist/llm/llm-module.d.ts +0 -20
- package/dist/llm/llm-module.d.ts.map +0 -1
- package/dist/llm/llm-module.js.map +0 -1
- package/dist/match/index.d.ts +0 -3
- package/dist/match/index.d.ts.map +0 -1
- package/dist/match/index.js +0 -10
- package/dist/match/index.js.map +0 -1
- package/dist/match/match.d.ts +0 -33
- package/dist/match/match.d.ts.map +0 -1
- package/dist/match/match.js +0 -85
- package/dist/match/match.js.map +0 -1
- package/dist/outbound/index.d.ts +0 -3
- package/dist/outbound/index.d.ts.map +0 -1
- package/dist/outbound/index.js +0 -8
- package/dist/outbound/index.js.map +0 -1
- package/dist/outbound/outbound.d.ts +0 -40
- package/dist/outbound/outbound.d.ts.map +0 -1
- package/dist/outbound/outbound.js +0 -84
- package/dist/outbound/outbound.js.map +0 -1
- package/dist/result/index.d.ts +0 -2
- package/dist/result/index.d.ts.map +0 -1
- package/dist/result/index.js.map +0 -1
- package/dist/result/result-store.d.ts.map +0 -1
- package/dist/result/result-store.js.map +0 -1
- package/dist/testing/fake-channel.d.ts.map +0 -1
- package/dist/testing/fake-channel.js.map +0 -1
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/docs/agents/README.md +0 -41
- package/docs/agents/barge-in.md +0 -67
- package/docs/agents/dialog.md +0 -98
- package/docs/agents/getting-started.md +0 -142
- package/docs/agents/imports.md +0 -40
- package/docs/agents/media-and-ports.md +0 -82
- package/docs/agents/modules.md +0 -83
- package/docs/agents/phases.md +0 -83
- package/docs/framework/extending.md +0 -59
- package/docs/framework/idn-parity.md +0 -18
- package/examples/minimal-agent/README.md +0 -7
- package/examples/minimal-agent/agent.ts +0 -94
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ResultRegistry } from '../../call/extraction/core';
|
|
2
|
+
import type { AgentHooks, CallView, ExtractionSpec, HookApi, ResultMeaning, ResultsSpec } from '../spec';
|
|
3
|
+
import type { RuleSpec } from './rule-env';
|
|
4
|
+
/** A result's meaning with the canon's own report label (`sameAs`: e.g. `goodbye` is reported as `default`). */
|
|
5
|
+
export type BaseResultMeaning = ResultMeaning & {
|
|
6
|
+
readonly sameAs?: string;
|
|
7
|
+
};
|
|
8
|
+
/** The library's base table: every result the canon knows (`silence`, `voicemail`, `goodbye`…). */
|
|
9
|
+
export declare function baseResultTable(): Record<string, BaseResultMeaning>;
|
|
10
|
+
/** What a result means: base table, then the agent's `'*'`, then the agent's own entry. */
|
|
11
|
+
export declare function resultMeaning(results: ResultsSpec, label: string): BaseResultMeaning;
|
|
12
|
+
/** A result whose meaning says `extract: false` (technical results: silence, voicemail…). */
|
|
13
|
+
export declare function skipsExtraction(results: ResultsSpec, preResult: string): boolean;
|
|
14
|
+
/** The result implied by the truthy entity with the highest priority; `null` when none. */
|
|
15
|
+
export declare function pickExtractedResult(entities: Readonly<Record<string, unknown>>, extraction: ExtractionSpec | undefined): string | null;
|
|
16
|
+
/** `fromFacts` at one point of the call: the first rule that holds sets the result; otherwise `current` stays. */
|
|
17
|
+
export declare function resultFromFacts(results: ResultsSpec, at: 'goodbye' | 'silenceLimit' | 'callEnd', call: CallView, current: string): string;
|
|
18
|
+
/** Report label of a result (`labels.map`, applied to the `result` field). */
|
|
19
|
+
export declare function labelFor(results: ResultsSpec, label: string | null): string | null;
|
|
20
|
+
export interface ResultInput {
|
|
21
|
+
/** The result set during the call (or the technical result of a failed extraction). */
|
|
22
|
+
readonly preResult: string;
|
|
23
|
+
/** Extracted entities (`{}` when extraction was skipped or failed). */
|
|
24
|
+
readonly entities: Readonly<Record<string, unknown>>;
|
|
25
|
+
readonly extractionSkipped: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ResultDecision {
|
|
28
|
+
/** Final result (before `labels.map`). */
|
|
29
|
+
readonly result: string;
|
|
30
|
+
readonly preResult: string;
|
|
31
|
+
/** Result implied by the entities, `null` when none. */
|
|
32
|
+
readonly extractedResult: string | null;
|
|
33
|
+
/** The final result books a redial (`recall`). */
|
|
34
|
+
readonly triggersCallback: boolean;
|
|
35
|
+
readonly extractionSkipped: boolean;
|
|
36
|
+
/** The entities the row shows when the `decide` hook or `results.rules` rewrote them. */
|
|
37
|
+
readonly entities?: Readonly<Record<string, unknown>>;
|
|
38
|
+
/** A text appended to the row's result label (`results.rules[].then.suffix`). */
|
|
39
|
+
readonly labelSuffix?: string;
|
|
40
|
+
}
|
|
41
|
+
/** The decision without the `decide` hook (synchronous). */
|
|
42
|
+
export declare function decideResultSync(input: ResultInput, spec: {
|
|
43
|
+
readonly results: ResultsSpec;
|
|
44
|
+
readonly extraction?: ExtractionSpec;
|
|
45
|
+
}): ResultDecision;
|
|
46
|
+
/**
|
|
47
|
+
* The decision after the agent's data rules: `results.rules` (unless `rulesOn: 'report'`), then `results.catalog`
|
|
48
|
+
* with `applyTo: 'result'` (the label becomes the result).
|
|
49
|
+
*/
|
|
50
|
+
export declare function decideByRules(first: ResultDecision, input: ResultInput, spec: Partial<RuleSpec> & {
|
|
51
|
+
readonly results: ResultsSpec;
|
|
52
|
+
readonly extraction?: ExtractionSpec;
|
|
53
|
+
}, call: CallView, log?: (event: string, data: Record<string, unknown>) => void): ResultDecision;
|
|
54
|
+
/**
|
|
55
|
+
* The full decision: {@link decideResultSync}, the data rules ({@link decideByRules}), then the agent's `decide` hook
|
|
56
|
+
* (bounded by the caller).
|
|
57
|
+
*/
|
|
58
|
+
export declare function decideResult(input: ResultInput, spec: Partial<RuleSpec> & {
|
|
59
|
+
readonly results: ResultsSpec;
|
|
60
|
+
readonly extraction?: ExtractionSpec;
|
|
61
|
+
readonly hooks?: AgentHooks;
|
|
62
|
+
}, call: CallView, api: HookApi): Promise<ResultDecision>;
|
|
63
|
+
/**
|
|
64
|
+
* The result canon with the agent's results added (the extraction refuses a result it does not know): the agent's own
|
|
65
|
+
* registry, so two agents in one process never read each other's meaning of a label. Labels the canon already knows
|
|
66
|
+
* keep their policy; the decision above reads the agent file, not the canon's policy.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resultRegistryOf(results: ResultsSpec, extraction: ExtractionSpec | undefined): ResultRegistry;
|
|
69
|
+
/**
|
|
70
|
+
* Registers the agent's results with the shared canon too, for code that reads it outside the agent's own calls (the
|
|
71
|
+
* first agent file that names a label sets its policy there). The agent's calls read {@link resultRegistryOf}.
|
|
72
|
+
*/
|
|
73
|
+
export declare function registerSpecResults(results: ResultsSpec, extraction: ExtractionSpec | undefined): void;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerSpecResults = exports.resultRegistryOf = exports.decideResult = exports.decideByRules = exports.decideResultSync = exports.labelFor = exports.resultFromFacts = exports.pickExtractedResult = exports.skipsExtraction = exports.resultMeaning = exports.baseResultTable = void 0;
|
|
4
|
+
// Results: what the call's outcome is, from the agent file's `results` (+ `extraction.entities`).
|
|
5
|
+
//
|
|
6
|
+
// Order (references/business.md § Results): the pre-result set during the call → `fromFacts` → the extracted result
|
|
7
|
+
// (`implies` + `priority` of the truthy entities) unless the result skips extraction → the pre-result when it
|
|
8
|
+
// `outranksExtraction` → `sameAs` → the `decide` hook → `labels.map` (report only). The base table is the
|
|
9
|
+
// result canon (`call/extraction`), so a label means the same everywhere.
|
|
10
|
+
const extraction_1 = require("../../call/extraction");
|
|
11
|
+
const core_1 = require("../../call/extraction/core");
|
|
12
|
+
const hooks_1 = require("../engine/hooks");
|
|
13
|
+
const compiled_1 = require("../expr/compiled");
|
|
14
|
+
const result_catalog_1 = require("./result-catalog");
|
|
15
|
+
const result_rules_1 = require("./result-rules");
|
|
16
|
+
/** Labels agent files added to the shared canon ({@link registerSpecResults}): not part of any other agent's base. */
|
|
17
|
+
const fromAgentFiles = new Set();
|
|
18
|
+
/** The shared canon without the labels agent files added to it: the base results and those registered by code. */
|
|
19
|
+
function canonPolicies() {
|
|
20
|
+
return (0, extraction_1.allPolicies)().filter((p) => !fromAgentFiles.has(p.name));
|
|
21
|
+
}
|
|
22
|
+
/** The library's base table: every result the canon knows (`silence`, `voicemail`, `goodbye`…). */
|
|
23
|
+
function baseResultTable() {
|
|
24
|
+
const out = {};
|
|
25
|
+
for (const p of canonPolicies()) {
|
|
26
|
+
out[p.name] = { recall: p.triggersCallback, extract: !p.skipExtraction, ...(p.display ? { sameAs: p.display } : {}) };
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
exports.baseResultTable = baseResultTable;
|
|
31
|
+
/** What a result means: base table, then the agent's `'*'`, then the agent's own entry. */
|
|
32
|
+
function resultMeaning(results, label) {
|
|
33
|
+
const base = baseResultTable()[label] ?? {};
|
|
34
|
+
return { ...base, ...(results.table['*'] ?? {}), ...(results.table[label] ?? {}) };
|
|
35
|
+
}
|
|
36
|
+
exports.resultMeaning = resultMeaning;
|
|
37
|
+
/** A result whose meaning says `extract: false` (technical results: silence, voicemail…). */
|
|
38
|
+
function skipsExtraction(results, preResult) {
|
|
39
|
+
return resultMeaning(results, preResult).extract === false;
|
|
40
|
+
}
|
|
41
|
+
exports.skipsExtraction = skipsExtraction;
|
|
42
|
+
/** The result implied by the truthy entity with the highest priority; `null` when none. */
|
|
43
|
+
function pickExtractedResult(entities, extraction) {
|
|
44
|
+
let best = null;
|
|
45
|
+
for (const e of extraction?.entities ?? []) {
|
|
46
|
+
if (!e.implies || !entities[e.name])
|
|
47
|
+
continue;
|
|
48
|
+
const priority = e.priority ?? 0;
|
|
49
|
+
if (best === null || priority > best.priority)
|
|
50
|
+
best = { implies: e.implies, priority };
|
|
51
|
+
}
|
|
52
|
+
return best?.implies ?? null;
|
|
53
|
+
}
|
|
54
|
+
exports.pickExtractedResult = pickExtractedResult;
|
|
55
|
+
/** `fromFacts` at one point of the call: the first rule that holds sets the result; otherwise `current` stays. */
|
|
56
|
+
function resultFromFacts(results, at, call, current) {
|
|
57
|
+
for (const rule of results.fromFacts ?? []) {
|
|
58
|
+
if (rule.at === at && (0, compiled_1.noData)(rule.when)(call))
|
|
59
|
+
return rule.result;
|
|
60
|
+
}
|
|
61
|
+
return current;
|
|
62
|
+
}
|
|
63
|
+
exports.resultFromFacts = resultFromFacts;
|
|
64
|
+
/** Report label of a result (`labels.map`, applied to the `result` field). */
|
|
65
|
+
function labelFor(results, label) {
|
|
66
|
+
if (label == null)
|
|
67
|
+
return null;
|
|
68
|
+
return results.labels?.map[label] ?? label;
|
|
69
|
+
}
|
|
70
|
+
exports.labelFor = labelFor;
|
|
71
|
+
/** The decision without the `decide` hook (synchronous). */
|
|
72
|
+
function decideResultSync(input, spec) {
|
|
73
|
+
const extractedResult = input.extractionSkipped ? null : pickExtractedResult(input.entities, spec.extraction);
|
|
74
|
+
const pre = input.preResult;
|
|
75
|
+
const outranks = resultMeaning(spec.results, pre).outranksExtraction === true;
|
|
76
|
+
let result = extractedResult != null && !outranks ? extractedResult : pre;
|
|
77
|
+
result = resultMeaning(spec.results, result).sameAs ?? result;
|
|
78
|
+
return {
|
|
79
|
+
result,
|
|
80
|
+
preResult: pre,
|
|
81
|
+
extractedResult,
|
|
82
|
+
triggersCallback: resultMeaning(spec.results, result).recall === true,
|
|
83
|
+
extractionSkipped: input.extractionSkipped,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
exports.decideResultSync = decideResultSync;
|
|
87
|
+
/**
|
|
88
|
+
* The decision after the agent's data rules: `results.rules` (unless `rulesOn: 'report'`), then `results.catalog`
|
|
89
|
+
* with `applyTo: 'result'` (the label becomes the result).
|
|
90
|
+
*/
|
|
91
|
+
function decideByRules(first, input, spec, call, log) {
|
|
92
|
+
let d = first;
|
|
93
|
+
const rules = spec.results.rules;
|
|
94
|
+
if (rules?.length && spec.results.rulesOn !== 'report') {
|
|
95
|
+
const out = (0, result_rules_1.applyResultRules)(spec, rules, { ...d, entities: d.entities ?? input.entities }, call, log);
|
|
96
|
+
const entities = out.entities !== (d.entities ?? input.entities) ? { entities: out.entities } : d.entities ? { entities: d.entities } : {};
|
|
97
|
+
d = {
|
|
98
|
+
result: out.result, preResult: out.preResult, extractedResult: out.extractedResult, triggersCallback: out.triggersCallback,
|
|
99
|
+
extractionSkipped: out.extractionSkipped, ...entities, ...(out.labelSuffix ? { labelSuffix: out.labelSuffix } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const catalog = spec.results.catalog;
|
|
103
|
+
if (catalog?.applyTo === 'result') {
|
|
104
|
+
const label = (0, result_catalog_1.catalogLabel)(spec, catalog, d.result, { ...call, extracted: d.entities ?? input.entities, result: d.result });
|
|
105
|
+
if (label != null && label !== d.result)
|
|
106
|
+
d = { ...d, result: label };
|
|
107
|
+
}
|
|
108
|
+
return d;
|
|
109
|
+
}
|
|
110
|
+
exports.decideByRules = decideByRules;
|
|
111
|
+
/**
|
|
112
|
+
* The full decision: {@link decideResultSync}, the data rules ({@link decideByRules}), then the agent's `decide` hook
|
|
113
|
+
* (bounded by the caller).
|
|
114
|
+
*/
|
|
115
|
+
async function decideResult(input, spec, call, api) {
|
|
116
|
+
const first = decideByRules(decideResultSync(input, spec), input, spec, call, (event, data) => api.log(event, data));
|
|
117
|
+
const name = spec.results.decide?.hook;
|
|
118
|
+
if (!name)
|
|
119
|
+
return first;
|
|
120
|
+
const hook = spec.hooks?.[name];
|
|
121
|
+
if (!hook)
|
|
122
|
+
throw new Error(`[templates/results] no hook "${name}"`);
|
|
123
|
+
const answer = await hook(call, {
|
|
124
|
+
result: first.result, preResult: first.preResult, extractedResult: first.extractedResult, entities: input.entities,
|
|
125
|
+
extractionSkipped: input.extractionSkipped, triggersCallback: first.triggersCallback,
|
|
126
|
+
}, api);
|
|
127
|
+
const out = (0, hooks_1.decideAnswer)(answer, (reason) => api.log('hook_result_invalid', { name, kind: 'decide', reason }));
|
|
128
|
+
// A label, or `{ result?, recall?, entities?, extractedResult? }`: the redial as the hook decided it (e.g. kept as it
|
|
129
|
+
// was), the entities the row shows and the extracted result restated when the client's rules rewrote them.
|
|
130
|
+
const picked = typeof out === 'string' ? { result: out } : out;
|
|
131
|
+
const result = typeof picked?.result === 'string' && picked.result ? picked.result : first.result;
|
|
132
|
+
const recall = typeof picked?.recall === 'boolean' ? picked.recall : result === first.result ? first.triggersCallback : resultMeaning(spec.results, result).recall === true;
|
|
133
|
+
const entities = picked?.entities != null && typeof picked.entities === 'object' ? picked.entities : undefined;
|
|
134
|
+
const extracted = picked != null && 'extractedResult' in picked && picked.extractedResult !== undefined
|
|
135
|
+
? { extractedResult: picked.extractedResult }
|
|
136
|
+
: {};
|
|
137
|
+
if (result === first.result && recall === first.triggersCallback && entities === undefined && !('extractedResult' in extracted))
|
|
138
|
+
return first;
|
|
139
|
+
return { ...first, result, triggersCallback: recall, ...(entities !== undefined ? { entities } : {}), ...extracted };
|
|
140
|
+
}
|
|
141
|
+
exports.decideResult = decideResult;
|
|
142
|
+
/** The agent's results the canon does not know, each with its meaning in the agent file. */
|
|
143
|
+
function agentPolicies(results, extraction, known) {
|
|
144
|
+
const labels = new Set(Object.keys(results.table).filter((l) => l !== '*'));
|
|
145
|
+
for (const e of extraction?.entities ?? [])
|
|
146
|
+
if (e.implies)
|
|
147
|
+
labels.add(e.implies);
|
|
148
|
+
for (const r of results.fromFacts ?? [])
|
|
149
|
+
labels.add(r.result);
|
|
150
|
+
const more = [];
|
|
151
|
+
for (const name of labels) {
|
|
152
|
+
if (known(name))
|
|
153
|
+
continue;
|
|
154
|
+
const m = resultMeaning(results, name);
|
|
155
|
+
more.push({ name, skipExtraction: m.extract === false, triggersCallback: m.recall === true, technical: false });
|
|
156
|
+
}
|
|
157
|
+
return more;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The result canon with the agent's results added (the extraction refuses a result it does not know): the agent's own
|
|
161
|
+
* registry, so two agents in one process never read each other's meaning of a label. Labels the canon already knows
|
|
162
|
+
* keep their policy; the decision above reads the agent file, not the canon's policy.
|
|
163
|
+
*/
|
|
164
|
+
function resultRegistryOf(results, extraction) {
|
|
165
|
+
const base = (0, core_1.createResultRegistry)();
|
|
166
|
+
const canon = canonPolicies();
|
|
167
|
+
const names = new Set(canon.map((p) => p.name));
|
|
168
|
+
return (0, core_1.createResultRegistry)([...canon.filter((p) => !base.isResult(p.name)), ...agentPolicies(results, extraction, (n) => names.has(n))]);
|
|
169
|
+
}
|
|
170
|
+
exports.resultRegistryOf = resultRegistryOf;
|
|
171
|
+
/**
|
|
172
|
+
* Registers the agent's results with the shared canon too, for code that reads it outside the agent's own calls (the
|
|
173
|
+
* first agent file that names a label sets its policy there). The agent's calls read {@link resultRegistryOf}.
|
|
174
|
+
*/
|
|
175
|
+
function registerSpecResults(results, extraction) {
|
|
176
|
+
const more = agentPolicies(results, extraction, extraction_1.isResult);
|
|
177
|
+
if (!more.length)
|
|
178
|
+
return;
|
|
179
|
+
(0, extraction_1.registerResults)(more);
|
|
180
|
+
for (const p of more)
|
|
181
|
+
fromAgentFiles.add(p.name);
|
|
182
|
+
}
|
|
183
|
+
exports.registerSpecResults = registerSpecResults;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ExprEnv } from '../expr/context';
|
|
2
|
+
import type { ExprContext } from '../expr/types';
|
|
3
|
+
import type { EngineSpec, CallView } from '../spec';
|
|
4
|
+
/** What a post-call rule list reads of the agent file. */
|
|
5
|
+
export type RuleSpec = Pick<EngineSpec, 'languages' | 'matchers' | 'facts' | 'tracking' | 'ladders' | 'choices'> & {
|
|
6
|
+
readonly input: Pick<EngineSpec['input'], 'timeZone'>;
|
|
7
|
+
};
|
|
8
|
+
/** The data-language environment of an agent file. */
|
|
9
|
+
export declare function ruleEnv(spec: Partial<RuleSpec>): ExprEnv;
|
|
10
|
+
/** A context for one rule: the call with these entities (and result facts) in view. */
|
|
11
|
+
export declare function ruleContext(spec: Partial<RuleSpec>, call: CallView, over: {
|
|
12
|
+
readonly entities?: Readonly<Record<string, unknown>>;
|
|
13
|
+
readonly result?: string | null;
|
|
14
|
+
readonly preResult?: string | null;
|
|
15
|
+
readonly extractedResult?: string | null;
|
|
16
|
+
readonly row?: Readonly<Record<string, unknown>>;
|
|
17
|
+
readonly self?: unknown;
|
|
18
|
+
}, now?: Date): ExprContext;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ruleContext = exports.ruleEnv = void 0;
|
|
4
|
+
// The evaluation environment of the post-call rule lists (`extraction.rules`, `results.rules`, `results.catalog`):
|
|
5
|
+
// the agent file's zone, languages, named matchers and facts, and its state blocks (`tracking`, `ladders`, `choices`:
|
|
6
|
+
// `{ fact: 'stage' }`, `{ stage }`, line flags read off the call's lines as during the call). The rule lists stay data in the compiled agent file and
|
|
7
|
+
// are evaluated here, after the call, against a call view that carries the running entities and result.
|
|
8
|
+
const context_1 = require("../expr/context");
|
|
9
|
+
const state_1 = require("../engine/turns/state");
|
|
10
|
+
/** The data-language environment of an agent file. */
|
|
11
|
+
function ruleEnv(spec) {
|
|
12
|
+
const blocks = (0, state_1.stateBlocksOf)(spec);
|
|
13
|
+
return {
|
|
14
|
+
timeZone: spec.input?.timeZone ?? 'UTC',
|
|
15
|
+
languages: spec.languages ?? ['en'],
|
|
16
|
+
...(spec.matchers ? { matchers: spec.matchers } : {}),
|
|
17
|
+
...(spec.facts ? { facts: spec.facts } : {}),
|
|
18
|
+
...(blocks ? { blocks } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.ruleEnv = ruleEnv;
|
|
22
|
+
/** A context for one rule: the call with these entities (and result facts) in view. */
|
|
23
|
+
function ruleContext(spec, call, over, now) {
|
|
24
|
+
const view = {
|
|
25
|
+
...call,
|
|
26
|
+
...(over.entities ? { extracted: over.entities } : {}),
|
|
27
|
+
...(over.result !== undefined ? { result: over.result ?? undefined } : {}),
|
|
28
|
+
...(over.preResult !== undefined ? { preResult: over.preResult } : {}),
|
|
29
|
+
...(over.extractedResult !== undefined ? { extractedResult: over.extractedResult } : {}),
|
|
30
|
+
};
|
|
31
|
+
const env = ruleEnv(spec);
|
|
32
|
+
return (0, context_1.callContext)(now ? { ...env, now: () => now } : env, view, {
|
|
33
|
+
...(over.entities ? { entities: over.entities } : {}),
|
|
34
|
+
...(over.row ? { row: over.row } : {}),
|
|
35
|
+
...('self' in over ? { self: over.self } : {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.ruleContext = ruleContext;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { MediaChannel, PlatformApi, ScriptDialogContext } from '@voctiv/agent-sdk';
|
|
2
|
+
import type { CallFacts, CallView, Source, Value } from '../spec';
|
|
3
|
+
/** What a source is read against. Every part is optional: a missing part reads as «no value». */
|
|
4
|
+
export interface SourceScope {
|
|
5
|
+
readonly context?: ScriptDialogContext;
|
|
6
|
+
/** INVITE headers (`{ header }` falls back to them after the dialer's header bag). */
|
|
7
|
+
readonly channel?: MediaChannel;
|
|
8
|
+
/** CMS globals already fetched (`{ global }`, `{ storage }` in synchronous reads). */
|
|
9
|
+
readonly globals?: Readonly<Record<string, unknown>>;
|
|
10
|
+
/** Process env of the script host; default: `process.env` when the sandbox has one. */
|
|
11
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
readonly facts?: CallFacts;
|
|
13
|
+
/** `{ platform: true }`: the value the platform supplies for the feature being read (recall budget, delay). */
|
|
14
|
+
readonly platformValue?: unknown;
|
|
15
|
+
/** Agent UUID when the dialog carries none. */
|
|
16
|
+
readonly agentUuid?: string;
|
|
17
|
+
readonly attempt?: number;
|
|
18
|
+
/** `input.headerBagEnvKey`: the dialog env key of a header bag read when the dialog carries none. */
|
|
19
|
+
readonly headerBagEnvKey?: string;
|
|
20
|
+
/** The platform API of the pass (`HookApi.platform`). */
|
|
21
|
+
readonly platform?: PlatformApi;
|
|
22
|
+
}
|
|
23
|
+
/** `null`, `undefined`, a blank string. */
|
|
24
|
+
export declare function isEmptyValue(v: unknown): boolean;
|
|
25
|
+
/** A `Value` that reads sources (not a literal). */
|
|
26
|
+
export declare function isSourced<T>(v: Value<T> | undefined): v is {
|
|
27
|
+
readonly from: Source | readonly Source[];
|
|
28
|
+
readonly default?: T;
|
|
29
|
+
readonly map?: Readonly<Record<string, T>>;
|
|
30
|
+
};
|
|
31
|
+
export declare function sourceList(from: Source | readonly Source[]): readonly Source[];
|
|
32
|
+
/** Sources read through `context.storage` (asynchronous on the platform). */
|
|
33
|
+
export declare function isAsyncSource(src: Source): boolean;
|
|
34
|
+
/** The CMS key of a `global` / `storage` source. */
|
|
35
|
+
export declare function storageKey(src: Source): string | undefined;
|
|
36
|
+
/** Reads one source now. `global` / `storage` come from `scope.globals` (fetch them first with {@link fetchGlobals}). */
|
|
37
|
+
export declare function readSource(src: Source, scope: SourceScope): unknown;
|
|
38
|
+
/** Reads CMS globals through `context.storage`, one request per key in order (as the agents did); never throws. */
|
|
39
|
+
export declare function fetchGlobals(keys: readonly string[], context: ScriptDialogContext | undefined): Promise<Record<string, unknown>>;
|
|
40
|
+
/** Reads one source, fetching a `global` / `storage` key when the scope does not hold it yet. */
|
|
41
|
+
export declare function fetchSource(src: Source, scope: SourceScope): Promise<unknown>;
|
|
42
|
+
/** A `Value` resolved, fetching CMS globals when it reads them. */
|
|
43
|
+
export declare function resolveValue<T>(v: Value<T> | undefined, scope: SourceScope): Promise<T | undefined>;
|
|
44
|
+
/** The `default` of a `Value` (its literal when it reads no source). */
|
|
45
|
+
export declare function valueDefault<T>(v: Value<T> | undefined): T | undefined;
|
|
46
|
+
/** Day and wall clock of `now` in `timeZone`. */
|
|
47
|
+
export declare function callFacts(timeZone: string, now?: Date): CallFacts;
|
|
48
|
+
/** A call view for functions and hooks of the business part (no conversation state outside the call). */
|
|
49
|
+
export declare function businessCallView(parts: Partial<Omit<CallView, 'vars' | 'language'>> & {
|
|
50
|
+
readonly vars: Readonly<Record<string, unknown>>;
|
|
51
|
+
readonly language: string;
|
|
52
|
+
}): CallView;
|
|
53
|
+
type ConversationFacts = {
|
|
54
|
+
counters: Readonly<Record<string, number>>;
|
|
55
|
+
flags: Readonly<Record<string, boolean>>;
|
|
56
|
+
replyAsrKeys?: readonly string[];
|
|
57
|
+
endedBy?: 'agent' | 'caller' | 'timeout';
|
|
58
|
+
/** Caller lines that reached the LLM / caller finals heard, at the end of the call. */
|
|
59
|
+
callerTurns?: number;
|
|
60
|
+
callerFinals?: number;
|
|
61
|
+
/** When the call ended (epoch ms). */
|
|
62
|
+
endedAtMs?: number;
|
|
63
|
+
transfer?: {
|
|
64
|
+
readonly started: boolean;
|
|
65
|
+
readonly completed: boolean;
|
|
66
|
+
readonly startedAt: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/** The conversation's rule counters and flags, kept for the hooks run after the call. */
|
|
70
|
+
export declare function setConversationFacts(context: ScriptDialogContext, facts: ConversationFacts): void;
|
|
71
|
+
export declare function conversationFactsOf(context: ScriptDialogContext | undefined): ConversationFacts | undefined;
|
|
72
|
+
/** The per-call scratch of the agent's hooks (`HookApi.state`, `CallView.hookState`): one object per call. */
|
|
73
|
+
export declare function hookStateOf(context: ScriptDialogContext): Record<string, unknown>;
|
|
74
|
+
/** Values kept across attempts (`results.remember`, `call.memory`): the dialog env. */
|
|
75
|
+
export declare function readMemory(context: ScriptDialogContext | undefined): Readonly<Record<string, unknown>>;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readMemory = exports.hookStateOf = exports.conversationFactsOf = exports.setConversationFacts = exports.businessCallView = exports.callFacts = exports.valueDefault = exports.resolveValue = exports.fetchSource = exports.fetchGlobals = exports.readSource = exports.storageKey = exports.isAsyncSource = exports.sourceList = exports.isSourced = exports.isEmptyValue = void 0;
|
|
4
|
+
const env_1 = require("../../call/env");
|
|
5
|
+
const outbound_1 = require("../../call/outbound");
|
|
6
|
+
const sip_1 = require("../../call/sip");
|
|
7
|
+
const shared_1 = require("../locales/shared");
|
|
8
|
+
/** `null`, `undefined`, a blank string. */
|
|
9
|
+
function isEmptyValue(v) {
|
|
10
|
+
return v == null || (typeof v === 'string' && v.trim() === '');
|
|
11
|
+
}
|
|
12
|
+
exports.isEmptyValue = isEmptyValue;
|
|
13
|
+
/** A `Value` that reads sources (not a literal). */
|
|
14
|
+
function isSourced(v) {
|
|
15
|
+
return v != null && typeof v === 'object' && !Array.isArray(v) && 'from' in v && !(v instanceof Date);
|
|
16
|
+
}
|
|
17
|
+
exports.isSourced = isSourced;
|
|
18
|
+
function sourceList(from) {
|
|
19
|
+
return Array.isArray(from) ? from : [from];
|
|
20
|
+
}
|
|
21
|
+
exports.sourceList = sourceList;
|
|
22
|
+
/** Sources read through `context.storage` (asynchronous on the platform). */
|
|
23
|
+
function isAsyncSource(src) {
|
|
24
|
+
return 'global' in src || 'storage' in src;
|
|
25
|
+
}
|
|
26
|
+
exports.isAsyncSource = isAsyncSource;
|
|
27
|
+
/** The CMS key of a `global` / `storage` source. */
|
|
28
|
+
function storageKey(src) {
|
|
29
|
+
if ('global' in src)
|
|
30
|
+
return src.global;
|
|
31
|
+
if ('storage' in src)
|
|
32
|
+
return src.storage;
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
exports.storageKey = storageKey;
|
|
36
|
+
function processEnv() {
|
|
37
|
+
const p = globalThis.process;
|
|
38
|
+
return p?.env ?? {};
|
|
39
|
+
}
|
|
40
|
+
/** The header bag kept in the dialog env under `key` (an object of header values), if any. */
|
|
41
|
+
function envHeaderBag(ctx, key) {
|
|
42
|
+
if (key == null)
|
|
43
|
+
return undefined;
|
|
44
|
+
const env = ctx.env$?.getValue?.();
|
|
45
|
+
const bag = env?.[key];
|
|
46
|
+
return bag && typeof bag === 'object' && !Array.isArray(bag) ? bag : undefined;
|
|
47
|
+
}
|
|
48
|
+
/** The dialer's header bag: `X-<name>`, then `<name>` (a blank value reads as none). */
|
|
49
|
+
function bagHeader(name, key, scope) {
|
|
50
|
+
const bag = scope.context ? (0, env_1.readProtoAdditional)(scope.context) ?? envHeaderBag(scope.context, scope.headerBagEnvKey) : undefined;
|
|
51
|
+
if (!bag)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (!isEmptyValue(bag[key]))
|
|
54
|
+
return bag[key];
|
|
55
|
+
if (!isEmptyValue(bag[name]))
|
|
56
|
+
return bag[name];
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
/** The INVITE header named `key` in any case (the first value of a list); found means found, even when blank. */
|
|
60
|
+
function inviteHeader(key, scope) {
|
|
61
|
+
const invite = scope.channel ? (0, sip_1.readInviteSipHeaders)(scope.channel) : undefined;
|
|
62
|
+
if (!invite)
|
|
63
|
+
return { found: false };
|
|
64
|
+
const lower = key.toLowerCase();
|
|
65
|
+
for (const [k, v] of Object.entries(invite)) {
|
|
66
|
+
if (k.toLowerCase() === lower)
|
|
67
|
+
return { found: true, value: Array.isArray(v) ? v[0] : v };
|
|
68
|
+
}
|
|
69
|
+
return { found: false };
|
|
70
|
+
}
|
|
71
|
+
function headerValue(src, scope) {
|
|
72
|
+
const name = src.header;
|
|
73
|
+
const key = /^x-/i.test(name) ? name : `X-${name}`;
|
|
74
|
+
const order = src.order ?? 'bagFirst';
|
|
75
|
+
if (order === 'bagFirst') {
|
|
76
|
+
const fromBag = bagHeader(name, key, scope);
|
|
77
|
+
if (fromBag !== undefined)
|
|
78
|
+
return fromBag;
|
|
79
|
+
}
|
|
80
|
+
const invite = inviteHeader(key, scope);
|
|
81
|
+
if (order !== 'inviteFirst' || (invite.found && !isEmptyValue(invite.value)))
|
|
82
|
+
return invite.value;
|
|
83
|
+
return bagHeader(name, key, scope) ?? invite.value;
|
|
84
|
+
}
|
|
85
|
+
function callValue(name, scope) {
|
|
86
|
+
const ctx = scope.context;
|
|
87
|
+
switch (name) {
|
|
88
|
+
case 'msisdn': return ctx?.msisdn;
|
|
89
|
+
case 'callUuid': return ctx ? (0, env_1.readCallUuid)(ctx) : undefined;
|
|
90
|
+
case 'dialogUuid': return ctx?.dialogUuid;
|
|
91
|
+
case 'agentUuid': return ctx ? (0, env_1.readAgentUuid)(ctx, scope.agentUuid ?? '') || undefined : scope.agentUuid;
|
|
92
|
+
case 'attempt': return scope.attempt ?? (ctx ? (0, env_1.readAttempt)(ctx) : undefined);
|
|
93
|
+
case 'today': return scope.facts?.today;
|
|
94
|
+
case 'now': return scope.facts?.now;
|
|
95
|
+
case 'direction': return ctx ? (0, env_1.readCallDirection)(ctx) : undefined;
|
|
96
|
+
case 'startedAt': return ctx ? (0, env_1.readCallStartedAtMs)(ctx) ?? undefined : undefined;
|
|
97
|
+
case 'trunkName': return typeof ctx?.trunkName === 'string' ? ctx.trunkName.trim() || undefined : undefined;
|
|
98
|
+
case 'bulkUuid': return ctx ? (0, outbound_1.readBulkUuidForSchedule)(ctx) : undefined;
|
|
99
|
+
default: return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Reads one source now. `global` / `storage` come from `scope.globals` (fetch them first with {@link fetchGlobals}). */
|
|
103
|
+
function readSource(src, scope) {
|
|
104
|
+
if ('header' in src)
|
|
105
|
+
return headerValue(src, scope);
|
|
106
|
+
if ('param' in src)
|
|
107
|
+
return scope.context ? (0, env_1.readCallParam)(scope.context, src.param) : undefined;
|
|
108
|
+
if ('entity' in src)
|
|
109
|
+
return scope.context ? (0, env_1.readCallParam)(scope.context, src.entity) : undefined;
|
|
110
|
+
if ('proto' in src)
|
|
111
|
+
return scope.context ? (0, env_1.readProtoAdditional)(scope.context)?.[src.proto] : undefined;
|
|
112
|
+
if ('env' in src)
|
|
113
|
+
return (scope.env ?? processEnv())[src.env];
|
|
114
|
+
if ('dialogEnv' in src)
|
|
115
|
+
return readMemory(scope.context)[src.dialogEnv];
|
|
116
|
+
if ('callRow' in src) {
|
|
117
|
+
let cur = scope.context?.callEntity;
|
|
118
|
+
for (const part of src.callRow.split('.'))
|
|
119
|
+
cur = cur != null && typeof cur === 'object' ? cur[part] : undefined;
|
|
120
|
+
return cur;
|
|
121
|
+
}
|
|
122
|
+
if ('call' in src)
|
|
123
|
+
return callValue(src.call, scope);
|
|
124
|
+
if ('platform' in src)
|
|
125
|
+
return scope.platformValue;
|
|
126
|
+
const key = storageKey(src);
|
|
127
|
+
return key != null ? scope.globals?.[key] : undefined;
|
|
128
|
+
}
|
|
129
|
+
exports.readSource = readSource;
|
|
130
|
+
/** Reads CMS globals through `context.storage`, one request per key in order (as the agents did); never throws. */
|
|
131
|
+
async function fetchGlobals(keys, context) {
|
|
132
|
+
const out = {};
|
|
133
|
+
if (!context?.storage)
|
|
134
|
+
return out;
|
|
135
|
+
for (const key of keys) {
|
|
136
|
+
if (key in out)
|
|
137
|
+
continue;
|
|
138
|
+
try {
|
|
139
|
+
out[key] = (await context.storage(key))[key] ?? null;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
out[key] = null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
exports.fetchGlobals = fetchGlobals;
|
|
148
|
+
/** Reads one source, fetching a `global` / `storage` key when the scope does not hold it yet. */
|
|
149
|
+
async function fetchSource(src, scope) {
|
|
150
|
+
const key = storageKey(src);
|
|
151
|
+
if (key != null && !(scope.globals && key in scope.globals)) {
|
|
152
|
+
return (await fetchGlobals([key], scope.context))[key];
|
|
153
|
+
}
|
|
154
|
+
return readSource(src, scope);
|
|
155
|
+
}
|
|
156
|
+
exports.fetchSource = fetchSource;
|
|
157
|
+
function mapped(raw, map, fallback) {
|
|
158
|
+
if (!map)
|
|
159
|
+
return raw;
|
|
160
|
+
const k = String(raw);
|
|
161
|
+
if (Object.prototype.hasOwnProperty.call(map, k))
|
|
162
|
+
return map[k];
|
|
163
|
+
const norm = k.trim().toLowerCase();
|
|
164
|
+
return Object.prototype.hasOwnProperty.call(map, norm) ? map[norm] : fallback;
|
|
165
|
+
}
|
|
166
|
+
/** A `Value` resolved, fetching CMS globals when it reads them. */
|
|
167
|
+
async function resolveValue(v, scope) {
|
|
168
|
+
if (!isSourced(v))
|
|
169
|
+
return v;
|
|
170
|
+
for (const src of sourceList(v.from)) {
|
|
171
|
+
const raw = await fetchSource(src, scope);
|
|
172
|
+
if (!isEmptyValue(raw))
|
|
173
|
+
return mapped(raw, v.map, v.default);
|
|
174
|
+
}
|
|
175
|
+
return v.default;
|
|
176
|
+
}
|
|
177
|
+
exports.resolveValue = resolveValue;
|
|
178
|
+
/** The `default` of a `Value` (its literal when it reads no source). */
|
|
179
|
+
function valueDefault(v) {
|
|
180
|
+
return isSourced(v) ? v.default : v;
|
|
181
|
+
}
|
|
182
|
+
exports.valueDefault = valueDefault;
|
|
183
|
+
/** Day and wall clock of `now` in `timeZone`. */
|
|
184
|
+
function callFacts(timeZone, now = new Date()) {
|
|
185
|
+
const z = (0, shared_1.zonedParts)(now, timeZone);
|
|
186
|
+
return { today: { year: z.year, month: z.month, day: z.day }, now, hour: z.hour, minute: z.minute, timeZone };
|
|
187
|
+
}
|
|
188
|
+
exports.callFacts = callFacts;
|
|
189
|
+
/** A call view for functions and hooks of the business part (no conversation state outside the call). */
|
|
190
|
+
function businessCallView(parts) {
|
|
191
|
+
return {
|
|
192
|
+
languageProvisional: false,
|
|
193
|
+
phase: 'closing',
|
|
194
|
+
lines: [],
|
|
195
|
+
agentLines: [],
|
|
196
|
+
callerLines: [],
|
|
197
|
+
callerTurns: 0,
|
|
198
|
+
callerFinals: 0,
|
|
199
|
+
counters: {},
|
|
200
|
+
flags: {},
|
|
201
|
+
elapsedMs: 0,
|
|
202
|
+
attempt: 1,
|
|
203
|
+
previous: null,
|
|
204
|
+
memory: {},
|
|
205
|
+
...parts,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
exports.businessCallView = businessCallView;
|
|
209
|
+
const conversationFacts = new WeakMap();
|
|
210
|
+
/** The conversation's rule counters and flags, kept for the hooks run after the call. */
|
|
211
|
+
function setConversationFacts(context, facts) {
|
|
212
|
+
conversationFacts.set(context, facts);
|
|
213
|
+
}
|
|
214
|
+
exports.setConversationFacts = setConversationFacts;
|
|
215
|
+
function conversationFactsOf(context) {
|
|
216
|
+
return context ? conversationFacts.get(context) : undefined;
|
|
217
|
+
}
|
|
218
|
+
exports.conversationFactsOf = conversationFactsOf;
|
|
219
|
+
const hookStates = new WeakMap();
|
|
220
|
+
/** The per-call scratch of the agent's hooks (`HookApi.state`, `CallView.hookState`): one object per call. */
|
|
221
|
+
function hookStateOf(context) {
|
|
222
|
+
let s = hookStates.get(context);
|
|
223
|
+
if (!s) {
|
|
224
|
+
s = {};
|
|
225
|
+
hookStates.set(context, s);
|
|
226
|
+
}
|
|
227
|
+
return s;
|
|
228
|
+
}
|
|
229
|
+
exports.hookStateOf = hookStateOf;
|
|
230
|
+
/** Values kept across attempts (`results.remember`, `call.memory`): the dialog env. */
|
|
231
|
+
function readMemory(context) {
|
|
232
|
+
try {
|
|
233
|
+
return context?.env$?.getValue() ?? {};
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return {};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.readMemory = readMemory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ExprEnv } from '../expr/context';
|
|
2
|
+
import type { ExprContext } from '../expr/types';
|
|
3
|
+
import type { TestPresets } from '../integration-forms';
|
|
4
|
+
import type { CallFacts, CallView } from '../spec';
|
|
5
|
+
/** The preset a switch value names (through `aliases`, else itself, else `otherwise`), or null. */
|
|
6
|
+
export declare function presetName(p: TestPresets, on: unknown): string | null;
|
|
7
|
+
/** The preset a switch value names: `keyOf` evaluated in `ctx` (its `input`: the value) when given, else {@link presetName}. */
|
|
8
|
+
export declare function pickPreset(p: TestPresets, on: unknown, ctx: ExprContext): string | null;
|
|
9
|
+
/** The `values` function of `input.testData` for presets: the picked preset's fields, evaluated in order. */
|
|
10
|
+
export declare function presetValues(p: TestPresets, env: ExprEnv): (call: CallView, on: unknown, facts?: CallFacts, sourced?: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>>;
|