inproc

package
v1.25.0 Latest Latest
Warning

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

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

Documentation

Overview

Package inproc is Harbor's in-process tool driver. Operators register Go functions as Tools via RegisterFunc; the driver derives ArgsSchema / OutSchema from the function's input / output types via reflection (RFC §6.4 "Tool authors write a function and register it") and wires the call through the ToolPolicy reliability shell so the registered function gets production-resilient timeout + retry + validation for free. The derivation itself lives in the neutral internal/tools/schema package (§13) — this driver is one of its two consumers, alongside the typed embed binding (internal/runtime/assemble.RunTyped).

A registered function may take content BY REFERENCE: declare a field of type internal/tools/artifactref.Ref and the derived schema renders it to the model as a plain artifact-id string, while the runtime resolves that id at dispatch and hands the function the stored bytes. The model authors an id and never sees content, and the resolved value is dispatch-local — it does not reach the argument JSON, the trajectory, an event payload or a log. See the artifactref package doc for the invariant and the mechanisms that hold it.

Concurrent reuse: the driver itself is stateless — every RegisterFunc call builds a fresh ToolDescriptor and registers it in the catalog. The descriptor's Invoke closure captures the caller's `fn` (which the caller guarantees is safe for concurrent invocation); no mutable state lives in the driver. Whether the input type declares an artifact reference is derived once at registration and captured immutably.

Index

Constants

This section is empty.

Variables

View Source
var ErrSchemaBuild = schema.ErrSchemaBuild

ErrSchemaBuild — the schema compiler choked on the derived JSON Schema. Indicates a deriver bug; the operator should report it. Re-exported alias of schema.ErrSchemaBuild.

View Source
var ErrUnsupportedType = schema.ErrUnsupportedType

ErrUnsupportedType — RegisterFunc rejected the input/output type at registration time because the reflection-based schema deriver cannot represent it (interfaces, channels, function-typed fields, cyclic structures). The error message names the offending Go field so the operator can fix it. Wraps via fmt.Errorf("%w: ...") pattern. Re-exported alias of schema.ErrUnsupportedType — the derivation now lives in the neutral internal/tools/schema package (§13; both this driver and RunTyped consume it), but the driver keeps its own sentinel name so existing callers' errors.Is checks are unaffected.

Functions

func RegisterFunc

func RegisterFunc[I any, O any](
	cat tools.ToolCatalog,
	name string,
	fn func(ctx context.Context, in I) (O, error),
	opts ...tools.DescriptorOption,
) error

RegisterFunc registers a Go function as a Tool. Input + output schemas are derived from the type parameters I and O via reflection.

The function `fn` must be safe to invoke concurrently. The driver wraps it in a ToolPolicy shell — timeout + retry + validation — so a plain registration is production-resilient.

`opts` configure the descriptor (policy, description, scopes, tags, examples). See DescriptorOption in the parent package for the full surface.

Example:

type WeatherArgs struct {
    City string `json:"city"`
}
type WeatherOut struct {
    TempC float64 `json:"temp_c"`
    Summary string `json:"summary"`
}

err := inproc.RegisterFunc[WeatherArgs, WeatherOut](
    cat,
    "weather.lookup",
    func(ctx context.Context, in WeatherArgs) (WeatherOut, error) { ... },
    tools.WithDescription("Look up current weather by city name."),
    tools.WithAuthScopes("weather:read"),
    tools.WithSideEffect(tools.SideEffectExternal))

Types

This section is empty.

Jump to

Keyboard shortcuts

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