@elsium-ai/workflows 0.1.6
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 +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +334 -0
- package/dist/step.d.ts +4 -0
- package/dist/step.d.ts.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workflow.d.ts +18 -0
- package/dist/workflow.d.ts.map +1 -0
- package/package.json +36 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { step, executeStep } from './step';
|
|
2
|
+
export { defineWorkflow, defineParallelWorkflow, defineBranchWorkflow } from './workflow';
|
|
3
|
+
export type { Workflow, ParallelWorkflowConfig, BranchConfig } from './workflow';
|
|
4
|
+
export type { StepConfig, StepContext, StepResult, StepStatus, RetryConfig, WorkflowConfig, WorkflowResult, WorkflowStatus, WorkflowRunOptions, } from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAG1C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACzF,YAAY,EAAE,QAAQ,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGhF,YAAY,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GAClB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../core/src/errors.ts
|
|
3
|
+
class ElsiumError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
provider;
|
|
6
|
+
model;
|
|
7
|
+
statusCode;
|
|
8
|
+
retryable;
|
|
9
|
+
retryAfterMs;
|
|
10
|
+
cause;
|
|
11
|
+
metadata;
|
|
12
|
+
constructor(details) {
|
|
13
|
+
super(details.message);
|
|
14
|
+
this.name = "ElsiumError";
|
|
15
|
+
this.code = details.code;
|
|
16
|
+
this.provider = details.provider;
|
|
17
|
+
this.model = details.model;
|
|
18
|
+
this.statusCode = details.statusCode;
|
|
19
|
+
this.retryable = details.retryable;
|
|
20
|
+
this.retryAfterMs = details.retryAfterMs;
|
|
21
|
+
this.cause = details.cause;
|
|
22
|
+
this.metadata = details.metadata;
|
|
23
|
+
}
|
|
24
|
+
toJSON() {
|
|
25
|
+
return {
|
|
26
|
+
name: this.name,
|
|
27
|
+
code: this.code,
|
|
28
|
+
message: this.message,
|
|
29
|
+
provider: this.provider,
|
|
30
|
+
model: this.model,
|
|
31
|
+
statusCode: this.statusCode,
|
|
32
|
+
retryable: this.retryable,
|
|
33
|
+
retryAfterMs: this.retryAfterMs,
|
|
34
|
+
metadata: this.metadata
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
static providerError(message, opts) {
|
|
38
|
+
return new ElsiumError({
|
|
39
|
+
code: "PROVIDER_ERROR",
|
|
40
|
+
message,
|
|
41
|
+
provider: opts.provider,
|
|
42
|
+
statusCode: opts.statusCode,
|
|
43
|
+
retryable: opts.retryable ?? false,
|
|
44
|
+
cause: opts.cause
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
static rateLimit(provider, retryAfterMs) {
|
|
48
|
+
return new ElsiumError({
|
|
49
|
+
code: "RATE_LIMIT",
|
|
50
|
+
message: `Rate limited by ${provider}`,
|
|
51
|
+
provider,
|
|
52
|
+
statusCode: 429,
|
|
53
|
+
retryable: true,
|
|
54
|
+
retryAfterMs
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
static authError(provider) {
|
|
58
|
+
return new ElsiumError({
|
|
59
|
+
code: "AUTH_ERROR",
|
|
60
|
+
message: `Authentication failed for ${provider}. Check your API key.`,
|
|
61
|
+
provider,
|
|
62
|
+
statusCode: 401,
|
|
63
|
+
retryable: false
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
static timeout(provider, timeoutMs) {
|
|
67
|
+
return new ElsiumError({
|
|
68
|
+
code: "TIMEOUT",
|
|
69
|
+
message: `Request to ${provider} timed out after ${timeoutMs}ms`,
|
|
70
|
+
provider,
|
|
71
|
+
retryable: true
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
static validation(message, metadata) {
|
|
75
|
+
return new ElsiumError({
|
|
76
|
+
code: "VALIDATION_ERROR",
|
|
77
|
+
message,
|
|
78
|
+
retryable: false,
|
|
79
|
+
metadata
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static budgetExceeded(spent, budget) {
|
|
83
|
+
return new ElsiumError({
|
|
84
|
+
code: "BUDGET_EXCEEDED",
|
|
85
|
+
message: `Token budget exceeded: spent ${spent}, budget ${budget}`,
|
|
86
|
+
retryable: false,
|
|
87
|
+
metadata: { spent, budget }
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// ../core/src/utils.ts
|
|
92
|
+
async function sleep(ms) {
|
|
93
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
94
|
+
}
|
|
95
|
+
// src/step.ts
|
|
96
|
+
function step(name, config) {
|
|
97
|
+
return { name, ...config };
|
|
98
|
+
}
|
|
99
|
+
function validateInput(stepConfig, rawInput, startTime) {
|
|
100
|
+
if (!stepConfig.input)
|
|
101
|
+
return null;
|
|
102
|
+
const parsed = stepConfig.input.safeParse(rawInput);
|
|
103
|
+
if (parsed.success)
|
|
104
|
+
return null;
|
|
105
|
+
return {
|
|
106
|
+
name: stepConfig.name,
|
|
107
|
+
status: "failed",
|
|
108
|
+
error: `Input validation failed: ${parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join(", ")}`,
|
|
109
|
+
durationMs: Math.round(performance.now() - startTime),
|
|
110
|
+
retryCount: 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function checkCondition(stepConfig, input, context, startTime) {
|
|
114
|
+
if (!stepConfig.condition || stepConfig.condition(input, context))
|
|
115
|
+
return null;
|
|
116
|
+
return {
|
|
117
|
+
name: stepConfig.name,
|
|
118
|
+
status: "skipped",
|
|
119
|
+
durationMs: Math.round(performance.now() - startTime),
|
|
120
|
+
retryCount: 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function tryFallback(stepConfig, err2, input, startTime, retryCount) {
|
|
124
|
+
if (!stepConfig.fallback) {
|
|
125
|
+
return {
|
|
126
|
+
name: stepConfig.name,
|
|
127
|
+
status: "failed",
|
|
128
|
+
error: err2.message,
|
|
129
|
+
durationMs: Math.round(performance.now() - startTime),
|
|
130
|
+
retryCount
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const fallbackResult = await stepConfig.fallback(err2, input);
|
|
135
|
+
return {
|
|
136
|
+
name: stepConfig.name,
|
|
137
|
+
status: "completed",
|
|
138
|
+
data: fallbackResult,
|
|
139
|
+
durationMs: Math.round(performance.now() - startTime),
|
|
140
|
+
retryCount
|
|
141
|
+
};
|
|
142
|
+
} catch (fallbackError) {
|
|
143
|
+
return {
|
|
144
|
+
name: stepConfig.name,
|
|
145
|
+
status: "failed",
|
|
146
|
+
error: `Fallback failed: ${fallbackError instanceof Error ? fallbackError.message : String(fallbackError)}`,
|
|
147
|
+
durationMs: Math.round(performance.now() - startTime),
|
|
148
|
+
retryCount
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function executeStep(stepConfig, rawInput, context) {
|
|
153
|
+
const startTime = performance.now();
|
|
154
|
+
let retryCount = 0;
|
|
155
|
+
const validationError = validateInput(stepConfig, rawInput, startTime);
|
|
156
|
+
if (validationError)
|
|
157
|
+
return validationError;
|
|
158
|
+
const input = rawInput;
|
|
159
|
+
const conditionSkip = checkCondition(stepConfig, input, context, startTime);
|
|
160
|
+
if (conditionSkip)
|
|
161
|
+
return conditionSkip;
|
|
162
|
+
const retryConfig = stepConfig.retry;
|
|
163
|
+
const maxRetries = retryConfig?.maxRetries ?? 0;
|
|
164
|
+
while (true) {
|
|
165
|
+
try {
|
|
166
|
+
const result = await executeWithTimeout(() => stepConfig.handler(input, context), stepConfig.timeoutMs, stepConfig.name);
|
|
167
|
+
return {
|
|
168
|
+
name: stepConfig.name,
|
|
169
|
+
status: "completed",
|
|
170
|
+
data: result,
|
|
171
|
+
durationMs: Math.round(performance.now() - startTime),
|
|
172
|
+
retryCount
|
|
173
|
+
};
|
|
174
|
+
} catch (error) {
|
|
175
|
+
const err2 = error instanceof Error ? error : new Error(String(error));
|
|
176
|
+
if (retryCount < maxRetries && shouldRetryError(err2, retryConfig)) {
|
|
177
|
+
retryCount++;
|
|
178
|
+
const delay = calculateBackoff(retryCount, retryConfig);
|
|
179
|
+
await sleep(delay);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
return tryFallback(stepConfig, err2, input, startTime, retryCount);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function executeWithTimeout(fn, timeoutMs, stepName) {
|
|
187
|
+
if (!timeoutMs)
|
|
188
|
+
return fn();
|
|
189
|
+
const controller = new AbortController;
|
|
190
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
191
|
+
try {
|
|
192
|
+
return await Promise.race([
|
|
193
|
+
fn(),
|
|
194
|
+
new Promise((_, reject) => {
|
|
195
|
+
controller.signal.addEventListener("abort", () => {
|
|
196
|
+
reject(ElsiumError.timeout(stepName, timeoutMs));
|
|
197
|
+
});
|
|
198
|
+
})
|
|
199
|
+
]);
|
|
200
|
+
} finally {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function shouldRetryError(error, config) {
|
|
205
|
+
if (!config)
|
|
206
|
+
return false;
|
|
207
|
+
if (config.shouldRetry)
|
|
208
|
+
return config.shouldRetry(error);
|
|
209
|
+
if (error instanceof ElsiumError)
|
|
210
|
+
return error.retryable;
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
function calculateBackoff(attempt, config) {
|
|
214
|
+
const baseDelay = config?.baseDelayMs ?? 1000;
|
|
215
|
+
const maxDelay = config?.maxDelayMs ?? 30000;
|
|
216
|
+
const delay = Math.min(baseDelay * 2 ** (attempt - 1), maxDelay);
|
|
217
|
+
return delay * (0.5 + Math.random() * 0.5);
|
|
218
|
+
}
|
|
219
|
+
// src/workflow.ts
|
|
220
|
+
function defineWorkflow(config) {
|
|
221
|
+
return {
|
|
222
|
+
name: config.name,
|
|
223
|
+
async run(input, options) {
|
|
224
|
+
const startTime = performance.now();
|
|
225
|
+
const stepResults = [];
|
|
226
|
+
const outputs = {};
|
|
227
|
+
let currentInput = input;
|
|
228
|
+
for (let i = 0;i < config.steps.length; i++) {
|
|
229
|
+
const stepConfig = config.steps[i];
|
|
230
|
+
const context = {
|
|
231
|
+
workflowName: config.name,
|
|
232
|
+
stepIndex: i,
|
|
233
|
+
previousOutputs: { ...outputs },
|
|
234
|
+
signal: options?.signal
|
|
235
|
+
};
|
|
236
|
+
const result = await executeStep(stepConfig, currentInput, context);
|
|
237
|
+
stepResults.push(result);
|
|
238
|
+
if (result.status === "completed" && result.data !== undefined) {
|
|
239
|
+
outputs[stepConfig.name] = result.data;
|
|
240
|
+
currentInput = result.data;
|
|
241
|
+
}
|
|
242
|
+
await config.onStepComplete?.(result);
|
|
243
|
+
if (result.status === "failed") {
|
|
244
|
+
await config.onStepError?.(new Error(result.error ?? "Step failed"), stepConfig.name);
|
|
245
|
+
const workflowResult2 = {
|
|
246
|
+
name: config.name,
|
|
247
|
+
status: "failed",
|
|
248
|
+
steps: stepResults,
|
|
249
|
+
totalDurationMs: Math.round(performance.now() - startTime),
|
|
250
|
+
outputs
|
|
251
|
+
};
|
|
252
|
+
await config.onComplete?.(workflowResult2);
|
|
253
|
+
return workflowResult2;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const workflowResult = {
|
|
257
|
+
name: config.name,
|
|
258
|
+
status: "completed",
|
|
259
|
+
steps: stepResults,
|
|
260
|
+
totalDurationMs: Math.round(performance.now() - startTime),
|
|
261
|
+
outputs
|
|
262
|
+
};
|
|
263
|
+
await config.onComplete?.(workflowResult);
|
|
264
|
+
return workflowResult;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function defineParallelWorkflow(config) {
|
|
269
|
+
return {
|
|
270
|
+
name: config.name,
|
|
271
|
+
async run(input, options) {
|
|
272
|
+
const startTime = performance.now();
|
|
273
|
+
const resultPromises = config.steps.map((stepConfig, i) => {
|
|
274
|
+
const context = {
|
|
275
|
+
workflowName: config.name,
|
|
276
|
+
stepIndex: i,
|
|
277
|
+
previousOutputs: {},
|
|
278
|
+
signal: options?.signal
|
|
279
|
+
};
|
|
280
|
+
return executeStep(stepConfig, input, context);
|
|
281
|
+
});
|
|
282
|
+
const stepResults = await Promise.all(resultPromises);
|
|
283
|
+
const outputs = {};
|
|
284
|
+
let failed = false;
|
|
285
|
+
for (let i = 0;i < stepResults.length; i++) {
|
|
286
|
+
const result = stepResults[i];
|
|
287
|
+
if (result.status === "completed" && result.data !== undefined) {
|
|
288
|
+
outputs[config.steps[i].name] = result.data;
|
|
289
|
+
}
|
|
290
|
+
if (result.status === "failed") {
|
|
291
|
+
failed = true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const workflowResult = {
|
|
295
|
+
name: config.name,
|
|
296
|
+
status: failed ? "failed" : "completed",
|
|
297
|
+
steps: stepResults,
|
|
298
|
+
totalDurationMs: Math.round(performance.now() - startTime),
|
|
299
|
+
outputs
|
|
300
|
+
};
|
|
301
|
+
await config.onComplete?.(workflowResult);
|
|
302
|
+
return workflowResult;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function defineBranchWorkflow(name, branches, fallback) {
|
|
307
|
+
return {
|
|
308
|
+
name,
|
|
309
|
+
async run(input, options) {
|
|
310
|
+
for (const branch of branches) {
|
|
311
|
+
if (branch.condition(input)) {
|
|
312
|
+
return branch.workflow.run(input, options);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (fallback) {
|
|
316
|
+
return fallback.run(input, options);
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
name,
|
|
320
|
+
status: "completed",
|
|
321
|
+
steps: [],
|
|
322
|
+
totalDurationMs: 0,
|
|
323
|
+
outputs: {}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
export {
|
|
329
|
+
step,
|
|
330
|
+
executeStep,
|
|
331
|
+
defineWorkflow,
|
|
332
|
+
defineParallelWorkflow,
|
|
333
|
+
defineBranchWorkflow
|
|
334
|
+
};
|
package/dist/step.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StepConfig, StepContext, StepResult } from './types';
|
|
2
|
+
export declare function step<TInput, TOutput>(name: string, config: Omit<StepConfig<TInput, TOutput>, 'name'>): StepConfig<TInput, TOutput>;
|
|
3
|
+
export declare function executeStep<TInput, TOutput>(stepConfig: StepConfig<TInput, TOutput>, rawInput: unknown, context: StepContext): Promise<StepResult<TOutput>>;
|
|
4
|
+
//# sourceMappingURL=step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../src/step.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/E,wBAAgB,IAAI,CAAC,MAAM,EAAE,OAAO,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,GAC/C,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAE7B;AA0ED,wBAAsB,WAAW,CAAC,MAAM,EAAE,OAAO,EAChD,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,WAAW,GAClB,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CA2C9B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
export type StepStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
|
|
3
|
+
export interface StepConfig<TInput = unknown, TOutput = unknown> {
|
|
4
|
+
name: string;
|
|
5
|
+
input?: z.ZodType<TInput>;
|
|
6
|
+
handler: (input: TInput, context: StepContext) => Promise<TOutput>;
|
|
7
|
+
retry?: RetryConfig;
|
|
8
|
+
condition?: (input: TInput, context: StepContext) => boolean;
|
|
9
|
+
fallback?: (error: Error, input: TInput) => Promise<TOutput>;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface StepContext {
|
|
13
|
+
workflowName: string;
|
|
14
|
+
stepIndex: number;
|
|
15
|
+
previousOutputs: Record<string, unknown>;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
export interface StepResult<T = unknown> {
|
|
19
|
+
name: string;
|
|
20
|
+
status: StepStatus;
|
|
21
|
+
data?: T;
|
|
22
|
+
error?: string;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
retryCount: number;
|
|
25
|
+
}
|
|
26
|
+
export interface RetryConfig {
|
|
27
|
+
maxRetries: number;
|
|
28
|
+
baseDelayMs?: number;
|
|
29
|
+
maxDelayMs?: number;
|
|
30
|
+
shouldRetry?: (error: Error) => boolean;
|
|
31
|
+
}
|
|
32
|
+
export type WorkflowStatus = 'pending' | 'running' | 'completed' | 'failed';
|
|
33
|
+
export interface WorkflowConfig {
|
|
34
|
+
name: string;
|
|
35
|
+
steps: StepConfig[];
|
|
36
|
+
onStepComplete?: (result: StepResult) => void | Promise<void>;
|
|
37
|
+
onStepError?: (error: Error, stepName: string) => void | Promise<void>;
|
|
38
|
+
onComplete?: (result: WorkflowResult) => void | Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export interface WorkflowResult {
|
|
41
|
+
name: string;
|
|
42
|
+
status: WorkflowStatus;
|
|
43
|
+
steps: StepResult[];
|
|
44
|
+
totalDurationMs: number;
|
|
45
|
+
outputs: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export interface WorkflowRunOptions {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAI5B,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEnF,MAAM,WAAW,UAAU,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC9D,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACzB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAClE,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAA;IAC5D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC,MAAM,CAAC,EAAE,WAAW,CAAA;CACpB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,CAAC,EAAE,CAAC,CAAA;IACR,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAID,MAAM,WAAW,WAAW;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAA;CACvC;AAID,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;AAE3E,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtE,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7D;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,cAAc,CAAA;IACtB,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,kBAAkB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAA;CACpB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StepConfig, WorkflowConfig, WorkflowResult, WorkflowRunOptions } from './types';
|
|
2
|
+
export interface Workflow {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
run(input: unknown, options?: WorkflowRunOptions): Promise<WorkflowResult>;
|
|
5
|
+
}
|
|
6
|
+
export declare function defineWorkflow(config: WorkflowConfig): Workflow;
|
|
7
|
+
export interface ParallelWorkflowConfig {
|
|
8
|
+
name: string;
|
|
9
|
+
steps: StepConfig[];
|
|
10
|
+
onComplete?: (result: WorkflowResult) => void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function defineParallelWorkflow(config: ParallelWorkflowConfig): Workflow;
|
|
13
|
+
export interface BranchConfig {
|
|
14
|
+
condition: (input: unknown) => boolean;
|
|
15
|
+
workflow: Workflow;
|
|
16
|
+
}
|
|
17
|
+
export declare function defineBranchWorkflow(name: string, branches: BranchConfig[], fallback?: Workflow): Workflow;
|
|
18
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,UAAU,EAGV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,MAAM,SAAS,CAAA;AAEhB,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAC1E;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CA0D/D;AAID,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7D;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,QAAQ,CA2C/E;AAID,MAAM,WAAW,YAAY;IAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;IACtC,QAAQ,EAAE,QAAQ,CAAA;CAClB;AAED,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,YAAY,EAAE,EACxB,QAAQ,CAAC,EAAE,QAAQ,GACjB,QAAQ,CAwBV"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elsium-ai/workflows",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Multi-step workflow pipelines and DAG execution for ElsiumAI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Eric Utrera <ebutrera9103@gmail.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/elsium-ai/elsium-ai",
|
|
10
|
+
"directory": "packages/workflows"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target bun && bun x tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
26
|
+
"dev": "bun --watch src/index.ts"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@elsium-ai/core": "workspace:*",
|
|
30
|
+
"zod": "^3.24.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"bun-types": "^1.3.0",
|
|
34
|
+
"typescript": "^5.7.0"
|
|
35
|
+
}
|
|
36
|
+
}
|