@athenaintel/react 0.4.1 → 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.cjs +105 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +105 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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`, {
|
|
@@ -24194,6 +24206,9 @@ function createThreadListStore(config2) {
|
|
|
24194
24206
|
}
|
|
24195
24207
|
},
|
|
24196
24208
|
switchThread: (threadId) => {
|
|
24209
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24210
|
+
console.log("[AthenaThreads] switchThread called", { threadId, prev: get2().activeThreadId });
|
|
24211
|
+
}
|
|
24197
24212
|
set2({ activeThreadId: threadId });
|
|
24198
24213
|
},
|
|
24199
24214
|
newThread: async () => {
|
|
@@ -24231,7 +24246,8 @@ function AthenaRuntimeInner({
|
|
|
24231
24246
|
workbench,
|
|
24232
24247
|
knowledgeBase,
|
|
24233
24248
|
systemPrompt,
|
|
24234
|
-
threadId
|
|
24249
|
+
threadId,
|
|
24250
|
+
initialMessages
|
|
24235
24251
|
}) {
|
|
24236
24252
|
const auiTools = useMemo(() => Tools({ toolkit: frontendTools }), [frontendTools]);
|
|
24237
24253
|
const aui = useAui({ tools: auiTools });
|
|
@@ -24247,7 +24263,8 @@ function AthenaRuntimeInner({
|
|
|
24247
24263
|
workbench,
|
|
24248
24264
|
knowledgeBase,
|
|
24249
24265
|
systemPrompt,
|
|
24250
|
-
threadId
|
|
24266
|
+
threadId,
|
|
24267
|
+
initialMessages
|
|
24251
24268
|
});
|
|
24252
24269
|
const athenaConfig = useMemo(
|
|
24253
24270
|
() => ({ backendUrl, apiKey, token }),
|
|
@@ -24255,6 +24272,66 @@ function AthenaRuntimeInner({
|
|
|
24255
24272
|
);
|
|
24256
24273
|
return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(TooltipProvider, { children }) }) });
|
|
24257
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
|
+
}
|
|
24258
24335
|
function useActiveThreadFromStore(store) {
|
|
24259
24336
|
return useSyncExternalStore(
|
|
24260
24337
|
(cb) => {
|
|
@@ -24286,6 +24363,17 @@ function AthenaProvider({
|
|
|
24286
24363
|
const parentAuthToken = useParentAuth();
|
|
24287
24364
|
const effectiveToken = tokenProp ?? parentAuthToken;
|
|
24288
24365
|
const effectiveBackendUrl = backendUrl ?? DEFAULT_BACKEND_URL;
|
|
24366
|
+
useEffect(() => {
|
|
24367
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24368
|
+
console.log("[AthenaAuth] AthenaProvider auth state", {
|
|
24369
|
+
hasTokenProp: !!tokenProp,
|
|
24370
|
+
hasParentAuthToken: !!parentAuthToken,
|
|
24371
|
+
hasEffectiveToken: !!effectiveToken,
|
|
24372
|
+
hasApiKey: !!apiKey,
|
|
24373
|
+
authMethod: effectiveToken ? "Bearer token (PropelAuth)" : apiKey ? "X-API-KEY" : "NONE"
|
|
24374
|
+
});
|
|
24375
|
+
}
|
|
24376
|
+
}, [tokenProp, parentAuthToken, effectiveToken, apiKey]);
|
|
24289
24377
|
const threadListStoreRef = useRef(null);
|
|
24290
24378
|
if (enableThreadList && !threadListStoreRef.current) {
|
|
24291
24379
|
threadListStoreRef.current = createThreadListStore({
|
|
@@ -24298,8 +24386,18 @@ function AthenaProvider({
|
|
|
24298
24386
|
enableThreadList ? threadListStoreRef.current : null
|
|
24299
24387
|
);
|
|
24300
24388
|
const resolvedThreadId = threadIdProp ?? activeThreadId ?? void 0;
|
|
24389
|
+
useEffect(() => {
|
|
24390
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24391
|
+
console.log("[AthenaThreads] AthenaProvider render", {
|
|
24392
|
+
activeThreadId,
|
|
24393
|
+
resolvedThreadId,
|
|
24394
|
+
enableThreadList,
|
|
24395
|
+
hasStore: !!threadListStoreRef.current
|
|
24396
|
+
});
|
|
24397
|
+
}
|
|
24398
|
+
}, [activeThreadId, resolvedThreadId, enableThreadList]);
|
|
24301
24399
|
const inner = /* @__PURE__ */ jsx(
|
|
24302
|
-
|
|
24400
|
+
ThreadStateLoader,
|
|
24303
24401
|
{
|
|
24304
24402
|
apiUrl,
|
|
24305
24403
|
backendUrl: effectiveBackendUrl,
|