tools

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllowedDir

func GetAllowedDir() string

GetAllowedDir 获取允许访问的目录

func GetWorkspaceDir

func GetWorkspaceDir() string

GetWorkspaceDir 获取工作区目录

func RuntimeContextFrom

func RuntimeContextFrom(ctx context.Context) (channel, chatID string)

RuntimeContextFrom extracts channel/chat metadata from context.

func RuntimeSessionKeyFrom

func RuntimeSessionKeyFrom(ctx context.Context) string

RuntimeSessionKeyFrom extracts session key metadata from context.

func SetAllowedDir

func SetAllowedDir(dir string)

SetAllowedDir 设置允许访问的目录

func SetWorkspaceDir

func SetWorkspaceDir(dir string)

SetWorkspaceDir 设置工作区目录(用于会话文件默认路径)

func TestMCPServer

func TestMCPServer(opts MCPServerOptions) (tools []string, err error)

TestMCPServer 测试单个 MCP 服务器连接

func ValidateParams

func ValidateParams(schema, params map[string]interface{}) error

ValidateParams 验证参数

func WithRuntimeContext

func WithRuntimeContext(ctx context.Context, channel, chatID string) context.Context

WithRuntimeContext injects channel/chat metadata for tools in the current request.

func WithRuntimeContextWithSession

func WithRuntimeContextWithSession(ctx context.Context, channel, chatID, sessionKey string) context.Context

WithRuntimeContextWithSession injects channel/chat/session metadata for tools in the current request.

Types

type BaseTool

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

BaseTool 工具基类

func (*BaseTool) Description

func (t *BaseTool) Description() string

Description 返回工具描述

func (*BaseTool) Name

func (t *BaseTool) Name() string

Name 返回工具名称

func (*BaseTool) Parameters

func (t *BaseTool) Parameters() map[string]interface{}

Parameters 返回参数定义

func (*BaseTool) ToOpenAISchema

func (t *BaseTool) ToOpenAISchema() map[string]interface{}

ToOpenAISchema 转换为 OpenAI 函数格式

type BrowserTool

type BrowserTool struct {
	BaseTool
	// contains filtered or unexported fields
}

BrowserTool provides Playwright-style browser actions via Node runner.

func NewBrowserTool

func NewBrowserTool(options BrowserToolOptions) *BrowserTool

NewBrowserTool creates browser tool.

func (*BrowserTool) Execute

func (t *BrowserTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute runs browser action.

type BrowserToolOptions

type BrowserToolOptions struct {
	NodePath   string
	ScriptPath string
	TimeoutSec int
	Chrome     WebFetchChromeOptions
}

BrowserToolOptions browser automation options.

func BrowserOptionsFromWebFetch

func BrowserOptionsFromWebFetch(fetch WebFetchOptions) BrowserToolOptions

BrowserOptionsFromWebFetch derives browser tool options from web_fetch config.

type CronService

type CronService interface {
	AddJob(name string, schedule cron.Schedule, payload cron.Payload) (*cron.Job, error)
	RemoveJob(id string) bool
	ListJobs() []*cron.Job
}

CronService 定时任务服务接口

type CronTool

type CronTool struct {
	BaseTool
	// contains filtered or unexported fields
}

CronTool 定时任务工具

func NewCronTool

func NewCronTool(service CronService) *CronTool

NewCronTool 创建定时任务工具

func (*CronTool) Execute

func (t *CronTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行定时任务操作

func (*CronTool) SetContext

func (t *CronTool) SetContext(channel, chatID string)

SetContext 设置当前上下文

type EditFileTool

type EditFileTool struct {
	BaseTool
}

EditFileTool 编辑文件工具(替换文本)

func NewEditFileTool

func NewEditFileTool() *EditFileTool

NewEditFileTool 创建编辑文件工具

func (*EditFileTool) Execute

func (t *EditFileTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行编辑文件

type ExecTool

type ExecTool struct {
	BaseTool
	WorkingDir          string
	Timeout             time.Duration
	RestrictToWorkspace bool
}

ExecTool Shell 执行工具

func NewExecTool

func NewExecTool(workingDir string, timeout int, restrictToWorkspace bool) *ExecTool

NewExecTool 创建 Shell 执行工具

func (*ExecTool) Description

func (t *ExecTool) Description() string

Description 返回工具描述

func (*ExecTool) Execute

func (t *ExecTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行 Shell 命令

func (*ExecTool) Name

func (t *ExecTool) Name() string

Name 返回工具名称

func (*ExecTool) Parameters

func (t *ExecTool) Parameters() map[string]interface{}

Parameters 返回参数定义

type ListDirTool

type ListDirTool struct {
	BaseTool
}

ListDirTool 列出目录工具

func NewListDirTool

func NewListDirTool() *ListDirTool

NewListDirTool 创建列出目录工具

func (*ListDirTool) Execute

func (t *ListDirTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行列出目录

type MCPConnector

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

MCPConnector 负责连接 MCP 服务器并将其工具注册为本地 Tool。

func NewMCPConnector

func NewMCPConnector(servers map[string]MCPServerOptions) *MCPConnector

NewMCPConnector 创建 MCP 连接器。

func (*MCPConnector) Close

func (c *MCPConnector) Close() error

Close 关闭所有已连接的 MCP 客户端。

func (*MCPConnector) Connect

func (c *MCPConnector) Connect(ctx context.Context, registry *Registry) error

Connect 连接所有 MCP 服务器,并注册它们暴露的工具。 即使部分服务器失败,其他服务器仍会继续连接。

func (*MCPConnector) RegisteredTools

func (c *MCPConnector) RegisteredTools() []string

RegisteredTools 返回已经注册到本地工具注册表中的 MCP 工具名列表。

type MCPServerOptions

type MCPServerOptions struct {
	Name    string
	Command string
	Args    []string
	Env     map[string]string
	URL     string
	Headers map[string]string
}

MCPServerOptions 是 MCP 服务器配置(兼容 Claude Desktop / Cursor 的 mcpServers 条目)。

type MessageCallback

type MessageCallback func(channel, chatID, content string) error

MessageCallback 消息发送回调函数类型

type MessageTool

type MessageTool struct {
	BaseTool
	// contains filtered or unexported fields
}

MessageTool 消息发送工具

func NewMessageTool

func NewMessageTool(callback MessageCallback) *MessageTool

NewMessageTool 创建消息发送工具

func (*MessageTool) Execute

func (t *MessageTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行消息发送

func (*MessageTool) SetContext

func (t *MessageTool) SetContext(channel, chatID string)

SetContext 设置当前上下文

type ReadFileTool

type ReadFileTool struct {
	BaseTool
}

ReadFileTool 读取文件工具

func NewReadFileTool

func NewReadFileTool() *ReadFileTool

NewReadFileTool 创建读取文件工具

func (*ReadFileTool) Execute

func (t *ReadFileTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行读取文件

type Registry

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

Registry 工具注册表

func NewRegistry

func NewRegistry() *Registry

NewRegistry 创建工具注册表

func (*Registry) Count

func (r *Registry) Count() int

Count 返回工具数量

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, params map[string]interface{}) (string, error)

Execute 执行工具

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get 获取工具

func (*Registry) GetDefinitions

func (r *Registry) GetDefinitions() []map[string]interface{}

GetDefinitions 获取所有工具定义(OpenAI 格式)

func (*Registry) List

func (r *Registry) List() []string

List 列出所有工具名称

func (*Registry) Register

func (r *Registry) Register(tool Tool) error

Register 注册工具

type SpawnCallback

type SpawnCallback func(ctx context.Context, request SpawnRequest) (SpawnResult, error)

SpawnCallback 子代理回调函数类型

type SpawnRequest

type SpawnRequest struct {
	Task             string
	Label            string
	Model            string
	SelectedSkills   []string
	EnabledSources   []string
	SessionKey       string
	NotifyParent     bool
	Channel          string
	ChatID           string
	ParentSessionKey string
}

SpawnRequest describes a background sub-session request.

type SpawnResult

type SpawnResult struct {
	SessionKey string `json:"sessionKey"`
	Message    string `json:"message,omitempty"`
}

SpawnResult contains sub-session execution metadata returned by callback.

type SpawnTask

type SpawnTask struct {
	ID         string
	Label      string
	Task       string
	Model      string
	Skills     []string
	Sources    []string
	SessionKey string
	StartTime  time.Time
	EndTime    *time.Time
	Status     string
	Result     string
	Error      string
}

SpawnTask 表示一个正在运行的后台任务

type SpawnTool

type SpawnTool struct {
	BaseTool
	// contains filtered or unexported fields
}

SpawnTool 子代理工具 - 用于后台任务执行

func NewSpawnTool

func NewSpawnTool(callback SpawnCallback) *SpawnTool

NewSpawnTool 创建子代理工具

func (*SpawnTool) Execute

func (t *SpawnTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行子代理任务

func (*SpawnTool) ListRunningTasks

func (t *SpawnTool) ListRunningTasks() []*SpawnTask

ListRunningTasks 列出正在运行的任务

func (*SpawnTool) SetContext

func (t *SpawnTool) SetContext(channel, chatID string)

SetContext 设置当前上下文

type TelegramDirectTool

type TelegramDirectTool struct {
	BaseTool
	// contains filtered or unexported fields
}

TelegramDirectTool Telegram 直接文件发送工具 这个工具直接调用 Telegram API,不通过 channel 架构

func NewTelegramDirectTool

func NewTelegramDirectTool(token, proxy string) *TelegramDirectTool

NewTelegramDirectTool 创建 Telegram 直接文件发送工具

func (*TelegramDirectTool) Execute

func (t *TelegramDirectTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行文件发送

func (*TelegramDirectTool) SetContext

func (t *TelegramDirectTool) SetContext(channel, chatID string)

SetContext 设置当前上下文

type TelegramFileCallback

type TelegramFileCallback func(channel, chatID, filePath, fileType, caption string) error

TelegramFileCallback Telegram 文件发送回调函数类型

type TelegramFileTool

type TelegramFileTool struct {
	BaseTool
	// contains filtered or unexported fields
}

TelegramFileTool Telegram 文件发送工具

func NewTelegramFileTool

func NewTelegramFileTool(callback TelegramFileCallback) *TelegramFileTool

NewTelegramFileTool 创建 Telegram 文件发送工具

func (*TelegramFileTool) Execute

func (t *TelegramFileTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行文件发送

func (*TelegramFileTool) SetContext

func (t *TelegramFileTool) SetContext(channel, chatID string)

SetContext 设置当前上下文

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() map[string]interface{}
	Execute(ctx context.Context, params map[string]interface{}) (string, error)
}

Tool 工具接口

type ToolCall

type ToolCall struct {
	ID        string                 `json:"id"`
	Name      string                 `json:"name"`
	Arguments map[string]interface{} `json:"arguments"`
}

ToolCall 工具调用

func ParseToolCalls

func ParseToolCalls(data []byte) ([]*ToolCall, error)

ParseToolCalls 从 JSON 解析工具调用

type WebFetchChromeOptions

type WebFetchChromeOptions struct {
	CDPEndpoint      string
	ProfileName      string
	UserDataDir      string
	Channel          string
	Headless         bool
	AutoStartCDP     bool
	TakeoverExisting bool
	HostUserDataDir  string
	LaunchTimeoutMs  int
}

WebFetchChromeOptions Chrome 抓取选项

type WebFetchOptions

type WebFetchOptions struct {
	Mode            string
	NodePath        string
	ScriptPath      string
	TimeoutSec      int
	UserAgent       string
	WaitUntil       string
	RenderWaitMs    int
	SmartWaitMs     int
	StableWaitMs    int
	WaitForSelector string
	WaitForText     string
	WaitForNoText   string
	Chrome          WebFetchChromeOptions
}

WebFetchOptions 网页抓取选项

type WebFetchTool

type WebFetchTool struct {
	BaseTool
	// contains filtered or unexported fields
}

WebFetchTool 网页抓取工具

func NewWebFetchTool

func NewWebFetchTool(options WebFetchOptions) *WebFetchTool

NewWebFetchTool 创建网页抓取工具

func (*WebFetchTool) Execute

func (t *WebFetchTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行网页抓取

type WebSearchTool

type WebSearchTool struct {
	BaseTool
	APIKey     string
	MaxResults int
}

WebSearchTool 网页搜索工具

func NewWebSearchTool

func NewWebSearchTool(apiKey string, maxResults int) *WebSearchTool

NewWebSearchTool 创建网页搜索工具

func (*WebSearchTool) Execute

func (t *WebSearchTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行网页搜索

type WriteFileTool

type WriteFileTool struct {
	BaseTool
}

WriteFileTool 写入文件工具

func NewWriteFileTool

func NewWriteFileTool() *WriteFileTool

NewWriteFileTool 创建写入文件工具

func (*WriteFileTool) Execute

func (t *WriteFileTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行写入文件

Jump to

Keyboard shortcuts

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