dsh-apis-plugin 0.2.1 → 0.2.2
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 +4 -0
- package/api-tools.js +5 -5
- package/client.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,9 @@ key=value 行格式,`#` 注释,UTF-8 编码:
|
|
|
40
40
|
# 集合标识(如网站域名),用于展示与「集合名/路径」消歧
|
|
41
41
|
host=site-a.example.com
|
|
42
42
|
|
|
43
|
+
# 集合用途说明(可选),会展示在接口目录与手风琴中,方便 AI 理解查询范围
|
|
44
|
+
title=智能标定业务系统
|
|
45
|
+
|
|
43
46
|
# 该集合的接口服务前缀:域名 + nginx 前缀 + 网关路由段
|
|
44
47
|
baseUrl=http://your-host/api
|
|
45
48
|
|
|
@@ -50,6 +53,7 @@ apis=
|
|
|
50
53
|
```
|
|
51
54
|
|
|
52
55
|
- `host`:集合名,缺失时依次回退 baseUrl 的主机名、文件所在文件夹名
|
|
56
|
+
- `title`:集合用途说明(可选),AI 查目录与 UI 手风琴均会展示
|
|
53
57
|
- `baseUrl`:请求时拼接在该集合的接口路径前(改文件即生效,无需重启)
|
|
54
58
|
- `apis`:该集合的接口白名单,支持 `{param}` 模板段(如 `/users/{id}`),agent 请求时填实际值
|
|
55
59
|
- **增删接口只改这个文件**,改完点插件配置页的「扫描」(或重启)生效
|
package/api-tools.js
CHANGED
|
@@ -40,7 +40,7 @@ function scanCollections(dir) {
|
|
|
40
40
|
}
|
|
41
41
|
const push = (file) => {
|
|
42
42
|
const cfg = loadCfgFile(file)
|
|
43
|
-
if (cfg.apis.length) out.push({ name: cfg.host || hostFromUrl(cfg.baseUrl) || basename(dirname(file)), file, dir: dirname(file), baseUrl: cfg.baseUrl || '', apis: cfg.apis })
|
|
43
|
+
if (cfg.apis.length) out.push({ name: cfg.host || hostFromUrl(cfg.baseUrl) || basename(dirname(file)), title: cfg.title || '', file, dir: dirname(file), baseUrl: cfg.baseUrl || '', apis: cfg.apis })
|
|
44
44
|
}
|
|
45
45
|
try {
|
|
46
46
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -132,7 +132,7 @@ export function defineApiPlugin(options) {
|
|
|
132
132
|
// 部署侧静态接口(yml config.endpoints + 工厂默认),与 cfg 动态读取分离,避免重扫时把旧列表拼回去
|
|
133
133
|
const staticEndpoints = [...new Set([...defaultEndpoints, ...(config.endpoints ?? [])])]
|
|
134
134
|
// 集合持久化为 JSON(客户端只读展示;文档分节不落盘)
|
|
135
|
-
const plain = (cs) => JSON.stringify(cs.map(({ name, baseUrl, apis }) => ({ name, baseUrl, apis })))
|
|
135
|
+
const plain = (cs) => JSON.stringify(cs.map(({ name, title, baseUrl, apis }) => ({ name, title, baseUrl, apis })))
|
|
136
136
|
const mergedEndpoints = (cs) => [...new Set([...cs.flatMap((c) => c.apis), ...staticEndpoints])]
|
|
137
137
|
|
|
138
138
|
const bootCollections = loadCollections(ymlApiDir)
|
|
@@ -168,10 +168,10 @@ export function defineApiPlugin(options) {
|
|
|
168
168
|
`${ns}: settings watch`,
|
|
169
169
|
)
|
|
170
170
|
|
|
171
|
-
//
|
|
171
|
+
// 已配置接口目录(按集合分组展示,title 说明集合用途;部署侧静态接口不在任何集合时单独一组)
|
|
172
172
|
function catalogText() {
|
|
173
173
|
const groups = collections.map((c) =>
|
|
174
|
-
`【${c.name}】${c.baseUrl ? `(baseUrl: ${c.baseUrl})` : ''}\n` + c.apis.map((e) => ' ' + e).join('\n'))
|
|
174
|
+
`【${c.name}】${c.title ? `(${c.title})` : ''}${c.baseUrl ? `(baseUrl: ${c.baseUrl})` : ''}\n` + c.apis.map((e) => ' ' + e).join('\n'))
|
|
175
175
|
const dyn = new Set(collections.flatMap((c) => c.apis))
|
|
176
176
|
const extra = staticEndpoints.filter((e) => !dyn.has(e))
|
|
177
177
|
if (extra.length) groups.push('【部署侧固定接口】\n' + extra.map((e) => ' ' + e).join('\n'))
|
|
@@ -210,7 +210,7 @@ export function defineApiPlugin(options) {
|
|
|
210
210
|
// 工具 1:查接口文档,让模型了解每个接口的参数与响应(prompt 按领域名拼接)
|
|
211
211
|
ctx.tools.register({
|
|
212
212
|
name: `${prefix}_api_doc`,
|
|
213
|
-
description: `查询${domainName}接口文档。接口按集合组织(集合名取各 cfg 文件的 host
|
|
213
|
+
description: `查询${domainName}接口文档。接口按集合组织(集合名取各 cfg 文件的 host 字段,cfg 的 title 字段标注该集合用途),api_doc.md 与部署的服务一一对应,是这些接口的权威依据。传 path(如 /users/page,跨集合同名接口用「集合名/路径」如 site-a.com/users/page)返回该接口的详细参数与响应说明;不传 path 返回通用说明和全部集合的接口目录。发起请求前先用它确认参数,按文档直接调用即可,不要再去查阅后端源码或其他材料核实接口行为。`,
|
|
214
214
|
parameters: {
|
|
215
215
|
path: { type: 'string', description: '接口路径,如 /users/{id};跨集合同名时用 集合名/路径' },
|
|
216
216
|
},
|
package/client.js
CHANGED
|
@@ -114,7 +114,10 @@ window.__ModuleLoader__.load({
|
|
|
114
114
|
onClick: () => setOpenGroups((m) => ({ ...m, [g.name]: !m[g.name] })),
|
|
115
115
|
children: [
|
|
116
116
|
jsx(Chevron, { open: isOpen }),
|
|
117
|
-
|
|
117
|
+
jsxs("div", { className: "apis-headText", children: [
|
|
118
|
+
jsx("span", { className: "apis-groupName", title: g.name, children: g.name }),
|
|
119
|
+
g.title && jsx("span", { className: "apis-desc", children: g.title }),
|
|
120
|
+
] }),
|
|
118
121
|
jsx("span", { className: "apis-count", children: `${apis.length} 个接口` }),
|
|
119
122
|
],
|
|
120
123
|
}),
|