@howone/sdk 0.5.1 → 0.5.3

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.mjs CHANGED
@@ -69,16 +69,19 @@ var init_config = __esm({
69
69
  env = "dev";
70
70
  localEnv = {
71
71
  AUTH_ROOT_VALUE: "https://howone.dev",
72
+ AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
72
73
  baseUrl: "http://localhost:3002/api",
73
74
  aiBaseUrl: "https://evoagentx-server.fly.dev"
74
75
  };
75
76
  devEnv = {
76
77
  AUTH_ROOT_VALUE: "https://howone.dev",
78
+ AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
77
79
  baseUrl: "https://api.howone.dev/api",
78
80
  aiBaseUrl: "https://evoagentx-server-stable.fly.dev"
79
81
  };
80
82
  prodEnv = {
81
83
  AUTH_ROOT_VALUE: "https://howone.ai",
84
+ AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
82
85
  baseUrl: "https://api.howone.ai/api",
83
86
  aiBaseUrl: "https://eax.services"
84
87
  };
@@ -202,6 +205,13 @@ function useAuth() {
202
205
  setTokenState(null);
203
206
  setUser(null);
204
207
  notifyAuthStateChanged();
208
+ try {
209
+ fetch(`${env2.AUTH_COOKIE_ROOT_VALUE}/logout`, {
210
+ method: "POST",
211
+ credentials: "include"
212
+ }).catch(() => void 0);
213
+ } catch {
214
+ }
205
215
  if (typeof window !== "undefined") {
206
216
  const loc = window.location.href;
207
217
  const pid = getDefaultProjectId();
@@ -1251,6 +1261,7 @@ var ElementSelectorProvider = ({ children }) => {
1251
1261
  init_config();
1252
1262
  import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1253
1263
  var HowoneContext = createContext2(null);
1264
+ var consumedTokenCache = /* @__PURE__ */ new Set();
1254
1265
  var redirectOverlayStylesInjected = false;
1255
1266
  var injectRedirectOverlayStyles = () => {
1256
1267
  if (redirectOverlayStylesInjected || typeof document === "undefined") return;
@@ -1314,6 +1325,63 @@ var HowOneProvider = ({
1314
1325
  const [token, setTokenState] = useState7(() => getToken());
1315
1326
  const [hasCheckedUrlToken, setHasCheckedUrlToken] = useState7(false);
1316
1327
  const [pendingRedirect, setPendingRedirect] = useState7(false);
1328
+ const authCookieRoot = useMemo(() => {
1329
+ const env3 = getGlobalEnvironment() ?? "dev";
1330
+ return setEnvironment(env3).AUTH_COOKIE_ROOT_VALUE;
1331
+ }, []);
1332
+ const consumeTokenToCookie = useCallback4(async (value2) => {
1333
+ if (!value2) return;
1334
+ if (consumedTokenCache.has(value2)) return;
1335
+ consumedTokenCache.add(value2);
1336
+ try {
1337
+ const response = await fetch(`${authCookieRoot}/consume`, {
1338
+ method: "POST",
1339
+ credentials: "include",
1340
+ headers: {
1341
+ Authorization: `Bearer ${value2}`
1342
+ }
1343
+ });
1344
+ if (!response.ok) {
1345
+ console.info("[HowOneProvider] consume token request failed:", response.status, response.statusText);
1346
+ }
1347
+ } catch (error) {
1348
+ try {
1349
+ const inIframe = typeof window !== "undefined" && window.top !== window.self;
1350
+ if (inIframe) {
1351
+ console.info("[HowOneProvider] consume token skipped in iframe context (likely third-party cookie/CORS policy).");
1352
+ return;
1353
+ }
1354
+ } catch {
1355
+ }
1356
+ console.warn("[HowOneProvider] Failed to consume token:", error);
1357
+ }
1358
+ }, [authCookieRoot]);
1359
+ const logoutFromCookie = useCallback4(async () => {
1360
+ try {
1361
+ await fetch(`${authCookieRoot}/logout`, {
1362
+ method: "POST",
1363
+ credentials: "include"
1364
+ });
1365
+ } catch (error) {
1366
+ console.warn("[HowOneProvider] Failed to logout from cookie:", error);
1367
+ }
1368
+ }, [authCookieRoot]);
1369
+ const readAccessTokenCookie = useCallback4(() => {
1370
+ if (typeof document === "undefined") return null;
1371
+ try {
1372
+ const parts = document.cookie.split("; ");
1373
+ for (const part of parts) {
1374
+ const [key, ...rest] = part.split("=");
1375
+ if (key === "access_token") {
1376
+ const raw = rest.join("=");
1377
+ return raw ? decodeURIComponent(raw) : null;
1378
+ }
1379
+ }
1380
+ } catch {
1381
+ return null;
1382
+ }
1383
+ return null;
1384
+ }, []);
1317
1385
  useEffect6(() => {
1318
1386
  try {
1319
1387
  const params = new URLSearchParams(window.location.search);
@@ -1322,10 +1390,11 @@ var HowOneProvider = ({
1322
1390
  const hashParams = new URLSearchParams(window.location.hash.slice(1));
1323
1391
  urlToken = hashParams.get("access_token") || hashParams.get("token");
1324
1392
  }
1325
- if (urlToken) {
1393
+ if (urlToken && isTokenValid(urlToken)) {
1326
1394
  setToken(urlToken);
1327
1395
  setTokenState(urlToken);
1328
1396
  setUser(parseUserFromToken(urlToken));
1397
+ void consumeTokenToCookie(urlToken);
1329
1398
  params.delete("access_token");
1330
1399
  params.delete("token");
1331
1400
  params.delete("project_id");
@@ -1333,12 +1402,20 @@ var HowOneProvider = ({
1333
1402
  const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
1334
1403
  window.history.replaceState({}, "", newUrl);
1335
1404
  }
1405
+ if (!urlToken) {
1406
+ const cookieToken = readAccessTokenCookie();
1407
+ if (cookieToken && isTokenValid(cookieToken)) {
1408
+ setToken(cookieToken);
1409
+ setTokenState(cookieToken);
1410
+ setUser(parseUserFromToken(cookieToken));
1411
+ }
1412
+ }
1336
1413
  } catch (e) {
1337
- console.error("[HowOneProvider] Failed to capture token from URL:", e);
1414
+ console.warn("[HowOneProvider] Failed to capture token from URL:", e);
1338
1415
  } finally {
1339
1416
  setHasCheckedUrlToken(true);
1340
1417
  }
1341
- }, []);
1418
+ }, [consumeTokenToCookie, readAccessTokenCookie]);
1342
1419
  const resolvedAuthUrl = useMemo(() => {
1343
1420
  const env3 = getGlobalEnvironment() ?? "dev";
1344
1421
  switch (env3) {
@@ -1356,11 +1433,6 @@ var HowOneProvider = ({
1356
1433
  injectRedirectOverlayStyles();
1357
1434
  }
1358
1435
  }, [pendingRedirect]);
1359
- useEffect6(() => {
1360
- if (pendingRedirect) {
1361
- injectRedirectOverlayStyles();
1362
- }
1363
- }, [pendingRedirect]);
1364
1436
  const redirectToAuth = useCallback4(() => {
1365
1437
  if (!redirectOnUnauthenticated || typeof window === "undefined") return;
1366
1438
  const activeProjectId = projectId ?? getDefaultProjectId();
@@ -1375,7 +1447,7 @@ var HowOneProvider = ({
1375
1447
  window.location.href = url.toString();
1376
1448
  return;
1377
1449
  } catch (error) {
1378
- console.error("[HowOneProvider] Failed to attach project_id to auth URL:", error);
1450
+ console.warn("[HowOneProvider] Failed to attach project_id to auth URL:", error);
1379
1451
  }
1380
1452
  }
1381
1453
  window.location.href = resolvedAuthUrl;
@@ -1396,7 +1468,7 @@ var HowOneProvider = ({
1396
1468
  });
1397
1469
  return;
1398
1470
  } catch (error) {
1399
- console.error("[HowOneProvider] Failed to build auth URL:", error);
1471
+ console.warn("[HowOneProvider] Failed to build auth URL:", error);
1400
1472
  }
1401
1473
  navigateToResolvedAuth();
1402
1474
  } catch {
@@ -1416,6 +1488,7 @@ var HowOneProvider = ({
1416
1488
  }
1417
1489
  setTokenState(null);
1418
1490
  setUser(null);
1491
+ void logoutFromCookie();
1419
1492
  redirectToAuth();
1420
1493
  };
1421
1494
  const value = {
@@ -2274,6 +2347,7 @@ var Request = class {
2274
2347
  this.abortControllers = /* @__PURE__ */ new Map();
2275
2348
  this.instance = axios.create({
2276
2349
  ...config,
2350
+ withCredentials: true,
2277
2351
  validateStatus: (status) => {
2278
2352
  return status >= 200 && status < 300;
2279
2353
  }
@@ -2650,6 +2724,17 @@ async function executeSSEWorkflow(request, options = {}) {
2650
2724
  options.onStreamContent(logData.delta);
2651
2725
  }
2652
2726
  }
2727
+ if (rawEvent.type === "execution_error" && rawEvent.data) {
2728
+ const errorData = rawEvent.data;
2729
+ if (errorData.log_type === "execution_display_error") {
2730
+ const errorContent = errorData.content;
2731
+ const displayMessage = errorContent || "Workflow execution failed";
2732
+ ClayxToast.error({
2733
+ title: "Execution Error",
2734
+ message: displayMessage
2735
+ });
2736
+ }
2737
+ }
2653
2738
  if (rawEvent.type === "stream" && rawEvent.delta && options.onStreamContent) {
2654
2739
  options.onStreamContent(rawEvent.delta);
2655
2740
  }
@@ -3715,6 +3800,13 @@ function createClient(opts) {
3715
3800
  applyToken(null);
3716
3801
  rememberExternalToken(null, 0);
3717
3802
  pendingExternalTokenPromise = null;
3803
+ try {
3804
+ fetch(`${env3.AUTH_COOKIE_ROOT_VALUE}/logout`, {
3805
+ method: "POST",
3806
+ credentials: "include"
3807
+ }).catch(() => void 0);
3808
+ } catch {
3809
+ }
3718
3810
  if (typeof window !== "undefined") {
3719
3811
  const loc = window.location.href;
3720
3812
  try {