gateway

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Overview

Package gateway decides whether an AI tool call may run, needs approval, or is denied, and audits every decision. It must not import core.

Index

Constants

View Source
const (
	SourceWit    = "wit"
	SourceSkill  = "skill"
	SourcePlugin = "plugin"
	SourceMCP    = "mcp"
	SourceHook   = "hook"
)
View Source
const (
	Allow   = ai.Allow
	Approve = ai.Approve
	Deny    = ai.Deny
)

Variables

This section is empty.

Functions

func Audit

func Audit(e Entry, redact func(string) string) sqlite.Statement

Audit is Record's audit_log row as a statement, for a caller that writes it in the same transaction as the event, such as an approval executing. Every string it stores goes through redact (nil: none).

func Host

func Host(d string) string

Host reduces a destination to its host[:port]: a URL loses its scheme, userinfo, path and query; "mcp:<server>" style labels stay as they are.

Types

type Call

type Call struct {
	Source, Extension, Tool, CallID string
	Write                           bool
	Egress                          []string
	TargetKind                      string
	TargetID                        int64
}

Call is one tool call. Egress lists the destinations of a network tool. Extension is the plugin name or MCP server ID of an extension's tool.

type Decision

type Decision = ai.Decision

type Entry

type Entry struct {
	Source, Extension, Tool, CallID string
	TargetKind                      string
	TargetID                        int64
	Destinations                    []string
	Decision, Reason                string
}

Entry is one audit_log row. Destinations are reduced to host[:port] (see Host); no URL, query, credential or body is ever stored.

type Gateway

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

func New

func New(db *store.DB, redact func(string) string) *Gateway

New is a gateway writing to db; redact (nil: none) cleans every string an audit row stores, such as secret values in a destination.

func (*Gateway) Check

func (g *Gateway) Check(ctx context.Context, scope *Scope, c Call) (Decision, error)

Check decides c under scope and writes one structured audit_log row. If the row cannot be written the call is denied. A nil scope has read no mail.

func (*Gateway) Record

func (g *Gateway) Record(ctx context.Context, e Entry) error

Record writes one audit_log row, such as for a host-initiated event that is not a tool call, like a skill run (decision "run").

func (*Gateway) Wrap

func (g *Gateway) Wrap(scope *Scope, c Call, t ai.ToolSpec, egress func(*Scope) []string) ai.ToolSpec

Wrap routes t through the gateway as c (Source, Extension, Write); every tool handed to ai.Run goes through it. Its Gate decides every call when it happens, with egress(scope) as its destinations: a scope tainted mid-run makes later egress calls interrupt for approval. The gateway decides first and a deny wins; then t's own NeedsApproval or Gate can only make it stricter. The final decision is audited with the call ID.

type Scope

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

Scope is one run's data provenance. The Service rebuilds it from runs.snapshot when a run resumes. Safe for concurrent use.

func (*Scope) MarkReadMail

func (s *Scope) MarkReadMail()

MarkReadMail records that mail content entered this run.

func (*Scope) ReadMail

func (s *Scope) ReadMail() bool

Jump to

Keyboard shortcuts

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