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

threadState.ts

40 lines1.4 KB

1import type { OrchestrationThread } from "@t3tools/contracts";
2import * as Option from "effect/Option";
3​
4export type EnvironmentThreadStatus = "empty" | "cached" | "synchronizing" | "live" | "deleted";
5​
6/**
7 * Pagination state for a windowed thread. Present only when the loaded thread
8 * is a window (the server returned `page` metadata); absent means the thread is
9 * fully loaded — either the server predates pagination or the window reached
10 * the top.
11 */
12export interface EnvironmentThreadPageState {
13 /** Opaque exclusive cursor for the next older slice; null when fully loaded. */
14 readonly beforeCursor: string | null;
15 readonly hasMore: boolean;
16 /** True while an older page fetch is in flight. */
17 readonly loadingOlder: boolean;
19​
20export interface EnvironmentThreadState {
21 readonly data: Option.Option<OrchestrationThread>;
22 readonly status: EnvironmentThreadStatus;
23 readonly error: Option.Option<string>;
24 readonly page: Option.Option<EnvironmentThreadPageState>;
26​
27export const EMPTY_ENVIRONMENT_THREAD_STATE: EnvironmentThreadState = {
28 data: Option.none(),
29 status: "empty",
30 error: Option.none(),
31 page: Option.none(),
32};
33​
34/** Whether the thread has older turns that can be loaded with more pages. */
35export function threadHasOlderTurns(state: EnvironmentThreadState): boolean {
36 return Option.match(state.page, {
37 onNone: () => false,
38 onSome: (page) => page.hasMore,
39 });