@superpanel-sdk/runtime 0.2.3 → 0.7.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 (319) hide show
  1. package/README.md +30 -10
  2. package/dist/builder/codegen/emit.d.ts +25 -12
  3. package/dist/builder/codegen/emit.js +339 -78
  4. package/dist/builder/codegen/generate.d.ts +21 -2
  5. package/dist/builder/codegen/generate.js +147 -34
  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 +29 -0
  9. package/dist/builder/company-imports.js +122 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +61 -8
  11. package/dist/builder/compile/compile-sequence.js +334 -80
  12. package/dist/builder/compile/function-code.d.ts +19 -3
  13. package/dist/builder/compile/function-code.js +123 -45
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +30 -27
  16. package/dist/builder/errors.d.ts +9 -0
  17. package/dist/builder/errors.js +17 -0
  18. package/dist/builder/function-params.d.ts +10 -0
  19. package/dist/builder/function-params.js +203 -0
  20. package/dist/builder/load.d.ts +70 -10
  21. package/dist/builder/load.js +258 -67
  22. package/dist/builder/paths.d.ts +9 -1
  23. package/dist/builder/paths.js +32 -2
  24. package/dist/builder/schedules.d.ts +25 -0
  25. package/dist/builder/schedules.js +101 -0
  26. package/dist/builder/slot-schema-validation.d.ts +4 -0
  27. package/dist/builder/slot-schema-validation.js +10 -0
  28. package/dist/builder/typecheck.d.ts +8 -0
  29. package/dist/builder/typecheck.js +102 -0
  30. package/dist/builder/types.d.ts +127 -19
  31. package/dist/builder/types.js +21 -1
  32. package/dist/cli/auth/auth.d.ts +37 -0
  33. package/dist/cli/auth/auth.js +211 -0
  34. package/dist/cli/auth/backend-url.d.ts +5 -0
  35. package/dist/cli/auth/backend-url.js +25 -0
  36. package/dist/cli/auth/clipboard.d.ts +9 -0
  37. package/dist/cli/auth/clipboard.js +38 -0
  38. package/dist/cli/auth/http.d.ts +20 -0
  39. package/dist/cli/auth/http.js +27 -0
  40. package/dist/cli/auth/index.d.ts +10 -0
  41. package/dist/cli/auth/index.js +27 -0
  42. package/dist/cli/auth/progress.d.ts +12 -0
  43. package/dist/cli/auth/progress.js +15 -0
  44. package/dist/cli/auth/serve-login.d.ts +8 -0
  45. package/dist/cli/auth/serve-login.js +24 -0
  46. package/dist/cli/calls/index.d.ts +177 -0
  47. package/dist/cli/calls/index.js +96 -0
  48. package/dist/cli/compile/index.js +3 -0
  49. package/dist/cli/config.d.ts +10 -0
  50. package/dist/cli/config.js +52 -0
  51. package/dist/cli/debug/index.d.ts +31 -0
  52. package/dist/cli/debug/index.js +119 -0
  53. package/dist/cli/exec/index.d.ts +39 -0
  54. package/dist/cli/exec/index.js +138 -0
  55. package/dist/cli/exec/session.d.ts +48 -0
  56. package/dist/cli/exec/session.js +82 -0
  57. package/dist/cli/exec/trace.d.ts +18 -0
  58. package/dist/cli/exec/trace.js +52 -0
  59. package/dist/cli/index.js +112 -9
  60. package/dist/cli/logs/index.d.ts +47 -0
  61. package/dist/cli/logs/index.js +113 -0
  62. package/dist/cli/mobile/index.d.ts +12 -0
  63. package/dist/cli/mobile/index.js +405 -0
  64. package/dist/cli/serve/index.d.ts +109 -3
  65. package/dist/cli/serve/index.js +506 -118
  66. package/dist/cli/turns/index.d.ts +105 -0
  67. package/dist/cli/turns/index.js +128 -0
  68. package/dist/cli/turns/run.d.ts +13 -0
  69. package/dist/cli/turns/run.js +57 -0
  70. package/dist/cli/turns/shadow.d.ts +112 -0
  71. package/dist/cli/turns/shadow.js +54 -0
  72. package/dist/cli/type-gen/index.js +9 -9
  73. package/dist/compiler.d.ts +7 -0
  74. package/dist/compiler.js +7 -0
  75. package/dist/compute-host/compute-host.d.ts +14 -23
  76. package/dist/compute-host/compute-host.js +18 -30
  77. package/dist/compute-host/index.d.ts +2 -4
  78. package/dist/compute-host/index.js +1 -2
  79. package/dist/compute-host/source-compute-host.d.ts +10 -10
  80. package/dist/compute-host/source-compute-host.js +33 -40
  81. package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
  82. package/dist/core/case-orchestrator/contact-hours.js +127 -0
  83. package/dist/core/case-orchestrator/index.d.ts +3 -0
  84. package/dist/core/case-orchestrator/index.js +3 -0
  85. package/dist/core/case-orchestrator/render.d.ts +75 -0
  86. package/dist/core/case-orchestrator/render.js +244 -0
  87. package/dist/core/case-orchestrator/time.d.ts +11 -0
  88. package/dist/core/case-orchestrator/time.js +29 -0
  89. package/dist/core/case-orchestrator/types.d.ts +708 -0
  90. package/dist/core/case-orchestrator/types.js +42 -0
  91. package/dist/core/context/call.d.ts +291 -0
  92. package/dist/core/context/call.js +94 -0
  93. package/dist/core/context/channels.d.ts +60 -0
  94. package/dist/core/context/channels.js +35 -0
  95. package/dist/core/context/contact.d.ts +96 -6
  96. package/dist/core/context/contact.js +48 -2
  97. package/dist/core/context/email-message.d.ts +198 -0
  98. package/dist/core/context/email-message.js +86 -0
  99. package/dist/core/context/email.d.ts +109 -0
  100. package/dist/core/context/email.js +90 -0
  101. package/dist/core/context/exchanges.d.ts +167 -0
  102. package/dist/core/context/exchanges.js +81 -0
  103. package/dist/core/context/instances.d.ts +307 -0
  104. package/dist/core/context/instances.js +137 -0
  105. package/dist/core/context/kv.d.ts +113 -0
  106. package/dist/core/context/kv.js +60 -0
  107. package/dist/core/context/platform-registry.d.ts +544 -4
  108. package/dist/core/context/platform-registry.js +14 -2
  109. package/dist/core/context/platform.d.ts +2 -1
  110. package/dist/core/context/sms.d.ts +177 -0
  111. package/dist/core/context/sms.js +77 -0
  112. package/dist/core/context/types.d.ts +79 -48
  113. package/dist/core/context/types.js +1 -7
  114. package/dist/core/conversation/index.d.ts +85 -0
  115. package/dist/core/conversation/index.js +133 -0
  116. package/dist/core/functions/errors.d.ts +74 -0
  117. package/dist/core/functions/errors.js +26 -0
  118. package/dist/core/functions/events.d.ts +192 -0
  119. package/dist/core/functions/events.js +23 -0
  120. package/dist/core/functions/schedules.d.ts +50 -0
  121. package/dist/core/functions/schedules.js +20 -0
  122. package/dist/core/functions/types.d.ts +29 -73
  123. package/dist/core/functions/types.js +1 -4
  124. package/dist/core/office-hours/index.d.ts +39 -0
  125. package/dist/core/office-hours/index.js +187 -0
  126. package/dist/core/page/define.d.ts +904 -0
  127. package/dist/core/page/define.js +518 -0
  128. package/dist/core/page/envelope.d.ts +55 -0
  129. package/dist/core/page/envelope.js +4 -0
  130. package/dist/core/page/fns.d.ts +448 -0
  131. package/dist/core/page/fns.js +539 -0
  132. package/dist/core/page/memory-reader.d.ts +27 -0
  133. package/dist/core/page/memory-reader.js +299 -0
  134. package/dist/core/page/ops.d.ts +58 -0
  135. package/dist/core/page/ops.js +220 -0
  136. package/dist/core/page/page-host.d.ts +20 -0
  137. package/dist/core/page/page-host.js +57 -0
  138. package/dist/core/page/records-query.d.ts +234 -0
  139. package/dist/core/page/records-query.js +780 -0
  140. package/dist/core/page/render.d.ts +295 -0
  141. package/dist/core/page/render.js +1060 -0
  142. package/dist/core/page/sandbox.d.ts +85 -0
  143. package/dist/core/page/sandbox.js +357 -0
  144. package/dist/core/page/time-format.d.ts +46 -0
  145. package/dist/core/page/time-format.js +125 -0
  146. package/dist/core/page/timeline.d.ts +40 -0
  147. package/dist/core/page/timeline.js +2 -0
  148. package/dist/core/page/typed.d.ts +648 -0
  149. package/dist/core/page/typed.js +2 -0
  150. package/dist/core/page/workspace.d.ts +57 -0
  151. package/dist/core/page/workspace.js +266 -0
  152. package/dist/core/party/index.d.ts +3 -0
  153. package/dist/core/party/index.js +3 -0
  154. package/dist/core/party/schema.d.ts +208 -0
  155. package/dist/core/party/schema.js +113 -0
  156. package/dist/core/party/types.d.ts +35 -0
  157. package/dist/core/party/types.js +15 -0
  158. package/dist/core/sequence/define.d.ts +56 -0
  159. package/dist/core/sequence/define.js +10 -0
  160. package/dist/core/sequence/index.d.ts +63 -0
  161. package/dist/core/sequence/index.js +231 -0
  162. package/dist/core/slot/binding.d.ts +40 -0
  163. package/dist/core/slot/binding.js +2 -0
  164. package/dist/core/slot/company-metadata.d.ts +102 -0
  165. package/dist/core/slot/company-metadata.js +536 -0
  166. package/dist/core/slot/compile-schema.d.ts +19 -13
  167. package/dist/core/slot/compile-schema.js +51 -248
  168. package/dist/core/slot/contact-timezone.d.ts +110 -0
  169. package/dist/core/slot/contact-timezone.js +186 -0
  170. package/dist/core/slot/field.d.ts +2 -25
  171. package/dist/core/slot/field.js +0 -71
  172. package/dist/core/slot/id-ref.d.ts +17 -2
  173. package/dist/core/slot/id-ref.js +16 -8
  174. package/dist/core/slot/index.d.ts +12 -13
  175. package/dist/core/slot/index.js +11 -12
  176. package/dist/core/slot/naming.d.ts +15 -0
  177. package/dist/core/slot/naming.js +96 -0
  178. package/dist/core/slot/platform-fields.d.ts +119 -0
  179. package/dist/core/slot/platform-fields.js +121 -0
  180. package/dist/core/slot/ref.d.ts +16 -0
  181. package/dist/core/slot/ref.js +14 -0
  182. package/dist/core/slot/row.d.ts +2 -9
  183. package/dist/core/slot/row.js +13 -23
  184. package/dist/core/slot/schema-compat.d.ts +17 -0
  185. package/dist/core/slot/schema-compat.js +103 -0
  186. package/dist/core/slot/schema.d.ts +353 -76
  187. package/dist/core/slot/schema.js +163 -10
  188. package/dist/core/slot/types.d.ts +30 -103
  189. package/dist/core/slot/value.d.ts +28 -3
  190. package/dist/core/slot/value.js +93 -57
  191. package/dist/dev-overlay/protocol.d.ts +74 -8
  192. package/dist/fn-context/build-context.d.ts +3 -1
  193. package/dist/fn-context/build-context.js +26 -10
  194. package/dist/fn-context/fake/empty-api.js +9 -28
  195. package/dist/fn-context/fake/index.d.ts +13 -4
  196. package/dist/fn-context/fake/index.js +29 -2
  197. package/dist/fn-context/fn-params.d.ts +3 -0
  198. package/dist/fn-context/fn-params.js +10 -0
  199. package/dist/fn-context/index.d.ts +5 -5
  200. package/dist/fn-context/index.js +4 -4
  201. package/dist/fn-context/log.js +2 -2
  202. package/dist/fn-context/make-ctx.d.ts +11 -0
  203. package/dist/fn-context/make-ctx.js +20 -9
  204. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
  205. package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
  206. package/dist/fn-context/rpc/errors.d.ts +13 -0
  207. package/dist/fn-context/rpc/errors.js +22 -0
  208. package/dist/fn-context/rpc/index.d.ts +4 -2
  209. package/dist/fn-context/rpc/index.js +4 -2
  210. package/dist/fn-context/rpc/integration/index.d.ts +15 -5
  211. package/dist/fn-context/rpc/integration/index.js +1 -1
  212. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  213. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  214. package/dist/fn-context/rpc/log.d.ts +11 -1
  215. package/dist/fn-context/rpc/platform.d.ts +13 -3
  216. package/dist/fn-context/rpc/platform.js +1 -1
  217. package/dist/fn-context/rpc/records.d.ts +85 -0
  218. package/dist/fn-context/rpc/records.js +24 -0
  219. package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
  220. package/dist/fn-context/rpc/trpc-client.js +222 -12
  221. package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
  222. package/dist/fn-context/rpc/trpc-init.js +10 -4
  223. package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
  224. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  225. package/dist/fn-context/run-scope.d.ts +4 -0
  226. package/dist/fn-context/run-scope.js +9 -0
  227. package/dist/fn-context/types.d.ts +52 -5
  228. package/dist/index.d.ts +36 -46
  229. package/dist/index.js +30 -33
  230. package/dist/logger.d.ts +11 -0
  231. package/dist/logger.js +49 -0
  232. package/dist/platform.d.ts +75 -0
  233. package/dist/platform.js +57 -0
  234. package/dist/testing-compile-child.d.ts +2 -0
  235. package/dist/testing-compile-child.js +20 -0
  236. package/dist/testing.d.ts +368 -0
  237. package/dist/testing.js +439 -0
  238. package/dist/voice-service/actions.d.ts +50 -6
  239. package/dist/voice-service/index.d.ts +2 -0
  240. package/dist/voice-service/index.js +2 -0
  241. package/dist/voice-service/protocol.d.ts +604 -0
  242. package/dist/voice-service/protocol.js +67 -0
  243. package/dist/voice-service/types.d.ts +55 -8
  244. package/dist/worker.d.ts +11 -0
  245. package/dist/worker.js +11 -0
  246. package/package.json +38 -15
  247. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  248. package/dist/builder/compile/compile-agenda.js +0 -64
  249. package/dist/builder/merge.d.ts +0 -4
  250. package/dist/builder/merge.js +0 -19
  251. package/dist/compute-host/read-only-cache.d.ts +0 -20
  252. package/dist/compute-host/read-only-cache.js +0 -61
  253. package/dist/core/context/db.d.ts +0 -69
  254. package/dist/core/context/db.js +0 -44
  255. package/dist/core/context/docusign.d.ts +0 -134
  256. package/dist/core/context/docusign.js +0 -108
  257. package/dist/core/context/filevine.d.ts +0 -323
  258. package/dist/core/context/filevine.js +0 -254
  259. package/dist/core/context/http.d.ts +0 -9
  260. package/dist/core/context/http.js +0 -4
  261. package/dist/core/context/hubspot.d.ts +0 -250
  262. package/dist/core/context/hubspot.js +0 -191
  263. package/dist/core/context/twilio.d.ts +0 -50
  264. package/dist/core/context/twilio.js +0 -42
  265. package/dist/core/functions/define/case-context.d.ts +0 -14
  266. package/dist/core/functions/define/case-context.js +0 -15
  267. package/dist/core/functions/define/compute.d.ts +0 -7
  268. package/dist/core/functions/define/compute.js +0 -17
  269. package/dist/core/functions/define/custom.d.ts +0 -4
  270. package/dist/core/functions/define/custom.js +0 -8
  271. package/dist/core/functions/define/system.d.ts +0 -7
  272. package/dist/core/functions/define/system.js +0 -12
  273. package/dist/core/functions/func-ref.d.ts +0 -16
  274. package/dist/core/functions/func-ref.js +0 -20
  275. package/dist/core/slot/deps.d.ts +0 -15
  276. package/dist/core/slot/deps.js +0 -88
  277. package/dist/core/slot/derived.d.ts +0 -32
  278. package/dist/core/slot/derived.js +0 -115
  279. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  280. package/dist/core/slot/platform-session-fields.js +0 -48
  281. package/dist/core/slot/sf-schema.d.ts +0 -23
  282. package/dist/core/slot/sf-schema.js +0 -125
  283. package/dist/core/slot/sf-validate.d.ts +0 -14
  284. package/dist/core/slot/sf-validate.js +0 -132
  285. package/dist/core/slot/snapshot.d.ts +0 -18
  286. package/dist/core/slot/snapshot.js +0 -138
  287. package/dist/core/slot/write.d.ts +0 -48
  288. package/dist/core/slot/write.js +0 -426
  289. package/dist/core/stage/builders.d.ts +0 -54
  290. package/dist/core/stage/builders.js +0 -31
  291. package/dist/core/stage/condition.d.ts +0 -17
  292. package/dist/core/stage/condition.js +0 -198
  293. package/dist/core/stage/drive.d.ts +0 -43
  294. package/dist/core/stage/drive.js +0 -78
  295. package/dist/core/stage/finish-when.d.ts +0 -20
  296. package/dist/core/stage/finish-when.js +0 -82
  297. package/dist/core/stage/flatten.d.ts +0 -27
  298. package/dist/core/stage/flatten.js +0 -466
  299. package/dist/core/stage/index.d.ts +0 -15
  300. package/dist/core/stage/index.js +0 -13
  301. package/dist/core/stage/interrupts.d.ts +0 -28
  302. package/dist/core/stage/interrupts.js +0 -120
  303. package/dist/core/stage/ivr-fields.d.ts +0 -9
  304. package/dist/core/stage/ivr-fields.js +0 -75
  305. package/dist/core/stage/simulate.d.ts +0 -24
  306. package/dist/core/stage/simulate.js +0 -33
  307. package/dist/core/stage/transfer-fields.d.ts +0 -19
  308. package/dist/core/stage/transfer-fields.js +0 -129
  309. package/dist/core/stage/transfer-spec.d.ts +0 -48
  310. package/dist/core/stage/transfer-spec.js +0 -113
  311. package/dist/core/stage/types.d.ts +0 -208
  312. package/dist/core/stage/types.js +0 -2
  313. package/dist/core/stage/validate.d.ts +0 -11
  314. package/dist/core/stage/validate.js +0 -330
  315. package/dist/core/stage/walk.d.ts +0 -39
  316. package/dist/core/stage/walk.js +0 -119
  317. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  318. package/dist/fn-context/system-args.d.ts +0 -6
  319. package/dist/fn-context/system-args.js +0 -14
@@ -1,75 +0,0 @@
1
- import { idField } from '../slot/schema.js';
2
- import { isResolved } from '../slot/field.js';
3
- import { getSingleField } from '../slot/snapshot.js';
4
- import { getCompiledTable } from '../slot/compile-schema.js';
5
- import { formatFieldPath } from '../slot/path.js';
6
- import { transferFieldKey } from './transfer-fields.js';
7
- const RESULT_ENUM = ['collected', 'failed'];
8
- function ivrFieldCore(label) {
9
- return {
10
- derived: false,
11
- label,
12
- dataType: 'string',
13
- source: 'system',
14
- extraction: 'Platform IVR result',
15
- enum: [...RESULT_ENUM],
16
- nullable: true,
17
- identifier: null,
18
- ref: null,
19
- };
20
- }
21
- export function ivrResultField(nodeId) {
22
- return formatFieldPath('session', `ivr_${transferFieldKey(nodeId)}_result`);
23
- }
24
- export function ivrAttempted(item, snapshot) {
25
- return isResolved(getSingleField(snapshot, item.resultField));
26
- }
27
- export function collectIvrBlocks(blocks, nodes = []) {
28
- const out = [];
29
- const seen = new Set();
30
- for (const block of Object.values(blocks)) {
31
- if (block.kind === 'ivr' && !seen.has(block.id)) {
32
- seen.add(block.id);
33
- out.push(block);
34
- }
35
- }
36
- visit(nodes);
37
- return out;
38
- function visit(list) {
39
- for (const node of list) {
40
- if (node.kind === 'ivr' && !seen.has(node.id)) {
41
- seen.add(node.id);
42
- out.push(node);
43
- }
44
- else if (node.kind === 'section' || node.kind === 'branch') {
45
- visit(node.children);
46
- }
47
- else if (node.kind === 'switchOn') {
48
- for (const children of Object.values(node.cases))
49
- visit(children);
50
- if (node.otherwise)
51
- visit(node.otherwise);
52
- }
53
- }
54
- }
55
- }
56
- export function registerIvrSessionFields(schema, ivrIds) {
57
- const ids = [...new Set(ivrIds)];
58
- if (ids.length === 0)
59
- return schema;
60
- const session = getCompiledTable(schema, 'session');
61
- if (!session)
62
- return schema;
63
- const fields = { ...session.fields };
64
- if (!fields.id)
65
- fields.id = { ...idField, ref: null };
66
- for (const id of ids) {
67
- const name = `ivr_${transferFieldKey(id)}_result`;
68
- if (!fields[name]) {
69
- fields[name] = ivrFieldCore(`IVR ${id} result`);
70
- }
71
- }
72
- const nextSession = { ...session, fields };
73
- return { ...schema, session: nextSession };
74
- }
75
- //# sourceMappingURL=ivr-fields.js.map
@@ -1,24 +0,0 @@
1
- import type { ComputeHost } from '../../compute-host/compute-host.js';
2
- import type { RuntimeSlotsSnapshot } from '../slot/types.js';
3
- import { type WalkResult } from './walk.js';
4
- import type { FlatAgendaItem } from './types.js';
5
- export type SimulatedItemStatus = 'folded' | 'done' | 'selected' | 'open';
6
- export type SimulatedItem = {
7
- placementId: string;
8
- blockId: string;
9
- kind: FlatAgendaItem['kind'];
10
- groupPath: string[];
11
- status: SimulatedItemStatus;
12
- applyWhen: boolean;
13
- finishWhen: boolean | null;
14
- };
15
- export type SimulateResult = {
16
- selected: FlatAgendaItem | null;
17
- walk: WalkResult;
18
- items: SimulatedItem[];
19
- };
20
- export declare function simulateAgenda(items: FlatAgendaItem[], snapshot: RuntimeSlotsSnapshot, options?: {
21
- currentPlacementId?: string | null;
22
- compute?: ComputeHost;
23
- }): Promise<SimulateResult>;
24
- //# sourceMappingURL=simulate.d.ts.map
@@ -1,33 +0,0 @@
1
- import { evaluateWhen } from './finish-when.js';
2
- import { walkAgenda } from './walk.js';
3
- export async function simulateAgenda(items, snapshot, options = {}) {
4
- const walk = await walkAgenda(items, snapshot, {
5
- currentPlacementId: options.currentPlacementId,
6
- compute: options.compute,
7
- });
8
- const simulated = [];
9
- for (const item of items) {
10
- const applies = (await evaluateWhen(item.applyWhen, snapshot, options.compute)).pass;
11
- const finished = applies ? (await evaluateWhen(item.finishWhen, snapshot, options.compute)).done : null;
12
- let status;
13
- if (!applies)
14
- status = 'folded';
15
- else if (finished)
16
- status = 'done';
17
- else if (walk.hit?.placementId === item.placementId)
18
- status = 'selected';
19
- else
20
- status = 'open';
21
- simulated.push({
22
- placementId: item.placementId,
23
- blockId: item.id,
24
- kind: item.kind,
25
- groupPath: item.groupPath,
26
- status,
27
- applyWhen: applies,
28
- finishWhen: finished,
29
- });
30
- }
31
- return { selected: walk.hit, walk, items: simulated };
32
- }
33
- //# sourceMappingURL=simulate.js.map
@@ -1,19 +0,0 @@
1
- import type { FieldPath } from '../slot/path.js';
2
- import type { CompiledSlotSchema } from '../slot/types.js';
3
- import type { AgendaBlock, AuthoringNode, TransferBlock } from './types.js';
4
- /** Sanitize a transfer node id into a session field fragment. */
5
- export declare function transferFieldKey(nodeId: string): string;
6
- export declare function transferResultField(nodeId: string): FieldPath;
7
- export declare const LAST_TRANSFER_RESULT_FIELD: `${string}.${string}`;
8
- export declare const CASE_TRANSFER_ATTEMPT_COUNT: `${string}.${string}`;
9
- export declare const CASE_LAST_TRANSFER_RESULT: `${string}.${string}`;
10
- export declare const CASE_LAST_TRANSFER_AT: `${string}.${string}`;
11
- export declare function collectTransferBlocks(blocks: Record<string, AgendaBlock>, nodes?: AuthoringNode[]): TransferBlock[];
12
- /**
13
- * Register per-node `session.transfer_<id>_result` and `session.last_transfer_result`.
14
- * Existing session fields with the same name are left untouched.
15
- */
16
- export declare function registerTransferSessionFields(schema: CompiledSlotSchema, transferIds: Iterable<string>, options?: {
17
- lastResult?: boolean;
18
- }): CompiledSlotSchema;
19
- //# sourceMappingURL=transfer-fields.d.ts.map
@@ -1,129 +0,0 @@
1
- import { idField } from '../slot/schema.js';
2
- import { getCompiledTable } from '../slot/compile-schema.js';
3
- import { formatFieldPath } from '../slot/path.js';
4
- const RESULT_ENUM = ['connected', 'failed'];
5
- function transferFieldCore(label) {
6
- return {
7
- derived: false,
8
- label,
9
- dataType: 'string',
10
- source: 'system',
11
- extraction: 'Platform transfer result',
12
- enum: [...RESULT_ENUM],
13
- nullable: true,
14
- identifier: null,
15
- ref: null,
16
- };
17
- }
18
- /** Sanitize a transfer node id into a session field fragment. */
19
- export function transferFieldKey(nodeId) {
20
- const cleaned = nodeId.replace(/[^A-Za-z0-9_]/g, '_');
21
- return cleaned.length > 0 ? cleaned : 'node';
22
- }
23
- export function transferResultField(nodeId) {
24
- return formatFieldPath('session', `transfer_${transferFieldKey(nodeId)}_result`);
25
- }
26
- export const LAST_TRANSFER_RESULT_FIELD = formatFieldPath('session', 'last_transfer_result');
27
- export const CASE_TRANSFER_ATTEMPT_COUNT = formatFieldPath('case_file', 'transfer_attempt_count');
28
- export const CASE_LAST_TRANSFER_RESULT = formatFieldPath('case_file', 'last_transfer_result');
29
- export const CASE_LAST_TRANSFER_AT = formatFieldPath('case_file', 'last_transfer_at');
30
- export function collectTransferBlocks(blocks, nodes = []) {
31
- const out = [];
32
- const seen = new Set();
33
- for (const block of Object.values(blocks)) {
34
- if (block.kind === 'transfer' && !seen.has(block.id)) {
35
- seen.add(block.id);
36
- out.push(block);
37
- }
38
- }
39
- visit(nodes);
40
- return out;
41
- function visit(list) {
42
- for (const node of list) {
43
- if (node.kind === 'transfer' && !seen.has(node.id)) {
44
- seen.add(node.id);
45
- out.push(node);
46
- }
47
- else if (node.kind === 'section' || node.kind === 'branch') {
48
- visit(node.children);
49
- }
50
- else if (node.kind === 'switchOn') {
51
- for (const children of Object.values(node.cases))
52
- visit(children);
53
- if (node.otherwise)
54
- visit(node.otherwise);
55
- }
56
- }
57
- }
58
- }
59
- /**
60
- * Register per-node `session.transfer_<id>_result` and `session.last_transfer_result`.
61
- * Existing session fields with the same name are left untouched.
62
- */
63
- export function registerTransferSessionFields(schema, transferIds, options) {
64
- const ids = [...new Set(transferIds)];
65
- if (ids.length === 0 && !options?.lastResult)
66
- return schema;
67
- const session = getCompiledTable(schema, 'session');
68
- if (!session)
69
- return schema;
70
- const fields = { ...session.fields };
71
- if (!fields.id)
72
- fields.id = { ...idField, ref: null };
73
- for (const id of ids) {
74
- const name = `transfer_${transferFieldKey(id)}_result`;
75
- if (!fields[name]) {
76
- fields[name] = transferFieldCore(`Transfer ${id} result`);
77
- }
78
- }
79
- if ((ids.length > 0 || options?.lastResult) && !fields.last_transfer_result) {
80
- fields.last_transfer_result = transferFieldCore('Last transfer result');
81
- }
82
- const nextSession = {
83
- ...session,
84
- fields,
85
- };
86
- const caseFile = getCompiledTable(schema, 'case_file');
87
- let nextCase = caseFile;
88
- if (caseFile && (ids.length > 0 || options?.lastResult)) {
89
- const caseFields = { ...caseFile.fields };
90
- if (!caseFields.id)
91
- caseFields.id = { ...idField, ref: null };
92
- if (!caseFields.transfer_attempt_count) {
93
- caseFields.transfer_attempt_count = {
94
- derived: false,
95
- label: 'Transfer attempt count',
96
- dataType: 'number',
97
- source: 'system',
98
- extraction: 'Platform transfer attempt count',
99
- enum: null,
100
- nullable: true,
101
- identifier: null,
102
- ref: null,
103
- };
104
- }
105
- if (!caseFields.last_transfer_result) {
106
- caseFields.last_transfer_result = transferFieldCore('Case last transfer result');
107
- }
108
- if (!caseFields.last_transfer_at) {
109
- caseFields.last_transfer_at = {
110
- derived: false,
111
- label: 'Last transfer at',
112
- dataType: 'datetime',
113
- source: 'system',
114
- extraction: 'Platform last transfer time',
115
- enum: null,
116
- nullable: true,
117
- identifier: null,
118
- ref: null,
119
- };
120
- }
121
- nextCase = { ...caseFile, fields: caseFields };
122
- }
123
- return {
124
- ...schema,
125
- session: nextSession,
126
- ...(nextCase ? { case_file: nextCase } : {}),
127
- };
128
- }
129
- //# sourceMappingURL=transfer-fields.js.map
@@ -1,48 +0,0 @@
1
- import type { FieldPath } from '../slot/path.js';
2
- import type { RuntimeSlotsSnapshot, ValidationIssue } from '../slot/types.js';
3
- export type TransferMode = 'cold' | 'warm' | 'async-warm';
4
- export type TransferCallerIdShown = 'client' | 'service';
5
- export type TransferConfirmMethod = 'keypad' | 'llm';
6
- export type TransferConfirmKey = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '*' | '#';
7
- export type TransferSay = string | Record<string, string>;
8
- export type TransferFallbackAction = 'end-call' | 'restore-normal-call-state';
9
- /** mars-voice-service `TransferCallArgs`. String fields may contain `{{table.field}}`. */
10
- export type TransferArguments = {
11
- sendDigits?: string;
12
- sipUrl?: string;
13
- sipUsername?: string;
14
- sipPassword?: string;
15
- transferCallerIdShown?: TransferCallerIdShown;
16
- };
17
- /** Shared dial config for agenda transfer nodes and interrupt transfer actions. */
18
- export type TransferDial = {
19
- numbers: string[];
20
- mode: TransferMode;
21
- say?: TransferSay | null;
22
- unsuccessfulSay?: TransferSay | null;
23
- fallbackAction?: TransferFallbackAction | null;
24
- arguments?: TransferArguments | null;
25
- warmConfirmMode?: TransferConfirmMethod[] | null;
26
- warmConfirmKeypad?: TransferConfirmKey | null;
27
- warmConfirmTimeoutMs?: number | null;
28
- warmLoopSay?: string | null;
29
- warmBriefingPrompt?: string | null;
30
- asyncWarmBridge?: {
31
- targetSayTemplate?: string;
32
- customerSayTemplate?: string;
33
- } | null;
34
- };
35
- export declare const E164_NUMBER: RegExp;
36
- export declare const SIP_URI: RegExp;
37
- export declare function isTransferDestinationLiteral(value: string): boolean;
38
- export declare function interpolateTemplate(text: string, read: (path: FieldPath) => string | number | boolean | null | undefined): string;
39
- export declare function interpolateFromSnapshot(text: string, snapshot: RuntimeSlotsSnapshot): string;
40
- export declare function resolveTransferDestinations(numbers: string[], snapshot: RuntimeSlotsSnapshot): string[];
41
- export declare function resolveTransferSay(say: TransferSay | null | undefined, language: string | null | undefined, fallback: string): string;
42
- export declare function resolveTransferArguments(dial: TransferDial, snapshot: RuntimeSlotsSnapshot): TransferArguments;
43
- export declare function transferArgumentsJson(dial: TransferDial, snapshot: RuntimeSlotsSnapshot): string;
44
- export declare function validateTransferDestinations(numbers: string[], options: {
45
- path: string;
46
- code: string;
47
- }): ValidationIssue[];
48
- //# sourceMappingURL=transfer-spec.d.ts.map
@@ -1,113 +0,0 @@
1
- import { parseFieldPath } from '../slot/path.js';
2
- import { getRowField } from '../slot/row.js';
3
- import { getSnapshotTable } from '../slot/snapshot.js';
4
- import { extractTemplateFields } from './condition.js';
5
- export const E164_NUMBER = /^\+[1-9]\d{7,14}$/;
6
- export const SIP_URI = /^sips?:[^@\s]+@[^@\s]+$/i;
7
- const TEMPLATE_RE = /\{\{\s*([A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g;
8
- export function isTransferDestinationLiteral(value) {
9
- return E164_NUMBER.test(value) || SIP_URI.test(value);
10
- }
11
- export function interpolateTemplate(text, read) {
12
- return text.replace(TEMPLATE_RE, (_all, path) => {
13
- const value = read(path);
14
- return value == null ? '' : String(value);
15
- });
16
- }
17
- function boundRowId(tableName, current) {
18
- if (!current)
19
- return undefined;
20
- if (tableName === 'contact')
21
- return current.contactId;
22
- if (tableName === 'case_contact')
23
- return current.caseContactId;
24
- if (tableName === 'case_file')
25
- return current.caseFileId;
26
- return undefined;
27
- }
28
- export function interpolateFromSnapshot(text, snapshot) {
29
- return interpolateTemplate(text, (path) => {
30
- const parsed = parseFieldPath(path);
31
- if (!parsed)
32
- return '';
33
- const data = getSnapshotTable(snapshot, parsed.table);
34
- if (!data)
35
- return '';
36
- if (!Array.isArray(data))
37
- return getRowField(data, parsed.field)?.value ?? '';
38
- const id = boundRowId(parsed.table, snapshot.current);
39
- if (!id)
40
- return '';
41
- const row = data.find((entry) => entry.id === id);
42
- return row ? (getRowField(row, parsed.field)?.value ?? '') : '';
43
- });
44
- }
45
- export function resolveTransferDestinations(numbers, snapshot) {
46
- const out = [];
47
- for (const raw of numbers) {
48
- const resolved = interpolateFromSnapshot(raw, snapshot).trim();
49
- if (resolved)
50
- out.push(resolved);
51
- }
52
- return out;
53
- }
54
- export function resolveTransferSay(say, language, fallback) {
55
- if (say == null)
56
- return fallback;
57
- if (typeof say === 'string')
58
- return say.trim() || fallback;
59
- const key = language?.trim().toLowerCase() || 'english';
60
- const picked = say[key] ?? say.english ?? Object.values(say).find((value) => value.trim().length > 0);
61
- return picked?.trim() || fallback;
62
- }
63
- function interpolatedArg(value, snapshot) {
64
- return value ? interpolateFromSnapshot(value, snapshot).trim() : '';
65
- }
66
- export function resolveTransferArguments(dial, snapshot) {
67
- const src = dial.arguments;
68
- if (!src)
69
- return {};
70
- const out = {};
71
- const sendDigits = interpolatedArg(src.sendDigits, snapshot);
72
- if (sendDigits)
73
- out.sendDigits = sendDigits;
74
- const sipUrl = interpolatedArg(src.sipUrl, snapshot);
75
- if (sipUrl)
76
- out.sipUrl = sipUrl;
77
- const sipUsername = interpolatedArg(src.sipUsername, snapshot);
78
- if (sipUsername)
79
- out.sipUsername = sipUsername;
80
- const sipPassword = interpolatedArg(src.sipPassword, snapshot);
81
- if (sipPassword)
82
- out.sipPassword = sipPassword;
83
- if (src.transferCallerIdShown)
84
- out.transferCallerIdShown = src.transferCallerIdShown;
85
- return out;
86
- }
87
- export function transferArgumentsJson(dial, snapshot) {
88
- return JSON.stringify(resolveTransferArguments(dial, snapshot));
89
- }
90
- export function validateTransferDestinations(numbers, options) {
91
- const issues = [];
92
- if (numbers.length === 0) {
93
- issues.push({
94
- code: options.code,
95
- message: 'transfer numbers must not be empty',
96
- path: options.path,
97
- });
98
- return issues;
99
- }
100
- for (const number of numbers) {
101
- if (extractTemplateFields(number).length > 0)
102
- continue;
103
- if (!isTransferDestinationLiteral(number)) {
104
- issues.push({
105
- code: options.code,
106
- message: `Transfer target must be E.164 or sip/sips URI: ${number}`,
107
- path: options.path,
108
- });
109
- }
110
- }
111
- return issues;
112
- }
113
- //# sourceMappingURL=transfer-spec.js.map
@@ -1,208 +0,0 @@
1
- import type { TopLevelCondition } from 'json-rules-engine';
2
- import type { FuncRef } from '../functions/func-ref.js';
3
- import type { FieldPath } from '../slot/path.js';
4
- import type { TransferDial, TransferFallbackAction } from './transfer-spec.js';
5
- export type Channel = 'call' | 'sms' | 'email' | 'webchat';
6
- /** Nested condition from the engine (`all` members): leaf or `TopLevelCondition`. */
7
- export type Condition = Extract<TopLevelCondition, {
8
- all: unknown;
9
- }>['all'][number];
10
- export type JsonRulesCondition = Condition;
11
- /**
12
- * Shared by applyWhen and finishWhen:
13
- * json-rules object, JSON string, boolFunction, or null (always).
14
- */
15
- export type When = FuncRef | Condition | Condition[] | null;
16
- export type ApplyWhen = When;
17
- export type FinishWhen = When;
18
- /** Compile-time sentinel for branch()/switchOn(); expanded before flatten. */
19
- export type OtherwiseSentinel = {
20
- op: 'otherwise';
21
- notAny?: When[];
22
- };
23
- export type AuthoringWhen = When | OtherwiseSentinel;
24
- export type CompiledWhen = {
25
- kind: 'always';
26
- } | {
27
- kind: 'fn';
28
- fn: string;
29
- } | {
30
- kind: 'rules';
31
- condition: JsonRulesCondition;
32
- };
33
- export type OnNoProgress = {
34
- maxTurns: number;
35
- action: 'move-on' | 'handoff' | 'schedule-callback';
36
- };
37
- export type FirstMessage = {
38
- kind: 'template';
39
- text: string;
40
- } | {
41
- kind: 'fn';
42
- fn: string;
43
- };
44
- export type TransferInterruptAction = {
45
- type: 'transfer';
46
- escalateCriteria?: string[];
47
- noEscalationCriteria?: string[];
48
- } & TransferDial;
49
- export type Interrupt = {
50
- id: string;
51
- label: string;
52
- tool: {
53
- name: string;
54
- description: string;
55
- };
56
- action: TransferInterruptAction | {
57
- type: 'switch-language';
58
- languages: string[];
59
- };
60
- priority: number;
61
- };
62
- export type AgendaHeader = {
63
- channel: Channel;
64
- systemPrompt: string | null;
65
- firstMessage: FirstMessage | null;
66
- firstMessageMode: 'assistant-speaks-first' | 'user-speaks-first' | null;
67
- voicemailPrompt: string | null;
68
- interrupts: Interrupt[];
69
- };
70
- export type TopicBlock = {
71
- kind: 'topic';
72
- id: string;
73
- label: string;
74
- instructions: string;
75
- fields: FieldPath[] | null;
76
- finishWhen: FinishWhen;
77
- onNoProgress: OnNoProgress | null;
78
- };
79
- export type ActionBlock = {
80
- kind: 'action';
81
- id: string;
82
- label: string;
83
- run: FuncRef;
84
- finishWhen: FinishWhen;
85
- say: string | null;
86
- };
87
- export type TransferBlock = {
88
- kind: 'transfer';
89
- id: string;
90
- label: string;
91
- } & TransferDial;
92
- export type IvrDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '*' | '#';
93
- export type IvrFallbackAction = TransferFallbackAction;
94
- export type DtmfResult = {
95
- result: IvrDigit[];
96
- value: string;
97
- };
98
- export type IvrBlock = {
99
- kind: 'ivr';
100
- id: string;
101
- label: string;
102
- onDtmfResult: FuncRef;
103
- finishWhen: FinishWhen;
104
- fallbackAction: IvrFallbackAction;
105
- confirmTimeoutMs: number;
106
- pauseAfterSayMs: number;
107
- loopSay: string;
108
- enterSay: string | null;
109
- succeedSay: string | null;
110
- unsuccessSay: string | null;
111
- finishOnKey?: IvrDigit | null;
112
- minDigits?: number | null;
113
- maxDigits?: number | null;
114
- validateDigits?: IvrDigit[] | null;
115
- };
116
- export type AgendaBlock = TopicBlock | ActionBlock | TransferBlock | IvrBlock;
117
- export type CompiledTopicBlock = Omit<TopicBlock, 'fields' | 'finishWhen'> & {
118
- fields: FieldPath[];
119
- finishWhen: CompiledWhen;
120
- };
121
- export type CompiledActionBlock = Omit<ActionBlock, 'run' | 'finishWhen'> & {
122
- run: string;
123
- finishWhen: CompiledWhen;
124
- };
125
- export type CompiledTransferBlock = TransferBlock & {
126
- finishWhen: CompiledWhen;
127
- resultField: FieldPath;
128
- };
129
- export type CompiledIvrBlock = Omit<IvrBlock, 'onDtmfResult' | 'finishWhen'> & {
130
- onDtmfResult: string;
131
- finishWhen: CompiledWhen;
132
- resultField: FieldPath;
133
- };
134
- export type CompiledAgendaBlock = CompiledTopicBlock | CompiledActionBlock | CompiledTransferBlock | CompiledIvrBlock;
135
- export type SectionPlacement = {
136
- kind: 'section';
137
- placementId: string;
138
- label: string;
139
- applyWhen: AuthoringWhen;
140
- children: Placement[];
141
- };
142
- export type NodePlacement = {
143
- kind: 'node';
144
- placementId: string;
145
- blockId: string;
146
- applyWhen: AuthoringWhen;
147
- };
148
- export type Placement = SectionPlacement | NodePlacement;
149
- export type AgendaConfig = {
150
- id: string;
151
- header: AgendaHeader | null;
152
- placements: Placement[];
153
- };
154
- export type SequenceAgendas = {
155
- blocks: Record<string, AgendaBlock>;
156
- agendas: Record<string, AgendaConfig>;
157
- };
158
- export type FlatNodePlacement = {
159
- placementId: string;
160
- applyWhen: CompiledWhen;
161
- groupPath: string[];
162
- };
163
- export type FlatTopicItem = CompiledTopicBlock & FlatNodePlacement;
164
- export type FlatActionItem = CompiledActionBlock & FlatNodePlacement;
165
- export type FlatTransferItem = CompiledTransferBlock & FlatNodePlacement;
166
- export type FlatIvrItem = CompiledIvrBlock & FlatNodePlacement;
167
- export type FlatAgendaItem = FlatTopicItem | FlatActionItem | FlatTransferItem | FlatIvrItem;
168
- export type CompiledAgenda = {
169
- header: AgendaHeader | null;
170
- flat: FlatAgendaItem[];
171
- };
172
- export type TopicNode = TopicBlock & {
173
- applyWhen: AuthoringWhen;
174
- };
175
- export type ActionNode = ActionBlock & {
176
- applyWhen: AuthoringWhen;
177
- };
178
- export type TransferNode = TransferBlock & {
179
- applyWhen: AuthoringWhen;
180
- };
181
- export type IvrNode = IvrBlock & {
182
- applyWhen: AuthoringWhen;
183
- };
184
- export type SectionNode = {
185
- kind: 'section';
186
- id: string;
187
- label: string;
188
- applyWhen: AuthoringWhen;
189
- children: AuthoringNode[];
190
- };
191
- export type BranchNode = {
192
- kind: 'branch';
193
- children: AuthoringNode[];
194
- };
195
- export type SwitchOnNode = {
196
- kind: 'switchOn';
197
- field: FieldPath;
198
- cases: Record<string, AuthoringNode[]>;
199
- otherwise?: AuthoringNode[];
200
- };
201
- export type AuthoringNode = TopicNode | ActionNode | TransferNode | IvrNode | SectionNode | BranchNode | SwitchOnNode;
202
- export type AgendaTree = {
203
- kind: 'agenda';
204
- id: string;
205
- header: AgendaHeader | null;
206
- tree: AuthoringNode[];
207
- };
208
- //# sourceMappingURL=types.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,11 +0,0 @@
1
- import type { FuncMap } from '../functions/types.js';
2
- import type { CompiledSlotSchema, ValidationIssue, ValidationResult } from '../slot/types.js';
3
- import type { CompiledAgenda } from './types.js';
4
- export type ValidateAgendaOptions = {
5
- schema: CompiledSlotSchema;
6
- functions?: FuncMap;
7
- agendaId?: string;
8
- };
9
- export declare function validateCompiledAgenda(compiled: CompiledAgenda, options: ValidateAgendaOptions): ValidationResult;
10
- export declare function fatalAgendaIssues(issues: ValidationIssue[]): ValidationIssue[];
11
- //# sourceMappingURL=validate.d.ts.map