@athenaintel/react 0.9.23 → 0.9.24

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
@@ -24496,6 +24496,424 @@ const useAthenaRuntime = (config2) => {
24496
24496
  }, [isExistingThread, runtime, threadId, backendUrl]);
24497
24497
  return runtime;
24498
24498
  };
24499
+ function createJSONStorage(getStorage, options) {
24500
+ let storage;
24501
+ try {
24502
+ storage = getStorage();
24503
+ } catch (e) {
24504
+ return;
24505
+ }
24506
+ const persistStorage = {
24507
+ getItem: (name) => {
24508
+ var _a2;
24509
+ const parse2 = (str2) => {
24510
+ if (str2 === null) {
24511
+ return null;
24512
+ }
24513
+ return JSON.parse(str2, void 0);
24514
+ };
24515
+ const str = (_a2 = storage.getItem(name)) != null ? _a2 : null;
24516
+ if (str instanceof Promise) {
24517
+ return str.then(parse2);
24518
+ }
24519
+ return parse2(str);
24520
+ },
24521
+ setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, void 0)),
24522
+ removeItem: (name) => storage.removeItem(name)
24523
+ };
24524
+ return persistStorage;
24525
+ }
24526
+ const toThenable = (fn) => (input) => {
24527
+ try {
24528
+ const result = fn(input);
24529
+ if (result instanceof Promise) {
24530
+ return result;
24531
+ }
24532
+ return {
24533
+ then(onFulfilled) {
24534
+ return toThenable(onFulfilled)(result);
24535
+ },
24536
+ catch(_onRejected) {
24537
+ return this;
24538
+ }
24539
+ };
24540
+ } catch (e) {
24541
+ return {
24542
+ then(_onFulfilled) {
24543
+ return this;
24544
+ },
24545
+ catch(onRejected) {
24546
+ return toThenable(onRejected)(e);
24547
+ }
24548
+ };
24549
+ }
24550
+ };
24551
+ const persistImpl = (config2, baseOptions) => (set2, get2, api) => {
24552
+ let options = {
24553
+ storage: createJSONStorage(() => window.localStorage),
24554
+ partialize: (state) => state,
24555
+ version: 0,
24556
+ merge: (persistedState, currentState) => ({
24557
+ ...currentState,
24558
+ ...persistedState
24559
+ }),
24560
+ ...baseOptions
24561
+ };
24562
+ let hasHydrated = false;
24563
+ let hydrationVersion = 0;
24564
+ const hydrationListeners = /* @__PURE__ */ new Set();
24565
+ const finishHydrationListeners = /* @__PURE__ */ new Set();
24566
+ let storage = options.storage;
24567
+ if (!storage) {
24568
+ return config2(
24569
+ (...args) => {
24570
+ console.warn(
24571
+ `[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`
24572
+ );
24573
+ set2(...args);
24574
+ },
24575
+ get2,
24576
+ api
24577
+ );
24578
+ }
24579
+ const setItem = () => {
24580
+ const state = options.partialize({ ...get2() });
24581
+ return storage.setItem(options.name, {
24582
+ state,
24583
+ version: options.version
24584
+ });
24585
+ };
24586
+ const savedSetState = api.setState;
24587
+ api.setState = (state, replace2) => {
24588
+ savedSetState(state, replace2);
24589
+ return setItem();
24590
+ };
24591
+ const configResult = config2(
24592
+ (...args) => {
24593
+ set2(...args);
24594
+ return setItem();
24595
+ },
24596
+ get2,
24597
+ api
24598
+ );
24599
+ api.getInitialState = () => configResult;
24600
+ let stateFromStorage;
24601
+ const hydrate = () => {
24602
+ var _a2, _b;
24603
+ if (!storage) return;
24604
+ const currentVersion = ++hydrationVersion;
24605
+ hasHydrated = false;
24606
+ hydrationListeners.forEach((cb) => {
24607
+ var _a22;
24608
+ return cb((_a22 = get2()) != null ? _a22 : configResult);
24609
+ });
24610
+ const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a2 = get2()) != null ? _a2 : configResult)) || void 0;
24611
+ return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
24612
+ if (deserializedStorageValue) {
24613
+ if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
24614
+ if (options.migrate) {
24615
+ const migration = options.migrate(
24616
+ deserializedStorageValue.state,
24617
+ deserializedStorageValue.version
24618
+ );
24619
+ if (migration instanceof Promise) {
24620
+ return migration.then((result) => [true, result]);
24621
+ }
24622
+ return [true, migration];
24623
+ }
24624
+ console.error(
24625
+ `State loaded from storage couldn't be migrated since no migrate function was provided`
24626
+ );
24627
+ } else {
24628
+ return [false, deserializedStorageValue.state];
24629
+ }
24630
+ }
24631
+ return [false, void 0];
24632
+ }).then((migrationResult) => {
24633
+ var _a22;
24634
+ if (currentVersion !== hydrationVersion) {
24635
+ return;
24636
+ }
24637
+ const [migrated, migratedState] = migrationResult;
24638
+ stateFromStorage = options.merge(
24639
+ migratedState,
24640
+ (_a22 = get2()) != null ? _a22 : configResult
24641
+ );
24642
+ set2(stateFromStorage, true);
24643
+ if (migrated) {
24644
+ return setItem();
24645
+ }
24646
+ }).then(() => {
24647
+ if (currentVersion !== hydrationVersion) {
24648
+ return;
24649
+ }
24650
+ postRehydrationCallback == null ? void 0 : postRehydrationCallback(stateFromStorage, void 0);
24651
+ stateFromStorage = get2();
24652
+ hasHydrated = true;
24653
+ finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
24654
+ }).catch((e) => {
24655
+ if (currentVersion !== hydrationVersion) {
24656
+ return;
24657
+ }
24658
+ postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);
24659
+ });
24660
+ };
24661
+ api.persist = {
24662
+ setOptions: (newOptions) => {
24663
+ options = {
24664
+ ...options,
24665
+ ...newOptions
24666
+ };
24667
+ if (newOptions.storage) {
24668
+ storage = newOptions.storage;
24669
+ }
24670
+ },
24671
+ clearStorage: () => {
24672
+ storage == null ? void 0 : storage.removeItem(options.name);
24673
+ },
24674
+ getOptions: () => options,
24675
+ rehydrate: () => hydrate(),
24676
+ hasHydrated: () => hasHydrated,
24677
+ onHydrate: (cb) => {
24678
+ hydrationListeners.add(cb);
24679
+ return () => {
24680
+ hydrationListeners.delete(cb);
24681
+ };
24682
+ },
24683
+ onFinishHydration: (cb) => {
24684
+ finishHydrationListeners.add(cb);
24685
+ return () => {
24686
+ finishHydrationListeners.delete(cb);
24687
+ };
24688
+ }
24689
+ };
24690
+ if (!options.skipHydration) {
24691
+ hydrate();
24692
+ }
24693
+ return stateFromStorage || configResult;
24694
+ };
24695
+ const persist = persistImpl;
24696
+ const useAssetPanelStore = create()(
24697
+ persist(
24698
+ (set2, get2) => ({
24699
+ isOpen: false,
24700
+ tabs: [],
24701
+ activeTabId: null,
24702
+ viewMode: "tabs",
24703
+ isFullscreen: false,
24704
+ assetPanelHostCount: 0,
24705
+ autoOpenGeneration: 0,
24706
+ autoOpenedAssets: /* @__PURE__ */ new Map(),
24707
+ registerAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: state.assetPanelHostCount + 1 })),
24708
+ unregisterAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: Math.max(0, state.assetPanelHostCount - 1) })),
24709
+ openAsset: (assetId, meta) => set2((s) => {
24710
+ const existing = s.tabs.find((t) => t.id === assetId);
24711
+ if (existing) {
24712
+ const tabs = meta ? s.tabs.map(
24713
+ (t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
24714
+ ) : s.tabs;
24715
+ return { isOpen: true, tabs, activeTabId: assetId };
24716
+ }
24717
+ const newTab = {
24718
+ id: assetId,
24719
+ name: (meta == null ? void 0 : meta.name) ?? null,
24720
+ type: (meta == null ? void 0 : meta.type) ?? "unknown"
24721
+ };
24722
+ return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
24723
+ }),
24724
+ closeTab: (assetId) => set2((s) => {
24725
+ var _a2;
24726
+ const tabs = s.tabs.filter((t) => t.id !== assetId);
24727
+ if (tabs.length === 0) {
24728
+ return { isOpen: false, tabs: [], activeTabId: null, isFullscreen: false };
24729
+ }
24730
+ 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;
24731
+ return { tabs, activeTabId };
24732
+ }),
24733
+ setActiveTab: (assetId) => set2({ activeTabId: assetId, viewMode: "tabs" }),
24734
+ setViewMode: (mode) => set2({ viewMode: mode }),
24735
+ closePanel: () => set2({ isOpen: false, tabs: [], activeTabId: null, viewMode: "tabs", isFullscreen: false }),
24736
+ toggleFullscreen: () => set2((s) => ({ isFullscreen: !s.isFullscreen })),
24737
+ resetAutoOpen: () => set2((s) => ({ autoOpenGeneration: s.autoOpenGeneration + 1 })),
24738
+ markAutoOpened: (assetId) => {
24739
+ const state = get2();
24740
+ if (state.autoOpenedAssets.get(assetId) === state.autoOpenGeneration) {
24741
+ return false;
24742
+ }
24743
+ state.autoOpenedAssets.set(assetId, state.autoOpenGeneration);
24744
+ return true;
24745
+ }
24746
+ }),
24747
+ {
24748
+ name: "athena-react-asset-panel",
24749
+ partialize: ({
24750
+ isOpen,
24751
+ tabs,
24752
+ activeTabId,
24753
+ viewMode,
24754
+ isFullscreen
24755
+ }) => ({
24756
+ isOpen,
24757
+ tabs,
24758
+ activeTabId,
24759
+ viewMode,
24760
+ isFullscreen
24761
+ }),
24762
+ storage: createJSONStorage(() => sessionStorage)
24763
+ }
24764
+ )
24765
+ );
24766
+ const THREAD_SNAPSHOT_STORAGE_KEY = "athena-react-asset-panel-thread-snapshots";
24767
+ const DEFAULT_ASSET_PANEL_SNAPSHOT = {
24768
+ isOpen: false,
24769
+ tabs: [],
24770
+ activeTabId: null,
24771
+ viewMode: "tabs",
24772
+ isFullscreen: false
24773
+ };
24774
+ const useBrowserLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
24775
+ const selectAssetPanelSnapshot = (state) => ({
24776
+ isOpen: state.isOpen,
24777
+ tabs: state.tabs,
24778
+ activeTabId: state.activeTabId,
24779
+ viewMode: state.viewMode,
24780
+ isFullscreen: state.isFullscreen
24781
+ });
24782
+ const areSnapshotsEqual = (left, right) => {
24783
+ if (left.isOpen !== right.isOpen || left.activeTabId !== right.activeTabId || left.viewMode !== right.viewMode || left.isFullscreen !== right.isFullscreen || left.tabs.length !== right.tabs.length) {
24784
+ return false;
24785
+ }
24786
+ return left.tabs.every((tab, index2) => {
24787
+ const otherTab = right.tabs[index2];
24788
+ return otherTab !== void 0 && tab.id === otherTab.id && tab.name === otherTab.name && tab.type === otherTab.type;
24789
+ });
24790
+ };
24791
+ const getSessionStorage = () => {
24792
+ if (typeof window === "undefined") {
24793
+ return null;
24794
+ }
24795
+ try {
24796
+ return sessionStorage;
24797
+ } catch {
24798
+ return null;
24799
+ }
24800
+ };
24801
+ const readAllThreadSnapshots = () => {
24802
+ const storage = getSessionStorage();
24803
+ if (!storage) {
24804
+ return {};
24805
+ }
24806
+ try {
24807
+ const raw = storage.getItem(THREAD_SNAPSHOT_STORAGE_KEY);
24808
+ if (!raw) {
24809
+ return {};
24810
+ }
24811
+ const parsed = JSON.parse(raw);
24812
+ if (!parsed || typeof parsed !== "object") {
24813
+ return {};
24814
+ }
24815
+ return parsed;
24816
+ } catch {
24817
+ return {};
24818
+ }
24819
+ };
24820
+ const writeAllThreadSnapshots = (snapshots) => {
24821
+ const storage = getSessionStorage();
24822
+ if (!storage) {
24823
+ return;
24824
+ }
24825
+ try {
24826
+ storage.setItem(THREAD_SNAPSHOT_STORAGE_KEY, JSON.stringify(snapshots));
24827
+ } catch {
24828
+ }
24829
+ };
24830
+ const readThreadSnapshot = (threadInfo) => {
24831
+ const snapshots = readAllThreadSnapshots();
24832
+ if (threadInfo.remoteId && snapshots[threadInfo.remoteId]) {
24833
+ return snapshots[threadInfo.remoteId];
24834
+ }
24835
+ return snapshots[threadInfo.threadId] ?? DEFAULT_ASSET_PANEL_SNAPSHOT;
24836
+ };
24837
+ const writeThreadSnapshot = (threadInfo, snapshot) => {
24838
+ const keys2 = [threadInfo.threadId, threadInfo.remoteId].filter(
24839
+ (value) => Boolean(value)
24840
+ );
24841
+ if (keys2.length === 0) {
24842
+ return;
24843
+ }
24844
+ const snapshots = readAllThreadSnapshots();
24845
+ let didChange = false;
24846
+ for (const key of keys2) {
24847
+ if (areSnapshotsEqual(snapshots[key] ?? DEFAULT_ASSET_PANEL_SNAPSHOT, snapshot)) {
24848
+ continue;
24849
+ }
24850
+ snapshots[key] = snapshot;
24851
+ didChange = true;
24852
+ }
24853
+ if (didChange) {
24854
+ writeAllThreadSnapshots(snapshots);
24855
+ }
24856
+ };
24857
+ function AssetPanelThreadPersistence() {
24858
+ const mainThreadId = useAuiState((state) => state.threads.mainThreadId);
24859
+ const activeRemoteId = useAuiState((state) => {
24860
+ const activeThread = state.threads.threadItems.find(
24861
+ (thread) => thread.id === state.threads.mainThreadId
24862
+ );
24863
+ return (activeThread == null ? void 0 : activeThread.remoteId) ?? null;
24864
+ });
24865
+ const panelSnapshot = useAssetPanelStore(selectAssetPanelSnapshot);
24866
+ const previousThreadRef = useRef(null);
24867
+ const pendingPersistSkipKeyRef = useRef(null);
24868
+ useBrowserLayoutEffect(() => {
24869
+ if (!mainThreadId) {
24870
+ return;
24871
+ }
24872
+ const activeThread = {
24873
+ threadId: mainThreadId,
24874
+ remoteId: activeRemoteId
24875
+ };
24876
+ const previousThread = previousThreadRef.current;
24877
+ const didThreadChange = !previousThread || previousThread.threadId !== activeThread.threadId || previousThread.remoteId !== activeThread.remoteId;
24878
+ if (!didThreadChange) {
24879
+ return;
24880
+ }
24881
+ if (previousThread) {
24882
+ writeThreadSnapshot(
24883
+ previousThread,
24884
+ selectAssetPanelSnapshot(useAssetPanelStore.getState())
24885
+ );
24886
+ }
24887
+ previousThreadRef.current = activeThread;
24888
+ pendingPersistSkipKeyRef.current = activeThread.remoteId ?? activeThread.threadId;
24889
+ const snapshotToRestore = readThreadSnapshot(activeThread);
24890
+ const currentSnapshot = selectAssetPanelSnapshot(useAssetPanelStore.getState());
24891
+ if (!areSnapshotsEqual(currentSnapshot, snapshotToRestore)) {
24892
+ useAssetPanelStore.setState((state) => ({
24893
+ ...state,
24894
+ ...snapshotToRestore
24895
+ }));
24896
+ }
24897
+ }, [mainThreadId, activeRemoteId]);
24898
+ useEffect(() => {
24899
+ if (!mainThreadId) {
24900
+ return;
24901
+ }
24902
+ const activeThreadKey = activeRemoteId ?? mainThreadId;
24903
+ if (pendingPersistSkipKeyRef.current === activeThreadKey) {
24904
+ pendingPersistSkipKeyRef.current = null;
24905
+ return;
24906
+ }
24907
+ writeThreadSnapshot(
24908
+ {
24909
+ threadId: mainThreadId,
24910
+ remoteId: activeRemoteId
24911
+ },
24912
+ panelSnapshot
24913
+ );
24914
+ }, [mainThreadId, activeRemoteId, panelSnapshot]);
24915
+ return null;
24916
+ }
24499
24917
  function TooltipProvider({
24500
24918
  delayDuration = 0,
24501
24919
  ...props
@@ -25016,7 +25434,10 @@ function AthenaWithThreadList({
25016
25434
  linkClicks,
25017
25435
  citationLinks
25018
25436
  });
25019
- return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(ThreadListRefreshContext.Provider, { value: handleRefresh, children: /* @__PURE__ */ jsx(TooltipProvider, { children }) }) }) });
25437
+ return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(ThreadListRefreshContext.Provider, { value: handleRefresh, children: /* @__PURE__ */ jsxs(TooltipProvider, { children: [
25438
+ /* @__PURE__ */ jsx(AssetPanelThreadPersistence, {}),
25439
+ children
25440
+ ] }) }) }) });
25020
25441
  }
25021
25442
  function AthenaProvider({
25022
25443
  children,
@@ -58769,273 +59190,6 @@ const MentionExtension = Node3.create({
58769
59190
  };
58770
59191
  }
58771
59192
  });
58772
- function createJSONStorage(getStorage, options) {
58773
- let storage;
58774
- try {
58775
- storage = getStorage();
58776
- } catch (e) {
58777
- return;
58778
- }
58779
- const persistStorage = {
58780
- getItem: (name) => {
58781
- var _a2;
58782
- const parse2 = (str2) => {
58783
- if (str2 === null) {
58784
- return null;
58785
- }
58786
- return JSON.parse(str2, void 0);
58787
- };
58788
- const str = (_a2 = storage.getItem(name)) != null ? _a2 : null;
58789
- if (str instanceof Promise) {
58790
- return str.then(parse2);
58791
- }
58792
- return parse2(str);
58793
- },
58794
- setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, void 0)),
58795
- removeItem: (name) => storage.removeItem(name)
58796
- };
58797
- return persistStorage;
58798
- }
58799
- const toThenable = (fn) => (input) => {
58800
- try {
58801
- const result = fn(input);
58802
- if (result instanceof Promise) {
58803
- return result;
58804
- }
58805
- return {
58806
- then(onFulfilled) {
58807
- return toThenable(onFulfilled)(result);
58808
- },
58809
- catch(_onRejected) {
58810
- return this;
58811
- }
58812
- };
58813
- } catch (e) {
58814
- return {
58815
- then(_onFulfilled) {
58816
- return this;
58817
- },
58818
- catch(onRejected) {
58819
- return toThenable(onRejected)(e);
58820
- }
58821
- };
58822
- }
58823
- };
58824
- const persistImpl = (config2, baseOptions) => (set2, get2, api) => {
58825
- let options = {
58826
- storage: createJSONStorage(() => window.localStorage),
58827
- partialize: (state) => state,
58828
- version: 0,
58829
- merge: (persistedState, currentState) => ({
58830
- ...currentState,
58831
- ...persistedState
58832
- }),
58833
- ...baseOptions
58834
- };
58835
- let hasHydrated = false;
58836
- let hydrationVersion = 0;
58837
- const hydrationListeners = /* @__PURE__ */ new Set();
58838
- const finishHydrationListeners = /* @__PURE__ */ new Set();
58839
- let storage = options.storage;
58840
- if (!storage) {
58841
- return config2(
58842
- (...args) => {
58843
- console.warn(
58844
- `[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`
58845
- );
58846
- set2(...args);
58847
- },
58848
- get2,
58849
- api
58850
- );
58851
- }
58852
- const setItem = () => {
58853
- const state = options.partialize({ ...get2() });
58854
- return storage.setItem(options.name, {
58855
- state,
58856
- version: options.version
58857
- });
58858
- };
58859
- const savedSetState = api.setState;
58860
- api.setState = (state, replace2) => {
58861
- savedSetState(state, replace2);
58862
- return setItem();
58863
- };
58864
- const configResult = config2(
58865
- (...args) => {
58866
- set2(...args);
58867
- return setItem();
58868
- },
58869
- get2,
58870
- api
58871
- );
58872
- api.getInitialState = () => configResult;
58873
- let stateFromStorage;
58874
- const hydrate = () => {
58875
- var _a2, _b;
58876
- if (!storage) return;
58877
- const currentVersion = ++hydrationVersion;
58878
- hasHydrated = false;
58879
- hydrationListeners.forEach((cb) => {
58880
- var _a22;
58881
- return cb((_a22 = get2()) != null ? _a22 : configResult);
58882
- });
58883
- const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a2 = get2()) != null ? _a2 : configResult)) || void 0;
58884
- return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
58885
- if (deserializedStorageValue) {
58886
- if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
58887
- if (options.migrate) {
58888
- const migration = options.migrate(
58889
- deserializedStorageValue.state,
58890
- deserializedStorageValue.version
58891
- );
58892
- if (migration instanceof Promise) {
58893
- return migration.then((result) => [true, result]);
58894
- }
58895
- return [true, migration];
58896
- }
58897
- console.error(
58898
- `State loaded from storage couldn't be migrated since no migrate function was provided`
58899
- );
58900
- } else {
58901
- return [false, deserializedStorageValue.state];
58902
- }
58903
- }
58904
- return [false, void 0];
58905
- }).then((migrationResult) => {
58906
- var _a22;
58907
- if (currentVersion !== hydrationVersion) {
58908
- return;
58909
- }
58910
- const [migrated, migratedState] = migrationResult;
58911
- stateFromStorage = options.merge(
58912
- migratedState,
58913
- (_a22 = get2()) != null ? _a22 : configResult
58914
- );
58915
- set2(stateFromStorage, true);
58916
- if (migrated) {
58917
- return setItem();
58918
- }
58919
- }).then(() => {
58920
- if (currentVersion !== hydrationVersion) {
58921
- return;
58922
- }
58923
- postRehydrationCallback == null ? void 0 : postRehydrationCallback(stateFromStorage, void 0);
58924
- stateFromStorage = get2();
58925
- hasHydrated = true;
58926
- finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
58927
- }).catch((e) => {
58928
- if (currentVersion !== hydrationVersion) {
58929
- return;
58930
- }
58931
- postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);
58932
- });
58933
- };
58934
- api.persist = {
58935
- setOptions: (newOptions) => {
58936
- options = {
58937
- ...options,
58938
- ...newOptions
58939
- };
58940
- if (newOptions.storage) {
58941
- storage = newOptions.storage;
58942
- }
58943
- },
58944
- clearStorage: () => {
58945
- storage == null ? void 0 : storage.removeItem(options.name);
58946
- },
58947
- getOptions: () => options,
58948
- rehydrate: () => hydrate(),
58949
- hasHydrated: () => hasHydrated,
58950
- onHydrate: (cb) => {
58951
- hydrationListeners.add(cb);
58952
- return () => {
58953
- hydrationListeners.delete(cb);
58954
- };
58955
- },
58956
- onFinishHydration: (cb) => {
58957
- finishHydrationListeners.add(cb);
58958
- return () => {
58959
- finishHydrationListeners.delete(cb);
58960
- };
58961
- }
58962
- };
58963
- if (!options.skipHydration) {
58964
- hydrate();
58965
- }
58966
- return stateFromStorage || configResult;
58967
- };
58968
- const persist = persistImpl;
58969
- const useAssetPanelStore = create()(
58970
- persist(
58971
- (set2, get2) => ({
58972
- isOpen: false,
58973
- tabs: [],
58974
- activeTabId: null,
58975
- viewMode: "tabs",
58976
- isFullscreen: false,
58977
- assetPanelHostCount: 0,
58978
- autoOpenGeneration: 0,
58979
- autoOpenedAssets: /* @__PURE__ */ new Map(),
58980
- registerAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: state.assetPanelHostCount + 1 })),
58981
- unregisterAssetPanelHost: () => set2((state) => ({ assetPanelHostCount: Math.max(0, state.assetPanelHostCount - 1) })),
58982
- openAsset: (assetId, meta) => set2((s) => {
58983
- const existing = s.tabs.find((t) => t.id === assetId);
58984
- if (existing) {
58985
- const tabs = meta ? s.tabs.map(
58986
- (t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
58987
- ) : s.tabs;
58988
- return { isOpen: true, tabs, activeTabId: assetId };
58989
- }
58990
- const newTab = {
58991
- id: assetId,
58992
- name: (meta == null ? void 0 : meta.name) ?? null,
58993
- type: (meta == null ? void 0 : meta.type) ?? "unknown"
58994
- };
58995
- return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
58996
- }),
58997
- closeTab: (assetId) => set2((s) => {
58998
- var _a2;
58999
- const tabs = s.tabs.filter((t) => t.id !== assetId);
59000
- if (tabs.length === 0) {
59001
- return { isOpen: false, tabs: [], activeTabId: null, isFullscreen: false };
59002
- }
59003
- 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;
59004
- return { tabs, activeTabId };
59005
- }),
59006
- setActiveTab: (assetId) => set2({ activeTabId: assetId, viewMode: "tabs" }),
59007
- setViewMode: (mode) => set2({ viewMode: mode }),
59008
- closePanel: () => set2({ isOpen: false, tabs: [], activeTabId: null, viewMode: "tabs", isFullscreen: false }),
59009
- toggleFullscreen: () => set2((s) => ({ isFullscreen: !s.isFullscreen })),
59010
- resetAutoOpen: () => set2((s) => ({ autoOpenGeneration: s.autoOpenGeneration + 1 })),
59011
- markAutoOpened: (assetId) => {
59012
- const state = get2();
59013
- if (state.autoOpenedAssets.get(assetId) === state.autoOpenGeneration) {
59014
- return false;
59015
- }
59016
- state.autoOpenedAssets.set(assetId, state.autoOpenGeneration);
59017
- return true;
59018
- }
59019
- }),
59020
- {
59021
- name: "athena-react-asset-panel",
59022
- partialize: ({
59023
- isOpen,
59024
- tabs,
59025
- activeTabId,
59026
- viewMode,
59027
- isFullscreen
59028
- }) => ({
59029
- isOpen,
59030
- tabs,
59031
- activeTabId,
59032
- viewMode,
59033
- isFullscreen
59034
- }),
59035
- storage: createJSONStorage(() => sessionStorage)
59036
- }
59037
- )
59038
- );
59039
59193
  const ATHENA_APP_HOSTNAMES = /* @__PURE__ */ new Set(["app.athenaintel.com", "staging-app.athenaintel.com"]);
59040
59194
  const ATHENA_PREVIEW_HOSTNAME_SUFFIX = ".previews.athenaintel.com";
59041
59195
  const ATHENA_WORKSPACE_HOSTNAME_SUFFIXES = [".app.athenaintel.com", ".staging-app.athenaintel.com"];