@superpanel-sdk/runtime 0.5.0 → 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 (189) hide show
  1. package/README.md +3 -3
  2. package/dist/builder/codegen/emit.d.ts +5 -10
  3. package/dist/builder/codegen/emit.js +100 -106
  4. package/dist/builder/codegen/generate.d.ts +3 -5
  5. package/dist/builder/codegen/generate.js +13 -32
  6. package/dist/builder/company-imports.d.ts +5 -0
  7. package/dist/builder/company-imports.js +9 -1
  8. package/dist/builder/compile/compile-sequence.d.ts +13 -11
  9. package/dist/builder/compile/compile-sequence.js +135 -83
  10. package/dist/builder/compile/function-code.d.ts +15 -9
  11. package/dist/builder/compile/function-code.js +59 -29
  12. package/dist/builder/compile/registry.d.ts +4 -4
  13. package/dist/builder/compile/registry.js +14 -12
  14. package/dist/builder/errors.d.ts +9 -0
  15. package/dist/builder/errors.js +17 -0
  16. package/dist/builder/function-params.d.ts +10 -0
  17. package/dist/builder/function-params.js +203 -0
  18. package/dist/builder/load.d.ts +17 -17
  19. package/dist/builder/load.js +27 -25
  20. package/dist/builder/paths.d.ts +6 -1
  21. package/dist/builder/paths.js +16 -2
  22. package/dist/builder/schedules.d.ts +9 -7
  23. package/dist/builder/schedules.js +20 -21
  24. package/dist/builder/typecheck.d.ts +1 -1
  25. package/dist/builder/typecheck.js +3 -6
  26. package/dist/builder/types.d.ts +41 -5
  27. package/dist/builder/types.js +19 -0
  28. package/dist/cli/calls/index.d.ts +177 -0
  29. package/dist/cli/calls/index.js +96 -0
  30. package/dist/cli/debug/index.d.ts +31 -0
  31. package/dist/cli/debug/index.js +119 -0
  32. package/dist/cli/exec/index.d.ts +39 -0
  33. package/dist/cli/exec/index.js +138 -0
  34. package/dist/cli/exec/session.d.ts +48 -0
  35. package/dist/cli/exec/session.js +82 -0
  36. package/dist/cli/exec/trace.d.ts +18 -0
  37. package/dist/cli/exec/trace.js +52 -0
  38. package/dist/cli/index.js +84 -1
  39. package/dist/cli/logs/index.d.ts +47 -0
  40. package/dist/cli/logs/index.js +113 -0
  41. package/dist/cli/mobile/index.d.ts +12 -0
  42. package/dist/cli/mobile/index.js +405 -0
  43. package/dist/cli/serve/index.d.ts +40 -4
  44. package/dist/cli/serve/index.js +167 -28
  45. package/dist/cli/turns/index.d.ts +105 -0
  46. package/dist/cli/turns/index.js +128 -0
  47. package/dist/cli/turns/run.d.ts +13 -0
  48. package/dist/cli/turns/run.js +57 -0
  49. package/dist/cli/turns/shadow.d.ts +112 -0
  50. package/dist/cli/turns/shadow.js +54 -0
  51. package/dist/cli/type-gen/index.js +0 -1
  52. package/dist/compute-host/compute-host.d.ts +5 -6
  53. package/dist/compute-host/compute-host.js +4 -13
  54. package/dist/compute-host/source-compute-host.d.ts +5 -7
  55. package/dist/compute-host/source-compute-host.js +12 -33
  56. package/dist/core/case-orchestrator/contact-hours.d.ts +26 -6
  57. package/dist/core/case-orchestrator/contact-hours.js +27 -8
  58. package/dist/core/case-orchestrator/index.d.ts +1 -4
  59. package/dist/core/case-orchestrator/index.js +1 -4
  60. package/dist/core/case-orchestrator/render.d.ts +1 -1
  61. package/dist/core/case-orchestrator/render.js +15 -10
  62. package/dist/core/case-orchestrator/types.d.ts +83 -128
  63. package/dist/core/case-orchestrator/types.js +0 -4
  64. package/dist/core/context/email-message.d.ts +40 -1
  65. package/dist/core/context/email-message.js +27 -0
  66. package/dist/core/context/email.d.ts +13 -1
  67. package/dist/core/context/email.js +2 -3
  68. package/dist/core/context/exchanges.d.ts +25 -0
  69. package/dist/core/context/exchanges.js +25 -7
  70. package/dist/core/context/instances.d.ts +31 -2
  71. package/dist/core/context/instances.js +18 -4
  72. package/dist/core/context/platform-registry.d.ts +35 -0
  73. package/dist/core/context/sms.d.ts +30 -0
  74. package/dist/core/context/sms.js +20 -0
  75. package/dist/core/context/types.d.ts +29 -1
  76. package/dist/core/conversation/index.d.ts +58 -4
  77. package/dist/core/conversation/index.js +123 -4
  78. package/dist/core/functions/errors.d.ts +74 -0
  79. package/dist/core/functions/errors.js +26 -0
  80. package/dist/core/functions/events.d.ts +23 -78
  81. package/dist/core/functions/events.js +8 -17
  82. package/dist/core/functions/schedules.d.ts +9 -10
  83. package/dist/core/functions/schedules.js +2 -2
  84. package/dist/core/functions/types.d.ts +17 -72
  85. package/dist/core/functions/types.js +1 -9
  86. package/dist/core/page/define.d.ts +230 -160
  87. package/dist/core/page/define.js +145 -104
  88. package/dist/core/page/envelope.d.ts +55 -0
  89. package/dist/core/page/envelope.js +4 -0
  90. package/dist/core/page/fns.d.ts +448 -0
  91. package/dist/core/page/fns.js +539 -0
  92. package/dist/core/page/memory-reader.d.ts +27 -0
  93. package/dist/core/page/memory-reader.js +299 -0
  94. package/dist/core/page/page-host.d.ts +20 -0
  95. package/dist/core/page/page-host.js +57 -0
  96. package/dist/core/page/records-query.d.ts +234 -0
  97. package/dist/core/page/records-query.js +780 -0
  98. package/dist/core/page/render.d.ts +67 -25
  99. package/dist/core/page/render.js +492 -272
  100. package/dist/core/page/sandbox.d.ts +85 -0
  101. package/dist/core/page/sandbox.js +357 -0
  102. package/dist/core/page/time-format.d.ts +27 -0
  103. package/dist/core/page/time-format.js +84 -0
  104. package/dist/core/page/typed.d.ts +165 -159
  105. package/dist/core/page/workspace.d.ts +25 -1
  106. package/dist/core/page/workspace.js +48 -13
  107. package/dist/core/party/schema.d.ts +74 -3
  108. package/dist/core/party/schema.js +39 -6
  109. package/dist/core/party/types.d.ts +8 -13
  110. package/dist/core/sequence/define.d.ts +1 -2
  111. package/dist/core/slot/company-metadata.d.ts +11 -22
  112. package/dist/core/slot/company-metadata.js +12 -39
  113. package/dist/core/slot/compile-schema.js +6 -6
  114. package/dist/core/slot/field.d.ts +1 -2
  115. package/dist/core/slot/field.js +0 -2
  116. package/dist/core/slot/index.d.ts +3 -3
  117. package/dist/core/slot/index.js +3 -3
  118. package/dist/core/slot/naming.d.ts +1 -1
  119. package/dist/core/slot/naming.js +1 -1
  120. package/dist/core/slot/platform-fields.d.ts +4 -4
  121. package/dist/core/slot/platform-fields.js +5 -5
  122. package/dist/core/slot/schema-compat.d.ts +8 -7
  123. package/dist/core/slot/schema-compat.js +22 -31
  124. package/dist/core/slot/schema.d.ts +3 -59
  125. package/dist/core/slot/schema.js +0 -15
  126. package/dist/core/slot/types.d.ts +4 -10
  127. package/dist/core/slot/value.d.ts +2 -0
  128. package/dist/core/slot/value.js +6 -2
  129. package/dist/dev-overlay/protocol.d.ts +38 -5
  130. package/dist/fn-context/build-context.js +10 -4
  131. package/dist/fn-context/fake/index.d.ts +2 -0
  132. package/dist/fn-context/fake/index.js +5 -3
  133. package/dist/fn-context/fn-params.d.ts +2 -5
  134. package/dist/fn-context/fn-params.js +6 -9
  135. package/dist/fn-context/index.d.ts +1 -1
  136. package/dist/fn-context/make-ctx.js +5 -4
  137. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +11 -3
  138. package/dist/fn-context/rpc/case-orchestrator-tools.js +0 -1
  139. package/dist/fn-context/rpc/errors.d.ts +13 -0
  140. package/dist/fn-context/rpc/errors.js +22 -0
  141. package/dist/fn-context/rpc/index.d.ts +1 -1
  142. package/dist/fn-context/rpc/index.js +1 -1
  143. package/dist/fn-context/rpc/integration/index.d.ts +11 -1
  144. package/dist/fn-context/rpc/log.d.ts +11 -1
  145. package/dist/fn-context/rpc/platform.d.ts +11 -1
  146. package/dist/fn-context/rpc/records.d.ts +13 -6
  147. package/dist/fn-context/rpc/records.js +2 -4
  148. package/dist/fn-context/rpc/trpc-client.d.ts +42 -0
  149. package/dist/fn-context/rpc/trpc-client.js +151 -22
  150. package/dist/fn-context/rpc/trpc-init.d.ts +19 -1
  151. package/dist/fn-context/rpc/trpc-init.js +10 -4
  152. package/dist/fn-context/rpc/trpc-router-factory.d.ts +66 -8
  153. package/dist/fn-context/run-scope.js +1 -1
  154. package/dist/fn-context/types.d.ts +20 -6
  155. package/dist/index.d.ts +11 -12
  156. package/dist/index.js +5 -8
  157. package/dist/logger.d.ts +4 -0
  158. package/dist/logger.js +8 -0
  159. package/dist/platform.d.ts +32 -33
  160. package/dist/platform.js +23 -22
  161. package/dist/testing-compile-child.d.ts +2 -0
  162. package/dist/testing-compile-child.js +20 -0
  163. package/dist/testing.d.ts +368 -0
  164. package/dist/testing.js +439 -0
  165. package/dist/voice-service/actions.d.ts +12 -35
  166. package/dist/voice-service/index.d.ts +2 -0
  167. package/dist/voice-service/index.js +2 -0
  168. package/dist/voice-service/protocol.d.ts +604 -0
  169. package/dist/voice-service/protocol.js +67 -0
  170. package/dist/voice-service/types.d.ts +16 -6
  171. package/dist/worker.d.ts +2 -1
  172. package/dist/worker.js +2 -1
  173. package/package.json +20 -16
  174. package/dist/core/case-orchestrator/follow-ups.d.ts +0 -31
  175. package/dist/core/case-orchestrator/follow-ups.js +0 -103
  176. package/dist/core/case-orchestrator/tools.d.ts +0 -29
  177. package/dist/core/case-orchestrator/tools.js +0 -31
  178. package/dist/core/case-orchestrator/validate.d.ts +0 -11
  179. package/dist/core/case-orchestrator/validate.js +0 -63
  180. package/dist/core/functions/define/bind.d.ts +0 -25
  181. package/dist/core/functions/define/bind.js +0 -14
  182. package/dist/core/functions/define/case.d.ts +0 -9
  183. package/dist/core/functions/define/case.js +0 -13
  184. package/dist/core/functions/define/events.d.ts +0 -20
  185. package/dist/core/functions/define/events.js +0 -21
  186. package/dist/core/functions/define/no-case.d.ts +0 -4
  187. package/dist/core/functions/define/no-case.js +0 -9
  188. package/dist/core/functions/func-ref.d.ts +0 -25
  189. package/dist/core/functions/func-ref.js +0 -20
@@ -3,13 +3,14 @@
3
3
  * inside the QuickJS sandbox, bundled into the page script, so it imports nothing at runtime and only
4
4
  * uses `globalThis.__host` (the sandbox's async host call, services `page/sandbox.ts`).
5
5
  *
6
- * A page script reads with `db` and returns a free-form document: objects are blocks, arrays are
7
- * lists, a slot is a cell, `field(slot, …)` a cell with page settings, other plain values read-only
8
- * content, and actions (`createRow`, `deleteRow`, `defineAction`) buttons. The platform turns the
9
- * document into a `RenderedPage` (`render.ts`).
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
10
  */
11
- import type { Channel, Direction } from '../conversation/index.js';
11
+ import { type Channel, type Direction, type Spoken } from '../conversation/index.js';
12
12
  import type { TimelineEntry, TimelineWhere } from './timeline.js';
13
+ import type { TimeParts } from './time-format.js';
13
14
  export type SlotState = 'filled' | 'empty' | 'asked_unknown' | 'declined';
14
15
  export type SlotRef = {
15
16
  table: string;
@@ -39,9 +40,16 @@ export type FindArgs = {
39
40
  orderBy?: Record<string, 'asc' | 'desc'> | Array<Record<string, 'asc' | 'desc'>>;
40
41
  take?: number;
41
42
  skip?: number;
42
- cursor?: {
43
- id: string;
44
- };
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;
45
53
  };
46
54
  /** One table's read methods (Prisma Client's read-only subset). */
47
55
  export type TableReader<Row = PageRow> = {
@@ -114,6 +122,8 @@ export type PageConversation = {
114
122
  isNewContact: boolean;
115
123
  /** ISO timestamp the session opened. */
116
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;
117
127
  };
118
128
  /**
119
129
  * Counts over this instance, worked out when the page renders (11-remove-sequence-schema §3.3.1).
@@ -167,37 +177,73 @@ export type PageActionRun = {
167
177
  export declare function tried(runs: PageRuns | null | undefined, key: string, scope?: ActionRunScope): boolean;
168
178
  /** The latest run of the action `key`, in this run or (`'case'`) on the case, if any. */
169
179
  export declare function lastActionRun(runs: PageRuns | null | undefined, key: string, scope?: ActionRunScope): PageActionRun | null;
170
- /** An agreed follow-up: the channel, when (ISO), and what it is about. */
171
- export type PageFollowUp = {
172
- channel: string;
173
- scheduledFor: string;
174
- note: string | 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;
175
204
  };
176
205
  /**
177
- * The button that books what the customer just asked for or agreed to (25 §5): a call back, a text, an
178
- * email, at the time they said. The platform books it at once as an agreed follow-up (09): the exchange
179
- * and the time of their words are its own; the AI gives the channel, the time and their words.
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).
180
210
  */
181
211
  export type FollowUpAction = {
182
212
  $action: 'followUp';
183
213
  /** The run key (default `followUp`). */
184
214
  key: string;
185
- /** The channels the customer may be followed up on, of the ones this sequence has a page for. */
215
+ /** The channels it may book, of the ones this sequence has a page for. */
186
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
+ };
187
222
  label?: string;
188
223
  description?: string;
189
224
  };
190
- /** `ctx.followUps`: the agreed follow-ups still to come, and `agree(...)`, the button that books one. */
191
- export type PageFollowUps = PageFollowUp[] & {
192
- agree(options: {
193
- channels: Array<'call' | 'sms' | 'email'>;
194
- key?: string;
195
- label?: string;
196
- description?: string;
197
- }): FollowUpAction;
198
- };
199
- /** The agreed follow-ups with the button that books one. */
200
- export declare function pageFollowUps(list: readonly PageFollowUp[]): PageFollowUps;
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;
201
247
  /**
202
248
  * One FAQ entry (24 §7): its id, what it covers (the catalog in the prompt shows these two), and the
203
249
  * answer (the AI fetches it with `get_faq`).
@@ -242,13 +288,15 @@ export type PageBaseContext = {
242
288
  }>;
243
289
  } | null;
244
290
  /**
245
- * The contact's agreed follow-ups still to come (09): calls and messages they asked for or agreed to,
246
- * soonest first. Empty without a Case Orchestrator (nothing books them). `ctx.followUps.agree({ channels })`
247
- * is the button that books one when the customer asks for it (25 §5).
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.
248
294
  */
249
- followUps: PageFollowUps;
295
+ nextSteps: PageNextStep[];
250
296
  /** The business root's id. */
251
297
  subject: string;
298
+ /** The instance this conversation is on: prefill it to a function that needs it (38 §2.2). */
299
+ instanceId: string;
252
300
  /** The contact of the conversation; null outside one. */
253
301
  caller: PageRow | null;
254
302
  /** This conversation's session row (the session fields, cells); null outside one. */
@@ -259,10 +307,13 @@ export type PageBaseContext = {
259
307
  history: PageHistory;
260
308
  /** ISO timestamp of this render. */
261
309
  now: string;
262
- /** A text or an email to send now (25 §8): `ctx.messages.text('link', { body })`. */
263
- messages: PageMessages;
264
310
  /** Times for people (25 §11): the sandbox has no `Intl`, so formatting goes through the platform. */
265
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;
266
317
  };
267
318
  /**
268
319
  * `ctx.time` (25 §11): the contact's time zone and today there, `format` for a time as people read it,
@@ -281,6 +332,10 @@ export type PageTime = {
281
332
  }): Promise<string>;
282
333
  /** The calendar day (`YYYY-MM-DD`) at `at` in `timeZone` (default `zone`), to compare days or key a rule by date. */
283
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>;
284
339
  };
285
340
  /**
286
341
  * A text the customer sent since the last run (20 §5.2): what this run is for. `earlier`: sent before,
@@ -329,27 +384,40 @@ export type PagePreviousCall = {
329
384
  }>;
330
385
  };
331
386
  /**
332
- * Who answered an outbound call (25 §13), as the voice service tells it: a person, a voicemail greeting,
333
- * a call-screening assistant, a phone menu; `said`: what it said. The page decides what to do: leave a
334
- * message (`ctx.call.voicemail`), tell the screener who calls and why (`announce`), press keys (`keypad`),
335
- * end. A page that returns nothing for it leaves the voice service to do what it does on its own (hang
336
- * up on a machine).
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.
337
391
  */
338
392
  export type PageFarEnd = {
339
- kind: 'human' | 'voicemail' | 'screening' | 'ivr';
393
+ kind: 'voicemail';
340
394
  said: string;
341
395
  };
342
- /** What only a call can do (20 §5.2): on `ctx.call`, so a text's page cannot even write it. */
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). */
343
406
  export type PageCallCaps = {
344
- transferTo: typeof transferTo;
345
- keypad: typeof keypad;
346
- announce: typeof announce;
347
- voicemail: typeof voicemail;
348
407
  /** This person's previous call on this case; null when there is none. */
349
408
  previous: PagePreviousCall | null;
350
- /** Who answered, once the voice service knows (25 §13); null until then, and on an inbound call. */
409
+ /** A voicemail answered, once the voice service knows (65 §3.1); null otherwise, and on an inbound call. */
351
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;
352
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';
353
421
  /** What each channel adds to the page function's context (20 §5.2). */
354
422
  export type PageChannelCaps = {
355
423
  call: {
@@ -433,24 +501,34 @@ export type RefFieldCell<S = Slot> = {
433
501
  readOnly?: boolean;
434
502
  };
435
503
  /**
436
- * A parameter taken from the schema (`schemaField('providers.name')`): the platform fills in its type,
437
- * allowed values, label and `extraction` (the page's `extraction` replaces the schema's). `table.id`,
438
- * or a lookup field, chooses a row on the page.
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.
439
506
  */
440
507
  export type SchemaFieldParam = {
441
508
  $schemaField: string;
442
509
  extraction?: string;
443
510
  };
444
- /** `schemaField()` options. `description` was renamed `extraction` and is refused. */
445
- export type SchemaFieldOptions = {
446
- extraction?: string;
447
- description?: RenamedOption<'extraction'>;
448
- };
449
- /** One parameter of an action: a schema field, or plain JSON Schema (function call `parameters`). */
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. */
450
512
  export type ActionParam = SchemaFieldParam | {
451
513
  type: 'string' | 'number' | 'integer' | 'boolean';
452
514
  description?: string;
453
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;
454
532
  } | {
455
533
  type: 'array';
456
534
  items: ActionParam;
@@ -470,6 +548,8 @@ export type ActionParameters = {
470
548
  export type CreateRowAction = {
471
549
  $action: 'createRow';
472
550
  table: string;
551
+ /** The run key (`runKey`); without it, `createRow:<table>`. */
552
+ key?: string;
473
553
  label?: string;
474
554
  description?: string;
475
555
  fields: string[];
@@ -480,6 +560,8 @@ export type CreateRowAction = {
480
560
  export type DeleteRowAction = {
481
561
  $action: 'deleteRow';
482
562
  rowId: string;
563
+ /** The run key (`runKey`); without it, `deleteRow:<row id>`. */
564
+ key?: string;
483
565
  label?: string;
484
566
  description?: string;
485
567
  reason?: string;
@@ -487,23 +569,35 @@ export type DeleteRowAction = {
487
569
  export type CustomAction = {
488
570
  $action: 'custom';
489
571
  name: string;
490
- description: string;
491
- parameters: ActionParameters;
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;
492
582
  /** Parameters filled where the page placed the action: kept on the server, never shown to the AI. */
493
583
  prefill: Record<string, unknown>;
494
584
  };
495
585
  /**
496
- * A company function (`functions/`, `defineCaseFunc`) as a button, or returned by the page function to
586
+ * A company function (`functions/`, 38 §2.1) as a button, or returned by the page function to
497
587
  * run now (20 §6.2). It runs on the Worker, outside the page's transaction, and is waited for; on a call,
498
588
  * `say` is said first and the customer cannot interrupt until it is done (20 §6.3).
499
589
  */
500
590
  export type FunctionAction = {
501
591
  $action: 'function';
502
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;
503
597
  label?: string;
504
598
  description?: string;
505
- /** Said first, verbatim, on a call only (ignored elsewhere): the customer only listens meanwhile. */
506
- say?: 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;
507
601
  /** What the AI fills: plain JSON Schema or schema fields, as a custom action's. */
508
602
  parameters?: ActionParameters;
509
603
  /** Parameters the page fills (a row's id) or offers rows for (`choose(...)`, 25 §10); kept on the server. */
@@ -524,43 +618,15 @@ export type ChooseParam = {
524
618
  };
525
619
  export declare function choose<R extends PageRow>(rows: readonly R[], label: (row: R) => string): ChooseParam;
526
620
  export declare function isChoose(value: unknown): value is ChooseParam;
527
- /**
528
- * A text or an email sent now (25 §8), on the platform's own way out: from this call's number (a text)
529
- * or the contact's mailbox (an email), opt-outs checked, recorded on the case and this run. What the page
530
- * leaves out the AI writes: `body`, and an email's `subject`.
531
- */
532
- export type MessageAction = {
533
- $action: 'message';
534
- channel: 'sms' | 'email';
535
- /** The run key: `lastActionRun(ctx.runs, key)` says whether it went. */
536
- key: string;
537
- /** The contact it goes to (a contact row the page read); absent: the contact of this conversation. */
538
- to?: string;
539
- /** The text, word for word; absent: the AI writes it. */
540
- body?: string;
541
- /** An email's subject; absent: the AI writes it. */
542
- subject?: string;
543
- /** On a call, said once it went (`'I just texted you the link.'`); ignored elsewhere. */
544
- say?: string;
545
- label?: string;
546
- description?: string;
547
- };
548
- export type MessageOptions = {
549
- to?: PageRow | string;
550
- body?: string;
551
- say?: string;
552
- label?: string;
553
- description?: string;
554
- };
555
- /** `ctx.messages` (25 §8): a text or an email to send now, as a button or returned to run at once. */
556
- export type PageMessages = {
557
- text(key: string, options?: MessageOptions): MessageAction;
558
- email(key: string, options?: MessageOptions & {
559
- subject?: string;
560
- }): MessageAction;
561
- };
562
- export declare const messages: PageMessages;
563
- export type PageAction = CreateRowAction | DeleteRowAction | CustomAction | ChannelAction | FunctionAction | MessageAction | FollowUpAction;
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;
564
630
  /** Hand the call to a person. */
565
631
  export type TransferAction = {
566
632
  $action: 'channel';
@@ -583,16 +649,35 @@ export type TransferAction = {
583
649
  * customer is put through once the person takes it. Nobody takes it: the conversation simply goes on.
584
650
  */
585
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
+ */
586
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;
587
665
  /**
588
666
  * Background only: what is said as the two are put through. `person`: to the person, once they take
589
667
  * the call (`{{briefing}}` is the briefing; without it, the briefing). `customer`: to the customer, in
590
- * their language (without it, a chime only).
668
+ * their language (66: per language; without it, a chime only).
591
669
  */
592
670
  bridge?: {
593
671
  person?: string;
594
- customer?: string;
672
+ customer?: Spoken;
595
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;
596
681
  label?: string;
597
682
  description?: string;
598
683
  };
@@ -602,29 +687,35 @@ export type KeypadAction = {
602
687
  channel: 'keypad';
603
688
  /** The run key: `tried(ctx.runs, key)` after the first try. */
604
689
  key: string;
605
- /** Said once, verbatim, before waiting for a key. */
606
- say: string;
690
+ /** Said once, verbatim, before waiting for a key, in the call's language (66). */
691
+ say: Spoken;
607
692
  /** The keys that count. */
608
693
  digits: string[];
609
694
  timeoutMs: number;
610
695
  /** Where the key goes: a slot read from db. */
611
696
  write?: SlotRef;
612
- /** Pressed key → value written (`{ '1': 'english', '2': 'spanish' }`); without it the key itself. */
697
+ /** Pressed key → value written (`{ '1': 'en', '2': 'es' }`); without it the key itself. */
613
698
  map?: Record<string, string | number | boolean>;
614
699
  label?: string;
615
700
  description?: string;
616
701
  };
617
- /** Say a fixed text, verbatim and not interruptible (a compliance statement). */
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
+ */
618
707
  export type AnnounceAction = {
619
708
  $action: 'channel';
620
709
  channel: 'announce';
621
710
  key: string;
622
- text: string;
711
+ text: Spoken;
712
+ answers?: true;
623
713
  };
624
714
  /** End the conversation (a call hangs up once the last line has played; an SMS conversation closes). */
625
715
  export type EndAction = {
626
716
  $action: 'channel';
627
- channel: 'end';
717
+ channel: 'end'; /** The run key; without it, `end`. */
718
+ key?: string;
628
719
  label?: string;
629
720
  description?: string;
630
721
  };
@@ -634,8 +725,9 @@ export type EndAction = {
634
725
  */
635
726
  export type VoicemailAction = {
636
727
  $action: 'channel';
637
- channel: 'voicemail';
638
- text: string;
728
+ channel: 'voicemail'; /** Per language (66). */
729
+ text: Spoken; /** The run key; without it, `voicemail`. */
730
+ key?: string;
639
731
  label?: string;
640
732
  description?: string;
641
733
  };
@@ -646,14 +738,16 @@ export declare function transferTo(options: {
646
738
  callerId?: TransferAction['callerId'];
647
739
  mode?: TransferAction['mode'];
648
740
  briefing?: string;
741
+ whisper?: string;
649
742
  bridge?: TransferAction['bridge'];
743
+ language?: string;
650
744
  label?: string;
651
745
  description?: string;
652
746
  }): TransferAction;
653
747
  /** Whether a transfer's `to` is a SIP URI rather than a phone number. */
654
748
  export declare function isSipUri(to: string): boolean;
655
- export declare function keypad(key: string, options: {
656
- say: string;
749
+ export declare function keypadAction(key: string, options: {
750
+ say: Spoken;
657
751
  digits: string[];
658
752
  timeoutMs?: number;
659
753
  write?: Slot | SlotRef;
@@ -665,36 +759,21 @@ export declare function keypad(key: string, options: {
665
759
  export declare function runFunction(name: string, options?: {
666
760
  label?: string;
667
761
  description?: string;
668
- say?: string;
762
+ say?: Spoken;
669
763
  parameters?: ActionParameters;
670
764
  prefill?: Record<string, unknown>;
671
765
  }): FunctionAction;
672
- export declare function announce(key: string, text: string): AnnounceAction;
673
- export declare function voicemail(text: string, options?: {
766
+ export declare function announceAction(key: string, text: Spoken, options?: {
767
+ answers?: boolean;
768
+ }): AnnounceAction;
769
+ export declare function voicemailAction(text: Spoken, options?: {
674
770
  label?: string;
675
771
  description?: string;
676
772
  }): VoicemailAction;
677
- export declare function end(options?: {
773
+ export declare function endAction(options?: {
678
774
  label?: string;
679
775
  description?: string;
680
776
  }): EndAction;
681
- /**
682
- * An action the page function returns to run now, with its run key (default: the action's name, a
683
- * channel action's key or kind) and whether the conversation waits for it (`wait: false`: run in the
684
- * background, the conversation goes on; not for channel actions).
685
- */
686
- export type PerformAction = {
687
- $perform: true;
688
- action: PageAction;
689
- key?: string;
690
- wait?: boolean;
691
- };
692
- export declare function perform(action: PageAction | {
693
- toJSON(): PageAction;
694
- }, options?: {
695
- key?: string;
696
- wait?: boolean;
697
- }): PerformAction;
698
777
  /** Every channel a page may be written for, in order. */
699
778
  export declare const PAGE_CHANNELS: readonly PageChannel[];
700
779
  /** A page function: the page for one channel, or an action to run now (17b §9.1, §9.8). */
@@ -740,66 +819,53 @@ export declare function checkPageStart(raw: unknown): PageStart;
740
819
  * (`options: [{ id, label }]`, or `choose(rows, label)`); read-only, `options` only labels the current
741
820
  * value. Its definition is always on the page. `field()` refuses a ref field.
742
821
  */
743
- export declare function refField<S extends Slot>(slot: S, options?: RefFieldOptions): RefFieldCell<S>;
744
- export declare function field<S extends Slot>(slot: S, options?: FieldOptions): FieldCell<S>;
745
- /** A parameter taken from the schema: `schemaField('providers.name')`, `schemaField('injuries.id')` (a row). */
746
- export declare function schemaField(path: string, options?: SchemaFieldOptions): SchemaFieldParam;
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>;
747
824
  /**
748
825
  * An action placed on a page: call it to prefill parameters (`addProvider({ injury: i.id })`), or place
749
- * it as it is (nothing prefilled). It crosses out of the sandbox as its JSON (`toJSON`).
826
+ * it as it is (nothing prefilled).
750
827
  */
751
- export type Placeable<A extends PageAction, P> = ((prefill?: P) => A) & {
752
- toJSON(): A;
753
- };
828
+ export type Placeable<A extends PageAction, P> = (prefill?: P) => A;
754
829
  /** Add a row (15 §10.6): `fields` are what the AI fills; call it to preset the rest (`({ status: 'active' })`). */
755
- export declare function createRow(table: TableReader | string, options: {
830
+ export declare function createRowAction(table: TableReader | string, options: {
756
831
  fields: readonly string[];
757
832
  required?: readonly string[];
758
833
  label?: string;
759
834
  description?: string;
760
835
  }): Placeable<CreateRowAction, Record<string, unknown>>;
761
836
  /** Delete a row (cascading, 15 §10.6.1): a built-in action with the row prefilled and nothing to fill. */
762
- export declare function deleteRow(row: PageRow | string, options?: {
837
+ export declare function deleteRowAction(row: PageRow | string, options?: {
763
838
  reason?: string;
764
839
  label?: string;
765
840
  description?: string;
766
841
  }): DeleteRowAction;
767
- type ActionRun<A> = (args: A, ctx: ActionContext) => unknown;
768
- export type DefinedAction<A> = Placeable<CustomAction, {
769
- [K in keyof A]?: A[K] | ChooseParam;
770
- }> & {
771
- readonly actionName: string;
772
- readonly run: ActionRun<A>;
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;
773
845
  };
774
- /**
775
- * A custom action, declared like an LLM function call: `parameters` are everything `run` takes. Where
776
- * the page places it, some parameters may be prefilled; the AI fills the rest.
777
- */
778
- export declare function defineAction<A = Record<string, unknown>>(definition: {
779
- name: string;
780
- description: string;
781
- parameters?: ActionParameters;
782
- run: ActionRun<A>;
783
- }): DefinedAction<A>;
784
846
  export type PageEntryArg = {
785
847
  /** `start`: `persona` and `faq` once, when the conversation starts (24 §4), with the same context. */
786
848
  mode: 'render' | 'start';
787
849
  /** The page function to run; outside a conversation, the first one the page defines. */
788
850
  channel: PageChannel | null;
789
851
  subject: string;
852
+ /** The instance this conversation is on (38 §2.2: a function that needs it is prefilled it). */
853
+ instanceId: string;
790
854
  caller: PageRow | null;
791
855
  session: PageRow | null;
792
856
  conversation: PageConversation | null;
793
857
  runs: PageRuns;
794
858
  scheduledAction: PageScheduledAction | null;
795
859
  officeHours: PageContext['officeHours'];
796
- followUps: PageFollowUp[];
860
+ nextSteps?: PageNextStep[];
797
861
  now: string;
798
862
  /** The contact's time zone and today there (25 §11). */
799
863
  time?: {
800
864
  zone: string;
801
865
  today: string;
802
866
  };
867
+ /** The environment's configuration (76 §2.19): its `env` integrations' values by key, as functions read them. */
868
+ env?: Record<string, unknown>;
803
869
  /** What the customer sent since the last run (20 §5.2): a text run's texts, an email run's emails. */
804
870
  sms?: {
805
871
  inbound: PageSmsMessage[];
@@ -811,6 +877,8 @@ export type PageEntryArg = {
811
877
  call?: {
812
878
  previous: PagePreviousCall | null;
813
879
  farEnd?: PageFarEnd | null;
880
+ heard?: PageHeard | null;
881
+ phase?: PageCallPhase;
814
882
  };
815
883
  }
816
884
  /** The channels with a page function: read once, when the sequence is compiled. */
@@ -828,7 +896,9 @@ export type PageEntryArg = {
828
896
  };
829
897
  /** No runs yet. */
830
898
  export declare function emptyRuns(): PageRuns;
831
- /** What the compiled page script evaluates to: renders the page, or runs one of its actions. */
832
- export declare function pageEntry(mod: Record<string, unknown>): (arg: PageEntryArg) => unknown;
833
- export {};
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;
834
904
  //# sourceMappingURL=define.d.ts.map