@howone/sdk 0.3.8 → 0.3.10

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 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.AUTH_ROOT_VALUE;
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 env2 = detectEnvironmentFromHostname();
374
- return API_BASE_URLS[env2] ?? API_BASE_URLS.dev;
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 env2 = getGlobalEnvironment() ?? "dev";
1378
- switch (env2) {
1396
+ const env3 = getGlobalEnvironment() ?? "dev";
1397
+ switch (env3) {
1379
1398
  case "local":
1380
1399
  return "http://localhost:3000/auth";
1381
1400
  case "prod":
@@ -2471,6 +2490,7 @@ function createArtifactsClient(req) {
2471
2490
  }
2472
2491
 
2473
2492
  // src/services/sse-executor.ts
2493
+ init_config();
2474
2494
  async function executeSSEWorkflow(request, options = {}) {
2475
2495
  const startTime = Date.now();
2476
2496
  const result = {
@@ -2559,6 +2579,18 @@ async function executeSSEWorkflow(request, options = {}) {
2559
2579
  if (rawEvent.type === "stream" && rawEvent.delta && options.onStreamContent) {
2560
2580
  options.onStreamContent(rawEvent.delta);
2561
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
+ }
2562
2594
  if (rawEvent.type === "execution_complete" && rawEvent.data) {
2563
2595
  const eventData = rawEvent.data;
2564
2596
  const eventResult = eventData.result;
@@ -2973,6 +3005,7 @@ async function executeWorkflowStreamPost(baseUrl, projectId, workflowId, request
2973
3005
  }
2974
3006
 
2975
3007
  // src/services/workflow-executor.ts
3008
+ init_config();
2976
3009
  var WorkflowExecutor = class {
2977
3010
  constructor(baseUrl, projectId, authToken) {
2978
3011
  this.baseUrl = baseUrl.replace(/\/$/, "");
@@ -3078,6 +3111,17 @@ var WorkflowExecutor = class {
3078
3111
  options.onCostUpdate(result.costStats);
3079
3112
  }
3080
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);
3081
3125
  } else if (event.type === "execution_complete" && event.data) {
3082
3126
  const completeData = event.data;
3083
3127
  const originalMessage = completeData.result?.original_message;
@@ -3217,9 +3261,9 @@ function wrapRequestWithProjectPrefix(biz, projectId) {
3217
3261
  return wrapped;
3218
3262
  }
3219
3263
  function createClient(opts) {
3220
- const envValue = opts.env || getGlobalEnvironment() || "prod";
3221
- const env2 = setEnvironment(envValue);
3222
- const actualAiBaseUrl = opts.baseUrl || env2.aiBaseUrl;
3264
+ const envValue2 = opts.env || getGlobalEnvironment() || "prod";
3265
+ const env3 = setEnvironment(envValue2);
3266
+ const actualAiBaseUrl = opts.baseUrl || env3.aiBaseUrl;
3223
3267
  function makeRequestFromBase(base) {
3224
3268
  return new request_default({
3225
3269
  baseURL: base,
@@ -3251,8 +3295,8 @@ function createClient(opts) {
3251
3295
  }
3252
3296
  });
3253
3297
  }
3254
- const biz = makeRequestFromBase(env2.baseUrl);
3255
- const ai = makeRequestFromBase(env2.aiBaseUrl);
3298
+ const biz = makeRequestFromBase(env3.baseUrl);
3299
+ const ai = makeRequestFromBase(env3.aiBaseUrl);
3256
3300
  const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
3257
3301
  let token = null;
3258
3302
  const bootstrapToken = getGlobalAvailableToken();
@@ -3266,9 +3310,7 @@ function createClient(opts) {
3266
3310
  return getGlobalAvailableToken();
3267
3311
  }
3268
3312
  try {
3269
- if (opts?.projectId) {
3270
- setDefaultProjectId(String(opts.projectId));
3271
- }
3313
+ setDefaultProjectId(opts?.projectId ? String(opts.projectId) : null);
3272
3314
  } catch {
3273
3315
  }
3274
3316
  function applyToken(t) {
@@ -3552,7 +3594,7 @@ function createClient(opts) {
3552
3594
  if (typeof window === "undefined") return;
3553
3595
  const loc = redirect || window.location.href;
3554
3596
  try {
3555
- const root = env2.baseUrl;
3597
+ const root = env3.baseUrl;
3556
3598
  const authUrl = new URL("/auth", String(root));
3557
3599
  authUrl.searchParams.set("redirect_uri", String(loc));
3558
3600
  if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
@@ -3560,7 +3602,7 @@ function createClient(opts) {
3560
3602
  } catch {
3561
3603
  const encoded = encodeURIComponent(String(loc));
3562
3604
  const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
3563
- const root = env2.baseUrl;
3605
+ const root = env3.baseUrl;
3564
3606
  window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
3565
3607
  }
3566
3608
  },
@@ -3569,6 +3611,21 @@ function createClient(opts) {
3569
3611
  applyToken(null);
3570
3612
  rememberExternalToken(null, 0);
3571
3613
  pendingExternalTokenPromise = null;
3614
+ if (typeof window !== "undefined") {
3615
+ const loc = window.location.href;
3616
+ try {
3617
+ const root = env3.AUTH_ROOT_VALUE;
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
+ }
3572
3629
  }
3573
3630
  },
3574
3631
  sanitizeUrl: (o) => {