-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport.py
More file actions
58 lines (46 loc) · 1.57 KB
/
Copy pathexport.py
File metadata and controls
58 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, TypedDict
from models.from_dict_validation import require_dict, require_non_empty_str_fields
class CollectedExportEntry(TypedDict):
"""One exportable conversation with rendered markdown (engine/CLI collection)."""
id: str
rel_path: str
content: str
out_path: str
updatedAt: int
title: str
workspace: str
@dataclass(frozen=True)
class ExportEntry:
"""One line of manifest.jsonl; log_id / title / workspace required, timestamps optional."""
log_id: str
title: str
workspace: str
created_at: Any = None
updated_at: Any = None
raw: dict[str, Any] = field(default_factory=dict)
@classmethod
def from_dict(cls, raw: dict[str, Any]) -> "ExportEntry":
"""Parse one manifest.jsonl row into a validated export entry.
Args:
raw: Decoded JSON object for a single manifest line.
Returns:
Validated :class:`ExportEntry`.
Raises:
SchemaError: When ``log_id``, ``title``, or ``workspace`` are missing.
"""
raw = require_dict(raw, model="ExportEntry", field="entry")
require_non_empty_str_fields(
raw,
("log_id", "title", "workspace"),
model="ExportEntry",
)
return cls(
log_id=raw["log_id"],
title=raw["title"],
workspace=raw["workspace"],
created_at=raw.get("created_at"),
updated_at=raw.get("updated_at"),
raw=raw,
)