@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.cjs CHANGED
@@ -24158,6 +24158,10 @@ function useThreadListStore() {
24158
24158
  }
24159
24159
  return store;
24160
24160
  }
24161
+ const ThreadLoadingContext = React.createContext(false);
24162
+ function useThreadLoading() {
24163
+ return React.useContext(ThreadLoadingContext);
24164
+ }
24161
24165
  function getAuthHeaders(auth) {
24162
24166
  if (auth.token) {
24163
24167
  return { Authorization: `Bearer ${auth.token}` };
@@ -24225,7 +24229,7 @@ async function archiveThread(backendUrl, auth, threadId) {
24225
24229
  }
24226
24230
  function createThreadListStore(config2) {
24227
24231
  const auth = { apiKey: config2.apiKey, token: config2.token };
24228
- return create((set2, get2) => ({
24232
+ const store = create((set2, get2) => ({
24229
24233
  threads: [],
24230
24234
  activeThreadId: null,
24231
24235
  isLoading: false,
@@ -24268,6 +24272,8 @@ function createThreadListStore(config2) {
24268
24272
  }
24269
24273
  }
24270
24274
  }));
24275
+ store.getState().fetchThreads();
24276
+ return store;
24271
24277
  }
24272
24278
  function AthenaRuntimeInner({
24273
24279
  children,
@@ -24309,66 +24315,6 @@ function AthenaRuntimeInner({
24309
24315
  );
24310
24316
  return /* @__PURE__ */ jsxRuntime.jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children }) }) });
24311
24317
  }
24312
- function ThreadStateLoader({
24313
- children,
24314
- threadId,
24315
- backendUrl,
24316
- apiKey,
24317
- token,
24318
- ...runtimeProps
24319
- }) {
24320
- const [initialMessages, setInitialMessages] = React.useState(void 0);
24321
- const [isLoading, setIsLoading] = React.useState(!!threadId);
24322
- React.useEffect(() => {
24323
- if (!threadId) {
24324
- setInitialMessages(void 0);
24325
- setIsLoading(false);
24326
- return;
24327
- }
24328
- let cancelled = false;
24329
- setIsLoading(true);
24330
- getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
24331
- var _a2;
24332
- if (cancelled) return;
24333
- if (process.env.NODE_ENV !== "production") {
24334
- console.log("[AthenaThreads] Loaded thread state", {
24335
- threadId,
24336
- messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
24337
- });
24338
- }
24339
- setInitialMessages(state.messages ?? []);
24340
- setIsLoading(false);
24341
- }).catch((err) => {
24342
- if (cancelled) return;
24343
- if (process.env.NODE_ENV !== "production") {
24344
- console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
24345
- }
24346
- setInitialMessages(void 0);
24347
- setIsLoading(false);
24348
- });
24349
- return () => {
24350
- cancelled = true;
24351
- };
24352
- }, [threadId, backendUrl, apiKey, token]);
24353
- if (isLoading) {
24354
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "100%", width: "100%" }, children: [
24355
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: 24, height: 24, border: "2px solid currentColor", borderTopColor: "transparent", borderRadius: "50%", animation: "spin 0.6s linear infinite", opacity: 0.4 } }),
24356
- /* @__PURE__ */ jsxRuntime.jsx("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` })
24357
- ] });
24358
- }
24359
- return /* @__PURE__ */ jsxRuntime.jsx(
24360
- AthenaRuntimeInner,
24361
- {
24362
- threadId,
24363
- backendUrl,
24364
- apiKey,
24365
- token,
24366
- initialMessages,
24367
- ...runtimeProps,
24368
- children
24369
- }
24370
- );
24371
- }
24372
24318
  function useActiveThreadFromStore(store) {
24373
24319
  return React.useSyncExternalStore(
24374
24320
  (cb) => {
@@ -24422,19 +24368,51 @@ function AthenaProvider({
24422
24368
  const activeThreadId = useActiveThreadFromStore(
24423
24369
  enableThreadList ? threadListStoreRef.current : null
24424
24370
  );
24425
- const resolvedThreadId = threadIdProp ?? activeThreadId ?? void 0;
24371
+ const [displayedThreadId, setDisplayedThreadId] = React.useState(null);
24372
+ const [loadedMessages, setLoadedMessages] = React.useState(void 0);
24373
+ const [isLoadingThread, setIsLoadingThread] = React.useState(false);
24426
24374
  React.useEffect(() => {
24427
- if (process.env.NODE_ENV !== "production") {
24428
- console.log("[AthenaThreads] AthenaProvider render", {
24429
- activeThreadId,
24430
- resolvedThreadId,
24431
- enableThreadList,
24432
- hasStore: !!threadListStoreRef.current
24433
- });
24375
+ var _a2;
24376
+ if (!enableThreadList) return;
24377
+ if (activeThreadId === displayedThreadId) return;
24378
+ const threads = ((_a2 = threadListStoreRef.current) == null ? void 0 : _a2.getState().threads) ?? [];
24379
+ const isExistingThread = threads.some((t) => t.thread_id === activeThreadId);
24380
+ if (!isExistingThread) {
24381
+ setLoadedMessages(void 0);
24382
+ setDisplayedThreadId(activeThreadId);
24383
+ setIsLoadingThread(false);
24384
+ return;
24434
24385
  }
24435
- }, [activeThreadId, resolvedThreadId, enableThreadList]);
24436
- const inner = /* @__PURE__ */ jsxRuntime.jsx(
24437
- ThreadStateLoader,
24386
+ let cancelled = false;
24387
+ setIsLoadingThread(true);
24388
+ getThreadState(effectiveBackendUrl, { apiKey, token: effectiveToken }, activeThreadId).then((state) => {
24389
+ var _a3;
24390
+ if (cancelled) return;
24391
+ if (process.env.NODE_ENV !== "production") {
24392
+ console.log("[AthenaThreads] Loaded thread state", {
24393
+ threadId: activeThreadId,
24394
+ messageCount: ((_a3 = state.messages) == null ? void 0 : _a3.length) ?? 0
24395
+ });
24396
+ }
24397
+ setLoadedMessages(state.messages ?? []);
24398
+ setDisplayedThreadId(activeThreadId);
24399
+ setIsLoadingThread(false);
24400
+ }).catch((err) => {
24401
+ if (cancelled) return;
24402
+ if (process.env.NODE_ENV !== "production") {
24403
+ console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
24404
+ }
24405
+ setLoadedMessages(void 0);
24406
+ setDisplayedThreadId(activeThreadId);
24407
+ setIsLoadingThread(false);
24408
+ });
24409
+ return () => {
24410
+ cancelled = true;
24411
+ };
24412
+ }, [activeThreadId, displayedThreadId, enableThreadList, effectiveBackendUrl, apiKey, effectiveToken]);
24413
+ const resolvedThreadId = threadIdProp ?? displayedThreadId ?? void 0;
24414
+ const inner = /* @__PURE__ */ jsxRuntime.jsx(ThreadLoadingContext.Provider, { value: isLoadingThread, children: /* @__PURE__ */ jsxRuntime.jsx(
24415
+ AthenaRuntimeInner,
24438
24416
  {
24439
24417
  apiUrl,
24440
24418
  backendUrl: effectiveBackendUrl,
@@ -24449,10 +24427,11 @@ function AthenaProvider({
24449
24427
  knowledgeBase,
24450
24428
  systemPrompt,
24451
24429
  threadId: resolvedThreadId,
24430
+ initialMessages: loadedMessages,
24452
24431
  children
24453
24432
  },
24454
24433
  resolvedThreadId ?? "__new__"
24455
- );
24434
+ ) });
24456
24435
  if (enableThreadList && threadListStoreRef.current) {
24457
24436
  return /* @__PURE__ */ jsxRuntime.jsx(ThreadListContext.Provider, { value: threadListStoreRef.current, children: inner });
24458
24437
  }
@@ -62338,6 +62317,7 @@ const AthenaChat = ({
62338
62317
  toolUIs,
62339
62318
  mentionTools
62340
62319
  }) => {
62320
+ const isLoadingThread = useThreadLoading();
62341
62321
  const tools = mentionTools ?? EMPTY_MENTION_TOOLS;
62342
62322
  const mergedToolUIs = React.useMemo(() => ({
62343
62323
  append_markdown_to_athena_document: AppendDocumentToolUI,
@@ -62349,40 +62329,43 @@ const AthenaChat = ({
62349
62329
  () => () => /* @__PURE__ */ jsxRuntime.jsx(AssistantMessage, { toolUIs: mergedToolUIs }),
62350
62330
  [mergedToolUIs]
62351
62331
  );
62352
- return /* @__PURE__ */ jsxRuntime.jsx(
62332
+ return /* @__PURE__ */ jsxRuntime.jsxs(
62353
62333
  ThreadPrimitiveRoot,
62354
62334
  {
62355
62335
  className: `aui-root aui-thread-root @container flex h-full flex-col bg-background ${className ?? ""}`,
62356
- style: { ["--thread-max-width"]: maxWidth },
62357
- children: /* @__PURE__ */ jsxRuntime.jsxs(
62358
- ThreadPrimitiveViewport,
62359
- {
62360
- turnAnchor: "top",
62361
- className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4",
62362
- children: [
62363
- /* @__PURE__ */ jsxRuntime.jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-thread-welcome-center flex w-full grow flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-4", children: [
62364
- /* @__PURE__ */ jsxRuntime.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 }),
62365
- /* @__PURE__ */ jsxRuntime.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 })
62366
- ] }) }) }) }),
62367
- /* @__PURE__ */ jsxRuntime.jsx(
62368
- ThreadPrimitiveMessages,
62369
- {
62370
- components: {
62371
- UserMessage,
62372
- AssistantMessage: AssistantMessageComponent
62336
+ style: { ["--thread-max-width"]: maxWidth, position: "relative" },
62337
+ children: [
62338
+ isLoadingThread && /* @__PURE__ */ jsxRuntime.jsx(ThreadLoadingOverlay, {}),
62339
+ /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-thread-welcome-center flex w-full grow flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-4", children: [
62346
+ /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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__ */ jsxRuntime.jsx(
62350
+ ThreadPrimitiveMessages,
62351
+ {
62352
+ components: {
62353
+ UserMessage,
62354
+ AssistantMessage: AssistantMessageComponent
62355
+ }
62373
62356
  }
62374
- }
62375
- ),
62376
- /* @__PURE__ */ jsxRuntime.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: [
62377
- /* @__PURE__ */ jsxRuntime.jsx(ThreadScrollToBottom, {}),
62378
- /* @__PURE__ */ jsxRuntime.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: [
62379
- /* @__PURE__ */ jsxRuntime.jsx(TiptapComposer, { tools }),
62380
- /* @__PURE__ */ jsxRuntime.jsx(ComposerAction, {})
62357
+ ),
62358
+ /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(ThreadScrollToBottom, {}),
62360
+ /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(TiptapComposer, { tools }),
62362
+ /* @__PURE__ */ jsxRuntime.jsx(ComposerAction, {})
62363
+ ] })
62381
62364
  ] })
62382
- ] })
62383
- ]
62384
- }
62385
- )
62365
+ ]
62366
+ }
62367
+ )
62368
+ ]
62386
62369
  }
62387
62370
  );
62388
62371
  };
@@ -62490,6 +62473,57 @@ const AssistantActionBar = () => /* @__PURE__ */ jsxRuntime.jsxs(
62490
62473
  ]
62491
62474
  }
62492
62475
  );
62476
+ const ThreadLoadingOverlay = () => /* @__PURE__ */ jsxRuntime.jsxs(
62477
+ "div",
62478
+ {
62479
+ className: "aui-thread-loading-overlay",
62480
+ style: {
62481
+ position: "absolute",
62482
+ inset: 0,
62483
+ zIndex: 50,
62484
+ display: "flex",
62485
+ flexDirection: "column",
62486
+ alignItems: "center",
62487
+ justifyContent: "center",
62488
+ gap: 12,
62489
+ background: "color-mix(in srgb, var(--background, #fff) 80%, transparent)",
62490
+ backdropFilter: "blur(4px)",
62491
+ WebkitBackdropFilter: "blur(4px)",
62492
+ animation: "aui-overlay-in 0.2s ease-out"
62493
+ },
62494
+ children: [
62495
+ /* @__PURE__ */ jsxRuntime.jsx(
62496
+ "div",
62497
+ {
62498
+ style: {
62499
+ width: 28,
62500
+ height: 28,
62501
+ border: "2.5px solid var(--border, #e5e5e5)",
62502
+ borderTopColor: "var(--primary, #2563eb)",
62503
+ borderRadius: "50%",
62504
+ animation: "aui-spin 0.7s linear infinite"
62505
+ }
62506
+ }
62507
+ ),
62508
+ /* @__PURE__ */ jsxRuntime.jsx(
62509
+ "span",
62510
+ {
62511
+ style: {
62512
+ fontSize: 13,
62513
+ fontWeight: 500,
62514
+ color: "var(--muted-foreground, #888)",
62515
+ letterSpacing: "0.01em"
62516
+ },
62517
+ children: "Loading conversation…"
62518
+ }
62519
+ ),
62520
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: `
62521
+ @keyframes aui-spin { to { transform: rotate(360deg); } }
62522
+ @keyframes aui-overlay-in { from { opacity: 0; } to { opacity: 1; } }
62523
+ ` })
62524
+ ]
62525
+ }
62526
+ );
62493
62527
  const UserMessage = () => /* @__PURE__ */ jsxRuntime.jsx(
62494
62528
  MessagePrimitiveRoot,
62495
62529
  {
@@ -62952,4 +62986,5 @@ exports.useComposerAttachment = useComposerAttachment;
62952
62986
  exports.useMentionSuggestions = useMentionSuggestions;
62953
62987
  exports.useParentAuth = useParentAuth;
62954
62988
  exports.useThreadList = useThreadList;
62989
+ exports.useThreadLoading = useThreadLoading;
62955
62990
  //# sourceMappingURL=index.cjs.map