1import type { OrchestrationV2ThreadDetailSnapshot, ThreadId } from "@t3tools/contracts";
2import * as Context from "effect/Context";
3import type * as Effect from "effect/Effect";
4
5import type { PreparedConnection } from "../connection/model.ts";
6
7export type ThreadSnapshotHistoryMeta = {
8 readonly historyCursor: string | null;
9 readonly hasMoreHistory: boolean;
10 readonly latestLocalTurnOrdinal?: number | null;
11};
12
13export type ThreadSnapshotLoadResult =
14 | {
15 readonly _tag: "present";
16 readonly snapshot: OrchestrationV2ThreadDetailSnapshot;
17 readonly history?: ThreadSnapshotHistoryMeta;
18 }
19 | { readonly _tag: "missing" }
20 | { readonly _tag: "unavailable" };
21
22export class ThreadSnapshotLoader extends Context.Service<
23 ThreadSnapshotLoader,
24 {
25 readonly load: (
26 prepared: PreparedConnection,
27 threadId: ThreadId,
28 ) => Effect.Effect<ThreadSnapshotLoadResult>;
29 }
30>()("@t3tools/client-runtime/state/threadSnapshotHttp/ThreadSnapshotLoader") {}