import { EnvironmentId, OrchestrationV2ShellSnapshot, OrchestrationV2ThreadProjection, ThreadId, } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; export const ORCHESTRATION_CACHE_SCHEMA_VERSION = 2 as const; export const StoredOrchestrationShellSnapshot = Schema.Struct({ schemaVersion: Schema.Literal(ORCHESTRATION_CACHE_SCHEMA_VERSION), environmentId: EnvironmentId, snapshot: OrchestrationV2ShellSnapshot, }); export const StoredOrchestrationThreadSnapshot = Schema.Struct({ schemaVersion: Schema.Literal(ORCHESTRATION_CACHE_SCHEMA_VERSION), environmentId: EnvironmentId, threadId: ThreadId, thread: OrchestrationV2ThreadProjection, }); /** Invalid orchestration caches are disposable and must never block live synchronization. */ export function decodeOrDiscardOrchestrationCache( decode: Effect.Effect, E, R>, discard: Effect.Effect, ) { return decode.pipe(Effect.catch(() => discard.pipe(Effect.as(Option.none())))); }