GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
Managed SSH project selection repeatedly activated the remote Host and could leave idle ACP bindings rejected as stale-controller after a controller generation change. Host environment updates also coupled project state to component installation evidence and presented a crowded control surface. Project selection is now local-only, one Host connection serves compatible project and conversation callers, idle bindings are safely replaced only after proven controller takeover, and active prompts keep exact resume/replay. Remote environment setup now uses explicit signed compound package preparation with bounded transfer, rollback, recovery, and clearer settings. Managed Hosts must be updated to separately distributed Agent 0.11.6 before the daemon-side controller recovery fix takes effect. Desktop packages do not embed the Agent or remote Runtime, and existing project data is preserved. Release note: 托管 SSH 项目切换不再重复连接,同一 Host 可顺畅承载多个项目和对话;同时修复重连后的 stale-controller,并优化远程环境安装、更新与状态布局。
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { ensureModelOperationNotAborted } from './model-package-utils'
|
|
|
|
const MAX_REDIRECTS = 3
|
|
const redirectStatuses = new Set([301, 302, 303, 307, 308])
|
|
|
|
export function validateSecureDownloadUrl(
|
|
value: string,
|
|
downloadLabel: string
|
|
): URL {
|
|
const url = new URL(value)
|
|
if (
|
|
url.protocol !== 'https:' ||
|
|
(url.port !== '' && url.port !== '443') ||
|
|
url.username ||
|
|
url.password ||
|
|
url.hash
|
|
) {
|
|
throw new Error(
|
|
`${downloadLabel}下载地址必须是使用标准端口、无凭据和 Fragment 的 HTTPS URL`
|
|
)
|
|
}
|
|
return url
|
|
}
|
|
|
|
export function isDownloadRedirectStatus(status: number): boolean {
|
|
return redirectStatuses.has(status)
|
|
}
|
|
|
|
export async function fetchModelDownloadResponse(options: {
|
|
transport: typeof fetch
|
|
initialUrl: string
|
|
redirectHosts: readonly string[]
|
|
signal: AbortSignal
|
|
modelLabel: string
|
|
}): Promise<Response> {
|
|
let url = validateSecureDownloadUrl(
|
|
options.initialUrl,
|
|
options.modelLabel
|
|
)
|
|
const initialHost = url.hostname
|
|
const allowedRedirectHosts = new Set(options.redirectHosts)
|
|
for (let redirectCount = 0; ; redirectCount += 1) {
|
|
ensureModelOperationNotAborted(options.signal)
|
|
const response = await options.transport(url, {
|
|
method: 'GET',
|
|
redirect: 'manual',
|
|
credentials: 'omit',
|
|
cache: 'no-store',
|
|
signal: options.signal
|
|
})
|
|
if (!isDownloadRedirectStatus(response.status)) {
|
|
return response
|
|
}
|
|
if (redirectCount >= MAX_REDIRECTS) {
|
|
await response.body?.cancel().catch(() => undefined)
|
|
throw new Error(
|
|
`${options.modelLabel}下载重定向次数过多`
|
|
)
|
|
}
|
|
const location = response.headers.get('location')
|
|
await response.body?.cancel().catch(() => undefined)
|
|
if (!location) {
|
|
throw new Error(
|
|
`${options.modelLabel}下载重定向缺少地址`
|
|
)
|
|
}
|
|
const nextUrl = validateSecureDownloadUrl(
|
|
new URL(location, url).toString(),
|
|
options.modelLabel
|
|
)
|
|
if (
|
|
nextUrl.hostname !== initialHost &&
|
|
!allowedRedirectHosts.has(nextUrl.hostname)
|
|
) {
|
|
throw new Error(
|
|
`${options.modelLabel}下载重定向到未声明的主机`
|
|
)
|
|
}
|
|
url = nextUrl
|
|
}
|
|
}
|