@athenaintel/react 0.10.13 → 0.10.15
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 +93 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +93 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24558,12 +24558,23 @@ const useAthenaRuntime = (config2) => {
|
|
|
24558
24558
|
if (isExistingThread && !hasResumedRef.current) {
|
|
24559
24559
|
hasResumedRef.current = true;
|
|
24560
24560
|
(async () => {
|
|
24561
|
+
var _a2;
|
|
24561
24562
|
try {
|
|
24562
24563
|
const auth = { apiKey: apiKeyRef.current, token: tokenRef.current };
|
|
24563
24564
|
const state = await getThreadState(backendUrl, auth, threadId);
|
|
24564
24565
|
runtime.thread.importExternalState({
|
|
24565
24566
|
messages: state.messages
|
|
24566
24567
|
});
|
|
24568
|
+
if (state.status === "running") {
|
|
24569
|
+
try {
|
|
24570
|
+
const lastMessageId = ((_a2 = runtime.thread.getState().messages.at(-1)) == null ? void 0 : _a2.id) ?? null;
|
|
24571
|
+
runtime.thread.unstable_resumeRun({ parentId: lastMessageId });
|
|
24572
|
+
} catch (resumeErr) {
|
|
24573
|
+
if (IS_DEV) {
|
|
24574
|
+
console.error("[AthenaSDK] Failed to resume running thread:", resumeErr);
|
|
24575
|
+
}
|
|
24576
|
+
}
|
|
24577
|
+
}
|
|
24567
24578
|
} catch (err) {
|
|
24568
24579
|
if (IS_DEV) {
|
|
24569
24580
|
console.error("[AthenaSDK] Failed to load thread state:", err);
|
|
@@ -24722,6 +24733,68 @@ function useAthenaThreadManager() {
|
|
|
24722
24733
|
};
|
|
24723
24734
|
}, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
|
|
24724
24735
|
}
|
|
24736
|
+
const POLL_DELAY_MS = 5e3;
|
|
24737
|
+
const POLL_INTERVAL_MS = 1e3;
|
|
24738
|
+
const POLL_MAX_DURATION_MS = 6e4;
|
|
24739
|
+
function useThreadTitlePolling(refresh) {
|
|
24740
|
+
const threadKey = useThread({
|
|
24741
|
+
optional: true,
|
|
24742
|
+
selector: (s) => {
|
|
24743
|
+
var _a2, _b;
|
|
24744
|
+
return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
|
|
24745
|
+
}
|
|
24746
|
+
}) ?? null;
|
|
24747
|
+
const hasMessages = useThread({
|
|
24748
|
+
optional: true,
|
|
24749
|
+
selector: (s) => s.messages.length > 0
|
|
24750
|
+
}) ?? false;
|
|
24751
|
+
const currentTitle = useThreadList({
|
|
24752
|
+
optional: true,
|
|
24753
|
+
selector: (s) => {
|
|
24754
|
+
const main = s.threadItems[s.mainThreadId];
|
|
24755
|
+
return (main == null ? void 0 : main.title) ?? "";
|
|
24756
|
+
}
|
|
24757
|
+
}) ?? "";
|
|
24758
|
+
const hasTitle = currentTitle.trim().length > 0;
|
|
24759
|
+
const polledThreadsRef = useRef(/* @__PURE__ */ new Set());
|
|
24760
|
+
const refreshRef = useRef(refresh);
|
|
24761
|
+
refreshRef.current = refresh;
|
|
24762
|
+
useEffect(() => {
|
|
24763
|
+
if (!threadKey || hasTitle || !hasMessages) {
|
|
24764
|
+
return;
|
|
24765
|
+
}
|
|
24766
|
+
if (polledThreadsRef.current.has(threadKey)) {
|
|
24767
|
+
return;
|
|
24768
|
+
}
|
|
24769
|
+
polledThreadsRef.current.add(threadKey);
|
|
24770
|
+
let stopped = false;
|
|
24771
|
+
let intervalId = null;
|
|
24772
|
+
let maxTimeoutId = null;
|
|
24773
|
+
const stop = () => {
|
|
24774
|
+
stopped = true;
|
|
24775
|
+
if (intervalId !== null) {
|
|
24776
|
+
clearInterval(intervalId);
|
|
24777
|
+
intervalId = null;
|
|
24778
|
+
}
|
|
24779
|
+
if (maxTimeoutId !== null) {
|
|
24780
|
+
clearTimeout(maxTimeoutId);
|
|
24781
|
+
maxTimeoutId = null;
|
|
24782
|
+
}
|
|
24783
|
+
};
|
|
24784
|
+
const startTimeoutId = setTimeout(() => {
|
|
24785
|
+
if (stopped) return;
|
|
24786
|
+
refreshRef.current();
|
|
24787
|
+
intervalId = setInterval(() => {
|
|
24788
|
+
refreshRef.current();
|
|
24789
|
+
}, POLL_INTERVAL_MS);
|
|
24790
|
+
maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
|
|
24791
|
+
}, POLL_DELAY_MS);
|
|
24792
|
+
return () => {
|
|
24793
|
+
clearTimeout(startTimeoutId);
|
|
24794
|
+
stop();
|
|
24795
|
+
};
|
|
24796
|
+
}, [threadKey, hasTitle, hasMessages]);
|
|
24797
|
+
}
|
|
24725
24798
|
function createJSONStorage(getStorage, options) {
|
|
24726
24799
|
let storage;
|
|
24727
24800
|
try {
|
|
@@ -25264,12 +25337,16 @@ const useAthenaConfigValue = ({
|
|
|
25264
25337
|
linkClicksRef.current = linkClicks;
|
|
25265
25338
|
const citationLinksRef = useRef(citationLinks);
|
|
25266
25339
|
citationLinksRef.current = citationLinks;
|
|
25340
|
+
const tokenRef = useRef(token);
|
|
25341
|
+
tokenRef.current = token;
|
|
25267
25342
|
return useMemo(
|
|
25268
25343
|
() => ({
|
|
25269
25344
|
backendUrl,
|
|
25270
25345
|
appUrl,
|
|
25271
25346
|
apiKey,
|
|
25272
|
-
token
|
|
25347
|
+
get token() {
|
|
25348
|
+
return tokenRef.current;
|
|
25349
|
+
},
|
|
25273
25350
|
get linkClicks() {
|
|
25274
25351
|
return linkClicksRef.current;
|
|
25275
25352
|
},
|
|
@@ -25277,7 +25354,7 @@ const useAthenaConfigValue = ({
|
|
|
25277
25354
|
return citationLinksRef.current;
|
|
25278
25355
|
}
|
|
25279
25356
|
}),
|
|
25280
|
-
[backendUrl, appUrl, apiKey
|
|
25357
|
+
[backendUrl, appUrl, apiKey]
|
|
25281
25358
|
);
|
|
25282
25359
|
};
|
|
25283
25360
|
function AthenaStandalone({
|
|
@@ -25438,6 +25515,7 @@ function AthenaWithThreadList({
|
|
|
25438
25515
|
});
|
|
25439
25516
|
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
25517
|
/* @__PURE__ */ jsx(AssetPanelThreadSync, {}),
|
|
25518
|
+
/* @__PURE__ */ jsx(ThreadTitlePoller, { refresh: handleRefresh }),
|
|
25441
25519
|
children
|
|
25442
25520
|
] }) }) }) });
|
|
25443
25521
|
}
|
|
@@ -25450,6 +25528,10 @@ function AssetPanelThreadSync() {
|
|
|
25450
25528
|
}, [activeThreadId, setCurrentThread]);
|
|
25451
25529
|
return null;
|
|
25452
25530
|
}
|
|
25531
|
+
function ThreadTitlePoller({ refresh }) {
|
|
25532
|
+
useThreadTitlePolling(refresh);
|
|
25533
|
+
return null;
|
|
25534
|
+
}
|
|
25453
25535
|
function AthenaProvider({
|
|
25454
25536
|
children,
|
|
25455
25537
|
config: config2,
|
|
@@ -65481,7 +65563,10 @@ const TooltipIconButton = forwardRef(
|
|
|
65481
65563
|
TooltipIconButton.displayName = "TooltipIconButton";
|
|
65482
65564
|
const MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024;
|
|
65483
65565
|
function useFileUpload() {
|
|
65484
|
-
const
|
|
65566
|
+
const config2 = useAthenaConfig();
|
|
65567
|
+
const configRef = useRef(config2);
|
|
65568
|
+
configRef.current = config2;
|
|
65569
|
+
const { backendUrl, apiKey } = config2;
|
|
65485
65570
|
const [isUploading, setIsUploading] = useState(false);
|
|
65486
65571
|
const [progress, setProgress] = useState(null);
|
|
65487
65572
|
const [error2, setError] = useState(null);
|
|
@@ -65514,9 +65599,10 @@ function useFileUpload() {
|
|
|
65514
65599
|
}
|
|
65515
65600
|
const baseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
|
|
65516
65601
|
const uploadUrl = `${baseUrl}/api/upload/`;
|
|
65602
|
+
const currentToken = configRef.current.token;
|
|
65517
65603
|
const headers = {};
|
|
65518
|
-
if (
|
|
65519
|
-
headers["Authorization"] = `Bearer ${
|
|
65604
|
+
if (currentToken) {
|
|
65605
|
+
headers["Authorization"] = `Bearer ${currentToken}`;
|
|
65520
65606
|
} else if (apiKey) {
|
|
65521
65607
|
headers["X-API-KEY"] = apiKey;
|
|
65522
65608
|
}
|
|
@@ -65566,7 +65652,7 @@ function useFileUpload() {
|
|
|
65566
65652
|
for (const [key, value] of Object.entries(headers)) {
|
|
65567
65653
|
xhr.setRequestHeader(key, value);
|
|
65568
65654
|
}
|
|
65569
|
-
xhr.withCredentials = !
|
|
65655
|
+
xhr.withCredentials = !currentToken && !apiKey;
|
|
65570
65656
|
xhr.send(formData);
|
|
65571
65657
|
});
|
|
65572
65658
|
if (result.errors.length > 0) {
|
|
@@ -65588,7 +65674,7 @@ function useFileUpload() {
|
|
|
65588
65674
|
setProgress(null);
|
|
65589
65675
|
}
|
|
65590
65676
|
},
|
|
65591
|
-
[backendUrl, apiKey
|
|
65677
|
+
[backendUrl, apiKey]
|
|
65592
65678
|
);
|
|
65593
65679
|
return { upload, isUploading, progress, error: error2, clearError };
|
|
65594
65680
|
}
|