@athenaintel/react 0.9.15 → 0.9.16

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/dist/index.d.ts CHANGED
@@ -51,6 +51,7 @@ export declare interface AssetPanelState {
51
51
  openAsset: (assetId: string, meta?: {
52
52
  name?: string;
53
53
  type?: AssetType;
54
+ embedSearchParams?: Record<string, string> | null;
54
55
  }) => void;
55
56
  closeTab: (assetId: string) => void;
56
57
  setActiveTab: (assetId: string) => void;
@@ -67,6 +68,7 @@ export declare interface AssetTab {
67
68
  id: string;
68
69
  name: string | null;
69
70
  type: AssetType;
71
+ embedSearchParams: Record<string, string> | null;
70
72
  }
71
73
 
72
74
  export declare type AssetType = 'presentation' | 'spreadsheet' | 'document' | 'notebook' | 'unknown';
@@ -146,6 +148,8 @@ export declare interface AthenaCitationLinkMetadata {
146
148
  assetId: string;
147
149
  assetIds: string[];
148
150
  assetType: AssetType | null;
151
+ assetName: string | null;
152
+ embedSearchParams: Record<string, string>;
149
153
  }
150
154
 
151
155
  /**
@@ -586,6 +590,8 @@ export declare interface ParsedAthenaCitationLink {
586
590
  assetId: string;
587
591
  assetIds: string[];
588
592
  assetType: AssetType | null;
593
+ assetName: string | null;
594
+ embedSearchParams: Record<string, string>;
589
595
  }
590
596
 
591
597
  declare interface QuoteContextValue {
@@ -1018,12 +1024,15 @@ export declare function useAssetEmbed(assetId: string | null, options?: UseAsset
1018
1024
  export declare interface UseAssetEmbedOptions {
1019
1025
  readOnly?: boolean;
1020
1026
  expiresInSeconds?: number;
1027
+ embedSearchParams?: Record<string, string> | null;
1021
1028
  }
1022
1029
 
1023
1030
  export declare interface UseAssetEmbedResult {
1024
1031
  embedUrl: string | null;
1025
1032
  isLoading: boolean;
1026
1033
  error: string | null;
1034
+ assetTitle: string | null;
1035
+ assetType: AssetType | null;
1027
1036
  }
1028
1037
 
1029
1038
  export declare const useAssetPanelStore: UseBoundStore<Omit<StoreApi<AssetPanelState>, "setState" | "persist"> & {
package/dist/index.js CHANGED
@@ -58857,14 +58857,20 @@ const useAssetPanelStore = create()(
58857
58857
  const existing = s.tabs.find((t) => t.id === assetId);
58858
58858
  if (existing) {
58859
58859
  const tabs = meta ? s.tabs.map(
58860
- (t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
58860
+ (t) => t.id === assetId ? {
58861
+ ...t,
58862
+ name: meta.name ?? t.name,
58863
+ type: meta.type ?? t.type,
58864
+ embedSearchParams: meta.embedSearchParams ?? t.embedSearchParams
58865
+ } : t
58861
58866
  ) : s.tabs;
58862
58867
  return { isOpen: true, tabs, activeTabId: assetId };
58863
58868
  }
58864
58869
  const newTab = {
58865
58870
  id: assetId,
58866
58871
  name: (meta == null ? void 0 : meta.name) ?? null,
58867
- type: (meta == null ? void 0 : meta.type) ?? "unknown"
58872
+ type: (meta == null ? void 0 : meta.type) ?? "unknown",
58873
+ embedSearchParams: (meta == null ? void 0 : meta.embedSearchParams) ?? null
58868
58874
  };
58869
58875
  return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
58870
58876
  }),
@@ -58925,13 +58931,43 @@ const ASSET_TYPE_ALIASES = {
58925
58931
  super_document: "document"
58926
58932
  };
58927
58933
  const isAthenaSpacesPath = (url) => url.pathname.replace(/\/+$/, "") === "/dashboard/spaces";
58928
- const normalizeAssetType = (value) => {
58934
+ const normalizeAssetType$1 = (value) => {
58929
58935
  if (!value) {
58930
58936
  return null;
58931
58937
  }
58932
58938
  const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
58933
58939
  return ASSET_TYPE_ALIASES[normalizedValue] ?? null;
58934
58940
  };
58941
+ const isLikelyAssetId = (value) => !!value && /^(asset|thread|project|collection)_[a-z0-9-]+$/i.test(value.trim());
58942
+ const sanitizeDisplayName = (value) => {
58943
+ if (!value) {
58944
+ return null;
58945
+ }
58946
+ const trimmedValue = value.trim();
58947
+ if (!trimmedValue) {
58948
+ return null;
58949
+ }
58950
+ if (trimmedValue.startsWith('"') && trimmedValue.endsWith('"') || trimmedValue.startsWith("'") && trimmedValue.endsWith("'")) {
58951
+ return trimmedValue.slice(1, -1).trim() || null;
58952
+ }
58953
+ return trimmedValue;
58954
+ };
58955
+ const getCitationDisplayName = ({
58956
+ assetName,
58957
+ linkText
58958
+ }) => {
58959
+ const sanitizedAssetName = sanitizeDisplayName(assetName);
58960
+ const sanitizedLinkText = sanitizeDisplayName(linkText);
58961
+ const genericLinkTextPattern = /^(this|that|the)\s+asset$/i;
58962
+ if (sanitizedAssetName && !isLikelyAssetId(sanitizedAssetName)) {
58963
+ return sanitizedAssetName;
58964
+ }
58965
+ if (sanitizedLinkText && !genericLinkTextPattern.test(sanitizedLinkText)) {
58966
+ return sanitizedLinkText;
58967
+ }
58968
+ return sanitizedAssetName ?? sanitizedLinkText;
58969
+ };
58970
+ const getEmbedSearchParams = (url) => Object.fromEntries(url.searchParams.entries());
58935
58971
  const getOrigin = (value) => {
58936
58972
  if (!value) {
58937
58973
  return null;
@@ -59013,7 +59049,11 @@ const parseAthenaCitationLink = ({
59013
59049
  url,
59014
59050
  assetId,
59015
59051
  assetIds,
59016
- assetType: normalizeAssetType(url.searchParams.get("asset_type") ?? url.searchParams.get("type"))
59052
+ assetType: normalizeAssetType$1(
59053
+ url.searchParams.get("asset_type") ?? url.searchParams.get("assetType") ?? url.searchParams.get("type")
59054
+ ),
59055
+ assetName: sanitizeDisplayName(url.searchParams.get("name")),
59056
+ embedSearchParams: getEmbedSearchParams(url)
59017
59057
  };
59018
59058
  };
59019
59059
  const isAthenaCitationUrl = ({
@@ -59061,12 +59101,19 @@ const useAthenaLinkClickHandler = () => {
59061
59101
  const citationMetadata = citationLink ? {
59062
59102
  assetId: citationLink.assetId,
59063
59103
  assetIds: citationLink.assetIds,
59064
- assetType: citationLink.assetType
59104
+ assetType: citationLink.assetType,
59105
+ assetName: citationLink.assetName,
59106
+ embedSearchParams: citationLink.embedSearchParams
59065
59107
  } : null;
59066
59108
  const openInAssetPanel = citationLink ? () => {
59109
+ const displayName = getCitationDisplayName({
59110
+ assetName: citationLink.assetName,
59111
+ linkText: trimmedLinkText
59112
+ });
59067
59113
  openAsset(citationLink.assetId, {
59068
- name: trimmedLinkText ?? void 0,
59069
- type: citationLink.assetType ?? void 0
59114
+ name: displayName ?? void 0,
59115
+ type: citationLink.assetType ?? void 0,
59116
+ embedSearchParams: citationLink.embedSearchParams
59070
59117
  });
59071
59118
  } : void 0;
59072
59119
  const context2 = {
@@ -63506,6 +63553,12 @@ function extractAssetId(result) {
63506
63553
  if (typeof id === "string" && id.startsWith("asset_")) return id;
63507
63554
  return null;
63508
63555
  }
63556
+ function extractAssetTitle(result) {
63557
+ const data = normalizeResult(result);
63558
+ if (!data) return null;
63559
+ const title = data.assetTitle ?? data.asset_title ?? data.title ?? data.name;
63560
+ return typeof title === "string" && title.trim().length > 0 ? title.trim() : null;
63561
+ }
63509
63562
  function resetAssetAutoOpen() {
63510
63563
  useAssetPanelStore.getState().resetAutoOpen();
63511
63564
  }
@@ -64225,6 +64278,7 @@ const OpenAssetToolUIImpl = ({
64225
64278
  const typedArgs = args;
64226
64279
  const argsAssetId = (typedArgs == null ? void 0 : typedArgs.asset_id) ?? (typedArgs == null ? void 0 : typedArgs.assetId) ?? "";
64227
64280
  const resultAssetId = extractAssetId(result);
64281
+ const resultAssetTitle = extractAssetTitle(result);
64228
64282
  const assetId = resultAssetId ?? (argsAssetId.startsWith("asset_") ? argsAssetId : null);
64229
64283
  const isRunning = (status == null ? void 0 : status.type) === "running";
64230
64284
  const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
@@ -64236,10 +64290,10 @@ const OpenAssetToolUIImpl = ({
64236
64290
  if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
64237
64291
  const store = useAssetPanelStore.getState();
64238
64292
  if (store.markAutoOpened(assetId)) {
64239
- store.openAsset(assetId);
64293
+ store.openAsset(assetId, { name: resultAssetTitle ?? void 0 });
64240
64294
  }
64241
64295
  }
64242
- }, [isComplete, isCancelled, assetId]);
64296
+ }, [isComplete, isCancelled, assetId, resultAssetTitle]);
64243
64297
  return /* @__PURE__ */ jsx(
64244
64298
  ToolCard,
64245
64299
  {
@@ -64255,7 +64309,7 @@ const OpenAssetToolUIImpl = ({
64255
64309
  "button",
64256
64310
  {
64257
64311
  type: "button",
64258
- onClick: () => openAsset(assetId),
64312
+ onClick: () => openAsset(assetId, { name: resultAssetTitle ?? void 0 }),
64259
64313
  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",
64260
64314
  children: [
64261
64315
  /* @__PURE__ */ jsx(ExternalLink, { className: "size-3" }),
@@ -65180,14 +65234,58 @@ const AthenaUserMessage = ({
65180
65234
  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 } }) })
65181
65235
  }
65182
65236
  );
65237
+ const EMBED_ASSET_TYPE_ALIASES = {
65238
+ document: "document",
65239
+ image: "document",
65240
+ notebook: "notebook",
65241
+ pdf: "document",
65242
+ powerpoint_deck: "presentation",
65243
+ presentation: "presentation",
65244
+ puck_presentation: "presentation",
65245
+ sheet: "spreadsheet",
65246
+ spreadsheet: "spreadsheet",
65247
+ super_document: "document"
65248
+ };
65183
65249
  const embedCache = /* @__PURE__ */ new Map();
65250
+ const normalizeAssetType = (value) => {
65251
+ if (!value) {
65252
+ return null;
65253
+ }
65254
+ const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
65255
+ return EMBED_ASSET_TYPE_ALIASES[normalizedValue] ?? null;
65256
+ };
65257
+ const appendEmbedSearchParams = ({
65258
+ embedUrl,
65259
+ embedSearchParams
65260
+ }) => {
65261
+ if (!embedSearchParams || Object.keys(embedSearchParams).length === 0) {
65262
+ return embedUrl;
65263
+ }
65264
+ const url = new URL(embedUrl);
65265
+ for (const [key, value] of Object.entries(embedSearchParams)) {
65266
+ if (!value) {
65267
+ continue;
65268
+ }
65269
+ url.searchParams.set(key, value);
65270
+ }
65271
+ return url.toString();
65272
+ };
65184
65273
  function useAssetEmbed(assetId, options = {
65185
65274
  backendUrl: ""
65186
65275
  }) {
65187
- const { readOnly = false, expiresInSeconds = 60 * 60 * 24 * 30, backendUrl, apiKey, token } = options;
65276
+ const {
65277
+ readOnly = false,
65278
+ expiresInSeconds = 60 * 60 * 24 * 30,
65279
+ backendUrl,
65280
+ apiKey,
65281
+ token,
65282
+ embedSearchParams
65283
+ } = options;
65188
65284
  const [embedUrl, setEmbedUrl] = useState(null);
65189
65285
  const [isLoading, setIsLoading] = useState(false);
65190
65286
  const [error2, setError] = useState(null);
65287
+ const [assetTitle, setAssetTitle] = useState(null);
65288
+ const [assetType, setAssetType] = useState(null);
65191
65289
  const abortRef = useRef(null);
65192
65290
  useEffect(() => {
65193
65291
  var _a2;
@@ -65195,14 +65293,18 @@ function useAssetEmbed(assetId, options = {
65195
65293
  setEmbedUrl(null);
65196
65294
  setIsLoading(false);
65197
65295
  setError(null);
65296
+ setAssetTitle(null);
65297
+ setAssetType(null);
65198
65298
  return;
65199
65299
  }
65200
- const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
65300
+ const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}:${JSON.stringify(embedSearchParams ?? {})}`;
65201
65301
  const cached = embedCache.get(cacheKey);
65202
65302
  if (cached && cached.expiresAt > Date.now() / 1e3) {
65203
65303
  setEmbedUrl(cached.url);
65204
65304
  setIsLoading(false);
65205
65305
  setError(null);
65306
+ setAssetTitle(cached.assetTitle);
65307
+ setAssetType(cached.assetType);
65206
65308
  return;
65207
65309
  }
65208
65310
  const apiBaseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
@@ -65210,11 +65312,14 @@ function useAssetEmbed(assetId, options = {
65210
65312
  (_a2 = abortRef.current) == null ? void 0 : _a2.abort();
65211
65313
  const controller = new AbortController();
65212
65314
  abortRef.current = controller;
65315
+ setEmbedUrl(null);
65213
65316
  setIsLoading(true);
65214
65317
  setError(null);
65318
+ setAssetTitle(null);
65319
+ setAssetType(null);
65215
65320
  const headers = { "Content-Type": "application/json" };
65216
65321
  if (token) {
65217
- headers["Authorization"] = `Bearer ${token}`;
65322
+ headers.Authorization = `Bearer ${token}`;
65218
65323
  } else if (apiKey) {
65219
65324
  headers["X-API-KEY"] = apiKey;
65220
65325
  }
@@ -65234,17 +65339,31 @@ function useAssetEmbed(assetId, options = {
65234
65339
  }
65235
65340
  return res.json();
65236
65341
  }).then((data) => {
65237
- embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
65238
- setEmbedUrl(data.embed_url);
65342
+ const resolvedAssetType = normalizeAssetType(data.athena_converted_type) ?? normalizeAssetType(data.athena_original_type);
65343
+ const resolvedEmbedUrl = appendEmbedSearchParams({
65344
+ embedUrl: data.embed_url,
65345
+ embedSearchParams
65346
+ });
65347
+ embedCache.set(cacheKey, {
65348
+ url: resolvedEmbedUrl,
65349
+ expiresAt: data.expires_at,
65350
+ assetTitle: data.title ?? null,
65351
+ assetType: resolvedAssetType
65352
+ });
65353
+ setEmbedUrl(resolvedEmbedUrl);
65354
+ setAssetTitle(data.title ?? null);
65355
+ setAssetType(resolvedAssetType);
65239
65356
  setIsLoading(false);
65240
65357
  }).catch((err) => {
65241
- if (err.name === "AbortError") return;
65358
+ if (err.name === "AbortError") {
65359
+ return;
65360
+ }
65242
65361
  setError(err.message);
65243
65362
  setIsLoading(false);
65244
65363
  });
65245
65364
  return () => controller.abort();
65246
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
65247
- return { embedUrl, isLoading, error: error2 };
65365
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token, embedSearchParams]);
65366
+ return { embedUrl, isLoading, error: error2, assetTitle, assetType };
65248
65367
  }
65249
65368
  const ASSET_TYPE_CONFIG = {
65250
65369
  presentation: { icon: Presentation, label: "Presentation" },
@@ -65254,13 +65373,28 @@ const ASSET_TYPE_CONFIG = {
65254
65373
  unknown: { icon: File$1, label: "Asset" }
65255
65374
  };
65256
65375
  const AssetIframe = memo(
65257
- ({ tabId, tabName }) => {
65376
+ ({ tabId, tabName, tabType, embedSearchParams }) => {
65258
65377
  const { backendUrl, apiKey, token } = useAthenaConfig();
65259
- const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tabId, {
65378
+ const { embedUrl, isLoading, error: error2, assetTitle, assetType } = useAssetEmbed(tabId, {
65260
65379
  backendUrl,
65261
65380
  apiKey,
65262
- token
65381
+ token,
65382
+ embedSearchParams
65263
65383
  });
65384
+ useEffect(() => {
65385
+ if (!assetTitle && !assetType) {
65386
+ return;
65387
+ }
65388
+ const nextName = assetTitle ?? tabName;
65389
+ const nextType = assetType ?? tabType;
65390
+ if (nextName === tabName && nextType === tabType) {
65391
+ return;
65392
+ }
65393
+ useAssetPanelStore.getState().openAsset(tabId, {
65394
+ name: nextName ?? void 0,
65395
+ type: nextType
65396
+ });
65397
+ }, [assetTitle, assetType, tabId, tabName, tabType]);
65264
65398
  if (isLoading) {
65265
65399
  return /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
65266
65400
  /* @__PURE__ */ jsx(LoaderCircle, { className: "mx-auto size-6 animate-spin text-muted-foreground" }),
@@ -65345,7 +65479,15 @@ const PanelContent = ({
65345
65479
  }
65346
65480
  )
65347
65481
  ] }),
65348
- /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(AssetIframe, { tabId: tab.id, tabName: tab.name }) })
65482
+ /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
65483
+ AssetIframe,
65484
+ {
65485
+ tabId: tab.id,
65486
+ tabName: tab.name,
65487
+ tabType: tab.type,
65488
+ embedSearchParams: tab.embedSearchParams
65489
+ }
65490
+ ) })
65349
65491
  ]
65350
65492
  },
65351
65493
  tab.id
@@ -65355,7 +65497,15 @@ const PanelContent = ({
65355
65497
  "div",
65356
65498
  {
65357
65499
  className: isActive2 ? "h-full w-full" : "hidden",
65358
- children: /* @__PURE__ */ jsx(AssetIframe, { tabId: tab.id, tabName: tab.name })
65500
+ children: /* @__PURE__ */ jsx(
65501
+ AssetIframe,
65502
+ {
65503
+ tabId: tab.id,
65504
+ tabName: tab.name,
65505
+ tabType: tab.type,
65506
+ embedSearchParams: tab.embedSearchParams
65507
+ }
65508
+ )
65359
65509
  },
65360
65510
  tab.id
65361
65511
  );