@kevisual/router 0.0.75 → 0.0.76

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/dist/app.js CHANGED
@@ -16824,7 +16824,6 @@ class Route {
16824
16824
  metadata;
16825
16825
  middleware;
16826
16826
  type = "route";
16827
- data;
16828
16827
  isDebug;
16829
16828
  constructor(path = "", key = "", opts) {
16830
16829
  if (!path) {
@@ -16916,22 +16915,21 @@ class Route {
16916
16915
  addTo(router, opts) {
16917
16916
  router.add(this, opts);
16918
16917
  }
16919
- setData(data) {
16920
- this.data = data;
16921
- return this;
16922
- }
16923
16918
  throw(...args) {
16924
16919
  throw new CustomError(...args);
16925
16920
  }
16926
16921
  }
16922
+ var extractArgs = (args) => {
16923
+ if (args && typeof args === "object" && typeof args.shape === "object") {
16924
+ return args.shape;
16925
+ }
16926
+ return args || {};
16927
+ };
16927
16928
  var toJSONSchema2 = (route) => {
16928
16929
  const pickValues = pick(route, pickValue);
16929
16930
  if (pickValues?.metadata?.args) {
16930
- const args = pickValues.metadata.args;
16931
- if (args && typeof args === "object" && args.toJSONSchema && typeof args.toJSONSchema === "function") {
16932
- pickValues.metadata.args = args.toJSONSchema();
16933
- return pickValues;
16934
- }
16931
+ let args = pickValues.metadata.args;
16932
+ args = extractArgs(args);
16935
16933
  const keys = Object.keys(args);
16936
16934
  const newArgs = {};
16937
16935
  for (let key of keys) {
@@ -19251,7 +19249,7 @@ var createRouterAgentPluginFn = (opts) => {
19251
19249
  tool: {
19252
19250
  ...routes.reduce((acc, route) => {
19253
19251
  const metadata = route.metadata;
19254
- let args = extractArgs(metadata?.args);
19252
+ let args = extractArgs2(metadata?.args);
19255
19253
  acc[metadata.skill] = {
19256
19254
  name: metadata.title || metadata.skill,
19257
19255
  description: metadata.summary || "",
@@ -19287,7 +19285,7 @@ var createRouterAgentPluginFn = (opts) => {
19287
19285
  };
19288
19286
  return AgentPlugin;
19289
19287
  };
19290
- var extractArgs = (args) => {
19288
+ var extractArgs2 = (args) => {
19291
19289
  if (args && typeof args === "object" && typeof args.shape === "object") {
19292
19290
  return args.shape;
19293
19291
  }
@@ -19485,7 +19483,7 @@ app
19485
19483
  10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
19486
19484
  `;
19487
19485
  // package.json
19488
- var version2 = "0.0.75";
19486
+ var version2 = "0.0.76";
19489
19487
 
19490
19488
  // agent/routes/route-create.ts
19491
19489
  app.route({
@@ -150,7 +150,6 @@ declare class Route<U = {
150
150
  metadata?: T;
151
151
  middleware?: RouteMiddleware[];
152
152
  type?: string;
153
- data?: any;
154
153
  /**
155
154
  * 是否开启debug,开启后会打印错误信息
156
155
  */
@@ -175,7 +174,6 @@ declare class Route<U = {
175
174
  add: (route: Route) => void;
176
175
  [key: string]: any;
177
176
  }, opts?: AddOpts): void;
178
- setData(data: any): this;
179
177
  throw(code?: number | string, message?: string, tips?: string): void;
180
178
  }
181
179
  /**
@@ -178,7 +178,6 @@ declare class Route<U = {
178
178
  metadata?: T;
179
179
  middleware?: RouteMiddleware[];
180
180
  type?: string;
181
- data?: any;
182
181
  /**
183
182
  * 是否开启debug,开启后会打印错误信息
184
183
  */
@@ -203,7 +202,6 @@ declare class Route<U = {
203
202
  add: (route: Route) => void;
204
203
  [key: string]: any;
205
204
  }, opts?: AddOpts): void;
206
- setData(data: any): this;
207
205
  throw(code?: number | string, message?: string, tips?: string): void;
208
206
  }
209
207
  declare const toJSONSchema: (route: RouteInfo) => Pick<RouteInfo, "path" | "key" | "id" | "description" | "type" | "middleware" | "metadata">;
@@ -13988,7 +13988,6 @@ class Route {
13988
13988
  metadata;
13989
13989
  middleware;
13990
13990
  type = "route";
13991
- data;
13992
13991
  isDebug;
13993
13992
  constructor(path = "", key = "", opts) {
13994
13993
  if (!path) {
@@ -14080,22 +14079,21 @@ class Route {
14080
14079
  addTo(router, opts) {
14081
14080
  router.add(this, opts);
14082
14081
  }
14083
- setData(data) {
14084
- this.data = data;
14085
- return this;
14086
- }
14087
14082
  throw(...args) {
14088
14083
  throw new CustomError(...args);
14089
14084
  }
14090
14085
  }
14086
+ var extractArgs = (args) => {
14087
+ if (args && typeof args === "object" && typeof args.shape === "object") {
14088
+ return args.shape;
14089
+ }
14090
+ return args || {};
14091
+ };
14091
14092
  var toJSONSchema2 = (route) => {
14092
14093
  const pickValues = pick(route, pickValue);
14093
14094
  if (pickValues?.metadata?.args) {
14094
- const args = pickValues.metadata.args;
14095
- if (args && typeof args === "object" && args.toJSONSchema && typeof args.toJSONSchema === "function") {
14096
- pickValues.metadata.args = args.toJSONSchema();
14097
- return pickValues;
14098
- }
14095
+ let args = pickValues.metadata.args;
14096
+ args = extractArgs(args);
14099
14097
  const keys = Object.keys(args);
14100
14098
  const newArgs = {};
14101
14099
  for (let key of keys) {
@@ -147,7 +147,6 @@ declare class Route<U = {
147
147
  metadata?: T;
148
148
  middleware?: RouteMiddleware[];
149
149
  type?: string;
150
- data?: any;
151
150
  /**
152
151
  * 是否开启debug,开启后会打印错误信息
153
152
  */
@@ -172,7 +171,6 @@ declare class Route<U = {
172
171
  add: (route: Route) => void;
173
172
  [key: string]: any;
174
173
  }, opts?: AddOpts): void;
175
- setData(data: any): this;
176
174
  throw(code?: number | string, message?: string, tips?: string): void;
177
175
  }
178
176
  /**
package/dist/router.d.ts CHANGED
@@ -184,7 +184,6 @@ declare class Route<U = {
184
184
  metadata?: T;
185
185
  middleware?: RouteMiddleware[];
186
186
  type?: string;
187
- data?: any;
188
187
  /**
189
188
  * 是否开启debug,开启后会打印错误信息
190
189
  */
@@ -209,7 +208,6 @@ declare class Route<U = {
209
208
  add: (route: Route) => void;
210
209
  [key: string]: any;
211
210
  }, opts?: AddOpts): void;
212
- setData(data: any): this;
213
211
  throw(code?: number | string, message?: string, tips?: string): void;
214
212
  }
215
213
  declare const toJSONSchema: (route: RouteInfo) => Pick<RouteInfo, "path" | "key" | "id" | "description" | "type" | "middleware" | "metadata">;
package/dist/router.js CHANGED
@@ -16821,7 +16821,6 @@ class Route {
16821
16821
  metadata;
16822
16822
  middleware;
16823
16823
  type = "route";
16824
- data;
16825
16824
  isDebug;
16826
16825
  constructor(path = "", key = "", opts) {
16827
16826
  if (!path) {
@@ -16913,22 +16912,21 @@ class Route {
16913
16912
  addTo(router, opts) {
16914
16913
  router.add(this, opts);
16915
16914
  }
16916
- setData(data) {
16917
- this.data = data;
16918
- return this;
16919
- }
16920
16915
  throw(...args) {
16921
16916
  throw new CustomError(...args);
16922
16917
  }
16923
16918
  }
16919
+ var extractArgs = (args) => {
16920
+ if (args && typeof args === "object" && typeof args.shape === "object") {
16921
+ return args.shape;
16922
+ }
16923
+ return args || {};
16924
+ };
16924
16925
  var toJSONSchema2 = (route) => {
16925
16926
  const pickValues = pick(route, pickValue);
16926
16927
  if (pickValues?.metadata?.args) {
16927
- const args = pickValues.metadata.args;
16928
- if (args && typeof args === "object" && args.toJSONSchema && typeof args.toJSONSchema === "function") {
16929
- pickValues.metadata.args = args.toJSONSchema();
16930
- return pickValues;
16931
- }
16928
+ let args = pickValues.metadata.args;
16929
+ args = extractArgs(args);
16932
16930
  const keys = Object.keys(args);
16933
16931
  const newArgs = {};
16934
16932
  for (let key of keys) {
package/dist/ws.d.ts CHANGED
@@ -197,7 +197,6 @@ declare class Route<U = {
197
197
  metadata?: T;
198
198
  middleware?: RouteMiddleware[];
199
199
  type?: string;
200
- data?: any;
201
200
  /**
202
201
  * 是否开启debug,开启后会打印错误信息
203
202
  */
@@ -222,7 +221,6 @@ declare class Route<U = {
222
221
  add: (route: Route) => void;
223
222
  [key: string]: any;
224
223
  }, opts?: AddOpts): void;
225
- setData(data: any): this;
226
224
  throw(code?: number | string, message?: string, tips?: string): void;
227
225
  }
228
226
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@kevisual/router",
4
- "version": "0.0.75",
4
+ "version": "0.0.76",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
@@ -21,7 +21,6 @@
21
21
  "keywords": [],
22
22
  "author": "abearxiong",
23
23
  "license": "MIT",
24
- "packageManager": "pnpm@10.30.0",
25
24
  "devDependencies": {
26
25
  "@kevisual/code-builder": "^0.0.6",
27
26
  "@kevisual/context": "^0.0.6",
package/src/route.ts CHANGED
@@ -137,7 +137,6 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
137
137
  metadata?: T;
138
138
  middleware?: RouteMiddleware[]; // middleware
139
139
  type? = 'route';
140
- data?: any;
141
140
  /**
142
141
  * 是否开启debug,开启后会打印错误信息
143
142
  */
@@ -241,23 +240,25 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
241
240
  addTo(router: QueryRouter | { add: (route: Route) => void;[key: string]: any }, opts?: AddOpts) {
242
241
  router.add(this, opts);
243
242
  }
244
- setData(data: any) {
245
- this.data = data;
246
- return this;
247
- }
248
243
  throw(code?: number | string, message?: string, tips?: string): void;
249
244
  throw(...args: any[]) {
250
245
  throw new CustomError(...args);
251
246
  }
252
247
  }
248
+ export const extractArgs = (args: any) => {
249
+ if (args && typeof args === 'object' && typeof args.shape === 'object') {
250
+ return args.shape as z.ZodRawShape;
251
+ }
252
+ return args || {};
253
+ };
254
+
253
255
  export const toJSONSchema = (route: RouteInfo) => {
254
256
  const pickValues = pick(route, pickValue as any);
255
257
  if (pickValues?.metadata?.args) {
256
- const args = pickValues.metadata.args;
257
- if (args && typeof args === 'object' && args.toJSONSchema && typeof args.toJSONSchema === 'function') {
258
- pickValues.metadata.args = args.toJSONSchema();
259
- return pickValues;
260
- }
258
+ let args = pickValues.metadata.args;
259
+ // 如果 args 本身是一个 zod object schema,先提取 shape
260
+ args = extractArgs(args);
261
+
261
262
  const keys = Object.keys(args);
262
263
  const newArgs: { [key: string]: any } = {};
263
264
  for (let key of keys) {