@kevisual/router 0.0.59 → 0.0.60

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.
@@ -80,7 +80,7 @@ type RouteContext<T = {
80
80
  needSerialize?: boolean;
81
81
  } & T;
82
82
  type SimpleObject = Record<string, any>;
83
- type Run<T extends SimpleObject = {}> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
83
+ type Run<T extends SimpleObject = {}> = (ctx: Required<RouteContext<T>>) => Promise<typeof ctx | null | void>;
84
84
  type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
85
85
  type RouteMiddleware = {
86
86
  path: string;
package/dist/opencode.js CHANGED
@@ -15323,6 +15323,9 @@ const createRouterAgentPluginFn = (opts) => {
15323
15323
  if (!router.hasRoute('call', '')) {
15324
15324
  addCallFn(router);
15325
15325
  }
15326
+ if (!router.hasRoute('auth', '')) {
15327
+ router.route({ path: 'auth', key: '', id: 'auth', description: '认证' }).define(async (ctx) => { }).addTo(router);
15328
+ }
15326
15329
  const _routes = filter(router.routes, opts?.query || '');
15327
15330
  const routes = _routes.filter(r => {
15328
15331
  const metadata = r.metadata;
@@ -15360,6 +15363,7 @@ const createRouterAgentPluginFn = (opts) => {
15360
15363
  }
15361
15364
  return str;
15362
15365
  }
15366
+ console.error('调用出错', res);
15363
15367
  return `Error: ${res?.message || '无法获取结果'}`;
15364
15368
  }
15365
15369
  };
@@ -78,7 +78,7 @@ type RouteContext<T = {
78
78
  needSerialize?: boolean;
79
79
  } & T;
80
80
  type SimpleObject$1 = Record<string, any>;
81
- type Run<T extends SimpleObject$1 = {}> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
81
+ type Run<T extends SimpleObject$1 = {}> = (ctx: Required<RouteContext<T>>) => Promise<typeof ctx | null | void>;
82
82
  type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
83
83
  type RouteMiddleware = {
84
84
  path: string;
package/dist/router.d.ts CHANGED
@@ -85,7 +85,7 @@ type RouteContext<T = {
85
85
  needSerialize?: boolean;
86
86
  } & T;
87
87
  type SimpleObject$1 = Record<string, any>;
88
- type Run<T extends SimpleObject$1 = {}> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
88
+ type Run<T extends SimpleObject$1 = {}> = (ctx: Required<RouteContext<T>>) => Promise<typeof ctx | null | void>;
89
89
  type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
90
90
  type RouteMiddleware = {
91
91
  path: string;
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@kevisual/router",
4
- "version": "0.0.59",
4
+ "version": "0.0.60",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
8
8
  "types": "./dist/router.d.ts",
9
9
  "scripts": {
10
10
  "build": "npm run clean && rollup -c",
11
- "build:app": "npm run build && rsync dist/*browser* ../deploy/dist",
11
+ "postbuild": "bun run bun.config.ts",
12
12
  "watch": "rollup -c -w",
13
13
  "clean": "rm -rf dist"
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
17
  "src",
18
+ "agent",
18
19
  "auto.ts",
19
20
  "mod.ts"
20
21
  ],
@@ -39,6 +40,7 @@
39
40
  "@types/ws": "^8.18.1",
40
41
  "@types/xml2js": "^0.4.14",
41
42
  "eventemitter3": "^5.0.4",
43
+ "fast-glob": "^3.3.3",
42
44
  "nanoid": "^5.1.6",
43
45
  "path-to-regexp": "^8.3.0",
44
46
  "rollup": "^4.55.2",
@@ -80,6 +82,7 @@
80
82
  "types": "./dist/router-simple.d.ts"
81
83
  },
82
84
  "./opencode": "./dist/opencode.js",
85
+ "./skill": "./dist/app.js",
83
86
  "./define": {
84
87
  "import": "./dist/router-define.js",
85
88
  "require": "./dist/router-define.js",
package/src/app.ts CHANGED
@@ -2,7 +2,6 @@ import { QueryRouter, Route, RouteContext, RouteOpts } from './route.ts';
2
2
  import { ServerNode, ServerNodeOpts } from './server/server.ts';
3
3
  import { HandleCtx } from './server/server-base.ts';
4
4
  import { ServerType } from './server/server-type.ts';
5
- import { CustomError } from './result/error.ts';
6
5
  import { handleServer } from './server/handle-server.ts';
7
6
  import { IncomingMessage, ServerResponse } from 'http';
8
7
  import { isBun } from './utils/is-engine.ts';
package/src/opencode.ts CHANGED
@@ -50,6 +50,9 @@ export const createRouterAgentPluginFn = (opts?: {
50
50
  if (!router.hasRoute('call', '')) {
51
51
  addCallFn(router as App)
52
52
  }
53
+ if (!router.hasRoute('auth', '')) {
54
+ router.route({ path: 'auth', key: '', id: 'auth', description: '认证' }).define(async (ctx) => { }).addTo(router as App)
55
+ }
53
56
  const _routes = filter(router.routes, opts?.query || '')
54
57
  const routes = _routes.filter(r => {
55
58
  const metadata = r.metadata as Skill
@@ -88,6 +91,7 @@ export const createRouterAgentPluginFn = (opts?: {
88
91
  }
89
92
  return str;
90
93
  }
94
+ console.error('调用出错', res);
91
95
  return `Error: ${res?.message || '无法获取结果'}`;
92
96
  }
93
97
  }
package/src/route.ts CHANGED
@@ -60,7 +60,7 @@ export type RouteContext<T = { code?: number }, S = any> = {
60
60
  needSerialize?: boolean;
61
61
  } & T;
62
62
  export type SimpleObject = Record<string, any>;
63
- export type Run<T extends SimpleObject = {}> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
63
+ export type Run<T extends SimpleObject = {}> = (ctx: Required<RouteContext<T>>) => Promise<typeof ctx | null | void>;
64
64
 
65
65
  export type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
66
66
  export type RouteMiddleware =
@@ -355,7 +355,7 @@ export class QueryRouter {
355
355
  const middleware = routeMiddleware[i];
356
356
  if (middleware) {
357
357
  try {
358
- await middleware.run(ctx);
358
+ await middleware.run(ctx as Required<RouteContext>);
359
359
  } catch (e) {
360
360
  if (route?.isDebug) {
361
361
  console.error('=====debug====:middlerware error');
@@ -385,7 +385,7 @@ export class QueryRouter {
385
385
  if (route) {
386
386
  if (route.run) {
387
387
  try {
388
- await route.run(ctx);
388
+ await route.run(ctx as Required<RouteContext>);
389
389
  } catch (e) {
390
390
  if (route?.isDebug) {
391
391
  console.error('=====debug====:', 'router run error:', e.message);