@kevisual/cnb 0.0.52 → 0.0.54

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/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 []
@@ -11,6 +11,7 @@ import './share/index.ts';
11
11
  import './cnb-manager/index.ts';
12
12
  import './build/index.ts';
13
13
  import './chat/chat.ts';
14
+ import './missions/index.ts';
14
15
 
15
16
  /**
16
17
  * 验证上下文中的 App ID 是否与指定的 App ID 匹配
@@ -0,0 +1 @@
1
+ import './list.ts'
@@ -0,0 +1,39 @@
1
+ import z from 'zod';
2
+ import { app, cnbManager } from '../../app.ts';
3
+
4
+ app.route({
5
+ path: 'cnb',
6
+ key: 'missions-list',
7
+ description: '查询missions列表',
8
+ metadata: {
9
+ args: {
10
+ repo: z.string().optional().describe('missions所在的仓库,例如 kevisual/projects'),
11
+ selector: z.array(z.any()).optional().describe('查询条件,例如 [{field: "resource_type", operator: "contains", value: ["issues"]},…]'),
12
+ }
13
+ }
14
+ }).define(async (ctx) => {
15
+ const cnb = await cnbManager.getContext(ctx);
16
+ const repo = ctx.query?.repo || 'kevisual/projects';
17
+ const res = await cnb.mission.queryResources(repo, ctx.query?.selector || [
18
+ {
19
+ "field": "resource_type",
20
+ "operator": "contains",
21
+ "value": [
22
+ "issues"
23
+ ]
24
+ },
25
+ {
26
+ "field": "state",
27
+ "operator": "not_equals",
28
+ "value": [
29
+ "closed"
30
+ ]
31
+ },
32
+ {
33
+ "field": "label",
34
+ "operator": "contains",
35
+ "value": ["AICoding"]
36
+ }
37
+ ])
38
+ ctx.forward(res);
39
+ }).addTo(app);
@@ -1,2 +1,3 @@
1
1
  import './list.ts'
2
- import './repo.ts'
2
+ import './repo.ts'
3
+ import './repo-label.ts'
@@ -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);
@@ -180,3 +180,31 @@ app.route({
180
180
  ctx.forward(res);
181
181
  }).addTo(app);
182
182
 
183
+ app.route({
184
+ path: 'cnb',
185
+ key: 'update-repo-visibility',
186
+ description: '更新代码仓库的可见性, 参数name, visibility',
187
+ middleware: ['auth'],
188
+ metadata: {
189
+ args: {
190
+ name: tool.schema.string().describe('代码仓库名称'),
191
+ visibility: tool.schema.string().describe('代码仓库可见性, public 或 private 或 protected'),
192
+ },
193
+ }
194
+ }).define(async (ctx) => {
195
+ const cnb = await cnbManager.getContext(ctx);
196
+ const name = ctx.query?.name;
197
+ const visibility = ctx.query?.visibility;
198
+
199
+ if (!name) {
200
+ ctx.throw(400, '缺少参数 name');
201
+ }
202
+ if (!visibility) {
203
+ ctx.throw(400, '缺少参数 visibility');
204
+ }
205
+ const res = await cnb.post({
206
+ url: `/${name}/-/settings/set_visibility`,
207
+ data: { visibility }
208
+ })
209
+ ctx.forward(res);
210
+ }).addTo(app);