Version answer display instructions and restrict unsupported payloads (#60904)

## What changed

- Replace free-form `AgentMessageDisplay` actions with a version `1` contract using `show`, `hide`, and `block` modes, with typed annotations, replacements, block reasons, and trusted-contact handling.
- Discard invalid or unsupported display instructions and set `moderated` to `true` when reading moderation data in Rust and the Python SDK.
- Update generated JSON schemas, TypeScript types, and Python SDK models to match the contract.

## Testing

Add coverage for display variants, tolerance of extra fields, and unsupported-version or unknown-mode fallback. Update the final-answer moderation test and add Python coverage for thread history and item notifications.

GitOrigin-RevId: ec64070002da67e8e377dccb3728806ac8b290e7
This commit is contained in:
psachdeva-oai
2026-11-11 23:35:05 +00:00
committed by copyberry
parent 9248df5978
commit 8a4b226ad5
39 changed files with 4261 additions and 643 deletions
@@ -142,3 +142,37 @@ def test_model_provider_errors_round_trip_wire_names(payload):
error = ModelProviderError.model_validate(payload)
assert error.model_dump(by_alias=True) == payload
def test_answer_display_is_read_in_thread_history_and_notifications():
from openai_codex.generated.v2_all import ItemCompletedNotification, ThreadItemsListResponse
display = {
"version": 1,
"mode": "show",
"trustedContacts": "check",
"annotation": {"kind": "wellbeingHelpline", "subject": "answer"},
}
item = {
"id": "a",
"type": "agentMessage",
"text": "answer",
"moderation": {"moderated": True, "display": {**display, "additionalV1Field": True}},
}
history = ThreadItemsListResponse.model_validate({"data": [{"turnId": "u", "item": item}]})
event = ItemCompletedNotification.model_validate(
{"threadId": "t", "turnId": "u", "completedAtMs": 1, "item": item}
)
for envelope in (history.data[0].item, event.item):
assert (
envelope.root.moderation.display.model_dump(
mode="json", by_alias=True, exclude_none=True
)
== display
)
item["moderation"] = {"moderated": False, "display": {"version": 2, "mode": "new"}}
moderated = ItemCompletedNotification.model_validate(
{"threadId": "t", "turnId": "u", "completedAtMs": 1, "item": item}
).item.root.moderation
assert moderated.moderated is True
assert moderated.display is None