feat: add A-Copilot settings and refine AI configuration layout
This commit is contained in:
@@ -6,7 +6,7 @@ const ts = require('typescript');
|
||||
const React = require('react');
|
||||
|
||||
const source = ts.createSourceFile('SettingsPage.tsx', fs.readFileSync(require.resolve('../src/pages/settings/SettingsPage.tsx'), 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
||||
const constants = source.statements.filter(node => ts.isVariableStatement(node) && ['AI_MODEL_DEFAULTS', 'AI_MODEL_OPTIONS', 'CUSTOM_AI_MODEL'].includes(node.declarationList.declarations[0].name.getText(source)));
|
||||
const constants = source.statements.filter(node => ts.isVariableStatement(node) && ['AI_MODEL_DEFAULTS', 'AI_MODEL_OPTIONS', 'CUSTOM_AI_MODEL', 'AI_PROVIDER_LABELS'].includes(node.declarationList.declarations[0].name.getText(source)));
|
||||
function compile(code, globals = {}) {
|
||||
const exports = {};
|
||||
vm.runInNewContext(ts.transpileModule(code, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.ReactJSX } }).outputText, { exports, require, ...globals });
|
||||
@@ -19,11 +19,11 @@ function find(node, predicate) {
|
||||
return ts.forEachChild(node, child => find(child, predicate));
|
||||
}
|
||||
const section = find(source, node => ts.isJsxElement(node) && node.openingElement.tagName.getText(source) === 'section' && node.openingElement.attributes.getText(source).includes('border-t border-[#e2e8f0] pt-5') && node.getText(source).includes('AI 공급자'));
|
||||
function controls(provider, model, custom = false) {
|
||||
function controls(provider, model, custom = false, configured = true) {
|
||||
const state = { aiProvider: provider, aiModel: model, aiCustomModel: custom };
|
||||
const context = {
|
||||
aiSettingLoading: false, saving: false, aiEndpointUrl: 'https://example.test', aiApiKey: '', aiHasApiKey: false, aiConfiguredProvider: null,
|
||||
AI_PROVIDER_LABELS: { OPENAI: 'OpenAI', ANTHROPIC: 'Claude', GEMINI: 'Gemini', QWEN: 'Qwen' },
|
||||
aiCopilotConfigured: configured,
|
||||
DEFAULT_QWEN_ENDPOINT: 'https://example.test', KeyRound: () => null,
|
||||
setAiProvider(value) { state.aiProvider = value; }, setAiModel(value) { state.aiModel = value; },
|
||||
setAiCustomModel(value) { state.aiCustomModel = value; }, setAiApiKey() {}, setAiEndpointUrl() {},
|
||||
@@ -37,7 +37,7 @@ function elements(root, predicate) {
|
||||
}
|
||||
|
||||
for (const provider of Object.keys(AI_MODEL_OPTIONS)) {
|
||||
test(`${provider} offers current models and a custom model field without changing defaults`, () => {
|
||||
test(`${provider} offers current models and a custom model field`, () => {
|
||||
const h = controls(provider, AI_MODEL_DEFAULTS[provider]);
|
||||
let tree = h.render();
|
||||
const select = elements(tree, node => node.type === 'select')[0];
|
||||
@@ -60,6 +60,18 @@ for (const provider of Object.keys(AI_MODEL_OPTIONS)) {
|
||||
});
|
||||
}
|
||||
|
||||
test('provider defaults select the highest-tier current models at the top of each list', () => {
|
||||
const expected = { OPENAI: 'gpt-6-astra', ANTHROPIC: 'claude-fable-5-1', GEMINI: 'gemini-4-argon', QWEN: 'qwen3.8-max' };
|
||||
for (const [provider, model] of Object.entries(expected)) {
|
||||
assert.equal(AI_MODEL_DEFAULTS[provider], model);
|
||||
assert.equal(AI_MODEL_OPTIONS[provider][0].value, model);
|
||||
const h = controls('QWEN', 'qwen3.7-plus');
|
||||
if (provider === 'QWEN') h.state.aiProvider = 'OPENAI';
|
||||
elements(h.render(), node => node.props.role === 'radio' && node.props.children === ({ OPENAI: 'OpenAI', ANTHROPIC: 'Claude', GEMINI: 'Gemini', QWEN: 'Qwen' })[provider])[0].props.onClick();
|
||||
assert.equal(h.state.aiModel, model);
|
||||
}
|
||||
});
|
||||
|
||||
test('saved unknown model IDs remain visible in custom mode', () => {
|
||||
const model = 'provider/private-model:revision-10';
|
||||
const h = controls('QWEN', model, true);
|
||||
@@ -72,15 +84,26 @@ test('saved unknown model IDs remain visible in custom mode', () => {
|
||||
test('the selected provider button preserves a custom draft', () => {
|
||||
const h = controls('OPENAI', 'custom-gpt', true);
|
||||
const providers = elements(h.render(), node => node.props.role === 'radio');
|
||||
providers[0].props.onClick();
|
||||
providers.find(node => node.props.children === 'OpenAI').props.onClick();
|
||||
assert.equal(h.state.aiModel, 'custom-gpt');
|
||||
assert.equal(h.state.aiCustomModel, true);
|
||||
providers[1].props.onClick();
|
||||
providers.find(node => node.props.children === 'Claude').props.onClick();
|
||||
assert.equal(h.state.aiProvider, 'ANTHROPIC');
|
||||
assert.equal(h.state.aiModel, AI_MODEL_DEFAULTS.ANTHROPIC);
|
||||
assert.equal(h.state.aiCustomModel, false);
|
||||
});
|
||||
|
||||
test('A-Copilot is first and exposes only fixed read-only fields without a model picker', () => {
|
||||
const tree = controls('A_COPILOT', 'a-copilot').render();
|
||||
assert.equal(elements(tree, node => node.props.role === 'radio')[0].props.children, 'A-Copilot');
|
||||
assert.equal(elements(tree, node => node.type === 'select').length, 0);
|
||||
const inputs = elements(tree, node => node.type === 'input');
|
||||
assert.deepEqual(inputs.map(node => node.props.value), ['A-Copilot', '서버에서 관리']);
|
||||
assert.ok(inputs.every(node => node.props.readOnly && !node.props.onChange));
|
||||
assert.equal(AI_MODEL_DEFAULTS.A_COPILOT, 'a-copilot');
|
||||
assert.equal(elements(controls('A_COPILOT', 'a-copilot', false, false).render(), node => node.props.role === 'alert').length, 1);
|
||||
});
|
||||
|
||||
test('official current API IDs are present', () => {
|
||||
for (const [provider, ids] of Object.entries({
|
||||
OPENAI: ['gpt-6.1-sol', 'gpt-6-astra', 'gpt-6-luna'],
|
||||
|
||||
Reference in New Issue
Block a user