Help us shape the future of Go! Take the 2026 Go Developer Survey

approval

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Approval

type Approval struct {
	Approved bool
	Feedback string
}

Approval 是用户对一次审批请求的响应。

type Approver

type Approver interface {
	RequestApproval(ctx context.Context, toolID string, payload any) (Approval, error)
}

Approver 是工具端看到的审批能力接口。调用方只需知道能发起审批请求, 不需要知道模式切换、前端信令等实现细节。

type Service

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

Service 管理审批流程,实现 Approver 接口。 零超时,goroutine 睡在 channel 上等待前端响应。 mode 为 "auto" 时自动批准所有请求,无需前端交互。

func NewService

func NewService(logger *slog.Logger, initialMode string) *Service

NewService 创建审批服务,默认手动模式。initialMode 为空时默认 "manual"。

func (*Service) Complete

func (s *Service) Complete(toolID string, approved bool, feedback string) error

Complete 前端调用,向等待中的工具发送审批结果。

func (*Service) RequestApproval

func (s *Service) RequestApproval(ctx context.Context, toolID string, payload any) (Approval, error)

RequestApproval 工具端调用,阻塞等待用户审批或 ctx 取消。 mode 为 "auto" 时直接返回批准。

func (*Service) SetMode

func (s *Service) SetMode(mode string)

SetMode 切换审批模式。"auto" 自动批准,"manual" 等待前端。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL