@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.cjs
CHANGED
|
@@ -24182,6 +24182,21 @@ async function listThreads(backendUrl, auth, opts = {}) {
|
|
|
24182
24182
|
}
|
|
24183
24183
|
return res.json();
|
|
24184
24184
|
}
|
|
24185
|
+
function deserializeMessage(msg) {
|
|
24186
|
+
if (msg && typeof msg === "object" && "lc" in msg && "kwargs" in msg && msg.type === "constructor") {
|
|
24187
|
+
const kwargs = msg.kwargs;
|
|
24188
|
+
if (Array.isArray(kwargs.tool_calls)) {
|
|
24189
|
+
kwargs.tool_calls = kwargs.tool_calls.map((tc) => {
|
|
24190
|
+
if (tc && typeof tc === "object" && "lc" in tc && "kwargs" in tc) {
|
|
24191
|
+
return tc.kwargs;
|
|
24192
|
+
}
|
|
24193
|
+
return tc;
|
|
24194
|
+
});
|
|
24195
|
+
}
|
|
24196
|
+
return kwargs;
|
|
24197
|
+
}
|
|
24198
|
+
return msg;
|
|
24199
|
+
}
|
|
24185
24200
|
async function getThreadState(backendUrl, auth, threadId) {
|
|
24186
24201
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24187
24202
|
const res = await fetch(`${base2}/api/unstable/threads/${threadId}`, {
|
|
@@ -24191,7 +24206,11 @@ async function getThreadState(backendUrl, auth, threadId) {
|
|
|
24191
24206
|
if (!res.ok) {
|
|
24192
24207
|
throw new Error(`[AthenaSDK] Failed to get thread state: ${res.status}`);
|
|
24193
24208
|
}
|
|
24194
|
-
|
|
24209
|
+
const data = await res.json();
|
|
24210
|
+
if (Array.isArray(data.messages)) {
|
|
24211
|
+
data.messages = data.messages.map(deserializeMessage);
|
|
24212
|
+
}
|
|
24213
|
+
return data;
|
|
24195
24214
|
}
|
|
24196
24215
|
async function archiveThread(backendUrl, auth, threadId) {
|
|
24197
24216
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
@@ -24298,16 +24317,21 @@ function ThreadStateLoader({
|
|
|
24298
24317
|
token,
|
|
24299
24318
|
...runtimeProps
|
|
24300
24319
|
}) {
|
|
24301
|
-
const [
|
|
24302
|
-
const [
|
|
24320
|
+
const [loadedMessages, setLoadedMessages] = React.useState(void 0);
|
|
24321
|
+
const [loadState, setLoadState] = React.useState(threadId ? "loading" : "done");
|
|
24322
|
+
const [showSpinner, setShowSpinner] = React.useState(false);
|
|
24303
24323
|
React.useEffect(() => {
|
|
24304
24324
|
if (!threadId) {
|
|
24305
|
-
|
|
24306
|
-
|
|
24325
|
+
setLoadedMessages(void 0);
|
|
24326
|
+
setLoadState("done");
|
|
24307
24327
|
return;
|
|
24308
24328
|
}
|
|
24309
24329
|
let cancelled = false;
|
|
24310
|
-
|
|
24330
|
+
setLoadState("loading");
|
|
24331
|
+
setShowSpinner(false);
|
|
24332
|
+
const spinnerTimer = setTimeout(() => {
|
|
24333
|
+
if (!cancelled) setShowSpinner(true);
|
|
24334
|
+
}, 200);
|
|
24311
24335
|
getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
|
|
24312
24336
|
var _a2;
|
|
24313
24337
|
if (cancelled) return;
|
|
@@ -24317,25 +24341,57 @@ function ThreadStateLoader({
|
|
|
24317
24341
|
messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
|
|
24318
24342
|
});
|
|
24319
24343
|
}
|
|
24320
|
-
|
|
24321
|
-
|
|
24344
|
+
setLoadedMessages(state.messages ?? []);
|
|
24345
|
+
setLoadState("done");
|
|
24322
24346
|
}).catch((err) => {
|
|
24323
24347
|
if (cancelled) return;
|
|
24324
24348
|
if (process.env.NODE_ENV !== "production") {
|
|
24325
24349
|
console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
|
|
24326
24350
|
}
|
|
24327
|
-
|
|
24328
|
-
|
|
24351
|
+
setLoadedMessages(void 0);
|
|
24352
|
+
setLoadState("done");
|
|
24329
24353
|
});
|
|
24330
24354
|
return () => {
|
|
24331
24355
|
cancelled = true;
|
|
24356
|
+
clearTimeout(spinnerTimer);
|
|
24332
24357
|
};
|
|
24333
24358
|
}, [threadId, backendUrl, apiKey, token]);
|
|
24334
|
-
if (
|
|
24335
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
24336
|
-
|
|
24337
|
-
|
|
24338
|
-
|
|
24359
|
+
if (loadState === "loading") {
|
|
24360
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
24361
|
+
"div",
|
|
24362
|
+
{
|
|
24363
|
+
style: {
|
|
24364
|
+
display: "flex",
|
|
24365
|
+
flexDirection: "column",
|
|
24366
|
+
alignItems: "center",
|
|
24367
|
+
justifyContent: "center",
|
|
24368
|
+
height: "100%",
|
|
24369
|
+
width: "100%",
|
|
24370
|
+
background: "var(--background, #fff)",
|
|
24371
|
+
color: "var(--muted-foreground, #888)",
|
|
24372
|
+
gap: 8,
|
|
24373
|
+
opacity: showSpinner ? 1 : 0,
|
|
24374
|
+
transition: "opacity 0.15s ease-in"
|
|
24375
|
+
},
|
|
24376
|
+
children: [
|
|
24377
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
24378
|
+
"div",
|
|
24379
|
+
{
|
|
24380
|
+
style: {
|
|
24381
|
+
width: 20,
|
|
24382
|
+
height: 20,
|
|
24383
|
+
border: "2px solid var(--border, #e5e5e5)",
|
|
24384
|
+
borderTopColor: "var(--primary, #2563eb)",
|
|
24385
|
+
borderRadius: "50%",
|
|
24386
|
+
animation: "aui-spin 0.6s linear infinite"
|
|
24387
|
+
}
|
|
24388
|
+
}
|
|
24389
|
+
),
|
|
24390
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 13 }, children: "Loading conversation…" }),
|
|
24391
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `@keyframes aui-spin { to { transform: rotate(360deg); } }` })
|
|
24392
|
+
]
|
|
24393
|
+
}
|
|
24394
|
+
);
|
|
24339
24395
|
}
|
|
24340
24396
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
24341
24397
|
AthenaRuntimeInner,
|
|
@@ -24344,7 +24400,7 @@ function ThreadStateLoader({
|
|
|
24344
24400
|
backendUrl,
|
|
24345
24401
|
apiKey,
|
|
24346
24402
|
token,
|
|
24347
|
-
initialMessages,
|
|
24403
|
+
initialMessages: loadedMessages,
|
|
24348
24404
|
...runtimeProps,
|
|
24349
24405
|
children
|
|
24350
24406
|
}
|