website: wire the site into the repo gates; make every tutorial example compile

- website joins the pnpm workspace; root scripts website:dev/website:build;
  run-gates gains a website-build gate (ci-primary + ci-static) — the
  VitePress build doubles as the site's dead-link check; AGENTS.md documents
  the commands.
- doc-typecheck + verify-type-equiv now scan website/zh-CN/**/*.md; every
  ```typescript fence converted to ```ts and made standalone-compilable
  (55 compiled, 1 ignore-check). Phantom APIs the compiler caught are fixed:
  invented event names (agent/turn-end, tool/call, llm/pre-request, ready,
  dispose) replaced with real catalog events or per-plugin declare-module
  merges; presentCall/inject/Config claims corrected to the real shapes.
- guide/config.md entry-fields table completed against loader EntryOptions;
  its coding-agent example brought in line with examples/coding-agent.
This commit is contained in:
lintianle
2026-07-16 18:12:22 +08:00
parent 4ce98cbab3
commit 6ce9f16030
21 changed files with 1949 additions and 227 deletions
+30 -15
View File
@@ -6,7 +6,7 @@
在 Harness 中,插件是一个导出 `apply` 函数的 TypeScript 模块。框架在加载时调用 `apply`,传入一个 `ctx`(上下文对象),你通过 `ctx` 注册能力:
```typescript
```ts
import type { Context } from 'cordis'
export const name = 'my-plugin'
@@ -22,16 +22,14 @@ export function apply(ctx: Context) {
在你的项目目录下创建 `src/my-plugin.ts`:
```typescript
```ts
import type { Context } from 'cordis'
export const name = 'hello-plugin'
export function apply(ctx: Context) {
// 监听 agent-loop 的 ready 事件
ctx.on('ready', () => {
console.log('[hello-plugin] 插件已加载!')
})
// apply 函数体在插件加载时执行
console.log('[hello-plugin] 插件已加载!')
}
```
@@ -52,7 +50,9 @@ export function apply(ctx: Context) {
如果你有需要手动清理的资源(比如一个网络连接),用 `ctx.effect()` 告诉框架怎么清理:
```typescript
```ts
import type { Context } from 'cordis'
export function apply(ctx: Context) {
ctx.effect(() => {
const timer = setInterval(() => {
@@ -69,13 +69,23 @@ export function apply(ctx: Context) {
如果你的插件需要使用其他服务(如 `tools`、`llm`),需要声明 `inject`:
```typescript
```ts
import type { Context } from 'cordis'
import { defineTool } from '@deepseek-ai/dsh-tools'
export const name = 'my-tool-plugin'
export const inject = ['tools']
export function apply(ctx: Context) {
// ctx.tools 现在可用
ctx.tools.register(/* ... */)
ctx.tools.register(defineTool({
name: 'demo',
description: 'Demo tool.',
parameters: {},
async execute() {
return []
},
}))
}
```
@@ -87,7 +97,10 @@ export function apply(ctx: Context) {
### 对象形式
```typescript
```ts
import type { Context } from 'cordis'
import type {} from '@deepseek-ai/dsh-tools'
export default {
name: 'my-plugin',
inject: ['tools'],
@@ -99,8 +112,9 @@ export default {
### 类形式
```typescript
import { Service } from 'cordis'
```ts
import { Service, type Context } from 'cordis'
import type {} from '@deepseek-ai/dsh-tools'
export default class MyService extends Service {
static inject = ['tools']
@@ -109,8 +123,9 @@ export default class MyService extends Service {
super(ctx, 'myService')
}
start() {
// 服务启动逻辑
// 服务的公开方法
greet(name: string) {
return `Hello, ${name}!`
}
}
```
@@ -121,7 +136,7 @@ export default class MyService extends Service {
参考仓库中的 `examples/echo-agent/src/echo-tool.ts`,这是一个注册 tool 的插件:
```typescript
```ts
import type { Context } from 'cordis'
import { defineTool } from '@deepseek-ai/dsh-tools'