Files
dify/web/app/(commonLayout)/workflow-copilot-debug/page.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

189 lines
5.5 KiB
TypeScript

'use client'
import { useState } from 'react'
import { COPILOT_ACTION_KINDS } from '@/app/components/workflow-copilot/types'
import { useCopilotSession } from '@/app/components/workflow-copilot/use-copilot-session'
import { API_PREFIX } from '@/config'
// Throwaway developer tool for driving the workflow-copilot Fix backend by hand.
// No i18n, no design polish, no reusable UI components on purpose.
// Session/stream request logic lives in `app/components/workflow-copilot/use-copilot-session.ts`,
// shared with the in-editor Workflow Copilot panel (see `app/components/workflow/panel/workflow-copilot-panel`).
export default function WorkflowCopilotDebugPage() {
const [baseUrl, setBaseUrl] = useState(API_PREFIX)
const [appId, setAppId] = useState('')
const [failedRunId, setFailedRunId] = useState('')
const [workspaceId, setWorkspaceId] = useState('')
const [messageText, setMessageText] = useState('')
const { view, lastRaw, lastError, progressLog, startFix, refresh, runAction, sendMessage } =
useCopilotSession({ baseUrl, workspaceId })
const handleStartFix = async () => {
await startFix(appId, failedRunId)
}
const handleGet = async () => {
await refresh()
}
const handleAction = async (kind: (typeof COPILOT_ACTION_KINDS)[number]) => {
await runAction(kind, kind === 'provide_testdata' ? { mode: 'mock' } : {})
}
const handleSendMessage = async () => {
const ok = await sendMessage(messageText)
if (ok) setMessageText('')
}
return (
<div style={{ padding: 24, fontFamily: 'monospace', maxWidth: 960 }}>
<h1>Workflow Copilot Debug</h1>
<p>Throwaway developer tool for driving the copilot Fix backend by hand.</p>
<fieldset style={{ marginBottom: 16 }}>
<legend>Connection</legend>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, maxWidth: 480 }}>
<label>
Base URL
<input
value={baseUrl}
onChange={(e) => setBaseUrl(e.target.value)}
style={{ width: '100%' }}
/>
</label>
<label>
App ID
<input
value={appId}
onChange={(e) => setAppId(e.target.value)}
style={{ width: '100%' }}
/>
</label>
<label>
Failed Run ID
<input
value={failedRunId}
onChange={(e) => setFailedRunId(e.target.value)}
style={{ width: '100%' }}
/>
</label>
<label>
Workspace ID
<input
value={workspaceId}
onChange={(e) => setWorkspaceId(e.target.value)}
style={{ width: '100%' }}
/>
</label>
</div>
<div style={{ marginTop: 8 }}>
<button
type="button"
onClick={() => {
void handleStartFix()
}}
>
Start Fix
</button>
<button
type="button"
onClick={() => {
void handleGet()
}}
style={{ marginLeft: 8 }}
>
Refresh (GET)
</button>
</div>
</fieldset>
<fieldset style={{ marginBottom: 16 }}>
<legend>Actions</legend>
<div>
{COPILOT_ACTION_KINDS.map((kind) => (
<button
key={kind}
type="button"
onClick={() => {
void handleAction(kind)
}}
style={{ marginRight: 8, marginBottom: 8 }}
>
{kind}
</button>
))}
</div>
<div style={{ display: 'flex', gap: 8, maxWidth: 480 }}>
<input
value={messageText}
onChange={(e) => setMessageText(e.target.value)}
placeholder="message text"
style={{ flex: 1 }}
/>
<button
type="button"
onClick={() => {
void handleSendMessage()
}}
>
Send Message
</button>
</div>
</fieldset>
{lastError && <div style={{ color: 'red', marginBottom: 16 }}>Error: {lastError}</div>}
<fieldset style={{ marginBottom: 16 }}>
<legend>Status</legend>
{view ? (
<ul>
<li>SessionID: {view.SessionID}</li>
<li>State: {view.State}</li>
<li>Version: {view.Version}</li>
<li>CanvasReadOnly: {String(view.CanvasReadOnly)}</li>
<li>RunStatus: {view.RunStatus}</li>
<li>Interrupted: {String(view.Interrupted)}</li>
</ul>
) : (
<p>No session yet.</p>
)}
</fieldset>
<fieldset style={{ marginBottom: 16 }}>
<legend>Conversation</legend>
<ul>
{(view?.Conversation ?? []).map((entry) => (
<li key={entry.Seq}>
{entry.Seq}
{' · '}
{entry.Kind}
{' · '}
{JSON.stringify(entry.Payload)}
</li>
))}
</ul>
</fieldset>
<fieldset style={{ marginBottom: 16 }}>
<legend>Progress Log (stream)</legend>
<ul>
{progressLog.map((entry) => (
<li key={entry.id}>
{entry.event}
{' · '}
{JSON.stringify(entry.data)}
</li>
))}
</ul>
</fieldset>
<fieldset>
<legend>Last Raw Response</legend>
<pre>{JSON.stringify(lastRaw, null, 2)}</pre>
</fieldset>
</div>
)
}