dsh-apis-plugin 0.1.10 → 0.1.11
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/api-tools.js +16 -6
- package/package.json +1 -1
package/api-tools.js
CHANGED
|
@@ -164,6 +164,9 @@ export function defineApiPlugin(options) {
|
|
|
164
164
|
return bootEndpoints
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
// 删除操作的待确认记录(key: "DELETE <完整地址>"):只有先收到过确认提示,confirm=true 才会放行
|
|
168
|
+
const pendingDeletes = new Set()
|
|
169
|
+
|
|
167
170
|
// 工具 1:查接口文档,让模型了解每个接口的参数与响应(prompt 按领域名拼接)
|
|
168
171
|
ctx.tools.register({
|
|
169
172
|
name: `${prefix}_api_doc`,
|
|
@@ -191,13 +194,13 @@ export function defineApiPlugin(options) {
|
|
|
191
194
|
// 工具 2:真正调用接口拿数据(prompt 按领域名拼接)
|
|
192
195
|
ctx.tools.register({
|
|
193
196
|
name: `${prefix}_api_request`,
|
|
194
|
-
description: `调用${domainName}接口并返回 JSON 数据。path 必须是已配置的接口(支持 /orders/{id} 这类模板路径,模板段填实际值);GET 用 query 传参,POST 用 body 传 JSON
|
|
197
|
+
description: `调用${domainName}接口并返回 JSON 数据。path 必须是已配置的接口(支持 /orders/{id} 这类模板路径,模板段填实际值);GET 用 query 传参,POST 用 body 传 JSON。安全规则:① DELETE 属于危险操作,首次调用只返回确认提示不会执行,必须先向用户二次确认,用户明确同意后才能携带 confirm=true 再次调用;② 返回结果若以 ⚠️ 开头(写操作警告/危险操作确认),必须在回复中原样向用户展示警告块内容(含接口、方法、完整地址与参数),不得省略、转述或只报结果。请依据 ${prefix}_api_doc 返回的文档构造请求,文档即权威,无需从源码核实接口行为。`,
|
|
195
198
|
parameters: {
|
|
196
199
|
path: { type: 'string', required: true, description: '接口路径,如 /users/detail 或 /orders/123' },
|
|
197
200
|
method: { type: 'string', description: 'HTTP 方法,默认 GET' },
|
|
198
201
|
query: { type: 'json', description: 'query 参数对象,如 { "keyword": "abc" }' },
|
|
199
202
|
body: { type: 'json', description: 'POST 请求体(JSON 对象)' },
|
|
200
|
-
confirm: { type: 'boolean', description: '
|
|
203
|
+
confirm: { type: 'boolean', description: '删除操作的二次确认标记:仅在与用户确认且收到过确认提示后才能传 true;未经确认提示不得传' },
|
|
201
204
|
},
|
|
202
205
|
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] },
|
|
203
206
|
async execute(args) {
|
|
@@ -220,10 +223,17 @@ export function defineApiPlugin(options) {
|
|
|
220
223
|
url.searchParams.set(k, String(v))
|
|
221
224
|
}
|
|
222
225
|
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
// 删除操作:两段式确认。首次调用只返回确认提示并记录待确认项;
|
|
227
|
+
// 即使模型首次就带 confirm=true,只要没有对应的待确认记录也一律拒绝执行
|
|
228
|
+
if (method === 'DELETE') {
|
|
229
|
+
const key = method + ' ' + url.toString()
|
|
230
|
+
if (args.confirm === true && pendingDeletes.has(key)) {
|
|
231
|
+
pendingDeletes.delete(key)
|
|
232
|
+
} else {
|
|
233
|
+
pendingDeletes.add(key)
|
|
234
|
+
return `⚠️【危险操作确认】本次将执行删除接口:\n ${method} ${url.toString()}\n` +
|
|
235
|
+
'该操作可能不可恢复。请先向用户二次确认;用户同意后,携带 confirm=true 重新调用本工具才会真正执行。'
|
|
236
|
+
}
|
|
227
237
|
}
|
|
228
238
|
|
|
229
239
|
// 写操作:在结果前向用户明示将执行哪个接口
|