From 01c7e509fd2169913050cdf0efa0ca546e8bb8a6 Mon Sep 17 00:00:00 2001 From: icarus Date: Fri, 19 Sep 2025 17:01:47 +0800 Subject: [PATCH] feat(hooks): add createSessionMessage to useSession hook Expose new function to create messages for agent sessions and automatically refresh session data --- src/renderer/src/hooks/agents/useSession.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/hooks/agents/useSession.ts b/src/renderer/src/hooks/agents/useSession.ts index 558d7a75f1..535c672a7e 100644 --- a/src/renderer/src/hooks/agents/useSession.ts +++ b/src/renderer/src/hooks/agents/useSession.ts @@ -29,11 +29,27 @@ export const useSession = (agentId: string, sessionId: string) => { [agentId, client, mutate, t] ) + const createSessionMessage = useCallback( + async (content: string) => { + if (!agentId || !sessionId) return + try { + await client.createMessage(agentId, sessionId, content) + // TODO: Can you return a created message value? + const result = await client.getSession(agentId, sessionId) + mutate(result) + } catch (error) { + window.toast.error(t('common.errors.create_message')) + } + }, + [agentId, sessionId, client, mutate, t] + ) + return { session: data, messages: data?.messages ?? [], error, isLoading, - updateSession + updateSession, + createSessionMessage } }