Open History to see the last commit
1import {
2 EnvironmentId,
3 OrchestrationV2ShellSnapshot,
4 OrchestrationV2ThreadProjection,
5 ThreadId,
6} from "@t3tools/contracts";
7import * as Effect from "effect/Effect";
8import * as Option from "effect/Option";
9import * as Schema from "effect/Schema";
10
11export const ORCHESTRATION_CACHE_SCHEMA_VERSION = 2 as const;
12
13export const StoredOrchestrationShellSnapshot = Schema.Struct({
14 schemaVersion: Schema.Literal(ORCHESTRATION_CACHE_SCHEMA_VERSION),
15 environmentId: EnvironmentId,
16 snapshot: OrchestrationV2ShellSnapshot,
17});
18
19export const StoredOrchestrationThreadSnapshot = Schema.Struct({
20 schemaVersion: Schema.Literal(ORCHESTRATION_CACHE_SCHEMA_VERSION),
21 environmentId: EnvironmentId,
22 threadId: ThreadId,
23 thread: OrchestrationV2ThreadProjection,
24});
25
26/** Invalid orchestration caches are disposable and must never block live synchronization. */
27export function decodeOrDiscardOrchestrationCache<A, E, R, E2, R2>(
28 decode: Effect.Effect<Option.Option<A>, E, R>,
29 discard: Effect.Effect<void, E2, R2>,
30) {
31 return decode.pipe(Effect.catch(() => discard.pipe(Effect.as(Option.none<A>()))));
32}