Merge: Knowledge version history - API and UI (closes #75, #76)

This commit is contained in:
Jason Woltje
2026-01-29 23:39:49 -06:00
14 changed files with 1222 additions and 140 deletions

View File

@@ -3,7 +3,12 @@
* Handles knowledge entry-related API requests
*/
import type { KnowledgeEntryWithTags, KnowledgeTag } from "@mosaic/shared";
import type {
KnowledgeEntryWithTags,
KnowledgeTag,
KnowledgeEntryVersionWithAuthor,
PaginatedResponse,
} from "@mosaic/shared";
import { EntryStatus, Visibility } from "@mosaic/shared";
import { apiGet, apiPost, apiPatch, apiDelete, type ApiResponse } from "./client";
@@ -44,6 +49,11 @@ export interface UpdateEntryData {
status?: EntryStatus;
visibility?: Visibility;
tags?: string[];
changeNote?: string;
}
export interface RestoreVersionData {
changeNote?: string;
}
/**
@@ -129,19 +139,46 @@ export async function fetchTags(): Promise<KnowledgeTag[]> {
}
/**
* Fetch entry-centered graph view
* Fetch version history for an entry
*/
export async function fetchEntryGraph(slug: string, depth: number = 1) {
export async function fetchVersions(
slug: string,
page: number = 1,
limit: number = 20
): Promise<PaginatedResponse<KnowledgeEntryVersionWithAuthor>> {
const params = new URLSearchParams();
params.append("depth", depth.toString());
return apiGet(`/api/knowledge/entries/${slug}/graph?${params.toString()}`);
params.append("page", page.toString());
params.append("limit", limit.toString());
return apiGet<PaginatedResponse<KnowledgeEntryVersionWithAuthor>>(
`/api/knowledge/entries/${slug}/versions?${params.toString()}`
);
}
/**
* Fetch knowledge base statistics
* Fetch a specific version of an entry
*/
export async function fetchKnowledgeStats() {
return apiGet("/api/knowledge/stats");
export async function fetchVersion(
slug: string,
version: number
): Promise<KnowledgeEntryVersionWithAuthor> {
return apiGet<KnowledgeEntryVersionWithAuthor>(
`/api/knowledge/entries/${slug}/versions/${version}`
);
}
/**
* Restore a previous version of an entry
*/
export async function restoreVersion(
slug: string,
version: number,
data?: RestoreVersionData
): Promise<KnowledgeEntryWithTags> {
return apiPost<KnowledgeEntryWithTags>(
`/api/knowledge/entries/${slug}/restore/${version}`,
data || {}
);
}
/**