Skip to content

Commit 8e11ddc

Browse files
committed
Make ServerCallContext a pydantic model
1 parent 45202a5 commit 8e11ddc

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/a2a/server/context.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,19 @@
33
import collections.abc
44
import typing
55

6+
from pydantic import BaseModel, Field
7+
68
from a2a.auth.user import UnauthenticatedUser, User
79

810

911
State = collections.abc.MutableMapping[str, typing.Any]
1012

1113

12-
class ServerCallContext:
14+
class ServerCallContext(BaseModel):
1315
"""A context passed when calling a server method.
1416
1517
This class allows storing arbitrary user data in the state attribute.
1618
"""
1719

18-
def __init__(self, state: State | None = None, user: User | None = None):
19-
self._state = state or {}
20-
self._user = user or UnauthenticatedUser()
21-
22-
@property
23-
def user(self) -> User:
24-
"""Get the user associated with this context, or UnauthenticatedUser."""
25-
return self._user
26-
27-
@property
28-
def state(self) -> State:
29-
"""Get the user-provided state."""
30-
return self._state
20+
state: State = Field(default={})
21+
user: User = Field(default=UnauthenticatedUser())

0 commit comments

Comments
 (0)