Skip to content

Commit d7c546e

Browse files
committed
refactor: Remove deprecated ENV_KEY_MAPPER and clean up environment migration logic
Signed-off-by: tbxark <tbxark@outlook.com>
1 parent 15844a1 commit d7c546e

File tree

2 files changed

+2
-68
lines changed

2 files changed

+2
-68
lines changed

packages/lib/core/src/config/context.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AgentUserConfig, AgentUserConfigKey } from '#/config/config';
22
import type * as Telegram from 'telegram-bot-api-types';
3-
import { ENV, ENV_KEY_MAPPER } from './env';
3+
import { ENV } from './env';
44
import { ConfigMerger } from './merger';
55

66
function cloneAgentUserConfig(source: AgentUserConfig): AgentUserConfig {
@@ -109,8 +109,7 @@ export class WorkerContext {
109109

110110
async execChangeAndSave(values: Record<AgentUserConfigKey, any>): Promise<void> {
111111
for (const ent of Object.entries(values || {})) {
112-
let [key, value] = ent as [AgentUserConfigKey, any];
113-
key = ENV_KEY_MAPPER[key] || key;
112+
const [key, value] = ent as [AgentUserConfigKey, any];
114113
if (ENV.LOCK_USER_CONFIG_KEYS.includes(key)) {
115114
throw new Error(`Key ${key} is locked`);
116115
}

packages/lib/core/src/config/env.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ function fixApiBase(base: string): string {
5050
return base.replace(/\/+$/, '');
5151
}
5252

53-
export const ENV_KEY_MAPPER: Record<string, AgentUserConfigKey> = {
54-
CHAT_MODEL: 'OPENAI_CHAT_MODEL',
55-
API_KEY: 'OPENAI_API_KEY',
56-
WORKERS_AI_MODEL: 'WORKERS_CHAT_MODEL',
57-
};
58-
5953
export type CustomMessageRender = (mode: string | null, message: string) => string;
6054

6155
class Environment extends EnvironmentConfig {
@@ -131,7 +125,6 @@ class Environment extends EnvironmentConfig {
131125
'API_GUARD',
132126
]);
133127
ConfigMerger.merge(this.USER_CONFIG, source);
134-
this.migrateOldEnv(source);
135128
this.fixAgentUserConfigApiBase();
136129
this.USER_CONFIG.DEFINE_KEYS = [];
137130
this.I18N = loadI18n(this.LANGUAGE.toLowerCase());
@@ -150,64 +143,6 @@ class Environment extends EnvironmentConfig {
150143
}
151144
}
152145

153-
private migrateOldEnv(source: any) {
154-
// 兼容旧版 TELEGRAM_TOKEN
155-
if (source.TELEGRAM_TOKEN && !this.TELEGRAM_AVAILABLE_TOKENS.includes(source.TELEGRAM_TOKEN)) {
156-
if (source.BOT_NAME && this.TELEGRAM_AVAILABLE_TOKENS.length === this.TELEGRAM_BOT_NAME.length) {
157-
this.TELEGRAM_BOT_NAME.push(source.BOT_NAME);
158-
}
159-
this.TELEGRAM_AVAILABLE_TOKENS.push(source.TELEGRAM_TOKEN);
160-
}
161-
162-
// 兼容旧版 OPENAI_API_DOMAIN
163-
if (source.OPENAI_API_DOMAIN && !this.USER_CONFIG.OPENAI_API_BASE) {
164-
this.USER_CONFIG.OPENAI_API_BASE = `${source.OPENAI_API_DOMAIN}/v1`;
165-
}
166-
167-
// 兼容旧版 WORKERS_AI_MODEL
168-
if (source.WORKERS_AI_MODEL && !this.USER_CONFIG.WORKERS_CHAT_MODEL) {
169-
this.USER_CONFIG.WORKERS_CHAT_MODEL = source.WORKERS_AI_MODEL;
170-
}
171-
172-
// 兼容旧版API_KEY
173-
if (source.API_KEY && this.USER_CONFIG.OPENAI_API_KEY.length === 0) {
174-
this.USER_CONFIG.OPENAI_API_KEY = source.API_KEY.split(',');
175-
}
176-
177-
// 兼容旧版CHAT_MODEL
178-
if (source.CHAT_MODEL && !this.USER_CONFIG.OPENAI_CHAT_MODEL) {
179-
this.USER_CONFIG.OPENAI_CHAT_MODEL = source.CHAT_MODEL;
180-
}
181-
182-
// 选择对应语言的SYSTEM_INIT_MESSAGE
183-
// if (!this.USER_CONFIG.SYSTEM_INIT_MESSAGE) {
184-
// this.USER_CONFIG.SYSTEM_INIT_MESSAGE = this.I18N?.env?.system_init_message || 'You are a helpful assistant';
185-
// }
186-
// 兼容旧版 GOOGLE_COMPLETIONS_API
187-
if (source.GOOGLE_COMPLETIONS_API && !this.USER_CONFIG.GOOGLE_API_BASE) {
188-
this.USER_CONFIG.GOOGLE_API_BASE = source.GOOGLE_COMPLETIONS_API.replace(/\/models\/?$/, '');
189-
}
190-
191-
if (source.GOOGLE_COMPLETIONS_MODEL && !this.USER_CONFIG.GOOGLE_CHAT_MODEL) {
192-
this.USER_CONFIG.GOOGLE_CHAT_MODEL = source.GOOGLE_COMPLETIONS_MODEL;
193-
}
194-
195-
// 兼容旧版 AZURE_COMPLETIONS_API
196-
if (source.AZURE_COMPLETIONS_API && !this.USER_CONFIG.AZURE_CHAT_MODEL) {
197-
const url = new URL(source.AZURE_COMPLETIONS_API);
198-
this.USER_CONFIG.AZURE_RESOURCE_NAME = url.hostname.split('.').at(0) || null;
199-
this.USER_CONFIG.AZURE_CHAT_MODEL = url.pathname.split('/').at(3) || 'gpt-5-mini';
200-
this.USER_CONFIG.AZURE_API_VERSION = url.searchParams.get('api-version') || '2024-06-01';
201-
}
202-
// 兼容旧版 AZURE_DALLE_API
203-
if (source.AZURE_DALLE_API && !this.USER_CONFIG.AZURE_IMAGE_MODEL) {
204-
const url = new URL(source.AZURE_DALLE_API);
205-
this.USER_CONFIG.AZURE_RESOURCE_NAME = url.hostname.split('.').at(0) || null;
206-
this.USER_CONFIG.AZURE_IMAGE_MODEL = url.pathname.split('/').at(3) || 'dall-e-3';
207-
this.USER_CONFIG.AZURE_API_VERSION = url.searchParams.get('api-version') || '2024-06-01';
208-
}
209-
}
210-
211146
private fixAgentUserConfigApiBase() {
212147
const keys: AgentUserConfigKey[] = [
213148
'OPENAI_API_BASE',

0 commit comments

Comments
 (0)