@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.cjs
CHANGED
|
@@ -24597,12 +24597,23 @@ const useAthenaRuntime = (config2) => {
|
|
|
24597
24597
|
if (isExistingThread && !hasResumedRef.current) {
|
|
24598
24598
|
hasResumedRef.current = true;
|
|
24599
24599
|
(async () => {
|
|
24600
|
+
var _a2;
|
|
24600
24601
|
try {
|
|
24601
24602
|
const auth = { apiKey: apiKeyRef.current, token: tokenRef.current };
|
|
24602
24603
|
const state = await getThreadState(backendUrl, auth, threadId);
|
|
24603
24604
|
runtime.thread.importExternalState({
|
|
24604
24605
|
messages: state.messages
|
|
24605
24606
|
});
|
|
24607
|
+
if (state.status === "running") {
|
|
24608
|
+
try {
|
|
24609
|
+
const lastMessageId = ((_a2 = runtime.thread.getState().messages.at(-1)) == null ? void 0 : _a2.id) ?? null;
|
|
24610
|
+
runtime.thread.unstable_resumeRun({ parentId: lastMessageId });
|
|
24611
|
+
} catch (resumeErr) {
|
|
24612
|
+
if (IS_DEV) {
|
|
24613
|
+
console.error("[AthenaSDK] Failed to resume running thread:", resumeErr);
|
|
24614
|
+
}
|
|
24615
|
+
}
|
|
24616
|
+
}
|
|
24606
24617
|
} catch (err) {
|
|
24607
24618
|
if (IS_DEV) {
|
|
24608
24619
|
console.error("[AthenaSDK] Failed to load thread state:", err);
|
|
@@ -24761,6 +24772,68 @@ function useAthenaThreadManager() {
|
|
|
24761
24772
|
};
|
|
24762
24773
|
}, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
|
|
24763
24774
|
}
|
|
24775
|
+
const POLL_DELAY_MS = 5e3;
|
|
24776
|
+
const POLL_INTERVAL_MS = 1e3;
|
|
24777
|
+
const POLL_MAX_DURATION_MS = 6e4;
|
|
24778
|
+
function useThreadTitlePolling(refresh) {
|
|
24779
|
+
const threadKey = useThread({
|
|
24780
|
+
optional: true,
|
|
24781
|
+
selector: (s) => {
|
|
24782
|
+
var _a2, _b;
|
|
24783
|
+
return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
|
|
24784
|
+
}
|
|
24785
|
+
}) ?? null;
|
|
24786
|
+
const hasMessages = useThread({
|
|
24787
|
+
optional: true,
|
|
24788
|
+
selector: (s) => s.messages.length > 0
|
|
24789
|
+
}) ?? false;
|
|
24790
|
+
const currentTitle = useThreadList({
|
|
24791
|
+
optional: true,
|
|
24792
|
+
selector: (s) => {
|
|
24793
|
+
const main = s.threadItems[s.mainThreadId];
|
|
24794
|
+
return (main == null ? void 0 : main.title) ?? "";
|
|
24795
|
+
}
|
|
24796
|
+
}) ?? "";
|
|
24797
|
+
const hasTitle = currentTitle.trim().length > 0;
|
|
24798
|
+
const polledThreadsRef = React.useRef(/* @__PURE__ */ new Set());
|
|
24799
|
+
const refreshRef = React.useRef(refresh);
|
|
24800
|
+
refreshRef.current = refresh;
|
|
24801
|
+
React.useEffect(() => {
|
|
24802
|
+
if (!threadKey || hasTitle || !hasMessages) {
|
|
24803
|
+
return;
|
|
24804
|
+
}
|
|
24805
|
+
if (polledThreadsRef.current.has(threadKey)) {
|
|
24806
|
+
return;
|
|
24807
|
+
}
|
|
24808
|
+
polledThreadsRef.current.add(threadKey);
|
|
24809
|
+
let stopped = false;
|
|
24810
|
+
let intervalId = null;
|
|
24811
|
+
let maxTimeoutId = null;
|
|
24812
|
+
const stop = () => {
|
|
24813
|
+
stopped = true;
|
|
24814
|
+
if (intervalId !== null) {
|
|
24815
|
+
clearInterval(intervalId);
|
|
24816
|
+
intervalId = null;
|
|
24817
|
+
}
|
|
24818
|
+
if (maxTimeoutId !== null) {
|
|
24819
|
+
clearTimeout(maxTimeoutId);
|
|
24820
|
+
maxTimeoutId = null;
|
|
24821
|
+
}
|
|
24822
|
+
};
|
|
24823
|
+
const startTimeoutId = setTimeout(() => {
|
|
24824
|
+
if (stopped) return;
|
|
24825
|
+
refreshRef.current();
|
|
24826
|
+
intervalId = setInterval(() => {
|
|
24827
|
+
refreshRef.current();
|
|
24828
|
+
}, POLL_INTERVAL_MS);
|
|
24829
|
+
maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
|
|
24830
|
+
}, POLL_DELAY_MS);
|
|
24831
|
+
return () => {
|
|
24832
|
+
clearTimeout(startTimeoutId);
|
|
24833
|
+
stop();
|
|
24834
|
+
};
|
|
24835
|
+
}, [threadKey, hasTitle, hasMessages]);
|
|
24836
|
+
}
|
|
24764
24837
|
function createJSONStorage(getStorage, options) {
|
|
24765
24838
|
let storage;
|
|
24766
24839
|
try {
|
|
@@ -25303,12 +25376,16 @@ const useAthenaConfigValue = ({
|
|
|
25303
25376
|
linkClicksRef.current = linkClicks;
|
|
25304
25377
|
const citationLinksRef = React.useRef(citationLinks);
|
|
25305
25378
|
citationLinksRef.current = citationLinks;
|
|
25379
|
+
const tokenRef = React.useRef(token);
|
|
25380
|
+
tokenRef.current = token;
|
|
25306
25381
|
return React.useMemo(
|
|
25307
25382
|
() => ({
|
|
25308
25383
|
backendUrl,
|
|
25309
25384
|
appUrl,
|
|
25310
25385
|
apiKey,
|
|
25311
|
-
token
|
|
25386
|
+
get token() {
|
|
25387
|
+
return tokenRef.current;
|
|
25388
|
+
},
|
|
25312
25389
|
get linkClicks() {
|
|
25313
25390
|
return linkClicksRef.current;
|
|
25314
25391
|
},
|
|
@@ -25316,7 +25393,7 @@ const useAthenaConfigValue = ({
|
|
|
25316
25393
|
return citationLinksRef.current;
|
|
25317
25394
|
}
|
|
25318
25395
|
}),
|
|
25319
|
-
[backendUrl, appUrl, apiKey
|
|
25396
|
+
[backendUrl, appUrl, apiKey]
|
|
25320
25397
|
);
|
|
25321
25398
|
};
|
|
25322
25399
|
function AthenaStandalone({
|
|
@@ -25477,6 +25554,7 @@ function AthenaWithThreadList({
|
|
|
25477
25554
|
});
|
|
25478
25555
|
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
25556
|
/* @__PURE__ */ jsxRuntime.jsx(AssetPanelThreadSync, {}),
|
|
25557
|
+
/* @__PURE__ */ jsxRuntime.jsx(ThreadTitlePoller, { refresh: handleRefresh }),
|
|
25480
25558
|
children
|
|
25481
25559
|
] }) }) }) });
|
|
25482
25560
|
}
|
|
@@ -25489,6 +25567,10 @@ function AssetPanelThreadSync() {
|
|
|
25489
25567
|
}, [activeThreadId, setCurrentThread]);
|
|
25490
25568
|
return null;
|
|
25491
25569
|
}
|
|
25570
|
+
function ThreadTitlePoller({ refresh }) {
|
|
25571
|
+
useThreadTitlePolling(refresh);
|
|
25572
|
+
return null;
|
|
25573
|
+
}
|
|
25492
25574
|
function AthenaProvider({
|
|
25493
25575
|
children,
|
|
25494
25576
|
config: config2,
|
|
@@ -65520,7 +65602,10 @@ const TooltipIconButton = React.forwardRef(
|
|
|
65520
65602
|
TooltipIconButton.displayName = "TooltipIconButton";
|
|
65521
65603
|
const MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024;
|
|
65522
65604
|
function useFileUpload() {
|
|
65523
|
-
const
|
|
65605
|
+
const config2 = useAthenaConfig();
|
|
65606
|
+
const configRef = React.useRef(config2);
|
|
65607
|
+
configRef.current = config2;
|
|
65608
|
+
const { backendUrl, apiKey } = config2;
|
|
65524
65609
|
const [isUploading, setIsUploading] = React.useState(false);
|
|
65525
65610
|
const [progress, setProgress] = React.useState(null);
|
|
65526
65611
|
const [error2, setError] = React.useState(null);
|
|
@@ -65553,9 +65638,10 @@ function useFileUpload() {
|
|
|
65553
65638
|
}
|
|
65554
65639
|
const baseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
|
|
65555
65640
|
const uploadUrl = `${baseUrl}/api/upload/`;
|
|
65641
|
+
const currentToken = configRef.current.token;
|
|
65556
65642
|
const headers = {};
|
|
65557
|
-
if (
|
|
65558
|
-
headers["Authorization"] = `Bearer ${
|
|
65643
|
+
if (currentToken) {
|
|
65644
|
+
headers["Authorization"] = `Bearer ${currentToken}`;
|
|
65559
65645
|
} else if (apiKey) {
|
|
65560
65646
|
headers["X-API-KEY"] = apiKey;
|
|
65561
65647
|
}
|
|
@@ -65605,7 +65691,7 @@ function useFileUpload() {
|
|
|
65605
65691
|
for (const [key, value] of Object.entries(headers)) {
|
|
65606
65692
|
xhr.setRequestHeader(key, value);
|
|
65607
65693
|
}
|
|
65608
|
-
xhr.withCredentials = !
|
|
65694
|
+
xhr.withCredentials = !currentToken && !apiKey;
|
|
65609
65695
|
xhr.send(formData);
|
|
65610
65696
|
});
|
|
65611
65697
|
if (result.errors.length > 0) {
|
|
@@ -65627,7 +65713,7 @@ function useFileUpload() {
|
|
|
65627
65713
|
setProgress(null);
|
|
65628
65714
|
}
|
|
65629
65715
|
},
|
|
65630
|
-
[backendUrl, apiKey
|
|
65716
|
+
[backendUrl, apiKey]
|
|
65631
65717
|
);
|
|
65632
65718
|
return { upload, isUploading, progress, error: error2, clearError };
|
|
65633
65719
|
}
|