# `AgentBlueprintProtocol`
[🔗](https://github.com/baselabs/agent_blueprint_protocol/blob/v1.1.0/lib/agent_blueprint_protocol.ex#L1)

The facade decodes and verifies protocol artifacts through the Elixir reference implementation.

Use it when an application needs artifact codecs and combined verification calls.

This module does not authorize operations.

## Example

```elixir
bytes = File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))
match?({:ok, %AgentBlueprintProtocol.Blueprint{}}, AgentBlueprintProtocol.decode_blueprint(bytes))
```

# `failure`
*since 1.0.0* 

```elixir
@type failure() :: {:error, AgentBlueprintProtocol.Error.t()}
```

A typed error result returned by a fallible facade operation.

# `canonical_bytes`
*since 1.0.0* 

```elixir
@spec canonical_bytes(
  AgentBlueprintProtocol.Blueprint.t()
  | AgentBlueprintProtocol.Deployment.t()
  | AgentBlueprintProtocol.Federation.t()
) :: {:ok, binary()} | failure()
```

Returns canonical JSON bytes for the supplied artifact.

## Example
    iex> with {:ok, blueprint} <- AgentBlueprintProtocol.Blueprint.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))), do: match?({:ok, bytes} when is_binary(bytes), AgentBlueprintProtocol.canonical_bytes(blueprint))
    true

# `decode_blueprint`
*since 1.0.0* 

```elixir
@spec decode_blueprint(binary(), AgentBlueprintProtocol.Bounds.t() | map()) ::
  {:ok, AgentBlueprintProtocol.Blueprint.t()} | failure()
```

Decodes and validates Blueprint bytes under the supplied parse limits.

## Example
    iex> bytes = File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))
    iex> match?({:ok, %AgentBlueprintProtocol.Blueprint{}}, AgentBlueprintProtocol.decode_blueprint(bytes))
    true
    iex> match?({:ok, %AgentBlueprintProtocol.Blueprint{}}, AgentBlueprintProtocol.decode_blueprint(bytes, %{bytes: 5000}))
    true

# `decode_deployment`
*since 1.0.0* 

```elixir
@spec decode_deployment(binary(), AgentBlueprintProtocol.Bounds.t() | map()) ::
  {:ok, AgentBlueprintProtocol.Deployment.t()} | failure()
```

Decodes and validates Deployment bytes under the supplied parse limits.

## Example
    iex> bytes = File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-deployment.json"))
    iex> match?({:ok, %AgentBlueprintProtocol.Deployment{}}, AgentBlueprintProtocol.decode_deployment(bytes))
    true
    iex> match?({:ok, %AgentBlueprintProtocol.Deployment{}}, AgentBlueprintProtocol.decode_deployment(bytes, %{bytes: 5000}))
    true

# `decode_federation_envelope`
*since 1.0.0* 

```elixir
@spec decode_federation_envelope(binary(), AgentBlueprintProtocol.Bounds.t() | map()) ::
  {:ok, AgentBlueprintProtocol.Federation.t()} | failure()
```

Decodes and validates Federation envelope bytes under the supplied parse limits.

## Example
    iex> bytes = File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))
    iex> match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.decode_federation_envelope(bytes))
    true
    iex> match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.decode_federation_envelope(bytes, %{bytes: 5000}))
    true

# `federation_mapping`
*since 1.0.0* 

```elixir
@spec federation_mapping() :: [AgentBlueprintProtocol.Federation.Mapping.Row.t()]
```

Returns the field mapping data for the supported federation carriers.

## Example

    iex> is_list(AgentBlueprintProtocol.federation_mapping())
    true

# `intersect`
*since 1.0.0* 

```elixir
@spec intersect(AgentBlueprintProtocol.BoundsAlgebra.Sources.t()) ::
  {:ok, AgentBlueprintProtocol.BoundsAlgebra.Result.t()} | failure()
```

Intersects the Blueprint, Deployment, and host bound sources.

## Example
    iex> with {:ok, blueprint} <- AgentBlueprintProtocol.Blueprint.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))), {:ok, deployment} <- AgentBlueprintProtocol.Deployment.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-deployment.json"))), {:ok, blueprint_bounds} <- AgentBlueprintProtocol.BoundsAlgebra.from_blueprint(blueprint), {:ok, deployment_bounds} <- AgentBlueprintProtocol.BoundsAlgebra.from_deployment(deployment), sources = %AgentBlueprintProtocol.BoundsAlgebra.Sources{blueprint: blueprint_bounds, deployment: deployment_bounds, host: deployment_bounds, protected_clamp: :acknowledge}, do: match?({:ok, %AgentBlueprintProtocol.BoundsAlgebra.Result{}}, AgentBlueprintProtocol.intersect(sources))
    true

# `negotiate`
*since 1.0.0* 

```elixir
@spec negotiate(
  AgentBlueprintProtocol.Blueprint.t()
  | AgentBlueprintProtocol.Deployment.t()
  | AgentBlueprintProtocol.Json.value(),
  AgentBlueprintProtocol.Negotiation.Support.t()
) :: {:ok, AgentBlueprintProtocol.Negotiation.Outcome.t()} | failure()
```

Checks an artifact against a consumer support posture.

## Example
    iex> with {:ok, blueprint} <- AgentBlueprintProtocol.Blueprint.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))), support = %AgentBlueprintProtocol.Negotiation.Support{revisions: MapSet.new([1]), core_fields: MapSet.new([])}, do: match?({:ok, %AgentBlueprintProtocol.Negotiation.Outcome{}}, AgentBlueprintProtocol.negotiate(blueprint, support))
    true

# `reconcile`
*since 1.0.0* 

```elixir
@spec reconcile(
  AgentBlueprintProtocol.Blueprint.t(),
  AgentBlueprintProtocol.Deployment.t(),
  AgentBlueprintProtocol.Reconcile.Inputs.t()
) :: {:ok, AgentBlueprintProtocol.Evidence.t()} | failure()
```

Runs the composed verification pass for a Blueprint and Deployment pair.

## Example
    iex> with {:ok, blueprint} <- AgentBlueprintProtocol.Blueprint.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))), {:ok, deployment} <- AgentBlueprintProtocol.Deployment.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-deployment.json"))), {:ok, host_bounds} <- AgentBlueprintProtocol.BoundsAlgebra.from_deployment(deployment), inputs = %AgentBlueprintProtocol.Reconcile.Inputs{host_bounds: host_bounds, support: %AgentBlueprintProtocol.Negotiation.Support{revisions: MapSet.new([1]), core_fields: MapSet.new([])}, keys: [], protected_clamp: :acknowledge, observations: %AgentBlueprintProtocol.Deployment.Observations{}}, do: match?({:ok, %AgentBlueprintProtocol.Evidence{}}, AgentBlueprintProtocol.reconcile(blueprint, deployment, inputs))
    true

# `verify_compatibility`
*since 1.0.0* 

```elixir
@spec verify_compatibility(
  AgentBlueprintProtocol.Deployment.t(),
  AgentBlueprintProtocol.Compatibility.Observed.t()
) :: {:ok, AgentBlueprintProtocol.Evidence.t()} | failure()
```

Compares manifest identities with identities reported by a host.

## Example

    iex> match?({:error, %AgentBlueprintProtocol.Error{code: :invalid_type}}, AgentBlueprintProtocol.verify_compatibility(:invalid, :invalid))
    true

---

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