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

orchestrationCache.ts

37 lines1.3 KB

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// Older caches may contain human turns that bypassed server history budgets.
14export const ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION = 5 as const;
15​
16export const StoredOrchestrationShellSnapshot = Schema.Struct({
17 schemaVersion: Schema.Literal(ORCHESTRATION_CACHE_SCHEMA_VERSION),
18 environmentId: EnvironmentId,
19 snapshot: OrchestrationV2ShellSnapshotJson,
20});
21​
22export const StoredOrchestrationThreadSnapshot = Schema.Struct({
23 schemaVersion: Schema.Literal(ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION),
24 environmentId: EnvironmentId,
25 threadId: ThreadId,
26 snapshot: OrchestrationV2ThreadDetailSnapshot.mapFields((fields) => ({
27 ...fields,
28 projection: OrchestrationV2ThreadProjectionJson,
29 })),
30});
31​
32export function decodeOrDiscardOrchestrationCache<A, E, R, E2, R2>(
33 decode: Effect.Effect<Option.Option<A>, E, R>,
34 discard: Effect.Effect<void, E2, R2>,
35) {
36 return decode.pipe(Effect.catch(() => discard.pipe(Effect.as(Option.none<A>()))));