From 1b3e64703e939a851070887b9efa419d2525cf4e Mon Sep 17 00:00:00 2001 From: john Date: Thu, 2 Jul 2026 21:15:41 +0800 Subject: [PATCH] Write conversation package manifests --- mindspace-service.mjs | 15 +++++++++++++++ mindspace-service.test.mjs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/mindspace-service.mjs b/mindspace-service.mjs index 20f8982..16c9097 100644 --- a/mindspace-service.mjs +++ b/mindspace-service.mjs @@ -44,6 +44,21 @@ export function createMindSpaceServiceFacade({ storageAdapter, publicBaseUrl } = return buildConversationPackageManifest(input); }, + async putConversationManifest({ packageRecord, artifacts = [] }) { + const manifest = buildConversationPackageManifest({ packageRecord, artifacts }); + const body = `${JSON.stringify(manifest, null, 2)}\n`; + const writeResult = await this.putPackageObject({ + packageRecord: manifest, + relativePath: 'manifest.json', + body, + }); + return { + manifest, + storageKey: writeResult.key, + writeResult, + }; + }, + buildConversationStoragePrefix(input) { return buildConversationStoragePrefix(input); }, diff --git a/mindspace-service.test.mjs b/mindspace-service.test.mjs index cfd8510..7716707 100644 --- a/mindspace-service.test.mjs +++ b/mindspace-service.test.mjs @@ -89,3 +89,39 @@ test('MindSpace service facade builds manifests from package artifacts', async ( 'https://m.tkmind.cn/MindSpace/user-1/public/report.html', ); }); + +test('MindSpace service facade writes manifest.json inside the conversation package', async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), 'mindspace-service-')); + const service = createMindSpaceServiceFacade({ + storageAdapter: createLocalMindSpaceStorageAdapter(root), + publicBaseUrl: 'https://m.tkmind.cn', + }); + const packageRecord = service.createConversationPackage({ + id: 'cp_session-1', + userId: 'user-1', + sessionId: 'session-1', + now: 1000, + }); + const artifact = service.createConversationArtifact({ + id: 'ca_report', + packageId: packageRecord.id, + artifactKind: 'public_html', + displayName: 'report.html', + sortOrder: 1, + now: 2000, + }); + + const result = await service.putConversationManifest({ + packageRecord, + artifacts: [artifact], + }); + + assert.equal(result.storageKey, 'users/user-1/conversations/session-1/manifest.json'); + const manifestJson = await service.getPackageObject({ packageRecord, relativePath: 'manifest.json' }); + const manifest = JSON.parse(manifestJson.toString('utf8')); + assert.equal(manifest.packageId, 'cp_session-1'); + assert.deepEqual( + manifest.artifacts.map((item) => item.artifactId), + ['ca_report'], + ); +});