fix(wechat): honor explicit page generation negation #19
@@ -6,6 +6,7 @@ import {
|
|||||||
resolveWechatImageGenerationPolicy,
|
resolveWechatImageGenerationPolicy,
|
||||||
WECHAT_PAGE_THUMBNAIL_MODE,
|
WECHAT_PAGE_THUMBNAIL_MODE,
|
||||||
} from './image-generation-policy.mjs';
|
} from './image-generation-policy.mjs';
|
||||||
|
import { classifyWechatIntent } from './intent/classifier.mjs';
|
||||||
|
|
||||||
test('service-account page always requires a fresh thumbnail without forcing body images', () => {
|
test('service-account page always requires a fresh thumbnail without forcing body images', () => {
|
||||||
const policy = resolveWechatImageGenerationPolicy({
|
const policy = resolveWechatImageGenerationPolicy({
|
||||||
@@ -47,3 +48,17 @@ test('standalone image intent gets an inline_image tool contract', () => {
|
|||||||
assert.match(instruction, /purpose=`inline_image`/);
|
assert.match(instruction, /purpose=`inline_image`/);
|
||||||
assert.match(instruction, /idempotency_key=wechat-msg-1-image/);
|
assert.match(instruction, /idempotency_key=wechat-msg-1-image/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('explicitly declining a page keeps standalone image generation out of page flow', () => {
|
||||||
|
const text = '请生成一张雨夜橘猫插画,只生成图片,不要生成页面';
|
||||||
|
const intent = classifyWechatIntent({ msgType: 'text', agentText: text });
|
||||||
|
assert.equal(intent.kind, 'chat.general');
|
||||||
|
|
||||||
|
const policy = resolveWechatImageGenerationPolicy({
|
||||||
|
text,
|
||||||
|
isPageGenerate: intent.kind === 'page.generate',
|
||||||
|
requireFreshPageThumbnail: true,
|
||||||
|
});
|
||||||
|
assert.equal(policy.pageThumbnailMode, 'auto');
|
||||||
|
assert.equal(policy.standaloneImageMode, 'required');
|
||||||
|
});
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
export const PAGE_GENERATE_PATTERN =
|
export const PAGE_GENERATE_PATTERN =
|
||||||
/(?:生成|创建|做|写|帮我.*(?:生成|创建|做|写)).*(?:html|页面|网页|page|文件)/iu;
|
/(?:生成|创建|做|写|帮我.*(?:生成|创建|做|写)).*(?:html|页面|网页|page|文件)/iu;
|
||||||
|
|
||||||
|
export const PAGE_GENERATE_NEGATION_PATTERN =
|
||||||
|
/(?:不要|无需|不用|别|不需要)\s*(?:再\s*)?(?:生成|创建|制作|做|写)\s*(?:任何|一个|新的)?\s*(?:html|页面|网页|page|文件)/iu;
|
||||||
|
|
||||||
export const DOCX_DOWNLOAD_PATTERN =
|
export const DOCX_DOWNLOAD_PATTERN =
|
||||||
/(?:(?:word|docx|\.docx|\.doc|文档).*(?:下载|链接|导出|给我)|(?:下载|导出|提供|给我).*(?:word|docx|\.docx|\.doc|文档))/iu;
|
/(?:(?:word|docx|\.docx|\.doc|文档).*(?:下载|链接|导出|给我)|(?:下载|导出|提供|给我).*(?:word|docx|\.docx|\.doc|文档))/iu;
|
||||||
|
|
||||||
@@ -21,6 +24,7 @@ export const CONNECTIVITY_TEST_PATTERN = /^(测试\s*\d*|test\s*\d*)[!!。.\s]
|
|||||||
export function isPageGenerateText(text) {
|
export function isPageGenerateText(text) {
|
||||||
const normalized = String(text ?? '').trim();
|
const normalized = String(text ?? '').trim();
|
||||||
if (!normalized) return false;
|
if (!normalized) return false;
|
||||||
|
if (PAGE_GENERATE_NEGATION_PATTERN.test(normalized)) return false;
|
||||||
return PAGE_GENERATE_PATTERN.test(normalized);
|
return PAGE_GENERATE_PATTERN.test(normalized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user