@kevisual/cnb 0.0.51 → 0.0.53

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/cli.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { app } from './index.ts';
2
2
  import { parse } from '@kevisual/router/src/commander.ts';
3
3
 
4
- parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
4
+ await parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
5
+
6
+ console.log('命令行工具已启动,输入 help 查看可用命令', 'end');
package/agent/npc.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { app } from './index.ts';
2
2
  import { parse } from '@kevisual/router/src/commander.ts';
3
3
 
4
- import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
4
+ import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabelItem } from '../src/index.ts'
5
5
  import { pick } from 'es-toolkit';
6
6
  import z from 'zod';
7
7
  import { useKey } from '@kevisual/context';
@@ -32,7 +32,7 @@ const getIssuesLabels = async () => {
32
32
  if (res.code === 200) {
33
33
  const issueData = res.data as any;
34
34
  const labels = issueData.labels || [];
35
- return labels as IssueLabel[];
35
+ return labels as IssueLabelItem[];
36
36
  }
37
37
  console.error('获取 Issue 详情失败', res);
38
38
  return []
@@ -0,0 +1,152 @@
1
+ import { createSkill, tool } from '@kevisual/router';
2
+ import { app, cnbManager } from '../../app.ts';
3
+
4
+ // 查询仓库标签列表
5
+ app.route({
6
+ path: 'cnb',
7
+ key: 'list-repo-labels',
8
+ description: '查询仓库的标签列表',
9
+ middleware: ['auth'],
10
+ metadata: {
11
+ tags: ['opencode'],
12
+ ...createSkill({
13
+ skill: 'list-repo-labels',
14
+ title: '查询仓库标签列表',
15
+ summary: '查询仓库的标签列表',
16
+ args: {
17
+ repo: tool.schema.string().describe('仓库路径, 如 my-user/my-repo'),
18
+ page: tool.schema.number().optional().describe('分页页码,默认 1'),
19
+ pageSize: tool.schema.number().optional().describe('分页每页大小,默认 30'),
20
+ keyword: tool.schema.string().optional().describe('标签搜索关键词'),
21
+ },
22
+ })
23
+ }
24
+ }).define(async (ctx) => {
25
+ const cnb = await cnbManager.getContext(ctx);
26
+ const repo = ctx.query?.repo;
27
+ const page = ctx.query?.page;
28
+ const pageSize = ctx.query?.pageSize;
29
+ const keyword = ctx.query?.keyword;
30
+
31
+ if (!repo) {
32
+ ctx.throw(400, '缺少参数 repo');
33
+ }
34
+
35
+ const res = await cnb.labels.repoLabel.list(repo, {
36
+ page,
37
+ page_size: pageSize,
38
+ keyword,
39
+ });
40
+ ctx.forward(res);
41
+ }).addTo(app);
42
+
43
+ // 创建标签
44
+ app.route({
45
+ path: 'cnb',
46
+ key: 'create-repo-label',
47
+ description: '创建仓库标签',
48
+ middleware: ['auth'],
49
+ metadata: {
50
+ tags: ['opencode'],
51
+ ...createSkill({
52
+ skill: 'create-repo-label',
53
+ title: '创建仓库标签',
54
+ summary: '创建一个仓库标签',
55
+ args: {
56
+ repo: tool.schema.string().describe('仓库路径, 如 my-user/my-repo'),
57
+ name: tool.schema.string().describe('标签名称'),
58
+ color: tool.schema.string().describe('标签颜色,十六进制颜色码,不含 # 前缀'),
59
+ description: tool.schema.string().optional().describe('标签描述'),
60
+ },
61
+ })
62
+ }
63
+ }).define(async (ctx) => {
64
+ const cnb = await cnbManager.getContext(ctx);
65
+ const repo = ctx.query?.repo;
66
+ const name = ctx.query?.name;
67
+ const color = ctx.query?.color;
68
+ const description = ctx.query?.description;
69
+
70
+ if (!repo || !name || !color) {
71
+ ctx.throw(400, '缺少参数 repo, name 或 color');
72
+ }
73
+
74
+ const res = await cnb.labels.repoLabel.create(repo, {
75
+ name,
76
+ color,
77
+ description,
78
+ });
79
+ ctx.forward(res);
80
+ }).addTo(app);
81
+
82
+ // 更新标签
83
+ app.route({
84
+ path: 'cnb',
85
+ key: 'update-repo-label',
86
+ description: '更新仓库标签',
87
+ middleware: ['auth'],
88
+ metadata: {
89
+ tags: ['opencode'],
90
+ ...createSkill({
91
+ skill: 'update-repo-label',
92
+ title: '更新仓库标签',
93
+ summary: '更新仓库标签信息',
94
+ args: {
95
+ repo: tool.schema.string().describe('仓库路径, 如 my-user/my-repo'),
96
+ name: tool.schema.string().describe('标签名称'),
97
+ color: tool.schema.string().optional().describe('标签颜色,十六进制颜色码,不含 # 前缀'),
98
+ description: tool.schema.string().optional().describe('标签描述'),
99
+ newName: tool.schema.string().optional().describe('新标签名称'),
100
+ },
101
+ })
102
+ }
103
+ }).define(async (ctx) => {
104
+ const cnb = await cnbManager.getContext(ctx);
105
+ const repo = ctx.query?.repo;
106
+ const name = ctx.query?.name;
107
+ const color = ctx.query?.color;
108
+ const description = ctx.query?.description;
109
+ const newName = ctx.query?.newName;
110
+
111
+ if (!repo || !name) {
112
+ ctx.throw(400, '缺少参数 repo 或 name');
113
+ }
114
+
115
+ const res = await cnb.labels.repoLabel.update(repo, name, {
116
+ color,
117
+ description,
118
+ new_name: newName,
119
+ });
120
+ ctx.forward(res);
121
+ }).addTo(app);
122
+
123
+ // 删除标签
124
+ app.route({
125
+ path: 'cnb',
126
+ key: 'delete-repo-label',
127
+ description: '删除仓库标签',
128
+ middleware: ['auth'],
129
+ metadata: {
130
+ tags: ['opencode'],
131
+ ...createSkill({
132
+ skill: 'delete-repo-label',
133
+ title: '删除仓库标签',
134
+ summary: '删除指定的仓库标签',
135
+ args: {
136
+ repo: tool.schema.string().describe('仓库路径, 如 my-user/my-repo'),
137
+ name: tool.schema.string().describe('标签名称'),
138
+ },
139
+ })
140
+ }
141
+ }).define(async (ctx) => {
142
+ const cnb = await cnbManager.getContext(ctx);
143
+ const repo = ctx.query?.repo;
144
+ const name = ctx.query?.name;
145
+
146
+ if (!repo || !name) {
147
+ ctx.throw(400, '缺少参数 repo 或 name');
148
+ }
149
+
150
+ const res = await cnb.labels.repoLabel.remove(repo, name);
151
+ ctx.forward(res);
152
+ }).addTo(app);
package/dist/cli.js CHANGED
@@ -4432,7 +4432,7 @@ var require_commander = __commonJS((exports) => {
4432
4432
  exports.InvalidOptionArgumentError = InvalidArgumentError3;
4433
4433
  });
4434
4434
 
4435
- // ../../node_modules/.pnpm/@kevisual+router@0.1.2/node_modules/@kevisual/router/dist/router.js
4435
+ // ../../node_modules/.pnpm/@kevisual+router@0.1.3/node_modules/@kevisual/router/dist/router.js
4436
4436
  import { createRequire as createRequire2 } from "node:module";
4437
4437
  import { webcrypto as crypto } from "node:crypto";
4438
4438
  import url2 from "node:url";
@@ -25101,6 +25101,78 @@ class AiBase extends CNBCore {
25101
25101
  }
25102
25102
  }
25103
25103
 
25104
+ // src/labels/repo-label.ts
25105
+ class RepoLabel extends CNBCore {
25106
+ constructor(options) {
25107
+ super(options);
25108
+ }
25109
+ list(repo, params) {
25110
+ const url3 = `/${repo}/-/labels`;
25111
+ return this.get({
25112
+ url: url3,
25113
+ params,
25114
+ headers: {
25115
+ Accept: "application/vnd.cnb.api+json"
25116
+ }
25117
+ });
25118
+ }
25119
+ create(repo, data) {
25120
+ const url3 = `/${repo}/-/labels`;
25121
+ return this.post({
25122
+ url: url3,
25123
+ data
25124
+ });
25125
+ }
25126
+ update(repo, name, data) {
25127
+ const url3 = `/${repo}/-/labels/${encodeURIComponent(name)}`;
25128
+ return this.patch({
25129
+ url: url3,
25130
+ data
25131
+ });
25132
+ }
25133
+ remove(repo, name) {
25134
+ const url3 = `/${repo}/-/labels/${encodeURIComponent(name)}`;
25135
+ return this.delete({ url: url3 });
25136
+ }
25137
+ }
25138
+
25139
+ class IssueLabel extends CNBCore {
25140
+ constructor(options) {
25141
+ super(options);
25142
+ }
25143
+ list(repo, number4, params) {
25144
+ const url3 = `/${repo}/-/issues/${number4}/labels`;
25145
+ return this.get({
25146
+ url: url3,
25147
+ params,
25148
+ headers: {
25149
+ Accept: "application/vnd.cnb.api+json"
25150
+ }
25151
+ });
25152
+ }
25153
+ set(repo, number4, data) {
25154
+ const url3 = `/${repo}/-/issues/${number4}/labels`;
25155
+ return this.put({
25156
+ url: url3,
25157
+ data
25158
+ });
25159
+ }
25160
+ add(repo, number4, data) {
25161
+ const url3 = `/${repo}/-/issues/${number4}/labels`;
25162
+ return this.post({
25163
+ url: url3,
25164
+ data
25165
+ });
25166
+ }
25167
+ clear(repo, number4) {
25168
+ const url3 = `/${repo}/-/issues/${number4}/labels`;
25169
+ return this.delete({ url: url3 });
25170
+ }
25171
+ remove(repo, number4, name) {
25172
+ const url3 = `/${repo}/-/issues/${number4}/labels/${encodeURIComponent(name)}`;
25173
+ return this.delete({ url: url3 });
25174
+ }
25175
+ }
25104
25176
  // src/index.ts
25105
25177
  class CNB extends CNBCore {
25106
25178
  workspace;
@@ -25111,6 +25183,7 @@ class CNB extends CNBCore {
25111
25183
  issue;
25112
25184
  mission;
25113
25185
  ai;
25186
+ labels;
25114
25187
  constructor(options) {
25115
25188
  super({ ...options, token: options.token, cookie: options.cookie, cnb: options.cnb });
25116
25189
  this.init(options);
@@ -25129,6 +25202,10 @@ class CNB extends CNBCore {
25129
25202
  this.issue = new Issue(options);
25130
25203
  this.mission = new Mission(options);
25131
25204
  this.ai = new AiBase(options);
25205
+ this.labels = {
25206
+ repoLabel: new RepoLabel(options),
25207
+ issueLabel: new IssueLabel(options)
25208
+ };
25132
25209
  }
25133
25210
  setToken(token) {
25134
25211
  this.token = token;
@@ -25138,6 +25215,8 @@ class CNB extends CNBCore {
25138
25215
  this.build.token = token;
25139
25216
  this.issue.token = token;
25140
25217
  this.mission.token = token;
25218
+ this.labels.repoLabel.token = token;
25219
+ this.labels.issueLabel.token = token;
25141
25220
  }
25142
25221
  setCookie(cookie) {
25143
25222
  this.cookie = cookie;
@@ -25147,8 +25226,15 @@ class CNB extends CNBCore {
25147
25226
  this.build.cookie = cookie;
25148
25227
  this.issue.cookie = cookie;
25149
25228
  this.mission.cookie = cookie;
25229
+ this.labels.repoLabel.cookie = cookie;
25230
+ this.labels.issueLabel.cookie = cookie;
25150
25231
  }
25232
+ getCNBVersion = getCNBVersion;
25151
25233
  }
25234
+ var getCNBVersion = () => {
25235
+ const url3 = "https://cnb.cool/api/version";
25236
+ return fetch(url3).then((res) => res.json());
25237
+ };
25152
25238
 
25153
25239
  // ../../node_modules/.pnpm/@ai-sdk+provider@3.0.8/node_modules/@ai-sdk/provider/dist/index.mjs
25154
25240
  var marker = "vercel.ai.error";
@@ -47948,7 +48034,7 @@ app.route({
47948
48034
  let repo2 = ctx.query?.repo || useKey("CNB_REPO_SLUG_LOWERCASE");
47949
48035
  const state = ctx.query?.state;
47950
48036
  const keyword = ctx.query?.keyword;
47951
- const labels = ctx.query?.labels;
48037
+ const labels2 = ctx.query?.labels;
47952
48038
  const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
47953
48039
  const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
47954
48040
  const order_by = ctx.query?.order_by;
@@ -47960,8 +48046,8 @@ app.route({
47960
48046
  params.state = state;
47961
48047
  if (keyword)
47962
48048
  params.keyword = keyword;
47963
- if (labels)
47964
- params.labels = labels;
48049
+ if (labels2)
48050
+ params.labels = labels2;
47965
48051
  if (page)
47966
48052
  params.page = page;
47967
48053
  if (page_size)
@@ -48030,7 +48116,7 @@ app.route({
48030
48116
  const title = ctx.query?.title;
48031
48117
  const body = ctx.query?.body;
48032
48118
  const assignees = ctx.query?.assignees;
48033
- const labels = ctx.query?.labels;
48119
+ const labels2 = ctx.query?.labels;
48034
48120
  const priority = ctx.query?.priority;
48035
48121
  if (!repo2 || !title) {
48036
48122
  ctx.throw(400, "缺少参数 repo 或 title");
@@ -48039,7 +48125,7 @@ app.route({
48039
48125
  title,
48040
48126
  body,
48041
48127
  assignees,
48042
- labels,
48128
+ labels: labels2,
48043
48129
  priority
48044
48130
  });
48045
48131
  ctx.forward(res);
@@ -48296,7 +48382,7 @@ var getLiveMdContent = (opts) => {
48296
48382
  2. Opencode web访问说明
48297
48383
  Opencode打开web地址,需要在浏览器输入用户名和密码,用户名固定为root,密码为CNB_TOKEN的值. 纯连接打开包含账号密码,第一次点击后,需要把账号密码清理掉才能访问,opencode的bug导致的。
48298
48384
  `;
48299
- const labels = [
48385
+ const labels2 = [
48300
48386
  {
48301
48387
  key: "vscodeWebUrl",
48302
48388
  title: "VSCode Web 地址",
@@ -48353,11 +48439,11 @@ Opencode打开web地址,需要在浏览器输入用户名和密码,用户名
48353
48439
  }
48354
48440
  ];
48355
48441
  const osInfoList = createOSInfo(more);
48356
- labels.push(...osInfoList);
48357
- return labels;
48442
+ labels2.push(...osInfoList);
48443
+ return labels2;
48358
48444
  };
48359
48445
  var createOSInfo = (more = false) => {
48360
- const labels = [];
48446
+ const labels2 = [];
48361
48447
  const startTimer = useKey("CNB_BUILD_START_TIME") || "";
48362
48448
  const cpus = os2.cpus();
48363
48449
  let totalIdle = 0;
@@ -48417,7 +48503,7 @@ var createOSInfo = (more = false) => {
48417
48503
  } catch (e) {
48418
48504
  diskUsage = "获取失败";
48419
48505
  }
48420
- labels.push({
48506
+ labels2.push({
48421
48507
  key: "cpuUsage",
48422
48508
  title: "CPU 使用率",
48423
48509
  value: `${cpuUsage}%`,
@@ -48459,7 +48545,7 @@ var createOSInfo = (more = false) => {
48459
48545
  const buildUptime = Date.now() - buildStartTimestamp;
48460
48546
  const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
48461
48547
  const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
48462
- labels.push({
48548
+ labels2.push({
48463
48549
  key: "buildStartTime",
48464
48550
  title: "构建启动时间",
48465
48551
  value: buildStartTime,
@@ -48478,13 +48564,13 @@ var createOSInfo = (more = false) => {
48478
48564
  timeTo4 = today4am.add(1, "day").valueOf() - now.valueOf();
48479
48565
  }
48480
48566
  const timeTo4Str = `[距离晚上4点重启时间: ${formatUptime(Math.floor(timeTo4 / 1000))}]`;
48481
- labels.push({
48567
+ labels2.push({
48482
48568
  key: "buildMaxRunTime",
48483
48569
  title: "最大运行时间",
48484
48570
  value: formatUptime(Math.floor(maxRunTime / 1000)),
48485
48571
  description: "构建最大运行时间(限制时间)"
48486
48572
  });
48487
- labels.unshift({
48573
+ labels2.unshift({
48488
48574
  key: "remainingTime",
48489
48575
  title: "剩余时间",
48490
48576
  value: maxRunTime - buildUptime,
@@ -48494,7 +48580,7 @@ var createOSInfo = (more = false) => {
48494
48580
  }
48495
48581
  if (more) {
48496
48582
  const loadavg = os2.loadavg();
48497
- labels.push({
48583
+ labels2.push({
48498
48584
  key: "hostname",
48499
48585
  title: "主机名",
48500
48586
  value: os2.hostname(),
@@ -48531,7 +48617,7 @@ var createOSInfo = (more = false) => {
48531
48617
  description: "系统负载 (15分钟)"
48532
48618
  });
48533
48619
  }
48534
- return labels;
48620
+ return labels2;
48535
48621
  };
48536
48622
 
48537
48623
  // agent/routes/cnb-board/cnb-dev-env.ts
@@ -48568,7 +48654,7 @@ app.route({
48568
48654
  if (notCNBCheck(ctx))
48569
48655
  return;
48570
48656
  const repoNameFromSlug = repoSlug.split("/").pop() || "";
48571
- const labels = [
48657
+ const labels2 = [
48572
48658
  {
48573
48659
  title: "CNB_REPO_SLUG",
48574
48660
  value: repoSlug,
@@ -48602,7 +48688,7 @@ app.route({
48602
48688
  ];
48603
48689
  ctx.body = {
48604
48690
  title: "CNB_BOARD_LIVE_REPO_INFO",
48605
- list: labels
48691
+ list: labels2
48606
48692
  };
48607
48693
  }).addTo(app);
48608
48694
  app.route({
@@ -48613,7 +48699,7 @@ app.route({
48613
48699
  }).define(async (ctx) => {
48614
48700
  if (notCNBCheck(ctx))
48615
48701
  return;
48616
- const labels = [
48702
+ const labels2 = [
48617
48703
  {
48618
48704
  title: "CNB_BUILD_ID",
48619
48705
  value: useKey("CNB_BUILD_ID") || "",
@@ -48747,7 +48833,7 @@ app.route({
48747
48833
  ];
48748
48834
  ctx.body = {
48749
48835
  title: "CNB_BOARD_LIVE_BUILD_INFO",
48750
- list: labels
48836
+ list: labels2
48751
48837
  };
48752
48838
  }).addTo(app);
48753
48839
  app.route({
@@ -48756,7 +48842,7 @@ app.route({
48756
48842
  description: "获取cnb-board live的PR信息",
48757
48843
  middleware: ["auth-admin"]
48758
48844
  }).define(async (ctx) => {
48759
- const labels = [
48845
+ const labels2 = [
48760
48846
  {
48761
48847
  title: "CNB_PULL_REQUEST",
48762
48848
  value: useKey("CNB_PULL_REQUEST") || "",
@@ -48845,7 +48931,7 @@ app.route({
48845
48931
  ];
48846
48932
  ctx.body = {
48847
48933
  title: "CNB_BOARD_LIVE_PULL_INFO",
48848
- list: labels
48934
+ list: labels2
48849
48935
  };
48850
48936
  }).addTo(app);
48851
48937
  app.route({
@@ -48856,7 +48942,7 @@ app.route({
48856
48942
  }).define(async (ctx) => {
48857
48943
  if (notCNBCheck(ctx))
48858
48944
  return;
48859
- const labels = [
48945
+ const labels2 = [
48860
48946
  {
48861
48947
  title: "CNB_NPC_SLUG",
48862
48948
  value: useKey("CNB_NPC_SLUG") || "",
@@ -48890,7 +48976,7 @@ app.route({
48890
48976
  ];
48891
48977
  ctx.body = {
48892
48978
  title: "CNB_BOARD_LIVE_NPC_INFO",
48893
- list: labels
48979
+ list: labels2
48894
48980
  };
48895
48981
  }).addTo(app);
48896
48982
  app.route({
@@ -48901,7 +48987,7 @@ app.route({
48901
48987
  }).define(async (ctx) => {
48902
48988
  if (notCNBCheck(ctx))
48903
48989
  return;
48904
- const labels = [
48990
+ const labels2 = [
48905
48991
  {
48906
48992
  title: "CNB_COMMENT_ID",
48907
48993
  value: useKey("CNB_COMMENT_ID") || "",
@@ -48935,7 +49021,7 @@ app.route({
48935
49021
  ];
48936
49022
  ctx.body = {
48937
49023
  title: "CNB_BOARD_LIVE_COMMENT_INFO",
48938
- list: labels
49024
+ list: labels2
48939
49025
  };
48940
49026
  }).addTo(app);
48941
49027
 
@@ -55609,7 +55695,7 @@ class RemoteApp {
55609
55695
  }
55610
55696
  }
55611
55697
 
55612
- // ../../node_modules/.pnpm/@kevisual+router@0.1.2/node_modules/@kevisual/router/src/commander.ts
55698
+ // ../../node_modules/.pnpm/@kevisual+router@0.1.3/node_modules/@kevisual/router/src/commander.ts
55613
55699
  var groupByPath = (routes) => {
55614
55700
  return routes.reduce((acc, route) => {
55615
55701
  const path3 = route.path || "default";
@@ -55721,7 +55807,7 @@ var createCommand2 = (opts) => {
55721
55807
  }
55722
55808
  };
55723
55809
  var parse8 = async (opts) => {
55724
- const { description, parse: parse5 = true, version: version3 } = opts;
55810
+ const { description, parse: parse5 = true, version: version3, exitOnEnd = true } = opts;
55725
55811
  const app3 = opts.app;
55726
55812
  const _program = opts.program || program;
55727
55813
  _program.description(description || "Router 命令行工具");
@@ -55762,9 +55848,13 @@ var parse8 = async (opts) => {
55762
55848
  return;
55763
55849
  }
55764
55850
  if (parse5) {
55765
- _program.parse(process.argv);
55851
+ await _program.parseAsync(process.argv);
55852
+ if (exitOnEnd) {
55853
+ process.exit(0);
55854
+ }
55766
55855
  }
55767
55856
  };
55768
55857
 
55769
55858
  // agent/cli.ts
55770
- parse8({ app, description: "CNB控制台命令行工具", parse: true });
55859
+ await parse8({ app, description: "CNB控制台命令行工具", parse: true });
55860
+ console.log("命令行工具已启动,输入 help 查看可用命令", "end");