@kevisual/cnb 0.0.61 → 0.0.63

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,6 @@
1
1
  import { execSync } from 'child_process';
2
2
  import { app, notCNBCheck } from '../../app.ts'
3
3
  import { z } from 'zod'
4
- import { title } from 'process';
5
4
 
6
5
  app.route({
7
6
  path: 'cnb',
@@ -34,7 +34,7 @@ const checkAppId = (ctx: any, appId: string) => {
34
34
  }
35
35
 
36
36
  app.route({
37
- id: 'auth',
37
+ rid: 'auth',
38
38
  path: 'auth',
39
39
  }).define(async (ctx) => {
40
40
  // ctx.body = 'Auth Route';
@@ -47,7 +47,7 @@ app.route({
47
47
  }).addTo(app, { overwrite: false });
48
48
 
49
49
  app.route({
50
- id: 'auth-admin',
50
+ rid: 'auth-admin',
51
51
  path: 'auth-admin',
52
52
  middleware: ['auth'],
53
53
  }).define(async (ctx) => {
@@ -28,7 +28,8 @@ app.route({
28
28
  const cnb = await cnbManager.getContext(ctx);
29
29
  const slug = ctx.query?.slug;
30
30
  const type = ctx.query?.type || 'all';
31
- const { ordering = 'name_ascend', name, page, page_size = 100 } = ctx.query || {};
31
+ const { ordering = 'name_ascend', name, page, page_size = 20 } = ctx.query || {};
32
+ let pageSize = Number(page_size) || 20;
32
33
 
33
34
  if (!slug) {
34
35
  ctx.throw(400, '缺少参数 slug');
@@ -36,17 +37,26 @@ app.route({
36
37
  if (!type) {
37
38
  ctx.throw(400, '缺少参数 type');
38
39
  }
39
- const params = {
40
+ if (pageSize > 99) {
41
+ pageSize = 99;
42
+ }
43
+ const params: Record<string, unknown> = {
40
44
  ordering,
41
45
  page,
42
- page_size,
46
+ page_size: pageSize + 1,
43
47
  }
44
48
  if (name) {
45
49
  params['name'] = name;
46
50
  }
47
51
  const res = await cnb.packages.package.list(slug, type, params);
48
- console.log('list-packages res', res, ctx.query);
49
- ctx.forward(res);
52
+ if (res.code === 200) {
53
+ const packages = res.data;
54
+ const list = packages.slice(0, pageSize);
55
+ const hasMore = packages.length > pageSize;
56
+ ctx.body = { list, hasMore, page, pageSize };
57
+ } else {
58
+ ctx.throw(500, '获取制品列表失败');
59
+ }
50
60
  }).addTo(app);
51
61
 
52
62
  // 获取制品详情
@@ -27,20 +27,31 @@ app.route({
27
27
  }).define(async (ctx) => {
28
28
  const cnb = await cnbManager.getContext(ctx);
29
29
  const slug = ctx.query?.slug;
30
- const { page, page_size, registry_type, filter_type, order_by } = ctx.query || {};
30
+ const { page, page_size = 20, registry_type, filter_type, order_by } = ctx.query || {};
31
+ let pageSize = Number(page_size) || 20;
31
32
 
32
33
  if (!slug) {
33
34
  ctx.throw(400, '缺少参数 slug');
34
35
  }
35
36
 
37
+ if (pageSize > 99) {
38
+ pageSize = 99;
39
+ }
36
40
  const res = await cnb.packages.registry.listGroupRegistries(slug, {
37
41
  page,
38
- page_size,
42
+ page_size: pageSize + 1,
39
43
  registry_type,
40
44
  filter_type,
41
45
  order_by,
42
46
  });
43
- ctx.forward(res);
47
+ if (res.code === 200) {
48
+ const registries = res.data;
49
+ const list = registries.slice(0, pageSize);
50
+ const hasMore = registries.length > pageSize;
51
+ ctx.body = { list, hasMore, page, pageSize };
52
+ } else {
53
+ ctx.throw(500, '获取制品库列表失败');
54
+ }
44
55
  }).addTo(app);
45
56
 
46
57
  // 设置制品库可见性
@@ -1,6 +1,7 @@
1
1
  import { createSkill } from '@kevisual/router';
2
2
  import { z } from 'zod';
3
3
  import { app, cnbManager } from '../../app.ts';
4
+ import { RepoItem } from '@/repo/index.ts';
4
5
 
5
6
  // "列出我的代码仓库,search blog"
6
7
  // 列出我的知识库的代码仓库
@@ -20,6 +21,7 @@ app.route({
20
21
  page: z.number().optional().describe('分页页码,默认 1'),
21
22
  pageSize: z.number().optional().describe('每页数量,默认99'),
22
23
  flags: z.string().optional().describe('仓库标记,如果是知识库则填写 KnowledgeBase'),
24
+ simple: z.boolean().optional().describe('是否返回简化的仓库信息,默认为 false'),
23
25
  },
24
26
  })
25
27
  }
@@ -28,6 +30,7 @@ app.route({
28
30
  const search = ctx.query?.search;
29
31
  const page = ctx.query?.page || 1;
30
32
  let pageSize = ctx.query?.pageSize || 99;
33
+ const simple = ctx.query?.simple || false;
31
34
  const flags = ctx.query?.flags;
32
35
  const params: any = {};
33
36
  if (flags) {
@@ -38,15 +41,21 @@ app.route({
38
41
  }
39
42
  const res = await cnb.repo.getRepoList({ search, page, page_size: pageSize + 1, role: 'developer', ...params });
40
43
  if (res.code === 200) {
41
- const repos = res.data.map((item) => ({
42
- name: item.name,
43
- path: item.path,
44
- description: item.description,
45
- web_url: item.web_url,
46
- }));
44
+ let repos = res.data as Partial<RepoItem>[];
45
+ if (simple) {
46
+ repos = repos.map((repo) => ({
47
+ id: repo.id,
48
+ name: repo.name,
49
+ description: repo.description,
50
+ visibility_level: repo.visibility_level,
51
+ web_url: repo.web_url,
52
+ site: repo.site,
53
+ topics: repo.topics,
54
+ }));
55
+ }
47
56
  const list = repos.slice(0, pageSize);
48
57
  const hasMore = repos.length > pageSize;
49
- ctx.body = { content: JSON.stringify(repos), list, hasMore, page, pageSize };
58
+ ctx.body = { list, hasMore, page, pageSize };
50
59
  } else {
51
60
  ctx.throw(500, '获取仓库列表失败');
52
61
  }
@@ -4,13 +4,14 @@ import { app, cnbManager } from '../../app.ts';
4
4
  app.route({
5
5
  path: 'cnb',
6
6
  key: 'rerun',
7
- description: '重新启动工作区,定时任务',
7
+ description: '重新启动工作区,定时任务, 必须仓库是启动状态',
8
8
  middleware: ['auth'],
9
9
  metadata: {
10
10
  args: {
11
11
  repo: z.string().optional().describe('仓库名称,例如:owner/repo'),
12
12
  config: z.string().optional().describe('工作区配置'),
13
13
  event: z.string().optional().describe('触发事件来源,api_trigger_event'),
14
+ noneStart: z.boolean().optional().describe('如果工作区一个都没有匹配到的话,是否需要启动一个新的工作区,默认为 true'),
14
15
  }
15
16
  }
16
17
  }).define(async (ctx) => {
@@ -18,6 +19,7 @@ app.route({
18
19
  const repo = ctx.args.repo;
19
20
  const config = ctx.args.config;
20
21
  const event = ctx.args.event || 'api_trigger_event';
22
+ const noneStart = ctx.args.noneStart ?? true;
21
23
  const res = await cnb.workspace.list({ status: "running" })
22
24
  if (res.code !== 200) {
23
25
  ctx.throw(500, res.message || 'Failed to list workspaces');
@@ -48,11 +50,18 @@ app.route({
48
50
  console.log(`工作区 ${repo} 停止成功,${res.data?.buildLogUrl ? `构建日志链接: ${res.data.buildLogUrl}` : ''}`);
49
51
  }
50
52
  if (config) {
51
- await cnb.build.startBuild(repo, { branch, config, event });
53
+ const res = await cnb.build.startBuild(repo, { branch, config, event });
54
+ console.log(`工作区 ${repo} 构建启动成功,`);
52
55
  } else {
53
56
  await cnb.workspace.startWorkspace(repo, { branch });
54
57
  }
55
-
58
+ }
59
+ if (_list.length === 0 && noneStart && repo) {
60
+ const branch = 'main';
61
+ const res = await cnb.build.startBuild(repo, { branch, config, event });
62
+ console.log(`工作区 ${repo} 构建启动成功`);
63
+ } else if (_list.length === 0) {
64
+ ctx.throw(404, '没有找到匹配的工作区可以重启');
56
65
  }
57
66
  ctx.body = {
58
67
  content: '工作区重新启动中',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/cnb",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "basename": "/root/cnb",
@@ -35,19 +35,19 @@
35
35
  "@ai-sdk/openai-compatible": "^2.0.37",
36
36
  "@kevisual/ai": "^0.0.28",
37
37
  "@kevisual/api": "^0.0.65",
38
- "@kevisual/code-builder": "^0.0.6",
38
+ "@kevisual/code-builder": "^0.0.7",
39
39
  "@kevisual/context": "^0.0.8",
40
40
  "@kevisual/dts": "^0.0.4",
41
41
  "@kevisual/remote-app": "^0.0.7",
42
42
  "@kevisual/types": "^0.0.12",
43
- "@opencode-ai/plugin": "^1.3.3",
43
+ "@opencode-ai/plugin": "^1.3.13",
44
44
  "@types/bun": "^1.3.11",
45
45
  "@types/node": "^25.5.0",
46
46
  "@types/ws": "^8.18.1",
47
- "ai": "^6.0.138",
47
+ "ai": "^6.0.143",
48
48
  "commander": "^14.0.3",
49
49
  "dayjs": "^1.11.20",
50
- "dotenv": "^17.3.1",
50
+ "dotenv": "^17.4.0",
51
51
  "zod": "^4.3.6"
52
52
  },
53
53
  "publishConfig": {
@@ -58,12 +58,12 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@kevisual/query": "^0.0.55",
61
- "@kevisual/router": "^0.2.4",
61
+ "@kevisual/router": "^0.2.5",
62
62
  "@kevisual/use-config": "^1.0.30",
63
- "@opencode-ai/sdk": "^1.3.3",
63
+ "@opencode-ai/sdk": "^1.3.13",
64
64
  "es-toolkit": "^1.45.1",
65
65
  "nanoid": "^5.1.7",
66
- "unstorage": "^1.17.4",
66
+ "unstorage": "^1.17.5",
67
67
  "ws": "npm:@kevisual/ws"
68
68
  },
69
69
  "exports": {
package/src/repo/index.ts CHANGED
@@ -154,7 +154,7 @@ type CreateCommitData = {
154
154
  }>;
155
155
  }
156
156
 
157
- type RepoItem = {
157
+ export type RepoItem = {
158
158
  id: string;
159
159
  name: string;
160
160
  freeze: boolean;
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { };