@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,74 @@
1
+ import type { PageTablesDesc } from '../page/typed.js';
2
+ import type { ExchangeRef } from '../context/exchanges.js';
3
+ import type { Ctx } from './types.js';
4
+ /**
5
+ * Errors of the company's code (67): a failure its code did not catch (a throw, its time or memory up), or
6
+ * a text or email conversation the AI marked stuck, is recorded once and the company's `onError` (root
7
+ * `errors.ts`) runs for it, in the background. What happens at the moment is the platform's and depends
8
+ * only on the channel (67 §3). The company does not throw errors of its own: what its code foresees, it
9
+ * handles where it happens. The platform's own failures are the platform's, not the company's (67 §4.4).
10
+ */
11
+ /** The module at the repository root `onError` is exported from. */
12
+ export declare const ERRORS_MODULE = "errors";
13
+ /** `onError`'s name in the company build's function registry. */
14
+ export declare const ON_ERROR_FUNCTION = "onError";
15
+ /**
16
+ * `crash` an uncaught throw, `timeout` / `memory` the call's limit, `stuck` the AI marked a text or email
17
+ * conversation stuck, `platform` the platform failed and what the code was doing was not done (74 §3.2: an
18
+ * Orchestrator run the platform cut off or could not run, or a {@link PlatformUnavailableError} not caught).
19
+ */
20
+ export type CodeErrorKind = 'crash' | 'timeout' | 'memory' | 'stuck' | 'platform';
21
+ /** What the company is told of a `platform` error (74 §3.2): the platform's own failure stays in its logs and alerts. */
22
+ export declare const PLATFORM_UNAVAILABLE_MESSAGE = "The platform was temporarily unavailable; we have been alerted.";
23
+ /**
24
+ * A `ctx.api` call the platform could not answer (74 §3.2): it was unreachable, or failed on its side, after
25
+ * the tries it was worth. Not caught, it is a `platform` error (we are alerted, `onError` is told); caught and
26
+ * thrown again as another error, it is the code's own.
27
+ */
28
+ export declare class PlatformUnavailableError extends Error {
29
+ readonly name = "PlatformUnavailableError";
30
+ /** The platform's refusal reason, when it gave one (`error.code`, as on any `ctx.api` error). */
31
+ code?: string;
32
+ }
33
+ /** What failed: the kind of entry, and its name (a function's, an event's, a job's, the page's `render` / `start` / `action:<name>`). */
34
+ export type CodeErrorSourceType = 'resolve' | 'page' | 'function' | 'event' | 'orchestrator' | 'schedule' | 'webhook' | 'conversation';
35
+ /** At most this much JSON for `args` (67 §4.2): bigger is cut, and says so. */
36
+ export declare const ERROR_JSON_MAX_BYTES: number;
37
+ /** One error, as `onError` gets it (`args.error`). */
38
+ export type CodeErrorEvent = {
39
+ /** The error's id: find it in the error view, say it to the platform's team. */
40
+ id: string;
41
+ kind: CodeErrorKind;
42
+ message: string;
43
+ /** Where your code threw, in your files; none for `timeout`, `memory`, `stuck`, `platform`. */
44
+ stack?: string;
45
+ source: {
46
+ type: CodeErrorSourceType;
47
+ name: string;
48
+ };
49
+ /** The published company build whose code ran; null when a repository was being served. */
50
+ buildId: string | null;
51
+ at: string;
52
+ ids: {
53
+ sequenceId?: string;
54
+ instanceId?: string;
55
+ contactId?: string;
56
+ runId?: string;
57
+ };
58
+ /** Who is waiting: the call (it was already ended), or a text's or email's exchange and what the customer sent. */
59
+ channel?: {
60
+ type: 'call';
61
+ callId?: string;
62
+ } | {
63
+ type: 'sms' | 'email';
64
+ exchange?: ExchangeRef;
65
+ waiting: string;
66
+ };
67
+ /** The arguments of the call that failed (cut at {@link ERROR_JSON_MAX_BYTES}). */
68
+ args?: unknown;
69
+ };
70
+ /** `onError` of `errors.ts`: `(ctx, { error })`, run once for each error, with no case. */
71
+ export type OnError<D extends PageTablesDesc | undefined = undefined> = (ctx: Ctx<D>, args: {
72
+ error: CodeErrorEvent;
73
+ }) => Promise<void>;
74
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Errors of the company's code (67): a failure its code did not catch (a throw, its time or memory up), or
3
+ * a text or email conversation the AI marked stuck, is recorded once and the company's `onError` (root
4
+ * `errors.ts`) runs for it, in the background. What happens at the moment is the platform's and depends
5
+ * only on the channel (67 §3). The company does not throw errors of its own: what its code foresees, it
6
+ * handles where it happens. The platform's own failures are the platform's, not the company's (67 §4.4).
7
+ */
8
+ /** The module at the repository root `onError` is exported from. */
9
+ export const ERRORS_MODULE = 'errors';
10
+ /** `onError`'s name in the company build's function registry. */
11
+ export const ON_ERROR_FUNCTION = 'onError';
12
+ /** What the company is told of a `platform` error (74 §3.2): the platform's own failure stays in its logs and alerts. */
13
+ export const PLATFORM_UNAVAILABLE_MESSAGE = 'The platform was temporarily unavailable; we have been alerted.';
14
+ /**
15
+ * A `ctx.api` call the platform could not answer (74 §3.2): it was unreachable, or failed on its side, after
16
+ * the tries it was worth. Not caught, it is a `platform` error (we are alerted, `onError` is told); caught and
17
+ * thrown again as another error, it is the code's own.
18
+ */
19
+ export class PlatformUnavailableError extends Error {
20
+ name = 'PlatformUnavailableError';
21
+ /** The platform's refusal reason, when it gave one (`error.code`, as on any `ctx.api` error). */
22
+ code;
23
+ }
24
+ /** At most this much JSON for `args` (67 §4.2): bigger is cut, and says so. */
25
+ export const ERROR_JSON_MAX_BYTES = 16 * 1024;
26
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,192 @@
1
+ import { z } from 'zod';
2
+ import type { Id, PageTablesDesc } from '../page/typed.js';
3
+ import type { Ctx } from './types.js';
4
+ /**
5
+ * Platform events.
6
+ *
7
+ * The event name is the key of the company `events` export. For every event the
8
+ * platform fixes the payload and the return type (`void` for every event; `webhook.received`, a
9
+ * function of its own, returns a {@link WebhookOutcome}) — companies only choose which events to
10
+ * subscribe to.
11
+ *
12
+ * A handler is a function like any other (38 §2.2): `(ctx, { event, subject, instanceId })`, the
13
+ * company's own code, not the conversation's: it does not get the page. It reads and writes with
14
+ * `ctx.api.db`.
15
+ *
16
+ * Payloads are provider-neutral on purpose: Twilio / Gmail vocabulary is
17
+ * translated in the channel adapter, never carried into these types.
18
+ */
19
+ /** Shared by every call event. `id` can be passed directly to `ctx.api.call.get`. */
20
+ export type CallEventBase = {
21
+ id: string;
22
+ /** Provider-neutral name for the channel-native id (voice: Twilio CallSid). */
23
+ externalId: string;
24
+ fromNumber: string;
25
+ toNumber: string;
26
+ };
27
+ export type CallInboundEvent = CallEventBase & {
28
+ startedAt: string;
29
+ };
30
+ export type CallOutboundEvent = CallEventBase & {
31
+ startedAt: string;
32
+ };
33
+ export type CallEndedEvent = CallEventBase & {
34
+ /** Provider-neutral terminal outcome. */
35
+ outcome: 'completed' | 'busy' | 'failed' | 'no-answer' | 'canceled';
36
+ durationSec: number | null;
37
+ };
38
+ /** Shared by every SMS event. `id` can be passed directly to `ctx.api.sms.get`. */
39
+ export type SmsEventBase = {
40
+ id: string;
41
+ fromNumber: string;
42
+ toNumber: string;
43
+ body: string;
44
+ };
45
+ export type SmsReceivedEvent = SmsEventBase & {
46
+ receivedAt: string;
47
+ };
48
+ export type SmsSendRequestedEvent = SmsEventBase & {
49
+ requestedAt: string;
50
+ };
51
+ /** Shared by every email event. `id` can be passed directly to `ctx.api.email.get`. */
52
+ export type EmailEventBase = {
53
+ id: string;
54
+ /** The provider's thread id (null for a thread we start, until its first email went). */
55
+ threadId: string | null;
56
+ fromAddress: string;
57
+ toAddresses: string[];
58
+ subject: string | null;
59
+ body: string | null;
60
+ };
61
+ export type EmailReceivedEvent = EmailEventBase & {
62
+ receivedAt: string;
63
+ };
64
+ export type EmailSendRequestedEvent = EmailEventBase & {
65
+ requestedAt: string;
66
+ };
67
+ /**
68
+ * The HTTP request exactly as the gateway saw it. The platform verifies nothing: every header,
69
+ * the absolute URL and the raw body are forwarded so the handler can check the sender's signature.
70
+ */
71
+ export type WebhookRequest = {
72
+ method: 'GET' | 'POST' | 'PUT';
73
+ /** Absolute URL as the sender saw it (`https://…/webhook/e/<code>/lead/created?x=1`); signatures are usually computed over it. */
74
+ url: string;
75
+ /** Sub-path after the webhook code: `/webhook/e/<code>/lead/created` → `lead/created`; `''` when absent. */
76
+ path: string;
77
+ query: Record<string, string>;
78
+ /** Every request header, lower-cased names, multi-valued headers joined with `, `. Nothing is removed. */
79
+ headers: Record<string, string>;
80
+ contentType: string | null;
81
+ /** Raw body text, always present (empty string for GET). */
82
+ body: string;
83
+ };
84
+ /**
85
+ * One inbound request to one of the environment's webhook URLs (made on the Webhooks page). The
86
+ * platform routes, stores and forwards it; it does not verify it and knows nothing
87
+ * about the sender's event model. The company's `webhook.ts` decides whether the request is genuine
88
+ * and answers with a {@link WebhookOutcome} (22-sequence-as-business-unit §9).
89
+ */
90
+ export type WebhookEvent = {
91
+ /** Delivery id. Stable across retries: use it as an idempotency key and to find the row in Trigger history. */
92
+ id: string;
93
+ receivedAt: string;
94
+ /** 1 on the first run, higher on worker retries. */
95
+ attempt: number;
96
+ /**
97
+ * Which webhook URL received it: `name` is the URL's name on the Webhooks page (the same in test and
98
+ * prod).
99
+ */
100
+ webhook: {
101
+ id: string;
102
+ name: string;
103
+ };
104
+ /**
105
+ * Body parsed by Content-Type: JSON → the parsed value (object, array or scalar);
106
+ * form-urlencoded → flat object; anything else → null. `request.body` always has the raw text.
107
+ */
108
+ payload: unknown;
109
+ request: WebhookRequest;
110
+ };
111
+ /**
112
+ * What `webhook.received` must return. Explicit on purpose: a plain `return` is a type error.
113
+ * - `accepted`: the request was genuine and handled; the delivery is marked succeeded.
114
+ * - `rejected`: the handler's own verification failed (bad signature, unknown sender, …); the
115
+ * delivery is marked rejected with `reason` and is never retried.
116
+ * Throwing means "something went wrong on our side": the delivery is marked failed and retried.
117
+ */
118
+ export type WebhookOutcome = {
119
+ status: 'accepted';
120
+ } | {
121
+ status: 'rejected';
122
+ reason: string;
123
+ };
124
+ /** Wire schema of {@link WebhookOutcome}; the worker validates the handler's return with it. */
125
+ export declare const webhookOutcome: z.ZodType<WebhookOutcome>;
126
+ /** Event name → { payload, handler return }. */
127
+ export type SystemEventMap = {
128
+ 'call.inbound': {
129
+ event: CallInboundEvent;
130
+ result: void;
131
+ };
132
+ 'call.outbound': {
133
+ event: CallOutboundEvent;
134
+ result: void;
135
+ };
136
+ 'call.ended': {
137
+ event: CallEndedEvent;
138
+ result: void;
139
+ };
140
+ 'sms.received': {
141
+ event: SmsReceivedEvent;
142
+ result: void;
143
+ };
144
+ 'sms.send-requested': {
145
+ event: SmsSendRequestedEvent;
146
+ result: void;
147
+ };
148
+ 'email.received': {
149
+ event: EmailReceivedEvent;
150
+ result: void;
151
+ };
152
+ 'email.send-requested': {
153
+ event: EmailSendRequestedEvent;
154
+ result: void;
155
+ };
156
+ };
157
+ export type SystemEventName = keyof SystemEventMap;
158
+ export type SystemEventPayload<K extends SystemEventName> = SystemEventMap[K]['event'];
159
+ export type SystemEventResult<K extends SystemEventName> = SystemEventMap[K]['result'];
160
+ /** Runtime table mirroring {@link SystemEventMap}: the events a handler may be written for. */
161
+ export declare const SYSTEM_EVENTS: {
162
+ readonly [K in SystemEventName]: true;
163
+ };
164
+ export declare const SYSTEM_EVENT_NAMES: readonly SystemEventName[];
165
+ export declare function isSystemEventName(value: string): value is SystemEventName;
166
+ /** What a handler is called with (38 §2.2): the event, and the instance it is on and its business root. */
167
+ export type EventHandlerArgs<K extends SystemEventName, S extends string = string> = {
168
+ event: SystemEventPayload<K>;
169
+ subject: Id<S>;
170
+ instanceId: string;
171
+ };
172
+ /** Handler for one event: `(ctx, { event, subject, instanceId })`; `D` types `ctx.api.db`, `S` the business root. */
173
+ export type EventHandler<K extends SystemEventName, D extends PageTablesDesc | undefined = undefined, S extends string = string> = (ctx: Ctx<D>, args: EventHandlerArgs<K, S>) => Promise<SystemEventResult<K>>;
174
+ /** Company `events` export: subscribe to any subset of platform events. */
175
+ export type EventHandlers<D extends PageTablesDesc | undefined = undefined, S extends string = string> = {
176
+ [K in SystemEventName]?: EventHandler<K, D, S>;
177
+ };
178
+ /** Loader/host-side view of an events map: handler argument types are not known. */
179
+ export type AnyEventHandlers = {
180
+ [K in SystemEventName]?: (ctx: any, args: any) => Promise<unknown>;
181
+ };
182
+ /** The company function that receives webhooks: `received` of `webhook.ts` at the repository root. */
183
+ export declare const WEBHOOK_RECEIVED_FUNCTION = "webhook.received";
184
+ /**
185
+ * `received` of `webhook.ts` (22 §9): every webhook of the environment comes here, told apart by
186
+ * `event.webhook.name`. It runs with no sequence; to hand a request to one, start an instance or call
187
+ * its code through the platform API. Return accepted / rejected explicitly; throw to be retried.
188
+ */
189
+ export type WebhookHandler<D extends PageTablesDesc | undefined = undefined> = (ctx: Ctx<D>, args: {
190
+ event: WebhookEvent;
191
+ }) => Promise<WebhookOutcome>;
192
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ /** Wire schema of {@link WebhookOutcome}; the worker validates the handler's return with it. */
3
+ export const webhookOutcome = z.discriminatedUnion('status', [
4
+ z.object({ status: z.literal('accepted') }),
5
+ z.object({ status: z.literal('rejected'), reason: z.string() }),
6
+ ]);
7
+ /** Runtime table mirroring {@link SystemEventMap}: the events a handler may be written for. */
8
+ export const SYSTEM_EVENTS = {
9
+ 'call.inbound': true,
10
+ 'call.outbound': true,
11
+ 'call.ended': true,
12
+ 'sms.received': true,
13
+ 'sms.send-requested': true,
14
+ 'email.received': true,
15
+ 'email.send-requested': true,
16
+ };
17
+ export const SYSTEM_EVENT_NAMES = Object.keys(SYSTEM_EVENTS);
18
+ export function isSystemEventName(value) {
19
+ return Object.hasOwn(SYSTEM_EVENTS, value);
20
+ }
21
+ /** The company function that receives webhooks: `received` of `webhook.ts` at the repository root. */
22
+ export const WEBHOOK_RECEIVED_FUNCTION = 'webhook.received';
23
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,50 @@
1
+ import type { PageTablesDesc } from '../page/typed.js';
2
+ import type { Ctx } from './types.js';
3
+ /**
4
+ * Recurring jobs (25 §6.4): `schedules.ts` at the repository root, next to `webhook.ts`; the
5
+ * company's only (a sequence has none). Each runs on its cron in every environment
6
+ * whose live release has it, with no case and no contact; `ctx.api` is the webhook handler's
7
+ * (`db`, `integration`, `instances.start`, `instances.notify`, `log`, `kv`).
8
+ */
9
+ /** What a job's `run` is told (`args.schedule`): which job, and the tick it runs for. */
10
+ export type ScheduleTick = {
11
+ /** The job's key in `defineSchedules({ … })`. */
12
+ name: string;
13
+ cron: string;
14
+ timezone: string;
15
+ /** The tick this run is for (ISO). A run made up after the worker was down has the missed tick's time. */
16
+ scheduledAt: string;
17
+ };
18
+ export type ScheduleDefinition<D extends PageTablesDesc | undefined = undefined> = {
19
+ /** Five fields: minute hour day-of-month month day-of-week (`'0 2 * * *'`: every day at 02:00). */
20
+ cron: string;
21
+ /** IANA name the cron is read in (`'UTC'`, `'America/Phoenix'`). */
22
+ timezone: string;
23
+ /** Throw to have the run recorded as failed; it is not retried, the next tick runs as usual. */
24
+ run: (ctx: Ctx<D>, args: {
25
+ schedule: ScheduleTick;
26
+ }) => Promise<void>;
27
+ };
28
+ /** The `schedules` export: job name → definition. */
29
+ export type Schedules<D extends PageTablesDesc | undefined = undefined> = Record<string, ScheduleDefinition<D>>;
30
+ /**
31
+ * Author-side helper for `schedules.ts`:
32
+ *
33
+ * ```ts
34
+ * export const schedules = defineSchedules({
35
+ * nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx, { schedule }) => { … } },
36
+ * });
37
+ * ```
38
+ */
39
+ export declare function defineSchedules<D extends PageTablesDesc | undefined = undefined>(schedules: Schedules<D>): Schedules<D>;
40
+ /** The module the repository root defines its jobs in. */
41
+ export declare const SCHEDULES_MODULE = "schedules";
42
+ /** A job's name in the build's function registry: `schedule.<name>` (a `noCase` function). */
43
+ export declare const SCHEDULE_FUNCTION_PREFIX = "schedule.";
44
+ export declare function scheduleFunctionName(name: string): string;
45
+ /** When each job of a build runs, by job name; its code is `functions[scheduleFunctionName(name)]`. */
46
+ export type ScheduleManifest = Record<string, {
47
+ cron: string;
48
+ timezone: string;
49
+ }>;
50
+ //# sourceMappingURL=schedules.d.ts.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Author-side helper for `schedules.ts`:
3
+ *
4
+ * ```ts
5
+ * export const schedules = defineSchedules({
6
+ * nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx, { schedule }) => { … } },
7
+ * });
8
+ * ```
9
+ */
10
+ export function defineSchedules(schedules) {
11
+ return schedules;
12
+ }
13
+ /** The module the repository root defines its jobs in. */
14
+ export const SCHEDULES_MODULE = 'schedules';
15
+ /** A job's name in the build's function registry: `schedule.<name>` (a `noCase` function). */
16
+ export const SCHEDULE_FUNCTION_PREFIX = 'schedule.';
17
+ export function scheduleFunctionName(name) {
18
+ return `${SCHEDULE_FUNCTION_PREFIX}${name}`;
19
+ }
20
+ //# sourceMappingURL=schedules.js.map
@@ -1,78 +1,34 @@
1
- import type { FieldPath } from '../slot/path.js';
2
- import type { CaseContext, SystemContext, Writes } from '../context/types.js';
3
- export type FuncOptions = {
4
- args?: Record<string, unknown>;
5
- description?: string;
6
- };
7
- /** First arg is CaseContext (or Slots when the sequence has no view). */
8
- export type ComputeFn<S = CaseContext, R = unknown> = (caseContext: S) => R | Promise<R>;
9
- export type FunctionCtx<Params extends object> = SystemContext & {
10
- params: Params;
11
- };
12
- export type CustomFn<S = CaseContext, P extends object = object> = (caseContext: S, ctx: FunctionCtx<P>) => Promise<Writes | null>;
13
- /** Inbound webhook request payload. */
14
- export type WebHookFunctionParams = {
15
- headers: Record<string, string | string[] | undefined>;
16
- body: unknown;
17
- rawBody?: string;
18
- };
19
- export type FunctionCall<Params extends object, Return> = (ctx: FunctionCtx<Params>) => Promise<Return>;
20
- export type WebHookFunction = FunctionCall<WebHookFunctionParams, void>;
21
- export type GetFirstMessageParams<S = CaseContext> = {
22
- caseContext: S;
23
- };
24
- export type GetFirstMessageFunction<S = CaseContext> = FunctionCall<GetFirstMessageParams<S>, string>;
25
- /** Object-key → implementation type for platform-invoked entries. */
26
- export type SystemFuncMap = {
27
- webhook: WebHookFunction;
28
- getFirstMessage: GetFirstMessageFunction;
29
- };
30
- type FuncMeta = {
31
- description?: string;
32
- args?: Record<string, unknown>;
33
- };
34
- /** One entry in a plain `functions` map (`{ name: define*Func(...) }`). */
35
- export type DefinedFunc = (FuncMeta & {
36
- kind: 'compute' | 'boolCompute';
37
- /** Implementation retained for compile → registry `code`; stripped from JSON via toFunctionRegistry. */
38
- main: ComputeFn;
39
- }) | (FuncMeta & {
40
- kind: 'custom';
41
- main: CustomFn;
42
- }) | (FuncMeta & {
43
- kind: 'system';
44
- main: FunctionCall<object, unknown>;
45
- });
1
+ import type { SystemContext } from '../context/types.js';
2
+ import type { Db } from '../page/define.js';
3
+ import type { PageTablesDesc, TypedDb } from '../page/typed.js';
4
+ /**
5
+ * `ctx` of every function and entry (38 §2.3): what it is called with besides its `args`. `ctx.api.db`
6
+ * reads and writes records like a page script and its actions (15 §10.15 task 4): any row of the
7
+ * company and environment, each write its own transaction. `D` (the company's `PageTables`, bound by
8
+ * `__gen`) types them.
9
+ */
10
+ export type Ctx<D extends PageTablesDesc | undefined = undefined> = Omit<SystemContext, 'api' | 'meta'> & {
11
+ /** What runs, where (38 §2.3): the instance a function works on is in its `args`, not here. */
12
+ meta: Omit<SystemContext['meta'], 'instanceId'>;
13
+ api: Omit<SystemContext['api'], 'db'> & {
14
+ db: D extends PageTablesDesc ? TypedDb<D> : Db;
15
+ };
16
+ };
17
+ /**
18
+ * A function as the company writes it (38 §2.1): `(ctx, args)`, `args` one object (`{}` when it takes
19
+ * none). Every entry the platform calls (functions, event handlers, `resolve`, the webhook, a schedule's
20
+ * `run`, the Orchestrator) is one; the platform tells its entries apart by name.
21
+ */
22
+ export type PlainFn = (ctx: any, args: any) => Promise<unknown>;
46
23
  /** Author map: key is the function name. */
47
- export type FuncMap = Record<string, DefinedFunc>;
48
- /** Map entry with name stamped from the key (for platform loaders). */
49
- export type FuncRegistration = DefinedFunc & {
50
- name: string;
51
- };
52
- type RegistryCode = {
53
- /**
54
- * Standalone JS function expression (esbuild-normalized).
55
- * Present on published builds; omitted on local serve overlay (`includeCode: false`).
56
- */
24
+ export type FuncMap = Record<string, PlainFn>;
25
+ /**
26
+ * Compiled function registry entry (JSON-safe). Same shape for `functions` and `events`. `code` is the
27
+ * standalone JS function expression (esbuild-normalized): present on published builds, omitted on the
28
+ * local serve overlay (`includeCode: false`).
29
+ */
30
+ export type FunctionRegistryEntry = {
57
31
  code?: string;
58
32
  };
59
- /** Compiled function registry entry shapes (JSON-safe). */
60
- export type FunctionRegistryEntry = (RegistryCode & {
61
- kind: 'compute' | 'boolCompute';
62
- }) | (RegistryCode & {
63
- kind: 'custom';
64
- writes: FieldPath[];
65
- }) | (RegistryCode & {
66
- kind: 'system';
67
- });
68
33
  export type FunctionRegistry = Record<string, FunctionRegistryEntry>;
69
- /** Compiled CaseContext projector (optional on SequenceBuild). */
70
- export type CaseContextViewRegistryEntry = {
71
- kind: 'caseContextView';
72
- /** Present on published builds; omitted on local serve overlay. */
73
- code?: string;
74
- };
75
- /** Stamp `name` from object keys when the platform loads a functions map. */
76
- export declare function toFuncRegistrations(functions: FuncMap): FuncRegistration[];
77
- export {};
78
34
  //# sourceMappingURL=types.d.ts.map
@@ -1,5 +1,2 @@
1
- /** Stamp `name` from object keys when the platform loads a functions map. */
2
- export function toFuncRegistrations(functions) {
3
- return Object.entries(functions).map(([name, def]) => ({ ...def, name }));
4
- }
1
+ export {};
5
2
  //# sourceMappingURL=types.js.map
@@ -0,0 +1,39 @@
1
+ export type Window = {
2
+ start: string;
3
+ end: string;
4
+ };
5
+ export type Weekday = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
6
+ /** Company `office-hours.ts` config. */
7
+ export type OfficeHours = {
8
+ /** IANA timezone name for the office (e.g. `'America/New_York'`). */
9
+ timezone: string;
10
+ /** Standard weekly open windows per weekday (`[]` means closed that weekday). */
11
+ week: Record<Weekday, Window[]>;
12
+ /** Recurring annual dates (`MM-DD`) whose `hours` replace `week` (`[]` means closed all day). */
13
+ holidays: {
14
+ date: string;
15
+ hours: Window[];
16
+ }[];
17
+ /** One-off calendar dates (`YYYY-MM-DD`) whose `hours` take precedence over both `holidays` and `week`. */
18
+ overrides: {
19
+ date: string;
20
+ hours: Window[];
21
+ }[];
22
+ };
23
+ /** The office hours now (`ctx.officeHours` of a page). `open` / `today` are filled by `resolveOfficeHours(now)`. */
24
+ export type OfficeHoursSnapshot = OfficeHours & {
25
+ /** Whether the office is currently open at the resolved timestamp (`ctx.time.now`). */
26
+ open: boolean;
27
+ /** Effective open windows for today's date in `timezone` (after applying `overrides` / `holidays` / `week`). */
28
+ today: Window[];
29
+ };
30
+ export type ParseOfficeHoursResult = {
31
+ ok: true;
32
+ value: OfficeHours;
33
+ } | {
34
+ ok: false;
35
+ issues: string[];
36
+ };
37
+ export declare function parseOfficeHours(value: unknown): ParseOfficeHoursResult;
38
+ export declare function resolveOfficeHours(config: OfficeHours | null | undefined, now: number): OfficeHoursSnapshot | null;
39
+ //# sourceMappingURL=index.d.ts.map