@aikirun/types 0.5.3

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 ADDED
@@ -0,0 +1,48 @@
1
+ # @aikirun/types
2
+
3
+ Core type definitions for Aiki durable execution platform.
4
+
5
+ This package provides the foundational TypeScript types used throughout the Aiki ecosystem. It is typically not used
6
+ directly, but imported by other Aiki packages.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @aikirun/types
12
+ ```
13
+
14
+ ## Exports
15
+
16
+ - `/client` - Client configuration and API types
17
+ - `/workflow` - Workflow definition types
18
+ - `/workflow-run` - Workflow execution state types
19
+ - `/workflow-run-api` - API contract types
20
+ - `/task` - Task definition and state types
21
+ - `/trigger` - Trigger strategy types
22
+ - `/duration` - Duration types
23
+ - `/retry` - Retry strategy types
24
+ - `/error` - Serializable error types
25
+
26
+ ## Usage
27
+
28
+ These types are primarily used by other Aiki packages:
29
+
30
+ ```typescript
31
+ import type { WorkflowOptions } from "@aikirun/types/workflow-run";
32
+ import type { TriggerStrategy } from "@aikirun/types/trigger";
33
+ ```
34
+
35
+ ## Related Packages
36
+
37
+ - [@aikirun/client](https://www.npmjs.com/package/@aikirun/client) - Client SDK
38
+ - [@aikirun/workflow](https://www.npmjs.com/package/@aikirun/workflow) - Workflow SDK
39
+ - [@aikirun/task](https://www.npmjs.com/package/@aikirun/task) - Task SDK
40
+ - [@aikirun/worker](https://www.npmjs.com/package/@aikirun/worker) - Worker SDK
41
+
42
+ ## Changelog
43
+
44
+ See the [CHANGELOG](https://github.com/aikirun/aiki/blob/main/CHANGELOG.md) for version history.
45
+
46
+ ## License
47
+
48
+ Apache-2.0
@@ -0,0 +1,125 @@
1
+ import { WorkflowMeta } from './workflow.js';
2
+ import { WorkflowRun, WorkflowRunId } from './workflow-run.js';
3
+ import { WorkflowRunApi } from './workflow-run-api.js';
4
+ import { INTERNAL } from './symbols.js';
5
+ import './error.js';
6
+ import './retry.js';
7
+ import './sleep.js';
8
+ import './duration.js';
9
+ import './utils.js';
10
+ import './task.js';
11
+ import './trigger.js';
12
+
13
+ interface ClientParams<AppContext> {
14
+ url: string;
15
+ redis: RedisConfig;
16
+ logger?: Logger;
17
+ contextFactory?: (run: Readonly<WorkflowRun>) => AppContext | Promise<AppContext>;
18
+ }
19
+ interface Client<AppContext> {
20
+ api: ApiClient;
21
+ logger: Logger;
22
+ close: () => Promise<void>;
23
+ [INTERNAL]: {
24
+ subscriber: {
25
+ create: (strategy: SubscriberStrategy, workflows: WorkflowMeta[], workerShards?: string[]) => SubscriberStrategyBuilder;
26
+ };
27
+ redis: RedisConnection;
28
+ contextFactory?: (run: WorkflowRun) => AppContext | Promise<AppContext>;
29
+ };
30
+ }
31
+ interface Logger {
32
+ info(message: string, metadata?: Record<string, unknown>): void;
33
+ debug(message: string, metadata?: Record<string, unknown>): void;
34
+ warn(message: string, metadata?: Record<string, unknown>): void;
35
+ error(message: string, metadata?: Record<string, unknown>): void;
36
+ trace(message: string, metadata?: Record<string, unknown>): void;
37
+ child(bindings: Record<string, unknown>): Logger;
38
+ }
39
+ interface ApiClient {
40
+ workflowRun: WorkflowRunApi;
41
+ }
42
+ interface RedisClient {
43
+ xclaim(...args: unknown[]): Promise<unknown>;
44
+ xack(stream: string, group: string, messageId: string): Promise<number>;
45
+ xgroup(...args: unknown[]): Promise<unknown>;
46
+ xreadgroup(...args: unknown[]): Promise<unknown>;
47
+ xpending(...args: unknown[]): Promise<unknown>;
48
+ quit(): Promise<unknown>;
49
+ }
50
+ interface RedisConfig {
51
+ host: string;
52
+ port: number;
53
+ password?: string;
54
+ db?: number;
55
+ maxRetriesPerRequest?: number;
56
+ retryDelayOnFailoverMs?: number;
57
+ connectTimeoutMs?: number;
58
+ }
59
+ interface RedisConnection {
60
+ getConnection: () => RedisClient;
61
+ closeConnection: () => Promise<void>;
62
+ }
63
+ interface SubscriberMessageMeta {
64
+ stream: string;
65
+ messageId: string;
66
+ consumerGroup: string;
67
+ }
68
+ interface WorkflowRunBatch {
69
+ data: {
70
+ workflowRunId: WorkflowRunId;
71
+ };
72
+ meta?: SubscriberMessageMeta;
73
+ }
74
+ type SubscriberDelayParams = {
75
+ type: "polled";
76
+ foundWork: boolean;
77
+ } | {
78
+ type: "retry";
79
+ attemptNumber: number;
80
+ } | {
81
+ type: "heartbeat";
82
+ } | {
83
+ type: "at_capacity";
84
+ };
85
+ interface ResolvedSubscriberStrategy {
86
+ type: string;
87
+ getNextDelay: (context: SubscriberDelayParams) => number;
88
+ getNextBatch: (size: number) => Promise<WorkflowRunBatch[]>;
89
+ heartbeat?: (workflowRunId: WorkflowRunId, meta: SubscriberMessageMeta) => Promise<void>;
90
+ acknowledge?: (workflowRunId: WorkflowRunId, meta: SubscriberMessageMeta) => Promise<void>;
91
+ }
92
+ interface PollingSubscriberStrategy {
93
+ type: "polling";
94
+ intervalMs?: number;
95
+ maxRetryIntervalMs?: number;
96
+ atCapacityIntervalMs?: number;
97
+ }
98
+ interface AdaptivePollingSubscriberStrategy {
99
+ type: "adaptive_polling";
100
+ minPollIntervalMs?: number;
101
+ maxPollIntervalMs?: number;
102
+ backoffMultiplier?: number;
103
+ emptyPollThreshold?: number;
104
+ jitterFactor?: number;
105
+ successResetThreshold?: number;
106
+ atCapacityIntervalMs?: number;
107
+ }
108
+ interface RedisStreamsSubscriberStrategy {
109
+ type: "redis_streams";
110
+ intervalMs?: number;
111
+ maxRetryIntervalMs?: number;
112
+ atCapacityIntervalMs?: number;
113
+ blockTimeMs?: number;
114
+ claimMinIdleTimeMs?: number;
115
+ }
116
+ type SubscriberStrategy = RedisStreamsSubscriberStrategy;
117
+ interface SubscriberStrategyBuilder {
118
+ init: (workerId: string, callbacks: StrategyCallbacks) => Promise<ResolvedSubscriberStrategy>;
119
+ }
120
+ interface StrategyCallbacks {
121
+ onError?: (error: Error) => void;
122
+ onStop?: () => Promise<void>;
123
+ }
124
+
125
+ export type { AdaptivePollingSubscriberStrategy, ApiClient, Client, ClientParams, Logger, PollingSubscriberStrategy, RedisClient, RedisConfig, RedisConnection, RedisStreamsSubscriberStrategy, ResolvedSubscriberStrategy, StrategyCallbacks, SubscriberDelayParams, SubscriberMessageMeta, SubscriberStrategy, SubscriberStrategyBuilder, WorkflowRunBatch };
package/dist/client.js ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ import { RequireAtLeastOneOf } from './utils.js';
2
+
3
+ interface DurationFields {
4
+ days?: number;
5
+ hours?: number;
6
+ minutes?: number;
7
+ seconds?: number;
8
+ milliseconds?: number;
9
+ }
10
+ type DurationObject = RequireAtLeastOneOf<DurationFields, keyof DurationFields>;
11
+ type DurationMs = number;
12
+ type Duration = DurationMs | DurationObject;
13
+
14
+ export type { Duration, DurationFields, DurationObject };
File without changes
@@ -0,0 +1,11 @@
1
+ type SerializableInput = null | string | number | boolean | {
2
+ [key: string]: SerializableInput;
3
+ } | SerializableInput[];
4
+ interface SerializableError {
5
+ message: string;
6
+ name: string;
7
+ stack?: string;
8
+ cause?: SerializableError;
9
+ }
10
+
11
+ export type { SerializableError, SerializableInput };
package/dist/error.js ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ interface NeverRetryStrategy {
2
+ type: "never";
3
+ }
4
+ interface FixedRetryStrategy {
5
+ type: "fixed";
6
+ maxAttempts: number;
7
+ delayMs: number;
8
+ }
9
+ interface ExponentialRetryStrategy {
10
+ type: "exponential";
11
+ maxAttempts: number;
12
+ baseDelayMs: number;
13
+ factor?: number;
14
+ maxDelayMs?: number;
15
+ }
16
+ interface JitteredRetryStrategy {
17
+ type: "jittered";
18
+ maxAttempts: number;
19
+ baseDelayMs: number;
20
+ jitterFactor?: number;
21
+ maxDelayMs?: number;
22
+ }
23
+ type RetryStrategy = NeverRetryStrategy | FixedRetryStrategy | ExponentialRetryStrategy | JitteredRetryStrategy;
24
+
25
+ export type { ExponentialRetryStrategy, FixedRetryStrategy, JitteredRetryStrategy, NeverRetryStrategy, RetryStrategy };
package/dist/retry.js ADDED
File without changes
@@ -0,0 +1,37 @@
1
+ import { DurationObject } from './duration.js';
2
+ import './utils.js';
3
+
4
+ type SleepId = string & {
5
+ _brand: "sleep_id";
6
+ };
7
+ type SleepPath = string & {
8
+ _brand: "sleep_path";
9
+ };
10
+ type SleepStatus = "none" | "sleeping" | "completed" | "cancelled";
11
+ interface SleepStateBase {
12
+ status: SleepStatus;
13
+ }
14
+ interface SleepStateNone extends SleepStateBase {
15
+ status: "none";
16
+ }
17
+ interface SleepStateSleeping extends SleepStateBase {
18
+ status: "sleeping";
19
+ awakeAt: number;
20
+ }
21
+ interface SleepStateCompleted extends SleepStateBase {
22
+ status: "completed";
23
+ completedAt: number;
24
+ }
25
+ interface SleepStateCancelled extends SleepStateBase {
26
+ status: "cancelled";
27
+ cancelledAt: number;
28
+ }
29
+ type SleepState = SleepStateNone | SleepStateSleeping | SleepStateCompleted | SleepStateCancelled;
30
+ type SleepParams = {
31
+ id: string;
32
+ } & DurationObject;
33
+ interface SleepResult {
34
+ cancelled: boolean;
35
+ }
36
+
37
+ export type { SleepId, SleepParams, SleepPath, SleepResult, SleepState, SleepStateCancelled, SleepStateCompleted, SleepStateNone, SleepStateSleeping, SleepStatus };
package/dist/sleep.js ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ declare const INTERNAL: unique symbol;
2
+
3
+ export { INTERNAL };
@@ -0,0 +1,5 @@
1
+ // symbols.ts
2
+ var INTERNAL = /* @__PURE__ */ Symbol("aiki.internal");
3
+ export {
4
+ INTERNAL
5
+ };
package/dist/task.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { SerializableError } from './error.js';
2
+
3
+ type TaskId = string & {
4
+ _brand: "task_id";
5
+ };
6
+ type TaskPath = string & {
7
+ _brand: "task_path";
8
+ };
9
+ type TaskStatus = "none" | "running" | "completed" | "failed";
10
+ interface TaskStateBase {
11
+ status: TaskStatus;
12
+ }
13
+ interface TaskStateNone extends TaskStateBase {
14
+ status: "none";
15
+ }
16
+ interface TaskStateRunning extends TaskStateBase {
17
+ status: "running";
18
+ attempts: number;
19
+ }
20
+ interface TaskStateCompleted<Output> extends TaskStateBase {
21
+ status: "completed";
22
+ output: Output;
23
+ }
24
+ interface TaskStateFailed extends TaskStateBase {
25
+ status: "failed";
26
+ reason: string;
27
+ attempts: number;
28
+ attemptedAt: number;
29
+ nextAttemptAt?: number;
30
+ error?: SerializableError;
31
+ }
32
+ type TaskState<Output> = TaskStateNone | TaskStateRunning | TaskStateCompleted<Output> | TaskStateFailed;
33
+ declare class TaskFailedError extends Error {
34
+ readonly taskPath: TaskPath;
35
+ readonly attempts: number;
36
+ readonly reason: string;
37
+ constructor(taskPath: TaskPath, attempts: number, reason: string);
38
+ }
39
+
40
+ export { TaskFailedError, type TaskId, type TaskPath, type TaskState, type TaskStateCompleted, type TaskStateFailed, type TaskStateNone, type TaskStateRunning, type TaskStatus };
package/dist/task.js ADDED
@@ -0,0 +1,13 @@
1
+ // task.ts
2
+ var TaskFailedError = class extends Error {
3
+ constructor(taskPath, attempts, reason) {
4
+ super(`Task ${taskPath} failed after ${attempts} attempts. Reason: ${reason}`);
5
+ this.taskPath = taskPath;
6
+ this.attempts = attempts;
7
+ this.reason = reason;
8
+ this.name = "TaskFailedError";
9
+ }
10
+ };
11
+ export {
12
+ TaskFailedError
13
+ };
@@ -0,0 +1,17 @@
1
+ import { DurationObject } from './duration.js';
2
+ import './utils.js';
3
+
4
+ type TriggerStrategy = {
5
+ type: "immediate";
6
+ } | {
7
+ type: "delayed";
8
+ delayMs: number;
9
+ } | {
10
+ type: "delayed";
11
+ delay: DurationObject;
12
+ } | {
13
+ type: "startAt";
14
+ startAt: number;
15
+ };
16
+
17
+ export type { TriggerStrategy };
File without changes
@@ -0,0 +1,5 @@
1
+ type RequireAtLeastOneOf<T, Keys extends keyof T> = {
2
+ [K in Keys]-?: Required<Pick<T, K>> & Omit<T, K>;
3
+ }[Keys];
4
+
5
+ export type { RequireAtLeastOneOf };
package/dist/utils.js ADDED
File without changes
@@ -0,0 +1,111 @@
1
+ import { TaskState } from './task.js';
2
+ import { WorkflowRunStatus, WorkflowRun, WorkflowRunState, WorkflowOptions, WorkflowRunStateScheduled, WorkflowRunStateScheduledByNew, WorkflowRunStateScheduledByResume, WorkflowRunStatePaused, WorkflowRunStateCancelled, WorkflowRunTransition } from './workflow-run.js';
3
+ import './error.js';
4
+ import './retry.js';
5
+ import './sleep.js';
6
+ import './duration.js';
7
+ import './utils.js';
8
+ import './trigger.js';
9
+
10
+ interface WorkflowRunApi {
11
+ listV1: (input: WorkflowRunListRequestV1) => Promise<WorkflowRunListResponseV1>;
12
+ getByIdV1: (input: WorkflowRunGetByIdRequestV1) => Promise<WorkflowRunGetByIdResponseV1>;
13
+ getStateV1: (input: WorkflowRunGetStateRequestV1) => Promise<WorkflowRunGetStateResponseV1>;
14
+ createV1: (input: WorkflowRunCreateRequestV1) => Promise<WorkflowRunCreateResponseV1>;
15
+ transitionStateV1: (input: WorkflowRunTransitionStateRequestV1) => Promise<WorkflowRunTransitionStateResponseV1>;
16
+ transitionTaskStateV1: (input: WorkflowRunTransitionTaskStateRequestV1) => Promise<WorkflowRunTransitionTaskStateResponseV1>;
17
+ listTransitionsV1: (input: WorkflowRunListTransitionsRequestV1) => Promise<WorkflowRunListTransitionsResponseV1>;
18
+ }
19
+ interface WorkflowRunListRequestV1 {
20
+ limit?: number;
21
+ offset?: number;
22
+ filters?: {
23
+ workflows?: {
24
+ id?: string;
25
+ versionId?: string;
26
+ }[];
27
+ status?: WorkflowRunStatus[];
28
+ };
29
+ sort?: {
30
+ field: "createdAt";
31
+ order: "asc" | "desc";
32
+ };
33
+ }
34
+ interface WorkflowRunListItem {
35
+ id: string;
36
+ workflowId: string;
37
+ workflowVersionId: string;
38
+ createdAt: number;
39
+ status: WorkflowRunStatus;
40
+ }
41
+ interface WorkflowRunListResponseV1 {
42
+ runs: WorkflowRunListItem[];
43
+ total: number;
44
+ }
45
+ interface WorkflowRunGetByIdRequestV1 {
46
+ id: string;
47
+ }
48
+ interface WorkflowRunGetByIdResponseV1 {
49
+ run: WorkflowRun;
50
+ }
51
+ interface WorkflowRunGetStateRequestV1 {
52
+ id: string;
53
+ }
54
+ interface WorkflowRunGetStateResponseV1 {
55
+ state: WorkflowRunState<unknown>;
56
+ }
57
+ interface WorkflowRunCreateRequestV1 {
58
+ workflowId: string;
59
+ workflowVersionId: string;
60
+ input: unknown;
61
+ options?: WorkflowOptions;
62
+ }
63
+ interface WorkflowRunCreateResponseV1 {
64
+ run: WorkflowRun;
65
+ }
66
+ interface WorkflowRunTransitionStateRequestBase {
67
+ type: "optimistic" | "pessimistic";
68
+ id: string;
69
+ state: WorkflowRunState<unknown>;
70
+ }
71
+ interface WorkflowRunTransitionStateRequestOptimistic extends WorkflowRunTransitionStateRequestBase {
72
+ type: "optimistic";
73
+ state: Exclude<WorkflowRunState<unknown>, {
74
+ status: "scheduled" | "paused" | "cancelled";
75
+ }> | Exclude<WorkflowRunStateScheduled, {
76
+ reason: "new" | "resume";
77
+ }>;
78
+ expectedRevision: number;
79
+ }
80
+ interface WorkflowRunTransitionStateRequestPessimistic extends WorkflowRunTransitionStateRequestBase {
81
+ type: "pessimistic";
82
+ state: WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByResume | WorkflowRunStatePaused | WorkflowRunStateCancelled;
83
+ }
84
+ type WorkflowRunTransitionStateRequestV1 = WorkflowRunTransitionStateRequestOptimistic | WorkflowRunTransitionStateRequestPessimistic;
85
+ interface WorkflowRunTransitionStateResponseV1 {
86
+ run: WorkflowRun;
87
+ }
88
+ interface WorkflowRunTransitionTaskStateRequestV1 {
89
+ id: string;
90
+ taskPath: string;
91
+ taskState: TaskState<unknown>;
92
+ expectedRevision: number;
93
+ }
94
+ interface WorkflowRunTransitionTaskStateResponseV1 {
95
+ run: WorkflowRun;
96
+ }
97
+ interface WorkflowRunListTransitionsRequestV1 {
98
+ id: string;
99
+ limit?: number;
100
+ offset?: number;
101
+ sort?: {
102
+ field: "createdAt";
103
+ order: "asc" | "desc";
104
+ };
105
+ }
106
+ interface WorkflowRunListTransitionsResponseV1 {
107
+ transitions: WorkflowRunTransition[];
108
+ total: number;
109
+ }
110
+
111
+ export type { WorkflowRunApi, WorkflowRunCreateRequestV1, WorkflowRunCreateResponseV1, WorkflowRunGetByIdRequestV1, WorkflowRunGetByIdResponseV1, WorkflowRunGetStateRequestV1, WorkflowRunGetStateResponseV1, WorkflowRunListItem, WorkflowRunListRequestV1, WorkflowRunListResponseV1, WorkflowRunListTransitionsRequestV1, WorkflowRunListTransitionsResponseV1, WorkflowRunTransitionStateRequestV1, WorkflowRunTransitionStateResponseV1, WorkflowRunTransitionTaskStateRequestV1, WorkflowRunTransitionTaskStateResponseV1 };
File without changes
@@ -0,0 +1,173 @@
1
+ import { SerializableError } from './error.js';
2
+ import { RetryStrategy } from './retry.js';
3
+ import { SleepState } from './sleep.js';
4
+ import { TaskState } from './task.js';
5
+ import { TriggerStrategy } from './trigger.js';
6
+ import './duration.js';
7
+ import './utils.js';
8
+
9
+ type WorkflowRunId = string & {
10
+ _brand: "workflow_run_id";
11
+ };
12
+ type WorkflowRunStatus = "scheduled" | "queued" | "running" | "paused" | "sleeping" | "awaiting_event" | "awaiting_retry" | "awaiting_child_workflow" | "cancelled" | "completed" | "failed";
13
+ type TerminalWorkflowRunStatus = "cancelled" | "completed" | "failed";
14
+ type NonTerminalWorkflowRunStatus = Exclude<WorkflowRunStatus, TerminalWorkflowRunStatus>;
15
+ interface WorkflowOptions {
16
+ retry?: RetryStrategy;
17
+ idempotencyKey?: string;
18
+ trigger?: TriggerStrategy;
19
+ shardKey?: string;
20
+ }
21
+ interface WorkflowRunStateBase {
22
+ status: WorkflowRunStatus;
23
+ }
24
+ type WorkflowRunScheduledReason = "new" | "retry" | "awake" | "resume" | "event";
25
+ interface WorkflowRunStateScheduledBase extends WorkflowRunStateBase {
26
+ status: "scheduled";
27
+ scheduledAt: number;
28
+ reason: WorkflowRunScheduledReason;
29
+ }
30
+ interface WorkflowRunStateScheduledByNew extends WorkflowRunStateScheduledBase {
31
+ reason: "new";
32
+ }
33
+ interface WorkflowRunStateScheduledByRetry extends WorkflowRunStateScheduledBase {
34
+ reason: "retry";
35
+ }
36
+ interface WorkflowRunStateScheduledByAwake extends WorkflowRunStateScheduledBase {
37
+ reason: "awake";
38
+ }
39
+ interface WorkflowRunStateScheduledByResume extends WorkflowRunStateScheduledBase {
40
+ reason: "resume";
41
+ }
42
+ interface WorkflowRunStateScheduledByEvent extends WorkflowRunStateScheduledBase {
43
+ reason: "event";
44
+ }
45
+ type WorkflowRunStateScheduled = WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByRetry | WorkflowRunStateScheduledByAwake | WorkflowRunStateScheduledByResume | WorkflowRunStateScheduledByEvent;
46
+ interface WorkflowRunStateQueued extends WorkflowRunStateBase {
47
+ status: "queued";
48
+ reason: WorkflowRunScheduledReason;
49
+ }
50
+ interface WorkflowRunStateRunning extends WorkflowRunStateBase {
51
+ status: "running";
52
+ }
53
+ interface WorkflowRunStatePaused extends WorkflowRunStateBase {
54
+ status: "paused";
55
+ pausedAt: number;
56
+ }
57
+ interface WorkflowRunStateSleeping extends WorkflowRunStateBase {
58
+ status: "sleeping";
59
+ sleepPath: string;
60
+ durationMs: number;
61
+ }
62
+ interface WorkflowRunStateAwaitingEvent extends WorkflowRunStateBase {
63
+ status: "awaiting_event";
64
+ }
65
+ type WorkflowFailureCause = "task" | "child_workflow" | "self";
66
+ interface WorkflowRunStateAwaitingBase extends WorkflowRunStateBase {
67
+ status: "awaiting_retry";
68
+ cause: WorkflowFailureCause;
69
+ reason: string;
70
+ nextAttemptAt: number;
71
+ }
72
+ interface WorkflowRunStateAwaitingRetryCausedByTask extends WorkflowRunStateAwaitingBase {
73
+ cause: "task";
74
+ taskPath: string;
75
+ }
76
+ interface WorkflowRunStateAwaitingRetryCausedByChildWorkflow extends WorkflowRunStateAwaitingBase {
77
+ cause: "child_workflow";
78
+ childWorkflowRunId: string;
79
+ }
80
+ interface WorkflowRunStateAwaitingRetryCausedBySelf extends WorkflowRunStateAwaitingBase {
81
+ cause: "self";
82
+ error: SerializableError;
83
+ }
84
+ type WorkflowRunStateAwaitingRetry = WorkflowRunStateAwaitingRetryCausedByTask | WorkflowRunStateAwaitingRetryCausedByChildWorkflow | WorkflowRunStateAwaitingRetryCausedBySelf;
85
+ interface WorkflowRunStateAwaitingChildWorkflow extends WorkflowRunStateBase {
86
+ status: "awaiting_child_workflow";
87
+ }
88
+ interface WorkflowRunStateCancelled extends WorkflowRunStateBase {
89
+ status: "cancelled";
90
+ reason?: string;
91
+ }
92
+ interface WorkflowRunStateCompleted<Output> extends WorkflowRunStateBase {
93
+ status: "completed";
94
+ output: Output;
95
+ }
96
+ interface WorkflowRunStateFailedBase extends WorkflowRunStateBase {
97
+ status: "failed";
98
+ cause: WorkflowFailureCause;
99
+ reason: string;
100
+ }
101
+ interface WorkflowRunStateFailedByTask extends WorkflowRunStateFailedBase {
102
+ cause: "task";
103
+ taskPath: string;
104
+ }
105
+ interface WorkflowRunStateFailedByChildWorkflow extends WorkflowRunStateFailedBase {
106
+ cause: "child_workflow";
107
+ childWorkflowRunId: string;
108
+ }
109
+ interface WorkflowRunStateFailedBySelf extends WorkflowRunStateFailedBase {
110
+ cause: "self";
111
+ error: SerializableError;
112
+ }
113
+ type WorkflowRunStateFailed = WorkflowRunStateFailedByTask | WorkflowRunStateFailedByChildWorkflow | WorkflowRunStateFailedBySelf;
114
+ type WorkflowRunStateInComplete = WorkflowRunStateScheduled | WorkflowRunStateQueued | WorkflowRunStateRunning | WorkflowRunStatePaused | WorkflowRunStateSleeping | WorkflowRunStateAwaitingEvent | WorkflowRunStateAwaitingRetry | WorkflowRunStateAwaitingChildWorkflow | WorkflowRunStateCancelled | WorkflowRunStateFailed;
115
+ type WorkflowRunState<Output> = WorkflowRunStateInComplete | WorkflowRunStateCompleted<Output>;
116
+ interface WorkflowRun<Input = unknown, Output = unknown> {
117
+ id: string;
118
+ workflowId: string;
119
+ workflowVersionId: string;
120
+ createdAt: number;
121
+ revision: number;
122
+ input: Input;
123
+ options: WorkflowOptions;
124
+ attempts: number;
125
+ state: WorkflowRunState<Output>;
126
+ tasksState: Record<string, TaskState<unknown>>;
127
+ sleepsState: Record<string, SleepState>;
128
+ childWorkflowsRunState: Record<string, WorkflowRunState<unknown>>;
129
+ }
130
+ interface WorkflowRunTransitionBase {
131
+ createdAt: number;
132
+ type: "state" | "task_state";
133
+ }
134
+ interface WorkflowRunStateTransition extends WorkflowRunTransitionBase {
135
+ type: "state";
136
+ state: WorkflowRunState<unknown>;
137
+ }
138
+ interface WorkflowRunTaskStateTransition extends WorkflowRunTransitionBase {
139
+ type: "task_state";
140
+ taskPath: string;
141
+ taskState: TaskState<unknown>;
142
+ }
143
+ type WorkflowRunTransition = WorkflowRunStateTransition | WorkflowRunTaskStateTransition;
144
+ declare class WorkflowRunConflictError extends Error {
145
+ readonly id: WorkflowRunId;
146
+ readonly operation: string;
147
+ readonly attempts: number;
148
+ constructor(id: WorkflowRunId, operation: string, attempts: number);
149
+ }
150
+ declare class WorkflowRunNotExecutableError extends Error {
151
+ readonly id: WorkflowRunId;
152
+ readonly status: WorkflowRunStatus;
153
+ constructor(id: WorkflowRunId, status: WorkflowRunStatus);
154
+ }
155
+ declare class WorkflowRunPausedError extends Error {
156
+ constructor(id: WorkflowRunId);
157
+ }
158
+ declare class WorkflowRunCancelledError extends Error {
159
+ constructor(id: WorkflowRunId);
160
+ }
161
+ declare class WorkflowRunFailedError extends Error {
162
+ readonly id: WorkflowRunId;
163
+ readonly attempts: number;
164
+ readonly reason: string;
165
+ readonly failureCause?: WorkflowFailureCause | undefined;
166
+ constructor(id: WorkflowRunId, attempts: number, reason: string, failureCause?: WorkflowFailureCause | undefined);
167
+ }
168
+ declare class WorkflowRunSuspendedError extends Error {
169
+ readonly id: WorkflowRunId;
170
+ constructor(id: WorkflowRunId);
171
+ }
172
+
173
+ export { type NonTerminalWorkflowRunStatus, type TerminalWorkflowRunStatus, type WorkflowFailureCause, type WorkflowOptions, type WorkflowRun, WorkflowRunCancelledError, WorkflowRunConflictError, WorkflowRunFailedError, type WorkflowRunId, WorkflowRunNotExecutableError, WorkflowRunPausedError, type WorkflowRunScheduledReason, type WorkflowRunState, type WorkflowRunStateAwaitingBase, type WorkflowRunStateAwaitingChildWorkflow, type WorkflowRunStateAwaitingEvent, type WorkflowRunStateAwaitingRetry, type WorkflowRunStateAwaitingRetryCausedByChildWorkflow, type WorkflowRunStateAwaitingRetryCausedBySelf, type WorkflowRunStateAwaitingRetryCausedByTask, type WorkflowRunStateCancelled, type WorkflowRunStateCompleted, type WorkflowRunStateFailed, type WorkflowRunStateFailedByChildWorkflow, type WorkflowRunStateFailedBySelf, type WorkflowRunStateFailedByTask, type WorkflowRunStateInComplete, type WorkflowRunStatePaused, type WorkflowRunStateQueued, type WorkflowRunStateRunning, type WorkflowRunStateScheduled, type WorkflowRunStateScheduledByAwake, type WorkflowRunStateScheduledByEvent, type WorkflowRunStateScheduledByNew, type WorkflowRunStateScheduledByResume, type WorkflowRunStateScheduledByRetry, type WorkflowRunStateSleeping, type WorkflowRunStateTransition, type WorkflowRunStatus, WorkflowRunSuspendedError, type WorkflowRunTaskStateTransition, type WorkflowRunTransition, type WorkflowRunTransitionBase };
@@ -0,0 +1,55 @@
1
+ // workflow-run.ts
2
+ var WorkflowRunConflictError = class extends Error {
3
+ constructor(id, operation, attempts) {
4
+ super(`Conflict while performing ${operation} on workflow ${id} after ${attempts} attempts`);
5
+ this.id = id;
6
+ this.operation = operation;
7
+ this.attempts = attempts;
8
+ this.name = "WorkflowRunConflictError";
9
+ }
10
+ };
11
+ var WorkflowRunNotExecutableError = class extends Error {
12
+ constructor(id, status) {
13
+ super(`Workflow ${id} is not executable while ${status}`);
14
+ this.id = id;
15
+ this.status = status;
16
+ this.name = "WorkflowRunNotExecutableError";
17
+ }
18
+ };
19
+ var WorkflowRunPausedError = class extends Error {
20
+ constructor(id) {
21
+ super(`Workflow ${id} paused`);
22
+ this.name = "WorkflowRunPausedError";
23
+ }
24
+ };
25
+ var WorkflowRunCancelledError = class extends Error {
26
+ constructor(id) {
27
+ super(`Workflow ${id} cancelled`);
28
+ this.name = "WorkflowRunCancelledError";
29
+ }
30
+ };
31
+ var WorkflowRunFailedError = class extends Error {
32
+ constructor(id, attempts, reason, failureCause) {
33
+ super(`Workflow ${id} failed after ${attempts} attempt(s): ${reason}`);
34
+ this.id = id;
35
+ this.attempts = attempts;
36
+ this.reason = reason;
37
+ this.failureCause = failureCause;
38
+ this.name = "WorkflowRunFailedError";
39
+ }
40
+ };
41
+ var WorkflowRunSuspendedError = class extends Error {
42
+ constructor(id) {
43
+ super(`Workflow ${id} is suspended`);
44
+ this.id = id;
45
+ this.name = "WorkflowRunSuspendedError";
46
+ }
47
+ };
48
+ export {
49
+ WorkflowRunCancelledError,
50
+ WorkflowRunConflictError,
51
+ WorkflowRunFailedError,
52
+ WorkflowRunNotExecutableError,
53
+ WorkflowRunPausedError,
54
+ WorkflowRunSuspendedError
55
+ };
@@ -0,0 +1,12 @@
1
+ type WorkflowId = string & {
2
+ _brand: "workflow_id";
3
+ };
4
+ type WorkflowVersionId = string & {
5
+ _brand: "workflow_version_id";
6
+ };
7
+ interface WorkflowMeta {
8
+ id: WorkflowId;
9
+ versionId: WorkflowVersionId;
10
+ }
11
+
12
+ export type { WorkflowId, WorkflowMeta, WorkflowVersionId };
File without changes
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@aikirun/types",
3
+ "version": "0.5.3",
4
+ "description": "Core type definitions for Aiki - including workflow, task, client, and trigger types",
5
+ "type": "module",
6
+ "exports": {
7
+ "./utils": {
8
+ "types": "./dist/utils.d.ts",
9
+ "import": "./dist/utils.js"
10
+ },
11
+ "./symbols": {
12
+ "types": "./dist/symbols.d.ts",
13
+ "import": "./dist/symbols.js"
14
+ },
15
+ "./duration": {
16
+ "types": "./dist/duration.d.ts",
17
+ "import": "./dist/duration.js"
18
+ },
19
+ "./retry": {
20
+ "types": "./dist/retry.d.ts",
21
+ "import": "./dist/retry.js"
22
+ },
23
+ "./error": {
24
+ "types": "./dist/error.d.ts",
25
+ "import": "./dist/error.js"
26
+ },
27
+ "./client": {
28
+ "types": "./dist/client.d.ts",
29
+ "import": "./dist/client.js"
30
+ },
31
+ "./trigger": {
32
+ "types": "./dist/trigger.d.ts",
33
+ "import": "./dist/trigger.js"
34
+ },
35
+ "./workflow": {
36
+ "types": "./dist/workflow.d.ts",
37
+ "import": "./dist/workflow.js"
38
+ },
39
+ "./workflow-run": {
40
+ "types": "./dist/workflow-run.d.ts",
41
+ "import": "./dist/workflow-run.js"
42
+ },
43
+ "./workflow-run-api": {
44
+ "types": "./dist/workflow-run-api.d.ts",
45
+ "import": "./dist/workflow-run-api.js"
46
+ },
47
+ "./task": {
48
+ "types": "./dist/task.d.ts",
49
+ "import": "./dist/task.js"
50
+ },
51
+ "./sleep": {
52
+ "types": "./dist/sleep.d.ts",
53
+ "import": "./dist/sleep.js"
54
+ }
55
+ },
56
+ "files": [
57
+ "dist"
58
+ ],
59
+ "scripts": {
60
+ "build": "tsup"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "license": "Apache-2.0"
66
+ }