@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,904 @@
1
+ /**
2
+ * The page module (15 §10.2–§10.6): what a sequence's `context.page.ts` is written with. It runs
3
+ * inside the QuickJS sandbox, bundled into the page script, so it imports nothing at runtime and only
4
+ * uses `globalThis.__host` (the sandbox's async host call, services `page/sandbox.ts`).
5
+ *
6
+ * A page script reads with `db` and returns a page written with functions (76): `page(…)`, or
7
+ * `doNow(…)` to do something first. The page functions (`fns.ts`) are built from what is here (a
8
+ * field's cell, a button's action) and cross the sandbox as an envelope; the platform turns it into a
9
+ * `RenderedPage` (`render.ts`).
10
+ */
11
+ import { type Channel, type Direction, type Spoken } from '../conversation/index.js';
12
+ import type { TimelineEntry, TimelineWhere } from './timeline.js';
13
+ import type { TimeParts } from './time-format.js';
14
+ export type SlotState = 'filled' | 'empty' | 'asked_unknown' | 'declined';
15
+ export type SlotRef = {
16
+ table: string;
17
+ id: string;
18
+ field: string;
19
+ };
20
+ /** One field as read: plain data, never mutated. */
21
+ export type Slot<V = unknown> = Readonly<{
22
+ value: V | null;
23
+ state: SlotState;
24
+ reason: string | null;
25
+ updatedAt: string | null;
26
+ ref: SlotRef;
27
+ /** The target row, on a lookup that was `include`d. */
28
+ row?: PageRow | null;
29
+ }>;
30
+ /** A row as `db` returns it: `id`, one slot per field. */
31
+ export type PageRow = {
32
+ readonly id: string;
33
+ } & {
34
+ readonly [field: string]: unknown;
35
+ };
36
+ export type FindArgs = {
37
+ where?: Record<string, unknown>;
38
+ include?: Record<string, unknown>;
39
+ select?: Record<string, boolean>;
40
+ orderBy?: Record<string, 'asc' | 'desc'> | Array<Record<string, 'asc' | 'desc'>>;
41
+ take?: number;
42
+ skip?: number;
43
+ /**
44
+ * Where a page starts: a row as `db` returned it, normally the last of the page before. The rows
45
+ * strictly after it in this read's order come (`orderBy`, then creation, then id; rows without a
46
+ * value of the order field last), then `skip`. Read by value, never looked up: a row deleted or
47
+ * changed since still marks where it was. It needs the row's `id` and `createdAt`, its `updatedAt`
48
+ * when ordered by that, and the slot of each field ordered by (keep it in `select`). Only that place
49
+ * is sent (over `ctx.api.db`, not the rest of the row and what it included); an order value not of
50
+ * its field's type is refused.
51
+ */
52
+ after?: PageRow;
53
+ };
54
+ /** One table's read methods (Prisma Client's read-only subset). */
55
+ export type TableReader<Row = PageRow> = {
56
+ readonly $table: string;
57
+ findUnique(args: {
58
+ where: Record<string, unknown>;
59
+ include?: FindArgs['include'];
60
+ select?: FindArgs['select'];
61
+ }): Promise<Row | null>;
62
+ findFirst(args: FindArgs): Promise<Row | null>;
63
+ findMany(args: FindArgs): Promise<Row[]>;
64
+ count(args: {
65
+ where: Record<string, unknown>;
66
+ }): Promise<number>;
67
+ };
68
+ /**
69
+ * Prisma-shaped writes of an action's `run` (15 §10.6.1): create / update / upsert / delete. `upsert`
70
+ * finds the row by one `unique` field (18-record-search-index §4.5): updated when there is one, else
71
+ * created with that value.
72
+ */
73
+ export type TableWriter = {
74
+ create(args: {
75
+ data: Record<string, unknown>;
76
+ }): Promise<{
77
+ id: string;
78
+ }>;
79
+ update(args: {
80
+ where: {
81
+ id: string;
82
+ };
83
+ data: Record<string, unknown>;
84
+ }): Promise<{
85
+ id: string;
86
+ }>;
87
+ upsert(args: {
88
+ where: Record<string, unknown>;
89
+ create: Record<string, unknown>;
90
+ update: Record<string, unknown>;
91
+ }): Promise<{
92
+ id: string;
93
+ }>;
94
+ delete(args: {
95
+ where: {
96
+ id: string;
97
+ };
98
+ reason?: string;
99
+ }): Promise<{
100
+ id: string;
101
+ }>;
102
+ };
103
+ /** `db` where only reading is allowed (a page render): each table's read methods. */
104
+ export type ReadDb = {
105
+ readonly [table: string]: TableReader;
106
+ };
107
+ /** `db`, Prisma-shaped: each table's read and write methods on one object. */
108
+ export type Db = {
109
+ readonly [table: string]: TableReader & TableWriter;
110
+ };
111
+ /**
112
+ * What the platform knows about this conversation (11-remove-sequence-schema §3.3): written once when
113
+ * its session opened, read-only, never a cell.
114
+ */
115
+ export type PageConversation = {
116
+ /** The session id. */
117
+ id: string;
118
+ channel: Channel;
119
+ /** Who started this conversation; a resumed one keeps it. */
120
+ direction: Direction;
121
+ /** The contact was created while this conversation opened. */
122
+ isNewContact: boolean;
123
+ /** ISO timestamp the session opened. */
124
+ startedAt: string;
125
+ /** The provider's id of the call (Twilio's CallSid, 62), as the resolve got it; null when unknown. */
126
+ externalId: string | null;
127
+ };
128
+ /**
129
+ * Counts over this instance, worked out when the page renders (11-remove-sequence-schema §3.3.1).
130
+ * The first call of the instance is `await history.sessionCount({ channel: 'call' }) === 1`.
131
+ */
132
+ export type PageHistory = {
133
+ /** Conversations (sessions) of this instance, every contact, the current one included. */
134
+ sessionCount(where?: {
135
+ channel?: Channel;
136
+ }): Promise<number>;
137
+ /**
138
+ * Exchanges of this instance recorded so far (an unanswered dial included). The current
139
+ * conversation's own is recorded once its first step is decided, so the opening decision does not
140
+ * count it (a scheduled call's, written before dialing, it does); later turns do. "Is this the first
141
+ * call" is `sessionCount`'s question.
142
+ */
143
+ exchangeCount(where?: {
144
+ channel?: Channel;
145
+ direction?: Direction;
146
+ }): Promise<number>;
147
+ /**
148
+ * The case's timeline (20 §3): messages, calls, the AI's runs and actions, field changes, scheduled
149
+ * contacts, oldest first; the newest `limit` (50) unless `before` pages back. A text page can show the
150
+ * last call; a call page, the texts since.
151
+ */
152
+ timeline(where?: TimelineWhere): Promise<TimelineEntry[]>;
153
+ };
154
+ /** The channels a page function is written for (17b §9.1, 20 §5.1): one page function per channel. */
155
+ export type PageChannel = 'call' | 'sms' | 'email';
156
+ /**
157
+ * What the platform recorded (17b §9.8), read-only. `actions` by action key: every run of an action in
158
+ * this run on this case (one the page function returned, or a button the AI pressed), oldest first;
159
+ * `caseActions` the same for the whole case, every channel and run (21 §6.7).
160
+ */
161
+ export type PageRuns = {
162
+ actions: Record<string, PageActionRun[]>;
163
+ caseActions: Record<string, PageActionRun[]>;
164
+ };
165
+ /** Where `tried()` and `lastActionRun()` look: this run on this case (the default), or the whole case. */
166
+ export type ActionRunScope = 'run' | 'case';
167
+ /** `started`: under way (a keypad or a transfer waiting for its result, a function running). */
168
+ export type PageActionRun = {
169
+ result: 'ok' | 'failed' | 'started';
170
+ /** ISO time. */
171
+ at: string;
172
+ error?: string;
173
+ /** What a channel action brought back (the digits pressed), or what a function returned (25 §11, as text). */
174
+ value?: string;
175
+ };
176
+ /** Whether the action `key` ran at least once (whatever its result), in this run or (`'case'`) on the case. */
177
+ export declare function tried(runs: PageRuns | null | undefined, key: string, scope?: ActionRunScope): boolean;
178
+ /** The latest run of the action `key`, in this run or (`'case'`) on the case, if any. */
179
+ export declare function lastActionRun(runs: PageRuns | null | undefined, key: string, scope?: ActionRunScope): PageActionRun | null;
180
+ /**
181
+ * The case's next step (40 §2.2): its pending contact — when, on which channel, whom, why, and where it
182
+ * was booked. Independent appointments may coexist (51); the platform shows them after every conversation page.
183
+ */
184
+ export type PageNextStep = {
185
+ id: string;
186
+ name?: string | null;
187
+ channel: 'call' | 'sms' | 'email';
188
+ /** When it runs, ISO 8601. */
189
+ at: string;
190
+ /** Whom it contacts: the contact's id, and what they are called (their name, else their phone or email; null when none is on file). */
191
+ contact: {
192
+ id: string;
193
+ name: string | null;
194
+ };
195
+ /** Why (40 §2.6); null when nobody said. */
196
+ reason: string | null;
197
+ /** The contact's own words asking for it or agreeing to it (an agreed follow-up, 09); null otherwise. */
198
+ customerQuote: string | null;
199
+ /** The conversation it was booked in, its channel and when it started; null: booked outside one (the Orchestrator, company code). */
200
+ bookedIn: {
201
+ channel: 'call' | 'sms' | 'email';
202
+ at: string;
203
+ } | null;
204
+ };
205
+ /**
206
+ * The button that books the case's next step (40 §2.2): what the customer asked for or agreed to, or
207
+ * what the AI decides the case needs. The AI gives when, the channel, why, and the customer's words
208
+ * when they said it (an agreed follow-up, 09); whom is the conversation's contact unless the page lets
209
+ * the AI choose (`options`) or fixes one (`prefill`). It adds an independent appointment, or edits one explicitly by ID (51).
210
+ */
211
+ export type FollowUpAction = {
212
+ $action: 'followUp';
213
+ /** The run key (default `followUp`). */
214
+ key: string;
215
+ /** The channels it may book, of the ones this sequence has a page for. */
216
+ channels: Array<'call' | 'sms' | 'email'>;
217
+ /** What the page fixed: the channel (one of `channels`), whom (a contact row's id); `contactId: choose(...)`: the contacts the AI chooses among. */
218
+ prefill?: {
219
+ channel?: 'call' | 'sms' | 'email';
220
+ contactId?: string | ChooseParam;
221
+ };
222
+ label?: string;
223
+ description?: string;
224
+ };
225
+ /** The button that cancels the case's next step (40 §2.2), with why. */
226
+ export type CancelFollowUpAction = {
227
+ $action: 'cancelFollowUp';
228
+ /** The run key (default `cancelFollowUp`). */
229
+ key: string;
230
+ label?: string;
231
+ description?: string;
232
+ };
233
+ /** The next-step button (`scheduleFollowUp({ channels })`, 76). */
234
+ export declare function followUpAction(options: {
235
+ channels: Array<'call' | 'sms' | 'email'>;
236
+ key?: string;
237
+ label?: string;
238
+ description?: string;
239
+ prefill?: Record<string, unknown>;
240
+ }): FollowUpAction;
241
+ /** The cancel-next-step button (`cancelFollowUp()`, 76). */
242
+ export declare function cancelFollowUpAction(options?: {
243
+ key?: string;
244
+ label?: string;
245
+ description?: string;
246
+ }): CancelFollowUpAction;
247
+ /**
248
+ * One FAQ entry (24 §7): its id, what it covers (the catalog in the prompt shows these two), and the
249
+ * answer (the AI fetches it with `get_faq`).
250
+ */
251
+ export type PageFaqEntry = {
252
+ id: string;
253
+ description: string;
254
+ content: string;
255
+ };
256
+ /** At most this many FAQ entries in a conversation (24 §7.2): the catalog is in every prompt. */
257
+ export declare const MAX_FAQ_ENTRIES = 100;
258
+ /** What the page decides once, when the conversation starts (24 §4): who the AI is, and its FAQ. */
259
+ export type PageStart = {
260
+ persona: string;
261
+ faq: PageFaqEntry[];
262
+ };
263
+ /** The scheduled contact this conversation carries out (an outbound call or message, 09 §3.5). */
264
+ export type PageScheduledAction = {
265
+ id: string;
266
+ /** What the contact agreed to, in the exchange where they agreed; null for a routine follow-up. */
267
+ agreedInExchangeId: string | null;
268
+ /** The contact's own words agreeing to it; null for a routine follow-up. */
269
+ customerQuote: string | null;
270
+ note: string | null;
271
+ /** ISO time it was scheduled for. */
272
+ scheduledFor: string;
273
+ };
274
+ export type PageBaseContext = {
275
+ /** Read-only: a render never writes. */
276
+ db: ReadDb;
277
+ /** What the platform recorded in this conversation; empty outside one. */
278
+ runs: PageRuns;
279
+ /** Why this conversation happened when the platform started it (17b §9.2); null for an inbound one. */
280
+ scheduledAction: PageScheduledAction | null;
281
+ /** The sequence's office hours now; null when it has none. */
282
+ officeHours: {
283
+ open: boolean;
284
+ timezone: string;
285
+ today: Array<{
286
+ start: string;
287
+ end: string;
288
+ }>;
289
+ } | null;
290
+ /**
291
+ * The case's independent pending contact appointments (51), soonest first. The platform shows
292
+ * their stable IDs before the page. `scheduleFollowUp()` adds or edits one; `cancelFollowUp()`
293
+ * cancels an explicit target. Empty when nothing is booked.
294
+ */
295
+ nextSteps: PageNextStep[];
296
+ /** The business root's id. */
297
+ subject: string;
298
+ /** The instance this conversation is on: prefill it to a function that needs it (38 §2.2). */
299
+ instanceId: string;
300
+ /** The contact of the conversation; null outside one. */
301
+ caller: PageRow | null;
302
+ /** This conversation's session row (the session fields, cells); null outside one. */
303
+ session: PageRow | null;
304
+ /** This conversation's platform facts; null outside one. */
305
+ conversation: PageConversation | null;
306
+ /** Counts over this instance. */
307
+ history: PageHistory;
308
+ /** ISO timestamp of this render. */
309
+ now: string;
310
+ /** Times for people (25 §11): the sandbox has no `Intl`, so formatting goes through the platform. */
311
+ time: PageTime;
312
+ /**
313
+ * The environment's configuration, read only (76 §2.19): the values of its `env` integrations, the
314
+ * same functions read with `ctx.api.integration.envs`; null when no `env` integration has the key.
315
+ */
316
+ env: PageEnv;
317
+ };
318
+ /**
319
+ * `ctx.time` (25 §11): the contact's time zone and today there, `format` for a time as people read it,
320
+ * and `day` for the calendar day of a time. `zone` is the contact's `timezone`, else worked out from
321
+ * their postal code, state or phone.
322
+ */
323
+ export type PageTime = {
324
+ /** The contact's time zone (America/New_York without a contact). */
325
+ zone: string;
326
+ /** Today, `YYYY-MM-DD`, in `zone`. */
327
+ today: string;
328
+ /** `at` as people read it, in `timeZone` (default `zone`): "Tue, Nov 3, 3:00 PM EST". */
329
+ format(at: string, options?: {
330
+ timeZone?: string;
331
+ style?: 'datetime' | 'date' | 'time';
332
+ }): Promise<string>;
333
+ /** The calendar day (`YYYY-MM-DD`) at `at` in `timeZone` (default `zone`), to compare days or key a rule by date. */
334
+ day(at: string | number, timeZone?: string): Promise<string>;
335
+ /** The exact moment (ISO, UTC) a clock in `timeZone` (default `zone`) shows `date` at `time` (`HH:mm`), 74 §4.7. */
336
+ at(date: string, time: string, timeZone?: string): Promise<string>;
337
+ /** `at` on a clock in `timeZone` (default `zone`): date, `HH:mm`, hour, minute, ISO weekday, offset (74 §4.7). */
338
+ parts(at: string | number, timeZone?: string): Promise<TimeParts>;
339
+ };
340
+ /**
341
+ * A text the customer sent since the last run (20 §5.2): what this run is for. `earlier`: sent before,
342
+ * in a run that failed, and not answered yet (20 §5.4).
343
+ */
344
+ export type PageSmsMessage = {
345
+ id: string;
346
+ body: string;
347
+ at: string;
348
+ earlier?: boolean;
349
+ };
350
+ /** An email the customer sent since the last run (20 §5.2), quoted history and signature taken out. */
351
+ export type PageEmailMessage = {
352
+ id: string;
353
+ from: string;
354
+ to: string[];
355
+ cc: string[];
356
+ subject: string | null;
357
+ body: string;
358
+ at: string;
359
+ /** Listed only (20 §7): their contents are not read yet. */
360
+ attachments: Array<{
361
+ name: string;
362
+ contentType?: string;
363
+ }>;
364
+ /** Sent before, in a run that failed, and not answered yet (20 §5.4). */
365
+ earlier?: boolean;
366
+ };
367
+ /**
368
+ * This person's previous call on this case (21 §5.2): the facts a page decides by whether to pick up where it
369
+ * left off (a line dropped a minute ago) or open as usual (a call a week ago, or one handed to a person). A
370
+ * new call never carries the previous one's conversation or session fields.
371
+ */
372
+ export type PagePreviousCall = {
373
+ /** ISO time it ended. */
374
+ endedAt: string;
375
+ direction: Direction;
376
+ /** How the call went: connected, no_answer, busy, failed, fallback, apology. */
377
+ outcome: string | null;
378
+ /** How its conversation ended, when the AI took it: `hangup` (the line closed: the caller hung up, or it dropped), `end` (the AI ended it), `transfer`, `error`. */
379
+ endedBy: string | null;
380
+ /** Its last lines, oldest first. */
381
+ lastLines: Array<{
382
+ speaker: 'party' | 'ai';
383
+ text: string;
384
+ }>;
385
+ };
386
+ /**
387
+ * A voicemail greeting answered the outbound call, as the voice service tells it (65 §3.1); `said`: what
388
+ * it said. The page decides what to do: leave a message (`doNow(voicemail({ … }))`), or end (a full mailbox). A page
389
+ * that returns nothing for it has the voice service hang up. Anything else that answers (a person, a
390
+ * call-screening assistant, a phone menu) the page's model tells from the words; the page writes what to do.
391
+ */
392
+ export type PageFarEnd = {
393
+ kind: 'voicemail';
394
+ said: string;
395
+ };
396
+ /**
397
+ * The words this render answers (65 §3.2): what the person just said; `first`, the far end's first words
398
+ * on an outbound call, before the AI said anything (a "Hello?" can get the opening line at once, a long
399
+ * first sentence is the model's to answer). Null when the render answers no words (the opening, an event).
400
+ */
401
+ export type PageHeard = {
402
+ text: string;
403
+ first: boolean;
404
+ };
405
+ /** What only a call has (20 §5.2): on `ctx.call`. A call's own buttons (transfers, `keypad`) are left off a text's page (76 §2.12). */
406
+ export type PageCallCaps = {
407
+ /** This person's previous call on this case; null when there is none. */
408
+ previous: PagePreviousCall | null;
409
+ /** A voicemail answered, once the voice service knows (65 §3.1); null otherwise, and on an inbound call. */
410
+ farEnd: PageFarEnd | null;
411
+ /** The words this render answers (65 §3.2); null when it answers none. */
412
+ heard: PageHeard | null;
413
+ /**
414
+ * `live` while the call is on the line; `wrapup` once it has hung up and the AI finishes what the call
415
+ * left (40 §2.5): fields, buttons that need no line, notes. Nothing said is heard then.
416
+ */
417
+ phase: PageCallPhase;
418
+ };
419
+ /** Where a call is (40 §2.5): on the line, or its wrap-up after the hang-up. */
420
+ export type PageCallPhase = 'live' | 'wrapup';
421
+ /** What each channel adds to the page function's context (20 §5.2). */
422
+ export type PageChannelCaps = {
423
+ call: {
424
+ call: PageCallCaps;
425
+ };
426
+ sms: {
427
+ sms: {
428
+ inbound: PageSmsMessage[];
429
+ };
430
+ };
431
+ email: {
432
+ email: {
433
+ inbound: PageEmailMessage[];
434
+ mailbox: string;
435
+ };
436
+ };
437
+ };
438
+ /** The context of one channel's page function. */
439
+ export type PageContextOf<C extends PageChannel> = PageBaseContext & {
440
+ channel: C;
441
+ } & PageChannelCaps[C];
442
+ /** Any channel's context: what a helper shared by several page functions takes (switch on `channel`). */
443
+ export type PageContext = {
444
+ [C in PageChannel]: PageContextOf<C>;
445
+ }[PageChannel];
446
+ export type ActionContext = {
447
+ db: Db;
448
+ subject: string;
449
+ caller: PageRow | null;
450
+ /**
451
+ * On a call, this party's session for this case (25 §9), as `ctx.session` on the page; null by text and
452
+ * email. `db.session.update({ where: { id: session.id }, data })` writes it in the action's transaction.
453
+ */
454
+ session: PageRow | null;
455
+ now: string;
456
+ };
457
+ /**
458
+ * Page settings of a cell `field(...)` opens: `readOnly` to show it with these settings without opening
459
+ * it, and `expand` to show the AI its definition (type, allowed values, how to fill it; 24 §2.2), not
460
+ * shown when left out. How to fill a field on this page is the page's `$extraction`, one per field for
461
+ * the whole page (26 §15.3); `extraction` here is refused. `hint` was renamed and is refused;
462
+ * `required` was removed (24 §2.3).
463
+ */
464
+ export type FieldOptions = {
465
+ readOnly?: boolean;
466
+ expand?: boolean;
467
+ extraction?: MovedOption<'$extraction'>;
468
+ hint?: MovedOption<'$extraction'>;
469
+ required?: RemovedOption;
470
+ };
471
+ /** A removed option: any value is a type error. */
472
+ export type RemovedOption = never;
473
+ /** A removed option: any value is a type error whose message names the new one. */
474
+ export type RenamedOption<New extends string> = `renamed: use ${New}`;
475
+ /** An option that moved to the page: any value is a type error whose message names where it went. */
476
+ export type MovedOption<Where extends string> = `moved: use the page's ${Where}`;
477
+ export type FieldCell<S = Slot> = {
478
+ $field: true;
479
+ slot: S;
480
+ readOnly?: boolean;
481
+ expand?: boolean;
482
+ };
483
+ /** A row a ref field may point at, and what the AI sees of it (26 §16.2 #7). */
484
+ export type RefOption = {
485
+ id: string;
486
+ label: string;
487
+ };
488
+ export type RefFieldOptions = {
489
+ /**
490
+ * The rows it may point at, with their labels: `[{ id, label }]`, or `choose(rows, label)`. Read-only:
491
+ * only to label the current value (put the current row in it). None: only the row's name is shown.
492
+ */
493
+ options?: readonly RefOption[] | ChooseParam;
494
+ readOnly?: boolean;
495
+ };
496
+ /** A ref field on the page (26 §16.2 #7): its candidates given by the page, each with its label. */
497
+ export type RefFieldCell<S = Slot> = {
498
+ $refField: true;
499
+ slot: S;
500
+ options: RefOption[];
501
+ readOnly?: boolean;
502
+ };
503
+ /**
504
+ * A parameter taken from the schema (an added row's fields, `createRow(table, { fields })`): the platform fills
505
+ * in its type, allowed values and `extraction`. `table.id`, or a lookup field, chooses a row on the page.
506
+ */
507
+ export type SchemaFieldParam = {
508
+ $schemaField: string;
509
+ extraction?: string;
510
+ };
511
+ /** One parameter of an action: plain JSON Schema as the build reads it from a function's `args` type (38 §2.4), or a schema field. */
512
+ export type ActionParam = SchemaFieldParam | {
513
+ type: 'string' | 'number' | 'integer' | 'boolean';
514
+ description?: string;
515
+ enum?: Array<string | number>;
516
+ }
517
+ /** A row of `table` (`Id<'table'>`, 38 §2.4): the page prefills it or gives the rows to choose among. */
518
+ | {
519
+ type: 'ref';
520
+ table: string;
521
+ description?: string;
522
+ }
523
+ /** A string in a format (`IsoDate`, `Phone`…, 38 §2.4). */
524
+ | {
525
+ type: 'date' | 'datetime' | 'time' | 'phone' | 'email';
526
+ description?: string;
527
+ }
528
+ /** When a contact may be reached (`ContactSchedule`, 25 §3): checked as a contact_schedule field's value is. */
529
+ | {
530
+ type: 'contact_schedule';
531
+ description?: string;
532
+ } | {
533
+ type: 'array';
534
+ items: ActionParam;
535
+ description?: string;
536
+ } | {
537
+ type: 'object';
538
+ properties: Record<string, ActionParam>;
539
+ required?: string[];
540
+ description?: string;
541
+ };
542
+ /** An action's `parameters`, as an LLM function call declares them. */
543
+ export type ActionParameters = {
544
+ type: 'object';
545
+ properties: Record<string, ActionParam>;
546
+ required?: string[];
547
+ };
548
+ export type CreateRowAction = {
549
+ $action: 'createRow';
550
+ table: string;
551
+ /** The run key (`runKey`); without it, `createRow:<table>`. */
552
+ key?: string;
553
+ label?: string;
554
+ description?: string;
555
+ fields: string[];
556
+ required: string[];
557
+ /** Preset values (the parent, `status: 'active'`): kept on the server, never shown to the AI. */
558
+ prefill: Record<string, unknown>;
559
+ };
560
+ export type DeleteRowAction = {
561
+ $action: 'deleteRow';
562
+ rowId: string;
563
+ /** The run key (`runKey`); without it, `deleteRow:<row id>`. */
564
+ key?: string;
565
+ label?: string;
566
+ description?: string;
567
+ reason?: string;
568
+ };
569
+ export type CustomAction = {
570
+ $action: 'custom';
571
+ name: string;
572
+ /** How to fill each parameter on this page, by name (`run(…, { args })`, 31 §7): replaces the parameter's own. */
573
+ args?: Record<string, string>;
574
+ /** What the AI sees as its title (`button({ title })`); without it, `name`. */
575
+ label?: string;
576
+ /** The run key (`runKey`); without it, `name`. */
577
+ key?: string;
578
+ /** What the AI sees it does (`button({ does })`). */
579
+ description?: string;
580
+ /** What it takes; without them, its `args` type's, as the build read it (38 §2.9). */
581
+ parameters?: ActionParameters;
582
+ /** Parameters filled where the page placed the action: kept on the server, never shown to the AI. */
583
+ prefill: Record<string, unknown>;
584
+ };
585
+ /**
586
+ * A company function (`functions/`, 38 §2.1) as a button, or returned by the page function to
587
+ * run now (20 §6.2). It runs on the Worker, outside the page's transaction, and is waited for; on a call,
588
+ * `say` is said first and the customer cannot interrupt until it is done (20 §6.3).
589
+ */
590
+ export type FunctionAction = {
591
+ $action: 'function';
592
+ name: string;
593
+ /** How to fill each parameter on this page, by name (`run(…, { args })`, 31 §7): replaces the parameter's own. */
594
+ args?: Record<string, string>;
595
+ /** The run key (`runKey`); without it, `name`. */
596
+ key?: string;
597
+ label?: string;
598
+ description?: string;
599
+ /** Said first, verbatim, on a call only (ignored elsewhere), in the call's language (66): the customer only listens meanwhile. */
600
+ say?: Spoken;
601
+ /** What the AI fills: plain JSON Schema or schema fields, as a custom action's. */
602
+ parameters?: ActionParameters;
603
+ /** Parameters the page fills (a row's id) or offers rows for (`choose(...)`, 25 §10); kept on the server. */
604
+ prefill?: Record<string, unknown>;
605
+ };
606
+ /**
607
+ * The rows a row parameter may be chosen among (25 §10), with what the AI sees of each:
608
+ * `cancel({ appointment: choose(appointments, (a) => `${a.date.value} with ${a.provider.value}`) })`. The
609
+ * candidates are these rows, wherever else the page shows them (or not); none: the button is left off.
610
+ */
611
+ export type ChooseParam = {
612
+ $choose: true;
613
+ table: string | null;
614
+ options: Array<{
615
+ id: string;
616
+ label: string;
617
+ }>;
618
+ };
619
+ export declare function choose<R extends PageRow>(rows: readonly R[], label: (row: R) => string): ChooseParam;
620
+ export declare function isChoose(value: unknown): value is ChooseParam;
621
+ /** A platform tool on the page (76 §2.18): the AI presses it like a button and reads its result next turn. */
622
+ export type ToolAction = {
623
+ $action: 'tool';
624
+ tool: PageToolName;
625
+ };
626
+ /** The platform's tools (76 §2.18). */
627
+ export type PageToolName = 'pressKeypad' | 'convertTime';
628
+ export declare const PAGE_TOOLS: readonly PageToolName[];
629
+ export type PageAction = CreateRowAction | DeleteRowAction | CustomAction | ChannelAction | FunctionAction | FollowUpAction | CancelFollowUpAction | ToolAction;
630
+ /** Hand the call to a person. */
631
+ export type TransferAction = {
632
+ $action: 'channel';
633
+ channel: 'transfer';
634
+ /** E.164 number to dial, or a SIP URI (`sip:desk@pbx.example.com`, headers after `?`). */
635
+ to: string;
636
+ /** A SIP `to` that asks for credentials: kept on the server, never on the page the AI reads. */
637
+ sipAuth?: {
638
+ username: string;
639
+ password: string;
640
+ };
641
+ /**
642
+ * The caller ID the person sees: the customer's number or ours (default: the voice service's own rule).
643
+ * A call that came in by SIP shows ours to a phone number whatever is asked (the carrier refuses it).
644
+ */
645
+ callerId?: 'customer' | 'service';
646
+ /**
647
+ * cold: connect and leave; warm: brief the person first with `briefing`, the customer on hold meanwhile;
648
+ * background: warm, but the AI keeps talking with the customer while the person is called, and the
649
+ * customer is put through once the person takes it. Nobody takes it: the conversation simply goes on.
650
+ */
651
+ mode: 'cold' | 'warm' | 'background';
652
+ /**
653
+ * What the briefing should cover (74 §3.3): the very words, or an instruction ("say who is calling and
654
+ * why"). A model writes it as two or three sentences read aloud to the person, from this and the
655
+ * conversation so far (at the opening, from this alone), in their `language`; field names, underscores
656
+ * and codes are said the way a person would say them.
657
+ */
658
+ briefing?: string;
659
+ /**
660
+ * Warm and background (76 §2.9): what the person hears on a loop when they pick up, before they confirm:
661
+ * who it is and what about. The platform adds how to confirm; without it, "You have a call from {company}".
662
+ * English for now, whatever `language` says.
663
+ */
664
+ whisper?: string;
665
+ /**
666
+ * Background only: what is said as the two are put through. `person`: to the person, once they take
667
+ * the call (`{{briefing}}` is the briefing; without it, the briefing). `customer`: to the customer, in
668
+ * their language (66: per language; without it, a chime only).
669
+ */
670
+ bridge?: {
671
+ person?: string;
672
+ customer?: Spoken;
673
+ };
674
+ /**
675
+ * The language of the person taking the call (BCP-47; default `en`), not the customer's (48 §10.3): what
676
+ * is said to them (the briefing, the waiting line) is said and written in it, and they are heard in it.
677
+ */
678
+ language?: string;
679
+ /** The run key (`runKey`): two transfers on a page apart; without it, `transfer`. */
680
+ key?: string;
681
+ label?: string;
682
+ description?: string;
683
+ };
684
+ /** Collect keypresses on a call: what was pressed is written to `write` (through `map` when given). */
685
+ export type KeypadAction = {
686
+ $action: 'channel';
687
+ channel: 'keypad';
688
+ /** The run key: `tried(ctx.runs, key)` after the first try. */
689
+ key: string;
690
+ /** Said once, verbatim, before waiting for a key, in the call's language (66). */
691
+ say: Spoken;
692
+ /** The keys that count. */
693
+ digits: string[];
694
+ timeoutMs: number;
695
+ /** Where the key goes: a slot read from db. */
696
+ write?: SlotRef;
697
+ /** Pressed key → value written (`{ '1': 'en', '2': 'es' }`); without it the key itself. */
698
+ map?: Record<string, string | number | boolean>;
699
+ label?: string;
700
+ description?: string;
701
+ };
702
+ /**
703
+ * Say a fixed text, verbatim and not interruptible (a compliance statement), in the call's language (66).
704
+ * After it, the model answers what the customer said; `answers`: the text is that answer (an opening line
705
+ * for a "Hello?", 65 §3.2), and nothing more is said after it.
706
+ */
707
+ export type AnnounceAction = {
708
+ $action: 'channel';
709
+ channel: 'announce';
710
+ key: string;
711
+ text: Spoken;
712
+ answers?: true;
713
+ };
714
+ /** End the conversation (a call hangs up once the last line has played; an SMS conversation closes). */
715
+ export type EndAction = {
716
+ $action: 'channel';
717
+ channel: 'end'; /** The run key; without it, `end`. */
718
+ key?: string;
719
+ label?: string;
720
+ description?: string;
721
+ };
722
+ /**
723
+ * Leave a message on the voicemail (25 §13): after its beep, word for word (what a regulated business may
724
+ * leave is fixed), then hang up. The call's outcome is `voicemail`.
725
+ */
726
+ export type VoicemailAction = {
727
+ $action: 'channel';
728
+ channel: 'voicemail'; /** Per language (66). */
729
+ text: Spoken; /** The run key; without it, `voicemail`. */
730
+ key?: string;
731
+ label?: string;
732
+ description?: string;
733
+ };
734
+ export type ChannelAction = TransferAction | KeypadAction | AnnounceAction | EndAction | VoicemailAction;
735
+ export declare function transferTo(options: {
736
+ to: string;
737
+ sipAuth?: TransferAction['sipAuth'];
738
+ callerId?: TransferAction['callerId'];
739
+ mode?: TransferAction['mode'];
740
+ briefing?: string;
741
+ whisper?: string;
742
+ bridge?: TransferAction['bridge'];
743
+ language?: string;
744
+ label?: string;
745
+ description?: string;
746
+ }): TransferAction;
747
+ /** Whether a transfer's `to` is a SIP URI rather than a phone number. */
748
+ export declare function isSipUri(to: string): boolean;
749
+ export declare function keypadAction(key: string, options: {
750
+ say: Spoken;
751
+ digits: string[];
752
+ timeoutMs?: number;
753
+ write?: Slot | SlotRef;
754
+ map?: Record<string, string | number | boolean>;
755
+ label?: string;
756
+ description?: string;
757
+ }): KeypadAction;
758
+ /** A company function as a button (20 §6.2): `runFunction('importOrders', { label, say, parameters })`. */
759
+ export declare function runFunction(name: string, options?: {
760
+ label?: string;
761
+ description?: string;
762
+ say?: Spoken;
763
+ parameters?: ActionParameters;
764
+ prefill?: Record<string, unknown>;
765
+ }): FunctionAction;
766
+ export declare function announceAction(key: string, text: Spoken, options?: {
767
+ answers?: boolean;
768
+ }): AnnounceAction;
769
+ export declare function voicemailAction(text: Spoken, options?: {
770
+ label?: string;
771
+ description?: string;
772
+ }): VoicemailAction;
773
+ export declare function endAction(options?: {
774
+ label?: string;
775
+ description?: string;
776
+ }): EndAction;
777
+ /** Every channel a page may be written for, in order. */
778
+ export declare const PAGE_CHANNELS: readonly PageChannel[];
779
+ /** A page function: the page for one channel, or an action to run now (17b §9.1, §9.8). */
780
+ export type PageFunction<D> = (ctx: PageContext) => D | Promise<D>;
781
+ /**
782
+ * Who the employee is and how they talk on this conversation's channel (`ctx.channel`), and the FAQ the
783
+ * AI may look things up in (24 §4). Called once, when the conversation starts, with the page's context
784
+ * at that moment; what they return holds for the whole conversation (the head of every prompt).
785
+ */
786
+ export type PagePersona = (ctx: PageContext) => string | Promise<string>;
787
+ export type PageFaq = (ctx: PageContext) => PageFaqEntry[] | Promise<PageFaqEntry[]>;
788
+ export type PageDefinition<D> = {
789
+ persona: PagePersona;
790
+ faq?: PageFaq;
791
+ call?: (ctx: PageContextOf<'call'>) => D | Promise<D>;
792
+ sms?: (ctx: PageContextOf<'sms'>) => D | Promise<D>;
793
+ email?: (ctx: PageContextOf<'email'>) => D | Promise<D>;
794
+ };
795
+ export type DefinedPage<D> = {
796
+ kind: 'page';
797
+ persona: PagePersona;
798
+ faq: PageFaq | null;
799
+ channels: Partial<Record<PageChannel, PageFunction<D>>>;
800
+ };
801
+ /**
802
+ * `context.page.ts` (17b §9.1, 24 §4): `definePage({ persona: (ctx) => '…', faq: (ctx) => [...], call:
803
+ * async (ctx) => page, sms: … })`. One page function per channel; what they share is the company code's
804
+ * own business.
805
+ */
806
+ export declare function definePage<D>(definition: PageDefinition<D>): DefinedPage<D>;
807
+ /**
808
+ * What `persona` and `faq` returned, checked (24 §4): a persona's text; at most `MAX_FAQ_ENTRIES` FAQ
809
+ * entries, each with an id of its own, a description and an answer. Throws what is wrong.
810
+ */
811
+ export declare function checkPageStart(raw: unknown): PageStart;
812
+ /**
813
+ * A cell the AI may write (19-page-writable-cells): a slot placed on a page as is is read-only;
814
+ * `field(slot)` opens it, unless `readOnly: true`. The row id and the parent never open; a lookup
815
+ * chooses among its table's rows on the page.
816
+ */
817
+ /**
818
+ * A ref field (a lookup) on the page (26 §16.2 #7): the rows the AI may set it to, each with its label
819
+ * (`options: [{ id, label }]`, or `choose(rows, label)`); read-only, `options` only labels the current
820
+ * value. Its definition is always on the page. `field()` refuses a ref field.
821
+ */
822
+ export declare function refFieldCell<S extends Slot>(slot: S, options?: RefFieldOptions): RefFieldCell<S>;
823
+ export declare function fieldCell<S extends Slot>(slot: S, options?: FieldOptions): FieldCell<S>;
824
+ /**
825
+ * An action placed on a page: call it to prefill parameters (`addProvider({ injury: i.id })`), or place
826
+ * it as it is (nothing prefilled).
827
+ */
828
+ export type Placeable<A extends PageAction, P> = (prefill?: P) => A;
829
+ /** Add a row (15 §10.6): `fields` are what the AI fills; call it to preset the rest (`({ status: 'active' })`). */
830
+ export declare function createRowAction(table: TableReader | string, options: {
831
+ fields: readonly string[];
832
+ required?: readonly string[];
833
+ label?: string;
834
+ description?: string;
835
+ }): Placeable<CreateRowAction, Record<string, unknown>>;
836
+ /** Delete a row (cascading, 15 §10.6.1): a built-in action with the row prefilled and nothing to fill. */
837
+ export declare function deleteRowAction(row: PageRow | string, options?: {
838
+ reason?: string;
839
+ label?: string;
840
+ description?: string;
841
+ }): DeleteRowAction;
842
+ /** The environment's configuration on a page (76 §2.19), read only. */
843
+ export type PageEnv = {
844
+ get<T = unknown>(key: string): T | null;
845
+ };
846
+ export type PageEntryArg = {
847
+ /** `start`: `persona` and `faq` once, when the conversation starts (24 §4), with the same context. */
848
+ mode: 'render' | 'start';
849
+ /** The page function to run; outside a conversation, the first one the page defines. */
850
+ channel: PageChannel | null;
851
+ subject: string;
852
+ /** The instance this conversation is on (38 §2.2: a function that needs it is prefilled it). */
853
+ instanceId: string;
854
+ caller: PageRow | null;
855
+ session: PageRow | null;
856
+ conversation: PageConversation | null;
857
+ runs: PageRuns;
858
+ scheduledAction: PageScheduledAction | null;
859
+ officeHours: PageContext['officeHours'];
860
+ nextSteps?: PageNextStep[];
861
+ now: string;
862
+ /** The contact's time zone and today there (25 §11). */
863
+ time?: {
864
+ zone: string;
865
+ today: string;
866
+ };
867
+ /** The environment's configuration (76 §2.19): its `env` integrations' values by key, as functions read them. */
868
+ env?: Record<string, unknown>;
869
+ /** What the customer sent since the last run (20 §5.2): a text run's texts, an email run's emails. */
870
+ sms?: {
871
+ inbound: PageSmsMessage[];
872
+ };
873
+ email?: {
874
+ inbound: PageEmailMessage[];
875
+ mailbox: string;
876
+ };
877
+ call?: {
878
+ previous: PagePreviousCall | null;
879
+ farEnd?: PageFarEnd | null;
880
+ heard?: PageHeard | null;
881
+ phase?: PageCallPhase;
882
+ };
883
+ }
884
+ /** The channels with a page function: read once, when the sequence is compiled. */
885
+ | {
886
+ mode: 'channels';
887
+ } | {
888
+ mode: 'action';
889
+ name: string;
890
+ /** The prefilled parameters and the AI's, merged. */
891
+ args: Record<string, unknown>;
892
+ subject: string;
893
+ caller: PageRow | null;
894
+ session: PageRow | null;
895
+ now: string;
896
+ };
897
+ /** No runs yet. */
898
+ export declare function emptyRuns(): PageRuns;
899
+ /**
900
+ * What the compiled page script evaluates to: renders the page, or runs one of its actions. `actionsModule`
901
+ * is the sequence's `actions.ts` (76 §2.11), null without one.
902
+ */
903
+ export declare function pageEntry(mod: Record<string, unknown>, actionsModule?: Record<string, unknown> | null): (arg: PageEntryArg) => unknown;
904
+ //# sourceMappingURL=define.d.ts.map