Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

fix(ui): tidy the new-workflow chat and the page after saving a workflow (#412)

Rufusa13d6f38f294
diff --git a/packages/ui/src/app/jobs/[name]/page.tsx b/packages/ui/src/app/jobs/[name]/page.tsx
index dae11b5f..87e2a5a2 100644
--- a/packages/ui/src/app/jobs/[name]/page.tsx
+++ b/packages/ui/src/app/jobs/[name]/page.tsx
@@ -1,10 +1,10 @@
"use client";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { useParams, useSearchParams } from "next/navigation";
+import { usePathname, useParams, useRouter, useSearchParams } from "next/navigation";
import Link from "next/link";
import WorkflowRunner from "@/components/WorkflowRunner";
-import Button from "@/components/ui/Button";
+import Button, { buttonClass } from "@/components/ui/Button";
import ApprovedTargets from "@/components/jobs/ApprovedTargets";
import PendingWorkflowReview from "@/components/jobs/PendingWorkflowReview";
import {
@@ -15,6 +15,7 @@ import {
getWorkflow,
getWorkflowSample,
} from "@/lib/api";
+import { describeCadence } from "@/lib/workflowChanges";
type FormState = Record<string, string>;
@@ -71,6 +72,8 @@ function isMultiline(name: string, schema: WorkflowInputFieldSchema): boolean {
export default function JobDetailPage() {
const params = useParams<{ name: string }>();
const searchParams = useSearchParams();
+ const router = useRouter();
+ const pathname = usePathname();
const name = params?.name;
const [workflow, setWorkflow] = useState<WorkflowMeta | null>(null);
const [loadError, setLoadError] = useState<string | null>(null);
@@ -78,6 +81,13 @@ export default function JobDetailPage() {
// 404s); it gets its review card instead, where turning it on approves it.
const [pendingDef, setPendingDef] = useState<DynamicWorkflowDef | null>(null);
const [reloadKey, setReloadKey] = useState(0);
+ // A saved custom workflow, for when it runs.
+ const [customDef, setCustomDef] = useState<DynamicWorkflowDef | null>(null);
+ // Only offer "Fill with an example" when the workflow has one.
+ const [hasSample, setHasSample] = useState(false);
+ // Arrived straight from creating or changing it (`?saved=1`). Read once and
+ // dropped from the URL, so a refresh doesn't say it again.
+ const [justSaved] = useState(() => searchParams?.get("saved") === "1");
const [form, setForm] = useState<FormState>({});
const [running, setRunning] = useState(false);
const [prefillBanner, setPrefillBanner] = useState<
@@ -90,6 +100,16 @@ export default function JobDetailPage() {
const initializedForWorkflowRef = useRef<string | null>(null);
const prefillRaw = searchParams?.get("prefill") ?? null;
+ useEffect(() => {
+ if (!justSaved || !pathname) return;
+ const rest = new URLSearchParams(searchParams?.toString() ?? "");
+ rest.delete("saved");
+ const qs = rest.toString();
+ router.replace(qs ? `${pathname}?${qs}` : pathname, { scroll: false });
+ // Once, on arrival.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
useEffect(() => {
if (!name) return;
// Only initialize the form once per workflow name. Re-runs that don't
@@ -122,6 +142,16 @@ export default function JobDetailPage() {
if (appliedAny) setPrefillBanner("suggestion");
setForm(initial);
initializedForWorkflowRef.current = name;
+ if (wf.is_custom) {
+ getCustomWorkflow(name)
+ .then((d) => !cancelled && setCustomDef(d))
+ .catch(() => {});
+ }
+ if (Object.keys(props).length > 0) {
+ getWorkflowSample(name)
+ .then(() => !cancelled && setHasSample(true))
+ .catch(() => {});
+ }
})
.catch(async (e) => {
const message = e instanceof Error ? e.message : String(e);
@@ -229,6 +259,44 @@ export default function JobDetailPage() {
}
const props = workflow.input_schema.properties ?? {};
+ const hasInputs = Object.keys(props).length > 0;
+ // "Load context" is setup every run does, not something this workflow does.
+ const steps = workflow.steps
+ .filter((s) => s.id !== "context")
+ .map((s) => {
+ const custom = customDef?.steps.find((c) => c.id === s.id);
+ const detail = !custom
+ ? ""
+ : custom.kind === "approval_gate"
+ ? custom.question
+ : custom.kind === "synthesis"
+ ? custom.instructions
+ : custom.goal;
+ return { id: s.id, title: s.title, detail: s.description || detail };
+ });
+ const editHref = workflow.is_custom
+ ? `/jobs/new?edit=${encodeURIComponent(workflow.name)}`
+ : null;
+ const runButtons = (
+ <div className="flex flex-wrap items-center gap-3">
+ <Button
+ type="submit"
+ variant="primary"
+ disabled={!allRequiredFilled}
+ className="px-7"
+ >
+ Run it now
+ </Button>
+ {editHref && (
+ <Link href={editHref} className={buttonClass("secondary")}>
+ Change it
+ </Link>
+ )}
+ {hasInputs && (
+ <span className="text-sm text-fg-muted">All fields with * are required.</span>
+ )}
+ </div>
+ );
return (
<div className="flex flex-col h-full bg-surface text-fg">
@@ -238,6 +306,16 @@ export default function JobDetailPage() {
<Link href="/jobs" className="text-sm text-fg-muted hover:text-fg">
← Workflows
</Link>
+ {justSaved && (
+ <div className="mt-3">
+ <p
+ role="status"
+ className="inline-flex items-center gap-1.5 rounded-full bg-emerald-500/10 px-3 py-1 text-sm font-medium text-emerald-500"
+ >
+ <span aria-hidden="true">✓</span> Saved
+ </p>
+ </div>
+ )}
<h1 className="mt-2 mb-2 text-2xl sm:text-3xl font-bold tracking-tight text-fg">
{workflow.title}
</h1>
@@ -264,7 +342,66 @@ export default function JobDetailPage() {
)}
</div>
- {!running && (
+ {!running && (steps.length > 0 || customDef) && (
+ <section className="rounded-2xl border border-line bg-surface-elevated p-5 shadow-sm sm:p-7">
+ {customDef && (
+ <div
+ className={`flex items-start justify-between gap-3 ${
+ steps.length > 0 ? "border-b border-line pb-4 mb-4" : ""
+ }`}
+ >
+ <div>
+ <p className="text-[15px] font-semibold text-fg">
+ {customDef.cadence
+ ? describeCadence(customDef.cadence)
+ : "Runs when you start it"}
+ </p>
+ <p className="text-sm text-fg-muted">
+ {hasInputs
+ ? "You fill in a few details each time."
+ : "Nothing to fill in."}
+ </p>
+ </div>
+ {editHref && (
+ <Link
+ href={editHref}
+ className="shrink-0 text-sm text-fg-muted hover:text-fg"
+ >
+ Change
+ </Link>
+ )}
+ </div>
+ )}
+ {steps.length > 0 && (
+ <>
+ <h2 className="text-lg font-semibold text-fg">What it does</h2>
+ <ol className="mt-3 space-y-2.5">
+ {steps.map((step, i) => (
+ <li key={step.id} className="flex gap-3 text-[15px]">
+ <span className="shrink-0 mt-0.5 flex h-6 w-6 items-center justify-center rounded-full bg-surface-overlay text-xs text-fg-muted">
+ {i + 1}
+ </span>
+ <div className="min-w-0">
+ <p className="text-fg">{step.title}</p>
+ {step.detail && (
+ <p className="text-sm text-fg-muted line-clamp-2 break-words">
+ {step.detail}
+ </p>
+ )}
+ </div>
+ </li>
+ ))}
+ </ol>
+ </>
+ )}
+ </section>
+ )}
+
+ {!running && !hasInputs && (
+ <form onSubmit={handleSubmit}>{runButtons}</form>
+ )}
+
+ {!running && hasInputs && (
<form
onSubmit={handleSubmit}
className="space-y-6 rounded-2xl border border-line bg-surface-elevated p-5 shadow-sm sm:p-7"
@@ -273,14 +410,16 @@ export default function JobDetailPage() {
<h2 className="text-lg font-semibold text-fg">What it needs</h2>
{/* Fills every field with a realistic sample; each field's
own "Use example" fills just that one. */}
- <button
- type="button"
- onClick={handleLoadSample}
- title="Load a realistic sample to see what good inputs look like. You can edit anything before running."
- className="min-h-10 rounded-lg px-2 text-[15px] font-semibold text-accent hover:underline underline-offset-4 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/60"
- >
- Fill with an example
- </button>
+ {hasSample && (
+ <button
+ type="button"
+ onClick={handleLoadSample}
+ title="Load a realistic sample to see what good inputs look like. You can edit anything before running."
+ className="min-h-10 rounded-lg px-2 text-[15px] font-semibold text-accent hover:underline underline-offset-4 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/60"
+ >
+ Fill with an example
+ </button>
+ )}
</div>
{prefillBanner && (
@@ -375,16 +514,7 @@ export default function JobDetailPage() {
);
})}
- <div className="flex flex-wrap items-center gap-3 pt-1">
- <Button type="submit" variant="primary" disabled={!allRequiredFilled} className="px-7">
- Continue
- </Button>
- {Object.keys(props).length > 0 && (
- <span className="text-sm text-fg-muted">
- All fields with * are required.
- </span>
- )}
- </div>
+ <div className="pt-1">{runButtons}</div>
</form>
)}
diff --git a/packages/ui/src/app/jobs/new/page.tsx b/packages/ui/src/app/jobs/new/page.tsx
index 3d2cbc60..6eaf084b 100644
--- a/packages/ui/src/app/jobs/new/page.tsx
+++ b/packages/ui/src/app/jobs/new/page.tsx
@@ -429,7 +429,7 @@ function BuilderInner() {
try {
if (editName) await updateCustomWorkflow(editName, def);
else await createCustomWorkflow(def);
- router.push(`/jobs/${encodeURIComponent(def.name)}`);
+ router.push(`/jobs/${encodeURIComponent(def.name)}?saved=1`);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
setSaving(false);
@@ -1047,6 +1047,7 @@ function AdvancedBuilderPage() {
function WizardPage() {
const editName = useSearchParams().get("edit");
+ const [progress, setProgress] = useState<string | null>(null);
return (
<div className="flex flex-col h-full min-h-0 bg-surface text-fg">
<div className="border-b border-line px-4 sm:px-6 py-4">
@@ -1054,13 +1055,22 @@ function WizardPage() {
<Link href="/jobs" className="text-sm text-fg-muted hover:text-fg">
← Back to workflows
</Link>
- <h1 className="text-2xl sm:text-3xl font-bold tracking-tight text-fg mt-1">
- {editName ? "Edit workflow" : "New workflow"}
- </h1>
+ <div className="mt-1 flex items-baseline justify-between gap-3">
+ <h1 className="text-2xl sm:text-3xl font-bold tracking-tight text-fg">
+ {editName ? "Edit workflow" : "New workflow"}
+ </h1>
+ {progress && (
+ <span className="shrink-0 text-sm text-fg-subtle">{progress}</span>
+ )}
+ </div>
</div>
</div>
<div className="flex-1 min-h-0">
- <WorkflowWizard key={editName ?? ""} editName={editName ?? undefined} />
+ <WorkflowWizard
+ key={editName ?? ""}
+ editName={editName ?? undefined}
+ onProgress={setProgress}
+ />
</div>
</div>
);
diff --git a/packages/ui/src/components/jobs/WorkflowDraftReview.tsx b/packages/ui/src/components/jobs/WorkflowDraftReview.tsx
index 329b0cf8..24b15b8c 100644
--- a/packages/ui/src/components/jobs/WorkflowDraftReview.tsx
+++ b/packages/ui/src/components/jobs/WorkflowDraftReview.tsx
@@ -127,10 +127,10 @@ export default function WorkflowDraftReview({
pending.onActivated();
} else if (edit && sessionId) {
const saved = await saveWorkflowDesignerEdit(sessionId, def);
- router.push(`/jobs/${encodeURIComponent(saved.name)}`);
+ router.push(`/jobs/${encodeURIComponent(saved.name)}?saved=1`);
} else {
const saved = await createCustomWorkflow(def);
- router.push(`/jobs/${encodeURIComponent(saved.name)}`);
+ router.push(`/jobs/${encodeURIComponent(saved.name)}?saved=1`);
}
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
diff --git a/packages/ui/src/components/jobs/WorkflowWizard.tsx b/packages/ui/src/components/jobs/WorkflowWizard.tsx
index 1df6ac0e..eff11d80 100644
--- a/packages/ui/src/components/jobs/WorkflowWizard.tsx
+++ b/packages/ui/src/components/jobs/WorkflowWizard.tsx
@@ -35,7 +35,14 @@ const EDIT_STARTERS = [
* changes, save. The thread scrolls inside a fixed-height panel with the
* composer pinned, so the page never grows.
*/
-export default function WorkflowWizard({ editName }: { editName?: string } = {}) {
+export default function WorkflowWizard({
+ editName,
+ onProgress,
+}: {
+ editName?: string;
+ /** "Question 1 of 3" while asking, or null; the page shows it by its title. */
+ onProgress?: (text: string | null) => void;
+} = {}) {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
@@ -93,11 +100,26 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
bottomRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
}, [turn, pending, busy]);
+ // Which question this is, for the page header. None while drafting or
+ // changing a saved workflow.
+ const asked = turn?.questions_asked ?? 0;
+ const progress =
+ turn && !turn.editing && turn.phase !== "draft" && asked > 0
+ ? `Question ${Math.min(asked, turn.max_questions)} of ${turn.max_questions}`
+ : null;
+ useEffect(() => {
+ onProgress?.(progress);
+ }, [onProgress, progress]);
+ useEffect(() => () => onProgress?.(null), [onProgress]);
+
const run = useCallback(
async (op: () => Promise<WorkflowDesignerTurn>, pendingText: string | null) => {
setError(null);
setBusy(true);
setPending(pendingText);
+ // The message moves into the thread as it is sent, so the box empties
+ // now rather than showing the same text twice while waiting.
+ if (pendingText !== null) setInput("");
try {
const next = await op();
setTurn(next);
@@ -112,6 +134,8 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
}
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
+ // Put an unsent message back, ready to retry.
+ if (pendingText !== null) setInput(pendingText);
} finally {
setPending(null);
setBusy(false);
@@ -133,9 +157,7 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
const handedOff = takeWorkflowDescription()?.trim();
if (resumeId || editName) return;
if (handedOff) {
- // Kept in the composer until the first turn succeeds, so a failed
- // start leaves the text ready to retry.
- setInput(handedOff);
+ // A failed start puts the text back in the composer to retry.
void run(() => startWorkflowDesigner(handedOff), handedOff);
return;
}
@@ -179,6 +201,9 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
}
const started = turn !== null;
+ // The intro and examples go as soon as the first message is sent, not
+ // when the first reply arrives.
+ const showIntro = !started && pending === null;
const original = turn?.editing ? turn.original ?? null : null;
// Changing a saved workflow, before the user has said what to change.
const editOpening = !!original && turn!.transcript.length === 0;
@@ -197,7 +222,7 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
<div className="flex flex-col h-full min-h-0">
<div className="flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 py-6">
<div className="max-w-3xl mx-auto space-y-4">
- {!started && (
+ {showIntro && (
<div className="space-y-3">
<p className="text-base text-fg">
Describe the job you want done — what it should produce, who it&rsquo;s
@@ -302,12 +327,23 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
{pending && (
<div className="flex justify-end">
- <div className="max-w-[85%] rounded-2xl px-4 py-3 text-[15px] whitespace-pre-wrap bg-indigo-600/20 text-fg opacity-70">
+ <div className="max-w-[85%] rounded-2xl px-4 py-3 text-[15px] whitespace-pre-wrap bg-indigo-600/20 text-fg">
{pending}
</div>
</div>
)}
- {busy && <p className="text-sm text-fg-muted">Thinking…</p>}
+ {busy && (
+ <div className="flex justify-start" role="status" aria-live="polite">
+ <div className="flex items-center gap-2.5 rounded-2xl border border-line bg-surface-elevated px-4 py-3 text-sm text-fg-muted">
+ <span className="flex gap-1" aria-hidden="true">
+ <span className="h-1.5 w-1.5 rounded-full bg-fg-muted animate-pulse" />
+ <span className="h-1.5 w-1.5 rounded-full bg-fg-muted animate-pulse [animation-delay:150ms]" />
+ <span className="h-1.5 w-1.5 rounded-full bg-fg-muted animate-pulse [animation-delay:300ms]" />
+ </span>
+ {started ? "Thinking…" : "Reading what you need…"}
+ </div>
+ </div>
+ )}
<div ref={bottomRef} />
</div>
</div>
@@ -325,11 +361,13 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
send(input);
}
}}
- rows={started ? 2 : 4}
+ rows={showIntro ? 4 : 2}
disabled={busy}
autoFocus
placeholder={
- isDraft
+ busy
+ ? "Waiting for my reply…"
+ : isDraft
? "Tell me what to change… (Enter to send)"
: editOpening
? "e.g. Have Mark sign off instead, and run it on Fridays."
@@ -346,7 +384,7 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
disabled={busy || !input.trim()}
className="px-6"
>
- {busy ? "Thinking…" : started ? "Send" : "Start"}
+ {showIntro ? "Start" : "Send"}
</Button>
{started && !isDraft && !editOpening && (
<Button variant="ghost" onClick={draftNow} disabled={busy}>
@@ -354,11 +392,6 @@ export default function WorkflowWizard({ editName }: { editName?: string } = {})
</Button>
)}
<span className="ml-auto flex items-center gap-3 text-sm text-fg-subtle">
- {started && !original && (
- <span>
- {turn!.questions_asked} of {turn!.max_questions} questions
- </span>
- )}
<Link
href={
editTarget