Skip to content

Commit 7408b7e

Browse files
committed
fix(codegen): isolate v2 schema semantics
1 parent fe9479a commit 7408b7e

7 files changed

Lines changed: 64 additions & 43 deletions

File tree

scripts/_schema_semantics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SchemaSemantics:
2020
schema_json: Path
2121
version_file: Path
2222
schema_out: Path
23+
base_class: str
2324
model_name_map: dict[str, str]
2425
compatibility_aliases: str = ""
2526

scripts/gen_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def render_schema(semantics: SchemaSemantics) -> str:
9797
collapse_root_models=True,
9898
skip_root_model=True,
9999
output_model_type=DataModelType.PydanticV2BaseModel,
100-
base_class="acp._schema_base.BaseModel",
100+
base_class=semantics.base_class,
101101
use_specialized_enum=False,
102102
use_standard_collections=False,
103103
use_union_operator=False,

scripts/gen_schema_v1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class Jsonrpc(Enum):
227227
schema_json=ROOT / "schema" / "schema.json",
228228
version_file=ROOT / "schema" / "VERSION",
229229
schema_out=ROOT / "src" / "acp" / "schema.py",
230+
base_class="acp._schema_base.BaseModel",
230231
model_name_map=MODEL_NAME_MAP,
231232
compatibility_aliases=COMPATIBILITY_ALIASES,
232233
)

scripts/gen_schema_v2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,6 @@
227227
schema_json=ROOT / "schema" / "v2" / "schema.json",
228228
version_file=ROOT / "schema" / "v2" / "VERSION",
229229
schema_out=ROOT / "src" / "acp" / "experimental" / "v2" / "schema.py",
230+
base_class="acp.experimental.v2._schema_base.BaseModel",
230231
model_name_map=MODEL_NAME_MAP,
231232
)

src/acp/_schema_base.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,7 @@
1919
class BaseModel(pydantic.BaseModel):
2020
"""Runtime behavior shared by generated ACP schema models."""
2121

22-
# datamodel-code-generator does not emit the `not` constraints used by ACP's
23-
# open unions, so catch-all variants must reject tags owned by known variants.
2422
_reserved_tags: ClassVar[dict[str, tuple[str, frozenset[str]]]] = {
25-
"OtherAuthMethod": ("type", frozenset({"agent", "terminal"})),
26-
"OtherAvailableCommandInput": ("type", frozenset({"text"})),
27-
"OtherContentBlock": ("type", frozenset({"audio", "image", "resource", "resource_link", "text"})),
28-
"OtherDiffChange": ("operation", frozenset({"add", "copy", "delete", "modify", "move"})),
29-
"OtherMcpServer": ("type", frozenset({"acp", "http", "stdio"})),
30-
"OtherNesSuggestion": ("kind", frozenset({"edit", "jump", "rename", "searchAndReplace"})),
31-
"OtherPermissionOutcome": ("outcome", frozenset({"cancelled", "selected"})),
32-
"OtherPermissionSubject": ("type", frozenset({"command", "tool_call"})),
33-
"OtherPlanUpdateContent": ("type", frozenset({"file", "items", "markdown"})),
34-
"OtherReplayFrom": ("type", frozenset({"start"})),
35-
"OtherSessionConfigOption": ("type", frozenset({"boolean", "select"})),
36-
"OtherSessionStateUpdate": ("state", frozenset({"idle", "requires_action", "running"})),
37-
"OtherSessionUpdate": (
38-
"sessionUpdate",
39-
frozenset({
40-
"agent_message",
41-
"agent_message_chunk",
42-
"agent_thought",
43-
"agent_thought_chunk",
44-
"available_commands_update",
45-
"compaction_summary_chunk",
46-
"compaction_update",
47-
"config_option_update",
48-
"plan_removed",
49-
"plan_update",
50-
"session_info_update",
51-
"state_update",
52-
"terminal_output_chunk",
53-
"terminal_update",
54-
"tool_call_content_chunk",
55-
"tool_call_update",
56-
"usage_update",
57-
"user_message",
58-
"user_message_chunk",
59-
}),
60-
),
61-
"OtherState": ("state", frozenset({"idle", "requires_action", "running"})),
62-
"OtherToolCallContent": ("type", frozenset({"content", "diff", "terminal"})),
63-
"SetSessionConfigOptionOtherRequest": ("type", frozenset({"boolean", "id"})),
6423
"CreateOtherSessionElicitationRequest": ("mode", frozenset({"form", "url"})),
6524
"CreateOtherRequestElicitationRequest": ("mode", frozenset({"form", "url"})),
6625
"OtherElicitationResponse": ("action", frozenset({"accept", "cancel", "decline"})),
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from typing import ClassVar
2+
3+
from acp._schema_base import BaseModel as _BaseModel
4+
5+
6+
class BaseModel(_BaseModel):
7+
"""Runtime behavior shared by generated ACP v2 schema models."""
8+
9+
# datamodel-code-generator does not emit the `not` constraints used by ACP's
10+
# open unions, so catch-all variants must reject tags owned by known variants.
11+
_reserved_tags: ClassVar[dict[str, tuple[str, frozenset[str]]]] = {
12+
"OtherAuthMethod": ("type", frozenset({"agent", "terminal"})),
13+
"OtherAvailableCommandInput": ("type", frozenset({"text"})),
14+
"OtherContentBlock": ("type", frozenset({"audio", "image", "resource", "resource_link", "text"})),
15+
"OtherDiffChange": ("operation", frozenset({"add", "copy", "delete", "modify", "move"})),
16+
"OtherMcpServer": ("type", frozenset({"acp", "http", "stdio"})),
17+
"OtherNesSuggestion": ("kind", frozenset({"edit", "jump", "rename", "searchAndReplace"})),
18+
"OtherPermissionOutcome": ("outcome", frozenset({"cancelled", "selected"})),
19+
"OtherPermissionSubject": ("type", frozenset({"command", "tool_call"})),
20+
"OtherPlanUpdateContent": ("type", frozenset({"file", "items", "markdown"})),
21+
"OtherReplayFrom": ("type", frozenset({"start"})),
22+
"OtherSessionConfigOption": ("type", frozenset({"boolean", "select"})),
23+
"OtherSessionStateUpdate": ("state", frozenset({"idle", "requires_action", "running"})),
24+
"OtherSessionUpdate": (
25+
"sessionUpdate",
26+
frozenset({
27+
"agent_message",
28+
"agent_message_chunk",
29+
"agent_thought",
30+
"agent_thought_chunk",
31+
"available_commands_update",
32+
"compaction_summary_chunk",
33+
"compaction_update",
34+
"config_option_update",
35+
"plan_removed",
36+
"plan_update",
37+
"session_info_update",
38+
"state_update",
39+
"terminal_output_chunk",
40+
"terminal_update",
41+
"tool_call_content_chunk",
42+
"tool_call_update",
43+
"usage_update",
44+
"user_message",
45+
"user_message_chunk",
46+
}),
47+
),
48+
"OtherState": ("state", frozenset({"idle", "requires_action", "running"})),
49+
"OtherToolCallContent": ("type", frozenset({"content", "diff", "terminal"})),
50+
"SetSessionConfigOptionOtherRequest": ("type", frozenset({"boolean", "id"})),
51+
"CreateOtherSessionElicitationRequest": ("mode", frozenset({"form", "url"})),
52+
"CreateOtherRequestElicitationRequest": ("mode", frozenset({"form", "url"})),
53+
"OtherElicitationResponse": ("action", frozenset({"accept", "cancel", "decline"})),
54+
"ElicitationOtherPropertySchema": (
55+
"type",
56+
frozenset({"array", "boolean", "integer", "number", "string"}),
57+
),
58+
"OtherMultiSelectItems": ("type", frozenset({"string"})),
59+
}

src/acp/experimental/v2/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Annotated, Any, Dict, List, Literal, Optional, Union
88

99
from acp._deserialize import coerce_protocol_version, skip_invalid_items, use_default_on_error
10-
from acp._schema_base import BaseModel
10+
from acp.experimental.v2._schema_base import BaseModel
1111
from pydantic import (
1212
AnyUrl,
1313
AwareDatetime,

0 commit comments

Comments
 (0)