lumoCmd

package
v0.0.0-...-9bcff37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package lumoCmd implements the lumo subcommands for proton-cli.

Index

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

func AddCommand(cmd *cobra.Command)

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

func FormatHistory(messages []lumo.Message, decrypt func(lumo.Message) string) string

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

func FormatSpaceList(rows []SpaceRow) string

FormatSpaceList renders a tab-aligned table of spaces sorted by creation time descending (newest first).

func FormatStatusBar

func FormatStatusBar(convID, model string, width int) string

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

func GenerateAPIKey(dir string) (string, error)

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

func IsEmptyInput(s string) bool

IsEmptyInput reports whether the input is empty or whitespace-only.

func LoadOrGenerateAPIKey

func LoadOrGenerateAPIKey(dir string) (string, error)

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

func LoadOrGenerateTLS(dir string) (certPath, keyPath string, err error)

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.

func ParseSlashCommand

func ParseSlashCommand(input string) (cmd string, args string, ok bool)

ParseSlashCommand parses a slash command from user input. Returns the command name, remaining args, and whether the input is a slash command. Returns ok=false for non-slash input.

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

type ConversationRow struct {
	ID         string
	Title      string
	CreateTime string
}

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

type ResolvedConversation struct {
	ConversationID string
	SpaceID        string
}

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.

type SpaceRow

type SpaceRow struct {
	ID         string
	CreateTime string
	ConvCount  int
	Encrypted  bool
	Deleted    bool
	Name       string // decrypted name, "(empty)", or "(encrypted)"
}

SpaceRow is a display-only struct for the space list table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL