Documentation
¶
Overview ¶
Package lumoCmd implements the lumo subcommands for proton-cli.
Index ¶
- func AccumulateResponse(content, id, model string) lumo.ChatCompletionResponse
- func AddCommand(cmd *cobra.Command)
- func ChunkToSSEEvent(msg lumo.GenerationResponseMessage, id, model string) (lumo.ChatCompletionChunk, bool)
- func FilterActiveConversations(convs []lumo.Conversation) []lumo.Conversation
- func FormatConversationList(rows []ConversationRow) string
- func FormatHistory(messages []lumo.Message, decrypt func(lumo.Message) string) string
- func FormatLog(messages []lumo.Message, opts LogFormatOptions, ...) (string, int)
- func FormatSpaceList(rows []SpaceRow) string
- func FormatStatusBar(convID, model string, width int) string
- func GenerateAPIKey(dir string) (string, error)
- func HelpText() string
- func IsEmptyInput(s string) bool
- func LoadOrGenerateAPIKey(dir string) (string, error)
- func LoadOrGenerateTLS(dir string) (certPath, keyPath string, err error)
- func MessagesToTurns(msgs []lumo.OAIMessage) []lumo.Turn
- func ParseSlashCommand(input string) (cmd string, args string, ok bool)
- type ChatSession
- type ConversationRow
- type LogFormatOptions
- type ResolvedConversation
- type SlashCommand
- type SpaceRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccumulateResponse ¶
func AccumulateResponse(content, id, model string) lumo.ChatCompletionResponse
AccumulateResponse builds a complete ChatCompletionResponse from collected content after all chunks have been received.
func AddCommand ¶
AddCommand registers a subcommand under the lumo command group.
func ChunkToSSEEvent ¶
func ChunkToSSEEvent(msg lumo.GenerationResponseMessage, id, model string) (lumo.ChatCompletionChunk, bool)
ChunkToSSEEvent converts a Lumo response message to an OpenAI streaming chunk. Returns the chunk and whether the message produced output (token_data with non-empty content).
func FilterActiveConversations ¶
func FilterActiveConversations(convs []lumo.Conversation) []lumo.Conversation
FilterActiveConversations returns only conversations with an empty DeleteTime (i.e., not soft-deleted).
func FormatConversationList ¶
func FormatConversationList(rows []ConversationRow) string
FormatConversationList renders a tab-aligned table of conversations. Rows are sorted by creation time descending (newest first). Empty titles are replaced with "Untitled".
func FormatHistory ¶
FormatHistory renders prior messages for chat resume. Each message is prefixed with a role label (You: / Lumo:). The decrypt callback decrypts each message's content on demand — the formatter never sees keys.
func FormatLog ¶
func FormatLog(messages []lumo.Message, opts LogFormatOptions, decrypt func(lumo.Message) (string, bool)) (string, int)
FormatLog renders messages as a readable log. Each message is separated by a blank line. The decrypt callback returns the plaintext content and a success flag; when ok is false, FormatLog renders "[message decryption failed]" as the content.
Returns the formatted string and the count of decryption failures.
func FormatSpaceList ¶
FormatSpaceList renders a tab-aligned table of spaces sorted by creation time descending (newest first).
func FormatStatusBar ¶
FormatStatusBar renders a status bar line:
── conv:<truncID> | model:<model> ──
The conversation ID is truncated to 8 characters. The result is padded with horizontal-rule characters to fill the given width.
func GenerateAPIKey ¶
GenerateAPIKey generates a new random API key and persists it, replacing any existing key. Returns the hex-encoded key (64 chars).
func HelpText ¶
func HelpText() string
HelpText returns the help message for available slash commands.
func IsEmptyInput ¶
IsEmptyInput reports whether the input is empty or whitespace-only.
func LoadOrGenerateAPIKey ¶
LoadOrGenerateAPIKey reads the persisted key from dir. If none exists, generates a new 32-byte random token (hex-encoded, 64 chars), persists it with mode 0600, and returns it.
func LoadOrGenerateTLS ¶
LoadOrGenerateTLS returns cert and key file paths. If the files exist at <dir>/tls/, returns those paths. Otherwise generates a self-signed ECDSA P-256 cert with SANs [localhost, 127.0.0.1], valid for 10 years, and persists it.
func MessagesToTurns ¶
func MessagesToTurns(msgs []lumo.OAIMessage) []lumo.Turn
MessagesToTurns converts OpenAI messages to Lumo turns. Role mapping: system→RoleSystem, user→RoleUser, assistant→RoleAssistant. Unknown roles default to RoleUser.
Types ¶
type ChatSession ¶
type ChatSession struct {
Client *lumo.Client
Space *lumo.Space
Conversation *lumo.Conversation
SpaceID string
Turns []lumo.Turn
Writer io.Writer
Reader io.Reader
WebSearchEnabled bool
}
ChatSession holds the state for a single interactive chat session.
func (*ChatSession) Run ¶
func (s *ChatSession) Run(ctx context.Context) error
Run executes the interactive chat loop. It reads lines from Reader, persists messages, calls Generate, and streams responses to Writer.
The loop exits on EOF, /exit, or context cancellation. Ctrl+C during generation cancels only the current request — the loop continues. Generation and persistence errors are non-fatal.
type ConversationRow ¶
ConversationRow is a display-only struct for the conversation list table. Title is decrypted on demand and discarded after rendering.
type LogFormatOptions ¶
type LogFormatOptions struct {
Timestamps bool // prefix each message with formatted CreateTime
Color bool // emit ANSI color codes on sender names
}
LogFormatOptions controls FormatLog output.
type ResolvedConversation ¶
ResolvedConversation holds the result of conversation resolution.
type SlashCommand ¶
type SlashCommand int
SlashCommand identifies a recognized slash command.
const ( // CmdNone indicates the input is not a slash command. CmdNone SlashCommand = iota // CmdExit indicates the /exit command. CmdExit // CmdHelp indicates the /help command. CmdHelp // CmdWebSearch indicates the /websearch command. CmdWebSearch // CmdUnknown indicates an unrecognized slash command. CmdUnknown )
func ClassifyCommand ¶
func ClassifyCommand(cmd string) SlashCommand
ClassifyCommand maps a parsed command name to a SlashCommand constant.