@reactive-agents/orchestration 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tyler Buell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @reactive-agents/orchestration
2
+
3
+ Multi-agent orchestration for the [Reactive Agents](https://tylerjrbuell.github.io/reactive-agents-ts/) framework.
4
+
5
+ Coordinate fleets of agents in parallel or sequential workflows, with typed message passing and failure handling.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ bun add @reactive-agents/orchestration effect
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - **Parallel execution** — run multiple agents concurrently, collect results
16
+ - **Sequential pipelines** — chain agents where each step's output feeds the next
17
+ - **Typed handoffs** — Effect-TS schemas validate inter-agent messages
18
+ - **Failure isolation** — one agent failing doesn't crash the whole workflow
19
+
20
+ ## Usage
21
+
22
+ ```typescript
23
+ import { ReactiveAgents } from "reactive-agents";
24
+ import { createOrchestration } from "@reactive-agents/orchestration";
25
+
26
+ const workflow = createOrchestration({
27
+ name: "research-pipeline",
28
+ steps: [
29
+ { agent: "searcher", input: (ctx) => ctx.query },
30
+ { agent: "summarizer", input: (ctx) => ctx.previousResult },
31
+ { agent: "critic", input: (ctx) => ctx.previousResult },
32
+ ],
33
+ });
34
+
35
+ const result = await workflow.run({ query: "Latest advances in fusion energy" });
36
+ ```
37
+
38
+ ## Documentation
39
+
40
+ Full documentation at [tylerjrbuell.github.io/reactive-agents-ts](https://tylerjrbuell.github.io/reactive-agents-ts/)
@@ -0,0 +1,308 @@
1
+ import { Schema, Effect, Ref, Context, Layer } from 'effect';
2
+ import * as effect_Cause from 'effect/Cause';
3
+ import * as effect_Types from 'effect/Types';
4
+ import * as effect_Brand from 'effect/Brand';
5
+
6
+ declare const WorkflowIdSchema: Schema.brand<typeof Schema.String, "WorkflowId">;
7
+ type WorkflowId = typeof WorkflowIdSchema.Type;
8
+ declare const WorkflowPattern: Schema.Literal<["sequential", "parallel", "map-reduce", "pipeline", "orchestrator-workers"]>;
9
+ type WorkflowPattern = typeof WorkflowPattern.Type;
10
+ declare const WorkflowState: Schema.Literal<["pending", "running", "paused", "completed", "failed", "recovering"]>;
11
+ type WorkflowState = typeof WorkflowState.Type;
12
+ declare const WorkflowStepSchema: Schema.Struct<{
13
+ id: typeof Schema.String;
14
+ name: typeof Schema.String;
15
+ agentId: Schema.optional<typeof Schema.String>;
16
+ input: typeof Schema.Unknown;
17
+ output: Schema.optional<typeof Schema.Unknown>;
18
+ status: Schema.Literal<["pending", "running", "completed", "failed", "skipped"]>;
19
+ startedAt: Schema.optional<typeof Schema.DateFromSelf>;
20
+ completedAt: Schema.optional<typeof Schema.DateFromSelf>;
21
+ error: Schema.optional<typeof Schema.String>;
22
+ retryCount: typeof Schema.Number;
23
+ maxRetries: typeof Schema.Number;
24
+ }>;
25
+ type WorkflowStep = typeof WorkflowStepSchema.Type;
26
+ declare const WorkflowSchema: Schema.Struct<{
27
+ id: Schema.brand<typeof Schema.String, "WorkflowId">;
28
+ name: typeof Schema.String;
29
+ pattern: Schema.Literal<["sequential", "parallel", "map-reduce", "pipeline", "orchestrator-workers"]>;
30
+ steps: Schema.Array$<Schema.Struct<{
31
+ id: typeof Schema.String;
32
+ name: typeof Schema.String;
33
+ agentId: Schema.optional<typeof Schema.String>;
34
+ input: typeof Schema.Unknown;
35
+ output: Schema.optional<typeof Schema.Unknown>;
36
+ status: Schema.Literal<["pending", "running", "completed", "failed", "skipped"]>;
37
+ startedAt: Schema.optional<typeof Schema.DateFromSelf>;
38
+ completedAt: Schema.optional<typeof Schema.DateFromSelf>;
39
+ error: Schema.optional<typeof Schema.String>;
40
+ retryCount: typeof Schema.Number;
41
+ maxRetries: typeof Schema.Number;
42
+ }>>;
43
+ state: Schema.Literal<["pending", "running", "paused", "completed", "failed", "recovering"]>;
44
+ createdAt: typeof Schema.DateFromSelf;
45
+ updatedAt: typeof Schema.DateFromSelf;
46
+ completedAt: Schema.optional<typeof Schema.DateFromSelf>;
47
+ metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
48
+ }>;
49
+ type Workflow = typeof WorkflowSchema.Type;
50
+ type DomainEvent = {
51
+ type: "WorkflowCreated";
52
+ workflowId: WorkflowId;
53
+ timestamp: Date;
54
+ payload: Workflow;
55
+ } | {
56
+ type: "StepStarted";
57
+ workflowId: WorkflowId;
58
+ timestamp: Date;
59
+ payload: {
60
+ stepId: string;
61
+ agentId: string;
62
+ };
63
+ } | {
64
+ type: "StepCompleted";
65
+ workflowId: WorkflowId;
66
+ timestamp: Date;
67
+ payload: {
68
+ stepId: string;
69
+ output: unknown;
70
+ };
71
+ } | {
72
+ type: "StepFailed";
73
+ workflowId: WorkflowId;
74
+ timestamp: Date;
75
+ payload: {
76
+ stepId: string;
77
+ error: string;
78
+ };
79
+ } | {
80
+ type: "WorkflowCompleted";
81
+ workflowId: WorkflowId;
82
+ timestamp: Date;
83
+ payload: {
84
+ result: unknown;
85
+ };
86
+ } | {
87
+ type: "WorkflowFailed";
88
+ workflowId: WorkflowId;
89
+ timestamp: Date;
90
+ payload: {
91
+ error: string;
92
+ };
93
+ } | {
94
+ type: "WorkflowPaused";
95
+ workflowId: WorkflowId;
96
+ timestamp: Date;
97
+ payload: {
98
+ reason: string;
99
+ };
100
+ } | {
101
+ type: "WorkflowResumed";
102
+ workflowId: WorkflowId;
103
+ timestamp: Date;
104
+ payload: Record<string, never>;
105
+ };
106
+ declare const CheckpointSchema: Schema.Struct<{
107
+ id: typeof Schema.String;
108
+ workflowId: Schema.brand<typeof Schema.String, "WorkflowId">;
109
+ timestamp: typeof Schema.DateFromSelf;
110
+ state: Schema.Struct<{
111
+ id: Schema.brand<typeof Schema.String, "WorkflowId">;
112
+ name: typeof Schema.String;
113
+ pattern: Schema.Literal<["sequential", "parallel", "map-reduce", "pipeline", "orchestrator-workers"]>;
114
+ steps: Schema.Array$<Schema.Struct<{
115
+ id: typeof Schema.String;
116
+ name: typeof Schema.String;
117
+ agentId: Schema.optional<typeof Schema.String>;
118
+ input: typeof Schema.Unknown;
119
+ output: Schema.optional<typeof Schema.Unknown>;
120
+ status: Schema.Literal<["pending", "running", "completed", "failed", "skipped"]>;
121
+ startedAt: Schema.optional<typeof Schema.DateFromSelf>;
122
+ completedAt: Schema.optional<typeof Schema.DateFromSelf>;
123
+ error: Schema.optional<typeof Schema.String>;
124
+ retryCount: typeof Schema.Number;
125
+ maxRetries: typeof Schema.Number;
126
+ }>>;
127
+ state: Schema.Literal<["pending", "running", "paused", "completed", "failed", "recovering"]>;
128
+ createdAt: typeof Schema.DateFromSelf;
129
+ updatedAt: typeof Schema.DateFromSelf;
130
+ completedAt: Schema.optional<typeof Schema.DateFromSelf>;
131
+ metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
132
+ }>;
133
+ eventIndex: typeof Schema.Number;
134
+ }>;
135
+ type Checkpoint = typeof CheckpointSchema.Type;
136
+ declare const WorkerAgentSchema: Schema.Struct<{
137
+ agentId: typeof Schema.String;
138
+ specialty: typeof Schema.String;
139
+ status: Schema.Literal<["idle", "busy", "failed", "draining"]>;
140
+ currentWorkflowId: Schema.optional<Schema.brand<typeof Schema.String, "WorkflowId">>;
141
+ currentStepId: Schema.optional<typeof Schema.String>;
142
+ completedTasks: typeof Schema.Number;
143
+ failedTasks: typeof Schema.Number;
144
+ avgLatencyMs: typeof Schema.Number;
145
+ }>;
146
+ type WorkerAgent = typeof WorkerAgentSchema.Type;
147
+
148
+ declare const WorkflowError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
149
+ readonly _tag: "WorkflowError";
150
+ } & Readonly<A>;
151
+ declare class WorkflowError extends WorkflowError_base<{
152
+ readonly message: string;
153
+ readonly workflowId?: string;
154
+ readonly cause?: unknown;
155
+ }> {
156
+ }
157
+ declare const WorkflowStepError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
158
+ readonly _tag: "WorkflowStepError";
159
+ } & Readonly<A>;
160
+ declare class WorkflowStepError extends WorkflowStepError_base<{
161
+ readonly message: string;
162
+ readonly workflowId: string;
163
+ readonly stepId: string;
164
+ readonly cause?: unknown;
165
+ }> {
166
+ }
167
+ declare const CheckpointError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
168
+ readonly _tag: "CheckpointError";
169
+ } & Readonly<A>;
170
+ declare class CheckpointError extends CheckpointError_base<{
171
+ readonly message: string;
172
+ readonly workflowId: string;
173
+ }> {
174
+ }
175
+ declare const WorkerPoolError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
176
+ readonly _tag: "WorkerPoolError";
177
+ } & Readonly<A>;
178
+ declare class WorkerPoolError extends WorkerPoolError_base<{
179
+ readonly message: string;
180
+ readonly availableWorkers: number;
181
+ readonly requiredWorkers: number;
182
+ }> {
183
+ }
184
+
185
+ interface WorkflowEngine {
186
+ readonly executeSequential: (workflow: Workflow, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
187
+ readonly executeParallel: (workflow: Workflow, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
188
+ readonly executeMapReduce: (workflow: Workflow, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
189
+ readonly appendEvent: (event: DomainEvent) => Effect.Effect<void, never>;
190
+ readonly updateWorkflow: (workflow: Workflow) => Effect.Effect<void, never>;
191
+ readonly createCheckpoint: (workflow: Workflow) => Effect.Effect<Checkpoint, never>;
192
+ readonly workflowsRef: Ref.Ref<Map<string, Workflow>>;
193
+ readonly eventLogRef: Ref.Ref<DomainEvent[]>;
194
+ }
195
+ declare const makeWorkflowEngine: Effect.Effect<{
196
+ executeSequential: (workflow: Workflow, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
197
+ executeParallel: (workflow: Workflow, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
198
+ executeMapReduce: (workflow: Workflow, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
199
+ appendEvent: (event: DomainEvent) => Effect.Effect<void, never>;
200
+ updateWorkflow: (workflow: Workflow) => Effect.Effect<void, never>;
201
+ createCheckpoint: (workflow: Workflow) => Effect.Effect<Checkpoint, never>;
202
+ workflowsRef: Ref.Ref<Map<string, {
203
+ readonly id: string & effect_Brand.Brand<"WorkflowId">;
204
+ readonly name: string;
205
+ readonly completedAt?: Date | undefined;
206
+ readonly pattern: "sequential" | "parallel" | "map-reduce" | "pipeline" | "orchestrator-workers";
207
+ readonly steps: readonly {
208
+ readonly id: string;
209
+ readonly name: string;
210
+ readonly agentId?: string | undefined;
211
+ readonly input: unknown;
212
+ readonly output?: unknown;
213
+ readonly status: "pending" | "running" | "completed" | "failed" | "skipped";
214
+ readonly startedAt?: Date | undefined;
215
+ readonly completedAt?: Date | undefined;
216
+ readonly error?: string | undefined;
217
+ readonly retryCount: number;
218
+ readonly maxRetries: number;
219
+ }[];
220
+ readonly state: "pending" | "running" | "paused" | "completed" | "failed" | "recovering";
221
+ readonly createdAt: Date;
222
+ readonly updatedAt: Date;
223
+ readonly metadata?: {
224
+ readonly [x: string]: unknown;
225
+ } | undefined;
226
+ }>>;
227
+ eventLogRef: Ref.Ref<DomainEvent[]>;
228
+ }, never, never>;
229
+
230
+ interface EventSourcing {
231
+ readonly saveCheckpoint: (checkpoint: Checkpoint) => Effect.Effect<void, CheckpointError>;
232
+ readonly loadLatestCheckpoint: (workflowId: WorkflowId) => Effect.Effect<Checkpoint, CheckpointError>;
233
+ readonly replayFromCheckpoint: (checkpoint: Checkpoint, events: readonly DomainEvent[]) => Effect.Effect<Workflow, CheckpointError>;
234
+ }
235
+ declare const makeEventSourcing: Effect.Effect<{
236
+ saveCheckpoint: (checkpoint: Checkpoint) => Effect.Effect<void, CheckpointError>;
237
+ loadLatestCheckpoint: (workflowId: WorkflowId) => Effect.Effect<Checkpoint, CheckpointError>;
238
+ replayFromCheckpoint: (checkpoint: Checkpoint, events: readonly DomainEvent[]) => Effect.Effect<Workflow, CheckpointError>;
239
+ }, never, never>;
240
+
241
+ interface WorkerPool {
242
+ readonly spawn: (specialty: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;
243
+ readonly assignTask: (workflowId: WorkflowId, stepId: string, requiredSpecialty?: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;
244
+ readonly releaseWorker: (agentId: string, success: boolean, latencyMs: number) => Effect.Effect<void, never>;
245
+ readonly getStatus: Effect.Effect<{
246
+ total: number;
247
+ idle: number;
248
+ busy: number;
249
+ workers: WorkerAgent[];
250
+ }, never>;
251
+ }
252
+ declare const makeWorkerPool: Effect.Effect<{
253
+ spawn: (specialty: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;
254
+ assignTask: (workflowId: WorkflowId, stepId: string, requiredSpecialty?: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;
255
+ releaseWorker: (agentId: string, success: boolean, latencyMs: number) => Effect.Effect<void, never>;
256
+ getStatus: Effect.Effect<{
257
+ total: number;
258
+ idle: number;
259
+ busy: number;
260
+ workers: {
261
+ readonly agentId: string;
262
+ readonly status: "failed" | "idle" | "busy" | "draining";
263
+ readonly specialty: string;
264
+ readonly currentWorkflowId?: (string & effect_Brand.Brand<"WorkflowId">) | undefined;
265
+ readonly currentStepId?: string | undefined;
266
+ readonly completedTasks: number;
267
+ readonly failedTasks: number;
268
+ readonly avgLatencyMs: number;
269
+ }[];
270
+ }, never, never>;
271
+ }, never, never>;
272
+
273
+ declare const OrchestrationService_base: Context.TagClass<OrchestrationService, "OrchestrationService", {
274
+ readonly executeWorkflow: (name: string, pattern: WorkflowPattern, steps: readonly Omit<WorkflowStep, "status" | "startedAt" | "completedAt" | "error" | "retryCount">[], executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>, options?: {
275
+ maxRetries?: number;
276
+ }) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
277
+ readonly resumeWorkflow: (workflowId: WorkflowId, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | CheckpointError | WorkflowStepError>;
278
+ readonly pauseWorkflow: (workflowId: WorkflowId, reason: string) => Effect.Effect<void, WorkflowError>;
279
+ readonly checkpoint: (workflowId: WorkflowId) => Effect.Effect<Checkpoint, CheckpointError | WorkflowError>;
280
+ readonly getWorkflow: (workflowId: WorkflowId) => Effect.Effect<Workflow, WorkflowError>;
281
+ readonly listWorkflows: (filter?: {
282
+ state?: WorkflowState;
283
+ pattern?: WorkflowPattern;
284
+ }) => Effect.Effect<readonly Workflow[], never>;
285
+ readonly spawnWorker: (specialty: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;
286
+ readonly getEventLog: (workflowId?: WorkflowId) => Effect.Effect<readonly DomainEvent[], never>;
287
+ }>;
288
+ declare class OrchestrationService extends OrchestrationService_base {
289
+ }
290
+ declare const OrchestrationServiceLive: Effect.Effect<{
291
+ readonly executeWorkflow: (name: string, pattern: WorkflowPattern, steps: readonly Omit<WorkflowStep, "status" | "startedAt" | "completedAt" | "error" | "retryCount">[], executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>, options?: {
292
+ maxRetries?: number;
293
+ }) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;
294
+ readonly resumeWorkflow: (workflowId: WorkflowId, executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>) => Effect.Effect<Workflow, WorkflowError | CheckpointError | WorkflowStepError>;
295
+ readonly pauseWorkflow: (workflowId: WorkflowId, reason: string) => Effect.Effect<void, WorkflowError>;
296
+ readonly checkpoint: (workflowId: WorkflowId) => Effect.Effect<Checkpoint, CheckpointError | WorkflowError>;
297
+ readonly getWorkflow: (workflowId: WorkflowId) => Effect.Effect<Workflow, WorkflowError>;
298
+ readonly listWorkflows: (filter?: {
299
+ state?: WorkflowState;
300
+ pattern?: WorkflowPattern;
301
+ }) => Effect.Effect<readonly Workflow[], never>;
302
+ readonly spawnWorker: (specialty: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;
303
+ readonly getEventLog: (workflowId?: WorkflowId) => Effect.Effect<readonly DomainEvent[], never>;
304
+ }, never, never>;
305
+
306
+ declare const createOrchestrationLayer: () => Layer.Layer<OrchestrationService>;
307
+
308
+ export { type Checkpoint, CheckpointError, CheckpointSchema, type DomainEvent, type EventSourcing, OrchestrationService, OrchestrationServiceLive, type WorkerAgent, WorkerAgentSchema, type WorkerPool, WorkerPoolError, type Workflow, type WorkflowEngine, WorkflowError, type WorkflowId, WorkflowIdSchema, WorkflowPattern, WorkflowSchema, WorkflowState, type WorkflowStep, WorkflowStepError, WorkflowStepSchema, createOrchestrationLayer, makeEventSourcing, makeWorkerPool, makeWorkflowEngine };
package/dist/index.js ADDED
@@ -0,0 +1,549 @@
1
+ // src/types.ts
2
+ import { Schema } from "effect";
3
+ var WorkflowIdSchema = Schema.String.pipe(Schema.brand("WorkflowId"));
4
+ var WorkflowPattern = Schema.Literal(
5
+ "sequential",
6
+ "parallel",
7
+ "map-reduce",
8
+ "pipeline",
9
+ "orchestrator-workers"
10
+ );
11
+ var WorkflowState = Schema.Literal(
12
+ "pending",
13
+ "running",
14
+ "paused",
15
+ "completed",
16
+ "failed",
17
+ "recovering"
18
+ );
19
+ var WorkflowStepSchema = Schema.Struct({
20
+ id: Schema.String,
21
+ name: Schema.String,
22
+ agentId: Schema.optional(Schema.String),
23
+ input: Schema.Unknown,
24
+ output: Schema.optional(Schema.Unknown),
25
+ status: Schema.Literal("pending", "running", "completed", "failed", "skipped"),
26
+ startedAt: Schema.optional(Schema.DateFromSelf),
27
+ completedAt: Schema.optional(Schema.DateFromSelf),
28
+ error: Schema.optional(Schema.String),
29
+ retryCount: Schema.Number,
30
+ maxRetries: Schema.Number
31
+ });
32
+ var WorkflowSchema = Schema.Struct({
33
+ id: WorkflowIdSchema,
34
+ name: Schema.String,
35
+ pattern: WorkflowPattern,
36
+ steps: Schema.Array(WorkflowStepSchema),
37
+ state: WorkflowState,
38
+ createdAt: Schema.DateFromSelf,
39
+ updatedAt: Schema.DateFromSelf,
40
+ completedAt: Schema.optional(Schema.DateFromSelf),
41
+ metadata: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Unknown }))
42
+ });
43
+ var CheckpointSchema = Schema.Struct({
44
+ id: Schema.String,
45
+ workflowId: WorkflowIdSchema,
46
+ timestamp: Schema.DateFromSelf,
47
+ state: WorkflowSchema,
48
+ eventIndex: Schema.Number
49
+ });
50
+ var WorkerAgentSchema = Schema.Struct({
51
+ agentId: Schema.String,
52
+ specialty: Schema.String,
53
+ status: Schema.Literal("idle", "busy", "failed", "draining"),
54
+ currentWorkflowId: Schema.optional(WorkflowIdSchema),
55
+ currentStepId: Schema.optional(Schema.String),
56
+ completedTasks: Schema.Number,
57
+ failedTasks: Schema.Number,
58
+ avgLatencyMs: Schema.Number
59
+ });
60
+
61
+ // src/errors.ts
62
+ import { Data } from "effect";
63
+ var WorkflowError = class extends Data.TaggedError("WorkflowError") {
64
+ };
65
+ var WorkflowStepError = class extends Data.TaggedError("WorkflowStepError") {
66
+ };
67
+ var CheckpointError = class extends Data.TaggedError("CheckpointError") {
68
+ };
69
+ var WorkerPoolError = class extends Data.TaggedError("WorkerPoolError") {
70
+ };
71
+
72
+ // src/workflows/workflow-engine.ts
73
+ import { Effect, Ref } from "effect";
74
+ var makeWorkflowEngine = Effect.gen(function* () {
75
+ const workflowsRef = yield* Ref.make(/* @__PURE__ */ new Map());
76
+ const eventLogRef = yield* Ref.make([]);
77
+ const appendEvent = (event) => Ref.update(eventLogRef, (events) => [...events, event]);
78
+ const updateWorkflow = (workflow) => Ref.update(workflowsRef, (map) => {
79
+ const newMap = new Map(map);
80
+ newMap.set(workflow.id, workflow);
81
+ return newMap;
82
+ });
83
+ const createCheckpoint = (workflow) => Effect.gen(function* () {
84
+ const events = yield* Ref.get(eventLogRef);
85
+ return {
86
+ id: crypto.randomUUID(),
87
+ workflowId: workflow.id,
88
+ timestamp: /* @__PURE__ */ new Date(),
89
+ state: workflow,
90
+ eventIndex: events.length
91
+ };
92
+ });
93
+ const executeSequential = (workflow, executeStep) => Effect.gen(function* () {
94
+ let current = { ...workflow, state: "running" };
95
+ yield* updateWorkflow(current);
96
+ for (const step of current.steps) {
97
+ yield* appendEvent({
98
+ type: "StepStarted",
99
+ workflowId: workflow.id,
100
+ timestamp: /* @__PURE__ */ new Date(),
101
+ payload: { stepId: step.id, agentId: step.agentId ?? "default" }
102
+ });
103
+ const result = yield* executeStep(step);
104
+ yield* appendEvent({
105
+ type: "StepCompleted",
106
+ workflowId: workflow.id,
107
+ timestamp: /* @__PURE__ */ new Date(),
108
+ payload: { stepId: step.id, output: result }
109
+ });
110
+ current = {
111
+ ...current,
112
+ steps: current.steps.map(
113
+ (s) => s.id === step.id ? { ...s, status: "completed", output: result, completedAt: /* @__PURE__ */ new Date() } : s
114
+ ),
115
+ updatedAt: /* @__PURE__ */ new Date()
116
+ };
117
+ yield* updateWorkflow(current);
118
+ }
119
+ current = { ...current, state: "completed", completedAt: /* @__PURE__ */ new Date() };
120
+ yield* updateWorkflow(current);
121
+ yield* appendEvent({
122
+ type: "WorkflowCompleted",
123
+ workflowId: workflow.id,
124
+ timestamp: /* @__PURE__ */ new Date(),
125
+ payload: { result: current.steps.map((s) => s.output) }
126
+ });
127
+ return current;
128
+ });
129
+ const executeParallel = (workflow, executeStep) => Effect.gen(function* () {
130
+ let current = { ...workflow, state: "running" };
131
+ yield* updateWorkflow(current);
132
+ const results = yield* Effect.all(
133
+ current.steps.map(
134
+ (step) => Effect.gen(function* () {
135
+ yield* appendEvent({
136
+ type: "StepStarted",
137
+ workflowId: workflow.id,
138
+ timestamp: /* @__PURE__ */ new Date(),
139
+ payload: { stepId: step.id, agentId: step.agentId ?? "default" }
140
+ });
141
+ const result = yield* executeStep(step);
142
+ yield* appendEvent({
143
+ type: "StepCompleted",
144
+ workflowId: workflow.id,
145
+ timestamp: /* @__PURE__ */ new Date(),
146
+ payload: { stepId: step.id, output: result }
147
+ });
148
+ return { stepId: step.id, output: result };
149
+ })
150
+ ),
151
+ { concurrency: "unbounded" }
152
+ );
153
+ current = {
154
+ ...current,
155
+ state: "completed",
156
+ completedAt: /* @__PURE__ */ new Date(),
157
+ steps: current.steps.map((s) => {
158
+ const result = results.find((r) => r.stepId === s.id);
159
+ return result ? { ...s, status: "completed", output: result.output, completedAt: /* @__PURE__ */ new Date() } : s;
160
+ })
161
+ };
162
+ yield* updateWorkflow(current);
163
+ yield* appendEvent({
164
+ type: "WorkflowCompleted",
165
+ workflowId: workflow.id,
166
+ timestamp: /* @__PURE__ */ new Date(),
167
+ payload: { result: results.map((r) => r.output) }
168
+ });
169
+ return current;
170
+ });
171
+ const executeMapReduce = (workflow, executeStep) => Effect.gen(function* () {
172
+ const mapSteps = workflow.steps.slice(0, -1);
173
+ const reduceStep = workflow.steps[workflow.steps.length - 1];
174
+ const mapResults = yield* Effect.all(
175
+ mapSteps.map((step) => executeStep(step)),
176
+ { concurrency: "unbounded" }
177
+ );
178
+ const reduceInput = { ...reduceStep, input: mapResults };
179
+ const finalResult = yield* executeStep(reduceInput);
180
+ const completedWorkflow = {
181
+ ...workflow,
182
+ state: "completed",
183
+ completedAt: /* @__PURE__ */ new Date(),
184
+ updatedAt: /* @__PURE__ */ new Date(),
185
+ steps: [
186
+ ...mapSteps.map((s, i) => ({
187
+ ...s,
188
+ status: "completed",
189
+ output: mapResults[i],
190
+ completedAt: /* @__PURE__ */ new Date()
191
+ })),
192
+ { ...reduceStep, status: "completed", output: finalResult, completedAt: /* @__PURE__ */ new Date() }
193
+ ]
194
+ };
195
+ yield* updateWorkflow(completedWorkflow);
196
+ return completedWorkflow;
197
+ });
198
+ return {
199
+ executeSequential,
200
+ executeParallel,
201
+ executeMapReduce,
202
+ appendEvent,
203
+ updateWorkflow,
204
+ createCheckpoint,
205
+ workflowsRef,
206
+ eventLogRef
207
+ };
208
+ });
209
+
210
+ // src/durable/event-sourcing.ts
211
+ import { Effect as Effect2, Ref as Ref2 } from "effect";
212
+ var makeEventSourcing = Effect2.gen(function* () {
213
+ const checkpointsRef = yield* Ref2.make(/* @__PURE__ */ new Map());
214
+ const saveCheckpoint = (checkpoint) => Ref2.update(checkpointsRef, (map) => {
215
+ const newMap = new Map(map);
216
+ const existing = newMap.get(checkpoint.workflowId) ?? [];
217
+ newMap.set(checkpoint.workflowId, [...existing, checkpoint]);
218
+ return newMap;
219
+ }).pipe(
220
+ Effect2.mapError(() => new CheckpointError({ message: "Failed to save checkpoint", workflowId: checkpoint.workflowId }))
221
+ );
222
+ const loadLatestCheckpoint = (workflowId) => Effect2.gen(function* () {
223
+ const map = yield* Ref2.get(checkpointsRef);
224
+ const checkpoints = map.get(workflowId);
225
+ if (!checkpoints || checkpoints.length === 0) {
226
+ return yield* Effect2.fail(
227
+ new CheckpointError({ message: `No checkpoint found for workflow ${workflowId}`, workflowId })
228
+ );
229
+ }
230
+ return checkpoints[checkpoints.length - 1];
231
+ });
232
+ const replayFromCheckpoint = (checkpoint, events) => Effect2.gen(function* () {
233
+ let workflow = checkpoint.state;
234
+ const eventsToReplay = events.slice(checkpoint.eventIndex);
235
+ for (const event of eventsToReplay) {
236
+ workflow = applyEvent(workflow, event);
237
+ }
238
+ return workflow;
239
+ });
240
+ return { saveCheckpoint, loadLatestCheckpoint, replayFromCheckpoint };
241
+ });
242
+ function applyEvent(workflow, event) {
243
+ switch (event.type) {
244
+ case "StepStarted":
245
+ return {
246
+ ...workflow,
247
+ steps: workflow.steps.map(
248
+ (s) => s.id === event.payload.stepId ? { ...s, status: "running", startedAt: event.timestamp, agentId: event.payload.agentId } : s
249
+ ),
250
+ updatedAt: event.timestamp
251
+ };
252
+ case "StepCompleted":
253
+ return {
254
+ ...workflow,
255
+ steps: workflow.steps.map(
256
+ (s) => s.id === event.payload.stepId ? { ...s, status: "completed", output: event.payload.output, completedAt: event.timestamp } : s
257
+ ),
258
+ updatedAt: event.timestamp
259
+ };
260
+ case "StepFailed":
261
+ return {
262
+ ...workflow,
263
+ steps: workflow.steps.map(
264
+ (s) => s.id === event.payload.stepId ? { ...s, status: "failed", error: event.payload.error, retryCount: s.retryCount + 1 } : s
265
+ ),
266
+ updatedAt: event.timestamp
267
+ };
268
+ case "WorkflowCompleted":
269
+ return { ...workflow, state: "completed", completedAt: event.timestamp, updatedAt: event.timestamp };
270
+ case "WorkflowFailed":
271
+ return { ...workflow, state: "failed", updatedAt: event.timestamp };
272
+ case "WorkflowPaused":
273
+ return { ...workflow, state: "paused", updatedAt: event.timestamp };
274
+ case "WorkflowResumed":
275
+ return { ...workflow, state: "running", updatedAt: event.timestamp };
276
+ default:
277
+ return workflow;
278
+ }
279
+ }
280
+
281
+ // src/multi-agent/worker-pool.ts
282
+ import { Effect as Effect3, Ref as Ref3 } from "effect";
283
+ var makeWorkerPool = Effect3.gen(function* () {
284
+ const workersRef = yield* Ref3.make(/* @__PURE__ */ new Map());
285
+ const spawn = (specialty) => Effect3.gen(function* () {
286
+ const worker = {
287
+ agentId: `worker-${crypto.randomUUID().slice(0, 8)}`,
288
+ specialty,
289
+ status: "idle",
290
+ completedTasks: 0,
291
+ failedTasks: 0,
292
+ avgLatencyMs: 0
293
+ };
294
+ yield* Ref3.update(workersRef, (map) => {
295
+ const newMap = new Map(map);
296
+ newMap.set(worker.agentId, worker);
297
+ return newMap;
298
+ });
299
+ return worker;
300
+ });
301
+ const assignTask = (workflowId, stepId, requiredSpecialty) => Effect3.gen(function* () {
302
+ const workers = yield* Ref3.get(workersRef);
303
+ let candidate;
304
+ for (const worker of workers.values()) {
305
+ if (worker.status === "idle") {
306
+ if (!requiredSpecialty || worker.specialty === requiredSpecialty) {
307
+ candidate = worker;
308
+ break;
309
+ }
310
+ }
311
+ }
312
+ if (!candidate) {
313
+ return yield* Effect3.fail(
314
+ new WorkerPoolError({
315
+ message: `No idle worker available${requiredSpecialty ? ` with specialty "${requiredSpecialty}"` : ""}`,
316
+ availableWorkers: [...workers.values()].filter((w) => w.status === "idle").length,
317
+ requiredWorkers: 1
318
+ })
319
+ );
320
+ }
321
+ const assigned = {
322
+ ...candidate,
323
+ status: "busy",
324
+ currentWorkflowId: workflowId,
325
+ currentStepId: stepId
326
+ };
327
+ yield* Ref3.update(workersRef, (map) => {
328
+ const newMap = new Map(map);
329
+ newMap.set(assigned.agentId, assigned);
330
+ return newMap;
331
+ });
332
+ return assigned;
333
+ });
334
+ const releaseWorker = (agentId, success, latencyMs) => Ref3.update(workersRef, (map) => {
335
+ const newMap = new Map(map);
336
+ const worker = newMap.get(agentId);
337
+ if (worker) {
338
+ const totalTasks = worker.completedTasks + worker.failedTasks + 1;
339
+ newMap.set(agentId, {
340
+ ...worker,
341
+ status: "idle",
342
+ currentWorkflowId: void 0,
343
+ currentStepId: void 0,
344
+ completedTasks: success ? worker.completedTasks + 1 : worker.completedTasks,
345
+ failedTasks: success ? worker.failedTasks : worker.failedTasks + 1,
346
+ avgLatencyMs: (worker.avgLatencyMs * (totalTasks - 1) + latencyMs) / totalTasks
347
+ });
348
+ }
349
+ return newMap;
350
+ });
351
+ const getStatus = Effect3.gen(function* () {
352
+ const workers = yield* Ref3.get(workersRef);
353
+ const all = [...workers.values()];
354
+ return {
355
+ total: all.length,
356
+ idle: all.filter((w) => w.status === "idle").length,
357
+ busy: all.filter((w) => w.status === "busy").length,
358
+ workers: all
359
+ };
360
+ });
361
+ return { spawn, assignTask, releaseWorker, getStatus };
362
+ });
363
+
364
+ // src/orchestration-service.ts
365
+ import { Effect as Effect4, Context, Ref as Ref4 } from "effect";
366
+ var OrchestrationService = class extends Context.Tag("OrchestrationService")() {
367
+ };
368
+ var OrchestrationServiceLive = Effect4.gen(function* () {
369
+ const engine = yield* makeWorkflowEngine;
370
+ const eventSourcing = yield* makeEventSourcing;
371
+ const workerPool = yield* makeWorkerPool;
372
+ const executeWorkflow = (name, pattern, steps, executeStep, options) => Effect4.gen(function* () {
373
+ const maxRetries = options?.maxRetries ?? 3;
374
+ const workflowId = crypto.randomUUID();
375
+ const fullSteps = steps.map((s) => ({
376
+ ...s,
377
+ status: "pending",
378
+ retryCount: 0,
379
+ maxRetries
380
+ }));
381
+ const workflow = {
382
+ id: workflowId,
383
+ name,
384
+ pattern,
385
+ steps: fullSteps,
386
+ state: "pending",
387
+ createdAt: /* @__PURE__ */ new Date(),
388
+ updatedAt: /* @__PURE__ */ new Date()
389
+ };
390
+ yield* engine.updateWorkflow(workflow);
391
+ yield* engine.appendEvent({
392
+ type: "WorkflowCreated",
393
+ workflowId,
394
+ timestamp: /* @__PURE__ */ new Date(),
395
+ payload: workflow
396
+ });
397
+ let result;
398
+ switch (pattern) {
399
+ case "parallel":
400
+ result = yield* engine.executeParallel(workflow, executeStep);
401
+ break;
402
+ case "map-reduce":
403
+ result = yield* engine.executeMapReduce(workflow, executeStep);
404
+ break;
405
+ case "sequential":
406
+ case "pipeline":
407
+ case "orchestrator-workers":
408
+ default:
409
+ result = yield* engine.executeSequential(workflow, executeStep);
410
+ break;
411
+ }
412
+ const cp = yield* engine.createCheckpoint(result);
413
+ yield* eventSourcing.saveCheckpoint(cp).pipe(Effect4.catchAll(() => Effect4.void));
414
+ return result;
415
+ });
416
+ const resumeWorkflow = (workflowId, executeStep) => Effect4.gen(function* () {
417
+ const checkpoint2 = yield* eventSourcing.loadLatestCheckpoint(workflowId);
418
+ const events = yield* Ref4.get(engine.eventLogRef);
419
+ const workflow = yield* eventSourcing.replayFromCheckpoint(checkpoint2, events);
420
+ const resumed = { ...workflow, state: "running", updatedAt: /* @__PURE__ */ new Date() };
421
+ yield* engine.updateWorkflow(resumed);
422
+ yield* engine.appendEvent({
423
+ type: "WorkflowResumed",
424
+ workflowId,
425
+ timestamp: /* @__PURE__ */ new Date(),
426
+ payload: {}
427
+ });
428
+ const pendingSteps = resumed.steps.filter((s) => s.status === "pending" || s.status === "failed");
429
+ let current = resumed;
430
+ for (const step of pendingSteps) {
431
+ yield* engine.appendEvent({
432
+ type: "StepStarted",
433
+ workflowId,
434
+ timestamp: /* @__PURE__ */ new Date(),
435
+ payload: { stepId: step.id, agentId: step.agentId ?? "default" }
436
+ });
437
+ const result = yield* executeStep(step);
438
+ yield* engine.appendEvent({
439
+ type: "StepCompleted",
440
+ workflowId,
441
+ timestamp: /* @__PURE__ */ new Date(),
442
+ payload: { stepId: step.id, output: result }
443
+ });
444
+ current = {
445
+ ...current,
446
+ steps: current.steps.map(
447
+ (s) => s.id === step.id ? { ...s, status: "completed", output: result, completedAt: /* @__PURE__ */ new Date() } : s
448
+ ),
449
+ updatedAt: /* @__PURE__ */ new Date()
450
+ };
451
+ yield* engine.updateWorkflow(current);
452
+ }
453
+ current = { ...current, state: "completed", completedAt: /* @__PURE__ */ new Date() };
454
+ yield* engine.updateWorkflow(current);
455
+ return current;
456
+ });
457
+ const pauseWorkflow = (workflowId, reason) => Effect4.gen(function* () {
458
+ const workflows = yield* Ref4.get(engine.workflowsRef);
459
+ const workflow = workflows.get(workflowId);
460
+ if (!workflow) {
461
+ return yield* Effect4.fail(
462
+ new WorkflowError({ message: `Workflow ${workflowId} not found`, workflowId })
463
+ );
464
+ }
465
+ const paused = { ...workflow, state: "paused", updatedAt: /* @__PURE__ */ new Date() };
466
+ yield* engine.updateWorkflow(paused);
467
+ yield* engine.appendEvent({
468
+ type: "WorkflowPaused",
469
+ workflowId,
470
+ timestamp: /* @__PURE__ */ new Date(),
471
+ payload: { reason }
472
+ });
473
+ });
474
+ const checkpoint = (workflowId) => Effect4.gen(function* () {
475
+ const workflows = yield* Ref4.get(engine.workflowsRef);
476
+ const workflow = workflows.get(workflowId);
477
+ if (!workflow) {
478
+ return yield* Effect4.fail(
479
+ new WorkflowError({ message: `Workflow ${workflowId} not found`, workflowId })
480
+ );
481
+ }
482
+ const cp = yield* engine.createCheckpoint(workflow);
483
+ yield* eventSourcing.saveCheckpoint(cp);
484
+ return cp;
485
+ });
486
+ const getWorkflow = (workflowId) => Effect4.gen(function* () {
487
+ const workflows = yield* Ref4.get(engine.workflowsRef);
488
+ const workflow = workflows.get(workflowId);
489
+ if (!workflow) {
490
+ return yield* Effect4.fail(
491
+ new WorkflowError({ message: `Workflow ${workflowId} not found`, workflowId })
492
+ );
493
+ }
494
+ return workflow;
495
+ });
496
+ const listWorkflows = (filter) => Effect4.gen(function* () {
497
+ const workflows = yield* Ref4.get(engine.workflowsRef);
498
+ let all = [...workflows.values()];
499
+ if (filter?.state) {
500
+ all = all.filter((w) => w.state === filter.state);
501
+ }
502
+ if (filter?.pattern) {
503
+ all = all.filter((w) => w.pattern === filter.pattern);
504
+ }
505
+ return all;
506
+ });
507
+ const spawnWorker = (specialty) => workerPool.spawn(specialty);
508
+ const getEventLog = (workflowId) => Effect4.gen(function* () {
509
+ const events = yield* Ref4.get(engine.eventLogRef);
510
+ if (workflowId) {
511
+ return events.filter((e) => e.workflowId === workflowId);
512
+ }
513
+ return events;
514
+ });
515
+ return {
516
+ executeWorkflow,
517
+ resumeWorkflow,
518
+ pauseWorkflow,
519
+ checkpoint,
520
+ getWorkflow,
521
+ listWorkflows,
522
+ spawnWorker,
523
+ getEventLog
524
+ };
525
+ });
526
+
527
+ // src/runtime.ts
528
+ import { Layer } from "effect";
529
+ var createOrchestrationLayer = () => Layer.effect(OrchestrationService, OrchestrationServiceLive);
530
+ export {
531
+ CheckpointError,
532
+ CheckpointSchema,
533
+ OrchestrationService,
534
+ OrchestrationServiceLive,
535
+ WorkerAgentSchema,
536
+ WorkerPoolError,
537
+ WorkflowError,
538
+ WorkflowIdSchema,
539
+ WorkflowPattern,
540
+ WorkflowSchema,
541
+ WorkflowState,
542
+ WorkflowStepError,
543
+ WorkflowStepSchema,
544
+ createOrchestrationLayer,
545
+ makeEventSourcing,
546
+ makeWorkerPool,
547
+ makeWorkflowEngine
548
+ };
549
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/errors.ts","../src/workflows/workflow-engine.ts","../src/durable/event-sourcing.ts","../src/multi-agent/worker-pool.ts","../src/orchestration-service.ts","../src/runtime.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n// ─── Workflow ───\n\nexport const WorkflowIdSchema = Schema.String.pipe(Schema.brand(\"WorkflowId\"));\nexport type WorkflowId = typeof WorkflowIdSchema.Type;\n\nexport const WorkflowPattern = Schema.Literal(\n \"sequential\", \"parallel\", \"map-reduce\", \"pipeline\", \"orchestrator-workers\",\n);\nexport type WorkflowPattern = typeof WorkflowPattern.Type;\n\nexport const WorkflowState = Schema.Literal(\n \"pending\", \"running\", \"paused\", \"completed\", \"failed\", \"recovering\",\n);\nexport type WorkflowState = typeof WorkflowState.Type;\n\nexport const WorkflowStepSchema = Schema.Struct({\n id: Schema.String,\n name: Schema.String,\n agentId: Schema.optional(Schema.String),\n input: Schema.Unknown,\n output: Schema.optional(Schema.Unknown),\n status: Schema.Literal(\"pending\", \"running\", \"completed\", \"failed\", \"skipped\"),\n startedAt: Schema.optional(Schema.DateFromSelf),\n completedAt: Schema.optional(Schema.DateFromSelf),\n error: Schema.optional(Schema.String),\n retryCount: Schema.Number,\n maxRetries: Schema.Number,\n});\nexport type WorkflowStep = typeof WorkflowStepSchema.Type;\n\nexport const WorkflowSchema = Schema.Struct({\n id: WorkflowIdSchema,\n name: Schema.String,\n pattern: WorkflowPattern,\n steps: Schema.Array(WorkflowStepSchema),\n state: WorkflowState,\n createdAt: Schema.DateFromSelf,\n updatedAt: Schema.DateFromSelf,\n completedAt: Schema.optional(Schema.DateFromSelf),\n metadata: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n});\nexport type Workflow = typeof WorkflowSchema.Type;\n\n// ─── Domain Events ───\n\nexport type DomainEvent =\n | { type: \"WorkflowCreated\"; workflowId: WorkflowId; timestamp: Date; payload: Workflow }\n | { type: \"StepStarted\"; workflowId: WorkflowId; timestamp: Date; payload: { stepId: string; agentId: string } }\n | { type: \"StepCompleted\"; workflowId: WorkflowId; timestamp: Date; payload: { stepId: string; output: unknown } }\n | { type: \"StepFailed\"; workflowId: WorkflowId; timestamp: Date; payload: { stepId: string; error: string } }\n | { type: \"WorkflowCompleted\"; workflowId: WorkflowId; timestamp: Date; payload: { result: unknown } }\n | { type: \"WorkflowFailed\"; workflowId: WorkflowId; timestamp: Date; payload: { error: string } }\n | { type: \"WorkflowPaused\"; workflowId: WorkflowId; timestamp: Date; payload: { reason: string } }\n | { type: \"WorkflowResumed\"; workflowId: WorkflowId; timestamp: Date; payload: Record<string, never> };\n\n// ─── Checkpoint ───\n\nexport const CheckpointSchema = Schema.Struct({\n id: Schema.String,\n workflowId: WorkflowIdSchema,\n timestamp: Schema.DateFromSelf,\n state: WorkflowSchema,\n eventIndex: Schema.Number,\n});\nexport type Checkpoint = typeof CheckpointSchema.Type;\n\n// ─── Worker Agent ───\n\nexport const WorkerAgentSchema = Schema.Struct({\n agentId: Schema.String,\n specialty: Schema.String,\n status: Schema.Literal(\"idle\", \"busy\", \"failed\", \"draining\"),\n currentWorkflowId: Schema.optional(WorkflowIdSchema),\n currentStepId: Schema.optional(Schema.String),\n completedTasks: Schema.Number,\n failedTasks: Schema.Number,\n avgLatencyMs: Schema.Number,\n});\nexport type WorkerAgent = typeof WorkerAgentSchema.Type;\n","import { Data } from \"effect\";\n\nexport class WorkflowError extends Data.TaggedError(\"WorkflowError\")<{\n readonly message: string;\n readonly workflowId?: string;\n readonly cause?: unknown;\n}> {}\n\nexport class WorkflowStepError extends Data.TaggedError(\"WorkflowStepError\")<{\n readonly message: string;\n readonly workflowId: string;\n readonly stepId: string;\n readonly cause?: unknown;\n}> {}\n\nexport class CheckpointError extends Data.TaggedError(\"CheckpointError\")<{\n readonly message: string;\n readonly workflowId: string;\n}> {}\n\nexport class WorkerPoolError extends Data.TaggedError(\"WorkerPoolError\")<{\n readonly message: string;\n readonly availableWorkers: number;\n readonly requiredWorkers: number;\n}> {}\n","import { Effect, Ref } from \"effect\";\nimport type { Workflow, WorkflowStep, WorkflowId, DomainEvent, Checkpoint } from \"../types.js\";\nimport type { WorkflowStepError, WorkflowError } from \"../errors.js\";\n\nexport interface WorkflowEngine {\n readonly executeSequential: (\n workflow: Workflow,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;\n readonly executeParallel: (\n workflow: Workflow,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;\n readonly executeMapReduce: (\n workflow: Workflow,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;\n readonly appendEvent: (event: DomainEvent) => Effect.Effect<void, never>;\n readonly updateWorkflow: (workflow: Workflow) => Effect.Effect<void, never>;\n readonly createCheckpoint: (workflow: Workflow) => Effect.Effect<Checkpoint, never>;\n readonly workflowsRef: Ref.Ref<Map<string, Workflow>>;\n readonly eventLogRef: Ref.Ref<DomainEvent[]>;\n}\n\nexport const makeWorkflowEngine = Effect.gen(function* () {\n const workflowsRef = yield* Ref.make<Map<string, Workflow>>(new Map());\n const eventLogRef = yield* Ref.make<DomainEvent[]>([]);\n\n const appendEvent = (event: DomainEvent): Effect.Effect<void, never> =>\n Ref.update(eventLogRef, (events) => [...events, event]);\n\n const updateWorkflow = (workflow: Workflow): Effect.Effect<void, never> =>\n Ref.update(workflowsRef, (map) => {\n const newMap = new Map(map);\n newMap.set(workflow.id, workflow);\n return newMap;\n });\n\n const createCheckpoint = (workflow: Workflow): Effect.Effect<Checkpoint, never> =>\n Effect.gen(function* () {\n const events = yield* Ref.get(eventLogRef);\n return {\n id: crypto.randomUUID(),\n workflowId: workflow.id,\n timestamp: new Date(),\n state: workflow,\n eventIndex: events.length,\n };\n });\n\n const executeSequential = (\n workflow: Workflow,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ): Effect.Effect<Workflow, WorkflowError | WorkflowStepError> =>\n Effect.gen(function* () {\n let current: Workflow = { ...workflow, state: \"running\" as const };\n yield* updateWorkflow(current);\n\n for (const step of current.steps) {\n yield* appendEvent({\n type: \"StepStarted\",\n workflowId: workflow.id,\n timestamp: new Date(),\n payload: { stepId: step.id, agentId: step.agentId ?? \"default\" },\n });\n\n const result = yield* executeStep(step);\n\n yield* appendEvent({\n type: \"StepCompleted\",\n workflowId: workflow.id,\n timestamp: new Date(),\n payload: { stepId: step.id, output: result },\n });\n\n current = {\n ...current,\n steps: current.steps.map((s) =>\n s.id === step.id\n ? { ...s, status: \"completed\" as const, output: result, completedAt: new Date() }\n : s,\n ),\n updatedAt: new Date(),\n };\n yield* updateWorkflow(current);\n }\n\n current = { ...current, state: \"completed\" as const, completedAt: new Date() };\n yield* updateWorkflow(current);\n\n yield* appendEvent({\n type: \"WorkflowCompleted\",\n workflowId: workflow.id,\n timestamp: new Date(),\n payload: { result: current.steps.map((s) => s.output) },\n });\n\n return current;\n });\n\n const executeParallel = (\n workflow: Workflow,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ): Effect.Effect<Workflow, WorkflowError | WorkflowStepError> =>\n Effect.gen(function* () {\n let current: Workflow = { ...workflow, state: \"running\" as const };\n yield* updateWorkflow(current);\n\n const results = yield* Effect.all(\n current.steps.map((step) =>\n Effect.gen(function* () {\n yield* appendEvent({\n type: \"StepStarted\",\n workflowId: workflow.id,\n timestamp: new Date(),\n payload: { stepId: step.id, agentId: step.agentId ?? \"default\" },\n });\n const result = yield* executeStep(step);\n yield* appendEvent({\n type: \"StepCompleted\",\n workflowId: workflow.id,\n timestamp: new Date(),\n payload: { stepId: step.id, output: result },\n });\n return { stepId: step.id, output: result };\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n\n current = {\n ...current,\n state: \"completed\" as const,\n completedAt: new Date(),\n steps: current.steps.map((s) => {\n const result = results.find((r) => r.stepId === s.id);\n return result\n ? { ...s, status: \"completed\" as const, output: result.output, completedAt: new Date() }\n : s;\n }),\n };\n yield* updateWorkflow(current);\n\n yield* appendEvent({\n type: \"WorkflowCompleted\",\n workflowId: workflow.id,\n timestamp: new Date(),\n payload: { result: results.map((r) => r.output) },\n });\n\n return current;\n });\n\n const executeMapReduce = (\n workflow: Workflow,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ): Effect.Effect<Workflow, WorkflowError | WorkflowStepError> =>\n Effect.gen(function* () {\n const mapSteps = workflow.steps.slice(0, -1);\n const reduceStep = workflow.steps[workflow.steps.length - 1]!;\n\n // Map phase: parallel\n const mapResults = yield* Effect.all(\n mapSteps.map((step) => executeStep(step)),\n { concurrency: \"unbounded\" },\n );\n\n // Reduce phase\n const reduceInput = { ...reduceStep, input: mapResults };\n const finalResult = yield* executeStep(reduceInput);\n\n const completedWorkflow: Workflow = {\n ...workflow,\n state: \"completed\" as const,\n completedAt: new Date(),\n updatedAt: new Date(),\n steps: [\n ...mapSteps.map((s, i) => ({\n ...s,\n status: \"completed\" as const,\n output: mapResults[i],\n completedAt: new Date(),\n })),\n { ...reduceStep, status: \"completed\" as const, output: finalResult, completedAt: new Date() },\n ],\n };\n yield* updateWorkflow(completedWorkflow);\n\n return completedWorkflow;\n });\n\n return {\n executeSequential,\n executeParallel,\n executeMapReduce,\n appendEvent,\n updateWorkflow,\n createCheckpoint,\n workflowsRef,\n eventLogRef,\n } satisfies WorkflowEngine;\n});\n","import { Effect, Ref } from \"effect\";\nimport type { Workflow, WorkflowId, DomainEvent, Checkpoint } from \"../types.js\";\nimport { CheckpointError } from \"../errors.js\";\n\nexport interface EventSourcing {\n readonly saveCheckpoint: (checkpoint: Checkpoint) => Effect.Effect<void, CheckpointError>;\n readonly loadLatestCheckpoint: (workflowId: WorkflowId) => Effect.Effect<Checkpoint, CheckpointError>;\n readonly replayFromCheckpoint: (checkpoint: Checkpoint, events: readonly DomainEvent[]) => Effect.Effect<Workflow, CheckpointError>;\n}\n\nexport const makeEventSourcing = Effect.gen(function* () {\n const checkpointsRef = yield* Ref.make<Map<string, Checkpoint[]>>(new Map());\n\n const saveCheckpoint = (checkpoint: Checkpoint): Effect.Effect<void, CheckpointError> =>\n Ref.update(checkpointsRef, (map) => {\n const newMap = new Map(map);\n const existing = newMap.get(checkpoint.workflowId) ?? [];\n newMap.set(checkpoint.workflowId, [...existing, checkpoint]);\n return newMap;\n }).pipe(\n Effect.mapError(() => new CheckpointError({ message: \"Failed to save checkpoint\", workflowId: checkpoint.workflowId })),\n );\n\n const loadLatestCheckpoint = (workflowId: WorkflowId): Effect.Effect<Checkpoint, CheckpointError> =>\n Effect.gen(function* () {\n const map = yield* Ref.get(checkpointsRef);\n const checkpoints = map.get(workflowId);\n if (!checkpoints || checkpoints.length === 0) {\n return yield* Effect.fail(\n new CheckpointError({ message: `No checkpoint found for workflow ${workflowId}`, workflowId }),\n );\n }\n return checkpoints[checkpoints.length - 1]!;\n });\n\n const replayFromCheckpoint = (\n checkpoint: Checkpoint,\n events: readonly DomainEvent[],\n ): Effect.Effect<Workflow, CheckpointError> =>\n Effect.gen(function* () {\n let workflow = checkpoint.state;\n const eventsToReplay = events.slice(checkpoint.eventIndex);\n\n for (const event of eventsToReplay) {\n workflow = applyEvent(workflow, event);\n }\n\n return workflow;\n });\n\n return { saveCheckpoint, loadLatestCheckpoint, replayFromCheckpoint } satisfies EventSourcing;\n});\n\nfunction applyEvent(workflow: Workflow, event: DomainEvent): Workflow {\n switch (event.type) {\n case \"StepStarted\":\n return {\n ...workflow,\n steps: workflow.steps.map((s) =>\n s.id === event.payload.stepId\n ? { ...s, status: \"running\" as const, startedAt: event.timestamp, agentId: event.payload.agentId }\n : s,\n ),\n updatedAt: event.timestamp,\n };\n case \"StepCompleted\":\n return {\n ...workflow,\n steps: workflow.steps.map((s) =>\n s.id === event.payload.stepId\n ? { ...s, status: \"completed\" as const, output: event.payload.output, completedAt: event.timestamp }\n : s,\n ),\n updatedAt: event.timestamp,\n };\n case \"StepFailed\":\n return {\n ...workflow,\n steps: workflow.steps.map((s) =>\n s.id === event.payload.stepId\n ? { ...s, status: \"failed\" as const, error: event.payload.error, retryCount: s.retryCount + 1 }\n : s,\n ),\n updatedAt: event.timestamp,\n };\n case \"WorkflowCompleted\":\n return { ...workflow, state: \"completed\" as const, completedAt: event.timestamp, updatedAt: event.timestamp };\n case \"WorkflowFailed\":\n return { ...workflow, state: \"failed\" as const, updatedAt: event.timestamp };\n case \"WorkflowPaused\":\n return { ...workflow, state: \"paused\" as const, updatedAt: event.timestamp };\n case \"WorkflowResumed\":\n return { ...workflow, state: \"running\" as const, updatedAt: event.timestamp };\n default:\n return workflow;\n }\n}\n","import { Effect, Ref } from \"effect\";\nimport type { WorkerAgent, WorkflowId } from \"../types.js\";\nimport { WorkerPoolError } from \"../errors.js\";\n\nexport interface WorkerPool {\n readonly spawn: (specialty: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;\n readonly assignTask: (workflowId: WorkflowId, stepId: string, requiredSpecialty?: string) => Effect.Effect<WorkerAgent, WorkerPoolError>;\n readonly releaseWorker: (agentId: string, success: boolean, latencyMs: number) => Effect.Effect<void, never>;\n readonly getStatus: Effect.Effect<{ total: number; idle: number; busy: number; workers: WorkerAgent[] }, never>;\n}\n\nexport const makeWorkerPool = Effect.gen(function* () {\n const workersRef = yield* Ref.make<Map<string, WorkerAgent>>(new Map());\n\n const spawn = (specialty: string): Effect.Effect<WorkerAgent, WorkerPoolError> =>\n Effect.gen(function* () {\n const worker: WorkerAgent = {\n agentId: `worker-${crypto.randomUUID().slice(0, 8)}`,\n specialty,\n status: \"idle\",\n completedTasks: 0,\n failedTasks: 0,\n avgLatencyMs: 0,\n };\n\n yield* Ref.update(workersRef, (map) => {\n const newMap = new Map(map);\n newMap.set(worker.agentId, worker);\n return newMap;\n });\n\n return worker;\n });\n\n const assignTask = (\n workflowId: WorkflowId,\n stepId: string,\n requiredSpecialty?: string,\n ): Effect.Effect<WorkerAgent, WorkerPoolError> =>\n Effect.gen(function* () {\n const workers = yield* Ref.get(workersRef);\n let candidate: WorkerAgent | undefined;\n\n for (const worker of workers.values()) {\n if (worker.status === \"idle\") {\n if (!requiredSpecialty || worker.specialty === requiredSpecialty) {\n candidate = worker;\n break;\n }\n }\n }\n\n if (!candidate) {\n return yield* Effect.fail(\n new WorkerPoolError({\n message: `No idle worker available${requiredSpecialty ? ` with specialty \"${requiredSpecialty}\"` : \"\"}`,\n availableWorkers: [...workers.values()].filter((w) => w.status === \"idle\").length,\n requiredWorkers: 1,\n }),\n );\n }\n\n const assigned: WorkerAgent = {\n ...candidate,\n status: \"busy\",\n currentWorkflowId: workflowId,\n currentStepId: stepId,\n };\n\n yield* Ref.update(workersRef, (map) => {\n const newMap = new Map(map);\n newMap.set(assigned.agentId, assigned);\n return newMap;\n });\n\n return assigned;\n });\n\n const releaseWorker = (agentId: string, success: boolean, latencyMs: number): Effect.Effect<void, never> =>\n Ref.update(workersRef, (map) => {\n const newMap = new Map(map);\n const worker = newMap.get(agentId);\n if (worker) {\n const totalTasks = worker.completedTasks + worker.failedTasks + 1;\n newMap.set(agentId, {\n ...worker,\n status: \"idle\" as const,\n currentWorkflowId: undefined,\n currentStepId: undefined,\n completedTasks: success ? worker.completedTasks + 1 : worker.completedTasks,\n failedTasks: success ? worker.failedTasks : worker.failedTasks + 1,\n avgLatencyMs: (worker.avgLatencyMs * (totalTasks - 1) + latencyMs) / totalTasks,\n });\n }\n return newMap;\n });\n\n const getStatus = Effect.gen(function* () {\n const workers = yield* Ref.get(workersRef);\n const all = [...workers.values()];\n return {\n total: all.length,\n idle: all.filter((w) => w.status === \"idle\").length,\n busy: all.filter((w) => w.status === \"busy\").length,\n workers: all,\n };\n });\n\n return { spawn, assignTask, releaseWorker, getStatus } satisfies WorkerPool;\n});\n","import { Effect, Context, Ref } from \"effect\";\nimport type {\n Workflow,\n WorkflowId,\n WorkflowPattern,\n WorkflowStep,\n WorkflowState,\n DomainEvent,\n Checkpoint,\n WorkerAgent,\n} from \"./types.js\";\nimport { WorkflowError, WorkflowStepError, CheckpointError, WorkerPoolError } from \"./errors.js\";\nimport { makeWorkflowEngine, type WorkflowEngine } from \"./workflows/workflow-engine.js\";\nimport { makeEventSourcing, type EventSourcing } from \"./durable/event-sourcing.js\";\nimport { makeWorkerPool, type WorkerPool } from \"./multi-agent/worker-pool.js\";\n\nexport class OrchestrationService extends Context.Tag(\"OrchestrationService\")<\n OrchestrationService,\n {\n readonly executeWorkflow: (\n name: string,\n pattern: WorkflowPattern,\n steps: readonly Omit<WorkflowStep, \"status\" | \"startedAt\" | \"completedAt\" | \"error\" | \"retryCount\">[],\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n options?: { maxRetries?: number },\n ) => Effect.Effect<Workflow, WorkflowError | WorkflowStepError>;\n\n readonly resumeWorkflow: (\n workflowId: WorkflowId,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ) => Effect.Effect<Workflow, WorkflowError | CheckpointError | WorkflowStepError>;\n\n readonly pauseWorkflow: (\n workflowId: WorkflowId,\n reason: string,\n ) => Effect.Effect<void, WorkflowError>;\n\n readonly checkpoint: (\n workflowId: WorkflowId,\n ) => Effect.Effect<Checkpoint, CheckpointError | WorkflowError>;\n\n readonly getWorkflow: (\n workflowId: WorkflowId,\n ) => Effect.Effect<Workflow, WorkflowError>;\n\n readonly listWorkflows: (filter?: {\n state?: WorkflowState;\n pattern?: WorkflowPattern;\n }) => Effect.Effect<readonly Workflow[], never>;\n\n readonly spawnWorker: (\n specialty: string,\n ) => Effect.Effect<WorkerAgent, WorkerPoolError>;\n\n readonly getEventLog: (\n workflowId?: WorkflowId,\n ) => Effect.Effect<readonly DomainEvent[], never>;\n }\n>() {}\n\nexport const OrchestrationServiceLive = Effect.gen(function* () {\n const engine: WorkflowEngine = yield* makeWorkflowEngine;\n const eventSourcing: EventSourcing = yield* makeEventSourcing;\n const workerPool: WorkerPool = yield* makeWorkerPool;\n\n const executeWorkflow = (\n name: string,\n pattern: WorkflowPattern,\n steps: readonly Omit<WorkflowStep, \"status\" | \"startedAt\" | \"completedAt\" | \"error\" | \"retryCount\">[],\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n options?: { maxRetries?: number },\n ): Effect.Effect<Workflow, WorkflowError | WorkflowStepError> =>\n Effect.gen(function* () {\n const maxRetries = options?.maxRetries ?? 3;\n const workflowId = crypto.randomUUID() as WorkflowId;\n\n const fullSteps: WorkflowStep[] = steps.map((s) => ({\n ...s,\n status: \"pending\" as const,\n retryCount: 0,\n maxRetries,\n }));\n\n const workflow: Workflow = {\n id: workflowId,\n name,\n pattern,\n steps: fullSteps,\n state: \"pending\",\n createdAt: new Date(),\n updatedAt: new Date(),\n };\n\n yield* engine.updateWorkflow(workflow);\n yield* engine.appendEvent({\n type: \"WorkflowCreated\",\n workflowId,\n timestamp: new Date(),\n payload: workflow,\n });\n\n let result: Workflow;\n switch (pattern) {\n case \"parallel\":\n result = yield* engine.executeParallel(workflow, executeStep);\n break;\n case \"map-reduce\":\n result = yield* engine.executeMapReduce(workflow, executeStep);\n break;\n case \"sequential\":\n case \"pipeline\":\n case \"orchestrator-workers\":\n default:\n result = yield* engine.executeSequential(workflow, executeStep);\n break;\n }\n\n // Save a final checkpoint (best-effort, don't fail the workflow)\n const cp = yield* engine.createCheckpoint(result);\n yield* eventSourcing.saveCheckpoint(cp).pipe(Effect.catchAll(() => Effect.void));\n\n return result;\n });\n\n const resumeWorkflow = (\n workflowId: WorkflowId,\n executeStep: (step: WorkflowStep) => Effect.Effect<unknown, WorkflowStepError>,\n ): Effect.Effect<Workflow, WorkflowError | CheckpointError | WorkflowStepError> =>\n Effect.gen(function* () {\n const checkpoint = yield* eventSourcing.loadLatestCheckpoint(workflowId);\n const events = yield* Ref.get(engine.eventLogRef);\n const workflow = yield* eventSourcing.replayFromCheckpoint(checkpoint, events);\n\n // Resume workflow by marking it running and re-executing pending steps\n const resumed: Workflow = { ...workflow, state: \"running\" as const, updatedAt: new Date() };\n yield* engine.updateWorkflow(resumed);\n yield* engine.appendEvent({\n type: \"WorkflowResumed\",\n workflowId,\n timestamp: new Date(),\n payload: {},\n });\n\n // Re-execute only pending/failed steps\n const pendingSteps = resumed.steps.filter((s) => s.status === \"pending\" || s.status === \"failed\");\n let current = resumed;\n for (const step of pendingSteps) {\n yield* engine.appendEvent({\n type: \"StepStarted\",\n workflowId,\n timestamp: new Date(),\n payload: { stepId: step.id, agentId: step.agentId ?? \"default\" },\n });\n\n const result = yield* executeStep(step);\n\n yield* engine.appendEvent({\n type: \"StepCompleted\",\n workflowId,\n timestamp: new Date(),\n payload: { stepId: step.id, output: result },\n });\n\n current = {\n ...current,\n steps: current.steps.map((s) =>\n s.id === step.id\n ? { ...s, status: \"completed\" as const, output: result, completedAt: new Date() }\n : s,\n ),\n updatedAt: new Date(),\n };\n yield* engine.updateWorkflow(current);\n }\n\n current = { ...current, state: \"completed\" as const, completedAt: new Date() };\n yield* engine.updateWorkflow(current);\n return current;\n });\n\n const pauseWorkflow = (\n workflowId: WorkflowId,\n reason: string,\n ): Effect.Effect<void, WorkflowError> =>\n Effect.gen(function* () {\n const workflows = yield* Ref.get(engine.workflowsRef);\n const workflow = workflows.get(workflowId);\n if (!workflow) {\n return yield* Effect.fail(\n new WorkflowError({ message: `Workflow ${workflowId} not found`, workflowId }),\n );\n }\n\n const paused: Workflow = { ...workflow, state: \"paused\" as const, updatedAt: new Date() };\n yield* engine.updateWorkflow(paused);\n yield* engine.appendEvent({\n type: \"WorkflowPaused\",\n workflowId,\n timestamp: new Date(),\n payload: { reason },\n });\n });\n\n const checkpoint = (\n workflowId: WorkflowId,\n ): Effect.Effect<Checkpoint, CheckpointError | WorkflowError> =>\n Effect.gen(function* () {\n const workflows = yield* Ref.get(engine.workflowsRef);\n const workflow = workflows.get(workflowId);\n if (!workflow) {\n return yield* Effect.fail(\n new WorkflowError({ message: `Workflow ${workflowId} not found`, workflowId }),\n );\n }\n\n const cp = yield* engine.createCheckpoint(workflow);\n yield* eventSourcing.saveCheckpoint(cp);\n return cp;\n });\n\n const getWorkflow = (\n workflowId: WorkflowId,\n ): Effect.Effect<Workflow, WorkflowError> =>\n Effect.gen(function* () {\n const workflows = yield* Ref.get(engine.workflowsRef);\n const workflow = workflows.get(workflowId);\n if (!workflow) {\n return yield* Effect.fail(\n new WorkflowError({ message: `Workflow ${workflowId} not found`, workflowId }),\n );\n }\n return workflow;\n });\n\n const listWorkflows = (filter?: {\n state?: WorkflowState;\n pattern?: WorkflowPattern;\n }): Effect.Effect<readonly Workflow[], never> =>\n Effect.gen(function* () {\n const workflows = yield* Ref.get(engine.workflowsRef);\n let all = [...workflows.values()];\n if (filter?.state) {\n all = all.filter((w) => w.state === filter.state);\n }\n if (filter?.pattern) {\n all = all.filter((w) => w.pattern === filter.pattern);\n }\n return all;\n });\n\n const spawnWorker = (specialty: string): Effect.Effect<WorkerAgent, WorkerPoolError> =>\n workerPool.spawn(specialty);\n\n const getEventLog = (\n workflowId?: WorkflowId,\n ): Effect.Effect<readonly DomainEvent[], never> =>\n Effect.gen(function* () {\n const events = yield* Ref.get(engine.eventLogRef);\n if (workflowId) {\n return events.filter((e) => e.workflowId === workflowId);\n }\n return events;\n });\n\n return {\n executeWorkflow,\n resumeWorkflow,\n pauseWorkflow,\n checkpoint,\n getWorkflow,\n listWorkflows,\n spawnWorker,\n getEventLog,\n } as const;\n});\n","import { Layer } from \"effect\";\nimport { OrchestrationService, OrchestrationServiceLive } from \"./orchestration-service.js\";\n\nexport const createOrchestrationLayer = (): Layer.Layer<OrchestrationService> =>\n Layer.effect(OrchestrationService, OrchestrationServiceLive);\n"],"mappings":";AAAA,SAAS,cAAc;AAIhB,IAAM,mBAAmB,OAAO,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAGtE,IAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EAAc;AAAA,EAAY;AAAA,EAAc;AAAA,EAAY;AACtD;AAGO,IAAM,gBAAgB,OAAO;AAAA,EAClC;AAAA,EAAW;AAAA,EAAW;AAAA,EAAU;A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AAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF,CAAC;;;AClRD,SAAS,aAAa;AAGf,IAAM,2BAA2B,MACtC,MAAM,OAAO,sBAAsB,wBAAwB;","names":["Effect","Ref","Effect","Ref","Effect","Ref","Effect","Ref","Effect","Ref","Effect","checkpoint","Ref"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@reactive-agents/orchestration",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsup --config ../../tsup.config.base.ts",
9
+ "typecheck": "tsc --noEmit",
10
+ "test": "bun test",
11
+ "test:watch": "bun test --watch"
12
+ },
13
+ "dependencies": {
14
+ "effect": "^3.10.0",
15
+ "@reactive-agents/core": "0.1.0",
16
+ "@reactive-agents/llm-provider": "0.1.0",
17
+ "@reactive-agents/identity": "0.1.0",
18
+ "@reactive-agents/reasoning": "0.1.0",
19
+ "@reactive-agents/cost": "0.1.0"
20
+ },
21
+ "devDependencies": {
22
+ "typescript": "^5.7.0",
23
+ "bun-types": "latest"
24
+ },
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/tylerjrbuell/reactive-agents-ts.git",
29
+ "directory": "packages/orchestration"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js",
43
+ "default": "./dist/index.js"
44
+ }
45
+ },
46
+ "description": "Multi-agent orchestration for Reactive Agents — workflow engine and agent coordination",
47
+ "homepage": "https://tylerjrbuell.github.io/reactive-agents-ts/",
48
+ "bugs": {
49
+ "url": "https://github.com/tylerjrbuell/reactive-agents-ts/issues"
50
+ }
51
+ }