From ab886c6f9fd501e3a01de3116ce1ef107774584c Mon Sep 17 00:00:00 2001 From: joohwan Date: Mon, 18 May 2026 16:05:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 19 +++++++++---------- src/commands/region.ts | 10 ++++++---- src/user.ts | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/api.ts b/src/api.ts index 9ab7af7..2f42f62 100644 --- a/src/api.ts +++ b/src/api.ts @@ -3,7 +3,7 @@ import * as e2b from 'e2b' import { getUserConfig, UserConfig } from './user' import { asBold, asPrimary } from './utils/format' -import { getRegionDomain, getRegionApiUrl } from './commands/region' +import { getRegionDomain, getRegionApiUrl, DEFAULT_REGION } from './commands/region' export let apiKey = process.env.AGENTBOX_API_KEY export let accessToken = process.env.AGENTBOX_ACCESS_TOKEN @@ -88,21 +88,20 @@ export function ensureAccessToken() { } const userConfig = getUserConfig() +const region = userConfig?.region || DEFAULT_REGION // Inject region-based domain/apiUrl into env so SDK internal calls (Sandbox.list, etc.) also use them -if (userConfig?.region) { - if (!process.env.UCLOUD_SANDBOX_DOMAIN) { - process.env.UCLOUD_SANDBOX_DOMAIN = getRegionDomain(userConfig.region) - } - if (!process.env.UCLOUD_SANDBOX_API_URL) { - process.env.UCLOUD_SANDBOX_API_URL = getRegionApiUrl(userConfig.region) - } +if (!process.env.UCLOUD_SANDBOX_DOMAIN) { + process.env.UCLOUD_SANDBOX_DOMAIN = getRegionDomain(region) +} +if (!process.env.UCLOUD_SANDBOX_API_URL) { + process.env.UCLOUD_SANDBOX_API_URL = getRegionApiUrl(region) } export const connectionConfig = new e2b.ConnectionConfig({ accessToken: process.env.AGENTBOX_ACCESS_TOKEN || userConfig?.accessToken, apiKey: process.env.AGENTBOX_API_KEY || userConfig?.teamApiKey, - domain: process.env.UCLOUD_SANDBOX_DOMAIN || getRegionDomain(userConfig?.region), - apiUrl: process.env.UCLOUD_SANDBOX_API_URL || getRegionApiUrl(userConfig?.region), + domain: process.env.UCLOUD_SANDBOX_DOMAIN || getRegionDomain(region), + apiUrl: process.env.UCLOUD_SANDBOX_API_URL || getRegionApiUrl(region), }) export const client = new e2b.ApiClient(connectionConfig) diff --git a/src/commands/region.ts b/src/commands/region.ts index 22d1f72..d86c00f 100644 --- a/src/commands/region.ts +++ b/src/commands/region.ts @@ -5,6 +5,8 @@ import * as chalk from 'chalk' import { getUserConfig, USER_CONFIG_PATH } from 'src/user' +export const DEFAULT_REGION = 'cn-wlcb' + const REGIONS = [ { id: 'cn-wlcb', name: 'cn-wlcb (China - North)' }, { id: 'us-ca', name: 'us-ca (US - West)' }, @@ -13,13 +15,13 @@ const REGIONS = [ type RegionId = (typeof REGIONS)[number]['id'] export function getRegionDomain(region?: string): string { - if (!region) return 'sandbox.ucloudai.com' - return `${region}.sandbox.ucloudai.com` + const r = region || DEFAULT_REGION + return `${r}.sandbox.ucloudai.com` } export function getRegionApiUrl(region?: string): string { - if (!region) return 'https://api.sandbox.ucloudai.com' - return `https://api.${region}.sandbox.ucloudai.com` + const r = region || DEFAULT_REGION + return `https://api.${r}.sandbox.ucloudai.com` } function switchRegion(region: string) { diff --git a/src/user.ts b/src/user.ts index e09dcc0..b24bd93 100644 --- a/src/user.ts +++ b/src/user.ts @@ -21,7 +21,7 @@ export interface UserConfig { export const USER_CONFIG_PATH = path.join(os.homedir(), '.ucloud-sandbox-cli', 'config.json') export const DOCS_BASE = process.env.UCLOUD_SANDBOX_DOCS_BASE || - `https://${process.env.UCLOUD_SANDBOX_DOMAIN || 'sandbox.ucloudai.com'}/docs` + `https://${process.env.UCLOUD_SANDBOX_DOMAIN || 'cn-wlcb.sandbox.ucloudai.com'}/docs` export function getUserConfig(): UserConfig | null { if (!fs.existsSync(USER_CONFIG_PATH)) return null