@athenaintel/react 0.6.0 → 0.6.2
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 +125 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +125 -56
- package/dist/index.js.map +1 -1
- package/package.json +9 -10
package/dist/index.js
CHANGED
|
@@ -7632,7 +7632,7 @@ const toAppendMessage = (messages, message) => {
|
|
|
7632
7632
|
startRun: message.startRun
|
|
7633
7633
|
};
|
|
7634
7634
|
};
|
|
7635
|
-
const getThreadState = (runtime, threadListItemState) => {
|
|
7635
|
+
const getThreadState$1 = (runtime, threadListItemState) => {
|
|
7636
7636
|
const lastMessage = runtime.messages.at(-1);
|
|
7637
7637
|
return Object.freeze({
|
|
7638
7638
|
threadId: threadListItemState.id,
|
|
@@ -7655,7 +7655,7 @@ class ThreadRuntimeImpl {
|
|
|
7655
7655
|
__publicField(this, "_eventSubscriptionSubjects", /* @__PURE__ */ new Map());
|
|
7656
7656
|
const stateBinding = new ShallowMemoizeSubject({
|
|
7657
7657
|
path: threadBinding.path,
|
|
7658
|
-
getState: () => getThreadState(threadBinding.getState(), threadListItemBinding.getState()),
|
|
7658
|
+
getState: () => getThreadState$1(threadBinding.getState(), threadListItemBinding.getState()),
|
|
7659
7659
|
subscribe: (callback) => {
|
|
7660
7660
|
const sub1 = threadBinding.subscribe(callback);
|
|
7661
7661
|
const sub2 = threadListItemBinding.subscribe(callback);
|
|
@@ -20619,6 +20619,73 @@ const parseLangGraphState = (state) => {
|
|
|
20619
20619
|
}
|
|
20620
20620
|
return result;
|
|
20621
20621
|
};
|
|
20622
|
+
function getAuthHeaders(auth) {
|
|
20623
|
+
if (auth.token) {
|
|
20624
|
+
return { Authorization: `Bearer ${auth.token}` };
|
|
20625
|
+
}
|
|
20626
|
+
if (auth.apiKey) {
|
|
20627
|
+
return { "X-API-KEY": auth.apiKey };
|
|
20628
|
+
}
|
|
20629
|
+
return {};
|
|
20630
|
+
}
|
|
20631
|
+
function getAgoraBaseUrl(backendUrl) {
|
|
20632
|
+
const stripped = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
|
|
20633
|
+
if (stripped === backendUrl) {
|
|
20634
|
+
return backendUrl.replace(/\/$/, "");
|
|
20635
|
+
}
|
|
20636
|
+
return stripped;
|
|
20637
|
+
}
|
|
20638
|
+
async function listThreads(backendUrl, auth, opts = {}) {
|
|
20639
|
+
const base2 = getAgoraBaseUrl(backendUrl);
|
|
20640
|
+
const res = await fetch(`${base2}/api/conversations/threads/list`, {
|
|
20641
|
+
method: "POST",
|
|
20642
|
+
headers: { "Content-Type": "application/json", ...getAuthHeaders(auth) },
|
|
20643
|
+
body: JSON.stringify({ limit: opts.limit ?? 50, offset: opts.offset ?? 0 })
|
|
20644
|
+
});
|
|
20645
|
+
if (!res.ok) {
|
|
20646
|
+
throw new Error(`[AthenaSDK] Failed to list threads: ${res.status}`);
|
|
20647
|
+
}
|
|
20648
|
+
return res.json();
|
|
20649
|
+
}
|
|
20650
|
+
function deserializeMessage(msg) {
|
|
20651
|
+
if (msg && typeof msg === "object" && "lc" in msg && "kwargs" in msg && msg.type === "constructor") {
|
|
20652
|
+
const kwargs = msg.kwargs;
|
|
20653
|
+
const deserializedToolCalls = Array.isArray(kwargs.tool_calls) ? kwargs.tool_calls.map((tc) => {
|
|
20654
|
+
if (tc && typeof tc === "object" && "lc" in tc && "kwargs" in tc) {
|
|
20655
|
+
return tc.kwargs;
|
|
20656
|
+
}
|
|
20657
|
+
return tc;
|
|
20658
|
+
}) : kwargs.tool_calls;
|
|
20659
|
+
return { ...kwargs, tool_calls: deserializedToolCalls };
|
|
20660
|
+
}
|
|
20661
|
+
return msg;
|
|
20662
|
+
}
|
|
20663
|
+
async function getThreadState(backendUrl, auth, threadId) {
|
|
20664
|
+
const base2 = getAgoraBaseUrl(backendUrl);
|
|
20665
|
+
const res = await fetch(`${base2}/api/unstable/threads/${threadId}`, {
|
|
20666
|
+
method: "GET",
|
|
20667
|
+
headers: { ...getAuthHeaders(auth) }
|
|
20668
|
+
});
|
|
20669
|
+
if (!res.ok) {
|
|
20670
|
+
throw new Error(`[AthenaSDK] Failed to get thread state: ${res.status}`);
|
|
20671
|
+
}
|
|
20672
|
+
const data = await res.json();
|
|
20673
|
+
if (Array.isArray(data.messages)) {
|
|
20674
|
+
data.messages = data.messages.map(deserializeMessage);
|
|
20675
|
+
}
|
|
20676
|
+
return data;
|
|
20677
|
+
}
|
|
20678
|
+
async function archiveThread(backendUrl, auth, threadId) {
|
|
20679
|
+
const base2 = getAgoraBaseUrl(backendUrl);
|
|
20680
|
+
const res = await fetch(`${base2}/api/conversations/threads/archive`, {
|
|
20681
|
+
method: "POST",
|
|
20682
|
+
headers: { "Content-Type": "application/json", ...getAuthHeaders(auth) },
|
|
20683
|
+
body: JSON.stringify({ thread_id: threadId })
|
|
20684
|
+
});
|
|
20685
|
+
if (!res.ok) {
|
|
20686
|
+
throw new Error(`[AthenaSDK] Failed to archive thread: ${res.status}`);
|
|
20687
|
+
}
|
|
20688
|
+
}
|
|
20622
20689
|
const DEFAULT_API_URL = "https://sync.athenaintel.com/api/chat";
|
|
20623
20690
|
const DEFAULT_BACKEND_URL = "https://api.athenaintel.com/api/assistant-ui";
|
|
20624
20691
|
const DEFAULT_MODEL = "claude-sonnet-4-6-low";
|
|
@@ -20919,15 +20986,33 @@ const useAthenaRuntime = (config2) => {
|
|
|
20919
20986
|
}
|
|
20920
20987
|
});
|
|
20921
20988
|
const hasResumedRef = useRef(false);
|
|
20989
|
+
const prevThreadIdRef = useRef(threadId);
|
|
20990
|
+
if (prevThreadIdRef.current !== threadId) {
|
|
20991
|
+
prevThreadIdRef.current = threadId;
|
|
20992
|
+
hasResumedRef.current = false;
|
|
20993
|
+
}
|
|
20922
20994
|
useEffect(() => {
|
|
20923
20995
|
if (isExistingThread && !hasResumedRef.current) {
|
|
20924
20996
|
hasResumedRef.current = true;
|
|
20925
|
-
|
|
20926
|
-
|
|
20927
|
-
|
|
20928
|
-
|
|
20997
|
+
(async () => {
|
|
20998
|
+
try {
|
|
20999
|
+
const auth = { apiKey: apiKeyRef.current, token: tokenRef.current };
|
|
21000
|
+
const state = await getThreadState(backendUrl, auth, threadId);
|
|
21001
|
+
runtime.thread.importExternalState({
|
|
21002
|
+
messages: state.messages
|
|
21003
|
+
});
|
|
21004
|
+
} catch (err) {
|
|
21005
|
+
if (process.env.NODE_ENV !== "production") {
|
|
21006
|
+
console.error("[AthenaSDK] Failed to load thread state:", err);
|
|
21007
|
+
}
|
|
21008
|
+
try {
|
|
21009
|
+
runtime.thread.unstable_resumeRun({ parentId: null });
|
|
21010
|
+
} catch {
|
|
21011
|
+
}
|
|
21012
|
+
}
|
|
21013
|
+
})();
|
|
20929
21014
|
}
|
|
20930
|
-
}, [isExistingThread, runtime]);
|
|
21015
|
+
}, [isExistingThread, runtime, threadId, backendUrl]);
|
|
20931
21016
|
return runtime;
|
|
20932
21017
|
};
|
|
20933
21018
|
function r(e) {
|
|
@@ -24161,50 +24246,13 @@ function useAthenaConfig() {
|
|
|
24161
24246
|
}
|
|
24162
24247
|
return ctx;
|
|
24163
24248
|
}
|
|
24164
|
-
function getAuthHeaders(auth) {
|
|
24165
|
-
if (auth.token) {
|
|
24166
|
-
return { Authorization: `Bearer ${auth.token}` };
|
|
24167
|
-
}
|
|
24168
|
-
if (auth.apiKey) {
|
|
24169
|
-
return { "X-API-KEY": auth.apiKey };
|
|
24170
|
-
}
|
|
24171
|
-
return {};
|
|
24172
|
-
}
|
|
24173
|
-
function getAgoraBaseUrl(backendUrl) {
|
|
24174
|
-
return backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
|
|
24175
|
-
}
|
|
24176
|
-
async function listThreads(backendUrl, auth, opts = {}) {
|
|
24177
|
-
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24178
|
-
const res = await fetch(`${base2}/api/conversations/threads/list`, {
|
|
24179
|
-
method: "POST",
|
|
24180
|
-
headers: { "Content-Type": "application/json", ...getAuthHeaders(auth) },
|
|
24181
|
-
body: JSON.stringify({ limit: opts.limit ?? 50, offset: opts.offset ?? 0 })
|
|
24182
|
-
});
|
|
24183
|
-
if (!res.ok) {
|
|
24184
|
-
throw new Error(`[AthenaSDK] Failed to list threads: ${res.status}`);
|
|
24185
|
-
}
|
|
24186
|
-
return res.json();
|
|
24187
|
-
}
|
|
24188
|
-
async function archiveThread(backendUrl, auth, threadId) {
|
|
24189
|
-
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24190
|
-
const res = await fetch(`${base2}/api/conversations/threads/archive`, {
|
|
24191
|
-
method: "POST",
|
|
24192
|
-
headers: { "Content-Type": "application/json", ...getAuthHeaders(auth) },
|
|
24193
|
-
body: JSON.stringify({ thread_id: threadId })
|
|
24194
|
-
});
|
|
24195
|
-
if (!res.ok) {
|
|
24196
|
-
throw new Error(`[AthenaSDK] Failed to archive thread: ${res.status}`);
|
|
24197
|
-
}
|
|
24198
|
-
}
|
|
24199
24249
|
const AthenaThreadIdContext = createContext(void 0);
|
|
24200
24250
|
function useAthenaThreadId() {
|
|
24201
24251
|
return useContext(AthenaThreadIdContext);
|
|
24202
24252
|
}
|
|
24203
24253
|
function useAthenaThreadListAdapter(config2) {
|
|
24204
24254
|
const configRef = useRef(config2);
|
|
24205
|
-
|
|
24206
|
-
configRef.current = config2;
|
|
24207
|
-
}, [config2]);
|
|
24255
|
+
configRef.current = config2;
|
|
24208
24256
|
const auth = useMemo(
|
|
24209
24257
|
() => ({ apiKey: config2.apiKey, token: config2.token }),
|
|
24210
24258
|
[config2.apiKey, config2.token]
|
|
@@ -24247,7 +24295,9 @@ function useAthenaThreadListAdapter(config2) {
|
|
|
24247
24295
|
await archiveThread(configRef.current.backendUrl, auth, remoteId);
|
|
24248
24296
|
},
|
|
24249
24297
|
async generateTitle(_remoteId, _messages) {
|
|
24250
|
-
return new
|
|
24298
|
+
return new ReadableStream({ start(c) {
|
|
24299
|
+
c.close();
|
|
24300
|
+
} });
|
|
24251
24301
|
},
|
|
24252
24302
|
async fetch(remoteId) {
|
|
24253
24303
|
return {
|
|
@@ -24505,7 +24555,7 @@ function AthenaWithThreadList({
|
|
|
24505
24555
|
apiKey,
|
|
24506
24556
|
token
|
|
24507
24557
|
});
|
|
24508
|
-
const
|
|
24558
|
+
const runtimeConfigRef = useRef({
|
|
24509
24559
|
apiUrl,
|
|
24510
24560
|
backendUrl,
|
|
24511
24561
|
apiKey,
|
|
@@ -24517,10 +24567,23 @@ function AthenaWithThreadList({
|
|
|
24517
24567
|
workbench,
|
|
24518
24568
|
knowledgeBase,
|
|
24519
24569
|
systemPrompt
|
|
24520
|
-
})
|
|
24570
|
+
});
|
|
24571
|
+
runtimeConfigRef.current = {
|
|
24572
|
+
apiUrl,
|
|
24573
|
+
backendUrl,
|
|
24574
|
+
apiKey,
|
|
24575
|
+
token,
|
|
24576
|
+
model,
|
|
24577
|
+
agent: agent2,
|
|
24578
|
+
tools,
|
|
24579
|
+
frontendToolIds,
|
|
24580
|
+
workbench,
|
|
24581
|
+
knowledgeBase,
|
|
24582
|
+
systemPrompt
|
|
24583
|
+
};
|
|
24521
24584
|
const runtimeHook = useCallback(
|
|
24522
|
-
() => useAthenaRuntimeHook(
|
|
24523
|
-
[
|
|
24585
|
+
() => useAthenaRuntimeHook(runtimeConfigRef.current),
|
|
24586
|
+
[]
|
|
24524
24587
|
);
|
|
24525
24588
|
const runtime = useRemoteThreadListRuntime({
|
|
24526
24589
|
runtimeHook,
|
|
@@ -61642,6 +61705,7 @@ function AssetToolCard({
|
|
|
61642
61705
|
assetId && isComplete && !isCancelled && CREATE_ASSET_TOOLS.includes(toolName.toLowerCase()) && /* @__PURE__ */ jsxs(
|
|
61643
61706
|
"button",
|
|
61644
61707
|
{
|
|
61708
|
+
type: "button",
|
|
61645
61709
|
onClick: () => openAsset(assetId, { name: title ?? void 0, type: assetType }),
|
|
61646
61710
|
className: "flex shrink-0 items-center gap-1 rounded-md border border-border/60 px-2 py-0.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
|
|
61647
61711
|
children: [
|
|
@@ -61654,6 +61718,7 @@ function AssetToolCard({
|
|
|
61654
61718
|
!isCancelled && /* @__PURE__ */ jsx(
|
|
61655
61719
|
"button",
|
|
61656
61720
|
{
|
|
61721
|
+
type: "button",
|
|
61657
61722
|
onClick: () => setDetailsOpen((o) => !o),
|
|
61658
61723
|
className: cn(
|
|
61659
61724
|
"flex size-5 shrink-0 items-center justify-center rounded transition-all",
|
|
@@ -61685,6 +61750,7 @@ function AssetOpenLink({ assetId, toolName }) {
|
|
|
61685
61750
|
return /* @__PURE__ */ jsx(
|
|
61686
61751
|
"button",
|
|
61687
61752
|
{
|
|
61753
|
+
type: "button",
|
|
61688
61754
|
onClick: (e) => {
|
|
61689
61755
|
e.stopPropagation();
|
|
61690
61756
|
openAsset(assetId, { type: assetType });
|
|
@@ -62109,7 +62175,7 @@ function ToolCard({
|
|
|
62109
62175
|
"flex size-8 shrink-0 items-center justify-center rounded-lg",
|
|
62110
62176
|
isRunning && "bg-blue-50 text-blue-600",
|
|
62111
62177
|
isComplete && "bg-emerald-50 text-emerald-600",
|
|
62112
|
-
isError && "bg-
|
|
62178
|
+
isError && "bg-destructive/10 text-destructive"
|
|
62113
62179
|
),
|
|
62114
62180
|
children: isRunning ? /* @__PURE__ */ jsx(Loader, { className: "size-4 animate-spin" }) : isError ? /* @__PURE__ */ jsx(CircleAlert, { className: "size-4" }) : /* @__PURE__ */ jsx(Icon2, { className: "size-4" })
|
|
62115
62181
|
}
|
|
@@ -62128,7 +62194,7 @@ function ToolCard({
|
|
|
62128
62194
|
/* @__PURE__ */ jsx("div", { className: "h-1.5 w-6 animate-pulse rounded-full bg-blue-100" })
|
|
62129
62195
|
] })
|
|
62130
62196
|
] }),
|
|
62131
|
-
error2 && /* @__PURE__ */ jsx("div", { className: "border-t border-border/40 bg-
|
|
62197
|
+
error2 && /* @__PURE__ */ jsx("div", { className: "border-t border-border/40 bg-destructive/10 px-4 py-2.5", children: /* @__PURE__ */ jsx("p", { className: "text-[12px] leading-relaxed text-destructive", children: error2 }) }),
|
|
62132
62198
|
children
|
|
62133
62199
|
] });
|
|
62134
62200
|
}
|
|
@@ -62374,6 +62440,7 @@ function CreateAssetToolUIImpl({
|
|
|
62374
62440
|
children: assetId && isComplete && !isCancelled && /* @__PURE__ */ jsx("div", { className: "border-t border-border/40 px-4 py-2", children: /* @__PURE__ */ jsxs(
|
|
62375
62441
|
"button",
|
|
62376
62442
|
{
|
|
62443
|
+
type: "button",
|
|
62377
62444
|
onClick: handleOpen,
|
|
62378
62445
|
className: "flex items-center gap-1.5 rounded-md border border-border/60 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
|
|
62379
62446
|
children: [
|
|
@@ -62529,12 +62596,12 @@ const RunPythonCodeToolUIImpl = ({
|
|
|
62529
62596
|
] }),
|
|
62530
62597
|
/* @__PURE__ */ jsx("pre", { className: "max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-muted/30 p-2 text-[11px] leading-relaxed font-mono text-foreground/80", children: [parsed.value, parsed.stdout, parsed.stderr].filter(Boolean).join("\n") })
|
|
62531
62598
|
] }),
|
|
62532
|
-
isComplete && hasError && /* @__PURE__ */ jsxs("div", { className: "border-t border-border/40 bg-
|
|
62599
|
+
isComplete && hasError && /* @__PURE__ */ jsxs("div", { className: "border-t border-border/40 bg-destructive/10 px-4 py-2.5", children: [
|
|
62533
62600
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 mb-1", children: [
|
|
62534
|
-
/* @__PURE__ */ jsx(TriangleAlert, { className: "size-3 text-
|
|
62535
|
-
/* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium text-
|
|
62601
|
+
/* @__PURE__ */ jsx(TriangleAlert, { className: "size-3 text-destructive" }),
|
|
62602
|
+
/* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium text-destructive", children: parsed.exception ? `${parsed.exception.name}: ${parsed.exception.value}` : "Error" })
|
|
62536
62603
|
] }),
|
|
62537
|
-
/* @__PURE__ */ jsx("pre", { className: "max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-
|
|
62604
|
+
/* @__PURE__ */ jsx("pre", { className: "max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-destructive/5 p-2 text-[11px] leading-relaxed font-mono text-destructive/80", children: ((_a2 = parsed.exception) == null ? void 0 : _a2.traceback) ?? parsed.error })
|
|
62538
62605
|
] }),
|
|
62539
62606
|
isComplete && hasImage && /* @__PURE__ */ jsxs("div", { className: "border-t border-border/40 px-4 py-2.5", children: [
|
|
62540
62607
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 mb-1.5", children: [
|
|
@@ -62555,6 +62622,7 @@ const RunPythonCodeToolUIImpl = ({
|
|
|
62555
62622
|
/* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-1.5", children: parsed.createdAssets.map((a) => /* @__PURE__ */ jsxs(
|
|
62556
62623
|
"button",
|
|
62557
62624
|
{
|
|
62625
|
+
type: "button",
|
|
62558
62626
|
onClick: () => openAsset(a.asset_id),
|
|
62559
62627
|
className: "flex items-center gap-1 rounded-md border border-border/60 px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
|
|
62560
62628
|
children: [
|
|
@@ -62609,6 +62677,7 @@ const OpenAssetToolUIImpl = ({
|
|
|
62609
62677
|
children: assetId && isComplete && !isCancelled && /* @__PURE__ */ jsx("div", { className: "border-t border-border/40 px-4 py-2", children: /* @__PURE__ */ jsxs(
|
|
62610
62678
|
"button",
|
|
62611
62679
|
{
|
|
62680
|
+
type: "button",
|
|
62612
62681
|
onClick: () => openAsset(assetId),
|
|
62613
62682
|
className: "flex items-center gap-1.5 rounded-md border border-border/60 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
|
|
62614
62683
|
children: [
|