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

useSidebarRowThreadKey.ts

15 lines894 Bytes

1import { useAtomValue } from "@effect/atom-react";
2import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
3import { resolveListedAncestorThreadRef } from "@t3tools/client-runtime/state/threads";
4​
5import { scopedThreadKey } from "../../lib/scopedEntities";
6import { environmentThreadShells } from "../../state/threads";
7​
8/** An open subagent, side chat or delegated task has no row; its listed ancestor's row is selected. */
9export function useSidebarRowThreadKey(openThreadKey: string | null): string | null {
10 const threads = useAtomValue(environmentThreadShells.quietThreadShellsAtom);
11 const openThreadRef = openThreadKey === null ? null : parseScopedThreadKey(openThreadKey);
12 if (openThreadRef === null) return openThreadKey;
13 const rowRef = resolveListedAncestorThreadRef(openThreadRef, threads);
14 return scopedThreadKey(rowRef.environmentId, rowRef.threadId);