优化会话fork代码
This commit is contained in:
@@ -1333,6 +1333,7 @@ export function MessageInput({
|
|||||||
disabled={disabled || !hasSendableContent}
|
disabled={disabled || !hasSendableContent}
|
||||||
size="icon"
|
size="icon"
|
||||||
className="rounded-l-none border-l border-primary-foreground/20 w-6"
|
className="rounded-l-none border-l border-primary-foreground/20 w-6"
|
||||||
|
aria-label={t("forkAndSend")}
|
||||||
>
|
>
|
||||||
<ChevronUp className="h-3 w-3" />
|
<ChevronUp className="h-3 w-3" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -611,6 +611,13 @@ const ConversationTabView = memo(function ConversationTabView({
|
|||||||
handleSendRef.current = handleSend
|
handleSendRef.current = handleSend
|
||||||
}, [handleSend])
|
}, [handleSend])
|
||||||
|
|
||||||
|
// Resolve the current conversation title from tab context (most up-to-date)
|
||||||
|
// or fall back to the DB detail summary.
|
||||||
|
const conversationTitle = useMemo(() => {
|
||||||
|
const tabTitle = tabs.find((tab) => tab.id === tabId)?.title
|
||||||
|
return tabTitle || detail?.summary.title || null
|
||||||
|
}, [tabs, tabId, detail?.summary.title])
|
||||||
|
|
||||||
const handleForkSend = useCallback(
|
const handleForkSend = useCallback(
|
||||||
async (draft: PromptDraft, selectedModeIdArg?: string | null) => {
|
async (draft: PromptDraft, selectedModeIdArg?: string | null) => {
|
||||||
const connectionId = conn.connectionId
|
const connectionId = conn.connectionId
|
||||||
@@ -621,20 +628,17 @@ const ConversationTabView = memo(function ConversationTabView({
|
|||||||
)
|
)
|
||||||
const persistedId = dbConvIdRef.current
|
const persistedId = dbConvIdRef.current
|
||||||
if (persistedId != null) {
|
if (persistedId != null) {
|
||||||
const currentTab = tabs.find((tab) => tab.id === tabId)
|
const baseTitle = conversationTitle ?? t("newConversation")
|
||||||
const currentTitle =
|
// Strip existing [Fork] prefix to avoid stacking
|
||||||
currentTab?.title || detail?.summary.title || t("newConversation")
|
const cleanTitle = baseTitle.replace(/^\[Fork]\s*/g, "")
|
||||||
// Point current conversation at S2 (forked) and add fork tag
|
// Point current conversation at S2 (forked) and add fork tag
|
||||||
await updateConversationExternalId(persistedId, forkedSessionId)
|
await updateConversationExternalId(persistedId, forkedSessionId)
|
||||||
await updateConversationTitle(
|
await updateConversationTitle(persistedId, `[Fork] ${cleanTitle}`)
|
||||||
persistedId,
|
|
||||||
`[Fork] ${currentTitle}`
|
|
||||||
)
|
|
||||||
// Save original S1 as a separate conversation with original title
|
// Save original S1 as a separate conversation with original title
|
||||||
const s1ConvId = await createConversation(
|
const s1ConvId = await createConversation(
|
||||||
folderId,
|
folderId,
|
||||||
selectedAgent,
|
selectedAgent,
|
||||||
currentTitle
|
cleanTitle
|
||||||
)
|
)
|
||||||
await updateConversationExternalId(s1ConvId, originalSessionId)
|
await updateConversationExternalId(s1ConvId, originalSessionId)
|
||||||
await updateConversationStatus(s1ConvId, "pending_review")
|
await updateConversationStatus(s1ConvId, "pending_review")
|
||||||
@@ -644,7 +648,7 @@ const ConversationTabView = memo(function ConversationTabView({
|
|||||||
setExternalId(effectiveConversationId, forkedSessionId)
|
setExternalId(effectiveConversationId, forkedSessionId)
|
||||||
|
|
||||||
await refreshConversations()
|
await refreshConversations()
|
||||||
// Now send the message on the forked session (S2)
|
// Send the message on the forked session (S2)
|
||||||
handleSend(draft, selectedModeIdArg)
|
handleSend(draft, selectedModeIdArg)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error(
|
toast.error(
|
||||||
@@ -662,7 +666,7 @@ const ConversationTabView = memo(function ConversationTabView({
|
|||||||
[
|
[
|
||||||
conn.connectionId,
|
conn.connectionId,
|
||||||
connStatus,
|
connStatus,
|
||||||
detail?.summary.title,
|
conversationTitle,
|
||||||
effectiveConversationId,
|
effectiveConversationId,
|
||||||
folderId,
|
folderId,
|
||||||
handleSend,
|
handleSend,
|
||||||
@@ -670,8 +674,6 @@ const ConversationTabView = memo(function ConversationTabView({
|
|||||||
selectedAgent,
|
selectedAgent,
|
||||||
setExternalId,
|
setExternalId,
|
||||||
t,
|
t,
|
||||||
tabId,
|
|
||||||
tabs,
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user