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