gateway

package
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gateway provides client utilities for nself-ai-gateway (port 3761).

Purpose: Wrap HTTP calls to nself-ai-gateway, nself-ai-cc, and nself-ai-mcp

for use in CLI gateway commands.

Inputs: Port constants from internal/ports; JWT from internal/auth. Outputs: Typed structs for keys, quota, routes, service health. Constraints: Key material never returned in any output type. SPORT: F02 — nself gateway command group.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKey

func AddKey(ctx context.Context, token, provider, label, keyMaterial string) (string, error)

AddKey registers a new provider key with nself-ai-gateway. keyMaterial is write-only — only sent to the gateway, never stored locally.

func RemoveKey

func RemoveKey(ctx context.Context, token, id string) error

RemoveKey deletes a key by ID from nself-ai-gateway.

Types

type KeyInfo

type KeyInfo struct {
	ID        string    `json:"id"`
	Provider  string    `json:"provider"`
	Label     string    `json:"label"`
	IsActive  bool      `json:"is_active"`
	CreatedAt time.Time `json:"created_at"`
}

KeyInfo is the public representation of a gateway key. Key material is intentionally absent — never returned from the gateway list endpoint.

func ListKeys

func ListKeys(ctx context.Context, token string) ([]KeyInfo, error)

ListKeys returns all keys from nself-ai-gateway. Key material is not included.

type QuotaRow

type QuotaRow struct {
	Provider string `json:"provider"`
	Model    string `json:"model"`
	Used     int64  `json:"used"`
	Limit    int64  `json:"limit"`
	ResetAt  string `json:"reset_at"`
}

QuotaRow represents one quota usage row.

func GetQuota

func GetQuota(ctx context.Context, token, provider, model string) ([]QuotaRow, error)

GetQuota fetches quota usage from nself-ai-gateway. provider and model are optional filters (empty string = no filter).

type RouteRow

type RouteRow struct {
	ID       string `json:"id"`
	Provider string `json:"provider"`
	Model    string `json:"model"`
	Target   string `json:"target"`
	Active   bool   `json:"active"`
}

RouteRow represents one routing rule in the gateway.

func ListRoutes

func ListRoutes(ctx context.Context, token string) ([]RouteRow, error)

ListRoutes fetches registered routing rules from nself-ai-gateway.

type ServiceHealth

type ServiceHealth struct {
	Name    string
	Port    int
	Healthy bool
	Message string
}

ServiceHealth reports the health of one AI service.

func StatusAll

func StatusAll(ctx context.Context) ([]ServiceHealth, bool)

StatusAll checks all three canonical AI services in parallel. Returns a slice of three ServiceHealth results. allHealthy is true only when all three are healthy.

Jump to

Keyboard shortcuts

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