diff options
Diffstat (limited to 'makima/frontend/src/lib/api.ts')
| -rw-r--r-- | makima/frontend/src/lib/api.ts | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts index f1e3a9f..931981b 100644 --- a/makima/frontend/src/lib/api.ts +++ b/makima/frontend/src/lib/api.ts @@ -236,3 +236,138 @@ export async function chatWithFile( } return res.json(); } + +// Version history types +export type VersionSource = "user" | "llm" | "system"; + +export interface FileVersion { + version: number; + name: string; + description: string | null; + summary: string | null; + body: BodyElement[]; + source: VersionSource; + createdAt: string; + changeDescription?: string; +} + +export interface FileVersionSummary { + version: number; + source: VersionSource; + createdAt: string; + changeDescription?: string; +} + +export interface FileVersionListResponse { + versions: FileVersionSummary[]; + total: number; +} + +export interface RestoreVersionRequest { + targetVersion: number; +} + +// Version history API functions +export async function listFileVersions(fileId: string): Promise<FileVersionListResponse> { + const res = await fetch(`${API_BASE}/api/v1/files/${fileId}/versions`); + if (!res.ok) { + throw new Error(`Failed to list versions: ${res.statusText}`); + } + return res.json(); +} + +export async function getFileVersion(fileId: string, version: number): Promise<FileVersion> { + const res = await fetch(`${API_BASE}/api/v1/files/${fileId}/versions/${version}`); + if (!res.ok) { + throw new Error(`Failed to get version: ${res.statusText}`); + } + return res.json(); +} + +export async function restoreFileVersion( + fileId: string, + targetVersion: number, + currentVersion: number +): Promise<FileDetail> { + const res = await fetch(`${API_BASE}/api/v1/files/${fileId}/versions/restore`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ targetVersion, currentVersion }), + }); + + if (res.status === 409) { + const conflict = (await res.json()) as ConflictErrorResponse; + throw new VersionConflictError(conflict); + } + + if (!res.ok) { + throw new Error(`Failed to restore version: ${res.statusText}`); + } + return res.json(); +} + +// ============================================================================= +// LLM Tool Definitions for Version History +// ============================================================================= +// These types define the tools available to the LLM for version history access. +// The backend should implement handlers for these tools. + +/** + * Tool: read_version + * Allows the LLM to read the content of a specific historical version. + * This is read-only - it does not modify the document. + */ +export interface ReadVersionToolInput { + version: number; +} + +export interface ReadVersionToolOutput { + success: boolean; + version: number; + body: BodyElement[]; + summary: string | null; + source: VersionSource; + createdAt: string; + changeDescription?: string; + message: string; +} + +/** + * Tool: list_versions + * Allows the LLM to list all available versions of the document. + */ +export interface ListVersionsToolOutput { + success: boolean; + versions: FileVersionSummary[]; + currentVersion: number; + message: string; +} + +/** + * Tool: restore_version + * Allows the LLM to restore the document to a specific historical version. + * This creates a new version with the content from the target version. + */ +export interface RestoreVersionToolInput { + targetVersion: number; + reason?: string; +} + +export interface RestoreVersionToolOutput { + success: boolean; + previousVersion: number; + newVersion: number; + restoredFromVersion: number; + message: string; +} + +// LLM Tool type definitions for the backend +export type LlmVersionTool = + | { name: "read_version"; input: ReadVersionToolInput } + | { name: "list_versions"; input: Record<string, never> } + | { name: "restore_version"; input: RestoreVersionToolInput }; + +export type LlmVersionToolResult = + | { name: "read_version"; result: ReadVersionToolOutput } + | { name: "list_versions"; result: ListVersionsToolOutput } + | { name: "restore_version"; result: RestoreVersionToolOutput }; |
