Compare commits

...

1 Commits

Author SHA1 Message Date
yyh
eb74946b25 fix(web): save agent configure draft on route leave (#38620) 2026-07-09 13:55:34 +00:00
2 changed files with 40 additions and 6 deletions

View File

@ -315,6 +315,40 @@ describe('useAgentConfigureSync', () => {
})
})
it('should save the latest dirty draft when Configure unmounts before autosave runs', async () => {
const { store, unmount } = renderUseAgentConfigureSync()
act(() => {
store.set(agentComposerDraftAtom, {
...defaultAgentSoulConfigFormState,
prompt: 'Route leave prompt',
})
})
expect(composerPutMutationFn).not.toHaveBeenCalled()
await act(async () => {
unmount()
await Promise.resolve()
})
expect(composerPutMutationFn).toHaveBeenCalledTimes(1)
expect(composerPutMutationFn).toHaveBeenCalledWith(expect.objectContaining({
params: {
agent_id: 'agent-1',
},
body: expect.objectContaining({
variant: 'agent_app',
save_strategy: 'save_to_current_version',
agent_soul: expect.objectContaining({
prompt: expect.objectContaining({
system_prompt: 'Route leave prompt',
}),
}),
}),
}))
})
it('should include Agent Soul files when autosaving file changes', async () => {
const { store } = renderUseAgentConfigureSync()

View File

@ -208,12 +208,6 @@ export function useAgentConfigureSync({
})
}, [debouncedSaveDraft, getAgentSoulDraft, store])
useEffect(() => {
return () => {
debouncedSaveDraft.flush?.()
}
}, [debouncedSaveDraft])
useEffect(() => {
const saveDraftWhenPageHidden = () => {
if (document.visibilityState === 'hidden')
@ -232,6 +226,12 @@ export function useAgentConfigureSync({
}
}, [saveDirtyDraftOnPageClose])
useEffect(() => {
return () => {
saveDirtyDraftOnPageClose()
}
}, [saveDirtyDraftOnPageClose])
const publishDraft = useCallback(async () => {
if (publishInFlightRef.current)
return