@kevisual/router 0.0.62 → 0.0.63

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.
@@ -2,7 +2,7 @@ import { EventEmitter } from 'eventemitter3';
2
2
  import * as http from 'node:http';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
4
  import { IncomingMessage as IncomingMessage$1, ServerResponse as ServerResponse$1 } from 'http';
5
- import { Plugin } from '@opencode-ai/plugin';
5
+ import { PluginInput, Hooks, Plugin } from '@opencode-ai/plugin';
6
6
 
7
7
  type RouterContextT = {
8
8
  code?: number;
@@ -672,6 +672,8 @@ declare const addCallFn: (app: App) => void;
672
672
  declare const createRouterAgentPluginFn: (opts?: {
673
673
  router?: App | QueryRouterServer;
674
674
  query?: string;
675
+ hooks?: (plugin: PluginInput) => Promise<Hooks>;
675
676
  }) => Plugin;
677
+ declare const usePluginInput: () => PluginInput;
676
678
 
677
- export { addCallFn, createRouterAgentPluginFn };
679
+ export { addCallFn, createRouterAgentPluginFn, usePluginInput };
package/dist/opencode.js CHANGED
@@ -2770,7 +2770,7 @@ class Doc {
2770
2770
  const version = {
2771
2771
  major: 4,
2772
2772
  minor: 3,
2773
- patch: 5,
2773
+ patch: 6,
2774
2774
  };
2775
2775
 
2776
2776
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -4132,11 +4132,9 @@ const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
4132
4132
  if (keyResult instanceof Promise) {
4133
4133
  throw new Error("Async schemas not supported in object keys currently");
4134
4134
  }
4135
- // Numeric string fallback: if key failed with "expected number", retry with Number(key)
4136
- const checkNumericKey = typeof key === "string" &&
4137
- number$2.test(key) &&
4138
- keyResult.issues.length &&
4139
- keyResult.issues.some((iss) => iss.code === "invalid_type" && iss.expected === "number");
4135
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
4136
+ // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
4137
+ const checkNumericKey = typeof key === "string" && number$2.test(key) && keyResult.issues.length;
4140
4138
  if (checkNumericKey) {
4141
4139
  const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
4142
4140
  if (retryResult instanceof Promise) {
@@ -11789,7 +11787,7 @@ function finalize(ctx, schema) {
11789
11787
  }
11790
11788
  }
11791
11789
  // When ref was extracted to $defs, remove properties that match the definition
11792
- if (refSchema.$ref) {
11790
+ if (refSchema.$ref && refSeen.def) {
11793
11791
  for (const key in schema) {
11794
11792
  if (key === "$ref" || key === "allOf")
11795
11793
  continue;
@@ -15684,8 +15682,11 @@ const createRouterAgentPluginFn = (opts) => {
15684
15682
  return false;
15685
15683
  });
15686
15684
  // opencode run "查看系统信息"
15687
- const AgentPlugin = async ({ project, client, $, directory, worktree }) => {
15685
+ const AgentPlugin = async (pluginInput) => {
15686
+ useContextKey('plugin-input', () => pluginInput, true);
15687
+ const hooks = opts?.hooks ? await opts.hooks(pluginInput) : {};
15688
15688
  return {
15689
+ ...hooks,
15689
15690
  'tool': {
15690
15691
  ...routes.reduce((acc, route) => {
15691
15692
  const metadata = route.metadata;
@@ -15717,15 +15718,19 @@ const createRouterAgentPluginFn = (opts) => {
15717
15718
  }
15718
15719
  };
15719
15720
  return acc;
15720
- }, {})
15721
+ }, {}),
15722
+ ...hooks?.tool
15721
15723
  },
15722
- 'tool.execute.before': async (opts) => {
15723
- // console.log('CnbPlugin: tool.execute.before', opts.tool);
15724
- // delete toolSkills['cnb-login-verify']
15725
- }
15724
+ // 'tool.execute.before': async (opts) => {
15725
+ // // console.log('CnbPlugin: tool.execute.before', opts.tool);
15726
+ // // delete toolSkills['cnb-login-verify']
15727
+ // },
15726
15728
  };
15727
15729
  };
15728
15730
  return AgentPlugin;
15729
15731
  };
15732
+ const usePluginInput = () => {
15733
+ return useContextKey('plugin-input');
15734
+ };
15730
15735
 
15731
- export { addCallFn, createRouterAgentPluginFn };
15736
+ export { addCallFn, createRouterAgentPluginFn, usePluginInput };
@@ -2418,7 +2418,7 @@ class Doc {
2418
2418
  const version = {
2419
2419
  major: 4,
2420
2420
  minor: 3,
2421
- patch: 5,
2421
+ patch: 6,
2422
2422
  };
2423
2423
 
2424
2424
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -3780,11 +3780,9 @@ const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
3780
3780
  if (keyResult instanceof Promise) {
3781
3781
  throw new Error("Async schemas not supported in object keys currently");
3782
3782
  }
3783
- // Numeric string fallback: if key failed with "expected number", retry with Number(key)
3784
- const checkNumericKey = typeof key === "string" &&
3785
- number$2.test(key) &&
3786
- keyResult.issues.length &&
3787
- keyResult.issues.some((iss) => iss.code === "invalid_type" && iss.expected === "number");
3783
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
3784
+ // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
3785
+ const checkNumericKey = typeof key === "string" && number$2.test(key) && keyResult.issues.length;
3788
3786
  if (checkNumericKey) {
3789
3787
  const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
3790
3788
  if (retryResult instanceof Promise) {
@@ -11437,7 +11435,7 @@ function finalize(ctx, schema) {
11437
11435
  }
11438
11436
  }
11439
11437
  // When ref was extracted to $defs, remove properties that match the definition
11440
- if (refSchema.$ref) {
11438
+ if (refSchema.$ref && refSeen.def) {
11441
11439
  for (const key in schema) {
11442
11440
  if (key === "$ref" || key === "allOf")
11443
11441
  continue;
package/dist/router.js CHANGED
@@ -2442,7 +2442,7 @@ class Doc {
2442
2442
  const version = {
2443
2443
  major: 4,
2444
2444
  minor: 3,
2445
- patch: 5,
2445
+ patch: 6,
2446
2446
  };
2447
2447
 
2448
2448
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -3804,11 +3804,9 @@ const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
3804
3804
  if (keyResult instanceof Promise) {
3805
3805
  throw new Error("Async schemas not supported in object keys currently");
3806
3806
  }
3807
- // Numeric string fallback: if key failed with "expected number", retry with Number(key)
3808
- const checkNumericKey = typeof key === "string" &&
3809
- number$2.test(key) &&
3810
- keyResult.issues.length &&
3811
- keyResult.issues.some((iss) => iss.code === "invalid_type" && iss.expected === "number");
3807
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
3808
+ // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
3809
+ const checkNumericKey = typeof key === "string" && number$2.test(key) && keyResult.issues.length;
3812
3810
  if (checkNumericKey) {
3813
3811
  const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
3814
3812
  if (retryResult instanceof Promise) {
@@ -11461,7 +11459,7 @@ function finalize(ctx, schema) {
11461
11459
  }
11462
11460
  }
11463
11461
  // When ref was extracted to $defs, remove properties that match the definition
11464
- if (refSchema.$ref) {
11462
+ if (refSchema.$ref && refSeen.def) {
11465
11463
  for (const key in schema) {
11466
11464
  if (key === "$ref" || key === "allOf")
11467
11465
  continue;
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@kevisual/router",
4
- "version": "0.0.62",
4
+ "version": "0.0.63",
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
- "postbuild": "bun run bun.config.ts",
12
11
  "watch": "rollup -c -w",
13
12
  "clean": "rm -rf dist"
14
13
  },
@@ -22,20 +21,20 @@
22
21
  "keywords": [],
23
22
  "author": "abearxiong",
24
23
  "license": "MIT",
25
- "packageManager": "pnpm@10.28.1",
24
+ "packageManager": "pnpm@10.28.2",
26
25
  "devDependencies": {
27
26
  "@kevisual/context": "^0.0.4",
28
27
  "@kevisual/js-filter": "^0.0.5",
29
28
  "@kevisual/local-proxy": "^0.0.8",
30
- "@kevisual/query": "^0.0.35",
29
+ "@kevisual/query": "^0.0.38",
31
30
  "@kevisual/use-config": "^1.0.28",
32
- "@opencode-ai/plugin": "^1.1.27",
31
+ "@opencode-ai/plugin": "^1.1.36",
33
32
  "@rollup/plugin-alias": "^6.0.0",
34
33
  "@rollup/plugin-commonjs": "29.0.0",
35
34
  "@rollup/plugin-node-resolve": "^16.0.3",
36
35
  "@rollup/plugin-typescript": "^12.3.0",
37
36
  "@types/bun": "^1.3.6",
38
- "@types/node": "^25.0.9",
37
+ "@types/node": "^25.0.10",
39
38
  "@types/send": "^1.2.1",
40
39
  "@types/ws": "^8.18.1",
41
40
  "@types/xml2js": "^0.4.14",
@@ -43,7 +42,7 @@
43
42
  "fast-glob": "^3.3.3",
44
43
  "nanoid": "^5.1.6",
45
44
  "path-to-regexp": "^8.3.0",
46
- "rollup": "^4.55.2",
45
+ "rollup": "^4.57.0",
47
46
  "rollup-plugin-dts": "^6.3.0",
48
47
  "send": "^1.2.1",
49
48
  "ts-loader": "^9.5.4",
@@ -53,14 +52,15 @@
53
52
  "typescript": "^5.9.3",
54
53
  "ws": "npm:@kevisual/ws",
55
54
  "xml2js": "^0.6.2",
56
- "zod": "^4.3.5"
55
+ "zod": "^4.3.6"
57
56
  },
58
57
  "repository": {
59
58
  "type": "git",
60
59
  "url": "git+https://github.com/abearxiong/kevisual-router.git"
61
60
  },
62
61
  "dependencies": {
63
- "hono": "^4.11.4"
62
+ "@kevisual/dts": "^0.0.3",
63
+ "hono": "^4.11.7"
64
64
  },
65
65
  "publishConfig": {
66
66
  "access": "public"
package/src/opencode.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { useContextKey } from '@kevisual/context'
2
2
  import { createSkill, type QueryRouterServer, tool, type QueryRouter, type Skill } from './route.ts'
3
3
  import { type App } from './app.ts'
4
- import { type Plugin } from "@opencode-ai/plugin"
4
+ import { PluginInput, type Plugin, Hooks } from "@opencode-ai/plugin"
5
5
 
6
6
  import { filter } from '@kevisual/js-filter';
7
+
7
8
  export const addCallFn = (app: App) => {
8
9
  app.route({
9
10
  path: 'call',
@@ -34,10 +35,12 @@ export const addCallFn = (app: App) => {
34
35
  ctx.forward(res);
35
36
  }).addTo(app)
36
37
  }
38
+
37
39
  export const createRouterAgentPluginFn = (opts?: {
38
40
  router?: App | QueryRouterServer,
39
41
  //** 过滤比如,WHERE metadata.tags includes 'opencode' */
40
- query?: string
42
+ query?: string,
43
+ hooks?: (plugin: PluginInput) => Promise<Hooks>
41
44
  }) => {
42
45
  let router = opts?.router
43
46
  if (!router) {
@@ -60,10 +63,14 @@ export const createRouterAgentPluginFn = (opts?: {
60
63
  return !!metadata.skill
61
64
  }
62
65
  return false
63
- })
66
+ });
67
+
64
68
  // opencode run "查看系统信息"
65
- const AgentPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
69
+ const AgentPlugin: Plugin = async (pluginInput) => {
70
+ useContextKey<PluginInput>('plugin-input', () => pluginInput, true)
71
+ const hooks = opts?.hooks ? await opts.hooks(pluginInput) : {}
66
72
  return {
73
+ ...hooks,
67
74
  'tool': {
68
75
  ...routes.reduce((acc, route) => {
69
76
  const metadata = route.metadata as Skill
@@ -96,13 +103,18 @@ export const createRouterAgentPluginFn = (opts?: {
96
103
  }
97
104
  }
98
105
  return acc;
99
- }, {} as Record<string, any>)
106
+ }, {} as Record<string, any>),
107
+ ...hooks?.tool
100
108
  },
101
- 'tool.execute.before': async (opts) => {
102
- // console.log('CnbPlugin: tool.execute.before', opts.tool);
103
- // delete toolSkills['cnb-login-verify']
104
- }
109
+ // 'tool.execute.before': async (opts) => {
110
+ // // console.log('CnbPlugin: tool.execute.before', opts.tool);
111
+ // // delete toolSkills['cnb-login-verify']
112
+ // },
105
113
  }
106
114
  }
107
115
  return AgentPlugin
108
116
  }
117
+
118
+ export const usePluginInput = (): PluginInput => {
119
+ return useContextKey<PluginInput>('plugin-input')
120
+ }
package/src/test/mini.ts CHANGED
@@ -4,7 +4,8 @@ const app = new Mini();
4
4
 
5
5
  app.route({
6
6
  path: 'main',
7
- id: 'abc'
7
+ id: 'abc',
8
+ description: '这是一个测试的 main 路由'
8
9
  }).define(async (ctx) => {
9
10
  ctx.body = {
10
11
  a: '123'
@@ -49,9 +49,11 @@ export const runCode = async (tsPath: string, params: RunCodeParams = {}): Promi
49
49
  });
50
50
  }
51
51
  import path from 'node:path'
52
- const res =await runCode(path.join(process.cwd(), './src/test/mini.ts'), {
52
+ const res = await runCode(path.join(process.cwd(), './src/test/mini.ts'), {
53
53
  // path: 'main'
54
54
  // id: 'abc'
55
+ path: 'router',
56
+ key: 'list'
55
57
  })
56
58
 
57
- console.log('res', res)
59
+ console.log('res', res.data.data.list)
package/dist/app.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import * as _opencode_ai_plugin from '@opencode-ai/plugin';
2
-
3
- declare const routerAgentPlugin: _opencode_ai_plugin.Plugin;
4
-
5
- export { routerAgentPlugin };