@howone/sdk 0.2.5 → 0.2.7

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
@@ -894,7 +894,7 @@ var LoginForm = ({
894
894
 
895
895
  // src/components/auth/HowoneProvider.tsx
896
896
  init_auth();
897
- import { createContext as createContext2, useContext as useContext2, useState as useState7, useEffect as useEffect6 } from "react";
897
+ import { createContext as createContext2, useContext as useContext2, useState as useState7, useEffect as useEffect6, useMemo } from "react";
898
898
 
899
899
  // src/components/theme/ThemeProvider.tsx
900
900
  import { createContext, useContext, useEffect as useEffect3, useState as useState3 } from "react";
@@ -3108,6 +3108,7 @@ var ErrorTracking = class {
3108
3108
  window.addEventListener("unhandledrejection", (event) => {
3109
3109
  event.preventDefault();
3110
3110
  const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
3111
+ this.internalLog("warn", "\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u6355\u83B7 unhandledrejection:", error.message);
3111
3112
  this.handleError(error, {
3112
3113
  type: "promise",
3113
3114
  source: "unhandledrejection"
@@ -3142,7 +3143,12 @@ var ErrorTracking = class {
3142
3143
  */
3143
3144
  safeForwardConsoleToParent(method, args) {
3144
3145
  if (window.parent === window) return;
3145
- if (!this.fullyInitialized) return;
3146
+ const argsStr = args.map((arg) => String(arg)).join(" ").toLowerCase();
3147
+ const is504Error = argsStr.includes("504") || argsStr.includes("gateway timeout");
3148
+ if (is504Error) {
3149
+ this.internalLog("warn", "\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}[ErrorTracking] \u63A7\u5236\u53F0\u6355\u83B7 504 \u9519\u8BEF:", argsStr.substring(0, 100));
3150
+ }
3151
+ if (!is504Error && !this.fullyInitialized) return;
3146
3152
  try {
3147
3153
  let stack = null;
3148
3154
  if (method === "warn" || method === "error") {
@@ -3350,12 +3356,25 @@ var ErrorTracking = class {
3350
3356
  }, 5e3);
3351
3357
  return false;
3352
3358
  }
3359
+ /**
3360
+ * 判断是否是 504 错误,需要立即发送
3361
+ */
3362
+ isCriticalNetworkError(error, details) {
3363
+ const message = error.message?.toLowerCase() || "";
3364
+ return message.includes("504") || message.includes("gateway timeout");
3365
+ }
3353
3366
  /**
3354
3367
  * 发送统一格式的错误
3355
3368
  */
3356
3369
  sendUnifiedError(error, details = {}) {
3357
3370
  if (window.parent === window) return;
3358
- if (!this.fullyInitialized) return;
3371
+ const isCriticalError = this.isCriticalNetworkError(error, details);
3372
+ if (isCriticalError) {
3373
+ this.internalLog("warn", "\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u68C0\u6D4B\u5230 504 \u9519\u8BEF\uFF0C\u7ACB\u5373\u53D1\u9001:", error.message);
3374
+ }
3375
+ if (!isCriticalError && !this.fullyInitialized) {
3376
+ return;
3377
+ }
3359
3378
  try {
3360
3379
  const currentViewInfo = this.viewDetector?.getCurrentViewInfo();
3361
3380
  const payload = {
@@ -4727,6 +4746,7 @@ var ErrorHandler = class {
4727
4746
  };
4728
4747
 
4729
4748
  // src/components/auth/HowoneProvider.tsx
4749
+ init_config();
4730
4750
  import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
4731
4751
  var globalErrorHandler = null;
4732
4752
  var initializeErrorHandler = () => {
@@ -4750,7 +4770,6 @@ var HowOneProvider = ({
4750
4770
  defaultTheme = "system",
4751
4771
  themeStorageKey = "howone-theme",
4752
4772
  forceDefaultTheme = false,
4753
- authUrl = "https://howone.dev/auth",
4754
4773
  redirectOnUnauthenticated = true
4755
4774
  }) => {
4756
4775
  const [user, setUser] = useState7(() => parseUserFromToken(getToken()));
@@ -4781,6 +4800,18 @@ var HowOneProvider = ({
4781
4800
  setHasCheckedUrlToken(true);
4782
4801
  }
4783
4802
  }, []);
4803
+ const resolvedAuthUrl = useMemo(() => {
4804
+ const env2 = getGlobalEnvironment() ?? "dev";
4805
+ switch (env2) {
4806
+ case "local":
4807
+ return "http://localhost:3000/auth";
4808
+ case "prod":
4809
+ return "https://howone.ai/auth";
4810
+ case "dev":
4811
+ default:
4812
+ return "https://howone.dev/auth";
4813
+ }
4814
+ }, []);
4784
4815
  useEffect6(() => {
4785
4816
  if (!hasCheckedUrlToken) {
4786
4817
  return;
@@ -4789,7 +4820,7 @@ var HowOneProvider = ({
4789
4820
  const currentUrl = new URL(window.location.href);
4790
4821
  if (!currentUrl.pathname.includes("/auth")) {
4791
4822
  try {
4792
- const authUrlObj = new URL(authUrl);
4823
+ const authUrlObj = new URL(resolvedAuthUrl);
4793
4824
  const redirectUri = window.location.href;
4794
4825
  authUrlObj.searchParams.set("redirect_uri", redirectUri);
4795
4826
  if (projectId) {
@@ -4798,11 +4829,11 @@ var HowOneProvider = ({
4798
4829
  window.location.href = authUrlObj.toString();
4799
4830
  } catch (error) {
4800
4831
  console.error("[HowOneProvider] Failed to build auth URL:", error);
4801
- window.location.href = authUrl;
4832
+ window.location.href = resolvedAuthUrl;
4802
4833
  }
4803
4834
  }
4804
4835
  }
4805
- }, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
4836
+ }, [token, user, redirectOnUnauthenticated, resolvedAuthUrl, projectId, hasCheckedUrlToken]);
4806
4837
  const logout = () => {
4807
4838
  try {
4808
4839
  setToken(null);