Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

OrchestrationEngine.ts

73 lines2.4 KB

1/**
2 * Historical name for the application event-sourcing engine.
3 *
4 * This is not the agent orchestrator. It retains serialized project-command
5 * validation, append, receipt, and projection transactions. Agent execution is
6 * owned by orchestration V2, whose thread events use the same event store.
7 *
8 * Uses Effect `Context.Service` for dependency injection. Command dispatch,
9 * replay, and unknown-input decoding all return typed domain errors.
10 *
11 * @module OrchestrationEngineService
12 */
13import type {
14 OrchestrationEvent,
15 ProjectOrchestrationCommand,
16} from "@t3tools/contracts/legacy-orchestration";
17import * as Context from "effect/Context";
18import type * as Effect from "effect/Effect";
19import type * as Stream from "effect/Stream";
20​
21import type { OrchestrationDispatchError } from "../Errors.ts";
22import type { OrchestrationEventStoreError } from "../../persistence/Errors.ts";
23​
24/**
25 * OrchestrationEngineShape - Service API for orchestration command and event flow.
26 */
27export interface OrchestrationEngineShape {
28 /**
29 * Replay persisted orchestration events from an exclusive sequence cursor.
30 *
31 * @param fromSequenceExclusive - Sequence cursor (exclusive).
32 * @returns Stream containing ordered events.
33 */
34 readonly readEvents: (
35 fromSequenceExclusive: number,
36 ) => Stream.Stream<OrchestrationEvent, OrchestrationEventStoreError, never>;
37​
38 /**
39 * Dispatch a validated orchestration command.
40 *
41 * @param command - Valid orchestration command.
42 * @returns Effect containing the sequence of the persisted event.
43 *
44 * Dispatch is serialized through an internal queue and deduplicated via
45 * command receipts.
46 */
47 readonly dispatch: (
48 command: ProjectOrchestrationCommand,
49 ) => Effect.Effect<{ sequence: number }, OrchestrationDispatchError, never>;
50​
51 /**
52 * Stream persisted domain events in dispatch order.
53 *
54 * This is a hot runtime stream (new events only), not a historical replay.
55 */
56 readonly streamDomainEvents: Stream.Stream<OrchestrationEvent>;
58​
59/**
60 * OrchestrationEngineService - Service tag for orchestration engine access.
61 *
62 * @example
63 * ```ts
64 * const program = Effect.gen(function* () {
65 * const engine = yield* OrchestrationEngineService
66 * return yield* engine.dispatch(command)
67 * })
68 * ```
69 */
70export class OrchestrationEngineService extends Context.Service<
71 OrchestrationEngineService,
72 OrchestrationEngineShape
73>()("t3/orchestration/Services/OrchestrationEngine/OrchestrationEngineService") {}