Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/web/src/components/BranchToolbar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
EnvironmentId,
EnvironmentMachineKind,
VcsRef,
ProjectId,
WorktreeSubmodules,
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
Expand All @@ -16,7 +15,6 @@ export {

export interface EnvironmentOption {
environmentId: EnvironmentId;
projectId: ProjectId;
label: string;
isPrimary: boolean;
machine: EnvironmentMachineKind;
Expand Down
97 changes: 80 additions & 17 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ import {
import { useNowMinute } from "../hooks/useNowMinute";
import { usePanelAnimationSettings, usePanelPresence } from "../panelAnimations";
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
import { useScratchProject } from "../hooks/useScratchProject";
import { isScratchProject } from "@t3tools/client-runtime/state/projects";
import { useRemoveClonedProject } from "../hooks/useRemoveClonedProject";
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
import { resolveAppModelSelectionForInstance } from "../modelSelection";
Expand Down Expand Up @@ -2649,7 +2651,7 @@ export default function ChatView(props: ChatViewProps) {
(p) => deriveLogicalProjectKeyFromSettings(p, projectGroupingSettings) === logicalKey,
);
const seen = new Set<string>();
const envs: EnvironmentOption[] = [];
const envs: (EnvironmentOption & { projectId: ProjectId })[] = [];
for (const p of memberProjects) {
if (seen.has(p.environmentId)) continue;
seen.add(p.environmentId);
Expand All @@ -2670,9 +2672,39 @@ export default function ChatView(props: ChatViewProps) {
});
return envs;
}, [activeProject, allProjects, projectGroupingSettings, primaryEnvironmentId, environmentById]);
const hasMultipleEnvironments = logicalProjectEnvironments.length > 1;
const { scratchWorkspaceRootFor, moveScratchDraft, isMovingScratchDraft } =
useScratchProject(draftId);
const isScratchDraft =
activeProject !== null &&
isScratchProject(activeProject, activeEnvironment?.serverConfig?.scratchWorkspaceRoot);
const availableEnvironments = useMemo(() => {
if (!isScratchDraft) return logicalProjectEnvironments;
return environments
.filter(
(environment) =>
environment.environmentId === activeProject?.environmentId ||
scratchWorkspaceRootFor(environment.environmentId) !== null,
)
.map((environment) => ({
environmentId: environment.environmentId,
label: environment.label,
isPrimary: environment.environmentId === primaryEnvironmentId,
machine: resolveEnvironmentMachineKind(environment.serverConfig),
}))
.sort((a, b) =>
a.isPrimary !== b.isPrimary ? (a.isPrimary ? -1 : 1) : a.label.localeCompare(b.label),
);
}, [
isScratchDraft,
logicalProjectEnvironments,
environments,
scratchWorkspaceRootFor,
primaryEnvironmentId,
activeProject?.environmentId,
]);
const hasMultipleEnvironments = availableEnvironments.length > 1;
const activeEnvironmentOption =
logicalProjectEnvironments.find(
availableEnvironments.find(
(environment) => environment.environmentId === activeThread?.environmentId,
) ?? null;
const showComposerEnvironmentIndicator = shouldShowEnvironmentIndicator({
Expand Down Expand Up @@ -2889,6 +2921,7 @@ export default function ChatView(props: ChatViewProps) {
clientSettingsHydrated &&
draftId &&
!envLocked &&
!isScratchDraft &&
hasMultipleEnvironments &&
loadBalancingSettings.loadBalancingEnabled &&
draftThread?.environmentSelection !== "manual" &&
Expand Down Expand Up @@ -4249,7 +4282,20 @@ export default function ChatView(props: ChatViewProps) {
// project in that environment while keeping the same logical project.
const onEnvironmentChange = useCallback(
(nextEnvironmentId: EnvironmentId) => {
if (envLocked || !draftId) return;
if (envLocked || !draftId || sendInFlightRef.current) return;
if (isScratchDraft) {
if (composerHasAttachments) {
toastManager.add({
type: "warning",
title: "Keep attachments on this machine",
description:
"Remove attachments before choosing another machine, then attach them there.",
});
return;
}
void moveScratchDraft(nextEnvironmentId);
return;
}
const target = logicalProjectEnvironments.find(
(env) => env.environmentId === nextEnvironmentId,
);
Expand All @@ -4260,7 +4306,16 @@ export default function ChatView(props: ChatViewProps) {
loadBalancedEnvironmentId: null,
});
},
[draftId, envLocked, logicalProjectEnvironments, setDraftThreadContext],
[
draftId,
envLocked,
isScratchDraft,
composerHasAttachments,
moveScratchDraft,
logicalProjectEnvironments,
setDraftThreadContext,
sendInFlightRef,
],
);

const activeTerminalGroup =
Expand Down Expand Up @@ -8127,6 +8182,7 @@ export default function ChatView(props: ChatViewProps) {
if (
!activeThread ||
isSendBusy ||
isMovingScratchDraft ||
isConnecting ||
isRevertingCheckpoint ||
!clientSettingsHydrated ||
Expand Down Expand Up @@ -10436,10 +10492,14 @@ export default function ChatView(props: ChatViewProps) {
gitCwd,
isGitRepo,
envLocked,
availableEnvironments: logicalProjectEnvironments,
availableEnvironments,
autoEnvironmentLabel,
onAutoEnvironment:
draftId && !envLocked && hasMultipleEnvironments && loadBalancingSettings.loadBalancingEnabled
draftId &&
!envLocked &&
!isScratchDraft &&
hasMultipleEnvironments &&
loadBalancingSettings.loadBalancingEnabled
? onAutoEnvironment
: undefined,
onEnvironmentChange,
Expand Down Expand Up @@ -10896,15 +10956,17 @@ export default function ChatView(props: ChatViewProps) {
canResume={resumableRunId !== null || hasHeldQueuedRuns}
isRevertingCheckpoint={isRevertingCheckpoint}
sendDisabledReason={
isRevertingCheckpoint
? "Rewinding conversation"
: feedbackUploading
? "Sending feedback"
: threadDetailLoading
? "Messages loading"
: worktreeSetupBlocksSend
? "Preparing worktree"
: projectCloneSendBlockReason
isMovingScratchDraft
? "Switching machine"
: isRevertingCheckpoint
? "Rewinding conversation"
: feedbackUploading
? "Sending feedback"
: threadDetailLoading
? "Messages loading"
: worktreeSetupBlocksSend
? "Preparing worktree"
: projectCloneSendBlockReason
}
isPreparingWorktree={isPreparingWorktree}
queuedRunsControl={
Expand Down Expand Up @@ -11085,12 +11147,13 @@ export default function ChatView(props: ChatViewProps) {
onAutoEnvironment={
draftId &&
!envLocked &&
!isScratchDraft &&
hasMultipleEnvironments &&
loadBalancingSettings.loadBalancingEnabled
? onAutoEnvironment
: undefined
}
availableEnvironments={logicalProjectEnvironments}
availableEnvironments={availableEnvironments}
composerControlsHostRef={setRestingComposerControlsHost}
contextStripVisible={showComposerContextStrip}
/>
Expand Down
Loading
Loading