@useatlas/react 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -2
  3. package/dist/{chunk-5SEVKHS5.cjs → chunk-35SCTKSW.js} +100 -7
  4. package/dist/chunk-35SCTKSW.js.map +1 -0
  5. package/dist/{chunk-UIRB6L36.cjs → chunk-DZFSZSQB.cjs} +46 -54
  6. package/dist/chunk-DZFSZSQB.cjs.map +1 -0
  7. package/dist/{chunk-2WFDP7G5.js → chunk-FMSGREKS.js} +46 -54
  8. package/dist/chunk-FMSGREKS.js.map +1 -0
  9. package/dist/{chunk-44HBZYKP.js → chunk-IDXGFWFS.cjs} +109 -3
  10. package/dist/chunk-IDXGFWFS.cjs.map +1 -0
  11. package/dist/global.d.ts +36 -0
  12. package/dist/hooks.cjs +10 -10
  13. package/dist/hooks.cjs.map +1 -1
  14. package/dist/hooks.d.cts +2 -2
  15. package/dist/hooks.d.ts +2 -2
  16. package/dist/hooks.js +3 -3
  17. package/dist/hooks.js.map +1 -1
  18. package/dist/index.cjs +385 -265
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +224 -4
  21. package/dist/index.d.ts +224 -4
  22. package/dist/index.js +328 -208
  23. package/dist/index.js.map +1 -1
  24. package/dist/lib/widget-types.d.ts +232 -0
  25. package/dist/{result-chart-YLCKBNV4.cjs → result-chart-ANZOT6FL.cjs} +24 -34
  26. package/dist/result-chart-ANZOT6FL.cjs.map +1 -0
  27. package/dist/{result-chart-NFAJ4IQ5.js → result-chart-C3EJTN5G.js} +22 -32
  28. package/dist/result-chart-C3EJTN5G.js.map +1 -0
  29. package/dist/widget.css +2 -2
  30. package/dist/widget.js +215 -246
  31. package/package.json +27 -17
  32. package/src/components/__tests__/data-table.test.tsx +125 -0
  33. package/src/components/actions/action-approval-card.tsx +26 -19
  34. package/src/components/actions/action-status-badge.tsx +3 -3
  35. package/src/components/atlas-chat.tsx +97 -37
  36. package/src/components/chart/result-chart.tsx +13 -37
  37. package/src/components/chat/api-key-bar.tsx +4 -4
  38. package/src/components/chat/data-table.tsx +42 -3
  39. package/src/components/chat/error-banner.tsx +108 -5
  40. package/src/components/chat/follow-up-chips.tsx +1 -1
  41. package/src/components/chat/managed-auth-card.tsx +6 -6
  42. package/src/components/conversations/conversation-item.tsx +19 -14
  43. package/src/components/conversations/conversation-list.tsx +3 -3
  44. package/src/components/conversations/conversation-sidebar.tsx +15 -4
  45. package/src/components/conversations/delete-confirmation.tsx +2 -2
  46. package/src/components/error-boundary.tsx +66 -0
  47. package/src/components/schema-explorer/schema-explorer.tsx +4 -0
  48. package/src/env.d.ts +9 -7
  49. package/src/global.d.ts +36 -0
  50. package/src/hooks/__tests__/use-atlas-conversations.test.tsx +4 -6
  51. package/src/hooks/use-atlas-chat.ts +1 -1
  52. package/src/hooks/use-atlas-conversations.ts +2 -2
  53. package/src/hooks/use-conversations.ts +60 -68
  54. package/src/index.ts +8 -0
  55. package/src/lib/action-types.ts +2 -2
  56. package/src/lib/helpers.ts +16 -16
  57. package/src/lib/types.ts +3 -2
  58. package/src/lib/widget-types.ts +232 -0
  59. package/src/test-setup.ts +2 -2
  60. package/dist/chunk-2WFDP7G5.js.map +0 -1
  61. package/dist/chunk-44HBZYKP.js.map +0 -1
  62. package/dist/chunk-5SEVKHS5.cjs.map +0 -1
  63. package/dist/chunk-UIRB6L36.cjs.map +0 -1
  64. package/dist/result-chart-NFAJ4IQ5.js.map +0 -1
  65. package/dist/result-chart-YLCKBNV4.cjs.map +0 -1
package/dist/hooks.d.cts CHANGED
@@ -118,8 +118,8 @@ interface UseAtlasConversationsReturn {
118
118
  setSelectedId: (id: string | null) => void;
119
119
  refresh: () => Promise<void>;
120
120
  loadConversation: (id: string) => Promise<UIMessage[] | null>;
121
- deleteConversation: (id: string) => Promise<boolean>;
122
- starConversation: (id: string, starred: boolean) => Promise<boolean>;
121
+ deleteConversation: (id: string) => Promise<void>;
122
+ starConversation: (id: string, starred: boolean) => Promise<void>;
123
123
  }
124
124
  /**
125
125
  * Manage conversation history with auth automatically wired from AtlasProvider.
package/dist/hooks.d.ts CHANGED
@@ -118,8 +118,8 @@ interface UseAtlasConversationsReturn {
118
118
  setSelectedId: (id: string | null) => void;
119
119
  refresh: () => Promise<void>;
120
120
  loadConversation: (id: string) => Promise<UIMessage[] | null>;
121
- deleteConversation: (id: string) => Promise<boolean>;
122
- starConversation: (id: string, starred: boolean) => Promise<boolean>;
121
+ deleteConversation: (id: string) => Promise<void>;
122
+ starConversation: (id: string, starred: boolean) => Promise<void>;
123
123
  }
124
124
  /**
125
125
  * Manage conversation history with auth automatically wired from AtlasProvider.
package/dist/hooks.js CHANGED
@@ -1,5 +1,5 @@
1
- import { useThemeMode, useDarkMode, applyBrandColor, setTheme, useConversations, AUTH_MODES } from './chunk-2WFDP7G5.js';
2
- export { AUTH_MODES, parseChatError } from './chunk-2WFDP7G5.js';
1
+ import { useThemeMode, useDarkMode, applyBrandColor, setTheme, useConversations, AUTH_MODES } from './chunk-FMSGREKS.js';
2
+ export { AUTH_MODES, parseChatError } from './chunk-FMSGREKS.js';
3
3
  import { createContext, useContext, useState, useRef, useMemo, useEffect } from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
  import { useChat } from '@ai-sdk/react';
@@ -51,7 +51,7 @@ function useAtlasChat(options = {}) {
51
51
  const headers = {};
52
52
  if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
53
53
  return new DefaultChatTransport({
54
- api: `${apiUrl}/api/chat`,
54
+ api: `${apiUrl}/api/v1/chat`,
55
55
  headers,
56
56
  credentials: isCrossOrigin ? "include" : void 0,
57
57
  body: () => conversationIdRef.current ? { conversationId: conversationIdRef.current } : {},
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/provider.tsx","../src/hooks/use-atlas-chat.ts","../src/hooks/use-atlas-auth.ts","../src/h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;AAAA,IACL,eAAe,KAAA,CAAM,aAAA;AAAA,IACrB,OAAO,KAAA,CAAM,KAAA;AAAA,IACb,WAAW,KAAA,CAAM,OAAA;AAAA,IACjB,WAAW,KAAA,CAAM,SAAA;AAAA,IACjB,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,eAAe,KAAA,CAAM,aAAA;AAAA,IACrB,SAAS,KAAA,CAAM,OAAA;AAAA,IACf,kBAAkB,KAAA,CAAM,gBAAA;AAAA,IACxB,oBAAoB,KAAA,CAAM,kBAAA;AAAA,IAC1B,kBAAkB,KAAA,CAAM;AAAA,GAC1B;AACF","file":"hooks.js","sourcesContent":["\"use client\";\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type { AtlasAuthClient } from \"../context\";\n\nexport type { AtlasAuthClient };\n\nexport interface AtlasProviderProps {\n /** Atlas API server URL (e.g. \"https://api.example.com\" or \"\" for same-origin). */\n apiUrl: string;\n /** API key for simple-key auth mode. Sent as Bearer token. Accessible in context by all hooks. */\n apiKey?: string;\n /** Custom auth client for managed auth mode (better-auth compatible). */\n authClient?: AtlasAuthClient;\n children: ReactNode;\n}\n\nexport interface AtlasContextValue {\n apiUrl: string;\n apiKey: string | undefined;\n authClient: AtlasAuthClient;\n isCrossOrigin: boolean;\n}\n\n/** No-op auth client for non-managed auth modes. Warns when auth operations are attempted. */\nconst noopAuthClient: AtlasAuthClient = {\n signIn: {\n email: async () => {\n console.warn(\"[Atlas] signIn called but no authClient was provided to AtlasProvider\");\n return { error: { message: \"Auth client not configured\" } };\n },\n },\n signUp: {\n email: async () => {\n console.warn(\"[Atlas] signUp called but no authClient was provided to AtlasProvider\");\n return { error: { message: \"Auth client not configured\" } };\n },\n },\n signOut: async () => {\n console.warn(\"[Atlas] signOut called but no authClient was provided to AtlasProvider\");\n },\n useSession: () => ({ data: null, isPending: false }),\n};\n\nconst AtlasContext = createContext<AtlasContextValue | null>(null);\n\n/** Access the AtlasProvider context. Throws if used outside <AtlasProvider>. */\nexport function useAtlasContext(): AtlasContextValue {\n const ctx = useContext(AtlasContext);\n if (!ctx) throw new Error(\"useAtlasContext must be used within <AtlasProvider>\");\n return ctx;\n}\n\n/**\n * Lightweight provider for headless Atlas hooks.\n *\n * Wraps your app and supplies API URL, auth credentials, and an optional\n * better-auth client to all Atlas hooks. Derives isCrossOrigin from apiUrl\n * to configure credential handling for cross-origin requests.\n */\nexport function AtlasProvider({\n apiUrl,\n apiKey,\n authClient = noopAuthClient,\n children,\n}: AtlasProviderProps) {\n const isCrossOrigin =\n typeof window !== \"undefined\" &&\n apiUrl !== \"\" &&\n !apiUrl.startsWith(window.location.origin);\n\n return (\n <AtlasContext.Provider value={{ apiUrl, apiKey, authClient, isCrossOrigin }}>\n {children}\n </AtlasContext.Provider>\n );\n}\n","\"use client\";\n\nimport { useState, useRef, useMemo } from \"react\";\nimport { useChat, type UIMessage } from \"@ai-sdk/react\";\nimport { DefaultChatTransport } from \"ai\";\nimport { useAtlasContext } from \"./provider\";\n\nexport type AtlasChatStatus = \"submitted\" | \"streaming\" | \"ready\" | \"error\";\n\nexport interface UseAtlasChatOptions {\n /** Conversation ID to associate with this chat session. The server will append messages to this conversation. To load prior messages, use loadConversation() from useAtlasConversations and pass them via setMessages. */\n initialConversationId?: string;\n /** Called when the server assigns or changes the conversation ID. */\n onConversationIdChange?: (id: string) => void;\n}\n\nexport interface UseAtlasChatReturn {\n messages: UIMessage[];\n /** Replace all messages, or update via callback `(prev) => next`. */\n setMessages: (messages: UIMessage[] | ((prev: UIMessage[]) => UIMessage[])) => void;\n /** Send a text message. Rejects on failure (also surfaces via `error`). */\n sendMessage: (text: string) => Promise<void>;\n /** Current input value (managed by the hook). */\n input: string;\n /** Update the input value. */\n setInput: (input: string) => void;\n /** Chat status from the AI SDK. */\n status: AtlasChatStatus;\n /** Whether the chat is currently loading (streaming or submitted). */\n isLoading: boolean;\n /** Last error, if any. */\n error: Error | null;\n /** Current conversation ID. Initially set from options, updated when the server returns an x-conversation-id header. */\n conversationId: string | null;\n /** Manually set the conversation ID. */\n setConversationId: (id: string | null) => void;\n}\n\nexport function useAtlasChat(options: UseAtlasChatOptions = {}): UseAtlasChatReturn {\n const { apiUrl, apiKey, isCrossOrigin } = useAtlasContext();\n const [conversationId, setConversationId] = useState<string | null>(\n options.initialConversationId ?? null,\n );\n const conversationIdRef = useRef(conversationId);\n conversationIdRef.current = conversationId;\n\n const onChangeRef = useRef(options.onConversationIdChange);\n onChangeRef.current = options.onConversationIdChange;\n\n const transport = useMemo(() => {\n const headers: Record<string, string> = {};\n if (apiKey) headers[\"Authorization\"] = `Bearer ${apiKey}`;\n\n return new DefaultChatTransport({\n api: `${apiUrl}/api/chat`,\n headers,\n credentials: isCrossOrigin ? \"include\" : undefined,\n body: () =>\n conversationIdRef.current\n ? { conversationId: conversationIdRef.current }\n : {},\n fetch: (async (input: RequestInfo | URL, init?: RequestInit) => {\n const response = await globalThis.fetch(input, init);\n const convId = response.headers.get(\"x-conversation-id\");\n if (convId && convId !== conversationIdRef.current) {\n setConversationId(convId);\n onChangeRef.current?.(convId);\n }\n return response;\n }) as typeof fetch,\n });\n }, [apiKey, apiUrl, isCrossOrigin]);\n\n const { messages, setMessages, sendMessage: rawSend, status, error } =\n useChat({ transport });\n\n const [input, setInput] = useState(\"\");\n\n const sendMessage = async (text: string) => {\n const previousInput = input;\n setInput(\"\");\n try {\n await rawSend({ text });\n } catch (err) {\n setInput(previousInput);\n throw err;\n }\n };\n\n return {\n messages,\n setMessages,\n sendMessage,\n input,\n setInput,\n status: status as AtlasChatStatus,\n isLoading: status === \"streaming\" || status === \"submitted\",\n error: error ?? null,\n conversationId,\n setConversationId,\n };\n}\n","\"use client\";\n\nimport { useState, useEffect } from \"react\";\nimport { useAtlasContext } from \"./provider\";\nimport { AUTH_MODES, type AuthMode } from \"../lib/types\";\n\nexport interface UseAtlasAuthReturn {\n /** Auth mode detected from the server's /api/health endpoint. `null` while the initial health check is in flight. */\n authMode: AuthMode | null;\n /** Whether the user is authenticated (based on auth mode, API key, or session). */\n isAuthenticated: boolean;\n /** Session data for managed auth mode. */\n session: { user?: { email?: string } } | null;\n /** Whether auth state is still being resolved (health check or managed session loading). */\n isLoading: boolean;\n /** Error from health check or auth operations. `null` when healthy. */\n error: Error | null;\n /** Sign in with email/password (managed auth). */\n login: (email: string, password: string) => Promise<{ error?: string }>;\n /** Sign up with email/password/name (managed auth). */\n signup: (email: string, password: string, name: string) => Promise<{ error?: string }>;\n /** Sign out (managed auth). */\n logout: () => Promise<{ error?: string }>;\n}\n\nexport function useAtlasAuth(): UseAtlasAuthReturn {\n const { apiUrl, apiKey, authClient, isCrossOrigin } = useAtlasContext();\n const [authMode, setAuthMode] = useState<AuthMode | null>(null);\n const [error, setError] = useState<Error | null>(null);\n const managedSession = authClient.useSession();\n\n useEffect(() => {\n let cancelled = false;\n\n async function fetchHealth(attempt: number): Promise<void> {\n try {\n const res = await fetch(`${apiUrl}/api/health`, {\n credentials: isCrossOrigin ? \"include\" : \"same-origin\",\n });\n if (!res.ok) {\n console.warn(`[Atlas] Health check returned HTTP ${res.status} (attempt ${attempt})`);\n if (attempt < 2 && !cancelled) {\n await new Promise((r) => setTimeout(r, 2000));\n return fetchHealth(attempt + 1);\n }\n if (!cancelled) {\n setError(new Error(`Health check failed with HTTP ${res.status}`));\n setAuthMode(\"none\");\n }\n return;\n }\n const data = await res.json();\n const mode = data?.checks?.auth?.mode;\n if (!cancelled) {\n if (typeof mode === \"string\" && AUTH_MODES.includes(mode as AuthMode)) {\n setAuthMode(mode as AuthMode);\n } else {\n console.warn(\"[Atlas] Health check returned no valid auth mode:\", data);\n setAuthMode(\"none\");\n }\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n console.warn(`[Atlas] Health check failed (attempt ${attempt}):`, message);\n if (attempt < 2 && !cancelled) {\n await new Promise((r) => setTimeout(r, 2000));\n return fetchHealth(attempt + 1);\n }\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(message));\n setAuthMode(\"none\");\n }\n }\n }\n\n fetchHealth(1);\n return () => { cancelled = true; };\n }, [apiUrl, isCrossOrigin]);\n\n const isAuthenticated = (() => {\n if (authMode === null) return false;\n if (authMode === \"none\") return true;\n if (authMode === \"simple-key\" || authMode === \"byot\") return !!apiKey;\n if (authMode === \"managed\") return !!managedSession.data?.user;\n return false;\n })();\n\n const login = async (email: string, password: string) => {\n try {\n const result = await authClient.signIn.email({ email, password });\n return { error: result.error?.message };\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Login failed\";\n console.warn(\"[Atlas] login error:\", message);\n return { error: message };\n }\n };\n\n const signup = async (email: string, password: string, name: string) => {\n try {\n const result = await authClient.signUp.email({ email, password, name });\n return { error: result.error?.message };\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Signup failed\";\n console.warn(\"[Atlas] signup error:\", message);\n return { error: message };\n }\n };\n\n const logout = async () => {\n try {\n await authClient.signOut();\n return {};\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Logout failed\";\n console.warn(\"[Atlas] logout error:\", message);\n return { error: message };\n }\n };\n\n return {\n authMode,\n isAuthenticated,\n session: managedSession.data ?? null,\n isLoading: authMode === null || (authMode === \"managed\" && !!managedSession.isPending),\n error,\n login,\n signup,\n logout,\n };\n}\n","\"use client\";\n\nimport {\n useDarkMode,\n useThemeMode,\n setTheme,\n applyBrandColor,\n type ThemeMode,\n} from \"./use-dark-mode\";\n\nexport type { ThemeMode };\n\nexport interface UseAtlasThemeReturn {\n /** Current theme setting: \"light\", \"dark\", or \"system\". */\n theme: ThemeMode;\n /** Whether the effective (resolved) theme is dark. */\n isDark: boolean;\n /** Set the theme mode. Persists to localStorage. */\n setTheme: (mode: ThemeMode) => void;\n /** Apply a brand color (oklch format, e.g. \"oklch(0.759 0.148 167.71)\") via CSS custom property --atlas-brand. */\n applyBrandColor: (color: string) => void;\n}\n\nexport function useAtlasTheme(): UseAtlasThemeReturn {\n const theme = useThemeMode();\n const isDark = useDarkMode();\n\n return {\n theme,\n isDark,\n setTheme,\n applyBrandColor,\n };\n}\n","\"use client\";\n\nimport type { UIMessage } from \"@ai-sdk/react\";\nimport { useAtlasContext } from \"./provider\";\nimport { useConversations } from \"./use-conversations\";\nimport type { Conversation } from \"../lib/types\";\n\nexport interface UseAtlasConversationsOptions {\n /** When false, refresh() becomes a no-op. Defaults to true. */\n enabled?: boolean;\n}\n\nexport interface UseAtlasConversationsReturn {\n conversations: Conversation[];\n total: number;\n isLoading: boolean;\n available: boolean;\n selectedId: string | null;\n setSelectedId: (id: string | null) => void;\n refresh: () => Promise<void>;\n loadConversation: (id: string) => Promise<UIMessage[] | null>;\n deleteConversation: (id: string) => Promise<boolean>;\n starConversation: (id: string, starred: boolean) => Promise<boolean>;\n}\n\n/**\n * Manage conversation history with auth automatically wired from AtlasProvider.\n *\n * Wraps the lower-level `useConversations` hook with context-derived\n * API URL and credentials.\n */\nexport function useAtlasConversations(\n options: UseAtlasConversationsOptions = {},\n): UseAtlasConversationsReturn {\n const { apiUrl, apiKey, isCrossOrigin } = useAtlasContext();\n const { enabled = true } = options;\n\n const inner = useConversations({\n apiUrl,\n enabled,\n getHeaders: () => {\n const headers: Record<string, string> = {};\n if (apiKey) headers[\"Authorization\"] = `Bearer ${apiKey}`;\n return headers;\n },\n getCredentials: () => (isCrossOrigin ? \"include\" : \"same-origin\"),\n });\n\n return {\n conversations: inner.conversations,\n total: inner.total,\n isLoading: inner.loading,\n available: inner.available,\n selectedId: inner.selectedId,\n setSelectedId: inner.setSelectedId,\n refresh: inner.refresh,\n loadConversation: inner.loadConversation,\n deleteConversation: inner.deleteConversation,\n starConversation: inner.starConversation,\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/provider.tsx","../src/hooks/use-atlas-chat.ts","../src/hooks/use-atlas-auth.ts","../src/hooks/use-atlas-theme.ts","../src/hooks/use-atlas-conversations.ts"],"names":["input","useState"],"mappings":";;;;;;;AAyBA,IAAM,cAAA,GAAkC;AAAA,EACtC,MAAA,EAAQ;AAAA,IACN,OAAO,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AAA;AAAA,IACjB,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,eAAe,KAAA,CAAM,aAAA;AAAA,IACrB,SAAS,KAAA,CAAM,OAAA;AAAA,IACf,kBAAkB,KAAA,CAAM,gBAAA;AAAA,IACxB,oBAAoB,KAAA,CAAM,kBAAA;AAAA,IAC1B,kBAAkB,KAAA,CAAM;AAAA,GAC1B;AACF","file":"hooks.js","sourcesContent":["\"use client\";\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type { AtlasAuthClient } from \"../context\";\n\nexport type { AtlasAuthClient };\n\nexport interface AtlasProviderProps {\n /** Atlas API server URL (e.g. \"https://api.example.com\" or \"\" for same-origin). */\n apiUrl: string;\n /** API key for simple-key auth mode. Sent as Bearer token. Accessible in context by all hooks. */\n apiKey?: string;\n /** Custom auth client for managed auth mode (better-auth compatible). */\n authClient?: AtlasAuthClient;\n children: ReactNode;\n}\n\nexport interface AtlasContextValue {\n apiUrl: string;\n apiKey: string | undefined;\n authClient: AtlasAuthClient;\n isCrossOrigin: boolean;\n}\n\n/** No-op auth client for non-managed auth modes. Warns when auth operations are attempted. */\nconst noopAuthClient: AtlasAuthClient = {\n signIn: {\n email: async () => {\n console.warn(\"[Atlas] signIn called but no authClient was provided to AtlasProvider\");\n return { error: { message: \"Auth client not configured\" } };\n },\n },\n signUp: {\n email: async () => {\n console.warn(\"[Atlas] signUp called but no authClient was provided to AtlasProvider\");\n return { error: { message: \"Auth client not configured\" } };\n },\n },\n signOut: async () => {\n console.warn(\"[Atlas] signOut called but no authClient was provided to AtlasProvider\");\n },\n useSession: () => ({ data: null, isPending: false }),\n};\n\nconst AtlasContext = createContext<AtlasContextValue | null>(null);\n\n/** Access the AtlasProvider context. Throws if used outside <AtlasProvider>. */\nexport function useAtlasContext(): AtlasContextValue {\n const ctx = useContext(AtlasContext);\n if (!ctx) throw new Error(\"useAtlasContext must be used within <AtlasProvider>\");\n return ctx;\n}\n\n/**\n * Lightweight provider for headless Atlas hooks.\n *\n * Wraps your app and supplies API URL, auth credentials, and an optional\n * better-auth client to all Atlas hooks. Derives isCrossOrigin from apiUrl\n * to configure credential handling for cross-origin requests.\n */\nexport function AtlasProvider({\n apiUrl,\n apiKey,\n authClient = noopAuthClient,\n children,\n}: AtlasProviderProps) {\n const isCrossOrigin =\n typeof window !== \"undefined\" &&\n apiUrl !== \"\" &&\n !apiUrl.startsWith(window.location.origin);\n\n return (\n <AtlasContext.Provider value={{ apiUrl, apiKey, authClient, isCrossOrigin }}>\n {children}\n </AtlasContext.Provider>\n );\n}\n","\"use client\";\n\nimport { useState, useRef, useMemo } from \"react\";\nimport { useChat, type UIMessage } from \"@ai-sdk/react\";\nimport { DefaultChatTransport } from \"ai\";\nimport { useAtlasContext } from \"./provider\";\n\nexport type AtlasChatStatus = \"submitted\" | \"streaming\" | \"ready\" | \"error\";\n\nexport interface UseAtlasChatOptions {\n /** Conversation ID to associate with this chat session. The server will append messages to this conversation. To load prior messages, use loadConversation() from useAtlasConversations and pass them via setMessages. */\n initialConversationId?: string;\n /** Called when the server assigns or changes the conversation ID. */\n onConversationIdChange?: (id: string) => void;\n}\n\nexport interface UseAtlasChatReturn {\n messages: UIMessage[];\n /** Replace all messages, or update via callback `(prev) => next`. */\n setMessages: (messages: UIMessage[] | ((prev: UIMessage[]) => UIMessage[])) => void;\n /** Send a text message. Rejects on failure (also surfaces via `error`). */\n sendMessage: (text: string) => Promise<void>;\n /** Current input value (managed by the hook). */\n input: string;\n /** Update the input value. */\n setInput: (input: string) => void;\n /** Chat status from the AI SDK. */\n status: AtlasChatStatus;\n /** Whether the chat is currently loading (streaming or submitted). */\n isLoading: boolean;\n /** Last error, if any. */\n error: Error | null;\n /** Current conversation ID. Initially set from options, updated when the server returns an x-conversation-id header. */\n conversationId: string | null;\n /** Manually set the conversation ID. */\n setConversationId: (id: string | null) => void;\n}\n\nexport function useAtlasChat(options: UseAtlasChatOptions = {}): UseAtlasChatReturn {\n const { apiUrl, apiKey, isCrossOrigin } = useAtlasContext();\n const [conversationId, setConversationId] = useState<string | null>(\n options.initialConversationId ?? null,\n );\n const conversationIdRef = useRef(conversationId);\n conversationIdRef.current = conversationId;\n\n const onChangeRef = useRef(options.onConversationIdChange);\n onChangeRef.current = options.onConversationIdChange;\n\n const transport = useMemo(() => {\n const headers: Record<string, string> = {};\n if (apiKey) headers[\"Authorization\"] = `Bearer ${apiKey}`;\n\n return new DefaultChatTransport({\n api: `${apiUrl}/api/v1/chat`,\n headers,\n credentials: isCrossOrigin ? \"include\" : undefined,\n body: () =>\n conversationIdRef.current\n ? { conversationId: conversationIdRef.current }\n : {},\n fetch: (async (input: RequestInfo | URL, init?: RequestInit) => {\n const response = await globalThis.fetch(input, init);\n const convId = response.headers.get(\"x-conversation-id\");\n if (convId && convId !== conversationIdRef.current) {\n setConversationId(convId);\n onChangeRef.current?.(convId);\n }\n return response;\n }) as typeof fetch,\n });\n }, [apiKey, apiUrl, isCrossOrigin]);\n\n const { messages, setMessages, sendMessage: rawSend, status, error } =\n useChat({ transport });\n\n const [input, setInput] = useState(\"\");\n\n const sendMessage = async (text: string) => {\n const previousInput = input;\n setInput(\"\");\n try {\n await rawSend({ text });\n } catch (err) {\n setInput(previousInput);\n throw err;\n }\n };\n\n return {\n messages,\n setMessages,\n sendMessage,\n input,\n setInput,\n status: status as AtlasChatStatus,\n isLoading: status === \"streaming\" || status === \"submitted\",\n error: error ?? null,\n conversationId,\n setConversationId,\n };\n}\n","\"use client\";\n\nimport { useState, useEffect } from \"react\";\nimport { useAtlasContext } from \"./provider\";\nimport { AUTH_MODES, type AuthMode } from \"../lib/types\";\n\nexport interface UseAtlasAuthReturn {\n /** Auth mode detected from the server's /api/health endpoint. `null` while the initial health check is in flight. */\n authMode: AuthMode | null;\n /** Whether the user is authenticated (based on auth mode, API key, or session). */\n isAuthenticated: boolean;\n /** Session data for managed auth mode. */\n session: { user?: { email?: string } } | null;\n /** Whether auth state is still being resolved (health check or managed session loading). */\n isLoading: boolean;\n /** Error from health check or auth operations. `null` when healthy. */\n error: Error | null;\n /** Sign in with email/password (managed auth). */\n login: (email: string, password: string) => Promise<{ error?: string }>;\n /** Sign up with email/password/name (managed auth). */\n signup: (email: string, password: string, name: string) => Promise<{ error?: string }>;\n /** Sign out (managed auth). */\n logout: () => Promise<{ error?: string }>;\n}\n\nexport function useAtlasAuth(): UseAtlasAuthReturn {\n const { apiUrl, apiKey, authClient, isCrossOrigin } = useAtlasContext();\n const [authMode, setAuthMode] = useState<AuthMode | null>(null);\n const [error, setError] = useState<Error | null>(null);\n const managedSession = authClient.useSession();\n\n useEffect(() => {\n let cancelled = false;\n\n async function fetchHealth(attempt: number): Promise<void> {\n try {\n const res = await fetch(`${apiUrl}/api/health`, {\n credentials: isCrossOrigin ? \"include\" : \"same-origin\",\n });\n if (!res.ok) {\n console.warn(`[Atlas] Health check returned HTTP ${res.status} (attempt ${attempt})`);\n if (attempt < 2 && !cancelled) {\n await new Promise((r) => setTimeout(r, 2000));\n return fetchHealth(attempt + 1);\n }\n if (!cancelled) {\n setError(new Error(`Health check failed with HTTP ${res.status}`));\n setAuthMode(\"none\");\n }\n return;\n }\n const data = await res.json();\n const mode = data?.checks?.auth?.mode;\n if (!cancelled) {\n if (typeof mode === \"string\" && AUTH_MODES.includes(mode as AuthMode)) {\n setAuthMode(mode as AuthMode);\n } else {\n console.warn(\"[Atlas] Health check returned no valid auth mode:\", data);\n setAuthMode(\"none\");\n }\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n console.warn(`[Atlas] Health check failed (attempt ${attempt}):`, message);\n if (attempt < 2 && !cancelled) {\n await new Promise((r) => setTimeout(r, 2000));\n return fetchHealth(attempt + 1);\n }\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(message));\n setAuthMode(\"none\");\n }\n }\n }\n\n fetchHealth(1);\n return () => { cancelled = true; };\n }, [apiUrl, isCrossOrigin]);\n\n const isAuthenticated = (() => {\n if (authMode === null) return false;\n if (authMode === \"none\") return true;\n if (authMode === \"simple-key\" || authMode === \"byot\") return !!apiKey;\n if (authMode === \"managed\") return !!managedSession.data?.user;\n return false;\n })();\n\n const login = async (email: string, password: string) => {\n try {\n const result = await authClient.signIn.email({ email, password });\n return { error: result.error?.message };\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Login failed\";\n console.warn(\"[Atlas] login error:\", message);\n return { error: message };\n }\n };\n\n const signup = async (email: string, password: string, name: string) => {\n try {\n const result = await authClient.signUp.email({ email, password, name });\n return { error: result.error?.message };\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Signup failed\";\n console.warn(\"[Atlas] signup error:\", message);\n return { error: message };\n }\n };\n\n const logout = async () => {\n try {\n await authClient.signOut();\n return {};\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Logout failed\";\n console.warn(\"[Atlas] logout error:\", message);\n return { error: message };\n }\n };\n\n return {\n authMode,\n isAuthenticated,\n session: managedSession.data ?? null,\n isLoading: authMode === null || (authMode === \"managed\" && !!managedSession.isPending),\n error,\n login,\n signup,\n logout,\n };\n}\n","\"use client\";\n\nimport {\n useDarkMode,\n useThemeMode,\n setTheme,\n applyBrandColor,\n type ThemeMode,\n} from \"./use-dark-mode\";\n\nexport type { ThemeMode };\n\nexport interface UseAtlasThemeReturn {\n /** Current theme setting: \"light\", \"dark\", or \"system\". */\n theme: ThemeMode;\n /** Whether the effective (resolved) theme is dark. */\n isDark: boolean;\n /** Set the theme mode. Persists to localStorage. */\n setTheme: (mode: ThemeMode) => void;\n /** Apply a brand color (oklch format, e.g. \"oklch(0.759 0.148 167.71)\") via CSS custom property --atlas-brand. */\n applyBrandColor: (color: string) => void;\n}\n\nexport function useAtlasTheme(): UseAtlasThemeReturn {\n const theme = useThemeMode();\n const isDark = useDarkMode();\n\n return {\n theme,\n isDark,\n setTheme,\n applyBrandColor,\n };\n}\n","\"use client\";\n\nimport type { UIMessage } from \"@ai-sdk/react\";\nimport { useAtlasContext } from \"./provider\";\nimport { useConversations } from \"./use-conversations\";\nimport type { Conversation } from \"../lib/types\";\n\nexport interface UseAtlasConversationsOptions {\n /** When false, refresh() becomes a no-op. Defaults to true. */\n enabled?: boolean;\n}\n\nexport interface UseAtlasConversationsReturn {\n conversations: Conversation[];\n total: number;\n isLoading: boolean;\n available: boolean;\n selectedId: string | null;\n setSelectedId: (id: string | null) => void;\n refresh: () => Promise<void>;\n loadConversation: (id: string) => Promise<UIMessage[] | null>;\n deleteConversation: (id: string) => Promise<void>;\n starConversation: (id: string, starred: boolean) => Promise<void>;\n}\n\n/**\n * Manage conversation history with auth automatically wired from AtlasProvider.\n *\n * Wraps the lower-level `useConversations` hook with context-derived\n * API URL and credentials.\n */\nexport function useAtlasConversations(\n options: UseAtlasConversationsOptions = {},\n): UseAtlasConversationsReturn {\n const { apiUrl, apiKey, isCrossOrigin } = useAtlasContext();\n const { enabled = true } = options;\n\n const inner = useConversations({\n apiUrl,\n enabled,\n getHeaders: () => {\n const headers: Record<string, string> = {};\n if (apiKey) headers[\"Authorization\"] = `Bearer ${apiKey}`;\n return headers;\n },\n getCredentials: () => (isCrossOrigin ? \"include\" : \"same-origin\"),\n });\n\n return {\n conversations: inner.conversations,\n total: inner.total,\n isLoading: inner.loading,\n available: inner.available,\n selectedId: inner.selectedId,\n setSelectedId: inner.setSelectedId,\n refresh: inner.refresh,\n loadConversation: inner.loadConversation,\n deleteConversation: inner.deleteConversation,\n starConversation: inner.starConversation,\n };\n}\n"]}