diff --git a/wechat-mp.mjs b/wechat-mp.mjs index 6acfbd0..f90b81c 100644 --- a/wechat-mp.mjs +++ b/wechat-mp.mjs @@ -435,7 +435,12 @@ function rewritePublishedHtmlLinks(text, artifacts = []) { `https?:\\/\\/[^\\s)]+\\/(?:MindSpace\\/[^\\s/]+\\/)?public\\/${escapeRegExp(filename)}\\b`, 'g', ); + const wrongTkmindHtmlLinkPattern = new RegExp( + `https?:\\/\\/(?:[^\\s./]+\\.)*tkmind\\.cn\\/[^\n\\s)]*${escapeRegExp(filename)}\\b`, + 'gi', + ); next = next.replace(wrongPublicLinkPattern, canonicalUrl); + next = next.replace(wrongTkmindHtmlLinkPattern, canonicalUrl); next = next.replace(PUBLIC_HTML_LINK_PATTERN, (match) => { if (match === canonicalUrl) return match; const matchedFilename = String(match).split('/').pop(); diff --git a/wechat-mp.test.mjs b/wechat-mp.test.mjs index 14d4fcf..489e252 100644 --- a/wechat-mp.test.mjs +++ b/wechat-mp.test.mjs @@ -336,6 +336,48 @@ test('maybeAttachPublishedHtmlLink rewrites wrong public html links to the canon ); }); +test('maybeAttachPublishedHtmlLink rewrites tkmind domain variants to the canonical published url', async () => { + const workspaceRoot = fs.mkdtempSync('/tmp/wechat-mp-rewrite-domain-'); + const htmlPath = `${workspaceRoot}/public/codex-prod-check-v6.html`; + fs.mkdirSync(`${workspaceRoot}/public`, { recursive: true }); + fs.writeFileSync(htmlPath, 'Prod Check'); + + const text = await maybeAttachPublishedHtmlLink( + { + text: '唯一可访问链接:https://mindspace.tkmind.cn/a70ff537-8908-486e-9b6c-042e07cc25db/codex-prod-check-v6.html', + messages: [ + { + role: 'assistant', + content: [ + { + type: 'toolRequest', + toolCall: { + value: { + name: 'sandbox-fs__write_file', + arguments: { + path: 'public/codex-prod-check-v6.html', + content: 'Prod Check', + }, + }, + }, + }, + ], + }, + ], + }, + { + workingDir: workspaceRoot, + publicBaseUrl: 'https://m.tkmind.cn', + }, + ); + + assert.doesNotMatch(text, /https:\/\/mindspace\.tkmind\.cn\/.+\/codex-prod-check-v6\.html/); + assert.match( + text, + /https:\/\/m\.tkmind\.cn\/MindSpace\/.+\/public\/codex-prod-check-v6\.html/, + ); +}); + test('wechat mp service splits long agent replies into multiple customer messages', async () => { const token = 'token'; const timestamp = '1710000000';