Documentation
¶
Overview ¶
Package commands 提供 slash 命令(Commands)系统。
对齐上游:packages/interaction/commands
设计要点:
- CommandDefinition 描述一个 slash 命令(如 /plan off);
- 命令入口通过 ctx.commands register/list/execute 路由;
- 执行 `#command/run` 与 `#command/done` 事件(而非当成普通 user/message);
- 例如 `/plan off` 直接写入 plan/mode(off) 事件,而不是作为对话消息。
Index ¶
- type CommandDefinition
- type CommandHandler
- type ErrUnknownCommand
- type Registry
- func (r *Registry) Dispatch(ctx context.Context, raw string, sl *session.SessionLog) (string, error)
- func (r *Registry) Freeze()
- func (r *Registry) Get(name string) (*CommandDefinition, bool)
- func (r *Registry) IsFrozen() bool
- func (r *Registry) List() []string
- func (r *Registry) Register(def *CommandDefinition) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandDefinition ¶
type CommandDefinition struct {
// Name 命令名(不含 "/" 前缀,如 "plan")。
Name string
// Description 命令描述(帮助展示)。
Description string
// Handler 执行函数。
Handler CommandHandler
}
CommandDefinition 是一个 slash 命令定义。
type CommandHandler ¶
type CommandHandler func(ctx context.Context, args string, sl *session.SessionLog) (output string, err error)
CommandHandler 是命令处理函数:接收参数字符串与事件日志,写事件并返回输出。
type ErrUnknownCommand ¶
type ErrUnknownCommand string
ErrUnknownCommand 表示命令不存在。
func (ErrUnknownCommand) Error ¶
func (e ErrUnknownCommand) Error() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 是命令注册中心(H07:基于可冻结共享注册表,Freeze 后读路径无锁)。
func (*Registry) Dispatch ¶
func (r *Registry) Dispatch(ctx context.Context, raw string, sl *session.SessionLog) (string, error)
Dispatch 解析 "/name args" 并执行对应命令(不存在返回 ErrUnknownCommand)。
func (*Registry) Freeze ¶
func (r *Registry) Freeze()
Freeze 冻结命令注册表(不可逆):此后读路径无锁走只读快照,写返回 ErrFrozen。
func (*Registry) Get ¶
func (r *Registry) Get(name string) (*CommandDefinition, bool)
Get 按名取命令(冻结后无锁读快照)。
func (*Registry) Register ¶
func (r *Registry) Register(def *CommandDefinition) error
Register 注册一个命令;冻结后返回 ErrFrozen。
Click to show internal directories.
Click to hide internal directories.