@repogo/plugins 0.1.35 → 0.1.38
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.
- package/README.md +243 -3
- package/dist/cache.d.ts +27 -0
- package/dist/context.d.ts +67 -2
- package/dist/define.d.ts +31 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +123 -7
- package/dist/runtime.d.ts +16 -1
- package/dist/self.d.ts +1 -0
- package/dist/testing.d.ts +4 -0
- package/dist/testing.js +1562 -49
- package/dist/tracking.d.ts +5 -0
- package/dist/uploads.d.ts +24 -0
- package/dist/workflow/attempts.d.ts +25 -0
- package/dist/workflow/availability.d.ts +8 -0
- package/dist/workflow/catalog.d.ts +21 -0
- package/dist/workflow/clock.d.ts +6 -0
- package/dist/workflow/contracts.d.ts +121 -0
- package/dist/workflow/definition.d.ts +35 -0
- package/dist/workflow/errors.d.ts +19 -0
- package/dist/workflow/events.d.ts +132 -0
- package/dist/workflow/interrupted.d.ts +3 -0
- package/dist/workflow/journal.d.ts +28 -0
- package/dist/workflow/lease.d.ts +2 -0
- package/dist/workflow/lifetime.d.ts +27 -0
- package/dist/workflow/policy.d.ts +36 -0
- package/dist/workflow/register.d.ts +11 -0
- package/dist/workflow/retry.d.ts +14 -0
- package/dist/workflow/runner.d.ts +29 -0
- package/dist/workflow/scope.d.ts +4 -0
- package/dist/workflow/service.d.ts +48 -0
- package/dist/workflow/sleep.d.ts +6 -0
- package/dist/workflow/state.d.ts +41 -0
- package/dist/workflow/storage.d.ts +22 -0
- package/dist/workflow/summary.d.ts +80 -0
- package/dist/workflow/testing.d.ts +12 -0
- package/dist/workflow-executor.js +22917 -0
- package/package.json +3 -3
- package/dist/index-83w1fk10.js +0 -28
package/dist/tracking.d.ts
CHANGED
|
@@ -29,6 +29,11 @@ export type Tracked<T> = {
|
|
|
29
29
|
* that committed before the error are still announced.
|
|
30
30
|
*/
|
|
31
31
|
export declare function tracked<T>(readOnly: boolean, announce: (tags: string[]) => void, work: () => Promise<T>): Promise<Tracked<T>>;
|
|
32
|
+
/**
|
|
33
|
+
* Runs `work` read-only in a scope of its own, apart from the call that started
|
|
34
|
+
* it: what it reads isn't that call's, so a detached fetch can outlive it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isolated<T>(work: () => Promise<T>): Promise<T>;
|
|
32
37
|
export declare function recordRead(tag: string): void;
|
|
33
38
|
/** Called before a write runs: a query, and anything it calls, may not write. */
|
|
34
39
|
export declare function assertWritable(tag: string): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** A file the phone uploaded for this call, staged on the environment until a day after its last use. */
|
|
4
|
+
export type UploadedFile = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
size: number;
|
|
9
|
+
path: string;
|
|
10
|
+
};
|
|
11
|
+
/** The files the host attached to the running call; a method it calls sees them too. */
|
|
12
|
+
export declare const callFiles: AsyncLocalStorage<UploadedFile[]>;
|
|
13
|
+
/**
|
|
14
|
+
* One file from an `<Upload>`: `files: z.array(upload())`. It accepts only a
|
|
15
|
+
* file the host attached to this call, so input written by hand can't point a
|
|
16
|
+
* method at another path. Copy what you keep: `put({ body: Bun.file(file.path) })`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function upload(): z.ZodObject<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
type: z.ZodString;
|
|
22
|
+
size: z.ZodNumber;
|
|
23
|
+
path: z.ZodString;
|
|
24
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WorkflowClock } from "./clock";
|
|
2
|
+
import type { JournalFailure, JSONValue } from "./events";
|
|
3
|
+
import type { StepPolicy } from "./policy";
|
|
4
|
+
export type StepContext = {
|
|
5
|
+
stepId: string;
|
|
6
|
+
attempt: number;
|
|
7
|
+
attempts: number;
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
};
|
|
10
|
+
export type AttemptOutcome<T> = {
|
|
11
|
+
type: "completed";
|
|
12
|
+
result: T;
|
|
13
|
+
} | {
|
|
14
|
+
type: "failed";
|
|
15
|
+
error: JournalFailure;
|
|
16
|
+
retryable: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
type: "unknown";
|
|
19
|
+
error: JournalFailure;
|
|
20
|
+
} | {
|
|
21
|
+
type: "stopped";
|
|
22
|
+
invoked: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** A timed-out invocation retains ownership until its callback settles. */
|
|
25
|
+
export declare function invokeAttempt<T extends JSONValue>(callback: (ctx: StepContext) => T | Promise<T>, stepId: string, attempt: number, policy: StepPolicy, limit: number, clock: WorkflowClock, signal: AbortSignal): Promise<AttemptOutcome<T>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Availability = {
|
|
2
|
+
seen: number;
|
|
3
|
+
offlineSince: number | null;
|
|
4
|
+
};
|
|
5
|
+
export type NetworkSource = () => boolean | null;
|
|
6
|
+
/** An assigned nonlocal interface detects known disconnection without external probes. */
|
|
7
|
+
export declare const networkAvailable: NetworkSource;
|
|
8
|
+
export declare function nextAvailability(saved: Availability | null, now: number, online: boolean | null): Availability;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Availability } from "./availability";
|
|
2
|
+
import type { RunMetadata, RunSummary } from "./contracts";
|
|
3
|
+
export type CatalogRun = {
|
|
4
|
+
run: RunMetadata;
|
|
5
|
+
summary: RunSummary;
|
|
6
|
+
seen: number;
|
|
7
|
+
terminal: number | null;
|
|
8
|
+
error: string | null;
|
|
9
|
+
};
|
|
10
|
+
export declare class WorkflowCatalog {
|
|
11
|
+
private sql;
|
|
12
|
+
private release;
|
|
13
|
+
private constructor();
|
|
14
|
+
static open(directory: string): Promise<WorkflowCatalog>;
|
|
15
|
+
all(): Promise<CatalogRun[]>;
|
|
16
|
+
put(value: CatalogRun): Promise<void>;
|
|
17
|
+
availability(): Promise<Availability | null>;
|
|
18
|
+
heartbeat(value: Availability): Promise<void>;
|
|
19
|
+
remove(id: string): Promise<void>;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { describe } from "./summary";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { HostCaller, SentNotice } from "../runtime";
|
|
4
|
+
import type { LogRecord } from "../logs";
|
|
5
|
+
export declare const RunSummarySchema: z.ZodObject<{
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
workflow: z.ZodString;
|
|
8
|
+
status: z.ZodEnum<{
|
|
9
|
+
running: "running";
|
|
10
|
+
failed: "failed";
|
|
11
|
+
waiting: "waiting";
|
|
12
|
+
completed: "completed";
|
|
13
|
+
unknown: "unknown";
|
|
14
|
+
pending: "pending";
|
|
15
|
+
attention: "attention";
|
|
16
|
+
cancelled: "cancelled";
|
|
17
|
+
expired: "expired";
|
|
18
|
+
blocked: "blocked";
|
|
19
|
+
}>;
|
|
20
|
+
currentStep: z.ZodNullable<z.ZodString>;
|
|
21
|
+
attempt: z.ZodNumber;
|
|
22
|
+
createdAt: z.ZodString;
|
|
23
|
+
updatedAt: z.ZodString;
|
|
24
|
+
nextAttemptAt: z.ZodNullable<z.ZodString>;
|
|
25
|
+
deadlineAt: z.ZodNullable<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export type RunSummary = z.infer<typeof RunSummarySchema>;
|
|
28
|
+
export type WorkflowTarget = {
|
|
29
|
+
dir: string;
|
|
30
|
+
plugin: string;
|
|
31
|
+
namespace: string;
|
|
32
|
+
workflow: string;
|
|
33
|
+
root: string;
|
|
34
|
+
};
|
|
35
|
+
export type WorkflowRequest = WorkflowTarget & {
|
|
36
|
+
operation: "start" | "list" | "get" | "cancel" | "cancelAll" | "retry" | "restart";
|
|
37
|
+
input: Record<string, unknown>;
|
|
38
|
+
caller?: "card" | "agent" | "cron" | "code" | "http";
|
|
39
|
+
settings?: {
|
|
40
|
+
timeoutMs: number;
|
|
41
|
+
maxOfflineMs: number;
|
|
42
|
+
retentionMs: number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type WorkflowBridge = (request: WorkflowRequest) => Promise<unknown>;
|
|
46
|
+
export declare const RunMetadataSchema: z.ZodObject<{
|
|
47
|
+
id: z.ZodString;
|
|
48
|
+
dir: z.ZodString;
|
|
49
|
+
root: z.ZodString;
|
|
50
|
+
namespace: z.ZodString;
|
|
51
|
+
plugin: z.ZodString;
|
|
52
|
+
caller: z.ZodEnum<{
|
|
53
|
+
card: "card";
|
|
54
|
+
agent: "agent";
|
|
55
|
+
cron: "cron";
|
|
56
|
+
code: "code";
|
|
57
|
+
http: "http";
|
|
58
|
+
}>;
|
|
59
|
+
workflow: z.ZodString;
|
|
60
|
+
input: z.ZodJSONSchema;
|
|
61
|
+
key: z.ZodNullable<z.ZodString>;
|
|
62
|
+
timeoutMs: z.ZodNumber;
|
|
63
|
+
maxOfflineMs: z.ZodNumber;
|
|
64
|
+
retentionMs: z.ZodNumber;
|
|
65
|
+
createdAt: z.ZodISODateTime;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
export declare const RunLocationSchema: z.ZodObject<{
|
|
68
|
+
id: z.ZodString;
|
|
69
|
+
key: z.ZodNullable<z.ZodString>;
|
|
70
|
+
maxOfflineMs: z.ZodNumber;
|
|
71
|
+
retentionMs: z.ZodNumber;
|
|
72
|
+
dir: z.ZodString;
|
|
73
|
+
root: z.ZodString;
|
|
74
|
+
namespace: z.ZodString;
|
|
75
|
+
plugin: z.ZodString;
|
|
76
|
+
caller: z.ZodEnum<{
|
|
77
|
+
card: "card";
|
|
78
|
+
agent: "agent";
|
|
79
|
+
cron: "cron";
|
|
80
|
+
code: "code";
|
|
81
|
+
http: "http";
|
|
82
|
+
}>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
export type RunMetadata = z.infer<typeof RunMetadataSchema>;
|
|
85
|
+
export type ExecutorStart = {
|
|
86
|
+
type: "start";
|
|
87
|
+
run: RunMetadata;
|
|
88
|
+
directory: string;
|
|
89
|
+
dataDir: string;
|
|
90
|
+
};
|
|
91
|
+
export type ExecutorMessage = {
|
|
92
|
+
type: "host";
|
|
93
|
+
id: number;
|
|
94
|
+
plugin: string;
|
|
95
|
+
method: string;
|
|
96
|
+
params: unknown;
|
|
97
|
+
} | {
|
|
98
|
+
type: "state";
|
|
99
|
+
summary: RunSummary;
|
|
100
|
+
detail: ReturnType<typeof describe>;
|
|
101
|
+
} | {
|
|
102
|
+
type: "invalidated";
|
|
103
|
+
tags: string[];
|
|
104
|
+
} | {
|
|
105
|
+
type: "notice";
|
|
106
|
+
notice: SentNotice;
|
|
107
|
+
} | {
|
|
108
|
+
type: "log";
|
|
109
|
+
records: LogRecord[];
|
|
110
|
+
} | {
|
|
111
|
+
type: "done";
|
|
112
|
+
} | {
|
|
113
|
+
type: "error";
|
|
114
|
+
message: string;
|
|
115
|
+
};
|
|
116
|
+
export type WorkflowCallbacks = {
|
|
117
|
+
host: HostCaller;
|
|
118
|
+
invalidate: (tags: string[]) => void;
|
|
119
|
+
notify: (notice: SentNotice) => void;
|
|
120
|
+
logs: (dir: string, records: LogRecord[]) => void;
|
|
121
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import type { Duration } from "../duration";
|
|
4
|
+
import type { StepContext as AttemptContext } from "./attempts";
|
|
5
|
+
import type { StepOptions } from "./policy";
|
|
6
|
+
import type { JSONValue } from "./events";
|
|
7
|
+
import type { RunContext } from "./runner";
|
|
8
|
+
export type StepContext = AttemptContext & {
|
|
9
|
+
runId: string;
|
|
10
|
+
idempotencyKey: string;
|
|
11
|
+
};
|
|
12
|
+
export type WorkflowSteps = {
|
|
13
|
+
run<T extends JSONValue>(name: string, callback: (ctx: StepContext) => T | Promise<T>, options?: StepOptions): Promise<T>;
|
|
14
|
+
};
|
|
15
|
+
export type WorkflowContext = Context & Omit<RunContext, "step"> & {
|
|
16
|
+
runId: string;
|
|
17
|
+
step: WorkflowSteps;
|
|
18
|
+
};
|
|
19
|
+
export declare function workflowContext(base: Context, run: RunContext & {
|
|
20
|
+
root: string;
|
|
21
|
+
runId: string;
|
|
22
|
+
}): WorkflowContext;
|
|
23
|
+
export type WorkflowOptions<O extends z.ZodType = z.ZodType> = {
|
|
24
|
+
description?: string;
|
|
25
|
+
output?: O;
|
|
26
|
+
confirm?: string;
|
|
27
|
+
timeout?: Duration;
|
|
28
|
+
maxOffline?: Duration;
|
|
29
|
+
retention?: Duration;
|
|
30
|
+
};
|
|
31
|
+
export type Workflow<I extends z.ZodType = z.ZodType, O extends z.ZodType = z.ZodType> = WorkflowOptions<O> & {
|
|
32
|
+
input: I;
|
|
33
|
+
run: (input: z.infer<I>, ctx: WorkflowContext) => unknown | Promise<unknown>;
|
|
34
|
+
};
|
|
35
|
+
export declare function workflow<I extends z.ZodType, O extends z.ZodType = z.ZodType>(input: I, run: (input: z.infer<I>, ctx: WorkflowContext) => unknown | Promise<unknown>, options?: WorkflowOptions<O>): Workflow<I, O>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JournalFailure } from "./events";
|
|
2
|
+
export declare class NonRetryable extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class RunnerError extends Error {
|
|
6
|
+
readonly code: "FAILED" | "BUSY" | "IDENTITY" | "REPLAY" | "CHANGED" | "ATTENTION" | "STEP" | "UNKNOWN" | "CANCELLED" | "EXPIRED" | "PAUSED" | "USAGE" | "WAITING";
|
|
7
|
+
readonly failure: JournalFailure | null;
|
|
8
|
+
constructor(code: "FAILED" | "BUSY" | "IDENTITY" | "REPLAY" | "CHANGED" | "ATTENTION" | "STEP" | "UNKNOWN" | "CANCELLED" | "EXPIRED" | "PAUSED" | "USAGE" | "WAITING", message: string, failure?: JournalFailure | null);
|
|
9
|
+
}
|
|
10
|
+
export declare class RunWaiting extends RunnerError {
|
|
11
|
+
readonly stepId: string;
|
|
12
|
+
readonly attempt: number;
|
|
13
|
+
readonly nextAttemptAt: string;
|
|
14
|
+
constructor(stepId: string, attempt: number, nextAttemptAt: string);
|
|
15
|
+
}
|
|
16
|
+
export declare function failure(error: unknown): JournalFailure;
|
|
17
|
+
export declare function asError(error: unknown): Error;
|
|
18
|
+
export declare function outcomeError(status: "failed" | "unknown", error: JournalFailure): RunnerError;
|
|
19
|
+
export declare function terminalError(status: "cancelled" | "expired"): RunnerError;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const sleepId: (position: number) => string;
|
|
3
|
+
declare const Failure: z.ZodObject<{
|
|
4
|
+
message: z.ZodString;
|
|
5
|
+
code: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export declare const EventInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
type: z.ZodLiteral<"run.started">;
|
|
9
|
+
workflow: z.ZodString;
|
|
10
|
+
input: z.ZodJSONSchema;
|
|
11
|
+
timeoutMs: z.ZodNumber;
|
|
12
|
+
location: z.ZodOptional<z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
key: z.ZodNullable<z.ZodString>;
|
|
15
|
+
maxOfflineMs: z.ZodNumber;
|
|
16
|
+
retentionMs: z.ZodNumber;
|
|
17
|
+
dir: z.ZodString;
|
|
18
|
+
root: z.ZodString;
|
|
19
|
+
namespace: z.ZodString;
|
|
20
|
+
plugin: z.ZodString;
|
|
21
|
+
caller: z.ZodEnum<{
|
|
22
|
+
card: "card";
|
|
23
|
+
agent: "agent";
|
|
24
|
+
cron: "cron";
|
|
25
|
+
code: "code";
|
|
26
|
+
http: "http";
|
|
27
|
+
}>;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
30
|
+
type: z.ZodLiteral<"sleep.scheduled">;
|
|
31
|
+
sleepId: z.ZodString;
|
|
32
|
+
durationMs: z.ZodNumber;
|
|
33
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"sleep.completed">;
|
|
35
|
+
sleepId: z.ZodString;
|
|
36
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
37
|
+
policy: z.ZodObject<{
|
|
38
|
+
kind: z.ZodEnum<{
|
|
39
|
+
query: "query";
|
|
40
|
+
mutation: "mutation";
|
|
41
|
+
}>;
|
|
42
|
+
attempts: z.ZodNumber;
|
|
43
|
+
timeoutMs: z.ZodNumber;
|
|
44
|
+
backoff: z.ZodObject<{
|
|
45
|
+
initialMs: z.ZodNumber;
|
|
46
|
+
factor: z.ZodNumber;
|
|
47
|
+
maxMs: z.ZodNumber;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
stepId: z.ZodString;
|
|
51
|
+
attempt: z.ZodNumber;
|
|
52
|
+
type: z.ZodLiteral<"step.started">;
|
|
53
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
54
|
+
result: z.ZodJSONSchema;
|
|
55
|
+
stepId: z.ZodString;
|
|
56
|
+
attempt: z.ZodNumber;
|
|
57
|
+
type: z.ZodLiteral<"step.completed">;
|
|
58
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
59
|
+
error: z.ZodObject<{
|
|
60
|
+
message: z.ZodString;
|
|
61
|
+
code: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
stepId: z.ZodString;
|
|
64
|
+
attempt: z.ZodNumber;
|
|
65
|
+
type: z.ZodLiteral<"step.failed">;
|
|
66
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
67
|
+
error: z.ZodObject<{
|
|
68
|
+
message: z.ZodString;
|
|
69
|
+
code: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strict>;
|
|
71
|
+
stepId: z.ZodString;
|
|
72
|
+
attempt: z.ZodNumber;
|
|
73
|
+
type: z.ZodLiteral<"step.unknown">;
|
|
74
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
75
|
+
error: z.ZodObject<{
|
|
76
|
+
message: z.ZodString;
|
|
77
|
+
code: z.ZodOptional<z.ZodString>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
delayMs: z.ZodNumber;
|
|
80
|
+
stepId: z.ZodString;
|
|
81
|
+
attempt: z.ZodNumber;
|
|
82
|
+
type: z.ZodLiteral<"step.retryScheduled">;
|
|
83
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
84
|
+
type: z.ZodLiteral<"run.retryRequested">;
|
|
85
|
+
stepId: z.ZodString;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
87
|
+
type: z.ZodLiteral<"run.completed">;
|
|
88
|
+
result: z.ZodJSONSchema;
|
|
89
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
90
|
+
type: z.ZodLiteral<"run.failed">;
|
|
91
|
+
error: z.ZodObject<{
|
|
92
|
+
message: z.ZodString;
|
|
93
|
+
code: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.core.$strict>;
|
|
95
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
96
|
+
type: z.ZodLiteral<"run.cancelRequested">;
|
|
97
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
98
|
+
type: z.ZodLiteral<"run.cancelled">;
|
|
99
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
100
|
+
type: z.ZodLiteral<"run.expired">;
|
|
101
|
+
reason: z.ZodString;
|
|
102
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
103
|
+
type: z.ZodLiteral<"run.unknown">;
|
|
104
|
+
error: z.ZodObject<{
|
|
105
|
+
message: z.ZodString;
|
|
106
|
+
code: z.ZodOptional<z.ZodString>;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
109
|
+
type: z.ZodLiteral<"run.attention">;
|
|
110
|
+
error: z.ZodObject<{
|
|
111
|
+
message: z.ZodString;
|
|
112
|
+
code: z.ZodOptional<z.ZodString>;
|
|
113
|
+
}, z.core.$strict>;
|
|
114
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
115
|
+
type: z.ZodLiteral<"run.restarted">;
|
|
116
|
+
}, z.core.$strict>], "type">;
|
|
117
|
+
declare const Envelope: z.ZodObject<{
|
|
118
|
+
version: z.ZodLiteral<1>;
|
|
119
|
+
seq: z.ZodNumber;
|
|
120
|
+
at: z.ZodISODateTime;
|
|
121
|
+
}, z.core.$strict>;
|
|
122
|
+
export type EventInput = z.infer<typeof EventInputSchema>;
|
|
123
|
+
export type JournalEvent = EventInput & z.infer<typeof Envelope>;
|
|
124
|
+
export type JournalFailure = z.infer<typeof Failure>;
|
|
125
|
+
export type JSONValue = z.infer<ReturnType<typeof z.json>>;
|
|
126
|
+
export declare class JournalError extends Error {
|
|
127
|
+
readonly code: "NOT_DUE" | "INVALID_EVENT" | "CORRUPT_JOURNAL" | "LOCKED" | "CLOSED" | "POISONED" | "LIMIT";
|
|
128
|
+
constructor(code: "NOT_DUE" | "INVALID_EVENT" | "CORRUPT_JOURNAL" | "LOCKED" | "CLOSED" | "POISONED" | "LIMIT", message: string);
|
|
129
|
+
}
|
|
130
|
+
export declare function eventInput(value: unknown): EventInput;
|
|
131
|
+
export declare function storedEvent(value: unknown): JournalEvent;
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type WorkflowClock } from "./clock";
|
|
2
|
+
import { type EventInput, type JournalEvent } from "./events";
|
|
3
|
+
import { type RunState } from "./state";
|
|
4
|
+
import { type JournalStorage } from "./storage";
|
|
5
|
+
/** Internal durable history for one run; the snapshot is only a readable projection. */
|
|
6
|
+
export declare class RunJournal {
|
|
7
|
+
private storage;
|
|
8
|
+
readonly clock: WorkflowClock;
|
|
9
|
+
private value;
|
|
10
|
+
private listeners;
|
|
11
|
+
private bytes;
|
|
12
|
+
private queue;
|
|
13
|
+
private closing;
|
|
14
|
+
private poisoned;
|
|
15
|
+
private snapshotFailure;
|
|
16
|
+
private constructor();
|
|
17
|
+
static open(directory: string, clock?: WorkflowClock): Promise<RunJournal>;
|
|
18
|
+
static openExisting(directory: string, clock?: WorkflowClock): Promise<RunJournal>;
|
|
19
|
+
/** The injected storage owns its lock; recovery closes it on failure. */
|
|
20
|
+
static recover(storage: JournalStorage, clock: WorkflowClock): Promise<RunJournal>;
|
|
21
|
+
onChange(listener: () => void): () => void;
|
|
22
|
+
get state(): RunState;
|
|
23
|
+
/** A failed snapshot does not invalidate an event already committed to the journal. */
|
|
24
|
+
get snapshotError(): unknown;
|
|
25
|
+
append(input: EventInput): Promise<JournalEvent>;
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
private checkpoint;
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WorkflowClock } from "./clock";
|
|
2
|
+
import type { RunJournal } from "./journal";
|
|
3
|
+
/** Cancellation is durable before notifying callbacks; expiry already has a recorded deadline. */
|
|
4
|
+
export declare class RunLifetime {
|
|
5
|
+
private journal;
|
|
6
|
+
private clock;
|
|
7
|
+
readonly deadlineAt: string | null;
|
|
8
|
+
private signal?;
|
|
9
|
+
private suspend?;
|
|
10
|
+
private maxOfflineMs?;
|
|
11
|
+
readonly controller: AbortController;
|
|
12
|
+
reason: "cancelled" | "expired" | "paused" | null;
|
|
13
|
+
private pending;
|
|
14
|
+
private closed;
|
|
15
|
+
private failure;
|
|
16
|
+
expiryReason: string;
|
|
17
|
+
private lastSeen;
|
|
18
|
+
private removeHeartbeat;
|
|
19
|
+
private removeTimer;
|
|
20
|
+
private pause;
|
|
21
|
+
private cancel;
|
|
22
|
+
constructor(journal: RunJournal, clock: WorkflowClock, deadlineAt: string | null, signal?: AbortSignal | undefined, suspend?: AbortSignal | undefined, maxOfflineMs?: number | undefined);
|
|
23
|
+
private heartbeat;
|
|
24
|
+
check(): void;
|
|
25
|
+
flush(): Promise<void>;
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Duration } from "../duration";
|
|
3
|
+
declare const StepOptionsSchema: z.ZodObject<{
|
|
4
|
+
kind: z.ZodOptional<z.ZodEnum<{
|
|
5
|
+
query: "query";
|
|
6
|
+
mutation: "mutation";
|
|
7
|
+
}>>;
|
|
8
|
+
attempts: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
timeout: z.ZodOptional<z.ZodCustom<Duration, Duration>>;
|
|
10
|
+
backoff: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
initial: z.ZodOptional<z.ZodCustom<Duration, Duration>>;
|
|
12
|
+
factor: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
max: z.ZodOptional<z.ZodCustom<Duration, Duration>>;
|
|
14
|
+
}, z.core.$strict>>;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export type StepOptions = z.infer<typeof StepOptionsSchema>;
|
|
17
|
+
export declare const maxDurationMs: number;
|
|
18
|
+
export declare const DurationMsSchema: z.ZodNumber;
|
|
19
|
+
export declare const StepPolicySchema: z.ZodObject<{
|
|
20
|
+
kind: z.ZodEnum<{
|
|
21
|
+
query: "query";
|
|
22
|
+
mutation: "mutation";
|
|
23
|
+
}>;
|
|
24
|
+
attempts: z.ZodNumber;
|
|
25
|
+
timeoutMs: z.ZodNumber;
|
|
26
|
+
backoff: z.ZodObject<{
|
|
27
|
+
initialMs: z.ZodNumber;
|
|
28
|
+
factor: z.ZodNumber;
|
|
29
|
+
maxMs: z.ZodNumber;
|
|
30
|
+
}, z.core.$strict>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type StepPolicy = z.infer<typeof StepPolicySchema>;
|
|
33
|
+
export declare function durationMs(value: Duration): number;
|
|
34
|
+
export declare function stepPolicy(options?: StepOptions): StepPolicy;
|
|
35
|
+
export declare function retryDelay(policy: StepPolicy, attempt: number, random: () => number): number;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import type { RegisteredMethod } from "../runtime";
|
|
3
|
+
import type { Workflow } from "./definition";
|
|
4
|
+
import type { WorkflowBridge } from "./contracts";
|
|
5
|
+
export declare function workflowTag(namespace: string): string;
|
|
6
|
+
export declare function workflowMethods(plugin: string, namespace: string, name: string, definition: Workflow, ctx: Context, bridge: WorkflowBridge | undefined, directory: () => string | null): RegisteredMethod[];
|
|
7
|
+
export declare function workflowSettings(definition: Workflow): {
|
|
8
|
+
timeoutMs: number;
|
|
9
|
+
maxOfflineMs: number;
|
|
10
|
+
retentionMs: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type StepContext } from "./attempts";
|
|
2
|
+
import { type WorkflowClock } from "./clock";
|
|
3
|
+
import { RunWaiting } from "./errors";
|
|
4
|
+
import { type JournalFailure, type JSONValue } from "./events";
|
|
5
|
+
import type { RunJournal } from "./journal";
|
|
6
|
+
import type { RunLifetime } from "./lifetime";
|
|
7
|
+
import { type StepPolicy } from "./policy";
|
|
8
|
+
import type { StepState } from "./state";
|
|
9
|
+
export type ExecutionEnvironment = {
|
|
10
|
+
clock: WorkflowClock;
|
|
11
|
+
random: () => number;
|
|
12
|
+
};
|
|
13
|
+
export declare function scheduleRetry(append: RunJournal["append"], name: string, attempt: number, policy: StepPolicy, error: JournalFailure, environment: ExecutionEnvironment): Promise<RunWaiting>;
|
|
14
|
+
export declare function executeStep<T extends JSONValue>(name: string, callback: (ctx: StepContext) => T | Promise<T>, policy: StepPolicy, saved: StepState | undefined, append: RunJournal["append"], environment: ExecutionEnvironment, lifetime: RunLifetime, stopped: () => unknown, markUncertain: () => void): Promise<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Duration } from "../duration";
|
|
2
|
+
import type { StepContext } from "./attempts";
|
|
3
|
+
import { type JSONValue } from "./events";
|
|
4
|
+
import { RunJournal } from "./journal";
|
|
5
|
+
import { type StepOptions } from "./policy";
|
|
6
|
+
export { RunnerError, RunWaiting, NonRetryable } from "./errors";
|
|
7
|
+
export type { StepContext } from "./attempts";
|
|
8
|
+
export type { StepOptions } from "./policy";
|
|
9
|
+
export type RunIdentity = {
|
|
10
|
+
workflow: string;
|
|
11
|
+
input: JSONValue;
|
|
12
|
+
};
|
|
13
|
+
export type WorkflowSteps = {
|
|
14
|
+
run<T extends JSONValue>(name: string, callback: (ctx: StepContext) => T | Promise<T>, options?: StepOptions): Promise<T>;
|
|
15
|
+
};
|
|
16
|
+
export type RunContext = {
|
|
17
|
+
step: WorkflowSteps;
|
|
18
|
+
sleep: (duration: Duration) => Promise<void>;
|
|
19
|
+
signal: AbortSignal;
|
|
20
|
+
};
|
|
21
|
+
export type RunOptions = {
|
|
22
|
+
timeout?: Duration;
|
|
23
|
+
maxOffline?: Duration;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
suspend?: AbortSignal;
|
|
26
|
+
random?: () => number;
|
|
27
|
+
};
|
|
28
|
+
/** Internal executor over the current code; callers own journal closure. */
|
|
29
|
+
export declare function runWorkflow<T extends JSONValue>(journal: RunJournal, identity: RunIdentity, handler: (input: JSONValue, ctx: RunContext) => T | Promise<T>, options?: RunOptions): Promise<T>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type NetworkSource } from "./availability";
|
|
2
|
+
import { type WorkflowClock } from "./clock";
|
|
3
|
+
import { type RunSummary, type WorkflowCallbacks, type WorkflowRequest } from "./contracts";
|
|
4
|
+
export declare class WorkflowService {
|
|
5
|
+
private dataDir;
|
|
6
|
+
private catalog;
|
|
7
|
+
private callbacks;
|
|
8
|
+
private clock;
|
|
9
|
+
private storageLimit;
|
|
10
|
+
private network;
|
|
11
|
+
private queue;
|
|
12
|
+
private details;
|
|
13
|
+
private rows;
|
|
14
|
+
private unrecovered;
|
|
15
|
+
private maintenanceErrors;
|
|
16
|
+
private cancelling;
|
|
17
|
+
private active;
|
|
18
|
+
private observers;
|
|
19
|
+
private timer;
|
|
20
|
+
private closing;
|
|
21
|
+
private started;
|
|
22
|
+
private constructor();
|
|
23
|
+
static open(dataDir: string, callbacks: WorkflowCallbacks, options?: {
|
|
24
|
+
clock?: WorkflowClock;
|
|
25
|
+
storageLimit?: number;
|
|
26
|
+
network?: NetworkSource;
|
|
27
|
+
}): Promise<WorkflowService>;
|
|
28
|
+
private directory;
|
|
29
|
+
private serial;
|
|
30
|
+
observe(listener: (summary: RunSummary) => void): () => void;
|
|
31
|
+
start(): void;
|
|
32
|
+
private wake;
|
|
33
|
+
private save;
|
|
34
|
+
request(request: WorkflowRequest): Promise<unknown>;
|
|
35
|
+
/** Cancels every unfinished run of the workflow in the project, or only those in one status. */
|
|
36
|
+
private cancelAll;
|
|
37
|
+
/** A run whose process already exited, as a sleeping one's has, is cancelled from its journal. */
|
|
38
|
+
private cancel;
|
|
39
|
+
private cancelIdle;
|
|
40
|
+
private cancelActive;
|
|
41
|
+
private create;
|
|
42
|
+
tick(): Promise<void>;
|
|
43
|
+
private launch;
|
|
44
|
+
private openJournal;
|
|
45
|
+
private recoverCatalog;
|
|
46
|
+
private bytes;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Duration } from "../duration";
|
|
2
|
+
import type { WorkflowClock } from "./clock";
|
|
3
|
+
import type { RunJournal } from "./journal";
|
|
4
|
+
import type { SleepState } from "./state";
|
|
5
|
+
/** The scheduled event anchors the wait; replay never calculates a fresh deadline. */
|
|
6
|
+
export declare function executeSleep(id: string, duration: Duration, saved: SleepState | undefined, append: RunJournal["append"], clock: WorkflowClock, check: () => void): Promise<void>;
|