@@ -20,7 +20,10 @@ import {
2020 parseAigcToolResult ,
2121 imageFileToDataUri ,
2222 audioFileToDataUri ,
23+ isMcpTtsVoice ,
24+ MCP_TTS_VOICES ,
2325 MCP_CALL_SERVICE ,
26+ resolveMcpImageSize ,
2427 type Client ,
2528 type LocalizedText ,
2629 type McpConnectedClient ,
@@ -199,6 +202,70 @@ export function mcpSingleImageOnlyError(localize: Localize): BailianError {
199202 return new BailianError ( message , ExitCode . USAGE , hint ) ;
200203}
201204
205+ // ---- Connection applicability gate ----
206+
207+ /**
208+ * Reject `auto` mode up front when the effective connection cannot reach the
209+ * Bailian AIGC MCP servers. Both Token Plan shapes were verified against the
210+ * live gateways: the token-plan endpoint has no `/api/v1/mcps` route at all
211+ * (bare 404, empty body) and plan keys (`sk-sp-`) are refused on the standard
212+ * MCP path (401 InvalidApiKey). Neither server response is self-explanatory,
213+ * and this applicability fact is authoritative on the client side, so it is
214+ * raised before any request instead of passing the opaque error through.
215+ */
216+ export function assertAutoMcpAvailable ( client : Client , localize : Localize ) : void {
217+ if ( ! client . usesTokenPlanConnection ( ) ) return ;
218+ const message = localize ( {
219+ "en-US" :
220+ "The current model (auto) routes generation through Bailian MCP, which the Token Plan connection (endpoint or API key) does not provide." ,
221+ "zh-CN" : "当前模型(auto)经百炼 MCP 路由生成,Token Plan 连接(端点或 API Key)不提供该能力。" ,
222+ } ) ;
223+ const hint = localize ( {
224+ "en-US" :
225+ "Switch to a config profile with a standard DashScope API key, or pass --model <id> to keep using Token Plan models." ,
226+ "zh-CN" :
227+ "请切换到含标准 DashScope API Key 的配置,或传入 --model <id> 继续使用 Token Plan 模型。" ,
228+ } ) ;
229+ throw new BailianError ( message , ExitCode . USAGE , hint ) ;
230+ }
231+
232+ // ---- MCP input value gates (auto mode) ----
233+
234+ /**
235+ * Resolve an `auto`-mode `--size` for MCP image generation: ratios map to the
236+ * server's pixel presets and pixel input passes through; values MCP cannot
237+ * accept are rejected up front with the unsupported-parameter USAGE error.
238+ */
239+ export function resolveAutoImageSize (
240+ size : string | undefined ,
241+ localize : Localize ,
242+ ) : string | undefined {
243+ if ( size === undefined ) return undefined ;
244+ const mapped = resolveMcpImageSize ( size ) ;
245+ if ( mapped === undefined ) {
246+ throw mcpUnsupportedError ( localize , [ `--size ${ size } ` ] ) ;
247+ }
248+ return mapped ;
249+ }
250+
251+ /**
252+ * Reject `auto`-mode TTS voices outside the MCP enum before any request: REST
253+ * voice IDs (e.g. `longxiaochun_v3`) are not accepted by `bailian_tts`.
254+ */
255+ export function assertMcpTtsVoice ( voice : string , localize : Localize ) : void {
256+ if ( isMcpTtsVoice ( voice ) ) return ;
257+ const list = MCP_TTS_VOICES . join ( ", " ) ;
258+ const message = localize ( {
259+ "en-US" : `The current model (auto) does not support voice "${ voice } ". MCP TTS voices: ${ list } .` ,
260+ "zh-CN" : `当前模型(auto)不支持音色 "${ voice } "。MCP 可选音色:${ list } 。` ,
261+ } ) ;
262+ const hint = localize ( {
263+ "en-US" : "Pass one of the listed MCP voices, or use --model <id> for the REST system voices." ,
264+ "zh-CN" : "请传入所列 MCP 音色,或使用 --model <id> 改用 REST 系统音色。" ,
265+ } ) ;
266+ throw new BailianError ( message , ExitCode . USAGE , hint ) ;
267+ }
268+
202269// ---- Local file input (auto mode inlines files as base64 data URIs) ----
203270
204271/**
0 commit comments