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 ,
@@ -16,19 +16,21 @@ const CreateAgent = () => {
1616 const navigate = useNavigate ( ) ;
1717 const [ loading , setLoading ] = useState ( false ) ;
1818 const [ token , setToken ] = useState ( "" ) ;
19- // 获取当前浏览器访问的地址作为服务端地址
20- const serverUrl = ENV_API_BASE_URL ;
19+ // 获取服务端地址。优先从环境变量获取,如果没有则使用当前窗口的源(origin)
20+ const serverUrl = ENV_API_BASE_URL || window . location . origin ;
2121 const { t } = useTranslation ( ) ;
2222
23- // State for copy buttons
23+ // 复制按钮的状态
2424 const [ serverUrlCopied , setServerUrlCopied ] = useState ( false ) ;
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 ( ( ) => {
30- // 获取当前访问的URL
31-
3234 const fetchToken = async ( ) => {
3335 setLoading ( true ) ;
3436 try {
@@ -62,10 +64,17 @@ const CreateAgent = () => {
6264 setTimeout ( ( ) => setTokenCopied ( false ) , 2000 ) ;
6365 } ;
6466
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+
6576 // 生成并复制安装命令
66- const installScriptUrl =
67- "https://gh-proxy.com/github.com/zaunist/xugou/blob/main/install-agent.sh" ;
68- 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` ;
6978
7079 const handleCopyInstallCommand = ( ) => {
7180 navigator . clipboard . writeText ( oneLinerInstallCommand ) ;
@@ -84,7 +93,7 @@ const CreateAgent = () => {
8493 </ Flex >
8594 </ Flex >
8695 < Card className = "my-4 pr-4" >
87- < Flex direction = "column" gap = "2 " className = "ml-4" >
96+ < Flex direction = "column" gap = "4 " className = "ml-4" >
8897 { /* 提示信息 */ }
8998 < Box >
9099 < Flex gap = "2" >
@@ -147,6 +156,30 @@ const CreateAgent = () => {
147156 </ Text >
148157 </ Flex >
149158
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+
150183 < Card >
151184 < Flex direction = "column" gap = "3" p = "3" >
152185 < Text as = "div" size = "2" weight = "bold" mb = "1" >
@@ -155,7 +188,7 @@ const CreateAgent = () => {
155188 "一键安装命令 (Linux/macOS/Windows):"
156189 ) }
157190 </ Text >
158- < Code size = "2" > { oneLinerInstallCommand } </ Code >
191+ < Code size = "2" className = "break-all" > { oneLinerInstallCommand } </ Code >
159192 < Button variant = "secondary" onClick = { handleCopyInstallCommand } >
160193 { installCommandCopied ? < CheckIcon /> : < CopyIcon /> }
161194 { installCommandCopied ? t ( "common.copied" ) : t ( "common.copy" ) }
@@ -171,7 +204,7 @@ const CreateAgent = () => {
171204 </ Box >
172205
173206 { /* 返回按钮 */ }
174- < Flex justify = "end" gap = "3" >
207+ < Flex justify = "end" gap = "3" mt = "4" >
175208 < Button variant = "secondary" onClick = { ( ) => navigate ( "/agents" ) } >
176209 { t ( "agent.add.returnToList" ) }
177210 </ Button >
0 commit comments