@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.d.ts CHANGED
@@ -1214,27 +1214,6 @@ export declare const useAthenaLinkClickHandler: () => AthenaLinkClickHandler;
1214
1214
 
1215
1215
  export declare const useAthenaRuntime: (config: AthenaRuntimeConfig) => AssistantRuntime;
1216
1216
 
1217
- /**
1218
- * Hook for managing thread navigation.
1219
- *
1220
- * Returns `null` when called outside `<AthenaProvider enableThreadList>`
1221
- * or before the runtime has initialized.
1222
- *
1223
- * @example
1224
- * ```tsx
1225
- * function MyComponent() {
1226
- * const threads = useAthenaThreadManager();
1227
- * if (!threads) return null;
1228
- *
1229
- * return (
1230
- * <div>
1231
- * <p>Active: {threads.activeThreadId}</p>
1232
- * <button onClick={() => threads.switchToNewThread()}>New Chat</button>
1233
- * </div>
1234
- * );
1235
- * }
1236
- * ```
1237
- */
1238
1217
  export declare function useAthenaThreadManager(): AthenaThreadManagerState | null;
1239
1218
 
1240
1219
  /**
package/dist/index.js CHANGED
@@ -24554,16 +24554,36 @@ const useAthenaRuntime = (config2) => {
24554
24554
  prevThreadIdRef.current = threadId;
24555
24555
  hasResumedRef.current = false;
24556
24556
  }
24557
+ const resolvedStatusApiUrl = apiUrl.replace(/\/api\/chat$/, "/api/status");
24557
24558
  useEffect(() => {
24558
24559
  if (isExistingThread && !hasResumedRef.current) {
24559
24560
  hasResumedRef.current = true;
24560
24561
  (async () => {
24562
+ var _a2;
24561
24563
  try {
24562
24564
  const auth = { apiKey: apiKeyRef.current, token: tokenRef.current };
24563
24565
  const state = await getThreadState(backendUrl, auth, threadId);
24564
24566
  runtime.thread.importExternalState({
24565
24567
  messages: state.messages
24566
24568
  });
24569
+ try {
24570
+ const statusRes = await fetch(resolvedStatusApiUrl, {
24571
+ method: "POST",
24572
+ headers: { "Content-Type": "application/json" },
24573
+ body: JSON.stringify({ threadId })
24574
+ });
24575
+ if (statusRes.ok) {
24576
+ const status = await statusRes.json();
24577
+ if (status.isRunning) {
24578
+ const lastMessageId = ((_a2 = runtime.thread.getState().messages.at(-1)) == null ? void 0 : _a2.id) ?? null;
24579
+ runtime.thread.unstable_resumeRun({ parentId: lastMessageId });
24580
+ }
24581
+ }
24582
+ } catch (statusErr) {
24583
+ if (IS_DEV) {
24584
+ console.warn("[AthenaSDK] Sync server status check failed:", statusErr);
24585
+ }
24586
+ }
24567
24587
  } catch (err) {
24568
24588
  if (IS_DEV) {
24569
24589
  console.error("[AthenaSDK] Failed to load thread state:", err);
@@ -24575,7 +24595,7 @@ const useAthenaRuntime = (config2) => {
24575
24595
  }
24576
24596
  })();
24577
24597
  }
24578
- }, [isExistingThread, runtime, threadId, backendUrl]);
24598
+ }, [isExistingThread, runtime, threadId, backendUrl, resolvedStatusApiUrl]);
24579
24599
  return runtime;
24580
24600
  };
24581
24601
  function TooltipProvider({
@@ -24690,12 +24710,18 @@ const ThreadListRefreshContext = createContext(null);
24690
24710
  function useRefreshThreadList() {
24691
24711
  return useContext(ThreadListRefreshContext);
24692
24712
  }
24713
+ const LOCAL_ID_PREFIX = "__LOCALID_";
24714
+ const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
24693
24715
  function useAthenaThreadManager() {
24694
24716
  const runtime = useAssistantRuntime({ optional: true });
24695
- const remoteId = useThread({ optional: true, selector: (s) => {
24696
- var _a2;
24697
- return (_a2 = s.metadata) == null ? void 0 : _a2.remoteId;
24698
- } });
24717
+ const remoteId = useThread({
24718
+ optional: true,
24719
+ selector: (s) => {
24720
+ var _a2;
24721
+ const id = (_a2 = s.metadata) == null ? void 0 : _a2.remoteId;
24722
+ return isLocalPlaceholder(id) ? void 0 : id;
24723
+ }
24724
+ });
24699
24725
  const isThreadLoading = useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
24700
24726
  const isListLoading = useThreadList({ optional: true, selector: (s) => s.isLoading });
24701
24727
  const runtimeRef = useRef(runtime);
@@ -25326,12 +25352,16 @@ const useAthenaConfigValue = ({
25326
25352
  linkClicksRef.current = linkClicks;
25327
25353
  const citationLinksRef = useRef(citationLinks);
25328
25354
  citationLinksRef.current = citationLinks;
25355
+ const tokenRef = useRef(token);
25356
+ tokenRef.current = token;
25329
25357
  return useMemo(
25330
25358
  () => ({
25331
25359
  backendUrl,
25332
25360
  appUrl,
25333
25361
  apiKey,
25334
- token,
25362
+ get token() {
25363
+ return tokenRef.current;
25364
+ },
25335
25365
  get linkClicks() {
25336
25366
  return linkClicksRef.current;
25337
25367
  },
@@ -25339,7 +25369,7 @@ const useAthenaConfigValue = ({
25339
25369
  return citationLinksRef.current;
25340
25370
  }
25341
25371
  }),
25342
- [backendUrl, appUrl, apiKey, token]
25372
+ [backendUrl, appUrl, apiKey]
25343
25373
  );
25344
25374
  };
25345
25375
  function AthenaStandalone({
@@ -65548,7 +65578,10 @@ const TooltipIconButton = forwardRef(
65548
65578
  TooltipIconButton.displayName = "TooltipIconButton";
65549
65579
  const MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024;
65550
65580
  function useFileUpload() {
65551
- const { backendUrl, apiKey, token } = useAthenaConfig();
65581
+ const config2 = useAthenaConfig();
65582
+ const configRef = useRef(config2);
65583
+ configRef.current = config2;
65584
+ const { backendUrl, apiKey } = config2;
65552
65585
  const [isUploading, setIsUploading] = useState(false);
65553
65586
  const [progress, setProgress] = useState(null);
65554
65587
  const [error2, setError] = useState(null);
@@ -65581,9 +65614,10 @@ function useFileUpload() {
65581
65614
  }
65582
65615
  const baseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
65583
65616
  const uploadUrl = `${baseUrl}/api/upload/`;
65617
+ const currentToken = configRef.current.token;
65584
65618
  const headers = {};
65585
- if (token) {
65586
- headers["Authorization"] = `Bearer ${token}`;
65619
+ if (currentToken) {
65620
+ headers["Authorization"] = `Bearer ${currentToken}`;
65587
65621
  } else if (apiKey) {
65588
65622
  headers["X-API-KEY"] = apiKey;
65589
65623
  }
@@ -65633,7 +65667,7 @@ function useFileUpload() {
65633
65667
  for (const [key, value] of Object.entries(headers)) {
65634
65668
  xhr.setRequestHeader(key, value);
65635
65669
  }
65636
- xhr.withCredentials = !token && !apiKey;
65670
+ xhr.withCredentials = !currentToken && !apiKey;
65637
65671
  xhr.send(formData);
65638
65672
  });
65639
65673
  if (result.errors.length > 0) {
@@ -65655,7 +65689,7 @@ function useFileUpload() {
65655
65689
  setProgress(null);
65656
65690
  }
65657
65691
  },
65658
- [backendUrl, apiKey, token]
65692
+ [backendUrl, apiKey]
65659
65693
  );
65660
65694
  return { upload, isUploading, progress, error: error2, clearError };
65661
65695
  }