@athenaintel/react 0.9.18 → 0.9.20
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/README.md +57 -1
- package/dist/AthenaAuthContext-B3AwLA5Z.cjs +15 -0
- package/dist/AthenaAuthContext-B3AwLA5Z.cjs.map +1 -0
- package/dist/AthenaAuthContext-DQsdayH2.js +16 -0
- package/dist/AthenaAuthContext-DQsdayH2.js.map +1 -0
- package/dist/auth.cjs +358 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.ts +240 -0
- package/dist/auth.js +359 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.cjs +146 -221
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +87 -17
- package/dist/index.js +146 -221
- package/dist/index.js.map +1 -1
- package/package.json +23 -12
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
import { jsx, jsxs, Fragment as Fragment$2 } from "react/jsx-runtime";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import React__default, { useMemo, useReducer, useLayoutEffect, useRef, useState, useContext, createContext, useSyncExternalStore, useDebugValue, useEffect, useCallback, memo, Fragment as Fragment$1, useId as useId$2, forwardRef, createRef, createElement, version as version$1, useImperativeHandle } from "react";
|
|
7
|
+
import { A as AthenaAuthContext } from "./AthenaAuthContext-DQsdayH2.js";
|
|
7
8
|
import * as ReactDOM from "react-dom";
|
|
8
9
|
import ReactDOM__default, { flushSync } from "react-dom";
|
|
9
10
|
function commitAllEffects(renderResult) {
|
|
@@ -16565,17 +16566,50 @@ function createAthenaSpacesUrl({
|
|
|
16565
16566
|
}
|
|
16566
16567
|
return url.toString();
|
|
16567
16568
|
}
|
|
16568
|
-
function isTrustedOrigin(
|
|
16569
|
+
function isTrustedOrigin({
|
|
16570
|
+
origin,
|
|
16571
|
+
trustedOrigins
|
|
16572
|
+
}) {
|
|
16569
16573
|
try {
|
|
16570
|
-
const
|
|
16574
|
+
const normalizedOrigin = new URL(origin).origin;
|
|
16575
|
+
if (trustedOrigins.includes(normalizedOrigin)) {
|
|
16576
|
+
return true;
|
|
16577
|
+
}
|
|
16578
|
+
const { hostname } = new URL(normalizedOrigin);
|
|
16571
16579
|
return hostname === "athenaintel.com" || hostname.endsWith(".athenaintel.com") || hostname === "localhost";
|
|
16572
16580
|
} catch {
|
|
16573
16581
|
return false;
|
|
16574
16582
|
}
|
|
16575
16583
|
}
|
|
16576
16584
|
const BRIDGE_TIMEOUT_MS = 2e3;
|
|
16577
|
-
|
|
16585
|
+
const normalizeOrigin = (value) => {
|
|
16586
|
+
try {
|
|
16587
|
+
return new URL(value).origin;
|
|
16588
|
+
} catch {
|
|
16589
|
+
return null;
|
|
16590
|
+
}
|
|
16591
|
+
};
|
|
16592
|
+
function useParentBridge({
|
|
16593
|
+
trustedOrigins = []
|
|
16594
|
+
} = {}) {
|
|
16578
16595
|
const isInIframe = typeof window !== "undefined" && window.parent !== window;
|
|
16596
|
+
const runtimeTrustedOrigins = useMemo(() => {
|
|
16597
|
+
const origins = /* @__PURE__ */ new Set();
|
|
16598
|
+
if (typeof window !== "undefined") {
|
|
16599
|
+
origins.add(window.location.origin);
|
|
16600
|
+
const referrerOrigin = normalizeOrigin(document.referrer);
|
|
16601
|
+
if (referrerOrigin) {
|
|
16602
|
+
origins.add(referrerOrigin);
|
|
16603
|
+
}
|
|
16604
|
+
}
|
|
16605
|
+
for (const trustedOrigin of trustedOrigins) {
|
|
16606
|
+
const normalizedOrigin = normalizeOrigin(trustedOrigin);
|
|
16607
|
+
if (normalizedOrigin) {
|
|
16608
|
+
origins.add(normalizedOrigin);
|
|
16609
|
+
}
|
|
16610
|
+
}
|
|
16611
|
+
return [...origins];
|
|
16612
|
+
}, [trustedOrigins]);
|
|
16579
16613
|
const [state, setState] = useState({
|
|
16580
16614
|
token: null,
|
|
16581
16615
|
apiUrl: null,
|
|
@@ -16589,7 +16623,9 @@ function useParentBridge() {
|
|
|
16589
16623
|
useEffect(() => {
|
|
16590
16624
|
if (!isInIframe) return;
|
|
16591
16625
|
const handler = (event) => {
|
|
16592
|
-
if (!isTrustedOrigin(event.origin))
|
|
16626
|
+
if (!isTrustedOrigin({ origin: event.origin, trustedOrigins: runtimeTrustedOrigins })) {
|
|
16627
|
+
return;
|
|
16628
|
+
}
|
|
16593
16629
|
if (!event.data || typeof event.data !== "object") return;
|
|
16594
16630
|
if (event.data.type === "athena-config") {
|
|
16595
16631
|
configReceived.current = true;
|
|
@@ -16624,7 +16660,7 @@ function useParentBridge() {
|
|
|
16624
16660
|
window.removeEventListener("message", handler);
|
|
16625
16661
|
clearTimeout(timer);
|
|
16626
16662
|
};
|
|
16627
|
-
}, [isInIframe]);
|
|
16663
|
+
}, [isInIframe, runtimeTrustedOrigins]);
|
|
16628
16664
|
return state;
|
|
16629
16665
|
}
|
|
16630
16666
|
function useParentAuth() {
|
|
@@ -24299,6 +24335,22 @@ const useAthenaRuntime = (config2) => {
|
|
|
24299
24335
|
tokenRef.current = token;
|
|
24300
24336
|
const apiKeyRef = useRef(apiKey);
|
|
24301
24337
|
apiKeyRef.current = apiKey;
|
|
24338
|
+
const runConfigRef = useRef({
|
|
24339
|
+
enabledTools,
|
|
24340
|
+
agent: agent2,
|
|
24341
|
+
model,
|
|
24342
|
+
workbench,
|
|
24343
|
+
knowledgeBase,
|
|
24344
|
+
systemPrompt
|
|
24345
|
+
});
|
|
24346
|
+
runConfigRef.current = {
|
|
24347
|
+
enabledTools,
|
|
24348
|
+
agent: agent2,
|
|
24349
|
+
model,
|
|
24350
|
+
workbench,
|
|
24351
|
+
knowledgeBase,
|
|
24352
|
+
systemPrompt
|
|
24353
|
+
};
|
|
24302
24354
|
const isExistingThread = !!threadIdProp;
|
|
24303
24355
|
const runtime = useAssistantTransportRuntime({
|
|
24304
24356
|
initialState: { messages: [] },
|
|
@@ -24397,16 +24449,17 @@ const useAthenaRuntime = (config2) => {
|
|
|
24397
24449
|
return true;
|
|
24398
24450
|
},
|
|
24399
24451
|
get runConfig() {
|
|
24452
|
+
const currentRunConfig = runConfigRef.current;
|
|
24400
24453
|
return {
|
|
24401
24454
|
custom: {
|
|
24402
|
-
enabled_tools: enabledTools,
|
|
24403
|
-
agent:
|
|
24404
|
-
model,
|
|
24455
|
+
enabled_tools: currentRunConfig.enabledTools,
|
|
24456
|
+
agent: currentRunConfig.agent,
|
|
24457
|
+
model: currentRunConfig.model,
|
|
24405
24458
|
effort_dial_duration: -1,
|
|
24406
24459
|
plan_mode_enabled: false,
|
|
24407
|
-
workbench,
|
|
24408
|
-
knowledge_base: knowledgeBase,
|
|
24409
|
-
...systemPrompt ? { system_prompt: systemPrompt } : {}
|
|
24460
|
+
workbench: currentRunConfig.workbench,
|
|
24461
|
+
knowledge_base: currentRunConfig.knowledgeBase,
|
|
24462
|
+
...currentRunConfig.systemPrompt ? { system_prompt: currentRunConfig.systemPrompt } : {}
|
|
24410
24463
|
},
|
|
24411
24464
|
persistToolInvocationLogs: true
|
|
24412
24465
|
};
|
|
@@ -24955,8 +25008,13 @@ function AthenaProvider({
|
|
|
24955
25008
|
const configuredApiUrl = (config2 == null ? void 0 : config2.apiUrl) ?? apiUrl;
|
|
24956
25009
|
const configuredBackendUrl = (config2 == null ? void 0 : config2.backendUrl) ?? backendUrl;
|
|
24957
25010
|
const configuredAppUrl = (config2 == null ? void 0 : config2.appUrl) ?? appUrl;
|
|
24958
|
-
const
|
|
24959
|
-
const
|
|
25011
|
+
const configuredTrustedParentOrigins = config2 == null ? void 0 : config2.trustedParentOrigins;
|
|
25012
|
+
const bridge = useParentBridge({
|
|
25013
|
+
trustedOrigins: configuredTrustedParentOrigins
|
|
25014
|
+
});
|
|
25015
|
+
const authContext = useContext(AthenaAuthContext);
|
|
25016
|
+
const authProviderToken = (authContext == null ? void 0 : authContext.accessToken) ?? null;
|
|
25017
|
+
const effectiveToken = configuredToken !== void 0 ? configuredToken : authProviderToken ?? bridge.token;
|
|
24960
25018
|
const effectiveApiUrl = configuredApiUrl ?? bridge.apiUrl ?? environmentUrls.apiUrl;
|
|
24961
25019
|
const effectiveBackendUrl = configuredBackendUrl ?? bridge.backendUrl ?? environmentUrls.backendUrl;
|
|
24962
25020
|
const effectiveAppUrl = configuredAppUrl ?? bridge.appUrl ?? deriveAthenaAppUrl({ apiUrl: effectiveApiUrl, backendUrl: effectiveBackendUrl }) ?? environmentUrls.appUrl;
|
|
@@ -58878,39 +58936,17 @@ const useAssetPanelStore = create()(
|
|
|
58878
58936
|
const existing = s.tabs.find((t) => t.id === assetId);
|
|
58879
58937
|
if (existing) {
|
|
58880
58938
|
const tabs = meta ? s.tabs.map(
|
|
58881
|
-
(t) => t.id === assetId ? {
|
|
58882
|
-
...t,
|
|
58883
|
-
name: meta.name ?? t.name,
|
|
58884
|
-
type: meta.type ?? t.type,
|
|
58885
|
-
embedSearchParams: meta.embedSearchParams ?? t.embedSearchParams
|
|
58886
|
-
} : t
|
|
58939
|
+
(t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
|
|
58887
58940
|
) : s.tabs;
|
|
58888
58941
|
return { isOpen: true, tabs, activeTabId: assetId };
|
|
58889
58942
|
}
|
|
58890
58943
|
const newTab = {
|
|
58891
58944
|
id: assetId,
|
|
58892
58945
|
name: (meta == null ? void 0 : meta.name) ?? null,
|
|
58893
|
-
type: (meta == null ? void 0 : meta.type) ?? "unknown"
|
|
58894
|
-
embedSearchParams: (meta == null ? void 0 : meta.embedSearchParams) ?? null
|
|
58946
|
+
type: (meta == null ? void 0 : meta.type) ?? "unknown"
|
|
58895
58947
|
};
|
|
58896
58948
|
return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
|
|
58897
58949
|
}),
|
|
58898
|
-
updateTabMeta: (assetId, meta) => set2((s) => {
|
|
58899
|
-
const existing = s.tabs.find((t) => t.id === assetId);
|
|
58900
|
-
if (!existing) {
|
|
58901
|
-
return {};
|
|
58902
|
-
}
|
|
58903
|
-
return {
|
|
58904
|
-
tabs: s.tabs.map(
|
|
58905
|
-
(t) => t.id === assetId ? {
|
|
58906
|
-
...t,
|
|
58907
|
-
name: meta.name ?? t.name,
|
|
58908
|
-
type: meta.type ?? t.type,
|
|
58909
|
-
embedSearchParams: meta.embedSearchParams ?? t.embedSearchParams
|
|
58910
|
-
} : t
|
|
58911
|
-
)
|
|
58912
|
-
};
|
|
58913
|
-
}),
|
|
58914
58950
|
closeTab: (assetId) => set2((s) => {
|
|
58915
58951
|
var _a2;
|
|
58916
58952
|
const tabs = s.tabs.filter((t) => t.id !== assetId);
|
|
@@ -58968,43 +59004,13 @@ const ASSET_TYPE_ALIASES = {
|
|
|
58968
59004
|
super_document: "document"
|
|
58969
59005
|
};
|
|
58970
59006
|
const isAthenaSpacesPath = (url) => url.pathname.replace(/\/+$/, "") === "/dashboard/spaces";
|
|
58971
|
-
const normalizeAssetType
|
|
59007
|
+
const normalizeAssetType = (value) => {
|
|
58972
59008
|
if (!value) {
|
|
58973
59009
|
return null;
|
|
58974
59010
|
}
|
|
58975
59011
|
const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
|
|
58976
59012
|
return ASSET_TYPE_ALIASES[normalizedValue] ?? null;
|
|
58977
59013
|
};
|
|
58978
|
-
const isLikelyAssetId = (value) => !!value && /^(asset|thread|project|collection)_[a-z0-9-]+$/i.test(value.trim());
|
|
58979
|
-
const sanitizeDisplayName = (value) => {
|
|
58980
|
-
if (!value) {
|
|
58981
|
-
return null;
|
|
58982
|
-
}
|
|
58983
|
-
const trimmedValue = value.trim();
|
|
58984
|
-
if (!trimmedValue) {
|
|
58985
|
-
return null;
|
|
58986
|
-
}
|
|
58987
|
-
if (trimmedValue.startsWith('"') && trimmedValue.endsWith('"') || trimmedValue.startsWith("'") && trimmedValue.endsWith("'")) {
|
|
58988
|
-
return trimmedValue.slice(1, -1).trim() || null;
|
|
58989
|
-
}
|
|
58990
|
-
return trimmedValue;
|
|
58991
|
-
};
|
|
58992
|
-
const getCitationDisplayName = ({
|
|
58993
|
-
assetName,
|
|
58994
|
-
linkText
|
|
58995
|
-
}) => {
|
|
58996
|
-
const sanitizedAssetName = sanitizeDisplayName(assetName);
|
|
58997
|
-
const sanitizedLinkText = sanitizeDisplayName(linkText);
|
|
58998
|
-
const genericLinkTextPattern = /^(this|that|the)\s+asset$/i;
|
|
58999
|
-
if (sanitizedAssetName && !isLikelyAssetId(sanitizedAssetName)) {
|
|
59000
|
-
return sanitizedAssetName;
|
|
59001
|
-
}
|
|
59002
|
-
if (sanitizedLinkText && !genericLinkTextPattern.test(sanitizedLinkText)) {
|
|
59003
|
-
return sanitizedLinkText;
|
|
59004
|
-
}
|
|
59005
|
-
return sanitizedAssetName ?? sanitizedLinkText;
|
|
59006
|
-
};
|
|
59007
|
-
const getEmbedSearchParams = (url) => Object.fromEntries(url.searchParams.entries());
|
|
59008
59014
|
const getOrigin = (value) => {
|
|
59009
59015
|
if (!value) {
|
|
59010
59016
|
return null;
|
|
@@ -59086,11 +59092,7 @@ const parseAthenaCitationLink = ({
|
|
|
59086
59092
|
url,
|
|
59087
59093
|
assetId,
|
|
59088
59094
|
assetIds,
|
|
59089
|
-
assetType: normalizeAssetType
|
|
59090
|
-
url.searchParams.get("asset_type") ?? url.searchParams.get("assetType") ?? url.searchParams.get("type")
|
|
59091
|
-
),
|
|
59092
|
-
assetName: sanitizeDisplayName(url.searchParams.get("name")),
|
|
59093
|
-
embedSearchParams: getEmbedSearchParams(url)
|
|
59095
|
+
assetType: normalizeAssetType(url.searchParams.get("asset_type") ?? url.searchParams.get("type"))
|
|
59094
59096
|
};
|
|
59095
59097
|
};
|
|
59096
59098
|
const isAthenaCitationUrl = ({
|
|
@@ -59138,19 +59140,12 @@ const useAthenaLinkClickHandler = () => {
|
|
|
59138
59140
|
const citationMetadata = citationLink ? {
|
|
59139
59141
|
assetId: citationLink.assetId,
|
|
59140
59142
|
assetIds: citationLink.assetIds,
|
|
59141
|
-
assetType: citationLink.assetType
|
|
59142
|
-
assetName: citationLink.assetName,
|
|
59143
|
-
embedSearchParams: citationLink.embedSearchParams
|
|
59143
|
+
assetType: citationLink.assetType
|
|
59144
59144
|
} : null;
|
|
59145
59145
|
const openInAssetPanel = citationLink ? () => {
|
|
59146
|
-
const displayName = getCitationDisplayName({
|
|
59147
|
-
assetName: citationLink.assetName,
|
|
59148
|
-
linkText: trimmedLinkText
|
|
59149
|
-
});
|
|
59150
59146
|
openAsset(citationLink.assetId, {
|
|
59151
|
-
name:
|
|
59152
|
-
type: citationLink.assetType ?? void 0
|
|
59153
|
-
embedSearchParams: citationLink.embedSearchParams
|
|
59147
|
+
name: trimmedLinkText ?? void 0,
|
|
59148
|
+
type: citationLink.assetType ?? void 0
|
|
59154
59149
|
});
|
|
59155
59150
|
} : void 0;
|
|
59156
59151
|
const context2 = {
|
|
@@ -62402,7 +62397,9 @@ const TOOL_META = {
|
|
|
62402
62397
|
create_email_draft: { displayName: "Drafting email", icon: Mail },
|
|
62403
62398
|
unified_email_create_draft: { displayName: "Drafting email", icon: Mail },
|
|
62404
62399
|
edit_email_draft: { displayName: "Editing email draft", icon: Mail },
|
|
62405
|
-
|
|
62400
|
+
unified_email_edit_draft: { displayName: "Editing email draft", icon: Mail },
|
|
62401
|
+
unified_email_fetch_attachments: { displayName: "Fetching email attachments", icon: Mail },
|
|
62402
|
+
unified_email_forward: { displayName: "Forwarding email", icon: Mail },
|
|
62406
62403
|
// Documents
|
|
62407
62404
|
read_full_asset: { displayName: "Reading document", icon: BookOpen },
|
|
62408
62405
|
create_new_document: { displayName: "Creating document", icon: FileText },
|
|
@@ -63590,12 +63587,6 @@ function extractAssetId(result) {
|
|
|
63590
63587
|
if (typeof id === "string" && id.startsWith("asset_")) return id;
|
|
63591
63588
|
return null;
|
|
63592
63589
|
}
|
|
63593
|
-
function extractAssetTitle(result) {
|
|
63594
|
-
const data = normalizeResult(result);
|
|
63595
|
-
if (!data) return null;
|
|
63596
|
-
const title = data.assetTitle ?? data.asset_title ?? data.title ?? data.name;
|
|
63597
|
-
return typeof title === "string" && title.trim().length > 0 ? title.trim() : null;
|
|
63598
|
-
}
|
|
63599
63590
|
function resetAssetAutoOpen() {
|
|
63600
63591
|
useAssetPanelStore.getState().resetAutoOpen();
|
|
63601
63592
|
}
|
|
@@ -64315,7 +64306,6 @@ const OpenAssetToolUIImpl = ({
|
|
|
64315
64306
|
const typedArgs = args;
|
|
64316
64307
|
const argsAssetId = (typedArgs == null ? void 0 : typedArgs.asset_id) ?? (typedArgs == null ? void 0 : typedArgs.assetId) ?? "";
|
|
64317
64308
|
const resultAssetId = extractAssetId(result);
|
|
64318
|
-
const resultAssetTitle = extractAssetTitle(result);
|
|
64319
64309
|
const assetId = resultAssetId ?? (argsAssetId.startsWith("asset_") ? argsAssetId : null);
|
|
64320
64310
|
const isRunning = (status == null ? void 0 : status.type) === "running";
|
|
64321
64311
|
const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
|
|
@@ -64327,10 +64317,10 @@ const OpenAssetToolUIImpl = ({
|
|
|
64327
64317
|
if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
|
|
64328
64318
|
const store = useAssetPanelStore.getState();
|
|
64329
64319
|
if (store.markAutoOpened(assetId)) {
|
|
64330
|
-
store.openAsset(assetId
|
|
64320
|
+
store.openAsset(assetId);
|
|
64331
64321
|
}
|
|
64332
64322
|
}
|
|
64333
|
-
}, [isComplete, isCancelled, assetId
|
|
64323
|
+
}, [isComplete, isCancelled, assetId]);
|
|
64334
64324
|
return /* @__PURE__ */ jsx(
|
|
64335
64325
|
ToolCard,
|
|
64336
64326
|
{
|
|
@@ -64346,7 +64336,7 @@ const OpenAssetToolUIImpl = ({
|
|
|
64346
64336
|
"button",
|
|
64347
64337
|
{
|
|
64348
64338
|
type: "button",
|
|
64349
|
-
onClick: () => openAsset(assetId
|
|
64339
|
+
onClick: () => openAsset(assetId),
|
|
64350
64340
|
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",
|
|
64351
64341
|
children: [
|
|
64352
64342
|
/* @__PURE__ */ jsx(ExternalLink, { className: "size-3" }),
|
|
@@ -64957,7 +64947,9 @@ const AthenaChat = ({
|
|
|
64957
64947
|
{
|
|
64958
64948
|
turnAnchor: "top",
|
|
64959
64949
|
className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4",
|
|
64950
|
+
"data-aui-thread-viewport": "",
|
|
64960
64951
|
children: [
|
|
64952
|
+
/* @__PURE__ */ jsx(ThreadScrollToTop, {}),
|
|
64961
64953
|
/* @__PURE__ */ jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsx("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col", children: /* @__PURE__ */ jsx("div", { className: "aui-thread-welcome-center flex w-full grow flex-col items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-4", children: [
|
|
64962
64954
|
/* @__PURE__ */ 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 }),
|
|
64963
64955
|
welcomeSubtext && /* @__PURE__ */ jsx("p", { className: "aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-muted-foreground text-lg delay-75 duration-200", children: welcomeSubtext }),
|
|
@@ -65003,6 +64995,50 @@ const ThreadLoadingOverlay = () => {
|
|
|
65003
64995
|
if (!remoteId || timedOut) return null;
|
|
65004
64996
|
return /* @__PURE__ */ jsx(AuiIf, { condition: (s) => s.thread.isEmpty, children: /* @__PURE__ */ jsx("div", { className: "absolute inset-0 z-10 flex items-center justify-center bg-background/80", children: /* @__PURE__ */ jsx("div", { className: "size-5 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent" }) }) });
|
|
65005
64997
|
};
|
|
64998
|
+
const THREAD_VIEWPORT_ATTR = "data-aui-thread-viewport";
|
|
64999
|
+
const useScrollToTop = () => {
|
|
65000
|
+
const [isAtTop, setIsAtTop] = useState(true);
|
|
65001
|
+
const [buttonEl, setButtonEl] = useState(null);
|
|
65002
|
+
const containerRef = useCallback((node) => {
|
|
65003
|
+
setButtonEl(node);
|
|
65004
|
+
}, []);
|
|
65005
|
+
const getViewport = useCallback(() => {
|
|
65006
|
+
if (!buttonEl) return null;
|
|
65007
|
+
return buttonEl.closest(`[${THREAD_VIEWPORT_ATTR}]`);
|
|
65008
|
+
}, [buttonEl]);
|
|
65009
|
+
useEffect(() => {
|
|
65010
|
+
const viewport = getViewport();
|
|
65011
|
+
if (!viewport) return;
|
|
65012
|
+
const handleScroll2 = () => {
|
|
65013
|
+
setIsAtTop(viewport.scrollTop <= 50);
|
|
65014
|
+
};
|
|
65015
|
+
handleScroll2();
|
|
65016
|
+
viewport.addEventListener("scroll", handleScroll2, { passive: true });
|
|
65017
|
+
return () => viewport.removeEventListener("scroll", handleScroll2);
|
|
65018
|
+
}, [getViewport]);
|
|
65019
|
+
const handleClick2 = useCallback(() => {
|
|
65020
|
+
const viewport = getViewport();
|
|
65021
|
+
if (!viewport) return;
|
|
65022
|
+
viewport.scrollTo({ top: 0, behavior: "smooth" });
|
|
65023
|
+
}, [getViewport]);
|
|
65024
|
+
return { isAtTop, containerRef, handleClick: handleClick2 };
|
|
65025
|
+
};
|
|
65026
|
+
const ThreadScrollToTop = () => {
|
|
65027
|
+
const { isAtTop, containerRef, handleClick: handleClick2 } = useScrollToTop();
|
|
65028
|
+
const isEmpty3 = useAuiState((s) => s.thread.isEmpty);
|
|
65029
|
+
if (isEmpty3) return null;
|
|
65030
|
+
return /* @__PURE__ */ jsx("div", { className: "sticky top-0 z-10 mx-auto flex h-0 w-full max-w-(--thread-max-width) justify-center", children: /* @__PURE__ */ jsx(
|
|
65031
|
+
TooltipIconButton,
|
|
65032
|
+
{
|
|
65033
|
+
ref: containerRef,
|
|
65034
|
+
tooltip: "Scroll to top",
|
|
65035
|
+
variant: "outline",
|
|
65036
|
+
className: cn("aui-thread-scroll-to-top absolute top-2 rounded-full p-4 dark:bg-background dark:hover:bg-accent", isAtTop && "invisible"),
|
|
65037
|
+
onClick: handleClick2,
|
|
65038
|
+
children: /* @__PURE__ */ jsx(ArrowUp, {})
|
|
65039
|
+
}
|
|
65040
|
+
) });
|
|
65041
|
+
};
|
|
65006
65042
|
const ThreadScrollToBottom = () => /* @__PURE__ */ jsx(ThreadPrimitiveScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
65007
65043
|
TooltipIconButton,
|
|
65008
65044
|
{
|
|
@@ -65271,67 +65307,14 @@ const AthenaUserMessage = ({
|
|
|
65271
65307
|
children: /* @__PURE__ */ jsx("div", { className: "aui-user-message-content wrap-break-word rounded-2xl bg-muted px-4 py-2.5 text-foreground", children: /* @__PURE__ */ jsx(MessagePrimitiveParts, { components: { Text: TextComponent } }) })
|
|
65272
65308
|
}
|
|
65273
65309
|
);
|
|
65274
|
-
const EMBED_ASSET_TYPE_ALIASES = {
|
|
65275
|
-
document: "document",
|
|
65276
|
-
image: "document",
|
|
65277
|
-
notebook: "notebook",
|
|
65278
|
-
pdf: "document",
|
|
65279
|
-
powerpoint_deck: "presentation",
|
|
65280
|
-
presentation: "presentation",
|
|
65281
|
-
puck_presentation: "presentation",
|
|
65282
|
-
sheet: "spreadsheet",
|
|
65283
|
-
spreadsheet: "spreadsheet",
|
|
65284
|
-
super_document: "document"
|
|
65285
|
-
};
|
|
65286
65310
|
const embedCache = /* @__PURE__ */ new Map();
|
|
65287
|
-
const normalizeAssetType = (value) => {
|
|
65288
|
-
if (!value) {
|
|
65289
|
-
return null;
|
|
65290
|
-
}
|
|
65291
|
-
const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
|
|
65292
|
-
return EMBED_ASSET_TYPE_ALIASES[normalizedValue] ?? null;
|
|
65293
|
-
};
|
|
65294
|
-
const getEmbedSearchParamsCacheKey = (embedSearchParams) => {
|
|
65295
|
-
if (!embedSearchParams || Object.keys(embedSearchParams).length === 0) {
|
|
65296
|
-
return "{}";
|
|
65297
|
-
}
|
|
65298
|
-
const sortedEntries = Object.entries(embedSearchParams).sort(
|
|
65299
|
-
([left], [right]) => left.localeCompare(right)
|
|
65300
|
-
);
|
|
65301
|
-
return JSON.stringify(Object.fromEntries(sortedEntries));
|
|
65302
|
-
};
|
|
65303
|
-
const appendEmbedSearchParams = ({
|
|
65304
|
-
embedUrl,
|
|
65305
|
-
embedSearchParams
|
|
65306
|
-
}) => {
|
|
65307
|
-
if (!embedSearchParams || Object.keys(embedSearchParams).length === 0) {
|
|
65308
|
-
return embedUrl;
|
|
65309
|
-
}
|
|
65310
|
-
const url = new URL(embedUrl);
|
|
65311
|
-
for (const [key, value] of Object.entries(embedSearchParams)) {
|
|
65312
|
-
if (!value) {
|
|
65313
|
-
continue;
|
|
65314
|
-
}
|
|
65315
|
-
url.searchParams.set(key, value);
|
|
65316
|
-
}
|
|
65317
|
-
return url.toString();
|
|
65318
|
-
};
|
|
65319
65311
|
function useAssetEmbed(assetId, options = {
|
|
65320
65312
|
backendUrl: ""
|
|
65321
65313
|
}) {
|
|
65322
|
-
const {
|
|
65323
|
-
readOnly = false,
|
|
65324
|
-
expiresInSeconds = 60 * 60 * 24 * 30,
|
|
65325
|
-
backendUrl,
|
|
65326
|
-
apiKey,
|
|
65327
|
-
token,
|
|
65328
|
-
embedSearchParams
|
|
65329
|
-
} = options;
|
|
65314
|
+
const { readOnly = false, expiresInSeconds = 60 * 60 * 24 * 30, backendUrl, apiKey, token } = options;
|
|
65330
65315
|
const [embedUrl, setEmbedUrl] = useState(null);
|
|
65331
65316
|
const [isLoading, setIsLoading] = useState(false);
|
|
65332
65317
|
const [error2, setError] = useState(null);
|
|
65333
|
-
const [assetTitle, setAssetTitle] = useState(null);
|
|
65334
|
-
const [assetType, setAssetType] = useState(null);
|
|
65335
65318
|
const abortRef = useRef(null);
|
|
65336
65319
|
useEffect(() => {
|
|
65337
65320
|
var _a2;
|
|
@@ -65339,18 +65322,14 @@ function useAssetEmbed(assetId, options = {
|
|
|
65339
65322
|
setEmbedUrl(null);
|
|
65340
65323
|
setIsLoading(false);
|
|
65341
65324
|
setError(null);
|
|
65342
|
-
setAssetTitle(null);
|
|
65343
|
-
setAssetType(null);
|
|
65344
65325
|
return;
|
|
65345
65326
|
}
|
|
65346
|
-
const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}
|
|
65327
|
+
const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
|
|
65347
65328
|
const cached = embedCache.get(cacheKey);
|
|
65348
65329
|
if (cached && cached.expiresAt > Date.now() / 1e3) {
|
|
65349
65330
|
setEmbedUrl(cached.url);
|
|
65350
65331
|
setIsLoading(false);
|
|
65351
65332
|
setError(null);
|
|
65352
|
-
setAssetTitle(cached.assetTitle);
|
|
65353
|
-
setAssetType(cached.assetType);
|
|
65354
65333
|
return;
|
|
65355
65334
|
}
|
|
65356
65335
|
const apiBaseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
|
|
@@ -65358,14 +65337,11 @@ function useAssetEmbed(assetId, options = {
|
|
|
65358
65337
|
(_a2 = abortRef.current) == null ? void 0 : _a2.abort();
|
|
65359
65338
|
const controller = new AbortController();
|
|
65360
65339
|
abortRef.current = controller;
|
|
65361
|
-
setEmbedUrl(null);
|
|
65362
65340
|
setIsLoading(true);
|
|
65363
65341
|
setError(null);
|
|
65364
|
-
setAssetTitle(null);
|
|
65365
|
-
setAssetType(null);
|
|
65366
65342
|
const headers = { "Content-Type": "application/json" };
|
|
65367
65343
|
if (token) {
|
|
65368
|
-
headers
|
|
65344
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
65369
65345
|
} else if (apiKey) {
|
|
65370
65346
|
headers["X-API-KEY"] = apiKey;
|
|
65371
65347
|
}
|
|
@@ -65385,31 +65361,17 @@ function useAssetEmbed(assetId, options = {
|
|
|
65385
65361
|
}
|
|
65386
65362
|
return res.json();
|
|
65387
65363
|
}).then((data) => {
|
|
65388
|
-
|
|
65389
|
-
|
|
65390
|
-
embedUrl: data.embed_url,
|
|
65391
|
-
embedSearchParams
|
|
65392
|
-
});
|
|
65393
|
-
embedCache.set(cacheKey, {
|
|
65394
|
-
url: resolvedEmbedUrl,
|
|
65395
|
-
expiresAt: data.expires_at,
|
|
65396
|
-
assetTitle: data.title ?? null,
|
|
65397
|
-
assetType: resolvedAssetType
|
|
65398
|
-
});
|
|
65399
|
-
setEmbedUrl(resolvedEmbedUrl);
|
|
65400
|
-
setAssetTitle(data.title ?? null);
|
|
65401
|
-
setAssetType(resolvedAssetType);
|
|
65364
|
+
embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
|
|
65365
|
+
setEmbedUrl(data.embed_url);
|
|
65402
65366
|
setIsLoading(false);
|
|
65403
65367
|
}).catch((err) => {
|
|
65404
|
-
if (err.name === "AbortError")
|
|
65405
|
-
return;
|
|
65406
|
-
}
|
|
65368
|
+
if (err.name === "AbortError") return;
|
|
65407
65369
|
setError(err.message);
|
|
65408
65370
|
setIsLoading(false);
|
|
65409
65371
|
});
|
|
65410
65372
|
return () => controller.abort();
|
|
65411
|
-
}, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token
|
|
65412
|
-
return { embedUrl, isLoading, error: error2
|
|
65373
|
+
}, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
|
|
65374
|
+
return { embedUrl, isLoading, error: error2 };
|
|
65413
65375
|
}
|
|
65414
65376
|
const ASSET_TYPE_CONFIG = {
|
|
65415
65377
|
presentation: { icon: Presentation, label: "Presentation" },
|
|
@@ -65419,28 +65381,13 @@ const ASSET_TYPE_CONFIG = {
|
|
|
65419
65381
|
unknown: { icon: File$1, label: "Asset" }
|
|
65420
65382
|
};
|
|
65421
65383
|
const AssetIframe = memo(
|
|
65422
|
-
({ tabId, tabName
|
|
65384
|
+
({ tabId, tabName }) => {
|
|
65423
65385
|
const { backendUrl, apiKey, token } = useAthenaConfig();
|
|
65424
|
-
const { embedUrl, isLoading, error: error2
|
|
65386
|
+
const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tabId, {
|
|
65425
65387
|
backendUrl,
|
|
65426
65388
|
apiKey,
|
|
65427
|
-
token
|
|
65428
|
-
embedSearchParams
|
|
65389
|
+
token
|
|
65429
65390
|
});
|
|
65430
|
-
useEffect(() => {
|
|
65431
|
-
if (!assetTitle && !assetType) {
|
|
65432
|
-
return;
|
|
65433
|
-
}
|
|
65434
|
-
const nextName = assetTitle ?? tabName;
|
|
65435
|
-
const nextType = assetType ?? tabType;
|
|
65436
|
-
if (nextName === tabName && nextType === tabType) {
|
|
65437
|
-
return;
|
|
65438
|
-
}
|
|
65439
|
-
useAssetPanelStore.getState().updateTabMeta(tabId, {
|
|
65440
|
-
name: nextName ?? void 0,
|
|
65441
|
-
type: nextType
|
|
65442
|
-
});
|
|
65443
|
-
}, [assetTitle, assetType, tabId, tabName, tabType]);
|
|
65444
65391
|
if (isLoading) {
|
|
65445
65392
|
return /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
65446
65393
|
/* @__PURE__ */ jsx(LoaderCircle, { className: "mx-auto size-6 animate-spin text-muted-foreground" }),
|
|
@@ -65502,7 +65449,7 @@ const PanelContent = ({
|
|
|
65502
65449
|
return /* @__PURE__ */ jsx(
|
|
65503
65450
|
"div",
|
|
65504
65451
|
{
|
|
65505
|
-
className:
|
|
65452
|
+
className: `flex-1 overflow-hidden ${isTiled ? `${gridClass} gap-px bg-border/60` : ""}`,
|
|
65506
65453
|
children: tabs.map((tab) => {
|
|
65507
65454
|
const isActive2 = tab.id === activeTabId;
|
|
65508
65455
|
const config2 = ASSET_TYPE_CONFIG[tab.type];
|
|
@@ -65525,15 +65472,7 @@ const PanelContent = ({
|
|
|
65525
65472
|
}
|
|
65526
65473
|
)
|
|
65527
65474
|
] }),
|
|
65528
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
65529
|
-
AssetIframe,
|
|
65530
|
-
{
|
|
65531
|
-
tabId: tab.id,
|
|
65532
|
-
tabName: tab.name,
|
|
65533
|
-
tabType: tab.type,
|
|
65534
|
-
embedSearchParams: tab.embedSearchParams
|
|
65535
|
-
}
|
|
65536
|
-
) })
|
|
65475
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(AssetIframe, { tabId: tab.id, tabName: tab.name }) })
|
|
65537
65476
|
]
|
|
65538
65477
|
},
|
|
65539
65478
|
tab.id
|
|
@@ -65543,15 +65482,7 @@ const PanelContent = ({
|
|
|
65543
65482
|
"div",
|
|
65544
65483
|
{
|
|
65545
65484
|
className: isActive2 ? "h-full w-full" : "hidden",
|
|
65546
|
-
children: /* @__PURE__ */ jsx(
|
|
65547
|
-
AssetIframe,
|
|
65548
|
-
{
|
|
65549
|
-
tabId: tab.id,
|
|
65550
|
-
tabName: tab.name,
|
|
65551
|
-
tabType: tab.type,
|
|
65552
|
-
embedSearchParams: tab.embedSearchParams
|
|
65553
|
-
}
|
|
65554
|
-
)
|
|
65485
|
+
children: /* @__PURE__ */ jsx(AssetIframe, { tabId: tab.id, tabName: tab.name })
|
|
65555
65486
|
},
|
|
65556
65487
|
tab.id
|
|
65557
65488
|
);
|
|
@@ -65569,10 +65500,7 @@ const TabBar = () => {
|
|
|
65569
65500
|
return /* @__PURE__ */ jsxs(
|
|
65570
65501
|
"div",
|
|
65571
65502
|
{
|
|
65572
|
-
className:
|
|
65573
|
-
"group flex max-w-[180px] shrink-0 cursor-pointer items-center gap-1.5 border-r border-border/40 px-3 py-1.5 text-xs",
|
|
65574
|
-
isActive2 ? "border-b-2 border-b-primary bg-background text-foreground" : "text-muted-foreground hover:bg-background/50 hover:text-foreground"
|
|
65575
|
-
),
|
|
65503
|
+
className: `group flex max-w-[180px] shrink-0 cursor-pointer items-center gap-1.5 border-r border-border/40 px-3 py-1.5 text-xs ${isActive2 ? "border-b-2 border-b-primary bg-background text-foreground" : "text-muted-foreground hover:bg-background/50 hover:text-foreground"}`,
|
|
65576
65504
|
onClick: () => setActiveTab(tab.id),
|
|
65577
65505
|
children: [
|
|
65578
65506
|
/* @__PURE__ */ jsx(TypeIcon, { className: "size-3 shrink-0" }),
|
|
@@ -65614,10 +65542,7 @@ const PanelHeader = ({ fullscreen }) => {
|
|
|
65614
65542
|
"button",
|
|
65615
65543
|
{
|
|
65616
65544
|
onClick: () => setViewMode(isTiled ? "tabs" : "tiled"),
|
|
65617
|
-
className:
|
|
65618
|
-
"flex size-7 items-center justify-center rounded-lg transition-colors",
|
|
65619
|
-
isTiled ? "bg-primary/10 text-primary" : "text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
65620
|
-
),
|
|
65545
|
+
className: `flex size-7 items-center justify-center rounded-lg transition-colors ${isTiled ? "bg-primary/10 text-primary" : "text-muted-foreground hover:bg-accent hover:text-foreground"}`,
|
|
65621
65546
|
title: isTiled ? "Switch to tabs" : "Tile all assets",
|
|
65622
65547
|
children: isTiled ? /* @__PURE__ */ jsx(Layers, { className: "size-3.5" }) : /* @__PURE__ */ jsx(LayoutGrid, { className: "size-3.5" })
|
|
65623
65548
|
}
|