Skip to content

The agent that grows with you

fix(desktop): the Capabilities draft keeps fields edited during its debounce

Teknium9e01b44dd239
diff --git a/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx b/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx
index d275af60c9b..1f6964abb28 100644
--- a/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx
@@ -216,9 +216,12 @@ describe('materializing the draft profile', () => {
// Mid-word keystrokes must not each mint (and orphan) a draft.
fireEvent.change(screen.getByPlaceholderText('inbox-triage'), { target: { value: 'late' } })
fireEvent.change(screen.getByPlaceholderText('inbox-triage'), { target: { value: 'late-name' } })
+ // Edited during the debounce: the draft must carry it, not the value from the last name change.
+ fireEvent.change(screen.getByPlaceholderText('Inbox Triage'), { target: { value: 'Late Title' } })
await waitFor(() => expect(mocks.skillsView.at(-1)).toMatchObject({ fixedProfile: 'late-name' }), { timeout: 3000 })
expect(createCalls().map(([, params]) => params.name)).toEqual(['late-name'])
+ expect(createCalls()[0][1].description).toBe('Late Title')
})
it('pins a remote-target draft to the TARGET machine, not the active gateway', async () => {
diff --git a/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx b/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx
index a927811a9e7..f787903d5b4 100644
--- a/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx
@@ -127,17 +127,19 @@ interface CreateAgentDialogProps {
* renames it) otherwise sat on a spinner forever. Debounced so typing a name
* does not mint a draft per keystroke. */
function useCapabilitiesDraft(ready: boolean, slug: string, draft: null | string, materialize: () => void) {
+ // The timer is keyed on the name, but must run the LATEST callback: a title
+ // or description typed during the wait belongs in the created profile.
+ const latest = useRef(materialize)
+ latest.current = materialize
+
useEffect(() => {
if (!ready || draft === slug) {
return
}
- const timer = window.setTimeout(materialize, 800)
+ const timer = window.setTimeout(() => latest.current(), 800)
return () => window.clearTimeout(timer)
- // materialize reads the current render's form state; re-arming on the
- // identity inputs is what matters.
- // eslint-disable-next-line react-hooks/exhaustive-deps
}, [ready, slug, draft])
}