dsh-plugin-image-workbench 1.1.5 → 1.1.7

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 (173) 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 +1371 -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/server/static/index.html +15 -0
  25. package/vendor/chatgpt2api/source/.env.example +82 -82
  26. package/vendor/chatgpt2api/source/.python-version +1 -1
  27. package/vendor/chatgpt2api/source/LICENSE +21 -21
  28. package/vendor/chatgpt2api/source/README.md +391 -391
  29. package/vendor/chatgpt2api/source/VERSION +1 -1
  30. package/vendor/chatgpt2api/source/api/__init__.py +2 -2
  31. package/vendor/chatgpt2api/source/api/accounts.py +537 -537
  32. package/vendor/chatgpt2api/source/api/ai.py +217 -217
  33. package/vendor/chatgpt2api/source/api/app.py +62 -62
  34. package/vendor/chatgpt2api/source/api/errors.py +46 -46
  35. package/vendor/chatgpt2api/source/api/image_inputs.py +309 -309
  36. package/vendor/chatgpt2api/source/api/image_tasks.py +120 -120
  37. package/vendor/chatgpt2api/source/api/support.py +134 -134
  38. package/vendor/chatgpt2api/source/api/system.py +365 -365
  39. package/vendor/chatgpt2api/source/assets/kunrouai.svg +50 -50
  40. package/vendor/chatgpt2api/source/config.default.json +108 -108
  41. package/vendor/chatgpt2api/source/main.py +9 -9
  42. package/vendor/chatgpt2api/source/pyproject.toml +27 -27
  43. package/vendor/chatgpt2api/source/scripts/init_proxy_config.py +186 -186
  44. package/vendor/chatgpt2api/source/scripts/migrate_storage.py +163 -163
  45. package/vendor/chatgpt2api/source/scripts/privoxy-warp.conf +13 -13
  46. package/vendor/chatgpt2api/source/scripts/test_outlook_token_mailbox.py +385 -385
  47. package/vendor/chatgpt2api/source/scripts/test_storage.py +129 -129
  48. package/vendor/chatgpt2api/source/scripts/verify_oauth_refresh.py +92 -92
  49. package/vendor/chatgpt2api/source/services/account_service.py +1757 -1757
  50. package/vendor/chatgpt2api/source/services/auth_service.py +253 -253
  51. package/vendor/chatgpt2api/source/services/backup_service.py +671 -671
  52. package/vendor/chatgpt2api/source/services/config.py +667 -667
  53. package/vendor/chatgpt2api/source/services/content_filter.py +242 -242
  54. package/vendor/chatgpt2api/source/services/cpa_service.py +315 -315
  55. package/vendor/chatgpt2api/source/services/editable_file_task_service.py +260 -260
  56. package/vendor/chatgpt2api/source/services/image_service.py +376 -376
  57. package/vendor/chatgpt2api/source/services/image_storage_service.py +405 -405
  58. package/vendor/chatgpt2api/source/services/image_tags_service.py +76 -76
  59. package/vendor/chatgpt2api/source/services/image_task_service.py +550 -550
  60. package/vendor/chatgpt2api/source/services/log_service.py +337 -337
  61. package/vendor/chatgpt2api/source/services/model_service.py +182 -182
  62. package/vendor/chatgpt2api/source/services/oauth_login_service.py +267 -267
  63. package/vendor/chatgpt2api/source/services/openai_backend_api.py +2763 -2763
  64. package/vendor/chatgpt2api/source/services/openai_oauth.py +32 -32
  65. package/vendor/chatgpt2api/source/services/protocol/__init__.py +2 -2
  66. package/vendor/chatgpt2api/source/services/protocol/anthropic_v1_messages.py +307 -307
  67. package/vendor/chatgpt2api/source/services/protocol/chat_completion_cache.py +238 -238
  68. package/vendor/chatgpt2api/source/services/protocol/conversation.py +1644 -1644
  69. package/vendor/chatgpt2api/source/services/protocol/error_response.py +124 -124
  70. package/vendor/chatgpt2api/source/services/protocol/openai_search.py +19 -19
  71. package/vendor/chatgpt2api/source/services/protocol/openai_v1_chat_complete.py +316 -316
  72. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_edit.py +86 -86
  73. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_generations.py +42 -42
  74. package/vendor/chatgpt2api/source/services/protocol/openai_v1_models.py +53 -53
  75. package/vendor/chatgpt2api/source/services/protocol/openai_v1_response.py +453 -453
  76. package/vendor/chatgpt2api/source/services/protocol/web_search_tool.py +160 -160
  77. package/vendor/chatgpt2api/source/services/proxy_service.py +648 -648
  78. package/vendor/chatgpt2api/source/services/storage/__init__.py +5 -5
  79. package/vendor/chatgpt2api/source/services/storage/base.py +38 -38
  80. package/vendor/chatgpt2api/source/services/storage/database_storage.py +194 -194
  81. package/vendor/chatgpt2api/source/services/storage/factory.py +104 -104
  82. package/vendor/chatgpt2api/source/services/storage/git_storage.py +183 -183
  83. package/vendor/chatgpt2api/source/services/storage/json_storage.py +95 -95
  84. package/vendor/chatgpt2api/source/services/sub2api_service.py +531 -531
  85. package/vendor/chatgpt2api/source/utils/helper.py +469 -469
  86. package/vendor/chatgpt2api/source/utils/image_tokens.py +346 -346
  87. package/vendor/chatgpt2api/source/utils/log.py +110 -110
  88. package/vendor/chatgpt2api/source/utils/pkce.py +19 -19
  89. package/vendor/chatgpt2api/source/utils/pow.py +207 -207
  90. package/vendor/chatgpt2api/source/utils/sentinel.py +159 -159
  91. package/vendor/chatgpt2api/source/utils/turnstile.py +184 -184
  92. package/vendor/chatgpt2api/source/uv.lock +904 -904
  93. package/vendor/chatgpt2api/source/web/bun.lock +1501 -1501
  94. package/vendor/chatgpt2api/source/web/components.json +24 -24
  95. package/vendor/chatgpt2api/source/web/eslint.config.mjs +17 -17
  96. package/vendor/chatgpt2api/source/web/next.config.ts +40 -40
  97. package/vendor/chatgpt2api/source/web/package.json +58 -58
  98. package/vendor/chatgpt2api/source/web/postcss.config.mjs +5 -5
  99. package/vendor/chatgpt2api/source/web/src/app/accounts/components/account-import-dialog.tsx +925 -925
  100. package/vendor/chatgpt2api/source/web/src/app/accounts/page.tsx +1307 -1307
  101. package/vendor/chatgpt2api/source/web/src/app/debug/components/chat-panel.tsx +224 -224
  102. package/vendor/chatgpt2api/source/web/src/app/debug/components/editable-file-panel.tsx +444 -444
  103. package/vendor/chatgpt2api/source/web/src/app/debug/components/ppt-panel.tsx +9 -9
  104. package/vendor/chatgpt2api/source/web/src/app/debug/components/psd-panel.tsx +9 -9
  105. package/vendor/chatgpt2api/source/web/src/app/debug/components/search-panel.tsx +172 -172
  106. package/vendor/chatgpt2api/source/web/src/app/debug/components/skill-panel.tsx +169 -169
  107. package/vendor/chatgpt2api/source/web/src/app/debug/components/types.ts +39 -39
  108. package/vendor/chatgpt2api/source/web/src/app/debug/page.tsx +59 -59
  109. package/vendor/chatgpt2api/source/web/src/app/globals.css +230 -230
  110. package/vendor/chatgpt2api/source/web/src/app/image/components/image-composer.tsx +542 -542
  111. package/vendor/chatgpt2api/source/web/src/app/image/components/image-results.tsx +554 -554
  112. package/vendor/chatgpt2api/source/web/src/app/image/components/image-sidebar.tsx +176 -176
  113. package/vendor/chatgpt2api/source/web/src/app/image/page.tsx +1799 -1799
  114. package/vendor/chatgpt2api/source/web/src/app/image-manager/page.tsx +732 -732
  115. package/vendor/chatgpt2api/source/web/src/app/layout.tsx +50 -50
  116. package/vendor/chatgpt2api/source/web/src/app/login/page.tsx +101 -101
  117. package/vendor/chatgpt2api/source/web/src/app/logs/page.tsx +356 -356
  118. package/vendor/chatgpt2api/source/web/src/app/page.tsx +30 -30
  119. package/vendor/chatgpt2api/source/web/src/app/settings/components/api-docs-card.tsx +341 -341
  120. package/vendor/chatgpt2api/source/web/src/app/settings/components/backup-settings-card.tsx +447 -447
  121. package/vendor/chatgpt2api/source/web/src/app/settings/components/base-url-card.tsx +71 -71
  122. package/vendor/chatgpt2api/source/web/src/app/settings/components/config-card.tsx +491 -491
  123. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pool-dialog.tsx +108 -108
  124. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pools-card.tsx +169 -169
  125. package/vendor/chatgpt2api/source/web/src/app/settings/components/import-browser-dialog.tsx +185 -185
  126. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-runtime-card.tsx +379 -379
  127. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings-card.tsx +127 -127
  128. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings.tsx +200 -200
  129. package/vendor/chatgpt2api/source/web/src/app/settings/components/settings-header.tsx +12 -12
  130. package/vendor/chatgpt2api/source/web/src/app/settings/components/sub2api-connections.tsx +886 -886
  131. package/vendor/chatgpt2api/source/web/src/app/settings/components/third-party-apps-card.tsx +81 -81
  132. package/vendor/chatgpt2api/source/web/src/app/settings/components/user-keys-card.tsx +422 -422
  133. package/vendor/chatgpt2api/source/web/src/app/settings/page.tsx +135 -135
  134. package/vendor/chatgpt2api/source/web/src/app/settings/store.ts +1069 -1069
  135. package/vendor/chatgpt2api/source/web/src/components/date-range-filter.tsx +49 -49
  136. package/vendor/chatgpt2api/source/web/src/components/header-actions.tsx +24 -24
  137. package/vendor/chatgpt2api/source/web/src/components/image-lightbox.tsx +434 -434
  138. package/vendor/chatgpt2api/source/web/src/components/image-thumbnail.tsx +46 -46
  139. package/vendor/chatgpt2api/source/web/src/components/theme-script.tsx +18 -18
  140. package/vendor/chatgpt2api/source/web/src/components/theme-toggle.tsx +14 -14
  141. package/vendor/chatgpt2api/source/web/src/components/top-nav.tsx +263 -263
  142. package/vendor/chatgpt2api/source/web/src/components/ui/animated-theme-toggler.tsx +256 -256
  143. package/vendor/chatgpt2api/source/web/src/components/ui/badge.tsx +41 -41
  144. package/vendor/chatgpt2api/source/web/src/components/ui/button.tsx +59 -59
  145. package/vendor/chatgpt2api/source/web/src/components/ui/calendar.tsx +46 -46
  146. package/vendor/chatgpt2api/source/web/src/components/ui/card.tsx +61 -61
  147. package/vendor/chatgpt2api/source/web/src/components/ui/checkbox.tsx +27 -27
  148. package/vendor/chatgpt2api/source/web/src/components/ui/dia-text-reveal.tsx +267 -267
  149. package/vendor/chatgpt2api/source/web/src/components/ui/dialog.tsx +132 -132
  150. package/vendor/chatgpt2api/source/web/src/components/ui/field.tsx +13 -13
  151. package/vendor/chatgpt2api/source/web/src/components/ui/input.tsx +19 -19
  152. package/vendor/chatgpt2api/source/web/src/components/ui/label.tsx +24 -24
  153. package/vendor/chatgpt2api/source/web/src/components/ui/morphing-text.tsx +149 -149
  154. package/vendor/chatgpt2api/source/web/src/components/ui/popover.tsx +38 -38
  155. package/vendor/chatgpt2api/source/web/src/components/ui/select.tsx +175 -175
  156. package/vendor/chatgpt2api/source/web/src/components/ui/sheet.tsx +143 -143
  157. package/vendor/chatgpt2api/source/web/src/components/ui/table.tsx +29 -29
  158. package/vendor/chatgpt2api/source/web/src/components/ui/tabs.tsx +91 -91
  159. package/vendor/chatgpt2api/source/web/src/components/ui/text-3d-flip.tsx +269 -269
  160. package/vendor/chatgpt2api/source/web/src/components/ui/textarea.tsx +18 -18
  161. package/vendor/chatgpt2api/source/web/src/components/version-release-dialog.tsx +127 -127
  162. package/vendor/chatgpt2api/source/web/src/constants/common-env.ts +6 -6
  163. package/vendor/chatgpt2api/source/web/src/hooks/use-version-check.ts +85 -85
  164. package/vendor/chatgpt2api/source/web/src/lib/api.ts +926 -926
  165. package/vendor/chatgpt2api/source/web/src/lib/auth-session.ts +26 -26
  166. package/vendor/chatgpt2api/source/web/src/lib/release.ts +25 -25
  167. package/vendor/chatgpt2api/source/web/src/lib/request.ts +93 -93
  168. package/vendor/chatgpt2api/source/web/src/lib/use-auth-guard.ts +89 -89
  169. package/vendor/chatgpt2api/source/web/src/lib/utils.ts +6 -6
  170. package/vendor/chatgpt2api/source/web/src/store/auth.ts +112 -112
  171. package/vendor/chatgpt2api/source/web/src/store/editable-file-history.ts +33 -33
  172. package/vendor/chatgpt2api/source/web/src/store/image-conversations.ts +318 -318
  173. package/vendor/chatgpt2api/source/web/tsconfig.json +42 -42
@@ -1,379 +1,379 @@
1
- "use client";
2
-
3
- import { AlertTriangle, Cookie, LoaderCircle, PlugZap, Save, ShieldCheck } from "lucide-react";
4
- import { useState } from "react";
5
- import { toast } from "sonner";
6
-
7
- import { Button } from "@/components/ui/button";
8
- import { Card, CardContent } from "@/components/ui/card";
9
- import { Checkbox } from "@/components/ui/checkbox";
10
- import { Input } from "@/components/ui/input";
11
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
12
- import { Textarea } from "@/components/ui/textarea";
13
- import {
14
- testProxy,
15
- testProxyClearance,
16
- type ClearanceTestResult,
17
- type ProxyRuntimeClearanceMode,
18
- type ProxyRuntimeEgressMode,
19
- type ProxyTestResult,
20
- } from "@/lib/api";
21
-
22
- import { useSettingsStore } from "../store";
23
-
24
- export function ProxyRuntimeCard() {
25
- const [isTestingProxy, setIsTestingProxy] = useState(false);
26
- const [isTestingClearance, setIsTestingClearance] = useState(false);
27
- const [proxyResult, setProxyResult] = useState<ProxyTestResult | null>(null);
28
- const [clearanceResult, setClearanceResult] = useState<ClearanceTestResult | null>(null);
29
- const [targetUrl, setTargetUrl] = useState("https://chatgpt.com");
30
- const config = useSettingsStore((state) => state.config);
31
- const isLoadingConfig = useSettingsStore((state) => state.isLoadingConfig);
32
- const isSavingConfig = useSettingsStore((state) => state.isSavingConfig);
33
- const saveConfig = useSettingsStore((state) => state.saveConfig);
34
- const setProxyRuntimeField = useSettingsStore((state) => state.setProxyRuntimeField);
35
- const setProxyRuntimeClearanceField = useSettingsStore((state) => state.setProxyRuntimeClearanceField);
36
- const setProxyRuntimeStatusCodesText = useSettingsStore((state) => state.setProxyRuntimeStatusCodesText);
37
-
38
- if (isLoadingConfig || !config?.proxy_runtime) {
39
- return (
40
- <Card className="rounded-2xl border-white/80 bg-white/90 shadow-sm">
41
- <CardContent className="flex items-center justify-center p-10">
42
- <LoaderCircle className="size-5 animate-spin text-stone-400" />
43
- </CardContent>
44
- </Card>
45
- );
46
- }
47
-
48
- const runtime = config.proxy_runtime;
49
- const clearance = runtime.clearance;
50
- const runtimeEnabled = Boolean(runtime.enabled);
51
- const clearanceMode = clearance.mode;
52
- const hasStoredClearance = Boolean(clearance.has_cf_cookies || clearance.has_cf_clearance);
53
-
54
- const handleTestRuntimeProxy = async () => {
55
- setIsTestingProxy(true);
56
- setProxyResult(null);
57
- try {
58
- const saved = await saveConfig();
59
- if (!saved) {
60
- return;
61
- }
62
- const data = await testProxy();
63
- setProxyResult(data.result);
64
- if (data.result.ok) {
65
- toast.success(`清障代理可用(${data.result.latency_ms} ms,HTTP ${data.result.status})`);
66
- } else {
67
- toast.error(`清障代理不可用:${data.result.error ?? "未知错误"}`);
68
- }
69
- } catch (error) {
70
- toast.error(error instanceof Error ? error.message : "测试清障代理失败");
71
- } finally {
72
- setIsTestingProxy(false);
73
- }
74
- };
75
-
76
- const handleTestClearance = async () => {
77
- setIsTestingClearance(true);
78
- setClearanceResult(null);
79
- try {
80
- const saved = await saveConfig();
81
- if (!saved) {
82
- return;
83
- }
84
- const data = await testProxyClearance(targetUrl.trim() || "https://chatgpt.com");
85
- setClearanceResult(data.result);
86
- if (data.result.ok) {
87
- toast.success(`Clearance 获取成功(${data.result.latency_ms} ms)`);
88
- } else {
89
- toast.error(`Clearance 获取失败:${data.result.error ?? data.result.status}`);
90
- }
91
- } catch (error) {
92
- toast.error(error instanceof Error ? error.message : "测试 Clearance 失败");
93
- } finally {
94
- setIsTestingClearance(false);
95
- }
96
- };
97
-
98
- return (
99
- <Card className="rounded-2xl border-white/80 bg-white/90 shadow-sm">
100
- <CardContent className="space-y-5 p-6">
101
- <div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
102
- <div>
103
- <div className="flex items-center gap-2 text-base font-semibold text-stone-900">
104
- <PlugZap className="size-5 text-stone-500" />
105
- FlareSolverr 清障
106
- </div>
107
- <p className="mt-1 text-xs leading-6 text-stone-500">
108
- 默认关闭。用于上游请求遇到 Cloudflare 拦截后获取 clearance,可配合 WARP / Privoxy 代理链路重试。
109
- </p>
110
- </div>
111
- <span className={`rounded-full px-3 py-1 text-xs ${runtimeEnabled ? "bg-emerald-50 text-emerald-700" : "bg-stone-100 text-stone-500"}`}>
112
- {runtimeEnabled ? "已启用" : "未启用"}
113
- </span>
114
- </div>
115
-
116
- <div className="rounded-xl border border-stone-200 bg-stone-50 px-4 py-3 text-xs leading-6 text-stone-600">
117
- 代理优先级:账号代理 &gt; FlareSolverr 代理链路 &gt; 显式代理 &gt; 全局代理。Cookie / cf_clearance 不会在接口响应中明文返回。
118
- </div>
119
-
120
- <div className="flex items-start gap-2 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-xs leading-6 text-amber-800">
121
- <AlertTriangle className="mt-1 size-4 shrink-0" />
122
- <span>使用 FlareSolverr 模式前,请先通过 Docker 启动 flaresolverr、privoxy、warp-proxy 等相关容器;容器内 URL 通常填写 http://flaresolverr:8191。</span>
123
- </div>
124
-
125
- <div className="grid gap-4 md:grid-cols-2">
126
- <label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-4 py-3 text-sm text-stone-700 md:col-span-2">
127
- <Checkbox
128
- checked={runtimeEnabled}
129
- onCheckedChange={(checked) => setProxyRuntimeField("enabled", Boolean(checked))}
130
- />
131
- 启用 FlareSolverr 清障
132
- </label>
133
-
134
- <div className="space-y-2">
135
- <label className="text-sm text-stone-700">出站模式</label>
136
- <Select
137
- value={runtime.egress_mode}
138
- onValueChange={(value) => setProxyRuntimeField("egress_mode", value as ProxyRuntimeEgressMode)}
139
- disabled={!runtimeEnabled}
140
- >
141
- <SelectTrigger className="h-10 rounded-xl border-stone-200 bg-white shadow-none">
142
- <SelectValue />
143
- </SelectTrigger>
144
- <SelectContent>
145
- <SelectItem value="direct">直连</SelectItem>
146
- <SelectItem value="single_proxy">单代理/WARP</SelectItem>
147
- </SelectContent>
148
- </Select>
149
- <p className="text-xs text-stone-500">WARP compose 默认使用 single_proxy。</p>
150
- </div>
151
-
152
- <div className="space-y-2">
153
- <label className="text-sm text-stone-700">清障代理 URL</label>
154
- <Input
155
- value={runtime.proxy_url}
156
- onChange={(event) => setProxyRuntimeField("proxy_url", event.target.value)}
157
- placeholder="http://privoxy:8118"
158
- className="h-10 rounded-xl border-stone-200 bg-white"
159
- disabled={!runtimeEnabled || runtime.egress_mode !== "single_proxy"}
160
- />
161
- <p className="text-xs leading-5 text-stone-500">
162
- 支持 http/https/socks5/socks5h,socks5 会转为 socks5h。带认证格式:协议://账号:密码@主机:端口,也可直接粘贴 主机:端口:账号:密码。
163
- </p>
164
- </div>
165
-
166
- <div className="space-y-2">
167
- <label className="text-sm text-stone-700">资源代理 URL</label>
168
- <Input
169
- value={runtime.resource_proxy_url}
170
- onChange={(event) => setProxyRuntimeField("resource_proxy_url", event.target.value)}
171
- placeholder="留空则复用清障代理"
172
- className="h-10 rounded-xl border-stone-200 bg-white"
173
- disabled={!runtimeEnabled || runtime.egress_mode !== "single_proxy"}
174
- />
175
- </div>
176
-
177
- <div className="space-y-2">
178
- <label className="text-sm text-stone-700">重置会话状态码</label>
179
- <Input
180
- value={runtime.reset_session_status_codes.join(",")}
181
- onChange={(event) => setProxyRuntimeStatusCodesText(event.target.value)}
182
- placeholder="403"
183
- className="h-10 rounded-xl border-stone-200 bg-white"
184
- disabled={!runtimeEnabled}
185
- />
186
- <p className="text-xs text-stone-500">默认 403,只对 Cloudflare/挑战类错误触发。</p>
187
- </div>
188
-
189
- <label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-4 py-3 text-sm text-stone-700">
190
- <Checkbox
191
- checked={Boolean(runtime.skip_ssl_verify)}
192
- onCheckedChange={(checked) => setProxyRuntimeField("skip_ssl_verify", Boolean(checked))}
193
- disabled={!runtimeEnabled}
194
- />
195
- 跳过 SSL 校验
196
- </label>
197
-
198
- <div className="flex items-end justify-end">
199
- <Button
200
- type="button"
201
- variant="outline"
202
- className="h-9 rounded-xl border-stone-200 bg-white px-4 text-stone-700"
203
- onClick={() => void handleTestRuntimeProxy()}
204
- disabled={isTestingProxy || !runtimeEnabled}
205
- >
206
- {isTestingProxy ? <LoaderCircle className="size-4 animate-spin" /> : <PlugZap className="size-4" />}
207
- 测试当前清障代理
208
- </Button>
209
- </div>
210
-
211
- {proxyResult ? (
212
- <div className={`rounded-xl border px-3 py-2 text-xs leading-6 md:col-span-2 ${proxyResult.ok ? "border-emerald-200 bg-emerald-50 text-emerald-800" : "border-rose-200 bg-rose-50 text-rose-800"}`}>
213
- {proxyResult.ok
214
- ? `代理可用:HTTP ${proxyResult.status},用时 ${proxyResult.latency_ms} ms,来源 ${proxyResult.proxy_source ?? "unknown"}`
215
- : `代理不可用:${proxyResult.error ?? "未知错误"}(用时 ${proxyResult.latency_ms} ms)`}
216
- </div>
217
- ) : null}
218
- </div>
219
-
220
- <div className="space-y-4 rounded-xl border border-stone-200 bg-white px-4 py-3">
221
- <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
222
- <div className="flex items-center gap-2 text-sm font-medium text-stone-800">
223
- <Cookie className="size-4 text-stone-500" />
224
- Cloudflare Clearance
225
- </div>
226
- <span className={`rounded-full px-3 py-1 text-xs ${clearance.enabled ? "bg-emerald-50 text-emerald-700" : "bg-stone-100 text-stone-500"}`}>
227
- {clearance.enabled ? clearanceMode : "disabled"}
228
- </span>
229
- </div>
230
-
231
- <div className="grid gap-4 md:grid-cols-2">
232
- <div className="space-y-2">
233
- <label className="text-sm text-stone-700">Clearance 模式</label>
234
- <Select
235
- value={clearanceMode}
236
- onValueChange={(value) => {
237
- const mode = value as ProxyRuntimeClearanceMode;
238
- setProxyRuntimeClearanceField("mode", mode);
239
- setProxyRuntimeClearanceField("enabled", mode !== "none");
240
- }}
241
- disabled={!runtimeEnabled}
242
- >
243
- <SelectTrigger className="h-10 rounded-xl border-stone-200 bg-white shadow-none">
244
- <SelectValue />
245
- </SelectTrigger>
246
- <SelectContent>
247
- <SelectItem value="none">不启用</SelectItem>
248
- <SelectItem value="manual">手动 Cookie</SelectItem>
249
- <SelectItem value="flaresolverr">FlareSolverr</SelectItem>
250
- </SelectContent>
251
- </Select>
252
- </div>
253
-
254
- <div className="space-y-2">
255
- <label className="text-sm text-stone-700">FlareSolverr URL</label>
256
- <Input
257
- value={clearance.flaresolverr_url}
258
- onChange={(event) => setProxyRuntimeClearanceField("flaresolverr_url", event.target.value)}
259
- placeholder="http://flaresolverr:8191"
260
- className="h-10 rounded-xl border-stone-200 bg-white"
261
- disabled={!runtimeEnabled || clearanceMode !== "flaresolverr"}
262
- />
263
- </div>
264
-
265
- <div className="space-y-2 md:col-span-2">
266
- <label className="text-sm text-stone-700">User-Agent</label>
267
- <Input
268
- value={clearance.user_agent}
269
- onChange={(event) => setProxyRuntimeClearanceField("user_agent", event.target.value)}
270
- className="h-10 rounded-xl border-stone-200 bg-white font-mono text-xs"
271
- disabled={!runtimeEnabled || clearanceMode === "none"}
272
- />
273
- </div>
274
-
275
- <div className="space-y-2">
276
- <label className="text-sm text-stone-700">超时秒数</label>
277
- <Input
278
- value={String(clearance.timeout_sec)}
279
- onChange={(event) => setProxyRuntimeClearanceField("timeout_sec", event.target.value)}
280
- placeholder="60"
281
- className="h-10 rounded-xl border-stone-200 bg-white"
282
- disabled={!runtimeEnabled || clearanceMode === "none"}
283
- />
284
- </div>
285
-
286
- <div className="space-y-2">
287
- <label className="text-sm text-stone-700">刷新间隔秒数</label>
288
- <Input
289
- value={String(clearance.refresh_interval)}
290
- onChange={(event) => setProxyRuntimeClearanceField("refresh_interval", event.target.value)}
291
- placeholder="3600"
292
- className="h-10 rounded-xl border-stone-200 bg-white"
293
- disabled={!runtimeEnabled || clearanceMode === "none"}
294
- />
295
- </div>
296
-
297
- <div className="space-y-2 md:col-span-2">
298
- <label className="text-sm text-stone-700">手动 Cookie</label>
299
- <Textarea
300
- value={clearance.cf_cookies}
301
- onChange={(event) => setProxyRuntimeClearanceField("cf_cookies", event.target.value)}
302
- placeholder="可选:foo=bar; cf_clearance=..."
303
- className="min-h-24 rounded-xl border-stone-200 bg-white font-mono text-xs shadow-none"
304
- disabled={!runtimeEnabled || clearanceMode !== "manual"}
305
- />
306
- <p className="text-xs text-stone-500">
307
- {hasStoredClearance ? "服务端已保存过 Cookie/clearance;留空保存不会清空已有值。" : "留空表示不使用手动 Cookie。"}
308
- </p>
309
- </div>
310
-
311
- <div className="space-y-2 md:col-span-2">
312
- <label className="text-sm text-stone-700">单独 cf_clearance</label>
313
- <Input
314
- value={clearance.cf_clearance}
315
- onChange={(event) => setProxyRuntimeClearanceField("cf_clearance", event.target.value)}
316
- placeholder="可选:只填写 cf_clearance 值"
317
- className="h-10 rounded-xl border-stone-200 bg-white font-mono text-xs"
318
- disabled={!runtimeEnabled || clearanceMode !== "manual"}
319
- />
320
- </div>
321
-
322
- <label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-stone-50 px-4 py-3 text-sm text-stone-700">
323
- <Checkbox
324
- checked={Boolean(clearance.warm_up_on_start)}
325
- onCheckedChange={(checked) => setProxyRuntimeClearanceField("warm_up_on_start", Boolean(checked))}
326
- disabled={!runtimeEnabled || clearanceMode === "none"}
327
- />
328
- 启动时预热 Clearance
329
- </label>
330
-
331
- <div className="space-y-2">
332
- <label className="text-sm text-stone-700">测试目标 URL</label>
333
- <Input
334
- value={targetUrl}
335
- onChange={(event) => setTargetUrl(event.target.value)}
336
- placeholder="https://chatgpt.com"
337
- className="h-10 rounded-xl border-stone-200 bg-white"
338
- disabled={!runtimeEnabled || clearanceMode === "none"}
339
- />
340
- </div>
341
-
342
- <div className="flex justify-end md:col-span-2">
343
- <Button
344
- type="button"
345
- variant="outline"
346
- className="h-9 rounded-xl border-stone-200 bg-white px-4 text-stone-700"
347
- onClick={() => void handleTestClearance()}
348
- disabled={isTestingClearance || !runtimeEnabled || clearanceMode === "none"}
349
- >
350
- {isTestingClearance ? <LoaderCircle className="size-4 animate-spin" /> : <ShieldCheck className="size-4" />}
351
- 测试 Clearance
352
- </Button>
353
- </div>
354
-
355
- {clearanceResult ? (
356
- <div className={`rounded-xl border px-3 py-2 text-xs leading-6 md:col-span-2 ${clearanceResult.ok ? "border-emerald-200 bg-emerald-50 text-emerald-800" : "border-rose-200 bg-rose-50 text-rose-800"}`}>
357
- {clearanceResult.ok
358
- ? `Clearance 可用:${clearanceResult.has_cookies ? "已获取 Cookie" : "无 Cookie"},用时 ${clearanceResult.latency_ms} ms`
359
- : `Clearance 不可用:${clearanceResult.error ?? clearanceResult.status}(用时 ${clearanceResult.latency_ms} ms)`}
360
- </div>
361
- ) : null}
362
- </div>
363
- </div>
364
-
365
- <div className="flex justify-end">
366
- <Button
367
- type="button"
368
- className="h-10 rounded-xl bg-stone-950 px-5 text-white hover:bg-stone-800"
369
- onClick={() => void saveConfig()}
370
- disabled={isSavingConfig}
371
- >
372
- {isSavingConfig ? <LoaderCircle className="size-4 animate-spin" /> : <Save className="size-4" />}
373
- 保存配置
374
- </Button>
375
- </div>
376
- </CardContent>
377
- </Card>
378
- );
379
- }
1
+ "use client";
2
+
3
+ import { AlertTriangle, Cookie, LoaderCircle, PlugZap, Save, ShieldCheck } from "lucide-react";
4
+ import { useState } from "react";
5
+ import { toast } from "sonner";
6
+
7
+ import { Button } from "@/components/ui/button";
8
+ import { Card, CardContent } from "@/components/ui/card";
9
+ import { Checkbox } from "@/components/ui/checkbox";
10
+ import { Input } from "@/components/ui/input";
11
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
12
+ import { Textarea } from "@/components/ui/textarea";
13
+ import {
14
+ testProxy,
15
+ testProxyClearance,
16
+ type ClearanceTestResult,
17
+ type ProxyRuntimeClearanceMode,
18
+ type ProxyRuntimeEgressMode,
19
+ type ProxyTestResult,
20
+ } from "@/lib/api";
21
+
22
+ import { useSettingsStore } from "../store";
23
+
24
+ export function ProxyRuntimeCard() {
25
+ const [isTestingProxy, setIsTestingProxy] = useState(false);
26
+ const [isTestingClearance, setIsTestingClearance] = useState(false);
27
+ const [proxyResult, setProxyResult] = useState<ProxyTestResult | null>(null);
28
+ const [clearanceResult, setClearanceResult] = useState<ClearanceTestResult | null>(null);
29
+ const [targetUrl, setTargetUrl] = useState("https://chatgpt.com");
30
+ const config = useSettingsStore((state) => state.config);
31
+ const isLoadingConfig = useSettingsStore((state) => state.isLoadingConfig);
32
+ const isSavingConfig = useSettingsStore((state) => state.isSavingConfig);
33
+ const saveConfig = useSettingsStore((state) => state.saveConfig);
34
+ const setProxyRuntimeField = useSettingsStore((state) => state.setProxyRuntimeField);
35
+ const setProxyRuntimeClearanceField = useSettingsStore((state) => state.setProxyRuntimeClearanceField);
36
+ const setProxyRuntimeStatusCodesText = useSettingsStore((state) => state.setProxyRuntimeStatusCodesText);
37
+
38
+ if (isLoadingConfig || !config?.proxy_runtime) {
39
+ return (
40
+ <Card className="rounded-2xl border-white/80 bg-white/90 shadow-sm">
41
+ <CardContent className="flex items-center justify-center p-10">
42
+ <LoaderCircle className="size-5 animate-spin text-stone-400" />
43
+ </CardContent>
44
+ </Card>
45
+ );
46
+ }
47
+
48
+ const runtime = config.proxy_runtime;
49
+ const clearance = runtime.clearance;
50
+ const runtimeEnabled = Boolean(runtime.enabled);
51
+ const clearanceMode = clearance.mode;
52
+ const hasStoredClearance = Boolean(clearance.has_cf_cookies || clearance.has_cf_clearance);
53
+
54
+ const handleTestRuntimeProxy = async () => {
55
+ setIsTestingProxy(true);
56
+ setProxyResult(null);
57
+ try {
58
+ const saved = await saveConfig();
59
+ if (!saved) {
60
+ return;
61
+ }
62
+ const data = await testProxy();
63
+ setProxyResult(data.result);
64
+ if (data.result.ok) {
65
+ toast.success(`清障代理可用(${data.result.latency_ms} ms,HTTP ${data.result.status})`);
66
+ } else {
67
+ toast.error(`清障代理不可用:${data.result.error ?? "未知错误"}`);
68
+ }
69
+ } catch (error) {
70
+ toast.error(error instanceof Error ? error.message : "测试清障代理失败");
71
+ } finally {
72
+ setIsTestingProxy(false);
73
+ }
74
+ };
75
+
76
+ const handleTestClearance = async () => {
77
+ setIsTestingClearance(true);
78
+ setClearanceResult(null);
79
+ try {
80
+ const saved = await saveConfig();
81
+ if (!saved) {
82
+ return;
83
+ }
84
+ const data = await testProxyClearance(targetUrl.trim() || "https://chatgpt.com");
85
+ setClearanceResult(data.result);
86
+ if (data.result.ok) {
87
+ toast.success(`Clearance 获取成功(${data.result.latency_ms} ms)`);
88
+ } else {
89
+ toast.error(`Clearance 获取失败:${data.result.error ?? data.result.status}`);
90
+ }
91
+ } catch (error) {
92
+ toast.error(error instanceof Error ? error.message : "测试 Clearance 失败");
93
+ } finally {
94
+ setIsTestingClearance(false);
95
+ }
96
+ };
97
+
98
+ return (
99
+ <Card className="rounded-2xl border-white/80 bg-white/90 shadow-sm">
100
+ <CardContent className="space-y-5 p-6">
101
+ <div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
102
+ <div>
103
+ <div className="flex items-center gap-2 text-base font-semibold text-stone-900">
104
+ <PlugZap className="size-5 text-stone-500" />
105
+ FlareSolverr 清障
106
+ </div>
107
+ <p className="mt-1 text-xs leading-6 text-stone-500">
108
+ 默认关闭。用于上游请求遇到 Cloudflare 拦截后获取 clearance,可配合 WARP / Privoxy 代理链路重试。
109
+ </p>
110
+ </div>
111
+ <span className={`rounded-full px-3 py-1 text-xs ${runtimeEnabled ? "bg-emerald-50 text-emerald-700" : "bg-stone-100 text-stone-500"}`}>
112
+ {runtimeEnabled ? "已启用" : "未启用"}
113
+ </span>
114
+ </div>
115
+
116
+ <div className="rounded-xl border border-stone-200 bg-stone-50 px-4 py-3 text-xs leading-6 text-stone-600">
117
+ 代理优先级:账号代理 &gt; FlareSolverr 代理链路 &gt; 显式代理 &gt; 全局代理。Cookie / cf_clearance 不会在接口响应中明文返回。
118
+ </div>
119
+
120
+ <div className="flex items-start gap-2 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-xs leading-6 text-amber-800">
121
+ <AlertTriangle className="mt-1 size-4 shrink-0" />
122
+ <span>使用 FlareSolverr 模式前,请先通过 Docker 启动 flaresolverr、privoxy、warp-proxy 等相关容器;容器内 URL 通常填写 http://flaresolverr:8191。</span>
123
+ </div>
124
+
125
+ <div className="grid gap-4 md:grid-cols-2">
126
+ <label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-4 py-3 text-sm text-stone-700 md:col-span-2">
127
+ <Checkbox
128
+ checked={runtimeEnabled}
129
+ onCheckedChange={(checked) => setProxyRuntimeField("enabled", Boolean(checked))}
130
+ />
131
+ 启用 FlareSolverr 清障
132
+ </label>
133
+
134
+ <div className="space-y-2">
135
+ <label className="text-sm text-stone-700">出站模式</label>
136
+ <Select
137
+ value={runtime.egress_mode}
138
+ onValueChange={(value) => setProxyRuntimeField("egress_mode", value as ProxyRuntimeEgressMode)}
139
+ disabled={!runtimeEnabled}
140
+ >
141
+ <SelectTrigger className="h-10 rounded-xl border-stone-200 bg-white shadow-none">
142
+ <SelectValue />
143
+ </SelectTrigger>
144
+ <SelectContent>
145
+ <SelectItem value="direct">直连</SelectItem>
146
+ <SelectItem value="single_proxy">单代理/WARP</SelectItem>
147
+ </SelectContent>
148
+ </Select>
149
+ <p className="text-xs text-stone-500">WARP compose 默认使用 single_proxy。</p>
150
+ </div>
151
+
152
+ <div className="space-y-2">
153
+ <label className="text-sm text-stone-700">清障代理 URL</label>
154
+ <Input
155
+ value={runtime.proxy_url}
156
+ onChange={(event) => setProxyRuntimeField("proxy_url", event.target.value)}
157
+ placeholder="http://privoxy:8118"
158
+ className="h-10 rounded-xl border-stone-200 bg-white"
159
+ disabled={!runtimeEnabled || runtime.egress_mode !== "single_proxy"}
160
+ />
161
+ <p className="text-xs leading-5 text-stone-500">
162
+ 支持 http/https/socks5/socks5h,socks5 会转为 socks5h。带认证格式:协议://账号:密码@主机:端口,也可直接粘贴 主机:端口:账号:密码。
163
+ </p>
164
+ </div>
165
+
166
+ <div className="space-y-2">
167
+ <label className="text-sm text-stone-700">资源代理 URL</label>
168
+ <Input
169
+ value={runtime.resource_proxy_url}
170
+ onChange={(event) => setProxyRuntimeField("resource_proxy_url", event.target.value)}
171
+ placeholder="留空则复用清障代理"
172
+ className="h-10 rounded-xl border-stone-200 bg-white"
173
+ disabled={!runtimeEnabled || runtime.egress_mode !== "single_proxy"}
174
+ />
175
+ </div>
176
+
177
+ <div className="space-y-2">
178
+ <label className="text-sm text-stone-700">重置会话状态码</label>
179
+ <Input
180
+ value={runtime.reset_session_status_codes.join(",")}
181
+ onChange={(event) => setProxyRuntimeStatusCodesText(event.target.value)}
182
+ placeholder="403"
183
+ className="h-10 rounded-xl border-stone-200 bg-white"
184
+ disabled={!runtimeEnabled}
185
+ />
186
+ <p className="text-xs text-stone-500">默认 403,只对 Cloudflare/挑战类错误触发。</p>
187
+ </div>
188
+
189
+ <label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-4 py-3 text-sm text-stone-700">
190
+ <Checkbox
191
+ checked={Boolean(runtime.skip_ssl_verify)}
192
+ onCheckedChange={(checked) => setProxyRuntimeField("skip_ssl_verify", Boolean(checked))}
193
+ disabled={!runtimeEnabled}
194
+ />
195
+ 跳过 SSL 校验
196
+ </label>
197
+
198
+ <div className="flex items-end justify-end">
199
+ <Button
200
+ type="button"
201
+ variant="outline"
202
+ className="h-9 rounded-xl border-stone-200 bg-white px-4 text-stone-700"
203
+ onClick={() => void handleTestRuntimeProxy()}
204
+ disabled={isTestingProxy || !runtimeEnabled}
205
+ >
206
+ {isTestingProxy ? <LoaderCircle className="size-4 animate-spin" /> : <PlugZap className="size-4" />}
207
+ 测试当前清障代理
208
+ </Button>
209
+ </div>
210
+
211
+ {proxyResult ? (
212
+ <div className={`rounded-xl border px-3 py-2 text-xs leading-6 md:col-span-2 ${proxyResult.ok ? "border-emerald-200 bg-emerald-50 text-emerald-800" : "border-rose-200 bg-rose-50 text-rose-800"}`}>
213
+ {proxyResult.ok
214
+ ? `代理可用:HTTP ${proxyResult.status},用时 ${proxyResult.latency_ms} ms,来源 ${proxyResult.proxy_source ?? "unknown"}`
215
+ : `代理不可用:${proxyResult.error ?? "未知错误"}(用时 ${proxyResult.latency_ms} ms)`}
216
+ </div>
217
+ ) : null}
218
+ </div>
219
+
220
+ <div className="space-y-4 rounded-xl border border-stone-200 bg-white px-4 py-3">
221
+ <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
222
+ <div className="flex items-center gap-2 text-sm font-medium text-stone-800">
223
+ <Cookie className="size-4 text-stone-500" />
224
+ Cloudflare Clearance
225
+ </div>
226
+ <span className={`rounded-full px-3 py-1 text-xs ${clearance.enabled ? "bg-emerald-50 text-emerald-700" : "bg-stone-100 text-stone-500"}`}>
227
+ {clearance.enabled ? clearanceMode : "disabled"}
228
+ </span>
229
+ </div>
230
+
231
+ <div className="grid gap-4 md:grid-cols-2">
232
+ <div className="space-y-2">
233
+ <label className="text-sm text-stone-700">Clearance 模式</label>
234
+ <Select
235
+ value={clearanceMode}
236
+ onValueChange={(value) => {
237
+ const mode = value as ProxyRuntimeClearanceMode;
238
+ setProxyRuntimeClearanceField("mode", mode);
239
+ setProxyRuntimeClearanceField("enabled", mode !== "none");
240
+ }}
241
+ disabled={!runtimeEnabled}
242
+ >
243
+ <SelectTrigger className="h-10 rounded-xl border-stone-200 bg-white shadow-none">
244
+ <SelectValue />
245
+ </SelectTrigger>
246
+ <SelectContent>
247
+ <SelectItem value="none">不启用</SelectItem>
248
+ <SelectItem value="manual">手动 Cookie</SelectItem>
249
+ <SelectItem value="flaresolverr">FlareSolverr</SelectItem>
250
+ </SelectContent>
251
+ </Select>
252
+ </div>
253
+
254
+ <div className="space-y-2">
255
+ <label className="text-sm text-stone-700">FlareSolverr URL</label>
256
+ <Input
257
+ value={clearance.flaresolverr_url}
258
+ onChange={(event) => setProxyRuntimeClearanceField("flaresolverr_url", event.target.value)}
259
+ placeholder="http://flaresolverr:8191"
260
+ className="h-10 rounded-xl border-stone-200 bg-white"
261
+ disabled={!runtimeEnabled || clearanceMode !== "flaresolverr"}
262
+ />
263
+ </div>
264
+
265
+ <div className="space-y-2 md:col-span-2">
266
+ <label className="text-sm text-stone-700">User-Agent</label>
267
+ <Input
268
+ value={clearance.user_agent}
269
+ onChange={(event) => setProxyRuntimeClearanceField("user_agent", event.target.value)}
270
+ className="h-10 rounded-xl border-stone-200 bg-white font-mono text-xs"
271
+ disabled={!runtimeEnabled || clearanceMode === "none"}
272
+ />
273
+ </div>
274
+
275
+ <div className="space-y-2">
276
+ <label className="text-sm text-stone-700">超时秒数</label>
277
+ <Input
278
+ value={String(clearance.timeout_sec)}
279
+ onChange={(event) => setProxyRuntimeClearanceField("timeout_sec", event.target.value)}
280
+ placeholder="60"
281
+ className="h-10 rounded-xl border-stone-200 bg-white"
282
+ disabled={!runtimeEnabled || clearanceMode === "none"}
283
+ />
284
+ </div>
285
+
286
+ <div className="space-y-2">
287
+ <label className="text-sm text-stone-700">刷新间隔秒数</label>
288
+ <Input
289
+ value={String(clearance.refresh_interval)}
290
+ onChange={(event) => setProxyRuntimeClearanceField("refresh_interval", event.target.value)}
291
+ placeholder="3600"
292
+ className="h-10 rounded-xl border-stone-200 bg-white"
293
+ disabled={!runtimeEnabled || clearanceMode === "none"}
294
+ />
295
+ </div>
296
+
297
+ <div className="space-y-2 md:col-span-2">
298
+ <label className="text-sm text-stone-700">手动 Cookie</label>
299
+ <Textarea
300
+ value={clearance.cf_cookies}
301
+ onChange={(event) => setProxyRuntimeClearanceField("cf_cookies", event.target.value)}
302
+ placeholder="可选:foo=bar; cf_clearance=..."
303
+ className="min-h-24 rounded-xl border-stone-200 bg-white font-mono text-xs shadow-none"
304
+ disabled={!runtimeEnabled || clearanceMode !== "manual"}
305
+ />
306
+ <p className="text-xs text-stone-500">
307
+ {hasStoredClearance ? "服务端已保存过 Cookie/clearance;留空保存不会清空已有值。" : "留空表示不使用手动 Cookie。"}
308
+ </p>
309
+ </div>
310
+
311
+ <div className="space-y-2 md:col-span-2">
312
+ <label className="text-sm text-stone-700">单独 cf_clearance</label>
313
+ <Input
314
+ value={clearance.cf_clearance}
315
+ onChange={(event) => setProxyRuntimeClearanceField("cf_clearance", event.target.value)}
316
+ placeholder="可选:只填写 cf_clearance 值"
317
+ className="h-10 rounded-xl border-stone-200 bg-white font-mono text-xs"
318
+ disabled={!runtimeEnabled || clearanceMode !== "manual"}
319
+ />
320
+ </div>
321
+
322
+ <label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-stone-50 px-4 py-3 text-sm text-stone-700">
323
+ <Checkbox
324
+ checked={Boolean(clearance.warm_up_on_start)}
325
+ onCheckedChange={(checked) => setProxyRuntimeClearanceField("warm_up_on_start", Boolean(checked))}
326
+ disabled={!runtimeEnabled || clearanceMode === "none"}
327
+ />
328
+ 启动时预热 Clearance
329
+ </label>
330
+
331
+ <div className="space-y-2">
332
+ <label className="text-sm text-stone-700">测试目标 URL</label>
333
+ <Input
334
+ value={targetUrl}
335
+ onChange={(event) => setTargetUrl(event.target.value)}
336
+ placeholder="https://chatgpt.com"
337
+ className="h-10 rounded-xl border-stone-200 bg-white"
338
+ disabled={!runtimeEnabled || clearanceMode === "none"}
339
+ />
340
+ </div>
341
+
342
+ <div className="flex justify-end md:col-span-2">
343
+ <Button
344
+ type="button"
345
+ variant="outline"
346
+ className="h-9 rounded-xl border-stone-200 bg-white px-4 text-stone-700"
347
+ onClick={() => void handleTestClearance()}
348
+ disabled={isTestingClearance || !runtimeEnabled || clearanceMode === "none"}
349
+ >
350
+ {isTestingClearance ? <LoaderCircle className="size-4 animate-spin" /> : <ShieldCheck className="size-4" />}
351
+ 测试 Clearance
352
+ </Button>
353
+ </div>
354
+
355
+ {clearanceResult ? (
356
+ <div className={`rounded-xl border px-3 py-2 text-xs leading-6 md:col-span-2 ${clearanceResult.ok ? "border-emerald-200 bg-emerald-50 text-emerald-800" : "border-rose-200 bg-rose-50 text-rose-800"}`}>
357
+ {clearanceResult.ok
358
+ ? `Clearance 可用:${clearanceResult.has_cookies ? "已获取 Cookie" : "无 Cookie"},用时 ${clearanceResult.latency_ms} ms`
359
+ : `Clearance 不可用:${clearanceResult.error ?? clearanceResult.status}(用时 ${clearanceResult.latency_ms} ms)`}
360
+ </div>
361
+ ) : null}
362
+ </div>
363
+ </div>
364
+
365
+ <div className="flex justify-end">
366
+ <Button
367
+ type="button"
368
+ className="h-10 rounded-xl bg-stone-950 px-5 text-white hover:bg-stone-800"
369
+ onClick={() => void saveConfig()}
370
+ disabled={isSavingConfig}
371
+ >
372
+ {isSavingConfig ? <LoaderCircle className="size-4 animate-spin" /> : <Save className="size-4" />}
373
+ 保存配置
374
+ </Button>
375
+ </div>
376
+ </CardContent>
377
+ </Card>
378
+ );
379
+ }