Add file-backed personality support and listing

This commit is contained in:
Eric Traut
2026-03-30 14:43:42 -06:00
parent ae057e0bb9
commit 8e00fec700
61 changed files with 1741 additions and 366 deletions

View File

@@ -452,9 +452,22 @@ def generate_v2_all() -> None:
],
cwd=sdk_root(),
)
_widen_generated_personality_type(out_path)
_normalize_generated_timestamps(out_path)
def _widen_generated_personality_type(out_path: Path) -> None:
source = out_path.read_text()
updated = re.sub(
r"class Personality\(Enum\):\n(?: .+\n)+",
"Personality = str\n\n",
source,
count=1,
)
if updated != source:
out_path.write_text(updated)
def _notification_specs() -> list[tuple[str, str]]:
server_notifications = json.loads(
(schema_root_dir() / "ServerNotification.json").read_text()
@@ -544,6 +557,11 @@ FIELD_ANNOTATION_OVERRIDES: dict[str, str] = {
# Keep public API typed without falling back to `Any`.
"config": "JsonObject",
"output_schema": "JsonObject",
"personality": "PersonalityLike",
}
FIELD_SERIALIZATION_OVERRIDES: dict[str, str] = {
"personality": "personality_value(personality)",
}
@@ -636,7 +654,11 @@ def _kw_signature_lines(fields: list[PublicFieldSpec]) -> list[str]:
def _model_arg_lines(
fields: list[PublicFieldSpec], *, indent: str = " "
) -> list[str]:
return [f"{indent}{field.wire_name}={field.py_name}," for field in fields]
lines = []
for field in fields:
value = FIELD_SERIALIZATION_OVERRIDES.get(field.wire_name, field.py_name)
lines.append(f"{indent}{field.wire_name}={value},")
return lines
def _replace_generated_block(source: str, block_name: str, body: str) -> str: