# `H.Transcript`
[🔗](https://github.com/parlant/harness/blob/v0.3.0/lib/h/transcript.ex#L1)

Pure Elixir reducer for conversation transcript SSE/PubSub frames.
Applies document deltas with `H.Document.apply_ops/2`.

# `t`

```elixir
@type t() :: %H.Transcript{
  before_entry_id: String.t() | nil,
  committed_docs: map(),
  conversation_id: String.t() | nil,
  docs: map(),
  entries: [map()],
  entry_ids: MapSet.t(String.t()),
  has_more: boolean(),
  seq: non_neg_integer() | nil,
  session_id: String.t() | nil
}
```

# `apply_commit`

```elixir
@spec apply_commit(t(), map() | binary()) ::
  {:ok, t(), %{appended_entries: [map()]}}
  | {:gap, t()}
  | {:stale, t()}
  | {:error, term()}
```

Applies a `commit` payload (decoded map or JSON binary).

Returns:
  * `{:gap, t}` when `t.seq` is `nil` or `frame_seq > t.seq + 1` (caller should resnapshot)
  * `{:stale, t}` when `frame_seq <= t.seq`
  * `{:ok, updated, %{appended_entries: new_entries}}` when `frame_seq == t.seq + 1`

# `apply_ephemeral`

```elixir
@spec apply_ephemeral(t(), map() | binary()) ::
  {:ok, t()} | :ignored | {:error, term()}
```

Applies an `ephemeral` payload (decoded map or JSON binary) to `docs["live"]`
without advancing `seq` or mutating `committed_docs`.

Returns `:ignored` when `t.seq == nil` or `base_seq != t.seq`.

# `apply_snapshot`

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

Applies a `snapshot` payload (decoded map or JSON binary).

Sets `seq`, deduplicates and orders `entries`, updates `before_entry_id` and
`has_more`, and resets both `committed_docs` and `docs`.

# `new`

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

Creates a new empty `H.Transcript` reducer state.

# `prepend_older_page`

```elixir
@spec prepend_older_page(t(), [map()], String.t() | integer() | nil) :: t()
```

Prepends an older page of entries in ascending order without duplicates and
updates `before_entry_id` and `has_more`.

---

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