@bratsos/workflow-engine 0.0.11 → 0.2.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 +270 -513
- package/dist/chunk-D7RVRRM2.js +3 -0
- package/dist/chunk-D7RVRRM2.js.map +1 -0
- package/dist/chunk-HL3OJG7W.js +1033 -0
- package/dist/chunk-HL3OJG7W.js.map +1 -0
- package/dist/chunk-MUWP5SF2.js +33 -0
- package/dist/chunk-MUWP5SF2.js.map +1 -0
- package/dist/chunk-NYKMT46J.js +1143 -0
- package/dist/chunk-NYKMT46J.js.map +1 -0
- package/dist/chunk-P4KMGCT3.js +2292 -0
- package/dist/chunk-P4KMGCT3.js.map +1 -0
- package/dist/chunk-SPXBCZLB.js +17 -0
- package/dist/chunk-SPXBCZLB.js.map +1 -0
- package/dist/cli/sync-models.d.ts +1 -0
- package/dist/cli/sync-models.js +210 -0
- package/dist/cli/sync-models.js.map +1 -0
- package/dist/client-D4PoxADF.d.ts +798 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +4 -0
- package/dist/client.js.map +1 -0
- package/dist/index-DAzCfO1R.d.ts +217 -0
- package/dist/index.d.ts +569 -0
- package/dist/index.js +399 -0
- package/dist/index.js.map +1 -0
- package/dist/interface-MMqhfQQK.d.ts +411 -0
- package/dist/kernel/index.d.ts +26 -0
- package/dist/kernel/index.js +3 -0
- package/dist/kernel/index.js.map +1 -0
- package/dist/kernel/testing/index.d.ts +44 -0
- package/dist/kernel/testing/index.js +85 -0
- package/dist/kernel/testing/index.js.map +1 -0
- package/dist/persistence/index.d.ts +2 -0
- package/dist/persistence/index.js +6 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/prisma/index.d.ts +37 -0
- package/dist/persistence/prisma/index.js +5 -0
- package/dist/persistence/prisma/index.js.map +1 -0
- package/dist/plugins-BCnDUwIc.d.ts +415 -0
- package/dist/ports-tU3rzPXJ.d.ts +245 -0
- package/dist/stage-BPw7m9Wx.d.ts +144 -0
- package/dist/testing/index.d.ts +264 -0
- package/dist/testing/index.js +920 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +11 -1
- package/skills/workflow-engine/SKILL.md +234 -348
- package/skills/workflow-engine/references/03-runtime-setup.md +111 -426
- package/skills/workflow-engine/references/05-persistence-setup.md +32 -0
- package/skills/workflow-engine/references/07-testing-patterns.md +141 -474
- package/skills/workflow-engine/references/08-common-patterns.md +118 -431
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { g as AIHelper, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, D as DEFAULT_MODEL_KEY, m as EnhancedStageContext, I as InferInput, V as LogPayload, n as ModelConfig, X as ModelFilter, M as ModelKey, o as ModelRegistry, N as NoInputSchema, S as SimpleStageResult, Y as StageCompletedPayload, Z as StageFailedPayload, _ as StageStartedPayload, t as SyncStageDefinition, $ as WorkflowCompletedPayload, W as WorkflowEventType, a0 as WorkflowFailedPayload, u as WorkflowSSEEvent, a1 as WorkflowStartedPayload, a2 as WorkflowSuspendedPayload, v as calculateCost, x as defineAsyncBatchStage, y as defineStage, H as listModels, K as modelSupportsBatch, Q as registerModels } from './client-D4PoxADF.js';
|
|
2
|
+
import 'ai';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import './interface-MMqhfQQK.js';
|
|
5
|
+
import './stage-BPw7m9Wx.js';
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AVAILABLE_MODELS, DEFAULT_MODEL_KEY, ModelKey, NoInputSchema, calculateCost, defineAsyncBatchStage, defineStage, listModels, modelSupportsBatch, registerModels } from './chunk-P4KMGCT3.js';
|
|
2
|
+
import './chunk-MUWP5SF2.js';
|
|
3
|
+
//# sourceMappingURL=client.js.map
|
|
4
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"client.js"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { A as AICallLogger, g as CreateAICallInput, h as AIHelperStats, l as WorkflowPersistence, a as CreateRunInput, W as WorkflowRunRecord, U as UpdateRunInput, m as WorkflowStatus, b as CreateStageInput, c as WorkflowStageRecord, d as UpsertStageInput, e as UpdateStageInput, n as WorkflowStageStatus, f as CreateLogInput, o as SaveArtifactInput, p as WorkflowArtifactRecord, C as CreateOutboxEventInput, O as OutboxRecord, J as JobQueue, E as EnqueueJobInput, D as DequeueResult } from './interface-MMqhfQQK.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PrismaAICallLogger - Prisma implementation of AICallLogger
|
|
5
|
+
*
|
|
6
|
+
* Handles AI call logging to the database. Uses fire-and-forget pattern
|
|
7
|
+
* for non-blocking logging during AI operations.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type PrismaClient$2 = any;
|
|
11
|
+
declare class PrismaAICallLogger implements AICallLogger {
|
|
12
|
+
private readonly prisma;
|
|
13
|
+
constructor(prisma: PrismaClient$2);
|
|
14
|
+
/**
|
|
15
|
+
* Log a single AI call (fire and forget)
|
|
16
|
+
* Does not await - logs asynchronously to avoid blocking AI operations
|
|
17
|
+
*/
|
|
18
|
+
logCall(call: CreateAICallInput): void;
|
|
19
|
+
/**
|
|
20
|
+
* Log batch results (for recording batch API results)
|
|
21
|
+
*/
|
|
22
|
+
logBatchResults(batchId: string, results: CreateAICallInput[]): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Get aggregated stats for a topic prefix
|
|
25
|
+
*/
|
|
26
|
+
getStats(topicPrefix: string): Promise<AIHelperStats>;
|
|
27
|
+
/**
|
|
28
|
+
* Check if batch results are already recorded
|
|
29
|
+
*/
|
|
30
|
+
isRecorded(batchId: string): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
declare function createPrismaAICallLogger(prisma: PrismaClient$2): AICallLogger;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* PrismaWorkflowPersistence - Prisma implementation of WorkflowPersistence
|
|
36
|
+
*
|
|
37
|
+
* This is the default persistence implementation used by the workflow engine.
|
|
38
|
+
* It wraps Prisma client operations to match the WorkflowPersistence interface.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
type PrismaClient$1 = any;
|
|
42
|
+
type DatabaseType = "postgresql" | "sqlite";
|
|
43
|
+
interface PrismaWorkflowPersistenceOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Database type. Defaults to "postgresql".
|
|
46
|
+
* Set to "sqlite" when using SQLite (uses optimistic locking instead of FOR UPDATE SKIP LOCKED).
|
|
47
|
+
*/
|
|
48
|
+
databaseType?: DatabaseType;
|
|
49
|
+
}
|
|
50
|
+
declare class PrismaWorkflowPersistence implements WorkflowPersistence {
|
|
51
|
+
private readonly prisma;
|
|
52
|
+
private enums;
|
|
53
|
+
private databaseType;
|
|
54
|
+
constructor(prisma: PrismaClient$1, options?: PrismaWorkflowPersistenceOptions);
|
|
55
|
+
withTransaction<T>(fn: (tx: WorkflowPersistence) => Promise<T>): Promise<T>;
|
|
56
|
+
createRun(data: CreateRunInput): Promise<WorkflowRunRecord>;
|
|
57
|
+
updateRun(id: string, data: UpdateRunInput): Promise<void>;
|
|
58
|
+
getRun(id: string): Promise<WorkflowRunRecord | null>;
|
|
59
|
+
getRunStatus(id: string): Promise<WorkflowStatus | null>;
|
|
60
|
+
getRunsByStatus(status: WorkflowStatus): Promise<WorkflowRunRecord[]>;
|
|
61
|
+
claimPendingRun(id: string): Promise<boolean>;
|
|
62
|
+
claimNextPendingRun(): Promise<WorkflowRunRecord | null>;
|
|
63
|
+
/**
|
|
64
|
+
* PostgreSQL implementation using FOR UPDATE SKIP LOCKED for zero-contention claiming.
|
|
65
|
+
* This atomically:
|
|
66
|
+
* 1. Finds the highest priority PENDING run (FIFO within same priority)
|
|
67
|
+
* 2. Locks it exclusively (other workers skip locked rows)
|
|
68
|
+
* 3. Updates it to RUNNING
|
|
69
|
+
* 4. Returns the claimed run
|
|
70
|
+
*/
|
|
71
|
+
private claimNextPendingRunPostgres;
|
|
72
|
+
/**
|
|
73
|
+
* SQLite implementation using optimistic locking.
|
|
74
|
+
* SQLite doesn't support FOR UPDATE SKIP LOCKED, so we use a two-step approach:
|
|
75
|
+
* 1. Find a PENDING run
|
|
76
|
+
* 2. Atomically update it (only succeeds if still PENDING)
|
|
77
|
+
* 3. If another worker claimed it, retry
|
|
78
|
+
*/
|
|
79
|
+
private claimNextPendingRunSqlite;
|
|
80
|
+
createStage(data: CreateStageInput): Promise<WorkflowStageRecord>;
|
|
81
|
+
upsertStage(data: UpsertStageInput): Promise<WorkflowStageRecord>;
|
|
82
|
+
updateStage(id: string, data: UpdateStageInput): Promise<void>;
|
|
83
|
+
updateStageByRunAndStageId(workflowRunId: string, stageId: string, data: UpdateStageInput): Promise<void>;
|
|
84
|
+
private buildRunUpdateData;
|
|
85
|
+
private buildStageUpdateData;
|
|
86
|
+
getStage(runId: string, stageId: string): Promise<WorkflowStageRecord | null>;
|
|
87
|
+
getStageById(id: string): Promise<WorkflowStageRecord | null>;
|
|
88
|
+
getStagesByRun(runId: string, options?: {
|
|
89
|
+
status?: WorkflowStageStatus;
|
|
90
|
+
orderBy?: "asc" | "desc";
|
|
91
|
+
}): Promise<WorkflowStageRecord[]>;
|
|
92
|
+
getSuspendedStages(beforeDate: Date): Promise<WorkflowStageRecord[]>;
|
|
93
|
+
getFirstSuspendedStageReadyToResume(runId: string): Promise<WorkflowStageRecord | null>;
|
|
94
|
+
getFirstFailedStage(runId: string): Promise<WorkflowStageRecord | null>;
|
|
95
|
+
getLastCompletedStage(runId: string): Promise<WorkflowStageRecord | null>;
|
|
96
|
+
getLastCompletedStageBefore(runId: string, executionGroup: number): Promise<WorkflowStageRecord | null>;
|
|
97
|
+
deleteStage(id: string): Promise<void>;
|
|
98
|
+
createLog(data: CreateLogInput): Promise<void>;
|
|
99
|
+
saveArtifact(data: SaveArtifactInput): Promise<void>;
|
|
100
|
+
loadArtifact(runId: string, key: string): Promise<unknown>;
|
|
101
|
+
hasArtifact(runId: string, key: string): Promise<boolean>;
|
|
102
|
+
deleteArtifact(runId: string, key: string): Promise<void>;
|
|
103
|
+
listArtifacts(runId: string): Promise<WorkflowArtifactRecord[]>;
|
|
104
|
+
getStageIdForArtifact(runId: string, stageId: string): Promise<string | null>;
|
|
105
|
+
saveStageOutput(runId: string, workflowType: string, stageId: string, output: unknown): Promise<string>;
|
|
106
|
+
appendOutboxEvents(events: CreateOutboxEventInput[]): Promise<void>;
|
|
107
|
+
getUnpublishedOutboxEvents(limit?: number): Promise<OutboxRecord[]>;
|
|
108
|
+
markOutboxEventsPublished(ids: string[]): Promise<void>;
|
|
109
|
+
incrementOutboxRetryCount(id: string): Promise<number>;
|
|
110
|
+
moveOutboxEventToDLQ(id: string): Promise<void>;
|
|
111
|
+
replayDLQEvents(maxEvents: number): Promise<number>;
|
|
112
|
+
acquireIdempotencyKey(key: string, commandType: string): Promise<{
|
|
113
|
+
status: "acquired";
|
|
114
|
+
} | {
|
|
115
|
+
status: "replay";
|
|
116
|
+
result: unknown;
|
|
117
|
+
} | {
|
|
118
|
+
status: "in_progress";
|
|
119
|
+
}>;
|
|
120
|
+
completeIdempotencyKey(key: string, commandType: string, result: unknown): Promise<void>;
|
|
121
|
+
releaseIdempotencyKey(key: string, commandType: string): Promise<void>;
|
|
122
|
+
private mapWorkflowRun;
|
|
123
|
+
private mapWorkflowStage;
|
|
124
|
+
private mapOutboxEvent;
|
|
125
|
+
private mapWorkflowArtifact;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Factory function to create PrismaWorkflowPersistence
|
|
129
|
+
*/
|
|
130
|
+
declare function createPrismaWorkflowPersistence(prisma: PrismaClient$1, options?: PrismaWorkflowPersistenceOptions): PrismaWorkflowPersistence;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* PrismaJobQueue - Prisma implementation of JobQueue
|
|
134
|
+
*
|
|
135
|
+
* Provides atomic job queue operations using PostgreSQL
|
|
136
|
+
* with FOR UPDATE SKIP LOCKED for safe concurrent access.
|
|
137
|
+
*
|
|
138
|
+
* This is migrated from the original services/job-queue.server.ts
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
type PrismaClient = any;
|
|
142
|
+
interface PrismaJobQueueOptions {
|
|
143
|
+
/**
|
|
144
|
+
* Unique worker identifier. Defaults to auto-generated ID.
|
|
145
|
+
*/
|
|
146
|
+
workerId?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Database type. Defaults to "postgresql".
|
|
149
|
+
* Set to "sqlite" when using SQLite (uses optimistic locking instead of FOR UPDATE SKIP LOCKED).
|
|
150
|
+
*/
|
|
151
|
+
databaseType?: DatabaseType;
|
|
152
|
+
}
|
|
153
|
+
declare class PrismaJobQueue implements JobQueue {
|
|
154
|
+
private workerId;
|
|
155
|
+
private prisma;
|
|
156
|
+
private enums;
|
|
157
|
+
private databaseType;
|
|
158
|
+
constructor(prisma: PrismaClient, options?: PrismaJobQueueOptions);
|
|
159
|
+
/**
|
|
160
|
+
* Add a new job to the queue
|
|
161
|
+
*/
|
|
162
|
+
enqueue(options: EnqueueJobInput): Promise<string>;
|
|
163
|
+
/**
|
|
164
|
+
* Enqueue multiple stages in parallel (same execution group)
|
|
165
|
+
*/
|
|
166
|
+
enqueueParallel(jobs: EnqueueJobInput[]): Promise<string[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Atomically dequeue the next available job
|
|
169
|
+
* Uses FOR UPDATE SKIP LOCKED (PostgreSQL) or optimistic locking (SQLite)
|
|
170
|
+
*/
|
|
171
|
+
dequeue(): Promise<DequeueResult | null>;
|
|
172
|
+
/**
|
|
173
|
+
* PostgreSQL implementation using FOR UPDATE SKIP LOCKED for safe concurrency
|
|
174
|
+
*/
|
|
175
|
+
private dequeuePostgres;
|
|
176
|
+
/**
|
|
177
|
+
* SQLite implementation using optimistic locking.
|
|
178
|
+
* SQLite doesn't support FOR UPDATE SKIP LOCKED, so we use a two-step approach:
|
|
179
|
+
* 1. Find a PENDING job
|
|
180
|
+
* 2. Atomically update it (only succeeds if still PENDING)
|
|
181
|
+
* 3. If another worker claimed it, retry
|
|
182
|
+
*/
|
|
183
|
+
private dequeueSqlite;
|
|
184
|
+
/**
|
|
185
|
+
* Mark job as completed
|
|
186
|
+
*/
|
|
187
|
+
complete(jobId: string): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Mark job as suspended (for async-batch)
|
|
190
|
+
*/
|
|
191
|
+
suspend(jobId: string, nextPollAt: Date): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Mark job as failed
|
|
194
|
+
*/
|
|
195
|
+
fail(jobId: string, error: string, shouldRetry?: boolean): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Get suspended jobs that are ready to be checked
|
|
198
|
+
*/
|
|
199
|
+
getSuspendedJobsReadyToPoll(): Promise<Array<{
|
|
200
|
+
jobId: string;
|
|
201
|
+
stageId: string;
|
|
202
|
+
workflowRunId: string;
|
|
203
|
+
}>>;
|
|
204
|
+
/**
|
|
205
|
+
* Release stale locks (for crashed workers)
|
|
206
|
+
*/
|
|
207
|
+
releaseStaleJobs(staleThresholdMs?: number): Promise<number>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Factory function to create PrismaJobQueue with prisma client
|
|
211
|
+
*
|
|
212
|
+
* @param prisma - Prisma client instance
|
|
213
|
+
* @param optionsOrWorkerId - Options object or workerId string (for backwards compatibility)
|
|
214
|
+
*/
|
|
215
|
+
declare function createPrismaJobQueue(prisma: PrismaClient, optionsOrWorkerId?: PrismaJobQueueOptions | string): JobQueue;
|
|
216
|
+
|
|
217
|
+
export { type DatabaseType as D, PrismaAICallLogger as P, PrismaJobQueue as a, type PrismaJobQueueOptions as b, PrismaWorkflowPersistence as c, type PrismaWorkflowPersistenceOptions as d, createPrismaAICallLogger as e, createPrismaJobQueue as f, createPrismaWorkflowPersistence as g };
|