chat

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MsgNFANote = &i18n.Message{
		ID:    "ui.chat.NFANote",
		Other: "NOTE: Any output should not be construed as financial advice.",
	}

	MsgCmdDescModel = &i18n.Message{
		ID:    "ui.chat.CmdDescModel",
		Other: "Set the AI model for NFA",
	}
	MsgCmdDescSkills = &i18n.Message{
		ID:    "ui.chat.CmdDescSkills",
		Other: "List loaded skills",
	}
	MsgCmdDescExit = &i18n.Message{
		ID:    "ui.chat.CmdDescExit",
		Other: "Exit the NFA",
	}

	MsgSkillsCount = &i18n.Message{
		ID:    "ui.chat.SkillsCount",
		One:   "{{ .Count }} skill",
		Other: "{{ .Count }} skills",
	}

	MsgTokenUsage    = &i18n.Message{ID: "ui.chat.TokenUsage", Other: "Token Usage:"}
	MsgSkills        = &i18n.Message{ID: "ui.chat.Skills", Other: "Skills"}
	MsgBuiltinSkills = &i18n.Message{ID: "ui.chat.BuiltinSkills", Other: "Builtin skills"}
	MsgLocalSkills   = &i18n.Message{ID: "ui.chat.LocalSkills", Other: "Local skills"}
	MsgSelectModel   = &i18n.Message{ID: "ui.chat.SelectModel", Other: "Select {{ .Type }} model"}
	MsgMultilineMode = &i18n.Message{ID: "ui.chat.MultilineMode", Other: "MULTILINE MODE"}
	MsgTabToToggle   = &i18n.Message{ID: "ui.chat.TabToToggle", Other: "(tab to toggle)"}
	MsgStopReason    = &i18n.Message{ID: "ui.chat.StopReason", Other: "stop reason: {{ .Reason }}"}
	MsgToolCall      = &i18n.Message{ID: "ui.chat.ToolCall", Other: "ToolCall:"}

	MsgSetModel = &i18n.Message{ID: "ui.chat.SetModel", Other: "set {{ .Type }} model:"}

	MsgResumeSession = &i18n.Message{ID: "ui.chat.ResumeSession", Other: "Resume this session with:"}
	MsgResumeCommand = &i18n.Message{ID: "ui.chat.ResumeCommand", Other: "nfa --resume {{ .SessionID }}"}
)

Functions

This section is empty.

Types

type ACPAgent

type ACPAgent interface {
	acp.Agent
	acp.AgentLoader
}

ACPAgent ACP Agent 接口

type Chat

type Chat struct {
	acputil.NopFS
	acputil.NopTerminal
	// contains filtered or unexported fields
}

Chat 对话应用

func NewChat

func NewChat(opts Options) *Chat

NewChat 创建对话应用

func (*Chat) Init

func (chat *Chat) Init() tea.Cmd

Init 开始运行 UI 的第一个操作

func (*Chat) RequestPermission

func (chat *Chat) RequestPermission(
	_ context.Context,
	params acp.RequestPermissionRequest,
) (acp.RequestPermissionResponse, error)

RequestPermission 请求授权

func (*Chat) Run

func (chat *Chat) Run(ctx context.Context) error

Run 运行

func (*Chat) SessionUpdate

func (chat *Chat) SessionUpdate(ctx context.Context, params acp.SessionNotification) error

SessionUpdate 更新会话

func (*Chat) Update

func (chat *Chat) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update 处理更新事件

func (*Chat) View

func (chat *Chat) View() tea.View

View 渲染显示内容

type InputBox

type InputBox struct {
	// contains filtered or unexported fields
}

InputBox 输入框

func NewInputBox

func NewInputBox(ctx context.Context, commands []SelectorOption, hist *history.History, histPath string) *InputBox

NewInputBox 创建输入框

func (*InputBox) AddCommands added in v0.3.0

func (box *InputBox) AddCommands(items []SelectorOption)

AddCommands 添加命令

func (*InputBox) Blur

func (box *InputBox) Blur()

Blur 移除焦点

func (*InputBox) Focus

func (box *InputBox) Focus() tea.Cmd

Focus 获得焦点

func (*InputBox) Focused

func (box *InputBox) Focused() bool

Focused 返回是否获得焦点

func (*InputBox) MultiLineMode

func (box *InputBox) MultiLineMode() bool

MultiLineMode 返回是否处于多行编辑模式

func (*InputBox) Reset

func (box *InputBox) Reset()

Reset 重置

func (*InputBox) Update

func (box *InputBox) Update(msg tea.Msg) (*InputBox, tea.Cmd)

Update 处理更新事件

func (*InputBox) Value

func (box *InputBox) Value() string

Value 返回输入内容

func (*InputBox) View

func (box *InputBox) View() string

View 渲染显示内容

type MessageItem

type MessageItem struct {
	Type          MessageType
	Text          string
	WithFirstLine bool
}

MessageItem 消息项

func (MessageItem) Render added in v0.5.0

func (msg MessageItem) Render() string

Render 渲染

type MessageType

type MessageType int

MessageType 消息类型

const (
	MessageTypeUser MessageType = iota
	MessageTypeAgent
	MessageTypeAgentThought
	MessageTypeToolCall
	MessageTypeToolCallUpdate
	MessageTypeError
	MessageTypeUnknown
)

type MessageViewport

type MessageViewport struct {
	// contains filtered or unexported fields
}

MessageViewport 消息视窗

func NewMessageViewport

func NewMessageViewport(ctx context.Context) (MessageViewport, error)

NewMessageViewport 创建消息视窗

func (MessageViewport) AgentProcessing

func (vp MessageViewport) AgentProcessing() bool

AgentProcessing 返回是否 Agent 处理中

func (*MessageViewport) Flush

func (vp *MessageViewport) Flush() tea.Cmd

Flush 将缓存的消息刷到屏幕上

func (*MessageViewport) Reset

func (vp *MessageViewport) Reset()

Reset 重置

func (MessageViewport) Update

func (vp MessageViewport) Update(msg tea.Msg) (MessageViewport, tea.Cmd)

Update 处理更新事件

func (MessageViewport) View

func (vp MessageViewport) View() string

View 渲染显示内容

type MessagesList

type MessagesList []MessageItem

MessagesList 消息列表

func (MessagesList) Append

func (l MessagesList) Append(item MessageItem) MessagesList

Append 追加消息

func (MessagesList) Split added in v0.5.0

func (l MessagesList) Split(agentProcessing bool) (MessagesList, MessagesList)

Split 将消息列表切分为前面的固定部分和最后的可追加部分

type Options

type Options struct {
	AgentIn               io.Writer
	AgentOut              io.Reader
	Agent                 ACPAgent
	InitialPrompt         string
	AutoExitAfterResponse bool
	ResumeSessionID       string
	Channels              []channels.Channel
}

Options UI 运行选项

type PromptResult

type PromptResult struct {
	Response acp.PromptResponse
	Error    error
}

type QuitError

type QuitError struct {
	Error error
}

type Selector

type Selector struct {
	SuggestionPrefix string
	ShowDescription  bool
	NamePadding      int
	// contains filtered or unexported fields
}

Selector 选择器

func NewSelector

func NewSelector(items []SelectorOption, suggestionPrefix string, height, width int) Selector

NewSelector 创建选择器

func (*Selector) AddItems added in v0.3.0

func (s *Selector) AddItems(items ...SelectorOption)

AddItems 添加选项

func (Selector) Enabled

func (s Selector) Enabled() bool

Enabled 返回是否可用

func (*Selector) RenewTable

func (s *Selector) RenewTable()

RenewTable 更新表格

func (Selector) Selected

func (s Selector) Selected() string

Selected 返回选中内容

func (*Selector) SetEnabled

func (s *Selector) SetEnabled(enabled bool)

SetEnabled 设置是否启用

func (*Selector) SetSearchKey

func (s *Selector) SetSearchKey(key string)

SetSearchKey 设置搜索键

func (*Selector) SetWidth

func (s *Selector) SetWidth(width int)

SetWidth 设置宽度

func (Selector) Update

func (s Selector) Update(msg tea.Msg) (Selector, tea.Cmd)

Update 处理更新事件

func (Selector) View

func (s Selector) View() string

View 渲染显示内容

type SelectorOption

type SelectorOption struct {
	Name        string
	Description string
}

SelectorOption 选择器选项

Jump to

Keyboard shortcuts

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