Manual-commit notebook snapshot extension (JupyterLab 4):
Backend
- Storage adapter layer (Local + S3 via boto3, pip extra)
- Dumb put/get/list/delete contract; key validation
- S3Storage: lazy boto3 import, S3ConnectionError with friendly
messages + connectivity check at startup
- SnapshotStore
- Strip code outputs/execution_count, MD5 on cleaned JSON
- Gzipped envelope (id/timestamp/name/description/hash/size/notebook)
- Append-only manifest.json (rebuildable from version files)
- SnapshotUnchangedError when new hash matches most recent version
- REST API (commit / list / content) under /snapshot/ namespace
- traitlets config (storage_type, local_root, s3_* + S3_* env fallback)
Frontend
- snapshot:commit command (toolbar button + command palette)
- Dialog for name + description
- SnapshotPanel (left sidebar timeline) + DiffWidget (main area)
- Cell diff: id-match first, LCS fallback; jsdiff for line diff
- Restore via model.fromJSON() + context.save() (no refresh)
- All AGENTS.md hard conventions enforced
Tests: 33 backend pytest passing (storage + store + routes)
Docs: AGENTS.md, design.md, README.md synced with implementation.
Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { ServerConnection } from '@jupyterlab/services';
|
|
|
|
import { requestAPI } from './request';
|
|
|
|
export interface VersionEntry {
|
|
id: string;
|
|
timestamp: number;
|
|
name: string;
|
|
description: string;
|
|
hash: string;
|
|
size: number;
|
|
}
|
|
|
|
export interface CommitResponse {
|
|
entry: VersionEntry | null;
|
|
skipped: boolean;
|
|
reason: string | null;
|
|
message: string | null;
|
|
}
|
|
|
|
export async function commitSnapshot(
|
|
serverSettings: ServerConnection.ISettings,
|
|
path: string,
|
|
content: unknown,
|
|
name: string,
|
|
description: string
|
|
): Promise<CommitResponse> {
|
|
return requestAPI<CommitResponse>('notebook-version/commit', serverSettings, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ path, content, name, description }),
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
}
|
|
|
|
export async function listSnapshots(
|
|
serverSettings: ServerConnection.ISettings,
|
|
path: string
|
|
): Promise<VersionEntry[]> {
|
|
const endpoint = `notebook-version/list?path=${encodeURIComponent(path)}`;
|
|
const response = await requestAPI<{ versions: VersionEntry[] }>(
|
|
endpoint,
|
|
serverSettings
|
|
);
|
|
return response.versions;
|
|
}
|
|
|
|
export async function getSnapshotContent(
|
|
serverSettings: ServerConnection.ISettings,
|
|
path: string,
|
|
id: string
|
|
): Promise<unknown> {
|
|
const endpoint = `notebook-version/content?path=${encodeURIComponent(path)}&id=${encodeURIComponent(id)}`;
|
|
return requestAPI<unknown>(endpoint, serverSettings);
|
|
}
|