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