feat: add WeChat media analysis adapters

This commit is contained in:
john
2026-07-18 17:41:32 +08:00
parent 055d53c58b
commit fd3904fdee
9 changed files with 380 additions and 12 deletions
+7 -1
View File
@@ -21,6 +21,12 @@ const ImageBuilder = {
build: (ctx) => buildText(TEMPLATES.image, ctx),
};
const FileBuilder = {
priority: 80,
support: (ctx) => ctx.msgType === 'file',
build: (ctx) => buildText(TEMPLATES.file, ctx),
};
const VoiceBuilder = {
priority: 80,
support: (ctx) => ctx.msgType === 'voice',
@@ -54,7 +60,7 @@ const DefaultBuilder = {
build: (ctx) => buildText(TEMPLATES.default, ctx),
};
const BUILDERS = [ImageBuilder, VoiceBuilder, LocationBuilder, LinkBuilder, IntentBuilder, DefaultBuilder]
const BUILDERS = [ImageBuilder, FileBuilder, VoiceBuilder, LocationBuilder, LinkBuilder, IntentBuilder, DefaultBuilder]
.sort((a, b) => b.priority - a.priority);
export function selectBuilder(ctx) {
+1
View File
@@ -13,6 +13,7 @@ const INTENT_RULES = [
export function resolveIntent(msgType, text) {
if (msgType === 'image') return { task: 'image_analysis' };
if (msgType === 'file') return { task: 'file_analysis' };
if (msgType === 'voice') return { task: 'voice_analysis' };
if (msgType === 'location') return { task: 'location' };
if (msgType === 'link') return { task: 'link' };
+5
View File
@@ -26,6 +26,11 @@ describe('buildAckText', () => {
assert.equal(result, '图片收到,我先看看。');
});
it('file → file template', () => {
const result = buildAckText({ intent: intent('file'), nickname: '', config: cfg, fallbackText: '' });
assert.equal(result, '文件收到,我先读取分析。');
});
it('voice → voice template', () => {
const result = buildAckText({ intent: intent('voice'), nickname: '', config: cfg, fallbackText: '' });
assert.equal(result, '收到语音,我先听一下。');
+1
View File
@@ -12,6 +12,7 @@ export const TEMPLATES = {
'让我看看这张图片。',
'图片已收到,我来处理。',
],
file: ['文件收到,我先读取分析。'],
voice: [
'收到语音,我先听一下。',
'听到啦,我马上处理。',
+14
View File
@@ -81,6 +81,20 @@ export function buildWechatAgentPrompt(intent, { grantedSkills = [] } = {}) {
.filter(Boolean)
.join('\n');
}
if (msgType === 'file') {
const attachment = intent?.attachment ?? {};
return [
currentTimeHint,
'【微信服务号文件消息】用户发送了需要解析的 Office 文件。',
attachment.filename ? `文件名:${attachment.filename}` : '',
attachment.publicUrl ? `文件链接:${attachment.publicUrl}` : '',
'请复用 H5 附件分析结果回答;Excel 在专用工具可用时必须优先使用 Excel 工具读取完整工作簿。',
'',
String(agentText).trim(),
]
.filter(Boolean)
.join('\n');
}
if (msgType === 'location') {
const location = intent?.location ?? {};
return [