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

This module decodes and validates Blueprint Core artifacts.

Use it when reading Blueprint bytes or working with a validated Blueprint value.

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.Blueprint.decode(bytes))
```

# `reason`
*since 1.0.0* 

```elixir
@type reason() :: AgentBlueprintProtocol.Error.t()
```

A typed error returned by AgentBlueprintProtocol.Blueprint.

# `t`
*since 1.0.0* 

```elixir
@type t() :: %AgentBlueprintProtocol.Blueprint{
  value: AgentBlueprintProtocol.Json.value()
}
```

The public data type for AgentBlueprintProtocol.Blueprint.

# `canonical_bytes`
*since 1.0.0* 

```elixir
@spec canonical_bytes(t()) ::
  {:ok, binary()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Returns canonical JSON bytes for the supplied artifact.

## Example

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

match?(
  {:ok, bytes} when is_binary(bytes),
  AgentBlueprintProtocol.Blueprint.canonical_bytes(blueprint)
)
```

# `content_digest`
*since 1.0.0* 

```elixir
@spec content_digest(t()) ::
  AgentBlueprintProtocol.Digest.t() | {:error, AgentBlueprintProtocol.Error.t()}
```

Computes the content digest for the artifact.

## Example

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

match?(
  %AgentBlueprintProtocol.Digest{},
  AgentBlueprintProtocol.Blueprint.content_digest(blueprint)
)
```

# `decode`
*since 1.0.0* 

```elixir
@spec decode(binary(), AgentBlueprintProtocol.Bounds.t() | map()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Decodes canonical JSON bytes and validates the Blueprint contents and digest.

## Example

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

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

# `digest_covered?`
*since 1.0.0* 

```elixir
@spec digest_covered?(binary()) :: boolean()
```

Reports whether the named artifact member contributes to its content digest.

## Example

```elixir
AgentBlueprintProtocol.Blueprint.digest_covered?("model_policy")
```

# `digest_input`
*since 1.0.0* 

```elixir
@spec digest_input(t()) ::
  AgentBlueprintProtocol.Json.value()
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Returns the tagged value used to compute the artifact digest.

## Example

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

match?({:object, _}, AgentBlueprintProtocol.Blueprint.digest_input(blueprint))
```

# `from_value`
*since 1.0.0* 

```elixir
@spec from_value(AgentBlueprintProtocol.Json.value(), map()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Validates the tagged value's structure and portability and constructs a draft artifact.
This function does not compare the declared digest with recomputed content and does
not verify signatures. Producers must compute and insert `content_digest`, encode
canonical bytes, and decode those bytes to check the completed artifact.

## Options

`:authored_extensions` defaults to `[]`. It is a list of critical namespace strings
whose bodies have already passed negotiation's schema validation for this same
value. It changes portability scanning of those bodies; it does not validate a
schema or establish content classification. Never infer this list from names alone.
Host consumers should use `AgentBlueprintProtocol.reconcile/3`, which derives it.

After successful negotiation of `value` with the host's `support` (an excerpt):

```elixir
{:ok, outcome} = AgentBlueprintProtocol.negotiate(value, support)
{:ok, draft} = AgentBlueprintProtocol.Blueprint.from_value(value, %{
  authored_extensions: outcome.critical_extensions
})
```

## Example

```elixir
{:ok, value} =
  AgentBlueprintProtocol.Json.decode(
    File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))
  )

match?(
  {:ok, %AgentBlueprintProtocol.Blueprint{}},
  AgentBlueprintProtocol.Blueprint.from_value(value)
)
```

```elixir
{:ok, value} =
  AgentBlueprintProtocol.Json.decode(
    File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))
  )

match?(
  {:ok, %AgentBlueprintProtocol.Blueprint{}},
  AgentBlueprintProtocol.Blueprint.from_value(value, %{authored_extensions: []})
)
```

# `members`
*since 1.1.0* 

```elixir
@spec members(integer()) ::
  {:ok, [binary()]} | {:error, AgentBlueprintProtocol.Error.t()}
```

  Returns the sorted Blueprint Core member names for a supported protocol revision.

  Hosts that support every core field of a revision declare the union of
  `AgentBlueprintProtocol.Blueprint.members/1` and
  `AgentBlueprintProtocol.Deployment.members/1` in
  `AgentBlueprintProtocol.Negotiation.Support.core_fields`.

  Revision 1 is supported. Other integers return `:protocol_revision_unsupported`
  with subject `["protocol_revision"]`; non-integers return `:invalid_type`.

  ## Example

      iex> with {:ok, names} <- AgentBlueprintProtocol.Blueprint.members(1), do: length(names)
      18

# `to_value`
*since 1.0.0* 

```elixir
@spec to_value(t()) ::
  AgentBlueprintProtocol.Json.value()
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Returns the tagged JSON value held by this artifact.

## Example

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

match?({:object, _}, AgentBlueprintProtocol.Blueprint.to_value(blueprint))
```

# `verify_content_digest`
*since 1.0.0* 

```elixir
@spec verify_content_digest(t()) :: :ok | {:error, AgentBlueprintProtocol.Error.t()}
```

Checks the declared artifact digest against its covered content.

## Example

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

AgentBlueprintProtocol.Blueprint.verify_content_digest(blueprint)
```

---

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