fix(wip): WIP - partial unify WeChat/H5 skill prompts (build agent changes)
- Reuse H5's buildAutoChatSkillPrefix in buildWechatAgentPrompt signature - Inject autoSkillPrefix into voice/text message prompts - Add origin tagging in GET /sessions for h5/wechat channel labels Still TODO (will complete in next cycle): - Full resolveGrantedSkills → buildWechatAgentPrompt flow - ensureWechatAgentSession idle rotation logic - setSessionOrigin + touchWechatAgentRoute calls - Backend schema/migrations (h5_user_sessions origin column) - Frontend type + UI component updates Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1164,6 +1164,16 @@ export function createTkmindProxy({
|
|||||||
|
|
||||||
const sessions = [...sessionsById.values()].sort(sortSessionsByRecent);
|
const sessions = [...sessionsById.values()].sort(sortSessionsByRecent);
|
||||||
await enrichSessionHistory(sessions);
|
await enrichSessionHistory(sessions);
|
||||||
|
if (typeof userAuth.getSessionOrigins === 'function' && sessions.length > 0) {
|
||||||
|
try {
|
||||||
|
const origins = await userAuth.getSessionOrigins(sessions.map((s) => s.id));
|
||||||
|
for (const session of sessions) {
|
||||||
|
session.origin = origins.get(session.id) ?? 'h5';
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// leave sessions untagged on lookup failure
|
||||||
|
}
|
||||||
|
}
|
||||||
const summaries = sessions.map(projectSessionSummary).filter((item) => matchesSessionQuery(item, query));
|
const summaries = sessions.map(projectSessionSummary).filter((item) => matchesSessionQuery(item, query));
|
||||||
const paged = summaries.slice(offset, offset + limit);
|
const paged = summaries.slice(offset, offset + limit);
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
+20
-3
@@ -9,6 +9,7 @@ import { isScheduleIntent, parseScheduleIntent, shouldUseScheduleAssistant } fro
|
|||||||
import { materializeMissingPublicHtmlWrites } from './mindspace-public-finish-sync.mjs';
|
import { materializeMissingPublicHtmlWrites } from './mindspace-public-finish-sync.mjs';
|
||||||
import { buildCurrentTimeAgentPrefix } from './user-memory-profile.mjs';
|
import { buildCurrentTimeAgentPrefix } from './user-memory-profile.mjs';
|
||||||
import { PUBLISH_ROOT_DIR } from './user-publish.mjs';
|
import { PUBLISH_ROOT_DIR } from './user-publish.mjs';
|
||||||
|
import { buildAutoChatSkillPrefix } from './chat-skills.mjs';
|
||||||
import { downloadTemporaryMedia, persistWechatImage } from './wechat-media.mjs';
|
import { downloadTemporaryMedia, persistWechatImage } from './wechat-media.mjs';
|
||||||
import { buildAckText } from './wechat/ack/ack-provider.mjs';
|
import { buildAckText } from './wechat/ack/ack-provider.mjs';
|
||||||
|
|
||||||
@@ -1073,8 +1074,12 @@ function normalizeWechatInboundIntent(inbound) {
|
|||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildWechatAgentPrompt(intent) {
|
export function buildWechatAgentPrompt(intent, { grantedSkills = [] } = {}) {
|
||||||
const msgType = String(intent?.msgType ?? 'text');
|
const msgType = String(intent?.msgType ?? 'text');
|
||||||
|
const autoSkillPrefix =
|
||||||
|
msgType === 'text' || msgType === 'voice'
|
||||||
|
? buildAutoChatSkillPrefix(intent?.agentText ?? intent?.content, grantedSkills)
|
||||||
|
: '';
|
||||||
const docxDownloadHint =
|
const docxDownloadHint =
|
||||||
looksLikeHtmlGenerationIntent(intent?.agentText ?? intent?.content) &&
|
looksLikeHtmlGenerationIntent(intent?.agentText ?? intent?.content) &&
|
||||||
looksLikeDocxDownloadIntent(intent?.agentText ?? intent?.content)
|
looksLikeDocxDownloadIntent(intent?.agentText ?? intent?.content)
|
||||||
@@ -1116,7 +1121,7 @@ export function buildWechatAgentPrompt(intent) {
|
|||||||
scheduleAssistantHint,
|
scheduleAssistantHint,
|
||||||
'【微信服务号语音消息】用户通过语音输入,以下是微信识别结果。',
|
'【微信服务号语音消息】用户通过语音输入,以下是微信识别结果。',
|
||||||
'',
|
'',
|
||||||
`用户语音识别文本:${String(intent?.agentText ?? '').trim()}`,
|
`用户语音识别文本:${autoSkillPrefix}${String(intent?.agentText ?? '').trim()}`,
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
@@ -1174,7 +1179,7 @@ export function buildWechatAgentPrompt(intent) {
|
|||||||
'【微信服务号新消息】请只回答下面这条用户消息,不要主动延续无关的历史话题。',
|
'【微信服务号新消息】请只回答下面这条用户消息,不要主动延续无关的历史话题。',
|
||||||
'若用户只是在测试连通性,请一句话确认收到即可,不要展开旧任务。',
|
'若用户只是在测试连通性,请一句话确认收到即可,不要展开旧任务。',
|
||||||
'',
|
'',
|
||||||
`用户消息:${content}`,
|
`用户消息:${autoSkillPrefix}${content}`,
|
||||||
);
|
);
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
@@ -1804,6 +1809,18 @@ export function createWechatMpService({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resolveGrantedSkills = async (userId) => {
|
||||||
|
try {
|
||||||
|
const row = await userAuth.getUserById(userId);
|
||||||
|
if (!row) return [];
|
||||||
|
const caps = await userAuth.resolveUserCapabilities(row);
|
||||||
|
return Array.isArray(caps?.grantedSkills) ? caps.grantedSkills : [];
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn?.('WeChat MP granted skills lookup failed:', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const runIntentMessage = async ({ inbound, intent, user }) => {
|
const runIntentMessage = async ({ inbound, intent, user }) => {
|
||||||
const resetCandidate =
|
const resetCandidate =
|
||||||
intent.msgType === 'text' || intent.msgType === 'voice' ? intent.agentText : '';
|
intent.msgType === 'text' || intent.msgType === 'voice' ? intent.agentText : '';
|
||||||
|
|||||||
Reference in New Issue
Block a user