@athenaintel/react 0.10.12 → 0.10.14

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
@@ -1167,6 +1167,13 @@ export declare function useAppendToComposer(): (text: string, opts?: {
1167
1167
  /**
1168
1168
  * Hook to generate an embed URL for rendering an asset in an iframe.
1169
1169
  * Calls the Athena embed token endpoint.
1170
+ *
1171
+ * Note: The auth token is read via a ref and is intentionally NOT part
1172
+ * of the effect dependency array. PropelAuth and similar providers refresh
1173
+ * the token value periodically (e.g. on window focus), but the underlying
1174
+ * session is the same — re-running the effect on every token rotation
1175
+ * would force the iframe to reload unnecessarily. The effect only re-runs
1176
+ * when the auth _mode_ changes (auth vs anonymous) or the asset changes.
1170
1177
  */
1171
1178
  export declare function useAssetEmbed(assetId: string | null, options?: UseAssetEmbedOptions & {
1172
1179
  backendUrl: string;
package/dist/index.js CHANGED
@@ -24722,6 +24722,68 @@ function useAthenaThreadManager() {
24722
24722
  };
24723
24723
  }, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
24724
24724
  }
24725
+ const POLL_DELAY_MS = 5e3;
24726
+ const POLL_INTERVAL_MS = 1e3;
24727
+ const POLL_MAX_DURATION_MS = 6e4;
24728
+ function useThreadTitlePolling(refresh) {
24729
+ const threadKey = useThread({
24730
+ optional: true,
24731
+ selector: (s) => {
24732
+ var _a2, _b;
24733
+ return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
24734
+ }
24735
+ }) ?? null;
24736
+ const hasMessages = useThread({
24737
+ optional: true,
24738
+ selector: (s) => s.messages.length > 0
24739
+ }) ?? false;
24740
+ const currentTitle = useThreadList({
24741
+ optional: true,
24742
+ selector: (s) => {
24743
+ const main = s.threadItems[s.mainThreadId];
24744
+ return (main == null ? void 0 : main.title) ?? "";
24745
+ }
24746
+ }) ?? "";
24747
+ const hasTitle = currentTitle.trim().length > 0;
24748
+ const polledThreadsRef = useRef(/* @__PURE__ */ new Set());
24749
+ const refreshRef = useRef(refresh);
24750
+ refreshRef.current = refresh;
24751
+ useEffect(() => {
24752
+ if (!threadKey || hasTitle || !hasMessages) {
24753
+ return;
24754
+ }
24755
+ if (polledThreadsRef.current.has(threadKey)) {
24756
+ return;
24757
+ }
24758
+ polledThreadsRef.current.add(threadKey);
24759
+ let stopped = false;
24760
+ let intervalId = null;
24761
+ let maxTimeoutId = null;
24762
+ const stop = () => {
24763
+ stopped = true;
24764
+ if (intervalId !== null) {
24765
+ clearInterval(intervalId);
24766
+ intervalId = null;
24767
+ }
24768
+ if (maxTimeoutId !== null) {
24769
+ clearTimeout(maxTimeoutId);
24770
+ maxTimeoutId = null;
24771
+ }
24772
+ };
24773
+ const startTimeoutId = setTimeout(() => {
24774
+ if (stopped) return;
24775
+ refreshRef.current();
24776
+ intervalId = setInterval(() => {
24777
+ refreshRef.current();
24778
+ }, POLL_INTERVAL_MS);
24779
+ maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
24780
+ }, POLL_DELAY_MS);
24781
+ return () => {
24782
+ clearTimeout(startTimeoutId);
24783
+ stop();
24784
+ };
24785
+ }, [threadKey, hasTitle, hasMessages]);
24786
+ }
24725
24787
  function createJSONStorage(getStorage, options) {
24726
24788
  let storage;
24727
24789
  try {
@@ -25438,6 +25500,7 @@ function AthenaWithThreadList({
25438
25500
  });
25439
25501
  return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(ThreadListRefreshContext.Provider, { value: handleRefresh, children: /* @__PURE__ */ jsxs(TooltipProvider, { children: [
25440
25502
  /* @__PURE__ */ jsx(AssetPanelThreadSync, {}),
25503
+ /* @__PURE__ */ jsx(ThreadTitlePoller, { refresh: handleRefresh }),
25441
25504
  children
25442
25505
  ] }) }) }) });
25443
25506
  }
@@ -25450,6 +25513,10 @@ function AssetPanelThreadSync() {
25450
25513
  }, [activeThreadId, setCurrentThread]);
25451
25514
  return null;
25452
25515
  }
25516
+ function ThreadTitlePoller({ refresh }) {
25517
+ useThreadTitlePolling(refresh);
25518
+ return null;
25519
+ }
25453
25520
  function AthenaProvider({
25454
25521
  children,
25455
25522
  config: config2,
@@ -66300,6 +66367,9 @@ function useAssetEmbed(assetId, options = {
66300
66367
  const [isLoading, setIsLoading] = useState(false);
66301
66368
  const [error2, setError] = useState(null);
66302
66369
  const abortRef = useRef(null);
66370
+ const tokenRef = useRef(token);
66371
+ tokenRef.current = token;
66372
+ const hasToken = !!token;
66303
66373
  useEffect(() => {
66304
66374
  var _a2;
66305
66375
  if (!assetId || !backendUrl) {
@@ -66308,7 +66378,8 @@ function useAssetEmbed(assetId, options = {
66308
66378
  setError(null);
66309
66379
  return;
66310
66380
  }
66311
- const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
66381
+ const authContext = hasToken ? "token" : apiKey ?? "anon";
66382
+ const cacheKey = `${assetId}:${readOnly}:${authContext}`;
66312
66383
  const cached = embedCache.get(cacheKey);
66313
66384
  if (cached && cached.expiresAt > Date.now() / 1e3) {
66314
66385
  setEmbedUrl(cached.url);
@@ -66324,8 +66395,9 @@ function useAssetEmbed(assetId, options = {
66324
66395
  setIsLoading(true);
66325
66396
  setError(null);
66326
66397
  const headers = { "Content-Type": "application/json" };
66327
- if (token) {
66328
- headers["Authorization"] = `Bearer ${token}`;
66398
+ const currentToken = tokenRef.current;
66399
+ if (currentToken) {
66400
+ headers["Authorization"] = `Bearer ${currentToken}`;
66329
66401
  } else if (apiKey) {
66330
66402
  headers["X-API-KEY"] = apiKey;
66331
66403
  }
@@ -66345,7 +66417,7 @@ function useAssetEmbed(assetId, options = {
66345
66417
  }
66346
66418
  return res.json();
66347
66419
  }).then((data) => {
66348
- embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
66420
+ embedCache.set(cacheKey, { url: data.embed_url, expiresAt: data.expires_at });
66349
66421
  setEmbedUrl(data.embed_url);
66350
66422
  setIsLoading(false);
66351
66423
  }).catch((err) => {
@@ -66354,7 +66426,7 @@ function useAssetEmbed(assetId, options = {
66354
66426
  setIsLoading(false);
66355
66427
  });
66356
66428
  return () => controller.abort();
66357
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
66429
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, hasToken]);
66358
66430
  return { embedUrl, isLoading, error: error2 };
66359
66431
  }
66360
66432
  const ASSET_TYPE_CONFIG = {