(info = {})
| 219 | } |
| 220 | |
| 221 | function syncClaudeProxySettings(info = {}) { |
| 222 | const env = info.env || process.env; |
| 223 | if (isDisabled(env)) { |
| 224 | return { synced: false, reason: 'disabled' }; |
| 225 | } |
| 226 | |
| 227 | const url = normalizeUrl(info.url); |
| 228 | const token = typeof info.token === 'string' ? info.token.trim() : ''; |
| 229 | if (!url || !isValidReusableProxyToken(token)) { |
| 230 | return { synced: false, reason: 'missing_proxy_settings' }; |
| 231 | } |
| 232 | |
| 233 | const resolved = resolveClaudeSettingsFile(info, env); |
| 234 | const file = resolved.file; |
| 235 | if (!file) { |
| 236 | return { synced: false, changed: false, reason: resolved.reason || 'missing_settings_path' }; |
| 237 | } |
| 238 | |
| 239 | const currentResult = readJsonFileResult(file); |
| 240 | if (currentResult.exists && !currentResult.ok) { |
| 241 | const backupFile = info.backup === false ? null : backupExistingFile(file); |
| 242 | return { |
| 243 | synced: false, |
| 244 | changed: false, |
| 245 | reason: 'invalid_settings_json', |
| 246 | file, |
| 247 | backupFile, |
| 248 | }; |
| 249 | } |
| 250 | const current = currentResult.value; |
| 251 | const settings = current && typeof current === 'object' && !Array.isArray(current) |
| 252 | ? current |
| 253 | : {}; |
| 254 | const cfg = settings.env && typeof settings.env === 'object' && !Array.isArray(settings.env) |
| 255 | ? { ...settings.env } |
| 256 | : {}; |
| 257 | |
| 258 | const existingBase = normalizeUrl(cfg.ANTHROPIC_BASE_URL); |
| 259 | const existingToken = typeof cfg.ANTHROPIC_AUTH_TOKEN === 'string' |
| 260 | ? cfg.ANTHROPIC_AUTH_TOKEN.trim() |
| 261 | : ''; |
| 262 | const existingApiKey = typeof cfg.ANTHROPIC_API_KEY === 'string' |
| 263 | ? cfg.ANTHROPIC_API_KEY.trim() |
| 264 | : ''; |
| 265 | const existingStoredUpstreamBase = normalizeUrl(cfg.EVOMAP_ANTHROPIC_BASE_URL); |
| 266 | const existingStoredUpstreamAuthToken = typeof cfg.EVOMAP_ANTHROPIC_AUTH_TOKEN === 'string' |
| 267 | ? cfg.EVOMAP_ANTHROPIC_AUTH_TOKEN.trim() |
| 268 | : ''; |
| 269 | const existingUpstreamApiKey = typeof cfg.EVOMAP_ANTHROPIC_API_KEY === 'string' |
| 270 | ? cfg.EVOMAP_ANTHROPIC_API_KEY.trim() |
| 271 | : ''; |
| 272 | const existingBaseIsProxy = isManagedProxyBaseUrl(settings, cfg, existingBase, info); |
| 273 | const runtimeEnv = info.runtimeEnv && typeof info.runtimeEnv === 'object' |
| 274 | ? info.runtimeEnv |
| 275 | : null; |
| 276 | |
| 277 | let changed = false; |
| 278 | let runtimeChanged = false; |
no test coverage detected