@ref0/sdk 0.0.0-stage → 0.5.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.
@@ -0,0 +1,674 @@
1
+ import { $t as WorkflowCallRefused, An as WorkflowText, B as GetIssueInput, Cn as WorkflowPermissions, E as ConnectionCallAnswer, En as WorkflowPullRequestOpen, I as EventRunInput, It as ThreadStage, Jt as WorkflowCall, L as ForkAnswer$1, Mn as WorkflowTrigger, Mt as StartActor$1, Nt as StartRun$1, On as WorkflowStartEnded, Qt as WorkflowCallRefusal, R as ForkCreate, Sn as WorkflowPasskeyState, St as SandboxPushAnswer, T as ConnectionCall, Tn as WorkflowPullRequestAnswer, Ut as WorkflowAction, Wt as WorkflowActionAnswer, Xt as WorkflowCallEnded, Yt as WorkflowCallAnswer, Zt as WorkflowCallInput, _ as CheckRunError, _n as WorkflowOwn, _t as SandboxExec, an as WorkflowCheckResultsAnswer, bn as WorkflowPasskeyEnded, bt as SandboxOpenAnswer, cn as WorkflowCheckStart, dn as WorkflowCheckStatesAnswer, en as WorkflowCalledState, fn as WorkflowCheckWhere, g as CheckOwn, gn as WorkflowFilters, h as CheckOn, hn as WorkflowEvent, in as WorkflowCheckResults, jn as WorkflowThreadStart, kn as WorkflowStartState, ln as WorkflowCheckStartAnswer, mn as WorkflowConnections, nn as WorkflowCheckRefusal, on as WorkflowCheckRun, pn as WorkflowComment, pt as Ref0Owned, qt as WorkflowAskClosed, rn as WorkflowCheckRefused, sn as WorkflowCheckRunEnded, tn as WorkflowCalledStateAnswer, un as WorkflowCheckStates, v as CheckRunParams, vn as WorkflowPasskeyAsk, vt as SandboxExecAnswer, xn as WorkflowPasskeyRead, xt as SandboxPush, y as CheckTreeEntry, yn as WorkflowPasskeyAsked, yt as SandboxOpen } from "./index-Dns8tCkT.mjs";
2
+ import { z } from "zod";
3
+ //#region src/needs.d.ts
4
+ /**
5
+ * The needs the gate returns, as the SDK makes them: each an empty object, with what it needs
6
+ * and the stack it was made on kept beside it, out of the gate's reach. So the gate returns only
7
+ * needs the SDK made, and ref0 reads where each came from, the line of `gate.ts` on that stack.
8
+ */
9
+ declare const needMade: unique symbol;
10
+ declare const checkNeedMade: unique symbol;
11
+ /** Something a change needs before it merges, as ref0 makes one for the gate to return. */
12
+ interface Need {
13
+ readonly [needMade]: true;
14
+ }
15
+ /**
16
+ * A need for a check's runs, as calling its handle makes one, `e2e({ spec })`: the one need a
17
+ * wrapper such as `local` takes, since it holds the check's params.
18
+ */
19
+ interface CheckNeed extends Need {
20
+ readonly [checkNeedMade]: true;
21
+ }
22
+ //#endregion
23
+ //#region src/start-rules.d.ts
24
+ /**
25
+ * A check's start rule, its `start`, and what it returns: `allow()`, `refuse(text)`, a called
26
+ * workflow's run, or a falsy value, as `&&` gives one. ref0 calls the rule in the check's own
27
+ * isolate before any start that isn't ref0's own makes a new run, once for each new run, with
28
+ * that run's params. A start that joins a run going, or is answered by one that ended, never
29
+ * reaches it. Any `refuse` refuses the start, with each refusal's words, and an `allow` overrides
30
+ * none. Otherwise a called workflow's run makes the start wait on it, and every such run must
31
+ * allow. A list with none of them allows.
32
+ */
33
+ /**
34
+ * Who's starting a check: a person, an agent with its owner, or ref0's own part, such as
35
+ * `ref0:workflows` for a workflow's start. Its `chain` runs up to the person accountable for it:
36
+ * an agent's session, the attachment its credential was made under and its person; or a
37
+ * workflow's run and its accountable person. A person starting their own has none.
38
+ */
39
+ type StartActor = (typeof StartActor$1)['Encoded'];
40
+ /**
41
+ * One run of the check started in the last day, newest first, the start's own new runs judged
42
+ * before this one first, so a grid can't pass a limit its rule counts. Each says when it started,
43
+ * and its actor, `{ kind: 'hidden', id: null }` unless the starter may read where it ran or it's
44
+ * their own, so a limit for each actor or for the repo counts every run. A run of ref0's part is
45
+ * no starter's own: one workflow's run is hidden from another's start like anyone's. Where it
46
+ * ran, its params and how it ended are there only from a scope the starter may read, and for a
47
+ * thread's own rule, one `main` doesn't have, only from that thread.
48
+ */
49
+ type StartRun = (typeof StartRun$1)['Encoded'];
50
+ /** What a start rule is given, for one new run a start would make. */
51
+ interface StartContext<Params> {
52
+ readonly actor: StartActor;
53
+ /** That run's params, as the check's `params` parsed them. */
54
+ readonly params: Params;
55
+ /** Where it would run: `main`'s tree, or the head of a thread. */
56
+ readonly where: WorkflowCheckWhere;
57
+ readonly runs: ReadonlyArray<StartRun>;
58
+ /**
59
+ * When the start is judged, in milliseconds since the epoch, as each `startedAt` is: the start's
60
+ * own new runs judged before this one started then. Count `runs` started past `now - window`
61
+ * for a limit over a window shorter than the day, since a check's code can't read the clock.
62
+ */
63
+ readonly now: number;
64
+ }
65
+ /** A start rule's yes: the start may make its run, unless another item of its list refuses it. */
66
+ interface Allow {
67
+ readonly kind: 'allow';
68
+ }
69
+ /** A start rule's no, in words its starter sees: one of its code's `text` templates. */
70
+ interface Refusal {
71
+ readonly kind: 'refuse';
72
+ readonly text: (typeof WorkflowText)['Encoded'];
73
+ }
74
+ /**
75
+ * A run of a called workflow on its input, what calling the workflow's handle makes,
76
+ * `approveE2e({ browser: 'webkit' })`, typed by what the workflow returns. In a start rule's list,
77
+ * one whose workflow returns `allow()` or `refuse(text)`: the start waits, holding no run, while
78
+ * ref0 runs it as the starter's person's, and its output decides the start.
79
+ */
80
+ interface CalledRun<Output = unknown> {
81
+ readonly kind: 'workflow';
82
+ readonly workflow: string;
83
+ readonly input: (typeof WorkflowCallInput)['Encoded'];
84
+ /** Only its type: what the workflow returns. */
85
+ readonly '~output'?: Output;
86
+ }
87
+ /** What a called workflow a start waits on returns: `allow()` lets the start go on. */
88
+ type StartOutput = Allow | Refusal;
89
+ /** One item of a start rule's list: falsy ones are dropped. */
90
+ type StartItem = Allow | Refusal | CalledRun<StartOutput> | false | null | undefined | 0 | '';
91
+ /** A check's start rule: the list for one new run, or a promise of it. */
92
+ type StartRule<Params> = (context: StartContext<Params>) => ReadonlyArray<StartItem> | Promise<ReadonlyArray<StartItem>>;
93
+ /** Lets a start make its run, unless another item of the rule's list refuses it. */
94
+ declare const allow: () => Allow;
95
+ /** Refuses a start, in words: `` refuse(text`Ten e2e runs a day each. Reuse a result instead`) ``. */
96
+ declare const refuse: (text: Refusal['text']) => Refusal;
97
+ //#endregion
98
+ //#region src/tree.d.ts
99
+ /**
100
+ * A tree, as `.ref0/` code reads one: a check run's `repo`, the tree it judges, and the gate's
101
+ * `change.before` and `change.after`. Each read goes to ref0 over RPC, which reads it from the
102
+ * repo's stored objects, counts it and keeps it, so a read always answers for that one tree.
103
+ */
104
+ /** A JSON value, as a check's params, output and `readJSON` hold them. */
105
+ type JsonValue = CheckRunParams[string];
106
+ /** Where a read of a tree looks: a path from the tree's root, with no `..`. `''` is the root, which `readTree` lists. */
107
+ interface TreeRead {
108
+ readonly path: string;
109
+ }
110
+ /** One entry of a folder, as `readTree` answers it: its name and its kind. */
111
+ type TreeEntry = (typeof CheckTreeEntry)['Encoded'];
112
+ /**
113
+ * Reads of one tree, and of nothing else, as Cloudflare's `ArtifactsRepo.readFile` reads a repo
114
+ * without its `ref`, which can only be that tree. A file past the most a read holds throws: 8 MiB
115
+ * in a check run, 1 MiB in the gate.
116
+ */
117
+ interface Tree {
118
+ /** The file at a path, or `null` when the tree has none there. */
119
+ readonly readFile: (read: TreeRead) => Promise<Blob | null>;
120
+ /** The file at a path, as UTF-8 text, or `null` when the tree has none there. */
121
+ readonly readText: (read: TreeRead) => Promise<string | null>;
122
+ /**
123
+ * The file at a path, as JSON, or `null` when the tree has none there, as for a file that
124
+ * holds `null`. A file that isn't JSON throws.
125
+ */
126
+ readonly readJSON: (read: TreeRead) => Promise<JsonValue>;
127
+ /**
128
+ * The folder at a path, as its entries sorted by name, or `null` when the tree has no folder
129
+ * there. A file there throws, as does a folder past 10,000 entries.
130
+ */
131
+ readonly readTree: (read: TreeRead) => Promise<ReadonlyArray<TreeEntry> | null>;
132
+ }
133
+ //#endregion
134
+ //#region src/run-scope.d.ts
135
+ /**
136
+ * What a workflow run's code is inside as it runs: the run's sink, for everything it asks of
137
+ * ref0, and the step whose callback it's in, if any. A check's handle reads them, so an import of
138
+ * a check runs it in the run that calls it.
139
+ */
140
+ /**
141
+ * Where ref0 hears a run's actions, its calls, its forks, its sandboxes and its passkey requests,
142
+ * one for each at its place, its checks and the called workflows it runs. A sandbox opened in a
143
+ * step's attempt takes its commands and its close here too.
144
+ */
145
+ interface ActionSink {
146
+ readonly act: (action: (typeof WorkflowAction)['Encoded']) => Promise<(typeof WorkflowActionAnswer)['Encoded']>;
147
+ readonly callConnection: (call: (typeof ConnectionCall)['Encoded']) => Promise<(typeof ConnectionCallAnswer)['Encoded']>;
148
+ /** A fork of the run's repo, made at its place in the run. */
149
+ readonly createFork: (fork: (typeof ForkCreate)['Encoded']) => Promise<(typeof ForkAnswer$1)['Encoded']>;
150
+ /** A pull request from a fork the run got, opened at its place in the run. */
151
+ readonly openPullRequest: (open: (typeof WorkflowPullRequestOpen)['Encoded']) => Promise<(typeof WorkflowPullRequestAnswer)['Encoded']>;
152
+ /** A call of a called workflow, in the step that makes it: the child run it started. */
153
+ readonly callWorkflow: (call: (typeof WorkflowCall)['Encoded']) => Promise<(typeof WorkflowCallAnswer)['Encoded']>;
154
+ /** How a child run the run called is going: going, done with its output, or failed. */
155
+ readonly calledState: (read: (typeof WorkflowCalledState)['Encoded']) => Promise<(typeof WorkflowCalledStateAnswer)['Encoded']>;
156
+ /** A start of a check's runs, in the step that starts them. */
157
+ readonly startChecks: (start: (typeof WorkflowCheckStart)['Encoded']) => Promise<(typeof WorkflowCheckStartAnswer)['Encoded']>;
158
+ /**
159
+ * Where a start of a check's runs that waited on called workflows stands: started, with its
160
+ * runs; still waiting; or refused.
161
+ */
162
+ readonly startState: (read: (typeof WorkflowStartState)['Encoded']) => Promise<(typeof WorkflowCheckStartAnswer)['Encoded']>;
163
+ /** Whether the check runs the run waits on have ended. */
164
+ readonly checkStates: (read: (typeof WorkflowCheckStates)['Encoded']) => Promise<(typeof WorkflowCheckStatesAnswer)['Encoded']>;
165
+ /** A page of the results of check runs the run waited on. */
166
+ readonly checkResults: (read: (typeof WorkflowCheckResults)['Encoded']) => Promise<(typeof WorkflowCheckResultsAnswer)['Encoded']>;
167
+ /** A sandbox for one attempt of the step that opens it. */
168
+ readonly openSandbox: (open: (typeof SandboxOpen)['Encoded']) => Promise<(typeof SandboxOpenAnswer)['Encoded']>;
169
+ readonly execSandbox: (exec: (typeof SandboxExec)['Encoded']) => Promise<(typeof SandboxExecAnswer)['Encoded']>;
170
+ readonly closeSandbox: (sandbox: string) => Promise<void>;
171
+ /** A push from a sandbox the run opened on a fork, at its place in the run. */
172
+ readonly pushSandbox: (push: (typeof SandboxPush)['Encoded']) => Promise<(typeof SandboxPushAnswer)['Encoded']>;
173
+ /** A passkey request, made once at its place in the run. */
174
+ readonly askPasskey: (ask: (typeof WorkflowPasskeyAsk)['Encoded']) => Promise<(typeof WorkflowPasskeyAsked)['Encoded']>;
175
+ /** Where one of the run's passkey requests stands. */
176
+ readonly passkeyState: (read: (typeof WorkflowPasskeyRead)['Encoded']) => Promise<(typeof WorkflowPasskeyState)['Encoded']>;
177
+ }
178
+ //#endregion
179
+ //#region src/called.d.ts
180
+ /**
181
+ * A called workflow's handle, as code that imports its file sees it, as a check's is: ref0's
182
+ * bundler swaps an import of `.ref0/workflows/<name>.ts` for `workflowHandle('<name>')`, so the
183
+ * workflow's code loads only in its own runs' isolates. In a start rule, calling it makes a run
184
+ * to wait on, `approveE2e({ browser: 'webkit' })`; in a workflow's run, `.run(step, input)` runs it
185
+ * as a child run of its own, waits for it in the run, and answers its output.
186
+ */
187
+ /**
188
+ * A called workflow, as code that imports its file sees it: `import approveE2e from
189
+ * './approve-e2e'`. What its file exports also keeps what ref0 calls on it in its own isolate, as
190
+ * `WorkflowOwn` in `@ref0/contracts` says; an import of the file is a handle without it.
191
+ */
192
+ interface CalledWorkflow<Input = unknown, Output = unknown> extends Partial<Ref0Owned<WorkflowOwn<WorkflowStep, ActionSink>>> {
193
+ /**
194
+ * A run of this workflow on `input`, for a start rule's list, which its output decides: a
195
+ * workflow that returns `allow()` or `refuse(text)`.
196
+ */
197
+ (input: Input): CalledRun<Output>;
198
+ /**
199
+ * Runs it as a child run of this run, in steps of its own, so call it outside `step.do`'s
200
+ * callback: it waits for the child's end in the run, and answers what the child returned, or
201
+ * throws `CalledRunFailed`. Each call is one child, found again by a replay; a second call of the
202
+ * same workflow is a child of its own.
203
+ */
204
+ readonly run: (step: WorkflowStep, input: Input) => Promise<Output>;
205
+ }
206
+ /**
207
+ * Why a call of a called workflow failed in its caller: ref0 refused it, by `why`, with what to do
208
+ * next, such as a chain of calls past four workflows; or the child run ended without returning,
209
+ * `failed`, in words that say how, such as its code throwing or its time running out. A refusal
210
+ * is kept as its step's result, so a replay throws it again and calls nothing.
211
+ */
212
+ declare class CalledRunFailed extends Error {
213
+ readonly workflow: string;
214
+ readonly why: WorkflowCallRefusal | 'failed';
215
+ /** The child run, once there is one. */
216
+ readonly run: string | undefined;
217
+ constructor(workflow: string, failed: (typeof WorkflowCallRefused)['Encoded'] | {
218
+ readonly kind: 'failed';
219
+ readonly why: string;
220
+ }, run?: string);
221
+ }
222
+ //#endregion
223
+ //#region src/workflow.d.ts
224
+ /**
225
+ * `workflow()` and what a run's code reads and asks, as a repo's `.ref0/workflows/` code imports
226
+ * them from `@ref0/sdk`. A workflow is one of two kinds: an event workflow, with `on`, runs on
227
+ * its events; a called workflow, with `input` and `title`, runs only when another workflow's run
228
+ * calls it, and returns its output. A run is a Workflows instance: its code gets Cloudflare's
229
+ * `step` and acts through `ref0` inside a step, each action applied once at its place in the run.
230
+ * ref0 bundles its own build of this file into each workflow, whatever version the repo's
231
+ * lockfile holds, and checks every action outside the run's isolate, so nothing here is trusted
232
+ * to check anything.
233
+ */
234
+ /** A trigger's event, as a run reads it. */
235
+ type EventOf<T extends WorkflowTrigger> = Extract<(typeof WorkflowEvent)['Encoded'], {
236
+ readonly kind: T;
237
+ }>;
238
+ /**
239
+ * The `type` of an event ref0 sends a run, which its `step.waitForEvent` names: a thread it
240
+ * started moving to a stage, `thread-61-settled`; a repeat of that thread's occurrence,
241
+ * `thread-61-repeated`; its ask's close, `ask-ship`, by the ask's key, which `ask.run` waits for;
242
+ * the end of a check run it started, `check-<run>`, which a check's `run` and `wait` wait for; or
243
+ * the end of a child run it called, `workflow-<run>`, which a called workflow's `run` waits for;
244
+ * or the end of its passkey request, `passkey-<request>`, which `passkey.run` waits for; or the
245
+ * end of a start of a check it made that waited on called workflows, `start-<start>`, which a
246
+ * check's `run` and `start` wait for.
247
+ */
248
+ type WaitType = `thread-${number}-${(typeof ThreadStage)['Encoded'] | 'repeated'}` | `ask-${string}` | `check-${string}` | `workflow-${string}` | `passkey-${string}` | `start-${string}`;
249
+ /** That a check run a run started has ended: its result is read from ref0, as `wait` reads it. */
250
+ type CheckRunEnded = (typeof WorkflowCheckRunEnded)['Encoded'];
251
+ /** That a child run a run called has ended: how it went is read from ref0. */
252
+ type CallEnded = (typeof WorkflowCallEnded)['Encoded'];
253
+ /** The event a `WaitType` brings, as a run reads it. */
254
+ type WaitedEvent<K extends WaitType> = K extends `ask-${string}` ? (typeof WorkflowAskClosed)['Encoded'] : K extends `check-${string}` ? CheckRunEnded : K extends `workflow-${string}` ? CallEnded : K extends `passkey-${string}` ? (typeof WorkflowPasskeyEnded)['Encoded'] : K extends `start-${string}` ? (typeof WorkflowStartEnded)['Encoded'] : K extends `thread-${number}-repeated` ? EventOf<'occurrence.repeated'> : EventOf<'thread.stage.moved'>;
255
+ /** A duration as Workflows reads one: `'10 minutes'`, `'1 day'`, or milliseconds. */
256
+ type Duration = `${number} ${'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'}${'s' | ''}` | number;
257
+ /** How a step is tried again, and how long one attempt may take, as Workflows reads it. */
258
+ interface StepConfig {
259
+ readonly retries?: {
260
+ readonly limit: number;
261
+ readonly delay: Duration;
262
+ readonly backoff?: 'constant' | 'linear' | 'exponential';
263
+ };
264
+ readonly timeout?: Duration;
265
+ }
266
+ /** What a step's callback is given: the step's name and count, and which attempt this is. */
267
+ interface StepContext {
268
+ readonly step: {
269
+ readonly name: string;
270
+ readonly count: number;
271
+ };
272
+ readonly attempt: number;
273
+ }
274
+ /**
275
+ * Cloudflare's `WorkflowStep`, as a run's code gets it: each step's result is kept, so a replay
276
+ * of the run returns it again rather than running the step. Everything outside a step runs
277
+ * again on each replay.
278
+ */
279
+ interface WorkflowStep {
280
+ do<T>(name: string, callback: (context: StepContext) => Promise<T>): Promise<T>;
281
+ do<T>(name: string, config: StepConfig, callback: (context: StepContext) => Promise<T>): Promise<T>;
282
+ sleep(name: string, duration: Duration): Promise<void>;
283
+ sleepUntil(name: string, timestamp: Date | number): Promise<void>;
284
+ /**
285
+ * Waits for the event ref0 sends the run under `type`, or until `timeout`, when it throws. An
286
+ * event sent before the wait is reached is kept for it. ref0 sends each in order, at least
287
+ * once: one whose send it couldn't confirm comes again, so a move's `revision` and a repeat's
288
+ * `count` tell it from the next.
289
+ */
290
+ waitForEvent<const K extends WaitType>(name: string, options: {
291
+ readonly type: K;
292
+ readonly timeout?: Duration;
293
+ }): Promise<{
294
+ readonly payload: WaitedEvent<K>;
295
+ readonly timestamp: Date;
296
+ readonly type: K;
297
+ }>;
298
+ }
299
+ type Comment = Omit<(typeof WorkflowComment)['Encoded'], 'verb'>;
300
+ type ThreadStart = Omit<(typeof WorkflowThreadStart)['Encoded'], 'verb'>;
301
+ type ActionAnswer = (typeof WorkflowActionAnswer)['Encoded'];
302
+ /**
303
+ * Where `pr.needs.add` adds: an attached workflow names the repo, since its thread may hold more.
304
+ */
305
+ interface NeedAddOptions {
306
+ readonly repo?: string;
307
+ }
308
+ /** What `forks.create` takes: a key naming what the fork is for, across runs, if any. */
309
+ type ForkOptions = Omit<(typeof ForkCreate)['Encoded'], 'place'>;
310
+ /** The run's fork, by its number in the run, or why not, never thrown. */
311
+ type ForkAnswer = (typeof ForkAnswer$1)['Encoded'];
312
+ /** What `pr.open` takes: the fork as `forks.create` answered it, and the title, as `text`. */
313
+ type PullRequestOptions = Omit<(typeof WorkflowPullRequestOpen)['Encoded'], 'place' | 'attempt'>;
314
+ /** The pull request's number and its thread's, or why not, never thrown. */
315
+ type PullRequestAnswer = (typeof WorkflowPullRequestAnswer)['Encoded'];
316
+ /**
317
+ * What a run asks of ref0, each inside a step. ref0 answers every action, refusing one it
318
+ * doesn't allow, and never throws for a refusal. A step's retry gets the answers its first try
319
+ * got, matched by the order of its calls, so a step asks in the same order each time: a retry
320
+ * that asks for something else where it asked before is refused `changed`.
321
+ */
322
+ interface Ref0Actions {
323
+ readonly comments: {
324
+ readonly create: (comment: Comment) => Promise<ActionAnswer>;
325
+ };
326
+ readonly threads: {
327
+ readonly start: (start: ThreadStart) => Promise<ActionAnswer>;
328
+ };
329
+ /**
330
+ * A fork of the repo the workflow lives in, from its `main`, for a workflow that declares
331
+ * `code: 'write'`. With a key, it's the workflow's fork for that key, which a later run gets
332
+ * again; without one, it's this run's own. While another running run holds the key's fork, it's
333
+ * refused `busy`.
334
+ */
335
+ readonly forks: {
336
+ readonly create: (options?: ForkOptions) => Promise<ForkAnswer>;
337
+ };
338
+ /** Pull requests in the workflow's repo: a need added to one, or one opened from a fork. */
339
+ readonly pr: {
340
+ /**
341
+ * Adds a need to an open pull request, for a workflow that declares `needs: 'add'`:
342
+ * `ref0.pr.needs.add(41, approval('dba'))`. A need already there gets this run as another
343
+ * source. Nothing a workflow does removes one.
344
+ */
345
+ readonly needs: {
346
+ readonly add: (pullRequest: number, need: Need, options?: NeedAddOptions) => Promise<ActionAnswer>;
347
+ };
348
+ /**
349
+ * A pull request from a fork the run got to `main`, for a workflow that declares
350
+ * `code: 'write'`: opened in a new thread the run starts, titled like it, which counts
351
+ * against the run's `threads`. A fork whose pull request is still open answers that one,
352
+ * which its push has already moved.
353
+ */
354
+ readonly open: (options: PullRequestOptions) => Promise<PullRequestAnswer>;
355
+ };
356
+ }
357
+ /** What a call through a connection answers: its result, or why not, never thrown. */
358
+ type CallAnswer = (typeof ConnectionCallAnswer)['Encoded'];
359
+ /** The connections a workflow declares, by name, with the operations it calls on each. */
360
+ type Declared = Readonly<Record<string, ReadonlyArray<string>>>;
361
+ /** Each operation a connection can have, by its method's name. */
362
+ interface Operations {
363
+ /** A Sentry issue, by its ID: its status, level, times and counts, and never its text. */
364
+ readonly getIssue: (input: (typeof GetIssueInput)['Encoded']) => Promise<CallAnswer>;
365
+ }
366
+ /**
367
+ * The connections a run calls, as its workflow declared them: each by its name, with only the
368
+ * operations declared for it. Each is called inside a step, and answers a refusal rather than
369
+ * throwing one.
370
+ */
371
+ type ConnectionsOf<C extends Declared> = { readonly [K in keyof C]: Pick<Operations, Extract<C[K][number], keyof Operations>>; };
372
+ /**
373
+ * What an event workflow's run reads and uses: its event, the live sessions an action may name by
374
+ * index, and its means.
375
+ */
376
+ interface WorkflowContext<T extends WorkflowTrigger, C extends Declared = {}> {
377
+ readonly event: EventOf<T>;
378
+ readonly sessions: (typeof EventRunInput)['Encoded']['sessions'];
379
+ readonly step: WorkflowStep;
380
+ readonly ref0: Ref0Actions;
381
+ readonly connections: ConnectionsOf<C>;
382
+ }
383
+ /**
384
+ * What a called workflow's run reads and uses: its input, as its `input` schema parsed it, and
385
+ * its means. It reads nothing of the event its caller answered, and acts for its caller's
386
+ * accountable person.
387
+ */
388
+ interface CalledContext<Input, C extends Declared = {}> {
389
+ readonly input: Input;
390
+ readonly step: WorkflowStep;
391
+ readonly ref0: Ref0Actions;
392
+ readonly connections: ConnectionsOf<C>;
393
+ }
394
+ /**
395
+ * What a workflow may do, call, reach and spend, with the connections it calls as written, so its
396
+ * run's `connections` has each one it declared.
397
+ */
398
+ type PermissionsOf<C extends Declared> = Omit<(typeof WorkflowPermissions)['Encoded'], 'connections'> & {
399
+ readonly connections?: C & (typeof WorkflowConnections)['Encoded'];
400
+ };
401
+ /** An event workflow, as its file's default export: `export default workflow({ on, … })`. */
402
+ interface EventWorkflowSpec<T extends WorkflowTrigger, C extends Declared = {}> {
403
+ readonly on: ReadonlyArray<T>;
404
+ readonly where?: (typeof WorkflowFilters)['Encoded'];
405
+ readonly permissions: PermissionsOf<C>;
406
+ readonly description?: string;
407
+ /** An event workflow takes no input: a workflow with `input` is a called one, with no `on`. */
408
+ readonly input?: never;
409
+ readonly title?: never;
410
+ readonly run: (context: WorkflowContext<T, C>) => Promise<void>;
411
+ }
412
+ /** A called workflow, as its file's default export: `export default workflow({ input, title, … })`. */
413
+ interface CalledWorkflowSpec<Input extends z.ZodObject, Output, C extends Declared = {}> {
414
+ /** Its input, one `z.object`, which parses each call's input before its run starts. */
415
+ readonly input: Input;
416
+ /** Its run's title, from its input, as `text`: what a list of runs and a wait on it show. */
417
+ readonly title: (context: {
418
+ readonly input: z.output<Input>;
419
+ }) => Text;
420
+ readonly permissions: PermissionsOf<C>;
421
+ readonly description?: string;
422
+ /** A called workflow answers no event: only a call runs it. */
423
+ readonly on?: never;
424
+ readonly where?: never;
425
+ /** Its run, which returns its output, its caller's answer, as JSON. */
426
+ readonly run: (context: CalledContext<z.output<Input>, C>) => Promise<Output>;
427
+ }
428
+ /** What a workflow's file exports keeps for ref0, in its own isolate. */
429
+ type Own = Ref0Owned<WorkflowOwn<WorkflowStep, ActionSink>>;
430
+ /**
431
+ * An event workflow, as its file exports it: nothing calls it, so it has no call and no `run`, and
432
+ * ref0's bundler refuses an import of its file.
433
+ */
434
+ type EventWorkflow = Own;
435
+ /** Words a run sends, as `text` makes them. */
436
+ type Text = (typeof WorkflowText)['Encoded'];
437
+ /**
438
+ * A workflow, one of two kinds. An event workflow: which events it answers, `on`, and how it
439
+ * narrows them, `where`. A called workflow: its `input`, its run's `title` from that, and a run
440
+ * that returns its output; its file's default export is its handle, which other workflows'
441
+ * runs call with `.run(step, input)` and a start rule calls bare. Both have their permissions,
442
+ * which say what they may do and call, the hosts their sandboxes may reach and their run's
443
+ * budgets, and a description. ref0 reads the literals, so they're written out in place, never
444
+ * computed; `input`, `title` and `run` are code. A workflow with both `on` and `input`, or
445
+ * neither, isn't one. A run that wants to stop returns.
446
+ */
447
+ declare function workflow<const T extends WorkflowTrigger, const C extends Declared = {}>(spec: EventWorkflowSpec<T, C>): EventWorkflow;
448
+ declare function workflow<const Input extends z.ZodObject, Output = void, const C extends Declared = {}>(spec: CalledWorkflowSpec<Input, Output, C>): CalledWorkflow<z.input<Input>, Output>;
449
+ /**
450
+ * Words to send, as a tagged template: `` text`Started a docs thread for ${event.pullRequest}` ``.
451
+ * The template's own words are kept as written, and ref0 passes only templates written in the
452
+ * workflow's code; each value is quoted when it's shown, so nothing from an event reads as an
453
+ * instruction.
454
+ */
455
+ declare const text: (strings: TemplateStringsArray, ...values: ReadonlyArray<string | number | boolean>) => (typeof WorkflowText)['Encoded'];
456
+ //#endregion
457
+ //#region src/check.d.ts
458
+ /**
459
+ * `check()` and `oneOf()`, as a repo's `.ref0/checks/` code imports them from `@ref0/sdk`, and
460
+ * what an import of a check is. ref0 reads a check's `description`, `timeout`, `on` and `reuse`
461
+ * from their literals, and whether it has a start rule, and loads its code only in an isolate of its own,
462
+ * where it calls what `check()` keeps under `~ref0`. Anywhere else, ref0's bundler swaps an
463
+ * import of its file for a handle by its name, `checkHandle('unit')`, through which a workflow
464
+ * run's code starts the check's runs and waits for them, each start one step. In the gate, calling a
465
+ * handle makes a need for it: `unit()` for every part, or `e2e({ spec })` for the parts those
466
+ * params give.
467
+ */
468
+ /** A durable step of a run, Workflows' own, which ref0 gives code as it runs it. */
469
+ type Step = WorkflowStep;
470
+ /**
471
+ * A check run a workflow run started, by ref0's reference to it, kept as a step's result: its
472
+ * check and its run. Only the workflow run that started it, and only its own check, waits on it.
473
+ */
474
+ interface CheckRunReference {
475
+ readonly check: string;
476
+ readonly run: (typeof WorkflowCheckRun)['Encoded']['run'];
477
+ }
478
+ /**
479
+ * A duration as ref0 reads one from a file, a count and its unit from seconds to days:
480
+ * `'45 minutes'`, `'1 hour'`. A workflow's step takes Workflows' own `Duration`.
481
+ */
482
+ type DurationText = `${number} ${'second' | 'seconds' | 'minute' | 'minutes' | 'hour' | 'hours' | 'day' | 'days'}`;
483
+ /**
484
+ * How a check run ended, as its `run` says, with what it found. `neutral` says nothing either
485
+ * way, as a check with nothing to judge does. `needs` are what its result adds to the change it
486
+ * judged, `approval()` and `review()` only, at most 16: `needs: [approval('dba')]`. They count
487
+ * whatever the conclusion, once a version's gate takes the run.
488
+ */
489
+ interface CheckResult<Output = unknown> {
490
+ readonly conclusion: 'success' | 'failure' | 'neutral';
491
+ readonly output?: Output;
492
+ readonly needs?: ReadonlyArray<Need>;
493
+ }
494
+ /** What a Standard Schema's `validate` answers: the output it took, or what's wrong with it. */
495
+ type OutputResult<Output> = {
496
+ readonly value: Output;
497
+ readonly issues?: undefined;
498
+ } | {
499
+ readonly issues: ReadonlyArray<{
500
+ readonly message: string;
501
+ }>;
502
+ };
503
+ /**
504
+ * Any Standard Schema, as zod, valibot and arktype make one: what a check's `output` takes. Its
505
+ * `validate` is what checks a run's output before the run is kept.
506
+ */
507
+ interface OutputSchema<Output = unknown> {
508
+ readonly '~standard': {
509
+ readonly version: 1;
510
+ readonly vendor: string;
511
+ readonly validate: (value: Output) => OutputResult<Output> | Promise<OutputResult<Output>>;
512
+ readonly types?: {
513
+ readonly input: unknown;
514
+ readonly output: Output;
515
+ } | undefined;
516
+ };
517
+ }
518
+ /**
519
+ * What a check's `run` is given: its params, its step, and reads of the tree it judges. The tree's
520
+ * ID isn't among them: a check learns about its tree only by reading it.
521
+ */
522
+ interface CheckContext<Params> {
523
+ readonly params: Params;
524
+ readonly step: Step;
525
+ /**
526
+ * The tree it judges, a file past 8 MiB throwing. ref0 keeps each read and its answer, so a run
527
+ * whose reads answer the same on another tree can answer for it there.
528
+ */
529
+ readonly repo: Tree;
530
+ }
531
+ /**
532
+ * What `check()` takes: ref0 reads `description`, `timeout`, `on` and `reuse` from their literals.
533
+ * `params`, `output`, `start` and `run` are code.
534
+ */
535
+ interface CheckSpec<Params extends z.ZodObject, Output> {
536
+ /** One line on what the check is, at most 80 characters, shown beside its name. */
537
+ readonly description?: string;
538
+ /** Its input, one `z.object`: a field made with `oneOf` is one run for each of its values. */
539
+ readonly params?: Params;
540
+ /** What `run` returns as its output, checked before a run is kept. */
541
+ readonly output?: OutputSchema<Output>;
542
+ /**
543
+ * Its start rule, which ref0 calls before a start that isn't ref0's own makes a new run, once
544
+ * for each new run: by hand, as `ref0 run`, or from a workflow. It returns `allow()`,
545
+ * `refuse(text)` or falsy values, and any refusal refuses the start, in its words. ref0's own
546
+ * starts, for the gate and the queue's tip as `on` says, never reach it, nor does a start a run
547
+ * already going or ended answers. Only people, as ``({ actor }) => [actor.kind !== 'person' &&
548
+ * refuse(text`People start this one`)]``. Anyone may start it unless it says.
549
+ */
550
+ readonly start?: StartRule<z.output<Params>>;
551
+ /** For the whole check run, 45 minutes unless it says, and 6 hours at most. */
552
+ readonly timeout?: DurationText;
553
+ /**
554
+ * When ref0 starts it itself, each once: `'change'`, on each change before it joins `main`;
555
+ * `'tip'`, on the merge queue's tip before `main` moves, so it guards `main`; `'deployed'`, on
556
+ * what deployed. `['change', 'tip']` unless it says, and `[]` for ref0 never to start it, so only
557
+ * other code and people do, as its start rule lets them.
558
+ */
559
+ readonly on?: CheckOn;
560
+ /**
561
+ * Whether a result answers a start again: `true` unless it says. Then a start of the same check,
562
+ * params and tree gets the run that judged them, however long ago it ended, and a pass may answer
563
+ * a start on another tree whose reads answer the same. Write `reuse: false` for a check whose
564
+ * result depends on the machine or the moment, such as a benchmark, or a sandbox command that
565
+ * reads the clock, which is the container's real time: a start then joins a run still going, and
566
+ * once that has ended starts a new one, within the 64 runs a day each check, params and tree make.
567
+ */
568
+ readonly reuse?: boolean;
569
+ readonly run: (context: CheckContext<z.output<Params>>) => CheckResult<Output> | Promise<CheckResult<Output>>;
570
+ }
571
+ /**
572
+ * What running a check from a workflow takes: its params, a `oneOf` field left out being one
573
+ * run for each of its values; and `where`, `main`'s tree or the head of the event's thread, its
574
+ * open pull request's. Without it, the event's thread when it's on one, and `main` when not.
575
+ */
576
+ interface CheckRunOptions<Params> {
577
+ readonly params?: Partial<Params>;
578
+ readonly where?: WorkflowCheckWhere;
579
+ /**
580
+ * This start's own name among concurrent starts that ask the same: up to 64 letters, digits,
581
+ * `.`, `_`, `:` or `-`, from a letter or digit. Workflows tells a run's steps of one name apart
582
+ * only by the order they're reached in, so equal asks started at once, each behind steps of
583
+ * its own, may get each other's runs on a replay, which differ when the head moved between
584
+ * them. Give each a key, such as its shard, for it to keep its own.
585
+ */
586
+ readonly key?: string;
587
+ }
588
+ /**
589
+ * How one check run a workflow started ended, with the params it ran with: its conclusion and
590
+ * output, if it judged, or its error, if it couldn't, never a success in its place.
591
+ */
592
+ type CheckRunResult<Output = unknown> = {
593
+ readonly run: CheckRunReference;
594
+ readonly params: CheckRunParams;
595
+ readonly conclusion: 'success' | 'failure' | 'neutral';
596
+ readonly output?: Output;
597
+ readonly error?: undefined;
598
+ } | {
599
+ readonly run: CheckRunReference;
600
+ readonly params: CheckRunParams;
601
+ readonly error: CheckRunError;
602
+ readonly why?: string;
603
+ readonly conclusion?: undefined;
604
+ };
605
+ /**
606
+ * ref0 refused a workflow's start of a check, or its read of one's runs, as `ref0 run` refuses
607
+ * one: `why`, what to do next, and for `busy`, when it may go. A refusal is kept as its step's
608
+ * result, so a replay throws it again and starts nothing. The SDK refuses a start's key or
609
+ * params itself, before any step, and a gate's need's params when the need is made.
610
+ */
611
+ declare class CheckRunRefused extends Error {
612
+ readonly why: WorkflowCheckRefusal;
613
+ readonly nextStep: string;
614
+ /** When a `busy` start may go, in milliseconds since the epoch. */
615
+ readonly retryAt: number | undefined;
616
+ constructor(check: string, refused: (typeof WorkflowCheckRefused)['Encoded']);
617
+ }
618
+ /**
619
+ * A check, as code that imports its file sees it: `import unit from '../checks/unit'`. What its
620
+ * file exports also keeps what ref0 calls on it in its own isolate, as `CheckOwn` in
621
+ * `@ref0/contracts` says; an import of the file is a handle without it.
622
+ */
623
+ interface Check<Params = unknown, Output = unknown> extends Partial<Ref0Owned<CheckOwn<Step>>> {
624
+ /**
625
+ * A need for it, as the gate returns one: every part, or with `params`, only the parts its
626
+ * expansion of them gives, as `e2e({ spec: 'apps/web/e2e/refund.spec.ts' })` asks. Wrap it in
627
+ * `local` for a local run to meet it too.
628
+ */
629
+ (params?: Partial<Params>): CheckNeed;
630
+ /**
631
+ * Starts its runs, one for each cell of its `oneOf` grid, and waits for each to end. A run of
632
+ * the same check, params and tree that's going is joined, and one that ended answers, unless the
633
+ * check says `reuse: false`, as `ref0 run` answers.
634
+ */
635
+ readonly run: (step: Step, options?: CheckRunOptions<Params>) => Promise<ReadonlyArray<CheckRunResult<Output>>>;
636
+ /** Starts its runs without waiting: a reference to each, for `wait` in a later step. */
637
+ readonly start: (step: Step, options?: CheckRunOptions<Params>) => Promise<{
638
+ readonly pending: ReadonlyArray<CheckRunReference>;
639
+ }>;
640
+ /** Waits for runs `start` started, and answers how each ended, in their order. */
641
+ readonly wait: (step: Step, pending: ReadonlyArray<CheckRunReference>) => Promise<ReadonlyArray<CheckRunResult<Output>>>;
642
+ }
643
+ /** Where a `oneOf` field's values come from: listed, or read from the tree and the params before it. */
644
+ type OneOfValues = ReadonlyArray<string> | ((tree: string, params: Readonly<Record<string, string | undefined>>) => ReadonlyArray<string> | Promise<ReadonlyArray<string>>);
645
+ /**
646
+ * A check: what it is, its params, when it runs, and the work of one run. Export it as its
647
+ * file's default, `.ref0/checks/<name>.ts`, named by its file.
648
+ */
649
+ declare const check: <const Params extends z.ZodObject = z.ZodObject<{}>, Output = unknown>(spec: CheckSpec<Params, Output>) => Check<z.output<Params>, Output>;
650
+ /**
651
+ * A param that's one check run for each of its values, and a grid with several. It's a zod 4
652
+ * string schema, so `.ref0/package.json` needs zod 4, the one its `z.object` comes from.
653
+ */
654
+ declare const oneOf: (values: OneOfValues) => z.ZodString;
655
+ //#endregion
656
+ //#region src/browse.d.ts
657
+ /**
658
+ * `sb.browse`: ref0's browser module, loaded beside a check that imports `@ref0/sdk/browser`, and
659
+ * a lease from the attempt's opener, held as its RPC stub and never settled, which settling would
660
+ * release. Its cleanup flushes the hooks' reports, disconnects, closes the lease and disposes it,
661
+ * each failure ignored and the first two bounded, so `fn`'s value or throw is what the browse
662
+ * answers, and a stalled step never keeps the lease from its close.
663
+ */
664
+ /**
665
+ * The browser `sb.browse` lends a check, as the SDK's root names it: no more than its version.
666
+ * `@ref0/sdk/browser`, which a check that browses imports, merges Playwright's members into it,
667
+ * so the root's published types never name Playwright, whose own reach Workers' types.
668
+ */
669
+ interface Browser {
670
+ readonly version: () => string;
671
+ }
672
+ //#endregion
673
+ export { StartActor as $, ForkOptions as A, WorkflowContext as B, Comment as C, EventWorkflow as D, EventOf as E, StepConfig as F, CalledWorkflow as G, text as H, StepContext as I, TreeEntry as J, JsonValue as K, ThreadStart as L, PullRequestAnswer as M, PullRequestOptions as N, EventWorkflowSpec as O, Ref0Actions as P, Refusal as Q, WaitType as R, CheckRunEnded as S, Duration as T, workflow as U, WorkflowStep as V, CalledRunFailed as W, Allow as X, TreeRead as Y, CalledRun as Z, ActionAnswer as _, CheckRunOptions as a, allow as at, CalledContext as b, CheckRunResult as c, Need as ct, OneOfValues as d, StartContext as et, OutputResult as f, oneOf as g, check as h, CheckResult as i, StartRun as it, NeedAddOptions as j, ForkAnswer as k, CheckSpec as l, Step as m, Check as n, StartOutput as nt, CheckRunReference as o, refuse as ot, OutputSchema as p, Tree as q, CheckContext as r, StartRule as rt, CheckRunRefused as s, CheckNeed as st, Browser as t, StartItem as tt, DurationText as u, CallAnswer as v, ConnectionsOf as w, CalledWorkflowSpec as x, CallEnded as y, WaitedEvent as z };
674
+ //# sourceMappingURL=browse-DBqoeS-u.d.mts.map