mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 14:59:27 +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
|
* Get current API server configuration from preference service
|
||||||
*/
|
*/
|
||||||
getCurrentConfig(): ApiServerConfig {
|
getCurrentConfig(): ApiServerConfig {
|
||||||
const config = preferenceService.getMultipleRaw([
|
const config = preferenceService.getMultiple({
|
||||||
'feature.csaas.enabled',
|
enabled: 'feature.csaas.enabled',
|
||||||
'feature.csaas.host',
|
host: 'feature.csaas.host',
|
||||||
'feature.csaas.port',
|
port: 'feature.csaas.port',
|
||||||
'feature.csaas.api_key'
|
apiKey: 'feature.csaas.api_key'
|
||||||
])
|
}) as ApiServerConfig
|
||||||
|
|
||||||
return {
|
return config
|
||||||
enabled: config['feature.csaas.enabled'] ?? false,
|
|
||||||
host: config['feature.csaas.host'] ?? 'localhost',
|
|
||||||
port: config['feature.csaas.port'] ?? 23333,
|
|
||||||
apiKey: config['feature.csaas.api_key'] ?? ''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -101,11 +101,11 @@ class ClaudeCodeService implements AgentServiceInterface {
|
|||||||
return aiStream
|
return aiStream
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiConfig = preferenceService.getMultipleRaw([
|
const apiConfig = preferenceService.getMultiple({
|
||||||
'feature.csaas.host',
|
host: 'feature.csaas.host',
|
||||||
'feature.csaas.port',
|
port: 'feature.csaas.port',
|
||||||
'feature.csaas.api_key'
|
apiKey: 'feature.csaas.api_key'
|
||||||
])
|
})
|
||||||
const loginShellEnv = await getLoginShellEnvironment()
|
const loginShellEnv = await getLoginShellEnvironment()
|
||||||
const loginShellEnvWithoutProxies = Object.fromEntries(
|
const loginShellEnvWithoutProxies = Object.fromEntries(
|
||||||
Object.entries(loginShellEnv).filter(([key]) => !key.toLowerCase().endsWith('_proxy'))
|
Object.entries(loginShellEnv).filter(([key]) => !key.toLowerCase().endsWith('_proxy'))
|
||||||
@ -273,9 +273,9 @@ class ClaudeCodeService implements AgentServiceInterface {
|
|||||||
for (const mcpId of session.mcps) {
|
for (const mcpId of session.mcps) {
|
||||||
mcpList[mcpId] = {
|
mcpList[mcpId] = {
|
||||||
type: 'http',
|
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: {
|
headers: {
|
||||||
Authorization: `Bearer ${apiConfig['feature.csaas.api_key']}`
|
Authorization: `Bearer ${apiConfig.apiKey}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user