tui

package
v8.0.76 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package tui provides a terminal-based management interface for CLIProxyAPI.

Index

Constants

This section is empty.

Variables

View Source
var ErrManagementUnsupported = fmt.Errorf("management API not supported by target server")

ErrManagementUnsupported is returned by CheckManagementSupport when neither the v8 nor the v0 management contract is reachable on the target server.

Functions

func CurrentLocale

func CurrentLocale() string

CurrentLocale returns the active locale code.

func Run

func Run(port int, secretKey string, hook *LogHook, output io.Writer) error

Run starts the TUI application targeting localhost on the given port. output specifies where bubbletea renders. If nil, defaults to os.Stdout.

func RunWithBaseURL

func RunWithBaseURL(baseURL string, secretKey string, hook *LogHook, output io.Writer) error

RunWithBaseURL starts the TUI application targeting the specified management base URL. output specifies where bubbletea renders. If nil, defaults to os.Stdout.

func SetLocale

func SetLocale(locale string)

SetLocale changes the active locale.

func T

func T(key string) string

T returns the translated string for the given key.

func TabNames

func TabNames() []string

TabNames returns tab names in the current locale.

func ToggleLocale

func ToggleLocale()

ToggleLocale switches between zh and en.

Types

type App

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

App is the root bubbletea model that contains all tab sub-models.

func NewApp

func NewApp(port int, secretKey string, hook *LogHook) App

NewApp creates the root TUI application model targeting localhost on the given port.

func NewAppWithBaseURL

func NewAppWithBaseURL(baseURL string, secretKey string, hook *LogHook) App

NewAppWithBaseURL creates the root TUI application model targeting the specified management base URL.

func (App) Init

func (a App) Init() tea.Cmd

func (App) Update

func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (App) View

func (a App) View() string

type Client

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

Client wraps HTTP calls to the management API.

The client prefers the v8 management contract and falls back to the deprecated /v0/management routes only when the v8 route is not implemented (404/405/501) by the target server. Configuration reads normalize the v8 tree-shaped document into the flat key set the TUI presents, so the tab models keep working on either contract.

func NewClient

func NewClient(port int, secretKey string) *Client

NewClient creates a new management API client targeting localhost on the given port.

func NewClientWithBaseURL

func NewClientWithBaseURL(baseURL string, secretKey string) *Client

NewClientWithBaseURL creates a new management API client targeting the specified base URL.

func (*Client) AddAPIKey

func (c *Client) AddAPIKey(key string) error

AddAPIKey adds a new API key. On v8 it appends to access.api-keys; on v0 it falls back to the legacy patch contract.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the client's configured management API base URL.

func (*Client) CancelAuthSession

func (c *Client) CancelAuthSession(state string) error

CancelAuthSession cancels a pending OAuth session on the management server.

func (*Client) CheckManagementSupport added in v8.0.68

func (c *Client) CheckManagementSupport() error

CheckManagementSupport reports whether the target exposes a usable management API on either contract. It is definitive only when a contract is actually served or clearly absent; a transient failure on one contract does not get reported as "unsupported" while the other is merely unreachable.

func (*Client) DeleteAPIKey

func (c *Client) DeleteAPIKey(index int, expected ...string) error

DeleteAPIKey deletes an API key by index. expected optionally binds the key value shown to the user, so a concurrent reorder/delete is refused rather than removing the wrong entry.

func (*Client) DeleteAuthFile

func (c *Client) DeleteAuthFile(name string) error

DeleteAuthFile deletes a single auth file by name.

func (*Client) DeleteField

func (c *Client) DeleteField(path string) error

DeleteField sends a DELETE request for a config field, preferring v8.

func (*Client) EditAPIKey

func (c *Client) EditAPIKey(index int, newValue string, expected ...string) error

EditAPIKey replaces an API key at the given index. expected is the key value the caller displayed when the user chose this index; if the server list no longer has that value at this position the write is refused instead of silently editing a shifted entry.

func (*Client) GetAPIKeys

func (c *Client) GetAPIKeys() ([]string, error)

GetAPIKeys fetches the list of API keys. API returns {"api-keys": [...]} on v0; the v8 equivalent is the bare array at /v8/management/config/access/api-keys.

func (*Client) GetAuthFiles

func (c *Client) GetAuthFiles() ([]map[string]any, error)

GetAuthFiles lists auth credential files. API returns {"files": [...]}.

func (*Client) GetAuthStatus

func (c *Client) GetAuthStatus(state string) (string, string, error)

GetAuthStatus polls the OAuth session status. Returns status ("wait", "ok", "error") and optional error message.

func (*Client) GetClaudeKeys

func (c *Client) GetClaudeKeys() ([]map[string]any, error)

GetClaudeKeys fetches Claude API keys. API returns {"claude-api-key": [...]}.

func (*Client) GetCodexKeys

func (c *Client) GetCodexKeys() ([]map[string]any, error)

GetCodexKeys fetches Codex API keys. API returns {"codex-api-key": [...]}.

func (*Client) GetConfig

func (c *Client) GetConfig() (map[string]any, error)

GetConfig fetches the parsed config. It prefers the v8 document, normalized to the flat shape the TUI presents, and falls back to the legacy v0 config.

func (*Client) GetConfigYAML

func (c *Client) GetConfigYAML() (string, error)

GetConfigYAML fetches the raw config.yaml content.

func (*Client) GetDebug

func (c *Client) GetDebug() (bool, error)

GetDebug fetches the current debug setting.

func (*Client) GetGeminiKeys

func (c *Client) GetGeminiKeys() ([]map[string]any, error)

GetGeminiKeys fetches Gemini API keys. API returns {"gemini-api-key": [...]}.

func (*Client) GetInteractionsKeys

func (c *Client) GetInteractionsKeys() ([]map[string]any, error)

GetInteractionsKeys fetches native Interactions API keys. API returns {"interactions-api-key": [...]}.

func (*Client) GetLogs

func (c *Client) GetLogs(after int64, limit int) ([]string, int64, error)

GetLogs fetches log lines from the server.

func (*Client) GetOpenAICompat

func (c *Client) GetOpenAICompat() ([]map[string]any, error)

GetOpenAICompat fetches OpenAI compatibility entries. API returns {"openai-compatibility": [...]}.

func (*Client) GetVertexKeys

func (c *Client) GetVertexKeys() ([]map[string]any, error)

GetVertexKeys fetches Vertex API keys. API returns {"vertex-api-key": [...]}.

func (*Client) GetXAIKeys

func (c *Client) GetXAIKeys() ([]map[string]any, error)

GetXAIKeys fetches xAI API keys. API returns {"xai-api-key": [...]}.

func (*Client) PatchAuthFileFields

func (c *Client) PatchAuthFileFields(name string, fields map[string]any) error

PatchAuthFileFields updates editable fields on an auth file.

func (*Client) PutBoolField

func (c *Client) PutBoolField(path string, value bool) error

PutBoolField updates a boolean config field.

func (*Client) PutConfigYAML

func (c *Client) PutConfigYAML(yamlContent string) error

PutConfigYAML uploads new config.yaml content, preferring the v8 endpoint.

func (*Client) PutIntField

func (c *Client) PutIntField(path string, value int) error

PutIntField updates an integer config field.

func (*Client) PutStringField

func (c *Client) PutStringField(path string, value string) error

PutStringField updates a string config field.

func (*Client) RefreshAllAuthFiles

func (c *Client) RefreshAllAuthFiles() error

RefreshAllAuthFiles triggers a forced refresh of all auth credentials.

func (*Client) RefreshAuthFile

func (c *Client) RefreshAuthFile(name string) error

RefreshAuthFile triggers a forced refresh of a single auth credential.

func (*Client) SetSecretKey

func (c *Client) SetSecretKey(secretKey string)

SetSecretKey updates management API bearer token used by this client.

func (*Client) StartOAuthFlow added in v8.0.68

func (c *Client) StartOAuthFlow(legacyAPIPath string) (map[string]any, error)

StartOAuthFlow begins an OAuth login for the given provider. It prefers the shared v8 endpoint and falls back to the provider-specific v0 route. legacyAPIPath is the v0 path segment (e.g. "codex-auth-url").

func (*Client) SubmitOAuthCallback added in v8.0.68

func (c *Client) SubmitOAuthCallback(providerKey, redirectURL, state string) error

SubmitOAuthCallback posts a callback URL to the management server, preferring the v8 callback endpoint.

func (*Client) ToggleAuthFile

func (c *Client) ToggleAuthFile(name string, disabled bool) error

ToggleAuthFile enables or disables an auth file.

type LogHook

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

LogHook is a logrus hook that captures log entries and sends them to a channel.

func NewLogHook

func NewLogHook(bufSize int) *LogHook

NewLogHook creates a new LogHook with a buffered channel of the given size.

func (*LogHook) Chan

func (h *LogHook) Chan() <-chan string

Chan returns the channel to read log lines from.

func (*LogHook) Fire

func (h *LogHook) Fire(entry *log.Entry) error

Fire is called by logrus when a log entry is fired.

func (*LogHook) Levels

func (h *LogHook) Levels() []log.Level

Levels returns the log levels this hook should fire on.

func (*LogHook) SetFormatter

func (h *LogHook) SetFormatter(f log.Formatter)

SetFormatter sets a custom formatter for the hook.

Jump to

Keyboard shortcuts

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