跳转至

阶段钩子(Stages)

在消息处理管道的固定点位插入自己的逻辑。阶段比工具更底层:工具是模型主动调用的,阶段是流程经过时必然触发的。

StageContext.IsResponded

func (c *StageContext) IsResponded() bool

plugin.go:342

StageContext.Lock

func (c *StageContext) Lock()

示例插件里的真实用法

插件 位置 代码
rtvoice example/rtvoice/plugin_test.go:29 r.mu.Lock()

plugin.go:340

StageContext.RLock

func (c *StageContext) RLock()

plugin.go:338

StageContext.RUnlock

func (c *StageContext) RUnlock()

plugin.go:339

PluginSDK.RegisterStage

func (s *PluginSDK) RegisterStage(stage Stage, handler StageHandler, scope ...StageScope)

RegisterStage registers a handler for a pipeline stage.

scope: StageScopeGlobal (default) — receives all stage events.
       StageScopeOwnTools — only before_toolcall/after_toolcall for this plugin's tools.

plugin.go:802

Stage

type Stage string

Stage represents a point in the message processing pipeline.

plugin.go:60

StageContext

type StageContext struct { mu sync.RWMutex RawMessage string UserID string GroupID string ContextMsgs []map[string]interface{} L …

StageContext provides context for stage handlers.

plugin.go:318

StageHandler

type StageHandler func(ctx *StageContext) error

StageHandler is a function that handles a pipeline stage event.

plugin.go:57

StageRegistrar

type StageRegistrar func(stage Stage, handler StageHandler)

StageRegistrar registers a stage handler.

plugin.go:582

StageScope

type StageScope int

StageScope controls which events a stage handler receives.

plugin.go:568

StageContext.Unlock

func (c *StageContext) Unlock()

示例插件里的真实用法

插件 位置 代码
rtvoice example/rtvoice/plugin_test.go:31 r.mu.Unlock()

plugin.go:341