|
1 | 1 | import base64 |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING, Any |
4 | | - |
5 | | - |
6 | | -if TYPE_CHECKING: |
7 | | - from cryptography.fernet import Fernet |
| 3 | +from typing import Any |
8 | 4 |
|
9 | 5 | from google.protobuf.json_format import MessageToDict, ParseDict |
10 | 6 |
|
11 | 7 | from a2a.compat.v0_3 import types as types_v03 |
12 | 8 | from a2a.compat.v0_3.versions import is_legacy_version |
13 | | -from a2a.server.models import PushNotificationConfigModel, TaskModel |
14 | 9 | from a2a.types import a2a_pb2 as pb2_v10 |
15 | 10 | from a2a.utils import constants, errors |
16 | 11 |
|
@@ -1378,77 +1373,3 @@ def to_compat_get_extended_agent_card_request( |
1378 | 1373 | ) -> types_v03.GetAuthenticatedExtendedCardRequest: |
1379 | 1374 | """Convert get extended agent card request to v0.3 compat type.""" |
1380 | 1375 | return types_v03.GetAuthenticatedExtendedCardRequest(id=request_id) |
1381 | | - |
1382 | | - |
1383 | | -def core_to_compat_task_model(task: pb2_v10.Task, owner: str) -> TaskModel: |
1384 | | - """Converts a 1.0 core Task to a TaskModel using v0.3 JSON structure.""" |
1385 | | - compat_task = to_compat_task(task) |
1386 | | - data = compat_task.model_dump(mode='json') |
1387 | | - |
1388 | | - return TaskModel( |
1389 | | - id=task.id, |
1390 | | - context_id=task.context_id, |
1391 | | - owner=owner, |
1392 | | - status=data.get('status'), |
1393 | | - history=data.get('history'), |
1394 | | - artifacts=data.get('artifacts'), |
1395 | | - task_metadata=data.get('metadata'), |
1396 | | - protocol_version='0.3', |
1397 | | - ) |
1398 | | - |
1399 | | - |
1400 | | -def compat_task_model_to_core(task_model: TaskModel) -> pb2_v10.Task: |
1401 | | - """Converts a TaskModel with v0.3 structure to a 1.0 core Task.""" |
1402 | | - compat_task = types_v03.Task( |
1403 | | - id=task_model.id, |
1404 | | - context_id=task_model.context_id, |
1405 | | - status=types_v03.TaskStatus.model_validate(task_model.status), |
1406 | | - artifacts=( |
1407 | | - [types_v03.Artifact.model_validate(a) for a in task_model.artifacts] |
1408 | | - if task_model.artifacts |
1409 | | - else [] |
1410 | | - ), |
1411 | | - history=( |
1412 | | - [types_v03.Message.model_validate(h) for h in task_model.history] |
1413 | | - if task_model.history |
1414 | | - else [] |
1415 | | - ), |
1416 | | - metadata=task_model.task_metadata, |
1417 | | - ) |
1418 | | - return to_core_task(compat_task) |
1419 | | - |
1420 | | - |
1421 | | -def core_to_compat_push_notification_config_model( |
1422 | | - task_id: str, |
1423 | | - config: pb2_v10.TaskPushNotificationConfig, |
1424 | | - owner: str, |
1425 | | - fernet: 'Fernet | None' = None, |
1426 | | -) -> PushNotificationConfigModel: |
1427 | | - """Converts a 1.0 core TaskPushNotificationConfig to a PushNotificationConfigModel using v0.3 JSON structure.""" |
1428 | | - compat_config = to_compat_push_notification_config(config) |
1429 | | - |
1430 | | - json_payload = compat_config.model_dump_json().encode('utf-8') |
1431 | | - data_to_store = fernet.encrypt(json_payload) if fernet else json_payload |
1432 | | - |
1433 | | - return PushNotificationConfigModel( |
1434 | | - task_id=task_id, |
1435 | | - config_id=config.id, |
1436 | | - owner=owner, |
1437 | | - config_data=data_to_store, |
1438 | | - protocol_version='0.3', |
1439 | | - ) |
1440 | | - |
1441 | | - |
1442 | | -def compat_push_notification_config_model_to_core( |
1443 | | - model_instance: str, task_id: str |
1444 | | -) -> pb2_v10.TaskPushNotificationConfig: |
1445 | | - """Converts a PushNotificationConfigModel with v0.3 structure back to a 1.0 core TaskPushNotificationConfig.""" |
1446 | | - inner_config = types_v03.PushNotificationConfig.model_validate_json( |
1447 | | - model_instance |
1448 | | - ) |
1449 | | - return to_core_task_push_notification_config( |
1450 | | - types_v03.TaskPushNotificationConfig( |
1451 | | - task_id=task_id, |
1452 | | - push_notification_config=inner_config, |
1453 | | - ) |
1454 | | - ) |
0 commit comments