mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
perf(test): skip tts provider lookup without directives
This commit is contained in:
@@ -56,6 +56,28 @@ const fullPolicy: SpeechModelOverridePolicy = {
|
||||
};
|
||||
|
||||
describe("parseTtsDirectives provider-aware routing", () => {
|
||||
it("does not resolve providers when text has no directives", () => {
|
||||
const failProvider = {
|
||||
get id() {
|
||||
throw new Error("provider should not be read without directives");
|
||||
},
|
||||
get autoSelectOrder() {
|
||||
throw new Error("provider order should not be read without directives");
|
||||
},
|
||||
} as unknown as SpeechProviderPlugin;
|
||||
|
||||
const result = parseTtsDirectives("hello without TTS markup", fullPolicy, {
|
||||
providers: [failProvider, failProvider],
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
cleanedText: "hello without TTS markup",
|
||||
overrides: {},
|
||||
warnings: [],
|
||||
hasDirective: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("routes generic speed to the explicitly declared provider", () => {
|
||||
const result = parseTtsDirectives(
|
||||
"hello [[tts:provider=minimax speed=1.2]] world",
|
||||
|
||||
@@ -62,7 +62,15 @@ export function parseTtsDirectives(
|
||||
return { cleanedText: text, overrides: {}, warnings: [], hasDirective: false };
|
||||
}
|
||||
|
||||
const providers = resolveDirectiveProviders(options);
|
||||
if (!/\[\[tts:/iu.test(text)) {
|
||||
return { cleanedText: text, overrides: {}, warnings: [], hasDirective: false };
|
||||
}
|
||||
|
||||
let providers: SpeechProviderPlugin[] | undefined;
|
||||
const getProviders = () => {
|
||||
providers ??= resolveDirectiveProviders(options);
|
||||
return providers;
|
||||
};
|
||||
const overrides: TtsDirectiveOverrides = {};
|
||||
const warnings: string[] = [];
|
||||
let cleanedText = text;
|
||||
@@ -107,10 +115,14 @@ export function parseTtsDirectives(
|
||||
}
|
||||
}
|
||||
|
||||
const orderedProviders = prioritizeProvider(
|
||||
providers,
|
||||
declaredProviderId ?? normalizeLowercaseStringOrEmpty(options?.preferredProviderId),
|
||||
);
|
||||
let orderedProviders: SpeechProviderPlugin[] | undefined;
|
||||
const getOrderedProviders = () => {
|
||||
orderedProviders ??= prioritizeProvider(
|
||||
getProviders(),
|
||||
declaredProviderId ?? normalizeLowercaseStringOrEmpty(options?.preferredProviderId),
|
||||
);
|
||||
return orderedProviders;
|
||||
};
|
||||
|
||||
for (const token of tokens) {
|
||||
const eqIndex = token.indexOf("=");
|
||||
@@ -127,7 +139,7 @@ export function parseTtsDirectives(
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const provider of orderedProviders) {
|
||||
for (const provider of getOrderedProviders()) {
|
||||
const parsed = provider.parseDirectiveToken?.({
|
||||
key,
|
||||
value: rawValue,
|
||||
|
||||
Reference in New Issue
Block a user