@athenaintel/react 0.10.14 → 0.10.16
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 +46 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -21
- package/dist/index.js +46 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24593,16 +24593,36 @@ const useAthenaRuntime = (config2) => {
|
|
|
24593
24593
|
prevThreadIdRef.current = threadId;
|
|
24594
24594
|
hasResumedRef.current = false;
|
|
24595
24595
|
}
|
|
24596
|
+
const resolvedStatusApiUrl = apiUrl.replace(/\/api\/chat$/, "/api/status");
|
|
24596
24597
|
React.useEffect(() => {
|
|
24597
24598
|
if (isExistingThread && !hasResumedRef.current) {
|
|
24598
24599
|
hasResumedRef.current = true;
|
|
24599
24600
|
(async () => {
|
|
24601
|
+
var _a2;
|
|
24600
24602
|
try {
|
|
24601
24603
|
const auth = { apiKey: apiKeyRef.current, token: tokenRef.current };
|
|
24602
24604
|
const state = await getThreadState(backendUrl, auth, threadId);
|
|
24603
24605
|
runtime.thread.importExternalState({
|
|
24604
24606
|
messages: state.messages
|
|
24605
24607
|
});
|
|
24608
|
+
try {
|
|
24609
|
+
const statusRes = await fetch(resolvedStatusApiUrl, {
|
|
24610
|
+
method: "POST",
|
|
24611
|
+
headers: { "Content-Type": "application/json" },
|
|
24612
|
+
body: JSON.stringify({ threadId })
|
|
24613
|
+
});
|
|
24614
|
+
if (statusRes.ok) {
|
|
24615
|
+
const status = await statusRes.json();
|
|
24616
|
+
if (status.isRunning) {
|
|
24617
|
+
const lastMessageId = ((_a2 = runtime.thread.getState().messages.at(-1)) == null ? void 0 : _a2.id) ?? null;
|
|
24618
|
+
runtime.thread.unstable_resumeRun({ parentId: lastMessageId });
|
|
24619
|
+
}
|
|
24620
|
+
}
|
|
24621
|
+
} catch (statusErr) {
|
|
24622
|
+
if (IS_DEV) {
|
|
24623
|
+
console.warn("[AthenaSDK] Sync server status check failed:", statusErr);
|
|
24624
|
+
}
|
|
24625
|
+
}
|
|
24606
24626
|
} catch (err) {
|
|
24607
24627
|
if (IS_DEV) {
|
|
24608
24628
|
console.error("[AthenaSDK] Failed to load thread state:", err);
|
|
@@ -24614,7 +24634,7 @@ const useAthenaRuntime = (config2) => {
|
|
|
24614
24634
|
}
|
|
24615
24635
|
})();
|
|
24616
24636
|
}
|
|
24617
|
-
}, [isExistingThread, runtime, threadId, backendUrl]);
|
|
24637
|
+
}, [isExistingThread, runtime, threadId, backendUrl, resolvedStatusApiUrl]);
|
|
24618
24638
|
return runtime;
|
|
24619
24639
|
};
|
|
24620
24640
|
function TooltipProvider({
|
|
@@ -24729,12 +24749,18 @@ const ThreadListRefreshContext = React.createContext(null);
|
|
|
24729
24749
|
function useRefreshThreadList() {
|
|
24730
24750
|
return React.useContext(ThreadListRefreshContext);
|
|
24731
24751
|
}
|
|
24752
|
+
const LOCAL_ID_PREFIX = "__LOCALID_";
|
|
24753
|
+
const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
|
|
24732
24754
|
function useAthenaThreadManager() {
|
|
24733
24755
|
const runtime = useAssistantRuntime({ optional: true });
|
|
24734
|
-
const remoteId = useThread({
|
|
24735
|
-
|
|
24736
|
-
|
|
24737
|
-
|
|
24756
|
+
const remoteId = useThread({
|
|
24757
|
+
optional: true,
|
|
24758
|
+
selector: (s) => {
|
|
24759
|
+
var _a2;
|
|
24760
|
+
const id = (_a2 = s.metadata) == null ? void 0 : _a2.remoteId;
|
|
24761
|
+
return isLocalPlaceholder(id) ? void 0 : id;
|
|
24762
|
+
}
|
|
24763
|
+
});
|
|
24738
24764
|
const isThreadLoading = useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
|
|
24739
24765
|
const isListLoading = useThreadList({ optional: true, selector: (s) => s.isLoading });
|
|
24740
24766
|
const runtimeRef = React.useRef(runtime);
|
|
@@ -25365,12 +25391,16 @@ const useAthenaConfigValue = ({
|
|
|
25365
25391
|
linkClicksRef.current = linkClicks;
|
|
25366
25392
|
const citationLinksRef = React.useRef(citationLinks);
|
|
25367
25393
|
citationLinksRef.current = citationLinks;
|
|
25394
|
+
const tokenRef = React.useRef(token);
|
|
25395
|
+
tokenRef.current = token;
|
|
25368
25396
|
return React.useMemo(
|
|
25369
25397
|
() => ({
|
|
25370
25398
|
backendUrl,
|
|
25371
25399
|
appUrl,
|
|
25372
25400
|
apiKey,
|
|
25373
|
-
token
|
|
25401
|
+
get token() {
|
|
25402
|
+
return tokenRef.current;
|
|
25403
|
+
},
|
|
25374
25404
|
get linkClicks() {
|
|
25375
25405
|
return linkClicksRef.current;
|
|
25376
25406
|
},
|
|
@@ -25378,7 +25408,7 @@ const useAthenaConfigValue = ({
|
|
|
25378
25408
|
return citationLinksRef.current;
|
|
25379
25409
|
}
|
|
25380
25410
|
}),
|
|
25381
|
-
[backendUrl, appUrl, apiKey
|
|
25411
|
+
[backendUrl, appUrl, apiKey]
|
|
25382
25412
|
);
|
|
25383
25413
|
};
|
|
25384
25414
|
function AthenaStandalone({
|
|
@@ -65587,7 +65617,10 @@ const TooltipIconButton = React.forwardRef(
|
|
|
65587
65617
|
TooltipIconButton.displayName = "TooltipIconButton";
|
|
65588
65618
|
const MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024;
|
|
65589
65619
|
function useFileUpload() {
|
|
65590
|
-
const
|
|
65620
|
+
const config2 = useAthenaConfig();
|
|
65621
|
+
const configRef = React.useRef(config2);
|
|
65622
|
+
configRef.current = config2;
|
|
65623
|
+
const { backendUrl, apiKey } = config2;
|
|
65591
65624
|
const [isUploading, setIsUploading] = React.useState(false);
|
|
65592
65625
|
const [progress, setProgress] = React.useState(null);
|
|
65593
65626
|
const [error2, setError] = React.useState(null);
|
|
@@ -65620,9 +65653,10 @@ function useFileUpload() {
|
|
|
65620
65653
|
}
|
|
65621
65654
|
const baseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
|
|
65622
65655
|
const uploadUrl = `${baseUrl}/api/upload/`;
|
|
65656
|
+
const currentToken = configRef.current.token;
|
|
65623
65657
|
const headers = {};
|
|
65624
|
-
if (
|
|
65625
|
-
headers["Authorization"] = `Bearer ${
|
|
65658
|
+
if (currentToken) {
|
|
65659
|
+
headers["Authorization"] = `Bearer ${currentToken}`;
|
|
65626
65660
|
} else if (apiKey) {
|
|
65627
65661
|
headers["X-API-KEY"] = apiKey;
|
|
65628
65662
|
}
|
|
@@ -65672,7 +65706,7 @@ function useFileUpload() {
|
|
|
65672
65706
|
for (const [key, value] of Object.entries(headers)) {
|
|
65673
65707
|
xhr.setRequestHeader(key, value);
|
|
65674
65708
|
}
|
|
65675
|
-
xhr.withCredentials = !
|
|
65709
|
+
xhr.withCredentials = !currentToken && !apiKey;
|
|
65676
65710
|
xhr.send(formData);
|
|
65677
65711
|
});
|
|
65678
65712
|
if (result.errors.length > 0) {
|
|
@@ -65694,7 +65728,7 @@ function useFileUpload() {
|
|
|
65694
65728
|
setProgress(null);
|
|
65695
65729
|
}
|
|
65696
65730
|
},
|
|
65697
|
-
[backendUrl, apiKey
|
|
65731
|
+
[backendUrl, apiKey]
|
|
65698
65732
|
);
|
|
65699
65733
|
return { upload, isUploading, progress, error: error2, clearError };
|
|
65700
65734
|
}
|