@kevisual/router 0.0.58 → 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.
- package/agent/app.ts +5 -0
- package/agent/gen/index.ts +205 -0
- package/agent/gen.ts +42 -0
- package/agent/main.ts +6 -0
- package/agent/routes/index.ts +14 -0
- package/agent/routes/route-create.ts +45 -0
- package/dist/app.d.ts +5 -0
- package/dist/app.js +19320 -0
- package/dist/opencode.d.ts +312 -4
- package/dist/opencode.js +5 -1
- package/dist/router-browser.d.ts +1 -2
- package/dist/router-browser.js +0 -5
- package/dist/router.d.ts +3 -22
- package/dist/router.js +6 -36
- package/package.json +6 -3
- package/src/app.ts +8 -34
- package/src/opencode.ts +8 -4
- package/src/route.ts +3 -9
package/src/opencode.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type App } from './app.ts'
|
|
|
4
4
|
import { type Plugin } from "@opencode-ai/plugin"
|
|
5
5
|
|
|
6
6
|
import { filter } from '@kevisual/js-filter';
|
|
7
|
-
export const addCallFn = (app:
|
|
7
|
+
export const addCallFn = (app: App) => {
|
|
8
8
|
app.route({
|
|
9
9
|
path: 'call',
|
|
10
10
|
key: '',
|
|
@@ -35,20 +35,23 @@ export const addCallFn = (app: QueryRouterServer) => {
|
|
|
35
35
|
}).addTo(app)
|
|
36
36
|
}
|
|
37
37
|
export const createRouterAgentPluginFn = (opts?: {
|
|
38
|
-
router?:
|
|
38
|
+
router?: App | QueryRouterServer,
|
|
39
39
|
//** 过滤比如,WHERE metadata.tags includes 'opencode' */
|
|
40
40
|
query?: string
|
|
41
41
|
}) => {
|
|
42
42
|
let router = opts?.router
|
|
43
43
|
if (!router) {
|
|
44
44
|
const app = useContextKey<App>('app')
|
|
45
|
-
router = app
|
|
45
|
+
router = app
|
|
46
46
|
}
|
|
47
47
|
if (!router) {
|
|
48
48
|
throw new Error('Router 参数缺失')
|
|
49
49
|
}
|
|
50
50
|
if (!router.hasRoute('call', '')) {
|
|
51
|
-
addCallFn(router as
|
|
51
|
+
addCallFn(router as App)
|
|
52
|
+
}
|
|
53
|
+
if (!router.hasRoute('auth', '')) {
|
|
54
|
+
router.route({ path: 'auth', key: '', id: 'auth', description: '认证' }).define(async (ctx) => { }).addTo(router as App)
|
|
52
55
|
}
|
|
53
56
|
const _routes = filter(router.routes, opts?.query || '')
|
|
54
57
|
const routes = _routes.filter(r => {
|
|
@@ -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
|
|
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);
|
|
@@ -664,15 +664,9 @@ export class QueryRouterServer extends QueryRouter {
|
|
|
664
664
|
setHandle(wrapperFn?: HandleFn, ctx?: RouteContext) {
|
|
665
665
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
|
666
666
|
}
|
|
667
|
-
use(path: string, fn: (ctx: any) => any, opts?: RouteOpts) {
|
|
668
|
-
const route = new Route(path, '', opts);
|
|
669
|
-
route.run = fn;
|
|
670
|
-
this.add(route);
|
|
671
|
-
}
|
|
672
667
|
addRoute(route: Route) {
|
|
673
668
|
this.add(route);
|
|
674
669
|
}
|
|
675
|
-
|
|
676
670
|
Route = Route;
|
|
677
671
|
route(opts: RouteOpts): Route<Required<RouteContext>>;
|
|
678
672
|
route(path: string, key?: string): Route<Required<RouteContext>>;
|