docs: 将仓库代码注释统一为中文
CI / docs-check (push) Canceled after 0s
CI / backend-test (push) Canceled after 0s
CI / service-test (push) Canceled after 0s
CI / frontend-test (push) Canceled after 0s
CI / rust-core (push) Canceled after 0s
CI / docs-check (pull_request) Canceled after 0s
CI / backend-test (pull_request) Canceled after 0s
CI / service-test (pull_request) Canceled after 0s
CI / frontend-test (pull_request) Canceled after 0s
CI / rust-core (pull_request) Canceled after 0s
CI / docs-check (push) Canceled after 0s
CI / backend-test (push) Canceled after 0s
CI / service-test (push) Canceled after 0s
CI / frontend-test (push) Canceled after 0s
CI / rust-core (push) Canceled after 0s
CI / docs-check (pull_request) Canceled after 0s
CI / backend-test (pull_request) Canceled after 0s
CI / service-test (pull_request) Canceled after 0s
CI / frontend-test (pull_request) Canceled after 0s
CI / rust-core (pull_request) Canceled after 0s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Bounded ZIP extraction for packages uploaded to the AI Core host."""
|
||||
"""上传到 AI Core 主机的包的有限 ZIP 提取。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
@@ -31,7 +31,7 @@ def install_zip(data: bytes, kind: str, storage: Path, install: Callable[[Path],
|
||||
if kind not in ('skill', 'plugin'):
|
||||
raise ValueError('Unknown extension kind')
|
||||
storage.mkdir(parents=True, exist_ok=True)
|
||||
# Retain successful extraction: Plugin commands and resources use this directory.
|
||||
# 保留成功提取:Plugin 命令和资源使用此目录。
|
||||
destination = Path(tempfile.mkdtemp(prefix=f'{kind}-', dir=storage))
|
||||
try:
|
||||
with zipfile.ZipFile(io.BytesIO(data)) as archive:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Local installation journal. Only explicitly managed ZIP roots may be removed."""
|
||||
"""本地安装日志。只能删除显式管理的 ZIP 根。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
@@ -83,7 +83,7 @@ class InstalledRuntime:
|
||||
def install(self, package_path, *, managed_root=None):
|
||||
with self.lock:
|
||||
root = Path(package_path).resolve()
|
||||
package_digest(root) # Check before changing runtime state.
|
||||
package_digest(root) # 更改运行时状态之前检查。
|
||||
if managed_root is not None:
|
||||
owned = Path(managed_root).resolve()
|
||||
if owned.parent != self.storage or not root.is_relative_to(owned):
|
||||
@@ -100,7 +100,7 @@ class InstalledRuntime:
|
||||
|
||||
def enable(self, identifier):
|
||||
with self.lock:
|
||||
# Changed packages must be reinstalled to re-parse their declarations.
|
||||
# 必须重新安装更改的软件包以重新解析其声明。
|
||||
saved = self._read(identifier)
|
||||
root = self.runtime._record(identifier).package_path
|
||||
if saved and saved.get('digest') != package_digest(root):
|
||||
@@ -132,7 +132,7 @@ class InstalledRuntime:
|
||||
def _cleanup(self, saved):
|
||||
raw = saved.get('managed_root')
|
||||
if not raw:
|
||||
return # Directory installs belong to the user.
|
||||
return # 目录安装属于用户。
|
||||
path = Path(raw)
|
||||
if path.is_symlink() or path.resolve().parent != self.storage:
|
||||
raise ValueError('Refusing to remove an unmanaged package directory')
|
||||
|
||||
@@ -383,7 +383,7 @@ class McpStdioClient:
|
||||
|
||||
|
||||
class McpHttpClient:
|
||||
"""MCP Streamable HTTP client supporting JSON and SSE POST responses."""
|
||||
"""MCP 可流式 HTTP 客户端,支持 JSON 和 SSE POST 响应。"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -722,7 +722,7 @@ class McpHttpClient:
|
||||
|
||||
|
||||
class McpLegacySseClient(McpHttpClient):
|
||||
"""Compatibility client for the deprecated 2024-11-05 HTTP+SSE transport."""
|
||||
"""已弃用的 2024 年 11 月 5 日 HTTP+SSE 传输的兼容性客户端。"""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -744,7 +744,7 @@ class McpLegacySseClient(McpHttpClient):
|
||||
self._endpoint = endpoint
|
||||
|
||||
def start_event_stream(self) -> None:
|
||||
"""The legacy client already owns its single GET event stream."""
|
||||
"""旧客户端已拥有其单个 GET 事件流。"""
|
||||
|
||||
return
|
||||
|
||||
@@ -1387,11 +1387,7 @@ def _bounded_json_response(response: httpx.Response) -> dict[str, Any]:
|
||||
|
||||
|
||||
def _bounded_sse_lines(response: httpx.Response):
|
||||
"""Split UTF-8 lines without httpx.iter_lines()'s unbounded line buffer.
|
||||
|
||||
Check each segment before appending it, including partial/no-newline input.
|
||||
SSE allows LF, CR and CRLF; a CRLF pair can span network chunks.
|
||||
"""
|
||||
"""在没有 httpx.iter_lines() 的无限行缓冲区的情况下分割 UTF-8 行。在附加之前检查每个段,包括部分/无换行输入。 SSE 允许 LF、CR 和 CRLF; CRLF 对可以跨越网络块。"""
|
||||
|
||||
pending = bytearray()
|
||||
event_size = 0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Independent, user-managed MCP server registry for development builds."""
|
||||
"""用于开发构建的独立的、用户管理的 MCP 服务器注册表。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -46,18 +46,14 @@ _MAX_MCP_SERVERS = 256
|
||||
|
||||
|
||||
class _McpConnectionBackend(PluginBackend):
|
||||
"""Bridge adapter for the independent server's float timeout contract.
|
||||
|
||||
Plugin manifests retain their integer/60-second startup restrictions.
|
||||
Reusing that validation here used to reject valid 120-second server configs.
|
||||
"""
|
||||
"""适配独立服务器浮点超时约定的桥接器。Plugin 清单仍采用整数和 60 秒启动限制;这里若复用该校验,会错误拒绝有效的 120 秒服务器配置。"""
|
||||
|
||||
startup_timeout_seconds: float = Field(default=15, ge=1, le=120)
|
||||
tool_timeout_seconds: float = Field(default=30, ge=1, le=300)
|
||||
|
||||
|
||||
class _McpServerRecord(McpServerConfig):
|
||||
"""Validated on-disk representation with defaults for older C.1 records."""
|
||||
"""已验证磁盘上的表示形式以及旧 C.1 记录的默认值。"""
|
||||
|
||||
version: int = Field(default=1, ge=1)
|
||||
secret_environment_version: Literal[1, 2] = 1
|
||||
@@ -81,7 +77,7 @@ class McpRegistryError(RuntimeError):
|
||||
|
||||
|
||||
def _serialized_lifecycle(method):
|
||||
"""Serialize lifecycle mutations without blocking MCP failure callbacks."""
|
||||
"""序列化生命周期变更而不阻止 MCP 失败回调。"""
|
||||
|
||||
@wraps(method)
|
||||
def wrapped(self, *args, **kwargs):
|
||||
@@ -92,7 +88,7 @@ def _serialized_lifecycle(method):
|
||||
|
||||
|
||||
class McpServerRegistry:
|
||||
"""Persists configuration and owns stdio host/tool lifecycles."""
|
||||
"""保留配置并拥有 stdio 主机/工具生命周期。"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -480,7 +476,7 @@ class McpServerRegistry:
|
||||
)
|
||||
headers[key] = value
|
||||
host_id = self._host_id(server_id)
|
||||
# A queued callback from the previous process must not affect its replacement.
|
||||
# 来自前一进程的排队回调不得影响其替换。
|
||||
generation = object()
|
||||
self._generations[server_id] = generation
|
||||
self.bridge.remove(host_id)
|
||||
@@ -528,8 +524,7 @@ class McpServerRegistry:
|
||||
self.tools.register(definition, arguments_model, executor)
|
||||
|
||||
def _unavailable(self, server_id: str, generation: object, message: str) -> None:
|
||||
# A failure may race with enable(). Waiting for the lifecycle mutation makes
|
||||
# sure tools registered immediately before the callback are also removed.
|
||||
# 故障可能与 enable() 发生竞争;等待生命周期变更完成,可确保回调前刚注册的工具也被移除。
|
||||
with self._lifecycle_lock:
|
||||
if self._generations.get(server_id) is not generation:
|
||||
return
|
||||
@@ -548,9 +543,7 @@ class McpServerRegistry:
|
||||
}
|
||||
self._write()
|
||||
finally:
|
||||
# broken() can run on the client's reader/event thread. stop() does
|
||||
# not join that thread, and setting _stopping before closing the
|
||||
# transport prevents the close itself from reporting another failure.
|
||||
# broken() 可能在客户端的读取器/事件线程中运行。stop() 不会等待该线程;关闭传输前先设置 _stopping,可避免关闭操作再次报告故障。
|
||||
self.bridge.remove(self._host_id(server_id))
|
||||
|
||||
def _require_launch_allowed(
|
||||
@@ -807,7 +800,7 @@ class McpServerRegistry:
|
||||
def _secret_ids(self, server_id: str, keys: list[str], kind: str) -> set[str]:
|
||||
ids = {self._secret_id(server_id, key, kind) for key in keys}
|
||||
if kind == "environment":
|
||||
# Include retained ambiguous legacy ciphertext when its last declaration is removed.
|
||||
# 当删除最后一个声明时,包括保留的不明确的遗留密文。
|
||||
ids.update(
|
||||
self._legacy_environment_secret_id(server_id, key) for key in keys
|
||||
)
|
||||
@@ -861,9 +854,7 @@ class McpServerRegistry:
|
||||
"status": PluginHostState.error,
|
||||
"error": "环境变量密钥名称曾发生大小写冲突,请分别重新录入密钥并测试连接。",
|
||||
}
|
||||
# Persist a migration marker even when legacy values were ambiguous.
|
||||
# Otherwise a later key removal could make that old shared value look
|
||||
# unambiguous and resurrect a deleted credential on the next restart.
|
||||
# 即使旧值不明确,也保留迁移标记。否则,稍后删除密钥可能会使旧的共享值看起来明确,并在下次重新启动时恢复已删除的凭据。
|
||||
for server_id in legacy_records:
|
||||
self._records[server_id]["secret_environment_version"] = 2
|
||||
self._write()
|
||||
@@ -924,7 +915,7 @@ class McpServerRegistry:
|
||||
) from exc
|
||||
|
||||
def _invalidate_test(self, server_id: str) -> None:
|
||||
"""Make credential changes safe before touching the encrypted store."""
|
||||
"""在接触加密存储之前确保凭证更改的安全。"""
|
||||
|
||||
with self._lock:
|
||||
record = self._record(server_id)
|
||||
|
||||
Reference in New Issue
Block a user