@superpanel-sdk/runtime 0.2.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/README.md +30 -10
  2. package/dist/builder/codegen/emit.d.ts +25 -12
  3. package/dist/builder/codegen/emit.js +339 -78
  4. package/dist/builder/codegen/generate.d.ts +21 -2
  5. package/dist/builder/codegen/generate.js +147 -34
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +29 -0
  9. package/dist/builder/company-imports.js +122 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +61 -8
  11. package/dist/builder/compile/compile-sequence.js +334 -80
  12. package/dist/builder/compile/function-code.d.ts +19 -3
  13. package/dist/builder/compile/function-code.js +123 -45
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +30 -27
  16. package/dist/builder/errors.d.ts +9 -0
  17. package/dist/builder/errors.js +17 -0
  18. package/dist/builder/function-params.d.ts +10 -0
  19. package/dist/builder/function-params.js +203 -0
  20. package/dist/builder/load.d.ts +70 -10
  21. package/dist/builder/load.js +258 -67
  22. package/dist/builder/paths.d.ts +9 -1
  23. package/dist/builder/paths.js +32 -2
  24. package/dist/builder/schedules.d.ts +25 -0
  25. package/dist/builder/schedules.js +101 -0
  26. package/dist/builder/slot-schema-validation.d.ts +4 -0
  27. package/dist/builder/slot-schema-validation.js +10 -0
  28. package/dist/builder/typecheck.d.ts +8 -0
  29. package/dist/builder/typecheck.js +102 -0
  30. package/dist/builder/types.d.ts +127 -19
  31. package/dist/builder/types.js +21 -1
  32. package/dist/cli/auth/auth.d.ts +37 -0
  33. package/dist/cli/auth/auth.js +211 -0
  34. package/dist/cli/auth/backend-url.d.ts +5 -0
  35. package/dist/cli/auth/backend-url.js +25 -0
  36. package/dist/cli/auth/clipboard.d.ts +9 -0
  37. package/dist/cli/auth/clipboard.js +38 -0
  38. package/dist/cli/auth/http.d.ts +20 -0
  39. package/dist/cli/auth/http.js +27 -0
  40. package/dist/cli/auth/index.d.ts +10 -0
  41. package/dist/cli/auth/index.js +27 -0
  42. package/dist/cli/auth/progress.d.ts +12 -0
  43. package/dist/cli/auth/progress.js +15 -0
  44. package/dist/cli/auth/serve-login.d.ts +8 -0
  45. package/dist/cli/auth/serve-login.js +24 -0
  46. package/dist/cli/calls/index.d.ts +177 -0
  47. package/dist/cli/calls/index.js +96 -0
  48. package/dist/cli/compile/index.js +3 -0
  49. package/dist/cli/config.d.ts +10 -0
  50. package/dist/cli/config.js +52 -0
  51. package/dist/cli/debug/index.d.ts +31 -0
  52. package/dist/cli/debug/index.js +119 -0
  53. package/dist/cli/exec/index.d.ts +39 -0
  54. package/dist/cli/exec/index.js +138 -0
  55. package/dist/cli/exec/session.d.ts +48 -0
  56. package/dist/cli/exec/session.js +82 -0
  57. package/dist/cli/exec/trace.d.ts +18 -0
  58. package/dist/cli/exec/trace.js +52 -0
  59. package/dist/cli/index.js +112 -9
  60. package/dist/cli/logs/index.d.ts +47 -0
  61. package/dist/cli/logs/index.js +113 -0
  62. package/dist/cli/mobile/index.d.ts +12 -0
  63. package/dist/cli/mobile/index.js +405 -0
  64. package/dist/cli/serve/index.d.ts +109 -3
  65. package/dist/cli/serve/index.js +506 -118
  66. package/dist/cli/turns/index.d.ts +105 -0
  67. package/dist/cli/turns/index.js +128 -0
  68. package/dist/cli/turns/run.d.ts +13 -0
  69. package/dist/cli/turns/run.js +57 -0
  70. package/dist/cli/turns/shadow.d.ts +112 -0
  71. package/dist/cli/turns/shadow.js +54 -0
  72. package/dist/cli/type-gen/index.js +9 -9
  73. package/dist/compiler.d.ts +7 -0
  74. package/dist/compiler.js +7 -0
  75. package/dist/compute-host/compute-host.d.ts +14 -23
  76. package/dist/compute-host/compute-host.js +18 -30
  77. package/dist/compute-host/index.d.ts +2 -4
  78. package/dist/compute-host/index.js +1 -2
  79. package/dist/compute-host/source-compute-host.d.ts +10 -10
  80. package/dist/compute-host/source-compute-host.js +33 -40
  81. package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
  82. package/dist/core/case-orchestrator/contact-hours.js +127 -0
  83. package/dist/core/case-orchestrator/index.d.ts +3 -0
  84. package/dist/core/case-orchestrator/index.js +3 -0
  85. package/dist/core/case-orchestrator/render.d.ts +75 -0
  86. package/dist/core/case-orchestrator/render.js +244 -0
  87. package/dist/core/case-orchestrator/time.d.ts +11 -0
  88. package/dist/core/case-orchestrator/time.js +29 -0
  89. package/dist/core/case-orchestrator/types.d.ts +708 -0
  90. package/dist/core/case-orchestrator/types.js +42 -0
  91. package/dist/core/context/call.d.ts +291 -0
  92. package/dist/core/context/call.js +94 -0
  93. package/dist/core/context/channels.d.ts +60 -0
  94. package/dist/core/context/channels.js +35 -0
  95. package/dist/core/context/contact.d.ts +96 -6
  96. package/dist/core/context/contact.js +48 -2
  97. package/dist/core/context/email-message.d.ts +198 -0
  98. package/dist/core/context/email-message.js +86 -0
  99. package/dist/core/context/email.d.ts +109 -0
  100. package/dist/core/context/email.js +90 -0
  101. package/dist/core/context/exchanges.d.ts +167 -0
  102. package/dist/core/context/exchanges.js +81 -0
  103. package/dist/core/context/instances.d.ts +307 -0
  104. package/dist/core/context/instances.js +137 -0
  105. package/dist/core/context/kv.d.ts +113 -0
  106. package/dist/core/context/kv.js +60 -0
  107. package/dist/core/context/platform-registry.d.ts +544 -4
  108. package/dist/core/context/platform-registry.js +14 -2
  109. package/dist/core/context/platform.d.ts +2 -1
  110. package/dist/core/context/sms.d.ts +177 -0
  111. package/dist/core/context/sms.js +77 -0
  112. package/dist/core/context/types.d.ts +79 -48
  113. package/dist/core/context/types.js +1 -7
  114. package/dist/core/conversation/index.d.ts +85 -0
  115. package/dist/core/conversation/index.js +133 -0
  116. package/dist/core/functions/errors.d.ts +74 -0
  117. package/dist/core/functions/errors.js +26 -0
  118. package/dist/core/functions/events.d.ts +192 -0
  119. package/dist/core/functions/events.js +23 -0
  120. package/dist/core/functions/schedules.d.ts +50 -0
  121. package/dist/core/functions/schedules.js +20 -0
  122. package/dist/core/functions/types.d.ts +29 -73
  123. package/dist/core/functions/types.js +1 -4
  124. package/dist/core/office-hours/index.d.ts +39 -0
  125. package/dist/core/office-hours/index.js +187 -0
  126. package/dist/core/page/define.d.ts +904 -0
  127. package/dist/core/page/define.js +518 -0
  128. package/dist/core/page/envelope.d.ts +55 -0
  129. package/dist/core/page/envelope.js +4 -0
  130. package/dist/core/page/fns.d.ts +448 -0
  131. package/dist/core/page/fns.js +539 -0
  132. package/dist/core/page/memory-reader.d.ts +27 -0
  133. package/dist/core/page/memory-reader.js +299 -0
  134. package/dist/core/page/ops.d.ts +58 -0
  135. package/dist/core/page/ops.js +220 -0
  136. package/dist/core/page/page-host.d.ts +20 -0
  137. package/dist/core/page/page-host.js +57 -0
  138. package/dist/core/page/records-query.d.ts +234 -0
  139. package/dist/core/page/records-query.js +780 -0
  140. package/dist/core/page/render.d.ts +295 -0
  141. package/dist/core/page/render.js +1060 -0
  142. package/dist/core/page/sandbox.d.ts +85 -0
  143. package/dist/core/page/sandbox.js +357 -0
  144. package/dist/core/page/time-format.d.ts +46 -0
  145. package/dist/core/page/time-format.js +125 -0
  146. package/dist/core/page/timeline.d.ts +40 -0
  147. package/dist/core/page/timeline.js +2 -0
  148. package/dist/core/page/typed.d.ts +648 -0
  149. package/dist/core/page/typed.js +2 -0
  150. package/dist/core/page/workspace.d.ts +57 -0
  151. package/dist/core/page/workspace.js +266 -0
  152. package/dist/core/party/index.d.ts +3 -0
  153. package/dist/core/party/index.js +3 -0
  154. package/dist/core/party/schema.d.ts +208 -0
  155. package/dist/core/party/schema.js +113 -0
  156. package/dist/core/party/types.d.ts +35 -0
  157. package/dist/core/party/types.js +15 -0
  158. package/dist/core/sequence/define.d.ts +56 -0
  159. package/dist/core/sequence/define.js +10 -0
  160. package/dist/core/sequence/index.d.ts +63 -0
  161. package/dist/core/sequence/index.js +231 -0
  162. package/dist/core/slot/binding.d.ts +40 -0
  163. package/dist/core/slot/binding.js +2 -0
  164. package/dist/core/slot/company-metadata.d.ts +102 -0
  165. package/dist/core/slot/company-metadata.js +536 -0
  166. package/dist/core/slot/compile-schema.d.ts +19 -13
  167. package/dist/core/slot/compile-schema.js +51 -248
  168. package/dist/core/slot/contact-timezone.d.ts +110 -0
  169. package/dist/core/slot/contact-timezone.js +186 -0
  170. package/dist/core/slot/field.d.ts +2 -25
  171. package/dist/core/slot/field.js +0 -71
  172. package/dist/core/slot/id-ref.d.ts +17 -2
  173. package/dist/core/slot/id-ref.js +16 -8
  174. package/dist/core/slot/index.d.ts +12 -13
  175. package/dist/core/slot/index.js +11 -12
  176. package/dist/core/slot/naming.d.ts +15 -0
  177. package/dist/core/slot/naming.js +96 -0
  178. package/dist/core/slot/platform-fields.d.ts +119 -0
  179. package/dist/core/slot/platform-fields.js +121 -0
  180. package/dist/core/slot/ref.d.ts +16 -0
  181. package/dist/core/slot/ref.js +14 -0
  182. package/dist/core/slot/row.d.ts +2 -9
  183. package/dist/core/slot/row.js +13 -23
  184. package/dist/core/slot/schema-compat.d.ts +17 -0
  185. package/dist/core/slot/schema-compat.js +103 -0
  186. package/dist/core/slot/schema.d.ts +353 -76
  187. package/dist/core/slot/schema.js +163 -10
  188. package/dist/core/slot/types.d.ts +30 -103
  189. package/dist/core/slot/value.d.ts +28 -3
  190. package/dist/core/slot/value.js +93 -57
  191. package/dist/dev-overlay/protocol.d.ts +74 -8
  192. package/dist/fn-context/build-context.d.ts +3 -1
  193. package/dist/fn-context/build-context.js +26 -10
  194. package/dist/fn-context/fake/empty-api.js +9 -28
  195. package/dist/fn-context/fake/index.d.ts +13 -4
  196. package/dist/fn-context/fake/index.js +29 -2
  197. package/dist/fn-context/fn-params.d.ts +3 -0
  198. package/dist/fn-context/fn-params.js +10 -0
  199. package/dist/fn-context/index.d.ts +5 -5
  200. package/dist/fn-context/index.js +4 -4
  201. package/dist/fn-context/log.js +2 -2
  202. package/dist/fn-context/make-ctx.d.ts +11 -0
  203. package/dist/fn-context/make-ctx.js +20 -9
  204. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
  205. package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
  206. package/dist/fn-context/rpc/errors.d.ts +13 -0
  207. package/dist/fn-context/rpc/errors.js +22 -0
  208. package/dist/fn-context/rpc/index.d.ts +4 -2
  209. package/dist/fn-context/rpc/index.js +4 -2
  210. package/dist/fn-context/rpc/integration/index.d.ts +15 -5
  211. package/dist/fn-context/rpc/integration/index.js +1 -1
  212. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  213. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  214. package/dist/fn-context/rpc/log.d.ts +11 -1
  215. package/dist/fn-context/rpc/platform.d.ts +13 -3
  216. package/dist/fn-context/rpc/platform.js +1 -1
  217. package/dist/fn-context/rpc/records.d.ts +85 -0
  218. package/dist/fn-context/rpc/records.js +24 -0
  219. package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
  220. package/dist/fn-context/rpc/trpc-client.js +222 -12
  221. package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
  222. package/dist/fn-context/rpc/trpc-init.js +10 -4
  223. package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
  224. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  225. package/dist/fn-context/run-scope.d.ts +4 -0
  226. package/dist/fn-context/run-scope.js +9 -0
  227. package/dist/fn-context/types.d.ts +52 -5
  228. package/dist/index.d.ts +36 -46
  229. package/dist/index.js +30 -33
  230. package/dist/logger.d.ts +11 -0
  231. package/dist/logger.js +49 -0
  232. package/dist/platform.d.ts +75 -0
  233. package/dist/platform.js +57 -0
  234. package/dist/testing-compile-child.d.ts +2 -0
  235. package/dist/testing-compile-child.js +20 -0
  236. package/dist/testing.d.ts +368 -0
  237. package/dist/testing.js +439 -0
  238. package/dist/voice-service/actions.d.ts +50 -6
  239. package/dist/voice-service/index.d.ts +2 -0
  240. package/dist/voice-service/index.js +2 -0
  241. package/dist/voice-service/protocol.d.ts +604 -0
  242. package/dist/voice-service/protocol.js +67 -0
  243. package/dist/voice-service/types.d.ts +55 -8
  244. package/dist/worker.d.ts +11 -0
  245. package/dist/worker.js +11 -0
  246. package/package.json +38 -15
  247. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  248. package/dist/builder/compile/compile-agenda.js +0 -64
  249. package/dist/builder/merge.d.ts +0 -4
  250. package/dist/builder/merge.js +0 -19
  251. package/dist/compute-host/read-only-cache.d.ts +0 -20
  252. package/dist/compute-host/read-only-cache.js +0 -61
  253. package/dist/core/context/db.d.ts +0 -69
  254. package/dist/core/context/db.js +0 -44
  255. package/dist/core/context/docusign.d.ts +0 -134
  256. package/dist/core/context/docusign.js +0 -108
  257. package/dist/core/context/filevine.d.ts +0 -323
  258. package/dist/core/context/filevine.js +0 -254
  259. package/dist/core/context/http.d.ts +0 -9
  260. package/dist/core/context/http.js +0 -4
  261. package/dist/core/context/hubspot.d.ts +0 -250
  262. package/dist/core/context/hubspot.js +0 -191
  263. package/dist/core/context/twilio.d.ts +0 -50
  264. package/dist/core/context/twilio.js +0 -42
  265. package/dist/core/functions/define/case-context.d.ts +0 -14
  266. package/dist/core/functions/define/case-context.js +0 -15
  267. package/dist/core/functions/define/compute.d.ts +0 -7
  268. package/dist/core/functions/define/compute.js +0 -17
  269. package/dist/core/functions/define/custom.d.ts +0 -4
  270. package/dist/core/functions/define/custom.js +0 -8
  271. package/dist/core/functions/define/system.d.ts +0 -7
  272. package/dist/core/functions/define/system.js +0 -12
  273. package/dist/core/functions/func-ref.d.ts +0 -16
  274. package/dist/core/functions/func-ref.js +0 -20
  275. package/dist/core/slot/deps.d.ts +0 -15
  276. package/dist/core/slot/deps.js +0 -88
  277. package/dist/core/slot/derived.d.ts +0 -32
  278. package/dist/core/slot/derived.js +0 -115
  279. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  280. package/dist/core/slot/platform-session-fields.js +0 -48
  281. package/dist/core/slot/sf-schema.d.ts +0 -23
  282. package/dist/core/slot/sf-schema.js +0 -125
  283. package/dist/core/slot/sf-validate.d.ts +0 -14
  284. package/dist/core/slot/sf-validate.js +0 -132
  285. package/dist/core/slot/snapshot.d.ts +0 -18
  286. package/dist/core/slot/snapshot.js +0 -138
  287. package/dist/core/slot/write.d.ts +0 -48
  288. package/dist/core/slot/write.js +0 -426
  289. package/dist/core/stage/builders.d.ts +0 -54
  290. package/dist/core/stage/builders.js +0 -31
  291. package/dist/core/stage/condition.d.ts +0 -17
  292. package/dist/core/stage/condition.js +0 -198
  293. package/dist/core/stage/drive.d.ts +0 -43
  294. package/dist/core/stage/drive.js +0 -78
  295. package/dist/core/stage/finish-when.d.ts +0 -20
  296. package/dist/core/stage/finish-when.js +0 -82
  297. package/dist/core/stage/flatten.d.ts +0 -27
  298. package/dist/core/stage/flatten.js +0 -466
  299. package/dist/core/stage/index.d.ts +0 -15
  300. package/dist/core/stage/index.js +0 -13
  301. package/dist/core/stage/interrupts.d.ts +0 -28
  302. package/dist/core/stage/interrupts.js +0 -120
  303. package/dist/core/stage/ivr-fields.d.ts +0 -9
  304. package/dist/core/stage/ivr-fields.js +0 -75
  305. package/dist/core/stage/simulate.d.ts +0 -24
  306. package/dist/core/stage/simulate.js +0 -33
  307. package/dist/core/stage/transfer-fields.d.ts +0 -19
  308. package/dist/core/stage/transfer-fields.js +0 -129
  309. package/dist/core/stage/transfer-spec.d.ts +0 -48
  310. package/dist/core/stage/transfer-spec.js +0 -113
  311. package/dist/core/stage/types.d.ts +0 -208
  312. package/dist/core/stage/types.js +0 -2
  313. package/dist/core/stage/validate.d.ts +0 -11
  314. package/dist/core/stage/validate.js +0 -330
  315. package/dist/core/stage/walk.d.ts +0 -39
  316. package/dist/core/stage/walk.js +0 -119
  317. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  318. package/dist/fn-context/system-args.d.ts +0 -6
  319. package/dist/fn-context/system-args.js +0 -14
@@ -0,0 +1,648 @@
1
+ /**
2
+ * The page module's types bound to one sequence (15 §10.15): what `__gen/index.ts` exports as
3
+ * `definePage`, `field`, `createRow` and `deleteRow`. Behaviour is
4
+ * `define.ts`'s; this file only types it.
5
+ *
6
+ * Everything starts from `PageTables`, generated per sequence into `__gen/slots.type.ts`: for each
7
+ * table, each field's value type, and for a ref field the table it points at (`ref`) and whether it
8
+ * is the parent (`parent`). From it:
9
+ *
10
+ * - a row read with `db` has `id: Id<'table'>`, `createdAt` / `updatedAt` (ISO 8601, the platform's)
11
+ * and one slot per field, its value typed by the schema; a lookup `include`d carries the target row
12
+ * in `.row`, a way back (`relatedName`) its rows as a list under its name;
13
+ * - `db.<table>`'s reads take only that table's fields and row times, a `where` starting at its top
14
+ * level from `id`, a ref field (15 §10.15 point 4), a field or a row time (the field index,
15
+ * 18-record-search-index §4.6), `include` of lookups and ways back only, `some` / `every` / `none` on
16
+ * a way back (13-data-model-v1 §23.4);
17
+ * - an action's arguments come from its `parameters`; `db.<table>`'s writes take only that table's fields;
18
+ * - the page is the conversation's: code (functions, event handlers, the Orchestrator) is called
19
+ * `(ctx, args)` and reads with `ctx.api.db`.
20
+ */
21
+ import type { Action, AllPrefilled, DoNode, FieldNode, FullPrefill, FunctionHandle, KeyedOf, LeftForAi, PageActionHandle, PageContent, PageNode, PageSettings, RequiredKeys, RunAction, AnyRunHandle, RunArgs, SameArgs, SayOf } from './fns.js';
22
+ import type { PageTime, ChooseParam, RefOption, PageBaseContext, PageChannel, PageChannelCaps, PageConversation, PageFaq, PageFaqEntry, PageHistory, PagePersona, PageRuns, PageScheduledAction, SlotState } from './define.js';
23
+ declare const ID_BRAND: unique symbol;
24
+ /** A row id of table `T`: an `Id<'injuries'>` is not an `Id<'providers'>`, and no string is an id. */
25
+ export type Id<T extends string = string> = string & {
26
+ readonly [ID_BRAND]: T;
27
+ };
28
+ declare const FORMAT_BRAND: unique symbol;
29
+ /**
30
+ * A string in a format the AI is told (38 §2.4): any string is one, and the builder reads the mark to
31
+ * show the parameter as `date`, `phone`…; one format is not another.
32
+ */
33
+ type Formatted<F extends string> = string & {
34
+ readonly [FORMAT_BRAND]?: F;
35
+ };
36
+ /** A calendar date, `YYYY-MM-DD`: the AI sees `date`. */
37
+ export type IsoDate = Formatted<'date'>;
38
+ /** An instant, ISO 8601 with an offset or Z: the AI sees `datetime`. */
39
+ export type IsoDateTime = Formatted<'datetime'>;
40
+ /** A time of day, `HH:mm`: the AI sees `time`. */
41
+ export type TimeOfDay = Formatted<'time'>;
42
+ /** A phone number: the AI sees `phone`. */
43
+ export type Phone = Formatted<'phone'>;
44
+ /** An email address: the AI sees `email`. */
45
+ export type Email = Formatted<'email'>;
46
+ /** One field, as `__gen/slots.type.ts` describes it. */
47
+ export type PageFieldDesc = {
48
+ value: unknown;
49
+ ref?: string;
50
+ parent?: true;
51
+ };
52
+ /**
53
+ * A table's ways back (`$relations`, 13-data-model-v1 §23.4 items 3–4): for each `relatedName`, the
54
+ * table whose rows point at this one and the ref field they point with.
55
+ */
56
+ export type PageRelationsDesc = {
57
+ [name: string]: {
58
+ table: string;
59
+ field: string;
60
+ };
61
+ };
62
+ /**
63
+ * A sequence's tables (`PageTables` in `__gen/slots.type.ts`): table → field → description, and its
64
+ * ways back under `$relations` (no field name starts with `$`).
65
+ */
66
+ export type PageTablesDesc = {
67
+ [table: string]: {
68
+ [field: string]: PageFieldDesc | PageRelationsDesc;
69
+ };
70
+ };
71
+ type TableOf<D> = Extract<keyof D, string>;
72
+ type FieldOf<D, T extends keyof D> = Exclude<Extract<keyof D[T], string>, '$relations'>;
73
+ /** The ways back to a table, by name; none when it has no `$relations`. */
74
+ type RelationsOf<D, T extends keyof D> = D[T] extends {
75
+ $relations: infer R;
76
+ } ? R : {};
77
+ type RelationOf<D, T extends keyof D> = Extract<keyof RelationsOf<D, T>, string>;
78
+ /** The table whose rows a way back lists. */
79
+ type RelationTable<D, T extends keyof D, K> = K extends keyof RelationsOf<D, T> ? RelationsOf<D, T>[K] extends {
80
+ table: infer R extends string;
81
+ } ? R & keyof D : never : never;
82
+ type Desc<D, T extends keyof D, F> = F extends keyof D[T] ? (D[T][F] extends PageFieldDesc ? D[T][F] : never) : never;
83
+ /** The table a ref field points at; never for a plain field. */
84
+ type RefTable<D, T extends keyof D, F> = Desc<D, T, F> extends {
85
+ ref: infer R extends string;
86
+ } ? R : never;
87
+ /** Lookup fields (refs that are not the parent): what `include` follows. */
88
+ type LookupOf<D, T extends keyof D> = {
89
+ [F in FieldOf<D, T>]: Desc<D, T, F> extends {
90
+ ref: string;
91
+ } ? (Desc<D, T, F> extends {
92
+ parent: true;
93
+ } ? never : F) : never;
94
+ }[FieldOf<D, T>];
95
+ /** Ref fields, parent included: what anchors a `where`. */
96
+ type RefFieldOf<D, T extends keyof D> = {
97
+ [F in FieldOf<D, T>]: Desc<D, T, F> extends {
98
+ ref: string;
99
+ } ? F : never;
100
+ }[FieldOf<D, T>];
101
+ /** Fields that are not refs: a condition on one starts a `where` through the field index. */
102
+ type PlainFieldOf<D, T extends keyof D> = Exclude<FieldOf<D, T>, RefFieldOf<D, T>>;
103
+ /** A row's times, the platform's (ISO 8601): when it was created, when it was last written. */
104
+ type RowTime = 'createdAt' | 'updatedAt';
105
+ type ParentOf<D, T extends keyof D> = {
106
+ [F in FieldOf<D, T>]: Desc<D, T, F> extends {
107
+ parent: true;
108
+ } ? F : never;
109
+ }[FieldOf<D, T>];
110
+ /** A field's value: a ref holds the id of a row of its table. */
111
+ type ValueOf<D, T extends keyof D, F> = Desc<D, T, F> extends {
112
+ ref: infer R extends string;
113
+ } ? Id<R> : Desc<D, T, F>['value'];
114
+ type Simplify<X> = {
115
+ [K in keyof X]: X[K];
116
+ } & {};
117
+ /** One field as read (15 §10.4): plain data. Judge with `.value` / `.state`. */
118
+ export type TypedSlot<V, T extends string, F extends string> = Readonly<{
119
+ value: V | null;
120
+ state: SlotState;
121
+ reason: string | null;
122
+ updatedAt: string | null;
123
+ ref: Readonly<{
124
+ table: T;
125
+ id: Id<T>;
126
+ field: F;
127
+ }>;
128
+ }>;
129
+ /**
130
+ * What `include` takes, at most 3 levels: lookup fields, `true` or a nested `{ include }`; ways back,
131
+ * `true` or the rows to list (`where`, `orderBy`, `skip`, `take`) and a nested `{ include }`.
132
+ */
133
+ export type IncludeArg<D, T extends keyof D, Depth extends unknown[] = []> = Depth['length'] extends 3 ? never : {
134
+ [F in LookupOf<D, T>]?: boolean | {
135
+ include?: IncludeArg<D, RefTable<D, T, F> & keyof D, [...Depth, unknown]>;
136
+ };
137
+ } & {
138
+ [K in RelationOf<D, T>]?: boolean | RelationInclude<D, RelationTable<D, T, K>, [...Depth, unknown]>;
139
+ };
140
+ /** The rows of a way back an `include` lists: filtered, ordered and paged like `findMany`. */
141
+ type RelationInclude<D, R extends keyof D, Depth extends unknown[]> = {
142
+ where?: WhereFields<D, R, true>;
143
+ orderBy?: OrderByArg<D, R>;
144
+ skip?: number;
145
+ take?: number;
146
+ include?: IncludeArg<D, R, Depth>;
147
+ };
148
+ /** What `select` takes: the fields to keep (`id` always comes). */
149
+ export type SelectArg<D, T extends keyof D> = {
150
+ [F in FieldOf<D, T>]?: boolean;
151
+ };
152
+ type IncludedRow<D, R extends keyof D, Spec> = [Spec] extends [{
153
+ include: infer I;
154
+ }] ? RowOf<D, R, I> : RowOf<D, R, undefined>;
155
+ /**
156
+ * The `.row` an `include` gives: there for sure on `true` or `{ include }`, not there on `false`, and
157
+ * maybe there on a `boolean` decided at run time (`include: { provider: flag }`).
158
+ */
159
+ type IncludedSlot<D, T extends keyof D & string, F extends string, Spec> = [Spec] extends [false | undefined] ? unknown : [Spec] extends [true | {
160
+ include?: unknown;
161
+ }] ? Readonly<{
162
+ row: IncludedRow<D, RefTable<D, T, F> & keyof D, Spec> | null;
163
+ }> : Readonly<{
164
+ row?: IncludedRow<D, RefTable<D, T, F> & keyof D, Exclude<Spec, boolean | undefined>> | null;
165
+ }>;
166
+ /** What `include` says of `F`; with `undefined` in it when the whole `include` may be absent this time. */
167
+ type IncludeSpec<Inc, F extends string> = F extends keyof NonNullable<Inc> ? NonNullable<Inc>[F] | (undefined extends Inc ? undefined : never) : undefined;
168
+ type SlotFor<D, T extends keyof D & string, F extends string, Inc> = TypedSlot<ValueOf<D, T, F>, T, F> & IncludedSlot<D, T, F, IncludeSpec<Inc, F>>;
169
+ /** Whether a `select` is given for sure (not `undefined`, nor maybe `undefined`). */
170
+ type NoSelect<Sel> = [Sel] extends [undefined] ? true : unknown extends Sel ? true : false;
171
+ /** Fields there for sure: every field without a `select`, else those selected with `true`. */
172
+ type SureFields<D, T extends keyof D, Sel> = NoSelect<Sel> extends true ? FieldOf<D, T> : {
173
+ [F in keyof NonNullable<Sel>]-?: [NonNullable<Sel>[F]] extends [true] ? F : never;
174
+ }[keyof NonNullable<Sel>] & FieldOf<D, T>;
175
+ /**
176
+ * Fields that may be there: with a `select` that may be absent this time, every other field; with a
177
+ * field selected by a `boolean` decided at run time, that field.
178
+ */
179
+ type MaybeFields<D, T extends keyof D, Sel> = NoSelect<Sel> extends true ? never : undefined extends Sel ? Exclude<FieldOf<D, T>, SureFields<D, T, Sel>> : Exclude<{
180
+ [F in keyof NonNullable<Sel>]-?: true extends NonNullable<Sel>[F] ? F : never;
181
+ }[keyof NonNullable<Sel>] & FieldOf<D, T>, SureFields<D, T, Sel>>;
182
+ /**
183
+ * The ways back an `include` lists: there for sure on `true` or `{ … }`, not there on `false`, maybe
184
+ * there on a `boolean` decided at run time.
185
+ */
186
+ type RelationRows<D, T extends keyof D, Inc> = {
187
+ readonly [K in RelationOf<D, T> as [IncludeSpec<Inc, K>] extends [true | object] ? K : never]: ReadonlyArray<IncludedRow<D, RelationTable<D, T, K>, IncludeSpec<Inc, K>>>;
188
+ } & {
189
+ readonly [K in RelationOf<D, T> as [IncludeSpec<Inc, K>] extends [false | undefined] ? never : [IncludeSpec<Inc, K>] extends [true | object] ? never : K]?: ReadonlyArray<IncludedRow<D, RelationTable<D, T, K>, Exclude<IncludeSpec<Inc, K>, boolean | undefined>>>;
190
+ };
191
+ /**
192
+ * The platform's part of a row: its id, and (a stored row, not the session) when it was created and
193
+ * last written, ISO 8601.
194
+ */
195
+ type RowSystem<T> = Readonly<{
196
+ id: Id<T & string>;
197
+ }> & (T extends 'session' ? unknown : Readonly<{
198
+ createdAt: string;
199
+ updatedAt: string;
200
+ }>);
201
+ /** A row as `db` returns it: `id`, its times, one slot per field, and the ways back it `include`s. */
202
+ export type RowOf<D, T extends keyof D, Inc = undefined, Sel = undefined> = RowSystem<T> & {
203
+ readonly [F in SureFields<D, T, Sel>]: SlotFor<D, T & string, F, Inc>;
204
+ } & {
205
+ readonly [F in MaybeFields<D, T, Sel>]?: SlotFor<D, T & string, F, Inc>;
206
+ } & RelationRows<D, T, Inc>;
207
+ type Ord = 'asc' | 'desc';
208
+ type OrderByArg<D, T extends keyof D> = {
209
+ [F in FieldOf<D, T> | RowTime]?: Ord;
210
+ } | ReadonlyArray<{
211
+ [F in FieldOf<D, T> | RowTime]?: Ord;
212
+ }>;
213
+ /** A `multi_select`'s filter (27 §3.2): Prisma's scalar-list filters, plus the slot's state. */
214
+ type ListValueFilter<V extends readonly unknown[]> = V | null | {
215
+ equals?: V | null;
216
+ has?: V[number];
217
+ hasSome?: readonly V[number][];
218
+ hasEvery?: readonly V[number][];
219
+ isEmpty?: boolean;
220
+ state?: SlotState;
221
+ };
222
+ type ScalarFilter<V> = [V] extends [readonly unknown[]] ? ListValueFilter<V> : ScalarFilterOf<V>;
223
+ type ScalarFilterOf<V> = V | null | {
224
+ equals?: V | null;
225
+ in?: readonly V[];
226
+ notIn?: readonly V[];
227
+ not?: V | null;
228
+ lt?: V;
229
+ lte?: V;
230
+ gt?: V;
231
+ gte?: V;
232
+ /** A text's beginning; there is no `contains` / `endsWith`: find by a beginning or an exact field (34 §10). */
233
+ startsWith?: string;
234
+ /** `insensitive`: text compared in any case (`equals`, `in`, `startsWith`, ranges). */
235
+ mode?: 'default' | 'insensitive';
236
+ /** By the slot's state (`asked_unknown`, `declined`, …): the one extension to Prisma's `where`. */
237
+ state?: SlotState;
238
+ };
239
+ type IdFilter<R extends string> = Id<R> | null | {
240
+ equals?: Id<R> | null;
241
+ in?: readonly Id<R>[];
242
+ notIn?: readonly Id<R>[];
243
+ not?: Id<R> | null;
244
+ state?: SlotState;
245
+ };
246
+ /** A row time (ISO 8601), compared as the instant it names. */
247
+ type TimeFilter = string | {
248
+ equals?: string;
249
+ in?: readonly string[];
250
+ notIn?: readonly string[];
251
+ not?: string;
252
+ lt?: string;
253
+ lte?: string;
254
+ gt?: string;
255
+ gte?: string;
256
+ };
257
+ /** `is` / `isNot` on a ref: one level only (a nested `is` is refused; read those rows first, then `in`). */
258
+ type RelationFilter<D, R extends keyof D> = {
259
+ is?: WhereFields<D, R, false> | null;
260
+ isNot?: WhereFields<D, R, false> | null;
261
+ };
262
+ /** `some` / `every` / `none` on a way back: one level only, like `is`. */
263
+ type ListFilter<D, R extends keyof D> = {
264
+ some?: WhereFields<D, R, false>;
265
+ every?: WhereFields<D, R, false>;
266
+ none?: WhereFields<D, R, false>;
267
+ };
268
+ type WhereFields<D, T extends keyof D, Rel extends boolean> = {
269
+ id?: IdFilter<T & string>;
270
+ } & {
271
+ [K in RowTime]?: TimeFilter;
272
+ } & {
273
+ [F in FieldOf<D, T>]?: Desc<D, T, F> extends {
274
+ ref: infer R extends string;
275
+ } ? IdFilter<R> | (Rel extends true ? RelationFilter<D, R & keyof D> : never) : ScalarFilter<Desc<D, T, F>['value']>;
276
+ } & (Rel extends true ? {
277
+ [K in RelationOf<D, T>]?: ListFilter<D, RelationTable<D, T, K>>;
278
+ } : unknown) & {
279
+ AND?: WhereFields<D, T, Rel> | ReadonlyArray<WhereFields<D, T, Rel>>;
280
+ OR?: ReadonlyArray<WhereFields<D, T, Rel>>;
281
+ NOT?: WhereFields<D, T, Rel> | ReadonlyArray<WhereFields<D, T, Rel>>;
282
+ };
283
+ /** What anchors a read: an id, `{ equals: id }` or `{ in: ids }`. */
284
+ type Anchor<R extends string> = Id<R> | {
285
+ equals: Id<R>;
286
+ } | {
287
+ in: readonly Id<R>[];
288
+ };
289
+ /**
290
+ * A `where`: this table's fields and row times, starting at its top level from `id` or a ref field
291
+ * (the rows it pins), or from a condition on a field or a row time (the field index finds the rows;
292
+ * a long text cannot start one). A start inside `AND` works at run time but does not type-check: write
293
+ * it at the top level, it means the same.
294
+ */
295
+ export type Where<D, T extends keyof D> = {
296
+ [K in 'id' | RefFieldOf<D, T>]: WhereFields<D, T, true> & {
297
+ [P in K]: Anchor<K extends 'id' ? T & string : RefTable<D, T, K>>;
298
+ };
299
+ }['id' | RefFieldOf<D, T>] | {
300
+ [K in PlainFieldOf<D, T> | RowTime]: WhereFields<D, T, true> & {
301
+ [P in K]-?: NonNullable<WhereFields<D, T, true>[P & keyof WhereFields<D, T, true>]>;
302
+ };
303
+ }[PlainFieldOf<D, T> | RowTime];
304
+ /**
305
+ * `include` as written, with any key that is not a lookup (a parent, another table's field, a typo)
306
+ * turned into `never`, at every level: an inferred argument gets no excess-property check otherwise.
307
+ */
308
+ type ExactInclude<D, T extends keyof D, I> = {
309
+ [K in keyof I]: K extends LookupOf<D, T> ? I[K] extends {
310
+ include: infer N;
311
+ } ? Omit<I[K], 'include'> & {
312
+ include: ExactInclude<D, RefTable<D, T, K> & keyof D, N>;
313
+ } : I[K] : K extends RelationOf<D, T> ? I[K] extends object ? ExactRelationInclude<D, RelationTable<D, T, K>, I[K]> : I[K] : never;
314
+ };
315
+ /**
316
+ * A way back's `{ where, orderBy, skip, take, include }` as written, any other key `never`; its
317
+ * `where` checked key by key at its top level (the listed table's fields, `id`, its ways back,
318
+ * `AND` / `OR` / `NOT`), its `include` like any `include`.
319
+ */
320
+ type ExactRelationInclude<D, R extends keyof D, S> = {
321
+ [P in keyof S]: P extends 'include' ? ExactInclude<D, R, S[P]> : P extends 'where' ? {
322
+ [W in keyof S[P]]: W extends FieldOf<D, R> | RelationOf<D, R> | 'id' | RowTime | 'AND' | 'OR' | 'NOT' ? S[P][W] : never;
323
+ } : P extends 'orderBy' | 'skip' | 'take' ? S[P] : never;
324
+ };
325
+ /** `select` as written, with any key that is not a field of the table turned into `never`. */
326
+ type ExactSelect<D, T extends keyof D, S> = {
327
+ [K in keyof S]: K extends FieldOf<D, T> ? S[K] : never;
328
+ };
329
+ /**
330
+ * `include` / `select`: left out, or written. Written, the key is required here so inference keeps an
331
+ * `undefined` in its value (`include: flag ? { … } : undefined`); an optional key would drop it.
332
+ */
333
+ type IncludeKey<D, T extends keyof D, I> = {
334
+ include?: undefined;
335
+ } | {
336
+ include: I & ExactInclude<D, T, I>;
337
+ };
338
+ type SelectKey<D, T extends keyof D, S> = {
339
+ select?: undefined;
340
+ } | {
341
+ select: S & ExactSelect<D, T, S>;
342
+ };
343
+ /**
344
+ * `after`: a row of the table as read, whatever its `include` / `select` (normally the last of the page
345
+ * before); the rows strictly after it in the read's order come (define.ts `FindArgs.after`).
346
+ */
347
+ type AfterRow<T> = Readonly<{
348
+ id: Id<T & string>;
349
+ createdAt?: string;
350
+ updatedAt?: string;
351
+ }> & {
352
+ readonly [field: string]: unknown;
353
+ };
354
+ export type FindManyArgs<D, T extends keyof D, I = IncludeArg<D, T>, S = SelectArg<D, T>> = IncludeKey<D, T, I> & SelectKey<D, T, S> & {
355
+ where: Where<D, T>;
356
+ orderBy?: OrderByArg<D, T>;
357
+ take?: number;
358
+ skip?: number;
359
+ after?: AfterRow<T>;
360
+ };
361
+ /** `findUnique`: by `id`; null when there is no such row. */
362
+ export type FindUniqueArgs<D, T extends keyof D, I = IncludeArg<D, T>, S = SelectArg<D, T>> = IncludeKey<D, T, I> & SelectKey<D, T, S> & {
363
+ where: {
364
+ id: Id<T & string>;
365
+ };
366
+ };
367
+ /**
368
+ * One table's read methods: Prisma Client's read-only subset. Only `include` / `select` are inferred
369
+ * (they shape the rows returned), and checked key by key (`ExactInclude`, `ExactSelect`); `where` is
370
+ * checked as written. A stray field anywhere is an error.
371
+ */
372
+ export type TypedTableReader<D, T extends keyof D> = {
373
+ readonly $table: T;
374
+ findUnique<const I extends IncludeArg<D, T> | undefined = undefined, const S extends SelectArg<D, T> | undefined = undefined>(args: FindUniqueArgs<D, T, I, S>): Promise<RowOf<D, T, I, S> | null>;
375
+ findFirst<const I extends IncludeArg<D, T> | undefined = undefined, const S extends SelectArg<D, T> | undefined = undefined>(args: FindManyArgs<D, T, I, S>): Promise<RowOf<D, T, I, S> | null>;
376
+ findMany<const I extends IncludeArg<D, T> | undefined = undefined, const S extends SelectArg<D, T> | undefined = undefined>(args: FindManyArgs<D, T, I, S>): Promise<Array<RowOf<D, T, I, S>>>;
377
+ count(args: {
378
+ where: Where<D, T>;
379
+ }): Promise<number>;
380
+ };
381
+ /** `db` where only reading is allowed (a page render): this sequence's tables, read methods only. */
382
+ export type TypedReadDb<D> = {
383
+ readonly [T in TableOf<D>]: TypedTableReader<D, T>;
384
+ };
385
+ type WriteValueOf<D, T extends keyof D, F> = ValueOf<D, T, F>;
386
+ /** A new row: its parent required, any other field optional. */
387
+ export type CreateData<D, T extends keyof D> = Simplify<{
388
+ [F in ParentOf<D, T>]: WriteValueOf<D, T, F>;
389
+ } & {
390
+ [F in Exclude<FieldOf<D, T>, ParentOf<D, T>>]?: WriteValueOf<D, T, F> | null;
391
+ }>;
392
+ /** A change to a row: any field but the parent. */
393
+ export type UpdateData<D, T extends keyof D> = {
394
+ [F in Exclude<FieldOf<D, T>, ParentOf<D, T>>]?: WriteValueOf<D, T, F> | null;
395
+ };
396
+ type TableWrites<D, T extends keyof D> = {
397
+ update(args: {
398
+ where: {
399
+ id: Id<T & string>;
400
+ };
401
+ data: UpdateData<D, T>;
402
+ }): Promise<{
403
+ id: Id<T & string>;
404
+ }>;
405
+ delete(args: {
406
+ where: {
407
+ id: Id<T & string>;
408
+ };
409
+ reason?: string;
410
+ }): Promise<{
411
+ id: Id<T & string>;
412
+ }>;
413
+ } & (T extends 'session' ? unknown : {
414
+ create(args: {
415
+ data: CreateData<D, T>;
416
+ }): Promise<{
417
+ id: Id<T & string>;
418
+ }>;
419
+ /**
420
+ * The row whose `unique` field in `where` holds that value, updated; else a new row with it
421
+ * (18-record-search-index §4.5). `where` names exactly one `unique` field.
422
+ */
423
+ upsert(args: {
424
+ where: {
425
+ [F in Exclude<FieldOf<D, T>, ParentOf<D, T>>]?: WriteValueOf<D, T, F>;
426
+ };
427
+ create: CreateData<D, T>;
428
+ update: UpdateData<D, T>;
429
+ }): Promise<{
430
+ id: Id<T & string>;
431
+ }>;
432
+ });
433
+ /**
434
+ * `db`: this sequence's tables, Prisma-shaped, reads and writes on one object. Writes are V1
435
+ * `create` / `update` / `delete`. A contact may be created (with
436
+ * no lookup for one with the same phone or email, 15 §10.6.1); session rows are not created here.
437
+ */
438
+ export type TypedDb<D> = {
439
+ readonly [T in TableOf<D>]: TypedTableReader<D, T> & TableWrites<D, T>;
440
+ };
441
+ type RowIfTable<D, T extends string> = T extends keyof D ? RowOf<D, T> : never;
442
+ /**
443
+ * One channel's page function context (20 §5.2): `C` the channel, with what only it has (`ctx.call`,
444
+ * `ctx.sms`, `ctx.email`). Without `C`, any channel's: what a helper shared by several pages takes.
445
+ */
446
+ export type TypedPageContext<D, S extends string, C extends PageChannel = PageChannel> = {
447
+ [K in C]: TypedPageBaseContext<D, S> & {
448
+ channel: K;
449
+ } & PageChannelCaps[K];
450
+ }[C];
451
+ type TypedPageBaseContext<D, S extends string> = {
452
+ /** Read-only: a render never writes. */
453
+ db: TypedReadDb<D>;
454
+ /** What the platform recorded (17b §7, 21 §6.7): `tried(ctx.runs, key)`, `tried(ctx.runs, key, 'case')`. */
455
+ runs: PageRuns;
456
+ /** Why this conversation happened when the platform started it; null for an inbound one. */
457
+ scheduledAction: PageScheduledAction | null;
458
+ /** The sequence's office hours now; null when it has none. */
459
+ officeHours: PageBaseContext['officeHours'];
460
+ /** The case's next step (40 §2.2): its pending contacts, soonest first; the platform shows it before the page. */
461
+ nextSteps: PageBaseContext['nextSteps'];
462
+ /** The business root's id. */
463
+ subject: Id<S>;
464
+ /** The instance this conversation is on: prefill it to a function that needs it (38 §2.2). */
465
+ instanceId: string;
466
+ /** The contact of the conversation; null outside one. */
467
+ caller: RowIfTable<D, 'contact'> | null;
468
+ /** This conversation's session row (the session fields, cells); null outside one. */
469
+ session: RowIfTable<D, 'session'> | null;
470
+ /** This conversation's platform facts (read-only, never a cell); null outside one. */
471
+ conversation: PageConversation | null;
472
+ /** Counts over this instance (`sessionCount`, `exchangeCount`). */
473
+ history: PageHistory;
474
+ /** ISO timestamp of this render. */
475
+ now: string;
476
+ /** The contact's time zone, today there, and `format` for a time as people read it (25 §11). */
477
+ time: PageTime;
478
+ /** The environment's configuration, read only (76 §2.19): `ctx.env.get('callback_number')`. */
479
+ env: PageBaseContext['env'];
480
+ };
481
+ export type TypedActionContext<D, S extends string> = {
482
+ db: TypedDb<D>;
483
+ subject: Id<S>;
484
+ caller: RowIfTable<D, 'contact'> | null;
485
+ /** On a call, this party's session for this case (25 §9); null by text and email. Written with `db.session.update`. */
486
+ session: RowIfTable<D, 'session'> | null;
487
+ now: string;
488
+ };
489
+ declare const CHOOSE_BRAND: unique symbol;
490
+ /** `choose(rows, label)` over rows of `T` (25 §10): the rows a row parameter of `T` is chosen among. */
491
+ export type TypedChoose<T extends string> = ChooseParam & {
492
+ readonly [CHOOSE_BRAND]?: T;
493
+ };
494
+ /**
495
+ * What the page fixed of an action's parameters (35 §2): values, a row parameter by its row's id; an
496
+ * optional one also `null`, none (the AI is not asked).
497
+ */
498
+ export type PrefillOf<A> = {
499
+ [K in keyof A]?: A[K] | (undefined extends A[K] ? null : never);
500
+ };
501
+ /** The parameters of `A` that are rows. */
502
+ type RowKeys<A> = {
503
+ [K in keyof A]-?: NonNullable<A[K]> extends {
504
+ readonly [ID_BRAND]: string;
505
+ } ? K : never;
506
+ }[keyof A];
507
+ /**
508
+ * The rows the AI chooses a row parameter among, each with its label (35 §2): `choose(rows, label)`.
509
+ * With no row parameter there is nothing to choose: `options` takes nothing (`{}` would take anything).
510
+ */
511
+ export type OptionsOf<A> = [RowKeys<A>] extends [never] ? never : {
512
+ [K in RowKeys<A>]?: NonNullable<A[K]> extends {
513
+ readonly [ID_BRAND]: infer T extends string;
514
+ } ? TypedChoose<T> : never;
515
+ };
516
+ /** A page action's function (76 §2.11): `(ctx, args)`; what it is called with is the button's `prefill` and what the AI fills. */
517
+ export type PageActionFn<A> = (ctx: never, args: A) => unknown;
518
+ /** What a page function returns: `page(…)`, or `doNow(…)` to do something first (76). */
519
+ export type PageResult = PageNode | DoNode;
520
+ /** The page module of one sequence: `D` its tables (`PageTables`), `S` its business root table. */
521
+ export type TypedPageModule<D, S extends string> = {
522
+ /** Each channel's page is its own (17b §9.1): what a call shows and what a text shows may differ. */
523
+ definePage<Call extends PageResult = never, Sms extends PageResult = never, Email extends PageResult = never>(definition: {
524
+ /** Called once when the conversation starts (24 §4): the persona for `ctx.channel`. */
525
+ persona: (ctx: TypedPageContext<D, S>) => string | Promise<string>;
526
+ /** Called once when the conversation starts (24 §4): the FAQ, at most 100 entries. */
527
+ faq?: (ctx: TypedPageContext<D, S>) => PageFaqEntry[] | Promise<PageFaqEntry[]>;
528
+ call?: (ctx: TypedPageContext<D, S, 'call'>) => Call | Promise<Call>;
529
+ sms?: (ctx: TypedPageContext<D, S, 'sms'>) => Sms | Promise<Sms>;
530
+ email?: (ctx: TypedPageContext<D, S, 'email'>) => Email | Promise<Email>;
531
+ }): {
532
+ kind: 'page';
533
+ persona: PagePersona;
534
+ faq: PageFaq | null;
535
+ channels: {
536
+ call?: (ctx: TypedPageContext<D, S, 'call'>) => Call | Promise<Call>;
537
+ sms?: (ctx: TypedPageContext<D, S, 'sms'>) => Sms | Promise<Sms>;
538
+ email?: (ctx: TypedPageContext<D, S, 'email'>) => Email | Promise<Email>;
539
+ };
540
+ };
541
+ /** The rows a row parameter is chosen among, each with what the AI sees of it (25 §10). */
542
+ choose<R extends {
543
+ readonly id: Id<TableOf<D>>;
544
+ }>(rows: readonly R[], label: (row: R) => string): TypedChoose<R['id'] extends {
545
+ readonly [ID_BRAND]: infer T extends string;
546
+ } ? T : never>;
547
+ };
548
+ type AnySlot = TypedSlot<unknown, string, string>;
549
+ /** What a function takes: its `args`, the second parameter of `(ctx, args)` (38 §2.1). */
550
+ export type FunctionParamsOf<Fn> = Fn extends (...args: infer A) => unknown ? A extends [unknown, infer P, ...unknown[]] ? P extends object ? P : Record<never, never> : Record<never, never> : Record<never, never>;
551
+ /** `table.field` of this sequence: how the page says to fill it (`page({ extraction })`). */
552
+ type FieldPathOf<D> = {
553
+ [T in TableOf<D>]: `${T}.${FieldOf<D, T>}`;
554
+ }[TableOf<D>];
555
+ /** `fn` of `__gen` (76 §2.15): a handle per company function, its `args` type the function's. */
556
+ export type FunctionHandles<F> = {
557
+ readonly [N in keyof F & string]: FunctionHandle<N, FunctionParamsOf<F[N]>>;
558
+ };
559
+ /**
560
+ * `act` of `__gen` (76 §2.11): a handle per page action of `actions.ts`, its `args` type the action's. An
561
+ * action takes the page action's `ctx` (`ActionCtx`): one written for another (a company function's `Ctx`)
562
+ * has no handle, and `run()` says so.
563
+ */
564
+ export type ActionHandles<A, D, S extends string> = {
565
+ readonly [N in keyof A & string]: A[N] extends (ctx: TypedActionContext<D, S>, ...rest: never[]) => unknown ? PageActionHandle<N, FunctionParamsOf<A[N]>> : `actions.${N} takes (ctx: ActionCtx, args): the page action's ctx`;
566
+ };
567
+ /** Add a row of `T` (15 §10.6): `fields` the AI fills, `prefill` what the page fixed, `options` a ref field's rows. */
568
+ type CreateRowOptions<D, T extends TableOf<D>> = {
569
+ /** What the AI fills; a ref field is chosen in `options` instead (35 §2). */
570
+ fields: ReadonlyArray<Exclude<FieldOf<D, T>, ParentOf<D, T> | RowKeys<CreateData<D, T>>>>;
571
+ required?: ReadonlyArray<Exclude<FieldOf<D, T>, ParentOf<D, T>>>;
572
+ prefill?: Partial<CreateData<D, T>>;
573
+ /** The rows the AI chooses a ref field's row among (35 §2). */
574
+ options?: OptionsOf<Omit<CreateData<D, T>, ParentOf<D, T>>>;
575
+ };
576
+ /**
577
+ * The fields a prefill surely fills: there, and never null, undefined or a written-out '' (76 §2.14), as
578
+ * the write counts them; a `string` from code counts as filled (the render refuses it when it is ''). `{ body_part: null }`, `''` or a value that may be missing fills nothing: a required field prefilled so is still nobody's.
579
+ */
580
+ type FilledKeys<P> = {
581
+ [X in keyof P]-?: undefined extends P[X] ? never : null extends P[X] ? never : string extends P[X] ? X : '' extends P[X] ? never : X;
582
+ }[keyof P];
583
+ /** The page's functions bound to one sequence (76 §2.17): what `__gen/index.ts` exports. */
584
+ export type TypedPageFns<D, S extends string, F> = {
585
+ /** The page (76 §2.7): settings, then content by name. */
586
+ page(settings: PageSettings<{
587
+ readonly [K in FieldPathOf<D>]?: string;
588
+ }>, content: PageContent): PageNode;
589
+ /** A field the AI may write, or read only. A ref field is `refField()`. */
590
+ field(slot: AnySlot, options?: {
591
+ readOnly?: boolean;
592
+ expand?: boolean;
593
+ }): FieldNode;
594
+ /** A ref field: writable, the rows it may be set to (`options`); read-only, who its value is (`label`). */
595
+ refField(slot: AnySlot, options: {
596
+ options: ReadonlyArray<RefOption> | ChooseParam;
597
+ readOnly?: false;
598
+ } | {
599
+ readOnly: true;
600
+ label?: string;
601
+ }): FieldNode;
602
+ /** Add a row (15 §10.6). */
603
+ createRow<T extends TableOf<D>, const R extends ReadonlyArray<Exclude<FieldOf<D, T>, ParentOf<D, T>>> = [], P extends Partial<CreateData<D, T>> = {}, K extends string | undefined = undefined>(table: T, options: Omit<CreateRowOptions<D, T>, 'options' | 'required' | 'prefill'> & {
604
+ required?: R;
605
+ prefill?: P & {
606
+ readonly [X in Exclude<keyof P, keyof CreateData<D, T>>]: `${X & string} is not a field of ${T}`;
607
+ };
608
+ options?: undefined;
609
+ runKey?: K;
610
+ }): Action<'createRow', KeyedOf<K>, [Exclude<R[number], FilledKeys<P>>] extends [never] ? AllPrefilled : LeftForAi>;
611
+ /** With `options`, the AI chooses a ref field's row: a button's, never `doNow()`'s. */
612
+ createRow<T extends TableOf<D>, K extends string | undefined = undefined>(table: T, options: CreateRowOptions<D, T> & {
613
+ options: NonNullable<CreateRowOptions<D, T>['options']>;
614
+ runKey?: K;
615
+ }): Action<'createRow', KeyedOf<K>, LeftForAi>;
616
+ /**
617
+ * Run a company function (`fn.x`) or a page action (76 §2.15): every required parameter prefilled
618
+ * (what `doNow()` takes), or some left for the AI. `options` are rows of each row parameter's own table.
619
+ */
620
+ run<H extends AnyRunHandle, K extends string | undefined = undefined>(handle: H & SameArgs<H>, options: ([RequiredKeys<RunArgs<H>>] extends [never] ? {
621
+ prefill?: PrefillOf<RunArgs<H>>;
622
+ } : {
623
+ prefill: FullPrefill<RunArgs<H>>;
624
+ }) & {
625
+ options?: undefined;
626
+ args?: undefined;
627
+ say?: SayOf<H>;
628
+ runKey?: K;
629
+ }): RunAction<KeyedOf<K>, AllPrefilled>;
630
+ run<H extends AnyRunHandle, K extends string | undefined = undefined>(handle: H & SameArgs<H>, options?: {
631
+ prefill?: PrefillOf<RunArgs<H>>;
632
+ options?: OptionsOf<RunArgs<H>>;
633
+ args?: {
634
+ [P in keyof RunArgs<H>]?: string;
635
+ };
636
+ say?: SayOf<H>;
637
+ runKey?: K;
638
+ }): RunAction<KeyedOf<K>, LeftForAi>;
639
+ /** Delete a row and everything under it (15 §10.6.1). */
640
+ deleteRow<K extends string | undefined = undefined>(row: Id<TableOf<D>> | {
641
+ readonly id: Id<TableOf<D>>;
642
+ }, options?: {
643
+ reason?: string;
644
+ runKey?: K;
645
+ }): Action<'deleteRow', KeyedOf<K>, AllPrefilled>;
646
+ };
647
+ export {};
648
+ //# sourceMappingURL=typed.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=typed.js.map