Fix/moonshot cn web search domain (#338)
This commit is contained in:
committed by
GitHub
Unverified
parent
b41a8eedd9
commit
c03d92e9a2
@@ -10,6 +10,7 @@ import {
|
||||
BUILTIN_PROVIDER_TYPES,
|
||||
getProviderConfig,
|
||||
getProviderEnvVar,
|
||||
getProviderEnvVars,
|
||||
} from '@electron/utils/provider-registry';
|
||||
|
||||
describe('provider metadata', () => {
|
||||
@@ -40,6 +41,17 @@ describe('provider metadata', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('uses a single canonical env key for moonshot provider', () => {
|
||||
expect(getProviderEnvVar('moonshot')).toBe('MOONSHOT_API_KEY');
|
||||
expect(getProviderEnvVars('moonshot')).toEqual(['MOONSHOT_API_KEY']);
|
||||
expect(getProviderConfig('moonshot')).toEqual(
|
||||
expect.objectContaining({
|
||||
baseUrl: 'https://api.moonshot.cn/v1',
|
||||
apiKeyEnv: 'MOONSHOT_API_KEY',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps builtin provider sources in sync', () => {
|
||||
expect(BUILTIN_PROVIDER_TYPES).toEqual(
|
||||
expect.arrayContaining(['anthropic', 'openai', 'google', 'openrouter', 'ark', 'moonshot', 'siliconflow', 'minimax-portal', 'minimax-portal-cn', 'qwen-portal', 'ollama'])
|
||||
|
||||
@@ -53,6 +53,23 @@ async function sanitizeConfig(filePath: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
// Mirror: remove stale tools.web.search.kimi.apiKey when moonshot provider exists.
|
||||
const providers = ((config.models as Record<string, unknown> | undefined)?.providers as Record<string, unknown> | undefined) || {};
|
||||
if (providers.moonshot) {
|
||||
const tools = (config.tools as Record<string, unknown> | undefined) || {};
|
||||
const web = (tools.web as Record<string, unknown> | undefined) || {};
|
||||
const search = (web.search as Record<string, unknown> | undefined) || {};
|
||||
const kimi = (search.kimi as Record<string, unknown> | undefined) || {};
|
||||
if ('apiKey' in kimi) {
|
||||
delete kimi.apiKey;
|
||||
search.kimi = kimi;
|
||||
web.search = search;
|
||||
tools.web = web;
|
||||
config.tools = tools;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
await writeFile(filePath, JSON.stringify(config, null, 2), 'utf-8');
|
||||
}
|
||||
@@ -223,4 +240,58 @@ describe('sanitizeOpenClawConfig (blocklist approach)', () => {
|
||||
expect(result.gateway).toEqual({ mode: 'local', auth: { token: 'xyz' } });
|
||||
expect(result.agents).toEqual({ defaults: { model: { primary: 'gpt-4' } } });
|
||||
});
|
||||
|
||||
it('removes tools.web.search.kimi.apiKey when moonshot provider exists', async () => {
|
||||
await writeConfig({
|
||||
models: {
|
||||
providers: {
|
||||
moonshot: { baseUrl: 'https://api.moonshot.cn/v1', api: 'openai-completions' },
|
||||
},
|
||||
},
|
||||
tools: {
|
||||
web: {
|
||||
search: {
|
||||
kimi: {
|
||||
apiKey: 'stale-inline-key',
|
||||
baseUrl: 'https://api.moonshot.cn/v1',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const modified = await sanitizeConfig(configPath);
|
||||
expect(modified).toBe(true);
|
||||
|
||||
const result = await readConfig();
|
||||
const kimi = ((((result.tools as Record<string, unknown>).web as Record<string, unknown>).search as Record<string, unknown>).kimi as Record<string, unknown>);
|
||||
expect(kimi).not.toHaveProperty('apiKey');
|
||||
expect(kimi.baseUrl).toBe('https://api.moonshot.cn/v1');
|
||||
});
|
||||
|
||||
it('keeps tools.web.search.kimi.apiKey when moonshot provider is absent', async () => {
|
||||
const original = {
|
||||
models: {
|
||||
providers: {
|
||||
openrouter: { baseUrl: 'https://openrouter.ai/api/v1', api: 'openai-completions' },
|
||||
},
|
||||
},
|
||||
tools: {
|
||||
web: {
|
||||
search: {
|
||||
kimi: {
|
||||
apiKey: 'should-stay',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
await writeConfig(original);
|
||||
|
||||
const modified = await sanitizeConfig(configPath);
|
||||
expect(modified).toBe(false);
|
||||
|
||||
const result = await readConfig();
|
||||
expect(result).toEqual(original);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user