@athenaintel/react 0.4.3 → 0.4.5
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 +72 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24164,6 +24164,21 @@ async function listThreads(backendUrl, auth, opts = {}) {
|
|
|
24164
24164
|
}
|
|
24165
24165
|
return res.json();
|
|
24166
24166
|
}
|
|
24167
|
+
function deserializeMessage(msg) {
|
|
24168
|
+
if (msg && typeof msg === "object" && "lc" in msg && "kwargs" in msg && msg.type === "constructor") {
|
|
24169
|
+
const kwargs = msg.kwargs;
|
|
24170
|
+
if (Array.isArray(kwargs.tool_calls)) {
|
|
24171
|
+
kwargs.tool_calls = kwargs.tool_calls.map((tc) => {
|
|
24172
|
+
if (tc && typeof tc === "object" && "lc" in tc && "kwargs" in tc) {
|
|
24173
|
+
return tc.kwargs;
|
|
24174
|
+
}
|
|
24175
|
+
return tc;
|
|
24176
|
+
});
|
|
24177
|
+
}
|
|
24178
|
+
return kwargs;
|
|
24179
|
+
}
|
|
24180
|
+
return msg;
|
|
24181
|
+
}
|
|
24167
24182
|
async function getThreadState(backendUrl, auth, threadId) {
|
|
24168
24183
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24169
24184
|
const res = await fetch(`${base2}/api/unstable/threads/${threadId}`, {
|
|
@@ -24173,7 +24188,11 @@ async function getThreadState(backendUrl, auth, threadId) {
|
|
|
24173
24188
|
if (!res.ok) {
|
|
24174
24189
|
throw new Error(`[AthenaSDK] Failed to get thread state: ${res.status}`);
|
|
24175
24190
|
}
|
|
24176
|
-
|
|
24191
|
+
const data = await res.json();
|
|
24192
|
+
if (Array.isArray(data.messages)) {
|
|
24193
|
+
data.messages = data.messages.map(deserializeMessage);
|
|
24194
|
+
}
|
|
24195
|
+
return data;
|
|
24177
24196
|
}
|
|
24178
24197
|
async function archiveThread(backendUrl, auth, threadId) {
|
|
24179
24198
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
@@ -24280,16 +24299,21 @@ function ThreadStateLoader({
|
|
|
24280
24299
|
token,
|
|
24281
24300
|
...runtimeProps
|
|
24282
24301
|
}) {
|
|
24283
|
-
const [
|
|
24284
|
-
const [
|
|
24302
|
+
const [loadedMessages, setLoadedMessages] = useState(void 0);
|
|
24303
|
+
const [loadState, setLoadState] = useState(threadId ? "loading" : "done");
|
|
24304
|
+
const [showSpinner, setShowSpinner] = useState(false);
|
|
24285
24305
|
useEffect(() => {
|
|
24286
24306
|
if (!threadId) {
|
|
24287
|
-
|
|
24288
|
-
|
|
24307
|
+
setLoadedMessages(void 0);
|
|
24308
|
+
setLoadState("done");
|
|
24289
24309
|
return;
|
|
24290
24310
|
}
|
|
24291
24311
|
let cancelled = false;
|
|
24292
|
-
|
|
24312
|
+
setLoadState("loading");
|
|
24313
|
+
setShowSpinner(false);
|
|
24314
|
+
const spinnerTimer = setTimeout(() => {
|
|
24315
|
+
if (!cancelled) setShowSpinner(true);
|
|
24316
|
+
}, 200);
|
|
24293
24317
|
getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
|
|
24294
24318
|
var _a2;
|
|
24295
24319
|
if (cancelled) return;
|
|
@@ -24299,25 +24323,57 @@ function ThreadStateLoader({
|
|
|
24299
24323
|
messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
|
|
24300
24324
|
});
|
|
24301
24325
|
}
|
|
24302
|
-
|
|
24303
|
-
|
|
24326
|
+
setLoadedMessages(state.messages ?? []);
|
|
24327
|
+
setLoadState("done");
|
|
24304
24328
|
}).catch((err) => {
|
|
24305
24329
|
if (cancelled) return;
|
|
24306
24330
|
if (process.env.NODE_ENV !== "production") {
|
|
24307
24331
|
console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
|
|
24308
24332
|
}
|
|
24309
|
-
|
|
24310
|
-
|
|
24333
|
+
setLoadedMessages(void 0);
|
|
24334
|
+
setLoadState("done");
|
|
24311
24335
|
});
|
|
24312
24336
|
return () => {
|
|
24313
24337
|
cancelled = true;
|
|
24338
|
+
clearTimeout(spinnerTimer);
|
|
24314
24339
|
};
|
|
24315
24340
|
}, [threadId, backendUrl, apiKey, token]);
|
|
24316
|
-
if (
|
|
24317
|
-
return /* @__PURE__ */ jsxs(
|
|
24318
|
-
|
|
24319
|
-
|
|
24320
|
-
|
|
24341
|
+
if (loadState === "loading") {
|
|
24342
|
+
return /* @__PURE__ */ jsxs(
|
|
24343
|
+
"div",
|
|
24344
|
+
{
|
|
24345
|
+
style: {
|
|
24346
|
+
display: "flex",
|
|
24347
|
+
flexDirection: "column",
|
|
24348
|
+
alignItems: "center",
|
|
24349
|
+
justifyContent: "center",
|
|
24350
|
+
height: "100%",
|
|
24351
|
+
width: "100%",
|
|
24352
|
+
background: "var(--background, #fff)",
|
|
24353
|
+
color: "var(--muted-foreground, #888)",
|
|
24354
|
+
gap: 8,
|
|
24355
|
+
opacity: showSpinner ? 1 : 0,
|
|
24356
|
+
transition: "opacity 0.15s ease-in"
|
|
24357
|
+
},
|
|
24358
|
+
children: [
|
|
24359
|
+
/* @__PURE__ */ jsx(
|
|
24360
|
+
"div",
|
|
24361
|
+
{
|
|
24362
|
+
style: {
|
|
24363
|
+
width: 20,
|
|
24364
|
+
height: 20,
|
|
24365
|
+
border: "2px solid var(--border, #e5e5e5)",
|
|
24366
|
+
borderTopColor: "var(--primary, #2563eb)",
|
|
24367
|
+
borderRadius: "50%",
|
|
24368
|
+
animation: "aui-spin 0.6s linear infinite"
|
|
24369
|
+
}
|
|
24370
|
+
}
|
|
24371
|
+
),
|
|
24372
|
+
/* @__PURE__ */ jsx("span", { style: { fontSize: 13 }, children: "Loading conversation…" }),
|
|
24373
|
+
/* @__PURE__ */ jsx("style", { children: `@keyframes aui-spin { to { transform: rotate(360deg); } }` })
|
|
24374
|
+
]
|
|
24375
|
+
}
|
|
24376
|
+
);
|
|
24321
24377
|
}
|
|
24322
24378
|
return /* @__PURE__ */ jsx(
|
|
24323
24379
|
AthenaRuntimeInner,
|
|
@@ -24326,7 +24382,7 @@ function ThreadStateLoader({
|
|
|
24326
24382
|
backendUrl,
|
|
24327
24383
|
apiKey,
|
|
24328
24384
|
token,
|
|
24329
|
-
initialMessages,
|
|
24385
|
+
initialMessages: loadedMessages,
|
|
24330
24386
|
...runtimeProps,
|
|
24331
24387
|
children
|
|
24332
24388
|
}
|