@athenaintel/react 0.10.36 → 0.10.38
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 +22 -1
- package/dist/assets/AthenaAssetEmbed.d.ts +6 -1
- package/dist/assets/asset-embed-messages.d.ts +14 -0
- package/dist/assets/use-asset-embed.d.ts +2 -1
- package/dist/index.cjs +113 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +113 -5
- 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,6 +56215,7 @@ 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";
|
|
56218
56219
|
function resolveAthenaAssetCitationBehavior({
|
|
56219
56220
|
citationBehavior,
|
|
56220
56221
|
hasCitationClickHandler
|
|
@@ -56222,12 +56223,22 @@ function resolveAthenaAssetCitationBehavior({
|
|
|
56222
56223
|
if (citationBehavior === "host" && !hasCitationClickHandler) return "browser";
|
|
56223
56224
|
return citationBehavior ?? (hasCitationClickHandler ? "host" : "browser");
|
|
56224
56225
|
}
|
|
56226
|
+
function resolveAthenaAssetCitationActionBehavior({
|
|
56227
|
+
citationActionBehavior,
|
|
56228
|
+
hasCitationActionHandler
|
|
56229
|
+
}) {
|
|
56230
|
+
if (citationActionBehavior === "host" && !hasCitationActionHandler) return "browser";
|
|
56231
|
+
return citationActionBehavior ?? (hasCitationActionHandler ? "host" : "browser");
|
|
56232
|
+
}
|
|
56225
56233
|
function isAthenaAssetEmbedReadyEvent(value) {
|
|
56226
56234
|
return typeof value === "object" && value !== null && "type" in value && value.type === ATHENA_ASSET_EMBED_READY_MESSAGE && "version" in value && value.version === 1;
|
|
56227
56235
|
}
|
|
56228
56236
|
function isAthenaAssetCitationClickEvent(value) {
|
|
56229
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";
|
|
56230
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
|
+
}
|
|
56231
56242
|
function buildAssetEmbedRequestBody({
|
|
56232
56243
|
assetId,
|
|
56233
56244
|
readOnly,
|
|
@@ -56340,10 +56351,92 @@ function resolveAssetEmbedUrl({
|
|
|
56340
56351
|
return embedUrl;
|
|
56341
56352
|
}
|
|
56342
56353
|
}
|
|
56343
|
-
function
|
|
56354
|
+
function setFiniteNumberParam({ params, key, value }) {
|
|
56355
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
56356
|
+
params.set(key, String(value));
|
|
56357
|
+
}
|
|
56358
|
+
}
|
|
56359
|
+
function appendCitationReferenceParams({
|
|
56360
|
+
params,
|
|
56361
|
+
reference: reference2
|
|
56362
|
+
}) {
|
|
56363
|
+
var _a2;
|
|
56364
|
+
const anchor = reference2 == null ? void 0 : reference2.anchor;
|
|
56365
|
+
if (!anchor || typeof anchor !== "object" || !("type" in anchor) || typeof anchor.type !== "string") {
|
|
56366
|
+
return;
|
|
56367
|
+
}
|
|
56368
|
+
switch (anchor.type) {
|
|
56369
|
+
case "page":
|
|
56370
|
+
params.set("anchor", anchor.type);
|
|
56371
|
+
setFiniteNumberParam({
|
|
56372
|
+
params,
|
|
56373
|
+
key: "page",
|
|
56374
|
+
value: "page" in anchor ? anchor.page : void 0
|
|
56375
|
+
});
|
|
56376
|
+
break;
|
|
56377
|
+
case "page_range":
|
|
56378
|
+
params.set("anchor", anchor.type);
|
|
56379
|
+
setFiniteNumberParam({
|
|
56380
|
+
params,
|
|
56381
|
+
key: "start_page",
|
|
56382
|
+
value: "startPage" in anchor ? anchor.startPage : void 0
|
|
56383
|
+
});
|
|
56384
|
+
setFiniteNumberParam({
|
|
56385
|
+
params,
|
|
56386
|
+
key: "end_page",
|
|
56387
|
+
value: "endPage" in anchor ? anchor.endPage : void 0
|
|
56388
|
+
});
|
|
56389
|
+
break;
|
|
56390
|
+
case "page_rect":
|
|
56391
|
+
params.set("anchor", anchor.type);
|
|
56392
|
+
setFiniteNumberParam({
|
|
56393
|
+
params,
|
|
56394
|
+
key: "page",
|
|
56395
|
+
value: "page" in anchor ? anchor.page : void 0
|
|
56396
|
+
});
|
|
56397
|
+
setFiniteNumberParam({
|
|
56398
|
+
params,
|
|
56399
|
+
key: "x",
|
|
56400
|
+
value: "x" in anchor ? anchor.x : void 0
|
|
56401
|
+
});
|
|
56402
|
+
setFiniteNumberParam({
|
|
56403
|
+
params,
|
|
56404
|
+
key: "y",
|
|
56405
|
+
value: "y" in anchor ? anchor.y : void 0
|
|
56406
|
+
});
|
|
56407
|
+
setFiniteNumberParam({
|
|
56408
|
+
params,
|
|
56409
|
+
key: "width",
|
|
56410
|
+
value: "width" in anchor ? anchor.width : void 0
|
|
56411
|
+
});
|
|
56412
|
+
setFiniteNumberParam({
|
|
56413
|
+
params,
|
|
56414
|
+
key: "height",
|
|
56415
|
+
value: "height" in anchor ? anchor.height : void 0
|
|
56416
|
+
});
|
|
56417
|
+
break;
|
|
56418
|
+
case "page_text":
|
|
56419
|
+
params.set("anchor", anchor.type);
|
|
56420
|
+
setFiniteNumberParam({
|
|
56421
|
+
params,
|
|
56422
|
+
key: "page",
|
|
56423
|
+
value: "page" in anchor ? anchor.page : void 0
|
|
56424
|
+
});
|
|
56425
|
+
if ("text" in anchor && typeof anchor.text === "string") {
|
|
56426
|
+
params.set("text", anchor.text);
|
|
56427
|
+
}
|
|
56428
|
+
break;
|
|
56429
|
+
}
|
|
56430
|
+
const excerpt = (_a2 = reference2.meta) == null ? void 0 : _a2.excerpt;
|
|
56431
|
+
if (typeof excerpt === "string" && excerpt) {
|
|
56432
|
+
params.set("excerpt", excerpt);
|
|
56433
|
+
}
|
|
56434
|
+
}
|
|
56435
|
+
function buildSdkAssetEmbedUrl(embedUrl, reference2) {
|
|
56344
56436
|
try {
|
|
56345
56437
|
const url = new URL(embedUrl);
|
|
56346
56438
|
url.searchParams.set("athena_sdk_bridge", "1");
|
|
56439
|
+
appendCitationReferenceParams({ params: url.searchParams, reference: reference2 });
|
|
56347
56440
|
return url.toString();
|
|
56348
56441
|
} catch {
|
|
56349
56442
|
return embedUrl;
|
|
@@ -56473,11 +56566,14 @@ const DEFAULT_STYLE = {
|
|
|
56473
56566
|
const AUTH_SYNC_INTERVAL_MS = 6e4;
|
|
56474
56567
|
const AthenaAssetEmbed = ({
|
|
56475
56568
|
assetId,
|
|
56569
|
+
reference: reference2,
|
|
56476
56570
|
displayMode = "full",
|
|
56477
56571
|
readOnly = true,
|
|
56478
56572
|
expiresInSeconds,
|
|
56479
56573
|
citationBehavior,
|
|
56480
56574
|
onCitationClick,
|
|
56575
|
+
citationActionBehavior,
|
|
56576
|
+
onCitationAction,
|
|
56481
56577
|
onLoad,
|
|
56482
56578
|
onError,
|
|
56483
56579
|
loadingFallback,
|
|
@@ -56508,11 +56604,18 @@ const AthenaAssetEmbed = ({
|
|
|
56508
56604
|
return null;
|
|
56509
56605
|
}
|
|
56510
56606
|
}, [embedUrl]);
|
|
56511
|
-
const iframeSrc = useMemo(
|
|
56607
|
+
const iframeSrc = useMemo(
|
|
56608
|
+
() => embedUrl ? buildSdkAssetEmbedUrl(embedUrl, reference2) : null,
|
|
56609
|
+
[embedUrl, reference2]
|
|
56610
|
+
);
|
|
56512
56611
|
const effectiveCitationBehavior = resolveAthenaAssetCitationBehavior({
|
|
56513
56612
|
citationBehavior,
|
|
56514
56613
|
hasCitationClickHandler: !!onCitationClick
|
|
56515
56614
|
});
|
|
56615
|
+
const effectiveCitationActionBehavior = resolveAthenaAssetCitationActionBehavior({
|
|
56616
|
+
citationActionBehavior,
|
|
56617
|
+
hasCitationActionHandler: !!onCitationAction
|
|
56618
|
+
});
|
|
56516
56619
|
const sendConfig = useCallback(() => {
|
|
56517
56620
|
var _a2, _b;
|
|
56518
56621
|
if (!targetOrigin) return;
|
|
@@ -56521,11 +56624,12 @@ const AthenaAssetEmbed = ({
|
|
|
56521
56624
|
type: ATHENA_ASSET_EMBED_CONFIG_MESSAGE,
|
|
56522
56625
|
version: 1,
|
|
56523
56626
|
...athenaConfig.token ? { token: athenaConfig.token } : {},
|
|
56524
|
-
citationBehavior: effectiveCitationBehavior
|
|
56627
|
+
citationBehavior: effectiveCitationBehavior,
|
|
56628
|
+
citationActionBehavior: effectiveCitationActionBehavior
|
|
56525
56629
|
},
|
|
56526
56630
|
targetOrigin
|
|
56527
56631
|
);
|
|
56528
|
-
}, [athenaConfig, effectiveCitationBehavior, targetOrigin]);
|
|
56632
|
+
}, [athenaConfig, effectiveCitationActionBehavior, effectiveCitationBehavior, targetOrigin]);
|
|
56529
56633
|
useEffect(() => {
|
|
56530
56634
|
if (!embedUrl || !targetOrigin) return;
|
|
56531
56635
|
const handleMessage = (event) => {
|
|
@@ -56537,11 +56641,15 @@ const AthenaAssetEmbed = ({
|
|
|
56537
56641
|
}
|
|
56538
56642
|
if (isAthenaAssetCitationClickEvent(event.data)) {
|
|
56539
56643
|
onCitationClick == null ? void 0 : onCitationClick(event.data);
|
|
56644
|
+
return;
|
|
56645
|
+
}
|
|
56646
|
+
if (isAthenaAssetCitationActionEvent(event.data)) {
|
|
56647
|
+
onCitationAction == null ? void 0 : onCitationAction(event.data);
|
|
56540
56648
|
}
|
|
56541
56649
|
};
|
|
56542
56650
|
window.addEventListener("message", handleMessage);
|
|
56543
56651
|
return () => window.removeEventListener("message", handleMessage);
|
|
56544
|
-
}, [embedUrl, onCitationClick, sendConfig, targetOrigin]);
|
|
56652
|
+
}, [embedUrl, onCitationAction, onCitationClick, sendConfig, targetOrigin]);
|
|
56545
56653
|
useEffect(() => {
|
|
56546
56654
|
if (!embedUrl) return;
|
|
56547
56655
|
sendConfig();
|