AgentBlueprintProtocol.Blueprint (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

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

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

Summary

Types

A typed error returned by AgentBlueprintProtocol.Blueprint.

t()

The public data type for AgentBlueprintProtocol.Blueprint.

Functions

Returns canonical JSON bytes for the supplied artifact.

Computes the content digest for the artifact.

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

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

Returns the tagged value used to compute the artifact digest.

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.

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

Returns the tagged JSON value held by this artifact.

Checks the declared artifact digest against its covered content.

Types

reason()

(since 1.0.0)
@type reason() :: AgentBlueprintProtocol.Error.t()

A typed error returned by AgentBlueprintProtocol.Blueprint.

t()

(since 1.0.0)
@type t() :: %AgentBlueprintProtocol.Blueprint{
  value: AgentBlueprintProtocol.Json.value()
}

The public data type for AgentBlueprintProtocol.Blueprint.

Functions

canonical_bytes(arg1)

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

Returns canonical JSON bytes for the supplied artifact.

Example

{: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(blueprint)

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

Computes the content digest for the artifact.

Example

{: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(binary, bounds \\ Bounds.maximum())

(since 1.0.0)
@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

match?(
  {:ok, %AgentBlueprintProtocol.Blueprint{}},
  AgentBlueprintProtocol.Blueprint.decode(
    File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))
  )
)
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?(member_name)

(since 1.0.0)
@spec digest_covered?(binary()) :: boolean()

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

Example

AgentBlueprintProtocol.Blueprint.digest_covered?("model_policy")

digest_input(arg1)

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

Returns the tagged value used to compute the artifact digest.

Example

{: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(value, opts \\ %{})

(since 1.0.0)
@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):

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

Example

{: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)
)
{: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(revision)

(since 1.1.0)
@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(arg1)

(since 1.0.0)

Returns the tagged JSON value held by this artifact.

Example

{: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(blueprint)

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

Checks the declared artifact digest against its covered content.

Example

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

AgentBlueprintProtocol.Blueprint.verify_content_digest(blueprint)