The assistant ("Assistente (IA)"): the conversation, its messages, the proposals the user approves, the queries the assistant shows it made, the field to ask, the list of conversations and the starting suggestions. The assistant proposes and the user approves; nothing changes without a confirmation.
<.ai_chat id="assistente" messages={@messages} user={@current_user}
on_send="send" on_approve="approve" on_reject="reject" />Or piece by piece (ai_message/1, ai_proposal/1, ai_tool_trace/1, ai_composer/1,
conversation_list/1, prompt_suggestions/1, ai_insights/1, ai_promo/1, ai_greeting/1).
A message of ai_chat is a map: :id, :role (:user or :assistant), :text (paragraphs
separated by a blank line, **bold** is bold), :name (of the user, for the avatar), :trace
(%{tools: [...], duration_ms: 3000, running: false}), :proposal (%{id:, title:, status:, changes: [%{label:, from:, to:, text:}], note:, editable:}), :streaming and :status.
messages can be a list or a LiveView stream (stream(socket, :messages, ...)).
The composer is a form: Enter sends, Shift+Enter breaks the line (hook LedgerUI.AiComposer,
file priv/static/ledger_ui/hooks/ai_composer.js).
Summary
Functions
The whole conversation: greeting and suggestions, the messages and the field to ask.
The field to ask the assistant: context chips, text, attachment and send (a form).
The greeting of the assistant: the first line in a gradient and the question under it.
Card of AI insights: icon, title, sentence with bold numbers, impact badge and action.
A message of the conversation.
Call to the assistant pinned on the sidebar, with insight count and main action.
An action the assistant proposes, which only happens when the user approves.
What the assistant consulted: summary (count and time) and one row per query.
The conversations of the assistant, by day, with a button for a new one and a search.
The starting suggestions: cards, pills or a grey grid.
Functions
The whole conversation: greeting and suggestions, the messages and the field to ask.
Attributes
id(:string) (required)messages(:any) - A list of message maps or a stream of them. Defaults to[].user(:any) - Defaults tonil.streaming(:boolean) - Defaults tofalse.context(:list) - Defaults to[].mention(:boolean) - Defaults tofalse.mention_label(:string) - Defaults to"Mencionar".variant(:string) - Defaults to"card". Must be one of"card","bare", or"page".draft(:string) - Defaults tonil.greeting(:string) - Defaults tonil.start(:boolean) - Shows the greeting and suggestions (or:empty) while a list has no messages. Defaults totrue.footnote(:string) - Defaults tonil.composer(:boolean) - Defaults totrue.placeholder(:string) - Defaults to"Pergunte sobre pedidos, estoque, fiscal ou financeiro".on_send(:any) - Defaults tonil.on_change(:any) - Defaults tonil.on_stop(:any) - Defaults tonil.on_approve(:any) - Defaults tonil.on_reject(:any) - Defaults tonil.on_undo(:any) - Defaults tonil.on_pick(:any) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block- Extra content after the messages.empty- Shown above the messages in place of the greeting and suggestions.header- The title and subtitle of the conversation, in the header of thecard.suggestion- A starting card; the content is its text. Accepts attributes:title(:string)prompt(:string)
The field to ask the assistant: context chips, text, attachment and send (a form).
Attributes
id(:string) - Needed for Enter-to-send (the hook needs a stable id). Defaults tonil.variant(:string) - Defaults to"default". Must be one of"default", or"canvas".send_label(:string) - Defaults to"Enviar".mic(:boolean) - Defaults tofalse.on_mic(:any) - Defaults tonil.mention(:boolean) - Shows the mention (@) button. Defaults tofalse.on_mention(:any) - Defaults tonil.mention_label(:string) - Defaults to"Mencionar".field(Phoenix.HTML.FormField) - Defaults tonil.name(:string) - Defaults tonil.value(:string) - Defaults tonil.context(:list) - Defaults to[].attachments(:list) - Defaults to[].upload(:any) - Defaults tonil.streaming(:boolean) - Defaults tofalse.on_stop(:any) - Defaults tonil.target(:any) - Defaults tonil.placeholder(:string) - Defaults to"Pergunte sobre pedidos, estoque, fiscal ou financeiro".class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["autocomplete", "phx-submit", "phx-change", "phx-target"].
Slots
chip- A custom chip, after the context ones.
The greeting of the assistant: the first line in a gradient and the question under it.
Attributes
name(:string) - Who is greeted;Bom dia/Boa tarde/Boa noiteby the hour. Defaults tonil.greeting(:string) - Replaces the whole first line. Defaults tonil.tagline(:string) - Defaults to"Em que posso ajudar hoje?".size(:string) - Defaults to"lg". Must be one of"sm","md", or"lg".tone(:string) - Defaults to"brand". Must be one of"brand", or"warm".class(:any) - Defaults tonil.- Global attributes are accepted.
Card of AI insights: icon, title, sentence with bold numbers, impact badge and action.
Attributes
insights(:list) (required) - Maps%{icon, title, text, impact, tone, action, href, navigate, patch, style};**bold**intextis bold.variant(:string) -cardhas the header;listis the items only. Defaults to"card". Must be one of"card", or"list".title(:string) - Defaults to"AI insights".count(:integer) - Number of new insights, as a badge in the header. Defaults tonil.count_label(:string) - Defaults to"new".on_chat(:any) - Shows the chat button in the header; an event name or aJScommand. Defaults tonil.chat_label(:string) - Defaults to"Abrir chat".target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
A message of the conversation.
Attributes
role(:string) - Defaults to"assistant". Must be one of"user", or"assistant".variant(:string) -cardframes the assistant's content;plainis loose text beside the spark. Defaults to"card". Must be one of"card", or"plain".streaming(:boolean) - Shows the blinking cursor (lu-stream-cursor) after the last paragraph. Defaults tofalse.status(:string) - Defaults to"ok". Must be one of"ok", or"error".name(:string) - The user's name: its initials make the avatar. Defaults tonil.actions(:list) - Buttons under the content:copy,useful,useless,regenerate. Defaults to[].on_action(:any) - Event name (payload%{action}) orJScommand. Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)trace- The queries the assistant made, above the content.
Call to the assistant pinned on the sidebar, with insight count and main action.
Attributes
title(:string) - Defaults to"Assistente".count(:integer) - Number of new suggestions/insights. Defaults tonil.subtitle(:string) - Replaces the default "N novas sugestões". Defaults tonil.text(:string) - A sentence under the title (card variant). Defaults tonil.action(:string) - Label of the main action button (card variant). Defaults tonil.variant(:string) - Defaults to"card". Must be one of"card", or"rail".tone(:string) - Defaults to"brand". Must be one of"brand", or"warm".on_click(:any) - Event name orJScommand of the call (the action forcard). Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
An action the assistant proposes, which only happens when the user approves.
Attributes
id(:string) (required)title(:string) (required) - What will be done.heading(:string) - Title of the card header. Defaults to"Proposta".status(:any) -pending,applying,approved,rejectedorfailed, as an atom or a string. Defaults to"pending".pending_label(:string) - Defaults to"Aguardando você".pending_note(:string) - Defaults tonil.layout(:string) - Defaults to"list". Must be one of"list","definition", or"table".headers(:list) - Column headers of thetablelayout. Defaults to["Regra", "Atual", "Proposto"].editable(:boolean) - Defaults tofalse.note(:string) - Defaults tonil.on_approve(:any) - Defaults tonil.on_reject(:any) - Defaults tonil.on_undo(:any) - Defaults tonil.on_edit(:any) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
action- A button in the footer of a failed proposal.change- A row of the proposal. Accepts attributes:label(:string)from(:string)to(:string)
impact- The effect in numbers. Accepts attributes:label(:string)
preview- A preview of the message or document. Accepts attributes:label(:string)
What the assistant consulted: summary (count and time) and one row per query.
Attributes
tools(:list) - Maps%{label, title, detail, ms, icon, failed, running}. Defaults to[].steps(:list) - The same astools. Defaults to[].running(:boolean) - The queries are still going on. Defaults tofalse.expanded(:boolean) - Opens the list of queries. Defaults tofalse.duration_ms(:integer) - The total time, shown in seconds. Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
The conversations of the assistant, by day, with a button for a new one and a search.
Attributes
conversations(:list) (required) - Maps%{id, title, status, day, pending, content, href, navigate, patch}.active(:any) - Theidof the open conversation. Defaults tonil.current(:any) - The same asactive. Defaults tonil.search(:string) - Defaults to"".group_by(:atom) - Defaults to:day. Must be one of:day.variant(:string) - Defaults to"card". Must be one of"card", or"rail".title(:string) - Defaults to"Assistente".shortcut(:string) - Defaults to"⌘ J".new_label(:string) - Defaults to"Nova conversa".on_new(:any) - Defaults tonil.on_search(:any) - Defaults tonil.on_select(:any) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
item- The content of an item, in place of the title and status. Accepts attributes:conversation(:map)
The starting suggestions: cards, pills or a grey grid.
Attributes
items(:list) (required) - Maps%{title, text, icon, tone, delay}; a pill shows thetext.tilt(:boolean) - Tilts the cards (decorative). Defaults totrue.variant(:string) - Defaults to"card". Must be one of"card","pill", or"grid".on_pick(:any) - Event name (payload%{value, title}) orJScommand. Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.