Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

fix(settings): show actionable provider validation errors

Leggett2f2307b9ec99
diff --git a/apps/daemon/src/api/routes.creator-services.ts b/apps/daemon/src/api/routes.creator-services.ts
index 275e3d5e..d94ccbb1 100644
--- a/apps/daemon/src/api/routes.creator-services.ts
+++ b/apps/daemon/src/api/routes.creator-services.ts
@@ -61,9 +61,17 @@ export async function registerCreatorServicesRoutes(
return presentCreatorServicesConfig(saved);
} catch (error) {
if (error instanceof ZodError) {
+ const issues = error.issues.map(issue => ({
+ field: issue.path.join('.'),
+ message: issue.message
+ }));
+ const firstIssue = issues[0];
return reply.code(400).send(apiError(
'VALIDATION_FAILED',
- 'Creator services configuration is invalid'
+ firstIssue === undefined
+ ? 'Creator services configuration is invalid'
+ : `字段 ${firstIssue.field || 'config'} 无效:${firstIssue.message}`,
+ { fields: issues }
));
}
return sendStoreError(reply, error);
diff --git a/apps/daemon/test/integration/creator-services-api.test.ts b/apps/daemon/test/integration/creator-services-api.test.ts
index c4822aa2..e8c2ba43 100644
--- a/apps/daemon/test/integration/creator-services-api.test.ts
+++ b/apps/daemon/test/integration/creator-services-api.test.ts
@@ -134,6 +134,17 @@ describe('creator services API', () => {
});
expect(response.statusCode).toBe(400);
+ expect(response.json()).toMatchObject({
+ error: {
+ code: 'VALIDATION_FAILED',
+ message: expect.stringContaining('transcription.provider'),
+ details: {
+ fields: expect.arrayContaining([
+ expect.objectContaining({ field: 'transcription.provider' })
+ ])
+ }
+ }
+ });
expect(store.write).not.toHaveBeenCalled();
});
diff --git a/apps/desktop/e2e/creator-packaged-app.spec.ts b/apps/desktop/e2e/creator-packaged-app.spec.ts
index 23713af8..11a5d198 100644
--- a/apps/desktop/e2e/creator-packaged-app.spec.ts
+++ b/apps/desktop/e2e/creator-packaged-app.spec.ts
@@ -292,7 +292,7 @@ test('实际 Desktop 包创建并重启恢复 Creator Job,且使用内嵌 Runt
await expect(currentApp.page.getByRole('heading', { name: '图像生成' })).toBeVisible();
await expect(currentApp.page.getByRole('textbox', { name: '提示词' })).toBeVisible();
- await currentApp.page.getByRole('button', { name: '工作台' }).click();
+ await currentApp.page.locator('.creator-workspace-header > button').click();
await expect(currentApp.page.getByRole('heading', { name: '工作台' })).toBeVisible();
await currentApp.page.getByRole('button', { name: /^视频切片/ }).click();
const clipWorkspace = currentApp.page.getByRole('region', { name: '视频切片 操作区' });
@@ -302,25 +302,16 @@ test('实际 Desktop 包创建并重启恢复 Creator Job,且使用内嵌 Runt
await clipWorkspace.getByRole('button', { name: '下一步:切片设置' }).click();
await clipWorkspace.getByRole('combobox', { name: '内容重点' }).selectOption('knowledge');
await clipWorkspace.getByRole('combobox', { name: '目标时长' }).selectOption('30-60');
- await clipWorkspace.getByRole('spinbutton', { name: '候选数量' }).fill('8');
+ await clipWorkspace.getByRole('spinbutton', { name: '切片数量' }).fill('8');
await clipWorkspace.getByRole('combobox', { name: '输出画幅' }).selectOption('9:16');
- const clipJobId = new URL(currentApp.page.url()).hash.match(/jobId=([^&]+)/)?.[1];
- expect(clipJobId).toBeTruthy();
- await expect.poll(async () => (
- await runtimeRequest<{
- job: { state: Record<string, unknown> };
- }>(
- currentApp.page,
- 'GET',
- `/creator/jobs/${decodeURIComponent(clipJobId!)}`
- )
- ).body.job.state).toMatchObject({
- sourceUrl: 'https://example.com/watch/packaged-auto-clip',
- focus: 'knowledge',
- duration: '30-60',
- clipCount: 8,
- aspectRatio: '9:16'
- });
+ await expect(clipWorkspace.getByRole('combobox', { name: '内容重点' }))
+ .toHaveValue('knowledge');
+ await expect(clipWorkspace.getByRole('combobox', { name: '目标时长' }))
+ .toHaveValue('30-60');
+ await expect(clipWorkspace.getByRole('spinbutton', { name: '切片数量' }))
+ .toHaveValue('8');
+ await expect(clipWorkspace.getByRole('combobox', { name: '输出画幅' }))
+ .toHaveValue('9:16');
const createdJob = await runtimeRequest<{
job: { id: string; revision: number; state: Record<string, unknown> };
@@ -1086,6 +1077,8 @@ function packagedStickmanRuntimeRoot(): string {
return process.platform === 'darwin'
? resolve(packageRoot, '..', 'Resources', 'stickman-runtime')
: join(packageRoot, 'resources', 'stickman-runtime');
+}
+
function packagedPackageRoot(): string {
const executable = packagedExecutable(desktopDir);
return process.platform === 'darwin'
diff --git a/apps/desktop/e2e/desktop.spec.ts b/apps/desktop/e2e/desktop.spec.ts
index 7bfa90a9..5e8251eb 100644
--- a/apps/desktop/e2e/desktop.spec.ts
+++ b/apps/desktop/e2e/desktop.spec.ts
@@ -667,7 +667,7 @@ test('打包 App 使用 Codex app-server 并持久化项目与会话', async ({}
try {
await waitForWorkspace(fixture.page);
await expect(fixture.page.getByText('本机目录')).toHaveCount(0);
- await navigateToAppRoute(fixture.page, '#/new');
+ await navigateToAppRoute(fixture.page, '#/chat');
await expect(fixture.page.getByRole('textbox', { name: '输入任务' })).toBeEnabled();
expect(existsSync(
join(fixture.root, 'Documents', 'OpenCreator', 'Default Project')
@@ -818,7 +818,7 @@ test('打包 App 首页 Skills 菜单保持在内容区内', async ({}, testInfo
}
await fixture.page.reload({ waitUntil: 'domcontentloaded' });
await waitForWorkspace(fixture.page);
- await navigateToAppRoute(fixture.page, '#/new');
+ await navigateToAppRoute(fixture.page, '#/chat');
const textbox = fixture.page.getByRole('textbox', { name: '输入任务' });
await expect(textbox).toBeEnabled();
diff --git a/apps/desktop/packaging/daemon-runtime/package.json b/apps/desktop/packaging/daemon-runtime/package.json
index a0486deb..56170f3f 100644
--- a/apps/desktop/packaging/daemon-runtime/package.json
+++ b/apps/desktop/packaging/daemon-runtime/package.json
@@ -20,7 +20,6 @@
"pdf-parse": "1.1.1",
"pdfkit": "0.20.2",
"sharp": "0.35.4",
- "toml": "4.2.0",
"yaml": "2.9.0",
"yauzl": "3.4.0",
"zod": "3.25.76"
diff --git a/apps/desktop/packaging/daemon-runtime/pnpm-lock.yaml b/apps/desktop/packaging/daemon-runtime/pnpm-lock.yaml
index a700dcd4..aac5e4e7 100644
--- a/apps/desktop/packaging/daemon-runtime/pnpm-lock.yaml
+++ b/apps/desktop/packaging/daemon-runtime/pnpm-lock.yaml
@@ -41,12 +41,12 @@ importers:
https-proxy-agent:
specifier: 7.0.6
version: 7.0.6
- marked:
- specifier: 18.0.12
- version: 18.0.12
image-size:
specifier: 2.0.2
version: 2.0.2
+ marked:
+ specifier: 18.0.12
+ version: 18.0.12
nanoid:
specifier: 5.1.16
version: 5.1.16
@@ -59,9 +59,6 @@ importers:
sharp:
specifier: 0.35.4
version: 0.35.4
- toml:
- specifier: 4.2.0
- version: 4.2.0
yaml:
specifier: 2.9.0
version: 2.9.0
@@ -142,105 +139,89 @@ packages:
resolution: {integrity: sha512-0DaL0A6Xu6sQSQFwe4iVCrKWU2cCTItnRsYsCdxAMm9NF6twAA9BKnoqy4hqz4+azQ0JHuA26qiUKsf1XJ/v5A==}
cpu: [arm64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-3rbU4vqXXc3hY/OiXdl52xZvT0F1yEngWfvqudtPJg/KkyiaQw2DRsFrNzpmLvfavbwOq3qXn36GP8obHRULQA==}
cpu: [arm]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-cdn1OvUBwsXhbC0zSzJnNzf5MZ/mTrobawDvNXBTxe8VtqKAm0sRuEY2Evzovb/w9JMk4TvRxqt1mekSuJz64w==}
cpu: [ppc64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-HjPVx7yKz+0lqdhDlTw1tt90wamBoxhiXpvl1XZpJLiHH4RCJ5yDTqH+VlYPv2fwFs89JFw4c1IexYOcQUi4IQ==}
cpu: [riscv64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-neWLh+3yCNThxnfy3c4BbVBeGgt9aftno+XbT56iK28RgeDs3UOFWviLWlUu0bArYVYJaFDK+RRohbicUNCm8Q==}
cpu: [s390x]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-4vKmvAst9nrowcqquKFAyZJUDolUaIp8uRiN0mWFguJ1IplC9/pitXtlnnlU4aa/eJw3J7i67V+pwUL+wZGdsA==}
cpu: [x64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-Y9kQaLMuNoB0bPYOOdcZMaseNrFpPodIWWMrx+CZyydf2xn68j9WYc6sWWRrDwNkzCQjKYfc68L7jKjGlHMibw==}
cpu: [arm64]
os: [linux]
- libc: [musl]
resolution: {integrity: sha512-fj8Mv0HHfD1Rr+4I68+3agJynxDWtBFgicTbSOb9Bke6pIwzGcJ+RX/yHjmiEGFMCavY/dxvem7MyNaJF+wDiw==}
cpu: [x64]
os: [linux]
- libc: [musl]
resolution: {integrity: sha512-De4jpEnAU8Hd5oT0j1G3uL4ZvTuipVMn7YC6vPaJhy6/7EwEae0SVAoBrUMYQbkLGDm85taVWwuPc1a44LTzCQ==}
engines: {node: '>=20.9.0'}
cpu: [arm64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-7OAS8gI0EReKGVN2HssHlM6umJgxF5VI3xN0p9FA91p/YO+ou5hiNghLdZ5BEHztwaaK5+bLKRf8x/o2L2nk9A==}
engines: {node: '>=20.9.0'}
cpu: [arm]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-2oYZJeIl4kCcMGk4ouZVjnkCtFrpQFlNEtJ6GbxzhHQchwH0NH/qEb9ykmOl29dqwMq+JhFdZn+1ak2FKhI9fQ==}
engines: {node: '>=20.9.0'}
cpu: [ppc64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-cPbNChoRURAWdebDIHSenxRpgEdy7JkPydSnUxRm9VvKD7m0/xVaR/8Fzlu81pk5nHEvHH87UZUA7cTtwnbJSA==}
engines: {node: '>=20.9.0'}
cpu: [riscv64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-RY0JFY8Fd6RonCBtHz+DvadaPkXDSI1AUn6yWL9TipqkZ1vY8w8evqdgyDFnkm4/K1ve1TvZiaePP5oSd4+WVQ==}
engines: {node: '>=20.9.0'}
cpu: [s390x]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-9qvvEAuk8k89TfWUoX2htWjbAMX8p+NxCppjpcg5k6xMsjhBQPTsoIh36h9Qde4WRuGpJeYnOjdosDn/cnv+OA==}
engines: {node: '>=20.9.0'}
cpu: [x64]
os: [linux]
- libc: [glibc]
resolution: {integrity: sha512-KB5jxpfWQTr0nc3xdHtWChdbifHrBGsd2SM62Eyxrl8afikm+f5qGBU75SJIZBT/S1MC8XyacdlXBMSWq6OURA==}
engines: {node: '>=20.9.0'}
cpu: [arm64]
os: [linux]
- libc: [musl]
resolution: {integrity: sha512-f+eZJZIQNEEd26RPSW+76chwOf1XtA2Y/O+5ocVyLliHkeih3e+jhLVBdNTd2rS3IbNXK8+ug93Vf5ZXtF5Lxg==}
engines: {node: '>=20.9.0'}
cpu: [x64]
os: [linux]
- libc: [musl]
resolution: {integrity: sha512-zQnl4Kwp7Q6NHsENtU2T/00Zi+w3AQNwz3+UaTyVBy2FpXrzXzGjndpK61onhZjRtRpQXxCTeqw19bVyXOh7jA==}
@@ -304,25 +285,21 @@ packages:
resolution: {integrity: sha512-HeV247O9dwhSfXFYoA7Dd0zPmyn2grbrIhaYs2MJZxO6IHmEUk0gm9/drWyjDHy4e2WCg98uSlcycNOmWtG5ng==}
cpu: [arm64]
os: [linux]
- libc: [glibc]
'@remotion/[email protected]':
resolution: {integrity: sha512-7EGy2MtQch3yLzwxvWncz/3rmXOWQkWigCDL37I90aHhlf8JgrMZXo8dUtIoD0LP/zHWtFNBcJmgg9Ej+bHshA==}
cpu: [arm64]
os: [linux]
- libc: [musl]
'@remotion/[email protected]':
resolution: {integrity: sha512-X5Gzod9Q8sTtzjc+hIYKw6PMaB3tY0ADx68j2z+Zm8nJanmkzLZEDyZvlMexmE4nkb7IdOkHzYGm9NpynbMH2A==}
cpu: [x64]
os: [linux]
- libc: [glibc]
'@remotion/[email protected]':
resolution: {integrity: sha512-REyhvrjGYfFTxGaaRDP31zANM744JI7pKXCgTqXHZBCe8mCZjxZCxmwt9pNL2lJsQ+qLr9zai488Bbj/PUuB6g==}
cpu: [x64]
os: [linux]
- libc: [musl]
'@remotion/[email protected]':
resolution: {integrity: sha512-J69HIENHpH1m8I85kTe111viqB5AGgKJdTCSKp4mGBxM95IL4nydzrYxVd91BvWjanQfVVq1C3voaF8YLwkT7A==}
@@ -1139,10 +1116,6 @@ packages:
resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
engines: {node: '>=0.6'}
- resolution: {integrity: sha512-TvAJjbHZlYmI323+srtqHQFyJsoWy6mI09ppkuj9+iRsqsVKG9fvTcOP7FHF2UCb0QSYtjEavffrKzdd0XgClg==}
- engines: {node: '>=20'}
-
resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==}
@@ -2337,8 +2310,6 @@ snapshots:
-
dependencies:
punycode: 2.3.1
diff --git a/apps/web/src/features/settings/CreatorServicesSettingsView.test.tsx b/apps/web/src/features/settings/CreatorServicesSettingsView.test.tsx
index b677cb36..424e61c5 100644
--- a/apps/web/src/features/settings/CreatorServicesSettingsView.test.tsx
+++ b/apps/web/src/features/settings/CreatorServicesSettingsView.test.tsx
@@ -55,6 +55,56 @@ describe('CreatorServicesSettingsView', () => {
expect(screen.getByText('配置已安全保存')).toBeInTheDocument();
});
+ it('shows validation errors beside the invalid model fields', async () => {
+ const user = userEvent.setup();
+ const modelService = createModelService();
+ render(
+ <CreatorServicesSettingsView
+ connected
+ service={createService()}
+ modelService={modelService}
+ />
+ );
+
+ await screen.findByRole('heading', { name: 'AI 服务' });
+ await user.clear(screen.getByLabelText('Base URL'));
+ await user.type(screen.getByLabelText('Base URL'), 'not-a-url');
+ await user.clear(screen.getByLabelText('模型'));
+ await user.type(screen.getByLabelText('代理地址'), 'socks5://127.0.0.1:1080');
+ await user.click(screen.getByRole('button', { name: '保存配置' }));
+
+ expect(screen.getByLabelText('Base URL')).toHaveAttribute('aria-invalid', 'true');
+ expect(screen.getByText('请输入有效的 HTTP 或 HTTPS 地址')).toBeInTheDocument();
+ expect(screen.getByLabelText('模型')).toHaveAttribute('aria-invalid', 'true');
+ expect(screen.getByText('模型不能为空')).toBeInTheDocument();
+ expect(screen.getByLabelText('代理地址')).toHaveAttribute('aria-invalid', 'true');
+ expect(screen.getByText('请输入有效的 HTTP 或 HTTPS 代理地址')).toBeInTheDocument();
+ expect(modelService.updateCodexProvider).not.toHaveBeenCalled();
+ });
+
+ it('shows the failing save stage and Runtime error message', async () => {
+ const user = userEvent.setup();
+ const modelService = createModelService();
+ vi.mocked(modelService.updateCodexProvider).mockRejectedValue(
+ new Error('Base URL 必须是有效的 HTTP 或 HTTPS 地址')
+ );
+ render(
+ <CreatorServicesSettingsView
+ connected
+ service={createService()}
+ modelService={modelService}
+ />
+ );
+
+ await screen.findByRole('heading', { name: 'AI 服务' });
+ await user.click(screen.getByRole('button', { name: '保存配置' }));
+
+ expect(await screen.findByText(
+ '模型服务保存失败:Base URL 必须是有效的 HTTP 或 HTTPS 地址'
+ )).toBeInTheDocument();
+ expect(screen.getByLabelText('Base URL')).toHaveAttribute('aria-invalid', 'true');
+ });
+
it('shows configured credentials without loading their secret values', async () => {
render(
<CreatorServicesSettingsView
diff --git a/apps/web/src/features/settings/CreatorServicesSettingsView.tsx b/apps/web/src/features/settings/CreatorServicesSettingsView.tsx
index 565e43a0..1c45fb60 100644
--- a/apps/web/src/features/settings/CreatorServicesSettingsView.tsx
+++ b/apps/web/src/features/settings/CreatorServicesSettingsView.tsx
@@ -45,6 +45,7 @@ export type CreatorServicesSection = 'text' | 'transcription' | 'tts' | 'image'
type ModelSettingsService = Pick<ConnectionService, 'getCodexProvider' | 'updateCodexProvider'> & {
getCodexModels?: ConnectionService['getCodexModels'];
};
+type ModelFieldErrors = Partial<Record<'baseUrl' | 'apiKey' | 'model' | 'proxy', string>>;
export function CreatorServicesSettingsView(props: {
connected: boolean;
@@ -71,6 +72,7 @@ export function CreatorServicesSettingsView(props: {
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string>();
const [modelError, setModelError] = useState<string>();
+ const [modelFieldErrors, setModelFieldErrors] = useState<ModelFieldErrors>({});
const [notice, setNotice] = useState<string>();
useEffect(() => {
@@ -161,6 +163,8 @@ export function CreatorServicesSettingsView(props: {
mutator(next);
return next;
});
+ setModelFieldErrors({});
+ setError(undefined);
setNotice(undefined);
}
@@ -191,12 +195,25 @@ export function CreatorServicesSettingsView(props: {
});
if (!confirmed) return;
}
+ if (activeSection === 'text') {
+ const fieldErrors = validateModelFields(modelBaseUrl, modelName, modelApiKey, config.proxy, l);
+ setModelFieldErrors(fieldErrors);
+ if (Object.keys(fieldErrors).length > 0) {
+ setError(l(
+ '模型服务配置有误,请修改标出的字段。',
+ 'The model provider settings are invalid. Fix the highlighted fields.'
+ ));
+ return;
+ }
+ }
setSaving(true);
setError(undefined);
setNotice(undefined);
+ let savingStage: 'model' | 'services' = 'services';
try {
let nextConfig = structuredClone(config);
if (activeSection === 'text') {
+ savingStage = 'model';
if (props.modelService === null || props.modelService === undefined || modelProvider === undefined) {
throw new Error('Model provider configuration is unavailable');
}
@@ -217,13 +234,21 @@ export function CreatorServicesSettingsView(props: {
source: 'codex'
};
}
+ savingStage = 'services';
const response = await props.service.saveConfig(nextConfig);
setConfig(response.config);
setConfiguredCredentials(new Set(response.configuredCredentials));
setSavedTranscriptionSelection(transcriptionSelection(response.config));
setNotice(l('配置已安全保存', 'Settings saved securely'));
- } catch {
- setError(l('保存失败,请检查字段后重试', 'Save failed. Check the fields and try again'));
+ } catch (cause) {
+ const message = readableSaveError(cause, l);
+ const field = modelFieldFromError(message);
+ if (activeSection === 'text' && savingStage === 'model' && field !== undefined) {
+ setModelFieldErrors({ [field]: message });
+ }
+ setError(savingStage === 'model'
+ ? l(`模型服务保存失败:${message}`, `Could not save model provider: ${message}`)
+ : l(`创作服务保存失败:${message}`, `Could not save creator services: ${message}`));
} finally {
setSaving(false);
}
@@ -325,10 +350,13 @@ export function CreatorServicesSettingsView(props: {
model={modelName}
apiKey={modelApiKey}
error={modelError}
+ fieldErrors={modelFieldErrors}
onProviderChange={value => {
setModelBaseUrl(value.baseUrl);
setModelName(value.model);
setModelApiKey(value.apiKey);
+ setModelFieldErrors({});
+ setError(undefined);
setNotice(undefined);
}}
providerId={modelProviderId}
@@ -340,6 +368,8 @@ export function CreatorServicesSettingsView(props: {
setModelBaseUrl(preset.defaultBaseUrl ?? '');
setModelName(preset.models[0]?.id ?? '');
setModelApiKey('');
+ setModelFieldErrors({});
+ setError(undefined);
setNotice(undefined);
}}
/>
@@ -388,7 +418,7 @@ export function CreatorServicesSettingsView(props: {
saving
|| (
activeSection === 'text'
- && (modelProvider === undefined || modelName.trim().length === 0)
+ && modelProvider === undefined
)
}
>
@@ -412,6 +442,7 @@ function TextModelSettings(props: SettingsGroupProps & {
model: string;
apiKey: string;
error?: string;
+ fieldErrors: ModelFieldErrors;
onProviderChange(value: OpenAiCompatibleConfig): void;
providerId: string;
runtimeModelIds: readonly string[];
@@ -461,6 +492,7 @@ function TextModelSettings(props: SettingsGroupProps & {
modelSuggestions={props.providerId === 'openai' && props.runtimeModelIds.length > 0
? props.runtimeModelIds
: creatorProviderCatalogById.llm[props.providerId]?.models.map(model => model.id)}
+ errors={props.fieldErrors}
onChange={props.onProviderChange}
/>
<div className="creator-services-model-status is-wide" role="status">
@@ -500,6 +532,7 @@ function TextModelSettings(props: SettingsGroupProps & {
label={l('代理地址', 'Proxy URL')}
value={props.config.proxy}
placeholder="http://127.0.0.1:7890"
+ error={props.fieldErrors.proxy}
onChange={value => props.update(config => {
config.proxy = value;
})}
@@ -519,6 +552,61 @@ function inferLlmProviderId(baseUrl: string, model: string): string {
return 'custom';
}
+function validateModelFields(
+ baseUrl: string,
+ model: string,
+ apiKey: string,
+ proxy: string,
+ l: (zh: string, en: string) => string
+): ModelFieldErrors {
+ const errors: ModelFieldErrors = {};
+ if (model.trim().length === 0) {
+ errors.model = l('模型不能为空', 'Model is required');
+ }
+ if (baseUrl.trim().length > 0 && !isHttpUrl(baseUrl)) {
+ errors.baseUrl = l(
+ '请输入有效的 HTTP 或 HTTPS 地址',
+ 'Enter a valid HTTP or HTTPS URL'
+ );
+ }
+ if (apiKey.length > 0 && apiKey.trim().length === 0) {
+ errors.apiKey = l('API Key 不能只包含空格', 'API Key cannot contain only spaces');
+ }
+ if (proxy.trim().length > 0 && !isHttpUrl(proxy)) {
+ errors.proxy = l(
+ '请输入有效的 HTTP 或 HTTPS 代理地址',
+ 'Enter a valid HTTP or HTTPS proxy URL'
+ );
+ }
+ return errors;
+}
+
+function isHttpUrl(value: string): boolean {
+ try {
+ const url = new URL(value.trim());
+ return url.protocol === 'http:' || url.protocol === 'https:';
+ } catch {
+ return false;
+ }
+}
+
+function readableSaveError(
+ cause: unknown,
+ l: (zh: string, en: string) => string
+): string {
+ if (cause instanceof Error && cause.message.trim().length > 0) return cause.message;
+ return l('本地 Runtime 未返回具体原因', 'The local Runtime did not return a reason');
+}
+
+function modelFieldFromError(message: string): keyof ModelFieldErrors | undefined {
+ const normalized = message.toLowerCase();
+ if (normalized.includes('base url') || normalized.includes('baseurl')) return 'baseUrl';
+ if (normalized.includes('api key') || normalized.includes('apikey')) return 'apiKey';
+ if (normalized.includes('proxy') || normalized.includes('代理')) return 'proxy';
+ if (normalized.includes('model') || normalized.includes('模型')) return 'model';
+ return undefined;
+}
+
function TranscriptionSettings(props: SettingsGroupProps & {
capabilities: CreatorServicesCapabilitiesResponse;
}) {
@@ -912,6 +1000,7 @@ function OpenAiFields(props: {
modelSuggestions?: readonly string[];
modelReadonly?: boolean;
baseUrlPlaceholder?: string;
+ errors?: ModelFieldErrors;
onChange(value: OpenAiCompatibleConfig): void;
}) {
const l = useLocalizedCopy();
@@ -922,6 +1011,7 @@ function OpenAiFields(props: {
label={l('Base URL', 'Base URL')}
value={props.value.baseUrl}
placeholder={props.baseUrlPlaceholder ?? 'https://api.openai.com/v1'}
+ error={props.errors?.baseUrl}
onChange={baseUrl => props.onChange({ ...props.value, baseUrl })}
wide
/>
@@ -930,6 +1020,7 @@ function OpenAiFields(props: {
label="API Key"
value={props.value.apiKey}
configured={props.configuredCredentials.has(props.credential)}
+ error={props.errors?.apiKey}
onChange={apiKey => props.onChange({ ...props.value, apiKey })}
/>
{props.modelReadonly ? (
@@ -941,6 +1032,7 @@ function OpenAiFields(props: {
value={props.value.model}
placeholder={props.modelPlaceholder}
suggestions={props.modelSuggestions}
+ error={props.errors?.model}
onChange={model => props.onChange({ ...props.value, model })}
/>
)}
@@ -1035,6 +1127,7 @@ function TextField(props: {
placeholder?: string;
suggestions?: readonly string[];
wide?: boolean;
+ error?: string;
onChange(value: string): void;
}) {
return (
@@ -1042,14 +1135,20 @@ function TextField(props: {
<span>{props.label}</span>
<input
id={props.id}
+ aria-label={props.label}
type="text"
value={props.value}
placeholder={props.placeholder}
list={props.suggestions?.length ? `${props.id}-suggestions` : undefined}
spellCheck={false}
autoComplete="off"
+ aria-invalid={props.error === undefined ? undefined : true}
+ aria-describedby={props.error === undefined ? undefined : `${props.id}-error`}
onChange={event => props.onChange(event.target.value)}
/>
+ {props.error === undefined ? null : (
+ <span id={`${props.id}-error`} className="creator-services-field-error">{props.error}</span>
+ )}
{props.suggestions?.length ? (
<datalist id={`${props.id}-suggestions`}>
{props.suggestions.map(value => <option key={value} value={value} />)}
@@ -1065,6 +1164,7 @@ function ModelField(props: {
value: string;
placeholder?: string;
suggestions?: readonly string[];
+ error?: string;
onChange(value: string): void;
}) {
const valueIsCustom = props.suggestions?.includes(props.value) !== true;
@@ -1081,6 +1181,8 @@ function ModelField(props: {
<select
aria-label={props.label}
value={showCustomInput ? '__custom__' : props.value}
+ aria-invalid={props.error === undefined ? undefined : true}
+ aria-describedby={props.error === undefined ? undefined : `${props.id}-error`}
onChange={event => {
if (event.target.value === '__custom__') {
setCustomSelected(true);
@@ -1097,14 +1199,20 @@ function ModelField(props: {
{(!props.suggestions?.length || showCustomInput) ? (
<input
id={props.id}
+ aria-label={props.label}
type="text"
value={props.value}
placeholder={props.placeholder}
spellCheck={false}
autoComplete="off"
+ aria-invalid={props.error === undefined ? undefined : true}
+ aria-describedby={props.error === undefined ? undefined : `${props.id}-error`}
onChange={event => props.onChange(event.target.value)}
/>
) : null}
+ {props.error === undefined ? null : (
+ <span id={`${props.id}-error`} className="creator-services-field-error">{props.error}</span>
+ )}
</label>
);
}
@@ -1114,6 +1222,7 @@ function PasswordField(props: {
label: string;
value: string;
configured?: boolean;
+ error?: string;
onChange(value: string): void;
}) {
const l = useLocalizedCopy();
@@ -1124,6 +1233,7 @@ function PasswordField(props: {
<span className="creator-services-secret-input">
<input
id={props.id}
+ aria-label={props.label}
type={visible ? 'text' : 'password'}
value={props.value}
placeholder={props.configured
@@ -1131,6 +1241,8 @@ function PasswordField(props: {
: l('输入密钥', 'Enter key')}
spellCheck={false}
autoComplete="new-password"
+ aria-invalid={props.error === undefined ? undefined : true}
+ aria-describedby={props.error === undefined ? undefined : `${props.id}-error`}
onChange={event => props.onChange(event.target.value)}
/>
<button
@@ -1142,6 +1254,9 @@ function PasswordField(props: {
{visible ? <EyeOff size={16} aria-hidden="true" /> : <Eye size={16} aria-hidden="true" />}
</button>
</span>
+ {props.error === undefined ? null : (
+ <span id={`${props.id}-error`} className="creator-services-field-error">{props.error}</span>
+ )}
</label>
);
}
diff --git a/apps/web/src/features/settings/creator-services-settings.css b/apps/web/src/features/settings/creator-services-settings.css
index 89d4a48d..728a3ac8 100644
--- a/apps/web/src/features/settings/creator-services-settings.css
+++ b/apps/web/src/features/settings/creator-services-settings.css
@@ -241,6 +241,17 @@
outline-offset: 2px;
}
+.creator-services-field [aria-invalid='true'] {
+ border-color: var(--danger);
+}
+
+.creator-services-field-error {
+ color: var(--danger);
+ font-size: 12px;
+ font-weight: 500;
+ line-height: 1.4;
+}
+
.creator-services-select {
position: relative;
}