-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtype.d.ts
More file actions
175 lines (150 loc) · 3.6 KB
/
type.d.ts
File metadata and controls
175 lines (150 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
type Variables = {
lang: string | undefined | null
}
type AnalyticsEngineDataPoint = {
blobs?: string[];
doubles?: number[];
indexes?: string[];
}
interface AnalyticsEngineDataset {
writeDataPoint: (point: AnalyticsEngineDataPoint) => void;
writeDataPoints?: (points: AnalyticsEngineDataPoint[]) => void;
}
type CloudflareBindings = {
DB: D1Database;
ASSETS: Fetcher;
ADMIN_TOKEN: string;
CF_API_TOKEN?: string;
CF_ACCOUNT_ID?: string;
FRONTEND_DEV_SERVER_URL?: string;
USAGE_ANALYTICS?: AnalyticsEngineDataset;
USAGE_ANALYTICS_DATASET?: string;
}
type HonoCustomType = {
"Bindings": CloudflareBindings;
"Variables": Variables;
}
// 数据库表行的基础结构
type BaseDbRow = {
created_at: string;
updated_at: string;
}
// channel_config 表的行结构
type ChannelConfigRow = BaseDbRow & {
key: string;
value: string; // JSON 字符串,解析后为 ChannelConfig 类型
}
// api_token 表的行结构
type ApiTokenRow = BaseDbRow & {
key: string;
value: string; // JSON 字符串,解析后为 ApiTokenData 类型
usage: number; // 原始计费单位整数
}
type ChannelType =
| "azure-openai"
| "openai"
| "gemini"
| "azure-openai-audio"
| "openai-audio"
| "claude"
| "claude-to-openai"
| "openai-responses"
| "azure-openai-responses"
| undefined
| null;
type ChannelModelMapping = {
id: string;
name: string;
enabled?: boolean;
default_params?: Record<string, unknown>;
}
type ChannelConfig = {
name: string;
type: ChannelType;
endpoint: string;
enabled?: boolean;
weight?: number;
api_key?: string;
api_keys?: string[];
auto_retry?: boolean;
auto_rotate?: boolean;
models?: ChannelModelMapping[];
supported_models?: string[];
deployment_mapper?: Record<string, string>;
model_pricing?: Record<string, ModelPricing>;
}
type ChannelConfigMap = {
[key: string]: ChannelConfig;
}
type OpenAIResponse = {
usage?: Usage
}
type Usage = {
prompt_tokens?: number,
completion_tokens?: number,
total_tokens?: number,
cached_tokens?: number,
}
type oawKeyPayload = {
channel_key: string;
multipler: number | undefined | null;
}
type CommonResponse = {
success?: boolean;
message?: string;
data?: any;
}
type PricingBillingMode = "volume" | "request";
type ModelPricing = {
billingMode?: PricingBillingMode;
input?: number;
output?: number;
cache?: number;
// 兼容旧版独立按次收费配置
request?: number;
}
type BillingConfig = {
displayDecimals: number;
}
type AdminSecurityConfig = {
enabled: boolean;
telegramBotToken: string;
telegramChatId: string;
verifiedFingerprint: string;
verifiedAt: string | null;
}
type ApiDocsConfig = {
enabled: boolean;
}
type SystemConfig = BillingConfig & {
adminSecurity: AdminSecurityConfig;
apiDocs: ApiDocsConfig;
}
type ApiTokenData = {
name: string;
channel_keys: string[];
total_quota: number; // 原始计费单位整数,-1 表示无限额度
}
type RequestTrackingState = {
retryCount: number;
upstreamStatus?: number;
errorSummary?: string;
}
type AdminLoginChallengeRow = BaseDbRow & {
id: string;
code_hash: string;
expires_at: string;
attempts: number;
max_attempts: number;
request_ip: string;
request_country: string;
request_region: string;
request_city: string;
request_colo: string;
request_timezone: string;
}
type AdminSessionRow = BaseDbRow & {
token_hash: string;
expires_at: string;
last_used_at: string;
}