Imported from SolveaCX/new-api (
constant/AGENTS.md). Install upstream withnpx skills add SolveaCX/new-api --skill constant. Copyright stays with the author.
constant
Purpose
全局常量定义层,集中管理渠道类型编号、API 类型枚举、Gin Context 键名、缓存键名、环境变量名、任务类型、支付方式等跨包共享的常量。不包含任何业务逻辑,仅作常量声明。
Key Files
| File | Description |
|---|---|
channel.go |
渠道类型常量(ChannelTypeOpenAI=1、ChannelTypeAnthropic=14 等,60+ 具名类型;ChannelTypeDummy 为哨兵),另有 ChannelTypeBlockRun=100、ChannelTypeBlockRunVideo=101、ChannelTypeBlockRunSeedance=102 等非连续编号;新增渠道在此追加 |
api_type.go |
API 类型枚举(APITypeOpenAI、APITypeAnthropic 等,iota 递增,APITypeDummy 为哨兵),决定 relay 层选择哪个 adapter |
context_key.go |
ContextKey 类型及所有 Gin Context 键名(token、channel、user、group、auto-group 等维度),避免硬编码字符串 |
cache_key.go |
Redis 缓存键名常量 |
endpoint_type.go |
Endpoint 类型常量 |
env.go |
环境变量名称常量 |
finish_reason.go |
大模型响应 finish_reason 常量(stop、length、tool_calls 等) |
multi_key_mode.go |
多 Key 模式常量 |
azure.go |
Azure 相关常量(API 版本等) |
midjourney.go |
Midjourney 任务动作类型常量 |
task.go |
通用异步任务状态常量 |
waffo_pay_method.go |
支付方式常量 |
setup.go |
系统初始化相关常量 |
README.md |
渠道类型说明文档 |
For AI Agents
Working In This Directory
- 新增渠道:必须同时在
channel.go追加ChannelTypeXxx常量(在ChannelTypeDummy之前,或使用 100+ 非连续段)、在api_type.go追加APITypeXxx(在APITypeDummy之前),并在 relay 层注册对应 adapter。 - 非连续编号段:
ChannelTypeBlockRun系列使用 100–102,与主序列(0–65)不连续;新增渠道时注意不与现有值冲突,ChannelTypeNamesmap 也需同步。 - Context 键:所有 Gin Context 的
c.Set/c.Get调用必须使用constant.ContextKeyXxx常量,不得硬编码字符串。 - 此包是纯常量包,禁止引入任何业务逻辑或外部依赖。
ChannelTypeDummy和APITypeDummy是哨兵值(用于计数),新增条目必须插入其之前。
Testing Requirements
- 此包无业务逻辑,通常无独立测试文件。
- 变更后运行全量编译验证无引用错误:
go build ./...
Common Patterns
- 渠道类型使用具名整型常量,不使用 iota(避免顺序依赖,允许非连续编号)。
- API 类型使用 iota,新增时追加到
APITypeDummy之前。 - Context 键使用
type ContextKey string强类型,避免与其他包的字符串键冲突。
Dependencies
Internal
- 无(纯常量包,不引用任何内部包)
External
- 无