Skip to content

Commit 662bbce

Browse files
committed
refactor(clients): child question selector returns thread shells
1 parent c7d32ae commit 662bbce

4 files changed

Lines changed: 11 additions & 38 deletions

File tree

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
515515
Keyboard.dismiss();
516516
navigation.navigate("Thread", {
517517
environmentId: props.environmentId,
518-
threadId: childInput.threadId,
518+
threadId: childInput.id,
519519
});
520520
},
521521
};

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7422,7 +7422,7 @@ export default function ChatView(props: ChatViewProps) {
74227422
const first = childThreadInputs[0];
74237423
if (!first || activePendingApproval || activePendingUserInput) return null;
74247424
return {
7425-
id: `child-input:${first.requestId}`,
7425+
id: `child-input:${first.id}`,
74267426
variant: "info",
74277427
priority: "activity",
74287428
icon: <MessageCircleIcon />,
@@ -7431,15 +7431,15 @@ export default function ChatView(props: ChatViewProps) {
74317431
? "Subagent needs input"
74327432
: `${childThreadInputs.length} subagents need input`,
74337433
description: childThreadInputs.map((child, index) => (
7434-
<Fragment key={child.threadId}>
7434+
<Fragment key={child.id}>
74357435
{index > 0 ? ", " : null}
7436-
<InlineButton tone="muted" onClick={() => onOpenRelatedThread(child.threadId)}>
7436+
<InlineButton tone="muted" onClick={() => onOpenRelatedThread(child.id)}>
74377437
{child.title}
74387438
</InlineButton>
74397439
</Fragment>
74407440
)),
74417441
actions: (
7442-
<Button size="xs" variant="ghost" onClick={() => onOpenRelatedThread(first.threadId)}>
7442+
<Button size="xs" variant="ghost" onClick={() => onOpenRelatedThread(first.id)}>
74437443
Open question
74447444
</Button>
74457445
),

‎apps/web/src/state/entities.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ const EMPTY_THREAD_SHELLS_ATOM = Atom.make<ReadonlyArray<EnvironmentThreadShell>
3737
const EMPTY_THREAD_SHELL_ATOM = Atom.make<EnvironmentThreadShell | null>(null).pipe(
3838
Atom.withLabel("web-thread-shell:empty"),
3939
);
40-
const EMPTY_CHILD_THREAD_INPUTS_ATOM = Atom.make<
41-
Atom.Type<ReturnType<typeof environmentThreadShells.childThreadInputsAtom>>
42-
>([]);
4340
const EMPTY_THREAD_PROJECTION_ATOM = Atom.make<EnvironmentThread | null>(null).pipe(
4441
Atom.withLabel("web-thread-projection:empty"),
4542
);
@@ -122,9 +119,7 @@ export function useThreadShell(ref: ScopedThreadRef | null): EnvironmentThreadSh
122119

123120
export function useChildThreadInputs(ref: ScopedThreadRef | null) {
124121
return useAtomValue(
125-
ref === null
126-
? EMPTY_CHILD_THREAD_INPUTS_ATOM
127-
: environmentThreadShells.childThreadInputsAtom(ref),
122+
ref === null ? EMPTY_THREAD_SHELLS_ATOM : environmentThreadShells.childThreadInputsAtom(ref),
128123
);
129124
}
130125

‎packages/client-runtime/src/state/threadShell.ts‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
OrchestrationV2ShellSnapshot,
44
OrchestrationV2ThreadShell,
55
ProjectId,
6-
RuntimeRequestId,
76
ScopedProjectRef,
87
ScopedThreadRef,
98
ThreadId,
@@ -26,11 +25,6 @@ import {
2625
const EMPTY_THREADS: ReadonlyArray<OrchestrationV2ThreadShell> = Object.freeze([]);
2726
const EMPTY_SCOPED_THREAD_REFS: ReadonlyArray<ScopedThreadRef> = Object.freeze([]);
2827
const EMPTY_THREAD_INDEX: ReadonlyMap<ThreadId, OrchestrationV2ThreadShell> = new Map();
29-
type ChildThreadInput = {
30-
readonly threadId: ThreadId;
31-
readonly title: string;
32-
readonly requestId: RuntimeRequestId;
33-
};
3428
const EMPTY_THREAD_REFS_BY_PROJECT: ReadonlyMap<
3529
ProjectId,
3630
ReadonlyArray<ScopedThreadRef>
@@ -146,10 +140,10 @@ export function createEnvironmentThreadShellAtoms(input: {
146140
});
147141

148142
// Child questions are hidden with their sidebar rows. Read their shell summaries,
149-
// without subscribing to every child transcript or repainting on unrelated activity.
143+
// without subscribing to every child transcript.
150144
const childThreadInputsAtomFamily = Atom.family((key: string) => {
151145
const ref = parseThreadKey(key);
152-
let previous: ReadonlyArray<ChildThreadInput> = [];
146+
let previous: ReadonlyArray<EnvironmentThreadShell> = [];
153147
return Atom.make((get) => {
154148
const children = new Map<ThreadId, OrchestrationV2ThreadShell[]>();
155149
for (const thread of get(environmentThreadsAtom(ref.environmentId))) {
@@ -161,7 +155,7 @@ export function createEnvironmentThreadShellAtoms(input: {
161155
}
162156
const seen = new Set<ThreadId>([ref.threadId]);
163157
const pending = [ref.threadId];
164-
const next: ChildThreadInput[] = [];
158+
const next: EnvironmentThreadShell[] = [];
165159
for (const parent of pending) {
166160
for (const child of children.get(parent) ?? []) {
167161
if (seen.has(child.id)) continue;
@@ -171,27 +165,11 @@ export function createEnvironmentThreadShellAtoms(input: {
171165
child.pendingRuntimeRequest?.kind === "user_input" &&
172166
!isProviderNativeSubagentThread(child)
173167
) {
174-
next.push({
175-
threadId: child.id,
176-
title: scopedThread(ref.environmentId, child).title,
177-
requestId: child.pendingRuntimeRequest.id,
178-
});
168+
next.push(scopedThread(ref.environmentId, child));
179169
}
180170
}
181171
}
182-
if (
183-
previous.length === next.length &&
184-
next.every((child, index) => {
185-
const old = previous[index];
186-
return (
187-
old?.threadId === child.threadId &&
188-
old.title === child.title &&
189-
old.requestId === child.requestId
190-
);
191-
})
192-
) {
193-
return previous;
194-
}
172+
if (arrayElementsEqual(previous, next)) return previous;
195173
previous = next;
196174
return next;
197175
}).pipe(Atom.withLabel(`environment-child-thread-inputs:${key}`));

0 commit comments

Comments
 (0)