# `Wardrik.Scope`

Who is acting through Wardrik, and what they may do.

    scope = MyApp.AgentRuntime.as("acme/@maria", roles: [:owner], resources: ["acme/@maria/*"])

`Wardrik.as/3` makes a scope. `Wardrik.grant/2` adds to it.

## Fields

  * `:server` - the `Wardrik.Server` that runs its operations.
  * `:wardrik` - which Wardrik, by name.
  * `:principal` - who is acting.
  * `:grants` - what the authorizer reads to decide what they may do.
  * `:policy` - in a token's scope, the policy every agent it defines is held to.
  * `:expires` - in a token's scope, when the token expires.
  * `:labels` - in an agent's scope, the labels of what its run has read. Messages it sends
    carry them too.
  * `:operation` - the operation running, while one runs.

# `t`

```elixir
@type t() :: %Wardrik.Scope{
  expires: DateTime.t() | nil,
  grants: term(),
  labels: [String.t()],
  operation: WardrikProtocol.operation() | nil,
  policy: String.t() | map() | nil,
  principal: WardrikCore.Principal.t(),
  server: module(),
  wardrik: atom() | struct()
}
```

# `grant`

```elixir
@spec grant(t(), keyword()) :: t()
```

Adds a statement built from `opts` to the scope's grants. See `Wardrik.Statement.new/1`.

# `new`

```elixir
@spec new(module(), atom(), WardrikCore.Principal.t() | String.t(), term()) :: t()
```

Returns a scope for `principal` on `wardrik`, run by `server`.

`grants` is a list of `Wardrik.Statement`s, or the options for one.

# `run`

```elixir
@spec run(t(), String.t(), map()) :: {:ok, term()} | {:error, Wardrik.Error.t()}
```

Runs operation `id` with `input` through the scope's server.

# `stream`

```elixir
@spec stream(t(), String.t(), map()) ::
  {:ok, Enumerable.t()} | {:error, Wardrik.Error.t()}
```

Streams operation `id` with `input` through the scope's server.

---

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