本教程会在 Web UI 中添加一个 greet 工具。请先完成第一个插件,并保留其中的 scratch-plugin 目录。
创建工具插件
将 scratch-plugin/src/my-plugin.ts 替换为:
importtype{Context}from'@deepseek-ai/cordis'import{defineTool}from'@deepseek-ai/dsh-tools'exportconstname='greet-tool'exportconstinject=['tools']exportfunctionapply(ctx: Context){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}],},asyncexecute(args){return`Hello, ${args.name}!`},}))}