ai

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ai adds optional AI explanations through the Vercel AI Gateway's OpenAI-compatible API. It is off unless configured. Findings are redacted before anything leaves the process: evidence bodies and payloads are never sent, and hosts, emails, IPs, query strings and token-like values are masked in the text that is.

Index

Constants

View Source
const (
	DefaultBaseURL = "https://ai-gateway.vercel.sh/v1"
	DefaultModel   = "anthropic/claude-sonnet-5.5"
	// APIKeyEnv is the Gateway's standard environment variable.
	APIKeyEnv = "AI_GATEWAY_API_KEY"
)

Defaults for the Vercel AI Gateway (OpenAI-compatible Chat Completions).

Variables

View Source
var ErrDisabled = errors.New("ai: not configured (set ai.enabled and AI_GATEWAY_API_KEY)")

ErrDisabled is returned when AI is not configured.

Functions

func Text

func Text(s, host string) string

Text masks sensitive values in free text. host, when non-empty, is replaced everywhere it appears.

Types

type Answer

type Answer struct {
	Text  string `json:"text"`
	Model string `json:"model"`
	Sent  any    `json:"sent"`
}

Answer is a model reply plus the exact redacted data that was sent, so users can see what left the process.

type Client

type Client struct {
	BaseURL string
	APIKey  string
	Model   string
	HTTP    *http.Client
}

Client calls a model through the Vercel AI Gateway.

func (*Client) Enabled

func (c *Client) Enabled() bool

Enabled reports whether the client can make calls.

func (*Client) Explain

func (c *Client) Explain(ctx context.Context, f core.Finding, stacks []string) (Answer, error)

Explain describes one finding in context and suggests how to fix it for the detected stacks.

func (*Client) Summarize

func (c *Client) Summarize(ctx context.Context, scans []core.ScanResult, opts scoring.Options) (Answer, error)

Summarize writes a short, non-technical summary of the latest scans.

type RedactedFinding

type RedactedFinding struct {
	CheckID    string   `json:"check_id"`
	Title      string   `json:"title"`
	Category   string   `json:"category"`
	Severity   string   `json:"severity"`
	Confidence string   `json:"confidence"`
	AssetKind  string   `json:"asset_kind"`
	Asset      string   `json:"asset"` // host masked, query dropped
	CWE        []string `json:"cwe,omitempty"`
	OWASP      []string `json:"owasp,omitempty"`
	What       string   `json:"what,omitempty"`
	Why        string   `json:"why,omitempty"`
	FixStacks  []string `json:"fix_stacks,omitempty"`
	Effort     string   `json:"effort,omitempty"`
}

RedactedFinding is everything about a finding that may be sent to a model.

func Finding

func Finding(f core.Finding) RedactedFinding

Finding builds the redacted view of a finding. Evidence (request, response, matched payload, config lines) is deliberately omitted.

type TargetSummary

type TargetSummary struct {
	Target      string            `json:"target"` // the configured target name, not its URL
	Environment string            `json:"environment"`
	Grade       string            `json:"grade"`
	Score       float64           `json:"score"`
	Open        map[string]int    `json:"open_by_severity"`
	Caps        []string          `json:"grade_caps,omitempty"`
	TopFixes    []RedactedFinding `json:"top_fixes,omitempty"`
}

TargetSummary is the redacted per-target input to a stakeholder summary.

Jump to

Keyboard shortcuts

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