Skip to content

Commit adc8488

Browse files
authored
feat(schema): update to 1.21.0 (#138)
1 parent 713cbc1 commit adc8488

13 files changed

Lines changed: 582 additions & 346 deletions

‎schema/VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
refs/tags/schema-v1.19.0
1+
refs/tags/schema-v1.21.0

‎schema/schema.json‎

Lines changed: 267 additions & 204 deletions
Large diffs are not rendered by default.

‎scripts/gen_schema.py‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
import argparse
5-
import copy
65
import difflib
76
import json
87
import subprocess
@@ -34,13 +33,6 @@
3433
"integer+uint64=integer",
3534
)
3635

37-
OPEN_UNIONS = {
38-
"CreateElicitationRequest": 2,
39-
"CreateElicitationResponse": 3,
40-
"ElicitationPropertySchema": 5,
41-
"MultiSelectItems": 1,
42-
}
43-
4436

4537
def _inline_model_ref(definition: str, *steps: tuple[str, int | None]) -> str:
4638
ref = f"#/$defs/{definition}"
@@ -312,7 +304,7 @@ def render_schema() -> str:
312304
if not SCHEMA_JSON.exists():
313305
raise FileNotFoundError("schema/schema.json is missing; fetch a pinned schema release first")
314306

315-
schema = _schema_for_codegen(json.loads(SCHEMA_JSON.read_text(encoding="utf-8")))
307+
schema = json.loads(SCHEMA_JSON.read_text(encoding="utf-8"))
316308
generated = generate(
317309
schema,
318310
input_file_type=InputFileType.JsonSchema,
@@ -348,18 +340,6 @@ def render_schema() -> str:
348340
return _format_python(f"{generated.rstrip()}\n\n\n{COMPATIBILITY_ALIASES}\n")
349341

350342

351-
def _schema_for_codegen(schema: dict[str, Any]) -> dict[str, Any]:
352-
"""Drop open-union constraints that Pydantic cannot represent statically."""
353-
patched = copy.deepcopy(schema)
354-
for name, catchall_index in OPEN_UNIONS.items():
355-
try:
356-
del patched["$defs"][name]["discriminator"]
357-
del patched["$defs"][name]["anyOf"][catchall_index]["not"]
358-
except KeyError:
359-
raise ValueError(f"{name} no longer has the expected open-union shape") from None
360-
return patched
361-
362-
363343
def _build_validators_config(schema: dict[str, Any]) -> dict[str, ModelValidators]:
364344
validators: dict[str, list[ValidatorDefinition]] = {
365345
"InitializeRequest": [

‎scripts/gen_signature.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import importlib.util
33
import inspect
44
import sys
5+
import types
56
import typing as t
67
from pathlib import Path
78

@@ -35,7 +36,6 @@ class NodeTransformer(ast.NodeTransformer):
3536
def __init__(self) -> None:
3637
self._type_import_node: ast.ImportFrom | None = None
3738
self._schema_import_node: ast.ImportFrom | None = None
38-
self._should_rewrite = False
3939
self._literals = {name: value for name, value in schema.__dict__.items() if t.get_origin(value) is t.Literal}
4040
self._current_model_name: str | None = None
4141

@@ -44,21 +44,20 @@ def _add_typing_import(self, name: str) -> None:
4444
return
4545
if not any(alias.name == name for alias in self._type_import_node.names):
4646
self._type_import_node.names.append(ast.alias(name=name))
47-
self._should_rewrite = True
4847

4948
def _add_schema_import(self, name: str) -> None:
5049
if not self._schema_import_node:
5150
return
5251
if not any(alias.name == name for alias in self._schema_import_node.names):
5352
self._schema_import_node.names.append(ast.alias(name=name))
54-
self._should_rewrite = True
5553

5654
def transform(self, source_file: Path) -> None:
5755
with source_file.open("r", encoding="utf-8") as f:
5856
source_code = f.read()
5957
tree = ast.parse(source_code)
58+
before = ast.dump(tree, include_attributes=False)
6059
self.visit(tree)
61-
if self._should_rewrite:
60+
if ast.dump(tree, include_attributes=False) != before:
6261
print("Rewriting signatures in", source_file)
6362
new_code = ast.unparse(tree)
6463
with source_file.open("w", encoding="utf-8") as f:
@@ -90,7 +89,6 @@ def visit_func(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> ast.AST:
9089
)
9190
if not decorator:
9291
return self.generic_visit(node)
93-
self._should_rewrite = True
9492
model_name = t.cast(ast.Name, decorator.args[0]).id
9593
model = t.cast(type[schema.BaseModel], getattr(schema, model_name))
9694
self._current_model_name = model_name
@@ -130,6 +128,12 @@ def _format_annotation(self, annotation: t.Any) -> ast.expr:
130128
origin = t.get_origin(annotation)
131129
if origin is t.Annotated:
132130
return self._format_annotation(t.get_args(annotation)[0])
131+
if origin in (t.Union, types.UnionType):
132+
first, *rest = t.get_args(annotation)
133+
formatted = self._format_annotation(first)
134+
for argument in rest:
135+
formatted = ast.BinOp(left=formatted, op=ast.BitOr(), right=self._format_annotation(argument))
136+
return formatted
133137
if origin is t.Literal and annotation in self._literals.values():
134138
name = next(name for name, value in self._literals.items() if value is annotation)
135139
self._add_schema_import(name)

‎src/acp/agent/connection.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
RequestPermissionResponse,
5050
SessionInfoUpdate,
5151
SessionNotification,
52+
SessionUpdateCompactionSummaryChunk,
53+
SessionUpdateCompactionUpdate,
5254
TerminalOutputRequest,
5355
TerminalOutputResponse,
5456
ToolCallProgress,
@@ -121,7 +123,9 @@ async def session_update(
121123
| CurrentModeUpdate
122124
| ConfigOptionUpdate
123125
| SessionInfoUpdate
124-
| UsageUpdate,
126+
| UsageUpdate
127+
| SessionUpdateCompactionUpdate
128+
| SessionUpdateCompactionSummaryChunk,
125129
**kwargs: Any,
126130
) -> None:
127131
await notify_model(

‎src/acp/contrib/tool_calls.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TrackedToolCallView(BaseModel):
5656

5757
tool_call_id: str
5858
title: str | None
59+
name: str | None
5960
kind: ToolKind | None
6061
status: ToolCallStatus | None
6162
content: tuple[Any, ...] | None
@@ -70,6 +71,7 @@ def __init__(
7071
*,
7172
tool_call_id: str,
7273
title: str | None = None,
74+
name: str | None = None,
7375
kind: ToolKind | None = None,
7476
status: ToolCallStatus | None = None,
7577
content: Sequence[Any] | None = None,
@@ -79,6 +81,7 @@ def __init__(
7981
) -> None:
8082
self.tool_call_id = tool_call_id
8183
self.title = title
84+
self.name = name
8285
self.kind = kind
8386
self.status = status
8487
self.content = _copy_model_list(content)
@@ -91,6 +94,7 @@ def to_view(self) -> TrackedToolCallView:
9194
return TrackedToolCallView(
9295
tool_call_id=self.tool_call_id,
9396
title=self.title,
97+
name=self.name,
9498
kind=self.kind,
9599
status=self.status,
96100
content=tuple(item.model_copy(deep=True) for item in self.content) if self.content else None,
@@ -103,6 +107,7 @@ def to_tool_call_model(self) -> ToolCallUpdate:
103107
return ToolCallUpdate(
104108
tool_call_id=self.tool_call_id,
105109
title=self.title,
110+
name=self.name,
106111
kind=self.kind,
107112
status=self.status,
108113
content=_copy_model_list(self.content),
@@ -118,6 +123,7 @@ def to_start_model(self) -> ToolCallStart:
118123
session_update="tool_call",
119124
tool_call_id=self.tool_call_id,
120125
title=self.title,
126+
name=self.name,
121127
kind=self.kind,
122128
status=self.status,
123129
content=_copy_model_list(self.content),
@@ -130,6 +136,7 @@ def update(
130136
self,
131137
*,
132138
title: Any = UNSET,
139+
name: Any = UNSET,
133140
kind: Any = UNSET,
134141
status: Any = UNSET,
135142
content: Any = UNSET,
@@ -141,6 +148,9 @@ def update(
141148
if title is not UNSET:
142149
self.title = cast(str | None, title)
143150
kwargs["title"] = self.title
151+
if name is not UNSET:
152+
self.name = cast(str | None, name)
153+
kwargs["name"] = self.name
144154
if kind is not UNSET:
145155
self.kind = cast(ToolKind | None, kind)
146156
kwargs["kind"] = self.kind
@@ -190,6 +200,7 @@ def start(
190200
external_id: str,
191201
*,
192202
title: str,
203+
name: str | None = None,
193204
kind: ToolKind | None = None,
194205
status: ToolCallStatus | None = "in_progress",
195206
content: Sequence[Any] | None = None,
@@ -202,6 +213,7 @@ def start(
202213
state = _TrackedToolCall(
203214
tool_call_id=call_id,
204215
title=title,
216+
name=name,
205217
kind=kind,
206218
status=status,
207219
content=content,
@@ -217,6 +229,7 @@ def progress(
217229
external_id: str,
218230
*,
219231
title: Any = UNSET,
232+
name: Any = UNSET,
220233
kind: Any = UNSET,
221234
status: Any = UNSET,
222235
content: Any = UNSET,
@@ -228,6 +241,7 @@ def progress(
228241
state = self._require_call(external_id)
229242
return state.update(
230243
title=title,
244+
name=name,
231245
kind=kind,
232246
status=status,
233247
content=content,

‎src/acp/interfaces.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
ResumeSessionResponse,
5757
SessionInfoUpdate,
5858
SessionNotification,
59+
SessionUpdateCompactionSummaryChunk,
60+
SessionUpdateCompactionUpdate,
5961
SetSessionConfigOptionBooleanRequest,
6062
SetSessionConfigOptionResponse,
6163
SetSessionConfigOptionSelectRequest,
@@ -102,7 +104,9 @@ async def session_update(
102104
| CurrentModeUpdate
103105
| ConfigOptionUpdate
104106
| SessionInfoUpdate
105-
| UsageUpdate,
107+
| UsageUpdate
108+
| SessionUpdateCompactionUpdate
109+
| SessionUpdateCompactionSummaryChunk,
106110
**kwargs: Any,
107111
) -> None: ...
108112

‎src/acp/meta.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Generated from schema/meta.json. Do not edit by hand.
2-
# Schema ref: refs/tags/schema-v1.19.0
2+
# Schema ref: refs/tags/schema-v1.21.0
33
AGENT_METHODS = {
44
"initialize": "initialize",
55
"authenticate": "authenticate",

0 commit comments

Comments
 (0)