@athenaintel/react 0.4.5 → 0.4.6

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.
package/dist/index.d.ts CHANGED
@@ -464,6 +464,9 @@ export declare function useParentAuth(): string | null;
464
464
  /** Hook to access thread list state and actions. */
465
465
  export declare function useThreadList(): ThreadListState & ThreadListActions;
466
466
 
467
+ /** Returns true while a thread switch is loading messages. */
468
+ export declare function useThreadLoading(): boolean;
469
+
467
470
  export declare type ViewMode = 'tabs' | 'tiled';
468
471
 
469
472
  export declare const WebSearchToolUI: ToolCallMessagePartComponent;
package/dist/index.js CHANGED
@@ -24140,6 +24140,10 @@ function useThreadListStore() {
24140
24140
  }
24141
24141
  return store;
24142
24142
  }
24143
+ const ThreadLoadingContext = createContext(false);
24144
+ function useThreadLoading() {
24145
+ return useContext(ThreadLoadingContext);
24146
+ }
24143
24147
  function getAuthHeaders(auth) {
24144
24148
  if (auth.token) {
24145
24149
  return { Authorization: `Bearer ${auth.token}` };
@@ -24207,7 +24211,7 @@ async function archiveThread(backendUrl, auth, threadId) {
24207
24211
  }
24208
24212
  function createThreadListStore(config2) {
24209
24213
  const auth = { apiKey: config2.apiKey, token: config2.token };
24210
- return create((set2, get2) => ({
24214
+ const store = create((set2, get2) => ({
24211
24215
  threads: [],
24212
24216
  activeThreadId: null,
24213
24217
  isLoading: false,
@@ -24250,6 +24254,8 @@ function createThreadListStore(config2) {
24250
24254
  }
24251
24255
  }
24252
24256
  }));
24257
+ store.getState().fetchThreads();
24258
+ return store;
24253
24259
  }
24254
24260
  function AthenaRuntimeInner({
24255
24261
  children,
@@ -24291,103 +24297,6 @@ function AthenaRuntimeInner({
24291
24297
  );
24292
24298
  return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(TooltipProvider, { children }) }) });
24293
24299
  }
24294
- function ThreadStateLoader({
24295
- children,
24296
- threadId,
24297
- backendUrl,
24298
- apiKey,
24299
- token,
24300
- ...runtimeProps
24301
- }) {
24302
- const [loadedMessages, setLoadedMessages] = useState(void 0);
24303
- const [loadState, setLoadState] = useState(threadId ? "loading" : "done");
24304
- const [showSpinner, setShowSpinner] = useState(false);
24305
- useEffect(() => {
24306
- if (!threadId) {
24307
- setLoadedMessages(void 0);
24308
- setLoadState("done");
24309
- return;
24310
- }
24311
- let cancelled = false;
24312
- setLoadState("loading");
24313
- setShowSpinner(false);
24314
- const spinnerTimer = setTimeout(() => {
24315
- if (!cancelled) setShowSpinner(true);
24316
- }, 200);
24317
- getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
24318
- var _a2;
24319
- if (cancelled) return;
24320
- if (process.env.NODE_ENV !== "production") {
24321
- console.log("[AthenaThreads] Loaded thread state", {
24322
- threadId,
24323
- messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
24324
- });
24325
- }
24326
- setLoadedMessages(state.messages ?? []);
24327
- setLoadState("done");
24328
- }).catch((err) => {
24329
- if (cancelled) return;
24330
- if (process.env.NODE_ENV !== "production") {
24331
- console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
24332
- }
24333
- setLoadedMessages(void 0);
24334
- setLoadState("done");
24335
- });
24336
- return () => {
24337
- cancelled = true;
24338
- clearTimeout(spinnerTimer);
24339
- };
24340
- }, [threadId, backendUrl, apiKey, token]);
24341
- if (loadState === "loading") {
24342
- return /* @__PURE__ */ jsxs(
24343
- "div",
24344
- {
24345
- style: {
24346
- display: "flex",
24347
- flexDirection: "column",
24348
- alignItems: "center",
24349
- justifyContent: "center",
24350
- height: "100%",
24351
- width: "100%",
24352
- background: "var(--background, #fff)",
24353
- color: "var(--muted-foreground, #888)",
24354
- gap: 8,
24355
- opacity: showSpinner ? 1 : 0,
24356
- transition: "opacity 0.15s ease-in"
24357
- },
24358
- children: [
24359
- /* @__PURE__ */ jsx(
24360
- "div",
24361
- {
24362
- style: {
24363
- width: 20,
24364
- height: 20,
24365
- border: "2px solid var(--border, #e5e5e5)",
24366
- borderTopColor: "var(--primary, #2563eb)",
24367
- borderRadius: "50%",
24368
- animation: "aui-spin 0.6s linear infinite"
24369
- }
24370
- }
24371
- ),
24372
- /* @__PURE__ */ jsx("span", { style: { fontSize: 13 }, children: "Loading conversation…" }),
24373
- /* @__PURE__ */ jsx("style", { children: `@keyframes aui-spin { to { transform: rotate(360deg); } }` })
24374
- ]
24375
- }
24376
- );
24377
- }
24378
- return /* @__PURE__ */ jsx(
24379
- AthenaRuntimeInner,
24380
- {
24381
- threadId,
24382
- backendUrl,
24383
- apiKey,
24384
- token,
24385
- initialMessages: loadedMessages,
24386
- ...runtimeProps,
24387
- children
24388
- }
24389
- );
24390
- }
24391
24300
  function useActiveThreadFromStore(store) {
24392
24301
  return useSyncExternalStore(
24393
24302
  (cb) => {
@@ -24441,19 +24350,51 @@ function AthenaProvider({
24441
24350
  const activeThreadId = useActiveThreadFromStore(
24442
24351
  enableThreadList ? threadListStoreRef.current : null
24443
24352
  );
24444
- const resolvedThreadId = threadIdProp ?? activeThreadId ?? void 0;
24353
+ const [displayedThreadId, setDisplayedThreadId] = useState(null);
24354
+ const [loadedMessages, setLoadedMessages] = useState(void 0);
24355
+ const [isLoadingThread, setIsLoadingThread] = useState(false);
24445
24356
  useEffect(() => {
24446
- if (process.env.NODE_ENV !== "production") {
24447
- console.log("[AthenaThreads] AthenaProvider render", {
24448
- activeThreadId,
24449
- resolvedThreadId,
24450
- enableThreadList,
24451
- hasStore: !!threadListStoreRef.current
24452
- });
24357
+ var _a2;
24358
+ if (!enableThreadList) return;
24359
+ if (activeThreadId === displayedThreadId) return;
24360
+ const threads = ((_a2 = threadListStoreRef.current) == null ? void 0 : _a2.getState().threads) ?? [];
24361
+ const isExistingThread = threads.some((t) => t.thread_id === activeThreadId);
24362
+ if (!isExistingThread) {
24363
+ setLoadedMessages(void 0);
24364
+ setDisplayedThreadId(activeThreadId);
24365
+ setIsLoadingThread(false);
24366
+ return;
24453
24367
  }
24454
- }, [activeThreadId, resolvedThreadId, enableThreadList]);
24455
- const inner = /* @__PURE__ */ jsx(
24456
- ThreadStateLoader,
24368
+ let cancelled = false;
24369
+ setIsLoadingThread(true);
24370
+ getThreadState(effectiveBackendUrl, { apiKey, token: effectiveToken }, activeThreadId).then((state) => {
24371
+ var _a3;
24372
+ if (cancelled) return;
24373
+ if (process.env.NODE_ENV !== "production") {
24374
+ console.log("[AthenaThreads] Loaded thread state", {
24375
+ threadId: activeThreadId,
24376
+ messageCount: ((_a3 = state.messages) == null ? void 0 : _a3.length) ?? 0
24377
+ });
24378
+ }
24379
+ setLoadedMessages(state.messages ?? []);
24380
+ setDisplayedThreadId(activeThreadId);
24381
+ setIsLoadingThread(false);
24382
+ }).catch((err) => {
24383
+ if (cancelled) return;
24384
+ if (process.env.NODE_ENV !== "production") {
24385
+ console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
24386
+ }
24387
+ setLoadedMessages(void 0);
24388
+ setDisplayedThreadId(activeThreadId);
24389
+ setIsLoadingThread(false);
24390
+ });
24391
+ return () => {
24392
+ cancelled = true;
24393
+ };
24394
+ }, [activeThreadId, displayedThreadId, enableThreadList, effectiveBackendUrl, apiKey, effectiveToken]);
24395
+ const resolvedThreadId = threadIdProp ?? displayedThreadId ?? void 0;
24396
+ const inner = /* @__PURE__ */ jsx(ThreadLoadingContext.Provider, { value: isLoadingThread, children: /* @__PURE__ */ jsx(
24397
+ AthenaRuntimeInner,
24457
24398
  {
24458
24399
  apiUrl,
24459
24400
  backendUrl: effectiveBackendUrl,
@@ -24468,10 +24409,11 @@ function AthenaProvider({
24468
24409
  knowledgeBase,
24469
24410
  systemPrompt,
24470
24411
  threadId: resolvedThreadId,
24412
+ initialMessages: loadedMessages,
24471
24413
  children
24472
24414
  },
24473
24415
  resolvedThreadId ?? "__new__"
24474
- );
24416
+ ) });
24475
24417
  if (enableThreadList && threadListStoreRef.current) {
24476
24418
  return /* @__PURE__ */ jsx(ThreadListContext.Provider, { value: threadListStoreRef.current, children: inner });
24477
24419
  }
@@ -62357,6 +62299,7 @@ const AthenaChat = ({
62357
62299
  toolUIs,
62358
62300
  mentionTools
62359
62301
  }) => {
62302
+ const isLoadingThread = useThreadLoading();
62360
62303
  const tools = mentionTools ?? EMPTY_MENTION_TOOLS;
62361
62304
  const mergedToolUIs = useMemo(() => ({
62362
62305
  append_markdown_to_athena_document: AppendDocumentToolUI,
@@ -62368,40 +62311,43 @@ const AthenaChat = ({
62368
62311
  () => () => /* @__PURE__ */ jsx(AssistantMessage, { toolUIs: mergedToolUIs }),
62369
62312
  [mergedToolUIs]
62370
62313
  );
62371
- return /* @__PURE__ */ jsx(
62314
+ return /* @__PURE__ */ jsxs(
62372
62315
  ThreadPrimitiveRoot,
62373
62316
  {
62374
62317
  className: `aui-root aui-thread-root @container flex h-full flex-col bg-background ${className ?? ""}`,
62375
- style: { ["--thread-max-width"]: maxWidth },
62376
- children: /* @__PURE__ */ jsxs(
62377
- ThreadPrimitiveViewport,
62378
- {
62379
- turnAnchor: "top",
62380
- className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4",
62381
- children: [
62382
- /* @__PURE__ */ jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsx("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col", children: /* @__PURE__ */ jsx("div", { className: "aui-thread-welcome-center flex w-full grow flex-col items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-4", children: [
62383
- /* @__PURE__ */ jsx("h1", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both font-semibold text-2xl duration-200", children: welcomeMessage }),
62384
- /* @__PURE__ */ jsx("p", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-muted-foreground text-xl delay-75 duration-200", children: welcomeSubtext })
62385
- ] }) }) }) }),
62386
- /* @__PURE__ */ jsx(
62387
- ThreadPrimitiveMessages,
62388
- {
62389
- components: {
62390
- UserMessage,
62391
- AssistantMessage: AssistantMessageComponent
62318
+ style: { ["--thread-max-width"]: maxWidth, position: "relative" },
62319
+ children: [
62320
+ isLoadingThread && /* @__PURE__ */ jsx(ThreadLoadingOverlay, {}),
62321
+ /* @__PURE__ */ jsxs(
62322
+ ThreadPrimitiveViewport,
62323
+ {
62324
+ turnAnchor: "top",
62325
+ className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4",
62326
+ children: [
62327
+ /* @__PURE__ */ jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsx("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col", children: /* @__PURE__ */ jsx("div", { className: "aui-thread-welcome-center flex w-full grow flex-col items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-4", children: [
62328
+ /* @__PURE__ */ jsx("h1", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both font-semibold text-2xl duration-200", children: welcomeMessage }),
62329
+ /* @__PURE__ */ jsx("p", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-muted-foreground text-xl delay-75 duration-200", children: welcomeSubtext })
62330
+ ] }) }) }) }),
62331
+ /* @__PURE__ */ jsx(
62332
+ ThreadPrimitiveMessages,
62333
+ {
62334
+ components: {
62335
+ UserMessage,
62336
+ AssistantMessage: AssistantMessageComponent
62337
+ }
62392
62338
  }
62393
- }
62394
- ),
62395
- /* @__PURE__ */ jsxs(ThreadPrimitiveViewportFooter, { className: "aui-thread-viewport-footer sticky bottom-0 mx-auto mt-auto flex w-full max-w-(--thread-max-width) flex-col gap-4 overflow-visible rounded-t-3xl bg-background pb-4 md:pb-6", children: [
62396
- /* @__PURE__ */ jsx(ThreadScrollToBottom, {}),
62397
- /* @__PURE__ */ jsxs(ComposerPrimitiveRoot, { className: "aui-composer-root relative flex w-full flex-col rounded-2xl border border-input bg-background px-1 pt-2 outline-none transition-shadow focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/20", children: [
62398
- /* @__PURE__ */ jsx(TiptapComposer, { tools }),
62399
- /* @__PURE__ */ jsx(ComposerAction, {})
62339
+ ),
62340
+ /* @__PURE__ */ jsxs(ThreadPrimitiveViewportFooter, { className: "aui-thread-viewport-footer sticky bottom-0 mx-auto mt-auto flex w-full max-w-(--thread-max-width) flex-col gap-4 overflow-visible rounded-t-3xl bg-background pb-4 md:pb-6", children: [
62341
+ /* @__PURE__ */ jsx(ThreadScrollToBottom, {}),
62342
+ /* @__PURE__ */ jsxs(ComposerPrimitiveRoot, { className: "aui-composer-root relative flex w-full flex-col rounded-2xl border border-input bg-background px-1 pt-2 outline-none transition-shadow focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/20", children: [
62343
+ /* @__PURE__ */ jsx(TiptapComposer, { tools }),
62344
+ /* @__PURE__ */ jsx(ComposerAction, {})
62345
+ ] })
62400
62346
  ] })
62401
- ] })
62402
- ]
62403
- }
62404
- )
62347
+ ]
62348
+ }
62349
+ )
62350
+ ]
62405
62351
  }
62406
62352
  );
62407
62353
  };
@@ -62509,6 +62455,57 @@ const AssistantActionBar = () => /* @__PURE__ */ jsxs(
62509
62455
  ]
62510
62456
  }
62511
62457
  );
62458
+ const ThreadLoadingOverlay = () => /* @__PURE__ */ jsxs(
62459
+ "div",
62460
+ {
62461
+ className: "aui-thread-loading-overlay",
62462
+ style: {
62463
+ position: "absolute",
62464
+ inset: 0,
62465
+ zIndex: 50,
62466
+ display: "flex",
62467
+ flexDirection: "column",
62468
+ alignItems: "center",
62469
+ justifyContent: "center",
62470
+ gap: 12,
62471
+ background: "color-mix(in srgb, var(--background, #fff) 80%, transparent)",
62472
+ backdropFilter: "blur(4px)",
62473
+ WebkitBackdropFilter: "blur(4px)",
62474
+ animation: "aui-overlay-in 0.2s ease-out"
62475
+ },
62476
+ children: [
62477
+ /* @__PURE__ */ jsx(
62478
+ "div",
62479
+ {
62480
+ style: {
62481
+ width: 28,
62482
+ height: 28,
62483
+ border: "2.5px solid var(--border, #e5e5e5)",
62484
+ borderTopColor: "var(--primary, #2563eb)",
62485
+ borderRadius: "50%",
62486
+ animation: "aui-spin 0.7s linear infinite"
62487
+ }
62488
+ }
62489
+ ),
62490
+ /* @__PURE__ */ jsx(
62491
+ "span",
62492
+ {
62493
+ style: {
62494
+ fontSize: 13,
62495
+ fontWeight: 500,
62496
+ color: "var(--muted-foreground, #888)",
62497
+ letterSpacing: "0.01em"
62498
+ },
62499
+ children: "Loading conversation…"
62500
+ }
62501
+ ),
62502
+ /* @__PURE__ */ jsx("style", { children: `
62503
+ @keyframes aui-spin { to { transform: rotate(360deg); } }
62504
+ @keyframes aui-overlay-in { from { opacity: 0; } to { opacity: 1; } }
62505
+ ` })
62506
+ ]
62507
+ }
62508
+ );
62512
62509
  const UserMessage = () => /* @__PURE__ */ jsx(
62513
62510
  MessagePrimitiveRoot,
62514
62511
  {
@@ -62971,6 +62968,7 @@ export {
62971
62968
  useComposerAttachment,
62972
62969
  useMentionSuggestions,
62973
62970
  useParentAuth,
62974
- useThreadList
62971
+ useThreadList,
62972
+ useThreadLoading
62975
62973
  };
62976
62974
  //# sourceMappingURL=index.js.map