openplancc/dsh-fuse

前言

DeepSeek Harness (DSH) 的核心设计理念是「一切皆插件」。在多代理开发场景下,成本控制是刚需。openplancc/dsh-fuse 是一个专注于成本策略的插件。它提供每次调用的计费功能,以及一个离线的 fuse 机制:在 token 被消耗前,强制执行预算、模型和推理努力限制。

核心功能

该插件具备以下能力:

  1. 多代理成本策略:支持在多代理环境下的成本管控。
  2. 每次调用计费:精确到每一次调用的计量。
  3. 离线 Fuse:在本地强制执行预算、模型和推理努力限制,响应时间通常小于 100ms。
  4. SaaS 仪表板同步:与 https://dsh.openplan.cc 同步数据,展示组织、项目和个人的支出情况。
  5. 零原生构建:使用 @libsql/client 作为本地存储,无需编译即可分发(需要 Node >= 20)。
  6. 设备流认证:默认使用设备流(RFC 8628)进行用户认证。
  7. 状态查询工具:提供 dsh_budget_status 工具,允许模型在运行时读取策略状态。

安装与启用

插件通过 dsh.bundle 声明来激活。安装时,DSH 会读取该声明并加载插件层。

通过注册表安装(推荐):

dsh plugin --profile <perfil> add @openplan/dsh-fuse

通过本地 tarball 安装:

pnpm pack
dsh plugin --profile <perfil> add ./openplan-dsh-fuse-<versão>.tgz

通过 Git 安装:

dsh plugin --profile <perfil> add github:<org>/<repo>#<sha>

配置

插件默认工作在本地模式。要启用 SaaS 同步或自定义策略,需要编辑 profile 目录下的 cordis.patch.yml 文件。该配置层位于 bundle 层之上。

配置结构如下:

# ~/.dsh/profiles/<perfil>/cordis.patch.yml
- id: fuse
  name: '@openplan/dsh-fuse'
  config:
    project: meu-projeto
    dev: eu@empresa.com
    # 机器/CI 环境,无浏览器时使用
    orgKey: !!js process.env.DSH_ORG_KEY
    baseUrl: https://dsh-api.openplan.cc
    # 本地预算(Fuse 在离线时强制执行):
    budgets:
      - limitUsd: 50
        window: month
      - limitUsd: 5
        window: day
    # 策略限制:
    policies:
      maxReasoningEffort: medium
      allowedModels:
        - deepseek/deepseek-v4-flash
      denylistedProjects:
        - projeto-cliente-confidencial
    # 价格配置(可选,默认从 registry/gateway 自动解析):
    pricingTable:
      deepseek/deepseek-v4.1-flash:
        inputCentsPerM: 15
        outputCentsPerM: 60
    # 未定价模型的兜底价格(防止费用为 0):
    unpricedFallback:
      inputCentsPerM: 15
      outputCentsPerM: 60

认证方式

  • 设备流(默认):人类用户连接时,运行以下命令:
    dsh plugin --profile <perfil> exec dsh-fuse-connect
此过程会打开浏览器进行授权,Token 保存为只读权限,且可随时在仪表板撤销。
  • Org Key:无头环境或 CI 中,通过环境变量 DSH_ORG_KEY 传入。

价格解析逻辑

插件自动从注册表(models.dev)或网关获取价格,并按以下顺序解析模型价格:
1. pricingAliases 中的显式映射。
2. 本地配置的 pricingTable。
3. Registry 或 Gateway 中的 provider/model 路由价格。
4. Adapter ID 本身。
5. 逐步移除前缀的后备匹配。

如果模型无定价,插件会标记为 unpriced 并记录日志,除非设置了 unpricedFallback。

使用

安装并配置后,可以通过以下命令进行操作:

连接到仪表板:

dsh plugin --profile <perfil> exec dsh-fuse-connect

检查配置层(无需启动 Harness):

dsh --profile <perfil> --dump-config

Agent 状态查询:
当 @deepseek-ai/dsh-tools 服务启动时,插件会注册 dsh_budget_status 工具。模型可以在会话中查询当前预算状态、已用额度及远程 429 限制,以便自适应调整策略。可以通过 budgetStatusTool: false 禁用此工具。

注意事项

  • 环境要求:需要 Node.js >= 20。
  • 本地模式:如果不配置 baseUrl 或 orgKey,插件将在本地模式运行,不与 SaaS 同步,仅依赖本地 Fuse 限制。
  • 权限:插件以当前 DSH 进程权限运行,安装前建议检查源码与许可证(MIT)。
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜