Record page drafts in conversation packages
This commit is contained in:
+63
-1
@@ -257,6 +257,7 @@ export function createPageService(pool, options = {}) {
|
||||
const storageRoot = path.resolve(options.storageRoot ?? path.join(process.cwd(), 'data', 'mindspace'));
|
||||
const h5Root = options.h5Root ? path.resolve(options.h5Root) : null;
|
||||
const idFactory = options.idFactory ?? (() => crypto.randomUUID());
|
||||
const conversationPackageRegistry = options.conversationPackageRegistry ?? null;
|
||||
|
||||
const resolveWorkspacePublishDir = async (userId) => {
|
||||
if (!h5Root) return null;
|
||||
@@ -553,7 +554,20 @@ export function createPageService(pool, options = {}) {
|
||||
}).catch(() => {});
|
||||
});
|
||||
}
|
||||
return getPage(userId, pageId);
|
||||
const page = await getPage(userId, pageId);
|
||||
await registerPageArtifactForConversation({
|
||||
registry: conversationPackageRegistry,
|
||||
userId,
|
||||
source,
|
||||
page,
|
||||
contentAssetId,
|
||||
contentMimeType,
|
||||
contentBytes: normalized.contentBytes,
|
||||
storageKey: stored.storageKey,
|
||||
versionNo: nextVersionNo,
|
||||
now,
|
||||
});
|
||||
return page;
|
||||
} catch (error) {
|
||||
await conn.rollback();
|
||||
if (writtenPath) await fs.rm(writtenPath, { force: true }).catch(() => {});
|
||||
@@ -1438,6 +1452,53 @@ export function createPageService(pool, options = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
async function registerPageArtifactForConversation({
|
||||
registry,
|
||||
userId,
|
||||
source,
|
||||
page,
|
||||
contentAssetId,
|
||||
contentMimeType,
|
||||
contentBytes,
|
||||
storageKey,
|
||||
versionNo,
|
||||
now,
|
||||
}) {
|
||||
const sessionId = String(source?.sessionId ?? '').trim();
|
||||
if (!registry || !sessionId || !page?.id) return null;
|
||||
try {
|
||||
const packageRecord = await registry.ensurePackage({
|
||||
userId,
|
||||
sessionId,
|
||||
title: page.title,
|
||||
now,
|
||||
});
|
||||
const artifact = await registry.recordArtifact({
|
||||
id: `ca_${page.id}_${page.currentVersionId}`,
|
||||
packageId: packageRecord.id,
|
||||
artifactKind: 'page',
|
||||
role: 'assistant',
|
||||
assetId: contentAssetId,
|
||||
pageId: page.id,
|
||||
messageId: source.messageId ?? page.sourceMessageId ?? null,
|
||||
displayName: page.title,
|
||||
mimeType: contentMimeType,
|
||||
sizeBytes: contentBytes,
|
||||
storageKey,
|
||||
sortOrder: Number.isFinite(Number(versionNo)) ? Number(versionNo) : 0,
|
||||
now,
|
||||
});
|
||||
await registry.writeManifestForSession({ userId, sessionId });
|
||||
return artifact;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'[MindSpace] conversation package page artifact registration failed:',
|
||||
error instanceof Error ? error.message : error,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const pageInternals = {
|
||||
escapeHtml,
|
||||
normalizePageInput,
|
||||
@@ -1449,6 +1510,7 @@ export const pageInternals = {
|
||||
previewContentSecurityPolicy,
|
||||
isHtmlPage,
|
||||
renderPublicationHtml,
|
||||
registerPageArtifactForConversation,
|
||||
redactContent,
|
||||
buildPageDeleteSummary,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user