Skip to content
Merged
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
114 changes: 4 additions & 110 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useProjectCloneBanner } from "./chat/useProjectCloneBanner";
import { useAttachmentPreviewHandoff } from "./chat/useAttachmentPreviewHandoff";
import { useTimelineRewind } from "./chat/useTimelineRewind";
import { useThreadLifecycle } from "./chat/useThreadLifecycle";
Expand Down Expand Up @@ -176,7 +177,7 @@ import { makeWorkspaceFileDropHandlers } from "./chat/workspaceFileDrop";
import { isEditableFocused } from "../lib/editableFocus";
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
import { shortcutLabelForCommand } from "../keybindings";
import { PaperclipIcon, ChevronDownIcon, DownloadIcon } from "lucide-react";
import { PaperclipIcon, ChevronDownIcon } from "lucide-react";
import { cn } from "~/lib/utils";
import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
import { stackedThreadToast, toastManager } from "./ui/toast";
Expand All @@ -198,7 +199,6 @@ import {
import { useNowMinute } from "../hooks/useNowMinute";
import { usePanelAnimationSettings, usePanelPresence } from "../panelAnimations";
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
import { useRemoveClonedProject } from "../hooks/useRemoveClonedProject";
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
import { resolveAppModelSelectionForInstance } from "../modelSelection";
import { isPreviewFocused } from "../lib/previewFocus";
Expand Down Expand Up @@ -235,10 +235,6 @@ import {
import { threadEnvironment } from "../state/threads";
import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills";
import { vcsEnvironment } from "../state/vcs";
import { sourceControlEnvironment } from "../state/sourceControl";
import { useProjectClone } from "../state/projectClones";
import { projectCloneDisplayName, projectCloneProgressSummary } from "@t3tools/contracts";
import { dismissProjectFileCopy, useProjectFileCopy } from "../lib/addProjectToMachine";
import {
type EnvironmentPresentation,
useEnvironmentProviders,
Expand Down Expand Up @@ -1117,110 +1113,8 @@ export default function ChatView(props: ChatViewProps) {
activeProject ?? undefined,
);
const activeProjectScripts = activeProject ? resolveProjectScripts(settings, activeProject) : [];
const activeProjectClone = useProjectClone(activeProjectRef);
const cancelProjectClone = useAtomCommand(sourceControlEnvironment.cancelProjectClone, {
reportFailure: false,
});
const retryProjectClone = useAtomCommand(sourceControlEnvironment.retryProjectClone, {
reportFailure: false,
});
const removeClonedProject = useRemoveClonedProject();
const runProjectCloneAction = async (
title: string,
action: () => Promise<AtomCommandResult<unknown, unknown>>,
): Promise<void> => {
const result = await action();
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
const error = squashAtomCommandFailure(result);
toastManager.add(
stackedThreadToast({
type: "error",
title,
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
}
};
const runProjectCloneActionStable = useStableCallback(runProjectCloneAction);
const activeProjectFileCopy = useProjectFileCopy(activeProjectRef);
const projectCloneSendBlockReason =
activeProjectClone?.phase === "running"
? "Cloning repository"
: activeProjectClone !== null && activeProjectClone.phase !== "done"
? "Repository not cloned"
: activeProjectFileCopy?.phase === "copying"
? "Copying files"
: null;
const projectCloneBannerItem = (() => {
if (activeProjectFileCopy?.phase === "failed" && activeProjectRef) {
return {
id: `project-file-copy:${activeProjectRef.projectId}`,
variant: "error",
icon: <DownloadIcon />,
title: activeProjectFileCopy.title,
description: activeProjectFileCopy.failures.join("\n"),
onDismiss: () => dismissProjectFileCopy(activeProjectRef),
};
}
if (!activeProjectClone || !activeProjectRef || activeProjectClone.phase === "done") {
return null;
}
const name = projectCloneDisplayName(activeProjectClone);
const { environmentId, projectId } = activeProjectRef;
if (activeProjectClone.phase === "running") {
return {
id: `project-clone:${projectId}`,
variant: "info",
priority: "activity",
icon: <DownloadIcon />,
title: `Cloning ${name}`,
description: projectCloneProgressSummary(activeProjectClone),
actions: (
<Button
size="xs"
variant="ghost"
onClick={() =>
void runProjectCloneActionStable("Failed to cancel clone", () =>
cancelProjectClone({ environmentId, input: { projectId } }),
)
}
>
Cancel
</Button>
),
};
}
const cancelled = activeProjectClone.phase === "cancelled";
return {
id: `project-clone:${projectId}`,
variant: cancelled ? "warning" : "error",
icon: <DownloadIcon />,
title: cancelled ? `Cancelled cloning ${name}` : `Failed to clone ${name}`,
description: cancelled ? "Retry to bring in the repository." : activeProjectClone.error,
actions: (
<>
<Button
size="xs"
variant="ghost"
onClick={() => void removeClonedProject({ environmentId, projectId })}
>
Remove project
</Button>
<Button
size="xs"
variant="ghost"
onClick={() =>
void runProjectCloneActionStable("Failed to retry clone", () =>
retryProjectClone({ environmentId, input: { projectId } }),
)
}
>
Retry
</Button>
</>
),
};
})() as ComposerBannerStackItem | null;
const { projectCloneBannerItem, projectCloneSendBlockReason } =
useProjectCloneBanner(activeProjectRef);
const activeProjectDefaultModelSelection = activeProjectSettings.settings.defaultModelSelection;
const handleNewThreadInActiveProject = () => {
startNewThreadForProject(activeProjectRef, handleNewThread);
Expand Down
134 changes: 134 additions & 0 deletions apps/web/src/components/chat/useProjectCloneBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { useStableCallback } from "../../hooks/useStableCallback";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
type AtomCommandResult,
} from "@t3tools/client-runtime/state/runtime";
import { DownloadIcon } from "lucide-react";
import { stackedThreadToast, toastManager } from "../ui/toast";
import { useRemoveClonedProject } from "../../hooks/useRemoveClonedProject";
import { sourceControlEnvironment } from "../../state/sourceControl";
import { useProjectClone } from "../../state/projectClones";
import {
projectCloneDisplayName,
projectCloneProgressSummary,
type ScopedProjectRef,
} from "@t3tools/contracts";
import { dismissProjectFileCopy, useProjectFileCopy } from "../../lib/addProjectToMachine";
import { type ComposerBannerStackItem } from "./ComposerBannerStack";
import { useAtomCommand } from "../../state/use-atom-command";
import { Button } from "../ui/button";
/**
* A project still being cloned or copied into place: the composer banner with its cancel,
* retry, and remove actions, and the reason sending waits until it is done.
*/
export function useProjectCloneBanner(activeProjectRef: ScopedProjectRef | null) {
const activeProjectClone = useProjectClone(activeProjectRef);
const cancelProjectClone = useAtomCommand(sourceControlEnvironment.cancelProjectClone, {
reportFailure: false,
});
const retryProjectClone = useAtomCommand(sourceControlEnvironment.retryProjectClone, {
reportFailure: false,
});
const removeClonedProject = useRemoveClonedProject();
const runProjectCloneAction = async (
title: string,
action: () => Promise<AtomCommandResult<unknown, unknown>>,
): Promise<void> => {
const result = await action();
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
const error = squashAtomCommandFailure(result);
toastManager.add(
stackedThreadToast({
type: "error",
title,
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
}
};
const runProjectCloneActionStable = useStableCallback(runProjectCloneAction);
const activeProjectFileCopy = useProjectFileCopy(activeProjectRef);
const projectCloneSendBlockReason =
activeProjectClone?.phase === "running"
? "Cloning repository"
: activeProjectClone !== null && activeProjectClone.phase !== "done"
? "Repository not cloned"
: activeProjectFileCopy?.phase === "copying"
? "Copying files"
: null;
const projectCloneBannerItem = (() => {
if (activeProjectFileCopy?.phase === "failed" && activeProjectRef) {
return {
id: `project-file-copy:${activeProjectRef.projectId}`,
variant: "error",
icon: <DownloadIcon />,
title: activeProjectFileCopy.title,
description: activeProjectFileCopy.failures.join("\n"),
onDismiss: () => dismissProjectFileCopy(activeProjectRef),
};
}
if (!activeProjectClone || !activeProjectRef || activeProjectClone.phase === "done") {
return null;
}
const name = projectCloneDisplayName(activeProjectClone);
const { environmentId, projectId } = activeProjectRef;
if (activeProjectClone.phase === "running") {
return {
id: `project-clone:${projectId}`,
variant: "info",
priority: "activity",
icon: <DownloadIcon />,
title: `Cloning ${name}`,
description: projectCloneProgressSummary(activeProjectClone),
actions: (
<Button
size="xs"
variant="ghost"
onClick={() =>
void runProjectCloneActionStable("Failed to cancel clone", () =>
cancelProjectClone({ environmentId, input: { projectId } }),
)
}
>
Cancel
</Button>
),
};
}
const cancelled = activeProjectClone.phase === "cancelled";
return {
id: `project-clone:${projectId}`,
variant: cancelled ? "warning" : "error",
icon: <DownloadIcon />,
title: cancelled ? `Cancelled cloning ${name}` : `Failed to clone ${name}`,
description: cancelled ? "Retry to bring in the repository." : activeProjectClone.error,
actions: (
<>
<Button
size="xs"
variant="ghost"
onClick={() => void removeClonedProject({ environmentId, projectId })}
>
Remove project
</Button>
<Button
size="xs"
variant="ghost"
onClick={() =>
void runProjectCloneActionStable("Failed to retry clone", () =>
retryProjectClone({ environmentId, input: { projectId } }),
)
}
>
Retry
</Button>
</>
),
};
})() as ComposerBannerStackItem | null;
return {
projectCloneBannerItem,
projectCloneSendBlockReason,
};
}
Loading