Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,43 @@ describe('bot session lifecycle bindings', () => {
assert.deepEqual(sent, ['bot-session-1', 'bot-session-2']);
assert.deepEqual(replies, ['reply from bot-session-1', 'reply from bot-session-2']);
});

test('keeps classified failure notices in the bot surface locale', async () => {
const replies: string[] = [];
const service = createBotIncomingMainService({
botRegistry: {
async sendMessage(_platform: string, _chatId: string, text: string) {
replies.push(text);
return 'message-id';
},
async sendTypingIndicator() {
return true;
},
} as unknown as BotRegistry,
sessions: {
async createSession() {
return 'bot-session';
},
async prepareSession() {
return 'ready' as const;
},
async runTurn() {
throw new Error('Request timeout');
},
},
});

await service.handleBotIncomingMessage({
platform: 'telegram',
userId: 'user',
userName: 'User',
chatId: 'chat',
isGroup: false,
text: 'hello',
sourceMessageId: 'source',
receivedAt: Date.now(),
} as BotIncomingMessage);

assert.deepEqual(replies, ['Maka 暂时无法处理这条消息:请求超时']);
});
});
4 changes: 2 additions & 2 deletions apps/desktop/src/main/bot-incoming-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
nonTextMessageAck,
plaintextHelpReply,
} from '@maka/core/bot-events';
import { generalizedErrorMessage } from '@maka/core/redaction';
import { generalizedErrorMessageForLocale } from '@maka/core/redaction';
import type { BotIncomingMessage, BotRegistry, BotReplyStream } from '@maka/runtime/bots';
import type { BotSessionAdapter, BotSessionTurnResult } from './bot-session-adapter.js';
import { isBotSessionUnavailableError } from './bot-session-adapter.js';
Expand Down Expand Up @@ -392,7 +392,7 @@ export function createBotIncomingMainService(deps: BotIncomingMainServiceDeps):
if (closed) return;
const detail = isSessionWorkspaceUnavailableError(error)
? '工作目录不可用,请在桌面端选择有效目录后重试'
: generalizedErrorMessage(error, '机器人对话处理失败');
: generalizedErrorMessageForLocale(error, '机器人对话处理失败', 'zh-CN');
const replyOptions = {
...(message.sourceMessageId ? { replyToMessageId: message.sourceMessageId } : {}),
// Error notice: same 5-minute TTL as the other transient system
Expand Down
Loading