@athenaintel/react 0.10.36 → 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 CHANGED
@@ -160,6 +160,11 @@ function AssetView() {
160
160
  onCitationClick={({ reference, sourceAssetId }) => {
161
161
  console.log('Citation clicked', { reference, sourceAssetId });
162
162
  }}
163
+ onCitationAction={({ action, reference }) => {
164
+ if (action === 'open-in-spaces') {
165
+ openAssetInMyApp(reference);
166
+ }
167
+ }}
163
168
  />
164
169
  </div>
165
170
  </AthenaProvider>
@@ -167,7 +172,9 @@ function AssetView() {
167
172
  }
168
173
  ```
169
174
 
170
- When `onCitationClick` is provided, citation navigation is delegated to the host by default. Set `citationBehavior="browser"` to observe the event while preserving Athena's default new-tab navigation, or `citationBehavior="host"` to delegate navigation without providing a callback.
175
+ When `onCitationClick` is provided, citation navigation is delegated to the host by default. Set `citationBehavior="browser"` to observe the event while preserving Athena's default new-tab navigation. Host mode requires `onCitationClick`; without a handler, the SDK safely falls back to browser navigation.
176
+
177
+ `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.
171
178
 
172
179
  ## Theming
173
180
 
@@ -1,5 +1,5 @@
1
1
  import { type FC, type IframeHTMLAttributes } from "react";
2
- import { type AthenaAssetCitationBehavior, type AthenaAssetCitationClickEvent } from "./asset-embed-messages";
2
+ import { type AthenaAssetCitationActionEvent, type AthenaAssetCitationBehavior, type AthenaAssetCitationClickEvent } from "./asset-embed-messages";
3
3
  export interface AthenaAssetEmbedProps extends Omit<IframeHTMLAttributes<HTMLIFrameElement>, "src" | "onError" | "onLoad"> {
4
4
  assetId: string;
5
5
  /** Defaults to the native full asset experience. */
@@ -9,6 +9,9 @@ export interface AthenaAssetEmbedProps extends Omit<IframeHTMLAttributes<HTMLIFr
9
9
  expiresInSeconds?: number;
10
10
  citationBehavior?: AthenaAssetCitationBehavior;
11
11
  onCitationClick?: (event: AthenaAssetCitationClickEvent) => void;
12
+ /** Controls the citation popover's actions, including the (+) Open in Spaces button. */
13
+ citationActionBehavior?: AthenaAssetCitationBehavior;
14
+ onCitationAction?: (event: AthenaAssetCitationActionEvent) => void;
12
15
  onLoad?: () => void;
13
16
  onError?: (error: Error) => void;
14
17
  loadingFallback?: React.ReactNode;
@@ -1,7 +1,9 @@
1
1
  export declare const ATHENA_ASSET_EMBED_READY_MESSAGE: "athena:asset-embed-ready";
2
2
  export declare const ATHENA_ASSET_EMBED_CONFIG_MESSAGE: "athena:asset-embed-config";
3
3
  export declare const ATHENA_ASSET_CITATION_CLICK_MESSAGE: "athena:asset-citation-click";
4
+ export declare const ATHENA_ASSET_CITATION_ACTION_MESSAGE: "athena:asset-citation-action";
4
5
  export type AthenaAssetCitationBehavior = "browser" | "host";
6
+ export type AthenaAssetCitationAction = "open-in-spaces";
5
7
  export interface AthenaAssetCitationReference {
6
8
  id: string;
7
9
  anchor?: unknown;
@@ -13,6 +15,12 @@ export interface AthenaAssetCitationClickEvent {
13
15
  sourceAssetId?: string;
14
16
  reference: AthenaAssetCitationReference;
15
17
  }
18
+ export interface AthenaAssetCitationActionEvent {
19
+ type: typeof ATHENA_ASSET_CITATION_ACTION_MESSAGE;
20
+ version: 1;
21
+ action: AthenaAssetCitationAction;
22
+ reference: AthenaAssetCitationReference;
23
+ }
16
24
  export interface AthenaAssetEmbedReadyEvent {
17
25
  type: typeof ATHENA_ASSET_EMBED_READY_MESSAGE;
18
26
  version: 1;
@@ -22,10 +30,16 @@ export interface AthenaAssetEmbedConfigEvent {
22
30
  version: 1;
23
31
  token?: string;
24
32
  citationBehavior: AthenaAssetCitationBehavior;
33
+ citationActionBehavior?: AthenaAssetCitationBehavior;
25
34
  }
26
35
  export declare function resolveAthenaAssetCitationBehavior({ citationBehavior, hasCitationClickHandler, }: {
27
36
  citationBehavior?: AthenaAssetCitationBehavior;
28
37
  hasCitationClickHandler: boolean;
29
38
  }): AthenaAssetCitationBehavior;
39
+ export declare function resolveAthenaAssetCitationActionBehavior({ citationActionBehavior, hasCitationActionHandler, }: {
40
+ citationActionBehavior?: AthenaAssetCitationBehavior;
41
+ hasCitationActionHandler: boolean;
42
+ }): AthenaAssetCitationBehavior;
30
43
  export declare function isAthenaAssetEmbedReadyEvent(value: unknown): value is AthenaAssetEmbedReadyEvent;
31
44
  export declare function isAthenaAssetCitationClickEvent(value: unknown): value is AthenaAssetCitationClickEvent;
45
+ export declare function isAthenaAssetCitationActionEvent(value: unknown): value is AthenaAssetCitationActionEvent;
package/dist/index.cjs CHANGED
@@ -56254,6 +56254,7 @@ const AthenaUserMessage = ({
56254
56254
  const ATHENA_ASSET_EMBED_READY_MESSAGE = "athena:asset-embed-ready";
56255
56255
  const ATHENA_ASSET_EMBED_CONFIG_MESSAGE = "athena:asset-embed-config";
56256
56256
  const ATHENA_ASSET_CITATION_CLICK_MESSAGE = "athena:asset-citation-click";
56257
+ const ATHENA_ASSET_CITATION_ACTION_MESSAGE = "athena:asset-citation-action";
56257
56258
  function resolveAthenaAssetCitationBehavior({
56258
56259
  citationBehavior,
56259
56260
  hasCitationClickHandler
@@ -56261,12 +56262,22 @@ function resolveAthenaAssetCitationBehavior({
56261
56262
  if (citationBehavior === "host" && !hasCitationClickHandler) return "browser";
56262
56263
  return citationBehavior ?? (hasCitationClickHandler ? "host" : "browser");
56263
56264
  }
56265
+ function resolveAthenaAssetCitationActionBehavior({
56266
+ citationActionBehavior,
56267
+ hasCitationActionHandler
56268
+ }) {
56269
+ if (citationActionBehavior === "host" && !hasCitationActionHandler) return "browser";
56270
+ return citationActionBehavior ?? (hasCitationActionHandler ? "host" : "browser");
56271
+ }
56264
56272
  function isAthenaAssetEmbedReadyEvent(value) {
56265
56273
  return typeof value === "object" && value !== null && "type" in value && value.type === ATHENA_ASSET_EMBED_READY_MESSAGE && "version" in value && value.version === 1;
56266
56274
  }
56267
56275
  function isAthenaAssetCitationClickEvent(value) {
56268
56276
  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";
56269
56277
  }
56278
+ function isAthenaAssetCitationActionEvent(value) {
56279
+ 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";
56280
+ }
56270
56281
  function buildAssetEmbedRequestBody({
56271
56282
  assetId,
56272
56283
  readOnly,
@@ -56517,6 +56528,8 @@ const AthenaAssetEmbed = ({
56517
56528
  expiresInSeconds,
56518
56529
  citationBehavior,
56519
56530
  onCitationClick,
56531
+ citationActionBehavior,
56532
+ onCitationAction,
56520
56533
  onLoad,
56521
56534
  onError,
56522
56535
  loadingFallback,
@@ -56552,6 +56565,10 @@ const AthenaAssetEmbed = ({
56552
56565
  citationBehavior,
56553
56566
  hasCitationClickHandler: !!onCitationClick
56554
56567
  });
56568
+ const effectiveCitationActionBehavior = resolveAthenaAssetCitationActionBehavior({
56569
+ citationActionBehavior,
56570
+ hasCitationActionHandler: !!onCitationAction
56571
+ });
56555
56572
  const sendConfig = React.useCallback(() => {
56556
56573
  var _a2, _b;
56557
56574
  if (!targetOrigin) return;
@@ -56560,11 +56577,12 @@ const AthenaAssetEmbed = ({
56560
56577
  type: ATHENA_ASSET_EMBED_CONFIG_MESSAGE,
56561
56578
  version: 1,
56562
56579
  ...athenaConfig.token ? { token: athenaConfig.token } : {},
56563
- citationBehavior: effectiveCitationBehavior
56580
+ citationBehavior: effectiveCitationBehavior,
56581
+ citationActionBehavior: effectiveCitationActionBehavior
56564
56582
  },
56565
56583
  targetOrigin
56566
56584
  );
56567
- }, [athenaConfig, effectiveCitationBehavior, targetOrigin]);
56585
+ }, [athenaConfig, effectiveCitationActionBehavior, effectiveCitationBehavior, targetOrigin]);
56568
56586
  React.useEffect(() => {
56569
56587
  if (!embedUrl || !targetOrigin) return;
56570
56588
  const handleMessage = (event) => {
@@ -56576,11 +56594,15 @@ const AthenaAssetEmbed = ({
56576
56594
  }
56577
56595
  if (isAthenaAssetCitationClickEvent(event.data)) {
56578
56596
  onCitationClick == null ? void 0 : onCitationClick(event.data);
56597
+ return;
56598
+ }
56599
+ if (isAthenaAssetCitationActionEvent(event.data)) {
56600
+ onCitationAction == null ? void 0 : onCitationAction(event.data);
56579
56601
  }
56580
56602
  };
56581
56603
  window.addEventListener("message", handleMessage);
56582
56604
  return () => window.removeEventListener("message", handleMessage);
56583
- }, [embedUrl, onCitationClick, sendConfig, targetOrigin]);
56605
+ }, [embedUrl, onCitationAction, onCitationClick, sendConfig, targetOrigin]);
56584
56606
  React.useEffect(() => {
56585
56607
  if (!embedUrl) return;
56586
56608
  sendConfig();