/** * Client-side helpers for authenticated Convex calls (AIM features). * * Every authQuery/authMutation needs `tokenHash`; this module reads it from * chatState so components only pass their own args. */ import { useConvexClient, useQuery } from 'convex-svelte'; import { api } from '../../convex/_generated/api'; import type { FunctionReference, FunctionArgs } from 'convex/server'; import type { Id } from '../../convex/_generated/dataModel'; import { chatState } from '$lib/states/chat.svelte'; import { browser } from '$app/environment'; import { env } from '$env/dynamic/public'; export const convexAvailable = browser && Boolean(env.PUBLIC_CONVEX_URL); /** Returns the current tokenHash or null when signed out. Reactive when read inside $derived. */ export function tokenHash() { return chatState.getSessionTokenHash(); } /** * Subscribe to an authenticated query. Must be called at component init * (top level of