@kevisual/router 0.0.90 → 0.1.1
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/app.js +1 -1
- package/dist/commander.d.ts +2 -0
- package/dist/commander.js +15 -3
- package/dist/opencode.d.ts +2 -0
- package/dist/router-browser.d.ts +2 -0
- package/dist/router-define.d.ts +2 -0
- package/dist/router.d.ts +2 -0
- package/dist/ws.d.ts +2 -0
- package/package.json +4 -4
- package/src/commander.ts +15 -5
- package/src/route.ts +1 -1
package/dist/app.js
CHANGED
|
@@ -19582,7 +19582,7 @@ app
|
|
|
19582
19582
|
10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
|
|
19583
19583
|
`;
|
|
19584
19584
|
// package.json
|
|
19585
|
-
var version2 = "0.
|
|
19585
|
+
var version2 = "0.1.1";
|
|
19586
19586
|
|
|
19587
19587
|
// agent/routes/route-create.ts
|
|
19588
19588
|
app.route({
|
package/dist/commander.d.ts
CHANGED
|
@@ -449,6 +449,8 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
449
449
|
path?: string;
|
|
450
450
|
key?: string;
|
|
451
451
|
payload?: any;
|
|
452
|
+
token?: string;
|
|
453
|
+
data?: any;
|
|
452
454
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
453
455
|
runAction<T extends {
|
|
454
456
|
id?: string;
|
package/dist/commander.js
CHANGED
|
@@ -2148,7 +2148,14 @@ var parseArgs = (args) => {
|
|
|
2148
2148
|
for (const pair of pairs) {
|
|
2149
2149
|
const idx = pair.indexOf("=");
|
|
2150
2150
|
const key = pair.slice(0, idx);
|
|
2151
|
-
const
|
|
2151
|
+
const raw = pair.slice(idx + 1);
|
|
2152
|
+
let value = raw;
|
|
2153
|
+
if (raw === "true")
|
|
2154
|
+
value = true;
|
|
2155
|
+
else if (raw === "false")
|
|
2156
|
+
value = false;
|
|
2157
|
+
else if (raw !== "" && !isNaN(Number(raw)))
|
|
2158
|
+
value = Number(raw);
|
|
2152
2159
|
result[key] = value;
|
|
2153
2160
|
}
|
|
2154
2161
|
return result;
|
|
@@ -2200,7 +2207,7 @@ var createCommand2 = (opts) => {
|
|
|
2200
2207
|
if (!route.key)
|
|
2201
2208
|
return;
|
|
2202
2209
|
const description = parseDescription(route);
|
|
2203
|
-
subProgram.command(route.key).description(description || "").option("--args <args>", "JSON
|
|
2210
|
+
subProgram.command(route.key).description(description || "").option("--args <args>", `命令参数,支持 JSON 格式或 key=value 形式,例如: --args '{"a":1}' 或 --args 'a=1 b=2'`).argument("[args...]", `位置参数(推荐通过 -- 分隔传入),支持 JSON 或 key=value 格式,例如: -- a=1 b=2 或 -- '{"a":1}'`).action(async (passedArgs, options, _command) => {
|
|
2204
2211
|
const output = (data) => {
|
|
2205
2212
|
if (typeof data === "object") {
|
|
2206
2213
|
process.stdout.write(JSON.stringify(data, null, 2) + `
|
|
@@ -2211,7 +2218,12 @@ var createCommand2 = (opts) => {
|
|
|
2211
2218
|
}
|
|
2212
2219
|
};
|
|
2213
2220
|
try {
|
|
2214
|
-
|
|
2221
|
+
let args = {};
|
|
2222
|
+
if (options.args) {
|
|
2223
|
+
args = parseArgs(options.args);
|
|
2224
|
+
} else if (passedArgs.length > 0) {
|
|
2225
|
+
args = parseArgs(passedArgs.join(" "));
|
|
2226
|
+
}
|
|
2215
2227
|
const res = await app.run({ path, key: route.key, payload: args }, { appId: app.appId });
|
|
2216
2228
|
if (res.code === 200) {
|
|
2217
2229
|
output(res.data);
|
package/dist/opencode.d.ts
CHANGED
|
@@ -449,6 +449,8 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
449
449
|
path?: string;
|
|
450
450
|
key?: string;
|
|
451
451
|
payload?: any;
|
|
452
|
+
token?: string;
|
|
453
|
+
data?: any;
|
|
452
454
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
453
455
|
runAction<T extends {
|
|
454
456
|
id?: string;
|
package/dist/router-browser.d.ts
CHANGED
|
@@ -521,6 +521,8 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
521
521
|
path?: string;
|
|
522
522
|
key?: string;
|
|
523
523
|
payload?: any;
|
|
524
|
+
token?: string;
|
|
525
|
+
data?: any;
|
|
524
526
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
525
527
|
runAction<T extends {
|
|
526
528
|
id?: string;
|
package/dist/router-define.d.ts
CHANGED
|
@@ -446,6 +446,8 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
446
446
|
path?: string;
|
|
447
447
|
key?: string;
|
|
448
448
|
payload?: any;
|
|
449
|
+
token?: string;
|
|
450
|
+
data?: any;
|
|
449
451
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
450
452
|
runAction<T extends {
|
|
451
453
|
id?: string;
|
package/dist/router.d.ts
CHANGED
|
@@ -527,6 +527,8 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
527
527
|
path?: string;
|
|
528
528
|
key?: string;
|
|
529
529
|
payload?: any;
|
|
530
|
+
token?: string;
|
|
531
|
+
data?: any;
|
|
530
532
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
531
533
|
runAction<T extends {
|
|
532
534
|
id?: string;
|
package/dist/ws.d.ts
CHANGED
|
@@ -496,6 +496,8 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
496
496
|
path?: string;
|
|
497
497
|
key?: string;
|
|
498
498
|
payload?: any;
|
|
499
|
+
token?: string;
|
|
500
|
+
data?: any;
|
|
499
501
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
500
502
|
runAction<T extends {
|
|
501
503
|
id?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/router.js",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"@kevisual/local-proxy": "^0.0.8",
|
|
30
30
|
"@kevisual/query": "^0.0.53",
|
|
31
31
|
"@kevisual/use-config": "^1.0.30",
|
|
32
|
-
"@opencode-ai/plugin": "^1.2.
|
|
32
|
+
"@opencode-ai/plugin": "^1.2.24",
|
|
33
33
|
"@types/bun": "^1.3.10",
|
|
34
|
-
"@types/node": "^25.
|
|
34
|
+
"@types/node": "^25.4.0",
|
|
35
35
|
"@types/send": "^1.2.1",
|
|
36
36
|
"@types/ws": "^8.18.1",
|
|
37
37
|
"@types/xml2js": "^0.4.14",
|
|
38
38
|
"commander": "^14.0.3",
|
|
39
39
|
"eventemitter3": "^5.0.4",
|
|
40
40
|
"fast-glob": "^3.3.3",
|
|
41
|
-
"hono": "^4.12.
|
|
41
|
+
"hono": "^4.12.7",
|
|
42
42
|
"nanoid": "^5.1.6",
|
|
43
43
|
"path-to-regexp": "^8.3.0",
|
|
44
44
|
"send": "^1.2.1",
|
package/src/commander.ts
CHANGED
|
@@ -22,8 +22,12 @@ export const parseArgs = (args: string) => {
|
|
|
22
22
|
for (const pair of pairs) {
|
|
23
23
|
const idx = pair.indexOf('=');
|
|
24
24
|
const key = pair.slice(0, idx);
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const raw = pair.slice(idx + 1);
|
|
26
|
+
let value: string | number | boolean = raw;
|
|
27
|
+
if (raw === 'true') value = true;
|
|
28
|
+
else if (raw === 'false') value = false;
|
|
29
|
+
else if (raw !== '' && !isNaN(Number(raw))) value = Number(raw);
|
|
30
|
+
result[key] = value as string;
|
|
27
31
|
}
|
|
28
32
|
return result;
|
|
29
33
|
}
|
|
@@ -77,8 +81,9 @@ export const createCommand = (opts: { app: App, program: Command }) => {
|
|
|
77
81
|
const description = parseDescription(route);
|
|
78
82
|
subProgram.command(route.key)
|
|
79
83
|
.description(description || '')
|
|
80
|
-
.option('--args <args>', 'JSON
|
|
81
|
-
.
|
|
84
|
+
.option('--args <args>', '命令参数,支持 JSON 格式或 key=value 形式,例如: --args \'{"a":1}\' 或 --args \'a=1 b=2\'')
|
|
85
|
+
.argument('[args...]', '位置参数(推荐通过 -- 分隔传入),支持 JSON 或 key=value 格式,例如: -- a=1 b=2 或 -- \'{"a":1}\'')
|
|
86
|
+
.action(async (passedArgs: string[], options, _command) => {
|
|
82
87
|
const output = (data: any) => {
|
|
83
88
|
if (typeof data === 'object') {
|
|
84
89
|
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
@@ -87,7 +92,12 @@ export const createCommand = (opts: { app: App, program: Command }) => {
|
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
try {
|
|
90
|
-
|
|
95
|
+
let args: Record<string, any> = {};
|
|
96
|
+
if (options.args) {
|
|
97
|
+
args = parseArgs(options.args);
|
|
98
|
+
} else if (passedArgs.length > 0) {
|
|
99
|
+
args = parseArgs(passedArgs.join(' '));
|
|
100
|
+
}
|
|
91
101
|
// 这里可以添加实际的命令执行逻辑,例如调用对应的路由处理函数
|
|
92
102
|
const res = await app.run({ path, key: route.key, payload: args }, { appId: app.appId });
|
|
93
103
|
if (res.code === 200) {
|
package/src/route.ts
CHANGED
|
@@ -775,7 +775,7 @@ export class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Qu
|
|
|
775
775
|
* @param param0
|
|
776
776
|
* @returns
|
|
777
777
|
*/
|
|
778
|
-
async run(msg: { id?: string; path?: string; key?: string; payload?: any }, ctx?: Partial<RouteContext<C>>) {
|
|
778
|
+
async run(msg: { id?: string; path?: string; key?: string; payload?: any, token?: string, data?: any }, ctx?: Partial<RouteContext<C>>) {
|
|
779
779
|
const handle = this.handle;
|
|
780
780
|
if (handle) {
|
|
781
781
|
return handle(msg, ctx);
|