From 06bf7ce024054e355eb9475fa0b24626f7511a8a Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Tue, 3 Nov 2026 12:33:44 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(settings):=20show=20saved=20API?= =?UTF-8?q?=20keys=20and=20preserve=20environment=20detection=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9bb49604b63bb5d50e879bcf63c9f5cb2afbd737. --- apps/web/tests/credential-editor.e2e.ts | 235 ------------------ .../detected-environment.expected.md | 25 -- .../missing-environment.expected.md | 23 -- .../credential-editor/saved-key.expected.md | 26 -- .../cards.expected.md | 4 +- .../default-models.expected.md | 4 +- .../models.expected.md | 4 +- .../fixtures/credential-editor.patch.yml | 5 - apps/web/tests/models-settings.e2e.ts | 9 +- .../tests/onboarding-deepseek-config.e2e.ts | 17 +- apps/web/tsconfig.json | 1 - docs/capability-seams.i18n.yaml | 4 +- docs/capability-seams.md | 2 +- docs/capability-seams.zh.md | 2 +- docs/subsystems/credentials.i18n.yaml | 4 +- docs/subsystems/credentials.md | 22 +- docs/subsystems/credentials.zh.md | 22 +- .../credential-editor/guide.i18n.yaml | 16 -- .../v0.2.2-alpha.2/credential-editor/guide.md | 19 -- .../credential-editor/guide.zh.md | 19 -- docs/user/guide/providers.i18n.yaml | 8 +- docs/user/guide/providers.md | 8 +- docs/user/guide/providers.zh.md | 8 +- .../api/settings-controller/README.i18n.yaml | 8 +- packages/api/settings-controller/README.md | 4 +- packages/api/settings-controller/README.zh.md | 4 +- .../settings-controller/src/credentials.ts | 24 +- packages/api/settings-controller/src/types.ts | 6 +- .../tests/credentials-controller.host.spec.ts | 40 --- .../ui-settings-models/README.i18n.yaml | 12 +- packages/client/ui-settings-models/README.md | 10 +- .../client/ui-settings-models/README.zh.md | 10 +- .../src/client/ApiKeyInput.tsx | 4 +- .../src/client/ModelListEditor.tsx | 2 +- .../src/client/ModelsSection.tsx | 49 +--- .../src/client/ProviderEditor.tsx | 36 ++- .../ui-settings-models/src/client/apiKey.ts | 9 +- .../ui-settings-models/src/client/locales.ts | 8 + .../src/client/operations.ts | 15 -- .../tests/components.client.spec.tsx | 178 +------------ .../tests/model-list-catalog.client.spec.tsx | 2 +- .../tests/model-order.client.spec.tsx | 4 +- .../model-reasoning-efforts.client.spec.tsx | 2 +- .../tests/provider-form.client.spec.tsx | 1 - .../credentials/authorization/tests/memory.ts | 4 - .../credentials-local/README.i18n.yaml | 4 +- .../credentials/credentials-local/README.md | 2 +- .../credentials-local/README.zh.md | 2 +- .../credentials-local/src/index.ts | 4 - .../credentials-local/tests/local.spec.ts | 12 - .../credentials/credentials/README.i18n.yaml | 12 +- packages/credentials/credentials/README.md | 6 +- packages/credentials/credentials/README.zh.md | 6 +- packages/credentials/credentials/src/index.ts | 7 - .../credentials/credentials/tests/memory.ts | 5 - .../liveshare/src/endpoint-classification.ts | 1 - .../endpoint-classification.client.spec.ts | 1 - .../extensions/tool-cordis/src/api-catalog.ts | 17 +- scripts/gen-doc-graphs.ts | 2 +- tsconfig.host.json | 1 - 60 files changed, 148 insertions(+), 853 deletions(-) delete mode 100644 apps/web/tests/credential-editor.e2e.ts delete mode 100644 apps/web/tests/expected/credential-editor/detected-environment.expected.md delete mode 100644 apps/web/tests/expected/credential-editor/missing-environment.expected.md delete mode 100644 apps/web/tests/expected/credential-editor/saved-key.expected.md delete mode 100644 apps/web/tests/fixtures/credential-editor.patch.yml delete mode 100644 docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.i18n.yaml delete mode 100644 docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.md delete mode 100644 docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.zh.md diff --git a/apps/web/tests/credential-editor.e2e.ts b/apps/web/tests/credential-editor.e2e.ts deleted file mode 100644 index b9ee283aa4..0000000000 --- a/apps/web/tests/credential-editor.e2e.ts +++ /dev/null @@ -1,235 +0,0 @@ -/** Saved credentials and endpoints reach the assembled editor and provider requests. */ -import { once } from 'node:events' -import { mkdtemp, rm, writeFile } from 'node:fs/promises' -import { createServer } from 'node:http' -import { tmpdir } from 'node:os' -import { join } from 'node:path' -import { fileURLToPath } from 'node:url' -import { chromium } from 'playwright' -import { expect, it, onTestFinished } from 'vitest' -import { BlockAssembler } from '@deepseek-ai/dsh-llm' -import { credentialRef } from '@deepseek-ai/dsh-credentials' -import { createLaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment' -import { captureStableAria, compareOrRefreshGolden, launchWebScaffold, webSnapshotMode } from './scaffold.ts' -import { openSettings, ZH_BROWSER_LOCALE } from './support.ts' - -it.each([false, true])('edits saved DeepSeek keys and restores environment detection (environment present: %s)', async (hasEnvironment) => { - const scaffold = await launchWebScaffold({ - deepSeekMissingCredential: true, - extraOverlayPath: fileURLToPath(new URL('./fixtures/credential-editor.patch.yml', import.meta.url)), - openInAppEnvironment: createLaunchEnvironmentSnapshot([{ - source: 'process', values: hasEnvironment ? { DEEPSEEK_API_KEY: 'fixture-environment-key' } : {}, - }]), - }) - try { - const browser = await chromium.launch() - try { - const page = await browser.newPage({ viewport: { width: 1440, height: 960 }, locale: ZH_BROWSER_LOCALE }) - const ref = credentialRef('DEEPSEEK_API_KEY') - await scaffold.ctx.credentials.set(ref, 'fixture-saved-deepseek-key') - await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) - await openSettings(page, 'zh') - const dialog = page.getByRole('dialog', { name: '设置' }) - await dialog.getByRole('button', { name: '模型', exact: true }).click() - const edit = dialog.getByRole('button', { name: '编辑 DeepSeek (deepseek-official)', exact: true }) - await edit.click() - const key = dialog.getByLabel('API 密钥', { exact: true }) - await expect.poll(() => key.inputValue()).toBe('fixture-saved-deepseek-key') - expect(await key.getAttribute('type')).toBe('password') - await compareOrRefreshGolden( - fileURLToPath(new URL('./expected/credential-editor/saved-key.expected.md', import.meta.url)), - await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd), webSnapshotMode(), - ) - await dialog.getByRole('button', { name: '显示密钥', exact: true }).click() - expect(await key.getAttribute('type')).toBe('text') - await key.fill('fixture-cancelled-key') - await dialog.getByRole('button', { name: '取消', exact: true }).click() - expect(await scaffold.ctx.credentials.readStored(ref)).toBe('fixture-saved-deepseek-key') - await edit.click() - await expect.poll(() => key.inputValue()).toBe('fixture-saved-deepseek-key') - expect(await key.getAttribute('type')).toBe('password') - await key.fill('fixture-replacement-key') - await dialog.getByRole('button', { name: '保存', exact: true }).click() - await dialog.getByText('已保存 DeepSeek (deepseek-official)。', { exact: true }).waitFor() - expect(await scaffold.ctx.credentials.readStored(ref)).toBe('fixture-replacement-key') - await page.reload({ waitUntil: 'load' }) - await openSettings(page, 'zh') - await dialog.getByRole('button', { name: '模型', exact: true }).click() - await edit.click() - await expect.poll(() => key.inputValue()).toBe('fixture-replacement-key') - await key.fill('') - expect(await key.getAttribute('placeholder')).toBe('留空使用环境认证(DEEPSEEK_API_KEY)') - await dialog.getByText('环境凭据状态尚未确认', { exact: true }).waitFor() - expect(await scaffold.ctx.credentials.readStored(ref)).toBe('fixture-replacement-key') - await dialog.getByRole('button', { name: '保存', exact: true }).click() - await dialog.getByText('已保存 DeepSeek (deepseek-official)。', { exact: true }).waitFor() - expect(await scaffold.ctx.credentials.readStored(ref)).toBeUndefined() - // A missing credential opens the first-run settings card automatically; - // an environment credential keeps an ordinary row whose editor is closed. - if (hasEnvironment) await edit.click() - await expect.poll(() => key.inputValue()).toBe('') - expect(await key.getAttribute('placeholder')).toBe('留空使用环境认证(DEEPSEEK_API_KEY)') - const hint = hasEnvironment - ? '已检测到环境变量(DEEPSEEK_API_KEY)' - : '未检测到环境变量。请填写 API 密钥,或设置环境变量 DEEPSEEK_API_KEY。' - const detection = dialog.getByText(hint, { exact: true }) - await detection.waitFor() - const colors = await detection.evaluate((element, present) => { - const label = element as HTMLElement - const actual = getComputedStyle(label).color - const previous = label.style.color - label.style.color = present ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-warn-label)' - const expected = getComputedStyle(label).color - label.style.color = previous - return { actual, expected } - }, hasEnvironment) - expect(colors.actual).toBe(colors.expected) - expect(await dialog.getByRole('button', { name: '显示密钥', exact: true }).count()).toBe(0) - expect((await scaffold.ctx.credentials.resolve(ref))?.source).toBe(hasEnvironment ? 'env' : undefined) - await compareOrRefreshGolden( - fileURLToPath(new URL(`./expected/credential-editor/${hasEnvironment ? 'detected' : 'missing'}-environment.expected.md`, import.meta.url)), - await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd), webSnapshotMode(), - ) - } finally { await browser.close() } - } finally { await scaffold.close() } -}) - -/** Local provider endpoint recording the destination path and authentication actually received. */ -async function connectionProbe(messages: boolean) { - const calls: { path: string; key: string | undefined }[] = [] - const server = createServer((request, response) => { - request.on('end', () => { - const key = messages ? request.headers['x-api-key'] : request.headers.authorization - calls.push({ path: request.url ?? '', key: typeof key === 'string' ? key : undefined }) - const events = messages ? [ - { type: 'message_start', message: { id: 'probe', type: 'message', role: 'assistant', model: 'credential-editor-model', content: [], usage: { input_tokens: 1, output_tokens: 0 } } }, - { type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } }, - { type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: 'connection-ok' } }, - { type: 'content_block_stop', index: 0 }, - { type: 'message_delta', delta: { stop_reason: 'end_turn' }, usage: { output_tokens: 1 } }, - { type: 'message_stop' }, - ] : [ - { choices: [{ delta: { role: 'assistant', content: 'connection-ok' }, index: 0, finish_reason: null }] }, - { choices: [{ delta: {}, index: 0, finish_reason: 'stop' }], usage: { prompt_tokens: 1, completion_tokens: 1 } }, - ] - response.writeHead(200, { 'content-type': 'text/event-stream' }) - response.end(events.map(event => `${'type' in event ? `event: ${event.type}\n` : ''}data: ${JSON.stringify(event)}\n\n`).join('') - + (messages ? '' : 'data: [DONE]\n\n')) - }) - request.resume() - }) - onTestFinished(async () => { - await new Promise((resolve) => { server.close(() => { resolve() }); server.closeAllConnections() }) - }) - server.listen(0, '127.0.0.1') - await once(server, 'listening') - const address = server.address() - if (address === null || typeof address === 'string') throw new Error('connection probe did not bind TCP') - return { url: `http://127.0.0.1:${String(address.port)}`, calls } -} - -it.each([ - { provider: 'deepseek-official', ref: 'DEEPSEEK_API_KEY', messages: true }, - { provider: 'openai', ref: 'OPENAI_API_KEY', messages: false }, - { provider: 'anthropic', ref: 'ANTHROPIC_API_KEY', messages: true }, - { provider: 'credential-fixture', ref: 'CREDENTIAL_FIXTURE_API_KEY', messages: false }, -])('uses the saved endpoint and key on the wire for $provider, then restores fallbacks', async ({ provider, ref, messages }) => { - const ambient = await connectionProbe(messages) - const saved = await connectionProbe(messages) - const root = await mkdtemp(join(tmpdir(), 'dsh-credential-routing-')) - onTestFinished(() => rm(root, { recursive: true, force: true })) - const overlay = join(root, 'connection.patch.yml') - const models = [{ id: 'credential-editor-model' }] - const baseSuffix = provider === 'anthropic' ? '' : '/v1' - const operation = provider === 'anthropic' ? '/v1/messages?beta=true' : messages ? '/messages' : '/chat/completions' - const ambientURL = `${ambient.url}/ambient${baseSuffix}` - await writeFile(overlay, JSON.stringify([ - { id: 'llm-deepseek', config: { models } }, - ...provider === 'deepseek-official' ? [] : [{ - id: 'llm-pi-ai', config: { providers: { [provider]: { - api: messages ? 'anthropic-messages' : 'openai-completions', - baseURL: ambientURL, models, - ...provider === 'credential-fixture' ? {} : { apiKeyEnv: ref }, - } } }, - }], - ])) - const scaffold = await launchWebScaffold({ - deepSeekMissingCredential: true, - extraOverlayPath: overlay, - openInAppEnvironment: createLaunchEnvironmentSnapshot([{ - source: 'process', values: { - [ref]: 'fixture-environment-key', - DEEPSEEK_BASE_URL: ambientURL, - OPENAI_BASE_URL: ambientURL, - ANTHROPIC_BASE_URL: ambientURL, - }, - }]), - }) - try { - const browser = await chromium.launch() - try { - const page = await browser.newPage({ locale: ZH_BROWSER_LOCALE }) - await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) - await openSettings(page, 'zh') - const dialog = page.getByRole('dialog', { name: '设置' }) - await dialog.getByRole('button', { name: '模型', exact: true }).click() - const edit = dialog.getByRole('button', { - name: `编辑 ${provider === 'deepseek-official' ? 'DeepSeek (deepseek-official)' : provider}`, exact: true, - }) - const key = dialog.getByLabel('API 密钥', { exact: true }) - const endpoint = dialog.getByLabel('API 地址', { exact: true }) - const savedURL = `${saved.url}/configured${baseSuffix}` - const generate = async (): Promise => { - const assembler = new BlockAssembler() - for await (const chunk of scaffold.ctx.llm.stream({ provider, model: 'credential-editor-model', messages: [] })) assembler.push(chunk) - expect(assembler.message({ provider, model: 'credential-editor-model' }).content).toContainEqual({ type: 'text', text: 'connection-ok' }) - } - await edit.click() - await key.fill('fixture-saved-key') - await dialog.getByText('自定义设置', { exact: true }).click() - await endpoint.fill(savedURL) - await dialog.getByRole('button', { name: '保存', exact: true }).click() - await expect.poll(() => key.count()).toBe(0) - await generate() - expect(saved.calls).toEqual([{ path: `/configured${baseSuffix}${operation}`, key: messages ? 'fixture-saved-key' : 'Bearer fixture-saved-key' }]) - expect(ambient.calls).toEqual([]) - await page.reload({ waitUntil: 'load' }) - await openSettings(page, 'zh') - await dialog.getByRole('button', { name: '模型', exact: true }).click() - await edit.click() - expect(await key.inputValue()).toBe('fixture-saved-key') - expect(await key.getAttribute('type')).toBe('password') - await dialog.getByText('自定义设置', { exact: true }).click() - expect(await endpoint.inputValue()).toBe(savedURL) - await generate() - expect(saved.calls).toHaveLength(2) - expect(saved.calls[1]).toEqual(saved.calls[0]) - expect(ambient.calls).toEqual([]) - await key.fill('') - await dialog.getByRole('button', { name: '保存', exact: true }).click() - await expect.poll(() => key.count()).toBe(0) - await generate() - expect(saved.calls).toHaveLength(3) - expect(saved.calls[2]).toEqual({ path: `/configured${baseSuffix}${operation}`, key: messages ? 'fixture-environment-key' : 'Bearer fixture-environment-key' }) - expect(ambient.calls).toEqual([]) - await edit.click() - await key.fill('fixture-saved-key') - await dialog.getByText('自定义设置', { exact: true }).click() - await endpoint.fill('') - await dialog.getByRole('button', { name: '保存', exact: true }).click() - await expect.poll(() => key.count()).toBe(0) - await generate() - expect(saved.calls).toHaveLength(3) - expect(ambient.calls).toEqual([{ path: `/ambient${baseSuffix}${operation}`, key: messages ? 'fixture-saved-key' : 'Bearer fixture-saved-key' }]) - await edit.click() - await key.fill('') - await dialog.getByRole('button', { name: '保存', exact: true }).click() - await expect.poll(() => key.count()).toBe(0) - await generate() - expect(saved.calls).toHaveLength(3) - expect(ambient.calls[1]).toEqual({ path: `/ambient${baseSuffix}${operation}`, key: messages ? 'fixture-environment-key' : 'Bearer fixture-environment-key' }) - expect(ambient.calls).toHaveLength(2) - expect(await scaffold.ctx.credentials.readStored(credentialRef(ref))).toBeUndefined() - } finally { await browser.close() } - } finally { await scaffold.close() } -}) diff --git a/apps/web/tests/expected/credential-editor/detected-environment.expected.md b/apps/web/tests/expected/credential-editor/detected-environment.expected.md deleted file mode 100644 index 829eeedd37..0000000000 --- a/apps/web/tests/expected/credential-editor/detected-environment.expected.md +++ /dev/null @@ -1,25 +0,0 @@ -- dialog "设置": - - text: 设置 - - navigation: - - button "通用设置" - - button "模型" - - button "内置插件" - - button "Agent 预设" - - button "打开配置文件" - - button "关闭" - - heading "模型" [level=2] - - paragraph: 填入各提供商的 API 密钥即可使用其模型。 - - list: - - listitem: - - text: DeepSeek - - img "API 密钥已配置" - - button "编辑 DeepSeek (deepseek-official)": 编辑 - - text: DeepSeek deepseek-official API 密钥 - - button "认证说明": "?" - - textbox "API 密钥": - - /placeholder: 留空使用环境认证(DEEPSEEK_API_KEY) - - paragraph: 已检测到环境变量(DEEPSEEK_API_KEY) - - group: 自定义设置 - - button "取消" - - button "保存" - - button "添加模型提供商" diff --git a/apps/web/tests/expected/credential-editor/missing-environment.expected.md b/apps/web/tests/expected/credential-editor/missing-environment.expected.md deleted file mode 100644 index 609ac50d0e..0000000000 --- a/apps/web/tests/expected/credential-editor/missing-environment.expected.md +++ /dev/null @@ -1,23 +0,0 @@ -- dialog "设置": - - text: 设置 - - navigation: - - button "通用设置" - - button "模型" - - button "内置插件" - - button "Agent 预设" - - button "打开配置文件" - - button "关闭" - - heading "模型" [level=2] - - paragraph: 填入各提供商的 API 密钥即可使用其模型。 - - status: 已保存 DeepSeek (deepseek-official)。 - - list: - - listitem: - - text: DeepSeek deepseek-official API 密钥 - - button "认证说明": "?" - - textbox "API 密钥": - - /placeholder: 留空使用环境认证(DEEPSEEK_API_KEY) - - paragraph: 未检测到环境变量。请填写 API 密钥,或设置环境变量 DEEPSEEK_API_KEY。 - - group: 自定义设置 - - button "取消" - - button "保存" - - button "添加模型提供商" diff --git a/apps/web/tests/expected/credential-editor/saved-key.expected.md b/apps/web/tests/expected/credential-editor/saved-key.expected.md deleted file mode 100644 index 2d4dde4639..0000000000 --- a/apps/web/tests/expected/credential-editor/saved-key.expected.md +++ /dev/null @@ -1,26 +0,0 @@ -- dialog "设置": - - text: 设置 - - navigation: - - button "通用设置" - - button "模型" - - button "内置插件" - - button "Agent 预设" - - button "打开配置文件" - - button "关闭" - - heading "模型" [level=2] - - paragraph: 填入各提供商的 API 密钥即可使用其模型。 - - list: - - listitem: - - text: DeepSeek - - img "API 密钥已配置" - - button "编辑 DeepSeek (deepseek-official)": 编辑 - - text: DeepSeek deepseek-official API 密钥 - - button "认证说明": "?" - - textbox "API 密钥": - - /placeholder: 留空使用环境认证(DEEPSEEK_API_KEY) - - text: fixture-saved-deepseek-key - - button "显示密钥" - - group: 自定义设置 - - button "取消" - - button "保存" - - button "添加模型提供商" diff --git a/apps/web/tests/expected/deepseek-messages-settings/cards.expected.md b/apps/web/tests/expected/deepseek-messages-settings/cards.expected.md index d4fa1c31fb..08a0750772 100644 --- a/apps/web/tests/expected/deepseek-messages-settings/cards.expected.md +++ b/apps/web/tests/expected/deepseek-messages-settings/cards.expected.md @@ -17,9 +17,7 @@ - text: DeepSeek deepseek-official API 密钥 - button "认证说明": "?" - textbox "API 密钥": - - /placeholder: 留空使用环境认证(DEEPSEEK_API_KEY) - - text: sk-messages-onboarding - - button "显示密钥" + - /placeholder: 留空使用已保存凭据 - group: - text: 自定义设置 API 地址 - textbox "API 地址": diff --git a/apps/web/tests/expected/onboarding-deepseek-config/default-models.expected.md b/apps/web/tests/expected/onboarding-deepseek-config/default-models.expected.md index 018ea8a13c..03900f109b 100644 --- a/apps/web/tests/expected/onboarding-deepseek-config/default-models.expected.md +++ b/apps/web/tests/expected/onboarding-deepseek-config/default-models.expected.md @@ -17,9 +17,7 @@ - text: DeepSeek deepseek-official API 密钥 - button "认证说明": "?" - textbox "API 密钥": - - /placeholder: 留空使用环境认证(DEEPSEEK_API_KEY) - - text: dsh_onboarding_fixture_key - - button "显示密钥" + - /placeholder: 留空使用已保存凭据 - group: - text: 自定义设置 API 地址 - textbox "API 地址": diff --git a/apps/web/tests/expected/onboarding-deepseek-config/models.expected.md b/apps/web/tests/expected/onboarding-deepseek-config/models.expected.md index a5811b5d66..27ba737236 100644 --- a/apps/web/tests/expected/onboarding-deepseek-config/models.expected.md +++ b/apps/web/tests/expected/onboarding-deepseek-config/models.expected.md @@ -17,9 +17,7 @@ - text: DeepSeek deepseek-official API 密钥 - button "认证说明": "?" - textbox "API 密钥": - - /placeholder: 留空使用环境认证(DEEPSEEK_API_KEY) - - text: dsh_onboarding_fixture_key - - button "显示密钥" + - /placeholder: 留空使用已保存凭据 - group: - text: 自定义设置 API 地址 - textbox "API 地址": diff --git a/apps/web/tests/fixtures/credential-editor.patch.yml b/apps/web/tests/fixtures/credential-editor.patch.yml deleted file mode 100644 index 911f60db22..0000000000 --- a/apps/web/tests/fixtures/credential-editor.patch.yml +++ /dev/null @@ -1,5 +0,0 @@ -- id: llm-deepseek - config: - baseURL: http://127.0.0.1 - models: - - id: credential-editor-model diff --git a/apps/web/tests/models-settings.e2e.ts b/apps/web/tests/models-settings.e2e.ts index 1b5a5dcbed..d36008959d 100644 --- a/apps/web/tests/models-settings.e2e.ts +++ b/apps/web/tests/models-settings.e2e.ts @@ -2,7 +2,7 @@ // wire — the one add card offers the dormant pi-ai catalog on its third-party // mode and the create form on its custom-API mode, a blank key saves a // reference-free profile for provider-native auth, and typing an API key later -// stores it under the derived reference (`MINIMAX_CN_API_KEY`) +// stores it write-only under the derived reference (`MINIMAX_CN_API_KEY`) // while the settings document records only that reference. Each saved row // appears after route topology invalidation without presenting liveness as // provider status. The customized-settings fold writes its curated fields — @@ -154,7 +154,8 @@ describe('web e2e: Models settings page configures a dormant provider', () => { await dialog.getByText('该 API 密钥格式错误,请检查。').waitFor({ timeout: 10_000 }) await expect.poll(async () => save.isEnabled(), { timeout: 10_000 }).toBe(false) - // An empty field leaves this new profile on native authentication. + // Clearing it restores submit: an empty field means "keep what is stored", + // never a refusal, or editing any other setting would demand the key. await key.fill('') await expect.poll(async () => save.isEnabled(), { timeout: 10_000 }).toBe(true) expect(await dialog.getByText('该 API 密钥格式错误,请检查。').count()).toBe(0) @@ -220,9 +221,7 @@ describe('web e2e: Models settings page configures a dormant provider', () => { onTestFailed(() => saveFailureShot(page, 'web-e2e-models-customized')) const dialog = page.getByRole('dialog', { name: '设置' }) await dialog.getByRole('button', { name: '编辑 minimax-cn' }).click() - const savedKey = dialog.getByLabel('API 密钥', { exact: true }) - await expect.poll(() => savedKey.inputValue(), { timeout: 10_000 }).toBe('sk-e2e-minimax') - expect(await savedKey.getAttribute('type')).toBe('password') + await dialog.getByPlaceholder('留空使用已保存凭据', { exact: true }).waitFor({ timeout: 10_000 }) expect(await dialog.textContent()).not.toContain('API 密钥来源:') expect(await dialog.textContent()).not.toMatch(/oauth/i) await dialog.getByText('自定义设置').click() diff --git a/apps/web/tests/onboarding-deepseek-config.e2e.ts b/apps/web/tests/onboarding-deepseek-config.e2e.ts index 06e451032d..8706a7a4de 100644 --- a/apps/web/tests/onboarding-deepseek-config.e2e.ts +++ b/apps/web/tests/onboarding-deepseek-config.e2e.ts @@ -2,6 +2,7 @@ // credential is absent, both ordered steps share the shipped modal chrome, // and the inline key write lands in an isolated harness home without a reload // or model call. +import { randomBytes } from 'node:crypto' import { assertModelInputLayout } from './model-input-layout.ts' import { readFile } from 'node:fs/promises' import { fileURLToPath } from 'node:url' @@ -32,7 +33,6 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup let page: Page let tripwire: ReturnType const browserConsole: string[] = [] - const secret = 'dsh_onboarding_fixture_key' beforeAll(async () => { scaffold = await launchWebScaffold({ deepSeekMissingCredential: true, welcomeNoticePending: true }) @@ -50,7 +50,7 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup await scaffold?.close() }) - it('stores a key and loads it masked only in an explicitly opened editor', async () => { + it('stores a key write-only and observes configured state without restarting', async () => { onTestFailed(() => saveFailureShot(page, 'web-e2e-onboarding-deepseek-config')) const welcome = page.getByRole('dialog', { name: WELCOME_NOTICE_COPY.zh.title }) await welcome.waitFor({ timeout: 15_000 }) @@ -86,6 +86,7 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup const initial = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd) await compareOrRefreshGolden(MISSING_EXPECTED, initial, MODE) + const secret = `dsh_onboarding_${randomBytes(12).toString('hex')}` await keyInput.fill(secret) await credentialStep.getByRole('button', { name: '保存并继续' }).click() await credentialStep.waitFor({ state: 'detached', timeout: 15_000 }) @@ -100,7 +101,8 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup const acknowledgedSettings = await readFile(join(scaffold.harnessHome, 'profiles', 'scaffold', 'cordis.patch.yml'), 'utf8') expect(acknowledgedSettings).toContain(`${WELCOME_NOTICE_ACK_FIELD}: ${WELCOME_NOTICE_VERSION}`) - // Opening the ordinary Models editor loads the saved key masked. + // The ordinary Models surface reuses the refreshed join and exposes the + // configured write-only placeholder without a reload. await openSettings(page, 'zh') const settings = page.getByRole('dialog', { name: '设置' }) await settings.waitFor({ timeout: 10_000 }) @@ -111,10 +113,9 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup const configuredInput = settings.getByLabel('API 密钥', { exact: true }) await configuredInput.waitFor({ timeout: 10_000 }) await expect.poll( - () => configuredInput.inputValue(), + () => configuredInput.getAttribute('placeholder'), { timeout: 10_000 }, - ).toBe(secret) - expect(await configuredInput.getAttribute('type')).toBe('password') + ).toBe('留空使用已保存凭据') const secondReloadWarnings = tripwire.warnings.length await page.reload({ waitUntil: 'load' }) @@ -254,9 +255,9 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup await settings.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).check() await expect.poll( - () => settings.getByLabel('API 密钥', { exact: true }).inputValue(), + () => settings.getByLabel('API 密钥', { exact: true }).getAttribute('placeholder'), { timeout: 10_000 }, - ).toBe(secret) + ).toBe('留空使用已保存凭据') const modelEditor = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd) await compareOrRefreshGolden(MODELS_EXPECTED, modelEditor, MODE) await settings.getByRole('button', { name: '保存', exact: true }).click() diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 938c0dae3c..9b3977d4ee 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -23,7 +23,6 @@ // this client-registered project must not also hold them (one program // cannot see both sides of the cordis Context merges). "exclude": [ - "tests/credential-editor.e2e.ts", "tests/sidebar-drawer.e2e.ts", "tests/creation-recommendations.e2e.ts", "tests/plugin-recommendations.e2e.ts", diff --git a/docs/capability-seams.i18n.yaml b/docs/capability-seams.i18n.yaml index 4dc23c45e6..1083094774 100644 --- a/docs/capability-seams.i18n.yaml +++ b/docs/capability-seams.i18n.yaml @@ -6,5 +6,5 @@ en: 41d772192075e133 zh: 5ef3da69b4de1d8a /capability-seams-and-core-services: - en: 6215d15e0e273fa4 - zh: dec5c7779e0a42f5 + en: 3c972fccec17a890 + zh: 94c82847a3c8b83c diff --git a/docs/capability-seams.md b/docs/capability-seams.md index 334e3757bc..e333a79f71 100644 --- a/docs/capability-seams.md +++ b/docs/capability-seams.md @@ -698,7 +698,7 @@ flowchart LR | `ctx.configEditor` | `core` | [`config-editor`](../packages/boot/config-editor) | - | [`settings`](../packages/settings/settings), [`agent-default-model`](../packages/core/agent-default-model) | - | Persists profile config patches under the application file lock and HMR queue, then reconciles Loader entries. | | `ctx.settings` | `core` | [`settings`](../packages/settings/settings) | - | [`api-settings-controller`](../packages/api/settings-controller) | - | Forms project volatile Config fields from active profile entries and delegate validated edits to config-editor. Plugins consume their own Config references. | | `ctx.subagentModelSelection` | `core` | [`tool-subagent`](../packages/subagent/tool-subagent) | - | [`tool-subagent`](../packages/subagent/tool-subagent) | - | Owns the default-off settings namespace that Agent-scoped delegation tools sample when composing a new top-level Session. | -| `ctx.credentials` | `seam` | [`credentials`](../packages/credentials/credentials) | [`credentials-local`](../packages/credentials/credentials-local) | [`api-settings-controller`](../packages/api/settings-controller), [`llm-deepseek`](../packages/llm/llm-deepseek), [`llm-pi-ai`](../packages/llm/llm-pi-ai) | - | Configuration carries references to secrets; providers own the values. Consumers resolve per operation, so a rotated credential reaches the very next request; the settings controller exposes value-free metadata, writes, and owner-only reads of stored keys. | +| `ctx.credentials` | `seam` | [`credentials`](../packages/credentials/credentials) | [`credentials-local`](../packages/credentials/credentials-local) | [`api-settings-controller`](../packages/api/settings-controller), [`llm-deepseek`](../packages/llm/llm-deepseek), [`llm-pi-ai`](../packages/llm/llm-pi-ai) | - | Configuration carries references to secrets; providers own the values. Consumers resolve per operation, so a rotated credential reaches the very next request; the settings controller exposes value-free views and write-only storage. | | `ctx.deepseekAccount` | `seam` | [`deepseek-account`](../packages/credentials/deepseek-account) | [`deepseek-account-platform`](../packages/credentials/deepseek-account-platform) | [`api-account-controller`](../packages/api/account-controller), [`llm-deepseek`](../packages/llm/llm-deepseek) | - | The Host owns browser authorization and local credentials; UI consumers receive state without tokens. | | `ctx.authorization` | `seam` | [`authorization`](../packages/credentials/authorization) | - | [`llm-pi-ai`](../packages/llm/llm-pi-ai) | - | Flows are registered by the plugin that knows how to obtain one credential and keyed by the record they write; the seam owns the conversation and the one-attempt-per-key lifecycle, never the protocol. | | `ctx.productAnalytics` | `service` | [`client-product-analytics`](../packages/client/product-analytics) | - | - | - | Accepts selected Desktop events, enriches available login identity, and observes live compaction under the live Host collection policy. | diff --git a/docs/capability-seams.zh.md b/docs/capability-seams.zh.md index d0f0bdffb0..cf3f2e67fc 100644 --- a/docs/capability-seams.zh.md +++ b/docs/capability-seams.zh.md @@ -700,7 +700,7 @@ flowchart LR | `ctx.configEditor` | `core` | [`config-editor`](../packages/boot/config-editor) | - | [`settings`](../packages/settings/settings), [`agent-default-model`](../packages/core/agent-default-model) | - | Persists profile config patches under the application file lock and HMR queue, then reconciles Loader entries. | | `ctx.settings` | `core` | [`settings`](../packages/settings/settings) | - | [`api-settings-controller`](../packages/api/settings-controller) | - | Forms project volatile Config fields from active profile entries and delegate validated edits to config-editor. Plugins consume their own Config references. | | `ctx.subagentModelSelection` | `core` | [`tool-subagent`](../packages/subagent/tool-subagent) | - | [`tool-subagent`](../packages/subagent/tool-subagent) | - | 拥有默认关闭的设置命名空间;Agent 作用域的委派工具会在组合新顶层 Session 时读取它。 | -| `ctx.credentials` | `seam` | [`credentials`](../packages/credentials/credentials) | [`credentials-local`](../packages/credentials/credentials-local) | [`api-settings-controller`](../packages/api/settings-controller), [`llm-deepseek`](../packages/llm/llm-deepseek), [`llm-pi-ai`](../packages/llm/llm-pi-ai) | - | 配置携带对机密信息的引用;提供方拥有实际值。消费方按操作解析,因此轮换后的凭据会在紧接着的下一次请求中生效;settings controller 提供不含实际值的元数据和写入操作,并仅向所有者读取已保存密钥。 | +| `ctx.credentials` | `seam` | [`credentials`](../packages/credentials/credentials) | [`credentials-local`](../packages/credentials/credentials-local) | [`api-settings-controller`](../packages/api/settings-controller), [`llm-deepseek`](../packages/llm/llm-deepseek), [`llm-pi-ai`](../packages/llm/llm-pi-ai) | - | 配置携带对机密信息的引用;提供方拥有实际值。消费方按操作解析,因此轮换后的凭据会在紧接着的下一次请求中生效;settings controller 提供不含实际值的视图和只写存储。 | | `ctx.deepseekAccount` | `seam` | [`deepseek-account`](../packages/credentials/deepseek-account) | [`deepseek-account-platform`](../packages/credentials/deepseek-account-platform) | [`api-account-controller`](../packages/api/account-controller), [`llm-deepseek`](../packages/llm/llm-deepseek) | - | Host 负责浏览器授权和本地凭证;UI 使用方只接收不含 token 的状态。 | | `ctx.authorization` | `seam` | [`authorization`](../packages/credentials/authorization) | - | [`llm-pi-ai`](../packages/llm/llm-pi-ai) | - | flow 由知道如何取得某份凭据的插件注册,并以其写入的记录为键;seam 拥有这段对话与"每个键同时只跑一次尝试"的生命周期,而非协议本身。 | | `ctx.productAnalytics` | `service` | [`client-product-analytics`](../packages/client/product-analytics) | - | - | - | 根据 Host 动态采集策略接收指定桌面事件、补充可用登录身份并监听实时压缩。 | diff --git a/docs/subsystems/credentials.i18n.yaml b/docs/subsystems/credentials.i18n.yaml index 06c51858d4..bad9827407 100644 --- a/docs/subsystems/credentials.i18n.yaml +++ b/docs/subsystems/credentials.i18n.yaml @@ -9,8 +9,8 @@ en: 0083032b9d19467d zh: 15d7a7520bac094e /user-credentials/resolution: - en: 0583aeab49d80a4b - zh: 1ffd60d7e79f67cf + en: baaab4bca76bea6b + zh: 54ccdc03ffd44f63 /user-credentials/description: en: f7b09588c0f34952 zh: 1b93d673c5bf6a80 diff --git a/docs/subsystems/credentials.md b/docs/subsystems/credentials.md index b4ffca123b..2a084fb29f 100644 --- a/docs/subsystems/credentials.md +++ b/docs/subsystems/credentials.md @@ -20,8 +20,6 @@ type CredentialRef = Branded<'CredentialRef'> `resolve(ref)` returns the value with the provider-defined source layer that supplied it, or `undefined` while unconfigured. Consumers re-resolve at each operation and never cache across operations — that per-operation read is the hot-update mechanism. -`readStored(ref)` returns only the provider-managed value for editing, or `undefined` when none is stored. It never reads environment fallbacks. The Remote editor operation restricts this read to the owner. - ```ts type-equiv /** One resolved credential value and the source layer that supplied it. */ interface ResolvedCredential { @@ -154,13 +152,6 @@ A CredentialKey answers "what credential does this plugin hold for this id". Not */ abstract resolve(ref: CredentialRef): Promise -/** - * Read the provider-managed value without consulting environment fallbacks. - * @param ref - the reference to read. - * @returns the stored secret, or undefined when no non-empty value is stored. - */ -abstract readStored(ref: CredentialRef): Promise - /** * Describe one reference for configuration surfaces without exposing the * value. @@ -237,7 +228,7 @@ Source: [`packages/credentials/credentials/src/index.ts`](../../packages/credent ### `ctx.credentialsController` — `CredentialsController` -Host service backing the generated `ctx.remote.credentials` namespace. It carries every wire obligation the credential seam itself does not: the batch fan-out bound, the field-by-field view projection, the reference-grammar guard, and the refusal mapping. Metadata reads exclude secrets; readStored returns only a provider-managed value for an explicitly opened editor. +Host service backing the generated `ctx.remote.credentials` namespace. It carries every wire obligation the credential seam itself does not: the batch fan-out bound, the field-by-field view projection, the reference-grammar guard, and the refusal mapping. Secret values cross in one direction only — no method here returns one. ```ts cordis-catalog /** @@ -252,15 +243,8 @@ Host service backing the generated `ctx.remote.credentials` namespace. It carrie @Remote async describe(refs: string[]): Promise> /** - * Read one stored value for a credential editor, excluding environment fallbacks. - * @param ref - reference name to read. - * @returns the stored secret, or undefined when the provider stores none. - * @throws RemoteError for a non-owner Remote caller, an invalid reference, or an absent provider. - */ -@Remote async readStored(ref: string): Promise - -/** - * Store one value from a configuration surface. + * Store one value from a configuration surface. The value crosses the wire in + * this direction only: no read path returns it. * @param ref - reference name to store under. * @param value - the non-empty secret value. * @throws RemoteError when the request is invalid, no provider is mounted, or the provider refuses the write. diff --git a/docs/subsystems/credentials.zh.md b/docs/subsystems/credentials.zh.md index d4784832ca..1e9221699a 100644 --- a/docs/subsystems/credentials.zh.md +++ b/docs/subsystems/credentials.zh.md @@ -20,8 +20,6 @@ type CredentialRef = Branded<'CredentialRef'> `resolve(ref)` 返回值及提供该值的来源层(由提供方定义);未配置期间返回 `undefined`。消费方在每个操作中重新解析,绝不跨操作缓存——这种按操作进行的读取正是热更新机制。 -`readStored(ref)` 仅返回用于编辑的提供方托管值;未存储时返回 `undefined`。它不读取环境后备值。编辑器的 Remote 操作仅允许所有者执行此读取。 - ```ts type-equiv /** One resolved credential value and the source layer that supplied it. */ interface ResolvedCredential { @@ -154,13 +152,6 @@ A CredentialKey answers "what credential does this plugin hold for this id". Not */ abstract resolve(ref: CredentialRef): Promise -/** - * Read the provider-managed value without consulting environment fallbacks. - * @param ref - the reference to read. - * @returns the stored secret, or undefined when no non-empty value is stored. - */ -abstract readStored(ref: CredentialRef): Promise - /** * Describe one reference for configuration surfaces without exposing the * value. @@ -237,7 +228,7 @@ Source: [`packages/credentials/credentials/src/index.ts`](../../packages/credent ### `ctx.credentialsController` — `CredentialsController` -Host service backing the generated `ctx.remote.credentials` namespace. It carries every wire obligation the credential seam itself does not: the batch fan-out bound, the field-by-field view projection, the reference-grammar guard, and the refusal mapping. Metadata reads exclude secrets; readStored returns only a provider-managed value for an explicitly opened editor. +Host service backing the generated `ctx.remote.credentials` namespace. It carries every wire obligation the credential seam itself does not: the batch fan-out bound, the field-by-field view projection, the reference-grammar guard, and the refusal mapping. Secret values cross in one direction only — no method here returns one. ```ts cordis-catalog /** @@ -252,15 +243,8 @@ Host service backing the generated `ctx.remote.credentials` namespace. It carrie @Remote async describe(refs: string[]): Promise> /** - * Read one stored value for a credential editor, excluding environment fallbacks. - * @param ref - reference name to read. - * @returns the stored secret, or undefined when the provider stores none. - * @throws RemoteError for a non-owner Remote caller, an invalid reference, or an absent provider. - */ -@Remote async readStored(ref: string): Promise - -/** - * Store one value from a configuration surface. + * Store one value from a configuration surface. The value crosses the wire in + * this direction only: no read path returns it. * @param ref - reference name to store under. * @param value - the non-empty secret value. * @throws RemoteError when the request is invalid, no provider is mounted, or the provider refuses the write. diff --git a/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.i18n.yaml deleted file mode 100644 index 3acec7569f..0000000000 --- a/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.i18n.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading -# section, a hash of its English and Chinese blocks outside code blocks and generated regions. -# After editing either side, bring the other along and re-record with: -# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.md -/: - en: 2f1907963c732ea8 - zh: e25494c07150f6b9 -/saved-api-keys-in-provider-editors: - en: 63376a595a0e6dae - zh: 2709df13410087e2 -/saved-api-keys-in-provider-editors/change: - en: 463718dbe83f900d - zh: d2e55dfebf8a4b9e -/saved-api-keys-in-provider-editors/migration: - en: 19c94ae9626773b1 - zh: 1098744f47162c43 diff --git a/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.md b/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.md deleted file mode 100644 index 8e721ad800..0000000000 --- a/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -kind: upgrade-guide -description: "Saved API keys appear in masked editor fields, and clearing a saved key removes its override." ---- -# Saved API keys in provider editors - -English | [中文](guide.zh.md) - -## Change - -Provider editors show stored API keys as masked values instead of empty fields. Applying an empty field removes a previously loaded key and restores environment authentication. Cancel preserves the stored key. Environment values are never loaded into the editor. - -Credential providers implement `readStored(ref): Promise` to return only the managed value, without environment fallbacks. The owner-only `credentials.readStored` Remote method supplies this value to an opened editor; general metadata reads remain redacted. - -## Migration - -1. Keep the loaded value to retain a saved key, replace it to rotate the key, or clear it and apply to use environment authentication. -2. Implement `readStored` in custom `CredentialProvider` subclasses; return `undefined` when no non-empty value is stored. -3. Reopen the DeepSeek editor to confirm the saved key appears masked. After clearing and applying, confirm the field is empty and offers environment authentication. diff --git a/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.zh.md b/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.zh.md deleted file mode 100644 index 75efbcc4d7..0000000000 --- a/docs/upgrade-guide/v0.2.2-alpha.2/credential-editor/guide.zh.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -kind: upgrade-guide -description: "已保存的 API 密钥显示为编辑器中的掩码值,清空已保存密钥会删除其覆盖。" ---- -# 提供商编辑器中的已保存 API 密钥 - -[English](guide.md) | 中文 - -## 变更 - -提供商编辑器以掩码值显示已保存的 API 密钥,不再显示空字段。应用空字段会删除之前加载的密钥并恢复环境认证。「取消」保留已保存密钥。环境变量值从不加载到编辑器。 - -凭据提供方实现 `readStored(ref): Promise`,仅返回托管值,不使用环境后备。仅允许所有者调用的 `credentials.readStored` Remote 方法向已打开的编辑器提供此值;普通元数据读取仍保持脱敏。 - -## 迁移 - -1. 保留加载的值即可保留已保存密钥,替换它可轮换密钥,清空并应用则使用环境认证。 -2. 为自定义 `CredentialProvider` 子类实现 `readStored`;未存储非空值时返回 `undefined`。 -3. 重新打开 DeepSeek 编辑器,确认已保存密钥显示为掩码。清空并应用后,确认字段为空且提示使用环境认证。 diff --git a/docs/user/guide/providers.i18n.yaml b/docs/user/guide/providers.i18n.yaml index 62801fa60d..b04aada43b 100644 --- a/docs/user/guide/providers.i18n.yaml +++ b/docs/user/guide/providers.i18n.yaml @@ -6,11 +6,11 @@ en: b1631dcf25e805a1 zh: 8ded02e2ae87f00b /configure-models/configure-deepseek: - en: 5cf396eb7f22b0f6 - zh: d70688c6cd826f3a + en: 44852da64a6a39ec + zh: 4c280e428f0fec08 /configure-models/add-a-third-party-provider: - en: c8fd933006c3830c - zh: 386f8f7d302e98c3 + en: f6fb44a85dc5e4dd + zh: 2b86ea4492c32ed7 /configure-models/add-a-custom-model-api: en: 17867305a3e1b52a zh: 876fedf1f6f563e4 diff --git a/docs/user/guide/providers.md b/docs/user/guide/providers.md index 1ab90f440e..fe831bcaf9 100644 --- a/docs/user/guide/providers.md +++ b/docs/user/guide/providers.md @@ -10,7 +10,7 @@ Open **Settings → Models**. The DeepSeek card exposes one API-key field; enter ![The Models page: the DeepSeek card, with Add model provider below it](providers-models-page.png) -Opening a provider editor loads its saved key into a masked input. Environment values are never loaded into this input. The key is stored in `$DSH_HOME/.credentials.yaml`, while settings retain only its credential reference. Credential metadata remains redacted. +Keys are write-only. The page receives a redacted descriptor after saving, never the literal secret. The key is stored in `$DSH_HOME/.credentials.yaml`, while settings retain only its credential reference. With a key saved and the default endpoint, DeepSeek's models follow the list the DeepSeek API publishes. The list loads when the models are first needed, refreshes in the background about every ten minutes while they are in use, and falls back to the built-in models when it cannot load. Editing **Models** under **Customized settings** keeps your own list instead and stops following the published one; **Restore defaults** follows it again and reloads it. While the published list is in use, the card shows the built-in models, so a newly published model appears only in the model picker. The [API-key provider reference](../../../packages/llm/llm-deepseek-api-key/README.md) owns the listing, fallback, and gating rules. @@ -18,11 +18,11 @@ With a key saved and the default endpoint, DeepSeek's models follow the list the Choose **Add model provider**. The card opens on **Third-party model provider**: pick a provider dsh ships with — the list shows provider ids such as `anthropic`, `openai`, `moonshotai` for Kimi, or `zai` for GLM — enter its API key, and save. The installed catalog supplies the endpoint, protocol, and model list. -The authentication **?** explains saved-credential priority and environment fallbacks. With no saved key, leave the input blank to try the listed environment variables. A green hint identifies a detected environment variable. A yellow hint means no credential variable was detected; enter an API key or configure the listed variable. An unconfirmed hint means the status read failed or a saved key still covers the environment lookup. Clearing a saved key shows an unconfirmed hint until you save its removal and the page refreshes the environment check. Detection does not validate the credential or test the connection. Provider-managed credential files, including AWS profiles and Google application-default credentials, are outside this check. Providers without native key authentication, such as `openai-codex`, show no key field unless the profile explicitly names a credential reference. +The authentication **?** explains saved-credential priority and environment fallbacks. Leave the key blank to use a saved credential or try the listed environment variables. A green hint identifies a detected environment variable. A yellow hint means no credential variable was detected; enter an API key or configure the listed variable. An unconfirmed hint means the status read failed. Detection does not validate the credential or test the connection. Provider-managed credential files, including AWS profiles and Google application-default credentials, are outside this check. Providers without native key authentication, such as `openai-codex`, show no key field unless the profile explicitly names a credential reference. -A saved key appears masked, with no status text below the input. An empty input uses **Leave blank to use env as auth** and one detection hint. A nonempty input shows no authentication status text. Address configuration variables appear under **Base URL** and do not count as credentials. +A saved credential uses the placeholder **Leave blank to use saved credentials**, with no status text below the input. Environment fallback uses **Leave blank to use env as auth** and one detection hint while the input is empty. A nonempty input shows no authentication status text. Address configuration variables appear under **Base URL** and do not count as credentials. -A nonempty key input has an eye button. Select **Show secret** to check the loaded or newly entered key, and **Hide secret** to mask it again. Changing the input masks it again. Saving an unchanged key preserves its exact stored value. Clearing it and saving removes the saved key. Cancelling preserves the saved key. +A nonempty key input has an eye button. Select **Show secret** to check what you typed, and **Hide secret** to mask it again. Changing the input masks it again. Stored credentials remain write-only. ## Add a custom model API diff --git a/docs/user/guide/providers.zh.md b/docs/user/guide/providers.zh.md index ddb44f1814..bb518c42b9 100644 --- a/docs/user/guide/providers.zh.md +++ b/docs/user/guide/providers.zh.md @@ -10,7 +10,7 @@ ![模型页:DeepSeek 卡片,及其下方的添加模型提供商入口](providers-models-page.zh.png) -打开提供商编辑器时,已保存密钥会载入遮罩输入框。环境变量的值不会载入此输入框。密钥存储在 `$DSH_HOME/.credentials.yaml` 中,settings 只保留它的凭据引用。凭据元数据仍保持脱敏。 +密钥是只写的。保存后,页面只会收到脱敏描述符,永远不会收到明文密钥。密钥存储在 `$DSH_HOME/.credentials.yaml` 中,settings 只保留它的凭据引用。 保存了密钥且使用默认端点时,DeepSeek 的模型跟随 DeepSeek API 发布的列表。第一次需要模型时加载列表,使用期间约每十分钟在后台刷新一次,无法加载时退回内置模型。在**自定义设置**里编辑**模型目录**会改用你自己的列表,不再跟随发布的列表;点**恢复默认模型**会重新跟随并重新加载。使用发布的列表时,卡片上显示的是内置模型,因此新发布的模型只出现在模型选择器中。列表、兜底和门控规则见 [API key 提供方参考](../../../packages/llm/llm-deepseek-api-key/README.zh.md)。 @@ -18,11 +18,11 @@ 选择**添加模型提供商**。卡片默认打开在**第三方模型提供商**:选取 dsh 自带的提供商——列表显示的是提供商 id,例如 `anthropic`、`openai`、Kimi 对应的 `moonshotai`、GLM 对应的 `zai`——输入其 API 密钥并保存。已安装目录会提供端点、协议和模型列表。 -认证 **?** 说明已保存凭据的优先级和环境后备。没有已保存密钥时,输入留空会尝试读取列出的环境变量。绿色提示标明已检测到环境变量。黄色提示表示未检测到凭据变量;请输入 API 密钥或配置列出的变量。状态未确认表示读取失败,或已保存密钥仍覆盖环境读取。清空已保存密钥后,提示会保持未确认,直到保存删除操作并刷新环境检测。检测不验证凭据,也不测试连接。AWS profile 和 Google 应用默认凭据等提供商管理的凭据文件不在检查范围内。没有原生密钥认证的提供商(例如 `openai-codex`)不显示密钥字段,除非 profile 显式指定了凭据引用。 +认证 **?** 说明已保存凭据的优先级和环境后备。密钥留空时,使用已保存凭据,或尝试读取列出的环境变量。绿色提示标明已检测到环境变量。黄色提示表示未检测到凭据变量;请输入 API 密钥或配置列出的变量。状态未确认表示读取失败。检测不验证凭据,也不测试连接。AWS profile 和 Google 应用默认凭据等提供商管理的凭据文件不在检查范围内。没有原生密钥认证的提供商(例如 `openai-codex`)不显示密钥字段,除非 profile 显式指定了凭据引用。 -已保存密钥以遮罩显示,输入框下方不显示状态文字。输入留空时,显示**留空使用环境认证**占位文字和一条检测提示。输入非空时,不显示认证状态文字。地址配置变量显示在**基础 URL**下方,不计作凭据。 +已保存凭据使用**留空使用已保存凭据**占位文字,输入框下方不显示状态文字。环境后备使用**留空使用环境认证**占位文字,输入留空时显示一条检测提示。输入非空时,不显示认证状态文字。地址配置变量显示在**基础 URL**下方,不计作凭据。 -密钥输入非空时,输入框内显示眼睛按钮。选择**显示密钥**检查已载入或新输入的密钥,选择**隐藏密钥**重新遮住输入。修改输入后会重新遮住密钥。保存未修改的密钥会保留原值。清空并保存会删除已保存密钥。取消编辑会保留已保存密钥。 +密钥输入非空时,输入框内显示眼睛按钮。选择**显示密钥**检查当前输入,选择**隐藏密钥**重新遮住输入。修改输入后会重新遮住密钥。已保存凭据仍保持只写。 ## 添加自定义模型 API diff --git a/packages/api/settings-controller/README.i18n.yaml b/packages/api/settings-controller/README.i18n.yaml index 979d0867fb..4b3f0d24d3 100644 --- a/packages/api/settings-controller/README.i18n.yaml +++ b/packages/api/settings-controller/README.i18n.yaml @@ -9,14 +9,14 @@ en: 7fecb4d8800e8f97 zh: 3e2c3fdb29b73cd0 /settings-controller/summary: - en: 94a995854f855609 - zh: 7165eecdd85a5632 + en: e5068267079e62d0 + zh: 9e2d663a6ca02c58 /settings-controller/table-of-contents: en: 3a654e12f423946b zh: 4e3a19aaee58f8a7 /settings-controller/use-this-package: - en: d6fbd0324044be6b - zh: 5e86d8c95e51b421 + en: cf2f4de5bee8be55 + zh: b2630dcba4be5ae8 /settings-controller/configuration: en: e0297f144b649af7 zh: e70ed56edffd97f0 diff --git a/packages/api/settings-controller/README.md b/packages/api/settings-controller/README.md index 17357971ed..b38072546d 100644 --- a/packages/api/settings-controller/README.md +++ b/packages/api/settings-controller/README.md @@ -8,7 +8,7 @@ English | [中文](README.zh.md) ## Summary -`@deepseek-ai/dsh-api-settings-controller` exposes generated `ctx.remote.settings` and `ctx.remote.credentials` namespaces for browser configuration surfaces. It returns redacted settings and credential metadata and supports settings and credential writes. It reads stored keys for owner-opened editors. It also opens provider-owned settings or Agent preset locations on the Host desktop. When a provider is absent, the namespace remains registered and returns an actionable configuration error. +`@deepseek-ai/dsh-api-settings-controller` exposes generated `ctx.remote.settings` and `ctx.remote.credentials` namespaces for browser configuration surfaces. It returns redacted settings and credential metadata, supports settings and credential writes without returning secret values, and opens provider-owned settings or Agent preset locations on the Host desktop. When a provider is absent, the namespace remains registered and returns an actionable configuration error. ## Table of Contents @@ -25,7 +25,7 @@ English | [中文](README.zh.md) Mount this package as a Loader entry in a profile that serves browser configuration. The entry registers both namespaces independently of their providers so a missing provider produces a named configuration error at invocation. Its generated descriptors enter the strict Typert registry, while the settings and credential Definitions remain plain Cordis Services with no wire obligations of their own. -`describe(refs)` answers one map keyed by the requested names, so a settings page describing every reference its rows carry settles those rows together. It accepts at most 64 names per call, reports an invalid name or empty write value as `bad-request`, and copies each answer field by field — a provider returning more than `CredentialInfo` declares cannot widen what crosses. Valid `set(ref, value)` and `unset(ref)` calls report a provider refusal as `credential-rejected`, carrying the provider's message with only the reference in its details. `readStored(ref)` returns a provider-managed key only for the owner or trusted in-process code; it returns no environment fallback. A non-owner read returns `credential/rejected` before consulting the provider. Metadata reads remain secret-free. +`describe(refs)` answers one map keyed by the requested names, so a settings page describing every reference its rows carry settles those rows together. It accepts at most 64 names per call, reports an invalid name or empty write value as `bad-request`, and copies each answer field by field — a provider returning more than `CredentialInfo` declares cannot widen what crosses. Valid `set(ref, value)` and `unset(ref)` calls report a provider refusal as `credential-rejected`, carrying the provider's message with only the reference in its details. Secret values cross in this direction only: no method here returns one. `settings.describe()` returns deployment facts and every namespace under `redactSecrets: true`. `settings.update`, `settings.replace`, and `settings.mutate` expose the settings service's three write operations and return the namespace's new redacted view; stale writes use `settings-conflict` and other provider refusals use `settings-rejected`. diff --git a/packages/api/settings-controller/README.zh.md b/packages/api/settings-controller/README.zh.md index 2c4f4a2b29..3c9e876740 100644 --- a/packages/api/settings-controller/README.zh.md +++ b/packages/api/settings-controller/README.zh.md @@ -8,7 +8,7 @@ kind: "package-reference" ## 概述 -`@deepseek-ai/dsh-api-settings-controller` 为浏览器配置界面提供生成的 `ctx.remote.settings` 与 `ctx.remote.credentials` namespace。它返回脱敏的 settings 与凭据元数据,支持 settings 与凭据写入。它为所有者打开的编辑器读取已保存密钥。它还在 Host 桌面打开由提供方持有的 settings 或 Agent preset 位置。提供方缺失时,namespace 仍会注册,并返回可操作的配置错误。 +`@deepseek-ai/dsh-api-settings-controller` 为浏览器配置界面提供生成的 `ctx.remote.settings` 与 `ctx.remote.credentials` namespace。它返回脱敏的 settings 与凭据元数据,支持 settings 与凭据写入而不返回机密值,并在 Host 桌面打开由提供方持有的 settings 或 Agent preset 位置。提供方缺失时,namespace 仍会注册,并返回可操作的配置错误。 ## 目录 @@ -25,7 +25,7 @@ kind: "package-reference" 请把本包作为 Loader entry 挂载到提供浏览器配置的 profile 中。本 entry 不依赖提供方是否存在而注册两个 namespace,因此缺少提供方会在调用时产生具名配置错误。它生成的 descriptor 进入严格 Typert 注册表,而 settings 与凭据 Definition 仍是普通 Cordis 服务,自身不承担任何 wire 义务。 -`describe(refs)` 以请求的名字为键返回一份 map,因此设置页描述其各行携带的全部引用时,这些行会一起落定。单次调用最多接受 64 个名字,无效名字或空写入值报告为 `bad-request`,并逐字段复制每个答案——提供方返回超出 `CredentialInfo` 声明的内容也无法扩大跨越 wire 的字段。有效的 `set(ref, value)` 与 `unset(ref)` 调用把提供方拒绝报告为 `credential-rejected`,携带提供方的消息,details 中只有该引用。`readStored(ref)` 仅向所有者或可信进程内代码返回提供方管理的密钥,不返回环境后备值。非所有者读取会在访问提供方之前返回 `credential/rejected`。元数据读取仍不包含机密。 +`describe(refs)` 以请求的名字为键返回一份 map,因此设置页描述其各行携带的全部引用时,这些行会一起落定。单次调用最多接受 64 个名字,无效名字或空写入值报告为 `bad-request`,并逐字段复制每个答案——提供方返回超出 `CredentialInfo` 声明的内容也无法扩大跨越 wire 的字段。有效的 `set(ref, value)` 与 `unset(ref)` 调用把提供方拒绝报告为 `credential-rejected`,携带提供方的消息,details 中只有该引用。机密值只在这个方向跨越 wire:这里没有任何方法会返回它。 `settings.describe()` 返回部署信息,以及在 `redactSecrets: true` 下读取的所有 namespace。`settings.update`、`settings.replace` 与 `settings.mutate` 暴露 settings 服务的三种写入操作,并返回该 namespace 的新脱敏视图;陈旧写入使用 `settings-conflict`,其他提供方拒绝使用 `settings-rejected`。 diff --git a/packages/api/settings-controller/src/credentials.ts b/packages/api/settings-controller/src/credentials.ts index f9172f8f9e..3889669048 100644 --- a/packages/api/settings-controller/src/credentials.ts +++ b/packages/api/settings-controller/src/credentials.ts @@ -9,7 +9,7 @@ import { Context } from '@deepseek-ai/cordis' import { credentialRef } from '@deepseek-ai/dsh-credentials' import type { CredentialProvider } from '@deepseek-ai/dsh-credentials' import type { CredentialInfo } from '@deepseek-ai/dsh-credentials/types' -import { principalOf, Remote, RemoteError, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol' +import { Remote, RemoteError, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol' import { z } from 'zod' /** @@ -61,8 +61,8 @@ declare module '@deepseek-ai/cordis' { * Host service backing the generated `ctx.remote.credentials` namespace. It * carries every wire obligation the credential seam itself does not: the batch * fan-out bound, the field-by-field view projection, the reference-grammar - * guard, and the refusal mapping. Metadata reads exclude secrets; readStored - * returns only a provider-managed value for an explicitly opened editor. + * guard, and the refusal mapping. Secret values cross in one direction only — + * no method here returns one. */ export class CredentialsController extends TypertRemoteService { /** @param ctx - Host context where a credential provider may be mounted. */ @@ -90,22 +90,8 @@ export class CredentialsController extends TypertRemoteService { } /** - * Read one stored value for a credential editor, excluding environment fallbacks. - * @param ref - reference name to read. - * @returns the stored secret, or undefined when the provider stores none. - * @throws RemoteError for a non-owner Remote caller, an invalid reference, or an absent provider. - */ - @Remote - async readStored(ref: string): Promise { - const request = parseRequest('credentials.readStored', unsetRequestSchema, { ref }) - if (principalOf(this.ctx.invocation) !== undefined) { - throw new RemoteError('credential/rejected', 'Only the owner can read stored credentials.', { ref: request.ref }) - } - return this.provider().readStored(credentialRef(request.ref)) - } - - /** - * Store one value from a configuration surface. + * Store one value from a configuration surface. The value crosses the wire in + * this direction only: no read path returns it. * @param ref - reference name to store under. * @param value - the non-empty secret value. * @throws RemoteError when the request is invalid, no provider is mounted, or the provider refuses the write. diff --git a/packages/api/settings-controller/src/types.ts b/packages/api/settings-controller/src/types.ts index d1dadc1e16..3d11c6ab0c 100644 --- a/packages/api/settings-controller/src/types.ts +++ b/packages/api/settings-controller/src/types.ts @@ -20,9 +20,9 @@ declare module '@deepseek-ai/dsh-typert-protocol' { */ 'settings/conflict': { readonly ns: string; readonly expected: number; readonly actual: number } /** - * A non-owner requested a stored secret, or the provider refused a valid - * credential write, for example because the stored document no longer - * parses. The details name only the reference, never the value. + * The provider refused a valid credential write, for example because the + * stored document no longer parses. The details name only the reference, + * never the value. */ 'credential/rejected': { readonly ref: string } } diff --git a/packages/api/settings-controller/tests/credentials-controller.host.spec.ts b/packages/api/settings-controller/tests/credentials-controller.host.spec.ts index 552baa7b5d..5eeb190385 100644 --- a/packages/api/settings-controller/tests/credentials-controller.host.spec.ts +++ b/packages/api/settings-controller/tests/credentials-controller.host.spec.ts @@ -2,17 +2,9 @@ import { describe, expect, it } from 'vitest' import { Context } from '@deepseek-ai/cordis' import type { CredentialInfo } from '@deepseek-ai/dsh-credentials/types' import { remoteErrorOf, remoteMethods } from '@deepseek-ai/dsh-typert-protocol' -import type { PeerId, RemoteInvocation } from '@deepseek-ai/dsh-typert-protocol' import CredentialsController from '../src/credentials.ts' import { MemoryCredentials } from '../../../credentials/credentials/tests/memory.ts' -declare module '@deepseek-ai/dsh-typert-protocol' { - interface PrincipalMap { - /** Non-owner used to verify stored-key read denial. */ - 'credential-viewer': { readonly kind: 'credential-viewer' } - } -} - /** A store whose `describe` carries more than the view declares, as a foreign provider might. */ class LeakyCredentials extends MemoryCredentials { override describe(): Promise { @@ -54,7 +46,6 @@ describe('the credentials Remote namespace a configuration surface calls', () => expect(binding.namespace).toBe('credentials') expect(remoteMethods(controller)).toEqual([ { method: 'describe', invocation: { kind: 'direct' } }, - { method: 'readStored', invocation: { kind: 'direct' } }, { method: 'set', invocation: { kind: 'direct' } }, { method: 'unset', invocation: { kind: 'direct' } }, ]) @@ -65,7 +56,6 @@ describe('the credentials Remote namespace a configuration surface calls', () => await ctx.plugin(CredentialsController) for (const call of [ () => ctx.credentialsController.describe(['DEEPSEEK_API_KEY']), - () => ctx.credentialsController.readStored('DEEPSEEK_API_KEY'), () => ctx.credentialsController.set('DEEPSEEK_API_KEY', 'sk-live'), () => ctx.credentialsController.unset('DEEPSEEK_API_KEY'), ]) { @@ -92,7 +82,6 @@ describe('the credentials Remote namespace a configuration surface calls', () => const controller = await boot() for (const call of [ () => controller.describe(['DEEPSEEK_API_KEY', 'not a var']), - () => controller.readStored('not a var'), () => controller.set('not a var', 'sk-live'), () => controller.unset('not a var'), ]) { @@ -126,35 +115,6 @@ describe('the credentials Remote namespace a configuration surface calls', () => .toEqual({ DEEPSEEK_API_KEY: { configured: false, writable: true } }) }) - it('reads stored secrets only through the explicit editor read', async () => { - const controller = await boot({ DEEPSEEK_API_KEY: 'fixture-saved-key' }) - expect(await controller.readStored('DEEPSEEK_API_KEY')).toBe('fixture-saved-key') - expect(await controller.readStored('OPENAI_API_KEY')).toBeUndefined() - expect(JSON.stringify(await controller.describe(['DEEPSEEK_API_KEY']))).not.toContain('fixture-saved-key') - await controller.unset('DEEPSEEK_API_KEY') - expect(await controller.readStored('DEEPSEEK_API_KEY')).toBeUndefined() - }) - - it('denies non-owner stored-key reads before consulting the provider', async () => { - const ctx = new Context() - await ctx.plugin(MemoryCredentials, { DEEPSEEK_API_KEY: 'fixture-saved-key' }) - await ctx.plugin(CredentialsController) - const signal = new AbortController().signal - const invocation: RemoteInvocation = { - request: { namespace: 'credentials', method: 'readStored', args: { ref: 'DEEPSEEK_API_KEY' } }, - service: 'credentialsController', signal, - peer: { - id: 'credential-viewer' as PeerId, ctx, signal, principal: { kind: 'credential-viewer' }, - interactions: 'none', dispose: () => Promise.resolve(), - }, - uplink: async function* (): AsyncGenerator {}, - } - const caller = ctx.extend({ invocation }) - const failure = await caller.credentialsController.readStored('DEEPSEEK_API_KEY').catch((error: unknown) => error) - expect(remoteErrorOf(failure)).toMatchObject({ code: 'credential/rejected', details: { ref: 'DEEPSEEK_API_KEY' } }) - expect(JSON.stringify(remoteErrorOf(failure))).not.toContain('fixture-saved-key') - }) - it('reports a refused write as credential/rejected naming only the reference', async () => { const controller = await boot({}, RejectingCredentials) const failure = await controller.set('DEEPSEEK_API_KEY', 'sk-live').catch((error: unknown) => error) diff --git a/packages/client/ui-settings-models/README.i18n.yaml b/packages/client/ui-settings-models/README.i18n.yaml index 3c28ce7528..02b3bd6729 100644 --- a/packages/client/ui-settings-models/README.i18n.yaml +++ b/packages/client/ui-settings-models/README.i18n.yaml @@ -9,8 +9,8 @@ en: 0db6fa836e1ff511 zh: 0e2968763e1fb7a5 /deepseek-ai-dsh-client-ui-settings-models/summary: - en: 2d39061747367414 - zh: 35edfca13c457deb + en: 51252c1e9fa6da0a + zh: 227b54d7898417fa /deepseek-ai-dsh-client-ui-settings-models/table-of-contents: en: d152484eb41ac6b4 zh: 09388d293f9be9cb @@ -18,11 +18,11 @@ en: db5aaf7f702e1f0c zh: 409a78c14fb2b6e3 /deepseek-ai-dsh-client-ui-settings-models/use-this-package/api-keys: - en: d771da09da774692 - zh: 9566b3c0e95da8a6 + en: f4817eb2e3537ed9 + zh: e589c193fa85473f /deepseek-ai-dsh-client-ui-settings-models/use-this-package/editing-a-provider: - en: 23c8e60086660111 - zh: f277b69a202f207c + en: ce52da7e6065ccc4 + zh: c63690cb5de5ea85 /deepseek-ai-dsh-client-ui-settings-models/use-this-package/adding-and-deleting-providers: en: c0b04b2b11af60d3 zh: d195eec281e445cb diff --git a/packages/client/ui-settings-models/README.md b/packages/client/ui-settings-models/README.md index 3e579642fe..8db24c5170 100644 --- a/packages/client/ui-settings-models/README.md +++ b/packages/client/ui-settings-models/README.md @@ -11,7 +11,7 @@ Desktop product events use the optional [product analytics service](../product-a ## Summary -`dsh-client-ui-settings-models` is the Models settings page of the dsh web client: users configure API keys (stored under the profile's credential reference), edit each provider's model list, and hand-declare custom pi-ai routes, with provider rows and one editor card at a time. The page joins the provider directory, the settings document, and the credential descriptions into one shared snapshot, so a row's state stays consistent across all three. It also walks first-run users through two ordered dialogs — a versioned preview notice and the conditional official-DeepSeek credential step. +`dsh-client-ui-settings-models` is the Models settings page of the dsh web client: users configure API keys (stored write-only under the profile's credential reference), edit each provider's model list, and hand-declare custom pi-ai routes, with provider rows and one editor card at a time. The page joins the provider directory, the settings document, and the credential descriptions into one shared snapshot, so a row's state stays consistent across all three. It also walks first-run users through two ordered dialogs — a versioned preview notice and the conditional official-DeepSeek credential step. ## Table of Contents @@ -41,15 +41,15 @@ Host configuration `credentialOnboarding` defaults to `true`. The Electron prelo ### API keys -The API key input shows a saved key masked and uses `autocomplete="new-password"` to avoid filling login passwords. Its eye button reveals the current value; editing or clearing the value masks it again. Environment values are never loaded into the input. +API-key inputs start empty and use `autocomplete="new-password"` to ask browsers not to autofill saved login passwords. A nonempty draft has the same eye control as masked conversation text: **Show secret** reveals the current input and **Hide secret** masks it. Changing or clearing the input masks it again. Stored credentials are never read into the input. -The primary field on an editor card is a single **API key** input — the page never asks for an environment-variable name. A typed key stores through `credentials.set` under the profile's reference, deriving `_API_KEY` when the profile has none, and the pi-ai profile records that derivation as `apiKeyEnv`, so `cordis.patch.yml` never carries a key value. Leaving a new pi-ai provider's key blank saves a reference-free profile and preserves provider-native authentication (for example the Bedrock credential chain or Vertex ADC). The field's placeholder and help tooltip use the profile's `apiKeyEnv` when it has one; otherwise they use the credential variables of the route's `nativeAuth`, excluding `baseURLEnv` address variables, in lookup order, as the configurable-provider directory reports them. These display hints omit references containing `oauth` (case-insensitively), and describe saved credentials followed by the displayed environment fallbacks. This presentation filter does not change the [credential resolution order](../../../docs/subsystems/credentials.md#resolution), the adapter's complete environment list, or an explicit reference. A filtered explicit reference still has a usable key input with the plain placeholder and no tooltip. A native route that has no key authentication omits the key field and authentication help entirely; an explicit reference still enables the field. A profile without a reference on a route without `nativeAuth`, such as a hand-declared route, shows the plain key placeholder and no tooltip. A row labels API-key state with a green solid dot only when a referenced credential is confirmed configured, and with a red solid dot only when a named reference is confirmed missing. A successful Apply emits a local accessible status message without echoing secret material. +The primary field on an editor card is a single **API key** input — the page never asks for an environment-variable name. A typed key stores write-only through `credentials.set` under the profile's reference, deriving `_API_KEY` when the profile has none, and the pi-ai profile records that derivation as `apiKeyEnv`, so `cordis.patch.yml` never carries a key value. Leaving a new pi-ai provider's key blank saves a reference-free profile and preserves provider-native authentication (for example the Bedrock credential chain or Vertex ADC). The field's placeholder and help tooltip use the profile's `apiKeyEnv` when it has one; otherwise they use the credential variables of the route's `nativeAuth`, excluding `baseURLEnv` address variables, in lookup order, as the configurable-provider directory reports them. These display hints omit references containing `oauth` (case-insensitively), and describe saved credentials followed by the displayed environment fallbacks. This presentation filter does not change the [credential resolution order](../../../docs/subsystems/credentials.md#resolution), the adapter's complete environment list, or an explicit reference. A filtered explicit reference still has a usable key input with the plain placeholder and no tooltip. A native route that has no key authentication omits the key field and authentication help entirely; an explicit reference still enables the field. A profile without a reference on a route without `nativeAuth`, such as a hand-declared route, shows the plain key placeholder and no tooltip. A row labels API-key state with a green solid dot only when a referenced credential is confirmed configured, and with a red solid dot only when a named reference is confirmed missing. A successful Apply emits a local accessible status message without echoing secret material. -Opening an existing provider editor reads its stored key through the owner-only `credentials.readStored` operation and shows it as a password input. The reveal button shows the loaded value. The key stays in that editor's local state; provider-directory and settings snapshots contain only redacted metadata. A failed read shows an error instead of an empty editor. Cancel discards edits, and Apply preserves an unchanged key, replaces an edited key, or removes a cleared key so environment authentication can apply. +The editor uses redacted `CredentialInfo` to choose the saved-credential placeholder or environment detection, without displaying a credential-source label. Refreshing the snapshot updates an open editor without a separate probe. The hint never receives a credential value or changes field writability. ### Editing a provider -An empty key field offers environment authentication; a saved key appears as a masked value. Redacted `credentials.describe` checks distinguish a detected environment reference, no detected variables, and an unconfirmed read. A missing-variable hint uses the warning color and names the first variable to configure. A detected environment reference uses green. Address configuration variables do not count as credentials. Hidden authentication references still participate in detection; a generic detected hint keeps their names hidden. Detection does not validate credentials, test a connection, or inspect provider-managed files such as AWS profiles and Google application-default credentials. A nonempty input shows no authentication status text. The page describes native variable names and named references in batches of at most 64. Editor reads return only provider-managed values, never environment values. +A blank key field offers a saved credential when one is detected, with no status text below the input; otherwise it offers environment authentication. Redacted `credentials.describe` checks distinguish a detected environment reference, no detected variables, and an unconfirmed read. A missing-variable hint uses the warning color and names the first variable to configure. A detected environment reference uses green. Address configuration variables do not count as credentials. Hidden authentication references still participate in detection; a generic detected hint keeps their names hidden. Detection does not validate credentials, test a connection, or inspect provider-managed files such as AWS profiles and Google application-default credentials. A nonempty input shows no authentication status text. The page reads native variable names as well as named references, in batches of at most 64, and never reads their values into the Client. An endpoint without a fixed catalog default shows the provider's `baseURLEnv` configuration names below the input. A profile endpoint remains the first placeholder choice. diff --git a/packages/client/ui-settings-models/README.zh.md b/packages/client/ui-settings-models/README.zh.md index f96f6d9d2b..23763f168c 100644 --- a/packages/client/ui-settings-models/README.zh.md +++ b/packages/client/ui-settings-models/README.zh.md @@ -11,7 +11,7 @@ kind: "package-reference" ## 概述 -`dsh-client-ui-settings-models` 是 dsh Web 客户端的 Models 设置页面:用户可以配置 API 密钥(存入 profile 的凭据引用之下)、编辑每个提供商的模型列表,并手工声明自定义 pi-ai 路由;页面以提供商行展示,一次只展开一张编辑卡片。该页面把提供商目录、设置文档与凭据描述合并为一个共享快照,因此行的状态在三个方面始终一致。它还会带首次运行的用户走两个有序弹窗——版本化预览版说明,以及按条件显示的官方 DeepSeek 凭据步骤。 +`dsh-client-ui-settings-models` 是 dsh Web 客户端的 Models 设置页面:用户可以配置 API 密钥(以只写方式存入 profile 的凭据引用之下)、编辑每个提供商的模型列表,并手工声明自定义 pi-ai 路由;页面以提供商行展示,一次只展开一张编辑卡片。该页面把提供商目录、设置文档与凭据描述合并为一个共享快照,因此行的状态在三个方面始终一致。它还会带首次运行的用户走两个有序弹窗——版本化预览版说明,以及按条件显示的官方 DeepSeek 凭据步骤。 ## 目录 @@ -41,15 +41,15 @@ Host 配置 `credentialOnboarding` 默认为 `true`。Electron preload 标记会 ### API 密钥 -API 密钥输入框以掩码显示已保存的密钥,并通过 `autocomplete="new-password"` 避免填入登录密码。眼睛按钮显示当前值;修改或清空输入后重新遮住密钥。环境变量值从不加载到输入框。 +API 密钥输入框初始为空,并通过 `autocomplete="new-password"` 请求浏览器不要自动填入已保存的登录密码。输入非空时,显示与会话密钥遮罩一致的眼睛按钮:**显示密钥**展示当前输入,**隐藏密钥**重新遮住输入。修改或清空输入后会重新遮住密钥。已保存凭据从不读入输入框。 -编辑卡片上的主字段是单独一个 **API 密钥**输入框——页面从不询问环境变量名。键入的密钥经 `credentials.set` 存入 profile 的引用之下,profile 没有引用时便派生 `_API_KEY`,pi-ai profile 会把这次派生记录为 `apiKeyEnv`,因此 `cordis.patch.yml` 从不携带密钥值。为新的 pi-ai 提供商留空密钥会保存一个不带引用的 profile,从而保留提供商原生认证(例如 Bedrock 凭据链或 Vertex ADC)。profile 有 `apiKeyEnv` 时,字段的占位文字与帮助提示采用该引用;否则按查找顺序采用可配置提供商目录为该路由报告的 `nativeAuth` 凭据变量,并排除 `baseURLEnv` 地址变量。这些显示提示会忽略包含 `oauth` 的引用(不区分大小写),并说明优先使用已保存凭据,其后为显示的环境后备。这项显示过滤不改变[凭据解析顺序](../../../docs/subsystems/credentials.zh.md#resolution)、适配器的完整环境变量列表或显式引用。被过滤的显式引用仍有可用的密钥输入框,使用普通占位文字且不显示帮助提示。没有密钥认证的原生路由不显示密钥字段及认证帮助;显式引用仍会启用该字段。路由没有 `nativeAuth`(例如手动声明的路由)且 profile 没有引用时,显示普通的密钥占位文字,且不显示帮助提示。只有确认引用的凭据已配置时,行才会以绿色实心点标示 API 密钥状态;只有确认具名引用缺失时,才会以红色实心点标示。「应用」成功后会发出本地无障碍状态消息,且绝不回显任何机密内容。 +编辑卡片上的主字段是单独一个 **API 密钥**输入框——页面从不询问环境变量名。键入的密钥经 `credentials.set` 以**只写**方式存入 profile 的引用之下,profile 没有引用时便派生 `_API_KEY`,pi-ai profile 会把这次派生记录为 `apiKeyEnv`,因此 `cordis.patch.yml` 从不携带密钥值。为新的 pi-ai 提供商留空密钥会保存一个不带引用的 profile,从而保留提供商原生认证(例如 Bedrock 凭据链或 Vertex ADC)。profile 有 `apiKeyEnv` 时,字段的占位文字与帮助提示采用该引用;否则按查找顺序采用可配置提供商目录为该路由报告的 `nativeAuth` 凭据变量,并排除 `baseURLEnv` 地址变量。这些显示提示会忽略包含 `oauth` 的引用(不区分大小写),并说明优先使用已保存凭据,其后为显示的环境后备。这项显示过滤不改变[凭据解析顺序](../../../docs/subsystems/credentials.zh.md#resolution)、适配器的完整环境变量列表或显式引用。被过滤的显式引用仍有可用的密钥输入框,使用普通占位文字且不显示帮助提示。没有密钥认证的原生路由不显示密钥字段及认证帮助;显式引用仍会启用该字段。路由没有 `nativeAuth`(例如手动声明的路由)且 profile 没有引用时,显示普通的密钥占位文字,且不显示帮助提示。只有确认引用的凭据已配置时,行才会以绿色实心点标示 API 密钥状态;只有确认具名引用缺失时,才会以红色实心点标示。「应用」成功后会发出本地无障碍状态消息,且绝不回显任何机密内容。 -打开已有提供商的编辑器时,通过仅允许所有者调用的 `credentials.readStored` 操作读取已保存密钥,并以密码输入框显示。显示按钮可以展示已加载的值。密钥只保存在该编辑器的本地状态中;提供商目录与设置快照只包含脱敏元数据。读取失败时显示错误,不打开空白编辑器。「取消」丢弃编辑;「保存」保留未修改的密钥、替换已编辑的密钥,或删除已清空的密钥,从而允许使用环境认证。 +编辑器使用脱敏 `CredentialInfo` 选择已保存凭据的占位文字或环境检测,不显示凭据来源标签。快照刷新会更新打开的编辑器,无需单独探测。提示从不接收凭据值,也不改变字段的可写性。 ### 编辑提供商 -空密钥字段提示使用环境认证;已保存的密钥显示为掩码值。脱敏的 `credentials.describe` 检查区分已检测到环境引用、未检测到变量和读取状态未确认。缺少变量时使用黄色提示,并列出应配置的首个变量名。已检测到环境引用时使用绿色。地址配置变量不计作凭据。隐藏的认证引用仍参与检测;使用不含变量名的通用检测提示。检测不验证凭据、不测试连接,也不检查 AWS profile 或 Google 应用默认凭据等提供商管理的文件。输入非空时,不显示认证状态文字。页面按每批最多 64 项描述原生变量名和具名引用。编辑器读取只返回提供方管理的值,不返回环境变量值。 +密钥字段留空时,已检测到已保存凭据则提示使用该凭据,输入框下方不显示状态文字;否则提示使用环境认证。脱敏的 `credentials.describe` 检查区分已检测到环境引用、未检测到变量和读取状态未确认。缺少变量时使用黄色提示,并列出应配置的首个变量名。已检测到环境引用时使用绿色。地址配置变量不计作凭据。隐藏的认证引用仍参与检测;使用不含变量名的通用检测提示。检测不验证凭据、不测试连接,也不检查 AWS profile 或 Google 应用默认凭据等提供商管理的文件。输入非空时,不显示认证状态文字。页面读取原生变量名和具名引用,每批最多 64 项,不将变量值读入 Client。 目录未提供固定默认端点时,输入框下方显示提供方的 `baseURLEnv` 配置变量名。Profile 中的端点仍是占位符的首选。 diff --git a/packages/client/ui-settings-models/src/client/ApiKeyInput.tsx b/packages/client/ui-settings-models/src/client/ApiKeyInput.tsx index 3727000fc1..e983a40303 100644 --- a/packages/client/ui-settings-models/src/client/ApiKeyInput.tsx +++ b/packages/client/ui-settings-models/src/client/ApiKeyInput.tsx @@ -1,4 +1,4 @@ -/** Credential input with the same reveal behavior as masked conversation text. */ +/** Write-only credential input with the same reveal behavior as masked conversation text. */ import { useState } from 'react' import type { InputHTMLAttributes, ReactNode } from 'react' import type { en } from './locales.ts' @@ -10,7 +10,7 @@ const EYE_OFF_PATH = `${EYE_CONTOUR}M2.5 2.5L13.5 13.5` /** Input attributes and section copy for the current credential draft. */ interface ApiKeyInputProps extends Omit, 'value' | 'type' | 'className' | 'autoComplete'> { - /** Stored credential or the user's current edit; initially masked. */ + /** Unsaved input; stored credentials are never read into this field. */ readonly value: string /** Section copy, including the same reveal labels as SecretText. */ readonly t: (key: keyof typeof en) => string diff --git a/packages/client/ui-settings-models/src/client/ModelListEditor.tsx b/packages/client/ui-settings-models/src/client/ModelListEditor.tsx index 37a2ae989f..05c2b3e1ab 100644 --- a/packages/client/ui-settings-models/src/client/ModelListEditor.tsx +++ b/packages/client/ui-settings-models/src/client/ModelListEditor.tsx @@ -63,7 +63,7 @@ export interface ProbeTarget { baseURL?: string /** Wire protocol the form names, when it names one. */ api?: string - /** Loaded or newly entered key currently shown in the form, when there is one. */ + /** Key typed into the form and not yet stored, when there is one. */ apiKey?: string } diff --git a/packages/client/ui-settings-models/src/client/ModelsSection.tsx b/packages/client/ui-settings-models/src/client/ModelsSection.tsx index adff556795..461ab37aad 100644 --- a/packages/client/ui-settings-models/src/client/ModelsSection.tsx +++ b/packages/client/ui-settings-models/src/client/ModelsSection.tsx @@ -86,8 +86,6 @@ export interface ProviderIdentity { /** One existing row or dormant directory entry addressed by an editor action. */ interface EditorTarget extends ProviderIdentity { - /** Stored secret retained only while this editor is open. */ - initialCredential?: string settingsNs: string settingsPath: readonly string[] /** Writable credential identified under this page's conventional reference. */ @@ -125,18 +123,16 @@ interface ProviderEditorRenderProps extends Pick< /** Render an editor for either the setup posture or an expanded provider row. */ function renderProviderEditor({ target, row, ...props }: ProviderEditorRenderProps): ReactNode { - const credential = row.apiKeyEnv === undefined ? row.derivedCredential : row.credential return ( @@ -258,10 +254,6 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS if (state.status === 'ready' && !hasReadySnapshot) setHasReadySnapshot(true) if (state.status === 'error' && hasReadySnapshot) setHasReadySnapshot(false) const [editing, setEditing] = useState(undefined) - const [credentialRead, setCredentialRead] = useState< - { provider: string; status: 'loading' } | { provider: string; status: 'failed'; message: string } - >() - const editorLoading = credentialRead?.status === 'loading' const [addOpen, setAddOpen] = useState(false) const [addMode, setAddMode] = useState('catalog') /** The modes shown since the add card opened; each keeps its panel mounted. */ @@ -277,26 +269,6 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS const [savedTarget, setSavedTarget] = useState(undefined) const [dismissedSetup, setDismissedSetup] = useState>(() => new Set()) - const openEditor = async (row: ProviderRow, target: EditorTarget): Promise => { - setSavedTarget(undefined) - setAddOpen(false) - setEditing(undefined) - setCredentialRead(undefined) - const info = row.apiKeyEnv === undefined ? row.derivedCredential : row.credential - if (info?.configured === false) { - setEditing(target) - return - } - setCredentialRead({ provider: target.provider, status: 'loading' }) - const loaded = await operations.readCredential(row.apiKeyEnv ?? deriveKeyRef(target.provider)) - if (loaded.kind === 'refused') { - setCredentialRead({ provider: target.provider, status: 'failed', message: loaded.message }) - return - } - setCredentialRead(undefined) - setEditing({ ...target, ...loaded.value === undefined ? {} : { initialCredential: loaded.value } }) - } - const announceSaved = (target: ProviderIdentity): void => { // Announced only once the refreshed directory is in the snapshot the // notice reads its name from: an apply can rename the route, and the @@ -537,12 +509,15 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS type="button" className={styles['secondaryButton']} aria-label={providerCopy(t('editProvider'), target)} - disabled={editorLoading || (!open && state.status !== 'ready')} - aria-busy={credentialRead?.provider === target.provider && editorLoading} + disabled={!open && state.status !== 'ready'} onClick={() => { if (!open && controller.store.getSnapshot().status !== 'ready') return - if (open) setEditing(undefined) - else void openEditor(row, target) + setSavedTarget(undefined) + // One card at a time: the add card closes with whatever + // it held, since closing either card would otherwise + // discard the other's draft. + setAddOpen(false) + setEditing(open ? undefined : target) }} > {t('edit')} @@ -554,7 +529,7 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS type="button" className={styles['dangerButton']} aria-label={providerCopy(t('removeProvider'), target)} - disabled={editorLoading || !state.writable || state.status !== 'ready'} + disabled={!state.writable || state.status !== 'ready'} onClick={() => { if (controller.store.getSnapshot().status !== 'ready') return setSavedTarget(undefined) @@ -569,8 +544,6 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS {error} - {credentialRead?.provider === target.provider && credentialRead.status === 'failed' - ?

{credentialRead.message}

: null} {renderSlot( 'settings.models.provider-card', { provider: row.entry, configured: row.configured, keyConfigured: keyConfiguredOf(row) }, @@ -578,7 +551,7 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS )} {open ? renderProviderEditor({ - target: { ...target, ...editing.initialCredential === undefined ? {} : { initialCredential: editing.initialCredential } }, + target, row, namespace, schema, @@ -725,7 +698,7 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace; renderS