consts

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APITypeChatCompletion = "chat-completion"
	APITypeResponses      = "responses"
	APITypeClaude         = "claude"
)

API type strings stored in database / used by frontend.

View Source
const (
	FinishReasonStop          = "stop"
	FinishReasonLength        = "length"
	FinishReasonToolCalls     = "tool_calls"
	FinishReasonContentFilter = "content_filter"
)

Finish reason values (normalized across protocols).

View Source
const (
	ClaudeStopEndTurn   = "end_turn"
	ClaudeStopMaxTokens = "max_tokens"
	ClaudeStopToolUse   = "tool_use"
)

Claude-specific stop reason values.

View Source
const (
	SettingKeyBYOKEnabled            = "byok_enabled"
	SettingKeyBYOKMaxChannelsPerUser = "byok_max_channels_per_user"
	SettingKeyBYOKBillingMode        = "byok_billing_mode"
	SettingKeyBYOKServiceFeeRatio    = "byok_service_fee_ratio"
	SettingKeyBYOKBaseURLAllowlist   = "byok_base_url_allowlist"
)

BYOK 相关 settings 表 key。Setting.Value 是 string,按 typed runtime 语义 由 LookupBool/Int/String/Float 解析。所有读写此 5 key 的代码必须用这些常量, 避免拼写漂移;这些 key 同时在 settings.go settingDefs 白名单 + seed.go 默认 写入 + 各 LookupXxx 调用点共享。

View Source
const (
	BYOKBillingModeFree       = "free"
	BYOKBillingModeServiceFee = "service_fee"
)

SettingKeyBYOKBillingMode 的合法枚举值。settings.go 的 validate 与 settler.go 的分支判断都引用同一常量,禁止任一边裸字面值。

View Source
const (
	BYOKDefaultEnabledStr            = "true"
	BYOKDefaultEnabledBool           = true
	BYOKDefaultMaxChannelsPerUserStr = "20"
	BYOKDefaultMaxChannelsPerUserInt = 20
	BYOKDefaultBillingMode           = BYOKBillingModeFree
	BYOKDefaultServiceFeeRatioStr    = "0.1"
	BYOKDefaultServiceFeeRatioFloat  = 0.1
	BYOKDefaultBaseURLAllowlistStr   = "[]"
)

BYOK 各 setting 的默认值。存在两种形式:

  • *Str:DB 持久化形式(Setting.Value 是 string column)。被 settings.go settingDefs 的 Default 字段与 seed.go SeedBYOKSettings 共用,确保 admin 未改过任何值时落库和兜底完全一致。
  • typed (Bool/Int/Float):runtime fallback 形式。被 validate.go / settler.go 的 LookupBool/LookupInt/LookupFloat 第二参数共用——LookupXxx 在 setting 不存在或解析失败时返回这个值,因此必须与 *Str 解析后语义相等。

双形式重复存在以避免每次调用 LookupXxx 都跑 strconv.Atoi/ParseFloat;改默认 值时务必同步两组常量。

View Source
const (
	ChannelTypeOpenAI    = 1
	ChannelTypeAzure     = 3
	ChannelTypeOllama    = 4
	ChannelTypeAnthropic = 14
	ChannelTypeGemini    = 24
	ChannelTypeAWS       = 33
	ChannelTypeVertexAI  = 41
)

Channel provider types (numeric IDs used in database). Values match new-api's constant.ChannelType* constants.

View Source
const (
	CtxKeyUserInfo      = "user_info"
	CtxKeyRequestScope  = "request_scope"
	CtxKeyTraceRecorder = "trace_recorder"
)

Gin context key 常量,用于 middleware 写入和 handler 读取。

View Source
const (
	ErrMissingToken       = "missing token"
	ErrInvalidToken       = "invalid token"
	ErrAdminOnly          = "admin only"
	ErrNotFound           = "not found"
	ErrMissingAPIKey      = "missing api key"
	ErrInvalidAPIKey      = "invalid api key"
	ErrTokenDisabled      = "token disabled"
	ErrTokenExpired       = "token expired"
	ErrModelNotAllowed    = "model not allowed"
	ErrReadRequestBody    = "failed to read request body"
	ErrInvalidRequestBody = "invalid request body"
	ErrModelRequired      = "model is required"
	ErrNoChannelAvailable = "no available channels"
)

HTTP 错误响应消息常量。

View Source
const (
	HeaderAuthorization    = "Authorization"
	HeaderContentType      = "Content-Type"
	HeaderConnection       = "Connection"
	HeaderCacheControl     = "Cache-Control"
	HeaderHost             = "Host"
	HeaderOpenAIOrg        = "OpenAI-Organization"
	HeaderXAPIKey          = "x-api-key"
	HeaderAnthropicVersion = "anthropic-version"

	// X-Vaala-* custom headers
	HeaderXRequestID       = "X-Vaala-Request-ID"
	HeaderXChannelID       = "X-Vaala-Channel-ID"
	HeaderXAgentID         = "X-Vaala-Agent-ID"
	HeaderXAgentSecret     = "X-Vaala-Agent-Secret"
	HeaderXAgentTag        = "X-Vaala-Agent-Tag"
	HeaderXAgentAddressTag = "X-Vaala-Agent-Address-Tag"
	HeaderXAgentHop        = "X-Vaala-Agent-Hop"
)

HTTP header names.

View Source
const (
	ContentTypeJSON       = "application/json"
	ContentTypeSSE        = "text/event-stream"
	BearerPrefix          = "Bearer "
	CacheControlNoCache   = "no-cache"
	ConnectionKeepAlive   = "keep-alive"
	AnthropicVersionValue = "2023-06-01"
)

HTTP header values / prefixes.

View Source
const (
	ClaimUserID      = "user_id"
	ClaimRole        = "role"
	ClaimUsername    = "username"
	ClaimDisplayName = "display_name"
	ClaimAvatarURL   = "avatar_url"
	ClaimExp         = "exp"
)

JWT MapClaims 字段名常量。

View Source
const (
	RoleUser  = 1
	RoleAdmin = 2
)
View Source
const (
	RouteChatCompletions = "/v1/chat/completions"
	RouteResponses       = "/v1/responses"
	RouteMessages        = "/v1/messages"
)

API route paths.

View Source
const (
	RPCSyncFullSync           = "sync.fullSync"
	RPCSyncGetVersion         = "sync.getVersion"
	RPCSyncPush               = "sync.push"
	RPCSyncRequestFullSync    = "sync.requestFullSync"
	RPCSyncForceFullSync      = "sync.forceFullSync"
	RPCSyncAutoAddrUpdate     = "sync.autoAddrUpdate"
	RPCSyncFetchEntity        = "sync.fetchEntity"
	RPCAgentHeartbeat         = "agent.heartbeat"
	RPCAgentCheckConnectivity = "agent.checkConnectivity"
	RPCChannelTest            = "channel.test"
	RPCChannelFetchModels     = "channel.fetchModels"
	RPCReportUsage            = "report.usage"
)

RPC/WebSocket 方法名常量。

View Source
const (
	StatusEnabled  = 1
	StatusDisabled = 0
)

Channel/resource status values.

View Source
const TraceBufferHardLimitMultiple = 30

TraceBufferHardLimitMultiple 是单个 Recorder buffer 的硬上限相对 maxBodySize 的倍数。 默认 maxBodySize=64KB → 单 buffer 硬上限 ≈ 1920 KB。

Variables

View Source
var SystemBYOKBaseURLs = []string{
	"https://api.openai.com",
	"https://api.anthropic.com",
}

SystemBYOKBaseURLs 是系统内置的 BYOK BaseURL 前缀集合,随版本演进。 新增 provider 直接在这里 append;老部署升级即自动生效。 不写入 settings 表;admin 不可禁用某条(如未来需要禁用能力,加 byok_system_baseurl_disabled setting 走黑名单并集)。

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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