@athenaintel/react 0.4.2 → 0.4.3

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
@@ -6,6 +6,7 @@ import { ComponentPropsWithRef } from 'react';
6
6
  import { FC } from 'react';
7
7
  import { ForwardRefExoticComponent } from 'react';
8
8
  import { JSX } from 'react/jsx-runtime';
9
+ import { LangChainMessage } from '@assistant-ui/react-langgraph';
9
10
  import * as React_2 from 'react';
10
11
  import { ReactNode } from 'react';
11
12
  import { RefAttributes } from 'react';
@@ -152,6 +153,8 @@ export declare interface AthenaRuntimeConfig {
152
153
  systemPrompt?: string;
153
154
  /** Thread ID override. Auto-generated if not provided. */
154
155
  threadId?: string;
156
+ /** Pre-loaded messages for existing threads (from thread switching). */
157
+ initialMessages?: LangChainMessage[];
155
158
  }
156
159
 
157
160
  export declare const BrowseToolUI: ToolCallMessagePartComponent;
package/dist/index.js CHANGED
@@ -7622,7 +7622,7 @@ const toAppendMessage = (messages, message) => {
7622
7622
  startRun: message.startRun
7623
7623
  };
7624
7624
  };
7625
- const getThreadState = (runtime, threadListItemState) => {
7625
+ const getThreadState$1 = (runtime, threadListItemState) => {
7626
7626
  const lastMessage = runtime.messages.at(-1);
7627
7627
  return Object.freeze({
7628
7628
  threadId: threadListItemState.id,
@@ -7645,7 +7645,7 @@ class ThreadRuntimeImpl {
7645
7645
  __publicField(this, "_eventSubscriptionSubjects", /* @__PURE__ */ new Map());
7646
7646
  const stateBinding = new ShallowMemoizeSubject({
7647
7647
  path: threadBinding.path,
7648
- getState: () => getThreadState(threadBinding.getState(), threadListItemBinding.getState()),
7648
+ getState: () => getThreadState$1(threadBinding.getState(), threadListItemBinding.getState()),
7649
7649
  subscribe: (callback) => {
7650
7650
  const sub1 = threadBinding.subscribe(callback);
7651
7651
  const sub2 = threadListItemBinding.subscribe(callback);
@@ -20758,7 +20758,8 @@ const useAthenaRuntime = (config2) => {
20758
20758
  workbench = [],
20759
20759
  knowledgeBase = [],
20760
20760
  systemPrompt,
20761
- threadId: threadIdProp
20761
+ threadId: threadIdProp,
20762
+ initialMessages
20762
20763
  } = config2;
20763
20764
  const generatedIdRef = useRef(null);
20764
20765
  if (generatedIdRef.current === null) {
@@ -20776,7 +20777,7 @@ const useAthenaRuntime = (config2) => {
20776
20777
  const apiKeyRef = useRef(apiKey);
20777
20778
  apiKeyRef.current = apiKey;
20778
20779
  const runtime = useAssistantTransportRuntime({
20779
- initialState: { messages: [] },
20780
+ initialState: { messages: initialMessages ?? [] },
20780
20781
  converter,
20781
20782
  api: apiUrl,
20782
20783
  headers: async () => {
@@ -24163,6 +24164,17 @@ async function listThreads(backendUrl, auth, opts = {}) {
24163
24164
  }
24164
24165
  return res.json();
24165
24166
  }
24167
+ async function getThreadState(backendUrl, auth, threadId) {
24168
+ const base2 = getAgoraBaseUrl(backendUrl);
24169
+ const res = await fetch(`${base2}/api/unstable/threads/${threadId}`, {
24170
+ method: "GET",
24171
+ headers: { ...getAuthHeaders(auth) }
24172
+ });
24173
+ if (!res.ok) {
24174
+ throw new Error(`[AthenaSDK] Failed to get thread state: ${res.status}`);
24175
+ }
24176
+ return res.json();
24177
+ }
24166
24178
  async function archiveThread(backendUrl, auth, threadId) {
24167
24179
  const base2 = getAgoraBaseUrl(backendUrl);
24168
24180
  const res = await fetch(`${base2}/api/conversations/threads/archive`, {
@@ -24234,7 +24246,8 @@ function AthenaRuntimeInner({
24234
24246
  workbench,
24235
24247
  knowledgeBase,
24236
24248
  systemPrompt,
24237
- threadId
24249
+ threadId,
24250
+ initialMessages
24238
24251
  }) {
24239
24252
  const auiTools = useMemo(() => Tools({ toolkit: frontendTools }), [frontendTools]);
24240
24253
  const aui = useAui({ tools: auiTools });
@@ -24250,7 +24263,8 @@ function AthenaRuntimeInner({
24250
24263
  workbench,
24251
24264
  knowledgeBase,
24252
24265
  systemPrompt,
24253
- threadId
24266
+ threadId,
24267
+ initialMessages
24254
24268
  });
24255
24269
  const athenaConfig = useMemo(
24256
24270
  () => ({ backendUrl, apiKey, token }),
@@ -24258,6 +24272,66 @@ function AthenaRuntimeInner({
24258
24272
  );
24259
24273
  return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(TooltipProvider, { children }) }) });
24260
24274
  }
24275
+ function ThreadStateLoader({
24276
+ children,
24277
+ threadId,
24278
+ backendUrl,
24279
+ apiKey,
24280
+ token,
24281
+ ...runtimeProps
24282
+ }) {
24283
+ const [initialMessages, setInitialMessages] = useState(void 0);
24284
+ const [isLoading, setIsLoading] = useState(!!threadId);
24285
+ useEffect(() => {
24286
+ if (!threadId) {
24287
+ setInitialMessages(void 0);
24288
+ setIsLoading(false);
24289
+ return;
24290
+ }
24291
+ let cancelled = false;
24292
+ setIsLoading(true);
24293
+ getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
24294
+ var _a2;
24295
+ if (cancelled) return;
24296
+ if (process.env.NODE_ENV !== "production") {
24297
+ console.log("[AthenaThreads] Loaded thread state", {
24298
+ threadId,
24299
+ messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
24300
+ });
24301
+ }
24302
+ setInitialMessages(state.messages ?? []);
24303
+ setIsLoading(false);
24304
+ }).catch((err) => {
24305
+ if (cancelled) return;
24306
+ if (process.env.NODE_ENV !== "production") {
24307
+ console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
24308
+ }
24309
+ setInitialMessages(void 0);
24310
+ setIsLoading(false);
24311
+ });
24312
+ return () => {
24313
+ cancelled = true;
24314
+ };
24315
+ }, [threadId, backendUrl, apiKey, token]);
24316
+ if (isLoading) {
24317
+ return /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "100%", width: "100%" }, children: [
24318
+ /* @__PURE__ */ jsx("div", { style: { width: 24, height: 24, border: "2px solid currentColor", borderTopColor: "transparent", borderRadius: "50%", animation: "spin 0.6s linear infinite", opacity: 0.4 } }),
24319
+ /* @__PURE__ */ jsx("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` })
24320
+ ] });
24321
+ }
24322
+ return /* @__PURE__ */ jsx(
24323
+ AthenaRuntimeInner,
24324
+ {
24325
+ threadId,
24326
+ backendUrl,
24327
+ apiKey,
24328
+ token,
24329
+ initialMessages,
24330
+ ...runtimeProps,
24331
+ children
24332
+ }
24333
+ );
24334
+ }
24261
24335
  function useActiveThreadFromStore(store) {
24262
24336
  return useSyncExternalStore(
24263
24337
  (cb) => {
@@ -24323,7 +24397,7 @@ function AthenaProvider({
24323
24397
  }
24324
24398
  }, [activeThreadId, resolvedThreadId, enableThreadList]);
24325
24399
  const inner = /* @__PURE__ */ jsx(
24326
- AthenaRuntimeInner,
24400
+ ThreadStateLoader,
24327
24401
  {
24328
24402
  apiUrl,
24329
24403
  backendUrl: effectiveBackendUrl,