11import { useState , useEffect } from "react" ;
22import { useNavigate } from "react-router-dom" ;
3- import { Box , Flex , Heading , Text , Code } from "@radix-ui/themes" ;
4- import { Button , Card , Separator } from "@/components/ui" ;
3+ import { Box , Flex , Heading , Text , Code , TextField } from "@radix-ui/themes" ;
4+ import { Button , Card , Separator , Switch } from "@/components/ui" ;
55import {
66 ArrowLeftIcon ,
77 CopyIcon ,
@@ -25,6 +25,10 @@ const CreateAgent = () => {
2525 const [ tokenCopied , setTokenCopied ] = useState ( false ) ;
2626 const [ installCommandCopied , setInstallCommandCopied ] = useState ( false ) ;
2727
28+ // 代理功能的状态
29+ const [ useProxy , setUseProxy ] = useState ( false ) ;
30+ const [ customProxyUrl , setCustomProxyUrl ] = useState ( "https://gh-proxy.com/" ) ;
31+
2832 // 生成服务端验证的 token
2933 useEffect ( ( ) => {
3034 const fetchToken = async ( ) => {
@@ -60,10 +64,17 @@ const CreateAgent = () => {
6064 setTimeout ( ( ) => setTokenCopied ( false ) , 2000 ) ;
6165 } ;
6266
67+ // 根据是否使用代理生成安装脚本 URL
68+ const getInstallScriptUrl = ( ) => {
69+ const baseUrl = "https://github.com/zaunist/xugou/blob/main/install-agent.sh" ;
70+ if ( useProxy ) {
71+ return `${ customProxyUrl } ${ baseUrl } ` ;
72+ }
73+ return baseUrl ;
74+ } ;
75+
6376 // 生成并复制安装命令
64- const installScriptUrl =
65- "https://gh-proxy.com/github.com/zaunist/xugou/blob/main/install-agent.sh" ;
66- const oneLinerInstallCommand = `curl -sSL ${ installScriptUrl } | bash -s -- --server ${ serverUrl } --token ${ token } --interval 60` ;
77+ const oneLinerInstallCommand = `curl -sSL ${ getInstallScriptUrl ( ) } | bash -s -- --server ${ serverUrl } --token ${ token } --interval 60` ;
6778
6879 const handleCopyInstallCommand = ( ) => {
6980 navigator . clipboard . writeText ( oneLinerInstallCommand ) ;
@@ -82,7 +93,7 @@ const CreateAgent = () => {
8293 </ Flex >
8394 </ Flex >
8495 < Card className = "my-4 pr-4" >
85- < Flex direction = "column" gap = "2 " className = "ml-4" >
96+ < Flex direction = "column" gap = "4 " className = "ml-4" >
8697 { /* 提示信息 */ }
8798 < Box >
8899 < Flex gap = "2" >
@@ -145,6 +156,30 @@ const CreateAgent = () => {
145156 </ Text >
146157 </ Flex >
147158
159+ { /* 代理设置 */ }
160+ < Flex direction = "column" gap = "2" mb = "4" >
161+ < Flex align = "center" gap = "2" >
162+ < Switch
163+ id = "proxy-switch"
164+ checked = { useProxy }
165+ onCheckedChange = { setUseProxy }
166+ />
167+ < Text as = "label" htmlFor = "proxy-switch" size = "2" >
168+ 启用 GitHub 代理
169+ </ Text >
170+ </ Flex >
171+ { useProxy && (
172+ < Flex direction = "column" gap = "1" pl = "6" >
173+ < Text size = "2" > 自定义代理地址 (可选):</ Text >
174+ < TextField . Input
175+ value = { customProxyUrl }
176+ onChange = { ( e ) => setCustomProxyUrl ( e . target . value ) }
177+ placeholder = "例如: https://gh-proxy.com/"
178+ />
179+ </ Flex >
180+ ) }
181+ </ Flex >
182+
148183 < Card >
149184 < Flex direction = "column" gap = "3" p = "3" >
150185 < Text as = "div" size = "2" weight = "bold" mb = "1" >
@@ -153,7 +188,7 @@ const CreateAgent = () => {
153188 "一键安装命令 (Linux/macOS/Windows):"
154189 ) }
155190 </ Text >
156- < Code size = "2" > { oneLinerInstallCommand } </ Code >
191+ < Code size = "2" className = "break-all" > { oneLinerInstallCommand } </ Code >
157192 < Button variant = "secondary" onClick = { handleCopyInstallCommand } >
158193 { installCommandCopied ? < CheckIcon /> : < CopyIcon /> }
159194 { installCommandCopied ? t ( "common.copied" ) : t ( "common.copy" ) }
@@ -169,7 +204,7 @@ const CreateAgent = () => {
169204 </ Box >
170205
171206 { /* 返回按钮 */ }
172- < Flex justify = "end" gap = "3" >
207+ < Flex justify = "end" gap = "3" mt = "4" >
173208 < Button variant = "secondary" onClick = { ( ) => navigate ( "/agents" ) } >
174209 { t ( "agent.add.returnToList" ) }
175210 </ Button >
0 commit comments