@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
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # @superpanel-sdk/runtime
2
2
 
3
- Slot + Stage runtime used by company repos and the platform: schema, writes, derived recompute, agenda compile/walk/simulate, and company-repo CLI.
3
+ Slot + Stage runtime used by company repos and the platform: schema, writes, the page contract (`definePage`: persona, FAQ, per-channel page functions, channel actions), and company-repo CLI.
4
4
 
5
- This package is currently published as an **internal prerelease**. Install a tagged build, not `latest`:
5
+ Each prod deploy of the platform publishes the runtime it runs as `latest`:
6
6
 
7
7
  ```bash
8
- npm i @superpanel-sdk/runtime@next
8
+ npm i @superpanel-sdk/runtime
9
9
  ```
10
10
 
11
- Requires Node.js `>=20.12`.
11
+ Requires Node.js `>=22.15`.
12
12
 
13
13
  ## CLI
14
14
 
@@ -18,18 +18,38 @@ npx superpanel-sdk-runtime type:gen --watch
18
18
  npx superpanel-sdk-runtime type:gen --check
19
19
  npx superpanel-sdk-runtime compile
20
20
  npx superpanel-sdk-runtime compile --sequence <id>
21
+ npx superpanel-sdk-runtime login
22
+ npx superpanel-sdk-runtime whoami
23
+ npx superpanel-sdk-runtime logout
21
24
  npx superpanel-sdk-runtime serve
25
+ npx superpanel-sdk-runtime serve --no-open
26
+ npx superpanel-sdk-runtime serve --environment <environment-id>
22
27
  ```
23
28
 
24
- `serve` reads `.env` from the current working directory:
29
+ `login` authorizes the current user and company in the browser (device authorization flow) and caches the resulting short-lived serve credential in `~/.superpanel/credentials.json`, scoped per backend URL. `serve` first reuses a cached, unexpired credential or opens the browser to log in, then prompts for the environment. A serve takes over the whole environment: every function there runs from the local repository. Pass `--no-open` to copy a fresh authorization URL to the system clipboard instead of opening the browser automatically. Passing `--environment` skips the prompt. `whoami` prints the cached login (email, company, expiry) without touching the network; `logout` clears it.
25
30
 
26
- - `SUPERPANEL_SDK_COMPANY_ID` / `--company`
27
- - `SUPERPANEL_SDK_API_KEY` / `--api-key`
28
- - `SUPERPANEL_SDK_BACKEND_URL` / `--url`
31
+ The Backend URL belongs to the company repo, not to the runtime package. Provisioning writes the
32
+ public control-plane URL to `.superpanel/config.json`; no deployment URL is baked into registry,
33
+ tarball, or local-directory installations of this package. At run time, resolution order is:
34
+
35
+ 1. `--url <backend-url>`
36
+ 2. `SUPERPANEL_SDK_BACKEND_URL` (environment variable, checked at run time)
37
+ 3. `.superpanel/config.json` in the company repo
38
+
39
+ If none of those resolve to a valid, non-empty URL, the CLI exits with an error instead of guessing a backend.
40
+
41
+ `--environment` accepts only an environment **ID** (not a name) and must not resolve to `prod`. In an interactive terminal it may be omitted and selected after login; non-interactive invocations must pass both `--environment` and at least one `--sequence`.
29
42
 
30
43
  ## Imports
31
44
 
45
+ Company code imports the company API, and only that: `import { … } from '@superpanel-sdk/runtime'`. The
46
+ compile refuses any other import of this package (`docs/impl/09-runtime-compat.md` §6).
47
+
48
+ The platform's entries resolve only under the `superpanel-platform` condition (`customConditions` in
49
+ tsconfig, `node --conditions=superpanel-platform`, `WRANGLER_BUILD_CONDITIONS` for wrangler):
50
+
32
51
  ```ts
33
- import { makeCtx, applyWrites, createAppRouter } from '@superpanel-sdk/runtime';
34
- import { createFakeApiHost } from '@superpanel-sdk/runtime/fn-context';
52
+ import { createAppRouter, makeCtx } from '@superpanel-sdk/runtime/platform'; // the whole runtime: platform services, tests and scripts
53
+ import { buildActionContext } from '@superpanel-sdk/runtime/worker'; // the user Worker's shell
54
+ import { compileRepo } from '@superpanel-sdk/runtime/compiler'; // what the compile child loads
35
55
  ```
@@ -1,17 +1,30 @@
1
- import type { EffectiveSchema } from '../../core/slot/schema.js';
2
- /** Emit `__gen/slots.type.ts` — Slots only (no CaseContext; avoids cycle with view.ts). */
3
- export declare function emitSlotsSource(schema: EffectiveSchema): string;
1
+ import type { CompiledSlotSchema } from '../../core/slot/types.js';
4
2
  /**
5
- * Emit `__gen/case-context.type.ts`.
6
- * Separate from slots.type.ts so dependencies stay one-way:
7
- * view.ts → slots.type.ts
8
- * case-context.type.ts → view.ts | slots.type.ts
9
- * functions → case-context.type.ts
3
+ * Emit a sequence's `__gen/slots.type.ts` (28 §2.2): the company's table types come from the root
4
+ * `__gen/tables.type.ts`, the one copy every sequence shares; only the subject is the sequence's.
10
5
  */
11
- export declare function emitCaseContextSource(options: {
12
- hasCaseContextView: boolean;
13
- }): string;
6
+ export declare function emitSlotsSource(subject: string): string;
7
+ /**
8
+ * `__gen/index.ts`: the one import a sequence's page, functions and events need. Re-exports the
9
+ * generated types, the page helpers bound to the company's tables (17b, 28 §2), and the types of its
10
+ * functions and entries (`Ctx`, `Events`, `CaseOrchestrator`, `Resolve`, 38). `functionsImport` is relative to `__gen/` (`null` without a functions module),
11
+ * `actionsImport` likewise for the page actions (`actions.ts`, 76 §2.11).
12
+ * Schema-independent, so the same text serves as the stub.
13
+ */
14
+ export declare function emitGenIndexSource(functionsImport: string | null, variablesImport?: string | null, actionsImport?: string | null): string;
15
+ /**
16
+ * Emit the repository root's `__gen/tables.type.ts`: the company's tables, as the code at the root
17
+ * (`resolve.ts`, `webhook.ts`) reads and writes them with `ctx.api.db`, and as every sequence's
18
+ * `__gen` re-exports them (28 §2.2).
19
+ */
20
+ export declare function emitCompanyTablesSource(schema: CompiledSlotSchema): string;
21
+ /**
22
+ * The repository root's `__gen/index.ts`: what `resolve.ts`, `webhook.ts`, `schedules.ts` and `errors.ts` import to get
23
+ * `ctx.api.db` bound to the company's tables. Schema-independent, so the same text serves as the stub.
24
+ */
25
+ export declare function emitCompanyGenIndexSource(): string;
26
+ /** Stub written when the repository root has no gen file yet. */
27
+ export declare function emitCompanyTablesStub(): string;
14
28
  /** Stub written when a sequence has no gen file yet. */
15
29
  export declare function emitSlotsStub(): string;
16
- export declare function emitCaseContextStub(): string;
17
30
  //# sourceMappingURL=emit.d.ts.map
@@ -1,77 +1,309 @@
1
+ import { compiledTableEntries, relationsOf } from '../../core/slot/compile-schema.js';
1
2
  import { slotFieldEntries } from '../../core/slot/row.js';
2
- function quoteLiteral(v) {
3
- return typeof v === 'number' ? String(v) : JSON.stringify(v);
3
+ /** A table or field name as a property key: bare when it is an identifier, else quoted (13-data-model-v1 §23.6). */
4
+ function propKey(name) {
5
+ return /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
4
6
  }
5
7
  function dataTypeToTs(dataType) {
6
8
  switch (dataType) {
7
9
  case 'string':
10
+ case 'text':
11
+ case 'phone':
12
+ case 'email':
8
13
  case 'date':
9
14
  case 'datetime':
15
+ case 'time':
16
+ case 'select':
10
17
  return 'string';
18
+ case 'multi_select':
19
+ return 'string[]';
11
20
  case 'number':
12
21
  return 'number';
13
22
  case 'boolean':
14
23
  return 'boolean';
24
+ case 'contact_schedule':
25
+ return 'ContactSchedule';
15
26
  }
16
27
  }
28
+ /** A field's value type: a `select` one of its options, a `multi_select` a list of them. */
29
+ function baseTypeExpr(field) {
30
+ if (!field.options?.length)
31
+ return dataTypeToTs(field.dataType);
32
+ const one = field.options.map((v) => JSON.stringify(v)).join(' | ');
33
+ return field.dataType === 'multi_select' ? `Array<${one}>` : one;
34
+ }
17
35
  function valueTypeExpr(field) {
18
- let base;
19
- if (field.enum && field.enum.length > 0) {
20
- base = field.enum.map(quoteLiteral).join(' | ');
21
- }
22
- else {
23
- base = dataTypeToTs(field.dataType);
24
- }
25
36
  // Runtime envelopes always allow null on value (empty / declined / no conclusion).
26
- if (field.nullable) {
27
- return `${base} | null`;
28
- }
29
- return `${base} | null`;
37
+ return `${baseTypeExpr(field)} | null`;
30
38
  }
31
- function emitRowFields(fields) {
39
+ /**
40
+ * A cell's mode on a page (19-page-writable-cells): `'rw'` when a page may open it with `field(...)`
41
+ * (not the row id, not the parent), `'ro'` when it never can.
42
+ */
43
+ function cellMode(fieldName, field) {
44
+ return fieldName !== 'id' && field.ref?.kind !== 'parent' ? 'rw' : 'ro';
45
+ }
46
+ /**
47
+ * An `@deprecated` tag above a deprecated field in the generated `Rows` / `PageTables` types. Rows
48
+ * read and written through `db` do not carry it (typed.ts maps over its own key sets). The flag is
49
+ * only a compat-check marker and the data stays (01-slot-db §2.3): pages and functions stop using
50
+ * the field.
51
+ */
52
+ function deprecatedTag(field, indent) {
53
+ return field.deprecated ? [`${indent}/** @deprecated */`] : [];
54
+ }
55
+ function emitRowFields(tableName, fields) {
32
56
  const fieldLines = [];
33
57
  for (const [fieldName, field] of slotFieldEntries(fields)) {
34
58
  const valueTs = valueTypeExpr(field);
35
- fieldLines.push(` ${fieldName}: FieldValueBase & { value: ${valueTs} };`);
59
+ // A ref field (another row's id) is marked so a region cannot list it (13 §20.3.1).
60
+ const kind = field.ref ? 'ref' : 'value';
61
+ const binding = `CellBinding<${JSON.stringify(tableName)}, ${JSON.stringify(fieldName)}, '${cellMode(fieldName, field)}', '${kind}'>`;
62
+ fieldLines.push(...deprecatedTag(field, ' '));
63
+ fieldLines.push(` ${propKey(fieldName)}: FieldValueBase & { value: ${valueTs} } & ${binding};`);
36
64
  }
37
65
  return fieldLines;
38
66
  }
39
- function emitTableType(tableName, rows, fields) {
40
- const fieldLines = emitRowFields(fields);
41
- const rowBody = ` id: string;\n${fieldLines.join('\n')}`;
42
- if (rows === 'multi') {
43
- return ` ${tableName}: {
44
- ${rowBody}
45
- }[];`;
46
- }
47
- return ` ${tableName}: {
48
- ${rowBody}
67
+ /** The conversation's contact row is marked `$current`. */
68
+ const PARTY_TABLES = new Set(['contact']);
69
+ /** One row of a table as a view receives it (`Rows[table]`). */
70
+ function emitRowType(tableName, fields) {
71
+ const meta = [
72
+ ' id: string;',
73
+ ` $ref: RowRef<${JSON.stringify(tableName)}>;`,
74
+ ...(PARTY_TABLES.has(tableName) ? [' $current?: true;'] : []),
75
+ ];
76
+ return ` ${propKey(tableName)}: {
77
+ ${[...meta, ...emitRowFields(tableName, fields)].join('\n')}
49
78
  };`;
50
79
  }
51
- /** Emit `__gen/slots.type.ts` — Slots only (no CaseContext; avoids cycle with view.ts). */
52
- export function emitSlotsSource(schema) {
53
- const tableBlocks = [];
54
- for (const [tableName, table] of Object.entries(schema)) {
55
- tableBlocks.push(emitTableType(tableName, table.rows, table.fields));
80
+ /**
81
+ * `PageTables` (15 §10.15): table → field → its value type, for a ref the table it points at and
82
+ * whether it is the parent; and the table's ways back under `$relations` (13-data-model-v1 §23.4). What the page module's types
83
+ * (`TypedPageModule`) are bound to.
84
+ */
85
+ function emitPageTables(schema) {
86
+ const lines = [];
87
+ for (const [tableName, table] of compiledTableEntries(schema)) {
88
+ const fields = slotFieldEntries(table.fields).flatMap(([fieldName, field]) => {
89
+ const tag = deprecatedTag(field, ' ');
90
+ if (field.ref) {
91
+ const target = JSON.stringify(field.ref.table);
92
+ const parent = field.ref.kind === 'parent' ? '; parent: true' : '';
93
+ return [...tag, ` ${propKey(fieldName)}: { value: Id<${target}>; ref: ${target}${parent} };`];
94
+ }
95
+ return [...tag, ` ${propKey(fieldName)}: { value: ${baseTypeExpr(field)} };`];
96
+ });
97
+ // Ways back (13-data-model-v1 §23.4): `$relations`, apart from the fields (no field starts with `$`).
98
+ const relations = relationsOf(schema, tableName).map((relation) => `${propKey(relation.name)}: { table: ${JSON.stringify(relation.table)}; field: ${JSON.stringify(relation.field)} }`);
99
+ if (relations.length > 0)
100
+ fields.push(` $relations: { ${relations.join('; ')} };`);
101
+ lines.push(` ${propKey(tableName)}: ${fields.length > 0 ? `{\n${fields.join('\n')}\n }` : '{}'};`);
102
+ }
103
+ return lines;
104
+ }
105
+ /** `RefTargets`: table → ref field → the table it points at. */
106
+ function emitRefTargets(schema) {
107
+ const lines = [];
108
+ for (const [tableName, table] of compiledTableEntries(schema)) {
109
+ const refs = slotFieldEntries(table.fields)
110
+ .filter(([, field]) => field.ref)
111
+ .map(([fieldName, field]) => `${propKey(fieldName)}: ${JSON.stringify(field.ref.table)}`);
112
+ lines.push(` ${propKey(tableName)}: { ${refs.join('; ')}${refs.length > 0 ? ' ' : ''}};`);
56
113
  }
114
+ return lines;
115
+ }
116
+ /** An object type from member lines; `{}` when there are none. */
117
+ function objectType(lines) {
118
+ return lines.length > 0 ? `{\n${lines.join('\n')}\n}` : '{}';
119
+ }
120
+ /**
121
+ * Emit a sequence's `__gen/slots.type.ts` (28 §2.2): the company's table types come from the root
122
+ * `__gen/tables.type.ts`, the one copy every sequence shares; only the subject is the sequence's.
123
+ */
124
+ export function emitSlotsSource(subject) {
57
125
  return `// GENERATED — do not edit
58
- // Source: company schema + sequence slots → effective schema
126
+ // Source: the company's tables (root __gen) and this sequence's subject
59
127
  // Regenerate: superpanel-sdk-runtime type:gen
60
128
 
61
- export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
129
+ export type { FieldState, FieldValueBase, PageTables, RefTargets, Rows } from '../../../__gen/tables.type.ts';
62
130
 
63
- export type FieldHistoryEntry = {
64
- value: string | number | boolean | null;
65
- state: FieldState;
66
- at: number;
67
- by:
68
- | "slot-filling"
69
- | "derived"
70
- | "function"
71
- | "human"
72
- | "import"
73
- | "platform";
74
- };
131
+ /** The table this sequence's runs are about (\`defineSequence({ subject })\`). */
132
+ export type SubjectTable = ${JSON.stringify(subject)};
133
+ `;
134
+ }
135
+ /**
136
+ * `__gen/index.ts`: the one import a sequence's page, functions and events need. Re-exports the
137
+ * generated types, the page helpers bound to the company's tables (17b, 28 §2), and the types of its
138
+ * functions and entries (`Ctx`, `Events`, `CaseOrchestrator`, `Resolve`, 38). `functionsImport` is relative to `__gen/` (`null` without a functions module),
139
+ * `actionsImport` likewise for the page actions (`actions.ts`, 76 §2.11).
140
+ * Schema-independent, so the same text serves as the stub.
141
+ */
142
+ export function emitGenIndexSource(functionsImport, variablesImport = null, actionsImport = null) {
143
+ const variablesType = variablesImport
144
+ ? `type VariablesModule = typeof import(${JSON.stringify(variablesImport)});
145
+ /** This sequence's run variables (\`variables.ts\`), as \`ctx.api.instances.get\` returns them. */
146
+ export type InstanceVariables = VariablesOf<VariablesModule extends { variables: infer V } ? V : Record<never, never>>;`
147
+ : `/** This sequence's run variables: none without \`variables.ts\`. */
148
+ export type InstanceVariables = VariablesOf<Record<never, never>>;`;
149
+ const functionsType = functionsImport
150
+ ? `type FunctionsModule = typeof import(${JSON.stringify(functionsImport)});
151
+ type Functions = FunctionsModule extends { functions: infer F } ? F : FunctionsModule extends { default: infer F } ? F : Record<never, never>;`
152
+ : `type Functions = Record<never, never>;`;
153
+ const actionsType = actionsImport
154
+ ? `type ActionsModule = typeof import(${JSON.stringify(actionsImport)});
155
+ type Actions = ActionsModule extends { actions: infer A } ? A : Record<never, never>;`
156
+ : `type Actions = Record<never, never>;`;
157
+ return `// GENERATED — do not edit
158
+ // Sequence entry: page helpers and function types bound to this sequence's tables, plus generated types
159
+ // Regenerate: superpanel-sdk-runtime type:gen
160
+
161
+ import {
162
+ choose as runtimeChoose,
163
+ definePage as runtimeDefinePage,
164
+ page as runtimePageFn,
165
+ field as runtimeFieldFn,
166
+ refField as runtimeRefFieldFn,
167
+ createRow as runtimeCreateRow,
168
+ run as runtimeRun,
169
+ deleteRow as runtimeDeleteRow,
170
+ functionHandles as runtimeFunctionHandles,
171
+ actionHandles as runtimeActionHandles,
172
+ type ActionHandles,
173
+ type FunctionHandles,
174
+ type TypedPageFns,
175
+ type Ctx as RuntimeCtx,
176
+ type CaseOrchestrator as RuntimeCaseOrchestrator,
177
+ type EventHandlers,
178
+ type Resolve as RuntimeResolve,
179
+ type VariablesOf,
180
+ type RowOf,
181
+ type TypedDb,
182
+ type PageChannel,
183
+ type TypedActionContext,
184
+ type TypedPageContext,
185
+ type TypedPageModule,
186
+ type TypedReadDb,
187
+ } from '@superpanel-sdk/runtime';
188
+ export { lastActionRun, tried } from '@superpanel-sdk/runtime';
189
+ // The page in functions (76): the ones not bound to this sequence's tables, as they are.
190
+ export {
191
+ announce,
192
+ backgroundTransfer,
193
+ block,
194
+ button,
195
+ cancelFollowUp,
196
+ coldTransfer,
197
+ convertTime,
198
+ data,
199
+ doNow,
200
+ end,
201
+ keypad,
202
+ list,
203
+ pressKeypad,
204
+ scheduleFollowUp,
205
+ text,
206
+ toolbox,
207
+ voicemail,
208
+ warmTransfer,
209
+ } from '@superpanel-sdk/runtime';
210
+ import type { PageTables, SubjectTable } from './slots.type.ts';
211
+
212
+ export type { PageTables, RefTargets, Rows, SubjectTable } from './slots.type.ts';
213
+ export type { ContactSchedule, Email, Id, IsoDate, IsoDateTime, Phone, TimeOfDay } from '@superpanel-sdk/runtime';
214
+
215
+ type PageModule = TypedPageModule<PageTables, SubjectTable>;
216
+ /**
217
+ * A page function's context: \`PageContext<'sms'>\` one channel's (with \`ctx.sms\`), \`PageContext\` any
218
+ * channel's (what a helper shared by several pages takes; call actions are on \`ctx.call\`).
219
+ */
220
+ export type PageContext<C extends PageChannel = PageChannel> = TypedPageContext<PageTables, SubjectTable, C>;
221
+ /**
222
+ * \`context.page.ts\` (17b §9.1): \`export default definePage({ persona: (ctx) => '…', faq: (ctx) => [...], call: async (ctx) => page, sms: …, email: … })\`.
223
+ * \`persona\` and \`faq\` are called once, when the conversation starts (24 §4).
224
+ * \`db\` takes the company's tables and fields.
225
+ */
226
+ export const definePage = runtimeDefinePage as unknown as PageModule['definePage'];
227
+ /**
228
+ * The rows a row parameter is chosen among (25 §10): \`cancel({ appointment: choose(appointments, (a) => a.date.value) })\`.
229
+ * The candidates are exactly these rows; with none the button is left off the page.
230
+ */
231
+ export const choose = runtimeChoose as unknown as PageModule['choose'];
232
+ /**
233
+ * A page action's \`ctx\` (76 §2.11), in \`actions.ts\`: \`export const actions = { verifyPin: async (ctx: ActionCtx, args: { pin: string }) => { … } }\`.
234
+ * It runs next to the database, in one transaction; \`db\` takes the company's tables and fields.
235
+ */
236
+ export type ActionCtx = TypedActionContext<PageTables, SubjectTable>;
237
+ type Fns = TypedPageFns<PageTables, SubjectTable, Functions>;
238
+ /** The page (76 §2.7): \`page({ guide, voice, extraction }, { …content by name })\`; returned by a page function unless it returns \`doNow()\`. */
239
+ export const page = runtimePageFn as unknown as Fns['page'];
240
+ /** A field the AI may write, or read only: \`field(m.incident_date, { expand: true })\`. A ref field is \`refField()\`. */
241
+ export const field = runtimeFieldFn as unknown as Fns['field'];
242
+ /** A ref field: writable, the rows it may be set to (\`options: choose(rows, label)\`); read-only, who its value is (\`label\`). */
243
+ export const refField = runtimeRefFieldFn as unknown as Fns['refField'];
244
+ /** Add a row of this sequence's tables: \`createRow('injury', { fields: ['body_part'], prefill: { case: c.id } })\`. */
245
+ export const createRow = runtimeCreateRow as unknown as Fns['createRow'];
246
+ /** Run a company function (\`fn.x\`) or a page action: \`run(fn.cancelOrder, { prefill: { order: o.id }, args: { reason: 'In their words' } })\`. */
247
+ export const run = runtimeRun as unknown as Fns['run'];
248
+ /** Delete a row and everything under it: \`deleteRow(injury)\`. */
249
+ export const deleteRow = runtimeDeleteRow as unknown as Fns['deleteRow'];
250
+ /** This sequence's company functions (\`functions/\`), by name, for \`run(fn.x, { … })\` (76 §2.15). */
251
+ export const fn = runtimeFunctionHandles() as unknown as FunctionHandles<Functions>;
252
+ /**
253
+ * This sequence's page actions (\`actions.ts\`), by name, for \`run(act.verifyPin, { … })\` (76 §2.11). An action runs
254
+ * next to the database, in one transaction.
255
+ */
256
+ export const act = runtimeActionHandles() as unknown as ActionHandles<Actions, PageTables, SubjectTable>;
257
+ /** A row of \`T\` as \`db\` returns it; \`Inc\` what was \`include\`d (\`Row<'case_contact', { contact: true }>\`). */
258
+ export type Row<T extends keyof PageTables, Inc = undefined> = RowOf<PageTables, T, Inc>;
259
+ /** \`ctx.api.db\` (and an action's \`db\`): the company's tables, reads and writes. */
260
+ export type Db = TypedDb<PageTables>;
261
+ /** \`db\` with the read methods only (a page render): a helper typed with it can only read. */
262
+ export type ReadDb = TypedReadDb<PageTables>;
263
+
264
+
265
+ /**
266
+ * A function's \`ctx\` (38 §2.3): \`export async function cancel(ctx: Ctx, args: { appointment: Id<'appointment'>; reason: string })\`;
267
+ * \`ctx.api.db\` takes the company's tables and fields.
268
+ */
269
+ export type Ctx = RuntimeCtx<PageTables>;
270
+
271
+ /**
272
+ * \`events.ts\` (38 §2.2): \`export const events: Events = { 'call.ended': async (ctx, { event, subject, instanceId }) => … }\`.
273
+ */
274
+ export type Events = EventHandlers<PageTables, SubjectTable>;
275
+
276
+ ${functionsType}
277
+ ${actionsType}
278
+ ${variablesType}
279
+ /** This sequence's functions (\`functions\` module), by name. */
280
+ export type FunctionsOf = Functions;
281
+
282
+ /**
283
+ * \`orchestrator.ts\`: \`export const orchestrator: CaseOrchestrator = async (ctx, args) => …\`; \`args.subject\` is
284
+ * a row of this sequence's subject table, \`ctx.api.db\` takes the company's tables and fields.
285
+ */
286
+ export type CaseOrchestrator = RuntimeCaseOrchestrator<PageTables, SubjectTable>;
287
+
288
+ /** \`resolve.ts\`: \`export const resolve: Resolve = async (ctx, conversation) => …\`; \`ctx.api.db\` take the company's tables. */
289
+ export type Resolve = RuntimeResolve<PageTables>;
290
+
291
+ `;
292
+ }
293
+ /**
294
+ * Emit the repository root's `__gen/tables.type.ts`: the company's tables, as the code at the root
295
+ * (`resolve.ts`, `webhook.ts`) reads and writes them with `ctx.api.db`, and as every sequence's
296
+ * `__gen` re-exports them (28 §2.2).
297
+ */
298
+ export function emitCompanyTablesSource(schema) {
299
+ const rowBlocks = compiledTableEntries(schema).map(([tableName, table]) => emitRowType(tableName, table.fields));
300
+ return `// GENERATED — do not edit
301
+ // Source: company schema (schema/)
302
+ // Regenerate: superpanel-sdk-runtime type:gen
303
+
304
+ import type { CellBinding, ContactSchedule, Id, RowRef } from '@superpanel-sdk/runtime';
305
+
306
+ export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
75
307
 
76
308
  export type FieldValueBase = {
77
309
  reason: string | null;
@@ -79,65 +311,94 @@ export type FieldValueBase = {
79
311
  updatedAt: number;
80
312
  updatedBy:
81
313
  | "slot-filling"
82
- | "derived"
83
314
  | "function"
84
315
  | "human"
85
316
  | "import"
86
317
  | "platform";
87
- history: FieldHistoryEntry[];
88
318
  };
89
319
 
90
- export type Slots = {
91
- current: {
92
- contactId: string;
93
- caseContactId: string;
94
- caseFileId: string;
95
- sessionId: string | null;
96
- };
97
- ${tableBlocks.join('\n')}
320
+ /** One row of each table, as a view receives it. */
321
+ export type Rows = {
322
+ ${rowBlocks.join('\n')}
98
323
  };
324
+
325
+ /** Each table's ref fields and the table each points at (\`q.rows(table).where(field, node)\`, \`node.follow(field)\`). */
326
+ export type RefTargets = ${objectType(emitRefTargets(schema))};
327
+
328
+ /** The company's tables as code reads and writes them (\`ctx.api.db\`, a page's and its actions' \`db\`). */
329
+ export type PageTables = ${objectType(emitPageTables(schema))};
99
330
  `;
100
331
  }
101
332
  /**
102
- * Emit `__gen/case-context.type.ts`.
103
- * Separate from slots.type.ts so dependencies stay one-way:
104
- * view.ts → slots.type.ts
105
- * case-context.type.ts → view.ts | slots.type.ts
106
- * functions → case-context.type.ts
333
+ * The repository root's `__gen/index.ts`: what `resolve.ts`, `webhook.ts`, `schedules.ts` and `errors.ts` import to get
334
+ * `ctx.api.db` bound to the company's tables. Schema-independent, so the same text serves as the stub.
107
335
  */
108
- export function emitCaseContextSource(options) {
109
- if (options.hasCaseContextView) {
110
- return `// GENERATED — do not edit
111
- // CaseContext from sequence view.ts
112
- // Regenerate: superpanel-sdk-runtime type:gen
113
-
114
- export type { CaseContext } from '../view.ts';
115
- `;
116
- }
336
+ export function emitCompanyGenIndexSource() {
117
337
  return `// GENERATED — do not edit
118
- // No view.ts — CaseContext is identity with Slots
338
+ // Company entry: types for the code at the repository root (resolve.ts, webhook.ts, schedules.ts, errors.ts), bound to the company's tables
119
339
  // Regenerate: superpanel-sdk-runtime type:gen
120
340
 
121
- import type { Slots } from './slots.type.ts';
341
+ import {
342
+ defineSchedules as runtimeDefineSchedules,
343
+ type CompanyResolve as RuntimeCompanyResolve,
344
+ type OnError as RuntimeOnError,
345
+ type Ctx as RuntimeCtx,
346
+ type RowOf,
347
+ type Schedules,
348
+ type TypedDb,
349
+ type WebhookHandler,
350
+ } from '@superpanel-sdk/runtime';
351
+ import type { PageTables } from './tables.type.ts';
122
352
 
123
- export type CaseContext = Slots;
353
+ export type { PageTables } from './tables.type.ts';
354
+ export type { Id } from '@superpanel-sdk/runtime';
355
+ export type { CodeErrorEvent } from '@superpanel-sdk/runtime';
356
+
357
+ /** A function's \`ctx\` (38 §2.3): \`ctx.api.db\` takes the company's tables. */
358
+ export type Ctx = RuntimeCtx<PageTables>;
359
+ /** \`resolve.ts\`: \`export const resolve: CompanyResolve = async (ctx, conversation) => …\`; \`ctx.api.db\` takes the company's tables. */
360
+ export type CompanyResolve = RuntimeCompanyResolve<PageTables>;
361
+ /** \`webhook.ts\`: \`export const received: Webhook = async (ctx, { event }) => …\`; \`ctx.api.db\` takes the company's tables. */
362
+ export type Webhook = WebhookHandler<PageTables>;
363
+ /**
364
+ * \`schedules.ts\` (25 §6.4): \`export const schedules = defineSchedules({ nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx, { schedule }) => … } })\`.
365
+ * No case: \`ctx.api.db\` takes the company's tables; start or notify any sequence's instances with \`ctx.api.instances\`.
366
+ */
367
+ export const defineSchedules = runtimeDefineSchedules as (schedules: Schedules<PageTables>) => Schedules<PageTables>;
368
+ /**
369
+ * \`errors.ts\` (67 §5): \`export const onError: OnError = async (ctx, { error }) => …\`. Run once for each failure your code
370
+ * did not catch, and each text or email conversation the AI marked stuck; with no case.
371
+ */
372
+ export type OnError = RuntimeOnError<PageTables>;
373
+ /** A row of \`T\` as \`db\` returns it; \`Inc\` what was \`include\`d. */
374
+ export type Row<T extends keyof PageTables, Inc = undefined> = RowOf<PageTables, T, Inc>;
375
+ /** \`ctx.api.db\` of the code at the root: the company's tables, reads and writes. */
376
+ export type Db = TypedDb<PageTables>;
124
377
  `;
125
378
  }
126
- /** Stub written when a sequence has no gen file yet. */
127
- export function emitSlotsStub() {
379
+ /** Stub written when the repository root has no gen file yet. */
380
+ export function emitCompanyTablesStub() {
128
381
  return `// GENERATED — do not edit
129
382
  // Stub — run: superpanel-sdk-runtime type:gen
130
383
 
131
- export type Slots = Record<string, unknown>;
384
+ export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
385
+ export type FieldValueBase = Record<string, unknown>;
386
+ export type Rows = Record<string, Record<string, unknown>>;
387
+ export type RefTargets = Record<string, Record<string, string>>;
388
+ export type PageTables = Record<string, Record<string, { value: unknown; ref?: string; parent?: true } | Record<string, { table: string; field: string }>>>;
132
389
  `;
133
390
  }
134
- export function emitCaseContextStub() {
391
+ /** Stub written when a sequence has no gen file yet. */
392
+ export function emitSlotsStub() {
135
393
  return `// GENERATED — do not edit
136
394
  // Stub — run: superpanel-sdk-runtime type:gen
137
395
 
138
- import type { Slots } from './slots.type.ts';
139
-
140
- export type CaseContext = Slots;
396
+ export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
397
+ export type FieldValueBase = Record<string, unknown>;
398
+ export type Rows = Record<string, Record<string, unknown>>;
399
+ export type RefTargets = Record<string, Record<string, string>>;
400
+ export type SubjectTable = string;
401
+ export type PageTables = Record<string, Record<string, { value: unknown; ref?: string; parent?: true } | Record<string, { table: string; field: string }>>>;
141
402
  `;
142
403
  }
143
404
  //# sourceMappingURL=emit.js.map
@@ -3,19 +3,38 @@ export { listSequenceIds };
3
3
  export type GenerateResult = {
4
4
  sequenceId: string;
5
5
  outPath: string;
6
- caseContextOutPath: string;
6
+ indexOutPath: string;
7
7
  source: string;
8
- caseContextSource: string;
8
+ indexSource: string;
9
+ /** The root `__gen/tables.type.ts` the sequence's types re-export (28 §2.2). */
10
+ tablesSource: string;
9
11
  wrote: boolean;
10
12
  };
13
+ /** The repository root's `__gen/`: types for `resolve.ts` and `webhook.ts`, bound to the company's tables. */
14
+ export declare function companyGenPaths(repoRoot: string): {
15
+ tablesOutPath: string;
16
+ indexOutPath: string;
17
+ };
11
18
  export declare function generateSequence(repoRoot: string, sequenceId: string, options?: {
12
19
  dryRun?: boolean;
13
20
  }): Promise<GenerateResult>;
21
+ /**
22
+ * The root `__gen/` and every sequence's (or only `sequenceIds`'). A repository with no sequence gets the
23
+ * root's alone, as the release type check does (22 §11), so `type:gen` and `typecheck` pass on it locally too.
24
+ */
14
25
  export declare function generateAll(repoRoot: string, options?: {
15
26
  dryRun?: boolean;
16
27
  sequenceIds?: string[];
17
28
  }): Promise<GenerateResult[]>;
18
29
  export declare function checkSequence(repoRoot: string, sequenceId: string): Promise<void>;
30
+ /** The root `__gen/` matches the company schema. */
31
+ export declare function checkCompany(repoRoot: string): Promise<void>;
32
+ /** The root `__gen/` and every sequence's are up to date; with no sequence, the root's alone. */
19
33
  export declare function checkAll(repoRoot: string): Promise<void>;
20
34
  export declare function ensureStub(repoRoot: string, sequenceId: string): void;
35
+ /**
36
+ * Writes the root `__gen/` files that are missing (a fresh checkout has none: `__gen/` is gitignored),
37
+ * so `resolve.ts` and `webhook.ts` can import it; existing ones are left untouched.
38
+ */
39
+ export declare function ensureCompanyStub(repoRoot: string): void;
21
40
  //# sourceMappingURL=generate.d.ts.map