Revert "fix(settings): show saved API keys and preserve environment detection…"

This reverts commit 9bb49604b63bb5d50e879bcf63c9f5cb2afbd737.
This commit is contained in:
imccyu authored and GitHub committed 2026-11-03 12:33:44 +08:00
1 parent e4ac64c9c7
commit 06bf7ce024
60 files changed
+148 -853

No files matched your search

@@ -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
+2 -2
View File
@@ -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`.
@@ -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`。
@@ -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<string | undefined> {
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.
@@ -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 }
}
@@ -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<CredentialInfo> {
@@ -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* <In>(): AsyncGenerator<In> {},
}
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)