支持在历史会话中分叉出新会话
This commit is contained in:
@@ -41,6 +41,7 @@ interface ChatInputProps {
|
||||
isEditingQueueItem?: boolean
|
||||
onSaveQueueEdit?: (draft: PromptDraft) => void
|
||||
onCancelQueueEdit?: () => void
|
||||
onForkSend?: (draft: PromptDraft, modeId?: string | null) => void
|
||||
}
|
||||
|
||||
export function ChatInput({
|
||||
@@ -71,6 +72,7 @@ export function ChatInput({
|
||||
isEditingQueueItem,
|
||||
onSaveQueueEdit,
|
||||
onCancelQueueEdit,
|
||||
onForkSend,
|
||||
}: ChatInputProps) {
|
||||
const t = useTranslations("Folder.chat.chatInput")
|
||||
const isConnected = status === "connected"
|
||||
@@ -116,6 +118,7 @@ export function ChatInput({
|
||||
isEditingQueueItem={isEditingQueueItem}
|
||||
onSaveQueueEdit={onSaveQueueEdit}
|
||||
onCancelQueueEdit={onCancelQueueEdit}
|
||||
onForkSend={onForkSend}
|
||||
placeholder={
|
||||
isConnecting
|
||||
? t("connecting")
|
||||
|
||||
@@ -51,6 +51,7 @@ interface ConversationShellProps {
|
||||
isEditingQueueItem?: boolean
|
||||
onSaveQueueEdit?: (draft: PromptDraft) => void
|
||||
onCancelQueueEdit?: () => void
|
||||
onForkSend?: (draft: PromptDraft, modeId?: string | null) => void
|
||||
}
|
||||
|
||||
export function ConversationShell({
|
||||
@@ -88,6 +89,7 @@ export function ConversationShell({
|
||||
isEditingQueueItem,
|
||||
onSaveQueueEdit,
|
||||
onCancelQueueEdit,
|
||||
onForkSend,
|
||||
}: ConversationShellProps) {
|
||||
return (
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
@@ -129,6 +131,7 @@ export function ConversationShell({
|
||||
isEditingQueueItem={isEditingQueueItem}
|
||||
onSaveQueueEdit={onSaveQueueEdit}
|
||||
onCancelQueueEdit={onCancelQueueEdit}
|
||||
onForkSend={onForkSend}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -15,14 +15,22 @@ import {
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import {
|
||||
Check,
|
||||
ChevronUp,
|
||||
Ellipsis,
|
||||
FileSearch,
|
||||
GitFork,
|
||||
ListPlus,
|
||||
Plus,
|
||||
Send,
|
||||
Square,
|
||||
X,
|
||||
} from "lucide-react"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { matchShortcutEvent } from "@/lib/keyboard-shortcuts"
|
||||
import { useShortcutSettings } from "@/hooks/use-shortcut-settings"
|
||||
@@ -76,6 +84,7 @@ interface MessageInputProps {
|
||||
isEditingQueueItem?: boolean
|
||||
onSaveQueueEdit?: (draft: PromptDraft) => void
|
||||
onCancelQueueEdit?: () => void
|
||||
onForkSend?: (draft: PromptDraft, modeId?: string | null) => void
|
||||
}
|
||||
|
||||
interface ResourceInputAttachment {
|
||||
@@ -280,6 +289,7 @@ export function MessageInput({
|
||||
isEditingQueueItem = false,
|
||||
onSaveQueueEdit,
|
||||
onCancelQueueEdit,
|
||||
onForkSend,
|
||||
}: MessageInputProps) {
|
||||
const t = useTranslations("Folder.chat.messageInput")
|
||||
const tQueue = useTranslations("Folder.chat.messageQueue")
|
||||
@@ -960,6 +970,24 @@ export function MessageInput({
|
||||
effectiveDraftStorageKey,
|
||||
])
|
||||
|
||||
const handleForkSendClick = useCallback(() => {
|
||||
if (!onForkSend) return
|
||||
const draft = buildDraft()
|
||||
if (!draft) return
|
||||
onForkSend(draft, showModeSelector ? effectiveModeId : null)
|
||||
if (effectiveDraftStorageKey) {
|
||||
clearMessageInputDraft(effectiveDraftStorageKey)
|
||||
}
|
||||
setText("")
|
||||
setAttachments([])
|
||||
}, [
|
||||
onForkSend,
|
||||
buildDraft,
|
||||
effectiveModeId,
|
||||
showModeSelector,
|
||||
effectiveDraftStorageKey,
|
||||
])
|
||||
|
||||
const handleKeyDown = useCallback(
|
||||
(e: React.KeyboardEvent) => {
|
||||
if (
|
||||
@@ -1288,6 +1316,35 @@ export function MessageInput({
|
||||
<Square className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
) : onForkSend ? (
|
||||
<div className="absolute right-2 bottom-2 flex items-center">
|
||||
<Button
|
||||
onClick={handleSend}
|
||||
disabled={disabled || !hasSendableContent}
|
||||
size="icon"
|
||||
className="rounded-r-none"
|
||||
title={t("send")}
|
||||
>
|
||||
<Send className="h-4 w-4" />
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
disabled={disabled || !hasSendableContent}
|
||||
size="icon"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 w-6"
|
||||
>
|
||||
<ChevronUp className="h-3 w-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" side="top">
|
||||
<DropdownMenuItem onSelect={handleForkSendClick}>
|
||||
<GitFork className="h-4 w-4" />
|
||||
{t("forkAndSend")}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleSend}
|
||||
|
||||
@@ -24,10 +24,12 @@ import { ConversationShell } from "@/components/chat/conversation-shell"
|
||||
import { AgentSelector } from "@/components/chat/agent-selector"
|
||||
import { ChatInput } from "@/components/chat/chat-input"
|
||||
import {
|
||||
acpFork,
|
||||
createConversation,
|
||||
openSettingsWindow,
|
||||
updateConversationExternalId,
|
||||
updateConversationStatus,
|
||||
updateConversationTitle,
|
||||
} from "@/lib/tauri"
|
||||
import { useConversationRuntime } from "@/contexts/conversation-runtime-context"
|
||||
import { useConversationDetail } from "@/hooks/use-conversation-detail"
|
||||
@@ -137,7 +139,8 @@ const ConversationTabView = memo(function ConversationTabView({
|
||||
const tWelcome = useTranslations("Folder.chat.welcomeInputPanel")
|
||||
const sharedT = useTranslations("Folder.chat.shared")
|
||||
const { folder, folderId, refreshConversations } = useFolderContext()
|
||||
const { bindConversationTab, setTabRuntimeConversationId } = useTabContext()
|
||||
const { tabs, bindConversationTab, setTabRuntimeConversationId } =
|
||||
useTabContext()
|
||||
const { setSessionStats } = useSessionStats()
|
||||
const {
|
||||
appendOptimisticTurn,
|
||||
@@ -608,6 +611,70 @@ const ConversationTabView = memo(function ConversationTabView({
|
||||
handleSendRef.current = handleSend
|
||||
}, [handleSend])
|
||||
|
||||
const handleForkSend = useCallback(
|
||||
async (draft: PromptDraft, selectedModeIdArg?: string | null) => {
|
||||
const connectionId = conn.connectionId
|
||||
if (!connectionId || connStatus !== "connected") return
|
||||
try {
|
||||
const { forkedSessionId, originalSessionId } = await acpFork(
|
||||
connectionId
|
||||
)
|
||||
const persistedId = dbConvIdRef.current
|
||||
if (persistedId != null) {
|
||||
const currentTab = tabs.find((tab) => tab.id === tabId)
|
||||
const currentTitle =
|
||||
currentTab?.title || detail?.summary.title || t("newConversation")
|
||||
// Point current conversation at S2 (forked) and add fork tag
|
||||
await updateConversationExternalId(persistedId, forkedSessionId)
|
||||
await updateConversationTitle(
|
||||
persistedId,
|
||||
`[Fork] ${currentTitle}`
|
||||
)
|
||||
// Save original S1 as a separate conversation with original title
|
||||
const s1ConvId = await createConversation(
|
||||
folderId,
|
||||
selectedAgent,
|
||||
currentTitle
|
||||
)
|
||||
await updateConversationExternalId(s1ConvId, originalSessionId)
|
||||
await updateConversationStatus(s1ConvId, "pending_review")
|
||||
}
|
||||
// Update runtime session id to S2
|
||||
sessionIdRef.current = forkedSessionId
|
||||
setExternalId(effectiveConversationId, forkedSessionId)
|
||||
|
||||
await refreshConversations()
|
||||
// Now send the message on the forked session (S2)
|
||||
handleSend(draft, selectedModeIdArg)
|
||||
} catch (err) {
|
||||
toast.error(
|
||||
t("forkSessionFailed", {
|
||||
error:
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: typeof err === "object" && err !== null
|
||||
? JSON.stringify(err)
|
||||
: String(err),
|
||||
})
|
||||
)
|
||||
}
|
||||
},
|
||||
[
|
||||
conn.connectionId,
|
||||
connStatus,
|
||||
detail?.summary.title,
|
||||
effectiveConversationId,
|
||||
folderId,
|
||||
handleSend,
|
||||
refreshConversations,
|
||||
selectedAgent,
|
||||
setExternalId,
|
||||
t,
|
||||
tabId,
|
||||
tabs,
|
||||
]
|
||||
)
|
||||
|
||||
const handleOpenAgentsSettings = useCallback(() => {
|
||||
openSettingsWindow("agents", { agentType: selectedAgent }).catch((err) => {
|
||||
console.error(
|
||||
@@ -757,6 +824,11 @@ const ConversationTabView = memo(function ConversationTabView({
|
||||
isEditingQueueItem={mqEditingItemId != null}
|
||||
onSaveQueueEdit={handleSaveQueueEdit}
|
||||
onCancelQueueEdit={handleQueueCancelEdit}
|
||||
onForkSend={
|
||||
connStatus === "connected" && hasPersistedConversation
|
||||
? handleForkSend
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{isWelcomeMode ? (
|
||||
<div className="flex h-full min-h-0 flex-col items-center justify-center">
|
||||
|
||||
Reference in New Issue
Block a user