@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.mjs CHANGED
@@ -202,6 +202,22 @@ function useAuth() {
202
202
  setTokenState(null);
203
203
  setUser(null);
204
204
  notifyAuthStateChanged();
205
+ if (typeof window !== "undefined") {
206
+ const loc = window.location.href;
207
+ const pid = getDefaultProjectId();
208
+ try {
209
+ const root = env2.AUTH_ROOT_VALUE;
210
+ const authUrl = new URL("/auth", String(root));
211
+ authUrl.searchParams.set("redirect_uri", String(loc));
212
+ if (pid) authUrl.searchParams.set("project_id", String(pid));
213
+ window.location.href = authUrl.toString();
214
+ } catch {
215
+ const encoded = encodeURIComponent(String(loc));
216
+ const pidParam = pid ? `&project_id=${encodeURIComponent(String(pid))}` : "";
217
+ const root = env2.baseUrl;
218
+ window.location.href = `${root}/auth?redirect_uri=${encoded}${pidParam}`;
219
+ }
220
+ }
205
221
  };
206
222
  return {
207
223
  token,
@@ -230,11 +246,14 @@ function notifyAuthStateChanged() {
230
246
  }
231
247
  }
232
248
  }
233
- var AUTH_TOKEN_KEY, authSubscribers;
249
+ var AUTH_TOKEN_KEY, envValue, env2, authSubscribers;
234
250
  var init_auth = __esm({
235
251
  "src/auth/index.ts"() {
236
252
  "use strict";
253
+ init_config();
237
254
  AUTH_TOKEN_KEY = "auth_token";
255
+ envValue = getGlobalEnvironment() || "prod";
256
+ env2 = setEnvironment(envValue);
238
257
  authSubscribers = /* @__PURE__ */ new Set();
239
258
  }
240
259
  });
@@ -300,8 +319,8 @@ var detectEnvironmentFromHostname = () => {
300
319
  }
301
320
  };
302
321
  var resolveApiBaseUrl = () => {
303
- const env2 = detectEnvironmentFromHostname();
304
- return API_BASE_URLS[env2] ?? API_BASE_URLS.dev;
322
+ const env3 = detectEnvironmentFromHostname();
323
+ return API_BASE_URLS[env3] ?? API_BASE_URLS.dev;
305
324
  };
306
325
  var UnifiedAuthService = class {
307
326
  constructor() {
@@ -1304,8 +1323,8 @@ var HowOneProvider = ({
1304
1323
  }
1305
1324
  }, []);
1306
1325
  const resolvedAuthUrl = useMemo(() => {
1307
- const env2 = getGlobalEnvironment() ?? "dev";
1308
- switch (env2) {
1326
+ const env3 = getGlobalEnvironment() ?? "dev";
1327
+ switch (env3) {
1309
1328
  case "local":
1310
1329
  return "http://localhost:3000/auth";
1311
1330
  case "prod":
@@ -2401,6 +2420,7 @@ function createArtifactsClient(req) {
2401
2420
  }
2402
2421
 
2403
2422
  // src/services/sse-executor.ts
2423
+ init_config();
2404
2424
  async function executeSSEWorkflow(request, options = {}) {
2405
2425
  const startTime = Date.now();
2406
2426
  const result = {
@@ -2489,6 +2509,18 @@ async function executeSSEWorkflow(request, options = {}) {
2489
2509
  if (rawEvent.type === "stream" && rawEvent.delta && options.onStreamContent) {
2490
2510
  options.onStreamContent(rawEvent.delta);
2491
2511
  }
2512
+ if (rawEvent.type === "key_limit_exceed") {
2513
+ const errorMsg = rawEvent.data.content;
2514
+ result.errors.push(errorMsg);
2515
+ showLimitUpgradeToast(
2516
+ "Your credits are exhausted. Please upgrade your plan to continue generating projects.",
2517
+ () => window.open(`${getEnvs().AUTH_ROOT_VALUE}/price`, "_blank")
2518
+ );
2519
+ if (options.onError) {
2520
+ options.onError(new Error(errorMsg));
2521
+ }
2522
+ throw new Error(errorMsg);
2523
+ }
2492
2524
  if (rawEvent.type === "execution_complete" && rawEvent.data) {
2493
2525
  const eventData = rawEvent.data;
2494
2526
  const eventResult = eventData.result;
@@ -2903,6 +2935,7 @@ async function executeWorkflowStreamPost(baseUrl, projectId, workflowId, request
2903
2935
  }
2904
2936
 
2905
2937
  // src/services/workflow-executor.ts
2938
+ init_config();
2906
2939
  var WorkflowExecutor = class {
2907
2940
  constructor(baseUrl, projectId, authToken) {
2908
2941
  this.baseUrl = baseUrl.replace(/\/$/, "");
@@ -3008,6 +3041,17 @@ var WorkflowExecutor = class {
3008
3041
  options.onCostUpdate(result.costStats);
3009
3042
  }
3010
3043
  }
3044
+ } else if (event.type === "key_limit_exceed") {
3045
+ const errorMsg = event.data?.content;
3046
+ result.errors.push(errorMsg);
3047
+ showLimitUpgradeToast(
3048
+ "Your credits are exhausted. Please upgrade your plan to continue generating projects.",
3049
+ () => window.open(`${getEnvs().AUTH_ROOT_VALUE}/price`, "_blank")
3050
+ );
3051
+ if (options?.onError) {
3052
+ options.onError(new Error(errorMsg));
3053
+ }
3054
+ throw new Error(errorMsg);
3011
3055
  } else if (event.type === "execution_complete" && event.data) {
3012
3056
  const completeData = event.data;
3013
3057
  const originalMessage = completeData.result?.original_message;
@@ -3147,9 +3191,9 @@ function wrapRequestWithProjectPrefix(biz, projectId) {
3147
3191
  return wrapped;
3148
3192
  }
3149
3193
  function createClient(opts) {
3150
- const envValue = opts.env || getGlobalEnvironment() || "prod";
3151
- const env2 = setEnvironment(envValue);
3152
- const actualAiBaseUrl = opts.baseUrl || env2.aiBaseUrl;
3194
+ const envValue2 = opts.env || getGlobalEnvironment() || "prod";
3195
+ const env3 = setEnvironment(envValue2);
3196
+ const actualAiBaseUrl = opts.baseUrl || env3.aiBaseUrl;
3153
3197
  function makeRequestFromBase(base) {
3154
3198
  return new request_default({
3155
3199
  baseURL: base,
@@ -3181,8 +3225,8 @@ function createClient(opts) {
3181
3225
  }
3182
3226
  });
3183
3227
  }
3184
- const biz = makeRequestFromBase(env2.baseUrl);
3185
- const ai = makeRequestFromBase(env2.aiBaseUrl);
3228
+ const biz = makeRequestFromBase(env3.baseUrl);
3229
+ const ai = makeRequestFromBase(env3.aiBaseUrl);
3186
3230
  const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
3187
3231
  let token = null;
3188
3232
  const bootstrapToken = getGlobalAvailableToken();
@@ -3196,9 +3240,7 @@ function createClient(opts) {
3196
3240
  return getGlobalAvailableToken();
3197
3241
  }
3198
3242
  try {
3199
- if (opts?.projectId) {
3200
- setDefaultProjectId(String(opts.projectId));
3201
- }
3243
+ setDefaultProjectId(opts?.projectId ? String(opts.projectId) : null);
3202
3244
  } catch {
3203
3245
  }
3204
3246
  function applyToken(t) {
@@ -3482,7 +3524,7 @@ function createClient(opts) {
3482
3524
  if (typeof window === "undefined") return;
3483
3525
  const loc = redirect || window.location.href;
3484
3526
  try {
3485
- const root = env2.baseUrl;
3527
+ const root = env3.baseUrl;
3486
3528
  const authUrl = new URL("/auth", String(root));
3487
3529
  authUrl.searchParams.set("redirect_uri", String(loc));
3488
3530
  if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
@@ -3490,7 +3532,7 @@ function createClient(opts) {
3490
3532
  } catch {
3491
3533
  const encoded = encodeURIComponent(String(loc));
3492
3534
  const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
3493
- const root = env2.baseUrl;
3535
+ const root = env3.baseUrl;
3494
3536
  window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
3495
3537
  }
3496
3538
  },
@@ -3499,6 +3541,21 @@ function createClient(opts) {
3499
3541
  applyToken(null);
3500
3542
  rememberExternalToken(null, 0);
3501
3543
  pendingExternalTokenPromise = null;
3544
+ if (typeof window !== "undefined") {
3545
+ const loc = window.location.href;
3546
+ try {
3547
+ const root = env3.AUTH_ROOT_VALUE;
3548
+ const authUrl = new URL("/auth", String(root));
3549
+ authUrl.searchParams.set("redirect_uri", String(loc));
3550
+ if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
3551
+ window.location.href = authUrl.toString();
3552
+ } catch {
3553
+ const encoded = encodeURIComponent(String(loc));
3554
+ const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
3555
+ const root = env3.baseUrl;
3556
+ window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
3557
+ }
3558
+ }
3502
3559
  }
3503
3560
  },
3504
3561
  sanitizeUrl: (o) => {