AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(platform): multi-choice, answer review, full keyboard use and touch sizing for expert onboarding cards (#15874)
Ubbe02a4bb29aa2b
diff --git a/autogpt_platform/backend/backend/copilot/tools/ask_question.py b/autogpt_platform/backend/backend/copilot/tools/ask_question.pyindex 5f51856323..30a6c1034a 100644--- a/autogpt_platform/backend/backend/copilot/tools/ask_question.py+++ b/autogpt_platform/backend/backend/copilot/tools/ask_question.py@@ -181,7 +181,7 @@ def _parse_one(item: Any, idx: int) -> ClarifyingQuestion | None:options=options,# A free-text question has nothing to multi-select, so the flag is# dropped rather than sent on for the card to render a lone checkbox.- allow_multiple=bool(options) and _parse_allow_multiple(item),+ allow_multiple=bool(options) and parse_allow_multiple(item),)@@ -209,7 +209,7 @@ def _parse_options(raw: Any) -> list[str]:return list(unique)-def _parse_allow_multiple(item: dict[str, Any]) -> bool:+def parse_allow_multiple(item: dict[str, Any]) -> bool:"""Read the multi-select flag, tolerating the string a model may send.Anything else is False: a question defaults to one answer, and guessingdiff --git a/autogpt_platform/backend/backend/copilot/tools/expert_onboarding.py b/autogpt_platform/backend/backend/copilot/tools/expert_onboarding.pyindex 9c04632c01..8003309efe 100644--- a/autogpt_platform/backend/backend/copilot/tools/expert_onboarding.py+++ b/autogpt_platform/backend/backend/copilot/tools/expert_onboarding.py@@ -7,6 +7,7 @@ from typing import Anyfrom backend.copilot.model import ChatSession+from .ask_question import parse_allow_multiplefrom .base import BaseToolfrom .models import (ErrorResponse,@@ -93,10 +94,21 @@ class ExpertOnboardingTool(BaseTool):"description": (f"2-{MAX_OPTIONS} answers the user can ""tap, 1-5 words each, concrete and "- "specific to your role. Exactly one is "- "chosen. Leave out "- "'not sure', 'later' and 'skip' answers: "- "the card already offers Other and Skip."+ "specific to your role. One is chosen "+ "unless 'allow_multiple' is set. Leave "+ "out 'not sure', 'later' and 'skip' "+ "answers: the card already offers Other "+ "and Skip."+ ),+ },+ "allow_multiple": {+ "type": "boolean",+ "description": (+ "Let the user pick several of 'options'. "+ "Set it when the answers combine ('which "+ "services?'); leave it out for a choice "+ "between alternatives. Ignored without "+ "options."),},"keyword": {@@ -245,10 +257,14 @@ def _parse_one(item: Any, index: int) -> ExpertOnboardingStep | None:else f"step-{index}")+ options = _parse_options(item.get("options"))return ExpertOnboardingStep(question=question.strip()[:MAX_QUESTION_LENGTH],keyword=keyword,- options=_parse_options(item.get("options")),+ options=options,+ # A free-text question has nothing to multi-select, so the flag is+ # dropped rather than sent on for the card to render a lone checkbox.+ allow_multiple=bool(options) and parse_allow_multiple(item),)diff --git a/autogpt_platform/backend/backend/copilot/tools/expert_onboarding_test.py b/autogpt_platform/backend/backend/copilot/tools/expert_onboarding_test.pyindex caccf6c67b..a95caccc49 100644--- a/autogpt_platform/backend/backend/copilot/tools/expert_onboarding_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/expert_onboarding_test.py@@ -122,6 +122,49 @@ async def test_step_without_options_is_open_ended(assert result.steps[0].options == []+async def test_step_can_take_several_answers(+ tool: ExpertOnboardingTool, session: ChatSession+):+ result = await tool._execute(+ user_id="test-user",+ session=session,+ greeting="Hi.",+ steps=[+ {+ "question": "Which services?",+ "options": ["Linear", "GitHub"],+ "allow_multiple": True,+ },+ # Models sometimes send the flag as a string.+ {+ "question": "Which channels?",+ "options": ["Email", "Slack"],+ "allow_multiple": "true",+ },+ {"question": "Which outcome?", "options": ["Briefs", "Reports"]},+ ],+ )++ assert isinstance(result, ExpertOnboardingResponse)+ assert [step.allow_multiple for step in result.steps] == [True, True, False]+++async def test_open_ended_step_drops_the_multi_select_flag(+ tool: ExpertOnboardingTool, session: ChatSession+):+ result = await tool._execute(+ user_id="test-user",+ session=session,+ greeting="Hi.",+ steps=[{"question": "Anything else?", "allow_multiple": True}],+ )++ assert isinstance(result, ExpertOnboardingResponse)+ assert result.steps[0].allow_multiple is False++@pytest.mark.asyncioasync def test_missing_keyword_falls_back_to_index(tool: ExpertOnboardingTool, session: ChatSessiondiff --git a/autogpt_platform/backend/backend/copilot/tools/models.py b/autogpt_platform/backend/backend/copilot/tools/models.pyindex d2cb6c5cc9..a7b8dda6ce 100644--- a/autogpt_platform/backend/backend/copilot/tools/models.py+++ b/autogpt_platform/backend/backend/copilot/tools/models.py@@ -873,6 +873,9 @@ class ExpertOnboardingStep(BaseModel):# Tappable answers. The card always offers a free-text escape as well, so# an empty list simply means "this one is open-ended".options: list[str] = Field(default_factory=list)+ # Several of `options` may be picked. Only ever set alongside options:+ # there is nothing to multi-select in a free-text question.+ allow_multiple: bool = Falseclass ExpertOnboardingResponse(ToolResponseBase):diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/new-chat-onboarding.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/new-chat-onboarding.test.tsxindex 67e1d37176..5f281d9276 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/new-chat-onboarding.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/new-chat-onboarding.test.tsx@@ -133,7 +133,10 @@ describe("new full-page expert chats", () => {const onSend = vi.fn();render(<ChatContainer {...props} onSend={onSend} />);fireEvent.click(await screen.findByRole("radio", { name: "AI" }));- fireEvent.click(screen.getByRole("button", { name: /Send answers/i }));+ // The pick moves on to the review after a short beat; Send lives there.+ fireEvent.click(+ await screen.findByRole("button", { name: /Send answers/i }),+ );await waitFor(() =>expect(onSend).toHaveBeenCalledWith("**Here are my answers:**\n\n> What topic?\n\nAI\n\nPlease proceed.",diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/ExpertOnboardingCard.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/ExpertOnboardingCard.tsxindex fe6cd49420..a87275736c 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/ExpertOnboardingCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/ExpertOnboardingCard.tsx@@ -1,12 +1,9 @@"use client";import { Icon } from "@/components/atoms/Icon/Icon";-import { cn } from "@/lib/utils";import {- ArrowLeft01Icon,ArrowRight01Icon,CheckmarkCircle02Icon,- SentIcon,} from "@hugeicons/core-free-icons";import type { ToolUIPart } from "ai";import { domAnimation, LazyMotion, m } from "framer-motion";@@ -16,6 +13,8 @@ import { AnsweredQuestions } from "../AnsweredQuestions/AnsweredQuestions";import { MorphingTextAnimation } from "../MorphingTextAnimation/MorphingTextAnimation";import { AnsweredQuestionsContext } from "../QuestionDock/AnsweredQuestionsContext";import { OnboardingChoices } from "./components/OnboardingChoices/OnboardingChoices";+import { OnboardingFooter } from "./components/OnboardingFooter";+import { OnboardingReview } from "./components/OnboardingReview";import { parseExpertOnboarding, type ExpertOnboardingOutput } from "./helpers";import { PendingOnboardingContext } from "./PendingOnboardingContext";import { useExpertOnboardingCard } from "./useExpertOnboardingCard";@@ -71,16 +70,21 @@ function OnboardingForm({ callId, onboarding, isLive }: FormProps) {const answers = useContext(AnsweredQuestionsContext).get(callId);const sectionId = useId();const {+ answer,+ answers,+ choicesRef,current,currentStep,- isAnswered,isDone,- isLast,+ isNextReview,+ isReady,+ isReview,isSending,- value,advance,choose,+ edit,goBack,+ handleKeyDown,setAnswer,skip,} = useExpertOnboardingCard({@@ -93,7 +97,7 @@ function OnboardingForm({ callId, onboarding, isLive }: FormProps) {? expertsById.get(onboarding.expertId): undefined;const name = expert?.name ?? "Your new hire";- const labelId = `${sectionId}-${currentStep.keyword}`;+ const labelId = `${sectionId}-${currentStep?.keyword ?? "review"}`;if (isDone) {// Skipped questions have no answer to show, so only answered ones stay.@@ -119,21 +123,29 @@ function OnboardingForm({ callId, onboarding, isLive }: FormProps) {}const total = onboarding.steps.length;+ const shown = Math.min(current + 1, total);return (- <div className="w-full max-w-xl overflow-hidden rounded-lg border border-zinc-200 bg-white shadow-[0_16px_40px_-24px_rgba(0,0,0,0.25)]">+ // Focusable so a click anywhere on the card brings its keys along.+ <div+ tabIndex={-1}+ onKeyDown={handleKeyDown}+ className="w-full max-w-xl overflow-hidden rounded-lg border border-zinc-200 bg-white shadow-[0_16px_40px_-24px_rgba(0,0,0,0.25)] outline-none"+ ><divrole="progressbar"aria-label="Setup progress"aria-valuemin={1}aria-valuemax={total}- aria-valuenow={current + 1}- aria-valuetext={`Question ${current + 1} of ${total}`}+ aria-valuenow={shown}+ aria-valuetext={+ isReview ? "Check your answers" : `Question ${shown} of ${total}`+ }className="h-1 bg-zinc-100"><divclassName="h-full bg-zinc-800 transition-[width] duration-300 ease-out"- style={{ width: `${((current + 1) / total) * 100}%` }}+ style={{ width: `${(shown / total) * 100}%` }}/></div>@@ -141,71 +153,64 @@ function OnboardingForm({ callId, onboarding, isLive }: FormProps) {``motion`` component below it. */}<LazyMotion features={domAnimation} strict><m.div- key={currentStep.keyword}+ key={currentStep?.keyword ?? "review"}initial={{ opacity: 0, y: 8 }}animate={{ opacity: 1, y: 0 }}transition={{ duration: 0.25, ease: [0.23, 1, 0.32, 1] }}- className="flex flex-col gap-4 px-5 pt-5"+ className="flex flex-col gap-4 px-4 pt-4 sm:px-5 sm:pt-5">- <span className="flex gap-2 text-lg font-medium leading-snug text-zinc-900">- <span- aria-hidden="true"- className="flex shrink-0 items-center gap-0.5 text-sm text-zinc-400"- >- {current + 1}- <Icon icon={ArrowRight01Icon} size={12} />- </span>- <span id={labelId}>{currentStep.question}</span>- </span>- <OnboardingChoices- key={currentStep.keyword}- options={currentStep.options}- value={value}- labelId={labelId}- autoFocus={current > 0}- onChoose={choose}- onChange={setAnswer}- onSubmit={advance}- />+ {currentStep ? (+ <>+ <span className="flex flex-col gap-1">+ <span className="flex gap-2 text-base font-medium leading-snug text-zinc-900 sm:text-lg">+ <span+ aria-hidden="true"+ className="flex shrink-0 items-center gap-0.5 text-sm text-zinc-400"+ >+ {current + 1}+ <Icon icon={ArrowRight01Icon} size={12} />+ </span>+ <span id={labelId}>{currentStep.question}</span>+ </span>+ {currentStep.allow_multiple && (+ <span className="text-sm text-zinc-500">+ Choose as many as you like+ </span>+ )}+ </span>+ <OnboardingChoices+ key={currentStep.keyword}+ ref={choicesRef}+ options={currentStep.options}+ answer={answer}+ isMultiple={currentStep.allow_multiple}+ labelId={labelId}+ onChoose={choose}+ onChange={setAnswer}+ onSubmit={advance}+ />+ </>+ ) : (+ <OnboardingReview+ steps={onboarding.steps}+ answers={answers}+ labelId={labelId}+ onEdit={edit}+ />+ )}</m.div></LazyMotion>- <div className="flex items-center justify-between px-5 pb-4 pt-4">- <button- type="button"- aria-label="Previous question"- disabled={current === 0}- onClick={goBack}- className="flex size-8 items-center justify-center rounded-md text-zinc-400 transition-colors enabled:hover:bg-zinc-100 enabled:hover:text-zinc-600 disabled:invisible"- >- <Icon icon={ArrowLeft01Icon} size={16} />- </button>- <div className="flex items-center gap-2">- <button- type="button"- onClick={skip}- disabled={isSending}- className="flex h-8 items-center rounded-md border border-zinc-200 bg-white px-3.5 text-sm font-medium text-zinc-700 transition-colors enabled:hover:border-zinc-300 enabled:hover:bg-zinc-50 disabled:opacity-50"- >- Skip questions- </button>- <button- type="button"- aria-label={isLast ? "Send answers" : "Next question"}- disabled={!isAnswered || isSending}- onClick={advance}- className={cn(- "flex h-8 items-center gap-1.5 rounded-md px-4 text-sm font-medium transition-all duration-200 enabled:active:scale-95",- isAnswered && !isSending- ? "bg-zinc-900 text-white hover:bg-zinc-800"- : "bg-zinc-100 text-zinc-400",- )}- >- {isLast ? "Send" : "Next"}- <Icon icon={isLast ? SentIcon : ArrowRight01Icon} size={14} />- </button>- </div>- </div>+ <OnboardingFooter+ canGoBack={current > 0}+ isReady={isReady}+ isReview={isReview}+ isNextReview={isNextReview}+ isSending={isSending}+ onBack={goBack}+ onSkip={skip}+ onNext={advance}+ /></div>);}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/__tests__/ExpertOnboardingCard.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/__tests__/ExpertOnboardingCard.test.tsxindex 8f46addff8..4b4c5744a6 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/__tests__/ExpertOnboardingCard.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/__tests__/ExpertOnboardingCard.test.tsx@@ -112,12 +112,41 @@ function isChecked(name: RegExp) {return screen.getByRole("radio", { name }).getAttribute("aria-checked");}-// A tap on a non-final step moves on by itself after a short beat.+// A tap moves on by itself after a short beat.async function answerFirstStep() {fireEvent.click(screen.getByRole("radio", { name: /Social listening/ }));await screen.findByText("Which service should I be connected to?");}+// The last question moves on to the review, not to Send.+async function answerLastStep() {+ fireEvent.click(screen.getByRole("radio", { name: /Linear/ }));+ await screen.findByText("Check your answers");+}++async function answerAllSteps() {+ await answerFirstStep();+ await answerLastStep();+}++function multiSelectPart() {+ return onboardingPart({+ steps: [+ {+ question: "Which services should I be connected to?",+ keyword: "services",+ options: ["Linear", "GitHub", "Figma"],+ allow_multiple: true,+ },+ {+ question: "Which outcome should I start with?",+ keyword: "outcome",+ options: ["Social listening", "Campaign briefs"],+ },+ ],+ });+}+describe("ExpertOnboardingCard", () => {it("leaves the expert's name and greeting to the thread header", () => {renderCard(onboardingPart());@@ -172,18 +201,41 @@ describe("ExpertOnboardingCard", () => {expect(questionNumber()).toBe("Question 1 of 2");});- it("will not send until the last step is answered", async () => {- renderCard(onboardingPart());+ it("shows every answer for review before anything is sent", async () => {+ const { onSend } = renderCard(onboardingPart());await answerFirstStep();- expect(actionButton("Send answers").disabled).toBe(true);+ expect(actionButton("Review answers").disabled).toBe(true);- fireEvent.click(screen.getByRole("radio", { name: /Linear/ }));+ await answerLastStep();- // The last tap only selects: sending waits for the button.+ expect(onSend).not.toHaveBeenCalled();+ expect(+ screen.getByRole("button", { name: /Which outcome.*Social listening/ }),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: /Which service.*Linear/ }),+ ).toBeDefined();expect(actionButton("Send answers").disabled).toBe(false);});+ it("jumps from the review to a question and straight back", async () => {+ renderCard(onboardingPart());+ await answerAllSteps();++ fireEvent.click(screen.getByRole("button", { name: /Which outcome/ }));++ expect(questionNumber()).toBe("Question 1 of 2");+ expect(isChecked(/Social listening/)).toBe("true");++ // The changed answer goes back to the review, not to question two.+ fireEvent.click(screen.getByRole("radio", { name: /Campaign briefs/ }));+ await screen.findByText("Check your answers");+ expect(+ screen.getByRole("button", { name: /Which outcome.*Campaign briefs/ }),+ ).toBeDefined();+ });+it("keeps the Next button for a typed answer, which cannot auto-advance", () => {renderCard(onboardingPart());@@ -200,11 +252,10 @@ describe("ExpertOnboardingCard", () => {expect(questionNumber()).toBe("Question 2 of 2");});- it("sends every answer as one message on the last step", async () => {+ it("sends every answer as one message from the review", async () => {const { onSend } = renderCard(onboardingPart());- await answerFirstStep();+ await answerAllSteps();- fireEvent.click(screen.getByRole("radio", { name: /Linear/ }));fireEvent.click(actionButton("Send answers"));expect(onSend).toHaveBeenCalledTimes(1);@@ -335,8 +386,15 @@ describe("ExpertOnboardingCard", () => {renderCard(onboardingPart());- expect(questionNumber()).toBe("Question 2 of 2");- expect(isChecked(/Linear/)).toBe("true");+ // The last pick was saved as a move to the review, so that is where the+ // reload lands, with both answers in place.+ expect(screen.getByText("Check your answers")).toBeDefined();+ expect(+ screen.getByRole("button", { name: /Which outcome.*Social listening/ }),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: /Which service.*Linear/ }),+ ).toBeDefined();});it("starts a different card from the beginning", async () => {@@ -356,8 +414,7 @@ describe("ExpertOnboardingCard", () => {onSend.mockResolvedValue(undefined);renderCard(onboardingPart(), CALL_ID, onSend);- await answerFirstStep();- fireEvent.click(screen.getByRole("radio", { name: /Linear/ }));+ await answerAllSteps();fireEvent.click(actionButton("Send answers"));await waitFor(() =>expect(screen.getByText(/Setup questions from/)).toBeDefined(),@@ -375,13 +432,162 @@ describe("ExpertOnboardingCard", () => {onSend.mockRejectedValue(new Error("no session"));renderCard(onboardingPart(), CALL_ID, onSend);- await answerFirstStep();- fireEvent.click(screen.getByRole("radio", { name: /Linear/ }));+ await answerAllSteps();fireEvent.click(actionButton("Send answers"));await waitFor(() => expect(onSend).toHaveBeenCalledTimes(1));- // Still the live form, with the answer intact — not a settled history row.- await waitFor(() => expect(isChecked(/Linear/)).toBe("true"));+ // Still the live form, with the answers intact — not a settled history row.+ await waitFor(() =>+ expect(actionButton("Send answers").disabled).toBe(false),+ );+ expect(+ screen.getByRole("button", { name: /Which service.*Linear/ }),+ ).toBeDefined();expect(screen.queryByText(/Setup questions from/)).toBeNull();});++ describe("multi-select questions", () => {+ it("ticks several options without moving on", async () => {+ renderCard(multiSelectPart());++ expect(screen.getAllByRole("checkbox")).toHaveLength(3);+ fireEvent.click(screen.getByRole("checkbox", { name: /Linear/ }));+ fireEvent.click(screen.getByRole("checkbox", { name: /Figma/ }));++ await new Promise((resolve) => setTimeout(resolve, 400));+ expect(questionNumber()).toBe("Question 1 of 2");+ expect(+ screen+ .getByRole("checkbox", { name: /Linear/ })+ .getAttribute("aria-checked"),+ ).toBe("true");+ expect(+ screen+ .getByRole("checkbox", { name: /Figma/ })+ .getAttribute("aria-checked"),+ ).toBe("true");++ fireEvent.click(actionButton("Next question"));+ expect(questionNumber()).toBe("Question 2 of 2");+ });++ it("sends the ticks and the typed text as a list", async () => {+ const { onSend } = renderCard(multiSelectPart());++ fireEvent.click(screen.getByRole("checkbox", { name: /Linear/ }));+ fireEvent.click(screen.getByRole("checkbox", { name: /GitHub/ }));+ fireEvent.click(screen.getByRole("button", { name: "Other" }));+ fireEvent.change(screen.getByRole("textbox"), {+ target: { value: "Notion" },+ });+ fireEvent.click(actionButton("Next question"));+ fireEvent.click(screen.getByRole("radio", { name: /Campaign briefs/ }));+ await screen.findByText("Check your answers");++ expect(+ screen.getByRole("button", {+ name: /Which services.*Linear, GitHub, Notion/,+ }),+ ).toBeDefined();++ fireEvent.click(actionButton("Send answers"));++ expect(onSend.mock.calls[0][0]).toContain(+ "> Which services should I be connected to?\n\n- Linear\n- GitHub\n- Notion",+ );+ });++ it("keeps the ticks after a reload", () => {+ renderCard(multiSelectPart());+ fireEvent.click(screen.getByRole("checkbox", { name: /GitHub/ }));+ cleanup();++ renderCard(multiSelectPart());++ expect(+ screen+ .getByRole("checkbox", { name: /GitHub/ })+ .getAttribute("aria-checked"),+ ).toBe("true");+ });+ });++ describe("keyboard", () => {+ it("puts the first question in focus", () => {+ renderCard(onboardingPart());++ expect(document.activeElement).toBe(+ screen.getByRole("radio", { name: /Social listening/ }),+ );+ });++ it("picks by letter from anywhere in the card", async () => {+ renderCard(onboardingPart());++ fireEvent.keyDown(+ screen.getByRole("button", { name: "Skip questions" }),+ {+ key: "b",+ },+ );++ expect(isChecked(/Campaign briefs/)).toBe("true");+ await screen.findByText("Which service should I be connected to?");+ });++ it("goes back with Backspace", async () => {+ renderCard(onboardingPart());+ await answerFirstStep();++ fireEvent.keyDown(screen.getByRole("radio", { name: /Linear/ }), {+ key: "Backspace",+ });++ expect(questionNumber()).toBe("Question 1 of 2");+ });++ it("skips with Escape", () => {+ const { onSend } = renderCard(onboardingPart());++ fireEvent.keyDown(+ screen.getByRole("radio", { name: /Social listening/ }),+ { key: "Escape" },+ );++ expect(onSend).toHaveBeenCalledWith(+ "Let's skip the setup questions for now.",+ );+ });++ it("leaves letters and Backspace to the Other text box", () => {+ const { onSend } = renderCard(onboardingPart());+ fireEvent.click(screen.getByRole("button", { name: "Other" }));+ const textarea = screen.getByRole("textbox");++ fireEvent.keyDown(textarea, { key: "a" });+ fireEvent.keyDown(textarea, { key: "Backspace" });+ fireEvent.keyDown(textarea, { key: "Escape" });++ expect(screen.queryByRole("radio", { checked: true })).toBeNull();+ expect(onSend).not.toHaveBeenCalled();+ });++ it("ignores keys while an IME is composing", () => {+ renderCard(onboardingPart());++ fireEvent.keyDown(+ screen.getByRole("radio", { name: /Social listening/ }),+ { key: "b", isComposing: true },+ );++ expect(screen.queryByRole("radio", { checked: true })).toBeNull();+ });++ it("moves focus to Send on the review", async () => {+ renderCard(onboardingPart());+ await answerAllSteps();++ expect(document.activeElement).toBe(actionButton("Send answers"));+ });+ });});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/OnboardingChoices.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/OnboardingChoices.tsxindex d1403f3890..32a917412f 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/OnboardingChoices.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/OnboardingChoices.tsx@@ -3,54 +3,71 @@import { Icon } from "@/components/atoms/Icon/Icon";import { cn } from "@/lib/utils";import { Tick02Icon } from "@hugeicons/core-free-icons";+import type { Ref } from "react";+import type { QuestionAnswer } from "../../../../tools/clarifying-questions";import { getOptionLetter } from "../../helpers";-import { useOnboardingChoices } from "./useOnboardingChoices";+import {+ useOnboardingChoices,+ type OnboardingChoicesHandle,+} from "./useOnboardingChoices";interface Props {+ ref?: Ref<OnboardingChoicesHandle>;options: string[];- value: string;+ answer: QuestionAnswer | undefined;+ isMultiple: boolean;labelId: string;- autoFocus: boolean;onChoose: (option: string) => void;- onChange: (value: string) => void;+ onChange: (answer: QuestionAnswer) => void;onSubmit: () => void;}/** One question's answers as lettered rows: a tap or its letter key picks- * the row, and the last row, "Other", opens a text box. Mounted per step,- * so the text box toggle starts fresh on every question. */+ * the row, and the last row, "Other", opens a text box. A multi-select+ * question ticks rows instead and keeps the typed text beside the ticks.+ * Mounted per step, so the text box toggle starts fresh on every question. */export function OnboardingChoices({+ ref,options,- value,+ answer,+ isMultiple,labelId,- autoFocus,onChoose,onChange,onSubmit,}: Props) {const {active,- didOpenOther,isTyping,optionRefs,+ selected,+ text,+ changeText,choose,startTyping,- handleLetterKey,handleOptionKeyDown,handleTextKeyDown,- } = useOnboardingChoices({ options, value, onChoose, onChange, onSubmit });+ } = useOnboardingChoices({+ ref,+ options,+ answer,+ isMultiple,+ onChoose,+ onChange,+ onSubmit,+ });return (<div className="flex flex-col gap-2">{options.length > 0 && (<div- role="radiogroup"+ role={isMultiple ? "group" : "radiogroup"}aria-labelledby={labelId}- aria-required="true"+ aria-required={isMultiple ? undefined : true}className="flex flex-col gap-2">{options.map((option, index) => {- const isSelected = option === value.trim();+ const isSelected = selected.includes(option);return (<buttonkey={option}@@ -58,14 +75,14 @@ export function OnboardingChoices({optionRefs.current[index] = element;}}type="button"- role="radio"+ role={isMultiple ? "checkbox" : "radio"}aria-checked={isSelected}tabIndex={index === active ? 0 : -1}- autoFocus={autoFocus && !isTyping && index === active}+ autoFocus={!isTyping && index === active}onClick={() => choose(option)}onKeyDown={(event) => handleOptionKeyDown(event, index)}className={cn(- "flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-[15px] leading-snug transition-colors",+ "flex w-full items-center gap-3 rounded-md px-3 py-3 text-left text-base leading-snug outline-none transition-colors focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:ring-offset-1 sm:py-2.5 sm:text-[15px] [@media(hover:none)]:min-h-11",isSelected? "bg-zinc-900 text-white": "bg-zinc-50 text-zinc-800 ring-1 ring-zinc-100 hover:bg-zinc-100",@@ -84,22 +101,23 @@ export function OnboardingChoices({{isTyping ? (<textarea- required+ required={!isMultiple}rows={2}aria-labelledby={labelId}- autoFocus={autoFocus || didOpenOther}- value={value}- onChange={(event) => onChange(event.target.value)}+ autoFocus+ enterKeyHint="next"+ value={text}+ onChange={(event) => changeText(event.target.value)}onKeyDown={handleTextKeyDown}- placeholder="Type your answer"- className="resize-none rounded-md bg-zinc-50 px-4 py-3 text-[15px] leading-relaxed text-zinc-800 ring-1 ring-zinc-200 transition-shadow placeholder:text-zinc-400 focus:outline-none focus:ring-zinc-400"+ placeholder={isMultiple ? "Add your own answer" : "Type your answer"}+ // 16px on phones: iOS zooms the page into any smaller text field.+ className="resize-none rounded-md bg-zinc-50 px-4 py-3 text-base leading-relaxed text-zinc-800 ring-1 ring-zinc-200 transition-shadow placeholder:text-zinc-400 focus:outline-none focus:ring-zinc-400 sm:text-[15px]"/>) : (<buttontype="button"onClick={startTyping}- onKeyDown={handleLetterKey}- className="flex w-full items-center gap-3 rounded-md border border-dashed border-zinc-200 px-3 py-2.5 text-left text-[15px] text-zinc-500 transition-colors hover:bg-zinc-50 hover:text-zinc-700"+ className="flex w-full items-center gap-3 rounded-md border border-dashed border-zinc-200 px-3 py-3 text-left text-base text-zinc-500 outline-none transition-colors hover:bg-zinc-50 hover:text-zinc-700 focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:ring-offset-1 sm:py-2.5 sm:text-[15px] [@media(hover:none)]:min-h-11"><LetterBadge index={options.length} isSelected={false} />Other@@ -114,12 +132,13 @@ interface LetterBadgeProps {isSelected: boolean;}+// Letter keys mean nothing on a touch screen, so neither do their badges.function LetterBadge({ index, isSelected }: LetterBadgeProps) {return (<spanaria-hidden="true"className={cn(- "flex size-6 shrink-0 items-center justify-center rounded-md text-xs font-medium",+ "flex size-6 shrink-0 items-center justify-center rounded-md text-xs font-medium [@media(hover:none)]:hidden",isSelected? "bg-white/15 text-white": "bg-white text-zinc-500 ring-1 ring-zinc-200",diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/useOnboardingChoices.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/useOnboardingChoices.tsindex 925d87db3c..187bf74f0c 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/useOnboardingChoices.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingChoices/useOnboardingChoices.ts@@ -1,53 +1,101 @@import { isComposingEvent, isKey } from "@/lib/keyboard";-import { useRef, useState, type KeyboardEvent } from "react";+import {+ useImperativeHandle,+ useRef,+ useState,+ type KeyboardEvent,+ type Ref,+} from "react";+import {+ toAnswerText,+ toMultiAnswer,+ type QuestionAnswer,+} from "../../../../tools/clarifying-questions";import { getLetterIndex } from "../../helpers";+export interface OnboardingChoicesHandle {+ /** Picks the row a bare letter key names. Returns whether it did. */+ pickLetter: (event: KeyboardEvent) => boolean;+}+interface Args {+ ref?: Ref<OnboardingChoicesHandle>;options: string[];- value: string;+ answer: QuestionAnswer | undefined;+ isMultiple: boolean;onChoose: (option: string) => void;- onChange: (value: string) => void;+ onChange: (answer: QuestionAnswer) => void;onSubmit: () => void;}export function useOnboardingChoices({+ ref,options,- value,+ answer,+ isMultiple,onChoose,onChange,onSubmit,}: Args) {- const trimmed = value.trim();- const isCustom = trimmed.length > 0 && !options.includes(trimmed);+ // A single answer is one string, a tapped option or typed text. Several+ // answers keep the ticks and the typed text apart, so text that happens to+ // match an option is still the user's own words.+ const multi = toMultiAnswer(answer);+ const text = isMultiple ? multi.custom : toAnswerText(answer);+ const trimmed = text.trim();+ const selected = isMultiple+ ? multi.selected.filter((option) => options.includes(option))+ : options.filter((option) => option === trimmed);+ const isCustom =+ trimmed.length > 0 && (isMultiple || !options.includes(trimmed));const [isTyping, setIsTyping] = useState(isCustom || options.length === 0);- // A saved custom answer opens the text box on mount, but only a click on- // Other may pull focus into it.- const [didOpenOther, setDidOpenOther] = useState(false);+ const [active, setActive] = useState(() =>+ Math.max(options.indexOf(selected[0] ?? ""), 0),+ );const optionRefs = useRef<(HTMLButtonElement | null)[]>([]);- const selected = options.indexOf(trimmed);- const active = selected === -1 ? 0 : selected;++ useImperativeHandle(ref, () => ({ pickLetter }));++ function toggle(option: string) {+ const next = selected.includes(option)+ ? selected.filter((pick) => pick !== option)+ : [...selected, option];+ // Kept in the order offered, so the reply reads like the question.+ onChange({+ selected: options.filter((pick) => next.includes(pick)),+ custom: text,+ });+ }function choose(option: string) {+ setActive(options.indexOf(option));+ if (isMultiple) {+ toggle(option);+ return;+ }setIsTyping(false);onChoose(option);}function startTyping() {- if (!isCustom) onChange("");+ if (!isMultiple && !isCustom) onChange("");setIsTyping(true);- setDidOpenOther(true);}- // Arrows only move the selection: picking with them must not jump to the- // next question while the user is still browsing the list.+ function changeText(next: string) {+ onChange(isMultiple ? { selected, custom: next } : next);+ }++ // Arrows only move: picking with them must not jump to the next question+ // while the user is still browsing the list, or tick boxes on the way past.function moveTo(index: number) {- onChange(options[index]);+ setActive(index);+ if (!isMultiple) onChange(options[index]);optionRefs.current[index]?.focus();}- // A letter picks its row from anywhere in the list, the last one being- // "Other". Returns whether the key was used.- function handleLetterKey(event: KeyboardEvent) {+ // A letter picks its row, the last one being "Other".+ function pickLetter(event: KeyboardEvent) {if (isComposingEvent(event)) return false;const letter = getLetterIndex(event);if (letter === null || letter > options.length) return false;@@ -58,16 +106,18 @@ export function useOnboardingChoices({}function handleOptionKeyDown(event: KeyboardEvent, index: number) {- if (handleLetterKey(event)) return;+ const option = options[index];if (isKey(event, "Enter")) {event.preventDefault();- if (options[index] === trimmed) onSubmit();- else choose(options[index]);+ const isPicked = selected.includes(option);+ // With several answers, Enter is "done ticking" once any is ticked.+ if (isPicked || (isMultiple && selected.length > 0)) onSubmit();+ else choose(option);return;}if (isKey(event, " ")) {event.preventDefault();- choose(options[index]);+ choose(option);return;}const step = isKey(event, "ArrowDown", "ArrowRight")@@ -89,12 +139,13 @@ export function useOnboardingChoices({return {active,- didOpenOther,isTyping,optionRefs,+ selected,+ text,+ changeText,choose,startTyping,- handleLetterKey,handleOptionKeyDown,handleTextKeyDown,};diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingFooter.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingFooter.tsxnew file mode 100644index 0000000000..ee33ce8c7a--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingFooter.tsx@@ -0,0 +1,101 @@+"use client";++import { Icon } from "@/components/atoms/Icon/Icon";+import { cn } from "@/lib/utils";+import {+ ArrowLeft01Icon,+ ArrowRight01Icon,+ SentIcon,+} from "@hugeicons/core-free-icons";++interface Props {+ canGoBack: boolean;+ isReady: boolean;+ isReview: boolean;+ isNextReview: boolean;+ isSending: boolean;+ onBack: () => void;+ onSkip: () => void;+ onNext: () => void;+}++// Shortcut cues only help where there is a keyboard; on touch screens they+// are noise, so they show only where the pointer can hover.+const KEY_HINT =+ "hidden rounded border border-zinc-200 px-1 text-[11px] font-medium leading-4 text-zinc-400 [@media(hover:hover)]:inline";++export function OnboardingFooter({+ canGoBack,+ isReady,+ isReview,+ isNextReview,+ isSending,+ onBack,+ onSkip,+ onNext,+}: Props) {+ const isEnabled = isReady && !isSending;+ const label = isReview ? "Send" : isNextReview ? "Review" : "Next";+ const ariaLabel = isReview+ ? "Send answers"+ : isNextReview+ ? "Review answers"+ : "Next question";++ return (+ <div className="flex items-center justify-between gap-2 px-4 pb-4 pt-4 sm:px-5">+ <button+ type="button"+ aria-label="Previous question"+ aria-keyshortcuts="Backspace"+ disabled={!canGoBack}+ onClick={onBack}+ className="flex size-8 items-center justify-center rounded-md text-zinc-400 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-zinc-400 enabled:hover:bg-zinc-100 enabled:hover:text-zinc-600 disabled:invisible [@media(hover:none)]:size-11"+ >+ <Icon icon={ArrowLeft01Icon} size={16} />+ </button>+ <div className="flex items-center gap-2">+ <button+ type="button"+ aria-keyshortcuts="Escape"+ onClick={onSkip}+ disabled={isSending}+ className="flex h-8 items-center gap-2 rounded-md border border-zinc-200 bg-white px-3.5 text-sm font-medium text-zinc-700 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-zinc-400 enabled:hover:border-zinc-300 enabled:hover:bg-zinc-50 disabled:opacity-50 [@media(hover:none)]:h-11"+ >+ Skip questions+ <kbd aria-hidden="true" className={KEY_HINT}>+ Esc+ </kbd>+ </button>+ <button+ // Remounted on the review step so autoFocus lands on Send: the+ // question the focus was in has just unmounted.+ key={isReview ? "send" : "next"}+ type="button"+ aria-label={ariaLabel}+ aria-keyshortcuts="Enter"+ disabled={!isEnabled}+ autoFocus={isReview}+ onClick={onNext}+ className={cn(+ "flex h-8 items-center gap-1.5 rounded-md px-4 text-sm font-medium outline-none transition-all duration-200 focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:ring-offset-1 enabled:active:scale-95 [@media(hover:none)]:h-11",+ isEnabled+ ? "bg-zinc-900 text-white hover:bg-zinc-800"+ : "bg-zinc-100 text-zinc-400",+ )}+ >+ {label}+ <Icon icon={isReview ? SentIcon : ArrowRight01Icon} size={14} />+ {isEnabled && (+ <kbd+ aria-hidden="true"+ className={cn(KEY_HINT, "border-white/25 text-white/70")}+ >+ Enter ↵+ </kbd>+ )}+ </button>+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingReview.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingReview.tsxnew file mode 100644index 0000000000..5ae978ec34--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/components/OnboardingReview.tsx@@ -0,0 +1,52 @@+"use client";++import { Icon } from "@/components/atoms/Icon/Icon";+import { PencilEdit02Icon } from "@hugeicons/core-free-icons";+import type { QuestionAnswer } from "../../../tools/clarifying-questions";+import { getAnswerSummary, type ExpertOnboardingStep } from "../helpers";++interface Props {+ steps: ExpertOnboardingStep[];+ answers: Record<string, QuestionAnswer>;+ labelId: string;+ onEdit: (index: number) => void;+}++/** The step before Send: every answer on one screen, each a way back to its+ * question, since sending is the one move the user can't take back. */+export function OnboardingReview({ steps, answers, labelId, onEdit }: Props) {+ return (+ <div className="flex flex-col gap-4">+ <span+ id={labelId}+ className="text-base font-medium leading-snug text-zinc-900 sm:text-lg"+ >+ Check your answers+ </span>+ <ul aria-labelledby={labelId} className="flex flex-col gap-2">+ {steps.map((step, index) => (+ <li key={step.keyword}>+ <button+ type="button"+ onClick={() => onEdit(index)}+ className="group flex w-full items-start gap-3 rounded-md bg-zinc-50 px-3 py-2.5 text-left outline-none ring-1 ring-zinc-100 transition-colors hover:bg-zinc-100 focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:ring-offset-1 [@media(hover:none)]:min-h-11"+ >+ <span className="flex min-w-0 flex-1 flex-col gap-0.5">+ <span className="sr-only">Change your answer to </span>+ <span className="text-sm text-zinc-500">{step.question}</span>+ <span className="break-words text-base text-zinc-900 sm:text-[15px]">+ {getAnswerSummary(answers[step.keyword]) || "No answer yet"}+ </span>+ </span>+ <Icon+ icon={PencilEdit02Icon}+ size={16}+ className="mt-0.5 shrink-0 text-zinc-400 transition-colors group-hover:text-zinc-600"+ />+ </button>+ </li>+ ))}+ </ul>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/helpers.tsindex 2e08d8af5d..74e783554b 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/helpers.ts@@ -2,6 +2,11 @@ import type { ExpertOnboardingStep as ExpertOnboardingStepPayload } from "@/app/import { ResponseType } from "@/app/api/__generated__/models/responseType";import type { ToolUIPart, UIDataTypes, UIMessage, UITools } from "ai";import type { KeyboardEvent } from "react";+import {+ formatAnswer,+ toAnswerList,+ type QuestionAnswer,+} from "../../tools/clarifying-questions";export const EXPERT_ONBOARDING_PART_TYPE = "tool-expert_onboarding";@@ -42,7 +47,9 @@ function toStep(value: unknown, index: number): ExpertOnboardingStep | null {typeof option === "string" && option.trim() ? [option.trim()] : [],): [];- return { question: question.trim(), keyword, options };+ // A free-text question has nothing to tick, so the flag needs options.+ const allow_multiple = options.length > 0 && record?.allow_multiple === true;+ return { question: question.trim(), keyword, options, allow_multiple };}export function parseExpertOnboarding(@@ -76,13 +83,29 @@ export function getLetterIndex(event: KeyboardEvent): number | null {return index >= 0 && index < 26 ? index : null;}+/** Whether a keydown came from a field the user types into, where letters,+ * Backspace and Escape belong to the text rather than the card. */+export function isTextEntryTarget(target: EventTarget): boolean {+ if (!(target instanceof HTMLElement)) return false;+ return (+ target instanceof HTMLTextAreaElement ||+ target instanceof HTMLInputElement ||+ target.isContentEditable+ );+}++/** An answer as one line for the review list: picks joined by commas. */+export function getAnswerSummary(answer: QuestionAnswer | undefined): string {+ return toAnswerList(answer).join(", ");+}+export function buildOnboardingAnswersMessage(steps: ExpertOnboardingStep[],- answers: Record<string, string>,+ answers: Record<string, QuestionAnswer>,): string {const body = steps.flatMap((step) => {- const answer = (answers[step.keyword] ?? "").trim();+ const answer = formatAnswer(answers[step.keyword]);return answer ? [`> ${step.question}\n\n${answer}`] : [];}).join("\n\n");diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/onboardingProgress.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/onboardingProgress.tsindex 3bb4ac7200..3cd406fb93 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/onboardingProgress.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/onboardingProgress.ts@@ -6,9 +6,14 @@* tool call id is the same on both copies, so progress keyed by it survives* the swap — and, since it lives in sessionStorage, a reload mid-card too. */+import type {+ MultiAnswer,+ QuestionAnswer,+} from "../../tools/clarifying-questions";+export interface OnboardingProgress {step: number;- answers: Record<string, string>;+ answers: Record<string, QuestionAnswer>;}const KEY_PREFIX = "copilot:expert-onboarding-progress:";@@ -25,6 +30,24 @@ function getStorage(): Storage | null {}}+function isStringList(value: unknown): value is string[] {+ return (+ Array.isArray(value) && value.every((item) => typeof item === "string")+ );+}++// Progress saved before multi-select questions holds only strings, which+// still read as single answers.+function toAnswer(value: unknown): QuestionAnswer | null {+ if (typeof value === "string") return value;+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;+ const record = value as Partial<Record<keyof MultiAnswer, unknown>>;+ if (!isStringList(record.selected) || typeof record.custom !== "string") {+ return null;+ }+ return { selected: record.selected, custom: record.custom };+}+function toProgress(value: unknown): OnboardingProgress | null {if (!value || typeof value !== "object" || Array.isArray(value)) return null;const record = value as Record<string, unknown>;@@ -32,14 +55,15 @@ function toProgress(value: unknown): OnboardingProgress | null {typeof record.step === "number" && Number.isInteger(record.step)? Math.max(record.step, 0): 0;- const answers: Record<string, string> = {};+ const answers: Record<string, QuestionAnswer> = {};if (record.answers &&typeof record.answers === "object" &&!Array.isArray(record.answers)) {- for (const [keyword, answer] of Object.entries(record.answers)) {- if (typeof answer === "string") answers[keyword] = answer;+ for (const [keyword, raw] of Object.entries(record.answers)) {+ const answer = toAnswer(raw);+ if (answer !== null) answers[keyword] = answer;}}return { step, answers };diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/useExpertOnboardingCard.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/useExpertOnboardingCard.tsindex 40a357b886..abf2ce16b2 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/useExpertOnboardingCard.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ExpertOnboardingCard/useExpertOnboardingCard.ts@@ -1,10 +1,17 @@"use client";import { useMountEffect } from "@/hooks/useMountEffect";-import { useEffect, useRef, useState } from "react";+import { isComposingEvent, isKey } from "@/lib/keyboard";+import { useEffect, useRef, useState, type KeyboardEvent } from "react";+import {+ isAnswered,+ type QuestionAnswer,+} from "../../tools/clarifying-questions";import { useCopilotChatActions } from "../CopilotChatActionsProvider/useCopilotChatActions";+import type { OnboardingChoicesHandle } from "./components/OnboardingChoices/useOnboardingChoices";import {buildOnboardingAnswersMessage,+ isTextEntryTarget,type ExpertOnboardingStep,} from "./helpers";import {@@ -31,22 +38,31 @@ export function useExpertOnboardingCard({ callId, steps, isLive }: Args) {const [step, setStep] = useState(() => readOnboardingProgress(callId)?.step ?? 0,);- const [answers, setAnswers] = useState<Record<string, string>>(+ const [answers, setAnswers] = useState<Record<string, QuestionAnswer>>(() => readOnboardingProgress(callId)?.answers ?? {},);const [isSent, setIsSent] = useState(false);const [isSending, setIsSending] = useState(false);+ // Set while the user changes one answer from the review list, so Next takes+ // them straight back to it instead of through every later question.+ const [isEditing, setIsEditing] = useState(false);// The step a tapped option is about to move to. Saved in place of ``step``// so a remount inside the auto-advance beat still lands on the next// question instead of stranding the user on the one they just answered.const [advancingTo, setAdvancingTo] = useState<number | null>(null);const advanceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);+ const choicesRef = useRef<OnboardingChoicesHandle>(null);- const current = Math.min(step, steps.length - 1);- const currentStep = steps[current];- const value = answers[currentStep.keyword] ?? "";- const isAnswered = value.trim().length > 0;- const isLast = current === steps.length - 1;+ // One step past the last question lists every answer before Send.+ const reviewStep = steps.length;+ const current = Math.min(step, reviewStep);+ const isReview = current === reviewStep;+ const currentStep = isReview ? null : steps[current];+ const answer = currentStep ? answers[currentStep.keyword] : undefined;+ const isReady = isReview+ ? steps.every((s) => isAnswered(answers[s.keyword]))+ : isAnswered(answer);+ const nextStep = isEditing ? reviewStep : current + 1;// A card the thread has moved past renders as history, whether the answers// went out from this tab or from another one.const isDone = isSent || !isLive;@@ -66,30 +82,42 @@ export function useExpertOnboardingCard({ callId, steps, isLive }: Args) {setAdvancingTo(null);}- function setAnswer(next: string) {+ function goTo(index: number) {+ if (index === reviewStep) setIsEditing(false);+ setStep(index);+ }++ function setAnswer(next: QuestionAnswer) {+ if (!currentStep) return;cancelAutoAdvance();setAnswers((previous) => ({ ...previous, [currentStep.keyword]: next }));}- // A tapped option is a whole answer, so it moves on by itself. The last- // step waits for Send: sending is the one move the user can't take back.+ // A tapped option is a whole answer, so it moves on by itself. Nothing goes+ // out without the review step, so the last question moves on too.function choose(option: string) {setAnswer(option);- if (isLast) return;- const next = current + 1;+ const next = nextStep;setAdvancingTo(next);advanceTimer.current = setTimeout(() => {advanceTimer.current = null;setAdvancingTo(null);- setStep(next);+ goTo(next);}, AUTO_ADVANCE_MS);}function goBack() {cancelAutoAdvance();+ setIsEditing(false);setStep(Math.max(current - 1, 0));}+ function edit(index: number) {+ cancelAutoAdvance();+ setIsEditing(true);+ setStep(index);+ }+// Settling the card is what removes the user's only copy of their answers,// so it waits for the send to resolve. A rejected send (no session, dispatch// failure) leaves the form exactly as it was, still submittable.@@ -108,30 +136,62 @@ export function useExpertOnboardingCard({ callId, steps, isLive }: Args) {}function advance() {- if (!isAnswered) return;- if (!isLast) {- setStep(current + 1);+ if (!isReady) return;+ cancelAutoAdvance();+ if (isReview) {+ void send(buildOnboardingAnswersMessage(steps, answers));return;}- void send(buildOnboardingAnswersMessage(steps, answers));+ goTo(nextStep);}function skip() {void send(SKIP_MESSAGE);}+ // Keys for the whole card, not just the option list: letters pick, Enter+ // moves on, Backspace goes back and Escape skips. A text box keeps every+ // key for its text, and a row or button that handled a key itself has+ // already called preventDefault.+ function handleKeyDown(event: KeyboardEvent<HTMLElement>) {+ if (event.defaultPrevented || isComposingEvent(event)) return;+ if (isTextEntryTarget(event.target)) return;+ if (isKey(event, "Escape")) {+ event.preventDefault();+ skip();+ return;+ }+ if (isKey(event, "Backspace")) {+ event.preventDefault();+ if (current > 0) goBack();+ return;+ }+ // On a button Enter is that button's click.+ if (isKey(event, "Enter")) {+ if (event.target !== event.currentTarget) return;+ event.preventDefault();+ advance();+ return;+ }+ choicesRef.current?.pickLetter(event);+ }+return {+ answer,answers,+ choicesRef,current,currentStep,- isAnswered,isDone,- isLast,+ isReady,+ isReview,isSending,- value,+ isNextReview: !isReview && nextStep === reviewStep,advance,choose,+ edit,goBack,+ handleKeyDown,setAnswer,skip,};diff --git a/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/ExpertChatDrawer.test.tsx b/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/ExpertChatDrawer.test.tsxindex 772058084b..465a25d1f4 100644--- a/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/ExpertChatDrawer.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/ExpertChatDrawer.test.tsx@@ -491,7 +491,9 @@ describe("ExpertChatDrawer", () => {/>,);fireEvent.click(await screen.findByRole("radio", { name: "Pricing" }));- fireEvent.click(screen.getByRole("button", { name: "Send answers" }));+ fireEvent.click(+ await screen.findByRole("button", { name: "Send answers" }),+ );await waitFor(() => expect(createSession).toHaveBeenCalled());await waitFor(() =>expect(@@ -503,10 +505,8 @@ describe("ExpertChatDrawer", () => {).toBe(false),);expect(- screen- .getByRole("radio", { name: "Pricing" })- .getAttribute("aria-checked"),- ).toBe("true");+ screen.getByRole("button", { name: /Which outcome.*Pricing/ }),+ ).toBeDefined();});test("keeps settled setup out of new chats", async () => {diff --git a/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/onboarding-thread-reset.test.tsx b/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/onboarding-thread-reset.test.tsxindex 0c5a25011f..0751f2cf63 100644--- a/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/onboarding-thread-reset.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/team/components/ExpertChatDrawer/__tests__/onboarding-thread-reset.test.tsx@@ -51,7 +51,7 @@ test("an old chat creation cannot settle setup in a new thread", async () => {}const { rerender } = render(drawer(0));fireEvent.click(await screen.findByRole("radio", { name: "Pricing" }));- fireEvent.click(screen.getByRole("button", { name: "Send answers" }));+ fireEvent.click(await screen.findByRole("button", { name: "Send answers" }));await waitFor(() => expect(createSession).toHaveBeenCalledOnce());rerender(drawer(1));finishCreate();diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.jsonindex a8e8c858c7..872cb834cc 100644--- a/autogpt_platform/frontend/src/app/api/openapi.json+++ b/autogpt_platform/frontend/src/app/api/openapi.json@@ -25239,6 +25239,11 @@"items": { "type": "string" },"type": "array","title": "Options"+ },+ "allow_multiple": {+ "type": "boolean",+ "title": "Allow Multiple",+ "default": false}},"type": "object",