Add conversation package registry

This commit is contained in:
john
2026-07-02 21:17:40 +08:00
parent 1b3e64703e
commit 97b648322a
5 changed files with 223 additions and 2 deletions
@@ -0,0 +1,39 @@
function registryError(message, code) {
return Object.assign(new Error(message), { code });
}
function requireMethod(target, methodName, code) {
if (!target || typeof target[methodName] !== 'function') {
throw registryError(`MindSpace conversation package registry requires ${methodName}`, code);
}
}
export function createConversationPackageRegistry({ store, service } = {}) {
requireMethod(store, 'upsertPackage', 'missing_conversation_package_store');
requireMethod(store, 'upsertArtifact', 'missing_conversation_package_store');
requireMethod(store, 'getPackageBySession', 'missing_conversation_package_store');
requireMethod(store, 'listArtifacts', 'missing_conversation_package_store');
requireMethod(service, 'putConversationManifest', 'missing_mindspace_service');
return {
async ensurePackage(input) {
return store.upsertPackage(input);
},
async recordArtifact(input) {
return store.upsertArtifact(input);
},
async writeManifestForSession({ userId, sessionId }) {
const packageRecord = await store.getPackageBySession(userId, sessionId);
if (!packageRecord) return null;
const artifacts = await store.listArtifacts(packageRecord.id);
return service.putConversationManifest({ packageRecord, artifacts });
},
};
}
export const conversationPackageRegistryInternals = {
registryError,
requireMethod,
};