Skip to content

Automate browser based workflows with AI

Sidebar: replace the Getting started nav row with a progress card (SKY-15526) (#8438)

Marc Kelechavaef5afc07ba73
diff --git a/skyvern-frontend/src/components/onboarding/GettingStartedTrack.test.tsx b/skyvern-frontend/src/components/onboarding/GettingStartedTrack.test.tsx
index ede8c8584..bdcb3dac3 100644
--- a/skyvern-frontend/src/components/onboarding/GettingStartedTrack.test.tsx
+++ b/skyvern-frontend/src/components/onboarding/GettingStartedTrack.test.tsx
@@ -15,6 +15,16 @@ import {
} from "@/routes/root/useOnboardingTrack";
import { GettingStartedTrack } from "./GettingStartedTrack";
+const completedAt = "2026-09-01T12:00:00Z";
+const noProgress = {
+ first_agent_created: null,
+ first_successful_run: null,
+};
+const completedProgress = {
+ first_agent_created: completedAt,
+ first_successful_run: completedAt,
+};
+
function track(completedKeys: readonly string[]): OnboardingTrackV1 {
return {
version: "onboarding_track_v1",
@@ -24,21 +34,42 @@ function track(completedKeys: readonly string[]): OnboardingTrackV1 {
total_count: 8,
items: TRACK_KEYS.map((key) => ({
key,
- completed_at: completedKeys.includes(key) ? "2026-09-01T12:00:00Z" : null,
+ completed_at: completedKeys.includes(key) ? completedAt : null,
verification: SELF_ATTESTED_KEYS.has(key) ? "self" : "server",
})),
};
}
+
+function nineItemTrack(
+ completedKeys: readonly string[] = [],
+): OnboardingTrackV1 {
+ const base = track(completedKeys);
+ return {
+ ...base,
+ total_count: 9,
+ items: [
+ ...base.items,
+ {
+ key: SECOND_AGENT_KEY,
+ completed_at: completedKeys.includes(SECOND_AGENT_KEY)
+ ? completedAt
+ : null,
+ verification: "server",
+ },
+ ],
+ };
+}
+
function renderTrack(
value: OnboardingTrackV1,
overrides: Partial<Parameters<typeof GettingStartedTrack>[0]> = {},
) {
const props = {
track: value,
+ progress: noProgress,
credentialUnlocked: true,
intent: null,
onAttest: vi.fn(),
- onDismiss: vi.fn(),
onRestore: vi.fn(),
isPending: false,
...overrides,
@@ -50,6 +81,7 @@ function renderTrack(
);
return props;
}
+
const titlesIn = (group: string) =>
within(screen.getByRole("region", { name: group }))
.getAllByRole("listitem")
@@ -57,19 +89,161 @@ const titlesIn = (group: string) =>
const primaryLinks = () =>
screen
.getAllByRole("link")
- .filter((link) => link.className.includes("bg-cta"))
- .map((link) => link.textContent);
+ .filter((link) => link.className.includes("bg-cta"));
+const expectProgress = (done: number, total: number) => {
+ expect(screen.getByText(`${done} of ${total} done`)).toBeTruthy();
+ const progressbar = screen.getByRole("progressbar", {
+ name: "Getting started progress",
+ });
+ expect(progressbar.getAttribute("aria-valuenow")).toBe(String(done));
+ expect(progressbar.getAttribute("aria-valuemax")).toBe(String(total));
+ expect(progressbar.children).toHaveLength(total);
+};
+
afterEach(cleanup);
-it("orders Keep going by intent and gives the first incomplete row the only primary action", () => {
- renderTrack(track(["first_scheduled_run"]), { intent: "extract_data" });
+it.each([
+ ["no progress data", null, "Open schedules"],
+ ["a fresh account", noProgress, "Describe your first agent"],
+ [
+ "only the first agent created",
+ { first_agent_created: completedAt, first_successful_run: null },
+ "Run agent",
+ ],
+ ["the first agent complete", completedProgress, "Open schedules"],
+])("renders one filled action with %s", (_, progress, actionName) => {
+ renderTrack(track([]), { progress });
+ expect(primaryLinks()).toHaveLength(1);
+ expect(primaryLinks()[0]).toBe(
+ screen.getByRole("link", { name: actionName }),
+ );
+});
+
+it("renders the three first-agent steps with their shipped destinations", () => {
+ renderTrack(track([]));
+ const rows = within(
+ screen.getByRole("region", { name: "First agent" }),
+ ).getAllByRole("listitem");
+ const describeLink = screen.getByRole("link", {
+ name: "Describe your first agent",
+ });
+ const runLink = screen.getByRole("link", { name: "Run agent" });
+
+ expect(rows).toHaveLength(3);
+ expect(
+ rows.map((row) => row.querySelector("p .sr-only")?.textContent),
+ ).toEqual(["Complete: ", "Current step: ", "Upcoming step: "]);
+ expect(rows[0]?.querySelector("a")).toBeNull();
+ expect(rows[1]?.contains(describeLink)).toBe(true);
+ expect(describeLink.getAttribute("href")).toBe("/discover?focus=prompt");
+ expect(rows[2]?.contains(runLink)).toBe(true);
+ expect(runLink.getAttribute("href")).toBe("/agents");
+ expect(
+ within(screen.getByRole("region", { name: "First agent" }))
+ .getAllByRole("link", {
+ name: /How it works.*opens in new tab/,
+ })
+ .map((link) => link.getAttribute("href")),
+ ).toEqual([
+ "https://www.skyvern.com/docs/cloud/building-agents/build-an-agent",
+ "https://www.skyvern.com/docs/cloud/building-agents/run-an-agent",
+ ]);
+});
+
+it("renders no filled action after all required rows are complete", () => {
+ renderTrack(
+ track([
+ "first_scheduled_run",
+ "first_api_run",
+ "mcp_installed",
+ "credential_saved",
+ ]),
+ { progress: completedProgress },
+ );
+ expect(primaryLinks()).toHaveLength(0);
+ expect(
+ screen.getByRole("button", { name: "Mark Star Skyvern on GitHub done" }),
+ ).toBeTruthy();
+});
+
+it.each([
+ ["fresh paid", track([]), true, noProgress, 1, 7],
+ ["fresh Free", track([]), false, noProgress, 1, 6],
+ ["nine-item", nineItemTrack(), true, noProgress, 1, 8],
+ ["first agent done", track([]), true, completedProgress, 3, 7],
+])(
+ "counts progress and renders one bar segment per step for %s",
+ (_, value, credentialUnlocked, progress, done, total) => {
+ renderTrack(value, { credentialUnlocked, progress });
+ expectProgress(done, total);
+ },
+);
+
+it("collapses a completed first-agent group and expands its three rows", () => {
+ renderTrack(track([]), { progress: completedProgress });
+ expect(screen.getByText("First agent ready")).toBeTruthy();
+ expect(screen.queryByText("Create your first agent")).toBeNull();
+ const toggle = screen.getByRole("button", {
+ name: "Show first agent steps",
+ });
+ expect(toggle.getAttribute("aria-expanded")).toBe("false");
+ expect(
+ document.getElementById(toggle.getAttribute("aria-controls")!),
+ ).toBeTruthy();
+
+ fireEvent.click(toggle);
+
+ expect(toggle.getAttribute("aria-expanded")).toBe("true");
+ expect(screen.getByRole("button", { name: "Hide first agent steps" })).toBe(
+ toggle,
+ );
+ expect(titlesIn("First agent")).toHaveLength(3);
+ expect(screen.getByText("Create your first agent")).toBeTruthy();
+ expect(screen.getByText("Run your first agent")).toBeTruthy();
+});
+
+it("labels required group completion and community work as optional", () => {
+ renderTrack(
+ track([
+ "first_scheduled_run",
+ "first_api_run",
+ "mcp_installed",
+ "credential_saved",
+ ]),
+ { progress: completedProgress },
+ );
+ expect(
+ within(screen.getByRole("region", { name: "First agent" })).getByText(
+ "Done",
+ ),
+ ).toBeTruthy();
+ expect(
+ within(screen.getByRole("region", { name: "Keep going" })).getByText(
+ "Done",
+ { selector: "span" },
+ ),
+ ).toBeTruthy();
+ expect(
+ within(screen.getByRole("region", { name: "Stay in the loop" })).getByText(
+ "Optional",
+ ),
+ ).toBeTruthy();
+});
+
+it("orders Keep going by intent after first-agent work is complete", () => {
+ renderTrack(track(["first_scheduled_run"]), {
+ progress: completedProgress,
+ intent: "extract_data",
+ });
expect(titlesIn("Keep going")).toEqual([
"Current step: Run an agent from your own code",
"Complete: Run your agent automatically",
"Upcoming step: Use Skyvern from Claude, Cursor, or ChatGPT",
"Upcoming step: Let your agent log in for you",
]);
- expect(primaryLinks()).toEqual(["Get an API key"]);
+ expect(primaryLinks()[0]).toBe(
+ screen.getByRole("link", { name: "Get an API key" }),
+ );
expect(screen.queryByRole("region", { name: "Bring your team" })).toBeNull();
expect(screen.queryByText("Bring a teammate")).toBeNull();
expect(titlesIn("Stay in the loop")).toEqual([
@@ -77,10 +251,11 @@ it("orders Keep going by intent and gives the first incomplete row the only prim
"Upcoming step: Join the Discord",
"Upcoming step: Follow for updates",
]);
- expect(screen.getByText("1 of 4 complete")).toBeTruthy();
expect(
- screen
- .getAllByRole("link", { name: "How it works" })
+ within(screen.getByRole("region", { name: "Keep going" }))
+ .getAllByRole("link", {
+ name: /How it works.*opens in new tab/,
+ })
.map((link) => link.getAttribute("href")),
).toEqual([
"https://www.skyvern.com/docs/developers/getting-started/quickstart",
@@ -88,66 +263,131 @@ it("orders Keep going by intent and gives the first incomplete row the only prim
]);
});
-it("leads a nine-row track with the second-agent detail and omits it from eight-row tracks", () => {
- const base = track([]);
- renderTrack(
- {
- ...base,
- total_count: 9,
- items: [
- ...base.items,
- {
- key: SECOND_AGENT_KEY,
- completed_at: null,
- verification: "server",
- },
- ],
- },
- { rowDetails: { second_agent_run: <span>detail</span> } },
- );
- expect(titlesIn("Keep going")[0]).toBe("Current step: Run a second agent");
+it("uses agent copy and leads a nine-item Keep going group with the second-agent detail", () => {
+ renderTrack(nineItemTrack(), {
+ progress: completedProgress,
+ rowDetails: { second_agent_run: <span>detail</span> },
+ });
+ const row = screen.getByText("Run a second agent").closest("li");
+ expect(row).not.toBeNull();
+ expect(row?.textContent?.toLowerCase()).toContain("agent");
+ expect(row?.textContent?.toLowerCase()).not.toContain("workflow");
expect(screen.getByText("detail")).toBeTruthy();
- expect(screen.getByText("0 of 5 complete")).toBeTruthy();
- expect(primaryLinks()).toEqual(["Run another workflow…"]);
- expect(
- screen
- .getByRole("link", { name: "Run another workflow…" })
- .getAttribute("href"),
- ).toBe("/agents");
+ expect(primaryLinks()).toHaveLength(1);
+ expect(primaryLinks()[0]).toBe(
+ screen.getByRole("link", { name: "Run another agent" }),
+ );
+ expect(primaryLinks()[0]?.getAttribute("href")).toBe("/agents");
cleanup();
- renderTrack(base);
+ renderTrack(track([]));
expect(screen.queryByText("Run a second agent")).toBeNull();
});
-it("locks the credential row on Free, keeps it first for fill_forms, and leaves it uncounted", () => {
- renderTrack(track([]), { credentialUnlocked: false, intent: "fill_forms" });
- expect(titlesIn("Keep going")[0]).toBe(
- "Locked: Let your agent log in for you",
- );
- expect(screen.getByText("Available on Hobby and up")).toBeTruthy();
+it("moves a locked Free credential row to the end without counting it", () => {
+ renderTrack(track([]), {
+ progress: completedProgress,
+ credentialUnlocked: false,
+ intent: "fill_forms",
+ });
+ const rows = within(
+ screen.getByRole("region", { name: "Keep going" }),
+ ).getAllByRole("listitem");
+ const lastRow = rows[rows.length - 1]!;
+ expect(lastRow.textContent).toContain("Let your agent log in for you");
+ expect(lastRow.textContent).toContain("Available on Hobby and up");
expect(
- screen.getByRole("link", { name: "Upgrade" }).getAttribute("href"),
+ within(lastRow).getByRole("link", { name: "Upgrade" }).getAttribute("href"),
).toBe("/billing");
- expect(primaryLinks()).toEqual(["Open schedules"]);
- expect(screen.getByText("0 of 3 complete")).toBeTruthy();
- expect(screen.getByRole("progressbar").getAttribute("aria-valuemax")).toBe(
- "3",
+ expect(primaryLinks()).toHaveLength(1);
+ expect(primaryLinks()[0]).toBe(
+ screen.getByRole("link", { name: "Open schedules" }),
+ );
+ expectProgress(3, 6);
+});
+
+it("does not label a Free group done while its locked row remains", () => {
+ renderTrack(
+ track(["first_scheduled_run", "first_api_run", "mcp_installed"]),
+ { progress: completedProgress, credentialUnlocked: false },
);
+ expect(
+ within(screen.getByRole("region", { name: "Keep going" })).getByText(
+ "3 steps",
+ ),
+ ).toBeTruthy();
});
-it("attests the clicked community row and never offers a client control on server rows", () => {
+it("uses the community ring as the attest control and keeps links enabled while pending", () => {
const props = renderTrack(track([]));
- const keepGoing = screen.getByRole("region", { name: "Keep going" });
- expect(within(keepGoing).queryByRole("button")).toBeNull();
- fireEvent.click(screen.getAllByRole("button", { name: "Mark done" })[1]!);
+ const ring = screen.getByRole("button", {
+ name: "Mark Join the Discord done",
+ });
+ fireEvent.click(ring);
expect(props.onAttest).toHaveBeenCalledWith("discord_joined");
- fireEvent.click(screen.getByRole("button", { name: "Hide for now" }));
- expect(props.onDismiss).toHaveBeenCalledOnce();
+ expect(screen.queryByText("Mark done")).toBeNull();
+ expect(screen.queryByText("Hide for now")).toBeNull();
+
cleanup();
const pending = renderTrack(track([]), { isPending: true });
- fireEvent.click(screen.getAllByRole("button", { name: "Mark done" })[0]!);
- fireEvent.click(screen.getByRole("button", { name: "Hide for now" }));
+ const pendingRing = screen.getByRole("button", {
+ name: "Mark Star Skyvern on GitHub done",
+ });
+ expect(pendingRing.getAttribute("aria-disabled")).toBe("true");
+ expect(pendingRing.getAttribute("aria-busy")).toBe("true");
+ fireEvent.click(pendingRing);
expect(pending.onAttest).not.toHaveBeenCalled();
- expect(pending.onDismiss).not.toHaveBeenCalled();
+ expect(
+ screen
+ .getAllByRole("button")
+ .filter((button) => button.hasAttribute("aria-disabled"))
+ .every((button) =>
+ button.getAttribute("aria-label")?.startsWith("Mark "),
+ ),
+ ).toBe(true);
+ for (const link of screen.getAllByRole("link")) {
+ expect(link.hasAttribute("aria-disabled")).toBe(false);
+ expect(link.className).not.toContain("pointer-events-none");
+ expect(link.className).not.toContain("opacity-");
+ }
+});
+
+it("replaces a completed community ring with the done badge", () => {
+ renderTrack(track(["github_starred"]));
+ const completedRow = screen.getByText("Star Skyvern on GitHub").closest("li");
+ expect(completedRow).not.toBeNull();
+ expect(
+ within(completedRow!).queryByRole("button", { name: /Mark .* done/ }),
+ ).toBeNull();
+ expect(completedRow!.querySelector('[aria-hidden="true"] svg')).toBeTruthy();
+
+ const incompleteRow = screen.getByText("Join the Discord").closest("li");
+ expect(incompleteRow).not.toBeNull();
+ expect(
+ within(incompleteRow!).getByRole("button", {
+ name: "Mark Join the Discord done",
+ }),
+ ).toBeTruthy();
+ expect(
+ within(incompleteRow!).getByRole("link", {
+ name: /Join Discord.*opens in new tab/,
+ }),
+ ).toBeTruthy();
+});
+
+it("keeps the progress live region mounted while idle", () => {
+ renderTrack(track([]));
+ const liveRegion = document.querySelector('[aria-live="polite"]');
+ expect(liveRegion).not.toBeNull();
+ expect(liveRegion?.textContent).toBe("");
+});
+
+it("keeps only Resume in the dismissed state", () => {
+ const value = { ...track([]), state: "dismissed" as const };
+ const props = renderTrack(value);
+ const resume = screen.getByRole("button", { name: "Resume" });
+ expect(screen.getAllByRole("button")).toHaveLength(1);
+ expect(screen.queryByRole("list")).toBeNull();
+ fireEvent.click(resume);
+ expect(props.onRestore).toHaveBeenCalledOnce();
});
diff --git a/skyvern-frontend/src/components/onboarding/GettingStartedTrack.tsx b/skyvern-frontend/src/components/onboarding/GettingStartedTrack.tsx
index 62471522d..a009a64c1 100644
--- a/skyvern-frontend/src/components/onboarding/GettingStartedTrack.tsx
+++ b/skyvern-frontend/src/components/onboarding/GettingStartedTrack.tsx
@@ -1,12 +1,13 @@
-import { ExternalLinkIcon, LockClosedIcon } from "@radix-ui/react-icons";
+import {
+ ArrowRightIcon,
+ CheckIcon,
+ ChevronRightIcon,
+ ExternalLinkIcon,
+ LockClosedIcon,
+} from "@radix-ui/react-icons";
+import { useState, type ReactNode } from "react";
import { Link } from "react-router-dom";
-import {
- PendingIcon,
- ProgressSegments,
- StepDot,
- type StepState,
-} from "@/components/onboarding/OnboardingProgressBand";
import { Button } from "@/components/ui/button";
import {
countedTrackItems,
@@ -27,6 +28,14 @@ import {
X_URL,
} from "@/util/externalLinks";
+type FirstAgentKey =
+ | "account_created"
+ | "first_agent_created"
+ | "first_successful_run";
+type FirstAgentProgress = {
+ first_agent_created: string | null;
+ first_successful_run: string | null;
+};
type RowLink = { label: string; to: string } | { label: string; href: string };
type RowDefinition = {
title: string;
@@ -34,23 +43,49 @@ type RowDefinition = {
links: RowLink[];
howItWorks?: string;
};
-type RowState = StepState | "locked";
+type RowState = "complete" | "active" | "upcoming" | "locked";
type GettingStartedTrackProps = {
track: OnboardingTrackV1;
credentialUnlocked: boolean;
intent: string | null;
+ progress: FirstAgentProgress | null;
onAttest: (key: TrackKey) => void;
- onDismiss: () => void;
onRestore: () => void;
isPending: boolean;
- rowDetails?: Partial<Record<TrackKey, React.ReactNode>>;
+ rowDetails?: Partial<Record<TrackKey, ReactNode>>;
};
+const firstAgentSteps: ReadonlyArray<{
+ key: FirstAgentKey;
+ title: string;
+ action?: RowLink;
+ howItWorks?: string;
+}> = [
+ { key: "account_created", title: "Account created" },
+ {
+ key: "first_agent_created",
+ title: "Create your first agent",
+ action: {
+ label: "Describe your first agent",
+ to: "/discover?focus=prompt",
+ },
+ howItWorks:
+ "https://www.skyvern.com/docs/cloud/building-agents/build-an-agent",
+ },
+ {
+ key: "first_successful_run",
+ title: "Run your first agent",
+ action: { label: "Run agent", to: "/agents" },
+ howItWorks:
+ "https://www.skyvern.com/docs/cloud/building-agents/run-an-agent",
+ },
+];
+
const rowDefinitions: Record<TrackKey, RowDefinition> = {
second_agent_run: {
title: "Run a second agent",
- why: "You finished your first workflow.",
- links: [{ label: "Run another workflow…", to: "/agents" }],
+ why: "You finished your first agent. Complete one more before the offer ends to earn your bonus.",
+ links: [{ label: "Run another agent", to: "/agents" }],
},
first_scheduled_run: {
title: "Run your agent automatically",
@@ -117,78 +152,251 @@ const communityOrder: readonly TrackKey[] = [
"social_followed",
];
+const rowClassName =
+ "grid grid-cols-[22px_1fr] items-start gap-3.5 border-b border-neutral-200 px-1 py-3 last:border-b-0 dark:border-white/[0.06] sm:grid-cols-[22px_minmax(0,1fr)_auto] sm:items-center";
+const titleClassName =
+ "text-sm font-medium leading-5 text-neutral-900 dark:text-neutral-50";
+const mutedTitleClassName =
+ "text-sm font-medium leading-5 text-neutral-500 dark:text-neutral-400";
+const descriptionClassName =
+ "mt-px text-xs leading-4 text-neutral-600 dark:text-neutral-400";
+const mutedDescriptionClassName =
+ "mt-px text-xs leading-4 text-neutral-500 dark:text-neutral-400";
+const howItWorksClassName =
+ "rounded-sm text-neutral-500 underline decoration-neutral-300 underline-offset-[3px] hover:text-neutral-700 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring dark:text-neutral-400 dark:decoration-white/[0.18] dark:hover:text-neutral-200";
+const actionBase =
+ "inline-flex h-8 shrink-0 items-center rounded-md text-[13px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring sm:whitespace-nowrap";
+const filledAction = `${actionBase} gap-1.5 bg-cta px-3 font-semibold text-cta-foreground shadow-[0_1px_2px_rgba(0,0,0,0.3)] hover:bg-cta-hover`;
+const quietAction = `${actionBase} gap-[5px] px-1.5 font-medium text-neutral-700 hover:text-neutral-950 dark:text-neutral-300 dark:hover:text-neutral-50`;
+const upgradeAction = `${actionBase} gap-[5px] px-1.5 font-medium text-sky-700 hover:text-sky-800 dark:text-sky-300 dark:hover:text-sky-200`;
+
function keepGoingOrder(intent: string | null): TrackKey[] {
const first = intentFirstRow[intent ?? ""] ?? "first_scheduled_run";
return [first, ...productionOrder.filter((key) => key !== first)];
}
-const quietButtonClassName =
- "h-11 touch-manipulation text-muted-foreground hover:text-foreground";
-const quietLinkClassName =
- "inline-flex min-h-11 touch-manipulation items-center text-xs text-muted-foreground underline-offset-4 hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring";
+function formatDate(completedAt: string): string {
+ return new Date(completedAt).toLocaleDateString(undefined, {
+ month: "short",
+ day: "numeric",
+ });
+}
-function RowLinkButton({
- link,
- primary,
- isPending,
-}: {
- link: RowLink;
- primary: boolean;
- isPending: boolean;
-}) {
- const variant = isPending ? "disabled" : primary ? "default" : "outline";
+function ProgressBar({ done, total }: { done: number; total: number }) {
return (
- <Button asChild variant={variant} className="h-11 touch-manipulation">
- {"href" in link ? (
- <a href={link.href} target="_blank" rel="noopener noreferrer">
- {link.label}
- <ExternalLinkIcon aria-hidden="true" className="ml-2 size-4" />
- </a>
- ) : (
- <Link to={link.to}>{link.label}</Link>
- )}
- </Button>
+ <div
+ role="progressbar"
+ aria-label="Getting started progress"
+ aria-valuemin={0}
+ aria-valuemax={total}
+ aria-valuenow={done}
+ className="flex w-full gap-1"
+ >
+ {Array.from({ length: total }, (_, index) => (
+ <span
+ key={index}
+ aria-hidden="true"
+ className={`h-[3px] flex-1 rounded-full ${
+ index < done
+ ? "bg-sky-600 dark:bg-sky-400"
+ : index === done
+ ? "bg-sky-600/35 dark:bg-sky-400/35"
+ : "bg-neutral-200 dark:bg-white/10"
+ }`}
+ />
+ ))}
+ </div>
);
}
-function RowBullet({
- state,
- index,
-}: {
- state: RowState;
- index: number | null;
-}) {
- if (index === null) {
+type TrackBadgeProps =
+ | { kind: "num" | "next"; number: number }
+ | { kind: "done" | "lock" }
+ | {
+ kind: "ring";
+ title: string;
+ isPending: boolean;
+ onAttest: () => void;
+ };
+
+function TrackBadge(props: TrackBadgeProps) {
+ const base =
+ "mt-px flex size-[22px] shrink-0 items-center justify-center rounded-full text-[11px] font-semibold tabular-nums sm:mt-0";
+ if (props.kind === "done") {
return (
- <span
- aria-hidden="true"
- className={`flex size-6 shrink-0 items-center justify-center rounded-full text-xs font-semibold ${
- state === "complete"
- ? "bg-badge-success text-foreground"
- : "border border-border text-muted-foreground"
- }`}
- >
- {state === "complete" ? "✓" : "•"}
+ <span aria-hidden="true" className={`${base} bg-green-600 text-white`}>
+ <CheckIcon className="size-3.5" />
</span>
);
}
- if (state === "locked") {
+ if (props.kind === "lock") {
return (
<span
aria-hidden="true"
- className="flex size-6 shrink-0 items-center justify-center rounded-full border border-border text-muted-foreground"
+ className={`${base} border border-neutral-300 text-neutral-500 dark:border-white/10`}
>
<LockClosedIcon className="size-3" />
</span>
);
}
- return <StepDot state={state} index={index} />;
+ if (props.kind === "ring") {
+ return (
+ <button
+ type="button"
+ aria-label={`Mark ${props.title} done`}
+ aria-disabled={props.isPending}
+ aria-busy={props.isPending}
+ className="-m-[11px] flex size-11 cursor-pointer touch-manipulation items-center justify-center rounded-full focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring sm:-m-[5px] sm:size-8 hover:[&>span]:border-neutral-700 dark:hover:[&>span]:border-white/60"
+ onClick={() => {
+ if (!props.isPending) props.onAttest();
+ }}
+ >
+ <span
+ aria-hidden="true"
+ className={`${base} border border-neutral-500 text-neutral-500 dark:border-white/40 ${
+ props.isPending
+ ? "animate-pulse opacity-60 motion-reduce:animate-none"
+ : ""
+ }`}
+ />
+ </button>
+ );
+ }
+ return (
+ <span
+ aria-hidden="true"
+ className={`${base} border ${
+ props.kind === "next"
+ ? "border-sky-500 text-sky-700 shadow-[0_0_0_3px_rgba(56,189,248,0.12)] dark:border-sky-400 dark:text-sky-300"
+ : "border-neutral-300 text-neutral-600 dark:border-white/10 dark:text-neutral-400"
+ }`}
+ >
+ {"number" in props ? props.number : null}
+ </span>
+ );
+}
+
+function TrackAction({ link, primary }: { link: RowLink; primary: boolean }) {
+ const className = primary ? filledAction : quietAction;
+ const iconClassName = primary
+ ? "size-3.5"
+ : "size-3.5 text-neutral-500 dark:text-neutral-400";
+ return "href" in link ? (
+ <a
+ href={link.href}
+ target="_blank"
+ rel="noopener noreferrer"
+ className={className}
+ >
+ {link.label}
+ <ExternalLinkIcon aria-hidden="true" className={iconClassName} />
+ <span className="sr-only"> (opens in new tab)</span>
+ </a>
+ ) : (
+ <Link to={link.to} className={className}>
+ {link.label}
+ <ArrowRightIcon aria-hidden="true" className={iconClassName} />
+ </Link>
+ );
+}
+
+function RowBadge({
+ item,
+ index,
+ state,
+ isPending,
+ onAttest,
+}: {
+ item: OnboardingTrackItemV1;
+ index: number | null;
+ state: RowState;
+ isPending: boolean;
+ onAttest: (key: TrackKey) => void;
+}) {
+ if (state === "complete") return <TrackBadge kind="done" />;
+ if (state === "locked") return <TrackBadge kind="lock" />;
+ if (SELF_ATTESTED_KEYS.has(item.key)) {
+ return (
+ <TrackBadge
+ kind="ring"
+ title={rowDefinitions[item.key].title}
+ isPending={isPending}
+ onAttest={() => onAttest(item.key)}
+ />
+ );
+ }
+ return (
+ <TrackBadge
+ kind={state === "active" ? "next" : "num"}
+ number={index ?? 0}
+ />
+ );
+}
+
+function FirstAgentRow({
+ step,
+ index,
+ state,
+ completedAt,
+ primary,
+}: {
+ step: (typeof firstAgentSteps)[number];
+ index: number;
+ state: Exclude<RowState, "locked">;
+ completedAt: string | null;
+ primary: boolean;
+}) {
+ const isDone = state === "complete";
+ return (
+ <li className={rowClassName}>
+ {isDone ? (
+ <TrackBadge kind="done" />
+ ) : (
+ <TrackBadge kind={state === "active" ? "next" : "num"} number={index} />
+ )}
+ <div className="min-w-0">
+ <p className={isDone ? mutedTitleClassName : titleClassName}>
+ <span className="sr-only">
+ {isDone
+ ? "Complete: "
+ : state === "active"
+ ? "Current step: "
+ : "Upcoming step: "}
+ </span>
+ {step.title}
+ </p>
+ {isDone && completedAt ? (
+ <p className={mutedDescriptionClassName}>
+ Done <time dateTime={completedAt}>{formatDate(completedAt)}</time>
+ </p>
+ ) : !isDone && step.howItWorks ? (
+ <p className={descriptionClassName}>
+ <a
+ href={step.howItWorks}
+ target="_blank"
+ rel="noopener noreferrer"
+ className={howItWorksClassName}
+ >
+ How it works
+ <span className="sr-only"> (opens in new tab)</span>
+ </a>
+ </p>
+ ) : null}
+ </div>
+ {!isDone && step.action ? (
+ <div className="col-start-2 flex flex-wrap items-center sm:col-start-auto sm:justify-end">
+ <TrackAction link={step.action} primary={primary} />
+ </div>
+ ) : null}
+ </li>
+ );
}
function TrackRow({
item,
index,
state,
+ primary,
onAttest,
isPending,
detail,
@@ -196,23 +404,26 @@ function TrackRow({
item: OnboardingTrackItemV1;
index: number | null;
state: RowState;
+ primary: boolean;
onAttest: (key: TrackKey) => void;
isPending: boolean;
- detail?: React.ReactNode;
+ detail?: ReactNode;
}) {
const definition = rowDefinitions[item.key];
const isDone = state === "complete";
const isLocked = state === "locked";
return (
- <li className="grid min-h-11 gap-3 rounded-md border border-border/70 bg-background/70 px-4 py-3 text-sm sm:grid-cols-[auto_1fr_auto] sm:items-center">
- <RowBullet state={state} index={index} />
+ <li className={rowClassName}>
+ <RowBadge
+ item={item}
+ index={index}
+ state={state}
+ isPending={isPending}
+ onAttest={onAttest}
+ />
<div className="min-w-0">
<p
- className={
- isDone || isLocked
- ? "text-muted-foreground"
- : "font-medium text-foreground"
- }
+ className={isDone || isLocked ? mutedTitleClassName : titleClassName}
>
<span className="sr-only">
{isDone
@@ -225,66 +436,60 @@ function TrackRow({
</span>
{definition.title}
</p>
- <p className="text-xs text-muted-foreground">
+ <p
+ className={
+ isDone || isLocked
+ ? mutedDescriptionClassName
+ : descriptionClassName
+ }
+ >
{item.completed_at !== null ? (
<>
Done{" "}
<time dateTime={item.completed_at}>
- {new Date(item.completed_at).toLocaleDateString(undefined, {
- month: "short",
- day: "numeric",
- })}
+ {formatDate(item.completed_at)}
</time>
</>
) : isLocked ? (
"Available on Hobby and up"
) : (
- definition.why
+ <>
+ {definition.why}
+ {definition.howItWorks ? (
+ <>
+ {" "}
+ <a
+ href={definition.howItWorks}
+ target="_blank"
+ rel="noopener noreferrer"
+ className={howItWorksClassName}
+ >
+ How it works
+ <span className="sr-only"> (opens in new tab)</span>
+ </a>
+ </>
+ ) : null}
+ </>
)}
</p>
- {isLocked ? null : detail}
+ {detail}
</div>
{isDone ? null : isLocked ? (
- <div className="flex items-center sm:justify-end">
- <Button asChild variant="outline" className="h-11 touch-manipulation">
- <Link to="/billing">Upgrade</Link>
- </Button>
+ <div className="col-start-2 flex items-center sm:col-start-auto sm:justify-end">
+ <Link to="/billing" className={upgradeAction}>
+ Upgrade
+ <ArrowRightIcon aria-hidden="true" className="size-3.5" />
+ </Link>
</div>
) : (
- <div className="flex flex-wrap items-center gap-2 sm:justify-end">
+ <div className="col-start-2 flex flex-wrap items-center gap-1 sm:col-start-auto sm:justify-end">
{definition.links.map((link, linkIndex) => (
- <RowLinkButton
+ <TrackAction
key={link.label}
link={link}
- primary={state === "active" && linkIndex === 0}
- isPending={isPending}
+ primary={primary && linkIndex === 0}
/>
))}
- {definition.howItWorks ? (
- <a
- href={definition.howItWorks}
- target="_blank"
- rel="noopener noreferrer"
- className={quietLinkClassName}
- >
- How it works
- </a>
- ) : null}
- {SELF_ATTESTED_KEYS.has(item.key) ? (
- <Button
- type="button"
- variant={isPending ? "disabled" : "ghost"}
- className={quietButtonClassName}
- aria-disabled={isPending}
- aria-busy={isPending}
- onClick={() => {
- if (!isPending) onAttest(item.key);
- }}
- >
- {isPending ? <PendingIcon /> : null}
- Mark done
- </Button>
- ) : null}
</div>
)}
</li>
@@ -293,17 +498,24 @@ function TrackRow({
function TrackGroup({
label,
+ meta,
children,
}: {
label: string;
- children: React.ReactNode;
+ meta: string;
+ children: ReactNode;
}) {
return (
- <section aria-label={label} className="space-y-2">
- <h2 className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">
- {label}
- </h2>
- <ol className="space-y-2">{children}</ol>
+ <section aria-label={label}>
+ <div className="flex items-baseline justify-between pb-1">
+ <h2 className="text-[11px] font-semibold uppercase tracking-[0.06em] text-neutral-500 dark:text-neutral-400">
+ {label}
+ </h2>
+ <span className="text-xs text-neutral-500 dark:text-neutral-400">
+ {meta}
+ </span>
+ </div>
+ {children}
</section>
);
}
@@ -312,16 +524,17 @@ function GettingStartedTrack({
track,
credentialUnlocked,
intent,
+ progress,
onAttest,
- onDismiss,
onRestore,
isPending,
rowDetails,
}: GettingStartedTrackProps) {
+ const [firstAgentExpanded, setFirstAgentExpanded] = useState(false);
const heading = (
<h1
id="getting-started-heading"
- className="text-2xl font-semibold tracking-tight"
+ className="text-2xl font-semibold tracking-[-0.02em]"
>
Getting started
</h1>
@@ -356,89 +569,183 @@ function GettingStartedTrack({
const byKey = new Map(track.items.map((item) => [item.key, item]));
const rowsFor = (keys: readonly TrackKey[]) =>
keys.flatMap((key) => byKey.get(key) ?? []);
- const keepGoing = rowsFor([SECOND_AGENT_KEY, ...keepGoingOrder(intent)]);
+ const orderedKeepGoing = rowsFor([
+ SECOND_AGENT_KEY,
+ ...keepGoingOrder(intent),
+ ]);
+ const keepGoing = credentialUnlocked
+ ? orderedKeepGoing
+ : [
+ ...orderedKeepGoing.filter((row) => row.key !== "credential_saved"),
+ ...orderedKeepGoing.filter((row) => row.key === "credential_saved"),
+ ];
const community = rowsFor(communityOrder);
const isLocked = (item: OnboardingTrackItemV1) =>
item.key === "credential_saved" && !credentialUnlocked;
const counted = countedTrackItems(track, credentialUnlocked);
- const done = counted.filter((row) => row.completed_at !== null).length;
- const currentKey = keepGoing.find(
+ // Null progress = first-agent data unavailable: omit the group, count track rows only.
+ const hasProgress = progress !== null;
+ const firstAgentCreatedAt = progress?.first_agent_created ?? null;
+ const firstSuccessfulRunAt = progress?.first_successful_run ?? null;
+ const firstAgentCreated = firstAgentCreatedAt !== null;
+ const firstSuccessfulRun = firstSuccessfulRunAt !== null;
+ const firstAgentComplete = firstAgentCreated && firstSuccessfulRun;
+ const firstAgentCurrentKey: FirstAgentKey | null = !hasProgress
+ ? null
+ : !firstAgentCreated
+ ? "first_agent_created"
+ : !firstSuccessfulRun
+ ? "first_successful_run"
+ : null;
+ const keepGoingCurrentKey = keepGoing.find(
(row) => row.completed_at === null && !isLocked(row),
)?.key;
+ const primaryKey: FirstAgentKey | TrackKey | null =
+ firstAgentCurrentKey ?? keepGoingCurrentKey ?? null;
+ const countedDone = counted.filter((row) => row.completed_at !== null).length;
+ const done = hasProgress
+ ? 1 + Number(firstAgentCreated) + Number(firstSuccessfulRun) + countedDone
+ : countedDone;
+ const total = hasProgress ? 3 + counted.length : counted.length;
+ const keepGoingComplete = keepGoing.every((row) => row.completed_at !== null);
const stateOf = (row: OnboardingTrackItemV1): RowState =>
row.completed_at !== null
? "complete"
: isLocked(row)
? "locked"
- : row.key === currentKey
+ : row.key === primaryKey
? "active"
: "upcoming";
let position = 0;
- const numbered = (row: OnboardingTrackItemV1) =>
- isLocked(row) ? position : position++;
return (
<section
aria-labelledby="getting-started-heading"
aria-busy={isPending}
- className="mx-auto max-w-2xl space-y-6"
+ className="mx-auto max-w-2xl space-y-7"
>
- {isPending ? (
- <span className="sr-only" aria-live="polite">
- Saving your progress…
- </span>
- ) : null}
- <div className="flex flex-wrap items-start justify-between gap-3">
- <div>
+ <span className="sr-only" aria-live="polite">
+ {isPending ? "Saving your progress…" : null}
+ </span>
+ <header className="space-y-3">
+ <div className="flex items-baseline justify-between gap-4">
{heading}
- <p className="mt-1 text-sm text-muted-foreground">
+ <p className="text-[13px] tabular-nums text-muted-foreground">
<span className="sr-only">Progress: </span>
- {done} of {counted.length} complete
+ {done} of {total} done
</p>
</div>
- <Button
- type="button"
- variant={isPending ? "disabled" : "ghost"}
- className={quietButtonClassName}
- aria-disabled={isPending}
- aria-busy={isPending}
- onClick={() => {
- if (!isPending) onDismiss();
- }}
+ <ProgressBar done={done} total={total} />
+ </header>
+
+ {hasProgress ? (
+ <TrackGroup
+ label="First agent"
+ meta={firstAgentComplete && !firstAgentExpanded ? "Done" : "3 steps"}
>
- Hide for now
- </Button>
- </div>
- <ProgressSegments
- completedSteps={done}
- totalSteps={counted.length}
- label="Getting started progress"
- />
- <TrackGroup label="Keep going">
- {keepGoing.map((row) => (
- <TrackRow
- key={row.key}
- item={row}
- index={numbered(row)}
- state={stateOf(row)}
- onAttest={onAttest}
- isPending={isPending}
- detail={rowDetails?.[row.key]}
- />
- ))}
+ {firstAgentComplete ? (
+ <div className="grid grid-cols-[22px_1fr_auto] items-start gap-3.5 border-b border-neutral-200 px-1 py-2.5 dark:border-white/[0.06] sm:items-center">
+ <TrackBadge kind="done" />
+ <p className="min-w-0">
+ <span className="text-sm font-medium text-neutral-700 dark:text-neutral-200">
+ First agent ready
+ </span>
+ <span className="text-xs text-neutral-500 dark:text-neutral-400">
+ {" "}
+ · Account, first agent, first run ·{" "}
+ {firstSuccessfulRunAt
+ ? formatDate(firstSuccessfulRunAt)
+ : null}
+ </span>
+ </p>
+ <button
+ type="button"
+ aria-expanded={firstAgentExpanded}
+ aria-controls="first-agent-steps"
+ aria-label={`${firstAgentExpanded ? "Hide" : "Show"} first agent steps`}
+ className="-my-1.5 flex size-11 touch-manipulation items-center justify-center rounded-md text-neutral-500 hover:text-neutral-700 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring dark:text-neutral-400 dark:hover:text-neutral-200 sm:my-0 sm:size-8"
+ onClick={() => setFirstAgentExpanded((expanded) => !expanded)}
+ >
+ <ChevronRightIcon
+ aria-hidden="true"
+ className={`size-4 transition-transform motion-reduce:transition-none ${
+ firstAgentExpanded ? "rotate-90" : ""
+ }`}
+ />
+ </button>
+ </div>
+ ) : null}
+ <ol
+ id="first-agent-steps"
+ hidden={firstAgentComplete && !firstAgentExpanded}
+ >
+ {!firstAgentComplete || firstAgentExpanded
+ ? firstAgentSteps.map((step, index) => {
+ const completedAt =
+ step.key === "account_created"
+ ? null
+ : (progress?.[step.key] ?? null);
+ const stepComplete =
+ step.key === "account_created" || completedAt !== null;
+ const state: Exclude<RowState, "locked"> = stepComplete
+ ? "complete"
+ : step.key === firstAgentCurrentKey
+ ? "active"
+ : "upcoming";
+ return (
+ <FirstAgentRow
+ key={step.key}
+ step={step}
+ index={index + 1}
+ state={state}
+ completedAt={completedAt}
+ primary={step.key === primaryKey}
+ />
+ );
+ })
+ : null}
+ </ol>
+ </TrackGroup>
+ ) : null}
+
+ <TrackGroup
+ label="Keep going"
+ meta={keepGoingComplete ? "Done" : `${counted.length} steps`}
+ >
+ <ol>
+ {keepGoing.map((row) => {
+ const index = isLocked(row) ? null : ++position;
+ return (
+ <TrackRow
+ key={row.key}
+ item={row}
+ index={index}
+ state={stateOf(row)}
+ primary={row.key === primaryKey}
+ onAttest={onAttest}
+ isPending={isPending}
+ detail={rowDetails?.[row.key]}
+ />
+ );
+ })}
+ </ol>
</TrackGroup>
- <TrackGroup label="Stay in the loop">
- {community.map((row) => (
- <TrackRow
- key={row.key}
- item={row}
- index={null}
- state={row.completed_at !== null ? "complete" : "upcoming"}
- onAttest={onAttest}
- isPending={isPending}
- detail={rowDetails?.[row.key]}
- />
- ))}
+
+ <TrackGroup label="Stay in the loop" meta="Optional">
+ <ol>
+ {community.map((row) => (
+ <TrackRow
+ key={row.key}
+ item={row}
+ index={null}
+ state={row.completed_at !== null ? "complete" : "upcoming"}
+ primary={false}
+ onAttest={onAttest}
+ isPending={isPending}
+ detail={rowDetails?.[row.key]}
+ />
+ ))}
+ </ol>
</TrackGroup>
</section>
);
diff --git a/skyvern-frontend/src/routes/discover/useOnboardingProgress.test.tsx b/skyvern-frontend/src/routes/discover/useOnboardingProgress.test.tsx
index 70147d748..573304b20 100644
--- a/skyvern-frontend/src/routes/discover/useOnboardingProgress.test.tsx
+++ b/skyvern-frontend/src/routes/discover/useOnboardingProgress.test.tsx
@@ -8,12 +8,14 @@ import { act, renderHook, waitFor } from "@testing-library/react";
import { beforeEach, expect, it, vi } from "vitest";
const mocks = vi.hoisted<{
get: ReturnType<typeof vi.fn>;
- flag: boolean | undefined;
+ flags: Record<string, boolean | undefined>;
+ useFeatureFlag: ReturnType<typeof vi.fn<(name: string) => void>>;
org: string | undefined;
user: string | undefined;
}>(() => ({
get: vi.fn(),
- flag: true,
+ flags: {},
+ useFeatureFlag: vi.fn<(name: string) => void>(),
org: "org-test",
user: "user-test",
}));
@@ -23,7 +25,12 @@ vi.mock("@/api/AxiosClient", () => ({
vi.mock("@/hooks/useCredentialGetter", () => ({
useCredentialGetter: () => () => Promise.resolve("test-token"),
}));
-vi.mock("@/hooks/useFeatureFlag", () => ({ useFeatureFlag: () => mocks.flag }));
+vi.mock("@/hooks/useFeatureFlag", () => ({
+ useFeatureFlag: (name: string) => {
+ mocks.useFeatureFlag(name);
+ return mocks.flags[name];
+ },
+}));
vi.mock("@/hooks/useUser", () => ({
useUser: () => ({
get: () => (mocks.user === undefined ? null : { id: mocks.user }),
@@ -35,6 +42,10 @@ vi.mock("@/store/ActiveOrgContext", async () => ({
)),
useActiveOrgId: () => mocks.org,
}));
+import {
+ ONBOARDING_PROGRESS_FLAG,
+ ONBOARDING_TRACK_FLAG,
+} from "@/util/featureFlags";
import { useOnboardingProgress } from "./useOnboardingProgress";
const validPayload = () => ({
version: "onboarding_progress_v1",
@@ -47,6 +58,13 @@ const validPayload = () => ({
{ key: "first_successful_run", completed_at: null },
],
});
+function deferred<T>() {
+ let resolve!: (value: T) => void;
+ const promise = new Promise<T>((resolvePromise) => {
+ resolve = resolvePromise;
+ });
+ return { promise, resolve };
+}
function renderProgress(client = new QueryClient()) {
const wrapper = ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={client}>{children}</QueryClientProvider>
@@ -56,7 +74,10 @@ function renderProgress(client = new QueryClient()) {
}
beforeEach(() => {
vi.clearAllMocks();
- mocks.flag = true;
+ mocks.flags = {
+ [ONBOARDING_TRACK_FLAG]: true,
+ [ONBOARDING_PROGRESS_FLAG]: true,
+ };
mocks.org = "org-test";
mocks.user = "user-test";
});
@@ -66,7 +87,10 @@ it.each([
[true, undefined, "user-test"],
[true, "org-test", undefined],
])("does not GET when onboarding progress is gated", (flag, org, user) => {
- mocks.flag = flag;
+ mocks.flags = {
+ [ONBOARDING_TRACK_FLAG]: flag,
+ [ONBOARDING_PROGRESS_FLAG]: flag,
+ };
mocks.org = org;
mocks.user = user;
renderProgress();
@@ -76,7 +100,10 @@ it.each([
[validPayload(), "active"],
[{ ...validPayload(), version: "onboarding_progress_v0" }, null],
])("parses valid V1 and hides malformed versions", async (data, expected) => {
- mocks.flag = true;
+ mocks.flags = {
+ [ONBOARDING_TRACK_FLAG]: true,
+ [ONBOARDING_PROGRESS_FLAG]: true,
+ };
mocks.org = "org-test";
mocks.user = "user-test";
mocks.get.mockResolvedValue({ data });
@@ -86,6 +113,73 @@ it.each([
expect(result.current.progress?.state ?? null).toBe(expected),
);
});
+it.each([
+ ["track", true, false],
+ ["progress", false, true],
+])("GETs under the %s flag alone", async (_, trackFlag, progressFlag) => {
+ mocks.flags = {
+ [ONBOARDING_TRACK_FLAG]: trackFlag,
+ [ONBOARDING_PROGRESS_FLAG]: progressFlag,
+ };
+ mocks.get.mockResolvedValue({ data: validPayload() });
+
+ const { result } = renderProgress();
+
+ await waitFor(() => expect(mocks.get).toHaveBeenCalledOnce());
+ await waitFor(() => expect(result.current.status).toBe("ready"));
+ expect(mocks.useFeatureFlag).toHaveBeenCalledWith(ONBOARDING_TRACK_FLAG);
+ expect(mocks.useFeatureFlag).toHaveBeenCalledWith(ONBOARDING_PROGRESS_FLAG);
+});
+it("reports disabled when both onboarding flags are off", () => {
+ mocks.flags = {
+ [ONBOARDING_TRACK_FLAG]: false,
+ [ONBOARDING_PROGRESS_FLAG]: false,
+ };
+
+ const { result } = renderProgress();
+
+ expect(mocks.get).not.toHaveBeenCalled();
+ expect(result.current.status).toBe("disabled");
+});
+it("reports loading with null progress until the GET resolves, then ready", async () => {
+ const pending = deferred<{ data: unknown }>();
+ mocks.get.mockReturnValue(pending.promise);
+
+ const { result } = renderProgress();
+
+ await waitFor(() => expect(mocks.get).toHaveBeenCalledOnce());
+ expect(result.current.status).toBe("loading");
+ expect(result.current.progress).toBeNull();
+
+ pending.resolve({ data: validPayload() });
+
+ await waitFor(() => expect(result.current.status).toBe("ready"));
+ expect(result.current.progress?.state).toBe("active");
+});
+it("reports an error with null progress after a 404", async () => {
+ mocks.get.mockRejectedValueOnce({ response: { status: 404 } });
+
+ const { result } = renderProgress();
+
+ await waitFor(() => expect(result.current.status).toBe("error"));
+ expect(result.current.progress).toBeNull();
+});
+it("keeps the last progress when a refetch fails", async () => {
+ mocks.get
+ .mockResolvedValueOnce({ data: validPayload() })
+ .mockRejectedValueOnce({ response: { status: 500 } });
+
+ const { result } = renderProgress();
+ await waitFor(() => expect(result.current.status).toBe("ready"));
+
+ await act(async () => {
+ await result.current.refetch();
+ });
+
+ expect(mocks.get).toHaveBeenCalledTimes(2);
+ expect(result.current.status).toBe("ready");
+ expect(result.current.progress).toEqual(validPayload());
+});
it("refetches fresh cached progress when Discover remounts", async () => {
const client = new QueryClient({
defaultOptions: {
@@ -125,7 +219,10 @@ it("refetches fresh cached progress when Discover remounts", async () => {
expect(secondMount.result.current.progress).toEqual(refreshedPayload);
});
it("isolates progress cache entries by authenticated user", async () => {
- mocks.flag = true;
+ mocks.flags = {
+ [ONBOARDING_TRACK_FLAG]: true,
+ [ONBOARDING_PROGRESS_FLAG]: true,
+ };
mocks.org = "org-test";
mocks.user = "user-a";
mocks.get.mockResolvedValue({ data: validPayload() });
diff --git a/skyvern-frontend/src/routes/discover/useOnboardingProgress.ts b/skyvern-frontend/src/routes/discover/useOnboardingProgress.ts
index 9f68bfb77..8b1a4ba7f 100644
--- a/skyvern-frontend/src/routes/discover/useOnboardingProgress.ts
+++ b/skyvern-frontend/src/routes/discover/useOnboardingProgress.ts
@@ -7,7 +7,10 @@ import {
getOrgScopedQueryKey,
useActiveOrgId,
} from "@/store/ActiveOrgContext";
-import { ONBOARDING_PROGRESS_FLAG } from "@/util/featureFlags";
+import {
+ ONBOARDING_PROGRESS_FLAG,
+ ONBOARDING_TRACK_FLAG,
+} from "@/util/featureFlags";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
type ProgressActionKey = "first_agent_created" | "first_successful_run";
type OnboardingProgressItemV1 = {
@@ -113,15 +116,17 @@ function useOnboardingProgress() {
const activeOrgId = useActiveOrgId();
const activeUserId = useUser().get()?.id;
const queryClient = useQueryClient();
+ const trackFlag = useFeatureFlag(ONBOARDING_TRACK_FLAG);
+ const progressFlag = useFeatureFlag(ONBOARDING_PROGRESS_FLAG);
+ const flagOn = trackFlag === true || progressFlag === true;
+ const flagOff = trackFlag === false && progressFlag === false;
const enabled =
- useFeatureFlag(ONBOARDING_PROGRESS_FLAG) === true &&
- activeOrgId !== undefined &&
- activeUserId !== undefined;
+ flagOn && activeOrgId !== undefined && activeUserId !== undefined;
const queryKey = getOrgScopedQueryKey(
["onboarding-progress", activeUserId],
getActiveOrgQueryKeyScope(activeOrgId),
);
- const { data, isError } = useQuery<OnboardingProgressV1 | null>({
+ const { data, isError, refetch } = useQuery<OnboardingProgressV1 | null>({
queryKey,
queryFn: async ({ signal }) => {
const client = await getClient(credentialGetter);
@@ -146,9 +151,22 @@ function useOnboardingProgress() {
},
onSuccess: () => queryClient.invalidateQueries({ queryKey, exact: true }),
});
+ // A failed refetch keeps the last good payload, so a transient error never resets the count.
+ const known = enabled && data !== undefined;
+ const status: "disabled" | "loading" | "error" | "ready" = !enabled
+ ? flagOff
+ ? "disabled"
+ : "loading"
+ : known
+ ? "ready"
+ : isError
+ ? "error"
+ : "loading";
return {
- progress: enabled && !isError ? (data ?? null) : null,
+ progress: known ? data : null,
+ status,
isPending,
+ refetch,
dismiss: () => mutate("dismiss"),
restore: () => mutate("restore"),
};
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.prose.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.prose.test.tsx
index 64da5c8e7..160c15775 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.prose.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.prose.test.tsx
@@ -242,6 +242,61 @@ describe("NarrativeView terminal prose", () => {
expect(container.querySelector(".rounded-xl")).toBeNull();
});
+ it("keeps the question treatment on an ask that carries recorded evidence", () => {
+ render(
+ <NarrativeView
+ turn={terminalTurn({
+ responseKind: "clarify",
+ responseType: "REPLY",
+ terminalMessage: "Which **login** should I use?",
+ terminalEnvelope: {
+ nextState: "awaiting_user_input",
+ renderedFromEnvelope: true,
+ runVerdict: null,
+ runDisplayReason: null,
+ },
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "The sign-in flow did not reach the expected page.",
+ },
+ })}
+ />,
+ );
+
+ // The ask reads as an ask, and the recorded outcome it followed survives.
+ expect(screen.getByTestId("copilot-detail-prose").className).toContain(
+ "border-l-2",
+ );
+ expect(screen.getByText("login", { selector: "strong" })).toBeTruthy();
+ expect(screen.getByText("Outcome not confirmed")).toBeTruthy();
+ });
+
+ it("leaves the ask untreated until the backend stamps the envelope", () => {
+ render(
+ <NarrativeView
+ turn={terminalTurn({
+ responseKind: "clarify",
+ responseType: "REPLY",
+ terminalMessage: "Which login should I use?",
+ terminalEnvelope: {
+ nextState: "awaiting_user_input",
+ renderedFromEnvelope: false,
+ runVerdict: null,
+ runDisplayReason: null,
+ },
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "The sign-in flow did not reach the expected page.",
+ },
+ })}
+ />,
+ );
+
+ expect(screen.getByTestId("copilot-detail-prose").className).toContain(
+ "text-foreground",
+ );
+ });
+
it("moves a run-level unconfirmed reason into its failed activity row", () => {
render(
<NarrativeView
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts
index 43c569df1..36efb939d 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts
@@ -1,16 +1,12 @@
import { describe, expect, it } from "vitest";
-import { getReviewGateVerdict } from "./cards/ReviewGateCard";
import { derivePhases } from "./copilotPhases";
import {
ActivityEntry,
- BlockState,
EMPTY_NARRATIVE,
TurnNarrativeState,
applyNarrativeEvent,
- computeTurnSummary,
condenseActivityEntries,
- effectiveMode,
humanizeJudgeText,
hydrateHistoryNarrative,
hydrateNarrativeFromPayload,
@@ -917,7 +913,6 @@ describe("applyNarrativeEvent — terminal", () => {
);
expect(s.responseType).toBe("ASK_QUESTION");
- expect(effectiveMode(s)).toBe("clarify");
});
it("preserves cancelled responses with drafts as response terminals", () => {
@@ -942,7 +937,6 @@ describe("applyNarrativeEvent — terminal", () => {
expect(s.terminal).toBe("response");
expect(s.draft?.blockCount).toBe(2);
expect(s.blocks.map((b) => b.state)).toEqual(["drafted", "drafted"]);
- expect(effectiveMode(s)).toBe("build");
});
it("response closes design even when design_end was never emitted (CORR-3)", () => {
@@ -970,74 +964,6 @@ describe("applyNarrativeEvent — terminal", () => {
});
});
-describe("effectiveMode", () => {
- it("reports build when classifier said unknown but blocks were drafted from empty prior", () => {
- const s: TurnNarrativeState = {
- ...EMPTY_NARRATIVE,
- draft: { blockCount: 2, blockLabels: ["a", "b"], summary: null },
- terminal: "response",
- };
- expect(effectiveMode(s)).toBe("build");
- });
-
- it("reports edit when prior_block_count > 0 and turn drafted blocks", () => {
- const s: TurnNarrativeState = {
- ...EMPTY_NARRATIVE,
- draft: { blockCount: 2, blockLabels: ["a", "b"], summary: null },
- terminal: "response",
- priorBlockCount: 2,
- };
- expect(effectiveMode(s)).toBe("edit");
- });
-
- it("reports clarify when classifier said draft_only but no blocks were drafted", () => {
- const s: TurnNarrativeState = {
- ...EMPTY_NARRATIVE,
- draft: null,
- terminal: "response",
- };
- expect(effectiveMode(s)).toBe("clarify");
- });
-
- it("derives docs_answer / diagnose / refuse from the response kind when there are no blocks", () => {
- for (const [responseKind, expected] of [
- ["answer", "docs_answer"],
- ["diagnose", "diagnose"],
- ["refuse", "refuse"],
- ] as const) {
- const s: TurnNarrativeState = {
- ...EMPTY_NARRATIVE,
- responseKind,
- terminal: "response",
- };
- expect(effectiveMode(s)).toBe(expected);
- }
- });
-
- it("reports clarify when backend classified the response as ASK_QUESTION", () => {
- const s: TurnNarrativeState = {
- ...EMPTY_NARRATIVE,
- responseType: "ASK_QUESTION",
- terminal: "response",
- };
- expect(effectiveMode(s)).toBe("clarify");
- });
-});
-
-const summaryBlock = (
- label: string,
- state: BlockState["state"] = "completed",
-): BlockState => ({
- workflowRunBlockId: `wrb_${label}`,
- label,
- blockType: "task",
- state,
- lastSeenIteration: 0,
- activity: [],
- startedAt: null,
- endedAt: null,
-});
-
const reproBlock = (label: string): Record<string, unknown> => ({
workflowRunBlockId: "",
label,
@@ -1087,33 +1013,6 @@ const reproClarifyPayload = (
...overrides,
});
-const buildTurn = (
- overrides: Partial<TurnNarrativeState> = {},
-): TurnNarrativeState => ({
- ...EMPTY_NARRATIVE,
- terminal: "response",
- ...overrides,
-});
-
-const draft3 = {
- blockCount: 3,
- blockLabels: ["block_one", "block_two", "block_three"],
- summary: null,
-};
-
-// What the backend publishes for a draft whose blocks all ran clean on current source.
-const testedFacts = {
- factsAvailable: true,
- authoredBlockCount: 3,
- matchingSourceBlockCount: 3,
- evaluationState: null,
- runId: "wr_1",
- runCompleted: true,
- terminalCause: null,
- blocksRunThisTurn: 3,
- ranCleanOnCurrentSource: true,
-} as const;
-
describe("hydrateNarrativeFromPayload — terminal adjudication fields", () => {
it("hydrates responseKind without inventing an authoring success stamp", () => {
const turn = hydrateNarrativeFromPayload(
@@ -1144,554 +1043,12 @@ describe("hydrateNarrativeFromPayload — terminal adjudication fields", () => {
});
});
-describe("computeTurnSummary — typed terminal adjudication", () => {
- it("renders the loop-guard clarify repro as needing input, not a green built-and-tested claim", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({ responseKind: "clarify" }),
- );
- expect(turn).toBeDefined();
- const summary = computeTurnSummary(turn!);
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it("renders non-build REPLY + not_demonstrated as Outcome not confirmed", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "REPLY",
- lastRunOutcome: {
- verdict: "not_demonstrated",
- displayReason: "The run never reached the target page.",
- },
- }),
- );
- expect(summary.headline).toBe("Outcome not confirmed");
- expect(summary.accent).toBe("warn");
- expect(summary.glyph).toBe("!");
- });
-
- it("suppresses the live turn warning for an interim last-run outcome", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "REPLY",
- lastRunOutcome: {
- verdict: "not_demonstrated",
- role: "interim_build_test",
- displayReason: "The workflow still needs its extraction block.",
- },
- }),
- );
-
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- });
-
- it("suppresses the live turn warning for an interim per-block outcome", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "REPLY",
- blocks: [
- {
- ...summaryBlock("open_search"),
- outcome: "not_demonstrated",
- outcomeRole: "interim_build_test",
- outcomeReason: "The workflow still needs its extraction block.",
- },
- ],
- }),
- );
-
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- });
-
- it("keeps an explicitly adjudicated outcome warning", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "REPLY",
- lastRunOutcome: {
- verdict: "not_demonstrated",
- role: "adjudicated",
- displayReason: "The goal was not demonstrated.",
- },
- }),
- );
-
- expect(summary.headline).toBe("Outcome not confirmed");
- expect(summary.accent).toBe("warn");
- });
-
- it("keeps the terminal envelope authoritative over interim live state", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "REPLY",
- terminalEnvelope: {
- runVerdict: "not_demonstrated",
- runDisplayReason: "The final run did not demonstrate the goal.",
- },
- lastRunOutcome: {
- verdict: "not_demonstrated",
- role: "interim_build_test",
- displayReason: "The workflow still needs its extraction block.",
- },
- blocks: [
- {
- ...summaryBlock("open_search"),
- outcome: "not_demonstrated",
- outcomeRole: "interim_build_test",
- },
- ],
- }),
- );
-
- expect(summary.headline).toBe("Outcome not confirmed");
- expect(summary.accent).toBe("warn");
- });
-
- it("uses hydrated not_demonstrated block outcomes when lastRunOutcome is absent", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({
- responseKind: "clarify",
- blocks: [
- {
- ...reproBlock("open_registry_find_registrant"),
- outcome: "demonstrated",
- },
- {
- ...reproBlock("search_jane_doe_credential_a"),
- outcome: "not_demonstrated",
- outcomeReason: "A verification challenge prevented confirmation.",
- },
- {
- ...reproBlock("expand_and_extract_certifications"),
- outcome: "demonstrated",
- },
- ],
- }),
- )!;
- expect(turn.lastRunOutcome).toBeNull();
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Outcome not confirmed");
- expect(summary.accent).toBe("warn");
- expect(summary.glyph).toBe("!");
- });
-
- it("keeps the Needs your input headline when response_type is ASK_QUESTION", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "ASK_QUESTION",
- lastRunOutcome: {
- verdict: "not_demonstrated",
- displayReason: "The run never reached the target page.",
- },
- }),
- );
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it("keeps the Needs your input headline for ASK_QUESTION even when hydrated blocks carry not_demonstrated", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({
- responseKind: "clarify",
- responseType: "ASK_QUESTION",
- blocks: [
- {
- ...reproBlock("open_registry_find_registrant"),
- outcome: "not_demonstrated",
- outcomeReason: "A verification challenge prevented confirmation.",
- },
- {
- ...reproBlock("search_jane_doe_credential_a"),
- outcome: "demonstrated",
- },
- {
- ...reproBlock("expand_and_extract_certifications"),
- outcome: "demonstrated",
- },
- ],
- }),
- )!;
- expect(turn.lastRunOutcome).toBeNull();
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it("treats build-kind ASK_QUESTION as an ask when no draft review is pending", () => {
- const turn = buildTurn({
- draft: draft3,
- proposalDisposition: "no_proposal",
- responseKind: "build",
- responseType: "ASK_QUESTION",
- });
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it("keeps review disposition precedence over build-kind ASK_QUESTION", () => {
- const turn = buildTurn({
- draft: draft3,
- proposalDisposition: "review_untested",
- responseKind: "build",
- responseType: "ASK_QUESTION",
- });
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Draft needs review");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("!");
- });
-
- it("keeps build-kind REPLY summary behavior unchanged", () => {
- const turn = buildTurn({
- draft: draft3,
- proposalDisposition: "no_proposal",
- responseKind: "build",
- responseType: "REPLY",
- });
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Built the workflow");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✓");
- });
-
- it("keeps legacy non-build behavior unchanged when responseType and verdict are absent", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- }),
- );
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it("keeps legacy non-build behavior unchanged when hydrated turns have neither signal", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({
- responseKind: "clarify",
- }),
- )!;
- expect(turn.lastRunOutcome).toBeNull();
- expect(
- turn.blocks.some((block) => block.outcome === "not_demonstrated"),
- ).toBe(false);
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it("keeps the factual stats line on an adjudicated clarify build turn", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({ responseKind: "clarify" }),
- )!;
- const summary = computeTurnSummary(turn);
- expect(summary.stats).toEqual(["15:02", "3 blocks ran", "3 new"]);
- });
-
- it("never claims re-tested edits on an adjudicated clarify edit turn", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({
- responseKind: "clarify",
- priorBlockCount: 2,
- }),
- )!;
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Needs your input");
- expect(summary.headline).not.toBe("Applied edits and re-tested");
- expect(summary.accent).not.toBe("ok");
- });
-
- it.each([
- ["clarify", "Needs your input"],
- ["recover", "Needs your input"],
- ["refuse", "Declined"],
- ["diagnose", "Answered"],
- ["answer", "Answered"],
- ] as const)(
- "maps non-build kind %s to %s with qa accent",
- (kind, headline) => {
- const summary = computeTurnSummary(buildTurn({ responseKind: kind }));
- expect(summary.headline).toBe(headline);
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- },
- );
-
- it("names the build without claiming it was tested when no coverage facts arrive", () => {
- const summary = computeTurnSummary(
- buildTurn({
- draft: draft3,
- proposalDisposition: "no_proposal",
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Built the workflow");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✓");
- });
-
- it("names an edit turn without claiming a re-test when no coverage facts arrive", () => {
- const summary = computeTurnSummary(
- buildTurn({
- draft: draft3,
- priorBlockCount: 2,
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Applied edits");
- expect(summary.accent).toBe("qa");
- });
-
- it("does not infer a completed run from a build response kind alone", () => {
- const summary = computeTurnSummary(buildTurn({ responseKind: "build" }));
- expect(summary.headline).toBe("Needs your input");
- });
-
- it("keeps the prose question heuristic without a run fact", () => {
- const summary = computeTurnSummary(
- buildTurn({
- draft: draft3,
- terminalMessage: "Could you provide feedback on the result?",
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Needs your input");
- });
-
- it("renders a clean completed build from its block lifecycle", () => {
- const summary = computeTurnSummary(
- buildTurn({
- draft: draft3,
- blocks: [
- summaryBlock("block_one"),
- summaryBlock("block_two"),
- summaryBlock("block_three"),
- ],
- proposalDisposition: "auto_applicable",
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Built the workflow");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✓");
- });
-
- it("renders a clean completed edit from its block lifecycle", () => {
- const summary = computeTurnSummary(
- buildTurn({
- draft: draft3,
- blocks: [
- summaryBlock("block_one"),
- summaryBlock("block_two"),
- summaryBlock("block_three"),
- ],
- priorBlockCount: 2,
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Applied edits");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✓");
- });
-
- it.each([
- [
- buildTurn({
- draft: draft3,
- proposalDisposition: "review_untested",
- responseKind: "build",
- }),
- "Draft needs review",
- ],
- [
- buildTurn({
- draft: draft3,
- proposalDisposition: "review_tested",
- responseKind: "build",
- }),
- // No facts back the tested framing, so the card states what it built and no more.
- "Built the workflow",
- ],
- ])(
- "keeps stopped or review-required states when there is no clean completed run (%#)",
- (turn, headline) => {
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe(headline);
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).not.toBe("✓");
- },
- );
-
- it("surfaces a tested proposal for review even when the turn ends in a question", () => {
- const askTurn = buildTurn({
- draft: draft3,
- proposalDisposition: "review_tested",
- turnFacts: testedFacts,
- responseKind: "clarify",
- responseType: "ASK_QUESTION",
- terminalMessage: "Is that output format okay?",
- });
-
- expect(computeTurnSummary(askTurn).headline).toBe(
- "Workflow ready for review",
- );
- expect(getReviewGateVerdict(askTurn, null)).toBe("tested");
- });
-
- it("a failed block still renders Run halted even with a verdict-authorized success", () => {
- const summary = computeTurnSummary(
- buildTurn({
- draft: draft3,
- blocks: [
- summaryBlock("block_one"),
- summaryBlock("block_two", "failed"),
- ],
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Run halted");
- expect(summary.accent).toBe("fail");
- expect(summary.glyph).toBe("✕");
- });
-
- it("cancelled with a reviewable draft still renders Stopped with a draft", () => {
- const summary = computeTurnSummary(
- buildTurn({
- cancelled: true,
- draft: draft3,
- proposalDisposition: "review_untested",
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Stopped with a draft");
- expect(summary.accent).toBe("qa");
- });
-
- it("legacy payload without adjudication renders via the unchanged inference chain", () => {
- const turn = hydrateNarrativeFromPayload(reproClarifyPayload())!;
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Built the workflow");
- expect(summary.accent).toBe("qa");
- expect(summary.stats).toEqual(["15:02", "3 blocks ran", "3 new"]);
- });
-});
-
-describe("computeTurnSummary — disposition-first reorder", () => {
- it("a pending untested draft outranks a non-build responseKind", () => {
- const turn = buildTurn({
- responseKind: "clarify",
- draft: draft3,
- proposalDisposition: "review_untested",
- });
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Draft needs review");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("!");
- });
-
- it("a pending tested draft outranks a non-build responseKind too", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- draft: draft3,
- proposalDisposition: "review_tested",
- turnFacts: testedFacts,
- }),
- );
- expect(summary.headline).toBe("Workflow ready for review");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("!");
- });
-
- it("fallback chain: an untested draft outranks needsInput text when responseKind is null", () => {
- const turn = buildTurn({
- draft: draft3,
- proposalDisposition: "review_untested",
- terminalMessage: "Could you provide the login details?",
- });
- expect(turn.responseKind).toBeNull();
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Draft needs review");
- });
-
- it("old payload (hydrated, no responseKind) still gets the draft-review reorder", () => {
- const turn = hydrateNarrativeFromPayload(
- reproClarifyPayload({ proposalDisposition: "review_untested" }),
- )!;
- expect(turn.responseKind).toBeNull();
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Draft needs review");
- });
-
- it("renames the pure-ask clarify headline to Needs your input", () => {
- const summary = computeTurnSummary(
- buildTurn({
- responseKind: "clarify",
- responseType: "ASK_QUESTION",
- }),
- );
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
- expect(summary.glyph).toBe("✦");
- });
-
- it.each([
- ["refuse", "Declined"],
- ["diagnose", "Answered"],
- ["answer", "Answered"],
- ] as const)(
- "leaves %s as %s under the default summary behavior",
- (kind, headline) => {
- const summary = computeTurnSummary(buildTurn({ responseKind: kind }));
- expect(summary.headline).toBe(headline);
- expect(summary.accent).toBe("qa");
- },
- );
-
- it("isStoppedWithDraft keeps absolute precedence", () => {
- const summary = computeTurnSummary(
- buildTurn({
- cancelled: true,
- draft: draft3,
- proposalDisposition: "review_untested",
- responseKind: "build",
- }),
- );
- expect(summary.headline).toBe("Stopped with a draft");
- expect(summary.accent).toBe("qa");
- });
-
- it("fallback needsInput renders Needs your input when no draft is pending", () => {
- const turn = buildTurn({
- terminalMessage: "Could you provide the login details?",
- });
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Needs your input");
- });
-});
-
describe("hydrateHistoryNarrative — persisted turn_outcome graft", () => {
it("grafts clarify from the adjacent turn_outcome onto a pre-fix payload", () => {
const turn = hydrateHistoryNarrative(reproClarifyPayload(), {
response_kind: "clarify",
})!;
expect(turn.responseKind).toBe("clarify");
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Needs your input");
- expect(summary.accent).toBe("qa");
});
it("keeps the payload's own responseKind over the graft", () => {
@@ -1702,14 +1059,11 @@ describe("hydrateHistoryNarrative — persisted turn_outcome graft", () => {
expect(turn.responseKind).toBe("refuse");
});
- it("renders grafted build-kind history via the legacy chain (no downgrade)", () => {
+ it("grafts build from the adjacent turn_outcome onto a pre-fix payload", () => {
const turn = hydrateHistoryNarrative(reproClarifyPayload(), {
response_kind: "build",
})!;
expect(turn.responseKind).toBe("build");
- const summary = computeTurnSummary(turn);
- expect(summary.headline).toBe("Built the workflow");
- expect(summary.accent).toBe("qa");
});
it("tolerates missing or unknown turn_outcome", () => {
@@ -1739,7 +1093,6 @@ describe("applyNarrativeEvent — terminal adjudication on live frames", () => {
}),
);
expect(s.responseKind).toBe("clarify");
- expect(computeTurnSummary(s).headline).toBe("Needs your input");
});
it("leaves both fields null on frames from an older backend", () => {
@@ -1857,32 +1210,6 @@ describe("a user stop renders as stopped, never as a failure", () => {
expect(block?.endedAt).not.toBeNull();
});
- it("does not treat a stopped block as a failure in the turn summary", () => {
- const summary = computeTurnSummary(
- buildTurn({
- cancelled: true,
- blocks: [
- {
- workflowRunBlockId: "wrb_1",
- label: "login",
- blockType: "task",
- state: "stopped",
- lastSeenIteration: 0,
- activity: [],
- startedAt: "2026-05-25T00:00:01Z",
- endedAt: "2026-05-25T00:00:04Z",
- } as BlockState,
- ],
- }),
- );
-
- expect(summary.isFail).toBe(false);
- expect(summary.isStopped).toBe(true);
- expect(summary.headline).toBe("Stopped");
- expect(summary.accent).not.toBe("fail");
- expect(summary.stats).toContain("1 stopped");
- });
-
it("keeps a stopped block through hydration so a reload does not downgrade it", () => {
const turn = hydrateNarrativeFromPayload({
turnId: "turn-1",
@@ -1954,15 +1281,6 @@ describe("a real cancel's backend payload still renders neutrally", () => {
expect(turn?.blocks[0]?.state).toBe("stopped");
});
- it("does not brand the settled cancel a failure", () => {
- const turn = hydrateNarrativeFromPayload(cancelledPayload())!;
- const summary = computeTurnSummary(turn);
-
- expect(summary.isFail).toBe(false);
- expect(summary.headline).not.toBe("Run halted");
- expect(summary.accent).not.toBe("fail");
- });
-
it("does not redden the rail for a run the user stopped", () => {
const turn = hydrateNarrativeFromPayload(cancelledPayload())!;
const phases = derivePhases(turn);
@@ -1971,61 +1289,11 @@ describe("a real cancel's backend payload still renders neutrally", () => {
expect(byId.test).toBe("stopped");
});
- // Stop pressed during the thinking phase, or on a QA turn: nothing to key a
- // block state off, so only the turn's own cancelled flag can tell the truth.
- it("does not read a blockless cancel as a clean success", () => {
- const summary = computeTurnSummary(
- buildTurn({ cancelled: true, blocks: [], draft: null }),
- );
-
- expect(summary.headline).toBe("Stopped");
- expect(summary.headline).not.toBe("Completed the run");
- expect(summary.glyph).not.toBe("✓");
- expect(summary.accent).not.toBe("ok");
- });
-
- // The labels a cancel actually carried before the relabel: the payload surface
- // wrote "build" through the terminal-reason arm, and "answer" without one.
- it.each(["build", "answer"] as const)(
- "renders a blockless cancel identically whether it is labelled %s or recover",
- (priorKind) => {
- const summaryFor = (responseKind: "build" | "answer" | "recover") =>
- computeTurnSummary(
- buildTurn({ cancelled: true, blocks: [], draft: null, responseKind }),
- );
-
- expect(summaryFor(priorKind)).toEqual(summaryFor("recover"));
- expect(summaryFor("recover").headline).toBe("Stopped");
- expect(summaryFor("recover").stats).toEqual(summaryFor(priorKind).stats);
- },
- );
-
- it.each(["build", "answer"] as const)(
- "renders a cancel that kept a draft identically whether it is labelled %s or recover",
- (priorKind) => {
- const summaryFor = (responseKind: "build" | "answer" | "recover") =>
- computeTurnSummary(
- buildTurn({
- cancelled: true,
- blocks: [],
- draft: draft3,
- proposalDisposition: "review_untested",
- responseKind,
- }),
- );
-
- expect(summaryFor(priorKind)).toEqual(summaryFor("recover"));
- expect(summaryFor("recover").headline).toBe("Stopped with a draft");
- expect(summaryFor("recover").accent).toBe("qa");
- },
- );
-
- it("still renders a genuine error turn as a failure", () => {
+ it("keeps a genuine error turn's block failed when it was not cancelled", () => {
const turn = hydrateNarrativeFromPayload({
...cancelledPayload(),
cancelled: false,
})!;
expect(turn.blocks[0]?.state).toBe("failed");
- expect(computeTurnSummary(turn).isFail).toBe(true);
});
});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx
index 9ba1ee267..62a2894ca 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx
@@ -20,6 +20,7 @@ import {
BlockState,
RecordedActionSummary,
TurnNarrativeState,
+ awaitsUserInput,
formatElapsed,
humanizeJudgeText,
isBlockOk,
@@ -35,6 +36,8 @@ import { useThemeAsDarkOrLight } from "../../../components/useThemeAsDarkOrLight
// copilot-row-flash-* animation duration.
const FLASH_WINDOW_MS = 600;
const OUTCOME_REASON_PREVIEW_LIMIT = 140;
+const QUESTION_PROSE_CLASSES =
+ "border-l-2 border-sky-500 pl-3 text-sky-700 dark:text-[#a7ccdd]";
const TERMINAL_PROSE_GRADIENT_CHARS = 32;
const TERMINAL_PROSE_GRADIENT_SETTLE_MS = 420;
@@ -1607,8 +1610,19 @@ function DetailView({
</div>
) : null}
+ {/* terminalProseTone's question branch without its evidence gate: an
+ ask that followed a run keeps the rail here, beside the evidence,
+ rather than replacing the card with prose-only chrome. */}
{turn.terminal && (turn.narrativeSummary || turn.terminalMessage) ? (
- <div className="text-[13px] leading-[1.55] text-foreground dark:text-slate-200">
+ <div
+ data-testid="copilot-detail-prose"
+ className={[
+ "text-[13px] leading-[1.55]",
+ awaitsUserInput(turn)
+ ? QUESTION_PROSE_CLASSES
+ : "text-foreground dark:text-slate-200",
+ ].join(" ")}
+ >
<CopilotMarkdown
text={humanizeJudgeText(
turn.narrativeSummary?.trim() ||
@@ -1657,7 +1671,11 @@ function terminalProseTone(turn: TurnNarrativeState): TerminalProseTone | null {
// A terminal question can follow a partial build or test. Keep recorded work
// on the expandable evidence path rather than losing it to prose-only chrome.
if (hasRecordedTerminalEvidence(turn)) return null;
- if (turn.responseKind === "clarify" || turn.responseType === "ASK_QUESTION") {
+ if (
+ awaitsUserInput(turn) ||
+ turn.responseKind === "clarify" ||
+ turn.responseType === "ASK_QUESTION"
+ ) {
return "question";
}
if (
@@ -1734,7 +1752,7 @@ function TerminalProse({
className={[
"text-[13px] leading-[1.55]",
tone === "question"
- ? "border-l-2 border-sky-500 pl-3 text-sky-700 dark:text-[#a7ccdd]"
+ ? QUESTION_PROSE_CLASSES
: "text-foreground dark:text-slate-200",
].join(" ")}
>
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.sessionPill.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.sessionPill.test.tsx
new file mode 100644
index 000000000..039718ca3
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.sessionPill.test.tsx
@@ -0,0 +1,116 @@
+// @vitest-environment jsdom
+
+import { cleanup, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it } from "vitest";
+
+import { ChatMessage, ConvoAggregatePill } from "./WorkflowCopilotChat";
+import { EMPTY_NARRATIVE, TurnNarrativeState } from "./narrativeState";
+
+afterEach(cleanup);
+
+const askingEnvelope = (renderedFromEnvelope: boolean) => ({
+ nextState: "awaiting_user_input" as const,
+ renderedFromEnvelope,
+ runVerdict: null,
+ runDisplayReason: null,
+});
+
+const turn = (
+ id: string,
+ overrides: Partial<TurnNarrativeState> = {},
+): ChatMessage => ({
+ id,
+ sender: "ai",
+ content: "",
+ timestamp: "2026-09-03T00:00:05Z",
+ narrative: {
+ ...EMPTY_NARRATIVE,
+ turnId: id,
+ terminal: "response",
+ startedAt: "2026-09-03T00:00:00Z",
+ endedAt: "2026-09-03T00:00:05Z",
+ ...overrides,
+ },
+});
+
+const pill = (messages: ChatMessage[]) => {
+ render(<ConvoAggregatePill messages={messages} isInFlight={false} />);
+ return screen.getByText(/turns/).textContent ?? "";
+};
+
+describe("ConvoAggregatePill — session status", () => {
+ it("says the session is waiting on the user, outranking an earlier halt", () => {
+ expect(
+ pill([
+ turn("t1", { terminal: "error" }),
+ turn("t2", { terminalEnvelope: askingEnvelope(true) }),
+ ]),
+ ).toContain("Waiting on you");
+ });
+
+ it("does not stay blocked on a question a later turn already moved past", () => {
+ expect(
+ pill([
+ turn("t1", { terminalEnvelope: askingEnvelope(true) }),
+ turn("t2"),
+ ]),
+ ).toContain("Done");
+ });
+
+ it("stops waiting once the user has replied", () => {
+ expect(
+ pill([
+ turn("t1"),
+ turn("t2", { terminalEnvelope: askingEnvelope(true) }),
+ { id: "u1", sender: "user", content: "the member portal" },
+ ]),
+ ).not.toContain("Waiting on you");
+ });
+
+ it("stops waiting on a later turn that carried no narrative", () => {
+ expect(
+ pill([
+ turn("t1"),
+ turn("t2", { terminalEnvelope: askingEnvelope(true) }),
+ { id: "a3", sender: "ai", content: "Answered in ask mode." },
+ ]),
+ ).not.toContain("Waiting on you");
+ });
+
+ it("keeps waiting behind a trailing run-lifecycle line", () => {
+ expect(
+ pill([
+ turn("t1"),
+ turn("t2", { terminalEnvelope: askingEnvelope(true) }),
+ {
+ id: "rl1",
+ sender: "ai",
+ content: "Run started - watching it now.",
+ kind: "run_lifecycle",
+ },
+ ]),
+ ).toContain("Waiting on you");
+ });
+
+ it("does not wait on a user who stopped the turn themselves", () => {
+ expect(
+ pill([
+ turn("t1"),
+ turn("t2", {
+ terminalEnvelope: askingEnvelope(true),
+ terminal: "error",
+ cancelled: true,
+ }),
+ ]),
+ ).not.toContain("Waiting on you");
+ });
+
+ it("keeps the legacy status until the backend stamps the envelope", () => {
+ expect(
+ pill([
+ turn("t1"),
+ turn("t2", { terminalEnvelope: askingEnvelope(false) }),
+ ]),
+ ).toContain("Done");
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx
index 53eb52e77..f128d4405 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx
@@ -83,6 +83,7 @@ import { CopilotWorkingStatus } from "./CopilotWorkingStatus";
import { useRunLifecycleAnnouncements } from "./useRunLifecycleAnnouncements";
import { ConfirmCard, shouldShowConfirmCard } from "./cards/ConfirmCard";
import { ConnectedAccountChoiceCard } from "./cards/ConnectedAccountChoiceCard";
+import { QuestionPartsCard } from "./cards/QuestionPartsCard";
import { connectedAccountChoiceLabel } from "./cards/connectedAccountChoiceLabel";
import { shouldShowDiffCard } from "./cards/DiffCard";
import { ReviewGateCard, getReviewGateVerdict } from "./cards/ReviewGateCard";
@@ -100,6 +101,7 @@ import {
RecordedActionSummary,
TurnNarrativeState,
applyNarrativeEvent,
+ awaitsUserInput,
hydrateHistoryNarrative,
notConfirmedOutcome,
parseUtcIsoMs,
@@ -318,7 +320,7 @@ function ModeGlyph({
);
}
-function ConvoAggregatePill({
+export function ConvoAggregatePill({
messages,
isInFlight,
}: {
@@ -352,12 +354,30 @@ function ConvoAggregatePill({
const anyError = turnsWithNarrative.some(
(m) => m.narrative?.terminal === "error" && !m.narrative?.cancelled,
);
- const status = isInFlight ? "In flight" : anyError ? "Halted" : "Done";
+ // The ask is pending only while it is the tail of the conversation. Reading
+ // the last narrative-bearing turn instead would strand the pill on a question
+ // that the user's own reply, or a later narration-free turn, already moved
+ // past. findLastTurnIndex skips run_lifecycle lines, which are sender "ai"
+ // with no narrative and must not count as an answer.
+ const lastTurn = messages[findLastTurnIndex(messages)];
+ const awaitingUser =
+ lastTurn?.sender === "ai" && awaitsUserInput(lastTurn.narrative);
+ // awaitingUser outranks anyError, which is session-wide: a question asked
+ // after a failed build test is what the user acts on next.
+ const status = isInFlight
+ ? "In flight"
+ : awaitingUser
+ ? "Waiting on you"
+ : anyError
+ ? "Halted"
+ : "Done";
const dotClass = isInFlight
? "bg-blue-400"
- : anyError
- ? "bg-rose-400"
- : "bg-emerald-400";
+ : awaitingUser
+ ? "bg-amber-400"
+ : anyError
+ ? "bg-rose-400"
+ : "bg-emerald-400";
return (
<div className="flex justify-center pb-1">
<span className="inline-flex items-center gap-2 rounded-full border border-border bg-slate-elevation1/60 px-3 py-0.5 text-[11px] text-tertiary-foreground">
@@ -3875,6 +3895,12 @@ export function WorkflowCopilotChat({
if (message.sender === "ai" && message.narrative) {
const turnId = message.narrative.turnId;
const choices = message.narrative.connectedAccountChoices;
+ // The account card owns its own choice interaction, so a turn
+ // that raised one never also raises the generic parts card.
+ const questionParts =
+ choices.length === 0 && awaitsUserInput(message.narrative)
+ ? (message.narrative.terminalEnvelope?.questionParts ?? [])
+ : [];
const adjacentMessage = messages[index + 1];
const selectedConnectionId =
adjacentMessage?.sender === "user" &&
@@ -3922,6 +3948,22 @@ export function WorkflowCopilotChat({
}
/>
) : null}
+ {questionParts.length > 0 ? (
+ <QuestionPartsCard
+ parts={questionParts}
+ answeredFrom={
+ adjacentMessage?.sender === "user"
+ ? adjacentMessage.content
+ : null
+ }
+ disabled={
+ !isLastMessage ||
+ isLoading ||
+ adjacentMessage !== undefined
+ }
+ onAnswer={(answer) => void handleSend(answer)}
+ />
+ ) : null}
{message.narrative.googleConnectionNotices.map((notice) => (
<GoogleReconnectCard
key={notice.connectionId}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/cards/QuestionPartsCard.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/cards/QuestionPartsCard.test.tsx
new file mode 100644
index 000000000..4375a1dc2
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/cards/QuestionPartsCard.test.tsx
@@ -0,0 +1,91 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { QuestionPartsCard } from "./QuestionPartsCard";
+import { questionAnswerLine } from "./questionAnswerLine";
+import { parseTerminalEnvelope } from "../narrativeState";
+
+afterEach(() => {
+ cleanup();
+});
+
+const parts = [
+ { part_id: "p1", prompt: "Which store?", choices: ["Acme", "Borough"] },
+ { part_id: "p2", prompt: "Which email gets the receipt?", choices: [] },
+ { part_id: "p3", prompt: "Which day?", choices: ["Monday", "Friday"] },
+];
+
+describe("QuestionPartsCard", () => {
+ it("sends only the parts the user actually answered", () => {
+ const onAnswer = vi.fn();
+ render(
+ <QuestionPartsCard
+ parts={parts}
+ answeredFrom={null}
+ disabled={false}
+ onAnswer={onAnswer}
+ />,
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "Borough" }));
+ fireEvent.click(screen.getByRole("button", { name: "Send" }));
+
+ expect(onAnswer).toHaveBeenCalledWith(
+ questionAnswerLine("Which store?", "Borough"),
+ );
+ // A part whose answer is a value only the user holds still shows, so the
+ // card never presents a compound ask as though it were a single question.
+ expect(
+ screen.getByText("Type your answer in the message box."),
+ ).toBeTruthy();
+ });
+
+ it("reads the answered part back off the sent message after a reload", () => {
+ render(
+ <QuestionPartsCard
+ parts={parts}
+ answeredFrom={questionAnswerLine("Which day?", "Friday")}
+ disabled
+ onAnswer={vi.fn()}
+ />,
+ );
+
+ expect(
+ screen
+ .getByRole("button", { name: "Friday" })
+ .getAttribute("aria-pressed"),
+ ).toBe("true");
+ expect(
+ screen
+ .getByRole("button", { name: "Monday" })
+ .getAttribute("aria-pressed"),
+ ).toBe("false");
+ expect(screen.queryByRole("button", { name: "Send" })).toBeNull();
+ });
+});
+
+describe("parseTerminalEnvelope question parts", () => {
+ it("keeps well-formed parts and drops the rest", () => {
+ const facts = parseTerminalEnvelope({
+ next_state: "awaiting_user_input",
+ rendered_from_envelope: true,
+ question_parts: [
+ { part_id: "p1", prompt: "Which store?", choices: ["Acme", 7] },
+ { prompt: "no id" },
+ "junk",
+ ],
+ });
+
+ expect(facts?.questionParts).toEqual([
+ { part_id: "p1", prompt: "Which store?", choices: ["Acme"] },
+ ]);
+ });
+
+ it("is empty on an envelope that carries no parts", () => {
+ expect(
+ parseTerminalEnvelope({ next_state: "stopped" })?.questionParts,
+ ).toEqual([]);
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/cards/QuestionPartsCard.tsx b/skyvern-frontend/src/routes/workflows/copilot/cards/QuestionPartsCard.tsx
new file mode 100644
index 000000000..8abdbbf58
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/cards/QuestionPartsCard.tsx
@@ -0,0 +1,132 @@
+import { CheckIcon, QuestionMarkCircledIcon } from "@radix-ui/react-icons";
+import { useState } from "react";
+
+import { Button } from "@/components/ui/button";
+import type { QuestionPart } from "../workflowCopilotTypes";
+import { questionAnswerLine } from "./questionAnswerLine";
+
+type QuestionPartsCardProps = {
+ parts: QuestionPart[];
+ // The message that followed this question, when one exists. Its lines are the
+ // record of which parts were answered.
+ answeredFrom: string | null;
+ disabled: boolean;
+ onAnswer: (message: string) => void;
+};
+
+export function QuestionPartsCard({
+ parts,
+ answeredFrom,
+ disabled,
+ onAnswer,
+}: QuestionPartsCardProps) {
+ const [selected, setSelected] = useState<Record<string, string>>({});
+ const answeredLines = new Set(
+ (answeredFrom ?? "")
+ .split("\n")
+ .map((line) => line.trim())
+ .filter(Boolean),
+ );
+ const answerOf = (part: QuestionPart) =>
+ part.choices.find((choice) =>
+ answeredLines.has(questionAnswerLine(part.prompt, choice)),
+ ) ?? null;
+ const settled = parts.some((part) => answerOf(part) !== null);
+ const pending = parts
+ .map((part) => {
+ const choice = selected[part.part_id];
+ return choice ? questionAnswerLine(part.prompt, choice) : null;
+ })
+ .filter((line): line is string => line !== null);
+
+ return (
+ <div
+ className="overflow-hidden rounded-lg border border-border bg-slate-elevation2"
+ role="group"
+ aria-label="Question parts"
+ >
+ <div className="flex items-center gap-2 border-b border-border px-3 py-2">
+ <span className="flex size-6 flex-none items-center justify-center rounded-md bg-background">
+ <QuestionMarkCircledIcon className="size-4 text-muted-foreground" />
+ </span>
+ <span className="text-xs font-semibold text-foreground">
+ {parts.length === 1 ? "One thing to answer" : "Answer what you can"}
+ </span>
+ </div>
+ <div className="flex flex-col p-2">
+ {parts.map((part, index) => {
+ const answered = answerOf(part);
+ const active = answered ?? selected[part.part_id] ?? null;
+ return (
+ <div
+ key={part.part_id}
+ className={[
+ "flex flex-col gap-1.5 px-1 py-2",
+ index > 0 ? "border-t border-border" : "",
+ ].join(" ")}
+ >
+ <span className="text-[13px] leading-[1.45] text-foreground">
+ {part.prompt}
+ </span>
+ {part.choices.length === 0 ? (
+ <span className="text-[11px] text-muted-foreground">
+ Type your answer in the message box.
+ </span>
+ ) : (
+ <div className="flex flex-wrap gap-1.5">
+ {part.choices.map((choice) => {
+ const isActive = active === choice;
+ return (
+ <button
+ key={choice}
+ type="button"
+ disabled={disabled || settled}
+ aria-pressed={isActive}
+ onClick={() =>
+ setSelected((current) => ({
+ ...current,
+ [part.part_id]: choice,
+ }))
+ }
+ className={[
+ "flex items-center gap-1.5 rounded-md border px-2 py-1 text-left text-[12px] outline-none transition-colors",
+ "focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:cursor-default disabled:opacity-60",
+ isActive
+ ? "border-success bg-accent text-foreground"
+ : "border-border text-muted-foreground hover:bg-accent hover:text-foreground",
+ ].join(" ")}
+ >
+ {isActive ? (
+ <CheckIcon
+ className="size-3.5 flex-none text-success"
+ aria-hidden="true"
+ />
+ ) : null}
+ {choice}
+ </button>
+ );
+ })}
+ </div>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ {settled || disabled ? null : (
+ <div className="flex items-center justify-between gap-2 border-t border-border px-3 py-2">
+ <span className="text-[11px] text-muted-foreground">
+ {pending.length} of {parts.length} answered
+ </span>
+ <Button
+ size="sm"
+ variant="secondary"
+ disabled={pending.length === 0}
+ onClick={() => onAnswer(pending.join("\n"))}
+ >
+ Send
+ </Button>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/cards/ReviewGateCard.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/cards/ReviewGateCard.test.tsx
index f0abc4fcf..dc8043a17 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/cards/ReviewGateCard.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/cards/ReviewGateCard.test.tsx
@@ -195,6 +195,8 @@ describe("ReviewGateCard — Test end-to-end recourse", () => {
turn={turn({
proposalDisposition: "review_untested",
terminalEnvelope: {
+ nextState: "stopped",
+ renderedFromEnvelope: false,
runVerdict: null,
runDisplayReason: null,
connectFailure: {
diff --git a/skyvern-frontend/src/routes/workflows/copilot/cards/questionAnswerLine.ts b/skyvern-frontend/src/routes/workflows/copilot/cards/questionAnswerLine.ts
new file mode 100644
index 000000000..b112fc278
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/cards/questionAnswerLine.ts
@@ -0,0 +1,7 @@
+// The line one answered part contributes to the reply. Its own file so the card
+// stays component-only (Fast Refresh), matching connectedAccountChoiceLabel.ts.
+// Exported because the answered state a reloaded chat shows is read back off the
+// sent message rather than from component state the reload threw away.
+export function questionAnswerLine(prompt: string, choice: string): string {
+ return `${prompt} — ${choice}`;
+}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.runOutcome.test.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.runOutcome.test.ts
index a137f0b68..3c0ad5b93 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.runOutcome.test.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.runOutcome.test.ts
@@ -5,10 +5,12 @@ import { getReviewGateVerdict } from "./cards/ReviewGateCard";
import {
EMPTY_NARRATIVE,
TurnNarrativeState,
+ TerminalEnvelopeFacts,
applyNarrativeEvent,
- computeTurnSummary,
+ awaitsUserInput,
hydrateNarrativeFromPayload,
isBlockOk,
+ isDeadlineHalt,
notConfirmedOutcome,
ranCleanOnCurrentSource,
} from "./narrativeState";
@@ -82,6 +84,16 @@ const bothBlocksRan = [
blockProgress({ block_label: "search_person", status: "completed" }),
];
+const envelopeFacts = (
+ facts: Partial<TerminalEnvelopeFacts>,
+): TerminalEnvelopeFacts => ({
+ nextState: null,
+ renderedFromEnvelope: false,
+ runVerdict: null,
+ runDisplayReason: null,
+ ...facts,
+});
+
describe("applyNarrativeEvent — run_outcome", () => {
it("negative verdict withholds the success affordance from completed rows", () => {
const s = reduce([
@@ -397,12 +409,52 @@ describe("hydrateNarrativeFromPayload — outcome", () => {
},
})!;
expect(withEnvelope.terminalEnvelope).toEqual({
+ nextState: "stopped",
+ questionParts: [],
+ renderedFromEnvelope: false,
runVerdict: "not_demonstrated",
runDisplayReason: "Checkout never reached confirmation.",
runOutcomeRole: null,
connectFailure: null,
});
+ const question = hydrateNarrativeFromPayload({
+ ...payload([]),
+ terminalEnvelope: {
+ next_state: "awaiting_user_input",
+ response_kind: "question",
+ user_action_required: true,
+ rendered_from_envelope: true,
+ },
+ })!;
+ expect(question.terminalEnvelope).toEqual({
+ nextState: "awaiting_user_input",
+ questionParts: [],
+ renderedFromEnvelope: true,
+ runVerdict: null,
+ runDisplayReason: null,
+ runOutcomeRole: null,
+ connectFailure: null,
+ });
+ expect(awaitsUserInput(question)).toBe(true);
+ // Unstamped envelope: carried, but not display authority.
+ expect(
+ awaitsUserInput({
+ cancelled: false,
+ terminalEnvelope: {
+ ...question.terminalEnvelope!,
+ renderedFromEnvelope: false,
+ },
+ }),
+ ).toBe(false);
+ // The cancel path persists this envelope verbatim, so the stop has to win.
+ expect(
+ awaitsUserInput({
+ cancelled: true,
+ terminalEnvelope: question.terminalEnvelope,
+ }),
+ ).toBe(false);
+
const legacy = hydrateNarrativeFromPayload(payload([]))!;
expect(legacy.terminalEnvelope).toBeNull();
@@ -411,6 +463,9 @@ describe("hydrateNarrativeFromPayload — outcome", () => {
terminalEnvelope: { run_verdict: "maybe", run_display_reason: 7 },
})!;
expect(malformed.terminalEnvelope).toEqual({
+ nextState: null,
+ questionParts: [],
+ renderedFromEnvelope: false,
runVerdict: null,
runDisplayReason: null,
runOutcomeRole: null,
@@ -471,10 +526,10 @@ describe("notConfirmedOutcome — envelope-first", () => {
it("envelope not_demonstrated wins even when a later pointer says demonstrated", () => {
const outcome = notConfirmedOutcome({
...base,
- terminalEnvelope: {
+ terminalEnvelope: envelopeFacts({
runVerdict: "not_demonstrated",
runDisplayReason: "Cart never showed the item.",
- },
+ }),
lastRunOutcome: {
verdict: "demonstrated",
displayReason: null,
@@ -489,7 +544,7 @@ describe("notConfirmedOutcome — envelope-first", () => {
it("envelope demonstrated suppresses the block-derived not_demonstrated", () => {
const outcome = notConfirmedOutcome({
...base,
- terminalEnvelope: { runVerdict: "demonstrated", runDisplayReason: null },
+ terminalEnvelope: envelopeFacts({ runVerdict: "demonstrated" }),
blocks: [
{
workflowRunBlockId: "wrb_1",
@@ -511,7 +566,7 @@ describe("notConfirmedOutcome — envelope-first", () => {
it("envelope not_evaluated suppresses not-confirmed like demonstrated does", () => {
const outcome = notConfirmedOutcome({
...base,
- terminalEnvelope: { runVerdict: "not_evaluated", runDisplayReason: null },
+ terminalEnvelope: envelopeFacts({ runVerdict: "not_evaluated" }),
lastRunOutcome: {
verdict: "not_demonstrated",
displayReason: "Stale pointer.",
@@ -523,11 +578,10 @@ describe("notConfirmedOutcome — envelope-first", () => {
it("an interim run-start envelope does not suppress the recorded not-confirmed outcome", () => {
const outcome = notConfirmedOutcome({
...base,
- terminalEnvelope: {
+ terminalEnvelope: envelopeFacts({
runVerdict: "not_evaluated",
- runDisplayReason: null,
runOutcomeRole: "interim_build_test",
- },
+ }),
lastRunOutcome: {
verdict: "not_demonstrated",
displayReason: "The earlier run never reached the dashboard.",
@@ -542,7 +596,7 @@ describe("notConfirmedOutcome — envelope-first", () => {
it("envelope without a run verdict falls back to the legacy inference", () => {
const outcome = notConfirmedOutcome({
...base,
- terminalEnvelope: { runVerdict: null, runDisplayReason: null },
+ terminalEnvelope: envelopeFacts({}),
lastRunOutcome: {
verdict: "not_demonstrated",
displayReason: "Legacy pointer reason.",
@@ -559,7 +613,7 @@ describe("notConfirmedOutcome — envelope-first", () => {
// the staged source.
const CLEAN_RECORDED_TURN = "surface-20260820T082523349904";
-describe("canonical turn facts — card, pill and prose over one bundle", () => {
+describe("canonical turn facts — pill and prose over one bundle", () => {
const surfaces = (leg: keyof typeof bundles) => {
const turn = hydrateNarrativeFromPayload(
bundles[leg] as unknown as Record<string, unknown>,
@@ -567,32 +621,27 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
if (!turn) throw new Error(`fixture ${leg} did not hydrate`);
return {
turn,
- card: computeTurnSummary(turn),
pill: getReviewGateVerdict(turn, null),
prose: turn.terminalMessage ?? "",
};
};
it("states coverage and evaluation as independent facts when one of three blocks ran", () => {
- const { card, pill, prose } = surfaces("partial-coverage");
-
- expect(card.headline).not.toBe("Built and tested the workflow");
- expect(card.stats).toContain("3 blocks authored");
- expect(card.stats).toContain("1/3 ran on current source");
- expect(card.stats).toContain("outcome not evaluated");
- expect(card.stats.join(" ")).not.toContain("wr_");
- expect(card.accent).not.toBe("ok");
- expect(card.isFail).toBe(false);
+ const { turn, pill, prose } = surfaces("partial-coverage");
+
+ expect(turn.turnFacts?.authoredBlockCount).toBe(3);
+ expect(turn.turnFacts?.matchingSourceBlockCount).toBe(1);
+ expect(turn.turnFacts?.evaluationState).toBe("not_evaluated");
expect(pill).toBe("untested");
expect(prose).not.toContain("tested draft");
});
it("reports a deadline halt without a failure row or a tested pill", () => {
- const { card, pill, prose } = surfaces("deadline-after-one-clean-run");
+ const { turn, pill, prose } = surfaces("deadline-after-one-clean-run");
- expect(card.isFail).toBe(false);
- expect(card.accent).not.toBe("fail");
- expect(card.stats).toContain("time limit reached");
+ expect(turn.turnFacts?.terminalCause).toBe("deadline_expired");
+ expect(turn.blocks.some((block) => block.state === "failed")).toBe(false);
+ expect(isDeadlineHalt(turn)).toBe(true);
expect(pill).toBe("untested");
expect(prose).toContain("1 block ran this turn");
expect(prose).toContain("outcome was not evaluated");
@@ -600,7 +649,7 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
});
it("marks an edited block as run against different source, never as failed", () => {
- const { turn, card, pill } = surfaces("different-source-edit-one-of-two");
+ const { turn, pill } = surfaces("different-source-edit-one-of-two");
expect(
turn.review?.blocks.map((block) => [block.label, block.coverage]),
@@ -609,46 +658,31 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
["append_star_count_to_sheet", "never_run"],
["append_star_count_to_sales_marketing", "never_run"],
]);
- expect(card.isFail).toBe(false);
+ expect(turn.blocks.some((block) => block.state === "failed")).toBe(false);
expect(pill).toBe("untested");
});
- it("excludes a removed block from the authored count", () => {
- const { card } = surfaces("mixed-edit-and-delete");
-
- expect(card.stats).toContain("2 blocks authored");
- expect(card.stats).toContain("1/2 ran on current source");
- });
-
it("names clean lifecycle plus full current-source coverage on the satisfaction path", () => {
- const { card, pill, prose } = surfaces("satisfaction");
-
- expect(card.stats).toContain("3 blocks authored");
- expect(card.stats).toContain("3/3 ran on current source");
- expect(card.stats).toContain("run completed");
- expect(card.headline).toBe("Every block ran clean on the current draft");
- expect(card.accent).toBe("ok");
- expect(card.isFail).toBe(false);
+ const { turn, pill, prose } = surfaces("satisfaction");
+
+ expect(turn.turnFacts?.authoredBlockCount).toBe(3);
+ expect(turn.turnFacts?.matchingSourceBlockCount).toBe(3);
+ expect(turn.turnFacts?.runCompleted).toBe(true);
+ expect(ranCleanOnCurrentSource(turn.turnFacts)).toBe(true);
expect(pill).toBe("tested");
- for (const claim of [/verified/i, /demonstrated/i, /goal/i, /confirm/i]) {
- expect(card.headline).not.toMatch(claim);
- }
expect(prose).not.toMatch(/verified|demonstrated/i);
});
it("states its counts without a completion claim when no run is anchored to the turn", () => {
- const { turn, card } = surfaces(CLEAN_RECORDED_TURN);
+ const { turn } = surfaces(CLEAN_RECORDED_TURN);
expect(turn.blocks.map((block) => block.state)).toEqual(["completed"]);
expect(turn.turnFacts?.runCompleted).toBeNull();
- expect(card.stats).toContain("1 block authored");
- expect(card.stats).toContain("1/1 ran on current source");
- expect(card.stats).not.toContain("run completed");
- expect(card.stats).not.toContain("run did not complete");
- expect(card.isFail).toBe(false);
+ expect(turn.turnFacts?.authoredBlockCount).toBe(1);
+ expect(turn.turnFacts?.matchingSourceBlockCount).toBe(1);
});
- it("withholds the satisfaction headline when the recorded run did not complete", () => {
+ it("withholds the tested pill when the recorded run did not complete", () => {
const recorded = bundles[CLEAN_RECORDED_TURN] as unknown as {
turnFacts: Record<string, unknown>;
};
@@ -661,14 +695,10 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
},
});
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
- expect(card.stats).toContain("run did not complete");
- expect(card.headline).not.toBe(
- "Every block ran clean on the current draft",
- );
+ expect(turn.turnFacts?.runCompleted).toBe(false);
+ expect(ranCleanOnCurrentSource(turn.turnFacts)).toBe(false);
expect(getReviewGateVerdict(turn, null)).toBe("untested");
- expect(card.isFail).toBe(false);
});
it("makes no completion claim when a stop left the run start unresolved", () => {
@@ -687,35 +717,16 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
},
});
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
expect(turn.turnFacts?.runCompleted).toBeNull();
- expect(card.stats).toContain("1/1 ran on current source");
- expect(card.stats).not.toContain("run completed");
- expect(card.stats).not.toContain("run did not complete");
+ expect(turn.turnFacts?.authoredBlockCount).toBe(1);
+ expect(turn.turnFacts?.matchingSourceBlockCount).toBe(1);
+ expect(ranCleanOnCurrentSource(turn.turnFacts)).toBe(false);
expect(getReviewGateVerdict(turn, null)).toBe("untested");
});
- it("withholds success from a fully covered turn whose recorded run failed", () => {
- const recorded = bundles[CLEAN_RECORDED_TURN] as unknown as {
- blocks: Array<Record<string, unknown>>;
- };
- const turn = hydrateNarrativeFromPayload({
- ...(bundles[CLEAN_RECORDED_TURN] as unknown as Record<string, unknown>),
- blocks: recorded.blocks.map((block) => ({ ...block, state: "failed" })),
- });
- if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
-
- expect(card.headline).not.toBe(
- "Every block ran clean on the current draft",
- );
- expect(card.isFail).toBe(true);
- expect(card.accent).toBe("fail");
- });
-
- it("says a renamed block is untested under this name across card and pill", () => {
- const { turn, card, pill } = surfaces("renamed-block");
+ it("says a renamed block is untested under this name across review and pill", () => {
+ const { turn, pill } = surfaces("renamed-block");
expect(
turn.review?.blocks.map((block) => [block.label, block.coverage]),
@@ -725,8 +736,7 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
["append_star_count_to_sales_marketing", "current_source"],
["extract_github_star_count", undefined],
]);
- expect(card.stats).toContain("2/3 ran on current source");
- expect(card.isFail).toBe(false);
+ expect(turn.turnFacts?.matchingSourceBlockCount).toBe(2);
expect(pill).toBe("untested");
});
@@ -748,41 +758,9 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
],
});
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
expect(turn.blocks.map((block) => block.state)).toEqual(["stopped"]);
- expect(card.isFail).toBe(false);
- expect(card.accent).not.toBe("fail");
- });
-
- it("does not call a deadline halt that delivered nothing a completed run", () => {
- const turn = hydrateNarrativeFromPayload({
- ...(bundles["deadline-after-one-clean-run"] as unknown as Record<
- string,
- unknown
- >),
- proposalDisposition: "no_proposal",
- draft: null,
- terminal: "error",
- blocks: [
- {
- workflowRunBlockId: "wrb_1",
- label: "append_star_count_to_sheet",
- blockType: "code",
- state: "completed",
- lastSeenIteration: 0,
- activity: [],
- },
- ],
- });
- if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
-
- // Suppressing the failure treatment for a deadline must not promote the turn
- // into a success: it ran out of time and handed nothing back.
- expect(card.isFail).toBe(false);
- expect(card.accent).not.toBe("ok");
- expect(card.headline).not.toMatch(/completed the run/i);
+ expect(isDeadlineHalt(turn)).toBe(true);
});
it("keeps a failed block a failure even when the deadline expired", () => {
@@ -803,11 +781,9 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
],
});
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
expect(turn.turnFacts?.terminalCause).toBe("deadline_expired");
- expect(card.isFail).toBe(true);
- expect(card.stats).toContain("1 failed");
+ expect(isDeadlineHalt(turn)).toBe(false);
});
it("makes no tested claim for a turn that published no facts or coverage", () => {
@@ -829,13 +805,10 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
},
});
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
expect(turn.turnFacts).toBeNull();
expect(turn.review?.blocks[0]?.coverage).toBeUndefined();
- expect(card.headline).not.toMatch(/tested/i);
- expect(card.accent).not.toBe("ok");
- expect(card.stats.join(" ")).not.toMatch(/ran on current source|authored/);
+ expect(getReviewGateVerdict(turn, null)).toBe("untested");
});
it("keeps the review when the backend sends a coverage value it does not know", () => {
@@ -865,20 +838,13 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
bundles["facts-absent"] as unknown as Record<string, unknown>,
);
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
expect(turn.turnFacts).toBeNull();
expect(turn.proposalDisposition).toBe("review_tested");
expect(getReviewGateVerdict(turn, null)).toBe("untested");
- // The tested branch is named "Workflow ready for review", which contains no literal
- // "tested" — assert the branch, not the substring.
- expect(card.headline).not.toBe("Workflow ready for review");
- expect(card.headline).toBe("Built the workflow");
- expect(card.glyph).not.toBe("\u2713");
- expect(card.accent).not.toBe("ok");
});
- it("keeps card and pill telling one story when the envelope is missing", () => {
+ it("keeps facts and pill telling one story when the envelope is missing", () => {
const full = bundles["full-coverage"] as unknown as Record<string, unknown>;
const facts = full.turnFacts as Record<string, unknown>;
const turn = hydrateNarrativeFromPayload({
@@ -893,15 +859,13 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
},
});
if (!turn) throw new Error("fixture did not hydrate");
- const card = computeTurnSummary(turn);
expect(turn.turnFacts?.factsAvailable).toBe(true);
expect(turn.turnFacts?.authoredBlockCount).toBe(facts.authoredBlockCount);
- expect(card.stats).toContain(
- `${facts.matchingSourceBlockCount}/${facts.authoredBlockCount} ran on current source`,
+ expect(turn.turnFacts?.matchingSourceBlockCount).toBe(
+ facts.matchingSourceBlockCount,
);
- expect(card.stats).not.toContain("run completed");
- expect(card.isFail).toBe(false);
+ expect(turn.turnFacts?.runCompleted).toBeNull();
expect(ranCleanOnCurrentSource(turn.turnFacts)).toBe(true);
expect(getReviewGateVerdict(turn, null)).toBe("tested");
});
@@ -921,9 +885,7 @@ describe("canonical turn facts — card, pill and prose over one bundle", () =>
});
if (!turn) throw new Error("fixture did not hydrate");
+ expect(ranCleanOnCurrentSource(turn.turnFacts)).toBe(false);
expect(getReviewGateVerdict(turn, null)).toBe("untested");
- expect(computeTurnSummary(turn).headline).not.toBe(
- "Every block ran clean on the current draft",
- );
});
});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
index 5b918a532..9dee56df4 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
@@ -6,6 +6,7 @@
import { buildRevealOffsets } from "./actionReveal";
import {
ConnectedAccountChoice,
+ QuestionPart,
CopilotResponseType,
ProposalDisposition,
RunOutcomeRole,
@@ -165,7 +166,25 @@ function isBuildTestConnectFailureState(
);
}
+// Closed vocabulary of TerminalOutcomeEnvelope.next_state. The envelope's
+// sibling response_kind and user_action_required carry the same bit for a
+// question turn, so only this one is parsed.
+export type TerminalNextState =
+ | "completed"
+ | "proposal_pending"
+ | "awaiting_user_input"
+ | "stopped";
+
export interface TerminalEnvelopeFacts {
+ nextState: TerminalNextState | null;
+ // Server-admitted parts of the model's own question, in the order it asked
+ // them. Optional like connectFailure: absent on an envelope an older backend
+ // wrote, and empty on every turn that did not end on an ASK_QUESTION.
+ questionParts?: QuestionPart[];
+ // The backend stamps this only when the terminal-envelope render flag is on
+ // for the org; until then the envelope is carried but is not display
+ // authority, so no surface may key off it.
+ renderedFromEnvelope: boolean;
runVerdict: BlockOutcome | null;
runDisplayReason: string | null;
// Absent on envelopes persisted before the role was carried.
@@ -227,6 +246,30 @@ export interface ReviewProjection {
}>;
}
+// part_id and the choice strings are minted or admitted server-side, so this
+// only has to drop a payload shape an older backend never sends.
+function parseQuestionParts(raw: unknown): QuestionPart[] {
+ if (!Array.isArray(raw)) return [];
+ const parts: QuestionPart[] = [];
+ for (const entry of raw) {
+ if (!entry || typeof entry !== "object") continue;
+ const part = entry as Record<string, unknown>;
+ if (typeof part.part_id !== "string" || typeof part.prompt !== "string") {
+ continue;
+ }
+ parts.push({
+ part_id: part.part_id,
+ prompt: part.prompt,
+ choices: Array.isArray(part.choices)
+ ? part.choices.filter(
+ (choice): choice is string => typeof choice === "string",
+ )
+ : [],
+ });
+ }
+ return parts;
+}
+
// Envelope dicts are backend model_dump output, so keys stay snake_case.
// The backend anchors run_verdict from final outcomes only, so "evaluating"
// is not a wire value here and parses to null like any unknown.
@@ -260,7 +303,17 @@ export function parseTerminalEnvelope(
};
})();
const role = obj.run_outcome_role;
+ const nextState = obj.next_state;
return {
+ questionParts: parseQuestionParts(obj.question_parts),
+ nextState:
+ nextState === "completed" ||
+ nextState === "proposal_pending" ||
+ nextState === "awaiting_user_input" ||
+ nextState === "stopped"
+ ? nextState
+ : null,
+ renderedFromEnvelope: obj.rendered_from_envelope === true,
runVerdict:
v === "demonstrated" || v === "not_demonstrated" || v === "not_evaluated"
? v
@@ -279,6 +332,27 @@ export function parseTerminalEnvelope(
};
}
+// The one typed source for "this turn ended on the user". The backend derives
+// next_state from response_type == ASK_QUESTION and keeps it through a failed
+// build test, so a question asked after scouting or a run still reads as one.
+// Read-gated: the envelope is display authority only once the backend stamped
+// rendered_from_envelope. A user stop is not an ask -- next_state is derived
+// before the cancel lands, so the cancel path persists awaiting_user_input on a
+// turn nobody is waiting on.
+export function awaitsUserInput(
+ turn:
+ | Pick<TurnNarrativeState, "terminalEnvelope" | "cancelled">
+ | null
+ | undefined,
+): boolean {
+ if (!turn || turn.cancelled) return false;
+ const envelope = turn.terminalEnvelope;
+ return (
+ envelope?.renderedFromEnvelope === true &&
+ envelope.nextState === "awaiting_user_input"
+ );
+}
+
export interface BlockState {
workflowRunBlockId: string;
label: string;
@@ -1771,26 +1845,6 @@ export function hydrateNarrativeFromPayload(
};
}
-// The chip reflects what the turn ACTUALLY did: its blocks, its response type,
-// and the backend's evidence-derived response kind.
-export function effectiveMode(turn: TurnNarrativeState): string {
- if (turn.responseType === "ASK_QUESTION") {
- return "clarify";
- }
- const blockCount = turn.draft?.blockCount ?? turn.blocks.length;
- if (blockCount > 0) {
- const priorBlocks = turn.priorBlockCount ?? 0;
- return priorBlocks > 0 ? "edit" : "build";
- }
- if (turn.responseKind === "answer") {
- return "docs_answer";
- }
- if (turn.responseKind === "diagnose" || turn.responseKind === "refuse") {
- return turn.responseKind;
- }
- return "clarify";
-}
-
// History rows persisted before narrative_payload carried responseKind still
// have the adjacent persisted turn_outcome; graft its response_kind so
// clarify/refuse/recover history corrects retroactively. Build-kind rows use
@@ -1840,17 +1894,6 @@ export function formatElapsed(
return `${m}:${s.toString().padStart(2, "0")}`;
}
-export interface TurnSummary {
- headline: string;
- stats: string[];
- accent: "ok" | "fail" | "qa" | "warn";
- glyph: string;
- isFail: boolean;
- isStopped: boolean;
- isQA: boolean;
- isStoppedWithDraft: boolean;
-}
-
export function latestBlocksByLabel(blocks: BlockState[]): BlockState[] {
const latest = new Map<string, BlockState>();
for (const block of blocks) {
@@ -1859,30 +1902,6 @@ export function latestBlocksByLabel(blocks: BlockState[]): BlockState[] {
return Array.from(latest.values());
}
-// Legacy prose heuristic, consulted only when the turn has no typed
-// adjudication (responseKind null).
-function asksUserForInput(turn: TurnNarrativeState): boolean {
- if (turn.responseType === "ASK_QUESTION") {
- return true;
- }
- const text = `${turn.terminalMessage ?? ""} ${turn.narrativeSummary ?? ""}`
- .toLowerCase()
- .trim();
- return (
- text.includes("please provide") ||
- text.includes("please share") ||
- text.includes("could you provide") ||
- text.includes("can you provide") ||
- /^(which|what|where|who|when|how)\b[\s\S]*\?/.test(text)
- );
-}
-
-interface AdjudicatedParts {
- headline: string;
- accent: TurnSummary["accent"];
- glyph: string;
-}
-
export interface NotConfirmedOutcome {
verdict: "not_demonstrated";
displayReason: string | null;
@@ -1934,61 +1953,6 @@ export function notConfirmedOutcome(
return null;
}
-// Headline parts for non-build terminal response kinds. Build rows always use
-// lifecycle and run facts rather than a separate verification stamp.
-function adjudicatedSummaryParts(
- turn: TurnNarrativeState,
- flags: {
- needsUntestedProposalReview: boolean;
- needsTestedProposalReview: boolean;
- hasEdited: boolean;
- hasDrafts: boolean;
- },
-): AdjudicatedParts | null {
- if (turn.responseKind === null) return null;
- // Disposition-first (rule A): a pending draft review outranks why the turn
- // ended, regardless of responseKind (including non-build/clarify turns).
- if (flags.needsUntestedProposalReview) {
- return { headline: "Draft needs review", accent: "qa", glyph: "!" };
- }
- if (flags.needsTestedProposalReview) {
- return { headline: "Workflow ready for review", accent: "qa", glyph: "!" };
- }
- if (turn.responseKind !== "build") {
- if (turn.responseKind === "refuse") {
- return { headline: "Declined", accent: "qa", glyph: "✦" };
- }
- if (turn.responseKind === "answer" || turn.responseKind === "diagnose") {
- return { headline: "Answered", accent: "qa", glyph: "✦" };
- }
- if (
- turn.responseType !== "ASK_QUESTION" &&
- notConfirmedOutcome(turn)?.verdict === "not_demonstrated"
- ) {
- return { headline: "Outcome not confirmed", accent: "warn", glyph: "!" };
- }
- return {
- headline: "Needs your input",
- accent: "qa",
- glyph: "✦",
- };
- }
- if (flags.needsUntestedProposalReview) {
- return { headline: "Draft needs review", accent: "qa", glyph: "!" };
- }
- if (flags.needsTestedProposalReview) {
- return { headline: "Workflow ready for review", accent: "qa", glyph: "!" };
- }
- if (turn.responseType === "ASK_QUESTION") {
- return {
- headline: "Needs your input",
- accent: "qa",
- glyph: "✦",
- };
- }
- return null;
-}
-
// A deadline exit stamps terminal="error" for budget reasons; that is a halt,
// not a block failure, so no surface may give it failure's treatment.
export function isDeadlineHalt(turn: TurnNarrativeState): boolean {
@@ -1997,173 +1961,3 @@ export function isDeadlineHalt(turn: TurnNarrativeState): boolean {
!latestBlocksByLabel(turn.blocks).some((b) => b.state === "failed")
);
}
-
-export function computeTurnSummary(turn: TurnNarrativeState): TurnSummary {
- const rollupBlocks = latestBlocksByLabel(turn.blocks);
- // A cancelled turn's terminal is "error" purely because the user stopped it,
- // so that arm must not brand their own stop a failure.
- const anyBlockFailed = rollupBlocks.some((b) => b.state === "failed");
- const facts = turn.turnFacts;
- const deadlineHalt = isDeadlineHalt(turn);
- const isFail =
- !turn.cancelled &&
- !deadlineHalt &&
- (turn.terminal === "error" || anyBlockFailed);
- // A stop halts the turn without failing it — a user cancel, or a budget halt
- // that cancels a block mid-run. It suppresses a success verdict exactly like
- // a failure, but never wears failure's treatment. `turn.cancelled` is load
- // bearing on its own: a stop during the thinking phase, or on a QA turn,
- // touches no block at all and would otherwise read as a clean success.
- const isStopped =
- turn.cancelled ||
- deadlineHalt ||
- rollupBlocks.some((b) => b.state === "stopped");
- const mode = effectiveMode(turn);
- const needsInput = asksUserForInput(turn);
- const isQA =
- mode === "docs_answer" ||
- mode === "diagnose" ||
- mode === "clarify" ||
- mode === "refuse";
- const hasDrafts = (turn.draft?.blockCount ?? 0) > 0;
- const cleanFullCurrentSourceCoverage = ranCleanOnCurrentSource(facts);
- const needsUntestedProposalReview =
- hasDrafts && turn.proposalDisposition === "review_untested";
- // The tested framing is a claim like any other, so it reads the published verdict
- // rather than the disposition alone.
- const needsTestedProposalReview =
- hasDrafts &&
- turn.proposalDisposition === "review_tested" &&
- cleanFullCurrentSourceCoverage;
- const hasEdited = (turn.priorBlockCount ?? 0) > 0 && hasDrafts;
- const authoredBlockCount = facts?.factsAvailable
- ? facts.authoredBlockCount
- : null;
- const matchingSourceBlockCount = facts?.factsAvailable
- ? facts.matchingSourceBlockCount
- : null;
- const coverageKnown =
- authoredBlockCount !== null &&
- authoredBlockCount > 0 &&
- matchingSourceBlockCount !== null;
- const hasReviewableDraft =
- hasDrafts &&
- (turn.proposalDisposition === "review_untested" ||
- turn.proposalDisposition === "review_tested" ||
- (turn.cancelled && turn.proposalDisposition !== "no_proposal"));
- const isStoppedWithDraft = hasReviewableDraft && (isFail || isStopped);
-
- // Fail/cancel precedence is absolute: a verdict never upgrades a halt.
- const adjudicated =
- isStoppedWithDraft || isFail || isStopped
- ? null
- : adjudicatedSummaryParts(turn, {
- needsUntestedProposalReview,
- needsTestedProposalReview,
- hasEdited,
- hasDrafts,
- });
-
- const headline = adjudicated
- ? adjudicated.headline
- : isStoppedWithDraft
- ? "Stopped with a draft"
- : isFail
- ? "Run halted"
- : isStopped
- ? "Stopped"
- : needsUntestedProposalReview
- ? "Draft needs review"
- : needsTestedProposalReview
- ? "Workflow ready for review"
- : needsInput
- ? "Needs your input"
- : isQA
- ? mode === "refuse"
- ? "Declined"
- : mode === "clarify"
- ? "Needs your input"
- : "Answered"
- : cleanFullCurrentSourceCoverage
- ? "Every block ran clean on the current draft"
- : hasEdited
- ? "Applied edits"
- : hasDrafts
- ? "Built the workflow"
- : "Completed the run";
-
- const stats: string[] = [];
- const turnElapsed = formatElapsed(turn.startedAt, turn.endedAt);
- if (turnElapsed) stats.push(turnElapsed);
- if (!isQA) {
- const ok = rollupBlocks.filter((b) => isBlockOk(b)).length;
- const failed = rollupBlocks.filter((b) => b.state === "failed").length;
- const stopped = rollupBlocks.filter((b) => b.state === "stopped").length;
- const newBlocks = hasEdited ? 0 : (turn.draft?.blockCount ?? 0);
- if (coverageKnown) {
- stats.push(
- `${authoredBlockCount} block${authoredBlockCount === 1 ? "" : "s"} authored`,
- );
- stats.push(
- `${matchingSourceBlockCount}/${authoredBlockCount} ran on current source`,
- );
- if (facts?.runCompleted === true) {
- stats.push("run completed");
- } else if (facts?.runCompleted === false) {
- stats.push("run did not complete");
- }
- if (facts?.evaluationState === "not_evaluated") {
- stats.push("outcome not evaluated");
- } else if (facts?.evaluationState === "not_demonstrated") {
- stats.push("outcome not confirmed");
- }
- if (facts?.terminalCause === "deadline_expired") {
- stats.push("time limit reached");
- }
- } else {
- if (ok) stats.push(`${ok} block${ok === 1 ? "" : "s"} ran`);
- if (newBlocks) stats.push(`${newBlocks} new`);
- }
- if (failed) stats.push(`${failed} failed`);
- if (stopped) stats.push(`${stopped} stopped`);
- }
-
- const accent = adjudicated
- ? adjudicated.accent
- : isStoppedWithDraft
- ? "qa"
- : isFail
- ? "fail"
- : isStopped ||
- needsUntestedProposalReview ||
- needsTestedProposalReview ||
- isQA ||
- (hasDrafts && !cleanFullCurrentSourceCoverage)
- ? "qa"
- : "ok";
- return {
- headline,
- stats,
- accent,
- glyph: adjudicated
- ? adjudicated.glyph
- : isStoppedWithDraft ||
- needsUntestedProposalReview ||
- needsTestedProposalReview ||
- // A draft still awaiting review never wears a success tick, whether or not
- // facts back its tested framing.
- (hasDrafts && turn.proposalDisposition === "review_tested")
- ? "!"
- : isFail
- ? "✕"
- : isStopped
- ? "■"
- : isQA
- ? "✦"
- : "✓",
- isFail,
- isStopped,
- isQA,
- isStoppedWithDraft,
- };
-}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts
index 5ca22fe17..678af7a4e 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts
@@ -11,6 +11,14 @@ export type ProposalDisposition =
| "review_tested";
export type CopilotResponseType = "REPLY" | "ASK_QUESTION" | "REPLACE_WORKFLOW";
+// One thing a terminal ASK_QUESTION asks. `choices` is what the model offered,
+// never the set of answers accepted: the composer always takes free-form text.
+export interface QuestionPart {
+ part_id: string;
+ prompt: string;
+ choices: string[];
+}
+
export interface ConnectedAccountChoice {
connection_id: string;
name: string;
diff --git a/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2 b/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2
index ba6f3acc6..61a0c1819 100644
--- a/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2
+++ b/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2
@@ -39,8 +39,9 @@ RESPONSE-TYPE CLASSIFICATION: if information is required before you can continue
{ "type": "REPLY", "user_response": "Short, plain-language.", "global_llm_context": { ... } }
When you built or tested something, lead with the outcome and its tested status. When you answered a question and changed nothing, just answer it.
**Option 2: Ask a blocking question**
-{ "type": "ASK_QUESTION", "user_response": "The specific question, 1-2 sentences.", "ask_subject": "output_schema | credentials | target_url | disambiguation | deliverable_permission | other", "connected_account_choices": [{"connection_id": "The exact connection_id returned by list_integrations"}], "global_llm_context": { ... } }
-When `list_integrations` returns an active, scope-compatible connection identified by the user's request, bind that row's exact `connection_id` as the native block's `credential_id` and continue without asking the user to repeat the opaque ID or click an account choice. For a build-and-test request, pass the completed workflow and bound block label to `update_and_run_blocks` in the same turn; do not stop at `update_workflow`. If the requested account remains ambiguous among compatible active rows, or no compatible active row exists, ask a grounded ordinary-language question; when the user must choose among Google connections, include one `connected_account_choices` entry per relevant connection in presentation order. Include only `connection_id`; omit the field for every other question.
+{ "type": "ASK_QUESTION", "user_response": "The specific question, 1-2 sentences.", "ask_subject": "output_schema | credentials | target_url | disambiguation | deliverable_permission | other", "parts": [{"prompt": "One thing you are asking", "choices": ["An answer the user can pick", "Another"]}], "connected_account_choices": [{"connection_id": "The exact connection_id returned by list_integrations"}], "global_llm_context": { ... } }
+Break the question into `parts` — one entry per separate thing you are asking, in the order you ask them, so a user who can answer only some of them can. Give a part `choices` when you know the candidate answers; leave it empty when the answer is a value only the user holds. The user can always type a free-form answer, so `choices` is what you would list, not every answer you would accept.
+When `list_integrations` returns an active, scope-compatible connection identified by the user's request, bind that row's exact `connection_id` as the native block's `credential_id` and continue without asking the user to repeat the opaque ID or click an account choice. For a build-and-test request, pass the completed workflow and bound block label to `update_and_run_blocks` in the same turn; do not stop at `update_workflow`. If the requested account remains ambiguous among compatible active rows, or no compatible active row exists, ask a grounded ordinary-language question; when the user must choose among Google connections, include one `connected_account_choices` entry per relevant connection in presentation order. Include only `connection_id`; omit `connected_account_choices` for every other question.
Output valid JSON only — nothing before or after it, and the output must start with { — no label before it. The user works in a UI and is not aware of YAML; do not mention YAML.
Always carry global_llm_context forward, extending it each turn: user_goal, urls_visited (append, don't repeat), fields_filled, credentials_checked, decisions_made (concise), workflow_state (what blocks exist now).
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index 3b41181f0..3eac9fbef 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -185,8 +185,10 @@ from skyvern.forge.sdk.copilot.terminal_envelope import (
TESTED_DRAFT_PRESERVED,
UNTESTED_DRAFT_PRESERVED,
InterruptedTurnFacts,
+ QuestionPart,
TerminalCause,
TerminalOutcomeEnvelope,
+ admit_question_parts,
assemble_terminal_envelope,
is_interim_run_outcome,
reason_in_reply_shadow,
@@ -1682,6 +1684,7 @@ def _assemble_terminal_envelope_safe(
connect_failure: BuildTestConnectFailure | None = None,
proposal_present: bool = False,
interruption: InterruptedTurnFacts | None = None,
+ question_parts: Sequence[QuestionPart] = (),
) -> dict[str, Any] | None:
try:
envelope = assemble_terminal_envelope(
@@ -1701,6 +1704,7 @@ def _assemble_terminal_envelope_safe(
connect_failure=connect_failure,
proposal_present=proposal_present,
interruption=interruption,
+ question_parts=question_parts,
)
except Exception:
LOG.warning("copilot terminal envelope assembly failed", exc_info=True)
@@ -1934,6 +1938,7 @@ def _make_agent_result(
connect_failure=connect_failure,
proposal_present=result_carries_workflow,
interruption=_crash_exit_interruption(ctx, turn_outcome, failed_operation),
+ question_parts=ctx.question_parts,
)
if terminal_envelope is not None and (
terminal_envelope.get("failed_operation") is not None
@@ -3472,7 +3477,7 @@ async def _translate_to_agent_result(
normalized_scaffolding = normalize_response_scaffolding(resp_type, str(user_response))
resp_type = normalized_scaffolding.response_type
user_response = normalized_scaffolding.user_response or "Done."
- model_authored_account_choice_ask = resp_type == "ASK_QUESTION"
+ model_authored_ask = resp_type == "ASK_QUESTION"
# Bind the signal to a local so the proposal-cascade gating below can't
# desync from the inline override if ctx mutates mid-translate.
@@ -3802,7 +3807,7 @@ async def _translate_to_agent_result(
final_user_response = str(user_response)
connected_account_choices = await _verified_connected_account_choices(
action_data,
- response_type=resp_type if model_authored_account_choice_ask else "REPLY",
+ response_type=resp_type if model_authored_ask else "REPLY",
organization_id=organization_id,
)
if connected_account_choices:
@@ -3810,6 +3815,12 @@ async def _translate_to_agent_result(
# copy owns the choice interaction. Do not let model prose invite an
# account-name reply or mix password credentials into this OAuth path.
final_user_response = _connected_google_account_choice_reply()
+ # Parts describe the model's own question, so every path that replaces the reply with
+ # server-authored copy leaves them describing text the user never sees.
+ server_authored_reply = blocker_active or unbacked_workflow_delivery_rewritten or bool(connected_account_choices)
+ ctx.question_parts = (
+ admit_question_parts(action_data.get("parts")) if model_authored_ask and not server_authored_reply else []
+ )
attempted_kind = _concrete_narrative_response_kind(
response_type=resp_type,
has_workflow_attempt=ctx.has_genuine_workflow_attempt(),
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index 6632d5d75..08ddb46ea 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -66,6 +66,7 @@ if TYPE_CHECKING:
from skyvern.forge.sdk.copilot.request_policy import RequestPolicy
from skyvern.forge.sdk.copilot.result_evidence import ScoutObservationContract
from skyvern.forge.sdk.copilot.run_outcome import RecordedRunOutcome
+ from skyvern.forge.sdk.copilot.terminal_envelope import QuestionPart
from skyvern.forge.sdk.copilot.turn_halt import TurnHalt
from skyvern.forge.sdk.core.event_source_stream import EventSourceStream
from skyvern.forge.sdk.schemas.copilot_turn_outcome import ConnectedAccountChoice
@@ -631,6 +632,9 @@ class AgentContext:
blocker_signal: CopilotToolBlockerSignal | None = None
# Presentation-only recovery rows; authority remains in RequestPolicy.
connected_account_recovery_choices: list[ConnectedAccountChoice] = field(default_factory=list)
+ # Admitted parts of the model's own terminal question; set at final translation and read
+ # by the terminal-envelope assembler. Presentation-only, like the rows above.
+ question_parts: list[QuestionPart] = field(default_factory=list)
turn_halt: TurnHalt | None = None
# Most recently emitted blocker signal for the current tool output. Unlike
# blocker_signal, this is last-wins so the activity-log projection can
diff --git a/skyvern/forge/sdk/copilot/terminal_envelope.py b/skyvern/forge/sdk/copilot/terminal_envelope.py
index 0eea8d211..d5d3dd940 100644
--- a/skyvern/forge/sdk/copilot/terminal_envelope.py
+++ b/skyvern/forge/sdk/copilot/terminal_envelope.py
@@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Sequence
from typing import Literal
-from pydantic import BaseModel, model_validator
+from pydantic import BaseModel, ConfigDict, Field, model_validator
from skyvern.forge.sdk.copilot.blocker_signal import assert_clean_user_facing_text
from skyvern.forge.sdk.copilot.build_test_connect_failure import BuildTestConnectFailure
@@ -60,6 +60,62 @@ class InterruptedTurnFacts(BaseModel):
last_recorded_build_test_phase: str | None = None
+# A part's prompt and each of its choices are model-authored text that reaches the chat
+# unrendered by any other surface, so both are admitted the way every other model-authored
+# envelope string is. The length bound is a render bound, not a budget: a choice label is the
+# answer the user sends, so an over-long one is dropped rather than truncated — a truncated
+# label answers a different question than the one it shows. How many things one question may
+# ask and how many options one of them may offer are independent, so they get their own names.
+QUESTION_PART_TEXT_LIMIT = 200
+QUESTION_PART_LIMIT = 8
+QUESTION_CHOICE_LIMIT = 8
+
+
+class QuestionPart(BaseModel):
+ """One thing a terminal question asks, with the options the model offered for it.
+
+ ``part_id`` is minted server-side in emission order rather than read from the model, so
+ the identity a later answer or event refers to is the one the user actually saw.
+ """
+
+ model_config = ConfigDict(extra="ignore", frozen=True)
+
+ part_id: str
+ prompt: str
+ choices: list[str] = Field(default_factory=list)
+
+
+def admit_question_parts(raw: object) -> list[QuestionPart]:
+ """Typed admission for the ``parts`` array a model emits on an ASK_QUESTION.
+
+ Nothing here refuses the turn: the question's own prose always renders and the composer
+ always takes a free-form answer, so a part that cannot be vouched for is dropped and the
+ user still sees the whole question. A part with no admitted choices is kept — dropping it
+ would hide half of a compound ask behind an affordance for the other half.
+ """
+ if not isinstance(raw, list):
+ return []
+ parts: list[QuestionPart] = []
+ for entry in raw[:QUESTION_PART_LIMIT]:
+ if not isinstance(entry, dict):
+ continue
+ prompt = _safe_question_text(entry.get("prompt"))
+ if prompt is None:
+ continue
+ raw_choices = entry.get("choices")
+ candidates = raw_choices[:QUESTION_CHOICE_LIMIT] if isinstance(raw_choices, list) else []
+ admitted = [_safe_question_text(choice) for choice in candidates]
+ choices = list(dict.fromkeys(choice for choice in admitted if choice is not None))
+ parts.append(QuestionPart(part_id=f"p{len(parts) + 1}", prompt=prompt, choices=choices))
+ return parts
+
+
+def _safe_question_text(value: object) -> str | None:
+ if not isinstance(value, str) or len(value) > QUESTION_PART_TEXT_LIMIT:
+ return None
+ return _safe_output_report(value)
+
+
class TerminalOutcomeEnvelope(BaseModel):
next_state: TerminalNextState
verified: bool
@@ -88,6 +144,7 @@ class TerminalOutcomeEnvelope(BaseModel):
# None when the client named no gesture, so the report stays silent rather
# than naming one the request never carried.
cancel_source: CopilotCancelSource | None = None
+ question_parts: list[QuestionPart] = Field(default_factory=list)
rendered_from_envelope: bool = False
envelope_version: int = 1
@@ -117,6 +174,7 @@ def assemble_terminal_envelope(
connect_failure: BuildTestConnectFailure | None = None,
proposal_present: bool = False,
interruption: InterruptedTurnFacts | None = None,
+ question_parts: Sequence[QuestionPart] = (),
) -> TerminalOutcomeEnvelope | None:
run_outcome = select_run_outcome_anchor(run_outcomes)
run_outcome_role = run_outcome.role if run_outcome is not None else None
@@ -181,6 +239,8 @@ def assemble_terminal_envelope(
proposal_present=proposal_present,
proposal_disposition=proposal_disposition,
interruption=interruption,
+ # Parts describe a question, so they ride only a turn that actually ended on one.
+ question_parts=list(question_parts) if user_action_required else [],
)
diff --git a/skyvern/forge/sdk/routes/scripts.py b/skyvern/forge/sdk/routes/scripts.py
index f62e8563b..92e9d9489 100644
--- a/skyvern/forge/sdk/routes/scripts.py
+++ b/skyvern/forge/sdk/routes/scripts.py
@@ -171,7 +171,7 @@ async def get_script_blocks_response(
)
if not artifact:
- LOG.error(
+ LOG.warning(
"No artifact found for script file",
workflow_permanent_id=workflow_permanent_id,
organization_id=organization_id,
@@ -185,7 +185,7 @@ async def get_script_blocks_response(
data = await app.STORAGE.retrieve_artifact(artifact)
if not data:
- LOG.error(
+ LOG.warning(
"No data found for artifact",
workflow_permanent_id=workflow_permanent_id,
organization_id=organization_id,
diff --git a/skyvern/forge/sdk/routes/workflow_copilot.py b/skyvern/forge/sdk/routes/workflow_copilot.py
index 72f62fcda..2334c1f68 100644
--- a/skyvern/forge/sdk/routes/workflow_copilot.py
+++ b/skyvern/forge/sdk/routes/workflow_copilot.py
@@ -942,7 +942,7 @@ async def _persist_interrupted_turn(
narrative_payload = _with_terminal_narrative_metadata(
_make_error_narrative_payload(turn_id, None, message),
# An interrupted turn halted; it did not fail. The FE reads this flag to
- # keep the row out of failure treatment (computeTurnSummary, narrativeState.ts).
+ # keep the row out of failure treatment (derivePhases, copilotPhases.ts).
cancelled=True,
proposal_disposition=_proposal_disposition(None),
terminal_envelope=interrupted_terminal_envelope(facts).model_dump(mode="json"),
diff --git a/tests/unit/test_copilot_agent_helpers.py b/tests/unit/test_copilot_agent_helpers.py
index 6bfec10c8..1af135e36 100644
--- a/tests/unit/test_copilot_agent_helpers.py
+++ b/tests/unit/test_copilot_agent_helpers.py
@@ -2541,6 +2541,50 @@ class TestTranslateToAgentResultGating:
assert agent_result.response_type == "ASK_QUESTION"
assert agent_result.user_response == "Which account should I use?"
+ def test_model_authored_ask_carries_its_parts_onto_the_terminal_envelope(self) -> None:
+ ctx = _ctx()
+ result = _fake_run_result(
+ {
+ "type": "ASK_QUESTION",
+ "user_response": "Which store, and how should I pick the items?",
+ "parts": [
+ {"prompt": "Which store?", "choices": ["Acme Supply", "Borough Goods"]},
+ {"prompt": "Which email should get the receipt?", "choices": []},
+ ],
+ }
+ )
+
+ agent_result = asyncio.run(
+ agent_module._translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_chat_request(), organization_id="org-1"
+ )
+ )
+
+ assert agent_result.terminal_envelope is not None
+ assert agent_result.terminal_envelope["question_parts"] == [
+ {"part_id": "p1", "prompt": "Which store?", "choices": ["Acme Supply", "Borough Goods"]},
+ {"part_id": "p2", "prompt": "Which email should get the receipt?", "choices": []},
+ ]
+
+ def test_a_reply_never_carries_question_parts(self) -> None:
+ ctx = _ctx()
+ result = _fake_run_result(
+ {
+ "type": "REPLY",
+ "user_response": "Done.",
+ "parts": [{"prompt": "Which store?", "choices": ["Acme Supply"]}],
+ }
+ )
+
+ agent_result = asyncio.run(
+ agent_module._translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_chat_request(), organization_id="org-1"
+ )
+ )
+
+ assert agent_result.terminal_envelope is not None
+ assert agent_result.terminal_envelope["question_parts"] == []
+
def test_request_policy_actuation_claim_does_not_rewrite_model_reply(self) -> None:
ctx = _ctx(
request_policy=RequestPolicy(
diff --git a/tests/unit/test_copilot_terminal_envelope.py b/tests/unit/test_copilot_terminal_envelope.py
index c664c7fa7..6d1cfb113 100644
--- a/tests/unit/test_copilot_terminal_envelope.py
+++ b/tests/unit/test_copilot_terminal_envelope.py
@@ -32,9 +32,11 @@ from skyvern.forge.sdk.copilot.terminal_envelope import (
INTERRUPTED_TERMINAL_HEADLINE,
MINIMAL_CANCEL_STOP,
MINIMAL_HONEST_STOP,
+ QUESTION_PART_TEXT_LIMIT,
UNTESTED_DRAFT_PRESERVED,
InterruptedTurnFacts,
TerminalOutcomeEnvelope,
+ admit_question_parts,
assemble_terminal_envelope,
finalize_applied_state,
interim_run_start_outcome,
@@ -1741,3 +1743,22 @@ def test_only_a_stop_click_is_reported_as_the_user_asking() -> None:
drafted = render_terminal_message(with_draft, _CANCEL_REPLY_UNVALIDATED, cancelled=True)[0]
assert drafted.startswith(CANCEL_STOP_AT_USER_REQUEST)
assert UNTESTED_DRAFT_PRESERVED in drafted
+
+
+def test_admission_keeps_only_parts_the_server_can_vouch_for() -> None:
+ parts = admit_question_parts(
+ [
+ {"prompt": "Which store?", "choices": ["Acme", "Borough", "Acme", 7]},
+ "not a part",
+ {"prompt": "Which email?", "choices": []},
+ {"choices": ["no prompt"]},
+ {"prompt": "x" * (QUESTION_PART_TEXT_LIMIT + 1), "choices": ["kept out with its part"]},
+ {"prompt": "Which day?", "choices": ["Monday", "y" * (QUESTION_PART_TEXT_LIMIT + 1)]},
+ ]
+ )
+
+ assert [(part.part_id, part.prompt, part.choices) for part in parts] == [
+ ("p1", "Which store?", ["Acme", "Borough"]),
+ ("p2", "Which email?", []),
+ ("p3", "Which day?", ["Monday"]),
+ ]