runtime

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package runtime is the invoke sequence shared by the CLI, MCP, and the library.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidApproval = errors.New("invalid approval")

ErrInvalidApproval is an approved id that does not match this caller, operation, and parameters.

Functions

func FromStrings

func FromStrings(in map[string]string) map[string]any

FromStrings adapts a string map at a boundary that does not carry JSON types.

func IdempotencyFrom added in v0.1.1

func IdempotencyFrom(ctx context.Context) string

IdempotencyFrom is the key set by WithIdempotency, or empty.

func WithIdempotency added in v0.1.1

func WithIdempotency(ctx context.Context, key string) context.Context

WithIdempotency carries the invoke's idempotency key to the Executor.

func WithProjection added in v0.1.1

func WithProjection(ctx context.Context, p Projection) context.Context

WithProjection carries the invoke's fields and page to the Executor. They override the Executor's own list.

Types

type Drafter added in v0.1.1

type Drafter interface {
	Draft(ctx context.Context, op *catalog.Operation, params map[string]string) (HTTPRequest, error)
}

Drafter is an Executor that can show Preview the request, before credentials, with secret values removed.

type Executor

type Executor interface {
	InvokeHTTPResult(ctx context.Context, op *catalog.Operation, params map[string]string) (result.HTTPResult, error)
}

Executor performs the HTTP call. It does not apply policy.

type HTTPRequest

type HTTPRequest struct {
	Method  string            `json:"method,omitempty"`
	URL     string            `json:"url,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    string            `json:"body,omitempty"`
}

HTTPRequest is the call that would be sent, with secret values removed.

type InvokeGate

type InvokeGate struct {
	Per    int
	Window time.Duration
	Max    int
	// contains filtered or unexported fields
}

InvokeGate is the per-runtime invoke cap. Zero Per, Window, and Max use 16 calls per second and 256 callers.

type Preview

type Preview struct {
	OperationID      string      `json:"operation_id,omitempty"`
	Method           string      `json:"method,omitempty"`
	Path             string      `json:"path,omitempty"`
	Request          HTTPRequest `json:"request"`
	Errors           []string    `json:"errors,omitempty"`
	Decision         string      `json:"decision,omitempty"`
	ApprovalRequired bool        `json:"approval_required"`
}

Preview is resolve, validate, and policy with no token fetch and no upstream HTTP.

type Projection added in v0.1.1

type Projection struct {
	Fields []string
	Offset int
	Limit  int
}

Projection names the response fields and the page an invoke asks for. An empty Fields list leaves the body unchanged.

func ProjectionFrom added in v0.1.1

func ProjectionFrom(ctx context.Context) (Projection, bool)

ProjectionFrom reports a projection set by WithProjection.

type Request

type Request struct {
	Operation   string
	Arguments   map[string]any
	Caller      string
	Approval    string
	Idempotency string
	Fields      []string
	Offset      int
	Limit       int
}

Request is one invoke. Caller is the caller or tenant. Arguments stay typed until HTTP serialization. Fields names the response fields to return. An empty list leaves the body unchanged.

type Result

type Result struct {
	Status      string       `json:"Status"`
	ApprovalID  string       `json:"ApprovalID"`
	OperationID string       `json:"OperationID"`
	HTTPStatus  int          `json:"HTTPStatus"`
	Body        string       `json:"Body"`
	Code        string       `json:"Code"`
	Retryable   bool         `json:"Retryable"`
	RetryAfter  string       `json:"RetryAfter,omitempty"`
	Error       string       `json:"Error"`
	Truncated   bool         `json:"Truncated"`
	Page        *result.Page `json:"Page"`
}

Result is the shaped outcome of one invoke.

type Runtime

type Runtime struct {
	Catalog *catalog.Catalog
	Policy  policy.Hook
	Base    policy.Hook
	State   *policy.State
	Exec    Executor
	Notify  policy.Notifier
	Gate    *InvokeGate
	// contains filtered or unexported fields
}

Runtime resolves, validates, checks policy, verifies approval, executes, shapes, and records. The owner constructs Gate so copies share one limiter. A nil Gate is created on first use.

func (*Runtime) Invoke

func (rt *Runtime) Invoke(ctx context.Context, req Request) (Result, error)

Invoke runs one operation. MCP uses this directly. It does not run the agent loop.

func (*Runtime) Preview

func (rt *Runtime) Preview(ctx context.Context, req Request) (Preview, error)

Preview resolves, validates, and checks policy. It does not fetch a token or call upstream.

Jump to

Keyboard shortcuts

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