@kevisual/router 0.0.57 → 0.0.58
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/opencode.d.ts +39 -1
- package/dist/opencode.js +14410 -1
- package/package.json +1 -1
- package/src/opencode.ts +34 -2
package/package.json
CHANGED
package/src/opencode.ts
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import { useContextKey } from '@kevisual/context'
|
|
2
|
-
import { type QueryRouter, type Skill } from './route.ts'
|
|
2
|
+
import { createSkill, type QueryRouterServer, tool, type QueryRouter, type Skill } from './route.ts'
|
|
3
3
|
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
|
-
|
|
7
|
+
export const addCallFn = (app: QueryRouterServer) => {
|
|
8
|
+
app.route({
|
|
9
|
+
path: 'call',
|
|
10
|
+
key: '',
|
|
11
|
+
description: '调用',
|
|
12
|
+
middleware: ['auth'],
|
|
13
|
+
metadata: {
|
|
14
|
+
tags: ['opencode'],
|
|
15
|
+
...createSkill({
|
|
16
|
+
skill: 'call-app',
|
|
17
|
+
title: '调用app应用',
|
|
18
|
+
summary: '调用router的应用, 参数path, key, payload',
|
|
19
|
+
args: {
|
|
20
|
+
path: tool.schema.string().describe('应用路径,例如 cnb'),
|
|
21
|
+
key: tool.schema.string().optional().describe('应用key,例如 list-repos'),
|
|
22
|
+
payload: tool.schema.object({}).optional().describe('调用参数'),
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
},
|
|
26
|
+
}).define(async (ctx) => {
|
|
27
|
+
const { path, key = '' } = ctx.query;
|
|
28
|
+
if (!path) {
|
|
29
|
+
ctx.throw('路径path不能为空');
|
|
30
|
+
}
|
|
31
|
+
const res = await ctx.run({ path, key, payload: ctx.query.payload || {} }, {
|
|
32
|
+
...ctx
|
|
33
|
+
});
|
|
34
|
+
ctx.forward(res);
|
|
35
|
+
}).addTo(app)
|
|
36
|
+
}
|
|
8
37
|
export const createRouterAgentPluginFn = (opts?: {
|
|
9
38
|
router?: QueryRouter,
|
|
10
39
|
//** 过滤比如,WHERE metadata.tags includes 'opencode' */
|
|
@@ -18,6 +47,9 @@ export const createRouterAgentPluginFn = (opts?: {
|
|
|
18
47
|
if (!router) {
|
|
19
48
|
throw new Error('Router 参数缺失')
|
|
20
49
|
}
|
|
50
|
+
if (!router.hasRoute('call', '')) {
|
|
51
|
+
addCallFn(router as QueryRouterServer)
|
|
52
|
+
}
|
|
21
53
|
const _routes = filter(router.routes, opts?.query || '')
|
|
22
54
|
const routes = _routes.filter(r => {
|
|
23
55
|
const metadata = r.metadata as Skill
|