b5a88d9746
Backfill missing platform-brand footer at serve time and block service- account links when the HTML file omits data-mindspace-page-tag. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.6 KiB
JavaScript
74 lines
2.6 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',
|
|
};
|
|
}
|
|
|
|
return { action: 'send', artifacts: sendable };
|
|
}
|