mindspace: close authority boundaries
This commit is contained in:
@@ -649,6 +649,91 @@ export async function ensurePageDataDeliveryReady({
|
||||
return { ok: failures.length === 0, failures };
|
||||
}
|
||||
|
||||
export async function preparePageDataAfterFinish({
|
||||
userId,
|
||||
publishDir,
|
||||
messages,
|
||||
pool,
|
||||
h5Root,
|
||||
storageRoot,
|
||||
userText = '',
|
||||
} = {}) {
|
||||
const recentUserText = String(
|
||||
userText ?? '',
|
||||
).trim();
|
||||
const pageService = pool
|
||||
? createPageService(pool, {
|
||||
h5Root,
|
||||
storageRoot,
|
||||
})
|
||||
: null;
|
||||
const findPageByRelativePath =
|
||||
pageService?.findPageByRelativePath?.bind(
|
||||
pageService,
|
||||
) ?? null;
|
||||
const evaluation =
|
||||
await evaluatePageDataFinishGuardAsync({
|
||||
publishDir,
|
||||
agentText:
|
||||
resolvePageDataGuardAgentText({
|
||||
agentText: recentUserText,
|
||||
messages,
|
||||
}),
|
||||
messages,
|
||||
pool,
|
||||
userId,
|
||||
findPageByRelativePath,
|
||||
});
|
||||
|
||||
if (
|
||||
!evaluation.structuralPageData &&
|
||||
evaluation.relevantFiles.length === 0
|
||||
) {
|
||||
return {
|
||||
autoBind: {
|
||||
bound: [],
|
||||
skipped: [],
|
||||
errors: [],
|
||||
},
|
||||
evaluation,
|
||||
};
|
||||
}
|
||||
|
||||
const autoBind =
|
||||
await maybeAutoBindPageDataHtmlPages({
|
||||
pool,
|
||||
userId,
|
||||
publishDir,
|
||||
h5Root,
|
||||
storageRoot,
|
||||
onlyRelativePaths:
|
||||
evaluation.relevantFiles.length
|
||||
? evaluation.relevantFiles.map(
|
||||
(file) => file.relativePath,
|
||||
)
|
||||
: null,
|
||||
findPageByRelativePath,
|
||||
});
|
||||
|
||||
const afterBind =
|
||||
await evaluatePageDataFinishGuardAsync({
|
||||
publishDir,
|
||||
agentText:
|
||||
resolvePageDataGuardAgentText({
|
||||
agentText: recentUserText,
|
||||
messages,
|
||||
}),
|
||||
messages,
|
||||
pool,
|
||||
userId,
|
||||
findPageByRelativePath,
|
||||
});
|
||||
return {
|
||||
autoBind,
|
||||
evaluation: afterBind,
|
||||
};
|
||||
}
|
||||
|
||||
export async function maybeRepairPageDataAfterFinish({
|
||||
sessionId,
|
||||
userId,
|
||||
@@ -662,43 +747,38 @@ export async function maybeRepairPageDataAfterFinish({
|
||||
env = process.env,
|
||||
logger = console,
|
||||
userText = '',
|
||||
preparation:
|
||||
suppliedPreparation = null,
|
||||
} = {}) {
|
||||
const recentUserText = String(userText ?? '').trim();
|
||||
const pageService = pool ? createPageService(pool, { h5Root, storageRoot }) : null;
|
||||
const evaluation = await evaluatePageDataFinishGuardAsync({
|
||||
publishDir,
|
||||
agentText: resolvePageDataGuardAgentText({ agentText: recentUserText, messages }),
|
||||
messages,
|
||||
pool,
|
||||
userId,
|
||||
findPageByRelativePath: pageService?.findPageByRelativePath?.bind(pageService) ?? null,
|
||||
});
|
||||
const preparation =
|
||||
suppliedPreparation ??
|
||||
(await preparePageDataAfterFinish({
|
||||
userId,
|
||||
publishDir,
|
||||
messages,
|
||||
pool,
|
||||
h5Root,
|
||||
storageRoot,
|
||||
userText,
|
||||
}));
|
||||
const evaluation =
|
||||
preparation?.evaluation ?? {
|
||||
structuralPageData: false,
|
||||
relevantFiles: [],
|
||||
};
|
||||
|
||||
if (!evaluation.structuralPageData && evaluation.relevantFiles.length === 0) {
|
||||
resetPageDataFinishGuardAttempts(sessionId);
|
||||
return { repaired: false, skipped: 'not_page_data', ...evaluation };
|
||||
}
|
||||
|
||||
const autoBind = await maybeAutoBindPageDataHtmlPages({
|
||||
pool,
|
||||
userId,
|
||||
publishDir,
|
||||
h5Root,
|
||||
storageRoot,
|
||||
onlyRelativePaths: evaluation.relevantFiles.length
|
||||
? evaluation.relevantFiles.map((file) => file.relativePath)
|
||||
: null,
|
||||
findPageByRelativePath: pageService?.findPageByRelativePath?.bind(pageService) ?? null,
|
||||
});
|
||||
|
||||
const afterBind = await evaluatePageDataFinishGuardAsync({
|
||||
publishDir,
|
||||
agentText: resolvePageDataGuardAgentText({ agentText: recentUserText, messages }),
|
||||
messages,
|
||||
pool,
|
||||
userId,
|
||||
findPageByRelativePath: pageService?.findPageByRelativePath?.bind(pageService) ?? null,
|
||||
});
|
||||
const autoBind =
|
||||
preparation?.autoBind ?? {
|
||||
bound: [],
|
||||
skipped: [],
|
||||
errors: [],
|
||||
};
|
||||
const afterBind = evaluation;
|
||||
|
||||
if (!afterBind.needsRepair) {
|
||||
resetPageDataFinishGuardAttempts(sessionId);
|
||||
|
||||
Reference in New Issue
Block a user