@athenaintel/react 0.4.4 → 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,66 +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 [initialMessages, setInitialMessages] = useState(void 0);
24303
- const [isLoading, setIsLoading] = useState(!!threadId);
24304
- useEffect(() => {
24305
- if (!threadId) {
24306
- setInitialMessages(void 0);
24307
- setIsLoading(false);
24308
- return;
24309
- }
24310
- let cancelled = false;
24311
- setIsLoading(true);
24312
- getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
24313
- var _a2;
24314
- if (cancelled) return;
24315
- if (process.env.NODE_ENV !== "production") {
24316
- console.log("[AthenaThreads] Loaded thread state", {
24317
- threadId,
24318
- messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
24319
- });
24320
- }
24321
- setInitialMessages(state.messages ?? []);
24322
- setIsLoading(false);
24323
- }).catch((err) => {
24324
- if (cancelled) return;
24325
- if (process.env.NODE_ENV !== "production") {
24326
- console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
24327
- }
24328
- setInitialMessages(void 0);
24329
- setIsLoading(false);
24330
- });
24331
- return () => {
24332
- cancelled = true;
24333
- };
24334
- }, [threadId, backendUrl, apiKey, token]);
24335
- if (isLoading) {
24336
- return /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "100%", width: "100%" }, children: [
24337
- /* @__PURE__ */ jsx("div", { style: { width: 24, height: 24, border: "2px solid currentColor", borderTopColor: "transparent", borderRadius: "50%", animation: "spin 0.6s linear infinite", opacity: 0.4 } }),
24338
- /* @__PURE__ */ jsx("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` })
24339
- ] });
24340
- }
24341
- return /* @__PURE__ */ jsx(
24342
- AthenaRuntimeInner,
24343
- {
24344
- threadId,
24345
- backendUrl,
24346
- apiKey,
24347
- token,
24348
- initialMessages,
24349
- ...runtimeProps,
24350
- children
24351
- }
24352
- );
24353
- }
24354
24300
  function useActiveThreadFromStore(store) {
24355
24301
  return useSyncExternalStore(
24356
24302
  (cb) => {
@@ -24404,19 +24350,51 @@ function AthenaProvider({
24404
24350
  const activeThreadId = useActiveThreadFromStore(
24405
24351
  enableThreadList ? threadListStoreRef.current : null
24406
24352
  );
24407
- 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);
24408
24356
  useEffect(() => {
24409
- if (process.env.NODE_ENV !== "production") {
24410
- console.log("[AthenaThreads] AthenaProvider render", {
24411
- activeThreadId,
24412
- resolvedThreadId,
24413
- enableThreadList,
24414
- hasStore: !!threadListStoreRef.current
24415
- });
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;
24416
24367
  }
24417
- }, [activeThreadId, resolvedThreadId, enableThreadList]);
24418
- const inner = /* @__PURE__ */ jsx(
24419
- 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,
24420
24398
  {
24421
24399
  apiUrl,
24422
24400
  backendUrl: effectiveBackendUrl,
@@ -24431,10 +24409,11 @@ function AthenaProvider({
24431
24409
  knowledgeBase,
24432
24410
  systemPrompt,
24433
24411
  threadId: resolvedThreadId,
24412
+ initialMessages: loadedMessages,
24434
24413
  children
24435
24414
  },
24436
24415
  resolvedThreadId ?? "__new__"
24437
- );
24416
+ ) });
24438
24417
  if (enableThreadList && threadListStoreRef.current) {
24439
24418
  return /* @__PURE__ */ jsx(ThreadListContext.Provider, { value: threadListStoreRef.current, children: inner });
24440
24419
  }
@@ -62320,6 +62299,7 @@ const AthenaChat = ({
62320
62299
  toolUIs,
62321
62300
  mentionTools
62322
62301
  }) => {
62302
+ const isLoadingThread = useThreadLoading();
62323
62303
  const tools = mentionTools ?? EMPTY_MENTION_TOOLS;
62324
62304
  const mergedToolUIs = useMemo(() => ({
62325
62305
  append_markdown_to_athena_document: AppendDocumentToolUI,
@@ -62331,40 +62311,43 @@ const AthenaChat = ({
62331
62311
  () => () => /* @__PURE__ */ jsx(AssistantMessage, { toolUIs: mergedToolUIs }),
62332
62312
  [mergedToolUIs]
62333
62313
  );
62334
- return /* @__PURE__ */ jsx(
62314
+ return /* @__PURE__ */ jsxs(
62335
62315
  ThreadPrimitiveRoot,
62336
62316
  {
62337
62317
  className: `aui-root aui-thread-root @container flex h-full flex-col bg-background ${className ?? ""}`,
62338
- style: { ["--thread-max-width"]: maxWidth },
62339
- children: /* @__PURE__ */ jsxs(
62340
- ThreadPrimitiveViewport,
62341
- {
62342
- turnAnchor: "top",
62343
- className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4",
62344
- children: [
62345
- /* @__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: [
62346
- /* @__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 }),
62347
- /* @__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 })
62348
- ] }) }) }) }),
62349
- /* @__PURE__ */ jsx(
62350
- ThreadPrimitiveMessages,
62351
- {
62352
- components: {
62353
- UserMessage,
62354
- 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
+ }
62355
62338
  }
62356
- }
62357
- ),
62358
- /* @__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: [
62359
- /* @__PURE__ */ jsx(ThreadScrollToBottom, {}),
62360
- /* @__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: [
62361
- /* @__PURE__ */ jsx(TiptapComposer, { tools }),
62362
- /* @__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
+ ] })
62363
62346
  ] })
62364
- ] })
62365
- ]
62366
- }
62367
- )
62347
+ ]
62348
+ }
62349
+ )
62350
+ ]
62368
62351
  }
62369
62352
  );
62370
62353
  };
@@ -62472,6 +62455,57 @@ const AssistantActionBar = () => /* @__PURE__ */ jsxs(
62472
62455
  ]
62473
62456
  }
62474
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
+ );
62475
62509
  const UserMessage = () => /* @__PURE__ */ jsx(
62476
62510
  MessagePrimitiveRoot,
62477
62511
  {
@@ -62934,6 +62968,7 @@ export {
62934
62968
  useComposerAttachment,
62935
62969
  useMentionSuggestions,
62936
62970
  useParentAuth,
62937
- useThreadList
62971
+ useThreadList,
62972
+ useThreadLoading
62938
62973
  };
62939
62974
  //# sourceMappingURL=index.js.map