2f51041822
Prevent text-only planning replies from marking WeChat delivery done when static-page-publish never confirmed a public HTML file. Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.8 KiB
JavaScript
80 lines
2.8 KiB
JavaScript
import { buildPagePublishFailureText } from '../prompts/page-generate.mjs';
|
|
import { selectSendableHtmlArtifacts, verifyPageArtifactContent } from '../verify/page-artifact.mjs';
|
|
import { filterSharePreviewReadyArtifacts, verifyArtifactSharePreview } from '../verify/share-preview.mjs';
|
|
|
|
export function evaluatePageGenerateSendableArtifacts({ verifiedArtifacts = [], confirmedArtifacts = [] } = {}) {
|
|
const sendable = selectSendableHtmlArtifacts({ verifiedArtifacts, confirmedArtifacts });
|
|
const verified = sendable.filter((artifact) => verifyPageArtifactContent(artifact).ok);
|
|
const candidates = verified.length > 0 ? verified : sendable;
|
|
return filterSharePreviewReadyArtifacts(candidates);
|
|
}
|
|
|
|
/**
|
|
* Decide whether a page.generate reply may be delivered to the user.
|
|
* Returns { action: 'send'|'fail'|'session_retry', failureText?, reason? }
|
|
*/
|
|
export function resolvePageGenerateOutcome({
|
|
reply,
|
|
confirmedArtifacts = [],
|
|
verifiedArtifacts = [],
|
|
suspiciousPublishClaim = false,
|
|
bareCompletionReply = false,
|
|
htmlGenerationNeedsRetry = false,
|
|
replyHasPublicLinks = false,
|
|
}) {
|
|
const sendable = evaluatePageGenerateSendableArtifacts({ verifiedArtifacts, confirmedArtifacts });
|
|
|
|
if (sendable.length > 0) {
|
|
return { action: 'send', artifacts: sendable };
|
|
}
|
|
|
|
if (
|
|
suspiciousPublishClaim ||
|
|
bareCompletionReply ||
|
|
(htmlGenerationNeedsRetry && replyHasPublicLinks && confirmedArtifacts.length === 0)
|
|
) {
|
|
return { action: 'session_retry', reason: 'poisoned_or_fake_claim' };
|
|
}
|
|
|
|
if (htmlGenerationNeedsRetry || suspiciousPublishClaim) {
|
|
return {
|
|
action: 'fail',
|
|
failureText: buildPagePublishFailureText(),
|
|
reason: 'skill_or_stub',
|
|
};
|
|
}
|
|
|
|
const previewCandidates = filterSharePreviewReadyArtifacts(
|
|
selectSendableHtmlArtifacts({ verifiedArtifacts, confirmedArtifacts }),
|
|
);
|
|
if (previewCandidates.length === 0 && confirmedArtifacts.length > 0) {
|
|
const previewIssue = verifyArtifactSharePreview(
|
|
selectSendableHtmlArtifacts({ verifiedArtifacts, confirmedArtifacts })[0] ?? confirmedArtifacts[0],
|
|
);
|
|
return {
|
|
action: 'fail',
|
|
failureText: buildPagePublishFailureText({
|
|
missingPlatformBrand: previewIssue.reason === 'missing_platform_brand',
|
|
missingSharePreview: previewIssue.reason !== 'missing_platform_brand',
|
|
}),
|
|
reason: previewIssue.reason ?? 'missing_share_preview',
|
|
};
|
|
}
|
|
|
|
if (!String(reply?.text ?? '').trim() && sendable.length === 0) {
|
|
return {
|
|
action: 'fail',
|
|
failureText: buildPagePublishFailureText(),
|
|
reason: 'empty_reply',
|
|
};
|
|
}
|
|
|
|
// Fail closed: page.generate must deliver a verified public HTML artifact.
|
|
// Text-only planning replies ("我先搜索…") must not mark WeChat delivery done.
|
|
return {
|
|
action: 'fail',
|
|
failureText: buildPagePublishFailureText(),
|
|
reason: 'missing_page_artifact',
|
|
};
|
|
}
|