forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeReceiptBus.ts
More file actions
66 lines (60 loc) · 2.57 KB
/
Copy pathRuntimeReceiptBus.ts
File metadata and controls
66 lines (60 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* RuntimeReceiptBus - Internal checkpoint-reactor synchronization receipts.
*
* This service exists to expose short-lived orchestration milestones that are
* useful in tests and harnesses but are not part of the production runtime
* event model. `CheckpointReactor` publishes receipts such as baseline capture,
* diff finalization, and turn-processing quiescence so integration tests can
* wait for those exact points without inferring them indirectly from persisted
* state.
*
* Production code should only call `publish`. Test code may subscribe via
* `streamEventsForTest`, which is intentionally named to make the intended
* usage explicit.
*
* @module RuntimeReceiptBus
*/
import { CheckpointRef, IsoDateTime, NonNegativeInt, ThreadId, TurnId } from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import * as Context from "effect/Context";
import type * as Effect from "effect/Effect";
import type * as Stream from "effect/Stream";
export const CheckpointBaselineCapturedReceipt = Schema.Struct({
type: Schema.Literal("checkpoint.baseline.captured"),
threadId: ThreadId,
checkpointTurnCount: NonNegativeInt,
checkpointRef: CheckpointRef,
createdAt: IsoDateTime,
});
export type CheckpointBaselineCapturedReceipt = typeof CheckpointBaselineCapturedReceipt.Type;
export const CheckpointDiffFinalizedReceipt = Schema.Struct({
type: Schema.Literal("checkpoint.diff.finalized"),
threadId: ThreadId,
turnId: TurnId,
checkpointTurnCount: NonNegativeInt,
checkpointRef: CheckpointRef,
status: Schema.Literals(["ready", "missing", "error"]),
createdAt: IsoDateTime,
});
export type CheckpointDiffFinalizedReceipt = typeof CheckpointDiffFinalizedReceipt.Type;
export const TurnProcessingQuiescedReceipt = Schema.Struct({
type: Schema.Literal("turn.processing.quiesced"),
threadId: ThreadId,
turnId: TurnId,
checkpointTurnCount: NonNegativeInt,
createdAt: IsoDateTime,
});
export type TurnProcessingQuiescedReceipt = typeof TurnProcessingQuiescedReceipt.Type;
export const OrchestrationRuntimeReceipt = Schema.Union([
CheckpointBaselineCapturedReceipt,
CheckpointDiffFinalizedReceipt,
TurnProcessingQuiescedReceipt,
]);
export type OrchestrationRuntimeReceipt = typeof OrchestrationRuntimeReceipt.Type;
export interface RuntimeReceiptBusShape {
readonly publish: (receipt: OrchestrationRuntimeReceipt) => Effect.Effect<void>;
readonly streamEventsForTest: Stream.Stream<OrchestrationRuntimeReceipt>;
}
export class RuntimeReceiptBus extends Context.Service<RuntimeReceiptBus, RuntimeReceiptBusShape>()(
"t3/orchestration/Services/RuntimeReceiptBus",
) {}