dsh-plugin-image-workbench 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +5 -3
  3. package/README.md +7 -3
  4. package/client.js +241 -241
  5. package/cordis.patch.yml +14 -14
  6. package/host.js +51 -0
  7. package/install.mjs +333 -387
  8. package/package.json +3 -2
  9. package/scripts/fetch-style-images.mjs +104 -0
  10. package/scripts/vendor-snapshot.py +154 -154
  11. package/server/access.py +26 -26
  12. package/server/app.py +1329 -1329
  13. package/server/catalog.py +147 -147
  14. package/server/composer.py +391 -391
  15. package/server/drafts.py +158 -158
  16. package/server/history.py +575 -575
  17. package/server/imaging.py +172 -172
  18. package/server/pool.py +1335 -1335
  19. package/server/pool_admin.py +921 -921
  20. package/server/pool_service.py +1073 -1073
  21. package/server/requirements.txt +6 -6
  22. package/server/smoke_check.py +402 -402
  23. package/server/static/access.html +202 -202
  24. package/vendor/chatgpt2api/source/.env.example +82 -82
  25. package/vendor/chatgpt2api/source/.python-version +1 -1
  26. package/vendor/chatgpt2api/source/LICENSE +21 -21
  27. package/vendor/chatgpt2api/source/README.md +391 -391
  28. package/vendor/chatgpt2api/source/VERSION +1 -1
  29. package/vendor/chatgpt2api/source/api/__init__.py +2 -2
  30. package/vendor/chatgpt2api/source/api/accounts.py +537 -537
  31. package/vendor/chatgpt2api/source/api/ai.py +217 -217
  32. package/vendor/chatgpt2api/source/api/app.py +62 -62
  33. package/vendor/chatgpt2api/source/api/errors.py +46 -46
  34. package/vendor/chatgpt2api/source/api/image_inputs.py +309 -309
  35. package/vendor/chatgpt2api/source/api/image_tasks.py +120 -120
  36. package/vendor/chatgpt2api/source/api/support.py +134 -134
  37. package/vendor/chatgpt2api/source/api/system.py +365 -365
  38. package/vendor/chatgpt2api/source/assets/kunrouai.svg +50 -50
  39. package/vendor/chatgpt2api/source/config.default.json +108 -108
  40. package/vendor/chatgpt2api/source/main.py +9 -9
  41. package/vendor/chatgpt2api/source/pyproject.toml +27 -27
  42. package/vendor/chatgpt2api/source/scripts/init_proxy_config.py +186 -186
  43. package/vendor/chatgpt2api/source/scripts/migrate_storage.py +163 -163
  44. package/vendor/chatgpt2api/source/scripts/privoxy-warp.conf +13 -13
  45. package/vendor/chatgpt2api/source/scripts/test_outlook_token_mailbox.py +385 -385
  46. package/vendor/chatgpt2api/source/scripts/test_storage.py +129 -129
  47. package/vendor/chatgpt2api/source/scripts/verify_oauth_refresh.py +92 -92
  48. package/vendor/chatgpt2api/source/services/account_service.py +1757 -1757
  49. package/vendor/chatgpt2api/source/services/auth_service.py +253 -253
  50. package/vendor/chatgpt2api/source/services/backup_service.py +671 -671
  51. package/vendor/chatgpt2api/source/services/config.py +667 -667
  52. package/vendor/chatgpt2api/source/services/content_filter.py +242 -242
  53. package/vendor/chatgpt2api/source/services/cpa_service.py +315 -315
  54. package/vendor/chatgpt2api/source/services/editable_file_task_service.py +260 -260
  55. package/vendor/chatgpt2api/source/services/image_service.py +376 -376
  56. package/vendor/chatgpt2api/source/services/image_storage_service.py +405 -405
  57. package/vendor/chatgpt2api/source/services/image_tags_service.py +76 -76
  58. package/vendor/chatgpt2api/source/services/image_task_service.py +550 -550
  59. package/vendor/chatgpt2api/source/services/log_service.py +337 -337
  60. package/vendor/chatgpt2api/source/services/model_service.py +182 -182
  61. package/vendor/chatgpt2api/source/services/oauth_login_service.py +267 -267
  62. package/vendor/chatgpt2api/source/services/openai_backend_api.py +2763 -2763
  63. package/vendor/chatgpt2api/source/services/openai_oauth.py +32 -32
  64. package/vendor/chatgpt2api/source/services/protocol/__init__.py +2 -2
  65. package/vendor/chatgpt2api/source/services/protocol/anthropic_v1_messages.py +307 -307
  66. package/vendor/chatgpt2api/source/services/protocol/chat_completion_cache.py +238 -238
  67. package/vendor/chatgpt2api/source/services/protocol/conversation.py +1644 -1644
  68. package/vendor/chatgpt2api/source/services/protocol/error_response.py +124 -124
  69. package/vendor/chatgpt2api/source/services/protocol/openai_search.py +19 -19
  70. package/vendor/chatgpt2api/source/services/protocol/openai_v1_chat_complete.py +316 -316
  71. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_edit.py +86 -86
  72. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_generations.py +42 -42
  73. package/vendor/chatgpt2api/source/services/protocol/openai_v1_models.py +53 -53
  74. package/vendor/chatgpt2api/source/services/protocol/openai_v1_response.py +453 -453
  75. package/vendor/chatgpt2api/source/services/protocol/web_search_tool.py +160 -160
  76. package/vendor/chatgpt2api/source/services/proxy_service.py +648 -648
  77. package/vendor/chatgpt2api/source/services/storage/__init__.py +5 -5
  78. package/vendor/chatgpt2api/source/services/storage/base.py +38 -38
  79. package/vendor/chatgpt2api/source/services/storage/database_storage.py +194 -194
  80. package/vendor/chatgpt2api/source/services/storage/factory.py +104 -104
  81. package/vendor/chatgpt2api/source/services/storage/git_storage.py +183 -183
  82. package/vendor/chatgpt2api/source/services/storage/json_storage.py +95 -95
  83. package/vendor/chatgpt2api/source/services/sub2api_service.py +531 -531
  84. package/vendor/chatgpt2api/source/utils/helper.py +469 -469
  85. package/vendor/chatgpt2api/source/utils/image_tokens.py +346 -346
  86. package/vendor/chatgpt2api/source/utils/log.py +110 -110
  87. package/vendor/chatgpt2api/source/utils/pkce.py +19 -19
  88. package/vendor/chatgpt2api/source/utils/pow.py +207 -207
  89. package/vendor/chatgpt2api/source/utils/sentinel.py +159 -159
  90. package/vendor/chatgpt2api/source/utils/turnstile.py +184 -184
  91. package/vendor/chatgpt2api/source/uv.lock +904 -904
  92. package/vendor/chatgpt2api/source/web/bun.lock +1501 -1501
  93. package/vendor/chatgpt2api/source/web/components.json +24 -24
  94. package/vendor/chatgpt2api/source/web/eslint.config.mjs +17 -17
  95. package/vendor/chatgpt2api/source/web/next.config.ts +40 -40
  96. package/vendor/chatgpt2api/source/web/package.json +58 -58
  97. package/vendor/chatgpt2api/source/web/postcss.config.mjs +5 -5
  98. package/vendor/chatgpt2api/source/web/src/app/accounts/components/account-import-dialog.tsx +925 -925
  99. package/vendor/chatgpt2api/source/web/src/app/accounts/page.tsx +1307 -1307
  100. package/vendor/chatgpt2api/source/web/src/app/debug/components/chat-panel.tsx +224 -224
  101. package/vendor/chatgpt2api/source/web/src/app/debug/components/editable-file-panel.tsx +444 -444
  102. package/vendor/chatgpt2api/source/web/src/app/debug/components/ppt-panel.tsx +9 -9
  103. package/vendor/chatgpt2api/source/web/src/app/debug/components/psd-panel.tsx +9 -9
  104. package/vendor/chatgpt2api/source/web/src/app/debug/components/search-panel.tsx +172 -172
  105. package/vendor/chatgpt2api/source/web/src/app/debug/components/skill-panel.tsx +169 -169
  106. package/vendor/chatgpt2api/source/web/src/app/debug/components/types.ts +39 -39
  107. package/vendor/chatgpt2api/source/web/src/app/debug/page.tsx +59 -59
  108. package/vendor/chatgpt2api/source/web/src/app/globals.css +230 -230
  109. package/vendor/chatgpt2api/source/web/src/app/image/components/image-composer.tsx +542 -542
  110. package/vendor/chatgpt2api/source/web/src/app/image/components/image-results.tsx +554 -554
  111. package/vendor/chatgpt2api/source/web/src/app/image/components/image-sidebar.tsx +176 -176
  112. package/vendor/chatgpt2api/source/web/src/app/image/page.tsx +1799 -1799
  113. package/vendor/chatgpt2api/source/web/src/app/image-manager/page.tsx +732 -732
  114. package/vendor/chatgpt2api/source/web/src/app/layout.tsx +50 -50
  115. package/vendor/chatgpt2api/source/web/src/app/login/page.tsx +101 -101
  116. package/vendor/chatgpt2api/source/web/src/app/logs/page.tsx +356 -356
  117. package/vendor/chatgpt2api/source/web/src/app/page.tsx +30 -30
  118. package/vendor/chatgpt2api/source/web/src/app/settings/components/api-docs-card.tsx +341 -341
  119. package/vendor/chatgpt2api/source/web/src/app/settings/components/backup-settings-card.tsx +447 -447
  120. package/vendor/chatgpt2api/source/web/src/app/settings/components/base-url-card.tsx +71 -71
  121. package/vendor/chatgpt2api/source/web/src/app/settings/components/config-card.tsx +491 -491
  122. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pool-dialog.tsx +108 -108
  123. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pools-card.tsx +169 -169
  124. package/vendor/chatgpt2api/source/web/src/app/settings/components/import-browser-dialog.tsx +185 -185
  125. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-runtime-card.tsx +379 -379
  126. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings-card.tsx +127 -127
  127. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings.tsx +200 -200
  128. package/vendor/chatgpt2api/source/web/src/app/settings/components/settings-header.tsx +12 -12
  129. package/vendor/chatgpt2api/source/web/src/app/settings/components/sub2api-connections.tsx +886 -886
  130. package/vendor/chatgpt2api/source/web/src/app/settings/components/third-party-apps-card.tsx +81 -81
  131. package/vendor/chatgpt2api/source/web/src/app/settings/components/user-keys-card.tsx +422 -422
  132. package/vendor/chatgpt2api/source/web/src/app/settings/page.tsx +135 -135
  133. package/vendor/chatgpt2api/source/web/src/app/settings/store.ts +1069 -1069
  134. package/vendor/chatgpt2api/source/web/src/components/date-range-filter.tsx +49 -49
  135. package/vendor/chatgpt2api/source/web/src/components/header-actions.tsx +24 -24
  136. package/vendor/chatgpt2api/source/web/src/components/image-lightbox.tsx +434 -434
  137. package/vendor/chatgpt2api/source/web/src/components/image-thumbnail.tsx +46 -46
  138. package/vendor/chatgpt2api/source/web/src/components/theme-script.tsx +18 -18
  139. package/vendor/chatgpt2api/source/web/src/components/theme-toggle.tsx +14 -14
  140. package/vendor/chatgpt2api/source/web/src/components/top-nav.tsx +263 -263
  141. package/vendor/chatgpt2api/source/web/src/components/ui/animated-theme-toggler.tsx +256 -256
  142. package/vendor/chatgpt2api/source/web/src/components/ui/badge.tsx +41 -41
  143. package/vendor/chatgpt2api/source/web/src/components/ui/button.tsx +59 -59
  144. package/vendor/chatgpt2api/source/web/src/components/ui/calendar.tsx +46 -46
  145. package/vendor/chatgpt2api/source/web/src/components/ui/card.tsx +61 -61
  146. package/vendor/chatgpt2api/source/web/src/components/ui/checkbox.tsx +27 -27
  147. package/vendor/chatgpt2api/source/web/src/components/ui/dia-text-reveal.tsx +267 -267
  148. package/vendor/chatgpt2api/source/web/src/components/ui/dialog.tsx +132 -132
  149. package/vendor/chatgpt2api/source/web/src/components/ui/field.tsx +13 -13
  150. package/vendor/chatgpt2api/source/web/src/components/ui/input.tsx +19 -19
  151. package/vendor/chatgpt2api/source/web/src/components/ui/label.tsx +24 -24
  152. package/vendor/chatgpt2api/source/web/src/components/ui/morphing-text.tsx +149 -149
  153. package/vendor/chatgpt2api/source/web/src/components/ui/popover.tsx +38 -38
  154. package/vendor/chatgpt2api/source/web/src/components/ui/select.tsx +175 -175
  155. package/vendor/chatgpt2api/source/web/src/components/ui/sheet.tsx +143 -143
  156. package/vendor/chatgpt2api/source/web/src/components/ui/table.tsx +29 -29
  157. package/vendor/chatgpt2api/source/web/src/components/ui/tabs.tsx +91 -91
  158. package/vendor/chatgpt2api/source/web/src/components/ui/text-3d-flip.tsx +269 -269
  159. package/vendor/chatgpt2api/source/web/src/components/ui/textarea.tsx +18 -18
  160. package/vendor/chatgpt2api/source/web/src/components/version-release-dialog.tsx +127 -127
  161. package/vendor/chatgpt2api/source/web/src/constants/common-env.ts +6 -6
  162. package/vendor/chatgpt2api/source/web/src/hooks/use-version-check.ts +85 -85
  163. package/vendor/chatgpt2api/source/web/src/lib/api.ts +926 -926
  164. package/vendor/chatgpt2api/source/web/src/lib/auth-session.ts +26 -26
  165. package/vendor/chatgpt2api/source/web/src/lib/release.ts +25 -25
  166. package/vendor/chatgpt2api/source/web/src/lib/request.ts +93 -93
  167. package/vendor/chatgpt2api/source/web/src/lib/use-auth-guard.ts +89 -89
  168. package/vendor/chatgpt2api/source/web/src/lib/utils.ts +6 -6
  169. package/vendor/chatgpt2api/source/web/src/store/auth.ts +112 -112
  170. package/vendor/chatgpt2api/source/web/src/store/editable-file-history.ts +33 -33
  171. package/vendor/chatgpt2api/source/web/src/store/image-conversations.ts +318 -318
  172. package/vendor/chatgpt2api/source/web/tsconfig.json +42 -42
@@ -1,926 +1,926 @@
1
- import { httpRequest, request } from "@/lib/request";
2
-
3
- export type AccountType = string;
4
- export type AccountStatus = "正常" | "限流" | "异常" | "禁用";
5
- export type ImageModel = string;
6
- export type AuthRole = "admin" | "user";
7
- export type ImageStorageMode = "local" | "webdav" | "both";
8
-
9
- export type ImageStorageSettings = {
10
- enabled: boolean;
11
- mode: ImageStorageMode;
12
- webdav_url: string;
13
- webdav_username: string;
14
- webdav_password: string;
15
- webdav_root_path: string;
16
- public_base_url: string;
17
- };
18
-
19
- export type Account = {
20
- access_token: string;
21
- type: AccountType;
22
- source_type?: string | null;
23
- status: AccountStatus;
24
- quota: number;
25
- email?: string | null;
26
- user_id?: string | null;
27
- limits_progress?: Array<{
28
- feature_name?: string;
29
- remaining?: number;
30
- reset_after?: string;
31
- }>;
32
- default_model_slug?: string | null;
33
- restore_at?: string | null;
34
- success: number;
35
- fail: number;
36
- /** 当前图片在途数(正在生成、尚未结束的图片数)。号池空闲时持续 > 0 表示并发槽位泄漏。 */
37
- image_inflight?: number;
38
- last_used_at?: string | null;
39
- proxy?: string | null;
40
- };
41
-
42
- export type AccountImportPayload = {
43
- access_token: string;
44
- accessToken?: string;
45
- type?: string;
46
- export_type?: string;
47
- source_type?: string;
48
- [key: string]: unknown;
49
- };
50
-
51
- export type Model = {
52
- id: string;
53
- object: string;
54
- created: number;
55
- owned_by: string;
56
- permission: unknown[];
57
- root: string;
58
- parent: string | null;
59
- };
60
-
61
- type AccountListResponse = {
62
- items: Account[];
63
- };
64
-
65
- type ModelListResponse = {
66
- object: string;
67
- data: Model[];
68
- };
69
-
70
- type AccountMutationResponse = {
71
- items: Account[];
72
- added?: number;
73
- skipped?: number;
74
- removed?: number;
75
- refreshed?: number;
76
- relogined?: number;
77
- errors?: Array<{ access_token: string; error: string }>;
78
- };
79
-
80
- export type AccountRefreshResponse = {
81
- items: Account[];
82
- refreshed: number;
83
- relogined?: number;
84
- errors: Array<{ access_token: string; error: string }>;
85
- };
86
-
87
- export type RefreshProgressResponse = {
88
- total: number;
89
- processed: number;
90
- done: boolean;
91
- error: string | null;
92
- status_counts?: Record<string, number>;
93
- total_quota?: number;
94
- result?: AccountRefreshResponse | null;
95
- results?: Array<{ token: string; status: string; error?: string | null }>;
96
- };
97
-
98
- type AccountUpdateResponse = {
99
- item: Account;
100
- items: Account[];
101
- };
102
-
103
- export type ProxyRuntimeEgressMode = "direct" | "single_proxy";
104
- export type ProxyRuntimeClearanceMode = "none" | "manual" | "flaresolverr";
105
-
106
- export type ProxyRuntimeClearanceSettings = {
107
- enabled: boolean;
108
- mode: ProxyRuntimeClearanceMode;
109
- cf_cookies: string;
110
- cf_clearance: string;
111
- user_agent: string;
112
- browser: string;
113
- flaresolverr_url: string;
114
- timeout_sec: number | string;
115
- refresh_interval: number | string;
116
- warm_up_on_start: boolean;
117
- has_cf_cookies?: boolean;
118
- has_cf_clearance?: boolean;
119
- };
120
-
121
- export type ProxyRuntimeSettings = {
122
- enabled: boolean;
123
- egress_mode: ProxyRuntimeEgressMode;
124
- proxy_url: string;
125
- resource_proxy_url: string;
126
- skip_ssl_verify: boolean;
127
- reset_session_status_codes: number[];
128
- clearance: ProxyRuntimeClearanceSettings;
129
- };
130
-
131
- export type ProxyRuntimeStatus = {
132
- enabled: boolean;
133
- egress_mode: ProxyRuntimeEgressMode | string;
134
- proxy_source: string;
135
- has_proxy: boolean;
136
- clearance_enabled: boolean;
137
- clearance_mode: ProxyRuntimeClearanceMode | string;
138
- has_clearance_bundle: boolean;
139
- cached_clearance_hosts: string[];
140
- };
141
-
142
- export type ProxyRuntimeResponse = {
143
- runtime: ProxyRuntimeSettings;
144
- status: ProxyRuntimeStatus;
145
- };
146
-
147
- export type ThirdPartyAppsSettings = {
148
- infinite_canvas: {
149
- enabled: boolean;
150
- url: string;
151
- };
152
- };
153
-
154
- export type SettingsConfig = {
155
- proxy: string;
156
- base_url?: string;
157
- global_system_prompt?: string;
158
- default_upstream_model_name?: string;
159
- default_thinking_effort?: "auto" | "standard" | "extended" | "max";
160
- sensitive_words?: string[];
161
- ai_review?: {
162
- enabled?: boolean;
163
- base_url?: string;
164
- api_key?: string;
165
- model?: string;
166
- prompt?: string;
167
- };
168
- refresh_account_interval_minute?: number | string;
169
- image_retention_days?: number | string;
170
- image_poll_timeout_secs?: number | string;
171
- image_account_concurrency?: number | string;
172
- image_parallel_generation?: boolean;
173
- image_settle_enabled?: boolean;
174
- image_check_before_hit_enabled?: boolean;
175
- image_remove_conversation_after_result?: boolean;
176
- image_remove_conversation_always?: boolean;
177
- image_settle_secs?: number | string;
178
- image_timeout_retry_secs?: number | string;
179
- auto_remove_invalid_accounts?: boolean;
180
- auto_remove_rate_limited_accounts?: boolean;
181
- auto_relogin_after_refresh?: boolean;
182
- log_levels?: string[];
183
- image_storage?: ImageStorageSettings;
184
- proxy_runtime?: ProxyRuntimeSettings;
185
- third_party_apps?: ThirdPartyAppsSettings;
186
- backup?: BackupSettings;
187
- backup_state?: BackupState;
188
- [key: string]: unknown;
189
- };
190
-
191
- export type BackupInclude = {
192
- config: boolean;
193
- cpa: boolean;
194
- sub2api: boolean;
195
- logs: boolean;
196
- image_tasks: boolean;
197
- accounts_snapshot: boolean;
198
- auth_keys_snapshot: boolean;
199
- images: boolean;
200
- };
201
-
202
- export type BackupSettings = {
203
- enabled: boolean;
204
- provider: "cloudflare_r2" | string;
205
- account_id: string;
206
- access_key_id: string;
207
- secret_access_key: string;
208
- bucket: string;
209
- prefix: string;
210
- interval_minutes: number | string;
211
- rotation_keep: number | string;
212
- encrypt: boolean;
213
- passphrase: string;
214
- include: BackupInclude;
215
- };
216
-
217
- export type BackupState = {
218
- running: boolean;
219
- last_started_at?: string | null;
220
- last_finished_at?: string | null;
221
- last_status?: string;
222
- last_error?: string | null;
223
- last_object_key?: string | null;
224
- };
225
-
226
- export type BackupItem = {
227
- key: string;
228
- name: string;
229
- size: number;
230
- updated_at?: string | null;
231
- encrypted: boolean;
232
- };
233
-
234
- export type BackupDetail = {
235
- key: string;
236
- name: string;
237
- encrypted: boolean;
238
- created_at?: string | null;
239
- trigger?: string | null;
240
- app_version?: string | null;
241
- storage_backend?: Record<string, unknown> | null;
242
- files: Array<{
243
- name: string;
244
- exists: boolean;
245
- content_type?: string;
246
- size: number;
247
- sha256?: string;
248
- }>;
249
- snapshots: Array<{
250
- name: string;
251
- count: number;
252
- }>;
253
- };
254
-
255
- export type ManagedImage = {
256
- rel: string;
257
- path?: string;
258
- name: string;
259
- date: string;
260
- size: number;
261
- url: string;
262
- thumbnail_url?: string;
263
- created_at: string;
264
- width?: number;
265
- height?: number;
266
- tags?: string[];
267
- };
268
-
269
- export type SystemLog = {
270
- id: string;
271
- time: string;
272
- type: "call" | "account" | string;
273
- summary?: string;
274
- detail?: Record<string, unknown>;
275
- [key: string]: unknown;
276
- };
277
-
278
- export type ImageResponse = {
279
- created: number;
280
- data: Array<{ b64_json?: string; url?: string; revised_prompt?: string }>;
281
- };
282
-
283
- export type ImageTask = {
284
- id: string;
285
- status: "queued" | "running" | "success" | "error";
286
- mode: "generate" | "edit";
287
- model?: ImageModel;
288
- size?: string;
289
- quality?: string;
290
- created_at: string;
291
- updated_at: string;
292
- conversation_id?: string;
293
- data?: Array<{ b64_json?: string; url?: string; revised_prompt?: string }>;
294
- error?: string;
295
- progress?: string;
296
- elapsed_secs?: number;
297
- duration_ms?: number;
298
- };
299
-
300
- type ImageTaskListResponse = {
301
- items: ImageTask[];
302
- missing_ids: string[];
303
- };
304
-
305
- export type LoginResponse = {
306
- ok: boolean;
307
- version: string;
308
- role: AuthRole;
309
- subject_id: string;
310
- name: string;
311
- };
312
-
313
- export type UserKey = {
314
- id: string;
315
- name: string;
316
- role: "user";
317
- enabled: boolean;
318
- created_at: string | null;
319
- last_used_at: string | null;
320
- };
321
-
322
- export async function login(authKey: string) {
323
- const normalizedAuthKey = String(authKey || "").trim();
324
- return httpRequest<LoginResponse>("/auth/login", {
325
- method: "POST",
326
- body: {},
327
- headers: {
328
- Authorization: `Bearer ${normalizedAuthKey}`,
329
- },
330
- redirectOnUnauthorized: false,
331
- });
332
- }
333
-
334
- export async function fetchAccounts() {
335
- return httpRequest<AccountListResponse>("/api/accounts");
336
- }
337
-
338
- export async function fetchModels() {
339
- return httpRequest<ModelListResponse>("/v1/models");
340
- }
341
-
342
- export async function createAccounts(tokens: string[], accounts: AccountImportPayload[] = []) {
343
- return httpRequest<AccountMutationResponse>("/api/accounts", {
344
- method: "POST",
345
- body: { tokens, accounts },
346
- });
347
- }
348
-
349
- export type OAuthLoginStartResponse = {
350
- session_id: string;
351
- authorize_url: string;
352
- expires_in: string;
353
- redirect_uri_prefix: string;
354
- };
355
-
356
- export async function startOAuthLogin(emailHint?: string) {
357
- return httpRequest<OAuthLoginStartResponse>("/api/accounts/oauth/start", {
358
- method: "POST",
359
- body: { email_hint: emailHint ?? "" },
360
- });
361
- }
362
-
363
- export async function finishOAuthLogin(sessionId: string, callback: string) {
364
- return httpRequest<AccountMutationResponse>("/api/accounts/oauth/finish", {
365
- method: "POST",
366
- body: { session_id: sessionId, callback },
367
- });
368
- }
369
-
370
- export async function deleteAccounts(tokens: string[]) {
371
- return httpRequest<AccountMutationResponse>("/api/accounts", {
372
- method: "DELETE",
373
- body: { tokens },
374
- });
375
- }
376
-
377
- export async function refreshAccounts(accessTokens: string[]) {
378
- return httpRequest<{ progress_id: string }>("/api/accounts/refresh", {
379
- method: "POST",
380
- body: { access_tokens: accessTokens },
381
- });
382
- }
383
-
384
- export async function fetchRefreshProgress(progressId: string) {
385
- return httpRequest<RefreshProgressResponse>(`/api/accounts/refresh/progress/${progressId}`);
386
- }
387
-
388
- export async function reLoginAccounts(accessTokens: string[]) {
389
- return httpRequest<{ progress_id: string }>("/api/accounts/re-login", {
390
- method: "POST",
391
- body: { access_tokens: accessTokens },
392
- });
393
- }
394
-
395
- export async function fetchReLoginProgress(progressId: string) {
396
- return httpRequest<RefreshProgressResponse>(`/api/accounts/re-login/progress/${progressId}`);
397
- }
398
-
399
- export async function updateAccount(
400
- accessToken: string,
401
- updates: {
402
- type?: AccountType;
403
- status?: AccountStatus;
404
- quota?: number;
405
- proxy?: string;
406
- },
407
- ) {
408
- return httpRequest<AccountUpdateResponse>("/api/accounts/update", {
409
- method: "POST",
410
- body: {
411
- access_token: accessToken,
412
- ...updates,
413
- },
414
- });
415
- }
416
-
417
- export async function generateImage(prompt: string, model?: ImageModel, size?: string, quality = "auto") {
418
- return httpRequest<ImageResponse>(
419
- "/v1/images/generations",
420
- {
421
- method: "POST",
422
- body: {
423
- prompt,
424
- ...(model ? { model } : {}),
425
- ...(size ? { size } : {}),
426
- quality,
427
- n: 1,
428
- response_format: "b64_json",
429
- },
430
- },
431
- );
432
- }
433
-
434
- export async function editImage(files: File | File[], prompt: string, model?: ImageModel, size?: string, quality = "auto") {
435
- const formData = new FormData();
436
- const uploadFiles = Array.isArray(files) ? files : [files];
437
-
438
- uploadFiles.forEach((file) => {
439
- formData.append("image", file);
440
- });
441
- formData.append("prompt", prompt);
442
- if (model) {
443
- formData.append("model", model);
444
- }
445
- if (size) {
446
- formData.append("size", size);
447
- }
448
- formData.append("quality", quality);
449
- formData.append("n", "1");
450
-
451
- return httpRequest<ImageResponse>(
452
- "/v1/images/edits",
453
- {
454
- method: "POST",
455
- body: formData,
456
- },
457
- );
458
- }
459
-
460
- export async function createImageGenerationTask(clientTaskId: string, prompt: string, model?: ImageModel, size?: string, quality = "auto") {
461
- return httpRequest<ImageTask>("/api/image-tasks/generations", {
462
- method: "POST",
463
- body: {
464
- client_task_id: clientTaskId,
465
- prompt,
466
- ...(model ? { model } : {}),
467
- ...(size ? { size } : {}),
468
- quality,
469
- },
470
- });
471
- }
472
-
473
- export async function createImageEditTask(
474
- clientTaskId: string,
475
- files: File | File[],
476
- prompt: string,
477
- model?: ImageModel,
478
- size?: string,
479
- quality = "auto",
480
- ) {
481
- const formData = new FormData();
482
- const uploadFiles = Array.isArray(files) ? files : [files];
483
-
484
- uploadFiles.forEach((file) => {
485
- formData.append("image", file);
486
- });
487
- formData.append("client_task_id", clientTaskId);
488
- formData.append("prompt", prompt);
489
- if (model) {
490
- formData.append("model", model);
491
- }
492
- if (size) {
493
- formData.append("size", size);
494
- }
495
- formData.append("quality", quality);
496
-
497
- return httpRequest<ImageTask>("/api/image-tasks/edits", {
498
- method: "POST",
499
- body: formData,
500
- });
501
- }
502
-
503
- export async function fetchImageTasks(ids: string[]) {
504
- const params = new URLSearchParams();
505
- if (ids.length > 0) {
506
- params.set("ids", ids.join(","));
507
- }
508
- params.set("_t", String(Date.now()));
509
- return httpRequest<ImageTaskListResponse>(`/api/image-tasks?${params.toString()}`);
510
- }
511
-
512
- export async function resumeImagePoll(taskId: string, extraTimeoutSecs = 30) {
513
- return httpRequest<ImageTask>(`/api/image-tasks/${encodeURIComponent(taskId)}/resume-poll`, {
514
- method: "POST",
515
- body: { extra_timeout_secs: extraTimeoutSecs },
516
- });
517
- }
518
-
519
- export async function fetchSettingsConfig() {
520
- return httpRequest<{ config: SettingsConfig }>("/api/settings");
521
- }
522
-
523
- export async function updateSettingsConfig(settings: SettingsConfig) {
524
- return httpRequest<{ config: SettingsConfig }>("/api/settings", {
525
- method: "POST",
526
- body: settings,
527
- });
528
- }
529
-
530
- export async function fetchThirdPartyApps() {
531
- return httpRequest<{ third_party_apps: ThirdPartyAppsSettings }>("/api/third-party-apps");
532
- }
533
-
534
- export async function testBackupConnection() {
535
- return httpRequest<{ result: { ok: boolean; status: number } }>("/api/backup/test", {
536
- method: "POST",
537
- body: {},
538
- });
539
- }
540
-
541
- export async function testImageStorageConnection() {
542
- return httpRequest<{ result: { ok: boolean; status: number; error?: string } }>("/api/image-storage/test", {
543
- method: "POST",
544
- body: {},
545
- });
546
- }
547
-
548
- export async function syncImageStorage() {
549
- return httpRequest<{ result: { uploaded: number; skipped: number; failed: number } }>("/api/image-storage/sync", {
550
- method: "POST",
551
- body: {},
552
- });
553
- }
554
-
555
- export async function fetchBackups() {
556
- return httpRequest<{ items: BackupItem[]; state: BackupState; settings: BackupSettings }>("/api/backups");
557
- }
558
-
559
- export async function runBackupNow() {
560
- return httpRequest<{ result: { key: string; size: number; encrypted: boolean } }>("/api/backups/run", {
561
- method: "POST",
562
- body: {},
563
- });
564
- }
565
-
566
- export async function deleteBackup(key: string) {
567
- return httpRequest<{ ok: boolean }>("/api/backups/delete", {
568
- method: "POST",
569
- body: { key },
570
- });
571
- }
572
-
573
- export async function fetchBackupDetail(key: string) {
574
- const params = new URLSearchParams();
575
- params.set("key", key);
576
- return httpRequest<{ item: BackupDetail }>(`/api/backups/detail?${params.toString()}`);
577
- }
578
-
579
- export function getBackupDownloadUrl(key: string) {
580
- const params = new URLSearchParams();
581
- params.set("key", key);
582
- return `/api/backups/download?${params.toString()}`;
583
- }
584
-
585
- export async function fetchManagedImages(filters: { start_date?: string; end_date?: string }) {
586
- const params = new URLSearchParams();
587
- if (filters.start_date) params.set("start_date", filters.start_date);
588
- if (filters.end_date) params.set("end_date", filters.end_date);
589
- return httpRequest<{ items: ManagedImage[]; groups: Array<{ date: string; items: ManagedImage[] }> }>(
590
- `/api/images${params.toString() ? `?${params.toString()}` : ""}`,
591
- );
592
- }
593
-
594
- export async function deleteManagedImages(body: { paths?: string[]; start_date?: string; end_date?: string; all_matching?: boolean }) {
595
- return httpRequest<{ removed: number }>("/api/images/delete", { method: "POST", body });
596
- }
597
-
598
- export async function downloadImages(paths: string[]) {
599
- const response = await request.post("/api/images/download", { paths }, { responseType: "blob" });
600
- const blob = response.data as Blob;
601
- const url = URL.createObjectURL(blob);
602
- const a = document.createElement("a");
603
- a.href = url;
604
- a.download = "images.zip";
605
- document.body.appendChild(a);
606
- a.click();
607
- document.body.removeChild(a);
608
- URL.revokeObjectURL(url);
609
- }
610
-
611
- export async function downloadSingleImage(path: string) {
612
- const response = await request.get(`/api/images/download/${path}`, { responseType: "blob" });
613
- const blob = response.data as Blob;
614
- const url = URL.createObjectURL(blob);
615
- const a = document.createElement("a");
616
- a.href = url;
617
- a.download = path.split("/").pop() || "image.png";
618
- document.body.appendChild(a);
619
- a.click();
620
- document.body.removeChild(a);
621
- URL.revokeObjectURL(url);
622
- }
623
-
624
- export async function fetchImageTags() {
625
- return httpRequest<{ tags: string[] }>("/api/images/tags");
626
- }
627
-
628
- export async function setImageTags(path: string, tags: string[]) {
629
- return httpRequest<{ ok: boolean; tags: string[] }>("/api/images/tags", {
630
- method: "POST",
631
- body: { path, tags },
632
- });
633
- }
634
-
635
- export async function deleteImageTag(tag: string) {
636
- return httpRequest<{ ok: boolean; removed_from: number }>(`/api/images/tags/${encodeURIComponent(tag)}`, {
637
- method: "DELETE",
638
- });
639
- }
640
-
641
- export type ImageStorageStats = {
642
- disk_total_mb: number; disk_used_mb: number; disk_free_mb: number;
643
- image_count: number; image_size_mb: number; image_size_bytes: number;
644
- };
645
-
646
- export async function fetchImageStorage() {
647
- return httpRequest<ImageStorageStats>("/api/images/storage");
648
- }
649
-
650
- export async function compressAllImages() {
651
- return httpRequest<{ compressed: number; saved_bytes: number; saved_mb: number }>("/api/images/storage/compress", { method: "POST" });
652
- }
653
-
654
- export async function deleteToTarget(targetFreeMb: number) {
655
- return httpRequest<{ removed: number; freed_mb: number; done: boolean }>(
656
- `/api/images/storage/cleanup-to-target?target_free_mb=${targetFreeMb}&dry_run=false`,
657
- { method: "POST" },
658
- );
659
- }
660
-
661
- export async function fetchSystemLogs(filters: { type?: string; start_date?: string; end_date?: string }) {
662
- const params = new URLSearchParams();
663
- if (filters.type) params.set("type", filters.type);
664
- if (filters.start_date) params.set("start_date", filters.start_date);
665
- if (filters.end_date) params.set("end_date", filters.end_date);
666
- return httpRequest<{ items: SystemLog[] }>(`/api/logs${params.toString() ? `?${params.toString()}` : ""}`);
667
- }
668
-
669
- export async function deleteSystemLogs(ids: string[]) {
670
- return httpRequest<{ removed: number }>("/api/logs/delete", {
671
- method: "POST",
672
- body: { ids },
673
- });
674
- }
675
-
676
- export async function fetchUserKeys() {
677
- return httpRequest<{ items: UserKey[] }>("/api/auth/users");
678
- }
679
-
680
- export async function createUserKey(name: string) {
681
- return httpRequest<{ item: UserKey; key: string; items: UserKey[] }>("/api/auth/users", {
682
- method: "POST",
683
- body: { name },
684
- });
685
- }
686
-
687
- export async function updateUserKey(keyId: string, updates: { enabled?: boolean; name?: string; key?: string }) {
688
- return httpRequest<{ item: UserKey; items: UserKey[] }>(`/api/auth/users/${keyId}`, {
689
- method: "POST",
690
- body: updates,
691
- });
692
- }
693
-
694
- export async function deleteUserKey(keyId: string) {
695
- return httpRequest<{ items: UserKey[] }>(`/api/auth/users/${keyId}`, {
696
- method: "DELETE",
697
- });
698
- }
699
-
700
- // ── CPA (CLIProxyAPI) ──────────────────────────────────────────────
701
-
702
- export type CPAPool = {
703
- id: string;
704
- name: string;
705
- base_url: string;
706
- import_job?: CPAImportJob | null;
707
- };
708
-
709
- export type CPARemoteFile = {
710
- name: string;
711
- email: string;
712
- };
713
-
714
- export type CPAImportJob = {
715
- job_id: string;
716
- status: "pending" | "running" | "completed" | "failed";
717
- created_at: string;
718
- updated_at: string;
719
- total: number;
720
- completed: number;
721
- added: number;
722
- skipped: number;
723
- refreshed: number;
724
- failed: number;
725
- errors: Array<{ name: string; error: string }>;
726
- };
727
-
728
- export async function fetchCPAPools() {
729
- return httpRequest<{ pools: CPAPool[] }>("/api/cpa/pools");
730
- }
731
-
732
- export async function createCPAPool(pool: { name: string; base_url: string; secret_key: string }) {
733
- return httpRequest<{ pool: CPAPool; pools: CPAPool[] }>("/api/cpa/pools", {
734
- method: "POST",
735
- body: pool,
736
- });
737
- }
738
-
739
- export async function updateCPAPool(
740
- poolId: string,
741
- updates: { name?: string; base_url?: string; secret_key?: string },
742
- ) {
743
- return httpRequest<{ pool: CPAPool; pools: CPAPool[] }>(`/api/cpa/pools/${poolId}`, {
744
- method: "POST",
745
- body: updates,
746
- });
747
- }
748
-
749
- export async function deleteCPAPool(poolId: string) {
750
- return httpRequest<{ pools: CPAPool[] }>(`/api/cpa/pools/${poolId}`, {
751
- method: "DELETE",
752
- });
753
- }
754
-
755
- export async function fetchCPAPoolFiles(poolId: string) {
756
- return httpRequest<{ pool_id: string; files: CPARemoteFile[] }>(`/api/cpa/pools/${poolId}/files`);
757
- }
758
-
759
- export async function startCPAImport(poolId: string, names: string[]) {
760
- return httpRequest<{ import_job: CPAImportJob | null }>(`/api/cpa/pools/${poolId}/import`, {
761
- method: "POST",
762
- body: { names },
763
- });
764
- }
765
-
766
- export async function fetchCPAPoolImportJob(poolId: string) {
767
- return httpRequest<{ import_job: CPAImportJob | null }>(`/api/cpa/pools/${poolId}/import`);
768
- }
769
-
770
- // ── Sub2API ────────────────────────────────────────────────────────
771
-
772
- export type Sub2APIServer = {
773
- id: string;
774
- name: string;
775
- base_url: string;
776
- email: string;
777
- has_api_key: boolean;
778
- group_id: string;
779
- import_job?: CPAImportJob | null;
780
- };
781
-
782
- export type Sub2APIRemoteAccount = {
783
- id: string;
784
- name: string;
785
- email: string;
786
- plan_type: string;
787
- status: string;
788
- expires_at: string;
789
- has_refresh_token: boolean;
790
- };
791
-
792
- export type Sub2APIRemoteGroup = {
793
- id: string;
794
- name: string;
795
- description: string;
796
- platform: string;
797
- status: string;
798
- account_count: number;
799
- active_account_count: number;
800
- };
801
-
802
- export async function fetchSub2APIServers() {
803
- return httpRequest<{ servers: Sub2APIServer[] }>("/api/sub2api/servers");
804
- }
805
-
806
- export async function createSub2APIServer(server: {
807
- name: string;
808
- base_url: string;
809
- email: string;
810
- password: string;
811
- api_key: string;
812
- group_id: string;
813
- }) {
814
- return httpRequest<{ server: Sub2APIServer; servers: Sub2APIServer[] }>("/api/sub2api/servers", {
815
- method: "POST",
816
- body: server,
817
- });
818
- }
819
-
820
- export async function updateSub2APIServer(
821
- serverId: string,
822
- updates: {
823
- name?: string;
824
- base_url?: string;
825
- email?: string;
826
- password?: string;
827
- api_key?: string;
828
- group_id?: string;
829
- },
830
- ) {
831
- return httpRequest<{ server: Sub2APIServer; servers: Sub2APIServer[] }>(`/api/sub2api/servers/${serverId}`, {
832
- method: "POST",
833
- body: updates,
834
- });
835
- }
836
-
837
- export async function fetchSub2APIServerGroups(serverId: string) {
838
- return httpRequest<{ server_id: string; groups: Sub2APIRemoteGroup[] }>(
839
- `/api/sub2api/servers/${serverId}/groups`,
840
- );
841
- }
842
-
843
- export async function deleteSub2APIServer(serverId: string) {
844
- return httpRequest<{ servers: Sub2APIServer[] }>(`/api/sub2api/servers/${serverId}`, {
845
- method: "DELETE",
846
- });
847
- }
848
-
849
- export async function fetchSub2APIServerAccounts(serverId: string) {
850
- return httpRequest<{ server_id: string; accounts: Sub2APIRemoteAccount[] }>(
851
- `/api/sub2api/servers/${serverId}/accounts`,
852
- );
853
- }
854
-
855
- export async function startSub2APIImport(serverId: string, accountIds: string[]) {
856
- return httpRequest<{ import_job: CPAImportJob | null }>(`/api/sub2api/servers/${serverId}/import`, {
857
- method: "POST",
858
- body: { account_ids: accountIds },
859
- });
860
- }
861
-
862
- export async function fetchSub2APIImportJob(serverId: string) {
863
- return httpRequest<{ import_job: CPAImportJob | null }>(`/api/sub2api/servers/${serverId}/import`);
864
- }
865
-
866
- // ── Upstream proxy ────────────────────────────────────────────────
867
-
868
- export type ProxySettings = {
869
- enabled: boolean;
870
- url: string;
871
- };
872
-
873
- export type ProxyTestResult = {
874
- ok: boolean;
875
- status: number;
876
- latency_ms: number;
877
- error: string | null;
878
- proxy_source?: string;
879
- has_proxy?: boolean;
880
- };
881
-
882
- export type ClearanceTestResult = {
883
- ok: boolean;
884
- status: string;
885
- latency_ms: number;
886
- has_cookies: boolean;
887
- user_agent: string;
888
- error: string | null;
889
- runtime: ProxyRuntimeStatus;
890
- };
891
-
892
- export async function fetchProxy() {
893
- return httpRequest<{ proxy: ProxySettings }>("/api/proxy");
894
- }
895
-
896
- export async function updateProxy(updates: { enabled?: boolean; url?: string }) {
897
- return httpRequest<{ proxy: ProxySettings }>("/api/proxy", {
898
- method: "POST",
899
- body: updates,
900
- });
901
- }
902
-
903
- export async function testProxy(url?: string) {
904
- return httpRequest<{ result: ProxyTestResult }>("/api/proxy/test", {
905
- method: "POST",
906
- body: { url: url ?? "" },
907
- });
908
- }
909
-
910
- export async function fetchProxyRuntime() {
911
- return httpRequest<ProxyRuntimeResponse>("/api/proxy/runtime");
912
- }
913
-
914
- export async function updateProxyRuntime(runtime: ProxyRuntimeSettings) {
915
- return httpRequest<ProxyRuntimeResponse>("/api/proxy/runtime", {
916
- method: "POST",
917
- body: runtime,
918
- });
919
- }
920
-
921
- export async function testProxyClearance(targetUrl?: string) {
922
- return httpRequest<{ result: ClearanceTestResult }>("/api/proxy/clearance/test", {
923
- method: "POST",
924
- body: { target_url: targetUrl ?? "https://chatgpt.com" },
925
- });
926
- }
1
+ import { httpRequest, request } from "@/lib/request";
2
+
3
+ export type AccountType = string;
4
+ export type AccountStatus = "正常" | "限流" | "异常" | "禁用";
5
+ export type ImageModel = string;
6
+ export type AuthRole = "admin" | "user";
7
+ export type ImageStorageMode = "local" | "webdav" | "both";
8
+
9
+ export type ImageStorageSettings = {
10
+ enabled: boolean;
11
+ mode: ImageStorageMode;
12
+ webdav_url: string;
13
+ webdav_username: string;
14
+ webdav_password: string;
15
+ webdav_root_path: string;
16
+ public_base_url: string;
17
+ };
18
+
19
+ export type Account = {
20
+ access_token: string;
21
+ type: AccountType;
22
+ source_type?: string | null;
23
+ status: AccountStatus;
24
+ quota: number;
25
+ email?: string | null;
26
+ user_id?: string | null;
27
+ limits_progress?: Array<{
28
+ feature_name?: string;
29
+ remaining?: number;
30
+ reset_after?: string;
31
+ }>;
32
+ default_model_slug?: string | null;
33
+ restore_at?: string | null;
34
+ success: number;
35
+ fail: number;
36
+ /** 当前图片在途数(正在生成、尚未结束的图片数)。号池空闲时持续 > 0 表示并发槽位泄漏。 */
37
+ image_inflight?: number;
38
+ last_used_at?: string | null;
39
+ proxy?: string | null;
40
+ };
41
+
42
+ export type AccountImportPayload = {
43
+ access_token: string;
44
+ accessToken?: string;
45
+ type?: string;
46
+ export_type?: string;
47
+ source_type?: string;
48
+ [key: string]: unknown;
49
+ };
50
+
51
+ export type Model = {
52
+ id: string;
53
+ object: string;
54
+ created: number;
55
+ owned_by: string;
56
+ permission: unknown[];
57
+ root: string;
58
+ parent: string | null;
59
+ };
60
+
61
+ type AccountListResponse = {
62
+ items: Account[];
63
+ };
64
+
65
+ type ModelListResponse = {
66
+ object: string;
67
+ data: Model[];
68
+ };
69
+
70
+ type AccountMutationResponse = {
71
+ items: Account[];
72
+ added?: number;
73
+ skipped?: number;
74
+ removed?: number;
75
+ refreshed?: number;
76
+ relogined?: number;
77
+ errors?: Array<{ access_token: string; error: string }>;
78
+ };
79
+
80
+ export type AccountRefreshResponse = {
81
+ items: Account[];
82
+ refreshed: number;
83
+ relogined?: number;
84
+ errors: Array<{ access_token: string; error: string }>;
85
+ };
86
+
87
+ export type RefreshProgressResponse = {
88
+ total: number;
89
+ processed: number;
90
+ done: boolean;
91
+ error: string | null;
92
+ status_counts?: Record<string, number>;
93
+ total_quota?: number;
94
+ result?: AccountRefreshResponse | null;
95
+ results?: Array<{ token: string; status: string; error?: string | null }>;
96
+ };
97
+
98
+ type AccountUpdateResponse = {
99
+ item: Account;
100
+ items: Account[];
101
+ };
102
+
103
+ export type ProxyRuntimeEgressMode = "direct" | "single_proxy";
104
+ export type ProxyRuntimeClearanceMode = "none" | "manual" | "flaresolverr";
105
+
106
+ export type ProxyRuntimeClearanceSettings = {
107
+ enabled: boolean;
108
+ mode: ProxyRuntimeClearanceMode;
109
+ cf_cookies: string;
110
+ cf_clearance: string;
111
+ user_agent: string;
112
+ browser: string;
113
+ flaresolverr_url: string;
114
+ timeout_sec: number | string;
115
+ refresh_interval: number | string;
116
+ warm_up_on_start: boolean;
117
+ has_cf_cookies?: boolean;
118
+ has_cf_clearance?: boolean;
119
+ };
120
+
121
+ export type ProxyRuntimeSettings = {
122
+ enabled: boolean;
123
+ egress_mode: ProxyRuntimeEgressMode;
124
+ proxy_url: string;
125
+ resource_proxy_url: string;
126
+ skip_ssl_verify: boolean;
127
+ reset_session_status_codes: number[];
128
+ clearance: ProxyRuntimeClearanceSettings;
129
+ };
130
+
131
+ export type ProxyRuntimeStatus = {
132
+ enabled: boolean;
133
+ egress_mode: ProxyRuntimeEgressMode | string;
134
+ proxy_source: string;
135
+ has_proxy: boolean;
136
+ clearance_enabled: boolean;
137
+ clearance_mode: ProxyRuntimeClearanceMode | string;
138
+ has_clearance_bundle: boolean;
139
+ cached_clearance_hosts: string[];
140
+ };
141
+
142
+ export type ProxyRuntimeResponse = {
143
+ runtime: ProxyRuntimeSettings;
144
+ status: ProxyRuntimeStatus;
145
+ };
146
+
147
+ export type ThirdPartyAppsSettings = {
148
+ infinite_canvas: {
149
+ enabled: boolean;
150
+ url: string;
151
+ };
152
+ };
153
+
154
+ export type SettingsConfig = {
155
+ proxy: string;
156
+ base_url?: string;
157
+ global_system_prompt?: string;
158
+ default_upstream_model_name?: string;
159
+ default_thinking_effort?: "auto" | "standard" | "extended" | "max";
160
+ sensitive_words?: string[];
161
+ ai_review?: {
162
+ enabled?: boolean;
163
+ base_url?: string;
164
+ api_key?: string;
165
+ model?: string;
166
+ prompt?: string;
167
+ };
168
+ refresh_account_interval_minute?: number | string;
169
+ image_retention_days?: number | string;
170
+ image_poll_timeout_secs?: number | string;
171
+ image_account_concurrency?: number | string;
172
+ image_parallel_generation?: boolean;
173
+ image_settle_enabled?: boolean;
174
+ image_check_before_hit_enabled?: boolean;
175
+ image_remove_conversation_after_result?: boolean;
176
+ image_remove_conversation_always?: boolean;
177
+ image_settle_secs?: number | string;
178
+ image_timeout_retry_secs?: number | string;
179
+ auto_remove_invalid_accounts?: boolean;
180
+ auto_remove_rate_limited_accounts?: boolean;
181
+ auto_relogin_after_refresh?: boolean;
182
+ log_levels?: string[];
183
+ image_storage?: ImageStorageSettings;
184
+ proxy_runtime?: ProxyRuntimeSettings;
185
+ third_party_apps?: ThirdPartyAppsSettings;
186
+ backup?: BackupSettings;
187
+ backup_state?: BackupState;
188
+ [key: string]: unknown;
189
+ };
190
+
191
+ export type BackupInclude = {
192
+ config: boolean;
193
+ cpa: boolean;
194
+ sub2api: boolean;
195
+ logs: boolean;
196
+ image_tasks: boolean;
197
+ accounts_snapshot: boolean;
198
+ auth_keys_snapshot: boolean;
199
+ images: boolean;
200
+ };
201
+
202
+ export type BackupSettings = {
203
+ enabled: boolean;
204
+ provider: "cloudflare_r2" | string;
205
+ account_id: string;
206
+ access_key_id: string;
207
+ secret_access_key: string;
208
+ bucket: string;
209
+ prefix: string;
210
+ interval_minutes: number | string;
211
+ rotation_keep: number | string;
212
+ encrypt: boolean;
213
+ passphrase: string;
214
+ include: BackupInclude;
215
+ };
216
+
217
+ export type BackupState = {
218
+ running: boolean;
219
+ last_started_at?: string | null;
220
+ last_finished_at?: string | null;
221
+ last_status?: string;
222
+ last_error?: string | null;
223
+ last_object_key?: string | null;
224
+ };
225
+
226
+ export type BackupItem = {
227
+ key: string;
228
+ name: string;
229
+ size: number;
230
+ updated_at?: string | null;
231
+ encrypted: boolean;
232
+ };
233
+
234
+ export type BackupDetail = {
235
+ key: string;
236
+ name: string;
237
+ encrypted: boolean;
238
+ created_at?: string | null;
239
+ trigger?: string | null;
240
+ app_version?: string | null;
241
+ storage_backend?: Record<string, unknown> | null;
242
+ files: Array<{
243
+ name: string;
244
+ exists: boolean;
245
+ content_type?: string;
246
+ size: number;
247
+ sha256?: string;
248
+ }>;
249
+ snapshots: Array<{
250
+ name: string;
251
+ count: number;
252
+ }>;
253
+ };
254
+
255
+ export type ManagedImage = {
256
+ rel: string;
257
+ path?: string;
258
+ name: string;
259
+ date: string;
260
+ size: number;
261
+ url: string;
262
+ thumbnail_url?: string;
263
+ created_at: string;
264
+ width?: number;
265
+ height?: number;
266
+ tags?: string[];
267
+ };
268
+
269
+ export type SystemLog = {
270
+ id: string;
271
+ time: string;
272
+ type: "call" | "account" | string;
273
+ summary?: string;
274
+ detail?: Record<string, unknown>;
275
+ [key: string]: unknown;
276
+ };
277
+
278
+ export type ImageResponse = {
279
+ created: number;
280
+ data: Array<{ b64_json?: string; url?: string; revised_prompt?: string }>;
281
+ };
282
+
283
+ export type ImageTask = {
284
+ id: string;
285
+ status: "queued" | "running" | "success" | "error";
286
+ mode: "generate" | "edit";
287
+ model?: ImageModel;
288
+ size?: string;
289
+ quality?: string;
290
+ created_at: string;
291
+ updated_at: string;
292
+ conversation_id?: string;
293
+ data?: Array<{ b64_json?: string; url?: string; revised_prompt?: string }>;
294
+ error?: string;
295
+ progress?: string;
296
+ elapsed_secs?: number;
297
+ duration_ms?: number;
298
+ };
299
+
300
+ type ImageTaskListResponse = {
301
+ items: ImageTask[];
302
+ missing_ids: string[];
303
+ };
304
+
305
+ export type LoginResponse = {
306
+ ok: boolean;
307
+ version: string;
308
+ role: AuthRole;
309
+ subject_id: string;
310
+ name: string;
311
+ };
312
+
313
+ export type UserKey = {
314
+ id: string;
315
+ name: string;
316
+ role: "user";
317
+ enabled: boolean;
318
+ created_at: string | null;
319
+ last_used_at: string | null;
320
+ };
321
+
322
+ export async function login(authKey: string) {
323
+ const normalizedAuthKey = String(authKey || "").trim();
324
+ return httpRequest<LoginResponse>("/auth/login", {
325
+ method: "POST",
326
+ body: {},
327
+ headers: {
328
+ Authorization: `Bearer ${normalizedAuthKey}`,
329
+ },
330
+ redirectOnUnauthorized: false,
331
+ });
332
+ }
333
+
334
+ export async function fetchAccounts() {
335
+ return httpRequest<AccountListResponse>("/api/accounts");
336
+ }
337
+
338
+ export async function fetchModels() {
339
+ return httpRequest<ModelListResponse>("/v1/models");
340
+ }
341
+
342
+ export async function createAccounts(tokens: string[], accounts: AccountImportPayload[] = []) {
343
+ return httpRequest<AccountMutationResponse>("/api/accounts", {
344
+ method: "POST",
345
+ body: { tokens, accounts },
346
+ });
347
+ }
348
+
349
+ export type OAuthLoginStartResponse = {
350
+ session_id: string;
351
+ authorize_url: string;
352
+ expires_in: string;
353
+ redirect_uri_prefix: string;
354
+ };
355
+
356
+ export async function startOAuthLogin(emailHint?: string) {
357
+ return httpRequest<OAuthLoginStartResponse>("/api/accounts/oauth/start", {
358
+ method: "POST",
359
+ body: { email_hint: emailHint ?? "" },
360
+ });
361
+ }
362
+
363
+ export async function finishOAuthLogin(sessionId: string, callback: string) {
364
+ return httpRequest<AccountMutationResponse>("/api/accounts/oauth/finish", {
365
+ method: "POST",
366
+ body: { session_id: sessionId, callback },
367
+ });
368
+ }
369
+
370
+ export async function deleteAccounts(tokens: string[]) {
371
+ return httpRequest<AccountMutationResponse>("/api/accounts", {
372
+ method: "DELETE",
373
+ body: { tokens },
374
+ });
375
+ }
376
+
377
+ export async function refreshAccounts(accessTokens: string[]) {
378
+ return httpRequest<{ progress_id: string }>("/api/accounts/refresh", {
379
+ method: "POST",
380
+ body: { access_tokens: accessTokens },
381
+ });
382
+ }
383
+
384
+ export async function fetchRefreshProgress(progressId: string) {
385
+ return httpRequest<RefreshProgressResponse>(`/api/accounts/refresh/progress/${progressId}`);
386
+ }
387
+
388
+ export async function reLoginAccounts(accessTokens: string[]) {
389
+ return httpRequest<{ progress_id: string }>("/api/accounts/re-login", {
390
+ method: "POST",
391
+ body: { access_tokens: accessTokens },
392
+ });
393
+ }
394
+
395
+ export async function fetchReLoginProgress(progressId: string) {
396
+ return httpRequest<RefreshProgressResponse>(`/api/accounts/re-login/progress/${progressId}`);
397
+ }
398
+
399
+ export async function updateAccount(
400
+ accessToken: string,
401
+ updates: {
402
+ type?: AccountType;
403
+ status?: AccountStatus;
404
+ quota?: number;
405
+ proxy?: string;
406
+ },
407
+ ) {
408
+ return httpRequest<AccountUpdateResponse>("/api/accounts/update", {
409
+ method: "POST",
410
+ body: {
411
+ access_token: accessToken,
412
+ ...updates,
413
+ },
414
+ });
415
+ }
416
+
417
+ export async function generateImage(prompt: string, model?: ImageModel, size?: string, quality = "auto") {
418
+ return httpRequest<ImageResponse>(
419
+ "/v1/images/generations",
420
+ {
421
+ method: "POST",
422
+ body: {
423
+ prompt,
424
+ ...(model ? { model } : {}),
425
+ ...(size ? { size } : {}),
426
+ quality,
427
+ n: 1,
428
+ response_format: "b64_json",
429
+ },
430
+ },
431
+ );
432
+ }
433
+
434
+ export async function editImage(files: File | File[], prompt: string, model?: ImageModel, size?: string, quality = "auto") {
435
+ const formData = new FormData();
436
+ const uploadFiles = Array.isArray(files) ? files : [files];
437
+
438
+ uploadFiles.forEach((file) => {
439
+ formData.append("image", file);
440
+ });
441
+ formData.append("prompt", prompt);
442
+ if (model) {
443
+ formData.append("model", model);
444
+ }
445
+ if (size) {
446
+ formData.append("size", size);
447
+ }
448
+ formData.append("quality", quality);
449
+ formData.append("n", "1");
450
+
451
+ return httpRequest<ImageResponse>(
452
+ "/v1/images/edits",
453
+ {
454
+ method: "POST",
455
+ body: formData,
456
+ },
457
+ );
458
+ }
459
+
460
+ export async function createImageGenerationTask(clientTaskId: string, prompt: string, model?: ImageModel, size?: string, quality = "auto") {
461
+ return httpRequest<ImageTask>("/api/image-tasks/generations", {
462
+ method: "POST",
463
+ body: {
464
+ client_task_id: clientTaskId,
465
+ prompt,
466
+ ...(model ? { model } : {}),
467
+ ...(size ? { size } : {}),
468
+ quality,
469
+ },
470
+ });
471
+ }
472
+
473
+ export async function createImageEditTask(
474
+ clientTaskId: string,
475
+ files: File | File[],
476
+ prompt: string,
477
+ model?: ImageModel,
478
+ size?: string,
479
+ quality = "auto",
480
+ ) {
481
+ const formData = new FormData();
482
+ const uploadFiles = Array.isArray(files) ? files : [files];
483
+
484
+ uploadFiles.forEach((file) => {
485
+ formData.append("image", file);
486
+ });
487
+ formData.append("client_task_id", clientTaskId);
488
+ formData.append("prompt", prompt);
489
+ if (model) {
490
+ formData.append("model", model);
491
+ }
492
+ if (size) {
493
+ formData.append("size", size);
494
+ }
495
+ formData.append("quality", quality);
496
+
497
+ return httpRequest<ImageTask>("/api/image-tasks/edits", {
498
+ method: "POST",
499
+ body: formData,
500
+ });
501
+ }
502
+
503
+ export async function fetchImageTasks(ids: string[]) {
504
+ const params = new URLSearchParams();
505
+ if (ids.length > 0) {
506
+ params.set("ids", ids.join(","));
507
+ }
508
+ params.set("_t", String(Date.now()));
509
+ return httpRequest<ImageTaskListResponse>(`/api/image-tasks?${params.toString()}`);
510
+ }
511
+
512
+ export async function resumeImagePoll(taskId: string, extraTimeoutSecs = 30) {
513
+ return httpRequest<ImageTask>(`/api/image-tasks/${encodeURIComponent(taskId)}/resume-poll`, {
514
+ method: "POST",
515
+ body: { extra_timeout_secs: extraTimeoutSecs },
516
+ });
517
+ }
518
+
519
+ export async function fetchSettingsConfig() {
520
+ return httpRequest<{ config: SettingsConfig }>("/api/settings");
521
+ }
522
+
523
+ export async function updateSettingsConfig(settings: SettingsConfig) {
524
+ return httpRequest<{ config: SettingsConfig }>("/api/settings", {
525
+ method: "POST",
526
+ body: settings,
527
+ });
528
+ }
529
+
530
+ export async function fetchThirdPartyApps() {
531
+ return httpRequest<{ third_party_apps: ThirdPartyAppsSettings }>("/api/third-party-apps");
532
+ }
533
+
534
+ export async function testBackupConnection() {
535
+ return httpRequest<{ result: { ok: boolean; status: number } }>("/api/backup/test", {
536
+ method: "POST",
537
+ body: {},
538
+ });
539
+ }
540
+
541
+ export async function testImageStorageConnection() {
542
+ return httpRequest<{ result: { ok: boolean; status: number; error?: string } }>("/api/image-storage/test", {
543
+ method: "POST",
544
+ body: {},
545
+ });
546
+ }
547
+
548
+ export async function syncImageStorage() {
549
+ return httpRequest<{ result: { uploaded: number; skipped: number; failed: number } }>("/api/image-storage/sync", {
550
+ method: "POST",
551
+ body: {},
552
+ });
553
+ }
554
+
555
+ export async function fetchBackups() {
556
+ return httpRequest<{ items: BackupItem[]; state: BackupState; settings: BackupSettings }>("/api/backups");
557
+ }
558
+
559
+ export async function runBackupNow() {
560
+ return httpRequest<{ result: { key: string; size: number; encrypted: boolean } }>("/api/backups/run", {
561
+ method: "POST",
562
+ body: {},
563
+ });
564
+ }
565
+
566
+ export async function deleteBackup(key: string) {
567
+ return httpRequest<{ ok: boolean }>("/api/backups/delete", {
568
+ method: "POST",
569
+ body: { key },
570
+ });
571
+ }
572
+
573
+ export async function fetchBackupDetail(key: string) {
574
+ const params = new URLSearchParams();
575
+ params.set("key", key);
576
+ return httpRequest<{ item: BackupDetail }>(`/api/backups/detail?${params.toString()}`);
577
+ }
578
+
579
+ export function getBackupDownloadUrl(key: string) {
580
+ const params = new URLSearchParams();
581
+ params.set("key", key);
582
+ return `/api/backups/download?${params.toString()}`;
583
+ }
584
+
585
+ export async function fetchManagedImages(filters: { start_date?: string; end_date?: string }) {
586
+ const params = new URLSearchParams();
587
+ if (filters.start_date) params.set("start_date", filters.start_date);
588
+ if (filters.end_date) params.set("end_date", filters.end_date);
589
+ return httpRequest<{ items: ManagedImage[]; groups: Array<{ date: string; items: ManagedImage[] }> }>(
590
+ `/api/images${params.toString() ? `?${params.toString()}` : ""}`,
591
+ );
592
+ }
593
+
594
+ export async function deleteManagedImages(body: { paths?: string[]; start_date?: string; end_date?: string; all_matching?: boolean }) {
595
+ return httpRequest<{ removed: number }>("/api/images/delete", { method: "POST", body });
596
+ }
597
+
598
+ export async function downloadImages(paths: string[]) {
599
+ const response = await request.post("/api/images/download", { paths }, { responseType: "blob" });
600
+ const blob = response.data as Blob;
601
+ const url = URL.createObjectURL(blob);
602
+ const a = document.createElement("a");
603
+ a.href = url;
604
+ a.download = "images.zip";
605
+ document.body.appendChild(a);
606
+ a.click();
607
+ document.body.removeChild(a);
608
+ URL.revokeObjectURL(url);
609
+ }
610
+
611
+ export async function downloadSingleImage(path: string) {
612
+ const response = await request.get(`/api/images/download/${path}`, { responseType: "blob" });
613
+ const blob = response.data as Blob;
614
+ const url = URL.createObjectURL(blob);
615
+ const a = document.createElement("a");
616
+ a.href = url;
617
+ a.download = path.split("/").pop() || "image.png";
618
+ document.body.appendChild(a);
619
+ a.click();
620
+ document.body.removeChild(a);
621
+ URL.revokeObjectURL(url);
622
+ }
623
+
624
+ export async function fetchImageTags() {
625
+ return httpRequest<{ tags: string[] }>("/api/images/tags");
626
+ }
627
+
628
+ export async function setImageTags(path: string, tags: string[]) {
629
+ return httpRequest<{ ok: boolean; tags: string[] }>("/api/images/tags", {
630
+ method: "POST",
631
+ body: { path, tags },
632
+ });
633
+ }
634
+
635
+ export async function deleteImageTag(tag: string) {
636
+ return httpRequest<{ ok: boolean; removed_from: number }>(`/api/images/tags/${encodeURIComponent(tag)}`, {
637
+ method: "DELETE",
638
+ });
639
+ }
640
+
641
+ export type ImageStorageStats = {
642
+ disk_total_mb: number; disk_used_mb: number; disk_free_mb: number;
643
+ image_count: number; image_size_mb: number; image_size_bytes: number;
644
+ };
645
+
646
+ export async function fetchImageStorage() {
647
+ return httpRequest<ImageStorageStats>("/api/images/storage");
648
+ }
649
+
650
+ export async function compressAllImages() {
651
+ return httpRequest<{ compressed: number; saved_bytes: number; saved_mb: number }>("/api/images/storage/compress", { method: "POST" });
652
+ }
653
+
654
+ export async function deleteToTarget(targetFreeMb: number) {
655
+ return httpRequest<{ removed: number; freed_mb: number; done: boolean }>(
656
+ `/api/images/storage/cleanup-to-target?target_free_mb=${targetFreeMb}&dry_run=false`,
657
+ { method: "POST" },
658
+ );
659
+ }
660
+
661
+ export async function fetchSystemLogs(filters: { type?: string; start_date?: string; end_date?: string }) {
662
+ const params = new URLSearchParams();
663
+ if (filters.type) params.set("type", filters.type);
664
+ if (filters.start_date) params.set("start_date", filters.start_date);
665
+ if (filters.end_date) params.set("end_date", filters.end_date);
666
+ return httpRequest<{ items: SystemLog[] }>(`/api/logs${params.toString() ? `?${params.toString()}` : ""}`);
667
+ }
668
+
669
+ export async function deleteSystemLogs(ids: string[]) {
670
+ return httpRequest<{ removed: number }>("/api/logs/delete", {
671
+ method: "POST",
672
+ body: { ids },
673
+ });
674
+ }
675
+
676
+ export async function fetchUserKeys() {
677
+ return httpRequest<{ items: UserKey[] }>("/api/auth/users");
678
+ }
679
+
680
+ export async function createUserKey(name: string) {
681
+ return httpRequest<{ item: UserKey; key: string; items: UserKey[] }>("/api/auth/users", {
682
+ method: "POST",
683
+ body: { name },
684
+ });
685
+ }
686
+
687
+ export async function updateUserKey(keyId: string, updates: { enabled?: boolean; name?: string; key?: string }) {
688
+ return httpRequest<{ item: UserKey; items: UserKey[] }>(`/api/auth/users/${keyId}`, {
689
+ method: "POST",
690
+ body: updates,
691
+ });
692
+ }
693
+
694
+ export async function deleteUserKey(keyId: string) {
695
+ return httpRequest<{ items: UserKey[] }>(`/api/auth/users/${keyId}`, {
696
+ method: "DELETE",
697
+ });
698
+ }
699
+
700
+ // ── CPA (CLIProxyAPI) ──────────────────────────────────────────────
701
+
702
+ export type CPAPool = {
703
+ id: string;
704
+ name: string;
705
+ base_url: string;
706
+ import_job?: CPAImportJob | null;
707
+ };
708
+
709
+ export type CPARemoteFile = {
710
+ name: string;
711
+ email: string;
712
+ };
713
+
714
+ export type CPAImportJob = {
715
+ job_id: string;
716
+ status: "pending" | "running" | "completed" | "failed";
717
+ created_at: string;
718
+ updated_at: string;
719
+ total: number;
720
+ completed: number;
721
+ added: number;
722
+ skipped: number;
723
+ refreshed: number;
724
+ failed: number;
725
+ errors: Array<{ name: string; error: string }>;
726
+ };
727
+
728
+ export async function fetchCPAPools() {
729
+ return httpRequest<{ pools: CPAPool[] }>("/api/cpa/pools");
730
+ }
731
+
732
+ export async function createCPAPool(pool: { name: string; base_url: string; secret_key: string }) {
733
+ return httpRequest<{ pool: CPAPool; pools: CPAPool[] }>("/api/cpa/pools", {
734
+ method: "POST",
735
+ body: pool,
736
+ });
737
+ }
738
+
739
+ export async function updateCPAPool(
740
+ poolId: string,
741
+ updates: { name?: string; base_url?: string; secret_key?: string },
742
+ ) {
743
+ return httpRequest<{ pool: CPAPool; pools: CPAPool[] }>(`/api/cpa/pools/${poolId}`, {
744
+ method: "POST",
745
+ body: updates,
746
+ });
747
+ }
748
+
749
+ export async function deleteCPAPool(poolId: string) {
750
+ return httpRequest<{ pools: CPAPool[] }>(`/api/cpa/pools/${poolId}`, {
751
+ method: "DELETE",
752
+ });
753
+ }
754
+
755
+ export async function fetchCPAPoolFiles(poolId: string) {
756
+ return httpRequest<{ pool_id: string; files: CPARemoteFile[] }>(`/api/cpa/pools/${poolId}/files`);
757
+ }
758
+
759
+ export async function startCPAImport(poolId: string, names: string[]) {
760
+ return httpRequest<{ import_job: CPAImportJob | null }>(`/api/cpa/pools/${poolId}/import`, {
761
+ method: "POST",
762
+ body: { names },
763
+ });
764
+ }
765
+
766
+ export async function fetchCPAPoolImportJob(poolId: string) {
767
+ return httpRequest<{ import_job: CPAImportJob | null }>(`/api/cpa/pools/${poolId}/import`);
768
+ }
769
+
770
+ // ── Sub2API ────────────────────────────────────────────────────────
771
+
772
+ export type Sub2APIServer = {
773
+ id: string;
774
+ name: string;
775
+ base_url: string;
776
+ email: string;
777
+ has_api_key: boolean;
778
+ group_id: string;
779
+ import_job?: CPAImportJob | null;
780
+ };
781
+
782
+ export type Sub2APIRemoteAccount = {
783
+ id: string;
784
+ name: string;
785
+ email: string;
786
+ plan_type: string;
787
+ status: string;
788
+ expires_at: string;
789
+ has_refresh_token: boolean;
790
+ };
791
+
792
+ export type Sub2APIRemoteGroup = {
793
+ id: string;
794
+ name: string;
795
+ description: string;
796
+ platform: string;
797
+ status: string;
798
+ account_count: number;
799
+ active_account_count: number;
800
+ };
801
+
802
+ export async function fetchSub2APIServers() {
803
+ return httpRequest<{ servers: Sub2APIServer[] }>("/api/sub2api/servers");
804
+ }
805
+
806
+ export async function createSub2APIServer(server: {
807
+ name: string;
808
+ base_url: string;
809
+ email: string;
810
+ password: string;
811
+ api_key: string;
812
+ group_id: string;
813
+ }) {
814
+ return httpRequest<{ server: Sub2APIServer; servers: Sub2APIServer[] }>("/api/sub2api/servers", {
815
+ method: "POST",
816
+ body: server,
817
+ });
818
+ }
819
+
820
+ export async function updateSub2APIServer(
821
+ serverId: string,
822
+ updates: {
823
+ name?: string;
824
+ base_url?: string;
825
+ email?: string;
826
+ password?: string;
827
+ api_key?: string;
828
+ group_id?: string;
829
+ },
830
+ ) {
831
+ return httpRequest<{ server: Sub2APIServer; servers: Sub2APIServer[] }>(`/api/sub2api/servers/${serverId}`, {
832
+ method: "POST",
833
+ body: updates,
834
+ });
835
+ }
836
+
837
+ export async function fetchSub2APIServerGroups(serverId: string) {
838
+ return httpRequest<{ server_id: string; groups: Sub2APIRemoteGroup[] }>(
839
+ `/api/sub2api/servers/${serverId}/groups`,
840
+ );
841
+ }
842
+
843
+ export async function deleteSub2APIServer(serverId: string) {
844
+ return httpRequest<{ servers: Sub2APIServer[] }>(`/api/sub2api/servers/${serverId}`, {
845
+ method: "DELETE",
846
+ });
847
+ }
848
+
849
+ export async function fetchSub2APIServerAccounts(serverId: string) {
850
+ return httpRequest<{ server_id: string; accounts: Sub2APIRemoteAccount[] }>(
851
+ `/api/sub2api/servers/${serverId}/accounts`,
852
+ );
853
+ }
854
+
855
+ export async function startSub2APIImport(serverId: string, accountIds: string[]) {
856
+ return httpRequest<{ import_job: CPAImportJob | null }>(`/api/sub2api/servers/${serverId}/import`, {
857
+ method: "POST",
858
+ body: { account_ids: accountIds },
859
+ });
860
+ }
861
+
862
+ export async function fetchSub2APIImportJob(serverId: string) {
863
+ return httpRequest<{ import_job: CPAImportJob | null }>(`/api/sub2api/servers/${serverId}/import`);
864
+ }
865
+
866
+ // ── Upstream proxy ────────────────────────────────────────────────
867
+
868
+ export type ProxySettings = {
869
+ enabled: boolean;
870
+ url: string;
871
+ };
872
+
873
+ export type ProxyTestResult = {
874
+ ok: boolean;
875
+ status: number;
876
+ latency_ms: number;
877
+ error: string | null;
878
+ proxy_source?: string;
879
+ has_proxy?: boolean;
880
+ };
881
+
882
+ export type ClearanceTestResult = {
883
+ ok: boolean;
884
+ status: string;
885
+ latency_ms: number;
886
+ has_cookies: boolean;
887
+ user_agent: string;
888
+ error: string | null;
889
+ runtime: ProxyRuntimeStatus;
890
+ };
891
+
892
+ export async function fetchProxy() {
893
+ return httpRequest<{ proxy: ProxySettings }>("/api/proxy");
894
+ }
895
+
896
+ export async function updateProxy(updates: { enabled?: boolean; url?: string }) {
897
+ return httpRequest<{ proxy: ProxySettings }>("/api/proxy", {
898
+ method: "POST",
899
+ body: updates,
900
+ });
901
+ }
902
+
903
+ export async function testProxy(url?: string) {
904
+ return httpRequest<{ result: ProxyTestResult }>("/api/proxy/test", {
905
+ method: "POST",
906
+ body: { url: url ?? "" },
907
+ });
908
+ }
909
+
910
+ export async function fetchProxyRuntime() {
911
+ return httpRequest<ProxyRuntimeResponse>("/api/proxy/runtime");
912
+ }
913
+
914
+ export async function updateProxyRuntime(runtime: ProxyRuntimeSettings) {
915
+ return httpRequest<ProxyRuntimeResponse>("/api/proxy/runtime", {
916
+ method: "POST",
917
+ body: runtime,
918
+ });
919
+ }
920
+
921
+ export async function testProxyClearance(targetUrl?: string) {
922
+ return httpRequest<{ result: ClearanceTestResult }>("/api/proxy/clearance/test", {
923
+ method: "POST",
924
+ body: { target_url: targetUrl ?? "https://chatgpt.com" },
925
+ });
926
+ }