DeepSeek Harness 插件

准备环境

dsh 从源码运行,见 dsh 说明。或见之前分享的 DeepSeek Harness 开始

开发插件

依照 dsh 文档,动手做一遍:

在 dsh 仓库根目录创建插件目录:

bash 复制代码
mkdir -p start-dsh-plugin/src

start-dsh-plugin/src/index.ts

ts 复制代码
import type { Context } from '@deepseek-ai/cordis'
import { defineTool } from '@deepseek-ai/dsh-tools'
import Schema from '@deepseek-ai/schemastery'

// 插件名称
export const name = 'start-dsh-plugin'
// 注册就绪
//   inject 让 Cordis 等待工具注册表就绪
export const inject = ['tools']

// 插件配置
//   对应 cordis.yml 中 config
export interface Config {
  greeting: string
  maxRetries: number
  verbose?: boolean
}

// Schema 校验
//   在插件加载时执行校验。如果配置不合法,插件会加载失败并给出明确错误信息
export const Config: Schema<Config> = Schema.object({
  greeting: Schema.string().default('Hello'),
  maxRetries: Schema.number().default(3),
  verbose: Schema.boolean().default(false),
})

// 插件实现
//   插件是一个导出 apply 函数的 TypeScript 模块,通过 ctx 注册能力
export function apply(ctx: Context, config: Config) {
  console.log(`[${name}] plugin loaded!`)

  // 注册一个 greet 工具
  ctx.tools.register(defineTool({
    name: 'greet',
    description: 'Greet someone by name.',
    parameters: {
      name: { type: 'string', required: true, description: 'The name to greet' },
    },
    output: {
      schema: { type: 'string' },
      render: (_args, value) => [{ type: 'text', text: value }],
    },
    async execute(args) {
      return `${config.greeting}, ${args.name}!`
    },
  }))
}

start-dsh-plugin/cordis.yml

yml 复制代码
- insert:
    - id: start-dsh-plugin
      name: './src/index.ts'
      config:
        greeting: 'Hi there'
        maxRetries: 5

重新运行 dsh web:

bash 复制代码
pnpm dsh web --patch ./start-dsh-plugin/cordis.yml

对话输入 Use the greet tool to greet Ada.,模型会调用 greet 工具,回复 Hi there, Ada! 👋

打包插件

上述通过 --patch overlay 加载本地插件。

这里再动手打包成组合包(bundle),用 dsh plugin add 来安装。

start-dsh-plugin/package.json

json 复制代码
{
  "name": "start-dsh-plugin",
  "version": "0.1.0",
  "type": "module",
  "main": "src/index.ts",
  "files": ["src/index.ts", "cordis.patch.yml"],
  "dsh": { "bundle": { "patch": "./cordis.patch.yml" } }
}

start-dsh-plugin/cordis.patch.yml

yml 复制代码
- insert:
    - id: start-dsh-plugin
      name: start-dsh-plugin
      config:
        greeting: 'Hi'
        maxRetries: 5

安装进 dsh web:

bash 复制代码
# 从本地安装
pnpm dsh plugin --profile web add ./start-dsh-plugin

# 通过名称移除
pnpm dsh plugin --profile web remove start-dsh-plugin

dsh web 是预装的一个 profile,都位于 $DSH_HOME/profiles/<name>

之后,重新运行 dsh web(web 是 --profile web 的别名):

bash 复制代码
# 查看配置树
pnpm dsh web --dump-config | grep start-dsh-plugin

# 重新运行
pnpm dsh web

发布脚本

要发布,先得补齐再构建:

构建 lib/:

bash 复制代码
cd start-dsh-plugin/

# 在 harness 仓库内构建
pnpm exec tsc -p tsconfig.local.json

# 或,clone 项目安装依赖再构建
pnpm install && pnpm run build
pnpm pack --dry-run

发布 tar:

bash 复制代码
rm -r lib/

# 打包
#  若在 harness 仓库内打包,把 package.json 里改为 "build": "tsc -p tsconfig.local.json"
pnpm pack

# 从 tar 包安装
pnpm dsh plugin --profile web add ./start-dsh-plugin-0.1.0.tgz

发布 npm:

bash 复制代码
pnpm login
pnpm publish --access public

# 从 npm 安装
pnpm dsh plugin --profile web add start-dsh-plugin

发布 github:

bash 复制代码
# 从 github 安装
#  官方文档要让允许从源码构建,但看其他插件就直接 package.json 指向源码、或把 lib/ 上传
pnpm dsh plugin --profile web add github:ikuokuo/start-dsh-plugin

一些问题

该 dsh 工具插件在其最新源码上不能正常启动,报错导入不了 'CallId'。

因其 dsh-tools 版本到了 0.1.2-alpha.1,而 package.json 里用的最新发布只到 "^0.1.1-rc.2"。

需在 harness 仓库内构建或打包,再安装。

哪找插件

相关推荐
charles_he17 分钟前
Agent 写操作超时后,最危险的动作是“再试一次”
人工智能·架构·agent
机械改造鹅20 分钟前
从零开始拆解Pi系列——(6)skills 机制
agent
tachibana227 分钟前
Agent 的长短期记忆系统
人工智能·ai·大模型·llm·agent
prog_610339 分钟前
【笔记】cllama:搜罗万象当LLM api server测qwen3.8:flash-next
笔记·大语言模型·agent·vibe-coding·qwen3.8-flash
特立独行的猫a1 小时前
仓颉语言原生 Coding Agent:cjh · 仓颉语言实现的 Harness
ai·agent·harmonyos·仓颉·cangjie·harness
狂师2 小时前
整理了一份 DeepSeek Harness 必备插件清单!
人工智能·开源·deepseek
沉默王二3 小时前
豆包工作Agent正式发布,直接给到夯。
人工智能·面试·agent
苏灿烤鱼3 小时前
AI总改崩你的代码?4.6万星GitNexus架构深拆
typescript·开源·agent
leeyi3 小时前
Eino + DeepFlux 实战全景复盘:100 篇,从 5 分钟 Demo 到企业级平台(第100篇-E86)
llm·aigc·agent