mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 18:50:56 +08:00
refactor(preferences): streamline API configuration retrieval
- Updated ApiServerService and ClaudeCodeService to use the new `getMultiple` method for fetching API server configuration from the preference service. - Simplified the structure of the returned configuration object, enhancing readability and maintainability. - Removed deprecated raw preference retrieval methods in favor of the new mapping approach.
This commit is contained in:
parent
8ea550d566
commit
747581dcfb
@ -61,19 +61,14 @@ export class ApiServerService {
|
||||
* Get current API server configuration from preference service
|
||||
*/
|
||||
getCurrentConfig(): ApiServerConfig {
|
||||
const config = preferenceService.getMultipleRaw([
|
||||
'feature.csaas.enabled',
|
||||
'feature.csaas.host',
|
||||
'feature.csaas.port',
|
||||
'feature.csaas.api_key'
|
||||
])
|
||||
const config = preferenceService.getMultiple({
|
||||
enabled: 'feature.csaas.enabled',
|
||||
host: 'feature.csaas.host',
|
||||
port: 'feature.csaas.port',
|
||||
apiKey: 'feature.csaas.api_key'
|
||||
}) as ApiServerConfig
|
||||
|
||||
return {
|
||||
enabled: config['feature.csaas.enabled'] ?? false,
|
||||
host: config['feature.csaas.host'] ?? 'localhost',
|
||||
port: config['feature.csaas.port'] ?? 23333,
|
||||
apiKey: config['feature.csaas.api_key'] ?? ''
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -101,11 +101,11 @@ class ClaudeCodeService implements AgentServiceInterface {
|
||||
return aiStream
|
||||
}
|
||||
|
||||
const apiConfig = preferenceService.getMultipleRaw([
|
||||
'feature.csaas.host',
|
||||
'feature.csaas.port',
|
||||
'feature.csaas.api_key'
|
||||
])
|
||||
const apiConfig = preferenceService.getMultiple({
|
||||
host: 'feature.csaas.host',
|
||||
port: 'feature.csaas.port',
|
||||
apiKey: 'feature.csaas.api_key'
|
||||
})
|
||||
const loginShellEnv = await getLoginShellEnvironment()
|
||||
const loginShellEnvWithoutProxies = Object.fromEntries(
|
||||
Object.entries(loginShellEnv).filter(([key]) => !key.toLowerCase().endsWith('_proxy'))
|
||||
@ -273,9 +273,9 @@ class ClaudeCodeService implements AgentServiceInterface {
|
||||
for (const mcpId of session.mcps) {
|
||||
mcpList[mcpId] = {
|
||||
type: 'http',
|
||||
url: `http://${apiConfig['feature.csaas.host']}:${apiConfig['feature.csaas.port']}/v1/mcps/${mcpId}/mcp`,
|
||||
url: `http://${apiConfig.host}:${apiConfig.port}/v1/mcps/${mcpId}/mcp`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiConfig['feature.csaas.api_key']}`
|
||||
Authorization: `Bearer ${apiConfig.apiKey}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user