mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 19:08:33 +01:00
feat(onboarding): create the first agent's setup draft in the naming step (#23315)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Onboarding creates a company, names its first agent, and then connects the agent to an AI provider > - A plugin can manage an execution environment that its driver prepares for each agent (`requiresAgent`). The agent's lifecycle starts that preparation when the agent's setup draft exists > - Onboarding created the setup draft when the connect step opened, after the agent was named > - The preparation can be slow, and a subscription sign-in in that environment waits for it > - This pull request creates the setup draft in the naming step, so the preparation overlaps naming > - The benefit is a shorter wait before sign-in when the default environment is plugin-managed ## Linked Issues or Issue Description Refs #23312. **What existing behavior does this improve?** The onboarding naming step and the connect step for a new company. **Current behavior** The wizard creates the first agent's provisional setup draft when the connect step opens. A plugin-managed execution environment starts its preparation for the agent only then. A subscription sign-in in that environment waits for the full preparation (see #23312). **Proposed behavior** The wizard creates the same provisional setup draft when the naming step opens for a company with no agents. The preparation runs while the user names the agent. **Reason and benefit** The preparation does not depend on the provider choice. A later configuration change prepares the same environment again, which is fast because the environment already exists. The user waits less before sign-in. ## What Changed - The naming step creates the provisional setup draft as soon as a company with no agents exists. The draft is the same record the connect step created before: a provisional adapter, `setupAdapterPending`, and the role label as a placeholder name. - The naming step saves the typed name to the draft after a 400 ms pause in typing. The connect step saves it at once, as before. - A company that has agents keeps the old path, so the connect step's same-name reuse still applies. A failed early create also falls back to the connect step. The wizard tries the early create once per company. - When the connect step restores a provisional draft (source still pending), the wizard keeps its own name, role and appearance when it has a name. A name typed after a reload in the naming step is newer than the draft's name. - The `create-company path` e2e test now expects the draft when the naming step opens. A new e2e test covers the early draft, the saved name, a reload in the naming step, and that the connect step adopts the same record. ## Verification - `pnpm typecheck` in `ui/`: no errors. - `PAPERCLIP_PLAYWRIGHT_CHANNEL=chrome npx playwright test --config tests/e2e/playwright.config.ts tests/e2e/onboarding-early-setup.spec.ts tests/e2e/onboarding.spec.ts -g "naming step creates|create-company path"`: 2 tests pass. - The new `onboarding-early-setup` test fails without the wizard change: it times out while it waits for the draft in the naming step. - I did not measure the time saved on a live plugin-managed execution environment. It is about the time the user spends in the naming step. ## Risks - A user who stops onboarding in the naming step leaves a setup draft. In a plugin-managed execution environment, that draft also keeps its prepared environment. Before this change, the same happened to a user who stopped in the connect step. - The draft's name is the role label until the first save in the naming step. A reload in the first 400 ms after typing can lose those characters. The wizard keeps the name that is typed after the reload. - No migration and no API change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), with extended thinking and tool use (code search, shell, tests) in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48deef0135
commit
630cf04230
3 files changed
+130
-18
No files matched your search
@@ -732,6 +732,7 @@ function OnboardingWizardInner({
|
||||
const [setupError, setSetupError] = useState(false);
|
||||
const [setupAttempt, setSetupAttempt] = useState(0);
|
||||
const preparingSetup = useRef(new Set<string>());
|
||||
const earlySetupTried = useRef(new Set<string>());
|
||||
const [restoredSetup, setRestoredSetup] = useState<Agent | null>(null);
|
||||
const setupSave = useRef<Promise<unknown>>(Promise.resolve());
|
||||
const [createdCompanyGoalId, setCreatedCompanyGoalId] = useState<string | null>(
|
||||
@@ -1389,6 +1390,56 @@ function OnboardingWizardInner({
|
||||
&& !selectedSavedKey && (restoredSetup.adapterConfig.env as Record<string, unknown> | undefined)?.[apiKeyEnvKeyFor(adapterType)];
|
||||
const connectStepReady = Boolean(setupPrepared || createdAgentId) && sourceSelected && !adapterEnvLoading && !savedKeys.loading && runnerDiscoveryReady && !browserSignInUnavailable && connectionModelReady;
|
||||
|
||||
useEffect(() => {
|
||||
if (step !== 3 || !createdCompanyId || !setupAgentId || createdAgentId || setupPrepared
|
||||
|| preparingSetup.current.has(createdCompanyId) || setupError) return;
|
||||
const companyId = createdCompanyId;
|
||||
const id = setupAgentId;
|
||||
preparingSetup.current.add(companyId);
|
||||
void agentsApi.get(id, companyId).then(agent => {
|
||||
if (!stillTheSameCompany(companyId) || agent.id !== id || agent.companyId !== companyId
|
||||
|| agent.pauseReason !== "setup" || agent.metadata?.setupAdapterPending !== true) return;
|
||||
if (agent.name !== AGENT_ROLE_LABELS[agent.role]) setAgentName(current => current.trim() ? current : agent.name);
|
||||
setSetupPrepared(true);
|
||||
}).catch(() => {}).finally(() => {
|
||||
preparingSetup.current.delete(companyId);
|
||||
setSetupAttempt(attempt => attempt + 1);
|
||||
});
|
||||
}, [step, createdCompanyId, setupAgentId, createdAgentId, setupPrepared, setupError]);
|
||||
|
||||
useEffect(() => {
|
||||
if (step !== 3 || !createdCompanyId || !adapterRegistryLoaded || setupAgentId || createdAgentId
|
||||
|| setupPrepared || preparingSetup.current.has(createdCompanyId) || earlySetupTried.current.has(createdCompanyId)
|
||||
|| setupError) return;
|
||||
const companyId = createdCompanyId;
|
||||
earlySetupTried.current.add(companyId);
|
||||
preparingSetup.current.add(companyId);
|
||||
const id = crypto.randomUUID();
|
||||
void (async () => {
|
||||
if ((await agentsApi.list(companyId)).some(agent => agent.status !== "terminated")) return null;
|
||||
const provisionalAdapter = disabledTypes.has("process") ? recommendedAdapters[0]?.type : "process";
|
||||
if (!provisionalAdapter || !stillTheSameCompany(companyId)) return null;
|
||||
setSetupAgentId(id);
|
||||
return agentsApi.create(companyId, {
|
||||
setupId: id, name: AGENT_ROLE_LABELS[agentRole], appearance: agentAppearance,
|
||||
role: agentRole, adapterType: provisionalAdapter, adapterConfig: {},
|
||||
metadata: { setupAdapterPending: true },
|
||||
onboardingFirstAgent: true, runtimeConfig: buildNewAgentRuntimeConfig({ heartbeatEnabled: false }),
|
||||
});
|
||||
})().then(agent => {
|
||||
if (!agent || !stillTheSameCompany(companyId)) return;
|
||||
setSetupAgentId(agent.id);
|
||||
if (agent.pauseReason !== "setup" && agent.status !== "pending_approval") setCreatedAgentId(agent.id);
|
||||
setSetupPrepared(true);
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.agents.list(companyId) });
|
||||
}).catch(() => {
|
||||
if (stillTheSameCompany(companyId)) setSetupAgentId(current => current === id ? null : current);
|
||||
}).finally(() => {
|
||||
preparingSetup.current.delete(companyId);
|
||||
setSetupAttempt(attempt => attempt + 1);
|
||||
});
|
||||
}, [step, createdCompanyId, adapterRegistryLoaded, setupAgentId, createdAgentId, setupPrepared, setupError]);
|
||||
|
||||
useEffect(() => {
|
||||
if (step !== 4 || !createdCompanyId || !agentName.trim() || !adapterRegistryLoaded
|
||||
|| createdAgentId || setupPrepared || preparingSetup.current.has(createdCompanyId) || setupError
|
||||
@@ -1435,9 +1486,11 @@ function OnboardingWizardInner({
|
||||
if (!restoring && agent.name) setAgentName(current => current.trim() === agentName.trim() ? agent.name : current);
|
||||
if (restoring && agent.adapterConfig) {
|
||||
setRestoredSetup(agent);
|
||||
setAgentName(agent.name);
|
||||
setAgentRole(agent.role);
|
||||
setAgentAppearance(resolveAgentAppearance(agent.appearance, agent.id));
|
||||
if (!(agent.metadata?.setupAdapterPending === true && agentName.trim())) {
|
||||
setAgentName(agent.name);
|
||||
setAgentRole(agent.role);
|
||||
setAgentAppearance(resolveAgentAppearance(agent.appearance, agent.id));
|
||||
}
|
||||
const config = agent.adapterConfig;
|
||||
if (agent.metadata?.setupAdapterPending === true) {
|
||||
setRunner("auto");
|
||||
@@ -2262,7 +2315,7 @@ function OnboardingWizardInner({
|
||||
return { ...runtimeConfig, ...(!existingAgent ? buildNewAgentRuntimeConfig({ heartbeatEnabled }) : {}), ...(binding ? { aiConnection: binding } : {}) };
|
||||
}
|
||||
|
||||
const setupSnapshot = step === 4 && setupPrepared && setupAgentId && !createdAgentId && !loading
|
||||
const setupSnapshot = (step === 3 || step === 4) && setupPrepared && setupAgentId && !createdAgentId && !loading
|
||||
? JSON.stringify({ name: agentName.trim() || AGENT_ROLE_LABELS[agentRole], appearance: agentAppearance,
|
||||
...(sourceSelected && runnerDiscoveryReady ? {
|
||||
adapterType, runner,
|
||||
@@ -2276,14 +2329,19 @@ function OnboardingWizardInner({
|
||||
if (!setupSnapshot || !setupAgentId || !createdCompanyId) return;
|
||||
const companyId = createdCompanyId;
|
||||
const id = setupAgentId;
|
||||
setupSave.current = setupSave.current.catch(() => {}).then(async () => {
|
||||
if (!stillTheSameCompany(companyId) || hiringAgentRef.current !== null) return;
|
||||
await agentsApi.update(id, JSON.parse(setupSnapshot), companyId);
|
||||
});
|
||||
void setupSave.current.catch(cause => {
|
||||
if (stillTheSameCompany(companyId)) setError(cause instanceof Error ? cause.message : "Could not save agent setup.");
|
||||
});
|
||||
}, [setupSnapshot, setupAgentId, createdCompanyId]);
|
||||
const save = () => {
|
||||
setupSave.current = setupSave.current.catch(() => {}).then(async () => {
|
||||
if (!stillTheSameCompany(companyId) || hiringAgentRef.current !== null) return;
|
||||
await agentsApi.update(id, JSON.parse(setupSnapshot), companyId);
|
||||
});
|
||||
void setupSave.current.catch(cause => {
|
||||
if (stillTheSameCompany(companyId)) setError(cause instanceof Error ? cause.message : "Could not save agent setup.");
|
||||
});
|
||||
};
|
||||
if (step !== 3) { save(); return; }
|
||||
const timer = setTimeout(save, 400);
|
||||
return () => clearTimeout(timer);
|
||||
}, [setupSnapshot, setupAgentId, createdCompanyId, step]);
|
||||
|
||||
async function runAdapterEnvironmentTest(
|
||||
adapterConfigOverride?: Record<string, unknown>,
|
||||
|
||||
Reference in new issue
Block a user