Skip to content

Commit 8032ce8

Browse files
authored
✨ feat: add json schema definition of manifest (#35)
* ✨ feat: generate json schema definition of manifest * 💬 docs: update plugin manifest guide
1 parent eec57eb commit 8032ce8

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ test-output
4646

4747
client.d.ts
4848
client.js
49-
bun.lockb
49+
bun.lockb
50+
schema.json

docs/guides/plugin-manifest.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ manifest 聚合了插件功能如何实现的信息。核心的字段为 `api`
1212

1313
```json
1414
{
15+
"$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json",
1516
"api": [
1617
{
1718
"url": "http://localhost:3400/api/clothes",
@@ -116,3 +117,38 @@ const JSONSchema = z.object({
116117
## API 与 Schema
117118

118119
关于 manifest 各个字段的完整介绍,参见:[manifest](/api/plugin-manifest)
120+
121+
## JSON 类型提示
122+
123+
SDK 提供了 manifest 的 JSON Schema 定义,它可以用于在编写 `manifest.json` 文件时为 IDE 提供类型信息和智能提示。
124+
125+
使用时你只需为 JSON 配置文件声明 `$schema` 字段来指向 schema 定义文件即可,以 [lobehub/chat-plugin-template](https://github.com/lobehub/chat-plugin-template/blob/main/public/manifest-dev.json) 为例,它的项目结构为:
126+
127+
```plaintext
128+
lobehub/chat-plugin-template
129+
├── CHANGELOG.md
130+
├── node_modules
131+
├── README.md
132+
├── src
133+
├── public
134+
│ ├── foo.json
135+
│ ├── manifest-dev.json
136+
│ └── manifest-standalone.json
137+
└── package.json
138+
```
139+
140+
那么 `manifest-dev.json``$schema` 字段可以配置为这样的相对路径:
141+
142+
```json filename=manifest-dev.json
143+
{
144+
"$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json",
145+
"api": [],
146+
"gateway": "http://localhost:3400/api/gateway",
147+
"identifier": "plugin-identifier",
148+
"ui": {
149+
"url": "http://localhost:3400",
150+
"height": 200
151+
},
152+
"version": "1"
153+
}
154+
```

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
"lib",
2929
"es",
3030
"client.d.ts",
31-
"client.js"
31+
"client.js",
32+
"schema.json"
3233
],
3334
"scripts": {
34-
"build": "father build && npm run build:client",
35+
"build": "father build && npm run build:client && npm run build:schema",
3536
"build:client": "tsc client.ts --declaration",
37+
"build:schema": "ts-json-schema-generator --path src/types/manifest.ts --type LobeChatPluginManifest -o schema.json",
3638
"ci": "npm run lint && npm run type-check && npm run doctor",
3739
"dev": "father dev",
3840
"docs:build": "dumi build",
@@ -102,6 +104,7 @@
102104
"remark-cli": "^11",
103105
"semantic-release": "^21",
104106
"stylelint": "^15",
107+
"ts-json-schema-generator": "^1.4.0",
105108
"typescript": "^5",
106109
"vitest": "latest"
107110
},

src/types/manifest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface LobeChatPluginApi {
3434
* @descCN 描述一个插件的构成要素
3535
*/
3636
export interface LobeChatPluginManifest {
37+
$schema?: string;
3738
api: LobeChatPluginApi[];
3839
gateway?: string;
3940
/**
@@ -68,4 +69,5 @@ export interface LobeChatPluginManifest {
6869
url: string;
6970
width?: number;
7071
};
72+
version?: '1';
7173
}

0 commit comments

Comments
 (0)