tools

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAuthError

func IsAuthError(err error) bool

func NewPersistentRepo

func NewPersistentRepo(
	localTools map[string]taskengine.ToolsRepo,
	dbInstance libdb.DBManager,
	httpClient *http.Client,
	messenger libbus.Messenger,
	tracker libtracker.ActivityTracker,
) taskengine.ToolsRepo

func NewSimpleProvider

func NewSimpleProvider(tools map[string]taskengine.ToolsRepo) taskengine.ToolsRepo

func PerformAuthFlow

func PerformAuthFlow(ctx context.Context, tools *runtimetypes.RemoteTools, client *http.Client) (map[string]ParamArg, error)

Types

type ArgLocation

type ArgLocation int
const (
	ArgLocationQuery ArgLocation = iota
	ArgLocationHeader
	ArgLocationPath
	ArgLocationBody
)

type AuthError

type AuthError struct {
	StatusCode int
	Body       string
}

AuthError indicates a 401 or 403 status was returned.

func (*AuthError) Error

func (e *AuthError) Error() string

type MockToolsRepo

type MockToolsRepo struct {
	Calls           []ToolsCallRecord
	ResponseMap     map[string]ToolsResponse
	DefaultResponse ToolsResponse
	ErrorSequence   []error
	// contains filtered or unexported fields
}

MockToolsRepo is a mock implementation of the ToolsRepo interface.

func NewMockToolsRegistry

func NewMockToolsRegistry() *MockToolsRepo

NewMockToolsRegistry returns a new instance of MockToolsRepo.

func (*MockToolsRepo) CallCount

func (m *MockToolsRepo) CallCount() int

CallCount returns the number of times Exec was called.

func (*MockToolsRepo) Exec

func (m *MockToolsRepo) Exec(
	ctx context.Context,
	startingTime time.Time,
	input any,
	debug bool,
	args *taskengine.ToolsCall,
) (any, taskengine.DataType, error)

Exec simulates execution of a tools call.

func (*MockToolsRepo) GetSchemasForSupportedTools

func (m *MockToolsRepo) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

GetSchemasForSupportedTools returns OpenAPI schemas for all mocked tools.

func (*MockToolsRepo) GetToolsForToolsByName

func (m *MockToolsRepo) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*MockToolsRepo) LastCall

func (m *MockToolsRepo) LastCall() *ToolsCallRecord

LastCall returns the most recent tools call.

func (*MockToolsRepo) Reset

func (m *MockToolsRepo) Reset()

Reset clears all recorded calls and resets counters.

func (*MockToolsRepo) Supports

func (m *MockToolsRepo) Supports(ctx context.Context) ([]string, error)

func (*MockToolsRepo) WithErrorSequence

func (m *MockToolsRepo) WithErrorSequence(errors ...error) *MockToolsRepo

WithErrorSequence sets a sequence of errors to return.

func (*MockToolsRepo) WithResponse

func (m *MockToolsRepo) WithResponse(toolsType string, response ToolsResponse) *MockToolsRepo

WithResponse configures a response for a specific tools type.

type MultiRepo

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

func NewMultiRepo

func NewMultiRepo(repos ...taskengine.ToolsRepo) *MultiRepo

func (*MultiRepo) Exec

func (m *MultiRepo) Exec(ctx context.Context, startingTime time.Time, input any, debug bool, args *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*MultiRepo) GetSchemasForSupportedTools

func (m *MultiRepo) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*MultiRepo) GetToolsForToolsByName

func (m *MultiRepo) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*MultiRepo) Supports

func (m *MultiRepo) Supports(ctx context.Context) ([]string, error)

type OpenAPIToolProtocol

type OpenAPIToolProtocol struct {
	// SpecSource, when non-empty, is the spec location instead of
	// endpointURL+"/openapi.json": an http(s) URL, or file:///abs/path.
	SpecSource string
}

OpenAPIToolProtocol implements ToolProtocol using OpenAPI v3 specs.

func (*OpenAPIToolProtocol) ExecuteTool

func (p *OpenAPIToolProtocol) ExecuteTool(
	ctx context.Context,
	endpointURL string,
	httpClient *http.Client,
	injectParams map[string]ParamArg,
	toolCall taskengine.ToolCall,
) (interface{}, taskengine.DataType, error)

ExecuteTool performs a tool call by making a corresponding HTTP request.

func (*OpenAPIToolProtocol) FetchSchema

func (p *OpenAPIToolProtocol) FetchSchema(ctx context.Context, endpointURL string, httpClient *http.Client) (*openapi3.T, error)

func (*OpenAPIToolProtocol) FetchTools

func (p *OpenAPIToolProtocol) FetchTools(ctx context.Context, endpointURL string, injectParams map[string]ParamArg, httpClient *http.Client) ([]taskengine.Tool, error)

type ParamArg

type ParamArg struct {
	Name  string
	Value string
	In    ArgLocation
}

type PersistentRepo

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

PersistentRepo implements taskengine.ToolsRepo using a single OpenAPI-based protocol.

func (*PersistentRepo) Exec

func (p *PersistentRepo) Exec(
	ctx context.Context,
	startingTime time.Time,
	input any,
	debug bool,
	args *taskengine.ToolsCall,
) (any, taskengine.DataType, error)

Exec executes a tools by name.

func (*PersistentRepo) GetSchemasForSupportedTools

func (p *PersistentRepo) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

GetSchemasForSupportedTools returns OpenAPI schemas for all remote tools.

func (*PersistentRepo) GetToolsForToolsByName

func (p *PersistentRepo) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

GetToolsForToolsByName returns the list of tools exposed by the named tools.

func (*PersistentRepo) Precheck added in v1.0.0

func (p *PersistentRepo) Precheck(ctx context.Context, input any, args *taskengine.ToolsCall) error

Precheck forwards to the local tools registered under args.Name; a remote provider, or a local one without the seam, raises no static objection.

func (*PersistentRepo) Supports

func (p *PersistentRepo) Supports(ctx context.Context) ([]string, error)

Supports returns a list of all tools names (local + MCP + remote).

type SimpleRepo

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

SimpleRepo holds a map of locally registered tools.

func (*SimpleRepo) Exec

func (m *SimpleRepo) Exec(
	ctx context.Context,
	startingTime time.Time,
	input any,
	debug bool,
	args *taskengine.ToolsCall,
) (any, taskengine.DataType, error)

func (*SimpleRepo) GetSchemasForSupportedTools

func (m *SimpleRepo) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

GetSchemasForSupportedTools aggregates the schemas from all registered tools.

func (*SimpleRepo) GetToolsForToolsByName

func (m *SimpleRepo) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*SimpleRepo) Supports

func (m *SimpleRepo) Supports(ctx context.Context) ([]string, error)

Supports returns a list of all tools names registered in the internal map.

type ToolProtocol

type ToolProtocol interface {
	FetchSchema(ctx context.Context, endpointURL string, httpClient *http.Client) (*openapi3.T, error)
	FetchTools(ctx context.Context, endpointURL string, injectParams map[string]ParamArg, httpClient *http.Client) ([]taskengine.Tool, error)
	ExecuteTool(
		ctx context.Context,
		endpointURL string,
		httpClient *http.Client,
		injectParams map[string]ParamArg,
		toolCall taskengine.ToolCall,
	) (interface{}, taskengine.DataType, error)
}

ToolProtocol discovers and executes tool calls against a remote service exposing tools via a standardized protocol (e.g. OpenAPI).

type ToolsCallRecord

type ToolsCallRecord struct {
	Args  taskengine.ToolsCall
	Input any
}

ToolsCallRecord stores the arguments passed to a mocked tools call.

type ToolsResponse

type ToolsResponse struct {
	Output any
	Schema *openapi3.T
}

ToolsResponse is a mocked tools call's direct output and optional OpenAPI schema.

Jump to

Keyboard shortcuts

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