@fuxi-ailabs/dsh-provider-auth
v1.1.0
Published
Shared provider/auth resolver for DSH plugins: explicit config, environment variables, and DSH credentials
Readme
@fuxi-ailabs/dsh-provider-auth
DSH 插件共享的 provider/auth resolver。它不直接调用模型,也不保存密钥;只把
“某个消费者应该用哪一组 baseUrl / apiKey / model”按统一优先级解析出来。
为什么单独拆插件
dsh-insight 的评分能力已经有一份 显式配置 → 环境变量 → DSH credentials 的解析逻辑。dsh-audit
需要同样一套规则,但协议和默认值不同:
dsh-insight评分:OpenAI-compatible,默认https://api.deepseek.comdsh-audit:Anthropic Messages,默认https://api.deepseek.com/anthropic
共享 resolver 只负责“从哪拿”,协议映射和探活仍留在各自插件。
服务
插件向宿主提供:
ctx.provide('providerAuth', service)消费方软取:
const auth = ctx.get('providerAuth')resolve(request)
const resolved = await auth.resolve({
id: 'sift',
protocol: 'anthropic-messages',
explicit: { baseUrl, apiKey, model },
env: {
baseUrl: ['DSH_SIFT_BASE_URL', 'ANTHROPIC_BASE_URL'],
apiKey: ['DSH_SIFT_AUTH_TOKEN', 'ANTHROPIC_AUTH_TOKEN'],
model: ['DSH_SIFT_MODEL', 'ANTHROPIC_MODEL'],
},
dsh: {
apiKeyRef: 'DEEPSEEK_API_KEY',
baseUrl: 'https://api.deepseek.com/anthropic',
model: 'deepseek-chat',
},
})优先级:
显式配置
> 环境变量
> DSH credentialsdescribe(request)
返回不包含密钥的状态:
{
configured: true,
source: 'dsh-credentials',
sourceDetail: 'DSH credentials DEEPSEEK_API_KEY (file)',
maskedKey: 'sk-d…6789',
note: '来源:DSH credentials DEEPSEEK_API_KEY (file)',
skipped: []
}供 /score --probe-provider 和后续独立的环境检查插件使用。
mask(secret)
默认保留前 4 位和后 4 位;短 key 直接返回 ****。
配置
- id: dsh-provider-auth
name: '@fuxi-ailabs/dsh-provider-auth'
config:
allowDshCredentials: true
maskHead: 4
maskTail: 4
providers:
anthropic-messages:
baseUrl: https://api.deepseek.com/anthropic
model: deepseek-chat
apiKeyRef: DEEPSEEK_API_KEY
openai-chat:
baseUrl: https://api.deepseek.com
model: deepseek-chat
apiKeyRef: DEEPSEEK_API_KEY消费插件可以只传协议,不再重复写 endpoint/model/key 引用:
providerAuth.resolve({
id: 'sift',
protocol: 'anthropic-messages',
})解析优先级:
显式请求配置
> 环境变量
> providerAuth providers[protocol]
> 消费方传入的 DSH 兼容模板边界
- 不保存密钥;密钥来自配置、环境变量或 DSH
credentials服务 - 不缓存密钥;每次
resolve()现取现用 - 不做协议转换
- 不负责模型探活
- 不向 client 暴露 secret
- 不是
dsh-insight评分能力 /dsh-audit的硬依赖;两个消费方应在服务缺席时保留自己的 fallback
开发
npm install
npm test
npm run typecheck
npm run pack