Files
DeepTutor/deeptutor/core/i18n.py
Bingxi Zhao (Frank) 740ec413a0 release: v1.5.7
Per-account MCP Services and CLI Apps — the two ways a deployment plugs in
tools DeepTutor never shipped — plus the isolation that makes them safe on a
shared install.

- MCP Services: a 45-entry curated store of hosted servers each account
  installs for itself, OAuth 2.1 (PKCE + dynamic client registration) for the
  servers that require it, static keys held by reference and resolved in memory
  at connect time, stdio refused for self-service. Settings no longer
  configures MCP; /settings/mcp redirects to the store.
- CLI Apps: 101 tools snapshotted from the two CLI-Anything registries.
  Installs are admin-only, the registry's install_cmd is parsed into an argv we
  build rather than executed, npm install scripts are forced off, and 66
  first-party entries are pinned to one reviewed commit. Apps land in
  data/cli-apps, one environment each, mounted read-only into the runner.
- Credentials that authorise a person move to data/system, the one branch the
  exec sandbox never mounts: Codex tokens relocate themselves on first use
  (refusing to follow a symlink), per-user MCP configs and keys land beside
  them.
- Grants gain a cli_apps whitelist with the same deny-by-default posture as
  MCP tools; a per-turn registry view keeps one owner's provider tools out of
  the process-global registry and refuses an unauthorised tool at execute, not
  just in the manifest.
- The composer reports what filled this turn's context window, a gutter rail
  jumps back through long conversations, and the workspace collapses to a
  drawer on small screens.
- The composer keeps focus after sending and across tab switches (#720);
  released images carry provenance and SBOM attestations (#722).

README prose, all ten translated READMEs, and the docs-site pages that named
Settings → MCP are updated to match. Release notes:
assets/releases/ver1-5-7.md
2026-07-31 00:25:48 +08:00

134 lines
7.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Small runtime i18n helper for backend-facing user messages."""
from __future__ import annotations
from typing import Any
def _parse_language(language: str | None) -> str:
raw = (language or "en").strip().lower()
if raw.startswith("zh") or raw in {"cn", "chinese"}:
return "zh"
return "en"
_MESSAGES: dict[str, dict[str, str]] = {
"en": {
"api.content_required": "content is required",
"api.invalid_channels_config": "Invalid channels config",
"api.partner_already_exists": "Partner '{name}' already exists",
"api.partner_not_found": "Partner not found",
"api.partner_not_found_or_not_running": "Partner not found or not running",
"api.partner_not_running": "Partner not running",
"api.partner_stopped_start_required": "Partner is stopped. Start it before chatting.",
"api.persona_already_exists": "Persona already exists: {name}",
"api.persona_name_required": "Persona name is required",
"api.persona_not_found": "Persona not found: {name}",
"api.soul_already_exists": "Soul '{name}' already exists",
"api.soul_content_empty": "Custom soul content is empty",
"api.soul_library_not_found": "Soul '{name}' not found in library",
"api.soul_not_found": "Soul not found",
"api.tool_not_found": "Tool '{name}' not found",
"cli_apps.abi_mismatch": (
"The CLI app {app!r} was installed for {installed} but this runtime is "
"{current}. An administrator needs to reinstall it."
),
"cli_apps.args_required": (
"{tool} needs an 'args' array — one command-line argument per element."
),
"cli_apps.entry_admin_only": (
"CLI apps are installed by an administrator; ask yours to add this one."
),
"cli_apps.install_in_progress": "That app is already being installed.",
"cli_apps.not_in_catalog": "No CLI app named {id!r} in the catalog.",
"cli_apps.not_installed": (
"The CLI app {app!r} is not installed on this deployment any more."
),
"cli_apps.still_running": "{app} is still running ({seconds}s)",
"mcp.configure_command_or_url": "Server {name!r}: configure either a command (stdio) or a url.",
"mcp.configure_before_testing": "Configure either a command (stdio) or a url before testing.",
"mcp.server_error": "Server {name!r}: {error}",
"mcp.server_missing": "No server named {name!r} in your list.",
"mcp.not_oauth": "This server does not use OAuth; give it a credential instead.",
"mcp.oauth_callback_incomplete": "The authorization response was incomplete.",
"mcp.oauth_callback_unknown": "That authorization has expired or already completed. Start it again.",
"mcp.oauth_done": "Authorized. You can close this tab.",
"mcp.oauth_failed": "Authorization failed.",
"mcp.catalog_entry_missing": "No MCP service named {id!r} in the catalog.",
"mcp.entry_admin_only": (
"This service runs as a local command and can only be added by an administrator."
),
"mcp.tool_not_available": (
"This tool is not available in this conversation. "
"Only the tools listed in the prompt can be called."
),
"sandbox.command_blocked": "Error: command blocked by safety guard (dangerous pattern).",
"sandbox.disabled_for_account": "Code execution is disabled for your account.",
"sandbox.no_backend": "no sandbox backend available",
},
"zh": {
"api.content_required": "content 不能为空",
"api.invalid_channels_config": "渠道配置无效",
"api.partner_already_exists": "伙伴 '{name}' 已存在",
"api.partner_not_found": "未找到伙伴",
"api.partner_not_found_or_not_running": "未找到伙伴或伙伴未运行",
"api.partner_not_running": "伙伴未运行",
"api.partner_stopped_start_required": "伙伴已停止。请先启动后再聊天。",
"api.persona_already_exists": "Persona 已存在:{name}",
"api.persona_name_required": "Persona 名称不能为空",
"api.persona_not_found": "未找到 Persona:{name}",
"api.soul_already_exists": "Soul '{name}' 已存在",
"api.soul_content_empty": "自定义 soul 内容为空",
"api.soul_library_not_found": "素材库中未找到 soul '{name}'",
"api.soul_not_found": "未找到 soul",
"api.tool_not_found": "未找到工具 '{name}'",
"cli_apps.abi_mismatch": (
"CLI 应用 {app!r} 是为 {installed} 安装的,当前运行环境是 {current},需要管理员重新安装。"
),
"cli_apps.args_required": "{tool} 需要 args 数组:每个命令行参数占一个元素。",
"cli_apps.entry_admin_only": "CLI 应用由管理员安装,请联系管理员添加。",
"cli_apps.install_in_progress": "该应用正在安装中。",
"cli_apps.not_in_catalog": "目录中没有名为 {id!r} 的 CLI 应用。",
"cli_apps.not_installed": "CLI 应用 {app!r} 已不在本部署中。",
"cli_apps.still_running": "{app} 仍在运行(已 {seconds} 秒)",
"mcp.configure_command_or_url": "服务器 {name!r}:请配置 command(stdio)或 url。",
"mcp.configure_before_testing": "测试前请先配置 command(stdio)或 url。",
"mcp.server_error": "服务器 {name!r}:{error}",
"mcp.server_missing": "你的列表中没有名为 {name!r} 的服务器。",
"mcp.not_oauth": "该服务器不使用 OAuth,请改为填写凭据。",
"mcp.oauth_callback_incomplete": "授权回调信息不完整。",
"mcp.oauth_callback_unknown": "该授权已过期或已完成,请重新发起。",
"mcp.oauth_done": "已授权,可以关闭此页。",
"mcp.oauth_failed": "授权失败。",
"mcp.catalog_entry_missing": "目录中没有名为 {id!r} 的 MCP 服务。",
"mcp.entry_admin_only": "该服务以本地命令方式运行,只能由管理员添加。",
"mcp.tool_not_available": "该工具在本次对话中不可用,只能调用提示中列出的工具。",
"sandbox.command_blocked": "错误:命令被安全防护拦截(匹配危险模式)。",
"sandbox.disabled_for_account": "你的账号已禁用代码执行。",
"sandbox.no_backend": "没有可用的沙箱后端",
},
}
def current_language(default: str = "en") -> str:
try:
from deeptutor.services.settings.interface_settings import get_ui_language
return _parse_language(get_ui_language(default=default))
except Exception:
return _parse_language(default)
def t(key: str, default: str = "", *, language: str | None = None, **kwargs: Any) -> str:
lang = _parse_language(language) if language else current_language()
text = _MESSAGES.get(lang, {}).get(key) or _MESSAGES["en"].get(key) or default
if kwargs:
try:
return text.format(**kwargs)
except (KeyError, IndexError, ValueError):
return text
return text
__all__ = ["current_language", "t"]