feat(web): hide subagent threads from user-facing thread lists
A subagent's child thread is an implementation detail of the agent that owns it, not a conversation the user started. Listing them alongside real threads makes the sidebar grow with every delegation. Filtered at the source — the shell snapshot the server serves — so every client sees the same set rather than each re-deriving it. The web client filters again for locally-held state, and the thread route redirects to the parent if a subagent thread is reached directly. Mobile is part of the sweep, not left behind. It still offered "Open subagent thread" and had no redirect to fall back on, so it would have navigated to a thread the client no longer receives. Its relationships banner also needed the same subagent-edge filter web has: those edges are derived from the projection rather than from thread shells, so they survive the shell filtering and would have rendered as "Unavailable" — and, sorting first, could have taken over the banner headline. Trade-off worth stating plainly: a subagent's transcript becomes unreachable. The Agents panel added in the previous PR shows what an agent did and what it returned, but not its full conversation. That is the intended shape here, and the "Open subagent thread" affordances are removed on both clients rather than left as dead ends.
This commit is contained in:
1 parent
87cb5bc0ad
commit
7ac23a7523
17 files changed
+262
-56
No files matched your search
@@ -83,7 +83,13 @@ export function ThreadRelationshipsBanner(props: {
|
||||
const rows = useMemo(
|
||||
() =>
|
||||
copySorted(
|
||||
immediateThreadRelationships(graph, props.threadId),
|
||||
// Subagent edges come from the projection, not from thread shells, so
|
||||
// they survive the shell filtering and would point at threads the
|
||||
// client no longer receives — rendering as "Unavailable", and taking
|
||||
// over the banner headline when they sort first.
|
||||
immediateThreadRelationships(graph, props.threadId).filter(
|
||||
(relationship) => relationship.edge.kind !== "subagent",
|
||||
),
|
||||
(left, right) =>
|
||||
Number(right.threadId === mergeTargetThreadId) -
|
||||
Number(left.threadId === mergeTargetThreadId),
|
||||
|
||||
@@ -128,9 +128,6 @@ function ThreadActivityThreadLink(props: {
|
||||
if (item.type === "thread_created") {
|
||||
targetThreadId = item.targetThreadId;
|
||||
label = "Open created thread";
|
||||
} else if (item.type === "subagent") {
|
||||
targetThreadId = support.subagent?.childThreadId ?? item.childThreadId;
|
||||
label = "Open subagent thread";
|
||||
} else if (item.type === "fork") {
|
||||
targetThreadId =
|
||||
item.targetThreadId === row.sourceThreadId && item.source.type === "run"
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
NodeId,
|
||||
type OrchestrationV2Command,
|
||||
type OrchestrationV2ThreadProjection,
|
||||
type OrchestrationV2ThreadShell,
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
RunId,
|
||||
@@ -26,6 +27,7 @@ import {
|
||||
ThreadManagementThreadNotInterruptibleError,
|
||||
ThreadManagementThreadArchivedError,
|
||||
ThreadManagementNoSteerableRunError,
|
||||
userFacingShellSnapshot,
|
||||
withCreationProvenance,
|
||||
} from "./ThreadManagementService.ts";
|
||||
|
||||
@@ -318,3 +320,59 @@ it.effect("uses thread-not-found only after a projection loads outside the proje
|
||||
expect("cause" in error).toBe(false);
|
||||
}).pipe(Effect.provide(testLayer));
|
||||
});
|
||||
|
||||
it("removes internal subagent children from active and archived shell collections", () => {
|
||||
const rootId = ThreadId.make("thread:thread-management:root");
|
||||
const forkId = ThreadId.make("thread:thread-management:fork");
|
||||
const lineageSubagentId = ThreadId.make("thread:thread-management:lineage-subagent");
|
||||
const nodeSubagentId = ThreadId.make("thread:thread-management:node-subagent");
|
||||
const shell = (
|
||||
id: ThreadId,
|
||||
lineage: OrchestrationV2ThreadShell["lineage"],
|
||||
forkedFrom: OrchestrationV2ThreadShell["forkedFrom"],
|
||||
) =>
|
||||
({
|
||||
id,
|
||||
lineage,
|
||||
forkedFrom,
|
||||
}) as OrchestrationV2ThreadShell;
|
||||
const rootLineage = {
|
||||
rootThreadId: rootId,
|
||||
parentThreadId: null,
|
||||
relationshipToParent: null,
|
||||
} as const;
|
||||
const snapshot = userFacingShellSnapshot({
|
||||
schemaVersion: 3,
|
||||
snapshotSequence: 10,
|
||||
threads: [
|
||||
shell(rootId, rootLineage, null),
|
||||
shell(
|
||||
forkId,
|
||||
{
|
||||
rootThreadId: rootId,
|
||||
parentThreadId: rootId,
|
||||
relationshipToParent: "fork",
|
||||
},
|
||||
{ type: "run", threadId: rootId, runId: RunId.make("run:thread-management:fork") },
|
||||
),
|
||||
shell(
|
||||
lineageSubagentId,
|
||||
{
|
||||
rootThreadId: rootId,
|
||||
parentThreadId: rootId,
|
||||
relationshipToParent: "subagent",
|
||||
},
|
||||
null,
|
||||
),
|
||||
],
|
||||
archivedThreads: [
|
||||
shell(nodeSubagentId, rootLineage, {
|
||||
type: "node",
|
||||
nodeId: NodeId.make("node:thread-management:subagent"),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(snapshot.threads.map((thread) => thread.id)).toEqual([rootId, forkId]);
|
||||
expect(snapshot.archivedThreads).toEqual([]);
|
||||
});
|
||||
@@ -308,6 +308,16 @@ export class ThreadManagementService extends Context.Service<
|
||||
ThreadManagementServiceShape
|
||||
>()("t3/orchestration-v2/ThreadManagementService") {}
|
||||
|
||||
export const isInternalSubagentThread = (
|
||||
thread: Pick<OrchestrationV2ThreadShell, "forkedFrom" | "lineage">,
|
||||
) => thread.lineage.relationshipToParent === "subagent" || thread.forkedFrom?.type === "node";
|
||||
|
||||
export const userFacingShellSnapshot = (snapshot: OrchestrationV2ThreadShellSnapshot) => ({
|
||||
...snapshot,
|
||||
threads: snapshot.threads.filter((thread) => !isInternalSubagentThread(thread)),
|
||||
archivedThreads: snapshot.archivedThreads.filter((thread) => !isInternalSubagentThread(thread)),
|
||||
});
|
||||
|
||||
export function isActiveRun(run: OrchestrationV2Run): boolean {
|
||||
return (
|
||||
run.status === "preparing" ||
|
||||
@@ -452,10 +462,7 @@ const make = Effect.gen(function* () {
|
||||
Effect.map((snapshot) =>
|
||||
snapshot.threads
|
||||
.filter((thread) => thread.projectId === input.projectId)
|
||||
.filter(
|
||||
(thread) =>
|
||||
input.includeSubagents || thread.lineage.relationshipToParent !== "subagent",
|
||||
)
|
||||
.filter((thread) => input.includeSubagents || !isInternalSubagentThread(thread))
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt) ||
|
||||
|
||||
@@ -89,7 +89,9 @@ export const orchestrationHttpApiLayer = HttpApiBuilder.group(
|
||||
const base = yield* sql.withTransaction(
|
||||
Effect.gen(function* () {
|
||||
const projects = yield* projectionSnapshotQuery.getShellSnapshotWithoutEnrichment();
|
||||
const threads = yield* threadManagement.getShellSnapshot();
|
||||
const threads = yield* threadManagement
|
||||
.getShellSnapshot()
|
||||
.pipe(Effect.map(ThreadManagementService.userFacingShellSnapshot));
|
||||
return {
|
||||
schemaVersion: threads.schemaVersion,
|
||||
snapshotSequence: yield* applicationEvents.latestApplicationSequence,
|
||||
|
||||
@@ -221,7 +221,7 @@ export const resolveAutoBootstrapWelcomeTargets = Effect.gen(function* () {
|
||||
const shell = yield* threads.getShellSnapshot();
|
||||
const existingThread = shell.threads.find(
|
||||
(thread) =>
|
||||
thread.projectId === project.id && thread.lineage.relationshipToParent !== "subagent",
|
||||
thread.projectId === project.id && !ThreadManagement.isInternalSubagentThread(thread),
|
||||
);
|
||||
if (existingThread === undefined) {
|
||||
const launched = yield* threadLaunch.launch({
|
||||
|
||||
+26
-9
@@ -744,7 +744,9 @@ const makeWsRpcLayer = (
|
||||
const base = yield* sql.withTransaction(
|
||||
Effect.gen(function* () {
|
||||
const projects = yield* projectionSnapshotQuery.getShellSnapshotWithoutEnrichment();
|
||||
const threads = yield* threadManagement.getShellSnapshot();
|
||||
const threads = yield* threadManagement
|
||||
.getShellSnapshot()
|
||||
.pipe(Effect.map(ThreadManagementService.userFacingShellSnapshot));
|
||||
return {
|
||||
schemaVersion: threads.schemaVersion,
|
||||
snapshotSequence: yield* applicationEvents.latestApplicationSequence,
|
||||
@@ -802,7 +804,16 @@ const makeWsRpcLayer = (
|
||||
return yield* projectItem(stored);
|
||||
}
|
||||
const shell = yield* threadManagement.getThreadShell(stored.event.threadId);
|
||||
return shellStreamItemFromThreadShell({ stored, shell });
|
||||
// An internal subagent thread is not part of the user-facing
|
||||
// stream; treating its shell as absent emits a removal the
|
||||
// client reducer absorbs.
|
||||
return shellStreamItemFromThreadShell({
|
||||
stored,
|
||||
shell:
|
||||
shell !== null && ThreadManagementService.isInternalSubagentThread(shell)
|
||||
? null
|
||||
: shell,
|
||||
});
|
||||
}),
|
||||
{ concurrency: 8 },
|
||||
);
|
||||
@@ -937,7 +948,9 @@ const makeWsRpcLayer = (
|
||||
.withTransaction(
|
||||
Effect.gen(function* () {
|
||||
const projects = yield* projectionSnapshotQuery.getShellSnapshotWithoutEnrichment();
|
||||
const threads = yield* threadManagement.getShellSnapshot();
|
||||
const threads = yield* threadManagement
|
||||
.getShellSnapshot()
|
||||
.pipe(Effect.map(ThreadManagementService.userFacingShellSnapshot));
|
||||
return {
|
||||
schemaVersion: threads.schemaVersion,
|
||||
snapshotSequence: yield* applicationEvents.latestApplicationSequence,
|
||||
@@ -973,13 +986,17 @@ const makeWsRpcLayer = (
|
||||
Effect.forEach(
|
||||
coalesceStoredThreadEvents(Array.from(events)),
|
||||
(stored) =>
|
||||
threadManagement
|
||||
.getThreadShell(stored.event.threadId)
|
||||
.pipe(
|
||||
Effect.map((shell) =>
|
||||
archivedShellStreamItemFromThreadShell({ stored, shell }),
|
||||
),
|
||||
threadManagement.getThreadShell(stored.event.threadId).pipe(
|
||||
Effect.map((shell) =>
|
||||
archivedShellStreamItemFromThreadShell({
|
||||
stored,
|
||||
shell:
|
||||
shell !== null && ThreadManagementService.isInternalSubagentThread(shell)
|
||||
? null
|
||||
: shell,
|
||||
}),
|
||||
),
|
||||
),
|
||||
{ concurrency: 8 },
|
||||
),
|
||||
),
|
||||
|
||||
@@ -41,7 +41,14 @@ import {
|
||||
sortSidebarV2ProjectGroups,
|
||||
sortThreadsForSidebar,
|
||||
} from "./Sidebar.logic";
|
||||
import { EnvironmentId, ProjectId, ProviderInstanceId, RunId, ThreadId } from "@t3tools/contracts";
|
||||
import {
|
||||
EnvironmentId,
|
||||
NodeId,
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
RunId,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
DEFAULT_INTERACTION_MODE,
|
||||
DEFAULT_RUNTIME_MODE,
|
||||
@@ -304,6 +311,13 @@ describe("sidebar thread lineage helpers", () => {
|
||||
});
|
||||
|
||||
expect(isSidebarSubagentThread(subagent)).toBe(true);
|
||||
expect(
|
||||
isSidebarSubagentThread(
|
||||
makeThreadFixture({
|
||||
forkedFrom: { type: "node", nodeId: NodeId.make("node-provider-subagent") },
|
||||
}),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(isSidebarSubagentThread(makeThreadFixture())).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as React from "react";
|
||||
import type { ContextMenuItem } from "@t3tools/contracts";
|
||||
import type { SidebarProjectSortOrder, SidebarThreadSortOrder } from "@t3tools/contracts/settings";
|
||||
import { isInternalSubagentThread as isSidebarSubagentThread } from "../threadVisibility";
|
||||
|
||||
export { isSidebarSubagentThread };
|
||||
import {
|
||||
getThreadSortTimestamp,
|
||||
sortThreads,
|
||||
@@ -97,12 +100,8 @@ export function buildMultiSelectThreadContextMenuItems(input: {
|
||||
];
|
||||
}
|
||||
|
||||
export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
|
||||
return thread.lineage.relationshipToParent === "subagent";
|
||||
}
|
||||
|
||||
export function filterSidebarV2VisibleThreads<
|
||||
T extends Pick<SidebarThreadSummary, "archivedAt" | "lineage"> & {
|
||||
T extends Pick<SidebarThreadSummary, "archivedAt" | "forkedFrom" | "lineage"> & {
|
||||
environmentId: string;
|
||||
projectId: string;
|
||||
},
|
||||
@@ -982,7 +981,7 @@ export function sortLogicalProjectsForSidebar<
|
||||
|
||||
export function sortSidebarV2ProjectGroups<
|
||||
TProject extends LogicalSidebarProject,
|
||||
TThread extends ScopedSidebarThread & Pick<SidebarThreadSummary, "lineage">,
|
||||
TThread extends ScopedSidebarThread & Pick<SidebarThreadSummary, "forkedFrom" | "lineage">,
|
||||
>(
|
||||
projects: readonly TProject[],
|
||||
threads: readonly TThread[],
|
||||
|
||||
@@ -1117,7 +1117,7 @@ describe("MessagesTimeline", () => {
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain('aria-label="Open Package audit"');
|
||||
expect(markup).not.toContain('aria-label="Open Package audit"');
|
||||
expect(markup).toContain("Reading src/index.ts");
|
||||
expect(markup).not.toContain("Inspect the package");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
@@ -1173,7 +1173,7 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain('data-v2-subagent-result-disclosure="true"');
|
||||
expect(markup).toContain('data-v2-subagent-result="true"');
|
||||
expect(markup).toContain('aria-label="Show full result for Isolation report"');
|
||||
expect(markup).toContain('aria-label="Open Isolation report"');
|
||||
expect(markup).not.toContain('aria-label="Open Isolation report"');
|
||||
expect(markup).toContain("Tests should be isolated.");
|
||||
expect(markup).toContain("Result: no shared state.");
|
||||
expect(markup).not.toContain("Explain test isolation");
|
||||
@@ -1226,7 +1226,7 @@ describe("MessagesTimeline", () => {
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain('aria-label="Open Package audit"');
|
||||
expect(markup).not.toContain('aria-label="Open Package audit"');
|
||||
expect(markup).toContain("Reading src/index.ts");
|
||||
expect(markup).not.toContain("Partial streamed answer so far");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
|
||||
@@ -150,7 +150,11 @@ export function ThreadRelationshipsPanel(props: {
|
||||
() =>
|
||||
orderWebThreadLineageRows({
|
||||
graph,
|
||||
rows: immediateThreadRelationships(graph, props.threadId),
|
||||
// Subagent edges point at hidden internal threads; rendering them
|
||||
// would offer navigation to conversations the client never receives.
|
||||
rows: immediateThreadRelationships(graph, props.threadId).filter(
|
||||
(relationship) => relationship.edge.kind !== "subagent",
|
||||
),
|
||||
currentThreadId: props.threadId,
|
||||
mergeTargetThreadId,
|
||||
}),
|
||||
|
||||
@@ -265,12 +265,6 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
|
||||
</Button>
|
||||
) : null}
|
||||
|
||||
{item.type === "subagent" && item.childThreadId !== null ? (
|
||||
<Button size="xs" variant="outline" onClick={() => props.onOpenThread(item.childThreadId!)}>
|
||||
Open subagent thread
|
||||
</Button>
|
||||
) : null}
|
||||
|
||||
{item.type === "handoff" ? (
|
||||
<div className="space-y-1 rounded-md border border-border/45 p-2 text-muted-foreground">
|
||||
<p>
|
||||
|
||||
@@ -211,7 +211,7 @@ export function V2LifecycleRow(props: {
|
||||
title={subagentDisplayTitle(item.title ?? "Subagent")}
|
||||
detail={detail}
|
||||
badge={item.status}
|
||||
threadId={item.childThreadId}
|
||||
threadId={null}
|
||||
expandedDetail={finalResult}
|
||||
onOpenThread={props.onOpenThread}
|
||||
/>
|
||||
|
||||
@@ -4,11 +4,16 @@ import { useEffect } from "react";
|
||||
import ChatView from "../components/ChatView";
|
||||
import { threadHasStarted } from "../components/ChatView.logic";
|
||||
import { finalizePromotedDraftThreadByRef, useComposerDraftStore } from "../composerDraftStore";
|
||||
import { resolveThreadRouteRef, resolveThreadRouteRenderState } from "../threadRoutes";
|
||||
import {
|
||||
buildThreadRouteParams,
|
||||
resolveThreadRouteRef,
|
||||
resolveThreadRouteRenderState,
|
||||
} from "../threadRoutes";
|
||||
import { SidebarInset } from "~/components/ui/sidebar";
|
||||
import { useEnvironmentThreadRefs, useThreadShell } from "../state/entities";
|
||||
import { useEnvironmentQuery } from "../state/query";
|
||||
import { environmentShell } from "../state/shell";
|
||||
import { isInternalSubagentThread } from "../threadVisibility";
|
||||
|
||||
function ChatThreadRouteView() {
|
||||
const navigate = useNavigate();
|
||||
@@ -42,6 +47,10 @@ function ChatThreadRouteView() {
|
||||
});
|
||||
const serverThreadStarted = threadHasStarted(serverThreadShell);
|
||||
const environmentHasAnyThreads = environmentHasServerThreads || environmentHasDraftThreads;
|
||||
const subagentParentThreadId =
|
||||
serverThreadShell && isInternalSubagentThread(serverThreadShell)
|
||||
? serverThreadShell.lineage.parentThreadId
|
||||
: null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!threadRef || !bootstrapComplete) {
|
||||
@@ -53,6 +62,24 @@ function ChatThreadRouteView() {
|
||||
}
|
||||
}, [bootstrapComplete, environmentHasAnyThreads, navigate, renderState, threadRef]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!threadRef || !serverThreadShell || !isInternalSubagentThread(serverThreadShell)) {
|
||||
return;
|
||||
}
|
||||
if (subagentParentThreadId === null) {
|
||||
void navigate({ to: "/", replace: true });
|
||||
return;
|
||||
}
|
||||
void navigate({
|
||||
to: "/$environmentId/$threadId",
|
||||
params: buildThreadRouteParams({
|
||||
environmentId: threadRef.environmentId,
|
||||
threadId: subagentParentThreadId,
|
||||
}),
|
||||
replace: true,
|
||||
});
|
||||
}, [navigate, serverThreadShell, subagentParentThreadId, threadRef]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!threadRef || !serverThreadStarted || !draftThread) {
|
||||
return;
|
||||
@@ -60,7 +87,11 @@ function ChatThreadRouteView() {
|
||||
finalizePromotedDraftThreadByRef(threadRef);
|
||||
}, [draftThread, serverThreadStarted, threadRef]);
|
||||
|
||||
if (!threadRef || renderState !== "ready") {
|
||||
if (
|
||||
!threadRef ||
|
||||
renderState !== "ready" ||
|
||||
(serverThreadShell !== null && isInternalSubagentThread(serverThreadShell))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { useMemo } from "react";
|
||||
import type {
|
||||
EnvironmentProject,
|
||||
EnvironmentThread,
|
||||
EnvironmentThreadShell,
|
||||
} from "@t3tools/client-runtime/state/shell";
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
|
||||
import {
|
||||
EMPTY_THREAD_HISTORY_META,
|
||||
type EnvironmentThreadStatus,
|
||||
@@ -13,6 +15,7 @@ import type { ScopedProjectRef, ScopedThreadRef, ServerConfig } from "@t3tools/c
|
||||
import type { EnvironmentId, OrchestrationV2ProjectedTurnItem, ThreadId } from "@t3tools/contracts";
|
||||
import { Atom } from "effect/unstable/reactivity";
|
||||
import { appAtomRegistry } from "../rpc/atomRegistry";
|
||||
import { isUserFacingThread } from "../threadVisibility";
|
||||
import { environmentProjects } from "./projects";
|
||||
import { environmentServerConfigsAtom } from "./server";
|
||||
import { allEnvironmentShellsBootstrappedAtom } from "./shell";
|
||||
@@ -29,9 +32,6 @@ const EMPTY_PROJECT_ATOM = Atom.make<EnvironmentProject | null>(null).pipe(
|
||||
const EMPTY_PROJECT_REFS_ATOM = Atom.make(EMPTY_PROJECT_REFS).pipe(
|
||||
Atom.withLabel("web-project-refs:empty"),
|
||||
);
|
||||
const EMPTY_THREAD_REFS_ATOM = Atom.make(EMPTY_THREAD_REFS).pipe(
|
||||
Atom.withLabel("web-thread-refs:empty"),
|
||||
);
|
||||
const EMPTY_THREAD_SHELL_ATOM = Atom.make<EnvironmentThreadShell | null>(null).pipe(
|
||||
Atom.withLabel("web-thread-shell:empty"),
|
||||
);
|
||||
@@ -70,7 +70,11 @@ export function useProjectRefs(): ReadonlyArray<ScopedProjectRef> {
|
||||
}
|
||||
|
||||
export function useThreadRefs(): ReadonlyArray<ScopedThreadRef> {
|
||||
return useAtomValue(environmentThreadShells.threadRefsAtom);
|
||||
const threads = useThreadShells();
|
||||
return useMemo(
|
||||
() => threads.map((thread) => scopeThreadRef(thread.environmentId, thread.id)),
|
||||
[threads],
|
||||
);
|
||||
}
|
||||
|
||||
export function useEnvironmentProjectRefs(
|
||||
@@ -86,10 +90,17 @@ export function useEnvironmentProjectRefs(
|
||||
export function useEnvironmentThreadRefs(
|
||||
environmentId: EnvironmentId | null,
|
||||
): ReadonlyArray<ScopedThreadRef> {
|
||||
return useAtomValue(
|
||||
environmentId === null
|
||||
? EMPTY_THREAD_REFS_ATOM
|
||||
: environmentThreadShells.environmentThreadRefsAtom(environmentId),
|
||||
const threads = useThreadShells();
|
||||
return useMemo(
|
||||
() =>
|
||||
environmentId === null
|
||||
? EMPTY_THREAD_REFS
|
||||
: threads.flatMap((thread) =>
|
||||
thread.environmentId === environmentId
|
||||
? [scopeThreadRef(thread.environmentId, thread.id)]
|
||||
: [],
|
||||
),
|
||||
[environmentId, threads],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,7 +113,8 @@ export function useServerConfigs(): ReadonlyMap<EnvironmentId, ServerConfig> {
|
||||
}
|
||||
|
||||
export function useThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
|
||||
return useAtomValue(environmentThreadShells.threadShellsAtom);
|
||||
const threads = useAtomValue(environmentThreadShells.threadShellsAtom);
|
||||
return useMemo(() => threads.filter(isUserFacingThread), [threads]);
|
||||
}
|
||||
|
||||
export function useAllEnvironmentShellsBootstrapped(): boolean {
|
||||
@@ -112,7 +124,8 @@ export function useAllEnvironmentShellsBootstrapped(): boolean {
|
||||
export function useThreadShellsForProjectRefs(
|
||||
refs: ReadonlyArray<ScopedProjectRef>,
|
||||
): ReadonlyArray<EnvironmentThreadShell> {
|
||||
return useAtomValue(environmentThreadShells.threadShellsForProjectRefsAtom(refs));
|
||||
const threads = useAtomValue(environmentThreadShells.threadShellsForProjectRefsAtom(refs));
|
||||
return useMemo(() => threads.filter(isUserFacingThread), [threads]);
|
||||
}
|
||||
|
||||
export function useProject(ref: ScopedProjectRef | null): EnvironmentProject | null {
|
||||
@@ -244,11 +257,17 @@ export function readEnvironmentSupportsVisitedTracking(environmentId: Environmen
|
||||
export function readEnvironmentThreadRefs(
|
||||
environmentId: EnvironmentId,
|
||||
): ReadonlyArray<ScopedThreadRef> {
|
||||
return appAtomRegistry.get(environmentThreadShells.environmentThreadRefsAtom(environmentId));
|
||||
return appAtomRegistry
|
||||
.get(environmentThreadShells.threadShellsAtom)
|
||||
.filter((thread) => thread.environmentId === environmentId && isUserFacingThread(thread))
|
||||
.map((thread) => scopeThreadRef(thread.environmentId, thread.id));
|
||||
}
|
||||
|
||||
export function readThreadRefs(): ReadonlyArray<ScopedThreadRef> {
|
||||
return appAtomRegistry.get(environmentThreadShells.threadRefsAtom);
|
||||
return appAtomRegistry
|
||||
.get(environmentThreadShells.threadShellsAtom)
|
||||
.filter(isUserFacingThread)
|
||||
.map((thread) => scopeThreadRef(thread.environmentId, thread.id));
|
||||
}
|
||||
|
||||
export function readThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
|
||||
@@ -256,9 +275,5 @@ export function readThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
|
||||
}
|
||||
|
||||
export function findThreadRef(threadId: ThreadId): ScopedThreadRef | null {
|
||||
return (
|
||||
appAtomRegistry
|
||||
.get(environmentThreadShells.threadRefsAtom)
|
||||
.find((ref) => ref.threadId === threadId) ?? null
|
||||
);
|
||||
return readThreadRefs().find((ref) => ref.threadId === threadId) ?? null;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { NodeId, RunId, ThreadId } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { isInternalSubagentThread, isUserFacingThread } from "./threadVisibility";
|
||||
|
||||
const rootId = ThreadId.make("thread:visibility:root");
|
||||
const rootLineage = {
|
||||
rootThreadId: rootId,
|
||||
parentThreadId: null,
|
||||
relationshipToParent: null,
|
||||
} as const;
|
||||
|
||||
describe("thread visibility", () => {
|
||||
it("keeps roots and user forks visible", () => {
|
||||
expect(isUserFacingThread({ lineage: rootLineage, forkedFrom: null })).toBe(true);
|
||||
expect(
|
||||
isUserFacingThread({
|
||||
lineage: {
|
||||
rootThreadId: rootId,
|
||||
parentThreadId: rootId,
|
||||
relationshipToParent: "fork",
|
||||
},
|
||||
forkedFrom: {
|
||||
type: "run",
|
||||
threadId: rootId,
|
||||
runId: RunId.make("run:visibility:fork"),
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("hides explicit and node-owned subagent children", () => {
|
||||
expect(
|
||||
isInternalSubagentThread({
|
||||
lineage: {
|
||||
rootThreadId: rootId,
|
||||
parentThreadId: rootId,
|
||||
relationshipToParent: "subagent",
|
||||
},
|
||||
forkedFrom: null,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isInternalSubagentThread({
|
||||
lineage: rootLineage,
|
||||
forkedFrom: {
|
||||
type: "node",
|
||||
nodeId: NodeId.make("node:visibility:subagent"),
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { OrchestrationV2ThreadShell } from "@t3tools/contracts";
|
||||
|
||||
export const isInternalSubagentThread = (
|
||||
thread: Pick<OrchestrationV2ThreadShell, "forkedFrom" | "lineage">,
|
||||
) => thread.lineage.relationshipToParent === "subagent" || thread.forkedFrom?.type === "node";
|
||||
|
||||
export const isUserFacingThread = (
|
||||
thread: Pick<OrchestrationV2ThreadShell, "forkedFrom" | "lineage">,
|
||||
) => !isInternalSubagentThread(thread);
|
||||
Reference in new issue
Block a user