Skip to content

Commit 4affcb1

Browse files
committed
Rename type to itemType
1 parent 0621aea commit 4affcb1

File tree

4 files changed

+52
-59
lines changed

4 files changed

+52
-59
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

src/a2a/types.py

Lines changed: 34 additions & 42 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+
itemType: 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+
itemType: 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+
itemType: 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
"""
@@ -982,6 +980,10 @@ class Message(BaseModel):
982980
"""
983981
indicates the end of the event stream
984982
"""
983+
itemType: Literal['message'] = 'message'
984+
"""
985+
event type
986+
"""
985987
messageId: str
986988
"""
987989
identifier created by the message creator
@@ -1002,10 +1004,6 @@ class Message(BaseModel):
10021004
"""
10031005
identifier of task the message is related to
10041006
"""
1005-
type: Literal['message'] = 'message'
1006-
"""
1007-
event type
1008-
"""
10091007

10101008

10111009
class MessageSendParams(BaseModel):
@@ -1076,9 +1074,7 @@ class SendStreamingMessageRequest(BaseModel):
10761074

10771075

10781076
class SetTaskPushNotificationConfigResponse(
1079-
RootModel[
1080-
JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse
1081-
]
1077+
RootModel[JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse]
10821078
):
10831079
root: JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse
10841080
"""
@@ -1103,6 +1099,10 @@ class TaskArtifactUpdateEvent(BaseModel):
11031099
"""
11041100
the context the task is associated with
11051101
"""
1102+
itemType: Literal['artifact-update'] = 'artifact-update'
1103+
"""
1104+
event type
1105+
"""
11061106
lastChunk: bool | None = None
11071107
"""
11081108
Indicates if this is the last chunk of the artifact
@@ -1115,10 +1115,6 @@ class TaskArtifactUpdateEvent(BaseModel):
11151115
"""
11161116
Task id
11171117
"""
1118-
type: Literal['artifact-update'] = 'artifact-update'
1119-
"""
1120-
event type
1121-
"""
11221118

11231119

11241120
class TaskStatus(BaseModel):
@@ -1150,6 +1146,10 @@ class TaskStatusUpdateEvent(BaseModel):
11501146
"""
11511147
indicates the end of the event stream
11521148
"""
1149+
itemType: Literal['status-update'] = 'status-update'
1150+
"""
1151+
event type
1152+
"""
11531153
metadata: dict[str, Any] | None = None
11541154
"""
11551155
extension metadata
@@ -1162,10 +1162,6 @@ class TaskStatusUpdateEvent(BaseModel):
11621162
"""
11631163
Task id
11641164
"""
1165-
type: Literal['status-update'] = 'status-update'
1166-
"""
1167-
event type
1168-
"""
11691165

11701166

11711167
class A2ARequest(
@@ -1207,6 +1203,10 @@ class Task(BaseModel):
12071203
"""
12081204
unique identifier for the task
12091205
"""
1206+
itemType: Literal['task'] = 'task'
1207+
"""
1208+
event type
1209+
"""
12101210
metadata: dict[str, Any] | None = None
12111211
"""
12121212
extension metadata
@@ -1215,10 +1215,6 @@ class Task(BaseModel):
12151215
"""
12161216
current status of the task
12171217
"""
1218-
type: Literal['task'] = 'task'
1219-
"""
1220-
event type
1221-
"""
12221218

12231219

12241220
class CancelTaskSuccessResponse(BaseModel):
@@ -1301,9 +1297,7 @@ class SendStreamingMessageSuccessResponse(BaseModel):
13011297
"""
13021298

13031299

1304-
class CancelTaskResponse(
1305-
RootModel[JSONRPCErrorResponse | CancelTaskSuccessResponse]
1306-
):
1300+
class CancelTaskResponse(RootModel[JSONRPCErrorResponse | CancelTaskSuccessResponse]):
13071301
root: JSONRPCErrorResponse | CancelTaskSuccessResponse
13081302
"""
13091303
JSON-RPC response for the 'tasks/cancel' method.
@@ -1342,9 +1336,7 @@ class JSONRPCResponse(
13421336
"""
13431337

13441338

1345-
class SendMessageResponse(
1346-
RootModel[JSONRPCErrorResponse | SendMessageSuccessResponse]
1347-
):
1339+
class SendMessageResponse(RootModel[JSONRPCErrorResponse | SendMessageSuccessResponse]):
13481340
root: JSONRPCErrorResponse | SendMessageSuccessResponse
13491341
"""
13501342
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+
'itemType': '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+
'itemType': 'task',
7474
}
7575

7676

tests/test_types.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@
106106
'version': '1.0',
107107
}
108108

109-
TEXT_PART_DATA: dict[str, Any] = {'type': 'text', 'text': 'Hello'}
109+
TEXT_PART_DATA: dict[str, Any] = {'itemType': 'text', 'text': 'Hello'}
110110
FILE_URI_PART_DATA: dict[str, Any] = {
111-
'type': 'file',
111+
'itemType': 'file',
112112
'file': {'uri': 'file:///path/to/file.txt', 'mimeType': 'text/plain'},
113113
}
114114
FILE_BYTES_PART_DATA: dict[str, Any] = {
115-
'type': 'file',
115+
'itemType': 'file',
116116
'file': {'bytes': 'aGVsbG8=', 'name': 'hello.txt'}, # base64 for "hello"
117117
}
118-
DATA_PART_DATA: dict[str, Any] = {'type': 'data', 'data': {'key': 'value'}}
118+
DATA_PART_DATA: dict[str, Any] = {'itemType': 'data', 'data': {'key': 'value'}}
119119

120120
MINIMAL_MESSAGE_USER: dict[str, Any] = {
121121
'role': 'user',
122122
'parts': [TEXT_PART_DATA],
123123
'messageId': 'msg-123',
124-
'type': 'message',
124+
'itemType': 'message',
125125
}
126126

127127
AGENT_MESSAGE_WITH_FILE: dict[str, Any] = {
@@ -142,7 +142,7 @@
142142
'id': 'task-abc',
143143
'contextId': 'session-xyz',
144144
'status': MINIMAL_TASK_STATUS,
145-
'type': 'task',
145+
'itemType': 'task',
146146
}
147147
FULL_TASK: dict[str, Any] = {
148148
'id': 'task-abc',
@@ -157,7 +157,7 @@
157157
}
158158
],
159159
'metadata': {'priority': 'high'},
160-
'type': 'task',
160+
'itemType': 'task',
161161
}
162162

163163
MINIMAL_TASK_ID_PARAMS: dict[str, Any] = {'id': 'task-123'}
@@ -269,15 +269,15 @@ def test_agent_card_invalid():
269269

270270
def test_text_part():
271271
part = TextPart(**TEXT_PART_DATA)
272-
assert part.type == 'text'
272+
assert part.itemType == 'text'
273273
assert part.text == 'Hello'
274274
assert part.metadata is None
275275

276276
with pytest.raises(ValidationError):
277277
TextPart(type='text') # Missing text # type: ignore
278278
with pytest.raises(ValidationError):
279279
TextPart(
280-
type='file', # type: ignore
280+
itemType='file', # type: ignore
281281
text='hello',
282282
) # Wrong type literal
283283

@@ -287,15 +287,15 @@ def test_file_part_variants():
287287
file_uri = FileWithUri(
288288
uri='file:///path/to/file.txt', mimeType='text/plain'
289289
)
290-
part_uri = FilePart(type='file', file=file_uri)
290+
part_uri = FilePart(itemType='file', file=file_uri)
291291
assert isinstance(part_uri.file, FileWithUri)
292292
assert part_uri.file.uri == 'file:///path/to/file.txt'
293293
assert part_uri.file.mimeType == 'text/plain'
294294
assert not hasattr(part_uri.file, 'bytes')
295295

296296
# Bytes variant
297297
file_bytes = FileWithBytes(bytes='aGVsbG8=', name='hello.txt')
298-
part_bytes = FilePart(type='file', file=file_bytes)
298+
part_bytes = FilePart(itemType='file', file=file_bytes)
299299
assert isinstance(part_bytes.file, FileWithBytes)
300300
assert part_bytes.file.bytes == 'aGVsbG8='
301301
assert part_bytes.file.name == 'hello.txt'
@@ -312,14 +312,14 @@ def test_file_part_variants():
312312

313313
# Invalid - wrong type literal
314314
with pytest.raises(ValidationError):
315-
FilePart(type='text', file=file_uri) # type: ignore
315+
FilePart(itemType='text', file=file_uri) # type: ignore
316316

317317
FilePart(**FILE_URI_PART_DATA, extra='extra') # type: ignore
318318

319319

320320
def test_data_part():
321321
part = DataPart(**DATA_PART_DATA)
322-
assert part.type == 'data'
322+
assert part.itemType == 'data'
323323
assert part.data == {'key': 'value'}
324324

325325
with pytest.raises(ValidationError):
@@ -656,7 +656,7 @@ def test_send_message_streaming_status_update_response() -> None:
656656
'taskId': '1',
657657
'contextId': '2',
658658
'final': False,
659-
'type': 'status-update',
659+
'itemType': 'status-update',
660660
}
661661

662662
event_data: dict[str, Any] = {
@@ -716,7 +716,7 @@ def test_send_message_streaming_artifact_update_response() -> None:
716716
'contextId': '2',
717717
'append': False,
718718
'lastChunk': True,
719-
'type': 'artifact-update',
719+
'itemType': 'artifact-update',
720720
}
721721
event_data: dict[str, Any] = {
722722
'jsonrpc': '2.0',

0 commit comments

Comments
 (0)