"use client"; import { useEffect, useState } from "react"; import { ChevronLeft, Search, X } from "lucide-react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import type { Workflow } from "../shared/types"; import { listWorkflows } from "@/app/lib/mikeApi"; import { BUILT_IN_WORKFLOWS } from "../workflows/builtinWorkflows"; import { Modal } from "../shared/Modal"; interface Props { open: boolean; onClose: () => void; onSelect: (workflow: Workflow) => void; projectName?: string; projectCmNumber?: string | null; initialWorkflowId?: string; } export function AssistantWorkflowModal({ open, onClose, onSelect, projectName, projectCmNumber, initialWorkflowId, }: Props) { const [workflows, setWorkflows] = useState([]); const [loading, setLoading] = useState(false); const [selected, setSelected] = useState(null); const [search, setSearch] = useState(""); useEffect(() => { if (!open) return; let cancelled = false; const builtins = BUILT_IN_WORKFLOWS.filter( (w) => w.type === "assistant", ); const frame = requestAnimationFrame(() => { if (cancelled) return; setWorkflows(builtins); setLoading(true); if (initialWorkflowId) { const match = builtins.find((w) => w.id === initialWorkflowId); if (match) setSelected(match); } }); listWorkflows("assistant") .then((custom) => { if (cancelled) return; const all = [...builtins, ...custom]; setWorkflows(all); if (initialWorkflowId) { const match = all.find((w) => w.id === initialWorkflowId); if (match) setSelected(match); } }) .catch(() => { if (cancelled) return; if (initialWorkflowId) { const match = builtins.find((w) => w.id === initialWorkflowId); if (match) setSelected(match); } }) .finally(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; cancelAnimationFrame(frame); }; }, [open, initialWorkflowId]); if (!open) return null; const filteredWorkflows = search ? workflows.filter((w) => w.title.toLowerCase().includes(search.toLowerCase())) : workflows; function handleClose() { setSelected(null); setSearch(""); onClose(); } function handleUse() { if (!selected) return; onSelect(selected); handleClose(); } const breadcrumbs = projectName ? [ "Projects", `${projectName}${projectCmNumber ? ` (#${projectCmNumber})` : ""}`, "Assistant", "Add workflow", ] : ["Assistant", "Add workflow"]; return ( {/* Content */}
{/* Left panel — workflow list */}
{/* Search */}
setSearch(e.target.value)} className="flex-1 bg-transparent text-xs text-gray-700 placeholder:text-gray-400 outline-none" /> {search && ( )}
{loading ? (
{[60, 45, 75, 50, 65, 40, 55].map((w, i) => (
))}
) : filteredWorkflows.length === 0 ? (

{search ? "No matches found" : "No assistant workflows found"}

) : (
{filteredWorkflows.map((wf) => ( ))}
)}
{/* Right panel — prompt preview */} {selected && (

Workflow Prompt

(

{children}

), h2: ({ children }) => (

{children}

), h3: ({ children }) => (

{children}

), p: ({ children }) => (

{children}

), ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), li: ({ children }) => (
  • {children}
  • ), strong: ({ children }) => ( {children} ), em: ({ children }) => ( {children} ), }} > {selected.prompt_md ?? "_No prompt defined._"}
    )}
    ); }