service

package
v0.0.0-...-5a2f47e Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApprovalPending  = "pending"
	ApprovalApproved = "approved"
	ApprovalRejected = "rejected"
	ApprovalExpired  = "expired"
)

Variables

View Source
var ErrApprovalNotFound = errors.New("approval not found")

Functions

This section is empty.

Types

type AgentService

type AgentService interface {
	Query(ctx context.Context, req *model.AgentQueryReq, userID int) (*model.AgentQueryResponse, error)
	QueryStream(ctx context.Context, req *model.AgentQueryReq, userID int, writer io.Writer) error
	QueryWithPipeline(ctx context.Context, req *model.AgentQueryReq, userID int) (*model.AgentQueryResponse, error)
	QueryStreamWithPipeline(ctx context.Context, req *model.AgentQueryReq, userID int, writer io.Writer) error
	CreateSession(ctx context.Context, req *model.CreateAgentSessionReq, userID int) (*model.AgentSession, error)
	ListSessions(ctx context.Context, req *model.ListAgentSessionsReq, userID int) (model.ListResp[*model.AgentSession], error)
	GetSession(ctx context.Context, id int) (*model.AgentSession, error)
	GetSessionByKey(ctx context.Context, key string) (*model.AgentSession, error)
	DeleteSession(ctx context.Context, id int) error
	UpdateSession(ctx context.Context, session *model.AgentSession) error
	ListMessages(ctx context.Context, req *model.ListAgentMessagesReq) (model.ListResp[*model.AgentMessage], error)
	GetMessage(ctx context.Context, sessionID string, messageID int64) (*model.AgentMessage, error)
	ResetSession(ctx context.Context, sessionKey string, userID int) (*model.AgentSession, error)
	CompactSession(ctx context.Context, sessionKey string, maxMessages int, userID int) error
	GetModelCatalog(ctx context.Context) (*ModelCatalog, error)
	ListTools(ctx context.Context) ([]map[string]interface{}, error)
	InvokeTool(ctx context.Context, toolName, argsJSON string) (string, error)

	// Agent管理
	ListAgents(ctx context.Context) ([]*model.GatewayAgent, error)
	GetAgent(ctx context.Context, agentID string) (*model.GatewayAgent, error)
	CreateAgent(ctx context.Context, agent *model.GatewayAgent) error
	UpdateAgent(ctx context.Context, agent *model.GatewayAgent) error
	DeleteAgent(ctx context.Context, agentID string) error

	// ReloadConfig 热重载运行时配置(DB 覆盖值)
	ReloadConfig(ctx context.Context, cfg *Config) error

	// GetConfig 返回当前内存中的服务配置(用于 Gateway 等外部组件读取 LLM 状态)。
	GetConfig() *Config
}

AgentService 智能体服务接口

func NewAgentService

func NewAgentService(
	dao dao.AgentDAO,
	toolMgr *manager.ToolManager,
	riskEval *risk.Evaluator,
	auditStore agentaudit.Store,
	cfg *Config,
	logger *zap.Logger,
	pipelineStage *pipeline.Stage,
	nudgeReviewer *nudge.MemoryNudgeReviewer,
) AgentService

NewAgentService 创建智能体服务实例

type ApprovalStore

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

func NewApprovalStore

func NewApprovalStore() *ApprovalStore

func (*ApprovalStore) Approve

func (s *ApprovalStore) Approve(ctx context.Context, id string) (agentmodel.Approval, error)

func (*ApprovalStore) Create

func (*ApprovalStore) Get

func (*ApprovalStore) ListBySession

func (s *ApprovalStore) ListBySession(_ context.Context, sessionID string) ([]agentmodel.Approval, error)

func (*ApprovalStore) Reject

type Config

type Config struct {
	LLM        LLMConfig
	MaxHistory int
}

Config 智能体服务配置,与 di.AgentConfig 字段对齐,避免 import cycle。

type ConfigService

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

func NewConfigService

func NewConfigService(dao *agentDao.AgentConfigDAO) *ConfigService

func (*ConfigService) DeleteConfig

func (s *ConfigService) DeleteConfig(ctx context.Context, key string) error

DeleteConfig removes a config entry by key.

func (*ConfigService) GetConfig

func (s *ConfigService) GetConfig(ctx context.Context, key string) (string, error)

GetConfig returns the raw config value JSON string for a key

func (*ConfigService) GetInjectionRules

func (s *ConfigService) GetInjectionRules(ctx context.Context) ([]InjectionRule, error)

GetInjectionRules loads injection regex rules from DB and compiles them

func (*ConfigService) GetLLMAuditPrompt

func (s *ConfigService) GetLLMAuditPrompt(ctx context.Context) (*LLMAuditPromptConfig, error)

GetLLMAuditPrompt loads the LLM audit prompt config from DB

func (*ConfigService) ListConfigs

func (s *ConfigService) ListConfigs(ctx context.Context) ([]map[string]string, error)

ListConfigs returns all config keys with descriptions (no values)

func (*ConfigService) UpsertConfig

func (s *ConfigService) UpsertConfig(ctx context.Context, key string, value string) error

UpsertConfig updates or creates a config entry

type InjectionRule

type InjectionRule struct {
	ID      int            `json:"id"`
	Pattern string         `json:"pattern"`
	Desc    string         `json:"desc"`
	Enabled bool           `json:"enabled"`
	Re      *regexp.Regexp `json:"-"` // compiled regex, not serialized
}

InjectionRule 单条注入检测规则

type InjectionRulesConfig

type InjectionRulesConfig struct {
	Rules []InjectionRule `json:"rules"`
}

InjectionRulesConfig injection_rules 配置的 JSON 结构

type InstallSkillRequest

type InstallSkillRequest struct {
	Name                          string `json:"name"`
	InstallID                     string `json:"installId,omitempty"`
	DangerouslyForceUnsafeInstall bool   `json:"dangerouslyForceUnsafeInstall"`
	TimeoutMs                     int    `json:"timeoutMs,omitempty"`
	Source                        string `json:"source,omitempty"`
	Slug                          string `json:"slug,omitempty"`
	Version                       string `json:"version,omitempty"`
}

InstallSkillRequest supports both local and ClawHub installs.

type LLMAuditPromptConfig

type LLMAuditPromptConfig struct {
	Enabled      bool    `json:"enabled"`
	Model        string  `json:"model"`
	Temperature  float64 `json:"temperature"`
	MaxTokens    int     `json:"max_tokens"`
	TimeoutSec   int     `json:"timeout_sec"`
	MaxRetries   int     `json:"max_retries"`
	SystemPrompt string  `json:"system_prompt"`
}

LLMAuditPromptConfig llm_audit_prompt 配置的 JSON 结构

type LLMConfig

type LLMConfig struct {
	Provider    string
	BaseURL     string
	APIKey      string
	Model       string
	Temperature float64
	MaxTokens   int
}

LLMConfig LLM 配置,与 di.AgentLLMConfig 字段对齐,避免 import cycle。

type ModelCatalog

type ModelCatalog struct {
	Providers    []ModelProvider `json:"providers"`
	DefaultModel string          `json:"defaultModel"`
}

ModelCatalog 模型目录,返回可用的 LLM 模型和提供商信息

type ModelEntry

type ModelEntry struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

ModelEntry 单个模型条目

type ModelProvider

type ModelProvider struct {
	ID     string       `json:"id"`
	Name   string       `json:"name"`
	Models []ModelEntry `json:"models"`
}

ModelProvider LLM 提供商

type SecurityVerdictsRequest

type SecurityVerdictsRequest struct {
	Items []agentskill.ClawHubSecurityVerdictRequest `json:"items,omitempty"`
}

SecurityVerdictsRequest allows callers to request verdicts for specific skills.

type SkillCardResponse

type SkillCardResponse struct {
	Schema    string `json:"schema"`
	SkillKey  string `json:"skillKey"`
	Path      string `json:"path"`
	SizeBytes int64  `json:"sizeBytes"`
	Content   string `json:"content"`
}

SkillCardResponse mirrors the frontend skillCard response shape.

type SkillCardStatus

type SkillCardStatus struct {
	Present   bool   `json:"present"`
	Path      string `json:"path"`
	SizeBytes int64  `json:"sizeBytes"`
}

SkillCardStatus mirrors the frontend SkillCardStatus type.

type SkillClawHubLink struct {
	Status           string `json:"status"`
	Valid            bool   `json:"valid"`
	Reason           string `json:"reason,omitempty"`
	Registry         string `json:"registry,omitempty"`
	Slug             string `json:"slug,omitempty"`
	InstalledVersion string `json:"installedVersion,omitempty"`
	InstalledAt      int64  `json:"installedAt,omitempty"`
	OriginPath       string `json:"originPath,omitempty"`
	LockPath         string `json:"lockPath,omitempty"`
}

SkillClawHubLink mirrors the frontend SkillClawHubLink type.

type SkillInstallOption

type SkillInstallOption struct {
	ID    string   `json:"id"`
	Kind  string   `json:"kind"`
	Label string   `json:"label"`
	Bins  []string `json:"bins"`
}

SkillInstallOption mirrors the frontend SkillInstallOption type.

type SkillMissing

type SkillMissing struct {
	Bins   []string `json:"bins"`
	Env    []string `json:"env"`
	Config []string `json:"config"`
	OS     []string `json:"os"`
}

SkillMissing mirrors the frontend missing shape.

type SkillRequirements

type SkillRequirements struct {
	AnyBins []string `json:"anyBins,omitempty"`
	Bins    []string `json:"bins"`
	Env     []string `json:"env"`
	Config  []string `json:"config"`
	OS      []string `json:"os"`
}

SkillRequirements mirrors the frontend requirements shape.

type SkillService

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

SkillService provides the Gateway-facing skill management layer.

func NewSkillService

func NewSkillService(store *agentskill.SkillStore, clawHub *agentskill.ClawHubClient, cfg SkillsConfig, logger *zap.Logger) *SkillService

NewSkillService creates a skill service.

func (*SkillService) Bins

func (s *SkillService) Bins(ctx context.Context) (map[string]interface{}, error)

Bins returns an empty map for now (placeholder for future per-skill binary introspection).

func (*SkillService) GetClawHubDetail

func (s *SkillService) GetClawHubDetail(ctx context.Context, slug string) (*agentskill.ClawHubSkillDetail, error)

GetClawHubDetail forwards the detail request to the ClawHub registry.

func (*SkillService) GetSkillCard

func (s *SkillService) GetSkillCard(ctx context.Context, skillKey string) (*SkillCardResponse, error)

GetSkillCard returns the full content of a skill's SKILL.md file.

func (*SkillService) InstallSkill

func (s *SkillService) InstallSkill(ctx context.Context, req InstallSkillRequest) (string, error)

InstallSkill installs a skill either from a local install option or from ClawHub.

func (*SkillService) SearchClawHub

func (s *SkillService) SearchClawHub(ctx context.Context, query string, limit int) ([]agentskill.ClawHubSearchResult, error)

SearchClawHub forwards the search to the ClawHub registry.

func (*SkillService) SecurityVerdicts

SecurityVerdicts returns ClawHub security verdicts for the requested skills. If no items are provided, verdicts are computed for locally installed ClawHub-linked skills.

func (*SkillService) Status

func (s *SkillService) Status(ctx context.Context, agentID string) (*SkillStatusReport, error)

Status returns a skill status report compatible with the OpenClaw UI.

func (*SkillService) UpdateSkill

func (s *SkillService) UpdateSkill(ctx context.Context, req UpdateSkillRequest) error

UpdateSkill toggles a skill's enabled/archived state or saves an API key.

type SkillStatusEntry

type SkillStatusEntry struct {
	Name                 string                    `json:"name"`
	Description          string                    `json:"description"`
	Source               string                    `json:"source"`
	FilePath             string                    `json:"filePath"`
	BaseDir              string                    `json:"baseDir"`
	SkillKey             string                    `json:"skillKey"`
	Bundled              bool                      `json:"bundled,omitempty"`
	PrimaryEnv           string                    `json:"primaryEnv,omitempty"`
	Emoji                string                    `json:"emoji,omitempty"`
	Homepage             string                    `json:"homepage,omitempty"`
	Always               bool                      `json:"always"`
	Disabled             bool                      `json:"disabled"`
	BlockedByAllowlist   bool                      `json:"blockedByAllowlist"`
	BlockedByAgentFilter bool                      `json:"blockedByAgentFilter,omitempty"`
	Eligible             bool                      `json:"eligible"`
	ModelVisible         bool                      `json:"modelVisible,omitempty"`
	UserInvocable        bool                      `json:"userInvocable,omitempty"`
	CommandVisible       bool                      `json:"commandVisible,omitempty"`
	Requirements         SkillRequirements         `json:"requirements"`
	Missing              SkillMissing              `json:"missing"`
	ConfigChecks         []SkillsStatusConfigCheck `json:"configChecks"`
	Install              []SkillInstallOption      `json:"install"`
	ClawHub              *SkillClawHubLink         `json:"clawhub,omitempty"`
	SkillCard            *SkillCardStatus          `json:"skillCard,omitempty"`
}

SkillStatusEntry mirrors the frontend SkillStatusEntry type.

type SkillStatusReport

type SkillStatusReport struct {
	WorkspaceDir     string             `json:"workspaceDir"`
	ManagedSkillsDir string             `json:"managedSkillsDir"`
	AgentID          string             `json:"agentId,omitempty"`
	AgentSkillFilter []string           `json:"agentSkillFilter,omitempty"`
	Skills           []SkillStatusEntry `json:"skills"`
}

SkillStatusReport mirrors the frontend SkillStatusReport type.

type SkillsConfig

type SkillsConfig struct {
	BaseDir        string
	ClawHubBaseURL string
	ClawHubAPIKey  string
	Registry       string
}

SkillsConfig configures the skill service.

type SkillsStatusConfigCheck

type SkillsStatusConfigCheck struct {
	Path      string `json:"path"`
	Satisfied bool   `json:"satisfied"`
}

SkillsStatusConfigCheck mirrors the frontend config check shape.

type UpdateSkillRequest

type UpdateSkillRequest struct {
	SkillKey string `json:"skillKey"`
	Enabled  *bool  `json:"enabled,omitempty"`
	APIKey   string `json:"apiKey,omitempty"`
}

UpdateSkillRequest supports enable toggle and API key storage.

Jump to

Keyboard shortcuts

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