# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-reject-an-a2a-v1-0-delegation-because-the-remote-agent-card-s-defaultinputmodes-silently-disagrees-with-the-task-s-declared-medi.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-reject-an-a2a-v1-0-delegation-because-the-remote-agent-card-s-defaultinputmodes-silently-disagrees-with-the-task-s-declared-medi.warrant.json
# Markdown SHA-256:   db4efe228c3c6d0b33fd5ad7d3a80f2e7ce245e45aa03527b31a2fac106b4055
# Code AST SHA-256:   3f6f0e745484869ab2226237433c4a74c6c6409e119624045aa3b03389278a75
# Verified Classes:   InheritedInputModesDelegationError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class InheritedInputModesDelegationError(RuntimeError):
    """Raised when a client attempts to delegate a non-text payload to an
    A2A v1.0 skill whose inputModes is inherited from defaultInputModes
    without a prior successful canary probe against the current card version."""


CANARY_MEDIA_TYPE = "text/plain"


def resolve_effective_input_modes(skill: dict, card: dict) -> list[str]:
    if "inputModes" in skill and skill["inputModes"]:
        return list(skill["inputModes"])
    return list(card.get("defaultInputModes", []))


def guard_delegation(
    skill: dict,
    card: dict,
    payload_media_type: str,
    card_version: str,
    probed_versions: set[tuple[str, str]],
) -> None:
    effective = resolve_effective_input_modes(skill, card)
    if payload_media_type not in effective:
        raise InheritedInputModesDelegationError(
            f"media type {payload_media_type!r} not in effective input modes "
            f"{effective!r} for skill {skill.get('name')!r}"
        )
    inherited = "inputModes" not in skill or not skill["inputModes"]
    if inherited and payload_media_type != CANARY_MEDIA_TYPE:
        probe_key = (skill["name"], card_version)
        if probe_key not in probed_versions:
            raise InheritedInputModesDelegationError(
                f"skill {skill['name']!r} inherits inputModes from "
                f"defaultInputModes; refusing {payload_media_type!r} dispatch "
                f"against card version {card_version!r} without canary probe"
            )


def dispatch(card: dict, skill_name: str, payload_media_type: str,
             card_version: str, probed_versions: set[tuple[str, str]]) -> None:
    skill = next((s for s in card["skills"] if s["name"] == skill_name), None)
    if skill is None:
        raise InheritedInputModesDelegationError(f"unknown skill {skill_name!r}")
    guard_delegation(skill, card, payload_media_type, card_version, probed_versions)
    # ... proceed with tasks/send ...
