@cogitator-ai/types 0.1.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/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/agent.d.ts +41 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +5 -0
- package/dist/agent.js.map +1 -0
- package/dist/errors.d.ts +108 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +179 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.d.ts +55 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +5 -0
- package/dist/llm.js.map +1 -0
- package/dist/memory.d.ts +207 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +5 -0
- package/dist/memory.js.map +1 -0
- package/dist/message.d.ts +33 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +5 -0
- package/dist/message.js.map +1 -0
- package/dist/runtime.d.ts +106 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sandbox.d.ts +120 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +5 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/swarm.d.ts +362 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +5 -0
- package/dist/swarm.js.map +1 -0
- package/dist/tool.d.ts +43 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +5 -0
- package/dist/tool.js.map +1 -0
- package/dist/workflow.d.ts +678 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +16 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow types for DAG-based multi-step pipelines
|
|
3
|
+
*
|
|
4
|
+
* Includes:
|
|
5
|
+
* - Core workflow execution types
|
|
6
|
+
* - Human-in-the-loop approval system
|
|
7
|
+
* - Saga pattern (retry, compensation, circuit breaker)
|
|
8
|
+
* - Map-Reduce patterns
|
|
9
|
+
* - Timer and scheduling system
|
|
10
|
+
* - Subworkflow support
|
|
11
|
+
* - Trigger system (cron, webhooks)
|
|
12
|
+
* - OpenTelemetry observability
|
|
13
|
+
* - Workflow management API
|
|
14
|
+
*/
|
|
15
|
+
export type WorkflowState = Record<string, unknown>;
|
|
16
|
+
export interface NodeConfig {
|
|
17
|
+
name?: string;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
retries?: number;
|
|
20
|
+
retryDelay?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface NodeContext<S = WorkflowState> {
|
|
23
|
+
state: S;
|
|
24
|
+
input?: unknown;
|
|
25
|
+
nodeId: string;
|
|
26
|
+
workflowId: string;
|
|
27
|
+
step: number;
|
|
28
|
+
}
|
|
29
|
+
export interface NodeResult<S = WorkflowState> {
|
|
30
|
+
state?: Partial<S>;
|
|
31
|
+
output?: unknown;
|
|
32
|
+
next?: string | string[];
|
|
33
|
+
}
|
|
34
|
+
export type NodeFn<S = WorkflowState> = (ctx: NodeContext<S>) => Promise<NodeResult<S>>;
|
|
35
|
+
export interface WorkflowNode<S = WorkflowState> {
|
|
36
|
+
name: string;
|
|
37
|
+
fn: NodeFn<S>;
|
|
38
|
+
config?: NodeConfig;
|
|
39
|
+
}
|
|
40
|
+
export type Edge = SequentialEdge | ConditionalEdge | ParallelEdge | LoopEdge;
|
|
41
|
+
export interface SequentialEdge {
|
|
42
|
+
type: 'sequential';
|
|
43
|
+
from: string;
|
|
44
|
+
to: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ConditionalEdge {
|
|
47
|
+
type: 'conditional';
|
|
48
|
+
from: string;
|
|
49
|
+
condition: (state: unknown) => string | string[];
|
|
50
|
+
targets: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface ParallelEdge {
|
|
53
|
+
type: 'parallel';
|
|
54
|
+
from: string;
|
|
55
|
+
to: string[];
|
|
56
|
+
}
|
|
57
|
+
export interface LoopEdge {
|
|
58
|
+
type: 'loop';
|
|
59
|
+
from: string;
|
|
60
|
+
condition: (state: unknown) => boolean;
|
|
61
|
+
back: string;
|
|
62
|
+
exit: string;
|
|
63
|
+
}
|
|
64
|
+
export interface Workflow<S = WorkflowState> {
|
|
65
|
+
name: string;
|
|
66
|
+
initialState: S;
|
|
67
|
+
nodes: Map<string, WorkflowNode<S>>;
|
|
68
|
+
edges: Edge[];
|
|
69
|
+
entryPoint: string;
|
|
70
|
+
}
|
|
71
|
+
export interface WorkflowExecuteOptions {
|
|
72
|
+
maxConcurrency?: number;
|
|
73
|
+
maxIterations?: number;
|
|
74
|
+
checkpoint?: boolean;
|
|
75
|
+
onNodeStart?: (node: string) => void;
|
|
76
|
+
onNodeComplete?: (node: string, result: unknown, duration: number) => void;
|
|
77
|
+
onNodeError?: (node: string, error: Error) => void;
|
|
78
|
+
}
|
|
79
|
+
export interface WorkflowResult<S = WorkflowState> {
|
|
80
|
+
workflowId: string;
|
|
81
|
+
workflowName: string;
|
|
82
|
+
state: S;
|
|
83
|
+
nodeResults: Map<string, {
|
|
84
|
+
output: unknown;
|
|
85
|
+
duration: number;
|
|
86
|
+
}>;
|
|
87
|
+
duration: number;
|
|
88
|
+
checkpointId?: string;
|
|
89
|
+
error?: Error;
|
|
90
|
+
}
|
|
91
|
+
export type WorkflowEvent = {
|
|
92
|
+
type: 'node:start';
|
|
93
|
+
node: string;
|
|
94
|
+
timestamp: number;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'node:complete';
|
|
97
|
+
node: string;
|
|
98
|
+
output: unknown;
|
|
99
|
+
duration: number;
|
|
100
|
+
} | {
|
|
101
|
+
type: 'node:error';
|
|
102
|
+
node: string;
|
|
103
|
+
error: Error;
|
|
104
|
+
} | {
|
|
105
|
+
type: 'workflow:complete';
|
|
106
|
+
state: unknown;
|
|
107
|
+
duration: number;
|
|
108
|
+
};
|
|
109
|
+
export interface WorkflowCheckpoint {
|
|
110
|
+
id: string;
|
|
111
|
+
workflowId: string;
|
|
112
|
+
workflowName: string;
|
|
113
|
+
state: WorkflowState;
|
|
114
|
+
completedNodes: string[];
|
|
115
|
+
nodeResults: Record<string, unknown>;
|
|
116
|
+
timestamp: number;
|
|
117
|
+
}
|
|
118
|
+
export interface CheckpointStore {
|
|
119
|
+
save(checkpoint: WorkflowCheckpoint): Promise<void>;
|
|
120
|
+
load(id: string): Promise<WorkflowCheckpoint | null>;
|
|
121
|
+
list(workflowName: string): Promise<WorkflowCheckpoint[]>;
|
|
122
|
+
delete(id: string): Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
export interface AddNodeOptions {
|
|
125
|
+
after?: string[];
|
|
126
|
+
config?: NodeConfig;
|
|
127
|
+
}
|
|
128
|
+
export interface AddConditionalOptions {
|
|
129
|
+
after?: string[];
|
|
130
|
+
}
|
|
131
|
+
export interface AddLoopOptions {
|
|
132
|
+
condition: (state: unknown) => boolean;
|
|
133
|
+
back: string;
|
|
134
|
+
exit: string;
|
|
135
|
+
after?: string[];
|
|
136
|
+
}
|
|
137
|
+
export type ApprovalType = 'approve-reject' | 'multi-choice' | 'free-form' | 'numeric-rating';
|
|
138
|
+
export interface ApprovalChoice {
|
|
139
|
+
id: string;
|
|
140
|
+
label: string;
|
|
141
|
+
value: unknown;
|
|
142
|
+
description?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface ApprovalRequest {
|
|
145
|
+
id: string;
|
|
146
|
+
workflowId: string;
|
|
147
|
+
runId: string;
|
|
148
|
+
nodeId: string;
|
|
149
|
+
type: ApprovalType;
|
|
150
|
+
title: string;
|
|
151
|
+
description?: string;
|
|
152
|
+
choices?: ApprovalChoice[];
|
|
153
|
+
assignee?: string;
|
|
154
|
+
assigneeGroup?: string[];
|
|
155
|
+
deadline?: number;
|
|
156
|
+
timeout?: number;
|
|
157
|
+
timeoutAction?: 'approve' | 'reject' | 'escalate' | 'fail';
|
|
158
|
+
escalateTo?: string;
|
|
159
|
+
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
160
|
+
metadata?: Record<string, unknown>;
|
|
161
|
+
createdAt: number;
|
|
162
|
+
}
|
|
163
|
+
export interface ApprovalResponse {
|
|
164
|
+
requestId: string;
|
|
165
|
+
decision: unknown;
|
|
166
|
+
respondedBy: string;
|
|
167
|
+
respondedAt: number;
|
|
168
|
+
comment?: string;
|
|
169
|
+
delegatedTo?: string;
|
|
170
|
+
delegationReason?: string;
|
|
171
|
+
}
|
|
172
|
+
export interface ApprovalChainStep {
|
|
173
|
+
assignee: string;
|
|
174
|
+
role?: string;
|
|
175
|
+
required: boolean;
|
|
176
|
+
timeout?: number;
|
|
177
|
+
timeoutAction?: 'approve' | 'reject' | 'escalate' | 'skip';
|
|
178
|
+
}
|
|
179
|
+
export interface HumanNodeConfig<S = WorkflowState> extends NodeConfig {
|
|
180
|
+
approval: {
|
|
181
|
+
type: ApprovalType;
|
|
182
|
+
title: string;
|
|
183
|
+
description?: string | ((state: S) => string);
|
|
184
|
+
choices?: ApprovalChoice[];
|
|
185
|
+
assignee?: string | ((state: S) => string);
|
|
186
|
+
assigneeGroup?: string[] | ((state: S) => string[]);
|
|
187
|
+
chain?: ApprovalChainStep[];
|
|
188
|
+
timeout?: number;
|
|
189
|
+
timeoutAction?: 'approve' | 'reject' | 'escalate' | 'fail';
|
|
190
|
+
escalateTo?: string;
|
|
191
|
+
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export interface ApprovalStore {
|
|
195
|
+
createRequest(request: ApprovalRequest): Promise<void>;
|
|
196
|
+
getRequest(id: string): Promise<ApprovalRequest | null>;
|
|
197
|
+
getPendingRequests(workflowId?: string): Promise<ApprovalRequest[]>;
|
|
198
|
+
getPendingForAssignee(assignee: string): Promise<ApprovalRequest[]>;
|
|
199
|
+
submitResponse(response: ApprovalResponse): Promise<void>;
|
|
200
|
+
getResponse(requestId: string): Promise<ApprovalResponse | null>;
|
|
201
|
+
deleteRequest(id: string): Promise<void>;
|
|
202
|
+
onResponse(requestId: string, callback: (response: ApprovalResponse) => void): () => void;
|
|
203
|
+
}
|
|
204
|
+
export interface ApprovalNotifier {
|
|
205
|
+
notify(request: ApprovalRequest): Promise<void>;
|
|
206
|
+
notifyEscalation(request: ApprovalRequest, reason: string): Promise<void>;
|
|
207
|
+
notifyTimeout(request: ApprovalRequest): Promise<void>;
|
|
208
|
+
notifyDelegation(request: ApprovalRequest, from: string, to: string): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
export type BackoffStrategy = 'constant' | 'linear' | 'exponential';
|
|
211
|
+
export interface RetryConfig {
|
|
212
|
+
maxRetries: number;
|
|
213
|
+
backoff?: BackoffStrategy;
|
|
214
|
+
initialDelay?: number;
|
|
215
|
+
maxDelay?: number;
|
|
216
|
+
multiplier?: number;
|
|
217
|
+
jitter?: number;
|
|
218
|
+
isRetryable?: (error: Error) => boolean;
|
|
219
|
+
}
|
|
220
|
+
export type CircuitBreakerState = 'closed' | 'open' | 'half-open';
|
|
221
|
+
export interface CircuitBreakerConfig {
|
|
222
|
+
enabled?: boolean;
|
|
223
|
+
threshold: number;
|
|
224
|
+
resetTimeout: number;
|
|
225
|
+
successThreshold?: number;
|
|
226
|
+
halfOpenMax?: number;
|
|
227
|
+
onStateChange?: (from: CircuitBreakerState, to: CircuitBreakerState, nodeId: string) => void;
|
|
228
|
+
}
|
|
229
|
+
export interface CircuitBreakerStatus {
|
|
230
|
+
state: CircuitBreakerState;
|
|
231
|
+
failures: number;
|
|
232
|
+
successes: number;
|
|
233
|
+
lastFailure?: number;
|
|
234
|
+
lastSuccess?: number;
|
|
235
|
+
nextAttempt?: number;
|
|
236
|
+
}
|
|
237
|
+
export type CompensationOrder = 'reverse' | 'forward' | 'parallel';
|
|
238
|
+
export interface CompensationConfig<S = WorkflowState> {
|
|
239
|
+
compensate?: (state: S, originalResult: unknown) => Promise<void>;
|
|
240
|
+
compensateCondition?: (state: S, error: Error) => boolean;
|
|
241
|
+
compensateOrder?: CompensationOrder;
|
|
242
|
+
compensateTimeout?: number;
|
|
243
|
+
}
|
|
244
|
+
export interface SagaNodeConfig extends NodeConfig {
|
|
245
|
+
retry?: RetryConfig;
|
|
246
|
+
circuitBreaker?: CircuitBreakerConfig;
|
|
247
|
+
compensation?: CompensationConfig;
|
|
248
|
+
idempotencyKey?: string | ((state: unknown) => string);
|
|
249
|
+
}
|
|
250
|
+
export interface DeadLetterEntry {
|
|
251
|
+
id: string;
|
|
252
|
+
workflowId: string;
|
|
253
|
+
workflowName: string;
|
|
254
|
+
nodeId: string;
|
|
255
|
+
error: {
|
|
256
|
+
message: string;
|
|
257
|
+
name: string;
|
|
258
|
+
stack?: string;
|
|
259
|
+
};
|
|
260
|
+
state: WorkflowState;
|
|
261
|
+
input?: unknown;
|
|
262
|
+
attempts: number;
|
|
263
|
+
maxAttempts: number;
|
|
264
|
+
lastAttempt: number;
|
|
265
|
+
createdAt: number;
|
|
266
|
+
expiresAt?: number;
|
|
267
|
+
tags?: string[];
|
|
268
|
+
metadata?: Record<string, unknown>;
|
|
269
|
+
}
|
|
270
|
+
export interface DeadLetterQueue {
|
|
271
|
+
add(entry: DeadLetterEntry): Promise<string>;
|
|
272
|
+
get(id: string): Promise<DeadLetterEntry | null>;
|
|
273
|
+
list(filters?: {
|
|
274
|
+
workflowId?: string;
|
|
275
|
+
nodeId?: string;
|
|
276
|
+
limit?: number;
|
|
277
|
+
}): Promise<DeadLetterEntry[]>;
|
|
278
|
+
retry(id: string): Promise<boolean>;
|
|
279
|
+
remove(id: string): Promise<boolean>;
|
|
280
|
+
count(filters?: {
|
|
281
|
+
workflowId?: string;
|
|
282
|
+
nodeId?: string;
|
|
283
|
+
}): Promise<number>;
|
|
284
|
+
clear(): Promise<void>;
|
|
285
|
+
}
|
|
286
|
+
export interface IdempotencyRecord {
|
|
287
|
+
key: string;
|
|
288
|
+
result?: unknown;
|
|
289
|
+
error?: {
|
|
290
|
+
name: string;
|
|
291
|
+
message: string;
|
|
292
|
+
stack?: string;
|
|
293
|
+
};
|
|
294
|
+
status: 'completed' | 'failed';
|
|
295
|
+
createdAt: number;
|
|
296
|
+
expiresAt?: number;
|
|
297
|
+
}
|
|
298
|
+
export interface IdempotencyStore {
|
|
299
|
+
check(key: string): Promise<{
|
|
300
|
+
isDuplicate: boolean;
|
|
301
|
+
record?: IdempotencyRecord;
|
|
302
|
+
}>;
|
|
303
|
+
store(key: string, result: unknown, error?: Error): Promise<void>;
|
|
304
|
+
get(key: string): Promise<IdempotencyRecord | null>;
|
|
305
|
+
delete(key: string): Promise<boolean>;
|
|
306
|
+
clear(): Promise<void>;
|
|
307
|
+
}
|
|
308
|
+
export interface MapNodeConfig<S = WorkflowState, T = unknown> extends NodeConfig {
|
|
309
|
+
items: (state: S) => T[];
|
|
310
|
+
concurrency?: number;
|
|
311
|
+
continueOnError?: boolean;
|
|
312
|
+
onProgress?: (completed: number, total: number, item: T) => void;
|
|
313
|
+
onItemComplete?: (item: T, result: unknown, index: number) => void;
|
|
314
|
+
onItemError?: (item: T, error: Error, index: number) => void;
|
|
315
|
+
}
|
|
316
|
+
export interface ReduceNodeConfig<S = WorkflowState, T = unknown, R = unknown> extends NodeConfig {
|
|
317
|
+
initial: R | ((state: S) => R);
|
|
318
|
+
reducer: (accumulator: R, result: T, index: number, state: S) => R;
|
|
319
|
+
streaming?: boolean;
|
|
320
|
+
onReduce?: (accumulator: R, result: T, index: number) => void;
|
|
321
|
+
}
|
|
322
|
+
export interface MapReduceResult<R = unknown> {
|
|
323
|
+
result: R;
|
|
324
|
+
succeeded: number;
|
|
325
|
+
failed: number;
|
|
326
|
+
total: number;
|
|
327
|
+
errors: {
|
|
328
|
+
index: number;
|
|
329
|
+
error: Error;
|
|
330
|
+
item?: unknown;
|
|
331
|
+
}[];
|
|
332
|
+
duration: number;
|
|
333
|
+
}
|
|
334
|
+
export type TimerType = 'fixed' | 'dynamic' | 'cron' | 'recurring';
|
|
335
|
+
export interface TimerConfig {
|
|
336
|
+
type: TimerType;
|
|
337
|
+
delay?: number;
|
|
338
|
+
delayFn?: (state: unknown) => number;
|
|
339
|
+
cron?: string;
|
|
340
|
+
timezone?: string;
|
|
341
|
+
timerId?: string;
|
|
342
|
+
persist?: boolean;
|
|
343
|
+
cancellable?: boolean;
|
|
344
|
+
}
|
|
345
|
+
export interface TimerEntry {
|
|
346
|
+
id: string;
|
|
347
|
+
workflowId: string;
|
|
348
|
+
runId: string;
|
|
349
|
+
nodeId: string;
|
|
350
|
+
firesAt: number;
|
|
351
|
+
type: TimerType;
|
|
352
|
+
cron?: string;
|
|
353
|
+
timezone?: string;
|
|
354
|
+
cancelled: boolean;
|
|
355
|
+
fired: boolean;
|
|
356
|
+
createdAt: number;
|
|
357
|
+
metadata?: Record<string, unknown>;
|
|
358
|
+
}
|
|
359
|
+
export interface TimerStore {
|
|
360
|
+
schedule(entry: Omit<TimerEntry, 'id' | 'cancelled' | 'fired' | 'createdAt'>): Promise<string>;
|
|
361
|
+
cancel(id: string): Promise<void>;
|
|
362
|
+
get(id: string): Promise<TimerEntry | null>;
|
|
363
|
+
getByWorkflow(workflowId: string): Promise<TimerEntry[]>;
|
|
364
|
+
getByRun(runId: string): Promise<TimerEntry[]>;
|
|
365
|
+
getPending(): Promise<TimerEntry[]>;
|
|
366
|
+
getOverdue(): Promise<TimerEntry[]>;
|
|
367
|
+
markFired(id: string): Promise<void>;
|
|
368
|
+
cleanup(olderThan: number): Promise<number>;
|
|
369
|
+
onFire(callback: (entry: TimerEntry) => void): () => void;
|
|
370
|
+
}
|
|
371
|
+
export interface CronSchedule {
|
|
372
|
+
expression: string;
|
|
373
|
+
timezone?: string;
|
|
374
|
+
next(): Date;
|
|
375
|
+
prev(): Date;
|
|
376
|
+
hasNext(): boolean;
|
|
377
|
+
iterate(count: number): Date[];
|
|
378
|
+
}
|
|
379
|
+
export type SubworkflowErrorStrategy = 'propagate' | 'catch' | 'retry' | 'ignore';
|
|
380
|
+
export interface SubworkflowConfig<S = WorkflowState, CS = WorkflowState> extends NodeConfig {
|
|
381
|
+
workflow: Workflow<CS>;
|
|
382
|
+
inputMapper?: (parentState: S, input?: unknown) => Partial<CS>;
|
|
383
|
+
outputMapper?: (childResult: WorkflowResult<CS>, parentState: S) => Partial<S>;
|
|
384
|
+
onError?: SubworkflowErrorStrategy;
|
|
385
|
+
retryConfig?: RetryConfig;
|
|
386
|
+
shareCheckpoints?: boolean;
|
|
387
|
+
maxDepth?: number;
|
|
388
|
+
inheritTraceContext?: boolean;
|
|
389
|
+
}
|
|
390
|
+
export interface SubworkflowResult<CS = WorkflowState> {
|
|
391
|
+
success: boolean;
|
|
392
|
+
result?: WorkflowResult<CS>;
|
|
393
|
+
error?: Error;
|
|
394
|
+
depth: number;
|
|
395
|
+
}
|
|
396
|
+
export interface CronTriggerConfig {
|
|
397
|
+
expression: string;
|
|
398
|
+
timezone?: string;
|
|
399
|
+
enabled: boolean;
|
|
400
|
+
runImmediately?: boolean;
|
|
401
|
+
condition?: (context: TriggerContext) => boolean;
|
|
402
|
+
input?: Record<string, unknown> | ((context: TriggerContext) => Record<string, unknown>);
|
|
403
|
+
maxConcurrent?: number;
|
|
404
|
+
catchUp?: boolean;
|
|
405
|
+
}
|
|
406
|
+
export interface WebhookAuthConfig {
|
|
407
|
+
type: 'bearer' | 'basic' | 'hmac' | 'api-key' | 'none';
|
|
408
|
+
secret?: string;
|
|
409
|
+
headerName?: string;
|
|
410
|
+
algorithm?: 'sha256' | 'sha512';
|
|
411
|
+
}
|
|
412
|
+
export interface WebhookRateLimitConfig {
|
|
413
|
+
requests: number;
|
|
414
|
+
window: number;
|
|
415
|
+
burstLimit?: number;
|
|
416
|
+
}
|
|
417
|
+
export interface WebhookTriggerConfig {
|
|
418
|
+
path: string;
|
|
419
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
420
|
+
auth?: WebhookAuthConfig;
|
|
421
|
+
rateLimit?: WebhookRateLimitConfig;
|
|
422
|
+
deduplicationKey?: (payload: unknown) => string;
|
|
423
|
+
deduplicationWindow?: number;
|
|
424
|
+
validatePayload?: (payload: unknown) => boolean;
|
|
425
|
+
transformPayload?: (payload: unknown) => unknown;
|
|
426
|
+
responseTimeout?: number;
|
|
427
|
+
}
|
|
428
|
+
export interface EventTriggerConfig {
|
|
429
|
+
eventType: string;
|
|
430
|
+
source?: string;
|
|
431
|
+
filter?: (event: unknown) => boolean;
|
|
432
|
+
transform?: (event: unknown) => unknown;
|
|
433
|
+
}
|
|
434
|
+
export interface TriggerContext {
|
|
435
|
+
triggerId: string;
|
|
436
|
+
triggerType: 'cron' | 'webhook' | 'event' | 'manual';
|
|
437
|
+
timestamp: number;
|
|
438
|
+
payload?: unknown;
|
|
439
|
+
headers?: Record<string, string>;
|
|
440
|
+
metadata?: Record<string, unknown>;
|
|
441
|
+
traceContext?: {
|
|
442
|
+
traceId: string;
|
|
443
|
+
spanId: string;
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
export interface WorkflowTrigger {
|
|
447
|
+
id: string;
|
|
448
|
+
workflowName: string;
|
|
449
|
+
type: 'cron' | 'webhook' | 'event';
|
|
450
|
+
config: CronTriggerConfig | WebhookTriggerConfig | EventTriggerConfig;
|
|
451
|
+
enabled: boolean;
|
|
452
|
+
createdAt: number;
|
|
453
|
+
lastTriggered?: number;
|
|
454
|
+
nextTrigger?: number;
|
|
455
|
+
triggerCount: number;
|
|
456
|
+
errorCount: number;
|
|
457
|
+
lastError?: string;
|
|
458
|
+
}
|
|
459
|
+
export interface TriggerManager {
|
|
460
|
+
register(trigger: Omit<WorkflowTrigger, 'id' | 'createdAt' | 'triggerCount' | 'errorCount'>): Promise<string>;
|
|
461
|
+
unregister(id: string): Promise<void>;
|
|
462
|
+
enable(id: string): Promise<void>;
|
|
463
|
+
disable(id: string): Promise<void>;
|
|
464
|
+
get(id: string): Promise<WorkflowTrigger | null>;
|
|
465
|
+
list(workflowName?: string): Promise<WorkflowTrigger[]>;
|
|
466
|
+
listEnabled(): Promise<WorkflowTrigger[]>;
|
|
467
|
+
fire(id: string, context?: Partial<TriggerContext>): Promise<string>;
|
|
468
|
+
onTrigger(callback: (trigger: WorkflowTrigger, context: TriggerContext) => void): () => void;
|
|
469
|
+
}
|
|
470
|
+
export type SpanExporter = 'console' | 'otlp' | 'jaeger' | 'zipkin';
|
|
471
|
+
export interface TracingConfig {
|
|
472
|
+
enabled: boolean;
|
|
473
|
+
serviceName?: string;
|
|
474
|
+
serviceVersion?: string;
|
|
475
|
+
attributes?: Record<string, unknown>;
|
|
476
|
+
sampleRate?: number;
|
|
477
|
+
propagateContext?: boolean;
|
|
478
|
+
exporter?: SpanExporter;
|
|
479
|
+
exporterEndpoint?: string;
|
|
480
|
+
exporterHeaders?: Record<string, string>;
|
|
481
|
+
batchSize?: number;
|
|
482
|
+
flushInterval?: number;
|
|
483
|
+
}
|
|
484
|
+
export interface MetricsConfig {
|
|
485
|
+
enabled: boolean;
|
|
486
|
+
prefix?: string;
|
|
487
|
+
labels?: Record<string, string>;
|
|
488
|
+
latencyBuckets?: number[];
|
|
489
|
+
tokenBuckets?: number[];
|
|
490
|
+
costBuckets?: number[];
|
|
491
|
+
pushGateway?: string;
|
|
492
|
+
pushInterval?: number;
|
|
493
|
+
}
|
|
494
|
+
export type SpanKind = 'internal' | 'client' | 'server' | 'producer' | 'consumer';
|
|
495
|
+
export type SpanStatus = 'ok' | 'error' | 'unset';
|
|
496
|
+
export interface SpanEvent {
|
|
497
|
+
name: string;
|
|
498
|
+
timestamp: number;
|
|
499
|
+
attributes?: Record<string, unknown>;
|
|
500
|
+
}
|
|
501
|
+
export interface SpanLink {
|
|
502
|
+
traceId: string;
|
|
503
|
+
spanId: string;
|
|
504
|
+
attributes?: Record<string, unknown>;
|
|
505
|
+
}
|
|
506
|
+
export interface WorkflowSpan {
|
|
507
|
+
traceId: string;
|
|
508
|
+
spanId: string;
|
|
509
|
+
parentSpanId?: string;
|
|
510
|
+
name: string;
|
|
511
|
+
kind: SpanKind;
|
|
512
|
+
startTime: number;
|
|
513
|
+
endTime?: number;
|
|
514
|
+
attributes: Record<string, unknown>;
|
|
515
|
+
events: SpanEvent[];
|
|
516
|
+
links: SpanLink[];
|
|
517
|
+
status: SpanStatus;
|
|
518
|
+
statusMessage?: string;
|
|
519
|
+
}
|
|
520
|
+
export interface NodeMetrics {
|
|
521
|
+
executionCount: number;
|
|
522
|
+
successCount: number;
|
|
523
|
+
failureCount: number;
|
|
524
|
+
retryCount: number;
|
|
525
|
+
avgDuration: number;
|
|
526
|
+
p50Duration: number;
|
|
527
|
+
p95Duration: number;
|
|
528
|
+
p99Duration: number;
|
|
529
|
+
minDuration: number;
|
|
530
|
+
maxDuration: number;
|
|
531
|
+
}
|
|
532
|
+
export interface WorkflowMetrics {
|
|
533
|
+
workflowName: string;
|
|
534
|
+
executionCount: number;
|
|
535
|
+
successCount: number;
|
|
536
|
+
failureCount: number;
|
|
537
|
+
cancelledCount: number;
|
|
538
|
+
latency: {
|
|
539
|
+
avg: number;
|
|
540
|
+
p50: number;
|
|
541
|
+
p90: number;
|
|
542
|
+
p99: number;
|
|
543
|
+
min: number;
|
|
544
|
+
max: number;
|
|
545
|
+
};
|
|
546
|
+
nodeMetrics: Map<string, NodeMetrics>;
|
|
547
|
+
tokenUsage: {
|
|
548
|
+
input: number;
|
|
549
|
+
output: number;
|
|
550
|
+
total: number;
|
|
551
|
+
};
|
|
552
|
+
totalCost: number;
|
|
553
|
+
lastUpdated: number;
|
|
554
|
+
}
|
|
555
|
+
export interface TraceContext {
|
|
556
|
+
traceId: string;
|
|
557
|
+
spanId: string;
|
|
558
|
+
traceFlags?: number;
|
|
559
|
+
traceState?: string;
|
|
560
|
+
}
|
|
561
|
+
export type Baggage = Record<string, string>;
|
|
562
|
+
export interface ScheduleOptions {
|
|
563
|
+
at?: number;
|
|
564
|
+
cron?: string;
|
|
565
|
+
timezone?: string;
|
|
566
|
+
input?: Partial<WorkflowState>;
|
|
567
|
+
priority?: number;
|
|
568
|
+
tags?: string[];
|
|
569
|
+
triggerId?: string;
|
|
570
|
+
traceContext?: TraceContext;
|
|
571
|
+
baggage?: Baggage;
|
|
572
|
+
timeout?: number;
|
|
573
|
+
maxRetries?: number;
|
|
574
|
+
}
|
|
575
|
+
export type WorkflowRunStatus = 'pending' | 'scheduled' | 'running' | 'paused' | 'waiting' | 'completed' | 'failed' | 'cancelled' | 'timeout';
|
|
576
|
+
export interface WorkflowRun {
|
|
577
|
+
id: string;
|
|
578
|
+
workflowName: string;
|
|
579
|
+
status: WorkflowRunStatus;
|
|
580
|
+
state: WorkflowState;
|
|
581
|
+
input?: unknown;
|
|
582
|
+
output?: unknown;
|
|
583
|
+
currentNodes: string[];
|
|
584
|
+
completedNodes: string[];
|
|
585
|
+
failedNodes: string[];
|
|
586
|
+
startedAt?: number;
|
|
587
|
+
completedAt?: number;
|
|
588
|
+
scheduledFor?: number;
|
|
589
|
+
pausedAt?: number;
|
|
590
|
+
priority: number;
|
|
591
|
+
tags: string[];
|
|
592
|
+
error?: {
|
|
593
|
+
message: string;
|
|
594
|
+
name: string;
|
|
595
|
+
stack?: string;
|
|
596
|
+
nodeId?: string;
|
|
597
|
+
};
|
|
598
|
+
checkpointId?: string;
|
|
599
|
+
triggerId?: string;
|
|
600
|
+
parentRunId?: string;
|
|
601
|
+
traceId?: string;
|
|
602
|
+
metadata?: Record<string, unknown>;
|
|
603
|
+
}
|
|
604
|
+
export interface WorkflowRunFilters {
|
|
605
|
+
status?: WorkflowRunStatus | WorkflowRunStatus[];
|
|
606
|
+
workflowName?: string;
|
|
607
|
+
tags?: string[];
|
|
608
|
+
triggerId?: string;
|
|
609
|
+
parentRunId?: string;
|
|
610
|
+
startedAfter?: number;
|
|
611
|
+
startedBefore?: number;
|
|
612
|
+
completedAfter?: number;
|
|
613
|
+
completedBefore?: number;
|
|
614
|
+
hasError?: boolean;
|
|
615
|
+
limit?: number;
|
|
616
|
+
offset?: number;
|
|
617
|
+
orderBy?: 'startedAt' | 'completedAt' | 'priority';
|
|
618
|
+
orderDirection?: 'asc' | 'desc';
|
|
619
|
+
}
|
|
620
|
+
export interface WorkflowRunStats {
|
|
621
|
+
total: number;
|
|
622
|
+
byStatus: Record<WorkflowRunStatus, number>;
|
|
623
|
+
avgDuration: number;
|
|
624
|
+
successRate: number;
|
|
625
|
+
failureRate: number;
|
|
626
|
+
}
|
|
627
|
+
export interface WorkflowManager {
|
|
628
|
+
schedule<S extends WorkflowState>(workflow: Workflow<S>, options?: ScheduleOptions): Promise<string>;
|
|
629
|
+
execute<S extends WorkflowState>(workflow: Workflow<S>, input?: Partial<S>, options?: WorkflowExecuteOptionsV2): Promise<WorkflowResult<S>>;
|
|
630
|
+
cancel(runId: string, reason?: string): Promise<void>;
|
|
631
|
+
getStatus(runId: string): Promise<WorkflowRun | null>;
|
|
632
|
+
listRuns(filters?: WorkflowRunFilters): Promise<WorkflowRun[]>;
|
|
633
|
+
getStats(workflowName?: string): Promise<WorkflowRunStats>;
|
|
634
|
+
pause(runId: string): Promise<void>;
|
|
635
|
+
resume(runId: string): Promise<void>;
|
|
636
|
+
retry(runId: string): Promise<string>;
|
|
637
|
+
replay<S extends WorkflowState>(workflow: Workflow<S>, runId: string, fromNode: string): Promise<WorkflowResult<S>>;
|
|
638
|
+
getActiveCount(): Promise<number>;
|
|
639
|
+
onRunStateChange(callback: (run: WorkflowRun) => void): () => void;
|
|
640
|
+
cleanup(olderThan: number): Promise<number>;
|
|
641
|
+
}
|
|
642
|
+
export interface RunStore {
|
|
643
|
+
save(run: WorkflowRun): Promise<void>;
|
|
644
|
+
get(id: string): Promise<WorkflowRun | null>;
|
|
645
|
+
list(filters?: WorkflowRunFilters): Promise<WorkflowRun[]>;
|
|
646
|
+
count(filters?: WorkflowRunFilters): Promise<number>;
|
|
647
|
+
update(id: string, updates: Partial<WorkflowRun>): Promise<void>;
|
|
648
|
+
delete(id: string): Promise<void>;
|
|
649
|
+
getStats(workflowName?: string): Promise<WorkflowRunStats>;
|
|
650
|
+
cleanup(olderThan: number): Promise<number>;
|
|
651
|
+
}
|
|
652
|
+
export interface WorkflowExecuteOptionsV2 extends WorkflowExecuteOptions {
|
|
653
|
+
approvalStore?: ApprovalStore;
|
|
654
|
+
approvalNotifier?: ApprovalNotifier;
|
|
655
|
+
deadLetterQueue?: DeadLetterQueue;
|
|
656
|
+
idempotencyStore?: IdempotencyStore;
|
|
657
|
+
defaultRetry?: RetryConfig;
|
|
658
|
+
defaultCircuitBreaker?: CircuitBreakerConfig;
|
|
659
|
+
timerStore?: TimerStore;
|
|
660
|
+
tracing?: TracingConfig;
|
|
661
|
+
metrics?: MetricsConfig;
|
|
662
|
+
parentTraceContext?: TraceContext;
|
|
663
|
+
baggage?: Baggage;
|
|
664
|
+
priority?: number;
|
|
665
|
+
tags?: string[];
|
|
666
|
+
triggerId?: string;
|
|
667
|
+
parentRunId?: string;
|
|
668
|
+
parentWorkflowId?: string;
|
|
669
|
+
parentNodeId?: string;
|
|
670
|
+
depth?: number;
|
|
671
|
+
metadata?: Record<string, unknown>;
|
|
672
|
+
onApprovalRequired?: (request: ApprovalRequest) => void;
|
|
673
|
+
onCompensationStart?: (nodeId: string) => void;
|
|
674
|
+
onCompensationComplete?: (nodeId: string) => void;
|
|
675
|
+
onTimerScheduled?: (entry: TimerEntry) => void;
|
|
676
|
+
onDeadLetter?: (entry: DeadLetterEntry) => void;
|
|
677
|
+
}
|
|
678
|
+
//# sourceMappingURL=workflow.d.ts.map
|