feat(web): start new threads with multiple models in separate worktrees (#12179)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
c0dded88b1
commit
0150c6a53b
19 files changed
+814
-56
No files matched your search
@@ -170,6 +170,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
|
||||
expect(second.capabilities.attachmentUploads).toBe(true);
|
||||
expect(second.capabilities.fileAttachments).toEqual({ maxUploadBytes: 50 * 1024 * 1024 });
|
||||
expect(second.capabilities.pullRequests).toBe(true);
|
||||
expect(second.capabilities.requiredWorktreeBootstrap).toBe(true);
|
||||
expect(second.capabilities.usagePriceOverrides).toBe(true);
|
||||
expect(second.capabilities.threadActiveReorder).toBe(true);
|
||||
expect(second.capabilities.threadTitleRegeneration).toBe(true);
|
||||
|
||||
@@ -222,6 +222,7 @@ export const make = Effect.gen(function* () {
|
||||
fileAttachments: { maxUploadBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES },
|
||||
pullRequests: true,
|
||||
inlineMessageContext: true,
|
||||
requiredWorktreeBootstrap: true,
|
||||
threadSettlement: true,
|
||||
threadAutoSettlement: true,
|
||||
storageCleanup: true,
|
||||
|
||||
@@ -11184,6 +11184,102 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect.each([
|
||||
{ caseName: "a non-repository", isRepository: false, failFetch: false },
|
||||
{ caseName: "a base without a commit", isRepository: true, failFetch: false },
|
||||
{ caseName: "a fetch failure", isRepository: true, failFetch: true },
|
||||
])(
|
||||
"rejects required worktree bootstrap before creating a thread for $caseName",
|
||||
({ isRepository, failFetch }) =>
|
||||
Effect.gen(function* () {
|
||||
const dispatchedCommands: Array<OrchestrationCommand> = [];
|
||||
const createWorktree = vi.fn(
|
||||
(_: Parameters<GitVcsDriver.GitVcsDriver["Service"]["createWorktree"]>[0]) =>
|
||||
Effect.die(new Error("createWorktree must not run before a valid base is found")),
|
||||
);
|
||||
|
||||
yield* buildAppUnderTest({
|
||||
layers: {
|
||||
vcsDriver: {
|
||||
isInsideWorkTree: () => Effect.succeed(isRepository),
|
||||
},
|
||||
gitVcsDriver: {
|
||||
execute: () =>
|
||||
Effect.succeed({
|
||||
...SUCCESSFUL_GIT_EXECUTION,
|
||||
exitCode: ChildProcessSpawner.ExitCode(128),
|
||||
stderr: "fatal: Needed a single revision",
|
||||
}),
|
||||
remoteExists: () => Effect.succeed(true),
|
||||
fetchRemote: () => Effect.die(new Error("fetch failed before thread creation")),
|
||||
createWorktree,
|
||||
},
|
||||
orchestrationEngine: {
|
||||
dispatch: (command) =>
|
||||
Effect.sync(() => {
|
||||
dispatchedCommands.push(command);
|
||||
return { sequence: dispatchedCommands.length };
|
||||
}),
|
||||
readEvents: () => Stream.empty,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
const wsUrl = yield* getWsServerUrl("/ws");
|
||||
const result = yield* Effect.scoped(
|
||||
withWsRpcClient(wsUrl, (client) =>
|
||||
client[ORCHESTRATION_WS_METHODS.dispatchCommand]({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.make("cmd-required-worktree"),
|
||||
threadId: ThreadId.make("thread-required-worktree"),
|
||||
message: {
|
||||
messageId: MessageId.make("msg-required-worktree"),
|
||||
role: "user",
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
modelSelection: defaultModelSelection,
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
bootstrap: {
|
||||
createThread: {
|
||||
projectId: defaultProjectId,
|
||||
title: "Bootstrap Thread",
|
||||
modelSelection: defaultModelSelection,
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: "main",
|
||||
worktreePath: null,
|
||||
createdAt,
|
||||
},
|
||||
prepareWorktree: {
|
||||
projectCwd: "/tmp/project",
|
||||
baseBranch: "main",
|
||||
requireWorktree: true,
|
||||
startFromOrigin: failFetch,
|
||||
},
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
).pipe(Effect.result),
|
||||
);
|
||||
|
||||
assertTrue(result._tag === "Failure");
|
||||
assertTrue(result.failure._tag === "OrchestrationDispatchCommandError");
|
||||
assert.strictEqual(result.failure.bootstrapThreadDisposition, "not-created");
|
||||
assert.include(
|
||||
result.failure.message,
|
||||
failFetch ? "fetch failed" : "separate worktree requires",
|
||||
);
|
||||
assert.equal(createWorktree.mock.calls.length, 0);
|
||||
assert.deepEqual(
|
||||
dispatchedCommands.map((command) => command.type),
|
||||
["thread.activity.append"],
|
||||
);
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("falls back to the project checkout when worktree mode targets a non-repository", () =>
|
||||
Effect.gen(function* () {
|
||||
const dispatchedCommands: Array<OrchestrationCommand> = [];
|
||||
|
||||
+12
-3
@@ -1369,6 +1369,12 @@ const makeWsRpcLayer = (
|
||||
}
|
||||
|
||||
if (prepareWorktree && !shouldPrepareWorktree) {
|
||||
if (prepareWorktree.requireWorktree) {
|
||||
return yield* new OrchestrationDispatchCommandError({
|
||||
message:
|
||||
"A separate worktree requires a Git repository and a base branch with a commit.",
|
||||
});
|
||||
}
|
||||
// Not a git repo, or the base has no commit: the thread runs in
|
||||
// the project checkout instead. The card says so and moves on.
|
||||
yield* track(
|
||||
@@ -1401,8 +1407,8 @@ const makeWsRpcLayer = (
|
||||
// every delete for the prior incarnation committed before it.
|
||||
// Drain through that event before setup or turn start can own
|
||||
// terminals and provider sessions under the reused thread id.
|
||||
yield* threadDeletionReactor.drainThrough(created.sequence);
|
||||
createdThread = true;
|
||||
yield* threadDeletionReactor.drainThrough(created.sequence);
|
||||
// Persist the send now rather than with the turn: the thread is
|
||||
// real from here on, so any client (or a reload) sees the message
|
||||
// while the worktree is still being prepared. The turn start
|
||||
@@ -1606,13 +1612,16 @@ const makeWsRpcLayer = (
|
||||
),
|
||||
onSuccess: (threadDeleted) =>
|
||||
Effect.fail(
|
||||
threadDeleted
|
||||
threadDeleted ||
|
||||
(bootstrap?.createThread &&
|
||||
bootstrap.prepareWorktree?.requireWorktree === true &&
|
||||
!createdThread)
|
||||
? new OrchestrationDispatchCommandError({
|
||||
message: dispatchError.message,
|
||||
...(dispatchError.cause !== undefined
|
||||
? { cause: dispatchError.cause }
|
||||
: {}),
|
||||
bootstrapThreadDisposition: "deleted",
|
||||
bootstrapThreadDisposition: threadDeleted ? "deleted" : "not-created",
|
||||
})
|
||||
: dispatchError,
|
||||
),
|
||||
|
||||
@@ -66,6 +66,7 @@ export interface BranchToolbarHandle {
|
||||
}
|
||||
|
||||
interface BranchToolbarProps {
|
||||
forceNewWorktree?: boolean;
|
||||
ref?: Ref<BranchToolbarHandle>;
|
||||
environmentId: EnvironmentId;
|
||||
threadId: ThreadId;
|
||||
@@ -89,6 +90,7 @@ interface BranchToolbarProps {
|
||||
}
|
||||
|
||||
interface MobileRunContextSelectorProps {
|
||||
forceNewWorktree: boolean;
|
||||
autoEnvironmentLabel?: string | undefined;
|
||||
onAutoEnvironment?: (() => void) | undefined;
|
||||
envLocked: boolean;
|
||||
@@ -106,6 +108,7 @@ interface MobileRunContextSelectorProps {
|
||||
}
|
||||
|
||||
const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
forceNewWorktree,
|
||||
autoEnvironmentLabel,
|
||||
onAutoEnvironment,
|
||||
envLocked,
|
||||
@@ -132,11 +135,13 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
: activeWorktreePath
|
||||
? FolderGitIcon
|
||||
: FolderIcon;
|
||||
const workspaceLabel = envModeLocked
|
||||
? resolveLockedWorkspaceLabel(activeWorktreePath)
|
||||
: effectiveEnvMode === "worktree"
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveCurrentWorkspaceLabel(activeWorktreePath);
|
||||
const workspaceLabel = forceNewWorktree
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: envModeLocked
|
||||
? resolveLockedWorkspaceLabel(activeWorktreePath)
|
||||
: effectiveEnvMode === "worktree"
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveCurrentWorkspaceLabel(activeWorktreePath);
|
||||
const isLocked = envLocked || envModeLocked;
|
||||
const workspaceIcon = (
|
||||
<Tooltip>
|
||||
@@ -269,7 +274,7 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
onEnvModeChange(value as EnvMode);
|
||||
}}
|
||||
>
|
||||
<MenuRadioItem disabled={envModeLocked} value="local">
|
||||
<MenuRadioItem disabled={envModeLocked || forceNewWorktree} value="local">
|
||||
<span className="flex min-w-0 items-center gap-1.5">
|
||||
{activeWorktreePath ? (
|
||||
<FolderGitIcon className="size-3" />
|
||||
@@ -476,6 +481,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
|
||||
}
|
||||
|
||||
export const BranchToolbar = memo(function BranchToolbar({
|
||||
forceNewWorktree = false,
|
||||
ref,
|
||||
environmentId,
|
||||
threadId,
|
||||
@@ -514,9 +520,11 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
: null;
|
||||
const activeProject = useProject(activeProjectRef);
|
||||
const hasActiveThread = serverThread !== null || draftThread !== null;
|
||||
const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
|
||||
const activeWorktreePath = forceNewWorktree
|
||||
? null
|
||||
: (serverThread?.worktreePath ?? draftThread?.worktreePath ?? null);
|
||||
const effectiveEnvMode =
|
||||
effectiveEnvModeOverride ??
|
||||
(forceNewWorktree ? "worktree" : effectiveEnvModeOverride) ??
|
||||
resolveEffectiveEnvMode({
|
||||
activeWorktreePath,
|
||||
hasServerThread: serverThread !== null,
|
||||
@@ -527,7 +535,8 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
// "Previous worktree" hops a draft into the most recently active worktree
|
||||
// of this project — the "keep going where I just was" follow-up flow. Only
|
||||
// drafts can hop; started server threads have their workspace pinned.
|
||||
const canUsePreviousWorktree = draftThread !== null && serverThread === null && !envModeLocked;
|
||||
const canUsePreviousWorktree =
|
||||
draftThread !== null && serverThread === null && !envModeLocked && !forceNewWorktree;
|
||||
const projectRefsForWorktreeLookup = useMemo(
|
||||
() => (canUsePreviousWorktree && activeProjectRef ? [activeProjectRef] : []),
|
||||
[canUsePreviousWorktree, activeProjectRef],
|
||||
@@ -606,6 +615,7 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
{showGitControls ? (
|
||||
<div className="contents @3xl/composer-surface:hidden">
|
||||
<MobileRunContextSelector
|
||||
forceNewWorktree={forceNewWorktree}
|
||||
autoEnvironmentLabel={autoEnvironmentLabel}
|
||||
onAutoEnvironment={onAutoEnvironment}
|
||||
envLocked={envLocked}
|
||||
@@ -652,6 +662,7 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
)}
|
||||
{showGitControls ? (
|
||||
<BranchToolbarEnvModeSelector
|
||||
forceNewWorktree={forceNewWorktree}
|
||||
envLocked={envModeLocked}
|
||||
effectiveEnvMode={effectiveEnvMode}
|
||||
activeWorktreePath={activeWorktreePath}
|
||||
@@ -677,13 +688,18 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
|
||||
{showGitControls ? (
|
||||
<BranchToolbarBranchSelector
|
||||
forceNewWorktree={forceNewWorktree}
|
||||
ref={branchSelectorRef}
|
||||
className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
|
||||
environmentId={environmentId}
|
||||
threadId={threadId}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
envLocked={envLocked}
|
||||
{...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
|
||||
{...(forceNewWorktree
|
||||
? { effectiveEnvModeOverride: "worktree" }
|
||||
: effectiveEnvModeOverride
|
||||
? { effectiveEnvModeOverride }
|
||||
: {})}
|
||||
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
|
||||
{...(onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : {})}
|
||||
startFromOrigin={startFromOrigin}
|
||||
|
||||
@@ -79,6 +79,7 @@ export interface BranchToolbarBranchSelectorHandle {
|
||||
}
|
||||
|
||||
interface BranchToolbarBranchSelectorProps {
|
||||
forceNewWorktree?: boolean;
|
||||
ref?: Ref<BranchToolbarBranchSelectorHandle>;
|
||||
className?: string;
|
||||
environmentId: EnvironmentId;
|
||||
@@ -99,6 +100,7 @@ function toBranchActionErrorMessage(error: unknown): string {
|
||||
}
|
||||
|
||||
export function BranchToolbarBranchSelector({
|
||||
forceNewWorktree = false,
|
||||
ref,
|
||||
className,
|
||||
environmentId,
|
||||
@@ -152,7 +154,9 @@ export function BranchToolbarBranchSelector({
|
||||
activeThreadBranchOverride !== undefined
|
||||
? activeThreadBranchOverride
|
||||
: (serverThread?.branch ?? draftThread?.branch ?? null);
|
||||
const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
|
||||
const activeWorktreePath = forceNewWorktree
|
||||
? null
|
||||
: (serverThread?.worktreePath ?? draftThread?.worktreePath ?? null);
|
||||
const activeProjectCwd = activeProject?.workspaceRoot ?? null;
|
||||
const branchCwd = activeWorktreePath ?? activeProjectCwd;
|
||||
const hasServerThread = serverThread !== null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
const PREVIOUS_WORKTREE_SELECT_VALUE = "previous-worktree";
|
||||
|
||||
interface BranchToolbarEnvModeSelectorProps {
|
||||
forceNewWorktree?: boolean;
|
||||
envLocked: boolean;
|
||||
effectiveEnvMode: EnvMode;
|
||||
activeWorktreePath: string | null;
|
||||
@@ -31,6 +32,7 @@ interface BranchToolbarEnvModeSelectorProps {
|
||||
}
|
||||
|
||||
export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSelector({
|
||||
forceNewWorktree = false,
|
||||
envLocked,
|
||||
effectiveEnvMode,
|
||||
activeWorktreePath,
|
||||
@@ -51,7 +53,7 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
|
||||
[activeWorktreePath, previousWorktreeLabel, showPreviousWorktree],
|
||||
);
|
||||
|
||||
if (envLocked) {
|
||||
if (envLocked || forceNewWorktree) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
@@ -59,7 +61,9 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
|
||||
className="inline-flex h-7 min-w-0 items-center gap-1 border border-transparent px-[calc(--spacing(2)-1px)] font-normal text-muted-foreground/70 text-xs sm:h-6"
|
||||
data-composer-context-control
|
||||
>
|
||||
{activeWorktreePath ? (
|
||||
{forceNewWorktree ? (
|
||||
<FolderGit2Icon className="size-3 shrink-0" />
|
||||
) : activeWorktreePath ? (
|
||||
<FolderGitIcon className="size-3 shrink-0" />
|
||||
) : (
|
||||
<FolderIcon className="size-3 shrink-0" />
|
||||
@@ -72,11 +76,17 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
|
||||
data-composer-label-motion
|
||||
className="block w-full min-w-0 max-w-[240px] truncate transition-opacity duration-180 ease-[cubic-bezier(0.32,0.72,0,1)] group-data-[compact]/composer-context:opacity-0 motion-reduce:transition-none"
|
||||
>
|
||||
{resolveLockedWorkspaceLabel(activeWorktreePath)}
|
||||
{forceNewWorktree
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveLockedWorkspaceLabel(activeWorktreePath)}
|
||||
</span>
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>{resolveLockedWorkspaceLabel(activeWorktreePath)}</TooltipPopup>
|
||||
<TooltipPopup>
|
||||
{forceNewWorktree
|
||||
? "Each model starts in its own worktree."
|
||||
: resolveLockedWorkspaceLabel(activeWorktreePath)}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,10 @@ import {
|
||||
type WorktreeSetupSnapshot,
|
||||
} from "@t3tools/contracts";
|
||||
import { type EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection";
|
||||
import { wasBootstrapThreadDeleted } from "@t3tools/client-runtime/errors";
|
||||
import {
|
||||
wasBootstrapThreadDeleted,
|
||||
wasBootstrapThreadNotCreated,
|
||||
} from "@t3tools/client-runtime/errors";
|
||||
import { readPastedComposerContext } from "./composerInlineTokenPaste";
|
||||
import { isPasteAsTextShortcut } from "@t3tools/client-runtime/text-paste";
|
||||
import { type CodexArtifactTemplate } from "@t3tools/client-runtime/codex-artifact-templates";
|
||||
@@ -82,9 +85,11 @@ import {
|
||||
} from "@t3tools/shared/terminalLabels";
|
||||
import { Debouncer } from "@tanstack/react-pacer";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { Atom } from "effect/unstable/reactivity";
|
||||
import {
|
||||
lazy,
|
||||
memo,
|
||||
type SetStateAction,
|
||||
Suspense,
|
||||
useCallback,
|
||||
useEffect,
|
||||
@@ -265,6 +270,10 @@ import { useRemoveClonedProject } from "../hooks/useRemoveClonedProject";
|
||||
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
|
||||
import { useThreadActions } from "../hooks/useThreadActions";
|
||||
import { resolveAppModelSelectionForInstance } from "../modelSelection";
|
||||
import {
|
||||
getComposerPromptInjectionState,
|
||||
getComposerProviderState,
|
||||
} from "./chat/composerProviderState";
|
||||
import { confirmTerminalClose, isTerminalCloseConfirmPending } from "../lib/terminalCloseConfirm";
|
||||
import { isPreviewFocused } from "../lib/previewFocus";
|
||||
import { getTerminalFocusOwner } from "../lib/terminalFocus";
|
||||
@@ -443,6 +452,7 @@ import {
|
||||
resolveBackgroundDraftWorkspaceOptions,
|
||||
resolveComposerInteractionMode,
|
||||
resolveComposerProviderSelection,
|
||||
getAntigravitySendBlockReason,
|
||||
resolveDraftHeroState,
|
||||
findRecordedWorktreeSetup,
|
||||
resolveVisibleWorktreeSetup,
|
||||
@@ -698,6 +708,14 @@ function pasteTextToFocusComposer(event: ClipboardEvent): string | null {
|
||||
return text.length > 0 ? text : null;
|
||||
}
|
||||
|
||||
const draftFanoutStateAtom = Atom.family((_routeKey: string) =>
|
||||
Atom.make({
|
||||
selections: null as ReadonlyArray<ModelSelection> | null,
|
||||
sendInFlight: { current: false },
|
||||
uncertainSubmissions: { current: new Map<string, ThreadId>() },
|
||||
}).pipe(Atom.keepAlive),
|
||||
);
|
||||
|
||||
function formatOutgoingPrompt(params: {
|
||||
provider: ProviderDriverKind;
|
||||
model: string | null;
|
||||
@@ -1771,7 +1789,23 @@ export default function ChatView(props: ChatViewProps) {
|
||||
const [timelineOverflows, setTimelineOverflows] = useState(false);
|
||||
const attachmentPreviewHandoffByMessageIdRef = useRef<Record<string, string[]>>({});
|
||||
const attachmentPreviewPromotionInFlightByMessageIdRef = useRef<Record<string, true>>({});
|
||||
const sendInFlightRef = useRef(false);
|
||||
const fanoutStateAtom = draftFanoutStateAtom(routeThreadKey);
|
||||
const fanoutState = useAtomValue(fanoutStateAtom);
|
||||
const sendInFlightRef = fanoutState.sendInFlight;
|
||||
const composerSendGenerationRef = useRef(0);
|
||||
const multipleModelSelections = fanoutState.selections;
|
||||
const setMultipleModelSelections = useCallback(
|
||||
(selections: SetStateAction<ReadonlyArray<ModelSelection> | null>) => {
|
||||
appAtomRegistry.update(fanoutStateAtom, (current) => ({
|
||||
...current,
|
||||
selections: typeof selections === "function" ? selections(current.selections) : selections,
|
||||
}));
|
||||
},
|
||||
[fanoutStateAtom],
|
||||
);
|
||||
const multipleModelSelectionsRef = useRef(multipleModelSelections);
|
||||
multipleModelSelectionsRef.current = multipleModelSelections;
|
||||
const uncertainMultipleSubmissionsRef = fanoutState.uncertainSubmissions;
|
||||
const environmentUnavailableSendToastSlotRef = useRef(0);
|
||||
const feedbackUploadsInFlightRef = useRef(new Set<string>());
|
||||
const terminalUiOpenByThreadRef = useRef<Record<string, boolean>>({});
|
||||
@@ -7302,6 +7336,31 @@ export default function ChatView(props: ChatViewProps) {
|
||||
notifyDirectAnnotationAttached();
|
||||
return;
|
||||
}
|
||||
const multipleModelSelections = queuedMessage ? null : sendCtx.multipleModelSelections;
|
||||
if (
|
||||
multipleModelSelections !== null &&
|
||||
serverConfig?.environment.capabilities.requiredWorktreeBootstrap !== true
|
||||
) {
|
||||
setThreadError(activeThread.id, "Update this server before starting multiple models.");
|
||||
return;
|
||||
}
|
||||
if (
|
||||
multipleModelSelections !== null &&
|
||||
(!isLocalDraftThread ||
|
||||
!isGitRepo ||
|
||||
!activeThreadBranch ||
|
||||
multipleModelSelections.length === 0)
|
||||
) {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "warning",
|
||||
title: "Choose models and a base branch",
|
||||
description:
|
||||
"Multiple models need a new thread in a Git project. Each gets its own worktree.",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const {
|
||||
images: sendContextImages,
|
||||
files: composerFiles,
|
||||
@@ -7379,7 +7438,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
composerReviewComments.length === 0
|
||||
? parseCodexFeedbackCommand(trimmed)
|
||||
: null;
|
||||
if (feedbackCommand && !queuedMessage) {
|
||||
if (feedbackCommand && !queuedMessage && multipleModelSelections === null) {
|
||||
if (!isServerThread || activeThread.session === null) {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
@@ -7502,7 +7561,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
composerReviewComments.length === 0
|
||||
? parseStandaloneComposerSlashCommand(trimmed)
|
||||
: null;
|
||||
if (standaloneSlashCommand && !queuedMessage) {
|
||||
if (standaloneSlashCommand && !queuedMessage && multipleModelSelections === null) {
|
||||
handleInteractionModeChange(standaloneSlashCommand);
|
||||
promptRef.current = "";
|
||||
clearComposerDraftContent(composerDraftTarget);
|
||||
@@ -7652,7 +7711,53 @@ export default function ChatView(props: ChatViewProps) {
|
||||
};
|
||||
};
|
||||
|
||||
const multipleTargets = [];
|
||||
for (const selection of multipleModelSelections ?? []) {
|
||||
const provider = providerInstanceEntries.find(
|
||||
(entry) => entry.instanceId === selection.instanceId,
|
||||
);
|
||||
if (!provider?.enabled || !provider.isAvailable || provider.status !== "ready") {
|
||||
setThreadError(threadIdForSend, `Provider for ${selection.model} is unavailable.`);
|
||||
return;
|
||||
}
|
||||
const providerBlockReason = getAntigravitySendBlockReason(provider.snapshot, selection.model);
|
||||
if (providerBlockReason) {
|
||||
setThreadError(threadIdForSend, providerBlockReason);
|
||||
return;
|
||||
}
|
||||
const providerState = getComposerProviderState({
|
||||
provider: provider.driverKind,
|
||||
model: selection.model,
|
||||
models: provider.models,
|
||||
modelOptions: selection.options,
|
||||
promptInjectionState: getComposerPromptInjectionState(messageTextForSend),
|
||||
planModeEnabled: settings.planModeEnabled,
|
||||
});
|
||||
const text = formatOutgoingPrompt({
|
||||
provider: provider.driverKind,
|
||||
model: selection.model,
|
||||
models: provider.models,
|
||||
effort: providerState.promptEffort,
|
||||
text: messageTextForSend || ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
|
||||
});
|
||||
if (composerRef.current?.validateProviderInput(text) === false) return;
|
||||
multipleTargets.push({
|
||||
selection: createModelSelection(
|
||||
selection.instanceId,
|
||||
selection.model,
|
||||
providerState.modelOptionsForDispatch,
|
||||
),
|
||||
text,
|
||||
interactionMode: resolveComposerInteractionMode({
|
||||
planModeEnabled: settings.planModeEnabled,
|
||||
provider: provider.snapshot,
|
||||
interactionMode: sendInteractionMode,
|
||||
}).interactionMode,
|
||||
});
|
||||
}
|
||||
|
||||
sendInFlightRef.current = true;
|
||||
const sendGeneration = ++composerSendGenerationRef.current;
|
||||
// Every early return above leaves a queued message in the queue for a
|
||||
// later retry. From here on a failure hands it back to the composer.
|
||||
if (queuedMessage) {
|
||||
@@ -7728,7 +7833,9 @@ export default function ChatView(props: ChatViewProps) {
|
||||
}
|
||||
|
||||
const resolvedSubmissionIntent =
|
||||
submissionIntent === "background" && isLocalDraftThread ? "background" : "foreground";
|
||||
(multipleModelSelections !== null || submissionIntent === "background") && isLocalDraftThread
|
||||
? "background"
|
||||
: "foreground";
|
||||
if (
|
||||
shouldDockDraftHeroForSubmission({
|
||||
isDraftHeroState,
|
||||
@@ -7763,7 +7870,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
return;
|
||||
}
|
||||
beginLocalDispatch({
|
||||
preparingWorktree: Boolean(baseBranchForWorktree),
|
||||
preparingWorktree: multipleModelSelections !== null || Boolean(baseBranchForWorktree),
|
||||
submissionIntent: resolvedSubmissionIntent,
|
||||
});
|
||||
|
||||
@@ -7792,6 +7899,267 @@ export default function ChatView(props: ChatViewProps) {
|
||||
};
|
||||
}),
|
||||
);
|
||||
if (multipleModelSelections !== null) {
|
||||
const failedSelections: ModelSelection[] = [];
|
||||
let clearedDraft = false;
|
||||
let releasedComposer = false;
|
||||
let canRestoreDraft = () => false;
|
||||
let startedCount = 0;
|
||||
try {
|
||||
const attachments = await turnAttachmentsPromise;
|
||||
const fileBlockReason = readLiveAttachmentCapabilities().fileBlockReason;
|
||||
if (fileBlockReason !== null) throw new Error(fileBlockReason);
|
||||
const context = buildOutgoingMessageContext(
|
||||
attachments.map((attachment, index) =>
|
||||
"id" in attachment && attachment.id !== undefined
|
||||
? attachment.id
|
||||
: composerAttachmentsSnapshot[index]!.id,
|
||||
),
|
||||
);
|
||||
const title = truncate(
|
||||
assistantCitationsToPlainText(stripInlineContextReferences(trimmed)).trim() ||
|
||||
composerAttachmentsSnapshot[0]?.name ||
|
||||
"New thread",
|
||||
);
|
||||
promptRef.current = "";
|
||||
clearComposerDraftContent(composerDraftTarget);
|
||||
composerRef.current?.resetCursorState();
|
||||
clearedDraft = true;
|
||||
const clearedDraftSnapshot = useComposerDraftStore
|
||||
.getState()
|
||||
.getComposerDraft(composerDraftTarget);
|
||||
const submittedSelections = multipleModelSelectionsRef.current;
|
||||
canRestoreDraft = () =>
|
||||
currentRouteThreadKeyRef.current === routeThreadKey &&
|
||||
composerSendGenerationRef.current === sendGeneration &&
|
||||
useComposerDraftStore.getState().getComposerDraft(composerDraftTarget) ===
|
||||
clearedDraftSnapshot &&
|
||||
multipleModelSelectionsRef.current === submittedSelections;
|
||||
setThreadError(threadIdForSend, null);
|
||||
const starts = Promise.all(
|
||||
multipleTargets.map(async (target) => {
|
||||
const retryKey = JSON.stringify([
|
||||
routeThreadKey,
|
||||
target.selection.instanceId,
|
||||
target.selection.model,
|
||||
]);
|
||||
const uncertainThreadId = uncertainMultipleSubmissionsRef.current.get(retryKey);
|
||||
const targetThreadId = uncertainThreadId ?? newThreadId();
|
||||
let requestMayHaveStarted = false;
|
||||
try {
|
||||
if (uncertainThreadId) {
|
||||
throw new Error(
|
||||
"The previous request may have started. Open its thread to check before sending again.",
|
||||
);
|
||||
}
|
||||
const supportsInlineMessageContext =
|
||||
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment
|
||||
.capabilities.inlineMessageContext === true;
|
||||
requestMayHaveStarted = true;
|
||||
const result = await startThreadTurn({
|
||||
environmentId,
|
||||
input: {
|
||||
threadId: targetThreadId,
|
||||
message: {
|
||||
messageId: newMessageId(),
|
||||
role: "user",
|
||||
text:
|
||||
context && !supportsInlineMessageContext
|
||||
? serializeLegacyContextMessage({
|
||||
text: target.text,
|
||||
records: context.records,
|
||||
})
|
||||
: target.text,
|
||||
attachments,
|
||||
...(context && supportsInlineMessageContext ? { context } : {}),
|
||||
},
|
||||
modelSelection: target.selection,
|
||||
titleSeed: title,
|
||||
runtimeMode,
|
||||
interactionMode: target.interactionMode,
|
||||
bootstrap: {
|
||||
createThread: {
|
||||
projectId: activeProject.id,
|
||||
title,
|
||||
modelSelection: target.selection,
|
||||
runtimeMode,
|
||||
interactionMode: target.interactionMode,
|
||||
branch: activeThreadBranch,
|
||||
worktreePath: null,
|
||||
createdAt: messageCreatedAt,
|
||||
},
|
||||
prepareWorktree: {
|
||||
projectCwd: activeProject.workspaceRoot,
|
||||
baseBranch: activeThreadBranch!,
|
||||
requireWorktree: true,
|
||||
branch: buildTemporaryWorktreeBranchName(randomHex),
|
||||
...(startFromOrigin ? { startFromOrigin: true } : {}),
|
||||
},
|
||||
runSetupScript: true,
|
||||
},
|
||||
createdAt: messageCreatedAt,
|
||||
},
|
||||
});
|
||||
if (result._tag === "Failure") {
|
||||
const error = squashAtomCommandFailure(result);
|
||||
if (wasBootstrapThreadDeleted(error) || wasBootstrapThreadNotCreated(error)) {
|
||||
requestMayHaveStarted = false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
startedCount += 1;
|
||||
} catch (error) {
|
||||
if (requestMayHaveStarted && !uncertainMultipleSubmissionsRef.current.has(retryKey)) {
|
||||
uncertainMultipleSubmissionsRef.current.set(retryKey, targetThreadId);
|
||||
}
|
||||
failedSelections.push(target.selection);
|
||||
const retainedThreadId = uncertainMultipleSubmissionsRef.current.get(retryKey);
|
||||
const failureToastId = toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: `Could not start ${target.selection.model}`,
|
||||
description: error instanceof Error ? error.message : "Failed to send message.",
|
||||
...(retainedThreadId
|
||||
? {
|
||||
timeout: 0,
|
||||
data: {
|
||||
secondaryActionProps: {
|
||||
children: "Allow retry",
|
||||
onClick: () => {
|
||||
void readLocalApi()
|
||||
?.dialogs.confirm(
|
||||
"The previous request may already be running. Check its thread first. Allow another send that could create a duplicate thread?",
|
||||
)
|
||||
.then(
|
||||
(confirmed) => {
|
||||
if (
|
||||
confirmed &&
|
||||
uncertainMultipleSubmissionsRef.current.get(retryKey) ===
|
||||
retainedThreadId
|
||||
) {
|
||||
uncertainMultipleSubmissionsRef.current.delete(retryKey);
|
||||
toastManager.close(failureToastId);
|
||||
}
|
||||
},
|
||||
() => undefined,
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
actionProps: {
|
||||
children: "Open thread",
|
||||
onClick: () => {
|
||||
void navigate({
|
||||
to: "/$environmentId/$threadId",
|
||||
params: buildThreadRouteParams(
|
||||
scopeThreadRef(environmentId, retainedThreadId),
|
||||
),
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
// Each request now owns its background thread. The original draft is
|
||||
// ready for another prompt while checkout and setup scripts finish.
|
||||
sendInFlightRef.current = false;
|
||||
resetLocalDispatch();
|
||||
releasedComposer = true;
|
||||
await starts;
|
||||
if (startedCount > 0) {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "success",
|
||||
title: `Started ${startedCount} ${startedCount === 1 ? "thread" : "threads"} in background`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (failedSelections.length === 0 && turnUsesAttachmentUploads) {
|
||||
releaseDraftAttachments(composerAttachmentsSnapshot);
|
||||
}
|
||||
} catch (error) {
|
||||
failedSelections.push(...multipleModelSelections);
|
||||
setThreadError(
|
||||
threadIdForSend,
|
||||
error instanceof Error ? error.message : "Failed to send messages.",
|
||||
);
|
||||
} finally {
|
||||
const restoreFailedDraft = () => {
|
||||
setMultipleModelSelections(failedSelections);
|
||||
if (clearedDraft) {
|
||||
setComposerDraftPrompt(composerDraftTarget, messageTextForSend);
|
||||
addComposerDraftImages(
|
||||
composerDraftTarget,
|
||||
composerImagesSnapshot.map(cloneComposerImageForRetry),
|
||||
);
|
||||
addComposerDraftFiles(composerDraftTarget, composerFilesSnapshot);
|
||||
setComposerDraftTerminalContexts(composerDraftTarget, composerTerminalContextsSnapshot);
|
||||
setComposerDraftPreviewAnnotations(
|
||||
composerDraftTarget,
|
||||
composerPreviewAnnotationsSnapshot,
|
||||
);
|
||||
setComposerDraftReviewComments(composerDraftTarget, composerReviewCommentsSnapshot);
|
||||
if (composerRef.current && currentRouteThreadKeyRef.current === routeThreadKey) {
|
||||
promptRef.current = messageTextForSend;
|
||||
composerRef.current.resetCursorState({
|
||||
cursor: collapseExpandedComposerCursor(
|
||||
messageTextForSend,
|
||||
messageTextForSend.length,
|
||||
),
|
||||
prompt: messageTextForSend,
|
||||
detectTrigger: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
if (failedSelections.length > 0) {
|
||||
if (canRestoreDraft() && composerRef.current) {
|
||||
restoreFailedDraft();
|
||||
} else if (clearedDraft) {
|
||||
const recoveryToastId = toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "A background prompt could not be sent",
|
||||
description:
|
||||
"Your newer draft is unchanged. Restore the failed prompt when this composer is empty.",
|
||||
timeout: 0,
|
||||
actionProps: {
|
||||
children: "Restore prompt",
|
||||
onClick: () => {
|
||||
if (
|
||||
!draftId ||
|
||||
!useComposerDraftStore.getState().getDraftSession(draftId) ||
|
||||
sendInFlightRef.current ||
|
||||
composerDraftHasUserContent(
|
||||
useComposerDraftStore.getState().getComposerDraft(composerDraftTarget),
|
||||
)
|
||||
) {
|
||||
toastManager.update(recoveryToastId, {
|
||||
description:
|
||||
"Return to the original draft and send or clear its current prompt before restoring.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
restoreFailedDraft();
|
||||
void navigate({ to: "/draft/$draftId", params: { draftId } });
|
||||
toastManager.close(recoveryToastId);
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!releasedComposer) {
|
||||
sendInFlightRef.current = false;
|
||||
resetLocalDispatch();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
const optimisticAttachments = composerAttachmentsSnapshot.map((attachment) =>
|
||||
attachment.type === "image"
|
||||
? {
|
||||
@@ -8868,7 +9236,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
);
|
||||
|
||||
const onProviderModelSelect = useCallback(
|
||||
(instanceId: ProviderInstanceId, model: string) => {
|
||||
(instanceId: ProviderInstanceId, model: string, options?: { focusComposer?: boolean }) => {
|
||||
if (!activeThread) return;
|
||||
// Look up the configured instance so model normalization and custom
|
||||
// model lookup stay scoped to that exact instance. Unknown instance ids
|
||||
@@ -8880,7 +9248,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
resolvedDriverKind !== null &&
|
||||
resolvedDriverKind !== lockedProvider
|
||||
) {
|
||||
scheduleComposerFocus();
|
||||
if (options?.focusComposer !== false) scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
if (lockedProvider !== null && activeThread.session?.providerInstanceId) {
|
||||
@@ -8892,7 +9260,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
entry?.continuation?.groupKey &&
|
||||
currentEntry.continuation.groupKey !== entry.continuation.groupKey
|
||||
) {
|
||||
scheduleComposerFocus();
|
||||
if (options?.focusComposer !== false) scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -8903,7 +9271,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
model,
|
||||
);
|
||||
if (!resolvedModel) {
|
||||
scheduleComposerFocus();
|
||||
if (options?.focusComposer !== false) scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
const nextModelSelection: ModelSelection = {
|
||||
@@ -8923,7 +9291,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
title: modelChangeBlockReason.title,
|
||||
description: modelChangeBlockReason.description,
|
||||
});
|
||||
scheduleComposerFocus();
|
||||
if (options?.focusComposer !== false) scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
setComposerDraftModelSelection(
|
||||
@@ -8932,7 +9300,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
{ explicit: true },
|
||||
);
|
||||
setStickyComposerModelSelection(nextModelSelection);
|
||||
scheduleComposerFocus();
|
||||
if (options?.focusComposer !== false) scheduleComposerFocus();
|
||||
},
|
||||
[
|
||||
activeThread,
|
||||
@@ -8946,6 +9314,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
);
|
||||
const onEnvModeChange = useCallback(
|
||||
(mode: DraftThreadEnvMode) => {
|
||||
if (multipleModelSelections !== null) return;
|
||||
if (canOverrideServerThreadEnvMode) {
|
||||
setPendingServerThreadEnvMode(mode);
|
||||
scheduleComposerFocus();
|
||||
@@ -8968,6 +9337,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
composerDraftTarget,
|
||||
draftThread?.worktreePath,
|
||||
isLocalDraftThread,
|
||||
multipleModelSelections,
|
||||
activeProjectSettings.settings.newWorktreesStartFromOrigin,
|
||||
setPendingServerThreadEnvMode,
|
||||
scheduleComposerFocus,
|
||||
@@ -9632,6 +10002,12 @@ export default function ChatView(props: ChatViewProps) {
|
||||
<ComposerSurface.Host>
|
||||
<div ref={attachDraftHeroComposerAnchorRef} className="relative z-10">
|
||||
<ChatComposer
|
||||
multipleModelSelections={multipleModelSelections}
|
||||
supportsMultipleModels={
|
||||
serverConfig?.environment.capabilities.requiredWorktreeBootstrap ===
|
||||
true
|
||||
}
|
||||
onMultipleModelSelectionsChange={setMultipleModelSelections}
|
||||
composerRef={composerRef}
|
||||
composerDraftTarget={composerDraftTarget}
|
||||
environmentId={environmentId}
|
||||
@@ -9769,6 +10145,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
{mountComposerContextStrip && (
|
||||
<div className="pointer-events-auto">
|
||||
<BranchToolbar
|
||||
forceNewWorktree={multipleModelSelections !== null}
|
||||
ref={branchToolbarRef}
|
||||
environmentId={activeThread.environmentId}
|
||||
threadId={activeThread.id}
|
||||
|
||||
@@ -245,6 +245,7 @@ import {
|
||||
import { useEnvironmentQuery } from "~/state/query";
|
||||
import { useDebouncedValue } from "~/state/queries";
|
||||
import { ProviderModelPicker } from "./ProviderModelPicker";
|
||||
import { resolveModelPickerSelectedModel } from "./ModelPickerContent";
|
||||
import { type ComposerCommandItem, ComposerCommandMenu } from "./ComposerCommandMenu";
|
||||
import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
|
||||
import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu";
|
||||
@@ -1267,6 +1268,7 @@ export interface ChatComposerHandle {
|
||||
selectedPromptEffort: string | null;
|
||||
selectedModelOptionsForDispatch: unknown;
|
||||
selectedModelSelection: ModelSelection;
|
||||
multipleModelSelections: ReadonlyArray<ModelSelection> | null;
|
||||
providerAvailable: boolean;
|
||||
selectedProvider: ProviderDriverKind;
|
||||
selectedModel: string;
|
||||
@@ -1276,6 +1278,7 @@ export interface ChatComposerHandle {
|
||||
};
|
||||
/** Validate the fully composed text immediately before a provider turn starts. */
|
||||
validateProviderInput: (providerInput: string) => boolean;
|
||||
setMultipleModelSelections: (selections: ReadonlyArray<ModelSelection>) => void;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@@ -1292,6 +1295,11 @@ export interface ChatComposerProps {
|
||||
routeKind: "server" | "draft";
|
||||
routeThreadRef: ScopedThreadRef;
|
||||
draftId: DraftId | null;
|
||||
multipleModelSelections: ReadonlyArray<ModelSelection> | null;
|
||||
supportsMultipleModels: boolean;
|
||||
onMultipleModelSelectionsChange: React.Dispatch<
|
||||
React.SetStateAction<ReadonlyArray<ModelSelection> | null>
|
||||
>;
|
||||
|
||||
// Thread context
|
||||
activeThreadId: ThreadId | null;
|
||||
@@ -1420,7 +1428,11 @@ export interface ChatComposerProps {
|
||||
cursorAdjacentToMention: boolean,
|
||||
) => void;
|
||||
|
||||
onProviderModelSelect: (instanceId: ProviderInstanceId, model: string) => void;
|
||||
onProviderModelSelect: (
|
||||
instanceId: ProviderInstanceId,
|
||||
model: string,
|
||||
options?: { focusComposer?: boolean },
|
||||
) => void;
|
||||
onOpenProviderSetup: (instanceId: ProviderInstanceId) => void;
|
||||
getModelDisabledReason: (instanceId: ProviderInstanceId, model: string) => string | null;
|
||||
toggleInteractionMode: () => void;
|
||||
@@ -1449,6 +1461,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
routeKind,
|
||||
routeThreadRef,
|
||||
draftId,
|
||||
multipleModelSelections,
|
||||
supportsMultipleModels,
|
||||
onMultipleModelSelectionsChange: setMultipleModelSelections,
|
||||
activeThreadId,
|
||||
activeThreadEnvironmentId: _activeThreadEnvironmentId,
|
||||
activeThread,
|
||||
@@ -1847,7 +1862,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
);
|
||||
const selectedInstanceId =
|
||||
selectedProviderEntry?.instanceId ?? NO_PROVIDER_MODEL_SELECTION.instanceId;
|
||||
const noProviderAvailable = selectedProviderEntry === undefined;
|
||||
const noProviderAvailable =
|
||||
selectedProviderEntry === undefined && multipleModelSelections === null;
|
||||
// Before the catalog arrives, every thread resolves to "no provider". Send
|
||||
// stays blocked either way; only the chrome waits, keeping the picker with
|
||||
// the thread's own selection instead of swapping in the setup button and
|
||||
@@ -1883,9 +1899,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
);
|
||||
const sendDisabledReason =
|
||||
externalSendDisabledReason ??
|
||||
(multipleModelSelections?.length === 0 ? "Select at least one model." : null) ??
|
||||
(activePendingProgress
|
||||
? attachmentBlockReason
|
||||
: (attachmentBlockReason ?? providerSendBlockReason));
|
||||
: (attachmentBlockReason ??
|
||||
(multipleModelSelections === null ? providerSendBlockReason : null)));
|
||||
const isSendDisabled = sendDisabledReason !== null;
|
||||
const selectedProviderStatus = useMemo(
|
||||
() => selectedProviderEntry?.snapshot ?? null,
|
||||
@@ -4943,7 +4961,42 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
) : null}
|
||||
<ProviderModelPicker
|
||||
isComposerOwned
|
||||
disabled={providerCatalogPending}
|
||||
disabled={providerCatalogPending || isSendBusy}
|
||||
{...(routeKind === "draft" && supportsMultipleModels
|
||||
? {
|
||||
...(multipleModelSelections !== null
|
||||
? { selectedModels: multipleModelSelections }
|
||||
: {}),
|
||||
onToggleModel: (instanceId: ProviderInstanceId, model: string) => {
|
||||
const current = multipleModelSelections ?? [selectedModelSelection];
|
||||
const matchesModel = (selection: ModelSelection) => {
|
||||
if (selection.instanceId !== instanceId) return false;
|
||||
const entry = providerInstanceEntries.find(
|
||||
(entry) => entry.instanceId === selection.instanceId,
|
||||
);
|
||||
const resolvedModel = resolveModelPickerSelectedModel({
|
||||
driverKind: entry?.driverKind,
|
||||
model: selection.model,
|
||||
options: modelOptionsByInstance.get(selection.instanceId) ?? [],
|
||||
});
|
||||
return (resolvedModel?.slug ?? selection.model) === model;
|
||||
};
|
||||
const exists = current.some(matchesModel);
|
||||
const next = exists
|
||||
? current.filter((selection) => !matchesModel(selection))
|
||||
: [...current, createModelSelection(instanceId, model)];
|
||||
if (next.length > 1) {
|
||||
setMultipleModelSelections(next);
|
||||
} else {
|
||||
setMultipleModelSelections(null);
|
||||
const remaining = next[0] ?? selectedModelSelection;
|
||||
onProviderModelSelect(remaining.instanceId, remaining.model, {
|
||||
focusComposer: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
: {})}
|
||||
activeInstanceId={
|
||||
providerCatalogPending
|
||||
? (activeThreadModelSelection?.instanceId ?? selectedInstanceId)
|
||||
@@ -4983,7 +5036,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
: {})}
|
||||
onOpenChange={setIsComposerModelPickerOpen}
|
||||
getModelDisabledReason={getModelDisabledReason}
|
||||
onInstanceModelChange={onProviderModelSelect}
|
||||
onInstanceModelChange={(instanceId, model) => {
|
||||
setMultipleModelSelections(null);
|
||||
onProviderModelSelect(instanceId, model);
|
||||
}}
|
||||
onOpenProviderSetup={onOpenProviderSetup}
|
||||
/>
|
||||
|
||||
@@ -5902,13 +5958,25 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
selectedPromptEffort,
|
||||
selectedModelOptionsForDispatch,
|
||||
selectedModelSelection,
|
||||
providerAvailable: !noProviderAvailable && providerSendBlockReason === null,
|
||||
multipleModelSelections:
|
||||
routeKind === "draft" && multipleModelSelections !== null
|
||||
? multipleModelSelections.map((selection) =>
|
||||
selection.instanceId === selectedModelSelection.instanceId &&
|
||||
selection.model === selectedModelSelection.model
|
||||
? selectedModelSelection
|
||||
: selection,
|
||||
)
|
||||
: null,
|
||||
providerAvailable:
|
||||
multipleModelSelections !== null ||
|
||||
(!noProviderAvailable && providerSendBlockReason === null),
|
||||
selectedProvider,
|
||||
selectedModel,
|
||||
selectedProviderModels,
|
||||
interactionMode,
|
||||
interactionModeEnabled: planModeUiEnabled,
|
||||
}),
|
||||
setMultipleModelSelections,
|
||||
validateProviderInput: (providerInput: string) => {
|
||||
const validationMessage = getComposerSubmissionValidationMessage({
|
||||
prompt: promptRef.current,
|
||||
@@ -5951,6 +6019,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
selectedModel,
|
||||
selectedModelOptionsForDispatch,
|
||||
selectedModelSelection,
|
||||
multipleModelSelections,
|
||||
setMultipleModelSelections,
|
||||
routeKind,
|
||||
noProviderAvailable,
|
||||
providerSendBlockReason,
|
||||
selectedPromptEffort,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type ProviderDriverKind, type ProviderInstanceId } from "@t3tools/contracts";
|
||||
import { memo } from "react";
|
||||
import { StarIcon } from "lucide-react";
|
||||
import { CheckIcon, StarIcon } from "lucide-react";
|
||||
import {
|
||||
getDisplayModelName,
|
||||
getTriggerDisplayModelLabel,
|
||||
@@ -31,6 +31,7 @@ export const ModelListRow = memo(function ModelListRow(props: {
|
||||
providerAccentColor?: string | undefined;
|
||||
isFavorite: boolean;
|
||||
isSelected: boolean;
|
||||
showSelection?: boolean;
|
||||
showProvider: boolean;
|
||||
preferShortName?: boolean;
|
||||
useTriggerLabel?: boolean;
|
||||
@@ -94,6 +95,9 @@ export const ModelListRow = memo(function ModelListRow(props: {
|
||||
</div>
|
||||
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
{props.showSelection && props.isSelected ? (
|
||||
<CheckIcon className="size-3.5" aria-hidden="true" />
|
||||
) : null}
|
||||
{props.jumpLabel ? (
|
||||
<Kbd className="h-4 min-w-0 rounded-sm px-1.5 text-[10px]">{props.jumpLabel}</Kbd>
|
||||
) : null}
|
||||
|
||||
@@ -151,6 +151,8 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
/** The instance currently selected in the composer (combobox "value"). */
|
||||
activeInstanceId: ProviderInstanceId;
|
||||
model: string;
|
||||
selectedModels?: ReadonlyArray<{ instanceId: ProviderInstanceId; model: string }>;
|
||||
onToggleModel?: (instanceId: ProviderInstanceId, model: string) => void;
|
||||
/**
|
||||
* When set, the picker is locked to the given driver kind — typically
|
||||
* because the user is editing a previously-sent message and can't change
|
||||
@@ -186,6 +188,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
instanceEntries,
|
||||
getModelDisabledReason,
|
||||
onInstanceModelChange,
|
||||
onToggleModel,
|
||||
} = props;
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [showTopScrollFade, setShowTopScrollFade] = useState(false);
|
||||
@@ -207,6 +210,23 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
const activeModelKey = activeModelSlug
|
||||
? modelPickerModelKey(props.activeInstanceId, activeModelSlug)
|
||||
: null;
|
||||
const selectedModelKeys = useMemo(
|
||||
() =>
|
||||
props.selectedModels?.map((selection) => {
|
||||
const entry = instanceEntries.find((entry) => entry.instanceId === selection.instanceId);
|
||||
const model = resolveModelPickerSelectedModel({
|
||||
driverKind: entry?.driverKind,
|
||||
model: selection.model,
|
||||
options: modelOptionsByInstance.get(selection.instanceId) ?? [],
|
||||
});
|
||||
return modelPickerModelKey(selection.instanceId, model?.slug ?? selection.model);
|
||||
}),
|
||||
[instanceEntries, modelOptionsByInstance, props.selectedModels],
|
||||
);
|
||||
const selectedModelKeySet = useMemo(
|
||||
() => new Set(selectedModelKeys ?? (activeModelKey ? [activeModelKey] : [])),
|
||||
[selectedModelKeys, activeModelKey],
|
||||
);
|
||||
const activeInstanceHasSelectableUnavailableModel =
|
||||
activeEntry !== undefined &&
|
||||
(modelOptionsByInstance.get(props.activeInstanceId) ?? []).some((option) =>
|
||||
@@ -575,7 +595,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
}, []);
|
||||
|
||||
const handleModelSelect = useCallback(
|
||||
(modelSlug: string, instanceId: ProviderInstanceId) => {
|
||||
(modelSlug: string, instanceId: ProviderInstanceId, additive = false) => {
|
||||
if (getModelDisabledReason?.(instanceId, modelSlug)) {
|
||||
return;
|
||||
}
|
||||
@@ -592,10 +612,20 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
// normalization rules, so pass the driver kind here.
|
||||
const resolvedModel = resolveSelectableModel(entry.driverKind, modelSlug, options);
|
||||
if (resolvedModel) {
|
||||
onInstanceModelChange(instanceId, resolvedModel);
|
||||
if (additive && onToggleModel) {
|
||||
onToggleModel(instanceId, resolvedModel);
|
||||
} else {
|
||||
onInstanceModelChange(instanceId, resolvedModel);
|
||||
}
|
||||
}
|
||||
},
|
||||
[entryByInstanceId, getModelDisabledReason, modelOptionsByInstance, onInstanceModelChange],
|
||||
[
|
||||
entryByInstanceId,
|
||||
getModelDisabledReason,
|
||||
modelOptionsByInstance,
|
||||
onInstanceModelChange,
|
||||
onToggleModel,
|
||||
],
|
||||
);
|
||||
|
||||
const toggleFavorite = useCallback(
|
||||
@@ -701,8 +731,8 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
return mapping.size > 0 ? mapping : EMPTY_MODEL_JUMP_LABELS;
|
||||
}, [keybindings, modelJumpCommandByKey, modelJumpShortcutContext]);
|
||||
const modelListExtraData = useMemo(
|
||||
() => ({ favoritesSet, modelJumpLabelByKey }),
|
||||
[favoritesSet, modelJumpLabelByKey],
|
||||
() => ({ favoritesSet, modelJumpLabelByKey, activeModelKey, selectedModelKeySet }),
|
||||
[favoritesSet, modelJumpLabelByKey, activeModelKey, selectedModelKeySet],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -804,7 +834,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
)}
|
||||
|
||||
{/* Main content area */}
|
||||
<Combobox
|
||||
<Combobox<string, boolean>
|
||||
inline
|
||||
items={allItemKeys}
|
||||
filteredItems={filteredItemKeys}
|
||||
@@ -812,7 +842,8 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
autoHighlight
|
||||
open
|
||||
virtualized
|
||||
value={activeModelKey}
|
||||
multiple={onToggleModel !== undefined}
|
||||
value={onToggleModel ? [...selectedModelKeySet] : activeModelKey}
|
||||
onItemHighlighted={(modelKey, eventDetails) => {
|
||||
highlightedModelKeyRef.current = typeof modelKey === "string" ? modelKey : null;
|
||||
if (eventDetails.reason === "keyboard" && eventDetails.index >= 0) {
|
||||
@@ -822,7 +853,11 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
});
|
||||
}
|
||||
}}
|
||||
onValueChange={(modelKey) => {
|
||||
onValueChange={(value, details) => {
|
||||
const modelKey = Array.isArray(value)
|
||||
? (value.find((key) => !selectedModelKeySet.has(key)) ??
|
||||
[...selectedModelKeySet].find((key) => !value.includes(key)))
|
||||
: value;
|
||||
if (typeof modelKey !== "string") {
|
||||
return;
|
||||
}
|
||||
@@ -833,7 +868,11 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
}
|
||||
const model = parseModelPickerModelKey(modelKey);
|
||||
if (model) {
|
||||
handleModelSelect(model.slug, model.instanceId);
|
||||
handleModelSelect(
|
||||
model.slug,
|
||||
model.instanceId,
|
||||
"shiftKey" in details.event && details.event.shiftKey === true,
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -901,7 +940,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
}
|
||||
const model = parseModelPickerModelKey(highlightedModelKeyRef.current);
|
||||
if (model) {
|
||||
handleModelSelect(model.slug, model.instanceId);
|
||||
handleModelSelect(model.slug, model.instanceId, e.shiftKey);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -967,7 +1006,12 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
isFavorite={favoritesSet.has(
|
||||
providerModelKey(model.instanceId, model.slug),
|
||||
)}
|
||||
isSelected={modelKey === activeModelKey}
|
||||
isSelected={
|
||||
selectedModelKeys !== undefined
|
||||
? selectedModelKeySet.has(modelKey)
|
||||
: modelKey === activeModelKey
|
||||
}
|
||||
showSelection={selectedModelKeys !== undefined}
|
||||
showProvider
|
||||
preferShortName={!isLocked}
|
||||
useTriggerLabel={false}
|
||||
|
||||
@@ -34,6 +34,8 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
*/
|
||||
activeInstanceId: ProviderInstanceId;
|
||||
model: string;
|
||||
selectedModels?: ReadonlyArray<{ instanceId: ProviderInstanceId; model: string }>;
|
||||
onToggleModel?: (instanceId: ProviderInstanceId, model: string) => void;
|
||||
lockedProvider: ProviderDriverKind | null;
|
||||
lockedContinuationGroupKey?: string | null;
|
||||
/** Instance entries rendered in the sidebar + used to resolve display name. */
|
||||
@@ -158,9 +160,37 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
const shortcutLabel = props.keybindings
|
||||
? shortcutLabelForCommand(props.keybindings, "modelPicker.toggle")
|
||||
: null;
|
||||
const selectedEntries = props.selectedModels?.map((selection) => {
|
||||
const entry = props.instanceEntries.find(
|
||||
(candidate) => candidate.instanceId === selection.instanceId,
|
||||
);
|
||||
const model = resolveModelPickerSelectedModel({
|
||||
driverKind: entry?.driverKind,
|
||||
model: selection.model,
|
||||
options: props.modelOptionsByInstance.get(selection.instanceId) ?? [],
|
||||
});
|
||||
return {
|
||||
...selection,
|
||||
entry,
|
||||
label: model
|
||||
? `${getTriggerDisplayModelName(model)}${model.isUnavailable ? " (Unavailable)" : ""}`
|
||||
: selection.model,
|
||||
};
|
||||
});
|
||||
const multipleLabel = selectedEntries
|
||||
? selectedEntries.length === 0
|
||||
? "Choose models"
|
||||
: `${selectedEntries
|
||||
.slice(0, 2)
|
||||
.map((selection) => selection.label)
|
||||
.join(", ")}${selectedEntries.length > 2 ? `, ${selectedEntries.length - 2} more` : ""}`
|
||||
: undefined;
|
||||
const allModelNames = selectedEntries
|
||||
? selectedEntries.map((selection) => selection.label).join(", ") || "Choose models"
|
||||
: undefined;
|
||||
const triggerTooltipContent = shortcutLabel
|
||||
? `${props.triggerLabel ?? triggerLabel} · ${shortcutLabel}`
|
||||
: (props.triggerLabel ?? triggerLabel);
|
||||
? `${props.triggerLabel ?? allModelNames ?? triggerLabel} · ${shortcutLabel}`
|
||||
: (props.triggerLabel ?? allModelNames ?? triggerLabel);
|
||||
|
||||
return (
|
||||
<Popover
|
||||
@@ -176,7 +206,7 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<PopoverTrigger
|
||||
render={
|
||||
<ComposerControl
|
||||
aria-label={props.triggerAriaLabel}
|
||||
aria-label={props.triggerAriaLabel ?? allModelNames}
|
||||
variant={props.triggerVariant ?? "ghost"}
|
||||
size={size}
|
||||
data-chat-provider-model-picker="true"
|
||||
@@ -192,7 +222,29 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<span
|
||||
className={cn("flex min-w-0 flex-1 items-center", size === "xs" ? "gap-1" : "gap-1.5")}
|
||||
>
|
||||
{activeEntry && props.triggerLabel === undefined ? (
|
||||
{selectedEntries && props.triggerLabel === undefined ? (
|
||||
<span className="flex shrink-0 items-center -space-x-1" aria-hidden="true">
|
||||
{selectedEntries
|
||||
.slice(0, 3)
|
||||
.map((selection) =>
|
||||
selection.entry ? (
|
||||
<ProviderInstanceIcon
|
||||
key={`${selection.instanceId}:${selection.model}`}
|
||||
driverKind={selection.entry.driverKind}
|
||||
displayName={selection.entry.displayName}
|
||||
accentColor={selection.entry.accentColor}
|
||||
className="size-4 rounded-full bg-[var(--chat-composer-glass-surface,var(--background))] ring-2 ring-[var(--chat-composer-glass-surface,var(--background))]"
|
||||
iconClassName="size-4"
|
||||
/>
|
||||
) : null,
|
||||
)}
|
||||
{selectedEntries.length > 3 ? (
|
||||
<span className="relative z-30 flex size-4 items-center justify-center rounded-full bg-[var(--chat-composer-glass-surface,var(--background))] text-[9px] ring-2 ring-[var(--chat-composer-glass-surface,var(--background))]">
|
||||
+{selectedEntries.length - 3}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
) : activeEntry && props.triggerLabel === undefined ? (
|
||||
<ProviderInstanceIcon
|
||||
driverKind={activeEntry.driverKind}
|
||||
displayName={activeEntry.displayName}
|
||||
@@ -216,11 +268,11 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
/>
|
||||
}
|
||||
>
|
||||
{props.triggerLabel ?? triggerTitle}
|
||||
{props.triggerLabel ?? multipleLabel ?? triggerTitle}
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{triggerTooltipContent}</TooltipPopup>
|
||||
</Tooltip>
|
||||
{selectedModel?.isUnavailable && props.triggerLabel === undefined ? (
|
||||
{selectedModel?.isUnavailable && !selectedEntries && props.triggerLabel === undefined ? (
|
||||
<Badge variant="outline" size="sm">
|
||||
Unavailable
|
||||
</Badge>
|
||||
@@ -239,6 +291,14 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<ModelPickerContent
|
||||
activeInstanceId={activeInstanceId}
|
||||
model={props.model}
|
||||
{...(props.selectedModels !== undefined ? { selectedModels: props.selectedModels } : {})}
|
||||
{...(props.onToggleModel
|
||||
? {
|
||||
onToggleModel: (instanceId: ProviderInstanceId, model: string) => {
|
||||
if (!props.disabled) props.onToggleModel?.(instanceId, model);
|
||||
},
|
||||
}
|
||||
: {})}
|
||||
lockedProvider={props.lockedProvider}
|
||||
lockedContinuationGroupKey={props.lockedContinuationGroupKey ?? null}
|
||||
instanceEntries={props.instanceEntries}
|
||||
|
||||
@@ -20,6 +20,11 @@ on Windows and Linux to start a new thread and immediately open another draft. T
|
||||
next draft keeps the workspace mode and base branch you selected. With **New
|
||||
worktree**, each background submission creates its own worktree.
|
||||
|
||||
To send the same prompt to several models on web or desktop, **Shift-click** models
|
||||
in a new thread's model picker to add or remove them. A regular click returns to a
|
||||
single model. Choose a base branch and send. Each selection starts a separate thread
|
||||
and worktree while you stay in the new thread composer. This requires a Git project.
|
||||
|
||||
## Pin and reorder threads
|
||||
|
||||
Pin a thread from its menu to keep it above your active work.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { OrchestrationDispatchCommandError } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { wasBootstrapThreadDeleted } from "./orchestration.ts";
|
||||
import { wasBootstrapThreadDeleted, wasBootstrapThreadNotCreated } from "./orchestration.ts";
|
||||
|
||||
describe("wasBootstrapThreadDeleted", () => {
|
||||
it("accepts only a confirmed deleted bootstrap thread", () => {
|
||||
@@ -21,3 +21,30 @@ describe("wasBootstrapThreadDeleted", () => {
|
||||
expect(wasBootstrapThreadDeleted(new Error("connection lost"))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("wasBootstrapThreadNotCreated", () => {
|
||||
it("accepts only a confirmed never-created bootstrap thread", () => {
|
||||
const notCreated = new OrchestrationDispatchCommandError({
|
||||
message: "A separate worktree requires a base commit.",
|
||||
bootstrapThreadDisposition: "not-created",
|
||||
});
|
||||
expect(wasBootstrapThreadNotCreated(notCreated)).toBe(true);
|
||||
expect(wasBootstrapThreadDeleted(notCreated)).toBe(false);
|
||||
expect(
|
||||
wasBootstrapThreadNotCreated(
|
||||
new OrchestrationDispatchCommandError({
|
||||
message: "Failed to create worktree.",
|
||||
bootstrapThreadDisposition: "deleted",
|
||||
}),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
wasBootstrapThreadNotCreated(
|
||||
new OrchestrationDispatchCommandError({
|
||||
message: "Failed to create worktree.",
|
||||
}),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(wasBootstrapThreadNotCreated(new Error("connection lost"))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -8,3 +8,9 @@ export function wasBootstrapThreadDeleted(error: unknown): boolean {
|
||||
isOrchestrationDispatchCommandError(error) && error.bootstrapThreadDisposition === "deleted"
|
||||
);
|
||||
}
|
||||
|
||||
export function wasBootstrapThreadNotCreated(error: unknown): boolean {
|
||||
return (
|
||||
isOrchestrationDispatchCommandError(error) && error.bootstrapThreadDisposition === "not-created"
|
||||
);
|
||||
}
|
||||
@@ -14,6 +14,16 @@ const descriptor = {
|
||||
} as const;
|
||||
|
||||
describe("ExecutionEnvironmentDescriptor", () => {
|
||||
it("requires an advertised required-worktree bootstrap capability", () => {
|
||||
expect(decodeDescriptor(descriptor).capabilities.requiredWorktreeBootstrap).toBeUndefined();
|
||||
expect(
|
||||
decodeDescriptor({
|
||||
...descriptor,
|
||||
capabilities: { ...descriptor.capabilities, requiredWorktreeBootstrap: true },
|
||||
}).capabilities.requiredWorktreeBootstrap,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("treats a missing pull-request capability as unsupported under version skew", () => {
|
||||
expect(decodeDescriptor(descriptor).capabilities.pullRequests).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -99,6 +99,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
|
||||
Absent on servers from before inline context shipped, which drop the records and forward
|
||||
the links as literal text -- so a client must serialize context the legacy way for them. */
|
||||
inlineMessageContext: Schema.optionalKey(Schema.Boolean),
|
||||
/** Server rejects required worktrees instead of falling back to the project checkout. */
|
||||
requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
|
||||
/** Server understands thread.settle / thread.unsettle commands. Absent on
|
||||
pre-settlement servers, so clients treat missing as unsupported and
|
||||
never send the commands under version skew. */
|
||||
|
||||
@@ -84,6 +84,18 @@ it.effect("decodes a dispatch error after its bootstrap thread was deleted", ()
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes a dispatch error before its bootstrap thread was created", () =>
|
||||
Effect.gen(function* () {
|
||||
const error = yield* decodeDispatchCommandError({
|
||||
_tag: "OrchestrationDispatchCommandError",
|
||||
message: "A separate worktree requires a base commit.",
|
||||
bootstrapThreadDisposition: "not-created",
|
||||
});
|
||||
|
||||
assert.strictEqual(error.bootstrapThreadDisposition, "not-created");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeTurnDiffInput({
|
||||
@@ -545,6 +557,7 @@ it.effect("accepts bootstrap metadata in thread.turn.start", () =>
|
||||
baseBranch: "main",
|
||||
branch: "t3code/example",
|
||||
startFromOrigin: true,
|
||||
requireWorktree: true,
|
||||
},
|
||||
runSetupScript: true,
|
||||
},
|
||||
@@ -553,6 +566,7 @@ it.effect("accepts bootstrap metadata in thread.turn.start", () =>
|
||||
assert.strictEqual(parsed.bootstrap?.createThread?.projectId, "project-1");
|
||||
assert.strictEqual(parsed.bootstrap?.prepareWorktree?.baseBranch, "main");
|
||||
assert.strictEqual(parsed.bootstrap?.prepareWorktree?.startFromOrigin, true);
|
||||
assert.strictEqual(parsed.bootstrap?.prepareWorktree?.requireWorktree, true);
|
||||
assert.strictEqual(parsed.bootstrap?.runSetupScript, true);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1271,6 +1271,7 @@ const ThreadTurnStartBootstrapPrepareWorktree = Schema.Struct({
|
||||
baseBranch: TrimmedNonEmptyString,
|
||||
branch: Schema.optional(TrimmedNonEmptyString),
|
||||
startFromOrigin: Schema.optional(Schema.Boolean),
|
||||
requireWorktree: Schema.optional(Schema.Boolean),
|
||||
});
|
||||
|
||||
const ThreadTurnStartBootstrap = Schema.Struct({
|
||||
@@ -2381,7 +2382,7 @@ export class OrchestrationDispatchCommandError extends Schema.TaggedError<Orches
|
||||
{
|
||||
message: TrimmedNonEmptyString,
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
bootstrapThreadDisposition: Schema.optional(Schema.Literal("deleted")),
|
||||
bootstrapThreadDisposition: Schema.optional(Schema.Literals(["deleted", "not-created"])),
|
||||
},
|
||||
) {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user