Documentation
¶
Overview ¶
Package ai 实现 ai binder:会话管理、消息收发、provider 配置、AI 工具审批。
同时暴露 ToolExecutor 接口给 opsctl,让 opsctl 在外部触发 AI 工具调用时复用同一执行路径。
Index ¶
- type AI
- func (a *AI) Cleanup()
- func (a *AI) ClearQueuedAIMessages(convID int64) []string
- func (a *AI) CreateAIProvider(name, providerType, apiBase, apiKey, model string, ...) (*AIProviderInfo, error)
- func (a *AI) CreateConversation() (*conversation_entity.Conversation, error)
- func (a *AI) DeleteAIProvider(id int64) error
- func (a *AI) DeleteConversation(id int64) error
- func (a *AI) DrainAIFlushAck()
- func (a *AI) FetchAIModels(providerType, apiBase, apiKey string) ([]AIModelInfo, error)
- func (a *AI) GetActiveAIProvider() (*AIProviderInfo, error)
- func (a *AI) GetCurrentConversationID() int64
- func (a *AI) GetModelDefaults(model string) *AIModelInfo
- func (a *AI) InitAIProvider()
- func (a *AI) ListAIProviders() ([]AIProviderInfo, error)
- func (a *AI) ListConversations() ([]*conversation_entity.Conversation, error)
- func (a *AI) LoadConversationMessages(id int64) ([]ConversationDisplayMessage, error)
- func (a *AI) QueueAIMessage(convID int64, queueID string, content string) error
- func (a *AI) RemoveQueuedAIMessage(convID int64, queueID string) bool
- func (a *AI) RespondAIApproval(confirmID string, resp permission.ApprovalResponse)
- func (a *AI) RespondPermission(behavior, message string)
- func (a *AI) SaveConversationMessages(convID int64, displayMsgs []ConversationDisplayMessage) error
- func (a *AI) SendAIMessage(convID int64, messages []runner.Message, aiCtx runner.AIContext) error
- func (a *AI) SetActiveAIProvider(id int64) error
- func (a *AI) SetExtensionService(svc *extension_svc.Service)
- func (a *AI) SetKafkaService(svc *kafka_svc.Service)
- func (a *AI) SetSerialManager(mgr *serial_svc.Manager)
- func (a *AI) SetWindowActivator(w WindowActivator)
- func (a *AI) Startup(ctx context.Context)
- func (a *AI) StopAIGeneration(convID int64) error
- func (a *AI) SwitchConversation(id int64) ([]ConversationDisplayMessage, error)
- func (a *AI) UpdateAIProvider(id int64, name, providerType, apiBase, apiKey, model string, ...) error
- func (a *AI) UpdateConversationTitle(id int64, title string) error
- func (a *AI) WaitAIFlushAck() <-chan struct{}
- type AIModelInfo
- type AIProviderInfo
- type ConversationDisplayMessage
- type LangProvider
- type WindowActivator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AI ¶
type AI struct {
// contains filtered or unexported fields
}
AI binder。
func (*AI) ClearQueuedAIMessages ¶
ClearQueuedAIMessages 清空 cago Runner 尚未消费的 Steer 队列。
func (*AI) CreateAIProvider ¶
func (a *AI) CreateAIProvider(name, providerType, apiBase, apiKey, model string, maxOutputTokens, contextWindow int, reasoningEnabled bool, reasoningEffort string) (*AIProviderInfo, error)
CreateAIProvider 创建新 Provider
func (*AI) CreateConversation ¶
func (a *AI) CreateConversation() (*conversation_entity.Conversation, error)
CreateConversation 创建新会话
func (*AI) DeleteAIProvider ¶
DeleteAIProvider 删除 Provider
func (*AI) DeleteConversation ¶
DeleteConversation 删除会话
func (*AI) DrainAIFlushAck ¶
func (a *AI) DrainAIFlushAck()
DrainAIFlushAck 在 emit ai:flush-all 之前清空 channel 上一次残留,避免拿到旧 ack。
func (*AI) FetchAIModels ¶
func (a *AI) FetchAIModels(providerType, apiBase, apiKey string) ([]AIModelInfo, error)
FetchAIModels 从 API 获取可用模型列表
func (*AI) GetActiveAIProvider ¶
func (a *AI) GetActiveAIProvider() (*AIProviderInfo, error)
GetActiveAIProvider 获取当前激活的 Provider
func (*AI) GetCurrentConversationID ¶
GetCurrentConversationID 获取当前会话ID
func (*AI) GetModelDefaults ¶
func (a *AI) GetModelDefaults(model string) *AIModelInfo
GetModelDefaults 获取模型的默认参数,未知模型返回 fallback 默认值
func (*AI) ListAIProviders ¶
func (a *AI) ListAIProviders() ([]AIProviderInfo, error)
ListAIProviders 列出所有 Provider
func (*AI) ListConversations ¶
func (a *AI) ListConversations() ([]*conversation_entity.Conversation, error)
ListConversations 获取会话列表
func (*AI) LoadConversationMessages ¶
func (a *AI) LoadConversationMessages(id int64) ([]ConversationDisplayMessage, error)
LoadConversationMessages 只读加载会话消息,不修改 currentConversationID。
func (*AI) QueueAIMessage ¶
QueueAIMessage 在生成过程中通过 cago Runner.Steer 把用户消息注入当前 turn。
func (*AI) RemoveQueuedAIMessage ¶
RemoveQueuedAIMessage 尝试从 cago Runner 尚未消费的 Steer 队列里删除一条消息。
func (*AI) RespondAIApproval ¶
func (a *AI) RespondAIApproval(confirmID string, resp permission.ApprovalResponse)
RespondAIApproval 前端响应 AI 审批请求(统一入口)
func (*AI) RespondPermission ¶
RespondPermission 前端响应权限确认请求
func (*AI) SaveConversationMessages ¶
func (a *AI) SaveConversationMessages(convID int64, displayMsgs []ConversationDisplayMessage) error
SaveConversationMessages 前端调用,保存显示消息到数据库。
func (*AI) SendAIMessage ¶
SendAIMessage 发送 AI 消息,通过 Wails Events 流式返回
func (*AI) SetActiveAIProvider ¶
SetActiveAIProvider 切换激活 Provider 并创建 Agent
func (*AI) SetExtensionService ¶
func (a *AI) SetExtensionService(svc *extension_svc.Service)
SetExtensionService 由 main.go 注入 extension_svc,供 SendAIMessage 注入 SKILL.md。
func (*AI) SetKafkaService ¶
SetKafkaService 由 main.go 注入:AI tool 在 chat ctx 中通过 helper.WithKafkaService 暴露给 handler。
func (*AI) SetSerialManager ¶
func (a *AI) SetSerialManager(mgr *serial_svc.Manager)
SetSerialManager 同上。
func (*AI) SetWindowActivator ¶
func (a *AI) SetWindowActivator(w WindowActivator)
SetWindowActivator 由 main.go 注入:local-tool 审批弹出时需要把窗口拉前台。
func (*AI) StopAIGeneration ¶
StopAIGeneration 调用 cago Runner.Cancel 触发取消。
func (*AI) SwitchConversation ¶
func (a *AI) SwitchConversation(id int64) ([]ConversationDisplayMessage, error)
SwitchConversation 切换到指定会话,返回显示消息
func (*AI) UpdateAIProvider ¶
func (a *AI) UpdateAIProvider(id int64, name, providerType, apiBase, apiKey, model string, maxOutputTokens, contextWindow int, reasoningEnabled bool, reasoningEffort string) error
UpdateAIProvider 更新 Provider
func (*AI) UpdateConversationTitle ¶
UpdateConversationTitle 更新会话标题。
func (*AI) WaitAIFlushAck ¶
func (a *AI) WaitAIFlushAck() <-chan struct{}
WaitAIFlushAck 暴露给 main.go 的 OnBeforeClose,等待前端 flush 完成。
type AIModelInfo ¶
type AIModelInfo struct {
ID string `json:"id"`
MaxOutputTokens int `json:"maxOutputTokens"`
ContextWindow int `json:"contextWindow"`
}
AIModelInfo 模型信息
type AIProviderInfo ¶
type AIProviderInfo struct {
ID int64 `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
APIBase string `json:"apiBase"`
APIKey string `json:"apiKey"`
MaskedAPIKey string `json:"maskedApiKey"`
Model string `json:"model"`
MaxOutputTokens int `json:"maxOutputTokens"`
ContextWindow int `json:"contextWindow"`
ReasoningEnabled bool `json:"reasoningEnabled"`
ReasoningEffort string `json:"reasoningEffort"`
IsActive bool `json:"isActive"`
}
AIProviderInfo 返回给前端的 Provider 信息
type ConversationDisplayMessage ¶
type ConversationDisplayMessage struct {
Role string `json:"role"`
Content string `json:"content"`
Blocks []conversation_entity.ContentBlock `json:"blocks"`
TokenUsage *conversation_entity.TokenUsage `json:"tokenUsage,omitempty"`
}
ConversationDisplayMessage 返回给前端的会话消息(用于恢复显示)
type WindowActivator ¶
type WindowActivator interface {
ActivateWindow()
}
WindowActivator 由 system binder 实现:审批弹窗时把窗口拉到前台。