@athenaintel/react 0.4.5 → 0.4.6
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 +137 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +138 -140
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24158,6 +24158,10 @@ function useThreadListStore() {
|
|
|
24158
24158
|
}
|
|
24159
24159
|
return store;
|
|
24160
24160
|
}
|
|
24161
|
+
const ThreadLoadingContext = React.createContext(false);
|
|
24162
|
+
function useThreadLoading() {
|
|
24163
|
+
return React.useContext(ThreadLoadingContext);
|
|
24164
|
+
}
|
|
24161
24165
|
function getAuthHeaders(auth) {
|
|
24162
24166
|
if (auth.token) {
|
|
24163
24167
|
return { Authorization: `Bearer ${auth.token}` };
|
|
@@ -24225,7 +24229,7 @@ async function archiveThread(backendUrl, auth, threadId) {
|
|
|
24225
24229
|
}
|
|
24226
24230
|
function createThreadListStore(config2) {
|
|
24227
24231
|
const auth = { apiKey: config2.apiKey, token: config2.token };
|
|
24228
|
-
|
|
24232
|
+
const store = create((set2, get2) => ({
|
|
24229
24233
|
threads: [],
|
|
24230
24234
|
activeThreadId: null,
|
|
24231
24235
|
isLoading: false,
|
|
@@ -24268,6 +24272,8 @@ function createThreadListStore(config2) {
|
|
|
24268
24272
|
}
|
|
24269
24273
|
}
|
|
24270
24274
|
}));
|
|
24275
|
+
store.getState().fetchThreads();
|
|
24276
|
+
return store;
|
|
24271
24277
|
}
|
|
24272
24278
|
function AthenaRuntimeInner({
|
|
24273
24279
|
children,
|
|
@@ -24309,103 +24315,6 @@ function AthenaRuntimeInner({
|
|
|
24309
24315
|
);
|
|
24310
24316
|
return /* @__PURE__ */ jsxRuntime.jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children }) }) });
|
|
24311
24317
|
}
|
|
24312
|
-
function ThreadStateLoader({
|
|
24313
|
-
children,
|
|
24314
|
-
threadId,
|
|
24315
|
-
backendUrl,
|
|
24316
|
-
apiKey,
|
|
24317
|
-
token,
|
|
24318
|
-
...runtimeProps
|
|
24319
|
-
}) {
|
|
24320
|
-
const [loadedMessages, setLoadedMessages] = React.useState(void 0);
|
|
24321
|
-
const [loadState, setLoadState] = React.useState(threadId ? "loading" : "done");
|
|
24322
|
-
const [showSpinner, setShowSpinner] = React.useState(false);
|
|
24323
|
-
React.useEffect(() => {
|
|
24324
|
-
if (!threadId) {
|
|
24325
|
-
setLoadedMessages(void 0);
|
|
24326
|
-
setLoadState("done");
|
|
24327
|
-
return;
|
|
24328
|
-
}
|
|
24329
|
-
let cancelled = false;
|
|
24330
|
-
setLoadState("loading");
|
|
24331
|
-
setShowSpinner(false);
|
|
24332
|
-
const spinnerTimer = setTimeout(() => {
|
|
24333
|
-
if (!cancelled) setShowSpinner(true);
|
|
24334
|
-
}, 200);
|
|
24335
|
-
getThreadState(backendUrl, { apiKey, token }, threadId).then((state) => {
|
|
24336
|
-
var _a2;
|
|
24337
|
-
if (cancelled) return;
|
|
24338
|
-
if (process.env.NODE_ENV !== "production") {
|
|
24339
|
-
console.log("[AthenaThreads] Loaded thread state", {
|
|
24340
|
-
threadId,
|
|
24341
|
-
messageCount: ((_a2 = state.messages) == null ? void 0 : _a2.length) ?? 0
|
|
24342
|
-
});
|
|
24343
|
-
}
|
|
24344
|
-
setLoadedMessages(state.messages ?? []);
|
|
24345
|
-
setLoadState("done");
|
|
24346
|
-
}).catch((err) => {
|
|
24347
|
-
if (cancelled) return;
|
|
24348
|
-
if (process.env.NODE_ENV !== "production") {
|
|
24349
|
-
console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
|
|
24350
|
-
}
|
|
24351
|
-
setLoadedMessages(void 0);
|
|
24352
|
-
setLoadState("done");
|
|
24353
|
-
});
|
|
24354
|
-
return () => {
|
|
24355
|
-
cancelled = true;
|
|
24356
|
-
clearTimeout(spinnerTimer);
|
|
24357
|
-
};
|
|
24358
|
-
}, [threadId, backendUrl, apiKey, token]);
|
|
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
|
-
);
|
|
24395
|
-
}
|
|
24396
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
24397
|
-
AthenaRuntimeInner,
|
|
24398
|
-
{
|
|
24399
|
-
threadId,
|
|
24400
|
-
backendUrl,
|
|
24401
|
-
apiKey,
|
|
24402
|
-
token,
|
|
24403
|
-
initialMessages: loadedMessages,
|
|
24404
|
-
...runtimeProps,
|
|
24405
|
-
children
|
|
24406
|
-
}
|
|
24407
|
-
);
|
|
24408
|
-
}
|
|
24409
24318
|
function useActiveThreadFromStore(store) {
|
|
24410
24319
|
return React.useSyncExternalStore(
|
|
24411
24320
|
(cb) => {
|
|
@@ -24459,19 +24368,51 @@ function AthenaProvider({
|
|
|
24459
24368
|
const activeThreadId = useActiveThreadFromStore(
|
|
24460
24369
|
enableThreadList ? threadListStoreRef.current : null
|
|
24461
24370
|
);
|
|
24462
|
-
const
|
|
24371
|
+
const [displayedThreadId, setDisplayedThreadId] = React.useState(null);
|
|
24372
|
+
const [loadedMessages, setLoadedMessages] = React.useState(void 0);
|
|
24373
|
+
const [isLoadingThread, setIsLoadingThread] = React.useState(false);
|
|
24463
24374
|
React.useEffect(() => {
|
|
24464
|
-
|
|
24465
|
-
|
|
24466
|
-
|
|
24467
|
-
|
|
24468
|
-
|
|
24469
|
-
|
|
24470
|
-
|
|
24375
|
+
var _a2;
|
|
24376
|
+
if (!enableThreadList) return;
|
|
24377
|
+
if (activeThreadId === displayedThreadId) return;
|
|
24378
|
+
const threads = ((_a2 = threadListStoreRef.current) == null ? void 0 : _a2.getState().threads) ?? [];
|
|
24379
|
+
const isExistingThread = threads.some((t) => t.thread_id === activeThreadId);
|
|
24380
|
+
if (!isExistingThread) {
|
|
24381
|
+
setLoadedMessages(void 0);
|
|
24382
|
+
setDisplayedThreadId(activeThreadId);
|
|
24383
|
+
setIsLoadingThread(false);
|
|
24384
|
+
return;
|
|
24471
24385
|
}
|
|
24472
|
-
|
|
24473
|
-
|
|
24474
|
-
|
|
24386
|
+
let cancelled = false;
|
|
24387
|
+
setIsLoadingThread(true);
|
|
24388
|
+
getThreadState(effectiveBackendUrl, { apiKey, token: effectiveToken }, activeThreadId).then((state) => {
|
|
24389
|
+
var _a3;
|
|
24390
|
+
if (cancelled) return;
|
|
24391
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24392
|
+
console.log("[AthenaThreads] Loaded thread state", {
|
|
24393
|
+
threadId: activeThreadId,
|
|
24394
|
+
messageCount: ((_a3 = state.messages) == null ? void 0 : _a3.length) ?? 0
|
|
24395
|
+
});
|
|
24396
|
+
}
|
|
24397
|
+
setLoadedMessages(state.messages ?? []);
|
|
24398
|
+
setDisplayedThreadId(activeThreadId);
|
|
24399
|
+
setIsLoadingThread(false);
|
|
24400
|
+
}).catch((err) => {
|
|
24401
|
+
if (cancelled) return;
|
|
24402
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24403
|
+
console.warn("[AthenaThreads] Failed to load thread state, starting fresh", err);
|
|
24404
|
+
}
|
|
24405
|
+
setLoadedMessages(void 0);
|
|
24406
|
+
setDisplayedThreadId(activeThreadId);
|
|
24407
|
+
setIsLoadingThread(false);
|
|
24408
|
+
});
|
|
24409
|
+
return () => {
|
|
24410
|
+
cancelled = true;
|
|
24411
|
+
};
|
|
24412
|
+
}, [activeThreadId, displayedThreadId, enableThreadList, effectiveBackendUrl, apiKey, effectiveToken]);
|
|
24413
|
+
const resolvedThreadId = threadIdProp ?? displayedThreadId ?? void 0;
|
|
24414
|
+
const inner = /* @__PURE__ */ jsxRuntime.jsx(ThreadLoadingContext.Provider, { value: isLoadingThread, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
24415
|
+
AthenaRuntimeInner,
|
|
24475
24416
|
{
|
|
24476
24417
|
apiUrl,
|
|
24477
24418
|
backendUrl: effectiveBackendUrl,
|
|
@@ -24486,10 +24427,11 @@ function AthenaProvider({
|
|
|
24486
24427
|
knowledgeBase,
|
|
24487
24428
|
systemPrompt,
|
|
24488
24429
|
threadId: resolvedThreadId,
|
|
24430
|
+
initialMessages: loadedMessages,
|
|
24489
24431
|
children
|
|
24490
24432
|
},
|
|
24491
24433
|
resolvedThreadId ?? "__new__"
|
|
24492
|
-
);
|
|
24434
|
+
) });
|
|
24493
24435
|
if (enableThreadList && threadListStoreRef.current) {
|
|
24494
24436
|
return /* @__PURE__ */ jsxRuntime.jsx(ThreadListContext.Provider, { value: threadListStoreRef.current, children: inner });
|
|
24495
24437
|
}
|
|
@@ -62375,6 +62317,7 @@ const AthenaChat = ({
|
|
|
62375
62317
|
toolUIs,
|
|
62376
62318
|
mentionTools
|
|
62377
62319
|
}) => {
|
|
62320
|
+
const isLoadingThread = useThreadLoading();
|
|
62378
62321
|
const tools = mentionTools ?? EMPTY_MENTION_TOOLS;
|
|
62379
62322
|
const mergedToolUIs = React.useMemo(() => ({
|
|
62380
62323
|
append_markdown_to_athena_document: AppendDocumentToolUI,
|
|
@@ -62386,40 +62329,43 @@ const AthenaChat = ({
|
|
|
62386
62329
|
() => () => /* @__PURE__ */ jsxRuntime.jsx(AssistantMessage, { toolUIs: mergedToolUIs }),
|
|
62387
62330
|
[mergedToolUIs]
|
|
62388
62331
|
);
|
|
62389
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
62332
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
62390
62333
|
ThreadPrimitiveRoot,
|
|
62391
62334
|
{
|
|
62392
62335
|
className: `aui-root aui-thread-root @container flex h-full flex-col bg-background ${className ?? ""}`,
|
|
62393
|
-
style: { ["--thread-max-width"]: maxWidth },
|
|
62394
|
-
children:
|
|
62395
|
-
|
|
62396
|
-
|
|
62397
|
-
|
|
62398
|
-
|
|
62399
|
-
|
|
62400
|
-
|
|
62401
|
-
|
|
62402
|
-
/* @__PURE__ */ jsxRuntime.jsx("
|
|
62403
|
-
|
|
62404
|
-
|
|
62405
|
-
|
|
62406
|
-
|
|
62407
|
-
|
|
62408
|
-
|
|
62409
|
-
|
|
62336
|
+
style: { ["--thread-max-width"]: maxWidth, position: "relative" },
|
|
62337
|
+
children: [
|
|
62338
|
+
isLoadingThread && /* @__PURE__ */ jsxRuntime.jsx(ThreadLoadingOverlay, {}),
|
|
62339
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
62340
|
+
ThreadPrimitiveViewport,
|
|
62341
|
+
{
|
|
62342
|
+
turnAnchor: "top",
|
|
62343
|
+
className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4",
|
|
62344
|
+
children: [
|
|
62345
|
+
/* @__PURE__ */ jsxRuntime.jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-thread-welcome-center flex w-full grow flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-4", children: [
|
|
62346
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both font-semibold text-2xl duration-200", children: welcomeMessage }),
|
|
62347
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-muted-foreground text-xl delay-75 duration-200", children: welcomeSubtext })
|
|
62348
|
+
] }) }) }) }),
|
|
62349
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
62350
|
+
ThreadPrimitiveMessages,
|
|
62351
|
+
{
|
|
62352
|
+
components: {
|
|
62353
|
+
UserMessage,
|
|
62354
|
+
AssistantMessage: AssistantMessageComponent
|
|
62355
|
+
}
|
|
62410
62356
|
}
|
|
62411
|
-
|
|
62412
|
-
|
|
62413
|
-
|
|
62414
|
-
|
|
62415
|
-
|
|
62416
|
-
|
|
62417
|
-
|
|
62357
|
+
),
|
|
62358
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ThreadPrimitiveViewportFooter, { className: "aui-thread-viewport-footer sticky bottom-0 mx-auto mt-auto flex w-full max-w-(--thread-max-width) flex-col gap-4 overflow-visible rounded-t-3xl bg-background pb-4 md:pb-6", children: [
|
|
62359
|
+
/* @__PURE__ */ jsxRuntime.jsx(ThreadScrollToBottom, {}),
|
|
62360
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ComposerPrimitiveRoot, { className: "aui-composer-root relative flex w-full flex-col rounded-2xl border border-input bg-background px-1 pt-2 outline-none transition-shadow focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/20", children: [
|
|
62361
|
+
/* @__PURE__ */ jsxRuntime.jsx(TiptapComposer, { tools }),
|
|
62362
|
+
/* @__PURE__ */ jsxRuntime.jsx(ComposerAction, {})
|
|
62363
|
+
] })
|
|
62418
62364
|
] })
|
|
62419
|
-
]
|
|
62420
|
-
|
|
62421
|
-
|
|
62422
|
-
|
|
62365
|
+
]
|
|
62366
|
+
}
|
|
62367
|
+
)
|
|
62368
|
+
]
|
|
62423
62369
|
}
|
|
62424
62370
|
);
|
|
62425
62371
|
};
|
|
@@ -62527,6 +62473,57 @@ const AssistantActionBar = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
|
62527
62473
|
]
|
|
62528
62474
|
}
|
|
62529
62475
|
);
|
|
62476
|
+
const ThreadLoadingOverlay = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
62477
|
+
"div",
|
|
62478
|
+
{
|
|
62479
|
+
className: "aui-thread-loading-overlay",
|
|
62480
|
+
style: {
|
|
62481
|
+
position: "absolute",
|
|
62482
|
+
inset: 0,
|
|
62483
|
+
zIndex: 50,
|
|
62484
|
+
display: "flex",
|
|
62485
|
+
flexDirection: "column",
|
|
62486
|
+
alignItems: "center",
|
|
62487
|
+
justifyContent: "center",
|
|
62488
|
+
gap: 12,
|
|
62489
|
+
background: "color-mix(in srgb, var(--background, #fff) 80%, transparent)",
|
|
62490
|
+
backdropFilter: "blur(4px)",
|
|
62491
|
+
WebkitBackdropFilter: "blur(4px)",
|
|
62492
|
+
animation: "aui-overlay-in 0.2s ease-out"
|
|
62493
|
+
},
|
|
62494
|
+
children: [
|
|
62495
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
62496
|
+
"div",
|
|
62497
|
+
{
|
|
62498
|
+
style: {
|
|
62499
|
+
width: 28,
|
|
62500
|
+
height: 28,
|
|
62501
|
+
border: "2.5px solid var(--border, #e5e5e5)",
|
|
62502
|
+
borderTopColor: "var(--primary, #2563eb)",
|
|
62503
|
+
borderRadius: "50%",
|
|
62504
|
+
animation: "aui-spin 0.7s linear infinite"
|
|
62505
|
+
}
|
|
62506
|
+
}
|
|
62507
|
+
),
|
|
62508
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
62509
|
+
"span",
|
|
62510
|
+
{
|
|
62511
|
+
style: {
|
|
62512
|
+
fontSize: 13,
|
|
62513
|
+
fontWeight: 500,
|
|
62514
|
+
color: "var(--muted-foreground, #888)",
|
|
62515
|
+
letterSpacing: "0.01em"
|
|
62516
|
+
},
|
|
62517
|
+
children: "Loading conversation…"
|
|
62518
|
+
}
|
|
62519
|
+
),
|
|
62520
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
62521
|
+
@keyframes aui-spin { to { transform: rotate(360deg); } }
|
|
62522
|
+
@keyframes aui-overlay-in { from { opacity: 0; } to { opacity: 1; } }
|
|
62523
|
+
` })
|
|
62524
|
+
]
|
|
62525
|
+
}
|
|
62526
|
+
);
|
|
62530
62527
|
const UserMessage = () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
62531
62528
|
MessagePrimitiveRoot,
|
|
62532
62529
|
{
|
|
@@ -62989,4 +62986,5 @@ exports.useComposerAttachment = useComposerAttachment;
|
|
|
62989
62986
|
exports.useMentionSuggestions = useMentionSuggestions;
|
|
62990
62987
|
exports.useParentAuth = useParentAuth;
|
|
62991
62988
|
exports.useThreadList = useThreadList;
|
|
62989
|
+
exports.useThreadLoading = useThreadLoading;
|
|
62992
62990
|
//# sourceMappingURL=index.cjs.map
|