# `Jidoka.AgentView`
[🔗](https://github.com/agentjido/jidoka/blob/v0.9.0/lib/jidoka/agent_view.ex#L1)

Surface-neutral UI projection contract for a Jidoka agent.

`AgentView` is not a Phoenix view and does not render HTML. It is a small
application-facing projection that LiveView, CLI examples, channels, tests, or
jobs can use to keep UI state separate from the durable agent runtime.

The struct is projection-only. It stores no pid, transcript persistence,
provider client, process state, or adapter data.

# `input`

```elixir
@type input() :: term()
```

# `status`

```elixir
@type status() :: :idle | :running | :error | :interrupted | :handoff
```

# `t`

```elixir
@type t() :: %Jidoka.AgentView{
  agent_id: binary(),
  conversation_id: binary(),
  error: nil | nil | any(),
  error_text: nil | nil | binary(),
  events: [map()],
  metadata: map(),
  outcome: nil | nil | any(),
  runtime_context: map(),
  status: (((:idle | :running) | :error) | :interrupted) | :handoff,
  streaming_message: nil | nil | map(),
  visible_messages: [map()]
}
```

# `agent_id`

```elixir
@callback agent_id(input()) :: String.t()
```

Returns the runtime agent identifier for a view input.

# `agent_module`

```elixir
@callback agent_module(input()) :: module() | Jidoka.Agent.Spec.t() | Jidoka.Turn.Plan.t()
```

Returns the agent module, specification, or plan for a view input.

# `conversation_id`

```elixir
@callback conversation_id(input()) :: String.t()
```

Returns the durable conversation identifier for a view input.

# `prepare`

```elixir
@callback prepare(input()) :: :ok | {:error, term()}
```

Prepares external resources before the initial view is built.

# `runtime_context`

```elixir
@callback runtime_context(input()) :: map()
```

Returns application context data for turns started by the view.

# `after_turn`

```elixir
@spec after_turn(
  t(),
  {:ok, Jidoka.Turn.Result.t()}
  | {:hibernate, Jidoka.Snapshot.t()}
  | {:error, term()}
) :: t()
```

Applies a Jidoka runtime result to view data.

# `apply_event`

```elixir
@spec apply_event(t(), Jidoka.Event.t() | map()) :: t()
```

Applies a streamed Jidoka runtime event to view data.

Content deltas update `streaming_message`; non-delta events are appended to
`events` as compact debug projections.

# `before_turn`

```elixir
@spec before_turn(t(), String.t()) :: t()
```

Applies optimistic user-message state before an agent turn starts.

# `default_agent_id`

```elixir
@spec default_agent_id(term(), String.t()) :: String.t()
```

Derives a runtime agent id from an agent module and conversation id.

# `default_conversation_id`

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

Derives a conversation id from keyword, atom-key map, or string-key map input.

# `default_runtime_context`

```elixir
@spec default_runtime_context(term(), String.t()) :: map()
```

Derives default runtime context from a conversation id.

# `initial`

```elixir
@spec initial(module(), input(), keyword()) :: {:ok, t()} | {:error, term()}
```

Builds the initial projection for a view module and input.

# `lifecycle_hooks`

```elixir
@spec lifecycle_hooks() :: [atom()]
```

Returns lifecycle hook names supported by the AgentView contract.

# `new`

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

Builds an AgentView struct from attributes.

# `new!`

```elixir
@spec new!(keyword() | map()) :: t()
```

Builds an AgentView struct from attributes and raises on invalid input.

# `normalize_id`

```elixir
@spec normalize_id(term(), String.t()) :: String.t()
```

Normalizes arbitrary text into a stable lower-snake id.

# `request_id`

```elixir
@spec request_id() :: String.t()
```

Generates a request id suitable for UI-initiated turns.

# `run`

```elixir
@spec run(module(), t(), String.t(), keyword()) :: t()
```

Runs one turn for a view module and maps the runtime result back into view data.

# `schema`

```elixir
@spec schema() :: Zoi.schema()
```

Returns the Zoi schema for AgentView.

# `visible_messages`

```elixir
@spec visible_messages(t()) :: [map()]
```

Returns visible messages for a view.

---

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