@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.
Files changed (282) hide show
  1. package/README.md +28 -8
  2. package/dist/builder/codegen/emit.d.ts +29 -11
  3. package/dist/builder/codegen/emit.js +328 -61
  4. package/dist/builder/codegen/generate.d.ts +21 -0
  5. package/dist/builder/codegen/generate.js +152 -20
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +24 -0
  9. package/dist/builder/company-imports.js +114 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +59 -8
  11. package/dist/builder/compile/compile-sequence.js +279 -77
  12. package/dist/builder/compile/function-code.d.ts +12 -2
  13. package/dist/builder/compile/function-code.js +87 -39
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +24 -23
  16. package/dist/builder/load.d.ts +70 -10
  17. package/dist/builder/load.js +250 -61
  18. package/dist/builder/paths.d.ts +3 -0
  19. package/dist/builder/paths.js +16 -0
  20. package/dist/builder/schedules.d.ts +23 -0
  21. package/dist/builder/schedules.js +102 -0
  22. package/dist/builder/slot-schema-validation.d.ts +4 -0
  23. package/dist/builder/slot-schema-validation.js +10 -0
  24. package/dist/builder/typecheck.d.ts +8 -0
  25. package/dist/builder/typecheck.js +105 -0
  26. package/dist/builder/types.d.ts +91 -19
  27. package/dist/builder/types.js +2 -1
  28. package/dist/cli/auth/auth.d.ts +37 -0
  29. package/dist/cli/auth/auth.js +211 -0
  30. package/dist/cli/auth/backend-url.d.ts +5 -0
  31. package/dist/cli/auth/backend-url.js +25 -0
  32. package/dist/cli/auth/clipboard.d.ts +9 -0
  33. package/dist/cli/auth/clipboard.js +38 -0
  34. package/dist/cli/auth/http.d.ts +20 -0
  35. package/dist/cli/auth/http.js +27 -0
  36. package/dist/cli/auth/index.d.ts +10 -0
  37. package/dist/cli/auth/index.js +27 -0
  38. package/dist/cli/auth/progress.d.ts +12 -0
  39. package/dist/cli/auth/progress.js +15 -0
  40. package/dist/cli/auth/serve-login.d.ts +8 -0
  41. package/dist/cli/auth/serve-login.js +24 -0
  42. package/dist/cli/compile/index.js +3 -0
  43. package/dist/cli/config.d.ts +10 -0
  44. package/dist/cli/config.js +52 -0
  45. package/dist/cli/index.js +28 -8
  46. package/dist/cli/serve/index.d.ts +73 -3
  47. package/dist/cli/serve/index.js +365 -116
  48. package/dist/cli/type-gen/index.js +9 -8
  49. package/dist/compiler.d.ts +7 -0
  50. package/dist/compiler.js +7 -0
  51. package/dist/compute-host/compute-host.d.ts +15 -23
  52. package/dist/compute-host/compute-host.js +25 -28
  53. package/dist/compute-host/index.d.ts +2 -4
  54. package/dist/compute-host/index.js +1 -2
  55. package/dist/compute-host/source-compute-host.d.ts +11 -9
  56. package/dist/compute-host/source-compute-host.js +46 -32
  57. package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
  58. package/dist/core/case-orchestrator/contact-hours.js +108 -0
  59. package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
  60. package/dist/core/case-orchestrator/follow-ups.js +103 -0
  61. package/dist/core/case-orchestrator/index.d.ts +6 -0
  62. package/dist/core/case-orchestrator/index.js +6 -0
  63. package/dist/core/case-orchestrator/render.d.ts +75 -0
  64. package/dist/core/case-orchestrator/render.js +239 -0
  65. package/dist/core/case-orchestrator/time.d.ts +11 -0
  66. package/dist/core/case-orchestrator/time.js +29 -0
  67. package/dist/core/case-orchestrator/tools.d.ts +29 -0
  68. package/dist/core/case-orchestrator/tools.js +31 -0
  69. package/dist/core/case-orchestrator/types.d.ts +753 -0
  70. package/dist/core/case-orchestrator/types.js +46 -0
  71. package/dist/core/case-orchestrator/validate.d.ts +11 -0
  72. package/dist/core/case-orchestrator/validate.js +63 -0
  73. package/dist/core/context/call.d.ts +291 -0
  74. package/dist/core/context/call.js +94 -0
  75. package/dist/core/context/channels.d.ts +60 -0
  76. package/dist/core/context/channels.js +35 -0
  77. package/dist/core/context/contact.d.ts +96 -6
  78. package/dist/core/context/contact.js +48 -2
  79. package/dist/core/context/email-message.d.ts +159 -0
  80. package/dist/core/context/email-message.js +59 -0
  81. package/dist/core/context/email.d.ts +97 -0
  82. package/dist/core/context/email.js +91 -0
  83. package/dist/core/context/exchanges.d.ts +142 -0
  84. package/dist/core/context/exchanges.js +63 -0
  85. package/dist/core/context/instances.d.ts +278 -0
  86. package/dist/core/context/instances.js +123 -0
  87. package/dist/core/context/kv.d.ts +113 -0
  88. package/dist/core/context/kv.js +60 -0
  89. package/dist/core/context/platform-registry.d.ts +509 -4
  90. package/dist/core/context/platform-registry.js +14 -2
  91. package/dist/core/context/platform.d.ts +2 -1
  92. package/dist/core/context/sms.d.ts +147 -0
  93. package/dist/core/context/sms.js +57 -0
  94. package/dist/core/context/types.d.ts +51 -48
  95. package/dist/core/context/types.js +1 -7
  96. package/dist/core/conversation/index.d.ts +31 -0
  97. package/dist/core/conversation/index.js +14 -0
  98. package/dist/core/functions/define/bind.d.ts +25 -0
  99. package/dist/core/functions/define/bind.js +14 -0
  100. package/dist/core/functions/define/case.d.ts +9 -0
  101. package/dist/core/functions/define/case.js +13 -0
  102. package/dist/core/functions/define/events.d.ts +20 -0
  103. package/dist/core/functions/define/events.js +21 -0
  104. package/dist/core/functions/define/no-case.d.ts +4 -0
  105. package/dist/core/functions/define/no-case.js +9 -0
  106. package/dist/core/functions/events.d.ts +247 -0
  107. package/dist/core/functions/events.js +32 -0
  108. package/dist/core/functions/func-ref.d.ts +11 -2
  109. package/dist/core/functions/schedules.d.ts +51 -0
  110. package/dist/core/functions/schedules.js +20 -0
  111. package/dist/core/functions/types.d.ts +62 -51
  112. package/dist/core/functions/types.js +6 -1
  113. package/dist/core/office-hours/index.d.ts +39 -0
  114. package/dist/core/office-hours/index.js +187 -0
  115. package/dist/core/page/define.d.ts +834 -0
  116. package/dist/core/page/define.js +477 -0
  117. package/dist/core/page/ops.d.ts +58 -0
  118. package/dist/core/page/ops.js +220 -0
  119. package/dist/core/page/render.d.ts +253 -0
  120. package/dist/core/page/render.js +840 -0
  121. package/dist/core/page/time-format.d.ts +19 -0
  122. package/dist/core/page/time-format.js +41 -0
  123. package/dist/core/page/timeline.d.ts +40 -0
  124. package/dist/core/page/timeline.js +2 -0
  125. package/dist/core/page/typed.d.ts +642 -0
  126. package/dist/core/page/typed.js +2 -0
  127. package/dist/core/page/workspace.d.ts +33 -0
  128. package/dist/core/page/workspace.js +231 -0
  129. package/dist/core/party/index.d.ts +3 -0
  130. package/dist/core/party/index.js +3 -0
  131. package/dist/core/party/schema.d.ts +137 -0
  132. package/dist/core/party/schema.js +80 -0
  133. package/dist/core/party/types.d.ts +40 -0
  134. package/dist/core/party/types.js +15 -0
  135. package/dist/core/sequence/define.d.ts +57 -0
  136. package/dist/core/sequence/define.js +10 -0
  137. package/dist/core/sequence/index.d.ts +63 -0
  138. package/dist/core/sequence/index.js +231 -0
  139. package/dist/core/slot/binding.d.ts +40 -0
  140. package/dist/core/slot/binding.js +2 -0
  141. package/dist/core/slot/company-metadata.d.ts +113 -0
  142. package/dist/core/slot/company-metadata.js +563 -0
  143. package/dist/core/slot/compile-schema.d.ts +19 -13
  144. package/dist/core/slot/compile-schema.js +51 -248
  145. package/dist/core/slot/contact-timezone.d.ts +110 -0
  146. package/dist/core/slot/contact-timezone.js +186 -0
  147. package/dist/core/slot/field.d.ts +2 -24
  148. package/dist/core/slot/field.js +0 -69
  149. package/dist/core/slot/id-ref.d.ts +17 -2
  150. package/dist/core/slot/id-ref.js +16 -8
  151. package/dist/core/slot/index.d.ts +12 -13
  152. package/dist/core/slot/index.js +11 -12
  153. package/dist/core/slot/naming.d.ts +15 -0
  154. package/dist/core/slot/naming.js +96 -0
  155. package/dist/core/slot/platform-fields.d.ts +119 -0
  156. package/dist/core/slot/platform-fields.js +121 -0
  157. package/dist/core/slot/ref.d.ts +16 -0
  158. package/dist/core/slot/ref.js +14 -0
  159. package/dist/core/slot/row.d.ts +2 -9
  160. package/dist/core/slot/row.js +13 -23
  161. package/dist/core/slot/schema-compat.d.ts +16 -0
  162. package/dist/core/slot/schema-compat.js +112 -0
  163. package/dist/core/slot/schema.d.ts +409 -76
  164. package/dist/core/slot/schema.js +178 -10
  165. package/dist/core/slot/types.d.ts +27 -94
  166. package/dist/core/slot/value.d.ts +26 -3
  167. package/dist/core/slot/value.js +89 -57
  168. package/dist/dev-overlay/protocol.d.ts +41 -8
  169. package/dist/fn-context/build-context.d.ts +3 -1
  170. package/dist/fn-context/build-context.js +20 -10
  171. package/dist/fn-context/fake/empty-api.js +9 -28
  172. package/dist/fn-context/fake/index.d.ts +11 -4
  173. package/dist/fn-context/fake/index.js +27 -2
  174. package/dist/fn-context/fn-params.d.ts +6 -0
  175. package/dist/fn-context/fn-params.js +13 -0
  176. package/dist/fn-context/index.d.ts +5 -5
  177. package/dist/fn-context/index.js +4 -4
  178. package/dist/fn-context/log.js +2 -2
  179. package/dist/fn-context/make-ctx.d.ts +11 -0
  180. package/dist/fn-context/make-ctx.js +18 -8
  181. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
  182. package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
  183. package/dist/fn-context/rpc/index.d.ts +3 -1
  184. package/dist/fn-context/rpc/index.js +3 -1
  185. package/dist/fn-context/rpc/integration/index.d.ts +4 -4
  186. package/dist/fn-context/rpc/integration/index.js +1 -1
  187. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  188. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  189. package/dist/fn-context/rpc/platform.d.ts +2 -2
  190. package/dist/fn-context/rpc/platform.js +1 -1
  191. package/dist/fn-context/rpc/records.d.ts +78 -0
  192. package/dist/fn-context/rpc/records.js +26 -0
  193. package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
  194. package/dist/fn-context/rpc/trpc-client.js +88 -7
  195. package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
  196. package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
  197. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  198. package/dist/fn-context/run-scope.d.ts +4 -0
  199. package/dist/fn-context/run-scope.js +9 -0
  200. package/dist/fn-context/types.d.ts +36 -3
  201. package/dist/index.d.ts +37 -46
  202. package/dist/index.js +33 -33
  203. package/dist/logger.d.ts +7 -0
  204. package/dist/logger.js +41 -0
  205. package/dist/platform.d.ts +76 -0
  206. package/dist/platform.js +56 -0
  207. package/dist/voice-service/actions.d.ts +71 -4
  208. package/dist/voice-service/types.d.ts +42 -5
  209. package/dist/worker.d.ts +10 -0
  210. package/dist/worker.js +10 -0
  211. package/package.json +38 -19
  212. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  213. package/dist/builder/compile/compile-agenda.js +0 -64
  214. package/dist/builder/merge.d.ts +0 -4
  215. package/dist/builder/merge.js +0 -19
  216. package/dist/compute-host/read-only-cache.d.ts +0 -20
  217. package/dist/compute-host/read-only-cache.js +0 -61
  218. package/dist/core/context/db.d.ts +0 -69
  219. package/dist/core/context/db.js +0 -44
  220. package/dist/core/context/docusign.d.ts +0 -134
  221. package/dist/core/context/docusign.js +0 -108
  222. package/dist/core/context/filevine.d.ts +0 -323
  223. package/dist/core/context/filevine.js +0 -254
  224. package/dist/core/context/http.d.ts +0 -9
  225. package/dist/core/context/http.js +0 -4
  226. package/dist/core/context/hubspot.d.ts +0 -250
  227. package/dist/core/context/hubspot.js +0 -191
  228. package/dist/core/context/twilio.d.ts +0 -50
  229. package/dist/core/context/twilio.js +0 -42
  230. package/dist/core/functions/define/case-context.d.ts +0 -14
  231. package/dist/core/functions/define/case-context.js +0 -15
  232. package/dist/core/functions/define/compute.d.ts +0 -7
  233. package/dist/core/functions/define/compute.js +0 -17
  234. package/dist/core/functions/define/custom.d.ts +0 -4
  235. package/dist/core/functions/define/custom.js +0 -8
  236. package/dist/core/functions/define/system.d.ts +0 -7
  237. package/dist/core/functions/define/system.js +0 -12
  238. package/dist/core/slot/deps.d.ts +0 -15
  239. package/dist/core/slot/deps.js +0 -88
  240. package/dist/core/slot/derived.d.ts +0 -32
  241. package/dist/core/slot/derived.js +0 -115
  242. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  243. package/dist/core/slot/platform-session-fields.js +0 -48
  244. package/dist/core/slot/sf-schema.d.ts +0 -23
  245. package/dist/core/slot/sf-schema.js +0 -125
  246. package/dist/core/slot/sf-validate.d.ts +0 -14
  247. package/dist/core/slot/sf-validate.js +0 -132
  248. package/dist/core/slot/snapshot.d.ts +0 -18
  249. package/dist/core/slot/snapshot.js +0 -138
  250. package/dist/core/slot/write.d.ts +0 -48
  251. package/dist/core/slot/write.js +0 -426
  252. package/dist/core/stage/builders.d.ts +0 -54
  253. package/dist/core/stage/builders.js +0 -31
  254. package/dist/core/stage/condition.d.ts +0 -17
  255. package/dist/core/stage/condition.js +0 -198
  256. package/dist/core/stage/drive.d.ts +0 -43
  257. package/dist/core/stage/drive.js +0 -78
  258. package/dist/core/stage/finish-when.d.ts +0 -20
  259. package/dist/core/stage/finish-when.js +0 -82
  260. package/dist/core/stage/flatten.d.ts +0 -27
  261. package/dist/core/stage/flatten.js +0 -466
  262. package/dist/core/stage/index.d.ts +0 -15
  263. package/dist/core/stage/index.js +0 -13
  264. package/dist/core/stage/interrupts.d.ts +0 -28
  265. package/dist/core/stage/interrupts.js +0 -120
  266. package/dist/core/stage/ivr-fields.d.ts +0 -9
  267. package/dist/core/stage/ivr-fields.js +0 -75
  268. package/dist/core/stage/simulate.d.ts +0 -24
  269. package/dist/core/stage/simulate.js +0 -33
  270. package/dist/core/stage/transfer-fields.d.ts +0 -19
  271. package/dist/core/stage/transfer-fields.js +0 -129
  272. package/dist/core/stage/transfer-spec.d.ts +0 -48
  273. package/dist/core/stage/transfer-spec.js +0 -113
  274. package/dist/core/stage/types.d.ts +0 -208
  275. package/dist/core/stage/types.js +0 -2
  276. package/dist/core/stage/validate.d.ts +0 -11
  277. package/dist/core/stage/validate.js +0 -330
  278. package/dist/core/stage/walk.d.ts +0 -39
  279. package/dist/core/stage/walk.js +0 -119
  280. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  281. package/dist/fn-context/system-args.d.ts +0 -6
  282. package/dist/fn-context/system-args.js +0 -14
@@ -1,330 +0,0 @@
1
- import { getCompiledTable } from '../slot/compile-schema.js';
2
- import { parseFieldPath } from '../slot/path.js';
3
- import { extractTemplateFields } from './condition.js';
4
- import { whenFields } from './finish-when.js';
5
- import { headerHasTransferInterrupt, validateInterrupts } from './interrupts.js';
6
- import { LAST_TRANSFER_RESULT_FIELD } from './transfer-fields.js';
7
- import { validateTransferDestinations } from './transfer-spec.js';
8
- function fieldExists(schema, path) {
9
- const parsed = parseFieldPath(path);
10
- if (!parsed)
11
- return false;
12
- return getCompiledTable(schema, parsed.table)?.fields[parsed.field] != null;
13
- }
14
- function requireFields(schema, fields, issues, path, code = 'unknown-field') {
15
- for (const field of fields) {
16
- if (!parseFieldPath(field)) {
17
- issues.push({ code: 'invalid-field-path', message: `Invalid field path: ${field}`, path: `${path}:${field}` });
18
- continue;
19
- }
20
- if (!fieldExists(schema, field)) {
21
- issues.push({ code, message: `Unknown field: ${field}`, path: `${path}:${field}` });
22
- }
23
- }
24
- }
25
- function earlierCollected(items, index) {
26
- const collected = new Set();
27
- for (let i = 0; i < index; i++) {
28
- const item = items[i];
29
- if (item.kind === 'topic') {
30
- for (const field of item.fields)
31
- collected.add(field);
32
- }
33
- if (item.kind === 'ivr') {
34
- for (const field of whenFields(item.finishWhen))
35
- collected.add(field);
36
- }
37
- }
38
- return collected;
39
- }
40
- function transferIndexByResultField(items) {
41
- const map = new Map();
42
- items.forEach((item, index) => {
43
- if (item.kind === 'transfer') {
44
- map.set(item.resultField, index);
45
- }
46
- });
47
- return map;
48
- }
49
- function listedCustomFunctions(functions) {
50
- const names = Object.entries(functions)
51
- .filter(([, def]) => def.kind === 'custom')
52
- .map(([name]) => name)
53
- .sort((a, b) => a.localeCompare(b));
54
- return names.length > 0 ? names.join(', ') : 'none';
55
- }
56
- function requireBoolWhen(when, functions, issues, path, label) {
57
- if (when.kind === 'fn') {
58
- const def = functions?.[when.fn];
59
- if (functions && !def) {
60
- issues.push({ code: 'unknown-function', message: `${label} fn not found: ${when.fn}`, path });
61
- }
62
- else if (def && def.kind !== 'boolCompute') {
63
- issues.push({
64
- code: label === 'applyWhen' ? 'apply-when-not-bool' : 'finish-when-not-bool',
65
- message: `${label} fn '${when.fn}' must be defineBoolComputeFunc`,
66
- path,
67
- });
68
- }
69
- return;
70
- }
71
- }
72
- function firstTransferIndex(items) {
73
- return items.findIndex((item) => item.kind === 'transfer');
74
- }
75
- export function validateCompiledAgenda(compiled, options) {
76
- const issues = [];
77
- const { schema, functions } = options;
78
- const prefix = options.agendaId ?? 'agenda';
79
- const items = compiled.flat;
80
- const seenPlacement = new Set();
81
- const transferByResult = transferIndexByResultField(items);
82
- const firstTransfer = firstTransferIndex(items);
83
- const transferInterrupt = headerHasTransferInterrupt(compiled.header);
84
- if (compiled.header) {
85
- issues.push(...validateInterrupts(compiled.header.interrupts, {
86
- schema,
87
- agendaId: prefix,
88
- }));
89
- }
90
- if (compiled.header?.channel && compiled.header.channel !== 'call') {
91
- for (const item of items) {
92
- if (item.kind === 'transfer') {
93
- issues.push({
94
- code: 'transfer-channel',
95
- message: `Transfer ${item.id} is only valid on call agendas`,
96
- path: `${prefix}/${item.placementId}`,
97
- });
98
- }
99
- if (item.kind === 'ivr') {
100
- issues.push({
101
- code: 'ivr-channel',
102
- message: `IVR ${item.id} is only valid on call agendas`,
103
- path: `${prefix}/${item.placementId}`,
104
- });
105
- }
106
- }
107
- }
108
- if (compiled.header?.firstMessage?.kind === 'template') {
109
- requireFields(schema, extractTemplateFields(compiled.header.firstMessage.text), issues, `${prefix}/header/firstMessage`);
110
- }
111
- if (compiled.header?.firstMessage?.kind === 'fn') {
112
- const name = compiled.header.firstMessage.fn;
113
- const def = functions?.[name];
114
- if (functions && !def) {
115
- issues.push({
116
- code: 'unknown-function',
117
- message: `firstMessage fn not found: ${name}`,
118
- path: `${prefix}/header/firstMessage`,
119
- });
120
- }
121
- else if (def && def.kind !== 'system') {
122
- issues.push({
123
- code: 'invalid-function-kind',
124
- message: `firstMessage fn must be a system function: ${name}`,
125
- path: `${prefix}/header/firstMessage`,
126
- });
127
- }
128
- }
129
- for (let index = 0; index < items.length; index++) {
130
- const item = items[index];
131
- const path = `${prefix}/${item.placementId}`;
132
- if (seenPlacement.has(item.placementId)) {
133
- issues.push({ code: 'duplicate-placement', message: `Duplicate placementId: ${item.placementId}`, path });
134
- }
135
- seenPlacement.add(item.placementId);
136
- requireFields(schema, whenFields(item.applyWhen), issues, `${path}/applyWhen`);
137
- const collected = earlierCollected(items, index);
138
- for (const field of whenFields(item.applyWhen)) {
139
- if (field.startsWith('session.transfer_') && field.endsWith('_result')) {
140
- const writer = transferByResult.get(field);
141
- if (writer == null || writer >= index) {
142
- issues.push({
143
- code: 'transfer-result-before-node',
144
- message: `applyWhen reads ${field} before the transfer node`,
145
- path: `${path}/applyWhen`,
146
- });
147
- }
148
- continue;
149
- }
150
- if (field === LAST_TRANSFER_RESULT_FIELD) {
151
- if (!transferInterrupt && (firstTransfer < 0 || firstTransfer >= index)) {
152
- issues.push({
153
- code: 'transfer-result-before-node',
154
- message: `applyWhen reads ${LAST_TRANSFER_RESULT_FIELD} before any transfer`,
155
- path: `${path}/applyWhen`,
156
- });
157
- }
158
- continue;
159
- }
160
- const parsed = parseFieldPath(field);
161
- const def = parsed ? getCompiledTable(schema, parsed.table)?.fields[parsed.field] : undefined;
162
- if (def?.derived)
163
- continue;
164
- if (def && !def.derived && def.source === 'system')
165
- continue;
166
- if (!collected.has(field)) {
167
- issues.push({
168
- code: 'fork-field-not-collected',
169
- message: `applyWhen field ${field} is not collected by an earlier topic`,
170
- path: `${path}/applyWhen`,
171
- });
172
- }
173
- }
174
- requireBoolWhen(item.applyWhen, functions, issues, `${path}/applyWhen`, 'applyWhen');
175
- if (item.kind === 'ivr') {
176
- requireBoolWhen(item.finishWhen, functions, issues, `${path}/finishWhen`, 'finishWhen');
177
- if (item.finishWhen.kind === 'rules') {
178
- requireFields(schema, whenFields(item.finishWhen), issues, `${path}/finishWhen`);
179
- }
180
- const run = functions?.[item.onDtmfResult];
181
- if (functions && !run) {
182
- issues.push({
183
- code: 'unknown-function',
184
- message: `IVR '${item.id}' onDtmfResult unknown function '${item.onDtmfResult}'. Custom functions: ${listedCustomFunctions(functions)}`,
185
- path: `${path}/onDtmfResult`,
186
- });
187
- }
188
- else if (run && run.kind !== 'custom') {
189
- issues.push({
190
- code: 'ivr-run-not-custom',
191
- message: `IVR '${item.id}' onDtmfResult '${item.onDtmfResult}' must be defineCustomFunc`,
192
- path: `${path}/onDtmfResult`,
193
- });
194
- }
195
- if (!item.loopSay.trim()) {
196
- issues.push({
197
- code: 'ivr-say-empty',
198
- message: 'ivr loopSay must not be empty',
199
- path: `${path}/loopSay`,
200
- });
201
- }
202
- if (!(item.confirmTimeoutMs > 0) || !(item.pauseAfterSayMs >= 0)) {
203
- issues.push({
204
- code: 'ivr-timing',
205
- message: 'ivr confirmTimeoutMs must be > 0 and pauseAfterSayMs must be >= 0',
206
- path: `${path}/timing`,
207
- });
208
- }
209
- if (item.fallbackAction !== 'end-call' && item.fallbackAction !== 'restore-normal-call-state') {
210
- issues.push({
211
- code: 'ivr-fallback',
212
- message: 'ivr fallbackAction must be end-call or restore-normal-call-state',
213
- path: `${path}/fallbackAction`,
214
- });
215
- }
216
- const digits = (item.validateDigits ?? []).map((digit) => digit.trim()).filter(Boolean);
217
- if (!item.finishOnKey && digits.length === 0) {
218
- issues.push({
219
- code: 'ivr-digits-empty',
220
- message: 'ivr needs validateDigits when finishOnKey is not set',
221
- path: `${path}/validateDigits`,
222
- });
223
- }
224
- }
225
- if (item.kind === 'topic') {
226
- requireFields(schema, item.fields, issues, `${path}/fields`);
227
- const referenced = whenFields(item.finishWhen);
228
- requireFields(schema, referenced, issues, `${path}/finishWhen`);
229
- requireBoolWhen(item.finishWhen, functions, issues, `${path}/finishWhen`, 'finishWhen');
230
- if (item.finishWhen.kind !== 'fn') {
231
- for (const field of referenced) {
232
- if (!item.fields.includes(field)) {
233
- issues.push({
234
- code: 'finish-when-not-in-fields',
235
- message: `finishWhen field ${field} is not in topic fields`,
236
- path: `${path}/finishWhen`,
237
- });
238
- }
239
- }
240
- }
241
- }
242
- if (item.kind === 'action') {
243
- requireBoolWhen(item.finishWhen, functions, issues, `${path}/finishWhen`, 'finishWhen');
244
- if (item.finishWhen.kind === 'rules') {
245
- requireFields(schema, whenFields(item.finishWhen), issues, `${path}/finishWhen`);
246
- }
247
- const run = functions?.[item.run];
248
- if (functions && !run) {
249
- issues.push({
250
- code: 'unknown-function',
251
- message: `Action '${item.id}' runs unknown function '${item.run}'. Custom functions: ${listedCustomFunctions(functions)}`,
252
- path: `${path}/run`,
253
- });
254
- }
255
- else if (run && run.kind !== 'custom') {
256
- issues.push({
257
- code: 'action-run-not-custom',
258
- message: `Action '${item.id}' runs '${item.run}', which is ${run.kind}. Actions must use defineCustomFunc.`,
259
- path: `${path}/run`,
260
- });
261
- }
262
- }
263
- if (item.kind === 'transfer') {
264
- for (const number of item.numbers) {
265
- requireFields(schema, extractTemplateFields(number), issues, `${path}/numbers`);
266
- }
267
- if (item.arguments) {
268
- for (const key of ['sendDigits', 'sipUrl', 'sipUsername', 'sipPassword']) {
269
- const text = item.arguments[key];
270
- if (text) {
271
- requireFields(schema, extractTemplateFields(text), issues, `${path}/arguments/${key}`);
272
- }
273
- }
274
- }
275
- if (typeof item.say === 'string') {
276
- requireFields(schema, extractTemplateFields(item.say), issues, `${path}/say`);
277
- }
278
- else if (item.say) {
279
- for (const text of Object.values(item.say)) {
280
- requireFields(schema, extractTemplateFields(text), issues, `${path}/say`);
281
- }
282
- }
283
- issues.push(...validateTransferDestinations(item.numbers, {
284
- path: `${path}/numbers`,
285
- code: 'transfer-target',
286
- }));
287
- requireFields(schema, [item.resultField, LAST_TRANSFER_RESULT_FIELD], issues, `${path}/result`);
288
- }
289
- }
290
- return issues.length === 0 ? { ok: true } : { ok: false, issues };
291
- }
292
- const FATAL_AGENDA_CODES = new Set([
293
- 'unknown-block',
294
- 'unknown-field',
295
- 'invalid-field-path',
296
- 'invalid-finish-when',
297
- 'unknown-function',
298
- 'finish-when-not-bool',
299
- 'apply-when-not-bool',
300
- 'invalid-apply-when',
301
- 'finish-when-not-in-fields',
302
- 'fork-field-not-collected',
303
- 'otherwise-not-unique',
304
- 'otherwise-not-last',
305
- 'branch-no-explicit',
306
- 'otherwise-unexpanded',
307
- 'transfer-channel',
308
- 'ivr-channel',
309
- 'ivr-run-not-custom',
310
- 'ivr-fallback',
311
- 'ivr-timing',
312
- 'ivr-say-empty',
313
- 'ivr-digits-empty',
314
- 'transfer-result-before-node',
315
- 'action-run-not-custom',
316
- 'duplicate-placement',
317
- 'block-kind-mismatch',
318
- 'interrupt-tool-reserved',
319
- 'interrupt-tool-duplicate',
320
- 'interrupt-priority-tie',
321
- 'interrupt-languages-empty',
322
- 'interrupt-language-field',
323
- 'interrupt-transfer-number',
324
- 'interrupt-escalation-criteria',
325
- 'transfer-target',
326
- ]);
327
- export function fatalAgendaIssues(issues) {
328
- return issues.filter((issue) => FATAL_AGENDA_CODES.has(issue.code));
329
- }
330
- //# sourceMappingURL=validate.js.map
@@ -1,39 +0,0 @@
1
- import type { ComputeHost } from '../../compute-host/compute-host.js';
2
- import type { FieldPath } from '../slot/path.js';
3
- import type { RuntimeSlotsSnapshot } from '../slot/types.js';
4
- import type { FlatAgendaItem } from './types.js';
5
- export type WalkSkipReason = 'folded' | 'done' | 'skipped';
6
- export type WalkSkip = {
7
- placementId: string;
8
- blockId: string;
9
- reason: WalkSkipReason;
10
- };
11
- export type WalkHitReason = 'sticky' | 'scan';
12
- export type WalkStats = {
13
- durationMs: number;
14
- evals: number;
15
- };
16
- export type WalkResult = {
17
- hit: FlatAgendaItem | null;
18
- reason: WalkHitReason | 'complete';
19
- skipped: WalkSkip[];
20
- decisions: WalkDecision[];
21
- stats: WalkStats;
22
- };
23
- export type WalkDecision = {
24
- placementId: string;
25
- blockId: string;
26
- status: 'folded' | 'done' | 'hit' | 'skipped';
27
- via: WalkHitReason;
28
- applyWhen: boolean | null;
29
- finishWhen: boolean | null;
30
- };
31
- export type WalkOptions = {
32
- currentPlacementId?: string | null;
33
- /** This-tick skips (action returned null). */
34
- skipPlacementIds?: ReadonlySet<string>;
35
- compute?: ComputeHost;
36
- };
37
- export declare function walkAgenda(items: FlatAgendaItem[], snapshot: RuntimeSlotsSnapshot, options?: WalkOptions): Promise<WalkResult>;
38
- export declare function unresolvedFinishWhenFields(item: FlatAgendaItem, snapshot: RuntimeSlotsSnapshot, compute?: ComputeHost): Promise<FieldPath[]>;
39
- //# sourceMappingURL=walk.d.ts.map
@@ -1,119 +0,0 @@
1
- import { evaluateWhen } from './finish-when.js';
2
- import { ivrAttempted } from './ivr-fields.js';
3
- function startsWithGroup(groupPath, prefix) {
4
- if (prefix.length === 0)
5
- return true;
6
- if (groupPath.length < prefix.length)
7
- return false;
8
- return prefix.every((id, i) => groupPath[i] === id);
9
- }
10
- async function consider(item, snapshot, compute, skip, via, skipped, decisions, stats) {
11
- if (skip.has(item.placementId)) {
12
- skipped.push({ placementId: item.placementId, blockId: item.id, reason: 'skipped' });
13
- decisions.push({
14
- placementId: item.placementId,
15
- blockId: item.id,
16
- status: 'skipped',
17
- via,
18
- applyWhen: null,
19
- finishWhen: null,
20
- });
21
- return 'skip';
22
- }
23
- stats.evals += 1;
24
- const applies = await evaluateWhen(item.applyWhen, snapshot, compute);
25
- if (!applies.pass) {
26
- skipped.push({ placementId: item.placementId, blockId: item.id, reason: 'folded' });
27
- decisions.push({
28
- placementId: item.placementId,
29
- blockId: item.id,
30
- status: 'folded',
31
- via,
32
- applyWhen: false,
33
- finishWhen: null,
34
- });
35
- return 'fold';
36
- }
37
- if (item.kind === 'ivr' && ivrAttempted(item, snapshot)) {
38
- skipped.push({ placementId: item.placementId, blockId: item.id, reason: 'done' });
39
- decisions.push({
40
- placementId: item.placementId,
41
- blockId: item.id,
42
- status: 'done',
43
- via,
44
- applyWhen: true,
45
- finishWhen: true,
46
- });
47
- return 'done';
48
- }
49
- stats.evals += 1;
50
- const finished = await evaluateWhen(item.finishWhen, snapshot, compute);
51
- if (finished.done) {
52
- skipped.push({ placementId: item.placementId, blockId: item.id, reason: 'done' });
53
- decisions.push({
54
- placementId: item.placementId,
55
- blockId: item.id,
56
- status: 'done',
57
- via,
58
- applyWhen: true,
59
- finishWhen: true,
60
- });
61
- return 'done';
62
- }
63
- decisions.push({
64
- placementId: item.placementId,
65
- blockId: item.id,
66
- status: 'hit',
67
- via,
68
- applyWhen: true,
69
- finishWhen: false,
70
- });
71
- return 'hit';
72
- }
73
- async function firstHit(items, snapshot, compute, skip, via, skipped, decisions, considered, stats) {
74
- for (const item of items) {
75
- if (considered.has(item.placementId))
76
- continue;
77
- considered.add(item.placementId);
78
- if ((await consider(item, snapshot, compute, skip, via, skipped, decisions, stats)) === 'hit') {
79
- return item;
80
- }
81
- }
82
- return null;
83
- }
84
- export async function walkAgenda(items, snapshot, options = {}) {
85
- const started = Date.now();
86
- const skip = options.skipPlacementIds ?? new Set();
87
- const skipped = [];
88
- const decisions = [];
89
- const considered = new Set();
90
- const stats = { evals: 0 };
91
- const currentId = options.currentPlacementId ?? null;
92
- const finish = (hit, reason) => ({
93
- hit,
94
- reason,
95
- skipped,
96
- decisions,
97
- stats: { durationMs: Date.now() - started, evals: stats.evals },
98
- });
99
- if (currentId) {
100
- const current = items.find((item) => item.placementId === currentId);
101
- if (current && current.groupPath.length > 0) {
102
- for (let depth = current.groupPath.length; depth >= 1; depth--) {
103
- const prefix = current.groupPath.slice(0, depth);
104
- const groupItems = items.filter((item) => startsWithGroup(item.groupPath, prefix));
105
- const hit = await firstHit(groupItems, snapshot, options.compute, skip, 'sticky', skipped, decisions, considered, stats);
106
- if (hit)
107
- return finish(hit, 'sticky');
108
- }
109
- }
110
- }
111
- const hit = await firstHit(items, snapshot, options.compute, skip, 'scan', skipped, decisions, considered, stats);
112
- if (hit)
113
- return finish(hit, 'scan');
114
- return finish(null, 'complete');
115
- }
116
- export async function unresolvedFinishWhenFields(item, snapshot, compute) {
117
- return (await evaluateWhen(item.finishWhen, snapshot, compute)).failedFields;
118
- }
119
- //# sourceMappingURL=walk.js.map
@@ -1,21 +0,0 @@
1
- import { type BoundIntegrationMeta } from '../../../core/context/types.js';
2
- import { type RpcContext } from '../trpc-init.js';
3
- export type ListBindingsHandler = (opts: {
4
- ctx: RpcContext;
5
- }) => Promise<BoundIntegrationMeta[]>;
6
- export declare function createListBindingsProcedure(handler: ListBindingsHandler): import("@trpc/server").TRPCQueryProcedure<{
7
- input: void;
8
- output: {
9
- surfaceKey: "docusigns" | "envs" | "filevines" | "hubspots" | "twilios";
10
- target: {
11
- kind: "account" | "resource";
12
- id: string;
13
- };
14
- name: string;
15
- methods: string[];
16
- credentials: Record<string, unknown>;
17
- config: Record<string, unknown>;
18
- }[];
19
- meta: object;
20
- }>;
21
- //# sourceMappingURL=list-bindings.d.ts.map
@@ -1,6 +0,0 @@
1
- /**
2
- * `kind: 'system'` — `args[0]` is the params object (empty when omitted).
3
- * Snapshot projection belongs to compute / custom / caseContextView, not here.
4
- */
5
- export declare function resolveSystemFnParams(args: unknown[]): object;
6
- //# sourceMappingURL=system-args.d.ts.map
@@ -1,14 +0,0 @@
1
- /**
2
- * `kind: 'system'` — `args[0]` is the params object (empty when omitted).
3
- * Snapshot projection belongs to compute / custom / caseContextView, not here.
4
- */
5
- export function resolveSystemFnParams(args) {
6
- const raw = args[0];
7
- if (raw == null)
8
- return {};
9
- if (typeof raw !== 'object' || Array.isArray(raw)) {
10
- throw new Error('system function args[0] must be a params object');
11
- }
12
- return raw;
13
- }
14
- //# sourceMappingURL=system-args.js.map