diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 23570ac4..a303ea92 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha":"ce516de","timestamp":1735032908} \ No newline at end of file +{"sha":"87f7151","timestamp":1735035314} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 0b431907..a8171ecc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,42 +1,3 @@ -class EnvironmentConfig { - LANGUAGE = "zh-cn"; - UPDATE_BRANCH = "master"; - CHAT_COMPLETE_API_TIMEOUT = 0; - TELEGRAM_API_DOMAIN = "https://api.telegram.org"; - TELEGRAM_AVAILABLE_TOKENS = []; - DEFAULT_PARSE_MODE = "Markdown"; - TELEGRAM_MIN_STREAM_INTERVAL = 0; - TELEGRAM_PHOTO_SIZE_OFFSET = 1; - TELEGRAM_IMAGE_TRANSFER_MODE = "base64"; - MODEL_LIST_COLUMNS = 1; - I_AM_A_GENEROUS_PERSON = false; - CHAT_WHITE_LIST = []; - LOCK_USER_CONFIG_KEYS = [ - "OPENAI_API_BASE", - "GOOGLE_COMPLETIONS_API", - "MISTRAL_API_BASE", - "COHERE_API_BASE", - "ANTHROPIC_API_BASE", - "AZURE_COMPLETIONS_API", - "AZURE_DALLE_API" - ]; - TELEGRAM_BOT_NAME = []; - CHAT_GROUP_WHITE_LIST = []; - GROUP_CHAT_BOT_ENABLE = true; - GROUP_CHAT_BOT_SHARE_MODE = true; - AUTO_TRIM_HISTORY = true; - MAX_HISTORY_LENGTH = 20; - MAX_TOKEN_LENGTH = -1; - HISTORY_IMAGE_PLACEHOLDER = null; - HIDE_COMMAND_BUTTONS = []; - SHOW_REPLY_BUTTON = false; - EXTRA_MESSAGE_CONTEXT = false; - EXTRA_MESSAGE_MEDIA_COMPATIBLE = ["image"]; - STREAM_MODE = true; - SAFE_MODE = true; - DEBUG_MODE = false; - DEV_MODE = false; -} class AgentShareConfig { AI_PROVIDER = "auto"; AI_IMAGE_PROVIDER = "auto"; @@ -98,6 +59,43 @@ class AnthropicConfig { class DefineKeys { DEFINE_KEYS = []; } +class EnvironmentConfig { + LANGUAGE = "zh-cn"; + UPDATE_BRANCH = "master"; + CHAT_COMPLETE_API_TIMEOUT = 0; + TELEGRAM_API_DOMAIN = "https://api.telegram.org"; + TELEGRAM_AVAILABLE_TOKENS = []; + DEFAULT_PARSE_MODE = "Markdown"; + TELEGRAM_MIN_STREAM_INTERVAL = 0; + TELEGRAM_PHOTO_SIZE_OFFSET = 1; + TELEGRAM_IMAGE_TRANSFER_MODE = "base64"; + MODEL_LIST_COLUMNS = 1; + I_AM_A_GENEROUS_PERSON = false; + CHAT_WHITE_LIST = []; + LOCK_USER_CONFIG_KEYS = [ + "OPENAI_API_BASE", + "GOOGLE_API_BASE", + "MISTRAL_API_BASE", + "COHERE_API_BASE", + "ANTHROPIC_API_BASE" + ]; + TELEGRAM_BOT_NAME = []; + CHAT_GROUP_WHITE_LIST = []; + GROUP_CHAT_BOT_ENABLE = true; + GROUP_CHAT_BOT_SHARE_MODE = true; + AUTO_TRIM_HISTORY = true; + MAX_HISTORY_LENGTH = 20; + MAX_TOKEN_LENGTH = -1; + HISTORY_IMAGE_PLACEHOLDER = null; + HIDE_COMMAND_BUTTONS = []; + SHOW_REPLY_BUTTON = false; + EXTRA_MESSAGE_CONTEXT = false; + EXTRA_MESSAGE_MEDIA_COMPATIBLE = ["image"]; + STREAM_MODE = true; + SAFE_MODE = true; + DEBUG_MODE = false; + DEV_MODE = false; +} const en = { "env": { "system_init_message": "You are a helpful assistant" }, "command": { "help": { "summary": "The following commands are currently supported:\n", "help": "Get command help", "new": "Start a new conversation", "start": "Get your ID and start a new conversation", "img": "Generate an image, the complete command format is `/img image description`, for example `/img beach at moonlight`", "version": "Get the current version number to determine whether to update", "setenv": "Set user configuration, the complete command format is /setenv KEY=VALUE", "setenvs": 'Batch set user configurations, the full format of the command is /setenvs {"KEY1": "VALUE1", "KEY2": "VALUE2"}', "delenv": "Delete user configuration, the complete command format is /delenv KEY", "clearenv": "Clear all user configuration", "system": "View some system information", "redo": "Redo the last conversation, /redo with modified content or directly /redo", "echo": "Echo the message", "models": "switch chat model" }, "new": { "new_chat_start": "A new conversation has started" } }, "callback_query": { "open_model_list": "Open models list", "select_provider": "Select a provider:", "select_model": "Choose model:", "change_model": "Change model to " } }; const pt = { "env": { "system_init_message": "Você é um assistente útil" }, "command": { "help": { "summary": "Os seguintes comandos são suportados atualmente:\n", "help": "Obter ajuda sobre comandos", "new": "Iniciar uma nova conversa", "start": "Obter seu ID e iniciar uma nova conversa", "img": "Gerar uma imagem, o formato completo do comando é `/img descrição da imagem`, por exemplo `/img praia ao luar`", "version": "Obter o número da versão atual para determinar se é necessário atualizar", "setenv": "Definir configuração do usuário, o formato completo do comando é /setenv CHAVE=VALOR", "setenvs": 'Definir configurações do usuário em lote, o formato completo do comando é /setenvs {"CHAVE1": "VALOR1", "CHAVE2": "VALOR2"}', "delenv": "Excluir configuração do usuário, o formato completo do comando é /delenv CHAVE", "clearenv": "Limpar todas as configurações do usuário", "system": "Ver algumas informações do sistema", "redo": "Refazer a última conversa, /redo com conteúdo modificado ou diretamente /redo", "echo": "Repetir a mensagem", "models": "Mudar o modelo de diálogo" }, "new": { "new_chat_start": "Uma nova conversa foi iniciada" } }, "callback_query": { "open_model_list": "Abra a lista de modelos", "select_provider": "Escolha um fornecedor de modelos.:", "select_model": "Escolha um modelo:", "change_model": "O modelo de diálogo já foi modificado para" } }; const zhHans = { "env": { "system_init_message": "你是一个得力的助手" }, "command": { "help": { "summary": "当前支持以下命令:\n", "help": "获取命令帮助", "new": "发起新的对话", "start": "获取你的ID, 并发起新的对话", "img": "生成一张图片, 命令完整格式为 `/img 图片描述`, 例如`/img 月光下的沙滩`", "version": "获取当前版本号, 判断是否需要更新", "setenv": "设置用户配置,命令完整格式为 /setenv KEY=VALUE", "setenvs": '批量设置用户配置, 命令完整格式为 /setenvs {"KEY1": "VALUE1", "KEY2": "VALUE2"}', "delenv": "删除用户配置,命令完整格式为 /delenv KEY", "clearenv": "清除所有用户配置", "system": "查看当前一些系统信息", "redo": "重做上一次的对话, /redo 加修改过的内容 或者 直接 /redo", "echo": "回显消息", "models": "切换对话模型" }, "new": { "new_chat_start": "新的对话已经开始" } }, "callback_query": { "open_model_list": "打开模型列表", "select_provider": "选择一个模型提供商:", "select_model": "选择一个模型:", "change_model": "对话模型已修改至" } }; @@ -194,8 +192,8 @@ class ConfigMerger { } } } -const BUILD_TIMESTAMP = 1735032142; -const BUILD_VERSION = "ce516de"; +const BUILD_TIMESTAMP = 1735035314; +const BUILD_VERSION = "87f7151"; function createAgentUserConfig() { return Object.assign( {}, diff --git a/packages/lib/core/src/config/config.ts b/packages/lib/core/src/config/config.ts index 715b52ab..aa81b58b 100644 --- a/packages/lib/core/src/config/config.ts +++ b/packages/lib/core/src/config/config.ts @@ -116,21 +116,14 @@ export class AnthropicConfig { ANTHROPIC_CHAT_MODELS_LIST = ''; } -export type AIProviderConfig = OpenAIConfig & - DallEConfig & - AzureConfig & - WorkersConfig & - GeminiConfig & - MistralConfig & - CohereConfig & - AnthropicConfig; +type UserConfig = AgentShareConfig & OpenAIConfig & DallEConfig & AzureConfig & WorkersConfig & GeminiConfig & MistralConfig & CohereConfig & AnthropicConfig; +export type AgentUserConfigKey = keyof UserConfig; export class DefineKeys { DEFINE_KEYS: AgentUserConfigKey[] = []; } -export type AgentUserConfig = Record & DefineKeys & AIProviderConfig; -export type AgentUserConfigKey = keyof AIProviderConfig; +export type AgentUserConfig = Record & DefineKeys & UserConfig; // -- 只能通过环境变量覆盖的配置 -- export class EnvironmentConfig { diff --git a/packages/lib/core/src/config/version.ts b/packages/lib/core/src/config/version.ts index 614afafb..856c1f07 100644 --- a/packages/lib/core/src/config/version.ts +++ b/packages/lib/core/src/config/version.ts @@ -1,2 +1,2 @@ -export const BUILD_TIMESTAMP = 1735032908; -export const BUILD_VERSION = 'ce516de'; +export const BUILD_TIMESTAMP = 1735035314; +export const BUILD_VERSION = '87f7151'; diff --git a/packages/lib/core/src/telegram/command/system.ts b/packages/lib/core/src/telegram/command/system.ts index 465b6a1f..1244249f 100644 --- a/packages/lib/core/src/telegram/command/system.ts +++ b/packages/lib/core/src/telegram/command/system.ts @@ -1,5 +1,5 @@ import type { HistoryItem, HistoryModifierResult, UserMessageItem } from '#/agent'; -import type { WorkerContext } from '#/config'; +import type {AgentUserConfigKey, WorkerContext} from '#/config'; import type * as Telegram from 'telegram-bot-api-types'; import type { CommandHandler } from './types'; import { loadChatLLM, loadImageGen } from '#/agent'; @@ -129,7 +129,7 @@ export class SetEnvCommandHandler implements CommandHandler { const key = subcommand.slice(0, kv); const value = subcommand.slice(kv + 1); try { - await context.execChangeAndSave({ [key]: value }); + await context.execChangeAndSave({ [key]: value } as Record); return sender.sendPlainText('Update user config success'); } catch (e) { return sender.sendPlainText(`ERROR: ${(e as Error).message}`); @@ -157,7 +157,7 @@ export class DelEnvCommandHandler implements CommandHandler { needAuth = TELEGRAM_AUTH_CHECKER.shareModeGroup; handle = async (message: Telegram.Message, subcommand: string, context: WorkerContext): Promise => { const sender = MessageSender.fromMessage(context.SHARE_CONTEXT.botToken, message); - if (ENV.LOCK_USER_CONFIG_KEYS.includes(subcommand)) { + if (ENV.LOCK_USER_CONFIG_KEYS.includes(subcommand as AgentUserConfigKey)) { const msg = `Key ${subcommand} is locked`; return sender.sendPlainText(msg); }