@athenaintel/react 0.4.0 → 0.4.2
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 +60 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16418,35 +16418,43 @@ function useParentAuth() {
|
|
|
16418
16418
|
const readySignalSent = useRef(false);
|
|
16419
16419
|
useEffect(() => {
|
|
16420
16420
|
const isInIframe = window.parent !== window;
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
|
|
16425
|
-
|
|
16426
|
-
const handler = (event) => {
|
|
16427
|
-
var _a2, _b, _c;
|
|
16428
|
-
console.log("[AthenaAuth] Received PostMessage", {
|
|
16429
|
-
type: (_a2 = event.data) == null ? void 0 : _a2.type,
|
|
16430
|
-
origin: event.origin,
|
|
16431
|
-
isTrusted: isTrustedOrigin(event.origin),
|
|
16432
|
-
hasToken: !!((_b = event.data) == null ? void 0 : _b.token),
|
|
16433
|
-
tokenPrefix: typeof ((_c = event.data) == null ? void 0 : _c.token) === "string" ? event.data.token.substring(0, 20) + "..." : void 0
|
|
16421
|
+
if (process.env.NODE_ENV !== "production") {
|
|
16422
|
+
console.log("[AthenaAuth] useParentAuth mounted", {
|
|
16423
|
+
isInIframe,
|
|
16424
|
+
currentOrigin: window.location.origin,
|
|
16425
|
+
currentUrl: window.location.href
|
|
16434
16426
|
});
|
|
16427
|
+
}
|
|
16428
|
+
const handler = (event) => {
|
|
16429
|
+
var _a2;
|
|
16430
|
+
if (process.env.NODE_ENV !== "production") {
|
|
16431
|
+
console.log("[AthenaAuth] Received PostMessage", {
|
|
16432
|
+
type: (_a2 = event.data) == null ? void 0 : _a2.type,
|
|
16433
|
+
origin: event.origin,
|
|
16434
|
+
isTrusted: isTrustedOrigin(event.origin)
|
|
16435
|
+
});
|
|
16436
|
+
}
|
|
16435
16437
|
if (!isTrustedOrigin(event.origin)) {
|
|
16436
|
-
|
|
16438
|
+
if (process.env.NODE_ENV !== "production") {
|
|
16439
|
+
console.warn("[AthenaAuth] Rejected PostMessage — untrusted origin:", event.origin);
|
|
16440
|
+
}
|
|
16437
16441
|
return;
|
|
16438
16442
|
}
|
|
16439
16443
|
if (event.data && typeof event.data === "object" && event.data.type === "athena-auth" && typeof event.data.token === "string") {
|
|
16440
|
-
|
|
16444
|
+
if (process.env.NODE_ENV !== "production") {
|
|
16445
|
+
console.log("[AthenaAuth] PropelAuth token received via PostMessage, length:", event.data.token.length);
|
|
16446
|
+
}
|
|
16441
16447
|
setAuthToken(event.data.token);
|
|
16442
16448
|
}
|
|
16443
16449
|
};
|
|
16444
16450
|
window.addEventListener("message", handler);
|
|
16445
16451
|
if (!readySignalSent.current && isInIframe) {
|
|
16446
|
-
|
|
16452
|
+
if (process.env.NODE_ENV !== "production") {
|
|
16453
|
+
console.log("[AthenaAuth] Sending athena-auth-ready signal to parent");
|
|
16454
|
+
}
|
|
16447
16455
|
window.parent.postMessage({ type: "athena-auth-ready" }, "*");
|
|
16448
16456
|
readySignalSent.current = true;
|
|
16449
|
-
} else if (!isInIframe) {
|
|
16457
|
+
} else if (!isInIframe && process.env.NODE_ENV !== "production") {
|
|
16450
16458
|
console.log("[AthenaAuth] Not in iframe — skipping parent auth (standalone mode)");
|
|
16451
16459
|
}
|
|
16452
16460
|
return () => window.removeEventListener("message", handler);
|
|
@@ -20773,13 +20781,15 @@ const useAthenaRuntime = (config2) => {
|
|
|
20773
20781
|
api: apiUrl,
|
|
20774
20782
|
headers: async () => {
|
|
20775
20783
|
const authHeaders = tokenRef.current ? { Authorization: `Bearer ${tokenRef.current}` } : apiKeyRef.current ? { "X-API-KEY": apiKeyRef.current } : {};
|
|
20776
|
-
|
|
20777
|
-
|
|
20778
|
-
|
|
20779
|
-
|
|
20780
|
-
|
|
20781
|
-
|
|
20782
|
-
|
|
20784
|
+
if (process.env.NODE_ENV !== "production") {
|
|
20785
|
+
console.log("[AthenaAuth] Request headers", {
|
|
20786
|
+
authMethod: tokenRef.current ? "Bearer token" : apiKeyRef.current ? "X-API-KEY" : "NONE",
|
|
20787
|
+
hasToken: !!tokenRef.current,
|
|
20788
|
+
tokenPrefix: tokenRef.current ? tokenRef.current.substring(0, 20) + "..." : void 0,
|
|
20789
|
+
apiKeyPrefix: apiKeyRef.current ? apiKeyRef.current.substring(0, 10) + "..." : void 0,
|
|
20790
|
+
apiUrl
|
|
20791
|
+
});
|
|
20792
|
+
}
|
|
20783
20793
|
return {
|
|
20784
20794
|
// Prefer parent-injected PropelAuth token over hardcoded API key
|
|
20785
20795
|
...authHeaders,
|
|
@@ -24143,7 +24153,7 @@ function getAgoraBaseUrl(backendUrl) {
|
|
|
24143
24153
|
}
|
|
24144
24154
|
async function listThreads(backendUrl, auth, opts = {}) {
|
|
24145
24155
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24146
|
-
const res = await fetch(`${base2}/api/
|
|
24156
|
+
const res = await fetch(`${base2}/api/conversations/threads/list`, {
|
|
24147
24157
|
method: "POST",
|
|
24148
24158
|
headers: { "Content-Type": "application/json", ...getAuthHeaders(auth) },
|
|
24149
24159
|
body: JSON.stringify({ limit: opts.limit ?? 50, offset: opts.offset ?? 0 })
|
|
@@ -24155,7 +24165,7 @@ async function listThreads(backendUrl, auth, opts = {}) {
|
|
|
24155
24165
|
}
|
|
24156
24166
|
async function archiveThread(backendUrl, auth, threadId) {
|
|
24157
24167
|
const base2 = getAgoraBaseUrl(backendUrl);
|
|
24158
|
-
const res = await fetch(`${base2}/api/
|
|
24168
|
+
const res = await fetch(`${base2}/api/conversations/threads/archive`, {
|
|
24159
24169
|
method: "POST",
|
|
24160
24170
|
headers: { "Content-Type": "application/json", ...getAuthHeaders(auth) },
|
|
24161
24171
|
body: JSON.stringify({ thread_id: threadId })
|
|
@@ -24184,6 +24194,9 @@ function createThreadListStore(config2) {
|
|
|
24184
24194
|
}
|
|
24185
24195
|
},
|
|
24186
24196
|
switchThread: (threadId) => {
|
|
24197
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24198
|
+
console.log("[AthenaThreads] switchThread called", { threadId, prev: get2().activeThreadId });
|
|
24199
|
+
}
|
|
24187
24200
|
set2({ activeThreadId: threadId });
|
|
24188
24201
|
},
|
|
24189
24202
|
newThread: async () => {
|
|
@@ -24276,6 +24289,17 @@ function AthenaProvider({
|
|
|
24276
24289
|
const parentAuthToken = useParentAuth();
|
|
24277
24290
|
const effectiveToken = tokenProp ?? parentAuthToken;
|
|
24278
24291
|
const effectiveBackendUrl = backendUrl ?? DEFAULT_BACKEND_URL;
|
|
24292
|
+
useEffect(() => {
|
|
24293
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24294
|
+
console.log("[AthenaAuth] AthenaProvider auth state", {
|
|
24295
|
+
hasTokenProp: !!tokenProp,
|
|
24296
|
+
hasParentAuthToken: !!parentAuthToken,
|
|
24297
|
+
hasEffectiveToken: !!effectiveToken,
|
|
24298
|
+
hasApiKey: !!apiKey,
|
|
24299
|
+
authMethod: effectiveToken ? "Bearer token (PropelAuth)" : apiKey ? "X-API-KEY" : "NONE"
|
|
24300
|
+
});
|
|
24301
|
+
}
|
|
24302
|
+
}, [tokenProp, parentAuthToken, effectiveToken, apiKey]);
|
|
24279
24303
|
const threadListStoreRef = useRef(null);
|
|
24280
24304
|
if (enableThreadList && !threadListStoreRef.current) {
|
|
24281
24305
|
threadListStoreRef.current = createThreadListStore({
|
|
@@ -24288,6 +24312,16 @@ function AthenaProvider({
|
|
|
24288
24312
|
enableThreadList ? threadListStoreRef.current : null
|
|
24289
24313
|
);
|
|
24290
24314
|
const resolvedThreadId = threadIdProp ?? activeThreadId ?? void 0;
|
|
24315
|
+
useEffect(() => {
|
|
24316
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24317
|
+
console.log("[AthenaThreads] AthenaProvider render", {
|
|
24318
|
+
activeThreadId,
|
|
24319
|
+
resolvedThreadId,
|
|
24320
|
+
enableThreadList,
|
|
24321
|
+
hasStore: !!threadListStoreRef.current
|
|
24322
|
+
});
|
|
24323
|
+
}
|
|
24324
|
+
}, [activeThreadId, resolvedThreadId, enableThreadList]);
|
|
24291
24325
|
const inner = /* @__PURE__ */ jsx(
|
|
24292
24326
|
AthenaRuntimeInner,
|
|
24293
24327
|
{
|