Files
goclaw/internal/tools/types.go
T
Viet TranandGitHub 6895e369f6 refactor: remove standalone mode, consolidate to managed-only (PostgreSQL) (#70)
- Remove standalone mode code: file-based stores, standalone gateway,
  heartbeat service, SQLite memory, standalone docker-compose
- Rename docker-compose.managed.yml → docker-compose.postgres.yml
- Clean up ~130 Go comments referencing "managed mode" qualifier
- Simplify docker-compose.yml env vars (providers/channels via web UI)
- Update .env.example to essential vars only (token + encryption key)
- Add setup wizard UI (provider → agent → channel bootstrap flow)
- Add logs.tail WebSocket handler for live log streaming
- Add cursor-pointer to interactive UI components
- Clean up config page (remove standalone-only sections)
- Update README and docs for managed-only architecture
2026-03-06 18:51:11 +07:00

108 lines
3.0 KiB
Go

package tools
import (
"context"
"github.com/nextlevelbuilder/goclaw/internal/bus"
"github.com/nextlevelbuilder/goclaw/internal/providers"
"github.com/nextlevelbuilder/goclaw/internal/store"
)
// Tool is the interface all tools must implement.
type Tool interface {
Name() string
Description() string
Parameters() map[string]interface{}
Execute(ctx context.Context, args map[string]interface{}) *Result
}
// ContextualTool receives channel/chat context before execution.
type ContextualTool interface {
Tool
SetContext(channel, chatID string)
}
// PeerKindAware tools receive the peer kind (direct/group) before execution.
type PeerKindAware interface {
SetPeerKind(peerKind string)
}
// SandboxAware tools receive sandbox scope key before execution.
// Used by exec tool to route commands through Docker containers.
type SandboxAware interface {
SetSandboxKey(key string)
}
// AsyncCallback is invoked when an async tool completes.
type AsyncCallback func(ctx context.Context, result *Result)
// AsyncTool supports asynchronous execution with completion callbacks.
type AsyncTool interface {
Tool
SetCallback(cb AsyncCallback)
}
// --- Configuration interfaces for reducing type assertions in cmd/ wiring ---
// InterceptorAware tools can receive ContextFile and Memory interceptors.
type InterceptorAware interface {
SetContextFileInterceptor(*ContextFileInterceptor)
SetMemoryInterceptor(*MemoryInterceptor)
}
// GroupWriterAware tools receive a GroupWriterCache for group permission checks.
type GroupWriterAware interface {
SetGroupWriterCache(*store.GroupWriterCache)
}
// MemoryStoreAware tools can receive a MemoryStore for Postgres queries.
type MemoryStoreAware interface {
SetMemoryStore(store.MemoryStore)
}
// ApprovalAware tools can receive an ExecApprovalManager.
type ApprovalAware interface {
SetApprovalManager(*ExecApprovalManager, string)
}
// PathAllowable tools can allow extra path prefixes for read access.
type PathAllowable interface {
AllowPaths(...string)
}
// PathDenyable tools can deny access to specific path prefixes within the workspace.
type PathDenyable interface {
DenyPaths(...string)
}
// SessionStoreAware tools can receive a SessionStore for session queries.
type SessionStoreAware interface {
SetSessionStore(store.SessionStore)
}
// BusAware tools can receive a MessageBus for publishing messages.
type BusAware interface {
SetMessageBus(*bus.MessageBus)
}
// ChannelSender abstracts sending a message to a channel.
// Implemented by channels.Manager.SendToChannel.
type ChannelSender func(ctx context.Context, channel, chatID, content string) error
// ChannelSenderAware tools can receive a channel sender function.
type ChannelSenderAware interface {
SetChannelSender(ChannelSender)
}
// ToProviderDef converts a Tool to a providers.ToolDefinition for LLM APIs.
func ToProviderDef(t Tool) providers.ToolDefinition {
return providers.ToolDefinition{
Type: "function",
Function: providers.ToolFunctionSchema{
Name: t.Name(),
Description: t.Description(),
Parameters: t.Parameters(),
},
}
}