diff --git a/eslint.config.js b/eslint.config.js index 786b1431..b2ef890a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,12 +1,14 @@ import antfu, { imports, javascript, jsdoc, node, typescript } from '@antfu/eslint-config'; -export default antfu( +/** @type {import('eslint-flat-config-utils').FlatConfigComposer} */ +const config = antfu( { type: 'app', stylistic: { indent: 4, quotes: 'single', semi: true, + // @ts-ignore braceStyle: '1tbs', }, markdown: false, @@ -40,3 +42,5 @@ export default antfu( }, }, ); + +export default config; diff --git a/packages/lib/core/src/config/env.ts b/packages/lib/core/src/config/env.ts index 3845655b..35701a16 100644 --- a/packages/lib/core/src/config/env.ts +++ b/packages/lib/core/src/config/env.ts @@ -39,6 +39,10 @@ function createAgentUserConfig(): AgentUserConfig { ); } +function fixApiBase(base: string): string { + return base.replace(/\/+$/, ''); +} + export const ENV_KEY_MAPPER: Record = { CHAT_MODEL: 'OPENAI_CHAT_MODEL', API_KEY: 'OPENAI_API_KEY', @@ -121,6 +125,7 @@ class Environment extends EnvironmentConfig { ]); ConfigMerger.merge(this.USER_CONFIG, source); this.migrateOldEnv(source); + this.fixAgentUserConfigApiBase(); this.USER_CONFIG.DEFINE_KEYS = []; this.I18N = loadI18n(this.LANGUAGE.toLowerCase()); } @@ -195,6 +200,23 @@ class Environment extends EnvironmentConfig { this.USER_CONFIG.AZURE_API_VERSION = url.searchParams.get('api-version') || '2024-06-01'; } } + + private fixAgentUserConfigApiBase() { + const keys: AgentUserConfigKey[] = [ + 'OPENAI_API_BASE', + 'GOOGLE_API_BASE', + 'MISTRAL_API_BASE', + 'COHERE_API_BASE', + 'ANTHROPIC_API_BASE', + ]; + for (const key of keys) { + const base = this.USER_CONFIG[key]; + if (this.USER_CONFIG[key] && typeof base === 'string') { + this.USER_CONFIG[key] = fixApiBase(base) as any; + } + } + this.TELEGRAM_API_DOMAIN = fixApiBase(this.TELEGRAM_API_DOMAIN); + } } export const ENV = new Environment(); diff --git a/packages/lib/core/src/telegram/api/index.ts b/packages/lib/core/src/telegram/api/index.ts index 88e133c3..71a0be0e 100644 --- a/packages/lib/core/src/telegram/api/index.ts +++ b/packages/lib/core/src/telegram/api/index.ts @@ -8,10 +8,7 @@ class APIClientBase { constructor(token: string, baseURL?: string) { this.token = token; if (baseURL) { - this.baseURL = baseURL; - } - while (this.baseURL.endsWith('/')) { - this.baseURL = this.baseURL.slice(0, -1); + this.baseURL = baseURL.replace(/\/+$/, ''); } this.request = this.request.bind(this); this.requestJSON = this.requestJSON.bind(this); diff --git a/wrangler-example.toml b/wrangler-example.toml index 6141f150..dcdcf699 100644 --- a/wrangler-example.toml +++ b/wrangler-example.toml @@ -10,7 +10,6 @@ main = './dist/index.js' # 先使用vite编译 然后再使用编译产物部 #main = './packages/apps/workers-next/dist/index.js' #main = './packages/apps/workers-next/src/index.ts' workers_dev = true -compatibility_flags = ["nodejs_compat_v2"] # 这里的 id 为必填项 请填写你的 kv namespace id # preview_id 只在调试时使用,不需要请删除 kv_namespaces = [