inproc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 13 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", brief 03 §3) and wires the call through the ToolPolicy reliability shell so the registered function gets production-resilient timeout + retry + validation for free (D-024).

Concurrent reuse (D-025): 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.

Index

Constants

This section is empty.

Variables

View Source
var ErrSchemaBuild = errors.New("inproc: failed to build JSON schema")

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

View Source
var ErrUnsupportedType = errors.New("inproc: unsupported type for tool registration")

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.

Functions

func DeriveSchema

func DeriveSchema(t reflect.Type) (schemaMap, error)

DeriveSchema converts a Go type into a JSON Schema object. Exported so the flow package can reuse it for its entry/exit types. Returns ErrUnsupportedType for shapes the deriver can't represent (interfaces, channels, function values, cyclic recursion).

Coverage:

  • bool → {"type": "boolean"}
  • int / int8…64 / uint / uint8…64 → {"type": "integer"}
  • float32 / float64 → {"type": "number"}
  • string → {"type": "string"}
  • []byte → {"type": "string", "contentEncoding": "base64"}
  • []T → {"type": "array", "items": Schema(T)}
  • map[string]T → {"type": "object", "additionalProperties": Schema(T)}
  • struct → {"type": "object", "properties": {...}, "required": [...]}
  • *T → Schema(T) with the property dropped from "required" at the parent level
  • time.Time → {"type": "string", "format": "date-time"}
  • json.RawMessage → {} (any-shaped; no constraint)

Struct fields use the `json:"name"` tag for property names; an `,omitempty` modifier removes the field from `required`. A `-` json tag skips the field entirely.

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 (D-025). 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