@athenaintel/react 0.10.15 → 0.10.17

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,6 +24554,7 @@ 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;
@@ -24565,15 +24566,23 @@ const useAthenaRuntime = (config2) => {
24565
24566
  runtime.thread.importExternalState({
24566
24567
  messages: state.messages
24567
24568
  });
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);
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 });
24575
24580
  }
24576
24581
  }
24582
+ } catch (statusErr) {
24583
+ if (IS_DEV) {
24584
+ console.warn("[AthenaSDK] Sync server status check failed:", statusErr);
24585
+ }
24577
24586
  }
24578
24587
  } catch (err) {
24579
24588
  if (IS_DEV) {
@@ -24586,7 +24595,7 @@ const useAthenaRuntime = (config2) => {
24586
24595
  }
24587
24596
  })();
24588
24597
  }
24589
- }, [isExistingThread, runtime, threadId, backendUrl]);
24598
+ }, [isExistingThread, runtime, threadId, backendUrl, resolvedStatusApiUrl]);
24590
24599
  return runtime;
24591
24600
  };
24592
24601
  function TooltipProvider({
@@ -24701,14 +24710,32 @@ const ThreadListRefreshContext = createContext(null);
24701
24710
  function useRefreshThreadList() {
24702
24711
  return useContext(ThreadListRefreshContext);
24703
24712
  }
24713
+ const LOCAL_ID_PREFIX = "__LOCALID_";
24714
+ const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
24704
24715
  function useAthenaThreadManager() {
24705
24716
  const runtime = useAssistantRuntime({ optional: true });
24706
- const remoteId = useThread({ optional: true, selector: (s) => {
24707
- var _a2;
24708
- return (_a2 = s.metadata) == null ? void 0 : _a2.remoteId;
24709
- } });
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
+ console.log("[AthenaSDK] useAthenaThreadManager selector", {
24723
+ metadata: s.metadata,
24724
+ threadId: s.threadId,
24725
+ rawRemoteId: id,
24726
+ isPlaceholder: isLocalPlaceholder(id)
24727
+ });
24728
+ return isLocalPlaceholder(id) ? void 0 : id;
24729
+ }
24730
+ });
24710
24731
  const isThreadLoading = useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
24711
24732
  const isListLoading = useThreadList({ optional: true, selector: (s) => s.isLoading });
24733
+ console.log("[AthenaSDK] useAthenaThreadManager render", {
24734
+ remoteId,
24735
+ isThreadLoading,
24736
+ isListLoading,
24737
+ hasRuntime: !!runtime
24738
+ });
24712
24739
  const runtimeRef = useRef(runtime);
24713
24740
  runtimeRef.current = runtime;
24714
24741
  const switchToThread = useCallback(