From ec375b14025c0d37dc0e9af3f0b3fb5945c8e96b Mon Sep 17 00:00:00 2001 From: john Date: Wed, 1 Jul 2026 21:07:25 +0800 Subject: [PATCH] fix(wip): WIP - partial unify WeChat/H5 skill prompts (build agent changes) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- tkmind-proxy.mjs | 10 ++++++++++ wechat-mp.mjs | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tkmind-proxy.mjs b/tkmind-proxy.mjs index 7429c4a..a4508c7 100644 --- a/tkmind-proxy.mjs +++ b/tkmind-proxy.mjs @@ -1164,6 +1164,16 @@ export function createTkmindProxy({ const sessions = [...sessionsById.values()].sort(sortSessionsByRecent); 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 paged = summaries.slice(offset, offset + limit); res.json({ diff --git a/wechat-mp.mjs b/wechat-mp.mjs index 16ef1e2..d2488fc 100644 --- a/wechat-mp.mjs +++ b/wechat-mp.mjs @@ -9,6 +9,7 @@ import { isScheduleIntent, parseScheduleIntent, shouldUseScheduleAssistant } fro import { materializeMissingPublicHtmlWrites } from './mindspace-public-finish-sync.mjs'; import { buildCurrentTimeAgentPrefix } from './user-memory-profile.mjs'; import { PUBLISH_ROOT_DIR } from './user-publish.mjs'; +import { buildAutoChatSkillPrefix } from './chat-skills.mjs'; import { downloadTemporaryMedia, persistWechatImage } from './wechat-media.mjs'; import { buildAckText } from './wechat/ack/ack-provider.mjs'; @@ -1073,8 +1074,12 @@ function normalizeWechatInboundIntent(inbound) { return base; } -export function buildWechatAgentPrompt(intent) { +export function buildWechatAgentPrompt(intent, { grantedSkills = [] } = {}) { const msgType = String(intent?.msgType ?? 'text'); + const autoSkillPrefix = + msgType === 'text' || msgType === 'voice' + ? buildAutoChatSkillPrefix(intent?.agentText ?? intent?.content, grantedSkills) + : ''; const docxDownloadHint = looksLikeHtmlGenerationIntent(intent?.agentText ?? intent?.content) && looksLikeDocxDownloadIntent(intent?.agentText ?? intent?.content) @@ -1116,7 +1121,7 @@ export function buildWechatAgentPrompt(intent) { scheduleAssistantHint, '【微信服务号语音消息】用户通过语音输入,以下是微信识别结果。', '', - `用户语音识别文本:${String(intent?.agentText ?? '').trim()}`, + `用户语音识别文本:${autoSkillPrefix}${String(intent?.agentText ?? '').trim()}`, ] .filter(Boolean) .join('\n'); @@ -1174,7 +1179,7 @@ export function buildWechatAgentPrompt(intent) { '【微信服务号新消息】请只回答下面这条用户消息,不要主动延续无关的历史话题。', '若用户只是在测试连通性,请一句话确认收到即可,不要展开旧任务。', '', - `用户消息:${content}`, + `用户消息:${autoSkillPrefix}${content}`, ); 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 resetCandidate = intent.msgType === 'text' || intent.msgType === 'voice' ? intent.agentText : '';