Module: Kward::MessageText

Defined in:
lib/kward/message_text.rb

Overview

Builds user-visible plain text from persisted conversation messages.

Conversations may store one value for the model and another value for the UI. Prompt templates, for example, keep expanded instructions in content while preserving the submitted slash command in display_content. This helper keeps tree navigation, forks, copy/export features, and RPC payloads aligned on the same visible text rules.

Class Method Summary collapse

Class Method Details

.content_text(content) ⇒ String

Converts message content into plain text without applying display-content overrides.

Parameters:

  • content (String, Array<Hash>, nil)

    message content field

Returns:

  • (String)

    textual content joined with newlines



36
37
38
39
40
41
42
43
# File 'lib/kward/message_text.rb', line 36

def content_text(content)
  case content
  when Array
    content.filter_map { |part| MessageAccess.value(part, :text) }.join("\n")
  else
    content.to_s
  end
end

.full_text(message) ⇒ String

Returns the plain text a user should see or edit for a message.

User messages prefer display_content/displayContent when present. Other messages, and user messages without display text, are reduced from their stored content. Array content contributes only textual parts so image and tool-call blocks do not leak implementation details into editable text.

Parameters:

  • message (Hash)

    persisted conversation message

Returns:

  • (String)

    stripped visible text



24
25
26
27
28
29
# File 'lib/kward/message_text.rb', line 24

def full_text(message)
  display_content = MessageAccess.display_content(message)
  return display_content.to_s.strip unless display_content.nil?

  content_text(MessageAccess.content(message)).strip
end