-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d61d32
commit 397ddb8
Showing
27 changed files
with
425 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { useAuthBearerToken } from '../auth/auth.store'; | ||
import { API_BASE_URL } from '../constants'; | ||
import { AgentMemoryUpdate } from './agent-memory-update'; | ||
|
||
export const useAgentMemoryUpdateMutation = (userId: string | null | undefined) => { | ||
const queryClient = useQueryClient(); | ||
const bearerToken = useAuthBearerToken(); | ||
|
||
return useMutation({ | ||
mutationFn: async (params: AgentMemoryUpdate) => | ||
await fetch(API_BASE_URL + `/agents/memory?${userId}`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': ' application/json' }, | ||
headers: { 'Content-Type': ' application/json', Authorization: bearerToken }, | ||
body: JSON.stringify(params), | ||
}).then((res) => res.json()), | ||
onSuccess: (res, { agent_id }) => | ||
onSuccess: (_, { agent_id }) => | ||
queryClient.invalidateQueries({ queryKey: [userId, 'agents', 'entry', agent_id, 'memory'] }), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useAuthBearerToken } from '../auth/auth.store'; | ||
import { API_BASE_URL } from '../constants'; | ||
import { AgentMemory } from './agent-memory'; | ||
|
||
export const useAgentMemoryQuery = (userId: string | null | undefined, agentId: string | null | undefined) => | ||
useQuery({ | ||
export const useAgentMemoryQuery = (userId: string | null | undefined, agentId: string | null | undefined) => { | ||
const bearerToken = useAuthBearerToken(); | ||
return useQuery({ | ||
queryKey: [userId, 'agents', 'entry', agentId, 'memory'], | ||
queryFn: async () => | ||
(await fetch(API_BASE_URL + `/agents/memory?agent_id=${agentId}&user_id=${userId}`).then((res) => | ||
res.json() | ||
)) as Promise<AgentMemory>, | ||
(await fetch(API_BASE_URL + `/agents/memory?agent_id=${agentId}&user_id=${userId}`, { | ||
headers: { | ||
Authorization: bearerToken, | ||
}, | ||
}).then((res) => res.json())) as Promise<AgentMemory>, | ||
enabled: !!userId && !!agentId, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useAuthBearerToken } from '../auth/auth.store'; | ||
import { API_BASE_URL } from '../constants'; | ||
import { Agent } from './agent'; | ||
|
||
export const useAgentsQuery = (userId: string | null | undefined) => | ||
useQuery({ | ||
export const useAgentsQuery = (userId: string | null | undefined) => { | ||
const bearerToken = useAuthBearerToken(); | ||
return useQuery({ | ||
queryKey: [userId, 'agents', 'list'], | ||
enabled: !!userId, | ||
queryFn: async () => | ||
(await fetch(API_BASE_URL + `/agents?user_id=${userId}`).then((res) => res.json())) as Promise<{ | ||
(await fetch(API_BASE_URL + `/agents?user_id=${userId}`, { | ||
headers: { | ||
Authorization: bearerToken, | ||
}, | ||
}).then((res) => res.json())) as Promise<{ | ||
num_agents: number; | ||
agents: Agent[]; | ||
}>, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { API_BASE_URL } from '../constants'; | ||
import { useAuthStoreActions } from './auth.store'; | ||
|
||
export type AuthResponse = { uuid: string }; | ||
export const useAuthMutation = () => { | ||
const { setAsAuthenticated } = useAuthStoreActions(); | ||
return useMutation({ | ||
mutationKey: ['auth'], | ||
mutationFn: (password: string) => | ||
fetch(API_BASE_URL + `/auth`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': ' application/json' }, | ||
body: JSON.stringify({ password }), | ||
}).then((res) => { | ||
if (!res.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return res.json(); | ||
}) as Promise<AuthResponse>, | ||
onSuccess: (data, password) => setAsAuthenticated(data.uuid, password), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { useAuthBearerToken } from '../auth/auth.store'; | ||
import { API_BASE_URL } from '../constants'; | ||
import { Human } from './human'; | ||
|
||
export const useHumansCreateMutation = (userId: string | null | undefined) => { | ||
const queryClient = useQueryClient(); | ||
const bearerToken = useAuthBearerToken(); | ||
return useMutation({ | ||
mutationFn: async (params: { name: string; text: string }): Promise<Human> => { | ||
const response = await fetch(API_BASE_URL + '/agents', { | ||
method: 'POST', | ||
headers: { 'Content-Type': ' application/json', Authorization: bearerToken }, | ||
body: JSON.stringify({ config: params, user_id: userId }), | ||
}); | ||
|
||
if (!response.ok) { | ||
// Throw an error if the response is not OK | ||
const errorBody = await response.text(); | ||
throw new Error(errorBody || 'Error creating human'); | ||
} | ||
|
||
return await response.json(); | ||
}, | ||
onSuccess: () => queryClient.invalidateQueries({ queryKey: [userId, 'humans', 'list'] }), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useAuthBearerToken } from '../auth/auth.store'; | ||
import { API_BASE_URL } from '../constants'; | ||
|
||
export const useMessagesQuery = ( | ||
userId: string | null | undefined, | ||
agentId: string | null | undefined, | ||
start = 0, | ||
count = 10 | ||
) => | ||
useQuery({ | ||
) => { | ||
const bearerToken = useAuthBearerToken(); | ||
return useQuery({ | ||
queryKey: [userId, 'agents', 'item', agentId, 'messages', 'list', start, count], | ||
queryFn: async () => | ||
(await fetch( | ||
API_BASE_URL + `/agents/message?agent_id=${agentId}&user_id=${userId}&start=${start}&count=${count}` | ||
API_BASE_URL + `/agents/message?agent_id=${agentId}&user_id=${userId}&start=${start}&count=${count}`, | ||
{ | ||
headers: { | ||
Authorization: bearerToken, | ||
}, | ||
} | ||
).then((res) => res.json())) as Promise<{ | ||
messages: { role: string; name: string; content: string }[]; | ||
}>, | ||
enabled: !!userId && !!agentId, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.