mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 23:12:38 +08:00
feat(hooks): add createSessionMessage to useSession hook
Expose new function to create messages for agent sessions and automatically refresh session data
This commit is contained in:
parent
5ddf9683b4
commit
01c7e509fd
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user