@superpanel-sdk/runtime 0.2.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/README.md +28 -8
  2. package/dist/builder/codegen/emit.d.ts +29 -11
  3. package/dist/builder/codegen/emit.js +328 -61
  4. package/dist/builder/codegen/generate.d.ts +21 -0
  5. package/dist/builder/codegen/generate.js +152 -20
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +24 -0
  9. package/dist/builder/company-imports.js +114 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +59 -8
  11. package/dist/builder/compile/compile-sequence.js +279 -77
  12. package/dist/builder/compile/function-code.d.ts +12 -2
  13. package/dist/builder/compile/function-code.js +87 -39
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +24 -23
  16. package/dist/builder/load.d.ts +70 -10
  17. package/dist/builder/load.js +250 -61
  18. package/dist/builder/paths.d.ts +3 -0
  19. package/dist/builder/paths.js +16 -0
  20. package/dist/builder/schedules.d.ts +23 -0
  21. package/dist/builder/schedules.js +102 -0
  22. package/dist/builder/slot-schema-validation.d.ts +4 -0
  23. package/dist/builder/slot-schema-validation.js +10 -0
  24. package/dist/builder/typecheck.d.ts +8 -0
  25. package/dist/builder/typecheck.js +105 -0
  26. package/dist/builder/types.d.ts +91 -19
  27. package/dist/builder/types.js +2 -1
  28. package/dist/cli/auth/auth.d.ts +37 -0
  29. package/dist/cli/auth/auth.js +211 -0
  30. package/dist/cli/auth/backend-url.d.ts +5 -0
  31. package/dist/cli/auth/backend-url.js +25 -0
  32. package/dist/cli/auth/clipboard.d.ts +9 -0
  33. package/dist/cli/auth/clipboard.js +38 -0
  34. package/dist/cli/auth/http.d.ts +20 -0
  35. package/dist/cli/auth/http.js +27 -0
  36. package/dist/cli/auth/index.d.ts +10 -0
  37. package/dist/cli/auth/index.js +27 -0
  38. package/dist/cli/auth/progress.d.ts +12 -0
  39. package/dist/cli/auth/progress.js +15 -0
  40. package/dist/cli/auth/serve-login.d.ts +8 -0
  41. package/dist/cli/auth/serve-login.js +24 -0
  42. package/dist/cli/compile/index.js +3 -0
  43. package/dist/cli/config.d.ts +10 -0
  44. package/dist/cli/config.js +52 -0
  45. package/dist/cli/index.js +28 -8
  46. package/dist/cli/serve/index.d.ts +73 -3
  47. package/dist/cli/serve/index.js +410 -113
  48. package/dist/cli/type-gen/index.js +9 -8
  49. package/dist/compiler.d.ts +7 -0
  50. package/dist/compiler.js +7 -0
  51. package/dist/compute-host/compute-host.d.ts +15 -23
  52. package/dist/compute-host/compute-host.js +25 -28
  53. package/dist/compute-host/index.d.ts +2 -2
  54. package/dist/compute-host/index.js +1 -1
  55. package/dist/compute-host/source-compute-host.d.ts +11 -9
  56. package/dist/compute-host/source-compute-host.js +50 -31
  57. package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
  58. package/dist/core/case-orchestrator/contact-hours.js +108 -0
  59. package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
  60. package/dist/core/case-orchestrator/follow-ups.js +103 -0
  61. package/dist/core/case-orchestrator/index.d.ts +6 -0
  62. package/dist/core/case-orchestrator/index.js +6 -0
  63. package/dist/core/case-orchestrator/render.d.ts +75 -0
  64. package/dist/core/case-orchestrator/render.js +239 -0
  65. package/dist/core/case-orchestrator/time.d.ts +11 -0
  66. package/dist/core/case-orchestrator/time.js +29 -0
  67. package/dist/core/case-orchestrator/tools.d.ts +29 -0
  68. package/dist/core/case-orchestrator/tools.js +31 -0
  69. package/dist/core/case-orchestrator/types.d.ts +753 -0
  70. package/dist/core/case-orchestrator/types.js +46 -0
  71. package/dist/core/case-orchestrator/validate.d.ts +11 -0
  72. package/dist/core/case-orchestrator/validate.js +63 -0
  73. package/dist/core/context/call.d.ts +291 -0
  74. package/dist/core/context/call.js +94 -0
  75. package/dist/core/context/channels.d.ts +60 -0
  76. package/dist/core/context/channels.js +35 -0
  77. package/dist/core/context/contact.d.ts +96 -6
  78. package/dist/core/context/contact.js +48 -2
  79. package/dist/core/context/email-message.d.ts +159 -0
  80. package/dist/core/context/email-message.js +59 -0
  81. package/dist/core/context/email.d.ts +97 -0
  82. package/dist/core/context/email.js +91 -0
  83. package/dist/core/context/exchanges.d.ts +142 -0
  84. package/dist/core/context/exchanges.js +63 -0
  85. package/dist/core/context/instances.d.ts +278 -0
  86. package/dist/core/context/instances.js +123 -0
  87. package/dist/core/context/kv.d.ts +113 -0
  88. package/dist/core/context/kv.js +60 -0
  89. package/dist/core/context/platform-registry.d.ts +509 -4
  90. package/dist/core/context/platform-registry.js +14 -2
  91. package/dist/core/context/platform.d.ts +2 -1
  92. package/dist/core/context/sms.d.ts +147 -0
  93. package/dist/core/context/sms.js +57 -0
  94. package/dist/core/context/types.d.ts +51 -30
  95. package/dist/core/context/types.js +1 -7
  96. package/dist/core/conversation/index.d.ts +31 -0
  97. package/dist/core/conversation/index.js +14 -0
  98. package/dist/core/functions/define/bind.d.ts +25 -0
  99. package/dist/core/functions/define/bind.js +14 -0
  100. package/dist/core/functions/define/case.d.ts +9 -0
  101. package/dist/core/functions/define/case.js +13 -0
  102. package/dist/core/functions/define/events.d.ts +20 -0
  103. package/dist/core/functions/define/events.js +21 -0
  104. package/dist/core/functions/define/no-case.d.ts +4 -0
  105. package/dist/core/functions/define/no-case.js +9 -0
  106. package/dist/core/functions/events.d.ts +247 -0
  107. package/dist/core/functions/events.js +32 -0
  108. package/dist/core/functions/func-ref.d.ts +11 -2
  109. package/dist/core/functions/schedules.d.ts +51 -0
  110. package/dist/core/functions/schedules.js +20 -0
  111. package/dist/core/functions/types.d.ts +62 -51
  112. package/dist/core/functions/types.js +6 -1
  113. package/dist/core/office-hours/index.d.ts +39 -0
  114. package/dist/core/office-hours/index.js +187 -0
  115. package/dist/core/page/define.d.ts +834 -0
  116. package/dist/core/page/define.js +477 -0
  117. package/dist/core/page/ops.d.ts +58 -0
  118. package/dist/core/page/ops.js +220 -0
  119. package/dist/core/page/render.d.ts +253 -0
  120. package/dist/core/page/render.js +840 -0
  121. package/dist/core/page/time-format.d.ts +19 -0
  122. package/dist/core/page/time-format.js +41 -0
  123. package/dist/core/page/timeline.d.ts +40 -0
  124. package/dist/core/page/timeline.js +2 -0
  125. package/dist/core/page/typed.d.ts +642 -0
  126. package/dist/core/page/typed.js +2 -0
  127. package/dist/core/page/workspace.d.ts +33 -0
  128. package/dist/core/page/workspace.js +231 -0
  129. package/dist/core/party/index.d.ts +3 -0
  130. package/dist/core/party/index.js +3 -0
  131. package/dist/core/party/schema.d.ts +137 -0
  132. package/dist/core/party/schema.js +80 -0
  133. package/dist/core/party/types.d.ts +40 -0
  134. package/dist/core/party/types.js +15 -0
  135. package/dist/core/sequence/define.d.ts +57 -0
  136. package/dist/core/sequence/define.js +10 -0
  137. package/dist/core/sequence/index.d.ts +63 -0
  138. package/dist/core/sequence/index.js +231 -0
  139. package/dist/core/slot/binding.d.ts +40 -0
  140. package/dist/core/slot/binding.js +2 -0
  141. package/dist/core/slot/company-metadata.d.ts +113 -0
  142. package/dist/core/slot/company-metadata.js +563 -0
  143. package/dist/core/slot/compile-schema.d.ts +19 -13
  144. package/dist/core/slot/compile-schema.js +51 -248
  145. package/dist/core/slot/contact-timezone.d.ts +110 -0
  146. package/dist/core/slot/contact-timezone.js +186 -0
  147. package/dist/core/slot/field.d.ts +2 -24
  148. package/dist/core/slot/field.js +0 -69
  149. package/dist/core/slot/id-ref.d.ts +17 -2
  150. package/dist/core/slot/id-ref.js +16 -8
  151. package/dist/core/slot/index.d.ts +12 -13
  152. package/dist/core/slot/index.js +11 -12
  153. package/dist/core/slot/naming.d.ts +15 -0
  154. package/dist/core/slot/naming.js +96 -0
  155. package/dist/core/slot/platform-fields.d.ts +119 -0
  156. package/dist/core/slot/platform-fields.js +121 -0
  157. package/dist/core/slot/ref.d.ts +16 -0
  158. package/dist/core/slot/ref.js +14 -0
  159. package/dist/core/slot/row.d.ts +2 -9
  160. package/dist/core/slot/row.js +13 -23
  161. package/dist/core/slot/schema-compat.d.ts +16 -0
  162. package/dist/core/slot/schema-compat.js +112 -0
  163. package/dist/core/slot/schema.d.ts +409 -76
  164. package/dist/core/slot/schema.js +178 -10
  165. package/dist/core/slot/types.d.ts +27 -92
  166. package/dist/core/slot/value.d.ts +26 -3
  167. package/dist/core/slot/value.js +89 -57
  168. package/dist/dev-overlay/protocol.d.ts +41 -8
  169. package/dist/fn-context/build-context.d.ts +3 -1
  170. package/dist/fn-context/build-context.js +20 -10
  171. package/dist/fn-context/fake/empty-api.js +9 -28
  172. package/dist/fn-context/fake/index.d.ts +11 -4
  173. package/dist/fn-context/fake/index.js +27 -2
  174. package/dist/fn-context/fn-params.d.ts +6 -0
  175. package/dist/fn-context/fn-params.js +13 -0
  176. package/dist/fn-context/index.d.ts +5 -5
  177. package/dist/fn-context/index.js +4 -4
  178. package/dist/fn-context/log.js +2 -2
  179. package/dist/fn-context/make-ctx.d.ts +11 -0
  180. package/dist/fn-context/make-ctx.js +18 -8
  181. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
  182. package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
  183. package/dist/fn-context/rpc/index.d.ts +3 -1
  184. package/dist/fn-context/rpc/index.js +3 -1
  185. package/dist/fn-context/rpc/integration/index.d.ts +4 -4
  186. package/dist/fn-context/rpc/integration/index.js +1 -1
  187. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  188. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  189. package/dist/fn-context/rpc/platform.d.ts +2 -2
  190. package/dist/fn-context/rpc/platform.js +1 -1
  191. package/dist/fn-context/rpc/records.d.ts +78 -0
  192. package/dist/fn-context/rpc/records.js +26 -0
  193. package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
  194. package/dist/fn-context/rpc/trpc-client.js +89 -5
  195. package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
  196. package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
  197. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  198. package/dist/fn-context/run-scope.d.ts +4 -0
  199. package/dist/fn-context/run-scope.js +9 -0
  200. package/dist/fn-context/types.d.ts +36 -3
  201. package/dist/index.d.ts +37 -46
  202. package/dist/index.js +33 -33
  203. package/dist/logger.d.ts +7 -0
  204. package/dist/logger.js +41 -0
  205. package/dist/platform.d.ts +76 -0
  206. package/dist/platform.js +56 -0
  207. package/dist/voice-service/actions.d.ts +71 -4
  208. package/dist/voice-service/types.d.ts +42 -2
  209. package/dist/worker.d.ts +10 -0
  210. package/dist/worker.js +10 -0
  211. package/package.json +38 -19
  212. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  213. package/dist/builder/compile/compile-agenda.js +0 -59
  214. package/dist/builder/merge.d.ts +0 -4
  215. package/dist/builder/merge.js +0 -19
  216. package/dist/core/context/db.d.ts +0 -69
  217. package/dist/core/context/db.js +0 -44
  218. package/dist/core/context/docusign.d.ts +0 -134
  219. package/dist/core/context/docusign.js +0 -108
  220. package/dist/core/context/filevine.d.ts +0 -323
  221. package/dist/core/context/filevine.js +0 -254
  222. package/dist/core/context/http.d.ts +0 -9
  223. package/dist/core/context/http.js +0 -4
  224. package/dist/core/context/hubspot.d.ts +0 -250
  225. package/dist/core/context/hubspot.js +0 -191
  226. package/dist/core/context/twilio.d.ts +0 -50
  227. package/dist/core/context/twilio.js +0 -42
  228. package/dist/core/functions/define/case-context.d.ts +0 -14
  229. package/dist/core/functions/define/case-context.js +0 -15
  230. package/dist/core/functions/define/compute.d.ts +0 -7
  231. package/dist/core/functions/define/compute.js +0 -17
  232. package/dist/core/functions/define/custom.d.ts +0 -4
  233. package/dist/core/functions/define/custom.js +0 -8
  234. package/dist/core/functions/define/system.d.ts +0 -7
  235. package/dist/core/functions/define/system.js +0 -12
  236. package/dist/core/slot/deps.d.ts +0 -15
  237. package/dist/core/slot/deps.js +0 -88
  238. package/dist/core/slot/derived.d.ts +0 -32
  239. package/dist/core/slot/derived.js +0 -115
  240. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  241. package/dist/core/slot/platform-session-fields.js +0 -48
  242. package/dist/core/slot/sf-schema.d.ts +0 -23
  243. package/dist/core/slot/sf-schema.js +0 -125
  244. package/dist/core/slot/sf-validate.d.ts +0 -14
  245. package/dist/core/slot/sf-validate.js +0 -132
  246. package/dist/core/slot/snapshot.d.ts +0 -18
  247. package/dist/core/slot/snapshot.js +0 -138
  248. package/dist/core/slot/write.d.ts +0 -41
  249. package/dist/core/slot/write.js +0 -319
  250. package/dist/core/stage/builders.d.ts +0 -36
  251. package/dist/core/stage/builders.js +0 -28
  252. package/dist/core/stage/condition.d.ts +0 -17
  253. package/dist/core/stage/condition.js +0 -198
  254. package/dist/core/stage/drive.d.ts +0 -43
  255. package/dist/core/stage/drive.js +0 -77
  256. package/dist/core/stage/finish-when.d.ts +0 -20
  257. package/dist/core/stage/finish-when.js +0 -82
  258. package/dist/core/stage/flatten.d.ts +0 -27
  259. package/dist/core/stage/flatten.js +0 -464
  260. package/dist/core/stage/index.d.ts +0 -11
  261. package/dist/core/stage/index.js +0 -10
  262. package/dist/core/stage/simulate.d.ts +0 -24
  263. package/dist/core/stage/simulate.js +0 -33
  264. package/dist/core/stage/transfer-fields.d.ts +0 -14
  265. package/dist/core/stage/transfer-fields.js +0 -88
  266. package/dist/core/stage/types.d.ts +0 -177
  267. package/dist/core/stage/types.js +0 -2
  268. package/dist/core/stage/validate.d.ts +0 -11
  269. package/dist/core/stage/validate.js +0 -226
  270. package/dist/core/stage/walk.d.ts +0 -34
  271. package/dist/core/stage/walk.js +0 -96
  272. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  273. package/dist/fn-context/system-args.d.ts +0 -6
  274. package/dist/fn-context/system-args.js +0 -14
package/README.md CHANGED
@@ -1,6 +1,6 @@
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, derived recompute, the page contract (`definePage`: persona, per-channel page functions, regions and todos, channel actions), and company-repo CLI.
4
4
 
5
5
  This package is currently published as an **internal prerelease**. Install a tagged build, not `latest`:
6
6
 
@@ -8,7 +8,7 @@ This package is currently published as an **internal prerelease**. Install a tag
8
8
  npm i @superpanel-sdk/runtime@next
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,16 +1,34 @@
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
+ * Emit `__gen/case-context.type.ts`: what code working on a case receives as `c` — functions, event
9
+ * handlers, the Orchestrator: the instance and its business root's id (the page is the conversation's).
10
+ */
11
+ export declare function emitCaseContextSource(): string;
12
+ /**
13
+ * `__gen/index.ts`: the one import a sequence's page, functions and events need. Re-exports the
14
+ * generated types, the page helpers bound to the company's tables (17b, 28 §2), and the define helpers bound
15
+ * to its case (`CaseInput`). `functionsImport` is relative to `__gen/` (`null` without a functions module).
16
+ * Schema-independent, so the same text serves as the stub.
17
+ */
18
+ export declare function emitGenIndexSource(functionsImport: string | null, variablesImport?: string | null): string;
19
+ /**
20
+ * Emit the repository root's `__gen/tables.type.ts`: the company's tables, as the code at the root
21
+ * (`resolve.ts`, `webhook.ts`) reads and writes them with `ctx.api.db`, and as every sequence's
22
+ * `__gen` re-exports them (28 §2.2).
23
+ */
24
+ export declare function emitCompanyTablesSource(schema: CompiledSlotSchema): string;
25
+ /**
26
+ * The repository root's `__gen/index.ts`: what `resolve.ts`, `webhook.ts` and `schedules.ts` import to get
27
+ * `ctx.api.db` bound to the company's tables. Schema-independent, so the same text serves as the stub.
28
+ */
29
+ export declare function emitCompanyGenIndexSource(): string;
30
+ /** Stub written when the repository root has no gen file yet. */
31
+ export declare function emitCompanyTablesStub(): string;
14
32
  /** Stub written when a sequence has no gen file yet. */
15
33
  export declare function emitSlotsStub(): string;
16
34
  export declare function emitCaseContextStub(): string;
@@ -1,72 +1,306 @@
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 }` : '{}'};`);
56
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 ? ' ' : ''}};`);
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
 
129
+ export type { FieldHistoryEntry, FieldState, FieldValueBase, PageTables, RefTargets, Rows } from '../../../__gen/tables.type.ts';
130
+
131
+ /** The table this sequence's runs are about (\`defineSequence({ subject })\`). */
132
+ export type SubjectTable = ${JSON.stringify(subject)};
133
+ `;
134
+ }
135
+ /**
136
+ * Emit `__gen/case-context.type.ts`: what code working on a case receives as `c` — functions, event
137
+ * handlers, the Orchestrator: the instance and its business root's id (the page is the conversation's).
138
+ */
139
+ export function emitCaseContextSource() {
140
+ return `// GENERATED — do not edit
141
+ // CaseInput: what functions, event handlers and the Orchestrator receive as c (the instance and its business root)
142
+ // Regenerate: superpanel-sdk-runtime type:gen
143
+
144
+ import type { CaseInput as RuntimeCaseInput } from '@superpanel-sdk/runtime';
145
+ import type { SubjectTable } from './slots.type.ts';
146
+
147
+ /** What functions, event handlers, orchestrator and contacts receive as \`c\`: the instance, and its business root's id. */
148
+ export type CaseInput = RuntimeCaseInput<SubjectTable>;
149
+ /** What orchestrator and contacts receive as \`c\` (the same as \`CaseInput\`). */
150
+ export type CaseOrchestratorInput = CaseInput;
151
+ `;
152
+ }
153
+ /**
154
+ * `__gen/index.ts`: the one import a sequence's page, functions and events need. Re-exports the
155
+ * generated types, the page helpers bound to the company's tables (17b, 28 §2), and the define helpers bound
156
+ * to its case (`CaseInput`). `functionsImport` is relative to `__gen/` (`null` without a functions module).
157
+ * Schema-independent, so the same text serves as the stub.
158
+ */
159
+ export function emitGenIndexSource(functionsImport, variablesImport = null) {
160
+ const variablesType = variablesImport
161
+ ? `type VariablesModule = typeof import(${JSON.stringify(variablesImport)});
162
+ /** This sequence's run variables (\`variables.ts\`), as \`ctx.api.instances.get\` returns them. */
163
+ export type InstanceVariables = VariablesOf<VariablesModule extends { variables: infer V } ? V : Record<never, never>>;`
164
+ : `/** This sequence's run variables: none without \`variables.ts\`. */
165
+ export type InstanceVariables = VariablesOf<Record<never, never>>;`;
166
+ const functionsType = functionsImport
167
+ ? `type FunctionsModule = typeof import(${JSON.stringify(functionsImport)});
168
+ type Functions = FunctionsModule extends { functions: infer F } ? F : FunctionsModule extends { default: infer F } ? F : Record<never, never>;`
169
+ : `type Functions = Record<never, never>;`;
170
+ return `// GENERATED — do not edit
171
+ // Sequence entry: define helpers bound to this sequence's case and tables, plus generated types
172
+ // Regenerate: superpanel-sdk-runtime type:gen
173
+
174
+ import {
175
+ bindDefines,
176
+ defineSchedules as runtimeDefineSchedules,
177
+ choose as runtimeChoose,
178
+ createRow as runtimeCreateRow,
179
+ defineAction as runtimeDefineAction,
180
+ definePage as runtimeDefinePage,
181
+ deleteRow as runtimeDeleteRow,
182
+ field as runtimeField,
183
+ refField as runtimeRefField,
184
+ runFunction as runtimeRunFunction,
185
+ schemaField as runtimeSchemaField,
186
+ type CaseOrchestrator as RuntimeCaseOrchestrator,
187
+ type CaseOrchestratorContacts as RuntimeCaseOrchestratorContacts,
188
+ type Resolve as RuntimeResolve,
189
+ type Schedules,
190
+ type VariablesOf,
191
+ type RowOf,
192
+ type TypedDb,
193
+ type PageChannel,
194
+ type TypedPageContext,
195
+ type TypedPageModule,
196
+ type TypedReadDb,
197
+ } from '@superpanel-sdk/runtime';
198
+ export { end, lastActionRun, perform, tried } from '@superpanel-sdk/runtime';
199
+ import type { CaseInput, CaseOrchestratorInput } from './case-context.type.ts';
200
+ import type { PageTables, SubjectTable } from './slots.type.ts';
201
+
202
+ export type { CaseInput, CaseOrchestratorInput } from './case-context.type.ts';
203
+ export type { PageTables, RefTargets, Rows, SubjectTable } from './slots.type.ts';
204
+ export type { Id } from '@superpanel-sdk/runtime';
205
+
206
+ type PageModule = TypedPageModule<PageTables, SubjectTable>;
207
+ /**
208
+ * A page function's context: \`PageContext<'sms'>\` one channel's (with \`ctx.sms\`), \`PageContext\` any
209
+ * channel's (what a helper shared by several pages takes; call actions are on \`ctx.call\`).
210
+ */
211
+ export type PageContext<C extends PageChannel = PageChannel> = TypedPageContext<PageTables, SubjectTable, C>;
212
+ /**
213
+ * \`context.page.ts\` (17b §9.1): \`export default definePage({ persona: (ctx) => '…', faq: (ctx) => [...], call: async (ctx) => page, sms: …, email: … })\`.
214
+ * \`persona\` and \`faq\` are called once, when the conversation starts (24 §4).
215
+ * \`db\` and \`schemaField\` take the company's tables and fields.
216
+ */
217
+ export const definePage = runtimeDefinePage as unknown as PageModule['definePage'];
218
+ /** A cell the AI may write: \`field(slot, { readOnly, expand })\` (a slot placed as is is read-only). How to fill a field on this page: the page's \`$extraction: { 'table.field': '…' }\`. */
219
+ export const field = runtimeField as unknown as PageModule['field'];
220
+ /**
221
+ * A ref field (26 §16.2 #7): \`refField(job.referred_by, { options: choose(regulars, (c) => c.first_name.value ?? '') })\`,
222
+ * the rows the AI may set it to, each with its label; \`{ readOnly: true, options: [...] }\` shows who the current one is.
223
+ */
224
+ export const refField = runtimeRefField as unknown as PageModule['refField'];
225
+ /** An action parameter taken from the schema: \`schemaField('providers.name')\`, \`schemaField('injuries.id')\` (a row). */
226
+ export const schemaField = runtimeSchemaField as unknown as PageModule['schemaField'];
227
+ /** The built-in action that adds a row: \`createRow('injuries', { fields })\`, called to preset values. */
228
+ export const createRow = runtimeCreateRow as unknown as PageModule['createRow'];
229
+ /** The built-in action that deletes a row (and everything under it): \`deleteRow(row.id)\`. */
230
+ export const deleteRow = runtimeDeleteRow as unknown as PageModule['deleteRow'];
231
+ /**
232
+ * The rows a row parameter is chosen among (25 §10): \`cancel({ appointment: choose(appointments, (a) => a.date.value) })\`.
233
+ * The candidates are exactly these rows; with none the button is left off the page.
234
+ */
235
+ export const choose = runtimeChoose as unknown as PageModule['choose'];
236
+ /**
237
+ * A custom action, declared like an LLM function call (\`parameters\`). Place it called: a row argument
238
+ * prefilled (\`markError({ injury: i.id })\`) or offered with \`choose(...)\` (25 §10).
239
+ */
240
+ export const defineAction = runtimeDefineAction as unknown as PageModule['defineAction'];
241
+ /**
242
+ * A company function (\`functions/\`) as a button, or returned by the page function to run now (20 §6.2):
243
+ * \`runFunction('importOrders', { label, say, parameters })\`. The name must be one of this sequence's functions.
244
+ */
245
+ export const runFunction = runtimeRunFunction as unknown as (
246
+ name: keyof Functions & string,
247
+ options?: Parameters<typeof runtimeRunFunction>[1],
248
+ ) => ReturnType<typeof runtimeRunFunction>;
249
+ /** A row of \`T\` as \`db\` returns it; \`Inc\` what was \`include\`d (\`Row<'case_contact', { contact: true }>\`). */
250
+ export type Row<T extends keyof PageTables, Inc = undefined> = RowOf<PageTables, T, Inc>;
251
+ /** \`ctx.api.db\` (and an action's \`db\`): the company's tables, reads and writes. */
252
+ export type Db = TypedDb<PageTables>;
253
+ /** \`db\` with the read methods only (a page render): a helper typed with it can only read. */
254
+ export type ReadDb = TypedReadDb<PageTables>;
255
+
256
+
257
+ /** Functions and event handlers get \`c\`: CaseInput; their \`ctx.api.db\` takes the company's tables and fields. */
258
+ export const { defineCaseFunc, defineNoCaseFunc, defineEvents } = bindDefines<PageTables, CaseInput>();
259
+
260
+ ${functionsType}
261
+ ${variablesType}
262
+ /** This sequence's functions (\`functions\` module), by name. */
263
+ export type FunctionsOf = Functions;
264
+
265
+ /**
266
+ * \`orchestrator.ts\`: \`export const orchestrator: CaseOrchestrator = async (c, ctx) => …\`;
267
+ * \`ctx.api.db\` take the company's tables and fields.
268
+ */
269
+ export type CaseOrchestrator = RuntimeCaseOrchestrator<CaseOrchestratorInput, PageTables>;
270
+ /** \`orchestrator.ts\`: \`export const contacts: CaseOrchestratorContacts = async (c, ctx) => contactIds\`. */
271
+ export type CaseOrchestratorContacts = RuntimeCaseOrchestratorContacts<CaseOrchestratorInput, PageTables>;
272
+
273
+ /** \`resolve.ts\`: \`export const resolve: Resolve = async (ctx) => …\`; \`ctx.api.db\` take the company's tables. */
274
+ export type Resolve = RuntimeResolve<PageTables>;
275
+
276
+ /**
277
+ * \`schedules.ts\` (25 §6.4): \`export const schedules = defineSchedules({ dailyRecall: { cron: '0 8 * * 1-5', timezone: 'America/Phoenix', run: async (ctx) => … } })\`.
278
+ * No case: \`ctx.api.db\` takes the company's tables; start or notify its instances with \`ctx.api.instances\`.
279
+ */
280
+ export const defineSchedules = runtimeDefineSchedules as (schedules: Schedules<PageTables>) => Schedules<PageTables>;
281
+ `;
282
+ }
283
+ /**
284
+ * Emit the repository root's `__gen/tables.type.ts`: the company's tables, as the code at the root
285
+ * (`resolve.ts`, `webhook.ts`) reads and writes them with `ctx.api.db`, and as every sequence's
286
+ * `__gen` re-exports them (28 §2.2).
287
+ */
288
+ export function emitCompanyTablesSource(schema) {
289
+ const rowBlocks = compiledTableEntries(schema).map(([tableName, table]) => emitRowType(tableName, table.fields));
290
+ return `// GENERATED — do not edit
291
+ // Source: company schema (schema/)
292
+ // Regenerate: superpanel-sdk-runtime type:gen
293
+
294
+ import type { CellBinding, ContactSchedule, Id, RowRef } from '@superpanel-sdk/runtime';
295
+
61
296
  export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
62
297
 
63
298
  export type FieldHistoryEntry = {
64
- value: string | number | boolean | null;
299
+ value: string | number | boolean | string[] | ContactSchedule | null;
65
300
  state: FieldState;
66
301
  at: number;
67
302
  by:
68
303
  | "slot-filling"
69
- | "derived"
70
304
  | "function"
71
305
  | "human"
72
306
  | "import"
@@ -79,7 +313,6 @@ export type FieldValueBase = {
79
313
  updatedAt: number;
80
314
  updatedBy:
81
315
  | "slot-filling"
82
- | "derived"
83
316
  | "function"
84
317
  | "human"
85
318
  | "import"
@@ -87,40 +320,67 @@ export type FieldValueBase = {
87
320
  history: FieldHistoryEntry[];
88
321
  };
89
322
 
90
- export type Slots = {
91
- current: {
92
- contactId: string;
93
- caseContactId: string;
94
- caseFileId: string;
95
- sessionId: string | null;
96
- };
97
- ${tableBlocks.join('\n')}
323
+ /** One row of each table, as a view receives it. */
324
+ export type Rows = {
325
+ ${rowBlocks.join('\n')}
98
326
  };
327
+
328
+ /** Each table's ref fields and the table each points at (\`q.rows(table).where(field, node)\`, \`node.follow(field)\`). */
329
+ export type RefTargets = ${objectType(emitRefTargets(schema))};
330
+
331
+ /** The company's tables as code reads and writes them (\`ctx.api.db\`, a page's \`db\`, actions' \`schemaField\`). */
332
+ export type PageTables = ${objectType(emitPageTables(schema))};
99
333
  `;
100
334
  }
101
335
  /**
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
336
+ * The repository root's `__gen/index.ts`: what `resolve.ts`, `webhook.ts` and `schedules.ts` import to get
337
+ * `ctx.api.db` bound to the company's tables. Schema-independent, so the same text serves as the stub.
107
338
  */
108
- export function emitCaseContextSource(options) {
109
- if (options.hasCaseContextView) {
110
- return `// GENERATED — do not edit
111
- // CaseContext from sequence view.ts
339
+ export function emitCompanyGenIndexSource() {
340
+ return `// GENERATED — do not edit
341
+ // Company entry: types for the code at the repository root (resolve.ts, webhook.ts, schedules.ts), bound to the company's tables
112
342
  // Regenerate: superpanel-sdk-runtime type:gen
113
343
 
114
- export type { CaseContext } from '../view.ts';
344
+ import {
345
+ defineSchedules as runtimeDefineSchedules,
346
+ defineWebhook as runtimeDefineWebhook,
347
+ type CompanyResolve as RuntimeCompanyResolve,
348
+ type RowOf,
349
+ type Schedules,
350
+ type TypedDb,
351
+ type WebhookHandler,
352
+ } from '@superpanel-sdk/runtime';
353
+ import type { PageTables } from './tables.type.ts';
354
+
355
+ export type { PageTables } from './tables.type.ts';
356
+ export type { Id } from '@superpanel-sdk/runtime';
357
+
358
+ /** \`resolve.ts\`: \`export const resolve: CompanyResolve = async (ctx) => …\`; \`ctx.api.db\` takes the company's tables. */
359
+ export type CompanyResolve = RuntimeCompanyResolve<PageTables>;
360
+ /** \`webhook.ts\`: \`export const received = defineWebhook(async (ctx) => …)\`; \`ctx.api.db\` takes the company's tables. */
361
+ export const defineWebhook = runtimeDefineWebhook as (handler: WebhookHandler<PageTables>) => WebhookHandler<PageTables>;
362
+ /**
363
+ * \`schedules.ts\` (25 §6.4): \`export const schedules = defineSchedules({ nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx) => … } })\`.
364
+ * No case: \`ctx.api.db\` takes the company's tables; start or notify any sequence's instances with \`ctx.api.instances\`.
365
+ */
366
+ export const defineSchedules = runtimeDefineSchedules as (schedules: Schedules<PageTables>) => Schedules<PageTables>;
367
+ /** A row of \`T\` as \`db\` returns it; \`Inc\` what was \`include\`d. */
368
+ export type Row<T extends keyof PageTables, Inc = undefined> = RowOf<PageTables, T, Inc>;
369
+ /** \`ctx.api.db\` of the code at the root: the company's tables, reads and writes. */
370
+ export type Db = TypedDb<PageTables>;
115
371
  `;
116
- }
372
+ }
373
+ /** Stub written when the repository root has no gen file yet. */
374
+ export function emitCompanyTablesStub() {
117
375
  return `// GENERATED — do not edit
118
- // No view.ts — CaseContext is identity with Slots
119
- // Regenerate: superpanel-sdk-runtime type:gen
120
-
121
- import type { Slots } from './slots.type.ts';
376
+ // Stub — run: superpanel-sdk-runtime type:gen
122
377
 
123
- export type CaseContext = Slots;
378
+ export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
379
+ export type FieldHistoryEntry = Record<string, unknown>;
380
+ export type FieldValueBase = Record<string, unknown>;
381
+ export type Rows = Record<string, Record<string, unknown>>;
382
+ export type RefTargets = Record<string, Record<string, string>>;
383
+ export type PageTables = Record<string, Record<string, { value: unknown; ref?: string; parent?: true } | Record<string, { table: string; field: string }>>>;
124
384
  `;
125
385
  }
126
386
  /** Stub written when a sequence has no gen file yet. */
@@ -128,16 +388,23 @@ export function emitSlotsStub() {
128
388
  return `// GENERATED — do not edit
129
389
  // Stub — run: superpanel-sdk-runtime type:gen
130
390
 
131
- export type Slots = Record<string, unknown>;
391
+ export type FieldState = "empty" | "filled" | "asked_unknown" | "declined";
392
+ export type FieldHistoryEntry = Record<string, unknown>;
393
+ export type FieldValueBase = Record<string, unknown>;
394
+ export type Rows = Record<string, Record<string, unknown>>;
395
+ export type RefTargets = Record<string, Record<string, string>>;
396
+ export type SubjectTable = string;
397
+ export type PageTables = Record<string, Record<string, { value: unknown; ref?: string; parent?: true } | Record<string, { table: string; field: string }>>>;
132
398
  `;
133
399
  }
134
400
  export function emitCaseContextStub() {
135
401
  return `// GENERATED — do not edit
136
402
  // Stub — run: superpanel-sdk-runtime type:gen
137
403
 
138
- import type { Slots } from './slots.type.ts';
404
+ import type { CaseInput as RuntimeCaseInput } from '@superpanel-sdk/runtime';
139
405
 
140
- export type CaseContext = Slots;
406
+ export type CaseInput = RuntimeCaseInput;
407
+ export type CaseOrchestratorInput = CaseInput;
141
408
  `;
142
409
  }
143
410
  //# sourceMappingURL=emit.js.map
@@ -4,18 +4,39 @@ export type GenerateResult = {
4
4
  sequenceId: string;
5
5
  outPath: string;
6
6
  caseContextOutPath: string;
7
+ indexOutPath: string;
7
8
  source: string;
8
9
  caseContextSource: string;
10
+ indexSource: string;
11
+ /** The root `__gen/tables.type.ts` the sequence's types re-export (28 §2.2). */
12
+ tablesSource: string;
9
13
  wrote: boolean;
10
14
  };
15
+ /** The repository root's `__gen/`: types for `resolve.ts` and `webhook.ts`, bound to the company's tables. */
16
+ export declare function companyGenPaths(repoRoot: string): {
17
+ tablesOutPath: string;
18
+ indexOutPath: string;
19
+ };
11
20
  export declare function generateSequence(repoRoot: string, sequenceId: string, options?: {
12
21
  dryRun?: boolean;
13
22
  }): Promise<GenerateResult>;
23
+ /**
24
+ * The root `__gen/` alone, from the company schema: what the root code of a repository with no
25
+ * sequence is typed by (22 §11). `generateAll` writes it too, with the sequences.
26
+ */
27
+ export declare function generateCompany(repoRoot: string): Promise<void>;
14
28
  export declare function generateAll(repoRoot: string, options?: {
15
29
  dryRun?: boolean;
16
30
  sequenceIds?: string[];
17
31
  }): Promise<GenerateResult[]>;
18
32
  export declare function checkSequence(repoRoot: string, sequenceId: string): Promise<void>;
33
+ /** The root `__gen/` matches the company schema. */
34
+ export declare function checkCompany(repoRoot: string): Promise<void>;
19
35
  export declare function checkAll(repoRoot: string): Promise<void>;
20
36
  export declare function ensureStub(repoRoot: string, sequenceId: string): void;
37
+ /**
38
+ * Writes the root `__gen/` files that are missing (a fresh checkout has none: `__gen/` is gitignored),
39
+ * so `resolve.ts` and `webhook.ts` can import it; existing ones are left untouched.
40
+ */
41
+ export declare function ensureCompanyStub(repoRoot: string): void;
21
42
  //# sourceMappingURL=generate.d.ts.map