- Add bubbletea/lipgloss/glamour dependencies for TUI - Create internal/tui package with EventWriter, styles, and bubbletea Model - Support streaming output display in conversation window - Add right panel with statistics and active agent status - Implement multi-agent collaboration with sub-agents - Add AgentCallTool for delegating tasks to sub-agents - Support parallel tool execution with goroutines - Auto-discover sub-agents from ~/.orca/prompts/ directory - Fix orchestrator routing based on msg.To field - Add non-blocking event writer with timeout to prevent blocking
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
// Package plugin 定义 Orca 框架的插件系统。
|
||
//
|
||
// 所有对框架的扩展(技能、工具、LLM 驱动等)
|
||
// 都作为实现 Plugin 接口的插件来实现。
|
||
// 内核管理插件生命周期:加载、初始化、启动、停止、关闭。
|
||
package plugin
|
||
|
||
import (
|
||
"fmt"
|
||
"sync"
|
||
)
|
||
|
||
// Registry 是管理插件注册的线程安全映射。
|
||
type Registry struct {
|
||
mu sync.RWMutex
|
||
plugins map[string]Plugin
|
||
states map[string]PluginState
|
||
}
|
||
|
||
// NewRegistry 创建新的空插件注册表。
|
||
func NewRegistry() *Registry {
|
||
return &Registry{
|
||
plugins: make(map[string]Plugin),
|
||
states: make(map[string]PluginState),
|
||
}
|
||
}
|
||
|
||
// Register 将插件添加到注册表。
|
||
func (r *Registry) Register(p Plugin) error {
|
||
r.mu.Lock()
|
||
defer r.mu.Unlock()
|
||
|
||
name := p.Name()
|
||
if _, exists := r.plugins[name]; exists {
|
||
return fmt.Errorf("plugin %q is already registered", name)
|
||
}
|
||
|
||
r.plugins[name] = p
|
||
r.states[name] = StateRegistered
|
||
return nil
|
||
}
|
||
|
||
// Unregister 从注册表中移除插件。
|
||
func (r *Registry) Unregister(name string) error {
|
||
r.mu.Lock()
|
||
defer r.mu.Unlock()
|
||
|
||
if _, exists := r.plugins[name]; !exists {
|
||
return fmt.Errorf("plugin %q is not registered", name)
|
||
}
|
||
|
||
delete(r.plugins, name)
|
||
delete(r.states, name)
|
||
return nil
|
||
}
|
||
|
||
// Get 按名称检索插件。
|
||
func (r *Registry) Get(name string) (Plugin, bool) {
|
||
r.mu.RLock()
|
||
defer r.mu.RUnlock()
|
||
|
||
p, ok := r.plugins[name]
|
||
return p, ok
|
||
}
|
||
|
||
// List 返回所有已注册的插件。
|
||
func (r *Registry) List() []Plugin {
|
||
r.mu.RLock()
|
||
defer r.mu.RUnlock()
|
||
|
||
plugins := make([]Plugin, 0, len(r.plugins))
|
||
for _, p := range r.plugins {
|
||
plugins = append(plugins, p)
|
||
}
|
||
return plugins
|
||
}
|
||
|
||
// State 返回已注册插件的生命周期状态。
|
||
func (r *Registry) State(name string) PluginState {
|
||
r.mu.RLock()
|
||
defer r.mu.RUnlock()
|
||
|
||
if state, ok := r.states[name]; ok {
|
||
return state
|
||
}
|
||
return StateUnknown
|
||
}
|
||
|
||
// SetState 更新已注册插件的生命周期状态。
|
||
func (r *Registry) SetState(name string, state PluginState) {
|
||
r.mu.Lock()
|
||
defer r.mu.Unlock()
|
||
|
||
if _, ok := r.plugins[name]; ok {
|
||
r.states[name] = state
|
||
}
|
||
}
|
||
|
||
// Count 返回已注册插件的数量。
|
||
func (r *Registry) Count() int {
|
||
r.mu.RLock()
|
||
defer r.mu.RUnlock()
|
||
|
||
return len(r.plugins)
|
||
}
|