



























@@ -111,28 +111,30 @@ function hasLegacyTtsSpeakerSelectionInPersonas(value: unknown): boolean {
111111});
112112}
113113114-function hasLegacyTtsSpeakerSelectionInAgentLocations(value: unknown): boolean {
114+type LegacyTtsMatcher = (value: unknown) => boolean;
115+116+function hasLegacyTtsInAgentLocations(value: unknown, matcher: LegacyTtsMatcher): boolean {
115117const agents = getRecord(value);
116118const agentList = Array.isArray(agents?.list) ? agents.list : [];
117-return agentList.some((entry) => hasLegacyTtsSpeakerSelection(getRecord(getRecord(entry)?.tts)));
119+return agentList.some((entry) => matcher(getRecord(getRecord(entry)?.tts)));
118120}
119121120122function supportsChannelRootTtsMigration(channelId: string): boolean {
121123return !CHANNEL_ROOT_TTS_UNSUPPORTED_IDS.has(channelId.trim().toLowerCase());
122124}
123125124-function hasLegacyTtsSpeakerSelectionInChannelLocations(value: unknown): boolean {
126+function hasLegacyTtsInChannelLocations(value: unknown, matcher: LegacyTtsMatcher): boolean {
125127const channels = getRecord(value);
126128for (const [channelId, channelValue] of Object.entries(channels ?? {})) {
127129if (isBlockedObjectKey(channelId)) {
128130continue;
129131}
130132const channel = getRecord(channelValue);
131133const migrateRootTts = supportsChannelRootTtsMigration(channelId);
132-if (migrateRootTts && hasLegacyTtsSpeakerSelection(getRecord(channel?.tts))) {
134+if (migrateRootTts && matcher(getRecord(channel?.tts))) {
133135return true;
134136}
135-if (hasLegacyTtsSpeakerSelection(getRecord(getRecord(channel?.voice)?.tts))) {
137+if (matcher(getRecord(getRecord(channel?.voice)?.tts))) {
136138return true;
137139}
138140const accounts = getRecord(channel?.accounts);
@@ -142,8 +144,8 @@ function hasLegacyTtsSpeakerSelectionInChannelLocations(value: unknown): boolean
142144}
143145const account = getRecord(accountValue);
144146if (
145-(migrateRootTts && hasLegacyTtsSpeakerSelection(getRecord(account?.tts))) ||
146-hasLegacyTtsSpeakerSelection(getRecord(getRecord(account?.voice)?.tts))
147+(migrateRootTts && matcher(getRecord(account?.tts))) ||
148+matcher(getRecord(getRecord(account?.voice)?.tts))
147149) {
148150return true;
149151}
@@ -152,7 +154,7 @@ function hasLegacyTtsSpeakerSelectionInChannelLocations(value: unknown): boolean
152154return false;
153155}
154156155-function hasLegacyTtsSpeakerSelectionInPluginLocations(value: unknown): boolean {
157+function hasLegacyTtsInPluginLocations(value: unknown, matcher: LegacyTtsMatcher): boolean {
156158const entries = getRecord(value);
157159if (!entries) {
158160return false;
@@ -163,60 +165,32 @@ function hasLegacyTtsSpeakerSelectionInPluginLocations(value: unknown): boolean
163165}
164166const entry = getRecord(entryValue);
165167const config = getRecord(entry?.config);
166-return hasLegacyTtsSpeakerSelection(getRecord(config?.tts));
168+return matcher(getRecord(config?.tts));
167169});
168170}
169171172+function hasLegacyTtsSpeakerSelectionInAgentLocations(value: unknown): boolean {
173+return hasLegacyTtsInAgentLocations(value, hasLegacyTtsSpeakerSelection);
174+}
175+176+function hasLegacyTtsSpeakerSelectionInChannelLocations(value: unknown): boolean {
177+return hasLegacyTtsInChannelLocations(value, hasLegacyTtsSpeakerSelection);
178+}
179+180+function hasLegacyTtsSpeakerSelectionInPluginLocations(value: unknown): boolean {
181+return hasLegacyTtsInPluginLocations(value, hasLegacyTtsSpeakerSelection);
182+}
183+170184function hasLegacyTtsEnabledInAgentLocations(value: unknown): boolean {
171-const agents = getRecord(value);
172-const agentList = Array.isArray(agents?.list) ? agents.list : [];
173-return agentList.some((entry) => hasLegacyTtsEnabled(getRecord(getRecord(entry)?.tts)));
185+return hasLegacyTtsInAgentLocations(value, hasLegacyTtsEnabled);
174186}
175187176188function hasLegacyTtsEnabledInChannelLocations(value: unknown): boolean {
177-const channels = getRecord(value);
178-for (const [channelId, channelValue] of Object.entries(channels ?? {})) {
179-if (isBlockedObjectKey(channelId)) {
180-continue;
181-}
182-const channel = getRecord(channelValue);
183-const migrateRootTts = supportsChannelRootTtsMigration(channelId);
184-if (migrateRootTts && hasLegacyTtsEnabled(getRecord(channel?.tts))) {
185-return true;
186-}
187-if (hasLegacyTtsEnabled(getRecord(getRecord(channel?.voice)?.tts))) {
188-return true;
189-}
190-const accounts = getRecord(channel?.accounts);
191-for (const [accountId, accountValue] of Object.entries(accounts ?? {})) {
192-if (isBlockedObjectKey(accountId)) {
193-continue;
194-}
195-const account = getRecord(accountValue);
196-if (
197-(migrateRootTts && hasLegacyTtsEnabled(getRecord(account?.tts))) ||
198-hasLegacyTtsEnabled(getRecord(getRecord(account?.voice)?.tts))
199-) {
200-return true;
201-}
202-}
203-}
204-return false;
189+return hasLegacyTtsInChannelLocations(value, hasLegacyTtsEnabled);
205190}
206191207192function hasLegacyTtsEnabledInPluginLocations(value: unknown): boolean {
208-const entries = getRecord(value);
209-if (!entries) {
210-return false;
211-}
212-return Object.entries(entries).some(([pluginId, entryValue]) => {
213-if (isBlockedObjectKey(pluginId) || !LEGACY_TTS_PLUGIN_IDS.has(pluginId)) {
214-return false;
215-}
216-const entry = getRecord(entryValue);
217-const config = getRecord(entry?.config);
218-return hasLegacyTtsEnabled(getRecord(config?.tts));
219-});
193+return hasLegacyTtsInPluginLocations(value, hasLegacyTtsEnabled);
220194}
221195222196function getOrCreateTtsProviders(tts: Record<string, unknown>): Record<string, unknown> {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。