Skip to content

Commit c16e275

Browse files
author
Chojan Shang
committed
fix: make gen all great
Signed-off-by: Chojan Shang <chojan.shang@vesoft.com>
1 parent 2c3e449 commit c16e275

File tree

2 files changed

+36
-59
lines changed

2 files changed

+36
-59
lines changed

scripts/gen_schema.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77
import subprocess
88
import sys
9+
from collections.abc import Callable
910
from pathlib import Path
1011

1112
ROOT = Path(__file__).resolve().parents[1]
@@ -228,18 +229,31 @@ def replace_block(
228229
_class_name: str = class_name,
229230
) -> str:
230231
header, block = match.group(1), match.group(2)
231-
field_pattern = re.compile(
232-
rf"(\n\s+{_field_name}:[^\n]*=)\s*[^\n]+",
233-
re.MULTILINE,
232+
field_patterns: tuple[tuple[re.Pattern[str], Callable[[re.Match[str]], str]], ...] = (
233+
(
234+
re.compile(
235+
rf"(\n\s+{_field_name}:.*?\]\s*=\s*)([\s\S]*?)(?=\n\s{{4}}[A-Za-z_]|$)",
236+
re.DOTALL,
237+
),
238+
lambda m, _rep=_replacement: m.group(1) + _rep,
239+
),
240+
(
241+
re.compile(
242+
rf"(\n\s+{_field_name}:[^\n]*=)\s*([^\n]+)",
243+
re.MULTILINE,
244+
),
245+
lambda m, _rep=_replacement: m.group(1) + " " + _rep,
246+
),
234247
)
235-
new_block, count = field_pattern.subn(rf"\1 {_replacement}", block, count=1)
236-
if count == 0:
237-
print(
238-
f"Warning: failed to override default for {_class_name}.{_field_name}",
239-
file=sys.stderr,
240-
)
241-
return match.group(0)
242-
return header + new_block
248+
for pattern, replacer in field_patterns:
249+
new_block, count = pattern.subn(replacer, block, count=1)
250+
if count:
251+
return header + new_block
252+
print(
253+
f"Warning: failed to override default for {_class_name}.{_field_name}",
254+
file=sys.stderr,
255+
)
256+
return match.group(0)
243257

244258
content, count = class_pattern.subn(replace_block, content, count=1)
245259
if count == 0:

src/acp/schema.py

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,13 @@
88

99
from pydantic import BaseModel, Field, RootModel
1010

11+
1112
PermissionOptionKind = Literal["allow_once", "allow_always", "reject_once", "reject_always"]
1213
PlanEntryPriority = Literal["high", "medium", "low"]
1314
PlanEntryStatus = Literal["pending", "in_progress", "completed"]
1415
StopReason = Literal["end_turn", "max_tokens", "max_turn_requests", "refusal", "cancelled"]
1516
ToolCallStatus = Literal["pending", "in_progress", "completed", "failed"]
16-
ToolKind = Literal[
17-
"read",
18-
"edit",
19-
"delete",
20-
"move",
21-
"search",
22-
"execute",
23-
"think",
24-
"fetch",
25-
"switch_mode",
26-
"other",
27-
]
17+
ToolKind = Literal["read", "edit", "delete", "move", "search", "execute", "think", "fetch", "switch_mode", "other"]
2818

2919

3020
class AuthenticateRequest(BaseModel):
@@ -646,10 +636,7 @@ class PermissionOption(BaseModel):
646636
Optional[Any],
647637
Field(alias="_meta", description="Extension point for implementations"),
648638
] = None
649-
kind: Annotated[
650-
PermissionOptionKind,
651-
Field(description="Hint about the nature of this permission option."),
652-
]
639+
kind: Annotated[PermissionOptionKind, Field(description="Hint about the nature of this permission option.")]
653640
name: Annotated[str, Field(description="Human-readable label to display to the user.")]
654641
optionId: Annotated[str, Field(description="Unique identifier for this permission option.")]
655642

@@ -669,21 +656,15 @@ class PlanEntry(BaseModel):
669656
description="The relative importance of this task.\nUsed to indicate which tasks are most critical to the overall goal."
670657
),
671658
]
672-
status: Annotated[
673-
PlanEntryStatus,
674-
Field(description="Current execution status of this task."),
675-
]
659+
status: Annotated[PlanEntryStatus, Field(description="Current execution status of this task.")]
676660

677661

678662
class PromptResponse(BaseModel):
679663
field_meta: Annotated[
680664
Optional[Any],
681665
Field(alias="_meta", description="Extension point for implementations"),
682666
] = None
683-
stopReason: Annotated[
684-
StopReason,
685-
Field(description="Indicates why the agent stopped processing the turn."),
686-
]
667+
stopReason: Annotated[StopReason, Field(description="Indicates why the agent stopped processing the turn.")]
687668

688669

689670
class ReadTextFileRequest(BaseModel):
@@ -932,20 +913,14 @@ class ToolCallUpdate(BaseModel):
932913
Optional[List[Union[ContentToolCallContent, FileEditToolCallContent, TerminalToolCallContent]]],
933914
Field(description="Replace the content collection."),
934915
] = None
935-
kind: Annotated[
936-
Optional[ToolKind],
937-
Field(description="Update the tool kind."),
938-
] = None
916+
kind: Annotated[Optional[ToolKind], Field(description="Update the tool kind.")] = None
939917
locations: Annotated[
940918
Optional[List[ToolCallLocation]],
941919
Field(description="Replace the locations collection."),
942920
] = None
943921
rawInput: Annotated[Optional[Any], Field(description="Update the raw input.")] = None
944922
rawOutput: Annotated[Optional[Any], Field(description="Update the raw output.")] = None
945-
status: Annotated[
946-
Optional[ToolCallStatus],
947-
Field(description="Update the execution status."),
948-
] = None
923+
status: Annotated[Optional[ToolCallStatus], Field(description="Update the execution status.")] = None
949924
title: Annotated[Optional[str], Field(description="Update the human-readable title.")] = None
950925
toolCallId: Annotated[str, Field(description="The ID of the tool call being updated.")]
951926

@@ -988,10 +963,7 @@ class ToolCallStart(BaseModel):
988963
rawInput: Annotated[Optional[Any], Field(description="Raw input parameters sent to the tool.")] = None
989964
rawOutput: Annotated[Optional[Any], Field(description="Raw output returned by the tool.")] = None
990965
sessionUpdate: Literal["tool_call"]
991-
status: Annotated[
992-
Optional[ToolCallStatus],
993-
Field(description="Current execution status of the tool call."),
994-
] = None
966+
status: Annotated[Optional[ToolCallStatus], Field(description="Current execution status of the tool call.")] = None
995967
title: Annotated[
996968
str,
997969
Field(description="Human-readable title describing what the tool is doing."),
@@ -1011,21 +983,15 @@ class ToolCallProgress(BaseModel):
1011983
Optional[List[Union[ContentToolCallContent, FileEditToolCallContent, TerminalToolCallContent]]],
1012984
Field(description="Replace the content collection."),
1013985
] = None
1014-
kind: Annotated[
1015-
Optional[ToolKind],
1016-
Field(description="Update the tool kind."),
1017-
] = None
986+
kind: Annotated[Optional[ToolKind], Field(description="Update the tool kind.")] = None
1018987
locations: Annotated[
1019988
Optional[List[ToolCallLocation]],
1020989
Field(description="Replace the locations collection."),
1021990
] = None
1022991
rawInput: Annotated[Optional[Any], Field(description="Update the raw input.")] = None
1023992
rawOutput: Annotated[Optional[Any], Field(description="Update the raw output.")] = None
1024993
sessionUpdate: Literal["tool_call_update"]
1025-
status: Annotated[
1026-
Optional[ToolCallStatus],
1027-
Field(description="Update the execution status."),
1028-
] = None
994+
status: Annotated[Optional[ToolCallStatus], Field(description="Update the execution status.")] = None
1029995
title: Annotated[Optional[str], Field(description="Update the human-readable title.")] = None
1030996
toolCallId: Annotated[str, Field(description="The ID of the tool call being updated.")]
1031997

@@ -1051,10 +1017,7 @@ class ToolCall(BaseModel):
10511017
] = None
10521018
rawInput: Annotated[Optional[Any], Field(description="Raw input parameters sent to the tool.")] = None
10531019
rawOutput: Annotated[Optional[Any], Field(description="Raw output returned by the tool.")] = None
1054-
status: Annotated[
1055-
Optional[ToolCallStatus],
1056-
Field(description="Current execution status of the tool call."),
1057-
] = None
1020+
status: Annotated[Optional[ToolCallStatus], Field(description="Current execution status of the tool call.")] = None
10581021
title: Annotated[
10591022
str,
10601023
Field(description="Human-readable title describing what the tool is doing."),

0 commit comments

Comments
 (0)