@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.cjs +55 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -8
- package/dist/index.js +55 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -16483,24 +16483,60 @@ function isTrustedOrigin(origin) {
|
|
|
16483
16483
|
return false;
|
|
16484
16484
|
}
|
|
16485
16485
|
}
|
|
16486
|
-
|
|
16487
|
-
|
|
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
|
|
16493
|
-
|
|
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
|
|
16522
|
+
if (!readySignalSent.current) {
|
|
16498
16523
|
window.parent.postMessage({ type: "athena-auth-ready" }, "*");
|
|
16499
16524
|
readySignalSent.current = true;
|
|
16500
16525
|
}
|
|
16501
|
-
|
|
16502
|
-
|
|
16503
|
-
|
|
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) => {
|
|
@@ -24627,15 +24663,19 @@ function AthenaProvider({
|
|
|
24627
24663
|
}) {
|
|
24628
24664
|
const frontendToolNames = React.useMemo(() => Object.keys(frontendTools), [frontendTools]);
|
|
24629
24665
|
const themeStyleVars = React.useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
|
|
24630
|
-
const
|
|
24631
|
-
const effectiveToken = tokenProp ??
|
|
24632
|
-
const
|
|
24666
|
+
const bridge = useParentBridge();
|
|
24667
|
+
const effectiveToken = tokenProp ?? bridge.token;
|
|
24668
|
+
const effectiveApiUrl = apiUrl ?? bridge.apiUrl ?? DEFAULT_API_URL;
|
|
24669
|
+
const effectiveBackendUrl = backendUrl ?? bridge.backendUrl ?? DEFAULT_BACKEND_URL;
|
|
24670
|
+
if (!bridge.ready) {
|
|
24671
|
+
return null;
|
|
24672
|
+
}
|
|
24633
24673
|
let inner;
|
|
24634
24674
|
if (enableThreadList) {
|
|
24635
24675
|
inner = /* @__PURE__ */ jsxRuntime.jsx(
|
|
24636
24676
|
AthenaWithThreadList,
|
|
24637
24677
|
{
|
|
24638
|
-
apiUrl,
|
|
24678
|
+
apiUrl: effectiveApiUrl,
|
|
24639
24679
|
backendUrl: effectiveBackendUrl,
|
|
24640
24680
|
apiKey,
|
|
24641
24681
|
token: effectiveToken,
|
|
@@ -24654,7 +24694,7 @@ function AthenaProvider({
|
|
|
24654
24694
|
inner = /* @__PURE__ */ jsxRuntime.jsx(
|
|
24655
24695
|
AthenaStandalone,
|
|
24656
24696
|
{
|
|
24657
|
-
apiUrl,
|
|
24697
|
+
apiUrl: effectiveApiUrl,
|
|
24658
24698
|
backendUrl: effectiveBackendUrl,
|
|
24659
24699
|
apiKey,
|
|
24660
24700
|
token: effectiveToken,
|
|
@@ -64405,6 +64445,7 @@ exports.CreateEmailDraftToolUI = CreateEmailDraftToolUI;
|
|
|
64405
64445
|
exports.CreateNotebookToolUI = CreateNotebookToolUI;
|
|
64406
64446
|
exports.CreatePresentationToolUI = CreatePresentationToolUI;
|
|
64407
64447
|
exports.CreateSheetToolUI = CreateSheetToolUI;
|
|
64448
|
+
exports.DEFAULT_API_URL = DEFAULT_API_URL;
|
|
64408
64449
|
exports.DEFAULT_BACKEND_URL = DEFAULT_BACKEND_URL;
|
|
64409
64450
|
exports.EmailSearchToolUI = EmailSearchToolUI;
|
|
64410
64451
|
exports.ExpandableSection = ExpandableSection;
|
|
@@ -64452,5 +64493,6 @@ exports.useComposerAttachment = useComposerAttachment;
|
|
|
64452
64493
|
exports.useFileUpload = useFileUpload;
|
|
64453
64494
|
exports.useMentionSuggestions = useMentionSuggestions;
|
|
64454
64495
|
exports.useParentAuth = useParentAuth;
|
|
64496
|
+
exports.useParentBridge = useParentBridge;
|
|
64455
64497
|
exports.useQuote = useQuote;
|
|
64456
64498
|
//# sourceMappingURL=index.cjs.map
|