@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
@@ -0,0 +1,167 @@
1
+ import { z } from 'zod';
2
+ import { type CaseActivity } from '../case-orchestrator/types.js';
3
+ /**
4
+ * One exchange, as company code names it (21 §11.4): each channel the way it is told apart — a call by
5
+ * its id, a text line by our number and theirs, an email by its thread.
6
+ */
7
+ export declare const exchangeRef: z.ZodDiscriminatedUnion<[z.ZodObject<{
8
+ channel: z.ZodLiteral<"call">;
9
+ callId: z.ZodString;
10
+ }, z.core.$strip>, z.ZodObject<{
11
+ channel: z.ZodLiteral<"sms">;
12
+ ours: z.ZodString;
13
+ theirs: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ channel: z.ZodLiteral<"email">;
16
+ emailThreadId: z.ZodString;
17
+ }, z.core.$strip>], "channel">;
18
+ export type ExchangeRef = z.infer<typeof exchangeRef>;
19
+ /**
20
+ * The latest exchange between our number / mailbox and theirs, whatever its session's state: a call
21
+ * back or a reply to a message is recognised by it (14-sequence-instance §18.4).
22
+ */
23
+ export declare const exchangeSummary: z.ZodObject<{
24
+ instanceId: z.ZodString;
25
+ sequence: z.ZodString;
26
+ at: z.ZodString;
27
+ sessionActive: z.ZodBoolean;
28
+ instanceActive: z.ZodBoolean;
29
+ contactId: z.ZodNullable<z.ZodString>;
30
+ }, z.core.$strip>;
31
+ export type ExchangeSummary = z.infer<typeof exchangeSummary>;
32
+ export declare const exchangeLastInput: z.ZodObject<{
33
+ ours: z.ZodObject<{
34
+ kind: z.ZodEnum<{
35
+ email: "email";
36
+ phone: "phone";
37
+ sip: "sip";
38
+ }>;
39
+ value: z.ZodString;
40
+ }, z.core.$strip>;
41
+ theirs: z.ZodObject<{
42
+ kind: z.ZodEnum<{
43
+ email: "email";
44
+ phone: "phone";
45
+ sip: "sip";
46
+ }>;
47
+ value: z.ZodString;
48
+ }, z.core.$strip>;
49
+ }, z.core.$strict>;
50
+ export type ExchangeLastParams = z.infer<typeof exchangeLastInput>;
51
+ export declare const exchangeLastOutput: z.ZodObject<{
52
+ exchange: z.ZodNullable<z.ZodObject<{
53
+ instanceId: z.ZodString;
54
+ sequence: z.ZodString;
55
+ at: z.ZodString;
56
+ sessionActive: z.ZodBoolean;
57
+ instanceActive: z.ZodBoolean;
58
+ contactId: z.ZodNullable<z.ZodString>;
59
+ }, z.core.$strip>>;
60
+ }, z.core.$strip>;
61
+ export type ExchangeLastResult = z.infer<typeof exchangeLastOutput>;
62
+ export declare const exchangeEmailThreadInput: z.ZodObject<{
63
+ ours: z.ZodObject<{
64
+ kind: z.ZodEnum<{
65
+ email: "email";
66
+ phone: "phone";
67
+ sip: "sip";
68
+ }>;
69
+ value: z.ZodString;
70
+ }, z.core.$strip>;
71
+ threadId: z.ZodString;
72
+ }, z.core.$strict>;
73
+ export type ExchangeEmailThreadParams = z.infer<typeof exchangeEmailThreadInput>;
74
+ /** The instance an email thread already belongs to. */
75
+ export declare const exchangeEmailThreadOutput: z.ZodObject<{
76
+ thread: z.ZodNullable<z.ZodObject<{
77
+ instanceId: z.ZodString;
78
+ sequence: z.ZodString;
79
+ instanceActive: z.ZodBoolean;
80
+ }, z.core.$strip>>;
81
+ }, z.core.$strip>;
82
+ export type ExchangeEmailThreadResult = z.infer<typeof exchangeEmailThreadOutput>;
83
+ /**
84
+ * What one instance exchanged with the contacts its code names (38 §2.8): each one's history, contact
85
+ * hours and channel availability, the instance's together. The Orchestrator reads it to write its
86
+ * prompt; whom to name is its own to read from the business data.
87
+ */
88
+ export declare const exchangeActivityInput: z.ZodObject<{
89
+ instanceId: z.ZodString;
90
+ contactIds: z.ZodArray<z.ZodString>;
91
+ }, z.core.$strip>;
92
+ export type ExchangeActivityParams = z.infer<typeof exchangeActivityInput>;
93
+ export declare const exchangeActivityOutput: z.ZodCustom<CaseActivity, CaseActivity>;
94
+ /** Platform exchange lookups, reached from scripts as `ctx.api.exchanges` (§18.4). */
95
+ export type ExchangesApi = {
96
+ /** The latest exchange between `ours` and `theirs`; null when they never exchanged anything. */
97
+ last(input: ExchangeLastParams): Promise<ExchangeLastResult>;
98
+ /** The instance an email thread belongs to; null when no message of it is on an instance. */
99
+ emailThread(input: ExchangeEmailThreadParams): Promise<ExchangeEmailThreadResult>;
100
+ /** An instance's exchanges with `contactIds`, in that order: the first one's time zone is the instance's. */
101
+ activity(input: ExchangeActivityParams): Promise<CaseActivity>;
102
+ };
103
+ /** Stand-in surface for fake contexts and local runs; never touches the database. */
104
+ export declare const exchangesMockService: ExchangesApi;
105
+ export declare const exchangesSurface: {
106
+ methods: {
107
+ last: {
108
+ input: z.ZodObject<{
109
+ ours: z.ZodObject<{
110
+ kind: z.ZodEnum<{
111
+ email: "email";
112
+ phone: "phone";
113
+ sip: "sip";
114
+ }>;
115
+ value: z.ZodString;
116
+ }, z.core.$strip>;
117
+ theirs: z.ZodObject<{
118
+ kind: z.ZodEnum<{
119
+ email: "email";
120
+ phone: "phone";
121
+ sip: "sip";
122
+ }>;
123
+ value: z.ZodString;
124
+ }, z.core.$strip>;
125
+ }, z.core.$strict>;
126
+ output: z.ZodObject<{
127
+ exchange: z.ZodNullable<z.ZodObject<{
128
+ instanceId: z.ZodString;
129
+ sequence: z.ZodString;
130
+ at: z.ZodString;
131
+ sessionActive: z.ZodBoolean;
132
+ instanceActive: z.ZodBoolean;
133
+ contactId: z.ZodNullable<z.ZodString>;
134
+ }, z.core.$strip>>;
135
+ }, z.core.$strip>;
136
+ };
137
+ emailThread: {
138
+ input: z.ZodObject<{
139
+ ours: z.ZodObject<{
140
+ kind: z.ZodEnum<{
141
+ email: "email";
142
+ phone: "phone";
143
+ sip: "sip";
144
+ }>;
145
+ value: z.ZodString;
146
+ }, z.core.$strip>;
147
+ threadId: z.ZodString;
148
+ }, z.core.$strict>;
149
+ output: z.ZodObject<{
150
+ thread: z.ZodNullable<z.ZodObject<{
151
+ instanceId: z.ZodString;
152
+ sequence: z.ZodString;
153
+ instanceActive: z.ZodBoolean;
154
+ }, z.core.$strip>>;
155
+ }, z.core.$strip>;
156
+ };
157
+ activity: {
158
+ input: z.ZodObject<{
159
+ instanceId: z.ZodString;
160
+ contactIds: z.ZodArray<z.ZodString>;
161
+ }, z.core.$strip>;
162
+ output: z.ZodCustom<CaseActivity, CaseActivity>;
163
+ };
164
+ };
165
+ mock: ExchangesApi;
166
+ };
167
+ //# sourceMappingURL=exchanges.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { z } from 'zod';
2
+ import { arrivalAddress } from '../party/schema.js';
3
+ import { EMPTY_CASE_ACTIVITY } from '../case-orchestrator/types.js';
4
+ /**
5
+ * One exchange, as company code names it (21 §11.4): each channel the way it is told apart — a call by
6
+ * its id, a text line by our number and theirs, an email by its thread.
7
+ */
8
+ export const exchangeRef = z.discriminatedUnion('channel', [
9
+ z.object({ channel: z.literal('call'), callId: z.string() }),
10
+ z.object({ channel: z.literal('sms'), ours: z.string(), theirs: z.string() }),
11
+ z.object({ channel: z.literal('email'), emailThreadId: z.string() }),
12
+ ]);
13
+ /**
14
+ * The latest exchange between our number / mailbox and theirs, whatever its session's state: a call
15
+ * back or a reply to a message is recognised by it (14-sequence-instance §18.4).
16
+ */
17
+ export const exchangeSummary = z.object({
18
+ instanceId: z.string(),
19
+ /** The instance's sequence (its name). */
20
+ sequence: z.string(),
21
+ at: z.string(),
22
+ /** Its session is still open (an SMS conversation not yet ended, a call in progress). */
23
+ sessionActive: z.boolean(),
24
+ instanceActive: z.boolean(),
25
+ /** The contact it was with. */
26
+ contactId: z.string().nullable(),
27
+ });
28
+ export const exchangeLastInput = z.strictObject({
29
+ /** Our number, SIP address or mailbox (`conversation.to` of `resolve`). A SIP address has calls only. */
30
+ ours: arrivalAddress,
31
+ /**
32
+ * Theirs (`conversation.from`). Phone exchanges are calls and texts; email ones are emails; a SIP caller's
33
+ * URI finds their calls from it.
34
+ */
35
+ theirs: arrivalAddress,
36
+ });
37
+ export const exchangeLastOutput = z.object({ exchange: exchangeSummary.nullable() });
38
+ export const exchangeEmailThreadInput = z.strictObject({
39
+ /**
40
+ * Our mailbox the email came to (`conversation.to` of `resolve`): a provider thread id is only one
41
+ * mailbox's. A number or SIP address has no threads.
42
+ */
43
+ ours: arrivalAddress,
44
+ /** The provider thread id (`conversation.threadId`). */
45
+ threadId: z.string().min(1),
46
+ });
47
+ /** The instance an email thread already belongs to. */
48
+ export const exchangeEmailThreadOutput = z.object({
49
+ thread: z.object({ instanceId: z.string(), sequence: z.string(), instanceActive: z.boolean() }).nullable(),
50
+ });
51
+ /**
52
+ * What one instance exchanged with the contacts its code names (38 §2.8): each one's history, contact
53
+ * hours and channel availability, the instance's together. The Orchestrator reads it to write its
54
+ * prompt; whom to name is its own to read from the business data.
55
+ */
56
+ export const exchangeActivityInput = z.object({
57
+ instanceId: z.string().min(1),
58
+ contactIds: z.array(z.string().min(1)),
59
+ });
60
+ export const exchangeActivityOutput = z.custom((value) => typeof value === 'object' && value !== null);
61
+ /** Stand-in surface for fake contexts and local runs; never touches the database. */
62
+ export const exchangesMockService = {
63
+ async last() {
64
+ return { exchange: null };
65
+ },
66
+ async emailThread() {
67
+ return { thread: null };
68
+ },
69
+ async activity() {
70
+ return EMPTY_CASE_ACTIVITY;
71
+ },
72
+ };
73
+ export const exchangesSurface = {
74
+ methods: {
75
+ last: { input: exchangeLastInput, output: exchangeLastOutput },
76
+ emailThread: { input: exchangeEmailThreadInput, output: exchangeEmailThreadOutput },
77
+ activity: { input: exchangeActivityInput, output: exchangeActivityOutput },
78
+ },
79
+ mock: exchangesMockService,
80
+ };
81
+ //# sourceMappingURL=exchanges.js.map
@@ -0,0 +1,307 @@
1
+ import { z } from 'zod';
2
+ /** One run of a sequence about one business root (14-sequence-instance §4). */
3
+ export declare const instanceSummary: z.ZodObject<{
4
+ id: z.ZodString;
5
+ sequenceId: z.ZodString;
6
+ sequence: z.ZodString;
7
+ subjectRecordId: z.ZodString;
8
+ status: z.ZodEnum<{
9
+ active: "active";
10
+ closed: "closed";
11
+ }>;
12
+ closeReason: z.ZodNullable<z.ZodString>;
13
+ origin: z.ZodString;
14
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
15
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
16
+ createdAt: z.ZodString;
17
+ lastActivityAt: z.ZodString;
18
+ closedAt: z.ZodNullable<z.ZodString>;
19
+ }, z.core.$strip>;
20
+ export type InstanceSummary = z.infer<typeof instanceSummary>;
21
+ export declare const instanceStartInput: z.ZodObject<{
22
+ sequence: z.ZodString;
23
+ subjectRecordId: z.ZodString;
24
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
25
+ origin: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strict>;
27
+ export type InstanceStartParams = z.infer<typeof instanceStartInput>;
28
+ /** A start: the instance, and whether it is new (false when one was already active on the root). */
29
+ export declare const instanceStartOutput: z.ZodObject<{
30
+ instance: z.ZodObject<{
31
+ id: z.ZodString;
32
+ sequenceId: z.ZodString;
33
+ sequence: z.ZodString;
34
+ subjectRecordId: z.ZodString;
35
+ status: z.ZodEnum<{
36
+ active: "active";
37
+ closed: "closed";
38
+ }>;
39
+ closeReason: z.ZodNullable<z.ZodString>;
40
+ origin: z.ZodString;
41
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
42
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
43
+ createdAt: z.ZodString;
44
+ lastActivityAt: z.ZodString;
45
+ closedAt: z.ZodNullable<z.ZodString>;
46
+ }, z.core.$strip>;
47
+ created: z.ZodBoolean;
48
+ }, z.core.$strip>;
49
+ export type InstanceStartResult = z.infer<typeof instanceStartOutput>;
50
+ export declare const instanceIdInput: z.ZodObject<{
51
+ instanceId: z.ZodString;
52
+ }, z.core.$strict>;
53
+ export type InstanceIdParams = z.infer<typeof instanceIdInput>;
54
+ export declare const instanceCloseInput: z.ZodObject<{
55
+ instanceId: z.ZodString;
56
+ reason: z.ZodString;
57
+ }, z.core.$strict>;
58
+ export type InstanceCloseParams = z.infer<typeof instanceCloseInput>;
59
+ /**
60
+ * A close: the instance as it is now, whether it was closed already (then nothing changed: its reason
61
+ * stays the first close's), and the pending scheduled actions this close cancelled.
62
+ */
63
+ export declare const instanceCloseOutput: z.ZodObject<{
64
+ id: z.ZodString;
65
+ sequenceId: z.ZodString;
66
+ sequence: z.ZodString;
67
+ subjectRecordId: z.ZodString;
68
+ status: z.ZodEnum<{
69
+ active: "active";
70
+ closed: "closed";
71
+ }>;
72
+ closeReason: z.ZodNullable<z.ZodString>;
73
+ origin: z.ZodString;
74
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
75
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
76
+ createdAt: z.ZodString;
77
+ lastActivityAt: z.ZodString;
78
+ closedAt: z.ZodNullable<z.ZodString>;
79
+ alreadyClosed: z.ZodBoolean;
80
+ cancelledScheduledActionIds: z.ZodArray<z.ZodString>;
81
+ }, z.core.$strip>;
82
+ export type InstanceCloseResult = z.infer<typeof instanceCloseOutput>;
83
+ export declare const instanceSetVariablesInput: z.ZodObject<{
84
+ instanceId: z.ZodString;
85
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
86
+ }, z.core.$strict>;
87
+ export type InstanceSetVariablesParams = z.infer<typeof instanceSetVariablesInput>;
88
+ export declare const instanceFindForContactInput: z.ZodObject<{
89
+ contactId: z.ZodString;
90
+ activeOnly: z.ZodOptional<z.ZodBoolean>;
91
+ }, z.core.$strict>;
92
+ export type InstanceFindForContactParams = z.infer<typeof instanceFindForContactInput>;
93
+ export declare const instanceNotifyInput: z.ZodObject<{
94
+ instanceId: z.ZodString;
95
+ reason: z.ZodString;
96
+ key: z.ZodOptional<z.ZodString>;
97
+ }, z.core.$strict>;
98
+ export type InstanceNotifyParams = z.infer<typeof instanceNotifyInput>;
99
+ /**
100
+ * `recorded`: the Orchestrator runs with an `external` trigger; `duplicate`: this key was already
101
+ * recorded; `instance_closed` / `no_orchestrator`: nothing runs (the instance ended, or its sequence
102
+ * has no orchestrator.ts).
103
+ */
104
+ export declare const instanceNotifyOutput: z.ZodObject<{
105
+ outcome: z.ZodEnum<{
106
+ duplicate: "duplicate";
107
+ instance_closed: "instance_closed";
108
+ no_orchestrator: "no_orchestrator";
109
+ recorded: "recorded";
110
+ }>;
111
+ }, z.core.$strip>;
112
+ export type InstanceNotifyResult = z.infer<typeof instanceNotifyOutput>;
113
+ export declare const instanceListOutput: z.ZodObject<{
114
+ instances: z.ZodArray<z.ZodObject<{
115
+ id: z.ZodString;
116
+ sequenceId: z.ZodString;
117
+ sequence: z.ZodString;
118
+ subjectRecordId: z.ZodString;
119
+ status: z.ZodEnum<{
120
+ active: "active";
121
+ closed: "closed";
122
+ }>;
123
+ closeReason: z.ZodNullable<z.ZodString>;
124
+ origin: z.ZodString;
125
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
126
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
127
+ createdAt: z.ZodString;
128
+ lastActivityAt: z.ZodString;
129
+ closedAt: z.ZodNullable<z.ZodString>;
130
+ }, z.core.$strip>>;
131
+ }, z.core.$strip>;
132
+ export type InstanceListResult = z.infer<typeof instanceListOutput>;
133
+ /** Platform instance capability, reached from scripts as `ctx.api.instances`. */
134
+ export type InstancesApi = {
135
+ /**
136
+ * Start an instance of a sequence on a business root row. When one is already active on that row
137
+ * (any sequence) it is returned with `created: false` instead: one active instance per root.
138
+ */
139
+ start(input: InstanceStartParams): Promise<InstanceStartResult>;
140
+ get(input: InstanceIdParams): Promise<InstanceSummary>;
141
+ /**
142
+ * End the instance: its pending scheduled actions are cancelled and no Run follows. Final. An
143
+ * instance already closed is returned as it is (`alreadyClosed`). Shown on the case's timeline.
144
+ */
145
+ close(input: InstanceCloseParams): Promise<InstanceCloseResult>;
146
+ /** Merge run variables by name (atomic per variable; checked against the sequence's declarations). */
147
+ setVariables(input: InstanceSetVariablesParams): Promise<InstanceSummary>;
148
+ /**
149
+ * The instances a contact takes part in: those whose business root is the contact, or a row that
150
+ * refers to the contact by a lookup and is under the root (by parent, up to 5 levels). Most recent
151
+ * activity first.
152
+ */
153
+ findForContact(input: InstanceFindForContactParams): Promise<InstanceListResult>;
154
+ /**
155
+ * Tell the instance about something outside the platform (25 §6.2): its Orchestrator runs with an
156
+ * `external` trigger (`{ reason }`), debounced with the others. Write the facts first (`ctx.api.db`):
157
+ * the Orchestrator reads the case as it is when it runs. From a webhook, a function or
158
+ * an event handler; the Orchestrator decides what it means (cancel the reminder, close the case).
159
+ */
160
+ notify(input: InstanceNotifyParams): Promise<InstanceNotifyResult>;
161
+ };
162
+ /** Stand-in surface for fake contexts and local runs; never touches the database. */
163
+ export declare const instancesMockService: InstancesApi;
164
+ export declare const instancesSurface: {
165
+ methods: {
166
+ start: {
167
+ input: z.ZodObject<{
168
+ sequence: z.ZodString;
169
+ subjectRecordId: z.ZodString;
170
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
171
+ origin: z.ZodOptional<z.ZodString>;
172
+ }, z.core.$strict>;
173
+ output: z.ZodObject<{
174
+ instance: z.ZodObject<{
175
+ id: z.ZodString;
176
+ sequenceId: z.ZodString;
177
+ sequence: z.ZodString;
178
+ subjectRecordId: z.ZodString;
179
+ status: z.ZodEnum<{
180
+ active: "active";
181
+ closed: "closed";
182
+ }>;
183
+ closeReason: z.ZodNullable<z.ZodString>;
184
+ origin: z.ZodString;
185
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
186
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
187
+ createdAt: z.ZodString;
188
+ lastActivityAt: z.ZodString;
189
+ closedAt: z.ZodNullable<z.ZodString>;
190
+ }, z.core.$strip>;
191
+ created: z.ZodBoolean;
192
+ }, z.core.$strip>;
193
+ };
194
+ get: {
195
+ input: z.ZodObject<{
196
+ instanceId: z.ZodString;
197
+ }, z.core.$strict>;
198
+ output: z.ZodObject<{
199
+ id: z.ZodString;
200
+ sequenceId: z.ZodString;
201
+ sequence: z.ZodString;
202
+ subjectRecordId: z.ZodString;
203
+ status: z.ZodEnum<{
204
+ active: "active";
205
+ closed: "closed";
206
+ }>;
207
+ closeReason: z.ZodNullable<z.ZodString>;
208
+ origin: z.ZodString;
209
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
210
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
211
+ createdAt: z.ZodString;
212
+ lastActivityAt: z.ZodString;
213
+ closedAt: z.ZodNullable<z.ZodString>;
214
+ }, z.core.$strip>;
215
+ };
216
+ close: {
217
+ input: z.ZodObject<{
218
+ instanceId: z.ZodString;
219
+ reason: z.ZodString;
220
+ }, z.core.$strict>;
221
+ output: z.ZodObject<{
222
+ id: z.ZodString;
223
+ sequenceId: z.ZodString;
224
+ sequence: z.ZodString;
225
+ subjectRecordId: z.ZodString;
226
+ status: z.ZodEnum<{
227
+ active: "active";
228
+ closed: "closed";
229
+ }>;
230
+ closeReason: z.ZodNullable<z.ZodString>;
231
+ origin: z.ZodString;
232
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
233
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
234
+ createdAt: z.ZodString;
235
+ lastActivityAt: z.ZodString;
236
+ closedAt: z.ZodNullable<z.ZodString>;
237
+ alreadyClosed: z.ZodBoolean;
238
+ cancelledScheduledActionIds: z.ZodArray<z.ZodString>;
239
+ }, z.core.$strip>;
240
+ };
241
+ setVariables: {
242
+ input: z.ZodObject<{
243
+ instanceId: z.ZodString;
244
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
245
+ }, z.core.$strict>;
246
+ output: z.ZodObject<{
247
+ id: z.ZodString;
248
+ sequenceId: z.ZodString;
249
+ sequence: z.ZodString;
250
+ subjectRecordId: z.ZodString;
251
+ status: z.ZodEnum<{
252
+ active: "active";
253
+ closed: "closed";
254
+ }>;
255
+ closeReason: z.ZodNullable<z.ZodString>;
256
+ origin: z.ZodString;
257
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
258
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
259
+ createdAt: z.ZodString;
260
+ lastActivityAt: z.ZodString;
261
+ closedAt: z.ZodNullable<z.ZodString>;
262
+ }, z.core.$strip>;
263
+ };
264
+ findForContact: {
265
+ input: z.ZodObject<{
266
+ contactId: z.ZodString;
267
+ activeOnly: z.ZodOptional<z.ZodBoolean>;
268
+ }, z.core.$strict>;
269
+ output: z.ZodObject<{
270
+ instances: z.ZodArray<z.ZodObject<{
271
+ id: z.ZodString;
272
+ sequenceId: z.ZodString;
273
+ sequence: z.ZodString;
274
+ subjectRecordId: z.ZodString;
275
+ status: z.ZodEnum<{
276
+ active: "active";
277
+ closed: "closed";
278
+ }>;
279
+ closeReason: z.ZodNullable<z.ZodString>;
280
+ origin: z.ZodString;
281
+ variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
282
+ experiments: z.ZodRecord<z.ZodString, z.ZodString>;
283
+ createdAt: z.ZodString;
284
+ lastActivityAt: z.ZodString;
285
+ closedAt: z.ZodNullable<z.ZodString>;
286
+ }, z.core.$strip>>;
287
+ }, z.core.$strip>;
288
+ };
289
+ notify: {
290
+ input: z.ZodObject<{
291
+ instanceId: z.ZodString;
292
+ reason: z.ZodString;
293
+ key: z.ZodOptional<z.ZodString>;
294
+ }, z.core.$strict>;
295
+ output: z.ZodObject<{
296
+ outcome: z.ZodEnum<{
297
+ duplicate: "duplicate";
298
+ instance_closed: "instance_closed";
299
+ no_orchestrator: "no_orchestrator";
300
+ recorded: "recorded";
301
+ }>;
302
+ }, z.core.$strip>;
303
+ };
304
+ };
305
+ mock: InstancesApi;
306
+ };
307
+ //# sourceMappingURL=instances.d.ts.map
@@ -0,0 +1,137 @@
1
+ import { z } from 'zod';
2
+ /** One run of a sequence about one business root (14-sequence-instance §4). */
3
+ export const instanceSummary = z.object({
4
+ id: z.string(),
5
+ sequenceId: z.string(),
6
+ /** The sequence's name (its directory under `sequences/`). */
7
+ sequence: z.string(),
8
+ subjectRecordId: z.string(),
9
+ status: z.enum(['active', 'closed']),
10
+ closeReason: z.string().nullable(),
11
+ origin: z.string(),
12
+ /** Run variables' current values (`variables.ts`). */
13
+ variables: z.record(z.string(), z.unknown()),
14
+ /** The group each experiment assigned. */
15
+ experiments: z.record(z.string(), z.string()),
16
+ createdAt: z.string(),
17
+ lastActivityAt: z.string(),
18
+ closedAt: z.string().nullable(),
19
+ });
20
+ export const instanceStartInput = z
21
+ .strictObject({
22
+ /** Name of the sequence to run. */
23
+ sequence: z.string().min(1),
24
+ /**
25
+ * A row of the table the sequence declares as `subject`. A new one is made first with
26
+ * `ctx.api.db.<table>.create` (28 §6), then the instance starts on it.
27
+ */
28
+ subjectRecordId: z.string().min(1),
29
+ /** Initial run variables, checked against the sequence's `variables.ts`. */
30
+ variables: z.record(z.string(), z.unknown()).optional(),
31
+ /** How it started (default `script`). */
32
+ origin: z.string().min(1).max(64).optional(),
33
+ });
34
+ /** A start: the instance, and whether it is new (false when one was already active on the root). */
35
+ export const instanceStartOutput = z.object({ instance: instanceSummary, created: z.boolean() });
36
+ export const instanceIdInput = z.strictObject({ instanceId: z.string().min(1) });
37
+ export const instanceCloseInput = z.strictObject({
38
+ instanceId: z.string().min(1),
39
+ /** completed | cancelled | a short text (at most 64 characters). */
40
+ reason: z.string().min(1).max(64),
41
+ });
42
+ /**
43
+ * A close: the instance as it is now, whether it was closed already (then nothing changed: its reason
44
+ * stays the first close's), and the pending scheduled actions this close cancelled.
45
+ */
46
+ export const instanceCloseOutput = instanceSummary.extend({
47
+ alreadyClosed: z.boolean(),
48
+ cancelledScheduledActionIds: z.array(z.string()),
49
+ });
50
+ export const instanceSetVariablesInput = z.strictObject({
51
+ instanceId: z.string().min(1),
52
+ /** Variables to set, merged by name (null unsets one). */
53
+ values: z.record(z.string(), z.unknown()),
54
+ });
55
+ export const instanceFindForContactInput = z.strictObject({
56
+ contactId: z.string().min(1),
57
+ /** Only active instances. */
58
+ activeOnly: z.boolean().optional(),
59
+ });
60
+ export const instanceNotifyInput = z.strictObject({
61
+ instanceId: z.string().min(1),
62
+ /**
63
+ * What happened, a short stable label (`payment.posted`), for the Run's trigger and its log. The facts go in the records first: the Orchestrator reads them when it runs.
64
+ */
65
+ reason: z.string().trim().min(1).max(64),
66
+ /**
67
+ * The event's own id (the payment's id), so a webhook delivered twice wakes the Orchestrator once:
68
+ * one key is recorded once per instance. Left out, every call is a new event.
69
+ */
70
+ key: z.string().trim().min(1).max(200).optional(),
71
+ });
72
+ /**
73
+ * `recorded`: the Orchestrator runs with an `external` trigger; `duplicate`: this key was already
74
+ * recorded; `instance_closed` / `no_orchestrator`: nothing runs (the instance ended, or its sequence
75
+ * has no orchestrator.ts).
76
+ */
77
+ export const instanceNotifyOutput = z.object({
78
+ outcome: z.enum(['recorded', 'duplicate', 'instance_closed', 'no_orchestrator']),
79
+ });
80
+ export const instanceListOutput = z.object({ instances: z.array(instanceSummary) });
81
+ const mockInstance = {
82
+ id: 'instance',
83
+ sequenceId: 'sequence',
84
+ sequence: 'sequence',
85
+ subjectRecordId: 'subject',
86
+ status: 'active',
87
+ closeReason: null,
88
+ origin: 'script',
89
+ variables: {},
90
+ experiments: {},
91
+ createdAt: new Date(0).toISOString(),
92
+ lastActivityAt: new Date(0).toISOString(),
93
+ closedAt: null,
94
+ };
95
+ /** Stand-in surface for fake contexts and local runs; never touches the database. */
96
+ export const instancesMockService = {
97
+ async start(input) {
98
+ return {
99
+ instance: { ...mockInstance, sequence: input.sequence, subjectRecordId: input.subjectRecordId },
100
+ created: true,
101
+ };
102
+ },
103
+ async get(input) {
104
+ return { ...mockInstance, id: input.instanceId };
105
+ },
106
+ async close(input) {
107
+ return {
108
+ ...mockInstance,
109
+ id: input.instanceId,
110
+ status: 'closed',
111
+ closeReason: input.reason,
112
+ alreadyClosed: false,
113
+ cancelledScheduledActionIds: [],
114
+ };
115
+ },
116
+ async setVariables(input) {
117
+ return { ...mockInstance, id: input.instanceId, variables: input.values };
118
+ },
119
+ async findForContact() {
120
+ return { instances: [] };
121
+ },
122
+ async notify() {
123
+ return { outcome: 'recorded' };
124
+ },
125
+ };
126
+ export const instancesSurface = {
127
+ methods: {
128
+ start: { input: instanceStartInput, output: instanceStartOutput },
129
+ get: { input: instanceIdInput, output: instanceSummary },
130
+ close: { input: instanceCloseInput, output: instanceCloseOutput },
131
+ setVariables: { input: instanceSetVariablesInput, output: instanceSummary },
132
+ findForContact: { input: instanceFindForContactInput, output: instanceListOutput },
133
+ notify: { input: instanceNotifyInput, output: instanceNotifyOutput },
134
+ },
135
+ mock: instancesMockService,
136
+ };
137
+ //# sourceMappingURL=instances.js.map