chat

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 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.",
	}

	MsgCmdDescClear = &i18n.Message{
		ID:    "ui.chat.CmdDescClear",
		Other: "Start a fresh conversation",
	}
	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 ACPClientSideConnection

type ACPClientSideConnection interface {
	Initialize(ctx context.Context, req acp.InitializeRequest) (acp.InitializeResponse, error)
	NewSession(ctx context.Context, req acp.NewSessionRequest) (acp.NewSessionResponse, error)
	LoadSession(ctx context.Context, req acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
	Prompt(ctx context.Context, req acp.PromptRequest) (acp.PromptResponse, error)
	Cancel(ctx context.Context, req acp.CancelNotification) error
}

ACPClientSideConnection ACP 客户端侧连接

type ChatUI

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

ChatUI 对话 UI

func NewChatUI

func NewChatUI(opts Options) *ChatUI

NewChatUI 创建对话 UI

func (*ChatUI) Init

func (ui *ChatUI) Init() tea.Cmd

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

func (*ChatUI) RequestPermission

func (ui *ChatUI) RequestPermission(
	_ context.Context,
	params acp.RequestPermissionRequest,
) (acp.RequestPermissionResponse, error)

RequestPermission 请求授权

func (*ChatUI) Run

func (ui *ChatUI) Run(ctx context.Context) error

Run 运行 UI

func (*ChatUI) SessionUpdate

func (ui *ChatUI) SessionUpdate(_ context.Context, params acp.SessionNotification) error

SessionUpdate 更新会话

func (*ChatUI) Update

func (ui *ChatUI) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update 处理更新事件

func (*ChatUI) View

func (ui *ChatUI) View() string

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) 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
}

MessageItem 消息项

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 追加消息

type ModelSelector

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

ModelSelector 模型选择器

func NewModelSelector

func NewModelSelector() *ModelSelector

NewModelSelector 创建模型选择器

func (*ModelSelector) GetSelectedModels

func (s *ModelSelector) GetSelectedModels() (ModelType, string, models.Models)

GetSelectedModels 返回更新后的模型选择

func (*ModelSelector) Init

func (s *ModelSelector) Init() tea.Cmd

Init 初始化

func (*ModelSelector) SetAvailableModels

func (s *ModelSelector) SetAvailableModels(availableModels []models.ModelConfig)

SetAvailableModels 设置可用模型列表

func (*ModelSelector) SetContext

func (s *ModelSelector) SetContext(ctx context.Context)

SetContext 设置上下文

func (*ModelSelector) SetCurrentModels

func (s *ModelSelector) SetCurrentModels(curModels models.Models)

SetCurrentModels 设置当前模型

func (*ModelSelector) SetModelType

func (s *ModelSelector) SetModelType(t ModelType)

SetModelType 设置选择的模型类型

func (*ModelSelector) Update

func (s *ModelSelector) Update(msg tea.Msg) (*ModelSelector, tea.Cmd)

Update 处理更新事件

func (*ModelSelector) View

func (s *ModelSelector) View() string

View 渲染显示内容

type ModelType

type ModelType string
const (
	ModelTypePrimary ModelType = "primary"
	ModelTypeLight   ModelType = "light"
	ModelTypeVision  ModelType = "vision"
)

type Options

type Options struct {
	AgentClientIn         io.Reader
	AgentClientOut        io.Writer
	InitialPrompt         string
	AutoExitAfterResponse bool
	ResumeSessionID       string
}

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) 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