dsh-apis-plugin 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/api-tools.js +2 -2
- package/client.js +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ apis=
|
|
|
44
44
|
|
|
45
45
|
- `baseUrl`:请求时拼接在接口路径前(改文件即生效,无需重启)
|
|
46
46
|
- `apis`:接口白名单,支持 `{param}` 模板段(如 `/users/{id}`),agent 请求时填实际值
|
|
47
|
-
-
|
|
47
|
+
- **增删接口只改这个文件**,改完点插件配置页的「扫描」(或重启)生效
|
|
48
48
|
|
|
49
49
|
### 2. api_doc.md(接口文档,建议提供)
|
|
50
50
|
|
|
@@ -67,6 +67,8 @@ apis=
|
|
|
67
67
|
|
|
68
68
|
agent 调用 `{prefix}_api_doc` 时按路径命中对应小节返回。
|
|
69
69
|
|
|
70
|
+
💡 建议:在「通用说明」里注明 *“本文档与线上服务一一对应,以此为准”*,并写清字段语义(如 `status=0 编辑中,1 待审核`)——工具描述已声明文档为权威依据,写清楚后 agent 会直接按文档调用,不会再去翻后端源码核实。
|
|
71
|
+
|
|
70
72
|
### 3. 部署侧 cordis.patch.yml(可选覆盖)
|
|
71
73
|
|
|
72
74
|
```yaml
|
|
@@ -88,7 +90,7 @@ agent 调用 `{prefix}_api_doc` 时按路径命中对应小节返回。
|
|
|
88
90
|
| 操作 | 说明 |
|
|
89
91
|
|---|---|
|
|
90
92
|
| API 配置 | 填 api.cfg / api_doc.md 所在目录,**失焦或回车自动保存** |
|
|
91
|
-
|
|
|
93
|
+
| 扫描 | 重扫目录:接口列表严格等于当前 api.cfg 内容;**目录留空点击则清空列表** |
|
|
92
94
|
| 接口列表 | 只读展示,增删请在 api.cfg 中操作 |
|
|
93
95
|
|
|
94
96
|
### Agent 工具
|
|
@@ -111,7 +113,7 @@ dsh 控制台日志:
|
|
|
111
113
|
```
|
|
112
114
|
|
|
113
115
|
- `endpoints=0`:检查 API 目录路径是否正确、api.cfg 是否与目录同级
|
|
114
|
-
- 加载后列表与 api.cfg
|
|
116
|
+
- 加载后列表与 api.cfg 不一致:确认已在配置页点过「扫描」
|
|
115
117
|
- 提示未配置 baseUrl:在 api.cfg 写入 `baseUrl=http://...`
|
|
116
118
|
|
|
117
119
|
## License
|
package/api-tools.js
CHANGED
|
@@ -167,7 +167,7 @@ export function defineApiPlugin(options) {
|
|
|
167
167
|
// 工具 1:查接口文档,让模型了解每个接口的参数与响应(prompt 按领域名拼接)
|
|
168
168
|
ctx.tools.register({
|
|
169
169
|
name: `${prefix}_api_doc`,
|
|
170
|
-
description: `查询${domainName}
|
|
170
|
+
description: `查询${domainName}接口文档。api_doc.md 与部署的服务一一对应,是这些接口的权威依据。传 path(如 /users/page)返回该接口的详细参数与响应说明;不传 path 返回通用说明和全部已配置接口目录。发起请求前先用它确认参数,按文档直接调用即可,不要再去查阅后端源码或其他材料核实接口行为。`,
|
|
171
171
|
parameters: {
|
|
172
172
|
path: { type: 'string', description: '接口路径,如 /users/{id}' },
|
|
173
173
|
},
|
|
@@ -187,7 +187,7 @@ export function defineApiPlugin(options) {
|
|
|
187
187
|
// 工具 2:真正调用接口拿数据(prompt 按领域名拼接)
|
|
188
188
|
ctx.tools.register({
|
|
189
189
|
name: `${prefix}_api_request`,
|
|
190
|
-
description: `调用${domainName}接口并返回 JSON 数据。path 必须是已配置的接口(支持 /orders/{id} 这类模板路径,模板段填实际值);GET 用 query 传参,POST 用 body 传 JSON
|
|
190
|
+
description: `调用${domainName}接口并返回 JSON 数据。path 必须是已配置的接口(支持 /orders/{id} 这类模板路径,模板段填实际值);GET 用 query 传参,POST 用 body 传 JSON。请依据 ${prefix}_api_doc 返回的文档构造请求,文档即权威,无需从源码核实接口行为。`,
|
|
191
191
|
parameters: {
|
|
192
192
|
path: { type: 'string', required: true, description: '接口路径,如 /users/detail 或 /orders/123' },
|
|
193
193
|
method: { type: 'string', description: 'HTTP 方法,默认 GET' },
|
package/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 浏览器半侧:在「插件配置」标签页为 dsh-apis-plugin 命名空间注册一张展示卡片
|
|
2
|
-
// 接口的增删以 api.cfg 为唯一来源:这里只读展示列表,编辑请改 api.cfg
|
|
3
|
-
// API
|
|
2
|
+
// 接口的增删以 api.cfg 为唯一来源:这里只读展示列表,编辑请改 api.cfg 后点「扫描」重扫
|
|
3
|
+
// API 目录失焦或点「扫描」时自动保存,无页脚按钮
|
|
4
4
|
// 样式与 DOM 结构对齐原生 PluginCard(li 卡片 + SVG 箭头)
|
|
5
5
|
window.__ModuleLoader__.load({
|
|
6
6
|
id: "dsh-apis-plugin",
|
|
@@ -81,8 +81,8 @@ window.__ModuleLoader__.load({
|
|
|
81
81
|
function ApisCard(props) {
|
|
82
82
|
const state = props.useApisCard((s) => s);
|
|
83
83
|
const [dirDraft, setDirDraft] = react.useState(null); // 文档目录,null 表示未编辑
|
|
84
|
-
const [loading, setLoading] = react.useState(false); //
|
|
85
|
-
const [loaded, setLoaded] = react.useState(false); //
|
|
84
|
+
const [loading, setLoading] = react.useState(false); // 扫描进行中
|
|
85
|
+
const [loaded, setLoaded] = react.useState(false); // 扫描完成后短暂提示
|
|
86
86
|
const [open, setOpen] = react.useState(false); // 折叠态只显示标题行
|
|
87
87
|
const ready = state.status === "ready" && state.writable;
|
|
88
88
|
|
|
@@ -93,15 +93,15 @@ window.__ModuleLoader__.load({
|
|
|
93
93
|
const shownDir = dirDraft ?? savedDir;
|
|
94
94
|
const dirDirty = dirDraft !== null && dirDraft !== savedDir;
|
|
95
95
|
|
|
96
|
-
/**
|
|
96
|
+
/** 目录失焦时自动保存(点「扫描」也会先写入目录) */
|
|
97
97
|
function commitDir() {
|
|
98
98
|
if (dirDirty && ready) scope.set("apiDir", dirDraft);
|
|
99
99
|
setDirDraft(null);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/**
|
|
102
|
+
/** 扫描:把目录写入配置并翻转 scanToken,服务端重扫 api.cfg 后回写接口列表;目录为空则清空列表 */
|
|
103
103
|
async function loadApis() {
|
|
104
|
-
if (loading || !ready
|
|
104
|
+
if (loading || !ready) return;
|
|
105
105
|
setLoading(true);
|
|
106
106
|
try {
|
|
107
107
|
if (dirDirty) await scope.set("apiDir", shownDir.trim());
|
|
@@ -143,7 +143,7 @@ window.__ModuleLoader__.load({
|
|
|
143
143
|
}),
|
|
144
144
|
// 展开体:API配置目录行 + 分隔线 + 接口行列表(只读)
|
|
145
145
|
open && react_jsx_runtime.jsxs("div", { className: "apis-body", children: [
|
|
146
|
-
// API配置:文档目录(api.cfg / api_doc.md 所在目录,失焦自动保存)+
|
|
146
|
+
// API配置:文档目录(api.cfg / api_doc.md 所在目录,失焦自动保存)+ 扫描按钮(目录为空则清空列表)
|
|
147
147
|
react_jsx_runtime.jsxs("div", { className: "apis-row", children: [
|
|
148
148
|
react_jsx_runtime.jsx("div", { className: "apis-rowLabel apis-rowLabelWide", children: "API配置" }),
|
|
149
149
|
react_jsx_runtime.jsx("input", {
|
|
@@ -151,19 +151,19 @@ window.__ModuleLoader__.load({
|
|
|
151
151
|
onChange: (e) => setDirDraft(e.target.value),
|
|
152
152
|
onBlur: commitDir,
|
|
153
153
|
onKeyDown: (e) => { if (e.key === "Enter") e.currentTarget.blur(); },
|
|
154
|
-
placeholder: "api.cfg / api_doc.md
|
|
154
|
+
placeholder: "api.cfg / api_doc.md 所在目录,留空扫描即清空列表",
|
|
155
155
|
className: "apis-input",
|
|
156
156
|
}),
|
|
157
157
|
react_jsx_runtime.jsx("button", {
|
|
158
|
-
type: "button", disabled: !ready || loading
|
|
158
|
+
type: "button", disabled: !ready || loading,
|
|
159
159
|
onClick: loadApis,
|
|
160
|
-
className: "apis-btn apis-discard", children: loading ? "扫描中…" : "
|
|
160
|
+
className: "apis-btn apis-discard", children: loading ? "扫描中…" : "扫描",
|
|
161
161
|
}),
|
|
162
|
-
loaded && react_jsx_runtime.jsx("span", { className: "apis-saved", children: "
|
|
162
|
+
loaded && react_jsx_runtime.jsx("span", { className: "apis-saved", children: "已扫描" }),
|
|
163
163
|
] }),
|
|
164
164
|
react_jsx_runtime.jsx("hr", { className: "apis-hr" }),
|
|
165
165
|
!state.writable && react_jsx_runtime.jsx("span", { className: "apis-description", children: "只读" }),
|
|
166
|
-
list.length ? list.map(row) : react_jsx_runtime.jsx("span", { className: "apis-empty", children: "暂无接口:请在 API 目录下的 api.cfg 中配置 apis
|
|
166
|
+
list.length ? list.map(row) : react_jsx_runtime.jsx("span", { className: "apis-empty", children: "暂无接口:请在 API 目录下的 api.cfg 中配置 apis,然后点击「扫描」" }),
|
|
167
167
|
] }),
|
|
168
168
|
],
|
|
169
169
|
});
|