@kevisual/cnb 0.0.56 → 0.0.57

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/cnb",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "basename": "/root/cnb",
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import { Issue } from "./issue/index.ts";
8
8
  import { Mission } from "./mission/index.ts";
9
9
  import { AiBase } from "./ai/index.ts";
10
10
  import { RepoLabel, IssueLabel } from "./labels/index.ts";
11
+ import { RegistryPackage, PackageManagement } from "./package/index.ts";
11
12
 
12
13
  type CNBOptions = CNBCoreOptions<{
13
14
  }>;
@@ -25,6 +26,10 @@ export class CNB extends CNBCore {
25
26
  repoLabel: RepoLabel;
26
27
  issueLabel: IssueLabel;
27
28
  };
29
+ packages!: {
30
+ registry: RegistryPackage;
31
+ package: PackageManagement;
32
+ };
28
33
  constructor(options: CNBOptions) {
29
34
  super({ ...options, token: options.token, cookie: options.cookie, cnb: options.cnb });
30
35
  this.init(options);
@@ -47,6 +52,10 @@ export class CNB extends CNBCore {
47
52
  repoLabel: new RepoLabel(options),
48
53
  issueLabel: new IssueLabel(options),
49
54
  };
55
+ this.packages = {
56
+ registry: new RegistryPackage(options),
57
+ package: new PackageManagement(options),
58
+ };
50
59
  }
51
60
  setToken(token: string) {
52
61
  this.token = token;
@@ -58,6 +67,8 @@ export class CNB extends CNBCore {
58
67
  this.mission.token = token;
59
68
  this.labels.repoLabel.token = token;
60
69
  this.labels.issueLabel.token = token;
70
+ this.packages.registry.token = token;
71
+ this.packages.package.token = token;
61
72
  }
62
73
  setCookie(cookie: string) {
63
74
  this.cookie = cookie;
@@ -69,6 +80,8 @@ export class CNB extends CNBCore {
69
80
  this.mission.cookie = cookie;
70
81
  this.labels.repoLabel.cookie = cookie;
71
82
  this.labels.issueLabel.cookie = cookie;
83
+ this.packages.registry.cookie = cookie;
84
+ this.packages.package.cookie = cookie;
72
85
  }
73
86
  getCNBVersion = getCNBVersion
74
87
  }
@@ -95,4 +108,5 @@ type VersionInfo = {
95
108
  }
96
109
 
97
110
  export * from './issue/npc/env.ts'
98
- export * from './labels/index.ts'
111
+ export * from './labels/index.ts'
112
+ export * from './package/index.ts'
@@ -63,8 +63,11 @@ export type IssueItem = {
63
63
  number: string;
64
64
  priority: string;
65
65
  started_at: string;
66
- state: string;
67
- state_reason: string;
66
+ state: 'open' | 'closed';
67
+ /**
68
+ * state_reason must be one of completed, not_planned, reopened
69
+ */
70
+ state_reason: 'completed' | 'not_planned' | 'reopened';
68
71
  title: string;
69
72
  updated_at: string;
70
73
  };
@@ -1,5 +1,6 @@
1
1
  import { CNBCore, CNBCoreOptions, Result } from "../cnb-core.ts";
2
2
 
3
+ // https://cnb.cool/cnb/plugins/cnbcool/knowledge-base/-/blob/main/src/api.py
3
4
  export class KnowledgeBase extends CNBCore {
4
5
  constructor(options: CNBCoreOptions) {
5
6
  super(options);
@@ -12,10 +13,7 @@ export class KnowledgeBase extends CNBCore {
12
13
  metadata_filtering_conditions?: MetadataFilteringConditions
13
14
  }): Promise<Result<QueryRag[]>> {
14
15
  const url = `/${repo}/-/knowledge/base/query`;
15
- let postData = {
16
- query: data.query,
17
- };
18
- return this.post({ url, data: postData });
16
+ return this.post({ url, data });
19
17
  }
20
18
  getEmbeddingModels(repo: string): Promise<Result<Array<{ name: string, dimensions: number }>>> {
21
19
  const url = `/${repo}/-/knowledge/embedding/models`;
@@ -31,6 +29,95 @@ export class KnowledgeBase extends CNBCore {
31
29
  const url = `/${repo}/-/knowledge/base`;
32
30
  return this.request({ url, method: 'DELETE' });
33
31
  }
32
+
33
+ /**
34
+ * 未暴露
35
+ * @param repo
36
+ * @param data
37
+ * @returns
38
+ */
39
+ createKnowledgeBase(repo: string, data: {
40
+ embedding_model_name: string;
41
+ include: string;
42
+ exclude: string;
43
+ issue_sync_enabled?: boolean;
44
+ processing?: {
45
+ chunk_size: number;
46
+ chunk_overlap: number;
47
+ text_separator: string;
48
+ };
49
+ issue?: {
50
+ labels: string;
51
+ state: string;
52
+ };
53
+ }): Promise<Result<any>> {
54
+ const url = `/${repo}/-/knowledge/base`;
55
+ return this.post({ url, data });
56
+ }
57
+ /**
58
+ * 未暴露
59
+ * @param repo
60
+ * @param data
61
+ * @returns
62
+ */
63
+ updateKnowledgeBase(repo: string, data: {
64
+ last_commit_sha?: string;
65
+ issue_last_sync_time?: string;
66
+ }): Promise<Result<any>> {
67
+ const url = `/${repo}/-/knowledge/base`;
68
+ return this.put({ url, data });
69
+ }
70
+
71
+ /**
72
+ * 未暴露
73
+ * @param repo
74
+ * @param text
75
+ * @returns
76
+ */
77
+ getEmbedding(repo: string, text: string): Promise<Result<{ embedding: number[] }>> {
78
+ const url = `/${repo}/-/knowledge/embedding`;
79
+ return this.post({ url, data: { text } });
80
+ }
81
+ /**
82
+ * 未暴露
83
+ * @param repo
84
+ * @param chunksData
85
+ * @returns
86
+ */
87
+ addDocument(repo: string, chunksData: {
88
+ path: string;
89
+ chunks: Array<{
90
+ content: string;
91
+ hash: string;
92
+ offset: number;
93
+ size: number;
94
+ }>;
95
+ }): Promise<Result<any>> {
96
+ const url = `/${repo}/-/knowledge/documents/upsert-document-with-chunks`;
97
+ return this.post({ url, data: chunksData });
98
+ }
99
+ /**
100
+ * 未暴露
101
+ * @param repo
102
+ * @param paths
103
+ * @returns
104
+ */
105
+
106
+ deleteDocument(repo: string, paths: string[]): Promise<Result<any>> {
107
+ const url = `/${repo}/-/knowledge/documents`;
108
+ return this.delete({ url, data: { paths } });
109
+ }
110
+ /**
111
+ * 未暴露
112
+ * @param repo
113
+ * @param page
114
+ * @param page_size
115
+ * @returns
116
+ */
117
+ listDocument(repo: string, page: number = 1, page_size: number = 50): Promise<Result<any[]>> {
118
+ const url = `/${repo}/-/knowledge/documents`;
119
+ return this.get({ url, params: { page, page_size } });
120
+ }
34
121
  }
35
122
 
36
123
  type MetadataFilteringConditions = {
@@ -42,7 +129,7 @@ type MetadataFilteringConditions = {
42
129
  */
43
130
  value?: string
44
131
  }>
45
- logical_operator?: 'adn' | 'or'
132
+ logical_operator?: 'and' | 'or'
46
133
  }
47
134
 
48
135
  type QueryRag = {
@@ -0,0 +1,2 @@
1
+ export * from './registry.ts';
2
+ export * from './package.ts';
@@ -0,0 +1,134 @@
1
+ import { CNBCore, CNBCoreOptions, Result } from "../cnb-core.ts";
2
+ import type { PackageType, Package, ListPackagesParams } from "./registry.ts";
3
+
4
+ /**
5
+ * 制品管理
6
+ */
7
+ export class PackageManagement extends CNBCore {
8
+ constructor(options: CNBCoreOptions) {
9
+ super(options);
10
+ }
11
+
12
+ /**
13
+ * 查询制品列表
14
+ * @param slug 资源路径
15
+ * @param type 制品类型
16
+ * @param params 查询参数
17
+ */
18
+ list(
19
+ slug: string,
20
+ type: PackageType,
21
+ params?: ListPackagesParams & { page?: number; page_size?: number }
22
+ ): Promise<Result<Package[]>> {
23
+ const url = `/${slug}/-/packages`;
24
+ return this.get({
25
+ url,
26
+ params: {
27
+ type,
28
+ ...params,
29
+ },
30
+ headers: {
31
+ Accept: "application/vnd.cnb.api+json",
32
+ },
33
+ });
34
+ }
35
+
36
+ /**
37
+ * 获取制品详情
38
+ * @param slug 资源路径
39
+ * @param type 制品类型
40
+ * @param name 制品名称
41
+ */
42
+ getOne(
43
+ slug: string,
44
+ type: PackageType,
45
+ name: string
46
+ ): Promise<Result<any>> {
47
+ const url = `/${slug}/-/packages/${type}/${encodeURIComponent(name)}`;
48
+ return this.get({
49
+ url,
50
+ headers: {
51
+ Accept: "application/vnd.cnb.api+json",
52
+ },
53
+ });
54
+ }
55
+
56
+ /**
57
+ * 删除制品
58
+ * @param slug 资源路径
59
+ * @param type 制品类型
60
+ * @param name 制品名称
61
+ */
62
+ remove(
63
+ slug: string,
64
+ type: PackageType,
65
+ name: string
66
+ ): Promise<Result<void>> {
67
+ const url = `/${slug}/-/packages/${type}/${encodeURIComponent(name)}`;
68
+ return this.delete({ url });
69
+ }
70
+
71
+ /**
72
+ * 获取制品标签详情
73
+ * @param slug 资源路径
74
+ * @param type 制品类型
75
+ * @param name 制品名称
76
+ * @param tag 标签名称
77
+ */
78
+ getTag(
79
+ slug: string,
80
+ type: PackageType,
81
+ name: string,
82
+ tag: string
83
+ ): Promise<Result<any>> {
84
+ const url = `/${slug}/-/packages/${type}/${encodeURIComponent(name)}/tags/${encodeURIComponent(tag)}`;
85
+ return this.get({
86
+ url,
87
+ headers: {
88
+ Accept: "application/vnd.cnb.api+json",
89
+ },
90
+ });
91
+ }
92
+
93
+ /**
94
+ * 删除制品标签
95
+ * @param slug 资源路径
96
+ * @param type 制品类型
97
+ * @param name 制品名称
98
+ * @param tag 标签名称
99
+ */
100
+ removeTag(
101
+ slug: string,
102
+ type: PackageType,
103
+ name: string,
104
+ tag: string
105
+ ): Promise<Result<void>> {
106
+ const url = `/${slug}/-/packages/${type}/${encodeURIComponent(name)}/tags/${encodeURIComponent(tag)}`;
107
+ return this.delete({ url });
108
+ }
109
+
110
+ /**
111
+ * 获取制品标签列表
112
+ * @param slug 资源路径
113
+ * @param type 制品类型
114
+ * @param name 制品名称
115
+ * @param params 查询参数
116
+ */
117
+ listTags(
118
+ slug: string,
119
+ type: PackageType,
120
+ name: string,
121
+ params?: { page?: number; page_size?: number }
122
+ ): Promise<Result<any>> {
123
+ const url = `/${slug}/-/packages/${type}/${encodeURIComponent(name)}/tags`;
124
+ return this.get({
125
+ url,
126
+ params,
127
+ headers: {
128
+ Accept: "application/vnd.cnb.api+json",
129
+ },
130
+ });
131
+ }
132
+ }
133
+
134
+ export type { PackageType, Package, ListPackagesParams };
@@ -0,0 +1,145 @@
1
+ import { CNBCore, CNBCoreOptions, Result } from "../cnb-core.ts";
2
+
3
+ /**
4
+ * 制品类型
5
+ */
6
+ export type PackageType =
7
+ | "all"
8
+ | "docker"
9
+ | "helm"
10
+ | "docker-model"
11
+ | "maven"
12
+ | "npm"
13
+ | "ohpm"
14
+ | "pypi"
15
+ | "nuget"
16
+ | "composer"
17
+ | "conan"
18
+ | "cargo";
19
+
20
+ /**
21
+ * 制品库可见性类型
22
+ */
23
+ export type VisibilityType = "private" | "public";
24
+
25
+ /**
26
+ * 制品库排序类型
27
+ */
28
+ export type PackageOrderingType = "pull_count" | "last_push_at" | "name_ascend" | "name_descend";
29
+
30
+ /**
31
+ * 最后推送者信息
32
+ */
33
+ export type LastPusher = {
34
+ is_frozen: boolean;
35
+ is_lock: boolean;
36
+ name: string;
37
+ username: string;
38
+ };
39
+
40
+ /**
41
+ * 制品基本信息
42
+ */
43
+ export type Package = {
44
+ count: number;
45
+ description: string;
46
+ labels: string[];
47
+ last_artifact_name: string;
48
+ last_pusher: LastPusher;
49
+ name: string;
50
+ package: string;
51
+ package_type: PackageType;
52
+ pull_count: number;
53
+ recent_pull_count: number;
54
+ };
55
+
56
+ /**
57
+ * 制品库信息
58
+ */
59
+ export type Registry = {
60
+ created_at: string;
61
+ description: string;
62
+ name: string;
63
+ owner: string;
64
+ type: PackageType;
65
+ visibility: VisibilityType;
66
+ };
67
+
68
+ /**
69
+ * 制品库列表查询参数
70
+ */
71
+ export type ListGroupRegistriesParams = {
72
+ /** 页码 */
73
+ page?: number;
74
+ /** 每页数量 */
75
+ page_size?: number;
76
+ /** 制品仓库类型 */
77
+ registry_type?: "npm" | "maven" | "ohpm";
78
+ /** 制品仓库可见性类型 */
79
+ filter_type?: VisibilityType;
80
+ /** 排序字段 */
81
+ order_by?: "created_at" | "name";
82
+ };
83
+
84
+ /**
85
+ * 制品列表查询参数
86
+ */
87
+ export type ListPackagesParams = {
88
+ /** 顺序类型 */
89
+ ordering?: PackageOrderingType;
90
+ /** 关键字,搜索制品名称 */
91
+ name?: string;
92
+ };
93
+
94
+ /**
95
+ * 制品库管理
96
+ */
97
+ export class RegistryPackage extends CNBCore {
98
+ constructor(options: CNBCoreOptions) {
99
+ super(options);
100
+ }
101
+
102
+ /**
103
+ * 查询组织下面用户有权限查看到的制品仓库
104
+ * @param slug 组织 slug
105
+ * @param params 查询参数
106
+ */
107
+ listGroupRegistries(
108
+ slug: string,
109
+ params?: ListGroupRegistriesParams
110
+ ): Promise<Result<Registry[]>> {
111
+ const url = `/${slug}/-/registries`;
112
+ return this.get({
113
+ url,
114
+ params,
115
+ headers: {
116
+ Accept: "application/vnd.cnb.api+json",
117
+ },
118
+ });
119
+ }
120
+
121
+ /**
122
+ * 设置制品库可见性
123
+ * @param registry 制品库路径
124
+ * @param data 可见性设置
125
+ */
126
+ setVisibility(
127
+ registry: string,
128
+ data: { visibility: VisibilityType }
129
+ ): Promise<Result<void>> {
130
+ const url = `/${registry}/-/settings/set_visibility`;
131
+ return this.post({
132
+ url,
133
+ data,
134
+ });
135
+ }
136
+
137
+ /**
138
+ * 删除制品库
139
+ * @param registry 制品库路径
140
+ */
141
+ remove(registry: string): Promise<Result<void>> {
142
+ const url = `/${registry}`;
143
+ return this.delete({ url });
144
+ }
145
+ }