feat: add message source context enhancement

This commit is contained in:
xmanrui 2026-08-29 10:46:06 +08:00
parent 5928b33057
commit 0cb79f74e9
69 changed files with 6217 additions and 597 deletions

View file

@ -1,5 +1,6 @@
import { normalizeAgentPresetCatalog, normalizeAgentPresetId, SET_AGENT_PRESET_ENDPOINT } from '../../agent-preset.js';
import { normalizeLastMessageError } from '../../last-message-error.js';
import { normalizeContextEnhancementConfig } from '../../../../src/channels/shared/context-enhancement.mjs';
export const WEIXIN_RPC_CHANNEL = '/weixin';
export const WEIXIN_ENDPOINTS = Object.freeze({
@ -12,6 +13,7 @@ export const WEIXIN_ENDPOINTS = Object.freeze({
deleteBot: 'bot.delete',
setWorkspace: 'bot.workspace.set',
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
setContextEnhancement: 'bot.context-enhancement.set',
});
const ACCOUNT_STATES = new Set(['connected', 'connecting', 'offline', 'error']);
@ -121,6 +123,7 @@ function normalizeBot(value) {
configured: value.configured === true,
workspace: string(value.workspace).slice(0, 4_096),
agentPreset: normalizeAgentPresetId(value.agentPreset),
contextEnhancement: normalizeContextEnhancementConfig(value.contextEnhancement),
bot: {
name: string(value.bot.name, '微信机器人'),
accountIdMasked: string(value.bot.accountIdMasked, '已安全保存'),

View file

@ -15,6 +15,7 @@ import {
} from './api.js';
import { createPollScheduler, useAnimationFrameScheduler } from '../../lifecycle.js';
import { WorkspaceEditor } from '../../workspace-editor.js';
import { ContextEnhancementEditor } from '../../context-enhancement.js';
import {
AgentPresetCatalogContext,
AgentPresetEditor,
@ -207,6 +208,7 @@ export function AccountCard({
onReconnect,
onWorkspaceSave,
onAgentPresetSave,
onContextEnhancementSave,
onRequestRemove,
onConfirmRemove,
onCancelRemove,
@ -238,6 +240,12 @@ export function AccountCard({
disabled: Boolean(busy),
onSave: onAgentPresetSave,
}),
h(ContextEnhancementEditor, {
config: account.contextEnhancement,
groupSupported: false,
disabled: Boolean(busy),
onSave: onContextEnhancementSave,
}),
h('div', { className: 'dxw-accountFooter dim-cardFooter' },
h('div', { className: 'dim-cardFooterLayout' },
h('div', { className: 'dxw-actions dim-cardActions' },
@ -280,6 +288,7 @@ function AccountList(props) {
onReconnect: () => props.onReconnect(account),
onWorkspaceSave: (workspace) => props.onWorkspaceSave(account, workspace),
onAgentPresetSave: (agentPreset) => props.onAgentPresetSave(account, agentPreset),
onContextEnhancementSave: (config) => props.onContextEnhancementSave(account, config),
onRequestRemove: () => props.onRequestRemove(account),
onConfirmRemove: () => props.onConfirmRemove(account),
onCancelRemove: props.onCancelRemove,
@ -594,13 +603,13 @@ export function WeixinSettingsTab({ rpcCall }) {
}
}, [invoke, loadStatus, setBotBusy, workspaceFence]);
const saveAgentPreset = React.useCallback(async (account, agentPreset) => {
const saveBotSetting = React.useCallback(async (account, operation, endpoint, payload) => {
const snapshotVersion = workspaceFence.beginMutation();
setBotBusy(account.botId, 'preset');
setBotBusy(account.botId, operation);
try {
const snapshot = normalizeSnapshot(await invoke(
WEIXIN_ENDPOINTS.setAgentPreset,
{ botId: account.botId, agentPreset },
endpoint,
{ botId: account.botId, ...payload },
));
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
setModel({
@ -703,7 +712,12 @@ export function WeixinSettingsTab({ rpcCall }) {
removeTarget,
onReconnect: (account) => void reconnect(account),
onWorkspaceSave: saveWorkspace,
onAgentPresetSave: saveAgentPreset,
onAgentPresetSave: (account, agentPreset) => saveBotSetting(
account, 'preset', WEIXIN_ENDPOINTS.setAgentPreset, { agentPreset },
),
onContextEnhancementSave: (account, config) => saveBotSetting(
account, 'context-enhancement', WEIXIN_ENDPOINTS.setContextEnhancement, { config },
),
onRequestRemove: (account) => setRemoveTarget(account.botId),
onConfirmRemove: (account) => void remove(account),
onCancelRemove: () => setRemoveTarget(null),