Add page indexes to conversation manifests
This commit is contained in:
@@ -142,6 +142,27 @@ function artifactManifestEntry(artifact) {
|
||||
};
|
||||
}
|
||||
|
||||
function groupedManifestEntries(artifacts, keyField, idField) {
|
||||
const groups = new Map();
|
||||
for (const artifact of artifacts) {
|
||||
const key = artifact[keyField];
|
||||
if (!key) continue;
|
||||
const existing = groups.get(key) ?? {
|
||||
[idField]: key,
|
||||
artifactIds: [],
|
||||
createdAt: artifact.createdAt,
|
||||
updatedAt: artifact.createdAt,
|
||||
};
|
||||
existing.artifactIds.push(artifact.id);
|
||||
if (!existing.displayName && artifact.displayName) existing.displayName = artifact.displayName;
|
||||
if (!existing.canonicalUrl && artifact.canonicalUrl) existing.canonicalUrl = artifact.canonicalUrl;
|
||||
existing.createdAt = Math.min(existing.createdAt, artifact.createdAt);
|
||||
existing.updatedAt = Math.max(existing.updatedAt, artifact.createdAt);
|
||||
groups.set(key, existing);
|
||||
}
|
||||
return [...groups.values()].sort((a, b) => a.createdAt - b.createdAt || a[idField].localeCompare(b[idField]));
|
||||
}
|
||||
|
||||
export function buildConversationPackageManifest({ packageRecord, artifacts = [] }) {
|
||||
const record = createConversationPackageRecord(packageRecord);
|
||||
const normalizedArtifacts = artifacts
|
||||
@@ -161,6 +182,8 @@ export function buildConversationPackageManifest({ packageRecord, artifacts = []
|
||||
createdAt: record.createdAt,
|
||||
updatedAt: record.updatedAt,
|
||||
artifacts: normalizedArtifacts.map(artifactManifestEntry),
|
||||
pages: groupedManifestEntries(normalizedArtifacts, 'pageId', 'pageId'),
|
||||
publications: groupedManifestEntries(normalizedArtifacts, 'publicationId', 'publicationId'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -110,8 +110,9 @@ test('buildConversationPackageManifest sorts artifacts and emits stable public s
|
||||
artifacts: [
|
||||
{
|
||||
id: 'ca_late',
|
||||
artifactKind: 'generated_file',
|
||||
displayName: 'notes.md',
|
||||
artifactKind: 'page',
|
||||
displayName: '项目周报',
|
||||
pageId: 'page-1',
|
||||
sortOrder: 2,
|
||||
createdAt: 3000,
|
||||
},
|
||||
@@ -122,6 +123,16 @@ test('buildConversationPackageManifest sorts artifacts and emits stable public s
|
||||
sortOrder: 1,
|
||||
createdAt: 2000,
|
||||
},
|
||||
{
|
||||
id: 'ca_public',
|
||||
artifactKind: 'public_html',
|
||||
displayName: 'report.html',
|
||||
pageId: 'page-1',
|
||||
publicationId: 'pub-1',
|
||||
canonicalUrl: 'https://m.tkmind.cn/MindSpace/user-1/public/report.html',
|
||||
sortOrder: 3,
|
||||
createdAt: 4000,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -130,7 +141,7 @@ test('buildConversationPackageManifest sorts artifacts and emits stable public s
|
||||
assert.equal(manifest.storagePrefix, 'users/user-1/conversations/session-1');
|
||||
assert.deepEqual(
|
||||
manifest.artifacts.map((artifact) => artifact.artifactId),
|
||||
['ca_first', 'ca_late'],
|
||||
['ca_first', 'ca_late', 'ca_public'],
|
||||
);
|
||||
assert.deepEqual(manifest.artifacts[0], {
|
||||
artifactId: 'ca_first',
|
||||
@@ -139,4 +150,24 @@ test('buildConversationPackageManifest sorts artifacts and emits stable public s
|
||||
sortOrder: 1,
|
||||
createdAt: 2000,
|
||||
});
|
||||
assert.deepEqual(manifest.pages, [
|
||||
{
|
||||
pageId: 'page-1',
|
||||
artifactIds: ['ca_late', 'ca_public'],
|
||||
displayName: '项目周报',
|
||||
canonicalUrl: 'https://m.tkmind.cn/MindSpace/user-1/public/report.html',
|
||||
createdAt: 3000,
|
||||
updatedAt: 4000,
|
||||
},
|
||||
]);
|
||||
assert.deepEqual(manifest.publications, [
|
||||
{
|
||||
publicationId: 'pub-1',
|
||||
artifactIds: ['ca_public'],
|
||||
displayName: 'report.html',
|
||||
canonicalUrl: 'https://m.tkmind.cn/MindSpace/user-1/public/report.html',
|
||||
createdAt: 4000,
|
||||
updatedAt: 4000,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -480,6 +480,22 @@ export type MindSpaceConversationPackage = {
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
artifacts: MindSpaceConversationArtifact[];
|
||||
pages?: Array<{
|
||||
pageId: string;
|
||||
artifactIds: string[];
|
||||
displayName?: string;
|
||||
canonicalUrl?: string;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
}>;
|
||||
publications?: Array<{
|
||||
publicationId: string;
|
||||
artifactIds: string[];
|
||||
displayName?: string;
|
||||
canonicalUrl?: string;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type MindSpacePageVersion = {
|
||||
|
||||
Reference in New Issue
Block a user