@superpanel-sdk/runtime 0.2.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/README.md +30 -10
  2. package/dist/builder/codegen/emit.d.ts +25 -12
  3. package/dist/builder/codegen/emit.js +339 -78
  4. package/dist/builder/codegen/generate.d.ts +21 -2
  5. package/dist/builder/codegen/generate.js +147 -34
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +29 -0
  9. package/dist/builder/company-imports.js +122 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +61 -8
  11. package/dist/builder/compile/compile-sequence.js +334 -80
  12. package/dist/builder/compile/function-code.d.ts +19 -3
  13. package/dist/builder/compile/function-code.js +123 -45
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +30 -27
  16. package/dist/builder/errors.d.ts +9 -0
  17. package/dist/builder/errors.js +17 -0
  18. package/dist/builder/function-params.d.ts +10 -0
  19. package/dist/builder/function-params.js +203 -0
  20. package/dist/builder/load.d.ts +70 -10
  21. package/dist/builder/load.js +258 -67
  22. package/dist/builder/paths.d.ts +9 -1
  23. package/dist/builder/paths.js +32 -2
  24. package/dist/builder/schedules.d.ts +25 -0
  25. package/dist/builder/schedules.js +101 -0
  26. package/dist/builder/slot-schema-validation.d.ts +4 -0
  27. package/dist/builder/slot-schema-validation.js +10 -0
  28. package/dist/builder/typecheck.d.ts +8 -0
  29. package/dist/builder/typecheck.js +102 -0
  30. package/dist/builder/types.d.ts +127 -19
  31. package/dist/builder/types.js +21 -1
  32. package/dist/cli/auth/auth.d.ts +37 -0
  33. package/dist/cli/auth/auth.js +211 -0
  34. package/dist/cli/auth/backend-url.d.ts +5 -0
  35. package/dist/cli/auth/backend-url.js +25 -0
  36. package/dist/cli/auth/clipboard.d.ts +9 -0
  37. package/dist/cli/auth/clipboard.js +38 -0
  38. package/dist/cli/auth/http.d.ts +20 -0
  39. package/dist/cli/auth/http.js +27 -0
  40. package/dist/cli/auth/index.d.ts +10 -0
  41. package/dist/cli/auth/index.js +27 -0
  42. package/dist/cli/auth/progress.d.ts +12 -0
  43. package/dist/cli/auth/progress.js +15 -0
  44. package/dist/cli/auth/serve-login.d.ts +8 -0
  45. package/dist/cli/auth/serve-login.js +24 -0
  46. package/dist/cli/calls/index.d.ts +177 -0
  47. package/dist/cli/calls/index.js +96 -0
  48. package/dist/cli/compile/index.js +3 -0
  49. package/dist/cli/config.d.ts +10 -0
  50. package/dist/cli/config.js +52 -0
  51. package/dist/cli/debug/index.d.ts +31 -0
  52. package/dist/cli/debug/index.js +119 -0
  53. package/dist/cli/exec/index.d.ts +39 -0
  54. package/dist/cli/exec/index.js +138 -0
  55. package/dist/cli/exec/session.d.ts +48 -0
  56. package/dist/cli/exec/session.js +82 -0
  57. package/dist/cli/exec/trace.d.ts +18 -0
  58. package/dist/cli/exec/trace.js +52 -0
  59. package/dist/cli/index.js +112 -9
  60. package/dist/cli/logs/index.d.ts +47 -0
  61. package/dist/cli/logs/index.js +113 -0
  62. package/dist/cli/mobile/index.d.ts +12 -0
  63. package/dist/cli/mobile/index.js +405 -0
  64. package/dist/cli/serve/index.d.ts +109 -3
  65. package/dist/cli/serve/index.js +506 -118
  66. package/dist/cli/turns/index.d.ts +105 -0
  67. package/dist/cli/turns/index.js +128 -0
  68. package/dist/cli/turns/run.d.ts +13 -0
  69. package/dist/cli/turns/run.js +57 -0
  70. package/dist/cli/turns/shadow.d.ts +112 -0
  71. package/dist/cli/turns/shadow.js +54 -0
  72. package/dist/cli/type-gen/index.js +9 -9
  73. package/dist/compiler.d.ts +7 -0
  74. package/dist/compiler.js +7 -0
  75. package/dist/compute-host/compute-host.d.ts +14 -23
  76. package/dist/compute-host/compute-host.js +18 -30
  77. package/dist/compute-host/index.d.ts +2 -4
  78. package/dist/compute-host/index.js +1 -2
  79. package/dist/compute-host/source-compute-host.d.ts +10 -10
  80. package/dist/compute-host/source-compute-host.js +33 -40
  81. package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
  82. package/dist/core/case-orchestrator/contact-hours.js +127 -0
  83. package/dist/core/case-orchestrator/index.d.ts +3 -0
  84. package/dist/core/case-orchestrator/index.js +3 -0
  85. package/dist/core/case-orchestrator/render.d.ts +75 -0
  86. package/dist/core/case-orchestrator/render.js +244 -0
  87. package/dist/core/case-orchestrator/time.d.ts +11 -0
  88. package/dist/core/case-orchestrator/time.js +29 -0
  89. package/dist/core/case-orchestrator/types.d.ts +708 -0
  90. package/dist/core/case-orchestrator/types.js +42 -0
  91. package/dist/core/context/call.d.ts +291 -0
  92. package/dist/core/context/call.js +94 -0
  93. package/dist/core/context/channels.d.ts +60 -0
  94. package/dist/core/context/channels.js +35 -0
  95. package/dist/core/context/contact.d.ts +96 -6
  96. package/dist/core/context/contact.js +48 -2
  97. package/dist/core/context/email-message.d.ts +198 -0
  98. package/dist/core/context/email-message.js +86 -0
  99. package/dist/core/context/email.d.ts +109 -0
  100. package/dist/core/context/email.js +90 -0
  101. package/dist/core/context/exchanges.d.ts +167 -0
  102. package/dist/core/context/exchanges.js +81 -0
  103. package/dist/core/context/instances.d.ts +307 -0
  104. package/dist/core/context/instances.js +137 -0
  105. package/dist/core/context/kv.d.ts +113 -0
  106. package/dist/core/context/kv.js +60 -0
  107. package/dist/core/context/platform-registry.d.ts +544 -4
  108. package/dist/core/context/platform-registry.js +14 -2
  109. package/dist/core/context/platform.d.ts +2 -1
  110. package/dist/core/context/sms.d.ts +177 -0
  111. package/dist/core/context/sms.js +77 -0
  112. package/dist/core/context/types.d.ts +79 -48
  113. package/dist/core/context/types.js +1 -7
  114. package/dist/core/conversation/index.d.ts +85 -0
  115. package/dist/core/conversation/index.js +133 -0
  116. package/dist/core/functions/errors.d.ts +74 -0
  117. package/dist/core/functions/errors.js +26 -0
  118. package/dist/core/functions/events.d.ts +192 -0
  119. package/dist/core/functions/events.js +23 -0
  120. package/dist/core/functions/schedules.d.ts +50 -0
  121. package/dist/core/functions/schedules.js +20 -0
  122. package/dist/core/functions/types.d.ts +29 -73
  123. package/dist/core/functions/types.js +1 -4
  124. package/dist/core/office-hours/index.d.ts +39 -0
  125. package/dist/core/office-hours/index.js +187 -0
  126. package/dist/core/page/define.d.ts +904 -0
  127. package/dist/core/page/define.js +518 -0
  128. package/dist/core/page/envelope.d.ts +55 -0
  129. package/dist/core/page/envelope.js +4 -0
  130. package/dist/core/page/fns.d.ts +448 -0
  131. package/dist/core/page/fns.js +539 -0
  132. package/dist/core/page/memory-reader.d.ts +27 -0
  133. package/dist/core/page/memory-reader.js +299 -0
  134. package/dist/core/page/ops.d.ts +58 -0
  135. package/dist/core/page/ops.js +220 -0
  136. package/dist/core/page/page-host.d.ts +20 -0
  137. package/dist/core/page/page-host.js +57 -0
  138. package/dist/core/page/records-query.d.ts +234 -0
  139. package/dist/core/page/records-query.js +780 -0
  140. package/dist/core/page/render.d.ts +295 -0
  141. package/dist/core/page/render.js +1060 -0
  142. package/dist/core/page/sandbox.d.ts +85 -0
  143. package/dist/core/page/sandbox.js +357 -0
  144. package/dist/core/page/time-format.d.ts +46 -0
  145. package/dist/core/page/time-format.js +125 -0
  146. package/dist/core/page/timeline.d.ts +40 -0
  147. package/dist/core/page/timeline.js +2 -0
  148. package/dist/core/page/typed.d.ts +648 -0
  149. package/dist/core/page/typed.js +2 -0
  150. package/dist/core/page/workspace.d.ts +57 -0
  151. package/dist/core/page/workspace.js +266 -0
  152. package/dist/core/party/index.d.ts +3 -0
  153. package/dist/core/party/index.js +3 -0
  154. package/dist/core/party/schema.d.ts +208 -0
  155. package/dist/core/party/schema.js +113 -0
  156. package/dist/core/party/types.d.ts +35 -0
  157. package/dist/core/party/types.js +15 -0
  158. package/dist/core/sequence/define.d.ts +56 -0
  159. package/dist/core/sequence/define.js +10 -0
  160. package/dist/core/sequence/index.d.ts +63 -0
  161. package/dist/core/sequence/index.js +231 -0
  162. package/dist/core/slot/binding.d.ts +40 -0
  163. package/dist/core/slot/binding.js +2 -0
  164. package/dist/core/slot/company-metadata.d.ts +102 -0
  165. package/dist/core/slot/company-metadata.js +536 -0
  166. package/dist/core/slot/compile-schema.d.ts +19 -13
  167. package/dist/core/slot/compile-schema.js +51 -248
  168. package/dist/core/slot/contact-timezone.d.ts +110 -0
  169. package/dist/core/slot/contact-timezone.js +186 -0
  170. package/dist/core/slot/field.d.ts +2 -25
  171. package/dist/core/slot/field.js +0 -71
  172. package/dist/core/slot/id-ref.d.ts +17 -2
  173. package/dist/core/slot/id-ref.js +16 -8
  174. package/dist/core/slot/index.d.ts +12 -13
  175. package/dist/core/slot/index.js +11 -12
  176. package/dist/core/slot/naming.d.ts +15 -0
  177. package/dist/core/slot/naming.js +96 -0
  178. package/dist/core/slot/platform-fields.d.ts +119 -0
  179. package/dist/core/slot/platform-fields.js +121 -0
  180. package/dist/core/slot/ref.d.ts +16 -0
  181. package/dist/core/slot/ref.js +14 -0
  182. package/dist/core/slot/row.d.ts +2 -9
  183. package/dist/core/slot/row.js +13 -23
  184. package/dist/core/slot/schema-compat.d.ts +17 -0
  185. package/dist/core/slot/schema-compat.js +103 -0
  186. package/dist/core/slot/schema.d.ts +353 -76
  187. package/dist/core/slot/schema.js +163 -10
  188. package/dist/core/slot/types.d.ts +30 -103
  189. package/dist/core/slot/value.d.ts +28 -3
  190. package/dist/core/slot/value.js +93 -57
  191. package/dist/dev-overlay/protocol.d.ts +74 -8
  192. package/dist/fn-context/build-context.d.ts +3 -1
  193. package/dist/fn-context/build-context.js +26 -10
  194. package/dist/fn-context/fake/empty-api.js +9 -28
  195. package/dist/fn-context/fake/index.d.ts +13 -4
  196. package/dist/fn-context/fake/index.js +29 -2
  197. package/dist/fn-context/fn-params.d.ts +3 -0
  198. package/dist/fn-context/fn-params.js +10 -0
  199. package/dist/fn-context/index.d.ts +5 -5
  200. package/dist/fn-context/index.js +4 -4
  201. package/dist/fn-context/log.js +2 -2
  202. package/dist/fn-context/make-ctx.d.ts +11 -0
  203. package/dist/fn-context/make-ctx.js +20 -9
  204. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
  205. package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
  206. package/dist/fn-context/rpc/errors.d.ts +13 -0
  207. package/dist/fn-context/rpc/errors.js +22 -0
  208. package/dist/fn-context/rpc/index.d.ts +4 -2
  209. package/dist/fn-context/rpc/index.js +4 -2
  210. package/dist/fn-context/rpc/integration/index.d.ts +15 -5
  211. package/dist/fn-context/rpc/integration/index.js +1 -1
  212. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  213. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  214. package/dist/fn-context/rpc/log.d.ts +11 -1
  215. package/dist/fn-context/rpc/platform.d.ts +13 -3
  216. package/dist/fn-context/rpc/platform.js +1 -1
  217. package/dist/fn-context/rpc/records.d.ts +85 -0
  218. package/dist/fn-context/rpc/records.js +24 -0
  219. package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
  220. package/dist/fn-context/rpc/trpc-client.js +222 -12
  221. package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
  222. package/dist/fn-context/rpc/trpc-init.js +10 -4
  223. package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
  224. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  225. package/dist/fn-context/run-scope.d.ts +4 -0
  226. package/dist/fn-context/run-scope.js +9 -0
  227. package/dist/fn-context/types.d.ts +52 -5
  228. package/dist/index.d.ts +36 -46
  229. package/dist/index.js +30 -33
  230. package/dist/logger.d.ts +11 -0
  231. package/dist/logger.js +49 -0
  232. package/dist/platform.d.ts +75 -0
  233. package/dist/platform.js +57 -0
  234. package/dist/testing-compile-child.d.ts +2 -0
  235. package/dist/testing-compile-child.js +20 -0
  236. package/dist/testing.d.ts +368 -0
  237. package/dist/testing.js +439 -0
  238. package/dist/voice-service/actions.d.ts +50 -6
  239. package/dist/voice-service/index.d.ts +2 -0
  240. package/dist/voice-service/index.js +2 -0
  241. package/dist/voice-service/protocol.d.ts +604 -0
  242. package/dist/voice-service/protocol.js +67 -0
  243. package/dist/voice-service/types.d.ts +55 -8
  244. package/dist/worker.d.ts +11 -0
  245. package/dist/worker.js +11 -0
  246. package/package.json +38 -15
  247. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  248. package/dist/builder/compile/compile-agenda.js +0 -64
  249. package/dist/builder/merge.d.ts +0 -4
  250. package/dist/builder/merge.js +0 -19
  251. package/dist/compute-host/read-only-cache.d.ts +0 -20
  252. package/dist/compute-host/read-only-cache.js +0 -61
  253. package/dist/core/context/db.d.ts +0 -69
  254. package/dist/core/context/db.js +0 -44
  255. package/dist/core/context/docusign.d.ts +0 -134
  256. package/dist/core/context/docusign.js +0 -108
  257. package/dist/core/context/filevine.d.ts +0 -323
  258. package/dist/core/context/filevine.js +0 -254
  259. package/dist/core/context/http.d.ts +0 -9
  260. package/dist/core/context/http.js +0 -4
  261. package/dist/core/context/hubspot.d.ts +0 -250
  262. package/dist/core/context/hubspot.js +0 -191
  263. package/dist/core/context/twilio.d.ts +0 -50
  264. package/dist/core/context/twilio.js +0 -42
  265. package/dist/core/functions/define/case-context.d.ts +0 -14
  266. package/dist/core/functions/define/case-context.js +0 -15
  267. package/dist/core/functions/define/compute.d.ts +0 -7
  268. package/dist/core/functions/define/compute.js +0 -17
  269. package/dist/core/functions/define/custom.d.ts +0 -4
  270. package/dist/core/functions/define/custom.js +0 -8
  271. package/dist/core/functions/define/system.d.ts +0 -7
  272. package/dist/core/functions/define/system.js +0 -12
  273. package/dist/core/functions/func-ref.d.ts +0 -16
  274. package/dist/core/functions/func-ref.js +0 -20
  275. package/dist/core/slot/deps.d.ts +0 -15
  276. package/dist/core/slot/deps.js +0 -88
  277. package/dist/core/slot/derived.d.ts +0 -32
  278. package/dist/core/slot/derived.js +0 -115
  279. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  280. package/dist/core/slot/platform-session-fields.js +0 -48
  281. package/dist/core/slot/sf-schema.d.ts +0 -23
  282. package/dist/core/slot/sf-schema.js +0 -125
  283. package/dist/core/slot/sf-validate.d.ts +0 -14
  284. package/dist/core/slot/sf-validate.js +0 -132
  285. package/dist/core/slot/snapshot.d.ts +0 -18
  286. package/dist/core/slot/snapshot.js +0 -138
  287. package/dist/core/slot/write.d.ts +0 -48
  288. package/dist/core/slot/write.js +0 -426
  289. package/dist/core/stage/builders.d.ts +0 -54
  290. package/dist/core/stage/builders.js +0 -31
  291. package/dist/core/stage/condition.d.ts +0 -17
  292. package/dist/core/stage/condition.js +0 -198
  293. package/dist/core/stage/drive.d.ts +0 -43
  294. package/dist/core/stage/drive.js +0 -78
  295. package/dist/core/stage/finish-when.d.ts +0 -20
  296. package/dist/core/stage/finish-when.js +0 -82
  297. package/dist/core/stage/flatten.d.ts +0 -27
  298. package/dist/core/stage/flatten.js +0 -466
  299. package/dist/core/stage/index.d.ts +0 -15
  300. package/dist/core/stage/index.js +0 -13
  301. package/dist/core/stage/interrupts.d.ts +0 -28
  302. package/dist/core/stage/interrupts.js +0 -120
  303. package/dist/core/stage/ivr-fields.d.ts +0 -9
  304. package/dist/core/stage/ivr-fields.js +0 -75
  305. package/dist/core/stage/simulate.d.ts +0 -24
  306. package/dist/core/stage/simulate.js +0 -33
  307. package/dist/core/stage/transfer-fields.d.ts +0 -19
  308. package/dist/core/stage/transfer-fields.js +0 -129
  309. package/dist/core/stage/transfer-spec.d.ts +0 -48
  310. package/dist/core/stage/transfer-spec.js +0 -113
  311. package/dist/core/stage/types.d.ts +0 -208
  312. package/dist/core/stage/types.js +0 -2
  313. package/dist/core/stage/validate.d.ts +0 -11
  314. package/dist/core/stage/validate.js +0 -330
  315. package/dist/core/stage/walk.d.ts +0 -39
  316. package/dist/core/stage/walk.js +0 -119
  317. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  318. package/dist/fn-context/system-args.d.ts +0 -6
  319. package/dist/fn-context/system-args.js +0 -14
@@ -1,10 +1,16 @@
1
1
  import type { ActionDataSlice } from '../fn-context/types.js';
2
- import type { SequenceBuild } from '../builder/types.js';
2
+ import type { CompanyBuild, SourceMaps } from '../builder/types.js';
3
+ import type { ComputeInvocation } from '../compute-host/compute-host.js';
4
+ /**
5
+ * Serve takes the whole environment (22-sequence-as-business-unit §6): while a session holds it, every
6
+ * sequence there runs the local repository's code, and one with no local directory has none.
7
+ */
3
8
  export type OverlayAuthMessage = {
4
9
  type: 'auth';
5
- apiKey: string;
6
- companyId: string;
7
- names?: string[];
10
+ /** Browser-issued, serve-scoped token. */
11
+ token: string;
12
+ /** Required environment id. */
13
+ environment?: string;
8
14
  };
9
15
  export type OverlayAuthOkMessage = {
10
16
  type: 'auth.ok';
@@ -12,29 +18,74 @@ export type OverlayAuthOkMessage = {
12
18
  export type OverlayAuthErrorMessage = {
13
19
  type: 'auth.error';
14
20
  error: string;
21
+ /**
22
+ * No default on the sending side — every send site picks one explicitly (see gateway-state.ts's
23
+ * `rejectAuth` and gateway-connection.ts's `failAuth`), so a future call site can't silently
24
+ * inherit the wrong one. The CLI (`toOverlayError` in packages/runtime/src/cli/serve/index.ts)
25
+ * maps each code to how it reacts.
26
+ * `authorization`: the serve token is invalid/expired, or a heartbeat found the user's access to
27
+ * the company was revoked — re-authenticate and retry.
28
+ * `unavailable`: a transient condition (infra hiccup, an unexpected internal error, a lease that
29
+ * was just replaced) — retry with backoff, no user action needed.
30
+ * `request`: the request itself is permanently invalid (missing or unknown environment, prod) —
31
+ * retrying the same request will never succeed; stop and tell the user.
32
+ */
33
+ code: 'authorization' | 'unavailable' | 'request';
15
34
  };
35
+ /** Another serve took the environment: this session ends. */
16
36
  export type OverlayReplacedMessage = {
17
37
  type: 'replaced';
18
38
  };
19
39
  export declare const OVERLAY_REPLACED_CLOSE_CODE = 4000;
40
+ /**
41
+ * Informational only: the session keeps serving. Sent e.g. when the pushed company schema is not
42
+ * backward compatible with this environment's or prod's live release.
43
+ */
44
+ /**
45
+ * The push of `generation` is served: registered, so every api instance runs it from now on. Sent after
46
+ * each push; a client may wait for it before it calls anything that should run the pushed code.
47
+ */
48
+ export type OverlayOkMessage = {
49
+ type: 'overlay.ok';
50
+ generation: number;
51
+ };
52
+ export type OverlayNoticeMessage = {
53
+ type: 'notice';
54
+ message: string;
55
+ details: string[];
56
+ };
57
+ /** The local company build, every sequence of the repository; each push replaces the previous one. */
20
58
  export type OverlayPushMessage = {
21
59
  type: 'overlay';
22
- sequenceId: string;
23
60
  generation: number;
24
- build: SequenceBuild;
61
+ /** `build.company.schema` is compiled from the local `schema/`; the backend uses it while serving. */
62
+ build: CompanyBuild;
63
+ /**
64
+ * Source maps of the code serve hands the backend to run (its page scripts), by `functionKey`: a page's
65
+ * failure is shown on the repository's own files with them.
66
+ */
67
+ sourceMaps?: SourceMaps;
25
68
  };
26
69
  export type OverlayExecuteMessage = {
27
70
  type: 'execute';
28
71
  requestId: string;
72
+ /** The sequence's directory name. */
29
73
  sequenceId: string;
30
74
  name: string;
31
- args?: unknown[];
75
+ invocation?: ComputeInvocation;
32
76
  data?: ActionDataSlice;
33
77
  runToken?: string;
34
78
  /** Logger request id for `ctx.api` RPC; not the overlay execute correlation id. */
35
79
  logRequestId?: string;
36
80
  /** Logger tags inherited from the backend execution context. */
37
81
  logTags?: string[];
82
+ /**
83
+ * Epoch ms after which the backend no longer waits for this request: serve does not start it then, so
84
+ * a request reported as failed never runs later. Set once by the process that started the call, by the
85
+ * backend's clock; serve compares it with its own, which assumes the two agree (NTP) to well within the
86
+ * execute timeout.
87
+ */
88
+ deadline: number;
38
89
  };
39
90
  export type OverlayExecuteResultMessage = {
40
91
  type: 'execute.result';
@@ -46,9 +97,24 @@ export type OverlayExecuteResultMessage = {
46
97
  requestId: string;
47
98
  ok: false;
48
99
  error: string;
100
+ /**
101
+ * Where it failed: the error's first line and the frames of the repository's own files, by their
102
+ * path from its root (the company's logs show it). Absent when the error had no stack.
103
+ */
104
+ stack?: string;
105
+ /**
106
+ * Nothing of the company's ran (expired before it started, an unknown sequence): the platform's
107
+ * failure, not the company's code's (67 §4.1).
108
+ */
109
+ notStarted?: true;
110
+ /**
111
+ * The code failed on a `PlatformUnavailableError` it did not catch (74 §3.2): the platform's failure,
112
+ * not the company's code's.
113
+ */
114
+ platform?: true;
49
115
  };
50
116
  export type OverlayClientMessage = OverlayAuthMessage | OverlayPushMessage | OverlayExecuteResultMessage;
51
- export type OverlayServerMessage = OverlayAuthOkMessage | OverlayAuthErrorMessage | OverlayReplacedMessage | OverlayExecuteMessage;
117
+ export type OverlayServerMessage = OverlayAuthOkMessage | OverlayAuthErrorMessage | OverlayReplacedMessage | OverlayExecuteMessage | OverlayNoticeMessage | OverlayOkMessage;
52
118
  export type OverlayMessage = OverlayClientMessage | OverlayServerMessage;
53
119
  export declare function encodeOverlayMessage(message: OverlayMessage): string;
54
120
  export declare function parseOverlayMessage(raw: string): OverlayMessage;
@@ -1,4 +1,4 @@
1
- import type { ActionContext, ActionDataSlice, ApiHost, RunScope } from './types.js';
1
+ import type { ActionContext, ActionDataSlice, ApiHost, CaseOrchestratorActionContext, CaseOrchestratorApiHost, RunScope } from './types.js';
2
2
  export type BuildActionContextOptions = {
3
3
  /** Defaults from `data.meta` when omitted. */
4
4
  run?: Partial<RunScope>;
@@ -8,4 +8,6 @@ export type BuildActionContextOptions = {
8
8
  * Shared by local unit, remote-fc, and (later) Worker-side invoke.
9
9
  */
10
10
  export declare function buildActionContext(data: ActionDataSlice, host: ApiHost, options?: BuildActionContextOptions): Promise<ActionContext>;
11
+ /** Assemble the `orchestrator` ctx (without `params`), its api from the host. */
12
+ export declare function buildCaseOrchestratorContext(data: ActionDataSlice, host: CaseOrchestratorApiHost, options?: BuildActionContextOptions): Promise<CaseOrchestratorActionContext>;
11
13
  //# sourceMappingURL=build-context.d.ts.map
@@ -1,21 +1,37 @@
1
1
  import { bindLogMeta } from './log.js';
2
- /**
3
- * Assemble ActionContext = JSON data slice + api from ApiHost.
4
- * Shared by local unit, remote-fc, and (later) Worker-side invoke.
5
- */
6
- export async function buildActionContext(data, host, options = {}) {
7
- const run = {
2
+ import { dayIn, formatTime, timeAt, timeParts } from '../core/page/time-format.js';
3
+ /** A run in an environment that is not being tested (68 §6.2): every contact hour holds. */
4
+ const NOTHING_IGNORED = Object.freeze({ contactHours: false, contactSchedule: false });
5
+ function resolveRunScope(data, options) {
6
+ return {
8
7
  companyId: options.run?.companyId ?? data.meta.companyId,
9
8
  environmentId: options.run?.environmentId ?? data.meta.environmentId,
10
- sequenceId: options.run?.sequenceId ?? data.meta.sequenceId,
11
9
  entry: options.run?.entry ?? data.meta.entry,
12
10
  };
13
- const api = await host.buildApi(run);
11
+ }
12
+ /** What the call brought for the api, besides the context: the integrations the platform listed. */
13
+ function given(data) {
14
+ return data.surfaces ? { surfaces: data.surfaces } : {};
15
+ }
16
+ function assembleContext(data, meta, api) {
14
17
  return {
15
- time: data.time,
16
- meta: data.meta,
18
+ time: { ...data.time, ignore: data.time.ignore ?? NOTHING_IGNORED, format: formatTime, day: dayIn, at: timeAt, parts: timeParts },
19
+ meta,
17
20
  config: data.config,
18
21
  api: { ...api, log: bindLogMeta(api.log, data.meta) },
19
22
  };
20
23
  }
24
+ /**
25
+ * Assemble ActionContext = JSON data slice + api from ApiHost.
26
+ * Shared by local unit, remote-fc, and (later) Worker-side invoke.
27
+ */
28
+ export async function buildActionContext(data, host, options = {}) {
29
+ const api = await host.buildApi(resolveRunScope(data, options), given(data));
30
+ return assembleContext(data, data.meta, api);
31
+ }
32
+ /** Assemble the `orchestrator` ctx (without `params`), its api from the host. */
33
+ export async function buildCaseOrchestratorContext(data, host, options = {}) {
34
+ const api = await host.buildCaseOrchestratorApi(resolveRunScope(data, options), given(data));
35
+ return assembleContext(data, data.meta, api);
36
+ }
21
37
  //# sourceMappingURL=build-context.js.map
@@ -1,43 +1,24 @@
1
1
  import { platformSurfaces } from '../../core/context/platform-registry.js';
2
- import { docusignMockService } from '../../core/context/docusign.js';
2
+ import { emailMockService } from '../../core/context/email.js';
3
3
  import { envMockService } from '../../core/context/env.js';
4
- import { filevineMockService } from '../../core/context/filevine.js';
5
- import { hubspotMockService } from '../../core/context/hubspot.js';
6
- import { twilioMockService } from '../../core/context/twilio.js';
7
- const MOCK_HUBSPOT_TARGET = { kind: 'account', id: 'mock-hubspot-main' };
8
- const MOCK_TWILIO_TARGET = { kind: 'account', id: 'mock-twilio-main' };
9
- const MOCK_FILEVINE_TARGET = { kind: 'account', id: 'mock-filevine-main' };
10
- const MOCK_DOCUSIGN_TARGET = { kind: 'account', id: 'mock-docusign-main' };
11
4
  const MOCK_ENV_TARGET = { kind: 'account', id: 'mock-env-main' };
5
+ const MOCK_EMAIL_TARGET = { kind: 'resource', id: 'mock-email-main' };
12
6
  function mockAccount(target, name) {
13
7
  return { target, name, credentials: {}, config: {} };
14
8
  }
15
- const hubspotStub = {
16
- ...mockAccount(MOCK_HUBSPOT_TARGET, 'main'),
17
- ...hubspotMockService,
18
- };
19
- const twilioStub = {
20
- ...mockAccount(MOCK_TWILIO_TARGET, 'main'),
21
- ...twilioMockService,
22
- };
23
- const filevineStub = {
24
- ...mockAccount(MOCK_FILEVINE_TARGET, 'main'),
25
- ...filevineMockService,
26
- };
27
- const docusignStub = {
28
- ...mockAccount(MOCK_DOCUSIGN_TARGET, 'main'),
29
- ...docusignMockService,
30
- };
31
9
  const envStub = {
32
10
  ...mockAccount(MOCK_ENV_TARGET, 'main'),
33
11
  ...envMockService,
34
12
  };
13
+ const emailStub = {
14
+ ...mockAccount(MOCK_EMAIL_TARGET, 'intake@example.com'),
15
+ address: 'intake@example.com',
16
+ provider: 'gmail',
17
+ ...emailMockService,
18
+ };
35
19
  export const emptyIntegration = () => ({
36
- hubspots: [hubspotStub],
37
- twilios: [twilioStub],
38
- filevines: [filevineStub],
39
- docusigns: [docusignStub],
40
20
  envs: [envStub],
21
+ emails: [emailStub],
41
22
  });
42
23
  /** Each registered surface backed by its mock, with per-method overrides applied on top. */
43
24
  export const defaultPlatformApis = (overrides = {}) => {
@@ -1,12 +1,21 @@
1
+ import { type CaseOrchestratorTools } from '../../core/case-orchestrator/types.js';
1
2
  import type { IntegrationApi, Logger } from '../../core/context/types.js';
2
- import { type HttpApi } from '../../core/context/http.js';
3
- import type { ApiHost } from '../types.js';
3
+ import type { Db } from '../../core/page/define.js';
4
+ import type { ApiHost, CaseOrchestratorApiHost } from '../types.js';
4
5
  import { type PlatformApiOverrides } from './empty-api.js';
5
6
  export type FakeApiHostOptions = PlatformApiOverrides & {
6
7
  integration?: Partial<IntegrationApi>;
7
8
  log?: Logger;
8
- http?: Partial<HttpApi>;
9
+ /** Case Orchestrator tools; a tool left out rejects when called. */
10
+ tools?: Partial<CaseOrchestratorTools>;
11
+ /** `ctx.api.db`; left out, every call rejects. */
12
+ db?: Db;
9
13
  };
14
+ /** Every table, every method: rejects when called (`what` names it in the error). */
15
+ /** A stand-in whose every call rejects, saying it is not faked. */
16
+ export declare function unfaked<T extends object>(what: string): T;
17
+ /** `ctx.api.tools` for fake contexts: a tool left out rejects when called. */
18
+ export declare function fakeTools(overrides?: Partial<CaseOrchestratorTools>): CaseOrchestratorTools;
10
19
  /** In-process ApiHost for local unit tests (`makeCtx` uses this). */
11
- export declare function createFakeApiHost(options?: FakeApiHostOptions): ApiHost;
20
+ export declare function createFakeApiHost(options?: FakeApiHostOptions): ApiHost & CaseOrchestratorApiHost;
12
21
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,28 @@
1
- import { defaultHttpApi } from '../../core/context/http.js';
1
+ import { CASE_ORCHESTRATOR_TOOL_NAMES } from '../../core/case-orchestrator/types.js';
2
2
  import { noopLog } from '../log.js';
3
3
  import { defaultPlatformApis, emptyIntegration } from './empty-api.js';
4
+ /** Every table, every method: rejects when called (`what` names it in the error). */
5
+ /** A stand-in whose every call rejects, saying it is not faked. */
6
+ export function unfaked(what) {
7
+ return new Proxy({}, {
8
+ get: (_, table) => new Proxy({}, {
9
+ get: (__, method) => async () => {
10
+ throw new Error(`FakeApiHost: ${what}.${String(table)}.${String(method)} is not faked`);
11
+ },
12
+ }),
13
+ });
14
+ }
15
+ /** `ctx.api.tools` for fake contexts: a tool left out rejects when called. */
16
+ export function fakeTools(overrides = {}) {
17
+ const tools = CASE_ORCHESTRATOR_TOOL_NAMES.map((tool) => [
18
+ tool,
19
+ overrides[tool] ??
20
+ (async () => {
21
+ throw new Error(`FakeApiHost: tools.${tool} is not faked`);
22
+ }),
23
+ ]);
24
+ return Object.fromEntries(tools);
25
+ }
4
26
  /** In-process ApiHost for local unit tests (`makeCtx` uses this). */
5
27
  export function createFakeApiHost(options = {}) {
6
28
  const integration = {
@@ -11,12 +33,17 @@ export function createFakeApiHost(options = {}) {
11
33
  ...defaultPlatformApis(options),
12
34
  integration,
13
35
  log: options.log ?? noopLog,
14
- http: { ...defaultHttpApi(), ...options.http },
36
+ db: options.db ?? unfaked('db'),
37
+ // Every function's (38 §2.7).
38
+ tools: fakeTools(options.tools),
15
39
  };
16
40
  return {
17
41
  async buildApi() {
18
42
  return api;
19
43
  },
44
+ async buildCaseOrchestratorApi() {
45
+ return api;
46
+ },
20
47
  };
21
48
  }
22
49
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ /** A function's `args` (38 §2.1): an object, `{}` when the caller gave none. */
2
+ export declare function resolveFnParams(args: unknown): object;
3
+ //# sourceMappingURL=fn-params.d.ts.map
@@ -0,0 +1,10 @@
1
+ /** A function's `args` (38 §2.1): an object, `{}` when the caller gave none. */
2
+ export function resolveFnParams(args) {
3
+ if (args == null)
4
+ return {};
5
+ if (typeof args !== 'object' || Array.isArray(args)) {
6
+ throw new Error('function args must be an object');
7
+ }
8
+ return args;
9
+ }
10
+ //# sourceMappingURL=fn-params.js.map
@@ -1,10 +1,10 @@
1
- export type { ActionContext, ActionDataSlice, ApiHost, RunScope } from './types.js';
2
- export { buildActionContext, type BuildActionContextOptions } from './build-context.js';
3
- export { resolveSystemFnParams } from './system-args.js';
1
+ export type { ActionContext, ActionDataSlice, ApiGiven, ApiHost, CaseOrchestratorActionContext, CaseOrchestratorApiHost, CaseOrchestratorRunScope, RunClaims, RunScope, } from './types.js';
2
+ export { buildActionContext, buildCaseOrchestratorContext, type BuildActionContextOptions, } from './build-context.js';
3
+ export { asCaseOrchestratorRun } from './run-scope.js';
4
+ export { resolveFnParams } from './fn-params.js';
4
5
  export { createFakeApiHost, type FakeApiHostOptions } from './fake/index.js';
5
6
  export { defaultPlatformApis, emptyIntegration, type PlatformApiOverrides } from './fake/empty-api.js';
6
7
  export { createRpcApiHost, LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './rpc/index.js';
7
8
  export { bindLogMeta, noopLog } from './log.js';
8
- export { makeCtx, makeCtxAsync } from './make-ctx.js';
9
- export { defaultHttpApi } from '../core/context/http.js';
9
+ export { makeCaseOrchestratorCtx, makeCtx, makeCtxAsync } from './make-ctx.js';
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,9 @@
1
- export { buildActionContext } from './build-context.js';
2
- export { resolveSystemFnParams } from './system-args.js';
1
+ export { buildActionContext, buildCaseOrchestratorContext, } from './build-context.js';
2
+ export { asCaseOrchestratorRun } from './run-scope.js';
3
+ export { resolveFnParams } from './fn-params.js';
3
4
  export { createFakeApiHost } from './fake/index.js';
4
5
  export { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
5
6
  export { createRpcApiHost, LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './rpc/index.js';
6
7
  export { bindLogMeta, noopLog } from './log.js';
7
- export { makeCtx, makeCtxAsync } from './make-ctx.js';
8
- export { defaultHttpApi } from '../core/context/http.js';
8
+ export { makeCaseOrchestratorCtx, makeCtx, makeCtxAsync } from './make-ctx.js';
9
9
  //# sourceMappingURL=index.js.map
@@ -4,9 +4,9 @@ export const noopLog = {
4
4
  error: () => { },
5
5
  };
6
6
  /** Identity fields that LogContext already stores first-class (mars ctx). */
7
- const CONTEXT_KEYS = ['companyId', 'sequenceId', 'contactId'];
7
+ const CONTEXT_KEYS = ['companyId', 'sequenceId'];
8
8
  /** Remaining SystemContext.meta fields; carried on log extra. */
9
- const EXTRA_META_KEYS = ['environmentId', 'entry', 'caseId'];
9
+ const EXTRA_META_KEYS = ['environmentId', 'entry', 'instanceId'];
10
10
  /**
11
11
  * Stamp every `ctx.api.log` call with SystemContext.meta. First-class ids stay
12
12
  * on extra so RpcApiHost can send them; the backend lifts them into LogContext.
@@ -1,4 +1,7 @@
1
+ import type { CaseOrchestratorTools } from '../core/case-orchestrator/types.js';
1
2
  import type { MakeCtxOverrides, SystemContext } from '../core/context/types.js';
3
+ import type { Db } from '../core/page/define.js';
4
+ import type { CaseOrchestratorActionContext } from './types.js';
2
5
  /**
3
6
  * Build a fake SystemContext for local unit tests.
4
7
  * Uses {@link createFakeApiHost}; sync because FakeApiHost has no I/O.
@@ -6,4 +9,12 @@ import type { MakeCtxOverrides, SystemContext } from '../core/context/types.js';
6
9
  export declare function makeCtx(overrides?: MakeCtxOverrides): SystemContext;
7
10
  /** Async makeCtx via {@link buildActionContext} + FakeApiHost (same result as {@link makeCtx}). */
8
11
  export declare function makeCtxAsync(overrides?: MakeCtxOverrides): Promise<SystemContext>;
12
+ /**
13
+ * Fake `orchestrator` ctx (without `params`) for local unit tests: `tools` fakes `ctx.api.tools`,
14
+ * `db` fakes `ctx.api.db` (left out, every call rejects).
15
+ */
16
+ export declare function makeCaseOrchestratorCtx(overrides?: MakeCtxOverrides & {
17
+ tools?: Partial<CaseOrchestratorTools>;
18
+ db?: Db;
19
+ }): Promise<CaseOrchestratorActionContext>;
9
20
  //# sourceMappingURL=make-ctx.d.ts.map
@@ -1,21 +1,20 @@
1
- import { defaultHttpApi } from '../core/context/http.js';
2
- import { buildActionContext } from './build-context.js';
3
- import { createFakeApiHost } from './fake/index.js';
1
+ import { buildActionContext, buildCaseOrchestratorContext } from './build-context.js';
2
+ import { createFakeApiHost, fakeTools, unfaked } from './fake/index.js';
4
3
  import { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
5
4
  import { bindLogMeta, noopLog } from './log.js';
5
+ import { dayIn, formatTime, timeAt, timeParts } from '../core/page/time-format.js';
6
6
  function toDataSlice(overrides) {
7
7
  const timezone = overrides.timezone ?? 'UTC';
8
8
  const today = overrides.today ?? '1970-01-01';
9
9
  const now = overrides.now ?? Date.parse(`${today}T00:00:00.000Z`);
10
10
  return {
11
- time: { now, timezone, today },
11
+ time: { now, timezone, today, ignore: overrides.ignore ?? { contactHours: false, contactSchedule: false } },
12
12
  meta: {
13
13
  companyId: 'company',
14
14
  environmentId: 'sandbox',
15
15
  sequenceId: 'sequence',
16
16
  entry: 'test',
17
- contactId: 'contact',
18
- caseId: 'case',
17
+ instanceId: 'instance',
19
18
  ...overrides.meta,
20
19
  },
21
20
  config: {
@@ -35,9 +34,10 @@ export function makeCtx(overrides = {}) {
35
34
  ...defaultPlatformApis(overrides.api),
36
35
  integration: { ...emptyIntegration(), ...overrides.api?.integration },
37
36
  log: bindLogMeta(overrides.api?.log ?? noopLog, data.meta),
38
- http: { ...defaultHttpApi(), ...overrides.api?.http },
37
+ db: overrides.api?.db ?? unfaked('db'),
38
+ tools: fakeTools(overrides.api?.tools),
39
39
  };
40
- return { ...data, api };
40
+ return { ...data, meta: data.meta, time: { ...data.time, ignore: data.time.ignore ?? { contactHours: false, contactSchedule: false }, format: formatTime, day: dayIn, at: timeAt, parts: timeParts }, api };
41
41
  }
42
42
  /** Async makeCtx via {@link buildActionContext} + FakeApiHost (same result as {@link makeCtx}). */
43
43
  export async function makeCtxAsync(overrides = {}) {
@@ -45,7 +45,18 @@ export async function makeCtxAsync(overrides = {}) {
45
45
  ...overrides.api,
46
46
  integration: overrides.api?.integration,
47
47
  log: overrides.api?.log,
48
- http: overrides.api?.http,
48
+ }));
49
+ }
50
+ /**
51
+ * Fake `orchestrator` ctx (without `params`) for local unit tests: `tools` fakes `ctx.api.tools`,
52
+ * `db` fakes `ctx.api.db` (left out, every call rejects).
53
+ */
54
+ export async function makeCaseOrchestratorCtx(overrides = {}) {
55
+ return buildCaseOrchestratorContext(toDataSlice({ ...overrides, meta: { entry: 'orchestrator', ...overrides.meta } }), createFakeApiHost({
56
+ ...overrides.api,
57
+ log: overrides.api?.log,
58
+ tools: overrides.tools,
59
+ db: overrides.db,
49
60
  }));
50
61
  }
51
62
  //# sourceMappingURL=make-ctx.js.map
@@ -0,0 +1,32 @@
1
+ import { type RpcContext } from './trpc-init.js';
2
+ export type CaseOrchestratorToolInvokeHandler = (input: {
3
+ tool: string;
4
+ input: unknown;
5
+ ctx: RpcContext;
6
+ }) => Promise<unknown>;
7
+ export declare function createCaseOrchestratorToolsRouter(invoke: CaseOrchestratorToolInvokeHandler): import("@trpc/server").TRPCBuiltRouter<{
8
+ ctx: RpcContext;
9
+ meta: object;
10
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape | {
11
+ message: string;
12
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
13
+ data: {
14
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
15
+ httpStatus: number;
16
+ path?: string;
17
+ stack?: string;
18
+ reason: string;
19
+ };
20
+ };
21
+ transformer: false;
22
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
23
+ invoke: import("@trpc/server").TRPCMutationProcedure<{
24
+ input: {
25
+ tool: string;
26
+ input: unknown;
27
+ };
28
+ output: unknown;
29
+ meta: object;
30
+ }>;
31
+ }>>;
32
+ //# sourceMappingURL=case-orchestrator-tools.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ import { publicProcedure, router } from './trpc-init.js';
3
+ const invokeInput = z.object({
4
+ tool: z.string().min(1),
5
+ input: z.unknown(),
6
+ });
7
+ export function createCaseOrchestratorToolsRouter(invoke) {
8
+ return router({
9
+ invoke: publicProcedure.input(invokeInput).mutation(({ ctx, input }) => invoke({ ...input, ctx })),
10
+ });
11
+ }
12
+ //# sourceMappingURL=case-orchestrator-tools.js.map
@@ -22,4 +22,17 @@ export declare class ScriptInputError extends Error implements RpcCodedError {
22
22
  });
23
23
  }
24
24
  export declare function parseScriptInput<S extends z.ZodType>(schema: S, input: unknown): z.infer<S>;
25
+ /**
26
+ * The business code a refused call carries to company code as `error.code` (`subject_busy`, `run_ended`, a
27
+ * write's code, 13 §16.3 item 8): the message reads `<reason>: <message>` for people, and the reason travels
28
+ * apart from it (`data.reason`), so `catch (error) { if (error.code === 'subject_busy') … }` works (64 §12).
29
+ */
30
+ export declare class RpcReasonError extends Error {
31
+ readonly reason: string;
32
+ constructor(reason: string, message: string);
33
+ }
34
+ /** A refusal with the HTTP-like `code` tRPC answers with and the business `reason` the caller sees. */
35
+ export declare function reasonError(code: RpcErrorCode, reason: string, message: string): TRPCError;
36
+ /** The business reason a server error carries, if any. */
37
+ export declare function rpcErrorReason(error: unknown): string | undefined;
25
38
  //# sourceMappingURL=errors.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { TRPCError } from '@trpc/server';
1
2
  export function isRpcCodedError(error) {
2
3
  return error instanceof Error && typeof error.rpcCode === 'string';
3
4
  }
@@ -20,4 +21,25 @@ export function parseScriptInput(schema, input) {
20
21
  }
21
22
  return parsed.data;
22
23
  }
24
+ /**
25
+ * The business code a refused call carries to company code as `error.code` (`subject_busy`, `run_ended`, a
26
+ * write's code, 13 §16.3 item 8): the message reads `<reason>: <message>` for people, and the reason travels
27
+ * apart from it (`data.reason`), so `catch (error) { if (error.code === 'subject_busy') … }` works (64 §12).
28
+ */
29
+ export class RpcReasonError extends Error {
30
+ reason;
31
+ constructor(reason, message) {
32
+ super(message);
33
+ this.reason = reason;
34
+ this.name = 'RpcReasonError';
35
+ }
36
+ }
37
+ /** A refusal with the HTTP-like `code` tRPC answers with and the business `reason` the caller sees. */
38
+ export function reasonError(code, reason, message) {
39
+ return new TRPCError({ code, message: `${reason}: ${message}`, cause: new RpcReasonError(reason, message) });
40
+ }
41
+ /** The business reason a server error carries, if any. */
42
+ export function rpcErrorReason(error) {
43
+ return error instanceof RpcReasonError ? error.reason : undefined;
44
+ }
23
45
  //# sourceMappingURL=errors.js.map
@@ -1,10 +1,12 @@
1
1
  export { createAppRouter, type AppRouter } from './trpc-router-factory.js';
2
2
  export type { RpcContext } from './trpc-init.js';
3
- export { ScriptInputError, isRpcCodedError, parseScriptInput, type RpcCodedError, type RpcErrorCode, } from './errors.js';
3
+ export { ScriptInputError, isRpcCodedError, parseScriptInput, reasonError, RpcReasonError, type RpcCodedError, type RpcErrorCode, } from './errors.js';
4
4
  export { createIntegrationRouter, type IntegrationInvokeHandler } from './integration/index.js';
5
- export { createListBindingsProcedure } from './integration/list-bindings.js';
5
+ export { createListSurfacesProcedure } from './integration/list-surfaces.js';
6
6
  export { createPlatformRouter, type PlatformInvokeHandler } from './platform.js';
7
7
  export { createLogRouter, type LogEmitHandler } from './log.js';
8
8
  export { createRpcApiHost } from './trpc-client.js';
9
+ export { createCaseOrchestratorToolsRouter, type CaseOrchestratorToolInvokeHandler, } from './case-orchestrator-tools.js';
10
+ export { createRecordsRouter, type RecordsReadInput, type RecordsHandlers, type RecordsResult, type RecordsWriteInput, } from './records.js';
9
11
  export { LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './request-id.js';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,11 @@
1
1
  export { createAppRouter } from './trpc-router-factory.js';
2
- export { ScriptInputError, isRpcCodedError, parseScriptInput, } from './errors.js';
2
+ export { ScriptInputError, isRpcCodedError, parseScriptInput, reasonError, RpcReasonError, } from './errors.js';
3
3
  export { createIntegrationRouter } from './integration/index.js';
4
- export { createListBindingsProcedure } from './integration/list-bindings.js';
4
+ export { createListSurfacesProcedure } from './integration/list-surfaces.js';
5
5
  export { createPlatformRouter } from './platform.js';
6
6
  export { createLogRouter } from './log.js';
7
7
  export { createRpcApiHost } from './trpc-client.js';
8
+ export { createCaseOrchestratorToolsRouter, } from './case-orchestrator-tools.js';
9
+ export { createRecordsRouter, } from './records.js';
8
10
  export { LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './request-id.js';
9
11
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import type { IntegrationTarget } from '../../../core/context/types.js';
2
2
  import { type RpcContext } from '../trpc-init.js';
3
- import { createListBindingsProcedure } from './list-bindings.js';
3
+ import { createListSurfacesProcedure } from './list-surfaces.js';
4
4
  /**
5
5
  * Provider-agnostic entry point for script surfaces: the target's provider decides
6
6
  * which methods exist, so adding one never touches the RPC layer.
@@ -12,18 +12,28 @@ export type IntegrationInvokeHandler = (input: {
12
12
  ctx: RpcContext;
13
13
  }) => Promise<unknown>;
14
14
  export declare function createIntegrationRouter(modules: {
15
- listBindings: ReturnType<typeof createListBindingsProcedure>;
15
+ listSurfaces: ReturnType<typeof createListSurfacesProcedure>;
16
16
  invoke: IntegrationInvokeHandler;
17
17
  }): import("@trpc/server").TRPCBuiltRouter<{
18
18
  ctx: RpcContext;
19
19
  meta: object;
20
- errorShape: import("@trpc/server").TRPCDefaultErrorShape;
20
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape | {
21
+ message: string;
22
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
23
+ data: {
24
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
25
+ httpStatus: number;
26
+ path?: string;
27
+ stack?: string;
28
+ reason: string;
29
+ };
30
+ };
21
31
  transformer: false;
22
32
  }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
23
- listBindings: import("@trpc/server").TRPCQueryProcedure<{
33
+ listSurfaces: import("@trpc/server").TRPCQueryProcedure<{
24
34
  input: void;
25
35
  output: {
26
- surfaceKey: "docusigns" | "envs" | "filevines" | "hubspots" | "twilios";
36
+ surfaceKey: "emails" | "envs";
27
37
  target: {
28
38
  kind: "account" | "resource";
29
39
  id: string;
@@ -10,7 +10,7 @@ const integrationInvokeInput = z.object({
10
10
  });
11
11
  export function createIntegrationRouter(modules) {
12
12
  return router({
13
- listBindings: modules.listBindings,
13
+ listSurfaces: modules.listSurfaces,
14
14
  invoke: publicProcedure
15
15
  .input(integrationInvokeInput)
16
16
  .mutation(async ({ ctx, input }) => modules.invoke({ target: input.target, method: input.method, params: input.params ?? {}, ctx })),