@athenaintel/react 0.9.14 → 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.js CHANGED
@@ -16483,7 +16483,7 @@ const createUrlWithFallback = (url, fallbackUrl) => {
16483
16483
  return new URL(`${normalizeBaseUrl(fallbackUrl)}/`);
16484
16484
  }
16485
16485
  };
16486
- const getHostname = (value) => {
16486
+ const getHostname$1 = (value) => {
16487
16487
  if (!value) return null;
16488
16488
  try {
16489
16489
  return new URL(value).hostname;
@@ -16524,7 +16524,7 @@ function deriveAthenaAppUrl({
16524
16524
  sourcePort: "8000"
16525
16525
  });
16526
16526
  if (workspaceAppUrl) return workspaceAppUrl;
16527
- const backendHostname = getHostname(backendUrl);
16527
+ const backendHostname = getHostname$1(backendUrl);
16528
16528
  if (backendHostname === "api.athenaintel.com") {
16529
16529
  return ATHENA_ENVIRONMENT_URLS.production.appUrl;
16530
16530
  }
@@ -16538,7 +16538,7 @@ function deriveAthenaAppUrl({
16538
16538
  sourcePort: "8787"
16539
16539
  });
16540
16540
  if (workspaceAppUrl) return workspaceAppUrl;
16541
- const apiHostname = getHostname(apiUrl);
16541
+ const apiHostname = getHostname$1(apiUrl);
16542
16542
  if (apiHostname === "sync.athenaintel.com") {
16543
16543
  return ATHENA_ENVIRONMENT_URLS.production.appUrl;
16544
16544
  }
@@ -58643,57 +58643,282 @@ const MentionExtension = Node3.create({
58643
58643
  };
58644
58644
  }
58645
58645
  });
58646
- const useAssetPanelStore = create((set2, get2) => ({
58647
- isOpen: false,
58648
- tabs: [],
58649
- activeTabId: null,
58650
- viewMode: "tabs",
58651
- isFullscreen: false,
58652
- assetPanelHostCount: 0,
58653
- autoOpenGeneration: 0,
58654
- autoOpenedAssets: /* @__PURE__ */ new Map(),
58655
- registerAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: state.assetPanelHostCount + 1 })),
58656
- unregisterAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: Math.max(0, state.assetPanelHostCount - 1) })),
58657
- openAsset: (assetId, meta) => set2((s) => {
58658
- const existing = s.tabs.find((t) => t.id === assetId);
58659
- if (existing) {
58660
- const tabs = meta ? s.tabs.map(
58661
- (t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
58662
- ) : s.tabs;
58663
- return { isOpen: true, tabs, activeTabId: assetId };
58646
+ function createJSONStorage(getStorage, options) {
58647
+ let storage;
58648
+ try {
58649
+ storage = getStorage();
58650
+ } catch (e) {
58651
+ return;
58652
+ }
58653
+ const persistStorage = {
58654
+ getItem: (name) => {
58655
+ var _a2;
58656
+ const parse2 = (str2) => {
58657
+ if (str2 === null) {
58658
+ return null;
58659
+ }
58660
+ return JSON.parse(str2, void 0);
58661
+ };
58662
+ const str = (_a2 = storage.getItem(name)) != null ? _a2 : null;
58663
+ if (str instanceof Promise) {
58664
+ return str.then(parse2);
58665
+ }
58666
+ return parse2(str);
58667
+ },
58668
+ setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, void 0)),
58669
+ removeItem: (name) => storage.removeItem(name)
58670
+ };
58671
+ return persistStorage;
58672
+ }
58673
+ const toThenable = (fn) => (input) => {
58674
+ try {
58675
+ const result = fn(input);
58676
+ if (result instanceof Promise) {
58677
+ return result;
58664
58678
  }
58665
- const newTab = {
58666
- id: assetId,
58667
- name: (meta == null ? void 0 : meta.name) ?? null,
58668
- type: (meta == null ? void 0 : meta.type) ?? "unknown"
58679
+ return {
58680
+ then(onFulfilled) {
58681
+ return toThenable(onFulfilled)(result);
58682
+ },
58683
+ catch(_onRejected) {
58684
+ return this;
58685
+ }
58669
58686
  };
58670
- return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
58671
- }),
58672
- closeTab: (assetId) => set2((s) => {
58673
- var _a2;
58674
- const tabs = s.tabs.filter((t) => t.id !== assetId);
58675
- if (tabs.length === 0) {
58676
- return { isOpen: false, tabs: [], activeTabId: null, isFullscreen: false };
58687
+ } catch (e) {
58688
+ return {
58689
+ then(_onFulfilled) {
58690
+ return this;
58691
+ },
58692
+ catch(onRejected) {
58693
+ return toThenable(onRejected)(e);
58694
+ }
58695
+ };
58696
+ }
58697
+ };
58698
+ const persistImpl = (config2, baseOptions) => (set2, get2, api) => {
58699
+ let options = {
58700
+ storage: createJSONStorage(() => window.localStorage),
58701
+ partialize: (state) => state,
58702
+ version: 0,
58703
+ merge: (persistedState, currentState) => ({
58704
+ ...currentState,
58705
+ ...persistedState
58706
+ }),
58707
+ ...baseOptions
58708
+ };
58709
+ let hasHydrated = false;
58710
+ let hydrationVersion = 0;
58711
+ const hydrationListeners = /* @__PURE__ */ new Set();
58712
+ const finishHydrationListeners = /* @__PURE__ */ new Set();
58713
+ let storage = options.storage;
58714
+ if (!storage) {
58715
+ return config2(
58716
+ (...args) => {
58717
+ console.warn(
58718
+ `[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`
58719
+ );
58720
+ set2(...args);
58721
+ },
58722
+ get2,
58723
+ api
58724
+ );
58725
+ }
58726
+ const setItem = () => {
58727
+ const state = options.partialize({ ...get2() });
58728
+ return storage.setItem(options.name, {
58729
+ state,
58730
+ version: options.version
58731
+ });
58732
+ };
58733
+ const savedSetState = api.setState;
58734
+ api.setState = (state, replace2) => {
58735
+ savedSetState(state, replace2);
58736
+ return setItem();
58737
+ };
58738
+ const configResult = config2(
58739
+ (...args) => {
58740
+ set2(...args);
58741
+ return setItem();
58742
+ },
58743
+ get2,
58744
+ api
58745
+ );
58746
+ api.getInitialState = () => configResult;
58747
+ let stateFromStorage;
58748
+ const hydrate = () => {
58749
+ var _a2, _b;
58750
+ if (!storage) return;
58751
+ const currentVersion = ++hydrationVersion;
58752
+ hasHydrated = false;
58753
+ hydrationListeners.forEach((cb) => {
58754
+ var _a22;
58755
+ return cb((_a22 = get2()) != null ? _a22 : configResult);
58756
+ });
58757
+ const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a2 = get2()) != null ? _a2 : configResult)) || void 0;
58758
+ return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
58759
+ if (deserializedStorageValue) {
58760
+ if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
58761
+ if (options.migrate) {
58762
+ const migration = options.migrate(
58763
+ deserializedStorageValue.state,
58764
+ deserializedStorageValue.version
58765
+ );
58766
+ if (migration instanceof Promise) {
58767
+ return migration.then((result) => [true, result]);
58768
+ }
58769
+ return [true, migration];
58770
+ }
58771
+ console.error(
58772
+ `State loaded from storage couldn't be migrated since no migrate function was provided`
58773
+ );
58774
+ } else {
58775
+ return [false, deserializedStorageValue.state];
58776
+ }
58777
+ }
58778
+ return [false, void 0];
58779
+ }).then((migrationResult) => {
58780
+ var _a22;
58781
+ if (currentVersion !== hydrationVersion) {
58782
+ return;
58783
+ }
58784
+ const [migrated, migratedState] = migrationResult;
58785
+ stateFromStorage = options.merge(
58786
+ migratedState,
58787
+ (_a22 = get2()) != null ? _a22 : configResult
58788
+ );
58789
+ set2(stateFromStorage, true);
58790
+ if (migrated) {
58791
+ return setItem();
58792
+ }
58793
+ }).then(() => {
58794
+ if (currentVersion !== hydrationVersion) {
58795
+ return;
58796
+ }
58797
+ postRehydrationCallback == null ? void 0 : postRehydrationCallback(stateFromStorage, void 0);
58798
+ stateFromStorage = get2();
58799
+ hasHydrated = true;
58800
+ finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
58801
+ }).catch((e) => {
58802
+ if (currentVersion !== hydrationVersion) {
58803
+ return;
58804
+ }
58805
+ postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);
58806
+ });
58807
+ };
58808
+ api.persist = {
58809
+ setOptions: (newOptions) => {
58810
+ options = {
58811
+ ...options,
58812
+ ...newOptions
58813
+ };
58814
+ if (newOptions.storage) {
58815
+ storage = newOptions.storage;
58816
+ }
58817
+ },
58818
+ clearStorage: () => {
58819
+ storage == null ? void 0 : storage.removeItem(options.name);
58820
+ },
58821
+ getOptions: () => options,
58822
+ rehydrate: () => hydrate(),
58823
+ hasHydrated: () => hasHydrated,
58824
+ onHydrate: (cb) => {
58825
+ hydrationListeners.add(cb);
58826
+ return () => {
58827
+ hydrationListeners.delete(cb);
58828
+ };
58829
+ },
58830
+ onFinishHydration: (cb) => {
58831
+ finishHydrationListeners.add(cb);
58832
+ return () => {
58833
+ finishHydrationListeners.delete(cb);
58834
+ };
58677
58835
  }
58678
- const activeTabId = s.activeTabId === assetId ? ((_a2 = tabs[Math.min(s.tabs.findIndex((t) => t.id === assetId), tabs.length - 1)]) == null ? void 0 : _a2.id) ?? null : s.activeTabId;
58679
- return { tabs, activeTabId };
58680
- }),
58681
- setActiveTab: (assetId) => set2({ activeTabId: assetId, viewMode: "tabs" }),
58682
- setViewMode: (mode) => set2({ viewMode: mode }),
58683
- closePanel: () => set2({ isOpen: false, tabs: [], activeTabId: null, viewMode: "tabs", isFullscreen: false }),
58684
- toggleFullscreen: () => set2((s) => ({ isFullscreen: !s.isFullscreen })),
58685
- resetAutoOpen: () => set2((s) => ({ autoOpenGeneration: s.autoOpenGeneration + 1 })),
58686
- markAutoOpened: (assetId) => {
58687
- const state = get2();
58688
- if (state.autoOpenedAssets.get(assetId) === state.autoOpenGeneration) {
58689
- return false;
58836
+ };
58837
+ if (!options.skipHydration) {
58838
+ hydrate();
58839
+ }
58840
+ return stateFromStorage || configResult;
58841
+ };
58842
+ const persist = persistImpl;
58843
+ const useAssetPanelStore = create()(
58844
+ persist(
58845
+ (set2, get2) => ({
58846
+ isOpen: false,
58847
+ tabs: [],
58848
+ activeTabId: null,
58849
+ viewMode: "tabs",
58850
+ isFullscreen: false,
58851
+ assetPanelHostCount: 0,
58852
+ autoOpenGeneration: 0,
58853
+ autoOpenedAssets: /* @__PURE__ */ new Map(),
58854
+ registerAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: state.assetPanelHostCount + 1 })),
58855
+ unregisterAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: Math.max(0, state.assetPanelHostCount - 1) })),
58856
+ openAsset: (assetId, meta) => set2((s) => {
58857
+ const existing = s.tabs.find((t) => t.id === assetId);
58858
+ if (existing) {
58859
+ const tabs = meta ? s.tabs.map(
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
58866
+ ) : s.tabs;
58867
+ return { isOpen: true, tabs, activeTabId: assetId };
58868
+ }
58869
+ const newTab = {
58870
+ id: assetId,
58871
+ name: (meta == null ? void 0 : meta.name) ?? null,
58872
+ type: (meta == null ? void 0 : meta.type) ?? "unknown",
58873
+ embedSearchParams: (meta == null ? void 0 : meta.embedSearchParams) ?? null
58874
+ };
58875
+ return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
58876
+ }),
58877
+ closeTab: (assetId) => set2((s) => {
58878
+ var _a2;
58879
+ const tabs = s.tabs.filter((t) => t.id !== assetId);
58880
+ if (tabs.length === 0) {
58881
+ return { isOpen: false, tabs: [], activeTabId: null, isFullscreen: false };
58882
+ }
58883
+ const activeTabId = s.activeTabId === assetId ? ((_a2 = tabs[Math.min(s.tabs.findIndex((t) => t.id === assetId), tabs.length - 1)]) == null ? void 0 : _a2.id) ?? null : s.activeTabId;
58884
+ return { tabs, activeTabId };
58885
+ }),
58886
+ setActiveTab: (assetId) => set2({ activeTabId: assetId, viewMode: "tabs" }),
58887
+ setViewMode: (mode) => set2({ viewMode: mode }),
58888
+ closePanel: () => set2({ isOpen: false, tabs: [], activeTabId: null, viewMode: "tabs", isFullscreen: false }),
58889
+ toggleFullscreen: () => set2((s) => ({ isFullscreen: !s.isFullscreen })),
58890
+ resetAutoOpen: () => set2((s) => ({ autoOpenGeneration: s.autoOpenGeneration + 1 })),
58891
+ markAutoOpened: (assetId) => {
58892
+ const state = get2();
58893
+ if (state.autoOpenedAssets.get(assetId) === state.autoOpenGeneration) {
58894
+ return false;
58895
+ }
58896
+ state.autoOpenedAssets.set(assetId, state.autoOpenGeneration);
58897
+ return true;
58898
+ }
58899
+ }),
58900
+ {
58901
+ name: "athena-react-asset-panel",
58902
+ partialize: ({
58903
+ isOpen,
58904
+ tabs,
58905
+ activeTabId,
58906
+ viewMode,
58907
+ isFullscreen
58908
+ }) => ({
58909
+ isOpen,
58910
+ tabs,
58911
+ activeTabId,
58912
+ viewMode,
58913
+ isFullscreen
58914
+ }),
58915
+ storage: createJSONStorage(() => sessionStorage)
58690
58916
  }
58691
- state.autoOpenedAssets.set(assetId, state.autoOpenGeneration);
58692
- return true;
58693
- }
58694
- }));
58917
+ )
58918
+ );
58695
58919
  const ATHENA_APP_HOSTNAMES = /* @__PURE__ */ new Set(["app.athenaintel.com", "staging-app.athenaintel.com"]);
58696
58920
  const ATHENA_PREVIEW_HOSTNAME_SUFFIX = ".previews.athenaintel.com";
58921
+ const ATHENA_WORKSPACE_HOSTNAME_SUFFIXES = [".app.athenaintel.com", ".staging-app.athenaintel.com"];
58697
58922
  const ASSET_TYPE_ALIASES = {
58698
58923
  document: "document",
58699
58924
  notebook: "notebook",
@@ -58706,13 +58931,43 @@ const ASSET_TYPE_ALIASES = {
58706
58931
  super_document: "document"
58707
58932
  };
58708
58933
  const isAthenaSpacesPath = (url) => url.pathname.replace(/\/+$/, "") === "/dashboard/spaces";
58709
- const normalizeAssetType = (value) => {
58934
+ const normalizeAssetType$1 = (value) => {
58710
58935
  if (!value) {
58711
58936
  return null;
58712
58937
  }
58713
58938
  const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
58714
58939
  return ASSET_TYPE_ALIASES[normalizedValue] ?? null;
58715
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());
58716
58971
  const getOrigin = (value) => {
58717
58972
  if (!value) {
58718
58973
  return null;
@@ -58723,6 +58978,20 @@ const getOrigin = (value) => {
58723
58978
  return null;
58724
58979
  }
58725
58980
  };
58981
+ const getHostname = (value) => {
58982
+ if (!value) {
58983
+ return null;
58984
+ }
58985
+ try {
58986
+ return new URL(value).hostname.toLowerCase();
58987
+ } catch {
58988
+ return null;
58989
+ }
58990
+ };
58991
+ const matchesHostnameOrSubdomain = ({
58992
+ hostname,
58993
+ candidateHostname
58994
+ }) => hostname === candidateHostname || hostname.endsWith(`.${candidateHostname}`);
58726
58995
  const getCurrentOrigin = () => {
58727
58996
  if (typeof window === "undefined") {
58728
58997
  return null;
@@ -58745,7 +59014,11 @@ const isAthenaAppUrl = ({
58745
59014
  appUrl
58746
59015
  }) => {
58747
59016
  const hostname = url.hostname.toLowerCase();
58748
- if (ATHENA_APP_HOSTNAMES.has(hostname) || hostname.endsWith(ATHENA_PREVIEW_HOSTNAME_SUFFIX)) {
59017
+ if (ATHENA_APP_HOSTNAMES.has(hostname) || hostname.endsWith(ATHENA_PREVIEW_HOSTNAME_SUFFIX) || ATHENA_WORKSPACE_HOSTNAME_SUFFIXES.some((suffix) => hostname.endsWith(suffix))) {
59018
+ return true;
59019
+ }
59020
+ const configuredHostname = getHostname(appUrl);
59021
+ if (configuredHostname && matchesHostnameOrSubdomain({ hostname, candidateHostname: configuredHostname })) {
58749
59022
  return true;
58750
59023
  }
58751
59024
  const configuredOrigin = getOrigin(appUrl);
@@ -58776,7 +59049,11 @@ const parseAthenaCitationLink = ({
58776
59049
  url,
58777
59050
  assetId,
58778
59051
  assetIds,
58779
- 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)
58780
59057
  };
58781
59058
  };
58782
59059
  const isAthenaCitationUrl = ({
@@ -58824,12 +59101,19 @@ const useAthenaLinkClickHandler = () => {
58824
59101
  const citationMetadata = citationLink ? {
58825
59102
  assetId: citationLink.assetId,
58826
59103
  assetIds: citationLink.assetIds,
58827
- assetType: citationLink.assetType
59104
+ assetType: citationLink.assetType,
59105
+ assetName: citationLink.assetName,
59106
+ embedSearchParams: citationLink.embedSearchParams
58828
59107
  } : null;
58829
59108
  const openInAssetPanel = citationLink ? () => {
59109
+ const displayName = getCitationDisplayName({
59110
+ assetName: citationLink.assetName,
59111
+ linkText: trimmedLinkText
59112
+ });
58830
59113
  openAsset(citationLink.assetId, {
58831
- name: trimmedLinkText ?? void 0,
58832
- type: citationLink.assetType ?? void 0
59114
+ name: displayName ?? void 0,
59115
+ type: citationLink.assetType ?? void 0,
59116
+ embedSearchParams: citationLink.embedSearchParams
58833
59117
  });
58834
59118
  } : void 0;
58835
59119
  const context2 = {
@@ -63269,6 +63553,12 @@ function extractAssetId(result) {
63269
63553
  if (typeof id === "string" && id.startsWith("asset_")) return id;
63270
63554
  return null;
63271
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
+ }
63272
63562
  function resetAssetAutoOpen() {
63273
63563
  useAssetPanelStore.getState().resetAutoOpen();
63274
63564
  }
@@ -63988,6 +64278,7 @@ const OpenAssetToolUIImpl = ({
63988
64278
  const typedArgs = args;
63989
64279
  const argsAssetId = (typedArgs == null ? void 0 : typedArgs.asset_id) ?? (typedArgs == null ? void 0 : typedArgs.assetId) ?? "";
63990
64280
  const resultAssetId = extractAssetId(result);
64281
+ const resultAssetTitle = extractAssetTitle(result);
63991
64282
  const assetId = resultAssetId ?? (argsAssetId.startsWith("asset_") ? argsAssetId : null);
63992
64283
  const isRunning = (status == null ? void 0 : status.type) === "running";
63993
64284
  const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
@@ -63999,10 +64290,10 @@ const OpenAssetToolUIImpl = ({
63999
64290
  if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
64000
64291
  const store = useAssetPanelStore.getState();
64001
64292
  if (store.markAutoOpened(assetId)) {
64002
- store.openAsset(assetId);
64293
+ store.openAsset(assetId, { name: resultAssetTitle ?? void 0 });
64003
64294
  }
64004
64295
  }
64005
- }, [isComplete, isCancelled, assetId]);
64296
+ }, [isComplete, isCancelled, assetId, resultAssetTitle]);
64006
64297
  return /* @__PURE__ */ jsx(
64007
64298
  ToolCard,
64008
64299
  {
@@ -64018,7 +64309,7 @@ const OpenAssetToolUIImpl = ({
64018
64309
  "button",
64019
64310
  {
64020
64311
  type: "button",
64021
- onClick: () => openAsset(assetId),
64312
+ onClick: () => openAsset(assetId, { name: resultAssetTitle ?? void 0 }),
64022
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",
64023
64314
  children: [
64024
64315
  /* @__PURE__ */ jsx(ExternalLink, { className: "size-3" }),
@@ -64943,14 +65234,58 @@ const AthenaUserMessage = ({
64943
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 } }) })
64944
65235
  }
64945
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
+ };
64946
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
+ };
64947
65273
  function useAssetEmbed(assetId, options = {
64948
65274
  backendUrl: ""
64949
65275
  }) {
64950
- 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;
64951
65284
  const [embedUrl, setEmbedUrl] = useState(null);
64952
65285
  const [isLoading, setIsLoading] = useState(false);
64953
65286
  const [error2, setError] = useState(null);
65287
+ const [assetTitle, setAssetTitle] = useState(null);
65288
+ const [assetType, setAssetType] = useState(null);
64954
65289
  const abortRef = useRef(null);
64955
65290
  useEffect(() => {
64956
65291
  var _a2;
@@ -64958,14 +65293,18 @@ function useAssetEmbed(assetId, options = {
64958
65293
  setEmbedUrl(null);
64959
65294
  setIsLoading(false);
64960
65295
  setError(null);
65296
+ setAssetTitle(null);
65297
+ setAssetType(null);
64961
65298
  return;
64962
65299
  }
64963
- const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
65300
+ const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}:${JSON.stringify(embedSearchParams ?? {})}`;
64964
65301
  const cached = embedCache.get(cacheKey);
64965
65302
  if (cached && cached.expiresAt > Date.now() / 1e3) {
64966
65303
  setEmbedUrl(cached.url);
64967
65304
  setIsLoading(false);
64968
65305
  setError(null);
65306
+ setAssetTitle(cached.assetTitle);
65307
+ setAssetType(cached.assetType);
64969
65308
  return;
64970
65309
  }
64971
65310
  const apiBaseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
@@ -64973,11 +65312,14 @@ function useAssetEmbed(assetId, options = {
64973
65312
  (_a2 = abortRef.current) == null ? void 0 : _a2.abort();
64974
65313
  const controller = new AbortController();
64975
65314
  abortRef.current = controller;
65315
+ setEmbedUrl(null);
64976
65316
  setIsLoading(true);
64977
65317
  setError(null);
65318
+ setAssetTitle(null);
65319
+ setAssetType(null);
64978
65320
  const headers = { "Content-Type": "application/json" };
64979
65321
  if (token) {
64980
- headers["Authorization"] = `Bearer ${token}`;
65322
+ headers.Authorization = `Bearer ${token}`;
64981
65323
  } else if (apiKey) {
64982
65324
  headers["X-API-KEY"] = apiKey;
64983
65325
  }
@@ -64997,17 +65339,31 @@ function useAssetEmbed(assetId, options = {
64997
65339
  }
64998
65340
  return res.json();
64999
65341
  }).then((data) => {
65000
- embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
65001
- 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);
65002
65356
  setIsLoading(false);
65003
65357
  }).catch((err) => {
65004
- if (err.name === "AbortError") return;
65358
+ if (err.name === "AbortError") {
65359
+ return;
65360
+ }
65005
65361
  setError(err.message);
65006
65362
  setIsLoading(false);
65007
65363
  });
65008
65364
  return () => controller.abort();
65009
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
65010
- return { embedUrl, isLoading, error: error2 };
65365
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token, embedSearchParams]);
65366
+ return { embedUrl, isLoading, error: error2, assetTitle, assetType };
65011
65367
  }
65012
65368
  const ASSET_TYPE_CONFIG = {
65013
65369
  presentation: { icon: Presentation, label: "Presentation" },
@@ -65017,13 +65373,28 @@ const ASSET_TYPE_CONFIG = {
65017
65373
  unknown: { icon: File$1, label: "Asset" }
65018
65374
  };
65019
65375
  const AssetIframe = memo(
65020
- ({ tabId, tabName }) => {
65376
+ ({ tabId, tabName, tabType, embedSearchParams }) => {
65021
65377
  const { backendUrl, apiKey, token } = useAthenaConfig();
65022
- const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tabId, {
65378
+ const { embedUrl, isLoading, error: error2, assetTitle, assetType } = useAssetEmbed(tabId, {
65023
65379
  backendUrl,
65024
65380
  apiKey,
65025
- token
65381
+ token,
65382
+ embedSearchParams
65026
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]);
65027
65398
  if (isLoading) {
65028
65399
  return /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
65029
65400
  /* @__PURE__ */ jsx(LoaderCircle, { className: "mx-auto size-6 animate-spin text-muted-foreground" }),
@@ -65108,7 +65479,15 @@ const PanelContent = ({
65108
65479
  }
65109
65480
  )
65110
65481
  ] }),
65111
- /* @__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
+ ) })
65112
65491
  ]
65113
65492
  },
65114
65493
  tab.id
@@ -65118,7 +65497,15 @@ const PanelContent = ({
65118
65497
  "div",
65119
65498
  {
65120
65499
  className: isActive2 ? "h-full w-full" : "hidden",
65121
- 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
+ )
65122
65509
  },
65123
65510
  tab.id
65124
65511
  );