AgentDbWeb.Context (agent_db v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Bulk enable/disable over an explicit URI list.

Bulk group assignment over an explicit URI list.

The size of the store's disposable read caches.

Removes the subtree at uri.

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

Removes a memory and its provenance.

A document's full content.

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

Reads several documents' layers in one store operation.

A session's messages.

Whether the store is usable, per check.

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

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

How much background work is outstanding, by status.

Recursive paged document URIs under scope for operations listings.

A page of the document names under prefix.

Paged installed-skill inventory across users.

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

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

Operation, job, and model counts by outcome.

Memories waiting for review.

Promotes a waiting memory candidate.

Writes a document, creating it or replacing it.

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

Recent operational failures, newest first.

Rejects a waiting memory candidate.

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

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

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

Enables or disables the subtree at uri.

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

Why a skill import was refused, in words.

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

Renders a store error on a controller connection.

Functions

bulk_set_enabled(uris, enabled)

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

Bulk enable/disable over an explicit URI list.

bulk_set_group(uris, tag)

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

Bulk group assignment over an explicit URI list.

cache_stats()

@spec cache_stats() :: map()

The size of the store's disposable read caches.

delete_document(uri)

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

Removes the subtree at uri.

error_message(reason)

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

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

forget_memory(uri)

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

Removes a memory and its provenance.

get_document(uri)

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

A document's full content.

get_layers(uri)

@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(uris)

Reads several documents' layers in one store operation.

get_session(id)

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

A session's messages.

health_check()

@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(user_id, source)

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

@spec index_coverage() :: map()

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

job_stats()

@spec job_stats() :: map()

How much background work is outstanding, by status.

list_all_documents(opts \\ [])

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

Recursive paged document URIs under scope for operations listings.

list_documents(opts \\ [])

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

A page of the document names under prefix.

list_skills(opts \\ [])

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

Paged installed-skill inventory across users.

memory_statistics()

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

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

model_status()

@spec model_status() :: map()

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

operation_stats()

@spec operation_stats() :: map()

Operation, job, and model counts by outcome.

pending_memory_candidates(opts \\ [])

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

Memories waiting for review.

promote_memory(uri)

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

Promotes a waiting memory candidate.

put_document(uri, content, opts \\ [])

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

Writes a document, creating it or replacing it.

queue_detail(limit \\ 20)

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

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

recent_errors(limit \\ 20)

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

Recent operational failures, newest first.

reject_memory_candidate(uri)

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

Rejects a waiting memory candidate.

role(arg1)

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

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

runtime_snapshot()

@spec runtime_snapshot() :: map()

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

search_documents(term, opts \\ [])

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

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

set_enabled(uri, enabled)

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

Enables or disables the subtree at uri.

set_group(uri, tag)

@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(reason)

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

Why a skill import was refused, in words.

storage_stats()

@spec storage_stats() :: map()

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

transport_error(conn, reason)

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

Renders a store error on a controller connection.