Localize pipeline fallback notifications

This commit is contained in:
2026-05-18 20:31:04 +03:00
parent 1773b44edd
commit df39d89ea8
9 changed files with 49 additions and 19 deletions
+1 -1
View File
@@ -292,7 +292,7 @@ export async function prepareUnifiedAiRequestPipeline(params: {
];
const state = createAiRequestPipelineState(options);
const fallbackNotifier = new PipelineFallbackNotifier(options.msg);
const fallbackNotifier = new PipelineFallbackNotifier(options.msg, options.responseLanguage);
const pipeline = new UserRequestPipeline({
stages,
stageNames: [
+1 -1
View File
@@ -167,7 +167,7 @@ export async function runUnifiedAiResponsePipeline(params: {
}): Promise<void> {
const {options, config, downloads, prepared, streamMessage, controller} = params;
const state = createResponsePipelineState(options);
const fallbackNotifier = new PipelineFallbackNotifier(options.msg);
const fallbackNotifier = new PipelineFallbackNotifier(options.msg, options.responseLanguage);
const adapter = getProviderAdapter(options.provider);
let selectedToolNames: string[] = [];
let filteredTools: unknown[] = [];
@@ -1,27 +1,26 @@
import {Localization} from "../../common/localization.js";
import type {PipelineFallbackAction, PipelineStageName} from "./types.js";
const DEFAULT_TEXT = "⚠️ I had to skip part of the request, but I can continue.";
const NOTIFY_TEXT = "⚠️ I hit a problem and need to continue with a fallback.";
const FAIL_TEXT = "⚠️ I could not finish this request.";
const RAG_TEXT = "⚠️ Document retrieval failed, so I will answer without RAG.";
const STT_TEXT = "⚠️ Speech transcription failed, so I will continue without the audio transcript.";
const TTS_TEXT = "⚠️ Text-to-speech failed, so I will continue without audio output.";
const TOOL_TEXT = "⚠️ Tool execution failed, so I will continue without that tool.";
export function resolvePipelineFallbackText(stage: PipelineStageName, action: PipelineFallbackAction): string | undefined {
export function resolvePipelineFallbackText(
stage: PipelineStageName,
action: PipelineFallbackAction,
locale?: string,
): string | undefined {
if (action === "continue_without_stage") return undefined;
if (action === "fail_request") return FAIL_TEXT;
if (action === "fail_request") return Localization.text("pipelineFallback.failRequest", {}, "⚠️ I could not finish this request.", locale);
switch (stage) {
case "speech_to_text":
return STT_TEXT;
return Localization.text("pipelineFallback.speechToText", {}, "⚠️ Speech transcription failed, so I will continue without the audio transcript.", locale);
case "document_rag":
return RAG_TEXT;
return Localization.text("pipelineFallback.documentRag", {}, "⚠️ Document retrieval failed, so I will answer without RAG.", locale);
case "tool_loop":
return TOOL_TEXT;
return Localization.text("pipelineFallback.toolLoop", {}, "⚠️ Tool execution failed, so I will continue without that tool.", locale);
case "text_to_speech":
return TTS_TEXT;
return Localization.text("pipelineFallback.textToSpeech", {}, "⚠️ Text-to-speech failed, so I will continue without audio output.", locale);
default:
return action === "notify_user" ? NOTIFY_TEXT : DEFAULT_TEXT;
return action === "notify_user"
? Localization.text("pipelineFallback.notifyUser", {}, "⚠️ I hit a problem and need to continue with a fallback.", locale)
: Localization.text("pipelineFallback.generic", {}, "⚠️ I had to skip part of the request, but I can continue.", locale);
}
}
@@ -1,4 +1,5 @@
import type {Message} from "typescript-telegram-bot-api";
import {Localization} from "../../common/localization.js";
import {replyToMessage, logError} from "../../util/utils.js";
import type {PipelineFallbackDecision} from "./fallback-executor.js";
import {PipelineFallbackNotificationRegistry} from "./fallback-notifier-registry.js";
@@ -9,6 +10,7 @@ export class PipelineFallbackNotifier {
constructor(
private readonly sourceMessage: Message,
private readonly responseLanguage?: string,
private readonly sendFallbackMessage: (text: string) => Promise<void> = async text => {
await replyToMessage({
message: this.sourceMessage,
@@ -22,7 +24,10 @@ export class PipelineFallbackNotifier {
return {notified: false};
}
const text = resolvePipelineFallbackText(decision.stage, decision.action);
const locale = this.responseLanguage === "default"
? Localization.currentLocale()
: Localization.normalizeLocale(this.responseLanguage) ?? Localization.currentLocale();
const text = resolvePipelineFallbackText(decision.stage, decision.action, locale);
if (!text) {
return {notified: false};
}