# `A2UIAgent.SchemaPruning`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_agent/lib/a2ui_agent/schema_pruning.ex#L1)

Prunes the protocol schemas a prompt shows the model.

Catalogs are pruned with `A2UIAgent.CatalogTransformer`; the
agent-to-renderer and common types schemas belong to the protocol, so
they are pruned here.

# `prune_common_types`
*since 0.1.0* 

```elixir
@spec prune_common_types(map(), [map()]) :: map()
```

Keeps only the common type definitions in use: those the
`referencing` schemas refer to (as `common_types.json#/$defs/<name>` or
`#/$defs/<name>`) and those a definition in use refers to.

# `prune_messages`
*since 0.1.0* 

```elixir
@spec prune_messages(map(), [String.t()]) :: map()
```

Keeps only the allowed messages of an agent-to-renderer schema.

`allowed` names message actions (`"createSurface"`) or message
definitions (`"CreateSurfaceMessage"`). The allowlist is read
literally: an empty one admits no message and unknown names are
ignored. Definitions only the removed messages use are removed too.

    iex> schema = %{
    ...>   "oneOf" => [%{"$ref" => "#/$defs/A"}, %{"$ref" => "#/$defs/B"}],
    ...>   "$defs" => %{
    ...>     "A" => %{"properties" => %{"createSurface" => %{"$ref" => "#/$defs/Shared"}}},
    ...>     "B" => %{"properties" => %{"deleteSurface" => %{}}},
    ...>     "Shared" => %{}
    ...>   }
    ...> }
    iex> pruned = A2UIAgent.SchemaPruning.prune_messages(schema, ["createSurface"])
    iex> {pruned["oneOf"], Map.keys(pruned["$defs"])}
    {[%{"$ref" => "#/$defs/A"}], ["A", "Shared"]}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
