@aikirun/workflow 0.23.1 → 0.24.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.
- package/README.md +1 -2
- package/dist/index.d.ts +48 -53
- package/dist/index.js +588 -260
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -32,10 +32,9 @@ Run with a client:
|
|
|
32
32
|
```typescript
|
|
33
33
|
import { client } from "@aikirun/client";
|
|
34
34
|
|
|
35
|
-
// Set AIKI_API_KEY env variable or pass apiKey option
|
|
36
35
|
const aikiClient = client({
|
|
37
36
|
url: "http://localhost:9850",
|
|
38
|
-
|
|
37
|
+
apiKey: "your-api-key",
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
const handle = await onboardingWorkflowV1.start(aikiClient, {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { WorkflowName, WorkflowVersionId } from '@aikirun/types/workflow';
|
|
2
|
-
import {
|
|
2
|
+
import { DistributiveOmit, RequireAtLeastOneProp } from '@aikirun/types/property';
|
|
3
|
+
import { Client, ApiClient } from '@aikirun/types/client';
|
|
3
4
|
import { INTERNAL } from '@aikirun/types/symbols';
|
|
4
|
-
import { WorkflowRun, TerminalWorkflowRunStatus, WorkflowRunState, WorkflowRunId,
|
|
5
|
+
import { WorkflowRun, TerminalWorkflowRunStatus, WorkflowRunState, WorkflowRunId, WorkflowStartOptions, WorkflowDefinitionOptions } from '@aikirun/types/workflow-run';
|
|
5
6
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
7
|
import { DurationObject, Duration } from '@aikirun/types/duration';
|
|
8
|
+
import { Logger } from '@aikirun/types/logger';
|
|
9
|
+
import { ReplayManifest } from '@aikirun/types/replay-manifest';
|
|
7
10
|
import { SleepResult } from '@aikirun/types/sleep';
|
|
8
11
|
import { EventSendOptions, EventWaitOptions, EventWaitResult } from '@aikirun/types/event';
|
|
9
12
|
import { Serializable } from '@aikirun/types/serializable';
|
|
10
|
-
import {
|
|
11
|
-
import { TaskInfo, TaskAddress } from '@aikirun/types/task';
|
|
13
|
+
import { TaskInfo } from '@aikirun/types/task';
|
|
12
14
|
import { WorkflowRunStateRequest, WorkflowRunTransitionTaskStateRequestV1 } from '@aikirun/types/workflow-run-api';
|
|
13
15
|
import { ScheduleOverlapPolicy, ScheduleActivateOptions, ScheduleId } from '@aikirun/types/schedule';
|
|
14
16
|
|
|
@@ -117,7 +119,7 @@ type WorkflowRunWaitResult<Status extends TerminalWorkflowRunStatus, Output, Tim
|
|
|
117
119
|
*
|
|
118
120
|
* @template Data - Type of event data (must be JSON serializable)
|
|
119
121
|
* @param params - Optional event configuration
|
|
120
|
-
* @param
|
|
122
|
+
* @param params.schema - Optional schema for runtime validation
|
|
121
123
|
* @returns EventDefinition for use in workflows
|
|
122
124
|
*
|
|
123
125
|
* @example
|
|
@@ -176,21 +178,7 @@ interface EventMulticasterBuilder<Data> {
|
|
|
176
178
|
declare function createEventWaiters<TEvents extends EventsDefinition>(handle: WorkflowRunHandle<unknown, unknown, unknown, TEvents>, eventsDefinition: TEvents, logger: Logger): EventWaiters<TEvents>;
|
|
177
179
|
declare function createEventSenders<TEvents extends EventsDefinition>(api: ApiClient, workflowRunId: string, eventsDefinition: TEvents, logger: Logger): EventSenders<TEvents>;
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
interface ReplayManifest {
|
|
182
|
-
consumeNextTask(address: TaskAddress): TaskInfo | undefined;
|
|
183
|
-
consumeNextChildWorkflowRun(address: WorkflowRunAddress): ChildWorkflowRunInfo | undefined;
|
|
184
|
-
hasUnconsumedEntries(): boolean;
|
|
185
|
-
getUnconsumedEntries(): UnconsumedManifestEntries;
|
|
186
|
-
}
|
|
187
|
-
interface UnconsumedManifestEntries {
|
|
188
|
-
taskIds: string[];
|
|
189
|
-
childWorkflowRunIds: string[];
|
|
190
|
-
}
|
|
191
|
-
declare function createReplayManifest(run: WorkflowRun): ReplayManifest;
|
|
192
|
-
|
|
193
|
-
interface WorkflowRunContext<Input, AppContext, TEvents extends EventsDefinition> {
|
|
181
|
+
interface WorkflowRunContext<Input, AppContext, TEvents extends EventsDefinition = EventsDefinition> {
|
|
194
182
|
id: WorkflowRunId;
|
|
195
183
|
name: WorkflowName;
|
|
196
184
|
versionId: WorkflowVersionId;
|
|
@@ -255,7 +243,7 @@ interface ChildWorkflowRunWaitOptions<Timed extends boolean> {
|
|
|
255
243
|
interface WorkflowVersionParams<Input, Output, AppContext, TEvents extends EventsDefinition> {
|
|
256
244
|
handler: (run: Readonly<WorkflowRunContext<Input, AppContext, TEvents>>, input: Input, context: AppContext) => Promise<Output>;
|
|
257
245
|
events?: TEvents;
|
|
258
|
-
|
|
246
|
+
options?: WorkflowDefinitionOptions;
|
|
259
247
|
schema?: RequireAtLeastOneProp<{
|
|
260
248
|
input?: StandardSchemaV1<Input>;
|
|
261
249
|
output?: StandardSchemaV1<Output>;
|
|
@@ -275,28 +263,8 @@ interface WorkflowVersion<Input, Output, AppContext, TEvents extends EventsDefin
|
|
|
275
263
|
handler: (run: WorkflowRunContext<Input, AppContext, TEvents>, input: Input, context: AppContext) => Promise<void>;
|
|
276
264
|
};
|
|
277
265
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
readonly versionId: WorkflowVersionId;
|
|
281
|
-
private readonly params;
|
|
282
|
-
readonly events: EventMulticasters<TEvents>;
|
|
283
|
-
readonly [INTERNAL]: WorkflowVersion<Input, Output, AppContext, TEvents>[typeof INTERNAL];
|
|
284
|
-
constructor(name: WorkflowName, versionId: WorkflowVersionId, params: WorkflowVersionParams<Input, Output, AppContext, TEvents>);
|
|
285
|
-
with(): WorkflowBuilder<Input, Output, AppContext, TEvents>;
|
|
286
|
-
start(client: Client<AppContext>, ...args: Input extends void ? [] : [Input]): Promise<WorkflowRunHandle<Input, Output, AppContext, TEvents>>;
|
|
287
|
-
startWithOpts(client: Client<AppContext>, startOpts: WorkflowStartOptions, ...args: Input extends void ? [] : [Input]): Promise<WorkflowRunHandle<Input, Output, AppContext, TEvents>>;
|
|
288
|
-
startAsChild(parentRun: WorkflowRunContext<unknown, AppContext, EventsDefinition>, ...args: Input extends void ? [] : [Input]): Promise<ChildWorkflowRunHandle<Input, Output, AppContext, TEvents>>;
|
|
289
|
-
startAsChildWithOpts(parentRun: WorkflowRunContext<unknown, AppContext, EventsDefinition>, startOpts: WorkflowStartOptions, ...args: Input extends void ? [] : [Input]): Promise<ChildWorkflowRunHandle<Input, Output, AppContext, TEvents>>;
|
|
290
|
-
private throwNonDeterminismError;
|
|
291
|
-
getHandleById(client: Client<AppContext>, runId: string): Promise<WorkflowRunHandle<Input, Output, AppContext, TEvents>>;
|
|
292
|
-
getHandleByReferenceId(client: Client<AppContext>, referenceId: string): Promise<WorkflowRunHandle<Input, Output, AppContext, TEvents>>;
|
|
293
|
-
private handler;
|
|
294
|
-
private tryExecuteWorkflow;
|
|
295
|
-
private assertRetryAllowed;
|
|
296
|
-
private parse;
|
|
297
|
-
private createFailedState;
|
|
298
|
-
private createAwaitingRetryState;
|
|
299
|
-
}
|
|
266
|
+
type AnyWorkflowVersion = WorkflowVersion<any, any, any, any>;
|
|
267
|
+
type UnknownWorkflowVersion = WorkflowVersion<unknown, unknown, unknown>;
|
|
300
268
|
interface WorkflowBuilder<Input, Output, AppContext, TEvents extends EventsDefinition> {
|
|
301
269
|
opt<Path extends PathFromObject<WorkflowStartOptions>>(path: Path, value: TypeOfValueAtPath<WorkflowStartOptions, Path>): WorkflowBuilder<Input, Output, AppContext, TEvents>;
|
|
302
270
|
start: WorkflowVersion<Input, Output, AppContext, TEvents>["start"];
|
|
@@ -304,17 +272,42 @@ interface WorkflowBuilder<Input, Output, AppContext, TEvents extends EventsDefin
|
|
|
304
272
|
}
|
|
305
273
|
|
|
306
274
|
declare function workflowRegistry(): WorkflowRegistry;
|
|
307
|
-
type Workflow$1 = WorkflowVersion<unknown, unknown, unknown>;
|
|
308
275
|
interface WorkflowRegistry {
|
|
309
|
-
add: (workflow:
|
|
310
|
-
addMany: (workflows:
|
|
311
|
-
remove: (workflow:
|
|
312
|
-
removeMany: (workflows:
|
|
276
|
+
add: (workflow: UnknownWorkflowVersion) => WorkflowRegistry;
|
|
277
|
+
addMany: (workflows: UnknownWorkflowVersion[]) => WorkflowRegistry;
|
|
278
|
+
remove: (workflow: UnknownWorkflowVersion) => WorkflowRegistry;
|
|
279
|
+
removeMany: (workflows: UnknownWorkflowVersion[]) => WorkflowRegistry;
|
|
313
280
|
removeAll: () => WorkflowRegistry;
|
|
314
|
-
getAll():
|
|
315
|
-
get: (name: WorkflowName, versionId: WorkflowVersionId) =>
|
|
281
|
+
getAll(): UnknownWorkflowVersion[];
|
|
282
|
+
get: (name: WorkflowName, versionId: WorkflowVersionId) => UnknownWorkflowVersion | undefined;
|
|
316
283
|
}
|
|
317
284
|
|
|
285
|
+
interface ExecuteWorkflowParams<AppContext> {
|
|
286
|
+
client: Client<AppContext>;
|
|
287
|
+
workflowRun: WorkflowRun;
|
|
288
|
+
workflowVersion: UnknownWorkflowVersion;
|
|
289
|
+
logger: Logger;
|
|
290
|
+
options: Required<WorkflowExecutionOptions>;
|
|
291
|
+
heartbeat?: () => Promise<void>;
|
|
292
|
+
}
|
|
293
|
+
interface WorkflowExecutionOptions {
|
|
294
|
+
heartbeatIntervalMs?: number;
|
|
295
|
+
/**
|
|
296
|
+
* Threshold for spinning vs persisting task retry delays (default: 10ms).
|
|
297
|
+
*
|
|
298
|
+
* Delays <= threshold: In-memory wait (fast, no task history entry)
|
|
299
|
+
* Delays > threshold: Server state transition (recorded in task history)
|
|
300
|
+
*
|
|
301
|
+
* Set to 0 to record all task delays in transition history.
|
|
302
|
+
*/
|
|
303
|
+
spinThresholdMs?: number;
|
|
304
|
+
}
|
|
305
|
+
declare function executeWorkflowRun<AppContext>(params: ExecuteWorkflowParams<AppContext>): Promise<boolean>;
|
|
306
|
+
|
|
307
|
+
/** biome-ignore-all lint/style/noNonNullAssertion: Manifest boundaries are tracked, hence, we never exceed array boundaries */
|
|
308
|
+
|
|
309
|
+
declare function createReplayManifest(run: WorkflowRun): ReplayManifest;
|
|
310
|
+
|
|
318
311
|
declare function createSleeper(handle: WorkflowRunHandle<unknown, unknown, unknown>, logger: Logger): (name: string, duration: Duration) => Promise<SleepResult>;
|
|
319
312
|
|
|
320
313
|
interface CronScheduleParams {
|
|
@@ -345,6 +338,8 @@ type ScheduleDefinition = ScheduleParams & {
|
|
|
345
338
|
};
|
|
346
339
|
declare function schedule(params: ScheduleParams): ScheduleDefinition;
|
|
347
340
|
|
|
341
|
+
declare function getSystemWorkflows(api: ApiClient): AnyWorkflowVersion[];
|
|
342
|
+
|
|
348
343
|
/**
|
|
349
344
|
* Defines a durable workflow with versioning and multiple task execution.
|
|
350
345
|
*
|
|
@@ -400,9 +395,9 @@ interface Workflow {
|
|
|
400
395
|
name: WorkflowName;
|
|
401
396
|
v: <Input extends Serializable, Output extends Serializable, AppContext = null, TEvents extends EventsDefinition = Record<string, never>>(versionId: string, params: WorkflowVersionParams<Input, Output, AppContext, TEvents>) => WorkflowVersion<Input, Output, AppContext, TEvents>;
|
|
402
397
|
[INTERNAL]: {
|
|
403
|
-
getAllVersions: () =>
|
|
404
|
-
getVersion: (versionId: WorkflowVersionId) =>
|
|
398
|
+
getAllVersions: () => UnknownWorkflowVersion[];
|
|
399
|
+
getVersion: (versionId: WorkflowVersionId) => UnknownWorkflowVersion | undefined;
|
|
405
400
|
};
|
|
406
401
|
}
|
|
407
402
|
|
|
408
|
-
export { type EventDefinition, type EventMulticaster, type EventMulticasters, type EventSender, type EventSenders, type EventWaiter, type EventWaiters, type
|
|
403
|
+
export { type AnyWorkflowVersion, type EventDefinition, type EventMulticaster, type EventMulticasters, type EventSender, type EventSenders, type EventWaiter, type EventWaiters, type ExecuteWorkflowParams, type ScheduleDefinition, type ScheduleHandle, type ScheduleParams, type Workflow, type WorkflowExecutionOptions, type WorkflowParams, type WorkflowRegistry, type WorkflowRunContext, type WorkflowRunHandle, type WorkflowRunWaitOptions, type WorkflowVersion, type WorkflowVersionParams, createEventSenders, createEventWaiters, createReplayManifest, createSleeper, event, executeWorkflowRun, getSystemWorkflows, schedule, workflow, workflowRegistry, workflowRunHandle };
|