feat(chat): add local-first conversation workspace

This commit is contained in:
2026-08-13 15:55:15 +08:00
parent d1d50d722c
commit 8991f78f9f
43 changed files with 5450 additions and 592 deletions
+21
View File
@@ -0,0 +1,21 @@
import type {RepositoryRefUpdate, StoredChatMessage} from "./conversation-types";
export type RepositoryPushPayload = {
repositoryId: string;
objects: StoredChatMessage[];
refs: RepositoryRefUpdate[];
};
function chunks<T>(items: T[], size: number) {
const result: T[][] = [];
for (let index = 0; index < items.length; index += size) result.push(items.slice(index, index + size));
return result;
}
export function repositoryPushBatches(payload: RepositoryPushPayload) {
const objectBatches = chunks([...new Map(payload.objects.map((object) => [object.id, object])).values()], 1000)
.map((objects) => ({repositoryId: payload.repositoryId, objects, refs: [] as RepositoryRefUpdate[]}));
const refBatches = chunks(payload.refs, 100)
.map((refs) => ({repositoryId: payload.repositoryId, objects: [] as StoredChatMessage[], refs}));
return [...objectBatches, ...refBatches];
}