@athenaintel/react 0.10.37 → 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 CHANGED
@@ -150,6 +150,8 @@ Use `AthenaAssetEmbed` to render a native Athena asset without chat, thread hist
150
150
  import { AthenaAssetEmbed, AthenaProvider } from '@athenaintel/react';
151
151
 
152
152
  function AssetView() {
153
+ const [linkedReference, setLinkedReference] = useState(null);
154
+
153
155
  return (
154
156
  <AthenaProvider config={{ token: accessToken }}>
155
157
  <div style={{ height: 800 }}>
@@ -162,10 +164,18 @@ function AssetView() {
162
164
  }}
163
165
  onCitationAction={({ action, reference }) => {
164
166
  if (action === 'open-in-spaces') {
165
- openAssetInMyApp(reference);
167
+ setLinkedReference(reference);
166
168
  }
167
169
  }}
168
170
  />
171
+ {linkedReference && (
172
+ <AthenaAssetEmbed
173
+ assetId={linkedReference.id}
174
+ reference={linkedReference}
175
+ displayMode="full"
176
+ readOnly
177
+ />
178
+ )}
169
179
  </div>
170
180
  </AthenaProvider>
171
181
  );
@@ -176,6 +186,10 @@ When `onCitationClick` is provided, citation navigation is delegated to the host
176
186
 
177
187
  `onCitationAction` handles actions initiated from a citation popover. It currently receives `action: 'open-in-spaces'` when the user clicks the (+) button. Providing the handler delegates that action to the host by default. Set `citationActionBehavior="browser"` to observe the event while preserving Athena's default navigation; requesting host mode without a handler safely falls back to browser behavior.
178
188
 
189
+ Pass the callback's complete `reference` to the linked `AthenaAssetEmbed`, rather than storing only
190
+ `reference.id`. The embed uses the reference anchor to navigate PDFs to the cited page. Updating the
191
+ reference also navigates when the host opens another citation in the same asset.
192
+
179
193
  ## Theming
180
194
 
181
195
  ```tsx
@@ -1,7 +1,9 @@
1
1
  import { type FC, type IframeHTMLAttributes } from "react";
2
- import { type AthenaAssetCitationActionEvent, type AthenaAssetCitationBehavior, type AthenaAssetCitationClickEvent } from "./asset-embed-messages";
2
+ import { type AthenaAssetCitationActionEvent, type AthenaAssetCitationBehavior, type AthenaAssetCitationClickEvent, type AthenaAssetCitationReference } from "./asset-embed-messages";
3
3
  export interface AthenaAssetEmbedProps extends Omit<IframeHTMLAttributes<HTMLIFrameElement>, "src" | "onError" | "onLoad"> {
4
4
  assetId: string;
5
+ /** Optional citation target to open inside the embedded asset, such as a PDF page. */
6
+ reference?: AthenaAssetCitationReference;
5
7
  /** Defaults to the native full asset experience. */
6
8
  displayMode?: "minimal" | "full";
7
9
  /** Defaults to true. */
@@ -1,3 +1,4 @@
1
+ import type { AthenaAssetCitationReference } from './asset-embed-messages';
1
2
  export interface UseAssetEmbedOptions {
2
3
  readOnly?: boolean;
3
4
  expiresInSeconds?: number;
@@ -26,7 +27,7 @@ export declare function resolveAssetEmbedUrl({ embedUrl, appUrl, backendUrl, cur
26
27
  backendUrl?: string | null;
27
28
  currentOrigin?: string | null;
28
29
  }): string;
29
- export declare function buildSdkAssetEmbedUrl(embedUrl: string): string;
30
+ export declare function buildSdkAssetEmbedUrl(embedUrl: string, reference?: AthenaAssetCitationReference): string;
30
31
  export declare function getAssetEmbedAuthContext({ token, apiKey }: {
31
32
  token?: string | null;
32
33
  apiKey?: string;
package/dist/index.cjs CHANGED
@@ -56390,10 +56390,92 @@ function resolveAssetEmbedUrl({
56390
56390
  return embedUrl;
56391
56391
  }
56392
56392
  }
56393
- function buildSdkAssetEmbedUrl(embedUrl) {
56393
+ function setFiniteNumberParam({ params, key, value }) {
56394
+ if (typeof value === "number" && Number.isFinite(value)) {
56395
+ params.set(key, String(value));
56396
+ }
56397
+ }
56398
+ function appendCitationReferenceParams({
56399
+ params,
56400
+ reference: reference2
56401
+ }) {
56402
+ var _a2;
56403
+ const anchor = reference2 == null ? void 0 : reference2.anchor;
56404
+ if (!anchor || typeof anchor !== "object" || !("type" in anchor) || typeof anchor.type !== "string") {
56405
+ return;
56406
+ }
56407
+ switch (anchor.type) {
56408
+ case "page":
56409
+ params.set("anchor", anchor.type);
56410
+ setFiniteNumberParam({
56411
+ params,
56412
+ key: "page",
56413
+ value: "page" in anchor ? anchor.page : void 0
56414
+ });
56415
+ break;
56416
+ case "page_range":
56417
+ params.set("anchor", anchor.type);
56418
+ setFiniteNumberParam({
56419
+ params,
56420
+ key: "start_page",
56421
+ value: "startPage" in anchor ? anchor.startPage : void 0
56422
+ });
56423
+ setFiniteNumberParam({
56424
+ params,
56425
+ key: "end_page",
56426
+ value: "endPage" in anchor ? anchor.endPage : void 0
56427
+ });
56428
+ break;
56429
+ case "page_rect":
56430
+ params.set("anchor", anchor.type);
56431
+ setFiniteNumberParam({
56432
+ params,
56433
+ key: "page",
56434
+ value: "page" in anchor ? anchor.page : void 0
56435
+ });
56436
+ setFiniteNumberParam({
56437
+ params,
56438
+ key: "x",
56439
+ value: "x" in anchor ? anchor.x : void 0
56440
+ });
56441
+ setFiniteNumberParam({
56442
+ params,
56443
+ key: "y",
56444
+ value: "y" in anchor ? anchor.y : void 0
56445
+ });
56446
+ setFiniteNumberParam({
56447
+ params,
56448
+ key: "width",
56449
+ value: "width" in anchor ? anchor.width : void 0
56450
+ });
56451
+ setFiniteNumberParam({
56452
+ params,
56453
+ key: "height",
56454
+ value: "height" in anchor ? anchor.height : void 0
56455
+ });
56456
+ break;
56457
+ case "page_text":
56458
+ params.set("anchor", anchor.type);
56459
+ setFiniteNumberParam({
56460
+ params,
56461
+ key: "page",
56462
+ value: "page" in anchor ? anchor.page : void 0
56463
+ });
56464
+ if ("text" in anchor && typeof anchor.text === "string") {
56465
+ params.set("text", anchor.text);
56466
+ }
56467
+ break;
56468
+ }
56469
+ const excerpt = (_a2 = reference2.meta) == null ? void 0 : _a2.excerpt;
56470
+ if (typeof excerpt === "string" && excerpt) {
56471
+ params.set("excerpt", excerpt);
56472
+ }
56473
+ }
56474
+ function buildSdkAssetEmbedUrl(embedUrl, reference2) {
56394
56475
  try {
56395
56476
  const url = new URL(embedUrl);
56396
56477
  url.searchParams.set("athena_sdk_bridge", "1");
56478
+ appendCitationReferenceParams({ params: url.searchParams, reference: reference2 });
56397
56479
  return url.toString();
56398
56480
  } catch {
56399
56481
  return embedUrl;
@@ -56523,6 +56605,7 @@ const DEFAULT_STYLE = {
56523
56605
  const AUTH_SYNC_INTERVAL_MS = 6e4;
56524
56606
  const AthenaAssetEmbed = ({
56525
56607
  assetId,
56608
+ reference: reference2,
56526
56609
  displayMode = "full",
56527
56610
  readOnly = true,
56528
56611
  expiresInSeconds,
@@ -56560,7 +56643,10 @@ const AthenaAssetEmbed = ({
56560
56643
  return null;
56561
56644
  }
56562
56645
  }, [embedUrl]);
56563
- const iframeSrc = React.useMemo(() => embedUrl ? buildSdkAssetEmbedUrl(embedUrl) : null, [embedUrl]);
56646
+ const iframeSrc = React.useMemo(
56647
+ () => embedUrl ? buildSdkAssetEmbedUrl(embedUrl, reference2) : null,
56648
+ [embedUrl, reference2]
56649
+ );
56564
56650
  const effectiveCitationBehavior = resolveAthenaAssetCitationBehavior({
56565
56651
  citationBehavior,
56566
56652
  hasCitationClickHandler: !!onCitationClick