@howone/sdk 0.2.9 → 0.2.11

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
@@ -19,6 +19,77 @@ var __copyProps = (to, from, except, desc) => {
19
19
  };
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
+ // src/config.ts
23
+ var config_exports = {};
24
+ __export(config_exports, {
25
+ getDefaultProjectId: () => getDefaultProjectId,
26
+ getEnvironment: () => getEnvironment,
27
+ getEnvs: () => getEnvs,
28
+ getGlobalEnvironment: () => getGlobalEnvironment,
29
+ setDefaultProjectId: () => setDefaultProjectId,
30
+ setEnvironment: () => setEnvironment
31
+ });
32
+ function setEnvironment(e) {
33
+ env = e;
34
+ return envs[env] || envs["dev"];
35
+ }
36
+ function getEnvironment() {
37
+ return env;
38
+ }
39
+ function getEnvs() {
40
+ return envs[env] || envs["dev"];
41
+ }
42
+ function setDefaultProjectId(id) {
43
+ DEFAULT_PROJECT_ID = id;
44
+ }
45
+ function getDefaultProjectId() {
46
+ try {
47
+ if (DEFAULT_PROJECT_ID) return DEFAULT_PROJECT_ID;
48
+ const g = globalThis.__HOWONE_PROJECT_ID__;
49
+ if (typeof g === "string" && g.length > 0) return String(g);
50
+ return null;
51
+ } catch {
52
+ return DEFAULT_PROJECT_ID;
53
+ }
54
+ }
55
+ function getGlobalEnvironment() {
56
+ try {
57
+ const g = globalThis.__HOWONE_ENV__;
58
+ if (g === "local" || g === "dev" || g === "prod") return g;
59
+ return null;
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+ var DEFAULT_PROJECT_ID, env, localEnv, devEnv, prodEnv, envs;
65
+ var init_config = __esm({
66
+ "src/config.ts"() {
67
+ "use strict";
68
+ DEFAULT_PROJECT_ID = null;
69
+ env = "dev";
70
+ localEnv = {
71
+ AUTH_ROOT_VALUE: "https://howone.dev",
72
+ baseUrl: "http://localhost:3002/api",
73
+ aiBaseUrl: "https://evoagentx-server.fly.dev"
74
+ };
75
+ devEnv = {
76
+ AUTH_ROOT_VALUE: "https://howone.dev",
77
+ baseUrl: "https://api.howone.dev/api",
78
+ aiBaseUrl: "https://evoagentx-server-stable.fly.dev"
79
+ };
80
+ prodEnv = {
81
+ AUTH_ROOT_VALUE: "https://howone.ai",
82
+ baseUrl: "https://api.howone.ai/api",
83
+ aiBaseUrl: "https://evoagentx-server-deploy.fly.dev"
84
+ };
85
+ envs = {
86
+ local: localEnv,
87
+ dev: devEnv,
88
+ prod: prodEnv
89
+ };
90
+ }
91
+ });
92
+
22
93
  // src/auth/index.ts
23
94
  var auth_exports = {};
24
95
  __export(auth_exports, {
@@ -168,77 +239,6 @@ var init_auth = __esm({
168
239
  }
169
240
  });
170
241
 
171
- // src/config.ts
172
- var config_exports = {};
173
- __export(config_exports, {
174
- getDefaultProjectId: () => getDefaultProjectId,
175
- getEnvironment: () => getEnvironment,
176
- getEnvs: () => getEnvs,
177
- getGlobalEnvironment: () => getGlobalEnvironment,
178
- setDefaultProjectId: () => setDefaultProjectId,
179
- setEnvironment: () => setEnvironment
180
- });
181
- function setEnvironment(e) {
182
- env = e;
183
- return envs[env] || envs["dev"];
184
- }
185
- function getEnvironment() {
186
- return env;
187
- }
188
- function getEnvs() {
189
- return envs[env] || envs["dev"];
190
- }
191
- function setDefaultProjectId(id) {
192
- DEFAULT_PROJECT_ID = id;
193
- }
194
- function getDefaultProjectId() {
195
- try {
196
- if (DEFAULT_PROJECT_ID) return DEFAULT_PROJECT_ID;
197
- const g = globalThis.__HOWONE_PROJECT_ID__;
198
- if (typeof g === "string" && g.length > 0) return String(g);
199
- return null;
200
- } catch {
201
- return DEFAULT_PROJECT_ID;
202
- }
203
- }
204
- function getGlobalEnvironment() {
205
- try {
206
- const g = globalThis.__HOWONE_ENV__;
207
- if (g === "local" || g === "dev" || g === "prod") return g;
208
- return null;
209
- } catch {
210
- return null;
211
- }
212
- }
213
- var DEFAULT_PROJECT_ID, env, localEnv, devEnv, prodEnv, envs;
214
- var init_config = __esm({
215
- "src/config.ts"() {
216
- "use strict";
217
- DEFAULT_PROJECT_ID = null;
218
- env = "dev";
219
- localEnv = {
220
- AUTH_ROOT_VALUE: "https://howone.dev",
221
- baseUrl: "http://localhost:3002/api",
222
- aiBaseUrl: "https://evoagentx-server.fly.dev"
223
- };
224
- devEnv = {
225
- AUTH_ROOT_VALUE: "https://howone.dev",
226
- baseUrl: "https://api.howone.dev/api",
227
- aiBaseUrl: "https://evoagentx-server-stable.fly.dev"
228
- };
229
- prodEnv = {
230
- AUTH_ROOT_VALUE: "https://howone.ai",
231
- baseUrl: "https://api.howone.ai/api",
232
- aiBaseUrl: "https://evoagentx-server-deploy.fly.dev"
233
- };
234
- envs = {
235
- local: localEnv,
236
- dev: devEnv,
237
- prod: prodEnv
238
- };
239
- }
240
- });
241
-
242
242
  // src/components/FloatingButton.tsx
243
243
  import { Icon } from "@iconify/react/dist/iconify.js";
244
244
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -272,9 +272,19 @@ var FloatingButton = ({
272
272
  };
273
273
 
274
274
  // src/services/unified-oauth.ts
275
+ init_config();
276
+ var API_BASE_URLS = {
277
+ local: "https://create-x-backend-dev.fly.dev",
278
+ dev: "https://create-x-backend-dev.fly.dev",
279
+ prod: "https://create-x-backend.fly.dev"
280
+ };
281
+ var resolveApiBaseUrl = () => {
282
+ const env2 = getGlobalEnvironment() ?? "dev";
283
+ return API_BASE_URLS[env2] ?? API_BASE_URLS.dev;
284
+ };
275
285
  var UnifiedAuthService = class {
276
286
  constructor() {
277
- this.API_BASE_URL = "https://create-x-backend-dev.fly.dev";
287
+ this.API_BASE_URL = resolveApiBaseUrl();
278
288
  }
279
289
  /**
280
290
  * 初始化 Google 登录流程
@@ -3086,7 +3096,6 @@ var ErrorTracking = class {
3086
3096
  this.setupGlobalErrorListeners();
3087
3097
  this.setupConsoleInterception();
3088
3098
  this.setupNetworkMonitoring();
3089
- this.setupResourceLoadMonitoring();
3090
3099
  this.initialized = true;
3091
3100
  setTimeout(() => {
3092
3101
  this.fullyInitialized = true;
@@ -3097,7 +3106,7 @@ var ErrorTracking = class {
3097
3106
  */
3098
3107
  setupGlobalErrorListeners() {
3099
3108
  window.addEventListener("error", (event) => {
3100
- this.internalLog("warn", "\u{1F3AF}\u{1F3AF}\u{1F3AF} window.error \u4E8B\u4EF6\u89E6\u53D1:", event.message || event.error?.message);
3109
+ event.preventDefault();
3101
3110
  this.handleError(event.error || new Error(event.message), {
3102
3111
  filename: event.filename,
3103
3112
  lineno: event.lineno,
@@ -3107,8 +3116,8 @@ var ErrorTracking = class {
3107
3116
  });
3108
3117
  });
3109
3118
  window.addEventListener("unhandledrejection", (event) => {
3119
+ event.preventDefault();
3110
3120
  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);
3112
3121
  this.handleError(error, {
3113
3122
  type: "promise",
3114
3123
  source: "unhandledrejection"
@@ -3143,12 +3152,7 @@ var ErrorTracking = class {
3143
3152
  */
3144
3153
  safeForwardConsoleToParent(method, args) {
3145
3154
  if (window.parent === window) 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;
3155
+ if (!this.fullyInitialized) return;
3152
3156
  try {
3153
3157
  let stack = null;
3154
3158
  if (method === "warn" || method === "error") {
@@ -3224,43 +3228,6 @@ var ErrorTracking = class {
3224
3228
  this.internalLog("error", "[ErrorTracking] \u63A7\u5236\u53F0\u8F6C\u53D1\u5931\u8D25:", error);
3225
3229
  }
3226
3230
  }
3227
- /**
3228
- * 设置资源加载监控(使用 PerformanceObserver 监控 504 错误)
3229
- */
3230
- setupResourceLoadMonitoring() {
3231
- if (!window.PerformanceObserver) {
3232
- this.internalLog("warn", "\u274C\u274C\u274CPerformanceObserver \u4E0D\u652F\u6301\u274C\u274C\u274C");
3233
- return;
3234
- }
3235
- try {
3236
- const observer = new PerformanceObserver((list) => {
3237
- for (const entry of list.getEntries()) {
3238
- console.log("\u{1F30D}\u{1F30D}entry---------entry\u{1F30D}\u{1F30D}", entry);
3239
- if (entry.entryType === "resource") {
3240
- const resourceEntry = entry;
3241
- if (resourceEntry.transferSize === 0 && !resourceEntry.duration) {
3242
- const url = resourceEntry.name;
3243
- console.log("\u{1F30D}\u{1F30D}url--------------url\u{1F30D}\u{1F30D}", url);
3244
- if (url.includes(".js") || url.includes(".mjs")) {
3245
- this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u68C0\u6D4B\u5230\u8D44\u6E90\u52A0\u8F7D\u5931\u8D25\uFF08\u53EF\u80FD\u662F 504\uFF09:", url);
3246
- this.handleError(new Error(`Resource load failed (possibly 504): ${url}`), {
3247
- type: "resource",
3248
- resourceUrl: url,
3249
- source: "PerformanceObserver",
3250
- transferSize: resourceEntry.transferSize,
3251
- duration: resourceEntry.duration
3252
- });
3253
- }
3254
- }
3255
- }
3256
- }
3257
- });
3258
- observer.observe({ entryTypes: ["resource"] });
3259
- this.internalLog("log", "\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u5DF2\u542F\u52A8\uFF0C\u76D1\u63A7\u8D44\u6E90\u52A0\u8F7D");
3260
- } catch (error) {
3261
- this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274CPerformanceObserver \u8BBE\u7F6E\u5931\u8D25:", error);
3262
- }
3263
- }
3264
3231
  /**
3265
3232
  * 设置网络监控
3266
3233
  */
@@ -3393,34 +3360,12 @@ var ErrorTracking = class {
3393
3360
  }, 5e3);
3394
3361
  return false;
3395
3362
  }
3396
- /**
3397
- * 判断是否是 504 错误或资源加载失败,需要立即发送
3398
- */
3399
- isCriticalNetworkError(error, details) {
3400
- const message = error.message?.toLowerCase() || "";
3401
- console.log("\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705", message, details);
3402
- if (message.includes("504") || message.includes("gateway timeout")) {
3403
- return true;
3404
- }
3405
- if (details.type === "resource" && details.source === "PerformanceObserver") {
3406
- return true;
3407
- }
3408
- return false;
3409
- }
3410
3363
  /**
3411
3364
  * 发送统一格式的错误
3412
3365
  */
3413
3366
  sendUnifiedError(error, details = {}) {
3414
3367
  if (window.parent === window) return;
3415
- const isCriticalError = this.isCriticalNetworkError(error, details);
3416
- console.log("\u53D1\u73B0504\u9519\u8BEF\u4E86\u5417\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", isCriticalError);
3417
- if (isCriticalError) {
3418
- 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);
3419
- }
3420
- console.log("\u7B2C\u4E8C\u4E2A\u5224\u65AD\u662F\u4EC0\u4E48\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", this.fullyInitialized);
3421
- if (!isCriticalError && !this.fullyInitialized) {
3422
- return;
3423
- }
3368
+ if (!this.fullyInitialized) return;
3424
3369
  try {
3425
3370
  const currentViewInfo = this.viewDetector?.getCurrentViewInfo();
3426
3371
  const payload = {