MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / buildChatLabUserAgentHeaders

Function buildChatLabUserAgentHeaders

apps/desktop/main/utils/httpHeaders.ts:4–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { getDesktopAppVersion } from '../runtime-compat'
3
4export 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}

Callers 2

buildPiModelFunction · 0.90
electronRemoteApiOptionsFunction · 0.90

Calls 2

getDesktopAppVersionFunction · 0.90
getVersionMethod · 0.65

Tested by

no test coverage detected