Skip to content

Commit ffe2f0f

Browse files
kthota-gholtskinner
authored andcommitted
fix: Rename type to kind (#34)
* Handle reusing queue on task events * Rename type to itemType * Replace usages of type * Add type generation script * Remove final from message type * Rename itemType to kind * fix linting in md --------- Co-authored-by: Holt Skinner <[email protected]>
1 parent 6733d20 commit ffe2f0f

File tree

12 files changed

+67
-69
lines changed

12 files changed

+67
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ __pycache__
88
.venv
99
coverage.xml
1010
.nox
11+
spec.json

development.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Development
2+
3+
## Type generation from spec
4+
5+
<!-- TODO replace spec.json with the public url so we always get the latest version-->
6+
7+
```bash
8+
uv run datamodel-codegen --input ./spec.json --input-file-type jsonschema --output ./src/a2a/types.py --target-python-version 3.10 --output-model-type pydantic_v2.BaseModel --disable-timestamp --use-schema-description --use-union-operator --use-field-description --use-default --use-default-kwarg --use-one-literal-as-default --class-name A2A --use-standard-collections
9+
```

examples/helloworld/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def main() -> None:
1818
'message': {
1919
'role': 'user',
2020
'parts': [
21-
{'type': 'text', 'text': 'how much is 10 USD in INR?'}
21+
{'kind': 'text', 'text': 'how much is 10 USD in INR?'}
2222
],
2323
'messageId': uuid4().hex,
2424
},

examples/langgraph/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create_send_message_payload(
2626
payload: dict[str, Any] = {
2727
'message': {
2828
'role': 'user',
29-
'parts': [{'type': 'text', 'text': text}],
29+
'parts': [{'kind': 'text', 'text': text}],
3030
'messageId': uuid4().hex,
3131
},
3232
}

src/a2a/types.py

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ class DataPart(BaseModel):
133133
"""
134134
Structured data content
135135
"""
136-
metadata: dict[str, Any] | None = None
136+
kind: Literal['data'] = 'data'
137137
"""
138-
Optional metadata associated with the part.
138+
Part type - data for DataParts
139139
"""
140-
type: Literal['data'] = 'data'
140+
metadata: dict[str, Any] | None = None
141141
"""
142-
Part type - data for DataParts
142+
Optional metadata associated with the part.
143143
"""
144144

145145

@@ -577,11 +577,11 @@ class TaskState(Enum):
577577
submitted = 'submitted'
578578
working = 'working'
579579
input_required = 'input-required'
580-
auth_required = 'auth-required'
581580
completed = 'completed'
582581
canceled = 'canceled'
583582
failed = 'failed'
584583
rejected = 'rejected'
584+
auth_required = 'auth-required'
585585
unknown = 'unknown'
586586

587587

@@ -590,6 +590,10 @@ class TextPart(BaseModel):
590590
Represents a text segment within parts.
591591
"""
592592

593+
kind: Literal['text'] = 'text'
594+
"""
595+
Part type - text for TextParts
596+
"""
593597
metadata: dict[str, Any] | None = None
594598
"""
595599
Optional metadata associated with the part.
@@ -598,10 +602,6 @@ class TextPart(BaseModel):
598602
"""
599603
Text content
600604
"""
601-
type: Literal['text'] = 'text'
602-
"""
603-
Part type - text for TextParts
604-
"""
605605

606606

607607
class UnsupportedOperationError(BaseModel):
@@ -745,13 +745,13 @@ class FilePart(BaseModel):
745745
"""
746746
File content either as url or bytes
747747
"""
748-
metadata: dict[str, Any] | None = None
748+
kind: Literal['file'] = 'file'
749749
"""
750-
Optional metadata associated with the part.
750+
Part type - file for FileParts
751751
"""
752-
type: Literal['file'] = 'file'
752+
metadata: dict[str, Any] | None = None
753753
"""
754-
Part type - file for FileParts
754+
Optional metadata associated with the part.
755755
"""
756756

757757

@@ -933,7 +933,7 @@ class SetTaskPushNotificationConfigSuccessResponse(BaseModel):
933933

934934
class Artifact(BaseModel):
935935
"""
936-
Represents an artifact generated for a task.
936+
Represents an artifact generated for a task task.
937937
"""
938938

939939
artifactId: str
@@ -959,9 +959,7 @@ class Artifact(BaseModel):
959959

960960

961961
class GetTaskPushNotificationConfigResponse(
962-
RootModel[
963-
JSONRPCErrorResponse | GetTaskPushNotificationConfigSuccessResponse
964-
]
962+
RootModel[JSONRPCErrorResponse | GetTaskPushNotificationConfigSuccessResponse]
965963
):
966964
root: JSONRPCErrorResponse | GetTaskPushNotificationConfigSuccessResponse
967965
"""
@@ -978,9 +976,9 @@ class Message(BaseModel):
978976
"""
979977
the context the message is associated with
980978
"""
981-
final: bool | None = None
979+
kind: Literal['message'] = 'message'
982980
"""
983-
indicates the end of the event stream
981+
event type
984982
"""
985983
messageId: str
986984
"""
@@ -1002,10 +1000,6 @@ class Message(BaseModel):
10021000
"""
10031001
identifier of task the message is related to
10041002
"""
1005-
type: Literal['message'] = 'message'
1006-
"""
1007-
event type
1008-
"""
10091003

10101004

10111005
class MessageSendParams(BaseModel):
@@ -1076,9 +1070,7 @@ class SendStreamingMessageRequest(BaseModel):
10761070

10771071

10781072
class SetTaskPushNotificationConfigResponse(
1079-
RootModel[
1080-
JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse
1081-
]
1073+
RootModel[JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse]
10821074
):
10831075
root: JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse
10841076
"""
@@ -1103,6 +1095,10 @@ class TaskArtifactUpdateEvent(BaseModel):
11031095
"""
11041096
the context the task is associated with
11051097
"""
1098+
kind: Literal['artifact-update'] = 'artifact-update'
1099+
"""
1100+
event type
1101+
"""
11061102
lastChunk: bool | None = None
11071103
"""
11081104
Indicates if this is the last chunk of the artifact
@@ -1115,10 +1111,6 @@ class TaskArtifactUpdateEvent(BaseModel):
11151111
"""
11161112
Task id
11171113
"""
1118-
type: Literal['artifact-update'] = 'artifact-update'
1119-
"""
1120-
event type
1121-
"""
11221114

11231115

11241116
class TaskStatus(BaseModel):
@@ -1150,6 +1142,10 @@ class TaskStatusUpdateEvent(BaseModel):
11501142
"""
11511143
indicates the end of the event stream
11521144
"""
1145+
kind: Literal['status-update'] = 'status-update'
1146+
"""
1147+
event type
1148+
"""
11531149
metadata: dict[str, Any] | None = None
11541150
"""
11551151
extension metadata
@@ -1162,10 +1158,6 @@ class TaskStatusUpdateEvent(BaseModel):
11621158
"""
11631159
Task id
11641160
"""
1165-
type: Literal['status-update'] = 'status-update'
1166-
"""
1167-
event type
1168-
"""
11691161

11701162

11711163
class A2ARequest(
@@ -1207,6 +1199,10 @@ class Task(BaseModel):
12071199
"""
12081200
unique identifier for the task
12091201
"""
1202+
kind: Literal['task'] = 'task'
1203+
"""
1204+
event type
1205+
"""
12101206
metadata: dict[str, Any] | None = None
12111207
"""
12121208
extension metadata
@@ -1215,10 +1211,6 @@ class Task(BaseModel):
12151211
"""
12161212
current status of the task
12171213
"""
1218-
type: Literal['task'] = 'task'
1219-
"""
1220-
event type
1221-
"""
12221214

12231215

12241216
class CancelTaskSuccessResponse(BaseModel):
@@ -1301,9 +1293,7 @@ class SendStreamingMessageSuccessResponse(BaseModel):
13011293
"""
13021294

13031295

1304-
class CancelTaskResponse(
1305-
RootModel[JSONRPCErrorResponse | CancelTaskSuccessResponse]
1306-
):
1296+
class CancelTaskResponse(RootModel[JSONRPCErrorResponse | CancelTaskSuccessResponse]):
13071297
root: JSONRPCErrorResponse | CancelTaskSuccessResponse
13081298
"""
13091299
JSON-RPC response for the 'tasks/cancel' method.
@@ -1342,9 +1332,7 @@ class JSONRPCResponse(
13421332
"""
13431333

13441334

1345-
class SendMessageResponse(
1346-
RootModel[JSONRPCErrorResponse | SendMessageSuccessResponse]
1347-
):
1335+
class SendMessageResponse(RootModel[JSONRPCErrorResponse | SendMessageSuccessResponse]):
13481336
root: JSONRPCErrorResponse | SendMessageSuccessResponse
13491337
"""
13501338
JSON-RPC response model for the 'message/send' method.

tests/client/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
'id': 'task-abc',
6464
'contextId': 'session-xyz',
6565
'status': {'state': 'working'},
66-
'type': 'task',
66+
'kind': 'task',
6767
}
6868

6969
MINIMAL_CANCELLED_TASK: dict[str, Any] = {
7070
'id': 'task-abc',
7171
'contextId': 'session-xyz',
7272
'status': {'state': 'canceled'},
73-
'type': 'task',
73+
'kind': 'task',
7474
}
7575

7676

tests/server/events/test_event_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'id': '123',
2929
'contextId': 'session-xyz',
3030
'status': {'state': 'submitted'},
31-
'type': 'task',
31+
'kind': 'task',
3232
}
3333

3434
MESSAGE_PAYLOAD: dict[str, Any] = {

tests/server/events/test_event_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'id': '123',
2222
'contextId': 'session-xyz',
2323
'status': {'state': 'submitted'},
24-
'type': 'task',
24+
'kind': 'task',
2525
}
2626
MESSAGE_PAYLOAD: dict[str, Any] = {
2727
'role': 'agent',

tests/server/request_handlers/test_jsonrpc_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
'id': 'task_123',
6363
'contextId': 'session-xyz',
6464
'status': {'state': 'submitted'},
65-
'type': 'task',
65+
'kind': 'task',
6666
}
6767
MESSAGE_PAYLOAD: dict[str, Any] = {
6868
'role': 'agent',

tests/server/tasks/test_inmemory_task_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'id': 'task-abc',
1111
'contextId': 'session-xyz',
1212
'status': {'state': 'submitted'},
13-
'type': 'task',
13+
'kind': 'task',
1414
}
1515

1616

0 commit comments

Comments
 (0)