bridge

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BashRuntime

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

BashRuntime Bash 运行时

func NewBashRuntime

func NewBashRuntime(config *RuntimeConfig) *BashRuntime

NewBashRuntime 创建 Bash 运行时

func (*BashRuntime) Execute

func (r *BashRuntime) Execute(ctx context.Context, code string, input map[string]interface{}) (*ExecutionResult, error)

func (*BashRuntime) IsAvailable

func (r *BashRuntime) IsAvailable() bool

func (*BashRuntime) Language

func (r *BashRuntime) Language() Language

type BatchCallResult

type BatchCallResult struct {
	Results   []*CallToolResult `json:"results"`
	Succeeded int               `json:"succeeded"`
	Failed    int               `json:"failed"`
}

BatchCallResult 批量调用结果

type CallToolInput

type CallToolInput struct {
	Name  string                 `json:"name"`
	Input map[string]interface{} `json:"input"`
}

CallToolInput 工具调用输入

type CallToolResult

type CallToolResult struct {
	Name    string      `json:"name"`
	Success bool        `json:"success"`
	Result  interface{} `json:"result,omitempty"`
	Error   string      `json:"error,omitempty"`
}

CallToolResult 工具调用结果

type ChainResult

type ChainResult struct {
	Steps       []*CallToolResult `json:"steps"`
	FinalResult interface{}       `json:"final_result"`
	Success     bool              `json:"success"`
	Error       string            `json:"error,omitempty"`
}

ChainResult 链执行结果

type ChainStep

type ChainStep struct {
	Name  string                 `json:"name"`
	Input map[string]interface{} `json:"input"`
	// InputMapper 可选:将前一步结果映射到当前输入
	InputMapper func(prevResult interface{}) map[string]interface{} `json:"-"`
}

ChainStep 链中的一步

type CodeRuntime

type CodeRuntime interface {
	// Execute 执行代码
	Execute(ctx context.Context, code string, input map[string]interface{}) (*ExecutionResult, error)
	// Language 返回支持的语言
	Language() Language
	// IsAvailable 检查运行时是否可用
	IsAvailable() bool
}

CodeRuntime 代码运行时接口

type ExecutionResult

type ExecutionResult struct {
	Success  bool        `json:"success"`
	Output   interface{} `json:"output,omitempty"`
	Stdout   string      `json:"stdout,omitempty"`
	Stderr   string      `json:"stderr,omitempty"`
	Error    string      `json:"error,omitempty"`
	ExitCode int         `json:"exit_code"`
	Duration int64       `json:"duration_ms"`
}

ExecutionResult 代码执行结果

type Language

type Language string

Language 支持的语言类型

const (
	LangPython Language = "python"
	LangNodeJS Language = "nodejs"
	LangBash   Language = "bash"
)

func DetectLanguage

func DetectLanguage(filename string) Language

DetectLanguage 根据文件扩展名检测语言

type NodeJSRuntime

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

NodeJSRuntime Node.js 运行时

func NewNodeJSRuntime

func NewNodeJSRuntime(config *RuntimeConfig) *NodeJSRuntime

NewNodeJSRuntime 创建 Node.js 运行时

func (*NodeJSRuntime) Execute

func (r *NodeJSRuntime) Execute(ctx context.Context, code string, input map[string]interface{}) (*ExecutionResult, error)

func (*NodeJSRuntime) IsAvailable

func (r *NodeJSRuntime) IsAvailable() bool

func (*NodeJSRuntime) Language

func (r *NodeJSRuntime) Language() Language

type PythonRuntime

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

PythonRuntime Python 运行时

func NewPythonRuntime

func NewPythonRuntime(config *RuntimeConfig) *PythonRuntime

NewPythonRuntime 创建 Python 运行时

func (*PythonRuntime) Execute

func (r *PythonRuntime) Execute(ctx context.Context, code string, input map[string]interface{}) (*ExecutionResult, error)

func (*PythonRuntime) IsAvailable

func (r *PythonRuntime) IsAvailable() bool

func (*PythonRuntime) Language

func (r *PythonRuntime) Language() Language

type RuntimeConfig

type RuntimeConfig struct {
	Timeout   time.Duration
	WorkDir   string
	Env       map[string]string
	MaxOutput int // 最大输出字节数
}

RuntimeConfig 运行时配置

func DefaultRuntimeConfig

func DefaultRuntimeConfig() *RuntimeConfig

DefaultRuntimeConfig 默认配置

type RuntimeManager

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

RuntimeManager 运行时管理器

func NewRuntimeManager

func NewRuntimeManager(config *RuntimeConfig) *RuntimeManager

NewRuntimeManager 创建运行时管理器

func (*RuntimeManager) AvailableLanguages

func (m *RuntimeManager) AvailableLanguages() []Language

AvailableLanguages 返回可用的语言列表

func (*RuntimeManager) Execute

func (m *RuntimeManager) Execute(ctx context.Context, lang Language, code string, input map[string]interface{}) (*ExecutionResult, error)

Execute 执行代码

func (*RuntimeManager) GetRuntime

func (m *RuntimeManager) GetRuntime(lang Language) (CodeRuntime, bool)

GetRuntime 获取指定语言的运行时

type ToolBridge

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

ToolBridge 工具桥接器 提供统一的工具调用接口,支持程序化调用和批量执行

func NewToolBridge

func NewToolBridge(registry *tools.Registry) *ToolBridge

NewToolBridge 创建工具桥接器

func (*ToolBridge) CallTool

func (b *ToolBridge) CallTool(ctx context.Context, name string, input map[string]interface{}, tc *tools.ToolContext) (*CallToolResult, error)

CallTool 调用单个工具

func (*ToolBridge) CallToolJSON

func (b *ToolBridge) CallToolJSON(ctx context.Context, name string, inputJSON string, tc *tools.ToolContext) (*CallToolResult, error)

CallToolJSON 使用 JSON 字符串调用工具

func (*ToolBridge) CallToolsBatch

func (b *ToolBridge) CallToolsBatch(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult

CallToolsBatch 批量调用工具(顺序执行)

func (*ToolBridge) CallToolsParallel

func (b *ToolBridge) CallToolsParallel(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult

CallToolsParallel 并行调用工具

func (*ToolBridge) GetTool

func (b *ToolBridge) GetTool(name string) (tools.Tool, error)

GetTool 获取或创建工具实例

func (*ToolBridge) GetToolSchema

func (b *ToolBridge) GetToolSchema(name string) (map[string]interface{}, error)

GetToolSchema 获取工具的 schema

func (*ToolBridge) ListAvailableTools

func (b *ToolBridge) ListAvailableTools() []string

ListAvailableTools 列出所有可用工具

type ToolChain

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

ToolChain 工具链 - 按顺序执行一系列工具,前一个的输出可作为后一个的输入

func NewToolChain

func NewToolChain(bridge *ToolBridge) *ToolChain

NewToolChain 创建工具链

func (*ToolChain) AddStep

func (c *ToolChain) AddStep(step ChainStep) *ToolChain

AddStep 添加步骤

func (*ToolChain) Execute

func (c *ToolChain) Execute(ctx context.Context, tc *tools.ToolContext) *ChainResult

Execute 执行工具链

Jump to

Keyboard shortcuts

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