35 lines
1018 B
TypeScript
35 lines
1018 B
TypeScript
import type schema from "#triplit/schema";
|
|
import type { Entity } from "@triplit/client";
|
|
|
|
export const useAgents = async () => {
|
|
const triplit = useTriplitClient();
|
|
|
|
const { results: agents, unsubscribe } = await useQuery('agents', triplit, triplit.query('agents').Include('topics'));
|
|
|
|
const createAgent = async (): Promise<Readonly<Entity<typeof schema, 'agents'>> | null> => {
|
|
const { user } = useAuth();
|
|
if (!user.value) {
|
|
console.error('No user');
|
|
return null;
|
|
}
|
|
|
|
return triplit.insert('agents', {
|
|
name: 'New Agent',
|
|
userId: user.value.id,
|
|
systemPrompt: 'You are a helpful assistant.',
|
|
defaultModelId: null,
|
|
imageUrl: null,
|
|
createdAt: new Date().toISOString(),
|
|
});
|
|
};
|
|
|
|
return {
|
|
agents,
|
|
unsubscribe,
|
|
getAgent: (id: string) => {
|
|
return agents.value?.find((a: any) => a.id === id);
|
|
},
|
|
createAgent,
|
|
};
|
|
};
|