feat(sessions): make session creation async and set active session

Dispatch active session id after successful creation to ensure UI reflects current state
This commit is contained in:
icarus 2025-09-22 17:55:21 +08:00
parent 1e9a811065
commit 42dbc6555c

View File

@ -34,14 +34,17 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
[dispatch]
)
const handleCreateSession = useCallback(() => {
const handleCreateSession = useCallback(async () => {
if (!agent) return
const session = {
...agent,
id: undefined
} satisfies CreateSessionForm
createSession(session)
}, [agent, createSession])
const created = await createSession(session)
if (created) {
dispatch(setActiveSessionIdAction({ agentId, sessionId: created.id }))
}
}, [agent, agentId, createSession, dispatch])
const currentActiveSessionId = activeSessionId[agentId]