seacloud-sdk 0.12.2 → 0.12.4

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/cli.js CHANGED
@@ -118,9 +118,26 @@ async function getApiToken(providedApiKey) {
118
118
  }
119
119
  return "";
120
120
  }
121
+ function checkIsDevelopmentHost(host) {
122
+ const devHostPatterns = ["localhost", "127.0.0.1", ":3000", ":8080", "seaverse.dev"];
123
+ return devHostPatterns.some((pattern) => host.includes(pattern));
124
+ }
121
125
  function createConfig(options = {}) {
122
126
  const apiKey = options.apiKey;
123
- const baseUrl = options.baseUrl || (typeof process !== "undefined" ? process.env?.SEACLOUD_BASE_URL : void 0) || "https://proxy-rs.seaverse.ai";
127
+ let baseUrl;
128
+ if (options.baseUrl) {
129
+ baseUrl = options.baseUrl;
130
+ } else if (typeof process !== "undefined" && process.env?.SEACLOUD_BASE_URL) {
131
+ baseUrl = process.env.SEACLOUD_BASE_URL;
132
+ } else {
133
+ const currentHost = typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" ? globalThis.window.location.host : "";
134
+ if (checkIsDevelopmentHost(currentHost)) {
135
+ baseUrl = "https://proxy-rs.sg.seaverse.dev";
136
+ console.log("[SeaCloud SDK] \u68C0\u6D4B\u5230\u5F00\u53D1\u73AF\u5883\uFF08currentHost\uFF09\uFF0C\u4F7F\u7528\u5F00\u53D1 baseUrl:", baseUrl);
137
+ } else {
138
+ baseUrl = "https://proxy-rs.seaverse.ai";
139
+ }
140
+ }
124
141
  const fetchImpl = options.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : void 0);
125
142
  if (!fetchImpl) {
126
143
  throw new Error("fetch is not available. Please provide a fetch implementation in config or upgrade to Node.js 18+");
@@ -292,7 +309,8 @@ async function initSeacloud(apiKeyOrConfig, options) {
292
309
  try {
293
310
  const parentHost = await getHostFromParent(3e3);
294
311
  if (parentHost) {
295
- const isDevelopment = parentHost.includes("localhost") || parentHost.includes("127.0.0.1") || parentHost.includes(":3000") || parentHost.includes(":8080") || parentHost.includes("seaverse.dev");
312
+ const currentHost = typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" ? globalThis.window.location.host : "";
313
+ const isDevelopment = checkIsDevelopmentHost(currentHost) || checkIsDevelopmentHost(parentHost);
296
314
  if (isDevelopment) {
297
315
  config.baseUrl = "https://proxy-rs.sg.seaverse.dev";
298
316
  console.log("[SeaCloud SDK] \u68C0\u6D4B\u5230\u5F00\u53D1\u73AF\u5883\uFF0C\u4F7F\u7528\u5F00\u53D1 baseUrl:", config.baseUrl);