@kevisual/cnb 0.0.39 → 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.
@@ -1,7 +1,10 @@
1
1
  import { Result } from '@kevisual/query';
2
2
  import { CNB } from '../../src/index.ts';
3
+ import { useKey } from '@kevisual/context';
3
4
  export const getConfig = async (opts: { token?: string }) => {
4
- const res = await fetch('https://kevisual.cn/api/router', {
5
+ const kevisualEnv = useKey('KEVISUAL_ENV')
6
+ const baseUrl = kevisualEnv === 'production' ? 'https://kevisual.cn/api/router' : 'https://kevisual.xiongxiao.me/api/router';
7
+ const res = await fetch(baseUrl, {
5
8
  method: 'POST',
6
9
  body: JSON.stringify({
7
10
  path: 'config',
@@ -51,6 +54,7 @@ export class CNBManager {
51
54
  cnbItem.runAt = Date.now()
52
55
  return cnbItem
53
56
  }
57
+
54
58
  const res = await getConfig({ token: opts?.kevisualToken })
55
59
  if (res.code === 200) {
56
60
  const cookie = res.data?.data?.CNB_COOKIE
@@ -43,6 +43,27 @@ app.route({
43
43
  }
44
44
  }).addTo(app);
45
45
 
46
+ app.route({
47
+ path: 'cnb',
48
+ key: 'get-repo',
49
+ description: '获取代码仓库详情, 参数name',
50
+ middleware: ['auth'],
51
+ metadata: {
52
+ args: {
53
+ name: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
54
+ }
55
+ }
56
+ }).define(async (ctx) => {
57
+ const cnb = await cnbManager.getContext(ctx);
58
+ const name = ctx.query?.name;
59
+
60
+ if (!name) {
61
+ ctx.throw(400, '缺少参数 name');
62
+ }
63
+ const res = await cnb.repo.getRepo(name);
64
+ ctx.forward(res);
65
+ }).addTo(app);
66
+
46
67
  app.route({
47
68
  path: 'cnb',
48
69
  key: 'create-repo-file',
@@ -106,7 +127,56 @@ app.route({
106
127
  if (!name) {
107
128
  ctx.throw(400, '缺少参数 name');
108
129
  }
130
+ try {
131
+ const resCookie = await cnb.user.checkCookieValid()
132
+ if (resCookie.code !== 200) {
133
+ ctx.throw(401, 'Cookie 无效或已过期');
134
+ }
135
+ const res = await cnb.repo.deleteRepoCookie(name);
136
+ ctx.forward(res);
137
+ } catch (error) {
138
+ ctx.code = 200
139
+ ctx.body = { content: '已经删除' }
140
+ }
141
+ }).addTo(app);
109
142
 
110
- const res = await cnb.repo.deleteRepoCookie(name);
143
+
144
+ app.route({
145
+ path: 'cnb',
146
+ key: 'update-repo-info',
147
+ description: '更新代码仓库信息, 参数name, description',
148
+ middleware: ['auth'],
149
+ metadata: {
150
+ tags: ['opencode'],
151
+ ...createSkill({
152
+ skill: 'update-repo-info',
153
+ title: '更新代码仓库信息',
154
+ args: {
155
+ name: tool.schema.string().describe('代码仓库名称'),
156
+ description: tool.schema.string().describe('代码仓库描述'),
157
+ license: tool.schema.string().describe('代码仓库许可证类型,如 MIT').optional(),
158
+ site: tool.schema.string().describe('代码仓库主页链接').optional(),
159
+ topics: tool.schema.array(tool.schema.string()).describe('代码仓库话题标签列表').optional(),
160
+ },
161
+ summary: '更新代码仓库的信息',
162
+ })
163
+ }
164
+ }).define(async (ctx) => {
165
+ const cnb = await cnbManager.getContext(ctx);
166
+ const name = ctx.query?.name;
167
+ const description = ctx.query?.description;
168
+ const license = ctx.query?.license;
169
+ const site = ctx.query?.site;
170
+ const topics = ctx.query?.topics;
171
+
172
+ if (!name) {
173
+ ctx.throw(400, '缺少参数 name');
174
+ }
175
+ if (!description) {
176
+ ctx.throw(400, '缺少参数 description');
177
+ }
178
+
179
+ const res = await cnb.repo.updateRepoInfo(name, { description, license, site, topics });
111
180
  ctx.forward(res);
112
- }).addTo(app);
181
+ }).addTo(app);
182
+
@@ -0,0 +1,43 @@
1
+ import { createSkill, tool } from '@kevisual/router';
2
+
3
+ import { app, cnbManager, notCNBCheck } from '../../app.ts';
4
+
5
+ // 启动工作空间
6
+ app.route({
7
+ path: 'cnb',
8
+ key: 'cloud-build',
9
+ description: '云端构建,参数 event, repo, branch, ref, config, env',
10
+ middleware: ['auth'],
11
+ metadata: {
12
+ tags: ['opencode'],
13
+ ...createSkill({
14
+ skill: 'cloud-build',
15
+ title: '云端构建',
16
+ summary: '在云端构建代码仓库,参数包括 event, repo, branch, ref, config, env',
17
+ args: {
18
+ env: tool.schema.any().optional().describe('构建环境变量,格式为 { "KEY": "VALUE" }'),
19
+ event: tool.schema.string().optional().describe('触发事件类型,例如 api_trigger_event'),
20
+ branch: tool.schema.string().optional().describe('分支名称,默认主分支'),
21
+ config: tool.schema.string().describe('构建config文件内容,例如 cloudbuild.yaml对应的yml的内容'),
22
+ repo: tool.schema.string().describe('代码仓库路径,例如 user/repo'),
23
+ },
24
+ })
25
+ }
26
+ }).define(async (ctx) => {
27
+ const cnb = await cnbManager.getContext(ctx);
28
+ const repo = ctx.query?.repo;
29
+ const branch = ctx.query?.branch || 'main';
30
+ const config = ctx.query?.config;
31
+ const event = ctx.query?.event || 'api_trigger_event';
32
+ const env = ctx.query?.env ?? {};
33
+ if (!repo) {
34
+ ctx.throw(400, '缺少参数 repo');
35
+ }
36
+ const res = await cnb.build.startBuild(repo, {
37
+ branch,
38
+ config,
39
+ event,
40
+ env,
41
+ });
42
+ ctx.forward(res);
43
+ }).addTo(app);
@@ -3,6 +3,7 @@ import { app, cnbManager, notCNBCheck } from '../../app.ts';
3
3
  import z from 'zod';
4
4
  import './skills.ts';
5
5
  import './keep.ts';
6
+ import './build.ts';
6
7
 
7
8
  // 启动工作空间
8
9
  app.route({
@@ -67,7 +68,7 @@ app.route({
67
68
  page: page ?? 1,
68
69
  pageSize: pageSize ?? 100,
69
70
  });
70
- ctx.forward({ code: 200, message: 'success', data: res });
71
+ ctx.forward(res);
71
72
  }).addTo(app);
72
73
 
73
74
  // 获取工作空间详情
@@ -99,7 +100,7 @@ app.route({
99
100
  ctx.throw(400, '缺少参数 sn');
100
101
  }
101
102
  const res = await cnb.workspace.getDetail(repo, sn);
102
- ctx.forward({ code: 200, message: 'success', data: res });
103
+ ctx.forward(res);
103
104
  }).addTo(app);
104
105
 
105
106
  // 删除工作空间
@@ -161,7 +162,6 @@ app.route({
161
162
  })
162
163
  }
163
164
  }).define(async (ctx) => {
164
- if (notCNBCheck(ctx)) { return; }
165
165
  const cnb = await cnbManager.getContext(ctx);
166
166
  const pipelineId = ctx.query?.pipelineId;
167
167
  const sn = ctx.query?.sn;
@@ -169,6 +169,7 @@ app.route({
169
169
  ctx.throw(400, 'pipelineId 和 sn 必须提供其中一个');
170
170
  }
171
171
  const res = await cnb.workspace.stopWorkspace({ pipelineId, sn });
172
- ctx.forward({ code: 200, message: 'success', data: res });
172
+ ctx.forward(res);
173
173
  }).addTo(app);
174
174
 
175
+