@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,31 +0,0 @@
1
- export function topic(id, config) {
2
- return { kind: 'topic', id, ...config };
3
- }
4
- export function action(id, config) {
5
- return { kind: 'action', id, ...config };
6
- }
7
- export function transfer(id, config) {
8
- return { kind: 'transfer', id, ...config };
9
- }
10
- export function ivr(id, config) {
11
- return { kind: 'ivr', id, ...config };
12
- }
13
- export function section(id, config, children) {
14
- return { kind: 'section', id, label: config.label, applyWhen: config.applyWhen, children };
15
- }
16
- export function branch(children) {
17
- return { kind: 'branch', children };
18
- }
19
- export function switchOn(field, cases) {
20
- const { otherwise: otherwiseChildren, ...rest } = cases;
21
- return {
22
- kind: 'switchOn',
23
- field,
24
- cases: rest,
25
- ...(otherwiseChildren ? { otherwise: otherwiseChildren } : {}),
26
- };
27
- }
28
- export function agenda(id, header, tree) {
29
- return { kind: 'agenda', id, header, tree };
30
- }
31
- //# sourceMappingURL=builders.js.map
@@ -1,17 +0,0 @@
1
- import type { FieldPath } from '../slot/path.js';
2
- import type { Condition, JsonRulesCondition, OtherwiseSentinel } from './types.js';
3
- export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
4
- export declare function isOtherwise(value: unknown): value is OtherwiseSentinel;
5
- export declare function looksLikeJsonRules(value: string): boolean;
6
- export declare function jsonRules(rules: Condition | Condition[] | string): Condition;
7
- export declare function otherwise(): OtherwiseSentinel;
8
- export declare function parseJsonRules(input: string): JsonRulesCondition;
9
- export declare function normalizeJsonRules(raw: unknown): JsonRulesCondition;
10
- export declare function collectJsonRulesFacts(condition: JsonRulesCondition | null | undefined): FieldPath[];
11
- export type ConditionEval = {
12
- pass: boolean;
13
- failedFields: FieldPath[];
14
- };
15
- export declare function evaluateJsonRules(condition: JsonRulesCondition, caseContext: unknown): Promise<ConditionEval>;
16
- export declare function extractTemplateFields(text: string): FieldPath[];
17
- //# sourceMappingURL=condition.d.ts.map
@@ -1,198 +0,0 @@
1
- import { Engine } from 'json-rules-engine';
2
- import { emptyFieldValue } from '../slot/field.js';
3
- import { parseFieldPath } from '../slot/path.js';
4
- import { getRowField } from '../slot/row.js';
5
- const OPERATORS = new Set([
6
- 'equal',
7
- 'notEqual',
8
- 'in',
9
- 'notIn',
10
- 'contains',
11
- 'doesNotContain',
12
- 'lessThan',
13
- 'lessThanInclusive',
14
- 'greaterThan',
15
- 'greaterThanInclusive',
16
- ]);
17
- const PASS_EVENT = 'pass';
18
- export function isPlainObject(value) {
19
- return value != null && typeof value === 'object' && !Array.isArray(value);
20
- }
21
- export function isOtherwise(value) {
22
- return isPlainObject(value) && value.op === 'otherwise' && !('fact' in value) && !('operator' in value);
23
- }
24
- export function looksLikeJsonRules(value) {
25
- const trimmed = value.trim();
26
- return trimmed.startsWith('{') || trimmed.startsWith('[');
27
- }
28
- export function jsonRules(rules) {
29
- if (typeof rules === 'string')
30
- return parseJsonRules(rules);
31
- if (Array.isArray(rules))
32
- return { all: rules };
33
- return rules;
34
- }
35
- export function otherwise() {
36
- return { op: 'otherwise' };
37
- }
38
- export function parseJsonRules(input) {
39
- let parsed;
40
- try {
41
- parsed = JSON.parse(input);
42
- }
43
- catch {
44
- throw new Error('Invalid json-rules JSON');
45
- }
46
- return normalizeJsonRules(parsed);
47
- }
48
- export function normalizeJsonRules(raw) {
49
- if (Array.isArray(raw)) {
50
- if (raw.length === 0)
51
- throw new Error('json-rules array must not be empty');
52
- return { all: raw.map(normalizeJsonRules) };
53
- }
54
- if (!isPlainObject(raw)) {
55
- throw new Error('Invalid json-rules condition');
56
- }
57
- if ('conditions' in raw) {
58
- return normalizeJsonRules(raw.conditions);
59
- }
60
- if ('all' in raw) {
61
- if (!Array.isArray(raw.all))
62
- throw new Error('json-rules `all` must be an array');
63
- return { all: raw.all.map(normalizeJsonRules) };
64
- }
65
- if ('any' in raw) {
66
- if (!Array.isArray(raw.any))
67
- throw new Error('json-rules `any` must be an array');
68
- return { any: raw.any.map(normalizeJsonRules) };
69
- }
70
- if ('not' in raw) {
71
- return { not: normalizeJsonRules(raw.not) };
72
- }
73
- if (typeof raw.fact !== 'string' || typeof raw.operator !== 'string') {
74
- throw new Error('json-rules leaf requires `fact` and `operator`');
75
- }
76
- if (!OPERATORS.has(raw.operator)) {
77
- throw new Error(`Unknown json-rules-engine operator: ${raw.operator}`);
78
- }
79
- const leaf = {
80
- fact: raw.fact,
81
- operator: raw.operator,
82
- value: 'value' in raw ? raw.value : undefined,
83
- };
84
- if (typeof raw.path === 'string')
85
- leaf.path = raw.path;
86
- return leaf;
87
- }
88
- export function collectJsonRulesFacts(condition) {
89
- if (!condition)
90
- return [];
91
- const out = [];
92
- const seen = new Set();
93
- visit(condition);
94
- return out;
95
- function visit(node) {
96
- if ('all' in node) {
97
- for (const child of node.all)
98
- visit(child);
99
- return;
100
- }
101
- if ('any' in node) {
102
- for (const child of node.any)
103
- visit(child);
104
- return;
105
- }
106
- if ('not' in node) {
107
- visit(node.not);
108
- return;
109
- }
110
- if ('fact' in node && node.fact && !seen.has(node.fact)) {
111
- seen.add(node.fact);
112
- out.push(node.fact);
113
- }
114
- }
115
- }
116
- export async function evaluateJsonRules(condition, caseContext) {
117
- const engine = new Engine([], { allowUndefinedFacts: true });
118
- engine.addRule({
119
- conditions: toEngineConditions(condition),
120
- event: { type: PASS_EVENT },
121
- });
122
- const { events, failureResults } = await engine.run(factsFromCaseContext(condition, caseContext));
123
- const pass = events.some((event) => event.type === PASS_EVENT);
124
- return {
125
- pass,
126
- failedFields: pass ? [] : collectFailedFacts(failureResults[0]?.conditions),
127
- };
128
- }
129
- function toEngineConditions(condition) {
130
- const node = applyDefaultPath(condition);
131
- if ('all' in node || 'any' in node || 'not' in node)
132
- return node;
133
- return { all: [node] };
134
- }
135
- function applyDefaultPath(condition) {
136
- if ('all' in condition)
137
- return { ...condition, all: condition.all.map(applyDefaultPath) };
138
- if ('any' in condition)
139
- return { ...condition, any: condition.any.map(applyDefaultPath) };
140
- if ('not' in condition)
141
- return { ...condition, not: applyDefaultPath(condition.not) };
142
- if ('path' in condition && condition.path)
143
- return condition;
144
- return { ...condition, path: '$.value' };
145
- }
146
- function factsFromCaseContext(condition, caseContext) {
147
- const facts = {};
148
- for (const fact of collectJsonRulesFacts(condition)) {
149
- facts[fact] = getContextField(caseContext, fact) ?? emptyFieldValue();
150
- }
151
- return facts;
152
- }
153
- function getContextField(caseContext, path) {
154
- const parsed = parseFieldPath(path);
155
- if (!parsed || !isPlainObject(caseContext))
156
- return undefined;
157
- const row = caseContext[parsed.table];
158
- if (!row || typeof row !== 'object' || Array.isArray(row))
159
- return undefined;
160
- return getRowField(row, parsed.field);
161
- }
162
- function collectFailedFacts(node) {
163
- const out = [];
164
- const seen = new Set();
165
- visit(node);
166
- return out;
167
- function visit(value) {
168
- if (value == null || typeof value !== 'object')
169
- return;
170
- const rec = value;
171
- if (typeof rec.fact === 'string' && rec.result === false && !seen.has(rec.fact)) {
172
- seen.add(rec.fact);
173
- out.push(rec.fact);
174
- }
175
- if (Array.isArray(rec.all))
176
- for (const child of rec.all)
177
- visit(child);
178
- if (Array.isArray(rec.any))
179
- for (const child of rec.any)
180
- visit(child);
181
- if (rec.not)
182
- visit(rec.not);
183
- }
184
- }
185
- const TEMPLATE_RE = /\{\{\s*([A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g;
186
- export function extractTemplateFields(text) {
187
- const out = [];
188
- const seen = new Set();
189
- for (const match of text.matchAll(TEMPLATE_RE)) {
190
- const path = match[1];
191
- if (!seen.has(path)) {
192
- seen.add(path);
193
- out.push(path);
194
- }
195
- }
196
- return out;
197
- }
198
- //# sourceMappingURL=condition.js.map
@@ -1,43 +0,0 @@
1
- import type { Writes } from '../context/types.js';
2
- import type { ComputeHost } from '../../compute-host/compute-host.js';
3
- import type { FieldPath } from '../slot/path.js';
4
- import type { RuntimeSlotsSnapshot } from '../slot/types.js';
5
- import { type WalkResult } from './walk.js';
6
- import type { FlatActionItem, FlatAgendaItem, FlatTransferItem } from './types.js';
7
- export declare const DEFAULT_MAX_ACTIONS_PER_TURN = 10;
8
- export type StageDriveHooks = {
9
- runAction: (item: FlatActionItem, snapshot: RuntimeSlotsSnapshot) => Promise<Writes | null>;
10
- applyWrites: (writes: Writes, snapshot: RuntimeSlotsSnapshot) => Promise<RuntimeSlotsSnapshot>;
11
- };
12
- export type StageDriveState = {
13
- snapshot: RuntimeSlotsSnapshot;
14
- currentPlacementId: string | null;
15
- };
16
- export type StageDriveResult = {
17
- snapshot: RuntimeSlotsSnapshot;
18
- currentPlacementId: string | null;
19
- walk: WalkResult;
20
- actionsRun: number;
21
- fused: boolean;
22
- };
23
- /**
24
- * Walk until a topic/transfer/ivr/complete, executing actions inline.
25
- * Action returning null is skipped for this tick; writes trigger a full re-walk.
26
- */
27
- export declare function driveAgenda(items: FlatAgendaItem[], state: StageDriveState, compute: ComputeHost, hooks: StageDriveHooks, options?: {
28
- maxActions?: number;
29
- }): Promise<StageDriveResult>;
30
- export type AdvanceResult = {
31
- ok: true;
32
- drive: StageDriveResult;
33
- } | {
34
- ok: false;
35
- missing: FieldPath[];
36
- item: FlatAgendaItem;
37
- };
38
- export declare function advanceAgenda(items: FlatAgendaItem[], state: StageDriveState, compute: ComputeHost, hooks: StageDriveHooks, options?: {
39
- maxActions?: number;
40
- }): Promise<AdvanceResult>;
41
- export declare function watchdogHint(item: FlatAgendaItem | null, snapshot: RuntimeSlotsSnapshot, compute?: ComputeHost): Promise<string | null>;
42
- export declare function transferWrites(item: FlatTransferItem, result: 'connected' | 'failed'): Writes;
43
- //# sourceMappingURL=drive.d.ts.map
@@ -1,78 +0,0 @@
1
- import { normalizeWrites } from '../slot/write.js';
2
- import { evaluateWhen } from './finish-when.js';
3
- import { unresolvedFinishWhenFields, walkAgenda } from './walk.js';
4
- export const DEFAULT_MAX_ACTIONS_PER_TURN = 10;
5
- /**
6
- * Walk until a topic/transfer/ivr/complete, executing actions inline.
7
- * Action returning null is skipped for this tick; writes trigger a full re-walk.
8
- */
9
- export async function driveAgenda(items, state, compute, hooks, options = {}) {
10
- const maxActions = options.maxActions ?? DEFAULT_MAX_ACTIONS_PER_TURN;
11
- let snapshot = state.snapshot;
12
- let currentPlacementId = state.currentPlacementId;
13
- const skip = new Set();
14
- let actionsRun = 0;
15
- let lastWalk;
16
- while (true) {
17
- lastWalk = await walkAgenda(items, snapshot, { currentPlacementId, compute, skipPlacementIds: skip });
18
- const hit = lastWalk.hit;
19
- if (!hit || hit.kind === 'topic' || hit.kind === 'transfer' || hit.kind === 'ivr') {
20
- return {
21
- snapshot,
22
- currentPlacementId: hit?.placementId ?? currentPlacementId,
23
- walk: lastWalk,
24
- actionsRun,
25
- fused: false,
26
- };
27
- }
28
- if (actionsRun >= maxActions) {
29
- return {
30
- snapshot,
31
- currentPlacementId: hit.placementId,
32
- walk: lastWalk,
33
- actionsRun,
34
- fused: true,
35
- };
36
- }
37
- actionsRun += 1;
38
- const writes = await hooks.runAction(hit, snapshot);
39
- if (!writes || !normalizeWrites(writes)) {
40
- skip.add(hit.placementId);
41
- continue;
42
- }
43
- snapshot = await hooks.applyWrites(writes, snapshot);
44
- skip.clear();
45
- currentPlacementId = hit.placementId;
46
- }
47
- }
48
- export async function advanceAgenda(items, state, compute, hooks, options = {}) {
49
- const current = (state.currentPlacementId ? items.find((item) => item.placementId === state.currentPlacementId) : null) ??
50
- (await walkAgenda(items, state.snapshot, { compute })).hit;
51
- if (current?.kind === 'topic') {
52
- const finished = await evaluateWhen(current.finishWhen, state.snapshot, compute);
53
- if (!finished.done) {
54
- return {
55
- ok: false,
56
- missing: await unresolvedFinishWhenFields(current, state.snapshot, compute),
57
- item: current,
58
- };
59
- }
60
- }
61
- const drive = await driveAgenda(items, state, compute, hooks, options);
62
- return { ok: true, drive };
63
- }
64
- export async function watchdogHint(item, snapshot, compute) {
65
- if (!item || item.kind !== 'topic')
66
- return null;
67
- const finished = await evaluateWhen(item.finishWhen, snapshot, compute);
68
- if (!finished.done)
69
- return null;
70
- return 'This section is complete. Wrap up naturally and advance.';
71
- }
72
- export function transferWrites(item, result) {
73
- return {
74
- [item.resultField]: result,
75
- 'session.last_transfer_result': result,
76
- };
77
- }
78
- //# sourceMappingURL=drive.js.map
@@ -1,20 +0,0 @@
1
- import type { FuncMap } from '../functions/types.js';
2
- import type { ComputeHost } from '../../compute-host/compute-host.js';
3
- import type { FieldPath } from '../slot/path.js';
4
- import type { RuntimeSlotsSnapshot } from '../slot/types.js';
5
- import { type ConditionEval } from './condition.js';
6
- import type { AuthoringWhen, CompiledWhen, When } from './types.js';
7
- export declare function compileWhen(raw: When, functions?: FuncMap): CompiledWhen;
8
- export declare function compileAuthoringWhen(raw: AuthoringWhen, functions?: FuncMap): CompiledWhen;
9
- export declare function andCompiledWhen(a: CompiledWhen, b: CompiledWhen): CompiledWhen;
10
- export declare function notAnyWhen(items: CompiledWhen[]): CompiledWhen;
11
- export declare function whenFields(when: CompiledWhen): FieldPath[];
12
- export type WhenEval = ConditionEval & {
13
- done: boolean;
14
- };
15
- export declare function evaluateWhen(when: CompiledWhen, snapshot: RuntimeSlotsSnapshot, compute?: ComputeHost): Promise<WhenEval>;
16
- export declare const compileFinishWhen: typeof compileWhen;
17
- export declare const evaluateFinishWhen: typeof evaluateWhen;
18
- export declare const finishWhenFields: typeof whenFields;
19
- export type FinishWhenEval = WhenEval;
20
- //# sourceMappingURL=finish-when.d.ts.map
@@ -1,82 +0,0 @@
1
- import { resolveFuncName } from '../functions/func-ref.js';
2
- import { collectJsonRulesFacts, evaluateJsonRules, isOtherwise, looksLikeJsonRules, normalizeJsonRules, parseJsonRules, } from './condition.js';
3
- function isDefinedFunc(value) {
4
- return (value != null &&
5
- typeof value === 'object' &&
6
- 'kind' in value &&
7
- 'main' in value &&
8
- (value.kind === 'compute' || value.kind === 'boolCompute' || value.kind === 'custom' || value.kind === 'system'));
9
- }
10
- export function compileWhen(raw, functions) {
11
- if (raw == null)
12
- return { kind: 'always' };
13
- if (typeof raw === 'string') {
14
- if (looksLikeJsonRules(raw)) {
15
- return { kind: 'rules', condition: parseJsonRules(raw) };
16
- }
17
- if (!raw)
18
- throw new Error('When function name must be a non-empty string');
19
- return { kind: 'fn', fn: raw };
20
- }
21
- if (isDefinedFunc(raw)) {
22
- return { kind: 'fn', fn: resolveFuncName(raw, functions) };
23
- }
24
- return { kind: 'rules', condition: normalizeJsonRules(raw) };
25
- }
26
- export function compileAuthoringWhen(raw, functions) {
27
- if (isOtherwise(raw)) {
28
- const items = (raw.notAny ?? []).map((item) => compileWhen(item, functions));
29
- return notAnyWhen(items);
30
- }
31
- return compileWhen(raw, functions);
32
- }
33
- export function andCompiledWhen(a, b) {
34
- if (a.kind === 'always')
35
- return b;
36
- if (b.kind === 'always')
37
- return a;
38
- if (a.kind === 'rules' && b.kind === 'rules') {
39
- return { kind: 'rules', condition: { all: [a.condition, b.condition] } };
40
- }
41
- throw new Error('Cannot combine boolFunction with another when; use json-rules all/any/not');
42
- }
43
- export function notAnyWhen(items) {
44
- if (items.length === 0)
45
- return { kind: 'always' };
46
- if (!items.every((item) => item.kind === 'rules')) {
47
- throw new Error('otherwise() siblings must be json-rules; use json-rules any/not');
48
- }
49
- return {
50
- kind: 'rules',
51
- condition: { not: { any: items.map((item) => item.condition) } },
52
- };
53
- }
54
- export function whenFields(when) {
55
- if (when.kind !== 'rules')
56
- return [];
57
- return collectJsonRulesFacts(when.condition);
58
- }
59
- export async function evaluateWhen(when, snapshot, compute) {
60
- if (when.kind === 'always')
61
- return { done: true, pass: true, failedFields: [] };
62
- if (when.kind === 'rules') {
63
- const caseContext = compute ? await compute.execute('caseContextView', [snapshot]) : snapshot;
64
- const result = await evaluateJsonRules(when.condition, caseContext);
65
- return { ...result, done: result.pass };
66
- }
67
- if (when.kind === 'fn') {
68
- if (!compute)
69
- throw new Error(`when fn '${when.fn}' requires a ComputeHost`);
70
- const raw = await compute.execute(when.fn, [snapshot]);
71
- if (typeof raw !== 'boolean') {
72
- throw new Error(`when fn '${when.fn}' must return boolean, got ${typeof raw}`);
73
- }
74
- return { done: raw, pass: raw, failedFields: [] };
75
- }
76
- const _exhaustive = when;
77
- return _exhaustive;
78
- }
79
- export const compileFinishWhen = compileWhen;
80
- export const evaluateFinishWhen = evaluateWhen;
81
- export const finishWhenFields = whenFields;
82
- //# sourceMappingURL=finish-when.js.map
@@ -1,27 +0,0 @@
1
- import type { FuncMap } from '../functions/types.js';
2
- import type { ValidationIssue } from '../slot/types.js';
3
- import type { AgendaBlock, AgendaTree, AuthoringNode, CompiledAgendaBlock, FlatAgendaItem, SequenceAgendas, Placement } from './types.js';
4
- export type FlattenOptions = {
5
- functions?: FuncMap;
6
- };
7
- export type FlattenResult = {
8
- items: FlatAgendaItem[];
9
- blocks: Record<string, CompiledAgendaBlock>;
10
- issues: ValidationIssue[];
11
- };
12
- /** Extract reusable blocks from an inline agenda tree. */
13
- export declare function extractBlocksFromTree(tree: AuthoringNode[], blocks?: Record<string, AgendaBlock>): Record<string, AgendaBlock>;
14
- export declare function flattenAgendaTree(tree: AuthoringNode[], options?: FlattenOptions): FlattenResult;
15
- export declare function flattenAgendaPlacements(placements: Placement[], blocks: Record<string, AgendaBlock>, options?: FlattenOptions): FlattenResult;
16
- export declare function flattenAgendaConfig(config: {
17
- placements?: Placement[];
18
- tree?: AuthoringNode[];
19
- }, blocks: Record<string, AgendaBlock>, options?: FlattenOptions): FlattenResult;
20
- export declare function treeToPlacements(tree: AuthoringNode[]): {
21
- blocks: Record<string, AgendaBlock>;
22
- placements: Placement[];
23
- };
24
- export declare function isAgendaTree(value: unknown): value is AgendaTree;
25
- export declare function isSequenceAgendas(value: unknown): value is SequenceAgendas;
26
- export declare function normalizeSequenceAgendas(value: unknown): SequenceAgendas;
27
- //# sourceMappingURL=flatten.d.ts.map