- Migrate web and mobile state, commands, and persistence to V2 projections - Render conversations from authoritative visible turn items - Harden runtime policy, launch handling, attachments, and cache invalidation
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { useAtomValue } from "@effect/atom-react";
|
|
import {
|
|
createEnvironmentThreadDetailAtoms,
|
|
createEnvironmentThreadShellAtoms,
|
|
createEnvironmentThreadStateAtoms,
|
|
EMPTY_ENVIRONMENT_THREAD_STATE,
|
|
type EnvironmentThreadState,
|
|
createThreadEnvironmentAtoms,
|
|
} from "@t3tools/client-runtime/state/threads";
|
|
import { presentThread, type EnvironmentThread } from "@t3tools/client-runtime/state/shell";
|
|
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
|
|
import * as Option from "effect/Option";
|
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
|
|
import { environmentCatalog } from "../connection/catalog";
|
|
import { connectionAtomRuntime } from "../connection/runtime";
|
|
import { environmentSnapshotAtom } from "./shell";
|
|
|
|
export const threadEnvironment = createThreadEnvironmentAtoms(connectionAtomRuntime);
|
|
export const environmentThreads = createEnvironmentThreadStateAtoms(connectionAtomRuntime);
|
|
export const environmentThreadDetails = createEnvironmentThreadDetailAtoms(
|
|
environmentThreads.stateAtom,
|
|
);
|
|
export const environmentThreadShells = createEnvironmentThreadShellAtoms({
|
|
catalogValueAtom: environmentCatalog.catalogValueAtom,
|
|
snapshotAtom: environmentSnapshotAtom,
|
|
});
|
|
|
|
const EMPTY_THREAD_STATE_ATOM = Atom.make(AsyncResult.success(EMPTY_ENVIRONMENT_THREAD_STATE)).pipe(
|
|
Atom.withLabel("web-environment-thread:empty"),
|
|
);
|
|
|
|
export function useEnvironmentThread(
|
|
environmentId: EnvironmentId | null,
|
|
threadId: ThreadId | null,
|
|
): Omit<EnvironmentThreadState, "data"> & { readonly data: Option.Option<EnvironmentThread> } {
|
|
const result = useAtomValue(
|
|
environmentId !== null && threadId !== null
|
|
? environmentThreads.stateAtom(environmentId, threadId)
|
|
: EMPTY_THREAD_STATE_ATOM,
|
|
);
|
|
const state = Option.getOrElse(
|
|
AsyncResult.value(result),
|
|
() => EMPTY_ENVIRONMENT_THREAD_STATE,
|
|
) as EnvironmentThreadState;
|
|
return {
|
|
...state,
|
|
data:
|
|
environmentId === null
|
|
? Option.none()
|
|
: Option.map(state.data, (projection) => presentThread(environmentId, projection)),
|
|
};
|
|
}
|