feat(chat): show pending context handoff when selecting a model (#18369)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
9 files changed
+217
-43
No files matched your search
@@ -6,6 +6,7 @@ import type { WorktreeSetupCardProps } from "./worktree-setup-card";
|
||||
import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types";
|
||||
import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff";
|
||||
import type {
|
||||
CodexFeedbackSubmission,
|
||||
EnvironmentThreadStatus,
|
||||
@@ -162,6 +163,7 @@ export interface ThreadDetailScreenProps {
|
||||
readonly feedbackSubmissions: ReadonlyArray<CodexFeedbackSubmission>;
|
||||
readonly onDismissFeedback: (id: MessageId) => void;
|
||||
readonly selectedThreadFeed: ReadonlyArray<ThreadFeedEntry>;
|
||||
readonly pendingHandoff?: HandoffEndpoints | null;
|
||||
readonly activityRun: ThreadFeedLatestRun | null;
|
||||
readonly activeWorkStartedAt: string | null;
|
||||
/** The live work is a provider-native subagent's runless root turn. */
|
||||
@@ -1159,6 +1161,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
threadId={props.selectedThread.id}
|
||||
workspaceRoot={props.threadCwd}
|
||||
feed={props.selectedThreadFeed}
|
||||
pendingHandoff={props.pendingHandoff}
|
||||
worktreeSetup={props.worktreeSetup}
|
||||
setupWorkingStartedAt={props.setupWorkingStartedAt}
|
||||
queuedMessages={props.queuedMessages}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ThreadMarkdownVideo, ThreadMediaVisibleContext } from "./ThreadMarkdown
|
||||
import { useMarkdownImageSource } from "../../native/useMarkdownImageSource";
|
||||
import { enrichedContextLinkPresentation } from "../../lib/enrichedLinkPresentation";
|
||||
import { ThreadContextDivider } from "./thread-context-divider";
|
||||
import { ThreadHandoffRow } from "./thread-handoff-row";
|
||||
import { ThreadHandoffDivider, ThreadHandoffRow } from "./thread-handoff-row";
|
||||
import { SecretRequestCard } from "./SecretRequestCard";
|
||||
import { AppActivityIndicator } from "../../components/AppActivityIndicator";
|
||||
import {
|
||||
@@ -15,6 +15,7 @@ import * as Haptics from "expo-haptics";
|
||||
import { KeyboardAwareLegendList } from "@legendapp/list/keyboard";
|
||||
import { useViewabilityAmount, type LegendListRef } from "@legendapp/list/react-native";
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
|
||||
import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff";
|
||||
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
|
||||
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
|
||||
import {
|
||||
@@ -292,6 +293,7 @@ export interface ThreadFeedProps {
|
||||
readonly threadTitle: string;
|
||||
readonly workspaceRoot?: string | null;
|
||||
readonly feed: ReadonlyArray<ThreadFeedEntry>;
|
||||
readonly pendingHandoff?: HandoffEndpoints | null;
|
||||
readonly contentPresentation: ThreadContentPresentation;
|
||||
readonly agentLabel: string;
|
||||
readonly latestRun: ThreadFeedLatestRun | null;
|
||||
@@ -2756,6 +2758,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
ListFooterComponent={
|
||||
props.pendingHandoff ? (
|
||||
<ThreadHandoffDivider
|
||||
environmentId={props.environmentId}
|
||||
endpoints={props.pendingHandoff}
|
||||
iconColor={iconSubtleColor}
|
||||
label="Context handoff pending"
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
contentContainerStyle={{
|
||||
paddingTop: 12,
|
||||
paddingLeft: contentHorizontalPadding + contentLeftInset,
|
||||
|
||||
@@ -995,6 +995,7 @@ function ThreadRouteContent(
|
||||
feedbackSubmissions={composer.feedbackSubmissions}
|
||||
onDismissFeedback={composer.dismissFeedback}
|
||||
selectedThreadFeed={composer.selectedThreadFeed}
|
||||
pendingHandoff={composer.pendingHandoff}
|
||||
activityRun={composer.selectedThreadActivityRun}
|
||||
activeWorkStartedAt={
|
||||
creationState?.kind === "preparing" ||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
|
||||
import { resolveHandoffEndpoints } from "@t3tools/client-runtime/handoff";
|
||||
import { resolveHandoffEndpoints, type HandoffEndpoints } from "@t3tools/client-runtime/handoff";
|
||||
import { resolveProviderInstanceDisplayName } from "@t3tools/client-runtime/state/provider-instance-display";
|
||||
import type {
|
||||
EnvironmentId,
|
||||
@@ -45,15 +45,34 @@ export function ThreadHandoffRow(props: {
|
||||
[props.environmentId, props.projectedItem],
|
||||
);
|
||||
const endpoints = useAtomValue(endpointsAtom);
|
||||
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
|
||||
if (item.type !== "handoff" || endpoints === null) return null;
|
||||
const color = item.status === "failed" ? "#e11d48" : props.iconColor;
|
||||
return (
|
||||
<ThreadContextDivider
|
||||
label="Context handoff"
|
||||
icon="arrow.left.arrow.right"
|
||||
<ThreadHandoffDivider
|
||||
environmentId={props.environmentId}
|
||||
endpoints={endpoints}
|
||||
iconColor={color}
|
||||
label="Context handoff"
|
||||
failed={item.status === "failed"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function ThreadHandoffDivider(props: {
|
||||
environmentId: EnvironmentId;
|
||||
endpoints: HandoffEndpoints;
|
||||
iconColor: ColorValue;
|
||||
label: string;
|
||||
failed?: boolean;
|
||||
}) {
|
||||
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
|
||||
const { endpoints } = props;
|
||||
return (
|
||||
<ThreadContextDivider
|
||||
label={props.label}
|
||||
icon="arrow.left.arrow.right"
|
||||
iconColor={props.iconColor}
|
||||
failed={props.failed}
|
||||
>
|
||||
<View className="flex-row flex-wrap items-center justify-center gap-1.5">
|
||||
{endpoints.from.map((endpoint, index) => (
|
||||
@@ -67,7 +86,7 @@ export function ThreadHandoffRow(props: {
|
||||
</Fragment>
|
||||
))}
|
||||
{endpoints.from.length > 0 ? (
|
||||
<SymbolView name="arrow.right" size={12} tintColor={color} />
|
||||
<SymbolView name="arrow.right" size={12} tintColor={props.iconColor} />
|
||||
) : null}
|
||||
<HandoffEndpoint {...endpoints.to} providers={config?.providers ?? []} />
|
||||
</View>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { readEnvironmentScope } from "./session";
|
||||
import type { ComposerTextPaste } from "../native/T3ComposerEditor.types";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell";
|
||||
import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff";
|
||||
import {
|
||||
deriveProviderSubagentStatus,
|
||||
deriveRunlessWorkStartedAt,
|
||||
@@ -334,6 +335,15 @@ export function useThreadComposerState() {
|
||||
const selectedThreadQueueCount = selectedThreadQueuedMessages.length;
|
||||
const selectedThread = selectedThreadShell;
|
||||
const modelSelection = selectedDraft?.modelSelection ?? selectedThread?.modelSelection ?? null;
|
||||
const pendingHandoff = useMemo(
|
||||
() =>
|
||||
resolvePendingHandoff(
|
||||
selectedThreadProjection?.projection,
|
||||
modelSelection,
|
||||
selectedEnvironmentRuntime?.serverConfig?.providers ?? [],
|
||||
),
|
||||
[modelSelection, selectedThreadProjection, selectedEnvironmentRuntime?.serverConfig?.providers],
|
||||
);
|
||||
const runtimeMode = selectedDraft?.runtimeMode ?? selectedThread?.runtimeMode ?? null;
|
||||
const selectedProvider = selectedEnvironmentRuntime?.serverConfig?.providers.find(
|
||||
(provider) => provider.instanceId === modelSelection?.instanceId,
|
||||
@@ -1091,6 +1101,7 @@ export function useThreadComposerState() {
|
||||
cancelQueuedRunEdit,
|
||||
onRemoveQueuedEditAttachment,
|
||||
modelSelection,
|
||||
pendingHandoff,
|
||||
canSwitchThreadProvider,
|
||||
runtimeMode,
|
||||
interactionMode,
|
||||
|
||||
@@ -108,6 +108,8 @@ import {
|
||||
presentProviderGoal,
|
||||
} from "@t3tools/client-runtime/state/thread-execution";
|
||||
import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows";
|
||||
import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff";
|
||||
import { HandoffRow } from "./chat/V2LifecycleRow";
|
||||
import {
|
||||
codexFeedbackMessage,
|
||||
parseCodexFeedbackCommand,
|
||||
@@ -1802,6 +1804,12 @@ export default function ChatView(props: ChatViewProps) {
|
||||
const composerActiveProvider = useComposerDraftStore(
|
||||
(store) => store.getComposerDraft(composerDraftTarget)?.activeProvider ?? null,
|
||||
);
|
||||
const composerSelectedModelSelection = useComposerDraftStore((store) => {
|
||||
const draft = store.getComposerDraft(composerDraftTarget);
|
||||
return draft?.activeProvider
|
||||
? (draft.modelSelectionByProvider[draft.activeProvider] ?? null)
|
||||
: null;
|
||||
});
|
||||
const composerHasAttachments = useComposerDraftStore((store) => {
|
||||
const draft = store.getComposerDraft(composerDraftTarget);
|
||||
return (draft?.images.length ?? 0) > 0 || (draft?.files.length ?? 0) > 0;
|
||||
@@ -7733,6 +7741,20 @@ export default function ChatView(props: ChatViewProps) {
|
||||
item.type === "user_message" &&
|
||||
(item.text.trim().toLowerCase() !== "/compact" || item.attachments.length > 0),
|
||||
);
|
||||
const pendingHandoff = useMemo(
|
||||
() =>
|
||||
resolvePendingHandoff(
|
||||
serverProjection,
|
||||
composerSelectedModelSelection ?? activeThread?.modelSelection,
|
||||
providerStatuses,
|
||||
),
|
||||
[
|
||||
serverProjection,
|
||||
composerSelectedModelSelection,
|
||||
activeThread?.modelSelection,
|
||||
providerStatuses,
|
||||
],
|
||||
);
|
||||
const compactThreadUnavailable =
|
||||
!canOperateThread ||
|
||||
!activeThread ||
|
||||
@@ -11563,7 +11585,22 @@ export default function ChatView(props: ChatViewProps) {
|
||||
{...(draftId ? { onWorktreeSetupWorkLocally } : {})}
|
||||
{...(onOpenWorktreeSetupTerminal ? { onOpenWorktreeSetupTerminal } : {})}
|
||||
isPreparingWorktree={!paintOnlyDisplayedTimeline && isPreparingWorktree}
|
||||
footer={paintOnlyDisplayedTimeline ? null : threadStatusLine}
|
||||
footer={
|
||||
paintOnlyDisplayedTimeline ? null : pendingHandoff === null ? (
|
||||
threadStatusLine
|
||||
) : (
|
||||
<>
|
||||
<div className="chat-content-lane">
|
||||
<HandoffRow
|
||||
endpoints={pendingHandoff}
|
||||
providers={providerStatuses}
|
||||
pending
|
||||
/>
|
||||
</div>
|
||||
{threadStatusLine}
|
||||
</>
|
||||
)
|
||||
}
|
||||
listRef={legendListRef}
|
||||
timelineEntries={displayedTimeline.entries}
|
||||
providerStatuses={
|
||||
|
||||
@@ -10,7 +10,11 @@ import { environmentThreadDetails } from "../../state/threads";
|
||||
import { MiddleTruncate } from "../ui/middle-truncate";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import { WorkLogRow } from "./WorkLog";
|
||||
import { resolveHandoffEndpoints, type HandoffTimelineRun } from "@t3tools/client-runtime/handoff";
|
||||
import {
|
||||
resolveHandoffEndpoints,
|
||||
type HandoffEndpoints,
|
||||
type HandoffTimelineRun,
|
||||
} from "@t3tools/client-runtime/handoff";
|
||||
import { Fragment } from "react";
|
||||
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
|
||||
import {
|
||||
@@ -121,39 +125,11 @@ export function V2LifecycleRow(props: {
|
||||
);
|
||||
}
|
||||
if (item.type === "handoff") {
|
||||
const { from: fromEndpoints, to } = resolveHandoffEndpoints(item, props.runs);
|
||||
return (
|
||||
<TimelineSystemDivider
|
||||
label="Context handoff"
|
||||
icon={ArrowRightLeftIcon}
|
||||
showDetailSeparator={false}
|
||||
tone={item.status === "failed" ? "danger" : "neutral"}
|
||||
detail={
|
||||
<span className="inline-flex min-w-0 flex-wrap items-center justify-center gap-1.5">
|
||||
{fromEndpoints.map((endpoint, index) => (
|
||||
<Fragment key={`${endpoint.instanceId}:${endpoint.model ?? ""}`}>
|
||||
{index > 0 ? (
|
||||
<span aria-hidden="true" className="-ml-1">
|
||||
,
|
||||
</span>
|
||||
) : null}
|
||||
<HandoffEndpoint
|
||||
providers={props.providerStatuses}
|
||||
instanceId={endpoint.instanceId}
|
||||
model={endpoint.model}
|
||||
/>
|
||||
</Fragment>
|
||||
))}
|
||||
{fromEndpoints.length > 0 ? (
|
||||
<ArrowRightIcon aria-hidden="true" className="size-3 shrink-0" />
|
||||
) : null}
|
||||
<HandoffEndpoint
|
||||
providers={props.providerStatuses}
|
||||
instanceId={item.toProviderInstanceId}
|
||||
model={to.model}
|
||||
/>
|
||||
</span>
|
||||
}
|
||||
<HandoffRow
|
||||
endpoints={resolveHandoffEndpoints(item, props.runs)}
|
||||
providers={props.providerStatuses}
|
||||
failed={item.status === "failed"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -570,6 +546,49 @@ function SubagentTimelineTooltip(
|
||||
);
|
||||
}
|
||||
|
||||
export function HandoffRow(props: {
|
||||
readonly endpoints: HandoffEndpoints;
|
||||
readonly providers: ReadonlyArray<ServerProvider>;
|
||||
readonly pending?: boolean;
|
||||
readonly failed?: boolean;
|
||||
}) {
|
||||
const { from: fromEndpoints, to } = props.endpoints;
|
||||
return (
|
||||
<TimelineSystemDivider
|
||||
label={props.pending ? "Context handoff pending" : "Context handoff"}
|
||||
icon={ArrowRightLeftIcon}
|
||||
showDetailSeparator={false}
|
||||
tone={props.failed ? "danger" : "neutral"}
|
||||
detail={
|
||||
<span className="inline-flex min-w-0 flex-wrap items-center justify-center gap-1.5">
|
||||
{fromEndpoints.map((endpoint, index) => (
|
||||
<Fragment key={`${endpoint.instanceId}:${endpoint.model ?? ""}`}>
|
||||
{index > 0 ? (
|
||||
<span aria-hidden="true" className="-ml-1">
|
||||
,
|
||||
</span>
|
||||
) : null}
|
||||
<HandoffEndpoint
|
||||
providers={props.providers}
|
||||
instanceId={endpoint.instanceId}
|
||||
model={endpoint.model}
|
||||
/>
|
||||
</Fragment>
|
||||
))}
|
||||
{fromEndpoints.length > 0 ? (
|
||||
<ArrowRightIcon aria-hidden="true" className="size-3 shrink-0" />
|
||||
) : null}
|
||||
<HandoffEndpoint
|
||||
providers={props.providers}
|
||||
instanceId={to.instanceId}
|
||||
model={to.model}
|
||||
/>
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function HandoffEndpoint(props: {
|
||||
readonly providers: ReadonlyArray<ServerProvider>;
|
||||
readonly instanceId: ProviderInstanceId;
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { ProviderInstanceId, RunId } from "@t3tools/contracts";
|
||||
import {
|
||||
ProviderInstanceId,
|
||||
RunId,
|
||||
type OrchestrationV2ThreadProjection,
|
||||
type ServerProvider,
|
||||
} from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { resolveHandoffEndpoints, type HandoffTimelineRun } from "./handoff.ts";
|
||||
import {
|
||||
resolveHandoffEndpoints,
|
||||
resolvePendingHandoff,
|
||||
type HandoffTimelineRun,
|
||||
} from "./handoff.ts";
|
||||
|
||||
const from = ProviderInstanceId.make("codex_personal");
|
||||
const to = ProviderInstanceId.make("claudeAgent");
|
||||
@@ -63,3 +72,39 @@ describe("handoff endpoints shared by web and mobile", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
const projection = {
|
||||
runs: [{ ...run("source", 1, from, "source"), startedAt: "2026-10-11T00:00:00Z" }],
|
||||
} as unknown as OrchestrationV2ThreadProjection;
|
||||
|
||||
describe("pending context handoff", () => {
|
||||
it("appears on selection, updates the destination, and disappears on returning", () => {
|
||||
expect(resolvePendingHandoff(projection, { instanceId: to, model: "first" }, [])).toEqual({
|
||||
from: [{ instanceId: from, model: "source" }],
|
||||
to: { instanceId: to, model: "first" },
|
||||
});
|
||||
expect(
|
||||
resolvePendingHandoff(projection, { instanceId: to, model: "second" }, [])?.to.model,
|
||||
).toBe("second");
|
||||
expect(resolvePendingHandoff(projection, { instanceId: from, model: "source" }, [])).toBeNull();
|
||||
expect(resolvePendingHandoff(projection, { instanceId: from, model: "other" }, [])).toBeNull();
|
||||
});
|
||||
it("only previews a same-provider model change when it needs a fresh native thread", () => {
|
||||
const providers = [
|
||||
{ instanceId: from, requiresNewThreadForModelChange: true },
|
||||
] as unknown as ServerProvider[];
|
||||
expect(
|
||||
resolvePendingHandoff(projection, { instanceId: from, model: "other" }, providers)?.to.model,
|
||||
).toBe("other");
|
||||
});
|
||||
it("resumes compatible account overlays without showing a handoff", () => {
|
||||
const providers = [from, to].map((instanceId) => ({
|
||||
instanceId,
|
||||
driver: "codex",
|
||||
continuation: { groupKey: "shared" },
|
||||
})) as unknown as ServerProvider[];
|
||||
expect(
|
||||
resolvePendingHandoff(projection, { instanceId: to, model: "target" }, providers),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,10 @@
|
||||
import type {
|
||||
ModelSelection,
|
||||
OrchestrationV2Run,
|
||||
OrchestrationV2ThreadProjection,
|
||||
OrchestrationV2TurnItem,
|
||||
ProviderInstanceId,
|
||||
ServerProvider,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
/**
|
||||
@@ -14,6 +17,30 @@ export type HandoffTimelineRun = Pick<
|
||||
"id" | "ordinal" | "providerInstanceId" | "modelSelection"
|
||||
>;
|
||||
|
||||
export type HandoffEndpoints = ReturnType<typeof resolveHandoffEndpoints>;
|
||||
|
||||
/** Preview the next send's handoff without adding anything to durable history. */
|
||||
export function resolvePendingHandoff(
|
||||
projection: OrchestrationV2ThreadProjection | null | undefined,
|
||||
selection: ModelSelection | null | undefined,
|
||||
providers: ReadonlyArray<ServerProvider>,
|
||||
): HandoffEndpoints | null {
|
||||
const from = projection?.runs.findLast(
|
||||
(run) => run.startedAt !== null && run.status !== "rolled_back",
|
||||
)?.modelSelection;
|
||||
if (from === undefined || selection == null) return null;
|
||||
const source = providers.find((provider) => provider.instanceId === from.instanceId);
|
||||
const target = providers.find((provider) => provider.instanceId === selection.instanceId);
|
||||
const needsHandoff =
|
||||
from.instanceId === selection.instanceId
|
||||
? from.model !== selection.model && target?.requiresNewThreadForModelChange === true
|
||||
: // Accounts sharing a continuation group resume the same native thread.
|
||||
source?.continuation?.groupKey === undefined ||
|
||||
source.driver !== target?.driver ||
|
||||
source.continuation.groupKey !== target.continuation?.groupKey;
|
||||
return needsHandoff ? { from: [from], to: selection } : null;
|
||||
}
|
||||
|
||||
export function resolveHandoffEndpoints(
|
||||
item: Pick<
|
||||
Extract<OrchestrationV2TurnItem, { type: "handoff" }>,
|
||||
|
||||
Reference in new issue
Block a user