@howone/sdk 0.3.7 → 0.3.9
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.js +106 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -212,6 +212,22 @@ function useAuth() {
|
|
|
212
212
|
setTokenState(null);
|
|
213
213
|
setUser(null);
|
|
214
214
|
notifyAuthStateChanged();
|
|
215
|
+
if (typeof window !== "undefined") {
|
|
216
|
+
const loc = window.location.href;
|
|
217
|
+
const pid = getDefaultProjectId();
|
|
218
|
+
try {
|
|
219
|
+
const root = env2.baseUrl;
|
|
220
|
+
const authUrl = new URL("/auth", String(root));
|
|
221
|
+
authUrl.searchParams.set("redirect_uri", String(loc));
|
|
222
|
+
if (pid) authUrl.searchParams.set("project_id", String(pid));
|
|
223
|
+
window.location.href = authUrl.toString();
|
|
224
|
+
} catch {
|
|
225
|
+
const encoded = encodeURIComponent(String(loc));
|
|
226
|
+
const pidParam = pid ? `&project_id=${encodeURIComponent(String(pid))}` : "";
|
|
227
|
+
const root = env2.baseUrl;
|
|
228
|
+
window.location.href = `${root}/auth?redirect_uri=${encoded}${pidParam}`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
215
231
|
};
|
|
216
232
|
return {
|
|
217
233
|
token,
|
|
@@ -240,12 +256,15 @@ function notifyAuthStateChanged() {
|
|
|
240
256
|
}
|
|
241
257
|
}
|
|
242
258
|
}
|
|
243
|
-
var import_react, AUTH_TOKEN_KEY, authSubscribers;
|
|
259
|
+
var import_react, AUTH_TOKEN_KEY, envValue, env2, authSubscribers;
|
|
244
260
|
var init_auth = __esm({
|
|
245
261
|
"src/auth/index.ts"() {
|
|
246
262
|
"use strict";
|
|
263
|
+
init_config();
|
|
247
264
|
import_react = require("react");
|
|
248
265
|
AUTH_TOKEN_KEY = "auth_token";
|
|
266
|
+
envValue = getGlobalEnvironment() || "prod";
|
|
267
|
+
env2 = setEnvironment(envValue);
|
|
249
268
|
authSubscribers = /* @__PURE__ */ new Set();
|
|
250
269
|
}
|
|
251
270
|
});
|
|
@@ -370,8 +389,8 @@ var detectEnvironmentFromHostname = () => {
|
|
|
370
389
|
}
|
|
371
390
|
};
|
|
372
391
|
var resolveApiBaseUrl = () => {
|
|
373
|
-
const
|
|
374
|
-
return API_BASE_URLS[
|
|
392
|
+
const env3 = detectEnvironmentFromHostname();
|
|
393
|
+
return API_BASE_URLS[env3] ?? API_BASE_URLS.dev;
|
|
375
394
|
};
|
|
376
395
|
var UnifiedAuthService = class {
|
|
377
396
|
constructor() {
|
|
@@ -1374,8 +1393,8 @@ var HowOneProvider = ({
|
|
|
1374
1393
|
}
|
|
1375
1394
|
}, []);
|
|
1376
1395
|
const resolvedAuthUrl = (0, import_react8.useMemo)(() => {
|
|
1377
|
-
const
|
|
1378
|
-
switch (
|
|
1396
|
+
const env3 = getGlobalEnvironment() ?? "dev";
|
|
1397
|
+
switch (env3) {
|
|
1379
1398
|
case "local":
|
|
1380
1399
|
return "http://localhost:3000/auth";
|
|
1381
1400
|
case "prod":
|
|
@@ -1395,34 +1414,42 @@ var HowOneProvider = ({
|
|
|
1395
1414
|
injectRedirectOverlayStyles();
|
|
1396
1415
|
}
|
|
1397
1416
|
}, [pendingRedirect]);
|
|
1398
|
-
(0, import_react8.
|
|
1399
|
-
if (!
|
|
1400
|
-
|
|
1401
|
-
}
|
|
1402
|
-
if (redirectOnUnauthenticated && !token && !user) {
|
|
1417
|
+
const redirectToAuth = (0, import_react8.useCallback)(() => {
|
|
1418
|
+
if (!redirectOnUnauthenticated || typeof window === "undefined") return;
|
|
1419
|
+
try {
|
|
1403
1420
|
const currentUrl = new URL(window.location.href);
|
|
1404
|
-
if (
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
authUrlObj.searchParams.set("project_id", projectId);
|
|
1411
|
-
}
|
|
1412
|
-
setPendingRedirect(true);
|
|
1413
|
-
requestAnimationFrame(() => {
|
|
1414
|
-
window.location.href = authUrlObj.toString();
|
|
1415
|
-
});
|
|
1416
|
-
} catch (error) {
|
|
1417
|
-
console.error("[HowOneProvider] Failed to build auth URL:", error);
|
|
1418
|
-
setPendingRedirect(true);
|
|
1419
|
-
requestAnimationFrame(() => {
|
|
1420
|
-
window.location.href = resolvedAuthUrl;
|
|
1421
|
-
});
|
|
1421
|
+
if (currentUrl.pathname.includes("/auth")) return;
|
|
1422
|
+
try {
|
|
1423
|
+
const authUrlObj = new URL(resolvedAuthUrl);
|
|
1424
|
+
authUrlObj.searchParams.set("redirect_uri", window.location.href);
|
|
1425
|
+
if (projectId) {
|
|
1426
|
+
authUrlObj.searchParams.set("project_id", projectId);
|
|
1422
1427
|
}
|
|
1428
|
+
setPendingRedirect(true);
|
|
1429
|
+
requestAnimationFrame(() => {
|
|
1430
|
+
window.location.href = authUrlObj.toString();
|
|
1431
|
+
});
|
|
1432
|
+
return;
|
|
1433
|
+
} catch (error) {
|
|
1434
|
+
console.error("[HowOneProvider] Failed to build auth URL:", error);
|
|
1423
1435
|
}
|
|
1436
|
+
setPendingRedirect(true);
|
|
1437
|
+
requestAnimationFrame(() => {
|
|
1438
|
+
window.location.href = resolvedAuthUrl;
|
|
1439
|
+
});
|
|
1440
|
+
} catch {
|
|
1441
|
+
setPendingRedirect(true);
|
|
1442
|
+
requestAnimationFrame(() => {
|
|
1443
|
+
window.location.href = resolvedAuthUrl;
|
|
1444
|
+
});
|
|
1424
1445
|
}
|
|
1425
|
-
}, [
|
|
1446
|
+
}, [redirectOnUnauthenticated, resolvedAuthUrl, projectId]);
|
|
1447
|
+
(0, import_react8.useEffect)(() => {
|
|
1448
|
+
if (!hasCheckedUrlToken) return;
|
|
1449
|
+
if (!token && !user) {
|
|
1450
|
+
redirectToAuth();
|
|
1451
|
+
}
|
|
1452
|
+
}, [token, user, hasCheckedUrlToken, redirectToAuth]);
|
|
1426
1453
|
const logout = () => {
|
|
1427
1454
|
try {
|
|
1428
1455
|
setToken(null);
|
|
@@ -1430,6 +1457,7 @@ var HowOneProvider = ({
|
|
|
1430
1457
|
}
|
|
1431
1458
|
setTokenState(null);
|
|
1432
1459
|
setUser(null);
|
|
1460
|
+
redirectToAuth();
|
|
1433
1461
|
};
|
|
1434
1462
|
const value = {
|
|
1435
1463
|
user,
|
|
@@ -2082,7 +2110,7 @@ var createToast = (type) => {
|
|
|
2082
2110
|
theme: getToastifyTheme(),
|
|
2083
2111
|
// 确保圆角样式不被覆盖,添加 rounded-xl 类
|
|
2084
2112
|
className: "!p-0 !shadow-none !rounded-xl",
|
|
2085
|
-
style: { padding: 0, borderRadius: "0.75rem" }
|
|
2113
|
+
style: { padding: 0, borderRadius: "0.75rem", backgroundColor: "transparent" }
|
|
2086
2114
|
}
|
|
2087
2115
|
);
|
|
2088
2116
|
};
|
|
@@ -2462,6 +2490,7 @@ function createArtifactsClient(req) {
|
|
|
2462
2490
|
}
|
|
2463
2491
|
|
|
2464
2492
|
// src/services/sse-executor.ts
|
|
2493
|
+
init_config();
|
|
2465
2494
|
async function executeSSEWorkflow(request, options = {}) {
|
|
2466
2495
|
const startTime = Date.now();
|
|
2467
2496
|
const result = {
|
|
@@ -2550,6 +2579,18 @@ async function executeSSEWorkflow(request, options = {}) {
|
|
|
2550
2579
|
if (rawEvent.type === "stream" && rawEvent.delta && options.onStreamContent) {
|
|
2551
2580
|
options.onStreamContent(rawEvent.delta);
|
|
2552
2581
|
}
|
|
2582
|
+
if (rawEvent.type === "key_limit_exceed") {
|
|
2583
|
+
const errorMsg = rawEvent.data.content;
|
|
2584
|
+
result.errors.push(errorMsg);
|
|
2585
|
+
showLimitUpgradeToast(
|
|
2586
|
+
"Your credits are exhausted. Please upgrade your plan to continue generating projects.",
|
|
2587
|
+
() => window.open(`${getEnvs().AUTH_ROOT_VALUE}/price`, "_blank")
|
|
2588
|
+
);
|
|
2589
|
+
if (options.onError) {
|
|
2590
|
+
options.onError(new Error(errorMsg));
|
|
2591
|
+
}
|
|
2592
|
+
throw new Error(errorMsg);
|
|
2593
|
+
}
|
|
2553
2594
|
if (rawEvent.type === "execution_complete" && rawEvent.data) {
|
|
2554
2595
|
const eventData = rawEvent.data;
|
|
2555
2596
|
const eventResult = eventData.result;
|
|
@@ -2964,6 +3005,7 @@ async function executeWorkflowStreamPost(baseUrl, projectId, workflowId, request
|
|
|
2964
3005
|
}
|
|
2965
3006
|
|
|
2966
3007
|
// src/services/workflow-executor.ts
|
|
3008
|
+
init_config();
|
|
2967
3009
|
var WorkflowExecutor = class {
|
|
2968
3010
|
constructor(baseUrl, projectId, authToken) {
|
|
2969
3011
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -3069,6 +3111,17 @@ var WorkflowExecutor = class {
|
|
|
3069
3111
|
options.onCostUpdate(result.costStats);
|
|
3070
3112
|
}
|
|
3071
3113
|
}
|
|
3114
|
+
} else if (event.type === "key_limit_exceed") {
|
|
3115
|
+
const errorMsg = event.data?.content;
|
|
3116
|
+
result.errors.push(errorMsg);
|
|
3117
|
+
showLimitUpgradeToast(
|
|
3118
|
+
"Your credits are exhausted. Please upgrade your plan to continue generating projects.",
|
|
3119
|
+
() => window.open(`${getEnvs().AUTH_ROOT_VALUE}/price`, "_blank")
|
|
3120
|
+
);
|
|
3121
|
+
if (options?.onError) {
|
|
3122
|
+
options.onError(new Error(errorMsg));
|
|
3123
|
+
}
|
|
3124
|
+
throw new Error(errorMsg);
|
|
3072
3125
|
} else if (event.type === "execution_complete" && event.data) {
|
|
3073
3126
|
const completeData = event.data;
|
|
3074
3127
|
const originalMessage = completeData.result?.original_message;
|
|
@@ -3208,9 +3261,9 @@ function wrapRequestWithProjectPrefix(biz, projectId) {
|
|
|
3208
3261
|
return wrapped;
|
|
3209
3262
|
}
|
|
3210
3263
|
function createClient(opts) {
|
|
3211
|
-
const
|
|
3212
|
-
const
|
|
3213
|
-
const actualAiBaseUrl = opts.baseUrl ||
|
|
3264
|
+
const envValue2 = opts.env || getGlobalEnvironment() || "prod";
|
|
3265
|
+
const env3 = setEnvironment(envValue2);
|
|
3266
|
+
const actualAiBaseUrl = opts.baseUrl || env3.aiBaseUrl;
|
|
3214
3267
|
function makeRequestFromBase(base) {
|
|
3215
3268
|
return new request_default({
|
|
3216
3269
|
baseURL: base,
|
|
@@ -3242,8 +3295,8 @@ function createClient(opts) {
|
|
|
3242
3295
|
}
|
|
3243
3296
|
});
|
|
3244
3297
|
}
|
|
3245
|
-
const biz = makeRequestFromBase(
|
|
3246
|
-
const ai = makeRequestFromBase(
|
|
3298
|
+
const biz = makeRequestFromBase(env3.baseUrl);
|
|
3299
|
+
const ai = makeRequestFromBase(env3.aiBaseUrl);
|
|
3247
3300
|
const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
|
|
3248
3301
|
let token = null;
|
|
3249
3302
|
const bootstrapToken = getGlobalAvailableToken();
|
|
@@ -3257,9 +3310,7 @@ function createClient(opts) {
|
|
|
3257
3310
|
return getGlobalAvailableToken();
|
|
3258
3311
|
}
|
|
3259
3312
|
try {
|
|
3260
|
-
|
|
3261
|
-
setDefaultProjectId(String(opts.projectId));
|
|
3262
|
-
}
|
|
3313
|
+
setDefaultProjectId(opts?.projectId ? String(opts.projectId) : null);
|
|
3263
3314
|
} catch {
|
|
3264
3315
|
}
|
|
3265
3316
|
function applyToken(t) {
|
|
@@ -3543,7 +3594,7 @@ function createClient(opts) {
|
|
|
3543
3594
|
if (typeof window === "undefined") return;
|
|
3544
3595
|
const loc = redirect || window.location.href;
|
|
3545
3596
|
try {
|
|
3546
|
-
const root =
|
|
3597
|
+
const root = env3.baseUrl;
|
|
3547
3598
|
const authUrl = new URL("/auth", String(root));
|
|
3548
3599
|
authUrl.searchParams.set("redirect_uri", String(loc));
|
|
3549
3600
|
if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
|
|
@@ -3551,7 +3602,7 @@ function createClient(opts) {
|
|
|
3551
3602
|
} catch {
|
|
3552
3603
|
const encoded = encodeURIComponent(String(loc));
|
|
3553
3604
|
const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
|
|
3554
|
-
const root =
|
|
3605
|
+
const root = env3.baseUrl;
|
|
3555
3606
|
window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
|
|
3556
3607
|
}
|
|
3557
3608
|
},
|
|
@@ -3560,6 +3611,21 @@ function createClient(opts) {
|
|
|
3560
3611
|
applyToken(null);
|
|
3561
3612
|
rememberExternalToken(null, 0);
|
|
3562
3613
|
pendingExternalTokenPromise = null;
|
|
3614
|
+
if (typeof window !== "undefined") {
|
|
3615
|
+
const loc = window.location.href;
|
|
3616
|
+
try {
|
|
3617
|
+
const root = env3.baseUrl;
|
|
3618
|
+
const authUrl = new URL("/auth", String(root));
|
|
3619
|
+
authUrl.searchParams.set("redirect_uri", String(loc));
|
|
3620
|
+
if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
|
|
3621
|
+
window.location.href = authUrl.toString();
|
|
3622
|
+
} catch {
|
|
3623
|
+
const encoded = encodeURIComponent(String(loc));
|
|
3624
|
+
const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
|
|
3625
|
+
const root = env3.baseUrl;
|
|
3626
|
+
window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3563
3629
|
}
|
|
3564
3630
|
},
|
|
3565
3631
|
sanitizeUrl: (o) => {
|