chore: refresh agent debug conversatation id

This commit is contained in:
Joel 2026-06-23 16:05:46 +08:00
parent 44a4fb8888
commit dd3ba72c2c
3 changed files with 40 additions and 3 deletions

View File

@ -6,6 +6,7 @@ const mocks = vi.hoisted(() => ({
queryState: {
agent: {
data: {
debug_conversation_id: 'debug-conversation-old',
icon: 'agent',
icon_background: '#E0F2FE',
icon_type: 'emoji',
@ -107,7 +108,13 @@ vi.mock('../components/preview/chat-features-panel', () => ({
}))
vi.mock('../components/preview/header', () => ({
AgentPreviewHeader: () => <div role="banner" />,
AgentPreviewHeader: (props: {
onRestart: () => void
}) => (
<button type="button" onClick={props.onRestart}>
restart preview
</button>
),
}))
vi.mock('../components/preview/versions-panel', () => ({
@ -125,6 +132,7 @@ describe('AgentConfigurePage', () => {
icon_background: '#E0F2FE',
icon_type: 'emoji',
name: 'Research Agent',
debug_conversation_id: 'debug-conversation-old',
},
isFetching: false,
isPending: false,

View File

@ -1,18 +1,41 @@
'use client'
import type { AgentAppDetailWithSite } from '@dify/contracts/api/console/agent/types.gen'
import { cn } from '@langgenius/dify-ui/cn'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import { consoleQuery } from '@/service/client'
export function AgentPreviewHeader({
agentId,
isChatFeaturesOpen,
onToggleChatFeatures,
onRestart,
}: {
agentId: string
isChatFeaturesOpen: boolean
onToggleChatFeatures: () => void
onRestart: () => void
}) {
const { t } = useTranslation('agentV2')
const queryClient = useQueryClient()
const refreshDebugConversationMutation = useMutation(consoleQuery.agent.byAgentId.debugConversation.refresh.post.mutationOptions({
onSuccess: ({ debug_conversation_id }) => {
queryClient.setQueryData<AgentAppDetailWithSite | undefined>(
consoleQuery.agent.byAgentId.get.queryKey({ input: { params: { agent_id: agentId } } }),
(agentDetail) => {
if (!agentDetail)
return agentDetail
return {
...agentDetail,
debug_conversation_id,
}
},
)
onRestart()
},
}))
return (
<div className="flex h-12 shrink-0 items-center gap-3 py-3 pr-3 pl-6">
@ -22,8 +45,13 @@ export function AgentPreviewHeader({
<div className="flex shrink-0 items-center gap-1">
<button
type="button"
onClick={onRestart}
className="flex size-6 items-center justify-center rounded-md p-0.5 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"
onClick={() => refreshDebugConversationMutation.mutate({
params: {
agent_id: agentId,
},
})}
disabled={refreshDebugConversationMutation.isPending}
className="flex size-6 items-center justify-center rounded-md p-0.5 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"
aria-label={t('agentDetail.configure.preview.restart')}
>
<span aria-hidden className="i-custom-vender-other-replay-line size-4" />

View File

@ -139,6 +139,7 @@ function AgentConfigurePageLoadedContent({
<div className="flex min-w-105 flex-1 gap-1 overflow-hidden">
<div className="flex min-w-105 flex-1 flex-col overflow-hidden rounded-lg bg-background-gradient-bg-fill-chat-bg-2 shadow-xl shadow-shadow-shadow-5">
<AgentPreviewHeader
agentId={agentId}
isChatFeaturesOpen={showChatFeatures}
onToggleChatFeatures={() => setShowChatFeatures(open => !open)}
onRestart={() => setClearPreviewChat(true)}