api

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(service aistudio.Service, config Config) http.Handler

NewHandler 创建公开 API 路由

func SetAccessLogChannel added in v0.2.0

func SetAccessLogChannel(ctx context.Context, channel string)

SetAccessLogChannel 写入请求实际使用的上游通道

func SetAccessLogError

func SetAccessLogError(ctx context.Context, err error)

SetAccessLogError 写入请求最终错误

func SetAccessLogFinishReason

func SetAccessLogFinishReason(ctx context.Context, reason string)

SetAccessLogFinishReason 写入生成请求的上游终止原因

func SetAccessLogFirstEvent

func SetAccessLogFirstEvent(ctx context.Context, firstEvent time.Duration)

SetAccessLogFirstEvent 写入首个上游语义事件耗时

func SetAccessLogGenerationConfig

func SetAccessLogGenerationConfig(ctx context.Context, config aistudio.GenerationConfig)

SetAccessLogGenerationConfig 写入生成请求采用的参数

func SetAccessLogGenerationInput

func SetAccessLogGenerationInput(ctx context.Context, request aistudio.GenerateRequest)

SetAccessLogGenerationInput 写入生成请求输入摘要

func SetAccessLogGenerationResult

func SetAccessLogGenerationResult(
	ctx context.Context,
	usage *aistudio.Usage,
	toolCalls int,
)

SetAccessLogGenerationResult 写入生成流的完成摘要

func SetAccessLogTarget

func SetAccessLogTarget(ctx context.Context, model string, account string)

SetAccessLogTarget 写入请求实际使用的模型与账户

func SetAccessLogUpstreamBytes

func SetAccessLogUpstreamBytes(ctx context.Context, bytes int64)

SetAccessLogUpstreamBytes 写入上游响应体字节数

func StartAccessLog

func StartAccessLog(ctx context.Context)

StartAccessLog 立即写入已经完成解析的请求开始记录

Types

type AccessLog

type AccessLog struct {
	Status          int
	Latency         time.Duration
	FirstEvent      time.Duration
	UpstreamBytes   int64
	Usage           *aistudio.Usage
	ToolCalls       int
	InputMessages   int
	InputTextChars  int
	InputMedia      int
	InputMediaBytes int64
	InputFiles      int
	Temperature     string
	TopP            string
	Thinking        string
	MaxOutputTokens string
	RequestID       string
	Method          string
	Path            string
	Model           string
	Account         string
	Channel         string
	FinishReason    string
	Error           string
	Canceled        bool
	Generation      bool
}

AccessLog 表示一次公开 API 请求的最终访问记录

type AccountCreateInput

type AccountCreateInput struct {
	Proxy    string `json:"proxy"`
	Locale   string `json:"locale"`
	Timezone string `json:"timezone"`
}

AccountCreateInput 表示浏览器登录的账户环境

type AccountInput

type AccountInput struct {
	Label    string `json:"label"`
	Enabled  bool   `json:"enabled"`
	Proxy    string `json:"proxy"`
	Locale   string `json:"locale"`
	Timezone string `json:"timezone"`
}

AccountInput 表示已有账户配置

type AdminAccount

type AdminAccount struct {
	ID          string   `json:"id"`
	Label       string   `json:"label"`
	Enabled     bool     `json:"enabled"`
	State       string   `json:"state"`
	Proxy       string   `json:"proxy"`
	Locale      string   `json:"locale"`
	Timezone    string   `json:"timezone"`
	Models      []string `json:"models"`
	BenefitTier string   `json:"benefit_tier"`
	Message     string   `json:"message"`
}

AdminAccount 表示管理端账户摘要

type AdminAccountCounts

type AdminAccountCounts struct {
	Total        int `json:"total"`
	Ready        int `json:"ready"`
	Busy         int `json:"busy"`
	Cooldown     int `json:"cooldown"`
	AuthRequired int `json:"auth_required"`
}

AdminAccountCounts 表示账户状态计数

type AdminCooldown

type AdminCooldown struct {
	AccountID    string    `json:"account_id"`
	AccountLabel string    `json:"account_label"`
	Channel      string    `json:"channel"`
	ModelID      string    `json:"model_id"`
	Until        time.Time `json:"until"`
	Reason       string    `json:"reason,omitempty"`
}

AdminCooldown 表示账户模型冷却

type AdminEvent

type AdminEvent struct {
	Type string `json:"type"`
	Data any    `json:"data"`
}

AdminEvent 表示管理端增量事件

type AdminLog

type AdminLog struct {
	Time    time.Time   `json:"time"`
	Level   string      `json:"level"`
	Source  string      `json:"source"`
	Message string      `json:"message"`
	Event   string      `json:"event"`
	Request *RequestLog `json:"request,omitempty"`
}

AdminLog 表示管理页面展示的一条运行日志

type AdminRequest

type AdminRequest struct {
	ID           string    `json:"id"`
	Model        string    `json:"model"`
	AccountID    string    `json:"account_id"`
	AccountLabel string    `json:"account_label"`
	Channel      string    `json:"channel,omitempty"`
	State        string    `json:"state"`
	StartedAt    time.Time `json:"started_at"`
}

AdminRequest 表示活动请求摘要

type AdminService

type AdminService interface {
	Status(context.Context) (AdminStatus, error)
	Models(context.Context) ([]aistudio.Model, error)
	Accounts(context.Context) ([]AdminAccount, error)
	CreateAccount(context.Context, AccountCreateInput) (AdminAccount, error)
	ChromeImportProfiles(context.Context) ([]ChromeImportProfile, error)
	ImportChromeAccounts(context.Context, ChromeImportInput) ([]AdminAccount, error)
	UpdateAccount(context.Context, string, AccountInput) (AdminAccount, error)
	DeleteAccount(context.Context, string) error
	LoginAccount(context.Context, string) (AdminAccount, error)
	VerifyAccount(context.Context, string) (AdminAccount, error)
	StartService(context.Context) (AdminStatus, error)
	StopService(context.Context) (AdminStatus, error)
	ClearLogs(context.Context) error
	RuntimeConfig(context.Context) (RuntimeConfig, error)
	UpdateRuntimeConfig(context.Context, RuntimeConfig) (RuntimeConfig, error)
	Cooldowns(context.Context) ([]AdminCooldown, error)
	Requests(context.Context) ([]AdminRequest, error)
	CancelRequest(context.Context, string) error
	Events(context.Context) (<-chan AdminEvent, error)
	RecordAccessStart(AccessLog)
	RecordAccessLog(AccessLog)
}

AdminService 定义管理端需要的权威状态能力

type AdminStatus

type AdminStatus struct {
	State          string             `json:"state"`
	Running        bool               `json:"running"`
	Ready          bool               `json:"ready"`
	Version        string             `json:"version"`
	ActiveRequests int                `json:"active_requests"`
	Accounts       AdminAccountCounts `json:"accounts"`
}

AdminStatus 表示管理端运行状态

type ChromeImportInput

type ChromeImportInput struct {
	AccountIDs []string `json:"account_ids"`
	Proxy      string   `json:"proxy"`
	Locale     string   `json:"locale"`
	Timezone   string   `json:"timezone"`
}

ChromeImportInput 表示批量导入的 Chrome 账号与账户环境

type ChromeImportProfile

type ChromeImportProfile struct {
	ID          string `json:"id"`
	Profile     string `json:"profile"`
	DisplayName string `json:"display_name"`
	Email       string `json:"email"`
	Locale      string `json:"locale"`
}

ChromeImportProfile 表示可从本机 Chrome 导入的账号

type Config

type Config struct {
	APIKey string
	Admin  AdminService
}

Config 定义公开 API 服务配置

type RequestLog

type RequestLog struct {
	ID              string            `json:"id"`
	State           string            `json:"state"`
	Model           string            `json:"model,omitempty"`
	Method          string            `json:"method,omitempty"`
	Path            string            `json:"path,omitempty"`
	Status          int               `json:"status,omitempty"`
	DurationMS      float64           `json:"duration_ms,omitempty"`
	Usage           *RequestLogUsage  `json:"usage,omitempty"`
	ToolCalls       int               `json:"tool_calls,omitempty"`
	FinishReason    string            `json:"finish_reason,omitempty"`
	Error           string            `json:"error,omitempty"`
	InputMessages   int               `json:"input_messages,omitempty"`
	InputTextChars  int               `json:"input_text_chars,omitempty"`
	InputMedia      int               `json:"input_media,omitempty"`
	InputMediaBytes int64             `json:"input_media_bytes,omitempty"`
	InputFiles      int               `json:"input_files,omitempty"`
	Parameters      map[string]string `json:"parameters,omitempty"`
	FirstEventMS    float64           `json:"first_event_ms,omitempty"`
	UpstreamBytes   int64             `json:"upstream_bytes,omitempty"`
	Channel         string            `json:"channel,omitempty"`
}

RequestLog 保存可关联的请求状态、用量与诊断字段

type RequestLogUsage

type RequestLogUsage struct {
	InputTokens            int64   `json:"input_tokens"`
	ReasoningTokens        int64   `json:"reasoning_tokens"`
	ReplyTokens            int64   `json:"reply_tokens"`
	OutputTokens           int64   `json:"output_tokens"`
	TotalTokens            int64   `json:"total_tokens"`
	AverageTokensPerSecond float64 `json:"average_tokens_per_second"`
}

RequestLogUsage 区分输入、思考、回复与端到端输出速率

type RuntimeConfig

type RuntimeConfig struct {
	AuthStates                string   `json:"auth_states"`
	ListenAddr                string   `json:"listen_addr"`
	APIKey                    string   `json:"proxy_api_key"`
	ActiveListenAddr          string   `json:"active_listen_addr"`
	ActiveAPIKey              string   `json:"active_proxy_api_key"`
	ManagementRestartRequired bool     `json:"management_restart_required"`
	ServiceRestartRequired    bool     `json:"service_restart_required"`
	Proxy                     string   `json:"proxy"`
	InitTimeout               string   `json:"init_timeout"`
	RequestTimeout            string   `json:"request_timeout"`
	WarmWorkerLimit           int      `json:"warm_worker_limit"`
	MaxActiveWorkers          int      `json:"max_active_workers"`
	WarmStartupConcurrency    int      `json:"warm_startup_concurrency"`
	PerAccountConcurrency     int      `json:"per_account_concurrency"`
	RoutingStrategy           string   `json:"routing_strategy"`
	UpstreamChannels          []string `json:"upstream_channels"`
	TemporaryChat             bool     `json:"temporary_chat"`
	WAABackend                string   `json:"waa_backend"`
}

RuntimeConfig 表示全局运行配置

Jump to

Keyboard shortcuts

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