feat: 更新静态资源代理文档,优化路由和插件集成,提升代码可读性和功能性

This commit is contained in:
2026-01-21 01:44:58 +08:00
parent 61add1aad1
commit 7dcf53fb4f
16 changed files with 487 additions and 69 deletions

View File

@@ -4,7 +4,7 @@ import { type App } from './app.ts'
import { type Plugin } from "@opencode-ai/plugin"
import { filter } from '@kevisual/js-filter';
export const addCallFn = (app: QueryRouterServer) => {
export const addCallFn = (app: App) => {
app.route({
path: 'call',
key: '',
@@ -35,20 +35,23 @@ export const addCallFn = (app: QueryRouterServer) => {
}).addTo(app)
}
export const createRouterAgentPluginFn = (opts?: {
router?: QueryRouter,
router?: App | QueryRouterServer,
//** 过滤比如WHERE metadata.tags includes 'opencode' */
query?: string
}) => {
let router = opts?.router
if (!router) {
const app = useContextKey<App>('app')
router = app.router
router = app
}
if (!router) {
throw new Error('Router 参数缺失')
}
if (!router.hasRoute('call', '')) {
addCallFn(router as QueryRouterServer)
addCallFn(router as App)
}
if (!router.hasRoute('auth', '')) {
router.route({ path: 'auth', key: '', id: 'auth', description: '认证' }).define(async (ctx) => { }).addTo(router as App)
}
const _routes = filter(router.routes, opts?.query || '')
const routes = _routes.filter(r => {
@@ -88,6 +91,7 @@ export const createRouterAgentPluginFn = (opts?: {
}
return str;
}
console.error('调用出错', res);
return `Error: ${res?.message || '无法获取结果'}`;
}
}