@athenaintel/react 0.7.3 → 0.9.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.cjs CHANGED
@@ -16483,24 +16483,60 @@ function isTrustedOrigin(origin) {
16483
16483
  return false;
16484
16484
  }
16485
16485
  }
16486
- function useParentAuth() {
16487
- const [authToken, setAuthToken] = React.useState(null);
16486
+ const BRIDGE_TIMEOUT_MS = 2e3;
16487
+ function useParentBridge() {
16488
+ const isInIframe = typeof window !== "undefined" && window.parent !== window;
16489
+ const [state, setState] = React.useState({
16490
+ token: null,
16491
+ apiUrl: null,
16492
+ backendUrl: null,
16493
+ // If not in an iframe, we're ready immediately (standalone mode)
16494
+ ready: !isInIframe
16495
+ });
16488
16496
  const readySignalSent = React.useRef(false);
16497
+ const configReceived = React.useRef(false);
16489
16498
  React.useEffect(() => {
16499
+ if (!isInIframe) return;
16490
16500
  const handler = (event) => {
16491
16501
  if (!isTrustedOrigin(event.origin)) return;
16492
- if (event.data && typeof event.data === "object" && event.data.type === "athena-auth" && typeof event.data.token === "string") {
16493
- setAuthToken(event.data.token);
16502
+ if (!event.data || typeof event.data !== "object") return;
16503
+ if (event.data.type === "athena-config") {
16504
+ configReceived.current = true;
16505
+ setState((prev) => ({
16506
+ ...prev,
16507
+ apiUrl: typeof event.data.apiUrl === "string" ? event.data.apiUrl : prev.apiUrl,
16508
+ backendUrl: typeof event.data.backendUrl === "string" ? event.data.backendUrl : prev.backendUrl,
16509
+ ready: true
16510
+ }));
16511
+ }
16512
+ if (event.data.type === "athena-auth" && typeof event.data.token === "string") {
16513
+ setState((prev) => ({
16514
+ ...prev,
16515
+ token: event.data.token,
16516
+ // If we got a token, we're ready even without config
16517
+ ready: true
16518
+ }));
16494
16519
  }
16495
16520
  };
16496
16521
  window.addEventListener("message", handler);
16497
- if (!readySignalSent.current && window.parent !== window) {
16522
+ if (!readySignalSent.current) {
16498
16523
  window.parent.postMessage({ type: "athena-auth-ready" }, "*");
16499
16524
  readySignalSent.current = true;
16500
16525
  }
16501
- return () => window.removeEventListener("message", handler);
16502
- }, []);
16503
- return authToken;
16526
+ const timer = setTimeout(() => {
16527
+ if (!configReceived.current) {
16528
+ setState((prev) => ({ ...prev, ready: true }));
16529
+ }
16530
+ }, BRIDGE_TIMEOUT_MS);
16531
+ return () => {
16532
+ window.removeEventListener("message", handler);
16533
+ clearTimeout(timer);
16534
+ };
16535
+ }, [isInIframe]);
16536
+ return state;
16537
+ }
16538
+ function useParentAuth() {
16539
+ return useParentBridge().token;
16504
16540
  }
16505
16541
  const { fromThreadMessageLike, getAutoStatus } = INTERNAL;
16506
16542
  const joinExternalMessages = (messages) => {
@@ -24339,14 +24375,19 @@ const THEME_TO_CSS = {
24339
24375
  input: "--input",
24340
24376
  ring: "--ring",
24341
24377
  radius: "--radius",
24378
+ fontFamily: "--font-family",
24342
24379
  // Extended SDK-specific variables
24343
24380
  sidebarBackground: "--sidebar-background",
24344
24381
  sidebarBorder: "--sidebar-border",
24382
+ sidebarWidth: "--sidebar-width",
24345
24383
  userBubble: "--user-bubble",
24346
24384
  userBubbleForeground: "--user-bubble-foreground",
24385
+ userBubbleRadius: "--user-bubble-radius",
24347
24386
  assistantForeground: "--assistant-foreground",
24387
+ assistantBubble: "--assistant-bubble",
24348
24388
  composerBorder: "--composer-border",
24349
- composerRadius: "--composer-radius"
24389
+ composerRadius: "--composer-radius",
24390
+ threadMaxWidth: "--thread-max-width"
24350
24391
  };
24351
24392
  function themeToStyleVars(theme) {
24352
24393
  const vars = {};
@@ -24627,15 +24668,19 @@ function AthenaProvider({
24627
24668
  }) {
24628
24669
  const frontendToolNames = React.useMemo(() => Object.keys(frontendTools), [frontendTools]);
24629
24670
  const themeStyleVars = React.useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
24630
- const parentAuthToken = useParentAuth();
24631
- const effectiveToken = tokenProp ?? parentAuthToken;
24632
- const effectiveBackendUrl = backendUrl ?? DEFAULT_BACKEND_URL;
24671
+ const bridge = useParentBridge();
24672
+ const effectiveToken = tokenProp ?? bridge.token;
24673
+ const effectiveApiUrl = apiUrl ?? bridge.apiUrl ?? DEFAULT_API_URL;
24674
+ const effectiveBackendUrl = backendUrl ?? bridge.backendUrl ?? DEFAULT_BACKEND_URL;
24675
+ if (!bridge.ready) {
24676
+ return null;
24677
+ }
24633
24678
  let inner;
24634
24679
  if (enableThreadList) {
24635
24680
  inner = /* @__PURE__ */ jsxRuntime.jsx(
24636
24681
  AthenaWithThreadList,
24637
24682
  {
24638
- apiUrl,
24683
+ apiUrl: effectiveApiUrl,
24639
24684
  backendUrl: effectiveBackendUrl,
24640
24685
  apiKey,
24641
24686
  token: effectiveToken,
@@ -24654,7 +24699,7 @@ function AthenaProvider({
24654
24699
  inner = /* @__PURE__ */ jsxRuntime.jsx(
24655
24700
  AthenaStandalone,
24656
24701
  {
24657
- apiUrl,
24702
+ apiUrl: effectiveApiUrl,
24658
24703
  backendUrl: effectiveBackendUrl,
24659
24704
  apiKey,
24660
24705
  token: effectiveToken,
@@ -64405,6 +64450,7 @@ exports.CreateEmailDraftToolUI = CreateEmailDraftToolUI;
64405
64450
  exports.CreateNotebookToolUI = CreateNotebookToolUI;
64406
64451
  exports.CreatePresentationToolUI = CreatePresentationToolUI;
64407
64452
  exports.CreateSheetToolUI = CreateSheetToolUI;
64453
+ exports.DEFAULT_API_URL = DEFAULT_API_URL;
64408
64454
  exports.DEFAULT_BACKEND_URL = DEFAULT_BACKEND_URL;
64409
64455
  exports.EmailSearchToolUI = EmailSearchToolUI;
64410
64456
  exports.ExpandableSection = ExpandableSection;
@@ -64452,5 +64498,6 @@ exports.useComposerAttachment = useComposerAttachment;
64452
64498
  exports.useFileUpload = useFileUpload;
64453
64499
  exports.useMentionSuggestions = useMentionSuggestions;
64454
64500
  exports.useParentAuth = useParentAuth;
64501
+ exports.useParentBridge = useParentBridge;
64455
64502
  exports.useQuote = useQuote;
64456
64503
  //# sourceMappingURL=index.cjs.map