feat: 支持自托管的 remote-control-server (#214)

* feat: 支持自托管的 remote-control-server (#214)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
claude-code-best
2026-04-09 17:40:50 +08:00
committed by GitHub
parent f17b7c7163
commit 2da6514095
81 changed files with 9875 additions and 40 deletions

View File

@@ -35,12 +35,24 @@ export function isRemoteSessionLocal(
/**
* Get the base URL for Claude AI based on environment.
* For localhost, derives the base URL from the ingress URL to preserve the
* actual server port instead of using the hardcoded default (4000).
*/
export function getClaudeAiBaseUrl(
sessionId?: string,
ingressUrl?: string,
): string {
if (isRemoteSessionLocal(sessionId, ingressUrl)) {
// If an ingress URL is available, extract its origin to keep the correct port.
// Self-hosted servers may run on any port (default 3000), not just 4000.
if (ingressUrl) {
try {
const parsed = new URL(ingressUrl)
return parsed.origin
} catch {
// Fall through to default
}
}
return CLAUDE_AI_LOCAL_BASE_URL
}
if (isRemoteSessionStaging(sessionId, ingressUrl)) {
@@ -71,6 +83,12 @@ export function getRemoteSessionUrl(
require('../bridge/sessionIdCompat.js') as typeof import('../bridge/sessionIdCompat.js')
/* eslint-enable @typescript-eslint/no-require-imports */
const compatId = toCompatSessionId(sessionId)
// Use CLAUDE_BRIDGE_BASE_URL from env if available, otherwise fall back to default logic
const bridgeBaseUrl = process.env.CLAUDE_BRIDGE_BASE_URL
if (bridgeBaseUrl) {
const base = bridgeBaseUrl.replace(/\/+$/, '')
return `${base}/code/${compatId}`
}
const baseUrl = getClaudeAiBaseUrl(compatId, ingressUrl)
return `${baseUrl}/code/${compatId}`
}