@athenaintel/react 0.7.3 → 0.8.0

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
@@ -96,7 +96,7 @@ export declare interface AthenaLayoutProps {
96
96
  minPercent?: number;
97
97
  }
98
98
 
99
- export declare function AthenaProvider({ children, apiKey, token: tokenProp, agent, model, tools, frontendTools, apiUrl, backendUrl, workbench, knowledgeBase, systemPrompt, threadId: threadIdProp, enableThreadList, theme, }: AthenaProviderProps): JSX.Element;
99
+ export declare function AthenaProvider({ children, apiKey, token: tokenProp, agent, model, tools, frontendTools, apiUrl, backendUrl, workbench, knowledgeBase, systemPrompt, threadId: threadIdProp, enableThreadList, theme, }: AthenaProviderProps): JSX.Element | null;
100
100
 
101
101
  export declare interface AthenaProviderProps {
102
102
  children: ReactNode;
@@ -306,6 +306,8 @@ export declare const CreatePresentationToolUI: ToolCallMessagePartComponent;
306
306
 
307
307
  export declare const CreateSheetToolUI: ToolCallMessagePartComponent;
308
308
 
309
+ export declare const DEFAULT_API_URL = "https://sync.athenaintel.com/api/chat";
310
+
309
311
  export declare const DEFAULT_BACKEND_URL = "https://api.athenaintel.com/api/assistant-ui";
310
312
 
311
313
  export declare const EmailSearchToolUI: ToolCallMessagePartComponent;
@@ -387,6 +389,17 @@ export declare function normalizeResult(result: unknown): Record<string, unknown
387
389
 
388
390
  export declare const OpenAssetToolUI: ToolCallMessagePartComponent;
389
391
 
392
+ export declare interface ParentBridgeState {
393
+ /** PropelAuth access token from the parent window. */
394
+ token: string | null;
395
+ /** Sync server chat URL provided by the Marathon wrapper. */
396
+ apiUrl: string | null;
397
+ /** Agora backend URL provided by the Marathon wrapper. */
398
+ backendUrl: string | null;
399
+ /** True once config has been received from the parent (or timeout fired). */
400
+ ready: boolean;
401
+ }
402
+
390
403
  declare interface QuoteContextValue {
391
404
  quote: QuoteData | null;
392
405
  setQuote: (quote: QuoteData | null) => void;
@@ -859,19 +872,28 @@ export declare interface UseFileUploadReturn {
859
872
  export declare function useMentionSuggestions(tools: MentionTool[]): MentionSuggestionsStore;
860
873
 
861
874
  /**
862
- * Listens for auth tokens sent from a parent window via PostMessage.
875
+ * Legacy hook — returns just the auth token from the parent bridge.
876
+ * Prefer useParentBridge() for new code.
877
+ */
878
+ export declare function useParentAuth(): string | null;
879
+
880
+ /**
881
+ * Listens for auth tokens AND environment config sent from a parent window
882
+ * via PostMessage.
883
+ *
884
+ * When the app runs inside a Marathon wrapper, the wrapper sends:
885
+ * 1. { type: 'athena-config', apiUrl, backendUrl } — correct API URLs for the environment
886
+ * 2. { type: 'athena-auth', token } — relayed from the Olympus token-bridge iframe
863
887
  *
864
- * When the app runs inside an Olympus iframe, the parent sends
865
- * the user's PropelAuth access token so the chat authenticates as the
866
- * actual viewer — not the hardcoded API key owner.
888
+ * When running inside an Olympus inline preview, only athena-auth is sent.
889
+ * When running standalone (no parent), returns defaults immediately.
867
890
  *
868
891
  * Protocol:
892
+ * Parent -> iframe: { type: 'athena-config', apiUrl: string, backendUrl: string }
869
893
  * Parent -> iframe: { type: 'athena-auth', token: '<propel-access-token>' }
870
894
  * iframe -> Parent: { type: 'athena-auth-ready' }
871
- *
872
- * Falls back to null when running standalone (no parent window).
873
895
  */
874
- export declare function useParentAuth(): string | null;
896
+ export declare function useParentBridge(): ParentBridgeState;
875
897
 
876
898
  export declare function useQuote(): QuoteContextValue;
877
899
 
package/dist/index.js CHANGED
@@ -16465,24 +16465,60 @@ function isTrustedOrigin(origin) {
16465
16465
  return false;
16466
16466
  }
16467
16467
  }
16468
- function useParentAuth() {
16469
- const [authToken, setAuthToken] = useState(null);
16468
+ const BRIDGE_TIMEOUT_MS = 2e3;
16469
+ function useParentBridge() {
16470
+ const isInIframe = typeof window !== "undefined" && window.parent !== window;
16471
+ const [state, setState] = useState({
16472
+ token: null,
16473
+ apiUrl: null,
16474
+ backendUrl: null,
16475
+ // If not in an iframe, we're ready immediately (standalone mode)
16476
+ ready: !isInIframe
16477
+ });
16470
16478
  const readySignalSent = useRef(false);
16479
+ const configReceived = useRef(false);
16471
16480
  useEffect(() => {
16481
+ if (!isInIframe) return;
16472
16482
  const handler = (event) => {
16473
16483
  if (!isTrustedOrigin(event.origin)) return;
16474
- if (event.data && typeof event.data === "object" && event.data.type === "athena-auth" && typeof event.data.token === "string") {
16475
- setAuthToken(event.data.token);
16484
+ if (!event.data || typeof event.data !== "object") return;
16485
+ if (event.data.type === "athena-config") {
16486
+ configReceived.current = true;
16487
+ setState((prev) => ({
16488
+ ...prev,
16489
+ apiUrl: typeof event.data.apiUrl === "string" ? event.data.apiUrl : prev.apiUrl,
16490
+ backendUrl: typeof event.data.backendUrl === "string" ? event.data.backendUrl : prev.backendUrl,
16491
+ ready: true
16492
+ }));
16493
+ }
16494
+ if (event.data.type === "athena-auth" && typeof event.data.token === "string") {
16495
+ setState((prev) => ({
16496
+ ...prev,
16497
+ token: event.data.token,
16498
+ // If we got a token, we're ready even without config
16499
+ ready: true
16500
+ }));
16476
16501
  }
16477
16502
  };
16478
16503
  window.addEventListener("message", handler);
16479
- if (!readySignalSent.current && window.parent !== window) {
16504
+ if (!readySignalSent.current) {
16480
16505
  window.parent.postMessage({ type: "athena-auth-ready" }, "*");
16481
16506
  readySignalSent.current = true;
16482
16507
  }
16483
- return () => window.removeEventListener("message", handler);
16484
- }, []);
16485
- return authToken;
16508
+ const timer = setTimeout(() => {
16509
+ if (!configReceived.current) {
16510
+ setState((prev) => ({ ...prev, ready: true }));
16511
+ }
16512
+ }, BRIDGE_TIMEOUT_MS);
16513
+ return () => {
16514
+ window.removeEventListener("message", handler);
16515
+ clearTimeout(timer);
16516
+ };
16517
+ }, [isInIframe]);
16518
+ return state;
16519
+ }
16520
+ function useParentAuth() {
16521
+ return useParentBridge().token;
16486
16522
  }
16487
16523
  const { fromThreadMessageLike, getAutoStatus } = INTERNAL;
16488
16524
  const joinExternalMessages = (messages) => {
@@ -24609,15 +24645,19 @@ function AthenaProvider({
24609
24645
  }) {
24610
24646
  const frontendToolNames = useMemo(() => Object.keys(frontendTools), [frontendTools]);
24611
24647
  const themeStyleVars = useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
24612
- const parentAuthToken = useParentAuth();
24613
- const effectiveToken = tokenProp ?? parentAuthToken;
24614
- const effectiveBackendUrl = backendUrl ?? DEFAULT_BACKEND_URL;
24648
+ const bridge = useParentBridge();
24649
+ const effectiveToken = tokenProp ?? bridge.token;
24650
+ const effectiveApiUrl = apiUrl ?? bridge.apiUrl ?? DEFAULT_API_URL;
24651
+ const effectiveBackendUrl = backendUrl ?? bridge.backendUrl ?? DEFAULT_BACKEND_URL;
24652
+ if (!bridge.ready) {
24653
+ return null;
24654
+ }
24615
24655
  let inner;
24616
24656
  if (enableThreadList) {
24617
24657
  inner = /* @__PURE__ */ jsx(
24618
24658
  AthenaWithThreadList,
24619
24659
  {
24620
- apiUrl,
24660
+ apiUrl: effectiveApiUrl,
24621
24661
  backendUrl: effectiveBackendUrl,
24622
24662
  apiKey,
24623
24663
  token: effectiveToken,
@@ -24636,7 +24676,7 @@ function AthenaProvider({
24636
24676
  inner = /* @__PURE__ */ jsx(
24637
24677
  AthenaStandalone,
24638
24678
  {
24639
- apiUrl,
24679
+ apiUrl: effectiveApiUrl,
24640
24680
  backendUrl: effectiveBackendUrl,
24641
24681
  apiKey,
24642
24682
  token: effectiveToken,
@@ -64388,6 +64428,7 @@ export {
64388
64428
  CreateNotebookToolUI,
64389
64429
  CreatePresentationToolUI,
64390
64430
  CreateSheetToolUI,
64431
+ DEFAULT_API_URL,
64391
64432
  DEFAULT_BACKEND_URL,
64392
64433
  EmailSearchToolUI,
64393
64434
  ExpandableSection,
@@ -64435,6 +64476,7 @@ export {
64435
64476
  useFileUpload,
64436
64477
  useMentionSuggestions,
64437
64478
  useParentAuth,
64479
+ useParentBridge,
64438
64480
  useQuote
64439
64481
  };
64440
64482
  //# sourceMappingURL=index.js.map