feat(workflow): implement workflow system with steps terminology (#102)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { IconBrain, IconListCheck, IconLoader2, IconPaperclip } from '@tabler/icons-react';
|
||||
import { IconBrain, IconCheck, IconListCheck, IconLoader2, IconPaperclip } from '@tabler/icons-react';
|
||||
import { Button } from '@kandev/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -27,6 +27,8 @@ type ChatToolbarProps = {
|
||||
isStarting: boolean;
|
||||
isSending: boolean;
|
||||
onCancel: () => void;
|
||||
showApproveButton?: boolean;
|
||||
onApprove?: () => void;
|
||||
};
|
||||
|
||||
export function ChatToolbar({
|
||||
@@ -40,6 +42,8 @@ export function ChatToolbar({
|
||||
isStarting,
|
||||
isSending,
|
||||
onCancel,
|
||||
showApproveButton,
|
||||
onApprove,
|
||||
}: ChatToolbarProps) {
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
@@ -102,6 +106,22 @@ export function ChatToolbar({
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Add attachments</TooltipContent>
|
||||
</Tooltip>
|
||||
{showApproveButton && onApprove && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="h-7 gap-1 border-green-300 text-green-700 hover:bg-green-50 hover:text-green-800"
|
||||
onClick={onApprove}
|
||||
>
|
||||
<IconCheck className="h-3.5 w-3.5" />
|
||||
Approve
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Approve and move to next step</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
<KeyboardShortcutTooltip shortcut={SHORTCUTS.SUBMIT} enabled={!isAgentBusy && !isStarting}>
|
||||
<Button
|
||||
type={isAgentBusy ? 'button' : 'submit'}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkBreaks from 'remark-breaks';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import { IconRobot } from '@tabler/icons-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { Message } from '@/lib/types/http';
|
||||
import { RichBlocks } from '@/components/task/chat/messages/rich-blocks';
|
||||
@@ -62,7 +61,7 @@ export function ChatMessage({ comment, label, className, showRichBlocks }: ChatM
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkBreaks]}
|
||||
components={{
|
||||
code: ({ className, children, ...props }) => {
|
||||
code: ({ className, children }) => {
|
||||
// Check if it's inline code (no className means inline, className with language-* means code block)
|
||||
const isInline = !className || !className.startsWith('language-');
|
||||
|
||||
|
||||
@@ -87,7 +87,6 @@ export function CodeBlock({ children, className }: CodeBlockProps) {
|
||||
const effectiveTheme = theme === 'system' ? systemTheme : theme;
|
||||
|
||||
const code = String(children).replace(/\n$/, '');
|
||||
const language = className?.replace('language-', '') || '';
|
||||
const languageExtension = getLanguageExtension(className);
|
||||
|
||||
// Custom padding theme
|
||||
|
||||
@@ -77,12 +77,6 @@ export function ScriptExecutionMessage({ comment }: { comment: Message }) {
|
||||
? IconCheck
|
||||
: IconX;
|
||||
|
||||
const statusText = isRunning
|
||||
? 'Running...'
|
||||
: isSuccess
|
||||
? 'Completed'
|
||||
: 'Failed';
|
||||
|
||||
const statusColor = isRunning
|
||||
? 'text-blue-500'
|
||||
: isSuccess
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { IconAlertTriangle, IconInfoCircle, IconPointFilled, IconHandStop, IconChevronDown, IconChevronRight } from '@tabler/icons-react';
|
||||
import { IconAlertTriangle, IconInfoCircle, IconHandStop, IconChevronDown, IconChevronRight } from '@tabler/icons-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { Message } from '@/lib/types/http';
|
||||
import type { StatusMetadata } from '@/components/task/chat/types';
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { IconBrain, IconChevronDown, IconChevronRight } from '@tabler/icons-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { Message } from '@/lib/types/http';
|
||||
import type { RichMetadata } from '@/components/task/chat/types';
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
'use client';
|
||||
|
||||
import type { WorkflowStep } from '@/lib/types/http';
|
||||
import { cn } from '@kandev/ui/lib/utils';
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from '@kandev/ui/tooltip';
|
||||
|
||||
type SessionWorkflowProgressProps = {
|
||||
steps: WorkflowStep[];
|
||||
currentStepId: string | null;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export function SessionWorkflowProgress({
|
||||
steps,
|
||||
currentStepId,
|
||||
className,
|
||||
}: SessionWorkflowProgressProps) {
|
||||
const currentStepIndex = currentStepId
|
||||
? steps.findIndex((step) => step.id === currentStepId)
|
||||
: -1;
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center gap-1', className)}>
|
||||
{steps.map((step, i) => (
|
||||
<Tooltip key={step.id}>
|
||||
<TooltipTrigger asChild>
|
||||
<div
|
||||
className={cn(
|
||||
'w-2 h-2 rounded-full',
|
||||
i < currentStepIndex && 'bg-green-500',
|
||||
i === currentStepIndex && 'bg-blue-500 ring-2 ring-blue-200',
|
||||
i > currentStepIndex && 'bg-gray-300'
|
||||
)}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{step.name}</TooltipContent>
|
||||
</Tooltip>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { IconStack2, IconPlus } from '@tabler/icons-react';
|
||||
import { IconStack2, IconPlus, IconStar } from '@tabler/icons-react';
|
||||
import { Button } from '@kandev/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -88,6 +88,8 @@ type SessionsDropdownProps = {
|
||||
activeSessionId?: string | null;
|
||||
taskTitle?: string;
|
||||
taskDescription?: string;
|
||||
primarySessionId?: string | null;
|
||||
onSetPrimary?: (sessionId: string) => void;
|
||||
};
|
||||
|
||||
export function SessionsDropdown({
|
||||
@@ -95,6 +97,8 @@ export function SessionsDropdown({
|
||||
activeSessionId = null,
|
||||
taskTitle = '',
|
||||
taskDescription = '',
|
||||
primarySessionId = null,
|
||||
onSetPrimary,
|
||||
}: SessionsDropdownProps) {
|
||||
const [currentTime, setCurrentTime] = useState(() => Date.now());
|
||||
const [showNewSessionDialog, setShowNewSessionDialog] = useState(false);
|
||||
@@ -242,6 +246,8 @@ export function SessionsDropdown({
|
||||
const showDuration = duration !== '0s';
|
||||
const number = sortedSessions.length - index;
|
||||
|
||||
const isPrimary = session.id === primarySessionId;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={session.id}
|
||||
@@ -253,8 +259,11 @@ export function SessionsDropdown({
|
||||
#{number}
|
||||
</span>
|
||||
|
||||
<span className="text-xs text-foreground flex-1 text-left">
|
||||
<span className="text-xs text-foreground flex-1 text-left flex items-center gap-1.5">
|
||||
{resolveAgentLabel(session)}
|
||||
{isPrimary && (
|
||||
<IconStar className="h-3.5 w-3.5 text-amber-500 fill-amber-500" />
|
||||
)}
|
||||
</span>
|
||||
|
||||
{showDuration ?
|
||||
@@ -263,6 +272,24 @@ export function SessionsDropdown({
|
||||
</span>
|
||||
: ''}
|
||||
|
||||
{!isPrimary && onSetPrimary && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onSetPrimary(session.id);
|
||||
}}
|
||||
className="w-5 shrink-0 flex items-center justify-center text-muted-foreground hover:text-amber-500 transition-colors"
|
||||
>
|
||||
<IconStar className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="left">Set as Primary</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
<div className="w-5 shrink-0 flex items-center justify-center">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { FormEvent, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { flushSync } from 'react-dom';
|
||||
import { getWebSocketClient } from '@/lib/ws/connection';
|
||||
import { useAppStore } from '@/components/state-provider';
|
||||
import { useSessionMessages } from '@/hooks/domains/session/use-session-messages';
|
||||
import { useSettingsData } from '@/hooks/domains/settings/use-settings-data';
|
||||
import { useSessionState } from '@/hooks/domains/session/use-session-state';
|
||||
@@ -14,6 +15,7 @@ import { RunningIndicator } from '@/components/task/chat/messages/running-indica
|
||||
import { TodoSummary } from '@/components/task/chat/todo-summary';
|
||||
import { VirtualizedMessageList } from '@/components/task/chat/virtualized-message-list';
|
||||
import { ChatToolbar } from '@/components/task/chat/chat-toolbar';
|
||||
import { approveSessionAction } from '@/app/actions/workspaces';
|
||||
|
||||
type TaskChatPanelProps = {
|
||||
onSend?: (message: string) => void;
|
||||
@@ -89,6 +91,48 @@ export function TaskChatPanel({
|
||||
}
|
||||
}, [resolvedSessionId]);
|
||||
|
||||
// Get store action for updating session
|
||||
const setTaskSession = useAppStore((state) => state.setTaskSession);
|
||||
|
||||
// Review panel handlers
|
||||
const handleApprove = useCallback(async () => {
|
||||
if (!resolvedSessionId || !taskId) return;
|
||||
try {
|
||||
const response = await approveSessionAction(resolvedSessionId);
|
||||
|
||||
// Update the session in the store so the review panel closes
|
||||
if (response?.session) {
|
||||
setTaskSession(response.session);
|
||||
}
|
||||
|
||||
// Check if the new step has auto_start_agent enabled
|
||||
// Use fire-and-forget (send) instead of request since resuming session + sending prompt
|
||||
// can take a long time. Session state updates will come via WebSocket events anyway.
|
||||
if (response?.workflow_step?.auto_start_agent) {
|
||||
const client = getWebSocketClient();
|
||||
if (client) {
|
||||
client.send({
|
||||
type: 'request',
|
||||
action: 'orchestrator.start',
|
||||
payload: {
|
||||
task_id: taskId,
|
||||
session_id: resolvedSessionId,
|
||||
workflow_step_id: response.workflow_step.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to approve session:', error);
|
||||
}
|
||||
}, [resolvedSessionId, taskId, setTaskSession]);
|
||||
|
||||
|
||||
|
||||
// Check if we should show the approve button
|
||||
// Show when session has a review_status that is not approved (meaning it's in a review step)
|
||||
const showApproveButton = session?.review_status != null && session.review_status !== 'approved';
|
||||
|
||||
const handleSubmit = async (event?: FormEvent) => {
|
||||
event?.preventDefault();
|
||||
const trimmed = messageInput.trim();
|
||||
@@ -155,6 +199,8 @@ export function TaskChatPanel({
|
||||
isStarting={isStarting}
|
||||
isSending={isSending}
|
||||
onCancel={handleCancelTurn}
|
||||
showApproveButton={showApproveButton}
|
||||
onApprove={handleApprove}
|
||||
/>
|
||||
</form>
|
||||
</>
|
||||
|
||||
@@ -55,7 +55,7 @@ export function TaskPageContent({
|
||||
...baseTask,
|
||||
title: kanbanTask.title ?? baseTask.title,
|
||||
description: kanbanTask.description ?? baseTask.description,
|
||||
column_id: (kanbanTask.columnId as string | undefined) ?? baseTask.column_id,
|
||||
workflow_step_id: (kanbanTask.workflowStepId as string | undefined) ?? baseTask.workflow_step_id,
|
||||
position: kanbanTask.position ?? baseTask.position,
|
||||
state: (kanbanTask.state as Task['state'] | undefined) ?? baseTask.state,
|
||||
repositories: baseTask.repositories,
|
||||
|
||||
@@ -23,7 +23,7 @@ export function TaskSessionSidebar({ workspaceId, boardId }: TaskSessionSidebarP
|
||||
const activeSessionId = useAppStore((state) => state.tasks.activeSessionId);
|
||||
const sessionsById = useAppStore((state) => state.taskSessions.items);
|
||||
const { tasks } = useTasks(boardId);
|
||||
const columns = useAppStore((state) => state.kanban.columns);
|
||||
const columns = useAppStore((state) => state.kanban.steps);
|
||||
const workspaces = useAppStore((state) => state.workspaces.items);
|
||||
const repositoriesByWorkspace = useAppStore((state) => state.repositories.itemsByWorkspaceId);
|
||||
const setActiveTask = useAppStore((state) => state.setActiveTask);
|
||||
@@ -52,7 +52,7 @@ export function TaskSessionSidebar({ workspaceId, boardId }: TaskSessionSidebarP
|
||||
title: task.title,
|
||||
state: task.state as TaskState | undefined,
|
||||
description: task.description,
|
||||
columnId: task.columnId,
|
||||
workflowStepId: task.workflowStepId,
|
||||
repositoryPath: task.repositoryId ? repositoryPathsById.get(task.repositoryId) : undefined,
|
||||
}));
|
||||
}, [repositoriesByWorkspace, tasks, workspaceId]);
|
||||
@@ -121,7 +121,7 @@ export function TaskSessionSidebar({ workspaceId, boardId }: TaskSessionSidebarP
|
||||
<div className="flex-1 min-h-0 overflow-y-auto space-y-4 pt-3">
|
||||
<TaskSwitcher
|
||||
tasks={tasksWithRepositories}
|
||||
columns={columns.map((column: KanbanState['columns'][number]) => ({ id: column.id, title: column.title }))}
|
||||
columns={columns.map((step: KanbanState['steps'][number]) => ({ id: step.id, title: step.title, color: step.color }))}
|
||||
activeTaskId={activeTaskId}
|
||||
selectedTaskId={selectedTaskId}
|
||||
onSelectTask={(taskId) => {
|
||||
@@ -137,13 +137,13 @@ export function TaskSessionSidebar({ workspaceId, boardId }: TaskSessionSidebarP
|
||||
workspaceId={workspaceId}
|
||||
boardId={boardId}
|
||||
defaultColumnId={columns[0]?.id ?? null}
|
||||
columns={columns.map((column: KanbanState['columns'][number]) => ({ id: column.id, title: column.title }))}
|
||||
columns={columns.map((step: KanbanState['steps'][number]) => ({ id: step.id, title: step.title, color: step.color }))}
|
||||
onSuccess={(task, _mode, meta) => {
|
||||
store.setState((state) => {
|
||||
if (state.kanban.boardId !== task.board_id) return state;
|
||||
const nextTask = {
|
||||
id: task.id,
|
||||
columnId: task.column_id,
|
||||
workflowStepId: task.workflow_step_id,
|
||||
title: task.title,
|
||||
description: task.description,
|
||||
position: task.position ?? 0,
|
||||
|
||||
@@ -19,13 +19,13 @@ type TaskSwitcherItem = {
|
||||
title: string;
|
||||
state?: TaskState;
|
||||
description?: string;
|
||||
columnId?: string;
|
||||
workflowStepId?: string;
|
||||
repositoryPath?: string;
|
||||
};
|
||||
|
||||
type TaskSwitcherProps = {
|
||||
tasks: TaskSwitcherItem[];
|
||||
columns: Array<{ id: string; title: string }>;
|
||||
columns: Array<{ id: string; title: string; color?: string }>;
|
||||
activeTaskId: string | null;
|
||||
selectedTaskId: string | null;
|
||||
onSelectTask: (taskId: string) => void;
|
||||
@@ -47,7 +47,7 @@ export function TaskSwitcher({
|
||||
const tasksByColumn = useMemo(() => {
|
||||
const grouped: Record<string, TaskSwitcherItem[]> = {};
|
||||
for (const task of sortedTasks) {
|
||||
const key = task.columnId ?? 'unknown';
|
||||
const key = task.workflowStepId ?? 'unknown';
|
||||
if (!grouped[key]) grouped[key] = [];
|
||||
grouped[key].push(task);
|
||||
}
|
||||
@@ -56,9 +56,9 @@ export function TaskSwitcher({
|
||||
|
||||
const columnsWithFallback = useMemo(() => {
|
||||
const seen = new Set(columns.map((column) => column.id));
|
||||
const extra: Array<{ id: string; title: string }> = [];
|
||||
const extra: Array<{ id: string; title: string; color?: string }> = [];
|
||||
if (tasksByColumn.unknown?.length) {
|
||||
extra.push({ id: 'unknown', title: 'Other' });
|
||||
extra.push({ id: 'unknown', title: 'Other', color: 'bg-neutral-400' });
|
||||
}
|
||||
return [...columns, ...extra].filter((column) => {
|
||||
if (seen.has(column.id)) return true;
|
||||
@@ -95,7 +95,10 @@ export function TaskSwitcher({
|
||||
className="group flex w-full items-center justify-between cursor-pointer"
|
||||
aria-label="Toggle column"
|
||||
>
|
||||
<span className="truncate text-sm font-medium text-muted-foreground">{column.title}</span>
|
||||
<span className="flex items-center gap-2 truncate text-sm font-medium text-muted-foreground">
|
||||
<span className={`w-2 h-2 rounded-full shrink-0 ${column.color ?? 'bg-neutral-400'}`} />
|
||||
{column.title}
|
||||
</span>
|
||||
<IconChevronRight className={`h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity ${isColumnOpen ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
{isColumnOpen && (
|
||||
|
||||
Reference in New Issue
Block a user