# `AgentDbWeb.Context`
[🔗](https://github.com/manhvu/agent_db/blob/v0.1.0/lib/agent_db_web/context.ex#L1)

The transport's view of the store.

Everything here goes through the `AgentDb` facade. A request handler needs
presentation -- a page of results, a status summary -- and not the machinery
behind them, so this module shapes what the facade returns and stops there.
Reading the database or the model manager from here would make the HTTP
surface a second way into the store's internals, and a change to either would
become a change to the wire.

# `bulk_set_enabled`

```elixir
@spec bulk_set_enabled([String.t()], boolean()) :: {:ok, map()} | {:error, term()}
```

Bulk enable/disable over an explicit URI list.

# `bulk_set_group`

```elixir
@spec bulk_set_group([String.t()], String.t()) :: {:ok, map()} | {:error, term()}
```

Bulk group assignment over an explicit URI list.

# `cache_stats`

```elixir
@spec cache_stats() :: map()
```

The size of the store's disposable read caches.

# `delete_document`

```elixir
@spec delete_document(String.t()) :: :ok | {:error, term()}
```

Removes the subtree at `uri`.

# `error_message`

```elixir
@spec error_message(term()) :: String.t()
```

Why a store operation failed, in words and from the shared taxonomy.

# `forget_memory`

```elixir
@spec forget_memory(String.t()) :: :ok | {:error, term()}
```

Removes a memory and its provenance.

# `get_document`

```elixir
@spec get_document(String.t()) :: {:ok, String.t()} | {:error, term()}
```

A document's full content.

# `get_layers`

```elixir
@spec get_layers(String.t()) :: %{l0: map(), l1: map(), l2: map()}
```

A document's LLM-facing layers, keyed the way the console labels them.

Returns `%{l0: layer, l1: layer, l2: layer}` where each layer is
`%{text: String.t(), source: :stored | :fallback | :unavailable, chars: non_neg_integer()}`.

The store answers these layers under their own names (`abstract`, `overview`,
`content`) because that is its vocabulary; the console's L0/L1/L2 labels are
presentation, and translation at the transport edge is what that edge is for.
One call to the facade, so a layer's meaning is the same wherever it is
shown.

# `get_layers_batch`

Reads several documents' layers in one store operation.

# `get_session`

```elixir
@spec get_session(String.t()) :: {:ok, [map()]} | {:error, term()}
```

A session's messages.

# `health_check`

```elixir
@spec health_check() :: %{
  status: String.t(),
  checks: %{db: boolean(), models: boolean()}
}
```

Whether the store is usable, per check.

A 200 or a 503 rather than an error: a store serving without a model is
serving, and a monitor should be able to see which part is down.

# `import_skills`

```elixir
@spec import_skills(String.t(), AgentDb.Skills.Source.source()) ::
  {:ok, map()} | {:error, term()}
```

Imports Agent Skills into a user's skills subtree. See `AgentDb.import_skills/2`.

# `index_coverage`

```elixir
@spec index_coverage() :: map()
```

How much of the store's content each index covers.

# `job_stats`

```elixir
@spec job_stats() :: map()
```

How much background work is outstanding, by status.

# `list_all_documents`

```elixir
@spec list_all_documents(map() | keyword()) :: {:ok, map()} | {:error, term()}
```

Recursive paged document URIs under `scope` for operations listings.

# `list_documents`

```elixir
@spec list_documents(map() | keyword()) :: {:ok, map()} | {:error, term()}
```

A page of the document names under `prefix`.

# `list_skills`

```elixir
@spec list_skills(map() | keyword()) :: {:ok, map()} | {:error, term()}
```

Paged installed-skill inventory across users.

# `memory_statistics`

```elixir
@spec memory_statistics() :: {:ok, map()} | {:error, term()}
```

Memory statistics: counts per type and status, pending, never surfaced.

# `model_status`

```elixir
@spec model_status() :: map()
```

How the store's models are doing, including a load in progress.

# `operation_stats`

```elixir
@spec operation_stats() :: map()
```

Operation, job, and model counts by outcome.

# `pending_memory_candidates`

```elixir
@spec pending_memory_candidates(keyword()) :: {:ok, [map()]} | {:error, term()}
```

Memories waiting for review.

# `promote_memory`

```elixir
@spec promote_memory(String.t()) :: {:ok, String.t()} | {:error, term()}
```

Promotes a waiting memory candidate.

# `put_document`

```elixir
@spec put_document(String.t(), String.t(), keyword()) :: :ok | {:error, term()}
```

Writes a document, creating it or replacing it.

# `queue_detail`

```elixir
@spec queue_detail(pos_integer()) :: map()
```

How far behind the queue is, and which jobs are failing.

# `recent_errors`

```elixir
@spec recent_errors(pos_integer()) :: [map()]
```

Recent operational failures, newest first.

# `reject_memory_candidate`

```elixir
@spec reject_memory_candidate(String.t()) :: :ok | {:error, term()}
```

Rejects a waiting memory candidate.

# `role`

```elixir
@spec role(String.t()) :: :user | :assistant | :system | :unknown
```

Maps a wire role to the atom the store writes, or `:unknown`.

# `runtime_snapshot`

```elixir
@spec runtime_snapshot() :: map()
```

A bounded, read-only view of the BEAM runtime.

# `search_documents`

```elixir
@spec search_documents(String.t(), map() | keyword()) ::
  {:ok, [map()]} | {:error, term()}
```

Searches the store. See `AgentDb.search/2` for the options.

# `set_enabled`

```elixir
@spec set_enabled(String.t(), boolean()) :: :ok | {:error, term()}
```

Enables or disables the subtree at `uri`.

# `set_group`

```elixir
@spec set_group(String.t(), String.t()) :: :ok | {:error, term()}
```

Assigns the operator group tag for the subtree at `uri`. Empty clears.

# `skill_import_error`

```elixir
@spec skill_import_error(term()) :: String.t()
```

Why a skill import was refused, in words.

# `storage_stats`

```elixir
@spec storage_stats() :: map()
```

What the store holds and how much room it takes on disk.

# `transport_error`

```elixir
@spec transport_error(Plug.Conn.t(), term()) :: Plug.Conn.t()
```

Renders a store error on a controller connection.

---

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