fix: preserve Telegram compatibility and stabilize Office

This commit is contained in:
xmanrui 2026-08-21 01:37:21 +08:00
parent 7f114e1c36
commit 24e690498b
23 changed files with 1679 additions and 314 deletions

View file

@ -27,7 +27,9 @@ export const TOKEN_BOT_ENDPOINTS = Object.freeze({
setWorkspace: 'bot.workspace.set',
});
export function createTokenChannelApi(channel, connectionSummary) {
export function createTokenChannelApi(channel, connectionSummary, {
normalizeBotExtension = () => ({}),
} = {}) {
const unwrapRpcResult = (result) => {
if (!isRecord(result) || typeof result.ok !== 'boolean') {
throw new Error(`${channel} 服务返回了无法识别的响应`);
@ -44,6 +46,7 @@ export function createTokenChannelApi(channel, connectionSummary) {
if (!isRecord(value) || !id(value.botId)) return undefined;
const connected = value.connected === true;
const state = ACCOUNT_STATES.has(value.state) ? value.state : 'offline';
const extension = normalizeBotExtension(value);
return {
botId: id(value.botId),
connected,
@ -65,6 +68,7 @@ export function createTokenChannelApi(channel, connectionSummary) {
code: text(value.error.code, `${channel.toUpperCase()}_ACCOUNT_ERROR`, 80),
message: text(value.error.message, `${channel}连接尚未就绪`),
} : null,
...(isRecord(extension) ? extension : {}),
};
};

View file

@ -59,9 +59,11 @@ export function createTokenChannelSettings(definition) {
credentialCloseLabel = '收起凭据',
credentialNoun = 'Bot Token',
emptyActionLabel = '填写 Bot Token',
AccountSettings = null,
accountSettingsEndpoint = null,
} = definition;
function AccountCard({ account, busy, testNotice, removing, onReconnect, onWorkspaceSave, onRequestRemove, onConfirmRemove, onCancelRemove }) {
function AccountCard({ account, busy, testNotice, removing, onReconnect, onWorkspaceSave, onAccountSettingsSave, onRequestRemove, onConfirmRemove, onCancelRemove }) {
const state = busy === 'reconnect' ? 'connecting' : account.state;
const tone = account.connected ? 'success' : state === 'error' ? 'error' : 'warning';
const stateLabel = account.connected ? '运行正常' : state === 'connecting' ? '正在连接' : '连接未就绪';
@ -88,6 +90,11 @@ export function createTokenChannelSettings(definition) {
disabled: Boolean(busy),
onSave: onWorkspaceSave,
}),
AccountSettings ? h(AccountSettings, {
account,
busy: Boolean(busy),
onSave: onAccountSettingsSave,
}) : null,
h('div', { className: 'ddt-accountFooter dim-cardFooter' },
summary ? h('div', { className: 'ddt-summary dim-cardSummary' }, summary) : null,
testNotice ? h('div', { className: 'ddt-summary dim-cardSummary', role: 'status' }, testNotice) : null,
@ -260,6 +267,14 @@ export function createTokenChannelSettings(definition) {
endpoints.setWorkspace,
{ botId: account.botId, workspace },
),
onAccountSettingsSave: AccountSettings && accountSettingsEndpoint
? (payload) => botAction(
account,
'settings',
accountSettingsEndpoint,
{ botId: account.botId, ...payload },
)
: undefined,
onRequestRemove: () => setRemoveTarget(account.botId),
onCancelRemove: () => setRemoveTarget(null),
onConfirmRemove: async () => {