Files
msime-windows/engine
時崎 ギャラクシーandfanlusky add122fcc6 feat: 候选词翻译新增 AI 辅助提供方,收敛为单一 translation.provider (#876)
* feat(engine): 翻译凭据测试新增 translation.ai 服务类型

* feat(server): 候选词翻译新增 AI 辅助提供方,收敛为单一 translation.provider

* feat(ui-html): 候选词翻译新增 AI 辅助提供方并跟随单一 provider

* fix(server): 将 ai_translation 加入编译目标与测试套件

* fix(server): 在 AiTranslation 命名空间导出 ParseTranslations 供测试调用

* fix(server): 解析模型返回时剥除 Markdown 代码块标记

* fix(server): AI 候选词翻译校验占位 Token、收紧解析,翻译配置改读快照

- AI 翻译的 Token 改用 IsUsableSecret 校验,出厂模板的占位符不再被当成可用凭据
- 解析模型回复时,合法 JSON 但键不对、数组长度不符或残缺 JSON 一律作废,不再把原文当译文显示和写进释义库
- 从旧布尔推导出腾讯云时保留 tencent_tmt.enabled 门禁;在设置页明确选择时才打开,升级不会替用户向腾讯云发送候选词
- 候选词翻译读取的 provider 与各服务配置合成一份加锁快照,配置重载时整份替换,候选线程和翻译 worker 不再直接读会被改写的全局字符串;每个任务只解析当前服务的配置
- provider 与三个旧布尔一次原子写入;旧的 niutrans/custom enabled 开关改为切换 provider
- AI 联想与 AI 翻译共用 ChatCompletions 传输层,翻译超时与 AI 联想一致改为 8 秒
- 设置页凭据测试与运行时共用 AiTranslation::FromConfiguredTranslation,provider 白名单只保留 IsValidTranslationProvider 一处

* fix(ui-html): 候选词翻译的 AI 配置提示随 AI 辅助页实时更新

AI 辅助页改服务商、地址、Token 或模型后,翻译区的提示和摘要立刻刷新,不用重开设置窗口;可用性判断与服务端一致,占位 Token 不算已配置。

---------

Co-authored-by: fanlusky <1730976608@qq.com>
2026-10-12 16:47:04 +08:00
..

Input engine (engine/)

中文 README · Website

The C++ conversion engine behind Metasequoia IME for Windows: input sessions, candidate lookup, helpcodes, the shared contracts and the voice module.

This directory used to be a submodule of metasequoiaime/MSIME-Engine. It is now a component of this repository, a sibling of server/, ui/, windows/ and installer/. Its upstream commit, and exactly what the Windows specialization removed, are recorded in UPSTREAM.md. Treat it as first-party code: reviewed, formatted and tested like anything else here, no longer merged from upstream.

Directory Purpose
core/, quanpin/, shuangpin/, english/, japanese/ Input sessions and candidate lookup
contracts/ The authoritative IPC wire format, dictionary format, punctuation policy and WebView message schema
helpcode/ Helpcode (形码) tables and generators
local_modes/, providers/, user_dictionary/ Local modes, online candidate sources, the user dictionary
voice/ Recording, WAV encoding, recognition and text cleanup; builds independently
googlepinyinime-rev/, ngram/kenlm/, utfcpp/, voice/third_party/ Vendored third-party code, kept in its upstream formatting and licence

Integration is through <metasequoia/session.h>. See runtime architecture.

Build

The product build does not build this directory on its own: server/CMakeLists.txt pulls it in with add_subdirectory, so CI compiles and exercises the engine through the server and the TSF frontend. After changing something here, run the server's build and tests.

Building it standalone still works and is much faster while working on the engine. Dependencies are CMake 3.25+, a C++17 compiler, Boost, fmt, spdlog and SQLite3.

vcpkg install --triplet x64-windows-static
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static
cmake --build build --config Release --parallel
ctest --test-dir build -C Release --output-on-failure --timeout 20

ctest runs every engine target registered in the root CMakeLists.txt: the segmentation, IPC and punctuation contracts, the platform API, data paths, runtime isolation, dictionary state and the per-mode session tests. tests/ additionally holds a separate Windows-only project that is not part of that build — add new tests to the registered targets so they actually run.

Formatting is driven from the repository root by scripts/format.sh, using the .clang-format in this directory (voice/ has its own with a wider column limit). The vendored third-party trees and the generated headers are excluded.

Contract rules

The IPC wire format, opcodes, voice framing and WebView message definitions live in contracts/ and are the single source of truth. Consumers include the same headers; do not restate them on either side. Dictionary naming is defined by contracts/dictionary/format.json, shared with the repository root's scripts/dictionary_product.py.

Data and licensing

The dictionaries are neither stored nor built here. They arrive as a release pinned by tag and digest in product-lock.json and are downloaded at build time; the pipeline that produced them left with the specialization. Per-source licensing is tracked in NOTICE.md — read it before redistributing the built databases.

Recognition goes through a cloud provider; local Whisper inference was removed. The only committed model is voice/assets/models/silero_vad.onnx, loaded solely by the standalone Windows host that is off by default.

Licence

GPL-3.0. Vendored googlepinyinime-rev, ngram/kenlm (LGPL-2.1-or-later), utfcpp and voice/third_party/miniaudio keep their upstream licences.