@superpanel-sdk/runtime 0.2.3 → 0.5.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 +28 -8
- package/dist/builder/codegen/emit.d.ts +29 -11
- package/dist/builder/codegen/emit.js +328 -61
- package/dist/builder/codegen/generate.d.ts +21 -0
- package/dist/builder/codegen/generate.js +152 -20
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +24 -0
- package/dist/builder/company-imports.js +114 -0
- package/dist/builder/compile/compile-sequence.d.ts +59 -8
- package/dist/builder/compile/compile-sequence.js +279 -77
- package/dist/builder/compile/function-code.d.ts +12 -2
- package/dist/builder/compile/function-code.js +87 -39
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +24 -23
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +250 -61
- package/dist/builder/paths.d.ts +3 -0
- package/dist/builder/paths.js +16 -0
- package/dist/builder/schedules.d.ts +23 -0
- package/dist/builder/schedules.js +102 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +105 -0
- package/dist/builder/types.d.ts +91 -19
- package/dist/builder/types.js +2 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/index.js +28 -8
- package/dist/cli/serve/index.d.ts +73 -3
- package/dist/cli/serve/index.js +365 -116
- package/dist/cli/type-gen/index.js +9 -8
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +15 -23
- package/dist/compute-host/compute-host.js +25 -28
- package/dist/compute-host/index.d.ts +2 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +11 -9
- package/dist/compute-host/source-compute-host.js +46 -32
- package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
- package/dist/core/case-orchestrator/contact-hours.js +108 -0
- package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
- package/dist/core/case-orchestrator/follow-ups.js +103 -0
- package/dist/core/case-orchestrator/index.d.ts +6 -0
- package/dist/core/case-orchestrator/index.js +6 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +239 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/tools.d.ts +29 -0
- package/dist/core/case-orchestrator/tools.js +31 -0
- package/dist/core/case-orchestrator/types.d.ts +753 -0
- package/dist/core/case-orchestrator/types.js +46 -0
- package/dist/core/case-orchestrator/validate.d.ts +11 -0
- package/dist/core/case-orchestrator/validate.js +63 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +159 -0
- package/dist/core/context/email-message.js +59 -0
- package/dist/core/context/email.d.ts +97 -0
- package/dist/core/context/email.js +91 -0
- package/dist/core/context/exchanges.d.ts +142 -0
- package/dist/core/context/exchanges.js +63 -0
- package/dist/core/context/instances.d.ts +278 -0
- package/dist/core/context/instances.js +123 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +509 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +147 -0
- package/dist/core/context/sms.js +57 -0
- package/dist/core/context/types.d.ts +51 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +31 -0
- package/dist/core/conversation/index.js +14 -0
- package/dist/core/functions/define/bind.d.ts +25 -0
- package/dist/core/functions/define/bind.js +14 -0
- package/dist/core/functions/define/case.d.ts +9 -0
- package/dist/core/functions/define/case.js +13 -0
- package/dist/core/functions/define/events.d.ts +20 -0
- package/dist/core/functions/define/events.js +21 -0
- package/dist/core/functions/define/no-case.d.ts +4 -0
- package/dist/core/functions/define/no-case.js +9 -0
- package/dist/core/functions/events.d.ts +247 -0
- package/dist/core/functions/events.js +32 -0
- package/dist/core/functions/func-ref.d.ts +11 -2
- package/dist/core/functions/schedules.d.ts +51 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +62 -51
- package/dist/core/functions/types.js +6 -1
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +834 -0
- package/dist/core/page/define.js +477 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/render.d.ts +253 -0
- package/dist/core/page/render.js +840 -0
- package/dist/core/page/time-format.d.ts +19 -0
- package/dist/core/page/time-format.js +41 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +642 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +33 -0
- package/dist/core/page/workspace.js +231 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +137 -0
- package/dist/core/party/schema.js +80 -0
- package/dist/core/party/types.d.ts +40 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +57 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +113 -0
- package/dist/core/slot/company-metadata.js +563 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -24
- package/dist/core/slot/field.js +0 -69
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +16 -0
- package/dist/core/slot/schema-compat.js +112 -0
- package/dist/core/slot/schema.d.ts +409 -76
- package/dist/core/slot/schema.js +178 -10
- package/dist/core/slot/types.d.ts +27 -94
- package/dist/core/slot/value.d.ts +26 -3
- package/dist/core/slot/value.js +89 -57
- package/dist/dev-overlay/protocol.d.ts +41 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +20 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +11 -4
- package/dist/fn-context/fake/index.js +27 -2
- package/dist/fn-context/fn-params.d.ts +6 -0
- package/dist/fn-context/fn-params.js +13 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +18 -8
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
- package/dist/fn-context/rpc/index.d.ts +3 -1
- package/dist/fn-context/rpc/index.js +3 -1
- package/dist/fn-context/rpc/integration/index.d.ts +4 -4
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/platform.d.ts +2 -2
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +78 -0
- package/dist/fn-context/rpc/records.js +26 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-client.js +88 -7
- package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +36 -3
- package/dist/index.d.ts +37 -46
- package/dist/index.js +33 -33
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +41 -0
- package/dist/platform.d.ts +76 -0
- package/dist/platform.js +56 -0
- package/dist/voice-service/actions.d.ts +71 -4
- package/dist/voice-service/types.d.ts +42 -5
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +10 -0
- package/package.json +38 -19
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -78
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import { resolveFuncName } from '../functions/func-ref.js';
|
|
2
|
-
import { isOtherwise, jsonRules } from './condition.js';
|
|
3
|
-
import { andCompiledWhen, compileAuthoringWhen, compileWhen, whenFields } from './finish-when.js';
|
|
4
|
-
import { ivrResultField } from './ivr-fields.js';
|
|
5
|
-
import { transferResultField } from './transfer-fields.js';
|
|
6
|
-
function isTopicNode(node) {
|
|
7
|
-
return node.kind === 'topic';
|
|
8
|
-
}
|
|
9
|
-
function isActionNode(node) {
|
|
10
|
-
return node.kind === 'action';
|
|
11
|
-
}
|
|
12
|
-
function isTransferNode(node) {
|
|
13
|
-
return node.kind === 'transfer';
|
|
14
|
-
}
|
|
15
|
-
function isIvrNode(node) {
|
|
16
|
-
return node.kind === 'ivr';
|
|
17
|
-
}
|
|
18
|
-
function isSectionNode(node) {
|
|
19
|
-
return node.kind === 'section';
|
|
20
|
-
}
|
|
21
|
-
function applyWhenOf(node) {
|
|
22
|
-
if (node.kind === 'branch' || node.kind === 'switchOn')
|
|
23
|
-
return null;
|
|
24
|
-
return node.applyWhen;
|
|
25
|
-
}
|
|
26
|
-
function toAgendaBlock(node) {
|
|
27
|
-
if (node.kind === 'topic') {
|
|
28
|
-
return {
|
|
29
|
-
kind: 'topic',
|
|
30
|
-
id: node.id,
|
|
31
|
-
label: node.label,
|
|
32
|
-
instructions: node.instructions,
|
|
33
|
-
fields: node.fields,
|
|
34
|
-
finishWhen: node.finishWhen,
|
|
35
|
-
onNoProgress: node.onNoProgress,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (node.kind === 'action') {
|
|
39
|
-
return {
|
|
40
|
-
kind: 'action',
|
|
41
|
-
id: node.id,
|
|
42
|
-
label: node.label,
|
|
43
|
-
run: node.run,
|
|
44
|
-
finishWhen: node.finishWhen,
|
|
45
|
-
say: node.say,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const { applyWhen: _applyWhen, ...block } = node;
|
|
49
|
-
return block;
|
|
50
|
-
}
|
|
51
|
-
function compileBlock(block, functions, issues, path) {
|
|
52
|
-
try {
|
|
53
|
-
if (block.kind === 'topic') {
|
|
54
|
-
const finishWhen = compileWhen(block.finishWhen, functions);
|
|
55
|
-
const fields = block.fields ?? whenFields(finishWhen);
|
|
56
|
-
return { ...block, fields, finishWhen };
|
|
57
|
-
}
|
|
58
|
-
if (block.kind === 'action') {
|
|
59
|
-
const finishWhen = compileWhen(block.finishWhen, functions);
|
|
60
|
-
const run = resolveFuncName(block.run, functions);
|
|
61
|
-
return { ...block, run, finishWhen };
|
|
62
|
-
}
|
|
63
|
-
if (block.kind === 'ivr') {
|
|
64
|
-
const finishWhen = compileWhen(block.finishWhen, functions);
|
|
65
|
-
const onDtmfResult = resolveFuncName(block.onDtmfResult, functions);
|
|
66
|
-
return { ...block, onDtmfResult, finishWhen, resultField: ivrResultField(block.id) };
|
|
67
|
-
}
|
|
68
|
-
const resultField = transferResultField(block.id);
|
|
69
|
-
const finishWhen = compileWhen(jsonRules({
|
|
70
|
-
fact: resultField,
|
|
71
|
-
path: '$.state',
|
|
72
|
-
operator: 'in',
|
|
73
|
-
value: ['filled', 'asked_unknown', 'declined'],
|
|
74
|
-
}), functions);
|
|
75
|
-
return { ...block, finishWhen, resultField };
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
issues.push({
|
|
79
|
-
code: 'invalid-finish-when',
|
|
80
|
-
message: error instanceof Error ? error.message : String(error),
|
|
81
|
-
path,
|
|
82
|
-
});
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function registerBlock(block, compiled, functions, issues, path) {
|
|
87
|
-
const existing = compiled[block.id];
|
|
88
|
-
if (existing && existing.kind !== block.kind) {
|
|
89
|
-
issues.push({
|
|
90
|
-
code: 'block-kind-mismatch',
|
|
91
|
-
message: `Block ${block.id} kind mismatch`,
|
|
92
|
-
path,
|
|
93
|
-
});
|
|
94
|
-
return existing;
|
|
95
|
-
}
|
|
96
|
-
const next = compileBlock(block, functions, issues, path);
|
|
97
|
-
if (!next)
|
|
98
|
-
return existing ?? null;
|
|
99
|
-
compiled[block.id] = next;
|
|
100
|
-
return next;
|
|
101
|
-
}
|
|
102
|
-
function expandSugar(nodes, issues, path) {
|
|
103
|
-
const out = [];
|
|
104
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
105
|
-
const node = nodes[i];
|
|
106
|
-
const childPath = `${path}[${i}]`;
|
|
107
|
-
if (node.kind === 'branch') {
|
|
108
|
-
out.push(...expandBranch(node, issues, childPath));
|
|
109
|
-
}
|
|
110
|
-
else if (node.kind === 'switchOn') {
|
|
111
|
-
out.push(...expandSwitchOn(node, issues, childPath));
|
|
112
|
-
}
|
|
113
|
-
else if (node.kind === 'section') {
|
|
114
|
-
out.push({ ...node, children: expandSugar(node.children, issues, `${childPath}/${node.id}`) });
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
out.push(node);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return out;
|
|
121
|
-
}
|
|
122
|
-
function expandBranch(node, issues, path) {
|
|
123
|
-
const children = expandSugar(node.children, issues, path);
|
|
124
|
-
const otherwiseIndexes = [];
|
|
125
|
-
for (let i = 0; i < children.length; i++) {
|
|
126
|
-
if (isOtherwise(applyWhenOf(children[i])))
|
|
127
|
-
otherwiseIndexes.push(i);
|
|
128
|
-
}
|
|
129
|
-
if (otherwiseIndexes.length > 1) {
|
|
130
|
-
issues.push({
|
|
131
|
-
code: 'otherwise-not-unique',
|
|
132
|
-
message: 'branch() otherwise must appear at most once',
|
|
133
|
-
path,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
if (otherwiseIndexes.length === 1 && otherwiseIndexes[0] !== children.length - 1) {
|
|
137
|
-
issues.push({
|
|
138
|
-
code: 'otherwise-not-last',
|
|
139
|
-
message: 'branch() otherwise must be last',
|
|
140
|
-
path,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
const explicit = children.filter((child) => !isOtherwise(applyWhenOf(child)));
|
|
144
|
-
if (explicit.length === 0) {
|
|
145
|
-
issues.push({
|
|
146
|
-
code: 'branch-no-explicit',
|
|
147
|
-
message: 'branch() needs at least one explicit condition branch',
|
|
148
|
-
path,
|
|
149
|
-
});
|
|
150
|
-
return children;
|
|
151
|
-
}
|
|
152
|
-
const explicitWhens = [];
|
|
153
|
-
for (const child of explicit) {
|
|
154
|
-
const when = applyWhenOf(child);
|
|
155
|
-
if (when == null) {
|
|
156
|
-
issues.push({
|
|
157
|
-
code: 'branch-null-sibling',
|
|
158
|
-
message: 'branch() explicit sibling cannot have applyWhen: null',
|
|
159
|
-
path,
|
|
160
|
-
});
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
if (isOtherwise(when))
|
|
164
|
-
continue;
|
|
165
|
-
explicitWhens.push(when);
|
|
166
|
-
}
|
|
167
|
-
if (otherwiseIndexes.length === 1 && explicitWhens.length > 0) {
|
|
168
|
-
const index = otherwiseIndexes[0];
|
|
169
|
-
const child = children[index];
|
|
170
|
-
children[index] = withApplyWhen(child, { op: 'otherwise', notAny: explicitWhens });
|
|
171
|
-
}
|
|
172
|
-
return children;
|
|
173
|
-
}
|
|
174
|
-
function expandSwitchOn(node, issues, path) {
|
|
175
|
-
const children = [];
|
|
176
|
-
for (const [key, tree] of Object.entries(node.cases)) {
|
|
177
|
-
children.push({
|
|
178
|
-
kind: 'section',
|
|
179
|
-
id: key,
|
|
180
|
-
label: key,
|
|
181
|
-
applyWhen: jsonRules({ fact: node.field, operator: 'equal', value: key }),
|
|
182
|
-
children: tree,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
if (node.otherwise) {
|
|
186
|
-
children.push({
|
|
187
|
-
kind: 'section',
|
|
188
|
-
id: 'otherwise',
|
|
189
|
-
label: 'otherwise',
|
|
190
|
-
applyWhen: { op: 'otherwise' },
|
|
191
|
-
children: node.otherwise,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return expandBranch({ kind: 'branch', children }, issues, path);
|
|
195
|
-
}
|
|
196
|
-
function withApplyWhen(node, applyWhen) {
|
|
197
|
-
if (node.kind === 'branch' || node.kind === 'switchOn')
|
|
198
|
-
return node;
|
|
199
|
-
return { ...node, applyWhen };
|
|
200
|
-
}
|
|
201
|
-
function tryCompileAuthoringWhen(raw, functions, issues, path) {
|
|
202
|
-
try {
|
|
203
|
-
return compileAuthoringWhen(raw, functions);
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
issues.push({
|
|
207
|
-
code: 'invalid-apply-when',
|
|
208
|
-
message: error instanceof Error ? error.message : String(error),
|
|
209
|
-
path,
|
|
210
|
-
});
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function uniquePlacementId(base, used) {
|
|
215
|
-
if (!used.has(base)) {
|
|
216
|
-
used.add(base);
|
|
217
|
-
return base;
|
|
218
|
-
}
|
|
219
|
-
let i = 2;
|
|
220
|
-
while (used.has(`${base}-${i}`))
|
|
221
|
-
i += 1;
|
|
222
|
-
const id = `${base}-${i}`;
|
|
223
|
-
used.add(id);
|
|
224
|
-
return id;
|
|
225
|
-
}
|
|
226
|
-
function flattenAuthoring(nodes, inherited, groupPath, compiled, functions, issues, usedIds, path) {
|
|
227
|
-
const expanded = expandSugar(nodes, issues, path);
|
|
228
|
-
const items = [];
|
|
229
|
-
for (let i = 0; i < expanded.length; i++) {
|
|
230
|
-
const node = expanded[i];
|
|
231
|
-
const childPath = `${path}[${i}]`;
|
|
232
|
-
if (isSectionNode(node)) {
|
|
233
|
-
if (isOtherwise(node.applyWhen) && node.applyWhen.notAny == null) {
|
|
234
|
-
issues.push({
|
|
235
|
-
code: 'otherwise-unexpanded',
|
|
236
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
237
|
-
path: childPath,
|
|
238
|
-
});
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
const compiledWhen = tryCompileAuthoringWhen(node.applyWhen, functions, issues, childPath);
|
|
242
|
-
if (!compiledWhen)
|
|
243
|
-
continue;
|
|
244
|
-
const merged = andCompiledWhen(inherited, compiledWhen);
|
|
245
|
-
const sectionId = uniquePlacementId(node.id, usedIds);
|
|
246
|
-
items.push(...flattenAuthoring(node.children, merged, [...groupPath, sectionId], compiled, functions, issues, usedIds, `${childPath}/${node.id}`));
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (node.kind === 'branch') {
|
|
250
|
-
items.push(...flattenAuthoring(node.children, inherited, groupPath, compiled, functions, issues, usedIds, childPath));
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (node.kind === 'switchOn') {
|
|
254
|
-
items.push(...flattenAuthoring(expandSwitchOn(node, issues, childPath), inherited, groupPath, compiled, functions, issues, usedIds, childPath));
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (isOtherwise(node.applyWhen) && node.applyWhen.notAny == null) {
|
|
258
|
-
issues.push({
|
|
259
|
-
code: 'otherwise-unexpanded',
|
|
260
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
261
|
-
path: childPath,
|
|
262
|
-
});
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
const compiledBlock = registerBlock(toAgendaBlock(node), compiled, functions, issues, childPath);
|
|
266
|
-
if (!compiledBlock)
|
|
267
|
-
continue;
|
|
268
|
-
const compiledWhen = tryCompileAuthoringWhen(node.applyWhen, functions, issues, childPath);
|
|
269
|
-
if (!compiledWhen)
|
|
270
|
-
continue;
|
|
271
|
-
const placementId = uniquePlacementId(node.id, usedIds);
|
|
272
|
-
items.push({
|
|
273
|
-
...compiledBlock,
|
|
274
|
-
placementId,
|
|
275
|
-
applyWhen: andCompiledWhen(inherited, compiledWhen),
|
|
276
|
-
groupPath,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
return items;
|
|
280
|
-
}
|
|
281
|
-
function flattenPlacements(placements, blocks, inherited, groupPath, compiled, functions, issues, usedIds, path) {
|
|
282
|
-
const items = [];
|
|
283
|
-
for (let i = 0; i < placements.length; i++) {
|
|
284
|
-
const placement = placements[i];
|
|
285
|
-
const childPath = `${path}[${i}]`;
|
|
286
|
-
if (placement.kind === 'section') {
|
|
287
|
-
if (isOtherwise(placement.applyWhen) && placement.applyWhen.notAny == null) {
|
|
288
|
-
issues.push({
|
|
289
|
-
code: 'otherwise-unexpanded',
|
|
290
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
291
|
-
path: childPath,
|
|
292
|
-
});
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
const compiledWhen = tryCompileAuthoringWhen(placement.applyWhen, functions, issues, childPath);
|
|
296
|
-
if (!compiledWhen)
|
|
297
|
-
continue;
|
|
298
|
-
const merged = andCompiledWhen(inherited, compiledWhen);
|
|
299
|
-
const sectionId = uniquePlacementId(placement.placementId, usedIds);
|
|
300
|
-
items.push(...flattenPlacements(placement.children, blocks, merged, [...groupPath, sectionId], compiled, functions, issues, usedIds, `${childPath}/${placement.placementId}`));
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
const block = blocks[placement.blockId];
|
|
304
|
-
if (!block) {
|
|
305
|
-
issues.push({
|
|
306
|
-
code: 'unknown-block',
|
|
307
|
-
message: `Unknown block: ${placement.blockId}`,
|
|
308
|
-
path: childPath,
|
|
309
|
-
});
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
if (isOtherwise(placement.applyWhen) && placement.applyWhen.notAny == null) {
|
|
313
|
-
issues.push({
|
|
314
|
-
code: 'otherwise-unexpanded',
|
|
315
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
316
|
-
path: childPath,
|
|
317
|
-
});
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
const compiledBlock = registerBlock(block, compiled, functions, issues, childPath);
|
|
321
|
-
if (!compiledBlock)
|
|
322
|
-
continue;
|
|
323
|
-
const compiledWhen = tryCompileAuthoringWhen(placement.applyWhen, functions, issues, childPath);
|
|
324
|
-
if (!compiledWhen)
|
|
325
|
-
continue;
|
|
326
|
-
const placementId = uniquePlacementId(placement.placementId, usedIds);
|
|
327
|
-
items.push({
|
|
328
|
-
...compiledBlock,
|
|
329
|
-
placementId,
|
|
330
|
-
applyWhen: andCompiledWhen(inherited, compiledWhen),
|
|
331
|
-
groupPath,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
return items;
|
|
335
|
-
}
|
|
336
|
-
function asSectionPlacement(node, usedIds, path, issues) {
|
|
337
|
-
if (isSectionNode(node)) {
|
|
338
|
-
return {
|
|
339
|
-
kind: 'section',
|
|
340
|
-
placementId: uniquePlacementId(node.id, usedIds),
|
|
341
|
-
label: node.label,
|
|
342
|
-
applyWhen: node.applyWhen,
|
|
343
|
-
children: node.children.map((child, i) => asPlacement(child, usedIds, `${path}/${node.id}[${i}]`, issues)),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
if (isTopicNode(node) || isActionNode(node) || isTransferNode(node) || isIvrNode(node)) {
|
|
347
|
-
return {
|
|
348
|
-
kind: 'node',
|
|
349
|
-
placementId: uniquePlacementId(node.id, usedIds),
|
|
350
|
-
blockId: node.id,
|
|
351
|
-
applyWhen: node.applyWhen,
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
issues.push({
|
|
355
|
-
code: 'invalid-placement',
|
|
356
|
-
message: `Cannot place ${node.kind} as a placement child before sugar expansion`,
|
|
357
|
-
path,
|
|
358
|
-
});
|
|
359
|
-
return {
|
|
360
|
-
kind: 'section',
|
|
361
|
-
placementId: uniquePlacementId('_invalid', usedIds),
|
|
362
|
-
label: '_invalid',
|
|
363
|
-
applyWhen: null,
|
|
364
|
-
children: [],
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
function asPlacement(node, usedIds, path, issues) {
|
|
368
|
-
return asSectionPlacement(node, usedIds, path, issues);
|
|
369
|
-
}
|
|
370
|
-
/** Extract reusable blocks from an inline agenda tree. */
|
|
371
|
-
export function extractBlocksFromTree(tree, blocks = {}) {
|
|
372
|
-
visit(tree);
|
|
373
|
-
return blocks;
|
|
374
|
-
function visit(nodes) {
|
|
375
|
-
for (const node of nodes) {
|
|
376
|
-
if (isTopicNode(node) || isActionNode(node) || isTransferNode(node) || isIvrNode(node)) {
|
|
377
|
-
blocks[node.id] = toAgendaBlock(node);
|
|
378
|
-
}
|
|
379
|
-
else if (isSectionNode(node) || node.kind === 'branch') {
|
|
380
|
-
visit(node.children);
|
|
381
|
-
}
|
|
382
|
-
else if (node.kind === 'switchOn') {
|
|
383
|
-
for (const children of Object.values(node.cases))
|
|
384
|
-
visit(children);
|
|
385
|
-
if (node.otherwise)
|
|
386
|
-
visit(node.otherwise);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
export function flattenAgendaTree(tree, options = {}) {
|
|
392
|
-
const issues = [];
|
|
393
|
-
const compiled = {};
|
|
394
|
-
const items = flattenAuthoring(tree, { kind: 'always' }, [], compiled, options.functions, issues, new Set(), 'tree');
|
|
395
|
-
return { items, blocks: compiled, issues };
|
|
396
|
-
}
|
|
397
|
-
export function flattenAgendaPlacements(placements, blocks, options = {}) {
|
|
398
|
-
const issues = [];
|
|
399
|
-
const compiled = {};
|
|
400
|
-
const items = flattenPlacements(placements, blocks, { kind: 'always' }, [], compiled, options.functions, issues, new Set(), 'placements');
|
|
401
|
-
return { items, blocks: compiled, issues };
|
|
402
|
-
}
|
|
403
|
-
export function flattenAgendaConfig(config, blocks, options = {}) {
|
|
404
|
-
if (config.tree)
|
|
405
|
-
return flattenAgendaTree(config.tree, options);
|
|
406
|
-
return flattenAgendaPlacements(config.placements ?? [], blocks, options);
|
|
407
|
-
}
|
|
408
|
-
export function treeToPlacements(tree) {
|
|
409
|
-
const issues = [];
|
|
410
|
-
const expanded = expandSugar(tree, issues, 'tree');
|
|
411
|
-
const blocks = extractBlocksFromTree(expanded);
|
|
412
|
-
const usedIds = new Set();
|
|
413
|
-
const placements = expanded.map((node, i) => asPlacement(node, usedIds, `tree[${i}]`, issues));
|
|
414
|
-
return { blocks, placements };
|
|
415
|
-
}
|
|
416
|
-
export function isAgendaTree(value) {
|
|
417
|
-
return (value != null &&
|
|
418
|
-
typeof value === 'object' &&
|
|
419
|
-
value.kind === 'agenda' &&
|
|
420
|
-
typeof value.id === 'string' &&
|
|
421
|
-
Array.isArray(value.tree));
|
|
422
|
-
}
|
|
423
|
-
export function isSequenceAgendas(value) {
|
|
424
|
-
if (value == null || typeof value !== 'object' || Array.isArray(value))
|
|
425
|
-
return false;
|
|
426
|
-
const obj = value;
|
|
427
|
-
return isPlainBlocks(obj.blocks) && isPlainAgendas(obj.agendas);
|
|
428
|
-
}
|
|
429
|
-
function isPlainBlocks(value) {
|
|
430
|
-
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
431
|
-
}
|
|
432
|
-
function isPlainAgendas(value) {
|
|
433
|
-
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
434
|
-
}
|
|
435
|
-
export function normalizeSequenceAgendas(value) {
|
|
436
|
-
if (isSequenceAgendas(value))
|
|
437
|
-
return value;
|
|
438
|
-
if (isAgendaTree(value)) {
|
|
439
|
-
const { blocks, placements } = treeToPlacements(value.tree);
|
|
440
|
-
return {
|
|
441
|
-
blocks,
|
|
442
|
-
agendas: {
|
|
443
|
-
[value.id]: { id: value.id, header: value.header, placements },
|
|
444
|
-
},
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
if (Array.isArray(value) && value.every(isAgendaTree)) {
|
|
448
|
-
const blocks = {};
|
|
449
|
-
const agendas = {};
|
|
450
|
-
for (const tree of value) {
|
|
451
|
-
const extracted = treeToPlacements(tree.tree);
|
|
452
|
-
Object.assign(blocks, extracted.blocks);
|
|
453
|
-
agendas[tree.id] = { id: tree.id, header: tree.header, placements: extracted.placements };
|
|
454
|
-
}
|
|
455
|
-
return { blocks, agendas };
|
|
456
|
-
}
|
|
457
|
-
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
|
458
|
-
const record = value;
|
|
459
|
-
const trees = Object.values(record);
|
|
460
|
-
if (trees.length > 0 && trees.every(isAgendaTree)) {
|
|
461
|
-
return normalizeSequenceAgendas(trees);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
throw new Error('Could not find agendas export as SequenceAgendas or agenda() tree');
|
|
465
|
-
}
|
|
466
|
-
//# sourceMappingURL=flatten.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type { ActionBlock, ActionNode, AgendaBlock, AgendaConfig, AgendaHeader, AgendaTree, ApplyWhen, AuthoringNode, AuthoringWhen, BranchNode, Channel, CompiledActionBlock, CompiledAgenda, CompiledAgendaBlock, CompiledTopicBlock, CompiledIvrBlock, CompiledTransferBlock, CompiledWhen, Condition, FirstMessage, FinishWhen, FlatActionItem, FlatAgendaItem, FlatIvrItem, FlatNodePlacement, FlatTopicItem, FlatTransferItem, DtmfResult, IvrBlock, IvrDigit, IvrFallbackAction, IvrNode, Interrupt, SequenceAgendas, JsonRulesCondition, NodePlacement, OnNoProgress, OtherwiseSentinel, Placement, SectionNode, SectionPlacement, SwitchOnNode, TopicBlock, TopicNode, TransferBlock, TransferInterruptAction, TransferNode, When, } from './types.js';
|
|
2
|
-
export type { TransferArguments, TransferCallerIdShown, TransferConfirmKey, TransferConfirmMethod, TransferDial, TransferFallbackAction, TransferMode, TransferSay, } from './transfer-spec.js';
|
|
3
|
-
export { E164_NUMBER, SIP_URI, interpolateFromSnapshot, interpolateTemplate, isTransferDestinationLiteral, resolveTransferArguments, resolveTransferDestinations, resolveTransferSay, transferArgumentsJson, validateTransferDestinations, } from './transfer-spec.js';
|
|
4
|
-
export { collectJsonRulesFacts, evaluateJsonRules, extractTemplateFields, isOtherwise, jsonRules, looksLikeJsonRules, normalizeJsonRules, otherwise, parseJsonRules, type ConditionEval, } from './condition.js';
|
|
5
|
-
export { andCompiledWhen, compileAuthoringWhen, compileFinishWhen, compileWhen, evaluateFinishWhen, evaluateWhen, finishWhenFields, notAnyWhen, whenFields, type FinishWhenEval, type WhenEval, } from './finish-when.js';
|
|
6
|
-
export { action, agenda, branch, ivr, section, switchOn, topic, transfer } from './builders.js';
|
|
7
|
-
export { extractBlocksFromTree, flattenAgendaConfig, flattenAgendaPlacements, flattenAgendaTree, isAgendaTree, isSequenceAgendas, normalizeSequenceAgendas, treeToPlacements, type FlattenOptions, type FlattenResult, } from './flatten.js';
|
|
8
|
-
export { CASE_LAST_TRANSFER_AT, CASE_LAST_TRANSFER_RESULT, CASE_TRANSFER_ATTEMPT_COUNT, LAST_TRANSFER_RESULT_FIELD, collectTransferBlocks, registerTransferSessionFields, transferFieldKey, transferResultField, } from './transfer-fields.js';
|
|
9
|
-
export { collectIvrBlocks, ivrAttempted, ivrResultField, registerIvrSessionFields, type IvrAttemptResult, } from './ivr-fields.js';
|
|
10
|
-
export { fatalAgendaIssues, validateCompiledAgenda, type ValidateAgendaOptions } from './validate.js';
|
|
11
|
-
export { RESERVED_INTERRUPT_TOOL_NAMES, collectTransferInterruptHeaders, headerHasTransferInterrupt, CONTACT_LANGUAGE_FIELD, getContactLang, inboundIvrCollect, isSpokenLanguage, ivrOf, languageFieldOf, validateInterrupts, type SpokenLanguage, } from './interrupts.js';
|
|
12
|
-
export { unresolvedFinishWhenFields, walkAgenda, type WalkDecision, type WalkHitReason, type WalkOptions, type WalkResult, type WalkSkip, type WalkSkipReason, type WalkStats, } from './walk.js';
|
|
13
|
-
export { simulateAgenda, type SimulateResult, type SimulatedItem, type SimulatedItemStatus } from './simulate.js';
|
|
14
|
-
export { DEFAULT_MAX_ACTIONS_PER_TURN, advanceAgenda, driveAgenda, transferWrites, watchdogHint, type AdvanceResult, type StageDriveHooks, type StageDriveResult, type StageDriveState, } from './drive.js';
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/stage/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { E164_NUMBER, SIP_URI, interpolateFromSnapshot, interpolateTemplate, isTransferDestinationLiteral, resolveTransferArguments, resolveTransferDestinations, resolveTransferSay, transferArgumentsJson, validateTransferDestinations, } from './transfer-spec.js';
|
|
2
|
-
export { collectJsonRulesFacts, evaluateJsonRules, extractTemplateFields, isOtherwise, jsonRules, looksLikeJsonRules, normalizeJsonRules, otherwise, parseJsonRules, } from './condition.js';
|
|
3
|
-
export { andCompiledWhen, compileAuthoringWhen, compileFinishWhen, compileWhen, evaluateFinishWhen, evaluateWhen, finishWhenFields, notAnyWhen, whenFields, } from './finish-when.js';
|
|
4
|
-
export { action, agenda, branch, ivr, section, switchOn, topic, transfer } from './builders.js';
|
|
5
|
-
export { extractBlocksFromTree, flattenAgendaConfig, flattenAgendaPlacements, flattenAgendaTree, isAgendaTree, isSequenceAgendas, normalizeSequenceAgendas, treeToPlacements, } from './flatten.js';
|
|
6
|
-
export { CASE_LAST_TRANSFER_AT, CASE_LAST_TRANSFER_RESULT, CASE_TRANSFER_ATTEMPT_COUNT, LAST_TRANSFER_RESULT_FIELD, collectTransferBlocks, registerTransferSessionFields, transferFieldKey, transferResultField, } from './transfer-fields.js';
|
|
7
|
-
export { collectIvrBlocks, ivrAttempted, ivrResultField, registerIvrSessionFields, } from './ivr-fields.js';
|
|
8
|
-
export { fatalAgendaIssues, validateCompiledAgenda } from './validate.js';
|
|
9
|
-
export { RESERVED_INTERRUPT_TOOL_NAMES, collectTransferInterruptHeaders, headerHasTransferInterrupt, CONTACT_LANGUAGE_FIELD, getContactLang, inboundIvrCollect, isSpokenLanguage, ivrOf, languageFieldOf, validateInterrupts, } from './interrupts.js';
|
|
10
|
-
export { unresolvedFinishWhenFields, walkAgenda, } from './walk.js';
|
|
11
|
-
export { simulateAgenda } from './simulate.js';
|
|
12
|
-
export { DEFAULT_MAX_ACTIONS_PER_TURN, advanceAgenda, driveAgenda, transferWrites, watchdogHint, } from './drive.js';
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { FieldPath } from '../slot/path.js';
|
|
2
|
-
import type { CompiledSlotSchema, ValidationIssue } from '../slot/types.js';
|
|
3
|
-
import type { AgendaHeader, FlatAgendaItem, FlatIvrItem, Interrupt, IvrDigit, IvrFallbackAction } from './types.js';
|
|
4
|
-
export type SpokenLanguage = string;
|
|
5
|
-
export declare const CONTACT_LANGUAGE_FIELD: "contact.language";
|
|
6
|
-
export declare const RESERVED_INTERRUPT_TOOL_NAMES: Set<string>;
|
|
7
|
-
export declare function isSpokenLanguage(value: unknown): value is SpokenLanguage;
|
|
8
|
-
export declare function ivrOf(items: FlatAgendaItem[] | null | undefined): FlatIvrItem | null;
|
|
9
|
-
export declare function languageFieldOf(): FieldPath;
|
|
10
|
-
/** Voice language. Empty / missing / non-language value → english. */
|
|
11
|
-
export declare function getContactLang(readField?: (path: FieldPath) => unknown): SpokenLanguage;
|
|
12
|
-
export declare function inboundIvrCollect(items: FlatAgendaItem[] | null | undefined): {
|
|
13
|
-
id: string;
|
|
14
|
-
fallbackAction: IvrFallbackAction;
|
|
15
|
-
confirmTimeoutMs: number;
|
|
16
|
-
pauseAfterSayMs: number;
|
|
17
|
-
finishOnKey?: IvrDigit | null;
|
|
18
|
-
minDigits?: number | null;
|
|
19
|
-
maxDigits?: number | null;
|
|
20
|
-
validateDigits: IvrDigit[];
|
|
21
|
-
} | null;
|
|
22
|
-
export declare function headerHasTransferInterrupt(header: AgendaHeader | null | undefined): boolean;
|
|
23
|
-
export declare function collectTransferInterruptHeaders(headers: Array<AgendaHeader | null | undefined>): boolean;
|
|
24
|
-
export declare function validateInterrupts(interrupts: Interrupt[], options: {
|
|
25
|
-
schema: CompiledSlotSchema;
|
|
26
|
-
agendaId?: string;
|
|
27
|
-
}): ValidationIssue[];
|
|
28
|
-
//# sourceMappingURL=interrupts.d.ts.map
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { getCompiledTable } from '../slot/compile-schema.js';
|
|
2
|
-
import { validateTransferDestinations } from './transfer-spec.js';
|
|
3
|
-
export const CONTACT_LANGUAGE_FIELD = 'contact.language';
|
|
4
|
-
export const RESERVED_INTERRUPT_TOOL_NAMES = new Set(['voice_turn', 'record_opt_out', 'advance']);
|
|
5
|
-
export function isSpokenLanguage(value) {
|
|
6
|
-
return typeof value === 'string' && value.trim().length > 0;
|
|
7
|
-
}
|
|
8
|
-
export function ivrOf(items) {
|
|
9
|
-
return items?.find((item) => item.kind === 'ivr') ?? null;
|
|
10
|
-
}
|
|
11
|
-
export function languageFieldOf() {
|
|
12
|
-
return CONTACT_LANGUAGE_FIELD;
|
|
13
|
-
}
|
|
14
|
-
function looksLikeSpokenLanguage(value) {
|
|
15
|
-
return isSpokenLanguage(value) && /[a-zA-Z]/.test(value);
|
|
16
|
-
}
|
|
17
|
-
/** Voice language. Empty / missing / non-language value → english. */
|
|
18
|
-
export function getContactLang(readField) {
|
|
19
|
-
if (!readField)
|
|
20
|
-
return 'english';
|
|
21
|
-
const raw = readField(CONTACT_LANGUAGE_FIELD);
|
|
22
|
-
return looksLikeSpokenLanguage(raw) ? raw.trim() : 'english';
|
|
23
|
-
}
|
|
24
|
-
export function inboundIvrCollect(items) {
|
|
25
|
-
const ivr = ivrOf(items);
|
|
26
|
-
if (!ivr)
|
|
27
|
-
return null;
|
|
28
|
-
const validateDigits = (ivr.validateDigits ?? []).filter((digit) => Boolean(digit?.trim()));
|
|
29
|
-
if (!ivr.finishOnKey && validateDigits.length === 0)
|
|
30
|
-
return null;
|
|
31
|
-
return {
|
|
32
|
-
id: ivr.id,
|
|
33
|
-
fallbackAction: ivr.fallbackAction,
|
|
34
|
-
confirmTimeoutMs: ivr.confirmTimeoutMs,
|
|
35
|
-
pauseAfterSayMs: ivr.pauseAfterSayMs,
|
|
36
|
-
finishOnKey: ivr.finishOnKey,
|
|
37
|
-
minDigits: ivr.minDigits,
|
|
38
|
-
maxDigits: ivr.maxDigits,
|
|
39
|
-
validateDigits,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export function headerHasTransferInterrupt(header) {
|
|
43
|
-
return header?.interrupts.some((interrupt) => interrupt.action.type === 'transfer') ?? false;
|
|
44
|
-
}
|
|
45
|
-
export function collectTransferInterruptHeaders(headers) {
|
|
46
|
-
return headers.some((header) => headerHasTransferInterrupt(header));
|
|
47
|
-
}
|
|
48
|
-
export function validateInterrupts(interrupts, options) {
|
|
49
|
-
const issues = [];
|
|
50
|
-
const prefix = `${options.agendaId ?? 'agenda'}/header/interrupts`;
|
|
51
|
-
const names = new Set();
|
|
52
|
-
const priorities = new Set();
|
|
53
|
-
for (const interrupt of interrupts) {
|
|
54
|
-
const path = `${prefix}/${interrupt.id}`;
|
|
55
|
-
if (RESERVED_INTERRUPT_TOOL_NAMES.has(interrupt.tool.name)) {
|
|
56
|
-
issues.push({
|
|
57
|
-
code: 'interrupt-tool-reserved',
|
|
58
|
-
message: `Interrupt tool name '${interrupt.tool.name}' is reserved`,
|
|
59
|
-
path,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (names.has(interrupt.tool.name)) {
|
|
63
|
-
issues.push({
|
|
64
|
-
code: 'interrupt-tool-duplicate',
|
|
65
|
-
message: `Interrupt tool name '${interrupt.tool.name}' is not unique`,
|
|
66
|
-
path,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
names.add(interrupt.tool.name);
|
|
70
|
-
if (priorities.has(interrupt.priority)) {
|
|
71
|
-
issues.push({
|
|
72
|
-
code: 'interrupt-priority-tie',
|
|
73
|
-
message: `Interrupt priority ${interrupt.priority} is not unique`,
|
|
74
|
-
path,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
priorities.add(interrupt.priority);
|
|
78
|
-
if (interrupt.action.type === 'switch-language') {
|
|
79
|
-
if (interrupt.action.languages.length === 0) {
|
|
80
|
-
issues.push({
|
|
81
|
-
code: 'interrupt-languages-empty',
|
|
82
|
-
message: 'switch-language languages must not be empty',
|
|
83
|
-
path: `${path}/languages`,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (!getCompiledTable(options.schema, 'contact')?.fields.language) {
|
|
87
|
-
issues.push({
|
|
88
|
-
code: 'interrupt-language-field',
|
|
89
|
-
message: `switch-language requires ${CONTACT_LANGUAGE_FIELD}`,
|
|
90
|
-
path: `${path}/languages`,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (interrupt.action.type === 'transfer') {
|
|
95
|
-
issues.push(...validateTransferDestinations(interrupt.action.numbers, {
|
|
96
|
-
path: `${path}/numbers`,
|
|
97
|
-
code: 'interrupt-transfer-number',
|
|
98
|
-
}));
|
|
99
|
-
issues.push(...validateCriteriaList(interrupt.action.escalateCriteria, `${path}/escalateCriteria`));
|
|
100
|
-
issues.push(...validateCriteriaList(interrupt.action.noEscalationCriteria, `${path}/noEscalationCriteria`));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return issues;
|
|
104
|
-
}
|
|
105
|
-
function validateCriteriaList(list, path) {
|
|
106
|
-
if (!list)
|
|
107
|
-
return [];
|
|
108
|
-
const issues = [];
|
|
109
|
-
for (let index = 0; index < list.length; index++) {
|
|
110
|
-
if (list[index]?.trim())
|
|
111
|
-
continue;
|
|
112
|
-
issues.push({
|
|
113
|
-
code: 'interrupt-escalation-criteria',
|
|
114
|
-
message: 'escalation criteria entry must not be empty',
|
|
115
|
-
path: `${path}[${index}]`,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return issues;
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=interrupts.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FieldPath } from '../slot/path.js';
|
|
2
|
-
import type { CompiledSlotSchema, RuntimeSlotsSnapshot } from '../slot/types.js';
|
|
3
|
-
import type { AgendaBlock, AuthoringNode, FlatIvrItem, IvrBlock } from './types.js';
|
|
4
|
-
export type IvrAttemptResult = 'collected' | 'failed';
|
|
5
|
-
export declare function ivrResultField(nodeId: string): FieldPath;
|
|
6
|
-
export declare function ivrAttempted(item: FlatIvrItem, snapshot: RuntimeSlotsSnapshot): boolean;
|
|
7
|
-
export declare function collectIvrBlocks(blocks: Record<string, AgendaBlock>, nodes?: AuthoringNode[]): IvrBlock[];
|
|
8
|
-
export declare function registerIvrSessionFields(schema: CompiledSlotSchema, ivrIds: Iterable<string>): CompiledSlotSchema;
|
|
9
|
-
//# sourceMappingURL=ivr-fields.d.ts.map
|