Files
dify/web/app/components/workflow/header/workflow-copilot-button.tsx
T
Charles YaoandClaude Opus 4.8 22dc64d6e6 feat(web): surface Workflow Copilot inside the workflow editor
Add a copilot toggle button next to Test Run in the workflow header and
a left-mounted panel that runs the copilot Fix flow (start fix, live
SSE progress log, approve_repair/run_verify/provide_testdata/publish/
undo/re_fix actions, and a message box), auto-resolving the app id
(workflow store `appId`), workspace id (`currentWorkspaceAtom`), and
the most recent failed run (`useWorkflowRunHistory`) instead of
requiring manual entry.

Extracts the session/SSE request logic from the standalone
`/workflow-copilot-debug` page into a shared
`app/components/workflow-copilot` module (`use-copilot-session`) so
both the debug page and the new panel drive the same implementation.

Adds a `showWorkflowCopilotPanel` store flag (defaults false) mirroring
the existing `showEnvPanel` pattern, so the feature is fully additive
and does not affect rag-pipeline/snippet editors that reuse the same
header/panel shell.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-18 21:45:04 -07:00

50 lines
1.6 KiB
TypeScript

import { Button } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
import { memo } from 'react'
import { useTranslation } from 'react-i18next'
import { useStore } from '@/app/components/workflow/store'
import useTheme from '@/hooks/use-theme'
const WorkflowCopilotButton = ({ disabled }: { disabled: boolean }) => {
const { t } = useTranslation()
const { theme } = useTheme()
const showWorkflowCopilotPanel = useStore((s) => s.showWorkflowCopilotPanel)
const setShowWorkflowCopilotPanel = useStore((s) => s.setShowWorkflowCopilotPanel)
const label = t(($) => $['copilot.buttonTooltip'], { ns: 'workflow' })
const handleClick = () => {
setShowWorkflowCopilotPanel(!showWorkflowCopilotPanel)
}
return (
<Tooltip>
<TooltipTrigger
render={
<Button
aria-label={label}
aria-pressed={showWorkflowCopilotPanel}
className={cn(
'rounded-lg border border-transparent p-2',
theme === 'dark' &&
showWorkflowCopilotPanel &&
'border-black/5 bg-white/10 backdrop-blur-xs',
)}
variant="ghost"
disabled={disabled}
onClick={handleClick}
>
<span
aria-hidden
className="i-ri-magic-line size-4 text-components-button-secondary-text"
/>
</Button>
}
/>
<TooltipContent>{label}</TooltipContent>
</Tooltip>
)
}
export default memo(WorkflowCopilotButton)