admincli

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectClient

func InjectClient(cmd *cobra.Command, client *AdminClient)

InjectClient stores an AdminClient in the cobra command's context.

func NewProviderCmd

func NewProviderCmd() *cobra.Command

func NewRouteCmd

func NewRouteCmd() *cobra.Command

func NewSettingsCmd

func NewSettingsCmd() *cobra.Command

func NewSystemCmd

func NewSystemCmd() *cobra.Command

func ResolveAdminURL

func ResolveAdminURL(configPath, urlFlag string) (string, error)

ResolveAdminURL returns the admin API base URL (e.g. "http://127.0.0.1:12345/api"). Priority: urlFlag > config file > defaults (127.0.0.1:12345).

func RunREPL

func RunREPL(rootCmd *cobra.Command, in io.Reader, out io.Writer) error

RunREPL starts an interactive command loop. rootCmd is the admin command tree; each input line is dispatched as a subcommand.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       int
	Msg        string
}

APIError is returned when the server responds with a non-zero code.

func (*APIError) Error

func (e *APIError) Error() string

type APIResponse

type APIResponse struct {
	Code int             `json:"code"`
	Msg  string          `json:"msg"`
	Data json.RawMessage `json:"data"`
}

APIResponse mirrors the server's unified response envelope.

type AdminClient

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

AdminClient is an HTTP client for the ais admin API.

func ClientFromCmd

func ClientFromCmd(cmd *cobra.Command) *AdminClient

ClientFromCmd retrieves the AdminClient from the cobra command's context. Panics with a clear message if the client was not injected.

func NewAdminClient

func NewAdminClient(baseURL string) *AdminClient

NewAdminClient creates a client targeting the given base URL (e.g. "http://127.0.0.1:12345/api").

func (*AdminClient) Delete

func (c *AdminClient) Delete(ctx context.Context, path string) (json.RawMessage, error)

Delete sends a DELETE request.

func (*AdminClient) Get

func (c *AdminClient) Get(ctx context.Context, path string) (json.RawMessage, error)

Get sends a GET request.

func (*AdminClient) Post

func (c *AdminClient) Post(ctx context.Context, path string, body any) (json.RawMessage, error)

Post sends a POST request with a JSON body.

func (*AdminClient) Put

func (c *AdminClient) Put(ctx context.Context, path string, body any) (json.RawMessage, error)

Put sends a PUT request with a JSON body.

type CreateProviderReq

type CreateProviderReq struct {
	Key          string   `json:"key"`
	Name         string   `json:"name"`
	BaseURL      string   `json:"base_url"`
	APIKey       string   `json:"api_key"`
	Format       string   `json:"format"`
	Path         string   `json:"path,omitempty"`
	LogoURL      string   `json:"logo_url,omitempty"`
	ThinkTag     string   `json:"think_tag,omitempty"`
	FallbackKeys []string `json:"fallback_keys,omitempty"`
	Models       []string `json:"models,omitempty"`
	DefaultModel string   `json:"default_model,omitempty"`
	EnableProxy  bool     `json:"enable_proxy"`
}

CreateProviderReq is the request body for POST /admin/providers.

type CreateRouteReq

type CreateRouteReq struct {
	Key          string `json:"key"`
	Provider     string `json:"provider"`
	DefaultModel string `json:"default_model,omitempty"`
	Disabled     bool   `json:"disabled"`
}

CreateRouteReq is the request body for POST /admin/routes.

type DefaultRouteItem

type DefaultRouteItem struct {
	DefaultRoute          string `json:"default_route"`
	DefaultAnthropicRoute string `json:"default_anthropic_route"`
	DefaultResponsesRoute string `json:"default_responses_route"`
	DefaultChatRoute      string `json:"default_chat_route"`
}

DefaultRouteItem mirrors the default route fields in status API response.

type Formatter

type Formatter struct {
	Format OutputFormat
	Out    io.Writer
}

Formatter renders data in the configured output format.

func FormatterFromCmd

func FormatterFromCmd(cmd *cobra.Command) *Formatter

FormatterFromCmd creates a Formatter from the command's --output flag.

func (*Formatter) PrintJSON

func (f *Formatter) PrintJSON(v any) error

PrintJSON pretty-prints v as indented JSON.

func (*Formatter) PrintMessage

func (f *Formatter) PrintMessage(msg string) error

PrintMessage prints a plain text message.

func (*Formatter) PrintTable

func (f *Formatter) PrintTable(headers []string, rows [][]string) error

PrintTable prints a header + rows as a column-aligned table.

type OutputFormat

type OutputFormat string

OutputFormat controls how data is rendered.

const (
	FormatTable OutputFormat = "table"
	FormatJSON  OutputFormat = "json"
)

func ParseOutputFormat

func ParseOutputFormat(s string) (OutputFormat, error)

ParseOutputFormat validates and returns an OutputFormat.

type PresetItem

type PresetItem struct {
	Key       string `json:"key"`
	Name      string `json:"name"`
	BaseURL   string `json:"base_url"`
	Format    string `json:"format"`
	Category  string `json:"category"`
	IsPartner bool   `json:"is_partner"`
}

PresetItem mirrors the API response for GET /admin/presets.

type ProviderItem

type ProviderItem struct {
	Key         string   `json:"key"`
	Name        string   `json:"name"`
	BaseURL     string   `json:"base_url"`
	Format      string   `json:"format"`
	Models      []string `json:"models"`
	EnableProxy bool     `json:"enable_proxy"`
	APIKey      string   `json:"api_key"`
	Path        string   `json:"path"`
	LogoURL     string   `json:"logo_url"`
	ThinkTag    string   `json:"think_tag"`
}

ProviderItem is a single provider in list output.

type RouteItem

type RouteItem struct {
	Key                  string            `json:"key"`
	Provider             string            `json:"provider"`
	DefaultModel         string            `json:"default_model"`
	Disabled             bool              `json:"disabled"`
	SceneMap             map[string]string `json:"scene_map"`
	ModelMap             map[string]string `json:"model_map"`
	LongContextThreshold int               `json:"long_context_threshold"`
}

RouteItem is a single route in list output.

type SettingsItem

type SettingsItem struct {
	Host             string   `json:"host"`
	Port             int      `json:"port"`
	AllowedIPs       []string `json:"allowed_ips"`
	LogRetentionDays int      `json:"log_retention_days"`
	ProxyURL         string   `json:"proxy_url"`
}

SettingsItem mirrors the API response for GET /admin/settings.

type StatusItem

type StatusItem struct {
	Server                any    `json:"server"`
	DefaultRoute          string `json:"default_route"`
	DefaultAnthropicRoute string `json:"default_anthropic_route"`
	DefaultResponsesRoute string `json:"default_responses_route"`
	DefaultChatRoute      string `json:"default_chat_route"`
	ProviderCount         int    `json:"provider_count"`
	RouteCount            int    `json:"route_count"`
}

StatusItem mirrors the API response for GET /admin/status.

Jump to

Keyboard shortcuts

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