|
1 | | -"""Adopter pattern: create_mcp_webhook_payload usage with cast() for field access. |
| 1 | +"""Adopter pattern: create_mcp_webhook_payload usage with typed attribute access. |
2 | 2 |
|
3 | | -create_mcp_webhook_payload returns dict[str, Any]. The zero-ignore pattern |
4 | | -for extracting typed values is cast() — explicit, visible, and does not |
5 | | -require # type: ignore. |
| 3 | +create_mcp_webhook_payload returns a typed McpWebhookPayload Pydantic model. |
| 4 | +The zero-ignore adopter pattern is direct attribute access for typed reads |
| 5 | +and to_wire_dict() for HTTP serialization — no cast() needed. |
6 | 6 | """ |
| 7 | + |
7 | 8 | from __future__ import annotations |
8 | 9 |
|
9 | 10 | import json |
10 | | -from typing import Any, cast |
| 11 | +from typing import Any |
11 | 12 |
|
12 | | -from adcp.types import GeneratedTaskStatus |
13 | | -from adcp.webhooks import create_mcp_webhook_payload |
| 13 | +from adcp.types import GeneratedTaskStatus, McpWebhookPayload, TaskType |
| 14 | +from adcp.webhooks import create_mcp_webhook_payload, to_wire_dict |
14 | 15 |
|
15 | 16 |
|
16 | | -def build_completed_payload(task_id: str, products: list[dict[str, Any]]) -> dict[str, Any]: |
| 17 | +def build_completed_payload(task_id: str, media_buy_id: str) -> McpWebhookPayload: |
17 | 18 | return create_mcp_webhook_payload( |
18 | 19 | task_id=task_id, |
19 | | - task_type="get_products", |
| 20 | + task_type=TaskType.create_media_buy, |
20 | 21 | status=GeneratedTaskStatus.completed, |
21 | | - result={"products": products}, |
22 | | - message=f"Found {len(products)} products", |
| 22 | + result={"media_buy_id": media_buy_id, "status": "active"}, |
| 23 | + message=f"Media buy {media_buy_id} activated", |
23 | 24 | ) |
24 | 25 |
|
25 | 26 |
|
26 | | -def extract_task_id(payload: dict[str, Any]) -> str: |
27 | | - return cast(str, payload["task_id"]) |
| 27 | +def extract_task_id(payload: McpWebhookPayload) -> str: |
| 28 | + return payload.task_id |
| 29 | + |
| 30 | + |
| 31 | +def extract_status(payload: McpWebhookPayload) -> str: |
| 32 | + return payload.status |
28 | 33 |
|
29 | 34 |
|
30 | | -def extract_status(payload: dict[str, Any]) -> str: |
31 | | - return cast(str, payload["status"]) |
| 35 | +def serialize_for_http(payload: McpWebhookPayload) -> dict[str, Any]: |
| 36 | + return to_wire_dict(payload) |
32 | 37 |
|
33 | 38 |
|
34 | | -payload = build_completed_payload("task_123", [{"product_id": "p1"}]) |
| 39 | +payload = build_completed_payload("task_123", "mb_abc") |
35 | 40 |
|
36 | | -serialized = json.dumps(payload) |
| 41 | +serialized = json.dumps(serialize_for_http(payload)) |
37 | 42 | assert isinstance(serialized, str) |
38 | 43 |
|
39 | 44 | task_id = extract_task_id(payload) |
|
0 commit comments