mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-11 03:13:24 +00:00
* feat(hooks/observe): add structured output validation hook (ObserveHook) - hooks/types.go: Add ObserveHook interface + BuiltInHookType enum - hooks/dispatcher.go: HookDispatcher emits ObserveHook with PhaseResult payload - pipeline/observe_stage.go: ObserveStage emits hook after ObserveResult built - pipeline/substates.go: ObserveStageResult carries hook results + validation errors - hooks/config.go: BuiltInHookTypeObserve added to BuiltInHookType enum PhaseResult carries structured output, token usage, tool calls + validation errors emitted post-ObserveStage. ObserveHook implementations can validate structured output against schemas, detect tool-call loops, enforce token budgets, etc. Hook fires after ObserveStage produces ObserveResult, before results propagate to next stage. ValidationError returned by hook halts pipeline and propagates error to caller without further stage execution. Co-Authored-By: Claude <noreply@anthropic.com> * ui(hooks): add post_model_response event to web UI - Add event to Zod schema, filter dropdown, and form dialog - Implement conditional test panel UI for model response payload - Add translations (en/zh/vi) for new test panel fields - Updated beta description to reference the new event Co-Authored-By: Claude <noreply@anthropic.com> * feat(mcp): add MCP CRUD server exposing goclaw resources at /api/mcp/ with Bearer token auth and X-GoClaw-Tenant-Id header, default to master tenant * feat(mcp): add goclaw_skills_write_file tool to edit skill files on disk The CRUD MCP server's goclaw_skills_update only touched skill DB metadata, with no way to edit a skill's SKILL.md/file content on the filesystem. Extract the versioned write logic from the web UI's skill file editor (SkillsHandler.handleWriteFile) into skills.WriteVersionedFile so both surfaces share identical validation and versioning, and expose it as a new MCP tool. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
92 lines
5.1 KiB
Go
92 lines
5.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/agent"
|
|
"github.com/nextlevelbuilder/goclaw/internal/audio"
|
|
"github.com/nextlevelbuilder/goclaw/internal/bus"
|
|
"github.com/nextlevelbuilder/goclaw/internal/config"
|
|
"github.com/nextlevelbuilder/goclaw/internal/gateway"
|
|
"github.com/nextlevelbuilder/goclaw/internal/gateway/methods"
|
|
"github.com/nextlevelbuilder/goclaw/internal/memory"
|
|
"github.com/nextlevelbuilder/goclaw/internal/providers"
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
"github.com/nextlevelbuilder/goclaw/internal/tools"
|
|
usagecaps "github.com/nextlevelbuilder/goclaw/internal/usage/caps"
|
|
)
|
|
|
|
func registerAllMethods(server *gateway.Server, agents *agent.Router, sessStore store.SessionStore, tracingStore store.TracingStore, runTimeline store.RunTimelineStore, cronStore store.CronStore, pairingStore store.PairingStore, cfg *config.Config, cfgPath, workspace, dataDir string, msgBus *bus.MessageBus, execApprovalMgr *tools.ExecApprovalManager, agentStore store.AgentStore, skillStore store.SkillStore, configSecretsStore store.ConfigSecretsStore, teamStore store.TeamStore, agentLinkStore store.AgentLinkStore, contextFileInterceptor *tools.ContextFileInterceptor, logTee *gateway.LogTee, heartbeatStore store.HeartbeatStore, configPermStore store.ConfigPermissionStore, sysConfigStore store.SystemConfigStore, tenantStore store.TenantStore, skillTenantCfgStore store.SkillTenantConfigStore, audioMgr *audio.Manager, usageCapSvc *usagecaps.Service, providerReg *providers.Registry, teamWorkEmbedder memory.EmbeddingProvider) (*methods.PairingMethods, *methods.HeartbeatMethods, *methods.ChatMethods, *methods.ConfigPermissionsMethods) {
|
|
router := server.Router()
|
|
|
|
// Phase 1: Core methods
|
|
chatMethods := methods.NewChatMethods(agents, sessStore, cfg, server.RateLimiter(), msgBus)
|
|
chatMethods.SetAudioManager(audioMgr) // Wire TTS auto-apply for WS responses
|
|
chatMethods.SetUsageCapService(usageCapSvc)
|
|
chatMethods.SetTeamWorkClassification(agentStore, teamStore, agentLinkStore, teamWorkEmbedder)
|
|
chatMethods.Register(router)
|
|
methods.NewAgentsMethods(agents, cfg, cfgPath, workspace, agentStore, contextFileInterceptor, msgBus).Register(router)
|
|
methods.NewSessionsMethods(sessStore, msgBus, cfg).Register(router)
|
|
methods.NewRunTimelineMethods(runTimeline, cfg).Register(router)
|
|
configMethods := methods.NewConfigMethods(cfg, cfgPath, configSecretsStore, msgBus)
|
|
if sysConfigStore != nil {
|
|
configMethods.SetSystemConfigSync(func(ctx context.Context, c *config.Config) {
|
|
// Only sync config for the current tenant (from request context)
|
|
seedConfigForContext(ctx, sysConfigStore, c, false) // onlyMissing=false → upsert
|
|
// Trigger readback via bus event with fresh context (request ctx may be canceled)
|
|
if msgBus != nil {
|
|
freshCtx := store.WithTenantID(context.Background(), store.TenantIDFromContext(ctx))
|
|
msgBus.Broadcast(bus.Event{Name: bus.TopicSystemConfigChanged, Payload: freshCtx})
|
|
}
|
|
})
|
|
}
|
|
configMethods.Register(router)
|
|
|
|
// Phase 2: Skills (uses SkillStore interface — PG or File)
|
|
methods.NewSkillsMethods(skillStore, skillTenantCfgStore).Register(router)
|
|
|
|
// Phase 2: Cron (store created externally, shared with gateway)
|
|
methods.NewCronMethods(cronStore, msgBus, cfg).Register(router)
|
|
|
|
// Phase 2: Heartbeat
|
|
heartbeatMethods := methods.NewHeartbeatMethods(heartbeatStore, msgBus)
|
|
// Wire cache-aware resolver so heartbeat can accept agent_key or UUID
|
|
// without a DB roundtrip on the hot path when the agent is router-cached.
|
|
heartbeatMethods.SetAgentRouter(agents)
|
|
heartbeatMethods.Register(router)
|
|
|
|
// Phase 2: Config permissions
|
|
cfgPerms := methods.NewConfigPermissionsMethods(configPermStore, agentStore)
|
|
cfgPerms.SetAgentRouter(agents)
|
|
cfgPerms.Register(router)
|
|
|
|
// Phase 2: Pairing (store created externally, shared with channel manager).
|
|
// OnApprove callback is set later by the caller after channel manager is created.
|
|
pairingMethods := methods.NewPairingMethods(pairingStore, msgBus, server.RateLimiter())
|
|
pairingMethods.Register(router)
|
|
|
|
// Phase 2: Usage (queries SessionStore for real token data)
|
|
methods.NewUsageMethods(sessStore, tracingStore).Register(router)
|
|
methods.NewLLMMethods(providerReg, cfg.Gateway.BackgroundProvider, cfg.Gateway.BackgroundModel).Register(router)
|
|
// Wire the same provider registry into the CRUD MCP server (see
|
|
// internal/mcp/crud_server.go, mounted at /api/mcp/ in BuildMux()).
|
|
server.SetLLMProviders(providerReg, cfg.Gateway.BackgroundProvider, cfg.Gateway.BackgroundModel)
|
|
|
|
// Phase 2: Exec approval (always registered — returns empty when manager is nil)
|
|
methods.NewExecApprovalMethods(execApprovalMgr, msgBus).Register(router)
|
|
|
|
// Phase 2: Send (outbound message routing)
|
|
methods.NewSendMethods(msgBus).Register(router)
|
|
|
|
// Phase 3: Live log tailing
|
|
methods.NewLogsMethods(logTee).Register(router)
|
|
|
|
slog.Info("registered all RPC methods",
|
|
"phase1", []string{"chat", "agents", "sessions", "config"},
|
|
"phase2", []string{"skills", "cron", "heartbeat", "pairing", "usage", "llm", "exec_approval", "send"},
|
|
)
|
|
|
|
return pairingMethods, heartbeatMethods, chatMethods, cfgPerms
|
|
}
|