export const createConversationThoughtsCollection = (
conversationId: string
) => {
return createCollection(
queryCollectionOptions({
queryKey: ["conversation-thoughts", conversationId],
id: `conversation-thoughts-${conversationId}`,
schema: ThoughtSchema,
getKey: (thought) => thought.id,
queryFn: async () => {
const response = await listConversationThoughts({
query: { conversation_id: conversationId },
});
// Transform API response to match schema
return (
response?.data?.thoughts?.map((thought) => ({
...thought,
topic_id: thought.conversation_id, // Map conversation_id to topic_id
archived_at: thought.archived_at as Date | null | undefined,
reply_to_id: thought.reply_to_id as string | null | undefined,
})) ?? []
);
},
queryClient,
onInsert: async ({ transaction }) => {
...
},
onUpdate: async ({ transaction }) => {
...
},
onDelete: async ({ transaction }) => {
...
},
})
);
};
export const createConversationThoughtsCollection = (
conversationId: string
) => {
return createCollection(
queryCollectionOptions({
queryKey: ["conversation-thoughts", conversationId],
id: `conversation-thoughts-${conversationId}`,
schema: ThoughtSchema,
getKey: (thought) => thought.id,
queryFn: async () => {
const response = await listConversationThoughts({
query: { conversation_id: conversationId },
});
// Transform API response to match schema
return (
response?.data?.thoughts?.map((thought) => ({
...thought,
topic_id: thought.conversation_id, // Map conversation_id to topic_id
archived_at: thought.archived_at as Date | null | undefined,
reply_to_id: thought.reply_to_id as string | null | undefined,
})) ?? []
);
},
queryClient,
onInsert: async ({ transaction }) => {
...
},
onUpdate: async ({ transaction }) => {
...
},
onDelete: async ({ transaction }) => {
...
},
})
);
};