@bratsos/workflow-engine 0.5.1 → 0.7.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 +65 -12
- package/dist/{chunk-RZY5YRGL.js → chunk-2HEV5ZJL.js} +2 -2
- package/dist/chunk-2HEV5ZJL.js.map +1 -0
- package/dist/{chunk-WQPZ6KON.js → chunk-5C7LRNM7.js} +280 -93
- package/dist/chunk-5C7LRNM7.js.map +1 -0
- package/dist/{chunk-PHLNTR5Z.js → chunk-Q2XDO3UF.js} +28 -7
- package/dist/chunk-Q2XDO3UF.js.map +1 -0
- package/dist/{chunk-ZYMT2PAO.js → chunk-WWK2SPN7.js} +16 -37
- package/dist/chunk-WWK2SPN7.js.map +1 -0
- package/dist/{client-oLD5ilXp.d.ts → client-DYs5wlHp.d.ts} +17 -99
- package/dist/client.d.ts +4 -3
- package/dist/client.js +1 -1
- package/dist/events-D_P24UaY.d.ts +105 -0
- package/dist/{index-CVkkGnxx.d.ts → index-aNuJ2QgN.d.ts} +11 -1
- package/dist/index.d.ts +184 -32
- package/dist/index.js +41 -9
- package/dist/index.js.map +1 -1
- package/dist/{interface-TsryH4d7.d.ts → interface-BeEPzTFy.d.ts} +9 -3
- package/dist/kernel/index.d.ts +6 -5
- package/dist/kernel/index.js +2 -1
- package/dist/kernel/testing/index.d.ts +3 -2
- package/dist/persistence/index.d.ts +2 -2
- package/dist/persistence/index.js +2 -2
- package/dist/persistence/prisma/index.d.ts +2 -2
- package/dist/persistence/prisma/index.js +2 -2
- package/dist/{plugins-C94AT8Wr.d.ts → plugins-Cl0WVVrE.d.ts} +9 -6
- package/dist/{ports-855bktyD.d.ts → ports-swhiWFw4.d.ts} +5 -106
- package/dist/{stage-BPw7m9Wx.d.ts → stage-_7BKqqUG.d.ts} +2 -2
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +25 -6
- package/dist/testing/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/workflow-engine/SKILL.md +30 -11
- package/skills/workflow-engine/references/02-workflow-builder.md +2 -0
- package/skills/workflow-engine/references/03-runtime-setup.md +1 -1
- package/skills/workflow-engine/references/08-common-patterns.md +2 -1
- package/skills/workflow-engine/references/09-troubleshooting.md +4 -3
- package/dist/chunk-PHLNTR5Z.js.map +0 -1
- package/dist/chunk-RZY5YRGL.js.map +0 -1
- package/dist/chunk-WQPZ6KON.js.map +0 -1
- package/dist/chunk-ZYMT2PAO.js.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
1
2
|
import { EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
2
3
|
import { ToolSet, generateText, StepResult, streamText } from 'ai';
|
|
3
4
|
import z$1, { z } from 'zod';
|
|
4
|
-
import { A as AICallLogger } from './interface-
|
|
5
|
-
import { b as StageContext, c as SuspendedStateSchema, C as CheckCompletionContext, d as CompletionCheckResult, S as Stage } from './stage-
|
|
5
|
+
import { A as AICallLogger } from './interface-BeEPzTFy.js';
|
|
6
|
+
import { b as StageContext, c as SuspendedStateSchema, C as CheckCompletionContext, d as CompletionCheckResult, S as Stage } from './stage-_7BKqqUG.js';
|
|
7
|
+
import './events-D_P24UaY.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Schema Helpers and Utilities
|
|
@@ -152,9 +154,9 @@ interface SimpleSuspendedResult {
|
|
|
152
154
|
/**
|
|
153
155
|
* Sync stage definition
|
|
154
156
|
*/
|
|
155
|
-
interface SyncStageDefinition<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown
|
|
157
|
+
interface SyncStageDefinition<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>, TId extends string = string> {
|
|
156
158
|
/** Unique stage identifier */
|
|
157
|
-
id:
|
|
159
|
+
id: TId;
|
|
158
160
|
/** Human-readable name */
|
|
159
161
|
name: string;
|
|
160
162
|
/** Optional description */
|
|
@@ -183,7 +185,7 @@ interface SyncStageDefinition<TInput extends z.ZodTypeAny | "none", TOutput exte
|
|
|
183
185
|
/**
|
|
184
186
|
* Async-batch stage definition (for long-running batch jobs)
|
|
185
187
|
*/
|
|
186
|
-
interface AsyncBatchStageDefinition<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown
|
|
188
|
+
interface AsyncBatchStageDefinition<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>, TId extends string = string> extends Omit<SyncStageDefinition<TInput, TOutput, TConfig, TContext, TId>, "execute"> {
|
|
187
189
|
/** Mark as async-batch mode */
|
|
188
190
|
mode: "async-batch";
|
|
189
191
|
/**
|
|
@@ -207,18 +209,18 @@ interface AsyncBatchStageDefinition<TInput extends z.ZodTypeAny | "none", TOutpu
|
|
|
207
209
|
/**
|
|
208
210
|
* Define a sync stage with simplified API
|
|
209
211
|
*/
|
|
210
|
-
declare function defineStage<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: SyncStageDefinition<TInput, TOutput, TConfig, TContext>): Stage<TInput extends "none" ? typeof NoInputSchema : TInput, TOutput, TConfig, TContext>;
|
|
212
|
+
declare function defineStage<TId extends string, TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: SyncStageDefinition<TInput, TOutput, TConfig, TContext, TId>): Stage<TInput extends "none" ? typeof NoInputSchema : TInput, TOutput, TConfig, TContext, TId>;
|
|
211
213
|
/**
|
|
212
214
|
* Define an async-batch stage with simplified API
|
|
213
215
|
*/
|
|
214
|
-
declare function defineStage<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: AsyncBatchStageDefinition<TInput, TOutput, TConfig, TContext>): Stage<TInput extends "none" ? typeof NoInputSchema : TInput, TOutput, TConfig, TContext>;
|
|
216
|
+
declare function defineStage<TId extends string, TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: AsyncBatchStageDefinition<TInput, TOutput, TConfig, TContext, TId>): Stage<TInput extends "none" ? typeof NoInputSchema : TInput, TOutput, TConfig, TContext, TId>;
|
|
215
217
|
/**
|
|
216
218
|
* Define an async-batch stage with proper type inference for checkCompletion
|
|
217
219
|
*
|
|
218
220
|
* This is a dedicated function (not an alias) to ensure TypeScript properly
|
|
219
221
|
* infers callback parameter types without overload resolution ambiguity.
|
|
220
222
|
*/
|
|
221
|
-
declare function defineAsyncBatchStage<TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: AsyncBatchStageDefinition<TInput, TOutput, TConfig, TContext>): Stage<TInput extends "none" ? typeof NoInputSchema : TInput, TOutput, TConfig, TContext>;
|
|
223
|
+
declare function defineAsyncBatchStage<TId extends string, TInput extends z.ZodTypeAny | "none", TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: AsyncBatchStageDefinition<TInput, TOutput, TConfig, TContext, TId>): Stage<TInput extends "none" ? typeof NoInputSchema : TInput, TOutput, TConfig, TContext, TId>;
|
|
222
224
|
|
|
223
225
|
/**
|
|
224
226
|
* Model Helper - Centralized model selection and cost tracking for AI scripts
|
|
@@ -389,21 +391,6 @@ declare class ModelStatsTracker {
|
|
|
389
391
|
* Perfect for parallel execution where different calls use different models
|
|
390
392
|
*/
|
|
391
393
|
static createAggregating(): ModelStatsTracker;
|
|
392
|
-
/**
|
|
393
|
-
* Get the model ID for use with AI SDK
|
|
394
|
-
* @deprecated Use getModelById(modelKey).id instead for parallel execution
|
|
395
|
-
*/
|
|
396
|
-
getModelId(): string;
|
|
397
|
-
/**
|
|
398
|
-
* Get the model configuration
|
|
399
|
-
* @deprecated Use getModelById(modelKey) instead for parallel execution
|
|
400
|
-
*/
|
|
401
|
-
getModelConfig(): ModelConfig;
|
|
402
|
-
/**
|
|
403
|
-
* Switch model (useful for sequential model switching)
|
|
404
|
-
* @deprecated For parallel execution, pass model key to recordCall() instead
|
|
405
|
-
*/
|
|
406
|
-
switchModel(modelKey: ModelKey): void;
|
|
407
394
|
/**
|
|
408
395
|
* Get a model helper with bound recordCall for parallel execution
|
|
409
396
|
* Perfect for running multiple AI calls in parallel with different models
|
|
@@ -497,23 +484,6 @@ declare class ModelStatsTracker {
|
|
|
497
484
|
*/
|
|
498
485
|
declare function printAvailableModels(): void;
|
|
499
486
|
|
|
500
|
-
/**
|
|
501
|
-
* AI Helper - Unified AI interaction tracking with hierarchical topics
|
|
502
|
-
*
|
|
503
|
-
* This is the new unified AI tracking system that replaces workflow-specific tracking.
|
|
504
|
-
* It supports:
|
|
505
|
-
* - Hierarchical topics for flexible categorization (e.g., "workflow.abc.stage.extraction")
|
|
506
|
-
* - All AI call types: generateText, generateObject, embed, streamText, batch
|
|
507
|
-
* - Automatic cost calculation with batch discounts
|
|
508
|
-
* - Persistent DB logging to AICall table
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```typescript
|
|
512
|
-
* const ai = createAIHelper("workflow.abc123").createChild("stage", "extraction");
|
|
513
|
-
* const result = await ai.generateText("gemini-2.5-flash", prompt);
|
|
514
|
-
* ```
|
|
515
|
-
*/
|
|
516
|
-
|
|
517
487
|
/**
|
|
518
488
|
* Register a custom embedding provider factory.
|
|
519
489
|
*
|
|
@@ -530,6 +500,11 @@ declare function printAvailableModels(): void;
|
|
|
530
500
|
* ```
|
|
531
501
|
*/
|
|
532
502
|
declare function registerEmbeddingProvider(providerName: string, factory: (modelId: string) => EmbeddingModelV3): void;
|
|
503
|
+
/**
|
|
504
|
+
* Custom provider resolver. Given a ModelConfig, return an AI SDK
|
|
505
|
+
* LanguageModel to use, or null/undefined to fall back to built-in resolution.
|
|
506
|
+
*/
|
|
507
|
+
type ProviderResolver = (modelConfig: ModelConfig) => _ai_sdk_provider.LanguageModelV3 | null | undefined;
|
|
533
508
|
type AICallType = "text" | "object" | "embed" | "stream" | "batch";
|
|
534
509
|
interface AITextResult {
|
|
535
510
|
text: string;
|
|
@@ -755,63 +730,6 @@ interface AIHelper {
|
|
|
755
730
|
* const result = await ai.generateText("gemini-2.5-flash", prompt);
|
|
756
731
|
* ```
|
|
757
732
|
*/
|
|
758
|
-
declare function createAIHelper(topic: string, logger: AICallLogger, logContext?: LogContext): AIHelper;
|
|
759
|
-
|
|
760
|
-
/**
|
|
761
|
-
* Workflow Event Types for SSE Streaming
|
|
762
|
-
*
|
|
763
|
-
* This file contains ONLY types and interfaces for workflow events.
|
|
764
|
-
* It is safe to use in both client and server environments.
|
|
765
|
-
*/
|
|
766
|
-
interface WorkflowSSEEvent {
|
|
767
|
-
type: WorkflowEventType;
|
|
768
|
-
workflowRunId: string;
|
|
769
|
-
timestamp: Date;
|
|
770
|
-
data: Record<string, unknown>;
|
|
771
|
-
}
|
|
772
|
-
type WorkflowEventType = "connected" | "workflow:started" | "workflow:completed" | "workflow:suspended" | "workflow:cancelled" | "workflow:failed" | "stage:started" | "stage:progress" | "stage:completed" | "stage:suspended" | "stage:failed" | "log";
|
|
773
|
-
interface WorkflowStartedPayload {
|
|
774
|
-
workflowRunId: string;
|
|
775
|
-
workflowName: string;
|
|
776
|
-
}
|
|
777
|
-
interface WorkflowCompletedPayload {
|
|
778
|
-
workflowRunId: string;
|
|
779
|
-
output: unknown;
|
|
780
|
-
duration?: number;
|
|
781
|
-
totalCost?: number;
|
|
782
|
-
totalTokens?: number;
|
|
783
|
-
}
|
|
784
|
-
interface WorkflowSuspendedPayload {
|
|
785
|
-
workflowRunId: string;
|
|
786
|
-
stageId: string;
|
|
787
|
-
}
|
|
788
|
-
interface WorkflowFailedPayload {
|
|
789
|
-
workflowRunId: string;
|
|
790
|
-
error: string;
|
|
791
|
-
}
|
|
792
|
-
interface StageStartedPayload {
|
|
793
|
-
stageId: string;
|
|
794
|
-
stageName: string;
|
|
795
|
-
stageNumber: number;
|
|
796
|
-
}
|
|
797
|
-
interface StageCompletedPayload {
|
|
798
|
-
stageId: string;
|
|
799
|
-
stageName: string;
|
|
800
|
-
duration: number;
|
|
801
|
-
cost?: number;
|
|
802
|
-
inputTokens?: number;
|
|
803
|
-
outputTokens?: number;
|
|
804
|
-
outputCount?: number;
|
|
805
|
-
}
|
|
806
|
-
interface StageFailedPayload {
|
|
807
|
-
stageId: string;
|
|
808
|
-
stageName: string;
|
|
809
|
-
error: string;
|
|
810
|
-
}
|
|
811
|
-
interface LogPayload {
|
|
812
|
-
level: string;
|
|
813
|
-
message: string;
|
|
814
|
-
meta?: Record<string, unknown>;
|
|
815
|
-
}
|
|
733
|
+
declare function createAIHelper(topic: string, logger: AICallLogger, logContext?: LogContext, providerResolver?: ProviderResolver): AIHelper;
|
|
816
734
|
|
|
817
|
-
export { type
|
|
735
|
+
export { type AIBatch as A, type BatchLogFn as B, getModelById as C, DEFAULT_MODEL_KEY as D, type EmbedOptions as E, getRegisteredModel as F, listModels as G, listRegisteredModels as H, type InferInput as I, modelSupportsBatch as J, printAvailableModels as K, type LogContext as L, ModelKey as M, NoInputSchema as N, type ObjectOptions as O, registerEmbeddingProvider as P, registerModels as Q, type RecordCallParams as R, type SimpleStageResult as S, type TextOptions as T, requireStageOutput as U, type ModelFilter as V, type AIBatchHandle as a, type AIBatchProvider as b, type AIBatchRequest as c, type AIBatchResult as d, type AICallType as e, type AIEmbedResult as f, type AIHelper as g, type AIObjectResult as h, type AIStreamResult as i, type AITextResult as j, AVAILABLE_MODELS as k, type AsyncBatchStageDefinition as l, type EnhancedStageContext as m, type ModelConfig as n, type ModelRegistry as o, type ModelStats as p, ModelStatsTracker as q, type ModelSyncConfig as r, type StreamOptions as s, type SyncStageDefinition as t, calculateCost as u, createAIHelper as v, defineAsyncBatchStage as w, defineStage as x, getDefaultModel as y, getModel as z };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { g as AIHelper, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, D as DEFAULT_MODEL_KEY, m as EnhancedStageContext, I as InferInput,
|
|
1
|
+
export { g as AIHelper, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, D as DEFAULT_MODEL_KEY, m as EnhancedStageContext, I as InferInput, n as ModelConfig, V as ModelFilter, M as ModelKey, o as ModelRegistry, N as NoInputSchema, S as SimpleStageResult, t as SyncStageDefinition, u as calculateCost, w as defineAsyncBatchStage, x as defineStage, G as listModels, J as modelSupportsBatch, Q as registerModels } from './client-DYs5wlHp.js';
|
|
2
|
+
export { K as KernelEvent, a as KernelEventType, S as StageCompletedEvent, b as StageFailedEvent, c as StageProgressEvent, d as StageStartedEvent, e as StageSuspendedEvent, W as WorkflowCancelledEvent, f as WorkflowCompletedEvent, g as WorkflowCreatedEvent, h as WorkflowFailedEvent, i as WorkflowStartedEvent, j as WorkflowSuspendedEvent } from './events-D_P24UaY.js';
|
|
2
3
|
import '@ai-sdk/provider';
|
|
3
4
|
import 'ai';
|
|
4
5
|
import 'zod';
|
|
5
|
-
import './interface-
|
|
6
|
-
import './stage-
|
|
6
|
+
import './interface-BeEPzTFy.js';
|
|
7
|
+
import './stage-_7BKqqUG.js';
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AVAILABLE_MODELS, DEFAULT_MODEL_KEY, ModelKey, NoInputSchema, calculateCost, defineAsyncBatchStage, defineStage, listModels, modelSupportsBatch, registerModels } from './chunk-
|
|
1
|
+
export { AVAILABLE_MODELS, DEFAULT_MODEL_KEY, ModelKey, NoInputSchema, calculateCost, defineAsyncBatchStage, defineStage, listModels, modelSupportsBatch, registerModels } from './chunk-WWK2SPN7.js';
|
|
2
2
|
import './chunk-MUWP5SF2.js';
|
|
3
3
|
//# sourceMappingURL=client.js.map
|
|
4
4
|
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel Event Types
|
|
3
|
+
*
|
|
4
|
+
* Discriminated union of all events emitted by the workflow kernel.
|
|
5
|
+
* Each event carries a string literal `type` discriminant, a `timestamp`,
|
|
6
|
+
* and a `workflowRunId` that scopes the event to a specific run.
|
|
7
|
+
*
|
|
8
|
+
* This file contains ONLY types -- no runtime code.
|
|
9
|
+
*/
|
|
10
|
+
/** Emitted when a new workflow run record is created. */
|
|
11
|
+
interface WorkflowCreatedEvent {
|
|
12
|
+
readonly type: "workflow:created";
|
|
13
|
+
readonly timestamp: Date;
|
|
14
|
+
readonly workflowRunId: string;
|
|
15
|
+
readonly workflowId: string;
|
|
16
|
+
}
|
|
17
|
+
/** Emitted when a workflow run begins execution. */
|
|
18
|
+
interface WorkflowStartedEvent {
|
|
19
|
+
readonly type: "workflow:started";
|
|
20
|
+
readonly timestamp: Date;
|
|
21
|
+
readonly workflowRunId: string;
|
|
22
|
+
}
|
|
23
|
+
/** Emitted when a workflow run finishes successfully. */
|
|
24
|
+
interface WorkflowCompletedEvent {
|
|
25
|
+
readonly type: "workflow:completed";
|
|
26
|
+
readonly timestamp: Date;
|
|
27
|
+
readonly workflowRunId: string;
|
|
28
|
+
readonly duration?: number;
|
|
29
|
+
readonly totalCost?: number;
|
|
30
|
+
readonly totalTokens?: number;
|
|
31
|
+
readonly output?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** Emitted when a workflow run terminates due to an unrecoverable error. */
|
|
34
|
+
interface WorkflowFailedEvent {
|
|
35
|
+
readonly type: "workflow:failed";
|
|
36
|
+
readonly timestamp: Date;
|
|
37
|
+
readonly workflowRunId: string;
|
|
38
|
+
readonly error: string;
|
|
39
|
+
}
|
|
40
|
+
/** Emitted when a workflow run is cancelled by an external request. */
|
|
41
|
+
interface WorkflowCancelledEvent {
|
|
42
|
+
readonly type: "workflow:cancelled";
|
|
43
|
+
readonly timestamp: Date;
|
|
44
|
+
readonly workflowRunId: string;
|
|
45
|
+
readonly reason?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Emitted when a workflow run suspends, waiting on an external signal. */
|
|
48
|
+
interface WorkflowSuspendedEvent {
|
|
49
|
+
readonly type: "workflow:suspended";
|
|
50
|
+
readonly timestamp: Date;
|
|
51
|
+
readonly workflowRunId: string;
|
|
52
|
+
readonly stageId: string;
|
|
53
|
+
}
|
|
54
|
+
/** Emitted when a stage begins execution. */
|
|
55
|
+
interface StageStartedEvent {
|
|
56
|
+
readonly type: "stage:started";
|
|
57
|
+
readonly timestamp: Date;
|
|
58
|
+
readonly workflowRunId: string;
|
|
59
|
+
readonly stageId: string;
|
|
60
|
+
readonly stageName: string;
|
|
61
|
+
readonly stageNumber: number;
|
|
62
|
+
}
|
|
63
|
+
/** Emitted when a stage completes successfully. */
|
|
64
|
+
interface StageCompletedEvent {
|
|
65
|
+
readonly type: "stage:completed";
|
|
66
|
+
readonly timestamp: Date;
|
|
67
|
+
readonly workflowRunId: string;
|
|
68
|
+
readonly stageId: string;
|
|
69
|
+
readonly stageName: string;
|
|
70
|
+
readonly duration: number;
|
|
71
|
+
}
|
|
72
|
+
/** Emitted when a stage suspends, awaiting a future poll. */
|
|
73
|
+
interface StageSuspendedEvent {
|
|
74
|
+
readonly type: "stage:suspended";
|
|
75
|
+
readonly timestamp: Date;
|
|
76
|
+
readonly workflowRunId: string;
|
|
77
|
+
readonly stageId: string;
|
|
78
|
+
readonly stageName: string;
|
|
79
|
+
readonly nextPollAt: Date;
|
|
80
|
+
}
|
|
81
|
+
/** Emitted when a stage fails with an error. */
|
|
82
|
+
interface StageFailedEvent {
|
|
83
|
+
readonly type: "stage:failed";
|
|
84
|
+
readonly timestamp: Date;
|
|
85
|
+
readonly workflowRunId: string;
|
|
86
|
+
readonly stageId: string;
|
|
87
|
+
readonly stageName: string;
|
|
88
|
+
readonly error: string;
|
|
89
|
+
}
|
|
90
|
+
/** Emitted to report incremental progress within a stage. */
|
|
91
|
+
interface StageProgressEvent {
|
|
92
|
+
readonly type: "stage:progress";
|
|
93
|
+
readonly timestamp: Date;
|
|
94
|
+
readonly workflowRunId: string;
|
|
95
|
+
readonly stageId: string;
|
|
96
|
+
readonly progress: number;
|
|
97
|
+
readonly message: string;
|
|
98
|
+
readonly details?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
/** Discriminated union of every kernel event. */
|
|
101
|
+
type KernelEvent = WorkflowCreatedEvent | WorkflowStartedEvent | WorkflowCompletedEvent | WorkflowFailedEvent | WorkflowCancelledEvent | WorkflowSuspendedEvent | StageStartedEvent | StageCompletedEvent | StageSuspendedEvent | StageFailedEvent | StageProgressEvent;
|
|
102
|
+
/** String literal union of all kernel event type discriminants. */
|
|
103
|
+
type KernelEventType = KernelEvent["type"];
|
|
104
|
+
|
|
105
|
+
export type { KernelEvent as K, StageCompletedEvent as S, WorkflowCancelledEvent as W, KernelEventType as a, StageFailedEvent as b, StageProgressEvent as c, StageStartedEvent as d, StageSuspendedEvent as e, WorkflowCompletedEvent as f, WorkflowCreatedEvent as g, WorkflowFailedEvent as h, WorkflowStartedEvent as i, WorkflowSuspendedEvent as j };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AICallLogger, g as CreateAICallInput, h as AIHelperStats, l as WorkflowPersistence,
|
|
1
|
+
import { A as AICallLogger, g as CreateAICallInput, h as AIHelperStats, l as WorkflowPersistence, C as CreateRunInput, W as WorkflowRunRecord, U as UpdateRunInput, m as WorkflowStatus, a as CreateStageInput, b as WorkflowStageRecord, c as UpsertStageInput, d as UpdateStageInput, n as WorkflowStageStatus, e as CreateLogInput, o as SaveArtifactInput, p as WorkflowArtifactRecord, f as CreateOutboxEventInput, O as OutboxRecord, J as JobQueue, E as EnqueueJobInput, D as DequeueResult } from './interface-BeEPzTFy.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* PrismaAICallLogger - Prisma implementation of AICallLogger
|
|
@@ -46,11 +46,17 @@ interface PrismaWorkflowPersistenceOptions {
|
|
|
46
46
|
* Set to "sqlite" when using SQLite (uses optimistic locking instead of FOR UPDATE SKIP LOCKED).
|
|
47
47
|
*/
|
|
48
48
|
databaseType?: DatabaseType;
|
|
49
|
+
/**
|
|
50
|
+
* Skip interactive transactions. Defaults to false.
|
|
51
|
+
* Set to true in single-process environments where transactions are not needed.
|
|
52
|
+
*/
|
|
53
|
+
skipInteractiveTransactions?: boolean;
|
|
49
54
|
}
|
|
50
55
|
declare class PrismaWorkflowPersistence implements WorkflowPersistence {
|
|
51
56
|
private readonly prisma;
|
|
52
57
|
private enums;
|
|
53
58
|
private databaseType;
|
|
59
|
+
private skipTransactions;
|
|
54
60
|
constructor(prisma: PrismaClient$1, options?: PrismaWorkflowPersistenceOptions);
|
|
55
61
|
withTransaction<T>(fn: (tx: WorkflowPersistence) => Promise<T>): Promise<T>;
|
|
56
62
|
createRun(data: CreateRunInput): Promise<WorkflowRunRecord>;
|
|
@@ -202,6 +208,10 @@ declare class PrismaJobQueue implements JobQueue {
|
|
|
202
208
|
stageId: string;
|
|
203
209
|
workflowRunId: string;
|
|
204
210
|
}>>;
|
|
211
|
+
/**
|
|
212
|
+
* Cancel all pending/suspended jobs for a workflow run.
|
|
213
|
+
*/
|
|
214
|
+
cancelByRun(workflowRunId: string): Promise<number>;
|
|
205
215
|
/**
|
|
206
216
|
* Release stale locks (for crashed workers)
|
|
207
217
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,190 @@
|
|
|
1
|
-
import { M as ModelKey } from './client-
|
|
2
|
-
export { A as AIBatch, a as AIBatchHandle, b as AIBatchProvider, c as AIBatchRequest, d as AIBatchResult, e as AICallType, f as AIEmbedResult, g as AIHelper, h as AIObjectResult, i as AIStreamResult, j as AITextResult, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, B as BatchLogFn, D as DEFAULT_MODEL_KEY, E as EmbedOptions, m as EnhancedStageContext, I as InferInput, L as LogContext, n as ModelConfig, o as ModelRegistry, p as ModelStats, q as ModelStatsTracker, r as ModelSyncConfig, N as NoInputSchema, O as ObjectOptions, R as RecordCallParams, S as SimpleStageResult, s as StreamOptions, t as SyncStageDefinition, T as TextOptions,
|
|
3
|
-
import { L as LogLevel } from './stage-
|
|
4
|
-
export { S as Stage, a as StageResult } from './stage-
|
|
5
|
-
|
|
1
|
+
import { M as ModelKey } from './client-DYs5wlHp.js';
|
|
2
|
+
export { A as AIBatch, a as AIBatchHandle, b as AIBatchProvider, c as AIBatchRequest, d as AIBatchResult, e as AICallType, f as AIEmbedResult, g as AIHelper, h as AIObjectResult, i as AIStreamResult, j as AITextResult, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, B as BatchLogFn, D as DEFAULT_MODEL_KEY, E as EmbedOptions, m as EnhancedStageContext, I as InferInput, L as LogContext, n as ModelConfig, o as ModelRegistry, p as ModelStats, q as ModelStatsTracker, r as ModelSyncConfig, N as NoInputSchema, O as ObjectOptions, R as RecordCallParams, S as SimpleStageResult, s as StreamOptions, t as SyncStageDefinition, T as TextOptions, u as calculateCost, v as createAIHelper, w as defineAsyncBatchStage, x as defineStage, y as getDefaultModel, z as getModel, C as getModelById, F as getRegisteredModel, G as listModels, H as listRegisteredModels, J as modelSupportsBatch, K as printAvailableModels, P as registerEmbeddingProvider, Q as registerModels, U as requireStageOutput } from './client-DYs5wlHp.js';
|
|
3
|
+
import { L as LogLevel } from './stage-_7BKqqUG.js';
|
|
4
|
+
export { S as Stage, a as StageResult } from './stage-_7BKqqUG.js';
|
|
5
|
+
import { y as Workflow } from './plugins-Cl0WVVrE.js';
|
|
6
|
+
export { C as CommandResult, I as IdempotencyInProgressError, z as InferWorkflowStageIds, J as JobExecuteCommand, a as JobExecuteResult, b as Kernel, c as KernelCommand, d as KernelCommandType, e as KernelConfig, W as KernelWorkflowRegistry, L as LeaseReapStaleCommand, f as LeaseReapStaleResult, O as OutboxFlushCommand, g as OutboxFlushResult, P as PluginDefinition, h as PluginReplayDLQCommand, i as PluginReplayDLQResult, j as PluginRunner, k as PluginRunnerConfig, R as RunCancelCommand, l as RunCancelResult, m as RunClaimPendingCommand, n as RunClaimPendingResult, o as RunCreateCommand, p as RunCreateResult, q as RunRerunFromCommand, r as RunRerunFromResult, s as RunTransitionCommand, t as RunTransitionResult, S as StagePollSuspendedCommand, u as StagePollSuspendedResult, A as WorkflowBuilder, v as createKernel, w as createPluginRunner, x as definePlugin } from './plugins-Cl0WVVrE.js';
|
|
6
7
|
import z$1, { z } from 'zod';
|
|
7
|
-
export { A as AICallLogger, i as AICallRecord, h as AIHelperStats, r as ArtifactType, g as CreateAICallInput,
|
|
8
|
-
export { P as PrismaAICallLogger, a as PrismaJobQueue, c as PrismaWorkflowPersistence, e as createPrismaAICallLogger, f as createPrismaJobQueue, g as createPrismaWorkflowPersistence } from './index-
|
|
8
|
+
export { A as AICallLogger, i as AICallRecord, h as AIHelperStats, r as ArtifactType, g as CreateAICallInput, e as CreateLogInput, f as CreateOutboxEventInput, C as CreateRunInput, a as CreateStageInput, D as DequeueResult, E as EnqueueJobInput, I as IdempotencyRecord, J as JobQueue, j as JobRecord, L as LogLevel, O as OutboxRecord, o as SaveArtifactInput, s as StaleVersionError, S as Status, U as UpdateRunInput, d as UpdateStageInput, c as UpsertStageInput, p as WorkflowArtifactRecord, q as WorkflowLogRecord, l as WorkflowPersistence, W as WorkflowRunRecord, b as WorkflowStageRecord } from './interface-BeEPzTFy.js';
|
|
9
|
+
export { P as PrismaAICallLogger, a as PrismaJobQueue, c as PrismaWorkflowPersistence, e as createPrismaAICallLogger, f as createPrismaJobQueue, g as createPrismaWorkflowPersistence } from './index-aNuJ2QgN.js';
|
|
9
10
|
import { ToolSet } from 'ai';
|
|
10
|
-
export {
|
|
11
|
+
export { K as KernelEvent, a as KernelEventType } from './events-D_P24UaY.js';
|
|
12
|
+
export { B as BlobStore, C as Clock, E as EventSink, J as JobTransport, P as Persistence, S as Scheduler } from './ports-swhiWFw4.js';
|
|
11
13
|
import '@ai-sdk/provider';
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Stage ID Utilities - Type-safe stage ID management
|
|
17
|
+
*
|
|
18
|
+
* Provides utilities for creating type-safe stage ID constants and
|
|
19
|
+
* branded types to prevent typos in stage ID references.
|
|
20
|
+
*
|
|
21
|
+
* ## Usage Patterns
|
|
22
|
+
*
|
|
23
|
+
* ### Pattern 1: Create Stage IDs from a Workflow (Recommended)
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { createStageIds } from "~/lib/workflow-v2/core/stage-ids";
|
|
27
|
+
*
|
|
28
|
+
* export const STAGE_IDS = createStageIds(certificateWorkflow);
|
|
29
|
+
* // = {
|
|
30
|
+
* // DATA_EXTRACTION: "data-extraction",
|
|
31
|
+
* // GUIDELINES: "guidelines",
|
|
32
|
+
* // GENERATOR: "generator",
|
|
33
|
+
* // } as const
|
|
34
|
+
*
|
|
35
|
+
* // Use in stage definitions
|
|
36
|
+
* dependencies: [STAGE_IDS.DATA_EXTRACTION], // Autocomplete!
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* ### Pattern 2: Define Stage IDs First (For Complex Workflows)
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* export const CERTIFICATE_STAGES = defineStageIds([
|
|
43
|
+
* "data-extraction",
|
|
44
|
+
* "guidelines",
|
|
45
|
+
* "legal-guidance",
|
|
46
|
+
* "unified-smart-retrieval",
|
|
47
|
+
* "analysis-synthesis",
|
|
48
|
+
* "generator",
|
|
49
|
+
* ] as const);
|
|
50
|
+
*
|
|
51
|
+
* // Type: { DATA_EXTRACTION: "data-extraction", ... }
|
|
52
|
+
* // With validation that stages match workflow definition
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* ### Pattern 3: Use with InferWorkflowStageIds
|
|
56
|
+
*
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import type { InferWorkflowStageIds } from "~/lib/workflow-v2/core/workflow";
|
|
59
|
+
*
|
|
60
|
+
* type CertificateStageId = InferWorkflowStageIds<typeof certificateWorkflow>;
|
|
61
|
+
* // = "data-extraction" | "guidelines" | "generator" | ...
|
|
62
|
+
*
|
|
63
|
+
* function requireStage(stageId: CertificateStageId) { ... }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Create a type-safe stage ID constants object from a workflow
|
|
69
|
+
*
|
|
70
|
+
* Extracts all stage IDs from a workflow and creates a frozen object
|
|
71
|
+
* with SCREAMING_SNAKE_CASE keys for autocomplete and type safety.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { certificateWorkflow } from "./certificate-workflow";
|
|
76
|
+
*
|
|
77
|
+
* export const STAGE_IDS = createStageIds(certificateWorkflow);
|
|
78
|
+
* // = {
|
|
79
|
+
* // DATA_EXTRACTION: "data-extraction",
|
|
80
|
+
* // GUIDELINES: "guidelines",
|
|
81
|
+
* // LEGAL_GUIDANCE: "legal-guidance",
|
|
82
|
+
* // GENERATOR: "generator",
|
|
83
|
+
* // } as const
|
|
84
|
+
*
|
|
85
|
+
* // Use in code with autocomplete:
|
|
86
|
+
* const data = ctx.require(STAGE_IDS.DATA_EXTRACTION);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function createStageIds<W extends Workflow<any, any, any>>(workflow: W): StageIdConstants<W>;
|
|
90
|
+
/**
|
|
91
|
+
* Define stage IDs from a tuple of string literals
|
|
92
|
+
*
|
|
93
|
+
* Use this when you want to define stage IDs before building the workflow,
|
|
94
|
+
* or when you need to share stage IDs across multiple files.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // Define stage IDs first
|
|
99
|
+
* export const CERTIFICATE_STAGES = defineStageIds([
|
|
100
|
+
* "data-extraction",
|
|
101
|
+
* "guidelines",
|
|
102
|
+
* "legal-guidance",
|
|
103
|
+
* "generator",
|
|
104
|
+
* ] as const);
|
|
105
|
+
*
|
|
106
|
+
* // Use in stage definitions
|
|
107
|
+
* dependencies: [CERTIFICATE_STAGES.DATA_EXTRACTION],
|
|
108
|
+
*
|
|
109
|
+
* // Type-safe access
|
|
110
|
+
* type StageId = typeof CERTIFICATE_STAGES[keyof typeof CERTIFICATE_STAGES];
|
|
111
|
+
* // = "data-extraction" | "guidelines" | ...
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function defineStageIds<const T extends readonly string[]>(stageIds: T): DefineStageIdsResult<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Validate that a stage ID exists in a workflow
|
|
117
|
+
*
|
|
118
|
+
* Use this for runtime validation when the stage ID comes from user input.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const stageId = request.params.stageId;
|
|
123
|
+
*
|
|
124
|
+
* if (!isValidStageId(certificateWorkflow, stageId)) {
|
|
125
|
+
* throw new Error(`Invalid stage ID: ${stageId}`);
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function isValidStageId<W extends Workflow<any, any, any>>(workflow: W, stageId: string): stageId is WorkflowStageId<W>;
|
|
130
|
+
/**
|
|
131
|
+
* Assert that a stage ID exists in a workflow
|
|
132
|
+
*
|
|
133
|
+
* Throws an error with helpful message if the stage ID is invalid.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* assertValidStageId(certificateWorkflow, stageId);
|
|
138
|
+
* // Now TypeScript knows stageId is a valid stage ID
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
declare function assertValidStageId<W extends Workflow<any, any, any>>(workflow: W, stageId: string): asserts stageId is WorkflowStageId<W>;
|
|
142
|
+
/**
|
|
143
|
+
* Extract stage IDs as a string union from a Workflow type
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* type StageId = WorkflowStageId<typeof certificateWorkflow>;
|
|
148
|
+
* // = "data-extraction" | "guidelines" | "generator" | ...
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
type WorkflowStageId<W extends Workflow<any, any, any>> = W extends Workflow<any, any, infer C> ? keyof C & string : never;
|
|
152
|
+
/**
|
|
153
|
+
* Result type for createStageIds function
|
|
154
|
+
*
|
|
155
|
+
* Maps each stage ID to a SCREAMING_SNAKE_CASE key.
|
|
156
|
+
*/
|
|
157
|
+
type StageIdConstants<W extends Workflow<any, any, any>> = {
|
|
158
|
+
readonly [K in WorkflowStageId<W> as Uppercase<K extends string ? ReplaceHyphens<K> : never>]: K;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Result type for defineStageIds function
|
|
162
|
+
*/
|
|
163
|
+
type DefineStageIdsResult<T extends readonly string[]> = {
|
|
164
|
+
readonly [K in T[number] as Uppercase<K extends string ? ReplaceHyphens<K> : never>]: K;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Helper type to replace hyphens with underscores
|
|
168
|
+
*/
|
|
169
|
+
type ReplaceHyphens<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Head}_${ReplaceHyphens<Tail>}` : S;
|
|
170
|
+
/**
|
|
171
|
+
* Validate that stage IDs match a workflow's expected stages
|
|
172
|
+
*
|
|
173
|
+
* Use this to ensure stage ID constants are in sync with the workflow.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // This will cause a compile error if stage IDs don't match
|
|
178
|
+
* const STAGE_IDS: ValidateStageIds<
|
|
179
|
+
* typeof certificateWorkflow,
|
|
180
|
+
* typeof CERTIFICATE_STAGES
|
|
181
|
+
* > = CERTIFICATE_STAGES;
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
type ValidateStageIds<W extends Workflow<any, any, any>, T extends Record<string, string>> = {
|
|
185
|
+
[K in keyof T]: T[K] extends WorkflowStageId<W> ? T[K] : `Error: "${T[K] & string}" is not a valid stage ID in workflow`;
|
|
186
|
+
};
|
|
187
|
+
|
|
13
188
|
/**
|
|
14
189
|
* Config Presets - Common configuration patterns for workflow stages
|
|
15
190
|
*
|
|
@@ -352,25 +527,6 @@ interface BatchStatus {
|
|
|
352
527
|
totalOutputTokens?: number;
|
|
353
528
|
}
|
|
354
529
|
type BatchState = "pending" | "processing" | "completed" | "failed" | "cancelled";
|
|
355
|
-
/**
|
|
356
|
-
* Result of a single request in a batch
|
|
357
|
-
*/
|
|
358
|
-
interface BatchResult<T> {
|
|
359
|
-
/** Index in the original request array */
|
|
360
|
-
index: number;
|
|
361
|
-
/** Custom ID if provided */
|
|
362
|
-
customId?: string;
|
|
363
|
-
/** Parsed/validated data */
|
|
364
|
-
data: T;
|
|
365
|
-
/** Input tokens used */
|
|
366
|
-
inputTokens: number;
|
|
367
|
-
/** Output tokens used */
|
|
368
|
-
outputTokens: number;
|
|
369
|
-
/** Status of this individual result */
|
|
370
|
-
status: "succeeded" | "failed";
|
|
371
|
-
/** Error message if this specific request failed */
|
|
372
|
-
error?: string;
|
|
373
|
-
}
|
|
374
530
|
/**
|
|
375
531
|
* Raw result from a provider (before schema validation)
|
|
376
532
|
*/
|
|
@@ -417,10 +573,6 @@ interface BatchRequestWithSchema<TSchema extends z.ZodTypeAny> extends BaseBatch
|
|
|
417
573
|
interface BatchRequestText extends BaseBatchRequest {
|
|
418
574
|
schema?: never;
|
|
419
575
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Union type for batch requests
|
|
422
|
-
*/
|
|
423
|
-
type BatchRequest<TSchema extends z.ZodTypeAny = z.ZodTypeAny> = BatchRequestWithSchema<TSchema> | BatchRequestText;
|
|
424
576
|
/**
|
|
425
577
|
* Interface that all batch providers must implement
|
|
426
578
|
*/
|
|
@@ -567,4 +719,4 @@ declare class OpenAIBatchProvider implements BatchProvider<OpenAIBatchRequest, R
|
|
|
567
719
|
private mapStatus;
|
|
568
720
|
}
|
|
569
721
|
|
|
570
|
-
export { type AIConfig, AIConfigSchema, AnthropicBatchProvider, type AnthropicBatchProviderConfig, type AnthropicBatchRequest, type BaseBatchRequest, type
|
|
722
|
+
export { type AIConfig, AIConfigSchema, AnthropicBatchProvider, type AnthropicBatchProviderConfig, type AnthropicBatchRequest, type BaseBatchRequest, type BatchLogger, type BatchMetrics, type BatchRequestText, type BatchRequestWithSchema, type BatchState, type BatchStatus, type BatchSubmitOptions, type ConcurrencyConfig, ConcurrencyConfigSchema, type DebugConfig, DebugConfigSchema, type FeatureFlagsConfig, FeatureFlagsConfigSchema, GoogleBatchProvider, type GoogleBatchProviderConfig, type GoogleBatchRequest, ModelKey, OpenAIBatchProvider, type OpenAIBatchProviderConfig, type OpenAIBatchRequest, type RawBatchResult, type SerializedBatch, type ValidateStageIds, Workflow, type WorkflowStageId, assertValidStageId, createStageIds, defineStageIds, getBestProviderForModel, isValidStageId, resolveModelForProvider, withAIConfig, withConcurrency, withFeatureFlags, withStandardConfig };
|