@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.cjs +81 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +81 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7640,7 +7640,7 @@ const toAppendMessage = (messages, message) => {
|
|
|
7640
7640
|
startRun: message.startRun
|
|
7641
7641
|
};
|
|
7642
7642
|
};
|
|
7643
|
-
const getThreadState = (runtime, threadListItemState) => {
|
|
7643
|
+
const getThreadState$1 = (runtime, threadListItemState) => {
|
|
7644
7644
|
const lastMessage = runtime.messages.at(-1);
|
|
7645
7645
|
return Object.freeze({
|
|
7646
7646
|
threadId: threadListItemState.id,
|
|
@@ -7663,7 +7663,7 @@ class ThreadRuntimeImpl {
|
|
|
7663
7663
|
__publicField(this, "_eventSubscriptionSubjects", /* @__PURE__ */ new Map());
|
|
7664
7664
|
const stateBinding = new ShallowMemoizeSubject({
|
|
7665
7665
|
path: threadBinding.path,
|
|
7666
|
-
getState: () => getThreadState(threadBinding.getState(), threadListItemBinding.getState()),
|
|
7666
|
+
getState: () => getThreadState$1(threadBinding.getState(), threadListItemBinding.getState()),
|
|
7667
7667
|
subscribe: (callback) => {
|
|
7668
7668
|
const sub1 = threadBinding.subscribe(callback);
|
|
7669
7669
|
const sub2 = threadListItemBinding.subscribe(callback);
|
|
@@ -20776,7 +20776,8 @@ const useAthenaRuntime = (config2) => {
|
|
|
20776
20776
|
workbench = [],
|
|
20777
20777
|
knowledgeBase = [],
|
|
20778
20778
|
systemPrompt,
|
|
20779
|
-
threadId: threadIdProp
|
|
20779
|
+
threadId: threadIdProp,
|
|
20780
|
+
initialMessages
|
|
20780
20781
|
} = config2;
|
|
20781
20782
|
const generatedIdRef = React.useRef(null);
|
|
20782
20783
|
if (generatedIdRef.current === null) {
|
|
@@ -20794,7 +20795,7 @@ const useAthenaRuntime = (config2) => {
|
|
|
20794
20795
|
const apiKeyRef = React.useRef(apiKey);
|
|
20795
20796
|
apiKeyRef.current = apiKey;
|
|
20796
20797
|
const runtime = useAssistantTransportRuntime({
|
|
20797
|
-
initialState: { messages: [] },
|
|
20798
|
+
initialState: { messages: initialMessages ?? [] },
|
|
20798
20799
|
converter,
|
|
20799
20800
|
api: apiUrl,
|
|
20800
20801
|
headers: async () => {
|
|
@@ -24181,6 +24182,17 @@ async function listThreads(backendUrl, auth, opts = {}) {
|
|
|
24181
24182
|
}
|
|
24182
24183
|
return res.json();
|
|
24183
24184
|
}
|
|
24185
|
+
async function getThreadState(backendUrl, auth, threadId) {
|
|
24186
|
+
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24187
|
+
const res = await fetch(`${base2}/api/unstable/threads/${threadId}`, {
|
|
24188
|
+
method: "GET",
|
|
24189
|
+
headers: { ...getAuthHeaders(auth) }
|
|
24190
|
+
});
|
|
24191
|
+
if (!res.ok) {
|
|
24192
|
+
throw new Error(`[AthenaSDK] Failed to get thread state: ${res.status}`);
|
|
24193
|
+
}
|
|
24194
|
+
return res.json();
|
|
24195
|
+
}
|
|
24184
24196
|
async function archiveThread(backendUrl, auth, threadId) {
|
|
24185
24197
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24186
24198
|
const res = await fetch(`${base2}/api/conversations/threads/archive`, {
|
|
@@ -24252,7 +24264,8 @@ function AthenaRuntimeInner({
|
|
|
24252
24264
|
workbench,
|
|
24253
24265
|
knowledgeBase,
|
|
24254
24266
|
systemPrompt,
|
|
24255
|
-
threadId
|
|
24267
|
+
threadId,
|
|
24268
|
+
initialMessages
|
|
24256
24269
|
}) {
|
|
24257
24270
|
const auiTools = React.useMemo(() => Tools({ toolkit: frontendTools }), [frontendTools]);
|
|
24258
24271
|
const aui = useAui({ tools: auiTools });
|
|
@@ -24268,7 +24281,8 @@ function AthenaRuntimeInner({
|
|
|
24268
24281
|
workbench,
|
|
24269
24282
|
knowledgeBase,
|
|
24270
24283
|
systemPrompt,
|
|
24271
|
-
threadId
|
|
24284
|
+
threadId,
|
|
24285
|
+
initialMessages
|
|
24272
24286
|
});
|
|
24273
24287
|
const athenaConfig = React.useMemo(
|
|
24274
24288
|
() => ({ backendUrl, apiKey, token }),
|
|
@@ -24276,6 +24290,66 @@ function AthenaRuntimeInner({
|
|
|
24276
24290
|
);
|
|
24277
24291
|
return /* @__PURE__ */ jsxRuntime.jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children }) }) });
|
|
24278
24292
|
}
|
|
24293
|
+
function ThreadStateLoader({
|
|
24294
|
+
children,
|
|
24295
|
+
threadId,
|
|
24296
|
+
backendUrl,
|
|
24297
|
+
apiKey,
|
|
24298
|
+
token,
|
|
24299
|
+
...runtimeProps
|
|
24300
|
+
}) {
|
|
24301
|
+
const [initialMessages, setInitialMessages] = React.useState(void 0);
|
|
24302
|
+
const [isLoading, setIsLoading] = React.useState(!!threadId);
|
|
24303
|
+
React.useEffect(() => {
|
|
24304
|
+
if (!threadId) {
|
|
24305
|
+
setInitialMessages(void 0);
|
|
24306
|
+
setIsLoading(false);
|
|
24307
|
+
return;
|
|
24308
|
+
}
|
|
24309
|
+
let cancelled = false;
|
|
24310
|
+
setIsLoading(true);
|
|
24311
|
+
getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
|
|
24312
|
+
var _a2;
|
|
24313
|
+
if (cancelled) return;
|
|
24314
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24315
|
+
console.log("[AthenaThreads] Loaded thread state", {
|
|
24316
|
+
threadId,
|
|
24317
|
+
messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
|
|
24318
|
+
});
|
|
24319
|
+
}
|
|
24320
|
+
setInitialMessages(state.messages ?? []);
|
|
24321
|
+
setIsLoading(false);
|
|
24322
|
+
}).catch((err) => {
|
|
24323
|
+
if (cancelled) return;
|
|
24324
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24325
|
+
console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
|
|
24326
|
+
}
|
|
24327
|
+
setInitialMessages(void 0);
|
|
24328
|
+
setIsLoading(false);
|
|
24329
|
+
});
|
|
24330
|
+
return () => {
|
|
24331
|
+
cancelled = true;
|
|
24332
|
+
};
|
|
24333
|
+
}, [threadId, backendUrl, apiKey, token]);
|
|
24334
|
+
if (isLoading) {
|
|
24335
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "100%", width: "100%" }, children: [
|
|
24336
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: 24, height: 24, border: "2px solid currentColor", borderTopColor: "transparent", borderRadius: "50%", animation: "spin 0.6s linear infinite", opacity: 0.4 } }),
|
|
24337
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` })
|
|
24338
|
+
] });
|
|
24339
|
+
}
|
|
24340
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
24341
|
+
AthenaRuntimeInner,
|
|
24342
|
+
{
|
|
24343
|
+
threadId,
|
|
24344
|
+
backendUrl,
|
|
24345
|
+
apiKey,
|
|
24346
|
+
token,
|
|
24347
|
+
initialMessages,
|
|
24348
|
+
...runtimeProps,
|
|
24349
|
+
children
|
|
24350
|
+
}
|
|
24351
|
+
);
|
|
24352
|
+
}
|
|
24279
24353
|
function useActiveThreadFromStore(store) {
|
|
24280
24354
|
return React.useSyncExternalStore(
|
|
24281
24355
|
(cb) => {
|
|
@@ -24341,7 +24415,7 @@ function AthenaProvider({
|
|
|
24341
24415
|
}
|
|
24342
24416
|
}, [activeThreadId, resolvedThreadId, enableThreadList]);
|
|
24343
24417
|
const inner = /* @__PURE__ */ jsxRuntime.jsx(
|
|
24344
|
-
|
|
24418
|
+
ThreadStateLoader,
|
|
24345
24419
|
{
|
|
24346
24420
|
apiUrl,
|
|
24347
24421
|
backendUrl: effectiveBackendUrl,
|