tools

package
v0.28.0 Latest Latest
Warning

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

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

Documentation

Overview

internal/tools/multi_repo.go

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 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 using the new simplified signature.

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 using the new simplified ToolsResponse.

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 string // optional; set by remoteprovider when RemoteTools.SpecURL is non-empty
}

OpenAPIToolProtocol implements ToolProtocol using OpenAPI v3 specs. SpecSource, when non-empty, is used as the spec location instead of endpointURL+"/openapi.json". Supported formats:

  • https://... or http://... — fetched over HTTP
  • file:///abs/path — read from local filesystem

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) 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 defines the methods required to interact with a remote service that exposes tools via a standardized protocol (e.g., OpenAPI). It is responsible for discovering available tools and executing tool calls. ToolProtocol defines the interface for interacting with remote tools via OpenAPI.

type ToolsCallRecord

type ToolsCallRecord struct {
	Args  taskengine.ToolsCall
	Input any
}

ToolsCallRecord now only stores the arguments passed to the tools.

type ToolsResponse

type ToolsResponse struct {
	Output any
	Schema *openapi3.T // Updated to match interface
}

ToolsResponse is simplified to only contain the direct output and optional OpenAPI schema.

Jump to

Keyboard shortcuts

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