mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 04:29:01 +01:00
Resume unnamed first agents at the naming step
This commit is contained in:
1 parent
9a5d1e8cfd
commit
9b759bc07e
5 files changed
+33
-3
No files matched your search
@@ -31,6 +31,11 @@ test.describe("Onboarding wizard", () => {
|
||||
const readDraft = async () =>
|
||||
(await (await page.request.get(`/api/agents/${draft.id}?companyId=${companyId}`)).json()) as { name: string };
|
||||
|
||||
// The dashboard resumes the provisional record even if the browser closed
|
||||
// before its owner entered a name.
|
||||
const company = await (await page.request.get(`/api/companies/${companyId}`)).json();
|
||||
await page.goto(`/${company.issuePrefix}/dashboard`);
|
||||
await expect(nameField).toBeVisible();
|
||||
await nameField.fill("Ada");
|
||||
await expect.poll(async () => (await readDraft()).name, { timeout: 15_000 }).toBe("Ada");
|
||||
|
||||
|
||||
@@ -3,12 +3,21 @@ import { claimOnboardingOffer, dashboardOnboardingOptions, resetOnboardingOffers
|
||||
|
||||
describe("dashboard onboarding recovery", () => {
|
||||
const setup = { id: "setup-1", companyId: "company-1", pauseReason: "setup" as const, status: "paused" as const };
|
||||
const draft = JSON.stringify({ createdCompanyId: "company-1", setupAgentId: "setup-1", step: 4 });
|
||||
const draft = JSON.stringify({ createdCompanyId: "company-1", setupAgentId: "setup-1", agentName: "Ada", step: 4 });
|
||||
|
||||
it("resumes the saved setup after a reload", () => {
|
||||
expect(dashboardOnboardingOptions("company-1", [setup], draft)).toEqual({ companyId: "company-1", initialStep: 4 });
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ step: 3, agentName: "Ada" },
|
||||
{ step: 4, agentName: "" },
|
||||
{ step: 4, agentName: " " },
|
||||
])("returns unfinished naming drafts to the name field (%j)", (fields) => {
|
||||
const raw = JSON.stringify({ ...JSON.parse(draft), ...fields });
|
||||
expect(dashboardOnboardingOptions("company-1", [setup], raw)).toEqual({ companyId: "company-1", initialStep: 3 });
|
||||
});
|
||||
|
||||
it("waits for agents and starts an empty company at the agent step", () => {
|
||||
expect(dashboardOnboardingOptions("company-1", undefined, draft)).toBeNull();
|
||||
expect(dashboardOnboardingOptions("company-1", [], null)).toEqual({ companyId: "company-1", initialStep: 3 });
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Agent } from "@paperclipai/shared";
|
||||
import { firstAgentResumeStep } from "./onboarding-state";
|
||||
import { ONBOARDING_AGENT_STEP } from "./onboarding-route";
|
||||
|
||||
/** Resume only the draft this browser saved, while no completed agent exists. */
|
||||
@@ -14,7 +15,7 @@ export function dashboardOnboardingOptions(
|
||||
const draft = JSON.parse(rawDraft ?? "null");
|
||||
if (draft?.createdCompanyId !== companyId || draft.createdAgentId
|
||||
|| !agents.some(agent => agent.id === draft.setupAgentId && agent.companyId === companyId)) return null;
|
||||
return { companyId, initialStep: 4 };
|
||||
return { companyId, initialStep: firstAgentResumeStep(draft) };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ import { restoreOnboardingState } from "./onboarding-state";
|
||||
const companies = [{ id: "company-new" }];
|
||||
|
||||
describe("restoreOnboardingState", () => {
|
||||
it("recovers an unnamed setup agent saved on the connect step", () => {
|
||||
const saved = { createdCompanyId: "company-new", setupAgentId: "draft-1", agentName: " ", step: 4 };
|
||||
expect(restoreOnboardingState(saved, companies)).toEqual({ ...saved, step: 3 });
|
||||
});
|
||||
|
||||
it("returns null for unusable input", () => {
|
||||
expect(restoreOnboardingState(null, companies)).toBeNull();
|
||||
expect(restoreOnboardingState("nonsense", companies)).toBeNull();
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
/** A provisional agent already exists while its owner is still choosing a name. */
|
||||
export function firstAgentResumeStep(draft: Record<string, unknown>): 3 | 4 {
|
||||
if (draft.step === 3 || typeof draft.agentName !== "string" || !draft.agentName.trim()) return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* localStorage is scoped per ORIGIN, not per account, so a browser that already
|
||||
* ran onboarding will happily hand a previous company's id to a brand new
|
||||
@@ -27,7 +33,11 @@ export function restoreOnboardingState(
|
||||
const companyId = saved.createdCompanyId;
|
||||
if (typeof companyId !== "string" || companyId === "") return saved;
|
||||
|
||||
return companies.some((c) => c.id === companyId) ? saved : null;
|
||||
if (!companies.some((c) => c.id === companyId)) return null;
|
||||
if (saved.step === 4 && saved.setupAgentId && !saved.createdAgentId) {
|
||||
saved.step = firstAgentResumeStep(saved);
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
// Exported so tests write/read the exact key the component uses, instead of
|
||||
|
||||
Reference in new issue
Block a user