()
| 2 | import { getDesktopAppVersion } from '../runtime-compat' |
| 3 | |
| 4 | export function buildChatLabUserAgentHeaders(): Record<string, string> { |
| 5 | const chatLabVersion = (() => { |
| 6 | try { |
| 7 | return getDesktopAppVersion(app.getVersion()) || 'dev' |
| 8 | } catch { |
| 9 | return 'dev' |
| 10 | } |
| 11 | })() |
| 12 | |
| 13 | const chatLabTag = `ChatLab/${chatLabVersion}` |
| 14 | const runtimeUA = (() => { |
| 15 | try { |
| 16 | return session.defaultSession.getUserAgent() |
| 17 | } catch { |
| 18 | // 默认会话未就绪时使用 Electron 级别回退 UA |
| 19 | return app.userAgentFallback || '' |
| 20 | } |
| 21 | })() |
| 22 | const userAgent = runtimeUA.includes(chatLabTag) ? runtimeUA : `${runtimeUA} ${chatLabTag}`.trim() |
| 23 | |
| 24 | return { |
| 25 | // 使用运行时真实 UA,并附加 ChatLab 版本标识,避免网关按 UA 策略拦截。 |
| 26 | 'User-Agent': userAgent, |
| 27 | 'X-ChatLab-Client': chatLabTag, |
| 28 | } |
| 29 | } |
no test coverage detected