@kb-labs/workflow-engine 2.94.0 → 2.96.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/dist/index.d.ts +55 -143
- package/dist/index.js +309 -311
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WorkflowSpec, RunTrigger, IdempotencyKey, ConcurrencyGroup, WorkflowRun, JobRun, StepRun, RetryPolicy, ArtifactMergeConfig } from '@kb-labs/workflow-contracts';
|
|
2
|
-
import { ILogger, ICache, IEventBus, IAnalytics,
|
|
2
|
+
import { ILogger, ICache, IEventBus, IAnalytics, ISnapshotManager, Unsubscribe, IJobScheduler, JobDefinition, JobHandle, CronExpression, JobFilter } from '@kb-labs/core-platform';
|
|
3
3
|
import { JobPriority, WorkflowEventName } from '@kb-labs/workflow-constants';
|
|
4
4
|
import { ArtifactClient } from '@kb-labs/workflow-artifacts';
|
|
5
5
|
import { IEntityRegistry } from '@kb-labs/core-registry';
|
|
6
|
-
import { PlatformServices, JobHandlerDecl, PluginContextDescriptor } from '@kb-labs/plugin-contracts';
|
|
6
|
+
import { PlatformServices, JobHandlerDecl, WorkflowHandlerDecl, CronDecl, PluginContextDescriptor } from '@kb-labs/plugin-contracts';
|
|
7
7
|
import { IExecutionBackend } from '@kb-labs/core-contracts';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -182,16 +182,6 @@ declare class RunSnapshotStorage {
|
|
|
182
182
|
deleteSnapshot(runId: string): Promise<void>;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
interface SnapshotManagerClient {
|
|
186
|
-
restoreSnapshot(request: {
|
|
187
|
-
snapshotId: string;
|
|
188
|
-
workspaceId?: string;
|
|
189
|
-
environmentId?: string;
|
|
190
|
-
targetPath?: string;
|
|
191
|
-
overwrite?: boolean;
|
|
192
|
-
metadata?: Record<string, unknown>;
|
|
193
|
-
}): Promise<unknown>;
|
|
194
|
-
}
|
|
195
185
|
interface WorkflowEngineOptions {
|
|
196
186
|
scheduler?: SchedulerOptions;
|
|
197
187
|
concurrency?: AcquireOptions;
|
|
@@ -206,7 +196,7 @@ interface WorkflowEngineOptions {
|
|
|
206
196
|
/** Platform analytics adapter (OPTIONAL) */
|
|
207
197
|
analytics?: IAnalytics;
|
|
208
198
|
/** Platform snapshot manager (OPTIONAL - for infra snapshot restore in replay) */
|
|
209
|
-
snapshotManager?:
|
|
199
|
+
snapshotManager?: ISnapshotManager;
|
|
210
200
|
/** Workspace root (monorepo root) - used for plugin execution context */
|
|
211
201
|
workspaceRoot?: string;
|
|
212
202
|
}
|
|
@@ -240,6 +230,12 @@ declare class WorkflowEngine {
|
|
|
240
230
|
* Implements exponential/linear backoff retry logic.
|
|
241
231
|
*/
|
|
242
232
|
markJobFailed(runId: string, jobId: string, error: Error, shouldRetry?: boolean): Promise<void>;
|
|
233
|
+
/**
|
|
234
|
+
* Recursively cancel jobs blocked on a failed/cancelled upstream job, so the
|
|
235
|
+
* DAG does not leave dependents stuck in 'queued'. Cancellation cascades:
|
|
236
|
+
* a cancelled job also cancels its own dependents.
|
|
237
|
+
*/
|
|
238
|
+
private cancelDownstreamJobs;
|
|
243
239
|
/**
|
|
244
240
|
* Mark job as interrupted (e.g., during graceful shutdown).
|
|
245
241
|
* Interrupted jobs will be retried on next daemon startup.
|
|
@@ -253,6 +249,12 @@ declare class WorkflowEngine {
|
|
|
253
249
|
* Mark job as completed successfully.
|
|
254
250
|
*/
|
|
255
251
|
markJobCompleted(runId: string, jobId: string): Promise<void>;
|
|
252
|
+
/** Build a minimal ExpressionContext from run state (for job-level if evaluation). */
|
|
253
|
+
private buildExpressionContext;
|
|
254
|
+
/** Evaluate a job-level `if:` expression. Strips ${{ }} wrapper if present. */
|
|
255
|
+
private evaluateJobIf;
|
|
256
|
+
/** Mark a job as skipped (success) and release any jobs blocked on it. */
|
|
257
|
+
private skipJob;
|
|
256
258
|
/**
|
|
257
259
|
* Check if all jobs in a run are completed and update run status accordingly.
|
|
258
260
|
*/
|
|
@@ -309,7 +311,13 @@ declare class WorkflowEngine {
|
|
|
309
311
|
/**
|
|
310
312
|
* Move permanently failed job to Dead Letter Queue.
|
|
311
313
|
*/
|
|
312
|
-
|
|
314
|
+
/**
|
|
315
|
+
* Record a dead-letter entry for a job that exhausted its retries. This is an
|
|
316
|
+
* observability artifact only — it does NOT change the run status. The run
|
|
317
|
+
* outcome is decided by checkRunCompletion (→ 'failed'). 'dlq' as a run status
|
|
318
|
+
* is reserved for infrastructure failures and is no longer set here (B-029).
|
|
319
|
+
*/
|
|
320
|
+
private deadLetterJob;
|
|
313
321
|
updateRun(runId: string, mutator: (run: WorkflowRun) => WorkflowRun | void): Promise<WorkflowRun | null>;
|
|
314
322
|
finalizeRun(runId: string, status: WorkflowRun['status'], context?: Partial<RunContext>): Promise<WorkflowRun | null>;
|
|
315
323
|
nextJob(): Promise<JobQueueEntry | null>;
|
|
@@ -325,7 +333,7 @@ declare class WorkflowEngine {
|
|
|
325
333
|
lineNo: number;
|
|
326
334
|
timestamp: string;
|
|
327
335
|
meta?: Record<string, unknown>;
|
|
328
|
-
}): Promise<void>;
|
|
336
|
+
}, stepName?: string): Promise<void>;
|
|
329
337
|
/**
|
|
330
338
|
* Create a snapshot of the current run state
|
|
331
339
|
*/
|
|
@@ -464,6 +472,8 @@ interface WorkflowStats {
|
|
|
464
472
|
*/
|
|
465
473
|
interface WorkflowRuntime {
|
|
466
474
|
id: string;
|
|
475
|
+
/** Discriminator for workflow kind. Enables type-safe routing in consumers. */
|
|
476
|
+
kind?: 'workflow' | 'job' | 'cron';
|
|
467
477
|
source: 'manifest' | 'standalone' | 'plugin';
|
|
468
478
|
pluginId?: string;
|
|
469
479
|
manifestPath?: string;
|
|
@@ -484,6 +494,10 @@ interface WorkflowRuntime {
|
|
|
484
494
|
required?: boolean;
|
|
485
495
|
default?: unknown;
|
|
486
496
|
}>;
|
|
497
|
+
/** Semantic version from workflow spec (e.g. "6.6.0") */
|
|
498
|
+
version?: string;
|
|
499
|
+
/** ISO timestamp of last modification */
|
|
500
|
+
updatedAt?: string;
|
|
487
501
|
}
|
|
488
502
|
/**
|
|
489
503
|
* Options for ManifestScanner
|
|
@@ -505,25 +519,16 @@ declare class ManifestScanner {
|
|
|
505
519
|
private readonly cliApi;
|
|
506
520
|
private readonly platform;
|
|
507
521
|
private readonly cacheTtlMs;
|
|
522
|
+
private readonly converter;
|
|
508
523
|
constructor(options: ManifestScannerOptions);
|
|
509
524
|
/**
|
|
510
525
|
* Scan all installed plugins for workflows and jobs.
|
|
526
|
+
* Purpose: listing — populates the REST API GET /api/v1/workflows catalog.
|
|
527
|
+
* (CronDiscovery in daemon handles scheduling — different output, different consumer.)
|
|
511
528
|
*
|
|
512
529
|
* Returns unified WorkflowRuntime representations.
|
|
513
530
|
*/
|
|
514
531
|
scanPlugins(): Promise<WorkflowRuntime[]>;
|
|
515
|
-
/**
|
|
516
|
-
* Convert workflow handler declaration to WorkflowRuntime.
|
|
517
|
-
*/
|
|
518
|
-
private convertWorkflowHandler;
|
|
519
|
-
/**
|
|
520
|
-
* Convert job handler declaration to WorkflowRuntime.
|
|
521
|
-
*/
|
|
522
|
-
private convertJobHandler;
|
|
523
|
-
/**
|
|
524
|
-
* Convert cron schedule declaration to WorkflowRuntime.
|
|
525
|
-
*/
|
|
526
|
-
private convertCronSchedule;
|
|
527
532
|
/**
|
|
528
533
|
* Scan all installed plugins for job handlers only.
|
|
529
534
|
*
|
|
@@ -548,6 +553,21 @@ declare class ManifestScanner {
|
|
|
548
553
|
watchPlugins(callback?: (workflows: WorkflowRuntime[]) => void): () => void;
|
|
549
554
|
}
|
|
550
555
|
|
|
556
|
+
/**
|
|
557
|
+
* @module @kb-labs/workflow-engine/manifest-converter
|
|
558
|
+
*
|
|
559
|
+
* Pure conversion utilities for plugin manifest declarations → WorkflowRuntime.
|
|
560
|
+
* No I/O, no caching, no platform dependency — testable in isolation.
|
|
561
|
+
*
|
|
562
|
+
* Used by ManifestScanner which handles fetch + cache responsibilities.
|
|
563
|
+
*/
|
|
564
|
+
|
|
565
|
+
declare class ManifestConverter {
|
|
566
|
+
convertWorkflowHandler(pluginId: string, handler: WorkflowHandlerDecl, pluginRoot: string): WorkflowRuntime;
|
|
567
|
+
convertJobHandler(pluginId: string, handler: JobHandlerDecl, pluginRoot: string): WorkflowRuntime;
|
|
568
|
+
convertCronSchedule(pluginId: string, cronDecl: CronDecl, pluginRoot: string): WorkflowRuntime;
|
|
569
|
+
}
|
|
570
|
+
|
|
551
571
|
/**
|
|
552
572
|
* @module @kb-labs/workflow-engine/workflow-repository
|
|
553
573
|
*
|
|
@@ -733,6 +753,13 @@ declare class WorkflowService {
|
|
|
733
753
|
listAll(options?: WorkflowServiceListOptions): Promise<WorkflowRuntime[]>;
|
|
734
754
|
/**
|
|
735
755
|
* Get workflow by ID (from either source).
|
|
756
|
+
*
|
|
757
|
+
* Lookup order:
|
|
758
|
+
* 1. Standalone by filename-derived id (canonical, fast path)
|
|
759
|
+
* 2. Standalone by `name:` field — allows `--workflow-id=dev-cycle` even
|
|
760
|
+
* when the file is named `03-dev-cycle.yml` (F8 ergonomics fix)
|
|
761
|
+
* 3. Manifest-based by id
|
|
762
|
+
* 4. Manifest-based by name field
|
|
736
763
|
*/
|
|
737
764
|
get(id: string): Promise<WorkflowRuntime | null>;
|
|
738
765
|
/**
|
|
@@ -780,121 +807,6 @@ declare class WorkflowService {
|
|
|
780
807
|
refreshManifests(): Promise<void>;
|
|
781
808
|
}
|
|
782
809
|
|
|
783
|
-
/**
|
|
784
|
-
* @module @kb-labs/workflow-engine/workflow-schedule-manager
|
|
785
|
-
*
|
|
786
|
-
* Manages scheduled workflow execution via CronManager.
|
|
787
|
-
*
|
|
788
|
-
* ## Features
|
|
789
|
-
* - Registers scheduled workflows with CronManager
|
|
790
|
-
* - Executes workflows on cron triggers
|
|
791
|
-
* - Tracks next/last run times
|
|
792
|
-
* - Supports both manifest-based jobs and standalone workflows
|
|
793
|
-
*
|
|
794
|
-
* ## Usage
|
|
795
|
-
* ```typescript
|
|
796
|
-
* const scheduleManager = new WorkflowScheduleManager({
|
|
797
|
-
* cronManager,
|
|
798
|
-
* workflowService,
|
|
799
|
-
* executor,
|
|
800
|
-
* platform,
|
|
801
|
-
* });
|
|
802
|
-
*
|
|
803
|
-
* await scheduleManager.registerAll();
|
|
804
|
-
* ```
|
|
805
|
-
*/
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Workflow executor interface.
|
|
809
|
-
* Executes workflows (will be implemented by workflow engine).
|
|
810
|
-
*/
|
|
811
|
-
interface WorkflowExecutor {
|
|
812
|
-
/**
|
|
813
|
-
* Execute workflow by ID.
|
|
814
|
-
*/
|
|
815
|
-
execute(request: {
|
|
816
|
-
workflowId: string;
|
|
817
|
-
trigger: 'manual' | 'schedule' | 'webhook' | 'push';
|
|
818
|
-
input?: Record<string, unknown>;
|
|
819
|
-
}): Promise<{
|
|
820
|
-
runId: string;
|
|
821
|
-
}>;
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* Options for WorkflowScheduleManager
|
|
825
|
-
*/
|
|
826
|
-
interface WorkflowScheduleManagerOptions {
|
|
827
|
-
/** CronManager instance */
|
|
828
|
-
cronManager: ICronManager;
|
|
829
|
-
/** WorkflowService for discovering workflows */
|
|
830
|
-
workflowService: WorkflowService;
|
|
831
|
-
/** Workflow executor */
|
|
832
|
-
executor: WorkflowExecutor;
|
|
833
|
-
/** Platform services */
|
|
834
|
-
platform: PlatformServices;
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Workflow Schedule Manager
|
|
838
|
-
*
|
|
839
|
-
* Integrates workflows with CronManager for scheduled execution.
|
|
840
|
-
*/
|
|
841
|
-
declare class WorkflowScheduleManager {
|
|
842
|
-
private readonly cronManager;
|
|
843
|
-
private readonly workflowService;
|
|
844
|
-
private readonly executor;
|
|
845
|
-
private readonly platform;
|
|
846
|
-
constructor(options: WorkflowScheduleManagerOptions);
|
|
847
|
-
/**
|
|
848
|
-
* Register all scheduled workflows with CronManager.
|
|
849
|
-
*
|
|
850
|
-
* Scans both manifest-based jobs and standalone workflows with schedules.
|
|
851
|
-
*/
|
|
852
|
-
registerAll(): Promise<void>;
|
|
853
|
-
/**
|
|
854
|
-
* Register single workflow schedule.
|
|
855
|
-
*/
|
|
856
|
-
register(workflow: WorkflowRuntime): Promise<void>;
|
|
857
|
-
/**
|
|
858
|
-
* Unregister workflow schedule.
|
|
859
|
-
*/
|
|
860
|
-
unregister(workflowId: string): Promise<void>;
|
|
861
|
-
/**
|
|
862
|
-
* Re-register all schedules (refresh).
|
|
863
|
-
*
|
|
864
|
-
* Useful after workflow changes or service restart.
|
|
865
|
-
*/
|
|
866
|
-
refresh(): Promise<void>;
|
|
867
|
-
/**
|
|
868
|
-
* Get next run time for scheduled workflow.
|
|
869
|
-
*/
|
|
870
|
-
getNextRun(workflowId: string): Date | null;
|
|
871
|
-
/**
|
|
872
|
-
* Get last run time for scheduled workflow.
|
|
873
|
-
*/
|
|
874
|
-
getLastRun(workflowId: string): Date | null;
|
|
875
|
-
/**
|
|
876
|
-
* Pause scheduled workflow.
|
|
877
|
-
*/
|
|
878
|
-
pause(workflowId: string): void;
|
|
879
|
-
/**
|
|
880
|
-
* Resume paused workflow schedule.
|
|
881
|
-
*/
|
|
882
|
-
resume(workflowId: string): void;
|
|
883
|
-
/**
|
|
884
|
-
* List all scheduled workflows.
|
|
885
|
-
*/
|
|
886
|
-
listScheduled(): Array<{
|
|
887
|
-
workflowId: string;
|
|
888
|
-
schedule: string;
|
|
889
|
-
status: 'active' | 'paused';
|
|
890
|
-
lastRun?: Date;
|
|
891
|
-
nextRun?: Date;
|
|
892
|
-
runCount: number;
|
|
893
|
-
}>;
|
|
894
|
-
private getCronId;
|
|
895
|
-
private getWorkflowId;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
810
|
interface WorkflowRegistryEntry {
|
|
899
811
|
id: string;
|
|
900
812
|
name: string;
|
|
@@ -1056,4 +968,4 @@ declare class JobManager implements IJobScheduler {
|
|
|
1056
968
|
private jobRecordToHandle;
|
|
1057
969
|
}
|
|
1058
970
|
|
|
1059
|
-
export { type AcquireOptions, ArtifactMerger, type ArtifactMergerOptions, ConcurrencyManager, type CreateRunInput, type EngineLogger, EnvSecretProvider, type EnvSecretProviderOptions, EventBusBridge, JobManager, type JobManagerConfig, type JobQueueEntry, ManifestScanner, type ManifestScannerOptions, type RetryDecision, type RunContext, RunCoordinator, type RunCoordinatorOptions, type RunSnapshot, RunSnapshotStorage, Scheduler, type SchedulerOptions, type SecretProvider, StateStore, type ValidationResult, WorkflowEngine, type WorkflowEngineOptions, type WorkflowEvent, type
|
|
971
|
+
export { type AcquireOptions, ArtifactMerger, type ArtifactMergerOptions, ConcurrencyManager, type CreateRunInput, type EngineLogger, EnvSecretProvider, type EnvSecretProviderOptions, EventBusBridge, JobManager, type JobManagerConfig, type JobQueueEntry, ManifestConverter, ManifestScanner, type ManifestScannerOptions, type RetryDecision, type RunContext, RunCoordinator, type RunCoordinatorOptions, type RunSnapshot, RunSnapshotStorage, Scheduler, type SchedulerOptions, type SecretProvider, StateStore, type ValidationResult, WorkflowEngine, type WorkflowEngineOptions, type WorkflowEvent, type WorkflowHandlerInfo, type WorkflowListOptions, WorkflowLoader, type WorkflowLoaderOptions, type WorkflowLoaderResult, WorkflowRegistry, type WorkflowRegistryEntry, type WorkflowRegistryOptions, WorkflowRepository, type WorkflowRepositoryOptions, type WorkflowRuntime, type WorkflowSchedule, WorkflowService, type WorkflowServiceListOptions, type WorkflowServiceOptions, type WorkflowStats, type WorkflowTrigger, type WorkflowTriggerType, calculateBackoff, createDefaultSecretProvider, shouldRetry };
|