feat(chat): add local-first conversation workspace
This commit is contained in:
@@ -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];
|
||||
}
|
||||
Reference in New Issue
Block a user