@kevisual/cnb 0.0.37 → 0.0.40
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 +30 -12
- package/agent/main.ts +18 -0
- package/agent/modules/cnb-manager.ts +119 -0
- package/agent/opencode.ts +1 -1
- package/agent/routes/cnb-board/cnb-dev-env.ts +5 -15
- package/agent/routes/cnb-board/index.ts +3 -2
- package/agent/routes/cnb-env/check.ts +3 -2
- package/agent/routes/cnb-env/env.ts +5 -3
- package/agent/routes/cnb-env/vscode.ts +5 -3
- package/agent/routes/cnb-manager/index.ts +48 -0
- package/agent/routes/index.ts +8 -0
- package/agent/routes/issues/issue.ts +5 -3
- package/agent/routes/issues/list.ts +3 -2
- package/agent/routes/knowledge/ai.ts +5 -3
- package/agent/routes/repo/list.ts +3 -2
- package/agent/routes/repo/repo.ts +79 -6
- package/agent/routes/share/index.ts +1 -1
- package/agent/routes/workspace/build.ts +43 -0
- package/agent/routes/workspace/index.ts +16 -9
- package/agent/routes/workspace/keep.ts +9 -5
- package/agent/routes/workspace/skills.ts +3 -2
- package/dist/cli.js +409 -118
- package/dist/opencode.js +417 -127
- package/dist/routes.d.ts +29 -54
- package/dist/routes.js +399 -108
- package/package.json +14 -6
- package/mod.ts +0 -1
- /package/agent/{command.ts → commander.ts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1398,12 +1398,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1398
1398
|
}
|
|
1399
1399
|
return this;
|
|
1400
1400
|
}
|
|
1401
|
-
_optionEx(
|
|
1401
|
+
_optionEx(config3, flags, description, fn, defaultValue) {
|
|
1402
1402
|
if (typeof flags === "object" && flags instanceof Option) {
|
|
1403
1403
|
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1404
1404
|
}
|
|
1405
1405
|
const option = this.createOption(flags, description);
|
|
1406
|
-
option.makeOptionMandatory(!!
|
|
1406
|
+
option.makeOptionMandatory(!!config3.mandatory);
|
|
1407
1407
|
if (typeof fn === "function") {
|
|
1408
1408
|
option.default(defaultValue).argParser(fn);
|
|
1409
1409
|
} else if (fn instanceof RegExp) {
|
|
@@ -2007,9 +2007,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2007
2007
|
`);
|
|
2008
2008
|
this.outputHelp({ error: true });
|
|
2009
2009
|
}
|
|
2010
|
-
const
|
|
2011
|
-
const exitCode =
|
|
2012
|
-
const code2 =
|
|
2010
|
+
const config3 = errorOptions || {};
|
|
2011
|
+
const exitCode = config3.exitCode || 1;
|
|
2012
|
+
const code2 = config3.code || "commander.error";
|
|
2013
2013
|
this._exit(exitCode, code2, message);
|
|
2014
2014
|
}
|
|
2015
2015
|
_parseOptionsEnv() {
|
|
@@ -2411,7 +2411,7 @@ var require_commander = __commonJS((exports) => {
|
|
|
2411
2411
|
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2412
2412
|
});
|
|
2413
2413
|
|
|
2414
|
-
// node_modules/.pnpm/@kevisual+router@0.0.
|
|
2414
|
+
// node_modules/.pnpm/@kevisual+router@0.0.90/node_modules/@kevisual/router/dist/router.js
|
|
2415
2415
|
import { createRequire as createRequire2 } from "node:module";
|
|
2416
2416
|
import { webcrypto as crypto2 } from "node:crypto";
|
|
2417
2417
|
import url2 from "node:url";
|
|
@@ -19293,6 +19293,9 @@ var toJSONSchemaRoute = (route) => {
|
|
|
19293
19293
|
if (pickValues?.metadata?.args) {
|
|
19294
19294
|
pickValues.metadata.args = toJSONSchema3(pickValues?.metadata?.args, { mergeObject: false });
|
|
19295
19295
|
}
|
|
19296
|
+
if (pickValues?.metadata?.returns) {
|
|
19297
|
+
pickValues.metadata.returns = toJSONSchema3(pickValues?.metadata?.returns, { mergeObject: false });
|
|
19298
|
+
}
|
|
19296
19299
|
return pickValues;
|
|
19297
19300
|
};
|
|
19298
19301
|
var toJSONSchema3 = toJSONSchema2;
|
|
@@ -22489,16 +22492,129 @@ class CNB extends CNBCore {
|
|
|
22489
22492
|
}
|
|
22490
22493
|
}
|
|
22491
22494
|
|
|
22495
|
+
// agent/modules/cnb-manager.ts
|
|
22496
|
+
var getConfig2 = async (opts) => {
|
|
22497
|
+
const kevisualEnv = useKey("KEVISUAL_ENV");
|
|
22498
|
+
const baseUrl = kevisualEnv === "production" ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
|
|
22499
|
+
const res = await fetch(baseUrl, {
|
|
22500
|
+
method: "POST",
|
|
22501
|
+
body: JSON.stringify({
|
|
22502
|
+
path: "config",
|
|
22503
|
+
key: "get",
|
|
22504
|
+
data: {
|
|
22505
|
+
key: "cnb_center_config.json"
|
|
22506
|
+
}
|
|
22507
|
+
}),
|
|
22508
|
+
headers: {
|
|
22509
|
+
"Content-Type": "application/json",
|
|
22510
|
+
Authorization: `Bearer ${opts.token}`
|
|
22511
|
+
}
|
|
22512
|
+
}).then((res2) => res2.json());
|
|
22513
|
+
return res;
|
|
22514
|
+
};
|
|
22515
|
+
|
|
22516
|
+
class CNBManager {
|
|
22517
|
+
cnbMap = new Map;
|
|
22518
|
+
constructor() {
|
|
22519
|
+
setInterval(() => {
|
|
22520
|
+
this.clearExpiredCNB();
|
|
22521
|
+
}, 1000 * 60 * 30);
|
|
22522
|
+
}
|
|
22523
|
+
getDefaultCNB() {
|
|
22524
|
+
const cnbItem = this.cnbMap.get("default");
|
|
22525
|
+
if (!cnbItem) {
|
|
22526
|
+
throw new Error("Default CNB not found");
|
|
22527
|
+
}
|
|
22528
|
+
return cnbItem;
|
|
22529
|
+
}
|
|
22530
|
+
async getCNB(opts) {
|
|
22531
|
+
const username = opts?.username;
|
|
22532
|
+
const cnbItem = this.cnbMap.get(username);
|
|
22533
|
+
if (cnbItem) {
|
|
22534
|
+
cnbItem.runAt = Date.now();
|
|
22535
|
+
return cnbItem;
|
|
22536
|
+
}
|
|
22537
|
+
const res = await getConfig2({ token: opts?.kevisualToken });
|
|
22538
|
+
if (res.code === 200) {
|
|
22539
|
+
const cookie = res.data?.data?.CNB_COOKIE;
|
|
22540
|
+
const token = res.data?.data?.CNB_API_KEY;
|
|
22541
|
+
if (token) {
|
|
22542
|
+
return this.addCNB({ username, token, cookie });
|
|
22543
|
+
}
|
|
22544
|
+
}
|
|
22545
|
+
return null;
|
|
22546
|
+
}
|
|
22547
|
+
async getContext(ctx) {
|
|
22548
|
+
const tokenUser = ctx?.state?.tokenUser;
|
|
22549
|
+
const username = tokenUser?.username;
|
|
22550
|
+
if (!username) {
|
|
22551
|
+
ctx.throw(403, "Unauthorized");
|
|
22552
|
+
}
|
|
22553
|
+
if (username === "default") {
|
|
22554
|
+
return this.getDefaultCNB().cnb;
|
|
22555
|
+
}
|
|
22556
|
+
const kevisualToken = ctx.query?.token;
|
|
22557
|
+
const item = await this.getCNB({ username, kevisualToken });
|
|
22558
|
+
if (!item) {
|
|
22559
|
+
ctx.throw(400, "不存在的 CNB 配置项,请检查 登录 Token 是否正确,或添加 CNB 配置");
|
|
22560
|
+
}
|
|
22561
|
+
return item.cnb;
|
|
22562
|
+
}
|
|
22563
|
+
addCNB(opts) {
|
|
22564
|
+
if (!opts.username || !opts.token) {
|
|
22565
|
+
throw new Error("username and token are required");
|
|
22566
|
+
}
|
|
22567
|
+
const exist = this.cnbMap.get(opts.username);
|
|
22568
|
+
if (exist) {
|
|
22569
|
+
exist.runAt = Date.now();
|
|
22570
|
+
return exist;
|
|
22571
|
+
}
|
|
22572
|
+
const cnb = opts?.cnb || new CNB({ token: opts.token, cookie: opts.cookie });
|
|
22573
|
+
opts.cnb = cnb;
|
|
22574
|
+
opts.runAt = Date.now();
|
|
22575
|
+
this.cnbMap.set(opts.username, opts);
|
|
22576
|
+
return opts;
|
|
22577
|
+
}
|
|
22578
|
+
clearExpiredCNB(expireTime = 1000 * 60 * 60) {
|
|
22579
|
+
const now = Date.now();
|
|
22580
|
+
for (const [username, item] of this.cnbMap.entries()) {
|
|
22581
|
+
if (username === "default") {
|
|
22582
|
+
continue;
|
|
22583
|
+
}
|
|
22584
|
+
if (item.runAt && now - item.runAt > expireTime) {
|
|
22585
|
+
this.cnbMap.delete(username);
|
|
22586
|
+
}
|
|
22587
|
+
}
|
|
22588
|
+
}
|
|
22589
|
+
clearUsername(username) {
|
|
22590
|
+
this.cnbMap.delete(username);
|
|
22591
|
+
}
|
|
22592
|
+
}
|
|
22593
|
+
|
|
22492
22594
|
// agent/app.ts
|
|
22493
|
-
var
|
|
22494
|
-
var
|
|
22495
|
-
|
|
22496
|
-
|
|
22497
|
-
|
|
22498
|
-
|
|
22499
|
-
|
|
22595
|
+
var cnbManager = new CNBManager;
|
|
22596
|
+
var token = useKey2("CNB_API_KEY") || useKey2("CNB_TOKEN");
|
|
22597
|
+
var cookie = useKey2("CNB_COOKIE");
|
|
22598
|
+
try {
|
|
22599
|
+
cnbManager.addCNB({
|
|
22600
|
+
username: "default",
|
|
22601
|
+
token,
|
|
22602
|
+
cookie,
|
|
22603
|
+
cnb: new CNB({ token, cookie })
|
|
22604
|
+
});
|
|
22605
|
+
} catch (error48) {}
|
|
22606
|
+
var cnb = (await cnbManager.getCNB({ username: "default" })).cnb;
|
|
22607
|
+
var app = await useContextKey("app", () => {
|
|
22500
22608
|
return new QueryRouterServer({});
|
|
22501
22609
|
});
|
|
22610
|
+
var notCNBCheck = (ctx) => {
|
|
22611
|
+
const isCNB = useKey2("CNB");
|
|
22612
|
+
if (!isCNB) {
|
|
22613
|
+
ctx.throw(400, "当前环境非 cnb-board 环境,无法获取 live 内容");
|
|
22614
|
+
return true;
|
|
22615
|
+
}
|
|
22616
|
+
return false;
|
|
22617
|
+
};
|
|
22502
22618
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/external.js
|
|
22503
22619
|
var exports_external2 = {};
|
|
22504
22620
|
__export(exports_external2, {
|
|
@@ -22640,7 +22756,7 @@ __export(exports_external2, {
|
|
|
22640
22756
|
cuid2: () => cuid25,
|
|
22641
22757
|
cuid: () => cuid6,
|
|
22642
22758
|
core: () => exports_core3,
|
|
22643
|
-
config: () =>
|
|
22759
|
+
config: () => config2,
|
|
22644
22760
|
coerce: () => exports_coerce2,
|
|
22645
22761
|
codec: () => codec2,
|
|
22646
22762
|
clone: () => clone2,
|
|
@@ -22779,7 +22895,7 @@ __export(exports_core3, {
|
|
|
22779
22895
|
decode: () => decode4,
|
|
22780
22896
|
createToJSONSchemaMethod: () => createToJSONSchemaMethod2,
|
|
22781
22897
|
createStandardJSONSchemaMethod: () => createStandardJSONSchemaMethod2,
|
|
22782
|
-
config: () =>
|
|
22898
|
+
config: () => config2,
|
|
22783
22899
|
clone: () => clone2,
|
|
22784
22900
|
_xor: () => _xor2,
|
|
22785
22901
|
_xid: () => _xid2,
|
|
@@ -23089,7 +23205,7 @@ class $ZodEncodeError2 extends Error {
|
|
|
23089
23205
|
}
|
|
23090
23206
|
}
|
|
23091
23207
|
var globalConfig2 = {};
|
|
23092
|
-
function
|
|
23208
|
+
function config2(newConfig) {
|
|
23093
23209
|
if (newConfig)
|
|
23094
23210
|
Object.assign(globalConfig2, newConfig);
|
|
23095
23211
|
return globalConfig2;
|
|
@@ -23659,10 +23775,10 @@ function prefixIssues2(path2, issues) {
|
|
|
23659
23775
|
function unwrapMessage2(message) {
|
|
23660
23776
|
return typeof message === "string" ? message : message?.message;
|
|
23661
23777
|
}
|
|
23662
|
-
function finalizeIssue2(iss, ctx,
|
|
23778
|
+
function finalizeIssue2(iss, ctx, config3) {
|
|
23663
23779
|
const full = { ...iss, path: iss.path ?? [] };
|
|
23664
23780
|
if (!iss.message) {
|
|
23665
|
-
const message = unwrapMessage2(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage2(ctx?.error?.(iss)) ?? unwrapMessage2(
|
|
23781
|
+
const message = unwrapMessage2(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage2(ctx?.error?.(iss)) ?? unwrapMessage2(config3.customError?.(iss)) ?? unwrapMessage2(config3.localeError?.(iss)) ?? "Invalid input";
|
|
23666
23782
|
full.message = message;
|
|
23667
23783
|
}
|
|
23668
23784
|
delete full.inst;
|
|
@@ -23913,7 +24029,7 @@ var _parse2 = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
23913
24029
|
throw new $ZodAsyncError2;
|
|
23914
24030
|
}
|
|
23915
24031
|
if (result.issues.length) {
|
|
23916
|
-
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
24032
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue2(iss, ctx, config2())));
|
|
23917
24033
|
captureStackTrace2(e, _params?.callee);
|
|
23918
24034
|
throw e;
|
|
23919
24035
|
}
|
|
@@ -23926,7 +24042,7 @@ var _parseAsync2 = (_Err) => async (schema, value, _ctx, params) => {
|
|
|
23926
24042
|
if (result instanceof Promise)
|
|
23927
24043
|
result = await result;
|
|
23928
24044
|
if (result.issues.length) {
|
|
23929
|
-
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
24045
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue2(iss, ctx, config2())));
|
|
23930
24046
|
captureStackTrace2(e, params?.callee);
|
|
23931
24047
|
throw e;
|
|
23932
24048
|
}
|
|
@@ -23941,7 +24057,7 @@ var _safeParse2 = (_Err) => (schema, value, _ctx) => {
|
|
|
23941
24057
|
}
|
|
23942
24058
|
return result.issues.length ? {
|
|
23943
24059
|
success: false,
|
|
23944
|
-
error: new (_Err ?? $ZodError2)(result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
24060
|
+
error: new (_Err ?? $ZodError2)(result.issues.map((iss) => finalizeIssue2(iss, ctx, config2())))
|
|
23945
24061
|
} : { success: true, data: result.value };
|
|
23946
24062
|
};
|
|
23947
24063
|
var safeParse3 = /* @__PURE__ */ _safeParse2($ZodRealError2);
|
|
@@ -23952,7 +24068,7 @@ var _safeParseAsync2 = (_Err) => async (schema, value, _ctx) => {
|
|
|
23952
24068
|
result = await result;
|
|
23953
24069
|
return result.issues.length ? {
|
|
23954
24070
|
success: false,
|
|
23955
|
-
error: new _Err(result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
24071
|
+
error: new _Err(result.issues.map((iss) => finalizeIssue2(iss, ctx, config2())))
|
|
23956
24072
|
} : { success: true, data: result.value };
|
|
23957
24073
|
};
|
|
23958
24074
|
var safeParseAsync3 = /* @__PURE__ */ _safeParseAsync2($ZodRealError2);
|
|
@@ -25112,9 +25228,9 @@ var $ZodE1642 = /* @__PURE__ */ $constructor2("$ZodE164", (inst, def) => {
|
|
|
25112
25228
|
def.pattern ?? (def.pattern = e1643);
|
|
25113
25229
|
$ZodStringFormat2.init(inst, def);
|
|
25114
25230
|
});
|
|
25115
|
-
function isValidJWT2(
|
|
25231
|
+
function isValidJWT2(token2, algorithm = null) {
|
|
25116
25232
|
try {
|
|
25117
|
-
const tokensParts =
|
|
25233
|
+
const tokensParts = token2.split(".");
|
|
25118
25234
|
if (tokensParts.length !== 3)
|
|
25119
25235
|
return false;
|
|
25120
25236
|
const [header] = tokensParts;
|
|
@@ -25621,7 +25737,7 @@ function handleUnionResults2(results, final, inst, ctx) {
|
|
|
25621
25737
|
code: "invalid_union",
|
|
25622
25738
|
input: final.value,
|
|
25623
25739
|
inst,
|
|
25624
|
-
errors: results.map((result) => result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
25740
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue2(iss, ctx, config2())))
|
|
25625
25741
|
});
|
|
25626
25742
|
return final;
|
|
25627
25743
|
}
|
|
@@ -25682,7 +25798,7 @@ function handleExclusiveUnionResults2(results, final, inst, ctx) {
|
|
|
25682
25798
|
code: "invalid_union",
|
|
25683
25799
|
input: final.value,
|
|
25684
25800
|
inst,
|
|
25685
|
-
errors: results.map((result) => result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
25801
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue2(iss, ctx, config2())))
|
|
25686
25802
|
});
|
|
25687
25803
|
} else {
|
|
25688
25804
|
final.issues.push({
|
|
@@ -26041,7 +26157,7 @@ var $ZodRecord2 = /* @__PURE__ */ $constructor2("$ZodRecord", (inst, def) => {
|
|
|
26041
26157
|
payload.issues.push({
|
|
26042
26158
|
code: "invalid_key",
|
|
26043
26159
|
origin: "record",
|
|
26044
|
-
issues: keyResult.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
26160
|
+
issues: keyResult.issues.map((iss) => finalizeIssue2(iss, ctx, config2())),
|
|
26045
26161
|
input: key,
|
|
26046
26162
|
path: [key],
|
|
26047
26163
|
inst
|
|
@@ -26112,7 +26228,7 @@ function handleMapResult2(keyResult, valueResult, final, key, input, inst, ctx)
|
|
|
26112
26228
|
origin: "map",
|
|
26113
26229
|
input,
|
|
26114
26230
|
inst,
|
|
26115
|
-
issues: keyResult.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
26231
|
+
issues: keyResult.issues.map((iss) => finalizeIssue2(iss, ctx, config2()))
|
|
26116
26232
|
});
|
|
26117
26233
|
}
|
|
26118
26234
|
}
|
|
@@ -26126,7 +26242,7 @@ function handleMapResult2(keyResult, valueResult, final, key, input, inst, ctx)
|
|
|
26126
26242
|
input,
|
|
26127
26243
|
inst,
|
|
26128
26244
|
key,
|
|
26129
|
-
issues: valueResult.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
26245
|
+
issues: valueResult.issues.map((iss) => finalizeIssue2(iss, ctx, config2()))
|
|
26130
26246
|
});
|
|
26131
26247
|
}
|
|
26132
26248
|
}
|
|
@@ -26396,7 +26512,7 @@ var $ZodCatch2 = /* @__PURE__ */ $constructor2("$ZodCatch", (inst, def) => {
|
|
|
26396
26512
|
payload.value = def.catchValue({
|
|
26397
26513
|
...payload,
|
|
26398
26514
|
error: {
|
|
26399
|
-
issues: result2.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
26515
|
+
issues: result2.issues.map((iss) => finalizeIssue2(iss, ctx, config2()))
|
|
26400
26516
|
},
|
|
26401
26517
|
input: payload.value
|
|
26402
26518
|
});
|
|
@@ -26410,7 +26526,7 @@ var $ZodCatch2 = /* @__PURE__ */ $constructor2("$ZodCatch", (inst, def) => {
|
|
|
26410
26526
|
payload.value = def.catchValue({
|
|
26411
26527
|
...payload,
|
|
26412
26528
|
error: {
|
|
26413
|
-
issues: result.issues.map((iss) => finalizeIssue2(iss, ctx,
|
|
26529
|
+
issues: result.issues.map((iss) => finalizeIssue2(iss, ctx, config2()))
|
|
26414
26530
|
},
|
|
26415
26531
|
input: payload.value
|
|
26416
26532
|
});
|
|
@@ -35534,12 +35650,12 @@ var ZodIssueCode2 = {
|
|
|
35534
35650
|
custom: "custom"
|
|
35535
35651
|
};
|
|
35536
35652
|
function setErrorMap2(map3) {
|
|
35537
|
-
|
|
35653
|
+
config2({
|
|
35538
35654
|
customError: map3
|
|
35539
35655
|
});
|
|
35540
35656
|
}
|
|
35541
35657
|
function getErrorMap2() {
|
|
35542
|
-
return
|
|
35658
|
+
return config2().customError;
|
|
35543
35659
|
}
|
|
35544
35660
|
var ZodFirstPartyTypeKind2;
|
|
35545
35661
|
(function(ZodFirstPartyTypeKind3) {})(ZodFirstPartyTypeKind2 || (ZodFirstPartyTypeKind2 = {}));
|
|
@@ -36030,11 +36146,11 @@ function date9(params) {
|
|
|
36030
36146
|
}
|
|
36031
36147
|
|
|
36032
36148
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/external.js
|
|
36033
|
-
|
|
36149
|
+
config2(en_default2());
|
|
36034
36150
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/index.js
|
|
36035
36151
|
var zod_default = exports_external2;
|
|
36036
36152
|
|
|
36037
|
-
// node_modules/.pnpm/@opencode-ai+plugin@1.2.
|
|
36153
|
+
// node_modules/.pnpm/@opencode-ai+plugin@1.2.23/node_modules/@opencode-ai/plugin/dist/tool.js
|
|
36038
36154
|
function tool2(input) {
|
|
36039
36155
|
return input;
|
|
36040
36156
|
}
|
|
@@ -36045,7 +36161,7 @@ app.route({
|
|
|
36045
36161
|
path: "cnb",
|
|
36046
36162
|
key: "user-check",
|
|
36047
36163
|
description: "检查用户登录状态,参数checkToken,default true; checkCookie, default false",
|
|
36048
|
-
middleware: ["auth
|
|
36164
|
+
middleware: ["auth"],
|
|
36049
36165
|
metadata: {
|
|
36050
36166
|
tags: ["opencode"],
|
|
36051
36167
|
...createSkill({
|
|
@@ -36062,8 +36178,9 @@ app.route({
|
|
|
36062
36178
|
const checkToken = ctx.query?.checkToken ?? true;
|
|
36063
36179
|
const checkCookie = ctx.query?.checkCookie ?? false;
|
|
36064
36180
|
let content = "";
|
|
36181
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36065
36182
|
if (checkToken) {
|
|
36066
|
-
const res = await
|
|
36183
|
+
const res = await cnb2.user.getUser();
|
|
36067
36184
|
if (res?.code !== 200) {
|
|
36068
36185
|
content += `Token 无效,请检查 CNB_TOKEN 配置。
|
|
36069
36186
|
`;
|
|
@@ -36073,7 +36190,7 @@ app.route({
|
|
|
36073
36190
|
}
|
|
36074
36191
|
}
|
|
36075
36192
|
if (checkCookie) {
|
|
36076
|
-
const res = await
|
|
36193
|
+
const res = await cnb2.user.getCurrentUser();
|
|
36077
36194
|
if (res?.code !== 200) {
|
|
36078
36195
|
content += `Cookie 无效,请检查 CNB_COOKIE 配置。
|
|
36079
36196
|
`;
|
|
@@ -36090,7 +36207,7 @@ app.route({
|
|
|
36090
36207
|
path: "cnb",
|
|
36091
36208
|
key: "list-repos",
|
|
36092
36209
|
description: "列出我的代码仓库",
|
|
36093
|
-
middleware: ["auth
|
|
36210
|
+
middleware: ["auth"],
|
|
36094
36211
|
metadata: {
|
|
36095
36212
|
tags: ["opencode"],
|
|
36096
36213
|
...createSkill({
|
|
@@ -36105,6 +36222,7 @@ app.route({
|
|
|
36105
36222
|
})
|
|
36106
36223
|
}
|
|
36107
36224
|
}).define(async (ctx) => {
|
|
36225
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36108
36226
|
const search = ctx.query?.search;
|
|
36109
36227
|
const pageSize = ctx.query?.pageSize || 9999;
|
|
36110
36228
|
const flags = ctx.query?.flags;
|
|
@@ -36112,7 +36230,7 @@ app.route({
|
|
|
36112
36230
|
if (flags) {
|
|
36113
36231
|
params.flags = flags;
|
|
36114
36232
|
}
|
|
36115
|
-
const res = await
|
|
36233
|
+
const res = await cnb2.repo.getRepoList({ search, page_size: pageSize, role: "developer", ...params });
|
|
36116
36234
|
if (res.code === 200) {
|
|
36117
36235
|
const repos = res.data.map((item) => ({
|
|
36118
36236
|
name: item.name,
|
|
@@ -36131,7 +36249,7 @@ app.route({
|
|
|
36131
36249
|
path: "cnb",
|
|
36132
36250
|
key: "create-repo",
|
|
36133
36251
|
description: "创建代码仓库, 参数name, visibility, description",
|
|
36134
|
-
middleware: ["auth
|
|
36252
|
+
middleware: ["auth"],
|
|
36135
36253
|
metadata: {
|
|
36136
36254
|
tags: ["opencode"],
|
|
36137
36255
|
...createSkill({
|
|
@@ -36146,6 +36264,7 @@ app.route({
|
|
|
36146
36264
|
})
|
|
36147
36265
|
}
|
|
36148
36266
|
}).define(async (ctx) => {
|
|
36267
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36149
36268
|
const name = ctx.query?.name;
|
|
36150
36269
|
const visibility = ctx.query?.visibility ?? "public";
|
|
36151
36270
|
const description = ctx.query?.description ?? "";
|
|
@@ -36153,7 +36272,7 @@ app.route({
|
|
|
36153
36272
|
ctx.throw(400, "缺少参数 name");
|
|
36154
36273
|
}
|
|
36155
36274
|
try {
|
|
36156
|
-
const res = await
|
|
36275
|
+
const res = await cnb2.repo.createRepo({
|
|
36157
36276
|
name,
|
|
36158
36277
|
visibility,
|
|
36159
36278
|
description
|
|
@@ -36164,11 +36283,30 @@ app.route({
|
|
|
36164
36283
|
ctx.body = { content: "JS仓库可能已存在" };
|
|
36165
36284
|
}
|
|
36166
36285
|
}).addTo(app);
|
|
36286
|
+
app.route({
|
|
36287
|
+
path: "cnb",
|
|
36288
|
+
key: "get-repo",
|
|
36289
|
+
description: "获取代码仓库详情, 参数name",
|
|
36290
|
+
middleware: ["auth"],
|
|
36291
|
+
metadata: {
|
|
36292
|
+
args: {
|
|
36293
|
+
name: tool.schema.string().describe("代码仓库名称, 如 my-user/my-repo")
|
|
36294
|
+
}
|
|
36295
|
+
}
|
|
36296
|
+
}).define(async (ctx) => {
|
|
36297
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36298
|
+
const name = ctx.query?.name;
|
|
36299
|
+
if (!name) {
|
|
36300
|
+
ctx.throw(400, "缺少参数 name");
|
|
36301
|
+
}
|
|
36302
|
+
const res = await cnb2.repo.getRepo(name);
|
|
36303
|
+
ctx.forward(res);
|
|
36304
|
+
}).addTo(app);
|
|
36167
36305
|
app.route({
|
|
36168
36306
|
path: "cnb",
|
|
36169
36307
|
key: "create-repo-file",
|
|
36170
36308
|
description: "在代码仓库中创建文件, repoName, filePath, content, encoding。使用CNB_COOKIE进行鉴权",
|
|
36171
|
-
middleware: ["auth
|
|
36309
|
+
middleware: ["auth"],
|
|
36172
36310
|
metadata: {
|
|
36173
36311
|
tags: ["opencode"],
|
|
36174
36312
|
...createSkill({
|
|
@@ -36184,6 +36322,7 @@ app.route({
|
|
|
36184
36322
|
})
|
|
36185
36323
|
}
|
|
36186
36324
|
}).define(async (ctx) => {
|
|
36325
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36187
36326
|
const repoName = ctx.query?.repoName;
|
|
36188
36327
|
const filePath = ctx.query?.filePath;
|
|
36189
36328
|
const content = ctx.query?.content;
|
|
@@ -36191,7 +36330,7 @@ app.route({
|
|
|
36191
36330
|
if (!repoName || !filePath || !content) {
|
|
36192
36331
|
ctx.throw(400, "缺少参数 repoName, filePath 或 content");
|
|
36193
36332
|
}
|
|
36194
|
-
const res = await
|
|
36333
|
+
const res = await cnb2.repo.createCommit(repoName, {
|
|
36195
36334
|
message: `添加文件 ${filePath} 通过 API `,
|
|
36196
36335
|
files: [
|
|
36197
36336
|
{ path: filePath, content, encoding }
|
|
@@ -36203,7 +36342,7 @@ app.route({
|
|
|
36203
36342
|
path: "cnb",
|
|
36204
36343
|
key: "delete-repo",
|
|
36205
36344
|
description: "删除代码仓库, 参数name",
|
|
36206
|
-
middleware: ["auth
|
|
36345
|
+
middleware: ["auth"],
|
|
36207
36346
|
metadata: {
|
|
36208
36347
|
tags: ["opencode"],
|
|
36209
36348
|
...createSkill({
|
|
@@ -36216,11 +36355,57 @@ app.route({
|
|
|
36216
36355
|
})
|
|
36217
36356
|
}
|
|
36218
36357
|
}).define(async (ctx) => {
|
|
36358
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36359
|
+
const name = ctx.query?.name;
|
|
36360
|
+
if (!name) {
|
|
36361
|
+
ctx.throw(400, "缺少参数 name");
|
|
36362
|
+
}
|
|
36363
|
+
try {
|
|
36364
|
+
const resCookie = await cnb2.user.checkCookieValid();
|
|
36365
|
+
if (resCookie.code !== 200) {
|
|
36366
|
+
ctx.throw(401, "Cookie 无效或已过期");
|
|
36367
|
+
}
|
|
36368
|
+
const res = await cnb2.repo.deleteRepoCookie(name);
|
|
36369
|
+
ctx.forward(res);
|
|
36370
|
+
} catch (error49) {
|
|
36371
|
+
ctx.code = 200;
|
|
36372
|
+
ctx.body = { content: "已经删除" };
|
|
36373
|
+
}
|
|
36374
|
+
}).addTo(app);
|
|
36375
|
+
app.route({
|
|
36376
|
+
path: "cnb",
|
|
36377
|
+
key: "update-repo-info",
|
|
36378
|
+
description: "更新代码仓库信息, 参数name, description",
|
|
36379
|
+
middleware: ["auth"],
|
|
36380
|
+
metadata: {
|
|
36381
|
+
tags: ["opencode"],
|
|
36382
|
+
...createSkill({
|
|
36383
|
+
skill: "update-repo-info",
|
|
36384
|
+
title: "更新代码仓库信息",
|
|
36385
|
+
args: {
|
|
36386
|
+
name: tool.schema.string().describe("代码仓库名称"),
|
|
36387
|
+
description: tool.schema.string().describe("代码仓库描述"),
|
|
36388
|
+
license: tool.schema.string().describe("代码仓库许可证类型,如 MIT").optional(),
|
|
36389
|
+
site: tool.schema.string().describe("代码仓库主页链接").optional(),
|
|
36390
|
+
topics: tool.schema.array(tool.schema.string()).describe("代码仓库话题标签列表").optional()
|
|
36391
|
+
},
|
|
36392
|
+
summary: "更新代码仓库的信息"
|
|
36393
|
+
})
|
|
36394
|
+
}
|
|
36395
|
+
}).define(async (ctx) => {
|
|
36396
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36219
36397
|
const name = ctx.query?.name;
|
|
36398
|
+
const description = ctx.query?.description;
|
|
36399
|
+
const license = ctx.query?.license;
|
|
36400
|
+
const site = ctx.query?.site;
|
|
36401
|
+
const topics = ctx.query?.topics;
|
|
36220
36402
|
if (!name) {
|
|
36221
36403
|
ctx.throw(400, "缺少参数 name");
|
|
36222
36404
|
}
|
|
36223
|
-
|
|
36405
|
+
if (!description) {
|
|
36406
|
+
ctx.throw(400, "缺少参数 description");
|
|
36407
|
+
}
|
|
36408
|
+
const res = await cnb2.repo.updateRepoInfo(name, { description, license, site, topics });
|
|
36224
36409
|
ctx.forward(res);
|
|
36225
36410
|
}).addTo(app);
|
|
36226
36411
|
|
|
@@ -36229,7 +36414,7 @@ app.route({
|
|
|
36229
36414
|
path: "cnb",
|
|
36230
36415
|
key: "clean-closed-workspace",
|
|
36231
36416
|
description: "批量删除已停止的cnb工作空间",
|
|
36232
|
-
middleware: ["auth
|
|
36417
|
+
middleware: ["auth"],
|
|
36233
36418
|
metadata: {
|
|
36234
36419
|
tags: ["opencode"],
|
|
36235
36420
|
...createSkill({
|
|
@@ -36239,7 +36424,8 @@ app.route({
|
|
|
36239
36424
|
})
|
|
36240
36425
|
}
|
|
36241
36426
|
}).define(async (ctx) => {
|
|
36242
|
-
const
|
|
36427
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36428
|
+
const closedWorkspaces = await cnb2.workspace.list({ status: "closed", pageSize: 100 });
|
|
36243
36429
|
if (closedWorkspaces.code !== 200) {
|
|
36244
36430
|
ctx.throw(500, "获取已关闭工作空间列表失败");
|
|
36245
36431
|
}
|
|
@@ -36251,7 +36437,7 @@ app.route({
|
|
|
36251
36437
|
const sns = list.map((ws) => ws.sn);
|
|
36252
36438
|
const results = [];
|
|
36253
36439
|
for (const sn of sns) {
|
|
36254
|
-
const res = await
|
|
36440
|
+
const res = await cnb2.workspace.deleteWorkspace({ sn });
|
|
36255
36441
|
results.push(res);
|
|
36256
36442
|
}
|
|
36257
36443
|
ctx.forward({ code: 200, message: "已关闭的工作空间删除完成", data: results });
|
|
@@ -36340,12 +36526,12 @@ function removeKeepAliveData(repo2, pipelineId) {
|
|
|
36340
36526
|
}
|
|
36341
36527
|
}
|
|
36342
36528
|
var createLiveData = (data) => {
|
|
36343
|
-
const { cookie, repo: repo2, pipelineId } = data;
|
|
36529
|
+
const { cookie: cookie2, repo: repo2, pipelineId } = data;
|
|
36344
36530
|
const createdTime = Date.now();
|
|
36345
36531
|
const wsUrl = `wss://${pipelineId}.cnb.space:443?skipWebSocketFrames=false`;
|
|
36346
36532
|
const pm2Name = `keep_${repo2}__${pipelineId}`.replace(/\//g, "__");
|
|
36347
36533
|
const filePath = path2.join(baseDir, `${pm2Name}.json`);
|
|
36348
|
-
const _newData = { wss: wsUrl, wsUrl, cookie, repo: repo2, pipelineId, createdTime, filePath, pm2Name };
|
|
36534
|
+
const _newData = { wss: wsUrl, wsUrl, cookie: cookie2, repo: repo2, pipelineId, createdTime, filePath, pm2Name };
|
|
36349
36535
|
if (!fs2.existsSync(path2.dirname(filePath))) {
|
|
36350
36536
|
fs2.mkdirSync(path2.dirname(filePath), { recursive: true });
|
|
36351
36537
|
}
|
|
@@ -36358,7 +36544,7 @@ app.route({
|
|
|
36358
36544
|
path: "cnb",
|
|
36359
36545
|
key: "keep-workspace-alive",
|
|
36360
36546
|
description: "保持工作空间存活技能,参数repo:代码仓库路径,例如 user/repo,pipelineId:流水线ID,例如 cnb-708-1ji9sog7o-001",
|
|
36361
|
-
middleware: ["auth
|
|
36547
|
+
middleware: ["auth"],
|
|
36362
36548
|
metadata: {
|
|
36363
36549
|
tags: [],
|
|
36364
36550
|
...{
|
|
@@ -36369,16 +36555,19 @@ app.route({
|
|
|
36369
36555
|
}
|
|
36370
36556
|
}
|
|
36371
36557
|
}).define(async (ctx) => {
|
|
36558
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36372
36559
|
const repo2 = ctx.query?.repo;
|
|
36373
36560
|
const pipelineId = ctx.query?.pipelineId;
|
|
36561
|
+
if (notCNBCheck(ctx))
|
|
36562
|
+
return;
|
|
36374
36563
|
if (!repo2 || !pipelineId) {
|
|
36375
36564
|
ctx.throw(400, "缺少参数 repo 或 pipelineId");
|
|
36376
36565
|
}
|
|
36377
|
-
const validCookie = await
|
|
36566
|
+
const validCookie = await cnb2.user.checkCookieValid();
|
|
36378
36567
|
if (validCookie.code !== 200) {
|
|
36379
36568
|
ctx.throw(401, "CNB_COOKIE 环境变量无效或已过期,请重新登录获取新的cookie");
|
|
36380
36569
|
}
|
|
36381
|
-
const res = await
|
|
36570
|
+
const res = await cnb2.workspace.getWorkspaceCookie(repo2, pipelineId);
|
|
36382
36571
|
if (res.code !== 200 || !res.data?.cookie) {
|
|
36383
36572
|
ctx.throw(500, `获取工作空间 Cookie 失败: ${res.message}`);
|
|
36384
36573
|
}
|
|
@@ -36395,7 +36584,7 @@ app.route({
|
|
|
36395
36584
|
path: "cnb",
|
|
36396
36585
|
key: "stop-keep-workspace-alive",
|
|
36397
36586
|
description: "停止保持工作空间存活技能, 参数repo:代码仓库路径,例如 user/repo,pipelineId:流水线ID,例如 cnb-708-1ji9sog7o-001",
|
|
36398
|
-
middleware: ["auth
|
|
36587
|
+
middleware: ["auth"],
|
|
36399
36588
|
metadata: {
|
|
36400
36589
|
tags: [],
|
|
36401
36590
|
...{
|
|
@@ -36406,6 +36595,8 @@ app.route({
|
|
|
36406
36595
|
}
|
|
36407
36596
|
}
|
|
36408
36597
|
}).define(async (ctx) => {
|
|
36598
|
+
if (notCNBCheck(ctx))
|
|
36599
|
+
return;
|
|
36409
36600
|
const repo2 = ctx.query?.repo;
|
|
36410
36601
|
const pipelineId = ctx.query?.pipelineId;
|
|
36411
36602
|
if (!repo2 || !pipelineId) {
|
|
@@ -36418,7 +36609,7 @@ app.route({
|
|
|
36418
36609
|
path: "cnb",
|
|
36419
36610
|
key: "keep-alive-current-workspace",
|
|
36420
36611
|
description: "保持当前工作空间存活技能",
|
|
36421
|
-
middleware: ["auth
|
|
36612
|
+
middleware: ["auth"],
|
|
36422
36613
|
metadata: {
|
|
36423
36614
|
tags: ["opencode"],
|
|
36424
36615
|
skill: "keep-alive-current-workspace",
|
|
@@ -36426,6 +36617,8 @@ app.route({
|
|
|
36426
36617
|
summary: "保持当前工作空间存活,防止被关闭或释放资源"
|
|
36427
36618
|
}
|
|
36428
36619
|
}).define(async (ctx) => {
|
|
36620
|
+
if (notCNBCheck(ctx))
|
|
36621
|
+
return;
|
|
36429
36622
|
const pipelineId = useKey("CNB_PIPELINE_ID");
|
|
36430
36623
|
const repo2 = useKey("CNB_REPO_SLUG_LOWERCASE");
|
|
36431
36624
|
if (!pipelineId || !repo2) {
|
|
@@ -36435,12 +36628,52 @@ app.route({
|
|
|
36435
36628
|
ctx.forward(res);
|
|
36436
36629
|
}).addTo(app);
|
|
36437
36630
|
|
|
36631
|
+
// agent/routes/workspace/build.ts
|
|
36632
|
+
app.route({
|
|
36633
|
+
path: "cnb",
|
|
36634
|
+
key: "cloud-build",
|
|
36635
|
+
description: "云端构建,参数 event, repo, branch, ref, config, env",
|
|
36636
|
+
middleware: ["auth"],
|
|
36637
|
+
metadata: {
|
|
36638
|
+
tags: ["opencode"],
|
|
36639
|
+
...createSkill({
|
|
36640
|
+
skill: "cloud-build",
|
|
36641
|
+
title: "云端构建",
|
|
36642
|
+
summary: "在云端构建代码仓库,参数包括 event, repo, branch, ref, config, env",
|
|
36643
|
+
args: {
|
|
36644
|
+
env: tool.schema.any().optional().describe('构建环境变量,格式为 { "KEY": "VALUE" }'),
|
|
36645
|
+
event: tool.schema.string().optional().describe("触发事件类型,例如 api_trigger_event"),
|
|
36646
|
+
branch: tool.schema.string().optional().describe("分支名称,默认主分支"),
|
|
36647
|
+
config: tool.schema.string().describe("构建config文件内容,例如 cloudbuild.yaml对应的yml的内容"),
|
|
36648
|
+
repo: tool.schema.string().describe("代码仓库路径,例如 user/repo")
|
|
36649
|
+
}
|
|
36650
|
+
})
|
|
36651
|
+
}
|
|
36652
|
+
}).define(async (ctx) => {
|
|
36653
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36654
|
+
const repo2 = ctx.query?.repo;
|
|
36655
|
+
const branch = ctx.query?.branch || "main";
|
|
36656
|
+
const config3 = ctx.query?.config;
|
|
36657
|
+
const event = ctx.query?.event || "api_trigger_event";
|
|
36658
|
+
const env = ctx.query?.env ?? {};
|
|
36659
|
+
if (!repo2) {
|
|
36660
|
+
ctx.throw(400, "缺少参数 repo");
|
|
36661
|
+
}
|
|
36662
|
+
const res = await cnb2.build.startBuild(repo2, {
|
|
36663
|
+
branch,
|
|
36664
|
+
config: config3,
|
|
36665
|
+
event,
|
|
36666
|
+
env
|
|
36667
|
+
});
|
|
36668
|
+
ctx.forward(res);
|
|
36669
|
+
}).addTo(app);
|
|
36670
|
+
|
|
36438
36671
|
// agent/routes/workspace/index.ts
|
|
36439
36672
|
app.route({
|
|
36440
36673
|
path: "cnb",
|
|
36441
36674
|
key: "start-workspace",
|
|
36442
36675
|
description: "启动开发工作空间, 参数 repo",
|
|
36443
|
-
middleware: ["auth
|
|
36676
|
+
middleware: ["auth"],
|
|
36444
36677
|
metadata: {
|
|
36445
36678
|
tags: ["opencode"],
|
|
36446
36679
|
...createSkill({
|
|
@@ -36455,13 +36688,14 @@ app.route({
|
|
|
36455
36688
|
})
|
|
36456
36689
|
}
|
|
36457
36690
|
}).define(async (ctx) => {
|
|
36691
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36458
36692
|
const repo2 = ctx.query?.repo;
|
|
36459
36693
|
const branch = ctx.query?.branch;
|
|
36460
36694
|
const ref = ctx.query?.ref;
|
|
36461
36695
|
if (!repo2) {
|
|
36462
36696
|
ctx.throw(400, "缺少参数 repo");
|
|
36463
36697
|
}
|
|
36464
|
-
const res = await
|
|
36698
|
+
const res = await cnb2.workspace.startWorkspace(repo2, {
|
|
36465
36699
|
branch,
|
|
36466
36700
|
ref
|
|
36467
36701
|
});
|
|
@@ -36471,7 +36705,7 @@ app.route({
|
|
|
36471
36705
|
path: "cnb",
|
|
36472
36706
|
key: "list-workspace",
|
|
36473
36707
|
description: "获取cnb开发工作空间列表,可选参数 status=running 获取运行中的环境",
|
|
36474
|
-
middleware: ["auth
|
|
36708
|
+
middleware: ["auth"],
|
|
36475
36709
|
metadata: {
|
|
36476
36710
|
tags: ["opencode"],
|
|
36477
36711
|
...createSkill({
|
|
@@ -36488,19 +36722,20 @@ app.route({
|
|
|
36488
36722
|
})
|
|
36489
36723
|
}
|
|
36490
36724
|
}).define(async (ctx) => {
|
|
36725
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36491
36726
|
const { status = "running", page, pageSize, slug, branch } = ctx.query || {};
|
|
36492
|
-
const res = await
|
|
36727
|
+
const res = await cnb2.workspace.list({
|
|
36493
36728
|
status,
|
|
36494
36729
|
page: page ?? 1,
|
|
36495
36730
|
pageSize: pageSize ?? 100
|
|
36496
36731
|
});
|
|
36497
|
-
ctx.forward(
|
|
36732
|
+
ctx.forward(res);
|
|
36498
36733
|
}).addTo(app);
|
|
36499
36734
|
app.route({
|
|
36500
36735
|
path: "cnb",
|
|
36501
36736
|
key: "get-workspace",
|
|
36502
36737
|
description: "获取工作空间详情,通过 repo 和 sn 获取",
|
|
36503
|
-
middleware: ["auth
|
|
36738
|
+
middleware: ["auth"],
|
|
36504
36739
|
metadata: {
|
|
36505
36740
|
tags: ["opencode"],
|
|
36506
36741
|
...createSkill({
|
|
@@ -36514,6 +36749,7 @@ app.route({
|
|
|
36514
36749
|
})
|
|
36515
36750
|
}
|
|
36516
36751
|
}).define(async (ctx) => {
|
|
36752
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36517
36753
|
const repo2 = ctx.query?.repo;
|
|
36518
36754
|
const sn = ctx.query?.sn;
|
|
36519
36755
|
if (!repo2) {
|
|
@@ -36522,14 +36758,14 @@ app.route({
|
|
|
36522
36758
|
if (!sn) {
|
|
36523
36759
|
ctx.throw(400, "缺少参数 sn");
|
|
36524
36760
|
}
|
|
36525
|
-
const res = await
|
|
36526
|
-
ctx.forward(
|
|
36761
|
+
const res = await cnb2.workspace.getDetail(repo2, sn);
|
|
36762
|
+
ctx.forward(res);
|
|
36527
36763
|
}).addTo(app);
|
|
36528
36764
|
app.route({
|
|
36529
36765
|
path: "cnb",
|
|
36530
36766
|
key: "delete-workspace",
|
|
36531
36767
|
description: "删除工作空间,通过 pipelineId 或 sn",
|
|
36532
|
-
middleware: ["auth
|
|
36768
|
+
middleware: ["auth"],
|
|
36533
36769
|
metadata: {
|
|
36534
36770
|
tags: ["opencode"],
|
|
36535
36771
|
...createSkill({
|
|
@@ -36544,6 +36780,7 @@ app.route({
|
|
|
36544
36780
|
})
|
|
36545
36781
|
}
|
|
36546
36782
|
}).define(async (ctx) => {
|
|
36783
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36547
36784
|
const pipelineId = ctx.query?.pipelineId;
|
|
36548
36785
|
const sn = ctx.query?.sn;
|
|
36549
36786
|
const sns = ctx.query?.sns;
|
|
@@ -36553,20 +36790,20 @@ app.route({
|
|
|
36553
36790
|
if (sns && sns.length > 0) {
|
|
36554
36791
|
const results = [];
|
|
36555
36792
|
for (const snItem of sns) {
|
|
36556
|
-
const res2 = await
|
|
36793
|
+
const res2 = await cnb2.workspace.deleteWorkspace({ sn: snItem });
|
|
36557
36794
|
results.push(res2);
|
|
36558
36795
|
}
|
|
36559
36796
|
ctx.forward({ code: 200, message: "success", data: results });
|
|
36560
36797
|
return;
|
|
36561
36798
|
}
|
|
36562
|
-
const res = await
|
|
36799
|
+
const res = await cnb2.workspace.deleteWorkspace({ pipelineId, sn });
|
|
36563
36800
|
ctx.forward(res);
|
|
36564
36801
|
}).addTo(app);
|
|
36565
36802
|
app.route({
|
|
36566
36803
|
path: "cnb",
|
|
36567
36804
|
key: "stop-workspace",
|
|
36568
36805
|
description: "停止工作空间,通过 pipelineId 或 sn",
|
|
36569
|
-
middleware: ["auth
|
|
36806
|
+
middleware: ["auth"],
|
|
36570
36807
|
metadata: {
|
|
36571
36808
|
tags: ["opencode"],
|
|
36572
36809
|
...createSkill({
|
|
@@ -36580,13 +36817,14 @@ app.route({
|
|
|
36580
36817
|
})
|
|
36581
36818
|
}
|
|
36582
36819
|
}).define(async (ctx) => {
|
|
36820
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36583
36821
|
const pipelineId = ctx.query?.pipelineId;
|
|
36584
36822
|
const sn = ctx.query?.sn;
|
|
36585
36823
|
if (!pipelineId && !sn) {
|
|
36586
36824
|
ctx.throw(400, "pipelineId 和 sn 必须提供其中一个");
|
|
36587
36825
|
}
|
|
36588
|
-
const res = await
|
|
36589
|
-
ctx.forward(
|
|
36826
|
+
const res = await cnb2.workspace.stopWorkspace({ pipelineId, sn });
|
|
36827
|
+
ctx.forward(res);
|
|
36590
36828
|
}).addTo(app);
|
|
36591
36829
|
|
|
36592
36830
|
// agent/routes/call/index.ts
|
|
@@ -36643,7 +36881,7 @@ app.route({
|
|
|
36643
36881
|
path: "cnb",
|
|
36644
36882
|
key: "get-cnb-port-uri",
|
|
36645
36883
|
description: "获取当前cnb工作空间的port代理uri",
|
|
36646
|
-
middleware: ["auth
|
|
36884
|
+
middleware: ["auth"],
|
|
36647
36885
|
metadata: {
|
|
36648
36886
|
tags: ["opencode"],
|
|
36649
36887
|
...createSkill({
|
|
@@ -36656,6 +36894,8 @@ app.route({
|
|
|
36656
36894
|
})
|
|
36657
36895
|
}
|
|
36658
36896
|
}).define(async (ctx) => {
|
|
36897
|
+
if (notCNBCheck(ctx))
|
|
36898
|
+
return;
|
|
36659
36899
|
const port = ctx.query?.port || 51515;
|
|
36660
36900
|
const uri = CNB_ENV?.CNB_VSCODE_PROXY_URI || "";
|
|
36661
36901
|
const finalUri = uri.replace("{{port}}", port.toString());
|
|
@@ -36668,7 +36908,7 @@ app.route({
|
|
|
36668
36908
|
path: "cnb",
|
|
36669
36909
|
key: "get-cnb-vscode-uri",
|
|
36670
36910
|
description: "获取当前cnb工作空间的vscode代理uri, 包括多种访问方式, 如web、vscode、codebuddy、cursor、ssh",
|
|
36671
|
-
middleware: ["auth
|
|
36911
|
+
middleware: ["auth"],
|
|
36672
36912
|
metadata: {
|
|
36673
36913
|
tags: ["opencode"],
|
|
36674
36914
|
...createSkill({
|
|
@@ -36685,6 +36925,8 @@ app.route({
|
|
|
36685
36925
|
})
|
|
36686
36926
|
}
|
|
36687
36927
|
}).define(async (ctx) => {
|
|
36928
|
+
if (notCNBCheck(ctx))
|
|
36929
|
+
return;
|
|
36688
36930
|
const web = ctx.query?.web ?? false;
|
|
36689
36931
|
const vscode = ctx.query?.vscode ?? true;
|
|
36690
36932
|
const codebuddy = ctx.query?.codebuddy ?? false;
|
|
@@ -36729,7 +36971,7 @@ app.route({
|
|
|
36729
36971
|
path: "cnb",
|
|
36730
36972
|
key: "set-cnb-cookie",
|
|
36731
36973
|
description: "设置当前cnb工作空间的cookie环境变量",
|
|
36732
|
-
middleware: ["auth
|
|
36974
|
+
middleware: ["auth"],
|
|
36733
36975
|
metadata: {
|
|
36734
36976
|
tags: ["opencode"],
|
|
36735
36977
|
...createSkill({
|
|
@@ -36742,19 +36984,20 @@ app.route({
|
|
|
36742
36984
|
})
|
|
36743
36985
|
}
|
|
36744
36986
|
}).define(async (ctx) => {
|
|
36745
|
-
const
|
|
36746
|
-
|
|
36987
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
36988
|
+
const cookie2 = ctx.query?.cookie;
|
|
36989
|
+
if (!cookie2) {
|
|
36747
36990
|
ctx.body = { content: "请提供有效的cookie值" };
|
|
36748
36991
|
return;
|
|
36749
36992
|
}
|
|
36750
|
-
|
|
36993
|
+
cnb2.cookie = cookie2;
|
|
36751
36994
|
ctx.body = { content: "已成功设置cnb的cookie环境变量" };
|
|
36752
36995
|
}).addTo(app);
|
|
36753
36996
|
app.route({
|
|
36754
36997
|
path: "cnb",
|
|
36755
36998
|
key: "get-cnb-cookie",
|
|
36756
36999
|
description: "获取当前cnb工作空间的cookie环境变量",
|
|
36757
|
-
middleware: ["auth
|
|
37000
|
+
middleware: ["auth"],
|
|
36758
37001
|
metadata: {
|
|
36759
37002
|
tags: ["opencode"],
|
|
36760
37003
|
...createSkill({
|
|
@@ -36764,8 +37007,9 @@ app.route({
|
|
|
36764
37007
|
})
|
|
36765
37008
|
}
|
|
36766
37009
|
}).define(async (ctx) => {
|
|
36767
|
-
const
|
|
36768
|
-
|
|
37010
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
37011
|
+
const cookie2 = cnb2.cookie || "未设置cookie环境变量";
|
|
37012
|
+
ctx.body = { content: `当前cnb工作空间的cookie环境变量为:${cookie2}` };
|
|
36769
37013
|
}).addTo(app);
|
|
36770
37014
|
|
|
36771
37015
|
// node_modules/.pnpm/@kevisual+ai@0.0.26/node_modules/@kevisual/ai/dist/ai-provider-browser.js
|
|
@@ -56623,7 +56867,7 @@ app.route({
|
|
|
56623
56867
|
path: "cnb",
|
|
56624
56868
|
key: "cnb-ai-chat",
|
|
56625
56869
|
description: "调用cnb的知识库ai对话功能进行聊天",
|
|
56626
|
-
middleware: ["auth
|
|
56870
|
+
middleware: ["auth"],
|
|
56627
56871
|
metadata: {
|
|
56628
56872
|
tags: ["opencode"],
|
|
56629
56873
|
...createSkill({
|
|
@@ -56637,6 +56881,7 @@ app.route({
|
|
|
56637
56881
|
})
|
|
56638
56882
|
}
|
|
56639
56883
|
}).define(async (ctx) => {
|
|
56884
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
56640
56885
|
const question = ctx.query?.question;
|
|
56641
56886
|
if (!question) {
|
|
56642
56887
|
ctx.body = { content: "请提供有效的消息内容" };
|
|
@@ -56644,13 +56889,13 @@ app.route({
|
|
|
56644
56889
|
}
|
|
56645
56890
|
let repo2 = ctx.query?.repo;
|
|
56646
56891
|
if (!repo2) {
|
|
56647
|
-
const res = await
|
|
56892
|
+
const res = await cnb2.repo.getRepoList({ flags: "KnowledgeBase" });
|
|
56648
56893
|
if (res.code === 200 && res.data.length > 0) {
|
|
56649
56894
|
repo2 = res.data[0].path;
|
|
56650
56895
|
}
|
|
56651
56896
|
}
|
|
56652
56897
|
console.log("Using knowledge base repo:", repo2);
|
|
56653
|
-
const ragRes = await
|
|
56898
|
+
const ragRes = await cnb2.knowledgeBase.queryKnowledgeBase(repo2 || "", {
|
|
56654
56899
|
query: question,
|
|
56655
56900
|
score_threshold: 0.62,
|
|
56656
56901
|
top_k: 10
|
|
@@ -56675,7 +56920,7 @@ ${item.chunk}
|
|
|
56675
56920
|
`);
|
|
56676
56921
|
const chat = new CNBChat({
|
|
56677
56922
|
repo: repo2,
|
|
56678
|
-
token:
|
|
56923
|
+
token: cnb2.token,
|
|
56679
56924
|
model: "hunyuan-a13b"
|
|
56680
56925
|
});
|
|
56681
56926
|
const messages = [
|
|
@@ -56725,7 +56970,7 @@ app.route({
|
|
|
56725
56970
|
path: "cnb",
|
|
56726
56971
|
key: "cnb-rag-query",
|
|
56727
56972
|
description: "调用cnb的知识库RAG查询功能进行问答",
|
|
56728
|
-
middleware: ["auth
|
|
56973
|
+
middleware: ["auth"],
|
|
56729
56974
|
metadata: {
|
|
56730
56975
|
tags: ["opencode"],
|
|
56731
56976
|
...createSkill({
|
|
@@ -56739,6 +56984,7 @@ app.route({
|
|
|
56739
56984
|
})
|
|
56740
56985
|
}
|
|
56741
56986
|
}).define(async (ctx) => {
|
|
56987
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
56742
56988
|
const question = ctx.query?.question;
|
|
56743
56989
|
if (!question) {
|
|
56744
56990
|
ctx.body = { content: "请提供有效的消息内容" };
|
|
@@ -56746,13 +56992,13 @@ app.route({
|
|
|
56746
56992
|
}
|
|
56747
56993
|
let repo2 = ctx.query?.repo || useKey("CNB_REPO_SLUG_LOWERCASE");
|
|
56748
56994
|
if (!repo2) {
|
|
56749
|
-
const res = await
|
|
56995
|
+
const res = await cnb2.repo.getRepoList({ flags: "KnowledgeBase" });
|
|
56750
56996
|
if (res.code === 200 && res.data.length > 0) {
|
|
56751
56997
|
repo2 = res.data[0].path;
|
|
56752
56998
|
}
|
|
56753
56999
|
}
|
|
56754
57000
|
console.log("Using knowledge base repo:", repo2);
|
|
56755
|
-
const ragRes = await
|
|
57001
|
+
const ragRes = await cnb2.knowledgeBase.queryKnowledgeBase(repo2 || "", {
|
|
56756
57002
|
query: question,
|
|
56757
57003
|
score_threshold: 0.62,
|
|
56758
57004
|
top_k: 10
|
|
@@ -56788,7 +57034,7 @@ app.route({
|
|
|
56788
57034
|
path: "cnb",
|
|
56789
57035
|
key: "list-issues",
|
|
56790
57036
|
description: "查询 Issue 列表, 参数 repo, state, keyword, labels, page, page_size 等",
|
|
56791
|
-
middleware: ["auth
|
|
57037
|
+
middleware: ["auth"],
|
|
56792
57038
|
metadata: {
|
|
56793
57039
|
tags: ["opencode"],
|
|
56794
57040
|
...createSkill({
|
|
@@ -56807,6 +57053,7 @@ app.route({
|
|
|
56807
57053
|
})
|
|
56808
57054
|
}
|
|
56809
57055
|
}).define(async (ctx) => {
|
|
57056
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
56810
57057
|
const repo2 = ctx.query?.repo || useKey("CNB_REPO_SLUG_LOWERCASE");
|
|
56811
57058
|
const state = ctx.query?.state;
|
|
56812
57059
|
const keyword = ctx.query?.keyword;
|
|
@@ -56830,7 +57077,7 @@ app.route({
|
|
|
56830
57077
|
params.page_size = page_size;
|
|
56831
57078
|
if (order_by)
|
|
56832
57079
|
params.order_by = order_by;
|
|
56833
|
-
const res = await
|
|
57080
|
+
const res = await cnb2.issue.getList(repo2, params);
|
|
56834
57081
|
ctx.forward(res);
|
|
56835
57082
|
}).addTo(app);
|
|
56836
57083
|
|
|
@@ -56839,7 +57086,7 @@ app.route({
|
|
|
56839
57086
|
path: "cnb",
|
|
56840
57087
|
key: "create-issue",
|
|
56841
57088
|
description: "创建 Issue, 参数 repo, title, body, assignees, labels, priority",
|
|
56842
|
-
middleware: ["auth
|
|
57089
|
+
middleware: ["auth"],
|
|
56843
57090
|
metadata: {
|
|
56844
57091
|
tags: ["opencode"],
|
|
56845
57092
|
...createSkill({
|
|
@@ -56857,6 +57104,7 @@ app.route({
|
|
|
56857
57104
|
})
|
|
56858
57105
|
}
|
|
56859
57106
|
}).define(async (ctx) => {
|
|
57107
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
56860
57108
|
const repo2 = ctx.query?.repo;
|
|
56861
57109
|
const title = ctx.query?.title;
|
|
56862
57110
|
const body = ctx.query?.body;
|
|
@@ -56866,7 +57114,7 @@ app.route({
|
|
|
56866
57114
|
if (!repo2 || !title) {
|
|
56867
57115
|
ctx.throw(400, "缺少参数 repo 或 title");
|
|
56868
57116
|
}
|
|
56869
|
-
const res = await
|
|
57117
|
+
const res = await cnb2.issue.createIssue(repo2, {
|
|
56870
57118
|
title,
|
|
56871
57119
|
body,
|
|
56872
57120
|
assignees,
|
|
@@ -56879,7 +57127,7 @@ app.route({
|
|
|
56879
57127
|
path: "cnb",
|
|
56880
57128
|
key: "complete-issue",
|
|
56881
57129
|
description: "完成 Issue, 参数 repo, issueNumber",
|
|
56882
|
-
middleware: ["auth
|
|
57130
|
+
middleware: ["auth"],
|
|
56883
57131
|
metadata: {
|
|
56884
57132
|
tags: ["opencode"],
|
|
56885
57133
|
...createSkill({
|
|
@@ -56894,6 +57142,7 @@ app.route({
|
|
|
56894
57142
|
})
|
|
56895
57143
|
}
|
|
56896
57144
|
}).define(async (ctx) => {
|
|
57145
|
+
const cnb2 = await cnbManager.getContext(ctx);
|
|
56897
57146
|
const repo2 = ctx.query?.repo;
|
|
56898
57147
|
const issueNumber = ctx.query?.issueNumber;
|
|
56899
57148
|
const state = ctx.query?.state ?? "closed";
|
|
@@ -56904,7 +57153,7 @@ app.route({
|
|
|
56904
57153
|
if (iss.state === "closed") {
|
|
56905
57154
|
iss.state_reason = "completed";
|
|
56906
57155
|
}
|
|
56907
|
-
const res = await
|
|
57156
|
+
const res = await cnb2.issue.updateIssue(repo2, issueNumber, iss);
|
|
56908
57157
|
ctx.forward(res);
|
|
56909
57158
|
}).addTo(app);
|
|
56910
57159
|
|
|
@@ -56915,15 +57164,15 @@ import { execSync as execSync2 } from "node:child_process";
|
|
|
56915
57164
|
var getLiveMdContent = (opts) => {
|
|
56916
57165
|
const more = opts?.more ?? false;
|
|
56917
57166
|
const url4 = useKey("CNB_VSCODE_PROXY_URI") || "";
|
|
56918
|
-
const
|
|
57167
|
+
const token2 = useKey("CNB_TOKEN") || "";
|
|
56919
57168
|
const openclawPort = useKey("OPENCLAW_PORT") || "80";
|
|
56920
57169
|
const openclawUrl = url4.replace("{{port}}", openclawPort);
|
|
56921
|
-
const openclawUrlSecret = openclawUrl + "/openclaw?token=" +
|
|
57170
|
+
const openclawUrlSecret = openclawUrl + "/openclaw?token=" + token2;
|
|
56922
57171
|
const opencodePort = useKey("OPENCODE_PORT") || "100";
|
|
56923
57172
|
const opencodeUrl = url4.replace("{{port}}", opencodePort);
|
|
56924
57173
|
const _opencodeURL = new URL(opencodeUrl);
|
|
56925
57174
|
_opencodeURL.username = "root";
|
|
56926
|
-
_opencodeURL.password =
|
|
57175
|
+
_opencodeURL.password = token2;
|
|
56927
57176
|
const opencodeUrlSecret = _opencodeURL.toString();
|
|
56928
57177
|
const kevisualUrl = url4.replace("{{port}}", "51515");
|
|
56929
57178
|
const openWebUrl = url4.replace("{{port}}", "200");
|
|
@@ -56943,7 +57192,7 @@ var getLiveMdContent = (opts) => {
|
|
|
56943
57192
|
- OpenCode: ${opencodeUrlSecret}
|
|
56944
57193
|
|
|
56945
57194
|
### 环境变量
|
|
56946
|
-
- CNB_TOKEN: ${
|
|
57195
|
+
- CNB_TOKEN: ${token2}
|
|
56947
57196
|
|
|
56948
57197
|
### 其他说明
|
|
56949
57198
|
|
|
@@ -56981,7 +57230,7 @@ Opencode打开web地址,需要在浏览器输入用户名和密码,用户名
|
|
|
56981
57230
|
{
|
|
56982
57231
|
key: "cnbTempToken",
|
|
56983
57232
|
title: "CNB Token",
|
|
56984
|
-
value:
|
|
57233
|
+
value: token2,
|
|
56985
57234
|
description: "CNB 临时 Token,保持和环境变量 CNB_TOKEN 一致"
|
|
56986
57235
|
},
|
|
56987
57236
|
{
|
|
@@ -57204,22 +57453,11 @@ var createOSInfo = (more = false) => {
|
|
|
57204
57453
|
};
|
|
57205
57454
|
|
|
57206
57455
|
// agent/routes/cnb-board/cnb-dev-env.ts
|
|
57207
|
-
var notCNBCheck = (ctx) => {
|
|
57208
|
-
const isCNB = useKey("CNB");
|
|
57209
|
-
if (!isCNB) {
|
|
57210
|
-
ctx.body = {
|
|
57211
|
-
title: "非 cnb-board 环境",
|
|
57212
|
-
list: []
|
|
57213
|
-
};
|
|
57214
|
-
return true;
|
|
57215
|
-
}
|
|
57216
|
-
return false;
|
|
57217
|
-
};
|
|
57218
57456
|
app.route({
|
|
57219
57457
|
path: "cnb_board",
|
|
57220
57458
|
key: "live",
|
|
57221
57459
|
description: "获取cnb-board live的mdContent内容",
|
|
57222
|
-
middleware: ["auth
|
|
57460
|
+
middleware: ["auth"],
|
|
57223
57461
|
metadata: {
|
|
57224
57462
|
args: {
|
|
57225
57463
|
more: zod_default.boolean().optional().describe("是否获取更多系统信息,默认false")
|
|
@@ -57239,7 +57477,7 @@ app.route({
|
|
|
57239
57477
|
path: "cnb_board",
|
|
57240
57478
|
key: "live_repo_info",
|
|
57241
57479
|
description: "获取cnb-board live的repo信息",
|
|
57242
|
-
middleware: ["auth
|
|
57480
|
+
middleware: ["auth"]
|
|
57243
57481
|
}).define(async (ctx) => {
|
|
57244
57482
|
const repoSlug = useKey("CNB_REPO_SLUG") || "";
|
|
57245
57483
|
const repoName = useKey("CNB_REPO_NAME") || "";
|
|
@@ -57289,7 +57527,7 @@ app.route({
|
|
|
57289
57527
|
path: "cnb_board",
|
|
57290
57528
|
key: "live_build_info",
|
|
57291
57529
|
description: "获取cnb-board live的构建信息",
|
|
57292
|
-
middleware: ["auth
|
|
57530
|
+
middleware: ["auth"]
|
|
57293
57531
|
}).define(async (ctx) => {
|
|
57294
57532
|
if (notCNBCheck(ctx))
|
|
57295
57533
|
return;
|
|
@@ -57645,8 +57883,10 @@ app.route({
|
|
|
57645
57883
|
path: "cnb_board",
|
|
57646
57884
|
key: "exit",
|
|
57647
57885
|
description: "cnb的工作环境退出程序",
|
|
57648
|
-
middleware: ["auth
|
|
57886
|
+
middleware: ["auth"]
|
|
57649
57887
|
}).define(async (ctx) => {
|
|
57888
|
+
if (notCNBCheck(ctx))
|
|
57889
|
+
return;
|
|
57650
57890
|
const cmd = "kill 1";
|
|
57651
57891
|
execCommand(cmd);
|
|
57652
57892
|
}).addTo(app);
|
|
@@ -57696,6 +57936,50 @@ app.route({
|
|
|
57696
57936
|
};
|
|
57697
57937
|
}).addTo(app);
|
|
57698
57938
|
|
|
57939
|
+
// agent/routes/cnb-manager/index.ts
|
|
57940
|
+
app.route({
|
|
57941
|
+
path: "cnb",
|
|
57942
|
+
key: "clear-me-manager",
|
|
57943
|
+
description: "清理我的cnb-manager记录",
|
|
57944
|
+
middleware: ["auth"]
|
|
57945
|
+
}).define(async (ctx) => {
|
|
57946
|
+
const tokenUser = ctx.tokenUser;
|
|
57947
|
+
if (!tokenUser) {
|
|
57948
|
+
ctx.throw(401, "未授权");
|
|
57949
|
+
}
|
|
57950
|
+
const username = tokenUser.username;
|
|
57951
|
+
if (!username) {
|
|
57952
|
+
ctx.throw(400, "无效的用户信息");
|
|
57953
|
+
}
|
|
57954
|
+
if (username !== "default") {
|
|
57955
|
+
cnbManager.clearUsername(username);
|
|
57956
|
+
}
|
|
57957
|
+
ctx.body = { content: "已清理cnb-manager记录" };
|
|
57958
|
+
}).addTo(app);
|
|
57959
|
+
app.route({
|
|
57960
|
+
path: "cnb",
|
|
57961
|
+
key: "get-my-config",
|
|
57962
|
+
description: "获取我的cnb配置",
|
|
57963
|
+
middleware: ["auth"]
|
|
57964
|
+
}).define(async (ctx) => {
|
|
57965
|
+
const username = ctx.tokenUser?.username;
|
|
57966
|
+
const token2 = ctx.query?.token;
|
|
57967
|
+
if (!username) {
|
|
57968
|
+
ctx.throw(400, "未授权");
|
|
57969
|
+
}
|
|
57970
|
+
if (!token2) {
|
|
57971
|
+
ctx.throw(400, "缺少token参数");
|
|
57972
|
+
}
|
|
57973
|
+
const cnbItem = await cnbManager.getCNB({ username, kevisualToken: token2 });
|
|
57974
|
+
if (!cnbItem) {
|
|
57975
|
+
ctx.throw(404, "未找到cnb-manager记录");
|
|
57976
|
+
}
|
|
57977
|
+
ctx.body = {
|
|
57978
|
+
token: cnbItem.token,
|
|
57979
|
+
cookie: cnbItem.cookie
|
|
57980
|
+
};
|
|
57981
|
+
}).addTo(app);
|
|
57982
|
+
|
|
57699
57983
|
// agent/routes/index.ts
|
|
57700
57984
|
var checkAppId = (ctx, appId) => {
|
|
57701
57985
|
const _appId = ctx?.app?.appId;
|
|
@@ -57712,6 +57996,9 @@ app.route({
|
|
|
57712
57996
|
path: "auth"
|
|
57713
57997
|
}).define(async (ctx) => {
|
|
57714
57998
|
if (checkAppId(ctx, app.appId)) {
|
|
57999
|
+
ctx.state.tokenUser = {
|
|
58000
|
+
username: "default"
|
|
58001
|
+
};
|
|
57715
58002
|
return;
|
|
57716
58003
|
}
|
|
57717
58004
|
}).addTo(app, { overwrite: false });
|
|
@@ -57721,6 +58008,9 @@ app.route({
|
|
|
57721
58008
|
middleware: ["auth"]
|
|
57722
58009
|
}).define(async (ctx) => {
|
|
57723
58010
|
if (checkAppId(ctx, app.appId)) {
|
|
58011
|
+
ctx.state.tokenUser = {
|
|
58012
|
+
username: "default"
|
|
58013
|
+
};
|
|
57724
58014
|
return;
|
|
57725
58015
|
}
|
|
57726
58016
|
}).addTo(app, { overwrite: false });
|
|
@@ -57741,7 +58031,7 @@ var {
|
|
|
57741
58031
|
Help
|
|
57742
58032
|
} = import__2.default;
|
|
57743
58033
|
|
|
57744
|
-
// node_modules/.pnpm/@kevisual+router@0.0.
|
|
58034
|
+
// node_modules/.pnpm/@kevisual+router@0.0.90/node_modules/@kevisual/router/src/commander.ts
|
|
57745
58035
|
var groupByPath = (routes) => {
|
|
57746
58036
|
return routes.reduce((acc, route) => {
|
|
57747
58037
|
const path3 = route.path || "default";
|
|
@@ -57809,7 +58099,7 @@ var createCommand2 = (opts) => {
|
|
|
57809
58099
|
for (const path3 in groupRoutes) {
|
|
57810
58100
|
const routeList = groupRoutes[path3];
|
|
57811
58101
|
const keys = routeList.map((route) => route.key).filter(Boolean);
|
|
57812
|
-
const subProgram = program2.command(path3).description(
|
|
58102
|
+
const subProgram = program2.command(path3).description(`路由[${path3}] ${keys.length > 0 ? ": " + keys.join(", ") : ""}`);
|
|
57813
58103
|
routeList.forEach((route) => {
|
|
57814
58104
|
if (!route.key)
|
|
57815
58105
|
return;
|
|
@@ -57841,12 +58131,13 @@ var createCommand2 = (opts) => {
|
|
|
57841
58131
|
};
|
|
57842
58132
|
var parse8 = (opts) => {
|
|
57843
58133
|
const { app: app3, description, parse: parse5 = true } = opts;
|
|
57844
|
-
program
|
|
57845
|
-
|
|
58134
|
+
const _program = opts.program || program;
|
|
58135
|
+
_program.description(description || "Router 命令行工具");
|
|
58136
|
+
createCommand2({ app: app3, program: _program });
|
|
57846
58137
|
if (parse5) {
|
|
57847
|
-
|
|
58138
|
+
_program.parse(process.argv);
|
|
57848
58139
|
}
|
|
57849
58140
|
};
|
|
57850
58141
|
|
|
57851
|
-
// agent/
|
|
58142
|
+
// agent/commander.ts
|
|
57852
58143
|
parse8({ app, description: "CNB控制台命令行工具", parse: true });
|