dsh-apis-plugin 0.1.6 → 0.1.8

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.
Files changed (3) hide show
  1. package/README.md +17 -11
  2. package/client.js +13 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,36 +13,42 @@ dsh plugin --profile web add dsh-apis-plugin
13
13
  安装后重启 `dsh web` 生效。指定版本:
14
14
 
15
15
  ```sh
16
- dsh plugin --profile web add dsh-apis-plugin@0.1.5
16
+ dsh plugin --profile web add dsh-apis-plugin@0.1.6
17
17
  ```
18
18
 
19
19
  ## 配置
20
20
 
21
+ 建议把 `api.cfg` 和 `api_doc.md` 一起放在同一个目录下(如项目的 `config/` 目录),然后在插件配置页把「API配置」指向该目录:
22
+
23
+ ```
24
+ config/
25
+ ├── api.cfg # 接口清单
26
+ └── api_doc.md # 接口文档
27
+ ```
28
+
21
29
  ### 1. api.cfg(接口清单,必需)
22
30
 
23
- 在插件配置页指定的 API 目录下创建 `api.cfg`(key=value 行,`#` 注释,UTF-8 编码):
31
+ key=value 行格式,`#` 注释,UTF-8 编码:
24
32
 
25
33
  ```ini
26
34
  # 接口服务前缀:域名 + nginx 前缀 + 网关路由段
27
35
  baseUrl=http://your-host/prod-api
28
36
 
29
- # 接口列表:逗号分隔同行书写
30
- apis=/users/page,/users/{id}
31
-
32
- # 或逐行列举
37
+ # 接口列表:apis= 下面逐行一个接口
33
38
  apis=
39
+ /users/page
40
+ /users/{id}
34
41
  /outline/page
35
42
  /outline/detailByNos
36
- /basicTargetChar/item/listByTargetCharId
37
43
  ```
38
44
 
39
45
  - `baseUrl`:请求时拼接在接口路径前(改文件即生效,无需重启)
40
46
  - `apis`:接口白名单,支持 `{param}` 模板段(如 `/users/{id}`),agent 请求时填实际值
41
- - **增删接口只改这个文件**,改完点插件配置页的「加载API」(或重启)生效
47
+ - **增删接口只改这个文件**,改完点插件配置页的「扫描」(或重启)生效
42
48
 
43
49
  ### 2. api_doc.md(接口文档,建议提供)
44
50
 
45
- 与 `api.cfg` 同目录。用 `---` 分节,每节描述一个接口,节内用反引号标注接口路径:
51
+ 与 `api.cfg` 放在一起。用 `---` 分节,每节描述一个接口,节内用反引号标注接口路径:
46
52
 
47
53
  ```markdown
48
54
  ## 通用说明
@@ -82,7 +88,7 @@ agent 调用 `{prefix}_api_doc` 时按路径命中对应小节返回。
82
88
  | 操作 | 说明 |
83
89
  |---|---|
84
90
  | API 配置 | 填 api.cfg / api_doc.md 所在目录,**失焦或回车自动保存** |
85
- | 加载API | 重扫目录:接口列表严格等于当前 api.cfg 内容 |
91
+ | 扫描 | 重扫目录:接口列表严格等于当前 api.cfg 内容;**目录留空点击则清空列表** |
86
92
  | 接口列表 | 只读展示,增删请在 api.cfg 中操作 |
87
93
 
88
94
  ### Agent 工具
@@ -105,7 +111,7 @@ dsh 控制台日志:
105
111
  ```
106
112
 
107
113
  - `endpoints=0`:检查 API 目录路径是否正确、api.cfg 是否与目录同级
108
- - 加载后列表与 api.cfg 不一致:确认已在配置页点过「加载API」
114
+ - 加载后列表与 api.cfg 不一致:确认已在配置页点过「扫描」
109
115
  - 提示未配置 baseUrl:在 api.cfg 写入 `baseUrl=http://...`
110
116
 
111
117
  ## License
package/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // 浏览器半侧:在「插件配置」标签页为 dsh-apis-plugin 命名空间注册一张展示卡片
2
- // 接口的增删以 api.cfg 为唯一来源:这里只读展示列表,编辑请改 api.cfg 后点「加载API」重扫
3
- // API 目录失焦或点「加载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); // 加载API 扫描中
85
- const [loaded, setLoaded] = react.useState(false); // 加载API 完成后短暂提示
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
- /** 目录失焦时自动保存(点「加载API」也会先写入目录) */
96
+ /** 目录失焦时自动保存(点「扫描」也会先写入目录) */
97
97
  function commitDir() {
98
98
  if (dirDirty && ready) scope.set("apiDir", dirDraft);
99
99
  setDirDraft(null);
100
100
  }
101
101
 
102
- /** 加载API:把目录写入配置并翻转 scanToken,服务端 watch 重扫 apis.txt 后回写接口列表 */
102
+ /** 扫描:把目录写入配置并翻转 scanToken,服务端重扫 api.cfg 后回写接口列表;目录为空则清空列表 */
103
103
  async function loadApis() {
104
- if (loading || !ready || !shownDir.trim()) return;
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 所在目录,失焦自动保存)+ 加载API 重扫按钮
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 || !shownDir.trim(),
158
+ type: "button", disabled: !ready || loading,
159
159
  onClick: loadApis,
160
- className: "apis-btn apis-discard", children: loading ? "扫描中…" : "加载API",
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,然后点击「加载API」" }),
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-apis-plugin",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "通用接口管理插件:把任意一套 HTTP 接口注册成 agent 可用的文档查询与请求双工具",
5
5
  "type": "module",
6
6
  "license": "MIT",