@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
@@ -0,0 +1,368 @@
1
+ import { type SequenceBuild } from './builder/types.js';
2
+ import { type LogLine, type LogsQuery } from './cli/logs/index.js';
3
+ import type { ApiCall } from './cli/exec/trace.js';
4
+ import { type TestCustomer, type TextCall } from './cli/calls/index.js';
5
+ import { type TurnRead, type TurnsQuery, type TurnSummary } from './cli/turns/index.js';
6
+ import type { CaseOrchestratorTools, ScheduledActionView } from './core/case-orchestrator/types.js';
7
+ import { type PageChannel, type PageContext, type PageEntryArg, type PageNextStep, type PageScheduledAction, type PageStart } from './core/page/define.js';
8
+ import { type MemoryRows } from './core/page/memory-reader.js';
9
+ import type { RecordsCall } from './core/page/records-query.js';
10
+ import { type RenderedPage } from './core/page/render.js';
11
+ import { type ConsoleLevel, type HostResult } from './core/page/sandbox.js';
12
+ import { type OfficeHours, type OfficeHoursSnapshot } from './core/office-hours/index.js';
13
+ import type { SystemContext } from './core/context/types.js';
14
+ import type { Db } from './core/page/define.js';
15
+ import { makeCaseOrchestratorCtx as makePlatformCaseOrchestratorCtx } from './fn-context/make-ctx.js';
16
+ import { type RunResult, type TurnInput } from './cli/turns/shadow.js';
17
+ export { fakeTools, unfaked } from './fn-context/fake/index.js';
18
+ /**
19
+ * What a test may set on the fake `ctx`. Each `api` surface takes only the methods the test fakes
20
+ * (`{ exchanges: { last: async () => ({ exchange: null }) } }`), the rest keep their stand-ins; `api.db`
21
+ * takes any object (`recordingDb`), so a test fakes only the tables it needs.
22
+ */
23
+ export type TestCtxOverrides = {
24
+ today?: string;
25
+ timezone?: string;
26
+ now?: number;
27
+ meta?: Partial<SystemContext['meta']>;
28
+ config?: Partial<SystemContext['config']>;
29
+ api?: {
30
+ [K in keyof SystemContext['api']]?: K extends 'db' ? object : Partial<SystemContext['api'][K]>;
31
+ };
32
+ };
33
+ /**
34
+ * A fake `ctx`, typed as the caller asks: `makeCtx<Ctx>()` for a function, with `Ctx` from the
35
+ * sequence's `__gen`. Data slice defaults: `today` 1970-01-01, `timezone` UTC. Any `api` call the test
36
+ * did not fake rejects, naming the call.
37
+ */
38
+ export declare function makeCtx<C = SystemContext>(overrides?: TestCtxOverrides): C;
39
+ /** A fake Orchestrator `ctx`, typed as the caller asks; `tools` fakes `ctx.api.tools`, `db` fakes `ctx.api.db`. */
40
+ export declare function makeCaseOrchestratorCtx<C = Awaited<ReturnType<typeof makePlatformCaseOrchestratorCtx>>>(overrides?: TestCtxOverrides & {
41
+ tools?: Partial<CaseOrchestratorTools>;
42
+ db?: object;
43
+ }): Promise<C>;
44
+ /** One call a function made on `db`. */
45
+ export type DbCall = {
46
+ table: string;
47
+ method: string;
48
+ args: unknown;
49
+ };
50
+ /** Answers for `db` calls, by table then method; the return value is what the call resolves to. */
51
+ export type DbHandlers = Record<string, Record<string, (args: any) => unknown>>;
52
+ /**
53
+ * A `db` that records every call in `calls`, in order, and answers from `handlers`. A call with no
54
+ * handler rejects, naming it, so a test sees every read and write the function makes.
55
+ */
56
+ export declare function recordingDb(handlers?: DbHandlers): {
57
+ db: Db;
58
+ calls: DbCall[];
59
+ };
60
+ /**
61
+ * A row as `ctx.api.db` hands it out, for a `recordingDb` handler to return: `id` as given, every other
62
+ * field a slot (`{ value, state, reason, updatedAt, ref }`), `filled` when it has a value, `empty` when
63
+ * null. A test that returns plain values instead (`{ crm_id: null }`) checks code against a shape the
64
+ * platform never gives: `if (row.crm_id)` is then false in the test and always true for real.
65
+ */
66
+ export declare function row(table: string, values: {
67
+ id: string;
68
+ } & Record<string, unknown>): any;
69
+ /** One request `mockFetch` answered. */
70
+ export type FetchCall = {
71
+ method: string;
72
+ url: string;
73
+ body: string | null;
74
+ };
75
+ /** A route: requests whose method (any, when left out) and URL (exact, or a pattern) match it. */
76
+ export type FetchRoute = {
77
+ method?: string;
78
+ url: string | RegExp;
79
+ /** A `Response` is returned as is; any other value is sent as JSON with status 200. */
80
+ respond: (request: Request) => unknown;
81
+ };
82
+ /**
83
+ * Replaces the global `fetch` until `restore()`: each request goes to the first matching route; one
84
+ * that matches none rejects, so a test never reaches a real system (a CRM, a payment provider).
85
+ */
86
+ export declare function mockFetch(routes: FetchRoute[]): {
87
+ calls: FetchCall[];
88
+ restore: () => void;
89
+ };
90
+ /** What the page function gets besides the data; each left out is what a conversation without it has. */
91
+ export type RenderPageInput = {
92
+ /** The sequence: its directory under `sequences/`. */
93
+ sequence: string;
94
+ /** The repository's root; the working directory when left out (where `npm test` runs). */
95
+ repoRoot?: string;
96
+ /** The rows the page can read, by table: `{ contact: [{ id: 'c1', first_name: 'Ann' }] }`. A field left out or null is empty. */
97
+ data: MemoryRows;
98
+ /** The id of the row the sequence runs about (its `subject` table's). */
99
+ subject: string;
100
+ /** The conversation's contact (`ctx.caller`), one of `data.contact`; none outside a conversation. */
101
+ caller?: string | null;
102
+ /** The page function to run; the page's first one when left out. */
103
+ channel?: PageChannel | null;
104
+ /** The render's time (ISO 8601); 2026-01-01T15:00:00Z when left out. */
105
+ now?: string;
106
+ scheduledAction?: PageScheduledAction | null;
107
+ officeHours?: PageContext['officeHours'];
108
+ nextSteps?: PageNextStep[];
109
+ /** `ctx.env`: the environment's configuration the page reads (76 §2.19); none when left out. A turn's export does not carry it. */
110
+ env?: Record<string, unknown>;
111
+ sms?: {
112
+ inbound: NonNullable<Extract<PageEntryArg, {
113
+ mode: 'render' | 'start';
114
+ }>['sms']>['inbound'];
115
+ };
116
+ email?: NonNullable<Extract<PageEntryArg, {
117
+ mode: 'render' | 'start';
118
+ }>['email']>;
119
+ call?: NonNullable<Extract<PageEntryArg, {
120
+ mode: 'render' | 'start';
121
+ }>['call']>;
122
+ /**
123
+ * `ctx.history`: the counts and the timeline the page reads; 0 and none when left out. Or each call and
124
+ * its answer (`[{ method, where, result }]`, a turn's export): a call not among them fails the render.
125
+ */
126
+ history?: {
127
+ sessionCount?: number;
128
+ exchangeCount?: number;
129
+ timeline?: unknown[];
130
+ } | HistoryAnswer[];
131
+ /** `ctx.session`, as the page gets it (a call's session row); none when left out. */
132
+ session?: RenderArg['session'];
133
+ /** `ctx.runs`: what the conversation's actions did; none when left out. */
134
+ runs?: RenderArg['runs'];
135
+ /** `ctx.conversation`; none when left out. */
136
+ conversation?: RenderArg['conversation'];
137
+ /** The case's id (`ctx.instanceId`); `test-instance` when left out. */
138
+ instanceId?: string;
139
+ };
140
+ /** What a render or a start of the page function is given. */
141
+ type RenderArg = Extract<PageEntryArg, {
142
+ mode: 'render' | 'start';
143
+ }>;
144
+ /** One `ctx.history` call a page made and its answer, as a turn's export keeps them. */
145
+ export type HistoryAnswer = {
146
+ method: unknown;
147
+ where: unknown;
148
+ result: HostResult;
149
+ };
150
+ export type RenderedTestPage = {
151
+ /** The page as the platform builds it from what the page function returned: its blocks, fields, buttons. */
152
+ page: RenderedPage;
153
+ /** The page as the AI reads it. */
154
+ text: string;
155
+ /** Every `db` read the page made, in order. */
156
+ reads: RecordsCall[];
157
+ /** The page's `console` lines. */
158
+ console: Array<{
159
+ level: ConsoleLevel;
160
+ text: string;
161
+ }>;
162
+ };
163
+ /** A page script that failed: what the sandbox said, and where in the compiled page it threw. */
164
+ export declare class PageTestError extends Error {
165
+ readonly scriptStack: string | null;
166
+ constructor(message: string, scriptStack: string | null);
167
+ }
168
+ /**
169
+ * Renders the sequence's page (`context.page.ts`) over `data`, as the platform renders it: the same
170
+ * compile, sandbox, `db` semantics and page building, with the rows read from `data` instead of the
171
+ * database. A read the platform refuses is refused here too.
172
+ */
173
+ export declare function renderPage(input: RenderPageInput): Promise<RenderedTestPage>;
174
+ /**
175
+ * A turn's export (`turns export <turnId>`, `exportTurn`) as `renderPage`'s input: the moment the turn
176
+ * began — its rows, its `ctx`, and each `ctx.history` answer — to render with this repository's code now.
177
+ */
178
+ export declare function fromTurn(dir: string, options?: {
179
+ repoRoot?: string;
180
+ }): RenderPageInput;
181
+ /** What the page decides when the conversation starts (its `persona` and `faq`), over `data`. */
182
+ export declare function startPage(input: RenderPageInput): Promise<PageStart>;
183
+ /**
184
+ * The office hours (`office-hours.ts`) at `at` (ISO 8601 or epoch ms), as the platform reads them: open
185
+ * or not, and today's windows. Office hours the platform would refuse fail with what is wrong.
186
+ */
187
+ export declare function officeHoursAt(officeHours: OfficeHours, at: string | number): OfficeHoursSnapshot;
188
+ /**
189
+ * The sequence compiled as a release compiles it (`index.ts`, its variables, functions, events, office
190
+ * hours, Orchestrator and page), for a test that checks its configuration. A configuration the release
191
+ * would refuse rejects with the release's message. Compiled once per test run.
192
+ */
193
+ export declare function compileForTest(input: {
194
+ sequence: string;
195
+ repoRoot?: string;
196
+ }): Promise<SequenceBuild>;
197
+ export type { ApiCall, LogLine, LogsQuery, OfficeHours, OfficeHoursSnapshot, SequenceBuild };
198
+ export type { TurnRead, TurnRecord, TurnSnapshot, TurnsQuery, TurnSummary } from './cli/turns/index.js';
199
+ export type { InboxItem, SentResult, TestCustomer, TextCall, TextCallEnd, TextCallEvent, TextCallStep } from './cli/calls/index.js';
200
+ /** An open connection to an environment for an integration test (`connect`). */
201
+ export type Connection<C = SystemContext> = {
202
+ /** The environment (never prod). */
203
+ environment: {
204
+ id: string;
205
+ name: string;
206
+ };
207
+ /** A real `ctx`: each `ctx.api` call reads and writes the environment's data, and is recorded in `calls`. */
208
+ ctx: C;
209
+ /**
210
+ * The last 200 `ctx.api` calls made through `ctx`, in order: `call`, `input`, `ok`, `output` or `error`,
211
+ * `ms`. Every call, however many, is in `callsFile` (one JSON per line).
212
+ */
213
+ calls: ApiCall[];
214
+ callsFile: string;
215
+ /**
216
+ * What the code wrote (`ctx.api.log`, the page's `console`, its functions' failures) in this environment,
217
+ * read from the platform's log store now: oldest first, since this connection opened unless `since` says
218
+ * otherwise, at most `limit` (200; 500 at most). Filter by `instance`, `run`, `contact`, `sequence`,
219
+ * `request`, `level` (`warn`: warn and error), `search`. Lines reach the store a few seconds after they
220
+ * are written.
221
+ */
222
+ logs(query?: Omit<LogsQuery, 'env'>): Promise<LogLine[]>;
223
+ /**
224
+ * A case's page as a conversation on it renders it now: this repository's page, the case's real data.
225
+ * `caller`: the conversation's contact; the case's subject when it is a contact and none is named.
226
+ * Returns `page` and `text` as the unit tests' `renderPage` does, so the same checks apply.
227
+ */
228
+ renderPage(input: {
229
+ instanceId: string;
230
+ channel: PageChannel;
231
+ caller?: string;
232
+ }): Promise<{
233
+ page: RenderedPage;
234
+ text: string;
235
+ }>;
236
+ /**
237
+ * The case's Orchestrator run now, as after an external event (`ctx.api.instances.notify`), with the
238
+ * inputs the platform builds for the case and this repository's code. Says how it ended and the
239
+ * follow-ups it scheduled and cancelled; they are real, and run when due.
240
+ */
241
+ runOrchestrator(input: {
242
+ instanceId: string;
243
+ reason?: string;
244
+ }): Promise<{
245
+ status: 'completed' | 'failed' | 'held' | 'idle' | 'no_orchestrator';
246
+ failureCode?: string;
247
+ scheduled: ScheduledActionView[];
248
+ cancelled: ScheduledActionView[];
249
+ }>;
250
+ /**
251
+ * One turn, always a shadow (68 §8): a text or email run, or a call's turn, as when the customer writes or
252
+ * says `say`, with this repository's page, the platform's model, and the case's data as it is now — or
253
+ * `from` a turn that ran (its id, or the directory it was exported to): its rows and conversation as they
254
+ * were then, its words heard again (`say` replaces them). It runs on a shadow of the environment's
255
+ * database: what it did comes back (`writes`, `actions`, `said`, `events`) and none of it is kept, sent,
256
+ * booked or woken. Company functions are not run: replayed from the turn's record (`from`), else
257
+ * `functions.results`, else answered as not run (`functions` says which). The model words things
258
+ * differently each time: check what it did, and with `repeat` how often (`rate(run => run.clicked('x'))`).
259
+ */
260
+ turn(input: TurnInput): Promise<RunResult>;
261
+ /**
262
+ * Runs `actions` on the case's page as the model's step would, with no model: `{ fill: '<field id>',
263
+ * value }`, `{ click: '<button id>', arguments }`, `{ note: '…' }`… (field and button ids as the page
264
+ * names them: `renderPage`'s `text`). Then the run ends without a reply. `stepResult` is what the
265
+ * platform told the model about each action.
266
+ */
267
+ act(input: TurnInput & {
268
+ actions: unknown[];
269
+ }): Promise<RunResult>;
270
+ /**
271
+ * The turns of a case, a run or a call in this environment, oldest first (68 §7.4): what the customer
272
+ * said, what the AI said, the buttons and functions it ran, the fields it wrote. Name one of them.
273
+ */
274
+ turns(query: TurnsQuery): Promise<TurnSummary[]>;
275
+ /** One turn, and what it began with (`snapshot`: null once it is no longer kept, after 30 days). */
276
+ readTurn(turnId: string): Promise<TurnRead>;
277
+ /** One turn written to `dir` (`.superpanel/turns/<turnId>/` when left out), as `turns export` writes it; the directory. */
278
+ exportTurn(turnId: string, dir?: string): Promise<string>;
279
+ /**
280
+ * Test lines and customers (68 §5.3): `line(name)` is the environment's simulated line of that name
281
+ * (`Main line` when left out), made when it has none, a number no provider carries; `phone()` a new test
282
+ * customer's number. A simulated line reaches test customers only, and a test customer only a simulated line.
283
+ */
284
+ sim: {
285
+ /**
286
+ * When a real line has that name, the simulated line stands in for it (`mirrors`): your `resolve` sees
287
+ * it by that name, and code's `from` that names the real line reaches a test customer through it.
288
+ */
289
+ line(name?: string): Promise<{
290
+ id: string;
291
+ number: string;
292
+ name: string;
293
+ mirrors: {
294
+ id: string;
295
+ number: string;
296
+ } | null;
297
+ }>;
298
+ /** The environment's simulated mailbox of that name (`Support` when left out), made when it has none: an address no provider has; standing in for a real one of that name, as `line` does. */
299
+ mailbox(name?: string): Promise<{
300
+ id: string;
301
+ address: string;
302
+ name: string;
303
+ mirrors: {
304
+ id: string;
305
+ address: string;
306
+ } | null;
307
+ }>;
308
+ phone(): string;
309
+ /**
310
+ * A test customer (68 §5.2), a new number and address unless given: they text and email the simulated
311
+ * lines and mailboxes, wait for what the environment sends them (`next('sms')`, `next('call')`), and
312
+ * answer or let ring its calls.
313
+ */
314
+ customer(input?: {
315
+ phone?: string;
316
+ email?: string;
317
+ }): TestCustomer;
318
+ };
319
+ /**
320
+ * A case's next scheduled step done now, as its job would when due (68 §6.4): for a step that waits for a
321
+ * day ("call on day 2"). Contact hours are the environment's to switch off (Environments page), not this.
322
+ */
323
+ runDue(input: {
324
+ instanceId: string;
325
+ scheduledActionId?: string;
326
+ }): Promise<{
327
+ action: {
328
+ id: string;
329
+ kind: string;
330
+ name: string | null;
331
+ reason: string | null;
332
+ scheduledFor: string;
333
+ } | null;
334
+ result: unknown;
335
+ }>;
336
+ /**
337
+ * A call in text (68 §4): a test customer (`from`, `sim.phone()`) calls a simulated line (`to`, its name or
338
+ * number, `Main line` when left out). This repository's code on the environment's real data, as a real
339
+ * call: the resolves, the opening, each turn, the wrap-up after the hang-up, `call.ended`, the Orchestrator.
340
+ * What the AI says comes back as text; a keypad, a transfer or a voicemail as an event to answer.
341
+ */
342
+ call: {
343
+ inbound(input: {
344
+ from: string;
345
+ to?: string;
346
+ }): Promise<TextCall>;
347
+ };
348
+ /** Stops serving this repository on the environment. Called by itself after the test file's tests. */
349
+ close(): Promise<void>;
350
+ };
351
+ export type { RunResult, ShadowRun, TurnInput } from './cli/turns/shadow.js';
352
+ /**
353
+ * Connects a test file to an environment (`sandbox` when `env` is left out) as the CLI's login: this
354
+ * repository's code serves it (as `superpanel-sdk-runtime serve` does, its imports checked as a release
355
+ * checks them) until the file's tests are done, and `ctx` reads and writes the environment's real data.
356
+ * What a test writes is written.
357
+ */
358
+ /**
359
+ * `debug`: when a test's debug package is written (68 §9, `.superpanel/tests/`): `failed` (the default),
360
+ * `always`, or `off`; `SUPERPANEL_TEST_DEBUG` overrides it.
361
+ */
362
+ export declare function connect<C = SystemContext>(options?: {
363
+ env?: string;
364
+ repoRoot?: string;
365
+ url?: string;
366
+ debug?: 'failed' | 'always' | 'off';
367
+ }): Promise<Connection<C>>;
368
+ //# sourceMappingURL=testing.d.ts.map