hooks

package
v0.0.74 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPersistentRepo

func NewPersistentRepo(
	localHooks map[string]taskengine.HookRepo,
	dbInstance libdb.DBManager,
	httpClient *http.Client,
) taskengine.HookRepo

func NewSimpleProvider

func NewSimpleProvider(hooks map[string]taskengine.HookRepo) taskengine.HookRepo

Types

type ArgLocation added in v0.0.74

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

type HookCallRecord

type HookCallRecord struct {
	Args  taskengine.HookCall
	Input any
}

HookCallRecord now only stores the arguments passed to the hook.

type HookResponse

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

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

type MockHookRepo

type MockHookRepo struct {
	Calls           []HookCallRecord
	ResponseMap     map[string]HookResponse
	DefaultResponse HookResponse
	ErrorSequence   []error
	// contains filtered or unexported fields
}

MockHookRepo is a mock implementation of the HookRepo interface.

func NewMockHookRegistry

func NewMockHookRegistry() *MockHookRepo

NewMockHookRegistry returns a new instance of MockHookRepo.

func (*MockHookRepo) CallCount

func (m *MockHookRepo) CallCount() int

CallCount returns number of times Exec was called

func (*MockHookRepo) Exec

func (m *MockHookRepo) Exec(
	ctx context.Context,
	startingTime time.Time,
	input any,
	args *taskengine.HookCall,
) (any, taskengine.DataType, error)

Exec simulates execution of a hook call using the new simplified signature.

func (*MockHookRepo) GetSchemasForSupportedHooks added in v0.0.74

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

GetSchemasForSupportedHooks returns OpenAPI schemas for all mocked hooks.

func (*MockHookRepo) GetToolsForHookByName added in v0.0.74

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

func (*MockHookRepo) LastCall

func (m *MockHookRepo) LastCall() *HookCallRecord

LastCall returns the most recent hook call

func (*MockHookRepo) Reset

func (m *MockHookRepo) Reset()

Reset clears all recorded calls and resets counters

func (*MockHookRepo) Supports

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

func (*MockHookRepo) WithErrorSequence

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

WithErrorSequence sets a sequence of errors to return

func (*MockHookRepo) WithResponse

func (m *MockHookRepo) WithResponse(hookType string, response HookResponse) *MockHookRepo

WithResponse configures a response for a specific hook type using the new simplified HookResponse.

type OpenAPIToolProtocol added in v0.0.74

type OpenAPIToolProtocol struct{}

func (*OpenAPIToolProtocol) ExecuteTool added in v0.0.74

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 added in v0.0.74

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

func (*OpenAPIToolProtocol) FetchTools added in v0.0.74

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

type ParamArg added in v0.0.74

type ParamArg struct {
	Name  string
	Value string
	In    ArgLocation
}

type PersistentRepo

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

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

func (*PersistentRepo) Exec

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

Exec executes a hook by name.

func (*PersistentRepo) GetSchemasForSupportedHooks added in v0.0.74

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

GetSchemasForSupportedHooks returns OpenAPI schemas for all remote hooks.

func (*PersistentRepo) GetToolsForHookByName added in v0.0.74

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

GetToolsForHookByName returns the list of tools exposed by the remote hook.

func (*PersistentRepo) Supports

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

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

type SimpleRepo

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

SimpleRepo holds a map of locally registered hooks.

func (*SimpleRepo) Exec

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

func (*SimpleRepo) GetSchemasForSupportedHooks added in v0.0.74

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

GetSchemasForSupportedHooks aggregates the schemas from all registered hooks.

func (*SimpleRepo) GetToolsForHookByName added in v0.0.74

func (m *SimpleRepo) GetToolsForHookByName(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 hook names registered in the internal map.

type ToolProtocol added in v0.0.74

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.

Jump to

Keyboard shortcuts

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