@athenaintel/react 0.10.35 → 0.10.37
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 +8 -1
- package/dist/assets/AthenaAssetEmbed.d.ts +4 -1
- package/dist/assets/asset-embed-messages.d.ts +18 -0
- package/dist/assets/use-asset-embed.d.ts +5 -0
- package/dist/index.cjs +95 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +95 -15
- package/dist/index.js.map +1 -1
- package/dist/styles.css +3 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export { AppendDocumentToolUI } from './tools/append-document-tool-ui';
|
|
|
27
27
|
export { getAssetInfo, tryParseJson } from './tools/asset-utils';
|
|
28
28
|
export { AthenaAssetEmbed } from './assets/AthenaAssetEmbed';
|
|
29
29
|
export type { AthenaAssetEmbedProps } from './assets/AthenaAssetEmbed';
|
|
30
|
-
export type { AthenaAssetCitationBehavior, AthenaAssetCitationClickEvent, AthenaAssetCitationReference, } from './assets/asset-embed-messages';
|
|
30
|
+
export type { AthenaAssetCitationAction, AthenaAssetCitationActionEvent, AthenaAssetCitationBehavior, AthenaAssetCitationClickEvent, AthenaAssetCitationReference, } from './assets/asset-embed-messages';
|
|
31
31
|
export { AssetPanel } from './assets/AssetPanel';
|
|
32
32
|
export type { AssetPanelProps } from './assets/AssetPanel';
|
|
33
33
|
export { AthenaLayout } from './assets/AthenaLayout';
|
package/dist/index.js
CHANGED
|
@@ -56215,12 +56215,30 @@ const AthenaUserMessage = ({
|
|
|
56215
56215
|
const ATHENA_ASSET_EMBED_READY_MESSAGE = "athena:asset-embed-ready";
|
|
56216
56216
|
const ATHENA_ASSET_EMBED_CONFIG_MESSAGE = "athena:asset-embed-config";
|
|
56217
56217
|
const ATHENA_ASSET_CITATION_CLICK_MESSAGE = "athena:asset-citation-click";
|
|
56218
|
+
const ATHENA_ASSET_CITATION_ACTION_MESSAGE = "athena:asset-citation-action";
|
|
56219
|
+
function resolveAthenaAssetCitationBehavior({
|
|
56220
|
+
citationBehavior,
|
|
56221
|
+
hasCitationClickHandler
|
|
56222
|
+
}) {
|
|
56223
|
+
if (citationBehavior === "host" && !hasCitationClickHandler) return "browser";
|
|
56224
|
+
return citationBehavior ?? (hasCitationClickHandler ? "host" : "browser");
|
|
56225
|
+
}
|
|
56226
|
+
function resolveAthenaAssetCitationActionBehavior({
|
|
56227
|
+
citationActionBehavior,
|
|
56228
|
+
hasCitationActionHandler
|
|
56229
|
+
}) {
|
|
56230
|
+
if (citationActionBehavior === "host" && !hasCitationActionHandler) return "browser";
|
|
56231
|
+
return citationActionBehavior ?? (hasCitationActionHandler ? "host" : "browser");
|
|
56232
|
+
}
|
|
56218
56233
|
function isAthenaAssetEmbedReadyEvent(value) {
|
|
56219
56234
|
return typeof value === "object" && value !== null && "type" in value && value.type === ATHENA_ASSET_EMBED_READY_MESSAGE && "version" in value && value.version === 1;
|
|
56220
56235
|
}
|
|
56221
56236
|
function isAthenaAssetCitationClickEvent(value) {
|
|
56222
56237
|
return typeof value === "object" && value !== null && "type" in value && value.type === ATHENA_ASSET_CITATION_CLICK_MESSAGE && "version" in value && value.version === 1 && "reference" in value && typeof value.reference === "object" && value.reference !== null && "id" in value.reference && typeof value.reference.id === "string";
|
|
56223
56238
|
}
|
|
56239
|
+
function isAthenaAssetCitationActionEvent(value) {
|
|
56240
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === ATHENA_ASSET_CITATION_ACTION_MESSAGE && "version" in value && value.version === 1 && "action" in value && value.action === "open-in-spaces" && "reference" in value && typeof value.reference === "object" && value.reference !== null && "id" in value.reference && typeof value.reference.id === "string";
|
|
56241
|
+
}
|
|
56224
56242
|
function buildAssetEmbedRequestBody({
|
|
56225
56243
|
assetId,
|
|
56226
56244
|
readOnly,
|
|
@@ -56317,7 +56335,11 @@ function resolveAssetEmbedUrl({
|
|
|
56317
56335
|
if (!resolvedEmbedUrl.pathname.startsWith("/embed/")) {
|
|
56318
56336
|
return embedUrl;
|
|
56319
56337
|
}
|
|
56320
|
-
const embedAppUrl = resolveEmbedAppUrl({
|
|
56338
|
+
const embedAppUrl = resolveEmbedAppUrl({
|
|
56339
|
+
appUrl,
|
|
56340
|
+
backendUrl,
|
|
56341
|
+
currentOrigin
|
|
56342
|
+
});
|
|
56321
56343
|
if (!embedAppUrl) {
|
|
56322
56344
|
return embedUrl;
|
|
56323
56345
|
}
|
|
@@ -56329,6 +56351,41 @@ function resolveAssetEmbedUrl({
|
|
|
56329
56351
|
return embedUrl;
|
|
56330
56352
|
}
|
|
56331
56353
|
}
|
|
56354
|
+
function buildSdkAssetEmbedUrl(embedUrl) {
|
|
56355
|
+
try {
|
|
56356
|
+
const url = new URL(embedUrl);
|
|
56357
|
+
url.searchParams.set("athena_sdk_bridge", "1");
|
|
56358
|
+
return url.toString();
|
|
56359
|
+
} catch {
|
|
56360
|
+
return embedUrl;
|
|
56361
|
+
}
|
|
56362
|
+
}
|
|
56363
|
+
const getJwtPayload = (token) => {
|
|
56364
|
+
try {
|
|
56365
|
+
const payloadSegment = token.split(".")[1];
|
|
56366
|
+
if (!payloadSegment || typeof atob !== "function") return null;
|
|
56367
|
+
const normalized = payloadSegment.replace(/-/g, "+").replace(/_/g, "/");
|
|
56368
|
+
const payload = JSON.parse(
|
|
56369
|
+
atob(normalized.padEnd(normalized.length + (4 - normalized.length % 4) % 4, "="))
|
|
56370
|
+
);
|
|
56371
|
+
return payload && typeof payload === "object" ? payload : null;
|
|
56372
|
+
} catch {
|
|
56373
|
+
return null;
|
|
56374
|
+
}
|
|
56375
|
+
};
|
|
56376
|
+
function getAssetEmbedAuthContext({ token, apiKey }) {
|
|
56377
|
+
if (!token) return apiKey ? `api-key:${apiKey}` : "anonymous";
|
|
56378
|
+
const payload = getJwtPayload(token);
|
|
56379
|
+
const userId = (payload == null ? void 0 : payload.user_id) ?? (payload == null ? void 0 : payload.sub);
|
|
56380
|
+
if (typeof userId !== "string" || !userId) return `opaque-token:${token}`;
|
|
56381
|
+
return `jwt:${JSON.stringify({
|
|
56382
|
+
issuer: (payload == null ? void 0 : payload.iss) ?? null,
|
|
56383
|
+
userId,
|
|
56384
|
+
activeOrgId: (payload == null ? void 0 : payload.active_org_id) ?? (payload == null ? void 0 : payload.org_id) ?? null,
|
|
56385
|
+
workspaceId: (payload == null ? void 0 : payload.workspace_id) ?? null,
|
|
56386
|
+
orgMemberships: (payload == null ? void 0 : payload.org_id_to_org_member_info) ?? null
|
|
56387
|
+
})}`;
|
|
56388
|
+
}
|
|
56332
56389
|
function useAssetEmbed(assetId, options = {
|
|
56333
56390
|
backendUrl: ""
|
|
56334
56391
|
}) {
|
|
@@ -56347,7 +56404,7 @@ function useAssetEmbed(assetId, options = {
|
|
|
56347
56404
|
const abortRef = useRef(null);
|
|
56348
56405
|
const tokenRef = useRef(token);
|
|
56349
56406
|
tokenRef.current = token;
|
|
56350
|
-
const
|
|
56407
|
+
const authContext = getAssetEmbedAuthContext({ token, apiKey });
|
|
56351
56408
|
useEffect(() => {
|
|
56352
56409
|
var _a2;
|
|
56353
56410
|
if (!assetId || !backendUrl) {
|
|
@@ -56356,7 +56413,6 @@ function useAssetEmbed(assetId, options = {
|
|
|
56356
56413
|
setError(null);
|
|
56357
56414
|
return;
|
|
56358
56415
|
}
|
|
56359
|
-
const authContext = hasToken ? "token" : apiKey ?? "anon";
|
|
56360
56416
|
const cacheKey = `${assetId}:${readOnly}:${displayMode}:${authContext}:${backendUrl}:${appUrl ?? ""}`;
|
|
56361
56417
|
const cached2 = embedCache.get(cacheKey);
|
|
56362
56418
|
if (cached2 && cached2.expiresAt > Date.now() / 1e3) {
|
|
@@ -56372,10 +56428,12 @@ function useAssetEmbed(assetId, options = {
|
|
|
56372
56428
|
abortRef.current = controller;
|
|
56373
56429
|
setIsLoading(true);
|
|
56374
56430
|
setError(null);
|
|
56375
|
-
const headers = {
|
|
56431
|
+
const headers = {
|
|
56432
|
+
"Content-Type": "application/json"
|
|
56433
|
+
};
|
|
56376
56434
|
const currentToken = tokenRef.current;
|
|
56377
56435
|
if (currentToken) {
|
|
56378
|
-
headers
|
|
56436
|
+
headers.Authorization = `Bearer ${currentToken}`;
|
|
56379
56437
|
} else if (apiKey) {
|
|
56380
56438
|
headers["X-API-KEY"] = apiKey;
|
|
56381
56439
|
}
|
|
@@ -56383,7 +56441,12 @@ function useAssetEmbed(assetId, options = {
|
|
|
56383
56441
|
method: "POST",
|
|
56384
56442
|
headers,
|
|
56385
56443
|
body: JSON.stringify(
|
|
56386
|
-
buildAssetEmbedRequestBody({
|
|
56444
|
+
buildAssetEmbedRequestBody({
|
|
56445
|
+
assetId,
|
|
56446
|
+
readOnly,
|
|
56447
|
+
expiresInSeconds,
|
|
56448
|
+
displayMode
|
|
56449
|
+
})
|
|
56387
56450
|
),
|
|
56388
56451
|
signal: controller.signal
|
|
56389
56452
|
}).then(async (res) => {
|
|
@@ -56398,7 +56461,10 @@ function useAssetEmbed(assetId, options = {
|
|
|
56398
56461
|
appUrl,
|
|
56399
56462
|
backendUrl
|
|
56400
56463
|
});
|
|
56401
|
-
embedCache.set(cacheKey, {
|
|
56464
|
+
embedCache.set(cacheKey, {
|
|
56465
|
+
url: resolvedEmbedUrl,
|
|
56466
|
+
expiresAt: data.expires_at
|
|
56467
|
+
});
|
|
56402
56468
|
setEmbedUrl(resolvedEmbedUrl);
|
|
56403
56469
|
setIsLoading(false);
|
|
56404
56470
|
}).catch((err) => {
|
|
@@ -56407,7 +56473,7 @@ function useAssetEmbed(assetId, options = {
|
|
|
56407
56473
|
setIsLoading(false);
|
|
56408
56474
|
});
|
|
56409
56475
|
return () => controller.abort();
|
|
56410
|
-
}, [assetId, readOnly, expiresInSeconds, displayMode, backendUrl, appUrl,
|
|
56476
|
+
}, [assetId, readOnly, expiresInSeconds, displayMode, backendUrl, appUrl, authContext, apiKey]);
|
|
56411
56477
|
return { embedUrl, isLoading, error: error2 };
|
|
56412
56478
|
}
|
|
56413
56479
|
const DEFAULT_STYLE = {
|
|
@@ -56423,6 +56489,8 @@ const AthenaAssetEmbed = ({
|
|
|
56423
56489
|
expiresInSeconds,
|
|
56424
56490
|
citationBehavior,
|
|
56425
56491
|
onCitationClick,
|
|
56492
|
+
citationActionBehavior,
|
|
56493
|
+
onCitationAction,
|
|
56426
56494
|
onLoad,
|
|
56427
56495
|
onError,
|
|
56428
56496
|
loadingFallback,
|
|
@@ -56453,7 +56521,15 @@ const AthenaAssetEmbed = ({
|
|
|
56453
56521
|
return null;
|
|
56454
56522
|
}
|
|
56455
56523
|
}, [embedUrl]);
|
|
56456
|
-
const
|
|
56524
|
+
const iframeSrc = useMemo(() => embedUrl ? buildSdkAssetEmbedUrl(embedUrl) : null, [embedUrl]);
|
|
56525
|
+
const effectiveCitationBehavior = resolveAthenaAssetCitationBehavior({
|
|
56526
|
+
citationBehavior,
|
|
56527
|
+
hasCitationClickHandler: !!onCitationClick
|
|
56528
|
+
});
|
|
56529
|
+
const effectiveCitationActionBehavior = resolveAthenaAssetCitationActionBehavior({
|
|
56530
|
+
citationActionBehavior,
|
|
56531
|
+
hasCitationActionHandler: !!onCitationAction
|
|
56532
|
+
});
|
|
56457
56533
|
const sendConfig = useCallback(() => {
|
|
56458
56534
|
var _a2, _b;
|
|
56459
56535
|
if (!targetOrigin) return;
|
|
@@ -56462,28 +56538,32 @@ const AthenaAssetEmbed = ({
|
|
|
56462
56538
|
type: ATHENA_ASSET_EMBED_CONFIG_MESSAGE,
|
|
56463
56539
|
version: 1,
|
|
56464
56540
|
...athenaConfig.token ? { token: athenaConfig.token } : {},
|
|
56465
|
-
citationBehavior: effectiveCitationBehavior
|
|
56541
|
+
citationBehavior: effectiveCitationBehavior,
|
|
56542
|
+
citationActionBehavior: effectiveCitationActionBehavior
|
|
56466
56543
|
},
|
|
56467
56544
|
targetOrigin
|
|
56468
56545
|
);
|
|
56469
|
-
}, [athenaConfig, effectiveCitationBehavior, targetOrigin]);
|
|
56546
|
+
}, [athenaConfig, effectiveCitationActionBehavior, effectiveCitationBehavior, targetOrigin]);
|
|
56470
56547
|
useEffect(() => {
|
|
56471
56548
|
if (!embedUrl || !targetOrigin) return;
|
|
56472
56549
|
const handleMessage = (event) => {
|
|
56473
56550
|
var _a2;
|
|
56474
|
-
if (event.origin !== targetOrigin || event.source !== ((_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow))
|
|
56475
|
-
return;
|
|
56551
|
+
if (event.origin !== targetOrigin || event.source !== ((_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow)) return;
|
|
56476
56552
|
if (isAthenaAssetEmbedReadyEvent(event.data)) {
|
|
56477
56553
|
sendConfig();
|
|
56478
56554
|
return;
|
|
56479
56555
|
}
|
|
56480
56556
|
if (isAthenaAssetCitationClickEvent(event.data)) {
|
|
56481
56557
|
onCitationClick == null ? void 0 : onCitationClick(event.data);
|
|
56558
|
+
return;
|
|
56559
|
+
}
|
|
56560
|
+
if (isAthenaAssetCitationActionEvent(event.data)) {
|
|
56561
|
+
onCitationAction == null ? void 0 : onCitationAction(event.data);
|
|
56482
56562
|
}
|
|
56483
56563
|
};
|
|
56484
56564
|
window.addEventListener("message", handleMessage);
|
|
56485
56565
|
return () => window.removeEventListener("message", handleMessage);
|
|
56486
|
-
}, [embedUrl, onCitationClick, sendConfig, targetOrigin]);
|
|
56566
|
+
}, [embedUrl, onCitationAction, onCitationClick, sendConfig, targetOrigin]);
|
|
56487
56567
|
useEffect(() => {
|
|
56488
56568
|
if (!embedUrl) return;
|
|
56489
56569
|
sendConfig();
|
|
@@ -56520,7 +56600,7 @@ const AthenaAssetEmbed = ({
|
|
|
56520
56600
|
{
|
|
56521
56601
|
...iframeProps,
|
|
56522
56602
|
ref: iframeRef,
|
|
56523
|
-
src:
|
|
56603
|
+
src: iframeSrc ?? void 0,
|
|
56524
56604
|
title: title ?? `Athena asset ${assetId}`,
|
|
56525
56605
|
allow,
|
|
56526
56606
|
className: cn("block h-full w-full", className),
|