# `OpenUI.Message`
[🔗](https://github.com/ideia4it/openui/blob/v0.1.1/lib/openui/message.ex#L1)

The protocol a host stores responses with (prompt.md, section 7): the
program wrapped in `]]>openui:content`, `]]>openui:context` and
`]]>openui:end` marker lines. The model never writes or sees these lines.

    raw = OpenUI.Message.build(content: program, context: [state], end: true)
    %OpenUI.Message{content: program} = OpenUI.Message.parse(raw)

When a response was regenerated, the last `content` wins.

# `t`

```elixir
@type t() :: %OpenUI.Message{
  attributes: %{required(String.t()) =&gt; String.t()},
  content: String.t(),
  context: term(),
  end?: boolean()
}
```

# `build`

```elixir
@spec build(keyword()) :: String.t()
```

Writes a stored message. `context` is written as is when it is a string,
else as JSON, and is left out when `nil`. `attributes` are key-value pairs,
such as `[{"library", "support@1.2.0"}]`.

# `from_event`

```elixir
@spec from_event(OpenUI.Event.t()) :: String.t()
```

The stored turn for an action that continues the conversation, in the
reference format: the message, and as context
`["User clicked: <message>", formState, context]` (the context only when
the action has one).

# `model_text`

```elixir
@spec model_text(String.t(), :assistant | :user) :: String.t()
```

What the model reads of a stored message, with every marker line removed:
the program for an assistant turn; for a user turn, the message and, when
there is a context, `context and form values = <its JSON>`.

# `parse`

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

Reads a stored message. With `streaming: true`, a last line that may be a
marker cut mid-stream is held back.

---

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