@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.cjs +77 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +77 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24761,6 +24761,68 @@ function useAthenaThreadManager() {
|
|
|
24761
24761
|
};
|
|
24762
24762
|
}, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
|
|
24763
24763
|
}
|
|
24764
|
+
const POLL_DELAY_MS = 5e3;
|
|
24765
|
+
const POLL_INTERVAL_MS = 1e3;
|
|
24766
|
+
const POLL_MAX_DURATION_MS = 6e4;
|
|
24767
|
+
function useThreadTitlePolling(refresh) {
|
|
24768
|
+
const threadKey = useThread({
|
|
24769
|
+
optional: true,
|
|
24770
|
+
selector: (s) => {
|
|
24771
|
+
var _a2, _b;
|
|
24772
|
+
return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
|
|
24773
|
+
}
|
|
24774
|
+
}) ?? null;
|
|
24775
|
+
const hasMessages = useThread({
|
|
24776
|
+
optional: true,
|
|
24777
|
+
selector: (s) => s.messages.length > 0
|
|
24778
|
+
}) ?? false;
|
|
24779
|
+
const currentTitle = useThreadList({
|
|
24780
|
+
optional: true,
|
|
24781
|
+
selector: (s) => {
|
|
24782
|
+
const main = s.threadItems[s.mainThreadId];
|
|
24783
|
+
return (main == null ? void 0 : main.title) ?? "";
|
|
24784
|
+
}
|
|
24785
|
+
}) ?? "";
|
|
24786
|
+
const hasTitle = currentTitle.trim().length > 0;
|
|
24787
|
+
const polledThreadsRef = React.useRef(/* @__PURE__ */ new Set());
|
|
24788
|
+
const refreshRef = React.useRef(refresh);
|
|
24789
|
+
refreshRef.current = refresh;
|
|
24790
|
+
React.useEffect(() => {
|
|
24791
|
+
if (!threadKey || hasTitle || !hasMessages) {
|
|
24792
|
+
return;
|
|
24793
|
+
}
|
|
24794
|
+
if (polledThreadsRef.current.has(threadKey)) {
|
|
24795
|
+
return;
|
|
24796
|
+
}
|
|
24797
|
+
polledThreadsRef.current.add(threadKey);
|
|
24798
|
+
let stopped = false;
|
|
24799
|
+
let intervalId = null;
|
|
24800
|
+
let maxTimeoutId = null;
|
|
24801
|
+
const stop = () => {
|
|
24802
|
+
stopped = true;
|
|
24803
|
+
if (intervalId !== null) {
|
|
24804
|
+
clearInterval(intervalId);
|
|
24805
|
+
intervalId = null;
|
|
24806
|
+
}
|
|
24807
|
+
if (maxTimeoutId !== null) {
|
|
24808
|
+
clearTimeout(maxTimeoutId);
|
|
24809
|
+
maxTimeoutId = null;
|
|
24810
|
+
}
|
|
24811
|
+
};
|
|
24812
|
+
const startTimeoutId = setTimeout(() => {
|
|
24813
|
+
if (stopped) return;
|
|
24814
|
+
refreshRef.current();
|
|
24815
|
+
intervalId = setInterval(() => {
|
|
24816
|
+
refreshRef.current();
|
|
24817
|
+
}, POLL_INTERVAL_MS);
|
|
24818
|
+
maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
|
|
24819
|
+
}, POLL_DELAY_MS);
|
|
24820
|
+
return () => {
|
|
24821
|
+
clearTimeout(startTimeoutId);
|
|
24822
|
+
stop();
|
|
24823
|
+
};
|
|
24824
|
+
}, [threadKey, hasTitle, hasMessages]);
|
|
24825
|
+
}
|
|
24764
24826
|
function createJSONStorage(getStorage, options) {
|
|
24765
24827
|
let storage;
|
|
24766
24828
|
try {
|
|
@@ -25477,6 +25539,7 @@ function AthenaWithThreadList({
|
|
|
25477
25539
|
});
|
|
25478
25540
|
return /* @__PURE__ */ jsxRuntime.jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(ThreadListRefreshContext.Provider, { value: handleRefresh, children: /* @__PURE__ */ jsxRuntime.jsxs(TooltipProvider, { children: [
|
|
25479
25541
|
/* @__PURE__ */ jsxRuntime.jsx(AssetPanelThreadSync, {}),
|
|
25542
|
+
/* @__PURE__ */ jsxRuntime.jsx(ThreadTitlePoller, { refresh: handleRefresh }),
|
|
25480
25543
|
children
|
|
25481
25544
|
] }) }) }) });
|
|
25482
25545
|
}
|
|
@@ -25489,6 +25552,10 @@ function AssetPanelThreadSync() {
|
|
|
25489
25552
|
}, [activeThreadId, setCurrentThread]);
|
|
25490
25553
|
return null;
|
|
25491
25554
|
}
|
|
25555
|
+
function ThreadTitlePoller({ refresh }) {
|
|
25556
|
+
useThreadTitlePolling(refresh);
|
|
25557
|
+
return null;
|
|
25558
|
+
}
|
|
25492
25559
|
function AthenaProvider({
|
|
25493
25560
|
children,
|
|
25494
25561
|
config: config2,
|
|
@@ -66339,6 +66406,9 @@ function useAssetEmbed(assetId, options = {
|
|
|
66339
66406
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
66340
66407
|
const [error2, setError] = React.useState(null);
|
|
66341
66408
|
const abortRef = React.useRef(null);
|
|
66409
|
+
const tokenRef = React.useRef(token);
|
|
66410
|
+
tokenRef.current = token;
|
|
66411
|
+
const hasToken = !!token;
|
|
66342
66412
|
React.useEffect(() => {
|
|
66343
66413
|
var _a2;
|
|
66344
66414
|
if (!assetId || !backendUrl) {
|
|
@@ -66347,7 +66417,8 @@ function useAssetEmbed(assetId, options = {
|
|
|
66347
66417
|
setError(null);
|
|
66348
66418
|
return;
|
|
66349
66419
|
}
|
|
66350
|
-
const
|
|
66420
|
+
const authContext = hasToken ? "token" : apiKey ?? "anon";
|
|
66421
|
+
const cacheKey = `${assetId}:${readOnly}:${authContext}`;
|
|
66351
66422
|
const cached = embedCache.get(cacheKey);
|
|
66352
66423
|
if (cached && cached.expiresAt > Date.now() / 1e3) {
|
|
66353
66424
|
setEmbedUrl(cached.url);
|
|
@@ -66363,8 +66434,9 @@ function useAssetEmbed(assetId, options = {
|
|
|
66363
66434
|
setIsLoading(true);
|
|
66364
66435
|
setError(null);
|
|
66365
66436
|
const headers = { "Content-Type": "application/json" };
|
|
66366
|
-
|
|
66367
|
-
|
|
66437
|
+
const currentToken = tokenRef.current;
|
|
66438
|
+
if (currentToken) {
|
|
66439
|
+
headers["Authorization"] = `Bearer ${currentToken}`;
|
|
66368
66440
|
} else if (apiKey) {
|
|
66369
66441
|
headers["X-API-KEY"] = apiKey;
|
|
66370
66442
|
}
|
|
@@ -66384,7 +66456,7 @@ function useAssetEmbed(assetId, options = {
|
|
|
66384
66456
|
}
|
|
66385
66457
|
return res.json();
|
|
66386
66458
|
}).then((data) => {
|
|
66387
|
-
embedCache.set(
|
|
66459
|
+
embedCache.set(cacheKey, { url: data.embed_url, expiresAt: data.expires_at });
|
|
66388
66460
|
setEmbedUrl(data.embed_url);
|
|
66389
66461
|
setIsLoading(false);
|
|
66390
66462
|
}).catch((err) => {
|
|
@@ -66393,7 +66465,7 @@ function useAssetEmbed(assetId, options = {
|
|
|
66393
66465
|
setIsLoading(false);
|
|
66394
66466
|
});
|
|
66395
66467
|
return () => controller.abort();
|
|
66396
|
-
}, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey,
|
|
66468
|
+
}, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, hasToken]);
|
|
66397
66469
|
return { embedUrl, isLoading, error: error2 };
|
|
66398
66470
|
}
|
|
66399
66471
|
const ASSET_TYPE_CONFIG = {
|