@kevisual/cnb 0.0.40 → 0.0.42

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 CHANGED
@@ -29,7 +29,6 @@ export const notCNBCheck = (ctx: any) => {
29
29
  const isCNB = useKey('CNB');
30
30
  if (!isCNB) {
31
31
  ctx.throw(400, '当前环境非 cnb-board 环境,无法获取 live 内容');
32
- return true;
33
32
  }
34
33
  return false;
35
34
  }
@@ -0,0 +1,66 @@
1
+ import { execSync } from 'child_process';
2
+ import { app, notCNBCheck } from '../../app.ts'
3
+ import { z } from 'zod'
4
+ import { title } from 'process';
5
+
6
+ app.route({
7
+ path: 'cnb',
8
+ key: 'docker-sync',
9
+ middleware: ['auth'],
10
+ metadata: {
11
+ tag: ['opencode'],
12
+ skill: 'cnb-docker-sync',
13
+ title: 'CNB Docker 镜像同步',
14
+ args: {
15
+ image: z.string().describe('Docker 同步的具体的镜像名称.'),
16
+ toVersion: z.string().optional().describe('修改后的版本号.'),
17
+ }
18
+ }
19
+ }).define(async (ctx) => {
20
+ const { image, toVersion } = ctx.args;
21
+ notCNBCheck(ctx);
22
+ if (!image) {
23
+ ctx.body = {
24
+ message: '请提供 Docker 镜像名称.',
25
+ data: null,
26
+ }
27
+ return;
28
+ }
29
+ const config = {
30
+ registry: 'docker.cnb.cool/kevisual/dev-env',
31
+ dockers: [{ image, toVersion }]
32
+ }
33
+ // docker tag ghcr.io/esm-dev/esm.sh:v137 docker.cnb.cool/kevisual/dev-env/esm.sh:v137
34
+ // docker push docker.cnb.cool/kevisual/dev-env/esm.sh:v137
35
+ const run = async () => {
36
+ const dockers = config.dockers;
37
+ for (const { image, toVersion } of dockers) {
38
+ const imageName = image.split(':')[0].split('/').slice(-1)[0]
39
+ const tag = image.split(':')[1]
40
+ const newImage = `${config.registry}/${imageName}:${toVersion || tag}`
41
+ // console.log(`docker tag ${image} ${newImage}`)
42
+ // console.log(`docker push ${newImage}`)
43
+ const shell = `docker pull ${image} && docker tag ${image} ${newImage} && docker push ${newImage}`
44
+ console.log(shell)
45
+
46
+ console.log('\n-------------new---------------------------------\n')
47
+ console.log(`${newImage}`)
48
+ console.log('\n--------------------------------------------------\n')
49
+ try {
50
+ execSync(shell, { stdio: 'inherit' })
51
+ } catch (error) {
52
+ console.error(`Error: ${error}`)
53
+ }
54
+ }
55
+ }
56
+ run().then(() => {
57
+ // TODO: 通知用户同步完成
58
+ });;
59
+ ctx.body = {
60
+ message: 'Docker 镜像同步任务中,请稍后在目标仓库查看.',
61
+ data: {
62
+ registry: config.registry,
63
+ dockers: config.dockers,
64
+ }
65
+ }
66
+ }).addTo(app);
@@ -0,0 +1 @@
1
+ import './docker.ts'
@@ -9,6 +9,7 @@ import './issues/index.ts'
9
9
  import './cnb-board/index.ts';
10
10
  import './share/index.ts';
11
11
  import './cnb-manager/index.ts';
12
+ import './build/index.ts';
12
13
 
13
14
  /**
14
15
  * 验证上下文中的 App ID 是否与指定的 App ID 匹配
@@ -0,0 +1,167 @@
1
+ import { createSkill, tool } from '@kevisual/router';
2
+ import { app, cnbManager } from '../../app.ts';
3
+ import { useKey } from '@kevisual/context';
4
+
5
+ // 查询 Issue 评论列表
6
+ app.route({
7
+ path: 'cnb',
8
+ key: 'list-issue-comments',
9
+ description: '查询 Issue 评论列表, 参数 repo, issueNumber, page, page_size',
10
+ middleware: ['auth'],
11
+ metadata: {
12
+ tags: ['opencode'],
13
+ ...createSkill({
14
+ skill: 'list-issue-comments',
15
+ title: '查询 Issue 评论列表',
16
+ args: {
17
+ repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
18
+ issueNumber: tool.schema.number().describe('Issue 编号'),
19
+ page: tool.schema.number().optional().describe('分页页码,默认: 1'),
20
+ page_size: tool.schema.number().optional().describe('分页每页大小,默认: 30'),
21
+ },
22
+ summary: '查询 Issue 评论列表',
23
+ })
24
+ }
25
+ }).define(async (ctx) => {
26
+ const cnb = await cnbManager.getContext(ctx);
27
+ let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
28
+ const issueNumber = ctx.query?.issueNumber;
29
+ const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
30
+ const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
31
+
32
+ if (!repo) {
33
+ ctx.throw(400, '缺少参数 repo');
34
+ }
35
+ if (!issueNumber) {
36
+ ctx.throw(400, '缺少参数 issueNumber');
37
+ }
38
+
39
+ const params: Record<string, any> = {};
40
+ if (page) params.page = page;
41
+ if (page_size) params.page_size = page_size;
42
+
43
+ const res = await cnb.issue.getCommentList(repo, issueNumber, params);
44
+ ctx.forward(res);
45
+ }).addTo(app);
46
+
47
+ // 创建 Issue 评论
48
+ app.route({
49
+ path: 'cnb',
50
+ key: 'create-issue-comment',
51
+ description: '创建 Issue 评论, 参数 repo, issueNumber, body',
52
+ middleware: ['auth'],
53
+ metadata: {
54
+ tags: ['opencode'],
55
+ ...createSkill({
56
+ skill: 'create-issue-comment',
57
+ title: '创建 Issue 评论',
58
+ args: {
59
+ repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
60
+ issueNumber: tool.schema.number().describe('Issue 编号'),
61
+ body: tool.schema.string().describe('评论内容'),
62
+ },
63
+ summary: '创建 Issue 评论',
64
+ })
65
+ }
66
+ }).define(async (ctx) => {
67
+ const cnb = await cnbManager.getContext(ctx);
68
+ let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
69
+ const issueNumber = ctx.query?.issueNumber;
70
+ const body = ctx.query?.body;
71
+
72
+ if (!repo) {
73
+ ctx.throw(400, '缺少参数 repo');
74
+ }
75
+ if (!issueNumber) {
76
+ ctx.throw(400, '缺少参数 issueNumber');
77
+ }
78
+ if (!body) {
79
+ ctx.throw(400, '缺少参数 body');
80
+ }
81
+
82
+ const res = await cnb.issue.createComment(repo, issueNumber, body);
83
+ ctx.forward(res);
84
+ }).addTo(app);
85
+
86
+ // 获取 Issue 指定评论
87
+ app.route({
88
+ path: 'cnb',
89
+ key: 'get-issue-comment',
90
+ description: '获取 Issue 指定评论, 参数 repo, issueNumber, commentId',
91
+ middleware: ['auth'],
92
+ metadata: {
93
+ tags: ['opencode'],
94
+ ...createSkill({
95
+ skill: 'get-issue-comment',
96
+ title: '获取 Issue 评论',
97
+ args: {
98
+ repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
99
+ issueNumber: tool.schema.number().describe('Issue 编号'),
100
+ commentId: tool.schema.number().describe('评论 ID'),
101
+ },
102
+ summary: '获取 Issue 评论',
103
+ })
104
+ }
105
+ }).define(async (ctx) => {
106
+ const cnb = await cnbManager.getContext(ctx);
107
+ let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
108
+ const issueNumber = ctx.query?.issueNumber;
109
+ const commentId = ctx.query?.commentId;
110
+
111
+ if (!repo) {
112
+ ctx.throw(400, '缺少参数 repo');
113
+ }
114
+ if (!issueNumber) {
115
+ ctx.throw(400, '缺少参数 issueNumber');
116
+ }
117
+ if (!commentId) {
118
+ ctx.throw(400, '缺少参数 commentId');
119
+ }
120
+
121
+ const res = await cnb.issue.getComment(repo, issueNumber, commentId);
122
+ ctx.forward(res);
123
+ }).addTo(app);
124
+
125
+ // 修改 Issue 评论
126
+ app.route({
127
+ path: 'cnb',
128
+ key: 'update-issue-comment',
129
+ description: '修改 Issue 评论, 参数 repo, issueNumber, commentId, body',
130
+ middleware: ['auth'],
131
+ metadata: {
132
+ tags: ['opencode'],
133
+ ...createSkill({
134
+ skill: 'update-issue-comment',
135
+ title: '修改 Issue 评论',
136
+ args: {
137
+ repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
138
+ issueNumber: tool.schema.number().describe('Issue 编号'),
139
+ commentId: tool.schema.number().describe('评论 ID'),
140
+ body: tool.schema.string().describe('评论内容'),
141
+ },
142
+ summary: '修改 Issue 评论',
143
+ })
144
+ }
145
+ }).define(async (ctx) => {
146
+ const cnb = await cnbManager.getContext(ctx);
147
+ let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
148
+ const issueNumber = ctx.query?.issueNumber;
149
+ const commentId = ctx.query?.commentId;
150
+ const body = ctx.query?.body;
151
+
152
+ if (!repo) {
153
+ ctx.throw(400, '缺少参数 repo');
154
+ }
155
+ if (!issueNumber) {
156
+ ctx.throw(400, '缺少参数 issueNumber');
157
+ }
158
+ if (!commentId) {
159
+ ctx.throw(400, '缺少参数 commentId');
160
+ }
161
+ if (!body) {
162
+ ctx.throw(400, '缺少参数 body');
163
+ }
164
+
165
+ const res = await cnb.issue.updateComment(repo, issueNumber, commentId, body);
166
+ ctx.forward(res);
167
+ }).addTo(app);
@@ -1,2 +1,3 @@
1
1
  import './list.ts'
2
- import './issue.ts'
2
+ import './issue.ts'
3
+ import './comments.ts'
@@ -14,7 +14,7 @@ app.route({
14
14
  skill: 'list-issues',
15
15
  title: '查询 Issue 列表',
16
16
  args: {
17
- repo: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
17
+ repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
18
18
  state: tool.schema.string().optional().describe('Issue 状态:open 或 closed'),
19
19
  keyword: tool.schema.string().optional().describe('问题搜索关键词'),
20
20
  labels: tool.schema.string().optional().describe('问题标签,多个用逗号分隔'),
@@ -27,7 +27,7 @@ app.route({
27
27
  }
28
28
  }).define(async (ctx) => {
29
29
  const cnb = await cnbManager.getContext(ctx);
30
- const repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
30
+ let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
31
31
  const state = ctx.query?.state;
32
32
  const keyword = ctx.query?.keyword;
33
33
  const labels = ctx.query?.labels;