Documentation
¶
Overview ¶
Package runtime is the invoke sequence shared by the CLI, MCP, and the library.
Index ¶
- Constants
- Variables
- func FromStrings(in map[string]string) map[string]any
- func IdempotencyFrom(ctx context.Context) string
- func WithIdempotency(ctx context.Context, key string) context.Context
- func WithProjection(ctx context.Context, p Projection) context.Context
- type Drafter
- type Executor
- type HTTPRequest
- type InvokeGate
- type Preview
- type Projection
- type Request
- type Result
- type Runtime
Constants ¶
const ( StatusOK = "ok" StatusError = "error" StatusDenied = "denied" StatusLimited = "limited" StatusConfirmationRequired = string(policy.DecisionConfirmationNeeded) CodeMissingAuth = "missing_auth" CodeInvalidBody = "invalid_body" CodeMissingParam = "missing_param" CodeNotCallable = "not_callable" CodeInvokeLimited = "invoke_limited" WhyHeld = "held until you approve" WhyMissingAuth = "missing auth" )
Variables ¶
var ErrInvalidApproval = errors.New("invalid approval")
ErrInvalidApproval is an approved id that does not match this caller, operation, and parameters.
Functions ¶
func FromStrings ¶
FromStrings adapts a string map at a boundary that does not carry JSON types.
func IdempotencyFrom ¶ added in v0.1.1
IdempotencyFrom is the key set by WithIdempotency, or empty.
func WithIdempotency ¶ added in v0.1.1
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
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"`
Why string `json:"Why,omitempty"`
Caller string `json:"Caller,omitempty"`
HTTP bool `json:"HTTP"`
Sent bool `json:"Sent"`
}
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
JSON jsonopts.Set
// contains filtered or unexported fields
}
Runtime resolves, validates, checks policy, verifies approval, executes, shapes, and records. The owner constructs Gate so a second Runtime can share one limiter. A nil Gate is created on first use.