@howone/sdk 0.5.0 → 0.5.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.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +86 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -577,6 +577,7 @@ declare function onAuthStateChanged(cb: (state: AuthState$1) => void): () => voi
|
|
|
577
577
|
type Environment = 'local' | 'dev' | 'prod';
|
|
578
578
|
type envs = {
|
|
579
579
|
AUTH_ROOT_VALUE: string;
|
|
580
|
+
AUTH_COOKIE_ROOT_VALUE: string;
|
|
580
581
|
baseUrl: string;
|
|
581
582
|
aiBaseUrl: string;
|
|
582
583
|
};
|
|
@@ -1038,7 +1039,7 @@ type HowoneContextValue = {
|
|
|
1038
1039
|
interface HowOneProviderProps {
|
|
1039
1040
|
children: React$1.ReactNode;
|
|
1040
1041
|
autoRedirect?: boolean;
|
|
1041
|
-
|
|
1042
|
+
showHowOneFlag?: boolean;
|
|
1042
1043
|
projectId?: string;
|
|
1043
1044
|
defaultTheme?: Theme$1;
|
|
1044
1045
|
themeStorageKey?: string;
|
|
@@ -1059,7 +1060,7 @@ interface HowOneProviderProps {
|
|
|
1059
1060
|
* <HowOneProvider
|
|
1060
1061
|
* defaultTheme="dark"
|
|
1061
1062
|
* themeStorageKey="my-app-theme"
|
|
1062
|
-
*
|
|
1063
|
+
* showHowOneFlag={true}
|
|
1063
1064
|
* redirectOnUnauthenticated={true}
|
|
1064
1065
|
* >
|
|
1065
1066
|
* <App />
|
package/dist/index.d.ts
CHANGED
|
@@ -577,6 +577,7 @@ declare function onAuthStateChanged(cb: (state: AuthState$1) => void): () => voi
|
|
|
577
577
|
type Environment = 'local' | 'dev' | 'prod';
|
|
578
578
|
type envs = {
|
|
579
579
|
AUTH_ROOT_VALUE: string;
|
|
580
|
+
AUTH_COOKIE_ROOT_VALUE: string;
|
|
580
581
|
baseUrl: string;
|
|
581
582
|
aiBaseUrl: string;
|
|
582
583
|
};
|
|
@@ -1038,7 +1039,7 @@ type HowoneContextValue = {
|
|
|
1038
1039
|
interface HowOneProviderProps {
|
|
1039
1040
|
children: React$1.ReactNode;
|
|
1040
1041
|
autoRedirect?: boolean;
|
|
1041
|
-
|
|
1042
|
+
showHowOneFlag?: boolean;
|
|
1042
1043
|
projectId?: string;
|
|
1043
1044
|
defaultTheme?: Theme$1;
|
|
1044
1045
|
themeStorageKey?: string;
|
|
@@ -1059,7 +1060,7 @@ interface HowOneProviderProps {
|
|
|
1059
1060
|
* <HowOneProvider
|
|
1060
1061
|
* defaultTheme="dark"
|
|
1061
1062
|
* themeStorageKey="my-app-theme"
|
|
1062
|
-
*
|
|
1063
|
+
* showHowOneFlag={true}
|
|
1063
1064
|
* redirectOnUnauthenticated={true}
|
|
1064
1065
|
* >
|
|
1065
1066
|
* <App />
|
package/dist/index.js
CHANGED
|
@@ -80,16 +80,19 @@ var init_config = __esm({
|
|
|
80
80
|
env = "dev";
|
|
81
81
|
localEnv = {
|
|
82
82
|
AUTH_ROOT_VALUE: "https://howone.dev",
|
|
83
|
+
AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
|
|
83
84
|
baseUrl: "http://localhost:3002/api",
|
|
84
85
|
aiBaseUrl: "https://evoagentx-server.fly.dev"
|
|
85
86
|
};
|
|
86
87
|
devEnv = {
|
|
87
88
|
AUTH_ROOT_VALUE: "https://howone.dev",
|
|
89
|
+
AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
|
|
88
90
|
baseUrl: "https://api.howone.dev/api",
|
|
89
91
|
aiBaseUrl: "https://evoagentx-server-stable.fly.dev"
|
|
90
92
|
};
|
|
91
93
|
prodEnv = {
|
|
92
94
|
AUTH_ROOT_VALUE: "https://howone.ai",
|
|
95
|
+
AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
|
|
93
96
|
baseUrl: "https://api.howone.ai/api",
|
|
94
97
|
aiBaseUrl: "https://eax.services"
|
|
95
98
|
};
|
|
@@ -212,6 +215,13 @@ function useAuth() {
|
|
|
212
215
|
setTokenState(null);
|
|
213
216
|
setUser(null);
|
|
214
217
|
notifyAuthStateChanged();
|
|
218
|
+
try {
|
|
219
|
+
fetch(`${env2.AUTH_COOKIE_ROOT_VALUE}/logout`, {
|
|
220
|
+
method: "POST",
|
|
221
|
+
credentials: "include"
|
|
222
|
+
}).catch(() => void 0);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
215
225
|
if (typeof window !== "undefined") {
|
|
216
226
|
const loc = window.location.href;
|
|
217
227
|
const pid = getDefaultProjectId();
|
|
@@ -1374,7 +1384,7 @@ var injectRedirectOverlayStyles = () => {
|
|
|
1374
1384
|
};
|
|
1375
1385
|
var HowOneProvider = ({
|
|
1376
1386
|
children,
|
|
1377
|
-
|
|
1387
|
+
showHowOneFlag = true,
|
|
1378
1388
|
projectId,
|
|
1379
1389
|
defaultTheme = "system",
|
|
1380
1390
|
themeStorageKey = "howone-theme",
|
|
@@ -1385,6 +1395,49 @@ var HowOneProvider = ({
|
|
|
1385
1395
|
const [token, setTokenState] = (0, import_react8.useState)(() => getToken());
|
|
1386
1396
|
const [hasCheckedUrlToken, setHasCheckedUrlToken] = (0, import_react8.useState)(false);
|
|
1387
1397
|
const [pendingRedirect, setPendingRedirect] = (0, import_react8.useState)(false);
|
|
1398
|
+
const authCookieRoot = (0, import_react8.useMemo)(() => {
|
|
1399
|
+
const env3 = getGlobalEnvironment() ?? "dev";
|
|
1400
|
+
return setEnvironment(env3).AUTH_COOKIE_ROOT_VALUE;
|
|
1401
|
+
}, []);
|
|
1402
|
+
const consumeTokenToCookie = (0, import_react8.useCallback)(async (value2) => {
|
|
1403
|
+
try {
|
|
1404
|
+
await fetch(`${authCookieRoot}/consume`, {
|
|
1405
|
+
method: "POST",
|
|
1406
|
+
credentials: "include",
|
|
1407
|
+
headers: {
|
|
1408
|
+
Authorization: `Bearer ${value2}`
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
console.error("[HowOneProvider] Failed to consume token:", error);
|
|
1413
|
+
}
|
|
1414
|
+
}, [authCookieRoot]);
|
|
1415
|
+
const logoutFromCookie = (0, import_react8.useCallback)(async () => {
|
|
1416
|
+
try {
|
|
1417
|
+
await fetch(`${authCookieRoot}/logout`, {
|
|
1418
|
+
method: "POST",
|
|
1419
|
+
credentials: "include"
|
|
1420
|
+
});
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
console.error("[HowOneProvider] Failed to logout from cookie:", error);
|
|
1423
|
+
}
|
|
1424
|
+
}, [authCookieRoot]);
|
|
1425
|
+
const readAccessTokenCookie = (0, import_react8.useCallback)(() => {
|
|
1426
|
+
if (typeof document === "undefined") return null;
|
|
1427
|
+
try {
|
|
1428
|
+
const parts = document.cookie.split("; ");
|
|
1429
|
+
for (const part of parts) {
|
|
1430
|
+
const [key, ...rest] = part.split("=");
|
|
1431
|
+
if (key === "access_token") {
|
|
1432
|
+
const raw = rest.join("=");
|
|
1433
|
+
return raw ? decodeURIComponent(raw) : null;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
} catch {
|
|
1437
|
+
return null;
|
|
1438
|
+
}
|
|
1439
|
+
return null;
|
|
1440
|
+
}, []);
|
|
1388
1441
|
(0, import_react8.useEffect)(() => {
|
|
1389
1442
|
try {
|
|
1390
1443
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -1393,10 +1446,11 @@ var HowOneProvider = ({
|
|
|
1393
1446
|
const hashParams = new URLSearchParams(window.location.hash.slice(1));
|
|
1394
1447
|
urlToken = hashParams.get("access_token") || hashParams.get("token");
|
|
1395
1448
|
}
|
|
1396
|
-
if (urlToken) {
|
|
1449
|
+
if (urlToken && isTokenValid(urlToken)) {
|
|
1397
1450
|
setToken(urlToken);
|
|
1398
1451
|
setTokenState(urlToken);
|
|
1399
1452
|
setUser(parseUserFromToken(urlToken));
|
|
1453
|
+
void consumeTokenToCookie(urlToken);
|
|
1400
1454
|
params.delete("access_token");
|
|
1401
1455
|
params.delete("token");
|
|
1402
1456
|
params.delete("project_id");
|
|
@@ -1404,12 +1458,20 @@ var HowOneProvider = ({
|
|
|
1404
1458
|
const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
|
|
1405
1459
|
window.history.replaceState({}, "", newUrl);
|
|
1406
1460
|
}
|
|
1461
|
+
if (!urlToken) {
|
|
1462
|
+
const cookieToken = readAccessTokenCookie();
|
|
1463
|
+
if (cookieToken && isTokenValid(cookieToken)) {
|
|
1464
|
+
setToken(cookieToken);
|
|
1465
|
+
setTokenState(cookieToken);
|
|
1466
|
+
setUser(parseUserFromToken(cookieToken));
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1407
1469
|
} catch (e) {
|
|
1408
1470
|
console.error("[HowOneProvider] Failed to capture token from URL:", e);
|
|
1409
1471
|
} finally {
|
|
1410
1472
|
setHasCheckedUrlToken(true);
|
|
1411
1473
|
}
|
|
1412
|
-
}, []);
|
|
1474
|
+
}, [consumeTokenToCookie, readAccessTokenCookie]);
|
|
1413
1475
|
const resolvedAuthUrl = (0, import_react8.useMemo)(() => {
|
|
1414
1476
|
const env3 = getGlobalEnvironment() ?? "dev";
|
|
1415
1477
|
switch (env3) {
|
|
@@ -1487,6 +1549,7 @@ var HowOneProvider = ({
|
|
|
1487
1549
|
}
|
|
1488
1550
|
setTokenState(null);
|
|
1489
1551
|
setUser(null);
|
|
1552
|
+
void logoutFromCookie();
|
|
1490
1553
|
redirectToAuth();
|
|
1491
1554
|
};
|
|
1492
1555
|
const value = {
|
|
@@ -1505,7 +1568,7 @@ var HowOneProvider = ({
|
|
|
1505
1568
|
children: [
|
|
1506
1569
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ElementSelectorProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(HowoneContext.Provider, { value, children: [
|
|
1507
1570
|
children,
|
|
1508
|
-
|
|
1571
|
+
showHowOneFlag && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FloatingButton, { onClick: () => window.open("https://howone.ai", "_blank") }),
|
|
1509
1572
|
pendingRedirect && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1510
1573
|
"div",
|
|
1511
1574
|
{
|
|
@@ -2345,6 +2408,7 @@ var Request = class {
|
|
|
2345
2408
|
this.abortControllers = /* @__PURE__ */ new Map();
|
|
2346
2409
|
this.instance = import_axios.default.create({
|
|
2347
2410
|
...config,
|
|
2411
|
+
withCredentials: true,
|
|
2348
2412
|
validateStatus: (status) => {
|
|
2349
2413
|
return status >= 200 && status < 300;
|
|
2350
2414
|
}
|
|
@@ -2721,6 +2785,17 @@ async function executeSSEWorkflow(request, options = {}) {
|
|
|
2721
2785
|
options.onStreamContent(logData.delta);
|
|
2722
2786
|
}
|
|
2723
2787
|
}
|
|
2788
|
+
if (rawEvent.type === "execution_error" && rawEvent.data) {
|
|
2789
|
+
const errorData = rawEvent.data;
|
|
2790
|
+
if (errorData.log_type === "execution_display_error") {
|
|
2791
|
+
const errorContent = errorData.content;
|
|
2792
|
+
const displayMessage = errorContent || "Workflow execution failed";
|
|
2793
|
+
ClayxToast.error({
|
|
2794
|
+
title: "Execution Error",
|
|
2795
|
+
message: displayMessage
|
|
2796
|
+
});
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2724
2799
|
if (rawEvent.type === "stream" && rawEvent.delta && options.onStreamContent) {
|
|
2725
2800
|
options.onStreamContent(rawEvent.delta);
|
|
2726
2801
|
}
|
|
@@ -3786,6 +3861,13 @@ function createClient(opts) {
|
|
|
3786
3861
|
applyToken(null);
|
|
3787
3862
|
rememberExternalToken(null, 0);
|
|
3788
3863
|
pendingExternalTokenPromise = null;
|
|
3864
|
+
try {
|
|
3865
|
+
fetch(`${env3.AUTH_COOKIE_ROOT_VALUE}/logout`, {
|
|
3866
|
+
method: "POST",
|
|
3867
|
+
credentials: "include"
|
|
3868
|
+
}).catch(() => void 0);
|
|
3869
|
+
} catch {
|
|
3870
|
+
}
|
|
3789
3871
|
if (typeof window !== "undefined") {
|
|
3790
3872
|
const loc = window.location.href;
|
|
3791
3873
|
try {
|