import { useQuery } from "@tanstack/react-query"; import { listMemoryTasks } from "@/services/memory"; import { queryKeys } from "@/lib/query-keys"; import { useRuntimeContext } from "@/providers/runtime-context-provider"; import type { MemoryScope } from "@/types/memory"; export function useMemoryTasks( memoryStoreName: string, scope: MemoryScope | null, options?: { limit?: number; nextToken?: string; status?: string; minTimestamp?: string; maxTimestamp?: string; }, ) { const { context, ready } = useRuntimeContext(); return useQuery({ queryKey: queryKeys.memoryTasks( context.dataScopeKey, memoryStoreName, scope, options?.nextToken, options?.limit, { status: options?.status, minTimestamp: options?.minTimestamp, maxTimestamp: options?.maxTimestamp, }, ), queryFn: () => listMemoryTasks(memoryStoreName, scope!, options), enabled: ready && !!memoryStoreName && !!scope?.appId, }); }