@uns-kit/api 2.0.15 → 2.0.16
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 +11 -0
- package/dist/uns-api-proxy.js +33 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,6 +42,14 @@ async function main() {
|
|
|
42
42
|
api.get("factory/", "status", {
|
|
43
43
|
apiDescription: "Factory status endpoint",
|
|
44
44
|
tags: ["status"],
|
|
45
|
+
queryParams: [
|
|
46
|
+
{ name: "from", type: "string", chatCanonical: "from" },
|
|
47
|
+
{ name: "to", type: "string", chatCanonical: "to" },
|
|
48
|
+
{ name: "limit", type: "number", chatCanonical: "limit", defaultValue: 200 },
|
|
49
|
+
],
|
|
50
|
+
chatDefaults: {
|
|
51
|
+
limit: 200,
|
|
52
|
+
},
|
|
45
53
|
});
|
|
46
54
|
|
|
47
55
|
api.event.on("apiGetEvent", (event) => {
|
|
@@ -52,6 +60,9 @@ async function main() {
|
|
|
52
60
|
void main();
|
|
53
61
|
```
|
|
54
62
|
|
|
63
|
+
`queryParams[].chatCanonical`, `queryParams[].defaultValue`, and `chatDefaults` are optional.
|
|
64
|
+
When provided, they are published into OpenAPI vendor metadata (`x-uns-chat`) so assistant tooling can map canonical chat inputs (`from`, `to`, `limit`, `topic`, ...) to endpoint-specific query parameters.
|
|
65
|
+
|
|
55
66
|
## Scripts
|
|
56
67
|
|
|
57
68
|
```bash
|
package/dist/uns-api-proxy.js
CHANGED
|
@@ -236,18 +236,48 @@ export default class UnsApiProxy extends UnsProxy {
|
|
|
236
236
|
this.app.router.get(fullPath, handler);
|
|
237
237
|
}
|
|
238
238
|
if (this.app.swaggerSpec) {
|
|
239
|
+
const queryParams = options?.queryParams || [];
|
|
240
|
+
const canonicalParams = queryParams.reduce((acc, param) => {
|
|
241
|
+
if (typeof param.chatCanonical === "string" && param.chatCanonical.trim().length) {
|
|
242
|
+
acc[param.chatCanonical.trim()] = param.name;
|
|
243
|
+
}
|
|
244
|
+
return acc;
|
|
245
|
+
}, {});
|
|
246
|
+
const chatDefaults = {};
|
|
247
|
+
for (const param of queryParams) {
|
|
248
|
+
if (param.defaultValue !== undefined) {
|
|
249
|
+
chatDefaults[param.name] = param.defaultValue;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const optionDefaults = options?.chatDefaults ?? {};
|
|
253
|
+
for (const [key, value] of Object.entries(optionDefaults)) {
|
|
254
|
+
if (value !== undefined) {
|
|
255
|
+
chatDefaults[key] = value;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const unsChatMeta = Object.keys(canonicalParams).length || Object.keys(chatDefaults).length
|
|
259
|
+
? {
|
|
260
|
+
canonicalParams,
|
|
261
|
+
defaults: chatDefaults,
|
|
262
|
+
}
|
|
263
|
+
: null;
|
|
239
264
|
this.app.swaggerSpec.paths = this.app.swaggerSpec.paths || {};
|
|
240
|
-
this.app.swaggerSpec.paths[
|
|
265
|
+
this.app.swaggerSpec.paths[apiPath] = {
|
|
241
266
|
get: {
|
|
242
267
|
summary: options?.apiDescription || "No description",
|
|
243
268
|
tags: options?.tags || [],
|
|
244
|
-
parameters:
|
|
269
|
+
parameters: queryParams.map((p) => ({
|
|
245
270
|
name: p.name,
|
|
246
271
|
in: "query",
|
|
247
272
|
required: !!p.required,
|
|
248
|
-
schema: {
|
|
273
|
+
schema: {
|
|
274
|
+
type: p.type,
|
|
275
|
+
...(p.defaultValue !== undefined ? { default: p.defaultValue } : {}),
|
|
276
|
+
},
|
|
249
277
|
description: p.description,
|
|
278
|
+
...(p.chatCanonical ? { "x-uns-chat-canonical": p.chatCanonical } : {}),
|
|
250
279
|
})),
|
|
280
|
+
...(unsChatMeta ? { "x-uns-chat": unsChatMeta } : {}),
|
|
251
281
|
responses: {
|
|
252
282
|
"200": { description: "OK" },
|
|
253
283
|
"400": { description: "Bad Request" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uns-kit/api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Express-powered API gateway plugin for UnsProxyProcess with JWT/JWKS support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"cookie-parser": "^1.4.7",
|
|
36
36
|
"express": "^5.1.0",
|
|
37
37
|
"multer": "^2.0.2",
|
|
38
|
-
"@uns-kit/core": "2.0.
|
|
38
|
+
"@uns-kit/core": "2.0.16"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jsonwebtoken": "^9.0.10",
|