@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
@@ -1,22 +1,27 @@
1
1
  import type { CompiledSlotSchema, RuntimeFieldDef } from '../slot/types.js';
2
+ import { type ActionParameters, type PageToolName } from './define.js';
2
3
  import type { ChannelAction, PageAction, PageChannel, SlotRef, SlotState } from './define.js';
4
+ import { type Spoken } from '../conversation/index.js';
3
5
  /**
4
- * `table#n` for each row a conversation has seen: the same row keeps its name on every page of the
5
- * conversation; names only grow and are never reused, so a late output naming a deleted row's name
6
- * cannot reach another row. Serialisable (`toJSON` / `fromJSON`) so a session can keep it.
6
+ * `table:` and the last 12 hex digits of the row's uuid (33): what the row is called in logs, the
7
+ * timeline and the database too, so the same in every conversation and every process; nothing to keep.
8
+ * A name comes from the id alone, never from which row came first: two rows of a table alike in those
9
+ * digits (one page of n rows: about n² / 2⁴⁹) are both named by their whole id from then on, and the
10
+ * short name they share resolves to neither. So a name from an earlier conversation, or another
11
+ * process, means the row it meant or no row (the AI is told), never another row. A name resolves only
12
+ * to a row named here, and the AI's names are checked against the page's own (`one-of`, `enum`) first.
7
13
  */
8
14
  export declare class RowNames {
9
- private readonly byId;
10
- private readonly byName;
11
- private readonly counters;
15
+ /** The rows named here: id → table. */
16
+ private readonly tables;
17
+ /** A short name → the ids of its table ending in its digits. */
18
+ private readonly byShort;
12
19
  name(table: string, id: string): string;
13
20
  resolve(name: string): {
14
21
  table: string;
15
22
  id: string;
16
23
  } | undefined;
17
24
  nameOf(id: string): string | undefined;
18
- toJSON(): Array<[string, string, string]>;
19
- static fromJSON(entries: Array<[string, string, string]>): RowNames;
20
25
  }
21
26
  export type ReadSlot = {
22
27
  value: unknown;
@@ -67,8 +72,10 @@ export type PageNode = BlockNode
67
72
  export type RenderedCell = {
68
73
  slotId: string;
69
74
  ref: SlotRef;
70
- /** The row's page name, `table#n`. */
75
+ /** The row's page name, `table:<uuid tail>`. */
71
76
  row: string;
77
+ /** A ref's value, by its row's name (33). */
78
+ valueRow?: string;
72
79
  label: string;
73
80
  description?: string;
74
81
  /** The schema's; the page's `$extraction` for its `table.field` replaces it (`RenderedPage.extractions`). */
@@ -155,42 +162,53 @@ export type RenderedAction = {
155
162
  parentId: string | null;
156
163
  set: Record<string, unknown>;
157
164
  fields: string[];
158
- required: string[];
165
+ required: string[]; /** The run key, when the page named one. */
166
+ key?: string;
159
167
  } | {
160
168
  kind: 'deleteRow';
161
169
  table: string;
162
170
  rowId: string;
163
- reason?: string;
171
+ reason?: string; /** The run key, when the page named one. */
172
+ key?: string;
164
173
  } | {
165
174
  kind: 'custom';
166
175
  name: string;
167
- prefill: Record<string, unknown>;
176
+ prefill: Record<string, unknown>; /** The run key, when the page named one. */
177
+ key?: string;
168
178
  } | {
169
179
  kind: 'channel';
170
180
  spec: ChannelAction;
171
181
  }
172
- /** A text or an email sent now (25 §8); `to` the contact (null: the conversation's). */
182
+ /**
183
+ * Book the case's next step (40 §2.2) on one of `channels`; `prefill`: what the page fixed (the
184
+ * channel, the contact's id), not asked of the AI.
185
+ */
173
186
  | {
174
- kind: 'message';
175
- channel: 'sms' | 'email';
187
+ kind: 'followUp';
176
188
  key: string;
177
- to: string | null;
178
- body?: string;
179
- subject?: string;
180
- say?: string;
189
+ channels: Array<'call' | 'sms' | 'email'>;
190
+ prefill: {
191
+ channel?: 'call' | 'sms' | 'email';
192
+ contactId?: string;
193
+ };
181
194
  }
182
- /** Book what the customer asked for, as an agreed follow-up (25 §5), on one of `channels`. */
195
+ /** Cancel the case's next step (40 §2.2), with why. */
183
196
  | {
184
- kind: 'followUp';
197
+ kind: 'cancelFollowUp';
185
198
  key: string;
186
- channels: Array<'call' | 'sms' | 'email'>;
199
+ }
200
+ /** A platform tool (76 §2.18): the platform runs it, the AI reads the result next turn. */
201
+ | {
202
+ kind: 'tool';
203
+ tool: PageToolName;
187
204
  }
188
205
  /** A company function (20 §6.2): run on the Worker by the platform, waited for, with the page's prefilled arguments. */
189
206
  | {
190
207
  kind: 'function';
191
- name: string;
192
- say?: string;
193
- prefill?: Record<string, unknown>;
208
+ name: string; /** Per language (66): the engine says the call's. */
209
+ say?: Spoken;
210
+ prefill?: Record<string, unknown>; /** The run key, when the page named one. */
211
+ key?: string;
194
212
  };
195
213
  };
196
214
  /**
@@ -224,6 +242,8 @@ export type RenderedPage = {
224
242
  }>;
225
243
  /** The page's `$extraction` (26 §15.3): how to fill a field on this page, by `table.field`; replaces the schema's. */
226
244
  extractions?: Record<string, string>;
245
+ /** The voice the page asks for (`page({ voice })`, 76). */
246
+ voice?: unknown;
227
247
  warnings: string[];
228
248
  };
229
249
  export declare class PageDocumentError extends Error {
@@ -236,8 +256,30 @@ export type RenderDocumentInput = {
236
256
  names: RowNames;
237
257
  /** The conversation's channel: a button the channel cannot do (a transfer by text) is an error (20 §5.2). */
238
258
  channel?: PageChannel;
259
+ /** The sequence's functions' parameters, from their `args` types (38 §2.4): a function button's. */
260
+ functions?: Readonly<Record<string, {
261
+ parameters?: ActionParameters;
262
+ }>>;
263
+ /** The page's actions' parameters, from their `args` types (38 §2.9): a page action button's. */
264
+ actions?: Readonly<Record<string, {
265
+ parameters?: ActionParameters;
266
+ }>>;
239
267
  };
240
268
  export declare function renderDocument(input: RenderDocumentInput): RenderedPage;
269
+ /**
270
+ * The buttons' ids (46 §2.1), in page order: what each does (its run key's words: a function's name,
271
+ * `add:injury`, `remove`, `transfer`, …); where several on the page do the same, the rows that tell them
272
+ * apart, by page name (`voidInjury@injury:3f9a2c1d7e04`); where that still leaves two alike, `#2`, `#3`
273
+ * after the first. Unique on the page, and the same from one render to the next while the button does
274
+ * the same thing to the same rows.
275
+ */
276
+ export declare function buttonIds(buttons: readonly RenderedAction[], rows: RenderedPage['rows']): string[];
277
+ /**
278
+ * The button the AI means by `id` on this page (46 §2.1), or null. Its own id first; else an id it read
279
+ * on an earlier page, where alike buttons needed their rows (`bookSlot@slot_option:d12f648904ec`) and now
280
+ * one is left (`bookSlot`): the one button doing that to those rows. Never a guess among several.
281
+ */
282
+ export declare function pressedButton(page: RenderedPage, id: string): string | null;
241
283
  /**
242
284
  * The run key of a button on the page (17b §7): the action's own key, whoever runs it — the model
243
285
  * pressing it, or the page function returning it — not its place on the page, which moves with rows.